From 7d96bb7ce8d9e4096ce7ff6ac6d8179f26bc6f4c Mon Sep 17 00:00:00 2001 From: Philip Eisenlohr Date: Mon, 3 Dec 2012 13:10:16 +0000 Subject: [PATCH] Add column(s) containing directional stiffness based on given cubic stiffness values C11, C12, and C44 (in consecutive columns) --- processing/post/addEhkl.py | 141 +++++++++++++++++++++++++++ processing/setup/setup_processing.py | 3 +- 2 files changed, 143 insertions(+), 1 deletion(-) create mode 100755 processing/post/addEhkl.py diff --git a/processing/post/addEhkl.py b/processing/post/addEhkl.py new file mode 100755 index 000000000..fc7c8fe38 --- /dev/null +++ b/processing/post/addEhkl.py @@ -0,0 +1,141 @@ +#!/usr/bin/env python + +import os,re,sys,math,numpy,string,damask +from optparse import OptionParser, Option + +# ----------------------------- +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 normalize(vec): + return vec/numpy.sqrt(numpy.inner(vec,vec)) + +def E_hkl(stiffness,vec): # stiffness = (c11,c12,c44) + v = normalize(vec) + S11 = (stiffness[0]+stiffness[1])/(stiffness[0]*stiffness[0]+stiffness[0]*stiffness[1]-2.0*stiffness[1]*stiffness[1]) + S12 = ( -stiffness[1])/(stiffness[0]*stiffness[0]+stiffness[0]*stiffness[1]-2.0*stiffness[1]*stiffness[1]) + S44 = 1.0/stiffness[2] + + invE = S11-(S11-S12-0.5*S44)* (1.0 - \ + (v[0]**4+v[1]**4+v[2]**4) \ + /#------------------------------------ + numpy.inner(v,v)**2 \ + ) + + return 1.0/invE + +# -------------------------------------------------------------------- +# MAIN +# -------------------------------------------------------------------- + +parser = OptionParser(option_class=extendableOption, usage='%prog options [file[s]]', description = """ +Add column(s) containing directional stiffness +based on given cubic stiffness values C11, C12, and C44 in consecutive columns. + +""" + string.replace('$Id$','\n','\\n') +) + +parser.add_option('-c','--stiffness', dest='vector', action='extend', type='string', \ + help='heading of column containing C11 (followed by C12, C44) field values', \ + metavar='