diff --git a/code/makefile b/code/makefile index 2d78f5def..99c203a0f 100644 --- a/code/makefile +++ b/code/makefile @@ -52,7 +52,7 @@ DEBUG3 =-fp-stack-check -g -traceback -gen-interfaces -warn interfaces DEBUG4 =-heap-arrays #checks for standard -DEBUG5 =stand std03/std95 +DEBUG5 =-stand std03/std95 #SUFFIX =$(DEBUG1) $(DEBUG2) $(DEBUG3) ######################################################################################## diff --git a/code/setup/setup_code.py b/code/setup/setup_code.py index 18df961cf..7ed7fed4e 100755 --- a/code/setup/setup_code.py +++ b/code/setup/setup_code.py @@ -15,13 +15,14 @@ bin_link = { \ 'DAMASK_spectral.exe', ], } - -basedir = damask_variables.relPath('code/') + +damask_variables = damask_tools.DAMASK_TOOLS() +baseDir = damask_variables.relPath('code/') for arch in architectures: me = architectures[arch] try: - parentFile = open(basedir+os.sep+me['parent']) + parentFile = open(baseDir+os.sep+me['parent']) parentContent = parentFile.readlines() parentFile.close() except IOError: @@ -30,17 +31,17 @@ for arch in architectures: 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: childFile.write(line.replace(me['versions'][0],version)) childFile.close() # 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() makefile.close() -makefile = open(os.path.join(basedir,'makefile'),'w') +makefile = open(os.path.join(baseDir,'makefile'),'w') for line in content: if line.startswith('FFTWPATH'): line='FFTWPATH =%s\n'%(damask_variables.pathInfo['fftw']) @@ -52,13 +53,14 @@ for line in content: makefile.close() # 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) ") - os.system('make --directory %s clean'%(basedir)) - os.system('make --directory %s %s'%(basedir,compiler_switches)) + os.system('make --directory %s clean'%(baseDir)) + os.system('make --directory %s %s'%(baseDir,compiler_switches)) 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: diff --git a/lib/damask_test.py b/lib/damask_test.py index edca52a03..810dc1912 100644 --- a/lib/damask_test.py +++ b/lib/damask_test.py @@ -12,18 +12,21 @@ class DAMASK_TEST(): General class for testing. Is sub-classed by the individual tests. ''' + #define those according to your test modelname=None jobname=None - testdir=None + test_dir=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=True # True ==> Need to define the test_variants generator 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, depending on what to change: orientations, parameters,.... Below is an EXAMPLE. @@ -44,9 +47,12 @@ class DAMASK_TEST(): def run_test(self): res=[] if self.has_variants: - for t in self.subtests(): + for t in self.test_variants(): + print '###############################################' + print '###############################################' print(t) - val=self.run_single_test() + print '###############################################' + val=self.run_single_test(t) res.append(val==True) else: val=self.run_single_test() @@ -56,18 +62,20 @@ class DAMASK_TEST(): print(res) return False - def run_single_test(self): + def run_single_test(self,variant): self.clean_current_results() - if self.calc_current_results() is False: + if self.calc_current_results(variant) is False: return False print('simulation finished') self.postprocess() if self.compare_to_reference() is False: + print '++++++++ Test not OK +++++++++' return False print 'Test OK' return True def clean_current_results(self): + os.chdir(self.test_dir) try: shutil.rmtree('current_results') except: @@ -109,49 +117,39 @@ class DAMASK_TEST(): shutil.copy2('./reference_results/%s'%file,'./current_results/%s'%file) # Note: possibly symlinking? No, because copy is OS independent. - def postprocess(self): - #print 'postprocessing results ...' - #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)) - print 'postprocessing results ...' - file=open('../postprocessing.cmd','r') - postproc=file.readlines() - file.close() - 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 read_val_from_file(self,fname=None): + file = open(fname,'r') + headerlength = int(file.readline().split()[0]) + 1 + file.close + import numpy as N + val = N.loadtxt(fname,skiprows=headerlength) + return val - - def compare_to_reference(self,tol=1e-5): + def compare_to_reference(self): import string - print 'comparing results against reference_results...' - txt_file=self.modelname+'_'+self.jobname+'.txt' - cur=self.read_val_from_file(fname='postProc/'+txt_file) - ref=self.read_val_from_file(fname='../reference_results/postProc/'+txt_file) + print 'comparing results against reference_results...' + os.chdir(os.path.join(self.test_dir,'current_results')) + cur=self.read_val_from_file(fname='postProc/'+self.post_txt) + ref=self.read_val_from_file(fname='../reference_results/postProc/'+self.post_txt) err=abs((ref/cur)-1.) # relative tolerance #err=abs(ref-cur) # absolute tolerance - - if err>tol: - print 'Current value: %e'%cur - print 'Reference value: %e'%ref - print('err: %e > tol: %e'%(err,tol)) - return False - print('err: %e < tol: %e'%(err,tol)) + print 'tol', self.tol + if err.any()>self.tol: + return False return True - def read_val_from_file(self,fname=None): - fid=open(fname,'r') - rl=fid.readlines() - print rl - cur=rl[-1] - lst=cur.split('\t') - print lst - val=float(lst[-1].rstrip()) - print val - fid.close() - return val - + def postprocess(self): + print 'postprocessing results ...' + os.chdir(self.test_dir) + file=open('./postprocessing.cmd','r') + postproc=file.readlines() + file.close() + os.chdir(os.path.join(self.test_dir,'current_results')) + 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... + if __name__ == "__main__": test=DAMASK_TESTER()