worked on the vtk binary out, still some problems with multicomponent datatypes

This commit is contained in:
Martin Diehl 2014-12-18 21:46:38 +00:00
parent 6604d0f8e8
commit 5e8fff13d9
1 changed files with 70 additions and 174 deletions

View File

@ -9,45 +9,6 @@ import damask
scriptID = string.replace('$Id$','\n','\\n') scriptID = string.replace('$Id$','\n','\\n')
scriptName = os.path.splitext(scriptID.split()[1])[0] scriptName = os.path.splitext(scriptID.split()[1])[0]
# -----------------------------
class backgroundMessage(threading.Thread):
# -----------------------------
def __init__(self):
threading.Thread.__init__(self)
self.message = ''
self.new_message = ''
self.counter = 0
self.symbols = ['- ', '\ ', '| ', '/ ']
self.waittime = 0.5
def __quit__(self):
length = len(self.message) + len(self.symbols[self.counter])
sys.stderr.write(chr(8)*length + ' '*length + chr(8)*length)
sys.stderr.write('')
def run(self):
while not threading.enumerate()[0]._Thread__stopped:
time.sleep(self.waittime)
self.update_message()
self.__quit__()
def set_message(self, new_message):
self.new_message = new_message
self.print_message()
def print_message(self):
length = len(self.message) + len(self.symbols[self.counter])
sys.stderr.write(chr(8)*length + ' '*length + chr(8)*length) # delete former message
sys.stderr.write(self.symbols[self.counter] + self.new_message) # print new message
self.message = self.new_message
def update_message(self):
self.counter = (self.counter + 1)%len(self.symbols)
self.print_message()
def outStdout(cmd,locals): def outStdout(cmd,locals):
if cmd[0:3] == '(!)': if cmd[0:3] == '(!)':
@ -150,75 +111,6 @@ def vtk_writeASCII_mesh(mesh,data,res,sep):
] ]
return cmds return cmds
# ++++++++++++++++++++++++++++++++++++++++++++++++++++
def gmsh_writeASCII_mesh(mesh,data,res,sep):
# ++++++++++++++++++++++++++++++++++++++++++++++++++++
""" function writes data array defined on a hexahedral mesh (geometry) """
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},\
}
N1 = (res[0]+1)*(res[1]+1)*(res[2]+1)
N = res[0]*res[1]*res[2]
cmds = [\
'$MeshFormat',
'2.1 0 8',
'$EndMeshFormat',
'$Nodes',
'%i float'%N1,
[[['\t'.join(map(str,l,mesh[:,i,j,k])) for l in range(1,N1+1) for i in range(res[0]+1)] for j in range(res[1]+1)] for k in range(res[2]+1)],
'$EndNodes',
'$Elements',
'%i'%N,
]
# cells
n_elem = 0
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
n_elem +=1
cmds.append('\t'.join(map(str,[ \
n_elem,
'5',
base,
base+1,
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,
])))
cmds += [\
'ElementData',
'1',
'%s'%item, # name of the view
'0.0', # thats the time value
'3',
'0', # time step
'1',
'%i'%N
]
for type in data:
plural = {True:'',False:'S'}[type.lower().endswith('s')]
for item in data[type]['_order_']:
cmds += [\
'%s %s float %i'%(info[type]['name'].upper()+plural,item,info[type]['len']),
'LOOKUP_TABLE default',
[[[sep.join(map(str,data[type][item][:,j,k]))] for j in range(res[1])] for k in range(res[2])],
]
return cmds
# +++++++++++++++++++++++++++++++++++++++++++++++++++ # +++++++++++++++++++++++++++++++++++++++++++++++++++
def vtk_writeASCII_points(coordinates,data,res,sep): def vtk_writeASCII_points(coordinates,data,res,sep):
@ -250,8 +142,6 @@ def vtk_writeASCII_points(coordinates,data,res,sep):
] ]
return cmds return cmds
# ----------------------- MAIN ------------------------------- # ----------------------- MAIN -------------------------------
@ -377,7 +267,7 @@ for filename in args:
continue continue
column['vector'] = {} column['vector'] = {}
matches['tensor'] = {} matches['vector'] = {}
for label in options.vector: for label in options.vector:
column['vector'][label] = -1 column['vector'][label] = -1
for col,head in enumerate(headings): for col,head in enumerate(headings):
@ -403,7 +293,8 @@ for filename in args:
values = np.array(sorted([map(transliterateToFloat,line.split()[:maxcol]) for line in content[headrow+1:]], values = np.array(sorted([map(transliterateToFloat,line.split()[:maxcol]) for line in content[headrow+1:]],
key=lambda x:(x[locol+0],x[locol+1],x[locol+2])),'d') # sort with z as fastest and x as slowest index 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
N = len(values) N = len(values)
@ -413,8 +304,8 @@ for filename in args:
tempGrid[j][str(values[i,locol+j])] = True tempGrid[j][str(values[i,locol+j])] = True
grid = np.array([len(tempGrid[0]),\ grid = np.array([len(tempGrid[0]),\
len(tempGrid[1]),\ len(tempGrid[1]),\
len(tempGrid[2]),],'i') len(tempGrid[2]),],'i')
dim = np.ones(3) dim = np.ones(3)
@ -436,7 +327,7 @@ for filename in args:
(3,3,grid[0],grid[1],grid[2]))) (3,3,grid[0],grid[1],grid[2])))
if not options.filenodalcoords: if not options.filenodalcoords:
F = np.reshape(np.transpose(values[:,column['tensor'][options.defgrad]: F = np.reshape(np.transpose(values[:,column['tensor'][options.defgrad]:
column['tensor'][options.defgrad]+9]), column['tensor'][options.defgrad]+9]),
(3,3,grid[0],grid[1],grid[2])) (3,3,grid[0],grid[1],grid[2]))
if options.linearreconstruction: if options.linearreconstruction:
centroids = damask.core.mesh.deformedCoordsLinear(dim,F,Favg) centroids = damask.core.mesh.deformedCoordsLinear(dim,F,Favg)
@ -486,67 +377,72 @@ for filename in args:
'quadruple': 4,\ 'quadruple': 4,\
} }
# vtk lib out # vtk lib out
#points = vtk.vtkPoints() if False:
#for z in range (grid[2]+1): points = vtk.vtkPoints()
# for y in range (grid[1]+1): for z in range (grid[2]+1):
# for x in range (grid[0]+1): for y in range (grid[1]+1):
# points.InsertNextPoint(nodes[:,x,y,z]) for x in range (grid[0]+1):
points.InsertNextPoint(nodes[:,x,y,z])
#hexs = vtk.vtkCellArray()
#i = 0 data=[]
#elems=[] j=0
#for z in range (grid[2]): for datatype in fields.keys():
# for y in range (grid[1]): for what in eval('options.'+datatype):
# for x in range (grid[0]): for label in matches[datatype][what]:
col = column[datatype][label]
# elems.append(vtk.vtkHexahedron()) if col != -1:
# base = z*(grid[1]+1)*(grid[0]+1)+y*(grid[0]+1)+x data.append(vtk.vtkFloatArray())
# elems[i].GetPointIds().SetId(0, base) data[j].SetNumberOfComponents(length[datatype])
# elems[i].GetPointIds().SetId(1, base+1) for i in xrange(grid[2]*grid[1]*grid[0]):
# elems[i].GetPointIds().SetId(2, base+grid[0]+2) for k in xrange(length[datatype]):
# elems[i].GetPointIds().SetId(3, base+grid[0]+1) data[j].InsertNextValue(values2[i,col+k])
# elems[i].GetPointIds().SetId(4, base+(grid[1]+1)*(grid[0]+1)) data[j].SetName(label)
# elems[i].GetPointIds().SetId(5, base+(grid[1]+1)*(grid[0]+1)+1) j+=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) if options.output_mesh:
# hexs.InsertNextCell(elems[i]) hexs = vtk.vtkCellArray()
# i+=1 i = 0
elems=[]
#uGrid = vtk.vtkUnstructuredGrid() for z in range (grid[2]):
#uGrid.SetPoints(points) for y in range (grid[1]):
#i = 0 for x in range (grid[0]):
#for z in range (grid[2]):
# for y in range (grid[1]): elems.append(vtk.vtkHexahedron())
# for x in range (grid[0]): base = z*(grid[1]+1)*(grid[0]+1)+y*(grid[0]+1)+x
# uGrid.InsertNextCell(elems[i].GetCellType(), elems[i].GetPointIds()) elems[i].GetPointIds().SetId(0, base)
# i+=1 elems[i].GetPointIds().SetId(1, base+1)
elems[i].GetPointIds().SetId(2, base+grid[0]+2)
#data=[] elems[i].GetPointIds().SetId(3, base+grid[0]+1)
#j=0 elems[i].GetPointIds().SetId(4, base+(grid[1]+1)*(grid[0]+1))
#for datatype in fields.keys(): elems[i].GetPointIds().SetId(5, base+(grid[1]+1)*(grid[0]+1)+1)
# for what in eval('options.'+datatype): elems[i].GetPointIds().SetId(6, base+(grid[1]+1)*(grid[0]+1)+grid[0]+2)
# for label in matches[datatype][what]: elems[i].GetPointIds().SetId(7, base+(grid[1]+1)*(grid[0]+1)+grid[0]+1)
# col = column[datatype][label] hexs.InsertNextCell(elems[i])
# if col != -1: i+=1
# data.append(vtk.vtkFloatArray())
# data[j].SetNumberOfComponents(1) #this is for scalar only so far uGrid = vtk.vtkUnstructuredGrid()
# for i in xrange(grid[0]*grid[1]*grid[2]): uGrid.SetPoints(points)
# data[j].InsertNextValue(values[i,col:col+length[datatype]]) i = 0
# data[j].SetName(label) for z in range (grid[2]):
# j+=1 for y in range (grid[1]):
for x in range (grid[0]):
#for i in xrange(len(data)): uGrid.InsertNextCell(elems[i].GetCellType(), elems[i].GetPointIds())
# uGrid.GetCellData().AddArray(data[i]) i+=1
#outWriter = vtk.vtkXMLUnstructuredGridWriter() for i in xrange(len(data)):
#outWriter.SetDataModeToBinary() uGrid.GetCellData().AddArray(data[i])
#outWriter.SetCompressorTypeToZLib()
#outWriter.SetFileName(os.path.splitext(filename)[0]+'.vtu') outWriter = vtk.vtkXMLUnstructuredGridWriter()
#outWriter.SetInput(uGrid) outWriter.SetDataModeToBinary()
#outWriter.Write() 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()
for datatype in fields.keys(): for datatype in fields.keys():
print '\n%s:'%datatype, print '\n%s:'%datatype,
fields[datatype]['_order_'] = [] fields[datatype]['_order_'] = []