VGM Version 5.3
Loading...
Searching...
No Matches
VMaterialFactory.cxx
Go to the documentation of this file.
1// $Id$
2
3// -----------------------------------------------------------------------
4// The BaseVGM package of the Virtual Geometry Model
5// Copyright (C) 2007, Ivana Hrivnacova
6// All rights reserved.
7//
8// For the licensing terms see vgm/LICENSE.
9// Contact: ivana@ipno.in2p3.fr
10// -----------------------------------------------------------------------
11
12//
13// Class VMaterialFactory
14// ---------------
15// The abstract base class to material factory.
16// It owns the material stores and implements the export
17// to other factory.
18//
19// Author: Ivana Hrivnacova; IPN Orsay
20
25
28
29//_____________________________________________________________________________
31 : VGM::IMaterialFactory(),
32 fDebug(0),
33 fName(name),
34 fIsotopes(),
35 fElements(),
36 fMaterials(),
37 fMedia()
38{
40}
41
42//_____________________________________________________________________________
44{
46}
47
48//_____________________________________________________________________________
50 : VGM::IMaterialFactory(rhs)
51{
53}
54
55//_____________________________________________________________________________
57{
58 // Deletes all objects created via material factory
59
60 // Delete isotopes
61 for (unsigned int i = 0; i < fIsotopes.size(); i++) {
62 delete fIsotopes[i];
63 }
64
65 // Delete elements
66 for (unsigned int i = 0; i < fElements.size(); i++) {
67 delete fElements[i];
68 }
69
70 // Delete materials
71 for (unsigned int j = 0; j < fMaterials.size(); j++) {
72 delete fMaterials[j];
73 }
74
75 // Delete media
76 for (unsigned int k = 0; k < fMedia.size(); k++) {
77 delete fMedia[k];
78 }
79}
80
81//
82// private functions
83//
84
85//_____________________________________________________________________________
86VGM::IIsotope* BaseVGM::VMaterialFactory::ExportIsotope(
87 VGM::IIsotope* isotope, VGM::IMaterialFactory* factory) const
88{
89 // Exports specified material to given factory
90 // ---
91
92 if (Debug() > 0) {
94 std::cout << "Exporting isotope: ";
95 if (Debug() > 1) std::cout << isotope;
96 std::cout << std::endl;
98 std::cout << *isotope << std::endl;
99 }
100
101 VGM::IIsotope* newIsotope = factory->CreateIsotope(
102 isotope->Name(), isotope->Z(), isotope->N(), isotope->A());
103 return newIsotope;
104}
105
106//_____________________________________________________________________________
107VGM::IElement* BaseVGM::VMaterialFactory::ExportElement(VGM::IElement* element,
108 VGM::IMaterialFactory* factory, IsotopeMap* isotopeMap) const
109{
110 // Exports specified element to given factory
111 // ---
112
113 if (Debug() > 0) {
115 std::cout << "Exporting element: ";
116 if (Debug() > 1) std::cout << element;
117 std::cout << std::endl;
119 std::cout << *element << std::endl;
120 }
121
122 VGM::IElement* newElement;
123 if (!element->NofIsotopes()) {
124 newElement = factory->CreateElement(
125 element->Name(), element->Symbol(), element->Z(), element->A());
126 }
127 else {
128 // Fill isotopes vector
129 VGM::IsotopeVector isotopes;
130 VGM::RelAbundanceVector relAbundances;
131 for (int i = 0; i < element->NofIsotopes(); i++) {
132 VGM::IIsotope* isotope = element->Isotope(i);
133 VGM::IIsotope* newIsotope = (*isotopeMap)[isotope];
134 double relAbundance = element->RelAbundance(i);
135
136 isotopes.push_back(newIsotope);
137 relAbundances.push_back(relAbundance);
138 }
139 newElement = factory->CreateElement(
140 element->Name(), element->Symbol(), isotopes, relAbundances);
141 }
142
143 return newElement;
144}
145
146//_____________________________________________________________________________
147VGM::IMaterial* BaseVGM::VMaterialFactory::ExportMaterial(
148 VGM::IMaterial* material, VGM::IMaterialFactory* factory,
149 ElementMap* elementMap) const
150{
151 // Exports specified material to given factory
152 // ---
153
154 if (Debug() > 0) {
156 std::cout << "Exporting material: ";
157 if (Debug() > 1) std::cout << material;
158 std::cout << std::endl;
160 std::cout << *material << std::endl;
161 }
162
163 VGM::IMaterial* newMaterial;
164 int nofElements = material->NofElements();
165 if (nofElements == 1) {
166 VGM::IElement* newElement = (*elementMap)[material->Element(0)];
167 newMaterial = factory->CreateMaterial(material->Name(), material->Density(),
168 newElement, material->RadiationLength(), material->NuclearInterLength(),
169 material->State(), material->Temperature(), material->Pressure());
170 }
171 else {
172 // Fill elements vector
173 VGM::ElementVector elements;
174 VGM::MassFractionVector massFractions;
175 for (int i = 0; i < material->NofElements(); i++) {
176 VGM::IElement* element = material->Element(i);
177 VGM::IElement* newElement = (*elementMap)[element];
178 double massFraction = material->MassFraction(i);
179
180 elements.push_back(newElement);
181 massFractions.push_back(massFraction);
182 }
183
184 newMaterial = factory->CreateMaterial(material->Name(), material->Density(),
185 elements, massFractions, material->State(), material->Temperature(),
186 material->Pressure());
187 }
188
189 return newMaterial;
190}
191
192//_____________________________________________________________________________
193VGM::IMedium* BaseVGM::VMaterialFactory::ExportMedium(VGM::IMedium* medium,
194 VGM::IMaterialFactory* factory, MaterialMap* materialMap) const
195{
196 // Exports specified material to given factory
197 // ---
198
199 if (Debug() > 0) {
201 std::cout << "Exporting medium: ";
202 if (Debug() > 1) std::cout << medium;
203 std::cout << std::endl;
205 std::cout << *medium << std::endl;
206 }
207
208 VGM::IMaterial* material = medium->Material();
209 VGM::IMaterial* newMaterial = (*materialMap)[material];
210
211 int nofParameters = medium->NofParameters();
212 double* parameters = new double[nofParameters];
213 for (int i = 0; i < nofParameters; i++) parameters[i] = medium->Parameter(i);
214
215 VGM::IMedium* newMedium = factory->CreateMedium(
216 medium->Name(), medium->Id(), newMaterial, nofParameters, parameters);
217
218 delete[] parameters;
219
220 return newMedium;
221}
222
223//_____________________________________________________________________________
224VGM::IMedium* BaseVGM::VMaterialFactory::GenerateMedium(
225 VGM::IMaterial* material, int mediumId, VGM::IMaterialFactory* factory,
226 MaterialMap* materialMap) const
227{
228 // Exports specified material to given factory
229 // ---
230
231 if (Debug() > 0) {
233 std::cout << "Generation medium for material: ";
234 if (Debug() > 1) std::cout << material;
235 std::cout << std::endl;
237 std::cout << *material << std::endl;
238 }
239
240 VGM::IMaterial* newMaterial = (*materialMap)[material];
241
242 int nofParameters = 0;
243 double* parameters = new double[nofParameters];
244
245 VGM::IMedium* newMedium = factory->CreateMedium(
246 material->Name(), mediumId, newMaterial, nofParameters, parameters);
247
248 delete[] parameters;
249
250 return newMedium;
251}
252
253//_____________________________________________________________________________
254BaseVGM::VMaterialFactory::IsotopeMap*
255BaseVGM::VMaterialFactory::ExportIsotopes(VGM::IMaterialFactory* factory) const
256{
257 // Export the whole isotope store to the given factory.
258 // ---
259
260 IsotopeMap* isotopeMap = new IsotopeMap();
261
262 for (unsigned int i = 0; i < Isotopes().size(); i++) {
263
264 VGM::IIsotope* isotope = Isotopes()[i];
265 VGM::IIsotope* newIsotope = ExportIsotope(isotope, factory);
266
267 // Map new isotope to old isotope
268 (*isotopeMap)[isotope] = newIsotope;
269 }
270
271 return isotopeMap;
272}
273
274//_____________________________________________________________________________
275BaseVGM::VMaterialFactory::ElementMap*
276BaseVGM::VMaterialFactory::ExportElements(
277 VGM::IMaterialFactory* factory, IsotopeMap* isotopeMap) const
278{
279 // Export the whole element store to the given factory.
280 // ---
281
282 ElementMap* elementMap = new ElementMap();
283
284 for (unsigned int i = 0; i < Elements().size(); i++) {
285
286 VGM::IElement* element = Elements()[i];
287 VGM::IElement* newElement = ExportElement(element, factory, isotopeMap);
288
289 // Map new element to old element
290 (*elementMap)[element] = newElement;
291 }
292
293 return elementMap;
294}
295
296//_____________________________________________________________________________
297BaseVGM::VMaterialFactory::MaterialMap*
298BaseVGM::VMaterialFactory::ExportMaterials(
299 VGM::IMaterialFactory* factory, ElementMap* elementMap) const
300{
301 // Export the whole material store to the given factory.
302 // ---
303
304 MaterialMap* materialMap = new MaterialMap();
305
306 for (unsigned int i = 0; i < Materials().size(); i++) {
307
308 VGM::IMaterial* material = Materials()[i];
309 VGM::IMaterial* newMaterial = ExportMaterial(material, factory, elementMap);
310
311 // Map new material to old material
312 (*materialMap)[material] = newMaterial;
313 }
314
315 return materialMap;
316}
317
318//_____________________________________________________________________________
319void BaseVGM::VMaterialFactory::ExportMedia(
320 VGM::IMaterialFactory* factory, MaterialMap* materialMap) const
321{
322 // Export the whole media store to the given factory.
323 // ---
324
325 for (unsigned int i = 0; i < Media().size(); i++) {
326 VGM::IMedium* medium = Media()[i];
327 ExportMedium(medium, factory, materialMap);
328 }
329
330 delete materialMap;
331}
332
333//_____________________________________________________________________________
334void BaseVGM::VMaterialFactory::GenerateMedia(
335 VGM::IMaterialFactory* factory, MaterialMap* materialMap) const
336{
337 // Generate media from materials.
338 // (Use this fuinction if the given factory has not defined media.)
339 // ---
340
341 for (unsigned int i = 0; i < Materials().size(); i++) {
342 VGM::IMaterial* material = Materials()[i];
343 GenerateMedium(material, i, factory, materialMap);
344 }
345
346 delete materialMap;
347}
348
349//
350// public functions
351//
352
353//_____________________________________________________________________________
355 const std::string& name) const
356{
359
360 for (unsigned int i = 0; i < Isotopes().size(); i++) {
361 const VGM::IIsotope* isotope = Isotopes()[i];
362 if (isotope->Name() == name) return isotope;
363 }
364
365 return 0;
366}
367
368//_____________________________________________________________________________
370 const std::string& name) const
371{
374
375 for (unsigned int i = 0; i < Elements().size(); i++) {
376 const VGM::IElement* element = Elements()[i];
377 if (element->Name() == name) return element;
378 }
379
380 return 0;
381}
382
383//_____________________________________________________________________________
385 const std::string& name) const
386{
389
390 for (unsigned int i = 0; i < Materials().size(); i++) {
391 const VGM::IMaterial* material = Materials()[i];
392 if (material->Name() == name) return material;
393 }
394
395 return 0;
396}
397
398//_____________________________________________________________________________
400 const std::string& name) const
401{
404
405 for (unsigned int i = 0; i < Media().size(); i++) {
406 const VGM::IMedium* medium = Media()[i];
407 if (medium->Name() == name) return medium;
408 }
409
410 return 0;
411}
412
413//_____________________________________________________________________________
415{
417
418 IsotopeMap* isotopeMap = ExportIsotopes(factory);
419 ElementMap* elementMap = ExportElements(factory, isotopeMap);
420 MaterialMap* materialMap = ExportMaterials(factory, elementMap);
421 if (Media().size() > 0)
422 ExportMedia(factory, materialMap);
423 else
424 GenerateMedia(factory, materialMap);
425
426 return true;
427}
428
429//_____________________________________________________________________________
431{
433
434 const VGM::IsotopeStore& isotopes = Isotopes();
435
436 for (unsigned i = 0; i < isotopes.size(); i++) {
437
438 std::cout << i << "th isotope: " << std::endl;
439 std::cout << *isotopes[i] << std::endl;
440 }
441}
442
443//_____________________________________________________________________________
445{
447
448 const VGM::ElementStore& elements = Elements();
449
450 for (unsigned i = 0; i < elements.size(); i++) {
451
452 std::cout << i << "th element: " << std::endl;
453 std::cout << *elements[i] << std::endl;
454 }
455}
456
457//_____________________________________________________________________________
459{
461
462 const VGM::MaterialStore& materials = Materials();
463
464 for (unsigned i = 0; i < materials.size(); i++) {
465
466 std::cout << i << "th material: " << std::endl;
467 std::cout << *materials[i] << std::endl;
468 }
469}
470
471//_____________________________________________________________________________
473{
475
476 const VGM::MediumStore& media = Media();
477
478 for (unsigned i = 0; i < media.size(); i++) {
479
480 std::cout << i << "th medium: " << std::endl;
481 std::cout << *media[i] << std::endl;
482 }
483}
The abstract base class to material factory.
virtual const VGM::IMedium * Medium(const std::string &name) const
Return medium specified by name.
virtual const VGM::IMaterial * Material(const std::string &name) const
Return material specified by name.
virtual const VGM::IElement * Element(const std::string &name) const
Return element specified by name.
virtual const VGM::IIsotope * Isotope(const std::string &name) const
Return isotope specified by name.
virtual void PrintMaterials() const
Print all materials.
virtual bool Export(VGM::IMaterialFactory *factory) const
Export materials to the specified material factory.
virtual void PrintMedia() const
Print all media.
virtual void PrintElements() const
Print all elements.
virtual void PrintIsotopes() const
Print all isotopes.
The VGM interface to elements.
Definition IElement.h:34
virtual IIsotope * Isotope(int i) const =0
Return the i-th isotope constituing this element.
virtual int NofIsotopes() const =0
Return the number of isotopes constituing this element.
virtual double Z() const =0
Return the effective atomic number.
virtual double RelAbundance(int i) const =0
Return the relative abundance (the fraction of nb of atomes per volume) of the i-th isotope constitui...
virtual std::string Name() const =0
Return the name of this element.
virtual std::string Symbol() const =0
Return the symbol of this element.
virtual double A() const =0
Return the effective effective mass of a mole in g/mole.
The VGM interface to elements.
Definition IIsotope.h:28
virtual int N() const =0
Return the effective number of nucleons.
virtual std::string Name() const =0
Return the name of this element.
virtual double A() const =0
Return the effective effective mass of a mole in g/mole.
virtual int Z() const =0
Return the effective atomic number.
The VGM interface to material factory providing functions for material conversions.
virtual IElement * CreateElement(const std::string &name, const std::string &symbol, double z, double a)=0
Create a chemical element.
virtual IMedium * CreateMedium(const std::string &name, int mediumId, VGM::IMaterial *material, int nofParameters, double *parameters)=0
Create a tracking medium.
virtual IMaterial * CreateMaterial(const std::string &name, double density, VGM::IElement *element, double radlen, double intlen)=0
Create a material.
virtual IIsotope * CreateIsotope(const std::string &name, int z, int n, double a=0.)=0
Create a chemical isotope.
The VGM interface to materials.
Definition IMaterial.h:44
virtual double Pressure() const =0
Return the density in atmosphere.
virtual IElement * Element(int iel) const =0
Return the i-th element constituing this material.
virtual double NuclearInterLength() const =0
Return the nuclear interaction length in mm.
virtual double Density() const =0
Return the density in g/cm3.
virtual double Temperature() const =0
Return the temperature in kelvins.
virtual std::string Name() const =0
Return the name of this element.
virtual double RadiationLength() const =0
Return the radiation length in mm.
virtual MaterialState State() const =0
Return the material state.
virtual double MassFraction(int iel) const =0
Return the mass fraction of the i-th element constituing this material.
virtual int NofElements() const =0
Return the number of elements constituing this material.
The VGM interface to tracking medium.
Definition IMedium.h:31
virtual IMaterial * Material() const =0
Return its associated material.
virtual int NofParameters() const =0
Return the number of defined parameters.
virtual double Parameter(int i) const =0
Return the i-th parameter.
virtual int Id() const =0
Return its unique identifier.
virtual std::string Name() const =0
Return its name.
void DebugInfo()
Debug printing.
Definition utilities.cxx:27
VGM interfaces.
Definition VMedium.h:28
std::vector< IMaterial * > MaterialStore
std::vector< double > RelAbundanceVector
Definition IElement.h:31
std::vector< double > MassFractionVector
Definition IMaterial.h:32
std::vector< IElement * > ElementVector
Definition IMaterial.h:31
std::vector< IMedium * > MediumStore
std::vector< IIsotope * > IsotopeStore
std::vector< IIsotope * > IsotopeVector
Definition IElement.h:30
std::vector< IElement * > ElementStore