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