1 Introduction

The convection diffusion equation is given by

$$\begin{aligned}&-\epsilon \Delta u +\mathbf{b}. \nabla u+cu=f ~~~\text {in}~~ \Omega ,\nonumber \\&u=g_D ~~\text {on}~~\Gamma _D,\nonumber \\&\epsilon \frac{\partial u}{\partial n}=g_N~~\text {on}~~\Gamma _N, \end{aligned}$$
(1.1)

where \(\epsilon \) is a small positive parameter and \(\Omega \) is an open bounded domain enclosed with \(\partial \Omega =\Gamma _D\cup \Gamma _N.\) Moreover, n is the outward unit normal to the boundary. This type of equations plays an important role in many physical phenomena. For example, scalar convection diffusion equations describe the transport of a scalar quantity, e.g. temperature or concentration. In these equations the operators \(-\epsilon \Delta \) and \(\mathbf{b }.\nabla \) determine what the solution of (1.1) looks like. The first one relates u proportionally to \(\epsilon \) and the second one transports u in the direction of vector \(\mathbf{b }\) (Larson and Bengzon 2013). Hence, these operators model the physical processes of diffusion and convection, respectively. Generally, solutions of the convection diffusion equations have layers, due to this trait there are some small parts of the domain where derivative of the solution is very large (John 2000). In Tang and Trummer (1996) boundary layer resolving pseudospectral methods are presented to overcome this problem. Adaptive techniques are very suitable to this kind of problems. In adaptive techniques a posteriori error estimation is needed to find information about locations for local mesh refinement as well as for estimating the global error. There are several works in implementation and analysis of a posteriori error estimation for solving many classes of partial differential equations in finite element methods (Ainsworth and Oden 1993; Bank and Weiser 1985; Eriksson et al. 1995). A good review of some a posteriori error estimation for convection diffusion equations can be found in John (2000).

The main challenge in convection diffusion problems depends to how large is “Péclet number” which provides a measure of how much the convective term prevails over the diusive one. A problem featuring \(Pe\gg 1\) will be named convection dominated diffusion problem (Quarteroni et al. 2014). In this case behaviour of the numerical solutions is oscillatory. To avoid these solutions, discretization parameters should be chosen sufficiently small which makes the numerical method inconvenient. An approximate solution of the problem does not exhibit oscillations if \(Pe < 1\). A stabilization technique is based on adding an artificial diffusion to make Péclet number as small as possible. Therefore, for smaller values of \(\epsilon \), this stabilization technique is more efficient. This more diffusion should be as little as possible not to sacrifice accuracy, but as much as need to obtain stability (Larson and Bengzon 2013).

The current work presents an adaptive element free Galerkin method for solving convection diffusion equations. The EFG method was introduced by Belytschko et al. (1994), Dolbow and Belytschko (1998). This method is based on the moving least squares (MLS) Yaw (2009) approximation and a background mesh for the integration purpose. The MLS shape functions do not have Kronecker delta property, therefore, the essential boundary condition should be enforced. In Dehghan and Abbaszadeh (2018a, b) the authors have combined the EFG method with the moving Kriging interpolation and radial point interpolation which have Kronecker delta property for solving transport problems, incompressible Navier–Stokes equation and some PDEs with discontinuous solutions. The element free Galerkin method is used for solving real world problems in Jannesari and Tatari (2016, 2017) and Dehghan and Narimani (2018). More about meshfree methods are presented in Liu (2003).

Rest of the paper is organized as follows: Sect. 2 is devoted to explain EFG method and MLS approximation. Section 3 explains the proposed adaptive technique and in Sect. 4, numerical results for some problems are presented to confirm validity of the approach. The last section is conclusion.

2 The EFG method

The element free Galerkin method is based on the weak formulation of the considered problem and MLS approximation. In MLS approximation nodal points are used and does not need any mesh generation. This approximation is not necessarily interpolant, hence enforcement of Dirichlet boundary conditions is not straightforward. There are several ways to impose these boundary conditions such as Lagrange multipliers and penalty method. In this work, the penalty method is used to impose Dirichlet boundary conditions.

2.1 MLS approximation

The MLS approximation which was introduced by Lancaster and Salkauskas (1981) is well-known technique with acceptable accuracy. This approximation is local and at any arbitrary evaluation point \(\mathbf{x}\), only the neighboring nodes in influence domain of point \(\mathbf{x}\) are consequential. The influence of a node \(\mathbf{x}_i\) is governed with a weight function \(w(\mathbf{x}-\mathbf{x}_i)\), which vanishes outside of the influence domain of node \(\mathbf{x}_i\). Let the true solution u be known at some selected points \(\mathbf{x}_i\). To approximate solution \(u_h(\mathbf{x})\) in the problem domain \({\bar{\Omega }}\), by least squares sense, the goal is to find minimum of the expression \((u_h(\mathbf{x}_i) -u(\mathbf{x}_i))^2\) for each i. Let the approximation \(u_h(\mathbf{x})\), be posed as a polynomial of order m with variant coefficients in the following matrix form

$$\begin{aligned} u_h(\mathbf{x})=\mathbf{p}^{\text {T}}(\mathbf{x})\mathbf{a}(\mathbf{x}),\qquad \forall \mathbf{x}\in {\bar{\Omega }}, \end{aligned}$$
(2.1)

where \(\mathbf{p}^{\text {T}}(\mathbf{x})=[p_1(\mathbf{x})~p_2(\mathbf{x})~\cdots ~p_m(\mathbf{x})]\) consists of complete monomial of order m. In two dimensional cases, linear and quadratic basis are defined as:

$$\begin{aligned} \mathbf{p}^{\text {T}}(\mathbf{x})= & {} [1~ x~y]~~~ \text {linear basis},~~~ m=3,\\ \mathbf{p}^{\text {T}}(\mathbf{x})= & {} [1~x~y~x^2~xy~y^2]~~~\text {quadratic basis},~~~ m=6. \end{aligned}$$

The vector \(a(\mathbf{x})\) is given by

$$\begin{aligned} \mathbf{a}(\mathbf{x})=[a_1(\mathbf{x})~\cdots ~a_m(\mathbf{x})]^{\text {T}}. \end{aligned}$$

The unknown parameters \(a_j(\mathbf{x})\), \(j=1,\ldots ,m,\) vary with space coordinates \(\mathbf{x}.\) Therefore, \(\mathbf{a }(\mathbf{x})\) should be determined at any given point \(\mathbf{x}\). In doing so, the least squares functional is written as following:

$$\begin{aligned} \mathcal{J}(\mathbf{x}) =\frac{1}{2}\sum _{i=1}^{N_{_t}} w(\mathbf{x}-\mathbf{x}_i) \bigg (\mathbf{p}^{\text {T}}(\mathbf{x}_i)\mathbf{a}(\mathbf{x})-u(\mathbf{x}_i)\bigg )^2. \end{aligned}$$
(2.2)

where \(N_{_t}\) is the total number of points. The coefficient \(\frac{1}{2}\) is added for mathematical convenience. Also, each summation term, is weighted by a weight function \(w(\mathbf{x}-\mathbf{x}_i)\) thus the local solution is influenced by the local nodes that are not far away. To minimize \(\mathcal{J}\) with respect to each \(a_i(\mathbf{x})\), for the sake of simplicity, first write functional \(\mathcal{J}\) in the following matrix form

$$\begin{aligned} \mathcal{J}(\mathbf{x})=\frac{1}{2}[\mathbf{P}{} \mathbf{a}(\mathbf{x})-\mathbf{u}]^{\text {T}}\mathbf{W}[\mathbf{P}{} \mathbf{a}(\mathbf{x})-\mathbf{u}], \end{aligned}$$
(2.3)

where

$$\begin{aligned} \mathbf{P}=\left[ \begin{array}{c} \mathbf{p}^{\text {T}}(\mathbf{x}_1)\\ \mathbf{p}^{\text {T}}(\mathbf{x}_2)\\ \vdots \\ \mathbf{p}^{\text {T}}(\mathbf{x}_{N_{_t}})\\ \end{array} \right] _{N_{_t}\times m}, \mathbf{W}=\left[ \begin{array}{c@{\quad }c@{\quad }c} w(\mathbf{x}-\mathbf{x_1})&{}\cdots &{}0\\ \cdots &{} \ddots &{} \cdots \\ \mathbf{0} &{} \cdots &{} w(\mathbf{x}-\mathbf{x}_{N_{_t}})\\ \end{array} \right] _{{N_{_t}}\times { N_{_t}}}, \end{aligned}$$

and

$$\begin{aligned} \mathbf{u}=[{ u_1}, { u_2}, \ldots , { u_{N_{_t}}}]^{\text {T}}. \end{aligned}$$

Setting \(\frac{\partial \mathcal{J}}{\partial \mathbf{a}}=0\) yields the following:

$$\begin{aligned} (\mathbf{P}{} \mathbf{a}(\mathbf{x})-\mathbf{u})^{\text {T}}{} \mathbf{W}{} \mathbf{P}=0. \end{aligned}$$
(2.4)

Transpose the whole Eq. (2.4) gives:

$$\begin{aligned} (\mathbf{W}{} \mathbf{P})^{\text {T}}(\mathbf{P}{} \mathbf{a}(\mathbf{x})-\mathbf{u})=0. \end{aligned}$$
(2.5)

This equation can be rewritten as follows:

$$\begin{aligned} \mathbf{P}^{\text {T}}{} \mathbf{W}{} \mathbf{P}{} \mathbf{a}(\mathbf{x})=\mathbf{P}^{\text {T}}{} \mathbf{W}{} \mathbf{u}. \end{aligned}$$
(2.6)

Define moment matrices \(\mathbf{A}(\mathbf{x})\) and \(\mathbf{B}(\mathbf{x})\) as follows:

$$\begin{aligned} \mathbf{A}(\mathbf{x})= & {} \mathbf{P}^{\text {T}}{} \mathbf{W}{} \mathbf{P}=\sum _{i=1}^{N_{_t}} w(\mathbf{x}-\mathbf{x}_i)\mathbf{p}(\mathbf{x}_i)\mathbf{p}^{\text {T}}(\mathbf{x}_i), \end{aligned}$$
(2.7)
$$\begin{aligned} \mathbf{B}(\mathbf{x})= & {} \mathbf{P}^{\text {T}}{} \mathbf{W}=[w(\mathbf{x}-\mathbf{x}_1)\mathbf{p}(\mathbf{x}_1),w(\mathbf{x}-\mathbf{x}_2)\mathbf{p}(\mathbf{x}_2),\ldots ,w(\mathbf{x}-\mathbf{x}_{N_{_t}})\mathbf{p}(\mathbf{x}_{N_{_t}})]. \end{aligned}$$
(2.8)

Using these definitions, Eq. (2.6) becomes:

$$\begin{aligned} \mathbf{A}(\mathbf{x})\mathbf{a}(\mathbf{x})=\mathbf{B}(\mathbf{x})\mathbf{u}, \end{aligned}$$
(2.9)

solve for unknown coeffiecints \(\mathbf{a}(\mathbf{x})\) and substituting it into Eq. (2.1):

$$\begin{aligned} u_h(\mathbf{x})=\sum _{i=1}^{N_{_t}}\phi _i(\mathbf{x}){u}_i={{\varvec{\Phi }}}^{\text {T}}(\mathbf{x}){\mathbf{u}},~~~~~\mathbf{x} \in {\bar{\Omega }}, \end{aligned}$$
(2.10)

where

$$\begin{aligned} {{\varvec{\Phi }}}^{\text {T}}(\mathbf{x})=\mathbf{p}^{\text {T}}(\mathbf{x})\mathbf{A}^{-1}(\mathbf{x})\mathbf{B}(\mathbf{x}), \end{aligned}$$
(2.11)

is the vector of shape functions. Moreover, derivatives of shape function can be obtained using the product rule on Eq. (2.11)

$$\begin{aligned} {{\varvec{\Phi }}}^{\text {T}}_{,k}(\mathbf{x})= \mathbf{p}^{\text {T}}_{,k}\mathbf{A}^{-1}{} \mathbf{B}+\mathbf{p}^{\text {T}}{} \mathbf{A}^{-1}_{,k}{} \mathbf{B}+ \mathbf{p}^{\text {T}}\mathbf{A}^{-1}{} \mathbf{B}_{,k}, \end{aligned}$$
(2.12)

with

$$\begin{aligned} \mathbf{A}^{-1}_{,k}=-\mathbf{A}^{-1}{} \mathbf{A}_{,k}{} \mathbf{A}^{-1}, \end{aligned}$$
(2.13)

where

$$\begin{aligned} \mathbf{A}_{,k}(\mathbf{x})=\sum _{i=1}^{N_{_t}} w_{,k}(\mathbf{x}-\mathbf{x}_i)\mathbf{p}(\mathbf{x}_i)\mathbf{p}^{\text {T}}(\mathbf{x}_i). \end{aligned}$$
(2.14)

Further details about MLS shape functions can be found in Yaw (2009). In all numerical examples we have used shifted and scaled MLS shape functions that computationally are more efficient. Details about how to construct these shape functions are presented in Belytschko et al. (1996).

2.2 The governing system

Consider Eq. (1.1) as follows:

find \(u \in H^1(\Omega )\) from

$$\begin{aligned} a(u,v)=l(v), ~~\forall v \in H^1(\Omega ), \end{aligned}$$
(2.15)

where

$$\begin{aligned} a(u,v)=\int _{\Omega } (-\epsilon \Delta u v+ \mathbf{b }. \nabla u v+cu v){\text {d}}\Omega , \end{aligned}$$

and

$$\begin{aligned} l(v)=(f,v)=\int _{\Omega }f v d{\Omega }, \end{aligned}$$

where v is the test function that is chosen as MLS shape function. Applying the integration by parts formula to the above equation and adding the penalty terms to enforce Dirichlet boundary conditions lead to the following system (Dolbow and Belytschko 1999):

$$\begin{aligned} (\mathbf{S}+\mathbf{E}+\mathbf{M}+\mathbf{M}_{\mathbf{p}})\mathbf{u}=\mathbf{F}+\mathbf{F}_{\mathbf{N}}+\mathbf{F}_{\mathbf{p}}, \end{aligned}$$

where

$$\begin{aligned} S_{ij}= & {} \epsilon \int _\Omega \nabla \phi _i .\nabla \phi _j {\text {d}}\Omega , \end{aligned}$$
(2.16)
$$\begin{aligned} E_{ij}= & {} \int _\Omega \mathbf{b}. \nabla \phi _i \phi _j {\text {d}}\Omega , \end{aligned}$$
(2.17)
$$\begin{aligned} M_{ij}= & {} \int _\Omega c \phi _i \phi _j {\text {d}}\Omega , \end{aligned}$$
(2.18)
$$\begin{aligned} M_{p_{ij}}= & {} \int _{\Gamma _D} \phi _i \gamma \phi _j {\text {d}}s, \end{aligned}$$
(2.19)

and

$$\begin{aligned} F_i= & {} \int _\Omega f_i \phi _i {\text {d}}\Omega , \end{aligned}$$
(2.20)
$$\begin{aligned} F_{N_i}= & {} \int _{\Gamma _N} \epsilon \frac{\partial u_i}{\partial n}\phi _i {\text {d}}s, \end{aligned}$$
(2.21)
$$\begin{aligned} F{p_i}= & {} \int _{\Gamma _D} g_{D_i}\gamma \phi _i {\text {d}}s. \end{aligned}$$
(2.22)

The parameter \(\gamma \) in Eqs. (2.19) and (2.22) is used to penalize difference between Dirichlet boundary conditions and the obtained solution by EFG approximation. Moreover, it should be noted that the EFG method requires the partitioning of the domain into cells, to evaluate all integrals appeared in Eqs. (2.16)–(2.22).

In the point of geometry, these cells should be as simple as possible and usually are rectangle or triangle. In this work, we use a triangular mesh as a partition of the domain. Based on Reference (Belytschko et al. 1994) a proper ratio of Gaussian points to total number of nodes is 4–7. To get this ratio, 3-point Gaussian rule is used, however, the results are acceptable using one point rule. An excellent detail about integration on triangle can be found in Gockenbach (2006).

2.2.1 Stabilization

Based on what is discussed in  Larson and Bengzon (2013), when \(\epsilon \) in Eq. (1.1) decreases we lose control of gradients of u, i.e. \(\nabla u\) can grow sharply. In other words, small perturbations of f can lead to a large local values of \(\nabla u\). Indeed, it is common for u to has thin regions called layers where it changes rapidly. Due to large local values of \(\nabla u\) there are great difficulties in handling layers and thus need modification of the numerical method. There are several techniques to do this such as adding an artificial diffusion, least squares stabilization (John 2000) and edge stabilization that is based on least square stabilization of the gradient jumps across the element boundaries (Burman and Hansbo 2004). In this paper \(\frac{h}{2}{} \mathbf{b}\) is added to the diffusion term as an artificial diffusion, where h is mesh size. Therefore, Eqs. (2.16) and (2.21) are replaced by the following equations

$$\begin{aligned} S_{ij}= \int _\Omega \left[ \epsilon +\frac{h}{2}b_1\phi _{i_x}, \epsilon +\frac{h}{2}b_2\phi _{i_y}\right] .\nabla \phi _j {\text {d}}\Omega , \end{aligned}$$

and

$$\begin{aligned} F_{N_i}=\int _{\Gamma _N} \left[ \epsilon +\frac{h}{2}b_1 u_{i_x}, \epsilon +\frac{h}{2}b_2 u_{i_y}\right] . n \phi _i {\text {d}}s. \end{aligned}$$

Although, this work is presented with the aim of implementation of an adaptive EFG technique for convection diffusion problems, stabilization strategy can help us to get better results with less computational effort.

3 The adaptive algorithm

Let \(\mathcal{T}=\{T\}\) be a partition of domain \(\Omega \) and the mesh size \(h_T\) is defined by \(h_T={\text {diam}}(T)\). The following adaptive algorithm generates a sequence of meshes, \(\mathcal{T}_0, \mathcal{T}_1 ,\mathcal{T}_2,\ldots \).

  • Start with a coarse mesh \(\mathcal{T}_0.\)

  • Solve the problem to get the discrete solution \(u_h\) on the current mesh.

  • Compute the error on each element using a suitable a posteriori error estimation.

  • Mark a fixed \((\theta )\) percentage of those element with largest error contribution.

  • Refine the marked element with a local mesh refinement technique such as red-green refinement and longest edge bisection, to generate new triangulation \(\mathcal{T}_{k+1}.\) Details of these local refinement techniques can be found in most finite element books such as Gockenbach (2006). If in the previous step we chose \(\theta =1\), then the refinement is global.

  • Continue this process until get acceptable tolerance, or when the maximum number of elements in the mesh exceeds from a user predefined number.

3.1 A posteriori error control

Let \(e_h=u-u_h\) be the numerical error relates to the exact solution u and numerical solution \(u_h\). Instead of measuring the error of the solution in some applications, it maybe useful to consider the gradient of error, i.e. \( \nabla e_h=\nabla u- \nabla u_h\). In most problems the exact value of the gradient is not known. Here, the main idea is post processing the gradient and to find an estimate for the true error by comparing the post-processed gradient and non post-processed gradient of the numerical solution \(u_h\) (Gratsch and Bathe 2005). Let \(Gu_h\) denote an improved (post-processed) approximation to the gradient. It can be approximated by

$$\begin{aligned} Gu_h(\mathbf{x })=\sum _{i=1}^{n_i}\phi _i(\mathbf{x}){gu_h}_i, \end{aligned}$$
(3.1)

where \(n_i\) is number of points in the influence domain of \(\mathbf{x }\). The coefficients \({gu_h}_i\) can be determined by solving the following equation:

$$\begin{aligned} (Gu_h, \phi )=(\nabla u_h,\phi ), \end{aligned}$$
(3.2)

or, in the other words, solving the following linear system:

$$\begin{aligned} \int _\Omega (Gu_h-\nabla u_h)\phi _j {\text {d}}\Omega =0,~~~~j=1,2,\ldots n_i. \end{aligned}$$
(3.3)

Substituting (3.1) into Eq. (3.3) leads to:

$$\begin{aligned} \sum _{i=1}^{n_i}\int _\Omega \phi _i \phi _j{gu_h}_i {\text {d}}\Omega =\int _\Omega \phi _j \nabla {u_h}_j {\text {d}}\Omega . \end{aligned}$$
(3.4)

Then using \({gu_h}_i\) to find \(Gu_h\) and applying it instead of the true gradient, yield the following a posteriori error estimation (Gratsch and Bathe 2005)

$$\begin{aligned} \Vert e_h\Vert _E^2 \approx (E_h) ^2=\sum _{T \in \mathcal{T}} \eta ^2_T, \end{aligned}$$
(3.5)

where \(\Vert . \Vert _E\) shows the energy norm and

$$\begin{aligned} \eta ^2_T=\Vert Gu_h-\nabla u_h\Vert ^2_{L^2(T)}. \end{aligned}$$

This kind of error estimation is known as recovery-based error estimation was introduced by Zienkiewicz and Zhu (1992).

4 Numerical investigation

In this section, the EFG method is applied for some examples to demonstrate efficiency and accuracy of the proposed method. In all of the examples linear basis \((m=3)\) and following cubic spline weight function with rectangular support are used

$$\begin{aligned} w(r)=\left\{ \begin{array}{ll} 4r^3-4r^2+\frac{2}{3} &{}\quad r\le \frac{1}{2} ,\\ - \frac{4}{3}r^3+4r^2-4r+\frac{4}{3} &{}\quad \frac{1}{2}<r\le 1,\\ 0 &{}\quad r>1. \end{array} \right. \end{aligned}$$
(4.1)

where \(r=\frac{||x-x_i||_2}{d_i}\), and \(d_i\) is about 1.5h where h is the maximum diameter of the triangles that one of their vertices is \(x_i\). Moreover, all examples are solved in unit square \([0,1]\times [0,1]\) and with \(\gamma =1000\) as the penalty parameter. To show efficiency of the present method, the initial mesh is chosen very coarse. The unit square is only divided into two triangles as the first mesh. Also, we set \(\theta =0.3\), and use the following definition as effectivity index

$$\begin{aligned} {\text {Effectivity index}} :=\frac{(\sum _{T \in \mathcal{T}}\eta _T^2)^{1/2}}{\Vert e_h \Vert _E}. \end{aligned}$$

Besides, in the following tables \(L^2\) error is reported on some level of refinements where adaptive.S and uniform.S are adaptive and uniform methods using stabilization and \(N_t\) is total number of nodes.

4.1 Example 1

As the first numerical experiment consider following example with \(\epsilon =10^{-3}\), \(\mathbf{b }=(2,3)^{\text {T}}\) and \(c=1\) and \(\partial \Omega =\Gamma _D.\) The right hand side f and Dirichlet boundary conditions are chosen such that

$$\begin{aligned} u=xy^2-y^2 \exp \left( \frac{2(x-1)}{\epsilon }\right) -x\exp \left( \frac{3(y-1)}{\epsilon }\right) +\exp \left( \frac{2(x-1)+3(y-1)}{\epsilon }\right) . \end{aligned}$$

In this case, the solution has typical regular boundary layers at \(x=1\) and \(y=1\) (John 2000). In Tables 1 and 2, \(L^2\) error of solutions computed by uniform and adaptive refinements are reported respectively. In each of these tables stabilized and unstabilized cases are investigated. According to these tables stabilization technique is more efficient for adaptive refinement. In Table 3 relative error and CPU time of stabilized adaptive and uniform refinements are compared which shows efficiency of the presented stabilized adaptive method.

The numerical solution and the last mesh of this test are plotted in Fig. 1. Also, Fig. 2 shows the effectivity indices and obtained \(L^2\) error for this example. In this example, the effectivity indices are lower than one. Indeed, the error is underestimated by around a factor between 0.1 and 0.5. We emphasize that an a posteriori error estimator is called efficient, if the effectivity index (EI) and inverse of it \((\frac{1}{EI})\) are bounded for all meshes. Besides, if it does not vary too much with respect to a given mesh. Also, Fig. 3 shows convergence rate for this example.

Table 1 Error of computed solution by uniform refinement, Example 1
Table 2 Error of computed solution on adaptive refined mesh, Example 1
Table 3 Relative error and CPU time of computed solution, Example 1
Fig. 1
figure 1

EFG solution by adaptive technique (left) and corresponding background mesh on level 20 (right), Example 1

Fig. 2
figure 2

The effectivity index as a function of refinement (left) and \(L^2\) error (right), Example 1

Fig. 3
figure 3

Convergence rate by adaptive and uniform refined mesh with stabilization, Example 1

Fig. 4
figure 4

EFG solution by adaptive technique (left) and the last adapted mesh (right), Example 2

Fig. 5
figure 5

The effectivity index as a function of refinement (left) and \(L^2\) error (right), Example 2

4.2 Example 2

This example is taken from Burman and Hansbo (2004). Consider (1.1) with \(\epsilon =10^{-5}\), \(\mathbf{b }=(1,0)^{\text {T}}\) and \(c=1\). The exact solution that has an internal boundary layer, is given by

$$\begin{aligned} u=\frac{1}{2}\left( 1-\tanh \left( \frac{x-0.5}{0.05}\right) \right) . \end{aligned}$$

The corresponding f and Dirichlet boundary conditions are obtained by inserting the exact solution into Eq. (1.1). The numerical solution and the final mesh of this test at level 15 of adaptive refinements are shown in Fig. 4. Moreover, the effectivity indices and the obtained \(L^2\) error at this refinement level have shown in Fig. 5. In this case, the effectivity indices for both stabilized and unstabilized are convergent to 1.5. However, \(L^2\) errors are too different in with and without stabilization. In Fig. 6, convergence rates of the solutions obtained by adaptive and uniform refined mesh with stabilization are compared. As in the previous example, Tables 45 and 6 are devoted to the comparison of adaptive and uniform refinements and effect of stabilization technique. Also, in Table 7 results of the current method and finite element method using edge stabilization (FEM-ES) are compared. Results of FEM-ES have extracted from Burman and Hansbo (2004). It should be noted that, the reported CPU time is the total elapsed time, from level 1 to the last level, and it is not the CPU time of last level.

Fig. 6
figure 6

Convergence rate by adaptive and uniform refined mesh with stabilization, Example 2

Table 4 Error of computed solution by uniform refinement, Example 2
Table 5 Error of computed solution on adaptive refined mesh, Example 2
Table 6 Relative error and CPU time of computed solution, Example 2
Table 7 Comparison of Adaptive.S and Uniform.S and FEM-ES, Example 2
Fig. 7
figure 7

EFG solution by adaptive technique (left) and corresponding adapted background mesh (right) on level 15, Example 3

Fig. 8
figure 8

The effectivity index as a function of refinement (left) and \(L^2\) error (right), Example 3

4.3 Example 3

In this case \(\epsilon =10^{-2}\), \(\mathbf{b }=(0,1)^{\text {T}}\) and \(c=0\). The exact solution is as follows:

$$\begin{aligned} u=\frac{\exp (\frac{1}{\epsilon })-\exp (\frac{x}{\epsilon })}{\exp (\frac{1}{\epsilon })-1}. \end{aligned}$$

The right-hand side f and Dirichlet boundary conditions can be computed from the exact solution. The results of this test are shown in Fig. 7. The effectivity indices and \(L^2\) error are gathered in Fig. 8. Also, as Example 2, we have reported the effectivity indices for both stabilized and unstabilized methods. However, here the results of using artificial diffusion (stabilized) and without this term (unstabilized) are not too different. The reason is that in this example \(\epsilon \) can not be too small because even the exact solution is undefined for \(\epsilon =10^{-3}\) in the MATLAB double precision floating point system. Also, Fig. 9 shows convergence rate of presented methods in this example. Comparisons of adaptive and uniform refinements and effect of stabilization are presented in Tables 89 and 10.

Fig. 9
figure 9

Convergence rate by adaptive and uniform refined mesh with stabilization, Example 3

Table 8 Error of computed solution by uniform refinement, Example 3
Table 9 Error of computed solution on adaptive refined mesh, Example 3
Table 10 Relative error and CPU time of computed solution, Example 3

4.4 Example 4

As the last example, consider the following example without exact solution, which involves discontinuous boundary conditions and causes not only a sharp layer, but also an internal sharp layer (Lin and Atluri 2000). In this case, \(\epsilon =10^{-3}\), the right hand side f and the reaction coffiecient c are zero. The vector \(\mathbf{b}=[\cos t, \sin t]\) and Dirichlet boundary conditions are as follows:

$$\begin{aligned} g_D=\left\{ \begin{array}{ll} 1&{}\quad 0\le x \le 1,\mathrm{}\ y=0\\ 1 &{} \quad x=0,\mathrm{}\ 0\le y \le 0.2\\ 0 &{}\quad {\text {otherwise}}. \end{array} \right. \end{aligned}$$
(4.2)

The numerical solution and last mesh obtained at level 20 of refinements for \(t=\frac{\pi }{4}\) are shown in Fig. 10. A mild oscillation can be observed near the point (0.05,0.2). Results without using stabilization and adaptive technique are not acceptable and are not reported in the paper.

Fig. 10
figure 10

The EFG solution by adaptive technique with \(t=\frac{\pi }{4}\) (left) and the adapted mesh at level 20 (right) Example 4

5 Conclusion

In this paper, an adaptive element free Galerkin (EFG) method is suggested for solving convection diffusion type equations. A posteriori error estimation based on the post-processed gradient is used. Also, to get the stability an artificial diffusion is considered. Here, it should be noted that based on the results reported in the tables, use of artificial diffusions has great effect on adaptive refinements, while this effect is insignificant for uniform refinements. To show efficiency of the proposed adaptive technique, some examples are solved numerically and the effectivity indices are computed in the examples with exact solution.