2019-12-13 03:28:37 +05:30
|
|
|
import subprocess
|
|
|
|
import shlex
|
2020-10-31 17:29:46 +05:30
|
|
|
import re
|
2020-06-03 17:02:47 +05:30
|
|
|
from pathlib import Path
|
2019-12-13 03:28:37 +05:30
|
|
|
|
2021-12-02 13:20:59 +05:30
|
|
|
_marc_version = '2021.3.1'
|
2021-10-18 02:05:25 +05:30
|
|
|
_marc_root = '/opt/msc'
|
2021-04-22 12:19:52 +05:30
|
|
|
_damask_root = str(Path(__file__).parents[3])
|
2021-04-22 11:25:41 +05:30
|
|
|
|
2020-03-22 00:48:46 +05:30
|
|
|
class Marc:
|
2021-10-18 02:05:25 +05:30
|
|
|
"""Wrapper to run DAMASK with MSC Marc."""
|
2019-12-13 03:28:37 +05:30
|
|
|
|
2021-10-18 02:05:25 +05:30
|
|
|
def __init__(self,marc_version=_marc_version,marc_root=_marc_root,damask_root=_damask_root):
|
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
|
|
|
|
----------
|
2021-11-25 22:00:22 +05:30
|
|
|
version : string
|
2020-01-14 03:56:40 +05:30
|
|
|
Marc version
|
|
|
|
|
|
|
|
"""
|
2021-11-25 22:06:41 +05:30
|
|
|
self.marc_version = marc_version
|
2021-10-18 02:05:25 +05:30
|
|
|
self.marc_root = Path(marc_root)
|
2021-04-22 12:19:52 +05:30
|
|
|
self.damask_root = Path(damask_root)
|
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-11-25 22:06:41 +05:30
|
|
|
path_lib = self.marc_root/f'mentat{self.marc_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-11-25 22:06:41 +05:30
|
|
|
path_tools = self.marc_root/f'marc{self.marc_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
|
|
|
|
|
|
|
|
2021-04-11 02:17:00 +05:30
|
|
|
def submit_job(self, model, job,
|
2020-01-14 03:56:40 +05:30
|
|
|
compile = False,
|
2021-04-11 02:17:00 +05:30
|
|
|
optimization = ''):
|
2021-08-25 17:56:25 +05:30
|
|
|
"""
|
|
|
|
Assemble command line arguments and call Marc executable.
|
2019-12-13 03:28:37 +05:30
|
|
|
|
2021-08-25 17:56:25 +05:30
|
|
|
Parameters
|
|
|
|
----------
|
|
|
|
model : str
|
|
|
|
Name of model.
|
|
|
|
job : str
|
|
|
|
Name of job.
|
|
|
|
compile : bool, optional
|
2021-08-25 20:27:38 +05:30
|
|
|
Compile DAMASK_Marc user subroutine (and save for future use).
|
2021-08-25 17:56:25 +05:30
|
|
|
Defaults to False.
|
|
|
|
optimization : str, optional
|
2021-08-25 20:27:38 +05:30
|
|
|
Optimization level '' (-O0), 'l' (-O1), or 'h' (-O3).
|
2021-08-25 19:40:39 +05:30
|
|
|
Defaults to ''.
|
2021-08-25 17:56:25 +05:30
|
|
|
|
|
|
|
"""
|
2022-04-24 22:20:23 +05:30
|
|
|
usersub = (self.damask_root/'src/Marc/DAMASK_Marc').with_suffix('.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
|
|
|
|
2021-08-25 00:44:39 +05:30
|
|
|
cmd = f'{self.tools_path/script} -jid {model}_{job} -nprocd 1 -autorst 0 -ci n -cr n -dcoup 0 -b no -v no ' \
|
|
|
|
+ (f'-u {usersub} -save y' if compile else f'-prog {usersub.with_suffix("")}')
|
|
|
|
|
2020-01-14 03:56:40 +05:30
|
|
|
print(cmd)
|
2020-10-31 17:29:46 +05:30
|
|
|
|
2021-04-11 02:17:00 +05:30
|
|
|
ret = subprocess.run(shlex.split(cmd),capture_output=True)
|
2020-10-31 17:29:46 +05:30
|
|
|
|
|
|
|
try:
|
2021-04-11 03:22:59 +05:30
|
|
|
v = int(re.search('Exit number ([0-9]+)',ret.stderr.decode()).group(1))
|
|
|
|
if 3004 != v:
|
2021-04-11 02:17:00 +05:30
|
|
|
print(ret.stderr.decode())
|
|
|
|
print(ret.stdout.decode())
|
|
|
|
raise RuntimeError(f'Marc simulation failed ({v})')
|
2020-10-31 17:29:46 +05:30
|
|
|
except (AttributeError,ValueError):
|
2021-04-11 02:17:00 +05:30
|
|
|
print(ret.stderr.decode())
|
|
|
|
print(ret.stdout.decode())
|
2020-10-31 17:29:46 +05:30
|
|
|
raise RuntimeError('Marc simulation failed (unknown return value)')
|