worked on the vtk binary out, still some problems with multicomponent datatypes
This commit is contained in:
parent
6604d0f8e8
commit
5e8fff13d9
|
@ -10,45 +10,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] == '(!)':
|
||||||
exec(cmd[3:])
|
exec(cmd[3:])
|
||||||
|
@ -151,75 +112,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):
|
||||||
# +++++++++++++++++++++++++++++++++++++++++++++++++++
|
# +++++++++++++++++++++++++++++++++++++++++++++++++++
|
||||||
|
@ -252,8 +144,6 @@ def vtk_writeASCII_points(coordinates,data,res,sep):
|
||||||
return cmds
|
return cmds
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
# ----------------------- MAIN -------------------------------
|
# ----------------------- MAIN -------------------------------
|
||||||
|
|
||||||
parser = OptionParser(option_class=damask.extendableOption, usage='%prog [options] datafile[s]', description = """
|
parser = OptionParser(option_class=damask.extendableOption, usage='%prog [options] datafile[s]', description = """
|
||||||
|
@ -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):
|
||||||
|
@ -404,6 +294,7 @@ 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)
|
||||||
|
|
||||||
|
@ -486,65 +377,70 @@ 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()
|
data=[]
|
||||||
#i = 0
|
j=0
|
||||||
#elems=[]
|
for datatype in fields.keys():
|
||||||
#for z in range (grid[2]):
|
for what in eval('options.'+datatype):
|
||||||
# for y in range (grid[1]):
|
for label in matches[datatype][what]:
|
||||||
# for x in range (grid[0]):
|
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
|
||||||
|
|
||||||
# elems.append(vtk.vtkHexahedron())
|
if options.output_mesh:
|
||||||
# base = z*(grid[1]+1)*(grid[0]+1)+y*(grid[0]+1)+x
|
hexs = vtk.vtkCellArray()
|
||||||
# elems[i].GetPointIds().SetId(0, base)
|
i = 0
|
||||||
# elems[i].GetPointIds().SetId(1, base+1)
|
elems=[]
|
||||||
# elems[i].GetPointIds().SetId(2, base+grid[0]+2)
|
for z in range (grid[2]):
|
||||||
# elems[i].GetPointIds().SetId(3, base+grid[0]+1)
|
for y in range (grid[1]):
|
||||||
# elems[i].GetPointIds().SetId(4, base+(grid[1]+1)*(grid[0]+1))
|
for x in range (grid[0]):
|
||||||
# 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()
|
elems.append(vtk.vtkHexahedron())
|
||||||
#uGrid.SetPoints(points)
|
base = z*(grid[1]+1)*(grid[0]+1)+y*(grid[0]+1)+x
|
||||||
#i = 0
|
elems[i].GetPointIds().SetId(0, base)
|
||||||
#for z in range (grid[2]):
|
elems[i].GetPointIds().SetId(1, base+1)
|
||||||
# for y in range (grid[1]):
|
elems[i].GetPointIds().SetId(2, base+grid[0]+2)
|
||||||
# for x in range (grid[0]):
|
elems[i].GetPointIds().SetId(3, base+grid[0]+1)
|
||||||
# uGrid.InsertNextCell(elems[i].GetCellType(), elems[i].GetPointIds())
|
elems[i].GetPointIds().SetId(4, base+(grid[1]+1)*(grid[0]+1))
|
||||||
# i+=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
|
||||||
|
|
||||||
#data=[]
|
uGrid = vtk.vtkUnstructuredGrid()
|
||||||
#j=0
|
uGrid.SetPoints(points)
|
||||||
#for datatype in fields.keys():
|
i = 0
|
||||||
# for what in eval('options.'+datatype):
|
for z in range (grid[2]):
|
||||||
# for label in matches[datatype][what]:
|
for y in range (grid[1]):
|
||||||
# col = column[datatype][label]
|
for x in range (grid[0]):
|
||||||
# if col != -1:
|
uGrid.InsertNextCell(elems[i].GetCellType(), elems[i].GetPointIds())
|
||||||
# data.append(vtk.vtkFloatArray())
|
i+=1
|
||||||
# data[j].SetNumberOfComponents(1) #this is for scalar only so far
|
|
||||||
# for i in xrange(grid[0]*grid[1]*grid[2]):
|
|
||||||
# data[j].InsertNextValue(values[i,col:col+length[datatype]])
|
|
||||||
# data[j].SetName(label)
|
|
||||||
# j+=1
|
|
||||||
|
|
||||||
#for i in xrange(len(data)):
|
for i in xrange(len(data)):
|
||||||
# uGrid.GetCellData().AddArray(data[i])
|
uGrid.GetCellData().AddArray(data[i])
|
||||||
|
|
||||||
#outWriter = vtk.vtkXMLUnstructuredGridWriter()
|
outWriter = vtk.vtkXMLUnstructuredGridWriter()
|
||||||
#outWriter.SetDataModeToBinary()
|
outWriter.SetDataModeToBinary()
|
||||||
#outWriter.SetCompressorTypeToZLib()
|
outWriter.SetCompressorTypeToZLib()
|
||||||
#outWriter.SetFileName(os.path.splitext(filename)[0]+'.vtu')
|
(head,tail) = os.path.split(filename)
|
||||||
#outWriter.SetInput(uGrid)
|
outWriter.SetFileName(os.path.join(head,'mesh_'+os.path.splitext(tail)[0]+'.vtu'))
|
||||||
#outWriter.Write()
|
outWriter.SetInput(uGrid)
|
||||||
|
outWriter.Write()
|
||||||
|
|
||||||
|
|
||||||
for datatype in fields.keys():
|
for datatype in fields.keys():
|
||||||
|
|
Loading…
Reference in New Issue