new module damask_test, set compile=false as default in msc_tools, added first draft of material.config generator to damask_tools

This commit is contained in:
Martin Diehl 2011-11-17 14:05:39 +00:00
parent 448c0c480a
commit ddb68eee7c
3 changed files with 151 additions and 3 deletions

112
lib/damask_test.py Normal file
View File

@ -0,0 +1,112 @@
#!/usr/bin/env python
import os, sys
import subprocess,shutil
import damask_tools; reload(damask_tools)
import msc_tools; reload(msc_tools)
damask_tools.DAMASK_TOOLS().check_env()
class DAMASK_TEST():
modelname=None
jobname=None
testdir=None
spectral_options=None
orientations=[]
compile=False
def run_test(self):
self.modelname='one_element_model'
self.jobname='job1'
self.testdir='2001_hex_plastic'
self.orientations=[]
self.clean_current_results()
if self.calc_current_results() is False:
return False
print('simulation finished')
self.postprocess()
if self.compare_to_reference() is False:
return False
print 'Test OK'
return True
def clean_current_results(self):
try:
shutil.rmtree('current_results')
except:
print('Could not delete current_results')
os.mkdir('current_results')
def calc_current_results(self,compile=None):
#theDir = os.path.split(sys.argv[0])[0]
#os.chdir(theDir)
#os.chdir('..')
#os.chdir('%s/testing'%os.getenv('DAMASK_ROOT'))
if compile is None: compile=self.compile
self.copy_from_ref=[self.modelname+'_'+self.jobname+'.dat',
self.modelname+'.mfd', # for dev
'material.config'
]
for file in self.copy_from_ref:
shutil.copy2('./reference_results/%s'%file,'./current_results/%s'%file)
# Note: possibly symlinking? No, because copy is OS independent.
os.chdir('./current_results')
m=msc_tools.MSC_TOOLS()
m.submit_job(compile=compile, compiled_dir='../../../code/')
print('simulation submitted')
self.exit_number=m.exit_number_from_outFile(outFile=self.modelname+'_'+self.jobname+'.out')
if not self.exit_number==3004:
print('Job did not exit with No. 3004')
return False
return True
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:
print(cmd)
os.system(cmd)
def compare_to_reference(self,tol=1e-5):
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)
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))
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
if __name__ == "__main__":
test=DAMASK_TESTER()
test.run_test()

View File

@ -6,4 +6,40 @@ class DAMASK_TOOLS():
print('No DAMASK_ROOT environment variable, did you run DAMASK/installation/setup_shellrc?')
sys.exit(1)
else:
return True
return True
class MATERIAL_CONFIG():
import os,sys
def __init__(self):
homogenization=[]
def add_homogenization(self, name=None, type=None):
if type is 'isostrain':
h={'type':type}
h['ngrains']=ngrains
return h
def add_crystallite(self, name=None):
pass
def add_texture(self, name=None):
pass
def add_phase(self, name=None):
pass
def add_microstructure(self, name=None, phase=None, texture=None):
pass
def write_file(self,label=None):
fname='material.config'
if label is not None: fname+='_%s'%label
#f=open(fname)
#f.write()
#f.close()
class HOMOGENIZATION():
type=None

View File

@ -38,7 +38,7 @@ class MSC_TOOLS():
run_marc_path='/msc/marc2010/tools/',
subroutine_dir=None,
subroutine_name='DAMASK_marc2010',
compile='yes',
compile=False,
compiled_dir='../../../code/',
modelname='one_element_model',
jobname='job1',
@ -58,7 +58,7 @@ class MSC_TOOLS():
options=' -nprocd 1 -autorst 0 -ci n -cr n -dcoup 0 -b no -v no'
cmd=run_marc+jid+options
if compile=='yes' or compile=='y':
if compile:
cmd=cmd+compilation
print 'Job submission with compilation.'
else: