def setUp(self): super().setUp() self.testdatadir = os.path.join(os.path.dirname(__file__), '..', 'testdata', 'pengeom') self.geo = Geometry('Test Geometry') surface1 = zplane(1e-8) surface2 = zplane(-1e-1) surface3 = cylinder(1.0) surface4 = xplane(0.0) self.mat1 = Material('copper', {29: 1.0}, 8.9) self.module1 = Module(self.mat1) self.module1.add_surface(surface1, SIDEPOINTER_NEGATIVE) self.module1.add_surface(surface2, SIDEPOINTER_POSITIVE) self.module1.add_surface(surface3, SIDEPOINTER_NEGATIVE) self.module1.add_surface(surface4, SIDEPOINTER_POSITIVE) self.geo.add_module(self.module1) self.mat2 = Material('zinc', {30: 1.0}, 7.14) self.module2 = Module(self.mat2) self.module2.add_surface(surface1, SIDEPOINTER_NEGATIVE) self.module2.add_surface(surface2, SIDEPOINTER_POSITIVE) self.module2.add_surface(surface3, SIDEPOINTER_NEGATIVE) self.module2.add_module(self.module1) self.geo.add_module(self.module2) self.geo.tilt_deg = 45
def setUp(self): super().setUp() self.mat = Material('mat1', { 29: 0.4, 30: 0.6 }, 8.9, 326.787, 2.686, 13.496) self.testdatadir = os.path.join(os.path.dirname(__file__), 'testdata')
def create_example3_detector(): # Create materials material_nai = Material('NaI', {11: 0.1534, 53: 0.8466}, 3.667) material_al2o3 = Material('Al2O3', {8: 0.4707, 13: 0.5293}, 3.97) material_al = Material('Al', {13: 1.0}, 2.7) materials = (material_nai, material_al2o3, material_al) # Create input input = PencylInput() input.TITLE.set('NaI detector with Al cover and Al2O3 reflecting foil') layer1 = input.geometry_definitions.add(-0.24, -0.16, 0.0, 0.0) layer1.CYLIND.add(3, 0.00, 4.05) layer2 = input.geometry_definitions.add(-0.16, 0.00) layer2.CYLIND.add(2, 0.00, 3.97) layer2.CYLIND.add(3, 3.97, 4.05) layer3 = input.geometry_definitions.add(0.00, 7.72) layer3.CYLIND.add(1, 0.00, 3.81) layer3.CYLIND.add(2, 3.81, 3.97) layer3.CYLIND.add(3, 3.97, 4.05) layer4 = input.geometry_definitions.add(7.72, 9.72) layer4.CYLIND.add(3, 0.00, 4.05) input.SKPAR.set(2) input.SENERG.set(9.5e6) input.SPOSIT.set(0, 0, -10.0) input.SCONE.set(0, 0, 0) input.materials.add(1, material_nai.filename, 5.0e4, 5.0e3, 5.0e4, 0.1, 0.1, 2e3, 2e3) input.materials.add(2, material_al2o3.filename, 5.0e4, 5.0e3, 5.0e4, 0.1, 0.1, 2e3, 2e3) input.materials.add(3, material_al.filename, 5.0e4, 5.0e3, 5.0e4, 0.1, 0.1, 2e3, 2e3) detector = input.energy_deposition_detectors.add(0, 1e7, 1000) detector.EDBODY.add(3, 1) input.DOSE2D.set(3, 1, 50, 50) input.RESUME.set('dump.dat') input.DUMPTO.set('dump.dat') input.DUMPP.set(60) input.NSIMSH.set(1e8) input.TIME.set(2e9) return input, materials
def create_example1_disc(): # Create materials material_cu = Material('Cu', {29: 1.0}, 8.9) # Create geometry module = Module(material_cu, 'Solid cylinder') module.add_surface(zplane(0.0), SIDEPOINTER_POSITIVE) module.add_surface(zplane(0.005), SIDEPOINTER_NEGATIVE) module.add_surface(cylinder(1.0), SIDEPOINTER_NEGATIVE) geometry = Geometry('A solid cylinder.') geometry.add_module(module) # Create input input = PenmainInput() input.TITLE.set('Point source and a homogeneous cylinder.') input.SKPAR.set(1) input.SENERG.set(40e3) input.SPOSIT.set(0.0, 0.0, -0.0001) input.SCONE.set(0.0, 0.0, 5.0) input.materials.add(1, material_cu.filename, 1e3, 1e3, 1e3, 0.05, 0.05, 1e3, 1e3) input.GEOMFN.set('disc.geo') input.PARINP.add(1, 0.005) input.PARINP.add(2, 0.01) input.DSMAX.add(1, 1e-4) input.IFORCE.add(1, 1, 4, 2000, 0.1, 2.0) input.IFORCE.add(1, 1, 5, 200, 0.1, 2.0) input.IBRSPL.add(1, 2) input.IXRSPL.add(1, 2) input.NBE.set(0, 0, 100) input.NBANGL.set(45, 18) detector = input.impact_detectors.add(0.0, 0.0, 100, 0, 2) detector.IDBODY.add(1) detector = input.energy_deposition_detectors.add(0, 0, 100) detector.EDBODY.add(1) input.GRIDZ.set(0, 0.005, 100) input.GRIDR.set(0.01, 50) input.RESUME.set('dump.dat') input.DUMPTO.set('dump.dat') input.DUMPP.set(60) input.NSIMSH.set(2e9) input.TIME.set(600) return input
class TestMMaterial(unittest.TestCase): def setUp(self): super().setUp() self.mat = Material('mat1', { 29: 0.4, 30: 0.6 }, 8.9, 326.787, 2.686, 13.496) self.testdatadir = os.path.join(os.path.dirname(__file__), 'testdata') def _test_material(self, mat): self.assertEqual('mat1', mat.name) self.assertAlmostEqual(0.4, mat.composition[29], 4) self.assertAlmostEqual(0.6, mat.composition[30], 4) self.assertAlmostEqual(8.9, mat.density_g_per_cm3, 4) self.assertAlmostEqual(326.787, mat.mean_excitation_energy_eV, 4) self.assertAlmostEqual(2.686, mat.oscillator_strength_fcb, 4) self.assertAlmostEqual(13.496, mat.oscillator_energy_wcb_eV, 4) def test__init__(self): self._test_material(self.mat) def testwriteread_input(self): fileobj = io.StringIO() try: self.mat.write_input(fileobj) fileobj.seek(0) mat = Material.read_input(fileobj) self._test_material(mat) finally: fileobj.close() def testread_material(self): filepath = os.path.join(self.testdatadir, 'material', 'mat1.mat') with open(filepath, 'r') as fp: mat = Material.read_material(fp) self._test_material(mat)
def testwriteread_input(self): fileobj = io.StringIO() try: self.mat.write_input(fileobj) fileobj.seek(0) mat = Material.read_input(fileobj) self._test_material(mat) finally: fileobj.close()
def create_example2_plane(): # Create materials material_h2o = Material('H2O', {8: 0.8881, 1: 0.1119}, 1.0) # Create geometry module_detector = Module(material_h2o, 'Fluence detector') module_detector.add_surface(sphere(2.0), SIDEPOINTER_NEGATIVE) module_phantom = Module(material_h2o, 'Water phantom') module_phantom.add_surface(zplane(0.0), SIDEPOINTER_POSITIVE) module_phantom.add_surface(zplane(30.0), SIDEPOINTER_NEGATIVE) geometry = Geometry('Semi-infinite water phantom') geometry.add_module(module_detector) geometry.add_module(module_phantom) index_lookup = geometry.indexify() # Create input input = PenmainInput() input.TITLE.set('Dose in a water phantom with a spherical impact detector') input.SKPAR.set(2) input.SENERG.set(3e7) input.SPOSIT.set(0.0, 0.0, -25.0) input.SCONE.set(0.0, 0.0, 5.0) input.materials.add(1, material_h2o.filename, 1e5, 1e4, 1e5, 0.05, 0.05, 5e3, 5e3) input.GEOMFN.set('plane.geo') input.NBE.set(1e5, 3e7, 100) input.NBANGL.set(45, 18) detector = input.impact_detectors.add(1e5, 0.0, 100, 0, 2) detector.IDBODY.add(index_lookup[module_detector]) input.GRIDZ.set(0, 30.0, 60) input.GRIDR.set(30.0, 60.0) input.RESUME.set('dump.dat') input.DUMPTO.set('dump.dat') input.DUMPP.set(60) input.NSIMSH.set(1e7) input.TIME.set(2e9) return input
def create_example1_disc(): # Create materials material_cu = Material('Cu', {29: 1.0}, 8.9) # Create input input = PencylInput() input.TITLE.set('Point source and a homogeneous cylinder.') definition = input.geometry_definitions.add(0.0, 0.005) definition.CYLIND.add(1, 0, 0.01) input.SKPAR.set(1) input.SENERG.set(40e3) input.SPOSIT.set(0, 0, -0.0001) input.SCONE.set(0, 0, 5) input.materials.add(1, material_cu.filename, 1e3, 1e3, 1e3, 0.05, 0.05, 1e3, 1e3) input.DSMAX.set(1, 1, 1e-4) input.IFORCE.add(1, 1, 1, 4, 2000, 0.1, 2.0) input.IFORCE.add(1, 1, 1, 5, 200, 0.1, 2.0) input.IBRSPL.add(1, 1, 2) input.IXRSPL.add(1, 1, 2) input.NBE.set(0, 0, 100) input.NBANGL.set(45, 18) input.EMERGP.set(0.005, 100) detector = input.energy_deposition_detectors.add(0, 0, 100) detector.EDBODY.add(1, 1) input.DOSE2D.set(1, 1, 100, 50) input.RESUME.set('dump.dat') input.DUMPTO.set('dump.dat') input.DUMPP.set(60) input.RSEED.set(1, 1) input.NSIMSH.set(1e9) input.TIME.set(600) return input
def setUp(self): super().setUp() self.mat1 = Material('copper', {29: 1.0}, 8.9) self.surface1 = SurfaceImplicit() self.surface2 = SurfaceImplicit() self.module2 = Module(VACUUM) self.module1 = Module(self.mat1, 'Test') self.module1.add_surface(self.surface1, -1) self.module1.add_surface(self.surface2, 1) self.module1.add_module(self.module2) self.module1.rotation.phi_deg = 180 self.module1.shift.z_cm = -1e5
import logging import io import os # Third party modules. # Local modules. from pypenelopetools.penepma.input import PenepmaInput from pypenelopetools.material import Material from pypenelopetools.pengeom.surface import xplane, zplane, cylinder from pypenelopetools.pengeom.module import Module, SIDEPOINTER_NEGATIVE, SIDEPOINTER_POSITIVE from pypenelopetools.pengeom.geometry import Geometry # Globals and constants variables. MATERIAL_CU = Material('Cu', {29: 1.0}, 8.9) MATERIAL_FE = Material('Fe', {26: 1.0}, 7.874) def create_epma1(): # Create geometry module = Module(MATERIAL_CU, 'Sample') module.add_surface(zplane(0.0), SIDEPOINTER_NEGATIVE) module.add_surface(zplane(-0.1), SIDEPOINTER_POSITIVE) module.add_surface(cylinder(1.0), SIDEPOINTER_NEGATIVE) geometry = Geometry('Cylindrical homogeneous foil') geometry.add_module(module) index_lookup = geometry.indexify()
def testread_material(self): filepath = os.path.join(self.testdatadir, 'material', 'mat1.mat') with open(filepath, 'r') as fp: mat = Material.read_material(fp) self._test_material(mat)