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

Description

A particle with a form factor and refractive index.

Definition at line 25 of file Particle.h.

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

Public Member Functions

 Particle (Material material, const IFormFactor &formfactor)
 
 Particle (Material material, const IFormFactor &formfactor, const IRotation &rotation)
 
 ~Particle () override
 
double abundance () const
 
void checkNodeArgs () const
 Raises exception if a parameter value is invalid. More...
 
std::string className () const override
 Returns the class name, to be hard-coded in each leaf class that inherits from INode. More...
 
Particleclone () 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...
 
virtual std::vector< std::unique_ptr< IParticle > > decompose () const
 Decompose in constituent IParticle objects. More...
 
const IFormFactorformfactor_at_bottom () const
 
bool isMagnetic () const
 Returns true if there is any magnetic material in this ISampleNode. More...
 
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...
 
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...
 
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

std::unique_ptr< const IFormFactorm_formfactor
 
const Material m_material
 

Constructor & Destructor Documentation

◆ Particle() [1/2]

Particle::Particle ( Material  material,
const IFormFactor formfactor 
)

Definition at line 20 of file Particle.cpp.

21  : m_material(std::move(material))
22  , m_formfactor(formfactor.clone())
23 {
24 }
IFormFactor * clone() const override=0
Returns a clone of this ISampleNode object.
const Material * material() const override
Returns nullptr, unless overwritten to return a specific material.
Definition: Particle.h:35
const Material m_material
Definition: Particle.h:40
std::unique_ptr< const IFormFactor > m_formfactor
Definition: Particle.h:41

Referenced by clone().

◆ Particle() [2/2]

Particle::Particle ( Material  material,
const IFormFactor formfactor,
const IRotation rotation 
)

Definition at line 26 of file Particle.cpp.

27  : Particle(material, formfactor)
28 {
30 }
const IRotation * rotation() const
Returns rotation object.
Definition: IParticle.cpp:31
void setRotation(const IRotation &rotation)
Sets transformation.
Definition: IParticle.cpp:36
Particle(Material material, const IFormFactor &formfactor)
Definition: Particle.cpp:20

References IParticle::rotation(), and IParticle::setRotation().

Here is the call graph for this function:

◆ ~Particle()

Particle::~Particle ( )
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().

◆ 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 Particle::className ( ) const
inlineoverridevirtual

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

Implements INode.

Definition at line 32 of file Particle.h.

32 { return "Particle"; }

◆ clone()

Particle * Particle::clone ( ) const
overridevirtual

Returns a clone of this ISampleNode object.

Implements IParticle.

Definition at line 34 of file Particle.cpp.

35 {
37  auto* p_result = new Particle(m_material, *m_formfactor);
38  p_result->setAbundance(m_abundance);
39  if (m_rotation)
40  p_result->setRotation(*m_rotation);
41  p_result->setParticlePosition(m_position);
42 
43  return p_result;
44 }
R3 m_position
Definition: IParticle.h:79
std::unique_ptr< IRotation > m_rotation
Definition: IParticle.h:80

References Particle(), ASSERT, IParticle::m_abundance, m_formfactor, m_material, IParticle::m_position, and IParticle::m_rotation.

Referenced by ParticleCoreShell::ParticleCoreShell(), and Compute::Slicing::createParticleInSlice().

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 > > IParticle::decompose ( ) const
virtualinherited

Decompose in constituent IParticle objects.

Reimplemented in ParticleComposition.

Definition at line 52 of file IParticle.cpp.

53 {
54  std::vector<std::unique_ptr<IParticle>> result;
55  result.emplace_back(this->clone());
56  return result;
57 }
IParticle * clone() const override=0
Returns a clone of this ISampleNode object.

References IParticle::clone().

Referenced by Compute::Slicing::createParticleInSlice().

Here is the call graph for this function:

◆ formfactor_at_bottom()

const IFormFactor* Particle::formfactor_at_bottom ( ) const
inline

Definition at line 37 of file Particle.h.

37 { return m_formfactor.get(); }

References m_formfactor.

◆ 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()

const Material* Particle::material ( ) const
inlineoverridevirtual

Returns nullptr, unless overwritten to return a specific material.

Reimplemented from ISampleNode.

Definition at line 35 of file Particle.h.

35 { return &m_material; }

References m_material.

◆ nodeChildren()

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

Returns all children.

Reimplemented from IParticle.

Definition at line 46 of file Particle.cpp.

47 {
48  return std::vector<const INode*>() << IParticle::nodeChildren() << m_formfactor;
49 }
std::vector< const INode * > nodeChildren() const override
Returns all children.
Definition: IParticle.cpp:20

References m_formfactor, 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 ParticleComposition::decompose().

◆ 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 ParticleComposition::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(), ParticleComposition::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

Member Data Documentation

◆ m_abundance

double IParticle::m_abundance {1.0}
protectedinherited

◆ m_formfactor

std::unique_ptr<const IFormFactor> Particle::m_formfactor
private

Definition at line 41 of file Particle.h.

Referenced by clone(), formfactor_at_bottom(), and nodeChildren().

◆ m_material

const Material Particle::m_material
private

Definition at line 40 of file Particle.h.

Referenced by clone(), and material().

◆ m_P

◆ m_position

◆ m_rotation


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