diff --git a/python/damask/seeds.py b/python/damask/seeds.py index 10d247859..76c0bbb26 100644 --- a/python/damask/seeds.py +++ b/python/damask/seeds.py @@ -8,7 +8,7 @@ from . import grid_filters def from_random(size,N_seeds,grid=None,seed=None): """ Random seeding in space. - + Parameters ---------- size : numpy.ndarray of shape (3) @@ -21,7 +21,7 @@ def from_random(size,N_seeds,grid=None,seed=None): seed : {None, int, array_like[ints], SeedSequence, BitGenerator, Generator}, optional A seed to initialize the BitGenerator. Defaults to None. If None, then fresh, unpredictable entropy will be pulled from the OS. - + """ rng = _np.random.default_rng(seed) if grid is None: @@ -31,13 +31,13 @@ def from_random(size,N_seeds,grid=None,seed=None): coords = grid_coords[rng.choice(_np.prod(grid),N_seeds, replace=False)] \ + _np.broadcast_to(size/grid,(N_seeds,3))*(rng.random((N_seeds,3))*.5-.25) # wobble without leaving grid - coords + return coords -def from_Poisson_disc(size,N_seeds,N_candidates,distance,seed=None): +def from_Poisson_disc(size,N_seeds,N_candidates,distance,periodic=True,seed=None): """ Seeding in space according to a Poisson disc distribution. - + Parameters ---------- size : numpy.ndarray of shape (3) @@ -48,10 +48,12 @@ def from_Poisson_disc(size,N_seeds,N_candidates,distance,seed=None): Number of candidates to consider for finding best candidate. distance : float Minimum acceptable distance to other seeds. + periodic : boolean, optional + Calculate minimum distance for periodically repeated grid. seed : {None, int, array_like[ints], SeedSequence, BitGenerator, Generator}, optional A seed to initialize the BitGenerator. Defaults to None. If None, then fresh, unpredictable entropy will be pulled from the OS. - + """ rng = _np.random.default_rng(seed) coords = _np.empty((N_seeds,3)) @@ -61,7 +63,8 @@ def from_Poisson_disc(size,N_seeds,N_candidates,distance,seed=None): progress = util._ProgressBar(N_seeds+1,'',50) while i < N_seeds: candidates = rng.random((N_candidates,3))*_np.broadcast_to(size,(N_candidates,3)) - tree = _spatial.cKDTree(coords[:i]) + tree = _spatial.cKDTree(coords[:i],boxsize=size) if periodic else \ + _spatial.cKDTree(coords[:i]) distances, dev_null = tree.query(candidates) best = distances.argmax() if distances[best] > distance: # require minimum separation @@ -75,12 +78,12 @@ def from_Poisson_disc(size,N_seeds,N_candidates,distance,seed=None): def from_geom(geom,selection=None,invert=False): """ Create seed from existing geometry description. - + Parameters ---------- geom : damask.Geom ... - + """ material = geom.materials.reshape((-1,1),order='F') mask = _np.full(geom.grid.prod(),True,dtype=bool) if selection is None else \ diff --git a/python/tests/test_seeds.py b/python/tests/test_seeds.py index 57631ccba..55b659ad1 100644 --- a/python/tests/test_seeds.py +++ b/python/tests/test_seeds.py @@ -13,11 +13,13 @@ class TestSeeds: coords = seeds.from_random(size,N_seeds,grid) assert (0<=coords).all() and (coords=distance