2016-07-18 23:05:35 +05:30
|
|
|
#!/usr/bin/env python2.7
|
2013-05-13 16:57:59 +05:30
|
|
|
# -*- coding: UTF-8 no BOM -*-
|
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
|
|
|
|
2016-03-02 17:13:09 +05:30
|
|
|
import os,sys
|
2015-09-05 20:16:57 +05:30
|
|
|
import numpy as np
|
2014-10-13 19:28:26 +05:30
|
|
|
from optparse import OptionParser
|
|
|
|
import damask
|
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
|
|
|
|
2016-01-27 22:36:00 +05:30
|
|
|
scriptName = os.path.splitext(os.path.basename(__file__))[0]
|
|
|
|
scriptID = ' '.join([scriptName,damask.version])
|
2016-07-18 09:47:22 +05:30
|
|
|
sys.path.append(damask.solver.Marc().libraryPath())
|
2013-07-18 18:58:54 +05:30
|
|
|
|
2013-05-13 16:57:59 +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
|
|
|
def outMentat(cmd,locals):
|
|
|
|
if cmd[0:3] == '(!)':
|
|
|
|
exec(cmd[3:])
|
|
|
|
elif cmd[0:3] == '(?)':
|
|
|
|
cmd = eval(cmd[3:])
|
2016-03-02 17:13:09 +05:30
|
|
|
py_mentat.py_send(cmd)
|
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
|
|
|
else:
|
2016-03-02 17:13:09 +05:30
|
|
|
py_mentat.py_send(cmd)
|
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
|
|
|
|
|
2013-05-13 16:57:59 +05:30
|
|
|
#-------------------------------------------------------------------------------------------------
|
2015-05-21 00:37:52 +05:30
|
|
|
def outFile(cmd,locals,dest):
|
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
|
|
|
if cmd[0:3] == '(!)':
|
|
|
|
exec(cmd[3:])
|
|
|
|
elif cmd[0:3] == '(?)':
|
|
|
|
cmd = eval(cmd[3:])
|
2015-05-21 00:37:52 +05:30
|
|
|
dest.write(cmd+'\n')
|
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
|
|
|
else:
|
2015-05-21 00:37:52 +05:30
|
|
|
dest.write(cmd+'\n')
|
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
|
|
|
|
|
2013-05-13 16:57:59 +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
|
|
|
def output(cmds,locals,dest):
|
|
|
|
for cmd in cmds:
|
|
|
|
if isinstance(cmd,list):
|
|
|
|
output(cmd,locals,dest)
|
|
|
|
else:
|
2015-05-21 00:37:52 +05:30
|
|
|
if dest == 'Mentat':
|
|
|
|
outMentat(str(cmd),locals)
|
|
|
|
else:
|
|
|
|
outFile(str(cmd),locals,dest)
|
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
|
|
|
|
|
|
|
|
|
|
|
|
|
2013-05-13 16:57:59 +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
|
|
|
def init():
|
2016-03-02 17:13:09 +05:30
|
|
|
return [
|
|
|
|
"#"+' '.join([scriptID] + sys.argv[1:]),
|
|
|
|
"*draw_manual", # prevent redrawing in Mentat, should be much faster
|
|
|
|
"*new_model yes",
|
|
|
|
"*reset",
|
|
|
|
"*select_clear",
|
|
|
|
"*set_element_class hex8",
|
|
|
|
"*set_nodes off",
|
|
|
|
"*elements_solid",
|
|
|
|
"*show_view 4",
|
|
|
|
"*reset_view",
|
|
|
|
"*view_perspective",
|
|
|
|
"*redraw",
|
|
|
|
]
|
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
|
|
|
|
|
|
|
|
2013-05-13 16:57:59 +05:30
|
|
|
#-------------------------------------------------------------------------------------------------
|
2011-01-24 21:51:17 +05:30
|
|
|
def mesh(r,d):
|
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 [
|
|
|
|
"*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",
|
2011-01-24 21:51:17 +05:30
|
|
|
"%i %i %i"%(r[2],r[1],r[0]),
|
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
|
|
|
"*subdivide_elements",
|
|
|
|
"all_existing",
|
|
|
|
"*set_sweep_tolerance",
|
2011-01-24 21:51:17 +05:30
|
|
|
"%f"%(float(min(d))/max(r)/2.0),
|
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
|
|
|
"*sweep_all",
|
|
|
|
"*renumber_all",
|
|
|
|
"*set_move_scale_factor x -1",
|
|
|
|
"*move_elements",
|
|
|
|
"all_existing",
|
|
|
|
"*flip_elements",
|
|
|
|
"all_existing",
|
|
|
|
"*fill_view",
|
|
|
|
]
|
|
|
|
|
|
|
|
|
2013-05-13 16:57:59 +05:30
|
|
|
#-------------------------------------------------------------------------------------------------
|
2010-10-26 19:15:23 +05:30
|
|
|
def material():
|
|
|
|
cmds = [\
|
|
|
|
"*new_mater standard",
|
|
|
|
"*mater_option general:state:solid",
|
2010-10-26 23:56:04 +05:30
|
|
|
"*mater_option structural:type:hypo_elast",
|
2010-10-26 19:15:23 +05:30
|
|
|
"*mater_name",
|
|
|
|
"hypela2",
|
|
|
|
"*add_mater_elements",
|
|
|
|
"all_existing",
|
|
|
|
"*geometry_type mech_three_solid",
|
2016-03-02 17:13:09 +05:30
|
|
|
# "*geometry_option red_integ_capacity:on", reduced integration with one IP gave trouble being always OUTDATED...
|
2010-10-26 19:15:23 +05:30
|
|
|
"*add_geometry_elements",
|
|
|
|
"all_existing",
|
|
|
|
]
|
|
|
|
|
|
|
|
return cmds
|
|
|
|
|
|
|
|
|
2013-05-13 16:57:59 +05:30
|
|
|
#-------------------------------------------------------------------------------------------------
|
2010-10-26 19:15:23 +05:30
|
|
|
def geometry():
|
|
|
|
cmds = [\
|
|
|
|
"*geometry_type mech_three_solid",
|
2011-01-27 20:02:29 +05:30
|
|
|
# "*geometry_option red_integ_capacity:on",
|
2010-10-26 19:15:23 +05:30
|
|
|
"*add_geometry_elements",
|
|
|
|
"all_existing",
|
2016-03-02 17:13:09 +05:30
|
|
|
# we are NOT using reduced integration (type 117) but opt for /elementhomogeneous/ in the respective phase description (material.config)
|
|
|
|
"*element_type 7",
|
2010-10-26 21:56:55 +05:30
|
|
|
"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
|
|
|
|
2013-05-13 16:57:59 +05:30
|
|
|
#-------------------------------------------------------------------------------------------------
|
|
|
|
def initial_conditions(homogenization,microstructures):
|
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
|
|
|
elements = []
|
|
|
|
element = 0
|
2013-05-13 16:57:59 +05:30
|
|
|
for id in microstructures:
|
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
|
|
|
element += 1
|
|
|
|
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",
|
2011-01-24 21:51:17 +05:30
|
|
|
"*icond_name _temperature",
|
2010-10-26 21:56:55 +05:30
|
|
|
"*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",
|
2011-01-24 21:51:17 +05:30
|
|
|
"*icond_name _homogenization",
|
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
|
|
|
"*icond_type state_variable",
|
|
|
|
"*icond_param_value state_var_id 2",
|
2011-01-24 21:51:17 +05:30
|
|
|
"*icond_dof_value var %i"%homogenization,
|
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
|
|
|
"*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
|
|
|
|
|
|
|
|
|
2013-05-13 16:57:59 +05:30
|
|
|
#--------------------------------------------------------------------------------------------------
|
|
|
|
# MAIN
|
|
|
|
#--------------------------------------------------------------------------------------------------
|
2014-10-13 19:28:26 +05:30
|
|
|
|
|
|
|
parser = OptionParser(option_class=damask.extendableOption, usage='%prog options [file[s]]', description = """
|
2015-08-21 01:12:05 +05:30
|
|
|
Generate MSC.Marc FE hexahedral mesh from geom file.
|
2011-01-24 21:51:17 +05:30
|
|
|
|
2014-10-13 19:28:26 +05:30
|
|
|
""", version = scriptID)
|
|
|
|
|
2015-08-21 01:12:05 +05:30
|
|
|
parser.add_option('-p', '--port',
|
|
|
|
dest = 'port',
|
|
|
|
type = 'int', metavar = 'int',
|
|
|
|
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,
|
|
|
|
homogenization = None,
|
|
|
|
)
|
2011-01-24 21:51:17 +05:30
|
|
|
|
2015-04-23 00:27:44 +05:30
|
|
|
(options, filenames) = parser.parse_args()
|
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
|
|
|
|
2015-08-21 01:12:05 +05:30
|
|
|
if options.port:
|
|
|
|
try:
|
2016-03-02 17:13:09 +05:30
|
|
|
import py_mentat
|
2015-08-21 01:12:05 +05:30
|
|
|
except:
|
|
|
|
parser.error('no valid Mentat release found.')
|
|
|
|
|
|
|
|
# --- loop over input files -------------------------------------------------------------------------
|
|
|
|
|
|
|
|
if filenames == []: filenames = [None]
|
|
|
|
|
|
|
|
for name in filenames:
|
|
|
|
try:
|
|
|
|
table = damask.ASCIItable(name = name,
|
|
|
|
outname = os.path.splitext(name)[0]+'.proc' if name else name,
|
|
|
|
buffered = False, labeled = False)
|
|
|
|
except: continue
|
2015-12-03 01:32:19 +05:30
|
|
|
damask.util.report(scriptName,name)
|
2015-08-21 01:12:05 +05:30
|
|
|
|
|
|
|
# --- interpret header ----------------------------------------------------------------------------
|
|
|
|
|
|
|
|
table.head_read()
|
|
|
|
info,extra_header = table.head_getGeom()
|
|
|
|
if options.homogenization: info['homogenization'] = options.homogenization
|
|
|
|
|
2015-12-03 01:32:19 +05:30
|
|
|
damask.util.croak(['grid a b c: %s'%(' x '.join(map(str,info['grid']))),
|
|
|
|
'size x y z: %s'%(' x '.join(map(str,info['size']))),
|
|
|
|
'origin x y z: %s'%(' : '.join(map(str,info['origin']))),
|
|
|
|
'homogenization: %i'%info['homogenization'],
|
|
|
|
'microstructures: %i'%info['microstructures'],
|
2015-08-21 01:12:05 +05:30
|
|
|
])
|
|
|
|
|
|
|
|
errors = []
|
|
|
|
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 != []:
|
2015-12-03 01:32:19 +05:30
|
|
|
damask.util.croak(errors)
|
2015-08-21 01:12:05 +05:30
|
|
|
table.close(dismiss = True)
|
|
|
|
continue
|
|
|
|
|
|
|
|
# --- read data ------------------------------------------------------------------------------------
|
|
|
|
|
2015-09-05 20:16:57 +05:30
|
|
|
microstructure = table.microstructure_read(info['grid']).reshape(info['grid'].prod(),order='F') # read microstructure
|
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
|
|
|
|
2015-04-23 00:27:44 +05:30
|
|
|
cmds = [\
|
|
|
|
init(),
|
2015-08-21 01:12:05 +05:30
|
|
|
mesh(info['grid'],info['size']),
|
2015-04-23 00:27:44 +05:30
|
|
|
material(),
|
|
|
|
geometry(),
|
2015-08-21 01:12:05 +05:30
|
|
|
initial_conditions(info['homogenization'],microstructure),
|
2015-04-23 00:27:44 +05:30
|
|
|
'*identify_sets',
|
2015-05-21 00:37:52 +05:30
|
|
|
'*show_model',
|
2015-04-23 00:27:44 +05:30
|
|
|
'*redraw',
|
|
|
|
]
|
|
|
|
|
|
|
|
outputLocals = {}
|
2015-08-21 01:12:05 +05:30
|
|
|
if options.port:
|
2016-03-02 17:13:09 +05:30
|
|
|
py_mentat.py_connect('',options.port)
|
2015-04-23 00:27:44 +05:30
|
|
|
output(cmds,outputLocals,'Mentat')
|
2016-03-02 17:13:09 +05:30
|
|
|
py_mentat.py_disconnect()
|
2015-04-23 00:27:44 +05:30
|
|
|
else:
|
2015-08-21 01:12:05 +05:30
|
|
|
output(cmds,outputLocals,table.__IO__['out']) # bad hack into internals of table class...
|
|
|
|
|
|
|
|
table.close()
|