r2s Package¶
r2s Package¶
The r2s package contains various accessory scripts, as well as the r2s.io package which handles interfacing with various file formats.
mcnp_n2p Module¶
Module contains class ModMCNPforPhotons which automates most of the conversion from an MCNP neutron transport problem to a photon transport problem with the same geometry/materials.
- class r2s.mcnp_n2p.ModMCNPforPhotons(myInputFileName, dagmc=None)¶
Bases: object
Class is used to convert a neutron problem in MCNP to a photon problem
An MCNP input file is read in, and stored in 4 parts: title card, block 1, block 2, and block 3.
- __init__(myInputFileName, dagmc=None)¶
Init function for class ModMCNPforPhotons.
Parameters : myInputFileName : string
MCNP input file.
dagmc : boolean
Whether to treat input as a DAGMCNP or regular MCNP input. By default, this is automatically determined.
- add_fmesh_from_scdmesh(sm)¶
Geometry information is read to create a photon fmesh card.
Lines are appended to self.block3Lines.
Parameters : sm : scdmesh.ScdMesh object
A structured mesh object (scdmesh.py) with mesh divisions in XYZ.
Returns : 1 if successful, 0 if an error occurs. :
Notes
Requires that block 3 has been read into self.block3Lines, and photon energies have been tagged to ‘sm.imesh.rootSet’.
- change_block_1()¶
Modify contents of self.block1Lines for a photon problem.
Method changes the importance cards to affect photons
Returns : ‘1’ when run successfully :
- change_block_2()¶
Modify contents of self.block2Lines for a photon problem (N/A).
Notes
Block 2 of MCNP input doesn’t depend on particle type Thus nothing is done.
- change_block_3()¶
Modify contents of self.block3Lines for a photon problem.
Notes
Method:
- changes the mode card from ‘mode n’ to ‘mode p’
- remove phys:n
- change inp:n to inp:p
- comments out any source-definition cards. These cards are:
sdef, si, sp, sb, sc, ds, kcode, ksrc
- convert()¶
Convert the blocks in MCNP input from neutron to photon problem.
- mcnp_block_parser(fr, blockLines, commentLines)¶
Read lines from input file until an entire block has been read.
Method receives a file reader, and reads lines until a blank line is encountered (or end of file)
Parameters : fr : file reading stream
...
blockLines : list
...
commentLines : list
...
Notes
Blank lines are tossed, and any comment lines beginning with c are tossed
Saved lines are added to a list and method returns this list.
- read()¶
Read an MCNP input file and store its parts in the object.
Notes
We clean the input file of a bunch of useless blank lines and lines filled with asterisks...
Saved lines are written to file tempFileName
Blocks 1 and 2 are used to create a surface parser object
- write_deck(outputFileName='')¶
Create a new MCNP input file from the object’s contents.
Method writes the contents of self.block#Lines to a new file. File name is determined automatically if not supplied.
Parameters : outputFileName : string
File path for created deck. If not specified, then the input file’s name is used, with an appened _p prior to any suffix (e.g. .inp).
Returns : N/A :
Notes
Requires that read() has been called for the class object so that ‘blockLines’ and ‘title’ are not empty.
- r2s.mcnp_n2p.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.
mmgrid Module¶
- class r2s.mmgrid.MatGrid(mesh)¶
Parent class for mmGrid-likes.
Daughter classes should define - create_tags() - generate()
- __init__(mesh)¶
- class r2s.mmgrid.SingleMatGrid(mesh)¶
Bases: r2s.mmgrid.MatGrid
Object representing a single material grid
Each voxel on the grid contains a single material.
- __init__(mesh)¶
Create a grid based on a given mesh
Tag voxels with each material
- generate()¶
Get voxel materials by getting voxel centers and checking with DagMC
- r2s.mmgrid.get_mat_id(materials, volume_id)¶
Returns : mat_idx : int?
- r2s.mmgrid.get_point_materials(materials, coords)¶
Query DAGMC for materials at a list of points
Parameters : materials : dictionary
...
coords : list of (x, y, z) float triplets
Point coordinates; typically for voxel centers.
Returns : mats : list of integers
List of integers corresponding material at each point in coords.
Notes
Requires that DagMC geometry has already been loaded via dagmc.load().
- r2s.mmgrid.get_vox_centers(mesh, voxels)¶
Calculate the center point of voxels and return a list of (x,y,z) coords
Parameters : mesh : iMesh.Mesh object
Mesh on which voxels are stored.
voxels : list of iBase.EntityHandles
List of volume entities on mesh to get center points of.
Returns : coords : list of (x, y, z) float triplets
Coordinates of voxel centers in mesh’s canonical voxel order.
- r2s.mmgrid.load_geom(filename)¶
Load geometry from the given file into dagmc
This is provided as a convenience so client code doesn’t need to invoke pydagmc. Note that DagMC can only have one set of geometry loaded per program invocation. This means that this function should only be called once, and the resulting geometry will become globally visible to all clients of mmgrid.
Parameters : filename : string
Filename with geometry information. Typically a .sat file.
- r2s.mmgrid.main(arguments=None)¶
- class r2s.mmgrid.mmGrid(scdmesh)¶
Bases: r2s.mmgrid.MatGrid
Object representing a macromaterial grid
- __init__(scdmesh)¶
Create a grid based on a given structured mesh
Tags material information to mesh
- classmethod fromDagGeom(ndiv=10)¶
Create a grid based on the geometry currently loaded in DagMC
Creates an equally spaced grid with ndiv divisions per side, set within the full DagMC geometry. This constructor requires that DagMC has geometry loaded with a rectangular graveyard volume
- generate(N, use_grid=False)¶
Sample the DagMC geometry and store the results on this grid.
N is the number of samples to take per voxel per dimension
- writeFile(filename, alara_geom_file=None)¶
Save mesh file, and optionally invoke creation of alara_geom file
- exception r2s.mmgrid.mmGridError¶
Bases: exceptions.Exception
- r2s.mmgrid.pairwise(l)¶
Generator: given a sequence x, yield (x[0],x[1]), (x[1],x[2]), ...
- r2s.mmgrid.prepare_materials()¶
Returns : names : ?
?
scdmesh Module¶
- class r2s.scdmesh.ScdMesh(x_points, y_points, z_points, imesh=None, **kw)¶
A structured mesh in the spirit of MOAB’s ScdMesh interface.
Public member variables:
self.imesh -- the iMesh instance in which this structured mesh resides self.dims -- A namedtuple indicating the minimum and maximum (i,j,k) coordinates of this structured mesh.
- __init__(x_points, y_points, z_points, imesh=None, **kw)¶
Construct a ScdMesh from given x, y, and z coordinates.
Parameters : x_points, y_points, z_points : list of floats
List of points. The i,j,k extents of the structured mesh will be numbered from 0.
imesh : iMesh.Mesh object
Parameter can be used to designate an iMesh instance in which to place the mesh; if None, a new instance will be created.
keyword arguments: :
- bdtag : iMesh.Tag handle
if the BOX_DIMS tag has already been looked up, it may be passed thus
- _scdset : iMesh.EntitySet handle (?)
an existing scdset to use; clients should use fromEntSet() instead of using this parameter.
- extents_tuple¶
alias of extents
- classmethod fromEntSet(imesh, eset)¶
Constructor function: create a ScdMesh from an existing entity set
The eset parameter must be a structured mesh set with the BOX_DIMS tag set on it.
- classmethod fromFile(filename, imesh=None)¶
Load structured meshes from a file
Returns one strutured mesh if the file contains one mesh, or a list if the file contains multiple meshes.
- getDivisions(dim)¶
Get the mesh divisions on a given dimension
Given a dimension ‘x’, ‘y’, or ‘z’, return a list of the mesh vertices along that dimension
- getHex(i, j, k)¶
Return the (i,j,k)’th hexahedron in the mesh
- getHexVolume(i, j, k)¶
Return the volume of the (i,j,k)’th hexahedron in the mesh
- getVtx(i, j, k)¶
Return the (i,j,k)’th vertex in the mesh
- iterateHex(order='zyx', **kw)¶
Get an iterator over the hexahedra of the mesh
The order argument specifies the iteration order. It must be a string of 1-3 letters from the set (x,y,z). The rightmost letter is the axis along which the iteration will advance the most quickly. Thus ‘zyx’ – x coordinates changing fastest, z coordinates changing least fast– is the default, and is identical to the order that would be given by the scdset.iterate() function.
When a dimension is absent from the order, iteration will proceed over only the column in the mesh that has the lowest corresonding (i/j/k) coordinate. Thus, with order ‘xy,’ iteration proceeds over the i/j plane of the structured mesh with the smallest k coordinate.
Specific slices can be specified with keyword arguments:
Keyword args:
x: specify one or more i-coordinates to iterate over. y: specify one or more j-coordinates to iterate over. z: specify one or more k-coordinates to iterate over.
Examples:
iterateHex(): equivalent to iMesh iterator over hexes in mesh iterateHex( 'xyz' ): iterate over entire mesh, with k-coordinates changing fastest, i-coordinates least fast. iterateHex( 'yz', x=3 ): Iterate over the j-k plane of the mesh whose i-coordinate is 3, with k values changing fastest. iterateHex( 'z' ): Iterate over k-coordinates, with i=dims.imin and j=dims.jmin iterateHex( 'yxz', y=(3,4) ): Iterate over all hexes with j-coordinate = 3 or 4. k-coordinate values change fastest, j-values least fast.
- iterateHexVolumes(order='zyx', **kw)¶
Get an iterator over the volumes of the mesh hexahedra
See iterateHex() for an explanation of the order argument and the available keyword arguments.
- iterateVtx(order='zyx', **kw)¶
Get an iterator over the vertices of the mesh
See iterateHex() for an explanation of the order argument and the available keyword arguments.
- exception r2s.scdmesh.ScdMeshError¶
Bases: exceptions.Exception
tag_ebins Module¶
Module contains the read_and_tag_phtn_ergs() and destroy_erg_bins_tag() methods. These are used for adding the photon energy group boundaries to a mesh; The functions are typically used when the user does not want to use the default 42 group structure for photons.
- r2s.tag_ebins.destroy_erg_bins_tag(sm)¶
Method removes the ‘PHTN_ERGS’ tag from a MOAB mesh
Parameters : sm : scdmesh.ScdMesh object
Structured mesh object with tags to be removed
Returns : return code :
1 if successful; 0 if failed.
- r2s.tag_ebins.main()¶
ACTION: Method defines an option parser and handles command-line usage of this module. REQUIRES: command line arguments to be passed - otherwise prints help information.
- r2s.tag_ebins.read_and_tag_phtn_ergs(fr, sm)¶
Method reads a file with a list of energies and tags them to the root set.
Method replaces the ‘PHTN_ERGS’ tag if it already exists.
Parameters : fr : readable file stream
a file stream listing one energy per line. It should have n+1 entries where n is the number of energy groups. Low energy first!
sm : scdmesh.ScdMesh object
Structured mesh object to tag energies to.
Notes
Reads a single energy from each line of ‘fr’, creating a list of these values. These values are tagged to the scdset of ‘sm’ with the tag handle ‘PHTN_ERGS’.
volumes Module¶
- r2s.volumes.calc_volume(mesh, voxel)¶
Calculates the volume of a hexahedral or tetrahedral voxel
Parameters : mesh : iMesh.Mesh object
Mesh object that includes voxel
voxel : iBase.Type.Region entity
Entity handle for the voxel for which volume is being found
Returns : volume : float
Volume of the voxel
Notes
Supports tetrahedral and hexahedral voxels only.
Code adapted from: http://pythonhosted.org/PyTAPS/tutorial/example.html?highlight=volume