2016-07-18 23:05:35 +05:30
|
|
|
#!/usr/bin/env python2.7
|
2014-04-02 00:11:14 +05:30
|
|
|
# -*- coding: UTF-8 no BOM -*-
|
2014-01-24 02:13:42 +05:30
|
|
|
|
2016-03-02 02:53:30 +05:30
|
|
|
import os,sys
|
2014-10-10 17:41:10 +05:30
|
|
|
import numpy as np
|
|
|
|
from optparse import OptionParser
|
|
|
|
import damask
|
2014-01-24 02:13:42 +05:30
|
|
|
|
2016-01-27 22:36:00 +05:30
|
|
|
scriptName = os.path.splitext(os.path.basename(__file__))[0]
|
|
|
|
scriptID = ' '.join([scriptName,damask.version])
|
2014-01-24 02:13:42 +05:30
|
|
|
|
|
|
|
#--------------------------------------------------------------------------------------------------
|
|
|
|
# MAIN
|
|
|
|
#--------------------------------------------------------------------------------------------------
|
|
|
|
|
2014-10-10 17:41:10 +05:30
|
|
|
parser = OptionParser(option_class=damask.extendableOption, usage='%prog options [file[s]]', description = """
|
2016-04-25 00:42:10 +05:30
|
|
|
Create seed file taking microstructure indices from given geom file.
|
|
|
|
Indices can be black-listed or white-listed.
|
2014-01-24 02:13:42 +05:30
|
|
|
|
2014-10-10 17:41:10 +05:30
|
|
|
""", version = scriptID)
|
2014-01-24 02:13:42 +05:30
|
|
|
|
2016-04-25 00:42:10 +05:30
|
|
|
parser.add_option('-w',
|
|
|
|
'--white',
|
|
|
|
action = 'extend', metavar = '<int LIST>',
|
2015-08-08 00:33:26 +05:30
|
|
|
dest = 'whitelist',
|
|
|
|
help = 'whitelist of grain IDs')
|
2016-04-25 00:42:10 +05:30
|
|
|
parser.add_option('-b',
|
|
|
|
'--black',
|
|
|
|
action = 'extend', metavar = '<int LIST>',
|
2015-08-08 00:33:26 +05:30
|
|
|
dest = 'blacklist',
|
|
|
|
help = 'blacklist of grain IDs')
|
2016-04-25 00:42:10 +05:30
|
|
|
parser.add_option('-p',
|
|
|
|
'--pos', '--seedposition',
|
2017-08-16 01:41:21 +05:30
|
|
|
dest = 'pos',
|
2015-08-08 00:33:26 +05:30
|
|
|
type = 'string', metavar = 'string',
|
2016-04-25 00:42:10 +05:30
|
|
|
help = 'label of coordinates [%default]')
|
2015-08-08 00:33:26 +05:30
|
|
|
|
|
|
|
parser.set_defaults(whitelist = [],
|
|
|
|
blacklist = [],
|
2016-04-25 00:42:10 +05:30
|
|
|
pos = 'pos',
|
2015-08-08 00:33:26 +05:30
|
|
|
)
|
2014-01-24 02:13:42 +05:30
|
|
|
|
|
|
|
(options,filenames) = parser.parse_args()
|
|
|
|
|
|
|
|
options.whitelist = map(int,options.whitelist)
|
|
|
|
options.blacklist = map(int,options.blacklist)
|
|
|
|
|
2015-08-08 00:33:26 +05:30
|
|
|
# --- loop over output files -------------------------------------------------------------------------
|
2014-01-24 02:13:42 +05:30
|
|
|
|
2015-08-13 00:23:39 +05:30
|
|
|
if filenames == []: filenames = [None]
|
2015-08-08 00:33:26 +05:30
|
|
|
|
|
|
|
for name in filenames:
|
2016-04-25 00:42:10 +05:30
|
|
|
try: table = damask.ASCIItable(name = name,
|
|
|
|
outname = os.path.splitext(name)[0]+'.seeds' if name else name,
|
|
|
|
buffered = False,
|
|
|
|
labeled = False)
|
|
|
|
except: continue
|
2015-09-24 18:51:44 +05:30
|
|
|
damask.util.report(scriptName,name)
|
2015-08-08 00:33:26 +05:30
|
|
|
|
|
|
|
# --- interpret header ----------------------------------------------------------------------------
|
|
|
|
|
|
|
|
table.head_read()
|
|
|
|
info,extra_header = table.head_getGeom()
|
2016-04-25 00:42:10 +05:30
|
|
|
damask.util.report_geom(info)
|
2015-08-08 00:33:26 +05:30
|
|
|
|
|
|
|
errors = []
|
|
|
|
if np.any(info['grid'] < 1): errors.append('invalid grid a b c.')
|
|
|
|
if np.any(info['size'] <= 0.0): errors.append('invalid size x y z.')
|
|
|
|
if errors != []:
|
2015-09-24 18:51:44 +05:30
|
|
|
damask.util.croak(errors)
|
2015-08-08 00:33:26 +05:30
|
|
|
table.close(dismiss = True)
|
2014-01-24 02:13:42 +05:30
|
|
|
continue
|
2015-08-08 00:33:26 +05:30
|
|
|
|
|
|
|
# --- read data ------------------------------------------------------------------------------------
|
|
|
|
|
|
|
|
microstructure = table.microstructure_read(info['grid']) # read (linear) microstructure
|
|
|
|
|
|
|
|
# --- generate grid --------------------------------------------------------------------------------
|
|
|
|
|
|
|
|
x = (0.5 + np.arange(info['grid'][0],dtype=float))/info['grid'][0]*info['size'][0]+info['origin'][0]
|
|
|
|
y = (0.5 + np.arange(info['grid'][1],dtype=float))/info['grid'][1]*info['size'][1]+info['origin'][1]
|
|
|
|
z = (0.5 + np.arange(info['grid'][2],dtype=float))/info['grid'][2]*info['size'][2]+info['origin'][2]
|
|
|
|
|
|
|
|
xx = np.tile( x, info['grid'][1]* info['grid'][2])
|
|
|
|
yy = np.tile(np.repeat(y,info['grid'][0] ),info['grid'][2])
|
|
|
|
zz = np.repeat(z,info['grid'][0]*info['grid'][1])
|
|
|
|
|
2016-03-02 02:53:30 +05:30
|
|
|
mask = np.logical_and(np.in1d(microstructure,options.whitelist,invert=False) if options.whitelist != []
|
|
|
|
else np.full_like(microstructure,True,dtype=bool),
|
|
|
|
np.in1d(microstructure,options.blacklist,invert=True ) if options.blacklist != []
|
|
|
|
else np.full_like(microstructure,True,dtype=bool))
|
2015-08-08 00:33:26 +05:30
|
|
|
|
|
|
|
# ------------------------------------------ assemble header ---------------------------------------
|
|
|
|
|
|
|
|
table.info_clear()
|
|
|
|
table.info_append(extra_header+[
|
|
|
|
scriptID + ' ' + ' '.join(sys.argv[1:]),
|
2016-04-25 00:42:10 +05:30
|
|
|
"grid\ta {}\tb {}\tc {}".format(*info['grid']),
|
|
|
|
"size\tx {}\ty {}\tz {}".format(*info['size']),
|
|
|
|
"origin\tx {}\ty {}\tz {}".format(*info['origin']),
|
|
|
|
"homogenization\t{}".format(info['homogenization']),
|
|
|
|
"microstructures\t{}".format(info['microstructures']),
|
2015-08-08 00:33:26 +05:30
|
|
|
])
|
2014-09-19 20:54:59 +05:30
|
|
|
table.labels_clear()
|
2016-04-25 00:42:10 +05:30
|
|
|
table.labels_append(['{dim}_{label}'.format(dim = 1+i,label = options.pos) for i in range(3)]+['microstructure'])
|
2014-09-19 20:54:59 +05:30
|
|
|
table.head_write()
|
2015-08-08 00:33:26 +05:30
|
|
|
table.output_flush()
|
2014-01-24 02:13:42 +05:30
|
|
|
|
2015-08-08 00:33:26 +05:30
|
|
|
# --- write seeds information ------------------------------------------------------------
|
|
|
|
|
|
|
|
table.data = np.squeeze(np.dstack((xx,yy,zz,microstructure)))[mask]
|
|
|
|
table.data_writeArray()
|
|
|
|
|
|
|
|
# ------------------------------------------ finalize output ---------------------------------------
|
|
|
|
|
|
|
|
table.close()
|