Solving PDE's with chebychev FFT

  • Level: Undergrad 
  • Thread starter Thread starter fahraynk
  • Start date Start date
  • Tags Tags
    Fft Pde
Join the discussion
Registration is free. Start your own thread to ask a follow-up.
11 replies · 4K views · last reply
fahraynk
Messages
185
Reaction score
5
I have seen one lecturer solve a PDE with just using Fast Fourier Transform (##FFT##) of a function ##v## on a chebychev grid. ##v_t=\mu v_x##

This lecturer uses ##FFT## on ##V##, then solves the ODE using an ODE solver in Matlab, then inverse ##FFT## to get the real solution :
$$FFT(v_t)=\hat{v_t}=FFT(\mu v_x)\\
=>\frac{\partial{\hat{v}}}{\partial{t}}=iK\mu \hat{v}$$
##K## is a vector of wave numbers, ##FFT## is fast Fourier transform of a function, ##ifft## is the inverse fast Fourier transform, and ##i## is the imaginary number.

the lecturer solves for ##\hat{v}## with an ODE solver, then inverse Fourier transform to get solution ##v##.

BUT, in the book Spectral Methods for Matlab, the author first transforms the function with ##FFT##, then he calculates the derivative in Fourier space, then the author claims he must transform this back into ##x## space to get the derivative. So, $$\mu \hat{v}_x=\mu iK\hat{v}\\ v_x=-\frac{ifft(\mu iK\hat{v})}{\sqrt{1-x^2}}$$

the ##\sqrt{1-x^2}## comes from chain rule derivative, where the author states when he takes the ##FFT## of the function, it puts the function into ##\theta## space, so to get the x derivative the author has to use chain rule for some reason.

I can't figure out why the methods are different. The only idea I have is maybe the first lecturer's function V is approximately zero at the boundaries, while the Spectral Methods for Matlab author's function is not zero at the boundaries. Could this be the only difference?
 
Physics news on Phys.org
I understand what the lecturer does , and that is standard theory of transforming PDEs to ODEs using Fourier transform.

However I can't quite understand what the book does, and how exactly it uses the chain rule. Can you post screenshots of the respective book pages?
 
Delta² said:
I understand what the lecturer does , and that is standard theory of transforming PDEs to ODEs using Fourier transform.

However I can't quite understand what the book does, and how exactly it uses the chain rule. Can you post screenshots of the respective book pages?
Thanks for your help.

Typeset slide titled Chebyshev spectral differentiation via FFT, listing steps: FFT coefficients v-hat_k, derivative coefficients W-hat_k = ik v-hat_k with W-hat_N = 0, inverse FFT for trigonometric interpolant derivative, and algebraic formulas for interior and endpoint derivatives.

Typeset text with the formula P(theta) = (1/(2pi)) sum from k=-N+1 to N of e^(ik theta) v_k-hat, equal to sum from n=0 to N of a_n cos(n theta).

Typeset page of mathematical text on Chebyshev spectral differentiation, showing the derivative formulas q'(x) with x = cos θ, endpoint derivatives via l'Hôpital's rule, and the second-derivative conversion equation (8.7).


This function outputs the derivative of a grid function v based on the above method :

Octave/MATLAB code listing of a function chebfft(v) that computes a Chebyshev derivative using FFT, with a line-by-line transformation from x to theta and back to x.
 
Attachments
  • Typeset slide titled Chebyshev spectral differentiation via FFT, listing steps: FFT coefficients v-hat_k, derivative coefficients W-hat_k = ik v-hat_k with W-hat_N = 0, inverse FFT for trigonometric interpolant derivative, and algebraic formulas for interior and endpoint derivatives.
    upload_2018-8-5_15-50-53.png
    24.3 KB · Views: 1,082
  • Typeset text with the formula P(theta) = (1/(2pi)) sum from k=-N+1 to N of e^(ik theta) v_k-hat, equal to sum from n=0 to N of a_n cos(n theta).
    upload_2018-8-5_15-50-58.png
    9.5 KB · Views: 1,035
  • Typeset page of mathematical text on Chebyshev spectral differentiation, showing the derivative formulas q'(x) with x = cos θ, endpoint derivatives via l'Hôpital's rule, and the second-derivative conversion equation (8.7).
    upload_2018-8-5_15-51-4.png
    34.2 KB · Views: 1,015
  • Listing of a MATLAB function chebfft.m that computes a Chebyshev differentiation matrix-vector product via FFT, with comments and code lines for the x = cos(pi*j/N) grid and the theta-to-x transform.
    upload_2018-8-5_15-51-10.png
    26.2 KB · Views: 627
  • Octave/MATLAB code listing of a function chebfft(v) that computes a Chebyshev derivative using FFT, with a line-by-line transformation from x to theta and back to x.
    upload_2018-8-5_15-53-21.png
    15.1 KB · Views: 924
  • Printed text describing Program 18, which calls chebfft to compute the Chebyshev derivative of f(x) = e^x sin(5x) for N = 10 and 20 using the FFT, with results given in Output.
    upload_2018-8-5_15-53-26.png
    5.2 KB · Views: 660
I have trouble understanding what the book does (especially the part with the algebraic and trigonometric interpolant of the given data), but I think at the end it calculates the derivative of a known function (given data). It doesn't solve a PDE.
 
Delta² said:
I have trouble understanding what the book does (especially the part with the algebraic and trigonometric interpolant of the given data), but I think at the end it calculates the derivative of a known function (given data). It doesn't solve a PDE.

Yeah, I know, but it is used to solve a pde, ##u_{tt}=u_{xx}##. Author uses leap from in time and chebfft (the program above) twice to approximate the x derivative.

Screenshot of MATLAB code titled Program 19: a Chebyshev-grid solver for the 2nd-order wave equation using a leap frog time-stepping loop, with plotting commands at the end.
 
Attachments
  • Screenshot of MATLAB code titled Program 19: a Chebyshev-grid solver for the 2nd-order wave equation using a leap frog time-stepping loop, with plotting commands at the end.
    upload_2018-8-5_18-17-58.png
    32 KB · Views: 982
Well the book in calculating the derivative for some reason it chooses to work in ##\theta## space (I guess for better accuracy), that is it first does the transform ##x=\cos\theta## and then it calculates ##v'(\theta)## with the aid of FFT, and then it uses the chain rule to calculate for ##v'(x)=v'(\theta)\frac{d\theta}{dx}=v'(\theta)\frac{1}{\sqrt{1-x^2}}##(1).

It doesn't solve a PDE which would involve ##\theta## and ##x## as independent variables.

I guess you interpret equation (1) as some sort of PDE, no it isn't a PDE.
 
Delta² said:
Well the book in calculating the derivative for some reason it chooses to work in ##\theta## space (I guess for better accuracy), that is it first does the transform ##x=\cos\theta## and then it calculates ##v'(\theta)## with the aid of FFT, and then it uses the chain rule to calculate for ##v'(x)=v'(\theta)\frac{d\theta}{dx}=v'(\theta)\frac{1}{\sqrt{1-x^2}}##(1).

It doesn't solve a PDE which would involve ##\theta## and ##x## as independent variables.

I guess you interpret equation (1) as some sort of PDE, no it isn't a PDE.

The program in my last post, program 19, is solving $$\frac{\partial^2 u}{\partial t^2} = \frac{\partial^2 u}{\partial x^2}$$ That is the PDE I am talking about. The author is solving it with leapfrog in ##t## and fft on chebyshev points in ##x##, but the only difference seems to be the ##\sqrt{1-x^2}## term. I don't understand why one author needs this extra term and the other doesn't. Why one author considers it ##\theta## space and the other does not.

The only answer I can think of is maybe the initial condition is zero at the boundaries in one case and not zero in the other case.
 
fahraynk said:
The program in my last post, program 19, is solving $$\frac{\partial^2 u}{\partial t^2} = \frac{\partial^2 u}{\partial x^2}$$ That is the PDE I am talking about. The author is solving it with leapfrog in ##t## and fft on chebyshev points in ##x##, but the only difference seems to be the ##\sqrt{1-x^2}## term. I don't understand why one author needs this extra term and the other doesn't. Why one author considers it ##\theta## space and the other does not.

The only answer I can think of is maybe the initial condition is zero at the boundaries in one case and not zero in the other case.
I am not sure either why the book works with the FFT and iFFT in ##\theta## space (it might had to do with the boundary conditions or for better accuracy in the calculation of the derivative), but that's where the extra term ##\sqrt{1-x^2}## comes from.

The lecturer works in all cases with FFT and iFFT in x-space. The book, inside chebfft(v(x)) works with FFT and iFFT in ##\theta## space not in x-space. so it calculates ##v_{\theta}=iFFT(\mu iK\hat{v})## and then it uses the chain rule ##v_x=v_{\theta}\cdot\frac{d\theta}{dx}##. When ##x=\cos\theta## or equivalently ##\theta=\arccos x## then ##\frac{d\theta}{dx}=\frac{-1}{\sqrt{1-x^2}}##.
 
Delta² said:
I am not sure either why the book works with the FFT and iFFT in ##\theta## space (it might had to do with the boundary conditions or for better accuracy in the calculation of the derivative), but that's where the extra term ##\sqrt{1-x^2}## comes from.

The lecturer works in all cases with FFT and iFFT in x-space. The book, inside chebfft(v(x)) works with FFT and iFFT in ##\theta## space not in x-space. so it calculates ##v_{\theta}=iFFT(\mu iK\hat{v})## and then it uses the chain rule ##v_x=v_{\theta}\cdot\frac{d\theta}{dx}##. When ##x=\cos\theta## or equivalently ##\theta=\arccos x## then ##\frac{d\theta}{dx}=\frac{-1}{\sqrt{1-x^2}}##.

Thanks for your help,
So, if ##iFFT## is in ##\theta##-space, and the author transforms the answer back into ##x##-space, than doesn't that mean the author has to initially transform the data from ##x##-space to ##\theta##-space? But the author starts out with a function defined on a chebyshev grid, and just uses chebfft on it. I don't see where the author originally transforms it from ##x##-space to ##\theta##-space, so I don't understand why he is transforming it back.
 
fahraynk said:
Thanks for your help,
So, if ##iFFT## is in ##\theta##-space, and the author transforms the answer back into ##x##-space, than doesn't that mean the author has to initially transform the data from ##x##-space to ##\theta##-space?

I think it does the transform of data from the x-space to θ - space in the lines from 2 to 4 inside the function chebfft(v), at least that's what I see in the image you uploaded and contains the code for chebfft(v). Inside it defines a new V that contains the transformed data and then it does FFT to V (not to v) , and proceeds with iFFT on the result it gets.
 
  • Like
Likes   Reactions: fahraynk
Delta² said:
I think it does the transform of data from the x-space to θ - space in the lines from 2 to 4 inside the function chebfft(v), at least that's what I see in the image you uploaded and contains the code for chebfft(v). Inside it defines a new V that contains the transformed data and then it does FFT to V (not to v) , and proceeds with iFFT on the result it gets.
Thanks again,

Interesting point, I think you're talking about this :

$$v=v(:)\\
V=[v;flipud(v(2:N))];$$

I thought those 2 lines just makes the grid function periodic, although I admit I don't fully understand why he did this!

If I take those lines out and just set : $$w=iFFT(i*K*FFT(v))$$, do you think it would be the same solution? I wonder why this "transform" makes the equation more accurate when he is already using chebychev grid points, what good does it do making it periodic with some weird flipping function (flipud)...
 
  • Like
Likes   Reactions: Delta2
It is a mystery to me too why it choses to work in θ -space .

If you take out those lines and proceed as you say, I don't think you ll get exactly the same solution but approximately the same solution maybe. You will also have to remove the line that applies the chain rule (line 8 or 9), otherwise you ll get totally different solutions.