2019-02-14 06:09:54 +05:30
|
|
|
#!/usr/bin/env python3
|
2015-08-25 02:18:50 +05:30
|
|
|
|
2019-06-14 16:33:30 +05:30
|
|
|
import os
|
|
|
|
import sys
|
2019-12-22 11:37:34 +05:30
|
|
|
from io import StringIO
|
2019-06-14 16:33:30 +05:30
|
|
|
from optparse import OptionParser
|
|
|
|
|
2015-08-25 02:18:50 +05:30
|
|
|
import damask
|
2019-06-14 16:33:30 +05:30
|
|
|
|
2015-10-16 01:21:27 +05:30
|
|
|
|
2016-01-27 22:36:00 +05:30
|
|
|
scriptName = os.path.splitext(os.path.basename(__file__))[0]
|
|
|
|
scriptID = ' '.join([scriptName,damask.version])
|
2015-08-25 02:18:50 +05:30
|
|
|
|
2019-06-14 16:33:30 +05:30
|
|
|
|
2015-08-25 02:18:50 +05:30
|
|
|
# --------------------------------------------------------------------
|
|
|
|
# MAIN
|
|
|
|
# --------------------------------------------------------------------
|
|
|
|
|
2019-02-16 22:11:56 +05:30
|
|
|
parser = OptionParser(option_class=damask.extendableOption, usage='%prog options [ASCIItable(s)]', description = """
|
2016-04-25 12:10:36 +05:30
|
|
|
Create regular voxel grid from points in an ASCIItable.
|
2015-08-25 02:18:50 +05:30
|
|
|
|
|
|
|
""", version = scriptID)
|
|
|
|
|
2016-04-23 00:32:07 +05:30
|
|
|
parser.add_option('-m',
|
|
|
|
'--mode',
|
2015-08-25 02:18:50 +05:30
|
|
|
dest = 'mode',
|
2016-05-13 12:58:54 +05:30
|
|
|
metavar='string',
|
2015-08-25 02:18:50 +05:30
|
|
|
type = 'choice', choices = ['cell','point'],
|
2016-04-23 00:50:36 +05:30
|
|
|
help = 'cell-centered or point-centered coordinates')
|
2016-04-23 00:32:07 +05:30
|
|
|
parser.add_option('-p',
|
|
|
|
'--pos', '--position',
|
|
|
|
dest = 'pos',
|
2015-08-25 02:18:50 +05:30
|
|
|
type = 'string', metavar = 'string',
|
2016-04-23 00:50:36 +05:30
|
|
|
help = 'label of coordinates [%default]')
|
2016-04-23 00:32:07 +05:30
|
|
|
|
|
|
|
parser.set_defaults(mode = 'cell',
|
|
|
|
pos = 'pos',
|
2015-08-25 02:18:50 +05:30
|
|
|
)
|
|
|
|
|
|
|
|
(options, filenames) = parser.parse_args()
|
|
|
|
if filenames == []: filenames = [None]
|
|
|
|
|
|
|
|
for name in filenames:
|
2020-03-19 13:32:50 +05:30
|
|
|
damask.util.report(scriptName,name)
|
2015-11-04 03:14:36 +05:30
|
|
|
|
2020-03-19 13:32:50 +05:30
|
|
|
table = damask.Table.from_ASCII(StringIO(''.join(sys.stdin.read())) if name is None else name)
|
2015-08-25 02:18:50 +05:30
|
|
|
|
2020-03-19 13:32:50 +05:30
|
|
|
if options.mode == 'cell':
|
|
|
|
grid, size, origin = damask.grid_filters.cell_coord0_gridSizeOrigin(table.get(options.pos))
|
|
|
|
elif options.mode == 'point':
|
|
|
|
grid, size, origin = damask.grid_filters.node_coord0_gridSizeOrigin(table.get(options.pos))
|
2016-04-23 00:32:07 +05:30
|
|
|
|
2020-03-19 13:32:50 +05:30
|
|
|
v = damask.VTK.from_rectilinearGrid(grid,size,origin)
|
2016-04-23 00:32:07 +05:30
|
|
|
|
2020-03-19 13:32:50 +05:30
|
|
|
if name:
|
|
|
|
v.write('{}_{}({})'.format(os.path.splitext(name)[0],options.pos,options.mode))
|
|
|
|
else:
|
|
|
|
sys.stdout.write(v.__repr__())
|