BornAgain  1.18.0
Simulate and fit neutron and x-ray scattering at grazing incidence
SpecularComputationTerm.cpp
Go to the documentation of this file.
1 // ************************************************************************** //
2 //
3 // BornAgain: simulate and fit scattering at grazing incidence
4 //
5 //! @file Core/Computation/SpecularComputationTerm.cpp
6 //! @brief Implements functor SpecularComputationTerm.
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 // ************************************************************************** //
21 // class SpecularComputationTerm
22 // ************************************************************************** //
23 
24 SpecularComputationTerm::SpecularComputationTerm(std::unique_ptr<ISpecularStrategy> strategy)
25  : m_Strategy(std::move(strategy)){};
26 
27 SpecularScalarTerm::SpecularScalarTerm(std::unique_ptr<ISpecularStrategy> strategy)
28  : SpecularComputationTerm(std::move(strategy))
29 {
30 }
31 
32 SpecularComputationTerm::~SpecularComputationTerm() = default;
33 
34 void SpecularComputationTerm::setProgressHandler(ProgressHandler* p_progress)
35 {
36  mP_progress_counter = std::make_unique<DelayedProgressCounter>(p_progress, 100);
37 }
38 
39 void SpecularComputationTerm::computeIntensity(SpecularSimulationElement& elem,
40  const std::vector<Slice>& slices) const
41 {
42  if (!elem.isCalculated())
43  return;
44 
45  eval(elem, slices);
46 
47  if (mP_progress_counter)
48  mP_progress_counter->stepProgress();
49 }
50 
51 // ************************************************************************** //
52 // class SpecularScalarTerm
53 // ************************************************************************** //
54 
55 SpecularScalarTerm::~SpecularScalarTerm() = default;
56 
57 void SpecularScalarTerm::eval(SpecularSimulationElement& elem,
58  const std::vector<Slice>& slices) const
59 {
60  const auto coeff = m_Strategy->Execute(slices, elem.produceKz(slices));
61  elem.setIntensity(std::norm(coeff.front()->getScalarR()));
62 }
63 
64 // ************************************************************************** //
65 // class SpecularMatrixTerm
66 // ************************************************************************** //
67 
68 namespace
69 {
70 
71 double matrix_intensity(const SpecularSimulationElement& elem,
72  const std::unique_ptr<const ILayerRTCoefficients>& coeff)
73 {
74  const auto& polarization = elem.polarizationHandler().getPolarization();
75  const auto& analyzer = elem.polarizationHandler().getAnalyzerOperator();
76 
77  const auto R = coeff->getReflectionMatrix();
78 
79  const complex_t result = (polarization * R.adjoint() * analyzer * R).trace();
80 
81  return std::abs(result);
82 }
83 
84 } // namespace
85 
86 SpecularMatrixTerm::SpecularMatrixTerm(std::unique_ptr<ISpecularStrategy> strategy)
87  : SpecularComputationTerm(std::move(strategy))
88 {
89 }
90 
91 SpecularMatrixTerm::~SpecularMatrixTerm() = default;
92 
93 void SpecularMatrixTerm::eval(SpecularSimulationElement& elem,
94  const std::vector<Slice>& slices) const
95 {
96  const auto coeff = m_Strategy->Execute(slices, elem.produceKz(slices));
97  elem.setIntensity(matrix_intensity(elem, coeff.front()));
98 }
Defines class DelayedProgressCounter.
Defines and implements class ILayerRTCoefficients.
Defines classes SpecularComputationTerm, SpecularScalarTerm, SpecularMatrixTerm.
Declares the class SpecularSimulationElement.
Eigen::Matrix2cd getAnalyzerOperator() const
Gets the polarization analyzer operator (in spin basis along z-axis)
Eigen::Matrix2cd getPolarization() const
Gets the polarization density matrix (in spin basis along z-axis)
Maintains information about progress of a computation.
Computes the specular scattering.
Data stucture containing both input and output of a single image pixel for specular simulation.
bool isCalculated() const
Returns calculation flag (if it's false, zero intensity is assigned to the element)
std::vector< complex_t > produceKz(const std::vector< Slice > &slices)
Returns kz values for Abeles computation of reflection/transition coefficients.
const PolarizationHandler & polarizationHandler() const
Returns assigned PolarizationHandler.