fix for periodic copies

old version had huge memory consumption as was probably wrong
This commit is contained in:
Martin Diehl 2020-03-21 16:41:52 +01:00
parent ab1ab42e75
commit c31c9be628
1 changed files with 9 additions and 41 deletions

View File

@ -24,47 +24,16 @@ def Laguerre_tessellation(grid, seeds, grains, size, periodic, weights, cpus):
dist = np.sum((tmp - seeds)**2,axis=1) -myWeights dist = np.sum((tmp - seeds)**2,axis=1) -myWeights
return np.argmin(dist) # seed point closest to point return np.argmin(dist) # seed point closest to point
copies = \ if periodic:
np.array([ weights_p = np.tile(weights,27).flatten(order='F') # Laguerre weights (1,2,3,1,2,3,...,1,2,3)
[ -1,-1,-1 ], seeds_p = np.vstack((seeds +np.array([size[0],0.,0.]),seeds, seeds +np.array([size[0],0.,0.])))
[ 0,-1,-1 ], seeds_p = np.vstack((seeds_p+np.array([0.,size[1],0.]),seeds_p,seeds_p+np.array([0.,size[1],0.])))
[ 1,-1,-1 ], seeds_p = np.vstack((seeds_p+np.array([0.,0.,size[2]]),seeds_p,seeds_p+np.array([0.,0.,size[2]])))
[ -1, 0,-1 ], else:
[ 0, 0,-1 ], weights_p = weights.flatten()
[ 1, 0,-1 ], seeds_p = seeds
[ -1, 1,-1 ],
[ 0, 1,-1 ],
[ 1, 1,-1 ],
[ -1,-1, 0 ],
[ 0,-1, 0 ],
[ 1,-1, 0 ],
[ -1, 0, 0 ],
[ 0, 0, 0 ],
[ 1, 0, 0 ],
[ -1, 1, 0 ],
[ 0, 1, 0 ],
[ 1, 1, 0 ],
[ -1,-1, 1 ],
[ 0,-1, 1 ],
[ 1,-1, 1 ],
[ -1, 0, 1 ],
[ 0, 0, 1 ],
[ 1, 0, 1 ],
[ -1, 1, 1 ],
[ 0, 1, 1 ],
[ 1, 1, 1 ],
],dtype=np.float)*size if periodic else \
np.array([
[ 0, 0, 0 ],
],dtype=np.float)
repeatweights = np.tile(weights,len(copies)).flatten(order='F') # Laguerre weights (1,2,3,1,2,3,...,1,2,3) arguments = [[arg,seeds_p,weights_p] for arg in list(grid)]
for vec in copies: # periodic copies of seed points ...
try: seeds = np.append(seeds, seeds+vec, axis=0) # ... (1+a,2+a,3+a,...,1+z,2+z,3+z)
except NameError: seeds = seeds+vec
damask.util.croak('...using {} cpu{}'.format(options.cpus, 's' if options.cpus > 1 else ''))
arguments = [[arg,seeds,repeatweights] for arg in list(grid)]
if cpus > 1: # use multithreading if cpus > 1: # use multithreading
pool = multiprocessing.Pool(processes = cpus) # initialize workers pool = multiprocessing.Pool(processes = cpus) # initialize workers
@ -77,7 +46,6 @@ def Laguerre_tessellation(grid, seeds, grains, size, periodic, weights, cpus):
for i,arg in enumerate(arguments): for i,arg in enumerate(arguments):
closestSeeds[i] = findClosestSeed(arg) closestSeeds[i] = findClosestSeed(arg)
# closestSeed is modulo number of original seed points (i.e. excluding periodic copies)
return grains[closestSeeds%seeds.shape[0]] return grains[closestSeeds%seeds.shape[0]]