BornAgain  1.18.0
Simulate and fit neutron and x-ray scattering at grazing incidence
BoxCompositionBuilder.cpp
Go to the documentation of this file.
1 // ************************************************************************** //
2 //
3 // BornAgain: simulate and fit scattering at grazing incidence
4 //
5 //! @file Sample/StandardSamples/BoxCompositionBuilder.cpp
6 //! @brief Implements class BoxCompositionBuilder.
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 
16 #include "Base/Const/Units.h"
24 
25 namespace
26 {
27 
28 const Material particleMaterial = HomogeneousMaterial("Ag", 1.245e-5, 5.419e-7);
29 const double layer_thickness = 100.0 * Units::nanometer;
30 const double length = 50.0 * Units::nanometer;
31 const double width = 20.0 * Units::nanometer;
32 const double height = 10.0 * Units::nanometer;
33 
35 {
36  ParticleLayout layout;
37  layout.addParticle(composition);
38 
39  Layer vacuum_layer(refMat::Vacuum);
40  Layer middle_layer(refMat::Teflon, layer_thickness);
41  middle_layer.addLayout(layout);
42  Layer substrate(refMat::Substrate2);
43 
44  MultiLayer* multi_layer = new MultiLayer();
45  multi_layer->addLayer(vacuum_layer);
46  multi_layer->addLayer(middle_layer);
47  multi_layer->addLayer(substrate);
48  return multi_layer;
49 }
50 
51 } // namespace
52 
53 // --- BoxCompositionRotateXBuilder ---
54 
56 {
58  ParticleComposition composition;
59  composition.addParticle(box, kvector_t(0.0, 0.0, 0.0));
60  composition.addParticle(box, kvector_t(length / 2.0, 0.0, 0.0));
61  composition.setRotation(RotationX(90.0 * Units::degree));
62  composition.setPosition(kvector_t(0.0, 0.0, -layer_thickness / 2.0));
63  return finalizeMultiLayer(composition);
64 }
65 
66 // --- BoxCompositionRotateYBuilder ---
67 
69 {
71  ParticleComposition composition;
72  composition.addParticle(box, kvector_t(0.0, 0.0, 0.0));
73  composition.addParticle(box, kvector_t(length / 2.0, 0.0, 0.0));
74  composition.setRotation(RotationY(90.0 * Units::degree));
75  composition.setPosition(kvector_t(0.0, 0.0, -layer_thickness / 2.0 + length / 4.0));
76  return finalizeMultiLayer(composition);
77 }
78 
79 // --- BoxCompositionRotateZBuilder ---
80 
82 {
84  ParticleComposition composition;
85  composition.addParticle(box, kvector_t(0.0, 0.0, 0.0));
86  composition.addParticle(box, kvector_t(length / 2.0, 0.0, 0.0));
87  composition.setRotation(RotationZ(90.0 * Units::degree));
88  composition.setPosition(kvector_t(0.0, 0.0, -layer_thickness / 2.0 - height / 2.0));
89  return finalizeMultiLayer(composition);
90 }
91 
92 // --- BoxCompositionRotateZandYBuilder ---
93 
95 {
97  ParticleComposition composition;
98  composition.addParticle(box, kvector_t(0.0, 0.0, 0.0));
99  composition.addParticle(box, kvector_t(length / 2.0, 0.0, 0.0));
100  composition.setRotation(RotationZ(90.0 * Units::degree));
101  composition.rotate(RotationY(90.0 * Units::degree));
102  composition.setPosition(kvector_t(0.0, 0.0, -layer_thickness / 2.0));
103  return finalizeMultiLayer(composition);
104 }
105 
106 // --- BoxStackCompositionBuilder ---
107 
108 // Composition of two boxes which gives you the box (10,20,50) with reference point as usual.
110 {
111  ParticleComposition composition;
112 
113  // box1 (20,50,5), rotatedZ
114  const double box1_length = 20;
115  const double box1_width = 50;
116  const double box1_height = 5;
117  Particle box1(particleMaterial, FormFactorBox(box1_length, box1_width, box1_height));
118  box1.setRotation(RotationZ(90. * Units::degree));
119 
120  // box2 (5,20,50), rotatedY
121  const double box2_length = 5.0;
122  const double box2_width = 20.0;
123  const double box2_height = 50.0;
124  Particle box2(particleMaterial, FormFactorBox(box2_length, box2_width, box2_height));
125  box2.setRotation(RotationY(90. * Units::degree));
126  box2.setPosition(kvector_t(-box2_height / 2.0, 0.0, box2_length / 2.0));
127 
128  composition.addParticle(box1, kvector_t(0.0, 0.0, 0.0));
129  composition.addParticle(box2, kvector_t(0.0, 0.0, box1_height));
130  composition.setRotation(RotationY(90.0 * Units::degree));
131  composition.setPosition(kvector_t(0.0, 0.0, -layer_thickness / 2.));
132 
133  return finalizeMultiLayer(composition);
134 }
Defines classes of BoxCompositionBuilder family.
Defines class FormFactorBox.
Defines class Layer.
Defines class MultiLayer.
Defines class ParticleComposition.
Defines class ParticleLayout.
Defines class Particle.
Defines materials in namespace refMat.
Defines some unit conversion factors and other constants in namespace Units.
BasicVector3D< double > kvector_t
Definition: Vectors3D.h:21
A rectangular prism (parallelepiped).
Definition: FormFactorBox.h:24
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 rotate(const IRotation &rotation) override final
Rotates the particle.
Definition: IParticle.cpp:50
void setRotation(const IRotation &rotation)
Sets transformation.
Definition: IParticle.cpp:44
A layer, with thickness (in nanometer) and material.
Definition: Layer.h:28
void addLayout(const ILayout &decoration)
Definition: Layer.cpp:57
A wrapper for underlying material implementation.
Definition: Material.h:29
Our sample model: a stack of layers one below the other.
Definition: MultiLayer.h:42
void addLayer(const Layer &layer)
Adds object to multilayer.
Definition: MultiLayer.cpp:54
A composition of particles at fixed positions.
void addParticle(const IParticle &particle)
Decorator class that adds particles to ISample objects.
void addParticle(const IAbstractParticle &particle, double abundance=-1.0, const kvector_t position={}, const IRotation &rotation=IdentityRotation())
Adds particle to the layout with abundance, position and the rotation defined.
A particle with a form factor and refractive index.
Definition: Particle.h:26
A rotation about the x axis.
Definition: Rotations.h:72
A rotation about the y axis.
Definition: Rotations.h:93
A rotation about the z axis.
Definition: Rotations.h:114
Material HomogeneousMaterial(const std::string &name, complex_t refractive_index, kvector_t magnetization)
Constructs a material with name, refractive_index and magnetization (in A/m).
static constexpr double degree
Definition: Units.h:40
static constexpr double nanometer
Definition: Units.h:24
MultiLayer * finalizeMultiLayer(const ParticleComposition &composition)
static const Material Substrate2
static const Material Vacuum
static const Material Teflon