thorougly testing seeding functionality

This commit is contained in:
Martin Diehl 2020-09-25 07:41:58 +02:00
parent 7dc8391c03
commit 9e3506b8ef
2 changed files with 28 additions and 2 deletions

View File

@ -95,7 +95,7 @@ def from_geom(geom,selection=None,invert=False,average=False,periodic=True):
""" """
material = geom.material.reshape((-1,1),order='F') material = geom.material.reshape((-1,1),order='F')
mask = _np.full(geom.grid.prod(),True,dtype=bool) if selection is None else \ mask = _np.full(geom.grid.prod(),True,dtype=bool) if selection is None else \
_np.isin(material,selection,invert=invert) _np.isin(material,selection,invert=invert).flatten()
coords = grid_filters.cell_coord0(geom.grid,geom.size).reshape(-1,3,order='F') coords = grid_filters.cell_coord0(geom.grid,geom.size).reshape(-1,3,order='F')
if not average: if not average:

View File

@ -3,6 +3,7 @@ import numpy as np
from scipy.spatial import cKDTree from scipy.spatial import cKDTree
from damask import seeds from damask import seeds
from damask import grid_filters
from damask import Geom from damask import Geom
class TestSeeds: class TestSeeds:
@ -25,7 +26,7 @@ class TestSeeds:
cKDTree(coords).query(coords, 2) cKDTree(coords).query(coords, 2)
assert (0<= coords).all() and (coords<size).all() and np.min(min_dists[:,1])>=distance assert (0<= coords).all() and (coords<size).all() and np.min(min_dists[:,1])>=distance
def test_from_geom(self): def test_from_geom_reconstruct(self):
grid = np.random.randint(10,20,3) grid = np.random.randint(10,20,3)
N_seeds = np.random.randint(30,300) N_seeds = np.random.randint(30,300)
size = np.ones(3) + np.random.random(3) size = np.ones(3) + np.random.random(3)
@ -34,3 +35,28 @@ class TestSeeds:
coords,material = seeds.from_geom(geom_1) coords,material = seeds.from_geom(geom_1)
geom_2 = Geom.from_Voronoi_tessellation(grid,size,coords,material) geom_2 = Geom.from_Voronoi_tessellation(grid,size,coords,material)
assert (geom_2.material==geom_1.material).all() assert (geom_2.material==geom_1.material).all()
@pytest.mark.parametrize('periodic',[True,False])
@pytest.mark.parametrize('average',[True,False])
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()
@pytest.mark.parametrize('periodic',[True,False])
@pytest.mark.parametrize('average',[True,False])
@pytest.mark.parametrize('invert',[True,False])
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()