added (transparent) capability to deal with geom files.

This commit is contained in:
Philip Eisenlohr 2016-04-18 14:47:50 -04:00
parent 24d029c7ed
commit 0bc7f36ee5
1 changed files with 34 additions and 20 deletions

View File

@ -15,7 +15,7 @@ scriptID = ' '.join([scriptName,damask.version])
# -------------------------------------------------------------------- # --------------------------------------------------------------------
parser = OptionParser(option_class=damask.extendableOption, usage='%prog options [file[s]]', description = """ parser = OptionParser(option_class=damask.extendableOption, usage='%prog options [file[s]]', description = """
Create regular voxel grid from points in an ASCIItable. Create regular voxel grid from points in an ASCIItable (or geom file).
""", version = scriptID) """, version = scriptID)
@ -38,9 +38,12 @@ parser.set_defaults(coords = 'pos',
if filenames == []: filenames = [None] if filenames == []: filenames = [None]
for name in filenames: for name in filenames:
isGeom = name.endswith('.geom')
try: table = damask.ASCIItable(name = name, try: table = damask.ASCIItable(name = name,
buffered = False, buffered = False,
readonly = True) labeled = not isGeom,
readonly = True,
)
except: continue except: continue
damask.util.report(scriptName,name) damask.util.report(scriptName,name)
@ -50,7 +53,7 @@ for name in filenames:
remarks = [] remarks = []
errors = [] errors = []
coordDim = table.label_dimension(options.coords) coordDim = 3 if isGeom else table.label_dimension(options.coords)
if not 3 >= coordDim >= 1: errors.append('coordinates "{}" need to have one, two, or three dimensions.'.format(options.coords)) if not 3 >= coordDim >= 1: errors.append('coordinates "{}" need to have one, two, or three dimensions.'.format(options.coords))
elif coordDim < 3: remarks.append('appending {} dimensions to coordinates "{}"...'.format(3-coordDim,options.coords)) elif coordDim < 3: remarks.append('appending {} dimensions to coordinates "{}"...'.format(3-coordDim,options.coords))
@ -62,6 +65,14 @@ for name in filenames:
# --------------- figure out size and grid --------------------------------------------------------- # --------------- figure out size and grid ---------------------------------------------------------
if isGeom:
info,extra_header = table.head_getGeom()
coords = [np.linspace(info['origin'][i],
info['origin'][i]+info['size'][i],
num = info['grid'][i]+1,
endpoint = True,
) for i in xrange(3)]
else:
table.data_readArray(options.coords) table.data_readArray(options.coords)
if len(table.data.shape) < 2: table.data.shape += (1,) # expand to 2D shape if len(table.data.shape) < 2: table.data.shape += (1,) # expand to 2D shape
if table.data.shape[1] < 3: if table.data.shape[1] < 3:
@ -70,14 +81,17 @@ for name in filenames:
3-table.data.shape[1]),dtype='f'))) # fill coords up to 3D with zeros 3-table.data.shape[1]),dtype='f'))) # fill coords up to 3D with zeros
coords = [np.unique(table.data[:,i]) for i in xrange(3)] coords = [np.unique(table.data[:,i]) for i in xrange(3)]
if options.mode == 'cell': if options.mode == 'cell':
coords = [0.5 * np.array([3.0 * coords[i][0] - coords[i][0 + len(coords[i]) > 1]] + \ coords = [0.5 * np.array([3.0 * coords[i][0] - coords[i][0 + len(coords[i]) > 1]] + \
[coords[i][j-1] + coords[i][j] for j in xrange(1,len(coords[i]))] + \ [coords[i][j-1] + coords[i][j] for j in xrange(1,len(coords[i]))] + \
[3.0 * coords[i][-1] - coords[i][-1 - (len(coords[i]) > 1)]]) for i in xrange(3)] [3.0 * coords[i][-1] - coords[i][-1 - (len(coords[i]) > 1)]]) for i in xrange(3)]
grid = np.array(map(len,coords),'i')
N = grid.prod() if options.mode == 'point' else (grid-1).prod()
if N != len(table.data): errors.append('data count {} does not match grid {}x{}x{}.'.format(N,*(grid - options.mode == 'cell') )) grid = np.array(map(len,coords),'i')
N = grid.prod() if options.mode == 'point' or isGeom else (grid-1).prod()
if not isGeom and N != len(table.data):
errors.append('data count {} does not match grid {}x{}x{}.'.format(N,*(grid - (options.mode == 'cell')) ))
if errors != []: if errors != []:
damask.util.croak(errors) damask.util.croak(errors)
table.close(dismiss = True) table.close(dismiss = True)
@ -108,9 +122,9 @@ for name in filenames:
(directory,filename) = os.path.split(name) (directory,filename) = os.path.split(name)
writer.SetDataModeToBinary() writer.SetDataModeToBinary()
writer.SetCompressorTypeToZLib() writer.SetCompressorTypeToZLib()
writer.SetFileName(os.path.join(directory,os.path.splitext(filename)[0] \ writer.SetFileName(os.path.join(directory,os.path.splitext(filename)[0] +
+'_{}({})'.format(options.coords, options.mode) \ ('' if isGeom else '_{}({})'.format(options.coords, options.mode)) +
+'.'+writer.GetDefaultFileExtension())) '.' + writer.GetDefaultFileExtension()))
else: else:
writer = vtk.vtkDataSetWriter() writer = vtk.vtkDataSetWriter()
writer.WriteToOutputStringOn() writer.WriteToOutputStringOn()