BornAgain  1.18.0
Simulate and fit neutron and x-ray scattering at grazing incidence
MesoCrystal.cpp
Go to the documentation of this file.
1 // ************************************************************************** //
2 //
3 // BornAgain: simulate and fit scattering at grazing incidence
4 //
5 //! @file Sample/Particle/MesoCrystal.cpp
6 //! @brief Implements class MesoCrystal.
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 MesoCrystal::MesoCrystal(const IClusteredParticles& particle_structure,
22  const IFormFactor& form_factor)
23  : mp_particle_structure(particle_structure.clone()), mp_meso_form_factor(form_factor.clone())
24 {
25  initialize();
26 }
27 
28 MesoCrystal::~MesoCrystal() = default;
29 
31 {
32  MesoCrystal* p_result =
33  new MesoCrystal(mp_particle_structure->clone(), mp_meso_form_factor->clone());
34  p_result->setAbundance(m_abundance);
35  if (mP_rotation)
36  p_result->setRotation(*mP_rotation);
37  p_result->setPosition(m_position);
38  return p_result;
39 }
40 
41 void MesoCrystal::accept(INodeVisitor* visitor) const
42 {
43  visitor->visit(this);
44 }
45 
47 {
48  if (!mp_particle_structure || !mp_meso_form_factor)
49  return {};
50  std::unique_ptr<IRotation> P_rotation(IRotation::createIdentity());
51  if (mP_rotation)
52  P_rotation.reset(mP_rotation->clone());
53  std::unique_ptr<IFormFactor> P_temp_ff(
54  mp_meso_form_factor->createSlicedFormFactor(limits, *P_rotation, m_position));
55  std::unique_ptr<IFormFactor> P_total_ff(
56  mp_particle_structure->createTotalFormFactor(*P_temp_ff, P_rotation.get(), m_position));
57  double meso_volume = mp_meso_form_factor->volume();
58  auto regions = mp_particle_structure->homogeneousRegions();
59  for (auto& region : regions)
60  region.m_volume *= meso_volume;
61  SlicedParticle result;
62  result.mP_slicedff = std::move(P_total_ff);
63  result.m_regions = regions;
64  return result;
65 }
66 
67 std::vector<const INode*> MesoCrystal::getChildren() const
68 {
69  return std::vector<const INode*>()
70  << IParticle::getChildren() << mp_particle_structure << mp_meso_form_factor;
71 }
72 
73 MesoCrystal::MesoCrystal(IClusteredParticles* p_particle_structure, IFormFactor* p_form_factor)
74  : mp_particle_structure(p_particle_structure), mp_meso_form_factor(p_form_factor)
75 {
76  initialize();
77 }
78 
79 void MesoCrystal::initialize()
80 {
81  setName("MesoCrystal");
83  registerChild(mp_particle_structure.get());
84  registerChild(mp_meso_form_factor.get());
85 }
Defines class FormFactorDecoratorPositionFactor.
Defines class FormFactorDecoratorRotation.
Defines class IClusteredParticles.
Defines class MesoCrystal.
Defines class SlicedParticle.
void setAbundance(double abundance)
Sets particle abundance.
An ordered assembly of particles.
Pure virtual base class for all form factors.
Definition: IFormFactor.h:40
Visitor interface to visit ISample objects.
Definition: INodeVisitor.h:149
std::vector< const INode * > getChildren() const override
Returns a vector of children (const).
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
void setRotation(const IRotation &rotation)
Sets transformation.
Definition: IParticle.cpp:44
void registerParticleProperties()
Registers abundance and position.
Definition: IParticle.cpp:125
A particle with an internal structure of smaller particles.
Definition: MesoCrystal.h:26
MesoCrystal * clone() const override final
Returns a clone of this ISample object.
Definition: MesoCrystal.cpp:30
SlicedParticle createSlicedParticle(ZLimits limits) const override final
Creates a sliced form factor for this particle.
Definition: MesoCrystal.cpp:46
std::vector< const INode * > getChildren() const override final
Returns a vector of children (const).
Definition: MesoCrystal.cpp:67
void accept(INodeVisitor *visitor) const override final
Calls the INodeVisitor's visit method.
Definition: MesoCrystal.cpp:41
Class that contains upper and lower limits of the z-coordinate for the slicing of form factors.
Definition: ZLimits.h:41
Struct that contains information on a sliced particle.