BornAgain  1.19.0
Simulate and fit neutron and x-ray scattering at grazing incidence
ParticleCoreShell.cpp
Go to the documentation of this file.
1 // ************************************************************************************************
2 //
3 // BornAgain: simulate and fit reflection and scattering
4 //
5 //! @file Sample/Particle/ParticleCoreShell.cpp
6 //! @brief Implements class ParticleCoreShell.
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 
22  kvector_t relative_core_position)
23 {
24  setName("ParticleCoreShell");
26  addAndRegisterCore(core, relative_core_position);
27  addAndRegisterShell(shell);
28 }
29 
31 
33 {
35  p_result->setAbundance(m_abundance);
36  if (m_rotation)
37  p_result->setRotation(*m_rotation);
38  p_result->setPosition(m_position);
39  return p_result;
40 }
41 
43 {
44  if (!m_core || !m_shell)
45  return {};
46  std::unique_ptr<IRotation> P_rotation(new IdentityRotation);
47  if (m_rotation)
48  P_rotation.reset(m_rotation->clone());
49 
50  // core
51  std::unique_ptr<Particle> P_core(m_core->clone());
52  P_core->rotate(*P_rotation);
53  P_core->translate(m_position);
54  auto sliced_core = P_core->createSlicedParticle(limits);
55 
56  // shell
57  std::unique_ptr<Particle> P_shell(m_shell->clone());
58  P_shell->rotate(*P_rotation);
59  P_shell->translate(m_position);
60  auto sliced_shell = P_shell->createSlicedParticle(limits);
61  if (!sliced_shell.m_slicedff)
62  return {};
63 
64  SlicedParticle result;
65  // if core out of limits, return sliced shell
66  if (!sliced_core.m_slicedff) {
67  result.m_slicedff.reset(sliced_shell.m_slicedff.release());
68  result.m_regions.push_back(sliced_shell.m_regions.back());
69  return result;
70  }
71 
72  // set core ambient material
73  if (sliced_shell.m_regions.size() != 1)
74  return {};
75  auto shell_material = sliced_shell.m_regions[0].m_material;
76  sliced_core.m_slicedff->setAmbientMaterial(shell_material);
77 
78  // construct sliced particle
79  sliced_shell.m_regions.back().m_volume -= sliced_core.m_regions.back().m_volume;
80  result.m_slicedff.reset(new FormFactorCoreShell(sliced_core.m_slicedff.release(),
81  sliced_shell.m_slicedff.release()));
82  result.m_regions.push_back(sliced_core.m_regions.back());
83  result.m_regions.push_back(sliced_shell.m_regions.back());
84 
85  return result;
86 }
87 
88 std::vector<const INode*> ParticleCoreShell::getChildren() const
89 {
90  return std::vector<const INode*>() << IParticle::getChildren() << m_core << m_shell;
91 }
92 
93 void ParticleCoreShell::addAndRegisterCore(const Particle& core, kvector_t relative_core_position)
94 {
95  m_core.reset(core.clone());
96  m_core->translate(relative_core_position);
97  registerChild(m_core.get());
98  m_core->registerAbundance(false);
99 }
100 
102 {
103  m_shell.reset(shell.clone());
104  registerChild(m_shell.get());
105  m_shell->registerAbundance(false);
106  m_shell->registerPosition(false);
107 }
108 
109 ParticleCoreShell::ParticleCoreShell() : m_shell{nullptr}, m_core{nullptr}
110 {
111  setName("ParticleCoreShell");
112 }
Defines class FormFactorCoreShell.
Defines ParticleCoreShell.
Defines class Particle.
Defines IRotation classes.
Defines class SlicedParticle.
Form Factor for a core shell particle.
void setAbundance(double abundance)
Sets particle abundance.
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
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
The identity rotation, which leaves everything in place.
Definition: Rotations.h:57
A particle with a core/shell geometry.
std::unique_ptr< Particle > m_shell
std::unique_ptr< Particle > m_core
std::vector< const INode * > getChildren() const final
Returns a vector of children.
void addAndRegisterShell(const Particle &shell)
SlicedParticle createSlicedParticle(ZLimits limits) const final
Creates a sliced form factor for this particle.
void addAndRegisterCore(const Particle &core, kvector_t relative_core_position)
ParticleCoreShell * clone() const final
Returns a clone of this ISampleNode object.
A particle with a form factor and refractive index.
Definition: Particle.h:24
Particle * clone() const final
Returns a clone of this ISampleNode object.
Definition: Particle.cpp:45
Class that contains upper and lower limits of the z-coordinate for the slicing of form factors.
Definition: ZLimits.h:45
Struct that contains information on a sliced particle.
std::vector< HomogeneousRegion > m_regions
std::unique_ptr< IFormFactor > m_slicedff