BornAgain  1.19.79
Open-source research software to simulate and fit neutron and x-ray reflectometry and grazing-incidence small-angle scattering
DepthProbeComputation.cpp
Go to the documentation of this file.
1 // ************************************************************************************************
2 //
3 // BornAgain: simulate and fit reflection and scattering
4 //
5 //! @file Sim/Computation/DepthProbeComputation.cpp
6 //! @brief Implements class DepthProbeComputation.
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 
16 #include "Base/Axis/IAxis.h"
19 #include "Base/Util/Assert.h"
22 
24  const SimulationOptions& options,
25  ProgressHandler& progress,
26  DepthProbeElementIter begin_it,
27  DepthProbeElementIter end_it)
28  : IComputation(re_sample, options, progress)
29  , m_begin_it(begin_it)
30  , m_end_it(end_it)
31 {
32 }
33 
35 
37 {
38  for (auto it = m_begin_it; it != m_end_it; ++it) {
39  DepthProbeElement& ele = *it;
40  if (!ele.isCalculated())
41  continue;
42 
43  const IAxis& z_positions = *ele.getZPositions();
44  const size_t n_z = z_positions.size();
45  const size_t n_layers = m_re_sample.numberOfSlices();
46  size_t start_z_ind = n_z;
47  std::valarray<double> intensities(0.0, n_z);
48 
50 
51  double z_layer_bottom(0.0);
52  double z_layer_top(0.0);
53  for (size_t i_layer = 0; i_layer < n_layers && start_z_ind != 0; ++i_layer) {
54  z_layer_bottom = m_re_sample.sliceBottomZ(i_layer);
55  z_layer_top = i_layer ? m_re_sample.sliceTopZ(i_layer) : 0;
56 
57  // get R & T coefficients for current layer
58  const auto* flux = dynamic_cast<const ScalarFlux*>(fluxes[i_layer].get());
59  ASSERT(flux);
60  const complex_t R = flux->getScalarR();
61  const complex_t T = flux->getScalarT();
62  const complex_t kz_out = flux->getScalarKz();
63  const complex_t kz_in = -kz_out;
64 
65  // Compute intensity for z's of the layer
66  size_t ip1_z = start_z_ind;
67  for (; ip1_z > 0; --ip1_z) {
68  const size_t i_z = ip1_z - 1;
69  if (i_layer + 1 != n_layers && z_positions[i_z] <= z_layer_bottom)
70  break;
71  const double z = z_positions[i_z] - z_layer_top;
72  intensities[i_z] = std::norm(R * exp_I(kz_out * z) + T * exp_I(kz_in * z));
73  }
74  start_z_ind = ip1_z;
75  }
76  ele.setIntensities(std::move(intensities));
77 
78  stepProgress();
79  }
80 }
Defines the macro ASSERT.
#define ASSERT(condition)
Definition: Assert.h:45
Declares class DepthProbeComputation.
Defines class DepthProbeElement.
std::vector< std::unique_ptr< const IFlux > > Fluxes
Defines interface IAxis.
Defines class ProgressHandler.
Defines class reSample.
Defines class ScalarFlux.
std::vector< DepthProbeElement >::iterator DepthProbeElementIter
DepthProbeComputation(const reSample &re_sample, const SimulationOptions &options, ProgressHandler &progress, DepthProbeElementIter begin_it, DepthProbeElementIter end_it)
DepthProbeElementIter m_begin_it
~DepthProbeComputation() override
void runProtected() override
Runs computation. May throw. To be called from run(), which catches exceptions.
DepthProbeElementIter m_end_it
void setIntensities(T &&intensities)
const IAxis * getZPositions() const
bool isCalculated() const
Abstract base class for one-dimensional axes.
Definition: IAxis.h:27
virtual size_t size() const =0
Returns the number of bins.
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
Maintains information about progress of a computation.
Specular reflection and transmission coefficients in a layer in case of scalar interactions between t...
Definition: ScalarFlux.h:29
Collect the different options for simulation.SimulationOptions.
Data structure that contains all the necessary data for scattering calculations.
Definition: ReSample.h:41
size_t numberOfSlices() const
Definition: ReSample.cpp:336
double sliceTopZ(size_t i) const
Definition: ReSample.cpp:356
Fluxes fluxesIn(const R3 &k) const
Definition: ReSample.cpp:384
double sliceBottomZ(size_t i) const
Definition: ReSample.cpp:361
Fluxes fluxes(const SliceStack &slices, const R3 &k, bool forward)
Computes refraction angle reflection/transmission coefficients for given sliced sample and wavevector...
constexpr Double_t R()
Definition: TMath.h:213