BornAgain  1.19.0
Simulate and fit neutron and x-ray scattering at grazing incidence
GISASSimulation.cpp
Go to the documentation of this file.
1 // ************************************************************************************************
2 //
3 // BornAgain: simulate and fit reflection and scattering
4 //
5 //! @file Core/Simulation/GISASSimulation.cpp
6 //! @brief Implements interface ISimulation.
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 
18 
20  const IDetector& detector)
21  : ISimulation2D(beam, sample, detector)
22 {
23  initialize();
24 }
25 
26 #ifndef SWIG
27 GISASSimulation::GISASSimulation(const Beam& beam, const IDetector& detector)
28  : ISimulation2D(beam, detector)
29 {
30  initialize();
31 }
32 #endif // SWIG
33 
35 {
36  initialize();
37 }
38 
40 {
41  initialize();
42 }
43 
45 {
46  setName("GISASSimulation");
47 }
48 
50 {
51  if (detector().dimension() != 2)
52  throw std::runtime_error("GISASSimulation::prepareSimulation() "
53  "-> Error. The detector was not properly configured.");
56 }
57 
59 {
61  const std::unique_ptr<OutputData<double>> data(
62  detector().createDetectorIntensity(m_sim_elements));
63  return SimulationResult(*data, *converter);
64 }
65 
66 void GISASSimulation::setBeamParameters(double wavelength, double alpha_i, double phi_i)
67 {
68  if (wavelength <= 0.0)
69  throw std::runtime_error(
70  "ISimulation::setBeamParameters() -> Error. Incoming wavelength <= 0.");
71  instrument().setBeamParameters(wavelength, alpha_i, phi_i);
72 }
73 
75 {
76  size_t result = 0;
78  return result;
79 }
80 
82 {
84  if (m_cache.empty())
85  m_cache.resize(m_sim_elements.size(), 0.0);
86 }
Defines class GISASSimulation.
Defines interface ISampleBuilder.
Declares utilities for unit converters.
An incident neutron or x-ray beam.
Definition: Beam.h:27
Main class to run a Grazing-Incidence Small-Angle Scattering simulation.
void initSimulationElementVector() override
Initializes the vector of ISimulation elements.
void setBeamParameters(double wavelength, double alpha_i, double phi_i)
Sets beam parameters from here (forwarded to Instrument)
size_t intensityMapSize() const override
Returns the total number of the intensity values in the simulation result.
void prepareSimulation() override
Put into a clean state for running a simulation.
SimulationResult result() const override
Returns the results of the simulation in a format that supports unit conversion and export to numpy a...
Abstract detector interface.
Definition: IDetector.h:36
void iterate(std::function< void(const_iterator)> func, bool visit_masks=false) const
Definition: IDetector.cpp:197
void setName(const std::string &name)
Abstract base class of OffSpecularSimulation and GISASSimulation.
Definition: ISimulation2D.h:27
std::vector< SimulationElement > generateSimulationElements(const Beam &beam)
Generate simulation elements for given beam.
std::vector< SimulationElement > m_sim_elements
Definition: ISimulation2D.h:98
void prepareSimulation() override
Put into a clean state for running a simulation.
std::vector< double > m_cache
Definition: ISimulation2D.h:99
const Instrument & instrument() const
Definition: ISimulation.h:55
IDetector & detector()
Definition: ISimulation.h:63
Beam & beam()
Definition: ISimulation.h:58
void setBeamParameters(double wavelength, double alpha_i, double phi_i)
Sets the beam wavelength and incoming angles.
Definition: Instrument.cpp:76
void initDetector()
init detector with beam settings
Definition: Instrument.cpp:59
Our sample model: a stack of layers one below the other.
Definition: MultiLayer.h:41
An iterator for SimulationArea.
Wrapper around OutputData<double> that also provides unit conversions.
std::unique_ptr< IUnitConverter > createConverterForGISAS(const Instrument &instrument)
Helper factory function to use in GISASSimulation.