Numerical Solution of Laplace Equation By Gilberto E. Urroz, October 2004

Similar documents
Finite Difference Methods (FDMs) 1

MATH 333: Partial Differential Equations

Open boundary conditions in numerical simulations of unsteady incompressible flow

Finite Difference Methods for Boundary Value Problems

Numerical Solution Techniques in Mechanical and Aerospace Engineering

Lecture 9 Approximations of Laplace s Equation, Finite Element Method. Mathématiques appliquées (MATH0504-1) B. Dewals, C.

FINITE VOLUME METHOD: BASIC PRINCIPLES AND EXAMPLES

1 Finite difference example: 1D implicit heat equation

Chapter Two: Numerical Methods for Elliptic PDEs. 1 Finite Difference Methods for Elliptic PDEs

Classification of partial differential equations and their solution characteristics

Notes for Lecture 10

Introduction to Boundary Value Problems

AMS 529: Finite Element Methods: Fundamentals, Applications, and New Trends

Solving the Generalized Poisson Equation Using the Finite-Difference Method (FDM)

Project 4: Navier-Stokes Solution to Driven Cavity and Channel Flow Conditions

Partial Differential Equations (PDEs) and the Finite Difference Method (FDM). An introduction

Partial Differential Equations

Kasetsart University Workshop. Multigrid methods: An introduction

8 A pseudo-spectral solution to the Stokes Problem

Finite Difference Method for PDE. Y V S S Sanyasiraju Professor, Department of Mathematics IIT Madras, Chennai 36

Simple Examples on Rectangular Domains

Basic Aspects of Discretization

Chapter 5 HIGH ACCURACY CUBIC SPLINE APPROXIMATION FOR TWO DIMENSIONAL QUASI-LINEAR ELLIPTIC BOUNDARY VALUE PROBLEMS

ECE539 - Advanced Theory of Semiconductors and Semiconductor Devices. Numerical Methods and Simulation / Umberto Ravaioli

Laplace's equation: the potential between parallel plates

Multiple Integrals and Vector Calculus (Oxford Physics) Synopsis and Problem Sets; Hilary 2015

Math background. Physics. Simulation. Related phenomena. Frontiers in graphics. Rigid fluids

Introduction. Finite and Spectral Element Methods Using MATLAB. Second Edition. C. Pozrikidis. University of Massachusetts Amherst, USA

INTRODUCTION TO PDEs

Numerical Solutions to Partial Differential Equations

PDE Solvers for Fluid Flow

DOING PHYSICS WITH MATLAB ELECTRIC FIELD AND ELECTRIC POTENTIAL: POISSON S EQUATION

Divergence Theorem and Its Application in Characterizing

Part I. Discrete Models. Part I: Discrete Models. Scientific Computing I. Motivation: Heat Transfer. A Wiremesh Model (2) A Wiremesh Model

DOING PHYSICS WITH MATLAB. ELECTRIC FIELD AND ELECTRIC POTENTIAL: POISSON S and LAPLACES S EQUATIONS

Finite Difference Methods (FDMs) 2

Review of Vector Analysis in Cartesian Coordinates

9. Iterative Methods for Large Linear Systems

An Overly Simplified and Brief Review of Differential Equation Solution Methods. 1. Some Common Exact Solution Methods for Differential Equations

AMS526: Numerical Analysis I (Numerical Linear Algebra for Computational and Data Sciences)

Assignment on iterative solution methods and preconditioning

Math 302 Outcome Statements Winter 2013

Solving PDEs with Multigrid Methods p.1

Scientific Computing with Case Studies SIAM Press, Lecture Notes for Unit VII Sparse Matrix

A High-Order Galerkin Solver for the Poisson Problem on the Surface of the Cubed Sphere

Harbor Creek School District

Fundamentals of Transport Processes Prof. Kumaran Indian Institute of Science, Bangalore Chemical Engineering

Industrial Applications of Computational Mechanics Extended Civil Engineering Problems. Prof. Dr.-Ing. Casimir Katz SOFiSTiK AG

Created by T. Madas VECTOR OPERATORS. Created by T. Madas

Finite-Elements Method 2

Additive Manufacturing Module 8

Transformed E&M I homework. Laplaceʼs Equation (Griffiths Chapter 3)

Chapter 2: Numeric, Cell, and Structure Arrays

Preliminary Examination, Numerical Analysis, August 2016

Elements of Vector Calculus : Scalar Field & its Gradient

Fluid flow I: The potential function

Mathematics for Engineers. Numerical mathematics

MAT389 Fall 2016, Problem Set 4

TEST CODE: MMA (Objective type) 2015 SYLLABUS

Math 7824 Spring 2010 Numerical solution of partial differential equations Classroom notes and homework

Finite Difference Methods for

PHYS 410/555 Computational Physics Solution of Non Linear Equations (a.k.a. Root Finding) (Reference Numerical Recipes, 9.0, 9.1, 9.

UNDERSTANDING ENGINEERING MATHEMATICS

Introduction to Vectors

FINITE-VOLUME SOLUTION OF DIFFUSION EQUATION AND APPLICATION TO MODEL PROBLEMS

Parallel Singular Value Decomposition. Jiaxing Tan

Module 7: The Laplace Equation

Finite Differences for Differential Equations 28 PART II. Finite Difference Methods for Differential Equations

Domain decomposition for the Jacobi-Davidson method: practical strategies

Fluid flow II: The stream function

Solution of the Two-Dimensional Steady State Heat Conduction using the Finite Volume Method

Transmission Lines and E. M. Waves Prof. R. K. Shevgaonkar Department of Electrical Engineering Indian Institute of Technology, Bombay

Study of Forced and Free convection in Lid driven cavity problem

Motivation: Sparse matrices and numerical PDE's

Partial Differential Equations

Mathematical Notes for E&M Gradient, Divergence, and Curl

JMBC Computational Fluid Dynamics I Exercises by A.E.P. Veldman

A Hybrid Method for the Wave Equation. beilina

Electro Magnetic Field Dr. Harishankar Ramachandran Department of Electrical Engineering Indian Institute of Technology Madras

Modeling, Simulating and Rendering Fluids. Thanks to Ron Fediw et al, Jos Stam, Henrik Jensen, Ryan

ME Computational Fluid Mechanics Lecture 5

Lecture 28 The Main Sources of Error

5. FVM discretization and Solution Procedure

The method of lines (MOL) for the diffusion equation

Mathematics for Physical Sciences III

AIMS Exercise Set # 1

Linear Algebra Using MATLAB

Electrodynamics and Microwaves 3. Gradient, Curl and Divergence

Numerical Solutions to Partial Differential Equations

Computational Fluid Dynamics Prof. Dr. SumanChakraborty Department of Mechanical Engineering Indian Institute of Technology, Kharagpur

Vectors. 1 Basic Definitions. Liming Pang

" = ˆ i # #x + ˆ j # #y + ˆ k # #z. "t = D #2 h

8. Introduction to Computational Fluid Dynamics

Multiple Integrals and Vector Calculus: Synopsis

Chapter 4. Two-Dimensional Finite Element Analysis

Numerical methods for the Navier- Stokes equations

Finite Element Analysis Prof. Dr. B. N. Rao Department of Civil Engineering Indian Institute of Technology, Madras. Module - 01 Lecture - 11

Chapter 1W Basic Electromagnetic Concepts

Answers to Exercises Computational Fluid Dynamics

Transcription:

Numerical Solution of Laplace Equation By Gilberto E. Urroz, October 004 Laplace equation governs a variety of equilibrium physical phenomena such as temperature distribution in solids, electrostatics, inviscid and irrotational two-dimensional flow (potential flow), and groundwater flow. In order to illustrate the numerical solution of the Laplace equation we consider the distribution of temperature in a two-dimensional, rectangular plate, where the temperature is maintained at given values along the four boundaries to the plate (i.e., Dirichlet-type boundary conditions). he Laplace equation, for this case, is written as 0. [0] x y NOE: While temperature distributions in solids are not of interest to most civil engineering applications, this situation provides a relatively simple physical phenomena that can be analyzed with Laplace s equation. emperature distribution in a rectangular plate he figure below represents a thin rectangular solid body whose temperature distribution is to be determined by the solution of Laplace s equation.. he rectangular body is covered with a computational grid as shown in the figure. Notice that we have arbitrarily divided the domain into 9 sub-domains (e.g., A A B B, etc.) in such a way that each sub-domain contains points on a grid with constant increments x i and y i. Here, the sub-index i describes a given sub-domain, e.g., subdomain A A B B could be identified as i, while sub-domain A A 3 B B 3 would be i, etc. Dirichlet boundary conditions for this case requires us to specify the temperature along the boundaries A A 4, A D, D D 4, and A 4 D 4. Finite difference approximation o produce a numerical solution, we proceed to find the most general finite-difference approximation for the equation on a given interior grid point. We will focus in a point such as B (or B 3, C, C 3 ), which represents the border point of four different sub-domains in the diagram above. he reason for selecting one of these points is that, at that point, the grid has different increments in both x and y, thus, being the most general case possible. his situation is illustrated in the following figure:

In order to find an approximation for the derivative xx we use the following equations:, i i, x x A x xx A, i i, x x B x xx B [] [] Subtracting equation [] from equation [], and solving for x / x while neglecting the terms involving xx / x, results in x i, i, x B x A. [3] Adding equations [] and [], and solving for xx / x, after replacing the expression for x, from [3], results in the following expression: xx, ( ) ( x i, i, A x B ) i i, x B x A x A x B i, o simplify the expression we introduce the following definitions: α x x A x B, β x x A x B, r x α x / β x, γ x x A x B. [4]. hus, ( ) i, xx i, i, r x ( ) i, i, Similarly, by using a aylor series expansion in y, we can obtain the following expression for the following derivatives in y: γ x [5].

y i, i, [6] y A y B and Where, (, ) yy i i, i, r y ( i, i, ) γ y α y y A y B, β y y A y B, r y α y / β y, γ y y A y B. [8]. [7] If we now replace the results of equations [5] and [7] into the Laplace equation, namely, xx yy 0, results in the following finite-difference approximation:, i i, r x ( ) i, i, i, γ x ( i, i, r y ( i, )) i, 0 γ y [9] Explicit solution to the finite-difference equation An explicit solution for the value of the unknown i at the center of the computational cell can be obtained from equation [9]: i γ y ( i, i, r ( x i, i, )) γ ( ( γ x x γ ) y r ( y )) [0] As indicated earlier, the result in equation [0] represents the most general case for the explicit solution for a node in the computational domain with different increments in both x and y. With reference to the grid shown earlier, this corresponds to one of these points: B, B 3, C, or C 3. Other possibilities to consider are illustrated in the following figure and detailed below: 3

Along lines B B, B B 3, B 3 B 4, C C, C C 3, and C 3 C 4 in page (except for the extreme points), where the values of the increment in x remain constant (see case (a) in the figure above): x A x B x, r x α x 0, β x x, γ x x, and i γ y ( i, i, ) x ( ( x γ ) y r ( y )) [] Along lines A B, B C, C D, A 3 B 3, B 3 C 3, and C 3 D 3 in page (except for the extreme points), where the values of the increment in x remain constant, (see case (b) in the figure above): y A y B y, r y α y 0, β y y, γ y y, and i y ( i, i, r ( x ( γ i, x y i, ) )) γ ( x ) [] In the interior points of any of the nine sub-domains shown in the grid diagram above, except for the boundary lines (see case (c) in the figure above): x A x B x, r x α x 0, β x x, γ x x, y A y B y, r y α y 0, β y y, γ y y, and equation [0] simplifies to where, β x/ y. i, i, β ( ) i, [3] ( β ) Explicit solution for uniform grid increments Consider a rectangular domain where the increments in both x and y are uniform. he appropriate equation to use for an explicit solution to the Laplace equation is equation [3]. he solution will start by loading the boundary conditions, and then calculating the values of i in the interior points of the domain. While we are initially tempted to calculate i only once with equation [3], it should be mentioned that these values are only a fist approximation to the solution. In practice, an iterative process must be performed to improve the results until each value i converges to a solution. We should, therefore, add an additional index, k, representing the current iteration, to each solution value. he solution values will now be referred to as k i, and equation [3] will be modified to read: k k k k,, β (,, ) i i i k i. [3-a] ( β ) 4

he iterative process should be repeated until convergence is achieved in every interior point of the domain, or until a maximum number of iterations, say, 000, have been performed. Convergence can be achieved, for example, if, given a tolerance value ε, the maximum difference between two consecutive iterations is less than the tolerance, i.e., if k k max,, ε. i Consider, as an example, a rectangular domain of length L 5 cm, and height H 3.5 cm, with increments x cm, and y 0.5 cm, as illustrated in the figure below. i here will be n L/ x sub-intervals in x, and m H/ y sub-intervals in y, with and x i (i-) x, for i,,, n, y (-) y, for,,, m. he boundary conditions are given as follows: i 5 along the left and right sides of the domain, while the temperatures are given by the function b (x) 5 x (-x) for the top and bottom sides of the domain, respectively. Solution is achieved by using function LaplaceExplicit.m in Matlab : function [x,y,] LaplaceExplicit(n,m,Dx,Dy) echo off; numgrid(n,m); R 5.0; R*ones(n,m); % All () includes all boundary conditions x [0:Dx:n*Dx];y[0:Dy:m*Dy]; % x and y vectors for i :n % Boundary conditions at m and 5

(m) (m) R*x(i)*(-x(i)); () () R*x(i)*(x(i)-); N ; % N new iteration for solution err N-; % Parameters in the solution beta Dx/Dy; denom *(beta^); % Iterative procedure epsilon e-5; % tolerance for convergence imax 000; % maximum number of iterations allowed k ; % initial index value for iteration % Calculation loop while k< imax for i :n for :m N()((i-,)(i,)beta^*((-)()))/denom; err() abs(n()-()); N; k k ; errmax max(max(err)); if errmax < epsilon [X,Y] meshgrid(x,y); figure();contour(x,y,',0);xlabel('x');ylabel('y'); title('laplace equation solution - Dirichlet boundary conditions - Explicit'); figure(3);surfc(x,y,');xlabel('x');ylabel('y');zlabel('(x,y)'); title('laplace equation solution - Dirichlet boundary conditions - Explicit'); fprintf('convergence achieved after %i iterations.\n',k); fprintf('see the following figures:\n'); fprintf('\n'); fprintf('figure - sketch of computational grid \n'); fprintf('figure - contour plot of temperature \n'); fprintf('figure 3 - surface plot of temperature \n'); return fprintf('\n No convergence after %i iterations.',k); o activate the function for the case illustrated in the figure above we use:» [x,y,] LaplaceExplicit(5,7,,0.5) he solution is returned in the vectors x and y, and in matrix. he function produces three plots: a sketch of the grid (similar to the figure above), the solution as a contours, and the solution as a surface. he last two figures are shown next: 6

3.5 Laplace equation solution - Dirichlet boundary conditions - Explicit 3.5 y.5 0.5 0 0 0.5.5.5 3 3.5 4 4.5 5 x Laplace equation solution - Dirichlet boundary conditions - Explicit 00 50 (x,y) 0-50 -00 4 3 y 0 0 x 3 4 5 Successive over-relaxation (SOR) A solution as that provided by equation [3] is referred as a relaxation solution, since the value at each node of the solution domain is slowly relaxed into a convergent solution. A way to accelerate the convergence is by improving the current iteration at point () by using as many values of the current iteration as possible. For example, if we are sweeping the solution grid by rows, ( i.e., by letting the sub-index i vary slower than the sub-index ), at each point i we would already know the value - k. hus, the following version of equation [3] will be used in the solution (notice the different time levels involved k and k): k k k k,, β (,, ) i i i k i. [4] ( β ) 7

An approach referred to as successive over-relaxation (SOR) weights the values of the solution at point i at iteration levels k and k by using weighting factors (-ω) and ω, where ω is known as the over-relaxation parameter. hus, the formula to use is: k ϖ k k k k ( ϖ ) (,, (,, )) i i β i i. [5] ( β ) k he following function, LaplaceSOR.m, calculates the solution for temperature distribution in the rectangular domain of page 5 by using successive over-relaxation as indicated by equation [5]. function [x,y,,k] LaplaceSOR(n,m,Dx,Dy,omega) echo off; numgrid(n,m); R 5.0; R*ones(n,m); % All () includes all boundary conditions x [0:Dx:n*Dx];y[0:Dy:m*Dy]; % x and y vectors for i :n % Boundary conditions at m and (m) (m) R*x(i)*(-x(i)); () () R*x(i)*(x(i)-); N ; % N new iteration for solution err N-; % Parameters in the solution beta Dx/Dy; denom *(beta^); % Iterative procedure epsilon e-5; % tolerance for convergence imax 000; % maximum number of iterations allowed k ; % initial index value for iteration % Calculation loop while k< imax for i :n for :m N()(-omega)*()omega*(N(i,)N(i-,)beta^*(()N(-)))/denom; err() abs(n()-()); N; k k ; errmax max(max(err)); if errmax < epsilon [X,Y] meshgrid(x,y); figure();contour(x,y,',0);xlabel('x');ylabel('y'); title('laplace equation solution - Dirichlet boundary conditions - Explicit'); figure(3);surfc(x,y,');xlabel('x');ylabel('y');zlabel('(x,y)'); title('laplace equation solution - Dirichlet boundary conditions - Explicit'); fprintf('convergence achieved after %i iterations.\n',k); fprintf('see the following figures:\n'); fprintf('\n'); 8

fprintf('figure - sketch of computational grid \n'); fprintf('figure - contour plot of temperature \n'); fprintf('figure 3 - surface plot of temperature \n'); return fprintf('\n No convergence after %i iterations.',k); An exercise using different values of and different values of ω was attempted to elucidate the effect of ω produce the smallest number of iterations. he results for a rectangular grid with n 0, m 0, and different values of β x/ y, are shown next. he results from this sensitivity analysis for successive over-relaxation in a rectangular domain, indicate that values of ω between.5 and.6 produce the smallest number of iterations for the solution, regardless of the value of β. Number of iterations 00 80 60 40 0 00 80 beta 0. beta 0.5 beta beta beta 5 Successive Over-relaxation 60 40 0.3.4.5.6.7.8.9 omega Alternative-direction successive over-relaxation (ADSOR) his approach tries to improve the solution further by sweeping first by rows, producing intermediate values of the solution that are referred to by the iteration number k/, i.e., k ϖ k ( ) ( / k k ( / k ϖ i,,,,, )) i i β i i, [6] ( β ) k / before, sweeping by columns to calculate: k k / ϖ k k / k k / ( ϖ ) i, (,, (,, )) i i β i i, [7] ( β ) 9

While the method indicated by equations [6] and [7] allow for the use of two different SOR parameters, namely, ω and ω, a single value can be used, i.e., ω ω ω. he following function, LaplaceADSOR.m, calculates the solution by using alternatedirection successive over-relaxation as indicated by equations [6] and [7]. function [x,y,,k] LaplaceADSOR(n,m,Dx,Dy,omega,omega) echo off; numgrid(n,m); R 5.0; R*ones(n,m); % All () includes all boundary conditions x [0:Dx:n*Dx];y[0:Dy:m*Dy]; % x and y vectors for i :n % Boundary conditions at m and (m) (m) R*x(i)*(-x(i)); () () R*x(i)*(x(i)-); N ; % N new iteration for solution I ; % I intermediate solution step err N-; % Parameters in the solution beta Dx/Dy; denom *(beta^); % Iterative procedure epsilon e-5; % tolerance for convergence imax 000; % maximum number of iterations allowed k ; % initial index value for iteration % Calculation loop while k< imax for i :n % Sweeping by rows for :m I()(-omega)*()omega*((i,)I(i-,)beta^*(()I(-)))/denom; N I; for :m % Sweeping by columns for i :n N()(-omega)*I()omega*(I(i,)N(i-,)beta^*(()N(-)))/denom; err() abs(n()-()); N; k k ; errmax max(max(err)); if errmax < epsilon [X,Y] meshgrid(x,y); figure();contour(x,y,',0);xlabel('x');ylabel('y'); title('laplace equation solution - Dirichlet boundary conditions - Explicit'); figure(3);surfc(x,y,');xlabel('x');ylabel('y');zlabel('(x,y)'); title('laplace equation solution - Dirichlet boundary conditions - Explicit'); fprintf('convergence achieved after %i iterations.\n',k); fprintf('see the following figures:\n'); 0

fprintf('\n'); fprintf('figure - sketch of computational grid \n'); fprintf('figure - contour plot of temperature \n'); fprintf('figure 3 - surface plot of temperature \n'); return fprintf('\n No convergence after %i iterations.',k); An exercise using different values of β and different values of ω ω ω was attempted to figure out the effect of ω in the number of iterations required for convergence. he results for a rectangular grid with n 0, m 0, and different values of β x/ y, are shown next. 00 000 Alternate-direction Successive Over-relaxation - Explicit beta 0. beta 0.5 beta beta beta 5 Number of iterations 800 600 400 00 0 0. 0.4 0.6 0.8..4.6.8 omega he value of ω that minimizes the number of iterations for convergence is obviously a function of β. he smaller the value of β, the higher the value of w required to minimize the number of iterations. For β 0., for example, ω.6 minimizes the number of iterations for convergence, while for β 5, the value of ω that minimizes the number of iterations is close to.0. An implicit solution Implicit solutions typically consist of solving a number of simultaneous algebraic equations involving the unknown values i in the interior points of the solution domain. For example, for points in the domain not contiguous to a boundary, i.e., for i, 3,, n-, and, 3,, m, the algebraic solutions to solve result from re-writing equation [3] to read:

i, i, i ( β ) β ( ) 0. [8] We ll refer to these points as the main domain. here are (n-3)(m-3) points in the main domain, thus, producing (n-3)(m-3) equations. he main domain and other sub-domains of interest are shown in the following figure. For points contiguous to boundaries, the following equations apply: Left bottom corner (L,B):, 3, ( β ), β (,, 3) 0. Left top corner (L,):, m 3, m ( β ), m β (, m, m ) 0. Right bottom corner (R,B): n, n, ( β ) n, β ( n, n, 3) 0. Right top corner (R,): n, m n, m ( β ) n, m β ( n, m n, m ) 0. Along the line i :, 3, ( β ), β (,, ) 0. Along the line i n: n, n, ( β ) n, β ( n, n, ) 0. Along the line : i, i, ( β ) i, β ( i, i, 3) 0. Along the line m: ( β ) β ( ) 0. i, m i, m m m m Notice that in these equations the values of,,,,,m,,m, n,, n,, n,m, n,m,,, n,,, and m are known. he corners, (L,B), (L,), (R,B), and (R,), produce 4 more equations besides the (n-3)(m-3) equations from the main domain. Lines i and i n produce (n-3) equations each, while the lines and m produce (m-3) equations each. hus, the

total number of equations produced is (n-3)(m-3) 4 (n-3) (m-3) (n-)(m-), which corresponds to the number of unknowns (n-)(m-) (n-)(m-). herefore, the system of equations should be, at least, in principle, uniquely determined. he system of equations can be cast as a matrix equation where the unknowns are the values i in the interior points of the solution domain. A difficulty that arises at this point is trying to write the matrix equation in terms of unknown variables having a single sub-index. his difficulty can be overcome by replacing the unknown i with the unknown X k where k (-)(n-) i. his way, the variables X k take the place of the variables i so that X,, X,3, etc., resulting in (n-)(m-) variables X k. he implicit solution is implemented in function LaplaceImplicit.m. he function uses sparse matrices, since a large number of elements of the matrix of coefficients for the system of equations are zero. A graph of the solution domain, diagrams of the matrix of coefficients and of the right-hand side vector, as well as graphics of the solution are produced by the function. function [x,y,] LaplaceImplicit(n,m,Dx,Dy) echo off; % he following function calculates index k for X(k) corresponding to % variable (), such that k (-)*(n-)i- k inline('(-)*(n-)i-','i','','n'); numgrid(n,m); % Shows numerical grid R 5.0; R*ones(n,m); % All () includes all boundary conditions x [0:Dx:n*Dx];y[0:Dy:m*Dy]; % x & y points in solution domain for i :n % Boundary conditions at m and (m) (m) R*x(i)*(-x(i)); () () R*x(i)*(x(i)-); beta Dx/Dy; % Parameters of the solution denom -*(beta^); kk (n-)*(m-); A zeros(kk,kk); b zeros(kk,); kvl []; kvr []; kvc []; kvb []; kv []; %main domain for i 3:n- for 3:m- kek(,n);klk(i-,,n);krk(i,,n); kck(,n);kbk(-,n);kk(,n); A(ke,kL) ; A(ke,kR) ; A(ke,kC) denom; A(ke,kB) beta^; A(ke,k)beta^; b(ke) 0; %Left-Bottom corner i;;kek(,n);krk(i,,n);kck(,n);kk(,n);b(ke)-(i-,)-beta^*(-); A(ke,kR) ; A(ke,kC) denom;a(ke,k)beta^; %Left-op corner i;m;kek(,n);krk(i,,n);kck(,n);kbk(-,n);b(ke)-(i-,)-beta^*(); A(ke,kR) ; A(ke,kC) denom;a(ke,kb) beta^; %Right-Bottom corner 3

in;;kek(,n);klk(i-,,n);kck(,n);kk(,n);b(ke)- (i,)-beta^*(-); A(ke,kL) ; A(ke,kC) denom;a(ke,k)beta^; %Right-op corner in;m;kek(,n);klk(i-,,n);kck(,n);kbk(-,n);b(ke)- (i,)-beta^*(); A(ke,kL) ; A(ke,kC) denom; A(ke,kB) beta^; %i (left column) i; for 3:m- kek(,n);krk(i,,n);kck(,n);kbk(-,n);kk(,n);b(ke)-(i-,); A(ke,kR) ; A(ke,kC) denom; A(ke,kB) beta^; A(ke,k)beta^; %in (right column) in; for 3:m- kek(,n);klk(i-,,n);kck(,n);kbk(-,n);kk(,n);b(ke)-(i,); A(ke,kL) ; A(ke,kC) denom; A(ke,kB) beta^; A(ke,k)beta^; % (bottom row) ; for i 3:n- kek(,n);klk(i-,,n);krk(i,,n);kck(,n);kk(,n);b(ke)-beta^*(-); A(ke,kL) ; A(ke,kR) ; A(ke,kC) denom; A(ke,k)beta^; %m (top row) m; for i 3:n- kek(,n);klk(i-,,n);krk(i,,n);kck(,n);kbk(-,n);b(ke)-beta^*(); A(ke,kL) ; A(ke,kR) ; A(ke,kC) denom; A(ke,kB) beta^; % Create sparse matrix A and sparse vector b As sparse(a); figure();spy(as);title('matrix of coefficients'); % Picture of sparse matrix A bs sparse(b); figure(3);spy(b);title('right-hand side vector'); % Picture of sparse vector b XX As\bs; % Solve using left division % Convert solution back to (), i.e., () X(k), with k - )*(n-)i- for i :n for :m ke k(,n); () XX(ke); [X,Y] meshgrid(x,y); % Generate grid data for contour plot and surface plot figure(4);contour(x,y,',0);xlabel('x');ylabel('y'); title('laplace equation solution - Dirichlet boundary conditions - Implicit'); figure(5);surfc(x,y,');xlabel('x');ylabel('y');zlabel('(x,y)'); 4

title('laplace equation solution - Dirichlet boundary conditions - Implicit'); % Indicate list of figures produced fprintf('see the following figures:\n'); fprintf('\n'); fprintf('figure - sketch of computational grid \n'); fprintf('figure - diagram of matrix of coefficients \n'); fprintf('figure 3 - diagram of right-hand side vector \n'); fprintf('figure 4 - contour plot of temperature \n'); fprintf('figure 5 - surface plot of temperature \n'); An example is calculated by using:» [x,y,] LaplaceImplicit(0,0,,); Results for this case are shown below. 0 8 6 4 0 0 4 6 8 0 Figure showing the solution domain. 5

0 Matrix of coefficients 0 0 30 40 50 60 70 80 0 0 0 30 40 50 60 70 80 nz 369 Spy graph of sparse matrix of coefficients. Right-hand side vector 0 0 0 30 40 50 60 70 80 0 nz 3 Spy graph of sparse right-hand side vector. 6

0 Laplace equation solution - Dirichlet boundary conditions - Implicit 9 8 7 6 y 5 4 3 0 0 3 4 5 6 7 8 9 0 x Contour plot of temperatures Laplace equation solution - Dirichlet boundary conditions - Implicit 400 00 (x,y) 0-00 -400 0 5 y 0 0 4 x 6 8 0 Surface plot of temperatures 7

Successive over-relaxation semi-implicit scheme he main difficulty of the implicit approach described earlier is that not all domains produce systems of equations that can be easily re-cast into a sparse matrix equation. In order to simplify the solution, a semi-implicit successive over-relaxation scheme is proposed. his scheme is such that, in each sweep by rows, a tri-diagonal system of equations is produced. his tri-diagonal system can be easily solved using the homas algorithm (described later). he equation to be used in each interior point, sweeping by rows, is: which can be re-cast as k k k k,, β (,, ) i i i k i, ( β ) k i, i, k k k k ( β ) β ( ). [9] For each value of, as we let i, 3,, n, we produce (n-) equations in (n-) unknowns. hese are solved using the homas algorithm. hen, the value of is incremented, so that, 3,, m, and new solutions calculated for each value of. he process is iterative, and convergence should be checked by using, for example, the criteria: k k max ε. [0] Alternate-direction successive over-relaxation semi-implicit scheme In this scheme tri-diagonal systems of equations are produced by first sweeping by rows, to produce intermediate values i k/, and then sweeping by columns to produce the new iteration values i k. he equations to use are: k ϖ k ( ) ( / k k ( / k ϖ i,,,,, )) i i β i i, [] ( β ) k / before, sweeping by columns to calculate: k k / ϖ k k / k k / ( ϖ ) i, (,, (,, )) i i β i i, [] ( β ) homas (or double sweep) algorithm his algorithm is described briefly in Vreughdenhill s Computational Hydraulics, section 7.4 (pages 40 and 4) for the specific case of the implicit Crank-Nicholson method for the diffusion equation. In this section, the homas, or double-sweep, algorithm is described for the numerical solution of Laplace s equation in a rectangular domain. 8

he algorithm solves a tri-diagonal system of equations of the form a k h k- b k h k c k h k d k, [3] for k,,, N, with a 0 and c N 0. hus, only the main diagonal of the matrix of coefficients and the two adacent diagonals in this system are non-zero (hence, the name tri-diagonal). he values of the constants a k, b k, c k, and d k are obtained from the implicit equations with the appropriate definitions of the variables h k. For example, if we were to obtain the tridiagonal equations for the implicit equation given in [9], namely, i, i i, ( β ) β ( ), [9] while sweeping by rows (i.e., is constant), make the replacements k N n, h k- i-,, h k, and h k i, in equation [3]. hus, the constants to use in this case would be a k c k, b k -(β ), and d k -β ( - ), [9-b] for k,, N- and a fixed value of. he equations and constants corresponding to ki and k i n, will be determined by the boundary conditions of the problem at x x and x x n, respectively. (NOE: it is assumed that the solution grid has n subintervals in x and m sub-intervals in y). If we were to use homas algorithm to solve the implicit equation in [9] while sweeping by columns (i.e., i remains constant), you can prove that the proper replacement of indices and variables would be k, N m, h k- -, h k, and h k in equation [3]. he corresponding constants in equation [3] for this case would be: a k c k, b k -(β ), and d k -β ( i-, i, ), [8-c] for k,, m- and a fixed value of. he equations and constants corresponding to k and k m, will be determined by the boundary conditions of the problem at y y and y y m, respectively. (NOE: using equations [] and [], the constants in [3] would have a more complicated expression). he algorithm postulates the following relationship for the solution of the system of equations [3]: h k e k f k h k, [4] where dk akek d ek, e [5] b a f b k k k f k b k ck a f k k, f c b [6] 9

he algorithm should proceed as follows: Apply upstream boundary condition (i.e., at k ) to calculate e and f. Calculate the coefficients e k, f k for k,, N. Apply downstream boundary condition to calculate h N. Perform a backward sweep calculating the values of h k from equation [4] for k N, N-,. Exercises part I []. (a) Write a function to implement the successive over-relaxation semi-implicit scheme described above. (b) Use the function to solve for the temperature distribution in the rectangular domain described earlier. []. (a) Write a function to implement the alternate-direction successive over-relaxation semi-implicit scheme described above. (b) Use the function to solve for the temperature distribution in the rectangular domain described earlier. (c) Produce a plot showing the effect of the value of ω on the number of iterations required to achieve a solution for different values of β x/ y. NOE: he following figure applies to problems [3] and [4]: [3]. (a) Use an explicit scheme without over-relaxation to solve for the temperature distribution in the domain shown above. (b) Produce a contour plot of the temperature. Let L L 3 5 cm, L 0 cm, x x x 3 x cm, H 3 cm, H 5 cm, y y y 3 y 0.5 cm. Let the boundary conditions for the temperature be such that: 0 o C along BC. decreases linearly from 0 o C at B and C down to 0 o C at A and D, respectively. increases linearly from 0 o C at A and D, to 5 o C at H and E, respectively. increases linearly from 5 o C at H and E to 7.5 o C at G and F, respectively. 0

Along GF, increases linearly from 7.5 o C at G and F towards the mid-point of segment GF, where it reaches a maximum value of 0 o C. [4]. (a) Use an explicit scheme without over-relaxation to solve for the temperature distribution in the domain shown above. (b) Produce a contour plot of the temperature. Let L L 3 5 cm, L 0 cm, x cm, x 0.5 cm, x 3.5 cm, H 4 cm, H cm, y cm, y.5 cm, y 3 0.5 cm. Use the same boundary conditions as in problem [3]. NOE: he following figure applies to problems [5] and [6]: [5]. (a) Use an explicit scheme without over-relaxation to solve for the temperature distribution in the domain shown above. (b) Produce a contour plot of the temperature. Let L 5 cm, L 4 cm, x x x cm, H 3 cm, H cm, y y y 0.5 cm. Let the boundary conditions for the temperature be such that: 0 o C along BC. decreases linearly from 0 o C at C to 5 o C at D. decreases linearly from 5 o C at D to 0 o C at E. 0 o C along EF and FA. increases linearly from 0 o C at A to 0 o C at B. [6]. (a) Use an explicit scheme without over-relaxation to solve for the temperature distribution in the domain shown above. (b) Produce a contour plot of the temperature.

Let L 5 cm, L 4 cm, x.5 cm. x 0.5 cm, H 3 cm, H cm, y cm, y 0.5 cm. Laplace equation solution in simple non-rectangular domains he figure below shows a two-dimensional thin solid body formed by removing the trapezoidal shape B B 3 B 4 B 4 from the rectangular shape A A 4 B B 4. he resulting shape has side B B 3 tilted by an angle θ with respect to the horizontal line B B B 4. he computational grid attached to the irregular shape above is designed so that there are a number of equally spaced grid nodes along the inclined size B B 3. he rectangular grid with increments x and y, that define the grid nodes along the inclined side, are related by tan θ y / x. he figure shows 5 different solution domains with varying size increments in x and y. Expressions for the finite-difference approximation for Laplace s equation in each of the domains, and on their boundaries, can be found, for example, by using equations [0] through [3]. he following Matlab script can be used to produce the plot of the irregularly-shaped body shown above for specific values of the dimensions L, L, L 3, H, and H : % Script for plotting irregularly-shaped body and computational grid % Calculating the geometry Dx 0.50; Dx 0.75; Dx3.00; L 3.00; L 4.50; L3 6.00; n L/Dx; n L/Dx; n3 L3/Dx3; i n; i in; i3 in3; theta 30*pi/80; Dy Dx*tan(theta); Dy 0.5; H L*tan(theta); H.00; m round(h/dy); m round(h/dy); m; mm; % Calculating coordinates x [0:Dx:L,LDx:Dx:LL,LLDx3:Dx3:LLL3]; y [0:Dy:H,HDy:Dy:HH]; % Plot solution domain figure(); plot([x(),x(i)],[y(),y()],'-b');hold on; plot([x(i),x(i)],[y(),y()],'-b');

plot([x(i),x(i3)],[y(),y()],'-b'); plot([x(i3),x(i3)],[y(),y()],'-b'); plot([x(),x(i3)],[y(),y()],'-b'); plot([x(),x()],[y(),y()],'-b'); axis([- 4-5 0]); % Plot solution grid for : plot([x(),x(i)],[y(),y()]); for :- plot([x(),x(i3)],[y(),y()]); for i :i plot([x(i),x(i)],[y(),y()]); for i i:i3- plot([x(i),x(i)],[y(),y()]); ii [i::i]; [::]; for i :n plot([x(i),x(ii(i))],[y((i)),y((i))]); plot([x(ii(i)),x(ii(i))],[y((i)),y()]); hold off; he following figure shows the result: 0 5 0-5 0 4 6 8 0 4 3

Outline of an explicit solution with Dirichlet boundary conditions For Dirichlet-type boundary conditions, the temperature will be known in every grid point on the boundary. For example, along the inclined boundary B B 3, the values of i, with () (i,),(i,),,( i, ) must be known. he algorithm for an implicit solution would proceed as follows: Load boundary conditions on all grid points on the boundaries. Use equation [0] for point C. Use equation [] for the points on lines C C and C B 3. Use equation [] for points on the lines A C, C B, and A 3 B 3. Finally, use equation [3] for interior points in each of the 5 domains. he solution is iterative, with a convergence criteria such as equation [0] used to determine when a solution has been achieved. hus, the explicit solution approach is very similar to that of a rectangular domain. NOE: Implicit solutions can also be set up following the approach used for rectangular domains after defining a solution grid as the one shown above. Exercises part II [7]. For the irregularly-shaped domain shown below, (a) use an explicit method to solve the Laplace equation for temperature distribution (equation [0]) as specified below. he dimensions of the figure are: L 0 cm, L 5 cm, L 3 8 cm, H 5 cm, H 3 cm, H 3 cm, x cm, x 0.5 cm, x 3 cm, y 0.5 cm, y 0.5 cm, y 3 0. cm. Boundary conditions: 80 o C along A B C D, 60 o along A B C D, varies linearly along A A 3 A 4 A as well as along D D, so that the temperature at the boundaries is continuous. (b) Produce a contour plot of the temperature distribution. Derivation of Laplace s and Poisson s equation in heat transfer in solids he heat flux (per unit area), q x, along the x direction is given by the equation 4

q x k, [7] x where k is the thermal conductivity of the material, and is the temperature. Equation [7] indicates that the heat flux q[j/m ] is proportional to the temperature gradient,, and that heat flows in the direction of decreasing temperature. he units of k are J/ o K m. It is possible to define a heat flux vector that accounts for heat fluxes in both the x and y directions for a two-dimensional case. hus, the heat flux vector would be written as: q qxi q y k i k k( i ) k grad( ) k. [8] x y x y In equation [], the differential expression the temperature, i.e., i x y is referred to as the gradient of grad( ) i. [9] x y he differential operator, called the del or nabla operator, is defined by: [ ] [ ] [ ] i. [30] x y When applied to a scalar function, such as temperature (x,y), the del operator produces a gradient (equation [9]). If applied to a vector function, e.g., to the heat flux vector from equation [8], through a dot or scalar product operation, we obtain the divergence of the vector function, e.g., q q x y div( q) q. [3] x y he divergence of a gradient of a scalar function produces the Laplacian of the scalar function, e.g., for the scalar function φ(x,y,z), φ φ φ φ φ φ div( grad( φ)). x x x y x y For the heat flux vector of equation [8], the divergence of that heat flux produces: div( q ) div( k grad( )) ( k ) k. [3] NOE: Equations [8] through [3] can be expanded to three dimensions by adding the corresponding derivatives with respect to z. he development presented here is strictly two-dimensional. 5

Poisson s equation Consider a two-dimensional body of thickness z that produces Q Joules of heat per unit volume in every point within the body. his heat is transported by the heat fluxes in both the x and y directions such that the net flux out of a point (measured by the divergence of the flux vector) is equal to the heat produced Q, i.e., div (q) k Q. [33] Re-writing equation [33], we find the following Poisson s equation for heat transfer with net heat production in every point: x y Q. [34] k Laplace s equation If there is no production of heat in the body of interest, then Q 0, and Poisson s equation [34] reduces to Laplace s equation: 0. [35] x y Neumann boundary condition in heat transfer in solids o incorporate a Neumann-type of boundary condition in heat transfer in solids we would need to postulate the heat flux at a given boundary. For example, if in the rectangular domain shown below, we indicate that the heat flux through, say, face BD is q x q o, then the corresponding boundary condition is: x BD qo k. [36] If face BD is thermally insulated, then no heat flux can occur through it, and the proper boundary condition is / x BD 0. he handling of Neumann-type of boundary conditions in the solution of Laplace s equation is presented in detail in a separate document on two-dimensional potential flow solutions. 6