Sei sulla pagina 1di 82

Finite Difference, Finite Element and Finite Volume Methods for the Numerical Solution of PDEs

Vrushali A. Bokil bokilv@math.oregonstate.edu


and

Nathan L. Gibson gibsonn@math.oregonstate.edu Department of Mathematics Oregon State University Corvallis, OR DOE Multiscale Summer School June 30, 2007

Multiscale Summer School p. 1/8

Math Modeling and Simulation of Physical Processes

Dene the physical problem Create a mathematical model


Systems of PDEs, ODEs, algebraic equations Dene initial and or boundary conditions to get a well-posed problem Discretize the domain generate the grid obtain discrete model Solve the discrete system Consistency, stability and convergence analysis

Create a discrete (numerical) model

Analyze errors in the discrete system

Multiscale Summer School p. 2/8

Contents

Partial Differential Equations (PDEs) Conservation Laws: Integral and Differential Forms Classication of PDEs: Elliptic, Parabolic and Hyperbolic Finite Difference Methods Analysis of Numerical Schemes: Consistency, Stability, Convergence Finite Volume and Finite Element Methods Iterative Methods for Large Sparse Linear Systems

Multiscale Summer School p. 3/8

Partial Differential Equations

PDEs: Mathematical models of continuous physical phenomenon in which a dependent variable, say u, is a function of more than one independent variable, say t (time), and x (eg., spatial position). Conservation Laws: PDEs derived by applying a physical principle such as conservation of mass, momentum or energy. These equations, govern the kinematic and mechanical behavior of general bodies. These laws can be written in either the strong or differential form, or an integral form. Well Posed Problem: Solution exits, is unique and depends continuously on the data. Boundary conditions on the (nite) boundary of the domain and/or initial conditions are required to obtain a well posed problem.

Multiscale Summer School p. 4/8

PDEs (continued)

For simplicity, we will deal only with single PDEs (as opposed to systems of several PDEs) with only two independent variables, Either two space variables, denoted by x and y, or One space variable denoted by x and one time variable denoted by t Partial derivatives with respect to independent variables are denoted by subscripts, for example ut = u t

uxy =

2u xy

Multiscale Summer School p. 5/8

Well Posed Problems

Boundary conditions, i.e., conditions on the (nite) boundary of the domain and/or initial conditions (for transient problems) are required to obtain a well posed problem. Properties of a well posed problem: Solution exists

Solution is unique Solution depends continuously on the data

Multiscale Summer School p. 6/8

Classications of PDEs

The Order of a PDE = the highest-order partial derivative appearing in it. For example, The advection equation ut + ux = 0 is a rst order PDE. The Heat equation ut = uxx is a second order PDE. A PDE is linear if the coefcients of the partial derivatives are not functions of u. For example The advection equation ut + ux = 0 is a linear PDE. The Burgers equation ut + uux = 0 is a nonlinear PDE.

Multiscale Summer School p. 7/8

Classications of PDEs (continued)


Second-order linear PDEs in general form auxx + buxy + cuyy + dux + euy + f u + g = 0 are classied based on the value of the discriminant b2 4ac b2 4ac > 0: hyperbolic e.g., wave equation : u u tt xx = 0 Hyperbolic PDEs describe time-dependent, conservative physical processes, such as convection, that are not evolving toward steady state.

b2 4ac = 0: parabolic e.g., heat equation utt uxx = 0 Parabolic PDEs describe time-dependent dissipative physical processes, such as diffusion, that are evolving toward steady state. b2 4ac < 0: elliptic e.g., Laplace equation: uxx + uyy = 0 Elliptic PDEs describe processes that have already reached steady states, and hence are time-independent.

Multiscale Summer School p. 8/8

Parabolic PDEs: Initial-Boundary value problems

Example: One dimensional (in space) Heat Equation for u = u(t, x) ut = uxx , 0 x A, t 0 The diffusion coefcient > 0 is a constant.

with

Boundary conditions: u(t, 0) = u0 , u(t, A) = uA , and Initial conditions: u(0, x) = g(x)


t

domain of influence

tq

q
domain of dependence

0 0 xq A

Multiscale Summer School p. 9/8

Elliptic PDEs: Boundary value problems

Example: Model of steady heat conduction in a two dimensional (in space) domain, governed by the Laplace equation for the temperature T = T (x, y) Txx + Tyy = 0, 0 x W, 0 y H

with boundary conditions


T (x, 0) = T1 , T (x, H) = T2 T (0, y) = T3 , T (W, y) = T4


y H T3 yq q 0 0 T1 xq W x T4 T2

Multiscale Summer School p. 10/8

Hyperbolic PDEs: Initial-Boundary value problems

Example: One-dimensional (in space) wave equation for u = u(t, x) utt = c2 uxx , 0 x L, t 0

with boundary conditions


Boundary conditions u(t, 0) = u0 , u(t, L) = uL Initial Conditions u(0, x) = f (x), ut (0, x) = g(x)
t
domain of influence

tq

q
slope = slope =

+c

0 0

domain of dependence

xq

Multiscale Summer School p. 11/8

Finite Difference Methods (FDM): Discretization


Suppose that we are solving for u = u(t, x) on the domain = [0, T ] [0, L]. We discretize the domain by partitioning the spatial interval [0, L] into m + 2 grid points x0 , x1 , . . . , xm , xm+1 = L, such that xj = xj+1 xj , j = 0, 1, 2, . . . m In the case that the m + 2 spatial points xj are equally spaced, we have x = xj , j
x xm+1 = L xm

q
0 = x0

q
x1

q
x2

q
...

. . . xj1 xj xj+1 . . . x

' E

We similarly discretize the temporal domain [0, T ] into discrete time levels tn with time step t.

Multiscale Summer School p. 12/8

Finite Difference Methods: Discretization


The numerical solution to the PDE is an approximation to the exact solution that is obtained using a discrete representation to the PDE at the grid points xj in the discrete spatial mesh at every time level tn . Let us denote this numerical solution as U such that
n Uj u(tn , xj )

Thus, the numerical solution is a collection of nite values,


n n n U n = [U1 , U2 , . . . , Um ]

at each time level tn .


n n The boundary conditions determine the values of U0 and Um+1 for all n. The initial conditions determine the values of U 0 at each spatial grid point.

Multiscale Summer School p. 13/8

Finite Difference Methods (continued)

Recall the denition of the derivative from introductory Calculus: ux (xj ) = lim u(xj + h) u(xj ) h0 h u(xj ) u(xj h) = lim h0 h u(xj + h) u(xj h) = lim h0 2h

We use these formulae with a small nite value of h = x, i.e., we approximate ux (xj ) u(xj + h) u(xj ) (Forward difference) h u(xj ) u(xj h) (Backward difference) h u(xj + h) u(xj h) (Centered difference) 2h

Multiscale Summer School p. 14/8

Error in FDM: Local Truncation Error


The local truncation error (LTE) is the error that results by substituting the exact solution into the nite difference formula. Errors in the approximations to the derivative are calculated using Taylor approximations around a grid point xj . For example, u(xj+1 ) = u(xj + x) (x)2 + O((x)3 ) = u(xj ) + ux (xj )x + uxx (xj ) 2 Thus, u(xj+1 ) u(xj ) x + uxx (xj ) + O((x)2 ) ux (xj ) = x 2 The forward difference is a rst order accurate approximation to the partial derivative ux at xj and the LTE is O(x).

Multiscale Summer School p. 15/8

Error in FDM: LTE


The backward difference is a rst order accurate

approximation to the partial derivative ux at xj and the LTE is O(x).

The centered difference is a second order accurate

approximation to the partial derivative ux at xj and the LTE is O((x)2). as x goes to zero.

Note that the LTE in all these approximations goes to zero

Multiscale Summer School p. 16/8

FDM for Parabolic PDEs: The Heat Equation


Consider the initial-boundary value problem for the heat equation ut = uxx , 0 x 1, t 0 u(0, x) = f (x), Initial Condition u(t, 0) = , Boundary Condition at x = 0 u(t, 1) = , Boundary Condition at x = 1 Discretize the spatial domain [0, 1] into m + 2 grid points using a uniform mesh step size x = 1/(m + 1) . Denote the spatial grid points by xj , j = 0, 1, . . . m + 1. E

q
0 = x0

q
x1

q
x2

q
...

. . . xj1 xj xj+1 . . . x

' E

x xm xm+1 = 1

Multiscale Summer School p. 17/8

FDM for Parabolic PDEs: The Heat Equation


Similarly discretize the temporal domain into temporal grid points tk = kt for suitably chosen time step t. k Denote the approximate solution at the grid point (tk , xj ) as Uj .
= u k uk 0 1 uk 2
k k uk j1 uj uj+1 k uk um+1 = m

tk = kt

q
0 = x0

q
x1

q
x2

q
...

. . . xj1 xj xj+1 . . . x

' E

x xm+1 = 1 xm

The space-time grid can be represented as . T . q . q


t

q q q q
x2

q q q q
...

q q q q

q q q q

q
(t2 , xj )

q q q q

q q q q

q q q q

T q q q
t

T t c1 q q

t2

q q q

q q q

t0 0 = x 0 x1

. . . xj1 xj xj+1 . . .

xm xm+1 = 1

Ex T

Multiscale Summer School p. 18/8

FDM for Parabolic PDEs: The Heat Equation


Replace ut by a forward difference in time and uxx by a central difference in space to obtain the explicit FDM
k+1 k k k k Uj U j Uj+1 2Uj + Uj1 = t (x)2

k+1 Uj

k Uj

t k k k + Uj+1 2Uj + Uj1 , j = 1, 2, . . . m (x)2

Associated to this scheme is a Computational Stencil

k+1

q q T s d q q dq q q
j

k1

q
j+1

j1

Multiscale Summer School p. 19/8

FDM for Parabolic PDEs: The Heat Equation


This is an explicit FDM for the heat equation: Solution at time level k + 1 is determined by solution at previous time levels only. We note that
k k From Boundary conditions: U0 = and Um+1 = for all values of k. 0 From Initial condition: Uj = f (xj ) for all values of j.

The local truncation error is O(t) + O((x)2 ).

Scheme is rst order accurate in time and second order accurate in space How do we choose the values of t and x??

Multiscale Summer School p. 20/8

FDM for Parabolic PDEs: The Heat Equation


A simulation with an initial condition that has a discontinuous derivative at x = 0.5.
1 0.9 0.8 0.7 0.6 0.5 0.4 0.3 0.2 0.1
Exact Solution Initial function

dx=0.01, dt=1e05, r=0.1


0 0 0.2 0.4 0.6 0.8 1

In the above 1 t r= x 2 with x = 0.01 and t = 105

Multiscale Summer School p. 21/8

FDM for Parabolic PDEs: The Heat Equation


Initial condition has a discontinuous derivative at x = 0.5. However, we see a rapid smoothing effect of this initial discontinuity as time evolves. In general high frequencies get rapidly damped as compared to low frequencies. We say that the heat equation is stiff. In the above we assumed that the value of 1 t r= x 2 Here x = 0.01 and t = 105 What happens if this value is greater than 1/2?

Multiscale Summer School p. 22/8

FDM for Parabolic PDEs: The Heat Equation


1.5 x 10
282

0.5

0.5

dx=0.01, dt=0.0001, r=1


1.5 0 0.2 0.4 0.6 0.8 1

We see unstable behavior of the numerical solution when r > 1/2! The numerical solution does not stay bounded. Thus, t and x cannot be chosen arbitrarily. They have to satisfy a stability condition.

Multiscale Summer School p. 23/8

Implicit FDM for Parabolic PDEs: The Heat Equation


Replace ut by a forward difference in time and uxx by a central difference in space to obtain the Implicit FDM
k+1 k+1 k+1 k+1 k Uj+1 2Uj Uj Uj + Uj1 = t (x)2

k+1 Uj

k Uj

t k+1 k+1 k+1 + Uj+1 2Uj + Uj1 , j = 1, 2, . . . m (x)2

Associated to this scheme is a Computational Stencil

k+1

q q q

q T q q
j

q q q
j+1

k1

j1

Multiscale Summer School p. 24/8

FDM for Parabolic PDEs: The Heat Equation


1 0.9 0.8 0.7 0.6 0.5 0.4 0.3 0.2 0.1
dx=0.01, dt=0.01, r=100 Exact Solution Initial function

0 0

0.2

0.4

0.6

0.8

We see stable behavior of the numerical solution! The numerical solution remains bounded even when r > 1/2. Thus, t and x can be chosen to have the same order of magnitude. The implicit FDM is unconditionally stable However, the implicit scheme is still rst order accurate in time and second order accurate in space. Also, a system of equations must be solved at each step.

Multiscale Summer School p. 25/8

Crank-Nicolson for The Heat Equation



Replace ut by a forward difference in time and uxx by a central difference in space to obtain the Implicit FDM

k+1 Uj

k Uj

t =
k+1 Uj

= 2

k Uj+1

k 2Uj

k Uj1

(x)2

+ 2

k+1 k+1 k+1 + Uj1 Uj+1 2Uj

(x)2

k Uj

j = 1, 2, . . . m

t k k+1 k+1 k+1 k k + + Uj1 , Uj+1 2Uj + Uj1 + Uj+1 2Uj 2(x)2

Associated to this scheme is a Computational Stencil


k+1

q q q

q T q q
j

q q q
j+1

This method is unconditionally stable, It is second-order accurate in time However a system of equations must be solved at each time step.

k1

j1

Multiscale Summer School p. 26/8

First vs Second Order Accuracy


0

Slope =1: First order accurate

log2(LTE)

10

Slope =2: Second Order accurate

12

14 14

12

10

8
log ( x)
2

Multiscale Summer School p. 27/8

Method of Lines (MOL) Discretization


Another way of solving time dependent PDEs numerically

is to discretize in space but not in time.

This results in a large coupled system of ODEs which we

can then solve using numerical methods developed for ODEs, such as Forward and Backward Euler method, Trapezoidal methods, Runge-Kutta methods etc.

The method of lines approach can be used to analyze the

stability of the numerical method for the PDE by analyzing the eigenvalues of the matrix of the resulting system of ODEs using the ideas of absolute stability for ODEs.

Multiscale Summer School p. 28/8

Analysis of FDM
Consistency implies that the local truncation error goes to zero as x and t approach zero. This is usually proved by invoking Taylors theorem. Stability implies that the numerical solution remains bounded at any given time t. Stability is harder to prove than consistency. Stability can be proven using either Eigenvalue analysis of the matrix representation of the FDM. Fourier analysis on the grid (von Neumann analysis) Computing the domain of dependence of the numerical method. Lax-Equivalence Theorem : A consistent approximation to a well-posed problem is convergent if and only if it is stable

Multiscale Summer School p. 29/8

Von Neumann Analysis for Time-dependent Problems


Example: The analytical solutions of the heat equation ut uxx = 0 can be found in the form

u(t, x) =

em t eim x

2 with m + m = 0. Here eim x = cos(m x) + i sin(m x).

To analyze the growth of different Fourier modes as they evolve under the numerical scheme we consider each frequency separately, namely let u(t, x) = em t eim x
k In the discrete case we assume that Uj = Gk eim jx with

G = em t . Any growth in the solution will be due to the presence of terms involving G. Thus requiring that this amplication factor G is bounded by one as k gives rise to a relation between t and x called the von Neumann stability condition.

Multiscale Summer School p. 30/8

FDM for Hyperbolic PDEs: The Advection Equation


Consider the initial value problem for the Advection equation ut + aux = 0, 0 x 1, t 0 u(0, x) = f (x), Initial Condition The solution u(x, t) = f (x at) is a wave that propagates to the right if a > 0 and to the left if a < 0.
u(x, t)

T
u(x, 0)

T c c E T T c E x 
x1 x2 x3

Characteristic x at = x3

Information propagates along characteristics

Multiscale Summer School p. 31/8

FDM for the Advection Equation


Replace ut by a forward difference in time and ux by a backward difference in space to obtain the explicit FDM
k+1 k k k Uj Uj Uj+1 Uj +a =0 t x at k+1 k k k Uj Uj1 , j = 1, 2, . . . m = Uj + = Uj x

Associated to this scheme is a Computational Stencil


k+1

q  T q q q q
j

q q q
j+1

k1

j1

Scheme is explicit First order accurate is time and space t and x are related through the Courant number at = x

Multiscale Summer School p. 32/8

Courant Friedrich Lewy (CFL) Condition


The CFL Condition : For stability, at each mesh point, the Domain of dependence of the PDE must lie within the domain of dependence of the numerical scheme.
t

T
at t

T
at t

b r
(x0 , 0)

r r

r r r r r r r x ' E

rCharacteristic x at = x0 r r t T c r rE x

r r r rb r
(x0 , 0)

rCharacteristic x at = x0 r r r r t T c r r r rE x ' E x

CFL is a necessary condition for stability of explicit FDM applied to Hyperbolic PDEs. It is not a sufcient condition. For the advection equation CFL condition for stability is || 1. i.e., x . t |a|

Multiscale Summer School p. 33/8

Elliptic PDEs: Laplace Equation


Time-independent problems Consider the Boundary value problem for the Laplace equation in two spatial dimensions uxx + uyy = 0, 0 x 1, 0 y 1 with boundary conditions prescribed as shown below
y u=1

T
u=0

u=0

E
u=0

Multiscale Summer School p. 34/8

FDM for Elliptic PDEs: Laplace Equation


Discretize the mesh using uniform mesh step in both the x and y directions as below.
boundary node
yJ+2 = 1

b b b

b r r r r r r b

b r r

b r

b r

b r r r r r r b

b r r r r r r b

b r r r r r r b

b r r r r r r b

b r r r r r r b

T b b b b b b b b Ex T =1
y

yJ+1 yJ

. . b . . . b . b b b

r r y T r c r r ' E x r r r r r b
x2

y2 y1

r r b
...

r r b

0 = y0 0 = x 0 x1

. . . xj1 xj xj+1 . . . xL+1xL+2

Multiscale Summer School p. 35/8

Elliptic PDEs: Laplace Equation


Replace both the second order derivatives uxx and uyy with centered differences at each grid point (xj , yk ) to obtain the difference scheme Uj,k+1 2Uj,k + Uj,k1 Uj+1,k 2Uj,k + Uj1,k + =0 (x)2 (y)2 If x = y this becomes Uj+1,k + Uj1,k + Uj,k+1 + Uj,k1 4Uj,k = 0 The Stencil for this FDM is called the Five-Point Stencil
k+1

q q q

q q q
j

q q q
j+1

k1

j1

Multiscale Summer School p. 36/8

Elliptic PDEs: Laplace Equation


This FDM gives rise to a system of linear equations of the form AU = b The right hand side vector b contains the boundary information. The vector U is the solution vector at the interior grid points. The matrix A is block tridiagonal if ordered in a natural way The structure of A depends on the ordering of the grid points. This system can be solved by iterative techniques or direct methods such as Gaussian elimination.

When m = 2, the system AU = b can be written as 4 1 1 1 4 0 1 0 4 0 1 1 0 1 1 4 U1,1 U2,1 U1,2 U2,2 0 0 1 1

Multiscale Summer School p. 37/8

Discretization of Elliptic PDEs


increasing j increasing i
4 1 1 1 4 1 1 1 1 1 1 1 1 4 1 1 1 1 4 1 4 1 4 1 4 1 4 1 4 1 1 4 1 4 1 1 1 1 1 1 1 1 4

each block (L + 1) (L + 1)

J+1 blocks

J + 1 blocks

Multiscale Summer School p. 38/8

Finite Element Method


Features Flexibility Complicated geometries High-order approximations Strong mathematical foundation

Multiscale Summer School p. 39/8

Basic Idea
M

u(x) u(x) =
j=1

uj j (x)

j are basis functions uj : M unknowns; Need M equations Discretizing derivatives results in linear system

Multiscale Summer School p. 40/8

1D Elliptic Example
u = f, u(0) = u(1) = 0

0<x<1

For example, elastic cord with xed ends Solution must be twice differentiable This is unnecessarily strong if f is discontinuous

Multiscale Summer School p. 41/8

Weak Formulation
Multiply both sides by an arbitrary test function v and integrate
1 1

u vdx =
0 1 0 0 1

f vdx f vdx.
0

u v dx u v|1 = 0
1 1

u v dx =
0 0

f vdx.

Since v was arbitrary, this equation must hold for all v such that the equation makes sense (v is square integrable), and v(0) = v(1) = 0.

Multiscale Summer School p. 42/8

Weak Formulation 2
Find u V such that
1 1

u v dx =
0 1 where V = H0 ([0, 1]). 0

f vdx

v V

Fewer derivatives required for u If f continuous, same u as strong form Innite possibilities for v Want to nd u on a discrete mesh

Multiscale Summer School p. 43/8

Finite-dimensional Subspace

Let 0 = x0 < x1 < . . . < xM +1 = 1 be a partition of the domain with hj = xj xj1 and h = max hj . Use the partition to dene a nite-dimensional subspace Vh V . For decreasing h, want that functions in Vh can get arbitrarily close to functions in V . For example, let Vh be piecewise linear (i.e., on each subinterval) functions such that v Vh is continuous on [0, 1] and v (0) = v (1) = 0. We may introduce basis functions j (x) such that j (xi ) = ij for i, j = 0, . . . , M + 1. Nodes xi are sometimes denoted Ni

Multiscale Summer School p. 44/8

Basis Functions
u1

Finite methods for partial differential equations


ui
1

19

ui ui
i
1

uN xi
1

x1

xi

xi

xN

u1 x 1 x

. . .
Ni (x) ui x 1 x

. . .
uN x 1 x

Multiscale Summer School p. 45/8

Finite Element Method


Find u Vh such that
1 1

u v dx =
0 0

f v dx

Vh . v

or
1 0 1

u j dx =

f j dx
0

j = 1, . . . , M.

Note: When u and v in same subspace: Galerkin If support of i is entire space: Spectral If Vh not a subspace of V : Non-conforming

Multiscale Summer School p. 46/8

Linear System

Can represent u =
1 M 0

Find i for i = 1, . . . , M such that


1

M i=1 i i (x)

i i j dx =
i=1

f j dx
0

j = 1, . . . , M.
1 0 i j dx

Thus if A = (aij ) with aij = b = (bi ) with bi =


1 0 f i dx,

and

then

A = b

Multiscale Summer School p. 47/8

Stiffness Matrix

The M M matrix A is called the stiffness matrix. For the piecewise linear basis functions we have chosen it will be tridiagonal. For the special case when hj h we have 2 1 0 0 . ... . . 1 2 1 ... . . 1 0 1 2 1 . h . ... ... ... ... 0 . . . . . . 1 2 1 . . 0 0 1 2

Multiscale Summer School p. 48/8

Compare to FDM

Note that if Trapezoid rule is used to approximate the right hand side, then bi = hfi , and therefore the equations determining u are i+1 2i + i1 = hfi h

which are exactly the same as FDM. The advantage of the FEM formulation is the generality it allows (e.g., uniform h was not required).

Multiscale Summer School p. 49/8

Multidimensional Problem

Let be the unit square (x, y) [0, 1] [0, 1] Assume homogeneous Dirichlet boundary conditions Then the 2D Possion problem is: 1 Find u V := H0 () such that u = f u=0 in , on .

Multiscale Summer School p. 50/8

Variational Formulation
Find u V such that a(u, v) = (f, v) , where a(u, v) :=

v V,

u f v.

v,

(f, v) :=

Note: used Greens formula and v = 0 on .

Multiscale Summer School p. 51/8

P1 Finite Element
We introduce a triangulation Th of into triangles Ki , and a nite dimensional subspace:
1 Vh := { H0 () : v |Ki P1 (Ki )}. v

Find u Vh such that a(, v ) = (f, v ) , u Vh . v

Multiscale Summer School p. 52/8

Using Basis Functions


Representing u and v in terms of nodal basis functions {i }M of Vh , i.e., j (Ni ) = ij for i=1 i, j = 0, . . . , M + 1, we get the following system of algebraic equations:
M

j a(i , j ) = (f, i ),
j=1

i = 1, . . . , M,

or in matrix form, A = b, where j = u(Nj ), Aij = a(i , j ) is SPD, and bi = (f, i ) .

Multiscale Summer School p. 53/8

Multidimensional Problem

Let be the unit cube {x, y, z} [0, 1] Assume homogeneous Dirichlet boundary conditions Then the 3D Possion problem is: 1 Find u V := H0 () such that u = f u=0 in , on .

Multiscale Summer School p. 54/8

Variational Formulation
Find u V such that a(u, v) = (f, v) , where a(u, v) :=

v V,

u f v.

v,

(f, v) :=

Note: used Greens formula and v = 0 on .

Multiscale Summer School p. 55/8

Q1 Finite Element
We introduce a triangulation Th of into 3-D rectangles Ki , and a nite dimensional subspace:
1 Vh := { H0 () : v |Ki Q1 (Ki )}. v
       

Find u Vh such that a(, v ) = (f, v ) , u Vh . v

 

Multiscale Summer School p. 56/8

Using Basis Functions


Representing u and v in terms of nodal basis functions {i }M of Vh , i.e., j (Ni ) = ij for i=1 i, j = 0, . . . , M + 1, we get the following system of algebraic equations:
M

j a(i , j ) = (f, i ),
j=1

i = 1, . . . , M,

or in matrix form, A = b, where j = u(Nj ), Aij = a(i , j ) is SPD, and bi = (f, i ) .

Multiscale Summer School p. 57/8

Neumann Problem

Let be the unit square (x, y) [0, 1] [0, 1] Assume Neumann boundary conditions Then the 2D Possion problem is: Find u V := H 1 () such that u = f u =g n in , on .

Multiscale Summer School p. 58/8

Variational Formulation
Find u V such that a(u, v) = (f, v) + g, v where a(u, v) :=
,

v V,

u f v,

v,

(f, v) := g, v

:=

gv.
u n

Note: used Greens formula and

= g on .

Multiscale Summer School p. 59/8

P1 Finite Element
We introduce a triangulation Th of into triangles Ki , and a nite dimensional subspace: Vh := { H 1 () : v |Ki P1 (Ki )}. v

Find u Vh such that a(, v ) = (f, v ) + g, v u


,

Vh . v

Multiscale Summer School p. 60/8

Using Basis Functions


Representing u and v in terms of nodal basis functions {i }M +1 of Vh , we get the following system of i=0 algebraic equations:
M +1

j a(i , j ) = (f, i )+ g, i
j=0

i = 0, . . . , M +1

or in matrix form, A = b, where j = u(Nj ), Aij = a(i , j ) is SPD, and bi = (f, i ) + g, i .

Multiscale Summer School p. 61/8

Mixed Boundary
Let be the unit cube, 0 the face at z = 0, and 1 = \ 0 . Then we want to approximate u in .
1

Multiscale Summer School p. 62/8

Mixed Robin Boundary


Find u V := H 1 () such that u = f u 0 u + 0 =0 n u =0 1 u + 1 n Note: assume i = 0. in , on 0 , on 1 .

Multiscale Summer School p. 63/8

Variational Formulation
Find u V such that a(u, v) or
1 a(u, v) + 0 0 u, v 1 + 1 1 u, v 0 1

u ,v n

u ,v n

= (f, v) ,
1

= (f, v) ,

where a(u, v) and (f, v) are the same as above and u, v


j

:=
j

uv,

j = 0, 1.

Multiscale Summer School p. 64/8

Finite Element Method


We introduce the triangulation Th as before, and the nite dimensional subspace Vh := { H 1 () : u|Ki Q1 (Ki )} u to get the nite element problem: Find u Vh such that
1 a(, v ) + 0 0 u, v u 1 + 1 1 u , v 0 1

= (f, v ) ,

Vh . v

Multiscale Summer School p. 65/8

Using Basis Functions


Representing u and v in terms of nodal basis functions {i }M of Vh we get the following matrix equation: i=1 (A + G) = b, where , A, and b are similar to those above and G0 := i , j ij
1 Gij 0 ,

:= i , j 1 , 0 0 1 1 G := G + G . 0 1

Multiscale Summer School p. 66/8

Parabolic and Elliptic


Build off of elliptic FEM If boundary not moving, space-time rectangular in t dimension Popular to use FEM for spatial discretization and FDM for time Performing FEM rst results in semi-discrete formulation This is equivalent to a coupled system of ODEs

Multiscale Summer School p. 67/8

Scalar Wave Problem


1 Find u H 2 ([0, T ]; L2 ()) L2 ([0, T ]; H0 ()) such that

1 u u = f 2 tt c u=0 u(, 0) = u0 () ut (, 0) = u1 ()

in , in (0, T ), in , in .

Multiscale Summer School p. 68/8

Variational Formulation
1 Find u(, t) : [0, T ] V := H0 () such that

1 (utt , v) + a(u, v) = (f, v) , 2 c (u(, 0), v) = (u0 (), v) , (ut (, 0), v) = (u1 (), v) ,

v V, v V, v V.

Multiscale Summer School p. 69/8

Semi-discrete Formulation
Find u(, t) : [0, T ] Vh such that 1 (h , v ) + a(, v ) = (f, v ) , u u 2 c ((, 0), v ) = (u0 (), v ) , u (uh (, 0), v ) = (u1 (), v ) , Vh , v Vh , v Vh . v

Multiscale Summer School p. 70/8

Using Basis Functions


In matrix form, 1 L(t) + A(t) = b, 2 c L(0) = 0 , L(0) = 1 , t (0, T ),

where , A, and b are as above, and 0 := (u0 , i ) , i 1 := (u1 , i ) , i Lij := (i , j ) .

Multiscale Summer School p. 71/8

Fully Discrete Formulation


In order to discretize in time, we introduce a (uniform) partition of the interval [0,T]: 0 = t0 < t1 < < tNT = T , and k := tn tn1 , n = 1, . . . , NT . 1 n+1 2 n + n1 n n L + A = b , 2 2 c k L 0 = 0 , where in i (tn ) and bn := bi (tn ). i n = 1, . . . , NT ,

L 1 = 0 + k1 ,

Multiscale Summer School p. 72/8

Mass Lumping

Note that the fully discrete formulation is still implicit, thus a linear solve at each time step must be performed. Since Lij := (i , j ) , it is possible to make L diagonal by using a quadrature rule (Trapezoid) for the integration. The resulting explicit method is exactly the FDM. When to lump is an important question; numerical dispersion analysis can show, for example, in 1D consistent mass matrix requires a smaller time step than lumped, and a linear solve! Mass lumping can reduce accuracy, especially in higher dimensions.

Multiscale Summer School p. 73/8

Other Considerations

Integration performed in local coordinates, then global matrix assembled. K may be mapped to reference domain (e.g., [1, 1]) for easy integration (especially quadrature rules). Technically speaking a nite element is a triple: geometric object, nite-dimensional linear function space, and a set of degrees of freedom. Many types of nite elements exist, including some with quadratic or cubic basis functions, rst or second derivatives as degrees of freedom, or degrees of freedom in locations other than vertices (e.g., centroid). More general than FDM, and more easily applied to slanted or curved boundaries, especially involving normal derivative boundary conditions.

Multiscale Summer School p. 74/8

Conservation Laws

Many PDEs are derived from physical models called conservation laws. The general principle is that the rate of change of u(x, t) within a volume V is equal to the ux past the boundary t u(x, t) +
V V

f (u) n = 0

where f is ux function. Nonlinear conservation laws can result in discontinuities in nite time even with smooth initial data.

Multiscale Summer School p. 75/8

Finite Volume Method

Rather than pointwise approximations on a grid, FVM approximates the average integral value on a reference volume. Suppose region Vi = [xi(1/2) , xi+(1/2) ] then
xi+(1/2)

ut dx + f (ui+(1/2) ) f (ui(1/2) ) = 0
xi(1/2)

where we have applied Gausss theorem and integrated xi+(1/2) analytically the resulting term xi(1/2) fx (u)dx.

We can apply a quadrature rule, for example Midpoint, to the remaining integral to get a semi-discrete form xi+(1/2) xi(1/2) ut (xi ) + f (ui+(1/2) ) f (ui(1/2) ) = 0.

Multiscale Summer School p. 76/8

FVM Example
Consider the elliptic equation uxx = f (x) on a control volume Vi = [xi(1/2) , xi+(1/2) ] then
xi+(1/2) xi+(1/2)

uxx dx =
xi(1/2) xi(1/2)

f dx.

Evaluating the left hand side analytically and the right via Midpoint gives ux (xi+(1/2) ) ux (xi(1/2) ) = xi+(1/2) xi(1/2) fi Finally, using centered differences on the remaining derivatives yields ui+1 2ui + ui1 = hfi h for h = xi+(1/2) xi(1/2) .

Multiscale Summer School p. 77/8

FVM Summary

Applies to integral form of conservation law. Handles discontinuities in solutions. Natural choice for heterogeneous material as each grid cell can be assigned different material parameters. There exist theory for convergence, accuracy and stability.

Multiscale Summer School p. 78/8

Systems of Linear Equations


For implicit methods must choose a linear solver. Direct (LU factorization) More accurate May be cheaper for many time steps Banded (otherwise ll-in) Iterative If accuracy less important than speed Matrix-free Sparse SPD

Multiscale Summer School p. 79/8

Iterative Methods

Successive Over Relaxation (SOR) Simple to code = 1 is Gauss-Seidel Conjugate Gradient SPD Eigenvalues clustered together (Precondition) Generalized Minimum Residual (GMRES) Non-SPD, e.g. convection-diffusion with upwinding Krylov method: builds orthonormal basis which may get big (Restart) Preconditioning helps (Incomplete Cholesky)

Multiscale Summer School p. 80/8

References
1. William Ames. Numerical Methods for Partial Differential Equations. Academic Press, Inc., 1992. 2. D. Braess. Finite Elements: Theory, Fast Solvers, and Applications in Solid Mechanics. Cambridge University Press, 2001. 3. N.L. Gibson. Solving a Fluid-plate Interaction Problem Using Finite Element Methods with Domain Decomposition Strategies. Masters thesis, University of Tennessee, Knoxville, 2001. 4. C. Johnson. Numerical solution of partial differential equations by the nite element method. Cambridge University Press New York, 1987. 5. C.T. Kelley. Iterative Methods for Linear and Nonlinear Equations. Society for Industrial & Applied Mathematics, 1995.

Multiscale Summer School p. 81/8

References (Cont)
6. H.P. Langtangen. Computational Partial Differential Equations: numerical methods and Diffpack programming. Springer, 2003. 7. T. Heath Michael. Scientic Computing: An Introductory Survey. McGraw-Hill, 2002. 8. Joaquim Peiro and Spenser Sherwin. Finite Difference, Finite Element and Finite Volume Methods For Partial Differential Equations, in Handbook of Materials Modeling. Volume I: Methods and Models, Springer, 2005.

Multiscale Summer School p. 82/8

Potrebbero piacerti anche