added --compress option: for ang files filtered to have single orientation in grain (OIM filter), microstructure and texture in material.config are compressed
This commit is contained in:
parent
3c2af8e7a6
commit
7a9fa061de
|
@ -1,7 +1,7 @@
|
|||
#!/usr/bin/env python
|
||||
# -*- coding: UTF-8 no BOM -*-
|
||||
|
||||
import os,sys,math,string,numpy
|
||||
import os,sys,math,string,numpy as np
|
||||
from optparse import OptionParser, OptionGroup, Option, SUPPRESS_HELP
|
||||
|
||||
scriptID = '$Id$'
|
||||
|
@ -25,7 +25,6 @@ class extendableOption(Option):
|
|||
else:
|
||||
Option.take_action(self, action, dest, opt, value, values, parser)
|
||||
|
||||
|
||||
#--------------------------------------------------------------------------------------------------
|
||||
# MAIN
|
||||
#--------------------------------------------------------------------------------------------------
|
||||
|
@ -48,6 +47,8 @@ parser.add_option('--crystallite', dest='crystallite', type='int', metav
|
|||
help='crystallite index to be used [%default]')
|
||||
parser.add_option('-c', '--configuration', dest='config', action='store_true', \
|
||||
help='output material configuration [%default]')
|
||||
parser.add_option('--compress', dest='compress', action='store_true', \
|
||||
help='search for matching mircrostructure and texture and lump them [%default]')
|
||||
parser.add_option('-a', '--axes', dest='axes', type='string', nargs = 3, metavar = 'string string string', \
|
||||
help='axes assignement of eulerangles x,y,z = %default')
|
||||
|
||||
|
@ -58,6 +59,7 @@ parser.set_defaults(homogenization = 1)
|
|||
parser.set_defaults(phase = [1,2])
|
||||
parser.set_defaults(crystallite = 1)
|
||||
parser.set_defaults(config = False)
|
||||
parser.set_defaults(compress= False)
|
||||
parser.set_defaults(axes = ['y','x','-z'])
|
||||
(options,filenames) = parser.parse_args()
|
||||
|
||||
|
@ -90,17 +92,14 @@ for file in files:
|
|||
else: file['croak'].write('\033[1m'+scriptName+'\033[0m\n')
|
||||
|
||||
info = {
|
||||
'grid': numpy.ones (3,'i'),
|
||||
'size': numpy.zeros(3,'d'),
|
||||
'origin': numpy.zeros(3,'d'),
|
||||
'grid': np.ones (3,'i'),
|
||||
'size': np.zeros(3,'d'),
|
||||
'origin': np.zeros(3,'d'),
|
||||
'microstructures': 0,
|
||||
'homogenization': options.homogenization
|
||||
}
|
||||
|
||||
microstructure = ['<microstructure>']
|
||||
texture = ['<texture>']
|
||||
step = [0,0]
|
||||
|
||||
point = 0
|
||||
for line in file['input']:
|
||||
words = line.split()
|
||||
|
@ -112,22 +111,66 @@ for file in files:
|
|||
if words[1] == 'XSTEP:': step[0] = float(words[2])
|
||||
if words[1] == 'YSTEP:': step[1] = float(words[2])
|
||||
if words[1] == 'NCOLS_ODD:':
|
||||
info['grid'][0] = int(words[2]); formatwidth = 1+int(math.log10(info['grid'][0]*info['grid'][1]))
|
||||
info['grid'][0] = int(words[2])
|
||||
eulerangles = np.zeros((info['grid'][0]*info['grid'][1],3),dtype='f')
|
||||
phase = np.zeros(info['grid'][0]*info['grid'][1],dtype='i')
|
||||
if words[1] == 'NROWS:':
|
||||
info['grid'][1] = int(words[2]); formatwidth = 1+int(math.log10(info['grid'][0]*info['grid'][1]))
|
||||
info['grid'][1] = int(words[2])
|
||||
eulerangles = np.zeros((info['grid'][0]*info['grid'][1],3),dtype='f')
|
||||
phase = np.zeros(info['grid'][0]*info['grid'][1],dtype='i')
|
||||
else: # finished with comments block
|
||||
phase[point] = options.phase[{True:0,False:1}[float(words[options.column-1])<options.threshold]]
|
||||
eulerangles[point,...] = map(lambda x: float(x)*180.0/math.pi, words[:3])
|
||||
point += 1
|
||||
me = str(point).zfill(formatwidth)
|
||||
microstructure += ['[Grain%s]\n'%me + \
|
||||
'crystallite\t%i\n'%options.crystallite + \
|
||||
'(constituent)\tphase %i\ttexture %s\tfraction 1.0\n'%(options.phase[{True:0,False:1}[float(words[options.column-1])<options.threshold]],me)
|
||||
]
|
||||
texture += ['[Grain%s]\n'%me + \
|
||||
'axes %s %s %s\n'%(options.axes[0],options.axes[1],options.axes[2]) +\
|
||||
'(gauss)\tphi1 %4.2f\tPhi %4.2f\tphi2 %4.2f\tscatter 0.0\tfraction 1.0\n'%tuple(map(lambda x: float(x)*180.0/math.pi, words[:3]))
|
||||
]
|
||||
|
||||
if info['grid'].prod() != point:
|
||||
file['croak'].write('Error: found %s microstructures. Header info in ang file might be wrong.\n'%point)
|
||||
sys.exit()
|
||||
|
||||
info['microstructures'] = info['grid'][0]*info['grid'][1]
|
||||
if options.compress:
|
||||
texture = []
|
||||
microstructure = []
|
||||
otherPoint=-1 # ensure to create first microstructure
|
||||
matPoints = np.zeros(info['grid'][0]*info['grid'][1],dtype='i')
|
||||
for myPoint in xrange(info['grid'][0]*info['grid'][1]):
|
||||
myTexture=-1
|
||||
for otherPoint in xrange(len(microstructure)):
|
||||
otherEulers = eulerangles[texture[microstructure[otherPoint][0]]]
|
||||
otherPhase = phase[[microstructure[otherPoint][1]]]
|
||||
if all(eulerangles[myPoint]==otherEulers) and phase[myPoint] == otherPhase: # common microstructure
|
||||
matPoints[myPoint] = otherPoint+1 # use other points microstructure
|
||||
otherPoint =-4 # in no case, create new microstructure
|
||||
break
|
||||
elif all(eulerangles[myPoint]==otherEulers): # found common texture and store it
|
||||
myTexture = microstructure[otherPoint][0]
|
||||
if otherPoint == len(microstructure)-1 or otherPoint == -2: #
|
||||
if myTexture == -1:
|
||||
texture.append(myPoint)
|
||||
myTexture = len(texture)-1
|
||||
microstructure.append([myTexture,myPoint])
|
||||
matPoints[myPoint] = len(microstructure) # use the new microstructure
|
||||
|
||||
else:
|
||||
texture = [i for i in xrange(info['grid'][0]*info['grid'][1])]
|
||||
microstructure = [[i+1,phase[i]] for i in xrange(info['grid'][0]*info['grid'][1])]
|
||||
matPoints = np.arange(info['grid'][0]*info['grid'][1],dtype='i')
|
||||
|
||||
formatOut = 1+int(math.log10(len(texture)))
|
||||
textureOut =['\n\n<texture>']
|
||||
for i in xrange(len(texture)):
|
||||
textureOut += ['[Texture%s]\n'%str(i+1).zfill(formatOut) + \
|
||||
'axes %s %s %s\n'%(options.axes[0],options.axes[1],options.axes[2]) +\
|
||||
'(gauss)\tphi1 %4.2f\tPhi %4.2f\tphi2 %4.2f\tscatter 0.0\tfraction 1.0\n'%tuple(eulerangles[texture[i],...])
|
||||
]
|
||||
formatOut = 1+int(math.log10(len(microstructure)))
|
||||
microstructureOut =['<microstructure>']
|
||||
for i in xrange(len(microstructure)):
|
||||
microstructureOut += ['[Grain%s]\n'%str(i+1).zfill(formatOut) + \
|
||||
'crystallite\t%i\n'%options.crystallite + \
|
||||
'(constituent)\tphase %i\ttexture %s\tfraction 1.0\n'%(phase[microstructure[i][1]],microstructure[i][0]+1)
|
||||
]
|
||||
|
||||
info['microstructures'] = len(microstructure)
|
||||
info['size'] = step[0]*info['grid'][0],step[1]*info['grid'][1],min(step)
|
||||
|
||||
#--- report ---------------------------------------------------------------------------------------
|
||||
|
@ -137,20 +180,18 @@ for file in files:
|
|||
'homogenization: %i\n'%info['homogenization'] + \
|
||||
'microstructures: %i\n\n'%info['microstructures'])
|
||||
|
||||
if numpy.any(info['grid'] < 1):
|
||||
if np.any(info['grid'] < 1):
|
||||
file['croak'].write('invalid grid a b c.\n')
|
||||
sys.exit()
|
||||
if numpy.any(info['size'] <= 0.0):
|
||||
if np.any(info['size'] <= 0.0):
|
||||
file['croak'].write('invalid size x y z.\n')
|
||||
sys.exit()
|
||||
if info['grid'].prod() != len(microstructure) -1:
|
||||
file['croak'].write('found %s microstructures. Header info in ang file might be wrong.\n'%point)
|
||||
sys.exit()
|
||||
|
||||
|
||||
#--- write data -----------------------------------------------------------------------------------
|
||||
if options.config:
|
||||
file['output'].write('\n'.join(microstructure) + \
|
||||
'\n'.join(texture))
|
||||
file['output'].write('\n'.join(microstructureOut) + \
|
||||
'\n'.join(textureOut))
|
||||
else:
|
||||
header = [scriptID + ' ' + ' '.join(sys.argv[1:]) + '\n']
|
||||
header.append("grid\ta %i\tb %i\tc %i\n"%(info['grid'][0],info['grid'][1],info['grid'][2],))
|
||||
|
@ -159,7 +200,11 @@ for file in files:
|
|||
header.append("microstructures\t%i\n"%info['microstructures'])
|
||||
header.append("homogenization\t%i\n"%info['homogenization'])
|
||||
file['output'].write('%i\theader\n'%(len(header))+''.join(header))
|
||||
file['output'].write("1 to %i\n"%(info['microstructures']))
|
||||
if options.compress:
|
||||
matPoints = matPoints.reshape((info['grid'][1],info['grid'][0]))
|
||||
np.savetxt(file['output'],matPoints,fmt='%0'+str(1+int(math.log10(np.amax(matPoints))))+'d')
|
||||
else:
|
||||
file['output'].write("1 to %i\n"%(info['microstructures']))
|
||||
|
||||
#--- output finalization --------------------------------------------------------------------------
|
||||
if file['name'] != 'STDIN':
|
||||
|
|
Loading…
Reference in New Issue