14
2D1290: Advanced Numerical Analysis: 2004 Computer Assignment 3: Recursive Projection Method(RPM) Joakim M ¨ oller 1 PART1: Bratu problem 1.1 Background The Bratu problem in 2D is given by xx u yy u λe u 0 u Γ 0 (1) By use of finite differences the discrete solution can be obtained from the fixed point iteration Au n 1 ij fu n ij A D x D x D y D y fu n ij λe u n ij (2) where D and D are the forward and backward operators in the x- and y-directions. By using that A is a penta-diagonal symmetric positive definite, the solution u n 1 ij can easily be obtain via the Cholesky factorization, A C T C. This only N p 2 3 p 2 flops and N square roots, see [2]. To simplify the notations we write the fixed-point iteration as u n 1 Fu n (3) The ultimate convergence rate depends on the spectral radius of the Jacobian Ju Fu u ρ J max j μ j (4) where μ j j 1 N are the eigenvalues of J , and u is the final solution, u Fu The spectral radius is closely related to the value of the parameter λ, see below 1

1 PART1: Bratu problem - KTH · 1 PART1: Bratu problem 1.1 Background The Bratu problem in 2D is given by ∂xxu ∂yyu λeu 0 uΓ 0 (1) By use of finite differences the discrete

  • Upload
    others

  • View
    26

  • Download
    0

Embed Size (px)

Citation preview

Page 1: 1 PART1: Bratu problem - KTH · 1 PART1: Bratu problem 1.1 Background The Bratu problem in 2D is given by ∂xxu ∂yyu λeu 0 uΓ 0 (1) By use of finite differences the discrete

2D1290: Advanced Numerical Analysis: 2004

Computer Assignment 3: Recursive Projection Method(RPM)

Joakim Moller

1 PART1: Bratu problem

1.1 Background

The Bratu problem in 2D is given by

∂xxu� ∂yyu

� λeu � 0 � uΓ� 0 (1)

By use of finite differences the discrete solution can be obtained from the fixedpoint iteration

Aun � 1i j

� f � uni j � �

A �����D � xD x�

D � yD y �f � un

i j � � λeuni j �

(2)

where D � and D are the forward and backward operators in the x- and y-directions.By using that A is a penta-diagonal symmetric positive definite, the solution un � 1

i j

can easily be obtain via the Cholesky factorization, A � CTC. This only N p2 � 3p2

flops and N square roots, see [2]. To simplify the notations we write the fixed-pointiteration as

un � 1 � F � un � (3)

The ultimate convergence rate depends on the spectral radius of the Jacobian

J � u � � � ∂F � u � �∂u

�ρ � J � � max

jµ j

(4)

where µ j � j � 1 ��������� N are the eigenvalues of J, and u � is the final solution, u � �F � u � � The spectral radius is closely related to the value of the parameter λ, seebelow

1

Page 2: 1 PART1: Bratu problem - KTH · 1 PART1: Bratu problem 1.1 Background The Bratu problem in 2D is given by ∂xxu ∂yyu λeu 0 uΓ 0 (1) By use of finite differences the discrete

2 2.5 3 3.5 4 4.5 5 5.5 6 6.5 70

10

20

30

40

50

60

70

λ

||u(λ

)||

(a)

2 2.5 3 3.5 4 4.5 5 5.5 6 6.5 70

0.5

1

1.5

2

2.5

3

3.5

4

λ

ρ(λ)

(b)

Figure 1: The spectral radius and solution norm (Euclidean) as a function of theparameter λ. The graphs was obtain by using Pseudo-arclength RPM-continuation,see [6].

2

Page 3: 1 PART1: Bratu problem - KTH · 1 PART1: Bratu problem 1.1 Background The Bratu problem in 2D is given by ∂xxu ∂yyu λeu 0 uΓ 0 (1) By use of finite differences the discrete

We see from the solution branch that for each λ-value, there is both a stable andunstable solution. The fixed point iteration can only compute the solutions on thelower part of the branch. Furthermore the convergence rate will approach zero asλ approach 6.80812, the turning point where ρ � J � becomes one.

In order to increase the convergence rate as λ approaches the critical valueand even compute unstable solutions we will use the Recursive Projection Method(RPM), [4], [5], [6].

qn � 1 ��� I � VpVTp � F � pn � qn �

pn � 1 � pn � Vp� I � V T

p JVp � 1V T

p � F � un � � pn �un � 1 � qn � pn

(5)

where pn and qn is the solution projected on the dominant eigenspace, spanned byVp, associated with the p largest eigenvalues, and its orthogonal complement. Thelab consists of 2 parts:

� Part 1, we will investigate a linear PDE to examine some theoretical proper-ties of RPM.

� Part2, we compute the solution of (1) for three different λ-values.

For two λ-values the solution will be stable, whereas in the last case, ρ � J ��� 1and special care has to be taken. The stable cases will be started with a ran-dom initial vector. whereas the last case the initial solution is taken from theupper-part of the branch. Run the Matlab-function u0=initfield(X ,Y ), whereX and Y are two matrices containing the grid-points of your mesh. This func-tion will create the initial data for the internal points of the computational byinterpolation of the data contained in the file init2.mat.

1.1.1 Linear test problem

Implement the RPM-algorithm. The basis extraction is done via the QR-method.Use a Krylov space with 10 vectors. Test RPM with the following linear problem.Use an equal meshing in x and y, where λ � 19 � 6. Nx

� Ny� 32,

∂xxu� ∂yyu

� λ � 1 � u � � f � x � y � �f � x � y � � sin � πx � y � 1 � y � (6)

� Plot the residuals of (3) and pn,qn and of (5)

3

Page 4: 1 PART1: Bratu problem - KTH · 1 PART1: Bratu problem 1.1 Background The Bratu problem in 2D is given by ∂xxu ∂yyu λeu 0 uΓ 0 (1) By use of finite differences the discrete

� Use Arnoldi to compute the 10 largest eigenvalues. Reproduce the the eigen-value plot below for the 10 largest eigenvalues, mark which eigenvalues thatRPM extracted. How do the eigenvalues relate to the convergence plot.

−1 −0.5 0 0.5 1−1

−0.8

−0.6

−0.4

−0.2

0

0.2

0.4

0.6

0.8

110 largest eigenvalues for lambda=19.6

Figure 2: The 10 largest eigenvalues of (3) associated with (6).

� Plot u � x � y � � p � x � y � � q � x � y � , when the solution has converged.

1.2 Non-linear test problem� Run the three test cases given in the table below:

CASE λ � u � 2 initial solution stable

1 6.6650 19.161 rand yes2 6.8029 22.615 rand yes3 6.7 27.287 file no

Table 1: Nonlinear test-cases

In order to obtain convergence for the third case, the unstable eigenvaluemust first be eliminated. Use Arnoldi to compute the unstable eigenvalueand eigenvector. Use this vector to form the first component of the basis Vp,i.e. we will apply RPM directly from the first iteration, and not wait for theQR-method to identify the dominant eigenspace.

� Plot residuals, spectra of the 10 largest eigenvalues and u � x � y � � p � x � y � � q � x � y �when the converge solution.

4

Page 5: 1 PART1: Bratu problem - KTH · 1 PART1: Bratu problem 1.1 Background The Bratu problem in 2D is given by ∂xxu ∂yyu λeu 0 uΓ 0 (1) By use of finite differences the discrete

2 PART 2: Compressible Flow Past a Symmetric Airfoil.

2.1 Background

The governing equations of fluid dynamics are known as the Navier-Stokes equa-tions.

∂∂t� W � � ∂

∂x� f � fv � � ∂

∂y� g � gv � � ∂

∂z� h � hv � � 0 (7)

where t denotes the time. The state-vector W is given by

W �

������

ρρuρvρwρE

������� (8)

and the convective fluxes are defined as

f �

������

ρuρu2 � p

ρuvρuw

u � ρE�

p �

������� � g �

������

ρvρvu

ρv2 � pρvw

v � ρE�

p �

������� � h �

������

ρwρwuρwv

ρw2 � pw � ρE

�p �

������� (9)

Here ρ is the density, u, v and w are the Cartesian velocity components, p is thepressure and E is the total energy. The viscous fluxes are defined as

fv�

������

0τxx

τxy

τxz

� τU � x � qx

������� � gv

������

0τyx

τyy

τyz

� τU � y � qy

������� � hv

������

0τzx

τzy

τzz

� τU � z � qz

������� (10)

with the shear stress tensor τ given by

5

Page 6: 1 PART1: Bratu problem - KTH · 1 PART1: Bratu problem 1.1 Background The Bratu problem in 2D is given by ∂xxu ∂yyu λeu 0 uΓ 0 (1) By use of finite differences the discrete

τxx� 2

3 µ � 2 ∂u∂x� ∂v

∂y� ∂w

∂z �τyy

� 23 µ � � ∂u

∂x�

2 ∂v∂y� ∂w

∂z �τzz

� 23 µ � � ∂u

∂x� ∂v

∂y�

2 ∂w∂z �

τxy� τyx

� µ � ∂v∂x� ∂u

∂y �τxz

� τzx� µ � ∂w

∂x� ∂u

∂z �τyz

� τzy� µ � ∂v

∂z� ∂w

∂y �

(11)

where µ is the viscosity (Stokes hypothesis). The viscous dissipation in the energyequation is calculated from

� τU � x � τxxu� τxyv

� τxzw

� τU � y � τyxu� τyyv

� τyzw

� τU � z � τzxu� τzyv

� τzzw

(12)

and the heat flux due to conduction is calculated according to Fourier’s law,

qx� � k ∂T

∂x

qy� � k ∂T

∂y

qz� � k ∂T

∂z

(13)

where T is the temperature and k the heat conductivity. Assuming a constantPrandtl number (for air Pr � 0 � 72), the heat conductivity can then be found by

k � µcp � Pr

The specific heats at constant volume and constant pressure are constant for acaloric perfect gas, and can be calculated from cv

� R � � γ � 1 � and cp� γcv re-

spectively, with γ � 1 � 4, and R the gas constant, equal to 287 � J � kgK � for air. Toclose the system of equations the pressure p must be related to the state vector W .This relation depends on the model used to describe the thermodynamic propertiesof the gas. For a caloric perfect gas this relation states

p � ρe � γ � 1 � � ρcvT � γ � 1 � � ρRT (14)

6

Page 7: 1 PART1: Bratu problem - KTH · 1 PART1: Bratu problem 1.1 Background The Bratu problem in 2D is given by ∂xxu ∂yyu λeu 0 uΓ 0 (1) By use of finite differences the discrete

0.6

0.8

1

1.2

1.4

1.6

1.8

2

2.2

1 2 3 4 5 6 7 8 9 10−1

0

1

2

3

4

5

Free stream mach−number: M0=1.65

Mach Number

0.4

0.6

0.8

1

1.2

1.4

1 2 3 4 5 6 7 8 9 10−1

0

1

2

3

4

5

Free stream mach−number: M0=0.72

Mach Number

where e is the internal energy. The internal and total energy are related by

e � E � 12� u2 � v2 � w2 � (15)

The equations are discretized using the MacCormack scheme, second order accu-rate.Here we will restrict the simulation to a stationary inviscid 2D flow, that is theviscosity is set to zero. The test case is the the transonic- and supersonic flow overa symmetric airfoil.

0 1 2 3 4 5 6 7 8 9 10

−1

0

1

2

3

4

5

71 x 21 grid

x

y

Figure 3: The Euler mesh.

7

Page 8: 1 PART1: Bratu problem - KTH · 1 PART1: Bratu problem 1.1 Background The Bratu problem in 2D is given by ∂xxu ∂yyu λeu 0 uΓ 0 (1) By use of finite differences the discrete

2.2 Setup

The students will be given a compressible Euler code implemented in matlab. Thetask is to connect the Euler code as a black-box to the RPM code, which will beused to accelerate the convergence. In doing so some alteration of the code mustbe performed.

� rewrite the file NS.m as a function-file of the form

wn � 1 � F � w � mode � nstep � (16)

where w � w � ρ � ρu � ρw� ρE � T for the mass, momentum and energy fluxes.mode is a flag giving information how the function file should operate. Ifmode � 0, do initialization. That is the code should create an initial solutionand set other parameters. In order not to reset all data in every time step,use matlabs save and load of the workspace. Be sure that w is not containedin your saved work space, since this variable is to be sent into the code. Ifmode � 1 compute the solution. The parameter nstep indicates the numberof time steps to be taken with in the code before returning the state vector toRPM.

� RPM works on a vector, whereas the code NS-code work with matrices,hence use the matlab function reshape to alter the structure of w each time itis sent in and out of the code

function w=F(w,mode,nstep)

if mode==0

initialize w

save data

reshape w as a vector

elseif mode==1

load data

reshape w as a matrix

for i=1:nstep

Maccormack scheme

end

save data

8

Page 9: 1 PART1: Bratu problem - KTH · 1 PART1: Bratu problem 1.1 Background The Bratu problem in 2D is given by ∂xxu ∂yyu λeu 0 uΓ 0 (1) By use of finite differences the discrete

reshape w as a vector

end

� The state vector is usually very scew, ρE is usually several order of magni-tudes larger than the other components of the state vector. In order to im-prove the performance of RPM we construct a function that scales the statevector. w=scale(w,flag), where if flag=1 the vector is scaled and if flag=0,the vector is unscaled. Note that the vector should only be scaled withinRPM whereas when sent to F it should be unscaled, hence the structure ofthe function used by RPM, should be of the form

function w=func(w,state,nstep)

w=scale(w,1)

w=F(w,state,nstep)

w=scale(w,0)

Note that the scale function also must be added in the beginning and at theend of the RPM algorithm.

The scaling is done as follows:

ρ � ρρ0

ρu � ρu�

ρ0 p0

ρv � ρv�

ρ0 p0

ρE � ρEγ � 1

2 � γ 1 � p0

(17)

where ρ0 and p0 are the initial density and pressure, and γ � 1 � 4 is the ratiobetween the specific heats for air.

2.3 The lab Exercise� Set the free stream mach-number to 1.65 and run the code. Set the amount

of artificial viscosity in NS to EPS2 = [0.25,0.25]; EPS4 = [0.008,0.008]and a CFL number equal 0.8. A good nstep value is 5. Typical values forthe Krylov acceptance ratio ka is 30 and the size of the Krylov matrix is 10.How does these affect the convergence rate and basis size ?

9

Page 10: 1 PART1: Bratu problem - KTH · 1 PART1: Bratu problem 1.1 Background The Bratu problem in 2D is given by ∂xxu ∂yyu λeu 0 uΓ 0 (1) By use of finite differences the discrete

� Plot the convergence history. How large was the extracted basis ? Plot alsothe convergence history, that is the projected residuals and the total residualPr � un � , Qr � un � , r � un � and compare this with the convergence history for theoriginal problem, that is if RPM is not switched on, see below

0 50 100 150 200 250 30010

−14

10−12

10−10

10−8

10−6

10−4

10−2

100

102

iter

resi

dual

Supersonic wing, M0=1.65

Originalr(u) Pr(u) Qr(u)

Figure 4: The convergence history for case M0� 1 � 65.

Plot solutions, for example the density and its projections, Pρ and Qρ.

� Use eigs (or your own Arnoldi implementation ) to plot the 100 largest eigen-values. Within this plot, plot the eigenvalues of PJP, found by RPM. Alsoplot maybe the to 2 or 3 first eigenvectors of J. Can you see any resemblancebetween these and the solution. To plot the eigenvectors of J, use that

JVy � V Hy�

Ry (18)

where y is an eigenvector of H and hence the vector x � Vy is an approxima-tive eigenvector of J. Note that the eigenvectors might be complex, so givento complex conjugates eigenvectors, the change them to � v� v �� �ℜ � v � � ℑ � v �

10

Page 11: 1 PART1: Bratu problem - KTH · 1 PART1: Bratu problem 1.1 Background The Bratu problem in 2D is given by ∂xxu ∂yyu λeu 0 uΓ 0 (1) By use of finite differences the discrete

� Redo the simulations with some different values for ka and ks, does it effectthe basis.

� Redo the simulation with M0� 0 � 72. Use EPS2 = [0.25,0.25] and EPS4 =

[0.001,0.001] and a CFL number equal 0.8.

3 PART 3 Assignments for experts: Arclength continua-tion with RPM

Heat and mass transfer in porous spherical catalyst where a first-order reactionoccurs is described by a non-linear boundary value problem,

d2ydξ2

� aξ

dydξ

� φ2yexp

�µβ � 1 � y �

1� β � 1 � y ��� � 0 � ξ � 1 (19)

subject to boundary conditions

ξ � 0 � dydξ

� 0 � � 0

ξ � 1 � y � 1 � � 1

For technical purposes usually a plot in η � φ is drawn, where η, the effective-ness factor, is defined as

η � a�

1φ2

dydξ

� ξ � 1 �Assignment: Using RPM, compute the bifurcation diagram, with the parameter

settings a � 2, µ � 60, β � 2 � 5. φ � � 0 � 0 � 16 � . In order to pass the turning point,i.e. when max � λ � � 1, RPM has to be modified. Use the Pseudo-arclength RPM,to handle this task, see [6]. In order for the continuation to work, it might benecessary to update the extracted basis before the computation of the solution at anew φ-value. Use e.g. Arnoldi with DGKS for this purposes, see [4]

In Fig(5), the bifurcation diagram for the parameter setting is shown. We useda second order finite difference scheme explicit in the forcing term and implicit inthe diffusion term. Using 30 grid points, the equation had different solutions. Asthe number of grid points increased, so did the number of solutions Fig(5), herewe used 3000 grid-points, one can at most see 8 solutions around φ � 0 � 111. In[1], one claims that the equation had 15 solutions for this parameter setting. Dueto the lack of memory, one can not continue to refine the grid using second order

11

Page 12: 1 PART1: Bratu problem - KTH · 1 PART1: Bratu problem 1.1 Background The Bratu problem in 2D is given by ∂xxu ∂yyu λeu 0 uΓ 0 (1) By use of finite differences the discrete

methods. Therefore, you should implement a suitable higher order method, to seeif you can reproduce the results of [1].

If you solve this problem, you do not need to solve the other computer assignments.

Good look

12

Page 13: 1 PART1: Bratu problem - KTH · 1 PART1: Bratu problem 1.1 Background The Bratu problem in 2D is given by ∂xxu ∂yyu λeu 0 uΓ 0 (1) By use of finite differences the discrete

0.1 0.105 0.11 0.115 0.12 0.125 0.13 0.135 0.14 0.145 0.151

1.5

2

2.5

3

3.5

4

4.5η(φ)

(a) η � φ-plot

0.1 0.105 0.11 0.115 0.12 0.125 0.13 0.135 0.14 0.145 0.150

2

4

6

8

10

12

max λ(φ)

(b) Max. eigenvalue of the Jacobian

Figure 5: The bifurcation diagram of (19), non-resolved.

13

Page 14: 1 PART1: Bratu problem - KTH · 1 PART1: Bratu problem 1.1 Background The Bratu problem in 2D is given by ∂xxu ∂yyu λeu 0 uΓ 0 (1) By use of finite differences the discrete

References

[1] Childs B., Scott M., Daniel W., Denman E., Nelson P., ’Codes for Boundary-Value Problems in Ordinary Differential Equations’, Lecture Notes in Com-puter Science 76, Springer-Verlag, 1970.

Lecture Notes in Computer S

[2] Golub G., Van Loan C., ’Matrix Computations’, The Johns Hopkins Univer-sity Press, Baltimore, third edition, 1996

[3] Hanke M., ’Lecture Notes: Advanced Numerical Methods’, Royal Instituteof Technology, NADA, February 2000

[4] Moller J.,’Lecture Notes: Eigenvalue problems, and Applications’, Royal In-stitute of Technology, NADA, to appear

[5] Moller J., ’Studies of Recursive projection Methods for Convergence accel-eration of Steady State Calculations.’ TRITA-NA-0119, Royal Institute ofTechnology, Stockholm, Sweden, June 2001

[6] Shroff G. M., Keller B., ’Stabilization of Unstable Procedures: The Recur-sive Projection Method’, SIAM J. Numer. Anal. vol 30, No 4,pp. 1099-1120,August 1993

14