BornAgain  1.19.79
Open-source research software to simulate and fit neutron and x-ray reflectometry and grazing-incidence small-angle scattering
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"
25 
26 using Units::deg;
27 
28 namespace {
29 
30 const Material particleMaterial = RefractiveMaterial("Ag", 1.245e-5, 5.419e-7);
31 const double layer_thickness = 100.0;
32 const double length = 50.0;
33 const double width = 20.0;
34 const double height = 10.0;
35 
36 MultiLayer* finalizeMultiLayer(const ParticleComposition& composition)
37 {
38  ParticleLayout layout;
39  layout.addParticle(composition);
40 
41  Layer vacuum_layer(refMat::Vacuum);
42  Layer middle_layer(refMat::Teflon, layer_thickness);
43  middle_layer.addLayout(layout);
44  Layer substrate(refMat::Substrate2);
45 
46  auto* sample = new MultiLayer();
47  sample->addLayer(vacuum_layer);
48  sample->addLayer(middle_layer);
49  sample->addLayer(substrate);
50  return sample;
51 }
52 
53 } // namespace
54 
55 // --- BoxCompositionRotateXBuilder ---
56 
58 {
59  Particle box(particleMaterial, Box(length / 2.0, width, height));
60  ParticleComposition composition;
61  composition.addParticle(box, R3(0.0, 0.0, 0.0));
62  composition.addParticle(box, R3(length / 2.0, 0.0, 0.0));
63  composition.setRotation(RotationX(90.0 * deg));
64  composition.setParticlePosition(R3(0.0, 0.0, -layer_thickness / 2.0));
65  return finalizeMultiLayer(composition);
66 }
67 
68 // --- BoxCompositionRotateYBuilder ---
69 
71 {
72  Particle box(particleMaterial, Box(length / 2.0, width, height));
73  ParticleComposition composition;
74  composition.addParticle(box, R3(0.0, 0.0, 0.0));
75  composition.addParticle(box, R3(length / 2.0, 0.0, 0.0));
76  composition.setRotation(RotationY(90.0 * deg));
77  composition.setParticlePosition(R3(0.0, 0.0, -layer_thickness / 2.0 + length / 4.0));
78  return finalizeMultiLayer(composition);
79 }
80 
81 // --- BoxCompositionRotateZBuilder ---
82 
84 {
85  Particle box(particleMaterial, Box(length / 2.0, width, height));
86  ParticleComposition composition;
87  composition.addParticle(box, R3(0.0, 0.0, 0.0));
88  composition.addParticle(box, R3(length / 2.0, 0.0, 0.0));
89  composition.setRotation(RotationZ(90.0 * deg));
90  composition.setParticlePosition(R3(0.0, 0.0, -layer_thickness / 2.0 - height / 2.0));
91  return finalizeMultiLayer(composition);
92 }
93 
94 // --- BoxCompositionRotateZandYBuilder ---
95 
97 {
98  Particle box(particleMaterial, Box(length / 2.0, width, height));
99  ParticleComposition composition;
100  composition.addParticle(box, R3(0.0, 0.0, 0.0));
101  composition.addParticle(box, R3(length / 2.0, 0.0, 0.0));
102  composition.setRotation(RotationZ(90.0 * deg));
103  composition.rotate(RotationY(90.0 * deg));
104  composition.setParticlePosition(R3(0.0, 0.0, -layer_thickness / 2.0));
105  return finalizeMultiLayer(composition);
106 }
107 
108 // --- BoxStackCompositionBuilder ---
109 
110 // Composition of two boxes which gives you the box (10,20,50) with reference point as usual.
112 {
113  ParticleComposition composition;
114 
115  // box1 (20,50,5), rotatedZ
116  const double box1_length = 20;
117  const double box1_width = 50;
118  const double box1_height = 5;
119  Particle box1(particleMaterial, Box(box1_length, box1_width, box1_height));
120  box1.setRotation(RotationZ(90. * deg));
121 
122  // box2 (5,20,50), rotatedY
123  const double box2_length = 5.0;
124  const double box2_width = 20.0;
125  const double box2_height = 50.0;
126  Particle box2(particleMaterial, Box(box2_length, box2_width, box2_height));
127  box2.setRotation(RotationY(90. * deg));
128  box2.setParticlePosition(R3(-box2_height / 2.0, 0.0, box2_length / 2.0));
129 
130  composition.addParticle(box1, R3(0.0, 0.0, 0.0));
131  composition.addParticle(box2, R3(0.0, 0.0, box1_height));
132  composition.setRotation(RotationY(90.0 * deg));
133  composition.setParticlePosition(R3(0.0, 0.0, -layer_thickness / 2.));
134 
135  return finalizeMultiLayer(composition);
136 }
Defines classes of BoxCompositionBuilder family.
Defines class Box.
Defines class Layer.
Defines class MultiLayer.
Defines class ParticleComposition.
Defines class ParticleLayout.
Defines class Particle.
Defines materials in namespace refMat.
Defines IRotation classes.
Defines some unit conversion factors and other constants in namespace Units.
A rectangular prism (parallelepiped).
Definition: Box.h:23
void setParticlePosition(R3 position)
Sets relative position of the particle's reference point in the coordinate system of parent.
Definition: IParticle.h:51
IParticle * rotate(const IRotation &rotation)
Rotates the particle, and returns this.
Definition: IParticle.cpp:41
void setRotation(const IRotation &rotation)
Sets transformation.
Definition: IParticle.cpp:36
A layer in a MultiLayer sample.
Definition: Layer.h:26
A wrapper for underlying material implementation.
Definition: Material.h:35
Our sample model: a stack of layers one below the other.
Definition: MultiLayer.h:43
A composition of particles at fixed positions.
void addParticle(const IParticle &particle)
Decorator class that adds particles to ISampleNode objects.
void addParticle(const IParticle &particle, double abundance=-1.0)
Adds particle to the layout with abundance, position and the rotation defined.
A particle with a form factor and refractive index.
Definition: Particle.h:25
A rotation about the x axis.
Definition: Rotations.h:74
A rotation about the y axis.
Definition: Rotations.h:98
A rotation about the z axis.
Definition: Rotations.h:122
Material RefractiveMaterial(const std::string &name, complex_t refractive_index, R3 magnetization)
MultiLayer * createBoxStackComposition()
MultiLayer * createBoxCompositionRotateX()
MultiLayer * createBoxCompositionRotateZ()
MultiLayer * createBoxCompositionRotateY()
MultiLayer * createBoxCompositionRotateZandY()
static constexpr double deg
Definition: Units.h:46
static const Material Substrate2
static const Material Vacuum
static const Material Teflon