BornAgain  1.19.79
Open-source research software to simulate and fit neutron and x-ray reflectometry and grazing-incidence small-angle scattering
IComputation Class Referenceabstract

Description

Interface for a single-threaded computation with given range of DiffuseElements and ProgressHandler.

Controlled by the multi-threading machinery in ISimulation::runSingleSimulation().

Definition at line 37 of file IComputation.h.

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

Public Member Functions

 IComputation (const reSample &re_sample, const SimulationOptions &options, ProgressHandler &progress)
 
virtual ~IComputation ()
 
void compute ()
 Calls runProtected(), catches exceptions, sets m_status. More...
 
std::string errorMessage () const
 
bool isCompleted () const
 

Protected Member Functions

void setProgressHandler (ProgressHandler *progress) const
 
void stepProgress () const
 

Protected Attributes

const SimulationOptionsm_options
 
ProgressHandlerm_progress
 
const reSamplem_re_sample
 
ComputationStatus m_status
 

Private Member Functions

virtual void runProtected ()=0
 Runs computation. May throw. To be called from run(), which catches exceptions. More...
 

Private Attributes

std::unique_ptr< DelayedProgressCounterm_progress_counter
 

Constructor & Destructor Documentation

◆ IComputation()

IComputation::IComputation ( const reSample re_sample,
const SimulationOptions options,
ProgressHandler progress 
)

Definition at line 20 of file IComputation.cpp.

22  : m_re_sample(re_sample)
23  , m_options(options)
24  , m_progress(&progress)
25 {
26 }
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()

IComputation::~IComputation ( )
virtualdefault

Member Function Documentation

◆ compute()

void IComputation::compute ( )

Calls runProtected(), catches exceptions, sets m_status.

Definition at line 41 of file IComputation.cpp.

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 }
void setFailed(const std::string &message)
void setProgressHandler(ProgressHandler *progress) const
virtual void runProtected()=0
Runs computation. May throw. To be called from run(), which catches exceptions.
ComputationStatus m_status
Definition: IComputation.h:56

References ProgressHandler::alive(), m_progress, m_status, runProtected(), ComputationStatus::setCompleted(), ComputationStatus::setFailed(), setProgressHandler(), and ComputationStatus::setRunning().

Here is the call graph for this function:

◆ errorMessage()

std::string IComputation::errorMessage ( ) const
inline

Definition at line 47 of file IComputation.h.

47 { return m_status.errorMessage(); }
std::string errorMessage() const

References ComputationStatus::errorMessage(), and m_status.

Here is the call graph for this function:

◆ isCompleted()

bool IComputation::isCompleted ( ) const
inline

Definition at line 46 of file IComputation.h.

46 { return m_status.isCompleted(); }
bool isCompleted() const

References ComputationStatus::isCompleted(), and m_status.

Here is the call graph for this function:

◆ runProtected()

virtual void IComputation::runProtected ( )
privatepure virtual

Runs computation. May throw. To be called from run(), which catches exceptions.

Implemented in SpecularComputation, DWBAComputation, and DepthProbeComputation.

Referenced by compute().

◆ setProgressHandler()

void IComputation::setProgressHandler ( ProgressHandler progress) const
protected

Definition at line 30 of file IComputation.cpp.

31 {
32  m_progress_counter = std::make_unique<DelayedProgressCounter>(progress, 100);
33 }
std::unique_ptr< DelayedProgressCounter > m_progress_counter
Definition: IComputation.h:62

References m_progress_counter.

Referenced by compute().

◆ stepProgress()

void IComputation::stepProgress ( ) const
protected

Member Data Documentation

◆ m_options

const SimulationOptions& IComputation::m_options
protected

Definition at line 54 of file IComputation.h.

◆ m_progress

ProgressHandler* IComputation::m_progress
protected

Definition at line 55 of file IComputation.h.

Referenced by compute(), and DWBAComputation::runProtected().

◆ m_progress_counter

std::unique_ptr<DelayedProgressCounter> IComputation::m_progress_counter
mutableprivate

Definition at line 62 of file IComputation.h.

Referenced by setProgressHandler(), and stepProgress().

◆ m_re_sample

const reSample& IComputation::m_re_sample
protected

◆ m_status

ComputationStatus IComputation::m_status
protected

Definition at line 56 of file IComputation.h.

Referenced by compute(), errorMessage(), and isCompleted().


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