BornAgain  1.18.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 scattering at grazing incidence
4 //
5 //! @file Core/Simulation/GISASSimulation.cpp
6 //! @brief Implements class Simulation.
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 
22 
23 GISASSimulation::GISASSimulation()
24 {
25  initialize();
26 }
27 
29 {
30  if (instrument().getDetectorDimension() != 2)
32  "GISASSimulation::prepareSimulation() "
33  "-> Error. The detector was not properly configured.");
34  instrument().initDetector();
36 }
37 
39 {
40  const auto converter = UnitConverterUtils::createConverterForGISAS(instrument());
41  const std::unique_ptr<OutputData<double>> data(
42  instrument().detector().createDetectorIntensity(m_sim_elements));
43  return SimulationResult(*data, *converter);
44 }
45 
46 void GISASSimulation::setBeamParameters(double wavelength, double alpha_i, double phi_i)
47 {
48  if (wavelength <= 0.0)
50  "Simulation::setBeamParameters() -> Error. Incoming wavelength <= 0.");
51  instrument().setBeamParameters(wavelength, alpha_i, phi_i);
52 }
53 
55 {
56  size_t result = 0;
57  instrument().detector().iterate([&result](IDetector::const_iterator) { ++result; }, true);
58  return result;
59 }
60 
61 GISASSimulation::GISASSimulation(const GISASSimulation& other) : Simulation2D(other)
62 {
63  initialize();
64 }
65 
66 void GISASSimulation::initSimulationElementVector()
67 {
68  auto beam = instrument().getBeam();
69  m_sim_elements = generateSimulationElements(beam);
70  if (m_cache.empty())
71  m_cache.resize(m_sim_elements.size(), 0.0);
72 }
73 
74 void GISASSimulation::initialize()
75 {
76  setName("GISASSimulation");
77 }
Defines class DWBAComputation.
Defines class GISASSimulation.
Defines class Histogram2D.
Defines interface IBackground.
Defines pure virtual base class ISampleBuilder.
Defines class MultiLayer.
Declares utilities for unit converters.
Main class to run a Grazing-Incidence Small-Angle Scattering simulation.
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...
void setBeamParameters(double wavelength, double alpha_i, double phi_i)
Sets the beam wavelength and incoming angles.
Definition: Instrument.cpp:87
void initDetector()
init detector with beam settings
Definition: Instrument.cpp:55
Pure virtual base class of OffSpecularSimulation and GISASSimulation.
Definition: Simulation2D.h:27
std::vector< SimulationElement > generateSimulationElements(const Beam &beam)
Generate simulation elements for given beam.
void prepareSimulation() override
Put into a clean state for running a simulation.
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.