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 
33 
35 {
36  mP_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  mP_progress_counter->stepProgress();
49 }
50 
51 // ************************************************************************** //
52 // class SpecularScalarTerm
53 // ************************************************************************** //
54 
56 
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 
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 
92 
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 }
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
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)
std::unique_ptr< DelayedProgressCounter > mP_progress_counter
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.
double matrix_intensity(const SpecularSimulationElement &elem, const std::unique_ptr< const ILayerRTCoefficients > &coeff)