BornAgain  1.19.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 reflection and scattering
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 const Material particleMaterial = HomogeneousMaterial("Ag", 1.245e-5, 5.419e-7);
28 const double layer_thickness = 100.0 * Units::nm;
29 const double length = 50.0 * Units::nm;
30 const double width = 20.0 * Units::nm;
31 const double height = 10.0 * Units::nm;
32 
33 MultiLayer* finalizeMultiLayer(const ParticleComposition& composition)
34 {
35  ParticleLayout layout;
36  layout.addParticle(composition);
37 
38  Layer vacuum_layer(refMat::Vacuum);
39  Layer middle_layer(refMat::Teflon, layer_thickness);
40  middle_layer.addLayout(layout);
41  Layer substrate(refMat::Substrate2);
42 
43  MultiLayer* multi_layer = new MultiLayer();
44  multi_layer->addLayer(vacuum_layer);
45  multi_layer->addLayer(middle_layer);
46  multi_layer->addLayer(substrate);
47  return multi_layer;
48 }
49 
50 } // namespace
51 
52 // --- BoxCompositionRotateXBuilder ---
53 
55 {
56  Particle box(particleMaterial, FormFactorBox(length / 2.0, width, height));
57  ParticleComposition composition;
58  composition.addParticle(box, kvector_t(0.0, 0.0, 0.0));
59  composition.addParticle(box, kvector_t(length / 2.0, 0.0, 0.0));
60  composition.setRotation(RotationX(90.0 * Units::deg));
61  composition.setPosition(kvector_t(0.0, 0.0, -layer_thickness / 2.0));
62  return finalizeMultiLayer(composition);
63 }
64 
65 // --- BoxCompositionRotateYBuilder ---
66 
68 {
69  Particle box(particleMaterial, FormFactorBox(length / 2.0, width, height));
70  ParticleComposition composition;
71  composition.addParticle(box, kvector_t(0.0, 0.0, 0.0));
72  composition.addParticle(box, kvector_t(length / 2.0, 0.0, 0.0));
73  composition.setRotation(RotationY(90.0 * Units::deg));
74  composition.setPosition(kvector_t(0.0, 0.0, -layer_thickness / 2.0 + length / 4.0));
75  return finalizeMultiLayer(composition);
76 }
77 
78 // --- BoxCompositionRotateZBuilder ---
79 
81 {
82  Particle box(particleMaterial, FormFactorBox(length / 2.0, width, height));
83  ParticleComposition composition;
84  composition.addParticle(box, kvector_t(0.0, 0.0, 0.0));
85  composition.addParticle(box, kvector_t(length / 2.0, 0.0, 0.0));
86  composition.setRotation(RotationZ(90.0 * Units::deg));
87  composition.setPosition(kvector_t(0.0, 0.0, -layer_thickness / 2.0 - height / 2.0));
88  return finalizeMultiLayer(composition);
89 }
90 
91 // --- BoxCompositionRotateZandYBuilder ---
92 
94 {
95  Particle box(particleMaterial, FormFactorBox(length / 2.0, width, height));
96  ParticleComposition composition;
97  composition.addParticle(box, kvector_t(0.0, 0.0, 0.0));
98  composition.addParticle(box, kvector_t(length / 2.0, 0.0, 0.0));
99  composition.setRotation(RotationZ(90.0 * Units::deg));
100  composition.rotate(RotationY(90.0 * Units::deg));
101  composition.setPosition(kvector_t(0.0, 0.0, -layer_thickness / 2.0));
102  return finalizeMultiLayer(composition);
103 }
104 
105 // --- BoxStackCompositionBuilder ---
106 
107 // Composition of two boxes which gives you the box (10,20,50) with reference point as usual.
109 {
110  ParticleComposition composition;
111 
112  // box1 (20,50,5), rotatedZ
113  const double box1_length = 20;
114  const double box1_width = 50;
115  const double box1_height = 5;
116  Particle box1(particleMaterial, FormFactorBox(box1_length, box1_width, box1_height));
117  box1.setRotation(RotationZ(90. * Units::deg));
118 
119  // box2 (5,20,50), rotatedY
120  const double box2_length = 5.0;
121  const double box2_width = 20.0;
122  const double box2_height = 50.0;
123  Particle box2(particleMaterial, FormFactorBox(box2_length, box2_width, box2_height));
124  box2.setRotation(RotationY(90. * Units::deg));
125  box2.setPosition(kvector_t(-box2_height / 2.0, 0.0, box2_length / 2.0));
126 
127  composition.addParticle(box1, kvector_t(0.0, 0.0, 0.0));
128  composition.addParticle(box2, kvector_t(0.0, 0.0, box1_height));
129  composition.setRotation(RotationY(90.0 * Units::deg));
130  composition.setPosition(kvector_t(0.0, 0.0, -layer_thickness / 2.));
131 
132  return finalizeMultiLayer(composition);
133 }
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:23
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) final
Rotates the particle.
Definition: IParticle.cpp:50
void setRotation(const IRotation &rotation)
Sets transformation.
Definition: IParticle.cpp:44
A layer in a MultiLayer sample.
Definition: Layer.h:27
A wrapper for underlying material implementation.
Definition: Material.h:29
Our sample model: a stack of layers one below the other.
Definition: MultiLayer.h:41
void addLayer(const Layer &layer)
Adds layer with default (zero) roughness.
Definition: MultiLayer.cpp:53
A composition of particles at fixed positions.
void addParticle(const IParticle &particle)
Decorator class that adds particles to ISampleNode 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:24
A rotation about the x axis.
Definition: Rotations.h:73
A rotation about the y axis.
Definition: Rotations.h:93
A rotation about the z axis.
Definition: Rotations.h:113
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 deg
Definition: Units.h:46
static constexpr double nm
Definition: Units.h:39
static const Material Substrate2
static const Material Vacuum
static const Material Teflon