2018-11-17 12:42:12 +05:30
|
|
|
#!/usr/bin/env python3
|
2011-10-11 23:05:53 +05:30
|
|
|
|
2019-05-25 11:48:48 +05:30
|
|
|
import os
|
|
|
|
import sys
|
|
|
|
from io import StringIO
|
2019-05-27 00:06:41 +05:30
|
|
|
from optparse import OptionParser
|
|
|
|
|
|
|
|
import numpy as np
|
|
|
|
|
2014-11-18 13:30:45 +05:30
|
|
|
import damask
|
2011-10-11 23:05:53 +05:30
|
|
|
|
2019-05-27 00:06:41 +05:30
|
|
|
|
2016-01-27 22:36:00 +05:30
|
|
|
scriptName = os.path.splitext(os.path.basename(__file__))[0]
|
|
|
|
scriptID = ' '.join([scriptName,damask.version])
|
2013-07-18 18:58:54 +05:30
|
|
|
|
2019-05-27 00:06:41 +05:30
|
|
|
|
2013-05-14 23:21:53 +05:30
|
|
|
#--------------------------------------------------------------------------------------------------
|
|
|
|
# MAIN
|
|
|
|
#--------------------------------------------------------------------------------------------------
|
2011-10-11 23:05:53 +05:30
|
|
|
|
2019-05-27 00:06:41 +05:30
|
|
|
parser = OptionParser(option_class=damask.extendableOption, usage='%prog options [geomfile(s)]', description = """
|
2018-03-30 21:18:02 +05:30
|
|
|
Offset microstructure index for points which see a microstructure different from themselves
|
|
|
|
(or listed as triggers) within a given (cubic) vicinity, i.e. within the region close to a grain/phase boundary.
|
2014-11-18 13:30:45 +05:30
|
|
|
|
|
|
|
""", version = scriptID)
|
2011-10-11 23:05:53 +05:30
|
|
|
|
2015-08-08 00:33:26 +05:30
|
|
|
parser.add_option('-v', '--vicinity',
|
|
|
|
dest = 'vicinity',
|
|
|
|
type = 'int', metavar = 'int',
|
|
|
|
help = 'voxel distance checked for presence of other microstructure [%default]')
|
2019-05-28 06:44:09 +05:30
|
|
|
parser.add_option('-o', '--offset',
|
2015-08-08 00:33:26 +05:30
|
|
|
dest='offset',
|
|
|
|
type = 'int', metavar = 'int',
|
2019-05-28 06:44:09 +05:30
|
|
|
help='offset (positive or negative) to tag microstructure indices, defaults to max microstructure index')
|
2018-03-30 21:18:02 +05:30
|
|
|
parser.add_option('-t', '--trigger',
|
2019-05-27 00:06:41 +05:30
|
|
|
dest = 'trigger',
|
|
|
|
action = 'extend', metavar = '<int LIST>',
|
2018-03-30 21:18:02 +05:30
|
|
|
help = 'list of microstructure indices triggering a change')
|
2018-02-20 20:50:35 +05:30
|
|
|
parser.add_option('-n', '--nonperiodic',
|
|
|
|
dest = 'mode',
|
|
|
|
action = 'store_const', const = 'nearest',
|
|
|
|
help = 'assume geometry to be non-periodic')
|
2011-10-11 23:05:53 +05:30
|
|
|
|
2015-08-08 00:33:26 +05:30
|
|
|
parser.set_defaults(vicinity = 1,
|
2018-03-30 21:18:02 +05:30
|
|
|
trigger = [],
|
2018-02-20 20:50:35 +05:30
|
|
|
mode = 'wrap',
|
2015-08-08 00:33:26 +05:30
|
|
|
)
|
2011-10-11 23:05:53 +05:30
|
|
|
|
|
|
|
(options, filenames) = parser.parse_args()
|
2018-03-30 21:18:02 +05:30
|
|
|
|
2019-05-27 00:06:41 +05:30
|
|
|
options.trigger = np.array(options.trigger, dtype=int)
|
2011-10-11 23:05:53 +05:30
|
|
|
|
2015-08-08 00:33:26 +05:30
|
|
|
|
2015-08-21 01:12:05 +05:30
|
|
|
if filenames == []: filenames = [None]
|
2015-08-08 00:33:26 +05:30
|
|
|
|
|
|
|
for name in filenames:
|
2020-08-08 23:12:34 +05:30
|
|
|
damask.util.report(scriptName,name)
|
2013-05-15 02:39:37 +05:30
|
|
|
|
2020-08-08 23:12:34 +05:30
|
|
|
geom = damask.Geom.from_file(StringIO(''.join(sys.stdin.read())) if name is None else name)
|
2011-10-11 23:05:53 +05:30
|
|
|
|
2020-08-08 23:12:34 +05:30
|
|
|
damask.util.croak(geom.vicinity_offset(options.vicinity,options.offset,options.trigger,
|
|
|
|
True if options.mode is 'wrap' else False))
|
|
|
|
geom.add_comments(scriptID + ' ' + ' '.join(sys.argv[1:]))
|
2019-05-30 17:37:49 +05:30
|
|
|
|
2020-08-08 23:12:34 +05:30
|
|
|
geom.to_file(sys.stdout if name is None else name,pack=False)
|