started solver sub package
improved guessing of DAMASK_ROOT
This commit is contained in:
parent
b2547e0117
commit
2fcbc1ff13
|
@ -1,5 +1,6 @@
|
||||||
from .environment import Environment # only one class
|
from .environment import Environment # only one class
|
||||||
from .asciitable import ASCIItable # only one class
|
from .asciitable import ASCIItable # only one class
|
||||||
from . import config # multiple classes
|
from . import config # multiple classes
|
||||||
from . import result # multiple subclasses
|
from .result import Result # one class with subclasses
|
||||||
from . import geometry # multiple subclasses
|
from .geometry import Geometry # one class with subclasses
|
||||||
|
from .solver import Solver # one class with subclasses
|
||||||
|
|
|
@ -1,7 +1,9 @@
|
||||||
import os,sys,string,re
|
import os,sys,string,re
|
||||||
|
|
||||||
class Environment():
|
class Environment():
|
||||||
__slots__ = ['pathInfo',
|
__slots__ = [ \
|
||||||
|
'rootRelation',
|
||||||
|
'pathInfo',
|
||||||
]
|
]
|
||||||
|
|
||||||
def __init__(self,rootRelation = '.'):
|
def __init__(self,rootRelation = '.'):
|
||||||
|
@ -10,25 +12,31 @@ class Environment():
|
||||||
'fftw': '.',
|
'fftw': '.',
|
||||||
'msc': '/msc',
|
'msc': '/msc',
|
||||||
}
|
}
|
||||||
self.get_pathInfo(rootRelation)
|
self.rootRelation = rootRelation
|
||||||
|
self.get_pathInfo()
|
||||||
|
|
||||||
def relPath(self,relative = '.'):
|
def relPath(self,relative = '.'):
|
||||||
return os.path.join(self.rootDir(),relative)
|
return os.path.join(self.rootDir(),relative)
|
||||||
|
|
||||||
def rootDir(self,rootRelation = '.'): #getting pathinfo
|
def rootDir(self):
|
||||||
damask_root = os.getenv('DAMASK_ROOT')
|
damask_root = os.getenv('DAMASK_ROOT')
|
||||||
if damask_root == '' or damask_root == None: damask_root = os.path.join(os.path.dirname(sys.argv[0]),rootRelation)
|
if damask_root == '' or damask_root == None: # env not set
|
||||||
|
if sys.argv[0] == '': # no caller path
|
||||||
|
cwd = os.getcwd()
|
||||||
|
else:
|
||||||
|
cwd = {False: os.path.dirname(sys.argv[0]),
|
||||||
|
True: sys.argv[0]}[os.path.isdir(sys.argv[0])]
|
||||||
|
damask_root = os.path.normpath(os.path.join(os.path.realpath(cwd),self.rootRelation))
|
||||||
|
|
||||||
return damask_root
|
return damask_root
|
||||||
|
|
||||||
def binDir(self,rootRelation = '.'): #getting pathinfo
|
def binDir(self):
|
||||||
damask_bin = os.getenv('DAMASK_BIN')
|
damask_bin = os.getenv('DAMASK_BIN')
|
||||||
if damask_bin == '' or damask_bin == None: damask_bin = self.relPath('bin/')
|
if damask_bin == '' or damask_bin == None: damask_bin = self.relPath('bin/')
|
||||||
return damask_bin
|
return damask_bin
|
||||||
|
|
||||||
def get_pathInfo(self,rootRelation = '.'): #getting pathinfo
|
def get_pathInfo(self):
|
||||||
damask_root = self.rootDir(rootRelation)
|
try: # check for user-defined pathinfo
|
||||||
|
|
||||||
try: # check for user-defined pathinfo
|
|
||||||
file = open(self.relPath('lib/pathinfo'))
|
file = open(self.relPath('lib/pathinfo'))
|
||||||
content = file.readlines()
|
content = file.readlines()
|
||||||
file.close()
|
file.close()
|
||||||
|
|
|
@ -0,0 +1,3 @@
|
||||||
|
from .solver import Solver # only one class
|
||||||
|
from .spectral import Spectral # only one class
|
||||||
|
from .marc import Marc # only one class
|
|
@ -0,0 +1,111 @@
|
||||||
|
from .solver import Solver
|
||||||
|
|
||||||
|
|
||||||
|
class Marc(Solver):
|
||||||
|
|
||||||
|
#--------------------------
|
||||||
|
def __init__(self):
|
||||||
|
#--------------------------
|
||||||
|
self.solver = 'Marc'
|
||||||
|
self.releases = { \
|
||||||
|
'2010.2':['linux64',''],
|
||||||
|
'2010': ['linux64',''],
|
||||||
|
'2008r1':[''],
|
||||||
|
'2007r1':[''],
|
||||||
|
'2005r3':[''],
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
#--------------------------
|
||||||
|
def version(self,rootRelation = ''):
|
||||||
|
#--------------------------
|
||||||
|
import os,damask.environment
|
||||||
|
|
||||||
|
MSCpath = damask.environment.Environment(rootRelation).pathInfo['msc']
|
||||||
|
|
||||||
|
for release,subdirs in sorted(self.releases.items(),reverse=True):
|
||||||
|
for subdir in subdirs:
|
||||||
|
libPath = '%s/mentat%s/shlib/%s'%(MSCpath,release,subdir)
|
||||||
|
if os.path.exists(libPath): return release
|
||||||
|
else: continue
|
||||||
|
|
||||||
|
return ''
|
||||||
|
|
||||||
|
|
||||||
|
#--------------------------
|
||||||
|
def libraryPath(self,rootRelation = ''):
|
||||||
|
#--------------------------
|
||||||
|
import os,damask.environment
|
||||||
|
|
||||||
|
MSCpath = damask.environment.Environment(rootRelation).pathInfo['msc']
|
||||||
|
|
||||||
|
for release,subdirs in sorted(self.releases.items(),reverse=True):
|
||||||
|
for subdir in subdirs:
|
||||||
|
libPath = '%s/mentat%s/shlib/%s'%(MSCpath,release,subdir)
|
||||||
|
if os.path.exists(libPath): return libPath
|
||||||
|
else: continue
|
||||||
|
|
||||||
|
return ''
|
||||||
|
|
||||||
|
|
||||||
|
#--------------------------
|
||||||
|
def submit_job(self,
|
||||||
|
#--------------------------
|
||||||
|
rootRelation = '',
|
||||||
|
run_marc_path='/msc/marc2010/tools/',
|
||||||
|
subroutine_dir=None,
|
||||||
|
subroutine_name='DAMASK_marc2010',
|
||||||
|
compile=False,
|
||||||
|
compiled_dir='../../../code/',
|
||||||
|
modelname='one_element_model',
|
||||||
|
jobname='job1',
|
||||||
|
#IOdir='',
|
||||||
|
host=[]
|
||||||
|
):
|
||||||
|
import os,damask.environment
|
||||||
|
import subprocess, shlex
|
||||||
|
import shutil
|
||||||
|
|
||||||
|
damaskEnv = damask.environment.Environment(rootRelation)
|
||||||
|
if subroutine_dir is None: subroutine_dir = damaskEnv.binDir()
|
||||||
|
if subroutine_name is None: subroutine_name = 'DAMASK_marc' + self.version(rootRelation)
|
||||||
|
if run_marc_path is None: run_marc_path = os.path.join(damaskEnv.pathInfo['msc'],self.version(rootRelation),'tools/')
|
||||||
|
|
||||||
|
# Define all options [see Marc Installation and Operation Guide, pp 23]
|
||||||
|
run_marc = os.path.jion(run_marc_path,'run_marc')
|
||||||
|
jid = ' -jid ' + modelname + '_' + jobname
|
||||||
|
compilation=' -u ' + subroutine_dir + subroutine_name + '.f90'+' -save y'
|
||||||
|
options=' -nprocd 1 -autorst 0 -ci n -cr n -dcoup 0 -b no -v no'
|
||||||
|
cmd=run_marc+jid+options
|
||||||
|
|
||||||
|
if compile:
|
||||||
|
cmd += compilation
|
||||||
|
print 'job submission with compilation.'
|
||||||
|
else:
|
||||||
|
shutil.copy2(subroutine_dir+subroutine_name+'.f90','./'+subroutine_name+'.f90')
|
||||||
|
shutil.copy2(compiled_dir+subroutine_name+'.marc','./'+subroutine_name+'.marc')
|
||||||
|
prog = ' -prog ' + subroutine_name
|
||||||
|
cmd += prog
|
||||||
|
print 'Job submission without compilation, using %s'%prog
|
||||||
|
out = open('out.log','w')
|
||||||
|
print(cmd)
|
||||||
|
#print shlex.split(cmd)
|
||||||
|
self.p = subprocess.Popen(shlex.split(cmd),stdout=out,stderr=subprocess.STDOUT)
|
||||||
|
self.p.wait()
|
||||||
|
out.close()
|
||||||
|
|
||||||
|
#--------------------------
|
||||||
|
def exit_number_from_outFile(self,outFile=None):
|
||||||
|
#--------------------------
|
||||||
|
import string
|
||||||
|
fid_out = open(outFile,'r')
|
||||||
|
for ln in fid_out:
|
||||||
|
if (string.find(ln,'tress iteration') is not -1):
|
||||||
|
print ln
|
||||||
|
elif (string.find(ln,'Exit number') is not -1):
|
||||||
|
substr = ln[string.find(ln,'Exit number'):len(ln)]
|
||||||
|
exitnumber = substr[12:16]
|
||||||
|
fid_out.close()
|
||||||
|
return int(exitnumber)
|
||||||
|
fid_out.close()
|
||||||
|
return -1
|
|
@ -0,0 +1,17 @@
|
||||||
|
import damask.solver
|
||||||
|
|
||||||
|
class Solver():
|
||||||
|
'''
|
||||||
|
General class for solver specific functionality.
|
||||||
|
Sub-classed by the individual solvers.
|
||||||
|
'''
|
||||||
|
|
||||||
|
def __init__(self,solver=''):
|
||||||
|
solverClass = {
|
||||||
|
'spectral': damask.solver.Spectral,
|
||||||
|
'marc': damask.solver.Marc,
|
||||||
|
}
|
||||||
|
if solver.lower() in solverClass.keys():
|
||||||
|
self.__class__=solverClass[solver.lower()]
|
||||||
|
self.__init__()
|
||||||
|
|
|
@ -0,0 +1,6 @@
|
||||||
|
from .solver import Solver
|
||||||
|
|
||||||
|
class Spectral(Solver):
|
||||||
|
|
||||||
|
def __init__(self):
|
||||||
|
self.solver='Spectral'
|
Loading…
Reference in New Issue