BornAgain  1.18.0
Simulate and fit neutron and x-ray scattering at grazing incidence
SSCAHelper.cpp
Go to the documentation of this file.
1 // ************************************************************************** //
2 //
3 // BornAgain: simulate and fit scattering at grazing incidence
4 //
5 //! @file Sample/Interference/SSCAHelper.cpp
6 //! @brief Implements class SSCAHelper.
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 
16 #include "Base/Types/Exceptions.h"
19 
20 SSCAHelper::SSCAHelper(double kappa) : m_kappa(kappa), m_mean_radius{} {}
21 
22 void SSCAHelper::init(const std::vector<FormFactorCoherentSum>& ff_wrappers)
23 {
24  m_mean_radius = 0.0;
25  for (auto& ffw : ff_wrappers)
26  m_mean_radius += ffw.relativeAbundance() * ffw.radialExtension();
27 }
28 
30  double qp, const std::vector<FormFactorCoherentSum>& ff_wrappers) const
31 {
32  complex_t result{};
33  for (auto& ffw : ff_wrappers) {
34  double radial_extension = ffw.radialExtension();
35  result +=
36  ffw.relativeAbundance() * calculatePositionOffsetPhase(2.0 * qp, radial_extension);
37  }
38  return result;
39 }
40 
42  const IInterferenceFunction* p_iff) const
43 {
44  const InterferenceFunctionRadialParaCrystal* p_iff_radial =
45  dynamic_cast<const InterferenceFunctionRadialParaCrystal*>(p_iff);
46  if (!p_iff_radial)
47  throw Exceptions::ClassInitializationException("Wrong interference function for SSCA");
48  return p_iff_radial->FTPDF(qp);
49 }
50 
51 complex_t SSCAHelper::calculatePositionOffsetPhase(double qp, double radial_extension) const
52 {
53  return exp_I(m_kappa * qp * (radial_extension - m_mean_radius));
54 }
55 
57 SSCAHelper::getMeanFormfactorNorm(double qp, const std::vector<complex_t>& precomputed_ff,
58  const std::vector<FormFactorCoherentSum>& ff_wrappers) const
59 {
60  complex_t ff_orig = 0., ff_conj = 0.; // original and conjugated mean formfactor
61  for (size_t i = 0; i < ff_wrappers.size(); ++i) {
62  double radial_extension = ff_wrappers[i].radialExtension();
63  complex_t prefac =
64  ff_wrappers[i].relativeAbundance() * calculatePositionOffsetPhase(qp, radial_extension);
65  ff_orig += prefac * precomputed_ff[i];
66  ff_conj += prefac * std::conj(precomputed_ff[i]);
67  }
68  return ff_orig * ff_conj;
69 }
70 
72  double qp, Eigen::Matrix2cd& ff_orig, Eigen::Matrix2cd& ff_conj,
73  const InterferenceFunctionUtils::matrixFFVector_t& precomputed_ff,
74  const std::vector<FormFactorCoherentSum>& ff_wrappers) const
75 {
76  ff_orig = Eigen::Matrix2cd::Zero();
77  ff_conj = Eigen::Matrix2cd::Zero();
78  for (size_t i = 0; i < ff_wrappers.size(); ++i) {
79  double radial_extension = ff_wrappers[i].radialExtension();
80  complex_t prefac =
81  ff_wrappers[i].relativeAbundance() * calculatePositionOffsetPhase(qp, radial_extension);
82  ff_orig += prefac * precomputed_ff[i];
83  ff_conj += prefac * precomputed_ff[i].adjoint();
84  }
85 }
std::complex< double > complex_t
Definition: Complex.h:20
complex_t exp_I(complex_t z)
Returns exp(I*z), where I is the imaginary unit.
Definition: Complex.h:30
Defines many exception classes in namespace Exceptionss.
Defines class FormFactorCoherentSum.
Defines class InterferenceFunctionRadialParaCrystal.
Defines class SSCAHelper.
Pure virtual base class of interference functions.
Interference function of radial paracrystal.
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
double m_mean_radius
Definition: SSCAHelper.h:49
complex_t calculatePositionOffsetPhase(double qp, double radial_extension) const
Definition: SSCAHelper.cpp:51
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
SSCAHelper(double kappa)
Definition: SSCAHelper.cpp:20
complex_t getCharacteristicDistribution(double qp, const IInterferenceFunction *p_iff) const
Definition: SSCAHelper.cpp:41
double m_kappa
Definition: SSCAHelper.h:48
complex_t getCharacteristicSizeCoupling(double qp, const std::vector< FormFactorCoherentSum > &ff_wrappers) const
Definition: SSCAHelper.cpp:29
std::vector< Eigen::Matrix2cd, Eigen::aligned_allocator< Eigen::Matrix2cd > > matrixFFVector_t