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 = """
|
2020-09-23 00:52:58 +05:30
|
|
|
Create seed file taking material indices from given geom file.
|
2016-04-25 00:42:10 +05:30
|
|
|
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
|
|
|
|
2020-09-15 10:28:06 +05:30
|
|
|
geom = damask.Geom.load_ASCII(StringIO(''.join(sys.stdin.read())) if name is None else name)
|
2020-09-24 02:57:15 +05:30
|
|
|
material = geom.material.reshape((-1,1),order='F')
|
2019-12-08 13:48:15 +05:30
|
|
|
|
2020-09-24 02:57:15 +05:30
|
|
|
mask = np.logical_and(np.in1d(material,options.whitelist,invert=False) if options.whitelist else \
|
2019-12-08 13:48:15 +05:30
|
|
|
np.full(geom.grid.prod(),True,dtype=bool),
|
2020-09-24 02:57:15 +05:30
|
|
|
np.in1d(material,options.blacklist,invert=True) if options.blacklist else \
|
2019-12-08 13:48:15 +05:30
|
|
|
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),
|
2020-09-23 05:33:41 +05:30
|
|
|
]
|
2019-12-08 13:48:15 +05:30
|
|
|
|
2020-09-15 10:28:06 +05:30
|
|
|
damask.Table(seeds[mask],{'pos':(3,)},comments)\
|
2020-09-24 02:57:15 +05:30
|
|
|
.add('material',material[mask].astype(int))\
|
2020-09-21 00:15:06 +05:30
|
|
|
.save(sys.stdout if name is None else os.path.splitext(name)[0]+'.seeds',legacy=True)
|