use geom class
This commit is contained in:
parent
12564557e6
commit
871ff4c218
|
@ -1,9 +1,11 @@
|
||||||
#!/usr/bin/env python3
|
#!/usr/bin/env python3
|
||||||
# -*- coding: UTF-8 no BOM -*-
|
|
||||||
|
|
||||||
import os,sys
|
import os
|
||||||
import numpy as np
|
import sys
|
||||||
from optparse import OptionParser
|
from optparse import OptionParser
|
||||||
|
|
||||||
|
import numpy as np
|
||||||
|
|
||||||
import damask
|
import damask
|
||||||
|
|
||||||
scriptName = os.path.splitext(os.path.basename(__file__))[0]
|
scriptName = os.path.splitext(os.path.basename(__file__))[0]
|
||||||
|
@ -191,78 +193,45 @@ parser.add_option('-p', '--port',
|
||||||
dest = 'port',
|
dest = 'port',
|
||||||
type = 'int', metavar = 'int',
|
type = 'int', metavar = 'int',
|
||||||
help = 'Mentat connection port [%default]')
|
help = 'Mentat connection port [%default]')
|
||||||
parser.add_option('--homogenization',
|
|
||||||
dest = 'homogenization',
|
|
||||||
type = 'int', metavar = 'int',
|
|
||||||
help = 'homogenization index to be used [auto]')
|
|
||||||
|
|
||||||
parser.set_defaults(port = None,
|
parser.set_defaults(port = None,
|
||||||
homogenization = None,
|
)
|
||||||
)
|
|
||||||
|
|
||||||
(options, filenames) = parser.parse_args()
|
(options, filenames) = parser.parse_args()
|
||||||
|
|
||||||
if options.port:
|
if options.port is not None:
|
||||||
try:
|
try:
|
||||||
import py_mentat
|
import py_mentat
|
||||||
except:
|
except ImportError:
|
||||||
parser.error('no valid Mentat release found.')
|
parser.error('no valid Mentat release found.')
|
||||||
|
|
||||||
# --- loop over input files ------------------------------------------------------------------------
|
# --- loop over input files ------------------------------------------------------------------------
|
||||||
|
|
||||||
if filenames == []: filenames = [None]
|
if filenames == []: filenames = [None]
|
||||||
|
|
||||||
for name in filenames:
|
for name in filenames:
|
||||||
try:
|
damask.util.report(scriptName,name)
|
||||||
table = damask.ASCIItable(name = name,
|
|
||||||
outname = os.path.splitext(name)[0]+'.proc' if name else name,
|
|
||||||
buffered = False, labeled = False)
|
|
||||||
except: continue
|
|
||||||
damask.util.report(scriptName,name)
|
|
||||||
|
|
||||||
# --- interpret header ----------------------------------------------------------------------------
|
geom = damask.Geom.from_file(StringIO(''.join(sys.stdin.read())) if name is None else name)
|
||||||
|
microstructure = geom.get_microstructure().flatten(order='F')
|
||||||
|
|
||||||
table.head_read()
|
cmds = [\
|
||||||
info,extra_header = table.head_getGeom()
|
init(),
|
||||||
if options.homogenization: info['homogenization'] = options.homogenization
|
mesh(geom.grid,geom.size),
|
||||||
|
material(),
|
||||||
|
geometry(),
|
||||||
|
initial_conditions(geom.homogenization,microstructure),
|
||||||
|
'*identify_sets',
|
||||||
|
'*show_model',
|
||||||
|
'*redraw',
|
||||||
|
'*draw_automatic',
|
||||||
|
]
|
||||||
|
|
||||||
damask.util.croak(['grid a b c: %s'%(' x '.join(map(str,info['grid']))),
|
outputLocals = {}
|
||||||
'size x y z: %s'%(' x '.join(map(str,info['size']))),
|
if options.port:
|
||||||
'origin x y z: %s'%(' : '.join(map(str,info['origin']))),
|
py_mentat.py_connect('',options.port)
|
||||||
'homogenization: %i'%info['homogenization'],
|
output(cmds,outputLocals,'Mentat')
|
||||||
'microstructures: %i'%info['microstructures'],
|
py_mentat.py_disconnect()
|
||||||
])
|
else:
|
||||||
|
with sys.stdout if name is None else open(os.path.splitext(name)[0]+'.proc','w') as f:
|
||||||
errors = []
|
output(cmds,outputLocals,f)
|
||||||
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 != []:
|
|
||||||
damask.util.croak(errors)
|
|
||||||
table.close(dismiss = True)
|
|
||||||
continue
|
|
||||||
|
|
||||||
# --- read data ------------------------------------------------------------------------------------
|
|
||||||
|
|
||||||
microstructure = table.microstructure_read(info['grid']).reshape(info['grid'].prod(),order='F') # read microstructure
|
|
||||||
|
|
||||||
cmds = [\
|
|
||||||
init(),
|
|
||||||
mesh(info['grid'],info['size']),
|
|
||||||
material(),
|
|
||||||
geometry(),
|
|
||||||
initial_conditions(info['homogenization'],microstructure),
|
|
||||||
'*identify_sets',
|
|
||||||
'*show_model',
|
|
||||||
'*redraw',
|
|
||||||
'*draw_automatic',
|
|
||||||
]
|
|
||||||
|
|
||||||
outputLocals = {}
|
|
||||||
if options.port:
|
|
||||||
py_mentat.py_connect('',options.port)
|
|
||||||
output(cmds,outputLocals,'Mentat')
|
|
||||||
py_mentat.py_disconnect()
|
|
||||||
else:
|
|
||||||
output(cmds,outputLocals,table.__IO__['out']) # bad hack into internals of table class...
|
|
||||||
|
|
||||||
table.close()
|
|
||||||
|
|
Loading…
Reference in New Issue