polishing

This commit is contained in:
Martin Diehl 2020-03-21 17:59:00 +01:00
parent f961f3590c
commit 67f64b7a7a
3 changed files with 28 additions and 30 deletions

View File

@ -13,43 +13,44 @@ from scipy import spatial
import damask
def findClosestSeed(seeds, weights, point):
return np.argmin(np.sum((np.broadcast_to(point,(len(seeds),3))-seeds)**2,axis=1) - weights)
scriptName = os.path.splitext(os.path.basename(__file__))[0]
scriptID = ' '.join([scriptName,damask.version])
def findClosestSeed(seeds, weights, point):
return np.argmin(np.sum((np.broadcast_to(point,(len(seeds),3))-seeds)**2,axis=1) - weights)
def Laguerre_tessellation(grid, seeds, grains, size, periodic, weights, cpus):
if periodic:
weights_p = np.tile(weights,27).flatten(order='F') # Laguerre weights (1,2,3,1,2,3,...,1,2,3)
seeds_p = np.vstack((seeds -np.array([size[0],0.,0.]),seeds, seeds +np.array([size[0],0.,0.])))
seeds_p = np.vstack((seeds_p-np.array([0.,size[1],0.]),seeds_p,seeds_p+np.array([0.,size[1],0.])))
seeds_p = np.vstack((seeds_p-np.array([0.,0.,size[2]]),seeds_p,seeds_p+np.array([0.,0.,size[2]])))
else:
weights_p = weights.flatten()
seeds_p = seeds
if periodic:
weights_p = np.tile(weights,27).flatten(order='F') # Laguerre weights (1,2,3,1,2,3,...,1,2,3)
seeds_p = np.vstack((seeds -np.array([size[0],0.,0.]),seeds, seeds +np.array([size[0],0.,0.])))
seeds_p = np.vstack((seeds_p-np.array([0.,size[1],0.]),seeds_p,seeds_p+np.array([0.,size[1],0.])))
seeds_p = np.vstack((seeds_p-np.array([0.,0.,size[2]]),seeds_p,seeds_p+np.array([0.,0.,size[2]])))
else:
weights_p = weights.flatten()
seeds_p = seeds
if cpus > 1:
default_args = partial(findClosestSeed,seeds_p,weights_p)
pool = multiprocessing.Pool(processes = cpus) # initialize workers
result = pool.map_async(default_args, [point for point in grid]) # evaluate function in parallel
pool.close()
pool.join()
closestSeeds = np.array(result.get()).flatten()
else:
closestSeeds= np.array([findClosestSeed(seeds_p,weights_p,point) for point in grid])
if cpus > 1:
default_args = partial(findClosestSeed,seeds_p,weights_p)
pool = multiprocessing.Pool(processes = cpus) # initialize workers
result = pool.map_async(default_args, [point for point in grid]) # evaluate function in parallel
pool.close()
pool.join()
closestSeeds = np.array(result.get()).flatten()
else:
closestSeeds= np.array([findClosestSeed(seeds_p,weights_p,point) for point in grid])
return grains[closestSeeds%seeds.shape[0]]
return grains[closestSeeds%seeds.shape[0]]
def Voronoi_tessellation(grid, seeds, grains, size, periodic = True):
KDTree = spatial.cKDTree(seeds,boxsize=size) if periodic else spatial.cKDTree(seeds)
devNull,closestSeeds = KDTree.query(grid)
KDTree = spatial.cKDTree(seeds,boxsize=size) if periodic else spatial.cKDTree(seeds)
devNull,closestSeeds = KDTree.query(grid)
return grains[closestSeeds]
return grains[closestSeeds]
# --------------------------------------------------------------------

View File

@ -2,7 +2,6 @@
import os
import sys
import random
from optparse import OptionParser,OptionGroup
import numpy as np
@ -139,8 +138,8 @@ for name in filenames:
i = 1
progress = damask.util._ProgressBar(options.N,'',50)
while i < options.N:
candidates = np.random.choice(unpicked[unpicked.mask==False],replace=False,
size=min(len(unpicked[unpicked.mask==False]),options.numCandidates))
candidates = np.random.choice(unpicked[not unpicked.mask],replace=False,
size=min(len(unpicked[not unpicked.mask]),options.numCandidates))
tree = spatial.cKDTree(seeds[:i])
distances, dev_null = tree.query(coords[candidates])
best = distances.argmax()

View File

@ -1,5 +1,3 @@
# -*- coding: UTF-8 no BOM -*-
"""Aggregator for configuration file handling"""
"""Aggregator for configuration file handling."""
from .material import Material # noqa