2014-01-08 02:12:51 +05:30
|
|
|
#!/usr/bin/env python
|
2014-04-02 00:11:14 +05:30
|
|
|
# -*- coding: UTF-8 no BOM -*-
|
2014-01-08 02:12:51 +05:30
|
|
|
|
|
|
|
import os,re,sys,math,string,h5py
|
|
|
|
import numpy as np
|
|
|
|
import 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)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# --------------------------------------------------------------------
|
|
|
|
# MAIN
|
|
|
|
# --------------------------------------------------------------------
|
|
|
|
|
|
|
|
parser = OptionParser(option_class=extendableOption, usage='%prog options [file[s]]', description = """
|
|
|
|
Add column(s) containing Cauchy stress based on given column(s) of
|
|
|
|
deformation gradient and first Piola--Kirchhoff stress.
|
|
|
|
|
|
|
|
""" + string.replace('$Id$','\n','\\n')
|
|
|
|
)
|
|
|
|
|
|
|
|
|
2014-09-12 19:44:55 +05:30
|
|
|
parser.add_option('-f','--defgrad', dest='defgrad', \
|
2014-01-08 02:12:51 +05:30
|
|
|
help='heading of columns containing deformation gradient [%default]')
|
2014-09-12 19:44:55 +05:30
|
|
|
parser.add_option('-p','--stress', dest='stress', \
|
2014-01-08 02:12:51 +05:30
|
|
|
help='heading of columns containing first Piola--Kirchhoff stress [%default]')
|
2014-09-12 19:44:55 +05:30
|
|
|
parser.add_option('-o','--output', dest='output', \
|
2014-01-08 02:12:51 +05:30
|
|
|
help='group containing requested data [%default]')
|
|
|
|
parser.set_defaults(defgrad = 'f')
|
|
|
|
parser.set_defaults(stress = 'p')
|
|
|
|
parser.set_defaults(output = 'crystallite')
|
|
|
|
|
|
|
|
(options,filenames) = parser.parse_args()
|
|
|
|
|
|
|
|
if options.defgrad == None or options.stress == None or options.output == None:
|
|
|
|
parser.error('missing data column...')
|
|
|
|
|
|
|
|
|
|
|
|
# ------------------------------------------ setup file handles ---------------------------------------
|
|
|
|
|
|
|
|
files = []
|
|
|
|
for name in filenames:
|
|
|
|
if os.path.exists(name):
|
|
|
|
files.append({'name':name, 'file':h5py.File(name,"a")})
|
|
|
|
|
|
|
|
# ------------------------------------------ loop over input files ------------------------------------
|
|
|
|
|
|
|
|
for myFile in files:
|
|
|
|
print(myFile['name'])
|
|
|
|
|
2014-01-13 21:52:01 +05:30
|
|
|
# ------------------------------------------ loop over increments -------------------------------------
|
|
|
|
for inc in myFile['file']['increments'].keys():
|
|
|
|
print("Current Increment: "+inc)
|
2014-01-28 13:04:13 +05:30
|
|
|
for instance in myFile['file']['increments/'+inc+'/'+options.output].keys():
|
|
|
|
dsets = myFile['file']['increments/'+inc+'/'+options.output+'/'+instance].keys()
|
2014-01-08 02:12:51 +05:30
|
|
|
if (options.defgrad in dsets and options.stress in dsets):
|
2014-01-28 13:04:13 +05:30
|
|
|
defgrad = myFile['file']['increments/'+inc+'/'+options.output+'/'+instance+'/'+options.defgrad]
|
|
|
|
stress = myFile['file']['increments/'+inc+'/'+options.output+'/'+instance+'/'+options.stress]
|
2014-01-08 02:12:51 +05:30
|
|
|
cauchy=np.zeros(np.shape(stress),'f')
|
|
|
|
for p in range(stress.shape[0]):
|
|
|
|
cauchy[p,...] = 1.0/np.linalg.det(defgrad[p,...])*np.dot(stress[p,...],defgrad[p,...].T) # [Cauchy] = (1/det(F)) * [P].[F_transpose]
|
2014-01-28 13:04:13 +05:30
|
|
|
cauchyFile = myFile['file']['increments/'+inc+'/'+options.output+'/'+instance].create_dataset('cauchy', data=cauchy)
|
2014-01-13 21:52:01 +05:30
|
|
|
cauchyFile.attrs['units'] = 'Pa'
|
2014-01-08 02:12:51 +05:30
|
|
|
|
|
|
|
|
|
|
|
|