Skip to content

Commit

Permalink
Automatic printing of e_bounds file
Browse files Browse the repository at this point in the history
  • Loading branch information
elliottbiondo committed Feb 12, 2016
1 parent 2b1d979 commit abd3a3d
Show file tree
Hide file tree
Showing 4 changed files with 61 additions and 10 deletions.
10 changes: 6 additions & 4 deletions docs/usersguide/r2s.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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 <http://pyne.io/usersguide/source_sampling.html#source-sampling-in-mcnp5>`_.
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
Expand Down
28 changes: 28 additions & 0 deletions pyne/alara.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.
"""
Expand Down
20 changes: 15 additions & 5 deletions scripts/r2s.py
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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():
Expand Down
13 changes: 12 additions & 1 deletion tests/test_alara.py
Original file line number Diff line number Diff line change
Expand Up @@ -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__)

Expand Down Expand Up @@ -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)

0 comments on commit abd3a3d

Please sign in to comment.