BornAgain  1.19.79
Open-source research software to simulate and fit neutron and x-ray reflectometry and grazing-incidence small-angle scattering
SliceStack.cpp
Go to the documentation of this file.
1 // ************************************************************************************************
2 //
3 // BornAgain: simulate and fit reflection and scattering
4 //
5 //! @file Resample/Slice/SliceStack.cpp
6 //! @brief Implements class SliceStack.
7 //!
8 //! @homepage http://www.bornagainproject.org
9 //! @license GNU General Public License v3 or higher (see COPYING)
10 //! @copyright Forschungszentrum Jülich GmbH 2018
11 //! @authors Scientific Computing Group at MLZ (see CITATION, AUTHORS)
12 //
13 // ************************************************************************************************
14 
16 #include "Base/Util/Assert.h"
17 #include <algorithm>
18 
20  : std::vector<Slice>((std::vector<Slice>)other)
21  , m_roughness_model(other.roughnessModel())
22 {
23 }
24 
25 void SliceStack::addTopSlice(double zbottom, const Material& material)
26 {
27  this->emplace_back(Slice(ZLimits(zbottom, ZLimits::inf), material, {}, nullptr));
28 }
29 
30 void SliceStack::addSlice(double thickness, const Material& material,
31  const LayerRoughness* const roughness)
32 {
33  ASSERT(!this->empty());
34  double top = this->back().zBottom();
35  ASSERT(thickness >= 0);
36  std::unique_ptr<ZLimits> zRange;
37  if (thickness == 0)
38  zRange = std::make_unique<ZLimits>(-ZLimits::inf, top);
39  else
40  zRange = std::make_unique<ZLimits>(top - thickness, top);
41  this->emplace_back(Slice(*zRange, material, {}, roughness));
42 }
43 
44 //! Adds n times the same slice to the stack.
45 
46 void SliceStack::addNSlices(size_t n, double thickness, const Material& material,
47  const LayerRoughness* const roughness)
48 {
49  ASSERT(thickness > 0);
50  ASSERT(n > 0);
51  const double slice_thickness = thickness / n;
52  addSlice(slice_thickness, material, roughness);
53  for (size_t i = 1; i < n; ++i)
54  addSlice(slice_thickness, material);
55 }
56 
57 SliceStack SliceStack::setBField(const R3& externalField)
58 {
59  if (this->empty())
60  return *this;
61  const double M_z0 = this->at(0).material().magnetization().z();
62  const double H_z = externalField.z() + M_z0;
63  for (Slice& slice : *this)
64  slice.initBField(externalField, H_z);
65  return *this;
66 }
67 
69 {
70  return std::any_of(this->cbegin(), this->cend(), [](const Slice& slice) -> bool {
71  return slice.material().isMagneticMaterial();
72  });
73 }
74 
75 const LayerRoughness* SliceStack::bottomRoughness(size_t i_slice) const
76 {
77  if (i_slice + 1 < size())
78  return (*this)[i_slice + 1].topRoughness();
79  return nullptr;
80 }
Defines the macro ASSERT.
#define ASSERT(condition)
Definition: Assert.h:45
Defines class SliceStack.
A roughness of interface between two layers.
A wrapper for underlying material implementation.
Definition: Material.h:35
A stack of Slices.
Definition: SliceStack.h:38
SliceStack(const RoughnessModel roughness_model)
Definition: SliceStack.h:40
SliceStack setBField(const R3 &externalField)
Definition: SliceStack.cpp:57
void addTopSlice(double zbottom, const Material &material)
Definition: SliceStack.cpp:25
void addNSlices(size_t n, double thickness, const Material &material, const LayerRoughness *roughness=nullptr)
Adds n times the same slice to the stack.
Definition: SliceStack.cpp:46
const LayerRoughness * bottomRoughness(size_t i_slice) const
Definition: SliceStack.cpp:75
void addSlice(double thickness, const Material &material, const LayerRoughness *roughness=nullptr)
Definition: SliceStack.cpp:30
bool containsMagneticMaterial() const
Definition: SliceStack.cpp:68
Data structure containing the data of a single slice, for calculating the Fresnel coefficients.
Definition: Slice.h:31
void initBField(R3 h_field, double h_z)
Initializes the magnetic B field from a given ambient field strength H.
Definition: Slice.cpp:93
const Material & material() const
Definition: Slice.cpp:51
An interval. Limits are of type double, and may be infinite. Used for the z-coordinate,...
Definition: ZLimits.h:32
static constexpr double inf
Definition: ZLimits.h:45