2012-04-18 15:28:59 +05:30
|
|
|
#!/usr/bin/env python
|
2014-04-02 00:11:14 +05:30
|
|
|
# -*- coding: UTF-8 no BOM -*-
|
2012-04-18 15:28:59 +05:30
|
|
|
|
2014-08-06 20:55:18 +05:30
|
|
|
import os,sys,string
|
2014-07-22 01:25:05 +05:30
|
|
|
import numpy as np
|
|
|
|
from collections import defaultdict
|
|
|
|
from optparse import OptionParser
|
|
|
|
import damask
|
2012-04-18 15:28:59 +05:30
|
|
|
|
2014-08-06 18:57:09 +05:30
|
|
|
scriptID = string.replace('$Id$','\n','\\n')
|
2014-12-19 00:56:52 +05:30
|
|
|
scriptName = os.path.splitext(scriptID.split()[1])[0]
|
2012-04-18 15:28:59 +05:30
|
|
|
|
|
|
|
# --------------------------------------------------------------------
|
|
|
|
# MAIN
|
|
|
|
# --------------------------------------------------------------------
|
|
|
|
|
2014-07-22 01:25:05 +05:30
|
|
|
parser = OptionParser(option_class=damask.extendableOption, usage='%prog options file[s]', description = """
|
2015-06-29 15:14:49 +05:30
|
|
|
Add deformed configuration of given initial coordinates.
|
2015-08-08 00:33:26 +05:30
|
|
|
Operates on periodic three-dimensional x,y,z-ordered data sets.
|
2012-04-18 15:28:59 +05:30
|
|
|
|
2014-08-06 18:57:09 +05:30
|
|
|
""", version = scriptID)
|
2012-04-18 15:28:59 +05:30
|
|
|
|
2015-08-08 00:33:26 +05:30
|
|
|
parser.add_option('-c','--coordinates',
|
|
|
|
dest = 'coords',
|
|
|
|
type = 'string', metavar = 'string',
|
|
|
|
help = 'column label of coordinates [%default]')
|
|
|
|
parser.add_option('-f','--defgrad',
|
|
|
|
dest = 'defgrad',
|
|
|
|
type = 'string', metavar = 'string',
|
|
|
|
help = 'column label of deformation gradient [%default]')
|
|
|
|
parser.add_option('--scaling',
|
|
|
|
dest = 'scaling',
|
|
|
|
type = 'float', nargs = 3, metavar = ' '.join(['float']*3),
|
|
|
|
help = 'x/y/z scaling of displacement fluctuation')
|
|
|
|
|
2015-06-29 15:14:49 +05:30
|
|
|
parser.set_defaults(coords = 'ipinitialcoord',
|
|
|
|
defgrad = 'f',
|
|
|
|
scaling = [1.,1.,1.],
|
|
|
|
)
|
2012-04-18 15:28:59 +05:30
|
|
|
|
|
|
|
(options,filenames) = parser.parse_args()
|
|
|
|
|
2015-06-08 10:37:14 +05:30
|
|
|
# --- loop over input files -------------------------------------------------------------------------
|
2015-08-08 00:33:26 +05:30
|
|
|
|
|
|
|
if filenames == []: filenames = ['STDIN']
|
2012-04-18 15:28:59 +05:30
|
|
|
|
2014-07-22 01:25:05 +05:30
|
|
|
for name in filenames:
|
2015-08-08 00:33:26 +05:30
|
|
|
if not (name == 'STDIN' or os.path.exists(name)): continue
|
|
|
|
table = damask.ASCIItable(name = name, outname = name+'_tmp',
|
|
|
|
buffered = False)
|
|
|
|
table.croak('\033[1m'+scriptName+'\033[0m'+(': '+name if name != 'STDIN' else ''))
|
2012-04-18 15:28:59 +05:30
|
|
|
|
2015-08-08 00:33:26 +05:30
|
|
|
# ------------------------------------------ read header ------------------------------------------
|
2015-06-08 10:37:14 +05:30
|
|
|
|
2015-08-08 00:33:26 +05:30
|
|
|
table.head_read()
|
|
|
|
|
|
|
|
# ------------------------------------------ sanity checks ----------------------------------------
|
|
|
|
|
|
|
|
errors = []
|
|
|
|
remarks = []
|
|
|
|
|
|
|
|
if table.label_dimension(options.coords) != 3: errors.append('coordinates {} are not a vector.'.format(options.coords))
|
|
|
|
else: colCoord = table.label_index(options.coords)
|
|
|
|
|
|
|
|
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)
|
|
|
|
|
|
|
|
if remarks != []: table.croak(remarks)
|
|
|
|
if errors != []:
|
|
|
|
table.croak(errors)
|
|
|
|
table.close(dismiss = True)
|
2015-06-08 10:37:14 +05:30
|
|
|
continue
|
|
|
|
|
2014-08-06 20:55:18 +05:30
|
|
|
# --------------- figure out size and grid ---------------------------------------------------------
|
2015-06-08 10:37:14 +05:30
|
|
|
|
2015-08-08 00:33:26 +05:30
|
|
|
table.data_readArray()
|
2012-04-18 15:28:59 +05:30
|
|
|
|
2014-08-06 20:55:18 +05:30
|
|
|
coords = [{},{},{}]
|
2015-08-08 00:33:26 +05:30
|
|
|
for i in xrange(len(table.data)):
|
2012-04-18 15:28:59 +05:30
|
|
|
for j in xrange(3):
|
2015-08-08 00:33:26 +05:30
|
|
|
coords[j][str(table.data[i,colCoord+j])] = True
|
|
|
|
grid = np.array(map(len,coords),'i')
|
2014-08-06 20:55:18 +05:30
|
|
|
size = grid/np.maximum(np.ones(3,'d'),grid-1.0)* \
|
|
|
|
np.array([max(map(float,coords[0].keys()))-min(map(float,coords[0].keys())),\
|
|
|
|
max(map(float,coords[1].keys()))-min(map(float,coords[1].keys())),\
|
|
|
|
max(map(float,coords[2].keys()))-min(map(float,coords[2].keys())),\
|
2014-08-07 00:36:33 +05:30
|
|
|
],'d') # size from bounding box, corrected for cell-centeredness
|
2014-08-06 20:55:18 +05:30
|
|
|
|
2015-08-08 00:33:26 +05:30
|
|
|
size = np.where(grid > 1, size, min(size[grid > 1]/grid[grid > 1])) # spacing for grid==1 equal to smallest among other spacings
|
2012-04-18 15:28:59 +05:30
|
|
|
|
2015-08-08 00:33:26 +05:30
|
|
|
N = grid.prod()
|
2014-08-07 00:36:33 +05:30
|
|
|
|
2014-08-06 20:55:18 +05:30
|
|
|
# ------------------------------------------ assemble header ---------------------------------------
|
2015-08-08 00:33:26 +05:30
|
|
|
|
|
|
|
table.info_append(scriptID + '\t' + ' '.join(sys.argv[1:]))
|
|
|
|
table.labels_append(['{}_{}.{}'%(coord+1,options.defgrad,options.coords) for coord in xrange(3)]) # extend ASCII header with new labels
|
2012-04-18 15:28:59 +05:30
|
|
|
table.head_write()
|
|
|
|
|
2015-08-08 00:33:26 +05:30
|
|
|
# ------------------------------------------ process deformation gradient --------------------------
|
|
|
|
|
|
|
|
F = table.data[:,colF:colF+9].transpose().reshape([3,3]+list(options.dimension),order='F')
|
|
|
|
Favg = damask.core.math.tensorAvg(F)
|
|
|
|
centres = damask.core.mesh.deformedCoordsFFT(size,F,Favg,[1.0,1.0,1.0])
|
|
|
|
|
|
|
|
stack = [table.data,centres]
|
|
|
|
|
2014-08-06 20:55:18 +05:30
|
|
|
# ------------------------------------------ output result -----------------------------------------
|
2012-04-18 15:28:59 +05:30
|
|
|
|
2015-08-08 00:33:26 +05:30
|
|
|
if len(stack) > 1: table.data = np.hstack(tuple(stack))
|
|
|
|
table.data_writeArray('%.12g')
|
|
|
|
|
|
|
|
# ------------------------------------------ output finalization -----------------------------------
|
|
|
|
|
|
|
|
table.close() # close ASCII tables
|
|
|
|
if name != 'STDIN': os.rename(name+'_tmp',name) # overwrite old one with tmp new
|