Geant4  10.02.p01
pyG4Material.cc
Go to the documentation of this file.
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 // $Id: pyG4Material.cc 76884 2013-11-18 12:54:03Z gcosmo $
27 // ====================================================================
28 // pyG4Material.cc
29 //
30 // 2005 Q
31 // ====================================================================
32 #include <boost/python.hpp>
33 #include "G4Version.hh"
34 #include "G4Material.hh"
35 
36 using namespace boost::python;
37 
38 // ====================================================================
39 // thin wrappers
40 // ====================================================================
41 namespace pyG4Material {
42 
43 // AddElement
48 
50 
51 // raw pointer -> Python list conversion
52 list f_GetFractionVector(const G4Material* material)
53 {
54  list fracList;
55  const G4double* fracVec= material-> GetFractionVector();
56  G4int nele= material-> GetNumberOfElements();
57  for(G4int i=0; i<nele; i++) {
58  fracList.append(fracVec[i]);
59  }
60  return fracList;
61 }
62 
63 list f_GetAtomsVector(const G4Material* material)
64 {
65  list atomsList;
66  const G4int* atomsVec= material-> GetAtomsVector();
67  G4int nele= material-> GetNumberOfElements();
68  for(G4int i=0; i<nele; i++) {
69  atomsList.append(atomsVec[i]);
70  }
71  return atomsList;
72 }
73 
75 {
76  list nbOfAtomsPerVolumeList;
77  const G4double* nbOfAtomsPerVolumeVec= material-> GetVecNbOfAtomsPerVolume();
78  G4int nele= material-> GetNumberOfElements();
79  for(G4int i=0; i<nele; i++) {
80  nbOfAtomsPerVolumeList.append(nbOfAtomsPerVolumeVec[i]);
81  }
82  return nbOfAtomsPerVolumeList;
83 }
84 
86 {
87  list atomicNumDensityList;
88  const G4double* atomicNumDensityVec= material-> GetAtomicNumDensityVector();
89  G4int nele= material-> GetNumberOfElements();
90  for(G4int i=0; i<nele; i++) {
91  atomicNumDensityList.append(atomicNumDensityVec[i]);
92  }
93  return atomicNumDensityList;
94 }
95 
96 // copy constructor is private, so ...
97 void Print(G4Material& mat)
98 {
99  G4cout << mat;
100 }
101 
102 }
103 
104 using namespace pyG4Material;
105 
106 // ====================================================================
107 // module definition
108 // ====================================================================
110 {
111  class_<G4Material, G4Material*, boost::noncopyable>
112  ("G4Material", "material class", no_init)
113  .def(init<const G4String&, G4double, G4double, G4double>())
114  .def(init<const G4String&, G4double, G4int>())
115  // ---
116  .def("AddElement", f1_AddElement)
117  .def("AddElement", f2_AddElement)
118  .def("AddMaterial", &G4Material::AddMaterial)
119  .def("GetName", &G4Material::GetName,
120  return_value_policy<reference_existing_object>())
121  .def("GetChemicalFormula", &G4Material::GetChemicalFormula,
122  return_value_policy<reference_existing_object>())
123  .def("SetName", &G4Material::SetName)
124  .def("SetChemicalFormula", &G4Material::SetChemicalFormula)
125  .def("GetDensity", &G4Material::GetDensity)
126  .def("GetState", &G4Material::GetState)
127  .def("GetTemperature", &G4Material::GetTemperature)
128  .def("GetPressure", &G4Material::GetPressure)
129  // ---
130  .def("GetElementVector", &G4Material::GetElementVector,
131  return_internal_reference<>())
132  .def("GetElement", &G4Material::GetElement,
133  return_value_policy<reference_existing_object>())
134  .def("GetTotNbOfAtomsPerVolume", &G4Material::GetTotNbOfAtomsPerVolume)
135  .def("GetTotNbOfElectPerVolume", &G4Material::GetTotNbOfElectPerVolume)
136  .def("GetFractionVector", f_GetFractionVector)
137  .def("GetAtomsVector", f_GetAtomsVector)
138  .def("GetVecNbOfAtomsPerVolume", f_GetVecNbOfAtomsPerVolume)
139  .def("GetAtomicNumDensityVector", f_GetAtomicNumDensityVector)
140  // ----
141  .def("GetElectronDensity", &G4Material::GetElectronDensity)
142  .def("GetRadlen", &G4Material::GetRadlen)
143  .def("GetNuclearInterLength", &G4Material::GetNuclearInterLength)
144  .def("GetIonisation", &G4Material::GetIonisation,
145  return_internal_reference<>())
146  .def("GetSandiaTable", &G4Material::GetSandiaTable,
147  return_internal_reference<>())
148  // ---
149  .def("GetZ", &G4Material::GetZ)
150  .def("GetA", &G4Material::GetA)
151  .def("SetMaterialPropertiesTable", &G4Material::SetMaterialPropertiesTable)
152  .def("GetMaterialPropertiesTable", &G4Material::GetMaterialPropertiesTable,
153  return_internal_reference<>())
154  .def("GetMaterialTable", &G4Material::GetMaterialTable,
155  return_value_policy<reference_existing_object>())
156  .staticmethod("GetMaterialTable")
157  .def("GetNumberOfMaterials", &G4Material::GetNumberOfMaterials)
158  .staticmethod("GetNumberOfMaterials")
159  .def("GetIndex", &G4Material::GetIndex)
160  .def("GetMaterial", &G4Material::GetMaterial,
161  f_GetMaterial()
162  [return_value_policy<reference_existing_object>()])
163  .staticmethod("GetMaterial")
164  // ---
165  //.def(self_ns::str(self))
166  .def("Print", Print)
167  ;
168 
169  // ---
170  enum_<G4State>("G4State")
171  .value("kStateUndefined", kStateUndefined)
172  .value("kStateSolid", kStateSolid)
173  .value("kStateLiquid", kStateLiquid)
174  .value("kStateGas", kStateGas)
175  ;
176 }
177 
G4double GetPressure() const
Definition: G4Material.hh:183
G4IonisParamMat * GetIonisation() const
Definition: G4Material.hh:226
G4double GetZ() const
Definition: G4Material.cc:625
void SetChemicalFormula(const G4String &chF)
Definition: G4Material.hh:173
void SetName(const G4String &name)
Definition: G4Material.hh:283
G4double GetTotNbOfElectPerVolume() const
Definition: G4Material.hh:212
void AddMaterial(G4Material *material, G4double fraction)
Definition: G4Material.cc:469
BOOST_PYTHON_FUNCTION_OVERLOADS(f_func2, func2, 1, 2)
static G4Material * GetMaterial(const G4String &name, G4bool warning=true)
Definition: G4Material.cc:604
size_t GetIndex() const
Definition: G4Material.hh:262
const G4String & GetChemicalFormula() const
Definition: G4Material.hh:179
void SetMaterialPropertiesTable(G4MaterialPropertiesTable *anMPT)
Definition: G4Material.hh:249
list f_GetFractionVector(const G4Material *material)
Definition: pyG4Material.cc:52
const G4String & GetName() const
Definition: G4Material.hh:178
static G4MaterialTable * GetMaterialTable()
Definition: G4Material.cc:589
G4double GetDensity() const
Definition: G4Material.hh:180
const G4Element * GetElement(G4int iel) const
Definition: G4Material.hh:202
const G4ElementVector * GetElementVector() const
Definition: G4Material.hh:190
int G4int
Definition: G4Types.hh:78
void(G4Material::* f2_AddElement)(G4Element *, G4double)
Definition: pyG4Material.cc:46
void(G4Material::* f1_AddElement)(G4Element *, G4int)
Definition: pyG4Material.cc:44
G4SandiaTable * GetSandiaTable() const
Definition: G4Material.hh:229
G4GLOB_DLL std::ostream G4cout
list f_GetVecNbOfAtomsPerVolume(const G4Material *material)
Definition: pyG4Material.cc:74
G4double GetElectronDensity() const
Definition: G4Material.hh:217
void Print(const std::vector< T > &data)
Definition: DicomRun.hh:109
static size_t GetNumberOfMaterials()
Definition: G4Material.cc:596
G4double GetRadlen() const
Definition: G4Material.hh:220
G4double GetA() const
Definition: G4Material.cc:638
G4double GetTotNbOfAtomsPerVolume() const
Definition: G4Material.hh:209
G4MaterialPropertiesTable * GetMaterialPropertiesTable() const
Definition: G4Material.hh:252
list f_GetAtomicNumDensityVector(const G4Material *material)
Definition: pyG4Material.cc:85
void export_G4Material()
G4double GetTemperature() const
Definition: G4Material.hh:182
void AddElement(G4Element *element, G4int nAtoms)
Definition: G4Material.cc:364
list f_GetAtomsVector(const G4Material *material)
Definition: pyG4Material.cc:63
G4State GetState() const
Definition: G4Material.hh:181
double G4double
Definition: G4Types.hh:76
G4double GetNuclearInterLength() const
Definition: G4Material.hh:223