[1337] | 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,v 1.7 2008/12/04 08:55:25 kmura Exp $ |
---|
| 27 | // $Name: geant4-09-04-beta-01 $ |
---|
| 28 | // ==================================================================== |
---|
| 29 | // pyG4Material.cc |
---|
| 30 | // |
---|
| 31 | // 2005 Q |
---|
| 32 | // ==================================================================== |
---|
| 33 | #include <boost/python.hpp> |
---|
| 34 | #include "G4Version.hh" |
---|
| 35 | #include "G4Material.hh" |
---|
| 36 | |
---|
| 37 | using namespace boost::python; |
---|
| 38 | |
---|
| 39 | // ==================================================================== |
---|
| 40 | // thin wrappers |
---|
| 41 | // ==================================================================== |
---|
| 42 | namespace pyG4Material { |
---|
| 43 | |
---|
| 44 | // AddElement |
---|
| 45 | void (G4Material::*f1_AddElement)(G4Element*, G4int) |
---|
| 46 | = &G4Material::AddElement; |
---|
| 47 | void (G4Material::*f2_AddElement)(G4Element*, G4double) |
---|
| 48 | = &G4Material::AddElement; |
---|
| 49 | |
---|
| 50 | #if G4VERSION_NUMBER >= 800 |
---|
| 51 | BOOST_PYTHON_FUNCTION_OVERLOADS(f_GetMaterial, G4Material::GetMaterial, 1, 2); |
---|
| 52 | #endif |
---|
| 53 | |
---|
| 54 | // raw pointer -> Python list conversion |
---|
| 55 | list f_GetFractionVector(const G4Material* material) |
---|
| 56 | { |
---|
| 57 | list fracList; |
---|
| 58 | const G4double* fracVec= material-> GetFractionVector(); |
---|
| 59 | G4int nele= material-> GetNumberOfElements(); |
---|
| 60 | for(G4int i=0; i<nele; i++) { |
---|
| 61 | fracList.append(fracVec[i]); |
---|
| 62 | } |
---|
| 63 | return fracList; |
---|
| 64 | } |
---|
| 65 | |
---|
| 66 | list f_GetAtomsVector(const G4Material* material) |
---|
| 67 | { |
---|
| 68 | list atomsList; |
---|
| 69 | const G4int* atomsVec= material-> GetAtomsVector(); |
---|
| 70 | G4int nele= material-> GetNumberOfElements(); |
---|
| 71 | for(G4int i=0; i<nele; i++) { |
---|
| 72 | atomsList.append(atomsVec[i]); |
---|
| 73 | } |
---|
| 74 | return atomsList; |
---|
| 75 | } |
---|
| 76 | |
---|
| 77 | list f_GetVecNbOfAtomsPerVolume(const G4Material* material) |
---|
| 78 | { |
---|
| 79 | list nbOfAtomsPerVolumeList; |
---|
| 80 | const G4double* nbOfAtomsPerVolumeVec= material-> GetVecNbOfAtomsPerVolume(); |
---|
| 81 | G4int nele= material-> GetNumberOfElements(); |
---|
| 82 | for(G4int i=0; i<nele; i++) { |
---|
| 83 | nbOfAtomsPerVolumeList.append(nbOfAtomsPerVolumeVec[i]); |
---|
| 84 | } |
---|
| 85 | return nbOfAtomsPerVolumeList; |
---|
| 86 | } |
---|
| 87 | |
---|
| 88 | list f_GetAtomicNumDensityVector(const G4Material* material) |
---|
| 89 | { |
---|
| 90 | list atomicNumDensityList; |
---|
| 91 | const G4double* atomicNumDensityVec= material-> GetAtomicNumDensityVector(); |
---|
| 92 | G4int nele= material-> GetNumberOfElements(); |
---|
| 93 | for(G4int i=0; i<nele; i++) { |
---|
| 94 | atomicNumDensityList.append(atomicNumDensityVec[i]); |
---|
| 95 | } |
---|
| 96 | return atomicNumDensityList; |
---|
| 97 | } |
---|
| 98 | |
---|
| 99 | // copy constructor is private, so ... |
---|
| 100 | void Print(G4Material& mat) |
---|
| 101 | { |
---|
| 102 | G4cout << mat; |
---|
| 103 | } |
---|
| 104 | |
---|
| 105 | } |
---|
| 106 | |
---|
| 107 | using namespace pyG4Material; |
---|
| 108 | |
---|
| 109 | // ==================================================================== |
---|
| 110 | // module definition |
---|
| 111 | // ==================================================================== |
---|
| 112 | void export_G4Material() |
---|
| 113 | { |
---|
| 114 | class_<G4Material, G4Material*, boost::noncopyable> |
---|
| 115 | ("G4Material", "material class", no_init) |
---|
| 116 | .def(init<const G4String&, G4double, G4double, G4double>()) |
---|
| 117 | .def(init<const G4String&, G4double, G4int>()) |
---|
| 118 | // --- |
---|
| 119 | .def("AddElement", f1_AddElement) |
---|
| 120 | .def("AddElement", f2_AddElement) |
---|
| 121 | .def("AddMaterial", &G4Material::AddMaterial) |
---|
| 122 | #if G4VERSION_NUMBER >= 920 |
---|
| 123 | .def("GetName", &G4Material::GetName, |
---|
| 124 | return_value_policy<reference_existing_object>()) |
---|
| 125 | .def("GetChemicalFormula", &G4Material::GetChemicalFormula, |
---|
| 126 | return_value_policy<reference_existing_object>()) |
---|
| 127 | .def("SetName", &G4Material::SetName) |
---|
| 128 | #else |
---|
| 129 | .def("GetName", &G4Material::GetName) |
---|
| 130 | .def("GetChemicalFormula", &G4Material::GetChemicalFormula) |
---|
| 131 | #endif |
---|
| 132 | .def("SetChemicalFormula", &G4Material::SetChemicalFormula) |
---|
| 133 | .def("GetDensity", &G4Material::GetDensity) |
---|
| 134 | .def("GetState", &G4Material::GetState) |
---|
| 135 | .def("GetTemperature", &G4Material::GetTemperature) |
---|
| 136 | .def("GetPressure", &G4Material::GetPressure) |
---|
| 137 | // --- |
---|
| 138 | .def("GetElementVector", &G4Material::GetElementVector, |
---|
| 139 | return_internal_reference<>()) |
---|
| 140 | .def("GetElement", &G4Material::GetElement, |
---|
| 141 | return_value_policy<reference_existing_object>()) |
---|
| 142 | .def("GetTotNbOfAtomsPerVolume", &G4Material::GetTotNbOfAtomsPerVolume) |
---|
| 143 | .def("GetTotNbOfElectPerVolume", &G4Material::GetTotNbOfElectPerVolume) |
---|
| 144 | .def("GetFractionVector", f_GetFractionVector) |
---|
| 145 | .def("GetAtomsVector", f_GetAtomsVector) |
---|
| 146 | .def("GetVecNbOfAtomsPerVolume", f_GetVecNbOfAtomsPerVolume) |
---|
| 147 | .def("GetAtomicNumDensityVector", f_GetAtomicNumDensityVector) |
---|
| 148 | // ---- |
---|
| 149 | .def("GetElectronDensity", &G4Material::GetElectronDensity) |
---|
| 150 | .def("GetRadlen", &G4Material::GetRadlen) |
---|
| 151 | .def("GetNuclearInterLength", &G4Material::GetNuclearInterLength) |
---|
| 152 | .def("GetIonisation", &G4Material::GetIonisation, |
---|
| 153 | return_internal_reference<>()) |
---|
| 154 | .def("GetSandiaTable", &G4Material::GetSandiaTable, |
---|
| 155 | return_internal_reference<>()) |
---|
| 156 | // --- |
---|
| 157 | .def("GetZ", &G4Material::GetZ) |
---|
| 158 | .def("GetA", &G4Material::GetA) |
---|
| 159 | .def("SetMaterialPropertiesTable", &G4Material::SetMaterialPropertiesTable) |
---|
| 160 | .def("GetMaterialPropertiesTable", &G4Material::GetMaterialPropertiesTable, |
---|
| 161 | return_internal_reference<>()) |
---|
| 162 | .def("GetMaterialTable", &G4Material::GetMaterialTable, |
---|
| 163 | return_value_policy<reference_existing_object>()) |
---|
| 164 | .staticmethod("GetMaterialTable") |
---|
| 165 | .def("GetNumberOfMaterials", &G4Material::GetNumberOfMaterials) |
---|
| 166 | .staticmethod("GetNumberOfMaterials") |
---|
| 167 | .def("GetIndex", &G4Material::GetIndex) |
---|
| 168 | #if G4VERSION_NUMBER >= 800 |
---|
| 169 | .def("GetMaterial", &G4Material::GetMaterial, |
---|
| 170 | f_GetMaterial() |
---|
| 171 | [return_value_policy<reference_existing_object>()]) |
---|
| 172 | #else |
---|
| 173 | .def("GetMaterial", &G4Material::GetMaterial, |
---|
| 174 | return_value_policy<reference_existing_object>()) |
---|
| 175 | #endif |
---|
| 176 | .staticmethod("GetMaterial") |
---|
| 177 | // --- |
---|
| 178 | //.def(self_ns::str(self)) |
---|
| 179 | .def("Print", Print) |
---|
| 180 | ; |
---|
| 181 | |
---|
| 182 | // --- |
---|
| 183 | enum_<G4State>("G4State") |
---|
| 184 | .value("kStateUndefined", kStateUndefined) |
---|
| 185 | .value("kStateSolid", kStateSolid) |
---|
| 186 | .value("kStateLiquid", kStateLiquid) |
---|
| 187 | .value("kStateGas", kStateGas) |
---|
| 188 | ; |
---|
| 189 | } |
---|
| 190 | |
---|