BornAgain  1.19.79
Open-source research software to simulate and fit neutron and x-ray reflectometry and grazing-incidence small-angle scattering
IComputation.cpp
Go to the documentation of this file.
1 // ************************************************************************************************
2 //
3 // BornAgain: simulate and fit reflection and scattering
4 //
5 //! @file Sim/Computation/IComputation.cpp
6 //! @brief Implements 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 
19 
20 IComputation::IComputation(const reSample& re_sample, const SimulationOptions& options,
21  ProgressHandler& progress)
22  : m_re_sample(re_sample)
23  , m_options(options)
24  , m_progress(&progress)
25 {
26 }
27 
28 IComputation::~IComputation() = default;
29 
31 {
32  m_progress_counter = std::make_unique<DelayedProgressCounter>(progress, 100);
33 }
34 
36 {
38  m_progress_counter->stepProgress();
39 }
40 
42 {
44  try {
45  if (!m_progress->alive())
46  return;
48 
49  runProtected(); // <--- here the main work is done
50 
52  } catch (const std::exception& ex) {
53  m_status.setFailed(ex.what());
54  }
55 }
Defines class DelayedProgressCounter.
Defines interface IComputation.
Defines class ProgressHandler.
Defines class reSample.
void setFailed(const std::string &message)
virtual ~IComputation()
ProgressHandler * m_progress
Definition: IComputation.h:55
IComputation(const reSample &re_sample, const SimulationOptions &options, ProgressHandler &progress)
std::unique_ptr< DelayedProgressCounter > m_progress_counter
Definition: IComputation.h:62
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
void stepProgress() const
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