BornAgain
1.19.79
Open-source research software to simulate and fit neutron and x-ray reflectometry and grazing-incidence small-angle scattering
|
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.
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 IBackground * | background () 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 ICoordSystem * | createCoordSystem () 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... | |
SimulationOptions & | options () |
const SimulationOptions & | options () const |
virtual std::vector< ParaMeta > | parDefs () const |
Returns the parameter definitions, to be hard-coded in each leaf class. More... | |
const MultiLayer * | sample () 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... | |
ProgressHandler & | progress () |
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< 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. 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< IBackground > | m_background |
std::shared_ptr< SimulationOptions > | m_options |
std::shared_ptr< ProgressHandler > | m_progress |
std::shared_ptr< MultiLayer > | m_sample |
ISimulation::ISimulation | ( | const MultiLayer & | sample | ) |
Definition at line 108 of file ISimulation.cpp.
|
overridedefault |
|
delete |
|
default |
|
privatepure virtual |
Implemented in SpecularSimulation, ISimulation2D, and DepthProbeSimulation.
Referenced by runSingleSimulation().
|
privatepure virtual |
Implemented in SpecularSimulation, ISimulation2D, and DepthProbeSimulation.
Referenced by runSingleSimulation().
void ISimulation::addParameterDistribution | ( | const ParameterDistribution & | par_distr | ) |
Definition at line 231 of file ISimulation.cpp.
References DistributionHandler::addParameterDistribution(), m_distribution_handler, and validateParametrization().
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.
|
inline |
Definition at line 76 of file ISimulation.h.
References m_background.
Referenced by DepthProbeSimulation::addBackgroundIntensity(), ISimulation2D::addBackgroundIntensity(), and SpecularSimulation::addBackgroundIntensity().
|
inherited |
Raises exception if a parameter value is invalid.
Definition at line 27 of file INode.cpp.
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().
|
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().
|
privatepure virtual |
Generate a single threaded computation for a given range of simulation elements.
re_sample | Preprocessed version of our sample |
start | Index of the first element to include into computation |
n_elements | Number of elements to process |
Implemented in SpecularSimulation, ISimulation2D, and DepthProbeSimulation.
Referenced by runSingleSimulation().
|
pure virtual |
Implemented in SpecularSimulation, ScatteringSimulation, OffspecSimulation, and DepthProbeSimulation.
|
pure virtual |
Force polarized computation even in absence of sample magnetization or external fields.
Implemented in SpecularSimulation, ISimulation2D, and DepthProbeSimulation.
Referenced by simulate().
const std::vector< ParameterDistribution > & ISimulation::getDistributions | ( | ) | const |
Definition at line 237 of file ISimulation.cpp.
References DistributionHandler::getDistributions(), and m_distribution_handler.
|
inlineprotectedvirtual |
Reimplemented in ISimulation2D.
Definition at line 106 of file ISimulation.h.
Referenced by simulate().
|
protectedpure virtual |
Initializes the vector of ISimulation elements.
Implemented in SpecularSimulation, ScatteringSimulation, OffspecSimulation, and DepthProbeSimulation.
Referenced by runSingleSimulation().
|
pure virtual |
Returns the total number of the intensity values in the simulation result.
Implemented in SpecularSimulation, ScatteringSimulation, OffspecSimulation, and DepthProbeSimulation.
|
privatepure virtual |
Implemented in SpecularSimulation, ISimulation2D, and DepthProbeSimulation.
Referenced by simulate().
|
overridevirtual |
Returns all children.
Reimplemented from INode.
Reimplemented in ISimulation2D.
Definition at line 201 of file ISimulation.cpp.
References m_sample.
Referenced by ISimulation2D::nodeChildren().
|
inherited |
Returns all descendants.
Definition at line 61 of file INode.cpp.
References INode::nodeChildren().
|
privatepure virtual |
Normalize the detector counts to beam intensity, to solid angle, and to exposure angle.
start_ind | Index of the first element to operate on |
n_elements | Number of elements to process |
Implemented in SpecularSimulation, ISimulation2D, and DepthProbeSimulation.
Referenced by runSingleSimulation().
|
protectedpure virtual |
Gets the number of elements this simulation needs to calculate.
Implemented in SpecularSimulation, OffspecSimulation, ISimulation2D, and DepthProbeSimulation.
Referenced by simulate().
SimulationOptions & ISimulation::options | ( | ) |
const SimulationOptions & ISimulation::options | ( | ) | const |
Definition at line 117 of file ISimulation.cpp.
References ASSERT, and m_options.
Referenced by DepthProbeSimulation::createComputation(), ISimulation2D::createComputation(), SpecularSimulation::createComputation(), and simulate().
|
protectedpure virtual |
Sets m_result.
Implemented in SpecularSimulation, ScatteringSimulation, OffspecSimulation, and DepthProbeSimulation.
Referenced by simulate().
|
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.
Referenced by INode::checkNodeArgs(), and IFormFactor::pythonConstructor().
|
protectedpure virtual |
Put into a clean state for running a simulation.
Implemented in SpecularSimulation, ScatteringSimulation, OffspecSimulation, ISimulation2D, and DepthProbeSimulation.
Referenced by simulate().
|
protected |
Definition at line 129 of file ISimulation.cpp.
References ASSERT, and m_progress.
Referenced by DepthProbeSimulation::createComputation(), ISimulation2D::createComputation(), and SpecularSimulation::createComputation().
|
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.
References addBackgroundIntensity(), addDataToCache(), ASSERT, createComputation(), initElementVector(), m_options, and normalize().
Referenced by simulate().
const MultiLayer * ISimulation::sample | ( | ) | const |
Definition at line 191 of file ISimulation.cpp.
References m_sample.
Referenced by simulate(), and DepthProbeSimulation::validityCheck().
void ISimulation::setBackground | ( | const IBackground & | bg | ) |
Definition at line 196 of file ISimulation.cpp.
References IBackground::clone(), and m_background.
void ISimulation::setTerminalProgressMonitor | ( | ) |
Initializes a progress monitor that prints to stdout.
Definition at line 142 of file ISimulation.cpp.
References m_progress.
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.
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().
void ISimulation::subscribe | ( | const std::function< bool(size_t)> & | inform | ) |
Definition at line 135 of file ISimulation.cpp.
References ASSERT, and m_progress.
std::string ISimulation::unitOfParameter | ( | ParameterDistribution::WhichParameter | which | ) | const |
Definition at line 209 of file ISimulation.cpp.
References ParameterDistribution::BeamAzimuthalAngle, ParameterDistribution::BeamInclinationAngle, and ParameterDistribution::BeamWavelength.
|
inlineprotectedvirtual |
|
inlineprivatevirtual |
Checks the distribution validity for simulation.
Reimplemented in SpecularSimulation, OffspecSimulation, and DepthProbeSimulation.
Definition at line 120 of file ISimulation.h.
Referenced by addParameterDistribution().
|
private |
Definition at line 137 of file ISimulation.h.
Referenced by background(), and setBackground().
|
protected |
Definition at line 104 of file ISimulation.h.
Referenced by addParameterDistribution(), getDistributions(), ISimulation2D::initDistributionHandler(), and simulate().
|
private |
Definition at line 135 of file ISimulation.h.
Referenced by options(), runSingleSimulation(), and simulate().
|
protectedinherited |
Definition at line 63 of file INode.h.
Referenced by IFootprintFactor::IFootprintFactor(), INode::checkNodeArgs(), IProfile1D::pythonConstructor(), IProfile2D::pythonConstructor(), IFormFactor::pythonConstructor(), Profile1DVoigt::pythonConstructor(), and Profile2DVoigt::pythonConstructor().
|
private |
Definition at line 136 of file ISimulation.h.
Referenced by progress(), setTerminalProgressMonitor(), simulate(), and subscribe().
|
private |
Definition at line 133 of file ISimulation.h.
Referenced by nodeChildren(), sample(), and simulate().