37 #include <Geant4/G4PhysicalConstants.hh>
38 #include <Geant4/G4SystemOfUnits.hh>
39 #include <Geant4/G4Element.hh>
40 #include <Geant4/G4Isotope.hh>
41 #include <Geant4/G4Material.hh>
56 AtomWrite(xercesc::DOMElement* element,
const G4double& a)
58 xercesc::DOMElement* atomElement =
NewElement(
"atom");
59 atomElement->setAttributeNode(
NewAttribute(
"unit",
"g/mole"));
60 atomElement->setAttributeNode(
NewAttribute(
"value",a*mole/
g));
61 element->appendChild(atomElement);
65 DWrite(xercesc::DOMElement* element,
const G4double&
d)
67 xercesc::DOMElement* DElement =
NewElement(
"D");
68 DElement->setAttributeNode(
NewAttribute(
"unit",
"g/cm3"));
70 element->appendChild(DElement);
74 PWrite(xercesc::DOMElement* element,
const G4double& P)
76 xercesc::DOMElement* PElement =
NewElement(
"P");
77 PElement->setAttributeNode(
NewAttribute(
"unit",
"pascal"));
78 PElement->setAttributeNode(
NewAttribute(
"value",P/hep_pascal));
79 element->appendChild(PElement);
83 TWrite(xercesc::DOMElement* element,
const G4double&
T)
85 xercesc::DOMElement* TElement =
NewElement(
"T");
87 TElement->setAttributeNode(
NewAttribute(
"value",T/kelvin));
88 element->appendChild(TElement);
92 MEEWrite(xercesc::DOMElement* element,
const G4double& MEE)
94 xercesc::DOMElement* PElement =
NewElement(
"MEE");
96 PElement->setAttributeNode(
NewAttribute(
"value",MEE/electronvolt));
97 element->appendChild(PElement);
105 xercesc::DOMElement* isotopeElement =
NewElement(
"isotope");
106 isotopeElement->setAttributeNode(
NewAttribute(
"name",name));
107 isotopeElement->setAttributeNode(
NewAttribute(
"N",isotopePtr->GetN()));
108 isotopeElement->setAttributeNode(
NewAttribute(
"Z",isotopePtr->GetZ()));
110 AtomWrite(isotopeElement,isotopePtr->GetA());
117 xercesc::DOMElement* elementElement =
NewElement(
"element");
118 elementElement->setAttributeNode(
NewAttribute(
"name",name));
120 const size_t NumberOfIsotopes = elementPtr->GetNumberOfIsotopes();
122 if (NumberOfIsotopes>0)
124 const G4double* RelativeAbundanceVector =
125 elementPtr->GetRelativeAbundanceVector();
126 for (
size_t i=0;i<NumberOfIsotopes;i++)
128 G4String fractionref =
GenerateName(elementPtr->GetIsotope(i)->GetName(),
129 elementPtr->GetIsotope(i));
130 xercesc::DOMElement* fractionElement =
NewElement(
"fraction");
132 RelativeAbundanceVector[i]));
133 fractionElement->setAttributeNode(
NewAttribute(
"ref",fractionref));
134 elementElement->appendChild(fractionElement);
140 elementElement->setAttributeNode(
NewAttribute(
"Z",elementPtr->GetZ()));
141 AtomWrite(elementElement,elementPtr->GetA());
150 G4String state_str(
"undefined");
151 const G4State state = materialPtr->GetState();
152 if (state==kStateSolid) { state_str =
"solid"; }
else
153 if (state==kStateLiquid) { state_str =
"liquid"; }
else
154 if (state==kStateGas) { state_str =
"gas"; }
158 xercesc::DOMElement* materialElement =
NewElement(
"material");
159 materialElement->setAttributeNode(
NewAttribute(
"name",name));
160 materialElement->setAttributeNode(
NewAttribute(
"state",state_str));
164 if (materialPtr->GetMaterialPropertiesTable())
169 if (materialPtr->GetTemperature() != STP_Temperature)
170 {
TWrite(materialElement,materialPtr->GetTemperature()); }
171 if (materialPtr->GetPressure() != STP_Pressure)
172 {
PWrite(materialElement,materialPtr->GetPressure()); }
175 MEEWrite(materialElement,materialPtr->GetIonisation()->GetMeanExcitationEnergy());
177 DWrite(materialElement,materialPtr->GetDensity());
179 const size_t NumberOfElements = materialPtr->GetNumberOfElements();
181 if ( (NumberOfElements>1)
182 || ( materialPtr->GetElement(0)
183 && materialPtr->GetElement(0)->GetNumberOfIsotopes()>1 ) )
185 const G4double* MassFractionVector = materialPtr->GetFractionVector();
187 for (
size_t i=0;i<NumberOfElements;i++)
189 const G4String fractionref =
191 materialPtr->GetElement(i));
192 xercesc::DOMElement* fractionElement =
NewElement(
"fraction");
194 MassFractionVector[i]));
195 fractionElement->setAttributeNode(
NewAttribute(
"ref",fractionref));
196 materialElement->appendChild(fractionElement);
202 materialElement->setAttributeNode(
NewAttribute(
"Z",materialPtr->GetZ()));
203 AtomWrite(materialElement,materialPtr->GetA());
212 const G4PhysicsOrderedFreeVector*
const pvec)
215 xercesc::DOMElement* matrixElement =
NewElement(
"matrix");
216 matrixElement->setAttributeNode(
NewAttribute(
"name", matrixref));
217 matrixElement->setAttributeNode(
NewAttribute(
"coldim",
"2"));
218 std::ostringstream pvalues;
219 for (
size_t i=0; i<pvec->GetVectorLength(); i++)
221 if (i!=0) { pvalues <<
" "; }
222 pvalues << pvec->Energy(i) <<
" " << (*pvec)[i];
224 matrixElement->setAttributeNode(
NewAttribute(
"values", pvalues.str()));
230 const G4Material*
const mat)
232 xercesc::DOMElement* propElement;
233 G4MaterialPropertiesTable* ptable = mat->GetMaterialPropertiesTable();
235 const std::map< G4int, G4PhysicsOrderedFreeVector*,
236 std::less<G4int> >* pmap = ptable->GetPropertyMap();
237 const std::map< G4int, G4double,
238 std::less<G4int> >* cmap = ptable->GetConstPropertyMap();
239 std::map< G4int, G4PhysicsOrderedFreeVector*,
240 std::less<G4int> >::const_iterator mpos;
241 std::map< G4int, G4double,
242 std::less<G4int> >::const_iterator cpos;
245 for (mpos=pmap->begin(); mpos!=pmap->end(); mpos++)
249 ptable->GetMaterialPropertyNames()[mpos->first]));
251 GenerateName(ptable->GetMaterialPropertyNames()[mpos->first],
257 matElement->appendChild(propElement);
261 G4String warn_message =
"Null pointer for material property -"
262 + ptable->GetMaterialPropertyNames()[mpos->first] +
"- of material -"
263 + mat->GetName() +
"- !";
264 G4Exception(
"G4GDMLWriteMaterials::PropertyWrite()",
"NullPointer",
265 JustWarning, warn_message);
270 for (cpos=cmap->begin(); cpos!=cmap->end(); cpos++)
274 ptable->GetMaterialConstPropertyNames()[cpos->first]));
276 ptable->GetMaterialConstPropertyNames()[cpos->first]));
277 xercesc::DOMElement* constElement =
NewElement(
"constant");
279 ptable->GetMaterialConstPropertyNames()[cpos->first]));
280 constElement->setAttributeNode(
NewAttribute(
"value", cpos->second));
282 matElement->appendChild(propElement);
288 std::cout <<
"G4GDML: Writing materials..." << std::endl;