2018-11-17 12:42:12 +05:30
|
|
|
#!/usr/bin/env python3
|
2016-08-19 22:23:48 +05:30
|
|
|
# -*- coding: UTF-8 no BOM -*-
|
|
|
|
|
2019-05-25 12:18:44 +05:30
|
|
|
import os
|
|
|
|
import sys
|
2016-08-19 22:23:48 +05:30
|
|
|
import numpy as np
|
|
|
|
from optparse import OptionParser
|
2019-05-25 13:44:53 +05:30
|
|
|
from io import StringIO
|
|
|
|
import damask
|
2016-08-19 22:23:48 +05:30
|
|
|
|
|
|
|
scriptName = os.path.splitext(os.path.basename(__file__))[0]
|
|
|
|
scriptID = ' '.join([scriptName,damask.version])
|
|
|
|
|
|
|
|
#--------------------------------------------------------------------------------------------------
|
|
|
|
# MAIN
|
|
|
|
#--------------------------------------------------------------------------------------------------
|
|
|
|
|
2016-09-21 21:13:07 +05:30
|
|
|
validDirections = ['x','y','z']
|
2016-08-19 22:23:48 +05:30
|
|
|
parser = OptionParser(option_class=damask.extendableOption, usage='%prog options [geomfile(s)]', description = """
|
2016-09-21 21:13:07 +05:30
|
|
|
Mirrors spectral geometry description along given directions.
|
2016-08-19 22:23:48 +05:30
|
|
|
|
|
|
|
""", version=scriptID)
|
|
|
|
|
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 {'x','y','z'}")
|
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.')
|
|
|
|
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-25 12:18:44 +05:30
|
|
|
|
2019-05-23 22:33:24 +05:30
|
|
|
|
2016-08-19 22:23:48 +05:30
|
|
|
# --- loop over input files -------------------------------------------------------------------------
|
|
|
|
|
|
|
|
if filenames == []: filenames = [None]
|
|
|
|
|
|
|
|
for name in filenames:
|
2019-05-25 12:18:44 +05:30
|
|
|
if name is None:
|
|
|
|
virt_file = StringIO(''.join(sys.stdin.read()))
|
|
|
|
geom = damask.Geom.from_file(virt_file)
|
|
|
|
else:
|
|
|
|
geom = damask.Geom.from_file(name)
|
|
|
|
|
2016-08-19 22:23:48 +05:30
|
|
|
damask.util.report(scriptName,name)
|
|
|
|
|
2019-05-25 12:18:44 +05:30
|
|
|
microstructure = geom.microstructure
|
2016-08-19 22:23:48 +05:30
|
|
|
|
2016-09-21 21:13:07 +05:30
|
|
|
if 'z' in options.directions:
|
|
|
|
microstructure = np.concatenate([microstructure,microstructure[:,:,::-1]],2)
|
2019-05-25 12:18:44 +05:30
|
|
|
geom.set_size(geom.get_size()*np.array([1,1,2]))
|
2016-09-21 21:13:07 +05:30
|
|
|
if 'y' in options.directions:
|
|
|
|
microstructure = np.concatenate([microstructure,microstructure[:,::-1,:]],1)
|
2019-05-25 12:18:44 +05:30
|
|
|
geom.set_size(geom.get_size()*np.array([1,2,1]))
|
2016-09-21 21:13:07 +05:30
|
|
|
if 'x' in options.directions:
|
|
|
|
microstructure = np.concatenate([microstructure,microstructure[::-1,:,:]],0)
|
2019-05-25 12:18:44 +05:30
|
|
|
geom.set_size(geom.get_size()*np.array([2,1,1]))
|
|
|
|
|
|
|
|
geom.microstructure = microstructure
|
|
|
|
geom.add_comment(scriptID + ' ' + ' '.join(sys.argv[1:]))
|
|
|
|
|
|
|
|
damask.util.croak('\n'.join(geom.info()))
|
|
|
|
|
|
|
|
if name is None:
|
|
|
|
sys.stdout.write(str(geom))
|
|
|
|
else:
|
|
|
|
geom.to_file(name)
|