2018-11-17 13:16:58 +05:30
|
|
|
#!/usr/bin/env python3
|
2014-01-24 02:13:42 +05:30
|
|
|
|
2019-12-08 13:48:15 +05:30
|
|
|
import os
|
|
|
|
import sys
|
|
|
|
from io import StringIO
|
2014-10-10 17:41:10 +05:30
|
|
|
from optparse import OptionParser
|
2019-12-08 13:48:15 +05:30
|
|
|
|
|
|
|
import numpy as np
|
|
|
|
|
2014-10-10 17:41:10 +05:30
|
|
|
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')
|
|
|
|
|
|
|
|
parser.set_defaults(whitelist = [],
|
|
|
|
blacklist = [],
|
|
|
|
)
|
2014-01-24 02:13:42 +05:30
|
|
|
|
|
|
|
(options,filenames) = parser.parse_args()
|
2015-08-13 00:23:39 +05:30
|
|
|
if filenames == []: filenames = [None]
|
2015-08-08 00:33:26 +05:30
|
|
|
|
2019-12-08 13:48:15 +05:30
|
|
|
options.whitelist = [int(i) for i in options.whitelist]
|
|
|
|
options.blacklist = [int(i) for i in options.blacklist]
|
2015-08-08 00:33:26 +05:30
|
|
|
|
2019-12-08 13:48:15 +05:30
|
|
|
for name in filenames:
|
|
|
|
damask.util.report(scriptName,name)
|
2020-04-20 22:43:45 +05:30
|
|
|
|
2019-12-08 13:48:15 +05:30
|
|
|
geom = damask.Geom.from_file(StringIO(''.join(sys.stdin.read())) if name is None else name)
|
|
|
|
microstructure = geom.get_microstructure().reshape((-1,1),order='F')
|
|
|
|
|
|
|
|
mask = np.logical_and(np.in1d(microstructure,options.whitelist,invert=False) if options.whitelist else \
|
|
|
|
np.full(geom.grid.prod(),True,dtype=bool),
|
|
|
|
np.in1d(microstructure,options.blacklist,invert=True) if options.blacklist else \
|
|
|
|
np.full(geom.grid.prod(),True,dtype=bool))
|
2020-04-20 22:43:45 +05:30
|
|
|
|
|
|
|
seeds = damask.grid_filters.cell_coord0(geom.grid,geom.size).reshape(-1,3,order='F')
|
|
|
|
|
2019-12-08 15:55:33 +05:30
|
|
|
comments = geom.comments \
|
|
|
|
+ [scriptID + ' ' + ' '.join(sys.argv[1:]),
|
2020-03-20 10:30:42 +05:30
|
|
|
'grid\ta {}\tb {}\tc {}'.format(*geom.grid),
|
|
|
|
'size\tx {}\ty {}\tz {}'.format(*geom.size),
|
|
|
|
'origin\tx {}\ty {}\tz {}'.format(*geom.origin),
|
|
|
|
'homogenization\t{}'.format(geom.homogenization)]
|
2019-12-08 13:48:15 +05:30
|
|
|
|
2020-03-20 10:30:42 +05:30
|
|
|
table = damask.Table(seeds[mask],{'pos':(3,)},comments)
|
2020-09-14 10:34:01 +05:30
|
|
|
table = table.add('microstructure',microstructure[mask])
|
|
|
|
table.to_file(sys.stdout if name is None else os.path.splitext(name)[0]+'.seeds')
|