BornAgain  1.18.0
Simulate and fit neutron and x-ray scattering at grazing incidence
LayerFillLimits Class Reference
Collaboration diagram for LayerFillLimits:

Public Member Functions

 LayerFillLimits (std::vector< double > layers_bottomz)
 
void update (ParticleLimits particle_limits, double offset=0.0)
 
std::vector< ZLimitslayerZLimits () const
 

Private Member Functions

size_t layerIndexTop (double top_z) const
 
size_t layerIndexBottom (double bottom_z) const
 
void updateLayerLimits (size_t i_layer, ZLimits limits)
 

Private Attributes

std::vector< double > m_layers_bottomz
 
std::vector< ZLimitsm_layer_fill_limits
 

Detailed Description

Helper class for the graded layer approximation.

Generates limits for each layer, indicating the region of the layer (along z) that contains particle(s)

The constructor takes the bottom layer z-coordinates as parameter. This means that for N layers, only N-1 coordinates need to be passed (the last layer is assumed to be semi-infinite).

Definition at line 30 of file LayerFillLimits.h.

Constructor & Destructor Documentation

◆ LayerFillLimits()

LayerFillLimits::LayerFillLimits ( std::vector< double >  layers_bottomz)

Definition at line 24 of file LayerFillLimits.cpp.

25  : m_layers_bottomz(std::move(layers_bottomz)), m_layer_fill_limits(m_layers_bottomz.size() + 1)
26 // default ZLimits designate an absence of limits
27 {
28 }
std::vector< ZLimits > m_layer_fill_limits
std::vector< double > m_layers_bottomz

Member Function Documentation

◆ update()

void LayerFillLimits::update ( ParticleLimits  particle_limits,
double  offset = 0.0 
)

Particle limits are given in global coordinates.

Definition at line 30 of file LayerFillLimits.cpp.

31 {
32  if (m_layers_bottomz.empty())
33  return; // do nothing for the single layer case
34  double top = particle_limits.m_top + offset;
35  double bottom = particle_limits.m_bottom + offset;
36  if (bottom > top)
37  throw std::runtime_error("LayerFillLimits::update: lower_limit > upper_limit.");
38  if (bottom == top) // zero-size particle
39  return;
40  size_t top_index = layerIndexTop(top);
41  size_t bottom_index = layerIndexBottom(bottom);
42  for (size_t i_layer = top_index; i_layer < bottom_index + 1; ++i_layer) {
43  ZLimits limits(bottom, top);
44  updateLayerLimits(i_layer, limits);
45  }
46 }
void updateLayerLimits(size_t i_layer, ZLimits limits)
size_t layerIndexTop(double top_z) const
size_t layerIndexBottom(double bottom_z) const
Class that contains upper and lower limits of the z-coordinate for the slicing of form factors.
Definition: ZLimits.h:41
double m_top
Definition: ZLimits.h:23
double m_bottom
Definition: ZLimits.h:22

References layerIndexBottom(), layerIndexTop(), ParticleLimits::m_bottom, m_layers_bottomz, ParticleLimits::m_top, and updateLayerLimits().

Referenced by MultiLayerUtils::ParticleRegions().

Here is the call graph for this function:

◆ layerZLimits()

std::vector< ZLimits > LayerFillLimits::layerZLimits ( ) const

Returns the filled region limits for each layer (in local layer coordinates)

Definition at line 48 of file LayerFillLimits.cpp.

49 {
50  return m_layer_fill_limits;
51 }

References m_layer_fill_limits.

Referenced by MultiLayerUtils::ParticleRegions().

◆ layerIndexTop()

size_t LayerFillLimits::layerIndexTop ( double  top_z) const
private

Definition at line 53 of file LayerFillLimits.cpp.

54 {
55  if (m_layers_bottomz.empty())
56  return 0;
57  if (top_z <= m_layers_bottomz.back())
58  return m_layers_bottomz.size();
59  auto index_above = std::lower_bound(m_layers_bottomz.rbegin(), m_layers_bottomz.rend(), top_z);
60  return static_cast<size_t>(m_layers_bottomz.rend() - index_above);
61 }

References m_layers_bottomz.

Referenced by update().

◆ layerIndexBottom()

size_t LayerFillLimits::layerIndexBottom ( double  bottom_z) const
private

Definition at line 63 of file LayerFillLimits.cpp.

64 {
65  if (m_layers_bottomz.empty())
66  return 0;
67  if (bottom_z < m_layers_bottomz.back())
68  return m_layers_bottomz.size();
69  auto index_below =
70  std::upper_bound(m_layers_bottomz.rbegin(), m_layers_bottomz.rend(), bottom_z);
71  return static_cast<size_t>(m_layers_bottomz.rend() - index_below);
72 }

References m_layers_bottomz.

Referenced by update().

◆ updateLayerLimits()

void LayerFillLimits::updateLayerLimits ( size_t  i_layer,
ZLimits  limits 
)
private

Definition at line 74 of file LayerFillLimits.cpp.

75 {
76  if (!limits.isFinite())
77  throw std::runtime_error("LayerFillLimits::updateLayerLimits: given limits are not "
78  "finite.");
79  auto old_limits = m_layer_fill_limits[i_layer];
80  double layer_ref = i_layer ? m_layers_bottomz[i_layer - 1] : m_layers_bottomz[i_layer];
81  double upper =
82  i_layer ? std::min(limits.upperLimit().m_value, layer_ref) : limits.upperLimit().m_value;
83  double lower = (i_layer == m_layer_fill_limits.size() - 1)
84  ? limits.lowerLimit().m_value
85  : std::max(limits.lowerLimit().m_value, m_layers_bottomz[i_layer]);
86  ZLimits bounded_limits(lower - layer_ref, upper - layer_ref);
87  m_layer_fill_limits[i_layer] = CalculateNewLayerLimits(old_limits, bounded_limits);
88 }
OneSidedLimit lowerLimit() const
Definition: ZLimits.cpp:39
OneSidedLimit upperLimit() const
Definition: ZLimits.cpp:44
bool isFinite() const
Definition: ZLimits.cpp:32
ZLimits CalculateNewLayerLimits(ZLimits old_limits, ZLimits bounded_limits)
double m_value
Definition: ZLimits.h:32

References anonymous_namespace{LayerFillLimits.cpp}::CalculateNewLayerLimits(), ZLimits::isFinite(), ZLimits::lowerLimit(), m_layer_fill_limits, m_layers_bottomz, OneSidedLimit::m_value, and ZLimits::upperLimit().

Referenced by update().

Here is the call graph for this function:

Member Data Documentation

◆ m_layers_bottomz

std::vector<double> LayerFillLimits::m_layers_bottomz
private

Definition at line 45 of file LayerFillLimits.h.

Referenced by layerIndexBottom(), layerIndexTop(), update(), and updateLayerLimits().

◆ m_layer_fill_limits

std::vector<ZLimits> LayerFillLimits::m_layer_fill_limits
private

Definition at line 46 of file LayerFillLimits.h.

Referenced by layerZLimits(), and updateLayerLimits().


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