changed to standard file and output handling
This commit is contained in:
parent
9694d63874
commit
b9c5edf7ab
|
@ -33,9 +33,9 @@ def outStdout(cmd,locals):
|
||||||
exec(cmd[3:])
|
exec(cmd[3:])
|
||||||
elif cmd[0:3] == '(?)':
|
elif cmd[0:3] == '(?)':
|
||||||
cmd = eval(cmd[3:])
|
cmd = eval(cmd[3:])
|
||||||
print cmd
|
sys.stdout.write(cmd+'\n')
|
||||||
else:
|
else:
|
||||||
print cmd
|
sys.stdout.write(cmd+'\n')
|
||||||
return
|
return
|
||||||
|
|
||||||
|
|
||||||
|
@ -163,11 +163,9 @@ Set up servo linking to achieve periodic boundary conditions for a regular hexah
|
||||||
|
|
||||||
""", version = scriptID)
|
""", version = scriptID)
|
||||||
|
|
||||||
parser.add_option("-p", "--port", type="int",\
|
parser.add_option("-p", "--port", type="int", dest="port", metavar='int',
|
||||||
dest="port",\
|
|
||||||
help="Mentat connection port [%default]")
|
help="Mentat connection port [%default]")
|
||||||
parser.add_option("-v", "--verbose", action="store_true",\
|
parser.add_option("-v", "--verbose", action="store_true", dest="verbose",
|
||||||
dest="verbose",\
|
|
||||||
help="write Mentat command stream also to stdout [%default]")
|
help="write Mentat command stream also to stdout [%default]")
|
||||||
parser.set_defaults(port = 40007)
|
parser.set_defaults(port = 40007)
|
||||||
parser.set_defaults(verbose = False)
|
parser.set_defaults(verbose = False)
|
||||||
|
@ -175,10 +173,15 @@ parser.set_defaults(verbose = False)
|
||||||
(options, args) = parser.parse_args()
|
(options, args) = parser.parse_args()
|
||||||
|
|
||||||
outputLocals = {}
|
outputLocals = {}
|
||||||
print '\033[1m'+scriptName+'\033[0m\n'
|
if options.verbose:
|
||||||
print 'waiting to connect...'
|
file={'croak':sys.stderr}
|
||||||
|
else:
|
||||||
|
file={'croak':sys.stdout}
|
||||||
|
|
||||||
|
file['croak'].write('\033[1m'+scriptName+'\033[0m\n\n')
|
||||||
|
file['croak'].write( 'waiting to connect...\n')
|
||||||
py_connect('',options.port)
|
py_connect('',options.port)
|
||||||
print 'connected...'
|
file['croak'].write('connected...\n')
|
||||||
output([\
|
output([\
|
||||||
'*draw_manual', # prevent redrawing in "new" Mentat, should be much faster
|
'*draw_manual', # prevent redrawing in "new" Mentat, should be much faster
|
||||||
'*remove_all_servos',
|
'*remove_all_servos',
|
||||||
|
|
|
@ -27,9 +27,10 @@ def outStdout(cmd,locals):
|
||||||
exec(cmd[3:])
|
exec(cmd[3:])
|
||||||
elif cmd[0:3] == '(?)':
|
elif cmd[0:3] == '(?)':
|
||||||
cmd = eval(cmd[3:])
|
cmd = eval(cmd[3:])
|
||||||
print(cmd)
|
sys.stdout.write(cmd+'\n')
|
||||||
else:
|
else:
|
||||||
print(cmd)
|
print(cmd)
|
||||||
|
sys.stdout.write(cmd+'\n')
|
||||||
return
|
return
|
||||||
|
|
||||||
#-------------------------------------------------------------------------------------------------
|
#-------------------------------------------------------------------------------------------------
|
||||||
|
@ -232,31 +233,23 @@ def parse_spectralFile(content,homog):
|
||||||
#--------------------------------------------------------------------------------------------------
|
#--------------------------------------------------------------------------------------------------
|
||||||
|
|
||||||
parser = OptionParser(option_class=damask.extendableOption, usage='%prog options [file[s]]', description = """
|
parser = OptionParser(option_class=damask.extendableOption, usage='%prog options [file[s]]', description = """
|
||||||
Generate FE hexahedral mesh from spectral description file.
|
Generate MSC.Marc FE hexahedral mesh from spectral description file.
|
||||||
|
|
||||||
Acceptable formats are
|
|
||||||
geom: header plus list of grain numbers or
|
|
||||||
spectral: phi1,Phi,phi2,x,y,z,id,phase.
|
|
||||||
""", version = scriptID)
|
""", version = scriptID)
|
||||||
|
|
||||||
parser.add_option("-p", "--port", type="int",\
|
parser.add_option("-p", "--port", type="int",dest="port",metavar='int',
|
||||||
dest="port",\
|
|
||||||
help="Mentat connection port")
|
help="Mentat connection port")
|
||||||
parser.add_option("-g", "--geom", action="store_const", const="geom",\
|
parser.add_option("-g", "--geom", action="store_const", const="geom",dest="filetype",
|
||||||
dest="filetype",\
|
|
||||||
help="file has 'geom' format")
|
help="file has 'geom' format")
|
||||||
parser.add_option("-s", "--spectral", action="store_const", const="spectral",\
|
parser.add_option("-s", "--spectral", action="store_const", const="spectral",dest="filetype",
|
||||||
dest="filetype",\
|
help="file has 'spectral' format (VPSC code by R.A. Lebensohn)")
|
||||||
help="file has 'spectral' format (VPSC Lebensohn)")
|
parser.add_option("--homogenization", type="int",dest="homogenization",metavar='int',
|
||||||
parser.add_option("--homogenization", type="int",\
|
help="homogenization index from material.config (only required for 'spectral' file type)")
|
||||||
dest="homogenization",\
|
|
||||||
help="homogenization index from material.config (only required for geom file type)")
|
|
||||||
|
|
||||||
|
|
||||||
parser.set_defaults(filetype = 'geom')
|
parser.set_defaults(filetype = 'geom')
|
||||||
parser.set_defaults(homogenization = 1)
|
parser.set_defaults(homogenization = 1)
|
||||||
|
|
||||||
(options, args) = parser.parse_args()
|
(options, filenames) = parser.parse_args()
|
||||||
|
|
||||||
|
|
||||||
sys.path.append(damask.solver.Marc().libraryPath('../../'))
|
sys.path.append(damask.solver.Marc().libraryPath('../../'))
|
||||||
|
@ -267,19 +260,29 @@ except:
|
||||||
print('no valid Mentat release found')
|
print('no valid Mentat release found')
|
||||||
if options.port != None: sys.exit(-1)
|
if options.port != None: sys.exit(-1)
|
||||||
|
|
||||||
if not os.path.isfile(args[0]):
|
#--- setup file handles --------------------------------------------------------------------------
|
||||||
parser.error("cannot open %s"%args[0])
|
files = []
|
||||||
|
if filenames == []:
|
||||||
|
files.append({'name':'STDIN',
|
||||||
|
'input':sys.stdin,
|
||||||
|
'output':sys.stdout,
|
||||||
|
'croak':sys.stderr,
|
||||||
|
})
|
||||||
|
else:
|
||||||
|
for name in filenames:
|
||||||
|
if os.path.exists(name):
|
||||||
|
files.append({'name':name,
|
||||||
|
'input':open(name),
|
||||||
|
'output':open(name+'_tmp','w'),
|
||||||
|
'croak':sys.stdout,
|
||||||
|
})
|
||||||
|
|
||||||
file = open(args[0])
|
#--- loop over input files ------------------------------------------------------------------------
|
||||||
content = file.readlines()
|
for file in files:
|
||||||
file.close()
|
file['croak'].write('\033[1m' + scriptName + '\033[0m: ' + (file['name'] if file['name'] != 'STDIN' else '') + '\n')
|
||||||
|
|
||||||
print('\033[1m'+scriptName+'\033[0m\n')
|
|
||||||
if options.filetype not in ['spectral','geom']:
|
|
||||||
options.filetype = os.path.splitext(args[0])[1][1:]
|
|
||||||
|
|
||||||
print('\nparsing %s...'%options.filetype,)
|
content = file['input'].readlines()
|
||||||
sys.stdout.flush()
|
|
||||||
|
|
||||||
(grid,size,homog,microstructures) = {\
|
(grid,size,homog,microstructures) = {\
|
||||||
'geom': parse_geomFile,
|
'geom': parse_geomFile,
|
||||||
|
@ -306,4 +309,3 @@ if (options.port != None):
|
||||||
py_disconnect()
|
py_disconnect()
|
||||||
else:
|
else:
|
||||||
output(cmds,outputLocals,'Stdout')
|
output(cmds,outputLocals,'Stdout')
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue