2018-11-17 12:42:12 +05:30
|
|
|
#!/usr/bin/env python3
|
2011-08-25 22:14:36 +05:30
|
|
|
|
2016-06-29 23:39:42 +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
|
2019-06-14 16:33:30 +05:30
|
|
|
from optparse import OptionParser
|
|
|
|
|
2016-06-29 23:39:42 +05:30
|
|
|
import numpy as np
|
2019-06-14 16:33:30 +05:30
|
|
|
|
2014-07-10 14:57:51 +05:30
|
|
|
import damask
|
2011-08-25 22:14:36 +05:30
|
|
|
|
2019-06-14 16:33:30 +05:30
|
|
|
|
2016-01-27 22:36:00 +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:44:57 +05:30
|
|
|
delta = size/grid*.5
|
2020-04-21 01:14:38 +05:30
|
|
|
|
2020-11-24 01:53:45 +05:30
|
|
|
return + np.linalg.norm(nodes[:-1,:-1,:-1] -centres - np.dot(F,delta * np.array((-1,-1,-1))),axis=-1)\
|
|
|
|
+ np.linalg.norm(nodes[+1:,:-1,:-1] -centres - np.dot(F,delta * np.array((+1,-1,-1))),axis=-1)\
|
|
|
|
+ np.linalg.norm(nodes[+1:,+1:,:-1] -centres - np.dot(F,delta * np.array((+1,+1,-1))),axis=-1)\
|
|
|
|
+ np.linalg.norm(nodes[:-1,+1:,:-1] -centres - np.dot(F,delta * np.array((-1,+1,-1))),axis=-1)\
|
|
|
|
+ np.linalg.norm(nodes[:-1,:-1,+1:] -centres - np.dot(F,delta * np.array((-1,-1,+1))),axis=-1)\
|
|
|
|
+ np.linalg.norm(nodes[+1:,:-1,+1:] -centres - np.dot(F,delta * np.array((+1,-1,+1))),axis=-1)\
|
|
|
|
+ np.linalg.norm(nodes[+1:,+1:,+1:] -centres - np.dot(F,delta * np.array((+1,+1,+1))),axis=-1)\
|
|
|
|
+ np.linalg.norm(nodes[:-1,+1:,+1:] -centres - np.dot(F,delta * np.array((-1,+1,+1))),axis=-1)
|
2016-03-24 18:49:00 +05:30
|
|
|
|
2016-03-24 17:05:33 +05:30
|
|
|
|
2011-08-25 22:14:36 +05:30
|
|
|
# --------------------------------------------------------------------
|
|
|
|
# MAIN
|
|
|
|
# --------------------------------------------------------------------
|
|
|
|
|
2020-11-14 23:30:51 +05:30
|
|
|
parser = OptionParser(usage='%prog options [ASCIItable(s)]', description = """
|
2015-08-08 00:33:26 +05:30
|
|
|
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
|
|
|
|
2014-08-06 18:57:09 +05:30
|
|
|
""", version = scriptID)
|
|
|
|
|
2011-08-25 22:14:36 +05:30
|
|
|
|
2015-08-08 00:33:26 +05:30
|
|
|
parser.add_option('-c','--coordinates',
|
2016-04-27 02:19:58 +05:30
|
|
|
dest = 'pos',
|
2015-08-08 00:33:26 +05:30
|
|
|
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')
|
2016-04-27 02:19:58 +05:30
|
|
|
parser.set_defaults(pos = 'pos',
|
|
|
|
defgrad = 'f',
|
|
|
|
shape = True,
|
|
|
|
volume = True,
|
2015-08-08 00:33:26 +05:30
|
|
|
)
|
2011-08-25 22:14:36 +05:30
|
|
|
|
|
|
|
(options,filenames) = parser.parse_args()
|
2015-08-21 01:12:05 +05:30
|
|
|
if filenames == []: filenames = [None]
|
2015-08-08 00:33:26 +05:30
|
|
|
|
2019-12-21 19:42:01 +05:30
|
|
|
|
2014-07-22 01:25:05 +05:30
|
|
|
for name in filenames:
|
2015-09-24 14:54:42 +05:30
|
|
|
damask.util.report(scriptName,name)
|
2020-04-21 01:14:38 +05:30
|
|
|
|
2020-09-21 00:15:06 +05:30
|
|
|
table = damask.Table.load(StringIO(''.join(sys.stdin.read())) if name is None else name)
|
2020-12-04 03:30:49 +05:30
|
|
|
grid,size,origin = damask.grid_filters.cellSizeOrigin_coordinates0_point(table.get(options.pos))
|
2016-06-27 23:08:12 +05:30
|
|
|
|
2020-04-21 01:14:38 +05:30
|
|
|
F = table.get(options.defgrad).reshape(tuple(grid)+(-1,),order='F').reshape(tuple(grid)+(3,3))
|
2020-12-04 03:30:49 +05:30
|
|
|
nodes = damask.grid_filters.coordinates_node(size,F)
|
2020-04-21 01:14:38 +05:30
|
|
|
|
2016-06-27 23:08:12 +05:30
|
|
|
if options.shape:
|
2020-12-04 03:30:49 +05:30
|
|
|
centers = damask.grid_filters.coordinates_point(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))
|