DAMASK_EICMD/processing/post/addCompatibilityMismatch.py

106 lines
4.4 KiB
Python
Raw Normal View History

#!/usr/bin/env python3
2011-08-25 22:14:36 +05:30
import os
2019-12-21 19:42:01 +05:30
import sys
2019-12-21 22:49:54 +05:30
from io import StringIO
from optparse import OptionParser
import numpy as np
import damask
2011-08-25 22:14:36 +05:30
scriptName = os.path.splitext(os.path.basename(__file__))[0]
scriptID = ' '.join([scriptName,damask.version])
2011-08-25 22:14:36 +05:30
2016-03-24 18:49:00 +05:30
def shapeMismatch(size,F,nodes,centres):
2016-03-24 17:05:33 +05:30
"""
2019-12-21 22:49:54 +05:30
Routine to calculate the shape mismatch.
2020-04-21 01:14:38 +05:30
2016-04-15 04:02:30 +05:30
shape mismatch is defined as difference between the vectors from the central point to
2016-03-24 17:05:33 +05:30
the corners of reconstructed (combatible) volume element and the vectors calculated by deforming
2019-12-21 22:49:54 +05:30
the initial volume element with the current deformation gradient.
2016-03-24 17:05:33 +05:30
"""
2020-04-21 01:14:38 +05:30
sMismatch = np.empty(F.shape[:3])
2016-03-24 18:49:00 +05:30
#--------------------------------------------------------------------------------------------------
# initial positions
2020-04-21 01:44:57 +05:30
delta = size/grid*.5
coordsInitial = np.vstack((delta * np.array((-1,-1,-1)),
delta * np.array((+1,-1,-1)),
delta * np.array((+1,+1,-1)),
delta * np.array((-1,+1,-1)),
delta * np.array((-1,-1,+1)),
delta * np.array((+1,-1,+1)),
delta * np.array((+1,+1,+1)),
delta * np.array((-1,+1,+1))))
2020-04-21 01:14:38 +05:30
2016-03-24 18:49:00 +05:30
#--------------------------------------------------------------------------------------------------
# compare deformed original and deformed positions to actual positions
2020-04-21 01:14:38 +05:30
for k in range(grid[0]):
2016-10-25 00:46:29 +05:30
for j in range(grid[1]):
2020-04-21 01:14:38 +05:30
for i in range(grid[2]):
sMismatch[k,j,i] = \
+ np.linalg.norm(nodes[k, j, i ,0:3] - centres[k,j,i,0:3] - np.dot(F[k,j,i,:,:], coordsInitial[0,0:3]))\
2020-04-21 01:14:38 +05:30
+ np.linalg.norm(nodes[k+1,j, i ,0:3] - centres[k,j,i,0:3] - np.dot(F[k,j,i,:,:], coordsInitial[1,0:3]))\
+ np.linalg.norm(nodes[k+1,j+1,i ,0:3] - centres[k,j,i,0:3] - np.dot(F[k,j,i,:,:], coordsInitial[2,0:3]))\
+ np.linalg.norm(nodes[k, j+1,i ,0:3] - centres[k,j,i,0:3] - np.dot(F[k,j,i,:,:], coordsInitial[3,0:3]))\
2020-04-21 01:14:38 +05:30
+ np.linalg.norm(nodes[k, j, i+1,0:3] - centres[k,j,i,0:3] - np.dot(F[k,j,i,:,:], coordsInitial[4,0:3]))\
+ np.linalg.norm(nodes[k+1,j, i+1,0:3] - centres[k,j,i,0:3] - np.dot(F[k,j,i,:,:], coordsInitial[5,0:3]))\
+ np.linalg.norm(nodes[k+1,j+1,i+1,0:3] - centres[k,j,i,0:3] - np.dot(F[k,j,i,:,:], coordsInitial[6,0:3]))\
2020-04-21 01:14:38 +05:30
+ np.linalg.norm(nodes[k ,j+1,i+1,0:3] - centres[k,j,i,0:3] - np.dot(F[k,j,i,:,:], coordsInitial[7,0:3]))
2016-03-24 18:49:00 +05:30
return sMismatch
2016-03-24 17:05:33 +05:30
2011-08-25 22:14:36 +05:30
# --------------------------------------------------------------------
# MAIN
# --------------------------------------------------------------------
parser = OptionParser(usage='%prog options [ASCIItable(s)]', description = """
Add column(s) containing the shape and volume mismatch resulting from given deformation gradient.
Operates on periodic three-dimensional x,y,z-ordered data sets.
2011-08-25 22:14:36 +05:30
""", version = scriptID)
2011-08-25 22:14:36 +05:30
parser.add_option('-c','--coordinates',
dest = 'pos',
type = 'string', metavar = 'string',
help = 'column heading of coordinates [%default]')
parser.add_option('-f','--defgrad',
dest = 'defgrad',
type = 'string', metavar = 'string ',
help = 'column heading of deformation gradient [%default]')
parser.add_option('--no-shape','-s',
dest = 'shape',
action = 'store_false',
help = 'omit shape mismatch')
parser.set_defaults(pos = 'pos',
defgrad = 'f',
shape = True,
volume = True,
)
2011-08-25 22:14:36 +05:30
(options,filenames) = parser.parse_args()
if filenames == []: filenames = [None]
2019-12-21 19:42:01 +05:30
for name in filenames:
damask.util.report(scriptName,name)
2020-04-21 01:14:38 +05:30
table = damask.Table.load(StringIO(''.join(sys.stdin.read())) if name is None else name)
2020-01-13 07:21:49 +05:30
grid,size,origin = damask.grid_filters.cell_coord0_gridSizeOrigin(table.get(options.pos))
2020-04-21 01:14:38 +05:30
F = table.get(options.defgrad).reshape(tuple(grid)+(-1,),order='F').reshape(tuple(grid)+(3,3))
nodes = damask.grid_filters.node_coord(size,F)
2020-04-21 01:14:38 +05:30
if options.shape:
2020-01-12 01:03:29 +05:30
centers = damask.grid_filters.cell_coord(size,F)
2020-04-21 01:14:38 +05:30
shapeMismatch = shapeMismatch(size,F,nodes,centers)
2020-09-14 10:34:01 +05:30
table = table.add('shapeMismatch(({}))'.format(options.defgrad),
shapeMismatch.reshape(-1,1,order='F'),
scriptID+' '+' '.join(sys.argv[1:]))
2020-04-21 01:14:38 +05:30
2020-11-24 01:24:07 +05:30
table.save((sys.stdout if name is None else name))