BornAgain  1.19.79
Open-source research software to simulate and fit neutron and x-ray reflectometry and grazing-incidence small-angle scattering
DepthProbeSimulation.h
Go to the documentation of this file.
1 // ************************************************************************************************
2 //
3 // BornAgain: simulate and fit reflection and scattering
4 //
5 //! @file Sim/Simulation/DepthProbeSimulation.h
6 //! @brief Defines class DepthProbeSimulation
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 
15 #ifndef BORNAGAIN_SIM_SIMULATION_DEPTHPROBESIMULATION_H
16 #define BORNAGAIN_SIM_SIMULATION_DEPTHPROBESIMULATION_H
17 
19 #include "Device/Data/Datafield.h"
21 
22 #include <vector>
23 
24 class IAxis;
25 class IComputation;
26 class IFootprintFactor;
27 class ICoordSystem;
28 
29 //! Simulation of radiation depth profile.
30 //!
31 //! Holds an instrument and sample model.
32 //! Computes radiation intensity as function of incoming glancing angle and penetration depth.
33 //! Scattered rays are neglected.
34 //! Only refraction, reflection and attenuation of the incoming beam are accounted for.
35 //! @ingroup simulation
36 
38 public:
41 
42  std::string className() const final { return "DepthProbeSimulation"; }
43 
44  //! Sets beam parameters with alpha_i of the beam defined in the range.
45  void setBeamParameters(double lambda, int nbins, double alpha_i_min, double alpha_i_max,
46  const IFootprintFactor* beam_shape = nullptr);
47 
48  //! Set z positions for intensity calculations. Negative z's correspond to the area
49  //! under sample surface. The more negative z is, the deeper layer corresponds to it.
50  void setZSpan(size_t n_bins, double z_min, double z_max);
51 
52  //! Returns a pointer to incident angle axis.
53  const IAxis* alphaAxis() const;
54 
55  //! Returns a pointer to z-position axis.
56  const IAxis* zAxis() const;
57 
58  //! Returns the total number of the intensity values in the simulation result
59  size_t intensityMapSize() const override;
60 
61  bool force_polarized() const override { return false; }
62 
63 #ifndef SWIG
64  ICoordSystem* createCoordSystem() const override;
65 
66 private:
67  void prepareSimulation() override {}
68 
69  SimulationResult pack_result() override;
70 
71  //! Sets beam parameters with alpha_i of the beam defined in the range.
72  void setBeamParameters(double lambda, const IAxis& alpha_axis,
73  const IFootprintFactor* beam_shape);
74 
75  //! Initializes the vector of ISimulation elements
76  void initElementVector() override;
77 
78  //! Gets the number of elements this simulation needs to calculate
79  size_t numberOfElements() const override;
80 
81  //! Generate simulation elements for given beam
82  std::vector<DepthProbeElement> generateElements(const Beam& beam);
83 
84  //! Generate a single threaded computation for a given range of simulation elements
85  //! @param re_sample Preprocessed version of our sample
86  //! @param start Index of the first element to include into computation
87  //! @param n_elements Number of elements to process
88  std::unique_ptr<IComputation> createComputation(const reSample& re_sample, size_t start,
89  size_t n_elements) override;
90 
91  //! Checks if simulation data is ready for retrieval.
92  void validityCheck() const;
93 
94  void checkCache() const;
95 
96  //! Checks the distribution validity for simulation.
97  void validateParametrization(const ParameterDistribution& par_distr) const override;
98 
99  //! Normalize the detector counts to beam intensity, to solid angle, and to exposure angle.
100  //! @param start_ind Index of the first element to operate on
101  //! @param n_elements Number of elements to process
102  void normalize(size_t start_ind, size_t n_elements) override;
103 
104  void addBackgroundIntensity(size_t start_ind, size_t n_elements) override;
105 
106  void addDataToCache(double weight) override;
107 
108  void moveDataFromCache() override;
109 
110  double incidentAngle(size_t index) const;
111 
112  //! Creates intensity data from simulation elements
113  std::unique_ptr<Datafield> createIntensityData() const;
114 
115  std::unique_ptr<IAxis> m_alpha_axis;
116  std::unique_ptr<IAxis> m_z_axis;
117  std::vector<DepthProbeElement> m_eles;
118  std::vector<std::valarray<double>> m_cache;
119 #endif
120 };
121 
122 #endif // BORNAGAIN_SIM_SIMULATION_DEPTHPROBESIMULATION_H
Defines and implements templated class Datafield.
Defines class DepthProbeElement.
Defines interface ISimulation2D.
An incident neutron or x-ray beam.
Definition: Beam.h:28
Simulation of radiation depth profile.
std::vector< DepthProbeElement > m_eles
bool force_polarized() const override
Force polarized computation even in absence of sample magnetization or external fields.
std::unique_ptr< IAxis > m_z_axis
void setBeamParameters(double lambda, int nbins, double alpha_i_min, double alpha_i_max, const IFootprintFactor *beam_shape=nullptr)
Sets beam parameters with alpha_i of the beam defined in the range.
void moveDataFromCache() override
void addDataToCache(double weight) override
std::string className() const final
Returns the class name, to be hard-coded in each leaf class that inherits from INode.
void setZSpan(size_t n_bins, double z_min, double z_max)
Set z positions for intensity calculations. Negative z's correspond to the area under sample surface....
DepthProbeSimulation(const MultiLayer &sample)
void addBackgroundIntensity(size_t start_ind, size_t n_elements) override
std::unique_ptr< Datafield > createIntensityData() const
Creates intensity data from simulation elements.
~DepthProbeSimulation() override
double incidentAngle(size_t index) const
void initElementVector() override
Initializes the vector of ISimulation elements.
std::vector< DepthProbeElement > generateElements(const Beam &beam)
Generate simulation elements for given beam.
const IAxis * alphaAxis() const
Returns a pointer to incident angle axis.
ICoordSystem * createCoordSystem() const override
std::unique_ptr< IComputation > createComputation(const reSample &re_sample, size_t start, size_t n_elements) override
Generate a single threaded computation for a given range of simulation elements.
void validateParametrization(const ParameterDistribution &par_distr) const override
Checks the distribution validity for simulation.
void validityCheck() const
Checks if simulation data is ready for retrieval.
void normalize(size_t start_ind, size_t n_elements) override
Normalize the detector counts to beam intensity, to solid angle, and to exposure angle.
size_t numberOfElements() const override
Gets the number of elements this simulation needs to calculate.
std::vector< std::valarray< double > > m_cache
std::unique_ptr< IAxis > m_alpha_axis
void prepareSimulation() override
Put into a clean state for running a simulation.
const IAxis * zAxis() const
Returns a pointer to z-position axis.
SimulationResult pack_result() override
Sets m_result.
size_t intensityMapSize() const override
Returns the total number of the intensity values in the simulation result.
Abstract base class for one-dimensional axes.
Definition: IAxis.h:27
Interface for a single-threaded computation with given range of DiffuseElements and ProgressHandler.
Definition: IComputation.h:37
Interface to provide axis translations to different units for simulation output.
Definition: ICoordSystem.h:40
Abstract base for classes that calculate the beam footprint factor.
Abstract base class of simulations that generate 2D patterns.
Definition: ISimulation2D.h:34
Beam & beam()
Definition: ISimulation2D.h:57
const MultiLayer * sample() const
Our sample model: a stack of layers one below the other.
Definition: MultiLayer.h:43
A parametric distribution function, for use with any model parameter.
Wrapper around Datafield that also provides unit conversions.
Data structure that contains all the necessary data for scattering calculations.
Definition: ReSample.h:41