BornAgain  1.18.0
Simulate and fit neutron and x-ray scattering at grazing incidence
IParticle.cpp
Go to the documentation of this file.
1 // ************************************************************************** //
2 //
3 // BornAgain: simulate and fit scattering at grazing incidence
4 //
5 //! @file Sample/Particle/IParticle.cpp
6 //! @brief Implements interface IParticle.
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 
20 
21 IParticle::~IParticle() = default;
22 
24 {
25  return createSlicedParticle(ZLimits{}).mP_slicedff.release();
26 }
27 
29 {
30  throw std::runtime_error("IParticle::createSlicedParticle error: "
31  "not implemented!");
32 }
33 
35 {
36  m_position += translation;
37 }
38 
40 {
41  return mP_rotation.get();
42 }
43 
44 void IParticle::setRotation(const IRotation& rotation)
45 {
46  mP_rotation.reset(rotation.clone());
48 }
49 
50 void IParticle::rotate(const IRotation& rotation)
51 {
52  if (mP_rotation) {
54  } else {
55  mP_rotation.reset(rotation.clone());
56  }
59 }
60 
61 std::vector<const INode*> IParticle::getChildren() const
62 {
63  return std::vector<const INode*>() << mP_rotation;
64 }
65 
66 void IParticle::registerAbundance(bool make_registered)
67 {
68  if (make_registered) {
69  if (!parameter("Abundance"))
70  registerParameter("Abundance", &m_abundance);
71  } else {
72  removeParameter("Abundance");
73  }
74 }
75 
76 void IParticle::registerPosition(bool make_registered)
77 {
78  if (make_registered) {
79  if (!parameter(XComponentName("Position"))) {
80  registerVector("Position", &m_position, "nm");
81  }
82  } else {
83  removeVector("Position");
84  }
85 }
86 
88 {
90  result.push_back(this->clone());
91  return result;
92 }
93 
95 {
96  std::unique_ptr<IFormFactor> P_ff(createFormFactor());
97  std::unique_ptr<IRotation> P_rot(IRotation::createIdentity());
98  return {P_ff->bottomZ(*P_rot), P_ff->topZ(*P_rot)};
99 }
100 
102 {
103  if (p_rotation) {
104  if (mP_rotation)
105  return createProduct(*p_rotation, *mP_rotation);
106  else
107  return p_rotation->clone();
108  } else {
109  if (mP_rotation)
110  return mP_rotation->clone();
111  else
112  return nullptr;
113  }
114 }
115 
116 kvector_t IParticle::composedTranslation(const IRotation* p_rotation, kvector_t translation) const
117 {
118  if (p_rotation) {
119  return translation + p_rotation->transformed(m_position);
120  } else {
121  return translation + m_position;
122  }
123 }
124 
126 {
129 }
Defines class FormFactorDecoratorPositionFactor.
Defines interface IParticle.
Defines class RealParameter.
IRotation * createProduct(const IRotation &left, const IRotation &right)
Returns concatenated rotation (first right, then left).
Definition: Rotations.cpp:75
Defines IRotation classes.
Defines class SlicedParticle.
Pure virtual base class for all form factors.
Definition: IFormFactor.h:40
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'.
static std::string XComponentName(const std::string &base_name)
void removeParameter(const std::string &name)
void removeVector(const std::string &base_name)
void registerVector(const std::string &base_name, kvector_t *p_vec, const std::string &units="nm")
void registerAbundance(bool make_registered=true)
Definition: IParticle.cpp:66
void translate(kvector_t translation) override final
Translates the particle.
Definition: IParticle.cpp:34
virtual SafePointerVector< IParticle > decompose() const
Decompose in constituent IParticle objects.
Definition: IParticle.cpp:87
virtual SlicedParticle createSlicedParticle(ZLimits limits) const
Creates a sliced form factor for this particle.
Definition: IParticle.cpp:28
void registerPosition(bool make_registered=true)
Registers the three components of its position.
Definition: IParticle.cpp:76
std::vector< const INode * > getChildren() const override
Returns a vector of children (const).
Definition: IParticle.cpp:61
void rotate(const IRotation &rotation) override final
Rotates the particle.
Definition: IParticle.cpp:50
std::unique_ptr< IRotation > mP_rotation
Definition: IParticle.h:95
IRotation * createComposedRotation(const IRotation *p_rotation) const
Creates a composed IRotation object.
Definition: IParticle.cpp:101
const IRotation * rotation() const
Returns rotation object.
Definition: IParticle.cpp:39
kvector_t composedTranslation(const IRotation *p_rotation, kvector_t translation) const
Gets a composed translation vector.
Definition: IParticle.cpp:116
IParticle * clone() const override=0
Returns a clone of this ISample object.
kvector_t m_position
Definition: IParticle.h:94
void setRotation(const IRotation &rotation)
Sets transformation.
Definition: IParticle.cpp:44
virtual IFormFactor * createFormFactor() const
Creates a form factor for this particle.
Definition: IParticle.cpp:23
virtual ParticleLimits bottomTopZ() const
Top and bottom z-coordinate.
Definition: IParticle.cpp:94
void registerParticleProperties()
Registers abundance and position.
Definition: IParticle.cpp:125
Pure virtual interface for rotations.
Definition: Rotations.h:27
virtual IRotation * clone() const =0
static IRotation * createIdentity()
Definition: Rotations.cpp:53
kvector_t transformed(const kvector_t &v) const
Definition: Rotations.cpp:58
A vector of pointers, owned by *this, with methods to handle them safely.
void push_back(T *pointer)
Class that contains upper and lower limits of the z-coordinate for the slicing of form factors.
Definition: ZLimits.h:41
Vertical extension of a particle, specified by bottom and top z coordinate.
Definition: ZLimits.h:21
Struct that contains information on a sliced particle.