This commit is contained in:
Martin Diehl 2019-05-30 14:07:49 +02:00
parent d0c7f8b934
commit bf60cffab5
20 changed files with 89 additions and 89 deletions

View File

@ -24,7 +24,7 @@ These objects can be boxes, cylinders, or ellipsoids.
""", version = scriptID) """, version = scriptID)
parser.add_option('-c', '--center', parser.add_option('-c', '--center',
dest='center', dest='center',
type='float', nargs = 3, metavar=' '.join(['float']*3), type='float', nargs = 3, metavar=' '.join(['float']*3),
help='a,b,c origin of primitive %default') help='a,b,c origin of primitive %default')
parser.add_option('-d', '--dimension', parser.add_option('-d', '--dimension',
@ -78,7 +78,7 @@ parser.set_defaults(center = (.0,.0,.0),
(options, filenames) = parser.parse_args() (options, filenames) = parser.parse_args()
if options.dimension is None: if options.dimension is None:
parser.error('no dimension specified.') parser.error('no dimension specified.')
if [options.angleaxis,options.quaternion].count(None) == 0: if [options.angleaxis,options.quaternion].count(None) == 0:
parser.error('more than one rotation specified.') parser.error('more than one rotation specified.')
@ -94,7 +94,7 @@ if filenames == []: filenames = [None]
for name in filenames: for name in filenames:
damask.util.report(scriptName,name) damask.util.report(scriptName,name)
geom = damask.Geom.from_file(StringIO(''.join(sys.stdin.read())) if name is None else name) geom = damask.Geom.from_file(StringIO(''.join(sys.stdin.read())) if name is None else name)
grid = geom.get_grid() grid = geom.get_grid()
size = geom.get_size() size = geom.get_size()
@ -106,7 +106,7 @@ for name in filenames:
else: else:
center = (np.array(options.center) + 0.5)/grid center = (np.array(options.center) + 0.5)/grid
r = np.array(options.dimension)/grid/2.0 r = np.array(options.dimension)/grid/2.0
if np.any(center<0.0) or np.any(center>=1.0): print('error') if np.any(center<0.0) or np.any(center>=1.0): print('error')
offset = np.ones(3)*0.5 if options.periodic else center offset = np.ones(3)*0.5 if options.periodic else center
@ -120,17 +120,17 @@ for name in filenames:
for z in range(grid[2]): for z in range(grid[2]):
coords = np.array([x+0.5,y+0.5,z+0.5])/grid coords = np.array([x+0.5,y+0.5,z+0.5])/grid
mask[x,y,z] = np.sum(np.abs((rotation*(coords-offset))/r)**e) < 1 mask[x,y,z] = np.sum(np.abs((rotation*(coords-offset))/r)**e) < 1
if options.periodic: if options.periodic:
shift = ((offset-center)*grid).astype(int) shift = ((offset-center)*grid).astype(int)
mask = np.roll(mask,shift,(0,1,2)) mask = np.roll(mask,shift,(0,1,2))
if options.inside: mask = np.logical_not(mask) if options.inside: mask = np.logical_not(mask)
fill = np.nanmax(geom.microstructure)+1 if options.fill is None else options.fill fill = np.nanmax(geom.microstructure)+1 if options.fill is None else options.fill
damask.util.croak(geom.update(np.where(mask,geom.microstructure,fill))) damask.util.croak(geom.update(np.where(mask,geom.microstructure,fill)))
geom.add_comments(scriptID + ' ' + ' '.join(sys.argv[1:])) geom.add_comments(scriptID + ' ' + ' '.join(sys.argv[1:]))
if name is None: if name is None:
sys.stdout.write(str(geom.show())) sys.stdout.write(str(geom.show()))
else: else:

View File

@ -45,7 +45,7 @@ if filenames == []: filenames = [None]
for name in filenames: for name in filenames:
damask.util.report(scriptName,name) damask.util.report(scriptName,name)
geom = damask.Geom.from_file(StringIO(''.join(sys.stdin.read())) if name is None else name) geom = damask.Geom.from_file(StringIO(''.join(sys.stdin.read())) if name is None else name)
grid = geom.get_grid() grid = geom.get_grid()
@ -56,13 +56,13 @@ for name in filenames:
new = np.full(grid,options.fill if options.fill is not None new = np.full(grid,options.fill if options.fill is not None
else np.nanmax(geom.microstructure)+1,geom.microstructure.dtype) else np.nanmax(geom.microstructure)+1,geom.microstructure.dtype)
for x in range(geom.microstructure.shape[0]): for x in range(geom.microstructure.shape[0]):
X = x + options.offset[0] X = x + options.offset[0]
if not 0 <= X < new.shape[0]: continue if not 0 <= X < new.shape[0]: continue
for y in range(geom.microstructure.shape[1]): for y in range(geom.microstructure.shape[1]):
Y = y + options.offset[1] Y = y + options.offset[1]
if not 0 <= Y < new.shape[1]: continue if not 0 <= Y < new.shape[1]: continue
for z in range(geom.microstructure.shape[2]): for z in range(geom.microstructure.shape[2]):
Z = z + options.offset[2] Z = z + options.offset[2]
if not 0 <= Z < new.shape[2]: continue if not 0 <= Z < new.shape[2]: continue

View File

@ -5,7 +5,7 @@ if [[ "$1" == "-f" || "$1" == "--float" ]]; then
arg='--float' arg='--float'
else else
arg='' arg=''
fi fi
for geom in "$@" for geom in "$@"
do do

View File

@ -43,7 +43,7 @@ if filenames == []: filenames = [None]
for name in filenames: for name in filenames:
damask.util.report(scriptName,name) damask.util.report(scriptName,name)
geom = damask.Geom.from_file(StringIO(''.join(sys.stdin.read())) if name is None else name) geom = damask.Geom.from_file(StringIO(''.join(sys.stdin.read())) if name is None else name)
damask.util.croak(geom.update(ndimage.filters.generic_filter( damask.util.croak(geom.update(ndimage.filters.generic_filter(

View File

@ -78,7 +78,7 @@ for name in filenames:
damask.util.report(scriptName,name) damask.util.report(scriptName,name)
errors = [] errors = []
inFile = h5py.File(name, 'r') inFile = h5py.File(name, 'r')
group_geom = os.path.join(rootDir,options.basegroup,'_SIMPL_GEOMETRY') group_geom = os.path.join(rootDir,options.basegroup,'_SIMPL_GEOMETRY')
try: try:
@ -88,8 +88,8 @@ for name in filenames:
origin = inFile[os.path.join(group_geom,'ORIGIN')][...] origin = inFile[os.path.join(group_geom,'ORIGIN')][...]
except: except:
errors.append('Geometry data ({}) not found'.format(group_geom)) errors.append('Geometry data ({}) not found'.format(group_geom))
group_pointwise = os.path.join(rootDir,options.basegroup,options.pointwise) group_pointwise = os.path.join(rootDir,options.basegroup,options.pointwise)
if options.average is None: if options.average is None:
label = 'Point' label = 'Point'
@ -100,33 +100,33 @@ for name in filenames:
rot = [damask.Rotation.fromQuaternion(q,True,P=+1) for q in quats] rot = [damask.Rotation.fromQuaternion(q,True,P=+1) for q in quats]
except: except:
errors.append('Pointwise orientation (quaternion) data ({}) not readable'.format(dataset)) errors.append('Pointwise orientation (quaternion) data ({}) not readable'.format(dataset))
dataset = os.path.join(group_pointwise,options.phase) dataset = os.path.join(group_pointwise,options.phase)
try: try:
phase = np.reshape(inFile[dataset][...],(np.product(grid))) phase = np.reshape(inFile[dataset][...],(np.product(grid)))
except: except:
errors.append('Pointwise phase data ({}) not readable'.format(dataset)) errors.append('Pointwise phase data ({}) not readable'.format(dataset))
microstructure = np.arange(1,np.product(grid)+1,dtype=int).reshape(grid,order='F') microstructure = np.arange(1,np.product(grid)+1,dtype=int).reshape(grid,order='F')
else: else:
label = 'Grain' label = 'Grain'
dataset = os.path.join(group_pointwise,options.microstructure) dataset = os.path.join(group_pointwise,options.microstructure)
try: try:
microstructure = np.transpose(inFile[dataset][...].reshape(grid[::-1]),(2,1,0)) # convert from C ordering microstructure = np.transpose(inFile[dataset][...].reshape(grid[::-1]),(2,1,0)) # convert from C ordering
except: except:
errors.append('Link between pointwise and grain average data ({}) not readable'.format(dataset)) errors.append('Link between pointwise and grain average data ({}) not readable'.format(dataset))
group_average = os.path.join(rootDir,options.basegroup,options.average) group_average = os.path.join(rootDir,options.basegroup,options.average)
dataset = os.path.join(group_average,options.quaternion) dataset = os.path.join(group_average,options.quaternion)
try: try:
rot = [damask.Rotation.fromQuaternion(q,True,P=+1) for q in inFile[dataset][...][1:]] # skip first entry (unindexed) rot = [damask.Rotation.fromQuaternion(q,True,P=+1) for q in inFile[dataset][...][1:]] # skip first entry (unindexed)
except: except:
errors.append('Average orientation data ({}) not readable'.format(dataset)) errors.append('Average orientation data ({}) not readable'.format(dataset))
dataset = os.path.join(group_average,options.phase) dataset = os.path.join(group_average,options.phase)
try: try:
phase = [i[0] for i in inFile[dataset][...]][1:] # skip first entry (unindexed) phase = [i[0] for i in inFile[dataset][...]][1:] # skip first entry (unindexed)
@ -148,7 +148,7 @@ for name in filenames:
'crystallite 1', 'crystallite 1',
'(constituent)\tphase {}\ttexture {}\tfraction 1.0'.format(phase[i],i+1), '(constituent)\tphase {}\ttexture {}\tfraction 1.0'.format(phase[i],i+1),
] ]
header = [scriptID + ' ' + ' '.join(sys.argv[1:])]\ header = [scriptID + ' ' + ' '.join(sys.argv[1:])]\
+ config_header + config_header
geom = damask.Geom(microstructure,size,origin, geom = damask.Geom(microstructure,size,origin,

View File

@ -85,7 +85,7 @@ for x in range(options.grid[0]):
for y in range(options.grid[1]): for y in range(options.grid[1]):
for z in range(options.grid[2]): for z in range(options.grid[2]):
microstructure[x,y,z]=options.microstructure[int(options.threshold < surface[options.type](X[x],Y[y],Z[z]))] microstructure[x,y,z]=options.microstructure[int(options.threshold < surface[options.type](X[x],Y[y],Z[z]))]
geom=damask.Geom(microstructure,options.size, geom=damask.Geom(microstructure,options.size,
homogenization=options.homogenization, homogenization=options.homogenization,
comments=[scriptID + ' ' + ' '.join(sys.argv[1:])]) comments=[scriptID + ' ' + ' '.join(sys.argv[1:])])

View File

@ -52,7 +52,7 @@ parser.add_option( '--aspect',
dest='aspect', dest='aspect',
type='float', metavar = 'float', type='float', metavar = 'float',
help='vertical/horizontal osteon aspect ratio [%default]') help='vertical/horizontal osteon aspect ratio [%default]')
parser.add_option('-w', '--omega', parser.add_option('-w', '--omega',
dest='omega', dest='omega',
type='float', metavar = 'float', type='float', metavar = 'float',
help='rotation angle around normal of osteon [%default]') help='rotation angle around normal of osteon [%default]')
@ -112,7 +112,7 @@ for y in range(grid[1]):
microstructure[x,y] = i microstructure[x,y] = i
Alpha[i] = alpha[x,y] Alpha[i] = alpha[x,y]
Beta [i] = beta [x,y] Beta [i] = beta [x,y]
i+=1 i+=1
config_header = ['<texture>', config_header = ['<texture>',
'[canal]', '[canal]',
@ -122,7 +122,7 @@ for i in range(3,np.max(microstructure)):
config_header += ['[Point{}]'.format(i-2), config_header += ['[Point{}]'.format(i-2),
'(gauss)\tphi1 {:.2f}\tPhi {:.2f}\tphi2 0'.format(Alpha[i],Beta[i]) '(gauss)\tphi1 {:.2f}\tPhi {:.2f}\tphi2 0'.format(Alpha[i],Beta[i])
] ]
config_header = ['<microstructure>', config_header = ['<microstructure>',
'[canal]', '[canal]',
'crystallite 1', 'crystallite 1',
@ -143,7 +143,7 @@ geom = damask.Geom(microstructure.reshape(grid),
size,-size/2, size,-size/2,
homogenization=options.homogenization,comments=header) homogenization=options.homogenization,comments=header)
damask.util.croak(geom) damask.util.croak(geom)
if name is None: if name is None:
sys.stdout.write(str(geom.show())) sys.stdout.write(str(geom.show()))
else: else:

View File

@ -63,7 +63,7 @@ geom = damask.Geom(microstructure=np.full(options.grid,options.fill,dtype=dtype)
homogenization=options.homogenization, homogenization=options.homogenization,
comments=scriptID + ' ' + ' '.join(sys.argv[1:])) comments=scriptID + ' ' + ' '.join(sys.argv[1:]))
damask.util.croak(geom) damask.util.croak(geom)
if name is None: if name is None:
sys.stdout.write(str(geom.show())) sys.stdout.write(str(geom.show()))
else: else:

View File

@ -18,7 +18,7 @@ scriptID = ' '.join([scriptName,damask.version])
# -------------------------------------------------------------------- # --------------------------------------------------------------------
parser = OptionParser(option_class=damask.extendableOption, usage='%prog options [ASCIItable(s)]', description = """ parser = OptionParser(option_class=damask.extendableOption, usage='%prog options [ASCIItable(s)]', description = """
Converts ASCII table. Input can be microstructure or orientation (as quaternion). For the latter, Converts ASCII table. Input can be microstructure or orientation (as quaternion). For the latter,
phase information can be given additionally. phase information can be given additionally.
""", version = scriptID) """, version = scriptID)
@ -78,7 +78,7 @@ for name in filenames:
table = damask.ASCIItable(name = name,readonly=True) table = damask.ASCIItable(name = name,readonly=True)
table.head_read() # read ASCII header info table.head_read() # read ASCII header info
# ------------------------------------------ sanity checks --------------------------------------- # ------------------------------------------ sanity checks ---------------------------------------
coordDim = table.label_dimension(options.pos) coordDim = table.label_dimension(options.pos)
@ -89,7 +89,7 @@ for name in filenames:
errors.append('input "{}" needs to have dimension {}.'.format(label,dim)) errors.append('input "{}" needs to have dimension {}.'.format(label,dim))
if options.phase and table.label_dimension(options.phase) != 1: if options.phase and table.label_dimension(options.phase) != 1:
errors.append('phase column "{}" is not scalar.'.format(options.phase)) errors.append('phase column "{}" is not scalar.'.format(options.phase))
if errors != []: if errors != []:
damask.util.croak(errors) damask.util.croak(errors)
continue continue
@ -97,7 +97,7 @@ for name in filenames:
table.data_readArray([options.pos] \ table.data_readArray([options.pos] \
+ (label if isinstance(label, list) else [label]) \ + (label if isinstance(label, list) else [label]) \
+ ([options.phase] if options.phase else [])) + ([options.phase] if options.phase else []))
if coordDim == 2: if coordDim == 2:
table.data = np.insert(table.data,2,np.zeros(len(table.data)),axis=1) # add zero z coordinate for two-dimensional input table.data = np.insert(table.data,2,np.zeros(len(table.data)),axis=1) # add zero z coordinate for two-dimensional input
if options.phase is None: if options.phase is None:
@ -112,7 +112,7 @@ for name in filenames:
indices = np.lexsort((table.data[:,0],table.data[:,1],table.data[:,2])) # indices of position when sorting x fast, z slow indices = np.lexsort((table.data[:,0],table.data[:,1],table.data[:,2])) # indices of position when sorting x fast, z slow
microstructure = np.empty(grid,dtype = int) # initialize empty microstructure microstructure = np.empty(grid,dtype = int) # initialize empty microstructure
i = 0 i = 0
if inputtype == 'microstructure': if inputtype == 'microstructure':
for z in range(grid[2]): for z in range(grid[2]):
for y in range(grid[1]): for y in range(grid[1]):
@ -124,21 +124,21 @@ for name in filenames:
elif inputtype == 'quaternion': elif inputtype == 'quaternion':
unique,unique_inverse = np.unique(table.data[:,3:8],return_inverse=True,axis=0) unique,unique_inverse = np.unique(table.data[:,3:8],return_inverse=True,axis=0)
for z in range(grid[2]): for z in range(grid[2]):
for y in range(grid[1]): for y in range(grid[1]):
for x in range(grid[0]): for x in range(grid[0]):
microstructure[x,y,z] = unique_inverse[indices[i]]+1 microstructure[x,y,z] = unique_inverse[indices[i]]+1
i+=1 i+=1
config_header = ['<texture>'] config_header = ['<texture>']
for i,data in enumerate(unique): for i,data in enumerate(unique):
ori = damask.Rotation(data[0:4]) ori = damask.Rotation(data[0:4])
config_header += ['[Grain{}]'.format(i+1), config_header += ['[Grain{}]'.format(i+1),
'(gauss)\tphi1 {:g}\tPhi {:g}\tphi2 {:g}'.format(*ori.asEulers(degrees = True)), '(gauss)\tphi1 {:g}\tPhi {:g}\tphi2 {:g}'.format(*ori.asEulers(degrees = True)),
] ]
if options.axes is not None: config_header += ['axes\t{} {} {}'.format(*options.axes)] if options.axes is not None: config_header += ['axes\t{} {} {}'.format(*options.axes)]
config_header += ['<microstructure>'] config_header += ['<microstructure>']
for i,data in enumerate(unique): for i,data in enumerate(unique):
config_header += ['[Grain{}]'.format(i+1), config_header += ['[Grain{}]'.format(i+1),
@ -151,7 +151,7 @@ for name in filenames:
geom = damask.Geom(microstructure,size,origin, geom = damask.Geom(microstructure,size,origin,
homogenization=options.homogenization,comments=header) homogenization=options.homogenization,comments=header)
damask.util.croak(geom) damask.util.croak(geom)
if name is None: if name is None:
sys.stdout.write(str(geom.show())) sys.stdout.write(str(geom.show()))
else: else:

View File

@ -1,7 +1,7 @@
#!/usr/bin/env python3 #!/usr/bin/env python3
import os import os
import sys import sys
import multiprocessing import multiprocessing
from optparse import OptionParser,OptionGroup from optparse import OptionParser,OptionGroup
@ -22,7 +22,7 @@ def laguerreTessellation(undeformed, coords, weights, grains, periodic = True, c
tmp = np.repeat(point.reshape(3,1), len(seeds), axis=1).T tmp = np.repeat(point.reshape(3,1), len(seeds), axis=1).T
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 = \ copies = \
np.array([ np.array([
[ -1,-1,-1 ], [ -1,-1,-1 ],
@ -60,7 +60,7 @@ def laguerreTessellation(undeformed, coords, weights, grains, periodic = True, c
repeatweights = np.tile(weights,len(copies)).flatten(order='F') # Laguerre weights (1,2,3,1,2,3,...,1,2,3) repeatweights = np.tile(weights,len(copies)).flatten(order='F') # Laguerre weights (1,2,3,1,2,3,...,1,2,3)
for i,vec in enumerate(copies): # periodic copies of seed points ... for i,vec in enumerate(copies): # periodic copies of seed points ...
try: seeds = np.append(seeds, coords+vec, axis=0) # ... (1+a,2+a,3+a,...,1+z,2+z,3+z) try: seeds = np.append(seeds, coords+vec, axis=0) # ... (1+a,2+a,3+a,...,1+z,2+z,3+z)
except NameError: seeds = coords+vec except NameError: seeds = coords+vec
if (repeatweights == 0.0).all(): # standard Voronoi (no weights, KD tree) if (repeatweights == 0.0).all(): # standard Voronoi (no weights, KD tree)
myKDTree = spatial.cKDTree(seeds) myKDTree = spatial.cKDTree(seeds)
@ -81,7 +81,7 @@ def laguerreTessellation(undeformed, coords, weights, grains, periodic = True, c
closestSeeds[i] = findClosestSeed(arg) closestSeeds[i] = findClosestSeed(arg)
# closestSeed is modulo number of original seed points (i.e. excluding periodic copies) # closestSeed is modulo number of original seed points (i.e. excluding periodic copies)
return grains[closestSeeds%coords.shape[0]] return grains[closestSeeds%coords.shape[0]]
# -------------------------------------------------------------------- # --------------------------------------------------------------------
@ -202,7 +202,7 @@ if filenames == []: filenames = [None]
for name in filenames: for name in filenames:
damask.util.report(scriptName,name) damask.util.report(scriptName,name)
table = damask.ASCIItable(name = name, readonly = True) table = damask.ASCIItable(name = name, readonly = True)
@ -210,17 +210,17 @@ for name in filenames:
table.head_read() table.head_read()
info,extra_header = table.head_getGeom() info,extra_header = table.head_getGeom()
if options.grid is not None: info['grid'] = options.grid if options.grid is not None: info['grid'] = options.grid
if options.size is not None: info['size'] = options.size if options.size is not None: info['size'] = options.size
if options.origin is not None: info['origin'] = options.origin if options.origin is not None: info['origin'] = options.origin
# ------------------------------------------ sanity checks --------------------------------------- # ------------------------------------------ sanity checks ---------------------------------------
remarks = [] remarks = []
errors = [] errors = []
labels = [] labels = []
hasGrains = table.label_dimension(options.microstructure) == 1 hasGrains = table.label_dimension(options.microstructure) == 1
hasEulers = table.label_dimension(options.eulers) == 3 hasEulers = table.label_dimension(options.eulers) == 3
hasWeights = table.label_dimension(options.weight) == 1 and options.laguerre hasWeights = table.label_dimension(options.weight) == 1 and options.laguerre
@ -250,8 +250,8 @@ for name in filenames:
table.close(dismiss=True) table.close(dismiss=True)
continue continue
# ------------------------------------------ read seeds --------------------------------------- # ------------------------------------------ read seeds ---------------------------------------
table.data_readArray(labels) table.data_readArray(labels)
coords = table.data[:,table.label_indexrange(options.pos)] * info['size'] if options.normalized \ coords = table.data[:,table.label_indexrange(options.pos)] * info['size'] if options.normalized \
else table.data[:,table.label_indexrange(options.pos)] - info['origin'] else table.data[:,table.label_indexrange(options.pos)] - info['origin']
@ -271,13 +271,13 @@ for name in filenames:
z = (np.arange(info['grid'][2])+0.5)*info['size'][2]/info['grid'][2] z = (np.arange(info['grid'][2])+0.5)*info['size'][2]/info['grid'][2]
X,Y,Z = np.meshgrid(x, y, z,indexing='ij') X,Y,Z = np.meshgrid(x, y, z,indexing='ij')
grid = np.stack((X,Y,Z),axis=-1).reshape((info['grid'].prod(),3),order='F') grid = np.stack((X,Y,Z),axis=-1).reshape((info['grid'].prod(),3),order='F')
damask.util.croak('tessellating...') damask.util.croak('tessellating...')
indices = laguerreTessellation(grid, coords, weights, grains, options.periodic, options.cpus) indices = laguerreTessellation(grid, coords, weights, grains, options.periodic, options.cpus)
config_header = [] config_header = []
if options.config: if options.config:
if hasEulers: if hasEulers:
config_header += ['<texture>'] config_header += ['<texture>']
for ID in grainIDs: for ID in grainIDs:
@ -286,7 +286,7 @@ for name in filenames:
'(gauss)\tphi1 {:.2f}\tPhi {:.2f}\tphi2 {:.2f}'.format(*eulers[eulerID]) '(gauss)\tphi1 {:.2f}\tPhi {:.2f}\tphi2 {:.2f}'.format(*eulers[eulerID])
] ]
if options.axes is not None: config_header += ['axes\t{} {} {}'.format(*options.axes)] if options.axes is not None: config_header += ['axes\t{} {} {}'.format(*options.axes)]
config_header += ['<microstructure>'] config_header += ['<microstructure>']
for ID in grainIDs: for ID in grainIDs:
config_header += ['[Grain{}]'.format(ID), config_header += ['[Grain{}]'.format(ID),
@ -295,13 +295,13 @@ for name in filenames:
] ]
config_header += ['<!skip>'] config_header += ['<!skip>']
header = [scriptID + ' ' + ' '.join(sys.argv[1:])]\ header = [scriptID + ' ' + ' '.join(sys.argv[1:])]\
+ config_header + config_header
geom = damask.Geom(indices.reshape(info['grid'],order='F'),info['size'],info['origin'], geom = damask.Geom(indices.reshape(info['grid'],order='F'),info['size'],info['origin'],
homogenization=options.homogenization,comments=header) homogenization=options.homogenization,comments=header)
damask.util.croak(geom) damask.util.croak(geom)
if name is None: if name is None:
sys.stdout.write(str(geom.show())) sys.stdout.write(str(geom.show()))
else: else:

View File

@ -60,9 +60,9 @@ if filenames == []: filenames = [None]
for name in filenames: for name in filenames:
damask.util.report(scriptName,name) damask.util.report(scriptName,name)
geom = damask.Geom.from_file(StringIO(''.join(sys.stdin.read())) if name is None else name) geom = damask.Geom.from_file(StringIO(''.join(sys.stdin.read())) if name is None else name)
grid_original = geom.get_grid() grid_original = geom.get_grid()
damask.util.croak(geom) damask.util.croak(geom)
microstructure = np.tile(geom.microstructure,np.where(grid_original == 1, 2,1)) # make one copy along dimensions with grid == 1 microstructure = np.tile(geom.microstructure,np.where(grid_original == 1, 2,1)) # make one copy along dimensions with grid == 1
@ -71,15 +71,15 @@ for name in filenames:
# --- initialize support data --------------------------------------------------------------------- # --- initialize support data ---------------------------------------------------------------------
# store a copy the initial microstructure to find locations of immutable indices # store a copy the initial microstructure to find locations of immutable indices
microstructure_original = np.copy(microstructure) microstructure_original = np.copy(microstructure)
if not options.ndimage: if not options.ndimage:
X,Y,Z = np.mgrid[0:grid[0],0:grid[1],0:grid[2]] X,Y,Z = np.mgrid[0:grid[0],0:grid[1],0:grid[2]]
# Calculates gaussian weights for simulating 3d diffusion # Calculates gaussian weights for simulating 3d diffusion
gauss = np.exp(-(X*X + Y*Y + Z*Z)/(2.0*options.d*options.d),dtype=np.float32) \ gauss = np.exp(-(X*X + Y*Y + Z*Z)/(2.0*options.d*options.d),dtype=np.float32) \
/np.power(2.0*np.pi*options.d*options.d,(3.0 - np.count_nonzero(grid_original == 1))/2.,dtype=np.float32) /np.power(2.0*np.pi*options.d*options.d,(3.0 - np.count_nonzero(grid_original == 1))/2.,dtype=np.float32)
gauss[:,:,:grid[2]//2:-1] = gauss[:,:,1:(grid[2]+1)//2] # trying to cope with uneven (odd) grid size gauss[:,:,:grid[2]//2:-1] = gauss[:,:,1:(grid[2]+1)//2] # trying to cope with uneven (odd) grid size
gauss[:,:grid[1]//2:-1,:] = gauss[:,1:(grid[1]+1)//2,:] gauss[:,:grid[1]//2:-1,:] = gauss[:,1:(grid[1]+1)//2,:]
gauss[:grid[0]//2:-1,:,:] = gauss[1:(grid[0]+1)//2,:,:] gauss[:grid[0]//2:-1,:,:] = gauss[1:(grid[0]+1)//2,:,:]
@ -102,7 +102,7 @@ for name in filenames:
grid[2]//2:-grid[2]//2] grid[2]//2:-grid[2]//2]
# transform bulk volume (i.e. where interfacial energy remained zero), store index of closest boundary voxel # transform bulk volume (i.e. where interfacial energy remained zero), store index of closest boundary voxel
index = ndimage.morphology.distance_transform_edt(periodic_interfaceEnergy == 0., index = ndimage.morphology.distance_transform_edt(periodic_interfaceEnergy == 0.,
return_distances = False, return_distances = False,
return_indices = True) return_indices = True)

View File

@ -32,7 +32,7 @@ parser.add_option('-d','--direction',
parser.add_option( '--periodic', parser.add_option( '--periodic',
dest = 'periodic', dest = 'periodic',
action = 'store_true', action = 'store_true',
help = 'omit periodic copies of outermost layers in mirror direction') help = 'omit periodic copies of outermost layers in mirror direction')
parser.set_defaults(periodic = False) parser.set_defaults(periodic = False)
@ -52,9 +52,9 @@ if filenames == []: filenames = [None]
for name in filenames: for name in filenames:
damask.util.report(scriptName,name) damask.util.report(scriptName,name)
geom = damask.Geom.from_file(StringIO(''.join(sys.stdin.read())) if name is None else name) geom = damask.Geom.from_file(StringIO(''.join(sys.stdin.read())) if name is None else name)
microstructure = geom.get_microstructure() microstructure = geom.get_microstructure()
if 'z' in options.directions: if 'z' in options.directions:
microstructure = np.concatenate([microstructure,microstructure[:,:,limits[0]:limits[1]:-1]],2) microstructure = np.concatenate([microstructure,microstructure[:,:,limits[0]:limits[1]:-1]],2)
@ -62,10 +62,10 @@ for name in filenames:
microstructure = np.concatenate([microstructure,microstructure[:,limits[0]:limits[1]:-1,:]],1) microstructure = np.concatenate([microstructure,microstructure[:,limits[0]:limits[1]:-1,:]],1)
if 'x' in options.directions: if 'x' in options.directions:
microstructure = np.concatenate([microstructure,microstructure[limits[0]:limits[1]:-1,:,:]],0) microstructure = np.concatenate([microstructure,microstructure[limits[0]:limits[1]:-1,:,:]],0)
damask.util.croak(geom.update(microstructure,rescale=True)) damask.util.croak(geom.update(microstructure,rescale=True))
geom.add_comments(scriptID + ' ' + ' '.join(sys.argv[1:])) geom.add_comments(scriptID + ' ' + ' '.join(sys.argv[1:]))
if name is None: if name is None:
sys.stdout.write(str(geom.show())) sys.stdout.write(str(geom.show()))
else: else:

View File

@ -33,7 +33,7 @@ for name in filenames:
damask.util.croak(geom) damask.util.croak(geom)
geom.add_comments(scriptID + ' ' + ' '.join(sys.argv[1:])) geom.add_comments(scriptID + ' ' + ' '.join(sys.argv[1:]))
compressType = None compressType = None
former = start = -1 former = start = -1
reps = 0 reps = 0
@ -65,7 +65,7 @@ for name in filenames:
reps = 1 reps = 1
former = current former = current
if compressType == '.': if compressType == '.':
f.write('{}\n'.format(former)) f.write('{}\n'.format(former))
elif compressType == 'to': elif compressType == 'to':

View File

@ -30,16 +30,16 @@ if filenames == []: filenames = [None]
for name in filenames: for name in filenames:
damask.util.report(scriptName,name) damask.util.report(scriptName,name)
geom = damask.Geom.from_file(StringIO(''.join(sys.stdin.read())) if name is None else name) geom = damask.Geom.from_file(StringIO(''.join(sys.stdin.read())) if name is None else name)
renumbered = np.empty(geom.get_grid(),dtype=geom.microstructure.dtype) renumbered = np.empty(geom.get_grid(),dtype=geom.microstructure.dtype)
for i, oldID in enumerate(np.unique(geom.microstructure)): for i, oldID in enumerate(np.unique(geom.microstructure)):
renumbered = np.where(geom.microstructure == oldID, i+1, renumbered) renumbered = np.where(geom.microstructure == oldID, i+1, renumbered)
damask.util.croak(geom.update(renumbered)) damask.util.croak(geom.update(renumbered))
geom.add_comments(scriptID + ' ' + ' '.join(sys.argv[1:])) geom.add_comments(scriptID + ' ' + ' '.join(sys.argv[1:]))
if name is None: if name is None:
sys.stdout.write(str(geom.show())) sys.stdout.write(str(geom.show()))
else: else:

View File

@ -41,7 +41,7 @@ if filenames == []: filenames = [None]
for name in filenames: for name in filenames:
damask.util.report(scriptName,name) damask.util.report(scriptName,name)
geom = damask.Geom.from_file(StringIO(''.join(sys.stdin.read())) if name is None else name) geom = damask.Geom.from_file(StringIO(''.join(sys.stdin.read())) if name is None else name)
grid = geom.get_grid() grid = geom.get_grid()
@ -55,7 +55,7 @@ for name in filenames:
np.array([o*float(n.lower().replace('x','')) if n.lower().endswith('x') \ np.array([o*float(n.lower().replace('x','')) if n.lower().endswith('x') \
else float(n) for o,n in zip(size,options.size)],dtype=float) else float(n) for o,n in zip(size,options.size)],dtype=float)
damask.util.croak(geom.update(microstructure = damask.util.croak(geom.update(microstructure =
ndimage.interpolation.zoom( ndimage.interpolation.zoom(
geom.microstructure, geom.microstructure,
new_grid/grid,output=geom.microstructure.dtype, new_grid/grid,output=geom.microstructure.dtype,

View File

@ -76,7 +76,7 @@ for name in filenames:
damask.util.report(scriptName,name) damask.util.report(scriptName,name)
geom = damask.Geom.from_file(StringIO(''.join(sys.stdin.read())) if name is None else name) geom = damask.Geom.from_file(StringIO(''.join(sys.stdin.read())) if name is None else name)
microstructure = geom.get_microstructure() microstructure = geom.get_microstructure()
fill = np.nanmax(microstructure)+1 if options.fill is None else options.fill fill = np.nanmax(microstructure)+1 if options.fill is None else options.fill
dtype = float if np.isnan(fill) or int(fill) != fill or microstructure.dtype==np.float else int dtype = float if np.isnan(fill) or int(fill) != fill or microstructure.dtype==np.float else int
@ -89,10 +89,10 @@ for name in filenames:
prefilter=False,output=dtype,cval=fill) # rotation around x prefilter=False,output=dtype,cval=fill) # rotation around x
microstructure = ndimage.rotate(microstructure,eulers[0],(0,1),order=0, microstructure = ndimage.rotate(microstructure,eulers[0],(0,1),order=0,
prefilter=False,output=dtype,cval=fill) # rotation around z prefilter=False,output=dtype,cval=fill) # rotation around z
damask.util.croak(geom.update(microstructure,rescale=True)) damask.util.croak(geom.update(microstructure,rescale=True))
geom.add_comments(scriptID + ' ' + ' '.join(sys.argv[1:])) geom.add_comments(scriptID + ' ' + ' '.join(sys.argv[1:]))
if name is None: if name is None:
sys.stdout.write(str(geom.show())) sys.stdout.write(str(geom.show()))
else: else:

View File

@ -30,17 +30,17 @@ if filenames == []: filenames = [None]
for name in filenames: for name in filenames:
damask.util.report(scriptName,name) damask.util.report(scriptName,name)
geom = damask.Geom.from_file(StringIO(''.join(sys.stdin.read())) if name is None else name) geom = damask.Geom.from_file(StringIO(''.join(sys.stdin.read())) if name is None else name)
damask.util.croak(geom) damask.util.croak(geom)
# --- generate grid -------------------------------------------------------------------------------- # --- generate grid --------------------------------------------------------------------------------
grid = geom.get_grid() grid = geom.get_grid()
size = geom.get_size() size = geom.get_size()
origin = geom.get_origin() origin = geom.get_origin()
x = (0.5 + np.arange(grid[0],dtype=float))/grid[0]*size[0]+origin[0] x = (0.5 + np.arange(grid[0],dtype=float))/grid[0]*size[0]+origin[0]
y = (0.5 + np.arange(grid[1],dtype=float))/grid[1]*size[1]+origin[1] y = (0.5 + np.arange(grid[1],dtype=float))/grid[1]*size[1]+origin[1]
z = (0.5 + np.arange(grid[2],dtype=float))/grid[2]*size[2]+origin[2] z = (0.5 + np.arange(grid[2],dtype=float))/grid[2]*size[2]+origin[2]

View File

@ -48,13 +48,13 @@ if filenames == []: filenames = [None]
for name in filenames: for name in filenames:
damask.util.report(scriptName,name) damask.util.report(scriptName,name)
geom = damask.Geom.from_file(StringIO(''.join(sys.stdin.read())) if name is None else name) geom = damask.Geom.from_file(StringIO(''.join(sys.stdin.read())) if name is None else name)
substituted = geom.get_microstructure() substituted = geom.get_microstructure()
for old,new in zip(sub[0::2],sub[1::2]): substituted[substituted==old] = new # substitute microstructure indices for old,new in zip(sub[0::2],sub[1::2]): substituted[substituted==old] = new # substitute microstructure indices
substituted += options.microstructure # constant shift substituted += options.microstructure # constant shift
damask.util.croak(geom.update(substituted,origin=geom.get_origin()+options.origin)) damask.util.croak(geom.update(substituted,origin=geom.get_origin()+options.origin))
geom.add_comments(scriptID + ' ' + ' '.join(sys.argv[1:])) geom.add_comments(scriptID + ' ' + ' '.join(sys.argv[1:]))

View File

@ -30,10 +30,10 @@ for name in filenames:
damask.util.report(scriptName,name) damask.util.report(scriptName,name)
geom = damask.Geom.from_file(StringIO(''.join(sys.stdin.read())) if name is None else name) geom = damask.Geom.from_file(StringIO(''.join(sys.stdin.read())) if name is None else name)
damask.util.croak(geom) damask.util.croak(geom)
geom.add_comments(scriptID + ' ' + ' '.join(sys.argv[1:])) geom.add_comments(scriptID + ' ' + ' '.join(sys.argv[1:]))
if name is None: if name is None:
sys.stdout.write(str(geom.show())) sys.stdout.write(str(geom.show()))
else: else:

View File

@ -68,7 +68,7 @@ if filenames == []: filenames = [None]
for name in filenames: for name in filenames:
damask.util.report(scriptName,name) damask.util.report(scriptName,name)
geom = damask.Geom.from_file(StringIO(''.join(sys.stdin.read())) if name is None else name) geom = damask.Geom.from_file(StringIO(''.join(sys.stdin.read())) if name is None else name)
offset = np.nanmax(geom.microstructure) if options.offset is None else options.offset offset = np.nanmax(geom.microstructure) if options.offset is None else options.offset
@ -81,7 +81,7 @@ for name in filenames:
extra_keywords={"trigger":options.trigger,"size":1+2*options.vicinity}), extra_keywords={"trigger":options.trigger,"size":1+2*options.vicinity}),
geom.microstructure + offset,geom.microstructure))) geom.microstructure + offset,geom.microstructure)))
geom.add_comments(scriptID + ' ' + ' '.join(sys.argv[1:])) geom.add_comments(scriptID + ' ' + ' '.join(sys.argv[1:]))
if name is None: if name is None:
sys.stdout.write(str(geom.show())) sys.stdout.write(str(geom.show()))
else: else: