Beispiel #1
0
 def test_from_geom_reconstruct(self):
     grid = np.random.randint(10, 20, 3)
     N_seeds = np.random.randint(30, 300)
     size = np.ones(3) + np.random.random(3)
     coords = seeds.from_random(size, N_seeds, grid)
     geom_1 = Geom.from_Voronoi_tessellation(grid, size, coords)
     coords, material = seeds.from_geom(geom_1)
     geom_2 = Geom.from_Voronoi_tessellation(grid, size, coords, material)
     assert (geom_2.material == geom_1.material).all()
Beispiel #2
0
 def test_from_geom_grid(self, periodic, average):
     grid = np.random.randint(10, 20, 3)
     size = np.ones(3) + np.random.random(3)
     coords = grid_filters.cell_coord0(grid, size).reshape(-1, 3)
     np.random.shuffle(coords)
     geom_1 = Geom.from_Voronoi_tessellation(grid, size, coords)
     coords, material = seeds.from_geom(geom_1,
                                        average=average,
                                        periodic=periodic)
     geom_2 = Geom.from_Voronoi_tessellation(grid, size, coords, material)
     assert (geom_2.material == geom_1.material).all()
Beispiel #3
0
 def test_from_table_recover(self,tmp_path):
     grid = np.random.randint(60,100,3)
     size = np.ones(3)+np.random.rand(3)
     s = seeds.from_random(size,np.random.randint(60,100))
     geom = Geom.from_Voronoi_tessellation(grid,size,s)
     coords = grid_filters.cell_coord0(grid,size)
     t = Table(np.column_stack((coords.reshape(-1,3,order='F'),geom.material.flatten(order='F'))),{'c':3,'m':1})
     assert geom_equal(geom.sort().renumber(),Geom.from_table(t,'c',['m']))
Beispiel #4
0
 def test_tessellation_approaches(self,periodic):
     grid   = np.random.randint(10,20,3)
     size   = np.random.random(3) + 1.0
     N_seeds= np.random.randint(10,30)
     seeds  = np.random.rand(N_seeds,3) * np.broadcast_to(size,(N_seeds,3))
     Voronoi  = Geom.from_Voronoi_tessellation( grid,size,seeds,                 np.arange(N_seeds)+5,periodic)
     Laguerre = Geom.from_Laguerre_tessellation(grid,size,seeds,np.ones(N_seeds),np.arange(N_seeds)+5,periodic)
     assert geom_equal(Laguerre,Voronoi)
Beispiel #5
0
 def test_tessellate_bicrystal(self,approach):
     grid  = np.random.randint(5,10,3)*2
     size  = grid.astype(np.float)
     seeds = np.vstack((size*np.array([0.5,0.25,0.5]),size*np.array([0.5,0.75,0.5])))
     material = np.zeros(grid)
     material[:,grid[1]//2:,:] = 1
     if   approach == 'Laguerre':
         geom = Geom.from_Laguerre_tessellation(grid,size,seeds,np.ones(2),periodic=np.random.random()>0.5)
     elif approach == 'Voronoi':
         geom = Geom.from_Voronoi_tessellation(grid,size,seeds,            periodic=np.random.random()>0.5)
     assert np.all(geom.material == material)
Beispiel #6
0
 def test_from_geom_selection(self, periodic, average, invert):
     grid = np.random.randint(10, 20, 3)
     N_seeds = np.random.randint(30, 300)
     size = np.ones(3) + np.random.random(3)
     coords = seeds.from_random(size, N_seeds, grid)
     geom = Geom.from_Voronoi_tessellation(grid, size, coords)
     selection = np.random.randint(N_seeds) + 1
     coords, material = seeds.from_geom(geom,
                                        average=average,
                                        periodic=periodic,
                                        invert=invert,
                                        selection=[selection])
     assert selection not in material if invert else (selection
                                                      == material).all()
Beispiel #7
0
def generate_volume_element_random_voronoi(microstructure_seeds, grid_size, homog_label,
                                           scale_morphology, scale_update_size,
                                           buffer_phase_size, buffer_phase_label,
                                           orientations=None):
    try:
        from damask import Geom

        geom_obj = Geom.from_Voronoi_tessellation(
            grid=np.array(grid_size),
            size=np.array(microstructure_seeds['size']),
            seeds=np.array(microstructure_seeds['position']),
        )

        if scale_morphology is not None:
            scale_morphology = np.array(scale_morphology)

            original_grid = geom_obj.get_grid()
            new_grid = original_grid * scale_morphology
            geom_scaled = geom_obj.scale(new_grid)

            if scale_update_size:
                original_size = geom_obj.get_size()
                new_size = original_size * scale_morphology
                geom_scaled.set_size(new_size)

            geom_obj = geom_scaled

        phase_labels = [microstructure_seeds['phase_label']]
        if buffer_phase_size is not None:
            original_grid = geom_obj.get_grid()
            original_size = geom_obj.get_size()

            new_grid = original_grid + np.array(buffer_phase_size)
            new_size = original_size * (new_grid / original_grid)

            geom_canvased = geom_obj.canvas(grid=new_grid)
            geom_canvased.set_size(new_size)

            geom_obj = geom_canvased
            phase_labels.append(buffer_phase_label)

        # specifying pack ensures consistent behaviour:
        geom_obj.to_file('geom.geom', pack=False)

    except ImportError:
        from damask import Grid as Geom

        grid_obj = Geom.from_Voronoi_tessellation(
            cells=np.array(grid_size),
            size=np.array(microstructure_seeds['size']),
            seeds=np.array(microstructure_seeds['position']),
            material=np.arange(1, microstructure_seeds['position'].shape[0]+1)
        )

        if scale_morphology is not None:
            scale_morphology = np.array(scale_morphology)

            original_cells = grid_obj.cells
            new_cells = original_cells * scale_morphology
            grid_scaled = grid_obj.scale(new_cells)

            if scale_update_size:
                original_size = grid_obj.size
                new_size = original_size * scale_morphology
                grid_scaled.size = new_size

            grid_obj = grid_scaled

        phase_labels = [microstructure_seeds['phase_label']]
        if buffer_phase_size is not None:
            original_cells = grid_obj.cells
            original_size = grid_obj.size

            new_cells = original_cells + np.array(buffer_phase_size)
            new_size = original_size * (new_cells / original_cells)

            grid_canvased = grid_obj.canvas(cells=new_cells)
            grid_canvased.size = new_size

            grid_obj = grid_canvased
            phase_labels.append(buffer_phase_label)

        grid_obj.save_ASCII('geom.geom')

    volume_element = geom_to_volume_element(
        'geom.geom',
        phase_labels=phase_labels,
        homog_label=homog_label,
        orientations=(orientations or microstructure_seeds['orientations']),
    )

    return {'volume_element': volume_element}