BornAgain  1.18.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 scattering at grazing incidence
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 
19 
21  kvector_t relative_core_position)
22 {
23  setName("ParticleCoreShell");
25  addAndRegisterCore(core, relative_core_position);
26  addAndRegisterShell(shell);
27 }
28 
30 
32 {
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 
42 {
43  if (!mp_core || !mp_shell)
44  return {};
45  std::unique_ptr<IRotation> P_rotation(IRotation::createIdentity());
46  if (mP_rotation)
47  P_rotation.reset(mP_rotation->clone());
48 
49  // core
50  std::unique_ptr<Particle> P_core(mp_core->clone());
51  P_core->rotate(*P_rotation);
52  P_core->translate(m_position);
53  auto sliced_core = P_core->createSlicedParticle(limits);
54 
55  // shell
56  std::unique_ptr<Particle> P_shell(mp_shell->clone());
57  P_shell->rotate(*P_rotation);
58  P_shell->translate(m_position);
59  auto sliced_shell = P_shell->createSlicedParticle(limits);
60  if (!sliced_shell.mP_slicedff)
61  return {};
62 
63  SlicedParticle result;
64  // if core out of limits, return sliced shell
65  if (!sliced_core.mP_slicedff) {
66  result.mP_slicedff.reset(sliced_shell.mP_slicedff.release());
67  result.m_regions.push_back(sliced_shell.m_regions.back());
68  return result;
69  }
70 
71  // set core ambient material
72  if (sliced_shell.m_regions.size() != 1)
73  return {};
74  auto shell_material = sliced_shell.m_regions[0].m_material;
75  sliced_core.mP_slicedff->setAmbientMaterial(shell_material);
76 
77  // construct sliced particle
78  sliced_shell.m_regions.back().m_volume -= sliced_core.m_regions.back().m_volume;
79  result.mP_slicedff.reset(new FormFactorCoreShell(sliced_core.mP_slicedff.release(),
80  sliced_shell.mP_slicedff.release()));
81  result.m_regions.push_back(sliced_core.m_regions.back());
82  result.m_regions.push_back(sliced_shell.m_regions.back());
83 
84  return result;
85 }
86 
87 std::vector<const INode*> ParticleCoreShell::getChildren() const
88 {
89  return std::vector<const INode*>() << IParticle::getChildren() << mp_core << mp_shell;
90 }
91 
92 void ParticleCoreShell::addAndRegisterCore(const Particle& core, kvector_t relative_core_position)
93 {
94  mp_core.reset(core.clone());
95  mp_core->translate(relative_core_position);
96  registerChild(mp_core.get());
97  mp_core->registerAbundance(false);
98 }
99 
101 {
102  mp_shell.reset(shell.clone());
103  registerChild(mp_shell.get());
104  mp_shell->registerAbundance(false);
105  mp_shell->registerPosition(false);
106 }
107 
108 ParticleCoreShell::ParticleCoreShell() : mp_shell{nullptr}, mp_core{nullptr}
109 {
110  setName("ParticleCoreShell");
111 }
Defines class FormFactorCoreShell.
Defines ParticleCoreShell.
Defines class Particle.
Defines class SlicedParticle.
Form Factor for a core shell particle.
void setAbundance(double abundance)
Sets particle abundance.
void registerChild(INode *node)
Definition: INode.cpp:58
void setName(const std::string &name)
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
std::unique_ptr< IRotation > mP_rotation
Definition: IParticle.h:95
kvector_t m_position
Definition: IParticle.h:94
void setRotation(const IRotation &rotation)
Sets transformation.
Definition: IParticle.cpp:44
void registerParticleProperties()
Registers abundance and position.
Definition: IParticle.cpp:125
static IRotation * createIdentity()
Definition: Rotations.cpp:53
A particle with a core/shell geometry.
std::vector< const INode * > getChildren() const override final
Returns a vector of children (const).
void addAndRegisterShell(const Particle &shell)
ParticleCoreShell * clone() const override final
Returns a clone of this ISample object.
void addAndRegisterCore(const Particle &core, kvector_t relative_core_position)
SlicedParticle createSlicedParticle(ZLimits limits) const override final
Creates a sliced form factor for this particle.
std::unique_ptr< Particle > mp_shell
std::unique_ptr< Particle > mp_core
A particle with a form factor and refractive index.
Definition: Particle.h:26
Particle * clone() const override final
Returns a clone of this ISample 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:41
Struct that contains information on a sliced particle.
std::vector< HomogeneousRegion > m_regions
std::unique_ptr< IFormFactor > mP_slicedff