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
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_epma2(): # Create geometry surface_top = zplane(0.0) surface_bottom = zplane(-0.1) surface_cylinder = cylinder(1.0) surface_divider = xplane(0.0) module_right = Module(MATERIAL_CU, 'Right half of the sample') module_right.add_surface(surface_top, SIDEPOINTER_NEGATIVE) module_right.add_surface(surface_bottom, SIDEPOINTER_POSITIVE) module_right.add_surface(surface_cylinder, SIDEPOINTER_NEGATIVE) module_right.add_surface(surface_divider, SIDEPOINTER_POSITIVE) module_left = Module(MATERIAL_FE, 'Left half of the sample') module_left.add_surface(surface_top, SIDEPOINTER_NEGATIVE) module_left.add_surface(surface_bottom, SIDEPOINTER_POSITIVE) module_left.add_surface(surface_cylinder, SIDEPOINTER_NEGATIVE) module_left.add_module(module_right) geometry = Geometry('Cylindrical homogeneous foil') geometry.add_module(module_right) geometry.add_module(module_left) index_lookup = geometry.indexify() index_lookup[MATERIAL_CU] = 1 index_lookup[MATERIAL_FE] = 2 # Create input input = PenepmaInput() input.TITLE.set('A CU-Fe couple') input.SENERG.set(15e3) input.SPOSIT.set(2e-5, 0.0, 1.0) input.SDIREC.set(180, 0.0) input.SAPERT.set(0.0) input.materials.add(index_lookup[MATERIAL_FE], MATERIAL_FE.filename, 1e3, 1e3, 1e3, 0.2, 0.2, 1e3, 1e3) # Note inversion input.materials.add(index_lookup[MATERIAL_CU], MATERIAL_CU.filename, 1e3, 1e3, 1e3, 0.2, 0.2, 1e3, 1e3) input.GEOMFN.set('epma2.geo') input.DSMAX.add(index_lookup[module_right], 1e-4) input.DSMAX.add(index_lookup[module_left], 1e-4) input.IFORCE.add(index_lookup[module_right], 1, 4, -5, 0.9, 1.0) input.IFORCE.add(index_lookup[module_right], 1, 5, -250, 0.9, 1.0) input.IFORCE.add(index_lookup[module_right], 2, 2, 10, 1e-3, 1.0) input.IFORCE.add(index_lookup[module_right], 2, 3, 10, 1e-3, 1.0) input.IFORCE.add(index_lookup[module_left], 1, 4, -5, 0.9, 1.0) input.IFORCE.add(index_lookup[module_left], 1, 5, -7, 0.9, 1.0) input.IFORCE.add(index_lookup[module_left], 2, 2, 10, 1e-3, 1.0) input.IFORCE.add(index_lookup[module_left], 2, 3, 10, 1e-3, 1.0) input.IBRSPL.add(index_lookup[module_right], 2) input.IBRSPL.add(index_lookup[module_left], 2) input.IXRSPL.add(index_lookup[module_right], 2) input.IXRSPL.add(index_lookup[module_left], 2) input.NBE.set(0, 0, 300) input.NBANGL.set(45, 30) input.photon_detectors.add(0, 90, 0, 360, 0, 0.0, 0.0, 1000) input.photon_detectors.add(5, 15, 0, 360, 0, 0.0, 0.0, 1000) input.photon_detectors.add(15, 25, 0, 360, 0, 0.0, 0.0, 1000) input.photon_detectors.add(25, 35, 0, 360, 0, 0.0, 0.0, 1000) input.photon_detectors.add(35, 45, 0, 360, 0, 0.0, 0.0, 1000) input.photon_detectors.add(45, 55, 0, 360, 0, 0.0, 0.0, 1000) input.photon_detectors.add(55, 65, 0, 360, 0, 0.0, 0.0, 1000) input.photon_detectors.add(65, 75, 0, 360, 0, 0.0, 0.0, 1000) input.photon_detectors.add(75, 85, 0, 360, 0, 0.0, 0.0, 1000) input.GRIDX.set(-1e-5, 5e-5, 60) input.GRIDY.set(-3e-5, 3e-5, 60) input.GRIDZ.set(-6e-5, 0.0, 60) input.XRLINE.add(26010300) input.XRLINE.add(29010300) input.RESUME.set('dump2.dat') input.DUMPTO.set('dump2.dat') input.DUMPP.set(60) input.RSEED.set(-10, 1) input.REFLIN.set(26010300, 1, 1.5e-3) input.NSIMSH.set(2e9) input.TIME.set(2e9) return input
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() # Create input input = PenepmaInput() input.TITLE.set('A Cu slab') input.SENERG.set(15e3) input.SPOSIT.set(0.0, 0.0, 1.0) input.SDIREC.set(180, 0.0) input.SAPERT.set(0.0) input.materials.add(index_lookup[MATERIAL_CU], MATERIAL_CU.filename, 1e3, 1e3, 1e3, 0.2, 0.2, 1e3, 1e3) input.GEOMFN.set('epma1.geo') input.DSMAX.add(index_lookup[module], 1e-4) input.IFORCE.add(index_lookup[module], 1, 4, -5, 0.9, 1.0) input.IFORCE.add(index_lookup[module], 1, 5, -250, 0.9, 1.0) input.IFORCE.add(index_lookup[module], 2, 2, 10, 1e-3, 1.0) input.IFORCE.add(index_lookup[module], 2, 3, 10, 1e-3, 1.0) input.IBRSPL.add(index_lookup[module], 2) input.IXRSPL.add(index_lookup[module], 2) input.NBE.set(0, 0, 300) input.NBANGL.set(45, 30) input.photon_detectors.add(0, 90, 0, 360, 0, 0.0, 0.0, 1000) input.photon_detectors.add(5, 15, 0, 360, 0, 0.0, 0.0, 1000) input.photon_detectors.add(15, 25, 0, 360, 0, 0.0, 0.0, 1000) input.photon_detectors.add(25, 35, 0, 360, 0, 0.0, 0.0, 1000) input.photon_detectors.add(35, 45, 0, 360, 0, 0.0, 0.0, 1000) input.photon_detectors.add(45, 55, 0, 360, 0, 0.0, 0.0, 1000) input.photon_detectors.add(55, 65, 0, 360, 0, 0.0, 0.0, 1000) input.photon_detectors.add(65, 75, 0, 360, 0, 0.0, 0.0, 1000) input.photon_detectors.add(75, 85, 0, 360, 0, 0.0, 0.0, 1000) input.GRIDX.set(-4e-5, 4e-5, 60) input.GRIDY.set(-4e-5, 4e-5, 60) input.GRIDZ.set(-6e-5, 0.0, 60) input.XRLINE.set(29010300) input.RESUME.set('dump1.dat') input.DUMPTO.set('dump1.dat') input.DUMPP.set(60) input.RSEED.set(-10, 1) input.REFLIN.set(29010300, 1, 1.25e-3) input.NSIMSH.set(2e9) input.TIME.set(2e9) return input
class TestGeometry(unittest.TestCase): LINES = [ 'XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX', ' Test Geometry', '0000000000000000000000000000000000000000000000000000000000000000', 'SURFACE ( 1) Plane Z=0.00 m', 'INDICES=( 0, 0, 0, 1, 0)', 'X-SCALE=(+1.000000000000000E+00, 0) (DEFAULT=1.0)', 'Y-SCALE=(+1.000000000000000E+00, 0) (DEFAULT=1.0)', 'Z-SCALE=(+1.000000000000000E+00, 0) (DEFAULT=1.0)', ' OMEGA=(+0.000000000000000E+00, 0) DEG (DEFAULT=0.0)', ' THETA=(+0.000000000000000E+00, 0) DEG (DEFAULT=0.0)', ' PHI=(+0.000000000000000E+00, 0) DEG (DEFAULT=0.0)', 'X-SHIFT=(+0.000000000000000E+00, 0) (DEFAULT=0.0)', 'Y-SHIFT=(+0.000000000000000E+00, 0) (DEFAULT=0.0)', 'Z-SHIFT=(+1.000000000000000E-08, 0) (DEFAULT=0.0)', '0000000000000000000000000000000000000000000000000000000000000000', 'SURFACE ( 2) Cylinder of radius 0.01 m along z-axis', 'INDICES=( 1, 1, 0, 0,-1)', 'X-SCALE=(+1.000000000000000E-02, 0) (DEFAULT=1.0)', 'Y-SCALE=(+1.000000000000000E-02, 0) (DEFAULT=1.0)', 'Z-SCALE=(+1.000000000000000E+00, 0) (DEFAULT=1.0)', ' OMEGA=(+0.000000000000000E+00, 0) DEG (DEFAULT=0.0)', ' THETA=(+0.000000000000000E+00, 0) DEG (DEFAULT=0.0)', ' PHI=(+0.000000000000000E+00, 0) DEG (DEFAULT=0.0)', 'X-SHIFT=(+0.000000000000000E+00, 0) (DEFAULT=0.0)', 'Y-SHIFT=(+0.000000000000000E+00, 0) (DEFAULT=0.0)', 'Z-SHIFT=(+0.000000000000000E+00, 0) (DEFAULT=0.0)', '0000000000000000000000000000000000000000000000000000000000000000', 'SURFACE ( 3) Plane Z=-0.00 m', 'INDICES=( 0, 0, 0, 1, 0)', 'X-SCALE=(+1.000000000000000E+00, 0) (DEFAULT=1.0)', 'Y-SCALE=(+1.000000000000000E+00, 0) (DEFAULT=1.0)', 'Z-SCALE=(+1.000000000000000E+00, 0) (DEFAULT=1.0)', ' OMEGA=(+0.000000000000000E+00, 0) DEG (DEFAULT=0.0)', ' THETA=(+0.000000000000000E+00, 0) DEG (DEFAULT=0.0)', ' PHI=(+0.000000000000000E+00, 0) DEG (DEFAULT=0.0)', 'X-SHIFT=(+0.000000000000000E+00, 0) (DEFAULT=0.0)', 'Y-SHIFT=(+0.000000000000000E+00, 0) (DEFAULT=0.0)', 'Z-SHIFT=(-1.000000000000000E-01, 0) (DEFAULT=0.0)', '0000000000000000000000000000000000000000000000000000000000000000', 'SURFACE ( 4) Plane X=0.00 m', 'INDICES=( 0, 0, 0, 1, 0)', 'X-SCALE=(+1.000000000000000E+00, 0) (DEFAULT=1.0)', 'Y-SCALE=(+1.000000000000000E+00, 0) (DEFAULT=1.0)', 'Z-SCALE=(+1.000000000000000E+00, 0) (DEFAULT=1.0)', ' OMEGA=(+0.000000000000000E+00, 0) DEG (DEFAULT=0.0)', ' THETA=(+9.000000000000000E+01, 0) DEG (DEFAULT=0.0)', ' PHI=(+0.000000000000000E+00, 0) DEG (DEFAULT=0.0)', 'X-SHIFT=(+0.000000000000000E+00, 0) (DEFAULT=0.0)', 'Y-SHIFT=(+0.000000000000000E+00, 0) (DEFAULT=0.0)', 'Z-SHIFT=(+0.000000000000000E+00, 0) (DEFAULT=0.0)', '0000000000000000000000000000000000000000000000000000000000000000', 'MODULE ( 1) ', 'MATERIAL( 1)', 'SURFACE ( 1), SIDE POINTER=(-1)', 'SURFACE ( 2), SIDE POINTER=(-1)', 'SURFACE ( 3), SIDE POINTER=( 1)', 'SURFACE ( 4), SIDE POINTER=( 1)', '1111111111111111111111111111111111111111111111111111111111111111', ' OMEGA=(+0.000000000000000E+00, 0) DEG (DEFAULT=0.0)', ' THETA=(+0.000000000000000E+00, 0) DEG (DEFAULT=0.0)', ' PHI=(+0.000000000000000E+00, 0) DEG (DEFAULT=0.0)', 'X-SHIFT=(+0.000000000000000E+00, 0) (DEFAULT=0.0)', 'Y-SHIFT=(+0.000000000000000E+00, 0) (DEFAULT=0.0)', 'Z-SHIFT=(+0.000000000000000E+00, 0) (DEFAULT=0.0)', '0000000000000000000000000000000000000000000000000000000000000000', 'MODULE ( 2) ', 'MATERIAL( 2)', 'SURFACE ( 1), SIDE POINTER=(-1)', 'SURFACE ( 2), SIDE POINTER=(-1)', 'SURFACE ( 3), SIDE POINTER=( 1)', 'MODULE ( 1)', '1111111111111111111111111111111111111111111111111111111111111111', ' OMEGA=(+0.000000000000000E+00, 0) DEG (DEFAULT=0.0)', ' THETA=(+0.000000000000000E+00, 0) DEG (DEFAULT=0.0)', ' PHI=(+0.000000000000000E+00, 0) DEG (DEFAULT=0.0)', 'X-SHIFT=(+0.000000000000000E+00, 0) (DEFAULT=0.0)', 'Y-SHIFT=(+0.000000000000000E+00, 0) (DEFAULT=0.0)', 'Z-SHIFT=(+0.000000000000000E+00, 0) (DEFAULT=0.0)', '0000000000000000000000000000000000000000000000000000000000000000', 'MODULE ( 3) Extra module for rotation and tilt', 'MATERIAL( 0)', 'MODULE ( 2)', '1111111111111111111111111111111111111111111111111111111111111111', ' OMEGA=(+2.700000000000000E+02, 0) DEG (DEFAULT=0.0)', ' THETA=(+4.500000000000000E+01, 0) DEG (DEFAULT=0.0)', ' PHI=(+9.000000000000000E+01, 0) DEG (DEFAULT=0.0)', 'X-SHIFT=(+0.000000000000000E+00, 0) (DEFAULT=0.0)', 'Y-SHIFT=(+0.000000000000000E+00, 0) (DEFAULT=0.0)', 'Z-SHIFT=(+0.000000000000000E+00, 0) (DEFAULT=0.0)', '0000000000000000000000000000000000000000000000000000000000000000', 'END 0000000000000000000000000000000000000000000000000000000' ] 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 _test_geometry(self, geometry): self.assertEqual('Test Geometry', geometry.title) self.assertEqual(3, len(geometry.get_modules())) self.assertEqual(4, len(geometry.get_surfaces())) self.assertEqual(3, len(geometry.get_materials())) def testskeleton(self): self.assertEqual('Test Geometry', self.geo.title) self.assertEqual(2, len(self.geo.get_modules())) self.assertEqual(4, len(self.geo.get_surfaces())) self.assertEqual(2, len(self.geo.get_materials())) self.assertAlmostEqual(45, self.geo.tilt_deg, 4) self.assertAlmostEqual(0.0, self.geo.rotation_deg, 4) def testindexify(self): index_lookup = self.geo.indexify() # 4 surfaces, 2 materials, 2 modules, 1 extra module self.assertEqual(4 + 2 + 2 + 1, len(index_lookup)) index_lookup2 = self.geo.indexify() self.assertDictEqual(index_lookup, index_lookup2) def testwriteread(self): material_lookup = {0: VACUUM, 1: self.mat1, 2: self.mat2} fileobj = io.StringIO() try: self.geo.write(fileobj) fileobj.seek(0) lines = fileobj.getvalue().splitlines() self.assertListEqual(self.LINES[:3], lines[:3]) self.assertEqual(self.LINES[14], lines[14]) self.assertEqual(self.LINES[26], lines[26]) self.assertEqual(self.LINES[38], lines[38]) self.assertEqual(self.LINES[50], lines[50]) self.assertEqual(self.LINES[51], lines[51]) self.assertListEqual(self.LINES[57:65], lines[57:65]) self.assertEqual(self.LINES[65], lines[65]) self.assertListEqual(self.LINES[71:], lines[71:]) fileobj.seek(0) geometry = Geometry() geometry.read(fileobj, material_lookup) self._test_geometry(geometry) index_lookup = geometry.indexify() self.assertEqual(4 + 3 + 3, len(index_lookup)) finally: fileobj.close() def test_epma1_read(self): material_lookup = {1: self.mat1} filepath = os.path.join(self.testdatadir, 'epma1.geo') geometry = Geometry() with open(filepath, 'r') as fp: geometry.read(fp, material_lookup) self.assertEqual('Cylindrical homogeneous foil', geometry.title) self.assertEqual(3, len(geometry.get_surfaces())) self.assertEqual(1, len(geometry.get_modules())) self.assertEqual(1, len(geometry.get_materials())) def test_epma2_read(self): material_lookup = {1: self.mat1, 2: self.mat2} filepath = os.path.join(self.testdatadir, 'epma2.geo') geometry = Geometry() with open(filepath, 'r') as fp: geometry.read(fp, material_lookup) self.assertEqual('Cylindrical foil with a material couple', geometry.title) self.assertEqual(4, len(geometry.get_surfaces())) self.assertEqual(2, len(geometry.get_modules())) self.assertEqual(2, len(geometry.get_materials()))