BornAgain  1.18.0
Simulate and fit neutron and x-ray scattering at grazing incidence
Layer.cpp
Go to the documentation of this file.
1 // ************************************************************************** //
2 //
3 // BornAgain: simulate and fit scattering at grazing incidence
4 //
5 //! @file Sample/Multilayer/Layer.cpp
6 //! @brief Implements class Layer.
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/Types/Exceptions.h"
20 
21 //! Constructor of a layer with thickness and material
22 //! @param material: material the layer is made of
23 //! @param thickness: thickness of a layer in nanometers
24 Layer::Layer(Material material, double thickness)
25  : m_material(std::move(material)), m_thickness(thickness)
26 {
27  setName("Layer");
29 }
30 
31 Layer::~Layer() = default;
32 
34 {
35  Layer* p_result = new Layer(m_material, m_thickness);
36  p_result->setName(getName());
37  p_result->m_B_field = m_B_field;
38  p_result->m_n_slices = m_n_slices;
39  for (auto p_layout : layouts())
40  p_result->addLayout(*p_layout);
41  return p_result;
42 }
43 
44 //! Sets layer thickness in nanometers.
45 void Layer::setThickness(double thickness)
46 {
47  if (thickness < 0.)
48  throw Exceptions::DomainErrorException("Layer thickness cannot be negative");
50 }
51 
53 {
54  m_material = std::move(material);
55 }
56 
57 void Layer::addLayout(const ILayout& layout)
58 {
59  ILayout* clone = layout.clone();
62 }
63 
64 std::vector<const ILayout*> Layer::layouts() const
65 {
66  std::vector<const ILayout*> result;
67  for (auto p_layout : m_layouts)
68  result.push_back(p_layout);
69  return result;
70 }
71 
72 std::vector<const INode*> Layer::getChildren() const
73 {
74  std::vector<const INode*> result;
75  for (auto layout : m_layouts)
76  result.push_back(layout);
77  return result;
78 }
79 
80 void Layer::registerThickness(bool make_registered)
81 {
82  if (make_registered) {
83  if (!parameter("Thickness"))
84  registerParameter("Thickness", &m_thickness).setUnit("nm").setNonnegative();
85  } else {
86  removeParameter("Thickness");
87  }
88 }
Defines many exception classes in namespace Exceptionss.
Defines and implements interface class ILayout.
Defines class Layer.
Defines class ParameterPool.
Defines class RealParameter.
Pure virtual interface class to equip a sample layer with scattering properties.
Definition: ILayout.h:32
virtual ILayout * clone() const =0
Returns a clone of this ISample object.
void registerChild(INode *node)
Definition: INode.cpp:58
RealParameter & registerParameter(const std::string &name, double *parpointer)
RealParameter * parameter(const std::string &name) const
Returns parameter with given 'name'.
void removeParameter(const std::string &name)
const std::string & getName() const
void setName(const std::string &name)
A layer, with thickness (in nanometer) and material.
Definition: Layer.h:28
double thickness() const
Definition: Layer.h:39
const Material * material() const override final
Returns nullptr, unless overwritten to return a specific material.
Definition: Layer.h:41
std::vector< const INode * > getChildren() const override final
Returns a vector of children (const).
Definition: Layer.cpp:72
kvector_t m_B_field
cached value of magnetic induction
Definition: Layer.h:57
double m_thickness
layer thickness in nanometers
Definition: Layer.h:58
~Layer() override
Layer * clone() const override final
Returns a clone of this ISample object.
Definition: Layer.cpp:33
void addLayout(const ILayout &decoration)
Definition: Layer.cpp:57
void setMaterial(Material material)
Definition: Layer.cpp:52
void setThickness(double thickness)
Sets layer thickness in nanometers.
Definition: Layer.cpp:45
unsigned int m_n_slices
number of slices to create for graded layer approach
Definition: Layer.h:60
Material m_material
material
Definition: Layer.h:56
Layer(Material material, double thickness=0)
Constructor of a layer with thickness and material.
Definition: Layer.cpp:24
void registerThickness(bool make_registered=true)
Definition: Layer.cpp:80
std::vector< const ILayout * > layouts() const
Definition: Layer.cpp:64
SafePointerVector< ILayout > m_layouts
independent layouts in this layer
Definition: Layer.h:59
A wrapper for underlying material implementation.
Definition: Material.h:29
RealParameter & setNonnegative()
RealParameter & setUnit(const std::string &name)
void push_back(T *pointer)