handling of seeds files without microstructure (but eulerangles)
This commit is contained in:
parent
09bfd1e18e
commit
4aa63e1ab9
|
@ -13,9 +13,9 @@ scriptName = os.path.splitext(scriptID.split()[1])[0]
|
||||||
# MAIN
|
# MAIN
|
||||||
#--------------------------------------------------------------------------------------------------
|
#--------------------------------------------------------------------------------------------------
|
||||||
identifiers = {
|
identifiers = {
|
||||||
'grid': ['a','b','c'],
|
'grid': ['a','b','c'],
|
||||||
'size': ['x','y','z'],
|
'size': ['x','y','z'],
|
||||||
'origin': ['x','y','z'],
|
'origin': ['x','y','z'],
|
||||||
}
|
}
|
||||||
mappings = {
|
mappings = {
|
||||||
'grid': lambda x: int(x),
|
'grid': lambda x: int(x),
|
||||||
|
@ -30,12 +30,9 @@ Produce VTK point mesh from seeds file
|
||||||
|
|
||||||
""", version = scriptID)
|
""", 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',\
|
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]')
|
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])
|
parser.set_defaults(size = [0.0,0.0,0.0])
|
||||||
|
|
||||||
(options, filenames) = parser.parse_args()
|
(options, filenames) = parser.parse_args()
|
||||||
|
@ -61,17 +58,32 @@ else:
|
||||||
for file in files:
|
for file in files:
|
||||||
file['croak'].write('\033[1m' + scriptName + '\033[0m: ' + (file['name'] if file['name'] != 'STDIN' else '') + '\n')
|
file['croak'].write('\033[1m' + scriptName + '\033[0m: ' + (file['name'] if file['name'] != 'STDIN' else '') + '\n')
|
||||||
|
|
||||||
theTable = damask.ASCIItable(file['input'],file['output'])
|
table = damask.ASCIItable(file['input'],file['output'])
|
||||||
theTable.head_read()
|
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 ----------------------------------------------------------------------------
|
#--- interpret header ----------------------------------------------------------------------------
|
||||||
info = {
|
info = {
|
||||||
'grid': np.zeros(3,'i'),
|
'grid': np.zeros(3,'i'),
|
||||||
'size': np.zeros(3,'d'),
|
'size': np.array(options.size),
|
||||||
'origin': np.zeros(3,'d'),
|
'origin': np.zeros(3,'d'),
|
||||||
|
'microstructures': 0,
|
||||||
}
|
}
|
||||||
|
|
||||||
for header in theTable.info:
|
for header in table.info:
|
||||||
headitems = map(str.lower,header.split())
|
headitems = map(str.lower,header.split())
|
||||||
if len(headitems) == 0: continue
|
if len(headitems) == 0: continue
|
||||||
if headitems[0] in mappings.keys():
|
if headitems[0] in mappings.keys():
|
||||||
|
@ -82,26 +94,18 @@ for file in files:
|
||||||
else:
|
else:
|
||||||
info[headitems[0]] = mappings[headitems[0]](headitems[1])
|
info[headitems[0]] = mappings[headitems[0]](headitems[1])
|
||||||
|
|
||||||
file['croak'].write('grid a b c: %s\n'%(' x '.join(map(str,info['grid']))) + \
|
if info['microstructures'] != len(grainIDs):
|
||||||
'size x y z: %s\n'%(' x '.join(map(str,info['size']))) + \
|
file['croak'].write('grain data not matching grain count (%i)...\n'%(len(grainIDs)))
|
||||||
'origin x y z: %s\n'%(' : '.join(map(str,info['origin']))))
|
info['microstructures'] = len(grainIDs)
|
||||||
if 0 not in options.grid: # user-specified grid
|
|
||||||
info['grid'] = np.array(options.grid)
|
|
||||||
if np.any(info['grid'] < 1):
|
if np.any(info['grid'] < 1):
|
||||||
file['croak'].write('invalid grid a b c.\n')
|
file['croak'].write('invalid grid a b c.\n')
|
||||||
# continue
|
continue
|
||||||
|
|
||||||
for i in xrange(3):
|
for i in xrange(3):
|
||||||
if info['size'][i] <= 0.0: # any invalid size?
|
if info['size'][i] <= 0.0: # any invalid size?
|
||||||
info['size'][i] = float(info['grid'][i])/max(info['grid'])
|
info['size'][i] = float(info['grid'][i])/max(info['grid'])
|
||||||
file['croak'].write('rescaling size %s...\n'%{0:'x',1:'y',2:'z'}[i])
|
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 --------------------------------------------------------------------------------
|
#--- generate grid --------------------------------------------------------------------------------
|
||||||
grid = vtk.vtkUnstructuredGrid()
|
grid = vtk.vtkUnstructuredGrid()
|
||||||
pts = vtk.vtkPoints()
|
pts = vtk.vtkPoints()
|
||||||
|
@ -111,12 +115,12 @@ for file in files:
|
||||||
IDs.SetNumberOfComponents(1)
|
IDs.SetNumberOfComponents(1)
|
||||||
IDs.SetName("GrainID")
|
IDs.SetName("GrainID")
|
||||||
|
|
||||||
for item in theTable.data:
|
for i,item in enumerate(coords):
|
||||||
pid = pts.InsertNextPoint(item[0:3])
|
pid = pts.InsertNextPoint(item[0:3])
|
||||||
pointIds = vtk.vtkIdList()
|
pointIds = vtk.vtkIdList()
|
||||||
pointIds.InsertId(0, pid)
|
pointIds.InsertId(0, pid)
|
||||||
grid.InsertNextCell(1, pointIds)
|
grid.InsertNextCell(1, pointIds)
|
||||||
IDs.InsertNextValue(int(item[3]))
|
IDs.InsertNextValue(grainIDs[i])
|
||||||
|
|
||||||
grid.SetPoints(pts)
|
grid.SetPoints(pts)
|
||||||
grid.GetCellData().AddArray(IDs)
|
grid.GetCellData().AddArray(IDs)
|
||||||
|
|
Loading…
Reference in New Issue