2018-11-17 12:42:12 +05:30
|
|
|
#!/usr/bin/env python3
|
2012-06-21 18:27:14 +05:30
|
|
|
|
2019-05-27 00:06:41 +05:30
|
|
|
import os
|
|
|
|
import sys
|
2019-05-30 05:23:45 +05:30
|
|
|
from io import StringIO
|
|
|
|
from optparse import OptionParser
|
|
|
|
|
2019-05-30 14:24:33 +05:30
|
|
|
import numpy as np
|
|
|
|
|
|
|
|
import damask
|
|
|
|
|
2019-05-31 13:57:26 +05:30
|
|
|
|
2016-01-27 22:36:00 +05:30
|
|
|
scriptName = os.path.splitext(os.path.basename(__file__))[0]
|
|
|
|
scriptID = ' '.join([scriptName,damask.version])
|
2014-11-07 16:37:03 +05:30
|
|
|
|
2019-05-30 14:24:33 +05:30
|
|
|
|
2014-11-07 16:37:03 +05:30
|
|
|
# --------------------------------------------------------------------
|
2013-05-15 22:53:21 +05:30
|
|
|
# MAIN
|
2014-11-07 16:37:03 +05:30
|
|
|
# --------------------------------------------------------------------
|
2012-06-21 18:27:14 +05:30
|
|
|
|
2019-05-30 14:24:33 +05:30
|
|
|
parser = OptionParser(option_class=damask.extendableOption, usage='%prog options [geomfile(s)]', description = """
|
|
|
|
Increases or decreases the (three-dimensional) canvas.
|
2016-04-24 21:54:00 +05:30
|
|
|
Grid can be given as absolute or relative values, e.g. 16 16 16 or 2x 0.5x 32.
|
2012-06-21 18:27:14 +05:30
|
|
|
|
2014-11-07 16:37:03 +05:30
|
|
|
""", version = scriptID)
|
|
|
|
|
2019-05-30 14:24:33 +05:30
|
|
|
parser.add_option('-g','--grid',
|
2015-08-08 00:33:26 +05:30
|
|
|
dest = 'grid',
|
|
|
|
type = 'string', nargs = 3, metavar = ' '.join(['string']*3),
|
2019-05-30 14:24:33 +05:30
|
|
|
help = 'a,b,c grid of hexahedral box')
|
|
|
|
parser.add_option('-o','--offset',
|
2015-08-08 00:33:26 +05:30
|
|
|
dest = 'offset',
|
|
|
|
type = 'int', nargs = 3, metavar = ' '.join(['int']*3),
|
2015-11-16 16:22:56 +05:30
|
|
|
help = 'a,b,c offset from old to new origin of grid [%default]')
|
2019-05-30 14:24:33 +05:30
|
|
|
parser.add_option('-f','--fill',
|
2015-08-08 00:33:26 +05:30
|
|
|
dest = 'fill',
|
2019-05-30 14:24:33 +05:30
|
|
|
type = 'float', metavar = 'int',
|
|
|
|
help = 'background microstructure index, defaults to max microstructure index + 1')
|
2019-05-26 16:36:22 +05:30
|
|
|
|
2019-05-30 14:24:33 +05:30
|
|
|
parser.set_defaults(offset = (0,0,0))
|
2012-06-21 18:27:14 +05:30
|
|
|
|
|
|
|
(options, filenames) = parser.parse_args()
|
|
|
|
|
2015-08-08 00:33:26 +05:30
|
|
|
|
2015-08-13 00:13:11 +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)
|
2019-05-30 17:37:49 +05:30
|
|
|
|
2019-05-30 05:23:45 +05:30
|
|
|
geom = damask.Geom.from_file(StringIO(''.join(sys.stdin.read())) if name is None else name)
|
2019-06-03 23:09:45 +05:30
|
|
|
origin = geom.get_origin()
|
|
|
|
size = geom.get_size()
|
2019-06-04 00:12:35 +05:30
|
|
|
old = new = geom.get_grid()
|
2019-05-31 19:28:47 +05:30
|
|
|
offset = np.asarray(options.offset)
|
|
|
|
|
2019-06-03 23:09:45 +05:30
|
|
|
if options.grid is not None:
|
2019-06-04 00:12:35 +05:30
|
|
|
new = np.maximum(1,
|
|
|
|
np.array([int(o*float(n.lower().replace('x',''))) if n.lower().endswith('x') \
|
|
|
|
else int(n) for o,n in zip(old,options.grid)],dtype=int))
|
2019-05-31 19:28:47 +05:30
|
|
|
|
2019-06-04 00:12:35 +05:30
|
|
|
canvas = np.full(new,options.fill if options.fill is not None
|
|
|
|
else np.nanmax(geom.microstructure)+1,geom.microstructure.dtype)
|
2019-05-31 19:28:47 +05:30
|
|
|
|
2019-11-24 23:32:19 +05:30
|
|
|
l = np.clip( offset, 0,np.minimum(old +offset,new)) # noqa
|
2019-06-04 00:12:35 +05:30
|
|
|
r = np.clip( offset+old,0,np.minimum(old*2+offset,new))
|
|
|
|
L = np.clip(-offset, 0,np.minimum(new -offset,old))
|
|
|
|
R = np.clip(-offset+new,0,np.minimum(new*2-offset,old))
|
|
|
|
canvas[l[0]:r[0],l[1]:r[1],l[2]:r[2]] = geom.microstructure[L[0]:R[0],L[1]:R[1],L[2]:R[2]]
|
2019-05-30 17:37:49 +05:30
|
|
|
|
2019-05-30 14:24:33 +05:30
|
|
|
|
2019-06-04 00:12:35 +05:30
|
|
|
damask.util.croak(geom.update(canvas,origin=origin+offset*size/old,rescale=True))
|
2019-05-28 06:44:09 +05:30
|
|
|
geom.add_comments(scriptID + ' ' + ' '.join(sys.argv[1:]))
|
2019-05-27 00:06:41 +05:30
|
|
|
|
2019-11-24 23:32:19 +05:30
|
|
|
geom.to_file(sys.stdout if name is None else name,pack=False)
|