2019-09-03 22:17:31 +05:30
|
|
|
import os
|
|
|
|
import subprocess
|
|
|
|
import shlex
|
2011-12-22 16:00:25 +05:30
|
|
|
|
2011-12-15 14:21:16 +05:30
|
|
|
from .solver import Solver
|
2019-09-03 22:17:31 +05:30
|
|
|
import damask
|
2011-12-15 14:21:16 +05:30
|
|
|
|
|
|
|
class Marc(Solver):
|
2019-09-03 22:17:31 +05:30
|
|
|
"""Wrapper to run DAMASK with MSCMarc."""
|
2011-12-15 14:21:16 +05:30
|
|
|
|
2019-09-20 06:51:53 +05:30
|
|
|
def __init__(self,version=damask.Environment().options['MARC_VERSION']):
|
2019-09-03 22:17:31 +05:30
|
|
|
"""
|
|
|
|
Create a Marc solver object.
|
|
|
|
|
|
|
|
Parameters
|
|
|
|
----------
|
|
|
|
version : float
|
|
|
|
Marc version
|
2011-12-15 14:21:16 +05:30
|
|
|
|
2019-09-03 22:17:31 +05:30
|
|
|
"""
|
|
|
|
self.solver ='Marc'
|
2019-09-20 06:51:53 +05:30
|
|
|
self.version = damask.environment.Environment().options['MARC_VERSION']
|
2011-12-15 14:21:16 +05:30
|
|
|
|
|
|
|
|
|
|
|
#--------------------------
|
2019-09-03 22:17:31 +05:30
|
|
|
def libraryPath(self):
|
2011-12-15 14:21:16 +05:30
|
|
|
|
2019-09-03 22:17:31 +05:30
|
|
|
path_MSC = damask.environment.Environment().options['MSC_ROOT']
|
|
|
|
path_lib = '{}/mentat{}/shlib/linux64'.format(path_MSC,self.version)
|
2018-11-16 01:46:13 +05:30
|
|
|
|
2019-09-03 22:17:31 +05:30
|
|
|
return path_lib if os.path.exists(path_lib) else ''
|
2018-11-16 01:46:13 +05:30
|
|
|
|
2011-12-15 14:21:16 +05:30
|
|
|
|
2012-01-18 15:11:10 +05:30
|
|
|
#--------------------------
|
2019-09-03 22:17:31 +05:30
|
|
|
def toolsPath(self):
|
2012-01-18 15:11:10 +05:30
|
|
|
|
2019-09-03 22:17:31 +05:30
|
|
|
path_MSC = damask.environment.Environment().options['MSC_ROOT']
|
|
|
|
path_tools = '{}/marc{}/tools'.format(path_MSC,self.version)
|
2018-11-16 01:46:13 +05:30
|
|
|
|
2019-09-03 22:17:31 +05:30
|
|
|
return path_tools if os.path.exists(path_tools) else ''
|
2018-11-16 01:46:13 +05:30
|
|
|
|
2012-01-18 15:11:10 +05:30
|
|
|
|
2011-12-15 14:21:16 +05:30
|
|
|
#--------------------------
|
|
|
|
def submit_job(self,
|
2019-09-21 00:24:30 +05:30
|
|
|
model,
|
2012-01-18 15:11:10 +05:30
|
|
|
job = 'job1',
|
2019-09-21 00:24:30 +05:30
|
|
|
logfile = False,
|
2012-01-18 15:11:10 +05:30
|
|
|
compile = False,
|
2013-08-08 14:42:44 +05:30
|
|
|
optimization ='',
|
2012-01-18 15:11:10 +05:30
|
|
|
):
|
|
|
|
|
2019-09-03 22:17:31 +05:30
|
|
|
|
2016-07-16 13:06:15 +05:30
|
|
|
damaskEnv = damask.environment.Environment()
|
2019-09-21 00:24:30 +05:30
|
|
|
|
|
|
|
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))
|
2012-01-18 15:11:10 +05:30
|
|
|
|
|
|
|
# Define options [see Marc Installation and Operation Guide, pp 23]
|
2018-11-16 10:53:28 +05:30
|
|
|
script = 'run_damask_{}mp'.format(optimization)
|
2013-08-08 14:42:44 +05:30
|
|
|
|
2019-09-03 22:17:31 +05:30
|
|
|
cmd = os.path.join(self.toolsPath(),script) + \
|
2012-01-18 15:11:10 +05:30
|
|
|
' -jid ' + model + '_' + job + \
|
|
|
|
' -nprocd 1 -autorst 0 -ci n -cr n -dcoup 0 -b no -v no'
|
|
|
|
|
2019-09-21 00:24:30 +05:30
|
|
|
if compile: cmd += ' -u ' + user + ' -save y'
|
|
|
|
else: cmd += ' -prog ' + os.path.splitext(user)[0]
|
2012-01-18 15:11:10 +05:30
|
|
|
|
2019-09-21 00:24:30 +05:30
|
|
|
print('job submission with{} compilation: {}'.format('' if compile else 'out',user))
|
|
|
|
if logfile: log = open(logfile, 'w')
|
2011-12-15 14:21:16 +05:30
|
|
|
print(cmd)
|
2018-11-16 10:53:28 +05:30
|
|
|
process = subprocess.Popen(shlex.split(cmd),stdout = log,stderr = subprocess.STDOUT)
|
2012-01-26 20:56:21 +05:30
|
|
|
log.close()
|
2018-11-16 10:53:28 +05:30
|
|
|
process.wait()
|
2011-12-15 14:21:16 +05:30
|
|
|
|
|
|
|
#--------------------------
|
|
|
|
def exit_number_from_outFile(self,outFile=None):
|
|
|
|
import string
|
2012-01-18 15:11:10 +05:30
|
|
|
exitnumber = -1
|
2011-12-15 14:21:16 +05:30
|
|
|
fid_out = open(outFile,'r')
|
2018-11-16 10:45:23 +05:30
|
|
|
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)]
|
2012-01-18 15:11:10 +05:30
|
|
|
exitnumber = int(substr[12:16])
|
|
|
|
|
2014-01-17 03:05:51 +05:30
|
|
|
fid_out.close()
|
2012-01-18 15:11:10 +05:30
|
|
|
return exitnumber
|