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

Helper class for the graded layer approximation. More...

Public Member Functions

 LayerFillLimits (std::vector< double > layers_bottomz)
 
std::vector< ZLimitslayerZLimits () const
 Returns the filled region limits for each layer (in local layer coordinates) More...
 
void update (ParticleLimits particle_limits, double offset=0.0)
 Particle limits are given in global coordinates. More...
 

Private Member Functions

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

Private Attributes

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

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 35 of file LayerFillLimits.h.

Constructor & Destructor Documentation

◆ LayerFillLimits()

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

Definition at line 23 of file LayerFillLimits.cpp.

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

Member Function Documentation

◆ layerIndexBottom()

size_t LayerFillLimits::layerIndexBottom ( double  bottom_z) const
private

Definition at line 62 of file LayerFillLimits.cpp.

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

References m_layers_bottomz.

Referenced by update().

◆ layerIndexTop()

size_t LayerFillLimits::layerIndexTop ( double  top_z) const
private

Definition at line 52 of file LayerFillLimits.cpp.

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

References m_layers_bottomz.

Referenced by update().

◆ layerZLimits()

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

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

Definition at line 47 of file LayerFillLimits.cpp.

48 {
49  return m_layer_fill_limits;
50 }

References m_layer_fill_limits.

◆ update()

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

Particle limits are given in global coordinates.

Definition at line 29 of file LayerFillLimits.cpp.

30 {
31  if (m_layers_bottomz.empty())
32  return; // do nothing for the single layer case
33  double top = particle_limits.m_top + offset;
34  double bottom = particle_limits.m_bottom + offset;
35  if (bottom > top)
36  throw std::runtime_error("LayerFillLimits::update: lower_limit > upper_limit.");
37  if (bottom == top) // zero-size particle
38  return;
39  size_t top_index = layerIndexTop(top);
40  size_t bottom_index = layerIndexBottom(bottom);
41  for (size_t i_layer = top_index; i_layer < bottom_index + 1; ++i_layer) {
42  ZLimits limits(bottom, top);
43  updateLayerLimits(i_layer, limits);
44  }
45 }
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:45
double m_top
Definition: ZLimits.h:28
double m_bottom
Definition: ZLimits.h:27

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

Here is the call graph for this function:

◆ updateLayerLimits()

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

Definition at line 73 of file LayerFillLimits.cpp.

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

References 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_layer_fill_limits

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

Definition at line 50 of file LayerFillLimits.h.

Referenced by layerZLimits(), and updateLayerLimits().

◆ m_layers_bottomz

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

Definition at line 49 of file LayerFillLimits.h.

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


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