Geant4 11.2.2
Toolkit for the simulation of the passage of particles through matter
Loading...
Searching...
No Matches
G4Material.cc
Go to the documentation of this file.
1//
2// ********************************************************************
3// * License and Disclaimer *
4// * *
5// * The Geant4 software is copyright of the Copyright Holders of *
6// * the Geant4 Collaboration. It is provided under the terms and *
7// * conditions of the Geant4 Software License, included in the file *
8// * LICENSE and available at http://cern.ch/geant4/license . These *
9// * include a list of copyright holders. *
10// * *
11// * Neither the authors of this software system, nor their employing *
12// * institutes,nor the agencies providing financial support for this *
13// * work make any representation or warranty, express or implied, *
14// * regarding this software system or assume any liability for its *
15// * use. Please see the license in the file LICENSE and URL above *
16// * for the full disclaimer and the limitation of liability. *
17// * *
18// * This code implementation is the result of the scientific and *
19// * technical work of the GEANT4 collaboration. *
20// * By using, copying, modifying or distributing the software (or *
21// * any work based on the software) you agree to acknowledge its *
22// * use in resulting scientific publications, and indicate your *
23// * acceptance of all terms of the Geant4 Software license. *
24// ********************************************************************
25
26// 26-06-96, Code uses operators (+=, *=, ++, -> etc.) correctly, P. Urban
27// 10-07-96, new data members added by L.Urban
28// 12-12-96, new data memberfFreeElecDensitys added by L.Urban
29// 20-01-97, aesthetic rearrangement. RadLength calculation modified.
30// Data members Zeff and Aeff REMOVED (i.e. passed to the Elements).
31// (local definition of Zeff in DensityEffect and FluctModel...)
32// Vacuum defined as a G4State. Mixture flag removed, M.Maire.
33// 29-01-97, State=Vacuum automatically set density=0 in the contructors.
34// Subsequent protections have been put in the calculation of
35// MeanExcEnergy, ShellCorrectionVector, DensityEffect, M.Maire.
36// 11-02-97, ComputeDensityEffect() rearranged, M.Maire.
37// 20-03-97, corrected initialization of pointers, M.Maire.
38// 28-05-98, the kState=kVacuum has been removed.
39// automatic check for a minimal density, M.Maire
40// 12-06-98, new method AddMaterial() allowing mixture of materials, M.Maire
41// 09-07-98, ionisation parameters removed from the class, M.Maire
42// 05-10-98, change names: NumDensity -> NbOfAtomsPerVolume
43// 18-11-98, new interface to SandiaTable
44// 19-01-99 enlarge tolerance on test of coherence of gas conditions
45// 19-07-99, Constructors with chemicalFormula added by V.Ivanchenko
46// 16-01-01, Nuclear interaction length, M.Maire
47// 12-03-01, G4bool fImplicitElement;
48// copy constructor and assignement operator revised (mma)
49// 03-05-01, flux.precision(prec) at begin/end of operator<<
50// 17-07-01, migration to STL. M. Verderi.
51// 14-09-01, Suppression of the data member fIndexInTable
52// 26-02-02, fIndexInTable renewed
53// 16-04-02, G4Exception put in constructor with chemical formula
54// 06-05-02, remove the check of the ideal gas state equation
55// 06-08-02, remove constructors with chemical formula (mma)
56// 22-01-04, proper STL handling of theElementVector (Hisaya)
57// 30-03-05, warning in GetMaterial(materialName)
58// 09-03-06, minor change of printout (V.Ivanchenko)
59// 10-01-07, compute fAtomVector in the case of mass fraction (V.Ivanchenko)
60// 27-07-07, improve destructor (V.Ivanchenko)
61// 18-10-07, moved definition of mat index to InitialisePointers (V.Ivanchenko)
62// 13-08-08, do not use fixed size arrays (V.Ivanchenko)
63// 26-10-11, new scheme for G4Exception (mma)
64// 13-04-12, map<G4Material*,G4double> fMatComponents, filled in AddMaterial()
65// 21-04-12, fMassOfMolecule, computed for AtomsCount (mma)
66
67#include "G4Material.hh"
68
69#include "G4ApplicationState.hh"
70#include "G4AtomicShells.hh"
71#include "G4Exp.hh"
72#include "G4ExtendedMaterial.hh"
73#include "G4Log.hh"
74#include "G4NistManager.hh"
76#include "G4StateManager.hh"
77#include "G4SystemOfUnits.hh"
78#include "G4UnitsTable.hh"
79
80#include <iomanip>
81
82G4MaterialTable G4Material::theMaterialTable;
83
84//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
85
86// Constructor to create a material from scratch
87
89 G4State state, G4double temp, G4double pressure)
90 : fName(name)
91{
92 InitializePointers();
93
94 if (density < universe_mean_density) {
95 G4cout << " G4Material WARNING:"
96 << " define a material with density=0 is not allowed. \n"
97 << " The material " << name << " will be constructed with the"
98 << " default minimal density: " << universe_mean_density / (g / cm3) << "g/cm3"
99 << G4endl;
100 density = universe_mean_density;
101 }
102
103 fDensity = density;
104 fState = state;
105 fTemp = temp;
106 fPressure = pressure;
107
108 // Initialize theElementVector allocating one
109 // element corresponding to this material
110 fNbComponents = fNumberOfElements = 1;
111 theElementVector = new G4ElementVector();
112
113 // take element from DB
115 G4int iz = G4lrint(z);
116 auto elm = nist->FindOrBuildElement(iz);
117 if (elm == nullptr) {
118 elm = new G4Element("ELM_" + name, name, z, a);
119 }
120 theElementVector->push_back(elm);
121
122 fMassFractionVector = new G4double[1];
123 fMassFractionVector[0] = 1.;
124 fMassOfMolecule = a / CLHEP::Avogadro;
125
126 if (fState == kStateUndefined) {
127 if (fDensity > kGasThreshold) {
128 fState = kStateSolid;
129 }
130 else {
131 fState = kStateGas;
132 }
133 }
134
135 ComputeDerivedQuantities();
136}
137
138//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
139
140// Constructor to create a material from a List of constituents
141// (elements and/or materials) added with AddElement or AddMaterial
142
143G4Material::G4Material(const G4String& name, G4double density, G4int nComponents, G4State state,
144 G4double temp, G4double pressure)
145 : fName(name)
146{
147 InitializePointers();
148
149 if (density < universe_mean_density) {
150 G4cout << "--- Warning from G4Material::G4Material()"
151 << " define a material with density=0 is not allowed. \n"
152 << " The material " << name << " will be constructed with the"
153 << " default minimal density: " << universe_mean_density / (g / cm3) << "g/cm3"
154 << G4endl;
155 density = universe_mean_density;
156 }
157
158 fDensity = density;
159 fState = state;
160 fTemp = temp;
161 fPressure = pressure;
162
163 fNbComponents = nComponents;
164 fMassFraction = true;
165
166 if (fState == kStateUndefined) {
167 if (fDensity > kGasThreshold) {
168 fState = kStateSolid;
169 }
170 else {
171 fState = kStateGas;
172 }
173 }
174}
175
176//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
177
178// Constructor to create a material from base material
179
180G4Material::G4Material(const G4String& name, G4double density, const G4Material* bmat,
181 G4State state, G4double temp, G4double pressure)
182 : fName(name)
183{
184 InitializePointers();
185
186 if (density < universe_mean_density) {
187 G4cout << "--- Warning from G4Material::G4Material()"
188 << " define a material with density=0 is not allowed. \n"
189 << " The material " << name << " will be constructed with the"
190 << " default minimal density: " << universe_mean_density / (g / cm3) << "g/cm3"
191 << G4endl;
192 density = universe_mean_density;
193 }
194
195 fDensity = density;
196 fState = state;
197 fTemp = temp;
198 fPressure = pressure;
199
200 fBaseMaterial = bmat;
201 auto ptr = bmat;
202 if (nullptr != ptr) {
203 while (true) {
204 ptr = ptr->GetBaseMaterial();
205 if (nullptr == ptr) {
206 break;
207 }
208 fBaseMaterial = ptr;
209 }
210 }
211
212 fChemicalFormula = fBaseMaterial->GetChemicalFormula();
213 fMassOfMolecule = fBaseMaterial->GetMassOfMolecule();
214
215 fNumberOfElements = (G4int)fBaseMaterial->GetNumberOfElements();
216 fNbComponents = fNumberOfElements;
217
218 CopyPointersOfBaseMaterial();
219}
220
221//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
222
224{
225 if (fBaseMaterial == nullptr) {
226 delete theElementVector;
227 delete fSandiaTable;
228 delete[] fMassFractionVector;
229 delete[] fAtomsVector;
230 }
231 delete fIonisation;
232 delete[] fVecNbOfAtomsPerVolume;
233
234 // Remove this material from theMaterialTable.
235 //
236 theMaterialTable[fIndexInTable] = nullptr;
237}
238
239//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
240
241void G4Material::InitializePointers()
242{
243 fBaseMaterial = nullptr;
244 fMaterialPropertiesTable = nullptr;
245 theElementVector = nullptr;
246 fAtomsVector = nullptr;
247 fMassFractionVector = nullptr;
248 fVecNbOfAtomsPerVolume = nullptr;
249
250 fIonisation = nullptr;
251 fSandiaTable = nullptr;
252
253 fDensity = fFreeElecDensity = fTemp = fPressure = 0.0;
254 fTotNbOfAtomsPerVolume = 0.0;
255 fTotNbOfElectPerVolume = 0.0;
256 fRadlen = fNuclInterLen = fMassOfMolecule = 0.0;
257
258 fState = kStateUndefined;
259 fNumberOfElements = fNbComponents = fIdxComponent = 0;
260 fMassFraction = true;
261 fChemicalFormula = "";
262
263 // Store in the static Table of Materials
264 fIndexInTable = theMaterialTable.size();
265 for (std::size_t i = 0; i < fIndexInTable; ++i) {
266 if (theMaterialTable[i]->GetName() == fName) {
267 G4cout << "G4Material WARNING: duplicate name of material " << fName << G4endl;
268 break;
269 }
270 }
271 theMaterialTable.push_back(this);
272}
273
274//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
275
276void G4Material::ComputeDerivedQuantities()
277{
278 // Header routine to compute various properties of material.
279 //
280 // Number of atoms per volume (per element), total nb of electrons per volume
281 G4double Zi, Ai;
282 fTotNbOfAtomsPerVolume = 0.;
283 delete[] fVecNbOfAtomsPerVolume;
284 fVecNbOfAtomsPerVolume = new G4double[fNumberOfElements];
285 fTotNbOfElectPerVolume = 0.;
286 fFreeElecDensity = 0.;
287 const G4double elecTh = 15. * CLHEP::eV; // threshold for conductivity e-
288 for (G4int i = 0; i < fNumberOfElements; ++i) {
289 Zi = (*theElementVector)[i]->GetZ();
290 Ai = (*theElementVector)[i]->GetA();
291 fVecNbOfAtomsPerVolume[i] = Avogadro * fDensity * fMassFractionVector[i] / Ai;
292 fTotNbOfAtomsPerVolume += fVecNbOfAtomsPerVolume[i];
293 fTotNbOfElectPerVolume += fVecNbOfAtomsPerVolume[i] * Zi;
294 if (fState != kStateGas) {
295 fFreeElecDensity +=
296 fVecNbOfAtomsPerVolume[i] * G4AtomicShells::GetNumberOfFreeElectrons(Zi, elecTh);
297 }
298 }
299
300 ComputeRadiationLength();
301 ComputeNuclearInterLength();
302
303 if (fIonisation == nullptr) {
304 fIonisation = new G4IonisParamMat(this);
305 }
306 if (fSandiaTable == nullptr) {
307 fSandiaTable = new G4SandiaTable(this);
308 }
309}
310
311//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
312
313void G4Material::CopyPointersOfBaseMaterial()
314{
315 G4double factor = fDensity / fBaseMaterial->GetDensity();
316 fTotNbOfAtomsPerVolume = factor * fBaseMaterial->GetTotNbOfAtomsPerVolume();
317 fTotNbOfElectPerVolume = factor * fBaseMaterial->GetTotNbOfElectPerVolume();
318 fFreeElecDensity = factor * fBaseMaterial->GetFreeElectronDensity();
319
320 if (fState == kStateUndefined) {
321 fState = fBaseMaterial->GetState();
322 }
323
324 theElementVector = const_cast<G4ElementVector*>(fBaseMaterial->GetElementVector());
325 fMassFractionVector = const_cast<G4double*>(fBaseMaterial->GetFractionVector());
326 fAtomsVector = const_cast<G4int*>(fBaseMaterial->GetAtomsVector());
327
328 const G4double* v = fBaseMaterial->GetVecNbOfAtomsPerVolume();
329 delete[] fVecNbOfAtomsPerVolume;
330 fVecNbOfAtomsPerVolume = new G4double[fNumberOfElements];
331 for (G4int i = 0; i < fNumberOfElements; ++i) {
332 fVecNbOfAtomsPerVolume[i] = factor * v[i];
333 }
334 fRadlen = fBaseMaterial->GetRadlen() / factor;
335 fNuclInterLen = fBaseMaterial->GetNuclearInterLength() / factor;
336
337 if (fIonisation == nullptr) {
338 fIonisation = new G4IonisParamMat(this);
339 }
340 fIonisation->SetMeanExcitationEnergy(fBaseMaterial->GetIonisation()->GetMeanExcitationEnergy());
341 if (fBaseMaterial->GetIonisation()->GetDensityEffectCalculator() != nullptr) {
343 }
344
345 fSandiaTable = fBaseMaterial->GetSandiaTable();
346 fMaterialPropertiesTable = fBaseMaterial->GetMaterialPropertiesTable();
347}
348
349//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
350
352{
353 // perform checks consistency
354 if (0 == fIdxComponent) {
355 fMassFraction = false;
356 fAtoms = new std::vector<G4int>;
357 fElm = new std::vector<const G4Element*>;
358 }
359 if (fIdxComponent >= fNbComponents) {
361 ed << "For material " << fName << " and added element " << elm->GetName()
362 << " with Natoms=" << nAtoms
363 << " wrong attempt to add more than the declared number of elements " << fIdxComponent
364 << " >= " << fNbComponents;
365 G4Exception("G4Material::AddElementByNumberOfAtoms()", "mat031", FatalException, ed, "");
366 }
367 if (fMassFraction) {
369 ed << "For material " << fName << " and added element " << elm->GetName()
370 << " with Natoms=" << nAtoms << " problem: cannot add by number of atoms after "
371 << "addition of elements by mass fraction";
372 G4Exception("G4Material::AddElementByNumberOfAtoms()", "mat031", FatalException, ed, "");
373 }
374 if (0 >= nAtoms) {
376 ed << "For material " << fName << " and added element " << elm->GetName()
377 << " with Natoms=" << nAtoms << " problem: number of atoms should be above zero";
378 G4Exception("G4Material::AddElementByNumberOfAtoms()", "mat031", FatalException, ed, "");
379 }
380
381 // filling
382 G4bool isAdded = false;
383 if (! fElm->empty()) {
384 for (G4int i = 0; i < fNumberOfElements; ++i) {
385 if (elm == (*fElm)[i]) {
386 (*fAtoms)[i] += nAtoms;
387 isAdded = true;
388 break;
389 }
390 }
391 }
392 if (! isAdded) {
393 fElm->push_back(elm);
394 fAtoms->push_back(nAtoms);
395 ++fNumberOfElements;
396 }
397 ++fIdxComponent;
398
399 // is filled - complete composition of atoms
400 if (fIdxComponent == fNbComponents) {
401 theElementVector = new G4ElementVector();
402 theElementVector->reserve(fNumberOfElements);
403 fAtomsVector = new G4int[fNumberOfElements];
404 fMassFractionVector = new G4double[fNumberOfElements];
405
406 G4double Amol = 0.;
407 for (G4int i = 0; i < fNumberOfElements; ++i) {
408 theElementVector->push_back((*fElm)[i]);
409 fAtomsVector[i] = (*fAtoms)[i];
410 G4double w = fAtomsVector[i] * (*fElm)[i]->GetA();
411 Amol += w;
412 fMassFractionVector[i] = w;
413 }
414 for (G4int i = 0; i < fNumberOfElements; ++i) {
415 fMassFractionVector[i] /= Amol;
416 }
417 delete fAtoms;
418 delete fElm;
419 fMassOfMolecule = Amol / CLHEP::Avogadro;
420 ComputeDerivedQuantities();
421 }
422}
423
424//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
425
427{
428 // perform checks consistency
429 if (fraction < 0.0 || fraction > 1.0) {
431 ed << "For material " << fName << " and added element " << elm->GetName()
432 << " massFraction= " << fraction << " is wrong ";
433 G4Exception("G4Material::AddElementByMassFraction()", "mat031", FatalException, ed, "");
434 }
435 if (! fMassFraction) {
437 ed << "For material " << fName << " and added element " << elm->GetName()
438 << ", massFraction= " << fraction << ", fIdxComponent=" << fIdxComponent
439 << " problem: cannot add by mass fraction after "
440 << "addition of elements by number of atoms";
441 G4Exception("G4Material::AddElementByMassFraction()", "mat031", FatalException, ed, "");
442 }
443 if (fIdxComponent >= fNbComponents) {
445 ed << "For material " << fName << " and added element " << elm->GetName()
446 << ", massFraction= " << fraction << ", fIdxComponent=" << fIdxComponent
447 << "; attempt to add more than the declared number of components " << fIdxComponent
448 << " >= " << fNbComponents;
449 G4Exception("G4Material::AddElementByMassFraction()", "mat031", FatalException, ed, "");
450 }
451 if (0 == fIdxComponent) {
452 fElmFrac = new std::vector<G4double>;
453 fElm = new std::vector<const G4Element*>;
454 }
455
456 // filling
457 G4bool isAdded = false;
458 if (! fElm->empty()) {
459 for (G4int i = 0; i < fNumberOfElements; ++i) {
460 if (elm == (*fElm)[i]) {
461 (*fElmFrac)[i] += fraction;
462 isAdded = true;
463 break;
464 }
465 }
466 }
467 if (! isAdded) {
468 fElm->push_back(elm);
469 fElmFrac->push_back(fraction);
470 ++fNumberOfElements;
471 }
472 ++fIdxComponent;
473
474 // is filled
475 if (fIdxComponent == fNbComponents) {
476 FillVectors();
477 }
478}
479
480//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
481
482// composition by fraction of mass
484{
485 if (fraction < 0.0 || fraction > 1.0) {
487 ed << "For material " << fName << " and added material " << material->GetName()
488 << ", massFraction= " << fraction << " is wrong ";
489 G4Exception("G4Material::AddMaterial()", "mat031", FatalException, ed, "");
490 }
491 if (! fMassFraction) {
493 ed << "For material " << fName << " and added material " << material->GetName()
494 << ", massFraction= " << fraction << ", fIdxComponent=" << fIdxComponent
495 << " problem: cannot add by mass fraction after "
496 << "addition of elements by number of atoms";
497 G4Exception("G4Material::AddMaterial()", "mat031", FatalException, ed, "");
498 }
499 if (fIdxComponent >= fNbComponents) {
501 ed << "For material " << fName << " and added material " << material->GetName()
502 << ", massFraction= " << fraction
503 << "; attempt to add more than the declared number of components " << fIdxComponent
504 << " >= " << fNbComponents;
505 G4Exception("G4Material::AddMaterial()", "mat031", FatalException, ed, "");
506 }
507 if (0 == fIdxComponent) {
508 fElmFrac = new std::vector<G4double>;
509 fElm = new std::vector<const G4Element*>;
510 }
511
512 // filling
513 auto nelm = (G4int)material->GetNumberOfElements();
514 for (G4int j = 0; j < nelm; ++j) {
515 auto elm = material->GetElement(j);
516 auto frac = material->GetFractionVector();
517 G4bool isAdded = false;
518 if (! fElm->empty()) {
519 for (G4int i = 0; i < fNumberOfElements; ++i) {
520 if (elm == (*fElm)[i]) {
521 (*fElmFrac)[i] += fraction * frac[j];
522 isAdded = true;
523 break;
524 }
525 }
526 }
527 if (! isAdded) {
528 fElm->push_back(elm);
529 fElmFrac->push_back(fraction * frac[j]);
530 ++fNumberOfElements;
531 }
532 }
533
534 fMatComponents[material] = fraction;
535 ++fIdxComponent;
536
537 // is filled
538 if (fIdxComponent == fNbComponents) {
539 FillVectors();
540 }
541}
542
543//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
544
545void G4Material::FillVectors()
546{
547 // there are material components
548 theElementVector = new G4ElementVector();
549 theElementVector->reserve(fNumberOfElements);
550 fAtomsVector = new G4int[fNumberOfElements];
551 fMassFractionVector = new G4double[fNumberOfElements];
552
553 G4double wtSum(0.0);
554 for (G4int i = 0; i < fNumberOfElements; ++i) {
555 theElementVector->push_back((*fElm)[i]);
556 fMassFractionVector[i] = (*fElmFrac)[i];
557 wtSum += fMassFractionVector[i];
558 }
559 delete fElmFrac;
560 delete fElm;
561
562 // check sum of weights -- OK?
563 if (std::abs(1. - wtSum) > perThousand) {
565 ed << "For material " << fName << " sum of fractional masses " << wtSum
566 << " is not 1 - results may be wrong";
567 G4Exception("G4Material::FillVectors()", "mat031", JustWarning, ed, "");
568 }
569 G4double coeff = (wtSum > 0.0) ? 1. / wtSum : 1.0;
570 G4double Amol(0.);
571 for (G4int i = 0; i < fNumberOfElements; ++i) {
572 fMassFractionVector[i] *= coeff;
573 Amol += fMassFractionVector[i] * (*theElementVector)[i]->GetA();
574 }
575 for (G4int i = 0; i < fNumberOfElements; ++i) {
576 fAtomsVector[i] = G4lrint(fMassFractionVector[i] * Amol / (*theElementVector)[i]->GetA());
577 }
578 ComputeDerivedQuantities();
579}
580
581//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
582
583void G4Material::ComputeRadiationLength()
584{
585 G4double radinv = 0.0;
586 for (G4int i = 0; i < fNumberOfElements; ++i) {
587 radinv += fVecNbOfAtomsPerVolume[i] * ((*theElementVector)[i]->GetfRadTsai());
588 }
589 fRadlen = (radinv <= 0.0 ? DBL_MAX : 1. / radinv);
590}
591
592//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
593
594void G4Material::ComputeNuclearInterLength()
595{
596 const G4double lambda0 = 35 * CLHEP::g / CLHEP::cm2;
597 const G4double twothird = 2.0 / 3.0;
598 G4double NILinv = 0.0;
599 for (G4int i = 0; i < fNumberOfElements; ++i) {
600 G4int Z = (*theElementVector)[i]->GetZasInt();
601 G4double A = (*theElementVector)[i]->GetN();
602 if (1 == Z) {
603 NILinv += fVecNbOfAtomsPerVolume[i] * A;
604 }
605 else {
606 NILinv += fVecNbOfAtomsPerVolume[i] * G4Exp(twothird * G4Log(A));
607 }
608 }
609 NILinv *= amu / lambda0;
610 fNuclInterLen = (NILinv <= 0.0 ? DBL_MAX : 1. / NILinv);
611}
612
613//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
614
616{
617 if (! IsLocked()) {
618 fChemicalFormula = chF;
619 }
620}
621
622//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
623
625{
626 if (val >= 0. && ! IsLocked()) {
627 fFreeElecDensity = val;
628 }
629}
630
631//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
632
634{
635 if (! IsLocked()) {
636 if (nullptr == fIonisation) {
637 fIonisation = new G4IonisParamMat(this);
638 }
639 fIonisation->ComputeDensityEffectOnFly(val);
640 }
641}
642
643//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
644
645G4MaterialTable* G4Material::GetMaterialTable() { return &theMaterialTable; }
646
647//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
648
649std::size_t G4Material::GetNumberOfMaterials() { return theMaterialTable.size(); }
650
651//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
652
654{
655 // search the material by its name
656 for (auto const & j : theMaterialTable) {
657 if (j->GetName() == materialName) {
658 return j;
659 }
660 }
661
662 // the material does not exist in the table
663 if (warn) {
664 G4cout << "G4Material::GetMaterial() WARNING: The material: " << materialName
665 << " does not exist in the table. Return NULL pointer." << G4endl;
666 }
667 return nullptr;
668}
669
670//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
671
673{
674 // search the material by its name
675 for (auto const & mat : theMaterialTable) {
676 if (1 == mat->GetNumberOfElements() && z == mat->GetZ() && a == mat->GetA() &&
677 dens == mat->GetDensity())
678 {
679 return mat;
680 }
681 }
682 return nullptr;
683}
684
685//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
686
688{
689 // search the material by its name
690 for (auto const & mat : theMaterialTable) {
691 if (nComp == mat->GetNumberOfElements() && dens == mat->GetDensity()) {
692 return mat;
693 }
694 }
695 return nullptr;
696}
697
698//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
699
701{
702 if (fNumberOfElements > 1) {
704 ed << "For material " << fName << " ERROR in GetZ() - Nelm=" << fNumberOfElements
705 << " > 1, which is not allowed";
706 G4Exception("G4Material::GetZ()", "mat036", FatalException, ed, "");
707 }
708 return (*theElementVector)[0]->GetZ();
709}
710
711//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
712
714{
715 if (fNumberOfElements > 1) {
717 ed << "For material " << fName << " ERROR in GetA() - Nelm=" << fNumberOfElements
718 << " > 1, which is not allowed";
719 G4Exception("G4Material::GetA()", "mat036", FatalException, ed, "");
720 }
721 return (*theElementVector)[0]->GetA();
722}
723
724//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
725
726std::ostream& operator<<(std::ostream& flux, const G4Material* material)
727{
728 std::ios::fmtflags mode = flux.flags();
729 flux.setf(std::ios::fixed, std::ios::floatfield);
730 G4long prec = flux.precision(3);
731
732 flux << " Material: " << std::setw(8) << material->fName << " " << material->fChemicalFormula
733 << " "
734 << " density: " << std::setw(6) << std::setprecision(3)
735 << G4BestUnit(material->fDensity, "Volumic Mass") << " RadL: " << std::setw(7)
736 << std::setprecision(3) << G4BestUnit(material->fRadlen, "Length")
737 << " Nucl.Int.Length: " << std::setw(7) << std::setprecision(3)
738 << G4BestUnit(material->fNuclInterLen, "Length") << "\n"
739 << std::setw(30) << " Imean: " << std::setw(7) << std::setprecision(3)
740 << G4BestUnit(material->GetIonisation()->GetMeanExcitationEnergy(), "Energy")
741 << " temperature: " << std::setw(6) << std::setprecision(2)
742 << (material->fTemp) / CLHEP::kelvin << " K"
743 << " pressure: " << std::setw(6) << std::setprecision(2)
744 << (material->fPressure) / CLHEP::atmosphere << " atm"
745 << "\n";
746
747 for (G4int i = 0; i < material->fNumberOfElements; i++) {
748 flux << "\n ---> " << (*(material->theElementVector))[i]
749 << "\n ElmMassFraction: " << std::setw(6) << std::setprecision(2)
750 << (material->fMassFractionVector[i]) / perCent << " %"
751 << " ElmAbundance " << std::setw(6) << std::setprecision(2)
752 << 100 * (material->fVecNbOfAtomsPerVolume[i]) / (material->fTotNbOfAtomsPerVolume)
753 << " % \n";
754 }
755 flux.precision(prec);
756 flux.setf(mode, std::ios::floatfield);
757
758 if (material->IsExtended()) {
759 static_cast<const G4ExtendedMaterial*>(material)->Print(flux);
760 }
761
762 return flux;
763}
764
765//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
766
767std::ostream& operator<<(std::ostream& flux, const G4Material& material)
768{
769 flux << &material;
770 return flux;
771}
772
773//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
774
775std::ostream& operator<<(std::ostream& flux, const G4MaterialTable& MaterialTable)
776{
777 // Dump info for all known materials
778 flux << "\n***** Table : Nb of materials = " << MaterialTable.size() << " *****\n" << G4endl;
779
780 for (auto i : MaterialTable) {
781 flux << i << G4endl << G4endl;
782 }
783
784 return flux;
785}
786
787//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
788
789G4bool G4Material::IsExtended() const { return false; }
790
791//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
792
794{
795 if (fMaterialPropertiesTable != anMPT && ! IsLocked()) {
796 delete fMaterialPropertiesTable;
797 fMaterialPropertiesTable = anMPT;
798 }
799}
800
801//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
802
803G4bool G4Material::IsLocked()
804{
806 return state != G4State_PreInit && state != G4State_Init && state != G4State_Idle;
807}
@ G4State_Init
@ G4State_Idle
@ G4State_PreInit
std::vector< const G4Element * > G4ElementVector
@ JustWarning
@ FatalException
void G4Exception(const char *originOfException, const char *exceptionCode, G4ExceptionSeverity severity, const char *description)
std::ostringstream G4ExceptionDescription
G4double G4Exp(G4double initial_x)
Exponential Function double precision.
Definition G4Exp.hh:180
G4double G4Log(G4double x)
Definition G4Log.hh:227
std::vector< G4Material * > G4MaterialTable
std::ostream & operator<<(std::ostream &flux, const G4Material *material)
G4State
@ kStateSolid
@ kStateGas
@ kStateUndefined
#define G4BestUnit(a, b)
double G4double
Definition G4Types.hh:83
long G4long
Definition G4Types.hh:87
bool G4bool
Definition G4Types.hh:86
int G4int
Definition G4Types.hh:85
const G4double A[17]
#define G4endl
Definition G4ios.hh:67
G4GLOB_DLL std::ostream G4cout
static G4int GetNumberOfFreeElectrons(G4int Z, G4double th)
const G4String & GetName() const
Definition G4Element.hh:115
G4DensityEffectCalculator * GetDensityEffectCalculator() const
G4double GetMeanExcitationEnergy() const
void ComputeDensityEffectOnFly(G4bool)
void SetMeanExcitationEnergy(G4double value)
G4double GetDensity() const
void ComputeDensityEffectOnFly(G4bool val)
const G4String & GetChemicalFormula() const
const G4ElementVector * GetElementVector() const
G4MaterialPropertiesTable * GetMaterialPropertiesTable() const
G4double GetTotNbOfAtomsPerVolume() const
G4State GetState() const
const G4Element * GetElement(G4int iel) const
virtual G4bool IsExtended() const
G4double GetZ() const
const G4double * GetFractionVector() const
G4double GetTotNbOfElectPerVolume() const
G4IonisParamMat * GetIonisation() const
G4double GetFreeElectronDensity() const
virtual ~G4Material()
void SetChemicalFormula(const G4String &chF)
const G4int * GetAtomsVector() const
G4double GetA() const
G4SandiaTable * GetSandiaTable() const
void AddElementByNumberOfAtoms(const G4Element *elm, G4int nAtoms)
static std::size_t GetNumberOfMaterials()
G4double GetRadlen() const
G4double GetMassOfMolecule() const
const G4double * GetVecNbOfAtomsPerVolume() const
G4Material(const G4String &name, G4double z, G4double a, G4double density, G4State state=kStateUndefined, G4double temp=NTP_Temperature, G4double pressure=CLHEP::STP_Pressure)
Definition G4Material.cc:88
static G4MaterialTable * GetMaterialTable()
void AddMaterial(G4Material *material, G4double fraction)
std::size_t GetNumberOfElements() const
const G4String & GetName() const
void SetMaterialPropertiesTable(G4MaterialPropertiesTable *anMPT)
void SetFreeElectronDensity(G4double val)
void AddElementByMassFraction(const G4Element *elm, G4double fraction)
static G4Material * GetMaterial(const G4String &name, G4bool warning=true)
G4double GetNuclearInterLength() const
static G4NistManager * Instance()
G4Element * FindOrBuildElement(G4int Z, G4bool isotopes=true)
const G4ApplicationState & GetCurrentState() const
static G4StateManager * GetStateManager()
int G4lrint(double ad)
Definition templates.hh:134
#define DBL_MAX
Definition templates.hh:62