2014-11-14 20:46:00 +05:30
|
|
|
#!/usr/bin/env python
|
|
|
|
# -*- coding: UTF-8 no BOM -*-
|
|
|
|
|
2014-11-18 13:30:45 +05:30
|
|
|
import os,sys,string,vtk
|
2014-11-14 20:46:00 +05:30
|
|
|
import numpy as np
|
2014-11-18 13:30:45 +05:30
|
|
|
from optparse import OptionParser
|
2014-11-14 20:46:00 +05:30
|
|
|
import damask
|
|
|
|
|
2016-01-27 22:36:00 +05:30
|
|
|
scriptName = os.path.splitext(os.path.basename(__file__))[0]
|
|
|
|
scriptID = ' '.join([scriptName,damask.version])
|
2014-11-14 20:46:00 +05:30
|
|
|
|
|
|
|
|
|
|
|
#--------------------------------------------------------------------------------------------------
|
|
|
|
# MAIN
|
|
|
|
#--------------------------------------------------------------------------------------------------
|
|
|
|
|
2014-11-18 13:30:45 +05:30
|
|
|
parser = OptionParser(option_class=damask.extendableOption, usage='%prog [geomfile[s]]', description = """
|
2015-11-20 22:00:55 +05:30
|
|
|
Translate geom description into ASCIItable containing 1/2/3_pos and microstructure.
|
2014-11-14 20:46:00 +05:30
|
|
|
|
2014-11-18 13:30:45 +05:30
|
|
|
""", version = scriptID)
|
2014-11-14 20:46:00 +05:30
|
|
|
|
2015-08-08 00:33:26 +05:30
|
|
|
parser.add_option('-p','--position',
|
|
|
|
dest = 'position',
|
|
|
|
type = 'string', metavar = 'string',
|
|
|
|
help = 'column label for position [%default]')
|
2015-11-20 22:00:55 +05:30
|
|
|
parser.add_option('-m','--microstructure',
|
|
|
|
dest = 'microstructure',
|
|
|
|
type = 'string', metavar = 'string',
|
|
|
|
help = 'column label for microstructure index [%default]')
|
2015-08-08 00:33:26 +05:30
|
|
|
|
|
|
|
parser.set_defaults(position = 'pos',
|
2015-11-20 22:00:55 +05:30
|
|
|
microstructure = 'microstructure',
|
2015-08-08 00:33:26 +05:30
|
|
|
)
|
|
|
|
|
2014-11-14 20:46:00 +05:30
|
|
|
(options, filenames) = parser.parse_args()
|
|
|
|
|
2015-08-08 00:33:26 +05:30
|
|
|
# --- loop over input files -------------------------------------------------------------------------
|
|
|
|
|
2015-08-21 01:12:05 +05:30
|
|
|
if filenames == []: filenames = [None]
|
2015-08-08 00:33:26 +05:30
|
|
|
|
|
|
|
for name in filenames:
|
2015-08-13 02:58:07 +05:30
|
|
|
try:
|
|
|
|
table = damask.ASCIItable(name = name,
|
|
|
|
outname = os.path.splitext(name)[0]+'.txt' if name else name,
|
|
|
|
buffered = False, labeled = False)
|
|
|
|
except: continue
|
2015-11-20 22:00:55 +05:30
|
|
|
damask.util.report(scriptName,name)
|
2015-08-08 00:33:26 +05:30
|
|
|
|
|
|
|
# --- interpret header ----------------------------------------------------------------------------
|
|
|
|
|
|
|
|
table.head_read()
|
|
|
|
info,extra_header = table.head_getGeom()
|
|
|
|
|
2015-11-20 22:00:55 +05:30
|
|
|
damask.util.croak(['grid a b c: %s'%(' x '.join(map(str,info['grid']))),
|
|
|
|
'size x y z: %s'%(' x '.join(map(str,info['size']))),
|
|
|
|
'origin x y z: %s'%(' : '.join(map(str,info['origin']))),
|
|
|
|
'homogenization: %i'%info['homogenization'],
|
|
|
|
'microstructures: %i'%info['microstructures'],
|
|
|
|
])
|
2015-08-08 00:33:26 +05:30
|
|
|
|
|
|
|
errors = []
|
|
|
|
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 errors != []:
|
2015-11-20 22:00:55 +05:30
|
|
|
damask.util.croak(errors)
|
2015-08-08 00:33:26 +05:30
|
|
|
table.close(dismiss = True)
|
2014-11-14 20:46:00 +05:30
|
|
|
continue
|
|
|
|
|
2015-08-08 00:33:26 +05:30
|
|
|
# --- read data ------------------------------------------------------------------------------------
|
|
|
|
|
|
|
|
microstructure = table.microstructure_read(info['grid']) # read microstructure
|
2014-11-14 20:46:00 +05:30
|
|
|
|
2015-08-08 00:33:26 +05:30
|
|
|
# ------------------------------------------ assemble header ---------------------------------------
|
2014-11-14 20:46:00 +05:30
|
|
|
|
2015-08-08 00:33:26 +05:30
|
|
|
table.info_clear()
|
|
|
|
table.info_append(extra_header + [scriptID + '\t' + ' '.join(sys.argv[1:])])
|
|
|
|
table.labels_clear()
|
2015-11-20 22:00:55 +05:30
|
|
|
table.labels_append(['{}_{}'.format(1+i,options.position) for i in xrange(3)]+[options.microstructure])
|
2015-08-08 00:33:26 +05:30
|
|
|
table.head_write()
|
|
|
|
table.output_flush()
|
2014-11-14 20:46:00 +05:30
|
|
|
|
|
|
|
#--- generate grid --------------------------------------------------------------------------------
|
|
|
|
|
2015-08-08 00:33:26 +05:30
|
|
|
x = (0.5 + np.arange(info['grid'][0],dtype=float))/info['grid'][0]*info['size'][0]+info['origin'][0]
|
|
|
|
y = (0.5 + np.arange(info['grid'][1],dtype=float))/info['grid'][1]*info['size'][1]+info['origin'][1]
|
|
|
|
z = (0.5 + np.arange(info['grid'][2],dtype=float))/info['grid'][2]*info['size'][2]+info['origin'][2]
|
2014-11-14 20:46:00 +05:30
|
|
|
|
2015-08-08 00:33:26 +05:30
|
|
|
xx = np.tile( x, info['grid'][1]* info['grid'][2])
|
|
|
|
yy = np.tile(np.repeat(y,info['grid'][0] ),info['grid'][2])
|
|
|
|
zz = np.repeat(z,info['grid'][0]*info['grid'][1])
|
|
|
|
|
|
|
|
table.data = np.squeeze(np.dstack((xx,yy,zz,microstructure)))
|
|
|
|
table.data_writeArray()
|
2014-11-14 20:46:00 +05:30
|
|
|
|
|
|
|
# ------------------------------------------ finalize output ---------------------------------------
|
|
|
|
|
2015-08-08 00:33:26 +05:30
|
|
|
table.close()
|