BornAgain  1.18.0
Simulate and fit neutron and x-ray scattering at grazing incidence
SpecularSimulation.h
Go to the documentation of this file.
1 // ************************************************************************** //
2 //
3 // BornAgain: simulate and fit scattering at grazing incidence
4 //
5 //! @file Core/Simulation/SpecularSimulation.h
6 //! @brief Defines class SpecularSimulation.
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_CORE_SIMULATION_SPECULARSIMULATION_H
16 #define BORNAGAIN_CORE_SIMULATION_SPECULARSIMULATION_H
17 
19 
20 class IAxis;
21 class IComputation;
22 class IFootprintFactor;
23 class ISampleBuilder;
24 class ISample;
25 class ISpecularScan;
26 class MultiLayer;
28 
29 //! Main class to run a specular simulation.
30 //! @ingroup simulation
31 
33 {
34 public:
36  ~SpecularSimulation() override;
37 
38  SpecularSimulation* clone() const override;
39 
40  //! Put into a clean state for running a simulation.
41  void prepareSimulation() override;
42 
43  void accept(INodeVisitor* visitor) const override final { visitor->visit(this); }
44 
45  //! Returns the results of the simulation in a format that supports unit conversion and export
46  //! to numpy arrays. If simulation was not run, returns an array of proper size filled with
47  //! zeros.
48  SimulationResult result() const override;
49 
50  //! Sets chosen specular scan to the simulation.
51  void setScan(const ISpecularScan& scan);
52 
53  //! Returns a pointer to coordinate axis.
54  const IAxis* coordinateAxis() const;
55 
56  //! Returns a pointer to footprint factor holder
57  const IFootprintFactor* footprintFactor() const;
58 
59  //! Returns the total number of the intensity values in the simulation result
60  size_t intensityMapSize() const override;
61 
62 #ifndef SWIG
63  //! Returns internal data handler
64  const ISpecularScan* dataHandler() const { return m_scan.get(); }
65 #endif // SWIG
66 
67 private:
68  SpecularSimulation(const SpecularSimulation& other); // used by clone()
69 
70  //! Initializes the vector of Simulation elements
71  void initSimulationElementVector() override;
72 
73  //! Generate a single threaded computation for a given range of simulation elements
74  //! @param start Index of the first element to include into computation
75  //! @param n_elements Number of elements to process
76  std::unique_ptr<IComputation> generateSingleThreadedComputation(size_t start,
77  size_t n_elements) override;
78 
79  void checkCache() const;
80 
81  //! Checks the distribution validity for simulation.
82  void validateParametrization(const ParameterDistribution& par_distr) const override;
83 
84  //! Initializes simulation
85  void initialize();
86 
87  //! Normalize the detector counts to beam intensity, to solid angle, and to exposure angle.
88  //! @param start_ind Index of the first element to operate on
89  //! @param n_elements Number of elements to process
90  void normalize(size_t start_ind, size_t n_elements) override;
91 
92  void addBackgroundIntensity(size_t start_ind, size_t n_elements) override;
93 
94  void addDataToCache(double weight) override;
95 
96  void moveDataFromCache() override;
97 
98  //! Gets the number of elements this simulation needs to calculate
99  size_t numberOfSimulationElements() const override;
100 
101  std::vector<double> rawResults() const override;
102  void setRawResults(const std::vector<double>& raw_data) override;
103 
104  std::unique_ptr<ISpecularScan> m_scan;
105  std::vector<SpecularSimulationElement> m_sim_elements;
106  std::vector<double> m_cache;
107 };
108 
109 #endif // BORNAGAIN_CORE_SIMULATION_SPECULARSIMULATION_H
Defines class Simulation.
Interface for one-dimensional axes.
Definition: IAxis.h:25
Interface for a single-threaded computation with given range of SimulationElements and ProgressHandle...
Definition: IComputation.h:35
Abstract base for classes that calculate the beam footprint factor.
Visitor interface to visit ISample objects.
Definition: INodeVisitor.h:149
Interface to the class capable to build samples to simulate.
Pure virtual base class for sample components and properties related to scattering.
Definition: ISample.h:28
Pure virtual base class for all types of specular scans.
Definition: ISpecularScan.h:31
Our sample model: a stack of layers one below the other.
Definition: MultiLayer.h:42
A parametric distribution function, for use with any model parameter.
Wrapper around OutputData<double> that also provides unit conversions.
Pure virtual base class of OffSpecularSimulation, GISASSimulation and SpecularSimulation.
Definition: Simulation.h:38
Data stucture containing both input and output of a single image pixel for specular simulation.
Main class to run a specular simulation.
std::vector< double > rawResults() const override
const IAxis * coordinateAxis() const
Returns a pointer to coordinate axis.
void accept(INodeVisitor *visitor) const override final
Calls the INodeVisitor's visit method.
void initialize()
Initializes simulation.
SimulationResult result() const override
Returns the results of the simulation in a format that supports unit conversion and export to numpy a...
void setRawResults(const std::vector< double > &raw_data) override
SpecularSimulation * clone() const override
std::vector< double > m_cache
void addDataToCache(double weight) override
std::vector< SpecularSimulationElement > m_sim_elements
size_t intensityMapSize() const override
Returns the total number of the intensity values in the simulation result.
std::unique_ptr< ISpecularScan > m_scan
~SpecularSimulation() override
void initSimulationElementVector() override
Initializes the vector of Simulation elements.
void setScan(const ISpecularScan &scan)
Sets chosen specular scan to the simulation.
void addBackgroundIntensity(size_t start_ind, size_t n_elements) override
void prepareSimulation() override
Put into a clean state for running a simulation.
size_t numberOfSimulationElements() const override
Gets the number of elements this simulation needs to calculate.
void moveDataFromCache() override
void validateParametrization(const ParameterDistribution &par_distr) const override
Checks the distribution validity for simulation.
const IFootprintFactor * footprintFactor() const
Returns a pointer to footprint factor holder.
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.
const ISpecularScan * dataHandler() const
Returns internal data handler.
std::unique_ptr< IComputation > generateSingleThreadedComputation(size_t start, size_t n_elements) override
Generate a single threaded computation for a given range of simulation elements.