2018-11-17 12:42:12 +05:30
|
|
|
#!/usr/bin/env python3
|
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
|
|
|
|
2019-12-08 14:01:56 +05:30
|
|
|
import os
|
|
|
|
import sys
|
2019-12-08 22:51:16 +05:30
|
|
|
from io import StringIO
|
2014-10-13 19:28:26 +05:30
|
|
|
from optparse import OptionParser
|
2019-12-08 14:01:56 +05:30
|
|
|
|
2014-10-13 19:28:26 +05:30
|
|
|
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
|
|
|
|
2022-11-28 13:51:47 +05:30
|
|
|
script_name = os.path.splitext(os.path.basename(__file__))[0]
|
|
|
|
script_id = ' '.join([script_name,damask.version])
|
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
|
|
|
|
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
|
|
|
|
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
|
|
|
|
2020-09-21 20:43:53 +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 init():
|
2016-03-02 17:13:09 +05:30
|
|
|
return [
|
2022-11-28 13:51:47 +05:30
|
|
|
"|"+' '.join([script_id] + sys.argv[1:]),
|
2016-03-02 17:13:09 +05:30
|
|
|
"*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),
|
2023-10-27 20:48:02 +05:30
|
|
|
"%f %f %f"%(d[0],0.0,0.0),
|
|
|
|
"%f %f %f"%(d[0],d[1],0.0),
|
|
|
|
"%f %f %f"%(0.0,d[1],0.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
|
|
|
"%f %f %f"%(0.0,0.0,d[2]),
|
2023-10-27 20:48:02 +05:30
|
|
|
"%f %f %f"%(d[0],0.0,d[2]),
|
|
|
|
"%f %f %f"%(d[0],d[1],d[2]),
|
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
|
|
|
"%f %f %f"%(0.0,d[1],d[2]),
|
|
|
|
"*add_elements",
|
2018-07-20 07:01:46 +05:30
|
|
|
"1",
|
|
|
|
"2",
|
|
|
|
"3",
|
|
|
|
"4",
|
|
|
|
"5",
|
|
|
|
"6",
|
|
|
|
"7",
|
|
|
|
"8",
|
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",
|
2023-10-27 20:48:02 +05:30
|
|
|
"%i %i %i"%(r[0],r[1],r[2]),
|
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",
|
2023-10-27 20:48:02 +05:30
|
|
|
"*remove_unused_nodes",
|
|
|
|
"*set_renumber_direction",
|
|
|
|
"%i %i %i"%(1,r[0],r[0]*r[1]),
|
|
|
|
"*renumber_elements_directed",
|
|
|
|
"*renumber_nodes_directed",
|
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
|
|
|
#-------------------------------------------------------------------------------------------------
|
2020-09-24 02:57:15 +05:30
|
|
|
def materials():
|
2020-08-08 21:52:34 +05:30
|
|
|
return [\
|
2010-10-26 19:15:23 +05:30
|
|
|
"*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",
|
|
|
|
]
|
2020-09-21 20:43:53 +05:30
|
|
|
|
2010-10-26 19:15:23 +05:30
|
|
|
|
2013-05-13 16:57:59 +05:30
|
|
|
#-------------------------------------------------------------------------------------------------
|
2010-10-26 19:15:23 +05:30
|
|
|
def geometry():
|
2020-08-08 21:52:34 +05:30
|
|
|
return [\
|
2010-10-26 19:15:23 +05:30
|
|
|
"*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
|
|
|
]
|
2020-09-21 20:43:53 +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
|
|
|
|
2013-05-13 16:57:59 +05:30
|
|
|
#-------------------------------------------------------------------------------------------------
|
2020-09-24 02:57:15 +05:30
|
|
|
def initial_conditions(material):
|
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
|
2020-09-24 02:57:15 +05:30
|
|
|
for id in material:
|
2020-09-21 20:43:53 +05:30
|
|
|
element += 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
|
|
|
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",
|
2023-10-27 20:48:02 +05:30
|
|
|
"*icond_type elem_temperature_state",
|
2010-10-26 21:56:55 +05:30
|
|
|
"*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
|
|
|
]
|
|
|
|
|
|
|
|
for grain,elementList in enumerate(elements):
|
|
|
|
cmds.append([\
|
|
|
|
"*new_icond",
|
2020-09-23 00:52:58 +05:30
|
|
|
"*icond_name material_%i"%(grain+1),
|
2023-10-27 20:48:02 +05:30
|
|
|
"*icond_type elem_user_state",
|
2020-09-07 20:31:38 +05:30
|
|
|
"*icond_param_value state_var_id 2",
|
2023-10-27 20:48:02 +05:30
|
|
|
"*icond_dof_value var %i"%(grain),
|
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",
|
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
|
|
|
|
2020-11-14 23:30:51 +05:30
|
|
|
parser = OptionParser(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
|
|
|
|
2022-11-28 13:51:47 +05:30
|
|
|
""", version = script_id)
|
2014-10-13 19:28:26 +05:30
|
|
|
|
2015-08-21 01:12:05 +05:30
|
|
|
parser.add_option('-p', '--port',
|
|
|
|
dest = 'port',
|
|
|
|
type = 'int', metavar = 'int',
|
|
|
|
help = 'Mentat connection port [%default]')
|
|
|
|
|
2019-12-08 14:01:56 +05:30
|
|
|
parser.set_defaults(port = 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
|
|
|
|
2019-12-08 14:01:56 +05:30
|
|
|
if options.port is not None:
|
|
|
|
try:
|
2020-11-20 00:56:15 +05:30
|
|
|
sys.path.append(str(damask.solver.Marc().library_path))
|
2019-12-08 14:01:56 +05:30
|
|
|
import py_mentat
|
|
|
|
except ImportError:
|
2020-11-20 00:56:15 +05:30
|
|
|
parser.error('no valid Mentat release found')
|
2015-08-21 01:12:05 +05:30
|
|
|
|
2018-07-20 07:01:46 +05:30
|
|
|
# --- loop over input files ------------------------------------------------------------------------
|
2015-08-21 01:12:05 +05:30
|
|
|
|
|
|
|
if filenames == []: filenames = [None]
|
|
|
|
|
|
|
|
for name in filenames:
|
2022-11-28 13:51:47 +05:30
|
|
|
print(script_name+': '+name)
|
2020-09-21 20:43:53 +05:30
|
|
|
|
2020-12-04 11:42:18 +05:30
|
|
|
geom = damask.Grid.load(StringIO(''.join(sys.stdin.read())) if name is None else name)
|
2020-09-24 02:57:15 +05:30
|
|
|
material = geom.material.flatten(order='F')
|
2019-12-08 14:01:56 +05:30
|
|
|
|
|
|
|
cmds = [\
|
|
|
|
init(),
|
2020-12-04 02:28:24 +05:30
|
|
|
mesh(geom.cells,geom.size),
|
2020-09-24 02:57:15 +05:30
|
|
|
materials(),
|
2019-12-08 14:01:56 +05:30
|
|
|
geometry(),
|
2020-09-24 02:57:15 +05:30
|
|
|
initial_conditions(material),
|
2019-12-08 14:01:56 +05:30
|
|
|
'*identify_sets',
|
|
|
|
'*show_model',
|
|
|
|
'*redraw',
|
|
|
|
'*draw_automatic',
|
2023-10-27 20:48:02 +05:30
|
|
|
'*fill_view',
|
2019-12-08 14:01:56 +05:30
|
|
|
]
|
2020-09-21 20:43:53 +05:30
|
|
|
|
2022-11-28 13:51:47 +05:30
|
|
|
output_locals = {}
|
2019-12-08 14:01:56 +05:30
|
|
|
if options.port:
|
|
|
|
py_mentat.py_connect('',options.port)
|
2022-11-28 13:51:47 +05:30
|
|
|
output(cmds,output_locals,'Mentat')
|
2019-12-08 14:01:56 +05:30
|
|
|
py_mentat.py_disconnect()
|
|
|
|
else:
|
|
|
|
with sys.stdout if name is None else open(os.path.splitext(name)[0]+'.proc','w') as f:
|
2022-11-28 13:51:47 +05:30
|
|
|
output(cmds,output_locals,f)
|