BornAgain  1.19.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 reflection and scattering
4 //
5 //! @file Core/Term/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 
33 
35 {
36  m_progress_counter = std::make_unique<DelayedProgressCounter>(p_progress, 100);
37 }
38 
40  const std::vector<Slice>& slices) const
41 {
42  if (!elem.isCalculated())
43  return;
44 
45  eval(elem, slices);
46 
48  m_progress_counter->stepProgress();
49 }
50 
51 // ************************************************************************************************
52 // class SpecularScalarTerm
53 // ************************************************************************************************
54 
56 
58  const std::vector<Slice>& slices) const
59 {
60  const auto coeff =
61  std::get<complex_t>(m_Strategy->computeTopLayerR(slices, elem.produceKz(slices)));
62  elem.setIntensity(std::norm(coeff));
63 }
64 
65 // ************************************************************************************************
66 // class SpecularMatrixTerm
67 // ************************************************************************************************
68 
69 namespace {
70 
71 double matrix_intensity(const SpecularSimulationElement& elem, const Eigen::Matrix2cd& R)
72 {
73  const auto& polarization = elem.polarizationHandler().getPolarization();
74  const auto& analyzer = elem.polarizationHandler().getAnalyzerOperator();
75 
76  const complex_t result = (polarization * R.adjoint() * analyzer * R).trace();
77 
78  return std::abs(result);
79 }
80 
81 } // namespace
82 
83 SpecularMatrixTerm::SpecularMatrixTerm(std::unique_ptr<ISpecularStrategy> strategy)
84  : SpecularComputationTerm(std::move(strategy))
85 {
86 }
87 
89 
91  const std::vector<Slice>& slices) const
92 {
93  const auto coeff =
94  std::get<Eigen::Matrix2cd>(m_Strategy->computeTopLayerR(slices, elem.produceKz(slices)));
95  elem.setIntensity(matrix_intensity(elem, coeff));
96 }
std::complex< double > complex_t
Definition: Complex.h:20
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.
std::unique_ptr< ISpecularStrategy > m_Strategy
std::unique_ptr< DelayedProgressCounter > m_progress_counter
virtual void eval(SpecularSimulationElement &elem, const std::vector< Slice > &slices) const =0
void setProgressHandler(ProgressHandler *p_progress)
virtual ~SpecularComputationTerm()
void computeIntensity(SpecularSimulationElement &elem, const std::vector< Slice > &slices) const
SpecularComputationTerm(std::unique_ptr< ISpecularStrategy > strategy)
void eval(SpecularSimulationElement &elem, const std::vector< Slice > &slices) const override
~SpecularMatrixTerm() override
SpecularMatrixTerm(std::unique_ptr< ISpecularStrategy > strategy)
SpecularScalarTerm(std::unique_ptr< ISpecularStrategy > strategy)
void eval(SpecularSimulationElement &elem, const std::vector< Slice > &slices) const override
~SpecularScalarTerm() override
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.
void setIntensity(double intensity)
const PolarizationHandler & polarizationHandler() const
Returns assigned PolarizationHandler.
Definition: filesystem.h:81