Você está na página 1de 12

4.3. FINITE DIFFERENCE SOLUTIONS OF THE DIFFUSION EQN.

115

4.3

Finite Dierence Solutions of the Diusion Eqn.

We have developed a wide variety of analytical solutions for the diusion equation with uniform diusivities (eq. (4.2)), including 1D, 2D, and 3D solutions for instantaneous point sources, distributed sources, and continuous sources in an unbounded domain. We have also introduced the method of images, by which we may extend these solutions to problems with perfectly absorbing and no-ux boundaries. However, where diusivities are not uniform, where boundaries are not perfectly absorbing or no-ux, and where boundaries have very complicated shapes, our analytical methods meet their limits, and we must turn to numerical modeling. The simplest numerical modeling technique is the nite dierence method. Let us illustrate the nite dierence method with the following 1D diusion problem: Consdier 1D diusion on the domain L x L for time t 0. Provided that diusion is Fickian, the governing equation is: C = t x Dx C x

where the diusivity Dx = Dx (x, t) is an arbitrary but known function of space and time2 . Since we know the function Dx (x, t), we also know its spatial derivative Dx /x, so we may expand the governing equation as follows: Dx C 2C C = + Dx 2 t x x x Let the initial condition be C (x, t = 0) = C0 (x) where C0 (x) is an arbitrary function of x. Let us dene a general Dirichlet boundary condition at x = L and a no-ux boundary condition at x = L: C (x = L, t) = CB (t) C x =0
x=L

(4.40)

In the case of non-Fickian diusion, Dx may also be a function of the concentration distribution C (x), in which case this problem becomes non-linear. We will discuss linear solutions only, but provided that the nonlinearity is weak, the nite dierence method may be easily extended to nonlinear problems if we linearize them in the example where Dx depends on concentration, we would linearize the problem by using the values of C (x) at the current time step to calculate Dx , then using this current value of Dx to calculate C (x) at the next time step.

Cornell University CEE 6550

(Alexandra King, Seth Schweitzer)

116

CHAPTER 4. THE DIFFUSION EQUATION

The nite dierence approach is to discretize x and t as illustrated below:

and to solve for Cin where Cin C (xi , tn ). In order to solve for Cin , we need to develop a nite dierence formula approximating eq. (4.40). We do so using Taylor series expansion in both space and time to approximate the spatial and temporal derivatives.

4.3.1

Approximating the Derivatives

Lets deal with the spatial derivatives rst: Note that if we know Cin , we may approximate n Cin +1 and Ci1 using Taylor series as follows:
n Cin +1 = Ci +

C x C x

x +
i n

2C x2 2C x2

n i n i

x2 + 2 x2 2

3C x3 3C x3

n i n i

x3 + O(x4 ) 6 x3 + O(x4 ) 6

(4.41)

n Cin 1 = Ci

x +
i

(4.42)

where O(x4 ) denotes terms that are order 4 and higher in x. Cornell University CEE 6550 (Alexandra King, Seth Schweitzer)

4.3. FINITE DIFFERENCE SOLUTIONS OF THE DIFFUSION EQN.

117

n n n There are three ways we can approximate (C/x)n i using Ci , Ci+1 , and Ci1 . Rearranging eq. (4.41), we nd the forward dierence approximation:

C x

=
i

n Cin +1 Ci + O(x) x

(4.43)

Rearranging eq. (4.42), we nd the backward dierence approximation: C x


n

=
i

Cin Cin 1 + O(x) x

(4.44)

And subtracting eq. (4.42) from eq. (4.41), we nd the central dierence approximation: n C n Cin C 1 = i+1 (4.45) + O(x2 ) x i 2x Note that the truncation error is O(x) for the forward and backward dierence approximations, so we say that these approximations are rst order accurate. Since the truncation error is O(x2 ) for the central dierence approximation, we say that it is second order accurate. Since x is small, second order accuracy is better than rst order accuracy. The time derivative, (C/t)n i , may also be approximated using forward, backward, or central dierencing, resulting in accuracy that is O(t), O(t), and O(t2 ), respectively.
n n n There is only one way to approximate ( 2 C/x2 )n i using Ci , Ci+1 , and Ci1 . Adding eq. (4.41) to eq. (4.42) and rearranging a little, we nd the following nite dierence approximation for ( 2 C/x2 )n i

2C x2

=
i

n n Cin +1 2Ci + Ci1 + O(x2 ) x2

(4.46)

4.3.2

The FTCS Scheme

As an example, let us illustrate how to solve for Cin using the FTCS scheme. FTCS stands for Forward dierence in Time and Central dierence in Space. Plugging in the forward dierence approximation for C/t and the central dierence approximation for C/x along with the nite dierence approximation for 2 C/x2 , the governing equation (eq. (4.40)) becomes Cin+1 Cin = t Dx x
n i n n n Cin Cin +1 Ci1 +1 2Ci + Ci1 + (Dx )n + O(t, x2 ) i 2x x2

We see that the FTCS scheme is rst order accurate in time and second order accurate in space. Rearranging, we may solve for concentration at time n + 1 in terms of Cornell University CEE 6550 (Alexandra King, Seth Schweitzer)

118

CHAPTER 4. THE DIFFUSION EQUATION

concentrations at the previous time, n, as follows Cin+1 = Dx t t Dx Dx t t Dx Dx t + Cin Cin + + Cin +1 + 1 2 1 2 2 2 2x x x x 2x x x

n where to make things look neater, we have let Dx = (Dx )n i and Dx /x = (Dx /x)i .

If the diusivity varies slowly (specically, if Dx /x is small compared to 2Dx /x), which we can ensure by picking a small x, then the FTCS scheme simplies to Cin+1 = Note that s Dx t x2 (4.48) Dx t n Dx t n Dx t n C + C + 1 2 C i i +1 x2 x2 x2 i1 (4.47)

is a dimensionless number called the diusion number. In terms of s, we nd the following nite dierence equation for the FTCS scheme:
n n Cin+1 = s Cin +1 + (1 2s) Ci + s Ci1

(4.49)

We may sketch the following computational stencil to illustrate that for the FTCS scheme, the concentration at location i at time n + 1 depends on the three concentrations at locations i 1, i, and i + 1 at time n

We march this computational stencil forward in time to solve for Cin over the whole grid, starting with the initial conditions and imposing the boundary conditions along the way.

Cornell University CEE 6550

(Alexandra King, Seth Schweitzer)

4.3. FINITE DIFFERENCE SOLUTIONS OF THE DIFFUSION EQN.

119

4.3.3

Imposing Initial and Boundary Conditions

Initial Conditions The initial conditions, C (x, t = 0) = C0 (x) give us the concentrations Cin=1 at time n = 1 for all locations i = 1, ..., I . If we apply our stencil (eq. (4.49)) at time n = 1 and locations i = 2, ..., I 1, we can calculate the values of Cin=2 at time n = 2 and locations i = 2, ..., I 1 as illustrated below:

Notice that we cannot calculate the boundary values of Cin=2 located at i = 1 and i = I using our computational stencil, and this is a good thing because otherwise the problem would be over-determined. Before we can calculate concentrations at time n = 3, we n=2 =2 need to impost the boundary conditions to evaluate Cin =1 and Ci=I .

Dirichlet Boundary Condition Imposing the Dirichlet boundary condition, C (x = L, t) = CB (t), is fairly straightforward. We simply use this boundary condition to specify the value of Cin =1 at times n = 2, 3, ... as illustrated below:

Cornell University CEE 6550

(Alexandra King, Seth Schweitzer)

120 Neumann Boundary Condition

CHAPTER 4. THE DIFFUSION EQUATION

Imposing the no-ux boundary condition C x =0


x=L

is a bit more tricky because this boundary condition does not explicitly tell us the value n n of Cin =I . We may use the forward dierence scheme to approximate Ci=I Ci=I 1 , but the forward dierence scheme is only rst order accurate in space! To maintain the second order spatial accuracy of the FTCS scheme, we must create ctitious grid points at i = I + 1 and apply the central dierencing scheme to approximate Cin =I +1 n n Ci=I 1 with second order accuracy. After calculating Ci=I +1 using the central dierence n n approximation, we may use the three known values, Cin =I 1 , Ci=I , and Ci=I +1 and our n+1 stencil (eq. (4.49)) to calculate Ci=I as illustrated below:

Cornell University CEE 6550

(Alexandra King, Seth Schweitzer)

4.3. FINITE DIFFERENCE SOLUTIONS OF THE DIFFUSION EQN.

121

4.3.4

Extending FTCS to 2D and 3D

We may easily extend the FTCS scheme to 2D and 3D diusion problems by writing Taylor series expansions in the y and z-directions. As an example, the FTCS stencil for the 2D diusion equation C = t x Dx C x + y Dy C y

with slowly varying diusivities (i.e., Dx /x << 2Dx /x and Dy /y << 2Dy /y ) is
n+1 n n n n Ci,j = sx Cin +1,j + sx Ci1,j + sy Ci,j +1 + sy Ci,j 1 + (1 2sx 2sy ) Ci,j

(4.50)

where the diusion numbers in x and y have been dened as follows sx This stencil is illustrated below: Dx t Dy t and sy 2 x y 2

This stencil, represented by eq. (4.50), is known as the ve-point stencil because ve points at time n are used to calculate values at time n + 1. Note that we may create a nine-point stencil by incorporating the values of concentration on the diagonals, such as Cin +1,j +1 into our nite dierence approximations of the second derivatives. We will not cover the nine-point stencil in this course, but you can look it up in many books about nite dierence methods. In 3D we can develop a seven-point or a 27-point stencil, depending on whether the diagonals are included. In general (in 1D, 2D, or 3D), higher order approximations of the derivatives may be used to get better accuracy (third order and higher), incorporating even more points into the computational stencil, but second order accuracy is usually enough.

Cornell University CEE 6550

(Alexandra King, Seth Schweitzer)

122

CHAPTER 4. THE DIFFUSION EQUATION

4.3.5

Implicit Schemes

The FTCS scheme is called an explicit scheme because the values of C at time n +1 are calculated explicitly from the values of C at time n. In contrast, an implicit scheme uses the values of C at time n + 1 (and possibly also the values of C at time n) to solve for the values of C at time n + 1. The result is a matrix equation for Cin+1 at each time step. A general implicit scheme for solving the 1D diusion equation has the form:
n+1 n

Cin+1 Cin = t

Dx C 2C + Dx 2 x x x

+ (1 )
i

Dx C 2C + Dx 2 x x x

(4.51)
i

where the dierential equations in parenthesis are discretized (e.g., as demonstrated in Section 4.3.2 for the FTCS scheme), and is a constant between zero and one that determines the amount of weight given to the values of C at times n and n + 1. For an explicit scheme such as the FTCS scheme, = 0 so that no weight is given to the terms at time n + 1; for a fully implicit scheme, = 1 so that no weight is given to the terms at time n. The most popular scheme is probably the Crank-Nicolson scheme for which = 0.5 and central dierencing is used in space. The Crank-Nicolson (C-N) scheme is said to be centered in time because equal weight is given to the values of C at times n and n + 1 in calculating the time derivative3 . Because of this, C-N is accurate to O(t2 , x2 ). This results in less dispersive error compared to the FTCS scheme (more on this soon). The nite dierence equation for the Crank-Nicolson scheme, assuming that Dx /x is small compared to 2Dx /x, works out to

s s n s s n+1 +1 Ci1 + (1 + s) Cin+1 Cin Ci1 + (1 s) Cin + Cin +1 = 2 2 2 2 +1

(4.52)

where s= Dx t x2

Note that even if Dx varies in space and time, it is evaluated at location i and time n for the purpose of calculating s.

C-N could be called the CTCS scheme as it is centered in both time and space, but nobody calls it that.

Cornell University CEE 6550

(Alexandra King, Seth Schweitzer)

4.3. FINITE DIFFERENCE SOLUTIONS OF THE DIFFUSION EQN. Equation (4.52) represents the following a tridiagonal matrix equation:
s (1 + s) 2 s 2

123

n+1 C1

0
s 2

0 0

. . .

. . .

. . .

0 0 0

0 0

s 2

(1 + s)
s 2

s (1 + s) 2

. . . 0 0 . . . . . . . .
s (1 + s) 2 s 2

s 2

s (1 + s) 2

=
s 2 s 2 s 2 n n + + (1 s) C2 C1 n C2 + (1 s) n C3 + (1 s) s 2

n+1 C2 n+1 C3 n+1 C4 . . . n+1 CI 1 n+1 CI n+1 CI +1


n C3

. . .
s 2 s 2 n CI 2 + (1 s) n CI 1 + (1 s)

s n n C3 + 2 C4 s n n C4 +2 C5 s n n CI 1 + 2 CI s n n CI + 2 CI +1

At each time step, we solve this matrix equation for the unknown values of Cin+1 from the known values of Cin . Since the matrix is tridiagonal, we may use the highly ecient Thomas algorithm, also known as the TDMA (the tridiagonal matrix algorithm). The Thomas algorithm solves a tridiagonal matrix in O(I ) steps whereas Gaussian elimination requires O(I 3 ) steps. The Thomas algorithm is suciently popular that you may nd it through a quick internet search. The boundary conditions have been left out of this matrix so that you can ll them in. If we apply a general Dirichlet type boundary condition at i = 1:
n+1 C (x = L, t) = CB (t) C1 = CB (tn+1 )

and a no-ux boundary condition at i = I , discretized using central dierencing and a Cornell University CEE 6550 (Alexandra King, Seth Schweitzer)

124

CHAPTER 4. THE DIFFUSION EQUATION

cticious grid point at i = I + 1 for second order accuracy: C x


n+1 n+1 = 0 CI +1 = CI 1 x= L

how would we impose the boundary conditions within the matrix equation?

4.3.6

Von Neumann Stabiltity Analysis

In a nite dierence solver, initial conditions will have some small numerical error E :

If the error is amplied as time progresses, the solution will become unstable, and the numerical solution will blow up. This is what a solution that is blowing up typically looks like:

How can we predict from the discretized equations whether errors will be amplied or damped out? There are several approaches, but here we will only discuss one. Von Neumanns idea was to represent the initial error as a Fourier series and see what happens to the individual Fourier modes as time progresses. Since the diusion equation is linear, the modes grow independently. The error at time n can be written Ein =

n e E

jix

Cornell University CEE 6550

(Alexandra King, Seth Schweitzer)

4.3. FINITE DIFFERENCE SOLUTIONS OF THE DIFFUSION EQN.

125

where we have adopted the electrical engineering convention that j 1 so we can n use i as the index of the x-axis as we did in the previous sections. is wave number, E n jix e is a single Fourier mode is the Fourier coecient for wave number , and E with wave number . Lets plug a single Fourier mode into the discretized FTCS equation
n n Cin+1 = s Cin +1 + (1 2s) Ci + s Ci1

and see if the amplitude grows or shrinks in time this will tell us if the solution is stable or unstable. The solution is stable if n+1 E 1 n E
n Plugging Cin = E e jix

into the discrete FTCS equation, we nd


j(i1)x

n+1 e E
n Dividing by E e

jix

n e = sE

n e + (1 2s)E

jix

n e + sE

j(i+1)x

jix

n+1 E = se n E Recall that e


j

jx

+ (1 2s) + se

+jx

= cos + j sin , that cos() = cos , and that sin() = sin n+1 E = 2s cos x + (1 2s) En

n+1 n /E 1 for all wave numbers , thus stability of the FTCS Stability requires E scheme requires |2s cos x + (1 2s)| 1

for all values of x. The worst case scenario is x = which requires |1 4s| 1 1 1 4s 1 2 4s 0 2 4s 0 1/2 s 0 So we see that for the FTCS formulation of the diusion equation to be stable, we must have 1 0s 2 Cornell University CEE 6550 (Alexandra King, Seth Schweitzer)

126

CHAPTER 4. THE DIFFUSION EQUATION

Since s = Dx t/x2 , this means that the time step t must be in the range 0 t x2 2Dx

for the FTCS scheme to be stable for all wave numbers. From a physical perspective, the stability requirement for the FTCS scheme is that the computational time step must be smaller than the time it takes the scalar to diuse between two adjacent computational grid points. This seems reasonable: if we want to keep track of the concentration at each grid point at each time step, we cant have the scalar skipping grid points during the time step. Note that since t x2 , if we double the spatial resolution, we have to quadruple the time resolution of our numerical solver!

Cornell University CEE 6550

(Alexandra King, Seth Schweitzer)

Você também pode gostar