handling of seeds files without microstructure (but eulerangles)

This commit is contained in:
Martin Diehl 2015-04-10 16:59:08 +00:00
parent 09bfd1e18e
commit 4aa63e1ab9
1 changed files with 30 additions and 26 deletions

View File

@ -30,12 +30,9 @@ Produce VTK point mesh from seeds file
""", version = scriptID)
parser.add_option('-g', '--grid', dest='grid', type='int', nargs = 3, metavar='int int int', \
help='a,b,c grid of hexahedral box [from seeds file]')
parser.add_option('-s', '--size', dest='size', type='float', nargs = 3, metavar='float float float',\
help='x,y,z size of hexahedral box [1.0 along largest grid point number]')
parser.set_defaults(grid = [0,0,0])
parser.set_defaults(size = [0.0,0.0,0.0])
(options, filenames) = parser.parse_args()
@ -61,17 +58,32 @@ else:
for file in files:
file['croak'].write('\033[1m' + scriptName + '\033[0m: ' + (file['name'] if file['name'] != 'STDIN' else '') + '\n')
theTable = damask.ASCIItable(file['input'],file['output'])
theTable.head_read()
table = damask.ASCIItable(file['input'],file['output'])
table.head_read()
labels = ['x','y','z']
grainCol = table.labels_index('microstructure')
hasGrains = grainCol != -1
if hasGrains:
labels += ['microstructure']
table.data_readArray(labels)
coords = table.data[:,0:3]
grain = table.data[:,grainCol] if hasGrains else 1+np.arange(len(coords))
grainIDs = np.unique(grain).astype('i')
#--- interpret header ----------------------------------------------------------------------------
info = {
'grid': np.zeros(3,'i'),
'size': np.zeros(3,'d'),
'size': np.array(options.size),
'origin': np.zeros(3,'d'),
'microstructures': 0,
}
for header in theTable.info:
for header in table.info:
headitems = map(str.lower,header.split())
if len(headitems) == 0: continue
if headitems[0] in mappings.keys():
@ -82,26 +94,18 @@ for file in files:
else:
info[headitems[0]] = mappings[headitems[0]](headitems[1])
file['croak'].write('grid a b c: %s\n'%(' x '.join(map(str,info['grid']))) + \
'size x y z: %s\n'%(' x '.join(map(str,info['size']))) + \
'origin x y z: %s\n'%(' : '.join(map(str,info['origin']))))
if 0 not in options.grid: # user-specified grid
info['grid'] = np.array(options.grid)
if info['microstructures'] != len(grainIDs):
file['croak'].write('grain data not matching grain count (%i)...\n'%(len(grainIDs)))
info['microstructures'] = len(grainIDs)
if np.any(info['grid'] < 1):
file['croak'].write('invalid grid a b c.\n')
# continue
continue
for i in xrange(3):
if info['size'][i] <= 0.0: # any invalid size?
info['size'][i] = float(info['grid'][i])/max(info['grid'])
file['croak'].write('rescaling size %s...\n'%{0:'x',1:'y',2:'z'}[i])
#--- read data --------------------------------------------------------------------------------
theTable.data_readArray(['x','y','z','microstructure'])
theTable.data[:,0:3] *= info['size']
theTable.data[:,0:3] += info['origin']
#--- generate grid --------------------------------------------------------------------------------
grid = vtk.vtkUnstructuredGrid()
pts = vtk.vtkPoints()
@ -111,12 +115,12 @@ for file in files:
IDs.SetNumberOfComponents(1)
IDs.SetName("GrainID")
for item in theTable.data:
for i,item in enumerate(coords):
pid = pts.InsertNextPoint(item[0:3])
pointIds = vtk.vtkIdList()
pointIds.InsertId(0, pid)
grid.InsertNextCell(1, pointIds)
IDs.InsertNextValue(int(item[3]))
IDs.InsertNextValue(grainIDs[i])
grid.SetPoints(pts)
grid.GetCellData().AddArray(IDs)