distance already controls whether tesselation works

at least for sufficiently large d
This commit is contained in:
Martin Diehl 2020-03-21 21:21:30 +01:00
parent 2c1a654966
commit b53288c0be
1 changed files with 9 additions and 12 deletions

View File

@ -5,7 +5,6 @@ import sys
from optparse import OptionParser,OptionGroup from optparse import OptionParser,OptionGroup
import numpy as np import numpy as np
from numpy import ma
from scipy import spatial from scipy import spatial
import damask import damask
@ -115,6 +114,9 @@ for name in filenames:
if options.N > np.prod(grid): if options.N > np.prod(grid):
damask.util.croak('More seeds than grid positions.') damask.util.croak('More seeds than grid positions.')
sys.exit() sys.exit()
if options.selective and options.distance < min(size/grid):
damask.util.croak('Distance must be larger than grid spacing.')
sys.exit()
if options.selective and options.distance**3*options.N > 0.5*np.prod(size): if options.selective and options.distance**3*options.N > 0.5*np.prod(size):
damask.util.croak('Number of seeds for given size and distance should be < {}.'\ damask.util.croak('Number of seeds for given size and distance should be < {}.'\
.format(int(0.5*np.prod(size)/options.distance**3))) .format(int(0.5*np.prod(size)/options.distance**3)))
@ -127,29 +129,24 @@ for name in filenames:
coords = damask.grid_filters.cell_coord0(grid,size).reshape(-1,3) coords = damask.grid_filters.cell_coord0(grid,size).reshape(-1,3)
if not options.selective: if not options.selective:
seeds = coords[np.random.choice(coords.shape[0], options.N, replace=False)] seeds = coords[np.random.choice(coords.shape[0], options.N, replace=False)] \
+ np.broadcast_to(size/grid,(options.N,3))*(np.random.rand(options.N,3)*.5-.25) # wobble without leaving grid
else: else:
seeds = np.empty((options.N,3)) seeds = np.empty((options.N,3))
unpicked = ma.array(np.arange(coords.shape[0]),mask=np.zeros(coords.shape[0],dtype=bool)) seeds[0] = np.random.random(3) * size
first_pick = np.random.randint(coords.shape[0])
seeds[0] = coords[first_pick]
unpicked.mask[first_pick]=True
i = 1 i = 1
progress = damask.util._ProgressBar(options.N,'',50) progress = damask.util._ProgressBar(options.N,'',50)
while i < options.N: while i < options.N:
candidates = np.random.choice(unpicked[np.logical_not(unpicked.mask)],replace=False, candidates = np.random.rand(options.numCandidates,3)*np.broadcast_to(size,(options.numCandidates,3))
size=min(np.count_nonzero(unpicked.mask),options.numCandidates))
tree = spatial.cKDTree(seeds[:i]) tree = spatial.cKDTree(seeds[:i])
distances, dev_null = tree.query(coords[candidates]) distances, dev_null = tree.query(candidates)
best = distances.argmax() best = distances.argmax()
if distances[best] > options.distance: # require minimum separation if distances[best] > options.distance: # require minimum separation
seeds[i] = coords[candidates[best]] # maximum separation to existing point cloud seeds[i] = candidates[best] # maximum separation to existing point cloud
unpicked.mask[candidates[best]]=True
i += 1 i += 1
progress.update(i) progress.update(i)
seeds += np.broadcast_to(size/grid,seeds.shape)*(np.random.random(seeds.shape)*.5-.25) # wobble without leaving grid
comments = [scriptID + ' ' + ' '.join(sys.argv[1:]), comments = [scriptID + ' ' + ' '.join(sys.argv[1:]),
'grid\ta {}\tb {}\tc {}'.format(*grid), 'grid\ta {}\tb {}\tc {}'.format(*grid),