1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121
|
// ************************************************************************************************
//
// BornAgain: simulate and fit reflection and scattering
//
//! @file Sim/Simulation/ISimulation.h
//! @brief Defines interface ISimulation.
//!
//! @homepage http://www.bornagainproject.org
//! @license GNU General Public License v3 or higher (see COPYING)
//! @copyright Forschungszentrum Jülich GmbH 2018
//! @authors Scientific Computing Group at MLZ (see CITATION, AUTHORS)
//
// ************************************************************************************************
#ifndef BORNAGAIN_SIM_SIMULATION_ISIMULATION_H
#define BORNAGAIN_SIM_SIMULATION_ISIMULATION_H
#include "Param/Distrib/ParameterDistribution.h"
#include "Param/Node/INode.h"
#include <functional>
#include <heinz/Vectors3D.h>
class Datafield;
class DistributionHandler;
class Frame;
class IBackground;
class IComputation;
class ProgressHandler;
class ReSample;
class Sample;
class SimulationOptions;
//! Abstract base class, holds the infrastructure to run a simulation.
//!
//! Base class of SpecularSimulation, OffspecSimulation, 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().
class ISimulation : public INode {
public:
ISimulation(const Sample& sample);
~ISimulation() override;
ISimulation(const ISimulation&) = delete;
//... Setters:
void setBackground(const IBackground& bg);
void setTerminalProgressMonitor();
SimulationOptions& options();
//... Executor:
Datafield simulate(); //!< Runs a simulation, and returns the result.
#ifndef SWIG
//... Setter:
void subscribe(const std::function<bool(size_t)>& inform);
//... Getters:
std::vector<const INode*> nodeChildren() const override;
const Sample* sample() const;
const IBackground* background() const;
const std::vector<ParameterDistribution>& paramDistributions() const;
const SimulationOptions& options() const;
protected:
ProgressHandler& progress();
DistributionHandler& distributionHandler();
std::vector<double> m_cache;
private:
//... Executor:
void runSingleSimulation(const ReSample& re_sample, size_t batch_start, size_t batch_size,
double weight = 1.0);
//... Virtual executors:
virtual void initDistributionHandler() {}
//! Put into a clean state for running a simulation.
virtual void prepareSimulation() {}
//! Initializes the vector of ISimulation elements.
virtual void initScanElementVector() {}
//! Runs a single threaded computation for a given range of simulation elements.
virtual void runComputation(const ReSample& re_sample, size_t iElement, double weight) = 0;
//... Virtual getters:
//! Forces polarized computation even in absence of sample magnetization or external fields
virtual bool force_polarized() const = 0;
//! Returns the number of elements this simulation needs to calculate.
virtual size_t nElements() const = 0;
//! Returns the number of output channels to be computed. Determines size of m_cache.
virtual size_t nOutChannels() const { return nElements(); }
//! Returns simulation result, based on intensity held in elements vector.
virtual Datafield packResult() const = 0;
//... Simulation model:
std::unique_ptr<const Sample> m_sample;
std::unique_ptr<const IBackground> m_background;
std::unique_ptr<SimulationOptions> m_options;
//... Computational auxiliaries:
std::unique_ptr<DistributionHandler> m_distribution_handler;
std::unique_ptr<ProgressHandler> m_progress;
#endif // SWIG
};
#endif // BORNAGAIN_SIM_SIMULATION_ISIMULATION_H
|