2018-11-15 21:10:54 +05:30
|
|
|
#!/usr/bin/env python
|
2015-06-21 17:26:05 +05:30
|
|
|
# -*- coding: UTF-8 no BOM -*-
|
|
|
|
|
2018-07-20 07:20:07 +05:30
|
|
|
import os,sys,math,time
|
2015-06-21 17:26:05 +05:30
|
|
|
import scipy.spatial, numpy as np
|
|
|
|
from optparse import OptionParser
|
|
|
|
import damask
|
|
|
|
|
2016-01-27 22:36:00 +05:30
|
|
|
scriptName = os.path.splitext(os.path.basename(__file__))[0]
|
|
|
|
scriptID = ' '.join([scriptName,damask.version])
|
2015-06-21 17:26:05 +05:30
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# --------------------------------------------------------------------
|
|
|
|
# MAIN
|
|
|
|
# --------------------------------------------------------------------
|
|
|
|
|
2016-05-12 12:24:34 +05:30
|
|
|
parser = OptionParser(option_class=damask.extendableOption, usage='%prog option(s) [ASCIItable(s)]', description = """
|
2015-08-13 00:26:40 +05:30
|
|
|
Generate geometry description and material configuration from position, phase, and orientation (or microstructure) data.
|
2015-06-21 17:26:05 +05:30
|
|
|
|
|
|
|
""", version = scriptID)
|
|
|
|
|
2015-08-08 00:33:26 +05:30
|
|
|
parser.add_option('--coordinates',
|
2016-04-27 02:19:58 +05:30
|
|
|
dest = 'pos',
|
2015-08-08 00:33:26 +05:30
|
|
|
type = 'string', metavar = 'string',
|
2017-05-29 14:02:22 +05:30
|
|
|
help = 'coordinates label (%default)')
|
2015-08-08 00:33:26 +05:30
|
|
|
parser.add_option('--phase',
|
|
|
|
dest = 'phase',
|
|
|
|
type = 'string', metavar = 'string',
|
|
|
|
help = 'phase label')
|
2015-08-13 00:26:40 +05:30
|
|
|
parser.add_option('--microstructure',
|
|
|
|
dest = 'microstructure',
|
|
|
|
type = 'string', metavar = 'string',
|
|
|
|
help = 'microstructure label')
|
2015-08-08 00:33:26 +05:30
|
|
|
parser.add_option('-t', '--tolerance',
|
|
|
|
dest = 'tolerance',
|
|
|
|
type = 'float', metavar = 'float',
|
2015-06-29 15:10:44 +05:30
|
|
|
help = 'angular tolerance for orientation squashing [%default]')
|
2015-08-08 00:33:26 +05:30
|
|
|
parser.add_option('-e', '--eulers',
|
|
|
|
dest = 'eulers',
|
|
|
|
type = 'string', metavar = 'string',
|
2015-06-21 17:26:05 +05:30
|
|
|
help = 'Euler angles label')
|
2015-08-08 00:33:26 +05:30
|
|
|
parser.add_option('-d', '--degrees',
|
|
|
|
dest = 'degrees',
|
|
|
|
action = 'store_true',
|
2015-06-21 17:26:05 +05:30
|
|
|
help = 'angles are given in degrees [%default]')
|
2015-08-08 00:33:26 +05:30
|
|
|
parser.add_option('-m', '--matrix',
|
|
|
|
dest = 'matrix',
|
|
|
|
type = 'string', metavar = 'string',
|
2015-06-21 17:26:05 +05:30
|
|
|
help = 'orientation matrix label')
|
2015-08-08 00:33:26 +05:30
|
|
|
parser.add_option('-a',
|
|
|
|
dest='a',
|
|
|
|
type = 'string', metavar = 'string',
|
2015-06-21 17:26:05 +05:30
|
|
|
help = 'crystal frame a vector label')
|
2015-08-08 00:33:26 +05:30
|
|
|
parser.add_option('-b',
|
|
|
|
dest='b',
|
|
|
|
type = 'string', metavar = 'string',
|
2015-06-21 17:26:05 +05:30
|
|
|
help = 'crystal frame b vector label')
|
2015-08-08 00:33:26 +05:30
|
|
|
parser.add_option('-c',
|
|
|
|
dest = 'c',
|
|
|
|
type = 'string', metavar='string',
|
2015-06-21 17:26:05 +05:30
|
|
|
help = 'crystal frame c vector label')
|
2015-08-08 00:33:26 +05:30
|
|
|
parser.add_option('-q', '--quaternion',
|
|
|
|
dest = 'quaternion',
|
|
|
|
type = 'string', metavar='string',
|
2015-06-21 17:26:05 +05:30
|
|
|
help = 'quaternion label')
|
2015-08-08 00:33:26 +05:30
|
|
|
parser.add_option('--axes',
|
|
|
|
dest = 'axes',
|
|
|
|
type = 'string', nargs = 3, metavar = ' '.join(['string']*3),
|
2015-06-21 17:26:05 +05:30
|
|
|
help = 'orientation coordinate frame in terms of position coordinate frame [same]')
|
2015-08-08 00:33:26 +05:30
|
|
|
parser.add_option('-s', '--symmetry',
|
|
|
|
dest = 'symmetry',
|
|
|
|
action = 'extend', metavar = '<string LIST>',
|
|
|
|
help = 'crystal symmetry %default {{{}}} '.format(', '.join(damask.Symmetry.lattices[1:])))
|
|
|
|
parser.add_option('--homogenization',
|
|
|
|
dest = 'homogenization',
|
|
|
|
type = 'int', metavar = 'int',
|
|
|
|
help = 'homogenization index to be used [%default]')
|
|
|
|
parser.add_option('--crystallite',
|
|
|
|
dest = 'crystallite',
|
|
|
|
type = 'int', metavar = 'int',
|
|
|
|
help = 'crystallite index to be used [%default]')
|
2015-11-30 21:52:59 +05:30
|
|
|
parser.add_option('--verbose',
|
|
|
|
dest = 'verbose', action = 'store_true',
|
|
|
|
help = 'output extra info')
|
2015-06-21 17:26:05 +05:30
|
|
|
|
2015-07-10 22:28:30 +05:30
|
|
|
parser.set_defaults(symmetry = [damask.Symmetry.lattices[-1]],
|
2015-06-21 17:26:05 +05:30
|
|
|
tolerance = 0.0,
|
|
|
|
degrees = False,
|
|
|
|
homogenization = 1,
|
|
|
|
crystallite = 1,
|
2015-12-03 04:43:10 +05:30
|
|
|
verbose = False,
|
2017-05-29 14:02:22 +05:30
|
|
|
pos = 'pos',
|
2015-06-21 17:26:05 +05:30
|
|
|
)
|
|
|
|
|
|
|
|
(options,filenames) = parser.parse_args()
|
|
|
|
|
2016-03-02 17:13:09 +05:30
|
|
|
input = [options.eulers is not None,
|
|
|
|
options.a is not None and \
|
|
|
|
options.b is not None and \
|
|
|
|
options.c is not None,
|
|
|
|
options.matrix is not None,
|
|
|
|
options.quaternion is not None,
|
|
|
|
options.microstructure is not None,
|
2015-06-21 17:26:05 +05:30
|
|
|
]
|
|
|
|
|
2015-08-21 01:12:05 +05:30
|
|
|
if np.sum(input) != 1:
|
2015-08-13 00:26:40 +05:30
|
|
|
parser.error('need either microstructure label or exactly one orientation input format.')
|
2016-03-02 17:13:09 +05:30
|
|
|
if options.axes is not None and not set(options.axes).issubset(set(['x','+x','-x','y','+y','-y','z','+z','-z'])):
|
2015-08-13 00:26:40 +05:30
|
|
|
parser.error('invalid axes {} {} {}.'.format(*options.axes))
|
2015-06-21 17:26:05 +05:30
|
|
|
|
|
|
|
(label,dim,inputtype) = [(options.eulers,3,'eulers'),
|
|
|
|
([options.a,options.b,options.c],[3,3,3],'frame'),
|
|
|
|
(options.matrix,9,'matrix'),
|
|
|
|
(options.quaternion,4,'quaternion'),
|
2015-08-21 01:12:05 +05:30
|
|
|
(options.microstructure,1,'microstructure'),
|
2015-06-21 17:26:05 +05:30
|
|
|
][np.where(input)[0][0]] # select input label that was requested
|
2015-11-20 21:57:57 +05:30
|
|
|
toRadians = math.pi/180.0 if options.degrees else 1.0 # rescale all angles to radians
|
|
|
|
threshold = np.cos(options.tolerance/2.*toRadians) # cosine of (half of) tolerance angle
|
2015-06-21 17:26:05 +05:30
|
|
|
|
|
|
|
# --- loop over input files -------------------------------------------------------------------------
|
2015-08-08 00:33:26 +05:30
|
|
|
|
2015-08-13 00:26:40 +05:30
|
|
|
if filenames == []: filenames = [None]
|
2015-06-21 17:26:05 +05:30
|
|
|
|
|
|
|
for name in filenames:
|
2015-08-13 00:26:40 +05:30
|
|
|
try:
|
2015-08-13 02:58:07 +05:30
|
|
|
table = damask.ASCIItable(name = name,
|
2015-09-24 21:04:27 +05:30
|
|
|
outname = os.path.splitext(name)[-2]+'.geom' if name else name,
|
2015-08-13 00:26:40 +05:30
|
|
|
buffered = False)
|
|
|
|
except: continue
|
2015-09-24 21:04:27 +05:30
|
|
|
damask.util.report(scriptName,name)
|
2015-08-08 00:33:26 +05:30
|
|
|
|
|
|
|
# ------------------------------------------ read head ---------------------------------------
|
|
|
|
|
2015-06-21 17:26:05 +05:30
|
|
|
table.head_read() # read ASCII header info
|
|
|
|
|
2015-08-08 00:33:26 +05:30
|
|
|
# ------------------------------------------ sanity checks ---------------------------------------
|
|
|
|
|
2016-04-27 02:19:58 +05:30
|
|
|
coordDim = table.label_dimension(options.pos)
|
2015-08-21 01:12:05 +05:30
|
|
|
|
2015-06-21 17:26:05 +05:30
|
|
|
errors = []
|
2015-08-21 01:12:05 +05:30
|
|
|
if not 3 >= coordDim >= 2:
|
2016-04-27 02:19:58 +05:30
|
|
|
errors.append('coordinates "{}" need to have two or three dimensions.'.format(options.pos))
|
2015-06-21 17:26:05 +05:30
|
|
|
if not np.all(table.label_dimension(label) == dim):
|
2015-11-20 21:57:57 +05:30
|
|
|
errors.append('input "{}" needs to have dimension {}.'.format(label,dim))
|
|
|
|
if options.phase and table.label_dimension(options.phase) != 1:
|
|
|
|
errors.append('phase column "{}" is not scalar.'.format(options.phase))
|
2015-06-21 17:26:05 +05:30
|
|
|
|
2015-08-21 01:12:05 +05:30
|
|
|
if errors != []:
|
2015-09-24 21:04:27 +05:30
|
|
|
damask.util.croak(errors)
|
2015-08-21 01:12:05 +05:30
|
|
|
table.close(dismiss = True)
|
|
|
|
continue
|
|
|
|
|
2016-04-27 02:19:58 +05:30
|
|
|
table.data_readArray([options.pos] \
|
2018-07-20 04:09:50 +05:30
|
|
|
+ (label if isinstance(label, list) else [label]) \
|
2015-11-20 21:57:57 +05:30
|
|
|
+ ([options.phase] if options.phase else []))
|
2015-06-21 17:26:05 +05:30
|
|
|
|
2015-08-21 01:12:05 +05:30
|
|
|
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
|
2015-11-30 21:52:59 +05:30
|
|
|
if options.verbose: damask.util.croak('extending to 3D...')
|
2016-03-02 17:13:09 +05:30
|
|
|
if options.phase is None:
|
2015-08-21 01:12:05 +05:30
|
|
|
table.data = np.column_stack((table.data,np.ones(len(table.data)))) # add single phase if no phase column given
|
2015-11-30 21:52:59 +05:30
|
|
|
if options.verbose: damask.util.croak('adding dummy phase info...')
|
2015-08-21 01:12:05 +05:30
|
|
|
|
|
|
|
# --------------- figure out size and grid ---------------------------------------------------------
|
|
|
|
|
2016-10-25 00:46:29 +05:30
|
|
|
coords = [np.unique(table.data[:,i]) for i in range(3)]
|
2018-07-20 04:09:50 +05:30
|
|
|
mincorner = np.array(list(map(min,coords)))
|
|
|
|
maxcorner = np.array(list(map(max,coords)))
|
|
|
|
grid = np.array(list(map(len,coords)),'i')
|
2015-08-21 01:12:05 +05:30
|
|
|
size = grid/np.maximum(np.ones(3,'d'), grid-1.0) * (maxcorner-mincorner) # size from edge to edge = dim * n/(n-1)
|
2016-03-02 17:13:09 +05:30
|
|
|
size = np.where(grid > 1, size, min(size[grid > 1]/grid[grid > 1])) # spacing for grid==1 set to smallest among other spacings
|
2015-08-21 01:12:05 +05:30
|
|
|
delta = size/np.maximum(np.ones(3,'d'), grid)
|
|
|
|
origin = mincorner - 0.5*delta # shift from cell center to corner
|
|
|
|
|
|
|
|
N = grid.prod()
|
|
|
|
|
|
|
|
if N != len(table.data):
|
|
|
|
errors.append('data count {} does not match grid {}.'.format(len(table.data),' x '.join(map(repr,grid))))
|
|
|
|
if np.any(np.abs(np.log10((coords[0][1:]-coords[0][:-1])/delta[0])) > 0.01) \
|
|
|
|
or np.any(np.abs(np.log10((coords[1][1:]-coords[1][:-1])/delta[1])) > 0.01) \
|
|
|
|
or np.any(np.abs(np.log10((coords[2][1:]-coords[2][:-1])/delta[2])) > 0.01):
|
|
|
|
errors.append('regular grid spacing {} violated.'.format(' x '.join(map(repr,delta))))
|
|
|
|
|
|
|
|
if errors != []:
|
2015-09-24 21:04:27 +05:30
|
|
|
damask.util.croak(errors)
|
2015-06-21 17:26:05 +05:30
|
|
|
table.close(dismiss = True)
|
|
|
|
continue
|
|
|
|
|
|
|
|
# ------------------------------------------ process data ------------------------------------------
|
2015-08-21 01:12:05 +05:30
|
|
|
|
2016-03-02 17:13:09 +05:30
|
|
|
colOri = table.label_index(label)+(3-coordDim) # column(s) of orientation data followed by 3 coordinates
|
2015-08-21 01:12:05 +05:30
|
|
|
|
|
|
|
if inputtype == 'microstructure':
|
2015-11-20 21:57:57 +05:30
|
|
|
|
2015-12-09 19:43:19 +05:30
|
|
|
grain = table.data[:,colOri]
|
|
|
|
nGrains = len(np.unique(grain))
|
2015-11-20 21:57:57 +05:30
|
|
|
|
2015-12-09 19:43:19 +05:30
|
|
|
else:
|
|
|
|
|
|
|
|
if options.verbose: bg = damask.util.backgroundMessage(); bg.start() # start background messaging
|
2015-11-20 21:57:57 +05:30
|
|
|
|
|
|
|
colPhase = -1 # column of phase data comes last
|
2015-11-30 21:52:59 +05:30
|
|
|
if options.verbose: bg.set_message('sorting positions...')
|
2015-11-20 21:57:57 +05:30
|
|
|
index = np.lexsort((table.data[:,0],table.data[:,1],table.data[:,2])) # index of position when sorting x fast, z slow
|
2015-11-30 21:52:59 +05:30
|
|
|
if options.verbose: bg.set_message('building KD tree...')
|
2015-11-20 21:57:57 +05:30
|
|
|
KDTree = scipy.spatial.KDTree((table.data[index,:3]-mincorner) / delta) # build KDTree with dX = dY = dZ = 1 and origin 0,0,0
|
2015-06-21 17:26:05 +05:30
|
|
|
|
2015-11-20 21:57:57 +05:30
|
|
|
statistics = {'global': 0, 'local': 0}
|
|
|
|
grain = -np.ones(N,dtype = 'int32') # initialize empty microstructure
|
2016-03-02 17:13:09 +05:30
|
|
|
orientations = [] # orientations
|
|
|
|
multiplicity = [] # orientation multiplicity (number of group members)
|
|
|
|
phases = [] # phase info
|
2015-11-20 21:57:57 +05:30
|
|
|
nGrains = 0 # counter for detected grains
|
|
|
|
existingGrains = np.arange(nGrains)
|
|
|
|
myPos = 0 # position (in list) of current grid point
|
|
|
|
|
|
|
|
tick = time.clock()
|
2015-11-30 21:52:59 +05:30
|
|
|
if options.verbose: bg.set_message('assigning grain IDs...')
|
2015-11-20 21:57:57 +05:30
|
|
|
|
2016-10-25 00:46:29 +05:30
|
|
|
for z in range(grid[2]):
|
|
|
|
for y in range(grid[1]):
|
|
|
|
for x in range(grid[0]):
|
2015-11-20 21:57:57 +05:30
|
|
|
if (myPos+1)%(N/500.) < 1:
|
|
|
|
time_delta = (time.clock()-tick) * (N - myPos) / myPos
|
2015-11-30 21:52:59 +05:30
|
|
|
if options.verbose: bg.set_message('(%02i:%02i:%02i) processing point %i of %i (grain count %i)...'
|
|
|
|
%(time_delta//3600,time_delta%3600//60,time_delta%60,myPos,N,nGrains))
|
2015-11-20 21:57:57 +05:30
|
|
|
|
|
|
|
myData = table.data[index[myPos]] # read data for current grid point
|
|
|
|
myPhase = int(myData[colPhase])
|
2016-03-02 17:13:09 +05:30
|
|
|
mySym = options.symmetry[min(myPhase,len(options.symmetry))-1] # take last specified option for all with higher index
|
2015-11-20 21:57:57 +05:30
|
|
|
|
2015-08-21 01:12:05 +05:30
|
|
|
if inputtype == 'eulers':
|
|
|
|
o = damask.Orientation(Eulers = myData[colOri:colOri+3]*toRadians,
|
2015-11-20 21:57:57 +05:30
|
|
|
symmetry = mySym)
|
2015-08-21 01:12:05 +05:30
|
|
|
elif inputtype == 'matrix':
|
|
|
|
o = damask.Orientation(matrix = myData[colOri:colOri+9].reshape(3,3).transpose(),
|
2015-11-20 21:57:57 +05:30
|
|
|
symmetry = mySym)
|
2015-08-21 01:12:05 +05:30
|
|
|
elif inputtype == 'frame':
|
|
|
|
o = damask.Orientation(matrix = np.hstack((myData[colOri[0]:colOri[0]+3],
|
|
|
|
myData[colOri[1]:colOri[1]+3],
|
|
|
|
myData[colOri[2]:colOri[2]+3],
|
|
|
|
)).reshape(3,3),
|
2015-11-20 21:57:57 +05:30
|
|
|
symmetry = mySym)
|
2015-08-21 01:12:05 +05:30
|
|
|
elif inputtype == 'quaternion':
|
|
|
|
o = damask.Orientation(quaternion = myData[colOri:colOri+4],
|
2015-11-20 21:57:57 +05:30
|
|
|
symmetry = mySym)
|
2015-09-11 21:08:03 +05:30
|
|
|
|
2015-11-20 21:57:57 +05:30
|
|
|
cos_disorientations = -np.ones(1,dtype='f') # largest possible disorientation
|
|
|
|
closest_grain = -1 # invalid neighbor
|
|
|
|
|
2015-12-09 19:43:19 +05:30
|
|
|
if options.tolerance > 0.0: # only try to compress orientations if asked to
|
|
|
|
neighbors = np.array(KDTree.query_ball_point([x,y,z], 3)) # point indices within radius
|
2016-03-02 17:13:09 +05:30
|
|
|
# filter neighbors: skip myself, anyone further ahead (cannot yet have a grain ID), and other phases
|
2015-12-09 19:43:19 +05:30
|
|
|
neighbors = neighbors[(neighbors < myPos) & \
|
2016-03-02 17:13:09 +05:30
|
|
|
(table.data[index[neighbors],colPhase] == myPhase)]
|
2015-12-09 19:43:19 +05:30
|
|
|
grains = np.unique(grain[neighbors]) # unique grain IDs among valid neighbors
|
2015-11-20 21:57:57 +05:30
|
|
|
|
2015-12-09 19:43:19 +05:30
|
|
|
if len(grains) > 0: # check immediate neighborhood first
|
2015-11-20 21:57:57 +05:30
|
|
|
cos_disorientations = np.array([o.disorientation(orientations[grainID],
|
|
|
|
SST = False)[0].quaternion.w \
|
|
|
|
for grainID in grains]) # store disorientation per grainID
|
2016-03-02 17:13:09 +05:30
|
|
|
closest_grain = np.argmax(cos_disorientations) # grain among grains with closest orientation to myself
|
2015-12-09 19:43:19 +05:30
|
|
|
match = 'local'
|
|
|
|
|
|
|
|
if cos_disorientations[closest_grain] < threshold: # orientation not close enough?
|
2016-03-02 17:13:09 +05:30
|
|
|
grains = existingGrains[np.atleast_1d( (np.array(phases) == myPhase ) & \
|
|
|
|
(np.in1d(existingGrains,grains,invert=True)))] # other already identified grains (of my phase)
|
2015-12-09 19:43:19 +05:30
|
|
|
|
|
|
|
if len(grains) > 0:
|
|
|
|
cos_disorientations = np.array([o.disorientation(orientations[grainID],
|
|
|
|
SST = False)[0].quaternion.w \
|
|
|
|
for grainID in grains]) # store disorientation per grainID
|
2016-03-02 17:13:09 +05:30
|
|
|
closest_grain = np.argmax(cos_disorientations) # grain among grains with closest orientation to myself
|
2015-12-09 19:43:19 +05:30
|
|
|
match = 'global'
|
2015-11-20 21:57:57 +05:30
|
|
|
|
|
|
|
if cos_disorientations[closest_grain] >= threshold: # orientation now close enough?
|
|
|
|
grainID = grains[closest_grain]
|
|
|
|
grain[myPos] = grainID # assign myself to that grain ...
|
|
|
|
orientations[grainID] = damask.Orientation.average([orientations[grainID],o],
|
|
|
|
[multiplicity[grainID],1]) # update average orientation of best matching grain
|
|
|
|
multiplicity[grainID] += 1
|
|
|
|
statistics[match] += 1
|
|
|
|
else:
|
2015-12-09 19:43:19 +05:30
|
|
|
grain[myPos] = nGrains # assign new grain to me ...
|
|
|
|
nGrains += 1 # ... and update counter
|
2015-11-20 21:57:57 +05:30
|
|
|
orientations.append(o) # store new orientation for future comparison
|
|
|
|
multiplicity.append(1) # having single occurrence so far
|
|
|
|
phases.append(myPhase) # store phase info for future reporting
|
2015-12-09 19:43:19 +05:30
|
|
|
existingGrains = np.arange(nGrains) # update list of existing grains
|
2015-11-20 21:57:57 +05:30
|
|
|
|
|
|
|
myPos += 1
|
|
|
|
|
2015-11-30 21:52:59 +05:30
|
|
|
if options.verbose:
|
|
|
|
bg.stop()
|
|
|
|
bg.join()
|
2015-12-03 04:43:10 +05:30
|
|
|
damask.util.croak("{} seconds total.\n{} local and {} global matches.".\
|
|
|
|
format(time.clock()-tick,statistics['local'],statistics['global']))
|
2015-11-20 21:57:57 +05:30
|
|
|
|
2015-12-09 19:43:19 +05:30
|
|
|
grain += 1 # offset from starting index 0 to 1
|
|
|
|
|
2015-08-08 00:33:26 +05:30
|
|
|
# --- generate header ----------------------------------------------------------------------------
|
2015-06-21 17:26:05 +05:30
|
|
|
|
|
|
|
info = {
|
2015-08-21 01:12:05 +05:30
|
|
|
'grid': grid,
|
|
|
|
'size': size,
|
|
|
|
'origin': origin,
|
2015-06-21 17:26:05 +05:30
|
|
|
'microstructures': nGrains,
|
|
|
|
'homogenization': options.homogenization,
|
|
|
|
}
|
2015-08-08 00:33:26 +05:30
|
|
|
|
2015-11-20 21:57:57 +05:30
|
|
|
damask.util.croak(['grid a b c: {}'.format(' x '.join(map(str,info['grid']))),
|
|
|
|
'size x y z: {}'.format(' x '.join(map(str,info['size']))),
|
|
|
|
'origin x y z: {}'.format(' : '.join(map(str,info['origin']))),
|
|
|
|
'homogenization: {}'.format(info['homogenization']),
|
|
|
|
'microstructures: {}'.format(info['microstructures']),
|
|
|
|
])
|
2015-08-08 00:33:26 +05:30
|
|
|
|
|
|
|
# --- write header ---------------------------------------------------------------------------------
|
2015-06-21 17:26:05 +05:30
|
|
|
|
|
|
|
formatwidth = 1+int(math.log10(info['microstructures']))
|
|
|
|
|
2015-08-21 01:12:05 +05:30
|
|
|
if inputtype == 'microstructure':
|
|
|
|
config_header = []
|
|
|
|
else:
|
|
|
|
config_header = ['<microstructure>']
|
|
|
|
for i,phase in enumerate(phases):
|
|
|
|
config_header += ['[Grain%s]'%(str(i+1).zfill(formatwidth)),
|
|
|
|
'crystallite %i'%options.crystallite,
|
|
|
|
'(constituent)\tphase %i\ttexture %s\tfraction 1.0'%(phase,str(i+1).rjust(formatwidth)),
|
|
|
|
]
|
2015-06-21 17:26:05 +05:30
|
|
|
|
2015-08-21 01:12:05 +05:30
|
|
|
config_header += ['<texture>']
|
2015-11-20 21:57:57 +05:30
|
|
|
for i,orientation in enumerate(orientations):
|
2015-08-21 01:12:05 +05:30
|
|
|
config_header += ['[Grain%s]'%(str(i+1).zfill(formatwidth)),
|
2016-03-02 17:13:09 +05:30
|
|
|
'axes\t%s %s %s'%tuple(options.axes) if options.axes is not None else '',
|
2015-11-20 21:57:57 +05:30
|
|
|
'(gauss)\tphi1 %g\tPhi %g\tphi2 %g\tscatter 0.0\tfraction 1.0'%tuple(orientation.asEulers(degrees = True)),
|
2015-08-21 01:12:05 +05:30
|
|
|
]
|
2015-06-21 17:26:05 +05:30
|
|
|
|
|
|
|
table.labels_clear()
|
|
|
|
table.info_clear()
|
2015-11-20 21:57:57 +05:30
|
|
|
table.info_append([scriptID + ' ' + ' '.join(sys.argv[1:])])
|
|
|
|
table.head_putGeom(info)
|
|
|
|
table.info_append(config_header)
|
2015-06-21 17:26:05 +05:30
|
|
|
table.head_write()
|
|
|
|
|
|
|
|
# --- write microstructure information ------------------------------------------------------------
|
|
|
|
|
2015-12-09 19:43:19 +05:30
|
|
|
table.data = grain.reshape(info['grid'][1]*info['grid'][2],info['grid'][0])
|
2015-06-21 17:26:05 +05:30
|
|
|
table.data_writeArray('%%%ii'%(formatwidth),delimiter=' ')
|
|
|
|
|
|
|
|
#--- output finalization --------------------------------------------------------------------------
|
|
|
|
|
|
|
|
table.close()
|