BornAgain  1.18.0
Simulate and fit neutron and x-ray scattering at grazing incidence
IntegratorMCMiser< T > Class Template Reference
Collaboration diagram for IntegratorMCMiser< T >:

Classes

struct  CallBackHolder
 

Public Member Functions

 IntegratorMCMiser (const T *p_object, miser_integrand< T > p_member_function, size_t dim)
 
 ~IntegratorMCMiser ()
 
double integrate (double *min_array, double *max_array, void *params, size_t nbr_points)
 

Static Private Member Functions

static double StaticCallBack (double *d_array, size_t dim, void *v)
 

Private Attributes

const T * mp_object
 
miser_integrand< T > m_member_function
 
size_t m_dim
 
gsl_monte_miser_state * m_gsl_workspace
 
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 34 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 85 of file IntegratorMCMiser.h.

87  : mp_object(p_object), m_member_function(p_member_function),
88  m_dim(dim), m_gsl_workspace{nullptr}
89 {
90  m_gsl_workspace = gsl_monte_miser_alloc(m_dim);
91 
92  const gsl_rng_type* random_type;
93  gsl_rng_env_setup();
94  random_type = gsl_rng_default;
95  m_random_gen = gsl_rng_alloc(random_type);
96 }
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 98 of file IntegratorMCMiser.h.

99 {
100  gsl_monte_miser_free(m_gsl_workspace);
101  gsl_rng_free(m_random_gen);
102 }

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 105 of file IntegratorMCMiser.h.

107 {
108  CallBackHolder cb = {mp_object, m_member_function, params};
109 
110  gsl_monte_function f;
111  f.f = StaticCallBack;
112  f.dim = m_dim;
113  f.params = &cb;
114 
115  double result, error;
116  gsl_monte_miser_integrate(&f, min_array, max_array, m_dim, nbr_points, m_random_gen,
117  m_gsl_workspace, &result, &error);
118  return result;
119 }
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 53 of file IntegratorMCMiser.h.

54  {
55  CallBackHolder* p_cb = static_cast<CallBackHolder*>(v);
56  auto mf = static_cast<miser_integrand<T>>(p_cb->m_member_function);
57  return (p_cb->m_object_pointer->*mf)(d_array, dim, p_cb->m_data);
58  }
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

◆ mp_object

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

Definition at line 59 of file IntegratorMCMiser.h.

◆ m_member_function

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

Definition at line 60 of file IntegratorMCMiser.h.

◆ m_dim

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

dimension of the integration

Definition at line 61 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 62 of file IntegratorMCMiser.h.

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

◆ m_random_gen

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

Definition at line 63 of file IntegratorMCMiser.h.

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


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