BornAgain  1.19.0
Simulate and fit neutron and x-ray scattering at grazing incidence
SpecularComputation Class Reference

Performs a single-threaded specular computation with given sample. More...

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

Public Member Functions

 SpecularComputation (const MultiLayer &multilayer, const SimulationOptions &options, ProgressHandler &progress, SpecularElementIter begin_it, SpecularElementIter end_it, bool forcePolarized=false)
 
 ~SpecularComputation () override
 
std::string errorMessage () const
 
bool isCompleted () const
 
void run ()
 

Protected Attributes

std::unique_ptr< ProcessedSamplem_processed_sample
 
ProgressHandlerm_progress
 
SimulationOptions m_sim_options
 
ComputationStatus m_status
 

Private Types

using SpecularElementIter = std::vector< SpecularSimulationElement >::iterator
 

Private Member Functions

void runProtected () override
 

Private Attributes

const SpecularElementIter m_begin_it
 these iterators define the span of detector bins this simulation will work on More...
 
std::unique_ptr< SpecularComputationTermm_computation_term
 
const SpecularElementIter m_end_it
 

Detailed Description

Performs a single-threaded specular computation with given sample.

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

Definition at line 35 of file SpecularComputation.h.

Member Typedef Documentation

◆ SpecularElementIter

Definition at line 36 of file SpecularComputation.h.

Constructor & Destructor Documentation

◆ SpecularComputation()

SpecularComputation::SpecularComputation ( const MultiLayer multilayer,
const SimulationOptions options,
ProgressHandler progress,
SpecularElementIter  begin_it,
SpecularElementIter  end_it,
bool  forcePolarized = false 
)

Definition at line 27 of file SpecularComputation.cpp.

31  : IComputation(multilayer, options, progress), m_begin_it(begin_it), m_end_it(end_it)
32 {
33  if (m_processed_sample->containsMagneticMaterial()
34  || m_processed_sample->externalField() != kvector_t{}
35  || forcePolarized)
36 
37  m_computation_term.reset(
38  new SpecularMatrixTerm(SpecularStrategyBuilder::build(multilayer, true)));
39  else
40  m_computation_term.reset(
41  new SpecularScalarTerm(SpecularStrategyBuilder::build(multilayer, false)));
42 }
IComputation(const MultiLayer &sample, const SimulationOptions &options, ProgressHandler &progress, bool forcePolarized=false)
std::unique_ptr< ProcessedSample > m_processed_sample
Definition: IComputation.h:54
std::unique_ptr< SpecularComputationTerm > m_computation_term
const SpecularElementIter m_begin_it
these iterators define the span of detector bins this simulation will work on
const SpecularElementIter m_end_it
Computes the specular scattering for a magnetic sample Used by SpecularComputation.
Computes the specular scattering for a scalar sample Used by SpecularComputation.
static std::unique_ptr< ISpecularStrategy > build(const MultiLayer &sample, const bool magnetic)

References SpecularStrategyBuilder::build(), m_computation_term, and IComputation::m_processed_sample.

Here is the call graph for this function:

◆ ~SpecularComputation()

SpecularComputation::~SpecularComputation ( )
overridedefault

Member Function Documentation

◆ errorMessage()

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

Definition at line 48 of file IComputation.h.

48 { return m_status.errorMessage(); }
std::string errorMessage() const
ComputationStatus m_status
Definition: IComputation.h:53

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

Here is the call graph for this function:

◆ isCompleted()

bool IComputation::isCompleted ( ) const
inlineinherited

Definition at line 47 of file IComputation.h.

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

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

Here is the call graph for this function:

◆ run()

void IComputation::run ( )
inherited

Definition at line 31 of file IComputation.cpp.

32 {
34  try {
35  runProtected();
37  } catch (const std::exception& ex) {
38  m_status.setFailed(ex.what());
39  }
40 }
void setFailed(const std::string &message)
virtual void runProtected()=0

References IComputation::m_status, IComputation::runProtected(), ComputationStatus::setCompleted(), ComputationStatus::setFailed(), and ComputationStatus::setRunning().

Here is the call graph for this function:

◆ runProtected()

void SpecularComputation::runProtected ( )
overrideprivatevirtual

Implements IComputation.

Definition at line 46 of file SpecularComputation.cpp.

47 {
48  if (!m_progress->alive())
49  return;
50 
51  m_computation_term->setProgressHandler(m_progress);
52  auto& slices = m_processed_sample->averageSlices();
53  for (auto it = m_begin_it; it != m_end_it; ++it)
54  m_computation_term->computeIntensity(*it, slices);
55 }
ProgressHandler * m_progress
Definition: IComputation.h:52

References ProgressHandler::alive(), m_begin_it, m_computation_term, m_end_it, IComputation::m_processed_sample, and IComputation::m_progress.

Here is the call graph for this function:

Member Data Documentation

◆ m_begin_it

const SpecularElementIter SpecularComputation::m_begin_it
private

these iterators define the span of detector bins this simulation will work on

Definition at line 48 of file SpecularComputation.h.

Referenced by runProtected().

◆ m_computation_term

std::unique_ptr<SpecularComputationTerm> SpecularComputation::m_computation_term
mutableprivate

Definition at line 49 of file SpecularComputation.h.

Referenced by SpecularComputation(), and runProtected().

◆ m_end_it

const SpecularElementIter SpecularComputation::m_end_it
private

Definition at line 48 of file SpecularComputation.h.

Referenced by runProtected().

◆ m_processed_sample

std::unique_ptr<ProcessedSample> IComputation::m_processed_sample
protectedinherited

◆ m_progress

ProgressHandler* IComputation::m_progress
protectedinherited

◆ m_sim_options

SimulationOptions IComputation::m_sim_options
protectedinherited

Definition at line 51 of file IComputation.h.

Referenced by DWBAComputation::DWBAComputation().

◆ m_status

ComputationStatus IComputation::m_status
protectedinherited

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