added some warnings if Mentat or PIL cabability missing
This commit is contained in:
parent
ff3bac2496
commit
164da22730
|
@ -3,14 +3,14 @@
|
||||||
import sys,os,math,re
|
import sys,os,math,re
|
||||||
from optparse import OptionParser, OptionGroup, Option, SUPPRESS_HELP
|
from optparse import OptionParser, OptionGroup, Option, SUPPRESS_HELP
|
||||||
|
|
||||||
try:
|
|
||||||
|
try: # check for Python Image Lib
|
||||||
import Image,ImageDraw
|
import Image,ImageDraw
|
||||||
ImageCapability = True
|
ImageCapability = True
|
||||||
except:
|
except:
|
||||||
ImageCapability = False
|
ImageCapability = False
|
||||||
|
|
||||||
|
try: # check for MSC.Mentat installation location
|
||||||
try:
|
|
||||||
file = open('%s/../MSCpath'%os.path.dirname(os.path.realpath(sys.argv[0])))
|
file = open('%s/../MSCpath'%os.path.dirname(os.path.realpath(sys.argv[0])))
|
||||||
MSCpath = os.path.normpath(file.readline().strip())
|
MSCpath = os.path.normpath(file.readline().strip())
|
||||||
file.close()
|
file.close()
|
||||||
|
@ -32,7 +32,7 @@ for release,subdirs in sorted(releases.items(),reverse=True):
|
||||||
continue
|
continue
|
||||||
break
|
break
|
||||||
|
|
||||||
try:
|
try: # check for MSC.Mentat Python interface
|
||||||
from py_mentat import *
|
from py_mentat import *
|
||||||
MentatCapability = True
|
MentatCapability = True
|
||||||
except:
|
except:
|
||||||
|
@ -309,11 +309,11 @@ def rcbParser(content,M,size,tolerance): # parser for TSL-O
|
||||||
|
|
||||||
for point in points:
|
for point in points:
|
||||||
rcData['point'].append(point['coords'])
|
rcData['point'].append(point['coords'])
|
||||||
print "\nfound %i points"%(len(rcData['point']))
|
print " found %i points"%(len(rcData['point']))
|
||||||
|
|
||||||
for segment in segments:
|
for segment in segments:
|
||||||
rcData['segment'].append(segment)
|
rcData['segment'].append(segment)
|
||||||
print "built %i segments"%(len(rcData['segment']))
|
print " built %i segments"%(len(rcData['segment']))
|
||||||
|
|
||||||
for grain in grains['legs']:
|
for grain in grains['legs']:
|
||||||
rcData['grain'].append(grain)
|
rcData['grain'].append(grain)
|
||||||
|
@ -327,7 +327,7 @@ def rcbParser(content,M,size,tolerance): # parser for TSL-O
|
||||||
myNeighbors[grainNeighbors[leg][side]] = 1
|
myNeighbors[grainNeighbors[leg][side]] = 1
|
||||||
if myNeighbors: # do I have any neighbors
|
if myNeighbors: # do I have any neighbors
|
||||||
rcData['grainMapping'].append(sorted(myNeighbors.iteritems(), key=lambda (k,v): (v,k), reverse=True)[0][0]) # most frequent grain is me
|
rcData['grainMapping'].append(sorted(myNeighbors.iteritems(), key=lambda (k,v): (v,k), reverse=True)[0][0]) # most frequent grain is me
|
||||||
print "found %i grains\n"%(len(rcData['grain']))
|
print " found %i grains\n"%(len(rcData['grain']))
|
||||||
|
|
||||||
rcData['box'] = grains['box']
|
rcData['box'] = grains['box']
|
||||||
|
|
||||||
|
@ -791,11 +791,14 @@ def fftbuild(rcData, height,xframe,yframe,resolution,extrusion): # bu
|
||||||
# ----------------------- MAIN -------------------------------
|
# ----------------------- MAIN -------------------------------
|
||||||
|
|
||||||
parser = OptionParser(option_class=extendedOption, usage='%prog [options] datafile[s]', description = """
|
parser = OptionParser(option_class=extendedOption, usage='%prog [options] datafile[s]', description = """
|
||||||
what I do...
|
Produce image, spectral geometry description, and (auto) Mentat procedure from TSL/OIM
|
||||||
""")
|
reconstructed boundary file
|
||||||
|
|
||||||
|
""" + string.replace('$Id: spectral_iterationCount 919 2011-06-15 18:14:05Z MPIE\p.eisenlohr $','\n','\\n')
|
||||||
|
)
|
||||||
|
|
||||||
parser.add_option("-o", "--output", action='extend', dest='output', type='string', \
|
parser.add_option("-o", "--output", action='extend', dest='output', type='string', \
|
||||||
help="type of output [image,mentat,procedure,spectral]")
|
help="types of output [image,mentat,procedure,spectral]")
|
||||||
parser.add_option("-p", "--port", type="int",\
|
parser.add_option("-p", "--port", type="int",\
|
||||||
dest="port",\
|
dest="port",\
|
||||||
help="Mentat connection port")
|
help="Mentat connection port")
|
||||||
|
@ -859,6 +862,7 @@ parser.set_defaults(mesh = 'dt_planar_trimesh')
|
||||||
parser.set_defaults(twoD = False)
|
parser.set_defaults(twoD = False)
|
||||||
|
|
||||||
(options, args) = parser.parse_args()
|
(options, args) = parser.parse_args()
|
||||||
|
|
||||||
if not len(args):
|
if not len(args):
|
||||||
parser.error('no boundary file specified')
|
parser.error('no boundary file specified')
|
||||||
|
|
||||||
|
@ -873,15 +877,18 @@ except:
|
||||||
options.output = [s.lower() for s in options.output] # lower case
|
options.output = [s.lower() for s in options.output] # lower case
|
||||||
|
|
||||||
myName = os.path.splitext(args[0])[0]
|
myName = os.path.splitext(args[0])[0]
|
||||||
print "\n",myName
|
print "\n%s\n"%myName
|
||||||
|
|
||||||
orientationData = rcbOrientationParser(boundarySegments)
|
orientationData = rcbOrientationParser(boundarySegments)
|
||||||
rcData = rcbParser(boundarySegments,options.M,options.size,options.tolerance)
|
rcData = rcbParser(boundarySegments,options.M,options.size,options.tolerance)
|
||||||
|
|
||||||
# ----- write image -----
|
# ----- write image -----
|
||||||
|
|
||||||
if ImageCapability and 'image' in options.output and options.imgsize > 0:
|
if 'image' in options.output and options.imgsize > 0:
|
||||||
image(myName,options.imgsize,options.xmargin,options.ymargin,rcData)
|
if ImageCapability:
|
||||||
|
image(myName,options.imgsize,options.xmargin,options.ymargin,rcData)
|
||||||
|
else:
|
||||||
|
print '...no image drawing possible (PIL missing)...'
|
||||||
|
|
||||||
# ----- write spectral geom -----
|
# ----- write spectral geom -----
|
||||||
|
|
||||||
|
@ -895,44 +902,47 @@ if 'spectral' in options.output:
|
||||||
geomFile.write('\n'.join(map(str,fftdata['fftpoints']))+'\n') # write grain indexes, one per line
|
geomFile.write('\n'.join(map(str,fftdata['fftpoints']))+'\n') # write grain indexes, one per line
|
||||||
geomFile.close() # close geom file
|
geomFile.close() # close geom file
|
||||||
|
|
||||||
print('assigned %i out of %i Fourier points'%(len(fftdata['fftpoints']), int(fftdata['resolution'][0])*int(fftdata['resolution'][1])))
|
print('assigned %i out of %i Fourier points.'%(len(fftdata['fftpoints']), int(fftdata['resolution'][0])*int(fftdata['resolution'][1])))
|
||||||
|
|
||||||
|
|
||||||
# ----- write Mentat procedure -----
|
# ----- write Mentat procedure -----
|
||||||
|
|
||||||
if MentatCapability and 'mentat' in options.output:
|
if 'mentat' in options.output:
|
||||||
rcData['offsetPoints'] = 1+4 # gage definition generates 4 points
|
if MentatCapability:
|
||||||
rcData['offsetSegments'] = 1+4 # gage definition generates 4 segments
|
rcData['offsetPoints'] = 1+4 # gage definition generates 4 points
|
||||||
|
rcData['offsetSegments'] = 1+4 # gage definition generates 4 segments
|
||||||
|
|
||||||
cmds = [\
|
cmds = [\
|
||||||
init(),
|
init(),
|
||||||
sample(options.size,rcData['dimension'][1]/rcData['dimension'][0],12,options.xmargin,options.ymargin),
|
sample(options.size,rcData['dimension'][1]/rcData['dimension'][0],12,options.xmargin,options.ymargin),
|
||||||
patch(options.size,options.resolution,options.mesh,rcData),
|
patch(options.size,options.resolution,options.mesh,rcData),
|
||||||
gage(options.mesh,rcData),
|
gage(options.mesh,rcData),
|
||||||
|
]
|
||||||
|
|
||||||
|
if not options.twoD:
|
||||||
|
cmds += [expand3D(options.size*(1.0+2.0*options.xmargin)/options.resolution*options.extrusion,options.extrusion),]
|
||||||
|
|
||||||
|
cmds += [\
|
||||||
|
cleanUp(options.size),
|
||||||
|
materials(),
|
||||||
|
initial_conditions(len(rcData['grain']),rcData['grainMapping']),
|
||||||
|
boundary_conditions(options.strainrate,options.size*(1.0+2.0*options.xmargin)/options.resolution*options.extrusion,\
|
||||||
|
options.size,rcData['dimension'][1]/rcData['dimension'][0],options.xmargin,options.ymargin),
|
||||||
|
loadcase(options.strain/options.strainrate,options.increments,0.01),
|
||||||
|
job(len(rcData['grain']),rcData['grainMapping'],options.twoD),
|
||||||
|
postprocess(),
|
||||||
|
["*identify_sets","*regen","*fill_view","*save_as_model %s yes"%(myName)],
|
||||||
]
|
]
|
||||||
|
|
||||||
if not options.twoD:
|
outputLocals = {'log':[]}
|
||||||
cmds += [expand3D(options.size*(1.0+2.0*options.xmargin)/options.resolution*options.extrusion,options.extrusion),]
|
if (options.port != None):
|
||||||
|
py_connect('',options.port)
|
||||||
cmds += [\
|
output(cmds,outputLocals,'Mentat')
|
||||||
cleanUp(options.size),
|
py_disconnect()
|
||||||
materials(),
|
if 'procedure' in options.output:
|
||||||
initial_conditions(len(rcData['grain']),rcData['grainMapping']),
|
output(outputLocals['log'],outputLocals,'Stdout')
|
||||||
boundary_conditions(options.strainrate,options.size*(1.0+2.0*options.xmargin)/options.resolution*options.extrusion,\
|
else:
|
||||||
options.size,rcData['dimension'][1]/rcData['dimension'][0],options.xmargin,options.ymargin),
|
print '...no interaction with Mentat possible...'
|
||||||
loadcase(options.strain/options.strainrate,options.increments,0.01),
|
|
||||||
job(len(rcData['grain']),rcData['grainMapping'],options.twoD),
|
|
||||||
postprocess(),
|
|
||||||
["*identify_sets","*regen","*fill_view","*save_as_model %s yes"%(myName)],
|
|
||||||
]
|
|
||||||
|
|
||||||
outputLocals = {'log':[]}
|
|
||||||
if (options.port != None):
|
|
||||||
py_connect('',options.port)
|
|
||||||
output(cmds,outputLocals,'Mentat')
|
|
||||||
py_disconnect()
|
|
||||||
if 'procedure' in options.output:
|
|
||||||
output(outputLocals['log'],outputLocals,'Stdout')
|
|
||||||
|
|
||||||
|
|
||||||
# ----- write config data to file -----
|
# ----- write config data to file -----
|
||||||
|
|
Loading…
Reference in New Issue