2018-11-17 12:42:12 +05:30
|
|
|
#!/usr/bin/env python3
|
2016-08-19 22:23:48 +05:30
|
|
|
|
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
|
|
|
|
|
|
|
|
import numpy as np
|
|
|
|
|
2019-05-25 13:44:53 +05:30
|
|
|
import damask
|
2016-08-19 22:23:48 +05:30
|
|
|
|
2019-05-26 21:39:34 +05:30
|
|
|
|
2016-08-19 22:23:48 +05:30
|
|
|
scriptName = os.path.splitext(os.path.basename(__file__))[0]
|
|
|
|
scriptID = ' '.join([scriptName,damask.version])
|
|
|
|
|
2019-05-26 21:39:34 +05:30
|
|
|
|
2016-08-19 22:23:48 +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.
|
2016-08-19 22:23:48 +05:30
|
|
|
|
|
|
|
""", version=scriptID)
|
|
|
|
|
2019-05-30 13:01:14 +05:30
|
|
|
validDirections = ['x','y','z']
|
2019-05-30 07:52:29 +05:30
|
|
|
|
2016-09-21 21:13:07 +05:30
|
|
|
parser.add_option('-d','--direction',
|
|
|
|
dest = 'directions',
|
|
|
|
action = 'extend', metavar = '<string LIST>',
|
2019-05-30 07:52:29 +05:30
|
|
|
help = "directions in which to mirror {{{}}}".format(','.join(validDirections)))
|
2019-06-03 23:00:58 +05:30
|
|
|
parser.add_option( '--reflect',
|
|
|
|
dest = 'reflect',
|
2019-05-26 21:39:34 +05:30
|
|
|
action = 'store_true',
|
2019-06-03 23:00:58 +05:30
|
|
|
help = 'reflect (include) outermost layers')
|
2019-05-30 07:52:29 +05:30
|
|
|
|
2019-06-03 23:00:58 +05:30
|
|
|
parser.set_defaults(reflect = False)
|
2016-08-19 22:23:48 +05:30
|
|
|
|
|
|
|
(options, filenames) = parser.parse_args()
|
|
|
|
|
2016-09-21 21:13:07 +05:30
|
|
|
if options.directions is None:
|
|
|
|
parser.error('no direction given.')
|
2019-05-26 21:39:34 +05:30
|
|
|
|
2016-09-21 21:13:07 +05:30
|
|
|
if not set(options.directions).issubset(validDirections):
|
|
|
|
invalidDirections = [str(e) for e in set(options.directions).difference(validDirections)]
|
|
|
|
parser.error('invalid directions {}. '.format(*invalidDirections))
|
2019-05-23 22:33:24 +05:30
|
|
|
|
2019-06-03 23:00:58 +05:30
|
|
|
limits = [None,None] if options.reflect else [-2,0]
|
2016-08-19 22:23:48 +05:30
|
|
|
|
2019-05-30 14:56:47 +05:30
|
|
|
|
2016-08-19 22:23:48 +05:30
|
|
|
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
|
|
|
|
2019-05-28 06:44:09 +05:30
|
|
|
geom = damask.Geom.from_file(StringIO(''.join(sys.stdin.read())) if name is None else name)
|
2019-05-30 17:37:49 +05:30
|
|
|
|
2019-05-28 06:44:09 +05:30
|
|
|
microstructure = geom.get_microstructure()
|
2016-09-21 21:13:07 +05:30
|
|
|
if 'z' in options.directions:
|
2019-05-26 21:39:34 +05:30
|
|
|
microstructure = np.concatenate([microstructure,microstructure[:,:,limits[0]:limits[1]:-1]],2)
|
2016-09-21 21:13:07 +05:30
|
|
|
if 'y' in options.directions:
|
2019-05-26 21:39:34 +05:30
|
|
|
microstructure = np.concatenate([microstructure,microstructure[:,limits[0]:limits[1]:-1,:]],1)
|
2016-09-21 21:13:07 +05:30
|
|
|
if 'x' in options.directions:
|
2019-05-26 21:39:34 +05:30
|
|
|
microstructure = np.concatenate([microstructure,microstructure[limits[0]:limits[1]:-1,:,:]],0)
|
2019-05-30 17:37:49 +05:30
|
|
|
|
2019-05-26 21:39:34 +05:30
|
|
|
damask.util.croak(geom.update(microstructure,rescale=True))
|
2019-05-28 06:44:09 +05:30
|
|
|
geom.add_comments(scriptID + ' ' + ' '.join(sys.argv[1:]))
|
2019-05-30 17:37:49 +05:30
|
|
|
|
2019-05-25 12:18:44 +05:30
|
|
|
if name is None:
|
2019-05-25 15:26:06 +05:30
|
|
|
sys.stdout.write(str(geom.show()))
|
2019-05-25 12:18:44 +05:30
|
|
|
else:
|
|
|
|
geom.to_file(name)
|