shortened excessively long lines
This commit is contained in:
parent
3a267dc7ff
commit
36c703ecd3
|
@ -11,8 +11,8 @@ scriptID = ' '.join([scriptName,damask.version])
|
||||||
|
|
||||||
def curlFFT(geomdim,field):
|
def curlFFT(geomdim,field):
|
||||||
grid = np.array(np.shape(field)[2::-1])
|
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: dataType = 'vector'
|
if n == 3: dataType = 'vector'
|
||||||
elif n == 9: dataType = 'tensor'
|
elif n == 9: dataType = 'tensor'
|
||||||
|
@ -25,19 +25,19 @@ def curlFFT(geomdim,field):
|
||||||
TWOPIIMG = 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: k_s[0] = 0 # 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)
|
||||||
elif i > grid[2]//2: k_s[0] -= grid[2]
|
elif i > grid[2]//2: 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: k_s[1] = 0 # 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)
|
||||||
elif j > grid[1]//2: k_s[1] -= grid[1]
|
elif j > grid[1]//2: 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: k_s[2] = 0 # 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)
|
||||||
|
|
||||||
xi = (k_s/geomdim)[2::-1].astype('c16') # reversing the field input order
|
xi = (k_s/geomdim)[2::-1].astype('c16') # reversing the field input order
|
||||||
|
|
||||||
if dataType == 'tensor':
|
if dataType == 'tensor':
|
||||||
for l in xrange(3):
|
for l in xrange(3):
|
||||||
|
@ -154,7 +154,8 @@ 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 is fastest,ie rightmost, but leftmost in our x,y,z notation
|
# we need to reverse order here, because x is fastest,ie rightmost, but leftmost in our x,y,z notation
|
||||||
|
stack.append(curlFFT(size[::-1],
|
||||||
table.data[:,data['column'][i]:data['column'][i]+data['dim']].
|
table.data[:,data['column'][i]:data['column'][i]+data['dim']].
|
||||||
reshape([grid[2],grid[1],grid[0]]+data['shape'])))
|
reshape([grid[2],grid[1],grid[0]]+data['shape'])))
|
||||||
|
|
||||||
|
|
|
@ -11,34 +11,34 @@ scriptID = ' '.join([scriptName,damask.version])
|
||||||
|
|
||||||
def divFFT(geomdim,field):
|
def divFFT(geomdim,field):
|
||||||
grid = np.array(np.shape(field)[2::-1])
|
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
|
||||||
|
|
||||||
field_fourier = np.fft.fftpack.rfftn(field,axes=(0,1,2))
|
field_fourier = np.fft.fftpack.rfftn(field,axes=(0,1,2))
|
||||||
div_fourier = np.zeros(field_fourier.shape[0:len(np.shape(field))-1],'c16') # size depents on whether tensor or vector
|
div_fourier = np.zeros(field_fourier.shape[0:len(np.shape(field))-1],'c16') # size depents on whether tensor or vector
|
||||||
|
|
||||||
# differentiation in Fourier space
|
# differentiation in Fourier space
|
||||||
k_s=np.zeros([3],'i')
|
k_s=np.zeros([3],'i')
|
||||||
TWOPIIMG = 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: k_s[0] = 0 # 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)
|
||||||
elif i > grid[2]//2: k_s[0] -= grid[2]
|
elif i > grid[2]//2: 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: k_s[1] = 0 # 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)
|
||||||
elif j > grid[1]//2: k_s[1] -= grid[1]
|
elif j > grid[1]//2: 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: k_s[2] = 0 # 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)
|
||||||
|
|
||||||
xi = (k_s/geomdim)[2::-1].astype('c16') # reversing the field input order
|
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
|
||||||
elif n == 3: # vector, 3 -> 1
|
elif n == 3: # vector, 3 -> 1
|
||||||
div_fourier[i,j,k] = sum(field_fourier[i,j,k,0:3]*xi) *TWOPIIMG
|
div_fourier[i,j,k] = sum(field_fourier[i,j,k,0:3]*xi) *TWOPIIMG
|
||||||
|
|
||||||
return np.fft.fftpack.irfftn(div_fourier,axes=(0,1,2)).reshape([N,n/3])
|
return np.fft.fftpack.irfftn(div_fourier,axes=(0,1,2)).reshape([N,n/3])
|
||||||
|
@ -76,7 +76,7 @@ parser.set_defaults(coords = 'ipinitialcoord',
|
||||||
if options.vector is None and options.tensor is None:
|
if options.vector is None and options.tensor is None:
|
||||||
parser.error('no data column specified.')
|
parser.error('no data column specified.')
|
||||||
|
|
||||||
# --- loop over input files -------------------------------------------------------------------------
|
# --- loop over input files ------------------------------------------------------------------------
|
||||||
|
|
||||||
if filenames == []: filenames = [None]
|
if filenames == []: filenames = [None]
|
||||||
|
|
||||||
|
@ -134,14 +134,15 @@ 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 equal 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 ones
|
||||||
|
|
||||||
# ------------------------------------------ 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 is fastest,ie rightmost, but leftmost in our x,y,z notation
|
# we need to reverse order here, because x is fastest,ie rightmost, but leftmost in our x,y,z notation
|
||||||
|
stack.append(divFFT(size[::-1],
|
||||||
table.data[:,data['column'][i]:data['column'][i]+data['dim']].
|
table.data[:,data['column'][i]:data['column'][i]+data['dim']].
|
||||||
reshape([grid[2],grid[1],grid[0]]+data['shape'])))
|
reshape([grid[2],grid[1],grid[0]]+data['shape'])))
|
||||||
|
|
||||||
|
|
|
@ -11,8 +11,8 @@ scriptID = ' '.join([scriptName,damask.version])
|
||||||
|
|
||||||
def gradFFT(geomdim,field):
|
def gradFFT(geomdim,field):
|
||||||
grid = np.array(np.shape(field)[2::-1])
|
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: dataType = 'vector'
|
if n == 3: dataType = 'vector'
|
||||||
elif n == 1: dataType = 'scalar'
|
elif n == 1: dataType = 'scalar'
|
||||||
|
|
||||||
|
@ -24,24 +24,24 @@ def gradFFT(geomdim,field):
|
||||||
TWOPIIMG = 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: k_s[0] = 0 # 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)
|
||||||
elif i > grid[2]//2: k_s[0] -= grid[2]
|
elif i > grid[2]//2: 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: k_s[1] = 0 # 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)
|
||||||
elif j > grid[1]//2: k_s[1] -= grid[1]
|
elif j > grid[1]//2: 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: k_s[2] = 0 # 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)
|
||||||
|
|
||||||
xi = (k_s/geomdim)[2::-1].astype('c16') # reversing the field order
|
xi = (k_s/geomdim)[2::-1].astype('c16') # reversing the field order
|
||||||
|
|
||||||
grad_fourier[i,j,k,0,:] = field_fourier[i,j,k,0]*xi *TWOPIIMG # vector field from scalar data
|
grad_fourier[i,j,k,0,:] = field_fourier[i,j,k,0]*xi *TWOPIIMG # vector field from scalar data
|
||||||
|
|
||||||
if dataType == 'vector':
|
if dataType == 'vector':
|
||||||
grad_fourier[i,j,k,1,:] = field_fourier[i,j,k,1]*xi *TWOPIIMG # tensor field from vector data
|
grad_fourier[i,j,k,1,:] = field_fourier[i,j,k,1]*xi *TWOPIIMG # tensor field from vector data
|
||||||
grad_fourier[i,j,k,2,:] = field_fourier[i,j,k,2]*xi *TWOPIIMG
|
grad_fourier[i,j,k,2,:] = field_fourier[i,j,k,2]*xi *TWOPIIMG
|
||||||
|
|
||||||
return np.fft.fftpack.irfftn(grad_fourier,axes=(0,1,2)).reshape([N,3*n])
|
return np.fft.fftpack.irfftn(grad_fourier,axes=(0,1,2)).reshape([N,3*n])
|
||||||
|
@ -79,7 +79,7 @@ parser.set_defaults(coords = 'ipinitialcoord',
|
||||||
if options.vector is None and options.scalar is None:
|
if options.vector is None and options.scalar is None:
|
||||||
parser.error('no data column specified.')
|
parser.error('no data column specified.')
|
||||||
|
|
||||||
# --- loop over input files -------------------------------------------------------------------------
|
# --- loop over input files ------------------------------------------------------------------------
|
||||||
|
|
||||||
if filenames == []: filenames = [None]
|
if filenames == []: filenames = [None]
|
||||||
|
|
||||||
|
@ -124,7 +124,7 @@ for name in filenames:
|
||||||
table.info_append(scriptID + '\t' + ' '.join(sys.argv[1:]))
|
table.info_append(scriptID + '\t' + ' '.join(sys.argv[1:]))
|
||||||
for type, data in items.iteritems():
|
for type, data in items.iteritems():
|
||||||
for label in data['active']:
|
for label in data['active']:
|
||||||
table.labels_append(['{}_gradFFT({})'.format(i+1,label) for i in xrange(3 * data['dim'])]) # extend ASCII header with new labels # grad increases the field dimension by one
|
table.labels_append(['{}_gradFFT({})'.format(i+1,label) for i in xrange(3 * data['dim'])]) # extend ASCII header with new labels
|
||||||
table.head_write()
|
table.head_write()
|
||||||
|
|
||||||
# --------------- figure out size and grid ---------------------------------------------------------
|
# --------------- figure out size and grid ---------------------------------------------------------
|
||||||
|
@ -143,7 +143,8 @@ 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(gradFFT(size[::-1], # we need to reverse order here, because x is fastest,ie rightmost, but leftmost in our x,y,z notation
|
# we need to reverse order here, because x is fastest,ie rightmost, but leftmost in our x,y,z notation
|
||||||
|
stack.append(gradFFT(size[::-1],
|
||||||
table.data[:,data['column'][i]:data['column'][i]+data['dim']].
|
table.data[:,data['column'][i]:data['column'][i]+data['dim']].
|
||||||
reshape([grid[2],grid[1],grid[0]]+data['shape'])))
|
reshape([grid[2],grid[1],grid[0]]+data['shape'])))
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue