BornAgain  1.19.79
Open-source research software to simulate and fit neutron and x-ray reflectometry and grazing-incidence small-angle scattering
IComputation.h
Go to the documentation of this file.
1 // ************************************************************************************************
2 //
3 // BornAgain: simulate and fit reflection and scattering
4 //
5 //! @file Sim/Computation/IComputation.h
6 //! @brief Defines interface IComputation.
7 //!
8 //! @homepage http://www.bornagainproject.org
9 //! @license GNU General Public License v3 or higher (see COPYING)
10 //! @copyright Forschungszentrum Jülich GmbH 2018
11 //! @authors Scientific Computing Group at MLZ (see CITATION, AUTHORS)
12 //
13 // ************************************************************************************************
14 
15 #ifdef SWIG
16 #error no need to expose this header to Swig
17 #endif
18 
19 #ifndef USER_API
20 #ifndef BORNAGAIN_SIM_COMPUTATION_ICOMPUTATION_H
21 #define BORNAGAIN_SIM_COMPUTATION_ICOMPUTATION_H
22 
24 #include <memory>
25 
27 class MultiLayer;
28 class reSample;
29 class ProgressHandler;
30 class SimulationOptions;
31 
32 //! Interface for a single-threaded computation with given range of DiffuseElements
33 //! and ProgressHandler.
34 //!
35 //! Controlled by the multi-threading machinery in ISimulation::runSingleSimulation().
36 
37 class IComputation {
38 public:
39  IComputation(const reSample& re_sample, const SimulationOptions& options,
40  ProgressHandler& progress);
41  virtual ~IComputation();
42 
43  //! Calls runProtected(), catches exceptions, sets m_status.
44  void compute();
45 
46  bool isCompleted() const { return m_status.isCompleted(); }
47  std::string errorMessage() const { return m_status.errorMessage(); }
48 
49 protected:
50  void setProgressHandler(ProgressHandler* progress) const;
51  void stepProgress() const;
52 
57 
58 private:
59  //! Runs computation. May throw. To be called from run(), which catches exceptions.
60  virtual void runProtected() = 0;
61 
62  mutable std::unique_ptr<DelayedProgressCounter> m_progress_counter;
63 };
64 
65 #endif // BORNAGAIN_SIM_COMPUTATION_ICOMPUTATION_H
66 #endif // USER_API
Defines and implements interface class ComputationStatus.
Completion status (flag and text) of a numeric computation.
std::string errorMessage() const
bool isCompleted() const
Counter for reporting progress (with delay interval) in a threaded computation.
Interface for a single-threaded computation with given range of DiffuseElements and ProgressHandler.
Definition: IComputation.h:37
virtual ~IComputation()
const SimulationOptions & m_options
Definition: IComputation.h:54
ProgressHandler * m_progress
Definition: IComputation.h:55
const reSample & m_re_sample
Definition: IComputation.h:53
IComputation(const reSample &re_sample, const SimulationOptions &options, ProgressHandler &progress)
std::unique_ptr< DelayedProgressCounter > m_progress_counter
Definition: IComputation.h:62
bool isCompleted() const
Definition: IComputation.h:46
void setProgressHandler(ProgressHandler *progress) const
virtual void runProtected()=0
Runs computation. May throw. To be called from run(), which catches exceptions.
void compute()
Calls runProtected(), catches exceptions, sets m_status.
ComputationStatus m_status
Definition: IComputation.h:56
std::string errorMessage() const
Definition: IComputation.h:47
void stepProgress() const
Our sample model: a stack of layers one below the other.
Definition: MultiLayer.h:43
Maintains information about progress of a computation.
Collect the different options for simulation.SimulationOptions.
Data structure that contains all the necessary data for scattering calculations.
Definition: ReSample.h:41