BornAgain  1.19.0
Simulate and fit neutron and x-ray scattering at grazing incidence
SpecularSimulation Class Reference

Main class to run a specular simulation. More...

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

Public Member Functions

 SpecularSimulation ()
 
 ~SpecularSimulation () override
 
void accept (INodeVisitor *visitor) const final
 Calls the INodeVisitor's visit method. More...
 
void addParameterDistribution (const ParameterDistribution &par_distr)
 
void addParameterDistribution (const std::string &param_name, const IDistribution1D &distribution, size_t nbr_samples, double sigma_factor=0.0, const RealLimits &limits=RealLimits())
 
const IBackgroundbackground () const
 
Beambeam ()
 
const Beambeam () const
 
SpecularSimulationclone () const override
 
SimulationResult convertData (const OutputData< double > &data, bool put_masked_areas_to_zero=true)
 Convert user data to SimulationResult object for later drawing in various axes units. More...
 
const IAxiscoordinateAxis () const
 Returns a pointer to coordinate axis. More...
 
int copyNumber (const INode *node) const
 Returns copyNumber of child, which takes into account existence of children with same name. More...
 
ParameterPoolcreateParameterTree () const
 Creates new parameter pool, with all local parameters and those of its children. More...
 
const ISpecularScandataHandler () const
 Returns internal data handler. More...
 
IDetectordetector ()
 
const IDetectordetector () const
 
std::string displayName () const
 Returns display name, composed from the name of node and it's copy number. More...
 
const IFootprintFactorfootprintFactor () const
 Returns a pointer to footprint factor holder. More...
 
std::vector< const INode * > getChildren () const
 Returns a vector of children. More...
 
IDetectorgetDetector ()
 
const IDetectorgetDetector () const
 
const DistributionHandlergetDistributionHandler () const
 
const std::string & getName () const
 
SimulationOptionsgetOptions ()
 
const SimulationOptionsgetOptions () const
 
Instrumentinstrument ()
 
const Instrumentinstrument () const
 
size_t intensityMapSize () const override
 Returns the total number of the intensity values in the simulation result. More...
 
virtual void onChange ()
 Action to be taken in inherited class when a parameter has changed. More...
 
RealParameterparameter (const std::string &name) const
 Returns parameter with given 'name'. More...
 
ParameterPoolparameterPool () const
 Returns pointer to the parameter pool. More...
 
std::string parametersToString () const
 Returns multiline string representing available parameters. More...
 
INodeparent ()
 
const INodeparent () const
 
void prepareSimulation () override
 Put into a clean state for running a simulation. More...
 
std::vector< const INode * > progeny () const
 Returns a vector of all descendants. More...
 
void registerChild (INode *node)
 
RealParameterregisterParameter (const std::string &name, double *parpointer)
 
void registerVector (const std::string &base_name, kvector_t *p_vec, const std::string &units="nm")
 
void removeParameter (const std::string &name)
 
void removeVector (const std::string &base_name)
 
SimulationResult result () const override
 Returns the results of the simulation in a format that supports unit conversion and export to numpy arrays. More...
 
void runMPISimulation ()
 Run a simulation in a MPI environment. More...
 
void runSimulation ()
 Run a simulation, possibly averaged over parameter distributions. More...
 
const MultiLayersample () const
 
void setBackground (const IBackground &bg)
 
void setDetectorResolutionFunction (const IResolutionFunction2D &resolution_function)
 
void setInstrument (const Instrument &instrument_)
 
void setName (const std::string &name)
 
void setOptions (const SimulationOptions &options)
 
void setParameterValue (const std::string &name, double value)
 
virtual void setParent (const INode *newParent)
 
void setSample (const MultiLayer &sample)
 The MultiLayer object will not be owned by the ISimulation object. More...
 
void setSampleBuilder (const std::shared_ptr< ISampleBuilder > &sample_builder)
 
void setScan (const ISpecularScan &scan)
 Sets chosen specular scan to the simulation. More...
 
void setTerminalProgressMonitor ()
 Initializes a progress monitor that prints to stdout. More...
 
void setVectorValue (const std::string &base_name, kvector_t value)
 
void subscribe (ProgressHandler::Callback_t inform)
 
virtual void transferToCPP ()
 Used for Python overriding of clone (see swig/tweaks.py) More...
 
virtual std::string treeToString () const
 Returns multiline string representing tree structure below the node. More...
 

Static Public Member Functions

static std::string XComponentName (const std::string &base_name)
 
static std::string YComponentName (const std::string &base_name)
 
static std::string ZComponentName (const std::string &base_name)
 

Protected Member Functions

const SimulationOptionsoptions () const
 
ProgressHandlerprogress ()
 
virtual void transferResultsToIntensityMap ()
 Creates the appropriate data structure (e.g. More...
 
virtual void updateIntensityMap ()
 

Protected Attributes

const size_t m_NP
 
std::vector< double > m_P
 

Private Member Functions

 SpecularSimulation (const SpecularSimulation &other)
 
void addBackgroundIntensity (size_t start_ind, size_t n_elements) override
 
void addDataToCache (double weight) override
 
void checkCache () const
 
std::unique_ptr< IComputationgenerateSingleThreadedComputation (size_t start, size_t n_elements) override
 Generate a single threaded computation for a given range of simulation elements. More...
 
void initialize ()
 Initializes simulation. More...
 
void initSimulationElementVector () override
 Initializes the vector of ISimulation elements. More...
 
void moveDataFromCache () override
 
void normalize (size_t start_ind, size_t n_elements) override
 Normalize the detector counts to beam intensity, to solid angle, and to exposure angle. More...
 
size_t numberOfSimulationElements () const override
 Gets the number of elements this simulation needs to calculate. More...
 
std::vector< double > rawResults () const override
 
void runSingleSimulation (size_t batch_start, size_t batch_size, double weight=1.0)
 Runs a single simulation with fixed parameter values. More...
 
void setRawResults (const std::vector< double > &raw_data) override
 
void validateParametrization (const ParameterDistribution &par_distr) const override
 Checks the distribution validity for simulation. More...
 

Private Attributes

std::unique_ptr< IBackgroundm_background
 
std::vector< double > m_cache
 
DistributionHandler m_distribution_handler
 
Instrument m_instrument
 
std::string m_name
 
SimulationOptions m_options
 
const INodem_parent {nullptr}
 
std::unique_ptr< ParameterPoolm_pool
 parameter pool (kind of pointer-to-implementation) More...
 
ProgressHandler m_progress
 
SampleProvider m_sample_provider
 
std::unique_ptr< ISpecularScanm_scan
 
std::vector< SpecularSimulationElementm_sim_elements
 

Detailed Description

Main class to run a specular simulation.

Definition at line 32 of file SpecularSimulation.h.

Constructor & Destructor Documentation

◆ SpecularSimulation() [1/2]

SpecularSimulation::SpecularSimulation ( )

Definition at line 61 of file SpecularSimulation.cpp.

61  : ISimulation()
62 {
63  initialize();
66 }
const Instrument & instrument() const
Definition: ISimulation.h:55
IDetector & detector()
Definition: ISimulation.h:63
void setDetector(const IDetector &detector)
Sets the detector (axes can be overwritten later)
Definition: Instrument.cpp:52
1D detector for specular simulations.
void initialize()
Initializes simulation.

References ISimulation::detector(), initialize(), ISimulation::instrument(), and Instrument::setDetector().

Referenced by clone().

Here is the call graph for this function:

◆ ~SpecularSimulation()

SpecularSimulation::~SpecularSimulation ( )
overridedefault

◆ SpecularSimulation() [2/2]

SpecularSimulation::SpecularSimulation ( const SpecularSimulation other)
private

Definition at line 68 of file SpecularSimulation.cpp.

69  : ISimulation(other)
70  , m_scan(other.m_scan ? other.m_scan->clone() : nullptr)
72  , m_cache(other.m_cache)
73 {
74  initialize();
75 }
std::vector< double > m_cache
std::vector< SpecularSimulationElement > m_sim_elements
std::unique_ptr< ISpecularScan > m_scan

References initialize().

Here is the call graph for this function:

Member Function Documentation

◆ accept()

void SpecularSimulation::accept ( INodeVisitor visitor) const
inlinefinalvirtual

Calls the INodeVisitor's visit method.

Implements INode.

Definition at line 42 of file SpecularSimulation.h.

42 { visitor->visit(this); }
virtual void visit(const BasicLattice2D *)
Definition: INodeVisitor.h:151

◆ addBackgroundIntensity()

void SpecularSimulation::addBackgroundIntensity ( size_t  start_ind,
size_t  n_elements 
)
overrideprivatevirtual

Implements ISimulation.

Definition at line 225 of file SpecularSimulation.cpp.

226 {
227  if (!background())
228  return;
229  for (size_t i = start_ind, stop_point = start_ind + n_elements; i < stop_point; ++i) {
230  auto& element = m_sim_elements[i];
231  element.setIntensity(background()->addBackground(element.intensity()));
232  }
233 }
const IBackground * background() const
Definition: ISimulation.h:74

References ISimulation::background(), and m_sim_elements.

Here is the call graph for this function:

◆ addDataToCache()

void SpecularSimulation::addDataToCache ( double  weight)
overrideprivatevirtual

Implements ISimulation.

Definition at line 235 of file SpecularSimulation.cpp.

236 {
237  checkCache();
238  for (size_t i = 0, size = m_sim_elements.size(); i < size; ++i)
239  m_cache[i] += m_sim_elements[i].intensity() * weight;
240 }

References checkCache(), m_cache, and m_sim_elements.

Here is the call graph for this function:

◆ addParameterDistribution() [1/2]

void ISimulation::addParameterDistribution ( const ParameterDistribution par_distr)
inherited

Definition at line 272 of file ISimulation.cpp.

273 {
274  validateParametrization(par_distr);
276 }
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:139
DistributionHandler m_distribution_handler
Definition: ISimulation.h:159

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

Here is the call graph for this function:

◆ addParameterDistribution() [2/2]

void ISimulation::addParameterDistribution ( const std::string &  param_name,
const IDistribution1D distribution,
size_t  nbr_samples,
double  sigma_factor = 0.0,
const RealLimits limits = RealLimits() 
)
inherited

Definition at line 264 of file ISimulation.cpp.

267 {
268  ParameterDistribution par_distr(param_name, distribution, nbr_samples, sigma_factor, limits);
269  addParameterDistribution(par_distr);
270 }
void addParameterDistribution(const std::string &param_name, 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.

Referenced by StandardSimulations::MiniGISASBeamDivergence(), and TransformToDomain::setBeamDistribution().

◆ background()

const IBackground* ISimulation::background ( ) const
inlineinherited

◆ beam() [1/2]

◆ beam() [2/2]

const Beam& ISimulation::beam ( ) const
inlineinherited

Definition at line 59 of file ISimulation.h.

59 { return m_instrument.beam(); }

References Instrument::beam(), and ISimulation::m_instrument.

Here is the call graph for this function:

◆ checkCache()

void SpecularSimulation::checkCache ( ) const
private

Definition at line 174 of file SpecularSimulation.cpp.

175 {
176  if (m_sim_elements.size() != m_cache.size())
177  throw std::runtime_error("Error in SpecularSimulation: the sizes of simulation element "
178  "vector and of its cache are different");
179 }

References m_cache, and m_sim_elements.

Referenced by addDataToCache(), and moveDataFromCache().

◆ clone()

SpecularSimulation * SpecularSimulation::clone ( ) const
overridevirtual

Implements ISimulation.

Definition at line 79 of file SpecularSimulation.cpp.

80 {
81  return new SpecularSimulation(*this);
82 }

References SpecularSimulation().

Here is the call graph for this function:

◆ convertData()

SimulationResult ISimulation::convertData ( const OutputData< double > &  data,
bool  put_masked_areas_to_zero = true 
)
inherited

Convert user data to SimulationResult object for later drawing in various axes units.

User data will be cropped to the ROI defined in the simulation, amplitudes in areas corresponding to the masked areas of the detector will be set to zero.

Definition at line 308 of file ISimulation.cpp.

310 {
311  auto converter = UnitConverterUtils::createConverter(*this);
312  auto roi_data = UnitConverterUtils::createOutputData(*converter, converter->defaultUnits());
313 
314  if (roi_data->hasSameDimensions(data)) {
315  // data is already cropped to ROI
316  if (put_masked_areas_to_zero) {
317  detector().iterate(
318  [&](IDetector::const_iterator it) {
319  (*roi_data)[it.roiIndex()] = data[it.roiIndex()];
320  },
321  /*visit_masked*/ false);
322  } else {
323  roi_data->setRawDataVector(data.getRawDataVector());
324  }
325 
326  } else if (detHasSameDimensions(detector(), data)) {
327  // exp data has same shape as the detector, we have to put orig data to smaller roi map
328  detector().iterate(
329  [&](IDetector::const_iterator it) {
330  (*roi_data)[it.roiIndex()] = data[it.detectorIndex()];
331  },
332  /*visit_masked*/ !put_masked_areas_to_zero);
333 
334  } else {
335  throw std::runtime_error("FitObject::init_dataset() -> Error. Detector and exp data have "
336  "different shape.");
337  }
338 
339  return SimulationResult(*roi_data, *converter);
340 }
void iterate(std::function< void(const_iterator)> func, bool visit_masks=false) const
Definition: IDetector.cpp:197
std::vector< T > getRawDataVector() const
Returns copy of raw data vector.
Definition: OutputData.h:334
An iterator for SimulationArea.
Wrapper around OutputData<double> that also provides unit conversions.
std::unique_ptr< IUnitConverter > createConverter(const ISimulation &simulation)
std::unique_ptr< OutputData< double > > createOutputData(const IUnitConverter &converter, Axes::Units units)
Returns zero-valued output data array in specified units.

References UnitConverterUtils::createConverter(), UnitConverterUtils::createOutputData(), ISimulation::detector(), SimulationAreaIterator::detectorIndex(), OutputData< T >::getRawDataVector(), IDetector::iterate(), and SimulationAreaIterator::roiIndex().

Here is the call graph for this function:

◆ coordinateAxis()

const IAxis * SpecularSimulation::coordinateAxis ( ) const

Returns a pointer to coordinate axis.

Definition at line 134 of file SpecularSimulation.cpp.

135 {
136  if (!m_scan || !m_scan->coordinateAxis())
137  throw std::runtime_error(
138  "Error in SpecularSimulation::getAlphaAxis: coordinate axis was not initialized.");
139  return m_scan->coordinateAxis();
140 }

References m_scan.

Referenced by result(), and TransformFromDomain::setSpecularBeamItem().

◆ copyNumber()

int INode::copyNumber ( const INode node) const
inherited

Returns copyNumber of child, which takes into account existence of children with same name.

Definition at line 94 of file INode.cpp.

95 {
96  if (node->parent() != this)
97  return -1;
98 
99  int result(-1), count(0);
100  for (auto child : getChildren()) {
101 
102  if (child == nullptr)
103  throw std::runtime_error("INode::copyNumber() -> Error. Nullptr as child.");
104 
105  if (child == node)
106  result = count;
107 
108  if (child->getName() == node->getName())
109  ++count;
110  }
111 
112  return count > 1 ? result : -1;
113 }
const INode * parent() const
Definition: INode.cpp:84
virtual std::vector< const INode * > getChildren() const
Returns a vector of children.
Definition: INode.cpp:63
const std::string & getName() const

References INode::getChildren(), IParametricComponent::getName(), and INode::parent().

Referenced by INode::displayName().

Here is the call graph for this function:

◆ createParameterTree()

ParameterPool * INode::createParameterTree ( ) const
virtualinherited

Creates new parameter pool, with all local parameters and those of its children.

Reimplemented from IParametricComponent.

Definition at line 126 of file INode.cpp.

127 {
128  std::unique_ptr<ParameterPool> result(new ParameterPool);
129 
130  for (const INode* child : progeny()) {
131  const std::string path = NodeUtils::nodePath(child, parent()) + "/";
132  child->parameterPool()->copyToExternalPool(path, result.get());
133  }
134 
135  return result.release();
136 }
Base class for tree-like structures containing parameterized objects.
Definition: INode.h:49
std::vector< const INode * > progeny() const
Returns a vector of all descendants.
Definition: INode.cpp:68
Container with parameters for IParametricComponent object.
Definition: ParameterPool.h:29
std::string nodePath(const INode *node, const INode *root=nullptr)
Returns path composed of node's displayName, with respect to root node.
Definition: NodeUtils.cpp:89

References NodeUtils::nodePath(), INode::parent(), and INode::progeny().

Referenced by ISimulation::runSimulation(), DepthProbeSimulation::validateParametrization(), OffSpecularSimulation::validateParametrization(), and validateParametrization().

Here is the call graph for this function:

◆ dataHandler()

const ISpecularScan* SpecularSimulation::dataHandler ( ) const
inline

Returns internal data handler.

Definition at line 63 of file SpecularSimulation.h.

63 { return m_scan.get(); }

References m_scan.

Referenced by TransformFromDomain::setSpecularBeamItem().

◆ detector() [1/2]

◆ detector() [2/2]

const IDetector& ISimulation::detector ( ) const
inlineinherited

Definition at line 64 of file ISimulation.h.

64 { return m_instrument.detector(); }

References Instrument::detector(), and ISimulation::m_instrument.

Here is the call graph for this function:

◆ displayName()

std::string INode::displayName ( ) const
inherited

Returns display name, composed from the name of node and it's copy number.

Definition at line 115 of file INode.cpp.

116 {
117  std::string result = getName();
118  if (m_parent) {
119  int index = m_parent->copyNumber(this);
120  if (index >= 0)
121  result = result + std::to_string(index);
122  }
123  return result;
124 }
const INode * m_parent
Definition: INode.h:83
int copyNumber(const INode *node) const
Returns copyNumber of child, which takes into account existence of children with same name.
Definition: INode.cpp:94

References INode::copyNumber(), IParametricComponent::getName(), and INode::m_parent.

Referenced by NodeUtils::nodePath().

Here is the call graph for this function:

◆ footprintFactor()

const IFootprintFactor * SpecularSimulation::footprintFactor ( ) const

Returns a pointer to footprint factor holder.

Definition at line 142 of file SpecularSimulation.cpp.

143 {
144  return m_scan->footprintFactor();
145 }

References m_scan.

Referenced by TransformFromDomain::setSpecularBeamItem().

◆ generateSingleThreadedComputation()

std::unique_ptr< IComputation > SpecularSimulation::generateSingleThreadedComputation ( size_t  start,
size_t  n_elements 
)
overrideprivatevirtual

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

Parameters
startIndex of the first element to include into computation
n_elementsNumber of elements to process

Implements ISimulation.

Definition at line 164 of file SpecularSimulation.cpp.

165 {
166  ASSERT(start < m_sim_elements.size() && start + n_elements <= m_sim_elements.size());
167  const auto& begin = m_sim_elements.begin() + static_cast<long>(start);
168  const auto polarized =
170  return std::make_unique<SpecularComputation>(*sample(), options(), progress(), begin,
171  begin + static_cast<long>(n_elements), polarized);
172 }
#define ASSERT(condition)
Definition: Assert.h:31
kvector_t analyzerDirection() const
Retrieve the analyzer characteristics.
const DetectionProperties & detectionProperties() const
Returns detection properties.
Definition: IDetector.h:82
const MultiLayer * sample() const
ProgressHandler & progress()
Definition: ISimulation.h:125
const SimulationOptions & options() const
Definition: ISimulation.h:124
matrixFFVector_t polarized(const SimulationElement &sim_element, const std::vector< FormFactorCoherentSum > &ff_wrappers)

References DetectionProperties::analyzerDirection(), ASSERT, IDetector::detectionProperties(), ISimulation::detector(), m_sim_elements, ISimulation::options(), FormFactorPrecompute::polarized(), ISimulation::progress(), and ISimulation::sample().

Here is the call graph for this function:

◆ getChildren()

std::vector< const INode * > ISimulation::getChildren ( ) const
virtualinherited

Returns a vector of children.

Reimplemented from INode.

Definition at line 254 of file ISimulation.cpp.

255 {
256  std::vector<const INode*> result;
257  result.push_back(&instrument());
259  if (m_background)
260  result.push_back(m_background.get());
261  return result;
262 }
SampleProvider m_sample_provider
Definition: ISimulation.h:158
virtual SimulationResult result() const =0
Returns the results of the simulation in a format that supports unit conversion and export to numpy a...
std::vector< const INode * > getChildren() const override
Returns a vector of children.

References SampleProvider::getChildren(), ISimulation::instrument(), ISimulation::m_background, ISimulation::m_sample_provider, and ISimulation::result().

Here is the call graph for this function:

◆ getDetector() [1/2]

IDetector* ISimulation::getDetector ( )
inlineinherited

Definition at line 61 of file ISimulation.h.

61 { return m_instrument.getDetector(); }
IDetector * getDetector()
Definition: Instrument.cpp:96

References Instrument::getDetector(), and ISimulation::m_instrument.

Referenced by ISimulation2D::detector2D(), TransformFromDomain::setDetector(), and TransformFromDomain::setDetectorMasks().

Here is the call graph for this function:

◆ getDetector() [2/2]

const IDetector* ISimulation::getDetector ( ) const
inlineinherited

Definition at line 62 of file ISimulation.h.

62 { return m_instrument.getDetector(); }

References Instrument::getDetector(), and ISimulation::m_instrument.

Here is the call graph for this function:

◆ getDistributionHandler()

const DistributionHandler& ISimulation::getDistributionHandler ( ) const
inlineinherited

Definition at line 88 of file ISimulation.h.

88 { return m_distribution_handler; }

References ISimulation::m_distribution_handler.

Referenced by TransformFromDomain::setGISASBeamItem().

◆ getName()

◆ getOptions() [1/2]

SimulationOptions& ISimulation::getOptions ( )
inlineinherited

Definition at line 92 of file ISimulation.h.

92 { return m_options; }
SimulationOptions m_options
Definition: ISimulation.h:156

References ISimulation::m_options.

◆ getOptions() [2/2]

◆ initialize()

void SpecularSimulation::initialize ( )
private

Initializes simulation.

Definition at line 196 of file SpecularSimulation.cpp.

197 {
198  setName("SpecularSimulation");
199 
200  // allow for negative inclinations in the beam of specular simulation
201  // it is required for proper averaging in the case of divergent beam
202  instrument()
203  .beam()
204  .parameter("InclinationAngle")
206 }
#define M_PI_2
Definition: Constants.h:45
RealParameter * parameter(const std::string &name) const
Returns parameter with given 'name'.
void setName(const std::string &name)
static RealLimits limited(double left_bound_value, double right_bound_value)
Creates an object bounded from the left and right.
Definition: RealLimits.cpp:125
RealParameter & setLimits(const RealLimits &limits)

References Instrument::beam(), ISimulation::instrument(), RealLimits::limited(), M_PI_2, IParametricComponent::parameter(), RealParameter::setLimits(), and IParametricComponent::setName().

Referenced by SpecularSimulation().

Here is the call graph for this function:

◆ initSimulationElementVector()

void SpecularSimulation::initSimulationElementVector ( )
overrideprivatevirtual

Initializes the vector of ISimulation elements.

Implements ISimulation.

Definition at line 152 of file SpecularSimulation.cpp.

153 {
154  if (!m_scan)
155  throw std::runtime_error("Error in SpecularSimulation: beam parameters were not set.");
156  m_sim_elements = generateSimulationElements(instrument(), *m_scan);
157 
158  if (!m_cache.empty())
159  return;
160  m_cache.resize(m_sim_elements.size(), 0);
161 }

References ISimulation::instrument(), m_cache, m_scan, and m_sim_elements.

Referenced by setRawResults().

Here is the call graph for this function:

◆ instrument() [1/2]

Instrument& ISimulation::instrument ( )
inlineinherited

Definition at line 56 of file ISimulation.h.

56 { return m_instrument; }

References ISimulation::m_instrument.

◆ instrument() [2/2]

◆ intensityMapSize()

size_t SpecularSimulation::intensityMapSize ( ) const
overridevirtual

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

Implements ISimulation.

Definition at line 147 of file SpecularSimulation.cpp.

148 {
149  return m_scan->coordinateAxis()->size();
150 }

References m_scan.

◆ moveDataFromCache()

void SpecularSimulation::moveDataFromCache ( )
overrideprivatevirtual

Implements ISimulation.

Definition at line 242 of file SpecularSimulation.cpp.

243 {
244  checkCache();
245  for (size_t i = 0, size = m_sim_elements.size(); i < size; ++i)
246  m_sim_elements[i].setIntensity(m_cache[i]);
247  m_cache.clear();
248  m_cache.shrink_to_fit();
249 }

References checkCache(), m_cache, and m_sim_elements.

Here is the call graph for this function:

◆ normalize()

void SpecularSimulation::normalize ( size_t  start_ind,
size_t  n_elements 
)
overrideprivatevirtual

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

Implements ISimulation.

Definition at line 208 of file SpecularSimulation.cpp.

209 {
210  const double beam_intensity = beam().intensity();
211 
212  std::vector<double> footprints;
213  // TODO: use just m_scan when pointwise resolution is implemented
214  if (const auto* aScan = dynamic_cast<const AngularSpecScan*>(m_scan.get()))
215  footprints = mangledScan(*aScan, beam())->footprint(start_ind, n_elements);
216  else
217  footprints = m_scan->footprint(start_ind, n_elements);
218 
219  for (size_t i = start_ind, k = 0; i < start_ind + n_elements; ++i, ++k) {
220  auto& element = m_sim_elements[i];
221  element.setIntensity(element.intensity() * beam_intensity * footprints[k]);
222  }
223 }
Scan type with inclination angles as coordinate values and a unique wavelength.
double intensity() const
Returns the beam intensity in neutrons/sec.
Definition: Beam.h:42
Beam & beam()
Definition: ISimulation.h:58

References ISimulation::beam(), Beam::intensity(), m_scan, and m_sim_elements.

Here is the call graph for this function:

◆ numberOfSimulationElements()

size_t SpecularSimulation::numberOfSimulationElements ( ) const
overrideprivatevirtual

Gets the number of elements this simulation needs to calculate.

Implements ISimulation.

Definition at line 93 of file SpecularSimulation.cpp.

94 {
95  return m_scan->numberOfSimulationElements();
96 }

References m_scan.

◆ onChange()

◆ options()

◆ parameter()

RealParameter * IParametricComponent::parameter ( const std::string &  name) const
inherited

Returns parameter with given 'name'.

Definition at line 86 of file IParametricComponent.cpp.

87 {
88  return m_pool->parameter(name);
89 }
std::unique_ptr< ParameterPool > m_pool
parameter pool (kind of pointer-to-implementation)
QString const & name(EShape k)
Definition: particles.cpp:21

References IParametricComponent::m_pool, and RealSpace::Particles::name().

Referenced by DepthProbeSimulation::initialize(), initialize(), Lattice3D::initialize(), IParticle::registerAbundance(), ParticleLayout::registerParticleDensity(), IParticle::registerPosition(), Layer::registerThickness(), Lattice2D::setRotationEnabled(), and DistributionLogNormal::setUnits().

Here is the call graph for this function:

◆ parameterPool()

ParameterPool* IParametricComponent::parameterPool ( ) const
inlineinherited

Returns pointer to the parameter pool.

Definition at line 39 of file IParametricComponent.h.

39 { return m_pool.get(); } // has non-const usages!

References IParametricComponent::m_pool.

Referenced by INode::INode(), IParametricComponent::IParametricComponent(), pyfmt2::argumentList(), SampleBuilderNode::borrow_builder_parameters(), SampleBuilderNode::reset(), and IDistribution1D::setUnits().

◆ parametersToString()

std::string IParametricComponent::parametersToString ( ) const
inherited

Returns multiline string representing available parameters.

Definition at line 43 of file IParametricComponent.cpp.

44 {
45  std::ostringstream result;
46  std::unique_ptr<ParameterPool> P_pool(createParameterTree());
47  result << *P_pool << "\n";
48  return result.str();
49 }
virtual ParameterPool * createParameterTree() const
Creates new parameter pool, with all local parameters and those of its children.

References IParametricComponent::createParameterTree().

Here is the call graph for this function:

◆ parent() [1/2]

INode * INode::parent ( )
inherited

Definition at line 89 of file INode.cpp.

90 {
91  return const_cast<INode*>(m_parent);
92 }

References INode::m_parent.

◆ parent() [2/2]

◆ prepareSimulation()

void SpecularSimulation::prepareSimulation ( )
overridevirtual

Put into a clean state for running a simulation.

Reimplemented from ISimulation.

Definition at line 84 of file SpecularSimulation.cpp.

85 {
86  if (detector().dimension() != 1) // detector must have only one axis
87  throw std::runtime_error("Error in SpecularSimulation::prepareSimulation: the detector was "
88  "not properly configured.");
91 }
virtual void prepareSimulation()
Put into a clean state for running a simulation.
void initDetector()
init detector with beam settings
Definition: Instrument.cpp:59

References ISimulation::detector(), Instrument::initDetector(), ISimulation::instrument(), and ISimulation::prepareSimulation().

Here is the call graph for this function:

◆ progeny()

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

Returns a vector of all descendants.

Definition at line 68 of file INode.cpp.

69 {
70  std::vector<const INode*> result;
71  result.push_back(this);
72  for (const auto* child : getChildren()) {
73  for (const auto* p : child->progeny())
74  result.push_back(p);
75  }
76  return result;
77 }

References INode::getChildren().

Referenced by INode::createParameterTree(), and ParticleDistribution::generateParticles().

Here is the call graph for this function:

◆ progress()

ProgressHandler& ISimulation::progress ( )
inlineprotectedinherited

◆ rawResults()

std::vector< double > SpecularSimulation::rawResults ( ) const
overrideprivatevirtual

Implements ISimulation.

Definition at line 251 of file SpecularSimulation.cpp.

252 {
253  std::vector<double> result;
254  result.resize(m_sim_elements.size());
255  for (unsigned i = 0; i < m_sim_elements.size(); ++i)
256  result[i] = m_sim_elements[i].intensity();
257  return result;
258 }
SimulationResult result() const override
Returns the results of the simulation in a format that supports unit conversion and export to numpy a...

References m_sim_elements, and result().

Here is the call graph for this function:

◆ registerChild()

void INode::registerChild ( INode node)
inherited

Definition at line 57 of file INode.cpp.

58 {
59  ASSERT(node);
60  node->setParent(this);
61 }
virtual void setParent(const INode *newParent)
Definition: INode.cpp:79

References ASSERT, and INode::setParent().

Referenced by Beam::Beam(), Crystal::Crystal(), IDetector::IDetector(), Instrument::Instrument(), InterferenceFunction2DLattice::InterferenceFunction2DLattice(), InterferenceFunction2DParaCrystal::InterferenceFunction2DParaCrystal(), InterferenceFunction2DSuperLattice::InterferenceFunction2DSuperLattice(), InterferenceFunctionFinite2DLattice::InterferenceFunctionFinite2DLattice(), Particle::Particle(), ParticleDistribution::ParticleDistribution(), ParticleLayout::addAndRegisterAbstractParticle(), ParticleCoreShell::addAndRegisterCore(), MultiLayer::addAndRegisterInterface(), MultiLayer::addAndRegisterLayer(), ParticleCoreShell::addAndRegisterShell(), Layer::addLayout(), ParticleComposition::addParticlePointer(), ISimulation::initialize(), MesoCrystal::initialize(), Beam::operator=(), Instrument::operator=(), IParticle::rotate(), ParticleLayout::setAndRegisterInterferenceFunction(), ISimulation::setBackground(), InterferenceFunction1DLattice::setDecayFunction(), InterferenceFunction2DLattice::setDecayFunction(), Instrument::setDetector(), IDetector::setDetectorResolution(), Beam::setFootprintFactor(), Particle::setFormFactor(), InterferenceFunctionFinite3DLattice::setLattice(), InterferenceFunctionRadialParaCrystal::setProbabilityDistribution(), InterferenceFunction2DParaCrystal::setProbabilityDistributions(), ConvolutionDetectorResolution::setResolutionFunction(), IParticle::setRotation(), LayerInterface::setRoughness(), and InterferenceFunction2DSuperLattice::setSubstructureIFF().

Here is the call graph for this function:

◆ registerParameter()

RealParameter & IParametricComponent::registerParameter ( const std::string &  name,
double *  parpointer 
)
inherited

Definition at line 51 of file IParametricComponent.cpp.

52 {
53  return m_pool->addParameter(
54  new RealParameter(name, data, getName(), [&]() -> void { onChange(); }));
55 }
virtual void onChange()
Action to be taken in inherited class when a parameter has changed.
Wraps a parameter of type double.
Definition: RealParameter.h:31

References IParametricComponent::getName(), IParametricComponent::m_pool, RealSpace::Particles::name(), and IParametricComponent::onChange().

Referenced by BasicLattice2D::BasicLattice2D(), Beam::Beam(), CylindersInBABuilder::CylindersInBABuilder(), DetectionProperties::DetectionProperties(), HexagonalLattice2D::HexagonalLattice2D(), IInterferenceFunction::IInterferenceFunction(), INode::INode(), InterferenceFunction1DLattice::InterferenceFunction1DLattice(), InterferenceFunction2DParaCrystal::InterferenceFunction2DParaCrystal(), InterferenceFunctionHardDisk::InterferenceFunctionHardDisk(), InterferenceFunctionRadialParaCrystal::InterferenceFunctionRadialParaCrystal(), InterferenceFunctionTwin::InterferenceFunctionTwin(), Lattice2D::Lattice2D(), LayerRoughness::LayerRoughness(), MultiLayer::MultiLayer(), ParticleDistribution::ParticleDistribution(), PlainMultiLayerBySLDBuilder::PlainMultiLayerBySLDBuilder(), ResolutionFunction2DGaussian::ResolutionFunction2DGaussian(), ResonatorBuilder::ResonatorBuilder(), SquareLattice2D::SquareLattice2D(), TriangularRippleBuilder::TriangularRippleBuilder(), IParticle::registerAbundance(), ParticleLayout::registerParticleDensity(), Layer::registerThickness(), IParametricComponent::registerVector(), ParticleLayout::registerWeight(), and Lattice2D::setRotationEnabled().

Here is the call graph for this function:

◆ registerVector()

void IParametricComponent::registerVector ( const std::string &  base_name,
kvector_t p_vec,
const std::string &  units = "nm" 
)
inherited

Definition at line 57 of file IParametricComponent.cpp.

59 {
60  registerParameter(XComponentName(base_name), &((*p_vec)[0])).setUnit(units);
61  registerParameter(YComponentName(base_name), &((*p_vec)[1])).setUnit(units);
62  registerParameter(ZComponentName(base_name), &((*p_vec)[2])).setUnit(units);
63 }
static std::string XComponentName(const std::string &base_name)
static std::string ZComponentName(const std::string &base_name)
RealParameter & registerParameter(const std::string &name, double *parpointer)
static std::string YComponentName(const std::string &base_name)
RealParameter & setUnit(const std::string &name)
MVVM_MODEL_EXPORT std::string base_name(const std::string &path)
Provide the filename of a file path.
Definition: fileutils.cpp:78

References ModelView::Utils::base_name(), IParametricComponent::registerParameter(), RealParameter::setUnit(), IParametricComponent::XComponentName(), IParametricComponent::YComponentName(), and IParametricComponent::ZComponentName().

Referenced by Beam::Beam(), DetectionProperties::DetectionProperties(), InterferenceFunctionTwin::InterferenceFunctionTwin(), MultiLayer::MultiLayer(), Lattice3D::initialize(), and IParticle::registerPosition().

Here is the call graph for this function:

◆ removeParameter()

void IParametricComponent::removeParameter ( const std::string &  name)
inherited

Definition at line 91 of file IParametricComponent.cpp.

92 {
93  m_pool->removeParameter(name);
94 }

References IParametricComponent::m_pool, and RealSpace::Particles::name().

Referenced by IParticle::registerAbundance(), ParticleLayout::registerParticleDensity(), Layer::registerThickness(), IParametricComponent::removeVector(), and Lattice2D::setRotationEnabled().

Here is the call graph for this function:

◆ removeVector()

void IParametricComponent::removeVector ( const std::string &  base_name)
inherited

Definition at line 96 of file IParametricComponent.cpp.

References ModelView::Utils::base_name(), IParametricComponent::removeParameter(), IParametricComponent::XComponentName(), IParametricComponent::YComponentName(), and IParametricComponent::ZComponentName().

Referenced by IParticle::registerPosition().

Here is the call graph for this function:

◆ result()

SimulationResult SpecularSimulation::result ( ) const
overridevirtual

Returns the results of the simulation in a format that supports unit conversion and export to numpy arrays.

If simulation was not run, returns an array of proper size filled with zeros.

Implements ISimulation.

Definition at line 98 of file SpecularSimulation.cpp.

99 {
100  OutputData<double> data;
101  data.addAxis(*coordinateAxis());
102 
103  if (!m_sim_elements.empty())
104  data.setRawDataVector(m_scan->createIntensities(m_sim_elements));
105  else
106  data.setAllTo(0.0);
107 
108  auto converter = UnitConverter1D::createUnitConverter(*m_scan);
109  return SimulationResult(data, *converter);
110 }
void setAllTo(const T &value)
Sets content of output data to specific value.
Definition: OutputData.h:476
void addAxis(const IAxis &new_axis)
Definition: OutputData.h:295
void setRawDataVector(const std::vector< T > &data_vector)
Sets new values to raw data vector.
Definition: OutputData.h:556
const IAxis * coordinateAxis() const
Returns a pointer to coordinate axis.
static std::unique_ptr< UnitConverter1D > createUnitConverter(const ISpecularScan &handler)
Factory function to create unit converter for particular type of specular data.

References OutputData< T >::addAxis(), coordinateAxis(), UnitConverter1D::createUnitConverter(), m_scan, m_sim_elements, OutputData< T >::setAllTo(), and OutputData< T >::setRawDataVector().

Referenced by rawResults().

Here is the call graph for this function:

◆ runMPISimulation()

void ISimulation::runMPISimulation ( )
inherited

Run a simulation in a MPI environment.

Definition at line 226 of file ISimulation.cpp.

227 {
228  MPISimulation ompi;
229  ompi.runSimulation(this);
230 }
void runSimulation(ISimulation *simulation)

References MPISimulation::runSimulation().

Here is the call graph for this function:

◆ runSimulation()

void ISimulation::runSimulation ( )
inherited

Run a simulation, possibly averaged over parameter distributions.

Run simulation with possible averaging over parameter distributions.

Definition at line 193 of file ISimulation.cpp.

194 {
196 
197  const size_t total_size = numberOfSimulationElements();
198  size_t param_combinations = m_distribution_handler.getTotalNumberOfSamples();
199 
200  m_progress.reset();
201  m_progress.setExpectedNTicks(param_combinations * total_size);
202 
203  // restrict calculation to current batch
204  const size_t n_batches = m_options.getNumberOfBatches();
205  const size_t current_batch = m_options.getCurrentBatch();
206 
207  const size_t batch_start = getStartIndex(n_batches, current_batch, total_size);
208  const size_t batch_size = getNumberOfElements(n_batches, current_batch, total_size);
209  if (batch_size == 0)
210  return;
211 
212  if(param_combinations == 1)
213  runSingleSimulation(batch_start, batch_size, 1.);
214  else{
215  std::unique_ptr<ParameterPool> param_pool(createParameterTree());
216  for (size_t index = 0; index < param_combinations; ++index) {
217  double weight = m_distribution_handler.setParameterValues(param_pool.get(), index);
218  runSingleSimulation(batch_start, batch_size, weight);
219  }
221  }
224 }
double setParameterValues(ParameterPool *p_parameter_pool, size_t index)
set the parameter values of the simulation object to a specific combination of values,...
void setParameterToMeans(ParameterPool *p_parameter_pool) const
Sets mean distribution values to the parameter pool.
size_t getTotalNumberOfSamples() const
get the total number of parameter value combinations (product of the individual sizes of each paramet...
ParameterPool * createParameterTree() const
Creates new parameter pool, with all local parameters and those of its children.
Definition: INode.cpp:126
void runSingleSimulation(size_t batch_start, size_t batch_size, double weight=1.0)
Runs a single simulation with fixed parameter values.
virtual size_t numberOfSimulationElements() const =0
Gets the number of elements this simulation needs to calculate.
virtual void moveDataFromCache()=0
virtual void transferResultsToIntensityMap()
Creates the appropriate data structure (e.g.
Definition: ISimulation.h:114
void setExpectedNTicks(size_t n)
unsigned getNumberOfBatches() const
unsigned getCurrentBatch() const

References INode::createParameterTree(), SimulationOptions::getCurrentBatch(), SimulationOptions::getNumberOfBatches(), DistributionHandler::getTotalNumberOfSamples(), ISimulation::m_distribution_handler, ISimulation::m_options, ISimulation::m_progress, ISimulation::moveDataFromCache(), ISimulation::numberOfSimulationElements(), ISimulation::prepareSimulation(), ProgressHandler::reset(), ISimulation::runSingleSimulation(), ProgressHandler::setExpectedNTicks(), DistributionHandler::setParameterToMeans(), DistributionHandler::setParameterValues(), and ISimulation::transferResultsToIntensityMap().

Referenced by JobWorker::start().

Here is the call graph for this function:

◆ runSingleSimulation()

void ISimulation::runSingleSimulation ( size_t  batch_start,
size_t  batch_size,
double  weight = 1.0 
)
privateinherited

Runs a single simulation with fixed parameter values.

If desired, the simulation is run in several threads.

Definition at line 280 of file ISimulation.cpp.

281 {
283 
284  const size_t n_threads = m_options.getNumberOfThreads();
285  ASSERT(n_threads > 0);
286 
287  std::vector<std::unique_ptr<IComputation>> computations;
288 
289  for (size_t i_thread = 0; i_thread < n_threads;
290  ++i_thread) { // Distribute computations by threads
291  const size_t thread_start = batch_start + getStartIndex(n_threads, i_thread, batch_size);
292  const size_t thread_size = getNumberOfElements(n_threads, i_thread, batch_size);
293  if (thread_size == 0)
294  break;
295  computations.push_back(generateSingleThreadedComputation(thread_start, thread_size));
296  }
297  runComputations(computations);
298 
299  normalize(batch_start, batch_size);
300  addBackgroundIntensity(batch_start, batch_size);
301  addDataToCache(weight);
302 }
virtual void addDataToCache(double weight)=0
virtual std::unique_ptr< IComputation > generateSingleThreadedComputation(size_t start, size_t n_elements)=0
Generate a single threaded computation for a given range of simulation elements.
virtual void addBackgroundIntensity(size_t start_ind, size_t n_elements)=0
virtual void initSimulationElementVector()=0
Initializes the vector of ISimulation 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.
unsigned getNumberOfThreads() const

References ISimulation::addBackgroundIntensity(), ISimulation::addDataToCache(), ASSERT, ISimulation::generateSingleThreadedComputation(), SimulationOptions::getNumberOfThreads(), ISimulation::initSimulationElementVector(), ISimulation::m_options, and ISimulation::normalize().

Referenced by ISimulation::runSimulation().

Here is the call graph for this function:

◆ sample()

const MultiLayer * ISimulation::sample ( ) const
inherited

Definition at line 238 of file ISimulation.cpp.

239 {
240  return m_sample_provider.sample();
241 }
const MultiLayer * sample() const
Returns current sample.

References ISimulation::m_sample_provider, and SampleProvider::sample().

Referenced by ISimulation::ISimulation(), DepthProbeSimulation::generateSingleThreadedComputation(), ISimulation2D::generateSingleThreadedComputation(), generateSingleThreadedComputation(), ISimulation::setSample(), and DepthProbeSimulation::validityCheck().

Here is the call graph for this function:

◆ setBackground()

void ISimulation::setBackground ( const IBackground bg)
inherited

Definition at line 248 of file ISimulation.cpp.

249 {
250  m_background.reset(bg.clone());
252 }
virtual IBackground * clone() const =0
void registerChild(INode *node)
Definition: INode.cpp:57

References IBackground::clone(), ISimulation::m_background, and INode::registerChild().

Referenced by ISimulation::ISimulation(), and StandardSimulations::ConstantBackgroundGISAS().

Here is the call graph for this function:

◆ setDetectorResolutionFunction()

void ISimulation::setDetectorResolutionFunction ( const IResolutionFunction2D resolution_function)
inherited

Definition at line 177 of file ISimulation.cpp.

178 {
179  detector().setResolutionFunction(resolution_function);
180 }
void setResolutionFunction(const IResolutionFunction2D &resFunc)
Definition: IDetector.cpp:112

References ISimulation::detector(), and IDetector::setResolutionFunction().

Referenced by StandardSimulations::MiniGISASDetectorResolution().

Here is the call graph for this function:

◆ setInstrument()

void ISimulation::setInstrument ( const Instrument instrument_)
inherited

Definition at line 158 of file ISimulation.cpp.

159 {
160  m_instrument = instrument_;
162 }
virtual void updateIntensityMap()
Definition: ISimulation.h:119

References ISimulation::m_instrument, and ISimulation::updateIntensityMap().

Here is the call graph for this function:

◆ setName()

void IParametricComponent::setName ( const std::string &  name)
inlineinherited

Definition at line 69 of file IParametricComponent.h.

69 { m_name = name; }

References IParametricComponent::m_name, and RealSpace::Particles::name().

Referenced by BasicLattice2D::BasicLattice2D(), Beam::Beam(), ConvolutionDetectorResolution::ConvolutionDetectorResolution(), Crystal::Crystal(), DetectionProperties::DetectionProperties(), DistributionHandler::DistributionHandler(), FormFactorCoreShell::FormFactorCoreShell(), FormFactorCrystal::FormFactorCrystal(), FormFactorDecoratorMaterial::FormFactorDecoratorMaterial(), FormFactorDecoratorPositionFactor::FormFactorDecoratorPositionFactor(), FormFactorDecoratorRotation::FormFactorDecoratorRotation(), FormFactorWeighted::FormFactorWeighted(), HexagonalLattice2D::HexagonalLattice2D(), IDetector::IDetector(), INode::INode(), Instrument::Instrument(), InterferenceFunction1DLattice::InterferenceFunction1DLattice(), InterferenceFunction2DLattice::InterferenceFunction2DLattice(), InterferenceFunction2DParaCrystal::InterferenceFunction2DParaCrystal(), InterferenceFunction2DSuperLattice::InterferenceFunction2DSuperLattice(), InterferenceFunction3DLattice::InterferenceFunction3DLattice(), InterferenceFunctionFinite2DLattice::InterferenceFunctionFinite2DLattice(), InterferenceFunctionFinite3DLattice::InterferenceFunctionFinite3DLattice(), InterferenceFunctionHardDisk::InterferenceFunctionHardDisk(), InterferenceFunctionNone::InterferenceFunctionNone(), InterferenceFunctionRadialParaCrystal::InterferenceFunctionRadialParaCrystal(), InterferenceFunctionTwin::InterferenceFunctionTwin(), ISampleBuilder::ISampleBuilder(), IsGISAXSDetector::IsGISAXSDetector(), Lattice3D::Lattice3D(), Layer::Layer(), LayerInterface::LayerInterface(), LayerRoughness::LayerRoughness(), MultiLayer::MultiLayer(), ParticleCoreShell::ParticleCoreShell(), ParticleDistribution::ParticleDistribution(), ParticleLayout::ParticleLayout(), RectangularDetector::RectangularDetector(), ResolutionFunction2DGaussian::ResolutionFunction2DGaussian(), SampleBuilderNode::SampleBuilderNode(), SphericalDetector::SphericalDetector(), SquareLattice2D::SquareLattice2D(), Layer::clone(), LayersWithAbsorptionBuilder::createSampleByIndex(), Basic2DParaCrystalBuilder::createSampleByIndex(), ParticleInVacuumBuilder::createSampleByIndex(), SimpleMagneticRotationBuilder::createSampleByIndex(), DepthProbeSimulation::initialize(), GISASSimulation::initialize(), OffSpecularSimulation::initialize(), initialize(), SpecularDetector1D::initialize(), MesoCrystal::initialize(), Particle::initialize(), ParticleComposition::initialize(), Beam::operator=(), SampleBuilderNode::operator=(), SampleBuilderNode::reset(), and SampleBuilderNode::setSBN().

Here is the call graph for this function:

◆ setOptions()

void ISimulation::setOptions ( const SimulationOptions options)
inlineinherited

Definition at line 90 of file ISimulation.h.

90 { m_options = options; }

References ISimulation::m_options, and ISimulation::options().

Here is the call graph for this function:

◆ setParameterValue()

void IParametricComponent::setParameterValue ( const std::string &  name,
double  value 
)
inherited

Definition at line 65 of file IParametricComponent.cpp.

66 {
67  if (name.find('*') == std::string::npos && name.find('/') == std::string::npos) {
68  m_pool->setParameterValue(name, value);
69  } else {
70  std::unique_ptr<ParameterPool> P_pool{createParameterTree()};
71  if (name.find('*') != std::string::npos)
72  P_pool->setMatchedParametersValue(name, value);
73  else
74  P_pool->setParameterValue(name, value);
75  }
76 }
int setMatchedParametersValue(const std::string &wildcards, double value)
Sets value of the nonzero parameters that match pattern ('*' allowed), or throws.

References IParametricComponent::createParameterTree(), IParametricComponent::m_pool, RealSpace::Particles::name(), and ParameterPool::setMatchedParametersValue().

Referenced by AsymRippleBuilder::buildSample(), and IParametricComponent::setVectorValue().

Here is the call graph for this function:

◆ setParent()

void INode::setParent ( const INode newParent)
virtualinherited

Reimplemented in SampleProvider.

Definition at line 79 of file INode.cpp.

80 {
81  m_parent = newParent;
82 }

References INode::m_parent.

Referenced by INode::registerChild(), SampleProvider::setBuilder(), and SampleProvider::setParent().

◆ setRawResults()

void SpecularSimulation::setRawResults ( const std::vector< double > &  raw_data)
overrideprivatevirtual

Implements ISimulation.

Definition at line 260 of file SpecularSimulation.cpp.

261 {
263  if (raw_data.size() != m_sim_elements.size())
264  throw std::runtime_error("SpecularSimulation::setRawResults: size of vector passed as "
265  "argument doesn't match number of elements in this simulation");
266  for (unsigned i = 0; i < raw_data.size(); i++)
267  m_sim_elements[i].setIntensity(raw_data[i]);
269 }
void initSimulationElementVector() override
Initializes the vector of ISimulation elements.

References initSimulationElementVector(), m_sim_elements, and ISimulation::transferResultsToIntensityMap().

Here is the call graph for this function:

◆ setSample()

void ISimulation::setSample ( const MultiLayer sample)
inherited

The MultiLayer object will not be owned by the ISimulation object.

Definition at line 233 of file ISimulation.cpp.

234 {
236 }
void setSample(const MultiLayer &multilayer)

References ISimulation::m_sample_provider, ISimulation::sample(), and SampleProvider::setSample().

Referenced by ISimulation::ISimulation().

Here is the call graph for this function:

◆ setSampleBuilder()

void ISimulation::setSampleBuilder ( const std::shared_ptr< ISampleBuilder > &  sample_builder)
inherited

Definition at line 243 of file ISimulation.cpp.

244 {
245  m_sample_provider.setBuilder(sample_builder);
246 }
void setBuilder(const std::shared_ptr< ISampleBuilder > &sample_builder)

References ISimulation::m_sample_provider, and SampleProvider::setBuilder().

Here is the call graph for this function:

◆ setScan()

void SpecularSimulation::setScan ( const ISpecularScan scan)

Sets chosen specular scan to the simulation.

Definition at line 112 of file SpecularSimulation.cpp.

113 {
114  if (m_scan)
115  throw std::runtime_error("Error in SpecularSimulation::setScan: Scan cannot be set twice");
116 
117  // TODO: move inside AngularSpecScan when pointwise resolution is implemented
118  if (scan.coordinateAxis()->lowerBound() < 0.0)
119  throw std::runtime_error(
120  "Error in SpecularSimulation::setScan: minimum value on coordinate axis is negative.");
121 
122  m_scan.reset(scan.clone());
123 
124  if(instrument().detector().dimension() > 0)
125  throw std::runtime_error("Error in SpecularSimulation::setScan: Axis already set");
126 
128 
129  // TODO: remove when pointwise resolution is implemented
130  if (const auto* aScan = dynamic_cast<const AngularSpecScan*>(&scan))
131  instrument().setBeamParameters(aScan->wavelength(), 0.0, 0.0);
132 }
virtual double lowerBound() const =0
Returns value of first point of axis.
void addAxis(const IAxis &axis)
Definition: IDetector.cpp:41
virtual const IAxis * coordinateAxis() const =0
Returns coordinate axis assigned to the data holder.
ISpecularScan * clone() const override=0
void setBeamParameters(double wavelength, double alpha_i, double phi_i)
Sets the beam wavelength and incoming angles.
Definition: Instrument.cpp:76

References IDetector::addAxis(), ISpecularScan::clone(), ISpecularScan::coordinateAxis(), ISimulation::detector(), Instrument::detector(), ISimulation::instrument(), IAxis::lowerBound(), m_scan, and Instrument::setBeamParameters().

Referenced by StandardSimulations::BasicSpecularQ(), StandardSimulations::SpecularDivergentBeam(), StandardSimulations::SpecularWithGaussianBeam(), StandardSimulations::SpecularWithSquareBeam(), StandardSimulations::TOFRWithPointwiseResolution(), and StandardSimulations::TOFRWithRelativeResolution().

Here is the call graph for this function:

◆ setTerminalProgressMonitor()

void ISimulation::setTerminalProgressMonitor ( )
inherited

Initializes a progress monitor that prints to stdout.

Definition at line 166 of file ISimulation.cpp.

167 {
168  m_progress.subscribe([](size_t percentage_done) -> bool {
169  if (percentage_done < 100)
170  std::cout << std::setprecision(2) << "\r... " << percentage_done << "%" << std::flush;
171  else // wipe out
172  std::cout << "\r... 100%\n";
173  return true;
174  });
175 }
void subscribe(ProgressHandler::Callback_t callback)

References ISimulation::m_progress, and ProgressHandler::subscribe().

Here is the call graph for this function:

◆ setVectorValue()

void IParametricComponent::setVectorValue ( const std::string &  base_name,
kvector_t  value 
)
inherited

Definition at line 78 of file IParametricComponent.cpp.

79 {
83 }
T z() const
Returns z-component in cartesian coordinate system.
Definition: BasicVector3D.h:67
T y() const
Returns y-component in cartesian coordinate system.
Definition: BasicVector3D.h:65
T x() const
Returns x-component in cartesian coordinate system.
Definition: BasicVector3D.h:63
void setParameterValue(const std::string &name, double value)

References ModelView::Utils::base_name(), IParametricComponent::setParameterValue(), BasicVector3D< T >::x(), IParametricComponent::XComponentName(), BasicVector3D< T >::y(), IParametricComponent::YComponentName(), BasicVector3D< T >::z(), and IParametricComponent::ZComponentName().

Here is the call graph for this function:

◆ subscribe()

void ISimulation::subscribe ( ProgressHandler::Callback_t  inform)
inlineinherited

Definition at line 94 of file ISimulation.h.

94 { m_progress.subscribe(inform); }

References ISimulation::m_progress, and ProgressHandler::subscribe().

Referenced by JobWorker::start().

Here is the call graph for this function:

◆ transferResultsToIntensityMap()

virtual void ISimulation::transferResultsToIntensityMap ( )
inlineprotectedvirtualinherited

Creates the appropriate data structure (e.g.

2D intensity map) from the calculated SimulationElement objects

Reimplemented in OffSpecularSimulation.

Definition at line 114 of file ISimulation.h.

114 {}

Referenced by ISimulation::runSimulation(), ISimulation2D::setRawResults(), and setRawResults().

◆ transferToCPP()

virtual void ICloneable::transferToCPP ( )
inlinevirtualinherited

Used for Python overriding of clone (see swig/tweaks.py)

Definition at line 34 of file ICloneable.h.

◆ treeToString()

std::string INode::treeToString ( ) const
virtualinherited

Returns multiline string representing tree structure below the node.

Definition at line 52 of file INode.cpp.

53 {
54  return NodeUtils::nodeToString(this);
55 }
std::string nodeToString(const INode *node)
Returns multiline string representing tree structure starting from given node.
Definition: NodeUtils.cpp:81

References NodeUtils::nodeToString().

Here is the call graph for this function:

◆ updateIntensityMap()

virtual void ISimulation::updateIntensityMap ( )
inlineprotectedvirtualinherited

Reimplemented in OffSpecularSimulation.

Definition at line 119 of file ISimulation.h.

119 {}

Referenced by ISimulation2D::setDetectorParameters(), and ISimulation::setInstrument().

◆ validateParametrization()

void SpecularSimulation::validateParametrization ( const ParameterDistribution par_distr) const
overrideprivatevirtual

Checks the distribution validity for simulation.

Reimplemented from ISimulation.

Definition at line 181 of file SpecularSimulation.cpp.

182 {
183  const bool zero_mean = par_distr.getDistribution()->getMean() == 0.0;
184  if (zero_mean)
185  return;
186 
187  std::unique_ptr<ParameterPool> parameter_pool(createParameterTree());
188  const std::vector<RealParameter*> names =
189  parameter_pool->getMatchedParameters(par_distr.getMainParameterName());
190  for (const auto par : names)
191  if (par->getName().find("InclinationAngle") != std::string::npos && !zero_mean)
192  throw std::runtime_error("Error in SpecularSimulation: parameter distribution of "
193  "beam inclination angle should have zero mean.");
194 }
virtual double getMean() const =0
Returns the distribution-specific mean.
const IDistribution1D * getDistribution() const
std::string getMainParameterName() const
get the main parameter's name

References INode::createParameterTree(), ParameterDistribution::getDistribution(), ParameterDistribution::getMainParameterName(), and IDistribution1D::getMean().

Here is the call graph for this function:

◆ XComponentName()

std::string IParametricComponent::XComponentName ( const std::string &  base_name)
staticinherited

Definition at line 103 of file IParametricComponent.cpp.

104 {
105  return base_name + "X";
106 }

References ModelView::Utils::base_name().

Referenced by Lattice3D::initialize(), IParticle::registerPosition(), IParametricComponent::registerVector(), IParametricComponent::removeVector(), IParametricComponent::setVectorValue(), and VectorParameterTranslator::translate().

Here is the call graph for this function:

◆ YComponentName()

std::string IParametricComponent::YComponentName ( const std::string &  base_name)
staticinherited

Definition at line 108 of file IParametricComponent.cpp.

109 {
110  return base_name + "Y";
111 }

References ModelView::Utils::base_name().

Referenced by IParametricComponent::registerVector(), IParametricComponent::removeVector(), IParametricComponent::setVectorValue(), and VectorParameterTranslator::translate().

Here is the call graph for this function:

◆ ZComponentName()

std::string IParametricComponent::ZComponentName ( const std::string &  base_name)
staticinherited

Definition at line 113 of file IParametricComponent.cpp.

114 {
115  return base_name + "Z";
116 }

References ModelView::Utils::base_name().

Referenced by IParametricComponent::registerVector(), IParametricComponent::removeVector(), IParametricComponent::setVectorValue(), and VectorParameterTranslator::translate().

Here is the call graph for this function:

Member Data Documentation

◆ m_background

std::unique_ptr<IBackground> ISimulation::m_background
privateinherited

◆ m_cache

std::vector<double> SpecularSimulation::m_cache
private

◆ m_distribution_handler

DistributionHandler ISimulation::m_distribution_handler
privateinherited

◆ m_instrument

◆ m_name

std::string IParametricComponent::m_name
privateinherited

◆ m_NP

const size_t INode::m_NP
protectedinherited

Definition at line 88 of file INode.h.

Referenced by INode::INode().

◆ m_options

◆ m_P

std::vector<double> INode::m_P
protectedinherited

Definition at line 89 of file INode.h.

Referenced by INode::INode(), and IFootprintFactor::setWidthRatio().

◆ m_parent

const INode* INode::m_parent {nullptr}
privateinherited

Definition at line 83 of file INode.h.

Referenced by INode::displayName(), INode::parent(), and INode::setParent().

◆ m_pool

◆ m_progress

ProgressHandler ISimulation::m_progress
privateinherited

◆ m_sample_provider

◆ m_scan

◆ m_sim_elements


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