BornAgain  1.19.0
Simulate and fit neutron and x-ray scattering at grazing incidence
Particle.cpp
Go to the documentation of this file.
1 // ************************************************************************************************
2 //
3 // BornAgain: simulate and fit reflection and scattering
4 //
5 //! @file Sample/Particle/Particle.cpp
6 //! @brief Implements class Particle.
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 
22 
23 Particle::~Particle() = default;
24 
25 Particle::Particle(Material material) : m_material(std::move(material))
26 {
27  initialize();
28 }
29 
30 Particle::Particle(Material material, const IFormFactor& form_factor)
31  : m_material(std::move(material)), m_form_factor(form_factor.clone())
32 {
33  initialize();
35 }
36 
37 Particle::Particle(Material material, const IFormFactor& form_factor, const IRotation& rotation)
38  : m_material(std::move(material)), m_form_factor(form_factor.clone())
39 {
40  initialize();
43 }
44 
46 {
47  Particle* p_result = new Particle(m_material);
48  p_result->setAbundance(m_abundance);
49  if (m_form_factor)
50  p_result->setFormFactor(*m_form_factor);
51  if (m_rotation)
52  p_result->setRotation(*m_rotation);
53  p_result->setPosition(m_position);
54 
55  return p_result;
56 }
57 
59 {
60  if (!m_form_factor)
61  return {};
62  std::unique_ptr<IRotation> P_rotation(new IdentityRotation);
63  if (m_rotation)
64  P_rotation.reset(m_rotation->clone());
65  std::unique_ptr<IFormFactor> P_tem_ff(
66  m_form_factor->createSlicedFormFactor(limits, *P_rotation, m_position));
67  if (!P_tem_ff)
68  return {};
69  std::unique_ptr<FormFactorDecoratorMaterial> P_ff(new FormFactorDecoratorMaterial(*P_tem_ff));
70  double volume = P_tem_ff->volume();
71  Material transformed_material(m_material.rotatedMaterial(P_rotation->getTransform3D()));
72  P_ff->setMaterial(transformed_material);
73  SlicedParticle result;
74  result.m_regions.push_back({volume, transformed_material});
75  result.m_slicedff = std::move(P_ff);
76  return result;
77 }
78 
80 {
81  m_material = std::move(material);
82 }
83 
84 void Particle::setFormFactor(const IFormFactor& form_factor)
85 {
86  if (&form_factor != m_form_factor.get()) {
87  m_form_factor.reset(form_factor.clone());
89  }
90 }
91 
92 std::vector<const INode*> Particle::getChildren() const
93 {
94  return std::vector<const INode*>() << IParticle::getChildren() << m_form_factor;
95 }
96 
98 {
99  setName("Particle");
101 }
Defines class FormFactorDecoratorMaterial.
Defines class FormFactorDecoratorPositionFactor.
Factory functions used to create material instances.
Defines class Particle.
Defines IRotation classes.
Defines class SlicedParticle.
Declares class Transform3D.
Decorates a scalar formfactor with the correct factor for the material's refractive index and that of...
void setAbundance(double abundance)
Sets particle abundance.
Abstract base class for all form factors.
Definition: IFormFactor.h:36
IFormFactor * clone() const override=0
Returns a clone of this ISampleNode object.
void registerChild(INode *node)
Definition: INode.cpp:57
void setName(const std::string &name)
std::vector< const INode * > getChildren() const override
Returns a vector of children.
Definition: IParticle.cpp:61
void setPosition(kvector_t position)
Sets relative position of the particle's reference point in the coordinate system of parent.
Definition: IParticle.h:50
const IRotation * rotation() const
Returns rotation object.
Definition: IParticle.cpp:39
kvector_t m_position
Definition: IParticle.h:94
std::unique_ptr< IRotation > m_rotation
Definition: IParticle.h:95
void setRotation(const IRotation &rotation)
Sets transformation.
Definition: IParticle.cpp:44
void registerParticleProperties()
Registers abundance and position.
Definition: IParticle.cpp:125
Abstract base class for rotations.
Definition: Rotations.h:28
The identity rotation, which leaves everything in place.
Definition: Rotations.h:57
A wrapper for underlying material implementation.
Definition: Material.h:29
Material rotatedMaterial(const Transform3D &transform) const
Definition: Material.cpp:101
A particle with a form factor and refractive index.
Definition: Particle.h:24
std::vector< const INode * > getChildren() const final
Returns a vector of children.
Definition: Particle.cpp:92
Particle * clone() const final
Returns a clone of this ISampleNode object.
Definition: Particle.cpp:45
const Material * material() const final
Returns nullptr, unless overwritten to return a specific material.
Definition: Particle.h:39
void setFormFactor(const IFormFactor &form_factor)
Definition: Particle.cpp:84
Particle()=delete
void initialize()
Definition: Particle.cpp:97
SlicedParticle createSlicedParticle(ZLimits limits) const final
Creates a sliced form factor for this particle.
Definition: Particle.cpp:58
Material m_material
Definition: Particle.h:44
void setMaterial(Material material)
Definition: Particle.cpp:79
std::unique_ptr< IFormFactor > m_form_factor
Definition: Particle.h:45
Class that contains upper and lower limits of the z-coordinate for the slicing of form factors.
Definition: ZLimits.h:45
Definition: filesystem.h:81
Struct that contains information on a sliced particle.
std::vector< HomogeneousRegion > m_regions
std::unique_ptr< IFormFactor > m_slicedff