DAMASK_EICMD/python/damask/solver/_marc.py

86 lines
2.6 KiB
Python
Raw Normal View History

2019-12-13 03:28:37 +05:30
import subprocess
import shlex
import string
2020-06-03 17:02:47 +05:30
from pathlib import Path
2019-12-13 03:28:37 +05:30
from .. import environment
2019-12-13 03:28:37 +05:30
2020-03-22 00:48:46 +05:30
class Marc:
"""Wrapper to run DAMASK with MSCMarc."""
2019-12-13 03:28:37 +05:30
def __init__(self,version=environment.options['MSC_VERSION']):
"""
Create a Marc solver object.
2020-03-22 00:47:50 +05:30
Parameters
----------
version : float
Marc version
"""
self.solver = 'Marc'
self.version = version
2019-12-13 03:28:37 +05:30
2020-06-03 17:02:47 +05:30
@property
def library_path(self):
2019-12-13 03:28:37 +05:30
path_MSC = environment.options['MSC_ROOT']
2020-06-25 01:04:51 +05:30
path_lib = Path(f'{path_MSC}/mentat{self.version}/shlib/linux64')
2019-12-13 03:28:37 +05:30
return path_lib if path_lib.is_dir() else None
2019-12-13 03:28:37 +05:30
2020-06-03 17:02:47 +05:30
@property
def tools_path(self):
2019-12-13 03:28:37 +05:30
path_MSC = environment.options['MSC_ROOT']
2020-06-25 01:04:51 +05:30
path_tools = Path(f'{path_MSC}/marc{self.version}/tools')
2019-12-13 03:28:37 +05:30
return path_tools if path_tools.is_dir() else None
2019-12-13 03:28:37 +05:30
#--------------------------
def submit_job(self,
model,
job = 'job1',
logfile = False,
compile = False,
optimization = '',
):
2019-12-13 03:28:37 +05:30
usersub = environment.root_dir/'src/DAMASK_marc'
2020-07-16 13:03:17 +05:30
usersub = usersub.parent/(usersub.name + ('.f90' if compile else '.marc'))
2020-06-25 01:04:51 +05:30
if not usersub.is_file():
raise FileNotFoundError("DAMASK4Marc ({}) '{}' not found".format(('source' if compile else 'binary'),usersub))
2019-12-13 03:28:37 +05:30
# Define options [see Marc Installation and Operation Guide, pp 23]
2020-06-25 01:04:51 +05:30
script = f'run_damask_{optimization}mp'
2020-03-22 00:47:50 +05:30
2020-06-03 17:02:47 +05:30
cmd = str(self.tools_path/Path(script)) + \
' -jid ' + model + '_' + job + \
' -nprocd 1 -autorst 0 -ci n -cr n -dcoup 0 -b no -v no'
2020-06-25 01:04:51 +05:30
if compile: cmd += ' -u ' + str(usersub) + ' -save y'
else: cmd += ' -prog ' + str(usersub.with_suffix(''))
2020-06-25 01:04:51 +05:30
print('job submission {} compilation: {}'.format(('with' if compile else 'without'),usersub))
if logfile: log = open(logfile, 'w')
print(cmd)
process = subprocess.Popen(shlex.split(cmd),stdout = log,stderr = subprocess.STDOUT)
log.close()
process.wait()
2020-03-22 00:47:50 +05:30
2019-12-13 03:28:37 +05:30
#--------------------------
def exit_number_from_outFile(self,outFile=None):
exitnumber = -1
with open(outFile,'r') as fid_out:
for line in fid_out:
if (string.find(line,'tress iteration') != -1):
print(line)
elif (string.find(line,'Exit number') != -1):
substr = line[string.find(line,'Exit number'):len(line)]
exitnumber = int(substr[12:16])
return exitnumber