A.3.3 Some Values for the Gamma Function Because,
12.6 FINITE DIFFERENCE NUMERICAL SOLUTIONS OF FICK’S SECOND LAW
12.6.1 f
Ick’
ss
econdl
aWInf
InIted
Ifferencef
ormIn Chapter 3, Euler’s method was used to numerically solve ordinary differential equations by using a difference equation for the derivative, that is,
dC dx
C x x C x
≅
(
+∆x)
−( )
∆ (12.25)
which is the definition of the derivative in the limit of ∆x→0. As was mentioned then, this type of solution is called the finite difference technique and how it is applied is covered extensively in the literature (e.g., Lapidus and Pinder 1982; Celia and Gray 1992; Johnson 2009). One attractive feature of this technique is that it lends itself very nicely to solution with a spreadsheet program. As might be expected, partial differential equations can also be solved by a finite difference approach with a spreadsheet if the geometry and boundary conditions are not too complicated. Yet, fairly complex problems can be solved by the technique with relatively simple programs (Kee et al. 2003)*.
Now, Equation 12.25 is the forward difference equation for the derivative. A backward difference could also be used
dC dx
C x C x x
≅
( )
− x(
−∆)
∆ (12.26)
with the same result. Fick’s second law, ∂ ∂ =C t D/ (∂2C x/∂ 2), a forward difference can be taken for
∂ ∂C t, specifically,
∂
∂C≅
(
+)
−( )
t
C x t t C x t t
, ,
∆ .
∆ (12.27)
Similarly, the first derivative with respect to x can be given by a forward difference,
∂
∂C≅
(
+)
−( )
x
C x x t C x t x
∆
∆
, , . (12.28)
* The finite difference technique is not to be confused with the finite element approach, which is very different, more powerful, and can be used to solve many different types of differential equations in not only diffusion and heat flow but also stress and strain analysis and fluid flow. There is also extensive literature on finite element analysis (e.g., Reddy and Gartling 2001; Johnson 2009) with several commercial computer software packages available.
12.6 Finite Difference Numerical Solutions of Fick’s Second Law 433 To get the second derivative with respect to x into difference form, it is most convenient to take the
backward difference of Equation 12.28 so the differential is symmetric about C(x, t). So this is
∂
∂2 ≅
(
+)
−( {
+}
−)
−( )
− − 2
C x
C x x t C x x x t C x t C x x t x
∆ ∆ ∆ ∆
∆ ∆
, , , ( ,
xx
∂
∂2 ≅
(
+)
−( )
+(
−)
2 2
C 2 x
C x x t C x t C x x t x
∆ ∆
∆
, , ,
(12.29) Putting Equations 12.28 and 12.29 together gives the finite difference equation for the partial dif- ferential equation:
C x t t C x t
t DC x x t C x t C x x t
x
, + , , , ,
(
∆)
−( )
≅(
+)
−( )
+(
−)
∆
∆ ∆
∆ 2
2
and rewriting this into its usual form, C x t t C x t D t
x C x x t C x t C x x t
, + , , , ,
( )
≅( )
+
(
+)
−( )
+(
−)
∆ ∆
∆ 2 ∆ 2 ∆ (12.30)
which is long, but not complicated. Equation 12.30 states that the concentration at a given x at the next time step, Δt, C(x, t + Δt) is just that at the previous time step, C(x, t), plus the parameters of the problem
(
D t x∆ ∆/ 2)
times the concentrations at the previous and next distance step, C x(
−∆x t,)
and C x
(
+∆x t,)
, less twice the previous distance step, C(x, t). The only condition is that the term D t x∆ ∆/ 2( )
must be small (less than 1/2 in this case [Morton and Mayers 1994]) otherwise the solu- tion oscillates and is easy to see in the solution. Also, the smaller the time step for a given distance step, the closer the solution comes to the analytical solution but requiring more time steps to be taken to get to a given Dt/L2.12.6.2 s
olVIngthef
InIted
Ifferencee
quatIonThe main attractive feature of the finite difference technique is that it lends itself very nicely to a spreadsheet solution. Figure 12.17 shows how the spreadsheet is set up for a solution for diffusion out of slab with boundary conditions C(0, t) = C(L, t) = 0, and the initial condition C(x, 0) = 1.0, the problem solved in Section 12.4. The distance step is horizontal and the time step is vertical.
x/L
0.1 1.0
200 0
0 0 0 0 0 0
1.0 1.0 1.0
D, Δx, Δt = fixed values 0.2
C(x−Δx)
0.3 C(x, t) C(x+Δt) C(x, t+Δt)
}
1Δt 2Δt 3Δt
4Δt Δx
(Δx)DΔt2
C(x, t + Δt) = C(x, t) + C(x + Δx, t) − 2C(x, t) + C(x − Δx, t) BC
t = 200Δt
IC Time
Distance 0 < x < L
Δt
FIGURE 12.17 Schematic showing how a spreadsheet can be used to evaluate a finite difference solution, in this case, for diffusion out of a sheet. The boundary conditions, C(0, t) = C(L, t) = 0 are placed in the columns x/L = 0 and x/L = 1.0, respectively. The initial condition, C(x, 0) = 1.0 is entered into row zero. For conve- nience, the values of D, Δx, and Δt are put into separate cells, so they can be varied separately to see how they affect the solution. Then the finite difference solution is entered into cell (row 1Δt, column x/L = 0.1) and copied to all the remaining cells up t = 200 Δt in this illustration. The values of C(x, t) are automatically calculated at each position.
The boundary condition C(0, t) = 0 is the first column and the initial condition is the first row, C(x, 0) = 1.0. The values of D, Δx, and Δt can be put into separate cells, so that each is easily changed independently. All that needs to be done is to put the difference equation, Equation 12.30 in the first cell of the x/L = 0.1 column and then copy it to all of the other x/L cells in the row. Then the row is copied downward as far as necessary to get the largest value of Dt/L2 desired: Dt L2≅0 5. in this case. The solution appears for different values of time vertically and different values of x/L horizon- tally. Figure 12.18 is a copy of the spreadsheet (up to x/L = 0.5) used to calculate diffusion out of a slab of thickness L. In this case
(
D t x∆ ∆/ 2)
=0 25 0 5. < . so the solution converges nicely to smooth curves. Since ∆x f L= , where f is some fraction of L, this can be written(
D t x∆ ∆/ 2)
=(
D t f L∆ / 2 2)
<0 5. . As a result, the value of D necessary to give significant values of Dt L2 in a reasonable number of time steps will depend on the value of D f L( )
2. In Figure 12.18, L = 1 cm and f = 0.1 so the dif- fusion coefficient used is D = 1.0 to ensure the inequality of(
D t x∆ ∆/ 2)
=(
D t f L∆ / 2 2)
<0 5. with∆t=0 0025. . This is a realistic value for the diffusion coefficient for a gas diffusing out of a box. If D = 10−4 cm2/s, appropriate for a liquid, then the Δt steps would be 25 seconds for this same value of
(
D t x∆ ∆/ 2)
=0 25 0 5. < . and the results are the same at any value of Dt L2. It should be noted that only four iterations are used when Dt L2=0 01. . This is not many iterations in time to smooth out the calculated curves. Nevertheless, Figure 12.19 compares this finite difference solution with the infinite series solution—that also requires a spreadsheet to sum the terms—and clearly, the finiteΔx = Δt =
0.1 0.0025 D = 1.00E+00
0 0.1 0.2 0.3 0.4 0.5
0 1 1 1 1 1
0 0.75000000 1.00000000 1.00000000 1.00000000 1.00000000 0 0.62500000 0.93750000 1.00000000 1.00000000 1.00000000 0 0.54687500 0.87500000 0.98437500 1.00000000 1.00000000 0 0.49218750 0.82031250 0.96093750 0.99609375 1.00000000 0 0.45117188 0.77343750 0.93457031 0.98828125 0.99804688 0 0.41894531 0.73315430 0.90771484 0.97729492 0.99316406 0 0.39276123 0.69824219 0.88146973 0.96386719 0.98522949 0 0.37094116 0.66767883 0.85626221 0.94860840 0.97454834 0 0.35239029 0.64064026 0.83220291 0.93200684 0.96157837 0 0.33635521 0.61646843 0.80926323 0.91444874 0.94679260 0 0.32229471 0.59463882 0.78736091 0.89623833 0.93062067 0 0.30980706 0.57473332 0.76639974 0.87761456 0.91342950 0 0.29858686 0.55641836 0.74628684 0.85876459 0.89552203 0 0.28839802 0.53942760 0.72693916 0.83983451 0.87714331 0 0.27905591 0.52354810 0.70828511 0.82093787 0.85848891 0 0.27041498 0.50860930 0.69026405 0.80216244 0.83971339 0 0.26235982 0.49447441 0.67282496 0.78357558 0.82093792 0 0.25479851 0.48103340 0.65592498 0.76522851 0.80225675 0 0.24765760 0.46819757 0.63952796 0.74715968 0.78374263 0 0.24087819 0.45589518 0.62360330 0.72939749 0.76545116
Initial condition x/L
Boundary condition Dt/L2 = 0.01
Dt/L2 = 0.05 Δt
Δx
FIGURE 12.18 Copy of part of the spreadsheet program for diffusion out of a sheet described in Figure 12.17.
The values of DT/L2=0.01 and 0.05 are shown for the parameters given at the top of the sheet.