BornAgain  1.19.79
Open-source research software to simulate and fit neutron and x-ray reflectometry and grazing-incidence small-angle scattering
ParticleLayout.cpp
Go to the documentation of this file.
1 // ************************************************************************************************
2 //
3 // BornAgain: simulate and fit reflection and scattering
4 //
5 //! @file Sample/Aggregate/ParticleLayout.cpp
6 //! @brief Implements class ParticleLayout.
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 
18 
20 
21 ParticleLayout::ParticleLayout(const IParticle& particle, double abundance)
22 {
23  addParticle(particle, abundance);
24 }
25 
26 ParticleLayout::~ParticleLayout() = default; // needs member class definitions => don't move to .h
27 
29 {
30  auto* result = new ParticleLayout();
31 
32  for (const IParticle* const particle : m_particles)
33  result->addAndRegisterAbstractParticle(particle->clone());
34 
35  if (m_interparticle)
36  result->setAndRegisterInterference(m_interparticle->clone());
37 
38  result->setTotalParticleSurfaceDensity(totalParticleSurfaceDensity());
39  result->setWeight(weight());
40 
41  return result;
42 }
43 
44 std::vector<const INode*> ParticleLayout::nodeChildren() const
45 {
46  std::vector<const INode*> result;
47  for (const IParticle* p : m_particles)
48  result.emplace_back(p);
49  result << m_interparticle;
50  return result;
51 }
52 
53 //! Adds particle to the layout with abundance, position and the rotation defined.
54 //! @param particle to be added
55 //! @param abundance Particle abundance
56 void ParticleLayout::addParticle(const IParticle& particle, double abundance)
57 {
58  IParticle* particle_clone = particle.clone();
59  if (abundance >= 0.0)
60  particle_clone->setAbundance(abundance);
61  addAndRegisterAbstractParticle(particle_clone);
62 }
63 
64 std::vector<const IParticle*> ParticleLayout::particles() const
65 {
66  std::vector<const IParticle*> result;
67  for (const IParticle* p : m_particles)
68  result.emplace_back(p);
69  return result;
70 }
71 
73 {
74  return m_interparticle.get();
75 }
76 
78 {
79  double result = 0.0;
80  for (const auto& particle : m_particles)
81  result += particle->abundance();
82  return result;
83 }
84 
85 //! Adds interference functions
87 {
88  setAndRegisterInterference(interparticle.clone());
89 }
90 
92 {
93  double iff_density = m_interparticle ? m_interparticle->particleDensity() : 0.0;
94  return iff_density > 0.0 ? iff_density : m_total_particle_density;
95 }
96 
98 {
100 }
101 
102 //! Sets total particle surface density.
103 //! @param particle_density: number of particles per square nanometer
105 {
106  m_total_particle_density = particle_density;
107 }
108 
109 //! Adds particle information with simultaneous registration in parent class.
111 {
112  m_particles.emplace_back(child);
113 }
114 
115 //! Sets interference function with simultaneous registration in parent class
117 {
118  m_interparticle.reset(child);
119 }
Defines class InterferenceNone.
Defines class ParticleLayout.
Defines class Particle.
Abstract base class of interference functions.
Definition: IInterference.h:24
IInterference * clone() const override=0
Abstract base class for Particle, ParticleComposition, ParticleCoreShell, MesoCrystal....
Definition: IParticle.h:31
void setAbundance(double abundance)
Sets particle abundance.
Definition: IParticle.h:43
IParticle * clone() const override=0
Returns a clone of this ISampleNode object.
void emplace_back(T *e)
Definition: OwningVector.h:62
Decorator class that adds particles to ISampleNode objects.
double weight() const
Returns the relative weight of this layout.
OwningVector< IParticle > m_particles
Vector of particle types.
void addAndRegisterAbstractParticle(IParticle *child)
Adds particle information with simultaneous registration in parent class.
void setTotalParticleSurfaceDensity(double particle_density)
Sets total particle surface density.
void setAndRegisterInterference(IInterference *child)
Sets interference function with simultaneous registration in parent class.
ParticleLayout * clone() const override
Returns a clone of this ISampleNode object.
void addParticle(const IParticle &particle, double abundance=-1.0)
Adds particle to the layout with abundance, position and the rotation defined.
double totalAbundance() const
const IInterference * interferenceFunction() const
std::unique_ptr< IInterference > m_interparticle
~ParticleLayout() override
void setInterference(const IInterference &interparticle)
Adds interference functions.
std::vector< const IParticle * > particles() const
double weightedParticleSurfaceDensity() const
double m_total_particle_density
std::vector< const INode * > nodeChildren() const override
Returns all children.
double totalParticleSurfaceDensity() const