99 G4cout <<
" G4Material WARNING:"
100 <<
" define a material with density=0 is not allowed. \n"
101 <<
" The material " << name <<
" will be constructed with the"
110 fPressure = pressure;
114 maxNbComponents = fNumberOfComponents = fNumberOfElements = 1;
115 fArrayLength = maxNbComponents;
118 const std::vector<G4String> elmnames =
122 if(iz < (
G4int)elmnames.size()) {
126 enam =
"ELM_" +
name;
129 theElementVector->push_back(
new G4Element(enam, snam, z, a));
131 fMassFractionVector =
new G4double[1];
132 fMassFractionVector[0] = 1. ;
141 ComputeDerivedQuantities();
154 InitializePointers();
158 G4cout <<
"--- Warning from G4Material::G4Material()"
159 <<
" define a material with density=0 is not allowed. \n"
160 <<
" The material " << name <<
" will be constructed with the"
169 fPressure = pressure;
171 maxNbComponents = nComponents;
172 fArrayLength = maxNbComponents;
173 fNumberOfComponents = fNumberOfElements = 0;
175 theElementVector->reserve(maxNbComponents);
193 InitializePointers();
197 G4cout <<
"--- Warning from G4Material::G4Material()"
198 <<
" define a material with density=0 is not allowed. \n"
199 <<
" The material " << name <<
" will be constructed with the"
208 fPressure = pressure;
210 fBaseMaterial = bmat;
215 maxNbComponents = fNumberOfElements;
216 fNumberOfComponents = fNumberOfElements;
218 CopyPointersOfBaseMaterial();
229 InitializePointers();
237 if(fBaseMaterial ==
nullptr) {
238 delete theElementVector;
241 if(fMassFractionVector) {
delete [] fMassFractionVector; }
242 if(fAtomsVector) {
delete [] fAtomsVector; }
245 if(VecNbOfAtomsPerVolume) {
delete [] VecNbOfAtomsPerVolume; }
249 theMaterialTable[fIndexInTable] =
nullptr;
254 void G4Material::InitializePointers()
256 theElementVector =
nullptr;
257 fMassFractionVector =
nullptr;
258 fAtomsVector =
nullptr;
259 fMaterialPropertiesTable =
nullptr;
261 VecNbOfAtomsPerVolume =
nullptr;
262 fBaseMaterial =
nullptr;
264 fChemicalFormula =
"";
273 fNumberOfComponents = 0;
274 fNumberOfElements = 0;
275 TotNbOfAtomsPerVolume = 0.0;
276 TotNbOfElectPerVolume = 0.0;
279 fMassOfMolecule = 0.0;
281 fIonisation =
nullptr;
282 fSandiaTable =
nullptr;
285 fIndexInTable = theMaterialTable.size();
286 for(
size_t i=0; i<fIndexInTable; ++i) {
287 if(theMaterialTable[i]->
GetName() == fName) {
288 G4cout <<
"G4Material WARNING: duplicate name of material "
293 theMaterialTable.push_back(
this);
298 void G4Material::ComputeDerivedQuantities()
305 TotNbOfAtomsPerVolume = 0.;
306 if (VecNbOfAtomsPerVolume) {
delete [] VecNbOfAtomsPerVolume; }
307 VecNbOfAtomsPerVolume =
new G4double[fNumberOfElements];
308 TotNbOfElectPerVolume = 0.;
309 for (
G4int i=0; i<fNumberOfElements; ++i) {
310 Zi = (*theElementVector)[i]->GetZ();
311 Ai = (*theElementVector)[i]->GetA();
312 VecNbOfAtomsPerVolume[i] =
Avogadro*fDensity*fMassFractionVector[i]/Ai;
313 TotNbOfAtomsPerVolume += VecNbOfAtomsPerVolume[i];
314 TotNbOfElectPerVolume += VecNbOfAtomsPerVolume[i]*Zi;
317 ComputeRadiationLength();
318 ComputeNuclearInterLength();
320 if (fIonisation) {
delete fIonisation; }
322 if (fSandiaTable) {
delete fSandiaTable; }
328 void G4Material::CopyPointersOfBaseMaterial()
336 fMassFractionVector =
341 if (VecNbOfAtomsPerVolume) {
delete [] VecNbOfAtomsPerVolume; }
342 VecNbOfAtomsPerVolume =
new G4double[fNumberOfElements];
343 for (
G4int i=0; i<fNumberOfElements; ++i) {
344 VecNbOfAtomsPerVolume[i] = factor*v[i];
346 fRadlen = fBaseMaterial->
GetRadlen()/factor;
349 if (fIonisation) {
delete fIonisation; }
365 if ( fNumberOfElements == 0 ) {
366 fAtomsVector =
new G4int [fArrayLength];
367 fMassFractionVector =
new G4double[fArrayLength];
371 if ( fNumberOfElements < maxNbComponents ) {
372 theElementVector->push_back(element);
373 fAtomsVector[fNumberOfElements] = nAtoms;
374 fNumberOfComponents = ++fNumberOfElements;
376 G4cout <<
"G4Material::AddElement ERROR for " << fName <<
" nElement= "
377 << fNumberOfElements <<
G4endl;
379 "Attempt to add more than the declared number of elements.");
382 if ( fNumberOfElements == maxNbComponents ) {
386 for (i=0; i<fNumberOfElements; ++i) {
387 G4double w = fAtomsVector[i]*(*theElementVector)[i]->GetA();
389 fMassFractionVector[i] = w;
391 for (i=0; i<fNumberOfElements; ++i) {
392 fMassFractionVector[i] /= Amol;
396 ComputeDerivedQuantities();
406 if(fraction < 0.0 || fraction > 1.0) {
407 G4cout <<
"G4Material::AddElement ERROR for " << fName <<
" and "
408 << element->
GetName() <<
" mass fraction= " << fraction
409 <<
" is wrong " <<
G4endl;
411 "Attempt to add element with wrong mass fraction");
414 if (fNumberOfComponents == 0) {
415 fMassFractionVector =
new G4double[fArrayLength];
416 fAtomsVector =
new G4int [fArrayLength];
419 if (fNumberOfComponents < maxNbComponents) {
422 while ((el<fNumberOfElements)&&(element!=(*theElementVector)[el])) { ++el; }
423 if (el<fNumberOfElements) fMassFractionVector[el] += fraction;
425 theElementVector->push_back(element);
426 fMassFractionVector[el] = fraction;
429 ++fNumberOfComponents;
431 G4cout <<
"G4Material::AddElement ERROR for " << fName <<
" nElement= "
432 << fNumberOfElements <<
G4endl;
434 "Attempt to add more than the declared number of elements.");
438 if (fNumberOfComponents == maxNbComponents) {
444 for (i=0; i<fNumberOfElements; ++i) {
445 wtSum += fMassFractionVector[i];
446 Zmol += fMassFractionVector[i]*(*theElementVector)[i]->GetZ();
447 Amol += fMassFractionVector[i]*(*theElementVector)[i]->GetA();
450 G4cerr <<
"WARNING !! for " << fName <<
" sum of fractional masses "
451 << wtSum <<
" is not 1 - results may be wrong"
454 for (i=0; i<fNumberOfElements; ++i) {
456 G4lrint(fMassFractionVector[i]*Amol/(*theElementVector)[i]->
GetA());
459 ComputeDerivedQuantities();
469 if(fraction < 0.0 || fraction > 1.0) {
470 G4cout <<
"G4Material::AddMaterial ERROR for " << fName <<
" and "
471 << material->
GetName() <<
" mass fraction= " << fraction
474 "Attempt to add material with wrong mass fraction");
477 if (fNumberOfComponents == 0) {
478 fMassFractionVector =
new G4double[fArrayLength];
479 fAtomsVector =
new G4int [fArrayLength];
486 G4int nold = fArrayLength;
487 fArrayLength += nelm - 1;
490 for(
G4int i=0; i<nold; ++i) {
491 v1[i] = fMassFractionVector[i];
492 i1[i] = fAtomsVector[i];
494 delete [] fAtomsVector;
495 delete [] fMassFractionVector;
496 fMassFractionVector = v1;
501 if (fNumberOfComponents < maxNbComponents) {
502 for (
G4int elm=0; elm<nelm; ++elm)
507 while ((el<fNumberOfElements)&&(element!=(*theElementVector)[el])) el++;
508 if (el < fNumberOfElements) fMassFractionVector[el] += fraction
511 theElementVector->push_back(element);
512 fMassFractionVector[el] = fraction
517 ++fNumberOfComponents;
519 fMatComponents[material] = fraction;
522 G4cout <<
"G4Material::AddMaterial ERROR for " << fName <<
" nElement= "
523 << fNumberOfElements <<
G4endl;
525 "Attempt to add more than the declared number of components.");
529 if (fNumberOfComponents == maxNbComponents) {
534 for (i=0; i<fNumberOfElements; ++i) {
535 wtSum += fMassFractionVector[i];
536 Zmol += fMassFractionVector[i]*(*theElementVector)[i]->GetZ();
537 Amol += fMassFractionVector[i]*(*theElementVector)[i]->GetA();
540 G4cout <<
"G4Material::AddMaterial WARNING !! for " << fName
541 <<
" sum of fractional masses "
542 << wtSum <<
" is not 1 - results may be wrong"
545 for (i=0; i<fNumberOfElements; ++i) {
547 G4lrint(fMassFractionVector[i]*Amol/(*theElementVector)[i]->
GetA());
550 ComputeDerivedQuantities();
556 void G4Material::ComputeRadiationLength()
559 for (
G4int i=0;i<fNumberOfElements;++i) {
560 radinv += VecNbOfAtomsPerVolume[i]*((*theElementVector)[i]->GetfRadTsai());
562 fRadlen = (radinv <= 0.0 ?
DBL_MAX : 1./radinv);
567 void G4Material::ComputeNuclearInterLength()
570 static const G4double twothird = 2.0/3.0;
572 for (
G4int i=0; i<fNumberOfElements; ++i) {
574 G4double A = (*theElementVector)[i]->GetN();
576 NILinv += VecNbOfAtomsPerVolume[i]*
A;
578 NILinv += VecNbOfAtomsPerVolume[i]*
G4Exp(twothird*
G4Log(A));
581 NILinv *=
amu/lambda0;
582 fNuclInterLen = (NILinv <= 0.0 ?
DBL_MAX : 1./NILinv);
589 return &theMaterialTable;
596 return theMaterialTable.size();
605 for (
size_t J=0 ; J<theMaterialTable.size() ; ++J)
607 if (theMaterialTable[J]->
GetName() == materialName)
608 {
return theMaterialTable[J]; }
613 G4cout <<
"G4Material::GetMaterial() WARNING: The material: "
615 <<
" does not exist in the table. Return NULL pointer."
625 if (fNumberOfElements > 1) {
626 G4cout <<
"G4Material ERROR in GetZ. The material: " << fName
629 "the Atomic number is not well defined." );
631 return (*theElementVector)[0]->GetZ();
638 if (fNumberOfElements > 1) {
639 G4cout <<
"G4Material ERROR in GetA. The material: " << fName
642 "the Atomic mass is not well defined." );
644 return (*theElementVector)[0]->GetA();
652 std::ios::fmtflags mode = flux.flags();
653 flux.setf(std::ios::fixed,std::ios::floatfield);
657 <<
" Material: " << std::setw(8) << material->fName
658 <<
" " << material->fChemicalFormula <<
" "
659 <<
" density: " << std::setw(6) << std::setprecision(3)
660 <<
G4BestUnit(material->fDensity,
"Volumic Mass")
661 <<
" RadL: " << std::setw(7) << std::setprecision(3)
663 <<
" Nucl.Int.Length: " << std::setw(7) << std::setprecision(3)
664 <<
G4BestUnit(material->fNuclInterLen,
"Length")
665 <<
"\n" << std::setw(30)
666 <<
" Imean: " << std::setw(7) << std::setprecision(3)
672 <<
" temperature: " << std::setw(6) << std::setprecision(2)
673 << (material->fTemp)/
kelvin <<
" K"
674 <<
" pressure: " << std::setw(6) << std::setprecision(2)
675 << (material->fPressure)/
atmosphere <<
" atm";
679 for (
G4int i=0; i<material->fNumberOfElements; i++) {
681 <<
"\n ---> " << (*(material->theElementVector))[i]
682 <<
"\n ElmMassFraction: "
683 << std::setw(6)<< std::setprecision(2)
684 << (material->fMassFractionVector[i])/
perCent <<
" %"
685 <<
" ElmAbundance " << std::setw(6)<< std::setprecision(2)
686 << 100*(material->VecNbOfAtomsPerVolume[i])
687 /(material->TotNbOfAtomsPerVolume)
690 flux.precision(prec);
691 flux.setf(mode,std::ios::floatfield);
712 flux <<
"\n***** Table : Nb of materials = " << MaterialTable.size()
715 for (
size_t i=0; i<MaterialTable.size(); ++i) {
static constexpr double kGasThreshold
G4IonisParamMat * GetIonisation() const
G4double GetTotNbOfElectPerVolume() const
std::vector< G4Element * > G4ElementVector
static constexpr double cm2
void AddMaterial(G4Material *material, G4double fraction)
static G4Material * GetMaterial(const G4String &name, G4bool warning=true)
const G4String & GetChemicalFormula() const
void SetMeanExcitationEnergy(G4double value)
static constexpr double perCent
const G4String & GetName() const
const std::vector< G4String > & GetNistElementNames() const
static G4MaterialTable * GetMaterialTable()
std::vector< G4Material * > G4MaterialTable
G4double GetDensity() const
#define G4BestUnit(a, b)
#define G4_USE_G4BESTUNIT_FOR_VERBOSE 1
static constexpr double g
const G4ElementVector * GetElementVector() const
static constexpr double Avogadro
static G4NistManager * Instance()
static constexpr double g
G4SandiaTable * GetSandiaTable() const
virtual G4bool IsExtended() const
const G4double * GetVecNbOfAtomsPerVolume() const
G4GLOB_DLL std::ostream G4cout
double A(double temperature)
static constexpr double amu
static size_t GetNumberOfMaterials()
static constexpr double kelvin
G4double GetRadlen() const
static constexpr double cm3
G4Material(const G4String &name, G4double z, G4double a, G4double density, G4State state=kStateUndefined, G4double temp=NTP_Temperature, G4double pressure=CLHEP::STP_Pressure)
void G4Exception(const char *originOfException, const char *exceptionCode, G4ExceptionSeverity severity, const char *comments)
G4double G4Log(G4double x)
G4double G4Exp(G4double initial_x)
Exponential Function double precision.
G4double GetTotNbOfAtomsPerVolume() const
G4MaterialPropertiesTable * GetMaterialPropertiesTable() const
G4double GetMassOfMolecule() const
std::ostream & operator<<(std::ostream &, const BasicVector3D< float > &)
const G4int * GetAtomsVector() const
static constexpr double universe_mean_density
G4double GetMeanExcitationEnergy() const
void AddElement(G4Element *element, G4int nAtoms)
size_t GetNumberOfElements() const
static constexpr double perThousand
const G4String & GetName() const
const G4double * GetFractionVector() const
static constexpr double atmosphere
G4double GetNuclearInterLength() const
G4GLOB_DLL std::ostream G4cerr