96 G4cout <<
" G4Material WARNING:"
97 <<
" define a material with density=0 is not allowed. \n"
98 <<
" The material " << name <<
" will be constructed with the"
107 fPressure = pressure;
111 maxNbComponents = fNumberOfComponents = fNumberOfElements = 1;
112 fArrayLength = maxNbComponents;
113 fImplicitElement =
true;
115 theElementVector->push_back(
new G4Element(name,
" ", z, a));
116 fMassFractionVector =
new G4double[1];
117 fMassFractionVector[0] = 1. ;
126 ComputeDerivedQuantities();
139 InitializePointers();
143 G4cout <<
"--- Warning from G4Material::G4Material()"
144 <<
" define a material with density=0 is not allowed. \n"
145 <<
" The material " << name <<
" will be constructed with the"
154 fPressure = pressure;
157 fArrayLength = maxNbComponents;
158 fNumberOfComponents = fNumberOfElements = 0;
160 theElementVector->reserve(maxNbComponents);
178 InitializePointers();
182 G4cout <<
"--- Warning from G4Material::G4Material()"
183 <<
" define a material with density=0 is not allowed. \n"
184 <<
" The material " << name <<
" will be constructed with the"
193 fPressure = pressure;
195 fBaseMaterial = bmat;
200 maxNbComponents = fNumberOfElements;
201 fNumberOfComponents = fNumberOfElements;
205 CopyPointersOfBaseMaterial();
214 : fNumberOfComponents(0), fNumberOfElements(0), theElementVector(0),
215 fImplicitElement(false), fMassFractionVector(0), fAtomsVector(0),
216 fMaterialPropertiesTable(0), fIndexInTable(0),
217 VecNbOfAtomsPerVolume(0)
219 InitializePointers();
228 if (theElementVector) {
delete theElementVector; }
229 if (fMassFractionVector) {
delete [] fMassFractionVector; }
230 if (fAtomsVector) {
delete [] fAtomsVector; }
231 if (fSandiaTable) {
delete fSandiaTable; }
233 if (fIonisation) {
delete fIonisation; }
234 if (VecNbOfAtomsPerVolume) {
delete [] VecNbOfAtomsPerVolume; }
238 theMaterialTable[fIndexInTable] = 0;
243 void G4Material::InitializePointers()
245 theElementVector = 0;
246 fMassFractionVector = 0;
248 fMaterialPropertiesTable = 0;
250 VecNbOfAtomsPerVolume = 0;
253 fImplicitElement =
false;
254 fChemicalFormula =
"";
263 TotNbOfAtomsPerVolume = 0;
264 TotNbOfElectPerVolume = 0;
267 fMassOfMolecule = 0.0;
273 fIndexInTable = theMaterialTable.size();
274 for(
size_t i=0; i<fIndexInTable; ++i) {
275 if(theMaterialTable[i]->
GetName() == fName) {
276 G4cout <<
"G4Material WARNING: doublicate name of the new material "
281 theMaterialTable.push_back(
this);
286 void G4Material::ComputeDerivedQuantities()
293 TotNbOfAtomsPerVolume = 0.;
294 if (VecNbOfAtomsPerVolume) {
delete [] VecNbOfAtomsPerVolume; }
295 VecNbOfAtomsPerVolume =
new G4double[fNumberOfElements];
296 TotNbOfElectPerVolume = 0.;
297 for (
size_t i=0; i<fNumberOfElements; ++i) {
298 Zi = (*theElementVector)[i]->GetZ();
299 Ai = (*theElementVector)[i]->GetA();
300 VecNbOfAtomsPerVolume[i] =
Avogadro*fDensity*fMassFractionVector[i]/Ai;
301 TotNbOfAtomsPerVolume += VecNbOfAtomsPerVolume[i];
302 TotNbOfElectPerVolume += VecNbOfAtomsPerVolume[i]*Zi;
305 ComputeRadiationLength();
306 ComputeNuclearInterLength();
308 if (fIonisation) {
delete fIonisation; }
310 if (fSandiaTable) {
delete fSandiaTable; }
316 void G4Material::CopyPointersOfBaseMaterial()
327 if (VecNbOfAtomsPerVolume) {
delete [] VecNbOfAtomsPerVolume; }
328 VecNbOfAtomsPerVolume =
new G4double[fNumberOfElements];
329 for (
size_t i=0; i<fNumberOfElements; ++i) {
330 VecNbOfAtomsPerVolume[i] = factor*v[i];
332 fRadlen = fBaseMaterial->
GetRadlen()/factor;
334 if (fIonisation) {
delete fIonisation; }
348 if ( fNumberOfElements == 0 ) {
349 fAtomsVector =
new G4int [fArrayLength];
350 fMassFractionVector =
new G4double[fArrayLength];
354 if (
G4int(fNumberOfElements) < maxNbComponents ) {
355 theElementVector->push_back(element);
356 fAtomsVector[fNumberOfElements] = nAtoms;
357 fNumberOfComponents = ++fNumberOfElements;
359 G4cout <<
"G4Material::AddElement ERROR for " << fName <<
" nElement= "
360 << fNumberOfElements <<
G4endl;
362 "Attempt to add more than the declared number of elements.");
365 if (
G4int(fNumberOfElements) == maxNbComponents ) {
369 for (i=0; i<fNumberOfElements; ++i) {
370 G4double w = fAtomsVector[i]*(*theElementVector)[i]->GetA();
372 fMassFractionVector[i] = w;
374 for (i=0; i<fNumberOfElements; ++i) {
375 fMassFractionVector[i] /= Amol;
379 ComputeDerivedQuantities();
389 if(fraction < 0.0 || fraction > 1.0) {
390 G4cout <<
"G4Material::AddElement ERROR for " << fName <<
" and "
391 << element->
GetName() <<
" mass fraction= " << fraction
392 <<
" is wrong " <<
G4endl;
394 "Attempt to add element with wrong mass fraction");
397 if (fNumberOfComponents == 0) {
398 fMassFractionVector =
new G4double[fArrayLength];
399 fAtomsVector =
new G4int [fArrayLength];
402 if (
G4int(fNumberOfComponents) < maxNbComponents) {
404 while ((el<fNumberOfElements)&&(element!=(*theElementVector)[el])) { ++el; }
405 if (el<fNumberOfElements) fMassFractionVector[el] += fraction;
407 theElementVector->push_back(element);
408 fMassFractionVector[el] = fraction;
412 ++fNumberOfComponents;
414 G4cout <<
"G4Material::AddElement ERROR for " << fName <<
" nElement= "
415 << fNumberOfElements <<
G4endl;
417 "Attempt to add more than the declared number of elements.");
421 if (
G4int(fNumberOfComponents) == maxNbComponents) {
427 for (i=0; i<fNumberOfElements; ++i) {
428 wtSum += fMassFractionVector[i];
429 Zmol += fMassFractionVector[i]*(*theElementVector)[i]->GetZ();
430 Amol += fMassFractionVector[i]*(*theElementVector)[i]->GetA();
433 G4cerr <<
"WARNING !! for " << fName <<
" sum of fractional masses "
434 << wtSum <<
" is not 1 - results may be wrong"
437 for (i=0; i<fNumberOfElements; ++i) {
439 G4lrint(fMassFractionVector[i]*Amol/(*theElementVector)[i]->
GetA());
442 ComputeDerivedQuantities();
452 if(fraction < 0.0 || fraction > 1.0) {
453 G4cout <<
"G4Material::AddMaterial ERROR for " << fName <<
" and "
454 << material->
GetName() <<
" mass fraction= " << fraction
457 "Attempt to add material with wrong mass fraction");
460 if (fNumberOfComponents == 0) {
461 fMassFractionVector =
new G4double[fArrayLength];
462 fAtomsVector =
new G4int [fArrayLength];
469 G4int nold = fArrayLength;
470 fArrayLength += nelm - 1;
473 for(
G4int i=0; i<nold; ++i) {
474 v1[i] = fMassFractionVector[i];
475 i1[i] = fAtomsVector[i];
477 delete [] fAtomsVector;
478 delete [] fMassFractionVector;
479 fMassFractionVector = v1;
484 if (
G4int(fNumberOfComponents) < maxNbComponents) {
485 for (
size_t elm=0; elm<nelm; ++elm)
489 while ((el<fNumberOfElements)&&(element!=(*theElementVector)[el])) el++;
490 if (el < fNumberOfElements) fMassFractionVector[el] += fraction
493 theElementVector->push_back(element);
494 fMassFractionVector[el] = fraction
500 ++fNumberOfComponents;
502 fMatComponents[
material] = fraction;
505 G4cout <<
"G4Material::AddMaterial ERROR for " << fName <<
" nElement= "
506 << fNumberOfElements <<
G4endl;
508 "Attempt to add more than the declared number of components.");
512 if (
G4int(fNumberOfComponents) == maxNbComponents) {
517 for (i=0; i<fNumberOfElements; ++i) {
518 wtSum += fMassFractionVector[i];
519 Zmol += fMassFractionVector[i]*(*theElementVector)[i]->GetZ();
520 Amol += fMassFractionVector[i]*(*theElementVector)[i]->GetA();
523 G4cout <<
"G4Material::AddMaterial WARNING !! for " << fName
524 <<
" sum of fractional masses "
525 << wtSum <<
" is not 1 - results may be wrong"
528 for (i=0;i<fNumberOfElements;i++) {
530 G4lrint(fMassFractionVector[i]*Amol/(*theElementVector)[i]->
GetA());
533 ComputeDerivedQuantities();
539 void G4Material::ComputeRadiationLength()
542 for (
size_t i=0;i<fNumberOfElements;++i) {
543 radinv += VecNbOfAtomsPerVolume[i]*((*theElementVector)[i]->GetfRadTsai());
545 fRadlen = (radinv <= 0.0 ?
DBL_MAX : 1./radinv);
550 void G4Material::ComputeNuclearInterLength()
554 for (
size_t i=0; i<fNumberOfElements; ++i) {
556 VecNbOfAtomsPerVolume[i]*std::pow((*theElementVector)[i]->GetN(),0.6666666667);
558 NILinv *=
amu/lambda0;
559 fNuclInterLen = (NILinv <= 0.0 ?
DBL_MAX : 1./NILinv);
566 return &theMaterialTable;
573 return theMaterialTable.size();
581 for (
size_t J=0 ; J<theMaterialTable.size() ; ++J)
583 if (theMaterialTable[J]->
GetName() == materialName)
584 {
return theMaterialTable[J]; }
589 G4cout <<
"G4Material::GetMaterial() WARNING: The material: "
590 << materialName <<
" does not exist in the table. Return NULL pointer."
600 InitializePointers();
608 if (fNumberOfElements > 1) {
609 G4cout <<
"G4Material ERROR in GetZ. The material: " << fName
612 "the Atomic number is not well defined." );
614 return (*theElementVector)[0]->GetZ();
621 if (fNumberOfElements > 1) {
622 G4cout <<
"G4Material ERROR in GetA. The material: " << fName
625 "the Atomic mass is not well defined." );
627 return (*theElementVector)[0]->GetA();
637 fChemicalFormula = right.fChemicalFormula;
638 fDensity = right.fDensity;
639 fState = right.fState;
641 fPressure = right.fPressure;
644 if (theElementVector) {
delete theElementVector; }
645 if (fMassFractionVector) {
delete [] fMassFractionVector; }
646 if (fAtomsVector) {
delete [] fAtomsVector; }
647 if (fIonisation) {
delete fIonisation; }
648 if (fSandiaTable) {
delete fSandiaTable; }
651 if (VecNbOfAtomsPerVolume) {
delete [] VecNbOfAtomsPerVolume; }
653 maxNbComponents = right.maxNbComponents;
654 fNumberOfComponents = right.fNumberOfComponents;
655 fNumberOfElements = right.fNumberOfElements;
656 fImplicitElement = right.fImplicitElement;
658 fMaterialPropertiesTable = right.fMaterialPropertiesTable;
659 fBaseMaterial = right.fBaseMaterial;
660 fMassOfMolecule= right.fMassOfMolecule;
661 fMatComponents= right.fMatComponents;
664 CopyPointersOfBaseMaterial();
668 fMassFractionVector =
new G4double[fNumberOfElements];
669 fAtomsVector =
new G4int[fNumberOfElements];
670 for (
size_t i=0; i<fNumberOfElements; ++i) {
671 (*theElementVector)[i] = (*right.theElementVector)[i];
672 fMassFractionVector[i] = right.fMassFractionVector[i];
673 fAtomsVector[i] = right.fAtomsVector[i];
675 ComputeDerivedQuantities();
699 std::ios::fmtflags mode = flux.flags();
700 flux.setf(std::ios::fixed,std::ios::floatfield);
701 G4long prec = flux.precision(3);
704 <<
" Material: " << std::setw(8) << material->fName
705 <<
" " << material->fChemicalFormula <<
" "
706 <<
" density: " << std::setw(6) << std::setprecision(3)
707 <<
G4BestUnit(material->fDensity,
"Volumic Mass")
708 <<
" RadL: " << std::setw(7) << std::setprecision(3)
710 <<
" Nucl.Int.Length: " << std::setw(7) << std::setprecision(3)
711 <<
G4BestUnit(material->fNuclInterLen,
"Length") <<
"\n" << std::setw(30)
712 <<
" Imean: " << std::setw(7) << std::setprecision(3)
717 <<
" temperature: " << std::setw(6) << std::setprecision(2)
718 << (material->fTemp)/
kelvin <<
" K"
719 <<
" pressure: " << std::setw(6) << std::setprecision(2)
720 << (material->fPressure)/
atmosphere <<
" atm";
724 for (
size_t i=0; i<material->fNumberOfElements; i++) {
726 <<
"\n ---> " << (*(material->theElementVector))[i]
727 <<
"\n ElmMassFraction: "
728 << std::setw(6)<< std::setprecision(2)
729 << (material->fMassFractionVector[i])/
perCent <<
" %"
730 <<
" ElmAbundance " << std::setw(6)<< std::setprecision(2)
731 << 100*(material->VecNbOfAtomsPerVolume[i])/(material->TotNbOfAtomsPerVolume)
734 flux.precision(prec);
735 flux.setf(mode,std::ios::floatfield);
753 flux <<
"\n***** Table : Nb of materials = " << MaterialTable.size()
756 for (
size_t i=0; i<MaterialTable.size(); ++i) {
G4IonisParamMat * GetIonisation() const
G4int operator==(const G4Material &) const
G4double GetTotNbOfElectPerVolume() const
std::vector< G4Element * > G4ElementVector
void AddMaterial(G4Material *material, G4double fraction)
static G4Material * GetMaterial(const G4String &name, G4bool warning=true)
int universe_mean_density
const G4String & GetChemicalFormula() const
void SetMeanExcitationEnergy(G4double value)
const G4String & GetName() const
static G4MaterialTable * GetMaterialTable()
std::vector< G4Material * > G4MaterialTable
G4double GetDensity() const
#define G4BestUnit(a, b)
#define G4_USE_G4BESTUNIT_FOR_VERBOSE 1
const G4ElementVector * GetElementVector() const
G4Material(const G4String &name, G4double z, G4double a, G4double density, G4State state=kStateUndefined, G4double temp=CLHEP::STP_Temperature, G4double pressure=CLHEP::STP_Pressure)
G4SandiaTable * GetSandiaTable() const
const G4double * GetVecNbOfAtomsPerVolume() const
G4GLOB_DLL std::ostream G4cout
static size_t GetNumberOfMaterials()
G4double GetRadlen() const
void G4Exception(const char *originOfException, const char *exceptionCode, G4ExceptionSeverity severity, const char *comments)
G4double GetTotNbOfAtomsPerVolume() const
G4int operator!=(const G4Material &) const
G4MaterialPropertiesTable * GetMaterialPropertiesTable() const
G4double GetMassOfMolecule() const
std::ostream & operator<<(std::ostream &, const BasicVector3D< float > &)
const G4int * GetAtomsVector() const
G4double GetMeanExcitationEnergy() const
void AddElement(G4Element *element, G4int nAtoms)
size_t GetNumberOfElements() const
const G4String & GetName() const
const G4double * GetFractionVector() const
G4double GetNuclearInterLength() const
G4GLOB_DLL std::ostream G4cerr