2011-02-01 16:18:44 +05:30
|
|
|
#!/usr/bin/env python
|
|
|
|
# -*- coding: UTF-8 no BOM -*-
|
|
|
|
|
2016-03-01 22:55:14 +05:30
|
|
|
import os,sys,re,fnmatch,vtk
|
2014-07-09 15:37:24 +05:30
|
|
|
import numpy as np
|
|
|
|
from optparse import OptionParser
|
2013-05-29 15:54:00 +05:30
|
|
|
import damask
|
2011-02-01 16:18:44 +05:30
|
|
|
|
2016-01-27 22:36:00 +05:30
|
|
|
scriptName = os.path.splitext(os.path.basename(__file__))[0]
|
|
|
|
scriptID = ' '.join([scriptName,damask.version])
|
2011-02-01 16:18:44 +05:30
|
|
|
|
2016-03-24 15:07:15 +05:30
|
|
|
def deformedCoordsFFT(size,F,scaling,Favg=None):
|
|
|
|
grid = np.array(np.shape(F)[:-2])
|
|
|
|
N = grid.prod()
|
|
|
|
step = size/grid
|
|
|
|
k_s = np.zeros([3],'i')
|
|
|
|
|
|
|
|
F_fourier = np.fft.fftpack.rfftn(F,s=grid,axes=(0,1,2))
|
|
|
|
coords_fourier = np.zeros(F_fourier.shape[:-1],'c16')
|
|
|
|
if Favg is None:
|
|
|
|
Favg = np.real(F_fourier[0,0,0,:,:]/N)
|
|
|
|
|
|
|
|
for i in xrange(grid[2]//2+1):
|
|
|
|
k_s[2] = i
|
|
|
|
if grid[2]%2 == 0 and i == grid[2]//2: k_s[2] = 0 # for even grid, set Nyquist freq to 0 (Johnson, MIT, 2011)
|
|
|
|
|
|
|
|
for j in xrange(grid[1]):
|
|
|
|
k_s[1] = j
|
|
|
|
if grid[1]%2 == 0 and j == grid[1]//2: k_s[1] = 0 # for even grid, set Nyquist freq to 0 (Johnson, MIT, 2011)
|
|
|
|
elif j > grid[1]//2: k_s[1] -= grid[1]
|
|
|
|
|
|
|
|
for k in xrange(grid[0]):
|
|
|
|
k_s[0] = k
|
|
|
|
if grid[0]%2 == 0 and k == grid[0]//2: k_s[0] = 0 # for even grid, set Nyquist freq to 0 (Johnson, MIT, 2011)
|
|
|
|
elif k > grid[0]//2: k_s[0] -= grid[0]
|
|
|
|
|
|
|
|
xi = 0.0+(k_s*0.5j*size/math.pi)
|
|
|
|
for m in xrange(3):
|
|
|
|
coords_fourier[k,j,i,m] = np.sum(F_fourier[k,j,i,m,:]*xi)
|
|
|
|
|
|
|
|
if (any(k_s != 0)):
|
|
|
|
coords_fourier[k,j,i,:]/=-np.linalg.norm(k_s)**2.0
|
|
|
|
|
|
|
|
coords = np.fft.fftpack.irfftn(coords_fourier,s=grid,axes=(0,1,2))
|
|
|
|
offset_coords =np.dot(F[0,0,0,:,:],step/2.0) - scaling*coords[0,0,0,:]
|
|
|
|
|
|
|
|
for z in xrange(grid[2]):
|
|
|
|
for y in xrange(grid[1]):
|
|
|
|
for x in xrange(grid[0]):
|
|
|
|
coords[x,y,z,:] += offset_coords + np.dot(Favg,[x,y,z]*step)
|
|
|
|
|
2011-02-01 16:18:44 +05:30
|
|
|
def outStdout(cmd,locals):
|
|
|
|
if cmd[0:3] == '(!)':
|
|
|
|
exec(cmd[3:])
|
|
|
|
elif cmd[0:3] == '(?)':
|
|
|
|
cmd = eval(cmd[3:])
|
|
|
|
print cmd
|
|
|
|
else:
|
|
|
|
print cmd
|
|
|
|
return
|
|
|
|
|
|
|
|
def outFile(cmd,locals):
|
|
|
|
if cmd[0:3] == '(!)':
|
|
|
|
exec(cmd[3:])
|
|
|
|
elif cmd[0:3] == '(?)':
|
|
|
|
cmd = eval(cmd[3:])
|
|
|
|
locals['filepointer'].write(cmd+'\n')
|
|
|
|
else:
|
|
|
|
locals['filepointer'].write(cmd+'\n')
|
|
|
|
return
|
|
|
|
|
|
|
|
|
|
|
|
def output(cmds,locals,dest):
|
|
|
|
for cmd in cmds:
|
|
|
|
if isinstance(cmd,list):
|
|
|
|
output(cmd,locals,dest)
|
|
|
|
else:
|
|
|
|
{\
|
|
|
|
'File': outFile,\
|
|
|
|
'Stdout': outStdout,\
|
|
|
|
}[dest](str(cmd),locals)
|
|
|
|
return
|
|
|
|
|
|
|
|
|
2011-02-01 22:13:00 +05:30
|
|
|
def transliterateToFloat(x):
|
|
|
|
try:
|
|
|
|
return float(x)
|
|
|
|
except:
|
|
|
|
return 0.0
|
|
|
|
|
2012-01-20 02:12:50 +05:30
|
|
|
|
|
|
|
def unravel(item):
|
|
|
|
if hasattr(item,'__contains__'): return ' '.join(map(unravel,item))
|
|
|
|
else: return str(item)
|
|
|
|
|
|
|
|
|
2011-02-01 16:18:44 +05:30
|
|
|
# ++++++++++++++++++++++++++++++++++++++++++++++++++++
|
2012-06-19 21:30:59 +05:30
|
|
|
def vtk_writeASCII_mesh(mesh,data,res,sep):
|
2016-03-02 01:14:43 +05:30
|
|
|
"""function writes data array defined on a hexahedral mesh (geometry)"""
|
2012-06-19 21:00:16 +05:30
|
|
|
info = {\
|
|
|
|
'tensor': {'name':'tensor','len':9},\
|
|
|
|
'vector': {'name':'vector','len':3},\
|
|
|
|
'scalar': {'name':'scalar','len':1},\
|
|
|
|
'double': {'name':'scalar','len':2},\
|
|
|
|
'triple': {'name':'scalar','len':3},\
|
|
|
|
'quadruple': {'name':'scalar','len':4},\
|
|
|
|
}
|
2011-02-01 16:18:44 +05:30
|
|
|
N1 = (res[0]+1)*(res[1]+1)*(res[2]+1)
|
|
|
|
N = res[0]*res[1]*res[2]
|
|
|
|
|
|
|
|
cmds = [\
|
|
|
|
'# vtk DataFile Version 3.1',
|
2014-08-06 18:57:09 +05:30
|
|
|
'powered by %s'%scriptID,
|
2011-02-01 16:18:44 +05:30
|
|
|
'ASCII',
|
|
|
|
'DATASET UNSTRUCTURED_GRID',
|
2013-05-29 15:54:00 +05:30
|
|
|
'POINTS %i double'%N1,
|
2013-01-31 21:58:08 +05:30
|
|
|
[[['\t'.join(map(str,mesh[:,i,j,k])) for i in range(res[0]+1)] for j in range(res[1]+1)] for k in range(res[2]+1)],
|
2011-02-01 16:18:44 +05:30
|
|
|
'CELLS %i %i'%(N,N*9),
|
|
|
|
]
|
|
|
|
|
|
|
|
# cells
|
2011-04-14 15:41:23 +05:30
|
|
|
for z in range (res[2]):
|
|
|
|
for y in range (res[1]):
|
|
|
|
for x in range (res[0]):
|
|
|
|
base = z*(res[1]+1)*(res[0]+1)+y*(res[0]+1)+x
|
2011-02-01 16:18:44 +05:30
|
|
|
cmds.append('8 '+'\t'.join(map(str,[ \
|
|
|
|
base,
|
|
|
|
base+1,
|
2011-04-14 15:41:23 +05:30
|
|
|
base+res[0]+2,
|
|
|
|
base+res[0]+1,
|
|
|
|
base+(res[1]+1)*(res[0]+1),
|
|
|
|
base+(res[1]+1)*(res[0]+1)+1,
|
|
|
|
base+(res[1]+1)*(res[0]+1)+res[0]+2,
|
|
|
|
base+(res[1]+1)*(res[0]+1)+res[0]+1,
|
2011-02-01 16:18:44 +05:30
|
|
|
])))
|
|
|
|
cmds += [\
|
|
|
|
'CELL_TYPES %i'%N,
|
|
|
|
['12']*N,
|
|
|
|
'CELL_DATA %i'%N,
|
|
|
|
]
|
|
|
|
|
|
|
|
for type in data:
|
2011-05-22 19:31:18 +05:30
|
|
|
plural = {True:'',False:'S'}[type.lower().endswith('s')]
|
2013-05-29 15:54:00 +05:30
|
|
|
for item in data[type]['_order_']:
|
2011-02-01 16:18:44 +05:30
|
|
|
cmds += [\
|
2015-04-09 00:18:35 +05:30
|
|
|
'%s %s double'%(info[type]['name'].upper()+plural,item),
|
2012-06-19 21:00:16 +05:30
|
|
|
{True:'LOOKUP_TABLE default',False:''}[info[type]['name'][:3]=='sca'],
|
2012-06-19 21:30:59 +05:30
|
|
|
[[[sep.join(map(unravel,data[type][item][:,j,k]))] for j in range(res[1])] for k in range(res[2])],
|
2011-02-01 16:18:44 +05:30
|
|
|
]
|
|
|
|
|
2011-02-07 20:05:42 +05:30
|
|
|
return cmds
|
2016-03-02 01:14:43 +05:30
|
|
|
|
|
|
|
#+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
|
2012-06-19 21:30:59 +05:30
|
|
|
def vtk_writeASCII_points(coordinates,data,res,sep):
|
2016-03-02 01:14:43 +05:30
|
|
|
"""function writes data array defined on a point field"""
|
2011-02-01 16:18:44 +05:30
|
|
|
N = res[0]*res[1]*res[2]
|
|
|
|
|
|
|
|
cmds = [\
|
|
|
|
'# vtk DataFile Version 3.1',
|
2014-08-06 18:57:09 +05:30
|
|
|
'powered by %s'%scriptID,
|
2011-02-01 16:18:44 +05:30
|
|
|
'ASCII',
|
|
|
|
'DATASET UNSTRUCTURED_GRID',
|
2015-04-09 00:18:35 +05:30
|
|
|
'POINTS %i double'%N,
|
2011-02-01 16:18:44 +05:30
|
|
|
[[['\t'.join(map(str,coordinates[i,j,k])) for i in range(res[0])] for j in range(res[1])] for k in range(res[2])],
|
|
|
|
'CELLS %i %i'%(N,N*2),
|
|
|
|
['1\t%i'%i for i in range(N)],
|
|
|
|
'CELL_TYPES %i'%N,
|
|
|
|
['1']*N,
|
|
|
|
'POINT_DATA %i'%N,
|
|
|
|
]
|
|
|
|
|
|
|
|
for type in data:
|
2011-05-22 19:31:18 +05:30
|
|
|
plural = {True:'',False:'S'}[type.lower().endswith('s')]
|
2011-02-01 16:18:44 +05:30
|
|
|
for item in data[type]:
|
|
|
|
cmds += [\
|
2015-04-09 00:18:35 +05:30
|
|
|
'%s %s double'%(type.upper()+plural,item),
|
2012-01-20 02:12:50 +05:30
|
|
|
{True:'LOOKUP_TABLE default',False:''}[type.lower()[:3]=='sca'],
|
2012-06-19 21:30:59 +05:30
|
|
|
[[[sep.join(map(unravel,data[type][item][:,j,k]))] for j in range(res[1])] for k in range(res[2])],
|
2011-02-01 16:18:44 +05:30
|
|
|
]
|
|
|
|
|
|
|
|
return cmds
|
|
|
|
|
|
|
|
|
|
|
|
# ----------------------- MAIN -------------------------------
|
|
|
|
|
2014-07-09 15:37:24 +05:30
|
|
|
parser = OptionParser(option_class=damask.extendableOption, usage='%prog [options] datafile[s]', description = """
|
2014-08-06 18:57:09 +05:30
|
|
|
Produce VTK file from data field.
|
|
|
|
Coordinates are taken from (consecutive) x, y, and z columns.
|
2011-02-01 16:18:44 +05:30
|
|
|
|
2014-08-06 18:57:09 +05:30
|
|
|
""", version = scriptID)
|
2011-08-18 13:30:19 +05:30
|
|
|
|
2014-07-25 00:17:09 +05:30
|
|
|
sepChoices = ['n','t','s']
|
2014-09-12 19:44:55 +05:30
|
|
|
parser.add_option('-s', '--scalar', dest='scalar', action='extend', metavar = '<string LIST>',
|
2014-07-25 00:17:09 +05:30
|
|
|
help='list of single scalars to visualize')
|
2014-09-12 19:44:55 +05:30
|
|
|
parser.add_option( '--double', dest='double', action='extend', metavar = '<string LIST>',
|
2014-07-25 00:17:09 +05:30
|
|
|
help='list of two scalars to visualize')
|
2014-09-12 19:44:55 +05:30
|
|
|
parser.add_option( '--triple', dest='triple', action='extend', metavar = '<string LIST>',
|
2014-07-25 00:17:09 +05:30
|
|
|
help='list of three scalars to visualize')
|
2014-09-12 19:44:55 +05:30
|
|
|
parser.add_option( '--quadruple', dest='quadruple', action='extend', metavar = '<string LIST>',
|
2014-07-25 00:17:09 +05:30
|
|
|
help='list of four scalars to visualize')
|
2014-09-12 19:44:55 +05:30
|
|
|
parser.add_option('-v', '--vector', dest='vector', action='extend', metavar = '<string LIST>',
|
2014-07-25 00:17:09 +05:30
|
|
|
help='list of vectors to visualize')
|
2014-09-12 19:44:55 +05:30
|
|
|
parser.add_option('-t', '--tensor', dest='tensor', action='extend', metavar = '<string LIST>',
|
2014-07-25 00:17:09 +05:30
|
|
|
help='list of tensors to visualize')
|
2014-09-12 19:44:55 +05:30
|
|
|
parser.add_option('-d', '--deformation', dest='defgrad', metavar = 'string',
|
2014-07-25 00:17:09 +05:30
|
|
|
help='heading of deformation gradient columns [%default]')
|
|
|
|
parser.add_option('--reference', dest='undeformed', action='store_true',
|
|
|
|
help='map results to reference (undeformed) configuration [%default]')
|
|
|
|
parser.add_option('-c','--cell', dest='cell', action='store_true',
|
|
|
|
help='data is cell-centered [%default]')
|
|
|
|
parser.add_option('-p','--vertex', dest='cell', action='store_false',
|
|
|
|
help='data is vertex-centered')
|
|
|
|
parser.add_option('--mesh', dest='output_mesh', action='store_true',
|
|
|
|
help='produce VTK mesh file [%default]')
|
|
|
|
parser.add_option('--nomesh', dest='output_mesh', action='store_false',
|
|
|
|
help='omit VTK mesh file')
|
|
|
|
parser.add_option('--points', dest='output_points', action='store_true',
|
|
|
|
help='produce VTK points file [%default]')
|
|
|
|
parser.add_option('--nopoints', dest='output_points', action='store_false',
|
|
|
|
help='omit VTK points file')
|
2014-09-12 19:44:55 +05:30
|
|
|
parser.add_option('--separator', dest='separator', type='choice', choices=sepChoices, metavar='string',
|
2014-09-12 20:16:12 +05:30
|
|
|
help='data separator {%s} [t]'%(' '.join(map(str,sepChoices))))
|
|
|
|
parser.add_option('--scaling', dest='scaling', action='extend', metavar = '<float LIST>',
|
|
|
|
help='scaling of fluctuation')
|
2014-09-12 19:44:55 +05:30
|
|
|
parser.add_option('-u', '--unitlength', dest='unitlength', type='float', metavar = 'float',
|
2014-07-25 00:17:09 +05:30
|
|
|
help='set unit length for 2D model [%default]')
|
2015-04-09 00:18:35 +05:30
|
|
|
|
2011-02-01 16:18:44 +05:30
|
|
|
parser.set_defaults(defgrad = 'f')
|
2012-06-19 21:30:59 +05:30
|
|
|
parser.set_defaults(separator = 't')
|
2011-02-01 16:18:44 +05:30
|
|
|
parser.set_defaults(scalar = [])
|
2012-06-19 21:00:16 +05:30
|
|
|
parser.set_defaults(double = [])
|
|
|
|
parser.set_defaults(triple = [])
|
|
|
|
parser.set_defaults(quadruple = [])
|
2011-02-01 16:18:44 +05:30
|
|
|
parser.set_defaults(vector = [])
|
|
|
|
parser.set_defaults(tensor = [])
|
2011-08-19 13:03:22 +05:30
|
|
|
parser.set_defaults(output_mesh = True)
|
|
|
|
parser.set_defaults(output_points = False)
|
2013-03-22 20:39:55 +05:30
|
|
|
parser.set_defaults(scaling = [])
|
2011-08-19 13:03:22 +05:30
|
|
|
parser.set_defaults(undeformed = False)
|
2011-08-25 20:58:33 +05:30
|
|
|
parser.set_defaults(unitlength = 0.0)
|
2011-10-20 17:59:59 +05:30
|
|
|
parser.set_defaults(cell = True)
|
2011-02-01 16:18:44 +05:30
|
|
|
|
2012-06-19 21:30:59 +05:30
|
|
|
sep = {'n': '\n', 't': '\t', 's': ' '}
|
|
|
|
|
2011-02-01 16:18:44 +05:30
|
|
|
(options, args) = parser.parse_args()
|
2013-03-22 20:39:55 +05:30
|
|
|
|
2013-03-26 21:46:59 +05:30
|
|
|
options.scaling += [1.0 for i in xrange(max(0,3-len(options.scaling)))]
|
2013-03-26 19:48:29 +05:30
|
|
|
options.scaling = map(float, options.scaling)
|
2013-03-26 21:46:59 +05:30
|
|
|
|
2011-02-01 16:18:44 +05:30
|
|
|
for filename in args:
|
|
|
|
if not os.path.exists(filename):
|
|
|
|
continue
|
|
|
|
file = open(filename)
|
|
|
|
content = file.readlines()
|
|
|
|
file.close()
|
2014-06-08 20:13:32 +05:30
|
|
|
m = re.search('(\d+)\s*head', content[0].lower())
|
2016-03-02 01:14:43 +05:30
|
|
|
if m is None:
|
2011-02-01 16:18:44 +05:30
|
|
|
continue
|
2011-12-06 23:16:33 +05:30
|
|
|
print filename,'\n'
|
2011-05-13 22:23:27 +05:30
|
|
|
sys.stdout.flush()
|
|
|
|
|
2011-02-01 16:18:44 +05:30
|
|
|
headrow = int(m.group(1))
|
|
|
|
headings = content[headrow].split()
|
|
|
|
column = {}
|
2013-05-29 15:54:00 +05:30
|
|
|
matches = {}
|
2011-02-01 16:18:44 +05:30
|
|
|
maxcol = 0
|
2013-06-27 23:51:20 +05:30
|
|
|
locol = -1
|
2011-02-01 16:18:44 +05:30
|
|
|
|
|
|
|
for col,head in enumerate(headings):
|
2015-03-24 19:22:40 +05:30
|
|
|
if head == {True:'1_ipinitialcoord',False:'1_nodeinitialcoord'}[options.cell]:
|
2011-10-20 17:59:59 +05:30
|
|
|
locol = col
|
2011-02-01 16:18:44 +05:30
|
|
|
maxcol = max(maxcol,col+3)
|
|
|
|
break
|
|
|
|
|
2011-10-20 17:59:59 +05:30
|
|
|
if locol < 0:
|
|
|
|
print 'missing coordinates..!'
|
2011-02-01 16:18:44 +05:30
|
|
|
continue
|
2013-05-29 15:54:00 +05:30
|
|
|
|
2011-02-01 16:18:44 +05:30
|
|
|
column['tensor'] = {}
|
2013-05-29 15:54:00 +05:30
|
|
|
matches['tensor'] = {}
|
2011-02-01 16:18:44 +05:30
|
|
|
for label in [options.defgrad] + options.tensor:
|
|
|
|
column['tensor'][label] = -1
|
|
|
|
for col,head in enumerate(headings):
|
2013-02-15 03:03:11 +05:30
|
|
|
if head == label or head == '1_'+label:
|
2011-02-01 16:18:44 +05:30
|
|
|
column['tensor'][label] = col
|
|
|
|
maxcol = max(maxcol,col+9)
|
2013-05-29 15:54:00 +05:30
|
|
|
matches['tensor'][label] = [label]
|
2011-02-01 16:18:44 +05:30
|
|
|
break
|
|
|
|
|
2012-06-19 21:00:16 +05:30
|
|
|
if not options.undeformed and column['tensor'][options.defgrad] < 0:
|
2011-05-13 22:23:27 +05:30
|
|
|
print 'missing deformation gradient "%s"..!'%options.defgrad
|
2011-02-01 16:18:44 +05:30
|
|
|
continue
|
|
|
|
|
|
|
|
column['vector'] = {}
|
2014-12-19 03:16:38 +05:30
|
|
|
matches['vector'] = {}
|
2011-02-01 16:18:44 +05:30
|
|
|
for label in options.vector:
|
|
|
|
column['vector'][label] = -1
|
|
|
|
for col,head in enumerate(headings):
|
2013-02-15 03:03:11 +05:30
|
|
|
if head == label or head == '1_'+label:
|
2011-02-01 16:18:44 +05:30
|
|
|
column['vector'][label] = col
|
|
|
|
maxcol = max(maxcol,col+3)
|
2013-05-29 15:54:00 +05:30
|
|
|
matches['vector'][label] = [label]
|
2011-02-01 16:18:44 +05:30
|
|
|
break
|
|
|
|
|
2012-06-19 21:00:16 +05:30
|
|
|
for length,what in enumerate(['scalar','double','triple','quadruple']):
|
|
|
|
column[what] = {}
|
2013-05-29 15:54:00 +05:30
|
|
|
labels = eval("options.%s"%what)
|
|
|
|
matches[what] = {}
|
|
|
|
for col,head in enumerate(headings):
|
|
|
|
for needle in labels:
|
|
|
|
if fnmatch.fnmatch(head,needle):
|
|
|
|
column[what][head] = col
|
2012-06-19 21:00:16 +05:30
|
|
|
maxcol = max(maxcol,col+1+length)
|
2013-05-29 15:54:00 +05:30
|
|
|
if needle not in matches[what]:
|
|
|
|
matches[what][needle] = [head]
|
|
|
|
else:
|
|
|
|
matches[what][needle] += [head]
|
2012-06-19 21:00:16 +05:30
|
|
|
|
2011-02-01 16:18:44 +05:30
|
|
|
|
2014-07-09 15:37:24 +05:30
|
|
|
values = np.array(sorted([map(transliterateToFloat,line.split()[:maxcol]) for line in content[headrow+1:]],
|
2014-12-19 03:16:38 +05:30
|
|
|
key=lambda x:(x[locol+0],x[locol+1],x[locol+2])),'d') # sort with z as fastest and x as slowest index
|
|
|
|
values2 = np.array([map(transliterateToFloat,line.split()[:maxcol]) for line in content[headrow+1:]],'d') # sort with x as fastest and z as slowest index
|
2011-04-14 15:41:23 +05:30
|
|
|
|
2011-02-01 16:18:44 +05:30
|
|
|
N = len(values)
|
2013-01-31 21:58:08 +05:30
|
|
|
|
2013-06-27 23:51:20 +05:30
|
|
|
tempGrid = [{},{},{}]
|
2011-10-20 17:59:59 +05:30
|
|
|
for j in xrange(3):
|
|
|
|
for i in xrange(N):
|
2013-06-27 23:51:20 +05:30
|
|
|
tempGrid[j][str(values[i,locol+j])] = True
|
2011-02-01 16:18:44 +05:30
|
|
|
|
2014-07-09 15:37:24 +05:30
|
|
|
grid = np.array([len(tempGrid[0]),\
|
2014-12-19 03:16:38 +05:30
|
|
|
len(tempGrid[1]),\
|
|
|
|
len(tempGrid[2]),],'i')
|
2014-06-08 20:13:32 +05:30
|
|
|
|
2014-07-09 15:37:24 +05:30
|
|
|
dim = np.ones(3)
|
2011-10-20 17:59:59 +05:30
|
|
|
|
2013-06-27 23:51:20 +05:30
|
|
|
for i,r in enumerate(grid):
|
2011-05-13 22:23:27 +05:30
|
|
|
if r > 1:
|
2013-06-27 23:51:20 +05:30
|
|
|
dim[i] = (max(map(float,tempGrid[i].keys()))-min(map(float,tempGrid[i].keys())))*r/(r-1.0)
|
|
|
|
if grid[2]==1: # for 2D case set undefined dimension to given unitlength or alternatively give it the length of the smallest element
|
2011-08-25 20:58:33 +05:30
|
|
|
if options.unitlength == 0.0:
|
2013-06-27 23:51:20 +05:30
|
|
|
dim[2] = min(dim/grid)
|
2011-08-25 20:58:33 +05:30
|
|
|
else:
|
|
|
|
dim[2] = options.unitlength
|
2014-06-08 20:13:32 +05:30
|
|
|
print dim
|
2013-01-31 21:58:08 +05:30
|
|
|
if options.undeformed:
|
2014-07-09 15:37:24 +05:30
|
|
|
Favg = np.eye(3)
|
2013-01-31 21:58:08 +05:30
|
|
|
else:
|
|
|
|
Favg = damask.core.math.tensorAvg(
|
2014-07-09 15:37:24 +05:30
|
|
|
np.reshape(np.transpose(values[:,column['tensor'][options.defgrad]:
|
2013-01-31 21:58:08 +05:30
|
|
|
column['tensor'][options.defgrad]+9]),
|
2013-06-27 23:51:20 +05:30
|
|
|
(3,3,grid[0],grid[1],grid[2])))
|
|
|
|
|
2015-04-09 00:18:35 +05:30
|
|
|
F = np.reshape(np.transpose(values[:,column['tensor'][options.defgrad]:
|
|
|
|
column['tensor'][options.defgrad]+9]),
|
|
|
|
(3,3,grid[0],grid[1],grid[2]))
|
2016-03-24 15:07:15 +05:30
|
|
|
F2 = np.reshape(values[:,column['tensor'][options.defgrad]:
|
|
|
|
column['tensor'][options.defgrad]+9],
|
|
|
|
(grid[0],grid[1],grid[2],3,3))
|
|
|
|
for z in xrange(grid[2]):
|
|
|
|
for y in xrange(grid[1]):
|
|
|
|
for x in xrange(grid[0]):
|
|
|
|
F2[x,y,z,:,:] = F2[x,y,z,:,:].T
|
|
|
|
centroids2 = deformedCoordsFFT(dim,F2,options.scaling,None)
|
2015-04-09 00:18:35 +05:30
|
|
|
centroids = damask.core.mesh.deformedCoordsFFT(dim,F,Favg,options.scaling)
|
2016-03-24 15:07:15 +05:30
|
|
|
|
2015-04-09 00:18:35 +05:30
|
|
|
nodes = damask.core.mesh.nodesAroundCentres(dim,Favg,centroids)
|
2012-01-20 02:12:50 +05:30
|
|
|
|
2011-05-22 03:13:40 +05:30
|
|
|
fields = {\
|
|
|
|
'tensor': {},\
|
|
|
|
'vector': {},\
|
|
|
|
'scalar': {},\
|
2012-06-19 21:00:16 +05:30
|
|
|
'double': {},\
|
|
|
|
'triple': {},\
|
|
|
|
'quadruple': {},\
|
2011-05-22 03:13:40 +05:30
|
|
|
}
|
|
|
|
reshape = {\
|
2012-01-20 02:12:50 +05:30
|
|
|
'tensor': [3,3],\
|
|
|
|
'vector': [3],\
|
|
|
|
'scalar': [],\
|
2012-06-19 21:00:16 +05:30
|
|
|
'double': [2],\
|
|
|
|
'triple': [3],\
|
|
|
|
'quadruple': [4],\
|
2011-05-22 03:13:40 +05:30
|
|
|
}
|
|
|
|
length = {\
|
|
|
|
'tensor': 9,\
|
|
|
|
'vector': 3,\
|
|
|
|
'scalar': 1,\
|
2012-06-19 21:00:16 +05:30
|
|
|
'double': 2,\
|
|
|
|
'triple': 3,\
|
|
|
|
'quadruple': 4,\
|
2011-05-22 03:13:40 +05:30
|
|
|
}
|
|
|
|
|
2014-10-14 12:43:13 +05:30
|
|
|
|
2014-12-19 03:16:38 +05:30
|
|
|
# vtk lib out
|
|
|
|
if False:
|
|
|
|
points = vtk.vtkPoints()
|
|
|
|
for z in range (grid[2]+1):
|
|
|
|
for y in range (grid[1]+1):
|
|
|
|
for x in range (grid[0]+1):
|
|
|
|
points.InsertNextPoint(nodes[:,x,y,z])
|
|
|
|
|
|
|
|
data=[]
|
|
|
|
j=0
|
|
|
|
for datatype in fields.keys():
|
|
|
|
for what in eval('options.'+datatype):
|
|
|
|
for label in matches[datatype][what]:
|
|
|
|
col = column[datatype][label]
|
|
|
|
if col != -1:
|
|
|
|
data.append(vtk.vtkFloatArray())
|
|
|
|
data[j].SetNumberOfComponents(length[datatype])
|
|
|
|
for i in xrange(grid[2]*grid[1]*grid[0]):
|
|
|
|
for k in xrange(length[datatype]):
|
|
|
|
data[j].InsertNextValue(values2[i,col+k])
|
|
|
|
data[j].SetName(label)
|
|
|
|
j+=1
|
|
|
|
|
|
|
|
if options.output_mesh:
|
|
|
|
hexs = vtk.vtkCellArray()
|
|
|
|
i = 0
|
|
|
|
elems=[]
|
|
|
|
for z in range (grid[2]):
|
|
|
|
for y in range (grid[1]):
|
|
|
|
for x in range (grid[0]):
|
|
|
|
|
|
|
|
elems.append(vtk.vtkHexahedron())
|
|
|
|
base = z*(grid[1]+1)*(grid[0]+1)+y*(grid[0]+1)+x
|
|
|
|
elems[i].GetPointIds().SetId(0, base)
|
|
|
|
elems[i].GetPointIds().SetId(1, base+1)
|
|
|
|
elems[i].GetPointIds().SetId(2, base+grid[0]+2)
|
|
|
|
elems[i].GetPointIds().SetId(3, base+grid[0]+1)
|
|
|
|
elems[i].GetPointIds().SetId(4, base+(grid[1]+1)*(grid[0]+1))
|
|
|
|
elems[i].GetPointIds().SetId(5, base+(grid[1]+1)*(grid[0]+1)+1)
|
|
|
|
elems[i].GetPointIds().SetId(6, base+(grid[1]+1)*(grid[0]+1)+grid[0]+2)
|
|
|
|
elems[i].GetPointIds().SetId(7, base+(grid[1]+1)*(grid[0]+1)+grid[0]+1)
|
|
|
|
hexs.InsertNextCell(elems[i])
|
|
|
|
i+=1
|
|
|
|
|
|
|
|
uGrid = vtk.vtkUnstructuredGrid()
|
|
|
|
uGrid.SetPoints(points)
|
|
|
|
i = 0
|
|
|
|
for z in range (grid[2]):
|
|
|
|
for y in range (grid[1]):
|
|
|
|
for x in range (grid[0]):
|
|
|
|
uGrid.InsertNextCell(elems[i].GetCellType(), elems[i].GetPointIds())
|
|
|
|
i+=1
|
|
|
|
|
|
|
|
for i in xrange(len(data)):
|
|
|
|
uGrid.GetCellData().AddArray(data[i])
|
|
|
|
|
|
|
|
outWriter = vtk.vtkXMLUnstructuredGridWriter()
|
|
|
|
outWriter.SetDataModeToBinary()
|
|
|
|
outWriter.SetCompressorTypeToZLib()
|
|
|
|
(head,tail) = os.path.split(filename)
|
|
|
|
outWriter.SetFileName(os.path.join(head,'mesh_'+os.path.splitext(tail)[0]+'.vtu'))
|
|
|
|
outWriter.SetInput(uGrid)
|
|
|
|
outWriter.Write()
|
2014-10-14 12:43:13 +05:30
|
|
|
|
2014-12-19 03:16:38 +05:30
|
|
|
|
2011-05-22 03:13:40 +05:30
|
|
|
for datatype in fields.keys():
|
|
|
|
print '\n%s:'%datatype,
|
2013-05-29 15:54:00 +05:30
|
|
|
fields[datatype]['_order_'] = []
|
2013-02-15 03:03:11 +05:30
|
|
|
for what in eval('options.'+datatype):
|
2013-05-29 15:54:00 +05:30
|
|
|
for label in matches[datatype][what]:
|
|
|
|
col = column[datatype][label]
|
|
|
|
if col != -1:
|
|
|
|
print label,
|
2014-07-09 15:37:24 +05:30
|
|
|
fields[datatype][label] = np.reshape(values[:,col:col+length[datatype]],[grid[0],grid[1],grid[2]]+reshape[datatype])
|
2013-05-29 15:54:00 +05:30
|
|
|
fields[datatype]['_order_'] += [label]
|
2011-05-26 15:14:10 +05:30
|
|
|
print '\n'
|
2011-02-01 16:18:44 +05:30
|
|
|
|
|
|
|
out = {}
|
2013-06-27 23:51:20 +05:30
|
|
|
if options.output_mesh: out['mesh'] = vtk_writeASCII_mesh(nodes,fields,grid,sep[options.separator])
|
|
|
|
if options.output_points: out['points'] = vtk_writeASCII_points(centroids,fields,grid,sep[options.separator])
|
2011-02-01 16:18:44 +05:30
|
|
|
|
|
|
|
for what in out.keys():
|
2011-05-22 03:13:40 +05:30
|
|
|
print what
|
2011-05-26 15:14:10 +05:30
|
|
|
(head,tail) = os.path.split(filename)
|
2013-02-15 03:03:11 +05:30
|
|
|
vtk = open(os.path.join(head,what+'_'+os.path.splitext(tail)[0]+'.vtk'), 'w')
|
2011-02-01 16:18:44 +05:30
|
|
|
output(out[what],{'filepointer':vtk},'File')
|
|
|
|
vtk.close()
|
2016-03-24 15:07:15 +05:30
|
|
|
print
|