simplified option parsing (so far, only for addCalculation and addMises)
This commit is contained in:
parent
3533138936
commit
51b92f3ef9
|
@ -13,6 +13,7 @@ from .result import Result # only one class
|
|||
from .geometry import Geometry # one class with subclasses
|
||||
from .solver import Solver # one class with subclasses
|
||||
from .test import Test
|
||||
from .util import extendableOption
|
||||
|
||||
try:
|
||||
from . import core
|
||||
|
|
|
@ -1,7 +1,9 @@
|
|||
# -*- coding: UTF-8 no BOM -*-
|
||||
|
||||
# damask utility functions
|
||||
import math
|
||||
import math
|
||||
from optparse import OptionParser, Option
|
||||
|
||||
try:
|
||||
import numpy
|
||||
except:
|
||||
|
@ -16,3 +18,21 @@ for f in ['cos', 'sin', 'tan']:
|
|||
exec('def %sd(deg): return (math.%s(deg/180.*math.pi))'%(f,f))
|
||||
exec('def a%sd(val): return (math.a%s(val)*180./math.pi)'%(f,f))
|
||||
|
||||
# -----------------------------
|
||||
class extendableOption(Option):
|
||||
# -----------------------------
|
||||
# used for definition of new option parser action 'extend', which enables to take multiple option arguments
|
||||
# taken from online tutorial http://docs.python.org/library/optparse.html
|
||||
|
||||
ACTIONS = Option.ACTIONS + ("extend",)
|
||||
STORE_ACTIONS = Option.STORE_ACTIONS + ("extend",)
|
||||
TYPED_ACTIONS = Option.TYPED_ACTIONS + ("extend",)
|
||||
ALWAYS_TYPED_ACTIONS = Option.ALWAYS_TYPED_ACTIONS + ("extend",)
|
||||
|
||||
def take_action(self, action, dest, opt, value, values, parser):
|
||||
if action == "extend":
|
||||
lvalue = value.split(",")
|
||||
values.ensure_value(dest, []).extend(lvalue)
|
||||
else:
|
||||
Option.take_action(self, action, dest, opt, value, values, parser)
|
||||
|
||||
|
|
|
@ -1,8 +1,10 @@
|
|||
#!/usr/bin/env python
|
||||
# -*- coding: UTF-8 no BOM -*-
|
||||
|
||||
import os,re,sys,math,string,damask,numpy
|
||||
from optparse import OptionParser, Option
|
||||
import os,re,sys,math,string
|
||||
import numpy as np
|
||||
from optparse import OptionParser
|
||||
import damask
|
||||
|
||||
scriptID = '$Id$'
|
||||
scriptName = scriptID.split()[1]
|
||||
|
@ -11,31 +13,11 @@ def unravel(item):
|
|||
if hasattr(item,'__contains__'): return ' '.join(map(unravel,item))
|
||||
else: return str(item)
|
||||
|
||||
# -----------------------------
|
||||
class extendableOption(Option):
|
||||
# -----------------------------
|
||||
# used for definition of new option parser action 'extend', which enables to take multiple option arguments
|
||||
# taken from online tutorial http://docs.python.org/library/optparse.html
|
||||
|
||||
ACTIONS = Option.ACTIONS + ("extend",)
|
||||
STORE_ACTIONS = Option.STORE_ACTIONS + ("extend",)
|
||||
TYPED_ACTIONS = Option.TYPED_ACTIONS + ("extend",)
|
||||
ALWAYS_TYPED_ACTIONS = Option.ALWAYS_TYPED_ACTIONS + ("extend",)
|
||||
|
||||
def take_action(self, action, dest, opt, value, values, parser):
|
||||
if action == "extend":
|
||||
lvalue = value.split(",")
|
||||
values.ensure_value(dest, []).extend(lvalue)
|
||||
else:
|
||||
Option.take_action(self, action, dest, opt, value, values, parser)
|
||||
|
||||
|
||||
|
||||
# --------------------------------------------------------------------
|
||||
# MAIN
|
||||
# --------------------------------------------------------------------
|
||||
|
||||
parser = OptionParser(option_class=extendableOption, usage='%prog options [file[s]]', description = """
|
||||
parser = OptionParser(option_class=damask.extendableOption, usage='%prog options [file[s]]', description = """
|
||||
Add column(s) with derived values according to user defined arithmetic operation between column(s).
|
||||
Columns can be specified either by label or index. Use ';' for ',' in functions.
|
||||
|
||||
|
@ -113,7 +95,7 @@ for file in files:
|
|||
table.data_read()
|
||||
labelLen = {}
|
||||
for label in options.labels:
|
||||
labelLen[label] = numpy.size(eval(eval(evaluator[label])))
|
||||
labelLen[label] = np.size(eval(eval(evaluator[label])))
|
||||
|
||||
# ------------------------------------------ assemble header ---------------------------------------
|
||||
for label,formula in zip(options.labels,options.formulas):
|
||||
|
|
|
@ -1,37 +1,19 @@
|
|||
#!/usr/bin/env python
|
||||
# -*- coding: UTF-8 no BOM -*-
|
||||
|
||||
import os,re,sys,math,numpy,string,damask
|
||||
from optparse import OptionParser, Option
|
||||
import os,re,sys,math,string
|
||||
import numpy as np
|
||||
from optparse import OptionParser
|
||||
import damask
|
||||
|
||||
scriptID = '$Id$'
|
||||
scriptName = scriptID.split()[1]
|
||||
|
||||
# -----------------------------
|
||||
class extendableOption(Option):
|
||||
# -----------------------------
|
||||
# used for definition of new option parser action 'extend', which enables to take multiple option arguments
|
||||
# taken from online tutorial http://docs.python.org/library/optparse.html
|
||||
|
||||
ACTIONS = Option.ACTIONS + ("extend",)
|
||||
STORE_ACTIONS = Option.STORE_ACTIONS + ("extend",)
|
||||
TYPED_ACTIONS = Option.TYPED_ACTIONS + ("extend",)
|
||||
ALWAYS_TYPED_ACTIONS = Option.ALWAYS_TYPED_ACTIONS + ("extend",)
|
||||
|
||||
def take_action(self, action, dest, opt, value, values, parser):
|
||||
if action == "extend":
|
||||
lvalue = value.split(",")
|
||||
values.ensure_value(dest, []).extend(lvalue)
|
||||
else:
|
||||
Option.take_action(self, action, dest, opt, value, values, parser)
|
||||
|
||||
|
||||
|
||||
def Mises(what,tensor):
|
||||
|
||||
dev = tensor - numpy.trace(tensor)/3.0*numpy.eye(3)
|
||||
dev = tensor - np.trace(tensor)/3.0*np.eye(3)
|
||||
symdev = 0.5*(dev+dev.T)
|
||||
return math.sqrt(numpy.sum(symdev*symdev.T)*
|
||||
return math.sqrt(np.sum(symdev*symdev.T)*
|
||||
{
|
||||
'stress': 3.0/2.0,
|
||||
'strain': 2.0/3.0,
|
||||
|
@ -41,7 +23,7 @@ def Mises(what,tensor):
|
|||
# MAIN
|
||||
# --------------------------------------------------------------------
|
||||
|
||||
parser = OptionParser(option_class=extendableOption, usage='%prog options [file[s]]', description = """
|
||||
parser = OptionParser(option_class=damask.extendableOption, usage='%prog options [file[s]]', description = """
|
||||
Add vonMises equivalent values for symmetric part of requested strains and/or stresses.
|
||||
|
||||
""" + string.replace(scriptID,'\n','\\n')
|
||||
|
@ -120,7 +102,7 @@ for file in files:
|
|||
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,table.data[column[datatype][label]:
|
||||
np.array(map(float,table.data[column[datatype][label]:
|
||||
column[datatype][label]+datainfo[datatype]['len']]),'d').reshape(3,3)))
|
||||
|
||||
table.data_write() # output processed line
|
||||
|
|
Loading…
Reference in New Issue