BornAgain  1.19.79
Open-source research software to simulate and fit neutron and x-ray reflectometry and grazing-incidence small-angle scattering
DecouplingApproximationStrategy Class Reference

Description

Strategy class to compute the total scattering from a particle layout in the decoupling approximation.

Definition at line 30 of file DecouplingApproximationStrategy.h.

Inheritance diagram for DecouplingApproximationStrategy:
[legend]
Collaboration diagram for DecouplingApproximationStrategy:
[legend]

Public Member Functions

 DecouplingApproximationStrategy (const std::vector< std::unique_ptr< const CoherentFFSum >> &weighted_formfactors, const IInterference *iff, SimulationOptions sim_params, bool polarized)
 
double evaluate (const DiffuseElement &ele) const
 Calculates the intensity for scalar particles/interactions. More...
 

Protected Attributes

const SimulationOptions m_options
 
const std::vector< std::unique_ptr< const CoherentFFSum > > & m_weighted_formfactors
 

Private Member Functions

double evaluate_for_fixed_angles (const double *fractions, size_t dim, const void *params) const
 
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. More...
 
double polarizedCalculation (const DiffuseElement &ele) const override
 This is the polarized version. More...
 
double scalarCalculation (const DiffuseElement &ele) const override
 Returns the total incoherent and coherent scattering intensity for given kf and for one particle layout (implied by the given particle form factors). This is the scalar version. More...
 

Private Attributes

const std::unique_ptr< IInterferencem_iff
 
const std::unique_ptr< IntegratorMCMiser< IInterparticleStrategy > > m_integrator
 
const bool m_polarized
 

Constructor & Destructor Documentation

◆ DecouplingApproximationStrategy()

DecouplingApproximationStrategy::DecouplingApproximationStrategy ( const std::vector< std::unique_ptr< const CoherentFFSum >> &  weighted_formfactors,
const IInterference iff,
SimulationOptions  sim_params,
bool  polarized 
)

Definition at line 21 of file DecouplingApproximationStrategy.cpp.

24  : IInterparticleStrategy(weighted_formfactors, sim_params, polarized)
25  , m_iff(iff ? iff->clone() : new InterferenceNone())
26 
27 {
28 }
const std::unique_ptr< IInterference > m_iff
IInterference * clone() const override=0
IInterparticleStrategy(const std::vector< std::unique_ptr< const CoherentFFSum >> &weighted_formfactors, const SimulationOptions &sim_params, bool polarized)
Default interference function (i.e. absence of any interference).

Member Function Documentation

◆ evaluate()

double IInterparticleStrategy::evaluate ( const DiffuseElement ele) const
inherited

Calculates the intensity for scalar particles/interactions.

Definition at line 35 of file IInterparticleStrategy.cpp.

36 {
37  if (m_options.isIntegrate() && (ele.solidAngle() > 0.0))
38  return MCIntegratedEvaluate(ele);
39  return evaluateSinglePoint(ele);
40 }
double solidAngle() const
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 SimulationOptions m_options
bool isIntegrate() const

References IInterparticleStrategy::evaluateSinglePoint(), SimulationOptions::isIntegrate(), IInterparticleStrategy::m_options, IInterparticleStrategy::MCIntegratedEvaluate(), and DiffuseElement::solidAngle().

Here is the call graph for this function:

◆ evaluate_for_fixed_angles()

double IInterparticleStrategy::evaluate_for_fixed_angles ( const double *  fractions,
size_t  dim,
const void *  params 
) const
privateinherited

Definition at line 57 of file IInterparticleStrategy.cpp.

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 }
Data stucture containing both input and output of a single detector cell.
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.

References IInterparticleStrategy::evaluateSinglePoint(), DiffuseElement::integrationFactor(), and DiffuseElement::pointElement().

Here is the call graph for this function:

◆ evaluateSinglePoint()

double IInterparticleStrategy::evaluateSinglePoint ( const DiffuseElement ele) const
privateinherited

Definition at line 42 of file IInterparticleStrategy.cpp.

43 {
44  if (!m_polarized)
45  return scalarCalculation(ele);
46  return polarizedCalculation(ele);
47 }
virtual double scalarCalculation(const DiffuseElement &ele) const =0
Evaluates the intensity in the scalar case.
virtual double polarizedCalculation(const DiffuseElement &ele) const =0
Evaluates the intensity in the polarized case.

References IInterparticleStrategy::m_polarized, IInterparticleStrategy::polarizedCalculation(), and IInterparticleStrategy::scalarCalculation().

Referenced by IInterparticleStrategy::evaluate(), and IInterparticleStrategy::evaluate_for_fixed_angles().

Here is the call graph for this function:

◆ MCIntegratedEvaluate()

double IInterparticleStrategy::MCIntegratedEvaluate ( const DiffuseElement ele) const
privateinherited

Performs a Monte Carlo integration over the bin for the evaluation of the intensity.

Definition at line 50 of file IInterparticleStrategy.cpp.

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 }
const std::unique_ptr< IntegratorMCMiser< IInterparticleStrategy > > m_integrator
size_t getMcPoints() const

References SimulationOptions::getMcPoints(), IInterparticleStrategy::m_integrator, and IInterparticleStrategy::m_options.

Referenced by IInterparticleStrategy::evaluate().

Here is the call graph for this function:

◆ polarizedCalculation()

double DecouplingApproximationStrategy::polarizedCalculation ( const DiffuseElement ele) const
overrideprivatevirtual

This is the polarized version.

Implements IInterparticleStrategy.

Definition at line 52 of file DecouplingApproximationStrategy.cpp.

53 {
54  SpinMatrix mean_intensity;
55  SpinMatrix mean_amplitude;
56 
57  const auto& polarization_handler = ele.polMatrices();
58  for (const auto& ffw : m_weighted_formfactors) {
59  const SpinMatrix ff = ffw->summedPolFF(ele);
60  if (!ff.allFinite())
61  throw std::runtime_error(
62  "numerical error in coherent sum (polarized, DA): amplitude is NaN");
63  const double fraction = ffw->relativeAbundance();
64  mean_amplitude += fraction * ff;
65  mean_intensity += fraction * (ff * polarization_handler.polarizerMatrix() * ff.adjoint());
66  }
67  const SpinMatrix amplitude_matrix = polarization_handler.analyzerMatrix() * mean_amplitude
68  * polarization_handler.polarizerMatrix()
69  * mean_amplitude.adjoint();
70  const SpinMatrix intensity_matrix = polarization_handler.analyzerMatrix() * mean_intensity;
71  const double amplitude_trace = std::abs(amplitude_matrix.trace());
72  const double intensity_trace = std::abs(intensity_matrix.trace());
73  const double coherence_factor = m_iff->structureFactor(ele.meanQ());
74  return intensity_trace + amplitude_trace * (coherence_factor - 1.0);
75 }
const PolMatrices & polMatrices() const
Returns polarizer and analyzer matrices.
Definition: IElement.h:37
const std::vector< std::unique_ptr< const CoherentFFSum > > & m_weighted_formfactors
SpinMatrix adjoint() const
Definition: SpinMatrix.cpp:180
complex_t trace() const
Definition: SpinMatrix.cpp:165

References SpinMatrix::adjoint(), m_iff, IInterparticleStrategy::m_weighted_formfactors, DiffuseElement::meanQ(), IElement::polMatrices(), and SpinMatrix::trace().

Here is the call graph for this function:

◆ scalarCalculation()

double DecouplingApproximationStrategy::scalarCalculation ( const DiffuseElement ele) const
overrideprivatevirtual

Returns the total incoherent and coherent scattering intensity for given kf and for one particle layout (implied by the given particle form factors). This is the scalar version.

Implements IInterparticleStrategy.

Definition at line 33 of file DecouplingApproximationStrategy.cpp.

34 {
35  double intensity = 0.0;
36  complex_t amplitude = complex_t(0.0, 0.0);
37  for (const auto& ffw : m_weighted_formfactors) {
38  const complex_t ff = ffw->summedFF(ele);
39  if (std::isnan(ff.real()))
40  throw std::runtime_error(
41  "numerical error in coherent sum (scalar, DA): amplitude is NaN");
42  const double fraction = ffw->relativeAbundance();
43  amplitude += fraction * ff;
44  intensity += fraction * std::norm(ff);
45  }
46  const double amplitude_norm = std::norm(amplitude); // squared magnitude
47  const double coherence_factor = m_iff->structureFactor(ele.meanQ());
48  return intensity + amplitude_norm * (coherence_factor - 1.0);
49 }

References m_iff, IInterparticleStrategy::m_weighted_formfactors, and DiffuseElement::meanQ().

Here is the call graph for this function:

Member Data Documentation

◆ m_iff

const std::unique_ptr<IInterference> DecouplingApproximationStrategy::m_iff
private

Definition at line 40 of file DecouplingApproximationStrategy.h.

Referenced by polarizedCalculation(), and scalarCalculation().

◆ m_integrator

const std::unique_ptr<IntegratorMCMiser<IInterparticleStrategy> > IInterparticleStrategy::m_integrator
privateinherited

◆ m_options

const SimulationOptions IInterparticleStrategy::m_options
protectedinherited

◆ m_polarized

const bool IInterparticleStrategy::m_polarized
privateinherited

◆ m_weighted_formfactors

const std::vector<std::unique_ptr<const CoherentFFSum> >& IInterparticleStrategy::m_weighted_formfactors
protectedinherited

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