Elliptic PDEs and Solvers LECTURE 3 Elliptic PDEs and Solvers
Aim of Lecture This week we will discuss Overview of Finite Difference Method for Elliptic PDEs Taylor series Forward, Backward, Central Differences Boundary conditions Using EXCEL to solve PDEs Jacobi Gauss-Seidel
Taylor Series Consider the function u expanded about the point i,j. i k
Finite Difference Equations Consider the function u expanded about the point x. Forward Difference Backward Difference NOTE: Order of Truncation Error
Taylor Series Central difference approximations obtained by: Similar approximation for y. i i+1 i-1 j j +1 j - 1 Central Difference
Finite Difference Method Method based on truncated Taylor series i i+1 i -1 j -1 j j+1 ui,j - Forward difference - Backward difference - Central difference - Central difference Above approximations can be substituted for differentials in the PDE.
Laplace Equation - FDM Consider the Laplace equation. i i+1 i -1 j -1 ui,j Difference formula for each node: When h = k we have:
Poisson Equation - FDM Consider the Poisson equation. i i+1 i -1 j -1 ui,j Difference formula for each node: When h = k we have:
Including Boundary Conditions u = a i i+1 i -1 j -1 j j+1 ui,j Two types of boundary conditions Dirichlet u = a Neumann Boundary conditions must be included into the discretised equations j -1 j ui,j j - 2 i -1 i i+1
Dirichlet Boundary Conditions ui,j+1 = 2 i i+1 i -1 j -1 j j+1 ui,j Dirichlet Boundary Conditions: e.g. u = 2 Include boundary value directly
Example i = 1 2 3 4 j = 1 2 3 4 Consider the following square domain and its representation using a Finite Difference Grid. Finite difference approximation u = 1 Y X (1,0) (0,0) (0,1) (1,1) u = 0 Need to solve for internal nodal values
Example Taking h = k = 1/3 we have: Can show that j = 1 2 3 4
Neumann Boundary Conditions j - 2 j -1 j ui,j Either use backward/forward difference so that Or use central difference (need to introduce artificial nodes outside the boundary, but note error) Alternatively, for derivatives in x direction, if then i i+1 i -1 j - 2 j -1 j ui,j
Example i = 1 2 3 j = 1 2 3 Consider the following square domain and its representation using a Finite Difference Grid. Y X (1,0) (0,0) (0,1) (1,1) u = 1
Example Taking h = k = 1/2 we have: So that j = 1 2 3 Taking h = k = 1/2 we have: So that Dirichlet boundary conditions give Using central difference approximation Artificial Node
EXCEL FOR SOLVING FINITE DIFFERENCE EQUATIONS
USING EXCEL Ideal for solving Finite Difference Equations i i+1 i-1 j
Setting Parameters Write Parameter in Name Box: Name Box Formula Box
IF command in Excel Using the IF Command IF(CONDITION, THEN DO THIS, ELSE DO THIS)
Setting up FD Grid in EXCEL Consider Tutorial 3, Question 2 Boundary conditions (grey) Unknowns (white) x values (peach)
Input FD Formula Formula for D16 Formula for D9 Previous Iteration Latest Iteration
Iteration in Excel The Function key (F9) updates all values (1 Iteration) Use the FLAG Parameter FLAG = 0 (sets all cell values back to 0) FLAG = 1 (Starts Iterations) Keep pressing F9 to increment iteration count. EXCEL updates cells in Columns. Can program both Jacobi and Gauss-Seidel.
Iteration in Excel Consider two iterations (Press F9 twice) First Iteration Second Iteration
Solution converged to 4 decimal places Iteration in Excel Continue Iterating (Pressing F9) until convergence Solution converged to 4 decimal places
Gauss Seidel in Excel Even easier than Jacobi (don’t require the old values of the previous iteration) Each cell just uses most up-to-date values Don’t even know/care which order the cells are calculated in Consider Tutorial 3, Question 1
Using Excel – summary/list of tasks Set up the parameters of the problem such as FLAG, h, k, g NB when solving a Laplace equation it is better to set up Excel to solve Poisson and then just set g = 0 Set up the domain (size, x/y values) Fill in the known (Dirichlet) boundary values Work out the general FD formula and copy it across all cells with unknown values Work out FD formulas for all unknown (Neumann) boundary values and copy to relevant cells – next week There should be no cells inside the domain that reference cells outside the domain (apart from parameters like g or h) Double click each boundary cell to check