seems to work

This commit is contained in:
Martin Diehl 2016-04-25 08:40:36 +02:00
parent 26f437b507
commit e8afd57536
2 changed files with 23 additions and 34 deletions

View File

@ -14,7 +14,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 (or geom file). Create regular voxel grid from points in an ASCIItable.
""", version = scriptID) """, version = scriptID)
@ -28,15 +28,9 @@ parser.add_option('-p',
dest = 'pos', dest = 'pos',
type = 'string', metavar = 'string', type = 'string', metavar = 'string',
help = 'label of coordinates [%default]') help = 'label of coordinates [%default]')
parser.add_option('-g',
'--geom',
dest = 'geom',
action = 'store_true',
help = 'geom input format')
parser.set_defaults(mode = 'cell', parser.set_defaults(mode = 'cell',
pos = 'pos', pos = 'pos',
geom = False,
) )
(options, filenames) = parser.parse_args() (options, filenames) = parser.parse_args()
@ -46,10 +40,9 @@ parser.set_defaults(mode = 'cell',
if filenames == []: filenames = [None] if filenames == []: filenames = [None]
for name in filenames: for name in filenames:
isGeom = options.geom or (name is not None and name.endswith('.geom'))
try: table = damask.ASCIItable(name = name, try: table = damask.ASCIItable(name = name,
buffered = False, buffered = False,
labeled = not isGeom, labeled = True,
readonly = True, readonly = True,
) )
except: continue except: continue
@ -61,7 +54,7 @@ for name in filenames:
remarks = [] remarks = []
errors = [] errors = []
coordDim = 3 if isGeom else table.label_dimension(options.pos) coordDim = table.label_dimension(options.pos)
if not 3 >= coordDim >= 1: errors.append('coordinates "{}" need to have one, two, or three dimensions.'.format(options.pos)) if not 3 >= coordDim >= 1: errors.append('coordinates "{}" need to have one, two, or three dimensions.'.format(options.pos))
elif coordDim < 3: remarks.append('appending {} dimensions to coordinates "{}"...'.format(3-coordDim,options.pos)) elif coordDim < 3: remarks.append('appending {} dimensions to coordinates "{}"...'.format(3-coordDim,options.pos))
@ -73,32 +66,24 @@ for name in filenames:
# --------------- figure out size and grid --------------------------------------------------------- # --------------- figure out size and grid ---------------------------------------------------------
if isGeom: table.data_readArray(options.pos)
info,extra_header = table.head_getGeom() if len(table.data.shape) < 2: table.data.shape += (1,) # expand to 2D shape
coords = [np.linspace(info['origin'][i], if table.data.shape[1] < 3:
info['origin'][i]+info['size'][i], table.data = np.hstack((table.data,
num = info['grid'][i]+1, np.zeros((table.data.shape[0],
endpoint = True, 3-table.data.shape[1]),dtype='f'))) # fill coords up to 3D with zeros
) for i in xrange(3)]
else:
table.data_readArray(options.pos)
if len(table.data.shape) < 2: table.data.shape += (1,) # expand to 2D shape
if table.data.shape[1] < 3:
table.data = np.hstack((table.data,
np.zeros((table.data.shape[0],
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') grid = np.array(map(len,coords),'i')
N = grid.prod() if options.mode == 'point' or isGeom else (grid-1).prod() N = grid.prod() if options.mode == 'point' else (grid-1).prod()
if not isGeom and N != len(table.data): if N != len(table.data):
errors.append('data count {} does not match grid {}x{}x{}.'.format(N,*(grid - (options.mode == 'cell')) )) 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)
@ -131,7 +116,7 @@ for name in filenames:
writer.SetDataModeToBinary() writer.SetDataModeToBinary()
writer.SetFileName(os.path.join(os.path.split(name)[0], writer.SetFileName(os.path.join(os.path.split(name)[0],
os.path.splitext(os.path.split(name)[1])[0] + os.path.splitext(os.path.split(name)[1])[0] +
('' if isGeom else '_{}({})'.format(options.pos, options.mode)) + '_{}({})'.format(options.pos, options.mode) +
'.' + writer.GetDefaultFileExtension())) '.' + writer.GetDefaultFileExtension()))
else: else:
writer = vtk.vtkDataSetWriter() writer = vtk.vtkDataSetWriter()

View File

@ -2,7 +2,10 @@
for geom in "$@" for geom in "$@"
do do
vtk_rectilinearGrid \ geom_toTable \
< $geom \
| \
vtk_rectilinearGrid > ${geom%.*}.vtk
--geom $geom --geom $geom
geom_toTable \ geom_toTable \
@ -11,5 +14,6 @@ do
vtk_addRectilinearGridData \ vtk_addRectilinearGridData \
--scalar microstructure \ --scalar microstructure \
--inplace \ --inplace \
--vtk ${geom%.*}.vtr --vtk ${geom%.*}.vtk
rm ${geom%.*}.vtk
done done