improved help for automatic documentation and simplified some scripts
This commit is contained in:
parent
88e16f9344
commit
59e546e3d7
|
@ -27,17 +27,17 @@ Example: distance to IP coordinates -- "math.sqrt( #ip.x#**2 + #ip.y#**2 + round
|
|||
""", version = scriptID)
|
||||
|
||||
parser.add_option('-l','--label', dest='labels', action='extend', metavar='<string LIST>',
|
||||
help='(list of) new column labels')
|
||||
help='(list of) new column labels')
|
||||
parser.add_option('-f','--formula', dest='formulas', action='extend', metavar='<string LIST>',
|
||||
help='(list of) formulas corresponding to labels')
|
||||
parser.set_defaults(labels= [])
|
||||
parser.set_defaults(formulas= [])
|
||||
help='(list of) formulas corresponding to labels')
|
||||
|
||||
(options,filenames) = parser.parse_args()
|
||||
|
||||
if len(options.labels) != len(options.formulas):
|
||||
if options.labels == None or options.formulas == None:
|
||||
parser.error('no formulas and/or labels specified')
|
||||
elif len(options.labels) != len(options.formulas):
|
||||
parser.error('number of labels (%i) and formulas (%i) do not match'%(len(options.labels),len(options.formulas)))
|
||||
|
||||
|
||||
for i in xrange(len(options.formulas)):
|
||||
options.formulas[i]=options.formulas[i].replace(';',',')
|
||||
|
||||
|
@ -104,8 +104,8 @@ for file in files:
|
|||
if labelLen[label] == 0:
|
||||
brokenFormula[label] = True
|
||||
if label not in brokenFormula:
|
||||
table.labels_append({True:['%i_%s'%(i+1,label) for i in xrange(labelLen[label])],
|
||||
False:label}[labelLen[label]>1] )
|
||||
table.labels_append(['%i_%s'%(i+1,label) for i in xrange(labelLen[label])] if labelLen[label]>1
|
||||
else label)
|
||||
table.head_write()
|
||||
firstLine = False
|
||||
|
||||
|
|
|
@ -3,7 +3,6 @@
|
|||
|
||||
import os,sys,string
|
||||
import numpy as np
|
||||
from collections import defaultdict
|
||||
from optparse import OptionParser
|
||||
import damask
|
||||
|
||||
|
@ -20,24 +19,14 @@ Add column(s) containing Cauchy stress based on given column(s) of deformation g
|
|||
""", version = scriptID)
|
||||
|
||||
parser.add_option('-f','--defgrad', dest='defgrad', metavar='string',
|
||||
help='heading of columns containing deformation gradient [%default]')
|
||||
help='heading of columns containing deformation gradient [%default]')
|
||||
parser.add_option('-p','--stress', dest='stress', metavar='string',
|
||||
help='heading of columns containing first Piola--Kirchhoff stress [%default]')
|
||||
help='heading of columns containing first Piola--Kirchhoff stress [%default]')
|
||||
parser.set_defaults(defgrad = 'f')
|
||||
parser.set_defaults(stress = 'p')
|
||||
parser.set_defaults(stress = 'p')
|
||||
|
||||
(options,filenames) = parser.parse_args()
|
||||
|
||||
datainfo = { # list of requested labels per datatype
|
||||
'defgrad': {'len':9,
|
||||
'label':[]},
|
||||
'stress': {'len':9,
|
||||
'label':[]},
|
||||
}
|
||||
|
||||
datainfo['defgrad']['label'].append(options.defgrad)
|
||||
datainfo['stress']['label'].append(options.stress)
|
||||
|
||||
# ------------------------------------------ setup file handles ------------------------------------
|
||||
files = []
|
||||
if filenames == []:
|
||||
|
@ -57,36 +46,24 @@ for file in files:
|
|||
table.info_append(scriptID + '\t' + ' '.join(sys.argv[1:]))
|
||||
|
||||
# --------------- figure out columns to process ---------------------------------------------------
|
||||
active = defaultdict(list)
|
||||
column = defaultdict(dict)
|
||||
missingColumns = False
|
||||
|
||||
for datatype,info in datainfo.items():
|
||||
for label in info['label']:
|
||||
key = '1_%s'%label
|
||||
if key not in table.labels:
|
||||
file['croak'].write('column %s not found...\n'%key)
|
||||
missingColumns = True # break if label not found
|
||||
else:
|
||||
active[datatype].append(label)
|
||||
column[datatype][label] = table.labels.index(key) # remember columns of requested data
|
||||
column={ 'defgrad': table.labels.index('1_'+options.defgrad),
|
||||
'stress': table.labels.index('1_'+options.stress)}
|
||||
for key in column:
|
||||
if column[key]<1:
|
||||
file['croak'].write('column %s not found...\n'%key)
|
||||
missingColumns=True
|
||||
if missingColumns: continue
|
||||
|
||||
if missingColumns:
|
||||
continue
|
||||
|
||||
# ------------------------------------------ assemble header --------------------------------------
|
||||
# ------------------------------------------ assemble header --------------------------------------
|
||||
table.labels_append(['%i_Cauchy'%(i+1) for i in xrange(9)]) # extend ASCII header with new labels
|
||||
table.head_write()
|
||||
|
||||
# ------------------------------------------ process data ------------------------------------------
|
||||
outputAlive = True
|
||||
while outputAlive and table.data_read(): # read next data line of ASCII table
|
||||
F = np.array(map(float,table.data[column['defgrad'][active['defgrad'][0]]:
|
||||
column['defgrad'][active['defgrad'][0]]+datainfo['defgrad']['len']]),\
|
||||
'd').reshape(3,3)
|
||||
P = np.array(map(float,table.data[column['stress'][active['stress'][0]]:
|
||||
column['stress'][active['stress'][0]]+datainfo['stress']['len']]),\
|
||||
'd').reshape(3,3)
|
||||
F = np.array(map(float,table.data[column['defgrad']:column['defgrad']+9]),'d').reshape(3,3)
|
||||
P = np.array(map(float,table.data[column['stress'] :column['stress']+9]),'d').reshape(3,3)
|
||||
table.data_append(list(1.0/np.linalg.det(F)*np.dot(P,F.T).reshape(9))) # [Cauchy] = (1/det(F)) * [P].[F_transpose]
|
||||
outputAlive = table.data_write() # output processed line
|
||||
|
||||
|
|
|
@ -21,9 +21,9 @@ Operates on periodic ordered three-dimensional data sets.
|
|||
""", version = scriptID)
|
||||
|
||||
parser.add_option('-c','--coordinates', dest='coords', metavar='string',
|
||||
help='column heading for coordinates [%default]')
|
||||
help='column heading for coordinates [%default]')
|
||||
parser.add_option('-f','--defgrad', dest='defgrad', metavar='string',
|
||||
help='heading of columns containing tensor field values')
|
||||
help='heading of columns containing tensor field values [%default]')
|
||||
parser.set_defaults(coords = 'ipinitialcoord')
|
||||
parser.set_defaults(defgrad = 'f' )
|
||||
|
||||
|
|
|
@ -27,12 +27,11 @@ Add column(s) containing determinant of requested tensor column(s).
|
|||
""", version = scriptID)
|
||||
|
||||
parser.add_option('-t','--tensor', dest='tensor', action='extend', metavar='<string LIST>',
|
||||
help='heading of columns containing tensor field values')
|
||||
parser.set_defaults(tensor = [])
|
||||
help='heading of columns containing tensor field values')
|
||||
|
||||
(options,filenames) = parser.parse_args()
|
||||
|
||||
if len(options.tensor) == 0:
|
||||
if options.tensor == None:
|
||||
parser.error('no data column specified...')
|
||||
|
||||
datainfo = { # list of requested labels per datatype
|
||||
|
@ -60,10 +59,9 @@ for file in files:
|
|||
table.head_read() # read ASCII header info
|
||||
table.info_append(scriptID + '\t' + ' '.join(sys.argv[1:]))
|
||||
|
||||
# --------------- figure out columns to process ---------------------------------------------------
|
||||
active = []
|
||||
column = defaultdict(dict)
|
||||
|
||||
# --------------- figure out columns to process ---------------------------------------------------
|
||||
for label in datainfo['tensor']['label']:
|
||||
key = '1_%s'%label
|
||||
if key not in table.labels:
|
||||
|
|
|
@ -27,15 +27,13 @@ Add column(s) containing deviator of requested tensor column(s).
|
|||
""", version = scriptID)
|
||||
|
||||
parser.add_option('-t','--tensor', dest='tensor', action='extend', metavar='<string LIST>',
|
||||
help='heading of columns containing tensor field values')
|
||||
help='heading of columns containing tensor field values')
|
||||
parser.add_option('-s','--spherical', dest='hydrostatic', action='store_true',
|
||||
help='also add sperical part of tensor (hydrostatic component, pressure)')
|
||||
parser.set_defaults(hydrostatic = False)
|
||||
parser.set_defaults(tensor = [])
|
||||
help='also add sperical part of tensor (hydrostatic component, pressure)')
|
||||
|
||||
(options,filenames) = parser.parse_args()
|
||||
|
||||
if len(options.tensor) == 0:
|
||||
if options.tensor == None:
|
||||
parser.error('no data column specified...')
|
||||
|
||||
datainfo = { # list of requested labels per datatype
|
||||
|
|
|
@ -10,11 +10,6 @@ import damask
|
|||
scriptID = string.replace('$Id$','\n','\\n')
|
||||
scriptName = os.path.splitext(scriptID.split()[1])[0]
|
||||
|
||||
#--------------------------------------------------------------------------------------------------
|
||||
#> @brief calculates curl field using differentation in Fourier space
|
||||
#> @todo enable odd resolution
|
||||
#--------------------------------------------------------------------------------------------------
|
||||
|
||||
def divFFT(geomdim,field):
|
||||
grid = np.array(np.shape(field)[0:3])
|
||||
wgt = 1.0/np.array(grid).prod()
|
||||
|
@ -67,18 +62,16 @@ Deals with both vector- and tensor-valued fields.
|
|||
""", version = scriptID)
|
||||
|
||||
parser.add_option('-c','--coordinates', dest='coords', metavar='string',
|
||||
help='column heading for coordinates [%default]')
|
||||
help='column heading for coordinates [%default]')
|
||||
parser.add_option('-v','--vector', dest='vector', action='extend', metavar='<string LIST>',
|
||||
help='heading of columns containing vector field values')
|
||||
help='heading of columns containing vector field values')
|
||||
parser.add_option('-t','--tensor', dest='tensor', action='extend', metavar='<string LIST>',
|
||||
help='heading of columns containing tensor field values')
|
||||
help='heading of columns containing tensor field values')
|
||||
parser.set_defaults(coords = 'ipinitialcoord')
|
||||
parser.set_defaults(vector = [])
|
||||
parser.set_defaults(tensor = [])
|
||||
|
||||
(options,filenames) = parser.parse_args()
|
||||
|
||||
if len(options.vector) + len(options.tensor) == 0:
|
||||
if (options.vector == None) and (options.tensor == None):
|
||||
parser.error('no data column specified...')
|
||||
|
||||
datainfo = { # list of requested labels per datatype
|
||||
|
|
Loading…
Reference in New Issue