2018-11-17 12:42:12 +05:30
|
|
|
#!/usr/bin/env python3
|
2012-06-21 18:27:14 +05:30
|
|
|
|
2019-05-25 14:06:46 +05:30
|
|
|
import os
|
|
|
|
import sys
|
2019-05-28 06:44:09 +05:30
|
|
|
import numpy as np
|
|
|
|
|
2019-05-25 15:39:09 +05:30
|
|
|
from io import StringIO
|
2014-11-07 16:43:14 +05:30
|
|
|
from optparse import OptionParser
|
2019-05-25 14:06:46 +05:30
|
|
|
from scipy import ndimage
|
2019-05-26 21:18:59 +05:30
|
|
|
|
2013-07-01 00:41:16 +05:30
|
|
|
import damask
|
2012-06-21 18:27:14 +05:30
|
|
|
|
2019-05-26 21:18:59 +05:30
|
|
|
|
2016-01-27 22:36:00 +05:30
|
|
|
scriptName = os.path.splitext(os.path.basename(__file__))[0]
|
|
|
|
scriptID = ' '.join([scriptName,damask.version])
|
2012-06-21 18:27:14 +05:30
|
|
|
|
2019-05-26 21:18:59 +05:30
|
|
|
|
2013-05-13 18:40:31 +05:30
|
|
|
#--------------------------------------------------------------------------------------------------
|
|
|
|
# MAIN
|
|
|
|
#--------------------------------------------------------------------------------------------------
|
2012-06-21 18:27:14 +05:30
|
|
|
|
2016-05-12 12:24:34 +05:30
|
|
|
parser = OptionParser(option_class=damask.extendableOption, usage='%prog options [geomfile(s)]', description = """
|
2019-05-26 21:18:59 +05:30
|
|
|
Scales independently in x, y, and z direction in terms of grid and/or size.
|
2013-07-01 00:41:16 +05:30
|
|
|
Either absolute values or relative factors (like "0.25x") can be used.
|
2014-11-07 16:43:14 +05:30
|
|
|
|
|
|
|
""", version = scriptID)
|
2012-06-21 18:27:14 +05:30
|
|
|
|
2015-08-08 00:33:26 +05:30
|
|
|
parser.add_option('-g', '--grid',
|
|
|
|
dest = 'grid',
|
|
|
|
type = 'string', nargs = 3, metavar = 'string string string',
|
2019-05-26 21:18:59 +05:30
|
|
|
help = 'a,b,c grid of hexahedral box')
|
2015-08-08 00:33:26 +05:30
|
|
|
parser.add_option('-s', '--size',
|
|
|
|
dest = 'size',
|
|
|
|
type = 'string', nargs = 3, metavar = 'string string string',
|
2019-05-26 21:18:59 +05:30
|
|
|
help = 'x,y,z size of hexahedral box')
|
2012-06-21 18:27:14 +05:30
|
|
|
|
|
|
|
(options, filenames) = parser.parse_args()
|
|
|
|
|
2012-11-06 02:49:12 +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:
|
2015-09-24 22:22:58 +05:30
|
|
|
damask.util.report(scriptName,name)
|
2013-07-01 00:41:16 +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-26 21:18:59 +05:30
|
|
|
microstructure = geom.get_microstructure()
|
2019-05-28 06:44:09 +05:30
|
|
|
grid = geom.get_grid()
|
2019-05-25 14:06:46 +05:30
|
|
|
size = geom.get_size()
|
|
|
|
|
2019-05-28 06:44:09 +05:30
|
|
|
new_grid = grid if options.grid is None else \
|
|
|
|
np.array([int(o*float(n.lower().replace('x',''))) if n.lower().endswith('x') \
|
|
|
|
else int(n) for o,n in zip(grid,options.grid)],dtype=int)
|
|
|
|
|
|
|
|
new_size = size if options.size is None else \
|
|
|
|
np.array([o*float(n.lower().replace('x','')) if n.lower().endswith('x') \
|
|
|
|
else float(n) for o,n in zip(size,options.size)],dtype=float)
|
|
|
|
|
|
|
|
if np.any(new_grid != grid):
|
|
|
|
microstructure = ndimage.interpolation.zoom(microstructure, new_grid/grid,output=microstructure.dtype,
|
|
|
|
order=0,mode='nearest', prefilter=False)
|
2019-05-25 14:06:46 +05:30
|
|
|
|
2019-05-28 06:44:09 +05:30
|
|
|
damask.util.croak(geom.update(microstructure,new_size))
|
|
|
|
geom.add_comments(scriptID + ' ' + ' '.join(sys.argv[1:]))
|
2019-05-26 21:18:59 +05:30
|
|
|
|
2019-05-25 14:06:46 +05:30
|
|
|
if name is None:
|
|
|
|
sys.stdout.write(str(geom.show()))
|
|
|
|
else:
|
|
|
|
geom.to_file(name)
|