BornAgain  1.19.79
Open-source research software to simulate and fit neutron and x-ray reflectometry and grazing-incidence small-angle scattering
IntegratorGK.cpp
Go to the documentation of this file.
1 // ************************************************************************************************
2 //
3 // BornAgain: simulate and fit reflection and scattering
4 //
5 //! @file Base/Math/IntegratorGK.cpp
6 //! @brief Implements classes RealIntegrator, ComplexIntegrator.
7 //!
8 //! @homepage http://www.bornagainproject.org
9 //! @license GNU General Public License v3 or higher (see COPYING)
10 //! @copyright Forschungszentrum Jülich GmbH 2018
11 //! @authors Scientific Computing Group at MLZ (see CITATION, AUTHORS)
12 //
13 // ************************************************************************************************
14 
15 #include "Base/Math/IntegratorGK.h"
16 
18  : m_gsl_f{m_Cfunction, nullptr}
19  , m_workspace{gsl_integration_workspace_alloc(200)}
20 {
21 }
22 
24 {
25  gsl_integration_workspace_free(m_workspace);
26 }
27 
28 double RealIntegrator::integrate(const std::function<double(double)>& f, double lmin, double lmax)
29 {
30  m_gsl_f.params = (void*)&f;
31  double result, error;
32  gsl_integration_qag(&m_gsl_f, lmin, lmax, 1e-9, 1e-7, 200, 3, m_workspace, &result, &error);
33  // TODO check error
34  return result;
35 }
36 
37 complex_t ComplexIntegrator::integrate(const std::function<complex_t(double)>& f, double lmin,
38  double lmax)
39 {
40  return {realPart.integrate([f](double x) { return f(x).real(); }, lmin, lmax),
41  imagPart.integrate([f](double x) { return f(x).imag(); }, lmin, lmax)};
42 }
Defines classes RealIntegrator, ComplexIntegrator.
complex_t integrate(const std::function< complex_t(double)> &f, double lmin, double lmax)
RealIntegrator realPart
Definition: IntegratorGK.h:49
RealIntegrator imagPart
Definition: IntegratorGK.h:50
double integrate(const std::function< double(double)> &f, double lmin, double lmax)
gsl_integration_workspace * m_workspace
Definition: IntegratorGK.h:40
gsl_function m_gsl_f
Definition: IntegratorGK.h:38