added "strict" option to reading microstructure from geom file. will now complain if data mismatches with grid.

This commit is contained in:
Philip Eisenlohr 2016-03-20 16:46:35 -04:00
parent 6865987ea7
commit a41cd3df40
2 changed files with 20 additions and 15 deletions

View File

@ -518,7 +518,8 @@ class ASCIItable():
# ------------------------------------------------------------------
def microstructure_read(self,
grid,
type = 'i'):
type = 'i',
strict = False):
"""read microstructure data (from .geom format)"""
def datatype(item):
return int(item) if type.lower() == 'i' else float(item)
@ -537,6 +538,7 @@ class ASCIItable():
s = min(len(items), N-i) # prevent overflow of microstructure array
microstructure[i:i+s] = items[:s]
i += s
i += len(items)
return microstructure
return (microstructure, i == N and not self.data_read() if strict # check for proper point count and end of file
else microstructure)

View File

@ -54,12 +54,25 @@ for name in filenames:
errors = []
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.')
#--- read microstructure information --------------------------------------------------------------
if options.data:
microstructure,ok = table.microstructure_read(info['grid'],strict = True) # read microstructure
if ok:
structure = vtk.vtkIntArray()
structure.SetName('Microstructures')
for idx in microstructure: structure.InsertNextValue(idx)
else: errors.append('mismatch between data and grid dimension.')
if errors != []:
damask.util.croak(errors)
table.close(dismiss = True)
continue
# --- generate VTK rectilinear grid --------------------------------------------------------------------------------
# --- generate VTK rectilinear grid ---------------------------------------------------------------
grid = vtk.vtkRectilinearGrid()
grid.SetDimensions([x+1 for x in info['grid']])
@ -72,18 +85,8 @@ for name in filenames:
elif i == 1: grid.SetYCoordinates(temp)
elif i == 2: grid.SetZCoordinates(temp)
#--- read microstructure information --------------------------------------------------------------
if options.data:
microstructure = table.microstructure_read(info['grid']) # read microstructure
structure = vtk.vtkIntArray()
structure.SetName('Microstructures')
for idx in microstructure:
structure.InsertNextValue(idx)
grid.GetCellData().AddArray(structure)
if options.data: grid.GetCellData().AddArray(structure)
# --- write data -----------------------------------------------------------------------------------
if name: