Skip to main content

Theory and Modern Applications

Fourth-order compact finite difference method for solving two-dimensional convection–diffusion equation

Abstract

A fourth-order compact finite difference scheme of the two-dimensional convection–diffusion equation is proposed to solve groundwater pollution problems. A suitable scheme is constructed to simulate the law of movement of pollutants in the medium, which is spatially fourth-order accurate and temporally second-order accurate. The matrix form and solving methods for the linear system of equations are discussed. The theoretical analysis of unconditionally stable character of the scheme is verified by the Fourier amplification factor method. Numerical experiments are given to demonstrate the efficiency and accuracy of the scheme proposed, and these show excellent agreement with the exact solution.

1 Introduction

In recent years, more and more attention has been paid to the movement of pollutants in groundwater by mathematical modeling [1]. The prediction and evaluation of groundwater dynamic movement and solute transport are important tasks for agricultural pollution and groundwater development [2]. A large number of mathematical models and a variety of effective numerical methods have been widely used to simulate the movement of contaminated groundwater. Convection–diffusion equation is a class of very important equations, it can describe many physical phenomena, such as atmospheric pollutants, distribution and diffusion of the oceans and rivers, heat conduction and so many other physical problems even including bacterial concentration. However, from the existing research results, we could only get the analytical solutions of a few classic models. In the process of dealing with practical problems, for many mathematical models, especially partial differential equations, their analytical solutions are not available in general. Therefore, research for the numerical solutions of partial differential equations is very necessary [3].

During the last three decades, the numerical solution of the convection–diffusion equation has been developed by all kinds of methods, for example, the finite difference method [4], the finite element method [5, 6], the finite volume method [7], the spectral element method [8] and even the Monte Carlo method [9]. But the characteristics of the two-dimensional convection–diffusion equation and the complexity of the mathematical model are a challenge to numerical computation, so constructing the simple and efficient numerical scheme needs to be further studied. A finite difference method is one of the effective and flexible methods to solve the numerical solution of partial differential equations with initial boundary value [10].

For the traditional finite difference methods, a classical spatial discretization, such as the second-order central difference scheme, fails to approach the exact solution of most equations; for obtaining a more accurate numerical solution one needs to add more nodes and use smaller mesh sizes, which would require more storage space and computing time [11]. In order to get more accurate results for constant mesh size, we have to increase the order of accuracy of the numerical approximation, which, in turn, means enlarging the stencil of grid points [12]. However, this results in some problems, for instance, the difficult treatments of the boundary conditions, the approximation of the points next to the boundaries, and the increasing of the bandwidth of the stiffness matrix. For many application problems, it is desirable to use higher-order numerical methods to obtain an accurate solution.

In terms of the above reasons, a compact finite difference scheme is desired to solve lots of differential equations numerically [1316]. One can compute more accurate solutions using limited grid sizes through developing high-order compact finite difference schemes. Significant work in this field has been done by Turkel and Singer [17] in 1998. In recent years, the high accuracy compact difference method has attracted more and more attention; see [1822]. Using a Taylor series expansion, Sari et al. [14] developed a tenth-order finite difference scheme, proposed to solve one-dimensional advection–diffusion equation. Gurarslan et al. [16] presented a sixth-order compact difference scheme in space and a fourth-order Runge–Kutta scheme in time to produce numerical solutions of the one-dimensional advection–diffusion equation, it has been seen to be very accurate in solving the contaminant transport equation for \(Pe \leq5\). Based on the Grünwald–Letnikov discretization of the Riemann–Liouville derivative, Cui obtained a fully discrete implicit scheme after approximating the second-order derivative with respect to space by the compact finite difference [19]. Li presented an efficient and stable compact fourth-order method for the phase field crystal equation [21]. Kaysar et al. gave an useful and efficient compact finite difference approximation of a fourth-order scheme for solving linear one-dimensional convection–diffusion equation [22]. All in all, there is a renewed interest in the development and application of compact finite difference methods for the numerical solution of the convection–diffusion equations.

Inspired by the above literature, in this paper, we are interested in the mathematical model of groundwater pollution with seepage only in x direction by integrating the knowledge of fourth-order compact finite difference, which is also unconditional stable. We consider a special class of convection–diffusion equations, which comes from the following practical problem: The leakage of a factory’s sewage pool causes the seepage of sewage, the concentration of pollution substance in the underground water is a function of spatial coordinate and temporal in any point. We take a micro-body in ground water to study, the concentration’s change of which is caused by diffusion (including molecular diffusion and osmotic dispersion), and the mass flux caused by the average liquid motion. We suppose the seepage area to be an infinite plane, assume the groundwater flow belongs to the one-dimensional cases, the diffusion of pollutants is a two-dimensional dispersion in a porous medium. At every stage, contaminant is injected at any region point and at arbitrary time in the river. Applying the mathematical software MATLAB, a numerical simulation is carried out on the problem of water pollution–diffusion to verify the validity and practicability of the model and algorithm. Numerical examples are given to illustrate the accuracy and reliability of the proposed scheme, so as to provide an important basis for water pollution accident disaster emergency disposal and decision-making for environmental protection personnel dealing with a water pollution incident, to be used as a reference.

The paper is organized as follows: in Sect. 2, we present a fourth-order compact difference scheme, in which the Crank–Nicolson scheme is used for temporal discretization and a fourth-order compact finite difference scheme dealing with a one-dimensional convection–diffusion equation is applied to the spatial discretization. In Sect. 3, the matrix form for the difference scheme is given, and the solving methods for the linear system of equations are discussed. In Sect. 4, the theoretical analysis, the Fourier method, namely the amplification factor method (or von Neumann condition) of the proposed scheme is presented. Finally, numerical examples are provided in Sect. 5, the numerical results shown in tables and figures derive the accuracy and prove the convergence order of the scheme, they are in agreement with our theoretical analysis. The paper concludes with a summary in Sect. 6.

2 Fourth-order compact finite difference scheme

In this paper, we consider the following two-dimensional convection–diffusion equation, which is used widely to simulate the motion process of the contaminant in groundwater flow and the water flow with any chemical solute. Here we take the seepage area as an infinite plane, assume the groundwater flow belongs to the one-dimensional cases, the diffusion of pollutants is a two-dimensional dispersion in a porous medium, and the contaminant \(f(x,y,t) \) is injected at any region point \((x, y)\) and at any time t in the river.

Let \(\Omega \subset\mathbf{R}^{2}\) with boundary Γ. We write

$$ \textstyle\begin{cases} \frac{\partial C}{\partial t} =D_{x} \frac{\partial^{2} C}{\partial x^{2}} + D_{y} \frac{\partial^{2} C}{\partial y^{2}} -v\frac{\partial C}{\partial x} + f, & (x,y)\in \Omega , t>0, \\ C(x,y,0)=C_{0}(x,y),& (x,y)\in \Omega , \\ C(x,y,t)=g(x,y,t),& (x,y)\in \Gamma , t>0, \end{cases} $$
(1)

where \(\Omega = [0, L_{x}]\times[0, L_{y}]\) is a rectangular domain in \(\mathbf{R}^{2}\), which represents different shapes of the river where the contaminants are located. \(\Gamma = \partial \Omega \) is the boundary of the rectangular domain. The function C stands for the concentration of a solute dependent on time t, here \(C = C(x,y,t)\). x and y are the horizontal coordinates, the unknown \(D_{x}\) and \(D_{y}\) are positive constants representing the longitudinal and transversal dispersion coefficients, respectively, and v is the mean pore velocity. The function \(f(x,y,t) \) is the source term, it refers to all items other than constant items, convection and diffusion items. In the case of pumping and injecting water, \(f = \mathbf{W} / \mathbf {n}\), where W is the amount of contaminant per unit volume of aquifer injected per unit time, it is a function of time and location, and n is the porosity of the porous medium [23]. The term \(g(x,y,t) \) in the right side of the second equation represents a boundary source on Γ, \(C_{0}(x,y)\), \(g(x,y,t)\) and the source term \(f(x,y,t)\) are given as sufficiently smooth functions.

The analytical solution for Eqs. (1) is not available easily, the purpose of this paper is to improve the accuracy in spatial direction, we suggest a fourth-order compact difference scheme. In order to present our scheme, we first introduce some essential notations, which will be used later.

Discretizing the spatial region firstly, let N and M be two positive integers, so that the step sizes are \(h_{x} = \frac{L_{x}}{N}, h_{y} = \frac{L_{y}}{M}\), under this condition, the spatial nodes can be denoted by \((x_{i},y_{j})\), namely, \(x_{i}=ih_{x}, i = 0, 1, \ldots, N-1, N; y_{j}=jh_{y}, j = 0, 1, \ldots, M-1, M\). Let \(\bar{\Omega }_{h}=\{(x_{i},y_{j}) | 0\leq i\leq N, 0\leq j\leq M\}, \Gamma _{h}=\bar{\Omega }_{h}\cap \Gamma , \Omega _{h}=\bar{\Omega }_{h}\cap \Omega \). For simplicity, introduce \(\omega=\{(i,j) | (x_{i},y_{j})\in \Omega _{h}\}, \sigma=\{(i,j) | (x_{i},y_{j})\in \Gamma _{h}\}\), then we have \(\bar{\omega}=\omega\cup\sigma\). Define \(\mathcal{U}_{h}=\{u | u=\{u_{ij} | (i,j)\in\bar{\omega}\}\}\), for any \(u \in\mathcal{U}_{h}\), similar to Ref. [24], introducing the following notations of difference quotients:

$$\begin{aligned} \Delta _{x}u_{ij}=\frac{u_{i+1,j}-u_{i-1,j}}{2h_{x}}, \qquad \delta^{2}_{x}u_{ij}=\frac{u_{i-1,j}-2u_{ij}+u_{i+1,j}}{h^{2}_{x}}, \qquad\delta ^{2}_{y}u_{ij}=\frac{u_{i,j-1}-2u_{ij}+u_{i,j+1}}{h^{2}_{y}}. \end{aligned}$$

Next, for the temporal approximation, take a positive integer K, partition the interval \([0,T]\) into K equal parts of width \(\tau= \frac {T}{K}\); we have the following notations:

$$t_{n}=n\tau, \qquad \Omega _{\tau}=\{t_{n} | 0\leq n\leq K\},\qquad t_{n+\frac{1}{2}}= \frac{t_{n}+t_{n+1}}{2},\quad n=0,1,\ldots, K-1, $$

where τ is called the temporal step size.

Set \(\mathcal{U}_{\tau}=\{w | w=(w^{0},w^{1},\ldots,w^{K})^{T}\}\), for any \(w\in\mathcal{U}_{\tau}\), introducing some notations as follows:

$$w^{n+\frac{1}{2}}=\frac{1}{2} \bigl(w^{n+1}+w^{n} \bigr), \qquad \delta_{t}w^{n+\frac {1}{2}}=\frac{1}{\tau } \bigl(w^{n+1}-w^{n} \bigr),\quad n=0,1,\ldots, K-1. $$

Define grid functions on \(\bar{\Omega }_{h} \times \Omega _{\tau}\), \(C^{n}_{ij}=C(x_{i},y_{j},t_{n}), (i,j)\in\bar{\omega}, 0\leq n\leq K \). Following Refs. [25, 26], the two-dimensional convection–diffusion equation in Eqs. (1) can be rewritten as the following two equations:

$$\begin{aligned} &D_{x} \frac{\partial^{2} C}{\partial x^{2}} + v\frac{\partial C}{\partial x} = f - \biggl( \frac{\partial C}{\partial t} - D_{y} \frac{\partial^{2} C}{\partial y^{2}} \biggr),\quad (x,y)\in \Omega , t>0, \end{aligned}$$
(2)
$$\begin{aligned} &{-}D_{y} \frac{\partial^{2} C}{\partial y^{2}} = f - \biggl( \frac{\partial C}{\partial t} - D_{x} \frac{\partial^{2} C}{\partial x^{2}} + v\frac{\partial C}{\partial x} \biggr),\quad (x,y)\in \Omega , t>0. \end{aligned}$$
(3)

Next, we only need to consider the compact difference scheme with Eq. (2) and Eq. (3), respectively.

For Eq. (2), considering it at the point \((x_{i},y_{j},t_{n+\frac{1}{2}})\), we have

$$\begin{aligned} & D_{x} \frac{\partial^{2} C}{\partial x^{2}}(x_{i},y_{j},t_{n + \frac{1}{2}}) + v\frac{\partial C}{\partial x} (x_{i},y_{j},t_{n + \frac{1}{2}}) \\ &\quad = f (x_{i},y_{j},t_{n + \frac{1}{2}})- [ \frac{\partial C}{\partial t}(x_{i},y_{j},t_{n + \frac{1}{2}}) - D_{y} \frac{\partial^{2} C}{\partial x^{2}}(x_{i},y_{j},t_{n + \frac {1}{2}}), \\ &\qquad (i,j)\in\omega, 0\leq n\leq K-1. \end{aligned}$$
(4)

Consider the one-dimensional steady convection–diffusion equation [24]

$$ - \alpha\frac{\partial^{2} u}{\partial x^{2}} + \beta\frac{\partial u}{\partial x} = \widetilde{f} (x), $$
(5)

where α is the constant conductivity, β is a constant representing the convective velocity, is a sufficiently smooth function of x, and u may represent the concentration of a solute, vorticity, heat, etc.

Its three point fourth-order compact scheme is as follows:

$$ - \biggl( \alpha+ \frac{\beta^{2} h^{2}}{12 \alpha} \biggr)\delta^{2}_{x} u(x_{i}) + \beta \Delta _{x} u(x_{i}) = \biggl[ 1 + \frac{h^{2}}{12} \biggl(\delta^{2}_{x} - \frac {\beta}{\alpha} \Delta _{x} \biggr) \biggr] \widetilde{f}(x_{i}), $$
(6)

where

$$\Delta _{x} u(x_{i}) = \frac{u(x_{i+1})- u(x_{i-1})}{2h} $$

and

$$\delta^{2}_{x} u(x_{i}) = \frac{u(x_{i+1})-2u(x_{i}) + u(x_{i-1})}{h^{2}} $$

are the central difference approximations for the first and second derivatives.

We think of the right term

$$f (x_{i},y_{j},t_{n + \frac{1}{2}})- [ \frac{\partial C}{\partial t}(x_{i},y_{j},t_{n + \frac{1}{2}}) - D_{y} \frac{\partial^{2} C}{\partial x^{2}}(x_{i},y_{j},t_{n + \frac{1}{2}}) $$

of Eq. (4) as a whole, similar to the right term of Eq. (5), using the method of Eq. (6), taking the Taylor formula into account [27], applying the Taylor expansion for Eq. (4); it generates

$$\begin{aligned} &{ -} \biggl(D_{x} + \frac{v^{2} h^{2}_{x}}{12 D_{x}} \biggr) \delta^{2}_{x} C^{n + \frac{1}{2}}_{ij} + v \Delta _{x} C^{n + \frac{1}{2}}_{ij} \\ &\quad= \biggl[ 1 + \frac{h^{2}_{x}}{12} \biggl(\delta^{2}_{x} - \frac{v}{D_{x}} \Delta _{x} \biggr) \biggr] \biggl[f^{n + \frac{1}{2}}_{ij} - \biggl( \frac{\partial C}{\partial t} - D_{y} \delta^{2}_{y} C \biggr)| ^{n + \frac{1}{2}}_{ij} \biggr] + R^{n+\frac{1}{2}}_{1ij}, \\ &\qquad (i,j)\in\omega, 0\leq n\leq K-1, \end{aligned}$$
(7)

where the truncation error is

$$\begin{aligned} \bigl\vert R^{n+\frac{1}{2}}_{1ij} \bigr\vert = O \bigl(h^{4}_{x} \bigr),\quad (i,j)\in\omega, 0\leq n\leq K-1. \end{aligned}$$
(8)

Considering Eq. (3) at the point \((x_{i},y_{j},t_{n+\frac{1}{2}})\), we have

$$\begin{aligned} & {-}D_{y} \frac{\partial^{2} C}{\partial y^{2}}(x_{i},y_{j},t_{n + \frac {1}{2}}) \\ &\quad = f (x_{i},y_{j},t_{n + \frac{1}{2}})- \biggl[ \frac{\partial C}{\partial t}(x_{i},y_{j},t_{n + \frac{1}{2}}) - D_{x} \frac{\partial^{2} C}{\partial x^{2}}(x_{i},y_{j},t_{n + \frac{1}{2}}) + v\frac{\partial C}{\partial x}(x_{i},y_{j},t_{n + \frac{1}{2}}) \biggr], \\ &\qquad(i,j)\in\omega, 0\leq n\leq K-1. \end{aligned}$$
(9)

For the interior nodes of the spatial of Eq. (3), we use the derivative type fourth-order compact differential formula to deal with the one-dimensional convection–diffusion equation [22].

For convenience, we define a compact difference operator by \(\mathcal {B}\) [12], for any \(u \in\mathcal{U}_{h}\),

$$ (\mathcal{B} u)_{ij} = \textstyle\begin{cases} \frac{u_{i,j-1} + 10 u_{ij} + u_{i,j+1}}{12}, & 1 \leq i \leq N, 1 \leq j \leq M-1, \\ u_{ij},& 1 \leq i \leq N, j = 0, M. \end{cases} $$
(10)

By Lemma 1.2(g) [12]: If \(g(x) \in C^{6}[c-h, c+h]\), then we have

$$ \frac{1}{12} \bigl[g^{\prime\prime}(c-h) +10 g^{\prime\prime} (c) + g^{\prime\prime} (c+h) \bigr] = \frac {1}{h^{2}} \bigl[g(c-h) +10 g(c) + g(c+h) \bigr] + \frac{h^{4}}{240}g^{6}(\xi_{6}), $$

where \(\xi_{6} \in(c-h, c+h)\), \(h>0\) and c are two positive constants.

We have

$$\begin{aligned} \mathcal{B} \frac{\partial^{2}u}{\partial{y^{2}}}(x_{i},y_{j},t_{n}) = \delta ^{2}_{y}u^{n}_{ij} + \frac{h_{y}^{4}}{240} \frac{\partial^{6} u}{\partial {y^{6}}}(x_{i},\xi_{jk},t_{n}), \end{aligned}$$
(11)

where \(1 \leq i \leq N, 1 \leq j \leq M-1, 1 \leq n \leq K\), and \(\xi _{jk} \in(y_{j-1}, y_{j})\).

Apply compact difference operator \(\mathcal{B}\) to both sides of Eq. (9), combine with Eq. (11); we have

$$\begin{aligned} & {-}D_{y}\delta^{2}_{y} C^{n + \frac{1}{2}}_{ij} \\ &\quad = \frac{1}{12} \biggl\{ \biggl[f(x_{i},y_{j},t_{n + \frac{1}{2}}) - \biggl(\frac {\partial C}{\partial t} (x_{i},y_{j},t_{n + \frac{1}{2}})- D_{x} \frac{\partial^{2} C}{\partial x^{2}}(x_{i},y_{j},t_{n + \frac{1}{2}}) + v \frac{\partial C}{\partial x}(x_{i},y_{j},t_{n + \frac{1}{2}}) \biggr) \biggr] \\ &\qquad{}+ 10 \biggl[f(x_{i},y_{j},t_{n + \frac{1}{2}}) - \biggl( \frac {\partial C}{\partial t}(x_{i},y_{j},t_{n + \frac{1}{2}}) - D_{x} \frac{\partial^{2} C}{\partial x^{2}}(x_{i},y_{j},t_{n + \frac{1}{2}}) + v \frac{\partial C}{\partial x}(x_{i},y_{j},t_{n + \frac{1}{2}}) \biggr) \biggr] \\ &\qquad{}+ \biggl[f(x_{i},y_{j},t_{n + \frac{1}{2}}) - \biggl( \frac{\partial C}{\partial t} (x_{i},y_{j},t_{n + \frac{1}{2}})- D_{x} \frac{\partial^{2} C}{\partial x^{2}} (x_{i},y_{j},t_{n + \frac{1}{2}}) + v \frac{\partial C}{\partial x}(x_{i},y_{j},t_{n + \frac{1}{2}}) \biggr) \biggr] \biggr\} \\ &\qquad{}+ \frac{h_{y}^{4}}{240} \frac{\partial^{6} u}{\partial {y^{6}}}(x_{i},\xi _{jk},t_{n}),\quad (i,j)\in\omega, 0\leq n\leq K-1. \end{aligned}$$
(12)

It is easy to observe that Eq. (12) is equal to the following form:

$$\begin{aligned} &{ -}D_{y}\delta^{2}_{y} C(x_{i},y_{j},t_{n + \frac {1}{2}}) \\ &\quad= \biggl[1 + \frac{h^{2}_{y}}{12} \delta^{2}_{y} \biggr] \biggl\{ f(x_{i},y_{j},t_{n + \frac {1}{2}})- \biggl[ \frac{\partial C}{\partial t} (x_{i},y_{j},t_{n + \frac {1}{2}}) \\ &\qquad{}- D_{x} \frac{\partial^{2} C}{\partial x^{2}} (x_{i},y_{j},t_{n + \frac {1}{2}}) + v \frac{\partial C}{\partial x}(x_{i},y_{j},t_{n + \frac {1}{2}}) \biggr] \biggr\} + \frac {h_{y}^{4}}{240} \frac{\partial^{6} u}{\partial{y^{6}}}(x_{i},\xi _{jk},t_{n}), \\ &\qquad(i,j)\in\omega, 0\leq n\leq K-1. \end{aligned}$$
(13)

Taking the Taylor formula into account again, applying the Taylor expansion for Eq. (13), we have

$$\begin{aligned} &{-}D_{y}\delta^{2}_{y} C^{n + \frac{1}{2}}_{ij} = \biggl[1 + \frac{h^{2}_{y}}{12} \delta^{2}_{y} \biggr] \biggl[f^{n + \frac{1}{2}}_{i,j} - \biggl(\frac{\partial C}{\partial t} - D_{x} \delta^{2}_{x}C + v \Delta _{x}C \biggr)| ^{n + \frac{1}{2}}_{i,j} \biggr] + R^{n+\frac {1}{2}}_{2ij}, \\ &\quad(i,j)\in\omega, 0\leq n\leq K-1, \end{aligned}$$
(14)

where the truncation error is

$$ \bigl\vert R^{n+\frac{1}{2}}_{2ij} \bigr\vert = O \bigl(h^{4}_{y} \bigr), \quad (i,j)\in\omega, 0\leq n\leq K-1.$$
(15)

Adding Eq. (7) to Eq. (14) and using Eq. (1) yield

$$\begin{aligned} &{-} \biggl(D_{x} + \frac{v^{2} h^{2}_{x}}{12 D_{x}} \biggr) \delta^{2}_{x} C^{n + \frac{1}{2}}_{ij} + v \Delta _{x} C^{n + \frac{1}{2}}_{ij} -D_{y}\delta ^{2}_{y} C^{n + \frac{1}{2}}_{ij} \\ &\quad= \biggl[ 1 + \frac{h^{2}_{x}}{12} \biggl(\delta^{2}_{x} - \frac{v}{D_{x}} \Delta _{x} \biggr) \biggr] \biggl[f^{n + \frac{1}{2}}_{ij} - \biggl( \frac{\partial C}{\partial t} - D_{y} \delta^{2}_{y} C \biggr)| ^{n + \frac{1}{2}}_{ij} \biggr] \\ &\qquad{}+ \biggl[1 + \frac{h^{2}_{y}}{12} \delta^{2}_{y} \biggr] \biggl[f^{n + \frac {1}{2}}_{i,j} - \biggl(\frac{\partial C}{\partial t} - D_{x} \delta^{2}_{x}C + v \Delta _{x}C \biggr)| ^{n + \frac{1}{2}}_{i,j} \biggr] + R^{n+\frac{1}{2}}_{1ij} + R^{n+\frac {1}{2}}_{2ij}. \end{aligned}$$
(16)

For the time term of Eq. (16), we make a Crank–Nicolson (C-N) time discretization, noticing the former notations, we can construct

$$\begin{aligned} & \biggl\{ \frac{1}{2} \biggl[ - \biggl(D_{x} + \frac{v^{2}h^{2}_{x}}{12D_{x}} \biggr) \delta^{2}_{x} + v \Delta _{x}- D_{y} \delta^{2}_{y} - \frac {D_{y}h^{2}_{x} + D_{x}h^{2}_{y}}{12}\delta^{2}_{x}\delta ^{2}_{y}+ \biggl(\frac {D_{y}vh^{2}_{x}}{12D_{x}} + \frac{vh^{2}_{y}}{12} \biggr) \delta^{2}_{y} \Delta _{x} \biggr] \\ &\qquad{}+ \frac{1}{\tau} \biggl[ 1+ \frac{h^{2}_{x}}{12} \biggl( \delta^{2}_{x} - \frac{v}{D_{x}} \Delta _{x} \biggr) + \frac{h^{2}_{y}}{12} \delta^{2}_{y} \biggr] \biggr\} C^{n+1}_{ij} \\ &\quad= \biggl[ 1+ \frac{h^{2}_{x}}{12} \biggl( \delta^{2}_{x} - \frac{v}{D_{x}} \Delta _{x} \biggr) + \frac{h^{2}_{y}}{12} \delta^{2}_{y} \biggr] \} f^{n+\frac{1}{2}}_{ij} \\ &\qquad{}- \biggl\{ \frac{1}{2} \biggl[ - \biggl(D_{x} + \frac {v^{2}h^{2}_{x}}{12D_{x}} \biggr) \delta^{2}_{x} + v \Delta _{x}- D_{y} \delta ^{2}_{y} - \frac{D_{y}h^{2}_{x} + D_{x}h^{2}_{y}}{12}\delta ^{2}_{x}\delta^{2}_{y} \\ &\qquad{}+ \biggl(\frac{D_{y}vh^{2}_{x}}{12D_{x}} + \frac{vh^{2}_{y}}{12} \biggr) \delta^{2}_{y} \Delta _{x} \biggr]- \frac{1}{\tau} \biggl[ 1+ \frac{h^{2}_{x}}{12} \biggl( \delta ^{2}_{x} - \frac{v}{D_{x}} \Delta _{x} \biggr) + \frac{h^{2}_{y}}{12} \delta ^{2}_{y} \biggr] \biggr\} C^{n}_{ij} + R^{n}_{ij}, \\ &\qquad(i,j)\in\omega, 0\leq n\leq K-1, \end{aligned}$$
(17)

where \(R^{n}_{ij} = \mathcal{O}(\tau^{2} + h_{x}^{4} + h_{y}^{4}) \) is the truncation error.

Taking the initial and boundary conditions of Eq. (1) into account, we have

$$ \begin{aligned}& C^{0}_{ij}=0,\quad (i,j) \in\omega, \\ &C^{n}_{ij}=g(x_{i},y_{j},t_{n}),\quad (i,j)\in\sigma, 0\leq n\leq K. \end{aligned} $$
(18)

Ignoring the higher-order terms \(R^{n+\frac{1}{2}}_{ij}\) in (17), and replacing \(C^{n}_{ij}\) with its approximation \(c^{n}_{ij}\), the compact difference scheme of Eq. (1) can be obtained,

$$\begin{aligned} \textstyle\begin{cases} \{ \frac{1}{2} [ - (D_{x} + \frac{v^{2}h^{2}_{x}}{12D_{x}}) \delta^{2}_{x} + v \Delta _{x}- D_{y} \delta^{2}_{y} - \frac {D_{y}h^{2}_{x} + D_{x}h^{2}_{y}}{12}\delta^{2}_{x}\delta^{2}_{y} +(\frac{D_{y}vh^{2}_{x}}{12D_{x}} + \frac{vh^{2}_{y}}{12}) \delta^{2}_{y} \Delta _{x}] \\ \qquad{} + \frac{1}{\tau}[ 1+ \frac{h^{2}_{x}}{12}( \delta^{2}_{x} - \frac{v}{D_{x}} \Delta _{x}) + \frac{h^{2}_{y}}{12} \delta ^{2}_{y}] \} c^{n+1}_{ij} \\ \quad=[ 1+ \frac{h^{2}_{x}}{12}( \delta^{2}_{x} - \frac{v}{D_{x}} \Delta _{x}) + \frac{h^{2}_{y}}{12} \delta^{2}_{y}] f^{n+\frac{1}{2}}_{ij} \\ \qquad{} - \{ \frac{1}{2} [ -(D_{x} + \frac {v^{2}h^{2}_{x}}{12D_{x}}) \delta^{2}_{x} + v \Delta _{x}- D_{y} \delta ^{2}_{y} - \frac{D_{y}h^{2}_{x} + D_{x}h^{2}_{y}}{12}\delta ^{2}_{x}\delta^{2}_{y} + (\frac{D_{y}vh^{2}_{x}}{12D_{x}} + \frac{vh^{2}_{y}}{12}) \delta^{2}_{y} \Delta _{x}]\\ \qquad{}- \frac{1}{\tau}[ 1+ \frac{h^{2}_{x}}{12}( \delta^{2}_{x} - \frac{v}{D_{x}} \Delta _{x}) + \frac{h^{2}_{y}}{12} \delta^{2}_{y}] \} c^{n}_{ij}, \\ \qquad(i,j)\in\omega, 0\leq n\leq K-1, \\ c^{0}_{ij}(x,y)=c_{0}(x_{i},y_{j}),\quad (i,j)\in\omega, \\ c^{n}_{ij}(x,y)=g(x_{i},y_{j},t_{n}),\quad (i,j)\in\omega, 0\leq n\leq K. \end{cases}\displaystyle \end{aligned}$$
(19)

The node graph of the scheme (19) is shown in Fig. 1, which is a two layer scheme.

Figure 1
figure 1

Node distribution graph of the compact difference scheme

Theorem 2.1

The truncation error of the compact finite difference scheme (19) is

$$ \bigl\vert R^{n}_{ij} \bigr\vert = \mathcal{O} \bigl( \tau^{2} + h_{x}^{4} + h_{y}^{4} \bigr),\quad (i,j)\in \omega, 0\leq n\leq K. $$
(20)

3 Matrix form of the numerical scheme

The numerical scheme of the convection–diffusion equation plays a very important role in computational fluid dynamics to simulate flow problems [20]. Therefore, accurate and stable difference schemes are of vital importance. To achieve the unconditional stability, we resort to the Crank–Nicolson method for a time discretization of Eq. (19). Notice the notations defined in Sect. 2 for the difference scheme (19), which will result in a system of algebraic equations that is sparse; the existence and uniqueness of the solution of the scheme (19) are easily known by the positive definite property. We have

$$\begin{aligned} &\biggl\{ \frac{1}{2} \biggl\{ \biggl[ \biggl(D_{x} + \frac{v^{2}h^{2}_{x}}{12D_{x}} \biggr)\frac{2}{h^{2}_{x}} + \frac{2D_{y}}{h^{2}_{y}} \biggr] + \biggl[- \frac{2(D_{y}h^{2}_{x} + D_{x}h^{2}_{y} )}{ 12h^{2}_{y} } \frac{2}{h^{2}_{x}} \biggr] \biggr\} \\ &\qquad{}+ \frac{1}{\tau} \biggl[ 1 - \frac{h^{2}_{x}}{12} \frac {2}{h^{2}_{x}} - \frac{h^{2}_{y}}{12} \frac{2}{h^{2}_{y}} \biggr] \biggr\} c^{n + 1}_{ij}+ \biggl\{ \frac{ 1}{2} \biggl\{ \biggl[- \biggl(D_{x} + \frac {v^{2}h^{2}_{x}}{12D_{x}} \biggr)\frac {1}{h^{2}_{x}} + \frac{v}{2h_{x}} \biggr] \\ &\qquad{}+ \biggl[\frac{2(D_{y}h^{2}_{x} + D_{x}h^{2}_{y} )}{ 12h^{2}_{y} } \frac{1}{h^{2}_{x}} \biggr] + \biggl[- \biggl( \frac{D_{y}v h^{2}_{y}}{12D_{x}} + \frac{v h^{2}_{y}}{12} \biggr)\frac{1}{2 h_{x}} \frac{2}{h^{2}_{y}} \biggr] \biggr\} \\ &\qquad{}+ \frac{1}{\tau} \biggl[ \frac{h^{2}_{x}}{12} \frac {2}{h^{2}_{x}} - \frac{h^{2}_{x}}{12} \frac{v}{D_{x}} \frac{1}{2h_{x}} \biggr] \biggr\} c^{n + 1}_{i+1,j} \\ &\qquad{}+ \biggl\{ \frac{1}{2} \biggl\{ \biggl[- \biggl(D_{x} + \frac {v^{2}h^{2}_{x}}{12D_{x}} \biggr)\frac{1}{h^{2}_{x}} - \frac{v}{2h_{x}} \biggr] + \biggl[ \frac {2(D_{y}h^{2}_{x} + D_{x}h^{2}_{y} )}{ 12h^{2}_{y} } \frac{1}{h^{2}_{x}} \biggr] \\ &\qquad{}- \biggl[- \biggl( \frac{D_{y}v h^{2}_{y}}{12D_{x}} + \frac{v h^{2}_{y}}{12} \biggr) \frac{1}{2 h_{x}}\frac{2}{h^{2}_{y}} \biggr] \biggr\} + \frac {1}{\tau} \biggl[ \frac {h^{2}_{x}}{12} \frac{2}{h^{2}_{x}} + \frac{h^{2}_{x}}{12} \frac {v}{D_{x}} \frac {1}{2h_{x}} \biggr] \biggr\} c^{n + 1}_{i-1,j} \\ &\qquad{}+ \biggl\{ \frac{1}{2} \biggl\{ -\frac{D_{y}}{h^{2}_{y}} -\frac {1}{2} \biggl[-\frac {2(D_{y}h^{2}_{x} + D_{x}h^{2}_{y} )}{ 12h^{2}_{y} } \frac{2}{h^{2}_{x}} \biggr] \biggr\} + \frac{1}{\tau} \frac{h^{2}_{y}}{12} \frac{2}{h^{2}_{y}} \biggr\} c^{n + 1}_{i,j+1} \\ &\qquad{}+ \biggl\{ \frac{1}{2} \biggl\{ -\frac{D_{y}}{h^{2}_{y}} -\frac {1}{2} \biggl[-\frac {2(D_{y}h^{2}_{x} + D_{x}h^{2}_{y} )}{ 12h^{2}_{y} } \frac{2}{h^{2}_{x}} \biggr] \biggr\} + \frac{1}{\tau} \frac{h^{2}_{y}}{12} \frac{2}{h^{2}_{y}} \biggr\} c^{n + 1}_{i,j-1} \\ &\qquad{}+ \{\frac{1}{2} \biggl\{ -\frac{1}{2} \biggl[\frac {2(D_{y}h^{2}_{x} + D_{x}h^{2}_{y} )}{ 12h^{2}_{y} } \frac{1}{h^{2}_{x}} \biggr] + \biggl[ \biggl( \frac{D_{y}v h^{2}_{y}}{12D_{x}} + \frac{v h^{2}_{y}}{12} \biggr)\frac{1}{2 h_{x}} \frac {1}{h^{2}_{y}} \biggr] \biggr\} c^{n + 1}_{i+1,j+1} \\ &\qquad{}+ \{\frac{1}{2} \biggl\{ -\frac{1}{2} \biggl[\frac {2(D_{y}h^{2}_{x} + D_{x}h^{2}_{y} )}{ 12h^{2}_{y} } \frac{1}{h^{2}_{x}} \biggr] - \biggl[ \biggl( \frac{D_{y}v h^{2}_{y}}{12D_{x}} + \frac{v h^{2}_{y}}{12} \biggr)\frac{1}{2 h_{x}}\frac {1}{h^{2}_{y}} \biggr] \biggr\} c^{n + 1}_{i-1,j+1} \\ &\qquad{}+ \{\frac{1}{2} \biggl\{ -\frac{1}{2} \biggl[\frac {2(D_{y}h^{2}_{x} + D_{x}h^{2}_{y} )}{ 12h^{2}_{y} } \frac{1}{h^{2}_{x}} \biggr] + \biggl[ \biggl( \frac{D_{y}v h^{2}_{y}}{12D_{x}} + \frac{v h^{2}_{y}}{12} \biggr)\frac{1}{2 h_{x}}\frac {1}{h^{2}_{y}} \biggr] \biggr\} c^{n + 1}_{i+1,j-1} \\ &\qquad{}+ \{\frac{1}{2} \biggl\{ -\frac{1}{2} \biggl[\frac {2(D_{y}h^{2}_{x} + D_{x}h^{2}_{y} )}{ 12h^{2}_{y} } \frac{1}{h^{2}_{x}} \biggr] + \biggl[ \biggl( \frac{D_{y}v h^{2}_{y}}{12D_{x}} + \frac{v h^{2}_{y}}{12} \biggr)\frac{1}{2 h_{x}}\frac {1}{h^{2}_{y}} \biggr] \biggr\} c^{n + 1}_{i-1,j-1} \\ &\quad= \biggl\{ - \frac{1}{2} \biggl\{ \biggl[ \biggl(D_{x} + \frac{v^{2}h^{2}_{x}}{12D_{x}} \biggr)\frac {2}{h^{2}_{x}} + \frac{2D_{y}}{h^{2}_{y}} \biggr] + \biggl[- \frac{2(D_{y}h^{2}_{x} + D_{x}h^{2}_{y} )}{ 12h^{2}_{y} } \frac{2}{h^{2}_{x}} \biggr] \biggr\} \\ &\qquad{}+ \frac{1}{\tau} \biggl[ 1 - \frac{h^{2}_{x}}{12} \frac {2}{h^{2}_{x}} - \frac{h^{2}_{y}}{12} \frac{2}{h^{2}_{y}} \biggr] \biggr\} c^{n}_{ij} \\ &\qquad{}+ \biggl\{ - \frac{1}{2} \biggl\{ \biggl[- \biggl(D_{x} + \frac {v^{2}h^{2}_{x}}{12D_{x}} \biggr)\frac{1}{h^{2}_{x}} + \frac{v}{2h_{x}} \biggr] + \biggl[ \frac {2(D_{y}h^{2}_{x} + D_{x}h^{2}_{y} )}{ 12h^{2}_{y} } \frac{1}{h^{2}_{x}} \biggr] \\ &\qquad{}+ \biggl[- \biggl( \frac{D_{y}v h^{2}_{y}}{12D_{x}} + \frac{v h^{2}_{y}}{12} \biggr) \frac{1}{2 h_{x}}\frac{2}{h^{2}_{y}} \biggr] \biggr\} + \frac {1}{\tau} \biggl[ \frac {h^{2}_{x}}{12} \frac{2}{h^{2}_{x}} - \frac{h^{2}_{x}}{12} \frac {v}{D_{x}} \frac {1}{2h_{x}} \biggr] \biggr\} c^{n}_{i+1,j} \\ &\qquad{}+ \biggl\{ - \frac{1}{2} \biggl\{ \biggl[- \biggl(D_{x} + \frac {v^{2}h^{2}_{x}}{12D_{x}} \biggr)\frac{1}{h^{2}_{x}} - \frac{v}{2h_{x}} \biggr] + \biggl[ \frac {2(D_{y}h^{2}_{x} + D_{x}h^{2}_{y} )}{ 12h^{2}_{y} } \frac {1}{h^{2}_{x}} \biggr] \\ &\qquad{}- \biggl[- \biggl( \frac{D_{y}v h^{2}_{y}}{12D_{x}} + \frac{v h^{2}_{y}}{12} \biggr) \frac{1}{2 h_{x}}\frac{2}{h^{2}_{y}} \biggr] \biggr\} + \frac {1}{\tau} \biggl[ \frac {h^{2}_{x}}{12} \frac{2}{h^{2}_{x}} + \frac{h^{2}_{x}}{12} \frac {v}{D_{x}} \frac {1}{2h_{x}} \biggr] \biggr\} c^{n}_{i-1,j} \\ &\qquad{}+ \biggl\{ - \frac{1}{2} \biggl\{ -\frac{D_{y}}{h^{2}_{y}} -\frac {1}{2} \biggl[-\frac{2(D_{y}h^{2}_{x} + D_{x}h^{2}_{y} )}{ 12h^{2}_{y} } \frac {2}{h^{2}_{x}} \biggr] \biggr\} + \frac{1}{\tau} \frac{h^{2}_{y}}{12} \frac {2}{h^{2}_{y}} \biggr\} c^{n}_{i,j+1} \\ &\qquad{}+ \biggl\{ - \frac{1}{2} \biggl\{ -\frac{D_{y}}{h^{2}_{y}} -\frac {1}{2} \biggl[-\frac{2(D_{y}h^{2}_{x} + D_{x}h^{2}_{y} )}{ 12h^{2}_{y} } \frac {2}{h^{2}_{x}} \biggr] \biggr\} + \frac{1}{\tau} \frac{h^{2}_{y}}{12} \frac {2}{h^{2}_{y}} \biggr\} c^{n}_{i,j-1} \\ &\qquad{}- \frac{1}{2} \biggl\{ -\frac{1}{2} \biggl[\frac{2(D_{y}h^{2}_{x} + D_{x}h^{2}_{y} )}{ 12h^{2}_{y} } \frac{1}{h^{2}_{x}} \biggr] + \biggl[ \biggl( \frac{D_{y}v h^{2}_{y}}{12D_{x}} + \frac{v h^{2}_{y}}{12} \biggr)\frac{1}{2 h_{x}}\frac {1}{h^{2}_{y}} \biggr] \biggr\} c^{n}_{i+1,j+1} \\ &\qquad{}- \frac{1}{2} \biggl\{ -\frac{1}{2} \biggl[\frac{2(D_{y}h^{2}_{x} + D_{x}h^{2}_{y} )}{ 12h^{2}_{y} } \frac{1}{h^{2}_{x}} \biggr] - \biggl[ \biggl( \frac{D_{y}v h^{2}_{y}}{12D_{x}} + \frac{v h^{2}_{y}}{12} \biggr)\frac{1}{2 h_{x}}\frac {1}{h^{2}_{y}} \biggr] \biggr\} c^{n}_{i-1,j+1} \\ &\qquad{}- \frac{1}{2} \biggl\{ -\frac{1}{2} \biggl[\frac{2(D_{y}h^{2}_{x} + D_{x}h^{2}_{y} )}{ 12h^{2}_{y} } \frac{1}{h^{2}_{x}} \biggr] + \biggl[ \biggl( \frac{D_{y}v h^{2}_{y}}{12D_{x}} + \frac{v h^{2}_{y}}{12} \biggr)\frac{1}{2 h_{x}}\frac {1}{h^{2}_{y}} \biggr] \biggr\} c^{n}_{i+1,j-1} \\ &\qquad{}- \frac{1}{2} \biggl\{ -\frac{1}{2} \biggl[\frac{2(D_{y}h^{2}_{x} + D_{x}h^{2}_{y} )}{ 12h^{2}_{y} } \frac{1}{h^{2}_{x}} \biggr] + \biggl[ \biggl( \frac{D_{y}v h^{2}_{y}}{12D_{x}} + \frac{v h^{2}_{y}}{12} \biggr)\frac{1}{2 h_{x}}\frac {1}{h^{2}_{y}} \biggr] \biggr\} c^{n}_{i-1,j-1} \\ &\qquad{}+ \biggl[ 1 - \frac{h^{2}_{x}}{12} \frac{2}{h^{2}_{x}} - \frac {h^{2}_{y}}{12} \frac{2}{h^{2}_{y}} \biggr]f^{n + \frac{1}{2}}_{ij} + \biggl[ \frac{h^{2}_{x}}{12} \frac{2}{h^{2}_{x}} - \frac{h^{2}_{x}}{12} \frac {v}{D_{x}} \frac{1}{2h_{x}} \biggr]f^{n + \frac{1}{2}}_{i+1,j} \\ &\qquad{}+ \biggl[ \frac{h^{2}_{x}}{12} \frac{2}{h^{2}_{x}} + \frac {h^{2}_{x}}{12} \frac{v}{D_{x}} \frac{1}{2h_{x}} \biggr]f^{n + \frac{1}{2}}_{i-1,j} + \frac{h^{2}_{y}}{12} \frac{2}{h^{2}_{y}}f^{n + \frac {1}{2}}_{i,j+1} + \frac {h^{2}_{y}}{12} \frac{2}{h^{2}_{y}}f^{n + \frac{1}{2}}_{i,j-1}. \end{aligned}$$
(21)

Let

$$\begin{aligned} &a_{1} = \biggl(D_{x} + \frac{v^{2}h^{2}_{x}}{12D_{x}} \biggr)\frac{2}{h^{2}_{x}} + \frac {2D_{y}}{h^{2}_{y}},\qquad a_{2} = - \biggl(D_{x} + \frac {v^{2}h^{2}_{x}}{12D_{x}} \biggr)\frac {1}{h^{2}_{x}} + \frac{v}{2h_{x}}, \\ &a_{3} = - \biggl(D_{x} + \frac{v^{2}h^{2}_{x}}{12D_{x}} \biggr) \frac{1}{h^{2}_{x}} - \frac {v}{2h_{x}},\qquad a_{4} = a_{5} = - \frac{D_{y}}{h^{2}_{y}}, \\ &b_{1} = -\frac{2(D_{y}h^{2}_{x} + D_{x}h^{2}_{y} )}{ 12h^{2}_{y} } \frac {2}{h^{2}_{x}},\qquad b_{2} = b_{3} = \frac{2(D_{y}h^{2}_{x} + D_{x}h^{2}_{y} )}{ 12h^{2}_{y} } \frac{1}{h^{2}_{x}}, \\ &b_{4} = b_{5} = -\frac{1}{2}b_{1},\qquad b_{6} = b_{8} = -\frac{1}{2}b_{2},\qquad b_{7} = b_{9} = -\frac{1}{2}b_{3}, \\ &c_{2} = - \biggl( \frac{D_{y}v h^{2}_{y}}{12D_{x}} + \frac{v h^{2}_{y}}{12} \biggr) \frac {1}{2 h_{x}}\frac{2}{h^{2}_{y}},\qquad c_{6} = c_{8} = \biggl( \frac{D_{y}v h^{2}_{y}}{12D_{x}} + \frac{v h^{2}_{y}}{12} \biggr)\frac{1}{2 h_{x}} \frac {1}{h^{2}_{y}}, \\ &c_{3} = -c_{2},\qquad c_{7} = -c_{6},\qquad c_{9} = -c_{8}, \\ &e_{1} = \frac{1}{\tau} \biggl[ 1 - \frac{h^{2}_{x}}{12} \frac {2}{h^{2}_{x}} - \frac {h^{2}_{y}}{12} \frac{2}{h^{2}_{y}} \biggr],\qquad e_{2} = \frac{1}{\tau} \biggl[ \frac {h^{2}_{x}}{12} \frac{1}{h^{2}_{x}} - \frac{h^{2}_{x}}{12} \frac {v}{D_{x}} \frac {1}{2h_{x}} \biggr], \\ &e_{3} = \frac{1}{\tau} \biggl[ \frac{h^{2}_{x}}{12} \frac{1}{h^{2}_{x}} + \frac {h^{2}_{x}}{12} \frac{v}{D_{x}} \frac{1}{2h_{x}} \biggr],\qquad e_{4} = e_{5} = \frac {1}{\tau} \frac{h^{2}_{y}}{12} \frac{2}{h^{2}_{y}}, \end{aligned}$$

It is obvious that the compact finite difference scheme (21) is a system of linear equations based on the variable \(c^{n}_{ij}, 0\leq i\leq N, 0\leq j\leq M, 0\leq n\leq K\), then Eq. (21) can be written as

$$\begin{aligned} & p_{1} c^{n+1}_{ij} + p_{2}c^{n+1}_{i+1,j} + p_{3}c^{n+1}_{i-1,j} + p_{4}c^{n+1}_{i,j+1} + p_{5}c^{n+1}_{i,j-1} + p_{6}c^{n+1}_{i+1,j+1} \\ &\qquad{}+ p_{7}c^{n+1}_{i-1,j+1} + p_{8}c^{n+1}_{i+1,j-1} + p_{9}c^{n+1}_{i-1,j-1} \\ &\quad= q_{1} c^{n}_{ij} + q_{2}c^{n}_{i+1,j} + q_{3}c^{n}_{i-1,j} + q_{4}c^{n}_{i,j+1} + q_{5}c^{n}_{i,j-1} + q_{6}c^{n}_{i+1,j+1} \\ &\qquad{}+ q_{7}c^{n}_{i-1,j+1} + q_{8}c^{n}_{i+1,j-1} + q_{9}c^{n}_{i-1,j-1} \\ &\qquad{}+ \tau e_{1} f^{n + \frac{1}{2}}_{ij} + \tau e_{2} f^{n + \frac{1}{2}}_{i+1,j} + \tau e_{3} f^{n + \frac{1}{2}}_{i-1,j} + \tau e_{4}f^{n + \frac{1}{2}}_{i,j+1} +\tau e_{5}f^{n + \frac{1}{2}}_{i,j-1}, \end{aligned}$$
(22)

where

$$\begin{aligned} &p_{1} = \frac{a_{1} + b_{1}}{2} + e_{1}, \qquad p_{2} = \frac{a_{2} + b_{2} + c_{2}}{2} + e_{2}, \qquad p_{3} = \frac{a_{3} + b_{3} + c_{3}}{2} + e_{3}, \\ & p_{4} = \frac{a_{4} + b_{4}}{2} + e_{4}, \qquad p_{5} = \frac{a_{5} + b_{5}}{2} + e_{5}, \qquad p_{6} = \frac{b_{6} + c_{6}}{2}, \\ \begin{aligned} &p_{7} = \frac{b_{7} + c_{7}}{2},\qquad p_{8} = \frac{b_{8} + c_{8}}{2},\qquad p_{9} = \frac{b_{9} + c_{6}}{9}, \\ &q_{1} = -\frac{a_{1} + b_{1}}{2} + e_{1},\qquad q_{2} = - \frac{a_{2} + b_{2} + c_{2}}{2} + e_{2}, \qquad q_{3} = -\frac{a_{3} + b_{3} + c_{3}}{2}, \end{aligned} \\ & q_{4} = -\frac{a_{4} + b_{4}}{2} + e_{4},\qquad q_{5} = -\frac{a_{5} + b_{5}}{2} + e_{5}, \qquad q_{6} = - \frac{b_{6} + c_{6}}{2}, \\ &q_{7} = -\frac{b_{7} + c_{7}}{2},\qquad q_{8} = - \frac{b_{8} + c_{8}}{2},\qquad q_{9} = -\frac{b_{9} + c_{6}}{9}. \end{aligned}$$
(23)

Let

$$\mathbf{c}_{j}= \begin{pmatrix} c_{1j} \\ c_{2j} \\ \vdots\\ c_{M-1,j} \end{pmatrix},\quad 0 \leq j \leq M-1. $$

We can give the matrix form of the scheme by

$$\begin{aligned} & \mathbf{P_{2}} \mathbf{c}^{n+1}_{j+1} + \mathbf {P_{1}} \mathbf {c}^{n+1}_{j} + \mathbf{P_{3}} \mathbf{c}^{n+1}_{j-1} \\ &\quad= \mathbf{Q_{2}} \mathbf{c}^{n}_{j+1} + \mathbf{Q_{1}} \mathbf {c}^{n}_{j} + \mathbf {Q_{3}} \mathbf{c}^{n}_{j-1} + \tau \mathbf{E_{2}} \mathbf {f}^{n+\frac {1}{2}}_{j+1} + \tau \mathbf{E_{1}} \mathbf{f}^{n+\frac{1}{2}}_{j} + \tau\mathbf {E_{3}} \mathbf{f}^{n+\frac{1}{2}}_{j-1},\quad 1 \leq j \leq M, \end{aligned}$$
(24)

where

$$\begin{aligned} &\mathbf{P_{1}}= \begin{pmatrix} p_{1} &p_{2} & & & \\ p_{3} &p_{1} &p_{2} & & \\ &\ddots&\ddots& \ddots& \\ & &p_{3} & p_{1} & p_{2} \\ & & & p_{3} & p_{1} \end{pmatrix},\qquad \mathbf{P_{2}}= \begin{pmatrix} p_{4} &p_{6} & & & \\ p_{7} &p_{4} &p_{6} & & \\ &\ddots&\ddots& \ddots& \\ & &p_{7} & p_{4} & p_{6} \\ & & & p_{7} & p_{4} \end{pmatrix},\qquad \\ &\mathbf{P_{3}}= \begin{pmatrix} p_{5} &p_{8} & & & \\ p_{9} &p_{5} &p_{8} & & \\ &\ddots&\ddots& \ddots& \\ & &p_{9} & p_{5} & p_{8} \\ & & & p_{9} & p_{5} \end{pmatrix},\qquad \mathbf{Q_{1}}= \begin{pmatrix} q_{1} &q_{2} & & & \\ q_{3} &q_{1} &q_{2} & & \\ &\ddots&\ddots& \ddots& \\ & &q_{3} & q_{1} & q_{2} \\ & & & q_{3} & q_{1} \end{pmatrix}, \\ &\mathbf{Q_{2}}= \begin{pmatrix} q_{4} &q_{6} & & & \\ q_{7} &q_{4} &q_{6} & & \\ &\ddots&\ddots& \ddots& \\ & &q_{7} & q_{4} & q_{6} \\ & & & q_{7} & q_{4} \end{pmatrix},\qquad \mathbf{Q_{3}}= \begin{pmatrix} q_{5} &q_{8} & & & \\ q_{9} &q_{5} &q_{8} & & \\ &\ddots&\ddots& \ddots& \\ & &q_{9} & q_{5} & q_{8} \\ & & & q_{9} & q_{5} \end{pmatrix}, \\ &\mathbf{E_{1}}= \begin{pmatrix} e_{1} &e_{2} & & & \\ e_{3} &e_{1} &e_{2} & & \\ &\ddots&\ddots& \ddots& \\ & &e_{3} & e_{1} & e_{2} \\ & & & e_{3} & e_{1} \end{pmatrix},\qquad \mathbf{E_{2}}= \begin{pmatrix} e_{4} & & & & \\ &e_{4} & & & \\ & &\ddots& & \\ & & & e_{4} & \\ & & & & e_{4} \end{pmatrix}, \\ &\mathbf{E_{3}}= \begin{pmatrix} e_{5} & & & & \\ &e_{5} & & & \\ & &\ddots& & \\ & & & e_{5} & \\ & & & & e_{5} \end{pmatrix},\qquad \mathbf{f}_{j}= \begin{pmatrix} [ 1+ \frac{h^{2}_{x}}{12}( \delta^{2}_{x} - \frac{v}{D_{x}} \Delta _{x}) + \frac {h^{2}_{y}}{12} \delta^{2}_{y}] f_{1j}\\ {}+ p_{9}c_{0,j-1} + p_{3}c_{0,j} + p_{7}c_{0,j+1} \\{} [ 1+ \frac{h^{2}_{x}}{12}( \delta^{2}_{x} - \frac{v}{D_{x}} \Delta _{x}) + \frac {h^{2}_{y}}{12} \delta^{2}_{y}] f_{2j} \\ \vdots\\{} [ 1+ \frac{h^{2}_{x}}{12}( \delta^{2}_{x} - \frac{v}{D_{x}} \Delta _{x}) + \frac {h^{2}_{y}}{12} \delta^{2}_{y}] f_{M-1,j}\\ {}+ p_{8}c_{M,j-1} + p_{2}c_{M,j} + p_{6}c_{M,j+1} \end{pmatrix}. \end{aligned}$$

By simply calculating, we can see that the matrix \(\mathbf{P}_{2}\) is the same as the matrix \(\mathbf{P}_{3}\) absolutely. So, we can further write (24) as

$$\begin{aligned} & \begin{pmatrix} \mathbf{P}_{1} &\mathbf{P}_{2} & & & \\ \mathbf{P}_{3} &\mathbf{P}_{1} &\mathbf{P}_{2} & & \\ &\ddots&\ddots& \ddots& \\ & &\mathbf{P}_{3} & \mathbf{P}_{1} & \mathbf{P}_{2} \\ & & & \mathbf{P}_{3} & \mathbf{P}_{1} \end{pmatrix} \begin{pmatrix} \mathbf{c}^{n+1}_{1} \\ \mathbf{c}^{n+1}_{2} \\ \vdots\\ \mathbf{c}^{n+1}_{M-2}\\ \mathbf{c}^{n+1}_{M-1} \end{pmatrix} \\ &\quad= \begin{pmatrix} \mathbf{Q}_{1} &\mathbf{Q}_{2} & & & \\ \mathbf{Q}_{3} &\mathbf{Q}_{1} &\mathbf{Q}_{2} & & \\ &\ddots&\ddots& \ddots& \\ & &\mathbf{Q}_{3} & \mathbf{Q}_{1} & \mathbf{Q}_{2} \\ & & & \mathbf{Q}_{3} & \mathbf{Q}_{1} \end{pmatrix} \begin{pmatrix} \mathbf{c}^{n}_{1} \\ \mathbf{c}^{n}_{2} \\ \vdots\\ \mathbf{c}^{n}_{M-2}\\ \mathbf{c}^{n}_{M-1} \end{pmatrix} \\ &\qquad{}+ \begin{pmatrix} \mathbf{E}_{1} &\mathbf{E}_{2} & & & \\ \mathbf{E}_{3} &\mathbf{E}_{1} &\mathbf{E}_{2} & & \\ &\ddots&\ddots& \ddots& \\ & &\mathbf{E}_{3} & \mathbf{E}_{1} & \mathbf{E}_{2} \\ & & & \mathbf{E}_{3} & \mathbf{E}_{1} \end{pmatrix} \begin{pmatrix} \mathbf{f}^{n+ \frac{1}{2}}_{1} - \mathbf{P}_{2}c_{0} \\ \mathbf{f}^{n+ \frac{1}{2}}_{2} \\ \vdots\\ \mathbf{f}^{n+ \frac{1}{2}}_{M-2}\\ \mathbf{f}^{n+ \frac{1}{2}}_{M-1} - \mathbf{P}_{2}c_{M} \end{pmatrix}. \end{aligned}$$

The coefficient matrix of the above linear equations is a three diagonal block matrix, and each row has at most nine nonzero elements, therefore we can rewrite the scheme (24) in the following matrix form:

$$\begin{aligned} \mathbf{P} \mathbf{c}^{n+1}_{ij} = \mathbf{Q} \mathbf{c}^{n}_{ij} + \tau\mathbf {Ef}^{n+1}_{ij}, \end{aligned}$$
(25)

where

$$\begin{aligned} &\mathbf{P} = \begin{pmatrix} \mathbf{P}_{1} &\mathbf{P}_{2} & & & \\ \mathbf{P}_{3} &\mathbf{P}_{1} &\mathbf{P}_{2} & & \\ &\ddots&\ddots& \ddots& \\ & &\mathbf{P}_{3} & \mathbf{P}_{1} & \mathbf{P}_{2} \\ & & & \mathbf{P}_{3} & \mathbf{P}_{1} \end{pmatrix},\qquad \mathbf{Q} = \begin{pmatrix} \mathbf{Q}_{1} &\mathbf{Q}_{2} & & & \\ \mathbf{Q}_{3} &\mathbf{Q}_{1} &\mathbf{Q}_{2} & & \\ &\ddots&\ddots& \ddots& \\ & &\mathbf{Q}_{3} & \mathbf{Q}_{1} & \mathbf{Q}_{2} \\ & & & \mathbf{Q}_{3} & \mathbf{Q}_{1} \end{pmatrix}, \\ &\mathbf{E} = \begin{pmatrix} \mathbf{E}_{1} &\mathbf{E}_{2} & & & \\ \mathbf{E}_{3} &\mathbf{E}_{1} &\mathbf{E}_{2} & & \\ &\ddots&\ddots& \ddots& \\ & &\mathbf{E}_{3} & \mathbf{E}_{1} & \mathbf{E}_{2} \\ & & & \mathbf{E}_{3} & \mathbf{E}_{1} \end{pmatrix}. \end{aligned}$$

Those three matrices are all strictly diagonally dominant tridiagonal matrices, which guarantees the existence and uniqueness of the solution.

4 Stability analysis

For the presentation of the theoretical analysis, we make \(f= 0 \) of the first equation in Eqs. (1) for convenience [1]. Assuming that the boundary conditions are accurate, we apply the Fourier method to the relative difference equation, by calculating the amplification factor to obtain an algebraic criterion for the stability analysis of the scheme (19). Without loss of generality, we choose \(D_{x}\), \(D_{y}\) and v as constants. Following the von Neumann condition [28] for linear stability, we assume that the numerical solution can be expressed in the form of a Fourier series [20].

Let

$$\begin{aligned} c^{n}_{ij} = \eta^{n} e^{ \sqrt{-1} ( i \xi_{x}h_{x} + j \xi _{y}h_{y})}, \end{aligned}$$
(26)

where \(\eta^{n}\) is the amplitude at time level n, \(\sqrt{-1} \) is called the imaginary unit, \(\xi_{x}\) and \(\xi_{y}\) represent the wave numbers in the x and y directions, respectively, the \(\xi _{x}h_{x}\) and \(\xi_{y}h_{y}\) are named phase angles.

The amplification factor is defined by

$$\begin{aligned} G(\xi_{x},\xi_{y},\tau) = \frac{\eta^{n+1}}{\eta^{n}}. \end{aligned}$$
(27)

Substituting the expression of \(c^{n+1}_{ij}\) and \(c^{n}_{ij}\) into Eq. (25), combining Eq. (26) with Eq. (27), the amplification factor can be written as

$$ G(\xi_{x},\xi_{y},\tau) = \frac{n}{m}, $$
(28)

where

$$\begin{aligned} n = {}&\bigl[(q_{1} + 2 q_{4})+( q_{2} + q_{3}) \gamma_{1} - 4q_{4} \gamma_{3} + (q_{6} + q_{7}) (\gamma_{4} + \gamma_{6}) \bigr] \\ &{}+ i \bigl[ (q_{2} - q_{3}) \gamma_{2} + (q_{6} - q_{7}) (\gamma_{5} + \gamma_{7}) \bigr], \\ m ={}& \bigl[(p_{1} + 2 p_{4})+( p_{2} + p_{3}) \gamma_{1} - 4p_{4} \gamma_{3} - (p_{6} + p_{7}) (\gamma_{4} + \gamma_{6}) \bigr] \\ &{}+ i \bigl[ (p_{2} - p_{3}) \gamma_{2} - (q_{6} - q_{7}) (\gamma_{5} + \gamma_{7}) \bigr], \end{aligned}$$

and

$$\begin{aligned} \begin{aligned} &\gamma_{1} = \cos \xi_{x}h_{x},\qquad \gamma_{2} = \sin \xi_{x}h_{x},\qquad \gamma_{3} = \sin^{2} \frac{\xi_{y}h_{y}}{2},\qquad \gamma_{4} = \cos(\xi_{x}h_{x} + \xi_{y}h_{y}), \\ &\gamma_{5} = \sin ( \xi_{x}h_{x} + \xi_{y}h_{y}),\qquad \gamma_{6} = \cos(\xi_{x}h_{x} - \xi_{y}h_{y}),\qquad \gamma_{7} = \sin ( \xi_{x}h_{x} - \xi_{y}h_{y}). \end{aligned} \end{aligned}$$
(29)

For stability, it has to satisfy the following condition [28]:

$$\begin{aligned} \bigl\vert G(\xi_{x},\xi_{y},\tau) \bigr\vert \leq1. \end{aligned}$$
(30)

Referring to the method of Ref. [29], let

$$\begin{aligned} \bigl\vert G(\xi_{x},\xi_{y},\tau) \bigr\vert ^{2} = \frac{p}{q}. \end{aligned}$$
(31)

We just need to compare the relationship between p and q. It is sufficient that \(p - q \leq0\), that is to say, then Eq. (30) is proved.

Imposing that condition directly on Eq. (28), it yields

$$\begin{aligned} p - q ={}& (q_{1} + 2q_{4} + p_{1} + 2p_{4}) (q_{1} + 2q_{4} - p_{1} - 2p_{4}) \\ &{}+ ( q_{2} + q_{3} + p_{2} + p_{3}) ( q_{2} + q_{3} - p_{2} - p_{3}) \gamma_{1}^{2} + 16 (q_{4} + p_{4}) (q_{4} - p_{4}) \gamma_{3}^{2} \\ &{}+ 2 \bigl\{ \bigl[(q_{1} + 2q_{4}) (q_{2} + q_{3}) - (p_{1} + 2p_{4}) (p_{2} + p_{3}) \bigr]\gamma_{1} \\ &{}+ 4 \bigl[ (p_{1} + 2p_{4})p_{4}- (q_{1} + 2q_{4})q_{4} \bigr] \gamma_{3} \\ &{}+ (q_{1} + 2q_{4}+ p_{1} + 2p_{4} ) ( q_{6} + q_{7}) (\gamma_{4} + \gamma_{6} ) + 4 \bigl[(p_{2} + p_{3}) p_{4}- (q_{2} + q_{3}) q_{4} \bigr] \gamma_{1} \gamma_{3} \\ &{}+ (q_{2} + q_{3} + p_{2} + p_{3} ) ( q_{6} + q_{7})\gamma_{1} (\gamma_{4} + \gamma_{6} ) - 4 ( q_{4} + p_{4}) (q_{6} + q_{7}) \gamma_{3}(\gamma _{4} + \gamma_{6} ) \\ &{}+ (q_{2} - q_{3} + p_{2} - p_{3} ) ( q_{6} - q_{7})\gamma_{2} (\gamma_{5} + \gamma_{7} ) \bigr\} . \end{aligned}$$
(32)

Notice the definitions of \(p_{k}, q_{k}\ (1 \leq k \leq9)\) in (23) and the definitions of \(\gamma_{l}\ (1 \leq l \leq5)\) in (29), with a detailed calculation we obtain, when \(v >0\), \(p - q \leq0\) for any \(h_{x}\), \(h_{y}\) and τ. Besides, we also checked it with MATLAB when \(v >0\) for any \(h_{x}\), \(h_{y}\) and τ. In other words, it shows \(p \leq q \).

As a result, we have

$$\begin{aligned} \bigl\vert G(\xi_{x},\xi_{y},\tau) \bigr\vert ^{2} = \frac{p}{q} \leq1. \end{aligned}$$
(33)

Thus, the following result can be derived:

$$\begin{aligned} \bigl\vert G(\xi_{x},\xi_{y},\tau) \bigr\vert \leq1,\quad 0 < \tau< \tau_{0}, 0 < K \tau< T. \end{aligned}$$
(34)

Hence, we derive the following result.

Theorem 4.1

When \(v >0\), the fourth-order compact finite difference scheme (19) is unconditionally stable.

5 Numerical experiments

In this part, to validate the applicability of the method we provided, two experiments have been considered. To test our fourth-order compact difference scheme (19) according to Sect. 2, those examples with their known exact solutions are chosen in order to show the performance of the high-order compact schemes using computer programs that implement the scheme (19).

There are no differences between square and rectangular domains for the numerical scheme we proposed. In the following numerical experiments, the domain is deliberately set to a square domain for simplicity, all tests are conducted on the domain \(\Omega = [0,1] \times[0,1]\) with a uniform mesh size \(h_{x}\) and \(h_{y}\) in x and y directions, respectively. The computations were performed in a MATLAB environment using version R2014a on a Lenovo notebook computer, and they were executed on Inter(R) Core(TM) i7-6500U CPU @ 2.50 GHz, RAM 8.00 GB (7.44 GB available).

The numerical results will be presented to illustrate the efficiency and accuracy of our method, and the experimental convergence orders are shown in Table 1, Table 3 and Table 5. At the same time, we also compare our results with the results from the previous second-order difference method, as shown in Table 2, Table 4 and Table 6 to illustrate the advance of the scheme (19).

Table 1 The comparison of the \(l^{2}\)-norm and the \(l^{\infty}\)-norm when \(\tau^{2} = h_{x} =h_{y} \) for \(\mathcal{O}(h_{x}^{4} + h_{y}^{4})\) fourth-order compact finite difference schemes in Example 1, at different values of the step size (for \(N = 4, 8, 16,32,64,128\)) in the x and y directions
Table 2 The comparison of the \(l^{2}\)-norm and the \(l^{\infty}\)-norm when \(\tau= h_{x} =h_{y} \) for \(\mathcal{O}(h_{x}^{2} + h_{y}^{2})\) standard central difference scheme, at different values of the step size (for \(N = 4,8,16,32,64,128\)) in the x and y directions

Here the numerical solution and the exact solution are compared with the use of the \(l^{2}\)-norm of the error and the \(l^{\infty}\)-norm of the error. The definitions of these two errors are as follows [30].

The \(l^{2}\)-norm of the error is defined by

$$\begin{aligned} \mathrm{Error}_{l^{2}} = \bigl\Vert c^{\mathrm{num}} - C^{\mathrm{exact}} \bigr\Vert _{l^{2}} = \sqrt{ \sum _{i ={ 1}}^{N} \sum_{j ={ 1}}^{M} \bigl\vert c^{K}_{ij} - C^{K}_{ij} \bigr\vert ^{2} h_{x}h_{y}}. \end{aligned}$$
(35)

The \(l^{\infty}\)-norm of the error is approximated by the formula for the \(l^{2}\)-norm of the error, which is defined by

$$\begin{aligned} \mathrm{Error}_{l^{\infty}} = \bigl\Vert c^{\mathrm{num}} - C^{\mathrm{exact}} \bigr\Vert _{l^{\infty}} = \max_{1 \leq i \leq N, 1 \leq j \leq M} \bigl\vert c^{K}_{ij} - C^{K}_{ij} \bigr\vert , \end{aligned}$$
(36)

where N and M are the numbers of sub-intervals, \(U_{ij}\) is the result from the numerical solution, and \(u_{ij}\) is from the analytic solution, K represents the last time level.

In the following tables, we take \(N=M \), the experimental order of convergence Rate is computed by the formula

$$\begin{aligned} \mathrm{Rate}_{l^{2}} =\frac{\mathrm{log}(\mathrm{Error}_{N_{1}} / \mathrm{Error}_{N_{2}})}{\mathrm{log}(N_{2}/N_{1})}, \end{aligned}$$
(37)

where \(\mathrm{Error}_{N_{1}} \) and \(\mathrm{Error}_{N_{2}} \) are the \(l^{2}\)-norms of fields with resolutions associated with grid sizes \(N_{1}\) and \(N_{2}\). We have

$$\begin{aligned} \mathrm{Rate}_{l^{\infty}} =\frac{\mathrm{log}(\mathrm{Error}_{1} / \mathrm{Error}_{2})}{\mathrm{log}(h_{1}/h_{2})}, \end{aligned}$$
(38)

where \(\mathrm{Error}_{1}\) and \(\mathrm{Error}_{2}\) are computed with mesh size \(h = h_{x} = h_{y}\) with \(\mathrm{Error}_{l^{\infty}}\), accordingly. For example, the orders of convergence are obtained by data from the first line divided by the second line, and the second divided by the third, i.e. we get the results for \(\mathrm{Rate}(h= \frac{1}{4})\) and \(\mathrm{Rate}(h= \frac{1}{8})\), respectively.

Example 1

In this part, we study the following two-dimensional convection–diffusion equation, and give main results for the numerical approximation:

$$ \textstyle\begin{cases} \frac{\partial C}{\partial t} =D_{x} \frac{\partial^{2} C}{\partial x^{2}} + D_{y} \frac{\partial^{2} C}{\partial y^{2}} -v\frac{\partial C}{\partial x} + f, & (x,y)\in \Omega , t>0, \\ C(x,y,t)=g(x,y,t),& (x,y)\in \Gamma , t>0, \\ C(x,y,0)=C_{0}(x,y),& (x,y)\in \Omega . \end{cases} $$
(39)

Let the right item

$$ f(x,y,t) = e^{-t} \bigl[ \bigl(2 \pi^{2}-1 \bigr) \sin\pi x \sin\pi y + v \pi\cos\pi x \sin\pi y \bigr], $$
(40)

and the exact solution of Eqs. (39),

$$ C(x,y,t) = e^{-t}\sin\pi x \sin\pi y, $$
(41)

and we take the temporal range \(t \in[0,T]\), \(D_{x} = D_{y} = v =1 \) in the experiment. Here \(C(x,y,t)= 0\), for all \((x,y)\in \Gamma \), but \(f(x,y,t)\neq0\), for any \((x,y)\in \Gamma \).

The spatial step size chosen in the numerical experiment are different \(h = \frac{1}{4}\), \(h = \frac{1}{8}\), \(h = \frac{1}{16}\), \(h = \frac {1}{32}\), \(h = \frac{1}{64}\), and \(h = \frac{1}{128}\), respectively. Applying the numerical scheme in Sect. 2 to Eqs. (39), the error and convergence order of difference approximation schemes are shown in Table 1 (where \(h= h_{x}=h_{y}\)).

Table 1 demonstrates the \(l^{2}\)-norm and the \(l^{\infty }\)-norm between numerical solution and exact solution in the case of the temporal increment is the same as the spatial increment, i.e. \(\tau^{2} = h \). Besides, we notice that when h is ever more smaller, the accuracy of the scheme (19) grows close to fourth order. Nevertheless, it only reaches two orders with standard difference scheme; see Table 2 (where \(h= h_{x}=h_{y}\)).

From the above two tables, it is obvious that with N increasing, the accuracies of \(l^{2}\)-norm and the \(l^{\infty}\)-norm are decreasing, that is to say, we can adopt a small spatial step size to solve this class of equation if we need the error filled with high accuracy. But for our high accuracy scheme, when \(h = \frac{1}{128}\), the space grid involves \(128 \times128\) points; at the same time, the number of time layers is \(128 \times128\) layers, too. Due to the limitations of computer storage performance, we cannot run the results needed, we have the MATLAB display: Out of memory. For a standard general scheme, when \(h = \frac{1}{128}\), the space grid and time layers are the same, only \(128 \times128\), and it can be computed by a computer.

To further collaborate the applicability of the proposed method, we have clearer pictures of the convergence of the compact difference (19), which are plotted in Fig. 2, the errors in the semi-log scale, which indicates an exponential convergence rate \(\mathcal{O}( \tau^{2} + h^{4}_{x} + h^{4}_{y})\) under the standard of the \(l^{2}\)-norm and the \(l^{\infty}\)-norm, respectively.

Figure 2
figure 2

\(L^{2}\)-norm errors of the standard difference scheme and the compact difference scheme in Example 1. (a) Approximation order of C in \(L^{2}\)-norm. (b) \(L^{2}\)-norm varying with spatial step

It should be realized that the scheme (19) provides reasonable approximations of the solution in terms of the standard difference scheme. In general, Figs. 2 also show the fact that the present method is computationally stable, effective, simple to use, convergent and giving an accuracy of the solution better than some previously existing methods.

Figures 3, 4 and 5, obtained by MATLAB software, show comparison results and the changes of numerical solution and exact solution with our compact difference scheme (19) under the condition of different step sizes, both spatially and temporally.

Figure 3
figure 3

The effect of numerical solution and exact solution at fixed \(T = 1, h = \frac{1}{4}\) and \(\tau= \frac{1}{16}\) in Example 1. (a\(N=2^{2}\). (b\(N=2^{2}\)

Figure 4
figure 4

The effect of numerical solution and exact solution at fixed \(T = 1, h = \frac{1}{8}\) and \(\tau= \frac{1}{64}\) in Example 1. (a\(N=2^{4}\). (b\(N=2^{4}\)

Figure 5
figure 5

The effect of numerical solution and exact solution at fixed \(T = 1, h = \frac{1}{32}\) and \(\tau= \frac{1}{1024}\) in Example 1. (a) \(N=2^{5}\). (b) \(N=2^{5}\)

Example 2

The equation with homogeneous Dirichlet boundary condition to be solved is

$$ \textstyle\begin{cases} \frac{\partial C}{\partial t} - D_{x} \frac{\partial^{2} C}{\partial x^{2}} - D_{y} \frac{\partial ^{2} C}{\partial y^{2}} + v\frac{\partial C}{\partial x} \\ \quad=e^{-t} [ -x(1-x)y(1-y) +2 x(1-x)y(1-y) \\ \qquad{} + v (1-2x)y(1-y)],\quad (x,y)\in \Omega , t>0, \\ C(x,y,t)=g(x,y,t),\quad (x,y)\in \Gamma , t>0, \\ C(x,y,0)=C_{0}(x,y),\quad (x,y)\in \Omega . \end{cases} $$
(42)

The exact solution of Eqs. (42) is

$$C(x,y,t) = e^{-t}x(1-x)y(1-y)). $$

We still take the temporal range \(t \in[0,T]\), and we choose the following coefficients of equations \(D_{x} = D_{y} = 1, v = 0.1\) in the numerical experiment.

The spatial step sizes chosen are the same as the former experiment, using the scheme (19) to Eqs. (42), we get the error and convergence order of the difference approximation schemes; see Table 3 (where \(h= h_{x}=h_{y}\)).

Table 3 The comparison of the \(l^{2}\)-norm and the \(l^{\infty}\)-norm when \(\tau^{2} = h_{x} =h_{y} \) for \(\mathcal{O}(h_{x}^{4} + h_{y}^{4})\) fourth-order compact finite difference schemes in Example 2, at different values of the step size (for \(N = 4,8,16,32,64,128\)) in the x and y directions

Next, we give the numerical results of the standard different scheme obtained by computer experiment; see Table 4 (where \(h= h_{x}=h_{y}\)).

Table 4 The comparison of the \(l^{2}\)-norm and the \(l^{\infty}\)-norm when \(\tau= h_{x} =h_{y} \) for \(\mathcal{O}(h_{x}^{2} + h_{y}^{2})\) standard central difference scheme, at different values of the step size (for \(N = 4,8,16,32,64,128\)) in the x and y directions

In Tables 3 and 4, we compare the second-order standard finite difference scheme and the fourth-order compact finite difference scheme (19) in the sense of the \(l^{2}\)-norm and the \(l^{\infty }\)-norm at \(T = 1\). We make \(\tau^{2} = h \) in the scheme (19) and \(\tau= h \) in another; applying MATLAB software, we get the numerical solution compared with the exact solution as shown in Fig. 6 and Fig. 7.

Figure 6
figure 6

The effect of numerical solution and exact solution at fixed \(T = 1, h = \frac{1}{32}\) and \(\tau= \frac{1}{1024}\) in Example 2. (a) \(N=2^{4}\). (b) \(N=2^{4}\)

Figure 7
figure 7

The effect of numerical solution and exact solution at fixed \(T = 1, h = \frac{1}{64}\) and \(\tau= \frac{1}{4096}\) in Example 2. (a) \(N=2^{6}\). (b) \(N=2^{6}\)

Using MATLAB, we can derive Fig. 8. The left one is the picture of the absolute error by employing a fourth-order finite difference scheme. The other one is for the error curves of the \(l^{\infty}\)-norm varying with spatial step. It proves that the degree of the numerical solutions is approximating the exact solutions in different grid points.

Figure 8
figure 8

Comparison figures of errors between the standard difference scheme and the compact difference scheme in Example 2. (a) Absolute error when \(T = 1, N = 32\) and \(K= N^{2}\). (b) \(l^{\infty}\)-norm varying with spatial step

Example 3

Consider the convection–diffusion equation with non-homogeneous Dirichlet boundary condition

$$ \textstyle\begin{cases} \frac{\partial C}{\partial t} - D_{x} \frac{\partial^{2} C}{\partial x^{2}} - D_{y} \frac{\partial ^{2} C}{\partial y^{2}} + v\frac{\partial C}{\partial x} \\ \quad = (2\pi^{2} -1) e^{-t}\sin\pi x \cos\pi y + \pi e^{-t} \cos\pi x \cos \pi y, \\ \qquad (x,y)\in \Omega , t>0, \\ C(x,y,t)=g(x,y,t),\quad (x,y)\in \Gamma , t>0, \\ C(x,y,0)=C_{0}(x,y),\quad (x,y)\in \Omega . \end{cases} $$
(43)

The exact solution of this problem (43) given by

$$C(x) = e^{-t}\sin\pi x \cos\pi y. $$

Taking the temporal range \(t \in[0,T]\) still, the coefficients are chosen as \(D_{x} = D_{y} = 1, v = 1\). We use this problem to check the accuracy for two different schemes: the scheme (19): the fourth-order compact finite difference scheme and the standard scheme: the second-order centered difference scheme.

Choosing the same time step sizes as the former ones, we show in Table 4 the errors in \(l^{2}\)-norm and the \(l^{\infty}\)-norm for scheme (19) to Eqs. (43) with different grid points, meanwhile, we also give the error and convergence order of standard second-order difference schemes; see Table 6.

From Table 5 and Table 6, when \(T = 1\), in the sense of either the \(l^{2}\)-norm or the \(l^{\infty}\)-norm, we can see that second-order standard finite difference scheme is worse than the proposed fourth-order compact finite difference scheme (19). Especially, when \(N = 2^{2}\), the convergence order of standard second-order difference schemes is obviously not in conformity with the theoretical results. In addition, with the increase of N, although the \(l^{2}\)-norm gradually converges to second order, for the \(l^{\infty}\)-norm, the numerical results are not very satisfactory, it produces a slight fluctuation with the increase of N. Compared with this, our method is more accurate and shows good convergence; it yields the smallest errors among the two methods.

Table 5 The comparison of the \(l^{2}\)-norm and the \(l^{\infty}\)-norm when \(\tau^{2} = h_{x} =h_{y} \) for \(\mathcal{O}(h_{x}^{4} + h_{y}^{4})\) fourth-order compact finite difference schemes in Example 3, at different values of the step size (for \(N = 4,8,16,32,64,128\)) in the x and y directions
Table 6 The comparison of the \(l^{2}\)-norm and the \(l^{\infty}\)-norm when \(\tau= h_{x} =h_{y} \) for \(\mathcal{O}(h_{x}^{2} + h_{y}^{2})\) standard central difference scheme, at different values of the step size (for \(N = 4,8,16,32,64,128\)) in the x and y directions

Applying MATLAB software, we get the numerical solution compared with exact solution as shown in Figs. 9, 10 and 11, these three pictures show the corresponding computational simulation results with varying number of mesh grid N.

Figure 9
figure 9

The effect of numerical solution and exact solution at fixed \(T = 1, h = \frac{1}{4}\) and \(\tau= \frac{1}{16}\) in Example 3. (a\(N=2^{2}\). (b) \(N=2^{2}\)

Figure 10
figure 10

The effect of numerical solution and exact solution at fixed \(T = 1, h = \frac{1}{8}\) and \(\tau= \frac{1}{64}\) in Example 3. (a) \(N=2^{3}\). (b) \(N=2^{3}\)

Figure 11
figure 11

The effect of numerical solution and exact solution at fixed \(T = 1, h = \frac{1}{64}\) and \(\tau= \frac{1}{4096}\) in Example 3. (a) \(N=2^{6}\). (b) \(N=2^{6}\)

Figure 12 shows the absolute error of the scheme (19) for the fixed number of N, and it describes the order between the two difference methods.

Figure 12
figure 12

Comparison figures of errors between the standard difference scheme and the compact difference scheme in Example 3. (a) Absolute error when \(T = 1, N = 32\) and \(K= N^{2}\). (b) Approximation order of C in \(L^{2}\)-norm

In summary, the numerical experiments performed show the efficiency of the fourth-order compact difference scheme (19), which is reliable for solving a two-dimensional convection–diffusion equation, and it is apparent from Figs. 3, 4, 5, 6, 7, 9, 10 and 11 that the exact solution and numerical solution are better fitted with step size generation encrypting; it turns out that the compact difference scheme (19) we used can be a good approximation to the exact solution.

6 Conclusions

Compact finite difference schemes up to order four for solving the convection–diffusion equation in two dimensions were developed in this paper. To further collaborate the applicability of the proposed method, tables of the \(l^{2}\)-norm and the \(l^{\infty}\)-norm for \(\mathcal {O}(\tau^{2} + h^{4}_{x} + h^{4}_{y})\) compact finite difference schemes and corresponding graphs have been plotted for Examples 1, 2 and 3, for the exact solution versus the numerical solutions at different values of mesh size h. It is found that not only the error norm \(l^{2}\) decreases with the increase of the number of nodes but also the \(l^{\infty}\)-norm shows the same trend; it decreases as the mesh size h decreases, which in turn shows the convergence of the computed solution. To sum up, the present method is computationally stable, effective, simple to use, convergent and giving a better accuracy of the solution than some previously existing methods.

References

  1. Zhu, Q., Wang, Q., Fu, J., Zhang, Z.: New second-order finite difference scheme for the problem of contaminant in groundwater flow. J. Appl. Math. 2012(2012), 129–154 (2012)

    MathSciNet  MATH  Google Scholar 

  2. Lin, L., Yang, J.Z., Zhang, B., Zhang, B., Zhu, Y.: A simplified numerical model of 3-D groundwater and solute transport at large scale area. J. Hydrodyn. 22(3), 319–328 (2010)

    Article  Google Scholar 

  3. Li, L.Y., Yin, Z.: Numerical simulation of groundwater pollution problems based on convection–diffusion equation. Am. J. Comput. Math. 7(3), 350–370 (2017)

    Article  Google Scholar 

  4. Saqib, M., Hasnain, S., Mashat, D.S.: Computational solutions of two dimensional convection–diffusion equation using Crank–Nicolson and time efficient ADI. Am. J. Comput. Math. 7(3), 208–227 (2017)

    Article  Google Scholar 

  5. Mekuria, G.T., Rao, J.A.: Adaptive finite element method for steady convection–diffusion equation. Am. J. Comput. Math. 6(3), 275–285 (2016)

    Article  Google Scholar 

  6. Qiu, W., Shi, K.: An HDG method for convection–diffusion equation. J. Sci. Comput. 66(1), 346–357 (2016)

    Article  MathSciNet  MATH  Google Scholar 

  7. Shu, C.W.: Bound-preserving high order finite volume schemes for conservation laws and convection–diffusion equations. In: Finite Volumes for Complex Applications VIII—Methods and Theoretical Aspects, Springer Proceedings, pp. 3–14 (2017)

    Chapter  Google Scholar 

  8. Ammi, M.R.S., Jamiai, I.: Finite difference and Legendre spectral method for a time-fractional diffusion-convection equation for image restoration. Discrete Contin. Dyn. Syst. 11(1), 103–117 (2017)

    Article  MathSciNet  MATH  Google Scholar 

  9. Koley, U., Risebro, N.H., Schwab, C., et al.: A multilevel Monte Carlo finite difference method for random scalar degenerate convection–diffusion equations. J. Hyperbolic Differ. Equ. 14(3), 415–454 (2017)

    Article  MathSciNet  MATH  Google Scholar 

  10. Noye, B.J., Tan, H.H.: Finite difference methods for solving the two-dimensional advection–diffusion equation. Int. J. Numer. Methods Fluids 9(1), 75–98 (1989)

    Article  MATH  Google Scholar 

  11. Lu, J.F., Guan, Z.: Numerical Methods for Partial Differential Equations. Qinghua University Press, Beijing (2003)

    Google Scholar 

  12. Sun, Z.Z.: Numerical Methods for Partial Differential Equations. Science Press, Beijing (2005)

    Google Scholar 

  13. Zhang, J.: An explicit fourth-order compact finite difference scheme for three-dimensional convection–diffusion equation. Int. J. Numer. Methods Biomed. Eng. 14(3), 209–218 (2010)

    MathSciNet  MATH  Google Scholar 

  14. Sari, M., Gürarslan, G., Zeytinoǧlu, A.: High-order finite difference schemes for solving the advection–diffusion equation. Math. Comput. Appl. 15(15), 449–460 (2010)

    MathSciNet  MATH  Google Scholar 

  15. Qiao, H.L., Jiang, Z.W.: The high accuracy compact finite difference scheme for three dimensional convection–diffusion equation. J. Shandong Univ. Nat. Sci. 1(32), 6–9 (2017)

    Google Scholar 

  16. Gurarslan, G., Karahan, H., Alkaya, D., et al.: Numerical solution of advection–diffusion equation using a sixth-order compact finite difference method. Math. Probl. Eng. 2013(3), 532–546 (2013)

    MathSciNet  MATH  Google Scholar 

  17. Singer, I., Turkel, E.: High-order finite difference methods for the Helmholtz equation. Comput. Methods Appl. Mech. Eng. 163(1–4), 343–358 (1998)

    Article  MathSciNet  MATH  Google Scholar 

  18. Bullo, T.A.: Fourth order compact finite difference method for solving one dimensional wave equation. J. Comput. Appl. Math. 8(4), 30–39 (2016)

    Google Scholar 

  19. Cui, M.R.: Compact finite difference method for the fractional diffusion equation. J. Comput. Appl. Phys. 228(20), 7792–7804 (2009)

    Article  MathSciNet  MATH  Google Scholar 

  20. Tian, Z.F., Ge, Y.B.: A fourth-order compact ADI method for solving two-dimensional unsteady convection–diffusion problems. J. Comput. Appl. Math. 198(1) 268–286 (2007)

    Article  MathSciNet  MATH  Google Scholar 

  21. Li, Y.B., Kim, J.: An efficient and stable compact fourth-order finite difference scheme for the phase field crystal equation. Comput. Methods Appl. Mech. Eng. 319, 194–216 (2017)

    Article  MathSciNet  Google Scholar 

  22. Kaysar, R., Arzigul, Y., Zulpiya, R.: High-order compact finite difference scheme for solving one dimensional convection–diffusion equation. J. Jiamusi Univ. (Nat. Sci. Ed.) 1(32), 135–138 (2014)

    Google Scholar 

  23. Sun, N.Z.: Groundwater Pollution: Mathematical Models and Numerical Methods. Geological Press, China (1989)

    Google Scholar 

  24. Yang, X.J., Wang, Y.: High accuracy explicit compact difference scheme for the diffusion equation. J. Hebei Univ. (Nat. Sci. Ed.) 2(36), 117–123 (2016)

    Google Scholar 

  25. Tian, Z.F., Dai, S.Q.: High-order exponential finite difference methods for convection–diffusion type problems. J. Comput. Phys. 220(2), 952–974 (2007)

    Article  MathSciNet  MATH  Google Scholar 

  26. Tian, Z.F., Cui, J.: A new method of constructing fourth-order compact scheme for the steady convection–diffusion equation. In: Zhuang, F.G. (ed.) Proceeding 7th International Symposium on Computational Fluid Dynamics, vol. 2, pp. 116–121. International Academic Publishers, Beijing (1997)

    Google Scholar 

  27. Ames, W.F.: Numerical Methods for Partial Differential Equations. Academic Press, New York (1977)

    MATH  Google Scholar 

  28. Li, R.H., Liu, B.: Numerical Methods for Partial Differential Equations. Higher Education Press, Beijing (2008)

    Google Scholar 

  29. Liu, M.H.: High-order compact difference method for the 2-D Poisson equation. J. Fujian U. Tech. 4(3), 373–376 (2006)

    MathSciNet  Google Scholar 

  30. Zapata, M.U., Balam, R.I.: High-order implicit finite difference schemes for the two-dimensional Poisson equation. Appl. Math. Comput. 309, 222–244 (2017)

    MathSciNet  Google Scholar 

Download references

Acknowledgements

The authors are very grateful to Xu Qiang of Shandong Normal University, Qiao Haili of Shandong University and Wang Xuanxin of Jinan University for their help and suggestions in the process of numerical calculation. We are also very grateful to the reviewers for their valuable comments.

Availability of data and materials

Not applicable.

Funding

This work is supported by National Natural Science Foundation of China (Nos. 11501335, 11371229), the Natural Science Foundation of Shandong Province of China (No. ZR2017MA020), and the Project of Shandong Province Higher Educational Science and Technology Program (No. J14LI03).

Author information

Authors and Affiliations

Authors

Contributions

LL carried out the main part of this article. All authors read and approved the final manuscript.

Corresponding author

Correspondence to Ziwen Jiang.

Ethics declarations

Competing interests

The authors declare that they have no competing interests.

Additional information

Publisher’s Note

Springer Nature remains neutral with regard to jurisdictional claims in published maps and institutional affiliations.

Rights and permissions

Open Access This article is distributed under the terms of the Creative Commons Attribution 4.0 International License (http://creativecommons.org/licenses/by/4.0/), which permits unrestricted use, distribution, and reproduction in any medium, provided you give appropriate credit to the original author(s) and the source, provide a link to the Creative Commons license, and indicate if changes were made.

Reprints and permissions

About this article

Check for updates. Verify currency and authenticity via CrossMark

Cite this article

Li, L., Jiang, Z. & Yin, Z. Fourth-order compact finite difference method for solving two-dimensional convection–diffusion equation. Adv Differ Equ 2018, 234 (2018). https://doi.org/10.1186/s13662-018-1652-5

Download citation

  • Received:

  • Accepted:

  • Published:

  • DOI: https://doi.org/10.1186/s13662-018-1652-5

MSC

Keywords