wrong file was selected during last commit

This commit is contained in:
Martin Diehl 2012-12-12 17:10:04 +00:00
parent 8cfaa5422e
commit 7848e933bb
2 changed files with 107 additions and 47 deletions

View File

@ -1 +1,2 @@
fdot 1.0e-3 0 0 0 * 0 0 * 0 stress * * * * 0 * * 0 * time 1 incs 4 freq 40 fdot 1.0e-3 0 0 0 * 0 0 * 0 stress * * * * 0 * * 0 * time 10 incs 40 freq 4
fdot 1.0e-3 0 0 0 * 0 0 * 0 stress * * * * 0 * * 0 * time 60 incs 60

View File

@ -39,6 +39,7 @@ class Test():
if len(update) == 0 and self.options.update: print ' This test has no reference to update' if len(update) == 0 and self.options.update: print ' This test has no reference to update'
if len(variants) == 0: variants = xrange(len(self.variants)) # iterate over all variants if len(variants) == 0: variants = xrange(len(self.variants)) # iterate over all variants
self.clean() self.clean()
self.prepareAll()
for variant in variants: for variant in variants:
try: try:
self.prepare(variant) self.prepare(variant)
@ -73,6 +74,11 @@ class Test():
return status return status
def prepareAll(self):
'''
Do all necessary preparations for the whole test
'''
return True
def prepare(self,variant): def prepare(self,variant):
''' '''
@ -119,6 +125,11 @@ class Test():
''' '''
return os.path.normpath(os.path.join(self.dirBase,'current/')) return os.path.normpath(os.path.join(self.dirBase,'current/'))
def dirProof(self):
'''
'''
return os.path.normpath(os.path.join(self.dirBase,'proof/'))
def fileInReference(self,file): def fileInReference(self,file):
''' '''
''' '''
@ -129,6 +140,11 @@ class Test():
''' '''
return os.path.join(self.dirCurrent(),file) return os.path.join(self.dirCurrent(),file)
def fileInProof(self,file):
'''
'''
return os.path.join(self.dirProof(),file)
def copy_Reference2Current(self,sourcefiles=[],targetfiles=[]): def copy_Reference2Current(self,sourcefiles=[],targetfiles=[]):
if len(targetfiles) == 0: targetfiles = sourcefiles if len(targetfiles) == 0: targetfiles = sourcefiles
@ -147,6 +163,15 @@ class Test():
except: except:
print 'Current2Reference: Unable to copy file ', file print 'Current2Reference: Unable to copy file ', file
def copy_Proof2Current(self,sourcefiles=[],targetfiles=[]):
if len(targetfiles) == 0: targetfiles = sourcefiles
for i,file in enumerate(sourcefiles):
try:
shutil.copy2(self.fileInProof(file),self.fileInCurrent(targetfiles[i]))
except:
print 'Proof2Current: Unable to copy file ', file
def copy_Current2Current(self,sourcefiles=[],targetfiles=[]): def copy_Current2Current(self,sourcefiles=[],targetfiles=[]):
for i,file in enumerate(sourcefiles): for i,file in enumerate(sourcefiles):
@ -186,7 +211,6 @@ class Test():
else: else:
raise Exception('mismatch in array size to compare') raise Exception('mismatch in array size to compare')
def compare_ArrayRefCur(self,ref,cur=''): def compare_ArrayRefCur(self,ref,cur=''):
if cur =='': cur = ref if cur =='': cur = ref
@ -194,36 +218,44 @@ class Test():
curName = self.fileInCurrent(cur) curName = self.fileInCurrent(cur)
return self.compare_Array(refName,curName) return self.compare_Array(refName,curName)
def compare_TableRefCur(self,headingsRef,ref,headingsCur='',cur=''): def compare_ArrayCurCur(self,cur0,cur1):
if headingsCur == '': headingsCur = headingsRef cur0Name = self.fileInCurrent(cur0)
if cur == '': cur = ref cur1Name = self.fileInCurrent(cur1)
refName = self.fileInReference(ref) return self.compare_Array(cur0Name,cur1Name)
curName = self.fileInCurrent(cur)
return self.compare_Table(headingsRef,refName,headingsCur,curName)
def compare_Table(self,headings0,file0,headings1,file1): def compare_Table(self,headings0,file0,headings1,file1,normHeadings='',normType=None,\
absoluteTolerance=False,perLine=False,skipLines=[]):
import numpy import numpy
print 'comparing ASCII Tables\n' , file0,'\n', file1 print 'comparing ASCII Tables\n' , file0,'\n', file1
if normHeadings == '': normHeadings = headings0
if len(headings0) == len(headings1): #check if comparison is possible and determine lenght of columns if len(headings0) == len(headings1) == len(normHeadings): #check if comparison is possible and determine lenght of columns
dataLength = len(headings0) dataLength = len(headings0)
length = [1 for i in xrange(dataLength)] length = [1 for i in xrange(dataLength)]
shape = [[] for i in xrange(dataLength)] shape = [[] for i in xrange(dataLength)]
data = [[] for i in xrange(dataLength)] data = [[] for i in xrange(dataLength)]
maxError = [0.0 for i in xrange(dataLength)] maxError = [0.0 for i in xrange(dataLength)]
maxNorm = [0.0 for i in xrange(dataLength)] absTol = [absoluteTolerance for i in xrange(dataLength)]
column = [[1 for i in xrange(dataLength)] for j in xrange(2)] column = [[1 for i in xrange(dataLength)] for j in xrange(2)]
norm = [[] for i in xrange(dataLength)]
normLength = [1 for i in xrange(dataLength)]
normShape = [[] for i in xrange(dataLength)]
normColumn = [1 for i in xrange(dataLength)]
for i in xrange(dataLength): for i in xrange(dataLength):
if headings0[i]['shape'] != headings1[i]['shape']: if headings0[i]['shape'] != headings1[i]['shape']:
raise Exception('shape mismatch when comparing ', headings0[i]['label'], ' with ', headings1[i]['label']) raise Exception('shape mismatch when comparing ', headings0[i]['label'], ' with ', headings1[i]['label'])
shape[i] = headings0[i]['shape'] shape[i] = headings0[i]['shape']
for j in xrange(numpy.shape(shape[i])[0]): for j in xrange(numpy.shape(shape[i])[0]):
length[i] *= shape[i][j] length[i] *= shape[i][j]
normShape[i] = normHeadings[i]['shape']
for j in xrange(numpy.shape(normShape[i])[0]):
normLength[i] *= normShape[i][j]
else: else:
raise Exception('trying to compare ', len(headings0), ' with ', len(headings1), ' data sets') raise Exception('trying to compare ', len(headings0), ' with ', len(headings1), ' normed by ', len(normHeadings),' data sets')
table0 = damask.ASCIItable(open(file0)) table0 = damask.ASCIItable(open(file0))
table0.head_read() table0.head_read()
@ -235,47 +267,74 @@ class Test():
False:'%s' }[length[i]>1]%headings0[i]['label'] False:'%s' }[length[i]>1]%headings0[i]['label']
key1 = {True :'1_%s', key1 = {True :'1_%s',
False:'%s' }[length[i]>1]%headings1[i]['label'] False:'%s' }[length[i]>1]%headings1[i]['label']
normKey = {True :'1_%s',
False:'%s' }[normLength[i]>1]%normHeadings[i]['label']
if key0 not in table0.labels: if key0 not in table0.labels:
raise Exception('column %s not found in 1. table...\n'%key0) raise Exception('column %s not found in 1. table...\n'%key0)
elif key1 not in table1.labels: elif key1 not in table1.labels:
raise Exception('column %s not found in 2. table...\n'%key1) raise Exception('column %s not found in 2. table...\n'%key1)
elif normKey not in table0.labels:
raise Exception('column %s not found in 1. table...\n'%normKey)
else: else:
column[0][i] = table0.labels.index(key0) # remember columns of requested data column[0][i] = table0.labels.index(key0) # remember columns of requested data
column[1][i] = table1.labels.index(key1) # remember columns of requested data in second column column[1][i] = table1.labels.index(key1) # remember columns of requested data in second column
normColumn[i] = table0.labels.index(normKey) # remember columns of requested data in second column
line0 = 0 line0 = 0
while table0.data_read(): # read next data line of ASCII table while table0.data_read(): # read next data line of ASCII table
line0 +=1 if line0 not in skipLines:
for i in xrange(dataLength): for i in xrange(dataLength):
myData = numpy.array(map(float,table0.data[column[0][i]:\ myData = numpy.array(map(float,table0.data[column[0][i]:\
column[0][i]+length[i]]),'d') column[0][i]+length[i]]),'d')
maxNorm[i] = max(maxNorm[i],numpy.linalg.norm(numpy.reshape(myData,shape[i]))) normData = numpy.array(map(float,table0.data[normColumn[i]:\
data[i]=numpy.append(data[i],myData) normColumn[i]+normLength[i]]),'d')
data[i] = numpy.append(data[i],numpy.reshape(myData,shape[i]))
if normType == 'pInf':
norm[i] = numpy.append(norm[i],numpy.max(numpy.abs(normData)))
else:
norm[i] = numpy.append(norm[i],numpy.linalg.norm(numpy.reshape(normData,normShape[i]),normType))
line0 +=1
for i in xrange(dataLength): for i in xrange(dataLength):
data[i] = numpy.reshape(data[i],[line0,length[i]]) if not perLine: norm[i] = [numpy.max(norm[i]) for j in xrange(line0-len(skipLines))]
if maxNorm[i] == 0.0: data[i] = numpy.reshape(data[i],[line0-len(skipLines),length[i]])
print 'Maximum norm of',headings0[i]['label'],'in 1. table is 0, using absolute tolerance' if any(norm[i]) == 0.0 or absTol[i]:
maxNorm[i] = 1.0 norm[i] = [1.0 for j in xrange(line0-len(skipLines))]
absTol[i] = True
if perLine:
print 'At least one norm of',headings0[i]['label'],'in 1. table is 0.0, using absolute tolerance'
else:
print 'Maximum norm of',headings0[i]['label'],'in 1. table is 0.0, using absolute tolerance'
line1 = 0 line1 = 0
while table1.data_read(): # read next data line of ASCII table while table1.data_read(): # read next data line of ASCII table
if line1 not in skipLines:
for i in xrange(dataLength): for i in xrange(dataLength):
myData = numpy.array(map(float,table1.data[column[1][i]:\ myData = numpy.array(map(float,table1.data[column[1][i]:\
column[1][i]+length[i]]),'d') column[1][i]+length[i]]),'d')
maxError[i] = max(maxError[i],numpy.linalg.norm(numpy.reshape(myData-data[i][line1,:],shape[i]))) maxError[i] = max(maxError[i],numpy.linalg.norm(numpy.reshape(myData-data[i][line1-len(skipLines),:],shape[i]))/norm[i][line1-len(skipLines)])
line1 +=1 line1 +=1
if (line0 != line1): raise Exception('found ', line0, ' lines in 1. table and ', line1, ' in 2. table') if (line0 != line1): raise Exception('found ', line0, ' lines in 1. table and ', line1, ' in 2. table')
print ' ********' print ' ********'
for i in xrange(dataLength): for i in xrange(dataLength):
maxError[i] = maxError[i]/maxNorm[i] if absTol[i]:
print ' * maximum absolute error ',maxError[i],' for ', headings0[i]['label'],' and ',headings1[i]['label']
else:
print ' * maximum relative error ',maxError[i],' for ', headings0[i]['label'],' and ',headings1[i]['label'] print ' * maximum relative error ',maxError[i],' for ', headings0[i]['label'],' and ',headings1[i]['label']
print ' ********' print ' ********'
return maxError return maxError
def compare_TableRefCur(self,headingsRef,ref,headingsCur='',cur='',normHeadings='',normType=None,\
absoluteTolerance=False,perLine=False,skipLines=[]):
if cur == '': cur = ref
if headingsCur == '': headingsCur = headingsRef
refName = self.fileInReference(ref)
curName = self.fileInCurrent(cur)
return self.compare_Table(headingsRef,refName,headingsCur,curName,normHeadings,normType,absoluteTolerance,perLine,skipLine)
def report_Success(self,culprit): def report_Success(self,culprit):
if culprit < 0: if culprit < 0: