BornAgain  1.19.79
Open-source research software to simulate and fit neutron and x-ray reflectometry and grazing-incidence small-angle scattering
ISimulation Class Referenceabstract

Description

Abstract base class, holds the infrastructure to run a simulation.

Base class of SpecularSimulation, ISimulation2D and DepthProbeSimulation.

Holds an instrument and sample model. Provides the common infrastructure to run a simulation: multithreading, batch processing, averaging over parameter distributions, etc.

Simulations are run, and results returned, by the function ISimulation::simulate().

Definition at line 42 of file ISimulation.h.

Inheritance diagram for ISimulation:
[legend]
Collaboration diagram for ISimulation:
[legend]

Public Member Functions

 ISimulation (const ISimulation &)=delete
 
 ISimulation (const MultiLayer &sample)
 
 ISimulation (ISimulation &&)=default
 
 ~ISimulation () override
 
void addParameterDistribution (const ParameterDistribution &par_distr)
 
void addParameterDistribution (ParameterDistribution::WhichParameter whichParameter, const IDistribution1D &distribution, size_t nbr_samples, double sigma_factor=0.0, const RealLimits &limits=RealLimits())
 
const IBackgroundbackground () const
 
void checkNodeArgs () const
 Raises exception if a parameter value is invalid. More...
 
virtual std::string className () const =0
 Returns the class name, to be hard-coded in each leaf class that inherits from INode. More...
 
virtual ICoordSystemcreateCoordSystem () const =0
 
virtual bool force_polarized () const =0
 Force polarized computation even in absence of sample magnetization or external fields. More...
 
const std::vector< ParameterDistribution > & getDistributions () const
 
virtual size_t intensityMapSize () const =0
 Returns the total number of the intensity values in the simulation result. More...
 
std::vector< const INode * > nodeChildren () const override
 Returns all children. More...
 
std::vector< const INode * > nodeOffspring () const
 Returns all descendants. More...
 
SimulationOptionsoptions ()
 
const SimulationOptionsoptions () const
 
virtual std::vector< ParaMetaparDefs () const
 Returns the parameter definitions, to be hard-coded in each leaf class. More...
 
const MultiLayersample () const
 
void setBackground (const IBackground &bg)
 
void setTerminalProgressMonitor ()
 Initializes a progress monitor that prints to stdout. More...
 
SimulationResult simulate ()
 Run a simulation, and return the result. More...
 
void subscribe (const std::function< bool(size_t)> &inform)
 
std::string unitOfParameter (ParameterDistribution::WhichParameter which) const
 

Protected Member Functions

virtual void initDistributionHandler ()
 
virtual void initElementVector ()=0
 Initializes the vector of ISimulation elements. More...
 
virtual size_t numberOfElements () const =0
 Gets the number of elements this simulation needs to calculate. More...
 
virtual SimulationResult pack_result ()=0
 Sets m_result. More...
 
virtual void prepareSimulation ()=0
 Put into a clean state for running a simulation. More...
 
ProgressHandlerprogress ()
 
virtual void updateIntensityMap ()
 

Protected Attributes

DistributionHandler m_distribution_handler
 
std::vector< double > m_P
 

Private Member Functions

virtual void addBackgroundIntensity (size_t start_ind, size_t n_elements)=0
 
virtual void addDataToCache (double weight)=0
 
virtual std::unique_ptr< IComputationcreateComputation (const reSample &re_sample, size_t start, size_t n_elements)=0
 Generate a single threaded computation for a given range of simulation elements. More...
 
virtual void moveDataFromCache ()=0
 
virtual void normalize (size_t start_ind, size_t n_elements)=0
 Normalize the detector counts to beam intensity, to solid angle, and to exposure angle. More...
 
void runSingleSimulation (const reSample &re_sample, size_t batch_start, size_t batch_size, double weight=1.0)
 Runs a single simulation with fixed parameter values. If desired, the simulation is run in several threads. More...
 
virtual void validateParametrization (const ParameterDistribution &) const
 Checks the distribution validity for simulation. More...
 

Private Attributes

std::shared_ptr< IBackgroundm_background
 
std::shared_ptr< SimulationOptionsm_options
 
std::shared_ptr< ProgressHandlerm_progress
 
std::shared_ptr< MultiLayerm_sample
 

Constructor & Destructor Documentation

◆ ISimulation() [1/3]

ISimulation::ISimulation ( const MultiLayer sample)

Definition at line 108 of file ISimulation.cpp.

109  : m_sample(sample.clone())
110  , m_options(std::make_unique<SimulationOptions>())
111  , m_progress(std::make_unique<ProgressHandler>())
112 {
113 }
std::shared_ptr< MultiLayer > m_sample
Definition: ISimulation.h:133
const MultiLayer * sample() const
std::shared_ptr< SimulationOptions > m_options
Definition: ISimulation.h:135
std::shared_ptr< ProgressHandler > m_progress
Definition: ISimulation.h:136
MultiLayer * clone() const override
Returns a clone of this ISampleNode object.
Definition: MultiLayer.cpp:36

◆ ~ISimulation()

ISimulation::~ISimulation ( )
overridedefault

◆ ISimulation() [2/3]

ISimulation::ISimulation ( const ISimulation )
delete

◆ ISimulation() [3/3]

ISimulation::ISimulation ( ISimulation &&  )
default

Member Function Documentation

◆ addBackgroundIntensity()

virtual void ISimulation::addBackgroundIntensity ( size_t  start_ind,
size_t  n_elements 
)
privatepure virtual

◆ addDataToCache()

virtual void ISimulation::addDataToCache ( double  weight)
privatepure virtual

◆ addParameterDistribution() [1/2]

void ISimulation::addParameterDistribution ( const ParameterDistribution par_distr)

Definition at line 231 of file ISimulation.cpp.

232 {
233  validateParametrization(par_distr);
235 }
void addParameterDistribution(const std::string &param_name, const IDistribution1D &distribution, size_t nbr_samples, double sigma_factor=0.0, const RealLimits &limits=RealLimits())
add a sampled parameter distribution
virtual void validateParametrization(const ParameterDistribution &) const
Checks the distribution validity for simulation.
Definition: ISimulation.h:120
DistributionHandler m_distribution_handler
Definition: ISimulation.h:104

References DistributionHandler::addParameterDistribution(), m_distribution_handler, and validateParametrization().

Here is the call graph for this function:

◆ addParameterDistribution() [2/2]

void ISimulation::addParameterDistribution ( ParameterDistribution::WhichParameter  whichParameter,
const IDistribution1D distribution,
size_t  nbr_samples,
double  sigma_factor = 0.0,
const RealLimits limits = RealLimits() 
)

Definition at line 222 of file ISimulation.cpp.

225 {
226  ParameterDistribution par_distr(whichParameter, distribution, nbr_samples, sigma_factor,
227  limits);
228  addParameterDistribution(par_distr);
229 }
void addParameterDistribution(ParameterDistribution::WhichParameter whichParameter, const IDistribution1D &distribution, size_t nbr_samples, double sigma_factor=0.0, const RealLimits &limits=RealLimits())
A parametric distribution function, for use with any model parameter.

◆ background()

const IBackground* ISimulation::background ( ) const
inline

Definition at line 76 of file ISimulation.h.

76 { return m_background.get(); }
std::shared_ptr< IBackground > m_background
Definition: ISimulation.h:137

References m_background.

Referenced by DepthProbeSimulation::addBackgroundIntensity(), ISimulation2D::addBackgroundIntensity(), and SpecularSimulation::addBackgroundIntensity().

◆ checkNodeArgs()

void INode::checkNodeArgs ( ) const
inherited

Raises exception if a parameter value is invalid.

Definition at line 27 of file INode.cpp.

28 {
29  size_t nP = m_P.size();
30  if (parDefs().size() != nP) {
31  std::cerr << "BUG in class " << className() << std::endl;
32  std::cerr << "#m_P = " << nP << std::endl;
33  std::cerr << "#PDf = " << parDefs().size() << std::endl;
34  for (const ParaMeta& pm : parDefs())
35  std::cerr << " PDf: " << pm.name << std::endl;
36  ASSERT(0);
37  }
38  ASSERT(parDefs().size() == nP);
39  for (size_t i = 0; i < nP; ++i) {
40  const ParaMeta pm = parDefs()[i];
41 
43  if (pm.vMin == -INF) {
44  ASSERT(pm.vMax == +INF);
45  // nothing to do
46  } else if (pm.vMax == +INF) {
47  ASSERT(pm.vMin == 0);
48  limits = RealLimits::nonnegative();
49  } else {
50  limits = RealLimits::limited(pm.vMin, pm.vMax);
51  }
52  limits.check(pm.name, m_P[i]);
53  }
54 }
#define ASSERT(condition)
Definition: Assert.h:45
const double INF
Definition: INode.h:26
virtual std::vector< ParaMeta > parDefs() const
Returns the parameter definitions, to be hard-coded in each leaf class.
Definition: INode.h:51
std::vector< double > m_P
Definition: INode.h:63
virtual std::string className() const =0
Returns the class name, to be hard-coded in each leaf class that inherits from INode.
Limits for a real fit parameter.
Definition: RealLimits.h:24
static RealLimits limitless()
Creates an object without bounds (default)
Definition: RealLimits.cpp:139
void check(const std::string &name, double value) const
Throws if value is outside limits. Parameter 'name' is for exception message.
Definition: RealLimits.cpp:170
static RealLimits nonnegative()
Creates an object which can have only positive values with 0. included.
Definition: RealLimits.cpp:124
static RealLimits limited(double left_bound_value, double right_bound_value)
Creates an object bounded from the left and right.
Definition: RealLimits.cpp:134
Metadata of one model parameter.
Definition: INode.h:29
double vMin
Definition: INode.h:33
double vMax
Definition: INode.h:34
std::string name
Definition: INode.h:30

References ASSERT, RealLimits::check(), INode::className(), INF, RealLimits::limited(), RealLimits::limitless(), INode::m_P, ParaMeta::name, RealLimits::nonnegative(), INode::parDefs(), ParaMeta::vMax, and ParaMeta::vMin.

Referenced by BarGauss::BarGauss(), BarLorentz::BarLorentz(), Bipyramid4::Bipyramid4(), Box::Box(), CantellatedCube::CantellatedCube(), Cone::Cone(), ConstantBackground::ConstantBackground(), CosineRippleBox::CosineRippleBox(), CosineRippleGauss::CosineRippleGauss(), CosineRippleLorentz::CosineRippleLorentz(), Cylinder::Cylinder(), DistributionCosine::DistributionCosine(), DistributionGate::DistributionGate(), DistributionGaussian::DistributionGaussian(), DistributionLogNormal::DistributionLogNormal(), DistributionLorentz::DistributionLorentz(), DistributionTrapezoid::DistributionTrapezoid(), Dodecahedron::Dodecahedron(), EllipsoidalCylinder::EllipsoidalCylinder(), FootprintGauss::FootprintGauss(), FootprintSquare::FootprintSquare(), FuzzySphere::FuzzySphere(), GaussSphere::GaussSphere(), HemiEllipsoid::HemiEllipsoid(), HollowSphere::HollowSphere(), HorizontalCylinder::HorizontalCylinder(), Icosahedron::Icosahedron(), LongBoxGauss::LongBoxGauss(), LongBoxLorentz::LongBoxLorentz(), PlatonicOctahedron::PlatonicOctahedron(), PlatonicTetrahedron::PlatonicTetrahedron(), Prism3::Prism3(), Prism6::Prism6(), Profile1DCauchy::Profile1DCauchy(), Profile1DCosine::Profile1DCosine(), Profile1DGate::Profile1DGate(), Profile1DGauss::Profile1DGauss(), Profile1DTriangle::Profile1DTriangle(), Profile1DVoigt::Profile1DVoigt(), Profile2DCauchy::Profile2DCauchy(), Profile2DCone::Profile2DCone(), Profile2DGate::Profile2DGate(), Profile2DGauss::Profile2DGauss(), Profile2DVoigt::Profile2DVoigt(), Pyramid2::Pyramid2(), Pyramid3::Pyramid3(), Pyramid4::Pyramid4(), Pyramid6::Pyramid6(), RotationEuler::RotationEuler(), RotationX::RotationX(), RotationY::RotationY(), RotationZ::RotationZ(), SawtoothRippleBox::SawtoothRippleBox(), SawtoothRippleGauss::SawtoothRippleGauss(), SawtoothRippleLorentz::SawtoothRippleLorentz(), Sphere::Sphere(), Spheroid::Spheroid(), TruncatedCube::TruncatedCube(), TruncatedSphere::TruncatedSphere(), and TruncatedSpheroid::TruncatedSpheroid().

Here is the call graph for this function:

◆ className()

virtual std::string INode::className ( ) const
pure virtualinherited

Returns the class name, to be hard-coded in each leaf class that inherits from INode.

Implemented in Particle, SphericalDetector, SpecularSimulation, ScatteringSimulation, OffspecSimulation, DepthProbeSimulation, PoissonBackground, ConstantBackground, GaussSphere, FuzzySphere, RotationEuler, RotationZ, RotationY, RotationX, IdentityRotation, ParticleCoreShell, ParticleComposition, MesoCrystal, Crystal, MultiLayer, Layer, Lattice3D, HexagonalLattice2D, SquareLattice2D, BasicLattice2D, LayerRoughness, LayerInterface, TruncatedSpheroid, TruncatedSphere, TruncatedCube, Spheroid, Sphere, SawtoothRippleLorentz, SawtoothRippleGauss, SawtoothRippleBox, Pyramid6, Pyramid4, Pyramid3, Pyramid2, Prism6, Prism3, PlatonicTetrahedron, PlatonicOctahedron, LongBoxLorentz, LongBoxGauss, Icosahedron, HorizontalCylinder, HollowSphere, HemiEllipsoid, EllipsoidalCylinder, Dodecahedron, Cylinder, CosineRippleLorentz, CosineRippleGauss, CosineRippleBox, Cone, CantellatedCube, Box, Bipyramid4, BarLorentz, BarGauss, Profile2DVoigt, Profile2DCone, Profile2DGate, Profile2DGauss, Profile2DCauchy, Profile1DVoigt, Profile1DCosine, Profile1DTriangle, Profile1DGate, Profile1DGauss, Profile1DCauchy, MisesGaussPeakShape, MisesFisherGaussPeakShape, LorentzFisherPeakShape, GaussFisherPeakShape, IsotropicLorentzPeakShape, IsotropicGaussPeakShape, ParticleLayout, InterferenceTwin, InterferenceRadialParaCrystal, InterferenceNone, InterferenceHardDisk, InterferenceFinite3DLattice, InterferenceFinite2DLattice, Interference3DLattice, Interference2DSuperLattice, Interference2DParaCrystal, Interference2DLattice, Interference1DLattice, DistributionTrapezoid, DistributionCosine, DistributionLogNormal, DistributionGaussian, DistributionLorentz, DistributionGate, ResolutionFunction2DGaussian, ConvolutionDetectorResolution, PolFilter, RectangularDetector, FootprintSquare, FootprintGauss, and Beam.

Referenced by INode::checkNodeArgs(), ExemplarySamples::createBasic2DParaCrystalWithFTDis(), IProfile1D::pythonConstructor(), IProfile2D::pythonConstructor(), IFormFactor::pythonConstructor(), and IFormFactor::shapeName().

◆ createComputation()

virtual std::unique_ptr<IComputation> ISimulation::createComputation ( const reSample re_sample,
size_t  start,
size_t  n_elements 
)
privatepure virtual

Generate a single threaded computation for a given range of simulation elements.

Parameters
re_samplePreprocessed version of our sample
startIndex of the first element to include into computation
n_elementsNumber of elements to process

Implemented in SpecularSimulation, ISimulation2D, and DepthProbeSimulation.

Referenced by runSingleSimulation().

◆ createCoordSystem()

virtual ICoordSystem* ISimulation::createCoordSystem ( ) const
pure virtual

◆ force_polarized()

virtual bool ISimulation::force_polarized ( ) const
pure virtual

Force polarized computation even in absence of sample magnetization or external fields.

Implemented in SpecularSimulation, ISimulation2D, and DepthProbeSimulation.

Referenced by simulate().

◆ getDistributions()

const std::vector< ParameterDistribution > & ISimulation::getDistributions ( ) const

Definition at line 237 of file ISimulation.cpp.

238 {
240 }
const std::vector< ParameterDistribution > & getDistributions() const

References DistributionHandler::getDistributions(), and m_distribution_handler.

Here is the call graph for this function:

◆ initDistributionHandler()

virtual void ISimulation::initDistributionHandler ( )
inlineprotectedvirtual

Reimplemented in ISimulation2D.

Definition at line 106 of file ISimulation.h.

106 {}

Referenced by simulate().

◆ initElementVector()

virtual void ISimulation::initElementVector ( )
protectedpure virtual

Initializes the vector of ISimulation elements.

Implemented in SpecularSimulation, ScatteringSimulation, OffspecSimulation, and DepthProbeSimulation.

Referenced by runSingleSimulation().

◆ intensityMapSize()

virtual size_t ISimulation::intensityMapSize ( ) const
pure virtual

Returns the total number of the intensity values in the simulation result.

Implemented in SpecularSimulation, ScatteringSimulation, OffspecSimulation, and DepthProbeSimulation.

◆ moveDataFromCache()

virtual void ISimulation::moveDataFromCache ( )
privatepure virtual

Implemented in SpecularSimulation, ISimulation2D, and DepthProbeSimulation.

Referenced by simulate().

◆ nodeChildren()

std::vector< const INode * > ISimulation::nodeChildren ( ) const
overridevirtual

Returns all children.

Reimplemented from INode.

Reimplemented in ISimulation2D.

Definition at line 201 of file ISimulation.cpp.

202 {
203  std::vector<const INode*> result;
204  if (m_sample)
205  result << m_sample.get();
206  return result;
207 }

References m_sample.

Referenced by ISimulation2D::nodeChildren().

◆ nodeOffspring()

std::vector< const INode * > INode::nodeOffspring ( ) const
inherited

Returns all descendants.

Definition at line 61 of file INode.cpp.

62 {
63  std::vector<const INode*> result;
64  result.push_back(this);
65  for (const auto* child : nodeChildren()) {
66  for (const auto* p : child->nodeOffspring())
67  result.push_back(p);
68  }
69  return result;
70 }
virtual std::vector< const INode * > nodeChildren() const
Returns all children.
Definition: INode.cpp:56

References INode::nodeChildren().

Here is the call graph for this function:

◆ normalize()

virtual void ISimulation::normalize ( size_t  start_ind,
size_t  n_elements 
)
privatepure virtual

Normalize the detector counts to beam intensity, to solid angle, and to exposure angle.

Parameters
start_indIndex of the first element to operate on
n_elementsNumber of elements to process

Implemented in SpecularSimulation, ISimulation2D, and DepthProbeSimulation.

Referenced by runSingleSimulation().

◆ numberOfElements()

virtual size_t ISimulation::numberOfElements ( ) const
protectedpure virtual

Gets the number of elements this simulation needs to calculate.

Implemented in SpecularSimulation, OffspecSimulation, ISimulation2D, and DepthProbeSimulation.

Referenced by simulate().

◆ options() [1/2]

SimulationOptions & ISimulation::options ( )

Definition at line 123 of file ISimulation.cpp.

124 {
125  ASSERT(m_options);
126  return *m_options;
127 }

References ASSERT, and m_options.

◆ options() [2/2]

const SimulationOptions & ISimulation::options ( ) const

◆ pack_result()

virtual SimulationResult ISimulation::pack_result ( )
protectedpure virtual

Sets m_result.

Implemented in SpecularSimulation, ScatteringSimulation, OffspecSimulation, and DepthProbeSimulation.

Referenced by simulate().

◆ parDefs()

virtual std::vector<ParaMeta> INode::parDefs ( ) const
inlinevirtualinherited

Returns the parameter definitions, to be hard-coded in each leaf class.

Reimplemented in ConstantBackground, GaussSphere, FuzzySphere, RotationEuler, RotationZ, RotationY, RotationX, Crystal, Layer, HexagonalLattice2D, SquareLattice2D, BasicLattice2D, LayerRoughness, TruncatedSpheroid, TruncatedSphere, TruncatedCube, Spheroid, Sphere, SawtoothRippleLorentz, SawtoothRippleGauss, SawtoothRippleBox, Pyramid6, Pyramid4, Pyramid3, Pyramid2, Prism6, Prism3, PlatonicTetrahedron, PlatonicOctahedron, LongBoxLorentz, LongBoxGauss, Icosahedron, HorizontalCylinder, HollowSphere, HemiEllipsoid, EllipsoidalCylinder, Dodecahedron, Cylinder, CosineRippleLorentz, CosineRippleGauss, CosineRippleBox, Cone, CantellatedCube, Box, Bipyramid4, BarLorentz, BarGauss, Profile2DVoigt, Profile2DCone, Profile2DGate, Profile2DGauss, Profile2DCauchy, Profile1DVoigt, Profile1DCosine, Profile1DTriangle, Profile1DGate, Profile1DGauss, Profile1DCauchy, MisesGaussPeakShape, MisesFisherGaussPeakShape, LorentzFisherPeakShape, GaussFisherPeakShape, IsotropicLorentzPeakShape, IsotropicGaussPeakShape, ParticleLayout, InterferenceTwin, InterferenceRadialParaCrystal, InterferenceHardDisk, Interference2DSuperLattice, Interference2DParaCrystal, Interference1DLattice, DistributionTrapezoid, DistributionCosine, DistributionLogNormal, DistributionGaussian, DistributionLorentz, DistributionGate, ResolutionFunction2DGaussian, PolFilter, FootprintSquare, and FootprintGauss.

Definition at line 51 of file INode.h.

51 { return {}; }

Referenced by INode::checkNodeArgs(), and IFormFactor::pythonConstructor().

◆ prepareSimulation()

virtual void ISimulation::prepareSimulation ( )
protectedpure virtual

Put into a clean state for running a simulation.

Implemented in SpecularSimulation, ScatteringSimulation, OffspecSimulation, ISimulation2D, and DepthProbeSimulation.

Referenced by simulate().

◆ progress()

ProgressHandler & ISimulation::progress ( )
protected

◆ runSingleSimulation()

void ISimulation::runSingleSimulation ( const reSample re_sample,
size_t  batch_start,
size_t  batch_size,
double  weight = 1.0 
)
private

Runs a single simulation with fixed parameter values. If desired, the simulation is run in several threads.

Definition at line 245 of file ISimulation.cpp.

247 {
249 
250  const size_t n_threads = m_options->getNumberOfThreads();
251  ASSERT(n_threads > 0);
252 
253  std::vector<std::unique_ptr<IComputation>> computations;
254 
255  for (size_t i_thread = 0; i_thread < n_threads; ++i_thread) {
256  const size_t thread_start = batch_start + startIndex(n_threads, i_thread, batch_size);
257  const size_t thread_size = batchSize(n_threads, i_thread, batch_size);
258  if (thread_size == 0)
259  break;
260  computations.emplace_back(createComputation(re_sample, thread_start, thread_size));
261  }
262  runComputations(computations);
263 
264  normalize(batch_start, batch_size);
265  addBackgroundIntensity(batch_start, batch_size);
266  addDataToCache(weight);
267 }
virtual void initElementVector()=0
Initializes the vector of ISimulation elements.
virtual void addDataToCache(double weight)=0
virtual void addBackgroundIntensity(size_t start_ind, size_t n_elements)=0
virtual std::unique_ptr< IComputation > createComputation(const reSample &re_sample, size_t start, size_t n_elements)=0
Generate a single threaded computation for a given range of simulation elements.
virtual void normalize(size_t start_ind, size_t n_elements)=0
Normalize the detector counts to beam intensity, to solid angle, and to exposure angle.

References addBackgroundIntensity(), addDataToCache(), ASSERT, createComputation(), initElementVector(), m_options, and normalize().

Referenced by simulate().

Here is the call graph for this function:

◆ sample()

const MultiLayer * ISimulation::sample ( ) const

Definition at line 191 of file ISimulation.cpp.

192 {
193  return m_sample.get();
194 }

References m_sample.

Referenced by simulate(), and DepthProbeSimulation::validityCheck().

◆ setBackground()

void ISimulation::setBackground ( const IBackground bg)

Definition at line 196 of file ISimulation.cpp.

197 {
198  m_background.reset(bg.clone());
199 }
IBackground * clone() const override=0

References IBackground::clone(), and m_background.

Here is the call graph for this function:

◆ setTerminalProgressMonitor()

void ISimulation::setTerminalProgressMonitor ( )

Initializes a progress monitor that prints to stdout.

Definition at line 142 of file ISimulation.cpp.

143 {
144  m_progress->subscribe([](size_t percentage_done) -> bool {
145  if (percentage_done < 100)
146  std::cout << std::setprecision(2) << "\r... " << percentage_done << "%" << std::flush;
147  else // wipe out
148  std::cout << "\r... 100%\n";
149  return true;
150  });
151 }

References m_progress.

◆ simulate()

SimulationResult ISimulation::simulate ( )

Run a simulation, and return the result.

Runs simulation with possible averaging over parameter distributions; returns result.

Definition at line 154 of file ISimulation.cpp.

155 {
157  throw std::runtime_error("Sample contains incompatible material definitions");
158  gsl_set_error_handler_off();
159 
161 
162  const auto re_sample = reSample::make(*sample(), options(), force_polarized());
163 
164  const size_t total_size = numberOfElements();
165  size_t param_combinations = m_distribution_handler.getTotalNumberOfSamples();
166 
167  m_progress->reset();
168  m_progress->setExpectedNTicks(param_combinations * total_size);
169 
170  // restrict calculation to current batch
171  const size_t n_batches = m_options->getNumberOfBatches();
172  const size_t current_batch = m_options->getCurrentBatch();
173 
174  const size_t batch_start = startIndex(n_batches, current_batch, total_size);
175  const size_t batch_size = batchSize(n_batches, current_batch, total_size);
176  ASSERT(batch_size);
177 
178  if (param_combinations == 1)
179  runSingleSimulation(re_sample, batch_start, batch_size, 1.);
180  else {
182  for (size_t index = 0; index < param_combinations; ++index) {
183  double weight = m_distribution_handler.setParameterValues(index);
184  runSingleSimulation(re_sample, batch_start, batch_size, weight);
185  }
186  }
188  return pack_result();
189 }
double setParameterValues(size_t index)
set the parameter values of the simulation object to a specific combination of values,...
size_t getTotalNumberOfSamples() const
get the total number of parameter value combinations (product of the individual sizes of each paramet...
virtual size_t numberOfElements() const =0
Gets the number of elements this simulation needs to calculate.
virtual void prepareSimulation()=0
Put into a clean state for running a simulation.
virtual SimulationResult pack_result()=0
Sets m_result.
const SimulationOptions & options() const
virtual void moveDataFromCache()=0
void runSingleSimulation(const reSample &re_sample, size_t batch_start, size_t batch_size, double weight=1.0)
Runs a single simulation with fixed parameter values. If desired, the simulation is run in several th...
virtual bool force_polarized() const =0
Force polarized computation even in absence of sample magnetization or external fields.
virtual void initDistributionHandler()
Definition: ISimulation.h:106
static reSample make(const MultiLayer &sample, const SimulationOptions &options, bool forcePolarized=false)
Factory method that wraps the private constructor.
Definition: ReSample.cpp:309
bool ContainsCompatibleMaterials(const MultiLayer &sample)
Returns true if the sample contains non-default materials of one type only.

References ASSERT, SampleUtils::Multilayer::ContainsCompatibleMaterials(), force_polarized(), DistributionHandler::getTotalNumberOfSamples(), initDistributionHandler(), m_distribution_handler, m_options, m_progress, m_sample, reSample::make(), moveDataFromCache(), numberOfElements(), options(), pack_result(), prepareSimulation(), runSingleSimulation(), sample(), and DistributionHandler::setParameterValues().

Here is the call graph for this function:

◆ subscribe()

void ISimulation::subscribe ( const std::function< bool(size_t)> &  inform)

Definition at line 135 of file ISimulation.cpp.

136 {
138  m_progress->subscribe(inform);
139 }

References ASSERT, and m_progress.

◆ unitOfParameter()

std::string ISimulation::unitOfParameter ( ParameterDistribution::WhichParameter  which) const

Definition at line 209 of file ISimulation.cpp.

210 {
211  switch (which) {
213  return "nm";
216  return "rad";
217  default:
218  throw std::runtime_error("ISimulation::unitOfParameter(): missing implementation");
219  }
220 }

References ParameterDistribution::BeamAzimuthalAngle, ParameterDistribution::BeamInclinationAngle, and ParameterDistribution::BeamWavelength.

◆ updateIntensityMap()

virtual void ISimulation::updateIntensityMap ( )
inlineprotectedvirtual

Reimplemented in OffspecSimulation.

Definition at line 97 of file ISimulation.h.

97 {}

◆ validateParametrization()

virtual void ISimulation::validateParametrization ( const ParameterDistribution ) const
inlineprivatevirtual

Checks the distribution validity for simulation.

Reimplemented in SpecularSimulation, OffspecSimulation, and DepthProbeSimulation.

Definition at line 120 of file ISimulation.h.

120 {}

Referenced by addParameterDistribution().

Member Data Documentation

◆ m_background

std::shared_ptr<IBackground> ISimulation::m_background
private

Definition at line 137 of file ISimulation.h.

Referenced by background(), and setBackground().

◆ m_distribution_handler

DistributionHandler ISimulation::m_distribution_handler
protected

◆ m_options

std::shared_ptr<SimulationOptions> ISimulation::m_options
private

Definition at line 135 of file ISimulation.h.

Referenced by options(), runSingleSimulation(), and simulate().

◆ m_P

◆ m_progress

std::shared_ptr<ProgressHandler> ISimulation::m_progress
private

Definition at line 136 of file ISimulation.h.

Referenced by progress(), setTerminalProgressMonitor(), simulate(), and subscribe().

◆ m_sample

std::shared_ptr<MultiLayer> ISimulation::m_sample
private

Definition at line 133 of file ISimulation.h.

Referenced by nodeChildren(), sample(), and simulate().


The documentation for this class was generated from the following files: