adopted use of general damask package

This commit is contained in:
Philip Eisenlohr 2011-12-15 08:53:18 +00:00
parent a8dece8694
commit fb7adf7b89
6 changed files with 43 additions and 91 deletions

View File

@ -1,6 +1,6 @@
#!/usr/bin/python #!/usr/bin/python
import os,re,sys,math,string,damask_tools import os,re,sys,math,string,damask
from optparse import OptionParser, Option from optparse import OptionParser, Option
# ----------------------------- # -----------------------------
@ -67,7 +67,7 @@ else:
for file in files: for file in files:
if file['name'] != 'STDIN': print file['name'] 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.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') + \ 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:])) '\t' + ' '.join(sys.argv[1:]))

View File

@ -1,6 +1,6 @@
#!/usr/bin/python #!/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 from optparse import OptionParser, Option
# ----------------------------- # -----------------------------
@ -75,7 +75,7 @@ else:
for file in files: for file in files:
if file['name'] != 'STDIN': print file['name'] 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.head_read() # read ASCII header info
table.info_append(string.replace('$Id$','\n','\\n') + \ table.info_append(string.replace('$Id$','\n','\\n') + \
'\t' + ' '.join(sys.argv[1:])) '\t' + ' '.join(sys.argv[1:]))

View File

@ -1,6 +1,6 @@
#!/usr/bin/python #!/usr/bin/python
import os,re,sys,math,string,damask_tools import os,re,sys,math,string,damask
from optparse import OptionParser, Option from optparse import OptionParser, Option
# ----------------------------- # -----------------------------
@ -79,7 +79,7 @@ else:
for file in files: for file in files:
if file['name'] != 'STDIN': print file['name'] 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.head_read() # read ASCII header info
table.info_append(string.replace('$Id$','\n','\\n') + \ table.info_append(string.replace('$Id$','\n','\\n') + \
'\t' + ' '.join(sys.argv[1:])) '\t' + ' '.join(sys.argv[1:]))

View File

@ -1,6 +1,6 @@
#!/usr/bin/python #!/usr/bin/python
import os,re,sys,math,numpy,string import os,re,sys,math,numpy,string,damask
from optparse import OptionParser, Option from optparse import OptionParser, Option
# ----------------------------- # -----------------------------
@ -31,7 +31,7 @@ def Mises(what,tensor):
{ {
'stress': 3.0/2.0, 'stress': 3.0/2.0,
'strain': 2.0/3.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', \ parser.add_option('-e','--strain', dest='strain', action='extend', type='string', \
help='heading(s) of columns containing strain tensors') help='heading(s) of columns containing strain tensors')
parser.add_option('-s','--stress', dest='stress', action='extend', type='string', \ parser.add_option('-s','--stress', dest='stress', action='extend', type='string', \
help='heading(s) of columns containing stress tensors') help='heading(s) of columns containing stress tensors')
parser.set_defaults(memory = False)
parser.set_defaults(strain = []) parser.set_defaults(strain = [])
parser.set_defaults(stress = []) parser.set_defaults(stress = [])
@ -86,30 +83,12 @@ else:
# ------------------------------------------ loop over input files --------------------------------------- # ------------------------------------------ loop over input files ---------------------------------------
for file in 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 table = damask.ASCIItable(file['input'],file['output'],False) # make unbuffered ASCII_table
table.head_read() # read ASCII header info
firstline = file['input'].readline() table.info_append(string.replace('$Id$','\n','\\n') + \
m = re.search('(\d+)\s*head', firstline.lower()) '\t' + ' '.join(sys.argv[1:]))
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:]
active = {} active = {}
column = {} column = {}
@ -119,57 +98,37 @@ for file in files:
for label in info['label']: for label in info['label']:
key = {True :'1_%s', key = {True :'1_%s',
False:'%s' }[info['len']>1]%label 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) sys.stderr.write('column %s not found...\n'%key)
else: else:
if datatype not in active: active[datatype] = [] if datatype not in active: active[datatype] = []
if datatype not in column: column[datatype] = {} if datatype not in column: column[datatype] = {}
active[datatype].append(label) active[datatype].append(label)
column[datatype][label] = headers.index(key) column[datatype][label] = table.labels.index(key) # remember columns of requested data
head.append('Mises(%s)'%label) table.labels_append('Mises(%s)'%label) # extend ASCII header with new labels
# ------------------------------------------ assemble header --------------------------------------- # ------------------------------------------ assemble header ---------------------------------------
output = '%i\theader'%(headerlines+1) + '\n' + \ table.head_write()
''.join(passOn) + \
string.replace('$Id$','\n','\\n')+ '\t' + \
' '.join(sys.argv[1:]) + '\n' + \
'\t'.join(headers + head) + '\n' # build extended header
if not options.memory: # ------------------------------------------ process data ---------------------------------------
file['output'].write(output)
output = ''
# ------------------------------------------ read file --------------------------------------- while table.data_read(): # read next data line of ASCII table
for line in {True : data, for datatype,labels in active.items(): # loop over vector,tensor
False : file['input']}[options.memory]: for label in labels: # loop over all requested norms
items = line.split()[:len(headers)] table.data_append(Mises(datatype,
if len(items) < len(headers):
continue
output += '\t'.join(items)
for datatype,labels in active.items():
for label in labels:
theMises = Mises(datatype,
numpy.array(map(float,items[column[datatype][label]: numpy.array(map(float,items[column[datatype][label]:
column[datatype][label]+datainfo[datatype]['len']]),'d').reshape(3,3)) column[datatype][label]+datainfo[datatype]['len']]),'d').reshape(3,3)))
output += '\t%f'%theMises
output += '\n' table.data_write() # output processed line
if not options.memory:
file['output'].write(output)
output = ''
file['input'].close()
# ------------------------------------------ output result --------------------------------------- # ------------------------------------------ output result ---------------------------------------
if options.memory: table.output_flush() # just in case of buffered ASCII table
file['output'].write(output)
file['input'].close() # close input ASCII table
if file['name'] != 'STDIN': if file['name'] != 'STDIN':
file['output'].close file['output'].close # close output ASCII table
os.rename(file['name']+'_tmp',file['name']) os.rename(file['name']+'_tmp',file['name']) # overwrite old one with tmp new

View File

@ -1,6 +1,6 @@
#!/usr/bin/python #!/usr/bin/python
import os,re,sys,math,string,damask_tools import os,re,sys,math,string,damask
from optparse import OptionParser, Option from optparse import OptionParser, Option
# ----------------------------- # -----------------------------
@ -79,7 +79,7 @@ else:
for file in files: for file in files:
if file['name'] != 'STDIN': print file['name'] 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.head_read() # read ASCII header info
table.info_append(string.replace('$Id$','\n','\\n') + \ table.info_append(string.replace('$Id$','\n','\\n') + \
'\t' + ' '.join(sys.argv[1:])) '\t' + ' '.join(sys.argv[1:]))

View File

@ -2,10 +2,9 @@
# Makes postprocessing routines acessible from everywhere. # Makes postprocessing routines acessible from everywhere.
import os,sys,glob,string import os,sys,glob,string,damask
from optparse import OptionParser, Option from optparse import OptionParser, Option
import damask_tools
# ----------------------------- # -----------------------------
class extendableOption(Option): class extendableOption(Option):
@ -52,10 +51,9 @@ else:
acml_subdir='%s64/lib'%options.compiler acml_subdir='%s64/lib'%options.compiler
#getting pathinfo damaskEnv = damask.Environment()
damask_variables = damask_tools.DAMASK_TOOLS() baseDir = damaskEnv.relPath('processing/')
baseDir = damask_variables.relPath('processing/') codeDir = damaskEnv.relPath('code/')
codeDir = damask_variables.relPath('code/')
#define ToDo list #define ToDo list
bin_link = { \ bin_link = { \
@ -101,7 +99,7 @@ compile = { \
execute = { \ execute = { \
'postMath' : [ '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 # 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 # 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 # 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) +\ '-c --fcompiler=%s '%(f2py_compiler) +\
'%s ' %(os.path.join(codeDir,'DAMASK2Python_helper.f90'))+\ '%s ' %(os.path.join(codeDir,'DAMASK2Python_helper.f90'))+\
'%s ' %(os.path.join(codeDir,'math.f90'))+\ '%s ' %(os.path.join(codeDir,'math.f90'))+\
'%s ' %(os.path.join(damask_variables.pathInfo['fftw'],'libfftw3.a'))+\ '%s ' %(os.path.join(damaskEnv.pathInfo['fftw'],'libfftw3.a'))+\
'%s' %(os.path.join(damask_variables.pathInfo['acml'],acml_subdir,'libacml.a'), '%s' %(os.path.join(damaskEnv.pathInfo['acml'],acml_subdir,'libacml.a')),
'mv %s %s' %(os.path.join(codeDir,'DAMASK.so'),damask_variables.relPath('lib/')), '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 tasks in execute:
for cmd in execute[tasks]: for cmd in execute[tasks]:
os.system(cmd) os.system(cmd)
os.chdir(damask_variables.relPath('processing/setup/')) os.chdir(damaskEnv.relPath('processing/setup/'))
modules = glob.glob('*.mod') modules = glob.glob('*.mod')
for module in modules: for module in modules:
@ -146,16 +144,11 @@ for dir in bin_link:
for file in bin_link[dir]: for file in bin_link[dir]:
src = os.path.abspath(os.path.join(baseDir,dir,file)) src = os.path.abspath(os.path.join(baseDir,dir,file))
if (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: 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 print sym_link,'-->',src
if os.path.lexists(sym_link): if os.path.lexists(sym_link):
os.remove(sym_link) os.remove(sym_link)
os.symlink(src,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)