lecture 22
DESCRIPTION
Lecture 22. MA471 Fall 2003. Advection Equation. Recall the 2D advection equation: We will use a Runge-Kutta time integrator and spectral representation in space. Periodic Data. Let’s assume we are given N values of a function f at N data points on the unit interval. - PowerPoint PPT PresentationTRANSCRIPT
Lecture 22
MA471 Fall 2003
Advection Equation
• Recall the 2D advection equation:
• We will use a Runge-Kutta time integrator and spectral representation in space.
0x yC C Ca a
t x y
Periodic Data
• Let’s assume we are given N values of a function f at N data points on the unit interval.
• For instance N=8 on a unit interval:
0 1/8 2/8 3/8 4/8 5/8 6/8 7/8 8/8
Discrete Fourier Transform• We can seek a trigonometric interpolation
of a function f as a linear combination of N (even) trigonometric functions:
• Such that:
/ 22
/ 2 1
ˆk N
ik xk
k N
If x f e
/ 22
/ 2 1
ˆ for 1,...,
where
j
k Nik x
j j kk N
j
f x If x f e j N
jx
N
Transform
• The interpolation formula defines a linear system for the unknown fhat coefficients:
/ 22
/ 2 1
2
1
ˆ for 1,...,
1ˆ for k 1,...,2 2
j
j
k Nik x
j kk N
j Nik x
k jj
f f e j N
N Nf f e
N
Or:
ˆ
ˆ
ifft
fft
f f
f f
Code for the DFT
Code for Inverse
DFT
Fast Fourier Transform
• See handout
Spectral Derivative
• We can differentiate the interpolant by:
/ 22
/ 2 1
ˆ2k N
ik xk
k N
dIfx ik f e
dx
/ 22
/ 2 1
ˆk N
i kxk
k N
If x f e
Detail
• We note that the derivative of the k=(N/2) mode
• is technically:
• However, as we show on the next slide – this mode has turning points at all the data points.
22
2
ˆiN
x
Ne f
22
2
ˆ22
iNx
N
iNe f
Real Component of N/2 Mode
i.e. the slope of the k=(N/2) mode is zeroat all the 8 points..
Modified Derivative Formula
• So we can create an alternative symmetric derivative formula:
/ 2 12
/ 2 1
1 ˆ22
k Nik x
kk N
dIfx ik f e
dx
Spectral Differentiation Scheme
1) Use an fft to compute:
2) Differentiate in spectral space. i.e. compute:
ˆ for 1, 2,..., 1,0,1,...,2 2 2k
N N Nf k
ˆ2 for 1,..., 12 2ˆ
0 for 2
k
k
N Ni k f k
gN
k
cont
3) Then:
4) Summary:a) fft transform data to compute coefficients
b) scale Fourier coefficients c) inverse fft (ifft) scaled coefficients
/ 2
/ 2 1
ˆk N
ikxk
k N
dIfx g e
dx
Final Twist
• Matlab stores the coefficients from the fast Fourier transform in a slightly odd order:
• The derivative matrix will now be a matrix with diagonal entries:
0 1 11 1 2
2 2 22
ˆ ˆ ˆ ˆ ˆ ˆ, ,.., , , , ,...,ˆNN N Nf f ff f f f
2 0,1,.., 1, , 1, 2,..., 12 2 2
N N Ni
0
Spectral Differentiation
Code
1) DFT data2) Scale Fourier
coefficients3) IFT scaled coefficients
Two-Dimensional Fourier Transform
• We can now construct a Fourier expansion in two variables for a function of two variables..
• The 2D inverse discrete transform and discrete transform are:
/ 2/ 22 2
/ 2 1 / 2 1
2 22
1 1
ˆ for , 1,...,
1ˆ for j,k 1,...,2 2
n m
n m
j Nk Nij x ik y
nm jkk N j N
n N m Nij x ik y
jk nmn m
f f e e n m N
N Nf f e e
N
/ 2/ 22 2
/ 2 1 / 2 1
ˆ,j Nk N
ij x ik yjk
k N j N
If x y f e e
Advection Equation
• Recall the 2D advection equation:
• We will use a Runge-Kutta time integrator and spectral representation in space.
0x yC C Ca a
t x y
Runge-Kutta Time Integrator
• We will now discuss a particularly simple Runge-Kutta time integrator introduced by Jameson-Schmidt-Turkel
• The idea is each time step is divided into s substeps, which taken together approximate the update to s’th order.
Side note: Jameson-Schmidt-Turkel Runge-Kutta Integrator
• Taylor’s theorem tell’s us that
• We will compute an approximate update as:
22
1 1* *
1
1 ...1! 2! !
for some ,1 !
ss
s s
s
dt d dt d dt dC t dt C t
dt dt s dt
dt d Ct t t t dt
s dt
22
1 ...1! 2! !
ssdt d dt d dt dC t dt C t
dt dt s dt
JST Runge-Kutta
• The numerical scheme will look like
• We then factorize the polynomial derivative term:
22
221
1 ...1! 2! !
1 ...1! 2! !
ss
ssn n
dt d dt d dt dC t dt C t
dt dt s dt
dt d dt d dt dC C
dt dt s dt
Factorized Scheme
n+1 ..1 2 1
nn n n ndt d dt d dt d dt dC
C C C C Cs dt s dt s dt dt
221 1 ...
1! 2! !
ssn ndt d dt d dt dC C
dt dt s dt
n
n
n+1
Set C=C
for : 1:1
C C
end
C =C
k s
dt dC
k dt
JST + Advection Equation• We now use the PDE definition
n
n
n+1
Set C=C
for : 1:1
C C
end
C =C
k s
dt dC
k dt
+
n
n
n+1
Set C=C
for : 1:1
C C
end
C =C
x y
k s
dt C Ca a
k x y
0x yC C Ca a
t x y
Now Use Spectral Representation
j j
Set
for : 1:1
ˆ = fft
ˆ ˆ
ˆ ˆ
ˆ ifft
ˆ ifft
for j=1,..,N
end
=
x x
y y
x x
y y
x x y yj j j j
k s
dt
k
c c
c c
d D c
d D c
d d
d d
c c a d a d
c c
A time step now consists of s substages.
Each stage involves:
a) Fourier transforming the ctildeusing a fast Fourier transform (fft)
b) Scaling the coefficients to differentiate in Fourier space
c) Transforming the derivatives back tophysical values at the nodes by inverse fast Fourier transform (ifft).
d) Finally updating ctilde according tothe advection equation.
At the end we update the concentration.
Matlab Implementation
• First set up the nodes and the differentiation scalings.
24) Compute dt
26) Initiate concentration
28-29) compute advection vector
32-45) full Runge-Kutta time step
35) fft ctilde
37) x- and y-differentiation in Fourier space
40-41) transform back to physical values of derivatives
43) Update ctilde
sin 2 cos 2
cos 2 sin 2
x
y
a x x
a x x
2 2
200 .75 .6
0
0, ,
x y
x y
C C Ca a
t x y
C t x y e
FFT Resources
• Check out: http://www.fftw.org/ for the fastest Fourier transform in the West
• Great list of links:– http://www.fftw.org/links.html
• FFT for irregularly spaced data:– http://www.math.mu-luebeck.de/potts/nfft/
Lab Exercise
1) Download example DFT code from website.
2) Benchmark codes as a function of N
3) Write your own version using an efficient FFT (say fftw) which:
1) FFT’s data
2) Scales coefficients
3) IFFT’s scaled coeffients
4) Write an advection code using the JST Runge-Kutta time integrator.
This is the scalar version of Project 4