Import Geant4 11.0.0 source tree

This commit is contained in:
Gabriele Cosmo
2021-12-10 14:46:44 +01:00
committed by Ben Morgan
parent 6399a014b6
commit 80e2389dd8
3932 changed files with 202519 additions and 246221 deletions
+74
View File
@@ -16,6 +16,80 @@ committal in the CVS repository !
* Reverse chronological order (last date on top), please *
----------------------------------------------------------
10-11-21 V.Ivanchenko (materials-V10-07-26)
- G4Material - revised and updated all G4Exceptions, provided complete
information for all exceptions, text become more precise,
functionality does not changed, this is the CMS request.
18-10-21 B.Morgan (materials-V10-07-25)
- Use std::string member functions from G4String in place of synonyms
16-10-21 D.Sawkey (materials-V10-07-24)
- G4MaterialPropertiesTable - fix error with ConstPropertyExists(string)
13-10-21 D.Sawkey (materials-V10-07-23)
- G4MaterialPropertiesTable - return const refs to vectors for
material[const]props and names. Rename Get[Const]PropertyMap to
Get[Const]Properties.
07-10-21 D.Sawkey (materials-V10-07-22)
- G4MaterialPropertiesTable - return nullptr when GetProperty(string)
called for non-existent property; fix error in GetMatConstPropNames
19-09-21 V.Ivanchenko (materials-V10-07-21)
- G4IonisParamMat - return exact computations according to the
original publication (fix #2334)
- G4DensityEffectData - minor clean-up
01-10-21 D.Sawkey (materials-V10-07-20)
- G4MaterialPropertiesTable - FatalException if asked for index of
non-existent property (fix Coverity defect)
19-09-21 V.Ivanchenko (materials-V10-07-19)
- G4DensityEffectCalculator - Matthew Strait critically updated
calculations (fix #2330)
09-09-21 D.Sawkey (materials-V10-07-18)
- G4MaterialPropertiesTable: - use std::vectors for material properties and
material const properties, rather than std::map (speed increase).
- use bool flag with mat const property to indicate whether it is defined
- renaming of variables: fist letter lower case, class variables start with f
- remove iterators to mat prop vectors (use C++11 iteration)
02-09-21 D.Sawkey (materials-V10-07-17)
- G4MaterialPropertiesTable: fix AddConstProperty with new key;
fix RemoveConstProperty; make exception codes unique
17-08-21 J.Hahnfeld (materials-V10-07-16)
- Define operator<< for G4ElementVector, take const references to avoid
needless copy construction
04-08-21 A.Ribon (materials-V10-07-15)
- G4ExtendedMaterial : removed useless dependence on G4PhysicsModelCatalog,
and improved comment.
19-07-21 V.Ivanchenko (materials-V10-07-14)
- G4MaterialPropertyTable - add "spline" argument to method, which
creates G4MaterialPropertyVector
14-07-21 V.Ivanchenko (materials-V10-07-13)
- G4ElementData - reduce length of internal arrays from 108 to 99,
max number 99 is used by G4LivermorePhotoElectricModel, hadronic
models use 93
- G4ElementVector - use const pointer to G4Element
12-07-21 V.Ivanchenko (materials-V10-07-12)
- G4ElementData - use G4int in method signature instead of size_t;
improve initialisation
09-07-21 V.Ivanchenko (materials-V10-07-11)
- G4Material - fixed Coverity report on non-initialized arrays;
use const pointers to G4Elements where; added warnings if
there is a mixture of definition of elements by number of atoms and
mass fraction; reduced code duplication and reduce number of
new/delete for the case when materials are added to the material
- G4ElementData - update class to provide more safe destruction end of run
23-05-21 V.Ivanchenko (materials-V10-07-10)
- G4ExtDEDXTable, G4IonStoppingData - corrected initialisation of spline
- G4NistMaterialBuilder - removed unused argument "isotopes" from all
+3 -1
View File
@@ -90,6 +90,7 @@
#include "G4IonisParamElm.hh"
#include "G4IsotopeVector.hh"
#include "G4ElementTable.hh"
#include "G4ElementVector.hh"
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
@@ -201,7 +202,8 @@ public: // with description
//
friend std::ostream& operator<<(std::ostream&, const G4Element*);
friend std::ostream& operator<<(std::ostream&, const G4Element&);
friend std::ostream& operator<<(std::ostream&, G4ElementTable);
friend std::ostream& operator<<(std::ostream&, const G4ElementTable&);
friend std::ostream& operator<<(std::ostream&, const G4ElementVector&);
public: // without description
+33 -24
View File
@@ -45,7 +45,6 @@
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
#include "globals.hh"
#include "G4NistElementBuilder.hh"
#include "G4PhysicsVector.hh"
#include "G4Physics2DVector.hh"
#include <vector>
@@ -75,6 +74,13 @@ public:
// set name of the dataset
void SetName(const G4String& nam);
//--------------------------------------------------------------
//
// run time methods - no check on validity of input index
// it is a responsibility of the consume code to check the input
//
//--------------------------------------------------------------
// get vector for the element
inline G4PhysicsVector* GetElementData(G4int Z);
@@ -86,10 +92,10 @@ public:
// get component ID which may be number of nucleons,
// or shell number, or any other integer
inline G4int GetComponentID(G4int Z, size_t idx);
inline G4int GetComponentID(G4int Z, G4int idx);
// get vector per shell or per isotope
inline G4PhysicsVector* GetComponentDataByIndex(G4int Z, size_t idx);
inline G4PhysicsVector* GetComponentDataByIndex(G4int Z, G4int idx);
// get vector per shell or per isotope
inline G4PhysicsVector* GetComponentDataByID(G4int Z, G4int id);
@@ -100,20 +106,23 @@ public:
// return cross section per element
// if not available return zero
inline G4double GetValueForComponent(G4int Z, size_t idx, G4double kinEnergy);
private:
inline G4double GetValueForComponent(G4int Z, G4int idx,
G4double kinEnergy);
// Assignment operator and copy constructor
G4ElementData & operator=(const G4ElementData &right) = delete;
G4ElementData(const G4ElementData&) = delete;
G4PhysicsVector* elmData[maxNumElements];
G4Physics2DVector* elm2Data[maxNumElements];
std::vector<G4PhysicsVector*> compData[maxNumElements];
std::vector<G4int> compID[maxNumElements];
size_t compLength[maxNumElements];
G4String name;
private:
static const G4int maxNumElm = 99;
G4PhysicsVector* elmData[maxNumElm];
G4Physics2DVector* elm2Data[maxNumElm];
std::vector<G4PhysicsVector*>* compData[maxNumElm];
std::vector<G4int>* compID[maxNumElm];
G4int compLength[maxNumElm];
G4String name = "";
};
inline void G4ElementData::SetName(const G4String& nam)
@@ -136,27 +145,27 @@ G4Physics2DVector* G4ElementData::GetElement2DData(G4int Z)
inline
size_t G4ElementData::GetNumberOfComponents(G4int Z)
{
return compLength[Z];
return compID[Z]->size();
}
inline G4int G4ElementData::GetComponentID(G4int Z, size_t idx)
inline G4int G4ElementData::GetComponentID(G4int Z, G4int idx)
{
return (compID[Z])[idx];
return (*(compID[Z]))[idx];
}
inline
G4PhysicsVector* G4ElementData::GetComponentDataByIndex(G4int Z, size_t idx)
inline G4PhysicsVector*
G4ElementData::GetComponentDataByIndex(G4int Z, G4int idx)
{
return (compData[Z])[idx];
return (*(compData[Z]))[idx];
}
inline
G4PhysicsVector* G4ElementData::GetComponentDataByID(G4int Z, G4int id)
{
G4PhysicsVector* v = 0;
for(size_t i=0; i<compLength[Z]; ++i) {
if(id == (compID[Z])[i]) {
v = (compData[Z])[i];
G4PhysicsVector* v = nullptr;
for(G4int i=0; i<compLength[Z]; ++i) {
if(id == (*(compID[Z]))[i]) {
v = (*(compData[Z]))[i];
break;
}
}
@@ -170,9 +179,9 @@ G4double G4ElementData::GetValueForElement(G4int Z, G4double kinEnergy)
}
inline G4double
G4ElementData::GetValueForComponent(G4int Z, size_t idx, G4double kinEnergy)
G4ElementData::GetValueForComponent(G4int Z, G4int idx, G4double kinEnergy)
{
return ((compData[Z])[idx])->Value(kinEnergy);
return (*(compData[Z]))[idx]->Value(kinEnergy);
}
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
+3 -2
View File
@@ -38,8 +38,9 @@
#define G4ELEMENTVECTOR_HH
#include <vector>
#include "G4Element.hh"
typedef std::vector<G4Element*> G4ElementVector;
class G4Element;
typedef std::vector<const G4Element*> G4ElementVector;
#endif
@@ -35,8 +35,7 @@
// Class description:
//
// Is used to define the additional material information. This class
// contains a map of G4VMaterialExtension associated with an integer
// key of G4PhysicsModelCatalog index.
// contains a map of G4VMaterialExtension associated with an integer key.
//
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
+42 -44
View File
@@ -152,21 +152,19 @@ public: // with description
//
// Add an element, giving number of atoms
//
void AddElement(G4Element* element, //the element
G4int nAtoms); //nb of atoms in a molecule
void AddElementByNumberOfAtoms(const G4Element* elm, G4int nAtoms);
inline
void AddElementByNumberOfAtoms(G4Element* elm, G4int nAtoms) {AddElement(elm, nAtoms);}
void AddElement(G4Element* elm, G4int nAtoms)
{ AddElementByNumberOfAtoms(elm, nAtoms); }
//
// Add an element or material, giving fraction of mass
//
void AddElement (G4Element* element , //the element
G4double fraction); //fractionOfMass
inline
void AddElementByMassFraction(G4Element* elm, G4double frac) {AddElement(elm, frac);}
void AddElementByMassFraction(const G4Element* elm, G4double fraction);
inline void AddElement (G4Element* elm, G4double frac)
{ AddElementByMassFraction(elm, frac); }
void AddMaterial(G4Material* material, //the material
G4double fraction); //fractionOfMass
void AddMaterial(G4Material* material, G4double fraction);
virtual ~G4Material();
//
@@ -277,7 +275,7 @@ public: // with description
//
friend std::ostream& operator<<(std::ostream&, const G4Material*);
friend std::ostream& operator<<(std::ostream&, const G4Material&);
friend std::ostream& operator<<(std::ostream&, G4MaterialTable);
friend std::ostream& operator<<(std::ostream&, const G4MaterialTable&);
G4Material(__void__&);
// Fake default constructor for usage restricted to direct object
@@ -312,52 +310,52 @@ private:
private:
const G4Material* fBaseMaterial; // Pointer to the base material
G4MaterialPropertiesTable* fMaterialPropertiesTable;
G4ElementVector* theElementVector; // vector of constituent Elements
G4double* fMassFractionVector; // composition by fractional mass
G4int* fAtomsVector; // composition by atom count
void FillVectors();
static
G4MaterialTable theMaterialTable; // the material table
G4MaterialTable theMaterialTable; // the material table
const G4Material* fBaseMaterial; // Pointer to the base material
G4MaterialPropertiesTable* fMaterialPropertiesTable;
//
// Derived data members (computed from the basic data members)
// General atomic properties defined in constructor or
// computed from the basic data members
//
// some general atomic properties
G4double* fVecNbOfAtomsPerVolume; // vector of nb of atoms per volume
G4IonisParamMat* fIonisation; // ionisation parameters
G4SandiaTable* fSandiaTable; // Sandia table
G4ElementVector* theElementVector; // vector of constituent G4Elements
G4int* fAtomsVector; // composition by atom count
G4double* fMassFractionVector; // composition by fractional mass
G4double* fVecNbOfAtomsPerVolume; // number of atoms per volume
G4IonisParamMat* fIonisation; // ionisation parameters
G4SandiaTable* fSandiaTable; // Sandia table
G4double fDensity; // Material density
G4double fFreeElecDensity; // Free electron density
G4double fTemp; // Temperature (defaults: STP)
G4double fPressure; // Pressure (defaults: STP)
G4double fDensity; // Material density
G4double fFreeElecDensity; // Free electron density
G4double fTemp; // Temperature (defaults: STP)
G4double fPressure; // Pressure (defaults: STP)
G4double fTotNbOfAtomsPerVolume; // total nb of atoms per volume
G4double fTotNbOfElectPerVolume; // total nb of electrons per volume
G4double fRadlen; // Radiation length
G4double fNuclInterLen; // Nuclear interaction length
G4double fMassOfMolecule; // for materials built by atoms count
G4double fTotNbOfAtomsPerVolume; // Total nb of atoms per volume
G4double fTotNbOfElectPerVolume; // Total nb of electrons per volume
G4double fRadlen; // Radiation length
G4double fNuclInterLen; // Nuclear interaction length
G4double fMassOfMolecule; // Correct for materials built by atoms count
G4State fState; // Material state (determined
// internally based on density)
size_t fIndexInTable; // the position in the material table
G4State fState; // Material state
size_t fIndexInTable; // Index in the material table
G4int fNumberOfElements; // Number of G4Elements in the material
G4int maxNbComponents; // totalNbOfComponentsInTheMaterial
G4int fArrayLength; // the length of fAtomsVector
G4int fNumberOfComponents; // Nb of components declared so far
// Class members used only at initialisation
G4int fNbComponents; // Number of material components
G4int fIdxComponent; // Index of a new component
G4bool fMassFraction; // Flag of the method to add components
G4int fNumberOfElements; // Nb of Elements in the material
// For composites built via AddMaterial()
std::map<G4Material*, G4double> fMatComponents;
std::map<G4Material*,G4double> fMatComponents; // for composites built via
// AddMaterial()
G4String fName; // Material name
G4String fChemicalFormula; // Material chemical formula
G4String fName; // Material name
G4String fChemicalFormula; // Material chemical formula
#ifdef G4MULTITHREADED
static G4Mutex materialMutex;
@@ -56,7 +56,7 @@
#include "G4MaterialPropertiesIndex.hh"
#include "G4MaterialPropertyVector.hh"
#include <map>
#include <vector>
class G4MaterialPropertiesTable
{
@@ -64,23 +64,22 @@ class G4MaterialPropertiesTable
G4MaterialPropertiesTable();
virtual ~G4MaterialPropertiesTable();
void AddConstProperty(const G4String& key, G4double PropertyValue,
void AddConstProperty(const G4String& key, G4double propertyValue,
G4bool createNewKey = false);
void AddConstProperty(const char* key, G4double PropertyValue,
void AddConstProperty(const char* key, G4double propertyValue,
G4bool createNewKey = false);
// Add a new property to the table by giving a key-name and value
G4MaterialPropertyVector* AddProperty(
const G4String& key, const std::vector<G4double>& photonEnergies,
const std::vector<G4double>& propertyValues, G4bool createNewKey = false);
const std::vector<G4double>& propertyValues, G4bool createNewKey = false,
G4bool spline = false);
// Add a new property to the table by giving a key-name and
// vectors of values
G4MaterialPropertyVector* AddProperty(const char* key,
G4double* PhotonEnergies,
G4double* PropertyValues,
G4int NumEntries,
G4bool createNewKey = false);
G4MaterialPropertyVector* AddProperty(
const char* key, G4double* photonEnergies, G4double* propertyValues,
G4int numEntries, G4bool createNewKey = false, G4bool spline = false);
// Add a new property to the table by giving a key-name and the
// arrays x and y of size NumEntries.
@@ -106,27 +105,24 @@ class G4MaterialPropertiesTable
G4double GetConstProperty(const G4String& key) const;
G4double GetConstProperty(const char* key) const;
// Get the constant property from the table corresponding to the key-name
G4double GetConstProperty(const G4int index) const;
// Get the constant property from the table corresponding to the key-index
// Get a constant property from the table
// It is an error to ask for a const property that the user has not defined.
// Check if it has been defined with ConstPropertyExists() first.
G4bool ConstPropertyExists(const G4String& key) const;
G4bool ConstPropertyExists(const char* key) const;
// Return true if a const property 'key' exists.
G4bool ConstPropertyExists(const G4int index) const;
// Return true if a const property with key-index 'index' exists.
// Return true if a const property has been defined by the user.
// Despite the name, this returns false for a const property in
// GetMaterialConstPropertyNames() but not defined by user.
// Use this method before calling GetConstProperty().
G4MaterialPropertyVector* GetProperty(const char* key,
G4bool warning = false);
G4MaterialPropertyVector* GetProperty(const G4String& key,
G4bool warning = false);
// Get the property from the table corresponding to the key-name.
G4MaterialPropertyVector* GetProperty(const G4int index,
G4bool warning = false);
// Get the property from the table corresponding to the key-index.
G4MaterialPropertyVector* GetProperty(const char* key) const;
G4MaterialPropertyVector* GetProperty(const G4String& key) const;
G4MaterialPropertyVector* GetProperty(const G4int index) const;
// Get the property from the table corresponding to the key-index or index.
// nullptr is returned if the property has not been defined by the user.
void AddEntry(const G4String& key, G4double aPhotonEnergy,
G4double aPropertyValue);
@@ -134,44 +130,56 @@ class G4MaterialPropertiesTable
G4double aPropertyValue);
// Add a new entry (pair of numbers) to the table for a given key.
G4int GetConstPropertyIndex(const G4String& key,
G4bool warning = false) const;
G4int GetConstPropertyIndex(const G4String& key) const;
// Get the constant property index from the key-name
// It is an error to request the index of a non-existent key (key not
// present in fMaterialConstPropertyNames()).
G4int GetPropertyIndex(const G4String& key, G4bool warning = false) const;
G4int GetPropertyIndex(const G4String& key) const;
// Get the property index by the key-name.
// It is an error to request the index of a non-existent key (key not
// present in GetMaterialPropertyNames()).
std::vector<G4String> GetMaterialPropertyNames() const;
std::vector<G4String> GetMaterialConstPropertyNames() const;
void DumpTable() const;
// print the material properties and material constant properties
void DumpTable();
const std::map<G4int, G4MaterialPropertyVector*, std::less<G4int>>*
GetPropertyMap() const
// the next four methods are used in persistency/GDML:
const std::vector<G4String>& GetMaterialPropertyNames() const
{
return &MP;
return fMatPropNames;
}
const std::map<G4int, G4double, std::less<G4int>>* GetConstPropertyMap() const
const std::vector<G4String>& GetMaterialConstPropertyNames() const
{
return &MCP;
return fMatConstPropNames;
}
// Accessors required for persistency purposes
const std::vector<G4MaterialPropertyVector*>& GetProperties() const
{
return fMP;
}
const std::vector<std::pair<G4double, G4bool>>& GetConstProperties()
const
{
return fMCP;
}
// return references to the vectors of material (constant) properties.
private:
G4MaterialPropertyVector* CalculateGROUPVEL();
// Calculate the group velocity based on RINDEX
std::map<G4int, G4MaterialPropertyVector*, std::less<G4int>> MP;
typedef std::map<G4int, G4MaterialPropertyVector*,
std::less<G4int>>::const_iterator MPiterator;
std::vector<G4MaterialPropertyVector*> fMP;
// Vector of pointer to material property vectors. All entries are
// initialized to nullptr. Pointer is not null when mat.prop. vector defined.
// Order of entries in MP defined by enum in G4MaterialPropertiesIndex.
std::map<G4int, G4double, std::less<G4int>> MCP;
typedef std::map<G4int, G4double, std::less<G4int>>::const_iterator
MCPiterator;
// material property map and constant property map by index types
std::vector<std::pair<G4double, G4bool>> fMCP;
// Vector of energy-independent (i.e., "constant") material properties. We
// need to keep track if a property is defined or not: the bool in the pair
// is 'true' if the property is defined.
// Order of entries in MCP defined by enum in G4MaterialPropertiesIndex.
std::vector<G4String> G4MaterialPropertyName;
std::vector<G4String> G4MaterialConstPropertyName;
std::vector<G4String> fMatPropNames;
std::vector<G4String> fMatConstPropNames;
// vectors of strings of property names
};
@@ -102,10 +102,13 @@ G4DensityEffectCalculator::G4DensityEffectCalculator(const G4Material* mat, G4in
for(G4int i=0; i<nlev; ++i) {
sum += sternf[i];
}
sum = (sum > 0.0) ? 1./sum : 0.0;
sum += fConductivity;
const G4double invsum = (sum > 0.0) ? 1./sum : 0.0;
for(G4int i=0; i<nlev; ++i) {
sternf[i] *= sum;
sternf[i] *= invsum;
}
fConductivity *= invsum;
plasmaE = fMaterial->GetIonisation()->GetPlasmaEnergy()/CLHEP::eV;
meanexcite = fMaterial->GetIonisation()->GetMeanExcitationEnergy()/CLHEP::eV;
}
@@ -131,7 +134,7 @@ G4double G4DensityEffectCalculator::ComputeDensityCorrection(G4double x)
G4cout << " Delta: computed= " << exact
<< ", parametrized= " << approx << G4endl;
}
if(approx > 0. && exact < 0.) {
if(approx >= 0. && exact < 0.) {
if(fVerbose > 0) {
++fWarnings;
if(fWarnings < maxWarnings) {
@@ -209,18 +212,32 @@ G4double G4DensityEffectCalculator::FermiDeltaCalculation(G4double x)
// Calculate the Sternheimer adjusted energy levels and parameters l_i given
// the Sternheimer parameter rho.
sternrho /= plasmaE;
for(G4int i=0; i<nlev; ++i) {
sternEbar[i] = levE[i] * sternrho;
sternl[i] = std::sqrt(gpow->powN(sternEbar[i], 2) + 2./3.*sternf[i]);
sternEbar[i] = levE[i] * (sternrho/plasmaE);
sternl[i] = std::sqrt(gpow->powN(sternEbar[i], 2) + (2./3.)*sternf[i]);
}
// The derivative of the function we are solving for is strictly
// negative for positive (physical) values, so if the value at
// zero is less than zero, it has no solution, and there is no
// density effect in the Sternheimer "exact" treatment (which is
// still an approximation).
//
// For conductors, this test is not needed, because Ell(L) contains
// the term fConductivity/(L*L), so the value at L=0 is always
// positive infinity. In the code we don't return inf, though, but
// rather set that term to zero, which means that if this test were
// used, it would give the wrong result for some materials.
if(fConductivity == 0 && Ell(0) <= 0) return 0;
// Make imphirical initial guess
const G4double sternL = Newton(sternrho, false);
if(sternL > -1.) {
return DeltaOnceSolved(sternL);
// Attempt to find the root from 40 starting points evenly distributed
// in log space. Trying a single starting point is not sufficient for
// convergence in most cases.
for(G4int startLi = -10; startLi < 30; ++startLi){
const G4double sternL = Newton(gpow->powN(2, startLi), false);
if(sternL != -1.) {
return DeltaOnceSolved(sternL);
}
}
return -1.; // Signal the caller to use the Sternheimer approximation,
// because we have been unable to solve the exact form.
}
@@ -251,7 +268,7 @@ G4double G4DensityEffectCalculator::Newton(G4double start, G4bool first)
const G4double del = value/dvalue;
lambda -= del;
const G4double eps = std::abs(del);
const G4double eps = std::abs(del/lambda);
if(eps <= 1.e-12) {
++ngood;
if(ngood == 2) {
@@ -263,7 +280,7 @@ G4double G4DensityEffectCalculator::Newton(G4double start, G4bool first)
} else {
++nbad;
}
if(nbad > maxIter || eps > 1.) { break; }
if(nbad > maxIter || std::isnan(value) || std::isinf(value)) { break; }
}
if(fVerbose > 2) {
G4cout << " Failed to converge last value= " << value
@@ -318,6 +335,7 @@ G4double G4DensityEffectCalculator::DEll(G4double L)
ans += sternf[i]/gpow->powN(y + L*L, 2);
}
}
ans += fConductivity/gpow->powN(L*L, 2);
ans *= (-2*L); // pulled out of the loop for efficiency
return ans;
}
@@ -332,12 +350,15 @@ G4double G4DensityEffectCalculator::Ell(G4double L)
ans += sternf[i]/(gpow->powN(sternEbar[i], 2) + L*L);
}
}
if(fConductivity > 0. && L != 0.) {
ans += fConductivity/(L*L);
}
ans -= gpow->powZ(10, -2 * sternx);
return ans;
}
/**
* Given the Sternheimer parameter l^2 (called 'sternL' here), and that
* Given the Sternheimer parameter l (called 'sternL' here), and that
* the l_i and adjusted energies have been found with SetupFermiDeltaCalc(),
* return the value of delta. Helper function for DoFermiDeltaCalc().
*/
@@ -350,6 +371,12 @@ G4double G4DensityEffectCalculator::DeltaOnceSolved(G4double sternL)
+ gpow->powN(sternL, 2))/gpow->powN(sternl[i], 2));
}
}
// sternl for the conduction electrons is sqrt(fConductivity), with
// no factor of 2./3 as with the other levels.
if(fConductivity > 0) {
ans += fConductivity * G4Log((fConductivity
+ gpow->powN(sternL, 2))/fConductivity);
}
ans -= gpow->powN(sternL, 2)/(1 + gpow->powZ(10, 2 * sternx));
return ans;
}
+1 -3
View File
@@ -1295,15 +1295,13 @@ void G4DensityEffectData::Initialize()
//G4_GRAPHITE_POROUS index=277
G4double M277[NDENSARRAY]={26.555,2.49,3.155,0.048,2.5387,0.20762,2.9532,0.14,0.038,78.0 };
AddMaterial(M277,"G4_GRAPHITE_POROUS");
}
G4int G4DensityEffectData::GetElementIndex(G4int Z, G4State st) const
{
G4int idx = -1;
if(Z > 0 && Z < NDENSELEM) {
if(st == state[Z]) { idx = indexZ[Z]; }
else if(st == kStateUndefined) { idx = indexZ[Z]; }
if(st == state[Z] || st == kStateUndefined) { idx = indexZ[Z]; }
}
return idx;
}
+20 -6
View File
@@ -111,7 +111,7 @@ G4Element::G4Element(const G4String& name, const G4String& symbol,
AddNaturalIsotopes();
for (G4int i=0;i<fNbOfAtomicShells;i++)
for (G4int i=0; i<fNbOfAtomicShells; ++i)
{
fAtomicShells[i] = G4AtomicShells::GetBindingEnergy(iz, i);
fNbOfShellElectrons[i] = G4AtomicShells::GetNumberOfElectrons(iz, i);
@@ -187,7 +187,7 @@ void G4Element::AddIsotope(G4Isotope* isotope, G4double abundance)
if ( fNumberOfIsotopes == (G4int)theIsotopeVector->size() ) {
G4double wtSum=0.0;
fAeff = 0.0;
for (G4int i=0; i<fNumberOfIsotopes; i++) {
for (G4int i=0; i<fNumberOfIsotopes; ++i) {
fAeff += fRelativeAbundanceVector[i]*(*theIsotopeVector)[i]->GetA();
wtSum += fRelativeAbundanceVector[i];
}
@@ -195,7 +195,7 @@ void G4Element::AddIsotope(G4Isotope* isotope, G4double abundance)
fNeff = fAeff/(g/mole);
if(wtSum != 1.0) {
for(G4int i=0; i<fNumberOfIsotopes; ++i) {
for (G4int i=0; i<fNumberOfIsotopes; ++i) {
fRelativeAbundanceVector[i] /= wtSum;
}
}
@@ -204,7 +204,7 @@ void G4Element::AddIsotope(G4Isotope* isotope, G4double abundance)
fAtomicShells = new G4double[fNbOfAtomicShells];
fNbOfShellElectrons = new G4int[fNbOfAtomicShells];
for ( G4int j = 0; j < fNbOfAtomicShells; j++ )
for (G4int j = 0; j < fNbOfAtomicShells; ++j)
{
fAtomicShells[j] = G4AtomicShells::GetBindingEnergy(iz, j);
fNbOfShellElectrons[j] = G4AtomicShells::GetNumberOfElectrons(iz, j);
@@ -276,7 +276,7 @@ void G4Element::ComputeDerivedQuantities()
ComputeLradTsaiFactor();
// parameters for energy loss by ionisation
if (fIonisation) { delete fIonisation; }
if (nullptr != fIonisation) { delete fIonisation; }
fIonisation = new G4IonisParamElm(fZeff);
fZ = G4lrint(fZeff);
}
@@ -463,7 +463,7 @@ std::ostream& operator<<(std::ostream& flux, const G4Element* element)
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
std::ostream& operator<<(std::ostream& flux, G4ElementTable ElementTable)
std::ostream& operator<<(std::ostream& flux, const G4ElementTable& ElementTable)
{
//Dump info for all known elements
flux << "\n***** Table : Nb of elements = " << ElementTable.size()
@@ -476,3 +476,17 @@ std::ostream& operator<<(std::ostream& flux, G4ElementTable ElementTable)
}
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
std::ostream& operator<<(std::ostream& flux, const G4ElementVector& ElementVector)
{
//Dump info for all known elements
flux << "\n***** Vector : Nb of elements = " << ElementVector.size()
<< " *****\n" << G4endl;
for (size_t i=0; i<ElementVector.size(); i++) flux << ElementVector[i]
<< G4endl << G4endl;
return flux;
}
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
+29 -27
View File
@@ -46,11 +46,12 @@
G4ElementData::G4ElementData()
{
name = "";
for(G4int i=0; i<maxNumElements; ++i) {
for(G4int i=0; i<maxNumElm; ++i) {
elmData[i] = nullptr;
elm2Data[i] = nullptr;
compLength[i] = 0;
compData[i] = nullptr;
compID[i] = nullptr;
}
}
@@ -58,76 +59,77 @@ G4ElementData::G4ElementData()
G4ElementData::~G4ElementData()
{
for(G4int i=0; i<maxNumElements; ++i) {
for(G4int i=0; i<maxNumElm; ++i) {
delete elmData[i];
delete elm2Data[i];
size_t n = compLength[i];
//G4cout << "Z= " << i << " L= " << n << G4endl;
for(size_t j=0; j<n; ++j) {
//G4cout << "j= " << j << " " << (compData[i])[j] << G4endl;
delete (compData[i])[j];
if(nullptr != compID[i]) {
for(size_t j=0; j<compID[i]->size(); ++j) {
delete (*(compData[i]))[j];
}
delete compID[i];
delete compData[i];
}
}
}
void G4ElementData::InitialiseForElement(G4int Z, G4PhysicsVector* v)
{
if(Z < 1 || Z >= maxNumElements) {
if(Z < 1 || Z >= maxNumElm) {
G4cout << "G4ElementData::InitialiseForElement ERROR for " << name
<< " Z = " << Z << " is out of range!" << G4endl;
G4Exception("G4ElementData::InitialiseForElement()", "mat601",
FatalException, "Wrong data handling");
return;
}
if(elmData[Z]) { delete elmData[Z]; }
if(nullptr != elmData[Z]) { delete elmData[Z]; }
elmData[Z] = v;
}
void G4ElementData::InitialiseForElement(G4int Z, G4Physics2DVector* v)
{
if(Z < 1 || Z >= maxNumElements) {
if(Z < 1 || Z >= maxNumElm) {
G4cout << "G4ElementData::InitialiseForElement ERROR for " << name
<< " Z = " << Z << " is out of range!" << G4endl;
G4Exception("G4ElementData::InitialiseForElement()", "mat601",
FatalException, "Wrong data handling");
return;
}
if(elm2Data[Z]) { delete elm2Data[Z]; }
if(nullptr != elm2Data[Z]) { delete elm2Data[Z]; }
elm2Data[Z] = v;
}
void G4ElementData::InitialiseForComponent(G4int Z, G4int nComponents)
{
if(Z < 1 || Z >= maxNumElements) {
if(Z < 1 || Z >= maxNumElm || nComponents < 0) {
G4cout << "G4ElementData::InitialiseForComponent ERROR for " << name
<< " Z = " << Z << " is out of range!" << G4endl;
<< " Z= " << Z << " Ncomp= " << nComponents
<< " is out of range!" << G4endl;
G4Exception("G4ElementData::InitialiseForComponent()", "mat602",
FatalException, "Wrong data handling");
return;
}
// reserve a new structure
size_t n = compLength[Z];
if(0 < n) {
for(size_t i=0; i<n; ++i) { delete (compData[Z])[i]; }
(compData[Z]).clear();
(compID[Z]).clear();
if(nullptr == compID[Z]) {
compID[Z] = new std::vector<G4int>();
compData[Z] = new std::vector<G4PhysicsVector*>();
}
(compData[Z]).reserve(nComponents);
(compID[Z]).reserve(nComponents);
compID[Z]->resize(nComponents, -1);
compData[Z]->resize(nComponents, nullptr);
compLength[Z] = 0;
}
void
G4ElementData::AddComponent(G4int Z, G4int id, G4PhysicsVector* v)
void G4ElementData::AddComponent(G4int Z, G4int id, G4PhysicsVector* v)
{
if(Z < 1 || Z >= maxNumElements) {
if(Z < 1 || Z >= maxNumElm ||
(G4int)compID[Z]->size() == compLength[Z]) {
G4cout << "G4ElementData::AddComponent ERROR for " << name
<< " Z = " << Z << " is out of range!" << G4endl;
G4Exception("G4ElementData::AddComponent()", "mat603",
FatalException, "Wrong data handling");
return;
}
(compData[Z]).push_back(v);
(compID[Z]).push_back(id);
++compLength[Z];
(*(compData[Z]))[compLength[Z]] = v;
(*(compID[Z]))[compLength[Z]] = id;
compLength[Z] = compLength[Z] + 1;
}
@@ -37,7 +37,6 @@
#include "G4ExtendedMaterial.hh"
#include "G4VMaterialExtension.hh"
#include "G4PhysicsModelCatalog.hh"
// Constructor to create an extended material from the base-class G4Material
+26 -20
View File
@@ -184,7 +184,7 @@ G4DensityEffectData* G4IonisParamMat::GetDensityEffectData()
G4double G4IonisParamMat::DensityCorrection(G4double x)
{
return (!fDensityEffectCalc) ? GetDensityCorrection(x)
return (nullptr == fDensityEffectCalc) ? GetDensityCorrection(x)
: fDensityEffectCalc->ComputeDensityCorrection(x);
}
@@ -226,7 +226,7 @@ void G4IonisParamMat::ComputeDensityEffectParameters()
}
}
// for base material case
if(idx < 0 && bmat) {
if(idx < 0 && nullptr != bmat) {
idx = fDensityData->GetIndex(bmat->GetName());
if(idx >= 0) {
corr = G4Log(bmat->GetDensity()/fMaterial->GetDensity());
@@ -281,7 +281,7 @@ void G4IonisParamMat::ComputeDensityEffectParameters()
} else {
static const G4double Cd2 = 4*pi*hbarc_squared*classic_electr_radius;
static const G4double Cd2 = 4*CLHEP::pi*CLHEP::hbarc_squared*CLHEP::classic_electr_radius;
fPlasmaEnergy = std::sqrt(Cd2*fMaterial->GetTotNbOfElectPerVolume());
// Compute parameters for the density effect correction in DE/Dx formula.
@@ -292,9 +292,9 @@ void G4IonisParamMat::ComputeDensityEffectParameters()
//
// condensed materials
//
if ((State == kStateSolid)||(State == kStateLiquid)) {
if ((State == kStateSolid) || (State == kStateLiquid)) {
static const G4double E100eV = 100.*eV;
static const G4double E100eV = 100.*CLHEP::eV;
static const G4double ClimiS[] = {3.681 , 5.215 };
static const G4double X0valS[] = {1.0 , 1.5 };
static const G4double X1valS[] = {2.0 , 3.0 };
@@ -317,17 +317,23 @@ void G4IonisParamMat::ComputeDensityEffectParameters()
//
fMdensity = 3.;
fX1density = 4.0;
if(fCdensity < 10.) {
fX0density = 1.6;
} else if(fCdensity < 11.5) {
fX0density = 1.6 + 0.2*(fCdensity - 10.);
} else if(fCdensity < 12.25) {
fX0density = 1.9 + (fCdensity - 11.5)/7.5;
} else if(fCdensity < 13.804) {
fX0density = 2.0;
fX1density = 4.0 + (fCdensity - 12.25)/1.554;
if(fCdensity <= 10.) {
fX0density = 1.6;
} else if(fCdensity <= 10.5) {
fX0density = 1.7;
} else if(fCdensity <= 11.0) {
fX0density = 1.8;
} else if(fCdensity <= 11.5) {
fX0density = 1.9;
} else if(fCdensity <= 12.25) {
fX0density = 2.0;
} else if(fCdensity <= 13.804) {
fX0density = 2.0;
fX1density = 5.0;
} else {
fX0density = 0.326*fCdensity-2.5; fX1density = 5.0;
fX0density = 0.326*fCdensity-2.5;
fX1density = 5.0;
}
//special: Hydrogen
@@ -395,12 +401,12 @@ void G4IonisParamMat::ComputeFluctModel()
fF2fluct = (Zeff > 2.) ? 2./Zeff : 0.0;
fF1fluct = 1. - fF2fluct;
fEnergy2fluct = 10.*Zeff*Zeff*eV;
fEnergy2fluct = 10.*Zeff*Zeff*CLHEP::eV;
fLogEnergy2fluct = G4Log(fEnergy2fluct);
fLogEnergy1fluct = (fLogMeanExcEnergy - fF2fluct*fLogEnergy2fluct)
/fF1fluct;
fEnergy1fluct = G4Exp(fLogEnergy1fluct);
fEnergy0fluct = 10.*eV;
fEnergy0fluct = 10.*CLHEP::eV;
fRateionexcfluct = 0.4;
}
@@ -444,7 +450,7 @@ void G4IonisParamMat::ComputeIonParameters()
}
fZeff = z;
fLfactor = lF;
fFermiEnergy = 25.*keV*vF*vF;
fFermiEnergy = 25.*CLHEP::keV*vF*vF;
fInvA23 = a23;
}
@@ -456,7 +462,7 @@ void G4IonisParamMat::SetMeanExcitationEnergy(G4double value)
if (G4NistManager::Instance()->GetVerbose() > 1) {
G4cout << "G4Material: Mean excitation energy is changed for "
<< fMaterial->GetName()
<< " Iold= " << fMeanExcitationEnergy/eV
<< " Iold= " << fMeanExcitationEnergy/CLHEP::eV
<< "eV; Inew= " << value/eV << " eV;"
<< G4endl;
}
@@ -525,7 +531,7 @@ void G4IonisParamMat::SetDensityEffectParameters(const G4Material* bmat)
void G4IonisParamMat::ComputeDensityEffectOnFly(G4bool val)
{
if(val) {
if(!fDensityEffectCalc) {
if(nullptr == fDensityEffectCalc) {
G4int n = 0;
for(size_t i=0; i<fMaterial->GetNumberOfElements(); ++i) {
const G4int Z = fMaterial->GetElement(i)->GetZasInt();
+266 -194
View File
@@ -116,8 +116,7 @@ G4Material::G4Material(const G4String& name, G4double z,
// Initialize theElementVector allocating one
// element corresponding to this material
maxNbComponents = fNumberOfComponents = fNumberOfElements = 1;
fArrayLength = maxNbComponents;
fNbComponents = fNumberOfElements = 1;
theElementVector = new G4ElementVector();
// take element from DB
@@ -167,11 +166,17 @@ G4Material::G4Material(const G4String& name, G4double density,
fTemp = temp;
fPressure = pressure;
maxNbComponents = nComponents;
fArrayLength = maxNbComponents;
fNumberOfComponents = fNumberOfElements = 0;
theElementVector = new G4ElementVector();
theElementVector->reserve(maxNbComponents);
fNbComponents = nComponents;
theElementVector = new G4ElementVector();
theElementVector->reserve(fNbComponents);
fAtomsVector = new G4int[fNbComponents];
fMassFractionVector = new G4double[fNbComponents];
for(G4int i=0; i<fNbComponents; ++i) {
fAtomsVector[i] = 0;
fMassFractionVector[i] = 0.0;
}
fMassFraction = true;
if (fState == kStateUndefined)
{
@@ -211,8 +216,7 @@ G4Material::G4Material(const G4String& name, G4double density,
fMassOfMolecule = fBaseMaterial->GetMassOfMolecule();
fNumberOfElements = fBaseMaterial->GetNumberOfElements();
maxNbComponents = fNumberOfElements;
fNumberOfComponents = fNumberOfElements;
fNbComponents = fNumberOfElements;
CopyPointersOfBaseMaterial();
}
@@ -236,7 +240,6 @@ G4Material::~G4Material()
if(fBaseMaterial == nullptr) {
delete theElementVector;
delete fSandiaTable;
//delete fMaterialPropertiesTable;
delete [] fMassFractionVector;
delete [] fAtomsVector;
}
@@ -252,34 +255,30 @@ G4Material::~G4Material()
void G4Material::InitializePointers()
{
theElementVector = nullptr;
fMassFractionVector = nullptr;
fAtomsVector = nullptr;
fMaterialPropertiesTable = nullptr;
fVecNbOfAtomsPerVolume = nullptr;
fBaseMaterial = nullptr;
fMaterialPropertiesTable = nullptr;
theElementVector = nullptr;
fAtomsVector = nullptr;
fMassFractionVector = nullptr;
fVecNbOfAtomsPerVolume = nullptr;
fChemicalFormula = "";
fIonisation = nullptr;
fSandiaTable = nullptr;
// initilized data members
fDensity = 0.0;
fFreeElecDensity = 0.0;
fState = kStateUndefined;
fTemp = 0.0;
fPressure = 0.0;
maxNbComponents = 0;
fArrayLength = 0;
fNumberOfComponents = 0;
fNumberOfElements = 0;
fDensity = fFreeElecDensity = fTemp = fPressure = 0.0;
fTotNbOfAtomsPerVolume = 0.0;
fTotNbOfElectPerVolume = 0.0;
fRadlen = 0.0;
fNuclInterLen = 0.0;
fMassOfMolecule = 0.0;
fRadlen = fNuclInterLen = fMassOfMolecule = 0.0;
fState = kStateUndefined;
fIonisation = nullptr;
fSandiaTable = nullptr;
fNumberOfElements = fNbComponents = fIdxComponent = 0;
fMassFraction = true;
fChemicalFormula = "";
// initilized data members
// Store in the static Table of Materials
fIndexInTable = theMaterialTable.size();
@@ -366,36 +365,64 @@ void G4Material::CopyPointersOfBaseMaterial()
// AddElement -- composition by atom count
void G4Material::AddElement(G4Element* element, G4int nAtoms)
void
G4Material::AddElementByNumberOfAtoms(const G4Element* elm, G4int nAtoms)
{
// initialization
if ( fNumberOfElements == 0 ) {
fAtomsVector = new G4int [fArrayLength];
fMassFractionVector = new G4double[fArrayLength];
// perform checks consistency
if(0 == fIdxComponent) { fMassFraction = false; }
if(fIdxComponent >= fNbComponents) {
G4ExceptionDescription ed;
ed << "For material " << fName << " and added element "
<< elm->GetName() << " with Natoms=" << nAtoms
<< " wrong attempt to add more than the declared number of elements "
<< fIdxComponent << " >= " << fNbComponents;
G4Exception ("G4Material::AddElementByNumberOfAtoms()", "mat031",
FatalException, ed, "");
}
// filling ...
if ( fNumberOfElements < maxNbComponents ) {
theElementVector->push_back(element);
fAtomsVector[fNumberOfElements] = nAtoms;
fNumberOfComponents = ++fNumberOfElements;
} else {
G4cout << "G4Material::AddElement ERROR for " << fName << " nElement= "
<< fNumberOfElements << G4endl;
G4Exception ("G4Material::AddElement()", "mat031", FatalException,
"Attempt to add more than the declared number of elements.");
if(fMassFraction) {
G4ExceptionDescription ed;
G4cout << "For material " << fName << " and added element "
<< elm->GetName() << " with Natoms=" << nAtoms
<< " problem: cannot add by number of atoms after "
<< "addition of elements by mass fraction";
G4Exception ("G4Material::AddElementByNumberOfAtoms()", "mat031",
FatalException, ed, "");
}
G4Element* element = const_cast<G4Element*>(elm);
// filling
if (fIdxComponent < fNbComponents) {
G4bool isAdded = false;
for (G4int i=0; i<fNumberOfElements; ++i) {
if ( element == (*theElementVector)[i] ) {
G4ExceptionDescription ed;
ed << "For material " << fName << " and added element "
<< elm->GetName() << ", Natoms=" << nAtoms
<< ", fIdxComponent=" << fIdxComponent
<< " problem: attempt to add the same element, which already is at idx="
<< i << " with the Natoms=" << fAtomsVector[i];
G4Exception ("G4Material::AddElementByNumberOfAtoms()", "mat031",
JustWarning, ed, "");
fAtomsVector[i] += nAtoms;
break;
}
}
if(!isAdded) {
theElementVector->push_back(element);
fAtomsVector[fNumberOfElements] = nAtoms;
++fNumberOfElements;
}
}
// filled.
if ( fNumberOfElements == maxNbComponents ) {
++fIdxComponent;
// is filled
if (fIdxComponent == fNbComponents) {
// compute proportion by mass
G4int i=0;
G4double Amol = 0.;
for (i=0; i<fNumberOfElements; ++i) {
for (G4int i=0; i<fNumberOfElements; ++i) {
G4double w = fAtomsVector[i]*(*theElementVector)[i]->GetA();
Amol += w;
fMassFractionVector[i] = w;
}
for (i=0; i<fNumberOfElements; ++i) {
for (G4int i=0; i<fNumberOfElements; ++i) {
fMassFractionVector[i] /= Amol;
}
@@ -408,64 +435,68 @@ void G4Material::AddElement(G4Element* element, G4int nAtoms)
// AddElement -- composition by fraction of mass
void G4Material::AddElement(G4Element* element, G4double fraction)
void
G4Material::AddElementByMassFraction(const G4Element* elm, G4double fraction)
{
// perform checks consistency
if(fraction < 0.0 || fraction > 1.0) {
G4cout << "G4Material::AddElement ERROR for " << fName << " and "
<< element->GetName() << " mass fraction= " << fraction
<< " is wrong " << G4endl;
G4Exception ("G4Material::AddElement()", "mat032", FatalException,
"Attempt to add element with wrong mass fraction");
G4ExceptionDescription ed;
ed << "For material " << fName << " and added element "
<< elm->GetName() << " massFraction= " << fraction
<< " is wrong ";
G4Exception ("G4Material::AddElementByMassFraction()", "mat031",
FatalException, ed, "");
}
// initialization
if (fNumberOfComponents == 0) {
fMassFractionVector = new G4double[fArrayLength];
fAtomsVector = new G4int [fArrayLength];
if(!fMassFraction) {
G4ExceptionDescription ed;
ed << "For material " << fName << " and added element "
<< elm->GetName() << ", massFraction= " << fraction
<< ", fIdxComponent=" << fIdxComponent
<< " problem: cannot add by mass fraction after "
<< "addition of elements by number of atoms";
G4Exception ("G4Material::AddElementByMassFraction()", "mat031",
FatalException, ed, "");
}
// filling ...
if (fNumberOfComponents < maxNbComponents) {
G4int el = 0;
// Loop checking, 07-Aug-2015, Vladimir Ivanchenko
while ((el<fNumberOfElements)&&(element!=(*theElementVector)[el])) { ++el; }
if (el<fNumberOfElements) fMassFractionVector[el] += fraction;
else {
if(fIdxComponent >= fNbComponents) {
G4ExceptionDescription ed;
ed << "For material " << fName << " and added element "
<< elm->GetName() << ", massFraction= " << fraction
<< ", fIdxComponent=" << fIdxComponent
<< " problem: attempt to add more than the declared number of elements "
<< fIdxComponent << " >= " << fNbComponents;
G4Exception ("G4Material::AddElementByMassFraction()", "mat031",
FatalException, ed, "");
}
G4Element* element = const_cast<G4Element*>(elm);
// filling
if (fIdxComponent < fNbComponents) {
G4bool isAdded = false;
for (G4int i=0; i<fNumberOfElements; ++i) {
if ( element == (*theElementVector)[i] ) {
G4ExceptionDescription ed;
ed << "For material " << fName << " and added element "
<< elm->GetName() << ", massFraction= " << fraction
<< ", fIdxComponent=" << fIdxComponent
<< " problem: attempt to add the same element, which is already at idx="
<< i << " with the fraction " << fMassFractionVector[i];
G4Exception ("G4Material::AddElementByMassFraction()", "mat031",
JustWarning, ed, "");
fMassFractionVector[i] += fraction;
isAdded = true;
break;
}
}
if(!isAdded) {
theElementVector->push_back(element);
fMassFractionVector[el] = fraction;
fMassFractionVector[fNumberOfElements] = fraction;
++fNumberOfElements;
}
++fNumberOfComponents;
} else {
G4cout << "G4Material::AddElement ERROR for " << fName << " nElement= "
<< fNumberOfElements << G4endl;
G4Exception ("G4Material::AddElement()", "mat033", FatalException,
"Attempt to add more than the declared number of elements.");
}
// filled.
if (fNumberOfComponents == maxNbComponents) {
G4int i=0;
G4double Zmol(0.), Amol(0.);
// check sum of weights -- OK?
G4double wtSum(0.0);
for (i=0; i<fNumberOfElements; ++i) {
wtSum += fMassFractionVector[i];
Zmol += fMassFractionVector[i]*(*theElementVector)[i]->GetZ();
Amol += fMassFractionVector[i]*(*theElementVector)[i]->GetA();
}
if (std::abs(1.-wtSum) > perThousand) {
G4cout << "WARNING !! for " << fName << " sum of fractional masses "
<< wtSum << " is not 1 - results may be wrong" << G4endl;
G4Exception ("G4Material::AddElement()", "mat033", JustWarning,
"Fractional masses are incorrect.");
}
for (i=0; i<fNumberOfElements; ++i) {
fAtomsVector[i] =
G4lrint(fMassFractionVector[i]*Amol/(*theElementVector)[i]->GetA());
}
ComputeDerivedQuantities();
}
++fIdxComponent;
// is filled
if(fIdxComponent == fNbComponents) { FillVectors(); }
}
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
@@ -475,90 +506,129 @@ void G4Material::AddElement(G4Element* element, G4double fraction)
void G4Material::AddMaterial(G4Material* material, G4double fraction)
{
if(fraction < 0.0 || fraction > 1.0) {
G4cout << "G4Material::AddMaterial ERROR for " << fName << " and "
<< material->GetName() << " mass fraction= " << fraction
<< " is wrong ";
G4Exception ("G4Material::AddMaterial()", "mat034", FatalException,
"Attempt to add material with wrong mass fraction");
G4ExceptionDescription ed;
ed << "For material " << fName << " and added material "
<< material->GetName() << ", massFraction= " << fraction
<< " is wrong ";
G4Exception ("G4Material::AddMaterial()", "mat031", FatalException,
ed, "");
}
// initialization
if (fNumberOfComponents == 0) {
fMassFractionVector = new G4double[fArrayLength];
fAtomsVector = new G4int [fArrayLength];
if(!fMassFraction) {
G4ExceptionDescription ed;
ed << "For material " << fName << " and added material "
<< material->GetName() << ", massFraction= " << fraction
<< ", fIdxComponent=" << fIdxComponent
<< " problem: cannot add by mass fraction after "
<< "addition of elements by number of atoms";
G4Exception ("G4Material::AddMaterial()", "mat031", FatalException,
ed, "");
}
G4int nelm = material->GetNumberOfElements();
// arrays should be extended
if(nelm > 1) {
G4int nold = fArrayLength;
fArrayLength += nelm - 1;
G4double* v1 = new G4double[fArrayLength];
G4int* i1 = new G4int[fArrayLength];
for(G4int i=0; i<nold; ++i) {
v1[i] = fMassFractionVector[i];
i1[i] = fAtomsVector[i];
}
delete [] fAtomsVector;
delete [] fMassFractionVector;
fMassFractionVector = v1;
fAtomsVector = i1;
if(fIdxComponent >= fNbComponents) {
G4ExceptionDescription ed;
ed << "For material " << fName << " and added material "
<< material->GetName() << ", massFraction= " << fraction
<< " attempt to add more than the declared number of elements "
<< fIdxComponent << " >= " << fNbComponents;
G4Exception ("G4Material::AddMaterial()", "mat031", FatalException,
ed, "");
}
// filling ...
if (fNumberOfComponents < maxNbComponents) {
for (G4int elm=0; elm<nelm; ++elm)
{
G4Element* element = (*(material->GetElementVector()))[elm];
G4int el = 0;
// Loop checking, 07-Aug-2015, Vladimir Ivanchenko
while ((el<fNumberOfElements)&&(element!=(*theElementVector)[el])) el++;
if (el < fNumberOfElements) fMassFractionVector[el] += fraction
*(material->GetFractionVector())[elm];
else {
theElementVector->push_back(element);
fMassFractionVector[el] = fraction
*(material->GetFractionVector())[elm];
++fNumberOfElements;
}
}
++fNumberOfComponents;
///store massFraction of material component
// filling
if (fIdxComponent < fNbComponents) {
fMatComponents[material] = fraction;
} else {
G4cout << "G4Material::AddMaterial ERROR for " << fName << " nElement= "
<< fNumberOfElements << G4endl;
G4Exception ("G4Material::AddMaterial()", "mat035", FatalException,
"Attempt to add more than the declared number of components.");
}
// filled.
if (fNumberOfComponents == maxNbComponents) {
G4int i=0;
G4double Zmol(0.), Amol(0.);
// check sum of weights -- OK?
G4double wtSum(0.0);
for (i=0; i<fNumberOfElements; ++i) {
wtSum += fMassFractionVector[i];
Zmol += fMassFractionVector[i]*(*theElementVector)[i]->GetZ();
Amol += fMassFractionVector[i]*(*theElementVector)[i]->GetA();
}
if (std::abs(1.-wtSum) > perThousand) {
G4cout << "G4Material::AddMaterial WARNING !! for " << fName
<< " sum of fractional masses "
<< wtSum << " is not 1 - results may be wrong"
<< G4endl;
G4Exception ("G4Material::AddMaterial()", "mat033", JustWarning,
"Fractional masses are incorrect.");
}
for (i=0; i<fNumberOfElements; ++i) {
fAtomsVector[i] =
G4lrint(fMassFractionVector[i]*Amol/(*theElementVector)[i]->GetA());
}
ComputeDerivedQuantities();
}
++fIdxComponent;
// is filled
if(fIdxComponent == fNbComponents) { FillVectors(); }
}
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
void G4Material::FillVectors()
{
// there are material components
if(!fMatComponents.empty()) {
G4int nel = fNumberOfElements;
// check list of materials
for(auto & x : fMatComponents) {
const G4Material* mat = x.first;
G4int nn = mat->GetNumberOfElements();
for(G4int j=0; j<nn; ++j) {
G4bool yes = true;
const G4Element* elm = mat->GetElement(j);
for(G4int k=0; k<fNumberOfElements; ++k) {
if(elm == (*theElementVector)[k]) {
yes = false;
break;
}
}
if(yes) { ++nel; }
}
}
// resize vectors
if(nel > fNbComponents) {
delete [] fAtomsVector;
fAtomsVector = new G4int[nel];
G4double* v = new G4double[nel];
for(G4int i=0; i<fNumberOfElements; ++i) {
fAtomsVector[i] = 0;
v[i] = fMassFractionVector[i];
}
delete [] fMassFractionVector;
fMassFractionVector = v;
for(G4int i=fNumberOfElements; i<nel; ++i) {
fAtomsVector[i] = 0;
fMassFractionVector[i] = 0.0;
}
}
// filling
for(auto & x : fMatComponents) {
const G4Material* mat = x.first;
G4double frac = x.second;
G4int nn = mat->GetNumberOfElements();
const G4double* elmFrac = mat->GetFractionVector();
for(G4int j=0; j<nn; ++j) {
G4bool yes = true;
const G4Element* elm = mat->GetElement(j);
for(G4int k=0; k<fNumberOfElements; ++k) {
if(elm == (*theElementVector)[k]) {
fMassFractionVector[k] += frac*elmFrac[j];
yes = false;
break;
}
}
if(yes) {
theElementVector->push_back(const_cast<G4Element*>(elm));
fMassFractionVector[fNumberOfElements] = frac*elmFrac[j];
++fNumberOfElements;
}
}
}
}
// check sum of weights -- OK?
G4double wtSum(0.0);
for (G4int i=0; i<fNumberOfElements; ++i) {
wtSum += fMassFractionVector[i];
}
if (std::abs(1.-wtSum) > perThousand) {
G4ExceptionDescription ed;
ed << "For material " << fName << " sum of fractional masses "
<< wtSum << " is not 1 - results may be wrong";
G4Exception ("G4Material::FillVectors()", "mat031", JustWarning,
ed, "");
}
G4double coeff = (wtSum > 0.0) ? 1./wtSum : 1.0;
G4double Amol(0.);
for (G4int i=0; i<fNumberOfElements; ++i) {
fMassFractionVector[i] *= coeff;
Amol += fMassFractionVector[i]*(*theElementVector)[i]->GetA();
}
for (G4int i=0; i<fNumberOfElements; ++i) {
fAtomsVector[i] =
G4lrint(fMassFractionVector[i]*Amol/(*theElementVector)[i]->GetA());
}
ComputeDerivedQuantities();
}
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
@@ -566,7 +636,7 @@ void G4Material::AddMaterial(G4Material* material, G4double fraction)
void G4Material::ComputeRadiationLength()
{
G4double radinv = 0.0 ;
for (G4int i=0;i<fNumberOfElements;++i) {
for (G4int i=0; i<fNumberOfElements; ++i) {
radinv += fVecNbOfAtomsPerVolume[i]*((*theElementVector)[i]->GetfRadTsai());
}
fRadlen = (radinv <= 0.0 ? DBL_MAX : 1./radinv);
@@ -625,7 +695,7 @@ void G4Material::ComputeDensityEffectOnFly(G4bool val)
#ifdef G4MULTITHREADED
G4MUTEXLOCK(&materialMutex);
#endif
if (!fIonisation) { fIonisation = new G4IonisParamMat(this); }
if (nullptr == fIonisation) { fIonisation = new G4IonisParamMat(this); }
fIonisation->ComputeDensityEffectOnFly(val);
#ifdef G4MULTITHREADED
G4MUTEXUNLOCK(&materialMutex);
@@ -701,10 +771,11 @@ G4Material* G4Material::GetMaterial(size_t nComp, G4double dens)
G4double G4Material::GetZ() const
{
if (fNumberOfElements > 1) {
G4cout << "G4Material ERROR in GetZ. The material: " << fName
<< " is a mixture.";
G4Exception ("G4Material::GetZ()", "mat036", FatalException,
"the Atomic number is not well defined." );
G4ExceptionDescription ed;
ed << "For material " << fName << " ERROR in GetZ() - Nelm="
<< fNumberOfElements << " > 1, which is not allowed";
G4Exception ("G4Material::GetZ()", "mat036", FatalException,
ed, "");
}
return (*theElementVector)[0]->GetZ();
}
@@ -714,10 +785,11 @@ G4double G4Material::GetZ() const
G4double G4Material::GetA() const
{
if (fNumberOfElements > 1) {
G4cout << "G4Material ERROR in GetA. The material: " << fName
<< " is a mixture.";
G4Exception ("G4Material::GetA()", "mat037", FatalException,
"the Atomic mass is not well defined." );
G4ExceptionDescription ed;
ed << "For material " << fName << " ERROR in GetA() - Nelm="
<< fNumberOfElements << " > 1, which is not allowed";
G4Exception ("G4Material::GetA()", "mat036", FatalException,
ed, "");
}
return (*theElementVector)[0]->GetA();
}
@@ -777,7 +849,7 @@ std::ostream& operator<<(std::ostream& flux, const G4Material& material)
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
std::ostream& operator<<(std::ostream& flux, G4MaterialTable MaterialTable)
std::ostream& operator<<(std::ostream& flux, const G4MaterialTable& MaterialTable)
{
//Dump info for all known materials
flux << "\n***** Table : Nb of materials = " << MaterialTable.size()
@@ -801,7 +873,7 @@ G4bool G4Material::IsExtended() const
void G4Material::SetMaterialPropertiesTable(G4MaterialPropertiesTable* anMPT)
{
if(anMPT && fMaterialPropertiesTable != anMPT) {
if(nullptr != anMPT && fMaterialPropertiesTable != anMPT) {
#ifdef G4MULTITHREADED
G4MUTEXLOCK(&materialMutex);
if(fMaterialPropertiesTable != anMPT) {
+226 -246
View File
@@ -54,158 +54,151 @@
#include <algorithm>
#include <cassert>
#ifdef G4MULTITHREADED
# include "G4AutoLock.hh"
namespace
{
G4Mutex materialPropertyTableMutex = G4MUTEX_INITIALIZER;
}
#endif
G4MaterialPropertiesTable::G4MaterialPropertiesTable()
{
// elements of these 2 vectors must be in same order as
// the corresponding enums in G4MaterialPropertiesIndex.hh
G4MaterialPropertyName.push_back(G4String("RINDEX"));
G4MaterialPropertyName.push_back(G4String("REFLECTIVITY"));
G4MaterialPropertyName.push_back(G4String("REALRINDEX"));
G4MaterialPropertyName.push_back(G4String("IMAGINARYRINDEX"));
G4MaterialPropertyName.push_back(G4String("EFFICIENCY"));
G4MaterialPropertyName.push_back(G4String("TRANSMITTANCE"));
G4MaterialPropertyName.push_back(G4String("SPECULARLOBECONSTANT"));
G4MaterialPropertyName.push_back(G4String("SPECULARSPIKECONSTANT"));
G4MaterialPropertyName.push_back(G4String("BACKSCATTERCONSTANT"));
G4MaterialPropertyName.push_back(G4String("GROUPVEL"));
G4MaterialPropertyName.push_back(G4String("MIEHG"));
G4MaterialPropertyName.push_back(G4String("RAYLEIGH"));
G4MaterialPropertyName.push_back(G4String("WLSCOMPONENT"));
G4MaterialPropertyName.push_back(G4String("WLSABSLENGTH"));
G4MaterialPropertyName.push_back(G4String("WLSCOMPONENT2"));
G4MaterialPropertyName.push_back(G4String("WLSABSLENGTH2"));
G4MaterialPropertyName.push_back(G4String("ABSLENGTH"));
G4MaterialPropertyName.push_back(G4String("PROTONSCINTILLATIONYIELD"));
G4MaterialPropertyName.push_back(G4String("DEUTERONSCINTILLATIONYIELD"));
G4MaterialPropertyName.push_back(G4String("TRITONSCINTILLATIONYIELD"));
G4MaterialPropertyName.push_back(G4String("ALPHASCINTILLATIONYIELD"));
G4MaterialPropertyName.push_back(G4String("IONSCINTILLATIONYIELD"));
G4MaterialPropertyName.push_back(G4String("ELECTRONSCINTILLATIONYIELD"));
G4MaterialPropertyName.push_back(G4String("SCINTILLATIONCOMPONENT1"));
G4MaterialPropertyName.push_back(G4String("SCINTILLATIONCOMPONENT2"));
G4MaterialPropertyName.push_back(G4String("SCINTILLATIONCOMPONENT3"));
fMatPropNames.push_back(G4String("RINDEX"));
fMatPropNames.push_back(G4String("REFLECTIVITY"));
fMatPropNames.push_back(G4String("REALRINDEX"));
fMatPropNames.push_back(G4String("IMAGINARYRINDEX"));
fMatPropNames.push_back(G4String("EFFICIENCY"));
fMatPropNames.push_back(G4String("TRANSMITTANCE"));
fMatPropNames.push_back(G4String("SPECULARLOBECONSTANT"));
fMatPropNames.push_back(G4String("SPECULARSPIKECONSTANT"));
fMatPropNames.push_back(G4String("BACKSCATTERCONSTANT"));
fMatPropNames.push_back(G4String("GROUPVEL"));
fMatPropNames.push_back(G4String("MIEHG"));
fMatPropNames.push_back(G4String("RAYLEIGH"));
fMatPropNames.push_back(G4String("WLSCOMPONENT"));
fMatPropNames.push_back(G4String("WLSABSLENGTH"));
fMatPropNames.push_back(G4String("WLSCOMPONENT2"));
fMatPropNames.push_back(G4String("WLSABSLENGTH2"));
fMatPropNames.push_back(G4String("ABSLENGTH"));
fMatPropNames.push_back(G4String("PROTONSCINTILLATIONYIELD"));
fMatPropNames.push_back(G4String("DEUTERONSCINTILLATIONYIELD"));
fMatPropNames.push_back(G4String("TRITONSCINTILLATIONYIELD"));
fMatPropNames.push_back(G4String("ALPHASCINTILLATIONYIELD"));
fMatPropNames.push_back(G4String("IONSCINTILLATIONYIELD"));
fMatPropNames.push_back(G4String("ELECTRONSCINTILLATIONYIELD"));
fMatPropNames.push_back(G4String("SCINTILLATIONCOMPONENT1"));
fMatPropNames.push_back(G4String("SCINTILLATIONCOMPONENT2"));
fMatPropNames.push_back(G4String("SCINTILLATIONCOMPONENT3"));
assert(G4MaterialPropertyName.size() == kNumberOfPropertyIndex);
assert(fMatPropNames.size() == kNumberOfPropertyIndex);
G4MaterialConstPropertyName.push_back(G4String("SURFACEROUGHNESS"));
G4MaterialConstPropertyName.push_back(G4String("ISOTHERMAL_COMPRESSIBILITY"));
G4MaterialConstPropertyName.push_back(G4String("RS_SCALE_FACTOR"));
G4MaterialConstPropertyName.push_back(G4String("WLSMEANNUMBERPHOTONS"));
G4MaterialConstPropertyName.push_back(G4String("WLSTIMECONSTANT"));
G4MaterialConstPropertyName.push_back(G4String("WLSMEANNUMBERPHOTONS2"));
G4MaterialConstPropertyName.push_back(G4String("WLSTIMECONSTANT2"));
G4MaterialConstPropertyName.push_back(G4String("MIEHG_FORWARD"));
G4MaterialConstPropertyName.push_back(G4String("MIEHG_BACKWARD"));
G4MaterialConstPropertyName.push_back(G4String("MIEHG_FORWARD_RATIO"));
G4MaterialConstPropertyName.push_back(G4String("SCINTILLATIONYIELD"));
G4MaterialConstPropertyName.push_back(G4String("RESOLUTIONSCALE"));
G4MaterialConstPropertyName.push_back(G4String("FERMIPOT"));
G4MaterialConstPropertyName.push_back(G4String("DIFFUSION"));
G4MaterialConstPropertyName.push_back(G4String("SPINFLIP"));
G4MaterialConstPropertyName.push_back(G4String("LOSS"));
G4MaterialConstPropertyName.push_back(G4String("LOSSCS"));
G4MaterialConstPropertyName.push_back(G4String("ABSCS"));
G4MaterialConstPropertyName.push_back(G4String("SCATCS"));
G4MaterialConstPropertyName.push_back(G4String("MR_NBTHETA"));
G4MaterialConstPropertyName.push_back(G4String("MR_NBE"));
G4MaterialConstPropertyName.push_back(G4String("MR_RRMS"));
G4MaterialConstPropertyName.push_back(G4String("MR_CORRLEN"));
G4MaterialConstPropertyName.push_back(G4String("MR_THETAMIN"));
G4MaterialConstPropertyName.push_back(G4String("MR_THETAMAX"));
G4MaterialConstPropertyName.push_back(G4String("MR_EMIN"));
G4MaterialConstPropertyName.push_back(G4String("MR_EMAX"));
G4MaterialConstPropertyName.push_back(G4String("MR_ANGNOTHETA"));
G4MaterialConstPropertyName.push_back(G4String("MR_ANGNOPHI"));
G4MaterialConstPropertyName.push_back(G4String("MR_ANGCUT"));
G4MaterialConstPropertyName.push_back(G4String("SCINTILLATIONTIMECONSTANT1"));
G4MaterialConstPropertyName.push_back(G4String("SCINTILLATIONTIMECONSTANT2"));
G4MaterialConstPropertyName.push_back(G4String("SCINTILLATIONTIMECONSTANT3"));
G4MaterialConstPropertyName.push_back(G4String("SCINTILLATIONRISETIME1"));
G4MaterialConstPropertyName.push_back(G4String("SCINTILLATIONRISETIME2"));
G4MaterialConstPropertyName.push_back(G4String("SCINTILLATIONRISETIME3"));
G4MaterialConstPropertyName.push_back(G4String("SCINTILLATIONYIELD1"));
G4MaterialConstPropertyName.push_back(G4String("SCINTILLATIONYIELD2"));
G4MaterialConstPropertyName.push_back(G4String("SCINTILLATIONYIELD3"));
G4MaterialConstPropertyName.push_back(G4String("PROTONSCINTILLATIONYIELD1"));
G4MaterialConstPropertyName.push_back(G4String("PROTONSCINTILLATIONYIELD2"));
G4MaterialConstPropertyName.push_back(G4String("PROTONSCINTILLATIONYIELD3"));
G4MaterialConstPropertyName.push_back(
G4String("DEUTERONSCINTILLATIONYIELD1"));
G4MaterialConstPropertyName.push_back(
G4String("DEUTERONSCINTILLATIONYIELD2"));
G4MaterialConstPropertyName.push_back(
G4String("DEUTERONSCINTILLATIONYIELD3"));
G4MaterialConstPropertyName.push_back(G4String("TRITONSCINTILLATIONYIELD1"));
G4MaterialConstPropertyName.push_back(G4String("TRITONSCINTILLATIONYIELD2"));
G4MaterialConstPropertyName.push_back(G4String("TRITONSCINTILLATIONYIELD3"));
G4MaterialConstPropertyName.push_back(G4String("ALPHASCINTILLATIONYIELD1"));
G4MaterialConstPropertyName.push_back(G4String("ALPHASCINTILLATIONYIELD2"));
G4MaterialConstPropertyName.push_back(G4String("ALPHASCINTILLATIONYIELD3"));
G4MaterialConstPropertyName.push_back(G4String("IONSCINTILLATIONYIELD1"));
G4MaterialConstPropertyName.push_back(G4String("IONSCINTILLATIONYIELD2"));
G4MaterialConstPropertyName.push_back(G4String("IONSCINTILLATIONYIELD3"));
G4MaterialConstPropertyName.push_back(
G4String("ELECTRONSCINTILLATIONYIELD1"));
G4MaterialConstPropertyName.push_back(
G4String("ELECTRONSCINTILLATIONYIELD2"));
G4MaterialConstPropertyName.push_back(
G4String("ELECTRONSCINTILLATIONYIELD3"));
fMP.assign(kNumberOfPropertyIndex, nullptr);
assert(G4MaterialConstPropertyName.size() == kNumberOfConstPropertyIndex);
fMatConstPropNames.push_back(G4String("SURFACEROUGHNESS"));
fMatConstPropNames.push_back(G4String("ISOTHERMAL_COMPRESSIBILITY"));
fMatConstPropNames.push_back(G4String("RS_SCALE_FACTOR"));
fMatConstPropNames.push_back(G4String("WLSMEANNUMBERPHOTONS"));
fMatConstPropNames.push_back(G4String("WLSTIMECONSTANT"));
fMatConstPropNames.push_back(G4String("WLSMEANNUMBERPHOTONS2"));
fMatConstPropNames.push_back(G4String("WLSTIMECONSTANT2"));
fMatConstPropNames.push_back(G4String("MIEHG_FORWARD"));
fMatConstPropNames.push_back(G4String("MIEHG_BACKWARD"));
fMatConstPropNames.push_back(G4String("MIEHG_FORWARD_RATIO"));
fMatConstPropNames.push_back(G4String("SCINTILLATIONYIELD"));
fMatConstPropNames.push_back(G4String("RESOLUTIONSCALE"));
fMatConstPropNames.push_back(G4String("FERMIPOT"));
fMatConstPropNames.push_back(G4String("DIFFUSION"));
fMatConstPropNames.push_back(G4String("SPINFLIP"));
fMatConstPropNames.push_back(G4String("LOSS"));
fMatConstPropNames.push_back(G4String("LOSSCS"));
fMatConstPropNames.push_back(G4String("ABSCS"));
fMatConstPropNames.push_back(G4String("SCATCS"));
fMatConstPropNames.push_back(G4String("MR_NBTHETA"));
fMatConstPropNames.push_back(G4String("MR_NBE"));
fMatConstPropNames.push_back(G4String("MR_RRMS"));
fMatConstPropNames.push_back(G4String("MR_CORRLEN"));
fMatConstPropNames.push_back(G4String("MR_THETAMIN"));
fMatConstPropNames.push_back(G4String("MR_THETAMAX"));
fMatConstPropNames.push_back(G4String("MR_EMIN"));
fMatConstPropNames.push_back(G4String("MR_EMAX"));
fMatConstPropNames.push_back(G4String("MR_ANGNOTHETA"));
fMatConstPropNames.push_back(G4String("MR_ANGNOPHI"));
fMatConstPropNames.push_back(G4String("MR_ANGCUT"));
fMatConstPropNames.push_back(G4String("SCINTILLATIONTIMECONSTANT1"));
fMatConstPropNames.push_back(G4String("SCINTILLATIONTIMECONSTANT2"));
fMatConstPropNames.push_back(G4String("SCINTILLATIONTIMECONSTANT3"));
fMatConstPropNames.push_back(G4String("SCINTILLATIONRISETIME1"));
fMatConstPropNames.push_back(G4String("SCINTILLATIONRISETIME2"));
fMatConstPropNames.push_back(G4String("SCINTILLATIONRISETIME3"));
fMatConstPropNames.push_back(G4String("SCINTILLATIONYIELD1"));
fMatConstPropNames.push_back(G4String("SCINTILLATIONYIELD2"));
fMatConstPropNames.push_back(G4String("SCINTILLATIONYIELD3"));
fMatConstPropNames.push_back(G4String("PROTONSCINTILLATIONYIELD1"));
fMatConstPropNames.push_back(G4String("PROTONSCINTILLATIONYIELD2"));
fMatConstPropNames.push_back(G4String("PROTONSCINTILLATIONYIELD3"));
fMatConstPropNames.push_back(G4String("DEUTERONSCINTILLATIONYIELD1"));
fMatConstPropNames.push_back(G4String("DEUTERONSCINTILLATIONYIELD2"));
fMatConstPropNames.push_back(G4String("DEUTERONSCINTILLATIONYIELD3"));
fMatConstPropNames.push_back(G4String("TRITONSCINTILLATIONYIELD1"));
fMatConstPropNames.push_back(G4String("TRITONSCINTILLATIONYIELD2"));
fMatConstPropNames.push_back(G4String("TRITONSCINTILLATIONYIELD3"));
fMatConstPropNames.push_back(G4String("ALPHASCINTILLATIONYIELD1"));
fMatConstPropNames.push_back(G4String("ALPHASCINTILLATIONYIELD2"));
fMatConstPropNames.push_back(G4String("ALPHASCINTILLATIONYIELD3"));
fMatConstPropNames.push_back(G4String("IONSCINTILLATIONYIELD1"));
fMatConstPropNames.push_back(G4String("IONSCINTILLATIONYIELD2"));
fMatConstPropNames.push_back(G4String("IONSCINTILLATIONYIELD3"));
fMatConstPropNames.push_back(G4String("ELECTRONSCINTILLATIONYIELD1"));
fMatConstPropNames.push_back(G4String("ELECTRONSCINTILLATIONYIELD2"));
fMatConstPropNames.push_back(G4String("ELECTRONSCINTILLATIONYIELD3"));
assert(fMatConstPropNames.size() == kNumberOfConstPropertyIndex);
fMCP.assign(kNumberOfConstPropertyIndex, { 0., false });
}
G4MaterialPropertiesTable::~G4MaterialPropertiesTable()
{
MPiterator it;
for(it = MP.begin(); it != MP.end(); ++it)
for(auto prop : fMP)
{
delete(*it).second;
delete(prop);
}
MP.clear();
MCP.clear();
G4MaterialPropertyName.clear();
G4MaterialConstPropertyName.clear();
}
G4int G4MaterialPropertiesTable::GetConstPropertyIndex(const G4String& key,
G4bool warning) const
G4int G4MaterialPropertiesTable::GetConstPropertyIndex(
const G4String& key) const
{
// Returns the constant material property index corresponding to a key
size_t index =
std::distance(G4MaterialConstPropertyName.begin(),
std::find(G4MaterialConstPropertyName.begin(),
G4MaterialConstPropertyName.end(), key));
if(index < G4MaterialConstPropertyName.size())
size_t index = std::distance(
fMatConstPropNames.begin(),
std::find(fMatConstPropNames.begin(), fMatConstPropNames.end(), key));
if(index < fMatConstPropNames.size())
return index;
if(warning)
{
G4ExceptionDescription ed;
ed << "Constant Material Property Index for key " << key << " not found.";
G4Exception("G4MaterialPropertiesTable::GetConstPropertyIndex()", "mat206",
JustWarning, ed);
}
return -1;
G4ExceptionDescription ed;
ed << "Constant Material Property Index for key " << key << " not found.";
G4Exception("G4MaterialPropertiesTable::GetConstPropertyIndex()", "mat200",
FatalException, ed);
return 0;
}
G4int G4MaterialPropertiesTable::GetPropertyIndex(const G4String& key,
G4bool warning) const
G4int G4MaterialPropertiesTable::GetPropertyIndex(const G4String& key) const
{
// Returns the material property index corresponding to a key
size_t index = std::distance(G4MaterialPropertyName.begin(),
std::find(G4MaterialPropertyName.begin(),
G4MaterialPropertyName.end(), key));
if(index < G4MaterialPropertyName.size())
size_t index =
std::distance(fMatPropNames.begin(),
std::find(fMatPropNames.begin(), fMatPropNames.end(), key));
if(index < fMatPropNames.size())
return index;
if(warning)
{
G4ExceptionDescription ed;
ed << "Material Property Index for key " << key << " not found.";
G4Exception("G4MaterialPropertiesTable::GetPropertyIndex()", "mat207",
JustWarning, ed);
}
return -1;
G4ExceptionDescription ed;
ed << "Material Property Index for key " << key << " not found.";
G4Exception("G4MaterialPropertiesTable::GetPropertyIndex()", "mat201",
FatalException, ed);
return 0;
}
G4double G4MaterialPropertiesTable::GetConstProperty(const G4int index) const
@@ -213,10 +206,8 @@ G4double G4MaterialPropertiesTable::GetConstProperty(const G4int index) const
// Returns the constant material property corresponding to an index
// fatal exception if property not found
MCPiterator j;
j = MCP.find(index);
if(j != MCP.end())
return j->second;
if(index < (G4int) fMCP.size() && fMCP[index].second == true)
return fMCP[index].first;
G4ExceptionDescription ed;
ed << "Constant Material Property Index " << index << " not found.";
G4Exception("G4MaterialPropertiesTable::GetConstProperty()", "mat202",
@@ -234,82 +225,97 @@ G4double G4MaterialPropertiesTable::GetConstProperty(const G4String& key) const
G4double G4MaterialPropertiesTable::GetConstProperty(const char* key) const
{
return GetConstProperty(G4String(key));
return GetConstProperty(GetConstPropertyIndex(G4String(key)));
}
G4bool G4MaterialPropertiesTable::ConstPropertyExists(const G4int index) const
{
// Returns true if a const property corresponding to 'index' exists
MCPiterator j;
j = MCP.find(index);
if(j != MCP.end())
if(index >= 0 && index < (G4int) fMCP.size() && fMCP[index].second == true)
{
return true;
}
return false;
}
G4bool G4MaterialPropertiesTable::ConstPropertyExists(const G4String& key) const
{
// Returns true if a const property 'key' exists
return ConstPropertyExists(GetConstPropertyIndex(key));
size_t index = std::distance(
fMatConstPropNames.begin(),
std::find(fMatConstPropNames.begin(), fMatConstPropNames.end(), key));
if(index < fMatConstPropNames.size()) // index is type size_t so >= 0
return ConstPropertyExists(index);
return false;
}
G4bool G4MaterialPropertiesTable::ConstPropertyExists(const char* key) const
{
return ConstPropertyExists(G4String(key));
size_t index = std::distance(
fMatConstPropNames.begin(),
std::find(fMatConstPropNames.begin(), fMatConstPropNames.end(), key));
if(index < fMatConstPropNames.size()) // index is type size_t so >= 0
return ConstPropertyExists(index);
return false;
}
G4MaterialPropertyVector* G4MaterialPropertiesTable::GetProperty(
const G4String& key, G4bool warning)
const G4String& key) const
{
// Returns a Material Property Vector corresponding to a key
const G4int index = GetPropertyIndex(key, warning);
return GetProperty(index);
if(std::find(fMatPropNames.begin(), fMatPropNames.end(), key) !=
fMatPropNames.end())
{
const G4int index = GetPropertyIndex(G4String(key));
return GetProperty(index);
}
return nullptr;
}
G4MaterialPropertyVector* G4MaterialPropertiesTable::GetProperty(
const char* key, G4bool warning)
const char* key) const
{
return GetProperty(G4String(key), warning);
if(std::find(fMatPropNames.begin(), fMatPropNames.end(), key) !=
fMatPropNames.end())
{
const G4int index = GetPropertyIndex(G4String(key));
return GetProperty(index);
}
return nullptr;
}
G4MaterialPropertyVector* G4MaterialPropertiesTable::GetProperty(
const G4int index, G4bool warning)
const G4int index) const
{
// Returns a Material Property Vector corresponding to an index
MPiterator i;
i = MP.find(index);
if(i != MP.end())
return i->second;
if(warning)
{
G4ExceptionDescription ed;
ed << "Material Property for index " << index << " not found.";
G4Exception("G4MaterialPropertiesTable::GetPropertyIndex()", "mat208",
JustWarning, ed);
}
// returns nullptr if the property has not been defined by user
if(index >= 0 && index < (G4int) fMP.size())
return fMP[index];
return nullptr;
}
G4MaterialPropertyVector* G4MaterialPropertiesTable::AddProperty(
const G4String& key, const std::vector<G4double>& photonEnergies,
const std::vector<G4double>& propertyValues, G4bool createNewKey)
const std::vector<G4double>& propertyValues, G4bool createNewKey,
G4bool spline)
{
if(photonEnergies.size() != propertyValues.size())
{
G4ExceptionDescription ed;
ed << "AddProperty error!";
G4Exception("G4MaterialPropertiesTable::AddProperty()", "mat210",
G4Exception("G4MaterialPropertiesTable::AddProperty()", "mat204",
FatalException, ed);
}
// if the key doesn't exist, add it if requested
if(std::find(G4MaterialPropertyName.begin(), G4MaterialPropertyName.end(),
key) == G4MaterialPropertyName.end())
if(std::find(fMatPropNames.begin(), fMatPropNames.end(), key) ==
fMatPropNames.end())
{
if(createNewKey)
{
G4MaterialPropertyName.push_back(key);
fMatPropNames.push_back(key);
fMP.push_back(nullptr);
}
else
{
@@ -317,15 +323,19 @@ G4MaterialPropertyVector* G4MaterialPropertiesTable::AddProperty(
ed << "Attempting to create a new material property key " << key
<< " without setting\n"
<< "createNewKey parameter of AddProperty to true.";
G4Exception("G4MaterialPropertiesTable::AddProperty()", "mat220",
G4Exception("G4MaterialPropertiesTable::AddProperty()", "mat205",
FatalException, ed);
}
}
G4MaterialPropertyVector* mpv =
new G4MaterialPropertyVector(photonEnergies, propertyValues);
new G4MaterialPropertyVector(photonEnergies, propertyValues, spline);
if(spline)
{
mpv->FillSecondDerivatives();
}
G4int index = GetPropertyIndex(key);
MP[index] = mpv;
fMP[index] = mpv;
// if key is RINDEX, we calculate GROUPVEL -
// contribution from Tao Lin (IHEP, the JUNO experiment)
@@ -338,20 +348,16 @@ G4MaterialPropertyVector* G4MaterialPropertiesTable::AddProperty(
}
G4MaterialPropertyVector* G4MaterialPropertiesTable::AddProperty(
const char* key, G4double* PhotonEnergies, G4double* PropertyValues,
G4int NumEntries, G4bool createNewKey)
const char* key, G4double* photonEnergies, G4double* propertyValues,
G4int numEntries, G4bool createNewKey, G4bool spline)
{
// Provides a way of adding a property to the Material Properties
// Table given a pair of numbers and a key
// Table given a pair of arrays and a key
G4String k(key);
std::vector<G4double> energies;
std::vector<G4double> values;
for(G4int i = 0; i < NumEntries; ++i)
{
energies.push_back(PhotonEnergies[i]);
values.push_back(PropertyValues[i]);
}
return AddProperty(k, energies, values, createNewKey);
std::vector<G4double> energies(photonEnergies, photonEnergies + numEntries);
std::vector<G4double> values(propertyValues, propertyValues + numEntries);
return AddProperty(k, energies, values, createNewKey, spline);
}
void G4MaterialPropertiesTable::AddProperty(const G4String& key,
@@ -361,12 +367,13 @@ void G4MaterialPropertiesTable::AddProperty(const G4String& key,
// Provides a way of adding a property to the Material Properties
// Table given an G4MaterialPropertyVector Reference and a key
// if the key doesn't exist, add it
if(std::find(G4MaterialPropertyName.begin(), G4MaterialPropertyName.end(),
key) == G4MaterialPropertyName.end())
if(std::find(fMatPropNames.begin(), fMatPropNames.end(), key) ==
fMatPropNames.end())
{
if(createNewKey)
{
G4MaterialPropertyName.push_back(key);
fMatPropNames.push_back(key);
fMP.push_back(nullptr);
}
else
{
@@ -374,12 +381,12 @@ void G4MaterialPropertiesTable::AddProperty(const G4String& key,
ed << "Attempting to create a new material property key " << key
<< " without setting\n"
<< "createNewKey parameter of AddProperty to true.";
G4Exception("G4MaterialPropertiesTable::AddProperty()", "mat221",
G4Exception("G4MaterialPropertiesTable::AddProperty()", "mat206",
FatalException, ed);
}
}
G4int index = GetPropertyIndex(key);
MP[index] = mpv;
fMP[index] = mpv;
// if key is RINDEX, we calculate GROUPVEL -
// contribution from Tao Lin (IHEP, the JUNO experiment)
@@ -399,24 +406,25 @@ void G4MaterialPropertiesTable::AddProperty(const char* key,
void G4MaterialPropertiesTable::AddProperty(const G4String& key,
const G4String& mat)
{
// load a material property vector defined in Geant4 source
G4MaterialPropertyVector* v =
G4OpticalMaterialProperties::GetProperty(key, mat);
AddProperty(key, v);
}
void G4MaterialPropertiesTable::AddConstProperty(const G4String& key,
G4double PropertyValue,
G4double propertyValue,
G4bool createNewKey)
{
// Provides a way of adding a constant property to the Material Properties
// Table given a key
if(std::find(G4MaterialConstPropertyName.begin(),
G4MaterialConstPropertyName.end(),
key) == G4MaterialConstPropertyName.end())
if(std::find(fMatConstPropNames.begin(), fMatConstPropNames.end(), key) ==
fMatConstPropNames.end())
{
if(createNewKey)
{
G4MaterialPropertyName.push_back(key);
fMatConstPropNames.push_back(key);
fMCP.push_back(std::pair<G4double, G4bool>{ 0., true });
}
else
{
@@ -424,40 +432,41 @@ void G4MaterialPropertiesTable::AddConstProperty(const G4String& key,
ed << "Attempting to create a new material constant property key " << key
<< " without setting"
<< " createNewKey parameter of AddProperty to true.";
G4Exception("G4MaterialPropertiesTable::AddProperty()", "mat222",
G4Exception("G4MaterialPropertiesTable::AddProperty()", "mat207",
FatalException, ed);
}
}
G4int index = GetConstPropertyIndex(key);
MCP[index] = PropertyValue;
fMCP[index] = std::pair<G4double, G4bool>{ propertyValue, true };
}
void G4MaterialPropertiesTable::AddConstProperty(const char* key,
G4double PropertyValue,
G4double propertyValue,
G4bool createNewKey)
{
// Provides a way of adding a constant property to the Material Properties
// Table given a key
AddConstProperty(G4String(key), PropertyValue, createNewKey);
AddConstProperty(G4String(key), propertyValue, createNewKey);
}
void G4MaterialPropertiesTable::RemoveConstProperty(const G4String& key)
{
G4int index = GetConstPropertyIndex(key);
MCP.erase(index);
if(index < (G4int) fMCP.size())
fMCP[index] = std::pair<G4double, G4bool>{ 0., false };
}
void G4MaterialPropertiesTable::RemoveConstProperty(const char* key)
{
GetConstPropertyIndex(G4String(key));
RemoveConstProperty(G4String(key));
}
void G4MaterialPropertiesTable::RemoveProperty(const G4String& key)
{
G4int index = GetPropertyIndex(key);
MP.erase(index);
delete fMP[index];
fMP[index] = nullptr;
}
void G4MaterialPropertiesTable::RemoveProperty(const char* key)
@@ -471,21 +480,22 @@ void G4MaterialPropertiesTable::AddEntry(const G4String& key,
{
// Allows to add an entry pair directly to the Material Property Vector
// given a key
if(std::find(G4MaterialPropertyName.begin(), G4MaterialPropertyName.end(),
key) == G4MaterialPropertyName.end())
if(std::find(fMatPropNames.begin(), fMatPropNames.end(), key) ==
fMatPropNames.end())
{
G4MaterialPropertyName.push_back(key);
G4Exception("G4MaterialPropertiesTable::AddEntry()", "mat214",
FatalException, "Material Property Vector not found.");
}
G4int index = GetPropertyIndex(key);
G4MaterialPropertyVector* targetVector = MP[index];
G4MaterialPropertyVector* targetVector = fMP[index];
if(targetVector != nullptr)
{
targetVector->InsertValues(aPhotonEnergy, aPropertyValue);
}
else
{
G4Exception("G4MaterialPropertiesTable::AddEntry()", "mat203",
G4Exception("G4MaterialPropertiesTable::AddEntry()", "mat208",
FatalException, "Material Property Vector not found.");
}
if(key == "RINDEX")
@@ -501,50 +511,32 @@ void G4MaterialPropertiesTable::AddEntry(const char* key,
AddEntry(G4String(key), aPhotonEnergy, aPropertyValue);
}
void G4MaterialPropertiesTable::DumpTable()
void G4MaterialPropertiesTable::DumpTable() const
{
// material properties
MPiterator i;
for(i = MP.begin(); i != MP.end(); ++i)
G4int j = 0;
for(const auto& prop : fMP)
{
G4cout << (*i).first << ": " << G4MaterialPropertyName[(*i).first]
<< G4endl;
if((*i).second != nullptr)
if(prop != nullptr)
{
(*i).second->DumpValues();
}
else
{
G4Exception("G4MaterialPropertiesTable::DumpTable()", "mat204",
JustWarning, "NULL Material Property Vector Pointer.");
G4cout << j << ": " << fMatPropNames[j] << G4endl;
prop->DumpValues();
}
++j;
}
// material constant properties
MCPiterator j;
for(j = MCP.begin(); j != MCP.end(); ++j)
j = 0;
for(const auto& cprop : fMCP)
{
G4cout << j->first << ": " << G4MaterialConstPropertyName[j->first]
<< G4endl;
if(j->second != 0.)
if(cprop.second == true)
{
G4cout << j->second << G4endl;
}
else
{
G4Exception("G4MaterialPropertiesTable::DumpTable()", "mat202",
JustWarning, "No Material Constant Property.");
G4cout << j << ": " << fMatConstPropNames[j] << " " << cprop.first
<< G4endl;
}
++j;
}
}
#ifdef G4MULTITHREADED
# include "G4AutoLock.hh"
namespace
{
G4Mutex materialPropertyTableMutex = G4MUTEX_INITIALIZER;
}
#endif
G4MaterialPropertyVector* G4MaterialPropertiesTable::CalculateGROUPVEL()
{
#ifdef G4MULTITHREADED
@@ -552,10 +544,10 @@ G4MaterialPropertyVector* G4MaterialPropertiesTable::CalculateGROUPVEL()
#endif
// check if "GROUPVEL" already exists. If so, remove it.
MPiterator itr;
itr = MP.find(kGROUPVEL);
if(itr != MP.end())
if(fMP[kGROUPVEL] != nullptr)
{
this->RemoveProperty("GROUPVEL");
}
// fetch RINDEX data, give up if unavailable
G4MaterialPropertyVector* rindex = this->GetProperty(kRINDEX);
@@ -580,7 +572,7 @@ G4MaterialPropertyVector* G4MaterialPropertiesTable::CalculateGROUPVEL()
if(E0 <= 0.)
{
G4Exception("G4MaterialPropertiesTable::CalculateGROUPVEL()", "mat205",
G4Exception("G4MaterialPropertiesTable::CalculateGROUPVEL()", "mat211",
FatalException, "Optical Photon Energy <= 0");
}
@@ -594,7 +586,7 @@ G4MaterialPropertyVector* G4MaterialPropertiesTable::CalculateGROUPVEL()
if(E1 <= 0.)
{
G4Exception("G4MaterialPropertiesTable::CalculateGROUPVEL()", "mat205",
G4Exception("G4MaterialPropertiesTable::CalculateGROUPVEL()", "mat212",
FatalException, "Optical Photon Energy <= 0");
}
@@ -631,7 +623,7 @@ G4MaterialPropertyVector* G4MaterialPropertiesTable::CalculateGROUPVEL()
if(E1 <= 0.)
{
G4Exception("G4MaterialPropertiesTable::CalculateGROUPVEL()", "mat205",
G4Exception("G4MaterialPropertiesTable::CalculateGROUPVEL()", "mat213",
FatalException, "Optical Photon Energy <= 0");
}
}
@@ -655,15 +647,3 @@ G4MaterialPropertyVector* G4MaterialPropertiesTable::CalculateGROUPVEL()
return groupvel;
}
std::vector<G4String> G4MaterialPropertiesTable::GetMaterialPropertyNames()
const
{
return G4MaterialPropertyName;
}
std::vector<G4String> G4MaterialPropertiesTable::GetMaterialConstPropertyNames()
const
{
return G4MaterialConstPropertyName;
}
@@ -102,7 +102,7 @@ void G4MicroElecMaterialStructure::ReadMaterialFile()
{
char *path = std::getenv("G4LEDATA");
if (materialName(0) == 'G' && materialName(1) == '4') {
if (materialName[0] == 'G' && materialName[1] == '4') {
//in the case the NIST database is used
materialName.erase(0, 1);
materialName.erase(0, 1);
@@ -133,7 +133,7 @@ void G4MicroElecMaterialStructure::ReadMaterialFile()
getline(fichier, filler);
std::stringstream line(filler);
if (filler(0) == '#' || filler.empty()) {continue;}
if (filler[0] == '#' || filler.empty()) {continue;}
line >> varLength;
line >> nameParameter;