Keywords

1 Introduction

The convection diffusion equation

$$ \frac{\partial u}{{\partial t}} + \nabla \cdot {\mathbf{v}}u = \nabla \cdot \left( {\mu \nabla u} \right) + f\left( {{\mathbf{x}},t} \right) $$
(1)

describes quantities in situations where there is both diffusion and convection or advection. It is important to get the solution of the equation with physics situation. Equation (1) is very important in computational fluid dynamics to model the transport phenomena. The coefficients \({\mathbf{v}}{ }\) and \(D\) are convection velocity and diffusion coefficient, \(\nabla \cdot {\mathbf{v}}u{ }\) picture the convention and \(\nabla \cdot \left( {\mu \nabla u} \right){ }\) picture the diffusion. 1 and 2-dimension cases have the analytical solutions. But, in general, it is difficult to obtain the explicit solutions in high space dimensions, which cause trouble in predicting the distribution of matter or energy. Then we have to try to obtain a numerical solution which balances computational speed and accuracy.

This paper deals with solving the convection diffusion equation with 1, 2 or 3 dimensions using the finite difference method.

2 Literature Review

Finite difference method, finite element method and finite volume method are common methods in engineering application. Finite difference method (FDM) is the classical way to calculate the numerical solution of PDE and ODE.

Cheng Aijie, Zhao Weidong [1] given a economical difference scheme for convection-diffusion equation with Dirichlet’s condition.

$$ \frac{\partial u}{{\partial t}} - \nabla \cdot \left( {a\left( {x,y} \right)\nabla u} \right) + \vec{b}\left( {x,y} \right) \cdot \nabla u = f\left( {x,y,t} \right),\left( {x,y} \right) \in {\Omega },t \in \left( {0,T} \right] $$
(2)
$$ u\left( {x,y,0} \right) = u^{0} \left( {x,y} \right),\quad \left( {x,y} \right) \in {\Omega }. $$
(3)
$$ u\left( {x,y,t} \right) = 0,\quad \left( {x,y} \right) \in \partial {\Omega } $$
(4)

\({\Omega } = \left( {0,1} \right) \times \left( {0,1} \right),\) \(\vec{b} = \left( {b_{1} \left( {x,y} \right),b_{2} \left( {x,y} \right)} \right),a \in C^{3} \left( {{\overline{\Omega }}} \right),\) \(b_{1} \in C^{0} \left( {{\overline{\Omega }}} \right),b_{2} \in C^{0} \left( {{\overline{\Omega }}} \right),{ }f \in C^{0} \left( {\left( {0,T} \right] \times {\overline{\Omega }}} \right)\) and \(a\left( {x,y} \right){ }\) has positive low boundary. By discretizing the equation along characteristics, they have improved the computational efficiency without sacrificing accuracy. When it is a convection-dominated problem, the method of characteristics is faster than CDS. Even some cases will converge on the method of characteristic but CDS when diffusion coefficient is small.

Muhammad Saqib, Shahid Hasnain, Daoud Suleiman Mashat [2] extend Crank-Nicholson and ADI scheme to non-linear two dimension convection-diffusion equation.

$$ u_{t} + uu_{x} + uu_{y} - \frac{1}{R}\left( {u_{xx} + u_{yy} } \right) = 0 $$
(5)

To compare with other numerical method, the computational solution is more approach the exact solution.

Murli M. Gupta, Jun Zhang [3] give an explicit fourth-order finite difference scheme for 3D convection diffusion equations in a highly efficient procedure for small to medium values of the grid Reynolds number in 2000.

Ewa Majchrzak, Łukasz Turchan [4] present the other algorithm based on the FDM for 1-dimension convection diffusion equation.

We will compare the explicit solution with numerical solution of Eq. (1) using FDM in the 1 - dimension and 2 dimensions cases and try to get 3 - situation.

3 Methodology

The FDM uses the finite difference in place of the derivative. Suppose \(u\left( x \right):R \to R\) is a real function. We approximate \(u^{\prime}{ }\) by calculate

$$ D_{ + } u\left( x \right) \equiv \frac{{u\left( {x + h} \right) - u\left( x \right)}}{h} $$
(6)

where \(h\) is a small and positive value [5]. By the definition, the smaller \(h\) is, the closer \(D_{ + } u\left( x \right){ }\) is to \(u^{\prime}\left( x \right)\). Similarly, we have many schemes to approximate \(u^{\prime}\left( x \right)\), such as

$$ {\text{backward approximation }}D_{ - } u\left( x \right) \equiv \frac{{u\left( x \right) - u\left( {x - h} \right)}}{h} $$
(7)
$$ {\text{centered approximation }}D_{0} u\left( x \right) \equiv \frac{{u\left( {x + h} \right) - u\left( {x - h} \right)}}{2h} $$
(8)

We expand the function \(u\) about the point \(x\) in Taylor series

$$ u\left( {x + h} \right) = u\left( x \right) + hu^{\prime}\left( x \right) + \frac{1}{2}h^{2} u^{\prime\prime}\left( x \right) + O\left( {h^{4} } \right) $$
(9)
$$ u\left( {x - h} \right) = u\left( x \right) - hu^{\prime}\left( x \right) + \frac{1}{2}h^{2} u^{\prime\prime}\left( x \right) + O\left( {h^{4} } \right) $$
(10)

Then the errors of \(D_{ + } ,D_{ - } ,D_{0}\) are

$$ D_{ + } u\left( x \right) - u^{\prime}\left( x \right) = \frac{1}{2}hu^{\prime\prime}\left( x \right) + O\left( {h^{2} } \right) $$
(11)
$$ D_{ - } u\left( x \right) - u^{\prime}\left( x \right) = \frac{1}{2}hu^{\prime\prime}\left( x \right) + O\left( {h^{2} } \right) $$
(12)
$$ D_{0} u\left( x \right) - u^{\prime}\left( x \right) = \frac{1}{6}h^{2} u^{\prime\prime\prime}\left( x \right) + O\left( {h^{4} } \right) $$
(13)

So centered approximation is more accurate than these formulas have different accuracy although all of them be used to approximate \(u^{\prime}\left( x \right)\)

$$ u\left( {x + h} \right) = u\left( x \right) + hu^{\prime}\left( x \right) + \frac{1}{2}h^{2} u^{\prime\prime}\left( x \right) + O\left( {h^{4} } \right) $$
(14)
$$ u\left( {x - h} \right) = u\left( x \right) - hu^{\prime}\left( x \right) + \frac{1}{2}h^{2} u^{\prime\prime}\left( x \right) + O\left( {h^{4} } \right) $$
(15)

We call \(D_{ + } ,D_{ - }\) are one order accuracy and \(D_{0} { }\) is two order accuracy of approximation.

The second order derivative of \(u{ }\) can be approximation by same way

$$ D_{0}^{2} u\left( x \right): = D_{ + } D_{ - } u\left( x \right) $$
(16)

To sum up, the method of approximation of derivatives we need are enough. Then, let’s discuss how to solve the equation by numerical method.

Let’s start with the simplest case. There only one space dimension ‘\(x\)’ in the equation:

$$ u_{t} + vu_{x} = \mu u_{xx} $$
(17)

We will express the equation as upwind scheme. First, The first order time derivative uses forward approximation

$$ u_{t} = \frac{{u\left( {x,t + {\Delta }t} \right) - u\left( {x,t} \right)}}{{{\Delta }t}} $$
(18)

Then, first and second space derivatives use centered approximation

$$ u_{x} = \frac{{u\left( {x + {\Delta }x,t} \right) - u\left( {x - {\Delta }x,t} \right)}}{{2{\Delta }x}} $$
(19)
$$ u_{xx} = \frac{{u\left( {x - {\Delta }x,t} \right) - 2u\left( {x,t} \right) + u\left( {x + {\Delta }x,t} \right)}}{{{\Delta }x^{2} }} $$
(20)

3.1 1-Dim Case

If we plug the difference back into the Eq. (17), we obtain

$$ \begin{array}{*{20}c} {\frac{{u\left( {x,t + {\Delta }t} \right) - u\left( {x,t} \right)}}{{{\Delta }t}} + v\frac{{u\left( {x + {\Delta }x,t} \right) - u\left( {x - {\Delta }x,t} \right)}}{{2{\Delta }x}}} \\ { = \mu \frac{{u\left( {x + {\Delta }x,t} \right) + u\left( {x - {\Delta }x,t} \right) - 2u\left( {x,t} \right)}}{{{\Delta }x^{2} }}} \\ \end{array} $$
(21)
$$ \begin{array}{*{20}c} {u\left( {x,t + {\Delta }t} \right)} \\ { = \left( {1 - \frac{{2\mu {\Delta }t}}{{{\Delta }x^{2} }}} \right)u\left( {x,t} \right) + \left( {\frac{{\mu {\Delta }t}}{{{\Delta }x^{2} }} - \frac{{v{\Delta }t}}{{2{\Delta }x}}} \right) u\left( {x + {\Delta }x,t} \right)} \\ { + \left( {\frac{{v{\Delta }t}}{{2{\Delta }x}} + \frac{{\mu {\Delta }t}}{{{\Delta }x^{2} }}} \right)u\left( {x - {\Delta }x,t} \right)} \\ \end{array} $$
(22)

Finally, we rewrite the equation as

$$ U_{i}^{n + 1} = \left( {1 - \frac{{2\mu {\Delta }t}}{{{\Delta }x^{2} }}} \right)U_{i}^{n} + \left( {\frac{{\mu {\Delta }t}}{{{\Delta }x^{2} }} - \frac{{v{\Delta }t}}{{2{\Delta }x}}} \right)U_{i + 1}^{n} + \left( {\frac{{v{\Delta }t}}{{2{\Delta }x}} + \frac{{\mu {\Delta }t}}{{{\Delta }x^{2} }}} \right)U_{i - 1}^{n} $$
(23)

This is an algebraic equation. We can calculate it by irritation method.

3.2 2-Dim Case

$$ u_{t} + v\left( {u_{x} + u_{y} } \right) = \mu \left( {u_{xx} + u_{yy} } \right) $$
(24)

The 2-dim convection diffusion equation also could use upwind scheme. We can obtain that

$$ \begin{array}{*{20}c} {\frac{{u\left( {x,y,t + {\Delta }t} \right) - u\left( {x,y,t} \right)}}{{{\Delta }t}}} \\ { + v\left( {\begin{array}{*{20}c} {\frac{{u\left( {x + {\Delta }x,y,t} \right) - u\left( {x - {\Delta }x,y,t} \right)}}{{2{\Delta }x}}} \\ { + \frac{{u\left( {x,y + {\Delta }y,t} \right) - u\left( {x,y - {\Delta }y,t} \right)}}{{2{\Delta }y}}} \\ \end{array} } \right)} \\ { = \mu \left( {\begin{array}{*{20}c} {\frac{{u\left( {x - {\Delta }x,y,t} \right) - 2u\left( {x,y,t} \right) + u\left( {x + {\Delta }x,y,t} \right)}}{{{\Delta }x^{2} }}} \\ { + \frac{{u\left( {x,y - {\Delta }y,t} \right) - 2u\left( {x,y,t} \right) + u\left( {x,y + {\Delta }y,t} \right)}}{{{\Delta }y^{2} }}} \\ \end{array} } \right)} \\ \end{array} $$
(25)

Rewrite the equation as

$$ \begin{array}{*{20}c} {U_{i,j}^{n + 1} = \left( {1 - \frac{{2\mu {\Delta }t}}{{{\Delta }x^{2} }} - \frac{{2\mu {\Delta }t}}{{{\Delta }y^{2} }}} \right)U_{i,j}^{n} + \left( {\frac{{\mu {\Delta }t}}{{{\Delta }x^{2} }} - \frac{{v{\Delta }t}}{{2{\Delta }x}}} \right) U_{i + 1,j}^{n} } \\ { + \left( {\frac{{v{\Delta }t}}{{2{\Delta }x}} + \frac{{\mu {\Delta }t}}{{{\Delta }x^{2} }}} \right)U_{i - 1,j}^{n} + \left( {\frac{{\mu {\Delta }t}}{{{\Delta }y^{2} }} - \frac{{v{\Delta }t}}{{2{\Delta }y}}} \right)U_{i,j + 1}^{n} + \left( {\frac{{v{\Delta }t}}{{2{\Delta }y}} + \frac{{\mu {\Delta }t}}{{{\Delta }y^{2} }}} \right)U_{i,j - 1}^{n} } \\ \end{array} $$
(26)

3.3 3-Dim Case

$$ \begin{array}{*{20}c} {u_{t} + v\left( {u_{x} + u_{y} + u_{z} } \right) = \mu \left( {u_{xx} + u_{yy} + u_{zz} } \right)} \\ \end{array} $$
(27)
$$\begin{array}{c}\frac{u\left(x,y,z,t+\Delta t\right)-u\left(x,y,z,t\right)}{\Delta t}\\ +v\left(\begin{array}{c} \frac{u\left(x+\Delta x,y,z,t\right)-u\left(x-\Delta x,y,z,t\right)}{2\Delta x}\\ +\frac{u\left(x,y+\Delta y,z,t\right)-u\left(x,y-\Delta y,z,t\right)}{2\Delta y}\\ +\frac{u\left(x,y,z+\Delta z,t\right)-u\left(x,y,z-\Delta z,t\right)}{2\Delta z}\end{array}\right)\\ -\mu \left(\begin{array}{c}\frac{u\left(x-\Delta x,y,z,t\right)-2u\left(x,y,z,t\right)+u\left(x+\Delta x,y,z,t\right)}{\Delta {x}^{2}}\\ +\frac{u\left(x,y-\Delta y,z,t\right)-2u\left(x,y,z,t\right)+u\left(x,y+\Delta y,z,t\right)}{\Delta {y}^{2}}\\ +\frac{u\left(x,y,z-\Delta z,t\right)-2u\left(x,y,z,t\right)+u\left(x,y,z+\Delta z,t\right)}{\Delta {z}^{2}}\end{array}\right)=0.\end{array}$$
(28)

It follows that

$$\begin{array}{c}u\left(x,y,z,t+\Delta t\right)=\left(1-\frac{2\mu\Delta t}{\Delta {x}^{2}}-\frac{2\mu\Delta t}{\Delta {y}^{2}}-\frac{2\mu\Delta t}{\Delta {z}^{2}}\right)u\left(x,y,z,t\right)\\ +\left(\frac{\mu\Delta t}{\Delta {x}^{2}}-\frac{v\Delta t }{2\Delta x}\right) u\left(x+\Delta x,y,z,t\right)\\ +\left(\frac{v\Delta t }{2\Delta x}+\frac{\mu\Delta t}{\Delta {x}^{2}}\right)u\left(x-\Delta x,y,z,t\right)\\ +\left(\frac{\mu\Delta t}{\Delta {y}^{2}}-\frac{v\Delta t }{2\Delta y}\right) u\left(x,y+\Delta y,z,t\right)\\ +\left(\frac{v\Delta t }{2\Delta y}+\frac{\mu\Delta t}{\Delta {y}^{2}}\right)u\left(x,y-\Delta y,z,t\right)\\ +\left(\frac{\mu\Delta t}{\Delta {z}^{2}}-\frac{v\Delta t }{2\Delta z}\right)u\left(x,y,z+\Delta z,t\right)\\ +\left(\frac{v\Delta t }{2\Delta z}+\frac{\mu\Delta t}{\Delta {z}^{2}}\right)u\left(x,y,z-\Delta z,t\right)\end{array}$$
(29)
$$\begin{array}{c}{U}_{i,j,k}^{n+1}=\left(1-\frac{2\mu\Delta t}{\Delta {x}^{2}}-\frac{2\mu\Delta t}{\Delta {y}^{2}}-\frac{2\mu\Delta t}{\Delta {z}^{2}}\right){U}_{i,j,k}^{n}\\ +\left(\frac{\mu\Delta t}{\Delta {x}^{2}}-\frac{v\Delta t }{2\Delta x}\right) {U}_{i+1,j,k}^{n}+\left(\frac{v\Delta t }{2\Delta x}+\frac{\mu\Delta t}{\Delta {x}^{2}}\right){U}_{i-1,j,k}^{n}\\ +\left(\frac{\mu\Delta t}{\Delta {y}^{2}}-\frac{v\Delta t }{2\Delta y}\right){U}_{i,j+1,k}^{n}+\left(\frac{v\Delta t }{2\Delta y}+\frac{\mu\Delta t}{\Delta {y}^{2}}\right){U}_{i,j-1,k}^{n}\\ +\left(\frac{\mu\Delta t}{\Delta {z}^{2}}-\frac{v\Delta t }{2\Delta z}\right){U}_{i,j,k+1}^{n}+\left(\frac{v\Delta t }{2\Delta z}+\frac{\mu\Delta t}{\Delta {z}^{2}}\right){U}_{i,j,k-1}^{n}\end{array}$$
(30)

4 Result

4.1 First Case

Let’s take \(v = 1,\mu = 0.5\), and equip suitable boundary condition. Then we can get a initial boundary value problem

$$ \begin{array}{*{20}c} {\left\{ {\begin{array}{*{20}c} {u_{t} + u_{x} = 0.5u_{xx} ,x \in \left( {0,1} \right),t \in \left( {0,1} \right)} \\ {u\left( {x,0} \right) = e^{x} , x \in \left[ {0,1} \right]} \\ {u\left( {0,t} \right) = e^{ - 0.5t} ,t \in \left[ {0,1} \right]} \\ {u\left( {1,t} \right) = e^{1 - 0.5t} ,t \in \left[ {0,1} \right]} \\ \end{array} } \right.} \\ \end{array} $$
(31)

When we set \(\Delta t = 0.01s,{ }\Delta x = 0.05,\) there is the irritation formula

$$ \begin{array}{*{20}c} {U_{i}^{n + 1} = 0.45U_{i + 1}^{n} + 0.55U_{i - 1}^{n} } \\ \end{array} $$
(32)

Through computer calculation by Matlab, we can get the solution and draw the figure of the equation (Fig. 1)

Fig. 1.
figure 1

Solution of 1-dim convection-diffusion equation

4.2 Case Two

When we take \(v = - 1,\;\mu = 0.05,\; \Delta x = 0.05,\;\Delta y = 0.05,\;\Delta t = 0.01s\), the 2-dimensional question become to (Figs. 2, 3, and 4)

$$ \left\{ {\begin{array}{*{20}c} {u_{t} = u_{x} + u_{y} + 0.05\left( {u_{xx} + u_{yy} } \right),\left( {x,y} \right) \in \left( {0,1} \right) \times \left( {0,1} \right),t \in \left( {0,1} \right)} \\ {u\left( {x,y,{ }0} \right) = e^{{\frac{1}{2}\left( {x + y} \right)}} ,x \in \left[ {0,1} \right]} \\ {u\left( {x,0,t} \right) = e^{{\frac{1}{2}x - t}} ,t \in \left[ {0,1} \right],x \in \left[ {0,1} \right]} \\ {u\left( {0,y,t} \right) = e^{{\frac{1}{2}y - t}} ,t \in \left[ {0,1} \right],y \in \left[ {0,1} \right]} \\ {u\left( {x,1,t} \right) = e^{{\frac{1}{2}\left( {1 + x} \right) - t}} ,t \in \left[ {0,1} \right],x \in \left[ {0,1} \right]} \\ {u\left( {1,y,t} \right) = e^{{\frac{1}{2}\left( {1 + y} \right) - t}} ,t \in \left[ {0,1} \right],y \in \left[ {0,1} \right]} \\ \end{array} } \right. $$
(33)
$$ \begin{array}{*{20}c} {U_{i,j}^{n + 1} = 0.2U_{i,j}^{n} + 0.1 U_{i + 1,j}^{n} + 0.3U_{i - 1,j}^{n} + 0.1U_{i,j + 1}^{n} + 0.3U_{i,j - 1}^{n} } \\ \end{array} $$
(34)
Fig. 2.
figure 2

Solution of 2-dim convection-diffusion equation t =0 s

Fig. 3.
figure 3

Solution of 2-dim convection-diffusion equation t = 0.5 s

Fig. 4.
figure 4

Solution of 2-dim convection-diffusion equation t = 1 s

4.3 Case Three

We take \(v = 1,\mu = 0.1,{\Delta }t = 0.01s,{\Delta }x = 0.1,{\Delta }y = 0.1\), then we get the equation

$$ \begin{array}{*{20}c} {u_{t} = u_{x} + u_{y} + u_{z} + 0.1\left( {u_{xx} + u_{yy} + u_{zz} } \right).} \\ \end{array} $$
(35)

we equip initial condition and boundary condition,

$$\left\{\begin{array}{c}{u}_{t}={u}_{x}+{u}_{y}+{u}_{z}+0.1\left({u}_{xx}+{u}_{yy}+{u}_{zz}\right),\left(x,y,z\right)\in \left(\mathrm{0,1}\right)\times \left(\mathrm{0,1}\right)\times \left(\mathrm{0,1}\right),\\ t\in \left(\mathrm{0,1}\right)\\ u\left(x,y, z,0\right)={e}^{\frac{1}{2}\left(x+y+z\right)},x,y,z\in \left[\mathrm{0,1}\right]\\ u\left(x,0,z,t\right)={e}^{\frac{1}{2}\left(x+z\right)-t},t\in \left[\mathrm{0,1}\right],x,z\in \left[\mathrm{0,1}\right]\\ u\left(0,y,z,t\right)={e}^{\frac{1}{2}\left(y+z\right)-t},t\in \left[\mathrm{0,1}\right],y,z\in \left[\mathrm{0,1}\right]\\ u\left(x,y,0,t\right)={e}^{\frac{1}{2}(x+y)-t},t\in \left[\mathrm{0,1}\right],x,y\in \left[\mathrm{0,1}\right] \\ u\left(x,1,z,t\right)={e}^{\frac{1}{2}\left(1+x+z\right)-t},t\in \left[\mathrm{0,1}\right],x,z\in \left[\mathrm{0,1}\right]\\ u\left(1,y,z,t\right)={e}^{\frac{1}{2}\left(1+y+z\right)-t},t\in \left[\mathrm{0,1}\right],y,z\in \left[\mathrm{0,1}\right]\\ u\left(x,y,1,t\right)={e}^{\frac{1}{2}\left(1+x+y\right)-t},t\in \left[\mathrm{0,1}\right],x,y\in \left[\mathrm{0,1}\right]\end{array}\right.$$
(36)

The irritation is

$$ \begin{array}{*{20}c} {U_{i,j,k}^{n + 1} = 0.4U_{i,j,k}^{n} + 0.05U_{i + 1,j,k}^{n} + 0.15U_{i - 1,j,k}^{n} + 0.05U_{i,j + 1,k}^{n} + 0.15U_{i,j - 1,k}^{n} } \\ { + 0.05U_{i,j,k + 1}^{n} + 0.15U_{i,j,k - 1}^{n} } \\ \end{array} $$
(37)

Calculated by Matlab, we can obtain the solution of the problem (Figs. 5, 6, and 7).

Fig. 5.
figure 5

Solution of 3-dim convection-diffusion equation t = 0 s

Fig. 6.
figure 6

Solution of 3-dim convection diffusion equation t = 0.5 s

Fig. 7.
figure 7

Solution of 3-dim convection-diffusion equation t = 1 s

5 Discussion

In view of the above, we get some several picture of numerical solution of convection-diffusion with different dimension. We can compare 1-dim cases with its explicit solution. The observation that its numerical solution approach its explicit solution suggest us that the finite difference method is visible to solve the fixed coefficient convection-diffusion equation. In the other two cases, the high value domain move over time, which accord with convection physical phenomenon. The diffusion process also represented by the picture of the solution.

For 1-dim case, the numerical solution close with its explicit solution \(e^{{x - \frac{1}{2}t}}\), and 2,3-dim cases display convection and diffusion phenomena.

In the case of improper coefficient setting, we find that there may be numerical oscillation. According to preliminary analysis, this may be caused by the positive and negative coefficients of the iterative formula. For convection-dominated problems these schemes have much smaller time-truncation errors than those of standard methods [6]. Improper coefficient may result in negative value of \(u\), which violates the laws of physics. When you look at the coefficients of the 3-dimensional equation, the \(1 - \frac{{2\mu {\Delta }t}}{{{\Delta }x^{2} }} - \frac{{2\mu {\Delta }t}}{{{\Delta }y^{2} }} - \frac{{2\mu {\Delta }t}}{{{\Delta }z^{2} }}\) term requires \({\Delta }t\) to be small enough, the \({\Delta }x\) to be large enough for the coefficient of \(U_{i,j,k}^{n}\) to be positive, and the \(\frac{{\mu {\Delta }t}}{{{\Delta }x^{2} }} - \frac{{v{\Delta }t}}{{2{\Delta }x}}\) term requires \({\Delta }x\) to be small enough for it to be positive. So when we have numerical oscillations, we should pick the appropriate \({\Delta }t\) and \(\Delta x,\;\Delta y,\;\Delta z\).

6 Conclusion

Based on FDM, we derive the calculation format and iterative formula suitable for the convection-diffusion equation. Numerical experiments are carried out for the above three cases. The results are close to the theoretical solution and show the convection and diffusion phenomena.