diff options
author | Ian Jauslin <ian@jauslin.org> | 2022-05-25 21:42:21 -0400 |
---|---|---|
committer | Ian Jauslin <ian@jauslin.org> | 2022-05-25 21:42:21 -0400 |
commit | 5d92b56c01a79ecbb2df963b4732d0f12687cf75 (patch) | |
tree | 9678116236f7a7d7b0320aabb9b281ac6e32304d | |
parent | a55065f4745f5f340eb6dffbd88fe2fb05a40625 (diff) |
Stabilize algorithm by enforcing real parts
-rw-r--r-- | src/navier-stokes.c | 6 |
1 files changed, 4 insertions, 2 deletions
diff --git a/src/navier-stokes.c b/src/navier-stokes.c index 89bfbbd..e553022 100644 --- a/src/navier-stokes.c +++ b/src/navier-stokes.c @@ -495,7 +495,8 @@ int ns_T( fftw_execute(fft2.fft_plan); // write to ifft for(i=0;i<N1*N2;i++){ - ifft.fft[i]=fft1.fft[i]*fft2.fft[i]; + // control numerical truncation by taking imaginary part (fft1 and fft2 should be purely imaginary) + ifft.fft[i]=-(__imag__ fft1.fft[i])*(__imag__ fft2.fft[i]); } // F(py/|p|*u)*F(qx*|q|*u) @@ -519,7 +520,8 @@ int ns_T( fftw_execute(fft2.fft_plan); // write to ifft for(i=0;i<N1*N2;i++){ - ifft.fft[i]=ifft.fft[i]-fft1.fft[i]*fft2.fft[i]; + // control numerical truncation by taking imaginary part (fft1 and fft2 should be purely imaginary) + ifft.fft[i]=ifft.fft[i]+(__imag__ fft1.fft[i])*(__imag__ fft2.fft[i]); } // inverse fft |