def test_detector_electron_fraction(self): # Create ops = Options(name='test1') ops.beam.energy_eV = 20e3 ops.detectors['fraction'] = ElectronFractionDetector() # Import resultscontainer = self.i.import_(ops, self.testdata) # Test self.assertEqual(1, len(resultscontainer)) result = resultscontainer['fraction'] self.assertAlmostEqual(0.5168187, result.backscattered[0], 4) self.assertAlmostEqual(7.5e-3, result.backscattered[1], 6) self.assertAlmostEqual(0.0, result.transmitted[0], 4) self.assertAlmostEqual(0.0, result.transmitted[1], 4) self.assertAlmostEqual(0.5113858, result.absorbed[0], 4) self.assertAlmostEqual(5.4e-3, result.absorbed[1], 6)
def testconvert_pencilbeam(self): # Base options ops = Options(name="Test") ops.beam = PencilBeam(1234) ops.limits.add(ShowersLimit(100)) ops.detectors['trajectories'] = TrajectoryDetector(False) # Convert with warnings.catch_warnings(record=True) as ws: opss = self.converter.convert(ops) # 7 warning: # PencilBeam -> GaussianBeam # Set default models (6) self.assertEqual(1, len(opss)) self.assertEqual(7, len(ws)) # Test self.assertAlmostEqual(1234, opss[0].beam.energy_eV, 4) self.assertAlmostEqual(0.0, opss[0].beam.diameter_m, 4) self.assertEqual(6, len(opss[0].models))
def testconvert1(self): # Base options ops = Options("Test") ops.beam.origin_m = (0.0, 0.0, 0.09) ops.limits.add(ShowersLimit(1234)) det = PhotonIntensityDetector((radians(35), radians(45)), (0, radians(360.0))) ops.detectors['det1'] = det # Convert opss = self.converter.convert(ops) self.assertEqual(1, len(opss)) self.assertEqual(1, len(opss[0].detectors)) self.assertEqual(1, len(opss[0].limits)) limit = list(ops.limits.iterclass(ShowersLimit))[0] self.assertEqual(1234, limit.showers) self.assertEqual(6, len(opss[0].models))
def testexport_horizontal_layers(self): # Create mat1 = PenelopeMaterial({79: 0.5, 47: 0.5}, 'mat1') mat2 = PenelopeMaterial({29: 0.5, 30: 0.5}, 'mat2') mat3 = PenelopeMaterial({13: 0.5, 14: 0.5}, 'mat3') ops = Options() ops.beam.energy_eV = 1234 ops.beam.diameter_m = 25e-9 ops.beam.origin_m = (100e-9, 0, 1) ops.geometry = HorizontalLayers(mat1) ops.geometry.add_layer(mat2, 52e-9) ops.geometry.add_layer(mat3, 25e-9) ops.limits.add(TimeLimit(100)) self.c._convert_geometry(ops) self.e.export_geometry(ops.geometry, self.tmpdir) # Test geofilepath = os.path.join(self.tmpdir, 'horizontallayers.geo') repfilepath = os.path.join(self.tmpdir, 'geometry.rep') nmat, nbody = pengeom.init(geofilepath, repfilepath) self.assertEqual(3, nmat) self.assertEqual(6, nbody) matfilepath = os.path.join(self.tmpdir, 'mat1.mat') self.assertTrue(os.path.exists(matfilepath)) matfilepath = os.path.join(self.tmpdir, 'mat2.mat') self.assertTrue(os.path.exists(matfilepath)) matfilepath = os.path.join(self.tmpdir, 'mat3.mat') self.assertTrue(os.path.exists(matfilepath))
fp.write(b'\x00\x00\x00\x00') # DELPHI: Inc(s,l);Blockwrite(Matfile,rho[0],l,f);Inc(Sum,f); fp.write(struct.pack('f', density_g_cm3)) # DELPHI: # l:=NC+1; # for i:=0 to NP do begin # Inc(s,l);BlockWrite(Matfile,PC[i],l,f);Inc(Sum,f); # end; fp.write(struct.pack('b', len(composition))) fp.write(b'\x00' * len(composition)) # DELPHI: Inc(s,l);BlockWrite(Matfile,PM,l,f);Inc(Sum,f); fp.write(struct.pack('b', len(composition))) for i in range(len(composition)): fp.write(struct.pack('b', i + 1)) return filepath if __name__ == '__main__': from pymontecarlo.options.options import Options from pymontecarlo.options.material import Material options = Options('test') options.geometry.body.material = Material({6: 0.4, 13: 0.1, 79: 0.5}) options.limits.add(ShowersLimit(1000)) Exporter().export(options, '/tmp')
sample = SubstrateSample(mat2) #sample = HorizontalLayerSample(mat3) #sample.add_layer(mat2, 10e-9) #sample.add_layer(mat3, 25e-9) #sample = VerticalLayerSample(mat1, mat2) #sample.add_layer(mat3, 10e-9) photon_detector = PhotonDetector('xray', math.radians(35.0)) analysis = KRatioAnalysis(photon_detector) limit = ShowersLimit(1000) options = Options(program, beam, sample, [analysis], [limit]) # Run simulation from pymontecarlo.runner.local import LocalSimulationRunner from pymontecarlo.project import Project project = Project() project.filepath = '/tmp/example.mcsim' with LocalSimulationRunner(project, max_workers=3) as runner: futures = runner.submit(options) print('{} simulations launched'.format(len(futures))) while not runner.wait(1): print(runner.progress)