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

Description

Performs a single-threaded specular computation with given sample.

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

Definition at line 32 of file SpecularComputation.h.

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

Public Member Functions

 SpecularComputation (const reSample &re_sample, const SimulationOptions &options, ProgressHandler &progress, SpecularElementIter begin_it, SpecularElementIter end_it)
 
 ~SpecularComputation () 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 Types

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

Private Member Functions

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

Private Attributes

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

Member Typedef Documentation

◆ SpecularElementIter

using SpecularComputation::SpecularElementIter = std::vector<SpecularElement>::iterator
private

Definition at line 33 of file SpecularComputation.h.

Constructor & Destructor Documentation

◆ SpecularComputation()

SpecularComputation::SpecularComputation ( const reSample re_sample,
const SimulationOptions options,
ProgressHandler progress,
SpecularElementIter  begin_it,
SpecularElementIter  end_it 
)

Definition at line 23 of file SpecularComputation.cpp.

27  : IComputation(std::move(re_sample), options, progress)
28  , m_begin_it(begin_it)
29  , m_end_it(end_it)
30 {
31 }
IComputation(const reSample &re_sample, const SimulationOptions &options, ProgressHandler &progress)
const SpecularElementIter m_begin_it
these iterators define the span of detector bins this simulation will work on
const SpecularElementIter m_end_it

◆ ~SpecularComputation()

SpecularComputation::~SpecularComputation ( )
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 SpecularComputation::runProtected ( )
overrideprivatevirtual

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

Implements IComputation.

Definition at line 35 of file SpecularComputation.cpp.

36 {
37  const SliceStack& slices = m_re_sample.averageSlices();
38 
39  for (auto it = m_begin_it; it != m_end_it; ++it) {
40  SpecularElement& ele = *it;
41  if (!ele.isCalculated())
42  continue;
43  std::vector<complex_t> kz_stack = ele.produceKz(slices);
44  if (m_re_sample.polarizing()) {
45  const SpinMatrix R = Compute::SpecularMagnetic::topLayerR(slices, kz_stack, true);
46 
47  const auto& polMatrix = ele.polMatrices().polarizerMatrix();
48  const auto& anaMatrix = ele.polMatrices().analyzerMatrix();
49 
50  const complex_t trace = (polMatrix * R.adjoint() * anaMatrix * R).trace();
51 
52  ele.setIntensity(std::abs(trace));
53  } else {
54  const complex_t R = Compute::SpecularScalar::topLayerR(slices, kz_stack);
55  ele.setIntensity(std::norm(R));
56  }
57 
58  stepProgress();
59  }
60 }
const reSample & m_re_sample
Definition: IComputation.h:53
void stepProgress() const
const PolMatrices & polMatrices() const
Returns polarizer and analyzer matrices.
Definition: IElement.h:37
const SpinMatrix & polarizerMatrix() const
Gets the polarization density matrix (in spin basis along z-axis)
Definition: PolMatrices.h:38
const SpinMatrix & analyzerMatrix() const
Gets the polarization analyzer operator (in spin basis along z-axis)
Definition: PolMatrices.h:44
A stack of Slices.
Definition: SliceStack.h:38
Data stucture containing both input and output of a single image pixel for specular simulation.
bool isCalculated() const
Returns calculation flag (if it's false, zero intensity is assigned to the element)
void setIntensity(double intensity)
std::vector< complex_t > produceKz(const SliceStack &slices)
Returns kz values for Abeles computation of reflection/transition coefficients.
bool polarizing() const
Contains magnetic material, or nonzero magnetic field.
Definition: ReSample.cpp:371
const SliceStack & averageSlices() const
Definition: ReSample.cpp:341
SpinMatrix topLayerR(const SliceStack &slices, const std::vector< complex_t > &kzs, bool forward)
Computes the Fresnel R coefficient for the top layer only Introduced in order to speed up pure reflec...
complex_t topLayerR(const SliceStack &slices, const std::vector< complex_t > &kz)
Computes the Fresnel R coefficient for the top layer only. Introduced in order to speed up pure refle...
constexpr Double_t R()
Definition: TMath.h:213

References PolMatrices::analyzerMatrix(), reSample::averageSlices(), SpecularElement::isCalculated(), m_begin_it, m_end_it, IComputation::m_re_sample, PolMatrices::polarizerMatrix(), reSample::polarizing(), IElement::polMatrices(), SpecularElement::produceKz(), TMath::R(), SpecularElement::setIntensity(), IComputation::stepProgress(), Compute::SpecularScalar::topLayerR(), and Compute::SpecularMagnetic::topLayerR().

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

Definition at line 35 of file IComputation.cpp.

36 {
38  m_progress_counter->stepProgress();
39 }

References IComputation::m_progress_counter.

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

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 45 of file SpecularComputation.h.

Referenced by runProtected().

◆ m_end_it

const SpecularElementIter SpecularComputation::m_end_it
private

Definition at line 45 of file SpecularComputation.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 DWBAComputation::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_status

ComputationStatus IComputation::m_status
protectedinherited

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