Esempio n. 1
0
    def test_unequal_grid_size(self):
        """Test creating an mmgrid on a mesh with uneven grid spacing"""
        grid_side = [-3,0,.1,.2,3]
        sm = ScdMesh( *([grid_side]*3) )
        grid = mmgrid.mmGrid( sm )
        grid.generate(5)#, True)

        for ijk, x in numpy.ndenumerate(grid.grid):
            self.assertAlmostEqual( 
                    sum(x['mats']), 1.0, 
                    msg='Normality at ijk={0}:\n'
                        '    sum({1}) = {2} != 1.0'.format(ijk, x['mats'], sum(x['mats'])))
Esempio n. 2
0
    def test_mmgrid_generate(self):
        grid_side = [-5,-3.75,-2.5,-1.25,0,1.25,2.5,3.75,5]
        sm = ScdMesh( *([grid_side]*3) )
        grid = mmgrid.mmGrid( sm )
        grid.generate(2, True)

        for ijk, x in numpy.ndenumerate(grid.grid):
            self.assertAlmostEqual( 
                    sum(x['mats']), 1.0, 
                    msg='Normality at ijk={0}:\n'
                        '    sum({1}) = {2} != 1.0'.format(ijk, x['mats'], sum(x['mats'])))

        grid.createTags()
Esempio n. 3
0
    def test_unequal_grid_size(self):
        """Test creating an mmgrid on a mesh with uneven grid spacing"""
        grid_side = [-3, 0, .1, .2, 3]
        sm = ScdMesh(*([grid_side] * 3))
        grid = mmgrid.mmGrid(sm)
        grid.generate(5)  #, True)

        for ijk, x in numpy.ndenumerate(grid.grid):
            self.assertAlmostEqual(sum(x['mats']),
                                   1.0,
                                   msg='Normality at ijk={0}:\n'
                                   '    sum({1}) = {2} != 1.0'.format(
                                       ijk, x['mats'], sum(x['mats'])))
Esempio n. 4
0
    def test_rayframes(self):

        # a mesh with divisions at -1, 0, and 1 for all three dimensions
        sm = ScdMesh(*([(-1, 0, 1)] * 3))
        mg = mmgrid.mmGrid(sm)

        squares = [(-1, 0, -1, 0), (-1, 0, 0, 1), (0, 1, -1, 0), (0, 1, 0, 1)]

        ijks = [[0, 0, 0], [0, 0, 1], [0, 1, 0], [0, 1, 1]]

        for (ijk, ab), ab_test, ijk_test in itertools.izip_longest(mg._rayframe("x"), squares, ijks):
            self.assertEqual(ab, ab_test)
            self.assertEqual(ijk, ijk_test)
Esempio n. 5
0
    def test_mmgrid_generate(self):
        grid_side = [-5, -3.75, -2.5, -1.25, 0, 1.25, 2.5, 3.75, 5]
        sm = ScdMesh(*([grid_side] * 3))
        grid = mmgrid.mmGrid(sm)
        grid.generate(2, True)

        for ijk, x in numpy.ndenumerate(grid.grid):
            self.assertAlmostEqual(sum(x['mats']),
                                   1.0,
                                   msg='Normality at ijk={0}:\n'
                                   '    sum({1}) = {2} != 1.0'.format(
                                       ijk, x['mats'], sum(x['mats'])))

        grid.create_tags()
Esempio n. 6
0
    def test_rayframes(self):

        # a mesh with divisions at -1, 0, and 1 for all three dimensions
        sm = ScdMesh(*([(-1, 0, 1)] * 3))
        mg = mmgrid.mmGrid(sm)

        squares = [(-1, 0, -1, 0), (-1, 0, 0, 1), (0, 1, -1, 0), (0, 1, 0, 1)]

        ijks = [[0, 0, 0], [0, 0, 1], [0, 1, 0], [0, 1, 1]]

        for (ijk, ab), ab_test, ijk_test in itertools.izip_longest(
                mg._rayframe('x'), squares, ijks):
            self.assertEqual(ab, ab_test)
            self.assertEqual(ijk, ijk_test)
Esempio n. 7
0
def handle_mesh_materials(mesh,
                          mcnp_geom,
                          gen_mmgrid=False,
                          mmgrid_rays=10,
                          isscd=True):
    """Tag the mesh with materials

    Parameters
    ----------
    mesh : ScdMesh or iMesh.Mesh()
        Mesh object to be tagged.
    mcnp_geom : string
        Filename/path for CAD geometry to be loaded into DAGMC from.
    gen_mmgrid : boolean
        Whether to generate a new macromaterials grid
    mmgrid_rays : integer
        Number of rays in each dimension to run mmgrid with
    isscd : boolean
        If True, handle geometry as a structured mesh. Otherwise mesh is
        assumed to be unstructured and materials are based on voxel centers.
    """

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

    if not isscd:  # is unstructured
        # Use non-structured mesh approach: tag material of voxel center points
        grid = mmgrid.SingleMatGrid(mesh)
        grid.generate()
        grid.create_tags()

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

        grid = mmgrid.mmGrid(mesh)
        grid.generate(mmgrid_rays, False)
        grid.create_tags()

    else:
        # Materials should already exist, e.g. via mmgrid
        return
Esempio n. 8
0
def handle_mesh_materials(mesh, mcnp_geom, gen_mmgrid=False, mmgrid_rays=10, 
                          isscd=True):
    """Tag the mesh with materials

    Parameters
    ----------
    mesh : ScdMesh or iMesh.Mesh()
        Mesh object to be tagged.
    mcnp_geom : string
        Filename/path for CAD geometry to be loaded into DAGMC from.
    gen_mmgrid : boolean
        Whether to generate a new macromaterials grid
    mmgrid_rays : integer
        Number of rays in each dimension to run mmgrid with
    isscd : boolean
        If True, handle geometry as a structured mesh. Otherwise mesh is
        assumed to be unstructured and materials are based on voxel centers.
    """

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

    if not isscd: # is unstructured
        # Use non-structured mesh approach: tag material of voxel center points
        grid = mmgrid.SingleMatGrid(mesh)
        grid.generate()
        grid.create_tags()

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

        grid = mmgrid.mmGrid( mesh )
        grid.generate( mmgrid_rays, False )
        grid.create_tags()

    else:
        # Materials should already exist, e.g. via mmgrid
        return
Esempio n. 9
0
 def test_mmgrid_create(self):
     sm = ScdMesh( *([(-1, 0, 1)]*3) )
     grid = mmgrid.mmGrid( sm )
     self.assertEqual( grid.grid.shape, (2,2,2) )
     self.assertEqual( grid.grid[0,0,0]['mats'].shape, (3,) )
     self.assertEqual( grid.grid[0,0,0]['errs'].shape, (3,) )
Esempio n. 10
0
 def test_mmgrid_create(self):
     sm = ScdMesh(*([(-1, 0, 1)] * 3))
     grid = mmgrid.mmGrid(sm)
     self.assertEqual(grid.grid.shape, (2, 2, 2))
     self.assertEqual(grid.grid[0, 0, 0]['mats'].shape, (3, ))
     self.assertEqual(grid.grid[0, 0, 0]['errs'].shape, (3, ))
Esempio n. 11
0
        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)

    grid = mmgrid.mmGrid( smesh )
    grid.generate( mmgrid_rays, False )
    grid.createTags()


print "Saving fluxes and materials to `{0}'".format(datafile)
smesh.imesh.save(datafile)

if visfile != None:
    print "Producing visualization file `{0}' with mbconvert".format(visfile)
    os.system('mbconvert {0} {1}'.format(datafile,visfile))

print "Writing alara problem file `{0}'".format(alara_geom)
mdict = get_material_dict()
write_alara_geom( alara_geom, smesh, mdict )