Ejemplo n.º 1
0
def test_wwinp_to_h5m():
    thisdir = os.path.dirname(__file__)
    wwinp = os.path.join(thisdir, "files_test_wwinp_to_h5m/wwinp_test.e")
    output = os.path.join(os.getcwd(), "wwinp_mesh.h5m")

    if output in os.listdir("."):
        os.remove(output)

    wwinp_to_h5m.cartesian(wwinp, output)

    with open(output) as f:
        written = f.read()

    expected_sm = ScdMesh.fromFile(os.path.join(thisdir, "files_test_wwinp_to_h5m/expected_wwinp_mesh.h5m"))
    written_sm = ScdMesh.fromFile(output)

    for x in range(0, 5):
        for y in range(0, 6):
            for z in range(0, 10):
                expected_voxel = expected_sm.getHex(x, y, z)
                expected = expected_sm.imesh.getTagHandle("ww_n_group_001")[expected_voxel]
                written_voxel = written_sm.getHex(x, y, z)
                written = written_sm.imesh.getTagHandle("ww_n_group_001")[written_voxel]
                assert_equal(written, expected)

    os.remove(output)
Ejemplo n.º 2
0
def test_wwinp_to_h5m():
    wwinp = 'files_test_wwinp_to_h5m/wwinp_test.txt'
    output = 'wwinp_mesh.h5m'
    
    if output in os.listdir('.'):
        os.remove(output)
    
    wwinp_to_h5m.cartesian(wwinp, output)
    
    with open(output) as f:
        written = f.read()
    
    expected_sm = ScdMesh.fromFile('files_test_wwinp_to_h5m/expected_wwinp_mesh.h5m')
    written_sm = ScdMesh.fromFile(output)
    
    for x in range(0,5):
        for y in range(0,6):
            for z in range(0,10):
                expected_voxel = expected_sm.getHex(x,y,z)
                expected = expected_sm.imesh.getTagHandle('ww_n_group_001')[expected_voxel]
                written_voxel = written_sm.getHex(x,y,z)
                written = written_sm.imesh.getTagHandle('ww_n_group_001')[written_voxel]
                assert_equal(written, expected)
    
    os.remove(output)
Ejemplo n.º 3
0
def test_wwinp_to_h5m_1D_p():
    thisdir = os.path.dirname(__file__)
    wwinp = os.path.join(thisdir, 'files_test_wwinp_to_h5m/1D_p.e')
    expected_file = os.path.join(thisdir, 'files_test_wwinp_to_h5m/expected_ww_mesh_1D_p.h5m')

    written_sm = wwinp_to_h5m.cartesian(wwinp)
    expected_sm = ScdMesh.fromFile(expected_file)
 
    #verify weight window lower bounds are the same
    for x in range(0,1):
        for y in range(0,1):
            for z in range(0,9):
                expected_voxel = expected_sm.getHex(x,y,z)
                expected = expected_sm.imesh.getTagHandle('ww_n_group_001')[expected_voxel]
                written_voxel = written_sm.getHex(x,y,z)
                written = written_sm.imesh.getTagHandle('ww_n_group_001')[written_voxel]
                assert_equal(written, expected)

    #verify correct particle identifier
    assert_equal(written_sm.imesh.getTagHandle('particle')[written_sm.imesh.rootSet], 1)

    #verify correct energy upper bounds
    expected_E = 100
    written_E = written_sm.imesh.getTagHandle('E_upper_bounds')[written_sm.imesh.rootSet]

    assert_equal(written_E, expected_E)
Ejemplo n.º 4
0
def 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.
    """

    usage = "usage: %prog ENERGY_FILE MESH_FILE [options] \n\n" \
            "ENERGY_FILE is a list of the energy bins for each photon energy " \
            "group, with a single energy per line. MESH_FILE is the MOAB " \
            "mesh that will store the contents of ENERGY_FILE in the tag " \
            "'PHTN_ERGS'."
    parser = OptionParser(usage)

    (options, args) = parser.parse_args()

    fr = open(args[0])
    sm = ScdMesh.fromFile(args[1])

    # Call the method to read fr and tag mesh
    read_and_tag_phtn_ergs(fr, sm)

    mesh.save(args[1])
    fr.close()

    return 1
Ejemplo n.º 5
0
def main( arguments = None ):

    #Instatiate options parser
    parser = OptionParser\
             (usage='%prog <ww mesh> [options]')

    parser.add_option('-o', dest='output_name', default='wwinp.out',\
        help='Name of WWINP output file, default=%default')

    parser.add_option('-t', action='store_true', dest='totals_bool',\
        default=False, \
        help='If multiple energy groups exist, only use Total \
         default=%default')

    (opts, args) = parser.parse_args( arguments )

    if len(args) != 1:
        parser.error\
        ( '\nNeed exactly 1 argument: <ww mesh>' )

    # load mesh
    ww_mesh = ScdMesh.fromFile(args[0])


    write_wwinp(ww_mesh, opts.totals_bool, opts.output_name)

    print "\tWrote WWINP file '{0}'".format(opts.output_name)

    print "Complete"
Ejemplo n.º 6
0
def 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.
    """

    usage = "usage: %prog input-h5m-file [options] arg"
    parser = OptionParser(usage)

    # Input and mesh file names
    parser.add_option("-o","--output",action="store",dest="output", \
            default="gammas",help="Option specifies the name of the 'gammas'" \
            "file. Default: %default")
    #

    (options, args) = parser.parse_args()

    # Create ScdMesh object, which also loads 'meshfile' into mesh.
    sm = ScdMesh.fromFile(args[0])

    gen_gammas_file_from_h5m(sm, options.output)

    return 1
Ejemplo n.º 7
0
def test_wwinp_to_h5m_3D_n():
    thisdir = os.path.dirname(__file__)
    wwinp = os.path.join(thisdir, 'files_test_wwinp_to_h5m/3D_n.e')
    expected_file = os.path.join(
        thisdir, 'files_test_wwinp_to_h5m/expected_ww_mesh_3D_n.h5m')

    written_sm = wwinp_to_h5m.cartesian(wwinp)
    expected_sm = ScdMesh.fromFile(expected_file)

    #verify weight window lower bounds are the same
    for x in range(0, 14):
        for y in range(0, 8):
            for z in range(0, 6):
                for e_group in range(1, 8):
                    expected_voxel = expected_sm.getHex(x, y, z)
                    expected = expected_sm.imesh.getTagHandle(
                        'ww_n_group_00{0}'.format(e_group))[expected_voxel]
                    written_voxel = written_sm.getHex(x, y, z)
                    written = written_sm.imesh.getTagHandle(
                        'ww_n_group_00{0}'.format(e_group))[written_voxel]
                    assert_equal(written, expected)

    #verify correct particle identifier
    assert_equal(
        written_sm.imesh.getTagHandle('particle')[written_sm.imesh.rootSet], 1)

    #verify correct energy upper bounds
    expected_E = [1E-9, 1E-8, 1E-7, 1E-6, 1E-5, 1E-4, 1E-3]
    written_E = written_sm.imesh.getTagHandle('E_upper_bounds')[
        written_sm.imesh.rootSet]

    for i in range(0, len(expected_E)):
        assert_equal(written_E[i], expected_E[i])
Ejemplo n.º 8
0
def test_wwinp_to_h5m_1D_p():
    thisdir = os.path.dirname(__file__)
    wwinp = os.path.join(thisdir, 'files_test_wwinp_to_h5m/1D_p.e')
    expected_file = os.path.join(
        thisdir, 'files_test_wwinp_to_h5m/expected_ww_mesh_1D_p.h5m')

    written_sm = wwinp_to_h5m.cartesian(wwinp)
    expected_sm = ScdMesh.fromFile(expected_file)

    #verify weight window lower bounds are the same
    for x in range(0, 1):
        for y in range(0, 1):
            for z in range(0, 9):
                expected_voxel = expected_sm.getHex(x, y, z)
                expected = expected_sm.imesh.getTagHandle(
                    'ww_n_group_001')[expected_voxel]
                written_voxel = written_sm.getHex(x, y, z)
                written = written_sm.imesh.getTagHandle(
                    'ww_n_group_001')[written_voxel]
                assert_equal(written, expected)

    #verify correct particle identifier
    assert_equal(
        written_sm.imesh.getTagHandle('particle')[written_sm.imesh.rootSet], 1)

    #verify correct energy upper bounds
    expected_E = 100
    written_E = written_sm.imesh.getTagHandle('E_upper_bounds')[
        written_sm.imesh.rootSet]

    assert_equal(written_E, expected_E)
Ejemplo n.º 9
0
def main(arguments=None):

    #Instatiate options parser
    parser = OptionParser\
             (usage='%prog <ww mesh> [options]')

    parser.add_option('-o', dest='output_name', default='wwinp.out',\
        help='Name of WWINP output file, default=%default')

    parser.add_option('-t', action='store_true', dest='totals_bool',\
        default=False, \
        help='If multiple energy groups exist, only use Total \
         default=%default'                          )

    (opts, args) = parser.parse_args(arguments)

    if len(args) != 1:
        parser.error\
        ( '\nNeed exactly 1 argument: <ww mesh>' )

    # load mesh
    ww_mesh = ScdMesh.fromFile(args[0])

    write_wwinp(ww_mesh, opts.totals_bool, opts.output_name)

    print "\tWrote WWINP file '{0}'".format(opts.output_name)

    print "Complete"
Ejemplo n.º 10
0
def test_h5m_to_wwinp_3D_n():
    thisdir = os.path.dirname(__file__)
    ww_sm_filename = os.path.join(
        thisdir, 'files_test_wwinp_to_h5m/expected_ww_mesh_3D_n.h5m')
    ww_sm = ScdMesh.fromFile(ww_sm_filename)
    output = os.path.join(os.getcwd(), 'test.e')
    expected_output = os.path.join(thisdir, 'files_test_wwinp_to_h5m/3D_n.e')

    if output in os.listdir('.'):
        os.remove(output)

    totals_bool = False
    h5m_to_wwinp.write_wwinp(ww_sm, totals_bool, output)

    with open(output) as f:
        written = f.readlines()

    with open(expected_output) as f:
        expected = f.readlines()

    # check to make sure the first line is the same except for the date
    assert_equal(written[0].split()[:-2], expected[0].split()[:-2])

    # check to make sure files are the same length
    assert_equal(len(written), len(expected))

    # check to make sure the rest of the lines have the same values
    # since the number formats are different, float comparisons are used
    for i in range(1, len(expected)):
        for j in range(0, len(expected[i].split())):
            assert_equal(float(written[i].split()[j]),
                         float(expected[i].split()[j]))

    os.remove(output)
Ejemplo n.º 11
0
def 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.
    """

    usage = "usage: %prog ENERGY_FILE MESH_FILE [options] \n\n" \
            "ENERGY_FILE is a list of the energy bins for each photon energy " \
            "group, with a single energy per line. MESH_FILE is the MOAB " \
            "mesh that will store the contents of ENERGY_FILE in the tag " \
            "'PHTN_ERGS'."
    parser = OptionParser(usage)

    (options, args) = parser.parse_args()

    fr = open(args[0])
    sm = ScdMesh.fromFile(args[1])

    # Call the method to read fr and tag mesh
    read_and_tag_phtn_ergs(fr, sm)

    sm.scdset.save(args[1])
    fr.close()

    return 1
Ejemplo n.º 12
0
def 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.
    """

    usage = "usage: %prog input-h5m-file [options] arg"
    parser = OptionParser(usage)
    
    # Input and mesh file names
    parser.add_option("-o","--output",action="store",dest="output", \
            default="gammas",help="Option specifies the name of the 'gammas'" \
            "file. Default: %default")
    #
   
    (options, args) = parser.parse_args()

    # Create ScdMesh object, which also loads 'meshfile' into mesh.
    sm = ScdMesh.fromFile(args[0])

    gen_gammas_file_from_h5m(sm, options.output)

    return 1
Ejemplo n.º 13
0
def test_wwinp_to_h5m_3D_n():
    thisdir = os.path.dirname(__file__)
    wwinp = os.path.join(thisdir, 'files_test_wwinp_to_h5m/3D_n.e')
    expected_file = os.path.join(thisdir, 'files_test_wwinp_to_h5m/expected_ww_mesh_3D_n.h5m')

    written_sm = wwinp_to_h5m.cartesian(wwinp)
    expected_sm = ScdMesh.fromFile(expected_file)
    
    #verify weight window lower bounds are the same
    for x in range(0,14):
        for y in range(0,8):
            for z in range(0,6):
                for e_group in range(1, 8):
                    expected_voxel = expected_sm.getHex(x,y,z)
                    expected = expected_sm.imesh.getTagHandle('ww_n_group_00{0}'.format(e_group))[expected_voxel]
                    written_voxel = written_sm.getHex(x,y,z)
                    written = written_sm.imesh.getTagHandle('ww_n_group_00{0}'.format(e_group))[written_voxel]
                    assert_equal(written, expected)

    #verify correct particle identifier
    assert_equal(written_sm.imesh.getTagHandle('particle')[written_sm.imesh.rootSet], 1)

    #verify correct energy upper bounds
    expected_E = [1E-9, 1E-8, 1E-7, 1E-6, 1E-5, 1E-4, 1E-3]
    written_E = written_sm.imesh.getTagHandle('E_upper_bounds')[written_sm.imesh.rootSet]
    
    for i in range(0, len(expected_E)):
        assert_equal(written_E[i], expected_E[i])
Ejemplo n.º 14
0
def test_h5m_to_wwinp_3D_n():
    thisdir = os.path.dirname(__file__)
    ww_sm_filename = os.path.join(thisdir, 'files_test_wwinp_to_h5m/expected_ww_mesh_3D_n.h5m')
    ww_sm = ScdMesh.fromFile(ww_sm_filename)
    output = os.path.join(os.getcwd(), 'test.e')
    expected_output = os.path.join(thisdir, 'files_test_wwinp_to_h5m/3D_n.e')
    
    if output in os.listdir('.'):
        os.remove(output)
    
    totals_bool = False 
    h5m_to_wwinp.write_wwinp(ww_sm, totals_bool, output)
    
    with open(output) as f:
        written = f.readlines()

    with open(expected_output) as f:
        expected = f.readlines()

    # check to make sure the first line is the same except for the date
    assert_equal(written[0].split()[:-2], expected[0].split()[:-2])

    # check to make sure files are the same length
    assert_equal(len(written), len(expected))

    # check to make sure the rest of the lines have the same values
    # since the number formats are different, float comparisons are used
    for i in range(1, len(expected)):
        for j in range(0, len(expected[i].split())):
            assert_equal(float(written[i].split()[j]), float(expected[i].split()[j]))

    os.remove(output)
Ejemplo n.º 15
0
def main( arguments = None ) :

    # Instantiate option parser
    parser = OptionParser\
             (usage='%prog <meshtal_file> <normalization_factor> [options]')

    parser.add_option('-o', dest='mesh_output', default='flux_mesh.h5m',\
                      help = 'Name of mesh output file, default=%default.\
                             For meshtal files with multiple tallies,\
                             if the -o flag is used all tallies must be named,\
                             with file names seperated by commas and no spaces\
                             (e.g. "tally14.h5m,tally24.h5m,tally34.h5m")')
    parser.add_option('-n', dest='norm', default=None,
                      help='Normalization factor, default=%default,\
                            For meshtal files with multiple tallies, if the -n\
                            flag is used, a normalization factor must be\
                            specified for all tallies, seperated by commas but \
                            not spaces (eg. -n 1.1,2.2,3.3) ')
    parser.add_option('-m', dest='smesh_filename', default=None,
                      help='Preexisting mesh on which to tag fluxes')
                         

    (opts, args) = parser.parse_args(arguments)
    
    #if len(args) != 2 :
     #   parser.error('\nNeed 1 argument: meshtal file')
    print "\n\nRunning read_meshtal.py"
    tally_numbers, tally_lines = find_tallies(args[1])
    print "Number of tallies found: {0}\nTally number(s): {1}" \
                                     .format(len(tally_numbers), tally_numbers)

    # Parse input from options parser, generate default values
    if opts.norm :
        norm = opts.norm.split(',')
    else :
        norm = [1]*len(tally_numbers)

    if opts.mesh_output !='flux_mesh.h5m' :
        mesh_output = opts.mesh_output.split(',')
    else:
        mesh_output = []
        for n in range(0, len(tally_numbers)) :
            if len(tally_numbers) == 1 :
                mesh_output.append('flux_mesh.h5m')
            else :
                mesh_output.append('flux_mesh_tally{0}.h5m'.format(tally_numbers[n]))

    # Convert each tally to h5m and name accordingly
    for n in range(0,len(tally_numbers)) :
        print "\nNow parsing tally number {0}".format(tally_numbers[n])
        if opts.smesh_filename:
            alt_sm = ScdMesh.fromFile(opts.smesh_filename)
            sm = read_meshtal(args[1], tally_lines[n], float(norm[n]), smesh=alt_sm)
        else:
            sm = read_meshtal(args[1], tally_lines[n],float(norm[n]))
        sm.scdset.save(mesh_output[n])

        print "\tSaved tally {0} as {1}".format(tally_numbers[n], mesh_output[n])
    print "\nStructured mesh tagging complete\n\n"
Ejemplo n.º 16
0
 def test_vox_cum(self):
     """Verify gammas file for voxel sampling with cumulative bins"""
     self.meshfile = meshfile_g
     self.sm = ScdMesh.fromFile(self.meshfile)
     write_gammas.gen_gammas_file_from_h5m(self.sm,
                                           outfile,
                                           cumulative=True)
     self.compare_gammas(outfile, gammas7)
Ejemplo n.º 17
0
 def test_uni_seq_bias(self):
     """Verify gammas file for uniform sampling with sequential bins and biasing"""
     self.meshfile = meshfile_g
     self.sm = ScdMesh.fromFile(self.meshfile)
     write_gammas.gen_gammas_file_from_h5m(self.sm,
                                           outfile,
                                           sampling='u',
                                           do_bias=True)
     self.compare_gammas(outfile, gammas2)
Ejemplo n.º 18
0
def write_magic(flux_mesh_filename, ww_inp_mesh_filename, totals_bool, \
                null_value, output_mesh, tolerance):
    """
    This function takes the filename of the flux mesh and optional wieght window
    mesh, as well necessary parameter, sends them to the magic funtion and
    writes the resulting wieght window mesh.

    Parameters
    ----------
    flux_mesh_filename: ScdMesh file name.
        A ScdMesh tagged with fluxes in the form X_group_YYY and or
        X_group_total. Addition required tags are "particle" (1 for n, 2 for p) 
        and E_group_bounds (vector of energy upper bounds).
    totals_bool : True or False
        Determines whether magic will be applied to individual energy group
        (False), or the total group (True)
    null_value : float
        The weight window lower bound value that is assigned to voxels where the
        relative error on flux exceeds the tolerance. This is only done for 
        initial weight window lower bound generation, not subsequent iterations.
    output_mesh : string
        Filename of output mesh
    tolerance: float
        The maximum relative error allowable for the MAGIC algorithm to create
        a weight window lower bound for for a given voxel for the intial weight
        window lower bound generation, or overwrite preexisting weight window
        lower bounds for subsequent iterations.  
    ww_inp_mesh_filename : ScdMesh file name
        A preexisting weight window mesh to apply MAGIC to.      
    """

    flux_mesh = ScdMesh.fromFile(flux_mesh_filename)

    if ww_inp_mesh_filename != None:
        ww_inp_mesh = ScdMesh.fromFile(ww_inp_mesh_filename)

    else:
        ww_inp_mesh = None
   

    ww_mesh = magic(flux_mesh, totals_bool, null_value, tolerance, ww_inp_mesh)
    ww_mesh.scdset.save(output_mesh)
    print "\tWrote WW mesh file '{0}'".format(output_mesh)
Ejemplo n.º 19
0
def write_magic(flux_mesh_filename, ww_inp_mesh_filename, totals_bool, \
                null_value, output_mesh, tolerance):
    """
    This function takes the filename of the flux mesh and optional wieght window
    mesh, as well necessary parameter, sends them to the magic funtion and
    writes the resulting wieght window mesh.

    Parameters
    ----------
    flux_mesh_filename: ScdMesh file name.
        A ScdMesh tagged with fluxes in the form X_group_YYY and or
        X_group_total. Addition required tags are "particle" (1 for n, 2 for p) 
        and E_group_bounds (vector of energy upper bounds).
    totals_bool : True or False
        Determines whether magic will be applied to individual energy group
        (False), or the total group (True)
    null_value : float
        The weight window lower bound value that is assigned to voxels where the
        relative error on flux exceeds the tolerance. This is only done for 
        initial weight window lower bound generation, not subsequent iterations.
    output_mesh : string
        Filename of output mesh
    tolerance: float
        The maximum relative error allowable for the MAGIC algorithm to create
        a weight window lower bound for for a given voxel for the intial weight
        window lower bound generation, or overwrite preexisting weight window
        lower bounds for subsequent iterations.  
    ww_inp_mesh_filename : ScdMesh file name
        A preexisting weight window mesh to apply MAGIC to.      
    """

    flux_mesh = ScdMesh.fromFile(flux_mesh_filename)

    if ww_inp_mesh_filename != None:
        ww_inp_mesh = ScdMesh.fromFile(ww_inp_mesh_filename)

    else:
        ww_inp_mesh = None

    ww_mesh = magic(flux_mesh, totals_bool, null_value, tolerance, ww_inp_mesh)
    ww_mesh.scdset.save(output_mesh)
    print "\tWrote WW mesh file '{0}'".format(output_mesh)
Ejemplo n.º 20
0
def 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.
    """

    usage = "usage: %prog [options] arg"
    parser = OptionParser(usage)
    
    # Input and mesh file names
    parser.add_option("-p","--phtn",action="store",dest="phtnsrcfile", \
            default=False,help="The photon source strengths are read from" \
            "FILENAME.")
    parser.add_option("-m","--mesh",action="store",dest="meshfile", \
            default="",help="file to write source information to, or" \
            " file name for saving a modified mesh.")
    # Other options
    parser.add_option("-i","--isotope",action="store",dest="isotope", \
            default="TOTAL",help="The isotope string identifier or 'TOTAL'. "\
            "Default: %default")
    parser.add_option("-c","--coolingstep",action="store",dest="coolingstep", \
            default=0,help="The cooling step number or string identifier. " \
            "(0 is first cooling step)  Default: %default")
    parser.add_option("-r","--retag",action="store_true",dest="retag", \
            default=False,help="Option enables retagging of .h5m meshes. " \
            "Default: %default")
    parser.add_option("-t","--totals",action="store_true",dest="totals", \
            default=False,help="Option enables adding the total photon " \
            "source strength for all energy groups as a tag for each voxel. " \
            "Default: %default")

    (options, args) = parser.parse_args()

    # Open an ScdMesh and then call read_to_h5m
    try:
        mesh = ScdMesh.fromFile(options.meshfile)
    except ScdMeshError:
        mesh = iMesh.Mesh()
        mesh.load(options.meshfile)

    read_to_h5m( \
                options.phtnsrcfile, mesh, options.isotope, \
                options.coolingstep, options.retag, options.totals)

    if isinstance(mesh, ScdMesh):
        mesh.imesh.save(options.meshfile)
    else:
        mesh.save(options.meshfile)

    return 1
Ejemplo n.º 21
0
def magic(flux_h5m, ww_mesh, total_bool, null_value, output, output_mesh, tolerance):
    """Runs magic.py from as a module
    """
    flux_mesh = ScdMesh.fromFile(flux_h5m)

    ww_mesh, e_groups = magic_wwinp(flux_mesh, ww_mesh, total_bool, null_value, tolerance)

    if output_mesh != 'None':
        ww_mesh.scdset.save(output_mesh)

    write_wwinp(ww_mesh, e_groups, output)
Ejemplo n.º 22
0
def main( arguments = None ) :

   #Instantiate option parser
    parser = OptionParser\
             (usage='%prog <meshtal_file> <normalization_factor> [options]')

    parser.add_option('-o', dest='mesh_output', default=None,\
                      help = 'Name of mesh output file, default=%default')
    parser.add_option('-n', dest='norm', default=None,
                      help = 'Normalization factor, default=%default')
    parser.add_option('-m', dest='smesh_filename', default=None,
                      help='Preexisting mesh on which to tag fluxes')
                         

    (opts, args) = parser.parse_args(arguments)
    
    #if len(args) != 2 :
     #   parser.error('\nNeed 1 argument: meshtal file')
    print "\n\nRunning read_meshtal.py"
    tally_numbers, tally_lines = find_tallies(args[1])
    print 'Number of tallies found: {0}\nTally number(s): {1}'\
                                     .format(len(tally_numbers), tally_numbers)

    # Parse input from options parser, generate default values
    if opts.norm :
        norm = opts.norm.split(',')
    else :
        norm=[1]*len(tally_numbers)

    if opts.mesh_output :
        mesh_output = opts.mesh_output.split(',')
    else:
        mesh_output=[]
        for n in range(0, len(tally_numbers)) :
            if len(tally_numbers) == 1 :
                mesh_output.append('flux_mesh.h5m')
            else :
                mesh_output.append('flux_mesh_tally{0}.h5m'.format(tally_numbers[n]))
    

    # Convert each tally to h5m and name accordingly
    for n in range(0,len(tally_numbers)) :
        print "\nNow parsing tally number {0}".format(tally_numbers[n])
        if opts.smesh_filename:
            alt_sm = ScdMesh.fromFile(opts.smesh_filename)
            sm = read_meshtal(args[1], tally_lines[n], float(norm[n]), smesh=alt_sm)
        else:
            sm = read_meshtal(args[1], tally_lines[n],float(norm[n]))

        sm.scdset.save(mesh_output[n])

        print "\tSaved tally {0} as {1}".format(tally_numbers[n], mesh_output[n])
    print '\nStructured mesh tagging complete\n\n'
Ejemplo n.º 23
0
def test_magic_it_0_1_group():
    thisdir = os.path.dirname(__file__)
    flux_sm_filename = os.path.join(thisdir, "files_test_magic/iteration_0_flux_1_group.h5m")
    flux_sm = ScdMesh.fromFile(flux_sm_filename)
    expected_sm_filename = os.path.join(thisdir, "files_test_magic/iteration_0_magic_1_group.h5m")
    expected_sm = ScdMesh.fromFile(expected_sm_filename)

    totals_bool = False
    null_value = 1e-3
    tolerance = 0.2

    written_sm = magic.magic(flux_sm, totals_bool, null_value, tolerance)

    # verify weight window lower bounds are the same
    for x in range(0, 3):
        for y in range(0, 3):
            for z in range(0, 3):
                expected_voxel = expected_sm.getHex(x, y, z)
                expected = expected_sm.imesh.getTagHandle("ww_n_group_001")[expected_voxel]
                written_voxel = written_sm.getHex(x, y, z)
                written = written_sm.imesh.getTagHandle("ww_n_group_001")[written_voxel]
                assert_equal(written, expected)
Ejemplo n.º 24
0
def test_magic_it_0_1_group():
    thisdir = os.path.dirname(__file__)
    flux_sm_filename = os.path.join(thisdir, 'files_test_magic/iteration_0_flux_1_group.h5m')
    flux_sm = ScdMesh.fromFile(flux_sm_filename)
    expected_sm_filename = os.path.join(thisdir, 'files_test_magic/iteration_0_magic_1_group.h5m')   
    expected_sm = ScdMesh.fromFile(expected_sm_filename)    

    totals_bool = False
    null_value = 1E-3
    tolerance = 0.2

    written_sm = magic.magic(flux_sm, totals_bool, null_value, tolerance)
    
    #verify weight window lower bounds are the same
    for x in range(0,3):
        for y in range(0,3):
            for z in range(0,3):
                expected_voxel = expected_sm.getHex(x,y,z)
                expected = expected_sm.imesh.getTagHandle('ww_n_group_001')[expected_voxel]
                written_voxel = written_sm.getHex(x,y,z)
                written = written_sm.imesh.getTagHandle('ww_n_group_001')[written_voxel]
                assert_equal(written, expected)
Ejemplo n.º 25
0
    def test_create_by_file(self):
        filename = os.path.join(os.path.dirname(__file__), 'h5m_files/grid543.h5m')
        sm = ScdMesh.fromFile(filename)
        self.assertEqual( sm.dims, (1, 11, -5, 5, 14, -3) )

        # This mesh is interesting because the i/j/k space is not numbered from zero
        # Check that divisions are correct

        self.assertEqual( sm.getDivisions('x'), range(1,6) )
        self.assertEqual( sm.getDivisions('y'), [1.0, 5.0, 10.0, 15.0] )
        self.assertEqual( sm.getDivisions('z'), [-10.0, 2.0, 12.0] )

        # loading a test file without structured mesh metadata should raise an error
        filename2 = os.path.join(os.path.dirname(__file__), 'files_scdmesh_test/test_matFracs.h5m')
        self.assertRaises( ScdMeshError, ScdMesh.fromFile, filename2 )
Ejemplo n.º 26
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
Ejemplo n.º 27
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
Ejemplo n.º 28
0
def main(arguments=None):

    parser = OptionParser\
             (usage='%prog structured_mesh x_value y_value z_value tag_name')

    #parser.add_option('-o', dest='fluxin_name', default='ALARAflux.in',\
    #    help='Name of ALARA fluxin output file, default=%default')

    (opts, args) = parser.parse_args(arguments)

    if len(args) != 6:
        parser.error\
        ( '\nNeed exactly 5 arguments: run with -h flag for usage' )

    #Load Structured mesh from file
    sm = ScdMesh.fromFile(args[1])

    print_value(sm, int(args[2]), int(args[3]), int(args[4]), args[5])
Ejemplo n.º 29
0
def 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.
    """

    usage = "Usage: %prog INPUTFILE [options]\n\n" \
            "INPUTFILE is the MCNP or DAG-MCNP input deck that is to be " \
            "modified. \nUse the -d option for DAG-MCNP files."
    parser = OptionParser(usage)
    
    # Output file name, and toggle for DAG-MCNP problems
    parser.add_option("-o","--output",action="store",dest="outputfile", \
            default="", help="Filename to write modified MCNP input to." \
            " Default is to append input filename with '_p'.")
    parser.add_option("-d","--dagmc",action="store_true",dest="dagmc", \
            default=False, help="Add flag to parse file like a DAG-MCNP file " \
            "(which has only title card and block 3 cards). Default: %default")
    parser.add_option("-m","--mesh",action="store",dest="fmesh", \
            default=None, help="Add meshtally (fmesh card), with mesh taken " \
            "from a .h5m or .vtk file that is supplied with this option.")

    (options, args) = parser.parse_args()
    
    if len(args):
        x = ModMCNPforPhotons(args[0], options.dagmc)

        x.read()
        x.convert()
        if options.fmesh != None:
            smesh = ScdMesh.fromFile(options.fmesh)
            x.add_fmesh_from_scdmesh(smesh)
        x.write_deck(options.outputfile)
    
    else:
        print "An input file must be specified as the first argument to use " \
                "this script.\nSee the -h option for more information."

    return 1
Ejemplo n.º 30
0
def main(arguments=None):

    parser = OptionParser\
             (usage='%prog structured_mesh x_value y_value z_value tag_name')

    #parser.add_option('-o', dest='fluxin_name', default='ALARAflux.in',\
    #    help='Name of ALARA fluxin output file, default=%default')

    (opts, args) = parser.parse_args( arguments )

    if len(args) != 6 :
        parser.error\
        ( '\nNeed exactly 5 arguments: run with -h flag for usage' )

    
    #Load Structured mesh from file
    sm=ScdMesh.fromFile(args[1])

    print_value(sm, int(args[2]), int(args[3]), int(args[4]), args[5])
Ejemplo n.º 31
0
def main():
    """ """    
    # Instatiate options parser
    parser = OptionParser\
             (usage='%prog <structured mesh> [options]')

    parser.add_option('-b', action='store_true', dest='backward_bool',\
        default=False, \
        help='Print to ALARA fluxin in fluxes in  decreasing energy. ' \
        'Default=%default')

    parser.add_option('-o', dest='fluxin_name', default='ALARAflux.in',\
        help='Name of ALARA fluxin output file, default=%default')

    (opts, args) = parser.parse_args()

    if len(args) != 2:
        parser.error\
        ( '\nNeed exactly 1 argument: structured mesh file' )

    # Load Structured mesh from file
    sm = ScdMesh.fromFile(args[1])

    write_alara_fluxin( opts.fluxin_name, sm, opts.backward_bool )
Ejemplo n.º 32
0
 def test_vox_seq(self):
     """Verify gammas file for voxel sampling with sequential bins"""
     self.meshfile = meshfile_g
     self.sm = ScdMesh.fromFile(self.meshfile)
     write_gammas.gen_gammas_file_from_h5m(self.sm, outfile)
     self.compare_gammas(outfile, gammas5)
Ejemplo n.º 33
0
 def setUp(self):
     os.system("cp " + meshfile_orig + " " + meshfile)
     self.sm = ScdMesh.fromFile(meshfile)
Ejemplo n.º 34
0
 def setUp(self):
     self.sm = ScdMesh.fromFile(meshfile)
Ejemplo n.º 35
0
 def test_uni_cum(self):
     """Verify gammas file for uniform sampling with cumulative bins"""
     self.meshfile = meshfile_g
     self.sm = ScdMesh.fromFile(self.meshfile)
     write_gammas.gen_gammas_file_from_h5m(self.sm, outfile, sampling='u', cumulative=True)
     self.compare_gammas(outfile, gammas3)
Ejemplo n.º 36
0
def handle_phtn_data(datafile, phtn_src, opt_isotope, opt_cooling,  \
        opt_sampling, opt_bias, opt_cumulative, cust_ergbins, 
        resample, uni_resamp_all, gammas="gammas"):
    """Loads phtn_src data, tags this to mesh, and generates 'gammas' file.

    Parameters
    ----------
    datafile : string
        Path to structured mesh file (e.g. .h5m file)
    phtn_src : string
        Path to phtn_src file
    opt_isotope : string
        The isotope identifier as listed in phtn_src file
    opt_cooling : int or string
        The cooling step, either as a numeric index (from 0) or a string
        identifier as listed in phtn_src file
    opt_sampling : ['v', 'u']
        Type of sampling to generate the 'gammas' file for; v=voxel; u=uniform
    opt_bias : boolean
        If true, look for bias values on the mesh and include them in 'gammas'
    opt_cumulative : boolean
        If true, write energy bins' relative probabilities cumulatively
    cust_ergbins : boolean
        If true, look for custom energy bins on the mesh and include them in
        'gammas'
    resample : boolean
        If true, 'r' flag is added to gammas, and resampling of particles 
        starting in void regions of voxels is enabled.
    uni_resamp_all : boolean
        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.
    gammas : string (optional)
        File name for 'gammas' file. Defaults to 'gammas'.

    Returns
    -------
    mesh : ScdMesh object or iMesh.Mesh object
        MOAB mesh object

    Notes
    -----
    Only creates gammas file if mesh is an ScdMesh.
    """
    print "Loading step one data file '{0}'".format(datafile)
    try:
        mesh = ScdMesh.fromFile(datafile)
    except ScdMeshError:
        mesh = iMesh.Mesh()
        mesh.load(datafile)

    # Tagging mesh
    print "Reading ALARA photon source '{0}'".format(phtn_src)
    read_alara_phtn.read_to_h5m(phtn_src, mesh, isotope=opt_isotope, \
            coolingstep=opt_cooling, retag=True, totals=True)

    print "Saving photon source information to '{0}'".format(datafile)
    if isinstance(mesh, ScdMesh):
        mesh.imesh.save(datafile)

        with open(phtn_src, 'r') as fr:
            try:
                coolingstepstring = read_alara_phtn.get_cooling_step_name( \
                    opt_cooling, fr)[0]
            except ValueError:
                coolingstepstring = opt_cooling

        print "Writing gammas file"
        write_gammas.gen_gammas_file_from_h5m(mesh, outfile=gammas, \
                sampling=opt_sampling, do_bias=opt_bias, \
                cumulative=opt_cumulative, cust_ergbins=cust_ergbins, \
                resample=resample, uni_resamp_all=uni_resamp_all, \
                coolingstep=coolingstepstring, isotope=opt_isotope)
    else:
        voxels = list(mesh.iterate(iBase.Type.region, iMesh.Topology.all))
        write_gammas.calc_total_source_strength(mesh, voxels)
        mesh.save(datafile)

    print "\n"

    return mesh
Ejemplo n.º 37
0
        # Use default
        param_list.append( param[1])

(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.
Ejemplo n.º 38
0
 def test_vox_seq_bias(self):
     """Verify gammas file for voxel sampling with sequential bins and biasing"""
     self.meshfile = meshfile_g
     self.sm = ScdMesh.fromFile(self.meshfile)
     write_gammas.gen_gammas_file_from_h5m(self.sm, outfile, do_bias=True)
     self.compare_gammas(outfile, gammas6)
Ejemplo n.º 39
0
def main():

    # TODO: How to handle non-structured meshes from the command line...
    mesh = ScdMesh.fromFile(sys.argv[1])
    write_alara_geom("alara_geom", mesh)
Ejemplo n.º 40
0
 def test_vow_cum_bias(self):
     """Verify gammas file for voxel sampling with cumulative bins and biasing"""
     self.meshfile = meshfile_g
     self.sm = ScdMesh.fromFile(self.meshfile)
     write_gammas.gen_gammas_file_from_h5m(self.sm, outfile, do_bias=True, cumulative=True)
     self.compare_gammas(outfile, gammas8)
Ejemplo n.º 41
0
 def test_uni_seq(self):
     """Verify gammas file for uniform sampling with sequential bins"""
     self.meshfile = meshfile_g
     self.sm = ScdMesh.fromFile(self.meshfile)
     write_gammas.gen_gammas_file_from_h5m(self.sm, outfile, sampling='u')
     self.compare_gammas(outfile, gammas1)
Ejemplo n.º 42
0
def magic_wwinp(flux_mesh, ww_mesh='None', total_bool=False, null_value=0, tolerance=0.1):
    """This function reads in a flux mesh and a ww mesh as well as relevant paramters
       then the magic method is applied and a newly tagged flux is returned.
    """

    # find meshtal type
    tag_names = []
    for tag in flux_mesh.imesh.getAllTags(flux_mesh.getHex(0,0,0)):
        tag_names.append(tag.name)

    if 'n_group_001' in tag_names or 'n_group_total' in tag_names:
       particle = 'n'
    elif 'p_group_001' in tag_names or 'p_group_total' in tag_names:
        particle = 'p'
    else:
        print >>sys.stderr, 'Tag X_group_YYY or X_group_total not found'
        sys.exit(1)

    # find number of e_groups
    num_e_groups = find_num_e_groups(flux_mesh, particle)

    if total_bool == False:
        e_groups = ['{0:03d}'.format(x) for x in range(1, num_e_groups + 1)]
        print "\tGenerating WW for {0} energy groups".format(num_e_groups)
    else:
        e_groups = ['total']
        print "\tGenerating WW for Total energy group"

    # find the max flux value for each e_group, store in vector
    max_fluxes = find_max_fluxes(flux_mesh, particle, e_groups, total_bool)

    if ww_mesh == 'None':
        print "\tNo WW mesh file supplied; generating one based on meshtal"
        ww_bool = False # mesh file NOT preexisting
        # create a mesh with the same dimensions as flux_mesh
        ww_mesh = ScdMesh(flux_mesh.getDivisions('x'),\
                          flux_mesh.getDivisions('y'),\
                          flux_mesh.getDivisions('z'))
        # create a tag for each energy group
        for e_group in e_groups:
            group_name = "ww_{0}_group_{1}".format(particle, e_group)
            ww_mesh.imesh.createTag(group_name, 1, float)   

        # create energy bounds
        tag_e_groups = ww_mesh.imesh.createTag("e_groups", len(e_groups), float)

        if e_groups != ['total']:
            tag_e_groups[ww_mesh.imesh.rootSet] = \
                flux_mesh.imesh.getTagHandle("e_groups")[flux_mesh.imesh.rootSet]
        else:
            tag_e_groups[ww_mesh.imesh.rootSet] = 1E36 # usual MCNP value           


    else:
        ww_bool = True # mesh file preexisting
        # make sure the supplied meshes have the same dimenstions
        ww_mesh = ScdMesh.fromFile(ww_mesh)
        try:
            for i in ('x', 'y', 'z'):
                flux_mesh.getDivisions(i) == ww_mesh.getDivisions(i)

        except:
            print >>sys.stderr, 'Mismatched dimensions on WWINP and flux meshes'
            sys.exit(1)

    print "\tSupplied meshes confirmed to have same dimensions"
    
    # iterate through all voxels          
    flux_voxels = flux_mesh.iterateHex('xyz')
    ww_voxels = ww_mesh.iterateHex('xyz')

    for (flux_voxel, ww_voxel) in zip(flux_voxels, ww_voxels):
        for i, e_group in enumerate(e_groups):
            flux = flux_mesh.imesh.getTagHandle(\
                '{0}_group_{1}'.format(particle, e_group))[flux_voxel]
            error = flux_mesh.imesh.getTagHandle(\
                 '{0}_group_{1}_error'.format(particle, e_group))[flux_voxel]
            if ((ww_bool == False and error != 0.0) \
            or (0.0 < error and error < tolerance)):
                if ww_bool == True:
                    if ww_mesh.imesh.getTagHandle('ww_{0}_group_{1}'\
                    .format(particle, e_group))[ww_voxel] != -1:       
                        ww_mesh.imesh.getTagHandle('ww_{0}_group_{1}'\
                        .format(particle, e_group))[ww_voxel]\
                        = flux/(2*max_fluxes[i]) # apply magic method

                else:
                    ww_mesh.imesh.getTagHandle(\
                        'ww_{0}_group_{1}'.format(particle, e_group))[ww_voxel]\
                         = flux/(2*max_fluxes[i]) # apply magic method

            elif ww_bool == False and error == 0.0 :
                ww_mesh.imesh.getTagHandle(\
                    'ww_{0}_group_{1}'.format(particle, e_group))[ww_voxel]\
                     = null_value

    return ww_mesh, e_groups
Ejemplo n.º 43
0
def main():

    mesh = ScdMesh.fromFile( sys.argv[1] )
    write_alara_geom( 'alara_geom', mesh )
Ejemplo n.º 44
0
 def setUp(self):
     filename = os.path.join(thisdir, 'h5m_files/grid543.h5m')
     self.sm = ScdMesh.fromFile(filename)
Ejemplo n.º 45
0
 def setUp(self):
     os.system("cp " + meshfile_orig + " " + meshfile)
     self.sm = ScdMesh.fromFile(meshfile)
     read_alara_phtn.read_to_h5m(inputfile, self.sm)
Ejemplo n.º 46
0
 def setUp(self):
     os.system("cp " + meshfile_orig + " " + meshfile)
     self.sm = ScdMesh.fromFile(meshfile)
     read_alara_phtn.read_to_h5m(inputfile, self.sm)
Ejemplo n.º 47
0
def main(arguments=None):

    # Instantiate option parser
    parser = OptionParser\
             (usage='%prog <meshtal_file> <normalization_factor> [options]')

    parser.add_option('-o', dest='mesh_output', default='flux_mesh.h5m',\
                      help = 'Name of mesh output file, default=%default.\
                             For meshtal files with multiple tallies,\
                             if the -o flag is used all tallies must be named,\
                             with file names seperated by commas and no spaces\
                             (e.g. "tally14.h5m,tally24.h5m,tally34.h5m")'                                                                          )
    parser.add_option('-n',
                      dest='norm',
                      default=None,
                      help='Normalization factor, default=%default,\
                            For meshtal files with multiple tallies, if the -n\
                            flag is used, a normalization factor must be\
                            specified for all tallies, seperated by commas but \
                            not spaces (eg. -n 1.1,2.2,3.3) ')
    parser.add_option('-m',
                      dest='smesh_filename',
                      default=None,
                      help='Preexisting mesh on which to tag fluxes')

    (opts, args) = parser.parse_args(arguments)

    #if len(args) != 2 :
    #   parser.error('\nNeed 1 argument: meshtal file')
    print "\n\nRunning read_meshtal.py"
    tally_numbers, tally_lines = find_tallies(args[1])
    print "Number of tallies found: {0}\nTally number(s): {1}" \
                                     .format(len(tally_numbers), tally_numbers)

    # Parse input from options parser, generate default values
    if opts.norm:
        norm = opts.norm.split(',')
    else:
        norm = [1] * len(tally_numbers)

    if opts.mesh_output != 'flux_mesh.h5m':
        mesh_output = opts.mesh_output.split(',')
    else:
        mesh_output = []
        for n in range(0, len(tally_numbers)):
            if len(tally_numbers) == 1:
                mesh_output.append('flux_mesh.h5m')
            else:
                mesh_output.append('flux_mesh_tally{0}.h5m'.format(
                    tally_numbers[n]))

    # Convert each tally to h5m and name accordingly
    for n in range(0, len(tally_numbers)):
        print "\nNow parsing tally number {0}".format(tally_numbers[n])
        if opts.smesh_filename:
            alt_sm = ScdMesh.fromFile(opts.smesh_filename)
            sm = read_meshtal(args[1],
                              tally_lines[n],
                              float(norm[n]),
                              smesh=alt_sm)
        else:
            sm = read_meshtal(args[1], tally_lines[n], float(norm[n]))
        sm.scdset.save(mesh_output[n])

        print "\tSaved tally {0} as {1}".format(tally_numbers[n],
                                                mesh_output[n])
    print "\nStructured mesh tagging complete\n\n"
Ejemplo n.º 48
0
#####################################################################

# Look for and open configuration file for r2s workflow
cfgfile = 'r2s.cfg'
if len(sys.argv) > 1:
    cfgfile = sys.argv[1]

config = ConfigParser.SafeConfigParser()
config.read(cfgfile)

# Required input file from config file
datafile = get_input_file(config, 'step1_datafile')

# Read in the mesh
smesh = ScdMesh.fromFile(datafile)

# Get the Tag object called PHTN_BIAS
try:
    bias_tag = smesh.imesh.createTag("PHTN_BIAS",1,"d")
except iBase.TagAlreadyExistsError:
    print "Tag already exists. Tags are being overwritten."
    bias_tag = smesh.imesh.getTagHandle("PHTN_BIAS")

# Calculate the center of all voxels in the problem and store in a list
centers = calc_centers_list(smesh)

# EXAMPLE OF MATH FOR DISTANCE BASED BIASING:
# This for loop calculates and tags the bias values.
# In this example, based on the voxel's distance from the plane y == -20
#  we assign a bias value between 1 and (maxBias+1).
Ejemplo n.º 49
0
def main():

    # TODO: How to handle non-structured meshes from the command line...
    mesh = ScdMesh.fromFile(sys.argv[1])
    write_alara_geom("alara_geom", mesh)
Ejemplo n.º 50
0
 def setUp(self):
     os.system("cp " + meshfile_orig + " " + meshfile)
     self.sm = ScdMesh.fromFile(meshfile)