Geant4  v4-10.4-release
 모두 클래스 네임스페이스들 파일들 함수 변수 타입정의 열거형 타입 열거형 멤버 Friends 매크로 그룹들 페이지들
G4GDMLWriteMaterials.cc
이 파일의 문서화 페이지로 가기
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 108895 2018-03-15 10:27:25Z gcosmo $
28 //
29 // class G4GDMLWriteMaterials Implementation
30 //
31 // Original author: Zoltan Torzsok, November 2007
32 //
33 // --------------------------------------------------------------------
34 
35 #include <sstream>
36 
37 #include "G4GDMLWriteMaterials.hh"
38 
39 #include "G4PhysicalConstants.hh"
40 #include "G4SystemOfUnits.hh"
41 #include "G4Element.hh"
42 #include "G4Isotope.hh"
43 #include "G4Material.hh"
44 
46  : G4GDMLWriteDefine(), materialsElement(0)
47 {
48 }
49 
51 {
52 }
53 
55 AtomWrite(xercesc::DOMElement* element,const G4double& a)
56 {
57  xercesc::DOMElement* atomElement = NewElement("atom");
58  atomElement->setAttributeNode(NewAttribute("unit","g/mole"));
59  atomElement->setAttributeNode(NewAttribute("value",a*mole/g));
60  element->appendChild(atomElement);
61 }
62 
64 DWrite(xercesc::DOMElement* element,const G4double& d)
65 {
66  xercesc::DOMElement* DElement = NewElement("D");
67  DElement->setAttributeNode(NewAttribute("unit","g/cm3"));
68  DElement->setAttributeNode(NewAttribute("value",d*cm3/g));
69  element->appendChild(DElement);
70 }
71 
73 PWrite(xercesc::DOMElement* element,const G4double& P)
74 {
75  xercesc::DOMElement* PElement = NewElement("P");
76  PElement->setAttributeNode(NewAttribute("unit","pascal"));
77  PElement->setAttributeNode(NewAttribute("value",P/hep_pascal));
78  element->appendChild(PElement);
79 }
80 
82 TWrite(xercesc::DOMElement* element,const G4double& T)
83 {
84  xercesc::DOMElement* TElement = NewElement("T");
85  TElement->setAttributeNode(NewAttribute("unit","K"));
86  TElement->setAttributeNode(NewAttribute("value",T/kelvin));
87  element->appendChild(TElement);
88 }
89 
91 MEEWrite(xercesc::DOMElement* element,const G4double& MEE)
92 {
93  xercesc::DOMElement* PElement = NewElement("MEE");
94  PElement->setAttributeNode(NewAttribute("unit","eV"));
95  PElement->setAttributeNode(NewAttribute("value",MEE/electronvolt));
96  element->appendChild(PElement);
97 }
98 
100 IsotopeWrite(const G4Isotope* const isotopePtr)
101 {
102  const G4String name = GenerateName(isotopePtr->GetName(),isotopePtr);
103 
104  xercesc::DOMElement* isotopeElement = NewElement("isotope");
105  isotopeElement->setAttributeNode(NewAttribute("name",name));
106  isotopeElement->setAttributeNode(NewAttribute("N",isotopePtr->GetN()));
107  isotopeElement->setAttributeNode(NewAttribute("Z",isotopePtr->GetZ()));
108  materialsElement->appendChild(isotopeElement);
109  AtomWrite(isotopeElement,isotopePtr->GetA());
110 }
111 
112 void G4GDMLWriteMaterials::ElementWrite(const G4Element* const elementPtr)
113 {
114  const G4String name = GenerateName(elementPtr->GetName(),elementPtr);
115 
116  xercesc::DOMElement* elementElement = NewElement("element");
117  elementElement->setAttributeNode(NewAttribute("name",name));
118 
119  const size_t NumberOfIsotopes = elementPtr->GetNumberOfIsotopes();
120 
121  if (NumberOfIsotopes>0)
122  {
123  const G4double* RelativeAbundanceVector =
124  elementPtr->GetRelativeAbundanceVector();
125  for (size_t i=0;i<NumberOfIsotopes;i++)
126  {
127  G4String fractionref = GenerateName(elementPtr->GetIsotope(i)->GetName(),
128  elementPtr->GetIsotope(i));
129  xercesc::DOMElement* fractionElement = NewElement("fraction");
130  fractionElement->setAttributeNode(NewAttribute("n",
131  RelativeAbundanceVector[i]));
132  fractionElement->setAttributeNode(NewAttribute("ref",fractionref));
133  elementElement->appendChild(fractionElement);
134  AddIsotope(elementPtr->GetIsotope(i));
135  }
136  }
137  else
138  {
139  elementElement->setAttributeNode(NewAttribute("Z",elementPtr->GetZ()));
140  AtomWrite(elementElement,elementPtr->GetA());
141  }
142 
143  materialsElement->appendChild(elementElement);
144  // Append the element AFTER all the possible components are appended!
145 }
146 
147 void G4GDMLWriteMaterials::MaterialWrite(const G4Material* const materialPtr)
148 {
149  G4String state_str("undefined");
150  const G4State state = materialPtr->GetState();
151  if (state==kStateSolid) { state_str = "solid"; } else
152  if (state==kStateLiquid) { state_str = "liquid"; } else
153  if (state==kStateGas) { state_str = "gas"; }
154 
155  const G4String name = GenerateName(materialPtr->GetName(), materialPtr);
156 
157  xercesc::DOMElement* materialElement = NewElement("material");
158  materialElement->setAttributeNode(NewAttribute("name",name));
159  materialElement->setAttributeNode(NewAttribute("state",state_str));
160 
161  // Write any property attached to the material...
162  //
163  if (materialPtr->GetMaterialPropertiesTable())
164  {
165  PropertyWrite(materialElement, materialPtr);
166  }
167 
168  if (materialPtr->GetTemperature() != STP_Temperature)
169  { TWrite(materialElement,materialPtr->GetTemperature()); }
170  if (materialPtr->GetPressure() != STP_Pressure)
171  { PWrite(materialElement,materialPtr->GetPressure()); }
172 
173  // Write Ionisation potential (mean excitation energy)
174  MEEWrite(materialElement,materialPtr->GetIonisation()->GetMeanExcitationEnergy());
175 
176  DWrite(materialElement,materialPtr->GetDensity());
177 
178  const size_t NumberOfElements = materialPtr->GetNumberOfElements();
179 
180  if ( (NumberOfElements>1)
181  || ( materialPtr->GetElement(0)
182  && materialPtr->GetElement(0)->GetNumberOfIsotopes()>1 ) )
183  {
184  const G4double* MassFractionVector = materialPtr->GetFractionVector();
185 
186  for (size_t i=0;i<NumberOfElements;i++)
187  {
188  const G4String fractionref =
189  GenerateName(materialPtr->GetElement(i)->GetName(),
190  materialPtr->GetElement(i));
191  xercesc::DOMElement* fractionElement = NewElement("fraction");
192  fractionElement->setAttributeNode(NewAttribute("n",
193  MassFractionVector[i]));
194  fractionElement->setAttributeNode(NewAttribute("ref",fractionref));
195  materialElement->appendChild(fractionElement);
196  AddElement(materialPtr->GetElement(i));
197  }
198  }
199  else
200  {
201  materialElement->setAttributeNode(NewAttribute("Z",materialPtr->GetZ()));
202  AtomWrite(materialElement,materialPtr->GetA());
203  }
204 
205  // Append the material AFTER all the possible components are appended!
206  //
207  materialsElement->appendChild(materialElement);
208 }
209 
211  const G4PhysicsOrderedFreeVector* const pvec)
212 {
213  const G4String matrixref = GenerateName(key, pvec);
214  xercesc::DOMElement* matrixElement = NewElement("matrix");
215  matrixElement->setAttributeNode(NewAttribute("name", matrixref));
216  matrixElement->setAttributeNode(NewAttribute("coldim", "2"));
217  std::ostringstream pvalues;
218  for (size_t i=0; i<pvec->GetVectorLength(); i++)
219  {
220  if (i!=0) { pvalues << " "; }
221  pvalues << pvec->Energy(i) << " " << (*pvec)[i];
222  }
223  matrixElement->setAttributeNode(NewAttribute("values", pvalues.str()));
224 
225  defineElement->appendChild(matrixElement);
226 }
227 
228 void G4GDMLWriteMaterials::PropertyWrite(xercesc::DOMElement* matElement,
229  const G4Material* const mat)
230 {
231  xercesc::DOMElement* propElement;
233 
234  const std::map< G4int, G4PhysicsOrderedFreeVector*,
235  std::less<G4int> >* pmap = ptable->GetPropertyMap();
236  const std::map< G4int, G4double,
237  std::less<G4int> >* cmap = ptable->GetConstPropertyMap();
238  std::map< G4int, G4PhysicsOrderedFreeVector*,
239  std::less<G4int> >::const_iterator mpos;
240  std::map< G4int, G4double,
241  std::less<G4int> >::const_iterator cpos;
242 
243 
244  for (mpos=pmap->begin(); mpos!=pmap->end(); mpos++)
245  {
246  propElement = NewElement("property");
247  propElement->setAttributeNode(NewAttribute("name",
248  ptable->GetMaterialPropertyNames()[mpos->first]));
249  propElement->setAttributeNode(NewAttribute("ref",
250  GenerateName(ptable->GetMaterialPropertyNames()[mpos->first],
251  mpos->second)));
252  if (mpos->second)
253  {
254  PropertyVectorWrite(ptable->GetMaterialPropertyNames()[mpos->first],
255  mpos->second);
256  matElement->appendChild(propElement);
257  }
258  else
259  {
260  G4String warn_message = "Null pointer for material property -"
261  + ptable->GetMaterialPropertyNames()[mpos->first] + "- of material -"
262  + mat->GetName() + "- !";
263  G4Exception("G4GDMLWriteMaterials::PropertyWrite()", "NullPointer",
264  JustWarning, warn_message);
265  continue;
266  }
267  }
268 
269  for (cpos=cmap->begin(); cpos!=cmap->end(); cpos++)
270  {
271  propElement = NewElement("property");
272  propElement->setAttributeNode(NewAttribute("name",
273  ptable->GetMaterialConstPropertyNames()[cpos->first]));
274  propElement->setAttributeNode(NewAttribute("ref",
275  ptable->GetMaterialConstPropertyNames()[cpos->first]));
276  xercesc::DOMElement* constElement = NewElement("constant");
277  constElement->setAttributeNode(NewAttribute("name",
278  ptable->GetMaterialConstPropertyNames()[cpos->first]));
279  constElement->setAttributeNode(NewAttribute("value", cpos->second));
280  defineElement->appendChild(constElement);
281  matElement->appendChild(propElement);
282  }
283 }
284 
285 void G4GDMLWriteMaterials::MaterialsWrite(xercesc::DOMElement* element)
286 {
287 #ifdef G4VERBOSE
288  G4cout << "G4GDML: Writing materials..." << G4endl;
289 #endif
290  materialsElement = NewElement("materials");
291  element->appendChild(materialsElement);
292 
293  isotopeList.clear();
294  elementList.clear();
295  materialList.clear();
296 }
297 
298 void G4GDMLWriteMaterials::AddIsotope(const G4Isotope* const isotopePtr)
299 {
300  for (size_t i=0; i<isotopeList.size(); i++) // Check if isotope is
301  { // already in the list!
302  if (isotopeList[i] == isotopePtr) { return; }
303  }
304  isotopeList.push_back(isotopePtr);
305  IsotopeWrite(isotopePtr);
306 }
307 
308 void G4GDMLWriteMaterials::AddElement(const G4Element* const elementPtr)
309 {
310  for (size_t i=0;i<elementList.size();i++) // Check if element is
311  { // already in the list!
312  if (elementList[i] == elementPtr) { return; }
313  }
314  elementList.push_back(elementPtr);
315  ElementWrite(elementPtr);
316 }
317 
318 void G4GDMLWriteMaterials::AddMaterial(const G4Material* const materialPtr)
319 {
320  for (size_t i=0;i<materialList.size();i++) // Check if material is
321  { // already in the list!
322  if (materialList[i] == materialPtr) { return; }
323  }
324  materialList.push_back(materialPtr);
325  MaterialWrite(materialPtr);
326 }
static constexpr double kelvin
Definition: G4SIunits.hh:281
G4double Energy(size_t index) const
const XML_Char * name
Definition: expat.h:151
const std::map< G4int, G4double, std::less< G4int > > * GetConstPropertyMap() const
static constexpr double hep_pascal
Definition: G4SIunits.hh:235
void PropertyVectorWrite(const G4String &, const G4PhysicsOrderedFreeVector *const)
const G4double * GetFractionVector() const
Definition: G4Material.hh:195
std::vector< ExP01TrackerHit * > a
Definition: ExP01Classes.hh:33
const std::map< G4int, G4MaterialPropertyVector *, std::less< G4int > > * GetPropertyMap() const
G4double * GetRelativeAbundanceVector() const
Definition: G4Element.hh:167
const G4String & GetName() const
Definition: G4Isotope.hh:88
static constexpr double STP_Temperature
const G4String & GetName() const
Definition: G4Element.hh:127
G4String GenerateName(const G4String &, const void *const)
Definition: G4GDMLWrite.cc:124
std::vector< const G4Isotope * > isotopeList
#define G4endl
Definition: G4ios.hh:61
xercesc::DOMElement * NewElement(const G4String &)
Definition: G4GDMLWrite.cc:161
G4double GetA() const
Definition: G4Isotope.hh:97
std::vector< G4String > GetMaterialPropertyNames() const
void MEEWrite(xercesc::DOMElement *, const G4double &)
static constexpr double electronvolt
Definition: G4SIunits.hh:206
void MaterialWrite(const G4Material *const)
G4int GetZ() const
Definition: G4Isotope.hh:91
static constexpr double STP_Pressure
void AtomWrite(xercesc::DOMElement *, const G4double &)
const G4String & GetName() const
Definition: G4Material.hh:179
G4double GetA() const
Definition: G4Material.cc:642
static constexpr double g
Definition: G4SIunits.hh:183
double G4double
Definition: G4Types.hh:76
G4State GetState() const
Definition: G4Material.hh:182
void PropertyWrite(xercesc::DOMElement *, const G4Material *const)
xercesc::DOMElement * defineElement
void AddMaterial(const G4Material *const)
Float_t d
void AddIsotope(const G4Isotope *const)
Float_t mat
G4double GetZ() const
Definition: G4Material.cc:629
void AddElement(const G4Element *const)
virtual void MaterialsWrite(xercesc::DOMElement *)
G4double GetMeanExcitationEnergy() const
void DWrite(xercesc::DOMElement *, const G4double &)
void PWrite(xercesc::DOMElement *, const G4double &)
static double P[]
void G4Exception(const char *originOfException, const char *exceptionCode, G4ExceptionSeverity severity, const char *description)
Definition: G4Exception.hh:65
G4int GetN() const
Definition: G4Isotope.hh:94
G4double GetPressure() const
Definition: G4Material.hh:184
int G4int
Definition: G4Types.hh:78
void IsotopeWrite(const G4Isotope *const)
std::vector< G4String > GetMaterialConstPropertyNames() const
xercesc::DOMElement * materialsElement
G4double GetA() const
Definition: G4Element.hh:139
G4IonisParamMat * GetIonisation() const
Definition: G4Material.hh:227
std::vector< const G4Material * > materialList
std::vector< const G4Element * > elementList
G4GLOB_DLL std::ostream G4cout
xercesc::DOMAttr * NewAttribute(const G4String &, const G4String &)
Definition: G4GDMLWrite.cc:137
const G4Isotope * GetIsotope(G4int iso) const
Definition: G4Element.hh:170
G4double GetZ() const
Definition: G4Element.hh:131
G4State
Definition: G4Material.hh:115
static constexpr double mole
Definition: G4SIunits.hh:286
static constexpr double cm3
Definition: G4SIunits.hh:121
const G4Element * GetElement(G4int iel) const
Definition: G4Material.hh:203
void TWrite(xercesc::DOMElement *, const G4double &)
void ElementWrite(const G4Element *const)
size_t GetNumberOfElements() const
Definition: G4Material.hh:187
G4MaterialPropertiesTable * GetMaterialPropertiesTable() const
Definition: G4Material.hh:252
size_t GetVectorLength() const
G4double GetTemperature() const
Definition: G4Material.hh:183
G4double GetDensity() const
Definition: G4Material.hh:181
size_t GetNumberOfIsotopes() const
Definition: G4Element.hh:159