2018-11-17 12:42:12 +05:30
|
|
|
#!/usr/bin/env python3
|
2015-06-21 17:26:05 +05:30
|
|
|
|
2019-05-27 12:08:02 +05:30
|
|
|
import os
|
|
|
|
import sys
|
2020-01-15 18:49:41 +05:30
|
|
|
from io import StringIO
|
2015-06-21 17:26:05 +05:30
|
|
|
from optparse import OptionParser
|
2019-05-27 12:08:02 +05:30
|
|
|
|
|
|
|
import numpy as np
|
|
|
|
|
2015-06-21 17:26:05 +05:30
|
|
|
import damask
|
|
|
|
|
2019-05-27 12:08:02 +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-06-21 17:26:05 +05:30
|
|
|
|
|
|
|
|
|
|
|
# --------------------------------------------------------------------
|
|
|
|
# MAIN
|
|
|
|
# --------------------------------------------------------------------
|
|
|
|
|
2019-05-27 12:08:02 +05:30
|
|
|
parser = OptionParser(option_class=damask.extendableOption, usage='%prog options [ASCIItable(s)]', description = """
|
2019-05-30 17:37:49 +05:30
|
|
|
Converts ASCII table. Input can be microstructure or orientation (as quaternion). For the latter,
|
2019-05-30 17:00:18 +05:30
|
|
|
phase information can be given additionally.
|
2015-06-21 17:26:05 +05:30
|
|
|
|
|
|
|
""", version = scriptID)
|
|
|
|
|
2015-08-08 00:33:26 +05:30
|
|
|
parser.add_option('--coordinates',
|
2016-04-27 02:19:58 +05:30
|
|
|
dest = 'pos',
|
2015-08-08 00:33:26 +05:30
|
|
|
type = 'string', metavar = 'string',
|
2017-05-29 14:02:22 +05:30
|
|
|
help = 'coordinates label (%default)')
|
2015-08-08 00:33:26 +05:30
|
|
|
parser.add_option('--phase',
|
|
|
|
dest = 'phase',
|
|
|
|
type = 'string', metavar = 'string',
|
|
|
|
help = 'phase label')
|
2015-08-13 00:26:40 +05:30
|
|
|
parser.add_option('--microstructure',
|
|
|
|
dest = 'microstructure',
|
|
|
|
type = 'string', metavar = 'string',
|
|
|
|
help = 'microstructure label')
|
2015-08-08 00:33:26 +05:30
|
|
|
parser.add_option('-q', '--quaternion',
|
|
|
|
dest = 'quaternion',
|
|
|
|
type = 'string', metavar='string',
|
2015-06-21 17:26:05 +05:30
|
|
|
help = 'quaternion label')
|
2015-08-08 00:33:26 +05:30
|
|
|
parser.add_option('--axes',
|
|
|
|
dest = 'axes',
|
|
|
|
type = 'string', nargs = 3, metavar = ' '.join(['string']*3),
|
2019-02-24 17:27:57 +05:30
|
|
|
help = 'orientation coordinate frame in terms of position coordinate frame [+x +y +z]')
|
2015-08-08 00:33:26 +05:30
|
|
|
parser.add_option('--homogenization',
|
|
|
|
dest = 'homogenization',
|
|
|
|
type = 'int', metavar = 'int',
|
|
|
|
help = 'homogenization index to be used [%default]')
|
2019-02-24 02:36:31 +05:30
|
|
|
|
2015-06-21 17:26:05 +05:30
|
|
|
|
2019-02-24 17:27:57 +05:30
|
|
|
parser.set_defaults(homogenization = 1,
|
2017-05-29 14:02:22 +05:30
|
|
|
pos = 'pos',
|
2015-06-21 17:26:05 +05:30
|
|
|
)
|
|
|
|
|
|
|
|
(options,filenames) = parser.parse_args()
|
2020-01-15 18:39:26 +05:30
|
|
|
if filenames == []: filenames = [None]
|
2015-06-21 17:26:05 +05:30
|
|
|
|
2020-01-15 18:39:26 +05:30
|
|
|
if np.sum([options.quaternion is not None,
|
|
|
|
options.microstructure is not None]) != 1:
|
2019-05-30 14:01:27 +05:30
|
|
|
parser.error('need either microstructure or quaternion (and optionally phase) as input.')
|
|
|
|
if options.microstructure is not None and options.phase is not None:
|
|
|
|
parser.error('need either microstructure or phase (and mandatory quaternion) as input.')
|
2016-03-02 17:13:09 +05:30
|
|
|
if options.axes is not None and not set(options.axes).issubset(set(['x','+x','-x','y','+y','-y','z','+z','-z'])):
|
2015-08-13 00:26:40 +05:30
|
|
|
parser.error('invalid axes {} {} {}.'.format(*options.axes))
|
2015-06-21 17:26:05 +05:30
|
|
|
|
|
|
|
for name in filenames:
|
2020-01-15 18:39:26 +05:30
|
|
|
damask.util.report(scriptName,name)
|
|
|
|
|
2020-09-21 00:15:06 +05:30
|
|
|
table = damask.Table.load(StringIO(''.join(sys.stdin.read())) if name is None else name)
|
2020-01-15 18:39:26 +05:30
|
|
|
table.sort_by(['{}_{}'.format(i,options.pos) for i in range(3,0,-1)]) # x fast, y slow
|
|
|
|
grid,size,origin = damask.grid_filters.cell_coord0_gridSizeOrigin(table.get(options.pos))
|
|
|
|
|
|
|
|
config_header = table.comments
|
|
|
|
|
|
|
|
if options.microstructure:
|
|
|
|
microstructure = table.get(options.microstructure).reshape(grid,order='F')
|
|
|
|
|
|
|
|
elif options.quaternion:
|
|
|
|
q = table.get(options.quaternion)
|
|
|
|
phase = table.get(options.phase).astype(int) if options.phase else \
|
|
|
|
np.ones((table.data.shape[0],1),dtype=int)
|
|
|
|
|
|
|
|
unique,unique_inverse = np.unique(np.hstack((q,phase)),return_inverse=True,axis=0)
|
|
|
|
microstructure = unique_inverse.reshape(grid,order='F') + 1
|
|
|
|
|
|
|
|
config_header = ['<texture>']
|
|
|
|
for i,data in enumerate(unique):
|
|
|
|
ori = damask.Rotation(data[0:4])
|
|
|
|
config_header += ['[Grain{}]'.format(i+1),
|
2020-05-17 11:31:34 +05:30
|
|
|
'(gauss)\tphi1 {:.2f}\tPhi {:.2f}\tphi2 {:.2f}'.format(*ori.as_Eulers(degrees = True)),
|
2020-01-15 18:39:26 +05:30
|
|
|
]
|
|
|
|
if options.axes is not None: config_header += ['axes\t{} {} {}'.format(*options.axes)]
|
|
|
|
|
|
|
|
config_header += ['<microstructure>']
|
|
|
|
for i,data in enumerate(unique):
|
|
|
|
config_header += ['[Grain{}]'.format(i+1),
|
|
|
|
'(constituent)\tphase {}\ttexture {}\tfraction 1.0'.format(int(data[4]),i+1),
|
|
|
|
]
|
|
|
|
|
|
|
|
header = [scriptID + ' ' + ' '.join(sys.argv[1:])]\
|
|
|
|
+ config_header
|
|
|
|
geom = damask.Geom(microstructure,size,origin,
|
|
|
|
homogenization=options.homogenization,comments=header)
|
|
|
|
damask.util.croak(geom)
|
|
|
|
|
2020-09-15 10:28:06 +05:30
|
|
|
geom.save_ASCII(sys.stdout if name is None else os.path.splitext(name)[0]+'.geom',pack=False)
|