numerical methods for partial d-math differential ... · mufinal = radtevl(u0,mesh,tfinal,m) that...

24
R. Hiptmair L. Scarabosio E. Fonn Spring Term 2013 Numerical Methods for Partial Differential Equations ETH Z¨ urich D-MATH Homework Problem Sheet 11 Introduction. Problem 11.1 Parabolic Evolution Problem (Core problem) Let R 2 and the time-dependent function u : [0,T ] H 1 (Ω) solve the following variational formulation of an evolution problem posed on the space-time cylinder × [0,T ]: grad u(x,t) · grad v(x)dx + d dt u(x,t)v(x)dS (x)=0 v H 1 (Ω), u(x, 0) = u 0 (x) x . (11.1.1) Note that the bilinear form with the time derivative in front is an integral over the boundary . (11.1a) Show that t 7→|u(·,t)| H 1 (Ω) is non-increasing. HINT: You can take for granted that v = ∂t u is a valid test function for the variational equation in (11.1.1). Solution: By the chain rule and symmetry we have 1 2 d dt |u| 2 H 1 (Ω) = 1 2 d dt (grad u, grad u) L 2 (Ω) = (grad u, grad u t ) L 2 (Ω) = - d dt u 2 dS 0, where in the last step we used that u is a solution to (11.1.1) with v = u t as test function. (11.1b) The spatial Galerkin semi-disretization of (11.1.1) results in an ordinary differential equation (ODE) of the form A μ(t)+ B d dt μ(t)=0, μ(t)= μ 0 . (11.1.2) What are the formulas for the entries of the matrices A and B, if the basis { b j N } N j =1 , of the N -dimensional trial and test space V N H 1 (Ω) is used? Solution: The formulas can be read straight from (11.1.1): A i,j = grad b i N (x) · grad b j N (x)dx, B i,j = b i N (x)b j N (x)dx. (11.1c) Which properties of the matrices A and B introduced in subproblem (11.1b) are en- sured regardless of the choice of the trial and test space V N and of the basis { b j N } N j =1 ? Solution: The matrices are symmetric and at least positive semi-definite. A could be singular because we work with H 1 and not H 1 0 , and B could be singular because the integral is just over the boundary. Problem Sheet 11 Page 1 Problem 11.1

Upload: others

Post on 07-Jul-2020

25 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Numerical Methods for Partial D-MATH Differential ... · mufinal = RadTEvl(u0,mesh,Tfinal,m) that carries out m uniform timesteps of the L-stable SDIRK-2 implicit 2-stage Runge-Kutta

R. HiptmairL. ScarabosioE. Fonn

Spring Term 2013

Numerical Methods for PartialDifferential Equations

ETH ZurichD-MATH

Homework Problem Sheet 11

Introduction.

Problem 11.1 Parabolic Evolution Problem (Core problem)Let Ω ⊂ R2 and the time-dependent function u : [0, T ] → H1(Ω) solve the following variationalformulation of an evolution problem posed on the space-time cylinder Ω× [0, T ]:∫

Ω

gradu(x, t) · grad v(x) dx+d

dt

∫∂Ω

u(x, t)v(x) dS(x) = 0 ∀v ∈ H1(Ω),

u(x, 0) = u0(x) ∀x ∈ Ω.

(11.1.1)

Note that the bilinear form with the time derivative in front is an integral over the boundary ∂Ω.

(11.1a) Show that t 7→ |u(·, t)|H1(Ω) is non-increasing.

HINT: You can take for granted that v = ∂∂tu is a valid test function for the variational equation

in (11.1.1).

Solution: By the chain rule and symmetry we have

1

2

d

dt|u|2H1(Ω) =

1

2

d

dt(gradu, gradu)L2(Ω) = (gradu, gradut)L2(Ω) = −

∫∂Ω

∣∣∣∣ ddtu∣∣∣∣2 dS ≤ 0,

where in the last step we used that u is a solution to (11.1.1) with v = ut as test function.

(11.1b) The spatial Galerkin semi-disretization of (11.1.1) results in an ordinary differentialequation (ODE) of the form

Aµ(t) +Bd

dtµ(t) = 0, µ(t) = µ0. (11.1.2)

What are the formulas for the entries of the matrices A and B, if the basisbjN

N

j=1, of the

N -dimensional trial and test space VN ⊂ H1(Ω) is used?

Solution: The formulas can be read straight from (11.1.1):

Ai,j =

∫Ω

grad biN(x) · grad bjN(x)dx, Bi,j =

∫∂Ω

biN(x)bjN(x)dx.

(11.1c) Which properties of the matrices A and B introduced in subproblem (11.1b) are en-sured regardless of the choice of the trial and test space VN and of the basis

bjN

N

j=1?

Solution: The matrices are symmetric and at least positive semi-definite. A could be singularbecause we work with H1 and not H1

0 , and B could be singular because the integral is just overthe boundary.

Problem Sheet 11 Page 1 Problem 11.1

Page 2: Numerical Methods for Partial D-MATH Differential ... · mufinal = RadTEvl(u0,mesh,Tfinal,m) that carries out m uniform timesteps of the L-stable SDIRK-2 implicit 2-stage Runge-Kutta

(11.1d) Now we focus on the specific choice VN = S01 (M), M a triangular mesh of Ω, for the

Galerkin finite element semi-discretization of (11.1.1).

Which difficulty is encountered when trying to solve the resulting ODE of the form (11.1.2) bymeans of the explicit Euler time-stepping scheme?

Solution: The explicit Euler time-stepping scheme turns out to take on the form

Bµn+1 = (B − τA)µ(n).

The problem with this is that the matrix B will generally not be nonsingular, so this systemprobably (for most µ(n)) has no solution, and certainly not a unique solution.

(11.1e) SDIRK-2 time-stepping is an L-stable implicit 2-stage Runge-Kutta method describedby the Butcher tableau

λ λ 01 1− λ λ

1− λ λ, λ := 1− 1

2

√2 > 0. (11.1.3)

Which equations have to be solved in every timestep, when SDIRK-2 with timestep τ > 0 isapplied to the ODE (11.1.2)?

Solution: Formulas [NPDE, Eq. (6.1.28)] gives us two systems of equations which we have tosolve for the unknown vectors k1, k2

(B + τλA)k1 = −Aµ,

(B + τλA)k2 = −A(µ+ τ(1− λ)k1).

Then [NPDE, Eq. (6.1.29)] gives us an update formula for µ

µj+1 = µj + τ(1− λ)k1 + τλk2.

(11.1f) Why is SDIRK-2 for (11.1.2) feasible for any timestep τ > 0, any trial and test spaceVN = 0 and any choice of its basis?

HINT: You have to show that the linear systems of equations to be solved to obtain the Runge-Kutta increments always have a solution.

Solution: We show that the bilinear form corresponding to the matrix B + λτA is symmetricpositive definite. Clearly, since λτ > 0,∫

∂Ω

u2(x)dx+ λτ

∫Ω

∥gradu(x)∥2 dx ≥ 0

for all u ∈ H1(Ω), so the form is positive. If this should equal zero, both integrals will equalzero. This means that u must be constant (gradient zero everywhere) and zero on the boundary,thus zero everywhere. This shows that the form is positive definite. It is clearly symmetric.

(11.1g) Implement a LehrFEM MATLAB function

function [A,B] = compGalMats(mesh)

Problem Sheet 11 Page 2 Problem 11.1

Page 3: Numerical Methods for Partial D-MATH Differential ... · mufinal = RadTEvl(u0,mesh,Tfinal,m) that carries out m uniform timesteps of the L-stable SDIRK-2 implicit 2-stage Runge-Kutta

that computes the Galerkin matrices A and B introduced in subproblem (11.1b) for the trial andtest space VN = S0

1 (M) equipped with the standard nodal basis. Here M is a triangular mesh ofΩ passed as argument mesh (a LehrFEM mesh data type complete with edge information).

Solution: See Listing 11.1.

Listing 11.1: Implementation for compGalMats.1 f u n c t i o n [A,B] = compGalMats(mesh)2

3 A = assemMat_LFE(mesh, @STIMA_Lapl_LFE);4 B = assemMat_Bnd_Robin(mesh, @(x,varargin)

ones( s i z e(x,1),1), 4);5

6 end

(11.1h) Implement a MATLAB function

mufinal = RadTEvl(u0,mesh,Tfinal,m)

that carries out m uniform timesteps of the L-stable SDIRK-2 implicit 2-stage Runge-Kuttamethod from (11.1.3) of subproblem (11.1e). Spatial discretization should rely on VN = S0

1 (M),M a triangular mesh of Ω passed as argument mesh (a LehrFEM mesh data type complete withedge information). The column vector u0 supplies the initial value µ0 ∈ RN , N := dimVN ,Tfinal the end time T . The function should return an approximation of u(x, t) for t = T in theform of a coefficient (column) N -vector mufinal with respect to the nodal basis of the finiteelement space.

HINT: A scrambled MATLAB implementation of compGalMats from subproblem (11.1g) isavailable in the file compGalMats ref.p.

Solution: See Listing 11.2.

Listing 11.2: Implementation for RadTEvl.1 f u n c t i o n mufinal = RadTEvl(u0, mesh, Tfinal, m)2

3 % Get matrices

4 [A, B] = compGalMats(mesh);5

6 % Time step and other parameters

7 tau = Tfinal / m;8 lam = 1-1/ s q r t(2);9

10 % Time stepping

11 f o r i = 1:m12 k1 = (B+lam*tau*A) \ (-A*u0);13 k2 = (B+lam*tau*A) \ (-A*(u0 + (1-lam)*tau*k1));14 u0 = u0 + (1-lam)*tau*k1 + lam*tau*k2;15 end16

Problem Sheet 11 Page 3 Problem 11.1

Page 4: Numerical Methods for Partial D-MATH Differential ... · mufinal = RadTEvl(u0,mesh,Tfinal,m) that carries out m uniform timesteps of the L-stable SDIRK-2 implicit 2-stage Runge-Kutta

17 % Output

18 mufinal = u0;19

20 end

(11.1i) Copy your implementation of RadTEvl from subproblem (11.1h) to a file RadTEvlNorm.mand extend it to a function

[mufinal,H1seminorms] = RadTEvlNorm(u0,mesh,Tfinal,m),

which is supposed to return approximations of |u(·, tl)|H1(Ω), tl := l Tm

, l = 0, . . . ,m, in the col-umn vector H1seminorms, in addition to an approximate solution at final time. The argumentsof the function are explained in subproblem (11.1h).

Solution: We can use the matrix A to compute the H1-seminorm. See Listing 11.3.

Listing 11.3: Implementation for RadTEvlNorm.1 f u n c t i o n [mufinal, H1seminorms] = RadTEvlNorm(u0, mesh,

Tfinal, m)2

3 % Get matrices

4 [A, B] = compGalMats(mesh);5

6 % Time step and other parameters

7 tau = Tfinal / m;8 lam = 1-1/ s q r t(2);9

10 % Time stepping

11 H1seminorms = z e r o s(1,m+1);12 H1seminorms(1) = s q r t(u0’ * A * u0);13 f o r i = 1:m14 k1 = (B+lam*tau*A) \ (-A*u0);15 k2 = (B+lam*tau*A) \ (-A*(u0 + (1-lam)*tau*k1));16 u0 = u0 + (1-lam)*tau*k1 + lam*tau*k2;17 H1seminorms(i+1) = abs( s q r t(u0’ * A * u0));18 end19

20 % Output

21 mufinal = u0;22

23 end

(11.1j) Write a MATLAB script

plotenergyevolution

that plots the approximate values for |u(·, tl)|H1(Ω), tl := l Tm

, l = 0, . . . ,m versus time.

Problem Sheet 11 Page 4 Problem 11.1

Page 5: Numerical Methods for Partial D-MATH Differential ... · mufinal = RadTEvl(u0,mesh,Tfinal,m) that carries out m uniform timesteps of the L-stable SDIRK-2 implicit 2-stage Runge-Kutta

0 1 2 3 4 5 610

−3

10−2

10−1

100

101

102

Time

H1 s

emin

orm

Figure 11.1: Decay of the energy in subproblem (11.1j).

Use the initial function u(x) = sin(30x1) + sin(30x2), T = 6, m = 200 and mesh read fromCoord Circ.dat and Elem Circ.dat.

Choose a suitable plot that reveals a potential exponential decay of t 7→ |u(·, tl)|H1(Ω).

HINT: A scrambled reference implementation of RadTEvlNorm is supplied in the file RadTEvlNorm ref.p.

Solution: See Listing 11.4 for the code and Figure 11.1 for the plot.

Listing 11.4: Implementation for plotenergyevolution.1 mesh = load_Mesh(’Coord_Circ.dat’, ’Elem_Circ.dat’);2 mesh = add_Edges(mesh);3 loc = get_BdEdges(mesh);4 mesh.BdFlags = z e r o s( s i z e(mesh.Edges,1),1);5 mesh.BdFlags(loc) = -1;6

7 u0 = s i n(30*mesh.Coordinates(:,1)) +s i n(30*mesh.Coordinates(:,2));

8 [ufin, norms] = RadTEvlNorm(u0, mesh, 6, 200);9

10 f i g u r e(1); c l f ;11 semi logy( l i n s p a c e(0,6,201), norms, ’LineWidth’, 2);12 gr id on;13 x l a b e l(’Time’); y l a b e l(’Hˆ1 seminorm’);

Listing 11.5: Testcalls for Problem 11.11 c l e a r a l l ;2

3 mesh.Coordinates = [0 0; 1 0; 1 1; 0 1];4 mesh.Elements = [1 2 4; 2 3 4];5 mesh = add_Edges(mesh);

Problem Sheet 11 Page 5 Problem 11.1

Page 6: Numerical Methods for Partial D-MATH Differential ... · mufinal = RadTEvl(u0,mesh,Tfinal,m) that carries out m uniform timesteps of the L-stable SDIRK-2 implicit 2-stage Runge-Kutta

6 loc = get_BdEdges(mesh);7 mesh.BdFlags = z e r o s( s i z e(mesh.Edges,1),1);8 mesh.BdFlags(loc) = -1;9 [A,B] = compGalMats(mesh);

10 f p r i n t f(’## compGalMats\n’);11 round( f u l l (2*A))12 round( f u l l (6*B))13

14 u = [2; 0.5; 0.5; 1];15 mf = RadTEvl(u, mesh, 1, 5);16 f p r i n t f(’## RadTEvl\n’);17 mf’18

19 [mf,errs] = RadTEvlNorm(u, mesh, 1, 5);20 f p r i n t f(’## RadTEvlNorm\n’);21 mf’22 errs

Listing 11.6: Output for Testcalls for Problem 11.11 ## compGalMats2

3 ans =4

5 2 -1 0 -16 -1 2 -1 07 0 -1 2 -18 -1 0 -1 29

10 ans =11

12 4 1 0 113 1 4 1 014 0 1 4 115 1 0 1 416

17 ## RadTEvl18

19 ans =20

21 1.1668 0.9441 0.8340 1.055122

23 ## RadTEvlNorm24

25 ans =26

27 1.1668 0.9441 0.8340 1.055128

29 errs =30

Problem Sheet 11 Page 6 Problem 11.1

Page 7: Numerical Methods for Partial D-MATH Differential ... · mufinal = RadTEvl(u0,mesh,Tfinal,m) that carries out m uniform timesteps of the L-stable SDIRK-2 implicit 2-stage Runge-Kutta

31 1.3229 0.8499 0.6145 0.4533 0.3353 0.2481

Problem 11.2 Parabolic Evolution Problem on Quadrilateral MeshOn the spatial domain Ω = (0, 1)2 we consider the parabolic initial boundary value problem

∂u

∂t−∆u = f on Ω× (0, T ),

u = 0 on ∂Ω× (0, T ),

u(·, 0) = u0 in Ω,

(11.2.1)

where the initial data u0 and the source function f = f(x, t) are given.

For the spatial finite element Galerkin discretization of (11.2.1) we employ parametric bilinearLagrangian finite elements on general quadrilateral meshes like the one depicted in Figure 11.2.

Figure 11.2: Example of a general quadrilateral mesh

(11.2a) Derive the spatial variational formulation of the parabolic evolution problem (11.2.1).

Solution: We multiply with a test function v(x), and integrate over the spacial domain Ω toobtain ∫

Ω

u v dx−∫Ω

∆u v dx =

∫Ω

fv dx,∫Ω

u v dx+

∫Ω

grad u · grad v dx−∫∂Ω

v grad u · n dx =

∫Ω

fv dx.

Since we have homogeneous Dirichlet boundary conditions, we require v = 0 on ∂Ω, so theboundary integral will vanish. What remains is

d

dtm(u, v) + a(u, v) = ℓ(v), (11.2.2)

where

Problem Sheet 11 Page 7 Problem 11.2

Page 8: Numerical Methods for Partial D-MATH Differential ... · mufinal = RadTEvl(u0,mesh,Tfinal,m) that carries out m uniform timesteps of the L-stable SDIRK-2 implicit 2-stage Runge-Kutta

m(u, v) =

∫Ω

u(x)v(x)dx, a(u, v) =

∫Ω

grad u(x)·grad v(x)dx, ℓ(v) =

∫Ω

f(x)v(x)dx.

The formulation (11.2.2) is time-dependent and should hold for all u(·, t), v ∈ H10 (Ω).

(11.2b) Give the formula of a bilinear transformation ΦK : K 7→ K that takes the unit squareK = (0, 1)2 to a general quadrilateral with the vertices a1,a2,a3,a4 ∈ R2 (numbered counter-clockwise, see Figure 11.3).

x1h

x2h

a1 a2

a4 a3

Phi

mapping

US PG

bilinear1

2

3

4

PSfrag replacementsx1

x2

a1

a2

a3

a4

a1

a2

a3

a4

ΦK

unit squaregeneral quadrilateral

Figure 11.3: Bilinear mapping taking the unit square to a general quadrilateral

Solution: Such a function is (see [NPDE, Ex. 3.6.20])

ΦK(x) = a1 + x1(a2 − a1) + x2(a

4 − a1) + x1x2(a1 − a2 + a3 − a4). (11.2.3)

(11.2c) We write bi, i = 1, . . . , 4, for the bilinear local shape functions on K and biK :=

(Φ−1K )∗bi for those on the generic quadrilateral K. Show that

gradx biK(x) = M(Φ−1

K (x))−⊤ gradx bi(Φ−1

K (x)), (11.2.4)

with a R2×2-valued function

M(x) :=(x2(a

1 − a2 + a3 − a4) + (a2 − a1), x1(a1 − a2 + a3 − a4) + (a4 − a1)

).

(11.2.5)

Solution: According to [NPDE, Lem. 3.6.16], we have

gradx biK(x) = DΦK(x)

−⊤ gradx bi(x).

To compute DΦK(x), we differentiate (11.2.3) with respect to x1 and x2.

∂x1

ΦK(x) = a2 − a1 + x2(a1 − a2 + a3 − a4),

∂x2

ΦK(x) = a4 − a1 + x1(a1 − a2 + a3 − a4).

So we see that (11.2.4) is indeed correct, with M(Φ−1K (x)) = M(x) = DΦK(x).

Problem Sheet 11 Page 8 Problem 11.2

Page 9: Numerical Methods for Partial D-MATH Differential ... · mufinal = RadTEvl(u0,mesh,Tfinal,m) that carries out m uniform timesteps of the L-stable SDIRK-2 implicit 2-stage Runge-Kutta

1 2

34

K1

K2

PSfrag replacements

a1

a2

a3

a4

K1

K2

Figure 11.4: A split quadrilateral.

(11.2d) A convex quadrilateral with vertices a1,a2,a3,a4 ∈ R2 (numbered counterclockwise)can be split into two triangles with vertices a1,a2,a3 and a1,a3,a4. The piecewise linear “tentfunctions” associated with the vertices of these triangles can serve as local shape functions on thequadrilateral.

Relying on the LehrFEM-MATLAB function STIMA Lapl LFE, which computes the elementstiffness matrix for −∆ and triangular linear Lagrangian finite elements, complete the LehrFEM-MATLAB function

function Aloc = STIMA Lapl BFEsplit(Vertices,varargin)

that computes the element matrix corresponding to the bilinear form a∆(u, v) :=∫Ωgradu ·

grad v dx based on the piecewise linear local shape function described above.

Here, the 2× 4 matrix Vertices passes the coordinates of a1,a2,a3,a4, whereas the variablevarargin can be ignored.

Solution:

Listing 11.7: STIMA Lapl BFEsplit.m

1 f u n c t i o n Aloc = STIMA_Lapl_BFEsplit(Vertices,varargin)2

3 % Preallocate memory

4

5 Aloc = z e r o s(4,4);6

7 % Add in element contributions

8

9 vidx = [1, 2, 3];10 Aloc(vidx,vidx) = Aloc(vidx,vidx) +

STIMA_Lapl_LFE(Vertices(vidx,:));

Problem Sheet 11 Page 9 Problem 11.2

Page 10: Numerical Methods for Partial D-MATH Differential ... · mufinal = RadTEvl(u0,mesh,Tfinal,m) that carries out m uniform timesteps of the L-stable SDIRK-2 implicit 2-stage Runge-Kutta

11

12 vidx = [1, 3, 4];13 Aloc(vidx,vidx) = Aloc(vidx,vidx) +

STIMA_Lapl_LFE(Vertices(vidx,:));14

15 end

(11.2e) Calculate a tight bound for the number of non-zero entries of the stiffness matrix for −∆(with homogeneous Dirichlet boundary conditions) discretized by means of paremetric bilinearLagrangian finite elements on a general quadrilateral mesh. The bound should be stated in termsof the numbers of cells, (interior) edges, and (interior) vertices of the mesh.

Solution: For every interior node i, there will be a nonzero element Ai,i. For almost everyinterior edge (i, j), there can be two nonzero elements Ai,j and Aj,i. Finally, for every cell(i, j, k, l) there will be at most another four nonzero elements Ai,k, Ak,i, Aj,l and Al,j .

Since a matrix element Ai,j will definitely be zero if i = j and nodes i, j do not share an edge ora cell, a good upper bound is

NNZ ≤ N + 2E + 4C,

where N is the number of interior nodes, E is the number of interior edges and C is the numberof cells.

(11.2f) With stiffness matrix A and mass matrix M we can formally write the spatially semi-discrete version of (11.2.1) as

Mdµ

dt(t)−Aµ(t) = φ(t), µ(0) = µ0. (11.2.6)

State a fully discrete version that uses implicit Euler timestepping with uniform timestep τ > 0.

Solution: The implicit Euler method is given by

M

τ

(µ(n+1) − µ(n)

)+Aµ(n+1) = φ(tn+1),

or(M+ τA)µ(n+1) = τφ(tn+1) +Mµ(n).

(11.2g) Explain why it is not advisable to use explicit Runge-Kutta single-step timesteppingmethods for (11.2.6) with a spatial discretization with piecewise linear Langrangian finite ele-ments.

Solution: Explicit Runge-Kutta methods face a CFL-condition, that is, the size of the timestep ishas to be smaller than a bound that decreases with (some power of) the meshwidth. In the case oflow-order spatial discretization, for instance, by means of (bi-)linear Lagrangian finite elements,stability enforces timesteps way smaller than what would be required to balance the accuracy ofspatial and temporal discretization. This ultimately renders the method inefficient. See [NPDE,Sect. 6.1.4.3] for details.

(11.2h) Implement the timestepping scheme from subproblem (11.2f) in

u = Parb Evl BFE(Mesh,u0,FHandle,T,Nsteps),

Problem Sheet 11 Page 10 Problem 11.2

Page 11: Numerical Methods for Partial D-MATH Differential ... · mufinal = RadTEvl(u0,mesh,Tfinal,m) that carries out m uniform timesteps of the L-stable SDIRK-2 implicit 2-stage Runge-Kutta

where Mesh is a LehrFEM mesh data structure for a quadrilateral mesh, u0 the coefficient vectorfor the intial data, FHandle of type @(x,t) passes the time-dependent right-hand side, T givesthe final time, and Nsteps the number of timesteps. The function is to return the finite elementsolution at final time (encoded by its basis coefficients, of course).

Parts of the code that compute the matrices A and M are already supplied. The function assemLoad BFEcan be used to obtain φ(t).

HINT: Further information can be found in the comments inside the function template. You mayuse the reference implementations of the MATLAB functions from earlier subproblems, in caseyou do not trust your implementations.

Solution:

Listing 11.8: Parb Evl BFE.m

1 f u n c t i o n u = Parb_Evl_BFE(Mesh,u0,FHandle,T,Nsteps)2

3 % Initialize quadrature rules

4 QuadRule = TProd(gauleg(0,1,4));5

6 % Compute matrices

7 M = assemMat_BFE(Mesh,@MASS_BFE,QuadRule);8 A = assemMat_BFE(Mesh,@STIMA_Lapl_BFE,QuadRule);9

10 % Compute time steps

11 dt = T/Nsteps;12

13 % Compute matrices

14 S1 = M + dt*A;15 S2 = M;16

17 % Isolate free nodes

18 [temp, FreeDofs] = assemDir_BFE(Mesh,-1, @(x,varargin)z e r o s( s i z e(x,1),1));

19

20 % Start time stepping

21 f o r i = 1:Nsteps22

23 % Assemble load vector

24 L_new =assemLoad_BFE(Mesh,QuadRule,@(x,varargin)FHandle(x,i*dt));

25 rhs = S2*u0 + dt*L_new;26

27 % Solve the linear system

28 u_new = z e r o s( s i z e(u0));29 u_new(FreeDofs) = S1(FreeDofs,FreeDofs)\rhs(FreeDofs);30

31 % Update vectors

32 u0 = u_new;

Problem Sheet 11 Page 11 Problem 11.2

Page 12: Numerical Methods for Partial D-MATH Differential ... · mufinal = RadTEvl(u0,mesh,Tfinal,m) that carries out m uniform timesteps of the L-stable SDIRK-2 implicit 2-stage Runge-Kutta

33

34 end35

36 u = u0;37

38 end

(11.2i) For u0(x) = sin(πx1) sin(πx2), f ≡ 0 we find the exact solution

u(x, t) = e−2π2t sin(πx1) sin(πx2), (x0, x1)⊤ ∈ Ω = (0, 1)2. (11.2.7)

for (11.2.1). Extend the MATLAB script main BFE.m to study the convergence (qualitativelyand quantitatively) of the spatial discretization on a sequence of regularly refined quadrilateralmeshes. To that end examine the discretization error ∥uN(T )− u(T )∥L2(Ω) for final time T = 0.1.Choose the timestep small enough such that the temporal discretization error will never dominate.What rate of convergence do you observe?

HINT: Look at the code template in main BFE.m for further information.

Solution:

Listing 11.9: main BFE.m

1 % Run script for bilinear finite elements on a quadrilateral

mesh

2

3 c l e a r a l l4 c l o s e a l l5

6 % Initialize constants

7

8 % Number of red refinement steps

9 NREFS = 4;10 %Final time

11 T = 0.1;12 % Right-hand side source term

13 F_HANDLE = @(x,varargin) z e r o s( s i z e(x,1),1);14 % Initial data

15 U0_HANDLE = @(x,varargin) s i n(pi*x(:,1)).* s i n(pi*x(:,2));16 % Exact solution

17 UEX_HANDLE = @(x,t,varargin)exp(-2*piˆ2*t)* s i n(pi*x(:,1)).* s i n(pi*x(:,2));

18

19 % Initialize mesh

20 Mesh = load_Mesh(’Coord_Square.dat’,’Elem_Square.dat’);21 Mesh = add_Edges(Mesh);22 Loc = get_BdEdges(Mesh);23 Mesh.BdFlags = z e r o s( s i z e(Mesh.Edges,1),1);24 Mesh.BdFlags(Loc) = -1;25 Mesh.ElemFlag = z e r o s( s i z e(Mesh.Elements,1),1);

Problem Sheet 11 Page 12 Problem 11.2

Page 13: Numerical Methods for Partial D-MATH Differential ... · mufinal = RadTEvl(u0,mesh,Tfinal,m) that carries out m uniform timesteps of the L-stable SDIRK-2 implicit 2-stage Runge-Kutta

26

27 % Initialize quadrature rules

28 QuadRule = TProd(gauleg(0,1,4));29

30 % Do NREFS uniform refinement steps

31 L2Err = z e r o s(1,NREFS);32 nDofs = z e r o s(1,NREFS);33

34 f o r j = 1:NREFS35

36 % refine mesh

37 Mesh = refine_REG(Mesh);38

39 % Number of time steps

40 NSTEPS = 200;41

42 % Compute matrices

43 M = assemMat_BFE(Mesh,@MASS_BFE,QuadRule);44

45 % Compute initial data

46 u_old = assemLoad_BFE(Mesh,QuadRule,U0_HANDLE);47 u_old = M\u_old;48

49 % Run timestepping

50 u_new = Parb_Evl_BFE(Mesh, u_old, F_HANDLE, T, NSTEPS);51

52 % Compute L2 error at time T

53 L2Err(j) = L2Err_BFE(Mesh,u_new,QuadRule,UEX_HANDLE,T);54 nDofs(j) = s i z e(Mesh.Coordinates,1);55

56 end57

58 % Plot out discretization error against number of dofs and

add slope triangles

59

60 f i g u r e(2);61 h = axes;62 p l o t(nDofs,L2Err,’ko-’)63 gr id(’on’);64 s e t(gca,’XScale’,’log’,’YScale’,’log’);65 s e t(h,’FontSize’,14);66 x l a b e l(’Dofs [log]’);67 y l a b e l(’Discretization error [log]’);68

69 p = p o l y f i t( l o g(nDofs), l o g(L2Err),1);70 add_Slope(gca,’NorthEast’,p(1));

Problem Sheet 11 Page 13 Problem 11.2

Page 14: Numerical Methods for Partial D-MATH Differential ... · mufinal = RadTEvl(u0,mesh,Tfinal,m) that carries out m uniform timesteps of the L-stable SDIRK-2 implicit 2-stage Runge-Kutta

(11.2j) How should the (uniform) timestep for the implicit Euler method be linked to the mesh-width in order to obtain optimal convergence of ∥uN(T )− u(T )∥L2(Ω) with best possible effi-ciency.

HINT: Take into account the convergence of the spatial discretization studied in subproblem (11.2i).

Solution: You should observe that the error in the spatial discretization has about order N−1 ≈h2. We also know that the implicit Euler method has temporal error of order τ (here τ is thetimestep). For optimal efficiency we want these two errors to be of approximately the same order.Thus,

τ ≈ h2.

Listing 11.10: Testcalls for Problem 11.21 f p r i n t f(’## STIMA_Lapl_BFEsplit\n’);2 STIMA_Lapl_BFEsplit([0 0; 2 0; 2 1.5; 0.2 1.2])3

4 fh = @(x,varargin) ones( s i z e(x,1),1);5 u0h = @(x,varargin) s i n(pi*x(:,1)) .* s i n(pi*x(:,2));6 Mesh.Coordinates = [0 0; 1 0; 2 0; 0 1; 1 1; 2 1; 0 2; 1 2; 2 2];7 Mesh.Elements = [1 2 5 4; 2 3 6 5; 4 5 8 7; 5 6 9 8];8 Mesh = add_Edges(Mesh);9 loc = get_BdEdges(Mesh);

10 Mesh.BdFlags = z e r o s( s i z e(Mesh.Edges,1),1);11 Mesh.BdFlags(loc) = -1;12 Mesh.ElemFlag = z e r o s( s i z e(Mesh.Elements,1),1);13

14 M = assemMat_BFE(Mesh, @MASS_BFE, TProd(gauleg(0,1,4)));15 u0 = assemLoad_BFE(Mesh, TProd(gauleg(0,1,4)), u0h);16 u0 = M\u0;17

18 q = Parb_Evl_BFE(Mesh, u0, fh, 1, 10);19

20 f p r i n t f(’## Parb_Evl_BFE\n’);21 sum(abs([q(1:4); q(6:end)]))22 q(5)

Listing 11.11: Output for Testcalls for Problem 11.21 ## STIMA_Lapl_BFEsplit2

3 ans =4

5 1.1679 -0.3750 0.1714 -0.96436 -0.3750 1.0417 -0.6667 07 0.1714 -0.6667 1.0190 -0.52388 -0.9643 0 -0.5238 1.48819

10 ## Parb_Evl_BFE11

12 ans =13

Problem Sheet 11 Page 14 Problem 11.2

Page 15: Numerical Methods for Partial D-MATH Differential ... · mufinal = RadTEvl(u0,mesh,Tfinal,m) that carries out m uniform timesteps of the L-stable SDIRK-2 implicit 2-stage Runge-Kutta

14 015

16 ans =17

18 0.3716

Problem 11.3 Least-Squares Galerkin DiscretizationOn a bounded polygon Ω ⊂ R2 we consider the stationary linear advection problem

v(x) · gradu = f in Ω,

u = g on Γin := x ∈ ∂Ω,v(x) · n < 0,(11.3.1)

where v : Ω 7→ R2 is a given continuous velocity field, f ∈ C0(Ω) a source term, and g ∈ C0(Γin)boundary values for the unknown u on the inflow boundary Γin.

The so-called least squares variational formulation of (11.3.1) boils down to a linear variationalproblem

u ∈ V : a(u,w) = ℓ(w) ∀w ∈ V, (11.3.2)

with

a(u,w) := ⟨v · gradu,v · gradw⟩L2 , ℓ(w) := ⟨v · gradw, f⟩L2 . (11.3.3)

(11.3a) Specify an appropriate function space V for the least squares variational formulation.

HINT: The Dirichlet boundary conditions in (11.3.1) should be treated as essential boundaryconditions.

Solution: The function space must consist of those functions u which are differentiable, and forwhich the energy norm is finite.

V = u | a(u, u) < ∞, u = g on Γin =u | v · gradu ∈ L2(Ω), u = g on Γin

.

(11.3b) The least squares variational formulation (11.3.2) is equivalent to a minimization prob-lem for a functional J of the form

J(u) := ∥T (u, f)∥2L2(Ω) , (11.3.4)

where T is an expression involving the functions u and f . What is T (u, f) in concrete terms.

Solution: The expression for T is

T (u, f) = v · gradu− f.

(11.3c) Consider the linear 2nd-order scalar elliptic boundary value problem

− div(A(x) grad u) = f in Ω,

u = g on Γin,

(A(x) gradu) · n = 0 on ∂Ω \ Γin,

(11.3.5)

Problem Sheet 11 Page 15 Problem 11.3

Page 16: Numerical Methods for Partial D-MATH Differential ... · mufinal = RadTEvl(u0,mesh,Tfinal,m) that carries out m uniform timesteps of the L-stable SDIRK-2 implicit 2-stage Runge-Kutta

where A : Ω 7→ R2×2 is a continuous matrix-valued function with A(x) = A(x)⊤ for all x ∈ Ω.Which choice of A makes the bilinear forms of the standard (i.e. not least squares) variationalformulation of (11.3.5) and the variational problem (11.3.2) agree?

HINT: For the standard variational formulation of (11.3.5), see [NPDE, Eq. (2.3.3)].

Solution: The bilinear form for (11.3.5) is∫Ω

gradw⊤A(x) grad u dx

If we set that integrand equal to the integrand from the previous bilinear form we get the identity

gradw⊤A(x) grad u = (v(x) · gradw)(v(x) · gradu) = gradw⊤v(x)v(x)⊤ gradu,

so we require A(x) = v(x)v(x)⊤, assuming here of course that v is a column vector.

(11.3d) The downloadable code contains the complete LehrFEM implementation of a finite el-ement solver for the boundary value problem (11.3.5); an approximate solution is computed bymeans of a piecewise linear Lagrangian finite element Galerkin discretization employing triangu-lar meshes and local vertex based quadrature. The main routine is

u = solveellbvp(mesh,A hd,v hd,f hd,g hd),

where mesh passes a LehrFEM mesh data structure complete with edge information and elementflags, and A hd, f hd, g hd are MATLAB function handles of type @(x,varargin) thatprovide the functions A, v (needed for Γin), f , and g. The inflow boundary is detected usingthe markFlags method, which gives inflow boundary edges an edge flag of -1, other boundaryedges -2 and interior edges 0. The values of the finite element solution at the vertices are returnedin the column vector u. The driver routine solvebvp main demonstrates the use of this routine.

Copy the file solveellbvp.m to solveadvbvp.m and modify it so that it implements aLehrFEM routine

u = solveadvbvp(mesh,v hd,g hd),

that solves (11.3.1) in the case f ≡ 0 by means of the least squares Galerkin approach basedon the variational formulation (11.3.2) and piecewise linear Lagrangian finite elements. Theargument v hd provides a function handle of type @(x,varargin) to the velocity field. Thisfunction should return a column vector ∈ R2. The g hd-argument is a function handle of type@(x,varargin) and passes the real valued function g.

Solution:

Listing 11.12: solveadvbvp.m1 f u n c t i o n u = solveadvbvp(mesh, v, g)2

3 qr.w = [1/6; 1/6; 1/6];4 qr.x = [0 0; 1 0; 0 1];5

6 A = @(x) v(x)*v(x)’;

Problem Sheet 11 Page 16 Problem 11.3

Page 17: Numerical Methods for Partial D-MATH Differential ... · mufinal = RadTEvl(u0,mesh,Tfinal,m) that carries out m uniform timesteps of the L-stable SDIRK-2 implicit 2-stage Runge-Kutta

7

8 mesh = markFlags(mesh, v);9

10 S = assemMat_LFE(mesh, @STIMA_AIP, qr, A);11 L = z e r o s( s i z e(mesh.Coordinates,1),1);12

13 [u, FreeDofs] = assemDir_LFE(mesh, -1, g);14 L = L - S*u;15

16 u(FreeDofs) = S(FreeDofs,FreeDofs)\L(FreeDofs);17

18 end

(11.3e) Implement a MATLAB function

lsqphi = lsqrhs(mesh,v hd,f hd)

that computes the right-hand side vector for the variational problem (11.3.2), when piecewiselinear Lagrangian finite elements are employed for its Galerkin discretization.

As in subproblem (11.3d) the argument mesh contains a LehrFEM mesh data structure completewith edges and boundary information. The function handles v hd and f hd of type @(x) givethe velocity field v and source term f , see subproblem (11.3d). Vertex based quadrature (trape-zoidal rule) is to be used for local computations.

HINT: Base your implementation on assemLoad LFE.

Solution:

Listing 11.13: lsqrhs.m1 f u n c t i o n lsqphi = lsqrhs(Mesh, v, FHandle, QuadRule, varargin)2

3 nPts = s i z e(QuadRule.w,1);4 nCoordinates = s i z e(Mesh.Coordinates,1);5 nElements = s i z e(Mesh.Elements,1);6

7 % Preallocate memory

8

9 L = z e r o s(nCoordinates,1);10

11 % Precompute shape functions

12

13 N = shap_LFE(QuadRule.x);14

15 % Assemble element contributions

16

17 f o r i = 1:nElements18

19 % Extract vertices

Problem Sheet 11 Page 17 Problem 11.3

Page 18: Numerical Methods for Partial D-MATH Differential ... · mufinal = RadTEvl(u0,mesh,Tfinal,m) that carries out m uniform timesteps of the L-stable SDIRK-2 implicit 2-stage Runge-Kutta

20

21 vidx = Mesh.Elements(i,:);22

23 % Compute element mapping

24

25 bK = Mesh.Coordinates(vidx(1),:);26 BK = [Mesh.Coordinates(vidx(2),:)-bK;

Mesh.Coordinates(vidx(3),:)-bK];27 inv_BK = inv(BK);28 det_BK = abs(det(BK));29

30 x = QuadRule.x*BK + ones(nPts,1)*bK;31

32 % Compute load data

33

34 FVal = FHandle(x,Mesh.ElemFlag(i),varargin:);35 vvals = [v(x(1,:)), v(x(2,:)), v(x(3,:))];36 grad_N = grad_shap_LFE(QuadRule.x);37

38 % Add contributions to global load vector

39

40 L(vidx(1)) = L(vidx(1)) + FVal(1) * grad_N(1,1:2) *inv_BK’ * vvals(:,1) * QuadRule.w(1) * det_BK...

41 + FVal(2) * grad_N(2,1:2) * inv_BK’ * vvals(:,2)

* QuadRule.w(2) * det_BK...42 + FVal(3) * grad_N(3,1:2) * inv_BK’ * vvals(:,3)

* QuadRule.w(3) * det_BK;43 L(vidx(2)) = L(vidx(2)) + FVal(1) * grad_N(1,3:4) *

inv_BK’ * vvals(:,1) * QuadRule.w(1) * det_BK...44 + FVal(2) * grad_N(2,3:4) * inv_BK’ * vvals(:,2)

* QuadRule.w(2) * det_BK...45 + FVal(3) * grad_N(3,3:4) * inv_BK’ * vvals(:,3)

* QuadRule.w(3) * det_BK;46 L(vidx(3)) = L(vidx(3)) + FVal(1) * grad_N(1,5:6) *

inv_BK’ * vvals(:,1) * QuadRule.w(1) * det_BK...47 + FVal(2) * grad_N(2,5:6) * inv_BK’ * vvals(:,2)

* QuadRule.w(2) * det_BK...48 + FVal(3) * grad_N(3,5:6) * inv_BK’ * vvals(:,3)

* QuadRule.w(3) * det_BK;49

50 end51

52 lsqphi = L;53

54 re turn

Problem Sheet 11 Page 18 Problem 11.3

Page 19: Numerical Methods for Partial D-MATH Differential ... · mufinal = RadTEvl(u0,mesh,Tfinal,m) that carries out m uniform timesteps of the L-stable SDIRK-2 implicit 2-stage Runge-Kutta

(11.3f) Assume g = 0. Write a MATLAB function

u = solveadvlsq(mesh,v,f)

that computes the coefficient vector u of the least squares solution of (11.3.1) obtained by a lin-ear Lagrangian finite element Galerkin solution of the related least squares variational problem(11.3.2). The arguments have the same meaning as in subproblem (11.3e).

HINT: You may copy large parts of your implementation of solveadvbvp from subproblem (11.3d).Also use lsqrhs.

Solution:

Listing 11.14: solveadvlsq.m1 f u n c t i o n u = solveadvlsq(mesh, v, f)2

3 qr.w = [1/6; 1/6; 1/6];4 qr.x = [0 0; 1 0; 0 1];5

6 A = @(x) v(x)*v(x)’;7

8 mesh = markFlags(mesh, v);9

10 S = assemMat_LFE(mesh, @STIMA_AIP, qr, A);11 L = lsqrhs(mesh, v, f, qr);12

13 g = @(x,varargin) z e r o s( s i z e(x,1),1);14

15 [u, FreeDofs] = assemDir_LFE(mesh, -1, g);16 L = L - S*u;17

18 u(FreeDofs) = S(FreeDofs,FreeDofs)\L(FreeDofs);19

20 end

Listing 11.15: Testcalls for Problem 11.31 load(’sqrmesh0.mat’);2 mesh.ElemFlag = ones( s i z e(mesh.Elements,1),1);3 mesh = add_Edges(mesh);4 mesh = add_Edge2Elem(mesh);5 loc = get_BdEdges(mesh);6 mesh.BdFlags = z e r o s( s i z e(mesh.Edges,1),1);7 mesh.BdFlags(loc) = [-1; -1; -1; -1];8

9 mesh1 = refine_REG(mesh);10 mesh2 = refine_REG(mesh1);11

12 mesh1 = add_Edge2Elem(mesh1);13 mesh2 = add_Edge2Elem(mesh2);

Problem Sheet 11 Page 19 Problem 11.3

Page 20: Numerical Methods for Partial D-MATH Differential ... · mufinal = RadTEvl(u0,mesh,Tfinal,m) that carries out m uniform timesteps of the L-stable SDIRK-2 implicit 2-stage Runge-Kutta

14

15 A_hd = @(x,varargin) [2 0; 0 1];16 v_hd = @(x,varargin) [1; 1];17 f_hd = @(x,varargin) ones( s i z e(x,1),1);18 g1_hd = @(x,varargin) z e r o s( s i z e(x,1),1);19 g2_hd = @(x,varargin) sum(x.ˆ2,2);20

21 f p r i n t f(’## solveadvbvp\n’);22 u = solveadvbvp(mesh1, v_hd, g2_hd);23 [ f i n d(u), u( f i n d(u))]24

25 f p r i n t f(’## solveadvlsq\n’);26 u = solveadvlsq(mesh2, v_hd, f_hd);27 [ f i n d(u), u( f i n d(u))]

Listing 11.16: Output for Testcalls for Problem 11.31 ## solveadvbvp2

3 ans =4

5 2.0000 1.00006 3.0000 2.00007 4.0000 1.00008 5.0000 0.25009 6.0000 1.0000

10 7.0000 0.250011 8.0000 1.250012 9.0000 1.250013

14 ## solveadvlsq15

16 ans =17

18 6.0000 0.000019 11.0000 0.000020 15.0000 0.000021 20.0000 0.000022 21.0000 0.000023 22.0000 -0.000024 23.0000 0.000025 24.0000 -0.000026 25.0000 0.0000

Problem Sheet 11 Page 20 Problem 11.3

Page 21: Numerical Methods for Partial D-MATH Differential ... · mufinal = RadTEvl(u0,mesh,Tfinal,m) that carries out m uniform timesteps of the L-stable SDIRK-2 implicit 2-stage Runge-Kutta

Problem 11.4 One-Dimensional Stationary Convection-Diffusion (Core prob-lem)

The one-dimensional stationary convection-diffusion equation with constant unit velocity wasstudied on several occasions in class and reads

− ϵ∂2u

∂x2+

∂2u

∂x2= f(x) in (0, 1). (11.4.1)

We supply it with homogeneous Dirichlet boundary conditions u(0) = u(1) = 0, and source termf(x) = 1, which yields the IBVP of [NPDE, Ex. 7.2.5].

For discretization, we will use piecewise linear finite elements on an equidistant mesh, with up-wind quadrature, see [NPDE, Sect. 7.2.2], for the discretization of the convection term.

(11.4a) State the discrete variational formulation underlying the upwind quadrature approachand compute the system matrix A and the right-hand side vector φ for the linear system ofequations Aµ = φ arising from the upwind quadrature discretization of (11.4.1).

Solution: The discrete variational formulation is: Find u ∈ S01,0(M) such that

ϵ

∫ 1

0

∂u

∂x· ∂v∂x

dx+

∫ 1

0

(∂u

∂x

)+

v(x)dx =

∫ 1

0

f(x)v(x)dx

for all v ∈ S01,0(M), where

(∂u∂x

)+ denotes the upwind derivative of u. This leads to

A =ϵ

h

2 −1−1 2 −1

. . . . . . . . .

+

1−1 1

. . . . . .

,

and

φ = h

f(x1)...

f(xN)

.

(11.4b) Write a MATLAB function

[x,U] = convdiff 1d(N,epsilon)

which solves (11.4.1) using the upwind quadrature Galerkin approach with N internal nodes and ϵgiven by epsilon, and returns the solution (including the boundary points) in the N +2-vectorU, and the positions of the mesh vertices in the N + 2 vector x.

Solution: See Listing 11.17.

Listing 11.17: Implementation for convdiff 1d.1 f u n c t i o n [x,U] = convdiff_1d(N, eps)2

3 h = 1/(N+1);4 e = ones(N,1);

Problem Sheet 11 Page 21 Problem 11.4

Page 22: Numerical Methods for Partial D-MATH Differential ... · mufinal = RadTEvl(u0,mesh,Tfinal,m) that carries out m uniform timesteps of the L-stable SDIRK-2 implicit 2-stage Runge-Kutta

5 A = (eps/h)* s p d i a g s([-e, 2*e, -e], -1:1, N, N) +s p d i a g s([-e, e], -1:0, N, N);

6 L = h*e;7

8 U = [0; A\L; 0];9 x = l i n s p a c e(0,1,N+2)’;

10

11 end

(11.4c) Investigate the convergence of the method implemented in (11.4b) in the L2-norm forϵ = 10−2, N = 10 ·21, . . . , 10 ·27. Use composite two-point Gaussian quadrature in each elementto evaluate the error. Plot the error in a loglog-plot and find the rate of convergence.

HINT: The two-point Gaussian quadrature rule relative to [−1, 1] has quadrature nodes ± 1√3

withweights 1. Since we use linear finite elements, linear interpolation of nodal values yields valuesof the approximate solution at the quadrature points. The exact solution is

u(x) = x− ex/ϵ − 1

e1/ϵ − 1.

Solution: See Listing 11.18, and Figure 11.5 for the error plot. The rate of convergence is com-puted as:

>> main_p1rate of convergence is 0.926420

Listing 11.18: Implementation for main p1.1 Nvals = 10*2.ˆ(1:7);2 errs = [];3 eps = 1e-2;4

5 exact = @(x) x - (exp(x/eps)-1)/(exp(1/eps)-1);6

7 f o r N = Nvals,8 [x,U] = convdiff_1d(N, eps);9 h = x(2);

10 gpts = s o r t([x(1:end-1) + h*(1-1/ s q r t(3))/2; x(1:end-1) +h*(1+1/ s q r t(3))/2]);

11 weights = h*ones(2*N+2,1)/2;12 U_appr = linterp(x, U, gpts)’;13 U_ex = exact(gpts);14 errs = [errs, s q r t(sum(weights.*(U_appr - U_ex).ˆ2))];15 end;16

17 l o g l o g(Nvals, errs)18 p = p o l y f i t( l o g(Nvals), l o g(errs), 1);19 f p r i n t f(’rate of convergence is %f\n’, -p(1))

Problem Sheet 11 Page 22 Problem 11.4

Page 23: Numerical Methods for Partial D-MATH Differential ... · mufinal = RadTEvl(u0,mesh,Tfinal,m) that carries out m uniform timesteps of the L-stable SDIRK-2 implicit 2-stage Runge-Kutta

101

102

103

104

10−3

10−2

10−1

number of interior nodes N

L2 err

or

L2 convergence [ref sol]

Figure 11.5: Error plot for subproblem (11.4c).

20 x l a b e l(’number of interior nodes N’);21 y l a b e l(’Lˆ2 error’);22 t i t l e (’Lˆ2 convergence’)23

24 %conf.myFontsize = 13;

25 %conf.size = [700, 300];

26 %conf.its = 1:1;

27 %fig_prepare(conf); legend off

28 t i t l e ( s p r i n t f(’%s [ref sol]’,g e t(g e t(gca,’title’),’string’)));

29 %saveas(gcf, ’p1.eps’, ’epsc’)

Listing 11.19: Testcalls for Problem 11.41 f p r i n t f(’## convdiff_1d(N, eps)’)2 N = 3;3 eps = 1e-1;4 [x, U] = convdiff_1d(N, eps);5 x_U = [x, U]

Listing 11.20: Output for Testcalls for Problem 11.41 >> test2 ## convdiff_1d(N, eps)3 x_U =4

5 0 06 0.2500 0.23327 0.5000 0.42458 0.7500 0.46919 1.0000 0

Problem Sheet 11 Page 23 Problem 11.4

Page 24: Numerical Methods for Partial D-MATH Differential ... · mufinal = RadTEvl(u0,mesh,Tfinal,m) that carries out m uniform timesteps of the L-stable SDIRK-2 implicit 2-stage Runge-Kutta

Published on May 13.To be submitted on May 20.MATLAB: Submit all files in the online system. Include the files that generatethe plots. Label all your plots. Include commands to run your functions. Com-ment on your results.

References

[NPDE] Lecture Slides for the course “Numerical Methods for Partial Differential Equations”,SVN revision # 55075.

[NCSE] Lecture Slides for the course “Numerical Methods for CSE”.

[LehrFEM] LehrFEM manual.

Last modified on May 22, 2013

Problem Sheet 11 Page 24 REFERENCES