BornAgain  1.19.79
Open-source research software to simulate and fit neutron and x-ray reflectometry and grazing-incidence small-angle scattering
IInterparticleStrategy.cpp
Go to the documentation of this file.
1 // ************************************************************************************************
2 //
3 // BornAgain: simulate and fit reflection and scattering
4 //
5 //! @file Resample/Interparticle/IInterparticleStrategy.cpp
6 //! @brief Implements default behaviour of IInterparticleStrategy.
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 
17 #include "Base/Util/Assert.h"
20 
22  const std::vector<std::unique_ptr<const CoherentFFSum>>& weighted_formfactors,
23  const SimulationOptions& sim_params, bool polarized)
24  : m_weighted_formfactors(weighted_formfactors)
25  , m_options(sim_params)
26  , m_polarized(polarized)
27  , m_integrator(
28  make_integrator_miser(this, &IInterparticleStrategy::evaluate_for_fixed_angles, 2))
29 {
31 }
32 
34 
36 {
37  if (m_options.isIntegrate() && (ele.solidAngle() > 0.0))
38  return MCIntegratedEvaluate(ele);
39  return evaluateSinglePoint(ele);
40 }
41 
43 {
44  if (!m_polarized)
45  return scalarCalculation(ele);
46  return polarizedCalculation(ele);
47 }
48 
49 //! Performs a Monte Carlo integration over the bin for the evaluation of the intensity.
51 {
52  double min_array[] = {0.0, 0.0};
53  double max_array[] = {1.0, 1.0};
54  return m_integrator->integrate(min_array, max_array, (void*)&ele, m_options.getMcPoints());
55 }
56 
57 double IInterparticleStrategy::evaluate_for_fixed_angles(const double* fractions, size_t,
58  const void* params) const
59 {
60  double par0 = fractions[0];
61  double par1 = fractions[1];
62 
63  const auto* pars = static_cast<const DiffuseElement*>(params);
64 
65  DiffuseElement ele = pars->pointElement(par0, par1);
66  return pars->integrationFactor(par0, par1) * evaluateSinglePoint(ele);
67 }
Defines the macro ASSERT.
#define ASSERT(condition)
Definition: Assert.h:45
Defines class CoherentFFSum.
Defines class DiffuseElement.
Defines interface IInterparticleStrategy.
Defines and implements template class IntegratorMCMiser.
P_integrator_miser< T > make_integrator_miser(const T *object, miser_integrand< T > mem_function, size_t dim)
Template function to create an integrator object.
Data stucture containing both input and output of a single detector cell.
double solidAngle() const
double integrationFactor(double x, double y) const
DiffuseElement pointElement(double x, double y) const
Returns copy of this DiffuseElement with k_f given by in-pixel coordinate x,y.
Abstract base class of DecouplingApproximationStrategy, SSCAStrategy. Provides function 'evaluate' th...
virtual double scalarCalculation(const DiffuseElement &ele) const =0
Evaluates the intensity in the scalar case.
const std::unique_ptr< IntegratorMCMiser< IInterparticleStrategy > > m_integrator
double evaluate_for_fixed_angles(const double *fractions, size_t dim, const void *params) const
double evaluate(const DiffuseElement &ele) const
Calculates the intensity for scalar particles/interactions.
virtual ~IInterparticleStrategy()
double evaluateSinglePoint(const DiffuseElement &ele) const
double MCIntegratedEvaluate(const DiffuseElement &ele) const
Performs a Monte Carlo integration over the bin for the evaluation of the intensity.
const std::vector< std::unique_ptr< const CoherentFFSum > > & m_weighted_formfactors
IInterparticleStrategy(const std::vector< std::unique_ptr< const CoherentFFSum >> &weighted_formfactors, const SimulationOptions &sim_params, bool polarized)
const SimulationOptions m_options
virtual double polarizedCalculation(const DiffuseElement &ele) const =0
Evaluates the intensity in the polarized case.
Collect the different options for simulation.SimulationOptions.
size_t getMcPoints() const
bool isIntegrate() const