Updating the solution in Fourier space (Assignment 6)

Updating the solution in Fourier space (Assignment 6)

par Christian DiMaria,
Nombre de réponses : 6

I've been running into trouble updating the solution in Fourier space during the diffusion sub-step. Basically for each timestep, I do the following:

  1. Reaction substep using the exact solution in the assignment description
  2. Forward FFT on the output of step 1
  3. Update the solution in Fourier space with u^(k,t+1) = u^(k,t)exp(-k*k*dt)
  4. Inverse Fourier transform (scaled by N) on the output of step 3

If I run my code without doing Step 3, I just get the solution to the reaction equation, since step 4 just cancels out step 2 in this case (i.e., I get the vector u scaled by u.size() if I apply forward and then inverse FFT without doing the update in step 3). But when I include the update in Step 3, my solution looks like nonsense for all t>0 (basically just oscillating rapidly around zero with very small amplitude).

My approach for that step was to loop over all elements in u^, corresponding to each k-value, like this:

for(int i = 0; i < uhat.size(); i++){

uhat[i] *= exp(-1.0*k[i]*k[i]*dt);

}

where k is a vector containing 2*pi*q/L for -N/2 <= q < N/2. I assumed that uhat[i] corresponds to the k-value stored at k[i] since they are both the same size, but maybe this is not correct and could be the cause of my problems.

En réponse à Christian DiMaria

Re: Updating the solution in Fourier space (Assignment 6)

par Ramses van Zon,
What routine from fftw did you use to perform the Fourier transform?
En réponse à Ramses van Zon

Re: Updating the solution in Fourier space (Assignment 6)

par Christian DiMaria,
I used the real-to-complex routine for the forward transform: fftw_plan_dft_r2c_1d
And then I used the complex-to-real routine for the inverse transform: fftw_plan_dft_c2r_1d

I'm not sure if those were the correct choices, but I did some testing just to make sure that if I take the forward transform of U then take the inverse transform of that, I recover the original vector scaled by the length N.
En réponse à Christian DiMaria

Re: Updating the solution in Fourier space (Assignment 6)

par Ramses van Zon,
That should work. When you transform back, you divide by N in every step, right?
En réponse à Ramses van Zon

Re: Updating the solution in Fourier space (Assignment 6)

par Ramses van Zon,
Also, I presume your u^ is complex valued with half the number of elements of u?
En réponse à Ramses van Zon

Re: Updating the solution in Fourier space (Assignment 6)

par Christian DiMaria,
I divide by N in every step when I transform back, but I just checked and my u^ vector has too many elements. It is complex valued but has the same number of elements as u, since I just allocated it as rvector<complex> uhat(N) at the beginning of my program. This is probably where my issue is coming from.
En réponse à Christian DiMaria

Re: Updating the solution in Fourier space (Assignment 6)

par Ramses van Zon,
I believe the length should by N/2 + 1 (see documentation), but yes, this could be the issue.