changed to standard file and output handling

This commit is contained in:
Martin Diehl 2015-04-22 18:57:44 +00:00
parent 9694d63874
commit b9c5edf7ab
2 changed files with 69 additions and 64 deletions

View File

@ -33,9 +33,9 @@ def outStdout(cmd,locals):
exec(cmd[3:])
elif cmd[0:3] == '(?)':
cmd = eval(cmd[3:])
print cmd
sys.stdout.write(cmd+'\n')
else:
print cmd
sys.stdout.write(cmd+'\n')
return
@ -163,11 +163,9 @@ Set up servo linking to achieve periodic boundary conditions for a regular hexah
""", version = scriptID)
parser.add_option("-p", "--port", type="int",\
dest="port",\
parser.add_option("-p", "--port", type="int", dest="port", metavar='int',
help="Mentat connection port [%default]")
parser.add_option("-v", "--verbose", action="store_true",\
dest="verbose",\
parser.add_option("-v", "--verbose", action="store_true", dest="verbose",
help="write Mentat command stream also to stdout [%default]")
parser.set_defaults(port = 40007)
parser.set_defaults(verbose = False)
@ -175,10 +173,15 @@ parser.set_defaults(verbose = False)
(options, args) = parser.parse_args()
outputLocals = {}
print '\033[1m'+scriptName+'\033[0m\n'
print 'waiting to connect...'
if options.verbose:
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)
print 'connected...'
file['croak'].write('connected...\n')
output([\
'*draw_manual', # prevent redrawing in "new" Mentat, should be much faster
'*remove_all_servos',

View File

@ -27,9 +27,10 @@ def outStdout(cmd,locals):
exec(cmd[3:])
elif cmd[0:3] == '(?)':
cmd = eval(cmd[3:])
print(cmd)
sys.stdout.write(cmd+'\n')
else:
print(cmd)
sys.stdout.write(cmd+'\n')
return
#-------------------------------------------------------------------------------------------------
@ -232,31 +233,23 @@ def parse_spectralFile(content,homog):
#--------------------------------------------------------------------------------------------------
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)
parser.add_option("-p", "--port", type="int",\
dest="port",\
parser.add_option("-p", "--port", type="int",dest="port",metavar='int',
help="Mentat connection port")
parser.add_option("-g", "--geom", action="store_const", const="geom",\
dest="filetype",\
parser.add_option("-g", "--geom", action="store_const", const="geom",dest="filetype",
help="file has 'geom' format")
parser.add_option("-s", "--spectral", action="store_const", const="spectral",\
dest="filetype",\
help="file has 'spectral' format (VPSC Lebensohn)")
parser.add_option("--homogenization", type="int",\
dest="homogenization",\
help="homogenization index from material.config (only required for geom file type)")
parser.add_option("-s", "--spectral", action="store_const", const="spectral",dest="filetype",
help="file has 'spectral' format (VPSC code by R.A. Lebensohn)")
parser.add_option("--homogenization", type="int",dest="homogenization",metavar='int',
help="homogenization index from material.config (only required for 'spectral' file type)")
parser.set_defaults(filetype = 'geom')
parser.set_defaults(homogenization = 1)
(options, args) = parser.parse_args()
(options, filenames) = parser.parse_args()
sys.path.append(damask.solver.Marc().libraryPath('../../'))
@ -267,29 +260,39 @@ except:
print('no valid Mentat release found')
if options.port != None: sys.exit(-1)
if not os.path.isfile(args[0]):
parser.error("cannot open %s"%args[0])
#--- setup file handles --------------------------------------------------------------------------
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])
content = file.readlines()
file.close()
#--- loop over input files ------------------------------------------------------------------------
for file in files:
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,)
sys.stdout.flush()
content = file['input'].readlines()
(grid,size,homog,microstructures) = {\
(grid,size,homog,microstructures) = {\
'geom': parse_geomFile,
'spectral': parse_spectralFile,
}[options.filetype](content,options.homogenization)
print('%i microstructures in %s with grid %s and homogenization %i\n'%(len(list(set(microstructures))),str(size),str(grid),homog))
print('%i microstructures in %s with grid %s and homogenization %i\n'%(len(list(set(microstructures))),str(size),str(grid),homog))
cmds = [\
cmds = [\
init(),
mesh(grid,size),
material(),
@ -297,13 +300,12 @@ cmds = [\
initial_conditions(homog,microstructures),
'*identify_sets',
'*redraw',
]
]
outputLocals = {}
if (options.port != None):
outputLocals = {}
if (options.port != None):
py_connect('',options.port)
output(cmds,outputLocals,'Mentat')
py_disconnect()
else:
else:
output(cmds,outputLocals,'Stdout')