From 582f895d188714380e436af94beea858d940726b Mon Sep 17 00:00:00 2001 From: Philip Eisenlohr Date: Thu, 12 Dec 2019 16:58:37 -0500 Subject: [PATCH] restored Solver module functionality --- python/damask/__init__.py | 1 + python/damask/environment.py | 2 +- python/damask/solver/__init__.py | 5 ++ python/damask/solver/abaqus.py | 33 ++++++++++++ python/damask/solver/marc.py | 88 ++++++++++++++++++++++++++++++++ python/damask/solver/solver.py | 6 +++ 6 files changed, 134 insertions(+), 1 deletion(-) create mode 100644 python/damask/solver/__init__.py create mode 100644 python/damask/solver/abaqus.py create mode 100644 python/damask/solver/marc.py create mode 100644 python/damask/solver/solver.py diff --git a/python/damask/__init__.py b/python/damask/__init__.py index b0966b45f..2e94d51ba 100644 --- a/python/damask/__init__.py +++ b/python/damask/__init__.py @@ -16,6 +16,7 @@ from .orientation import Symmetry, Lattice, Rotation, Orientation # noqa from .dadf5 import DADF5 # noqa from .geom import Geom # noqa +from .solver import Solver # noqa from .test import Test # noqa from .util import extendableOption # noqa diff --git a/python/damask/environment.py b/python/damask/environment.py index b00086b96..ff0c0e418 100644 --- a/python/damask/environment.py +++ b/python/damask/environment.py @@ -26,4 +26,4 @@ class Environment(): items = re.split(r'\s*=\s*',line) if len(items) == 2: self.options[items[0].upper()] = \ - re.sub(r'${*DAMASK_ROOT}*',self.rootDir(),os.path.expandvars(items[1])) # expand all shell variables and DAMASK_ROOT + re.sub(r'\${?DAMASK_ROOT}?',self.rootDir(),os.path.expandvars(items[1])) # expand all shell variables and DAMASK_ROOT diff --git a/python/damask/solver/__init__.py b/python/damask/solver/__init__.py new file mode 100644 index 000000000..70f48eb26 --- /dev/null +++ b/python/damask/solver/__init__.py @@ -0,0 +1,5 @@ +"""Tools to control the various solvers.""" + +from .solver import Solver # noqa +from .marc import Marc # noqa +from .abaqus import Abaqus # noqa diff --git a/python/damask/solver/abaqus.py b/python/damask/solver/abaqus.py new file mode 100644 index 000000000..00d711da2 --- /dev/null +++ b/python/damask/solver/abaqus.py @@ -0,0 +1,33 @@ +import subprocess + +from .solver import Solver +import damask + + +class Abaqus(Solver): + """Wrapper to run DAMASK with Abaqus.""" + + def __init__(self,version=int(damask.Environment().options['ABAQUS_VERSION'])): + """ + Create a Abaqus solver object. + + Parameters + ---------- + version : integer + Abaqus version + + """ + self.solver = 'Abaqus' + self.version = int(version) + + def return_run_command(self,model): + try: + cmd = 'abq'+self.version + subprocess.check_output([cmd,'information=release']) + except OSError: # link to abqXXX not existing + cmd = 'abaqus' + process = subprocess.Popen([cmd,'information=release'],stdout = subprocess.PIPE,stderr = subprocess.PIPE) + detectedVersion = int(process.stdout.readlines()[1].split()[1].decode('utf-8')) + if self.version != detectedVersion: + raise Exception('found Abaqus version {}, but requested {}'.format(detectedVersion,self.version)) + return '{} -job {} -user {}/src/DAMASK_abaqus interactive'.format(cmd,model,damask.Environment().rootDir()) diff --git a/python/damask/solver/marc.py b/python/damask/solver/marc.py new file mode 100644 index 000000000..16e867ac1 --- /dev/null +++ b/python/damask/solver/marc.py @@ -0,0 +1,88 @@ +import os +import subprocess +import shlex + +from .solver import Solver +import damask + +class Marc(Solver): + """Wrapper to run DAMASK with MSCMarc.""" + + def __init__(self,version=damask.Environment().options['MARC_VERSION']): + """ + Create a Marc solver object. + + Parameters + ---------- + version : float + Marc version + + """ + self.solver = 'Marc' + self.version = damask.Environment().options['MARC_VERSION'] + + +#-------------------------- + def libraryPath(self): + + path_MSC = damask.Environment().options['MSC_ROOT'] + path_lib = '{}/mentat{}/shlib/linux64'.format(path_MSC,self.version) + + return path_lib if os.path.exists(path_lib) else '' + + +#-------------------------- + def toolsPath(self): + + path_MSC = damask.Environment().options['MSC_ROOT'] + path_tools = '{}/marc{}/tools'.format(path_MSC,self.version) + + return path_tools if os.path.exists(path_tools) else '' + + +#-------------------------- + def submit_job(self, + model, + job = 'job1', + logfile = False, + compile = False, + optimization = '', + ): + + + damaskEnv = damask.Environment() + + user = os.path.join(damaskEnv.relPath('src'),'DAMASK_marc{}.{}'.format(self.version,'f90' if compile else 'marc')) + if not os.path.isfile(user): + raise FileNotFoundError("DAMASK4Marc ({}) '{}' not found".format(('source' if compile else 'binary'),user)) + + # Define options [see Marc Installation and Operation Guide, pp 23] + script = 'run_damask_{}mp'.format(optimization) + + cmd = os.path.join(self.toolsPath(),script) + \ + ' -jid ' + model + '_' + job + \ + ' -nprocd 1 -autorst 0 -ci n -cr n -dcoup 0 -b no -v no' + + if compile: cmd += ' -u ' + user + ' -save y' + else: cmd += ' -prog ' + os.path.splitext(user)[0] + + 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() + +#-------------------------- + def exit_number_from_outFile(self,outFile=None): + import string + 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 diff --git a/python/damask/solver/solver.py b/python/damask/solver/solver.py new file mode 100644 index 000000000..c1ca7ff69 --- /dev/null +++ b/python/damask/solver/solver.py @@ -0,0 +1,6 @@ +class Solver(): + """ + General class for solver specific functionality. + + Sub-classed by the individual solvers. + """