BornAgain  1.19.79
Open-source research software to simulate and fit neutron and x-ray reflectometry and grazing-incidence small-angle scattering
SpecularComputation.cpp
Go to the documentation of this file.
1 // ************************************************************************************************
2 //
3 // BornAgain: simulate and fit reflection and scattering
4 //
5 //! @file Sim/Computation/SpecularComputation.cpp
6 //! @brief Implements class SpecularComputation.
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 
18 #include "Resample/Flux/IFlux.h"
22 
24  const SimulationOptions& options,
25  ProgressHandler& progress, SpecularElementIter begin_it,
26  SpecularElementIter end_it)
27  : IComputation(std::move(re_sample), options, progress)
28  , m_begin_it(begin_it)
29  , m_end_it(end_it)
30 {
31 }
32 
34 
36 {
37  const SliceStack& slices = m_re_sample.averageSlices();
38 
39  for (auto it = m_begin_it; it != m_end_it; ++it) {
40  SpecularElement& ele = *it;
41  if (!ele.isCalculated())
42  continue;
43  std::vector<complex_t> kz_stack = ele.produceKz(slices);
44  if (m_re_sample.polarizing()) {
45  const SpinMatrix R = Compute::SpecularMagnetic::topLayerR(slices, kz_stack, true);
46 
47  const auto& polMatrix = ele.polMatrices().polarizerMatrix();
48  const auto& anaMatrix = ele.polMatrices().analyzerMatrix();
49 
50  const complex_t trace = (polMatrix * R.adjoint() * anaMatrix * R).trace();
51 
52  ele.setIntensity(std::abs(trace));
53  } else {
54  const complex_t R = Compute::SpecularScalar::topLayerR(slices, kz_stack);
55  ele.setIntensity(std::norm(R));
56  }
57 
58  stepProgress();
59  }
60 }
Defines namespace Compute::SpecularMagnetic.
Defines namespace Compute::SpecularScalar.
Defines and implements class IFlux.
Defines class ProgressHandler.
Defines class reSample.
Defines class SpecularComputation.
Declares the class SpecularElement.
Interface for a single-threaded computation with given range of DiffuseElements and ProgressHandler.
Definition: IComputation.h:37
const reSample & m_re_sample
Definition: IComputation.h:53
void stepProgress() const
const PolMatrices & polMatrices() const
Returns polarizer and analyzer matrices.
Definition: IElement.h:37
const SpinMatrix & polarizerMatrix() const
Gets the polarization density matrix (in spin basis along z-axis)
Definition: PolMatrices.h:38
const SpinMatrix & analyzerMatrix() const
Gets the polarization analyzer operator (in spin basis along z-axis)
Definition: PolMatrices.h:44
Maintains information about progress of a computation.
Collect the different options for simulation.SimulationOptions.
A stack of Slices.
Definition: SliceStack.h:38
SpecularComputation(const reSample &re_sample, const SimulationOptions &options, ProgressHandler &progress, SpecularElementIter begin_it, SpecularElementIter end_it)
std::vector< SpecularElement >::iterator SpecularElementIter
void runProtected() override
Runs computation. May throw. To be called from run(), which catches exceptions.
const SpecularElementIter m_begin_it
these iterators define the span of detector bins this simulation will work on
const SpecularElementIter m_end_it
~SpecularComputation() 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)
void setIntensity(double intensity)
std::vector< complex_t > produceKz(const SliceStack &slices)
Returns kz values for Abeles computation of reflection/transition coefficients.
Data structure that contains all the necessary data for scattering calculations.
Definition: ReSample.h:41
bool polarizing() const
Contains magnetic material, or nonzero magnetic field.
Definition: ReSample.cpp:371
const SliceStack & averageSlices() const
Definition: ReSample.cpp:341
SpinMatrix topLayerR(const SliceStack &slices, const std::vector< complex_t > &kzs, bool forward)
Computes the Fresnel R coefficient for the top layer only Introduced in order to speed up pure reflec...
complex_t topLayerR(const SliceStack &slices, const std::vector< complex_t > &kz)
Computes the Fresnel R coefficient for the top layer only. Introduced in order to speed up pure refle...
constexpr Double_t R()
Definition: TMath.h:213