did some conversion needed for use with python 3

This commit is contained in:
Martin Diehl 2013-09-18 19:31:27 +00:00
parent 56d21286a6
commit 415892b8e7
5 changed files with 51 additions and 51 deletions

View File

@ -118,7 +118,7 @@ class Material():
def __repr__(self): def __repr__(self):
me = [] me = []
for part in self.parts: for part in self.parts:
print 'doing',part print('doing',part)
me += ['','#-----------------------------#','<%s>'%part,'#-----------------------------#',] me += ['','#-----------------------------#','<%s>'%part,'#-----------------------------#',]
for section in self.data[part]['__order__']: for section in self.data[part]['__order__']:
me += ['','[%s] %s'%(section,'-'*max(0,27-len(section))),'',] me += ['','[%s] %s'%(section,'-'*max(0,27-len(section))),'',]
@ -260,7 +260,7 @@ def ex1():
mat.add_section('phase','phase1',p) mat.add_section('phase','phase1',p)
mat.add_section('texture','tex1',t) mat.add_section('texture','tex1',t)
mat.add_microstructure('mustruct1',{'phase':['phase1']*2,'texture':['tex1']*2,'fraction':[0.2]*2}) mat.add_microstructure('mustruct1',{'phase':['phase1']*2,'texture':['tex1']*2,'fraction':[0.2]*2})
print mat print(mat)
mat.write(file='poop') mat.write(file='poop')
mat.write(file='poop',overwrite=True) mat.write(file='poop',overwrite=True)

View File

@ -27,7 +27,7 @@ class Material():
def __repr__(self): def __repr__(self):
me = [] me = []
for part in self.parts: for part in self.parts:
print 'doing',part print('doing',part)
me += ['','#-----------------------------#','<%s>'%part,'#-----------------------------#',] me += ['','#-----------------------------#','<%s>'%part,'#-----------------------------#',]
for section in self.data[part]['__order__']: for section in self.data[part]['__order__']:
section_number=self.data[part]['__order__'].index(section) section_number=self.data[part]['__order__'].index(section)
@ -185,7 +185,7 @@ class Microstructure(Section):
theData = '' theData = ''
for property in ['phase','texture','fraction']: for property in ['phase','texture','fraction']:
if property not in data.keys(): # suboptimal!! if property not in data.keys(): # suboptimal!!
print 'Croak!' print('Croak!')
else: else:
theData += '%s %s\t'%(property,data[property]) theData += '%s %s\t'%(property,data[property])
self.add_multiKey('constituent',theData) self.add_multiKey('constituent',theData)
@ -265,7 +265,7 @@ def example_1(write_file=False):
p.add_key('interaction_slipslip',[1]*27) p.add_key('interaction_slipslip',[1]*27)
mat.add_section('phase','phase_label',p) mat.add_section('phase','phase_label',p)
print mat print(mat)
mat.write(file='material.config_example_1') mat.write(file='material.config_example_1')
mat.write(file='material.config_example_1',overwrite=True) mat.write(file='material.config_example_1',overwrite=True)
return mat return mat

View File

@ -23,31 +23,31 @@ class MARC_POST():
def opent16(self,incr=None): def opent16(self,incr=None):
self.fpath=os.path.join(self.projdir,self.postname) self.fpath=os.path.join(self.projdir,self.postname)
print 'Trying to open ',self.fpath,' ...' print('Trying to open ',self.fpath,' ...')
self.p=py_post.post_open(self.fpath) self.p=py_post.post_open(self.fpath)
if self.p==None: if self.p==None:
print 'Could not open %s.'%self.postname; #return 'err'#; sys.exit(1) print('Could not open %s.'%self.postname); #return 'err'#; sys.exit(1)
raise Exception('Could not open t16') raise Exception('Could not open t16')
print 'Postfile %s%s is open ...'%(self.projdir,self.postname) print('Postfile %s%s is open ...'%(self.projdir,self.postname))
self.maxincr=self.p.increments() self.maxincr=self.p.increments()
print 'and has %i increments'%self.maxincr print('and has %i increments'%self.maxincr)
if incr is None: if incr is None:
self.p.moveto(self.maxincr-1) self.p.moveto(self.maxincr-1)
else: else:
self.p.moveto(incr+1) self.p.moveto(incr+1)
print 'moved to increment ', self.p.increment print('moved to increment ', self.p.increment)
self.p.extrapolation('translate') # linear, translate, average. query with p.extrapolate self.p.extrapolation('translate') # linear, translate, average. query with p.extrapolate
print 'extrapolation method is ', self.p.extrapolate print('extrapolation method is ', self.p.extrapolate)
print 'collecting model information' print('collecting model information')
self.t16info(printFlag=0) self.t16info(printFlag=0)
print 't16 is open' print('t16 is open')
self.p self.p
def t16info(self, printFlag=1 def t16info(self, printFlag=1
): ):
if not self.p: if not self.p:
self.p=self.opent16()#post_open(self.postname) self.p=self.opent16()#post_open(self.postname)
print self.p print(self.p)
oldincr=self.p.position oldincr=self.p.position
if oldincr==0: if oldincr==0:
self.p.moveto(1) self.p.moveto(1)
@ -65,15 +65,15 @@ class MARC_POST():
self.nscal_list[i]=self.p.node_scalar_label(i) self.nscal_list[i]=self.p.node_scalar_label(i)
for i in range (0,self.elscals): for i in range (0,self.elscals):
self.elscal_list[i]=self.p.element_scalar_label(i) self.elscal_list[i]=self.p.element_scalar_label(i)
if printFlag==1: print i, self.elscal_list[i] if printFlag==1: print(i, self.elscal_list[i])
for i in range (0,self.eltens): for i in range (0,self.eltens):
self.elten_list[i]=self.p.element_tensor_label(i) self.elten_list[i]=self.p.element_tensor_label(i)
if printFlag==1: print i, self.elten_list[i] if printFlag==1: print(i, self.elten_list[i])
for i in range(0,self.p.element_tensors()): for i in range(0,self.p.element_tensors()):
if printFlag==1: print 'Element Tensor: ', i, self.p.element_tensor_label(i) if printFlag==1: print('Element Tensor: ', i, self.p.element_tensor_label(i))
if printFlag==1: print '' if printFlag==1: print('')
for i in range(0,self.p.element_scalars()): for i in range(0,self.p.element_scalars()):
if printFlag==1: print 'Element Scalar: ', i, self.p.element_scalar_label(i) if printFlag==1: print('Element Scalar: ', i, self.p.element_scalar_label(i))
if oldincr==0: if oldincr==0:
self.p.moveto(0) self.p.moveto(0)
@ -87,7 +87,7 @@ class MARC_POST():
else: else:
print('post object not open?') print('post object not open?')
except: except:
print 'ERROR. Could not close FEM result file.' print('ERROR. Could not close FEM result file.')
def getLabelNr(self, label=None, type='Scalar'): def getLabelNr(self, label=None, type='Scalar'):
if type[0]=='S' or type[0]=='s': # element scalar if type[0]=='S' or type[0]=='s': # element scalar
@ -506,7 +506,7 @@ class VTK_WRITER():
posXYZ+wVec, posXYZ+wVec,
posXYZ+wVec+lVec] posXYZ+wVec+lVec]
pts.extend([pts[0]+hVec,pts[1]+hVec,pts[2]+hVec,pts[3]+hVec]) pts.extend([pts[0]+hVec,pts[1]+hVec,pts[2]+hVec,pts[3]+hVec])
print len(pts), pts print(len(pts), pts)
self.fsb.write('POINTS %i float\n'%len(pts)) self.fsb.write('POINTS %i float\n'%len(pts))
for npts in range(0,len(pts)): for npts in range(0,len(pts)):
self.fsb.write('%f %f %f\n'%(pts[npts][0], pts[npts][1], pts[npts][2])) self.fsb.write('%f %f %f\n'%(pts[npts][0], pts[npts][1], pts[npts][2]))
@ -543,7 +543,7 @@ class VTK_WRITER():
self.fsb.write('\n') self.fsb.write('\n')
self.fsb.close() self.fsb.close()
print self.fsb print(self.fsb)
def example_unstructured(self): def example_unstructured(self):
self.openFile(filename='example_unstructured_grid.vtk') self.openFile(filename='example_unstructured_grid.vtk')

View File

@ -104,7 +104,7 @@ class Marc(Solver):
if compile: cmd += ' -u ' + user+'.f90' + ' -save y' if compile: cmd += ' -u ' + user+'.f90' + ' -save y'
else: cmd += ' -prog ' + user else: cmd += ' -prog ' + user
print 'job submission with%s compilation: %s'%({False:'out',True:''}[compile],user) print('job submission with%s compilation: %s'%({False:'out',True:''}[compile],user))
if logfile: if logfile:
log = open(logfile, 'w') log = open(logfile, 'w')
print(cmd) print(cmd)
@ -120,7 +120,7 @@ class Marc(Solver):
fid_out = open(outFile,'r') fid_out = open(outFile,'r')
for ln in fid_out: for ln in fid_out:
if (string.find(ln,'tress iteration') is not -1): if (string.find(ln,'tress iteration') is not -1):
print ln print(ln)
elif (string.find(ln,'Exit number') is not -1): elif (string.find(ln,'Exit number') is not -1):
substr = ln[string.find(ln,'Exit number'):len(ln)] substr = ln[string.find(ln,'Exit number'):len(ln)]
exitnumber = int(substr[12:16]) exitnumber = int(substr[12:16])

View File

@ -16,10 +16,10 @@ class Test():
def __init__(self,test_description): def __init__(self,test_description):
print '!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\n\n' \ print('!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\n\n' \
+'----------------------------------------------------------------\n' \ +'----------------------------------------------------------------\n' \
+'| '+test_description+'\n' \ +'| '+test_description+'\n' \
+'----------------------------------------------------------------' +'----------------------------------------------------------------')
self.dirBase = os.path.dirname(os.path.realpath(inspect.getfile(self.__class__))) self.dirBase = os.path.dirname(os.path.realpath(inspect.getfile(self.__class__)))
self.parser = OptionParser( self.parser = OptionParser(
description = 'Using: $Id run_test.py 1285 2012-02-09 08:54:09Z MPIE\m.diehl $', description = 'Using: $Id run_test.py 1285 2012-02-09 08:54:09Z MPIE\m.diehl $',
@ -37,7 +37,7 @@ class Test():
Run all variants and report first failure. Run all variants and report first failure.
''' '''
if not self.testPossible(): return -1 if not self.testPossible(): return -1
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() self.prepareAll()
@ -50,8 +50,8 @@ class Test():
self.update(variant) self.update(variant)
elif not self.compare(variant): elif not self.compare(variant):
return variant+1 return variant+1
except Exception,e : except Exception as e :
print '\nWARNING:\n %s\n'%e print('\nWARNING:\n %s\n'%e)
return variant+1 return variant+1
return 0 return 0
@ -159,7 +159,7 @@ class Test():
try: try:
shutil.copy2(self.fileInReference(file),self.fileInCurrent(targetfiles[i])) shutil.copy2(self.fileInReference(file),self.fileInCurrent(targetfiles[i]))
except: except:
print 'Reference2Current: Unable to copy file ', file print('Reference2Current: Unable to copy file ', file)
def copy_Base2Current(self,sourceDir,sourcefiles=[],targetfiles=[]): def copy_Base2Current(self,sourceDir,sourcefiles=[],targetfiles=[]):
@ -169,8 +169,8 @@ class Test():
try: try:
shutil.copy2(os.path.join(source,file),self.fileInCurrent(targetfiles[i])) shutil.copy2(os.path.join(source,file),self.fileInCurrent(targetfiles[i]))
except: except:
print os.path.join(source,file) print(os.path.join(source,file))
print 'Base2Current: Unable to copy file ', file print('Base2Current: Unable to copy file ', file)
def copy_Current2Reference(self,sourcefiles=[],targetfiles=[]): def copy_Current2Reference(self,sourcefiles=[],targetfiles=[]):
@ -179,7 +179,7 @@ class Test():
try: try:
shutil.copy2(self.fileInCurrent(file),self.fileInReference(targetfiles[i])) shutil.copy2(self.fileInCurrent(file),self.fileInReference(targetfiles[i]))
except: except:
print 'Current2Reference: Unable to copy file ', file print('Current2Reference: Unable to copy file ', file)
def copy_Proof2Current(self,sourcefiles=[],targetfiles=[]): def copy_Proof2Current(self,sourcefiles=[],targetfiles=[]):
@ -188,7 +188,7 @@ class Test():
try: try:
shutil.copy2(self.fileInProof(file),self.fileInCurrent(targetfiles[i])) shutil.copy2(self.fileInProof(file),self.fileInCurrent(targetfiles[i]))
except: except:
print 'Proof2Current: Unable to copy file ', file print('Proof2Current: Unable to copy file ', file)
def copy_Current2Current(self,sourcefiles=[],targetfiles=[]): def copy_Current2Current(self,sourcefiles=[],targetfiles=[]):
@ -196,13 +196,13 @@ class Test():
try: try:
shutil.copy2(self.fileInReference(file),self.fileInCurrent(targetfiles[i])) shutil.copy2(self.fileInReference(file),self.fileInCurrent(targetfiles[i]))
except: except:
print 'Current2Current: Unable to copy file ', file print('Current2Current: Unable to copy file ', file)
def execute_inCurrentDir(self,cmd,outfile='execute_log.txt'): def execute_inCurrentDir(self,cmd,outfile='execute_log.txt'):
os.chdir(self.dirCurrent()) os.chdir(self.dirCurrent())
file=open(outfile,'a+') file=open(outfile,'a+')
print cmd print(cmd)
process = subprocess.Popen(shlex.split(cmd),stdout = file,stderr = subprocess.STDOUT) process = subprocess.Popen(shlex.split(cmd),stdout = file,stderr = subprocess.STDOUT)
process.wait() process.wait()
file.close() file.close()
@ -210,7 +210,7 @@ class Test():
def compare_Array(self,File1,File2): def compare_Array(self,File1,File2):
import numpy import numpy
print 'comparing\n ' , File1,'\n ', File2 print('comparing\n ' , File1,'\n ', File2)
refFile = open(File1) refFile = open(File1)
table = damask.ASCIItable(refFile) table = damask.ASCIItable(refFile)
table.head_read() table.head_read()
@ -224,7 +224,7 @@ class Test():
max_loc=numpy.argmax(abs(refArrayNonZero[curArray.nonzero()]/curArray[curArray.nonzero()]-1.)) max_loc=numpy.argmax(abs(refArrayNonZero[curArray.nonzero()]/curArray[curArray.nonzero()]-1.))
refArrayNonZero = refArrayNonZero[curArray.nonzero()] refArrayNonZero = refArrayNonZero[curArray.nonzero()]
curArray = curArray[curArray.nonzero()] curArray = curArray[curArray.nonzero()]
print ' ********\n * maximum relative error ',max_err,' for ', refArrayNonZero[max_loc],' and ',curArray[max_loc],'\n ********' print(' ********\n * maximum relative error ',max_err,' for ', refArrayNonZero[max_loc],' and ',curArray[max_loc],'\n ********')
return max_err return max_err
else: else:
raise Exception('mismatch in array size to compare') raise Exception('mismatch in array size to compare')
@ -246,7 +246,7 @@ class Test():
absoluteTolerance=False,perLine=False,skipLines=[]): 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 normHeadings == '': normHeadings = headings0
if len(headings0) == len(headings1) == len(normHeadings): #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
@ -320,9 +320,9 @@ class Test():
norm[i] = [1.0 for j in xrange(line0-len(skipLines))] norm[i] = [1.0 for j in xrange(line0-len(skipLines))]
absTol[i] = True absTol[i] = True
if perLine: if perLine:
print 'At least one norm of',headings0[i]['label'],'in 1. table is 0.0, using absolute tolerance' print('At least one norm of',headings0[i]['label'],'in 1. table is 0.0, using absolute tolerance')
else: else:
print 'Maximum norm of',headings0[i]['label'],'in 1. table is 0.0, using absolute tolerance' 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
@ -335,13 +335,13 @@ class Test():
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):
if absTol[i]: if absTol[i]:
print ' * maximum absolute error ',maxError[i],' for ', headings0[i]['label'],' and ',headings1[i]['label'] print(' * maximum absolute error ',maxError[i],' for ', headings0[i]['label'],' and ',headings1[i]['label'])
else: 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,\ def compare_TableRefCur(self,headingsRef,ref,headingsCur='',cur='',normHeadings='',normType=None,\
@ -366,14 +366,14 @@ class Test():
def report_Success(self,culprit): def report_Success(self,culprit):
if culprit == 0: if culprit == 0:
print '%s passed.'%({False: 'The test', print('%s passed.'%({False: 'The test',
True: 'All %i tests'%(len(self.variants))}[len(self.variants) > 1]) True: 'All %i tests'%(len(self.variants))}[len(self.variants) > 1]))
print '\n!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\n' print('\n!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\n')
return 0 return 0
if culprit == -1: if culprit == -1:
print 'Warning: Could not start test' print('Warning: Could not start test')
return 0 return 0
else: else:
print ' ********\n * Test %i failed...\n ********'%(culprit) print(' ********\n * Test %i failed...\n ********'%(culprit))
print '\n!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\n' print('\n!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\n')
return culprit return culprit