polishing and introduction of locally derived grid in FFT subroutine
This commit is contained in:
parent
93466273ff
commit
ce26ad06da
|
@ -10,40 +10,35 @@ scriptName = os.path.splitext(os.path.basename(__file__))[0]
|
||||||
scriptID = ' '.join([scriptName,damask.version])
|
scriptID = ' '.join([scriptName,damask.version])
|
||||||
|
|
||||||
def curlFFT(geomdim,field):
|
def curlFFT(geomdim,field):
|
||||||
|
grid = np.array(np.shape(field)[2::-1])
|
||||||
N = grid.prod() # field size
|
N = grid.prod() # field size
|
||||||
n = np.array(np.shape(field)[3:]).prod() # data size
|
n = np.array(np.shape(field)[3:]).prod() # data size
|
||||||
|
|
||||||
if n == 3:
|
if n == 3: dataType = 'vector'
|
||||||
dataType = 'vector'
|
elif n == 9: dataType = 'tensor'
|
||||||
elif n == 9:
|
|
||||||
dataType = 'tensor'
|
|
||||||
|
|
||||||
field_fourier = np.fft.fftpack.rfftn(field,axes=(0,1,2))
|
field_fourier = np.fft.fftpack.rfftn(field,axes=(0,1,2))
|
||||||
curl_fourier = np.zeros(field_fourier.shape,'c16')
|
curl_fourier = np.zeros(field_fourier.shape,'c16')
|
||||||
|
|
||||||
# differentiation in Fourier space
|
# differentiation in Fourier space
|
||||||
k_s = np.zeros([3],'i')
|
k_s = np.zeros([3],'i')
|
||||||
TWOPIIMG = (0.0+2.0j*math.pi)
|
TWOPIIMG = 2.0j*math.pi
|
||||||
for i in xrange(grid[2]):
|
for i in xrange(grid[2]):
|
||||||
k_s[0] = i
|
k_s[0] = i
|
||||||
if(grid[2]%2==0 and i == grid[2]//2): # for even grid, set Nyquist freq to 0 (Johnson, MIT, 2011)
|
if grid[2]%2 == 0 and i == grid[2]//2: k_s[0] = 0 # for even grid, set Nyquist freq to 0 (Johnson, MIT, 2011)
|
||||||
k_s[0]=0
|
elif i > grid[2]//2: k_s[0] -= grid[2]
|
||||||
elif (i > grid[2]//2):
|
|
||||||
k_s[0] = k_s[0] - grid[2]
|
|
||||||
|
|
||||||
for j in xrange(grid[1]):
|
for j in xrange(grid[1]):
|
||||||
k_s[1] = j
|
k_s[1] = j
|
||||||
if(grid[1]%2==0 and j == grid[1]//2): # for even grid, set Nyquist freq to 0 (Johnson, MIT, 2011)
|
if grid[1]%2 == 0 and j == grid[1]//2: k_s[1] = 0 # for even grid, set Nyquist freq to 0 (Johnson, MIT, 2011)
|
||||||
k_s[1]=0
|
elif j > grid[1]//2: k_s[1] -= grid[1]
|
||||||
elif (j > grid[1]//2):
|
|
||||||
k_s[1] = k_s[1] - grid[1]
|
|
||||||
|
|
||||||
for k in xrange(grid[0]//2+1):
|
for k in xrange(grid[0]//2+1):
|
||||||
k_s[2] = k
|
k_s[2] = k
|
||||||
if(grid[0]%2==0 and k == grid[0]//2): # for even grid, set Nyquist freq to 0 (Johnson, MIT, 2011)
|
if grid[0]%2 == 0 and k == grid[0]//2: k_s[2] = 0 # for even grid, set Nyquist freq to 0 (Johnson, MIT, 2011)
|
||||||
k_s[2]=0
|
|
||||||
|
xi = (k_s/geomdim)[2::-1].astype('c16') # reversing the field input order
|
||||||
|
|
||||||
xi = np.array([k_s[2]/geomdim[2]+0.0j,k_s[1]/geomdim[1]+0.j,k_s[0]/geomdim[0]+0.j],'c16')
|
|
||||||
if dataType == 'tensor':
|
if dataType == 'tensor':
|
||||||
for l in xrange(3):
|
for l in xrange(3):
|
||||||
curl_fourier[i,j,k,0,l] = ( field_fourier[i,j,k,l,2]*xi[1]\
|
curl_fourier[i,j,k,0,l] = ( field_fourier[i,j,k,l,2]*xi[1]\
|
||||||
|
@ -100,10 +95,8 @@ if options.vector is None and options.tensor is None:
|
||||||
if filenames == []: filenames = [None]
|
if filenames == []: filenames = [None]
|
||||||
|
|
||||||
for name in filenames:
|
for name in filenames:
|
||||||
try:
|
try: table = damask.ASCIItable(name = name,buffered = False)
|
||||||
table = damask.ASCIItable(name = name,buffered = False)
|
except: continue
|
||||||
except:
|
|
||||||
continue
|
|
||||||
damask.util.report(scriptName,name)
|
damask.util.report(scriptName,name)
|
||||||
|
|
||||||
# ------------------------------------------ read header ------------------------------------------
|
# ------------------------------------------ read header ------------------------------------------
|
||||||
|
@ -161,9 +154,9 @@ for name in filenames:
|
||||||
stack = [table.data]
|
stack = [table.data]
|
||||||
for type, data in items.iteritems():
|
for type, data in items.iteritems():
|
||||||
for i,label in enumerate(data['active']):
|
for i,label in enumerate(data['active']):
|
||||||
stack.append(curlFFT(size[::-1], # we need to reverse order here, because x
|
stack.append(curlFFT(size[::-1], # we need to reverse order here, because x is fastest,ie rightmost, but leftmost in our x,y,z notation
|
||||||
table.data[:,data['column'][i]:data['column'][i]+data['dim']]. # is fastest,ie rightmost, but leftmost in
|
table.data[:,data['column'][i]:data['column'][i]+data['dim']].
|
||||||
reshape([grid[2],grid[1],grid[0]]+data['shape']))) # our x,y,z notation
|
reshape([grid[2],grid[1],grid[0]]+data['shape'])))
|
||||||
|
|
||||||
# ------------------------------------------ output result -----------------------------------------
|
# ------------------------------------------ output result -----------------------------------------
|
||||||
|
|
||||||
|
|
|
@ -10,6 +10,7 @@ scriptName = os.path.splitext(os.path.basename(__file__))[0]
|
||||||
scriptID = ' '.join([scriptName,damask.version])
|
scriptID = ' '.join([scriptName,damask.version])
|
||||||
|
|
||||||
def divFFT(geomdim,field):
|
def divFFT(geomdim,field):
|
||||||
|
grid = np.array(np.shape(field)[2::-1])
|
||||||
N = grid.prod() # field size
|
N = grid.prod() # field size
|
||||||
n = np.array(np.shape(field)[3:]).prod() # data size
|
n = np.array(np.shape(field)[3:]).prod() # data size
|
||||||
|
|
||||||
|
@ -18,27 +19,22 @@ def divFFT(geomdim,field):
|
||||||
|
|
||||||
# differentiation in Fourier space
|
# differentiation in Fourier space
|
||||||
k_s=np.zeros([3],'i')
|
k_s=np.zeros([3],'i')
|
||||||
TWOPIIMG = (0.0+2.0j*math.pi)
|
TWOPIIMG = 2.0j*math.pi
|
||||||
for i in xrange(grid[2]):
|
for i in xrange(grid[2]):
|
||||||
k_s[0] = i
|
k_s[0] = i
|
||||||
if(grid[2]%2==0 and i == grid[2]//2): # for even grid, set Nyquist freq to 0 (Johnson, MIT, 2011)
|
if grid[2]%2 == 0 and i == grid[2]//2: k_s[0] = 0 # for even grid, set Nyquist freq to 0 (Johnson, MIT, 2011)
|
||||||
k_s[0]=0
|
elif i > grid[2]//2: k_s[0] -= grid[2]
|
||||||
elif (i > grid[2]//2):
|
|
||||||
k_s[0] = k_s[0] - grid[2]
|
|
||||||
|
|
||||||
for j in xrange(grid[1]):
|
for j in xrange(grid[1]):
|
||||||
k_s[1] = j
|
k_s[1] = j
|
||||||
if(grid[1]%2==0 and j == grid[1]//2): # for even grid, set Nyquist freq to 0 (Johnson, MIT, 2011)
|
if grid[1]%2 == 0 and j == grid[1]//2: k_s[1] = 0 # for even grid, set Nyquist freq to 0 (Johnson, MIT, 2011)
|
||||||
k_s[1]=0
|
elif j > grid[1]//2: k_s[1] -= grid[1]
|
||||||
elif (j > grid[1]//2):
|
|
||||||
k_s[1] = k_s[1] - grid[1]
|
|
||||||
|
|
||||||
for k in xrange(grid[0]//2+1):
|
for k in xrange(grid[0]//2+1):
|
||||||
k_s[2] = k
|
k_s[2] = k
|
||||||
if(grid[0]%2==0 and k == grid[0]//2): # for even grid, set Nyquist freq to 0 (Johnson, MIT, 2011)
|
if grid[0]%2 == 0 and k == grid[0]//2: k_s[2] = 0 # for even grid, set Nyquist freq to 0 (Johnson, MIT, 2011)
|
||||||
k_s[2]=0
|
|
||||||
|
|
||||||
xi=np.array([k_s[2]/geomdim[2]+0.0j,k_s[1]/geomdim[1]+0.j,k_s[0]/geomdim[0]+0.j],'c16')
|
xi = (k_s/geomdim)[2::-1].astype('c16') # reversing the field input order
|
||||||
if n == 9: # tensor, 3x3 -> 3
|
if n == 9: # tensor, 3x3 -> 3
|
||||||
for l in xrange(3):
|
for l in xrange(3):
|
||||||
div_fourier[i,j,k,l] = sum(field_fourier[i,j,k,l,0:3]*xi) *TWOPIIMG
|
div_fourier[i,j,k,l] = sum(field_fourier[i,j,k,l,0:3]*xi) *TWOPIIMG
|
||||||
|
@ -85,10 +81,8 @@ if options.vector is None and options.tensor is None:
|
||||||
if filenames == []: filenames = [None]
|
if filenames == []: filenames = [None]
|
||||||
|
|
||||||
for name in filenames:
|
for name in filenames:
|
||||||
try:
|
try: table = damask.ASCIItable(name = name,buffered = False)
|
||||||
table = damask.ASCIItable(name = name,buffered = False)
|
except: continue
|
||||||
except:
|
|
||||||
continue
|
|
||||||
damask.util.report(scriptName,name)
|
damask.util.report(scriptName,name)
|
||||||
|
|
||||||
# ------------------------------------------ read header ------------------------------------------
|
# ------------------------------------------ read header ------------------------------------------
|
||||||
|
@ -140,16 +134,16 @@ for name in filenames:
|
||||||
maxcorner = np.array(map(max,coords))
|
maxcorner = np.array(map(max,coords))
|
||||||
grid = np.array(map(len,coords),'i')
|
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)
|
size = grid/np.maximum(np.ones(3,'d'), grid-1.0) * (maxcorner-mincorner) # size from edge to edge = dim * n/(n-1)
|
||||||
size = np.where(grid > 1, size, min(size[grid > 1]/grid[grid > 1])) # spacing for grid==1 set to smallest among other spacings
|
size = np.where(grid > 1, size, min(size[grid > 1]/grid[grid > 1])) # spacing for grid==1 equal to smallest among other spacings
|
||||||
|
|
||||||
# ------------------------------------------ process value field -----------------------------------
|
# ------------------------------------------ process value field -----------------------------------
|
||||||
|
|
||||||
stack = [table.data]
|
stack = [table.data]
|
||||||
for type, data in items.iteritems():
|
for type, data in items.iteritems():
|
||||||
for i,label in enumerate(data['active']):
|
for i,label in enumerate(data['active']):
|
||||||
stack.append(divFFT(size[::-1], # we need to reverse order here, because x
|
stack.append(divFFT(size[::-1], # we need to reverse order here, because x is fastest,ie rightmost, but leftmost in our x,y,z notation
|
||||||
table.data[:,data['column'][i]:data['column'][i]+data['dim']]. # is fastest,ie rightmost, but leftmost in
|
table.data[:,data['column'][i]:data['column'][i]+data['dim']].
|
||||||
reshape([grid[2],grid[1],grid[0]]+data['shape']))) # our x,y,z notation
|
reshape([grid[2],grid[1],grid[0]]+data['shape'])))
|
||||||
|
|
||||||
# ------------------------------------------ output result -----------------------------------------
|
# ------------------------------------------ output result -----------------------------------------
|
||||||
|
|
||||||
|
@ -158,4 +152,4 @@ for name in filenames:
|
||||||
|
|
||||||
# ------------------------------------------ output finalization -----------------------------------
|
# ------------------------------------------ output finalization -----------------------------------
|
||||||
|
|
||||||
table.close() # close input ASCII table (works for stdin)
|
table.close() # close input ASCII table (works for stdin)
|
||||||
|
|
Loading…
Reference in New Issue