From 4960cf43d4f69e9f9387f21508580c8178425259 Mon Sep 17 00:00:00 2001 From: Martin Diehl Date: Thu, 24 Sep 2020 21:43:04 +0200 Subject: [PATCH] documented and tested --- python/damask/seeds.py | 8 ++++++-- python/tests/test_seeds.py | 11 +++++++++++ 2 files changed, 17 insertions(+), 2 deletions(-) diff --git a/python/damask/seeds.py b/python/damask/seeds.py index 76c0bbb26..46be722cd 100644 --- a/python/damask/seeds.py +++ b/python/damask/seeds.py @@ -82,10 +82,14 @@ def from_geom(geom,selection=None,invert=False): Parameters ---------- geom : damask.Geom - ... + Geometry, from which the material IDs are used as seeds + selection : iterable of integers, optional + Material IDs to consider + invert : boolean, false + Do not consider the material IDs given in selection. Defaults to False. """ - material = geom.materials.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 \ _np.isin(material,selection,invert=invert) coords = grid_filters.cell_coord0(geom.grid,geom.size).reshape(-1,3,order='F') diff --git a/python/tests/test_seeds.py b/python/tests/test_seeds.py index 55b659ad1..49d9a6bfd 100644 --- a/python/tests/test_seeds.py +++ b/python/tests/test_seeds.py @@ -3,6 +3,7 @@ import numpy as np from scipy.spatial import cKDTree from damask import seeds +from damask import Geom class TestSeeds: @@ -23,3 +24,13 @@ class TestSeeds: min_dists, _ = cKDTree(coords,boxsize=size).query(coords, 2) if periodic else \ cKDTree(coords).query(coords, 2) assert (0<= coords).all() and (coords=distance + + def test_from_geom(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()