DAMASK_EICMD/python/damask/solver/_marc.py

91 lines
2.7 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
2020-03-22 00:47:50 +05:30
from .._environment 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
2020-03-22 00:47:50 +05:30
def __init__(self,version=Environment().options['MARC_VERSION']):
"""
Create a Marc solver object.
2020-03-22 00:47:50 +05:30
Parameters
----------
version : float
Marc version
"""
self.solver = 'Marc'
try:
self.version = int(version)
except TypeError:
self.version = -1
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
2020-03-22 00:47:50 +05:30
path_MSC = Environment().options['MSC_ROOT']
2020-06-03 17:02:47 +05:30
path_lib = Path('{}/mentat{}/shlib/linux64'.format(path_MSC,self.version))
2019-12-13 03:28:37 +05:30
2020-06-03 17:02:47 +05:30
return path_lib if path_lib.is_file() 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
2020-03-22 00:47:50 +05:30
path_MSC = Environment().options['MSC_ROOT']
2020-06-03 18:47:00 +05:30
path_tools = Path('{}/marc{}/tools'.format(path_MSC,self.version))
2019-12-13 03:28:37 +05:30
2020-06-03 17:02:47 +05:30
return path_tools if path_tools.is_file() 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
2020-06-03 17:02:47 +05:30
env = Environment()
2020-03-22 00:47:50 +05:30
2020-06-03 17:23:00 +05:30
user = env.root_dir/Path('src/DAMASK_marc{}'.format(self.version)).with_suffix('.f90' if compile else '.marc')
2020-06-03 17:02:47 +05:30
if not user.is_file():
raise FileNotFoundError("DAMASK4Marc ({}) '{}' not found".format(('source' if compile else 'binary'),user))
2019-12-13 03:28:37 +05:30
# Define options [see Marc Installation and Operation Guide, pp 23]
script = 'run_damask_{}mp'.format(optimization)
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-03 17:02:47 +05:30
if compile: cmd += ' -u ' + str(user) + ' -save y'
else: cmd += ' -prog ' + str(user.with_suffix(''))
print('job submission {} compilation: {}'.format('with' if compile else 'without',user))
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