BornAgain  1.19.79
Open-source research software to simulate and fit neutron and x-ray reflectometry and grazing-incidence small-angle scattering
IntegratorMCMiser< T > Class Template Reference

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

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, const void *params, size_t nbr_points) const
 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

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

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

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

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

108 {
109  gsl_monte_miser_free(m_gsl_workspace);
110  gsl_rng_free(m_random_gen);
111 }

Member Function Documentation

◆ integrate()

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

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

Definition at line 114 of file IntegratorMCMiser.h.

116 {
117  CallBackHolder cb = {m_object, m_member_function, params};
118 
119  gsl_monte_function f;
120  f.f = StaticCallBack;
121  f.dim = m_dim;
122  f.params = &cb;
123 
124  double result, error;
125  gsl_monte_miser_integrate(&f, min_array, max_array, m_dim, nbr_points, m_random_gen,
126  m_gsl_workspace, &result, &error);
127  return result;
128 }
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 59 of file IntegratorMCMiser.h.

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

Member Data Documentation

◆ m_dim

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

dimension of the integration

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

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

◆ m_member_function

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

Definition at line 66 of file IntegratorMCMiser.h.

◆ m_object

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

Definition at line 65 of file IntegratorMCMiser.h.

◆ m_random_gen

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

Definition at line 69 of file IntegratorMCMiser.h.

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


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