Professional Documents
Culture Documents
Nasser M. Abbasi
Contents
1 Introduction 1
1.1 Derivations of formulas for Neumann boundary conditions . . . . . . . . . . . . . . . . . 3
1.1.1 Left edge . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3
1.1.2 Right edge . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5
1.1.3 Top edge . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6
1.1.4 Bottom edge . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6
4 References 9
1 Introduction
This is a derivation of the 2D Laplacian finite difference approximation on 2D grid with Neumann
boundary conditions for solving the elliptic PDE.
The PDE is
2 u = f (x, y)
2u 2u
+ = f (x, y)
x2 y 2
The derivation is given for the general case of non-uniform grid (meaning hx is not equal to hy ). At
the end it is simplified to uniform grid by setting hx = hy .
Notation used is based on the following grid where it is assumed that the grid size is n n
1
Starting with centered difference scheme
Ui,j1 2Ui,j + Ui,j+1 Ui1,j 2Ui,j + Ui+1,j
+ = fi,j
h2x h2y
And solving for Ui,j gives
1 1 Ui,j1 Ui,j+1 Ui1,j Ui+1,j
2 2
+ 2 Uij + + = fi,j
hx hy h2x h2y
2
hx + h2y h2y (Ui,j1 + Ui,j+1 ) h2x (Ui1,j + Ui+1,j )
2 Uij + = fi,j
h2x h2y h2x h2y
2 h2x + h2y h2y (Ui,j1 + Ui,j+1 ) + h2x (Ui1,j + Ui+1,j )
U ij = fi,j
h2x h2y h2x h2y
Hence
1 h2x h2y
h2y (Ui,j1 + Ui,j+1 ) + h2x (Ui1,j + Ui+1,j ) +
Ui,j = fi,j (1A)
2 h2x + h2y 2 h2x + h2y
Therefore, for node i, j the equation 2 u = f (x, y) becomes
!
h2y (Ui,j1 + Ui,j+1 ) + h2x (Ui1,j + Ui+1,j ) 2 h2x + h2y Ui,j
= fi,j
h2x h2y
2 h2x + h2y Ui,j + h2y (Ui,j1 + Ui,j+1 ) + h2x (Ui1,j + Ui+1,j ) = h2x h2y fi,j
2
1.1 Derivations of formulas for Neumann boundary conditions
Below is the derivation of the discretization for the case when Neumann boundary conditions are used.
The value of the unknown u (x, y) is not given on the left boundary, only its derivative (in the normal
direction to the edge, pointing outwards) is given. Therefore it is not possible to use the standard 5-point
Laplacian on the first column j = 1, since that requires u be known on the left edge.
Therefore, when j = 1, then Ui,1 is not known (if this was a Dirichlet boundary conditions, then Ui,1
will be known).
Neumann boundary conditions are handled as follows. Taking the case of the left edge, an imaginary
boundary located hx to the left of the actual left edge is added as shown below
3
u u Ui,2 Ui,0
Then x
is approximated on the line j = 1 by using x
2hx
. Therefore for j = 1 the following
results
Ui,2 Ui,0
= gi,1 (2)
2hx
From eq (1A) above, given below again
1 h2x h2y
h2y (Ui,j1 + Ui,j+1 ) + h2x (Ui1,j + Ui+1,j ) +
Ui,j = fi,j
2 h2x + h2y 2 h2x + h2y
When j = 1 the above becomes
1 h2x h2y
h2y (Ui,0 + Ui,2 ) + h2x (Ui1,1 + Ui+1,1 ) +
Ui,1 = fi,j (3)
2 h2x + h2y 2 h2x + h2y
But using Eq. (2) gives
Ui,0 = Ui,2 2hx gi,1
Substituting the above into Eq. (3) results in
1 2 2
h2x h2y
Ui,1 = hy (Ui,2 2hx gi,1 + Ui,2 ) + hx (Ui1,1 + Ui+1,1 ) + fi,j (3A)
2 h2x + h2y 2 h2x + h2y
An expression for U on the left edge is obtained. This will be added to the set of the equations to
solve for.
Hence, For Neumann boundary conditions, the process starts by looking for the edge which have this
condition specified on it, and for each such edge a set of equations as the above are added to the current
set of equations for the internal points.
Therefore, for node (i, 1) the equation 2 u = f becomes
4
2 h2x + h2y Ui,1 h2y (2Ui,2 2hx gi,1 ) h2x (Ui1,1 + Ui+1,1 )
= fi,j
h2x h2y
2 h2x + h2y Ui,1 h2y (2Ui,2 2hx gi,1 ) h2x (Ui1,1 + Ui+1,1 ) = h2x h2y fi,j
The edge points which have Neumann boundary conditions are initialized the same way as the internal
units before the iterative process begins.
Eq. (3A) above reduces to the standard one when hx = hy giving
1
2Ui,2 2hx gi,1 + Ui1,1 + Ui+1,1 + h2 fi,j
Ui,1 =
4
2
Therefore, the equation u = f for such a node becomes
1 h2x h2y
h2y (Ui,j1 + Ui,j+1 ) + h2x (Ui1,j + Ui+1,j ) +
Ui,j = fi,j
2 h2x + h2y 2 h2x + h2y
For j = n it becomes
1 2 2
h2x h2y
Ui,n = hy (Ui,n1 + Ui,n+1 ) + hx (Ui1,n + Ui+1,n ) + fi,n (2)
2 h2x + h2y 2 h2x + h2y
But from Eq. (1)
Ui,n+1 = Ui,n1 2hx qi,n
Substituting the above into Eq. (2) results in
1 h2x h2y
h2y (2Ui,n1 2hx qi,n ) + h2x (Ui1,n + Ui+1,n ) +
Ui,n = fi,n (3)
2 h2x + h2y 2 h2x + h2y
Therefore, for node (i, n) the equation 2 u = f becomes
2 h2x + h2y Ui,n h2y (2Ui,n1 2hx qi,n ) h2x (Ui1,n + Ui+1,n )
= fi,n
h2x h2y
Eq. (3) reduces to the standard one when hx = hy giving
1
2Ui,n1 2hx qi,n + Ui1,n + Ui+1,n + h2 fi,n
Ui,n =
4
5
Therefore, equation 2 u = f for such a node becomes
1 2 2
h2x h2y
Ui,j = hy (Ui,j1 + Ui,j+1 ) + hx (Ui1,j + Ui+1,j ) + f1,j
2 h2x + h2y 2 h2x + h2y
For the i = 1 it becomes
1 h2x h2y
h2y (U1,j1 + U1,j+1 ) + h2x (U0,j + U2,j ) +
U1,j = f1,j (2)
2 h2x + h2y 2 h2x + h2y
But from Eq. (1)
U0,j = U2,j 2hy 1,j
Substituting the above into Eq. (2) results in
1 h2x h2y
h2y (U1,j1 + U1,j+1 ) + h2x (2U2,j 2hy 1,j ) +
U1,j = f1,j (3)
2 h2x + h2y 2 h2x + h2y
Therefore, for node (1, j) equation 2 u = f becomes
2 h2x + h2y U1,j h2y (U1,j1 + U1,j+1 ) h2x (2U2,j 2hy 1,j )
= f1,j
h2x h2y
2 h2x + h2y U1,j h2y (U1,j1 + U1,j+1 ) h2x (2U2,j 2hy 1,j ) = h2x h2y f1,j
Eq. (3) reduces to the standard one when k = 0 and when hx = hy giving
6
From Eq. (1A) above, shown below again
1 2 2
h2x h2y
Ui,j = hy (Ui,j1 + Ui,j+1 ) + hx (Ui1,j + Ui+1,j ) + fn,j
2 h2x + h2y 2 h2x + h2y
For i = n it becomes
1 h2x h2y
h2y (Un,j1 + Un,j+1 ) + h2x (Un1,j + Un+1,j ) +
Un,j = fn,j (2)
2 h2x + h2y 2 h2x + h2y
But from Eq. (1)
Un+1,j = Un1,j 2hy n,j
Substituting the above into Eq. (2) results in
1 h2x h2y
h2y (Un,j1 + Un,j+1 ) + h2x (2Un1,j 2hy n,j ) +
Un,j = fn,j (3)
2 h2x + h2y 2 h2x + h2y
Therefore, for node (n, j) equation 2 u = f becomes
2 h2x + h2y h2x h2y k 2 Un,j h2y (Un,j1 + Un,j+1 ) h2x (2Un1,j 2hy n,j )
= fn,j
h2x h2y
Eq. (3) reduces to the standard one when k = 0 and when hx = hy giving
7
2 Generating the solution equation for Jacobi iteration
From Eq. (1A) it was found that
1 2 2
h2x h2y
Ui,j = hy (Ui,j1 + Ui,j+1 ) + hx (Ui1,j + Ui+1,j ) + fi,j (1)
2 h2x + h2y 2 h2x + h2y
2 u = f is the following
!
h2y (Ui,j1 + Ui,j+1 ) + h2x (Ui1,j + Ui+1,j ) 2 h2x + h2y Ui,j
= fi,j
h2x h2y
Hence
The residue is
rij = fij + 2 u
!
h2y (Ui,j1 + Ui,j+1 ) + h2x (Ui1,j + Ui+1,j ) 2 h2x + h2y Ui,j
= fij + (2)
h2x h2y
8
rij = fij + 2 u
!
h2y (Ui,j1 + Ui,j+1 ) + h2x (Ui1,j + Ui+1,j ) 2 h2x + h2y Ui,j
= fij + (2)
h2x h2y
It is important in the above, to find the residual before updating the cell. In the code, the following
should be used
k !
h2y Ui,j1
k k
+ Ui,j+1 + h2x Ui1,j
k k
+ Ui+1,j 2 h2x + h2y Ui,j
rij = fij +
h2x h2y
k
h2y Ui,j1
k k
+ Ui,j+1 + h2x Ui1,j
k k
+ Ui+1,j + h2x h2y fi,j
Ui,j =
2 h2x + h2y
4 References
1. Applied Mathematics by David Logan, chapter 8
2. http://en.wikipedia.org/wiki/Helmholtz/equation