addDeformedConfiguration without core module
This commit is contained in:
parent
26b2a36cae
commit
f49091c952
|
@ -1,7 +1,7 @@
|
||||||
#!/usr/bin/env python
|
#!/usr/bin/env python
|
||||||
# -*- coding: UTF-8 no BOM -*-
|
# -*- coding: UTF-8 no BOM -*-
|
||||||
|
|
||||||
import os,sys,string
|
import os,sys,string,math
|
||||||
import numpy as np
|
import numpy as np
|
||||||
from optparse import OptionParser
|
from optparse import OptionParser
|
||||||
import damask
|
import damask
|
||||||
|
@ -9,6 +9,49 @@ import damask
|
||||||
scriptID = string.replace('$Id$','\n','\\n')
|
scriptID = string.replace('$Id$','\n','\\n')
|
||||||
scriptName = os.path.splitext(scriptID.split()[1])[0]
|
scriptName = os.path.splitext(scriptID.split()[1])[0]
|
||||||
|
|
||||||
|
#--------------------------------------------------------------------------------------------------
|
||||||
|
def deformedCoordsFFT(F,undeformed=False):
|
||||||
|
#--------------------------------------------------------------------------------------------------
|
||||||
|
wgt = 1.0/grid.prod()
|
||||||
|
integrator = grid[::-1] / 2.0 / math.pi
|
||||||
|
step = size[::-1]/grid[::-1]
|
||||||
|
|
||||||
|
F_fourier = np.fft.fftpack.rfftn(F,axes=(0,1,2))
|
||||||
|
if undeformed:
|
||||||
|
Favg=np.eye(3)
|
||||||
|
else:
|
||||||
|
Favg=np.real(F_fourier[0,0,0,:,:])*wgt
|
||||||
|
coords_fourier = np.zeros(F_fourier.shape[:-1],'c16')
|
||||||
|
|
||||||
|
#--------------------------------------------------------------------------------------------------
|
||||||
|
# integration in Fourier space
|
||||||
|
k_s = np.zeros([3],'i')
|
||||||
|
|
||||||
|
for k in xrange(grid[2]):
|
||||||
|
k_s[2] = k
|
||||||
|
if(k > grid[0]/2 ): k_s[2] = k_s[2] - grid[2]
|
||||||
|
for j in xrange(grid[1]):
|
||||||
|
k_s[1] = j
|
||||||
|
if(j > grid[1]/2 ): k_s[1] = k_s[1] - grid[1]
|
||||||
|
for i in xrange(grid[0]/2+1):
|
||||||
|
k_s[0] = i
|
||||||
|
for m in xrange(3):
|
||||||
|
coords_fourier[k,j,i,m] = sum(F_fourier[k,j,i,0:3,m]*k_s*\
|
||||||
|
np.array([0.+1.j,0.+1.j,0.+1.j],'c16')*integrator)
|
||||||
|
if (any(k_s != 0)):
|
||||||
|
coords_fourier[k,j,i,0:3] /= -sum(k_s*k_s)
|
||||||
|
#--------------------------------------------------------------------------------------------------
|
||||||
|
# add average to scaled fluctuation and put (0,0,0) on (0,0,0)
|
||||||
|
coords = np.fft.fftpack.irfftn(coords_fourier,axes=(0,1,2))
|
||||||
|
offset_coords = np.dot(F[0,0,0,0:3,0:3],step/2.0) - scaling*coords[0,0,0,0:3]
|
||||||
|
for k in xrange(grid[2]):
|
||||||
|
for j in xrange(grid[1]):
|
||||||
|
for i in xrange(grid[0]):
|
||||||
|
coords[k,j,i,0:3] = scaling*coords[k,j,i,0:3] \
|
||||||
|
+ offset_coords \
|
||||||
|
+ np.dot(Favg,step*np.array([i,j,k]))
|
||||||
|
return coords
|
||||||
|
|
||||||
# --------------------------------------------------------------------
|
# --------------------------------------------------------------------
|
||||||
# MAIN
|
# MAIN
|
||||||
# --------------------------------------------------------------------
|
# --------------------------------------------------------------------
|
||||||
|
@ -19,26 +62,29 @@ Operates on periodic three-dimensional x,y,z-ordered data sets.
|
||||||
|
|
||||||
""", version = scriptID)
|
""", version = scriptID)
|
||||||
|
|
||||||
parser.add_option('-c','--coordinates',
|
parser.add_option('-f', '--defgrad',dest='defgrad', metavar = 'string',
|
||||||
dest = 'coords',
|
help='heading of deformation gradient columns [%default]')
|
||||||
type = 'string', metavar = 'string',
|
parser.add_option('--reference', dest='undeformed', action='store_true',
|
||||||
help = 'column label of coordinates [%default]')
|
help='map results to reference (undeformed) average configuration [%default]')
|
||||||
parser.add_option('-f','--defgrad',
|
parser.add_option('--scaling', dest='scaling', action='extend', metavar = '<float LIST>',
|
||||||
dest = 'defgrad',
|
help='scaling of fluctuation')
|
||||||
type = 'string', metavar = 'string',
|
parser.add_option('-u', '--unitlength', dest='unitlength', type='float', metavar = 'float',
|
||||||
help = 'column label of deformation gradient [%default]')
|
help='set unit length for 2D model [%default]')
|
||||||
parser.add_option('--scaling',
|
parser.add_option('--coordinates', dest='coords', metavar='string',
|
||||||
dest = 'scaling',
|
help='column heading for coordinates [%default]')
|
||||||
type = 'float', nargs = 3, metavar = ' '.join(['float']*3),
|
|
||||||
help = 'x/y/z scaling of displacement fluctuation')
|
|
||||||
|
|
||||||
parser.set_defaults(coords = 'ipinitialcoord',
|
parser.set_defaults(defgrad = 'f')
|
||||||
defgrad = 'f',
|
parser.set_defaults(coords = 'ipinitialcoord')
|
||||||
scaling = [1.,1.,1.],
|
parser.set_defaults(scaling = [])
|
||||||
)
|
parser.set_defaults(undeformed = False)
|
||||||
|
parser.set_defaults(unitlength = 0.0)
|
||||||
|
|
||||||
(options,filenames) = parser.parse_args()
|
(options,filenames) = parser.parse_args()
|
||||||
|
|
||||||
|
options.scaling += [1.0 for i in xrange(max(0,3-len(options.scaling)))]
|
||||||
|
scaling = map(float, options.scaling)
|
||||||
|
|
||||||
|
|
||||||
# --- loop over input files -------------------------------------------------------------------------
|
# --- loop over input files -------------------------------------------------------------------------
|
||||||
|
|
||||||
if filenames == []: filenames = [None]
|
if filenames == []: filenames = [None]
|
||||||
|
@ -94,22 +140,15 @@ for name in filenames:
|
||||||
|
|
||||||
table.info_append(scriptID + '\t' + ' '.join(sys.argv[1:]))
|
table.info_append(scriptID + '\t' + ' '.join(sys.argv[1:]))
|
||||||
for coord in xrange(3):
|
for coord in xrange(3):
|
||||||
table.labels_append(['{}_{}.{}'.format(coord+1,options.defgrad,options.coords) ]) # extend ASCII header with new labels
|
label = '{}_{}_{}'.format(coord+1,options.defgrad,options.coords)
|
||||||
|
if np.any(scaling) != 1.0: label+='_{}_{}_{}'.format(scaling)
|
||||||
|
if options.undeformed: label+='_undeformed'
|
||||||
|
table.labels_append([label]) # extend ASCII header with new labels
|
||||||
table.head_write()
|
table.head_write()
|
||||||
|
|
||||||
# ------------------------------------------ read deformation gradient field -----------------------
|
# ------------------------------------------ read deformation gradient field -----------------------
|
||||||
table.data_rewind()
|
centroids = deformedCoordsFFT(table.data[:,colF:colF+9].reshape(grid[0],grid[1],grid[2],3,3),
|
||||||
F = np.array([0.0 for i in xrange(N*9)]).reshape([3,3]+grid.tolist())
|
options.undeformed)
|
||||||
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
|
|
||||||
F[0:3,0:3,x,y,z] = np.array(map(float,table.data[table.label_index(options.defgrad):\
|
|
||||||
table.label_index(options.defgrad)+9]),'d').reshape(3,3)
|
|
||||||
|
|
||||||
# ------------------------------------------ calculate coordinates ---------------------------------
|
|
||||||
Favg = damask.core.math.tensorAvg(F)
|
|
||||||
centroids = damask.core.mesh.deformedCoordsFFT(size,F,Favg)
|
|
||||||
|
|
||||||
# ------------------------------------------ process data ------------------------------------------
|
# ------------------------------------------ process data ------------------------------------------
|
||||||
table.data_rewind()
|
table.data_rewind()
|
||||||
|
@ -118,7 +157,7 @@ for name in filenames:
|
||||||
while outputAlive and table.data_read(): # read next data line of ASCII table
|
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
|
(x,y,z) = damask.util.gridLocation(idx,grid) # figure out (x,y,z) position from line count
|
||||||
idx += 1
|
idx += 1
|
||||||
table.data_append(list(centroids[:,x,y,z]))
|
table.data_append(list(centroids[z,y,x,:]))
|
||||||
outputAlive = table.data_write()
|
outputAlive = table.data_write()
|
||||||
|
|
||||||
# ------------------------------------------ output finalization -----------------------------------
|
# ------------------------------------------ output finalization -----------------------------------
|
||||||
|
|
Loading…
Reference in New Issue