2012-02-07 18:39:10 +05:30
|
|
|
#!/usr/bin/env python
|
2014-04-02 00:11:14 +05:30
|
|
|
# -*- coding: UTF-8 no BOM -*-
|
2011-08-25 22:14:36 +05:30
|
|
|
|
2016-03-01 22:55:14 +05:30
|
|
|
import os,sys
|
2014-07-10 14:57:51 +05:30
|
|
|
import numpy as np
|
|
|
|
from optparse import OptionParser
|
|
|
|
import damask
|
2011-08-25 22:14:36 +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
|
|
|
|
|
|
|
# --------------------------------------------------------------------
|
|
|
|
# MAIN
|
|
|
|
# --------------------------------------------------------------------
|
|
|
|
|
2014-07-10 14:57:51 +05:30
|
|
|
parser = OptionParser(option_class=damask.extendableOption, usage='%prog options file[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')
|
|
|
|
parser.add_option('--no-volume','-v',
|
|
|
|
dest = 'volume',
|
|
|
|
action = 'store_false',
|
|
|
|
help = 'omit volume 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-08 00:33:26 +05:30
|
|
|
# --- loop over input files -------------------------------------------------------------------------
|
|
|
|
|
2015-08-21 01:12:05 +05:30
|
|
|
if filenames == []: filenames = [None]
|
2015-08-08 00:33:26 +05:30
|
|
|
|
2014-07-22 01:25:05 +05:30
|
|
|
for name in filenames:
|
2015-08-21 01:12:05 +05:30
|
|
|
try:
|
|
|
|
table = damask.ASCIItable(name = name,
|
|
|
|
buffered = False)
|
|
|
|
except: continue
|
2015-09-24 14:54:42 +05:30
|
|
|
damask.util.report(scriptName,name)
|
2015-08-08 00:33:26 +05:30
|
|
|
|
|
|
|
# ------------------------------------------ read header ------------------------------------------
|
|
|
|
|
|
|
|
table.head_read()
|
|
|
|
|
|
|
|
# ------------------------------------------ sanity checks ----------------------------------------
|
|
|
|
|
|
|
|
errors = []
|
|
|
|
remarks = []
|
|
|
|
|
2016-04-27 02:19:58 +05:30
|
|
|
if table.label_dimension(options.pos) != 3: errors.append('coordinates {} are not a vector.'.format(options.pos))
|
|
|
|
else: colCoord = table.label_index(options.pos)
|
2011-08-25 22:14:36 +05:30
|
|
|
|
2015-08-08 00:33:26 +05:30
|
|
|
if table.label_dimension(options.defgrad) != 9: errors.append('deformation gradient {} is not a tensor.'.format(options.defgrad))
|
|
|
|
else: colF = table.label_index(options.defgrad)
|
|
|
|
|
2015-09-24 14:54:42 +05:30
|
|
|
if remarks != []: damask.util.croak(remarks)
|
2015-08-08 00:33:26 +05:30
|
|
|
if errors != []:
|
2015-09-24 14:54:42 +05:30
|
|
|
damask.util.croak(errors)
|
2015-08-08 00:33:26 +05:30
|
|
|
table.close(dismiss = True)
|
|
|
|
continue
|
|
|
|
|
|
|
|
# ------------------------------------------ assemble header --------------------------------------
|
2012-04-18 15:28:59 +05:30
|
|
|
|
2014-08-06 18:57:09 +05:30
|
|
|
table.info_append(scriptID + '\t' + ' '.join(sys.argv[1:]))
|
2015-08-08 00:33:26 +05:30
|
|
|
if options.shape: table.labels_append('shapeMismatch({})'.format(options.defgrad))
|
|
|
|
if options.volume: table.labels_append('volMismatch({})'.format(options.defgrad))
|
2012-04-18 15:28:59 +05:30
|
|
|
|
2014-08-06 20:55:18 +05:30
|
|
|
# --------------- figure out size and grid ---------------------------------------------------------
|
2015-08-08 00:33:26 +05:30
|
|
|
|
|
|
|
table.data_readArray()
|
2014-07-10 14:57:51 +05:30
|
|
|
|
2015-08-21 01:12:05 +05:30
|
|
|
coords = [np.unique(table.data[:,colCoord+i]) for i in xrange(3)]
|
|
|
|
mincorner = np.array(map(min,coords))
|
|
|
|
maxcorner = np.array(map(max,coords))
|
|
|
|
grid = np.array(map(len,coords),'i')
|
|
|
|
size = grid/np.maximum(np.ones(3,'d'), grid-1.0) * (maxcorner-mincorner) # size from edge to edge = dim * n/(n-1)
|
2016-03-02 01:14:43 +05:30
|
|
|
size = np.where(grid > 1, size, min(size[grid > 1]/grid[grid > 1])) # spacing for grid==1 set to smallest among other spacings
|
2011-08-25 22:14:36 +05:30
|
|
|
|
2015-08-08 00:33:26 +05:30
|
|
|
N = grid.prod()
|
2011-08-25 23:25:36 +05:30
|
|
|
|
2015-09-01 02:52:44 +05:30
|
|
|
# --------------- figure out columns to process ---------------------------------------------------
|
|
|
|
key = '1_%s'%options.defgrad
|
|
|
|
if key not in table.labels:
|
|
|
|
file['croak'].write('column %s not found...\n'%key)
|
|
|
|
continue
|
|
|
|
else:
|
|
|
|
column = table.labels.index(key) # remember columns of requested data
|
2015-08-08 00:33:26 +05:30
|
|
|
|
2015-09-01 02:52:44 +05:30
|
|
|
# ------------------------------------------ assemble header ---------------------------------------
|
|
|
|
if options.shape: table.labels_append(['shapeMismatch(%s)' %options.defgrad])
|
|
|
|
if options.volume: table.labels_append(['volMismatch(%s)'%options.defgrad])
|
|
|
|
table.head_write()
|
2015-08-08 00:33:26 +05:30
|
|
|
|
2015-09-01 02:52:44 +05:30
|
|
|
# ------------------------------------------ read deformation gradient field -----------------------
|
|
|
|
table.data_rewind()
|
|
|
|
F = np.zeros(N*9,'d').reshape([3,3]+list(grid))
|
|
|
|
idx = 0
|
|
|
|
while table.data_read():
|
|
|
|
(x,y,z) = damask.util.gridLocation(idx,grid) # figure out (x,y,z) position from line count
|
|
|
|
idx += 1
|
2016-03-03 15:13:43 +05:30
|
|
|
F[0:3,0:3,x,y,z] = np.array(map(float,table.data[column:column+9]),'d').reshape(3,3)
|
|
|
|
|
2015-09-01 02:52:44 +05:30
|
|
|
Favg = damask.core.math.tensorAvg(F)
|
|
|
|
centres = damask.core.mesh.deformedCoordsFFT(size,F,Favg,[1.0,1.0,1.0])
|
2015-08-31 16:30:45 +05:30
|
|
|
|
2015-09-01 02:52:44 +05:30
|
|
|
nodes = damask.core.mesh.nodesAroundCentres(size,Favg,centres)
|
|
|
|
if options.shape: shapeMismatch = damask.core.mesh.shapeMismatch( size,F,nodes,centres)
|
|
|
|
if options.volume: volumeMismatch = damask.core.mesh.volumeMismatch(size,F,nodes)
|
|
|
|
|
|
|
|
# ------------------------------------------ process data ------------------------------------------
|
|
|
|
table.data_rewind()
|
|
|
|
idx = 0
|
|
|
|
outputAlive = True
|
|
|
|
while outputAlive and table.data_read(): # read next data line of ASCII table
|
|
|
|
(x,y,z) = damask.util.gridLocation(idx,grid) # figure out (x,y,z) position from line count
|
|
|
|
idx += 1
|
|
|
|
if options.shape: table.data_append( shapeMismatch[x,y,z])
|
|
|
|
if options.volume: table.data_append(volumeMismatch[x,y,z])
|
|
|
|
outputAlive = table.data_write()
|
2015-08-08 00:33:26 +05:30
|
|
|
|
|
|
|
# ------------------------------------------ output finalization -----------------------------------
|
|
|
|
|
2016-03-03 15:13:43 +05:30
|
|
|
table.close() # close ASCII tables
|