From fb7adf7b891a685c1b5148ea8f2d69c669737806 Mon Sep 17 00:00:00 2001 From: Philip Eisenlohr Date: Thu, 15 Dec 2011 08:53:18 +0000 Subject: [PATCH] adopted use of general damask package --- processing/post/addCalculation.py | 4 +- processing/post/addCauchy.py | 4 +- processing/post/addDeterminant.py | 4 +- processing/post/addMises.py | 89 ++++++++-------------------- processing/post/addNorm.py | 4 +- processing/setup/setup_processing.py | 29 ++++----- 6 files changed, 43 insertions(+), 91 deletions(-) diff --git a/processing/post/addCalculation.py b/processing/post/addCalculation.py index 7f26b64bf..7d5de4809 100755 --- a/processing/post/addCalculation.py +++ b/processing/post/addCalculation.py @@ -1,6 +1,6 @@ #!/usr/bin/python -import os,re,sys,math,string,damask_tools +import os,re,sys,math,string,damask from optparse import OptionParser, Option # ----------------------------- @@ -67,7 +67,7 @@ else: for file in files: if file['name'] != 'STDIN': print file['name'] - table = damask_tools.ASCII_TABLE(file['input'],file['output'],False) # make unbuffered ASCII_table + table = damask.ASCIItable(file['input'],file['output'],False) # make unbuffered ASCII_table table.head_read() # read ASCII header info table.info_append(string.replace('$Id: addNorm.py 1118 2011-11-23 14:54:53Z MPIE\p.eisenlohr $','\n','\\n') + \ '\t' + ' '.join(sys.argv[1:])) diff --git a/processing/post/addCauchy.py b/processing/post/addCauchy.py index cd720f8f3..0e41b0338 100755 --- a/processing/post/addCauchy.py +++ b/processing/post/addCauchy.py @@ -1,6 +1,6 @@ #!/usr/bin/python -import os,re,sys,math,numpy,string,damask_tools +import os,re,sys,math,numpy,string,damask from optparse import OptionParser, Option # ----------------------------- @@ -75,7 +75,7 @@ else: for file in files: if file['name'] != 'STDIN': print file['name'] - table = damask_tools.ASCII_TABLE(file['input'],file['output'],False) # make unbuffered ASCII_table + table = damask.ASCIItable(file['input'],file['output'],False) # make unbuffered ASCII_table table.head_read() # read ASCII header info table.info_append(string.replace('$Id$','\n','\\n') + \ '\t' + ' '.join(sys.argv[1:])) diff --git a/processing/post/addDeterminant.py b/processing/post/addDeterminant.py index 20eeddf2a..4e237cb60 100755 --- a/processing/post/addDeterminant.py +++ b/processing/post/addDeterminant.py @@ -1,6 +1,6 @@ #!/usr/bin/python -import os,re,sys,math,string,damask_tools +import os,re,sys,math,string,damask from optparse import OptionParser, Option # ----------------------------- @@ -79,7 +79,7 @@ else: for file in files: if file['name'] != 'STDIN': print file['name'] - table = damask_tools.ASCII_TABLE(file['input'],file['output'],False) # make unbuffered ASCII_table + table = damask.ASCIItable(file['input'],file['output'],False) # make unbuffered ASCII_table table.head_read() # read ASCII header info table.info_append(string.replace('$Id$','\n','\\n') + \ '\t' + ' '.join(sys.argv[1:])) diff --git a/processing/post/addMises.py b/processing/post/addMises.py index 50532595e..cd9658c8d 100755 --- a/processing/post/addMises.py +++ b/processing/post/addMises.py @@ -1,6 +1,6 @@ #!/usr/bin/python -import os,re,sys,math,numpy,string +import os,re,sys,math,numpy,string,damask from optparse import OptionParser, Option # ----------------------------- @@ -31,7 +31,7 @@ def Mises(what,tensor): { 'stress': 3.0/2.0, 'strain': 2.0/3.0, - }[what]) + }[what.lower()]) # -------------------------------------------------------------------- @@ -45,14 +45,11 @@ Add vonMises equivalent values for symmetric part of requested strains and/or st ) -parser.add_option('-m','--memory', dest='memory', action='store_true', \ - help='load complete file into memory [%default]') parser.add_option('-e','--strain', dest='strain', action='extend', type='string', \ help='heading(s) of columns containing strain tensors') parser.add_option('-s','--stress', dest='stress', action='extend', type='string', \ help='heading(s) of columns containing stress tensors') -parser.set_defaults(memory = False) parser.set_defaults(strain = []) parser.set_defaults(stress = []) @@ -86,30 +83,12 @@ else: # ------------------------------------------ loop over input files --------------------------------------- for file in files: - print file['name'] + if file['name'] != 'STDIN': print file['name'] - # get labels by either read the first row, or - if keyword header is present - the last line of the header - - firstline = file['input'].readline() - m = re.search('(\d+)\s*head', firstline.lower()) - if m: - headerlines = int(m.group(1)) - passOn = [file['input'].readline() for i in range(1,headerlines)] - headers = file['input'].readline().split() - else: - headerlines = 1 - passOn = [] - headers = firstline.split() - - if options.memory: - data = file['input'].readlines() - else: - data = [] - - for i,l in enumerate(headers): - if l.startswith('1_'): - if re.match('\d+_',l[2:]) or i == len(headers)-1 or not headers[i+1].endswith(l[2:]): - headers[i] = l[2:] + table = damask.ASCIItable(file['input'],file['output'],False) # make unbuffered ASCII_table + table.head_read() # read ASCII header info + table.info_append(string.replace('$Id$','\n','\\n') + \ + '\t' + ' '.join(sys.argv[1:])) active = {} column = {} @@ -119,57 +98,37 @@ for file in files: for label in info['label']: key = {True :'1_%s', False:'%s' }[info['len']>1]%label - if key not in headers: + if key not in table.labels: sys.stderr.write('column %s not found...\n'%key) else: if datatype not in active: active[datatype] = [] if datatype not in column: column[datatype] = {} active[datatype].append(label) - column[datatype][label] = headers.index(key) - head.append('Mises(%s)'%label) + column[datatype][label] = table.labels.index(key) # remember columns of requested data + table.labels_append('Mises(%s)'%label) # extend ASCII header with new labels # ------------------------------------------ assemble header --------------------------------------- - output = '%i\theader'%(headerlines+1) + '\n' + \ - ''.join(passOn) + \ - string.replace('$Id$','\n','\\n')+ '\t' + \ - ' '.join(sys.argv[1:]) + '\n' + \ - '\t'.join(headers + head) + '\n' # build extended header + table.head_write() - if not options.memory: - file['output'].write(output) - output = '' +# ------------------------------------------ process data --------------------------------------- -# ------------------------------------------ read file --------------------------------------- - - for line in {True : data, - False : file['input']}[options.memory]: - items = line.split()[:len(headers)] - if len(items) < len(headers): - continue + while table.data_read(): # read next data line of ASCII table - output += '\t'.join(items) + for datatype,labels in active.items(): # loop over vector,tensor + for label in labels: # loop over all requested norms + table.data_append(Mises(datatype, + numpy.array(map(float,items[column[datatype][label]: + column[datatype][label]+datainfo[datatype]['len']]),'d').reshape(3,3))) - for datatype,labels in active.items(): - for label in labels: - theMises = Mises(datatype, - numpy.array(map(float,items[column[datatype][label]: - column[datatype][label]+datainfo[datatype]['len']]),'d').reshape(3,3)) - output += '\t%f'%theMises + table.data_write() # output processed line - output += '\n' - - if not options.memory: - file['output'].write(output) - output = '' - - file['input'].close() - # ------------------------------------------ output result --------------------------------------- - if options.memory: - file['output'].write(output) + table.output_flush() # just in case of buffered ASCII table + file['input'].close() # close input ASCII table if file['name'] != 'STDIN': - file['output'].close - os.rename(file['name']+'_tmp',file['name']) + file['output'].close # close output ASCII table + os.rename(file['name']+'_tmp',file['name']) # overwrite old one with tmp new + diff --git a/processing/post/addNorm.py b/processing/post/addNorm.py index 95bb6094d..9e5a2affc 100755 --- a/processing/post/addNorm.py +++ b/processing/post/addNorm.py @@ -1,6 +1,6 @@ #!/usr/bin/python -import os,re,sys,math,string,damask_tools +import os,re,sys,math,string,damask from optparse import OptionParser, Option # ----------------------------- @@ -79,7 +79,7 @@ else: for file in files: if file['name'] != 'STDIN': print file['name'] - table = damask_tools.ASCII_TABLE(file['input'],file['output'],False) # make unbuffered ASCII_table + table = damask.ASCIItable(file['input'],file['output'],False) # make unbuffered ASCII_table table.head_read() # read ASCII header info table.info_append(string.replace('$Id$','\n','\\n') + \ '\t' + ' '.join(sys.argv[1:])) diff --git a/processing/setup/setup_processing.py b/processing/setup/setup_processing.py index cd0a94e5f..a7fee7009 100755 --- a/processing/setup/setup_processing.py +++ b/processing/setup/setup_processing.py @@ -2,10 +2,9 @@ # Makes postprocessing routines acessible from everywhere. -import os,sys,glob,string +import os,sys,glob,string,damask from optparse import OptionParser, Option -import damask_tools # ----------------------------- class extendableOption(Option): @@ -52,10 +51,9 @@ else: acml_subdir='%s64/lib'%options.compiler -#getting pathinfo -damask_variables = damask_tools.DAMASK_TOOLS() -baseDir = damask_variables.relPath('processing/') -codeDir = damask_variables.relPath('code/') +damaskEnv = damask.Environment() +baseDir = damaskEnv.relPath('processing/') +codeDir = damaskEnv.relPath('code/') #define ToDo list bin_link = { \ @@ -101,7 +99,7 @@ compile = { \ execute = { \ 'postMath' : [ - 'rm %s'%(os.path.join(damask_variables.relPath('lib/'),'DAMASK.so')), + 'rm %s'%(os.path.join(damaskEnv.relPath('lib/'),'DAMASK.so')), # The following command is used to compile math.f90 and make the functions defined in DAMASK_math.pyf # available for python in the module DAMASK_math.so # It uses the fortran wrapper f2py that is included in the numpy package to construct the @@ -112,9 +110,9 @@ execute = { \ '-c --fcompiler=%s '%(f2py_compiler) +\ '%s ' %(os.path.join(codeDir,'DAMASK2Python_helper.f90'))+\ '%s ' %(os.path.join(codeDir,'math.f90'))+\ - '%s ' %(os.path.join(damask_variables.pathInfo['fftw'],'libfftw3.a'))+\ - '%s' %(os.path.join(damask_variables.pathInfo['acml'],acml_subdir,'libacml.a'), - 'mv %s %s' %(os.path.join(codeDir,'DAMASK.so'),damask_variables.relPath('lib/')), + '%s ' %(os.path.join(damaskEnv.pathInfo['fftw'],'libfftw3.a'))+\ + '%s' %(os.path.join(damaskEnv.pathInfo['acml'],acml_subdir,'libacml.a')), + 'mv %s %s' %(os.path.join(codeDir,'DAMASK.so'),damaskEnv.relPath('lib/')), ] } @@ -135,7 +133,7 @@ os.chdir(codeDir) # needed for compilation with gfortran and f for tasks in execute: for cmd in execute[tasks]: os.system(cmd) -os.chdir(damask_variables.relPath('processing/setup/')) +os.chdir(damaskEnv.relPath('processing/setup/')) modules = glob.glob('*.mod') for module in modules: @@ -146,16 +144,11 @@ for dir in bin_link: for file in bin_link[dir]: src = os.path.abspath(os.path.join(baseDir,dir,file)) if (file == ''): - sym_link = os.path.abspath(os.path.join(damask_variables.binDir(),dir)) + sym_link = os.path.abspath(os.path.join(damaskEnv.binDir(),dir)) else: - sym_link = os.path.abspath(os.path.join(damask_variables.binDir(),os.path.splitext(file)[0])) + sym_link = os.path.abspath(os.path.join(damaskEnv.binDir(),os.path.splitext(file)[0])) print sym_link,'-->',src if os.path.lexists(sym_link): os.remove(sym_link) os.symlink(src,sym_link) - #--- uncomment next lines to remove your old symbolic links in ~/bin - #old_link=sym_link.replace(damask_root,os.getenv('HOME')) - #if os.path.lexists(old_link): - # os.remove(old_link) -