adopting to Python standards
This commit is contained in:
parent
20f984fc87
commit
03a81b81e8
|
@ -11,8 +11,8 @@ import numpy as np
|
||||||
|
|
||||||
import damask
|
import damask
|
||||||
|
|
||||||
scriptName = os.path.splitext(os.path.basename(__file__))[0]
|
script_name = os.path.splitext(os.path.basename(__file__))[0]
|
||||||
scriptID = ' '.join([scriptName,damask.version])
|
script_id = ' '.join([script_name,damask.version])
|
||||||
|
|
||||||
# Convert .mfd file into a usable format
|
# Convert .mfd file into a usable format
|
||||||
# Broken into labeled sections (eg. nodes, links, etc)
|
# Broken into labeled sections (eg. nodes, links, etc)
|
||||||
|
@ -143,7 +143,7 @@ def add_servoLinks(mfd_data,active=[True,True,True]): # directions on which to
|
||||||
|
|
||||||
if Nmax > 0 and Nmax >= Nmin: # node is on at least as many front than back faces
|
if Nmax > 0 and Nmax >= Nmin: # node is on at least as many front than back faces
|
||||||
if any([maxFlag[i] and active[i] for i in range(3)]):
|
if any([maxFlag[i] and active[i] for i in range(3)]):
|
||||||
linkNodes.append({'id': node+1,'coord': NodeCoords[node], 'faceMember': [maxFlag[i] and active[i] for i in range(3)]})
|
linkNodes.append({'id':node+1,'coord':NodeCoords[node],'faceMember':[maxFlag[i] and active[i] for i in range(3)]})
|
||||||
|
|
||||||
mfd_data[mfd_dict['entities']]['els'][0][0] += len(linkNodes) * 3
|
mfd_data[mfd_dict['entities']]['els'][0][0] += len(linkNodes) * 3
|
||||||
|
|
||||||
|
@ -209,7 +209,7 @@ def add_servoLinks(mfd_data,active=[True,True,True]): # directions on which to
|
||||||
parser = OptionParser(usage='%prog options [file[s]]', description = """
|
parser = OptionParser(usage='%prog options [file[s]]', description = """
|
||||||
Set up servo linking to achieve periodic boundary conditions for a regular hexahedral mesh.
|
Set up servo linking to achieve periodic boundary conditions for a regular hexahedral mesh.
|
||||||
Use *py_connection to operate on model presently opened in MSC.Mentat.
|
Use *py_connection to operate on model presently opened in MSC.Mentat.
|
||||||
""", version = scriptID)
|
""", version = script_id)
|
||||||
|
|
||||||
parser.add_option('-p', '--port',
|
parser.add_option('-p', '--port',
|
||||||
type = int, metavar = 'int', default = None,
|
type = int, metavar = 'int', default = None,
|
||||||
|
@ -236,7 +236,7 @@ if remote:
|
||||||
sys.path.append(str(damask.solver.Marc().library_path))
|
sys.path.append(str(damask.solver.Marc().library_path))
|
||||||
import py_mentat
|
import py_mentat
|
||||||
|
|
||||||
print(scriptName+': waiting to connect...')
|
print(script_name+': waiting to connect...')
|
||||||
filenames = [os.path.join(tempfile._get_default_tempdir(), next(tempfile._get_candidate_names()) + '.mfd')]
|
filenames = [os.path.join(tempfile._get_default_tempdir(), next(tempfile._get_candidate_names()) + '.mfd')]
|
||||||
try:
|
try:
|
||||||
py_mentat.py_connect('',options.port)
|
py_mentat.py_connect('',options.port)
|
||||||
|
@ -250,13 +250,13 @@ if remote:
|
||||||
|
|
||||||
for name in filenames:
|
for name in filenames:
|
||||||
while remote and not os.path.exists(name): time.sleep(0.5)
|
while remote and not os.path.exists(name): time.sleep(0.5)
|
||||||
with open( name,'r') if name is not None else sys.stdin as fileIn:
|
with open( name,'r') if name is not None else sys.stdin as file_in:
|
||||||
print(scriptName+': '+name)
|
print(script_name+': '+name)
|
||||||
mfd = parseMFD(fileIn)
|
mfd = parseMFD(file_in)
|
||||||
|
|
||||||
add_servoLinks(mfd,[options.x,options.y,options.z])
|
add_servoLinks(mfd,[options.x,options.y,options.z])
|
||||||
with open( name,'w') if name is not None else sys.stdout as fileOut:
|
with open( name,'w') if name is not None else sys.stdout as file_out:
|
||||||
fileOut.write(asMFD(mfd))
|
file_out.write(asMFD(mfd))
|
||||||
|
|
||||||
if remote:
|
if remote:
|
||||||
py_mentat.py_send('*open_model "{}"'.format(filenames[0]))
|
py_mentat.py_send('*open_model "{}"'.format(filenames[0]))
|
||||||
|
|
|
@ -7,8 +7,8 @@ from optparse import OptionParser
|
||||||
|
|
||||||
import damask
|
import damask
|
||||||
|
|
||||||
scriptName = os.path.splitext(os.path.basename(__file__))[0]
|
script_name = os.path.splitext(os.path.basename(__file__))[0]
|
||||||
scriptID = ' '.join([scriptName,damask.version])
|
script_id = ' '.join([script_name,damask.version])
|
||||||
|
|
||||||
#-------------------------------------------------------------------------------------------------
|
#-------------------------------------------------------------------------------------------------
|
||||||
def outMentat(cmd,locals):
|
def outMentat(cmd,locals):
|
||||||
|
@ -45,7 +45,7 @@ def output(cmds,locals,dest):
|
||||||
#-------------------------------------------------------------------------------------------------
|
#-------------------------------------------------------------------------------------------------
|
||||||
def init():
|
def init():
|
||||||
return [
|
return [
|
||||||
"|"+' '.join([scriptID] + sys.argv[1:]),
|
"|"+' '.join([script_id] + sys.argv[1:]),
|
||||||
"*draw_manual", # prevent redrawing in Mentat, should be much faster
|
"*draw_manual", # prevent redrawing in Mentat, should be much faster
|
||||||
"*new_model yes",
|
"*new_model yes",
|
||||||
"*reset",
|
"*reset",
|
||||||
|
@ -170,7 +170,7 @@ def initial_conditions(material):
|
||||||
parser = OptionParser(usage='%prog options [file[s]]', description = """
|
parser = OptionParser(usage='%prog options [file[s]]', description = """
|
||||||
Generate MSC.Marc FE hexahedral mesh from geom file.
|
Generate MSC.Marc FE hexahedral mesh from geom file.
|
||||||
|
|
||||||
""", version = scriptID)
|
""", version = script_id)
|
||||||
|
|
||||||
parser.add_option('-p', '--port',
|
parser.add_option('-p', '--port',
|
||||||
dest = 'port',
|
dest = 'port',
|
||||||
|
@ -194,7 +194,7 @@ if options.port is not None:
|
||||||
if filenames == []: filenames = [None]
|
if filenames == []: filenames = [None]
|
||||||
|
|
||||||
for name in filenames:
|
for name in filenames:
|
||||||
print(scriptName+': '+name)
|
print(script_name+': '+name)
|
||||||
|
|
||||||
geom = damask.Grid.load(StringIO(''.join(sys.stdin.read())) if name is None else name)
|
geom = damask.Grid.load(StringIO(''.join(sys.stdin.read())) if name is None else name)
|
||||||
material = geom.material.flatten(order='F')
|
material = geom.material.flatten(order='F')
|
||||||
|
@ -211,11 +211,11 @@ for name in filenames:
|
||||||
'*draw_automatic',
|
'*draw_automatic',
|
||||||
]
|
]
|
||||||
|
|
||||||
outputLocals = {}
|
output_locals = {}
|
||||||
if options.port:
|
if options.port:
|
||||||
py_mentat.py_connect('',options.port)
|
py_mentat.py_connect('',options.port)
|
||||||
output(cmds,outputLocals,'Mentat')
|
output(cmds,output_locals,'Mentat')
|
||||||
py_mentat.py_disconnect()
|
py_mentat.py_disconnect()
|
||||||
else:
|
else:
|
||||||
with sys.stdout if name is None else open(os.path.splitext(name)[0]+'.proc','w') as f:
|
with sys.stdout if name is None else open(os.path.splitext(name)[0]+'.proc','w') as f:
|
||||||
output(cmds,outputLocals,f)
|
output(cmds,output_locals,f)
|
||||||
|
|
Loading…
Reference in New Issue