DAMASK_EICMD/python/damask/solver/marc.py

101 lines
2.9 KiB
Python
Raw Normal View History

# -*- coding: UTF-8 no BOM -*-
from .solver import Solver
class Marc(Solver):
def __init__(self):
self.solver = 'Marc'
#--------------------------
2016-07-16 13:06:15 +05:30
def version(self):
import damask.environment
return damask.environment.Environment().options['MARC_VERSION']
#--------------------------
def libraryPath(self,release = ''):
import os,damask.environment
MSCpath = damask.environment.Environment().options['MSC_ROOT']
if len(release) == 0: release = self.version()
path = '{}/mentat{}/shlib/linux64'.format(MSCpath,release)
return path if os.path.exists(path) else ''
#--------------------------
2016-07-16 13:06:15 +05:30
def toolsPath(self,release = ''):
import os,damask.environment
2016-07-16 13:06:15 +05:30
MSCpath = damask.environment.Environment().options['MSC_ROOT']
if len(release) == 0: release = self.version()
path = '%s/marc%s/tools'%(MSCpath,release)
return path if os.path.exists(path) else ''
#--------------------------
def submit_job(self,
release = '',
model = 'model',
job = 'job1',
logfile = None,
compile = False,
optimization ='',
):
import os,damask.environment
2016-03-02 03:32:47 +05:30
import subprocess,shlex
2016-07-16 13:06:15 +05:30
if len(release) == 0: release = self.version()
damaskEnv = damask.environment.Environment()
2018-11-16 10:53:28 +05:30
user = 'not found'
if compile:
2018-11-16 10:53:28 +05:30
if os.path.isfile(os.path.join(damaskEnv.relPath('src/'),'DAMASK_marc{}.f90'.format(release))):
user = os.path.join(damaskEnv.relPath('src/'),'DAMASK_marc{}'.format(release))
else:
2018-11-16 10:53:28 +05:30
if os.path.isfile(os.path.join(damaskEnv.relPath('src/'),'DAMASK_marc{}.marc'.format(release))):
user = os.path.join(damaskEnv.relPath('src/'),'DAMASK_marc{}'.format(release))
# Define options [see Marc Installation and Operation Guide, pp 23]
2018-11-16 10:53:28 +05:30
script = 'run_damask_{}mp'.format(optimization)
2016-07-16 13:06:15 +05:30
cmd = os.path.join(self.toolsPath(release),script) + \
' -jid ' + model + '_' + job + \
' -nprocd 1 -autorst 0 -ci n -cr n -dcoup 0 -b no -v no'
if compile: cmd += ' -u ' + user+'.f90' + ' -save y'
else: cmd += ' -prog ' + user
2018-11-16 10:53:28 +05:30
print('job submission with{} compilation: {}'.format({False:'out',True:''}[compile],user))
if logfile:
log = open(logfile, 'w')
print(cmd)
2018-11-16 10:53:28 +05:30
process = subprocess.Popen(shlex.split(cmd),stdout = log,stderr = subprocess.STDOUT)
log.close()
2018-11-16 10:53:28 +05:30
process.wait()
#--------------------------
def exit_number_from_outFile(self,outFile=None):
import string
exitnumber = -1
fid_out = open(outFile,'r')
for line in fid_out:
if (string.find(line,'tress iteration') is not -1):
print(line)
elif (string.find(line,'Exit number') is not -1):
substr = line[string.find(line,'Exit number'):len(line)]
exitnumber = int(substr[12:16])
fid_out.close()
return exitnumber