BornAgain  1.19.79
Open-source research software to simulate and fit neutron and x-ray reflectometry and grazing-incidence small-angle scattering
ScatteringSimulation.cpp
Go to the documentation of this file.
1 // ************************************************************************************************
2 //
3 // BornAgain: simulate and fit reflection and scattering
4 //
5 //! @file Sim/Simulation/ScatteringSimulation.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 
16 #include "Base/Axis/IAxis.h"
17 #include "Base/Util/Assert.h"
19 #include "Device/Data/Datafield.h"
23 
25  const IDetector& detector)
26  : ISimulation2D(beam, sample, detector)
27 {
28 }
29 
31 {
32  if (detector().rank() != 2)
33  throw std::runtime_error("ScatteringSimulation::prepareSimulation() "
34  "-> Error. The detector was not properly configured.");
36 }
37 
39 {
40  auto* const coordsys = createCoordSystem();
41  const std::unique_ptr<Datafield> data(detector().createDetectorIntensity(m_eles));
42  return {*data, *coordsys};
43 }
44 
46 {
47  // #baROI this can be heavily improved by using regionOfInterest directly??!
48  size_t result = 0;
50  return result;
51 }
52 
53 #ifndef SWIG
55 {
56  auto* const det2D = dynamic_cast<const IDetector*>(getDetector());
57  ASSERT(det2D);
58  return det2D->scatteringCoords(beam());
59 }
60 #endif
61 
63 {
65  if (m_cache.empty())
66  m_cache.resize(m_eles.size(), 0.0);
67 }
Defines the macro ASSERT.
#define ASSERT(condition)
Definition: Assert.h:45
Defines interface CoordSystem2D and its subclasses.
Defines and implements templated class Datafield.
Defines class DiffuseElement.
Defines interface IAxis.
Defines common detector interface.
Defines class ScatteringSimulation.
Defines class SimulationResult.
An incident neutron or x-ray beam.
Definition: Beam.h:28
Interface to provide axis translations to different units for simulation output.
Definition: ICoordSystem.h:40
Abstract detector interface.
Definition: IDetector.h:57
void iterateOverRegionOfInterest(std::function< void(const_iterator)> func) const
Iterate over all points within "region of interest", no matter whether they are masked or not....
Definition: IDetector.cpp:243
Abstract base class of simulations that generate 2D patterns.
Definition: ISimulation2D.h:34
IDetector & detector()
Definition: ISimulation2D.h:58
std::vector< std::unique_ptr< DiffuseElement > > generateElements(const Beam &beam)
Generate simulation elements for given beam.
Beam & beam()
Definition: ISimulation2D.h:57
void prepareSimulation() override
Put into a clean state for running a simulation.
std::vector< double > m_cache
std::vector< std::unique_ptr< DiffuseElement > > m_eles
const IDetector * getDetector() const
Definition: ISimulation2D.h:64
Our sample model: a stack of layers one below the other.
Definition: MultiLayer.h:43
ICoordSystem * createCoordSystem() const override
ScatteringSimulation(const Beam &beam, const MultiLayer &sample, const IDetector &detector)
void initElementVector() override
Initializes the vector of ISimulation elements.
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 pack_result() override
Sets m_result.
An iterator for SimulationArea.
Wrapper around Datafield that also provides unit conversions.