From abd3a3d98bbe6eb513aaf3c63b5743e5ea521c1a Mon Sep 17 00:00:00 2001 From: Elliott Biondo Date: Fri, 12 Feb 2016 14:53:20 -0600 Subject: [PATCH] Automatic printing of e_bounds file --- docs/usersguide/r2s.rst | 10 ++++++---- pyne/alara.py | 28 ++++++++++++++++++++++++++++ scripts/r2s.py | 20 +++++++++++++++----- tests/test_alara.py | 13 ++++++++++++- 4 files changed, 61 insertions(+), 10 deletions(-) diff --git a/docs/usersguide/r2s.rst b/docs/usersguide/r2s.rst index cfb858066f..ddca514c5b 100755 --- a/docs/usersguide/r2s.rst +++ b/docs/usersguide/r2s.rst @@ -105,11 +105,13 @@ decay time. These files will be named like: source_1.h5m, source_2.h5m ... source_N.h5m -These files can now be used as sources -for photon transport within MCNP. Information on compiling a version of MCNP5 -that can utilize these sources is found in the PyNE user's guide entry on +An "e_bounds" file containing the photon lower and upper energy bounds will also be generated. +These source files, combined with the "e_bounds" file can now be used as sources +for photon transport within MCNP. Information on compiling/using a version of MCNP5 +that can utilize these mesh-based sources is found in the PyNE user's guide entry on `mesh-based source sampling `_. -Note the each of these source files must be renamed to "source.h5m" for this purpose. By using these sources for photon transport, the shutdown dose rate can be obtained as a final answer. +Note that each of these source files must be renamed to "source.h5m" for this purpose. +By using these sources for photon transport, the shutdown dose rate can be obtained. Tally results will have to be normalized by the total photon source intentity. This information is found in the "total_photon_source_intensites.txt" file printed out by r2s.py step2. ********** References diff --git a/pyne/alara.py b/pyne/alara.py index 8885d40e7d..ae39fadc81 100644 --- a/pyne/alara.py +++ b/pyne/alara.py @@ -534,6 +534,34 @@ def irradiation_blocks(material_lib, element_lib, data_library, cooling, return s +def phtn_src_energy_bounds(input_file): + """Reads an ALARA input file and extracts the energy bounds from the + photon_source block. + + Parameters + ---------- + input_file : str + The ALARA input file name, which must contain a photon_source block. + + Returns + ------- + e_bounds : list of floats + The lower and upper energy bounds for the photon_source discretization. + """ + phtn_src_lines = "" + with open(input_file, 'r') as f: + line = f.readline() + while not (' photon_source ' in line and line.strip()[0] != "#"): + line = f.readline() + num_groups = float(line.split()[3]) + upper_bounds = [float(x) for x in line.split()[4:]] + while len(upper_bounds) < num_groups: + line = f.readline() + upper_bounds += [float(x) for x in line.split("#")[0].split('end')[0].split()] + e_bounds = [0.] + upper_bounds + return e_bounds + + def _build_matrix(N): """ This function builds burnup matrix, A. Decay only. """ diff --git a/scripts/r2s.py b/scripts/r2s.py index cac1583597..577e1eb1a8 100644 --- a/scripts/r2s.py +++ b/scripts/r2s.py @@ -5,8 +5,10 @@ from pyne.mesh import Mesh from pyne.dagmc import cell_materials, load -from pyne.r2s import irradiation_setup, photon_sampling_setup -from pyne.alara import photon_source_to_hdf5, photon_source_hdf5_to_mesh +from pyne.r2s import irradiation_setup, photon_sampling_setup,\ + total_photon_source_intensity +from pyne.alara import photon_source_to_hdf5, photon_source_hdf5_to_mesh,\ + phtn_src_energy_bounds from pyne.mcnp import Meshtal config_filename = 'config.ini' @@ -69,6 +71,7 @@ output zone integrate_energy + # Energy group upper bounds. The lower bound is always zero. photon_source fendl3bin phtn_src 24 1.00E4 2.00E4 5.00E4 1.00E5 2.00E5 3.00E5 4.00E5 6.00E5 8.00E5 1.00E6 1.22E6 1.44E6 1.66E6 2.00E6 2.50E6 3.00E6 4.00E6 5.00E6 6.50E6 8.00E6 1.00E7 1.20E7 @@ -158,12 +161,19 @@ def step2(): tags = {('TOTAL', dc): tag_name} photon_source_hdf5_to_mesh(mesh, h5_file, tags) mesh.mesh.save('{0}_{1}.h5m'.format(output, i+1)) - intensity = total_photon_source_intensity(m, tag_name) - intensities += "{0}: {1}".format(dc, intensity) + intensity = total_photon_source_intensity(mesh, tag_name) + intensities += "{0}: {1}\n".format(dc, intensity) - with open(tot_phtn_src_intensities, 'r') as f: + with open(tot_phtn_src_intensities, 'w') as f: f.write(intensities) + e_bounds = phtn_src_energy_bounds(alara_geom) + e_bounds_str = "" + for e in e_bounds: + e_bounds_str += "{0}\n".format(e) + with open("e_bounds", 'r') as f: + f.write(e_bounds_str) + print('R2S step2 complete.') def main(): diff --git a/tests/test_alara.py b/tests/test_alara.py index 93c7993335..b4c0b1a615 100644 --- a/tests/test_alara.py +++ b/tests/test_alara.py @@ -27,7 +27,7 @@ from pyne.material import Material from pyne.alara import mesh_to_fluxin, photon_source_to_hdf5, \ photon_source_hdf5_to_mesh, mesh_to_geom, num_density_to_mesh, \ - irradiation_blocks, record_to_geom + irradiation_blocks, record_to_geom, phtn_src_energy_bounds thisdir = os.path.dirname(__file__) @@ -429,3 +429,14 @@ def test_irradiation_blocks(): assert_equal(act, exp) +def test_phtn_src_energy_bounds(): + + input_file = os.path.join(thisdir, "files_test_alara", + "alara_other_blocks.txt") + e_bounds = phtn_src_energy_bounds(input_file) + expected_e_bounds = [0, 1.00E4, 2.00E4, 5.00E4, 1.00E5, 2.00E5, 3.00E5, + 4.00E5, 6.00E5, 8.00E5, 1.00E6, 1.22E6, 1.44E6, 1.66E6, + 2.00E6, 2.50E6, 3.00E6, 4.00E6, 5.00E6, 6.50E6, 8.00E6, + 1.00E7, 1.20E7, 1.40E7, 2.00E7] + + assert_array_equal(e_bounds, expected_e_bounds)