DAMASK_EICMD/processing/pre/geom_mirror.py

48 lines
1.5 KiB
Python
Raw Normal View History

#!/usr/bin/env python3
2019-05-25 12:18:44 +05:30
import os
import sys
2019-05-25 13:44:53 +05:30
from io import StringIO
2019-05-26 21:39:34 +05:30
from optparse import OptionParser
2019-05-25 13:44:53 +05:30
import damask
2019-05-26 21:39:34 +05:30
scriptName = os.path.splitext(os.path.basename(__file__))[0]
scriptID = ' '.join([scriptName,damask.version])
2019-05-26 21:39:34 +05:30
#--------------------------------------------------------------------------------------------------
# MAIN
#--------------------------------------------------------------------------------------------------
parser = OptionParser(option_class=damask.extendableOption, usage='%prog options [geomfile(s)]', description = """
2019-05-26 21:39:34 +05:30
Mirror along given directions.
""", version=scriptID)
validDirections = ['x','y','z']
2016-09-21 21:13:07 +05:30
parser.add_option('-d','--direction',
dest = 'directions',
action = 'extend', metavar = '<string LIST>',
help = "directions in which to mirror {{{}}}".format(','.join(validDirections)))
parser.add_option( '--reflect',
dest = 'reflect',
2019-05-26 21:39:34 +05:30
action = 'store_true',
help = 'reflect (include) outermost layers')
parser.set_defaults(reflect = False)
(options, filenames) = parser.parse_args()
if filenames == []: filenames = [None]
for name in filenames:
2019-05-25 15:26:06 +05:30
damask.util.report(scriptName,name)
2019-05-30 17:37:49 +05:30
geom = damask.Geom.from_file(StringIO(''.join(sys.stdin.read())) if name is None else name)
damask.util.croak(geom.mirror(options.directions,options.reflect))
geom.add_comments(scriptID + ' ' + ' '.join(sys.argv[1:]))
2019-11-24 23:32:19 +05:30
geom.to_file(sys.stdout if name is None else name,pack=False)