BornAgain  1.18.0
Simulate and fit neutron and x-ray scattering at grazing incidence
SSCApproximationStrategy.cpp
Go to the documentation of this file.
1 // ************************************************************************** //
2 //
3 // BornAgain: simulate and fit scattering at grazing incidence
4 //
5 //! @file Sample/Interference/SSCApproximationStrategy.cpp
6 //! @brief Implements class SSCApproximationStrategy.
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 
19 
22 
24  bool polarized)
25  : IInterferenceFunctionStrategy(sim_params, polarized), m_helper(kappa)
26 {
27 }
28 
30 {
32 }
33 
34 //! Returns the total scattering intensity for given kf and
35 //! for one particle layout (implied by the given particle form factors).
36 //! This is the scalar version
38 {
39  double qp = sim_element.getMeanQ().magxy();
40  double diffuse_intensity = 0.0;
41  auto precomputed_ff = PrecomputeScalarFormFactors(sim_element, m_formfactor_wrappers);
42  for (size_t i = 0; i < m_formfactor_wrappers.size(); ++i) {
43  complex_t ff = precomputed_ff[i];
44  double fraction = m_formfactor_wrappers[i].relativeAbundance();
45  diffuse_intensity += fraction * std::norm(ff);
46  }
47  complex_t mean_ff_norm =
51  double iff = 2.0 * (mean_ff_norm * omega / (1.0 - p2kappa * omega)).real();
52  double dw_factor = mP_iff->DWfactor(sim_element.getMeanQ());
53  return diffuse_intensity + dw_factor * iff;
54 }
55 
56 //! This is the polarized version
58 {
59  double qp = sim_element.getMeanQ().magxy();
60  Eigen::Matrix2cd diffuse_matrix = Eigen::Matrix2cd::Zero();
61  auto precomputed_ff = PrecomputePolarizedFormFactors(sim_element, m_formfactor_wrappers);
62  const auto& polarization_handler = sim_element.polarizationHandler();
63  for (size_t i = 0; i < m_formfactor_wrappers.size(); ++i) {
64  Eigen::Matrix2cd ff = precomputed_ff[i];
65  double fraction = m_formfactor_wrappers[i].relativeAbundance();
66  diffuse_matrix += fraction * (ff * polarization_handler.getPolarization() * ff.adjoint());
67  }
68  Eigen::Matrix2cd mff_orig, mff_conj; // original and conjugated mean formfactor
69  m_helper.getMeanFormfactors(qp, mff_orig, mff_conj, precomputed_ff, m_formfactor_wrappers);
72  Eigen::Matrix2cd interference_matrix = (2.0 * omega / (1.0 - p2kappa * omega))
73  * polarization_handler.getAnalyzerOperator() * mff_orig
74  * polarization_handler.getPolarization() * mff_conj;
75  Eigen::Matrix2cd diffuse_matrix2 = polarization_handler.getAnalyzerOperator() * diffuse_matrix;
76  double interference_trace = std::abs(interference_matrix.trace());
77  double diffuse_trace = std::abs(diffuse_matrix2.trace());
78  double dw_factor = mP_iff->DWfactor(sim_element.getMeanQ());
79  return diffuse_trace + dw_factor * interference_trace;
80 }
std::complex< double > complex_t
Definition: Complex.h:20
Defines class FormFactorCoherentSum.
Defines and implements the interface class IInterferenceFunction.
Defines class SSCApproximationStrategy.
Defines class SimulationElement.
double magxy() const
Returns distance from z axis.
Base class of all interference function strategy classes.
std::vector< FormFactorCoherentSum > m_formfactor_wrappers
std::unique_ptr< IInterferenceFunction > mP_iff
complex_t getMeanFormfactorNorm(double qp, const std::vector< complex_t > &precomputed_ff, const std::vector< FormFactorCoherentSum > &ff_wrappers) const
Definition: SSCAHelper.cpp:57
void init(const std::vector< FormFactorCoherentSum > &ff_wrappers)
Definition: SSCAHelper.cpp:22
void getMeanFormfactors(double qp, Eigen::Matrix2cd &ff_orig, Eigen::Matrix2cd &ff_conj, const InterferenceFunctionUtils::matrixFFVector_t &precomputed_ff, const std::vector< FormFactorCoherentSum > &ff_wrappers) const
Definition: SSCAHelper.cpp:71
complex_t getCharacteristicDistribution(double qp, const IInterferenceFunction *p_iff) const
Definition: SSCAHelper.cpp:41
complex_t getCharacteristicSizeCoupling(double qp, const std::vector< FormFactorCoherentSum > &ff_wrappers) const
Definition: SSCAHelper.cpp:29
double polarizedCalculation(const SimulationElement &sim_element) const override
This is the polarized version.
double scalarCalculation(const SimulationElement &sim_element) const override
Returns the total scattering intensity for given kf and for one particle layout (implied by the given...
SSCApproximationStrategy(SimulationOptions sim_params, double kappa, bool polarized)
Data stucture containing both input and output of a single detector cell.
kvector_t getMeanQ() const
const PolarizationHandler & polarizationHandler() const
Returns assigned PolarizationHandler.
Collect the different options for simulation.
std::vector< complex_t > PrecomputeScalarFormFactors(const SimulationElement &sim_element, const std::vector< FormFactorCoherentSum > &ff_wrappers)
matrixFFVector_t PrecomputePolarizedFormFactors(const SimulationElement &sim_element, const std::vector< FormFactorCoherentSum > &ff_wrappers)