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

Description

A layer in a MultiLayer sample.

Definition at line 26 of file Layer.h.

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

Public Member Functions

 Layer (Material material, double thickness=0)
 Constructor of a layer with thickness and material. More...
 
 ~Layer () override
 
void addLayout (const ParticleLayout &layout)
 
void checkNodeArgs () const
 Raises exception if a parameter value is invalid. More...
 
std::string className () const final
 Returns the class name, to be hard-coded in each leaf class that inherits from INode. More...
 
Layerclone () const override
 Returns a clone of this ISampleNode object. More...
 
std::vector< const Material * > containedMaterials () const
 Returns set of unique materials contained in this ISampleNode. More...
 
bool isMagnetic () const
 Returns true if there is any magnetic material in this ISampleNode. More...
 
std::vector< const ParticleLayout * > layouts () const
 
const Materialmaterial () const override
 Returns nullptr, unless overwritten to return a specific material. More...
 
std::vector< const INode * > nodeChildren () const override
 Returns all children. More...
 
std::vector< const INode * > nodeOffspring () const
 Returns all descendants. More...
 
size_t numberOfLayouts () const
 
unsigned int numberOfSlices () const
 
std::vector< ParaMetaparDefs () const final
 Returns the parameter definitions, to be hard-coded in each leaf class. More...
 
void setNumberOfSlices (unsigned int n_slices)
 
double thickness () const
 
virtual void transferToCPP ()
 Used for Python overriding of clone (see swig/tweaks.py) More...
 

Protected Attributes

std::vector< double > m_P
 

Private Attributes

R3 m_B_field
 cached value of magnetic induction More...
 
std::vector< std::unique_ptr< ParticleLayout > > m_layouts
 independent layouts in this layer More...
 
Material m_material
 material More...
 
unsigned int m_n_slices = 1
 number of slices to create for graded layer approach More...
 
double m_thickness
 layer thickness in nanometers More...
 

Constructor & Destructor Documentation

◆ Layer()

Layer::Layer ( Material  material,
double  thickness = 0 
)

Constructor of a layer with thickness and material.

Parameters
materialmaterial the layer is made of
thicknessthickness of a layer in nanometers

Definition at line 21 of file Layer.cpp.

22  : m_material(std::move(material))
24 {
25  if (thickness < 0.)
26  throw std::runtime_error("Layer thickness cannot be negative");
27 }
double thickness() const
Definition: Layer.h:41
double m_thickness
layer thickness in nanometers
Definition: Layer.h:53
Material m_material
material
Definition: Layer.h:51
const Material * material() const override
Returns nullptr, unless overwritten to return a specific material.
Definition: Layer.h:39

References thickness().

Referenced by clone().

Here is the call graph for this function:

◆ ~Layer()

Layer::~Layer ( )
overridedefault

Member Function Documentation

◆ addLayout()

void Layer::addLayout ( const ParticleLayout layout)

Definition at line 49 of file Layer.cpp.

50 {
51  m_layouts.emplace_back(layout.clone());
52 }
std::vector< std::unique_ptr< ParticleLayout > > m_layouts
independent layouts in this layer
Definition: Layer.h:54
ParticleLayout * clone() const override
Returns a clone of this ISampleNode object.

References ParticleLayout::clone(), and m_layouts.

Referenced by ExemplarySamples::createBasic2DLattice(), ExemplarySamples::createBasic2DParaCrystalWithFTDis(), ExemplarySamples::createBoxesSquareLattice2D(), ExemplarySamples::createCenteredSquareLattice2D(), ExemplarySamples::createCoreShellBoxRotateZandY(), ExemplarySamples::createCoreShellParticle(), ExemplarySamples::createCosineRipple(), ExemplarySamples::createCustomMorphology(), ExemplarySamples::createCylindersAndPrisms(), ExemplarySamples::createCylindersInBA(), ExemplarySamples::createCylindersInDWBA(), ExemplarySamples::createFiniteSquareLattice2D(), ExemplarySamples::createHardDisk(), ExemplarySamples::createHexParaCrystal(), ExemplarySamples::createLargeCylindersInDWBA(), ExemplarySamples::createLattice1D(), ExemplarySamples::createLayersWithAbsorptionBySLD(), ExemplarySamples::createLayersWithAbsorptionWithFF(), ExemplarySamples::createMagneticCylinders(), ExemplarySamples::createMagneticLayer(), ExemplarySamples::createMagneticParticleZeroField(), ExemplarySamples::createMagneticRotation(), ExemplarySamples::createMagneticSpheres(), ExemplarySamples::createMagneticSubstrateZeroField(), ExemplarySamples::createMesoCrystal(), ExemplarySamples::createMultipleLayout(), ExemplarySamples::createParticleComposition(), ExemplarySamples::createParticleInVacuumWithFF(), ExemplarySamples::createRadialParaCrystal(), ExemplarySamples::createRectParaCrystal(), ExemplarySamples::createRotatedPyramids(), ExemplarySamples::createRotatedSquareLattice2D(), ExemplarySamples::createSizeDistributionDAModel(), ExemplarySamples::createSizeDistributionLMAModel(), ExemplarySamples::createSizeDistributionSSCAModel(), ExemplarySamples::createSLDSlicedCylinders(), ExemplarySamples::createSlicedComposition(), ExemplarySamples::createSlicedCylinders(), ExemplarySamples::createSquareLattice2D(), ExemplarySamples::createSuperLattice(), ExemplarySamples::createTransformBox(), and ExemplarySamples::createTriangularRipple().

Here is the call graph for this function:

◆ checkNodeArgs()

void INode::checkNodeArgs ( ) const
inherited

Raises exception if a parameter value is invalid.

Definition at line 27 of file INode.cpp.

28 {
29  size_t nP = m_P.size();
30  if (parDefs().size() != nP) {
31  std::cerr << "BUG in class " << className() << std::endl;
32  std::cerr << "#m_P = " << nP << std::endl;
33  std::cerr << "#PDf = " << parDefs().size() << std::endl;
34  for (const ParaMeta& pm : parDefs())
35  std::cerr << " PDf: " << pm.name << std::endl;
36  ASSERT(0);
37  }
38  ASSERT(parDefs().size() == nP);
39  for (size_t i = 0; i < nP; ++i) {
40  const ParaMeta pm = parDefs()[i];
41 
43  if (pm.vMin == -INF) {
44  ASSERT(pm.vMax == +INF);
45  // nothing to do
46  } else if (pm.vMax == +INF) {
47  ASSERT(pm.vMin == 0);
48  limits = RealLimits::nonnegative();
49  } else {
50  limits = RealLimits::limited(pm.vMin, pm.vMax);
51  }
52  limits.check(pm.name, m_P[i]);
53  }
54 }
#define ASSERT(condition)
Definition: Assert.h:45
const double INF
Definition: INode.h:26
virtual std::vector< ParaMeta > parDefs() const
Returns the parameter definitions, to be hard-coded in each leaf class.
Definition: INode.h:51
std::vector< double > m_P
Definition: INode.h:63
virtual std::string className() const =0
Returns the class name, to be hard-coded in each leaf class that inherits from INode.
Limits for a real fit parameter.
Definition: RealLimits.h:24
static RealLimits limitless()
Creates an object without bounds (default)
Definition: RealLimits.cpp:139
void check(const std::string &name, double value) const
Throws if value is outside limits. Parameter 'name' is for exception message.
Definition: RealLimits.cpp:170
static RealLimits nonnegative()
Creates an object which can have only positive values with 0. included.
Definition: RealLimits.cpp:124
static RealLimits limited(double left_bound_value, double right_bound_value)
Creates an object bounded from the left and right.
Definition: RealLimits.cpp:134
Metadata of one model parameter.
Definition: INode.h:29
double vMin
Definition: INode.h:33
double vMax
Definition: INode.h:34
std::string name
Definition: INode.h:30

References ASSERT, RealLimits::check(), INode::className(), INF, RealLimits::limited(), RealLimits::limitless(), INode::m_P, ParaMeta::name, RealLimits::nonnegative(), INode::parDefs(), ParaMeta::vMax, and ParaMeta::vMin.

Referenced by BarGauss::BarGauss(), BarLorentz::BarLorentz(), Bipyramid4::Bipyramid4(), Box::Box(), CantellatedCube::CantellatedCube(), Cone::Cone(), ConstantBackground::ConstantBackground(), CosineRippleBox::CosineRippleBox(), CosineRippleGauss::CosineRippleGauss(), CosineRippleLorentz::CosineRippleLorentz(), Cylinder::Cylinder(), DistributionCosine::DistributionCosine(), DistributionGate::DistributionGate(), DistributionGaussian::DistributionGaussian(), DistributionLogNormal::DistributionLogNormal(), DistributionLorentz::DistributionLorentz(), DistributionTrapezoid::DistributionTrapezoid(), Dodecahedron::Dodecahedron(), EllipsoidalCylinder::EllipsoidalCylinder(), FootprintGauss::FootprintGauss(), FootprintSquare::FootprintSquare(), FuzzySphere::FuzzySphere(), GaussSphere::GaussSphere(), HemiEllipsoid::HemiEllipsoid(), HollowSphere::HollowSphere(), HorizontalCylinder::HorizontalCylinder(), Icosahedron::Icosahedron(), LongBoxGauss::LongBoxGauss(), LongBoxLorentz::LongBoxLorentz(), PlatonicOctahedron::PlatonicOctahedron(), PlatonicTetrahedron::PlatonicTetrahedron(), Prism3::Prism3(), Prism6::Prism6(), Profile1DCauchy::Profile1DCauchy(), Profile1DCosine::Profile1DCosine(), Profile1DGate::Profile1DGate(), Profile1DGauss::Profile1DGauss(), Profile1DTriangle::Profile1DTriangle(), Profile1DVoigt::Profile1DVoigt(), Profile2DCauchy::Profile2DCauchy(), Profile2DCone::Profile2DCone(), Profile2DGate::Profile2DGate(), Profile2DGauss::Profile2DGauss(), Profile2DVoigt::Profile2DVoigt(), Pyramid2::Pyramid2(), Pyramid3::Pyramid3(), Pyramid4::Pyramid4(), Pyramid6::Pyramid6(), RotationEuler::RotationEuler(), RotationX::RotationX(), RotationY::RotationY(), RotationZ::RotationZ(), SawtoothRippleBox::SawtoothRippleBox(), SawtoothRippleGauss::SawtoothRippleGauss(), SawtoothRippleLorentz::SawtoothRippleLorentz(), Sphere::Sphere(), Spheroid::Spheroid(), TruncatedCube::TruncatedCube(), TruncatedSphere::TruncatedSphere(), and TruncatedSpheroid::TruncatedSpheroid().

Here is the call graph for this function:

◆ className()

std::string Layer::className ( ) const
inlinefinalvirtual

Returns the class name, to be hard-coded in each leaf class that inherits from INode.

Implements INode.

Definition at line 32 of file Layer.h.

32 { return "Layer"; }

◆ clone()

Layer * Layer::clone ( ) const
overridevirtual

Returns a clone of this ISampleNode object.

Implements ISampleNode.

Definition at line 31 of file Layer.cpp.

32 {
33  auto* result = new Layer(m_material, m_thickness);
34  result->m_B_field = m_B_field;
35  result->m_n_slices = m_n_slices;
36  for (const auto* layout : layouts())
37  result->addLayout(*layout);
38  return result;
39 }
std::vector< const ParticleLayout * > layouts() const
Definition: Layer.cpp:54
unsigned int m_n_slices
number of slices to create for graded layer approach
Definition: Layer.h:55
Layer(Material material, double thickness=0)
Constructor of a layer with thickness and material.
Definition: Layer.cpp:21
R3 m_B_field
cached value of magnetic induction
Definition: Layer.h:52

References Layer(), layouts(), m_B_field, m_material, m_n_slices, and m_thickness.

Referenced by MultiLayer::addLayerWithTopRoughness().

Here is the call graph for this function:

◆ containedMaterials()

std::vector< const Material * > ISampleNode::containedMaterials ( ) const
inherited

Returns set of unique materials contained in this ISampleNode.

Definition at line 25 of file ISampleNode.cpp.

26 {
27  std::vector<const Material*> result;
28  if (const Material* p_material = material())
29  result.push_back(p_material);
30  for (const auto* child : nodeChildren()) {
31  if (const auto* sample = dynamic_cast<const ISampleNode*>(child)) {
32  for (const Material* p_material : sample->containedMaterials())
33  result.push_back(p_material);
34  }
35  }
36  return result;
37 }
virtual std::vector< const INode * > nodeChildren() const
Returns all children.
Definition: INode.cpp:56
Abstract base class for sample components and properties related to scattering.
Definition: ISampleNode.h:27
virtual const Material * material() const
Returns nullptr, unless overwritten to return a specific material.
Definition: ISampleNode.h:36
A wrapper for underlying material implementation.
Definition: Material.h:35

References ISampleNode::material(), and INode::nodeChildren().

Referenced by SampleUtils::Multilayer::ContainsCompatibleMaterials(), SampleToPython::initLabels(), and ISampleNode::isMagnetic().

Here is the call graph for this function:

◆ isMagnetic()

bool ISampleNode::isMagnetic ( ) const
inherited

Returns true if there is any magnetic material in this ISampleNode.

Definition at line 39 of file ISampleNode.cpp.

40 {
41  const auto materials = containedMaterials();
42  return std::any_of(materials.cbegin(), materials.cend(),
43  [](const Material* mat) { return mat->isMagneticMaterial(); });
44 }
std::vector< const Material * > containedMaterials() const
Returns set of unique materials contained in this ISampleNode.
Definition: ISampleNode.cpp:25

References ISampleNode::containedMaterials().

Referenced by reSample::make().

Here is the call graph for this function:

◆ layouts()

std::vector< const ParticleLayout * > Layer::layouts ( ) const

Definition at line 54 of file Layer.cpp.

55 {
56  std::vector<const ParticleLayout*> result;
57  for (const auto& layout : m_layouts)
58  result.push_back(layout.get());
59  return result;
60 }

References m_layouts.

Referenced by clone(), and Compute::Slicing::particleRegions().

◆ material()

const Material* Layer::material ( ) const
inlineoverridevirtual

Returns nullptr, unless overwritten to return a specific material.

Reimplemented from ISampleNode.

Definition at line 39 of file Layer.h.

39 { return &m_material; }

References m_material.

◆ nodeChildren()

std::vector< const INode * > Layer::nodeChildren ( ) const
overridevirtual

Returns all children.

Reimplemented from INode.

Definition at line 41 of file Layer.cpp.

42 {
43  std::vector<const INode*> result;
44  for (const auto& layout : m_layouts)
45  result.push_back(layout.get());
46  return result;
47 }

References m_layouts.

◆ nodeOffspring()

std::vector< const INode * > INode::nodeOffspring ( ) const
inherited

Returns all descendants.

Definition at line 61 of file INode.cpp.

62 {
63  std::vector<const INode*> result;
64  result.push_back(this);
65  for (const auto* child : nodeChildren()) {
66  for (const auto* p : child->nodeOffspring())
67  result.push_back(p);
68  }
69  return result;
70 }

References INode::nodeChildren().

Here is the call graph for this function:

◆ numberOfLayouts()

size_t Layer::numberOfLayouts ( ) const
inline

Definition at line 44 of file Layer.h.

44 { return m_layouts.size(); }

References m_layouts.

◆ numberOfSlices()

unsigned int Layer::numberOfSlices ( ) const
inline

Definition at line 48 of file Layer.h.

48 { return m_n_slices; }

References m_n_slices.

◆ parDefs()

std::vector<ParaMeta> Layer::parDefs ( ) const
inlinefinalvirtual

Returns the parameter definitions, to be hard-coded in each leaf class.

Reimplemented from INode.

Definition at line 33 of file Layer.h.

34  {
35  return {{"Thickness", "nm", "thickness", 0, +INF, 0}};
36  }

References INF.

◆ setNumberOfSlices()

void Layer::setNumberOfSlices ( unsigned int  n_slices)
inline

Definition at line 47 of file Layer.h.

47 { m_n_slices = n_slices; }

References m_n_slices.

Referenced by ExemplarySamples::createSLDSlicedCylinders(), and ExemplarySamples::createSlicedCylinders().

◆ thickness()

double Layer::thickness ( ) const
inline

Definition at line 41 of file Layer.h.

41 { return m_thickness; }

References m_thickness.

Referenced by Layer(), and MultiLayer::addLayerWithTopRoughness().

◆ transferToCPP()

virtual void ICloneable::transferToCPP ( )
inlinevirtualinherited

Used for Python overriding of clone (see swig/tweaks.py)

Definition at line 32 of file ICloneable.h.

Member Data Documentation

◆ m_B_field

R3 Layer::m_B_field
private

cached value of magnetic induction

Definition at line 52 of file Layer.h.

Referenced by clone().

◆ m_layouts

std::vector<std::unique_ptr<ParticleLayout> > Layer::m_layouts
private

independent layouts in this layer

Definition at line 54 of file Layer.h.

Referenced by addLayout(), layouts(), nodeChildren(), and numberOfLayouts().

◆ m_material

Material Layer::m_material
private

material

Definition at line 51 of file Layer.h.

Referenced by clone(), and material().

◆ m_n_slices

unsigned int Layer::m_n_slices = 1
private

number of slices to create for graded layer approach

Definition at line 55 of file Layer.h.

Referenced by clone(), numberOfSlices(), and setNumberOfSlices().

◆ m_P

◆ m_thickness

double Layer::m_thickness
private

layer thickness in nanometers

Definition at line 53 of file Layer.h.

Referenced by clone(), and thickness().


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