2014-01-24 02:13:42 +05:30
|
|
|
#!/usr/bin/env python
|
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 = """
|
2014-01-24 02:13:42 +05:30
|
|
|
Create seed file taking microstructure indices from given geom file but excluding black-listed grains.
|
|
|
|
|
2014-10-10 17:41:10 +05:30
|
|
|
""", version = scriptID)
|
2014-01-24 02:13:42 +05:30
|
|
|
|
2015-08-08 00:33:26 +05:30
|
|
|
parser.add_option('-w','--white',
|
|
|
|
action = 'extend', metavar='<int LIST>',
|
|
|
|
dest = 'whitelist',
|
|
|
|
help = 'whitelist of grain IDs')
|
|
|
|
parser.add_option('-b','--black',
|
|
|
|
action = 'extend', metavar='<int LIST>',
|
|
|
|
dest = 'blacklist',
|
|
|
|
help = 'blacklist of grain IDs')
|
|
|
|
parser.add_option('-p','--position',
|
|
|
|
dest = 'position',
|
|
|
|
type = 'string', metavar = 'string',
|
|
|
|
help = 'column label for coordinates [%default]')
|
|
|
|
|
|
|
|
parser.set_defaults(whitelist = [],
|
|
|
|
blacklist = [],
|
|
|
|
position = 'pos',
|
|
|
|
)
|
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:
|
2015-08-13 00:23:39 +05:30
|
|
|
try:
|
2015-08-13 02:58:07 +05:30
|
|
|
table = damask.ASCIItable(name = name,
|
|
|
|
outname = os.path.splitext(name)[0]+'.seeds' if name else name,
|
2015-08-13 00:23:39 +05:30
|
|
|
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()
|
|
|
|
|
2015-09-24 18:51:44 +05:30
|
|
|
damask.util.croak(['grid a b c: %s'%(' x '.join(map(str,info['grid']))),
|
2015-08-08 00:33:26 +05:30
|
|
|
'size x y z: %s'%(' x '.join(map(str,info['size']))),
|
|
|
|
'origin x y z: %s'%(' : '.join(map(str,info['origin']))),
|
|
|
|
'homogenization: %i'%info['homogenization'],
|
|
|
|
'microstructures: %i'%info['microstructures'],
|
|
|
|
])
|
|
|
|
|
|
|
|
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:]),
|
2015-08-13 00:23:39 +05:30
|
|
|
"grid\ta {grid[0]}\tb {grid[1]}\tc {grid[2]}".format(grid=info['grid']),
|
|
|
|
"size\tx {size[0]}\ty {size[1]}\tz {size[2]}".format(size=info['size']),
|
2015-08-08 00:33:26 +05:30
|
|
|
"origin\tx {origin[0]}\ty {origin[1]}\tz {origin[2]}".format(origin=info['origin']),
|
|
|
|
"homogenization\t{homog}".format(homog=info['homogenization']),
|
2015-08-13 00:23:39 +05:30
|
|
|
"microstructures\t{microstructures}".format(microstructures=info['microstructures']),
|
2015-08-08 00:33:26 +05:30
|
|
|
])
|
2014-09-19 20:54:59 +05:30
|
|
|
table.labels_clear()
|
2015-08-08 00:33:26 +05:30
|
|
|
table.labels_append(['{dim}_{label}'.format(dim = 1+i,label = options.position) 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()
|