BornAgain  1.18.0
Simulate and fit neutron and x-ray scattering at grazing incidence
SampleLabelHandler.cpp
Go to the documentation of this file.
1 // ************************************************************************** //
2 //
3 // BornAgain: simulate and fit scattering at grazing incidence
4 //
5 //! @file Core/Export/SampleLabelHandler.cpp
6 //! @brief Implement class SampleLabelHandler.
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 
24 #include <set>
25 
26 std::string SampleLabelHandler::labelCrystal(const Crystal* cr)
27 {
28  return m_CrystalLabel[cr];
29 }
30 
31 std::string SampleLabelHandler::labelFormFactor(const IFormFactor* ff)
32 {
33  return m_FormFactorLabel[ff];
34 }
35 
36 std::string SampleLabelHandler::labelInterferenceFunction(const IInterferenceFunction* iff)
37 {
38  return m_InterferenceFunctionLabel[iff];
39 }
40 
41 std::string SampleLabelHandler::labelLayer(const Layer* layer)
42 {
43  return m_LayerLabel[layer];
44 }
45 
46 std::string SampleLabelHandler::labelLayout(const ILayout* layout)
47 {
48  return m_ILayoutLabel[layout];
49 }
50 
51 std::string SampleLabelHandler::labelMaterial(const Material* mat)
52 {
53  return m_MaterialLabel[mat];
54 }
55 
56 std::string SampleLabelHandler::labelLattice(const Lattice* lat)
57 {
58  return m_LatticeLabel[lat];
59 }
60 
61 std::string SampleLabelHandler::labelMultiLayer(const MultiLayer* ml)
62 {
63  return m_MultiLayerLabel[ml];
64 }
65 
66 std::string SampleLabelHandler::labelParticle(const IAbstractParticle* absparticle)
67 {
68  if (const auto core_shell_particle = dynamic_cast<const ParticleCoreShell*>(absparticle))
69  return m_ParticleCoreShellLabel[core_shell_particle];
70  if (const auto particle = dynamic_cast<const Particle*>(absparticle))
71  return m_ParticleLabel[particle];
72  if (const auto particle = dynamic_cast<const ParticleDistribution*>(absparticle))
73  return m_ParticleDistributionLabel[particle];
74  if (const auto lattice_basis = dynamic_cast<const ParticleComposition*>(absparticle))
75  return m_ParticleCompositionLabel[lattice_basis];
76  if (const auto mesocrystal = dynamic_cast<const MesoCrystal*>(absparticle))
77  return m_MesoCrystalLabel[mesocrystal];
79  "SampleLabelHandler::getLabel: called for unknown IParticle type");
80 }
81 
82 std::string SampleLabelHandler::labelRotation(const IRotation* rot)
83 {
84  return m_RotationsLabel[rot];
85 }
86 
87 std::string SampleLabelHandler::labelRoughness(const LayerRoughness* roughness)
88 {
89  return m_LayerRoughnessLabel[roughness];
90 }
91 
92 void SampleLabelHandler::insertCrystal(const Crystal* sample)
93 {
94  std::string label = "crystal_" + std::to_string(m_CrystalLabel.size() + 1);
95  m_CrystalLabel.insert(sample, label);
96 }
97 
98 void SampleLabelHandler::insertFormFactor(const IFormFactor* sample)
99 {
100  std::string label = "formFactor_" + std::to_string(m_FormFactorLabel.size() + 1);
101  m_FormFactorLabel.insert(sample, label);
102 }
103 
104 void SampleLabelHandler::insertInterferenceFunction(const IInterferenceFunction* sample)
105 {
106  std::string label = "interference_" + std::to_string(m_InterferenceFunctionLabel.size() + 1);
107  m_InterferenceFunctionLabel.insert(sample, label);
108 }
109 
110 void SampleLabelHandler::insertLayer(const Layer* sample)
111 {
112  std::string label = "layer_" + std::to_string(m_LayerLabel.size() + 1);
113  m_LayerLabel.insert(sample, label);
114 }
115 
116 void SampleLabelHandler::insertLayout(const ILayout* sample)
117 {
118  std::string label = "layout_" + std::to_string(m_ILayoutLabel.size() + 1);
119  m_ILayoutLabel.insert(sample, label);
120 }
121 
122 void SampleLabelHandler::insertMaterial(const Material* mat)
123 {
124  for (auto it = m_MaterialLabel.begin(); it != m_MaterialLabel.end(); ++it) {
125  if (*(it->first) == *mat) {
126  m_MaterialLabel.insert(mat, it->second);
127  return;
128  }
129  }
130  // material not found => create new label
131  std::set<std::string> unique_labels;
132  for (auto it = m_MaterialLabel.begin(); it != m_MaterialLabel.end(); ++it)
133  unique_labels.insert(it->second);
134 
135  std::string label = "material_" + std::to_string(unique_labels.size() + 1);
136  m_MaterialLabel.insert(mat, label);
137 }
138 
139 void SampleLabelHandler::insertLattice(const Lattice* sample)
140 {
141  std::string label = "lattice_" + std::to_string(m_LatticeLabel.size() + 1);
142  m_LatticeLabel.insert(sample, label);
143 }
144 
145 void SampleLabelHandler::insertMesoCrystal(const MesoCrystal* sample)
146 {
147  std::string label = "mesocrystal_" + std::to_string(m_MesoCrystalLabel.size() + 1);
148  m_MesoCrystalLabel.insert(sample, label);
149 }
150 
151 void SampleLabelHandler::insertMultiLayer(const MultiLayer* sample)
152 {
153  std::string label = "multiLayer_" + std::to_string(m_MultiLayerLabel.size() + 1);
154  m_MultiLayerLabel.insert(sample, label);
155 }
156 
157 void SampleLabelHandler::insertParticleComposition(const ParticleComposition* sample)
158 {
159  std::string label =
160  "particleComposition_" + std::to_string(m_ParticleCompositionLabel.size() + 1);
161  m_ParticleCompositionLabel.insert(sample, label);
162 }
163 
164 void SampleLabelHandler::insertParticleDistribution(const ParticleDistribution* sample)
165 {
166  std::string label =
167  "particleDistribution_" + std::to_string(m_ParticleDistributionLabel.size() + 1);
168  m_ParticleDistributionLabel.insert(sample, label);
169 }
170 
171 void SampleLabelHandler::insertParticle(const Particle* sample)
172 {
173  std::string label = "particle_" + std::to_string(m_ParticleLabel.size() + 1);
174  m_ParticleLabel.insert(sample, label);
175 }
176 
177 void SampleLabelHandler::insertParticleCoreShell(const ParticleCoreShell* sample)
178 {
179  std::string label = "particleCoreShell_" + std::to_string(m_ParticleCoreShellLabel.size() + 1);
180  m_ParticleCoreShellLabel.insert(sample, label);
181 }
182 
183 void SampleLabelHandler::insertRotation(const IRotation* sample)
184 {
185  std::string label = "rotation_" + std::to_string(m_RotationsLabel.size() + 1);
186  m_RotationsLabel.insert(sample, label);
187 }
188 
189 void SampleLabelHandler::insertRoughness(const LayerRoughness* sample)
190 {
191  if (sample->getSigma() != 0 && sample->getHurstParameter() != 0
192  && sample->getLatteralCorrLength() != 0) {
193  std::string label = "layerRoughness_" + std::to_string(m_LayerRoughnessLabel.size() + 1);
194  m_LayerRoughnessLabel.insert(sample, label);
195  }
196 }
Defines and implements the interface class IInterferenceFunction.
Defines class LayerRoughness.
Defines class MesoCrystal.
Defines class MultiLayer.
Defines class ParticleComposition.
Defines ParticleCoreShell.
Defines class ParticleDistribution.
Defines class Particle.
Defines classes LabelMap and SampleLabelHandler.
A crystal structure with a ParticleComposition as a basis.
Definition: Crystal.h:26
Interface for a generic particle.
Pure virtual base class for all form factors.
Definition: IFormFactor.h:40
Pure virtual base class of interference functions.
Pure virtual interface class to equip a sample layer with scattering properties.
Definition: ILayout.h:32
Pure virtual interface for rotations.
Definition: Rotations.h:27
A lattice with three basis vectors.
Definition: Lattice.h:28
A roughness of interface between two layers.
double getSigma() const
Returns rms of roughness.
double getLatteralCorrLength() const
Returns lateral correlation length.
double getHurstParameter() const
Returns hurst parameter.
A layer, with thickness (in nanometer) and material.
Definition: Layer.h:28
A wrapper for underlying material implementation.
Definition: Material.h:29
A particle with an internal structure of smaller particles.
Definition: MesoCrystal.h:26
Our sample model: a stack of layers one below the other.
Definition: MultiLayer.h:42
A composition of particles at fixed positions.
A particle with a core/shell geometry.
A particle type that is a parametric distribution of IParticle's.
A particle with a form factor and refractive index.
Definition: Particle.h:26