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

Description

Provides function that performs a single-threaded DWBA computation for a range of DiffuseElements.

Handles progress counter and interrupts, runs loop over DiffuseElements, delegates all further work to DWBATerm.

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

Definition at line 41 of file DWBAComputation.h.

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

Public Member Functions

 DWBAComputation (const reSample &re_sample, const SimulationOptions &options, ProgressHandler &progress, std::vector< std::unique_ptr< DiffuseElement >>::iterator begin_it, std::vector< std::unique_ptr< DiffuseElement >>::iterator end_it)
 
 ~DWBAComputation () override
 
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

void runProtected () override
 Performs a single-threaded DWBA computation for a DiffuseElements in range m_begin_it ... m_end_it. Results are stored in those elements. More...
 

Private Attributes

std::vector< std::unique_ptr< DiffuseElement > >::iterator m_begin_it
 
std::vector< std::unique_ptr< DiffuseElement > >::iterator m_end_it
 
const std::vector< std::unique_ptr< const ParticleLayoutContribution > > m_layout_contribs
 
std::unique_ptr< DelayedProgressCounterm_progress_counter
 
const std::unique_ptr< const RoughMultiLayerContributionm_roughness_contrib
 
const std::unique_ptr< const GISASSpecularContributionm_specular_contrib
 

Constructor & Destructor Documentation

◆ DWBAComputation()

DWBAComputation::DWBAComputation ( const reSample re_sample,
const SimulationOptions options,
ProgressHandler progress,
std::vector< std::unique_ptr< DiffuseElement >>::iterator  begin_it,
std::vector< std::unique_ptr< DiffuseElement >>::iterator  end_it 
)

Definition at line 44 of file DWBAComputation.cpp.

48  : IComputation(re_sample, options, progress)
49  , m_begin_it(begin_it)
50  , m_end_it(end_it)
51  , m_specular_contrib(options.includeSpecular() ? new GISASSpecularContribution() : nullptr)
53  : nullptr)
54  , m_layout_contribs(makeLayoutComputation(m_re_sample.layouts(), options,
56 {
57 }
const std::unique_ptr< const RoughMultiLayerContribution > m_roughness_contrib
const std::vector< std::unique_ptr< const ParticleLayoutContribution > > m_layout_contribs
const std::unique_ptr< const GISASSpecularContribution > m_specular_contrib
std::vector< std::unique_ptr< DiffuseElement > >::iterator m_end_it
std::vector< std::unique_ptr< DiffuseElement > >::iterator m_begin_it
Computes the specular signal in the bin where q_parallel = 0. Used by DWBAComputation.
const reSample & m_re_sample
Definition: IComputation.h:53
IComputation(const reSample &re_sample, const SimulationOptions &options, ProgressHandler &progress)
Computes the diffuse reflection from the rough interfaces of a sample. Used by DWBAComputation.
bool includeSpecular() const
bool hasRoughness() const
Definition: ReSample.cpp:376
const std::vector< reLayout > & layouts() const
Definition: ReSample.cpp:351
bool containsMagneticMaterial() const
Definition: ReSample.cpp:366

◆ ~DWBAComputation()

DWBAComputation::~DWBAComputation ( )
overridedefault

Member Function Documentation

◆ compute()

void IComputation::compute ( )
inherited

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)
ProgressHandler * m_progress
Definition: IComputation.h:55
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(), IComputation::m_progress, IComputation::m_status, IComputation::runProtected(), ComputationStatus::setCompleted(), ComputationStatus::setFailed(), IComputation::setProgressHandler(), and ComputationStatus::setRunning().

Here is the call graph for this function:

◆ errorMessage()

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

Definition at line 47 of file IComputation.h.

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

References ComputationStatus::errorMessage(), and IComputation::m_status.

Here is the call graph for this function:

◆ isCompleted()

bool IComputation::isCompleted ( ) const
inlineinherited

Definition at line 46 of file IComputation.h.

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

References ComputationStatus::isCompleted(), and IComputation::m_status.

Here is the call graph for this function:

◆ runProtected()

void DWBAComputation::runProtected ( )
overrideprivatevirtual

Performs a single-threaded DWBA computation for a DiffuseElements in range m_begin_it ... m_end_it. Results are stored in those elements.

Implements IComputation.

Definition at line 66 of file DWBAComputation.cpp.

67 {
68  for (auto it = m_begin_it; it != m_end_it; ++it) {
69  if (!m_progress->alive())
70  break;
71  std::unique_ptr<DiffuseElement>& ele = *it;
72 
73  const Fluxes fluxes_in = m_re_sample.fluxesIn(ele->getKi());
74  const Fluxes fluxes_out = m_re_sample.fluxesOut(ele->meanKf());
75  ele->setFluxes(&fluxes_in, &fluxes_out);
76 
77  for (const auto& contrib : m_layout_contribs)
78  contrib->compute(*ele);
79 
81  m_roughness_contrib->compute(*ele);
82 
84  m_specular_contrib->compute(*ele);
85 
86  stepProgress();
87  }
88 }
std::vector< std::unique_ptr< const IFlux > > Fluxes
void stepProgress() const
Fluxes fluxesIn(const R3 &k) const
Definition: ReSample.cpp:384
Fluxes fluxesOut(const R3 &k) const
Definition: ReSample.cpp:391

References ProgressHandler::alive(), reSample::fluxesIn(), reSample::fluxesOut(), m_begin_it, m_end_it, m_layout_contribs, IComputation::m_progress, IComputation::m_re_sample, m_roughness_contrib, m_specular_contrib, and IComputation::stepProgress().

Here is the call graph for this function:

◆ setProgressHandler()

void IComputation::setProgressHandler ( ProgressHandler progress) const
protectedinherited

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 IComputation::m_progress_counter.

Referenced by IComputation::compute().

◆ stepProgress()

void IComputation::stepProgress ( ) const
protectedinherited

Member Data Documentation

◆ m_begin_it

std::vector<std::unique_ptr<DiffuseElement> >::iterator DWBAComputation::m_begin_it
private

Definition at line 54 of file DWBAComputation.h.

Referenced by runProtected().

◆ m_end_it

std::vector<std::unique_ptr<DiffuseElement> >::iterator DWBAComputation::m_end_it
private

Definition at line 54 of file DWBAComputation.h.

Referenced by runProtected().

◆ m_layout_contribs

const std::vector<std::unique_ptr<const ParticleLayoutContribution> > DWBAComputation::m_layout_contribs
private

Definition at line 57 of file DWBAComputation.h.

Referenced by runProtected().

◆ m_options

const SimulationOptions& IComputation::m_options
protectedinherited

Definition at line 54 of file IComputation.h.

◆ m_progress

ProgressHandler* IComputation::m_progress
protectedinherited

Definition at line 55 of file IComputation.h.

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

◆ m_progress_counter

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

Definition at line 62 of file IComputation.h.

Referenced by IComputation::setProgressHandler(), and IComputation::stepProgress().

◆ m_re_sample

const reSample& IComputation::m_re_sample
protectedinherited

◆ m_roughness_contrib

const std::unique_ptr<const RoughMultiLayerContribution> DWBAComputation::m_roughness_contrib
private

Definition at line 56 of file DWBAComputation.h.

Referenced by runProtected().

◆ m_specular_contrib

const std::unique_ptr<const GISASSpecularContribution> DWBAComputation::m_specular_contrib
private

Definition at line 55 of file DWBAComputation.h.

Referenced by runProtected().

◆ m_status

ComputationStatus IComputation::m_status
protectedinherited

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