generate hexahedral mesh in Mentat based on a data file of Ricardo Lebensohn's "txfft" format (phi1, Phi, phi2, x, y, z, grainId, phaseId)
Only grainId is used, physical dimension and subdivisions need to be provided on command line.
improvement possible by parsing x, y, z columns to get those directly.
2010-10-25 23:27:57 +05:30
|
|
|
#!/usr/bin/env python
|
|
|
|
|
|
|
|
import os, sys, math, re, threading, time
|
|
|
|
from optparse import OptionParser, OptionGroup, Option, SUPPRESS_HELP
|
|
|
|
|
|
|
|
releases = {'2010':['linux64',''],
|
|
|
|
'2008r1':[''],
|
|
|
|
'2007r1':[''],
|
|
|
|
'2005r3':[''],
|
|
|
|
}
|
|
|
|
|
2010-10-26 19:15:23 +05:30
|
|
|
# ----------------------- FUNCTIONS ----------------------------
|
generate hexahedral mesh in Mentat based on a data file of Ricardo Lebensohn's "txfft" format (phi1, Phi, phi2, x, y, z, grainId, phaseId)
Only grainId is used, physical dimension and subdivisions need to be provided on command line.
improvement possible by parsing x, y, z columns to get those directly.
2010-10-25 23:27:57 +05:30
|
|
|
|
|
|
|
def outMentat(cmd,locals):
|
|
|
|
if cmd[0:3] == '(!)':
|
|
|
|
exec(cmd[3:])
|
|
|
|
elif cmd[0:3] == '(?)':
|
|
|
|
cmd = eval(cmd[3:])
|
|
|
|
py_send(cmd)
|
|
|
|
else:
|
|
|
|
py_send(cmd)
|
|
|
|
return
|
|
|
|
|
|
|
|
def outStdout(cmd,locals):
|
|
|
|
if cmd[0:3] == '(!)':
|
|
|
|
exec(cmd[3:])
|
|
|
|
elif cmd[0:3] == '(?)':
|
|
|
|
cmd = eval(cmd[3:])
|
|
|
|
print cmd
|
|
|
|
else:
|
|
|
|
print cmd
|
|
|
|
return
|
|
|
|
|
|
|
|
|
|
|
|
def output(cmds,locals,dest):
|
|
|
|
for cmd in cmds:
|
|
|
|
if isinstance(cmd,list):
|
|
|
|
output(cmd,locals,dest)
|
|
|
|
else:
|
|
|
|
{\
|
|
|
|
'Mentat': outMentat,\
|
|
|
|
'Stdout': outStdout,\
|
2010-10-26 19:15:23 +05:30
|
|
|
}[dest](str(cmd),locals)
|
generate hexahedral mesh in Mentat based on a data file of Ricardo Lebensohn's "txfft" format (phi1, Phi, phi2, x, y, z, grainId, phaseId)
Only grainId is used, physical dimension and subdivisions need to be provided on command line.
improvement possible by parsing x, y, z columns to get those directly.
2010-10-25 23:27:57 +05:30
|
|
|
return
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def init():
|
|
|
|
return ["*new_model yes",
|
|
|
|
"*reset",
|
|
|
|
"*select_clear",
|
|
|
|
"*set_element_class hex8",
|
|
|
|
"*set_nodes off",
|
|
|
|
"*elements_solid",
|
|
|
|
"*show_view 4",
|
|
|
|
"*reset_view",
|
|
|
|
"*view_perspective",
|
|
|
|
"*redraw",
|
|
|
|
]
|
|
|
|
|
|
|
|
|
|
|
|
def mesh(N,d):
|
|
|
|
return [
|
|
|
|
"*add_nodes",
|
|
|
|
"%f %f %f"%(0.0,0.0,0.0),
|
|
|
|
"%f %f %f"%(0.0,0.0,d[2]),
|
|
|
|
"%f %f %f"%(0.0,d[1],d[2]),
|
|
|
|
"%f %f %f"%(0.0,d[1],0.0),
|
|
|
|
"%f %f %f"%(-d[0],0.0,0.0),
|
|
|
|
"%f %f %f"%(-d[0],0.0,d[2]),
|
|
|
|
"%f %f %f"%(-d[0],d[1],d[2]),
|
|
|
|
"%f %f %f"%(-d[0],d[1],0.0),
|
|
|
|
"*add_elements",
|
2010-10-26 19:15:23 +05:30
|
|
|
range(1,9),
|
generate hexahedral mesh in Mentat based on a data file of Ricardo Lebensohn's "txfft" format (phi1, Phi, phi2, x, y, z, grainId, phaseId)
Only grainId is used, physical dimension and subdivisions need to be provided on command line.
improvement possible by parsing x, y, z columns to get those directly.
2010-10-25 23:27:57 +05:30
|
|
|
"*sub_divisions",
|
|
|
|
"%i %i %i"%(N[2],N[1],N[0]),
|
|
|
|
"*subdivide_elements",
|
|
|
|
"all_existing",
|
|
|
|
"*set_sweep_tolerance",
|
|
|
|
"%f"%(float(min(d))/max(N)/2.0),
|
|
|
|
"*sweep_all",
|
|
|
|
"*renumber_all",
|
|
|
|
"*set_move_scale_factor x -1",
|
|
|
|
"*move_elements",
|
|
|
|
"all_existing",
|
|
|
|
"*flip_elements",
|
|
|
|
"all_existing",
|
|
|
|
"*fill_view",
|
|
|
|
]
|
|
|
|
|
|
|
|
|
2010-10-26 19:15:23 +05:30
|
|
|
def material():
|
|
|
|
cmds = [\
|
|
|
|
"*new_mater standard",
|
|
|
|
"*mater_option general:state:solid",
|
|
|
|
"*mater_option structural:type:hypo_ealst",
|
|
|
|
"*mater_name",
|
|
|
|
"hypela2",
|
|
|
|
"*add_mater_elements",
|
|
|
|
"all_existing",
|
|
|
|
"*geometry_type mech_three_solid",
|
|
|
|
"*geometry_option red_integ_capacity:on",
|
|
|
|
"*add_geometry_elements",
|
|
|
|
"all_existing",
|
|
|
|
]
|
|
|
|
|
|
|
|
return cmds
|
|
|
|
|
|
|
|
|
|
|
|
def geometry():
|
|
|
|
cmds = [\
|
|
|
|
"*geometry_type mech_three_solid",
|
|
|
|
"*geometry_option red_integ_capacity:on",
|
|
|
|
"*add_geometry_elements",
|
|
|
|
"all_existing",
|
2010-10-26 21:56:55 +05:30
|
|
|
"*element_type 117",
|
|
|
|
"all_existing",
|
2010-10-26 19:15:23 +05:30
|
|
|
]
|
|
|
|
|
|
|
|
return cmds
|
|
|
|
|
generate hexahedral mesh in Mentat based on a data file of Ricardo Lebensohn's "txfft" format (phi1, Phi, phi2, x, y, z, grainId, phaseId)
Only grainId is used, physical dimension and subdivisions need to be provided on command line.
improvement possible by parsing x, y, z columns to get those directly.
2010-10-25 23:27:57 +05:30
|
|
|
|
|
|
|
def initial_conditions(N,data):
|
|
|
|
elements = []
|
|
|
|
element = 0
|
|
|
|
for line in data:
|
|
|
|
element += 1
|
|
|
|
phi1,phi,phi2,x,y,z,id,phase = line.split()
|
|
|
|
id = int(id)
|
|
|
|
if len(elements) < id:
|
|
|
|
for i in range(id-len(elements)):
|
|
|
|
elements.append([])
|
|
|
|
elements[id-1].append(element)
|
|
|
|
|
|
|
|
cmds = [\
|
2010-10-26 21:56:55 +05:30
|
|
|
"*new_icond",
|
|
|
|
"*icond_name temperature",
|
|
|
|
"*icond_type state_variable",
|
|
|
|
"*icond_param_value state_var_id 1",
|
|
|
|
"*icond_dof_value var 300",
|
|
|
|
"*add_icond_elements",
|
|
|
|
"all_existing",
|
generate hexahedral mesh in Mentat based on a data file of Ricardo Lebensohn's "txfft" format (phi1, Phi, phi2, x, y, z, grainId, phaseId)
Only grainId is used, physical dimension and subdivisions need to be provided on command line.
improvement possible by parsing x, y, z columns to get those directly.
2010-10-25 23:27:57 +05:30
|
|
|
"*new_icond",
|
|
|
|
"*icond_name homogenization",
|
|
|
|
"*icond_type state_variable",
|
|
|
|
"*icond_param_value state_var_id 2",
|
|
|
|
"*icond_dof_value var 1",
|
|
|
|
"*add_icond_elements",
|
|
|
|
"all_existing",
|
|
|
|
]
|
|
|
|
|
|
|
|
for grain,elementList in enumerate(elements):
|
|
|
|
cmds.append([\
|
|
|
|
"*new_icond",
|
|
|
|
"*icond_name microstructure_%i"%(grain+1),
|
|
|
|
"*icond_type state_variable",
|
|
|
|
"*icond_param_value state_var_id 3",
|
|
|
|
"*icond_dof_value var %i"%(grain+1),
|
|
|
|
"*add_icond_elements",
|
2010-10-26 19:15:23 +05:30
|
|
|
elementList,
|
generate hexahedral mesh in Mentat based on a data file of Ricardo Lebensohn's "txfft" format (phi1, Phi, phi2, x, y, z, grainId, phaseId)
Only grainId is used, physical dimension and subdivisions need to be provided on command line.
improvement possible by parsing x, y, z columns to get those directly.
2010-10-25 23:27:57 +05:30
|
|
|
"#",
|
|
|
|
])
|
|
|
|
return cmds
|
|
|
|
|
|
|
|
|
|
|
|
# ----------------------- MAIN -------------------------------
|
2010-10-26 19:15:23 +05:30
|
|
|
|
generate hexahedral mesh in Mentat based on a data file of Ricardo Lebensohn's "txfft" format (phi1, Phi, phi2, x, y, z, grainId, phaseId)
Only grainId is used, physical dimension and subdivisions need to be provided on command line.
improvement possible by parsing x, y, z columns to get those directly.
2010-10-25 23:27:57 +05:30
|
|
|
parser = OptionParser()
|
|
|
|
parser.add_option("-p", "--port", type="int",\
|
|
|
|
dest="port",\
|
|
|
|
help="Mentat connection port")
|
|
|
|
parser.add_option("-d", "--dimension", type="int", nargs=3,\
|
|
|
|
dest="d",\
|
|
|
|
help="physical dimension")
|
|
|
|
parser.add_option("-N", "--subdivisions", type="int", nargs=3,\
|
|
|
|
dest="N",\
|
|
|
|
help="number of subdivisions")
|
|
|
|
|
|
|
|
parser.set_defaults(d = (16,16,16))
|
|
|
|
parser.set_defaults(N = (16,16,16))
|
|
|
|
|
2010-10-26 19:15:23 +05:30
|
|
|
try:
|
2010-10-26 21:56:55 +05:30
|
|
|
file = open('%s/../MSCpath'%os.path.dirname(os.path.realpath(sys.argv[0])))
|
2010-10-26 19:15:23 +05:30
|
|
|
MSCpath = os.path.normpath(file.readline().strip())
|
|
|
|
file.close()
|
|
|
|
except:
|
|
|
|
MSCpath = '/msc'
|
|
|
|
|
|
|
|
for release,subdirs in sorted(releases.items(),reverse=True):
|
|
|
|
for subdir in subdirs:
|
|
|
|
libPath = '%s/mentat%s/shlib/%s'%(MSCpath,release,subdir)
|
|
|
|
if os.path.exists(libPath):
|
|
|
|
sys.path.append(libPath)
|
|
|
|
break
|
|
|
|
else:
|
|
|
|
continue
|
|
|
|
break
|
|
|
|
|
|
|
|
try:
|
|
|
|
from py_mentat import *
|
|
|
|
except:
|
|
|
|
print('error: no valid Mentat release found in %s'%MSCpath)
|
|
|
|
sys.exit(-1)
|
|
|
|
|
generate hexahedral mesh in Mentat based on a data file of Ricardo Lebensohn's "txfft" format (phi1, Phi, phi2, x, y, z, grainId, phaseId)
Only grainId is used, physical dimension and subdivisions need to be provided on command line.
improvement possible by parsing x, y, z columns to get those directly.
2010-10-25 23:27:57 +05:30
|
|
|
(options, args) = parser.parse_args()
|
|
|
|
|
|
|
|
if not os.path.isfile(args[0]):
|
|
|
|
parser.error("cannot open %s"%args[0])
|
|
|
|
|
|
|
|
file = open(args[0])
|
|
|
|
content = file.readlines()
|
|
|
|
file.close()
|
|
|
|
|
|
|
|
cmds = [\
|
|
|
|
init(),
|
|
|
|
mesh(options.N,options.d),
|
2010-10-26 19:15:23 +05:30
|
|
|
material(),
|
|
|
|
geometry(),
|
generate hexahedral mesh in Mentat based on a data file of Ricardo Lebensohn's "txfft" format (phi1, Phi, phi2, x, y, z, grainId, phaseId)
Only grainId is used, physical dimension and subdivisions need to be provided on command line.
improvement possible by parsing x, y, z columns to get those directly.
2010-10-25 23:27:57 +05:30
|
|
|
initial_conditions(options.N,content),
|
|
|
|
]
|
|
|
|
|
|
|
|
outputLocals = {}
|
|
|
|
if (options.port != None):
|
|
|
|
py_connect('',options.port)
|
|
|
|
output(cmds,outputLocals,'Mentat')
|
|
|
|
py_disconnect()
|
|
|
|
else:
|
|
|
|
output(cmds,outputLocals,'Stdout')
|
2010-10-26 19:15:23 +05:30
|
|
|
|