2019-12-13 03:28:37 +05:30
|
|
|
import subprocess
|
|
|
|
import shlex
|
2020-10-31 17:29:46 +05:30
|
|
|
import re
|
|
|
|
import io
|
2021-01-15 01:42:29 +05:30
|
|
|
import os
|
2020-06-03 17:02:47 +05:30
|
|
|
from pathlib import Path
|
2019-12-13 03:28:37 +05:30
|
|
|
|
2020-03-22 00:48:46 +05:30
|
|
|
class Marc:
|
2020-01-14 03:56:40 +05:30
|
|
|
"""Wrapper to run DAMASK with MSCMarc."""
|
2019-12-13 03:28:37 +05:30
|
|
|
|
2021-01-15 01:42:29 +05:30
|
|
|
def __init__(self,version=os.environ['MSC_VERSION']):
|
2020-01-14 03:56:40 +05:30
|
|
|
"""
|
|
|
|
Create a Marc solver object.
|
2020-03-22 00:47:50 +05:30
|
|
|
|
2020-01-14 03:56:40 +05:30
|
|
|
Parameters
|
|
|
|
----------
|
|
|
|
version : float
|
|
|
|
Marc version
|
|
|
|
|
|
|
|
"""
|
|
|
|
self.solver = 'Marc'
|
2020-06-03 18:48:46 +05:30
|
|
|
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
|
|
|
|
2021-01-15 01:42:29 +05:30
|
|
|
path_lib = Path(f'{os.environ["MSC_ROOT"]}/mentat{self.version}/shlib/linux64')
|
2020-10-31 17:29:46 +05:30
|
|
|
if not path_lib.is_dir():
|
|
|
|
raise FileNotFoundError(f'library path "{path_lib}" not found')
|
|
|
|
|
|
|
|
return path_lib
|
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
|
|
|
|
2021-01-15 01:42:29 +05:30
|
|
|
path_tools = Path(f'{os.environ["MSC_ROOT"]}/marc{self.version}/tools')
|
2020-10-31 17:29:46 +05:30
|
|
|
if not path_tools.is_dir():
|
|
|
|
raise FileNotFoundError(f'tools path "{path_tools}" not found')
|
|
|
|
|
|
|
|
return path_tools
|
2019-12-13 03:28:37 +05:30
|
|
|
|
|
|
|
|
2020-01-14 03:56:40 +05:30
|
|
|
def submit_job(self,
|
|
|
|
model,
|
|
|
|
job = 'job1',
|
|
|
|
logfile = False,
|
|
|
|
compile = False,
|
|
|
|
optimization = '',
|
|
|
|
):
|
2019-12-13 03:28:37 +05:30
|
|
|
|
2021-03-26 13:49:59 +05:30
|
|
|
usersub = Path(os.environ['DAMASK_ROOT'])/'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():
|
2020-10-31 17:29:46 +05:30
|
|
|
raise FileNotFoundError(f'subroutine ({"source" if compile else "binary"}) "{usersub}" not found')
|
2019-12-13 03:28:37 +05:30
|
|
|
|
2020-01-14 03:56:40 +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-10-31 17:29:46 +05:30
|
|
|
cmd = str(self.tools_path/script) + \
|
|
|
|
' -jid ' + model+'_'+job + \
|
|
|
|
' -nprocd 1 -autorst 0 -ci n -cr n -dcoup 0 -b no -v no'
|
|
|
|
cmd += ' -u ' + str(usersub) + ' -save y' if compile else \
|
|
|
|
' -prog ' + str(usersub.with_suffix(''))
|
2020-01-14 03:56:40 +05:30
|
|
|
print(cmd)
|
2020-10-31 17:29:46 +05:30
|
|
|
|
|
|
|
if logfile is not None:
|
|
|
|
try:
|
2021-02-10 14:33:35 +05:30
|
|
|
f = open(logfile,'w+',newline='\n')
|
2020-10-31 17:29:46 +05:30
|
|
|
except TypeError:
|
|
|
|
f = logfile
|
|
|
|
else:
|
|
|
|
f = io.StringIO()
|
|
|
|
|
|
|
|
proc = subprocess.Popen(shlex.split(cmd),stdout=f,stderr=subprocess.STDOUT)
|
|
|
|
proc.wait()
|
|
|
|
f.seek(0)
|
|
|
|
|
|
|
|
try:
|
2020-11-01 23:04:52 +05:30
|
|
|
v = int(re.search('Exit number ([0-9]+)',''.join(f.readlines())).group(1))
|
2020-10-31 17:29:46 +05:30
|
|
|
except (AttributeError,ValueError):
|
|
|
|
raise RuntimeError('Marc simulation failed (unknown return value)')
|
|
|
|
|
|
|
|
if v != 3004:
|
|
|
|
raise RuntimeError(f'Marc simulation failed ({v})')
|