don't use shell variables

Marc solver can be controlled in python, installation can be tuned with
CLI arguments
This commit is contained in:
Martin Diehl 2021-04-22 08:49:52 +02:00
parent 0773fb5fae
commit 6699f2ee5f
6 changed files with 34 additions and 19 deletions

View File

@ -207,7 +207,7 @@ J2_plasticBehavior:
stage: fortran
script:
- module load $IntelMarc $HDF5Marc $MSC
- J2_plasticBehavior/test.py
- MSC_VERSION=2020 J2_plasticBehavior/test.py
except:
- master
- release

View File

@ -4,7 +4,7 @@
# Normal exit status is 0.
#
DIR=%INSTALLDIR%/marc%VERSION%
DIR=%INSTALLDIR%/marc2020
if test $MARCDIR1
then

View File

@ -4,7 +4,7 @@
# Normal exit status is 0.
#
DIR=%INSTALLDIR%/marc%VERSION%
DIR=%INSTALLDIR%/marc2020
if test $MARCDIR1
then

View File

@ -4,7 +4,7 @@
# Normal exit status is 0.
#
DIR=%INSTALLDIR%/marc%VERSION%
DIR=%INSTALLDIR%/marc2020
if test $MARCDIR1
then

View File

@ -5,23 +5,36 @@ import glob
import argparse
from pathlib import Path
msc_version = os.environ['MSC_VERSION']
msc_root = Path(os.environ['MSC_ROOT'])
damask_root = Path(os.environ['DAMASK_ROOT'])
import damask
parser = argparse.ArgumentParser(
description='Apply DAMASK modification to MSC.Marc/Mentat',
epilog = f'MSC_ROOT={msc_root} and MSC_VERSION={msc_version} (from {damask_root}/env/CONFIG)')
description='Apply DAMASK modification to MSC.Marc/Mentat',
prog = Path(__file__).name,
formatter_class=argparse.ArgumentDefaultsHelpFormatter)
parser.add_argument('--editor', dest='editor', metavar='string', default='vi',
help='Name of the editor for MSC.Mentat (executable)')
parser.add_argument('--msc-root', dest='msc_root', metavar='string',
default=damask.solver._marc._msc_root,
help='MSC.Marc/Mentat root directory')
parser.add_argument('--msc-version', dest='msc_version', metavar='string',
default=damask.solver._marc._msc_version,
help='MSC.Marc/Mentat version')
parser.add_argument('--damask-root', dest='damask_root', type=float, metavar = 'float',
default=damask.solver._marc._damask_root,
help='DAMASK root directory')
args = parser.parse_args()
msc_root = Path(args.msc_root)
damask_root = Path(args.damask_root)
msc_version = args.msc_version
def copy_and_replace(in_file,dst):
with open(in_file) as f:
content = f.read()
content = content.replace('%INSTALLDIR%',str(msc_root))
content = content.replace('%VERSION%', msc_version)
content = content.replace('%EDITOR%', parser.parse_args().editor)
content = content.replace('%EDITOR%', args.editor)
with open(dst/Path(in_file).name,'w') as f:
f.write(content)

View File

@ -1,16 +1,16 @@
import subprocess
import shlex
import re
import os
from pathlib import Path
_default_version='2020'
_default_path='/opt/msc'
_msc_version = 2020
_msc_root = '/opt/msc'
_damask_root = str(Path(__file__).parents[3])
class Marc:
"""Wrapper to run DAMASK with MSCMarc."""
def __init__(self,version=os.environ.get('MSC_VERSION',_default_version)):
def __init__(self,msc_version=_msc_version,msc_root=_msc_root,damask_root=_damask_root):
"""
Create a Marc solver object.
@ -20,12 +20,14 @@ class Marc:
Marc version
"""
self.version = version
self.msc_version = msc_version
self.msc_root = Path(msc_root)
self.damask_root = Path(damask_root)
@property
def library_path(self):
path_lib = Path(f'{os.environ.get("MSC_ROOT",_default_path)}/mentat{self.version}/shlib/linux64')
path_lib = self.msc_root/f'mentat{self.msc_version}/shlib/linux64'
if not path_lib.is_dir():
raise FileNotFoundError(f'library path "{path_lib}" not found')
@ -35,7 +37,7 @@ class Marc:
@property
def tools_path(self):
path_tools = Path(f'{os.environ.get("MSC_ROOT",_default_path)}/marc{self.version}/tools')
path_tools = self.msc_root/f'marc{self.msc_version}/tools'
if not path_tools.is_dir():
raise FileNotFoundError(f'tools path "{path_tools}" not found')
@ -46,7 +48,7 @@ class Marc:
compile = False,
optimization = ''):
usersub = Path(os.environ['DAMASK_ROOT'])/'src/DAMASK_Marc'
usersub = self.damask_root/'src/DAMASK_Marc'
usersub = usersub.parent/(usersub.name + ('.f90' if compile else '.marc'))
if not usersub.is_file():
raise FileNotFoundError(f'subroutine ({"source" if compile else "binary"}) "{usersub}" not found')