BornAgain  1.19.79
Open-source research software to simulate and fit neutron and x-ray reflectometry and grazing-incidence small-angle scattering
SSCAStrategy.cpp
Go to the documentation of this file.
1 // ************************************************************************************************
2 //
3 // BornAgain: simulate and fit reflection and scattering
4 //
5 //! @file Resample/Interparticle/SSCAStrategy.cpp
6 //! @brief Implements class SSCAStrategy.
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 
20 namespace {
21 
22 double meanRadius(const std::vector<std::unique_ptr<const CoherentFFSum>>& weighted_formfactors)
23 {
24  double result = 0.0;
25  for (const auto& ffw : weighted_formfactors)
26  result += ffw->relativeAbundance() * ffw->radialExtension();
27  return result;
28 }
29 
30 } // namespace
31 
32 
34  const std::vector<std::unique_ptr<const CoherentFFSum>>& weighted_formfactors,
35  const InterferenceRadialParaCrystal* iff, SimulationOptions sim_params, bool polarized,
36  double kappa)
37  : IInterparticleStrategy(weighted_formfactors, sim_params, polarized)
38  , m_iff(iff->clone())
39  , m_kappa(kappa)
40  , m_mean_radius(meanRadius(weighted_formfactors))
41 {
42 }
43 
44 //! Returns the total scattering intensity for given kf and
45 //! for one particle layout (implied by the given particle form factors).
46 //! This is the scalar version
48 {
49  const double qp = ele.meanQ().magxy();
50  double diffuse_intensity = 0.0;
51  complex_t ff_orig = 0., ff_conj = 0.; // original and conjugated mean formfactor
52  for (const auto& ffw : m_weighted_formfactors) {
53  complex_t ff = ffw->summedFF(ele);
54  double fraction = ffw->relativeAbundance();
55  diffuse_intensity += fraction * std::norm(ff);
56  double radial_extension = ffw->radialExtension();
57  complex_t prefac =
58  ffw->relativeAbundance() * calculatePositionOffsetPhase(qp, radial_extension);
59  ff_orig += prefac * ff;
60  ff_conj += prefac * std::conj(ff);
61  }
62  const complex_t mean_ff_norm = ff_orig * ff_conj;
63  const complex_t p2kappa = getCharacteristicSizeCoupling(qp, m_weighted_formfactors);
64  const complex_t omega = m_iff->FTPDF(qp);
65  const double iff = 2.0 * (mean_ff_norm * omega / (1.0 - p2kappa * omega)).real();
66  const double dw_factor = m_iff->DWfactor(ele.meanQ());
67  return diffuse_intensity + dw_factor * iff;
68 }
69 
70 //! This is the polarized version
72 {
73  const double qp = ele.meanQ().magxy();
74  SpinMatrix diffuse_matrix;
75  const auto& polarization_handler = ele.polMatrices();
76  SpinMatrix ff_orig;
77  SpinMatrix ff_conj;
78  for (const auto& ffw : m_weighted_formfactors) {
79  const SpinMatrix ff = ffw->summedPolFF(ele);
80  const double fraction = ffw->relativeAbundance();
81  diffuse_matrix += fraction * (ff * polarization_handler.polarizerMatrix() * ff.adjoint());
82  const double radial_extension = ffw->radialExtension();
83  const complex_t prefac =
84  ffw->relativeAbundance() * calculatePositionOffsetPhase(qp, radial_extension);
85  ff_orig += prefac * ff;
86  ff_conj += prefac * ff.adjoint();
87  }
88  const complex_t p2kappa = getCharacteristicSizeCoupling(qp, m_weighted_formfactors);
89  const complex_t omega = m_iff->FTPDF(qp);
90  const SpinMatrix interference_matrix = (2.0 * omega / (1.0 - p2kappa * omega))
91  * polarization_handler.analyzerMatrix() * ff_orig
92  * polarization_handler.polarizerMatrix() * ff_conj;
93  const SpinMatrix diffuse_matrix2 = polarization_handler.analyzerMatrix() * diffuse_matrix;
94  const double interference_trace = std::abs(interference_matrix.trace());
95  const double diffuse_trace = std::abs(diffuse_matrix2.trace());
96  const double dw_factor = m_iff->DWfactor(ele.meanQ());
97  return diffuse_trace + dw_factor * interference_trace;
98 }
99 
101  double qp, const std::vector<std::unique_ptr<const CoherentFFSum>>& ff_wrappers) const
102 {
103  complex_t result = 0;
104  for (const auto& ffw : ff_wrappers)
105  result += ffw->relativeAbundance()
106  * calculatePositionOffsetPhase(2.0 * qp, ffw->radialExtension());
107  return result;
108 }
109 
110 complex_t SSCAStrategy::calculatePositionOffsetPhase(double qp, double radial_extension) const
111 {
112  return exp_I(m_kappa * qp * (radial_extension - m_mean_radius));
113 }
Defines class CoherentFFSum.
Defines class DiffuseElement.
Defines class InterferenceRadialParaCrystal.
Defines class SSCAStrategy.
Data stucture containing both input and output of a single detector cell.
const PolMatrices & polMatrices() const
Returns polarizer and analyzer matrices.
Definition: IElement.h:37
Abstract base class of DecouplingApproximationStrategy, SSCAStrategy. Provides function 'evaluate' th...
const std::vector< std::unique_ptr< const CoherentFFSum > > & m_weighted_formfactors
Interference function of radial paracrystal.
const double m_kappa
Definition: SSCAStrategy.h:46
complex_t getCharacteristicSizeCoupling(double qp, const std::vector< std::unique_ptr< const CoherentFFSum >> &ff_wrappers) const
double polarizedCalculation(const DiffuseElement &ele) const override
This is the polarized version.
SSCAStrategy(const std::vector< std::unique_ptr< const CoherentFFSum >> &weighted_formfactors, const InterferenceRadialParaCrystal *iff, SimulationOptions sim_params, bool polarized, double kappa)
complex_t calculatePositionOffsetPhase(double qp, double radial_extension) const
const std::unique_ptr< InterferenceRadialParaCrystal > m_iff
Definition: SSCAStrategy.h:45
const double m_mean_radius
Definition: SSCAStrategy.h:47
double scalarCalculation(const DiffuseElement &ele) const override
Returns the total scattering intensity for given kf and for one particle layout (implied by the given...
Collect the different options for simulation.SimulationOptions.
complex_t trace() const
Definition: SpinMatrix.cpp:165