added "strict" option to reading microstructure from geom file. will now complain if data mismatches with grid.
This commit is contained in:
parent
6865987ea7
commit
a41cd3df40
|
@ -518,7 +518,8 @@ class ASCIItable():
|
||||||
# ------------------------------------------------------------------
|
# ------------------------------------------------------------------
|
||||||
def microstructure_read(self,
|
def microstructure_read(self,
|
||||||
grid,
|
grid,
|
||||||
type = 'i'):
|
type = 'i',
|
||||||
|
strict = False):
|
||||||
"""read microstructure data (from .geom format)"""
|
"""read microstructure data (from .geom format)"""
|
||||||
def datatype(item):
|
def datatype(item):
|
||||||
return int(item) if type.lower() == 'i' else float(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
|
s = min(len(items), N-i) # prevent overflow of microstructure array
|
||||||
microstructure[i:i+s] = items[:s]
|
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)
|
||||||
|
|
|
@ -54,12 +54,25 @@ for name in filenames:
|
||||||
errors = []
|
errors = []
|
||||||
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.')
|
||||||
|
|
||||||
|
#--- 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 != []:
|
if errors != []:
|
||||||
damask.util.croak(errors)
|
damask.util.croak(errors)
|
||||||
table.close(dismiss = True)
|
table.close(dismiss = True)
|
||||||
continue
|
continue
|
||||||
|
|
||||||
# --- generate VTK rectilinear grid --------------------------------------------------------------------------------
|
# --- generate VTK rectilinear grid ---------------------------------------------------------------
|
||||||
|
|
||||||
grid = vtk.vtkRectilinearGrid()
|
grid = vtk.vtkRectilinearGrid()
|
||||||
grid.SetDimensions([x+1 for x in info['grid']])
|
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 == 1: grid.SetYCoordinates(temp)
|
||||||
elif i == 2: grid.SetZCoordinates(temp)
|
elif i == 2: grid.SetZCoordinates(temp)
|
||||||
|
|
||||||
#--- read microstructure information --------------------------------------------------------------
|
|
||||||
|
|
||||||
if options.data:
|
if options.data: grid.GetCellData().AddArray(structure)
|
||||||
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)
|
|
||||||
|
|
||||||
# --- write data -----------------------------------------------------------------------------------
|
# --- write data -----------------------------------------------------------------------------------
|
||||||
if name:
|
if name:
|
||||||
|
|
Loading…
Reference in New Issue