Geant4 Cross Reference |
1 // 1 2 // ******************************************* 3 // * License and Disclaimer 4 // * 5 // * The Geant4 software is copyright of th 6 // * the Geant4 Collaboration. It is provided 7 // * conditions of the Geant4 Software License 8 // * LICENSE and available at http://cern.ch/ 9 // * include a list of copyright holders. 10 // * 11 // * Neither the authors of this software syst 12 // * institutes,nor the agencies providing fin 13 // * work make any representation or warran 14 // * regarding this software system or assum 15 // * use. Please see the license in the file 16 // * for the full disclaimer and the limitatio 17 // * 18 // * This code implementation is the result 19 // * technical work of the GEANT4 collaboratio 20 // * By using, copying, modifying or distri 21 // * any work based on the software) you ag 22 // * use in resulting scientific publicati 23 // * acceptance of all terms of the Geant4 Sof 24 // ******************************************* 25 // 26 // G4GDMLWriteMaterials implementation 27 // 28 // Author: Zoltan Torzsok, November 2007 29 // ------------------------------------------- 30 31 #include <sstream> 32 33 #include "G4GDMLWriteMaterials.hh" 34 35 #include "G4PhysicalConstants.hh" 36 #include "G4SystemOfUnits.hh" 37 #include "G4Element.hh" 38 #include "G4Isotope.hh" 39 #include "G4Material.hh" 40 41 // ------------------------------------------- 42 G4GDMLWriteMaterials::G4GDMLWriteMaterials() 43 : G4GDMLWriteDefine() 44 { 45 } 46 47 // ------------------------------------------- 48 G4GDMLWriteMaterials::~G4GDMLWriteMaterials() 49 { 50 } 51 52 // ------------------------------------------- 53 void G4GDMLWriteMaterials::AtomWrite(xercesc:: 54 const G4d 55 { 56 xercesc::DOMElement* atomElement = NewElemen 57 atomElement->setAttributeNode(NewAttribute(" 58 atomElement->setAttributeNode(NewAttribute(" 59 element->appendChild(atomElement); 60 } 61 62 // ------------------------------------------- 63 void G4GDMLWriteMaterials::DWrite(xercesc::DOM 64 const G4doub 65 { 66 xercesc::DOMElement* DElement = NewElement(" 67 DElement->setAttributeNode(NewAttribute("uni 68 DElement->setAttributeNode(NewAttribute("val 69 element->appendChild(DElement); 70 } 71 72 // ------------------------------------------- 73 void G4GDMLWriteMaterials::PWrite(xercesc::DOM 74 const G4doub 75 { 76 xercesc::DOMElement* PElement = NewElement(" 77 PElement->setAttributeNode(NewAttribute("uni 78 PElement->setAttributeNode(NewAttribute("val 79 element->appendChild(PElement); 80 } 81 82 // ------------------------------------------- 83 void G4GDMLWriteMaterials::TWrite(xercesc::DOM 84 const G4doub 85 { 86 xercesc::DOMElement* TElement = NewElement(" 87 TElement->setAttributeNode(NewAttribute("uni 88 TElement->setAttributeNode(NewAttribute("val 89 element->appendChild(TElement); 90 } 91 92 // ------------------------------------------- 93 void G4GDMLWriteMaterials::MEEWrite(xercesc::D 94 const G4do 95 { 96 xercesc::DOMElement* PElement = NewElement(" 97 PElement->setAttributeNode(NewAttribute("uni 98 PElement->setAttributeNode(NewAttribute("val 99 element->appendChild(PElement); 100 } 101 102 // ------------------------------------------- 103 void G4GDMLWriteMaterials::IsotopeWrite(const 104 { 105 const G4String name = GenerateName(isotopePt 106 107 xercesc::DOMElement* isotopeElement = NewEle 108 isotopeElement->setAttributeNode(NewAttribut 109 isotopeElement->setAttributeNode(NewAttribut 110 isotopeElement->setAttributeNode(NewAttribut 111 materialsElement->appendChild(isotopeElement 112 AtomWrite(isotopeElement, isotopePtr->GetA() 113 } 114 115 // ------------------------------------------- 116 void G4GDMLWriteMaterials::ElementWrite(const 117 { 118 const G4String name = GenerateName(elementPt 119 120 xercesc::DOMElement* elementElement = NewEle 121 elementElement->setAttributeNode(NewAttribut 122 123 const G4int NumberOfIsotopes = (G4int)elemen 124 125 if(NumberOfIsotopes > 0) 126 { 127 const G4double* RelativeAbundanceVector 128 = elementPtr->GetRelativeAbundanceVector 129 for(G4int i = 0; i < NumberOfIsotopes; ++i 130 { 131 G4String fractionref = GenerateName(elem 132 elem 133 xercesc::DOMElement* fractionElement = N 134 fractionElement->setAttributeNode( 135 NewAttribute("n", RelativeAbundanceVec 136 fractionElement->setAttributeNode(NewAtt 137 elementElement->appendChild(fractionElem 138 AddIsotope(elementPtr->GetIsotope(i)); 139 } 140 } 141 else 142 { 143 elementElement->setAttributeNode(NewAttrib 144 AtomWrite(elementElement, elementPtr->GetA 145 } 146 147 materialsElement->appendChild(elementElement 148 // Append the element AFTER all the possible 149 } 150 151 // ------------------------------------------- 152 void G4GDMLWriteMaterials::MaterialWrite(const 153 { 154 G4String state_str("undefined"); 155 const G4State state = materialPtr->GetState( 156 if(state == kStateSolid) 157 { 158 state_str = "solid"; 159 } 160 else if(state == kStateLiquid) 161 { 162 state_str = "liquid"; 163 } 164 else if(state == kStateGas) 165 { 166 state_str = "gas"; 167 } 168 169 const G4String name = GenerateName(materialP 170 171 xercesc::DOMElement* materialElement = NewEl 172 materialElement->setAttributeNode(NewAttribu 173 materialElement->setAttributeNode(NewAttribu 174 175 // Write any property attached to the materi 176 // 177 if(materialPtr->GetMaterialPropertiesTable() 178 { 179 PropertyWrite(materialElement, materialPtr 180 } 181 182 if(materialPtr->GetTemperature() != STP_Temp 183 { 184 TWrite(materialElement, materialPtr->GetTe 185 } 186 187 if(materialPtr->GetPressure() != STP_Pressur 188 { 189 PWrite(materialElement, materialPtr->GetPr 190 } 191 192 // Write Ionisation potential (mean excitati 193 MEEWrite(materialElement, 194 materialPtr->GetIonisation()->GetMe 195 196 DWrite(materialElement, materialPtr->GetDens 197 198 const G4int NumberOfElements = (G4int)materi 199 200 if((NumberOfElements > 1) || 201 (materialPtr->GetElement(0) != nullptr && 202 materialPtr->GetElement(0)->GetNumberOfI 203 { 204 const G4double* MassFractionVector = mater 205 206 for(G4int i = 0; i < NumberOfElements; ++i 207 { 208 const G4String fractionref = GenerateNam 209 materialPtr->GetElement(i)->GetName(), 210 xercesc::DOMElement* fractionElement = N 211 fractionElement->setAttributeNode( 212 NewAttribute("n", MassFractionVector[i 213 fractionElement->setAttributeNode(NewAtt 214 materialElement->appendChild(fractionEle 215 AddElement(materialPtr->GetElement(i)); 216 } 217 } 218 else 219 { 220 materialElement->setAttributeNode(NewAttri 221 AtomWrite(materialElement, materialPtr->Ge 222 } 223 224 // Append the material AFTER all the possibl 225 // 226 materialsElement->appendChild(materialElemen 227 } 228 229 // ------------------------------------------- 230 void G4GDMLWriteMaterials::PropertyVectorWrite 231 const G4String& key, const G4PhysicsFreeVect 232 { 233 for(std::size_t i = 0; i < propertyList.size 234 { 235 if(propertyList[i] == pvec) 236 { 237 return; 238 } 239 } 240 propertyList.push_back(pvec); 241 242 const G4String matrixref = GenerateName(key, 243 xercesc::DOMElement* matrixElement = NewElem 244 matrixElement->setAttributeNode(NewAttribute 245 matrixElement->setAttributeNode(NewAttribute 246 std::ostringstream pvalues; 247 for(std::size_t i = 0; i < pvec->GetVectorLe 248 { 249 if(i != 0) 250 { 251 pvalues << " "; 252 } 253 pvalues << pvec->Energy(i) << " " << (*pve 254 } 255 matrixElement->setAttributeNode(NewAttribute 256 257 defineElement->appendChild(matrixElement); 258 } 259 260 // ------------------------------------------- 261 void G4GDMLWriteMaterials::PropertyConstWrite( 262 const G4String& key, const G4double pval, 263 const G4MaterialPropertiesTable* ptable) 264 { 265 const G4String matrixref = Generat 266 xercesc::DOMElement* matrixElement = NewElem 267 matrixElement->setAttributeNode(NewAttribute 268 matrixElement->setAttributeNode(NewAttribute 269 std::ostringstream pvalues; 270 271 pvalues << pval; 272 matrixElement->setAttributeNode(NewAttribute 273 274 defineElement->appendChild(matrixElement); 275 } 276 277 // ------------------------------------------- 278 void G4GDMLWriteMaterials::PropertyWrite(xerce 279 const 280 { 281 xercesc::DOMElement* propElement; 282 G4MaterialPropertiesTable* ptable = mat->Get 283 284 auto pvec = ptable->GetProperties(); 285 auto cvec = ptable->GetConstProperties(); 286 287 for(size_t i = 0; i < pvec.size(); ++i) 288 { 289 if (pvec[i] != nullptr) 290 { 291 propElement = NewElement("property"); 292 propElement->setAttributeNode( 293 NewAttribute("name", ptable->GetMateri 294 propElement->setAttributeNode(NewAttribu 295 "ref", GenerateName(ptable->GetMateria 296 pvec[i]))); 297 PropertyVectorWrite(ptable->GetMaterialP 298 pvec[i]); 299 matElement->appendChild(propElement); 300 } 301 } 302 303 for(size_t i = 0; i < cvec.size(); ++i) 304 { 305 if (cvec[i].second == true) 306 { 307 propElement = NewElement("property"); 308 propElement->setAttributeNode(NewAttribu 309 "name", ptable->GetMaterialConstProper 310 propElement->setAttributeNode(NewAttribu 311 "ref", GenerateName(ptable->GetMateria 312 ptable))); 313 PropertyConstWrite(ptable->GetMaterialCo 314 cvec[i].first, ptable 315 matElement->appendChild(propElement); 316 } 317 } 318 } 319 320 // ------------------------------------------- 321 void G4GDMLWriteMaterials::MaterialsWrite(xerc 322 { 323 #ifdef G4VERBOSE 324 G4cout << "G4GDML: Writing materials..." << 325 #endif 326 materialsElement = NewElement("materials"); 327 element->appendChild(materialsElement); 328 329 isotopeList.clear(); 330 elementList.clear(); 331 materialList.clear(); 332 propertyList.clear(); 333 } 334 335 // ------------------------------------------- 336 void G4GDMLWriteMaterials::AddIsotope(const G4 337 { 338 for(std::size_t i = 0; i < isotopeList.size( 339 { 340 if(isotopeList[i] == isotopePtr) 341 { 342 return; 343 } 344 } 345 isotopeList.push_back(isotopePtr); 346 IsotopeWrite(isotopePtr); 347 } 348 349 // ------------------------------------------- 350 void G4GDMLWriteMaterials::AddElement(const G4 351 { 352 for(std::size_t i = 0; i < elementList.size( 353 { 354 if(elementList[i] == elementPtr) 355 { 356 return; 357 } 358 } 359 elementList.push_back(elementPtr); 360 ElementWrite(elementPtr); 361 } 362 363 // ------------------------------------------- 364 void G4GDMLWriteMaterials::AddMaterial(const G 365 { 366 for(std::size_t i = 0; i < materialList.size 367 { 368 if(materialList[i] == materialPtr) 369 { 370 return; 371 } 372 } 373 materialList.push_back(materialPtr); 374 MaterialWrite(materialPtr); 375 } 376