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
|
|
|
|
2016-03-01 22:55:14 +05:30
|
|
|
import os,string,h5py
|
2014-01-08 02:12:51 +05:30
|
|
|
import numpy as np
|
2016-03-02 01:14:43 +05:30
|
|
|
from optparse import OptionParser
|
|
|
|
import damask
|
2014-01-08 02:12:51 +05:30
|
|
|
|
|
|
|
# --------------------------------------------------------------------
|
|
|
|
# MAIN
|
|
|
|
# --------------------------------------------------------------------
|
|
|
|
|
2016-03-02 01:14:43 +05:30
|
|
|
parser = OptionParser(option_class=damask.extendableOption, usage='%prog options [file[s]]', description = """
|
2014-01-08 02:12:51 +05:30
|
|
|
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()
|
|
|
|
|
2016-03-02 01:14:43 +05:30
|
|
|
if options.defgrad is None or options.stress is None or options.output is None:
|
2014-01-08 02:12:51 +05:30
|
|
|
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'
|