BornAgain  1.19.0
Simulate and fit neutron and x-ray scattering at grazing incidence
IntegratorMCMiser< T > Class Template Reference

Template class to use Monte Carlo MISER integration of class member functions. More...

Classes

struct  CallBackHolder
 structure holding the object and possible extra parameters More...
 

Public Member Functions

 IntegratorMCMiser (const T *p_object, miser_integrand< T > p_member_function, size_t dim)
 to integrate p_member_function, which must belong to p_object More...
 
 ~IntegratorMCMiser ()
 
double integrate (double *min_array, double *max_array, void *params, size_t nbr_points)
 perform the actual integration over the ranges [min_array, max_array] More...
 

Static Private Member Functions

static double StaticCallBack (double *d_array, size_t dim, void *v)
 static function that can be passed to gsl integrator More...
 

Private Attributes

size_t m_dim
 dimension of the integration More...
 
gsl_monte_miser_state * m_gsl_workspace
 
miser_integrand< T > m_member_function
 
const T * m_object
 
gsl_rng * m_random_gen
 

Detailed Description

template<class T>
class IntegratorMCMiser< T >

Template class to use Monte Carlo MISER integration of class member functions.

Wraps an integrator from GNU Scientific Library. Since this class holds a persistent workspace, we need at least one instance per thread. Standard usage for integration inside a class T:

  • Create a handle to an integrator: 'auto integrator = make_integrator_miser(this, mem_function, dimension)'
  • Call: 'integrator.integrate(lmin, lmax, data, nbr_points)'

Definition at line 39 of file IntegratorMCMiser.h.

Constructor & Destructor Documentation

◆ IntegratorMCMiser()

template<class T >
IntegratorMCMiser< T >::IntegratorMCMiser ( const T *  p_object,
miser_integrand< T >  p_member_function,
size_t  dim 
)

to integrate p_member_function, which must belong to p_object

Definition at line 89 of file IntegratorMCMiser.h.

91  : m_object(p_object), m_member_function(p_member_function), m_dim(dim), m_gsl_workspace{nullptr}
92 {
93  m_gsl_workspace = gsl_monte_miser_alloc(m_dim);
94 
95  const gsl_rng_type* random_type;
96  gsl_rng_env_setup();
97  random_type = gsl_rng_default;
98  m_random_gen = gsl_rng_alloc(random_type);
99 }
miser_integrand< T > m_member_function
size_t m_dim
dimension of the integration
gsl_monte_miser_state * m_gsl_workspace

References IntegratorMCMiser< T >::m_dim, IntegratorMCMiser< T >::m_gsl_workspace, and IntegratorMCMiser< T >::m_random_gen.

◆ ~IntegratorMCMiser()

template<class T >
IntegratorMCMiser< T >::~IntegratorMCMiser

Definition at line 101 of file IntegratorMCMiser.h.

102 {
103  gsl_monte_miser_free(m_gsl_workspace);
104  gsl_rng_free(m_random_gen);
105 }

Member Function Documentation

◆ integrate()

template<class T >
double IntegratorMCMiser< T >::integrate ( double *  min_array,
double *  max_array,
void *  params,
size_t  nbr_points 
)

perform the actual integration over the ranges [min_array, max_array]

Definition at line 108 of file IntegratorMCMiser.h.

110 {
111  CallBackHolder cb = {m_object, m_member_function, params};
112 
113  gsl_monte_function f;
114  f.f = StaticCallBack;
115  f.dim = m_dim;
116  f.params = &cb;
117 
118  double result, error;
119  gsl_monte_miser_integrate(&f, min_array, max_array, m_dim, nbr_points, m_random_gen,
120  m_gsl_workspace, &result, &error);
121  return result;
122 }
static double StaticCallBack(double *d_array, size_t dim, void *v)
static function that can be passed to gsl integrator

◆ StaticCallBack()

template<class T >
static double IntegratorMCMiser< T >::StaticCallBack ( double *  d_array,
size_t  dim,
void *  v 
)
inlinestaticprivate

static function that can be passed to gsl integrator

Definition at line 57 of file IntegratorMCMiser.h.

58  {
59  CallBackHolder* p_cb = static_cast<CallBackHolder*>(v);
60  auto mf = static_cast<miser_integrand<T>>(p_cb->m_member_function);
61  return (p_cb->m_object_pointer->*mf)(d_array, dim, p_cb->m_data);
62  }
double(T::*)(double *, size_t, void *) const miser_integrand
Alias template for member function with signature double f(double)

References IntegratorMCMiser< T >::CallBackHolder::m_data, IntegratorMCMiser< T >::CallBackHolder::m_member_function, and IntegratorMCMiser< T >::CallBackHolder::m_object_pointer.

Member Data Documentation

◆ m_dim

template<class T >
size_t IntegratorMCMiser< T >::m_dim
private

dimension of the integration

Definition at line 65 of file IntegratorMCMiser.h.

Referenced by IntegratorMCMiser< T >::IntegratorMCMiser().

◆ m_gsl_workspace

template<class T >
gsl_monte_miser_state* IntegratorMCMiser< T >::m_gsl_workspace
private

Definition at line 66 of file IntegratorMCMiser.h.

Referenced by IntegratorMCMiser< T >::IntegratorMCMiser().

◆ m_member_function

template<class T >
miser_integrand<T> IntegratorMCMiser< T >::m_member_function
private

Definition at line 64 of file IntegratorMCMiser.h.

◆ m_object

template<class T >
const T* IntegratorMCMiser< T >::m_object
private

Definition at line 63 of file IntegratorMCMiser.h.

◆ m_random_gen

template<class T >
gsl_rng* IntegratorMCMiser< T >::m_random_gen
private

Definition at line 67 of file IntegratorMCMiser.h.

Referenced by IntegratorMCMiser< T >::IntegratorMCMiser().


The documentation for this class was generated from the following file: