[987] | 1 | // |
---|
| 2 | // ******************************************************************** |
---|
| 3 | // * License and Disclaimer * |
---|
| 4 | // * * |
---|
| 5 | // * The Geant4 software is copyright of the Copyright Holders of * |
---|
| 6 | // * the Geant4 Collaboration. It is provided under the terms and * |
---|
| 7 | // * conditions of the Geant4 Software License, included in the file * |
---|
| 8 | // * LICENSE and available at http://cern.ch/geant4/license . These * |
---|
| 9 | // * include a list of copyright holders. * |
---|
| 10 | // * * |
---|
| 11 | // * Neither the authors of this software system, nor their employing * |
---|
| 12 | // * institutes,nor the agencies providing financial support for this * |
---|
| 13 | // * work make any representation or warranty, express or implied, * |
---|
| 14 | // * regarding this software system or assume any liability for its * |
---|
| 15 | // * use. Please see the license in the file LICENSE and URL above * |
---|
| 16 | // * for the full disclaimer and the limitation of liability. * |
---|
| 17 | // * * |
---|
| 18 | // * This code implementation is the result of the scientific and * |
---|
| 19 | // * technical work of the GEANT4 collaboration. * |
---|
| 20 | // * By using, copying, modifying or distributing the software (or * |
---|
| 21 | // * any work based on the software) you agree to acknowledge its * |
---|
| 22 | // * use in resulting scientific publications, and indicate your * |
---|
| 23 | // * acceptance of all terms of the Geant4 Software license. * |
---|
| 24 | // ******************************************************************** |
---|
| 25 | // |
---|
| 26 | // |
---|
| 27 | // $Id: G4GDMLWriteMaterials.cc,v 1.20 2008/07/16 15:46:34 gcosmo Exp $ |
---|
| 28 | // GEANT4 tag $Name: geant4-09-02-ref-02 $ |
---|
| 29 | // |
---|
| 30 | // class G4GDMLWriteMaterials Implementation |
---|
| 31 | // |
---|
| 32 | // Original author: Zoltan Torzsok, November 2007 |
---|
| 33 | // |
---|
| 34 | // -------------------------------------------------------------------- |
---|
| 35 | |
---|
| 36 | #include "G4GDMLWriteMaterials.hh" |
---|
| 37 | |
---|
| 38 | void G4GDMLWriteMaterials:: |
---|
| 39 | AtomWrite(xercesc::DOMElement* element,const G4double& a) |
---|
| 40 | { |
---|
| 41 | xercesc::DOMElement* atomElement = NewElement("atom"); |
---|
| 42 | atomElement->setAttributeNode(NewAttribute("unit","g/mole")); |
---|
| 43 | atomElement->setAttributeNode(NewAttribute("value",a*mole/g)); |
---|
| 44 | element->appendChild(atomElement); |
---|
| 45 | } |
---|
| 46 | |
---|
| 47 | void G4GDMLWriteMaterials:: |
---|
| 48 | DWrite(xercesc::DOMElement* element,const G4double& d) |
---|
| 49 | { |
---|
| 50 | xercesc::DOMElement* DElement = NewElement("D"); |
---|
| 51 | DElement->setAttributeNode(NewAttribute("unit","g/cm3")); |
---|
| 52 | DElement->setAttributeNode(NewAttribute("value",d*cm3/g)); |
---|
| 53 | element->appendChild(DElement); |
---|
| 54 | } |
---|
| 55 | |
---|
| 56 | void G4GDMLWriteMaterials:: |
---|
| 57 | PWrite(xercesc::DOMElement* element,const G4double& P) |
---|
| 58 | { |
---|
| 59 | xercesc::DOMElement* PElement = NewElement("P"); |
---|
| 60 | PElement->setAttributeNode(NewAttribute("unit","pascal")); |
---|
| 61 | PElement->setAttributeNode(NewAttribute("value",P/pascal)); |
---|
| 62 | element->appendChild(PElement); |
---|
| 63 | } |
---|
| 64 | |
---|
| 65 | void G4GDMLWriteMaterials:: |
---|
| 66 | TWrite(xercesc::DOMElement* element,const G4double& T) |
---|
| 67 | { |
---|
| 68 | xercesc::DOMElement* TElement = NewElement("T"); |
---|
| 69 | TElement->setAttributeNode(NewAttribute("unit","K")); |
---|
| 70 | TElement->setAttributeNode(NewAttribute("value",T/kelvin)); |
---|
| 71 | element->appendChild(TElement); |
---|
| 72 | } |
---|
| 73 | |
---|
| 74 | void G4GDMLWriteMaterials:: |
---|
| 75 | IsotopeWrite(const G4Isotope* const isotopePtr) |
---|
| 76 | { |
---|
| 77 | const G4String name = GenerateName(isotopePtr->GetName(),isotopePtr); |
---|
| 78 | |
---|
| 79 | xercesc::DOMElement* isotopeElement = NewElement("isotope"); |
---|
| 80 | isotopeElement->setAttributeNode(NewAttribute("name",name)); |
---|
| 81 | isotopeElement->setAttributeNode(NewAttribute("N",isotopePtr->GetN())); |
---|
| 82 | isotopeElement->setAttributeNode(NewAttribute("Z",isotopePtr->GetZ())); |
---|
| 83 | materialsElement->appendChild(isotopeElement); |
---|
| 84 | AtomWrite(isotopeElement,isotopePtr->GetA()); |
---|
| 85 | } |
---|
| 86 | |
---|
| 87 | void G4GDMLWriteMaterials::ElementWrite(const G4Element* const elementPtr) |
---|
| 88 | { |
---|
| 89 | const G4String name = GenerateName(elementPtr->GetName(),elementPtr); |
---|
| 90 | |
---|
| 91 | xercesc::DOMElement* elementElement = NewElement("element"); |
---|
| 92 | elementElement->setAttributeNode(NewAttribute("name",name)); |
---|
| 93 | |
---|
| 94 | const size_t NumberOfIsotopes = elementPtr->GetNumberOfIsotopes(); |
---|
| 95 | |
---|
| 96 | if (NumberOfIsotopes>0) |
---|
| 97 | { |
---|
| 98 | const G4double* RelativeAbundanceVector = |
---|
| 99 | elementPtr->GetRelativeAbundanceVector(); |
---|
| 100 | for (size_t i=0;i<NumberOfIsotopes;i++) |
---|
| 101 | { |
---|
| 102 | G4String fractionref = GenerateName(elementPtr->GetIsotope(i)->GetName(), |
---|
| 103 | elementPtr->GetIsotope(i)); |
---|
| 104 | xercesc::DOMElement* fractionElement = NewElement("fraction"); |
---|
| 105 | fractionElement->setAttributeNode(NewAttribute("n", |
---|
| 106 | RelativeAbundanceVector[i])); |
---|
| 107 | fractionElement->setAttributeNode(NewAttribute("ref",fractionref)); |
---|
| 108 | elementElement->appendChild(fractionElement); |
---|
| 109 | AddIsotope(elementPtr->GetIsotope(i)); |
---|
| 110 | } |
---|
| 111 | } |
---|
| 112 | else |
---|
| 113 | { |
---|
| 114 | elementElement->setAttributeNode(NewAttribute("Z",elementPtr->GetZ())); |
---|
| 115 | AtomWrite(elementElement,elementPtr->GetA()); |
---|
| 116 | } |
---|
| 117 | |
---|
| 118 | materialsElement->appendChild(elementElement); |
---|
| 119 | // Append the element AFTER all the possible components are appended! |
---|
| 120 | } |
---|
| 121 | |
---|
| 122 | void G4GDMLWriteMaterials::MaterialWrite(const G4Material* const materialPtr) |
---|
| 123 | { |
---|
| 124 | G4String state_str("undefined"); |
---|
| 125 | const G4State state = materialPtr->GetState(); |
---|
| 126 | if (state==kStateSolid) { state_str = "solid"; } else |
---|
| 127 | if (state==kStateLiquid) { state_str = "liquid"; } else |
---|
| 128 | if (state==kStateGas) { state_str = "gas"; } |
---|
| 129 | |
---|
| 130 | const G4String name = GenerateName(materialPtr->GetName(), materialPtr); |
---|
| 131 | |
---|
| 132 | xercesc::DOMElement* materialElement = NewElement("material"); |
---|
| 133 | materialElement->setAttributeNode(NewAttribute("name",name)); |
---|
| 134 | materialElement->setAttributeNode(NewAttribute("state",state_str)); |
---|
| 135 | |
---|
| 136 | if (materialPtr->GetTemperature() != STP_Temperature) |
---|
| 137 | { TWrite(materialElement,materialPtr->GetTemperature()); } |
---|
| 138 | if (materialPtr->GetPressure() != STP_Pressure) |
---|
| 139 | { PWrite(materialElement,materialPtr->GetPressure()); } |
---|
| 140 | DWrite(materialElement,materialPtr->GetDensity()); |
---|
| 141 | |
---|
| 142 | const size_t NumberOfElements = materialPtr->GetNumberOfElements(); |
---|
| 143 | |
---|
| 144 | if (NumberOfElements>1) |
---|
| 145 | { |
---|
| 146 | const G4double* MassFractionVector = materialPtr->GetFractionVector(); |
---|
| 147 | |
---|
| 148 | for (size_t i=0;i<NumberOfElements;i++) |
---|
| 149 | { |
---|
| 150 | const G4String fractionref = |
---|
| 151 | GenerateName(materialPtr->GetElement(i)->GetName(), |
---|
| 152 | materialPtr->GetElement(i)); |
---|
| 153 | xercesc::DOMElement* fractionElement = NewElement("fraction"); |
---|
| 154 | fractionElement->setAttributeNode(NewAttribute("n", |
---|
| 155 | MassFractionVector[i])); |
---|
| 156 | fractionElement->setAttributeNode(NewAttribute("ref",fractionref)); |
---|
| 157 | materialElement->appendChild(fractionElement); |
---|
| 158 | AddElement(materialPtr->GetElement(i)); |
---|
| 159 | } |
---|
| 160 | } |
---|
| 161 | else |
---|
| 162 | { |
---|
| 163 | materialElement->setAttributeNode(NewAttribute("Z",materialPtr->GetZ())); |
---|
| 164 | AtomWrite(materialElement,materialPtr->GetA()); |
---|
| 165 | } |
---|
| 166 | |
---|
| 167 | materialsElement->appendChild(materialElement); |
---|
| 168 | // Append the material AFTER all the possible components are appended! |
---|
| 169 | } |
---|
| 170 | |
---|
| 171 | void G4GDMLWriteMaterials::MaterialsWrite(xercesc::DOMElement* element) |
---|
| 172 | { |
---|
| 173 | G4cout << "G4GDML: Writing materials..." << G4endl; |
---|
| 174 | |
---|
| 175 | materialsElement = NewElement("materials"); |
---|
| 176 | element->appendChild(materialsElement); |
---|
| 177 | |
---|
| 178 | isotopeList.clear(); |
---|
| 179 | elementList.clear(); |
---|
| 180 | materialList.clear(); |
---|
| 181 | } |
---|
| 182 | |
---|
| 183 | void G4GDMLWriteMaterials::AddIsotope(const G4Isotope* const isotopePtr) |
---|
| 184 | { |
---|
| 185 | for (size_t i=0; i<isotopeList.size(); i++) // Check if isotope is |
---|
| 186 | { // already in the list! |
---|
| 187 | if (isotopeList[i] == isotopePtr) { return; } |
---|
| 188 | } |
---|
| 189 | isotopeList.push_back(isotopePtr); |
---|
| 190 | IsotopeWrite(isotopePtr); |
---|
| 191 | } |
---|
| 192 | |
---|
| 193 | void G4GDMLWriteMaterials::AddElement(const G4Element* const elementPtr) |
---|
| 194 | { |
---|
| 195 | for (size_t i=0;i<elementList.size();i++) // Check if element is |
---|
| 196 | { // already in the list! |
---|
| 197 | if (elementList[i] == elementPtr) { return; } |
---|
| 198 | } |
---|
| 199 | elementList.push_back(elementPtr); |
---|
| 200 | ElementWrite(elementPtr); |
---|
| 201 | } |
---|
| 202 | |
---|
| 203 | void G4GDMLWriteMaterials::AddMaterial(const G4Material* const materialPtr) |
---|
| 204 | { |
---|
| 205 | for (size_t i=0;i<materialList.size();i++) // Check if material is |
---|
| 206 | { // already in the list! |
---|
| 207 | if (materialList[i] == materialPtr) { return; } |
---|
| 208 | } |
---|
| 209 | materialList.push_back(materialPtr); |
---|
| 210 | MaterialWrite(materialPtr); |
---|
| 211 | } |
---|