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 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] scriptName = os.path.splitext(os.path.basename(__file__))[0]
scriptID = ' '.join([scriptName,damask.version]) 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): def Laguerre_tessellation(grid, seeds, grains, size, periodic, weights, cpus):
if periodic: if periodic:
weights_p = np.tile(weights,27).flatten(order='F') # Laguerre weights (1,2,3,1,2,3,...,1,2,3) 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 -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.,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]]))) seeds_p = np.vstack((seeds_p-np.array([0.,0.,size[2]]),seeds_p,seeds_p+np.array([0.,0.,size[2]])))
else: else:
weights_p = weights.flatten() weights_p = weights.flatten()
seeds_p = seeds seeds_p = seeds
if cpus > 1: if cpus > 1:
default_args = partial(findClosestSeed,seeds_p,weights_p) default_args = partial(findClosestSeed,seeds_p,weights_p)
pool = multiprocessing.Pool(processes = cpus) # initialize workers pool = multiprocessing.Pool(processes = cpus) # initialize workers
result = pool.map_async(default_args, [point for point in grid]) # evaluate function in parallel result = pool.map_async(default_args, [point for point in grid]) # evaluate function in parallel
pool.close() pool.close()
pool.join() pool.join()
closestSeeds = np.array(result.get()).flatten() closestSeeds = np.array(result.get()).flatten()
else: else:
closestSeeds= np.array([findClosestSeed(seeds_p,weights_p,point) for point in grid]) 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): def Voronoi_tessellation(grid, seeds, grains, size, periodic = True):
KDTree = spatial.cKDTree(seeds,boxsize=size) if periodic else spatial.cKDTree(seeds) KDTree = spatial.cKDTree(seeds,boxsize=size) if periodic else spatial.cKDTree(seeds)
devNull,closestSeeds = KDTree.query(grid) devNull,closestSeeds = KDTree.query(grid)
return grains[closestSeeds] return grains[closestSeeds]
# -------------------------------------------------------------------- # --------------------------------------------------------------------

View File

@ -2,7 +2,6 @@
import os import os
import sys import sys
import random
from optparse import OptionParser,OptionGroup from optparse import OptionParser,OptionGroup
import numpy as np import numpy as np
@ -139,8 +138,8 @@ for name in filenames:
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[unpicked.mask==False],replace=False, candidates = np.random.choice(unpicked[not unpicked.mask],replace=False,
size=min(len(unpicked[unpicked.mask==False]),options.numCandidates)) size=min(len(unpicked[not 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(coords[candidates])
best = distances.argmax() 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 from .material import Material # noqa