Пример #1
0
def handle_meshtal(meshtal_file, gen_mmgrid, datafile, isscd=True):
    """Read MCNP meshtal file and tag mesh

    Parameters
    ----------
    mesh : ScdMesh or iMesh.Mesh()
        Mesh object to be tagged.
    gen_mmgrid : boolean
        Whether to generate a new macromaterials grid
    datafile : string
        File/path to mesh file to be created/loaded/tagged.
    isscd : boolean
        If True, handle geometry as a structured mesh. Otherwise mesh is
        assumed to be unstructured and unstructured mesh tally results are
        assumed to exist on the mesh (Error raised if tag TALLY_TAG is missing).
    """
    if not isscd:  # is unstructured
        mesh = iMesh.Mesh()
        mesh.load(datafile)
        try:
            mesh.getTagHandle("TALLY_TAG")
        except iBase.TagNotFoundError as e:
            print "Missing tag 'TALLY_TAG' suggests that '{0}' is missing " "unstructured mesh tally information.".format(
                datafile
            )
            raise e

        return mesh

    print "Loading mesh tally file `{0}'".format(meshtal_file)
    tally_numbers, tally_lines = find_tallies(meshtal_file)
    # If not regenerating the mmGrid info, attempt to load existing datafile
    if gen_mmgrid == False:
        print "Attempting to re-use existing ScdMesh file '{0}'".format(datafile)
        alt_sm = ScdMesh.fromFile(datafile)  # Note: ray tracing is done later
        try:
            mesh = read_meshtal(meshtal_file, tally_lines[0], mesh=alt_sm)
        except ScdMeshError:
            print "ERROR:"
            print "Existing mesh in '{0}' does not match mesh in '{1}'. " "Set the 'gen_mmgrid' option to True in your 'r2s.cfg' " "file.".format(
                datafile, meshtal_file
            )

    else:
        print "Creating ScdMesh file '{0}' from scratch.".format(datafile)
        mesh = read_meshtal(meshtal_file, tally_lines[0])

    return mesh
Пример #2
0
(gen_mmgrid, mmgrid_rays, opt_step2setup) = param_list



###########################
# Do step 1

print "Loading mesh tally file `{0}'".format(meshtal_file)
tally_numbers, tally_lines = find_tallies(meshtal_file)
# If not regenerating the mmGrid info, attempt to load existing datafile
if gen_mmgrid == False:
    print "Attempting to re-use existing ScdMesh file '{0}'".format(datafile)
    alt_sm = ScdMesh.fromFile(datafile)
    try:
        smesh = read_meshtal(meshtal_file, tally_lines[0], smesh=alt_sm)
    except ScdMeshError:
        print "ERROR:"
        print "Existing mesh in '{0}' does not match mesh in '{1}'. Set the " \
                "'gen_mmgrid' option to True in your 'r2s.cfg' file.".format( \
                datafile, meshtal_file)
        sys.exit()
else:
    smesh = read_meshtal(meshtal_file, tally_lines[0])

print "Loading geometry file `{0}'".format(mcnp_geom)
mmgrid.load_geom(mcnp_geom)

# Do ray tracing to create macromaterials, if enabled.
if gen_mmgrid:
    print "Will use {0} rays per mesh row".format(mmgrid_rays)