#!/usr/bin/env python # -*- coding: UTF-8 no BOM -*- 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='