io Package

read_alara_phtn Module

Module includes methods which find the lines in a ‘phtn_src’ file from ALARA that match a specified isotope and cooling time, and tags the photon source information to a mesh.

r2s.io.read_alara_phtn.get_cooling_step_name(coolingstep, fr)

Method determines the user-specified cooling step name in a phtn_src file

If coolingstep is a number, we search for the corresponding line in the file stream ‘fr’, and determine the corresponding cooling step string.

Parameters :

coolingstep : int or string

number for cooling step index or string for cooling step name

fr : readable file stream

Returns :

... : tuple

A 2 value tuple: (the cooling step string name, the number of photon energy bins used in the phtn_src file)

Notes

If coolingstep is not an integer, the calling function must catch a ValueError.

r2s.io.read_alara_phtn.main()

Method defines an option parser and handles command-line usage of this module.

Notes

Requires command line arguments to be passed - otherwise prints help information.

r2s.io.read_alara_phtn.read_to_h5m(inputfile, meshobj, isotope='TOTAL', coolingstep=0, retag=False, totals=False)

Read in a phtn_src file and tag the contents to a mesh.

Method reads in a phtn_src file line by line, looking for a specific isotope at a specific cooling step, and repeats for each voxel. Method tags the mesh with the photon source information, and then saves the mesh.

Parameters :

inputfile : string

Path to an ALARA-style ‘phtn_src’ file

meshobj : ScdMesh object

Structured mesh object to tag,

isotope : string

Isotope to read data for from ‘phtn_src’ file

coolingstep : int or string

String cooling step name, or number for index (0’th is ‘shutdown’)

retag : boolean

Whether to retag existing tags in mesh

totals : boolean

Whether to tag the total photon source strength for each voxel

r2s.io.read_alara_phtn.tag_phtn_src_totals(mesh, voxels, numergbins=-1, retag=False)

Method tags the total photon source strength for each voxel.

Method calculate the total photon source strength, and if retagging is enabled or the tag does not exist, tags the mesh.

Parameters :

mesh : iMesh.Mesh object

Mesh from which to get/create/delete tags

voxels : list of iMesh.Entity handles

List of voxel entity handles (iBase.Type.Region)

numergbins : int (optional)

Number of energy group tags to read

retag : boolean

Whether to overwrite existing ‘phtn_src_total’ tag. (Default: False)

read_meshtal Module

r2s.io.read_meshtal.find_first_line(meshtal, tally_line)

Searchs for the “Energy X Y Z” line, to determine the first line of data

Parameters :

meshtal : string

File path to meshtal file.

tally_line : int

Line number in file where tally begins

Returns :

m : int

Line number of first data line for the tally in meshtal

r2s.io.read_meshtal.find_mesh_bounds(meshtal, tally_line)

Parse the header of the meshtal to get the x, y, z, and energy boundaries

Parameters :

meshtal : string

File path to meshtal file.

tally_line : int

Line number in file where tally begins

Returns :

... : tuple of 4 ints

Tuple of the divisions in x, y, z and energy

r2s.io.read_meshtal.find_meshtal_type(meshtal, tally_line)

Searchs the meshtal header to determine if it is a neutron or photon meshtally

Parameters :

meshtal : string

File path to meshtal file.

tally_line : int

Line number in file where tally begins

Returns :

meshtal_type : {‘n’, ‘p’}

Tally type; either neutron (‘n’) or photon (‘p) is supported.

r2s.io.read_meshtal.find_tallies(meshtal)

Searches the meshtal file to determine the number of tallies present and returns the tallies and lines where they are listed.

Parameters :

meshtal : string

File path to meshtal file.

Returns :

tally_numbers : list of strings

List of tally numbers (as strings)

tally_lines : list of integers

List of the line numbers where tallies begin

r2s.io.read_meshtal.main(arguments=None)
r2s.io.read_meshtal.read_meshtal(filename, tally_line, norm=1.0, **kw)

Read an MCNP meshtal file and return a tagged structured mesh for it

The optional normalization factor will be multiplied into each flux value. This can be used to rescale a tally if a tally multiplier was not used in the original MCNP problem.

Parameters :

filename : string

File path to meshtal file.

tally_line : int

Line number in file where tally begins

norm : float, optional

Normalization factor to multiply into each flux value.

Keyword arguments: :

smesh: An existing scdmesh on which to tag the fluxes.

A ScdMeshError is raised if this mesh has incompatible ijk dims

Returns :

sm : ScdMesh object

Opened structured mesh from filename, with meshtally data tagged

r2s.io.read_meshtal.tag_fluxes(meshtal, meshtal_type, m, spatial_points, e_bins, sm, norm)

Tags the fluxes from a meshtally to a structured mesh.

Parameters :

meshtal : string

File path to meshtal file.

meshtal_type : {‘n’, ‘p’}

Tally type; either neutron (‘n’) or photon (‘p) is supported.

m : int

Line number of first data line for the tally in meshtal

spatial_points : int

Number of meshtally points (aka voxels)

e_bins : int

Number of energy bins in the meshtally

sm : scdmesh.ScdMesh

Structured mesh to tag fluxes to

norm : float, optional

Normalization factor to multiply into each flux value.

Returns :

N/A :

write_alara_fluxin Module

write_alara_fluxin.py is used to create a fluxin file for ALARA. Fluxes are taken from a MOAB mesh, with tag names of the form ‘n_group_###’ where ### is a 3 digit number with leading zeros as needed (e.g. 001).

r2s.io.write_alara_fluxin.find_num_e_groups(sm)

Return the number of energy groups used for neutron flux tags on a mesh

Parameters :

sm - Scdmesh.scmesh object :

Structured mesh object containing tags of the form ‘n_group_###’.

Returns :

num_e_groups - int :

Number of energy groups

r2s.io.write_alara_fluxin.get_flux_tag_handles(mesh)

Method identifies all tags containing flux information from a DAGMC meshtally

Parameters :

mesh : iMesh.Mesh object

MOAB mesh file object containing tags of the form “TALLY_TAG_lowE-highE”

Returns :

fluxtaghandles : list of iMesh.Tag objects

List of tag handles, sorted by tag name, from lowest energy to high

r2s.io.write_alara_fluxin.main()
r2s.io.write_alara_fluxin.print_fluxes(mesh, num_e_groups, backward_bool, fluxin_name, tags=None)

Method writes tag values to ALARA fluxin format for the flux at each energy for each voxel

Parameters :

mesh : iMesh.Mesh object

MOAB mesh file object containing tags of the form TALLY_TAG_lowE-highE

num_e_groups : integer

Number of energy groups in tally

backward_bool : boolean

If true, output data is in order from high energy to low energy. Note that this should be true when working with the FENDL libraries.

fluxin_name : string

Filename for output ALARA fluxin file

tags : list of iMesh.Tag objects

List of tag handles, sorted by tag name, from lowest energy to high

r2s.io.write_alara_fluxin.write_alara_fluxin(filename, mesh, backwards=False)

Load a MOAB mesh and create an alara_fluxin file from tags

Parameters :

filename - string :

Output filename for the fluxin file.

mesh - ScdMesh or iMesh.Mesh object :

MOAB mesh with tags to create fluxin file from.

backwards - boolean :

If true, prints fluxes from high energy to low energy. Note that this should be true when working with the FENDL libraries.

write_alara_geom Module

r2s.io.write_alara_geom.create_mixture_definitions(mesh)

Return a list of unique materials tagged onto the mesh.

unique_mixtures is a dictionary mapping mixture tuples (created through _create_mixture_tuple) to lists. The first element in the list is a unique integer ID for the mixtures; the rest of the elements are the hex handles that participate in that mixture.

mat_tags is a list of the material tags from the input mesh. This list is ordered in the same order as the mixture tuples.

Parameters :

mesh : ScdMesh object or iMesh.Mesh object

Mesh object to read materials data from

Returns :

... : tuple

A tuple of the list of mixtures and tag handles list; i.e. (unique_mixtures, mat_tags)

Notes

It is assumed that the mesh has the ‘matVOID’ tag.

r2s.io.write_alara_geom.main()
r2s.io.write_alara_geom.write_alara_geom(filename, mesh, namedict={})

Given a mesh with mmgrid tags, write an ALARA geometry file

Parameters :

filename : string

Path/filename of mesh file to write ALARA geometry to

mesh : ScdMesh object or iMesh.Mesh object

Mesh object containing materials tags

namedict : dictionary (optional)

Dictionary of names for material compositions

r2s.io.write_alara_geom.write_mat_loading(mesh, mat_tags, mixtures, output_file)

Write the mat_loading information to the ALARA geometry output

Parameters :

mesh : ScdMesh object or iMesh.Mesh object

Mesh object to read materials data from

mat_tags : ...

...

mixtures : ...

...

output_file : file object

Opened file for writing contents of ALARA geometry

r2s.io.write_alara_geom.write_mixtures(mixtures, mat_tags, name_dict, output_file)

Write the mixture lines to the ALARA geometry output

Parameters :

mixtures : ???

...

mat_tags : list of iMesh.Tag entities

...

name_dict : dictionary (optional?)

Dictionary of names for material compositions

output_file : file object

Opened file for writing contents of ALARA geometry

r2s.io.write_alara_geom.write_zones(mesh, output_file)

Write the volume and zone lines to the ALARA geometry output

Parameters :

mesh : ScdMesh object or iMesh.Mesh object

Mesh object to read materials data from

output_file : file object

Opened file for writing contents of ALARA geometry

write_gammas Module

r2s.io.write_gammas.calc_sm_volumes_list(sm)

Create a 1D list of the voxel volumes for a XYZ structured mesh

Parameters :

sm : ScdMesh object

A structured mesh object from which to calculate volumes.

Returns :

vols : list of floats

A 1D list of voxel volumes in order ‘xyz’

Notes

Voxel ordering follows meshtal file convention which is::
-for x for y iterate z -for x iterate y -iterate x
r2s.io.write_gammas.calc_total_source_strength(mesh, voxels, tag_srcsum=False, **kwargs)
r2s.io.write_gammas.gen_gammas_file_from_h5m(sm, outfile='gammas', sampling='v', do_bias=False, cumulative=False, cust_ergbins=False, resample=False, uni_resamp_all=False, **kwargs)

Generate gammas file using information from tags on a MOAB Scd mesh.

Method reads tags with photon source strengths from a structured mesh object and generates the gammas file for the modified source.F90 routine source_gamma.F90.

Parameters :

sm : ScdMesh

Structured mesh object to generate ‘gammas’ from.

outfile : string, optional

Output file name for the ‘gammas’ file

sampling : {‘v’, ‘u’}, optional

Format the file file for voxel sampling (‘v’) or uniform sampling (‘u’)

do_bias : boolean, optional

Attempt to tag bias values for voxels

cumulative : boolean, optional

Use the cumulative format for listing energy PDFs of each voxel

cust_ergbins : boolean, optional

Attempt to use custom energy bins found on ‘sm’

resample : boolean, optional

If true, ‘r’ flag is added to gammas, and resampling of particles starting in void regions of voxels is enabled.

uni_resamp_all : boolean, optional

If true, ‘a’ flag is added to gammas, and particles starting in void regions of voxels, during uniform sampling, are resampled over the entire problem, rather than resampling just the voxel. This has the potential to result in an unfair game.

keyword arguments :

Currently valid: {‘title’, ‘isotope’, ‘coolingstep’} These are passed to header creation code.

Notes

Requires that the structured mesh has photon source strength tags of the form ‘phtn_src_group_###’.

Will read photon energy bin boundary values if the root set has the tag ‘PHTN_ERG’ (a list of floats).

r2s.io.write_gammas.main()

Method defines an option parser and handles command-line usage of this module.

Notes

Requires command line arguments to be passed - otherwise prints help information.