2013-01-22 04:45:23 +05:30
|
|
|
#!/usr/bin/env python
|
2014-04-02 00:11:14 +05:30
|
|
|
# -*- coding: UTF-8 no BOM -*-
|
2013-01-22 04:45:23 +05:30
|
|
|
|
2016-03-01 22:55:14 +05:30
|
|
|
import os,sys
|
2014-08-07 00:36:33 +05:30
|
|
|
import numpy as np
|
|
|
|
from optparse import OptionParser
|
|
|
|
import damask
|
2013-01-22 04:45:23 +05:30
|
|
|
|
2016-01-27 22:36:00 +05:30
|
|
|
scriptName = os.path.splitext(os.path.basename(__file__))[0]
|
|
|
|
scriptID = ' '.join([scriptName,damask.version])
|
2013-01-22 04:45:23 +05:30
|
|
|
|
|
|
|
# --------------------------------------------------------------------
|
|
|
|
# MAIN
|
|
|
|
# --------------------------------------------------------------------
|
|
|
|
|
2014-08-07 00:36:33 +05:30
|
|
|
parser = OptionParser(option_class=damask.extendableOption, usage='%prog options [file[s]]', description = """
|
2013-01-22 15:26:36 +05:30
|
|
|
Blows up each value to a surrounding data block of size 'packing' thus increasing the former resolution
|
2014-08-07 00:36:33 +05:30
|
|
|
to resolution*packing.
|
2013-01-22 04:45:23 +05:30
|
|
|
|
2014-08-07 00:36:33 +05:30
|
|
|
""", version = scriptID)
|
2013-01-22 04:45:23 +05:30
|
|
|
|
2014-09-12 19:44:55 +05:30
|
|
|
parser.add_option('-c','--coordinates', dest='coords', metavar='string',
|
2015-05-15 00:18:15 +05:30
|
|
|
help='column heading for coordinates [%default]')
|
2014-09-12 19:44:55 +05:30
|
|
|
parser.add_option('-p','--packing', dest='packing', type='int', nargs=3, metavar='int int int',
|
2015-05-15 00:18:15 +05:30
|
|
|
help='dimension of packed group [%default]')
|
2014-09-12 19:44:55 +05:30
|
|
|
parser.add_option('-g','--grid', dest='resolution', type='int', nargs=3, metavar='int int int',
|
2015-05-15 00:18:15 +05:30
|
|
|
help='resolution in x,y,z [autodetect]')
|
2014-09-12 19:44:55 +05:30
|
|
|
parser.add_option('-s','--size', dest='dimension', type='float', nargs=3, metavar='int int int',
|
2015-05-15 00:18:15 +05:30
|
|
|
help='dimension in x,y,z [autodetect]')
|
2015-03-11 12:52:11 +05:30
|
|
|
parser.set_defaults(coords = 'ipinitialcoord')
|
2015-05-15 00:18:15 +05:30
|
|
|
parser.set_defaults(packing = (2,2,2))
|
|
|
|
parser.set_defaults(grid = (0,0,0))
|
|
|
|
parser.set_defaults(size = (0.0,0.0,0.0))
|
2013-01-22 04:45:23 +05:30
|
|
|
|
|
|
|
(options,filenames) = parser.parse_args()
|
|
|
|
|
|
|
|
|
2014-08-07 00:36:33 +05:30
|
|
|
options.packing = np.array(options.packing)
|
2013-01-22 04:45:23 +05:30
|
|
|
prefix = 'blowUp%ix%ix%i_'%(options.packing[0],options.packing[1],options.packing[2])
|
|
|
|
|
2015-09-01 02:52:44 +05:30
|
|
|
# --- loop over input files -------------------------------------------------------------------------
|
|
|
|
|
|
|
|
if filenames == []: filenames = [None]
|
|
|
|
|
2014-08-07 00:36:33 +05:30
|
|
|
for name in filenames:
|
2015-09-01 02:52:44 +05:30
|
|
|
try:
|
|
|
|
table = damask.ASCIItable(name = name,
|
|
|
|
outname = os.path.join(os.path.dirname(name),
|
|
|
|
prefix+ \
|
|
|
|
os.path.basename(name)) if name else name,
|
|
|
|
buffered = False)
|
|
|
|
except: continue
|
2015-09-24 14:54:42 +05:30
|
|
|
damask.util.report(scriptName,name)
|
2015-09-01 02:52:44 +05:30
|
|
|
|
|
|
|
# ------------------------------------------ read header ------------------------------------------
|
|
|
|
|
|
|
|
table.head_read()
|
2016-03-01 22:55:14 +05:30
|
|
|
errors = []
|
2015-09-01 02:52:44 +05:30
|
|
|
|
|
|
|
# ------------------------------------------ sanity checks ----------------------------------------
|
|
|
|
|
2016-03-01 22:55:14 +05:30
|
|
|
if table.label_dimension(options.coords) != 3:
|
|
|
|
damask.util.croak('coordinates {} are not a vector.'.format(options.coords))
|
|
|
|
table.close(dismiss = True)
|
|
|
|
continue
|
|
|
|
else:
|
|
|
|
coordCol = table.label_index(options.coords)
|
2013-01-22 04:45:23 +05:30
|
|
|
|
|
|
|
|
2015-09-01 02:52:44 +05:30
|
|
|
# ------------------------------------------ assemble header --------------------------------------
|
|
|
|
|
2014-08-07 00:36:33 +05:30
|
|
|
table.info_append(scriptID + '\t' + ' '.join(sys.argv[1:]))
|
2013-01-22 04:45:23 +05:30
|
|
|
|
2014-08-07 00:36:33 +05:30
|
|
|
# --------------- figure out size and grid ---------------------------------------------------------
|
2015-09-01 02:52:44 +05:30
|
|
|
|
|
|
|
table.data_readArray()
|
|
|
|
|
|
|
|
coords = [{},{},{}]
|
|
|
|
for i in xrange(len(table.data)):
|
|
|
|
for j in xrange(3):
|
|
|
|
coords[j][str(table.data[i,coordCol+j])] = True
|
|
|
|
grid = np.array(map(len,coords),'i')
|
|
|
|
size = grid/np.maximum(np.ones(3,'d'),grid-1.0)* \
|
|
|
|
np.array([max(map(float,coords[0].keys()))-min(map(float,coords[0].keys())),\
|
|
|
|
max(map(float,coords[1].keys()))-min(map(float,coords[1].keys())),\
|
|
|
|
max(map(float,coords[2].keys()))-min(map(float,coords[2].keys())),\
|
|
|
|
],'d') # size from bounding box, corrected for cell-centeredness
|
|
|
|
|
|
|
|
size = np.where(grid > 1, size, min(size[grid > 1]/grid[grid > 1])) # spacing for grid==1 equal to smallest among other spacings
|
|
|
|
|
2013-01-22 04:45:23 +05:30
|
|
|
|
2014-08-07 00:36:33 +05:30
|
|
|
packing = np.array(options.packing,'i')
|
|
|
|
outSize = grid*packing
|
2013-01-22 04:45:23 +05:30
|
|
|
|
2014-08-07 00:36:33 +05:30
|
|
|
# ------------------------------------------ assemble header ---------------------------------------
|
2013-01-22 04:45:23 +05:30
|
|
|
table.head_write()
|
|
|
|
|
2014-08-07 00:36:33 +05:30
|
|
|
# ------------------------------------------ process data -------------------------------------------
|
2013-01-22 04:45:23 +05:30
|
|
|
table.data_rewind()
|
2014-08-07 00:36:33 +05:30
|
|
|
data = np.zeros(outSize.tolist()+[len(table.labels)])
|
|
|
|
p = np.zeros(3,'i')
|
2013-01-22 04:45:23 +05:30
|
|
|
|
2014-08-07 00:36:33 +05:30
|
|
|
for p[2] in xrange(grid[2]):
|
|
|
|
for p[1] in xrange(grid[1]):
|
|
|
|
for p[0] in xrange(grid[0]):
|
2013-01-22 04:45:23 +05:30
|
|
|
d = p*packing
|
|
|
|
table.data_read()
|
|
|
|
data[d[0]:d[0]+packing[0],
|
2014-04-01 23:22:31 +05:30
|
|
|
d[1]:d[1]+packing[1],
|
|
|
|
d[2]:d[2]+packing[2],
|
2014-08-07 00:36:33 +05:30
|
|
|
: ] = np.tile(np.array(table.data_asFloat(),'d'),packing.tolist()+[1]) # tile to match blowUp voxel size
|
|
|
|
elementSize = size/grid/packing
|
2013-01-22 04:45:23 +05:30
|
|
|
elem = 1
|
|
|
|
for c in xrange(outSize[2]):
|
|
|
|
for b in xrange(outSize[1]):
|
|
|
|
for a in xrange(outSize[0]):
|
2015-09-01 02:52:44 +05:30
|
|
|
data[a,b,c,coordCol:coordCol+3] = [a+0.5,b+0.5,c+0.5]*elementSize
|
|
|
|
data[a,b,c,table.label_index('elem')] = elem
|
2013-01-22 04:45:23 +05:30
|
|
|
table.data = data[a,b,c,:].tolist()
|
2014-08-07 00:36:33 +05:30
|
|
|
outputAlive = table.data_write() # output processed line
|
2013-01-22 04:45:23 +05:30
|
|
|
elem += 1
|
|
|
|
|
2015-09-01 02:52:44 +05:30
|
|
|
# ------------------------------------------ output finalization -----------------------------------
|
2013-01-22 04:45:23 +05:30
|
|
|
|
2015-09-01 02:52:44 +05:30
|
|
|
table.close() # close input ASCII table (works for stdin)
|