## 1 Introduction

Conservation laws play an important role in modeling and understanding physical processes. For example, conservation of mass, energy, and momentum are fundamental principles in gas and fluid dynamics. For ideal flow, these principles are modeled using the well-known system of Euler equations. Despite a long history and extensive research in understanding and solving Euler equations, many important mathematical and numerical questions remain unsolved. Especially for high-speed flows (higher than the speed of sound), solutions to the Euler system lose their regularity and many complex phenomena such as shocks, strong discontinuities, rarefaction, and contact waves develop. Besides, at very high temperature and energy gas transforms into plasma. Plasma is an ionized gas and the dynamic of plasmas is modeled by adding additional terms and equations involving the magnetic field $${\varvec{B}}$$ into the Euler system. This resulting system is usually referred to as Magnetohydrodynamics or MHD in short.

Numerical approximation of MHD started as soon as researchers started to simulate the Euler equations, see [1, 2]. Existing numerical methods for compressible Euler equations are hard to extend to approximate the MHD system. If one reason is solving d-additional equations, where d is the space dimension, other two main reasons are (i) developing high order robust shock-capturing techniques, (ii) satisfying the divergence-free constraint for the magnetic field, i.e., $$\nabla {\cdot \,}{\varvec{B}}= 0$$. State-of-the-art numerical methods to solve the MHD equations are finite differences, finite volumes, and discontinuous Galerkin (DG) schemes. Most of the finite difference and finite volume schemes are based on approximate solutions to the Riemann problem of MHD, see for instance [3,4,5,6,7,8,9] and references therein. Due to similarities of finite volume and DG schemes, an approximate Riemann solver approach was incorporated in the Galerkin variational formulation for the DG schemes, see e.g., [10,11,12]. In general, the exact or approximate Riemann solvers are difficult to compute. Especially, the MHD system is not strictly hyperbolic and has a non-convex flux, and therefore it may admit non-regular waves which may result in non-unique Riemann solution [13]. To overcome this difficulty, numerical methods that do not use Riemann solvers have been developed. For instance central DG schemes reported in [14,15,16] approximate the MHD solutions without using any approximate or exact Riemann solvers.

The success of finite volume and DG schemes has not been observed in a continuous finite element (FE) framework. A reason for it could be the lack of high order, robust explicit stabilization techniques to stabilize continuous FE approximations of MHD. Traditional stabilization methods for FE approximations of conservation laws including Euler and MHD equations are based on the Galerkin-Least-Squares argument (GLS) augmented with residual-based shock-capturing terms, see for instance [17, 18] and references therein. GLS schemes are implicit by construction, difficult to make high order in time, and nontrivial to implement since the test functions are required to be time-dependent. Only a few works were done to simulate resistive MHD using GLS stabilization, see for instance [19,20,21] and references therein.

It appears that a way of constructing a high-order explicit FE approximation of conservation laws could be by entirely disregarding the GLS terms from the stabilized formulation. Recently, [22,23,24,25] proposed the so-called entropy viscosity method, where the FE approximation is stabilized by adding an elliptic term, and the artificial viscosity coefficient is constructed to be proportional to an entropy residual of the system. For scalar conservation laws, the FE residual is one of the entropy residuals. Therefore, the residual-based artificial viscosity method can be obtained by disregarding the GLS terms in the stabilization method of [17]. In [26], we proved that the FE approximation of residual-based artificial viscosity method applied to scalar conservation laws converges to the unique entropy solution, and we extended the method to solve more general systems in the framework of DG, spectral elements, finite differences, and radial basis functions (RBF), see e.g., [27,28,29,30,31]. For other approaches to constructing the nonlinear artificial viscosity methods, we refer to the work of [32,33,34], where the stabilization is constructed based on a smoothness indicator of the solution.

In this work, we propose a new residual-based shock-capturing method for FE approximation of the MHD system. The method is explicit in time and works for high order polynomial degrees. The divergence-free constraint is obtained using several techniques, including the projection of $${\varvec{B}}$$ into a divergence-free space [35] and the hyperbolic cleaning [36]. We should emphasize that positivity and invariant domain preservation of the method as in [37] is left beyond the scope of this paper.

The paper is organized as follows: in Sect. 2, we introduce important notations and terms that are used in the paper, such as FE spaces, meshes, and matrices. In Sect. 3, we introduce the ideal MHD equations, eigenvalues, and the divergence cleaning techniques. In Sect. 4, we present a viscous regularization of the MHD equations using a novel residual-based shock-capturing method. Finally, in Sect. 5, we solve several well-known benchmark problems for ideal MHD. The results show that the viscosity method does not change the convergence orders of the base scheme for smooth problems while being able to capture discontinuous solutions in the non-smooth tests. Section 6 is the conclusion.

## 2 Continuous Galerkin Finite Element Method

In this section, we introduce the finite element spaces and notations that are used in this work.

Let us consider an open bounded domain $$\Omega \subset {{\mathbb {R}}}^d$$, $$d=1,2,3$$ with boundary $$\Gamma$$. We denote $${{\mathcal {T}}}_h$$ a finite partition of $$\Omega$$ into disjoint elements K such that no vertex of any element is placed on the interior of an edge of another element. The union of all the closure of elements K constitutes $${\overline{\Omega }}$$, where $${\overline{\Omega }}$$ denotes the closure of $$\Omega$$.

We seek finite element solution in Lagrange polynomial spaces

\begin{aligned} {{\mathcal {Q}}}_h = \{v(x): v \in {{\mathcal {C}}}^0(\Omega ), v\vert _K \in {{\mathbb {P}}}_k,\;\forall K \in {{\mathcal {T}}}_h\}, \end{aligned}
(2.1)

where $${{\mathbb {P}}}_k$$ is a space of polynomials of at most k degrees. Let $$\Phi _i$$ be the k-degree Lagrange basis function in $${{\mathcal {Q}}}_h$$ which takes value 1 at node i, and 0 at any other nodes. The node distribution is uniform as in conventional continuous FE methods. The functions $$\{\Phi _i\}_{i=1}^{N_h}$$ form a basis for $${{\mathcal {Q}}}_h$$, where $$N_h$$ is the total number of nodes in $${{\mathcal {Q}}}_h$$. We define $${{\mathcal {I}}}(i)$$ the set of all nodal points contained within the support of $$\Phi _i$$. Furthermore, we use the following Hilbert space inner products,

\begin{aligned} (v,w) = \int _{\Omega } vw\,\mathrm {d}x, \quad (\nabla v, \nabla w) = \int _{\Omega } \sum _{i=1}^d \frac{{\partial }v}{{\partial }x_i}\frac{{\partial }w}{{\partial }x_i} \,\mathrm {d}x. \end{aligned}

We will use a mesh-function $$h_h({\varvec{x}})\in {{\mathcal {Q}}}_h$$ which we compute using the following projection: find $$h_h({\varvec{x}})\in {{\mathcal {Q}}}_h$$ such that

\begin{aligned} \sum _{K\in {{\mathcal {T}}}_h} \int _K h_h v \,\mathrm {d}{\varvec{x}}= \sum _{K\in {{\mathcal {T}}}_h} \int _K \frac{h_K}{k} v \,\mathrm {d}{\varvec{x}}, \quad \forall v\in {{\mathcal {Q}}}_h, \end{aligned}
(2.2)

where $$h_K$$ is the circumradius of the element K.

## 3 Governing Equations of MHD

Let us denote the time interval $$[0, {\widehat{t}} \,\,]$$, where $${\widehat{t}}$$ is the final time. For all $$({\varvec{x}},t) \in D:= \Omega \times [0,{\widehat{t}} \,\,]$$, we seek solution of the MHD equations $${{\mathbf {\mathsf{{{U}}}}}}:=(\rho , {\varvec{m}}, E, {\varvec{B}}),\;\rho , E: D\rightarrow {{\mathbb {R}}}$$, $${\varvec{m}},{\varvec{B}}:D\rightarrow {{\mathbb {R}}}^d$$, where $$\rho$$ is the mass density, $${\varvec{m}}$$ is the momentum, E is the total energy, $${\varvec{B}}$$ is the magnetic field. The ideal MHD equations in conservative form with appropriate boundary conditions are defined as follows:

\begin{aligned} {\partial }_t {{\mathbf {\mathsf{{{U}}}}}}+ \nabla {\cdot \,}{{\mathbf {\mathsf{{{F}}}}}}_{{{\mathcal {E}}}}({{\mathbf {\mathsf{{{U}}}}}}) + \nabla {\cdot \,}{{\mathbf {\mathsf{{{F}}}}}}_{{{\mathcal {B}}}}({{\mathbf {\mathsf{{{U}}}}}}) = 0, \end{aligned}
(3.1)

where the nonlinear tensor fluxes $${{\mathbf {\mathsf{{{F}}}}}}_{{{\mathcal {E}}}}({{\mathbf {\mathsf{{{U}}}}}}), {{\mathbf {\mathsf{{{F}}}}}}_{{{\mathcal {B}}}}({{\mathbf {\mathsf{{{U}}}}}})$$ are defined as

\begin{aligned} {{\mathbf {\mathsf{{{F}}}}}}_{{{\mathcal {E}}}}:= \begin{pmatrix} {\varvec{m}}\\ {\varvec{m}}\otimes {\varvec{u}}+ p{{\mathbb {I}}}\\ {\varvec{u}}(E+p) \\ 0 \end{pmatrix}, \quad {{\mathbf {\mathsf{{{F}}}}}}_{{{\mathcal {B}}}}:= \begin{pmatrix} 0 \\ -{\varvec{\beta }}\\ -{\varvec{u}}{\cdot }{\varvec{\beta }}\\ {\varvec{u}}\otimes {\varvec{B}}- {\varvec{B}}\otimes {\varvec{u}}\\ \end{pmatrix}, \end{aligned}
(3.2)

with $${\varvec{u}}:={\varvec{m}}/ \rho$$ being the velocity field, and $${\varvec{\beta }}$$ being the Maxwell stress tensor:

\begin{aligned} {\varvec{\beta }}= \Big ( -\frac{1}{2}({\varvec{B}}{\cdot }{\varvec{B}}){{\mathbb {I}}}+ {\varvec{B}}\otimes {\varvec{B}}\Big ), \end{aligned}

where $${{\mathbb {I}}}$$ denotes the identity matrix of size $$d\times d$$. The combination of hydrodynamics and electromagnetism nature of the MHD system can be seen from the MHD equations in the form of (3.1), through the separated fluxes $${{\mathbf {\mathsf{{{F}}}}}}_{{{\mathcal {E}}}}({{\mathbf {\mathsf{{{U}}}}}})$$ and $${{\mathbf {\mathsf{{{F}}}}}}_{{{\mathcal {B}}}}({{\mathbf {\mathsf{{{U}}}}}})$$. The thermodynamic pressure p is computed from the equation of state

\begin{aligned} p = (\gamma -1) e, \end{aligned}
(3.3)

where e is the internal energy and $$\gamma$$ is the adiabatic gas constant. The internal energy is computed as

\begin{aligned} e = E - \frac{1}{2} \rho ({\varvec{u}}{\cdot }{\varvec{u}}) - \frac{1}{2} ({\varvec{B}}{\cdot }{\varvec{B}}). \end{aligned}
(3.4)

In addition, the magnetic field should satisfy the following divergence free constraint:

\begin{aligned} \nabla {\cdot \,}{\varvec{B}}= 0. \end{aligned}
(3.5)

Note that the above equations are in non-dimensional form, as suggested by [20, Sec. 3.1].

### 3.1 Eigenvalues of the Inviscid MHD

We are going to use the maximum wave speeds to construct our stabilization terms. A good approximation of the local wave speeds is obtained by eigenvalues of the inviscid MHD equations. It is well-known that eight eigenvalues are corresponding to the eight elementary waves for the ideal MHD equations, see e.g., [4, 38, 39]: let $${\varvec{e}}\in {{\mathbb {R}}}^d$$ be a direction vector, $$a:=(\gamma p/\rho )^{\frac{1}{2}}$$ be the speed of sound, $$c_{a} := {\varvec{B}}{\cdot }{\varvec{e}}/\rho ^\frac{1}{2}$$ and

\begin{aligned} c_{f,s}^2 = \frac{1}{2} \left( a^2 + \frac{{\varvec{B}}{\cdot }{\varvec{B}}}{\rho } \right) \pm \frac{1}{2} \left( \left( a^2 + \frac{{\varvec{B}}{\cdot }{\varvec{B}}}{\rho } \right) ^2 - 4a^2 {c_a}^2 \right) ^\frac{1}{2}. \end{aligned}

The eigenvalues from the smallest to the largest are

\begin{aligned} \lambda _{1,8} = {\varvec{u}}{\cdot }{\varvec{e}}\mp c_{f}, \quad \lambda _{2,7} = {\varvec{u}}{\cdot }{\varvec{e}}\mp {c_{a}}, \quad \lambda _{3,6} = {\varvec{u}}{\cdot }{\varvec{e}}\mp c_{s}, \quad \lambda _{4,5} = {\varvec{u}}{\cdot }{\varvec{e}}, \end{aligned}
(3.6)

where the subscripts $$_{f}$$, $$_{s}$$, and $$_{a}$$ correspond to fast and slow magnetosonic waves, and the Alfén waves. The characteristics $$\lambda _{4,5}$$ correspond to entropy and divergence waves. It is clear to see that the first and eighth eigenvalues are the ones of interest, which represent the fastest moving waves. Later in Sect. 4, we will use the maximum wave speed

\begin{aligned} \lambda _{\max } := \max _{i = 1,\ldots ,8} \vert \lambda _i \vert \end{aligned}

in the construction of the nonlinear viscosity term.

### 3.2 Divergence Cleaning Techniques

To satisfy the magnetic divergence-free condition (3.5), we have verified that our proposed nonlinear stabilization can be used along with popular techniques for divergence cleaning: the elliptic correction/projection method by [35], and the hyperbolic correction by [36, 40]. A numerical comparison between the mentioned techniques is included in Sect. 5.3.

#### 3.2.1 Elliptic Correction/Projection Method

In each time step, instead of using the magnetic solution $${\varvec{B}}$$ from the system, $${\varvec{B}}'$$ the projection of $${\varvec{B}}$$ onto a magnetic divergence-free space is used. [35] proposed using

\begin{aligned} {\varvec{B}}'={\varvec{B}}-\nabla \Psi _p, \end{aligned}

where $$\Psi _p$$ is the solution to the Poisson equation

\begin{aligned} \nabla ^2\Psi _p - \nabla {\cdot \,}{\varvec{B}}=0. \end{aligned}
(3.7)

This yields $$\nabla {\cdot \,}{\varvec{B}}' = 0$$ as the non-physical part $$\nabla \Psi _p$$ is removed from the numerical solution $${\varvec{B}}$$. After each correction in the magnetic field $${\varvec{B}}$$, the dependent variables: pressure p, temperature T, energy E, and the entropy functions are updated accordingly to ensure consistency of the discrete solution. Contrary to the seemingly ad-hoc nature of this method, [41] shows that the projection method preserves conservative properties and accuracy of the base scheme.

Pseudo time-stepping Numerically minimizing $$\vert \nabla {\cdot \,}{\varvec{B}}'\vert$$ by the projection method is considered computationally expensive. A more affordable alternative, proposed by [42], is solving the following time-dependent equation for $$\Psi _p$$,

\begin{aligned} \partial _{{\widetilde{t}}}\Psi _p-\nabla ^2\Psi _p + \nabla {\cdot \,}{\varvec{B}}= 0, \end{aligned}
(3.8)

where the variable $${{\widetilde{t}}}$$ is a separate time dimension. At equilibrium, the solution to (3.8) is the one to the Poisson equation. A semi-discretization of (3.8) is given by

\begin{aligned} \frac{\Psi _p^{\ell +1}-\Psi _p^{\ell }}{{\widetilde{\tau }}}-\nabla ^2\Psi _p^{\ell +1} + \nabla {\cdot \,}{\varvec{B}}^{\ell } = 0,\quad \ell =0,1,2,\dots , \end{aligned}

where $${\widetilde{\tau }}$$ is the pseudo step size. After each pseudo time step, the magnetic solution $${\varvec{B}}$$ is corrected $${\varvec{B}}^{\ell +1}={\varvec{B}}^{\ell }-\nabla \Psi _p^{\ell +1}$$. The divergence $$\nabla {\cdot \,}{\varvec{B}}'$$ is gradually decreased. One can think of this technique as an iterative method for solving the Poisson equation (3.7). The computational cost depends on how many pseudo steps are performed. Since the divergence error is not necessarily exactly zero, normally a few pseudo steps are sufficient.

#### 3.2.2 Hyperbolic Correction

An auxiliary scalar variable $$\Psi _l$$ is added to the system to transport and suppress the divergence violation on the magnetic field. We add a fifth equation to the MHD system

\begin{aligned} \partial _t\Psi _l + c_h \nabla {\cdot \,}{\varvec{B}}= - \frac{c_rc_h}{h_h}\Psi _l, \end{aligned}

where $$c_r = 0.3$$ in 2D or $$c_r = 1.0$$ in 3D [40], and $$h_h({\varvec{x}})$$ denotes the mesh function computed in (2.2). The coefficient $$c_h$$ is set to be the maximum wave speed $$c_h$$ = $$\max _{j=1,...,N_h}\left( \vert \lambda _1({\varvec{N}}_j)\vert , \vert \lambda _8({\varvec{N}}_j)\vert \right)$$. In addition, a source term is added to the right hand side of (3.1),

\begin{aligned} {\partial }_t {{\mathbf {\mathsf{{{U}}}}}}+ \nabla {\cdot \,}{{\mathbf {\mathsf{{{F}}}}}}_{{{\mathcal {E}}}}({{\mathbf {\mathsf{{{U}}}}}}) + \nabla {\cdot \,}{{\mathbf {\mathsf{{{F}}}}}}_{{{\mathcal {B}}}}({{\mathbf {\mathsf{{{U}}}}}}) = {{\mathbf {\mathsf{{{G}}}}}}_{\text {GLM}}({{\mathbf {\mathsf{{{U}}}}}}), \end{aligned}
(3.9)

where

\begin{aligned} {{\mathbf {\mathsf{{{G}}}}}}_{\text {GLM}}({{\mathbf {\mathsf{{{U}}}}}}) = -\begin{pmatrix} 0 \\ 0 \\ {\varvec{B}}{\cdot }\nabla \Psi _l \\ \nabla {\cdot \,}(\Psi _l {{\mathbb {I}}}) \\ 0 \end{pmatrix}. \end{aligned}

If the hyperbolic correction is used, the internal energy (3.4) is modified as

\begin{aligned} e = E - \frac{1}{2} \rho ({\varvec{u}}{\cdot }{\varvec{u}}) - \frac{1}{2} ({\varvec{B}}{\cdot }{\varvec{B}}) - \frac{1}{2}\Psi _l^2, \end{aligned}

and the extra wave speeds are given by $$\lambda _{\text {GLM}1,2}={\varvec{u}}{\cdot }{\varvec{e}}\pm c_h$$, see [43].

### Remark 1

(The Powell source term [4]) Even when one of the divergence cleaning methods is used, as in the numerical examples in Sect. 5, the divergence error of the numerical solution is not perfectly zero. It has been analyzed by several authors, see e.g., [43, 44], that when the divergence error is non-zero, the Powell source term [4] or its variances should be added to the ideal MHD system to maintain the consistency of the Lorentz force and thermodynamics. However, as a result from the addition of the source term, the flux becomes non-conservative. This leads to some drawbacks. For instance, in presence of strong shocks, the locations of the discontinuities can be inaccurate [41]. A common approach in the recent works is to combine the GLM method with the Powell term, see [43, 45]. We however do not observe significant numerical benefits of the Powell term in the numerical examples presented in this paper. The discussion of stability and entropy principles in addition of the Powell term to our FE framework is left as a future work.

## 4 Nonlinear Viscosity Method for MHD

The aim of this paper is to solve the inviscid MHD system (3.1) using continuous finite element approximations. We use the following two vector valued spaces:

\begin{aligned} {\mathcal {{\varvec{V}}}}_h := [{{\mathcal {Q}}}_h]^{d}, \quad {\mathcal {{\varvec{W}}}}_h := {{\mathcal {Q}}}_h {\times }{\mathcal {{\varvec{V}}}}_h {\times }{{\mathcal {Q}}}_h {\times }{\mathcal {{\varvec{V}}}}_h, \end{aligned}
(4.1)

where $${{\mathcal {Q}}}_h$$ is defined in (2.1). Then, we formulate the finite element approximation of the MHD system (3.1) as follows: find $${{\mathbf {\mathsf{{{U}}}}}}_h(t) :=(\rho _h, {\varvec{m}}_h, E_h, {\varvec{B}}_h)^\top \in {{\mathcal {C}}}^1([0,{\widehat{t}} \,\,]; {\mathcal {{\varvec{W}}}}_h)$$ such that

\begin{aligned} \begin{aligned} \big ({\partial }_t {{\mathbf {\mathsf{{{U}}}}}}_h, {{\mathbf {\mathsf{{{V}}}}}}_h \big ) +&\big ( \nabla {\cdot \,}{{\mathbf {\mathsf{{{F}}}}}}_{{{\mathcal {E}}}}({{\mathbf {\mathsf{{{U}}}}}}_h), {{\mathbf {\mathsf{{{V}}}}}}_h \big ) + \big ( \nabla {\cdot \,}{{\mathbf {\mathsf{{{F}}}}}}_{{{\mathcal {B}}}}({{\mathbf {\mathsf{{{U}}}}}}_h), {{\mathbf {\mathsf{{{V}}}}}}_h \big ) = 0, \quad \forall \,\, {{\mathbf {\mathsf{{{V}}}}}}_h \in {\mathcal {{\varvec{W}}}}_h. \end{aligned} \end{aligned}
(4.2)

Given that the flux functions are interpolated in a polynomial space, the inner products can be computed exactly using appropriate numerical quadrature rules. This holds true in our numerical simulations using FEniCS, an open-source finite element framework, see [46]. The finite element approximation of the flux terms in (4.2) is equivalent to central difference schemes, therefore produces spurious oscillations and cannot be used for strong discontinuities such as shocks and contact lines. Below, we introduce a nonlinear artificial viscosity approach to fix this issue.

### 4.1 New Class of Viscous Regularization of the MHD Equations

In this section, we propose using the following vanishing viscosity regularization of the MHD system. The new regularization is obtained by adding an elliptic term $$\nabla {\cdot \,}{{\mathbf {\mathsf{{{F}}}}}}_{{{\mathcal {V}}}}({{\mathbf {\mathsf{{{U}}}}}})$$ into the MHD system, where $${{\mathbf {\mathsf{{{F}}}}}}_{{{\mathcal {V}}}}({{\mathbf {\mathsf{{{U}}}}}})$$ denotes a viscous flux tensor.

As a heuristic argument to construct $${{\mathbf {\mathsf{{{F}}}}}}_{{{\mathcal {V}}}}({{\mathbf {\mathsf{{{U}}}}}})$$, we start from the viscous flux of the resistive MHD equations, see e.g., [47],

\begin{aligned} {{\mathbf {\mathsf{{{F}}}}}}_{{{\mathcal {V}}}}^0({{\mathbf {\mathsf{{{U}}}}}}_h):= \begin{pmatrix} 0 \\ {\varvec{\tau }}_h \\ {\varvec{u}}_h {\cdot }{\varvec{\tau }}_h + \kappa _h \nabla T_h + \eta _h{\varvec{B}}_h {\cdot }\big ( \nabla {\varvec{B}}_h - \nabla {\varvec{B}}_h^\top \big )\\ \eta _h \big ( \nabla {\varvec{B}}_h - \nabla {\varvec{B}}_h^\top \big ) \end{pmatrix}. \end{aligned}
(4.3)

where the temperature $$T_h$$ is a function in $${{\mathcal {Q}}}_h$$. The viscous shear stress tensor $${\varvec{\tau }}_h$$ is defined as

\begin{aligned} {\varvec{\tau }}_h = \mu _h \Big ( \nabla {\varvec{u}}_h + \nabla {\varvec{u}}_h^\top \Big ) + \lambda _h \nabla {\cdot \,}{\varvec{u}}_h{{\mathbb {I}}}, \end{aligned}

where $$\mu _h \ge 0$$ is the artificial dynamic viscosity, $$\lambda _h$$ is the bulk viscosity of undetermined sign such that $$\lambda _h + 2\mu _h > 0$$, $$\kappa _h \ge 0$$ is the artificial heat conduction, $$\eta _h \ge 0$$ is the artificial electric resistivity of the medium. Note that the electric resistivity $$\eta _h$$ has the same dimension as the dynamic viscosity coefficient $$\mu _h$$. We point out that the temperature and velocity fields are computed at the nodal points: $$T_h({\varvec{N}}_i) = p_h({\varvec{N}}_i)/\rho _h({\varvec{N}}_i)$$, $${\varvec{u}}_h({\varvec{N}}_i) = {\varvec{m}}_h({\varvec{N}}_i)/\rho _h({\varvec{N}}_i)$$, $$i\in \{1,\ldots ,N_h\}$$.

By considering zero magnetic field, i.e., $${\varvec{B}}\equiv 0$$ and thus $${{\mathbf {\mathsf{{{F}}}}}}_{{{\mathcal {B}}}}({{\mathbf {\mathsf{{{U}}}}}}) \equiv 0$$, we obtain from (3.1) the compressible Euler equations. For the compressible Euler equations, a frequent choice of viscous regularization is the Navier-Stokes flux, see e.g., [25], which coincides with $${{\mathbf {\mathsf{{{F}}}}}}_{{{\mathcal {V}}}}^0({{\mathbf {\mathsf{{{U}}}}}}_h)$$ when $${\varvec{B}}\equiv 0$$. The Navier-Stokes flux does not add any viscosity term to the mass equation. Therefore, positivity of density can be violated [25, 48]. In [48], the authors have shown the importance of regularizing the mass equation and have proven that it is a key argument for keeping density and internal energy positive, and for the minimum entropy principle. Numerical validation of the viscous regularization compressible Euler equation including the mass equation in the context of high-order finite element approximation is reported in [25]. They show that the new viscous flux performs better than the traditional Navier-Stokes flux in capturing complex phenomena, e.g., shocks, rarefaction, contact lines, while maintaining high order accuracy.

For MHD, we add a corresponding elliptic term scaling by a positive number $$\nu _h$$ to regularize the mass conservation. Therefore, the obtained viscous flux is a slightly modified Navier-Stokes viscous fluxes for the flow part and resistivity magnetic fluxes for the magnetic part:

\begin{aligned} {{\mathbf {\mathsf{{{F}}}}}}_{{{\mathcal {V}}}}({{\mathbf {\mathsf{{{U}}}}}}_h):= \begin{pmatrix} \nu _h\nabla \rho _h \\ {\varvec{\tau }}_h \\ {\varvec{u}}_h {\cdot }{\varvec{\tau }}_h + \kappa _h \nabla T_h + \eta _h {\varvec{B}}_h {\cdot }\big ( \nabla {\varvec{B}}_h - \nabla {\varvec{B}}_h^\top \big )\\ \eta _h \big ( \nabla {\varvec{B}}_h - \nabla {\varvec{B}}_h^\top \big ) \end{pmatrix}. \end{aligned}
(4.4)

Then, the viscous regularized finite element approximation of the MHD equations is: find $${{\mathbf {\mathsf{{{U}}}}}}^{{\varepsilon }}_h(t) \in {{\mathcal {C}}}^1([0,{\widehat{t}} \,\,]; {\mathcal {{\varvec{W}}}}_h)$$ such that

\begin{aligned} \begin{aligned}&\big ({\partial }_t {{\mathbf {\mathsf{{{U}}}}}}^{{\varepsilon }}_h, {{\mathbf {\mathsf{{{V}}}}}}_h \big ) + \big ( \nabla {\cdot \,}{{\mathbf {\mathsf{{{F}}}}}}_{{{\mathcal {E}}}}({{\mathbf {\mathsf{{{U}}}}}}^{{\varepsilon }}_h), {{\mathbf {\mathsf{{{V}}}}}}_h \big ) + \big ( \nabla {\cdot \,}{{\mathbf {\mathsf{{{F}}}}}}_{{{\mathcal {B}}}}({{\mathbf {\mathsf{{{U}}}}}}^{{\varepsilon }}_h), {{\mathbf {\mathsf{{{V}}}}}}_h \big ) \\&\quad = - \big ( {{\mathbf {\mathsf{{{F}}}}}}_{{{\mathcal {V}}}}({{\mathbf {\mathsf{{{U}}}}}}^{{\varepsilon }}_h), \nabla {{\mathbf {\mathsf{{{V}}}}}}_h) + \big ( {\varvec{n}}{\cdot }{{\mathbf {\mathsf{{{F}}}}}}_{{{\mathcal {V}}}}({{\mathbf {\mathsf{{{U}}}}}}^{{\varepsilon }}_h), {{\mathbf {\mathsf{{{V}}}}}}_h)_{\Gamma }, \quad \forall \,\, {{\mathbf {\mathsf{{{V}}}}}}_h \in {\mathcal {{\varvec{W}}}}_h, \end{aligned} \end{aligned}
(4.5)

where $${\varvec{n}}$$ is the normal vector pointing outward at every point on the boundary $$\Gamma$$. In the rest of the paper, we look for a viscous solution, however, to make the notation easier, we drop the superscript $$^{{\varepsilon }}$$ sign.

We construct the viscosity coefficients $$\nu _h, \mu _h, \kappa _h$$, and $$\eta _h$$, all are from the finite element space $${{\mathcal {Q}}}_h$$, and make them proportional to a nonlinear functional such that enough viscosity is added to the system in terms of stability and accuracy.

In the following sections, we construct $$\nu _i^{L,n}$$ and $$\nu _i^{H,n}$$, the low and high order kinematic artificial viscosity coefficients correspondingly for each nodes $${\varvec{N}}_i$$, $$i= \{1, \ldots , N_h\}$$. Other viscosity coefficients are then constructed using the kinematic viscosity coefficient.

### 4.2 First-Order Viscosity

At each node $$i \in \{1,2,\dots ,N_h \}$$, we compute the first order viscosity at time $$t=t^n$$ as

\begin{aligned} \nu _i^{L,n} = C_{\max }h_i\lambda ^n_{\max ,i}, \end{aligned}

where $$h_i$$ is the nodal values of the mesh function $$h_h({\varvec{x}})$$, $$\lambda ^n_{\max }$$ is the largest eigenvalue at time $$t=t^n$$, given by (3.6), and $$C_{\max }$$ is a positive parameter. A typical range of $$C_{\max }$$ is reportedly [0.15, 0.5], see [27]. In one space dimension, it can shown that $$C_{\max } = 0.5$$ leads to the first order Lax-Friedrichs scheme. We use $$C_{\max } = 0.5$$ in all the numerical examples in this article for all polynomial degrees. Note, that the mesh function is already scaled with the polynomial degree in (2.2).

This choice of first-order viscosity is consistent with the CFL condition discussed later. In addition, the largest eigenvalue turned out to be sufficient to construct a stable first-order viscosity for the numerical examples considered in this work. We emphasize that for a positivity preserving first-order scheme, similar to the Euler system, as in [49], a more accurate estimate of the maximum wave velocity is required.

Our goal is to build a high-order stabilized method. We use the first-order scheme as a safety factor and then construct a high-order extension of it.

### 4.3 High-Order Residual-Based Viscosity

The idea behind a high order scheme is to build an indicator that tracks strong shocks and discontinuities and activates the first-order method from the section above. At the same time, the indicator should decrease the viscosity where the solution is smooth. For this, we use the finite element residual of the PDE as an indicator, since it vanishes in smooth regions, i.e., $$\sim {{\mathcal {O}}}(h_h^{k+1})$$, and has a jump of size $$\sim {{\mathcal {O}}}(h_h^{- 1})$$ at discontinuities.

We use the residual as an indicator, therefore, we need to get rid of the corresponding solution unit. Our aim is to find a normalization function such that it transforms any input function to the same arithmetic range, and is locally amplified at the regions where the input function changes drastically.

Consider a continuous scalar function $$w:{{\mathbb {R}}}^d\rightarrow {{\mathbb {R}}}$$ and in particular the case $$w \in {{\mathcal {Q}}}_h$$. We propose dividing w by the following function to normalize w

\begin{aligned} n(w)_i = \left| {\bar{S}}(w) - \alpha \left( \max _{j\in {{\mathcal {I}}}(i)} w_j-\min _{j\in {{\mathcal {I}}}(i)}w_j\right) \right| , \end{aligned}
(4.6)

where $${\bar{S}}$$ indicates the global maximum variance $${\bar{S}}(w) = \Vert w - \text {mean}(w)\Vert _{L^{\infty }(\Omega )}$$, and the global constant $$\alpha$$ is calculated as

\begin{aligned} \alpha = \frac{C_l {\bar{S}}(w)}{\max _{\Omega }w-\min _{\Omega }w} \end{aligned}

which acts as a unit normalizer of local jumps to the global variance. As a technical detail, notice that when w is a constant uniform function, we have $${\max _{\Omega }w-\min _{\Omega }w}=\max _{j\in {{\mathcal {I}}}(i)} w_j-\min _{j\in {{\mathcal {I}}}(i)}w_j=0$$ for all $$i\in \{1,2,\dots ,N_h\}$$. In that case, n(w) reduces to $$\left| (1-C_l){\bar{S}}(w)\right|$$ which although being zero, we do not suffer from division by zero in the calculation of n(w). In an earlier development, the normalization function n(w) in [30] can be obtained by setting $$\alpha = 1$$ in (4.6). We observe that the new formulation (4.6) deals better with mixed-signed solutions since the two factors in n(w) are of the same unit. To demonstrate this argument, we rewrite the expression (4.6) as

\begin{aligned} n(w)_i = {\bar{S}}(w)\left( 1 - C_l \frac{\max _{j\in {{\mathcal {I}}}(i)}w_j-\min _{j\in {{\mathcal {I}}}(i)}w_j}{\max _{\Omega }w-\min _{\Omega }w} \right) . \end{aligned}
(4.7)

The parameter $$C_l \in (0, 1)$$ allows fine tuning of how sensitive this normalization affects the local discontinuities. Observe that the ratio $$(\max _{j\in {{\mathcal {I}}}(i)}w_j-\min _{j\in {{\mathcal {I}}}(i)}w_j)/(\max _{\Omega }w-\min _{\Omega }w)$$ is in between the interval [0, 1], and is amplified at local solution jumps. If the input function w holds both positive and negative parts, and if $$\alpha =1$$, it is possible that $$n(w)_i = 0$$ at the regions where the local jumps incidentally matches the global variance. However, once the local jump bypasses the global variance, n(w) can become uncontrollably big, which opposes to our aim that n(w) should be small at such circumstances. On the other hand, the formula (4.7) does not suffer this issue because the value within the bracket in (4.7) is strictly positive. How small n(w) can become is tuned with the parameter $$C_l$$. For example, if $$C_l = 1$$, n(w) can become zero at the largest jump of w. Lowering $$C_l$$ from 1 towards 0 would make n(w) at jumps of w larger and larger but not exceeding $${\bar{S}}(w)$$. In smooth regions, n(w) turns into $${\bar{S}}(w)$$, which is the classical normalization function of our residual-based viscosity technique, see [26].

Next, we construct a normalized finite element residual of the MHD equations as

\begin{aligned} {{\widetilde{R}}}_h^n := \max \left( \frac{R(\rho ^n_h)}{n(\rho ^n_h)}, \frac{R({\varvec{m}}^n_{h,1})}{n({\varvec{m}}^n_{h,1})}, \dots , \frac{R({\varvec{m}}^n_{h,d})}{n({\varvec{m}}^n_{h,d})},\frac{R(E^n_h)}{n(E^n_h)},\frac{R({\varvec{B}}^n_{h,1})}{n({\varvec{B}}^n_{h,1})},\dots ,\frac{R({\varvec{B}}^n_{h,d})}{n({\varvec{B}}^n_{h,d})}\right) ,\qquad \quad \end{aligned}
(4.8)

where the normalization terms $$n(\rho ^n_h),$$ $$n({\varvec{m}}^n_{h,1}),$$ $$\dots ,$$ $$n({\varvec{m}}^n_{h,d}),$$ $$n(E_h),$$ $$n({\varvec{B}}^n_{h,1}),\dots ,n({\varvec{B}}^n_{h,d})$$, as defined above, normalize the residual units and magnitude. It is also possible that the denominators in (4.8) become close to zero, in the cases when the initial solution or the analytic solution of the corresponding component is a constant or almost a constant. To avoid division by zero, instead of using $$R(q_h)/n(q_h)$$, where $$q_h$$ is a scalar function, we use $$R(q^n_h)\frac{n(q^n_h)}{n(q^n_h)^2+\epsilon }$$. We choose $$\epsilon$$ to be machine epsilon, i.e. approximately $$2.2e^{-16}$$.

For each component $$q^n_h\in \{\rho ^n_h, {\varvec{m}}^n_{h,1},\dots ,{\varvec{m}}^n_{h,d},E^n_h,{\varvec{B}}^n_{h,1},\dots ,{\varvec{B}}^n_{h,d}\}$$, the residual $$R(q^n_h)$$ can be calculated by standard finite element projection,

\begin{aligned} \int _{\Omega } R(q^n_h) \varphi _i \,\mathrm {d}x = \int _{\Omega } \vert \text {BDF}(q_h)^n+\nabla {\cdot \,}(f(q^n_h))\vert \, \varphi _i \,\mathrm {d}x, \end{aligned}
(4.9)

where $$f(q^n_h)$$ corresponds to the nonlinear MHD flux in (4.2) for each component $$q^n_h$$, and $$\text {BDF}(q_h)^n$$ is a backward difference approximation of the time derivative $${\partial }_tq_h$$ at time $$t=t^n$$. Note that the second-order BDF formula is sufficient in getting 4th order accurate scheme, which is given by

\begin{aligned} {\text {BDF2}(q_h)^n = \frac{3q_h^n-4q_h^{n-1}+q_h^{n-2}}{2h}.} \end{aligned}

For $${{\mathbb {P}}}_1,{{\mathbb {P}}}_3$$ Lagrange elements, we observe that without destroying robustness, the residual can be calculated much more efficiently by approximating the above projection solution by lumping the mass matrix,

\begin{aligned} R(q^n_h) \approx \frac{1}{m_i} \int _{\Omega } \vert \text {BDF}(q_h)^n+\nabla {\cdot \,}(f(q^n_h))\vert \, \varphi _i \,\mathrm {d}x, \end{aligned}

where $$m_i = \int _{\Omega } \varphi _i \,\mathrm {d}x > 0$$ for $${{\mathbb {P}}}_1,{{\mathbb {P}}}_3$$ Lagrange polynomials.

Finally, we are now ready to construct the final artificial viscosity on each node i at time $$t=t^n$$:

\begin{aligned} {\nu _{i}^n = \min \left( \nu _i^{L,n}, \nu _i^{H,n}\right) ,} \end{aligned}
(4.10)

where $$\nu _i^H = C_Rh_{h,i}^2 R^n_i$$, $$R^n_i$$ is the nodal value of the residual $${{\widetilde{R}}}_h^n$$, $$C_R$$ is a positive parameter. A typical range of $$C_{R}$$ is reportedly [0.1, 1], see [27]. For the numerical simulations in this paper, we use $$C_R = 1$$. In the rest of this paper, we refer to using (4.10) in the formulation of the viscous regularized Eq. (4.5) as the “RV method”.

### 4.4 Other Viscosity Coefficients

In the previous sections, we have shown how the kinematic viscosity coefficient $$\nu _h$$ is constructed. The unit of $$\nu _h$$ is $$\text{ length}^2/ \text{ time }$$, which corresponds to its physical unit. Next, we calculate the dynamic viscosity as

\begin{aligned} \mu _h := \rho _h \nu _h. \end{aligned}

The heat conduction $$\kappa _h$$ is then computed using the dynamic viscosity $$\mu _h$$:

\begin{aligned} \kappa _h := \frac{\mu _h}{Pr}, \end{aligned}

where Pr is the Prandtl number, a dimensionless parameter. We also know that the unit of electrical resistivity is the same as kinematic viscosity, i.e. $$\text{ length}^2/ \text{ time }$$. Thus, in our numerical calculation, we take

\begin{aligned} \eta _h := \nu _h. \end{aligned}

Lastly, we set the bulk viscosity coefficient $$\lambda _h:=0$$ in all results presented in this paper.

Once the MHD system is discretized in space using the continuous finite element method we obtain the system of ODEs (4.5). Let us denote this system as

\begin{aligned} {{\mathbb {M}}}{\partial }_t {{\mathbf {\mathsf{{{U}}}}}}_h(t) = {{\mathcal {F}}}({{\mathbf {\mathsf{{{U}}}}}}_h(t), {\varvec{\mu }}_h(t)), \end{aligned}

where $${{\mathbb {M}}}\in {{\mathbb {R}}}^{(2d+2)N_h\times (2d+2)N_h}$$ is the mass matrix, $${{\mathcal {F}}}({{\mathbf {\mathsf{{{U}}}}}}_h(t), {\varvec{\mu }}_h(t))$$ is the right-hand-side function of the system which depends on the solution $${{\mathbf {\mathsf{{{U}}}}}}_h(t)$$ and the viscosity vector is $${\varvec{\mu }}_h(t) := (\nu _h(t), \mu _h(t), \kappa _h(t), \eta _h(t))$$.

Next, discretize this system in time using explicit r-stage Runge-Kutta methods:

\begin{aligned} {{\mathbf {\mathsf{{{U}}}}}}^{n+1}_h = {{\mathbf {\mathsf{{{U}}}}}}^{n}_h + \tau _n (b_1 {{\mathbf {\mathsf{{{K}}}}}}_1 + \ldots + b_r {{\mathbf {\mathsf{{{K}}}}}}_r), \end{aligned}
(4.11)

where $$\tau _n := t^{n+1} - t^n$$, $${{\mathbf {\mathsf{{{U}}}}}}^{n}_h := {{\mathbf {\mathsf{{{U}}}}}}_h(t^n)$$, $$b_i$$, $$i=1,\ldots ,r$$ are coefficients obtained from the Butcher tableau, and the stage variables $${{\mathbf {\mathsf{{{K}}}}}}_i$$ are computed as follows: for the given solution $${{\mathbf {\mathsf{{{U}}}}}}_h^n$$ and the viscosity vector $${\varvec{\mu }}_h^n:={\varvec{\mu }}_h(t^n)$$ at time level $$t^n$$, set $${{\mathbf {\mathsf{{{W}}}}}}_0:= {{\mathbf {\mathsf{{{U}}}}}}_h^n$$, then let $${{\mathbf {\mathsf{{{W}}}}}}_l$$ be the solution at the l-th stage of the Runge-Kutta method, then compute $${{\mathbf {\mathsf{{{K}}}}}}_l$$ by solving the following system:

\begin{aligned} {{\mathbb {M}}}{{\mathbf {\mathsf{{{K}}}}}}_l = {{\mathbf {\mathsf{{{F}}}}}}({{\mathbf {\mathsf{{{W}}}}}}_l(t), {\varvec{\mu }}_h^n), \end{aligned}

for all $$l=0,\ldots , r$$. Note that the viscosity coefficients can also be computed on the fly at every Runge-Kutta stage. However, in this work, the viscosity coefficient is constructed from the previous time level and does not change within the Runge-Kutta stages.

The time-step $$\tau _n$$ is computed adaptively using a CFL condition

\begin{aligned} \tau _n = \text {CFL} \frac{\min _{{\varvec{x}}\in \Omega } h_h({\varvec{x}})}{\max _{j=1,\ldots ,N_h}\vert \lambda ^n_{\max ,j}\vert }. \end{aligned}
(4.12)

### 4.6 Boundary Conditions

In the following numerical examples we use the following boundary conditions: Dirichlet, Neumann, periodic, and slip or an impermeability boundary condition. The Neumann boundary condition is implemented as an additional boundary integral in the variational form. The periodic boundary condition is implemented by enforcing the same value of degrees of freedom (DOF) of matching nodes on two opposite boundaries in question.

The Dirichlet and slip boundary conditions are imposed strongly as a correction step after the Runge-Kutta method is applied. Assume that we want to compute solution at time level $$t^{n+1}$$, $${{\mathbf {\mathsf{{{U}}}}}}_h^{n+1}$$, we impose the Dirichlet boundary condition by setting the values of the solution on the boundary nodes $${\varvec{N}}_j$$ by its boundary data.

The slip or an impermeability boundary condition requires $${\varvec{u}}_h^{n+1} {\cdot }{\varvec{n}}= 0$$ on the boundary in question. This condition is equivalent to $${\varvec{m}}_h^{n+1} {\cdot }{\varvec{n}}= 0$$. Then, the boundary value of momentum at the boundary node $${\varvec{N}}_j$$, $${\varvec{m}}_h^{n+1}({\varvec{N}}_j)$$ is replaced by $${\varvec{m}}_h^{n+1}({\varvec{N}}_j) - {\varvec{m}}_h^{n+1}({\varvec{N}}_j) {\cdot }{\varvec{n}}$$.

We refer the reader to [25], where advantages of the strong implementation of the slip boundary condition versus its weak counterpart are discussed, and we refer to [37], where the correction technique is discussed for explicit schemes in more detail.

### 4.7 Summary of the Algorithm

To summarize, our stabilized finite element solution of the MHD system (3.1) can be obtained by the following steps. In each time step, the solution is advanced as

1. 1.

Calculate the residual using (4.9), combine the low order and high order viscosity to calculate the amount of artificial viscosity using (4.10).

2. 2.

Solve the main linear system (4.5) where the time derivative is discretized using a Runge-Kutta method (4.11) of order at least $$k+1$$.

3. 3.

If the projection method or the pseudo time-stepping method is used for cleaning divergence of $${\varvec{B}}_h$$, use the techniques described in Sect. 3.2.1. If the hyperbolic correction method in Sect. 3.2.2 is used, divergence cleaning is already incorporated into the system in the previous step.

4. 4.

Apply boundary conditions strongly as described in Sect. 4.6.

5. 5.

Compute an approximation of the maximum local velocity using (3.6), and identify the next time step size using (4.12).

## 5 Numerical Examples

In this section, we demonstrate the efficiency of our proposed stabilization method on several well-known benchmark problems. For the following tests, the residual viscosity parameters are $$C_{\max } = 0.5, C_R = 1.0, C_l = 0.4$$. We observe that the parameter $$C_l$$ is not sensitive as in most circumstances, apart from enhanced smoothness at sharp shocks, any choice of $$C_l\in (0,1)$$ would give satisfactory outcomes. We have used the classical Runge-Kutta 4 for all the tests with time step (4.12), where the CFL number is chosen to be 0.3. In all simulations below, we use $$Pr=1$$, and the rest of viscosity coefficients are computed as in Sect. 4.4.

### 5.1 Accuracy Test

The first two test problems where an analytic solution can be derived are presented to show the high order property of the stabilization in the smooth regions.

#### 5.1.1 Smooth Vortex Problem, [45]

Consider a periodic smooth vortex problem on a rectangle domain $$\Omega \!=\! {(-10, 10) \!\times \! (-10, 10)}$$. The reference solution is a stationary flow with a vortex perturbation

\begin{aligned} (\rho (t), {\varvec{u}}(t), p(t), {\varvec{B}}(t)) =(\rho _0, {\varvec{u}}_0+\delta {\varvec{u}}, p_0+\delta p, {\varvec{B}}_0+\delta {\varvec{B}}), \end{aligned}

where

\begin{aligned} \rho _0&= 1,&\\ {\varvec{u}}_0&= (1,1),&\delta {\varvec{u}}&= \frac{\mu }{\pi \sqrt{2}}e^{(1-r^2)/2}(-r_2,r_1),\\ p_0&=0,&\delta p&= -\frac{\mu ^2(1+r^2)e^{1-r^2}}{8\pi ^2}, \\ {\varvec{B}}_0&=(0.1,0.1),&\delta {\varvec{B}}&= \frac{\mu e^{(1-r^2)/2}}{2\pi }(-r_2,r_1), \end{aligned}

the vortex radius is $$r=\sqrt{r_1^2+r_2^2}$$, $$(r_1,r_2)=(x,y)-{\varvec{u}}_0t$$, and the vortex strength is $$\mu =5.389489439$$. The adiabatic constant is $$\gamma =\frac{5}{3}$$. The errors measured at final time $${\widehat{t}}=0.05$$ using $${{\mathbb {P}}}_1, {{\mathbb {P}}}_2, {{\mathbb {P}}}_3$$ elements are shown in Table 1. In Table 1, we show behavior of both the Galerkin solutions and the RV solutions. For the $${{\mathbb {P}}}_2$$ solution, the obtained error is lower than that of the $${{\mathbb {P}}}_1$$ solution under the same number of degrees of freedom. However, the convergence rate of the $${{\mathbb {P}}}_2$$ is second order, which is suboptimal with regards to theoretical derivations. This is a known issue with continuous Galerkin approximations, which was earlier reported in, e.g., [25]. An analysis of the suboptimal convergence for even-order CG schemes can be found in [50]. Figure 1 illustrates and compares the convergence history between the Galerkin solutions and the RV solutions. All the obtained convergence rates show that the RV method does not destroy high-order accuracy of the Galerkin smooth solutions.

#### 5.1.2 Smooth Wave Propagation, [45]

In this test case, we consider a rectangle domain $$\Omega = {(0, 2\pi ) \times (0, 2\pi )}$$. A periodic wave-like solution reads $$(\rho (t), {\varvec{u}}(t), p(t), {\varvec{B}}(t))$$ $$=$$ $$(1+0.99\sin (x+y-2t),(1,1),1,(0.1,0.1))$$. The adiabatic constant is $$\gamma =1.4$$. The errors measured at final time $${\widehat{t}}=0.1$$ using $${{\mathbb {P}}}_1, {{\mathbb {P}}}_2, {{\mathbb {P}}}_3$$ elements are shown in Table 2. Again, the obtained convergence orders of the corresponding Galerkin approximations remains unchanged when the artificial viscosity term is added.

### 5.2 Brio-Wu MHD Shock Tube Problem, [3]

The RV method shows high-order accuracy for smooth problems considered in above. Now, we start solving problems with strong shocks and discontinuities.

We want to solve the one-dimensional Brio-Wu MHD shock tube problem, which was first introduced by [3]. This is the one-dimensional Riemann problem in the domain $$\Omega = {(0, 1)}$$. The problem is challenging because the solution contains waves of different types, typical for an ideal MHD.

The problem setting is the following:

\begin{aligned} (\rho , u, p, B_x, B_y) = {\left\{ \begin{array}{ll} (1,0,1,0.75, 1), &{}x \in [0,0.5), \\ (0.125,0,0.1,0.75,-1), &{} x \in [0.5,1.0]. \end{array}\right. } \end{aligned}

The adiabatic constant is $$\gamma =2$$. The importance of this test is to examine whether a MHD solver can represent the shocks, rarefactions, contact lines, and the whole compound structure accurately. The solution at the final time $${\hat{t}} = 0.2$$ is shown in Fig. 2. A well-known reference solution is provided by the Athena code [51] with 10000 grid points.

The result in Fig. 2 shows that our proposed method can capture the wave structures efficiently and accurately. We also see that $${{\mathbb {P}}}_3$$ solution is sharper than $${{\mathbb {P}}}_1$$ for the same number of degrees of freedom.

### 5.3 2D Orszag-Tang problem, [52]

In this section, we consider the well-known benchmark Orszag-Tang problem in 2D. The considered domain is a square, $$\Omega = {(0,1) \times (0,1)}$$. The solution is initialized as

\begin{aligned} (\rho , {\varvec{u}}, p, {\varvec{B}})= \left( \frac{25}{36\pi },(-\sin (2\pi y),\sin (2\pi x)),\frac{5}{12\pi },\left( -\frac{\sin (2\pi y)}{\sqrt{4\pi }},\frac{\sin (4\pi x)}{\sqrt{4\pi }}\right) \right) . \end{aligned}

The adiabatic constant for this problem is $$\gamma =\frac{5}{3}$$. The periodic boundary condition is used in both directions. For divergence cleaning, we have used the projection method. The density solution $$\rho _h$$ and the artificial viscosity $$\mu _h$$ at time $$t = 0.5$$ and $$t=1.0$$ are shown in Fig. 3 using $${{\mathbb {P}}}_1$$ elements, and in Fig. 4 using $${{\mathbb {P}}}_3$$ elements. At $$t=1.0$$, the structure of the Orszag-Tang solution is considered turbulence [40].

Despite being a classical benchmark in studies of numerical schemes for MHD, the evolution of the Orszag-Tang solution after $$t=0.5$$ has rarely been reported or discussed in the literature. For the sake of the readers, we note that the time scale can be different in some other papers. For example, in [41], the solution at $$t=3.14$$ approximately corresponds to our solution at $$t=0.5$$. The authors in [53] pointed out that for short integration in time, whether or not a divergence cleaning procedure is involved does not affect the Orszag-Tang solution as there is no noticeable difference. We also observe this situation in our continuous finite element simulation both visually and numerically, at least up to $$t=0.5$$. In fact, it is evident that the Orszag-Tang solution up to $$t=0.5$$ is relatively straightforward to be obtained by numerical schemes with shock-capturing capability, e.g., [41, 53, 54]. However, long time integration would discriminate different discretizations, as remarked by [54]. Using DG method, the authors in [54] reported that not all choices of the slope limiters and discretizations of the Powell term [4] would work well after $$t = 0.5$$. The authors also identified that specifically at $$0.75 \le t \le 0.85$$, numerical solutions are prone to divergence blow-ups due to complex shock collisions.

For this test case, we use the FE setup same to all other test cases without changing any parameter. All the shocks are captured locally and accurately by the RV method. This could be a motivation of using entropy viscosity methods, or in particular RV methods, for shock-capturing purposes. Under the same number of degrees of freedom, the $${{\mathbb {P}}}_3$$ solution reveals more structural details of the shocks and turbulence. Similar to the reference [54] using a third-order DG scheme, we capture a twisting density upsurge in the centre of the domain using $${{\mathbb {P}}}_3$$ Lagrange elements.

We discuss the effect of different divergence cleaning techniques in the finite element settings in the remaining of this section.

#### 5.3.1 Numerical Comparison of the Divergence Cleaning Techniques

We show the absolute divergence error $$\int _{\Omega }\vert \nabla {\cdot \,}{\varvec{B}}_h\vert \,\mathrm {d}x$$ of the Orszag-Tang test as a function of time using different divergence cleaning techniques in Fig. 5. The simulation uses $${{\mathbb {P}}}_1$$ elements on a $$40\times 40$$ right triangulation mesh. We note that if a sufficiently fine mesh was used, the reference simulation without divergence cleaning would break at some time around $$t=0.7$$ due to large divergence error. The figure shows that our method works well with some of the most well-known divergence cleaning techniques in MHD. The divergence error remains small with the use of the projection method, pseudo time-stepping method, and hyperbolic method for divergence cleaning. Among the methods, the pseudo time-stepping method with 10 pseudo iterations performs the best. However, the method is the most expensive because 10 pseudo iterations need to be computed in each time step. The projection method is more expensive than the hyperbolic cleaning method because a Poisson equation needs to be solved in each time step. The obtained behavior of the divergence error agrees with the reported results, e.g., [40, 43]. We hereby conclude that the investigated divergence cleaning techniques incorporates well with our shock-capturing method, in which the divergence error remains controlled over long time simulation.

### 5.4 3D Orszag-Tang Problem, [55]

The 3D Orszag-Tang problem is extended from the 2D Orszag-Tang problem in Sect. 5.3. The domain is a unit cube $$\Omega = {(0,1)\times (0,1)\times (0,1)}$$. Essentially, density and pressure are identical to the 2D problem, independent of the z-coordinate. The velocity and magnetic field are also identical in the x- and y- directions, but zero in the z-direction,

\begin{aligned} (\rho _0, {\varvec{u}}_0, p_0, {\varvec{B}}_0)\!=\! \left( \frac{25}{36\pi },(-\sin (2\pi y),\sin (2\pi x),0),\frac{5}{12\pi },\left( -\frac{\sin (2\pi y)}{\sqrt{4\pi }},\frac{\sin (4\pi x)}{\sqrt{4\pi }},0\right) \!\right) . \end{aligned}

We then add a small perturbation to the velocity, similar to [55],

\begin{aligned} \delta {\varvec{u}}= (-\epsilon _p \sin (2\pi z)\sin (2\pi y), \epsilon _p \sin (2\pi z)\sin (2\pi x),\epsilon _p \sin (2\pi z)), \end{aligned}

where the perturbation parameter $$\epsilon _p$$ is a small real number. We set $$\epsilon _p = 0.2$$ same to [55]. The initial solution can be written as

\begin{aligned} (\rho (t), {\varvec{u}}(t), p(t), {\varvec{B}}(t)) =(\rho _0, {\varvec{u}}_0+\delta {\varvec{u}}, p_0, {\varvec{B}}_0+\delta {\varvec{B}}). \end{aligned}

The adiabatic constant is kept same to the 2D problem, $$\gamma =\frac{5}{3}$$. All boundaries are periodic. We use the projection method to clean the divergence. The CFL number is 0.3. A $${{\mathbb {P}}}_3$$ solution of the 3D Orszag-Tang problem is shown in Fig. 6. We stop the simulation at $$t=0.5$$ to make the density plot in Fig. 6(a) directly comparable with [55]. The density cut $$z=0$$ presents the highly recognizable 2D Orszag-Tang solution. Along the z-axis, the solution agrees well with the reported results in [55]. A quarter of the solution is hidden to reveal some of the inside structures. We see that the RV method can capture the shocks efficiently in 3D with the same finite element setup in 1D and 2D. We omit the discussion of divergence error in 3D as the purpose of this paper is to develop accurate shock-capturing techniques for finite element approximations.

### 5.5 MHD Rotor, [6]

The final benchmark we present is the rotor problem, first introduced in [6]. This problem is referred to as the “first rotor problem” in [41]. The initial solution is a disc being placed in the central of the domain $$\Omega = {(0,1) \times (0,1)}$$. The ambient solution is a stationary medium at ten times lesser density along a homogeneous magnetic field,

\begin{aligned} (\rho , {\varvec{u}}, p, {\varvec{B}})= \left( 1,(0,0)^T, 1, \left( \frac{5}{\sqrt{4\pi }},0\right) \right) . \end{aligned}

Let r be the radius of the disc centered at the domain central. The disc is defined as

\begin{aligned} (\rho , {\varvec{u}}, p)= {\left\{ \begin{array}{ll} &{} \left( 10, \left( \frac{u_0}{r_0}(0.5-y), \frac{u_0}{r_0}(x-0.5)\right) \right) \text { if } r< r_0\\ &{} \left( 1+9f, \left( f\frac{u_0}{r}(0.5-y),f\frac{u_0}{r}(x-0.5)\right) \right) \text { if }r_0 \le r < r_1, \end{array}\right. } \end{aligned}

where $$f = (r_1-r)/(r_1-r_0)$$, the inner radius $$r_0 = 0.1$$ and the outer radius $$r_1 = 0.115$$. The adiabatic constant is $$\gamma =1.4$$. Due to imbalance in the centrifugal force, the disc is rotated as it proceeds in time, generating a twisting moment in the magnetic field. The difficulties of this test include: (i) resolving the torsional Alfvén waves, and (ii) during the rotation, the pressure can get close to zero which is challenging for numerical methods. [41] reported that many schemes fail to solve this problem owing to negative pressure. Our density and pressure solution at $$t=0.15$$ are plotted in Fig. 7. The projection method is used for cleaning the divergence. It can be seen that the signature circle contour lines within the middle of Fig. 7(c) showing the rotational evolution, see e.g., [41], are finely captured.

## 6 Conclusion

The main purpose of this paper has been to numerically investigate a new viscous regularization of the ideal MHD equations. The proposed viscous regularization is inspired by the work of [48] on the Euler equations combining with the elliptic terms of the resistive MHD equations. The discretization consists of a high-order residual-based viscosity finite element method in space and the classical explicit Runge-Kuta methods in time. The results have shown that the proposed method can capture different structures of MHD discontinuities while achieving high-order accuracy, experimented up to fourth-order, in shock-free regions.

Future extensions of this paper may concern continuous analysis of the proposed viscous flux regarding e.g., positivity-preserving properties, Galilean invariance, and entropy principles. Discrete invariant-domain preserving schemes can be built upon such continuous properties using, for instance, the viscous operator by [56].