1 Introduction

We consider in this paper the following time fractional diffusion equation (TFDE):

$$\begin{aligned} \begin{aligned} {}^{C}_{0}D^{\alpha }_{t}v(\varvec{x},t)+{\mathcal {L}} v(\varvec{x},t)+{\mathcal {N}}(v(\varvec{x},t),t)=0, \qquad \forall (\varvec{x},t)\in D:=\Omega \times (0,T], \end{aligned} \end{aligned}$$
(1.1)

with the initial condition

$$\begin{aligned} \begin{aligned} v(\varvec{x},0)&=v_0(\varvec{x}), \qquad \forall \varvec{x}\in \Omega , \end{aligned} \end{aligned}$$
(1.2)

and the homogeneous boundary conditions. In the above, \(\alpha \in (0,1),\)\(\Omega \) is a bounded domain in \( \mathbb {R}^d\), \({\mathcal {L}}\) is a linear self-adjoint elliptic operator and \({\mathcal {N}}\) is a lower-order nonlinear operator, and \(^{C}_{0}D^{\alpha }_{t}\) (\(0<\alpha <1\)) is the left-sided Caputo fractional derivative of order \(\alpha \) (see the definition in 2.4).

There is now a vast literature on the numerical methods for the fractional differential equations, mostly with the finite difference methods (e.g., [3, 6, 19, 22, 32, 38, 39] and the references therein) and the finite element methods (e.g., [8, 16,17,18, 36] and the references therein).

The two main difficulties in solving fractional PDEs such as (1.1) are (i) fractional derivatives are non-local operators and generally lead to full nonsymmetric matrices; and (ii) their solutions are often singular so polynomial based approximations are not efficient.

Since spectral methods are capable of providing exceedingly accurate numerical results with less degrees of freedoms, they have been widely used for numerical approximations [1, 10, 28, 29]. In particular, well designed spectral methods appear to be particularly attractive to deal with the difficulties associated with fractional PDEs mentioned above. Polynomial based spectral methods have been developed for TFDEs, e.g., [2, 21, 33]. However, these methods use polynomial basis functions which are not particularly suitable for TFDEs whose solutions are generally non-smooth at \(t=0\). Spectral methods for fractional PDEs with non-smooth solutions have been a subject of intensive study in the last few years, e.g., Zayernouri and Karniadakis [35] first proposed to approximate the singular solutions by Jacobi poly-fractonomials, which were defined as eigenfunctions of a fractional Sturm–Liouville problem; Chen et al. [5] constructed efficient Petrov–Galerkin methods for fractional PDEs by using the generalized Jacobi functions (GJFs) which include Jacobi poly-fractonomials as special cases. Subsequently, some authors developed spectral methods by using Jacobi poly-fractonomials/GJFs to solve fractional PDEs [14, 34, 37, 40]. Hou and Xu [12, 13] introduced a Müntz spectral method for some weakly singular integro-differential equations and fractional differential equations. Liu et al. [23] proposed a novel spectral scheme using nonstandard singular basis function for time fractional differential equation. Very recently, Chen and Shen [4] developed the enriched spectral-Galerkin method for the problems with weakly singular solution.

In a previous work [31], we introduced a space–time Petrov–Galerkin spectral method for linear/nonlinear time fractional diffusion equation, which employs the GJFs in temporal discretization and Fourier-like basis in spatial discretization. The use of Fourier-like basis functions in space can be regarded as using the matrix decomposition/diagonalization method [11, 24, 30]. However, this approach is not feasible when \(\Omega \) is not a simple tensor product domain, one cannot construct a Fourier-like basis and the degree of freedom (DoF) in space is too large to perform eigen-decomposition. In this paper, we focus on how to construct an efficient matrix decomposition method based on time variable. The two main difficulties here are: (i) the stiffness matrix in the time variable is not symmetric so the matrix decomposition method based the eigen-decomposition is not suitable; and (ii) the solution has weak singularity at \(t=0\) which limits the accuracy of the approximation by the GJFs.

We shall present in this paper an enriched Petrov–Galerkin spectral method for linear and nonlinear TFDEs. This work introduces several new aspects: (i) We develop a novel direct solver for time Petrov–Galerkin spectral method, which employs QZ decomposition to solve the non-symmetric linear system efficiently in a stable manner; (ii) For the time variable, we choose GJFs to match the leading singularity of the underlying solution; (iii) We use an enriched Petrov–Galerkin method to match leading singular terms of the underlying solution, and thus significantly improved the accuracy.

The remainder of this paper is structured as follows. In Sect. 2, we introduce the basis functions for the time variable, and present some useful properties of fractional calculus. In Sect. 3, we develop efficient Petrov–Galerkin methods for TFDEs and establish the error bounds for the proposed method. We present the enriched Petrov–Galerkin method for TFDEs in Sect. 4. Numerical results for nonlinear problems and applications to time fractional Allen–Cahn equations are presented in Sect. 5. Some concluding remarks are given in the last section.

2 Preliminaries

In this section, we review some basics of fractional integrals/derivatives, define some suitable functional spaces to be used later, and introduce some properties of the shifted generalized Jacobi functions and the shifted Legendre polynomials.

2.1 Fractional Derivatives

We start with some preliminary definitions of fractional derivatives (see, e.g. [7, 25]).

Let \(I=(0,T)\). For \(\rho \in \mathbb {R}^{+},\) the left-sided and right-sided Riemann–Liouville integrals are respectively defined as

$$\begin{aligned} \begin{aligned}&{}_{0}I_{t}^\rho u(t)=\frac{1}{\Gamma (\rho )}\displaystyle \int ^{t}_0\displaystyle \frac{u(s)}{(t-s)^{1-\rho }}\mathrm{d}s,\quad t\in I,\\&{}_{t}I_{T}^\rho u(t)=\frac{1}{\Gamma (\rho )}\displaystyle \int ^{T}_{t}\displaystyle \frac{u(s)}{(s-t)^{1-\rho }}\mathrm{d}s,\quad t\in I, \end{aligned} \end{aligned}$$
(2.1)

where \(\Gamma (\cdot )\) is the usual Gamma function.

For \(\nu \in [m-1,m)\) with \(m\in \mathbb {N},\) the left-sided Riemann–Liouville fractional derivative of order \(\nu \) is defined by

$$\begin{aligned} {}_{0}D_{t}^{\nu } u(t)=\frac{1}{\Gamma (m-\nu )}\frac{\mathrm{d}^m}{\mathrm{d}t^m}\displaystyle \int ^{t}_{0}\displaystyle \frac{u(s)}{(t-s)^{\nu -m+1}}\mathrm{d}s,\quad t\in I, \end{aligned}$$
(2.2)

and the right-sided Riemann–Liouville fractional derivative of order \(\nu \) is defined by

$$\begin{aligned} {}_{t}D_{T}^{\nu } u(t)=\frac{(-1)^m}{\Gamma (m-\nu )}\frac{\mathrm{d}^m}{\mathrm{d}t^m}\displaystyle \int _{t}^{T}\displaystyle \frac{u(s)}{(s-t)^{\nu -m+1}}\mathrm{d}s,\quad t\in I. \end{aligned}$$
(2.3)

For \(\nu \in [m-1,m)\) with \(m\in \mathbb {N},\) the left-sided Caputo fractional derivative of order \(\nu \) is defined by

$$\begin{aligned} {}_{0}^CD_{t}^{\nu }u(t)=\frac{1}{\Gamma (m-\nu )}\displaystyle \int ^{t}_{0}\displaystyle \frac{u^{(m)}(s)}{(t-s)^{\nu -m+1}}\mathrm{d}s,\quad t\in I, \end{aligned}$$
(2.4)

and the right-sided Caputo fractional derivative of order \(\nu \) is defined by

$$\begin{aligned} {}_{t}^CD_{T}^{\nu } u(t)=\frac{(-1)^m}{\Gamma (m-\nu )}\displaystyle \int _{t}^{T}\displaystyle \frac{u^{(m)}(s)}{(s-t)^{\nu -m+1}}\mathrm{d}s,\quad t\in I. \end{aligned}$$
(2.5)

The following lemma shows the relationship between the Riemann–Liouville and Caputo fractional derivatives (see, e.g., [7, 25]).

Lemma 2.1

For \(\nu \in [k-1,k)\) with \(k\in \mathbb {N}\), we have

$$\begin{aligned} {}_{0}D_{t}^{\nu }u(t)=^{C}_{0}D_{t}^{\nu }u(t)+\displaystyle \sum ^{k-1}_{j=0}\displaystyle \frac{u^{(j)}(0)}{\Gamma (1+j-\nu )}t^{j-\nu }. \end{aligned}$$
(2.6)

2.2 Some Functional Spaces and Their Properties

We now introduce some functional spaces to be used later.

Let \(C^\infty _0(I)\) be the space of smooth functions with compact support in I, and \(H^s_0(I)\) denote the closure of \(C_0^\infty (I)\) with respect to norm \(\Vert \cdot \Vert _{s,I}\).

For any real \(s>0\), we introduce some useful spaces.

  • Let \({\widetilde{H}}^s(I)\) be the set of functions in \(H^s(I)\) whose extension by zero to \(\mathbb {R}\) is in \(H^s(\mathbb {R})\).

  • Let \({\widetilde{H}}^s_l(I)\) be the set of functions u whose extension by zero, denoted by \(\tilde{u}\) is in \(H^s(-\infty ,T)\).

  • Let \({\widetilde{H}}^s_r(I)\) be the set of functions u whose extension by zero, denoted by \(\tilde{u}\) is in \(H^s(0,\infty )\).

Therefore, a direct consequence is as follows, see, e.g, [15].

Lemma 2.2

The operators \({}_{0}D_{t}^{s}\) and \({}_{t}D_{T}^{s}\) extend continuously to bounded operators from \({\widetilde{H}}^s_l(I)\) and \({\widetilde{H}}^s_r(I)\), respectively, to \(L^2(I)\).

We define the following space in x-direction,

$$\begin{aligned}&H_{{\mathcal {L}}}(\Omega )=\{v~|~v\in L^2(\Omega ),\langle {\mathcal {L}}v,v\rangle <\infty ,\nonumber \\&\quad \mathrm{and }~v |_{\partial \Omega }~\text {satisfy a homegeneous boundary condition}\}, \end{aligned}$$
(2.7)

equipped with the norm

$$\begin{aligned} \Vert v\Vert _{{\mathcal {L}}}=\left( \int _{\Omega }v^2(x)\mathrm{d}x+\int _{\Omega }{\mathcal {L}}v(x)v(x)\mathrm{d}x\right) ^{1/2}. \end{aligned}$$
(2.8)

The notation \(\langle \cdot ,\cdot \rangle _{L^2(\Omega )}\) denotes the duality pairing between \(H_{{\mathcal {L}}}(\Omega )\) and its dual \(H_{{\mathcal {L}}}^{\!-1}(\Omega )\), also the inner product in \(L^2(\Omega )\). For \(u,v\in L^2(D)\), for each \(t\in I\), \(u(t),\,v(t)\in H_{{\mathcal {L}}}(\Omega )\), we denote

$$\begin{aligned} b(u,v):=\langle {\mathcal {L}}u,v\rangle _{L^2(D)}=\int ^T_0\int _{\Omega }{\mathcal {L}}u(x,t)\,v(x,t)\mathrm{d}x\mathrm{d}t, \end{aligned}$$
(2.9)

and the Bochner spaces on D :

$$\begin{aligned} \begin{aligned}&\mathbb {V}:=L^2(I;H_{{\mathcal {L}} }(\Omega )) \quad \text{ with } \text{ norm } \quad \Vert v\Vert _{\mathbb {V}}^2=b(v, v), \\&\mathbb {V}^{*}:=L^2(I; H^{-1}_{{\mathcal {L}}}(\Omega )) \quad \text{ with } \text{ norm } \quad \Vert v\Vert _{\mathbb {V}^{*}}=\sup _{\phi \in \mathbb {V}} \frac{\langle v, \phi \rangle _{L^2(D)}}{\Vert \phi \Vert _{\!\mathbb {V}}}. \end{aligned} \end{aligned}$$
(2.10)

Below we will also use \(\langle \cdot ,\cdot \rangle _{L^2(D)}\) for the duality pairing between \(\mathbb {V}\) and \(\mathbb {V}^*\). For any \(s\in (0,1)\), we also define space

$$\begin{aligned} B^s(D):= {\widetilde{H}}^s_l(I,H^{\!-1}_{{\mathcal {L}}}(\Omega ))\cap L^2(I,H_{{\mathcal {L}}}(\Omega )), \end{aligned}$$

equipped with the norm

$$\begin{aligned} \Vert v\Vert _{B^s(D)}:=\Big (\Vert {}_0D^s_tv\Vert ^2_{L^2(I,H^{\!-1}_{{\mathcal {L}}}(\Omega ))}+\Vert v\Vert ^2_{L^2(I,H_{{\mathcal {L}}}(\Omega ))}\Big )^{1/2}. \end{aligned}$$

The following Lemma are useful; see, e.g., [8].

Lemma 2.3

For all \(0<\alpha <1\), if \(u\in B^\alpha (D),\) then

$$\begin{aligned} \Vert u\Vert _{{\widetilde{H}}^{\alpha }_l(I;H^{\!-1}_{{\mathcal {L}}}(\Omega ))}\sim \Vert {}_0D^\alpha _tu\Vert _{L^2(I;H^{\!-1}_{{\mathcal {L}}}(\Omega ))}. \end{aligned}$$
(2.11)

2.3 Trial & Test Functions in Time

We introduce below the trial & test functions that we will use for the time variable. For \(\alpha ,\beta >-1,\) let \(P_n^{(\alpha ,\beta )}(x),\)\(x\in \Lambda \) be the standard Jacobi polynomial of degree n, and denote the weight function \(\chi ^{(\alpha ,\beta )}(x)=(1-x)^\alpha (1+x)^\beta \). The set of Jacobi polynomials is a complete \(L^2_{\chi ^{(\alpha ,\beta )}}(\Lambda )\)-orthogonal system, i.e.,

$$\begin{aligned} \displaystyle \int ^1_{-1}P_l^{(\alpha ,\beta )}(x)P_m^{(\alpha ,\beta )}(x)\chi ^{(\alpha ,\beta )}(x)\mathrm{d}x =\gamma ^{(\alpha ,\beta )}_l\delta _{l,m}, \end{aligned}$$
(2.12)

where \(\delta _{l,m}\) is the Kronecker function, and

$$\begin{aligned} \gamma ^{(\alpha ,\beta )}_l=\displaystyle \frac{2^{\alpha +\beta +1}}{(2l+\alpha +\beta +1)} \displaystyle \frac{\Gamma (l+\alpha +1)\Gamma (l+\beta +1)}{l!\Gamma (l+\alpha +\beta +1)}. \end{aligned}$$

In particular, \(P_0^{(\alpha ,\beta )}(x)=1.\)

The shifted Jacobi polynomial of degree n is defined by

$$\begin{aligned} {\widetilde{P}}_n^{(\alpha ,\beta )}(t)=P_n^{(\alpha ,\beta )}\left( \displaystyle \frac{2t-T}{T}\right) ,\quad t \in I,\quad n\ge 0. \end{aligned}$$
(2.13)

Clearly, the set of \(\{{\widetilde{P}}_n^{(\alpha ,\beta )}(t)\}_{n\ge 0}\) is a complete \(L^2_{\omega ^{(\alpha ,\beta )}}(I)\)-orthogonal system with the weight function \(\omega ^{(\alpha ,\beta )}(t)={(T-t)}^{\alpha }t^\beta ,\) by (2.12) and (2.13) we get that

$$\begin{aligned} \displaystyle \int _{I}{\widetilde{P}}_l^{(\alpha ,\beta )}(t){\widetilde{P}}_m^{(\alpha ,\beta )}(t)\omega ^{(\alpha ,\beta )}(t)\mathrm{d}t =\Big (\frac{T}{2}\Big )^{\alpha +\beta +1}\gamma ^{(\alpha ,\beta )}_l\delta _{l,m}. \end{aligned}$$
(2.14)

For any \(\alpha ,~\beta >-1,\) the shifted generalized Jacobi functions on I is defined by (cf. [27])

$$\begin{aligned} \begin{array}{ll} J^{(\alpha ,\beta )}_n(t)=t^\beta {\widetilde{P}}^{(\alpha ,\beta )}_n(t),\quad t\in I,\quad n\ge 0. \end{array} \end{aligned}$$
(2.15)

and our approximation space on I is defined by

$$\begin{aligned} {\mathcal {F}}_N^{(\alpha )}(I):=\{t^\alpha \psi (t):\psi (t)\in {\mathcal {P}}_N(I)\}=\mathrm{span}\{J_n^{(-\alpha ,\alpha )}(t) =t^\alpha {\widetilde{P}}^{(-\alpha ,\alpha )}_n(t):0\le n\le N\}, \end{aligned}$$
(2.16)

which incorporates the homogeneous boundary conditions at \(t=0.\)

A particular case is the shifted Legendre polynomial \(L_n(t)\), \(t\in I\) is defined by

$$\begin{aligned} L_n(t)=P^{0,0}_n\left( \displaystyle \frac{2t}{T}-1\right) ,\quad \quad n=0,1,2,\ldots . \end{aligned}$$
(2.17)

The set of \(L_n(t)\) is a complete \(L^2(I)\)-orthogonal system, namely,

$$\begin{aligned} \displaystyle \int _{I}L_{l}(t)L_{m}(t)\mathrm{d}t=\displaystyle \frac{T}{2l+1}\delta _{l,m}, \end{aligned}$$
(2.18)

Clearly, we derive from (2.15)–(2.17) and a direct calculation that (cf. [5])

$$\begin{aligned} {}_{0}D_{t}^{\alpha }J_n^{(-\alpha ,\alpha )}(t)=\displaystyle \frac{\Gamma (n+\alpha +1)}{n!}L_n(t). \end{aligned}$$
(2.19)

3 A Petrov–Galerkin Space–Time Method

In this section, we will propose a Petrov–Galerkin spectral method for (1.1). We shall start by considering a special case of (1.1) with \({\mathcal {N}} v=\beta v-g\):

$$\begin{aligned} \begin{aligned} {}^{C}_{0}D^{\alpha }_{t}v(\varvec{x},t)+{\mathcal {L}}v(\varvec{x},t)+\beta v(\varvec{x},t)=g(\varvec{x},t), \qquad \forall (\varvec{x},t)\in D, \end{aligned} \end{aligned}$$
(3.1)

with the initial and boundary conditions (1.2) and the constant \(\beta \ge 0\). Note that the above linear equation will be used as a preconditioner for nonlinear equation (1.1) later.

3.1 GJFs Petrov–Galerkin Method for (3.1)

Throughout this paper, we assume that \(v_0\in H^2(\Omega )\cap H^1_0(\Omega )\). For the case of non-homogeneous initial conditions \(v(\varvec{x},0)=v_0(\varvec{x})\), we first decompose the solution \(v(\varvec{x},t)\) into two parts as

$$\begin{aligned} v(\varvec{x},t)=u(\varvec{x},t)+v_0(\varvec{x}), \end{aligned}$$
(3.2)

with \(u(\varvec{x},0)=0\). Hence, by (3.2) and (2.6), the Eq. (3.1) is equivalent to the following equation with Riemann–Liouville fractional derivative:

$$\begin{aligned} \begin{aligned} {}_{0}D^{\alpha }_{t}u(\varvec{x},t)+ {\mathcal {L}}u(\varvec{x},t)+\beta u(\varvec{x},t)=f(\varvec{x},t), \qquad \forall (\varvec{x},t)\in D, \end{aligned} \end{aligned}$$
(3.3)

where

$$\begin{aligned} f(\varvec{x},t)=g(\varvec{x},t)-{\mathcal {L}}v_0(\varvec{x})-\beta v_0(\varvec{x}), \end{aligned}$$

with homogeneous initial

$$\begin{aligned} \begin{aligned} u(\varvec{x},0)&=0, \qquad \forall \varvec{x}\in \Omega , \end{aligned} \end{aligned}$$
(3.4)

and the corresponding boundary conditions.

We first recall the weak formulation of (3.1): find \(u\in B^\alpha (D)\) such that

$$\begin{aligned} {\mathcal {A}}(u,v):=\langle {}_{0}D^{\alpha }_{t}u,v\rangle _{L^2(D)}+b(u,v)+\beta (u, v)_{L^2(D)}=(g,v)_{L^2(D)}, \qquad \forall v\in \mathbb {V}. \end{aligned}$$
(3.5)

where \(b(\cdot ,\cdot )\) and \(\mathbb {V}\) are defined in (2.9) and  (2.10), respectively. Without loss of generality, we assume that the bilinear form \(b(\cdot ,\cdot ):\mathbb {V}\times \mathbb {V}\rightarrow \mathbb {R}\) satisfies

  • Continuity: \(\exists \,C_1>0\)   such that    \(|b(u,v)|\le C_1\Vert u\Vert _{\mathbb {V}}\Vert v\Vert _{\mathbb {V}}\),

  • Coercivity: \(\exists \,C_2>0\)   such that    \(|b(u,u)|\ge C_2\Vert u\Vert _{\mathbb {V}}^2\).

A direct consequence is the following.

Theorem 3.1

For any \(f\in \mathbb {V}^*\), problem (3.5) has a unique solution \(u\in B^\alpha (D)\), and it satisfies

$$\begin{aligned} \Vert u\Vert _{B^\alpha (D)}\le c\Vert f\Vert _{\mathbb {V}^*}. \end{aligned}$$

Proof

By using an argument similar to the proof of Lemma 2.4 in [8], we deduce that

$$\begin{aligned} \begin{aligned}&|{\mathcal {A}}(u,v)| \le \left| \langle {}_{0}D^{\alpha }_{t}u,v\rangle _{L^2(D)}\right| +|b(u,v)|+\beta |(u,v)_{L^2(D)}| \le c_\beta \Vert u\Vert _{B^{\alpha }(D)}\Vert v\Vert _{\mathbb {V}}, \\&\sup _{v\in \mathbb {V}} \frac{{\mathcal {A}}(u,v)}{\Vert v\Vert _{\mathbb {V}}} \ge \Vert u\Vert _{B^{\alpha }(D)}, \quad \text {for all}\quad u\in B^\alpha (D). \end{aligned} \end{aligned}$$
(3.6)

Hence, the existence, uniqueness and stability follow directly from the continuity and inf-sup condition of the bilinear form \({\mathcal {A}}(\cdot ,\cdot )\). \(\square \)

Remark 3.1

The Galerkin weak formulation (see, e.g., [21]) is to find: \(u\in \tilde{B}^{\frac{\alpha }{2}}:=H^{\frac{\alpha }{2}}(I;L^2(\Omega ))\cap L^2(I;H^1_0(\Omega ))\) such that

$$\begin{aligned} a(u, v)=\big \langle {}_0 D_{t}^{\frac{\alpha }{2}} u, {}_tD_{T}^{\frac{\alpha }{2}} v\big \rangle _{L^2(D)}+(\nabla u,\nabla v)_{L^2(D)}=\langle f,v\rangle _{L^2(D)}, \quad \forall v\in \tilde{B}^{\frac{\alpha }{2}}. \end{aligned}$$

Then, the bilinear form \(a(\cdot ,\cdot )\) is continuous and coercive on \({\tilde{B}}^{\frac{\alpha }{2}}\), and the variational problem is well-posed. More results on well-posedness and regularity for  (3.5), we refer to [9, 20] and the references therein.

Let \(V_h\) be a finite-dimensional approximation space of \(V:=H_{{\mathcal {L}}}(\Omega )\):

$$\begin{aligned} V_h=\text {span}\{\phi _1,\phi _2,\ldots ,\phi _{{M}}\}. \end{aligned}$$
(3.7)

For the time variable, we shall use the fractional polynomial space \({\mathcal {F}}_{N}^{(\alpha )}(I)\) defined in (2.16). Then, the Petrov–Galerkin method for (3.3) is to seek \(u_L(\varvec{x},t):=u_{MN}\in V_h \otimes {\mathcal {F}}^{(\alpha )}_N\subset B^\alpha (D)\), such that

$$\begin{aligned}&{\mathcal {A}}(u_L,v):=\langle {}_{0}D^{\alpha }_{t}u_L,v\rangle _{L^2(D)}+ b(u_L,v)\nonumber \\&\qquad +\beta (u_L, v)_{L^2(D)}=(g,v)_{L^2(D)}, \quad \forall v\in V_h\otimes {\mathcal {P}}_N\subset \mathbb {V}. \end{aligned}$$
(3.8)

Next, we shall construct suitable basis functions of \({\mathcal {F}}_{N}^{(\alpha )}(I)\) so that the above system can be solved efficiently.

For the time variable, we use the generalized Jacobi functions \(J^{(-\alpha ,\alpha )}_{n}(t)\) defined in the last section:

$$\begin{aligned} {\mathcal {F}}_{N}^{(\alpha )}(I)=\mathrm{span}\{J_{n}^{(-\alpha ,\alpha )}(t):0\le n\le N\}, \end{aligned}$$
(3.9)

and for \({\mathcal {P}}_{N}(I)\) in the test space, we simply use the scaled Legendre polynomials, namely:

$$\begin{aligned} {\mathcal {P}}_{N}(I)=\mathrm{span}\Big \{L^{(\alpha )}_n(t):=\kappa _{n,\alpha }L_n(t):0\le n\le N\Big \},\qquad \mathrm{with}\quad \kappa _{n,\alpha }=\displaystyle \frac{n!(2n+1)}{T\cdot \Gamma (n+\alpha +1)}. \end{aligned}$$
(3.10)

We now describe the numerical implementations for (3.8) under this set of basis functions. We write

$$\begin{aligned} u_L(\varvec{x},t)=\displaystyle \sum ^{M}_{m=1}\displaystyle \sum ^{N}_{n=0}{\widetilde{u}}_{mn}\phi _{m}(\varvec{x})J^{(-\alpha ,\alpha )}_{n}(t). \end{aligned}$$
(3.11)

Denote

$$\begin{aligned} \begin{aligned}&f_{mn}=(f,\phi _mL_n^{(\alpha )})_{L^2(D)},\qquad F=(f_{mn})_{1\le m\le M,0\le n\le N}, \\&s^t_{pq}=\displaystyle \int _I{}_{0}D^{\alpha }_{t}J^{(-\alpha ,\alpha )}_{q}(t)L_p^{(\alpha )}(t)\mathrm{d}t,\qquad m^t_{pq}=\displaystyle \int _IJ^{(-\alpha ,\alpha )}_{q}(t)L_p^{(\alpha )}(t)\mathrm{d}t,\qquad \\&\varvec{S}^t=(s^t_{pq})_{0\le p,q\le N},\qquad \varvec{M}^t=(m^t_{pq})_{0\le p,q\le N},\quad U=({\widetilde{u}}_{mn})_{1\le m\le M,0\le n\le N}. \end{aligned} \end{aligned}$$
(3.12)

It can be easily verified from (2.18), (2.19) and (3.10) that \(\varvec{S}^t=\varvec{I}\) with \(\varvec{I}\) being the identity matrix. On the other hand,

$$\begin{aligned} m^t_{pq}=\displaystyle \int _IJ^{(-\alpha ,\alpha )}_{p}(t)L_q^{(\alpha )}(t)dt=\displaystyle \int _I {{\widetilde{P}}}_p^{(-\alpha ,\alpha )}(t) L_q^{(\alpha )}(t) t^\alpha dt. \end{aligned}$$
(3.13)

So \(\varvec{M}^t\) is not sparse but can be accurately computed by Jacobi-Gauss quadrature with index \((0,\alpha )\).

Then, we find that (3.8) is equivalent to the following linear system:

$$\begin{aligned} \varvec{M}^{h}\,U(\varvec{S}^t)^T+\varvec{S}^{h}\,U(\varvec{M}^t)^T+\beta \varvec{M}^h\,U(\varvec{M}^t)^T=F, \end{aligned}$$
(3.14)

where \(\varvec{M}^h\) and \(\varvec{S}^h\) are the mass matrix and stiffness matrix in the space variable, namely,

$$\begin{aligned} \begin{aligned}&s^h_{pq}=\displaystyle \int _{\Omega }{\mathcal {L}}\phi _q(\varvec{x})\phi _p(\varvec{x})d\varvec{x},\qquad m^h_{pq}=\displaystyle \int _{\Omega }\phi _q(\varvec{x})\phi _p(\varvec{x})d\varvec{x},\qquad \\&\varvec{S}^h=(s^h_{pq})_{1\le p,q\le M},\qquad \varvec{M}^h=(m^h_{pq})_{1\le p,q\le M}. \end{aligned} \end{aligned}$$
(3.15)

Obviously, it is not computationally efficient to use matrix decomposition method in the space direction for non-tensor product domains. Because the size of \(\varvec{M}^{h}\) and \(\varvec{S}^{h}\) alway very large in (3.14). In this paper, we devote to do matrix decomposition in the time direction. Notice that an advantage of using matrix decomposition in time direction is that we only need to solve N times elliptic equation in the space direction. Moreover, it is straightforward to extend this approach to the nonlinear case (1.1), we omitted all the details in this paper.

3.2 Several Algorithms for (3.14)

This subsection focuses on the efficient algorithms for the nonsymmetric linear system.

Algorithm I: Eigen-Decomposition. We consider the generalized eigenvalue problem: let \(\varvec{E}:=({\bar{e}}_0,\ldots ,\bar{e}_{N})=(e_{pq})_{p,q=0,\ldots ,N}\) be the matrix formed by the orthonormal eigenvectors of the generalized eigenvalue problem \(\varvec{M}^t{\bar{e}}_j=\lambda _j\varvec{S}^t{\bar{e}}_j\) and \(\Lambda =\text {diag}(\lambda _0,\ldots ,\lambda _{N})\), i.e.,

$$\begin{aligned} \varvec{M}^t\varvec{E}=\varvec{S}^t\,\varvec{E}\Lambda . \end{aligned}$$
(3.16)

Setting \(U=V\varvec{E}^T\), and multiplying (3.14) [or  (4.6) respectively] both side by \((\varvec{S}^t\varvec{E})^{-T}\), we arrive at

$$\begin{aligned} \varvec{M}^h\,V+\varvec{S}^h\,V\Lambda +\beta \varvec{M}^h\,V\Lambda =G:=F(\varvec{S}^t\varvec{E})^{-T}. \end{aligned}$$
(3.17)

Hence, the m-th column of the above matrix equation becomes:

$$\begin{aligned} (\lambda _n\varvec{S}^h+(1+\beta \lambda _n)\varvec{M}^h){\mathbf {v}}_n={\mathbf {g}}_n,\qquad 0\le n\le N, \end{aligned}$$
(3.18)

where

$$\begin{aligned} \begin{aligned}&V=({\widetilde{v}}_{m,n})_{1\le m\le M,0\le n\le N},\quad {\mathbf {v}}_n=({\widetilde{v}}_{1,n},{\widetilde{v}}_{2,n},\ldots ,{\widetilde{v}}_{M,n})^T,\\&G=(g_{m,n})_{1\le m\le M,0\le n\le N}, \quad {\mathbf {g}}_n=(g_{1,n},g_{2,n},\ldots ,g_{M,n})^T. \end{aligned} \end{aligned}$$

The coefficient U can be computed by \(U=V\varvec{E}^T\). Finally, we can use (3.11) and (3.2) to get the solution \(u_L\). This approach is very efficient because we only need to solve \(N+1\) times elliptic equation in space, and the total cost is \(O(NT_M)\), where \(T_M\) is the cost of the underlying algorithm in the space direction. However, since \(\varvec{M}^t\) is nonsymmetric, this approach suffer from large round off errors. In Table 1, we tabulate the maximum error of \((\varvec{S}^t\varvec{E})^{-1}\varvec{M}^t\varvec{E}-\Lambda \) for the stifness/mass matrix in (3.12) with various N, which indicate that error of eigen-decomposition is grown as N increases. We then conclude that the eigen-decomposition algorithm for linear system with the full nonsymmetric matrix is not stable.

Table 1 The error of eigen-decomposition

Algorithm II: Partial QZ Decomposition. We consider following QZ decomposition:

$$\begin{aligned} \varvec{Q}\,(\varvec{S}^t)^T\varvec{Z} =\varvec{A},\quad \varvec{Q}\,(\varvec{M}^t)^T\varvec{Z} =\varvec{B},\quad \Leftrightarrow \varvec{Q}^T\,\varvec{A}\varvec{Z}^T =(\varvec{S}^t)^T, \quad \varvec{Q}^T\,\varvec{B}\varvec{Z}^T =(\varvec{M}^t)^T, \end{aligned}$$
(3.19)

where \(\varvec{Q}\), \(\varvec{Z}\) are the unitary matrices, and \(\varvec{A}\), \(\varvec{B}\) are upper triangular matrices, namely,

$$\begin{aligned} \begin{array}{ll}\varvec{A}=\begin{pmatrix} a_{0,0}&{}a_{0,1}&{}\dots &{}a_{0,N}\\ &{} a_{1,1} &{} \dots &{}a_{1,N}\\ &{} &{}\ddots &{}\vdots \\ &{} &{} &{}a_{N,N} \end{pmatrix},\qquad \varvec{B}=\begin{pmatrix} b_{0,0}&{}b_{0,1}&{}\dots &{}b_{0,N}\\ &{} b_{1,1} &{} \dots &{}b_{1,N}\\ &{} &{}\ddots &{}\vdots \\ &{} &{} &{}b_{N,N} \end{pmatrix}. \end{array} \end{aligned}$$

Setting \(U=V\varvec{Q}\), and multiplying (3.14) both sides by \(\varvec{Z}\), we arrive at

$$\begin{aligned} \varvec{M}^h\,V\,\varvec{A}+\varvec{S}^h\,V\,\varvec{B}+\beta \varvec{M}^h\,V\,\varvec{B}=G:=F\varvec{Z}. \end{aligned}$$
(3.20)

We can obtain the column of coefficients \({\mathbf {v}}_n=({\widetilde{v}}_{1,n},{\widetilde{v}}_{1,n},\ldots ,{\widetilde{v}}_{M,n})^T,\) one by one, namely,

$$\begin{aligned} a_{n,n}\varvec{M}^h\,{\mathbf {v}}_n+b_{n,n}\varvec{S}^h\,{\mathbf {v}}_n+\beta b_{n,n}\varvec{M}^h\,{\mathbf {v}}_n =\varvec{g}_n-\varvec{h}_{n-1},\quad 0\le n\le N, \end{aligned}$$

where

$$\begin{aligned} \varvec{h}_{n-1}=\displaystyle \sum _{k=0}^{n-1}\left( a_{k,n}\varvec{M}^h\,{\mathbf {v}}_k+b_{k,n}\varvec{S}^h\,{\mathbf {v}}_k+\beta b_{k,n}\varvec{M}^h\,{\mathbf {v}}_k\right) . \end{aligned}$$
(3.21)

Briefly, we obtain the unknown coefficients \({\mathbf {v}}_n\) in terms of previous computed coefficients \(\{{\mathbf {v}}_k\}_{k=0}^{n-1}\), as stated in Algorithm II below.

figure a

Finally, the coefficient matrix U can be computed by \(U=V\varvec{Q}\), and we can use (3.11) and (3.2) to get the value of solution \(u_L\). In this algorithm, we only need to solve \(N+1\) times elliptic equation, so this new approach is also very efficient. Let \(T_M\) be the cost of solving one elliptic equation in space, then the total cost is \(O(N^2M)+(N+1)T_M\) (usually \(N\ll M\)). In Table 2, we tabulate the maximum error of \(\max \{|\varvec{Q}^T\,\varvec{A}\varvec{Z}^T -\varvec{S}^t|,| \varvec{Q}^T\,\varvec{B}\varvec{Z}^T -\varvec{M}^t|\}\) for the stifness/mass in  (3.12) with various N, which indicate that error of eigen decomposition is awaly stable. We find that QZ decomposition are much more stable than eigen decomposition for full nonsymmetric matrix.

Table 2 The error of QZ-decomposition

Algorithm III: Full Decomposition. In cases where it is feasible to diagonalize also in the space variables, e.g., when \(\Omega \) is a simple geometric (such as rectangular domains), we can simplify the algorithm even further.

We consider following eigen decomposition in space and QZ decomposition in time:

$$\begin{aligned} \varvec{M}^h\varvec{E}^h=\varvec{S}^h\varvec{E}^h\Lambda ^h,\qquad \varvec{Q}^t\,(\varvec{S}^t)^T\varvec{Z}^t =\varvec{A}^t,\quad \varvec{Q}^t\,(\varvec{M}^t)^T\varvec{Z}^t =\varvec{B}^t,\quad \end{aligned}$$

where \(\varvec{E}^h\) and \(\Lambda ^h\) are matrix form eigenvectors and eigenvalues, \(\varvec{Q}^t\), \(\varvec{Z}^t\) are the unitary matrices, and \(\varvec{A}^t\), \(\varvec{B}^t\) are upper triangular matrices.

Setting \(U=\varvec{E}\,V\varvec{Q}^t\), and multiplying the left (resp. right) of Eq. (3.14) by \((\varvec{S}^h\varvec{E}^h)^{-1}\) (resp. \(\varvec{Z}^t\)), we arrive at

$$\begin{aligned} \Lambda ^h\,V\,\varvec{A}^t+\,V\,\varvec{B}^t+\beta \Lambda ^h\,V\,\varvec{B}^t=G:=(\varvec{S}^h\varvec{E}^h)^{-1}F\varvec{Z}^t. \end{aligned}$$
(3.22)

We can solve the coefficients \(\{{\widetilde{v}}_{mn}\}_{0\le n\le N},\) one by one, namely,

$$\begin{aligned} {\widetilde{v}}_{mn}=\displaystyle \frac{g_{mn}-h_{mn}}{\lambda ^h_{mm}a^t_{nn}+b^t_{nn}+\beta \lambda ^h_{mm}b^t_{nn}}, \end{aligned}$$
(3.23)

where

$$\begin{aligned} \begin{array}{ll}&h_{mn}=\displaystyle \sum _{k=0}^{n-1}\left( \lambda ^h_{m,m}{\widetilde{v}}_{mk}a^t_{kn} +{\widetilde{v}}_{mk}b^t_{kn}+\beta \lambda ^h_{m,m}{\widetilde{v}}_{mk}b^t_{kn}\right) ,\qquad 1\le m\le M. \end{array} \end{aligned}$$
(3.24)

Briefly, we obtain tcoefficients \(\{{\widetilde{v}}_{mn}\}_{0\le n\le N},\) in terms of previous computed coefficients \(\{{\widetilde{v}}_{mj}\}_{j=0,1\ldots ,n-1}\), as stated in Algorithm III below.

figure b

Finally, the coefficient matrix U can be computed by \(U=\varvec{E}\,V\varvec{Q}^t\), and we can use (3.2) to get the value of solution \(u_L\). Notice that the full decomposition algorithm procedure is simpler to implement than the partial QZ decomposition algorithm, when \(\Omega \) is a simple geometric.

We summarize the three algorithms below: (i) all the three algorithm are only need to consists of solving \(N+1\) times systems of order M; (ii) Algorithms II and III are very stable for solving nonsymmetric linear systems, while Algorithms I are not; (iii) Algorithms II and III provide the same numerical result when \(\Omega \) is a simple geometric, and Algorithm III is simpler to implement than Algorithm II; (iv) It is worthwhile to point out that we can use QZ decomposition in both time and space direction when the spatial discretization is nonsymmetric too.

3.3 Error Estimates for Petrov–Galerkin Spectral Method

In this subsection, we conduct an error analysis for the Petrov–Galerkin method described in the previous section. Since the full error analysis for the nonlinear system is beyond the scope of this paper, we shall only consider the analysis for the linear case of (3.1) with \({\mathcal {L}}=-\Delta \), that is

$$\begin{aligned} \widetilde{{\mathcal {N}}}(u)=\beta (u+u_0). \end{aligned}$$

In order to characterize the regularity of u in t, we define the following non-uniformly weighted space involving fractional derivatives

$$\begin{aligned} {\mathcal {B}}^s_{\alpha ,\beta }(I):=\{v\in L^2_{\omega ^{(\alpha ,-\beta )}}(I):{}_{0}D_{t}^{\beta +r}v\in L^2_{\omega ^{(\alpha +\beta +r,r)}}(I)\quad \mathrm{for}\quad 0\le r\le s\},\quad s\in \mathbb {N}_0. \end{aligned}$$

The correspongding projection operator in time is \(\pi ^{(-\alpha ,\alpha )}_N:\; L^2_{\omega ^{(-\alpha ,-\alpha )}}(I)\rightarrow {\mathcal {F}}_{N}^{(\alpha )}(I)\) defined by

$$\begin{aligned} (\pi ^{(-\alpha ,\alpha )}_Nv-v,\psi )_{\omega ^{(-\alpha ,-\alpha )}}=0,\quad \forall \psi \in {\mathcal {F}}_N^{(\alpha )}(I). \end{aligned}$$
(3.25)

It is shown in [5] that

$$\begin{aligned} ({}_{0}D^{\alpha }_{t}(\pi ^{(-\alpha ,\alpha )}_Nv-v),p)=0,\quad \forall p\in {\mathcal {P}}_N(I). \end{aligned}$$
(3.26)

We recall from [27] that

Lemma 3.1

Let \(\alpha \in (0,1),\) for any \(v\in {\mathcal {B}}^s_{-\alpha ,\alpha }(I),\) with integer \(0\le s\le N\). Then

$$\begin{aligned} \Vert \pi ^{(-\alpha ,\alpha )}_Nv-v\Vert _{\omega ^{(-\alpha ,-\alpha )}}\lesssim N^{-(\alpha +s)}\Vert {}_{0}D_{t}^{\alpha +s}v\Vert _{\omega ^{(s,s)}}. \end{aligned}$$
(3.27)

and

$$\begin{aligned} \Vert {}_{0}D_{t}^{\alpha }(\pi ^{(-\alpha ,\alpha )}_Nv-v)\Vert _{I}\lesssim N^{-s}\Vert {}_{0}D_{t}^{\alpha +s}v\Vert _{\omega ^{(s,s)}}. \end{aligned}$$
(3.28)

Let \(\pi ^h\) be the \(H^1_0\)-orthogonal projection in space direction

$$\begin{aligned} \langle \pi ^h u-u,v\rangle _{H_{{\mathcal {L}}}(\Omega )}=( \nabla (\pi ^hu-u),\nabla v)_{L^2(\Omega )}=0,\quad \forall v\in V_h. \end{aligned}$$
(3.29)

Hence, using Lemma 3.1, we arrive at following result.

Theorem 3.2

Let u be the solution of (3.3) and \(u_L\) be the numerical solution (3.8). If \(u\in B^\alpha (D)\) and \({}_{0}D_{t}^{\alpha +s}u\in L^2_{\omega ^{(s,s)}}(I,H_{{\mathcal {L}}}(\Omega ))\) there holds

$$\begin{aligned} \Vert u-u_L\Vert _{B^\alpha (D)}\lesssim N^{-s}\Vert {}_{0}D_{t}^{\alpha +s}u\Vert _{L^2_{\omega ^{(s,s)}}(I,H_{{\mathcal {L}}}(\Omega ))}+ \Vert u-\pi ^hu\Vert _{B^\alpha (D)}. \end{aligned}$$
(3.30)

Proof

The discrete inf-sup condition can be derived in a similar fashion as Lemma 3.3 of [8], namely, there is a constant \(c_\alpha >0\), independent N, such that

$$\begin{aligned} \sup _{v\in V_h\otimes {\mathcal {P}}_N} \frac{{\mathcal {A}}(u_L,v)}{\Vert v\Vert _{\mathbb {V}}} \ge c_{\alpha }\Vert u_L\Vert _{B^{\alpha }(D)} \;\; \;\text{ for } \text{ all }\;\;\; u_L\in V_h\otimes {\mathcal {F}}^{(\alpha )}_N. \end{aligned}$$
(3.31)

We can derive from continuity and Theorem 3.1 and 3.31 that  3.8 admits a unique solution \(u_L\in B^\alpha (D)\) satisfying

$$\begin{aligned} \Vert u_L\Vert _{B^\alpha (D)}\le \frac{1}{c_\alpha }\Vert f\Vert _{V^*} \end{aligned}$$

Moreover, we have

$$\begin{aligned} \Vert u-u_L\Vert _{B^\alpha (D)}\le C\inf _{v\in V_h\otimes {\mathcal {F}}^{(\alpha )}_N}\Vert u-v\Vert _{B^\alpha (D)}. \end{aligned}$$
(3.32)

Taking \(v=\pi ^{(-\alpha ,\alpha )}_N\pi ^hu=\pi ^h\pi ^{(-\alpha ,\alpha )}_Nu\) into 3.32, we obtain from above equation that

$$\begin{aligned} \begin{aligned}&\Vert u-u_L\Vert ^2_{B^\alpha (D)}\le C\Vert u-\pi ^{(-\alpha ,\alpha )}_N \circ \pi ^hu\Vert ^2_{B^\alpha (D)}\\&\quad \lesssim \Vert {}_{0}D_{t}^{\alpha }(u-\pi ^{(-\alpha ,\alpha )}_N \circ \pi ^hu)\Vert ^2_{L^2(D)}+\Vert u-\pi ^{(-\alpha ,\alpha )}_N \circ \pi ^hu\Vert ^2_{L^2(I,H_{{\mathcal {L}}}(\Omega ))}:=I_1+I_2. \end{aligned} \end{aligned}$$
(3.33)

In view of this, taking \(s=0\) in (3.28), we conclude that

$$\begin{aligned} \begin{aligned} I_1&=\Vert {}_{0}D_{t}^{\alpha }(u-\pi ^{(-\alpha ,\alpha )}_N \circ \pi ^hu)\Vert ^2_{L^2(D)} \\&\lesssim \Vert {}_{0}D_{t}^{\alpha }\pi ^{(-\alpha ,\alpha )}_N (u-\pi ^hu)\Vert ^2_{L^2(D)}+\Vert {}_{0}D_{t}^{\alpha }(u-\pi ^{(-\alpha ,\alpha )}_N u)\Vert ^2_{L^2(D)} \\&\lesssim \Vert {}_{0}D_{t}^{\alpha } (u-\pi ^hu)\Vert ^2_{L^2(D)}+\Vert {}_{0}D_{t}^{\alpha }(u-\pi ^{(-\alpha ,\alpha )}_N u)\Vert ^2_{L^2(D)} \\&\lesssim N^{-2s}\Vert {}_{0}D_{t}^{\alpha +s}u\Vert ^2_{L^2_{\omega ^{(s,s)}}(I,L^2(\Omega ))}+\Vert {}_{0}D_{t}^{\alpha } (u-\pi ^hu)\Vert ^2_{L^2(D)}. \end{aligned} \end{aligned}$$

By (3.29), we treat the second term \(I_2\) as

$$\begin{aligned} \begin{aligned} I_2&= \Vert u-\pi ^{(-\alpha ,\alpha )}_N \circ \pi ^hu\Vert ^2_{L^2(I,H_{{\mathcal {L}}}(\Omega ))} \\&\lesssim \Vert \pi ^h(u-\pi ^{(-\alpha ,\alpha )}_N u)\Vert ^2_{L^2(I,H_{{\mathcal {L}}}(\Omega ))}+ \Vert u-\pi ^hu\Vert ^2_{L^2(I,H_{{\mathcal {L}}}(\Omega ))} \\&\lesssim \Vert u-\pi ^{(-\alpha ,\alpha )}_N u\Vert ^2_{L^2(I,H_{{\mathcal {L}}}(\Omega ))}+ \Vert u-\pi ^hu\Vert ^2_{L^2(I,H_{{\mathcal {L}}}(\Omega ))} \\&\lesssim N^{-2(\alpha +s)}\Vert {}_{0}D_{t}^{\alpha +s}u\Vert ^2_{L^2_{\omega ^{(s,s)}}(I,H_{{\mathcal {L}}}(\Omega ))}+\Vert u-\pi ^hu\Vert ^2_{L^2(I,H_{{\mathcal {L}}}(\Omega ))}. \end{aligned} \end{aligned}$$

A combination of the above estimates and Lemma 2.2 leads to the desired result. \(\square \)

3.4 Numerical Examples

We employ the Petrov–Galerkin method to the linear TFDEs to demonstrate the spatial and temporal convergence rates of the proposed algorithms.

Example 1

We first consider following linear TFDEs in rectangular domains

$$\begin{aligned}&{}^{C}_{0}D^{\alpha }_{t}u(\varvec{x},t)-\mathrm{div}(a(\varvec{x})\nabla u(\varvec{x},t))\nonumber \\&+\beta u(\varvec{x},t)=f(\varvec{x},t), \qquad \forall (\varvec{x},t)\in (-1,1)^2:= \Omega \times (0,T], \end{aligned}$$
(3.34)

with the exact solution \(u(x,y,t)=\sin (\pi x)\sin (\pi y)(t^{\alpha }\sin (\pi t)+1),\)\(a(x,y)=1\), and non-homogeneous initial conditions \(u_0(x,y)=\sin (\pi x)\sin (\pi y)\).

Without loss of generality, we use piecewise linear FEM for spatial discretization and GJFs Petrov–Galerkin method for temporal discretization. Let \({\mathcal {T}}_h=\{K\}\) be a uniformly regular family of rectangular in \((-1,1)^2\), and define the mesh size h. In Fig. 1, we list the maximum errors of (3.34), in log–log scale (or semi-log scale) at \(T=1\). We see from Fig. 1 (left) the proposed scheme has a second-order convergence rate in time. In Fig. 1 (right), we observe an exponential decrease of the numerical errors with increasing N and a level-off the error curves beyond \(N=8\), due to the saturation of spatial errors.

Fig. 1
figure 1

Left: the maximum error in log–log scale against various h and \(\alpha \) for Example 1 with \(M=20\); Right: the \(L^2(\Omega )\)-error in semi-log scale against various N and \(\alpha \) for Example 1 with \(h=1/90\)

Example 2

This example is devoted to comparing the numerical stability of algorithms in Sect. 3.2. To this end, we employ GJFs Petrov–Galerkin method in temporal discretization and Legendre spectral method in spatial discretization to resolve Example 1 numerically. In Fig. 2 (left), we compare the \(B^\alpha (D)\)-errors of algorithm I with algorithm III, for which we take \(M=40\). Notice that algorithms II and III give the same numerical result, so we prefer to use algorithm III in this example. We observe that for the \(N\le 10\) the numerical results from two algorithms are the same; but for \(N>10\), the algorithm III (or algorithm II) provides more accurate numerical results than algorithm I. This is because the eigen-decomposition is not stable for the nonsymmetric linear system, see Sect. 3.2. In Fig. 2 (right), we also list the \(B^\alpha (D)\)-errors, in semi-log scale, with \(N=40\). Although the exact solution has singularity at \(t=0\), but in the weighted Sobolev spaces \({\mathcal {B}}^s_{-\alpha ,\alpha }(I)\) which involving fractional derivatives, we have \(u|_t\in {\mathcal {B}}^s_{-\alpha ,\alpha }(I)\) for any large s. We observe that the numerical errors decay exponentially as M/N increases. We note in particular that very high accuracy is achieved with quite small M / N for this special problem.

Fig. 2
figure 2

Left: the \(B^\alpha (D)\)-error in semi-log scale against various N and \(\alpha \) for Example 2 with \(M=20\); Right: the \(B^\alpha (D)\)-error in semi-log scale against various M and \(\alpha \) for Example 2 with \(N=20\)

Example 3

We also consider Eq. (3.34) in rectangular domains with the exact solution \(u(x,y,t)=\sin (\pi x)\sin (\pi y)\cdot \sin (\pi t^{\alpha }),\)\(a(x,y)=\frac{x^2+y^2}{2},\) and the homogeneous initial conditions \(u_0(\varvec{x})=0\). Clearly, the singularity of the exact solution in time is more complicated than Example 1. Since we have

$$\begin{aligned} u|_t=\sin (\pi t^{\alpha })=t^\alpha -\frac{1}{3!}t^{3\alpha }+O(t^{5\alpha }). \end{aligned}$$
(3.35)

The GJFs can match the first leading singularity of the solution, then the convergence rate only depends on the second leading singularity of the solution. Here we take \(\alpha =0.8,\,0.6,\,0.4,\,0.2\). Then, we can derive from Theorem 3.1 and (3.35) that the corresponding convergence rate is \(N^{-4},N^{-3}, N^{-2}, N^{-1}\). In Fig. 3 (left) we plot the \(B^\alpha \)-errors in log–log scale against various N and \(\alpha \) with \(M=20\). We observe that the numerical results are consistent with theoretical results. We also list the \(B^\alpha \)-errors in semi-log scale against various M and \(\alpha \) with \(N=60\) in Fig. 3 (right). They indicate that the numerical errors decay exponentially as M increases, and numerical errors decay algebraically as N increases.

Fig. 3
figure 3

Left: the \(B^{\alpha }(D)\)-error in log–log scale against various N and \(\alpha \) for Example 3 with \(M=20\); Right: the \(B^{\alpha }(D)\)-error in semi-log scale against various M and \(\alpha \) for Example 3 with \(N=60\)

Fig. 4
figure 4

Left: the \(B^\alpha (D)\)-error in semi-log scale against various N and \(\alpha \) for Example 4 with \(M=40\); Right: the \(B^\alpha (D)\)-error in semi-log scale against various M and \(\alpha \) for Example 4 with \(N=20\)

Example 4

We consider TFDEs (3.34) in unit disk \(\Omega =\{x^2+y^2<1\}\) with the exact solution \(u(x,y,t)=(x^2+y^2-1)(\cos (8(x+y))+\sin (8(x+y)))\cdot t^{\alpha }\sin (\pi t),\)\(a(x,y)=1\), and homogeneous initial conditions \(u_0(x,y)=0\). In Fig. 4, we list the \(B^\alpha (D)\)-errors, in semi-log scale. We observe that the numerical errors decay exponentially as M/N increases. We note in particular that very high accuracy is achieved with quite small M / N for this special problem.

Example 5

We also consider Eq. (3.34) in unit disk \(\Omega =\{x^2+y^2<1\}\) with the exact solution \(u(x,y,t)=(x^2+y^2-1)(\cos (8(x+y))+\sin (8(x+y)))\cdot \sin (\pi t^{\alpha }),\)\(a(x,y)=1,\) and the homogeneous initial conditions \(u_0(\varvec{x})=0\). In Fig. 5 (left) the \(B^\alpha (D)\)-errors in log–log scale against various N and \(\alpha \) with \(M=20\) . We also list the \(B^\alpha (D)\)-errors in semi-log scale against various M and \(\alpha \) with \(N=60\) in Fig. 5 (right). We see that the numerical errors decay exponentially as M increases, and numerical errors decay algebraically as N increases.

Fig. 5
figure 5

Left: the \(B^\alpha \)-error in log–log scale against various N and \(\alpha \) for Example 5 with \(M=40\); Right: the \(B^\alpha \)-error in semi-log scale against various M and \(\alpha \) for Example 5 with \(N=60\)

Example 6

To eliminate the error of spatial direction, we also consider Eq. (3.34) in unit disk \(\Omega =\{x^2+y^2<1\}\) with the given right hand side term \(f(x,y,t)=(x^2+y^2-1)\), \(a(x,y)=1,\) and the homogeneous initial conditions. Since no exact solution is available, we use the numerical solution with \(M=50\), \(N=100\) and add three singular functions (see Sect. 4.2 for more detail) as the reference solution. In Fig. 6 (left) the \(B^\alpha (D)\)-errors in log–log scale against various N and \(\alpha \) with \(M=40\) . We observe that the numerical errors decay algebraically as M increases. Since the GJFs Petrov–Galerkin method only match the first leading singularity of the solution, then the second leading singularity are \(t^\nu =t^{0.8},t^{1.2},t^{1.6}\) with respect to \(\alpha =0.4,0.6,0.8\). We can derive from Theorem 3.2 that the convergence rate are \(N^{-1},N^{-2},N^{-2}\) respectively. Similarly, we plot the \(B^\alpha (D)\)-errors in log–log scale against various N and \(\alpha \) with \(M=40\) with \(f(x,y,t)=(x^2+y^2-1)\cdot \cos (\pi t)\) in Fig. 6 (right).

Fig. 6
figure 6

Left: the \(B^{\alpha }\)-error in log–log scale against various N and \(\alpha \) for Example 6 with \(M=40\); Right: the \(B^{\alpha }\)-error in semi-log scale against various N and \(\alpha \) for Example 6 with \(M=40\)

4 An Improved Algorithm with Enriched Approximation Space in Time

This section is devoted to the improved algorithm with enriched approximation space in time. We develop in this section an enriched Petrov–Galerkin method for TFDEs as well as the error estimate for the proposed method. Some numerical examples to illustrate the efficiency of our method are presented.

4.1 Algorithm

In order to introduce the enriched Petrov–Galerkin method for  (3.3), we first need the following basis function space for time variable

$$\begin{aligned} \begin{aligned}&{\mathcal {F}}_{N}^{(k,\alpha )}(I):=\mathrm{span}\{J_n^{-\alpha ,\alpha }(t)=t^\alpha {\widetilde{P}}^{-\alpha ,\alpha }_n(t):0\le n\le N\}\oplus \{\psi _i=t^{\nu _i},~i=1,\ldots ,k\}, \end{aligned} \end{aligned}$$
(4.1)

and in the test space, we take

$$\begin{aligned} \begin{aligned}&{\mathcal {P}}_{N+k}(I)=\mathrm{span}\Big \{L^{(\alpha )}_n(t):=\kappa _{n,\alpha }L_n(t):0\le n\le N+k\Big \}, \end{aligned} \end{aligned}$$
(4.2)

where \(\psi _i,~i=1,\ldots ,k\) are some known singular functions.

Remark 4.1

Although we can use the basis in (4.1) directly, due to the added basis \(\{\psi _i\}_{i=1}^k\) are not orthogonal to the original one \(\{J_n^{-\alpha ,\alpha }(t)\}_{n=0}^N\), which leads to ill-condition matrix. Moreover, the ill-condition will affect the accuracy of solving the linear system.

In order to make the implementation more efficient, it is strongly recommended to use following modified Gram–Schmidt process:

$$\begin{aligned} \varphi _n:=J_n^{-\alpha ,\alpha }(t)=t^\alpha {\widetilde{P}}^{-\alpha ,\alpha }_n(t),\qquad 0\le n\le N, \end{aligned}$$

and \(\varphi _{N+i},\)\(i=1,\ldots ,k\) can be computed as

$$\begin{aligned}&\varphi _{N+i}^{(0)}= t^{\nu _i}-\mathrm{proj}_{\varphi _0}(t^{\nu _i}),\nonumber \\&\varphi _{N+i}^{(1)}= \varphi _{N+i}^{(0)}-\mathrm{proj}_{\varphi _1}(\varphi _{N+i}^{(0)}),\nonumber \\&\qquad \quad \vdots \nonumber \\&\varphi _{N+i}^{(N+i-2)}= \varphi _{N+i}^{(N+i-3)}-\mathrm{proj}_{\varphi _{N+i-2}}(\varphi _{N+i}^{(N+i-3)}),\nonumber \\&\varphi _{N+i} = \varphi _{N+i}^{(N+i-2)}-\mathrm{proj}_{ \varphi _{N+i-1} }(\varphi _{N+i}^{(N+i-2)}), \end{aligned}$$
(4.3)

where

$$\begin{aligned} \mathrm{proj}_{u}(v)=\displaystyle \frac{(u,v)_{\omega ^{(-\alpha ,-\alpha )}}}{(u,u)_{\omega ^{(-\alpha ,-\alpha )}}}u. \end{aligned}$$

Then, the enriched Petrov–Galerkin method for (3.3) is to seek \(u^k_L(\varvec{x},t):=u^k_{MN}\in V_h\otimes {\mathcal {F}}_{N}^{(k,\alpha )}\), such that

$$\begin{aligned} ({}_{0}D^{\alpha }_{t}u^k_L,v)_{L^2(D)}+ b(u^k_L,v)+\beta (u^k_L, v)_{L^2(D)}=(f,v)_{L^2(D)}, \qquad \forall v\in V_h\otimes {\mathcal {P}}_{N+k}. \end{aligned}$$
(4.4)

We now describe the numerical implementations for  (4.4) under this set of basis functions. We write

$$\begin{aligned} u^k_L(\varvec{x},t)=\displaystyle \sum ^{M}_{m=1}\displaystyle \sum ^{N+k}_{n=0}{\widetilde{u}}_{mn}\phi _{m}(\varvec{x})\varphi _n(t). \end{aligned}$$
(4.5)

Denote

$$\begin{aligned} \begin{aligned}&f^{en}_{mn}=(f,\phi _m(\varvec{x})L_n^{(\alpha )}(t))_D,\qquad F^{en}=(f^{en}_{mn})_{1\le m\le M,0\le n\le N+k}, \\&s^{en}_{pq}=\displaystyle \int _I{}_{0}D^{\alpha }_{t}\varphi _{q}(t)L_p^{(\alpha )}(t)dt,\qquad m^{en}_{pq}=\displaystyle \int _I\varphi _{q}(t)L_p^{(\alpha )}(t)dt,\qquad \\&\varvec{S}^{en}=(s^{en}_{pq})_{0\le p,q\le N+k},\qquad \varvec{M}^{en}=(m^{en}_{pq})_{0\le p,q\le N+k}, \\&U=({\widetilde{u}}_{mn})_{1\le m\le M,0\le n\le N+k}. \end{aligned} \end{aligned}$$

Then, from (3.2), we find that (4.4) is equivalent to the following linear system:

$$\begin{aligned} \varvec{M}^h\,U(\varvec{S}^{en})^T+\varvec{S}^h\,U(\varvec{M}^{en})^T+\beta \varvec{M}^h\,U (\varvec{M}^{en})^T=F^{en}. \end{aligned}$$
(4.6)

Then, we can use Algorithm II or Algorithm III [cf. Sect. (3)] to resolve linear system 4.6.

In Table 3, we tabulate the maximum error of \((\varvec{S}^{en}\varvec{E})^{-1}\varvec{M}^{en}\varvec{E}-\Lambda \) (resp. \(\max \{|\varvec{Q}^T\,\varvec{A}\varvec{Z}^T -\varvec{S}^{en}|,| \varvec{Q}^T\,\varvec{B}\varvec{Z}^T -\varvec{M}^{en}|\}\)) for eigen-decomposition (resp. QZ decomposition) in (4.6) with various N, which indicate that error of eigen decomposition is grow as N increases. We observe similar behaviors as in Sect. 3.2 that the QZ decomposition is much more stable than eigen decomposition for the nonsymmetric enriched matrices.

Table 3 A comparison of decomposition error between eigen and QZ decomposition

4.2 Error Analysis

In this subsection, we shall restrict our attention to the linear case (3.3) with \({\mathcal {L}}=-\Delta \). To this end, we begin with the representation of the solution of (3.3). Let us consider the following eigenvalue problem

$$\begin{aligned}\begin{aligned} {\mathcal {L}}\,\varphi =\lambda \varphi \quad \text {in}\;\Omega , \end{aligned} \end{aligned}$$

where \(\varphi \) satisfy the homogeneous boundary condition, and it admits a nondecreasing sequence \(\{\lambda _j\}^\infty _{j=1}\) of positive eigenvalues and the eigenfunctions \(\{\varphi _j\}^\infty _{j=1}\) forms an orthonormal basis in \(L^2(\Omega )\). Then, the solution of (3.3) can be expressed as (see e.g., [26])

$$\begin{aligned} u(x, t)=\sum _{n=1}^{\infty } \int _{0}^{t} s^{\alpha -1} E_{\alpha , \alpha }(-(\lambda _{n}+\beta )s^{\alpha }) (f(\cdot ,t-s), \varphi _{n})_{L^2(\Omega )} \varphi _{n}(x)\mathrm{d} s, \end{aligned}$$
(4.7)

where \(E_{a, b}(z)\) denotes the two-parameter Mittag–Leffler function:

$$\begin{aligned} E_{a, b}(z)=\sum _{j=0}^{\infty } \frac{z^{j}}{\Gamma (a j+b)}, \quad z \in \mathbb {C}, a>0, b \in \mathbb {R}. \end{aligned}$$

Denote by \(k\in \mathbb {N}\) the number of elements contained in the set

$$\begin{aligned} \begin{array}{ll}&I(k;\alpha ):=\{(i,j):i,j\in \mathbb {N}_0,i+j\alpha <\overline{k}\},\quad \overline{k}\in \mathbb {N}. \end{array} \end{aligned}$$
(4.8)

For any given right hand side \(f\in C^{\overline{k}}(I;L^2(\Omega ))\) in (3.3), we can easily get the singularity of the solution in t-direction. More precisely, for any k, the solution of (4.7) in t-direction can be rewritten as

$$\begin{aligned} u|_{t}=\displaystyle \sum _{I(k;\alpha )} \gamma _{ij}^\alpha t^{i+j\alpha }+{{\widetilde{u}}}^k(t),\quad t\in I, \end{aligned}$$

where the coefficients \(\gamma _{i,j}^\alpha \) are dependent on ij and \(\alpha .\) Let the leading singularity of \({{\widetilde{u}}}^k(t)\) be \(t^{\nu +\overline{k}-1},\) with \(\nu \in (0,1]\). Clearly, the singularity of our approximation space is \(A(k;\alpha )=\{i\in \mathbb {N}_0,i+\alpha <\overline{k}\},~\overline{k}\in \mathbb {N}\), so the rest part of the singularity is given by

$$\begin{aligned} R(k;\alpha ):=I(k;\alpha )/A(k;\alpha )=\{(i,j):i,j\in \mathbb {N}_0,i+j\alpha <\overline{k},j\ne 1\},\quad \overline{k}\in \mathbb {N}. \end{aligned}$$
(4.9)

where \(k\in \mathbb {N}\) denote the number of elements contained in \(R(k;\alpha )\) or \(A(k;\alpha )\).

Following the same procedure in Petrov–Galerkin spectral method, we arrive at

$$\begin{aligned} \Vert u-u^k_L\Vert _{B^\alpha (D)}\lesssim \inf _{v|_t\in {\mathcal {F}}_{N}^{(k,\alpha )}}\Vert v-u\Vert _{B^\alpha (D)}+\inf _{v|_x\in V_h}\Vert v-u\Vert _{B^\alpha (D)}. \end{aligned}$$

To this end, we assume that

$$\begin{aligned} u(\cdot ,t)={\widetilde{u}}^k(\cdot ,t)+\displaystyle \sum _{I(k;\alpha )}\gamma ^\alpha _{ij}t^{i+j\alpha } ={\widetilde{u}}^k(\cdot ,t)+\displaystyle \sum _{i=1}^ku^s_i\psi _i(t), \end{aligned}$$
(4.10)

then, we take

$$\begin{aligned} v|_t=\pi ^{-\alpha ,\alpha }_N{\widetilde{u}}^k(\cdot ,t)+\displaystyle \sum _{i=1}^ku^s_i\psi _i(t) \end{aligned}$$

and by applying Theorem 3.2 we have

$$\begin{aligned} \Vert v-u\Vert _{B^\alpha (D)}\lesssim N^{-s}\Vert {}_{0}D_{t}^{\alpha +s}{\widetilde{u}}^k\Vert _{L^2_{\omega ^{(s,s)}}(I,H_{{\mathcal {L}}}(\Omega ))}+\inf _{v|_x\in V_h}\Vert u-v\Vert _{B^\alpha (D)}. \end{aligned}$$

Theorem 4.1

Let u be the solution of (3.3) and \(u^k_L\) be the numerical solution (4.4). Assume (4.10) holds and the leading singularity of \({\widetilde{u}}^k|_t\) near \(t=0\) is \(t^{\nu +\overline{k}-1}\) with \(\nu \in (0,1]\) and \(\overline{k}\) is defined in (4.8). If \(u\in B^\alpha (D)\) and \({}_{0}D_{t}^{\alpha +m}{\widetilde{u}}^k\in L^2_{\omega ^{(m,m)}}(I,H_{{\mathcal {L}}}(\Omega ))\), there holds

$$\begin{aligned} \Vert u-u^k_L\Vert _{B^\alpha (D)}\lesssim N^{-m}\Vert {}_{0}D_{t}^{\alpha +m}{\widetilde{u}}^k\Vert _{L^2_{\omega ^{(m,m)}}(I,H_{{\mathcal {L}}}(\Omega ))}+\inf _{v_L|_x\in V_h}\Vert u-v_L\Vert _{B^\alpha (D)}, \end{aligned}$$
(4.11)

where the convergence index \(m\in \mathbb {N}\) satisfy

  • for \(\nu -\alpha \in (-1,-\frac{1}{2}]\),    we have    \(m=2\overline{k}-3\),with  \(\overline{k}\ge 2\);

  • for \(\nu -\alpha \in (-\frac{1}{2},0]\),    we have    \(m=2\overline{k}-2\), with \(\overline{k}\ge 2\);

  • for \(\nu -\alpha \in (0,\frac{1}{2}]\) ,    we have    \(m=2\overline{k}-1\), with \(\overline{k}\ge 1\);

  • for \(\nu -\alpha \in (\frac{1}{2},1]\),    we have    \(m=2\overline{k}\), with \(\overline{k}\ge 1\);

Proof

Since the leading singularity of \({\widetilde{u}}^k|_{t}\) is \(t^{\nu +\overline{k}-1}\), \(\nu \in (0,1]\), which imply \(\nu -\alpha \in (-\alpha ,1-\alpha ]\). According to Lemma 3.1 and Theorem 3.2, we only need to consider

$$\begin{aligned} \begin{aligned}&\Vert {}_{0}D_{t}^{\alpha +m}t^{\nu +\overline{k}-1}\Vert _{L^2_{\omega ^{(m,m)}}(I)}\approx \int _I \left( t^{\nu -\alpha +\overline{k}-m-1}\right) ^2 t^m dt<\infty , \\&\Vert {}_{0}D_{t}^{\alpha +m+1}t^{\nu +\overline{k}-1}\Vert _{L^2_{\omega ^{(m+1,m+1)}}(I)}\approx \int _I \left( t^{\nu -\alpha +\overline{k}-m-2}\right) ^2 t^{m+1} dt=\infty , \end{aligned} \end{aligned}$$
(4.12)

or equivalently,

$$\begin{aligned} \begin{aligned}&2\nu -2\alpha +2\overline{k}-m-2>-1\Rightarrow 2\nu -2\alpha +2\overline{k}-m>1, \\&2\nu -2\alpha +2\overline{k}-m-2\le -1\Rightarrow 2\nu -2\alpha +2\overline{k}-m\le 2. \end{aligned} \end{aligned}$$
(4.13)

To determine the value of \(m\ge 0\), by fact that \(\overline{k}\ge 1\) and a direct computation from (4.13) gives

  • For \(\nu -\alpha \in (-1,-\frac{1}{2}]\) (or \(2(\nu -\alpha )\in (-2,-1]\)), we obtain that \(m=2\overline{k}-3\), namely,

    $$\begin{aligned} \begin{array}{ll} \mathrm{If} \;\overline{k}=2,3,4,5,\ldots \quad , \quad \mathrm{we~have}~ m=1,3,5,7\ldots . \end{array} \end{aligned}$$
  • For \(\nu -\alpha \in (-\frac{1}{2},0]\) (or \(2(\nu -\alpha )\in (-1,0]\)), we obtain that \(m=2\overline{k}-2\), namely,

    $$\begin{aligned} \begin{array}{ll} \mathrm{If} \;\overline{k}=1,2,3,4,\ldots ,\quad \mathrm{we ~have}~m=0,2,4,6,\ldots . \end{array} \end{aligned}$$
  • For \(\nu -\alpha \in (0,\frac{1}{2}]\) (or \(2(\nu -\alpha )\in (0,1]\)), we obtain that \(m=2\overline{k}-1\), namely,

    $$\begin{aligned} \begin{array}{ll} \mathrm{If} \;\overline{k}=1,2,3,4,\ldots ,\quad \mathrm{we ~have}~m=1,3,5,7\ldots . \end{array} \end{aligned}$$
  • For \(\nu -\alpha \in (\frac{1}{2},1]\) (or \(2(\nu -\alpha )\in (1,2]\)), we obtain that \(m=2\overline{k}\), namely,

    $$\begin{aligned} \begin{array}{ll} \mathrm{If} \;\overline{k}=1,2,3,4,\ldots ,\quad \mathrm{we ~have}~m=2,4,6,8, \ldots . \end{array} \end{aligned}$$

Note that in the case \(\nu -\alpha \in (-\frac{1}{2},0]\): when \(m=0,\) we got \(\alpha >\nu +\overline{k}-1\) in (4.12), but this is not true. Hence, we have \(m\ge 2\) in the case \(\nu -\alpha \in (-\frac{1}{2},0]\). A combination of the above estimates leads to the desired result. \(\square \)

4.3 Numerical Results

In order to ignore the error in spatial direction, we consider TFDEs  (3.34) in 1D with a given source function \(f(x,t)=\sin (\pi x)\cdot \cos (\pi t),\)\(a(x)=\frac{x^2}{2}\) and homogeneous initial conditions. In this example, we use improved algorithm to reslove (3.34) numerically. More specifically, we can take the first k-th singular term \(t^{\nu _j}\) in \(R(k;\alpha )=\{t^{i+j\alpha }, ~i,j\in \mathbb {N}_0,i+j\alpha <\overline{k},j\ne 1\}.\) The exact solution is unknown, we compute a numerical solution with \(M=40\), \(N=100\) and \(k=4\) as the exact solution. In Fig. 7 , we list the Max-errors in log–log scale against various N, k and \(\alpha \) with \(M=30\). They indicate that the enriched Petrov–Galerkin method is better than the Petrov–Galerkin method, and the numerical errors decay algebraically.

Fig. 7
figure 7

Left: the Max-error in log–log scale against various N and \(\alpha \) for Example 6 with \(M=30\); Right: the Max-error in semi-log scale against various M and \(\alpha \) for Example 6 with \(M=30\)

5 Numerical Results for Nonlinear Problems

In this section, we shall present some numerical results obtained by the proposed methods introduced in Sect. 3 for nonlinear problem.

Example 5.1

Consider the following time fractional Burgers equation in 1D:

$$\begin{aligned} ^C_{0}D^{\alpha }_{t}u(x,t)-\gamma \Delta u(x,t)+\partial _x\Big (\frac{1}{2}u^2(x,t)\Big )=0, \qquad \forall (x,t)\in D, \end{aligned}$$
(5.1)

with the initial data \(u_0(x)=-\sin (\pi x)\).

We initially solved this problem by using the preconditioned Jacobian-free Newton-Krylov method. To accelerate the convergence, we employed a two-grid approach. Namely, we use \({\widetilde{N}}\approx N/2\) and \(M\approx M/2\) as the initial data for the iteration the coarse approximation solution with N for the fine approximation solution with N and M. This two-grid approach significantly improved the convergence, only less than 10 iterations are needed to achieve \(10^{-7}\)-digit accuracy.

We plots in Fig. 8a the numerical solution with \(M=100,\)\(N=80,\)\(\alpha =0.7,\)\(\gamma =0.01\) at \(t = 0, ~0.25,~0.5,~0.75,~1\). We observe that, similar to the usual Burgers equation, the profile of solution become steeper as t increases to about \(t = 0.25\), and the solution start to relax towards zero for \(t > 0.25\). To investigate the influence of \(\alpha \) on the solution, we plot the numerical solution with \(\gamma = 0.01, N = 64, M = 100\) at \(t =1\) for various \(\alpha \) in Fig. 8b. As a comparison, we also plot the solution with \(\alpha =1\), i.e., the usual Burgers equation. We observe that, as \(\alpha \) increases, the profile of the solution becomes steeper and dissipates faster.

Fig. 8
figure 8

a The numerical solution with \(\alpha =0.7\), \(\gamma =0.01\), \(N=80\), \(M=100\) against various t; b The numerical solution with \(\gamma =0.01\), \(N=80\), \(M=100\) at \(t=1\) against various \(\alpha \)

Example 5.2

Consider the following time fractional Allen–Cahn equation in 1D:

$$\begin{aligned} ^C_{0}D^{\alpha }_{t}u(x,t)-\epsilon ^2 \Delta u(x,t)+ f(u(x,t))=0, \qquad \forall (x,t)\in D, \end{aligned}$$
(5.2)

with the initial data

$$\begin{aligned} u_0(x)=\left\{ \begin{array}{ll} 1,\qquad &{} 0\le x\le 1,\\ -1, &{} -1\le x<0, \end{array}\right. \end{aligned}$$
(5.3)

and homogeneous Neumann boundary conditions

$$\begin{aligned} \frac{\partial u}{\partial n}|_{\partial \Omega }=0. \end{aligned}$$

In the above, \(f(u)=(u^2-1)u=F^\prime (u)\) is the usual double-well potential, \(\Omega \) is the bounded domain and n is the outward normal. The parameters we use in the following presentation is \(\epsilon =0.1\).

We also employed a two-grid approach (see Example 5.1) to resolve (5.2). Note that in this example, only less than 12 iterations are needed to achieve \(10^{-7}\)-digit accuracy. We plots in Fig. 9a the numerical solution with \(M=250,\)\(N=80,\)\(\alpha =0.7,\)\(\epsilon =0.1\) at \(t = 0, ~0.5,~1,~1.5,~2\). We observe that the relaxation process as t increases is similar to the usual Allen–Cahn equation.

To further investigate the influence of \(\alpha \) on the solution, we plot the numerical solution with \(\epsilon = 0.1, N = 80, M = 250\) at \(t =1\) for various \(\alpha \) in Fig. 8b. As a comparison, we also plot the solution with \(\alpha =1\), i.e., the usual Allen–Cahn equation. We observe that, as \(\alpha \) decreases, the speed of profile relaxation also decreases.

Fig. 9
figure 9

a The numerical solution with \(\alpha =0.7\), \(\epsilon =0.1\), \(N=64\), \(M=250\) against various t; b The numerical solution with \(\epsilon =0.1\), \(N=64\), \(M=250\) at \(t=1\) against various \(\alpha \)

6 Concluding Remarks

We developed an efficient Petrov–Galerkin spectral method for linear/nonlinear TFDEs. The proposed method employs an enriched Petrov–Galerkin method for time discretization and can be coupled with any consistent Galerkin type discretization in space. The main contributions of this paper are: (i) a novel and efficient matrix diagonalization method based on QZ decomposition is introduced to solve the space–time linear system directly; (ii) an enriched Petrov–Galerkin method which significantly improves the accuracy in time; and (iii) rigorous error analysis for the space–time Petrov–Galerkin method with and without additional enriched basis functions.