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

Description

A composition of particles at fixed positions.

Definition at line 24 of file ParticleComposition.h.

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

Public Member Functions

 ParticleComposition ()
 
 ~ParticleComposition () override
 
double abundance () const
 
void addParticle (const IParticle &particle)
 
void addParticle (const IParticle &particle, R3 position)
 
void addParticles (const IParticle &particle, std::vector< R3 > positions)
 
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...
 
ParticleCompositionclone () 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...
 
std::vector< std::unique_ptr< IParticle > > decompose () const override
 Decompose in constituent IParticle objects. More...
 
bool isMagnetic () const
 Returns true if there is any magnetic material in this ISampleNode. More...
 
virtual const Materialmaterial () const
 Returns nullptr, unless overwritten to return a specific material. More...
 
size_t nbrParticles () const
 Returns number of different particles. More...
 
std::vector< const INode * > nodeChildren () const override
 Returns all children. More...
 
std::vector< const INode * > nodeOffspring () const
 Returns all descendants. More...
 
virtual std::vector< ParaMetaparDefs () const
 Returns the parameter definitions, to be hard-coded in each leaf class. More...
 
R3 particlePosition () const
 Returns particle position. More...
 
std::vector< const IParticle * > particles () const
 
IParticlerotate (const IRotation &rotation)
 Rotates the particle, and returns this. More...
 
const IRotationrotation () const
 Returns rotation object. More...
 
void setAbundance (double abundance)
 Sets particle abundance. More...
 
void setParticlePosition (double x, double y, double z)
 Sets relative position of the particle's reference point in the coordinate system of parent. More...
 
void setParticlePosition (R3 position)
 Sets relative position of the particle's reference point in the coordinate system of parent. More...
 
void setRotation (const IRotation &rotation)
 Sets transformation. More...
 
virtual void transferToCPP ()
 Used for Python overriding of clone (see swig/tweaks.py) More...
 
IParticletranslate (R3 translation)
 Translates the particle, and returns this. More...
 

Protected Attributes

double m_abundance {1.0}
 
std::vector< double > m_P
 
R3 m_position
 
std::unique_ptr< IRotationm_rotation
 

Private Attributes

OwningVector< IParticlem_particles
 

Constructor & Destructor Documentation

◆ ParticleComposition()

ParticleComposition::ParticleComposition ( )

Definition at line 19 of file ParticleComposition.cpp.

19 {}

Referenced by clone().

◆ ~ParticleComposition()

ParticleComposition::~ParticleComposition ( )
overridedefault

Member Function Documentation

◆ abundance()

double IParticle::abundance ( ) const
inlineinherited

Definition at line 38 of file IParticle.h.

38 { return m_abundance; }
double m_abundance
Definition: IParticle.h:78

References IParticle::m_abundance.

Referenced by SampleToPython::defineParticleLayouts(), and IParticle::setAbundance().

◆ addParticle() [1/2]

void ParticleComposition::addParticle ( const IParticle particle)

Definition at line 63 of file ParticleComposition.cpp.

64 {
65  m_particles.emplace_back(particle.clone());
66 }
IParticle * clone() const override=0
Returns a clone of this ISampleNode object.
void emplace_back(T *e)
Definition: OwningVector.h:62
OwningVector< IParticle > m_particles

References IParticle::clone(), OwningVector< T >::emplace_back(), and m_particles.

Referenced by addParticles(), ExemplarySamples::createBoxCompositionRotateX(), ExemplarySamples::createBoxCompositionRotateY(), ExemplarySamples::createBoxCompositionRotateZ(), ExemplarySamples::createBoxCompositionRotateZandY(), ExemplarySamples::createBoxStackComposition(), and ExemplarySamples::createSlicedComposition().

Here is the call graph for this function:

◆ addParticle() [2/2]

void ParticleComposition::addParticle ( const IParticle particle,
R3  position 
)

Definition at line 68 of file ParticleComposition.cpp.

69 {
70  m_particles.emplace_back(particle.clone()->translate(position));
71 }
IParticle * translate(R3 translation)
Translates the particle, and returns this.
Definition: IParticle.cpp:25

References IParticle::clone(), OwningVector< T >::emplace_back(), m_particles, and IParticle::translate().

Here is the call graph for this function:

◆ addParticles()

void ParticleComposition::addParticles ( const IParticle particle,
std::vector< R3 >  positions 
)

Definition at line 75 of file ParticleComposition.cpp.

76 {
77  for (size_t i = 0; i < positions.size(); ++i)
78  addParticle(particle, positions[i]);
79 }
void addParticle(const IParticle &particle)

References addParticle().

Referenced by ExemplarySamples::createCenteredSquareLattice2D(), and ExemplarySamples::createParticleComposition().

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 ParticleComposition::className ( ) const
inlinefinalvirtual

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

Implements INode.

Definition at line 31 of file ParticleComposition.h.

31 { return "ParticleComposition"; }

◆ clone()

ParticleComposition * ParticleComposition::clone ( ) const
overridevirtual

Returns a clone of this ISampleNode object.

Implements IParticle.

Definition at line 23 of file ParticleComposition.cpp.

24 {
25  auto* result = new ParticleComposition();
26  result->setAbundance(m_abundance);
27  for (size_t index = 0; index < m_particles.size(); ++index)
28  result->addParticle(*m_particles[index]);
29  if (m_rotation)
30  result->setRotation(*m_rotation);
31  result->setParticlePosition(m_position);
32  return result;
33 }
R3 m_position
Definition: IParticle.h:79
std::unique_ptr< IRotation > m_rotation
Definition: IParticle.h:80
size_t size() const
Definition: OwningVector.h:70

References ParticleComposition(), IParticle::m_abundance, m_particles, IParticle::m_position, IParticle::m_rotation, and OwningVector< T >::size().

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:

◆ decompose()

std::vector< std::unique_ptr< IParticle > > ParticleComposition::decompose ( ) const
overridevirtual

Decompose in constituent IParticle objects.

Reimplemented from IParticle.

Definition at line 44 of file ParticleComposition.cpp.

45 {
46  std::vector<std::unique_ptr<IParticle>> result;
47  const auto* rot = rotation();
48  const auto& translation = particlePosition();
49  for (const auto& particle : m_particles) {
50  const auto sublist = particle->decompose();
51  for (const auto& subparticle : sublist) {
52  IParticle* new_subparticle = subparticle->clone();
53  if (rot)
54  new_subparticle->rotate(*rot);
55  new_subparticle->translate(translation);
56  result.emplace_back(new_subparticle);
57  }
58  }
59  return result;
60 }
Abstract base class for Particle, ParticleComposition, ParticleCoreShell, MesoCrystal....
Definition: IParticle.h:31
const IRotation * rotation() const
Returns rotation object.
Definition: IParticle.cpp:31
IParticle * rotate(const IRotation &rotation)
Rotates the particle, and returns this.
Definition: IParticle.cpp:41
R3 particlePosition() const
Returns particle position.
Definition: IParticle.h:46

References IParticle::clone(), m_particles, IParticle::particlePosition(), IParticle::rotate(), IParticle::rotation(), and IParticle::translate().

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:

◆ material()

virtual const Material* ISampleNode::material ( ) const
inlinevirtualinherited

Returns nullptr, unless overwritten to return a specific material.

Reimplemented in Particle, and Layer.

Definition at line 36 of file ISampleNode.h.

36 { return nullptr; }

Referenced by ISampleNode::containedMaterials().

◆ nbrParticles()

size_t ParticleComposition::nbrParticles ( ) const
inline

Returns number of different particles.

Definition at line 43 of file ParticleComposition.h.

43 { return m_particles.size(); }

References m_particles, and OwningVector< T >::size().

Here is the call graph for this function:

◆ nodeChildren()

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

Returns all children.

Reimplemented from IParticle.

Definition at line 35 of file ParticleComposition.cpp.

36 {
37  std::vector<const INode*> result = IParticle::nodeChildren();
38  for (const IParticle* p : m_particles)
39  result.emplace_back(p);
40  return result;
41 }
std::vector< const INode * > nodeChildren() const override
Returns all children.
Definition: IParticle.cpp:20

References m_particles, and IParticle::nodeChildren().

Here is the call graph for this function:

◆ 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:

◆ parDefs()

virtual std::vector<ParaMeta> INode::parDefs ( ) const
inlinevirtualinherited

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

Reimplemented in ConstantBackground, GaussSphere, FuzzySphere, RotationEuler, RotationZ, RotationY, RotationX, Crystal, Layer, HexagonalLattice2D, SquareLattice2D, BasicLattice2D, LayerRoughness, TruncatedSpheroid, TruncatedSphere, TruncatedCube, Spheroid, Sphere, SawtoothRippleLorentz, SawtoothRippleGauss, SawtoothRippleBox, Pyramid6, Pyramid4, Pyramid3, Pyramid2, Prism6, Prism3, PlatonicTetrahedron, PlatonicOctahedron, LongBoxLorentz, LongBoxGauss, Icosahedron, HorizontalCylinder, HollowSphere, HemiEllipsoid, EllipsoidalCylinder, Dodecahedron, Cylinder, CosineRippleLorentz, CosineRippleGauss, CosineRippleBox, Cone, CantellatedCube, Box, Bipyramid4, BarLorentz, BarGauss, Profile2DVoigt, Profile2DCone, Profile2DGate, Profile2DGauss, Profile2DCauchy, Profile1DVoigt, Profile1DCosine, Profile1DTriangle, Profile1DGate, Profile1DGauss, Profile1DCauchy, MisesGaussPeakShape, MisesFisherGaussPeakShape, LorentzFisherPeakShape, GaussFisherPeakShape, IsotropicLorentzPeakShape, IsotropicGaussPeakShape, ParticleLayout, InterferenceTwin, InterferenceRadialParaCrystal, InterferenceHardDisk, Interference2DSuperLattice, Interference2DParaCrystal, Interference1DLattice, DistributionTrapezoid, DistributionCosine, DistributionLogNormal, DistributionGaussian, DistributionLorentz, DistributionGate, ResolutionFunction2DGaussian, PolFilter, FootprintSquare, and FootprintGauss.

Definition at line 51 of file INode.h.

51 { return {}; }

Referenced by INode::checkNodeArgs(), and IFormFactor::pythonConstructor().

◆ particlePosition()

R3 IParticle::particlePosition ( ) const
inlineinherited

Returns particle position.

Definition at line 46 of file IParticle.h.

46 { return m_position; }

References IParticle::m_position.

Referenced by decompose().

◆ particles()

std::vector< const IParticle * > ParticleComposition::particles ( ) const

Definition at line 81 of file ParticleComposition.cpp.

82 {
83  std::vector<const IParticle*> result;
84  for (const IParticle* p : m_particles)
85  result.emplace_back(p);
86  return result;
87 }

References m_particles.

◆ rotate()

IParticle * IParticle::rotate ( const IRotation rotation)
inherited

Rotates the particle, and returns this.

Definition at line 41 of file IParticle.cpp.

42 {
43  if (m_rotation)
45  else
46  m_rotation.reset(rotation.clone());
48  return this;
49 }
IRotation * createProduct(const IRotation &left, const IRotation &right)
Returns concatenated rotation (first right, then left).
Definition: Rotations.cpp:59
IRotation * clone() const override=0
R3 transformed(const R3 &v) const
Definition: Rotations.cpp:42

References IRotation::clone(), createProduct(), IParticle::m_position, IParticle::m_rotation, IParticle::rotation(), and IRotation::transformed().

Referenced by ExemplarySamples::createBoxCompositionRotateZandY(), ExemplarySamples::createCoreShellBoxRotateZandY(), ExemplarySamples::createLayersWithAbsorptionBySLD(), ExemplarySamples::createLayersWithAbsorptionWithFF(), ExemplarySamples::createMagneticRotation(), ExemplarySamples::createRotatedPyramids(), ExemplarySamples::createTransformBox(), and decompose().

Here is the call graph for this function:

◆ rotation()

const IRotation * IParticle::rotation ( ) const
inherited

Returns rotation object.

Definition at line 31 of file IParticle.cpp.

32 {
33  return m_rotation.get();
34 }

References IParticle::m_rotation.

Referenced by Particle::Particle(), decompose(), IParticle::rotate(), and IParticle::setRotation().

◆ setAbundance()

void IParticle::setAbundance ( double  abundance)
inlineinherited

Sets particle abundance.

Parameters
abundanceproportion of this type of particles normalized to the total number of particles in the layout.

Definition at line 43 of file IParticle.h.

double abundance() const
Definition: IParticle.h:38

References IParticle::abundance(), and IParticle::m_abundance.

Referenced by ParticleLayout::addParticle().

Here is the call graph for this function:

◆ setParticlePosition() [1/2]

void IParticle::setParticlePosition ( double  x,
double  y,
double  z 
)
inlineinherited

Sets relative position of the particle's reference point in the coordinate system of parent.

Parameters
xx-coordinate in nanometers
yy-coordinate in nanometers
zz-coordinate in nanometers

Definition at line 58 of file IParticle.h.

58 { m_position = R3(x, y, z); }

References IParticle::m_position.

◆ setParticlePosition() [2/2]

◆ setRotation()

◆ transferToCPP()

virtual void ICloneable::transferToCPP ( )
inlinevirtualinherited

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

Definition at line 32 of file ICloneable.h.

◆ translate()

IParticle * IParticle::translate ( R3  translation)
inherited

Translates the particle, and returns this.

Definition at line 25 of file IParticle.cpp.

26 {
27  m_position += translation;
28  return this;
29 }

References IParticle::m_position.

Referenced by addParticle(), ExemplarySamples::createMagneticRotation(), ExemplarySamples::createMagneticSpheres(), ExemplarySamples::createMagneticSubstrateZeroField(), ExemplarySamples::createSuperLattice(), and decompose().

Member Data Documentation

◆ m_abundance

double IParticle::m_abundance {1.0}
protectedinherited

◆ m_P

◆ m_particles

OwningVector<IParticle> ParticleComposition::m_particles
private

◆ m_position

◆ m_rotation

std::unique_ptr<IRotation> IParticle::m_rotation
protectedinherited

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