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

Description

Performs a single-threaded depth probe computation with given sample.

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

Definition at line 33 of file DepthProbeComputation.h.

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

Public Member Functions

 DepthProbeComputation (const reSample &re_sample, const SimulationOptions &options, ProgressHandler &progress, DepthProbeElementIter begin_it, DepthProbeElementIter end_it)
 
 ~DepthProbeComputation () 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 DepthProbeElementIter = std::vector< DepthProbeElement >::iterator
 

Private Member Functions

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

Private Attributes

DepthProbeElementIter m_begin_it
 
DepthProbeElementIter m_end_it
 
std::unique_ptr< DelayedProgressCounterm_progress_counter
 

Member Typedef Documentation

◆ DepthProbeElementIter

using DepthProbeComputation::DepthProbeElementIter = std::vector<DepthProbeElement>::iterator
private

Definition at line 34 of file DepthProbeComputation.h.

Constructor & Destructor Documentation

◆ DepthProbeComputation()

DepthProbeComputation::DepthProbeComputation ( const reSample re_sample,
const SimulationOptions options,
ProgressHandler progress,
DepthProbeElementIter  begin_it,
DepthProbeElementIter  end_it 
)

Definition at line 23 of file DepthProbeComputation.cpp.

28  : IComputation(re_sample, options, progress)
29  , m_begin_it(begin_it)
30  , m_end_it(end_it)
31 {
32 }
DepthProbeElementIter m_begin_it
DepthProbeElementIter m_end_it
IComputation(const reSample &re_sample, const SimulationOptions &options, ProgressHandler &progress)

◆ ~DepthProbeComputation()

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

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

Implements IComputation.

Definition at line 36 of file DepthProbeComputation.cpp.

37 {
38  for (auto it = m_begin_it; it != m_end_it; ++it) {
39  DepthProbeElement& ele = *it;
40  if (!ele.isCalculated())
41  continue;
42 
43  const IAxis& z_positions = *ele.getZPositions();
44  const size_t n_z = z_positions.size();
45  const size_t n_layers = m_re_sample.numberOfSlices();
46  size_t start_z_ind = n_z;
47  std::valarray<double> intensities(0.0, n_z);
48 
50 
51  double z_layer_bottom(0.0);
52  double z_layer_top(0.0);
53  for (size_t i_layer = 0; i_layer < n_layers && start_z_ind != 0; ++i_layer) {
54  z_layer_bottom = m_re_sample.sliceBottomZ(i_layer);
55  z_layer_top = i_layer ? m_re_sample.sliceTopZ(i_layer) : 0;
56 
57  // get R & T coefficients for current layer
58  const auto* flux = dynamic_cast<const ScalarFlux*>(fluxes[i_layer].get());
59  ASSERT(flux);
60  const complex_t R = flux->getScalarR();
61  const complex_t T = flux->getScalarT();
62  const complex_t kz_out = flux->getScalarKz();
63  const complex_t kz_in = -kz_out;
64 
65  // Compute intensity for z's of the layer
66  size_t ip1_z = start_z_ind;
67  for (; ip1_z > 0; --ip1_z) {
68  const size_t i_z = ip1_z - 1;
69  if (i_layer + 1 != n_layers && z_positions[i_z] <= z_layer_bottom)
70  break;
71  const double z = z_positions[i_z] - z_layer_top;
72  intensities[i_z] = std::norm(R * exp_I(kz_out * z) + T * exp_I(kz_in * z));
73  }
74  start_z_ind = ip1_z;
75  }
76  ele.setIntensities(std::move(intensities));
77 
78  stepProgress();
79  }
80 }
#define ASSERT(condition)
Definition: Assert.h:45
std::vector< std::unique_ptr< const IFlux > > Fluxes
void setIntensities(T &&intensities)
const IAxis * getZPositions() const
bool isCalculated() const
Abstract base class for one-dimensional axes.
Definition: IAxis.h:27
virtual size_t size() const =0
Returns the number of bins.
const reSample & m_re_sample
Definition: IComputation.h:53
void stepProgress() const
Specular reflection and transmission coefficients in a layer in case of scalar interactions between t...
Definition: ScalarFlux.h:29
size_t numberOfSlices() const
Definition: ReSample.cpp:336
double sliceTopZ(size_t i) const
Definition: ReSample.cpp:356
Fluxes fluxesIn(const R3 &k) const
Definition: ReSample.cpp:384
double sliceBottomZ(size_t i) const
Definition: ReSample.cpp:361
Fluxes fluxes(const SliceStack &slices, const R3 &k, bool forward)
Computes refraction angle reflection/transmission coefficients for given sliced sample and wavevector...
constexpr Double_t R()
Definition: TMath.h:213

References ASSERT, Compute::SpecularMagnetic::fluxes(), reSample::fluxesIn(), DepthProbeElement::getKi(), DepthProbeElement::getZPositions(), DepthProbeElement::isCalculated(), m_begin_it, m_end_it, IComputation::m_re_sample, reSample::numberOfSlices(), TMath::R(), DepthProbeElement::setIntensities(), IAxis::size(), reSample::sliceBottomZ(), reSample::sliceTopZ(), 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

Definition at line 35 of file IComputation.cpp.

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

References IComputation::m_progress_counter.

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

Member Data Documentation

◆ m_begin_it

DepthProbeElementIter DepthProbeComputation::m_begin_it
private

Definition at line 45 of file DepthProbeComputation.h.

Referenced by runProtected().

◆ m_end_it

DepthProbeElementIter DepthProbeComputation::m_end_it
private

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