BornAgain  1.18.0
Simulate and fit neutron and x-ray scattering at grazing incidence
IInterferenceFunctionStrategy.cpp
Go to the documentation of this file.
1 // ************************************************************************** //
2 //
3 // BornAgain: simulate and fit scattering at grazing incidence
4 //
5 //! @file Sample/Interference/IInterferenceFunctionStrategy.cpp
6 //! @brief Implements default behaviour of IInterferenceFunctionStrategy.
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/Types/Exceptions.h"
21 
23  bool polarized)
24  : mP_iff(nullptr), m_options(sim_params), m_polarized(polarized),
25  mP_integrator(
26  make_integrator_miser(this, &IInterferenceFunctionStrategy::evaluate_for_fixed_angles, 2))
27 {
28 }
29 
31 
33  const std::vector<FormFactorCoherentSum>& weighted_formfactors,
34  const IInterferenceFunction* p_iff)
35 {
36  if (weighted_formfactors.empty())
38  "IInterferenceFunctionStrategy::init: strategy gets no form factors.");
39  m_formfactor_wrappers = weighted_formfactors;
40  if (p_iff)
41  mP_iff.reset(p_iff->clone());
42  else
43  mP_iff.reset(new InterferenceFunctionNone());
44 
46 }
47 
49 {
50  if (m_options.isIntegrate() && (sim_element.getSolidAngle() > 0.0))
51  return MCIntegratedEvaluate(sim_element);
52  return evaluateSinglePoint(sim_element);
53 }
54 
55 double
57 {
58  if (!m_polarized)
59  return scalarCalculation(sim_element);
60  else
61  return polarizedCalculation(sim_element);
62 }
63 
64 //! Performs a Monte Carlo integration over the bin for the evaluation of the intensity.
65 double
67 {
68  double min_array[] = {0.0, 0.0};
69  double max_array[] = {1.0, 1.0};
70  return mP_integrator->integrate(min_array, max_array, (void*)&sim_element,
72 }
73 
75  void* params) const
76 {
77  double par0 = fractions[0];
78  double par1 = fractions[1];
79 
80  SimulationElement* pars = static_cast<SimulationElement*>(params);
81 
82  SimulationElement sim_element(*pars, par0, par1);
83  return pars->getIntegrationFactor(par0, par1) * evaluateSinglePoint(sim_element);
84 }
85 
Defines many exception classes in namespace Exceptionss.
Defines class FormFactorCoherentSum.
Defines class IInterferenceFunctionStrategy.
Defines and implements template class IntegratorMCMiser.
Defines class InterferenceFunctionNone.
Defines class SimulationElement.
Base class of all interference function strategy classes.
double evaluate_for_fixed_angles(double *fractions, size_t dim, void *params) const
virtual double scalarCalculation(const SimulationElement &sim_element) const =0
Evaluates the intensity in the scalar case.
double evaluate(const SimulationElement &sim_element) const
Calculates the intensity for scalar particles/interactions.
std::vector< FormFactorCoherentSum > m_formfactor_wrappers
double evaluateSinglePoint(const SimulationElement &sim_element) const
IInterferenceFunctionStrategy(const SimulationOptions &sim_params, bool polarized)
void init(const std::vector< FormFactorCoherentSum > &weighted_formfactors, const IInterferenceFunction *p_iff)
Initializes the object with form factors and an interference function.
double MCIntegratedEvaluate(const SimulationElement &sim_element) const
Performs a Monte Carlo integration over the bin for the evaluation of the intensity.
virtual double polarizedCalculation(const SimulationElement &sim_element) const =0
Evaluates the intensity in the polarized case.
std::unique_ptr< IntegratorMCMiser< IInterferenceFunctionStrategy > > mP_integrator
std::unique_ptr< IInterferenceFunction > mP_iff
Pure virtual base class of interference functions.
virtual IInterferenceFunction * clone() const =0
Returns a clone of this ISample object.
Default interference function (i.e.
Data stucture containing both input and output of a single detector cell.
double getSolidAngle() const
double getIntegrationFactor(double x, double y) const
Collect the different options for simulation.
size_t getMcPoints() const
bool isIntegrate() const
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.