Skip to content

Commit

Permalink
Adding capabilitiy of printing photon source totals
Browse files Browse the repository at this point in the history
  • Loading branch information
elliottbiondo committed Feb 12, 2016
1 parent 2d5c237 commit 2b1d979
Show file tree
Hide file tree
Showing 3 changed files with 53 additions and 3 deletions.
27 changes: 27 additions & 0 deletions pyne/r2s.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from os.path import isfile
from warnings import warn
from pyne.utils import QAWarning
import numpy as np

from pyne.mesh import Mesh
from pyne.mcnp import Meshtal
Expand Down Expand Up @@ -138,3 +139,29 @@ def photon_sampling_setup(mesh, phtn_src, tags):
photon_source_to_hdf5(phtn_src)
h5_file = phtn_src + ".h5"
photon_source_hdf5_to_mesh(mesh, h5_file, tags)


def total_photon_source_intensity(m, tag_name):
"""This function reads mesh tagged with photon source densities and returns
the total photon emission desinty.
Parameters
----------
m : PyNE Mesh
The mesh-based photon emission density distribution in p/cm3/s.
tag_name : str
The name of the tag on the mesh with the photon emission density information.
Returns
-------
intensity : float
The total photon emission density across the entire mesh (p/s).
"""

sd_tag = m.mesh.getTagHandle(tag_name)
intensity = 0.
for idx, _, ve in m:
vol = m.elem_volume(ve)
ve_data = sd_tag[ve]
intensity += vol*np.sum(ve_data)
return intensity
16 changes: 14 additions & 2 deletions scripts/r2s.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,9 @@
# The prefix of the .h5m files containing the source density distributations for
# each decay time.
output: source
# The name of the output files containing the total photon source intensities for
# each decay time
tot_phtn_src_intensities : total_photon_source_intensites.txt
"""

alara_params =\
Expand All @@ -66,7 +69,7 @@
output zone
integrate_energy
photon_source fendl3bin phtn_src1 24 1.00E4 2.00E4 5.00E4 1.00E5
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
1.40E7 2.00E7
Expand Down Expand Up @@ -142,16 +145,25 @@ def step2():
structured = config.getboolean('general', 'structured')
decay_times = config.get('step2', 'decay_times').split(',')
output = config.get('step2', 'output')
tot_phtn_src_intensities = config.get('step2', 'tot_phtn_src_intensities')
tag_name = "source_density"

h5_file = 'phtn_src.h5'
if not isfile(h5_file):
photon_source_to_hdf5('phtn_src')
intensities = "Total photon source intensities (p/s)\n"
for i, dc in enumerate(decay_times):
print('Writing source for decay time: {0}'.format(dc))
mesh = Mesh(structured=structured, mesh='blank_mesh.h5m')
tags = {('TOTAL', dc): 'source_density'}
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)

with open(tot_phtn_src_intensities, 'r') as f:
f.write(intensities)

print('R2S step2 complete.')

def main():
Expand Down
13 changes: 12 additions & 1 deletion tests/test_r2s.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@

from pyne.utils import QAWarning
warnings.simplefilter("ignore", QAWarning)
from pyne.r2s import irradiation_setup, photon_sampling_setup
from pyne.r2s import irradiation_setup, photon_sampling_setup, total_photon_source_intensity
from pyne.material import Material
from pyne.mesh import Mesh, IMeshTag
from pyne.mcnp import Meshtal
Expand Down Expand Up @@ -275,3 +275,14 @@ def test_photon_sampling_setup_unstructured():
for i, mat, ve in m:
assert_array_equal(m.tag1[i], exp_tag1[i])
assert_array_equal(m.tag2[i], exp_tag2[i])


def test_total_photon_source_intensity():

m = Mesh(structured = True, structured_coords=[[0, 1, 2],[0, 1, 3], [0, 1]])
m.source_density = IMeshTag(2, float)
m.source_density[:] = [[1., 2.], [3., 4.], [5., 6.], [7., 8.]]

intensity = total_photon_source_intensity(m, "source_density")
assert_equal(intensity, 58)

0 comments on commit 2b1d979

Please sign in to comment.