def test_from_grid_reconstruct(self): cells = 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, cells) grid_1 = Grid.from_Voronoi_tessellation(cells, size, coords) coords, material = seeds.from_grid(grid_1) grid_2 = Grid.from_Voronoi_tessellation(cells, size, coords, material) assert (grid_2.material == grid_1.material).all()
def test_from_grid_grid(self, periodic, average): cells = np.random.randint(10, 20, 3) size = np.ones(3) + np.random.random(3) coords = grid_filters.coordinates0_point(cells, size).reshape(-1, 3) np.random.shuffle(coords) grid_1 = Grid.from_Voronoi_tessellation(cells, size, coords) coords, material = seeds.from_grid(grid_1, average=average, periodic=periodic) grid_2 = Grid.from_Voronoi_tessellation(cells, size, coords, material) assert (grid_2.material == grid_1.material).all()
def test_from_table_recover(self,tmp_path): cells = np.random.randint(60,100,3) size = np.ones(3)+np.random.rand(3) s = seeds.from_random(size,np.random.randint(60,100)) grid = Grid.from_Voronoi_tessellation(cells,size,s) coords = grid_filters.coordinates0_point(cells,size) t = Table(np.column_stack((coords.reshape(-1,3,order='F'),grid.material.flatten(order='F'))),{'c':3,'m':1}) assert grid_equal(grid.sort().renumber(),Grid.from_table(t,'c',['m']))
def test_tessellation_approaches(self,periodic): cells = 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 = Grid.from_Voronoi_tessellation( cells,size,seeds, np.arange(N_seeds)+5,periodic) Laguerre = Grid.from_Laguerre_tessellation(cells,size,seeds,np.ones(N_seeds),np.arange(N_seeds)+5,periodic) assert grid_equal(Laguerre,Voronoi)
def test_regrid_double_cells(self): size = np.random.random(3) # noqa cells = np.random.randint(8, 32, (3)) g = Grid.from_Voronoi_tessellation(cells, size, seeds.from_random(size, 10)) F = np.broadcast_to(np.eye(3), tuple(cells) + (3, 3)) assert all( g.scale(cells * 2).material.flatten() == g.material.flatten()[ grid_filters.regrid(size, F, cells * 2)])
def test_tessellate_bicrystal(self,approach): cells = np.random.randint(5,10,3)*2 size = cells.astype(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(cells) material[:,cells[1]//2:,:] = 1 if approach == 'Laguerre': grid = Grid.from_Laguerre_tessellation(cells,size,seeds,np.ones(2),periodic=np.random.random()>0.5) elif approach == 'Voronoi': grid = Grid.from_Voronoi_tessellation(cells,size,seeds, periodic=np.random.random()>0.5) assert np.all(grid.material == material)
def test_from_grid_selection(self, periodic, average, invert): cells = 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, cells) grid = Grid.from_Voronoi_tessellation(cells, size, coords) selection = np.random.randint(N_seeds) + 1 coords, material = seeds.from_grid(grid, average=average, periodic=periodic, invert=invert, selection=[selection]) assert selection not in material if invert else (selection == material).all()