1 Introduction

Systems of conservation laws that model a physical system or process often possess an additional conserved quantity, the entropy, which is conserved for smooth solutions but increases (or decreases according to the sign convention adopted) in the presence of shocks. A method is said to be entropy conservative if the local changes of entropy are the same as predicted by the entropy conservation law. The approximation is said to be entropy stable if it produces more entropy than an entropy conservative scheme.

We introduce the important distinction between entropy conservation and stability because there is a problem with entropy conservative formulations. They may suffer breakdown if used without dissipation to capture shocks. Physically, entropy must be dissipated at a shock. However, an isentropic algorithm does not allow the capture of this physical process, which generates large amplitude oscillations around the shock [3]. A more dire issue is that entropy conservative formulations can not converge to the weak solution as there is no mechanism to admit the dissipation physically required at the shock.

Tadmor [25, 26] was the first to introduce the idea of entropy conservation to design stable numerical approximations of nonlinear hyperbolic conservation laws. At a semi-discrete level the principle is that the discrete flux function satisfies discrete conservation laws of the conservative variables as well as the scalar conservation law for entropy in a discrete sense. Tadmor’s flux function performs well for smooth data but can be made stable for shock problems [27]. But, Tadmor’s flux function, which involves an integral in phase space, is numerically expensive. For large scale simulations we want a more practical, computationally tractable, entropy conserving flux.

Thus, in this paper, it is our goal to develop affordable, entropy stable methods for the shallow water magnetohydrodynamic (SWMHD) model. There is recent work for optimal, entropy stable approximations for the Euler equations from Ismail and Roe [15] which was extended to arbitrary order with a discontinuous Galerkin (DG) spectral element formulation by Carpenter et al. [3]. Also, there is recent work on entropy-stable, high-order, and well-balanced approximations for the shallow water equations [11, 12, 29].

The remainder of this paper is organized as follows: Sect. 2 provides an introduction to the SWMHD equations. In Sect. 3 we briefly describe the finite volume discretization used. Section 4 defines the necessary variables and analytical tools to discuss the entropy in a mathematically rigorous way. We derive an entropy conserving numerical flux in Sect. 5.1 and discuss the stabilized flux in Sect. 5.2. Numerical results are presented in Sect. 6, where we verify theoretical predictions. Section 7 presents concluding remarks. Finally, in the Appendix we provide entropy stable fluxes that can be used for two dimensional computations.

2 The Shallow Water Magnetohydrodynamic Model

The shallow water magnetohydrodynamics (SWMHD) equations were first proposed by Gilman as a model for phenomena in the solar tachocline [13], which is the thin layer in a star between the outer turbulent convection zone, and the quiescent interior where heat transfer is predominantly radiative. The tachocline has many interesting physical applications such as the formation of sunspots [5]. Tachoclines can also serve as a useful model of solar dynamo action [7, 8, 13].

As was first shown by Gilman [13] with complete details presented by Rossmanith [24] the SWMHD equations are derived from the ideal MHD equations by integrating in the z-direction under the assumption of incompressibility, a two dimensional variation of the flow variables, and magnetohydrostatic equilibrium in the z-direction:

$$\begin{aligned} \begin{aligned} \rho&\equiv constant,\\ \frac{\partial }{\partial z}\left( p + \frac{\Vert \varvec{B}\Vert ^2}{2}\right)&= \rho g,\\ p + \frac{\Vert \varvec{B}\Vert ^2}{2}&= \rho g z,\\ \int _0^h \left( p + \frac{\Vert \varvec{B}\Vert ^2}{2}\right) \,dz&= \rho g \frac{h^2}{2}. \end{aligned} \end{aligned}$$
(2.1)

Under these assumptions and the divergence-free constraint \(\nabla \cdot (h\varvec{B})\) the SWMHD equations can be cast into the form of a system of conservation laws [5, 24]. The one dimensional SWMHD equations comprise a hyperbolic system written in the conservative form

$$\begin{aligned} \begin{aligned} \frac{\partial \varvec{u}}{\partial t} + \frac{\partial \varvec{f}}{\partial x} = \begin{bmatrix} h\\ hv_1\\ hv_2\\ hB_1\\ hB_2\\ \end{bmatrix}_t + \begin{bmatrix} hv_1 \\ hv_1^2 +\frac{1}{2}gh^2 - hB_1^2 \\ hv_1v_2-hB_1B_2 \\ 0 \\ hv_1B_2 - hv_2B_1\\ \end{bmatrix}_x&= \begin{bmatrix} 0 \\ 0 \\ 0 \\ 0 \\ 0 \\ \end{bmatrix},\\\quad \frac{\partial (hB_1)}{\partial x}&= 0, \end{aligned} \end{aligned}$$
(2.2)

where the final equation is the one dimensional involution condition on the magnetic field \(\varvec{B}\). The variables \(v_1\), \(v_2\), and \(\varvec{B}\) in (2.2) are the horizontal components of the fluid velocity and magnetic field, h is the fluid layer depth, and g is the constant gravitational acceleration.

Hyperbolic systems, like the SWMHD equations, are typically solved numerically with Godunov-type methods [20]. These methods require the solution of a Riemann problem at element interfaces. Unfortunately, the one-dimensional SWMHD equations are degenerate [5], just like the ideal MHD equations [22, 23], due to the involution, \(\nabla \cdot (h\varvec{B}) = 0\). For example, if we consider the one dimensional problem we see from (2.2) that \(\partial _t(hB_1) = 0\). Thus, there is no propagating Riemann wave associated with the conservative variable \(hB_1\). To alleviate such degeneracies we are interested in relaxing the involution \(\nabla \cdot (h\varvec{B}) = 0\) such that a conventional Riemann solver based method may be used for the approximation of the SWMHD system.

To accomplish this we weaken the divergence condition to require that \(\nabla \cdot (hB)\approx 0,\) i.e., the divergence condition is to be maintained up to finite precision error. Dellar [6] showed that for the relaxed assumption of the divergence condition we obtain a forced version of the SWMHD model

$$\begin{aligned} \begin{aligned} \frac{\partial \varvec{u}}{\partial t} + \frac{\partial \varvec{f}}{\partial x} = \begin{bmatrix} h\\ hv_1\\ hv_2\\ hB_1\\ hB_2\\ \end{bmatrix}_t + \begin{bmatrix} hv_1 \\ hv_1^2 +\frac{1}{2}gh^2 - hB_1^2 \\ hv_1v_2-hB_1B_2 \\ 0 \\ hv_1B_2 - hv_2B_1\\ \end{bmatrix}_x&= - \frac{\partial (hB_1)}{\partial x}\begin{bmatrix} 0 \\ 0 \\ 0 \\ v_1 \\ v_2 \\ \end{bmatrix} = \varvec{s}, \end{aligned} \end{aligned}$$
(2.3)

where the source term is proportional to the divergence condition. Importantly, the source term in (2.3) alters the system to make \(hB_1\) an advected scalar while maintaining the conservation of mass and momentum. The forced equations (2.3) can be derived from a Hamiltonian approach [6], so the system (2.3) conserves the total energy. The conservation of total energy is important when we develop the entropy conserving flux in Sect. 5.1. Also, the source term serves to restore Galilean invariance when \(\nabla \cdot (h\varvec{B})\ne 0\) [6]. Finally, the source term in (2.3) is analogous to the Janhunen source term for the ideal MHD equations [16].

It is important to note that the source term in (2.3) preserves the conservation of the momentum and energy, while enforcing the involution condition on \(h\varvec{B}\). Preserving the conservative properties of the fluid equations removes a significant drawback of the other common proposed Powell type source term for the SWMHD equations. The Powell source term renders the equations of momentum and energy for SWMHD non-conservative [6]. However, according to the Lax-Wendroff theorem [19] only conservative schemes can be expected to compute the correct jump conditions and propagation speed for a discontinuous solution. Difficulties of the non-conservative formulation obtaining the correct weak solution has been documented in the literature for the ideal MHD equations [28].

3 Finite Volume Discretization

The finite volume (FV) method is a discretization technique for partial differential equations especially useful for the approximation of systems of conservations laws. The finite volume method is designed to approximate conservation laws in their original form, e.g.,

$$\begin{aligned} \int _V\varvec{u}_t\,dx + \int _{\partial V} \varvec{f}\cdot \hat{\varvec{n}}\,dS = 0. \end{aligned}$$
(3.1)

For instance, in one spatial dimension we break the interval into non-overlapping intervals (the “volumes”)

$$\begin{aligned} V_i = \left[ x_{i-\tfrac{1}{2}},x_{i+\tfrac{1}{2}}\right] , \end{aligned}$$
(3.2)

and the integral equation of a balance law, with a source term, becomes

$$\begin{aligned} \frac{d}{dt}\int _{x_{i-{1}/{2}}}^{x_{i+{1}/{2}}} \varvec{u}\,dx + \varvec{f}^*\left( x_{i+{1}/{2}}\right) - \varvec{f}^*\left( x_{i-{1}/{2}}\right) = \int _{x_{i-{1}/{2}}}^{x_{i+{1}/{2}}} \varvec{s}\,dx \end{aligned}$$
(3.3)

At this point, we make approximations. A common approximation is to assume that the solution and the source term are constant within the volume. Then we determine, for example, what is analogous to a midpoint quadrature approximation of the solution integral

$$\begin{aligned} \int _{x_{i-{1}/{2}}}^{x_{i+{1}/{2}}} \varvec{u}\,dx \approx \int _{x_{i-{1}/{2}}}^{x_{i+{1}/{2}}} \varvec{u}_i\,dx = \varvec{u}_i\varDelta x_i. \end{aligned}$$
(3.4)

Note that the solution is typically discontinuous at the boundaries of the volumes. To resolve this, we introduce the idea of a “numerical flux,” \(\varvec{f}^*(\varvec{u}^L,\varvec{u}^R)\), often derived from the (approximate) solution of a Riemann problem. That is, \(\varvec{f}^*\) is a function that takes the two states of the solution at an element interface and returns a single flux value. For consistency, we require that

$$\begin{aligned} \varvec{f}^*(\varvec{u},\varvec{u}) = \varvec{f}, \end{aligned}$$
(3.5)

that is, the numerical flux is equivalent to the physical flux if the states on each side of the interface are identical. A significant portion of this paper is devoted to the derivation of a numerical flux that conserves the discrete entropy of the system for the shallow water MHD equations. So we defer the discussion of the numerical flux to Sect. 5.

We must also address how to discretize the source term \(\varvec{s}\) in (3.3). There is a significant amount of freedom in the source term discretization. But, previous work by Fjordholm et al. [9] demonstrated that designing entropy stable methods for the shallow water equations with discontinuous bottom topography required a special treatment of the source term. In the later derivations a consistent source term discretization necessary for entropy conservation will reveal itself. Thus, we also defer the discussion of the discrete treatment of the source term to Sect. 5.1.

4 Entropy Analysis

In this section we define the entropy variables and entropy Jacobian necessary to develop an entropy stable approximation for the SWMHD equations. We note that one can find a fully general and detailed description of entropy stability theory in, for example, [2, 10].

For the SWMHD equations the total energy acts as an entropy function, [6],

$$\begin{aligned} U\left( \varvec{u}\right) = \frac{1}{2}\left( gh^2+hv_1^2+hv_2^2+hB_1^2+hB_2^2\right) , \end{aligned}$$
(4.1)

where \(\varvec{u}\) is the vector of conserved variables. From the total entropy (4.1) we define the set of entropy variables

$$\begin{aligned} U_{\varvec{u}} := \varvec{q} = \left( gh-\frac{1}{2}\left\{ v_1^2+v_2^2+B_1^2+B_2^2\right\} ,\,v_1,\,v_2,\,B_1,\,B_2\right) ^T. \end{aligned}$$
(4.2)

The entropy variables (4.2) are equipped with the symmetric positive definite (s.p.d) Jacobian matrices

$$\begin{aligned} \mathbf H ^{-1} =\varvec{q}_{\varvec{u}} = \frac{1}{h}\begin{bmatrix} c^2+v_1^2+v_2^2+B_1^2+B_2^2&\quad -v_1&\quad -v_2&\quad -B_1&\quad -B_2 \\ -v_1&\quad 1&\quad 0&\quad 0&\quad 0 \\ -v_2&\quad 0&\quad 1&\quad 0&\quad 0 \\ -B_1&\quad 0&\quad 0&\quad 1&\quad 0 \\ -B_2&\quad 0&\quad 0&\quad 0&\quad 1 \end{bmatrix}, \end{aligned}$$
(4.3)

and

$$\begin{aligned} \mathbf H =\varvec{u}_{\varvec{q}} = \frac{1}{g} \begin{bmatrix} 1&\quad v_1&\quad v_2&\quad B_1&\quad B_2 \\ v_1&\quad v_1^2 + c^2&\quad v_1 v_2&\quad v_1 B_1&\quad v_1 B_2 \\ v_2&\quad v_1 v_2&\quad v_2^2 + c^2&\quad v_2 B_1&\quad v_2 B_2 \\ B_1&\quad v_1 B_1&\quad v_2 B_1&\quad B_1^2 + c^2&\quad B_1 B_2 \\ B_2&\quad v_1 B_2&\quad v_2 B_2&\quad B_1 B_2&\quad B_2^2 + c^2 \end{bmatrix}, \end{aligned}$$
(4.4)

where \(c^2 = gh\) is the standard wave speed for the shallow water equations. The fact that the matrices \(\mathbf H \) and \(\mathbf H ^{-1}\) are s.p.d. is a direct consequence that the entropy function (4.1) is a strongly convex, injective mapping [6]. For the derivations that follow we also require the flux Jacobian in the x-direction:

$$\begin{aligned} \mathbf A =\varvec{f}_{\varvec{u}} = \begin{bmatrix} 0&\quad 1&\quad 0&\quad 0&\quad 0 \\ c^2 - v_1^2 + B_1^2&\quad 2v_1&\quad 0&\quad -2B_1&\quad 0 \\ -v_1v_2+B_1B_2&\quad v_2&\quad v_1&\quad -B_2&\quad -B_1 \\ 0&\quad 0&\quad 0&\quad 0&\quad 0 \\ v_2B_1 - v_1B_2&\quad B_2&\quad -B_1&\quad -v_2&\quad v_1 \end{bmatrix}. \end{aligned}$$
(4.5)

Because it will be of use in later derivations we also compute the entropy potential

$$\begin{aligned} \psi = \varvec{q}\cdot \varvec{f} - F = \frac{1}{2}gh^2v_1 - hB_1\left( v_1B_1 + v_2B_2\right) , \end{aligned}$$
(4.6)

where F is the entropy flux derived from the identity \(U_{\varvec{u}}\mathbf A = F_{\varvec{u}}\), [9],

$$\begin{aligned} F = gh^2v_1 + \frac{1}{2}\Big (hv_1^3 + hv_1v_2^2 + hv_1B_2^2 - hv_1B_1^2\Big ) - hv_2B_1B_2. \end{aligned}$$
(4.7)

4.1 Discrete Entropy Conservation for the 1D SWMHD Equations

We introduce the concept of discrete entropy conservation. Let’s assume that we have two adjacent states (LR) with cell areas \((\varDelta x_L,\varDelta x_R)\). We discretize the SWMHD equations semi-discretely and examine the approximation at the \(i+\tfrac{1}{2}\) interface. We suppress the interface index unless it is necessary for clarity.

$$\begin{aligned} \begin{aligned} \varDelta x_L\frac{\partial \varvec{u}_L}{\partial t}&= \varvec{f}_L - \varvec{f}^* + \varDelta x_L{\varvec{s}}_{i+\tfrac{1}{2}},\\ \varDelta x_R\frac{\partial \varvec{u}_R}{\partial t}&= \varvec{f}^*-\varvec{f}_R + \varDelta x_R{\varvec{s}}_{i+\tfrac{1}{2}}. \end{aligned} \end{aligned}$$
(4.8)

We interpret the update (4.8) as a finite volume scheme where we have left and right cell-averaged values separated by a common flux interface.

We premultiply the expressions (4.8) by the entropy variables to convert to entropy space. From the chain rule we know that \(U_t = \varvec{q}^T\varvec{u}_t\), hence a semi-discrete entropy update is

$$\begin{aligned} \begin{aligned} \varDelta x_L\frac{\partial U_L}{\partial t}&= \varvec{q}_L^T\left( \varvec{f}_L - \varvec{f}^* + \varDelta x_L{\varvec{s}}_{i+\tfrac{1}{2}}\right) , \\ \varDelta x_R\frac{\partial U_R}{\partial t}&= \varvec{q}_R^T\left( \varvec{f}^*-\varvec{f}_R + \varDelta x_R{\varvec{s}}_{i+\tfrac{1}{2}}\right) . \end{aligned} \end{aligned}$$
(4.9)

If we denote the jump in a state as \(\llbracket \cdot \rrbracket = (\cdot )_R - (\cdot )_L\) and the average of a state as , then we find the total element update to the entropy is

(4.10)

We want the discrete entropy update to satisfy the discrete entropy conservation law. To achieve this, we require

(4.11)

We combine the known entropy potential \(\psi \) in (4.6) and the linearity of the jump operator to rewrite the entropy conservation condition (4.11) as

(4.12)

We denote the constraint (4.12) as the discrete entropy conserving condition. However, this is a single condition on the vector \(\varvec{f}^*\), so there are many potential solutions for the entropy conserving flux. However, we have the additional requirement that the numerical flux must be consistent (3.5). We develop an affordable entropy conserving flux function in Sect. 5. We also defer the discretization of the source term \({\varvec{s}_{i+1/2}}\) to to the next section because special care must be taken to guarantee that (4.12) is satisfied.

5 Derivation of an Entropy Stable Numerical Flux

With the necessary entropy variable and Jacobian definitions as well as the formulation of the discrete entropy conserving condition (4.12) we are ready to derive an affordable entropy conserving numerical flux in Sect. 5.1. As we previously noted, entropy conserving methods may suffer breakdown in the presence of shocks [3]. Thus, in Sect. 5.2, we will design an entropy stable Riemann solver that uses the entropy conserving flux as a base and incorporates a dissipation term required for stability.

5.1 Entropy Conserving Numerical Flux for 1D SWMHD

In this section we define an affordable, entropy conserving numerical flux for the one dimensional SWMHD equations.

Theorem 1

(Entropy Conserving Numerical Flux) If we discretize the source term in the finite volume method to contribute to each element as

(5.1)

then we can determine a discrete, entropy conservative flux to be

(5.2)

Proof

To derive an affordable entropy conservative flux for the one dimensional SWMHD equations we first expand the discrete entropy conserving condition (4.12) componentwise to find

(5.3)

To determine the unknown flux components of \(\varvec{f}^*\) we use (5.3) to obtain a system of equations for each of the linear jump terms. For this expansion step we make repeated use of the linear jump operator properties:

(5.4)

We expand the terms of (5.3) to linear jump terms of the primitive variables h, \(v_1\), \(v_2\), \(B_1\), and \(B_2\). This is straightforward in all but the last two terms on the right hand side

(5.5)

Care must be taken when we expand the the second term on the right hand side of the entropy condition (5.5). If we naively split the jump terms all the way to individual linear jump terms it will introduce averages of the magnetic field variables \(\varvec{B}\) on the jump in fluid height h. However, the continuity equation in the SWMHD model contains no influence from the magnetic field. Therefore, it would be impossible for the resulting numerical flux to be consistent with the physical flux.

To remove this inconsistency we split the magnetic field jumps on the right hand side of (5.5) in such a way that cancellation with the source term is possible. Thus, rather than fully expanding each jump term down to the primitive variable level, it is useful to leave the product \(hB_1\) term as a jump. This choice is motivated by the structure of the source term because

$$\begin{aligned} \frac{\partial }{\partial x}\!\left( hB_1\right) \approx \frac{\llbracket hB_1 \rrbracket }{\varDelta x}. \end{aligned}$$
(5.6)

We expand the second term on the right hand side of (5.5) as follows:

(5.7)

We substitute (5.7) into the expanded entropy constraint (5.5) to obtain

(5.8)

From the structure of the expanded entropy conserving constraint (5.8) we are prepared to select a discretization of the source term at the interface. The goal is to cancel the jump in \(hB_1\) term. We choose that the source term discretization on cell i will contribute to the interfaces \(i+\tfrac{1}{2}\) and \(i-\tfrac{1}{2}\). In exact arithmetic the dot product of the entropy variables with the source term is

$$\begin{aligned} -\frac{\partial }{\partial x}(hB_1)\left( v_1B_1 + v_2B_2\right) . \end{aligned}$$
(5.9)

From (5.9) we see that it will be possible to create a consistent discretization to cancel the \(\llbracket hB_1 \rrbracket \) term that remains in (5.8). To do so we require the source term discretization

(5.10)

The source term discretization (5.10) is consistent to the source term in (2.3). For example, on a regular grid where \(\varDelta x_L = \varDelta x_R\) we have for \(\varvec{s}_{i+1/2}\)

(5.11)

where consistency is easily checked. We note that there may be computational issues if either \(B_1\) or \(B_2\) is zero. However, if \(B_2=0\) (for example), then the contribution to the entropy conservation constraint is also zero. Now it is possible to use the source term discretization (5.10) to see the explicit cancellation of the problematic \(\llbracket hB_1 \rrbracket \) term at the \(i+\tfrac{1}{2}\) interface:

(5.12)

With the remaining \(\llbracket hB_1 \rrbracket \) term is removed from (5.8) we are left with the constraint on the numerical flux that only depends on the linear jump in each primitive variable

(5.13)

We collect the like terms and determine a set of equations for the unknown components of the entropy conserving numerical flux \(\varvec{f}^{*,ec}\):

(5.14)

The equations (5.14) are easily solved to determine the form of the entropy conserving flux to be

(5.15)

Interestingly, to guarantee the conservation of entropy we had to relax the divergence-free condition to \(\partial _x(hB_1)\approx 0\). This assumption manifests itself in the fourth component of \(\varvec{f}^{*,ec}\), which is nonzero. Essentially the fourth term in \(\varvec{f}^{*,ec}\) is the commutator of multiplication and averaging of \(hB_1\). \(\square \)

Remark 1

If the flow occurs without the presence of a magnetic field then the SWMHD model becomes the traditional shallow water (SW) equations. The structure of \(\varvec{f}^{*,ec}\) (5.15) can be separated into a shallow water component and magnetic field component, i.e.,

(5.16)

Thus, if the magnetic field is zero we find

(5.17)

and \(\varvec{f}^{*,ec}\) becomes the appropriate entropy conserving flux for the SW equations described in [9, 12].

Remark 2

We have considered a computational problem with a flat bottom topography. So it is a natural question for a shallow water type model if the approximation remains well-balanced, i.e., recovers a constant fluid height solution in the presence of a non-constant bottom topography [29]. Previous work by Fjordholm et al. [9] provides a consistent, well-balanced, and entropy conserving treatment of a non-constant (and even discontinuous) bottom topography b. For example in the x-direction

(5.18)

In the presence of a non-constant bottom topography one would add the discretized source term (5.18) to the x component of the momentum equation of the SWMHD model. Note that the treatment of the bottom topography source term by Fjordholm et al. in (5.18) is analogous to our treatment of the Janhunen source term for SWMHD (5.10).

5.2 Dissipation Terms for an Entropy Stable Flux

To create an entropy stable numerical flux function we use the entropy conserving flux (5.15) as a base and subtract some form of numerical dissipation, e.g.,

$$\begin{aligned} \varvec{f}^* = \varvec{f}^{*,ec} - \frac{1}{2}\mathbf D \llbracket \varvec{u} \rrbracket , \end{aligned}$$
(5.19)

where \(\mathbf D \) is a dissipation matrix.

Our goal to guarantee the entropy stability of the approximation is to reformulate the dissipation term (5.19) such that it is guaranteed to be positive. To do so we will consider the eigenstructure of the flux Jacobian \(\mathbf A \) altered by the Powell source term

$$\begin{aligned} \varvec{s}_{Powell} = -\frac{\partial }{\partial x}(hB_1)\begin{bmatrix} 0 \\ B_1 \\ B_2 \\ v_1 \\ v_2 \end{bmatrix}. \end{aligned}$$
(5.20)

It is important to note that we use the Janhunen source term (2.3) to derive an entropy conservative numerical flux function in Sect. 5.1. However, to design an entropy stable approximation we require that the eigendecomposition of the flux Jacobian matrix can be related to the entropy Jacobian (4.4). This particular scaling, first examined by Merriam [21] and explored more thoroughly by Barth [2], requires that the PDE system is symmetrizable. Previous analysis of the SWMHD system by Dellar [6] and ideal MHD equations [2, 14] have demonstrated that the Powell source term is necessary to restore a symmetric MHD system. We reiterate that the altered flux Jacobian is used only to derive the dissipation term. Just as Lax-Friedrichs differs from Roe in the construction of a dissipation term, we use the Powell source term only to build our dissipation term. Thus, we do not introduce any inconsistency in the previous entropy conserving flux derivations. We demonstrate with numerical tests in Sect. 6.4 that the newly developed entropy stable flux functions are competitive with the well known Roe flux.

We denote the flux Jacobian modified with the Powell source term (5.20) as

$$\begin{aligned} \widehat{\mathbf{A }} = \begin{bmatrix} 0&\quad 1&\quad 0&\quad 0&\quad 0 \\ gh - v_1^2 + B_1^2&\quad 2v_1&\quad 0&\quad -B_1&\quad 0 \\ -v_1v_2+B_1B_2&\quad v_2&\quad v_1&\quad 0&\quad -B_1 \\ 0&\quad 0&\quad 0&\quad v_1&\quad 0 \\ v_2B_1 - v_1B_2&\quad B_2&\quad -B_1&\quad 0&\quad v_1 \\ \end{bmatrix}, \end{aligned}$$
(5.21)

equipped with a full set of eigenvalues

$$\begin{aligned} \lambda _1 = v_1-c_g,\quad \lambda _2 = v_1-B_1,\quad \lambda _3 = v_1,\quad \lambda _4 = v_1+B_1,\quad \lambda _5 = v_1+c_g, \end{aligned}$$
(5.22)

and right eigenvectors

$$\begin{aligned} \widehat{\mathbf{R }} = \begin{bmatrix} 1&\quad 0&\quad 1&\quad 0&\quad 1 \\ v_1-c_g&\quad 0&\quad v_1&\quad 0&\quad v_1+c_g \\ v_2&\quad 1&\quad v_2&\quad 1&\quad v_2 \\ 0&\quad 0&\quad \frac{c_g^2}{B_1}&\quad 0&\quad 0 \\ B_2&\quad 1&\quad B_2&\quad -1&\quad B_2 \end{bmatrix}, \quad \widehat{\mathbf{L }} = \widehat{\mathbf{R }}^{-1}, \end{aligned}$$
(5.23)

where \(c_g^2 = gh+B_1^2\) is the magnetogravity wave speed.

Now that we have a symmetrizable matrix \(\widehat{\mathbf{A }}\) we utilize a previous result from Barth [2] which provides a systematic approach to restructure a general eigenvalue problem to a symmetric eigenvalue problem. To do so we rescale the right eigenvectors of an eigendecomposition with respect to a right symmetrizer matrix in the following way:

Lemma 1

(Eigenvector Scaling) Let \(\mathbf A \in \mathbb {R}^{n\times n}\) be an arbitrary diagonalizable matrix and S the set of all right symmetrizers:

$$\begin{aligned} S=\left\{ \mathbf B \in \mathbb {R}^{n\times n}\,\big |\;\mathbf B \;is\; s.p.d,\;\;\mathbf AB = (\mathbf AB )^T\right\} . \end{aligned}$$
(5.24)

Further, let \(\mathbf R \in \mathbb {R}^{n\times n}\) denote the right eigenvector matrix which diagonalizes \(\mathbf A \), i.e., \(\mathbf A =\mathbf R {\varvec{\varLambda }}\mathbf R ^{-1}\), with r distinct eigenvalues. Then for each \(\mathbf B \in S\) there exists a symmetric block diagonal matrix \(\mathbf T \) that block scales columns of \(\mathbf R \), \(\widetilde{\mathbf{R }} = \mathbf RT \), such that

$$\begin{aligned} \mathbf B =\widetilde{\mathbf{R }}\widetilde{\mathbf{R }}^T,\; \mathbf A =\widetilde{\mathbf{R }}{\varvec{\varLambda }}\widetilde{\mathbf{R }}^{-1}, \end{aligned}$$
(5.25)

which implies

$$\begin{aligned} \mathbf AB =\widetilde{\mathbf{R }}{\varvec{\varLambda }}\widetilde{\mathbf{R }}^{T}. \end{aligned}$$
(5.26)

Proof

The proof of the eigenvector scaling lemma is given in [2]. \(\square \)

Theorem 2

(Entropy Stable 1 (ES1)) If we apply the diagonal scaling matrix

$$\begin{aligned} \mathbf T = diag\left( \frac{c}{c_g\sqrt{2g}},\,\frac{c}{\sqrt{2g}},\,\frac{B_1}{c_g\sqrt{g}},\,\frac{c}{\sqrt{2g}},\,\frac{c}{c_g\sqrt{2g}}\right) , \end{aligned}$$
(5.27)

to the matrix of right eigenvectors \(\widehat{\mathbf{R }}\) (5.23), then we obtain the Merriam identity [21] (Eq. 7.3.1 pg. 77)

$$\begin{aligned} \mathbf H = \widetilde{\mathbf{R }}\widetilde{\mathbf{R }}^T = \left( \widehat{\mathbf{R }}\mathbf T \right) \left( \widehat{\mathbf{R }}\mathbf T \right) ^T = \widehat{\mathbf{R }}\mathbf S \widehat{\mathbf{R }}^T, \end{aligned}$$
(5.28)

that relates the right eigenvectors of \(\widehat{\mathbf{A }}\) to the entropy Jacobian matrix (4.4). For convenience, we introduce the diagonal scaling matrix \(\mathbf S =\mathbf T \,^2\) in (5.28). We then have the guaranteed entropy stable flux interface contribution

$$\begin{aligned} \varvec{f}^{*,ES1} = \varvec{f}^{*,ec}-\frac{1}{2}\mathbf D \llbracket \varvec{u} \rrbracket =\varvec{f}^{*,ec} - \frac{1}{2} \widehat{\mathbf{R }}|\widehat{{\varvec{\varLambda }}}|\mathbf S \widehat{\mathbf{R }}^T\llbracket \varvec{q} \rrbracket . \end{aligned}$$
(5.29)

Proof

We define the dissipation term in the numerical flux (5.19) to be

$$\begin{aligned} -\frac{1}{2}\mathbf D \llbracket \varvec{u} \rrbracket = -\frac{1}{2} |\widehat{\mathbf{A }}|\llbracket \varvec{u} \rrbracket = -\frac{1}{2} \widehat{\mathbf{R }}|\widehat{{\varvec{\varLambda }}}|\widehat{\mathbf{L }}\llbracket \varvec{u} \rrbracket , \end{aligned}$$
(5.30)

where the eigendecomposition of \(\widehat{\mathbf{A }} = \widehat{\mathbf{R }}\widehat{{\varvec{\varLambda }}}\widehat{\mathbf{L }}\) is given by (5.22) and (5.23). We define entropy stability to mean the approximation guarantees that the entropy within the system is a decreasing function, satisfying the following inequality

$$\begin{aligned} \frac{\partial U}{\partial t} + \frac{\partial F}{\partial x} - \varvec{q}^T\varvec{s} \le 0. \end{aligned}$$
(5.31)

From the previously computed discrete entropy update (4.10) the total entropy within an element (now including the dissipative term (5.30)) is

(5.32)

from the design of the entropy conserving flux \(\varvec{f}^{*,ec}\). To ensure entropy stability, we must guarantee that the RHS term in (5.32) is non-positive. Unfortunately, it was shown by Barth [2] that the term

$$\begin{aligned} - \frac{1}{2}\llbracket \varvec{q} \rrbracket ^T \widehat{\mathbf{R }}|\widehat{{\varvec{\varLambda }}}|\widehat{\mathbf{L }}\llbracket \varvec{u} \rrbracket , \end{aligned}$$
(5.33)

may become positive in the presence of very strong shocks. However, we know from entropy symmetrization theory, e.g., [2, 21], that the entropy Jacobian \(\mathbf H \), given by (4.4), is a right symmetrizer for the flux Jacobian that incorporates the Powell source term \(\widehat{\mathbf{A }}\). Therefore, with the proper scaling matrix \(\mathbf T \) we acquire the Merriam identity

$$\begin{aligned} \mathbf H = \widetilde{\mathbf{R }}\widetilde{\mathbf{R }}^T = \left( \widehat{\mathbf{R }}\mathbf T \right) \left( \widehat{\mathbf{R }}\mathbf T \right) ^T = \widehat{\mathbf{R }}\mathbf S \widehat{\mathbf{R }}^T. \end{aligned}$$
(5.34)

The rescaling of the right eigenvectors of \(\widehat{\mathbf{A }}\) to satisfy the Merriam identity (5.28) is sufficient to guarantee the negativity of (5.33). We see from (5.33) and (5.34)

$$\begin{aligned} \begin{aligned} -\frac{1}{2}\llbracket \varvec{q} \rrbracket ^T \widehat{\mathbf{R }}|\widehat{{\varvec{\varLambda }}}|\widehat{\mathbf{L }}\llbracket \varvec{u} \rrbracket&\simeq - \frac{1}{2}\llbracket \varvec{q} \rrbracket ^T \widehat{\mathbf{R }}|\widehat{{\varvec{\varLambda }}}|\widehat{\mathbf{L }}\varvec{u}_{\varvec{q}}\llbracket \varvec{q} \rrbracket , \\&= - \frac{1}{2}\llbracket \varvec{q} \rrbracket ^T \widehat{\mathbf{R }}|\widehat{{\varvec{\varLambda }}}|\widehat{\mathbf{L }}\mathbf H \llbracket \varvec{q} \rrbracket , \\&=- \frac{1}{2}\llbracket \varvec{q} \rrbracket ^T \widehat{\mathbf{R }}|\widehat{{\varvec{\varLambda }}}|\widehat{\mathbf{L }}\left( \widehat{\mathbf{R }}\mathbf S \widehat{\mathbf{R }}^T\right) \llbracket \varvec{q} \rrbracket , \\&=- \frac{1}{2}\llbracket \varvec{q} \rrbracket ^T \widehat{\mathbf{R }}|\widehat{{\varvec{\varLambda }}}|\mathbf S \widehat{\mathbf{R }}^T\llbracket \varvec{q} \rrbracket , \end{aligned} \end{aligned}$$
(5.35)

where we used that \(\widehat{\mathbf{L }}=\widehat{\mathbf{R }}^{-1}\). So with the appropriate diagonal scaling matrix \(\mathbf S \) we have shown that (5.35) is guaranteed negative because the product is a quadratic form scaled by a negative. We use the right eigenvectors from (5.23), the constraint (5.28), and straightforward algebraic manipulation to determine the diagonal scaling matrix

$$\begin{aligned} \mathbf T = diag\left( \frac{c}{c_g\sqrt{2g}},\,\frac{c}{\sqrt{2g}},\,\frac{B_1}{c_g\sqrt{g}},\,\frac{c}{\sqrt{2g}},\,\frac{c}{c_g\sqrt{2g}}\right) , \end{aligned}$$
(5.36)

where \(c^2 = gh\) and \(c_g^2 = gh+B_1^2\) are the wave speed and magnetogravity wave speed respectively. \(\square \)

Remark 3

There are other possible, negativity guaranteeing (but more dissipative) choices for the dissipation term (5.19). For example, if we make the simple choice of dissipation matrix to be

$$\begin{aligned} \mathbf D = |\lambda _{max}|\mathbf I , \end{aligned}$$
(5.37)

where \(\lambda _{max}\) is the largest eigenvalue of the system from (5.22) and \(\mathbf I \) is the identity matrix, then we obtain a local Lax-Friedrichs type interface stabilization

$$\begin{aligned} \begin{aligned} \varvec{f}^{*,ES2}&= \varvec{f}^{*,ec} - \frac{1}{2}|\lambda _{max}|\mathbf I \llbracket \varvec{u} \rrbracket , \\&= \varvec{f}^{*,ec} - \frac{1}{2}|\lambda _{max}|\mathbf H \llbracket \varvec{q} \rrbracket , \\&= \varvec{f}^{*,ec} - \frac{1}{2}\widehat{\mathbf{R }}|\lambda _{max}|\mathbf S \widehat{\mathbf{R }}^T\llbracket \varvec{q} \rrbracket ,\\ \end{aligned} \end{aligned}$$
(5.38)

where, again, we use the Merriam identity (5.28) for the entropy Jacobian \(\mathbf H \).

6 Numerical Results

In this section, we numerically verify the theoretical findings for the entropy conserving and entropy stable approximations for the SWMHD equations. To integrate the semi-discrete formulation in time we use a low storage five-stage, fourth-order accurate Runge-Kutta time integrator of Carpenter and Kennedy [4]. First, in Sect. 6.1, we consider a test problem with a known analytical solution to demonstrate the accuracy of the entropy conserving method as well as the optimal and Lax-Friedrichs stabilized formulations. Next, Sect. 6.2 demonstrates the entropy conservation of the approximation for a strong Riemann problem. In Sect. 6.3 we demonstrate the computed solution of a strong Riemann problem for the entropy conserving method. This solution will exhibit significant oscillations in shocked regions. Finally, in Sect. 6.4 we compare the two entropy stable approximations (5.29) and (5.38) against a high-resolution approximation comparable to that presented in the literature [5, 24].

6.1 Convergence

For the convergence test, we switch to the manufactured solution technique and generate a smooth and periodic solution

$$\begin{aligned} \begin{bmatrix} h(x,t)\\ hv_1(x,t)\\ hv_2(x,t)\\ hB_1(x,t)\\ hB_2(x,t)\\ \end{bmatrix} = \begin{bmatrix} 2+\sin {(2\pi \,(x-t))}\\ 2+\sin {(2\pi \,(x-t))}\\ 2+\sin {(2\pi \,(x-t))}\\ 1\\ 4+2\,\sin {(2\pi \,(x-t))} \end{bmatrix} \end{aligned}$$
(6.1)

with an additional analytic source term on the right hand side

$$\begin{aligned} \begin{bmatrix} s_1(x,t)\\ s_2(x,t)\\ s_3(x,t)\\ s_4(x,t)\\ s_5(x,t) \end{bmatrix} = \begin{bmatrix} 0\\ h_x(x,t)\left( g\,h(x,t)+\frac{1}{h(x,t)^2}\right) \\ 0\\ 0\\ 0 \end{bmatrix} \end{aligned}$$
(6.2)

on the domain \(\varOmega =[-1,1]\) with periodic boundary conditions and final time \(T=2\). We select the time step for the RK method small enough such that the error in the approximation is dominated by the error in the spatial discretizations. For all computations, a regular grid is chosen according to the number of grid cells listed in the tables below. Except for the entropy conserving scheme, where we also test a stretched mesh with a fixed ratio of

$$\begin{aligned} \frac{\varDelta x_{max}}{\varDelta x_{min}}=4. \end{aligned}$$
(6.3)

First, we test the entropy conserving scheme on a regular grid. The \(L_2\)-errors for all conserved quantities are shown in Table 1. It is interesting to note, that for the specific regular grid used in the numerical experiment, the entropy conserving scheme achieves second order accuracy. We note that the average accuracy is hovering around 1.7, however looking closely at the finest grid results, it is clear that the experimental order of convergence is close to 2. However, the higher order convergence for the finite volume scheme is an effect of approximating the solution on a regular grid. The scheme drops to first order accuracy when an irregular grid is chosen as shown in Table 2, where we stretch the grid with a constant factor of (6.3).

Table 1 Experimental order of convergence EOC for entropy conserving scheme on a regular grid
Table 2 Experimental order of convergence EOC for entropy conserving scheme on an irregular grid with a stretching factor of (6.3)

Next, we demonstrate the convergence of the two entropy stable finite volume schemes. The convergence results for the ES1 method are shown for the regular grid test in Table 3 and the irregular grid test in Table 4, where we see the average experimental convergence rate for either the regular or irregular grids are both first order accurate. The convergence behavior for the ES2 scheme on both grids fluctuates. Thus, we decided to run more tests on even finer grids to demonstrate that, again, the experimental order of convergence for regular or irregular grids is in the range of 0.7–1.36 (Tables 5, 6).

Table 3 Experimental order of convergence EOC for ES1 scheme (5.29) on a regular grid
Table 4 Experimental order of convergence EOC for ES1 scheme (5.29) on an irregular grid with a stretching factor of (6.3)

6.2 Mass, Momentum, and Entropy Conservation

By design we know the finite volume scheme for the SWMHD equations with the Janhunen source term (2.3) will conserve mass and momentum. From the derivations in 5.1 we know that the scheme also exactly preserves the entropy on a general grid, if we use the newly designed flux \(\varvec{f}^{*,ec}\) (5.15). We measure the change in any of the conservative variables with

$$\begin{aligned} \varDelta e(T) := |e_{int}(t=0) - e_{int}(T)|, \end{aligned}$$
(6.4)

where, for example, \(e_{int}\) is the entropy function

$$\begin{aligned} U = \frac{1}{2}\left( gh^2+hv_1^2+hv_2^2+hB_1^2+hB_2^2\right) \end{aligned}$$
(6.5)

integrated with a Gauss–Lobatto quadrature rule over the whole domain.

Table 5 Experimental order of convergence EOC for ES2 scheme (5.38) on a regular grid
Table 6 Experimental order of convergence EOC for ES2 scheme on an irregular grid with a stretching factor of (6.3)

To demonstrate the conservative properties we consider the one dimensional strong Riemann problem taken from [5] with the initial condition

$$\begin{aligned} \begin{bmatrix}h\\v_1\\v_2\\B_1\\B_2\end{bmatrix} = \left\{ \begin{array}{lc} \left[ 1,0,0,1,0\right] ^{T}, &{}\quad \text {if}\quad x \le 0, \\ \left[ 2,0,0,0.5,1\right] ^{T}, &{}\quad \text {if}\quad x > 0, \end{array} \right. \end{aligned}$$
(6.6)

on the domain \(\varOmega = [-1,1]\) and periodic boundary conditions. We compute the error in the change of each conservative variable for three values of the Courant–Friedrichs–Lewy (CFL) number: 1.0, 0.1, and 0.01. For each simulation the entropy conserving finite volume scheme used 100 regular grid cells for the results in Table 7 and 100 irregular grid cells in Table 8. The final time of each simulation was \(T=0.4\).

We see that for each value of the CFL number we obtain errors in the mass and momentum on the order of machine precision. Also, as expected, the addition of the Janhunen source term to enforce the divergence condition causes us to lose conservation of the quantities \(h\varvec{B}\). Interestingly, in the error for the change in entropy we see the dissipative influence of the time integrator. The dissipation introduced by the temporal discretization can be significantly reduced if we shrink the time step. We see that the error of the entropy can be lowered to single or double machine precision by decreasing the CFL number, and hence the time step.

It is also possible to see the temporal accuracy in Table 7 and Table 8. If we shrink the time step by a factor ten we see that the error in the entropy shrinks by a little over a factor of \(10^4\), as we expect for a fourth order time integrator.

Table 7 Conservation errors (integrated over the whole domain) of the entropy conserving approximation of the Riemann problem (6.6) for different CFL numbers, final time \(T=0.4\), and 100 regular grid cells
Table 8 Conservation errors (integrated over the whole domain) for different CFL numbers with end time \(t=0.4\) on an irregular grid with a stretching factor of (6.3)

6.3 Entropy Conserving Riemann Problem

We now apply the entropy conserving (EC) scheme to the strong Riemann problem (6.6), except we choose inflow/outflow type boundary conditions. The computation is performed on 100 regular grid cells with CFL number 0.1 up to a final time of \(T=0.4\). To create a reference solution we use the ES1 scheme on 5000 grid cells. We present the solution computed with the EC finite volume method against the reference solution in Fig. 1.

The results for the computed fluid height h, velocities \(v_1\), \(v_2\), and magnetic field \(B_1\), \(B_2\) respectively in Fig. 1 show that the EC scheme computes the rarefactions and the shocks in the solution quite accurately, but at the expense of large post-shock oscillations. These oscillations are expected as energy must be dissipated across the shock but the EC scheme is basically dissipation free except for the influence of the time integrator (as we previously noted in Sect. 6.2).

Fig. 1
figure 1

In blue we present the entropy conserving approximations of the quantities h, \(v_1\), \(v_2\), \(B_1\), and \(B_2\) at \(\hbox {T} = 0.4\). Solid black represents the reference solution (Color figure online)

6.4 Entropy Stable Riemann Problem

Next, we use the ES1 and ES2 schemes to compute the solution of (6.6) with inflow/outflow type boundary conditions. Again, the computation is performed on 100 regular grid cells with CFL number 0.1 up to a final time of \(T=0.4\) with a reference solution created using a high-resolution run of the ES1 scheme on 5000 grid cells. We note that the same reference solution could be obtained from a high-resolution computation of the ES2 scheme. We present the solution computed with the entropy stable methods against the reference solution in Fig. 2.

Fig. 2
figure 2

The entropy stable approximations of the quantities h, \(v_1\), \(v_2\), \(B_1\), and \(B_2\) at \(\hbox {T} = 0.4\). Solid black is the reference solution, dashed blue is the ES2 scheme, and red with knots is the ES1 scheme (Color figure online)

Our computed results for the computed fluid height h, velocities \(v_1\), \(v_2\), and magnetic field \(B_1\), \(B_2\) shown in Fig. 2 compare well to the literature [5, 24]. We see that, as was discussed in Sect. 5.2, the Lax-Friedrichs type stabilization introduces more dissipation into the approximation.

As a final test we compare the ES1 scheme to a standard Roe scheme. The development of Roe type schemes for the SWMHD equations has been considered by several authors and complete details can be found in [5, 17, 24]. The comparative computation used 100 regular grid cells with a CFL number of 0.1 up integrated to \(T=0.4\). A reference solution was created from a high-resolution run of the ES1 scheme on 5000 grid cells. The computed results of the schemes are presented in Fig. 3. We see that for the same number of degrees of freedom the ES1 scheme is less dissipative than the Roe scheme. This is particularly evident in the approximation of quantities in the tangential direction, \(v_2\) and \(B_2\). We also note that the Roe scheme is more dissipative than the ES2 Lax-Friedrichs type entropy stable approximation which can be seen from a comparison of the results in Figs. 2 and 3.

Fig. 3
figure 3

The entropy stable results compared against a Roe scheme for the quantities h, \(v_1\), \(v_2\), \(B_1\), and \(B_2\) at \(\hbox {T} = 0.4\). Solid black is the reference solution, dashed blue is the Roe scheme, and red with knots is the ES1 scheme (Color figure online)

7 Concluding Remarks

In this work we present a novel, affordable, entropy stable flux for the shallow water MHD equations. The derivations required us to relax the involution condition such that \(\partial _x(hB_1)\approx 0\) within finite precision error. Under this less restrictive assumption we were able to derive an entropy conserving flux, denoted \(\varvec{f}^{*,ec}\). Special care had to be taken for the discretization of the source term in order to guarantee discrete entropy conservation. Because entropy conserving approximations can suffer breakdown at shocks we extended our analysis and derived two stabilizing dissipation terms that we apply to the entropy conserving flux. We finally used a variety of numerical test examples to demonstrate and underline the theoretical findings.

The derivation of the entropy conserving and entropy stable numerical fluxes in this paper focused on the one-dimensional SWMHD equations. The restriction to one spatial dimension was because the analysis proved to be quite involved. However, the discussion was general, so the derivations in this paper readily extend to provably entropy conserving and entropy stable approximations of the SWMHD equations on multi-dimensional Cartesian grids. In the Appendix we provide details on the multidimensional flux functions.

It is well known that the issue of divergence-free constraint and the accuracy of an approximation is more serious in two dimensions. As was discussed in Sect. 2 the Janhunen source term acts, analogously, to a hyperbolic divergence cleaning method where the error in the involution term is radiated out of the computational domain. To verify the utility of our method we consider a two dimensional example similar to the “rotor problem” of Balsara and Spicer [1] and considered by Tóth [28] for the ideal MHD equations. The computational domain is \(\varOmega = [-1,1]\times [-1,1]\) with initial data

$$\begin{aligned} \begin{bmatrix}h\\v_1\\v_2\\B_1\\B_2\end{bmatrix} = \left\{ \begin{array}{lc} \left[ 10,-y,x,0.1,0\right] ^T, &{} \quad \text {if}\quad \Vert \varvec{x}\Vert _2 < 0.1, \\ \left[ 1,0,0,1,0\right] ^T, &{} \quad \text {if}\quad \Vert \varvec{x}\Vert _2 > 0.1, \end{array} \right. \end{aligned}$$
(7.1)

integrated up to the final time \(T=0.2\). The computational results of the two dimensional ES1 scheme with 200 regular grid cells in each direction are presented in Fig. 4. We note that the computed fluid height h and velocity components \(v_1\) and \(v_2\) compare well with previous results found in the literature [18]. As we expect, because we use a different divergence cleaning procedure, our results for the \(B_1\) and \(B_2\) magnetic fields differ slightly from those computed in [18].

Fig. 4
figure 4

The computed solution to the “rotor problem” (7.1) using the ES1 scheme for the quantities h, \(v_1\), \(v_2\), \(B_1\), and \(B_2\) at \(\hbox {T} = 0.2\). Dashed lines are negative contour lines

In this paper we have demonstrated that the entropy stable approximations for the SWMHD equations are competitive with existing solvers. We also showed that the methods readily extend to multiple dimensions because the source term we need for entropy conservation also acts as a divergence cleaning technique.