simpliefied scripts for vtk generation and introduce simple test to check if they run
This commit is contained in:
parent
851d2e1b2c
commit
6d74cbf374
|
@ -1,7 +1,7 @@
|
||||||
#!/usr/bin/env python
|
#!/usr/bin/env python
|
||||||
# -*- coding: UTF-8 no BOM -*-
|
# -*- coding: UTF-8 no BOM -*-
|
||||||
|
|
||||||
import os,sys,string,re,vtk
|
import os,sys,string,vtk
|
||||||
import numpy as np
|
import numpy as np
|
||||||
from optparse import OptionParser
|
from optparse import OptionParser
|
||||||
import damask
|
import damask
|
||||||
|
@ -37,14 +37,14 @@ for name in filenames:
|
||||||
table = damask.ASCIItable(name = name,
|
table = damask.ASCIItable(name = name,
|
||||||
buffered = False, labeled = False, readonly = True)
|
buffered = False, labeled = False, readonly = True)
|
||||||
except: continue
|
except: continue
|
||||||
table.croak('\033[1m'+scriptName+'\033[0m'+(': '+name if name else ''))
|
damask.util.report(scriptName,name)
|
||||||
|
|
||||||
# --- interpret header ----------------------------------------------------------------------------
|
# --- interpret header ----------------------------------------------------------------------------
|
||||||
|
|
||||||
table.head_read()
|
table.head_read()
|
||||||
info,extra_header = table.head_getGeom()
|
info,extra_header = table.head_getGeom()
|
||||||
|
|
||||||
table.croak(['grid a b c: %s'%(' x '.join(map(str,info['grid']))),
|
damask.util.croak(['grid a b c: %s'%(' x '.join(map(str,info['grid']))),
|
||||||
'size x y z: %s'%(' x '.join(map(str,info['size']))),
|
'size x y z: %s'%(' x '.join(map(str,info['size']))),
|
||||||
'origin x y z: %s'%(' : '.join(map(str,info['origin']))),
|
'origin x y z: %s'%(' : '.join(map(str,info['origin']))),
|
||||||
'homogenization: %i'%info['homogenization'],
|
'homogenization: %i'%info['homogenization'],
|
||||||
|
@ -55,7 +55,7 @@ for name in filenames:
|
||||||
if np.any(info['grid'] < 1): errors.append('invalid grid a b c.')
|
if np.any(info['grid'] < 1): errors.append('invalid grid a b c.')
|
||||||
if np.any(info['size'] <= 0.0): errors.append('invalid size x y z.')
|
if np.any(info['size'] <= 0.0): errors.append('invalid size x y z.')
|
||||||
if errors != []:
|
if errors != []:
|
||||||
table.croak(errors)
|
damask.util.croak(errors)
|
||||||
table.close(dismiss = True)
|
table.close(dismiss = True)
|
||||||
continue
|
continue
|
||||||
|
|
||||||
|
@ -86,25 +86,21 @@ for name in filenames:
|
||||||
grid.GetCellData().AddArray(structure)
|
grid.GetCellData().AddArray(structure)
|
||||||
|
|
||||||
# --- write data -----------------------------------------------------------------------------------
|
# --- write data -----------------------------------------------------------------------------------
|
||||||
|
|
||||||
if name:
|
if name:
|
||||||
(dir,filename) = os.path.split(name)
|
|
||||||
writer = vtk.vtkXMLRectilinearGridWriter()
|
writer = vtk.vtkXMLRectilinearGridWriter()
|
||||||
|
(head,tail) = os.path.split(name)
|
||||||
writer.SetDataModeToBinary()
|
writer.SetDataModeToBinary()
|
||||||
writer.SetCompressorTypeToZLib()
|
writer.SetCompressorTypeToZLib()
|
||||||
writer.SetFileName(os.path.join(dir,'mesh_'+os.path.splitext(filename)[0]
|
writer.SetFileName(os.path.join(head,'mesh_'+os.path.splitext(tail)[0]
|
||||||
+'.'+writer.GetDefaultFileExtension()))
|
+'.'+writer.GetDefaultFileExtension()))
|
||||||
if vtk.VTK_MAJOR_VERSION <= 5: writer.SetInput(grid)
|
|
||||||
else: writer.SetInputData(grid)
|
|
||||||
writer.Write()
|
|
||||||
else:
|
else:
|
||||||
writer = vtk.vtkRectilinearGridWriter()
|
writer = vtk.vtkDataSetWriter()
|
||||||
writer.WriteToOutputStringOn()
|
writer.WriteToOutputStringOn()
|
||||||
writer.SetFileTypeToASCII()
|
|
||||||
writer.SetHeader('# powered by '+scriptID)
|
writer.SetHeader('# powered by '+scriptID)
|
||||||
if vtk.VTK_MAJOR_VERSION <= 5: writer.SetInput(grid)
|
|
||||||
else: writer.SetInputData(grid)
|
if vtk.VTK_MAJOR_VERSION <= 5: writer.SetInput(grid)
|
||||||
writer.Write()
|
else: writer.SetInputData(grid)
|
||||||
sys.stdout.write(writer.GetOutputString()[0:writer.GetOutputStringLength()])
|
writer.Write()
|
||||||
|
if name == None: sys.stdout.write(writer.GetOutputString()[0:writer.GetOutputStringLength()])
|
||||||
|
|
||||||
table.close()
|
table.close()
|
||||||
|
|
|
@ -41,14 +41,14 @@ for name in filenames:
|
||||||
table = damask.ASCIItable(name = name,
|
table = damask.ASCIItable(name = name,
|
||||||
buffered = False, readonly = True)
|
buffered = False, readonly = True)
|
||||||
except: continue
|
except: continue
|
||||||
table.croak('\033[1m'+scriptName+'\033[0m'+(': '+name if name else ''))
|
damask.util.report(scriptName,name)
|
||||||
|
|
||||||
# --- interpret header ----------------------------------------------------------------------------
|
# --- interpret header ----------------------------------------------------------------------------
|
||||||
|
|
||||||
table.head_read()
|
table.head_read()
|
||||||
info,extra_header = table.head_getGeom()
|
info,extra_header = table.head_getGeom()
|
||||||
|
|
||||||
table.croak(['grid a b c: %s'%(' x '.join(map(str,info['grid']))),
|
damask.util.croak(['grid a b c: %s'%(' x '.join(map(str,info['grid']))),
|
||||||
'size x y z: %s'%(' x '.join(map(str,info['size']))),
|
'size x y z: %s'%(' x '.join(map(str,info['size']))),
|
||||||
'origin x y z: %s'%(' : '.join(map(str,info['origin']))),
|
'origin x y z: %s'%(' : '.join(map(str,info['origin']))),
|
||||||
'homogenization: %i'%info['homogenization'],
|
'homogenization: %i'%info['homogenization'],
|
||||||
|
@ -68,9 +68,9 @@ for name in filenames:
|
||||||
remarks.append('rescaling size {} to {}...'.format({0:'x',1:'y',2:'z'}[i],info['size'][i]))
|
remarks.append('rescaling size {} to {}...'.format({0:'x',1:'y',2:'z'}[i],info['size'][i]))
|
||||||
if table.label_dimension(options.position) != 3: errors.append('columns "{}" have dimension {}'.format(options.position,
|
if table.label_dimension(options.position) != 3: errors.append('columns "{}" have dimension {}'.format(options.position,
|
||||||
table.label_dimension(options.position)))
|
table.label_dimension(options.position)))
|
||||||
if remarks != []: table.croak(remarks)
|
if remarks != []: damask.util.croak(remarks)
|
||||||
if errors != []:
|
if errors != []:
|
||||||
table.croak(errors)
|
damask.util.croak(errors)
|
||||||
table.close(dismiss=True)
|
table.close(dismiss=True)
|
||||||
continue
|
continue
|
||||||
|
|
||||||
|
@ -104,26 +104,23 @@ for name in filenames:
|
||||||
grid.SetPoints(pts)
|
grid.SetPoints(pts)
|
||||||
grid.GetCellData().AddArray(IDs)
|
grid.GetCellData().AddArray(IDs)
|
||||||
|
|
||||||
# --- write data -----------------------------------------------------------------------------------
|
#--- write data -----------------------------------------------------------------------------------
|
||||||
|
|
||||||
if name:
|
if name:
|
||||||
(dir,filename) = os.path.split(name)
|
writer = vtk.vtkXMLRectilinearGridWriter()
|
||||||
writer = vtk.vtkXMLUnstructuredGridWriter()
|
(head,tail) = os.path.split(name)
|
||||||
writer.SetDataModeToBinary()
|
writer.SetDataModeToBinary()
|
||||||
writer.SetCompressorTypeToZLib()
|
writer.SetCompressorTypeToZLib()
|
||||||
writer.SetFileName(os.path.join(dir,'seeds_'+os.path.splitext(filename)[0]
|
writer.SetFileName(os.path.join(head,'mesh_'+os.path.splitext(tail)[0]
|
||||||
+'.'+writer.GetDefaultFileExtension()))
|
+'.'+writer.GetDefaultFileExtension()))
|
||||||
if vtk.VTK_MAJOR_VERSION <= 5: writer.SetInput(grid)
|
|
||||||
else: writer.SetInputData(grid)
|
|
||||||
writer.Write()
|
|
||||||
else:
|
else:
|
||||||
writer = vtk.vtkUnstructuredGridWriter()
|
writer = vtk.vtkDataSetWriter()
|
||||||
writer.WriteToOutputStringOn()
|
writer.WriteToOutputStringOn()
|
||||||
writer.SetFileTypeToASCII()
|
|
||||||
writer.SetHeader('# powered by '+scriptID)
|
writer.SetHeader('# powered by '+scriptID)
|
||||||
if vtk.VTK_MAJOR_VERSION <= 5: writer.SetInput(grid)
|
|
||||||
else: writer.SetInputData(grid)
|
if vtk.VTK_MAJOR_VERSION <= 5: writer.SetInput(grid)
|
||||||
writer.Write()
|
else: writer.SetInputData(grid)
|
||||||
sys.stdout.write(writer.GetOutputString()[0:writer.GetOutputStringLength()])
|
writer.Write()
|
||||||
|
if name == None: sys.stdout.write(writer.GetOutputString()[0:writer.GetOutputStringLength()])
|
||||||
|
|
||||||
table.close()
|
table.close()
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue