BornAgain  1.18.0
Simulate and fit neutron and x-ray scattering at grazing incidence
DepthProbeComputationTerm.cpp
Go to the documentation of this file.
1 // ************************************************************************** //
2 //
3 // BornAgain: simulate and fit scattering at grazing incidence
4 //
5 //! @file Core/Computation/DepthProbeComputationTerm.cpp
6 //! @brief Implements functor DepthProbeComputationTerm.
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"
22 
24  : mp_sample{p_sample}
25 {
26 }
27 
29 
31 {
32  mP_progress_counter = std::make_unique<DelayedProgressCounter>(p_progress, 100);
33 }
34 
36 {
37  if (elem.isCalculated()) {
38  const IAxis& z_positions = *elem.getZPositions();
39  const size_t n_z = z_positions.size();
40  const size_t n_layers = mp_sample->numberOfSlices();
41  size_t start_z_ind = n_z;
42  std::valarray<double> intensities(0.0, n_z);
43 
44  double z_layer_bottom(0.0);
45  double z_layer_top(0.0);
46  for (size_t i_layer = 0; i_layer < n_layers && start_z_ind != 0; ++i_layer) {
47  z_layer_bottom = mp_sample->sliceBottomZ(i_layer);
48  z_layer_top = mp_sample->sliceTopZ(i_layer);
49 
50  // get R & T coefficients for current layer
51  const auto p_coefficients = mp_sample->fresnelMap()->getInCoefficients(elem, i_layer);
52  const complex_t R = p_coefficients->getScalarR();
53  const complex_t T = p_coefficients->getScalarT();
54  const complex_t kz_out = p_coefficients->getScalarKz();
55  const complex_t kz_in = -kz_out;
56 
57  // Compute intensity for z's of the layer
58  size_t ip1_z = start_z_ind;
59  for (; ip1_z > 0; --ip1_z) {
60  const size_t i_z = ip1_z - 1;
61  if (i_layer + 1 != n_layers && z_positions[i_z] <= z_layer_bottom)
62  break;
63  const double local_position = z_positions[i_z] - z_layer_top;
64  intensities[i_z] = std::norm(R * exp_I(kz_out * local_position)
65  + T * exp_I(kz_in * local_position));
66  }
67  start_z_ind = ip1_z;
68  }
69  elem.setIntensities(std::move(intensities));
70  }
71  if (mP_progress_counter) {
72  mP_progress_counter->stepProgress();
73  }
74 }
std::complex< double > complex_t
Definition: Complex.h:20
complex_t exp_I(complex_t z)
Returns exp(I*z), where I is the imaginary unit.
Definition: Complex.h:30
Defines class DelayedProgressCounter.
Defines functor DepthProbeComputationTerm.
Defines class DepthProbeElement.
Defines class IAxis.
Defines class IFresnelMap.
Defines and implements class ILayerRTCoefficients.
Defines class ProcessedSample.
DepthProbeComputationTerm(const ProcessedSample *p_sample)
void setProgressHandler(ProgressHandler *p_progress)
std::unique_ptr< DelayedProgressCounter > mP_progress_counter
void compute(DepthProbeElement &elem) const
const ProcessedSample * mp_sample
void setIntensities(T &&intensities)
const IAxis * getZPositions() const
bool isCalculated() const
Interface for one-dimensional axes.
Definition: IAxis.h:25
virtual size_t size() const =0
retrieve the number of bins
std::unique_ptr< const ILayerRTCoefficients > getInCoefficients(const T &sim_element, size_t layer_index) const
Retrieves the amplitude coefficients for an incoming wavevector.
Definition: IFresnelMap.h:41
Data structure that contains all the necessary data for scattering calculations.
double sliceTopZ(size_t i) const
double sliceBottomZ(size_t i) const
const IFresnelMap * fresnelMap() const
size_t numberOfSlices() const
Maintains information about progress of a computation.