Skip to content

Commit

Permalink
Fix Fourier NCC bug with rescaled domains by casting wavenumbers to i…
Browse files Browse the repository at this point in the history
…nt before computing coupling
  • Loading branch information
kburns committed Sep 22, 2023
1 parent 2363ae4 commit cf4db46
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 7 deletions.
16 changes: 10 additions & 6 deletions dedalus/core/basis.py
Original file line number Diff line number Diff line change
Expand Up @@ -1008,12 +1008,14 @@ def valid_elements(self, tensorsig, grid_space, elements):
@CachedMethod
def product_matrix(self, arg_basis, out_basis, i):
# Directly compare wavenumber arrays to handle any permutations
k_ncc = self.wavenumbers[i]
k_out = out_basis.wavenumbers
# First turn them into integer mode numbers to avoid floating point issues
k0 = self.wavenumbers[1]
k_ncc = np.round(self.wavenumbers[i]/k0).astype(int)
k_out = np.round(out_basis.wavenumbers/k0).astype(int)
if arg_basis is None:
k_arg = np.array([0])
else:
k_arg = arg_basis.wavenumbers
k_arg = np.round(arg_basis.wavenumbers/k0).astype(int)
k_prod = k_arg + k_ncc
_, rows, cols = np.intersect1d(k_out, k_prod, assume_unique=True, return_indices=True)
data = np.ones_like(rows)
Expand Down Expand Up @@ -1160,12 +1162,14 @@ def valid_elements(self, tensorsig, grid_space, elements):
@CachedMethod
def product_matrix(self, arg_basis, out_basis, i):
# Directly compare wavenumber arrays to handle any permutations
k_ncc = self.wavenumbers[i]
k_out = out_basis.wavenumbers
# First turn them into integer mode numbers to avoid floating point issues
k0 = self.wavenumbers[2]
k_ncc = np.round(self.wavenumbers[i]/k0).astype(int)
k_out = np.round(out_basis.wavenumbers/k0).astype(int)
if arg_basis is None:
k_arg = np.array([0])
else:
k_arg = arg_basis.wavenumbers
k_arg = np.round(arg_basis.wavenumbers/k0).astype(int)
# Skip multiplication by constant
if k_ncc == 0:
if i % 2 == 0:
Expand Down
2 changes: 1 addition & 1 deletion dedalus/tests/test_cartesian_ncc.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ def test_eval_jacobi_ncc(N, a0, b0, k_ncc, k_arg, dealias, dtype):
assert np.allclose(w2['c'][:-2*k_arg], 0)


@pytest.mark.parametrize('N', [16])
@pytest.mark.parametrize('N', [24])
@pytest.mark.parametrize('dealias', [3/2])
@pytest.mark.parametrize('dtype', [np.float64, np.complex128])
def test_eval_fourier_ncc(N, dealias, dtype):
Expand Down

0 comments on commit cf4db46

Please sign in to comment.