00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036 #include "G4tgbMaterialMixtureByVolume.hh"
00037
00038 #include "G4SystemOfUnits.hh"
00039 #include "G4tgbMaterial.hh"
00040 #include "G4tgbMaterialMgr.hh"
00041 #include "G4tgrMessenger.hh"
00042
00043
00044 G4tgbMaterialMixtureByVolume::G4tgbMaterialMixtureByVolume()
00045 {
00046 }
00047
00048
00049
00050 G4tgbMaterialMixtureByVolume::~G4tgbMaterialMixtureByVolume()
00051 {
00052 }
00053
00054
00055
00056 G4tgbMaterialMixtureByVolume::G4tgbMaterialMixtureByVolume( G4tgrMaterial* hg )
00057 {
00058 theTgrMate = hg;
00059 }
00060
00061
00062
00063 G4Material* G4tgbMaterialMixtureByVolume::BuildG4Material()
00064 {
00065
00066
00067 G4Material* mate = new G4Material( theTgrMate->GetName(),
00068 theTgrMate->GetDensity(),
00069 theTgrMate->GetNumberOfComponents(),
00070 theTgrMate->GetState(),
00071 theTgrMate->GetTemperature(),
00072 theTgrMate->GetPressure() );
00073 #ifdef G4VERBOSE
00074 if( G4tgrMessenger::GetVerboseLevel() >= 2 )
00075 {
00076 G4cout << " G4tgbMaterialMixtureByVolume::buildG4Material() -"
00077 << " Constructing new G4Material:"
00078 << " " << theTgrMate->GetName()
00079 << " " << theTgrMate->GetDensity()/g*cm3
00080 << " " << theTgrMate->GetNumberOfComponents()
00081 << " " << theTgrMate->GetState()
00082 << " " << theTgrMate->GetTemperature()
00083 << " " << theTgrMate->GetPressure() << G4endl;
00084 }
00085 #endif
00086
00087
00088 TransformToFractionsByWeight();
00089
00090
00091 G4Material* compMate = 0;
00092 G4tgbMaterialMgr* mf = G4tgbMaterialMgr::GetInstance();
00093 for( G4int ii = 0; ii < theTgrMate->GetNumberOfComponents(); ii++)
00094 {
00095
00096 compMate = mf->FindOrBuildG4Material( GetComponent(ii) );
00097 if( compMate != 0 )
00098 {
00099
00100 mate->AddMaterial( compMate, theFractionsByWeight[ii] );
00101 }
00102 else
00103 {
00104 G4String ErrMessage = "Component " + GetComponent(ii)
00105 + " of material " + theTgrMate->GetName()
00106 + "\n" + "is not an element nor a material !";
00107 G4Exception("G4tgbMaterialMixtureByVolume::BuildG4Material()",
00108 "InvalidSetup", FatalException, ErrMessage);
00109 }
00110 }
00111
00112 #ifdef G4VERBOSE
00113 if( G4tgrMessenger::GetVerboseLevel() >= 1 )
00114 {
00115 G4cout << " Constructing new G4Material by volume: " << *mate << G4endl;
00116 }
00117 #endif
00118
00119 return mate;
00120 }
00121
00122
00123
00124 void G4tgbMaterialMixtureByVolume::TransformToFractionsByWeight()
00125 {
00126 G4tgbMaterialMgr* mf = G4tgbMaterialMgr::GetInstance();
00127 G4Material* compMate = 0;
00128 G4double totalfd = 0.;
00129 for( G4int ii = 0; ii < theTgrMate->GetNumberOfComponents(); ii++ )
00130 {
00131 compMate = mf->FindOrBuildG4Material( GetComponent(ii) );
00132 if( compMate != 0 )
00133 {
00134
00135 theFractionsByWeight.push_back( GetFraction(ii)*compMate->GetDensity() );
00136 totalfd += theFractionsByWeight[ii];
00137 }
00138 else
00139 {
00140 G4String ErrMessage = "Component " + GetComponent(ii)
00141 + " of material " + theTgrMate->GetName()
00142 + "\n" + "is not a material !";
00143 G4Exception("G4tgbMaterialMixtureByVolume::BuildG4Material()",
00144 "InvalidSetup", FatalException, ErrMessage);
00145 }
00146 }
00147 for( G4int ii = 0; ii < theTgrMate->GetNumberOfComponents(); ii++ )
00148 {
00149 theFractionsByWeight[ii] /= totalfd;
00150 #ifdef G4VERBOSE
00151 if( G4tgrMessenger::GetVerboseLevel() >= 2 )
00152 {
00153 G4cout << " G4tgbMaterialMixtureByVolume::TransformToFractionsByWeight()"
00154 << " Component " << ii << " : "
00155 << mf->FindOrBuildG4Material( GetComponent(ii) )->GetName()
00156 << " FractionByVolume= " << GetFraction(ii)
00157 << " FractionByWeight= " << theFractionsByWeight[ii]
00158 << G4endl;
00159 }
00160 #endif
00161 }
00162 }