corrected small mistake in setup_code and makefile

test no. 1500, spectral compile test with intel compiler is now working. adjusted run_test and tamask_test
This commit is contained in:
Martin Diehl 2011-12-09 15:13:27 +00:00
parent 609175318e
commit 7d1d2b6229
3 changed files with 55 additions and 55 deletions

View File

@ -52,7 +52,7 @@ DEBUG3 =-fp-stack-check -g -traceback -gen-interfaces -warn interfaces
DEBUG4 =-heap-arrays DEBUG4 =-heap-arrays
#checks for standard #checks for standard
DEBUG5 =stand std03/std95 DEBUG5 =-stand std03/std95
#SUFFIX =$(DEBUG1) $(DEBUG2) $(DEBUG3) #SUFFIX =$(DEBUG1) $(DEBUG2) $(DEBUG3)
######################################################################################## ########################################################################################

View File

@ -15,13 +15,14 @@ bin_link = { \
'DAMASK_spectral.exe', 'DAMASK_spectral.exe',
], ],
} }
basedir = damask_variables.relPath('code/') damask_variables = damask_tools.DAMASK_TOOLS()
baseDir = damask_variables.relPath('code/')
for arch in architectures: for arch in architectures:
me = architectures[arch] me = architectures[arch]
try: try:
parentFile = open(basedir+os.sep+me['parent']) parentFile = open(baseDir+os.sep+me['parent'])
parentContent = parentFile.readlines() parentContent = parentFile.readlines()
parentFile.close() parentFile.close()
except IOError: except IOError:
@ -30,17 +31,17 @@ for arch in architectures:
for version in me['versions'][1:]: for version in me['versions'][1:]:
childFile = open(basedir+os.sep+version.join(os.path.splitext(me['parent'])),'w') childFile = open(baseDir+os.sep+version.join(os.path.splitext(me['parent'])),'w')
for line in parentContent: for line in parentContent:
childFile.write(line.replace(me['versions'][0],version)) childFile.write(line.replace(me['versions'][0],version))
childFile.close() childFile.close()
# changing dirs in make file # changing dirs in make file
damask_variables = damask_tools.DAMASK_TOOLS()
makefile = open(os.path.join(basedir,'makefile')) makefile = open(os.path.join(baseDir,'makefile'))
content = makefile.readlines() content = makefile.readlines()
makefile.close() makefile.close()
makefile = open(os.path.join(basedir,'makefile'),'w') makefile = open(os.path.join(baseDir,'makefile'),'w')
for line in content: for line in content:
if line.startswith('FFTWPATH'): if line.startswith('FFTWPATH'):
line='FFTWPATH =%s\n'%(damask_variables.pathInfo['fftw']) line='FFTWPATH =%s\n'%(damask_variables.pathInfo['fftw'])
@ -52,13 +53,14 @@ for line in content:
makefile.close() makefile.close()
# compiling spectral code # compiling spectral code
if raw_input("Do you want to compile the spectral code now? (y/n) ") is 'y' or 'Y': compile = raw_input("Do you want to compile the spectral code now? (y/n) ")
if (compile == 'y' or compile == 'Y'):
compiler_switches = raw_input("Please give compiling switches (Enter to use default) ") compiler_switches = raw_input("Please give compiling switches (Enter to use default) ")
os.system('make --directory %s clean'%(basedir)) os.system('make --directory %s clean'%(baseDir))
os.system('make --directory %s %s'%(basedir,compiler_switches)) os.system('make --directory %s %s'%(baseDir,compiler_switches))
if '--clean' in [s.lower() for s in sys.argv]: if '--clean' in [s.lower() for s in sys.argv]:
os.system('make --directory %s clean'%basedir) os.system('make --directory %s clean'%baseDir)
for dir in bin_link: for dir in bin_link:

View File

@ -12,18 +12,21 @@ class DAMASK_TEST():
General class for testing. General class for testing.
Is sub-classed by the individual tests. Is sub-classed by the individual tests.
''' '''
#define those according to your test
modelname=None modelname=None
jobname=None jobname=None
testdir=None test_dir=None
spectral_options=None spectral_options=None
compile=False compile=False = None
post_txt = None
tol = 0.0
has_variants=False # False ==> A single test case is run has_variants=False # False ==> A single test case is run
#has_variants=True # True ==> Need to define the test_variants generator #has_variants=True # True ==> Need to define the test_variants generator
def test_variants(self): def test_variants(self):
''' '''
If has_subtests == True this method defines the generator for subtests If has_subtests == True this method defines the generator for test variants
This generator must be defined in each test, This generator must be defined in each test,
depending on what to change: orientations, parameters,.... depending on what to change: orientations, parameters,....
Below is an EXAMPLE. Below is an EXAMPLE.
@ -44,9 +47,12 @@ class DAMASK_TEST():
def run_test(self): def run_test(self):
res=[] res=[]
if self.has_variants: if self.has_variants:
for t in self.subtests(): for t in self.test_variants():
print '###############################################'
print '###############################################'
print(t) print(t)
val=self.run_single_test() print '###############################################'
val=self.run_single_test(t)
res.append(val==True) res.append(val==True)
else: else:
val=self.run_single_test() val=self.run_single_test()
@ -56,18 +62,20 @@ class DAMASK_TEST():
print(res) print(res)
return False return False
def run_single_test(self): def run_single_test(self,variant):
self.clean_current_results() self.clean_current_results()
if self.calc_current_results() is False: if self.calc_current_results(variant) is False:
return False return False
print('simulation finished') print('simulation finished')
self.postprocess() self.postprocess()
if self.compare_to_reference() is False: if self.compare_to_reference() is False:
print '++++++++ Test not OK +++++++++'
return False return False
print 'Test OK' print 'Test OK'
return True return True
def clean_current_results(self): def clean_current_results(self):
os.chdir(self.test_dir)
try: try:
shutil.rmtree('current_results') shutil.rmtree('current_results')
except: except:
@ -109,49 +117,39 @@ class DAMASK_TEST():
shutil.copy2('./reference_results/%s'%file,'./current_results/%s'%file) shutil.copy2('./reference_results/%s'%file,'./current_results/%s'%file)
# Note: possibly symlinking? No, because copy is OS independent. # Note: possibly symlinking? No, because copy is OS independent.
def postprocess(self): def read_val_from_file(self,fname=None):
#print 'postprocessing results ...' file = open(fname,'r')
#os.system('%s/processing/post/postResults --es "Comp 33 of Stress" %s.t16 --range 100 100 1'%(os.getenv('DAMASK_ROOT'),self.modelname+'_'+self.jobname)) headerlength = int(file.readline().split()[0]) + 1
print 'postprocessing results ...' file.close
file=open('../postprocessing.cmd','r') import numpy as N
postproc=file.readlines() val = N.loadtxt(fname,skiprows=headerlength)
file.close() return val
for cmd in postproc: # PHILIP: suggestion to just execute the script "postprocessing" directly within a shell, i.e. os.system('../postprocessing')
print(cmd)
os.system(cmd) # PHILIP: reason is that for loops and the like get broken with line by line execution from here...
# CLAUDIO: Actually that's what we had before - I stole the code from one of your scripts because for lengthy postprocessing, the user can then see the progress. I don't get the part about the breaking loops, let's discuss tomorrow.
def compare_to_reference(self):
def compare_to_reference(self,tol=1e-5):
import string import string
print 'comparing results against reference_results...' print 'comparing results against reference_results...'
txt_file=self.modelname+'_'+self.jobname+'.txt' os.chdir(os.path.join(self.test_dir,'current_results'))
cur=self.read_val_from_file(fname='postProc/'+txt_file) cur=self.read_val_from_file(fname='postProc/'+self.post_txt)
ref=self.read_val_from_file(fname='../reference_results/postProc/'+txt_file) ref=self.read_val_from_file(fname='../reference_results/postProc/'+self.post_txt)
err=abs((ref/cur)-1.) # relative tolerance err=abs((ref/cur)-1.) # relative tolerance
#err=abs(ref-cur) # absolute tolerance #err=abs(ref-cur) # absolute tolerance
print 'tol', self.tol
if err>tol: if err.any()>self.tol:
print 'Current value: %e'%cur return False
print 'Reference value: %e'%ref
print('err: %e > tol: %e'%(err,tol))
return False
print('err: %e < tol: %e'%(err,tol))
return True return True
def read_val_from_file(self,fname=None): def postprocess(self):
fid=open(fname,'r') print 'postprocessing results ...'
rl=fid.readlines() os.chdir(self.test_dir)
print rl file=open('./postprocessing.cmd','r')
cur=rl[-1] postproc=file.readlines()
lst=cur.split('\t') file.close()
print lst os.chdir(os.path.join(self.test_dir,'current_results'))
val=float(lst[-1].rstrip()) for cmd in postproc: # PHILIP: suggestion to just execute the script "postprocessing" directly within a shell, i.e. os.system('../postprocessing')
print val print(cmd)
fid.close() os.system(cmd) # PHILIP: reason is that for loops and the like get broken with line by line execution from here...
return val
if __name__ == "__main__": if __name__ == "__main__":
test=DAMASK_TESTER() test=DAMASK_TESTER()