1 Introduction

Modelling in geophysical fluid dynamics have gained relevance in recent years due to the importance in predicting and understanding the time evolution of a rich variety of atmospheric and oceanic flows. Such flows occur at different spatial and temporal scales. Models aiming at simulating geophysical flows are derived according to the characteristic of the flows and to the scales associated to them. Many geophysical and atmospheric flows are characterized by their large horizontal length scale compared to their depth. That is, they are shallow, and in those cases the shallow water equations are suitable to model their time evolution.

The shallow water equations form a non-linear hyperbolic balance law with geometric source terms involving the topography, and can be derived by vertically averaging the Euler equations together with appropriate assumptions. The correct modelling of shallow water flows rely on the use of numerical methods satisfying desirable properties. For instance, steady-state flows (those independent of time) arise when a delicate balance between flux gradients and source terms occurs. A careful consideration of that balance in the numerical method is necessary for the correct and accurate computation of flows that are near steady states. On the other hand, positivity-preserving is another important property that enhances stability to any numerical scheme when treating near wet-dry states. A scheme enjoying such property guarantees that if the water depth is initially non-negative, the numerical approximation in subsequent steps preserves the non-negativity of that quantity. Professor Chi-Wang Shu and his group have extensively studied those properties and contributed in that direction. In [38], a WENO scheme with the exact conservation property is developed. The scheme is high-order accurate and a suit of one- and two- dimensional examples were used to test the numerical method. A high-order finite volume WENO scheme that is exactly well balanced for steady states with vanishing (at rest) and non-vanishing velocity was proposed in [28]. This was done by using equilibrium variables to include moving flow equilibria and avoid spurious oscillations. More advantages of such extended property were presented in [41]. A well-balanced and positivity-preserving discontinuous Galerkin method was presented in [42]. A WENO scheme with the same two properties can be found in [39]. In [40], a survey of numerical methods for shallow water flows exposes various approaches proposed over the years, including unstructured meshes. In the present work for shallow water equations with horizontal density gradients, we extend the well-balanced property to more general steady states that arise in still water with a balance between water depth and density compensating for a constant pressure. Additionally, we use Riemann invariants and a hybrid algorithm that avoids spurious oscillations near interfaces of water with density jumps.

Other numerical frameworks can be found in [1, 6, 7, 14, 18, 22, 23, 25, 27, 30, 33, 34] and references therein. A clear illustration of the interplay between flux gradients and the topography to generate a variety of steaty states appears in flows in channels with variable geometry. Upwind schemes recognizing steady states at rest have been derived [15, 16, 37]. The Q-scheme introduced in [12] is used in [9] to solve the two layer shallow water system. Well-balanced and positivity preserving central and central-upwind schemes have been derived in [6, 23].

The shallow water equations considered in the above references consist of conservation of mass and balance of momentum, and have shown to be a good approximation for a variety of geophysical flows. Furthermore, the density is assumed constant. In stratified flows the density fluctuations are weak. Despite such small variations, the effect in the dynamics is important in the study of stratified fluids and marine density flows, among others. In that direction, a model for two-layer shallow water flows in channels was analyzed in [9] with applications to simulations of the flow through the Strait of Gibraltar. On the other hand, a model for two-layer shallow water flows was considered in [4]. The model look upon two layers of immiscible fluids where exchange of momentum is allowed. The authors observed that such system does not provide an explicit formula for the eigenstructure, which is needed for numerical schemes based on approximate Riemann solvers. A relaxation approach was proposed to better access to the eigenstructure of the system. A multi-layer shallow water flow model can be found in [5], and robust well balanced schemes have been derived in [8].

In the present work, we propose a model for shallow water flows where horizontal density fluctuations are taken into account. The model is obtained by vertically averaging the Euler equations. All variables, including the density are vertically averaged and can have horizontal variations. In a two-layer or multi-layer shallow water flow, one can assume that the density is piece-wise constant and changing across each layer. The variables evolved in the present model can be interpreted as the total contribution of all layers by vertically averaging each conserved variable from the bottom to the top surface. Under such procedure, we lose information about the interface between each layer and can only observe the overall contribution. However, we note that the eigenstructure in the new setting has explicit simple formulas that reduce back to the standard equations when the density does not fluctuate. The system is hyperbolic with an eigenstructure that includes the usual shock/rarefaction waves of the shallow water equations plus a contact discontinuity associated to density jumps. The contact discontinuity is a degenerate field across which the pressure and velocity are preserved, representing the corresponding Riemann invariants. Steady states in this model arise when a delicate balance between flux gradients and source terms occurs. For constant density, smooth steady states are characterized by constant discharge and energy. A new class of steady states at rest appears in the present setting. For a flat topography, such steady states at rest are characterized by a constant pressure.

In this work we also propose a Roe-type upwind scheme for the model, and a technique is used to systematically find Roe matrices and ensure conservation of the scheme at a discrete level. Our numerical scheme preserves both types of steady states at rest. The usual steady states at rest are preserved by finding an appropriate local linearizations of the source terms that recognize their equilibrium with the flux differences. Recognition of the other type of steady states at rest is a straightforward consequence of conservation. As mentioned above, the two Riemann invariants associated to the contact discontinuity are the pressure and velocity. Pressure spurious oscillations can arise near those waves if no additional mechanisms are implemented in the scheme to recognize such invariants. A detailed analysis of pressure oscillations in compressible multifluids is done in [3]. A primitive formulation to remove such oscillations is implemented in [19], and hybrid approaches to multimaterial/multiphase flows can be found in [20, 21]. In the present setting, we consider water with different densities as two different phases and apply a hybrid strategy consisting of integrating the Riemann invariants near the contact discontinuity (primitive equations), and reverting back to the conserved variables away from it. This process enables the scheme to recognize the Riemann invariants and correctly captures the flow near all the waves and jump discontinuities. We note that this hybrid algorithm can be applied to any numerical scheme.

A related model for shallow water flows with horizontal potential temperature gradients was presented in [11] for the study of the formation of ocean currents. It is based on [31], and it is known as the Ripa system. The high-resolution non-oscillatory central-upwind scheme presented in [11] is well balanced and satisfies the positivity-preserving property. As in the model with density fluctuations, jumps between warm and cold water are represented by contact discontinuities, with pressure and velocity as the corresponding Riemann invariants. The numerical scheme in [11] avoids spurious pressure oscillations near those interfaces using the interface tracking method in [10] and treating warm and cold water as two different fluids. Different contributions and approaches have appeared recently for the Ripa system. A relaxation technique for the exact capture of steady states is implemented in [13], where entropy inequalities of the system are provided. The scheme is also positivity preserving and entropy satisfying. A well-balanced central finite volume scheme was derived in [36]. A suit of numerical example carefully chosen are also included to test different aspects of the scheme such as the effect of removing well-balance in the algorithm. In [35], Riemann solvers are analyzed to derive a HLLC scheme that enjoys the well-balance, positivity preserving and entropy dissipative properties. A well-balanced WENO scheme can also be found in [17].

The paper is structured as follows. In Sect. 2 we provide a description of the system (5), its properties, and the challenges that these properties pose for the numerical methods considered here. We leave the derivation of the model to Appendix B. In Sect. 3 we describe the proposed hybrid numerical scheme and prove that it is well balanced, i.e., it preserves steady states at rest, steady states appearing due to a balance between water depth and density to keep the pressure constant, and correctly computes the flow near water interfaces with density jumps. We provide all the details of the 1-D scheme and briefly describe the 2-D extension, leaving the details to Appendix A. In Sect. 4, one shows 1-D numerical results to illustrate all the properties the scheme. Section 5 adds 2-D numerical tests including perturbations to steady states, radial dam breaks and formation of coherent structures as a result of the interaction between fluids with different densities. We end this section with the conclusions.

2 The Model and Its Properties

The model for shallow water flows in one and two dimension has been extensively used in the past to test a variety of numerical models. Here we account for the effects of horizontal density gradients in the time evolution of the fluid. In conservation form, the model reads

$$\begin{aligned} \begin{pmatrix} \rho h \\ \rho h u \\ \rho h v \\ h \end{pmatrix}_t \,+\, \begin{pmatrix} \rho h u \\ \rho h u^2+\frac{g}{2} \rho h^2 \\ \rho h uv \\ h u \end{pmatrix}_x \,+\, \begin{pmatrix} \rho h v \\ \rho huv \\ \rho h v^2+\frac{g}{2} \rho h^2 \\ h v \end{pmatrix}_y \,=\, \begin{pmatrix} 0 \\ -g \rho h B_x \\ -g \rho h B_y \\ 0 \end{pmatrix}, \end{aligned}$$
(1)

where h(xyt) denotes the depth of the layer at a location (xy) and time t, u(xyt) and v(xyt) the velocities in each direction x and y respectively, \(\rho (x,y,t)\) is the vertically averaged density, B(xy) the bottom topography and g the acceleration of gravity. The model can be derived by vertically averaging the Euler equations and allowing for horizontal density fluctuations. We leave the details to Appendix B. For ease of notation, we will denote the pressure by \(p=\frac{g}{2} \rho h^2\), which is actually the vertically integrated pressure, as observed in Appendix B. The density is horizontally advected by the fluid. This can be seen by combining the first and last equations.

The model in [11] with applications to ocean currents is derived by vertically averaging a multi-layer ocean model. Their model incorporates the horizontal temperature gradients, which results in the variation of fluid density in each layer. Despite the fact that our extra variable is the density \(\rho \) and the extra variable in [11] is a rescaled potential temperature \(\theta \), one can go mathematically from their model to system (1) by replacing h by \(\rho h\) and \(\theta \) by \(1/\rho \), except in the source term where \(\theta \) is replaced by \(\rho \).

System (1) consists of conservation of mass; balance of momentum with source terms given by the topography and a hydrostatic pressure; and advection of the vertically averaged density. In quasilinear form, the system reads

$$\begin{aligned} \begin{pmatrix} \rho h \\ \rho h u \\ \rho h v \\ h \end{pmatrix}_t + \begin{pmatrix} 0 &{} 1 &{} 0 &{} 0 \\ \frac{g}{2} h-u^2 &{} 2 u &{} 0 &{} \frac{g}{2} \rho h \\ -uv &{} v &{} u &{} 0 \\ -u/\rho &{} 1/\rho &{} 0 &{} u \end{pmatrix} \begin{pmatrix} \rho h \\ \rho h u \\ \rho h v \\ h \end{pmatrix}_x + \begin{pmatrix} 0 &{} 0 &{} 1 &{} 0 \\ - uv &{} v &{} u &{} 0 \\ \frac{g h }{2} -v^2 &{} 0 &{} 2 v&{} \frac{g}{2} \rho h \\ -v/\rho &{} 0 &{} 1/\rho &{} v \end{pmatrix} \begin{pmatrix} \rho h \\ \rho h u \\ \rho h v \\ h \end{pmatrix}_y = \begin{pmatrix} 0 \\ -g\rho h B_x \\ -g\rho h B_y \\ 0 \end{pmatrix}, \end{aligned}$$
(2)

where the coefficient matrices and their corresponding eigenvalues and eigenvectors are given by

$$\begin{aligned} A = \begin{pmatrix} 0 &{} 1 &{} 0 &{} 0 \\ \frac{c^2}{2} -u^2 &{} 2 u &{} 0 &{} \frac{\rho c^2}{2} \\ -uv &{} v &{} u &{} 0 \\ -u/\rho &{} 1/\rho &{} 0 &{} u \end{pmatrix}, \Lambda ^A = \begin{pmatrix} u - c &{} 0 &{} 0 &{} 0 \\ 0 &{} u &{} 0 &{} 0 \\ 0 &{} 0 &{} u &{} 0\\ 0 &{} 0 &{} 0 &{} u+c \end{pmatrix}, {\mathbf{R }}^A = \begin{pmatrix} 1 &{} 1 &{} 0 &{} 1 \\ u-c &{} u &{} 0 &{} u+c \\ v &{} 0 &{} 1 &{} v \\ 1/\rho &{} -1/\rho &{} 0 &{} 1/\rho \end{pmatrix}, \end{aligned}$$
(3)

and

$$\begin{aligned} B = \begin{pmatrix} 0 &{} 0 &{} 1 &{} 0 \\ -uv &{} v &{} u &{} 0 \\ \frac{c^2}{2}-v^2 &{} 0 &{} 2v &{} \frac{\rho c^2}{2} \\ -v/\rho &{} 0 &{} 1/\rho &{} v \end{pmatrix}, \Lambda ^B = \begin{pmatrix} v - c &{} 0 &{} 0 &{} 0 \\ 0 &{} v &{} 0 &{} 0 \\ 0 &{} 0 &{} v &{} 0\\ 0 &{} 0 &{} 0 &{} v+c \end{pmatrix}, {\mathbf{R }}^B = \begin{pmatrix} 1 &{} 1 &{} 0 &{} 1 \\ u &{} 0 &{} 1 &{} u \\ v-c &{} v &{} 0 &{} v+c \\ 1/\rho &{} -1/\rho &{} 0 &{} 1/\rho \end{pmatrix}, \end{aligned}$$
(4)

where \(c=\sqrt{gh}\) is the speed of sound.

Each coefficient matrix has a double eigenvalue. However, each coefficient matrix has a complete set of eigenvectors provided that \(c>0\). Formally, the system is hyperbolic and for each unit vector \((\alpha , \beta )\), the matrix

$$\begin{aligned} \alpha A + \beta B = \begin{pmatrix} 0 &{} \alpha &{} \beta &{} 0 \\ \alpha \left( \frac{c^2}{2}-u^2 \right) - \beta uv &{} 2\alpha u+\beta v &{} \beta u &{} \alpha \frac{\rho c^2}{2}\\ \beta \left( \frac{c^2}{2} - v^2 \right) -\alpha u v &{} \alpha v &{} \alpha u+2\beta v &{} \beta \frac{\rho c^2}{2} \\ -(\alpha u+\beta v) /\rho &{} \alpha /\rho &{} \beta /\rho &{} \alpha u+\beta v \end{pmatrix} \end{aligned}$$

has eigenstructure

$$\begin{aligned}&\Lambda ^{\alpha A+\beta B} = \begin{pmatrix} \alpha u+\beta v -c &{} 0 &{} 0 &{} 0\\ 0 &{} \alpha u+\beta v &{} 0 &{} 0 \\ 0 &{} 0 &{} \alpha u+\beta v &{} 0 \\ 0 &{} 0 &{} 0 &{} \alpha u+ \beta v +c \end{pmatrix},\\&R^{\alpha A+\beta B} = \begin{pmatrix} 1 &{} 1 &{} 0 &{} 1 \\ u-\alpha c &{} u &{} \beta &{} u+\alpha c \\ v - \beta c &{} v &{} -\alpha &{} v+\beta c \\ 1/\rho &{} -1/\rho &{} 0 &{} 1/\rho \end{pmatrix}, \end{aligned}$$

which forms a complete set of eigenvectors provided that \(c>0\). That is, strict hyperbolicity is lost for \(h = 0\), when eigenvectors coincide, representing a so-called “dry state”.

We note that the model reduces to the standard form when \(\rho \) is uniform in x and y. In that case, we recover the familiar shallow water equations if we remove one of the redundant equation for h, and combining the first and last columns in the coefficient matrices

$$\begin{aligned} \begin{pmatrix} h \\ h u \\ h v \end{pmatrix}_t + \begin{pmatrix} 0 &{} 1 &{} 0 \\ c^2-u^2 &{} 2 u &{} 0 \\ -uv &{} v &{} u \end{pmatrix} \begin{pmatrix} h \\ h u \\ h v \end{pmatrix}_x + \begin{pmatrix} 0 &{} 0 &{} 1 \\ - uv &{} v &{} u \\ c^2 -v^2 &{} 0 &{} 2 v \end{pmatrix} \begin{pmatrix} h \\ h u \\ h v \end{pmatrix}_y = \begin{pmatrix} 0 \\ -g h B_x \\ -g h B_y \end{pmatrix}. \end{aligned}$$

The term \((c^2-u^2)(\rho h)_x\) in Eq. (3) that usually appears in the x- momentum equation has now split into \((c^2/2-u^2)(\rho h)_x+g\rho h/2 h_x\), and analogously for the y- momentum equation in the 2-D case.

2.1 The 1-D System

A simpler 1-D version of the above system is obtained when we assume that the flow moves only in, say, the x direction. In that case the velocity in the y direction \(v = 0\) vanishes, and all the quantities are independent of y. The model for shallow water flows in one dimension has been extensively used in the past to test a variety of numerical models. The derivation of the numerical scheme, as well as important properties of the model and numerical method are easier to analyze in one dimension. For instance, steady-sate flows are easy to visualize in those cases. The model is given by the following set of equations:

$$\begin{aligned}&\partial _t (\rho h) + \partial _x( \rho h u ) = 0, \end{aligned}$$
(5a)
$$\begin{aligned}&\partial _t (\rho h u)+\partial _x \left( \rho h u^2+\frac{g}{2}\rho h^2 \right) = -g\rho h B_x , \end{aligned}$$
(5b)
$$\begin{aligned}&\partial _t h+ \partial _x (hu) = 0 . \end{aligned}$$
(5c)

One can connect with the two-layer model in [4] as follows. Each layer has a corresponding depth (\(h_k, k=1,2\)), velocity (\(u_k, k=1,2\)) and constant density (\(\rho _k, k=1,2\)). Any quantity can be vertically integrated as \(\overline{(\cdot )} = (h_1 (\cdot )_1 + h_2 (\cdot )_2 )/(h_1+h_2)\). In particular, one can think of our density as \(\bar{\rho }= (h_1 \rho _1+h_2 \rho _2)/(h_1+h_2)\), which satisfies the equation

$$\begin{aligned} \partial _t \bar{\rho }= \frac{1}{h_1+h_2} \left[ \bar{\rho }\partial _x ( (h_1+h_2) \bar{u}) - \partial _x ( (h_1+h_2) \overline{\rho u} ) \right] \approx - \bar{u} \partial _ x \bar{\rho }, \end{aligned}$$

when \(\overline{\rho u} \approx \bar{\rho }\bar{u}\). This supports the idea that the density is simply advected by the flow. Conservation of mass and balance of momentum can be approximated similarly by adding the corresponding equations in each layer.

The resulting system (5) is hyperbolic. The spectral information extends that of the regular shallow water equations. Namely, the Jacobian matrix has three eigenvalues, two of which reduce to the standard eigenvalues when \(\rho \) is constant. The extra eigenvalue is a degenerate field and is associated to the horizontal density fluctuations.

The quasilinear form of the reduced system becomes

$$\begin{aligned} \partial _t \begin{pmatrix} \rho h \\ \rho h u \\ h \end{pmatrix} + \begin{pmatrix} 0 &{} 1 &{} 0 \\ \frac{c^2}{2} -u^2 &{} 2u &{} \rho \frac{c^2}{2} \\ - u/\rho &{} 1/\rho &{} u \end{pmatrix} \partial _x \begin{pmatrix} \rho h \\ \rho h u \\ h \end{pmatrix} = \begin{pmatrix} 0 \\ -g\rho h B_x \\ 0 \end{pmatrix}, \end{aligned}$$
(6)

with eigenvectors and eigenvalues

$$\begin{aligned} {\mathbf{R }}^\text {c} = \begin{pmatrix} 1 &{} 1 &{} 1 \\ u-c &{} u &{} u+c \\ 1/\rho &{} - 1/\rho &{} 1/\rho \end{pmatrix} \qquad \qquad \Lambda = \begin{pmatrix} u-c &{} 0 &{} 0\\ 0 &{} u &{} 0 \\ 0 &{} 0 &{} u+c \end{pmatrix}. \end{aligned}$$
(7)

Strict hyperbolicity is lost for \(h = 0\), when eigenvectors coincide, representing a so-called “dry state”.

2.2 Steady States

Steady-state flows arise when a delicate balance between flux gradients and source terms occurs. That is,

$$\begin{aligned} (\rho h u)_x = 0, (h u)_x = 0, (\rho h u^2+g\rho h^2 /2)_x = -g\rho h B_x. \end{aligned}$$
(8)

Here \(Q = \rho hu\), known as the flow rate or discharge, is constant. We immediately conclude that either the state is at rest \(u =0\), or the density \(\rho \) is constant. Smooth steady-state solutions in the absence of density gradients are characterized by two invariants, the flow rate Q, and E, the energy per unit of cross sectional area

$$\begin{aligned} \rho = \text {Constant}, \qquad \qquad Q \equiv \rho h u = \text {Constant}, \qquad \qquad E \equiv \dfrac{1}{2} \rho u^2 + g \rho (h+B) = \text {Constant}, \end{aligned}$$
(9)

among which it is easy to recognize the steady state at rest

$$\begin{aligned} \rho = \text {Constant}, \qquad \qquad u = 0, \qquad \qquad h + B = \text {Constant.} \end{aligned}$$
(10)

After some manipulations of the equations that are valid for smooth flows, we get

$$\begin{aligned} \begin{array}{lllllllll} Q_t &{} + &{} u Q_x &{} + &{} h E_x &{} + &{} -h \left( \frac{u^2}{2}+gB+\frac{c^2}{2} \right) \rho _x &{} = &{} 0, \\ E_t &{} + &{} g Q_x &{} + &{} u E_x &{} + &{} \frac{u c^2}{2} \rho _x &{} = &{} 0, \\ &{} &{}&{}&{}\quad \rho _t &{}+&{} u \rho _x &{} = &{} 0. \end{array} \end{aligned}$$
(11)

As mentioned above, the Eqs. (11) are valid only when the flow is smooth. Near jump discontinuities, the conserved variables \((\rho h,\rho h u,h)^T\) must be integrated to well resolve the flow. In the case of constant density, the equilibrium variables Q and E have been used in [28] to preserve steady states with non-vanishing velocity.

Other smooth steady states at rest, due to a balancing between the topography and pressure, are characterized by

$$\begin{aligned} u=0, \quad \quad \partial _x\left( \frac{g \rho h^2}{2} \right) = -g\rho h B_x. \end{aligned}$$
(12)

Since three variables are involved and just two conditions are imposed, the class has one degree of freedom. For any positive function h(x) and topography B(x), the solution for \(\rho \) is

$$\begin{aligned} \frac{g\rho (x) h(x)^2}{2} = p_o \exp \left( -2\int _{x_o}^x \frac{B_x(x)}{h(x)} dx \right) . \end{aligned}$$
(13)

For a flat topography, it simplifies to

$$\begin{aligned} B= \text {Constant}, \qquad \qquad u = 0, \qquad \qquad \frac{g\rho h^2}{2} = p_o = \text {Constant.} \end{aligned}$$
(14)

We note that the steady states at rest described in (14) are not stable to perturbations in the following sense. For given boundary conditions and any steady state at rest of the form (14) \(g \rho (x) h(x)^2/2=p_o\), there are infinitely many states arbitrarily close to the initial state. For instance, any perturbation in the water depth \(h(x)+\epsilon (x)\) with \(\epsilon \) supported in the interior of the domain, a corresponding \(\rho _\epsilon = 2 p_o/(h(x)+\epsilon (x))^2/g\) defines a new steady state. In Sect. 4.3, a numerical test is done where the water depth is initially perturbed. Once the perturbation leaves the domain, the flow returns to a steady state. However, the ending state is not necessarily the same as the initial one.

2.3 Entropy Functions

For a given conservation law, finding entropy functions can help choosing the correct weak solution [24, 29]. The regular shallow water equations [1] and the Ripa system [13] are both endowed with entropy functions. The following proposition shows the details for model (5).

Proposition 1

System (5) is endowed with an entropy function

$$\begin{aligned} \mathcal{E} = hE-p, \end{aligned}$$
(15)

and entropy inequality

$$\begin{aligned} \mathcal{E}_t +(u ( \mathcal{E}+p))_x \le 0. \end{aligned}$$
(16)

Proof

We consider the quasilinear form of system (5) plus a friction term in the momentum equation

$$\begin{aligned} \begin{array}{lllll} (\rho h)_t &{}+&{} (\rho h u)_x &{}= &{} 0,\\ (\rho h u)_t &{}+&{} \left( \frac{c^2}{2}-u^2 \right) (\rho h)_x +2 u (\rho h u)_x +\frac{g}{2} \rho h (h)_x &{} = &{} -gh \rho B_x-\epsilon u,\\ h_t &{} - &{} \frac{u}{\rho } (\rho h)_x +\frac{1}{\rho } (\rho hu)_x +u (h)_x &{} = &{} 0, \end{array} \end{aligned}$$
(17)

where \(\epsilon \) is the corresponding friction coefficient.

The kinetic part of the equation satisfies \(( \frac{1}{2} \rho h u^2)_t = u(\rho h u)_t-\frac{1}{2}u^2 (\rho h)_t\), implying

$$\begin{aligned} \left( \frac{1}{2} \rho h u^2 \right) _t +\frac{3}{2} u^2 (\rho h u)_x-u^3 (\rho h)_x+u c^2 \left( \frac{1}{2}(\rho h)_x+\frac{\rho }{2}(h)_x+\rho B_x\right) = -\epsilon u^2 \end{aligned}$$
(18)

We note that \(\mathcal{E} = hE-p = \rho h u^2/2+gBh\rho +p\). The pressure \(p = \frac{g}{2} \rho h h\) satisfies

$$\begin{aligned} p_t = -\frac{g}{2}h (\rho hu)_x-\frac{g}{2} \rho h (hu)_x. \end{aligned}$$
(19)

Re-writing \(hu = \rho h u h/ (\rho h) \), we get

$$\begin{aligned} p_t = -gh (\rho hu)_x-\frac{g}{2} \rho hu (h)_x+\frac{g}{2}hu (\rho h)_x. \end{aligned}$$
(20)

Combining Eqs. (18) and (20), we get

$$\begin{aligned} \mathcal{E}_t = -(gh Q)_x-(g Q B)_x+u^3 (\rho h)_x-\frac{3}{2}u^2 Q_x-\epsilon u^2 = -(gh Q)_x-(g Q B)_x - \frac{1}{2}\left( \rho h u^3 \right) _x-\epsilon u^2, \end{aligned}$$
(21)

concluding the proof. \(\square \)

We note that the entropy function reduces to \(\mathcal{E} = \rho h \frac{1}{2} u^2+ \frac{g}{2}\rho ^{-1} (\rho h)^2 + c^2 \rho B\). It is in fact a convex function of the variables \(\rho h,u,\rho \).

2.4 The Riemann Invariants Across Waves

Further information about the type of waves can be obtained for the simplified 1-D model. This is crucial for the type of numerical algorithm to be considered in this work. We now proceed to compute the Riemann invariants across each wave. The first family has eigenvector \({\mathbf{r }}^c_1 = (1,u-c,1/\rho )^T\). Changes across this wave satisfy

$$\begin{aligned} \frac{\delta (\rho h)}{1} = \frac{\delta (\rho hu)}{u-c} = \rho \delta (h), \end{aligned}$$
(22)

which implies

$$\begin{aligned} \delta \rho =0, \delta u = -\frac{c}{\rho h} \delta (\rho h) = -\sqrt{g} h^{-1/2}\delta h = -\sqrt{g} 2 \delta h^{1/2}, \end{aligned}$$
(23)

and it gives us the two Riemann invariants for the first family: \(\rho \), \(u+2c\). Analogously, the Riemann invariants for the third family are \(\rho \) and \(u-2c\).

The second family is associated with the interfaces between regions of water with density jumps. The eigenvector for this family is \({\mathbf{r }}_2^c = (1,u,-1/\rho )^T\). Changes across this wave satisfy

$$\begin{aligned} \frac{\delta (\rho h)}{1} = \frac{\delta (\rho hu)}{u}=-\rho \delta (h). \end{aligned}$$
(24)

Since \(\delta (\rho hu) = u \delta (\rho h)\), then \(\delta u=0\), providing the first Riemann invariant. On the other hand,

$$\begin{aligned} \delta (\rho h) = -\rho \delta (h), \end{aligned}$$
(25)

or \(2\delta \log (h) = - \delta \log (\rho )\). The second Riemann invariant is the vertically integrated pressure \(p = \frac{g}{2}\rho h^2\). This indicates that the second family is a contact discontinuity and a degenerate field. That information together with the eigenvector and eigenvalues are summarized in Table 1. We have 2 shock or rarefaction waves and a contact discontinuity. In Table 1, we also show the information for a primitive formulation to be explained in the next section.

2.5 A Hybrid Strategy to Avoid Spurious Pressure Oscillations

Shallow water flows have a rich variety of steady states when the flux gradients are in balance with the corresponding source terms. From all of them, most numerical methods attempt to recognize those at rest, where the velocity vanishes and the total height is constant. Recognizing more general steady-states may involve non-trivial rootfinding to go from conserved to equilibrium variables [28]. The model here offers a larger family of steady states when the topography is flat, the velocity vanishes, and a balance between the density and the water depth occurs, eventuating in a constant pressure. The state-of-the-art upwind scheme will trivially recognize those states because the flux gradient vanishes and the scheme is conservative.

In the case where the pressure and velocity are constant but not necessarily vanishing, the corresponding data is associated with the contact discontinuity. The pressure equilibrium may be disturbed by the numerical scheme in such situations. The density changes are weak in stratified flows and such errors may not be too strong. However, strong spurious pressure oscillations may arise in other potential applications with strong density interfaces. Furthermore, the same techniques here can be implemented in the model in [11] where changes in potential temperature can be more pronounced. Spurious oscillations have also been reported in multimaterial flows [3, 10, 19, 20]. The density here plays the role of the fluid composition, where regions of water separated by density interfaces are considered to be the two species. To rectify those numerical artifacts in the pressure and velocity, the authors in [11] followed their interface tracking strategy in [10]. In the present paper, we use a hybrid algorithm that detects the lack of changes in pressure and velocity across the contact discontinuity.

The hybrid strategy consists of the following idea. The use of the conserved variables \({\mathbf{W }}^\text {c} = (\rho h,\rho hu,h)^T\) is necessary for the numerical scheme to correctly capture the flow near shock waves. A disadvantage of this procedure occurs near the contact discontinuity, where the numerical scheme is in general not able to maintain the pressure equilibrium. However, such contact discontinuity is a degenerate field with parallel characteristics, allowing us to use non-conservative formulations. A particularly helpful choice is the use of primitive variables \({\mathbf{W }}^\text {nc} = (u,p,\rho )^T\). Any consistent discretization of the primitive equations will trivially recognize the Riemann invariants for that wave, maintaining constant velocity and pressure at a discrete level. We also require that the hybrid strategy recognizes when \(\rho \) is constant, reducing back to the standard shallow water system. This can be done by using the two Riemann invariants plus the density as the primitive variables. The primitive equations are

$$\begin{aligned} \begin{pmatrix} u \\ p \\ \rho \end{pmatrix}_t + \begin{pmatrix} u &{} (\rho h)^{-1} &{} 0 \\ \rho h c^2 &{} u &{} 0 \\ 0 &{} 0 &{} u \end{pmatrix} \begin{pmatrix} u \\ p \\ \rho \end{pmatrix}_x = \begin{pmatrix} -g B_x \\ 0 \\ 0 \end{pmatrix}. \end{aligned}$$
(26)

The switch from the conservative to primitive variables has to be done near density interfaces. We determine those interfaces when the difference between values of \(\rho \) at neighboring cells exceed a threshold. The hybrid strategy is then

$$\begin{aligned} \text {Update cell { i} using } \left\{ \begin{array}{ll} {\mathbf{W }}^\text {c} &{} \text { if } \,\, \max _{i-1 \le i' \le i+1}( |\rho _{i'+1}-\rho _{i'}| ) < \rho _o, \\ \\ {\mathbf{W }}^\text {nc} &{} \text {otherwise.} \end{array} \right. \end{aligned}$$
(27)

Unless otherwise noted, we choose the threshold to be \(10\%\) of the maximum variation in the density at the initial time

$$\begin{aligned} \rho _o = \frac{\max _{i}\rho _i - \min _i \rho _i}{10}. \end{aligned}$$
(28)

The strategy described above can be applied to any numerical scheme. In the present work we are using the upwind scheme, for which we need to know the eigenvalues and eigenvectors. For the non-conservative system (26), the eigenvectors are

$$\begin{aligned} {\mathbf{R }}^\text {nc} = \begin{pmatrix} c &{} 0 &{} c \\ -\rho h c^2 &{} 0 &{} \rho h c^2 \\ 0 &{} 1 &{} 0 \end{pmatrix}. \end{aligned}$$
(29)

We now summarize in Table 1 all the spectral information derived above for the conservative and primitive formulations.

Table 1 Spectral information and Riemann invariants for each wave family for the conservative and primitive formulations

3 Numerical Scheme

Hyperbolic conservation laws involve several theoretical and numerical difficulties. The most known of them being the formation of shock waves in finite time [24]. Numerically, the schemes need to be conservative and accurate near shock waves. On the other hand, a particular aspect of shallow water flows is the existence of steady-state solutions when a balance between the flux gradients and the corresponding source terms occurs. Numerical schemes that respect steady states at rest are known as well-balanced schemes. The well-balance property is important as it enables the scheme to be accurate near steady states.

Different advantages can be obtained in different numerical schemes. Central schemes are advantageous in that the positivity-preserving property can be incorporated with a special polynomial reconstruction of the data and a modified CFL restriction [22, 23]. Roe-type upwind schemes on the other hand are usually less dissipative near shock waves. In this section we present a Roe-type numerical scheme for shallow water flows with horizontal density gradients. The numerical method is well balanced and preserves non-standard steady-state flows where the topography is flat and the pressure is constant by a special balance between the density and the water depth. The well balance property is achieved by systematically using discrete forms of the product rule in the process of going from the conserved to the quasi-linear form. Similar techniques have been used in [2].

3.1 Roe-Type Upwind Schemes

Let us consider a general hyperbolic balance law in two-dimensions

$$\begin{aligned} \mathbf{W }_t + (\mathbf{F }_A(\mathbf{W }))_x+(\mathbf{F }_B(\mathbf{W }))_y = \mathbf{S }( \mathbf{W }), \end{aligned}$$
(30)

where \(\mathbf{W }\) is the vector of conserved variables; \(\mathbf{F }_A(\mathbf{W }), \mathbf{F }_B(\mathbf{W })\) are the flux functions in the x and y directions, respectively; and \(\mathbf{S }\) is the source term. The flux functions need to satisfy the conditions for hyperbolicity. Namely, for each unit vector \((\alpha ,\beta )\) the projection \(\alpha A+\beta B\) of the Jacobians \(A=\partial F_A/\partial W, B=\partial F_B / \partial W\) has real eigenvalues and a complete set of eigenvectors. The source terms are known as non-conservative products when they involve derivatives of the solution. The Rankine–Hugoniot conditions change when non-conservative products are present, resulting in more theoretical challenges. In other circumstances, the source terms physically derived depend on derivatives of other external parameters involved in the problem, like the topography, as in the present work. The source terms can usually be split into two terms involving contributions in the x or y direction only, say \(\mathbf{S } = \mathbf{S }_A +\mathbf{S }_B\).

In quasi-linear form, the system reads

$$\begin{aligned} \mathbf{W }_t + A(\mathbf{W })\mathbf{W }_x + B(\mathbf{W }) \mathbf{W }_y=\mathbf{S }^A(\mathbf{W }) + S^B(\mathbf{W }), \end{aligned}$$
(31)

where \(A(\mathbf{W }), B(\mathbf{W })\) are the two coefficient matrices in the x and y directions, respectively, such that \((\mathbf{F }_A(W))_x = A(\mathbf{W }) \mathbf{W }_x, (\mathbf{F }_B(\mathbf{W }))_y = B(\mathbf{W })\mathbf{W }_y\) as described above. In the upwind scheme shown below and following [32], we require Roe matrices \(A(\mathbf{W }_\ell ,\mathbf{W }_r)\) and \(B(\mathbf{W }_\text {s}, \mathbf{W }_\text {n})\) satisfying the following conditions:

  1. (a)

    \(A(\mathbf{W }_\ell ,\mathbf{W }_r)\), \(B(\mathbf{W }_{s},\mathbf{W }_{n})\) have real eigenvalues and a complete set of eigenvectors,

  2. (b)

    \(\Delta _x \mathbf{F }_A = A(\mathbf{W }_\ell , \mathbf{W }_r) \Delta _x W\), \(\Delta _y \mathbf{F }_B = B(W_\text {s}, \mathbf{W }_{n}) \Delta _y W\), and

  3. (c)

    \(A(\mathbf{W }_\ell ,\mathbf{W }_r) \rightarrow A(\mathbf{W })\) as \(\mathbf{W }_\ell , \mathbf{W }_r \rightarrow \mathbf{W }\), \(B(\mathbf{W }_\text {s},\mathbf{W }_\text {n}) \rightarrow B(\mathbf{W })\) as \(\mathbf{W }_{s}, \mathbf{W }_\text {n} \rightarrow \mathbf{W }\).

Here \(\Delta _x (\cdot ) = (\cdot )_\ell - (\cdot )_r\) is the data difference between right and left cells, \(\Delta _y (\cdot ) = (\cdot )_\text {n} - (\cdot )_\text {s}\) is the data difference between north and south cells.

We partition the 2-D domain into the grid cells \(I_{(i,j)} := [x_{i-\frac{1}{2}},x_{i+\frac{1}{2}}] \times [y_{j-\frac{1}{2}},y_{j+\frac{1}{2}}] \), where \(\Delta x, \Delta y\) are the spatial scales, \(x_{i\pm \frac{1}{2}} = x_i\pm \frac{\Delta x}{2}\), \(y_{j\pm \frac{1}{2}} = y_j\pm \frac{\Delta y}{2}\), and \((x_i, y_j)\) is the center of the grid cell. For ease of notation, we denote the Roe matrices in each cell (ij) by \(A_{i\pm \frac{1}{2},j},B_{i,j\pm \frac{1}{2}}\). The 2-D scheme has the general form

$$\begin{aligned} \mathbf{W }_{i,j}^{n+1}= & {} \mathbf{W }_{i,j}^n-\dfrac{\Delta t}{\Delta x} \left\{ A^+_{i-\frac{1}{2},j}\left( \mathbf{W }_{i,j}^n-\mathbf{W }_{i-1,j}^n\right) - \Delta x\; \mathbf{S }_{A,i-\frac{1}{2},j}^+\right. \nonumber \\&\left. +\,A^-_{i+\frac{1}{2},j}\left( \mathbf{W }_{i+1,j}^n-\mathbf{W }_{i,j}^n\right) - \Delta x\; \mathbf{S }_{A,i+\frac{1}{2},j}^- \right\} \nonumber \\&-\,\dfrac{\Delta t}{\Delta y} \left\{ B^+_{i,j-\frac{1}{2}}\left( \mathbf{W }_{i,j}^n-\mathbf{W }_{i,j-1}^n\right) -\Delta y\; \mathbf{S }_{B,i,j-\frac{1}{2}}^+ \right. \nonumber \\&\left. +\,B^-_{i,j+\frac{1}{2}}\left( \mathbf{W }_{i,j+1}^n-\mathbf{W }_{i,j}^n\right) -\Delta y\; \mathbf{S }_{B,i,j+\frac{1}{2}}^- \right\} .\nonumber \\ \end{aligned}$$
(32)

Here,

$$\begin{aligned} \begin{array}{lll} A^+\Delta _x \mathbf{W } -\Delta x\; \mathbf{S }_A^+= \displaystyle {\sum _{\lambda _k^A> 0}} (\alpha _k^A \lambda _k^A - \beta _k^A) \mathbf{r }_k^A ~, \quad A^-\Delta _x \mathbf{W } - \Delta x\; \mathbf{S }_A^- = \displaystyle {\sum _{\lambda _k^A \le 0} } (\alpha _k^A \lambda _k^A - \beta _k^A) \mathbf{r }_k^A, \\ B^+\Delta _y \mathbf{W } -\Delta y\; \mathbf{S }_B^+ = \displaystyle {\sum _{\lambda _k^B > 0}} (\alpha _k^B \lambda _k^B - \beta _k^B) \mathbf{r }_k^B ~, \quad B^-\Delta _y \mathbf{W } -\Delta y\; \mathbf{S }_B^-= \displaystyle {\sum _{\lambda _k^B \le 0} } (\alpha _k^B \lambda _k^B - \beta _k^B) \mathbf{r }_k^B. \end{array} \end{aligned}$$
(33)

where \(\lambda _k^A, \lambda _k^B\) and \(\mathbf{r }_k^A, \mathbf{r }_k^B\) are the eigenvalues and eigenvectors of some local linearization of each coefficient matrix, to be specified, and \(\alpha _k^A,\alpha _k^B\) and \(\beta _k^A,\beta _k^B\) are the wave strengths associated with the flux gradient and the source

$$\begin{aligned} \Delta _x \mathbf{W }=\sum _{k}\alpha _k^A \mathbf{r }_k^A , \quad \Delta x \, \mathbf{S }^A=\sum _{k}\beta _k^A \mathbf{r }_k^A , \qquad \Delta _y \mathbf{W }=\sum _{k}\alpha _k^B \mathbf{r }_k^B , \quad \Delta y \, \mathbf{S }^B =\sum _{k}\beta _k^B \mathbf{r }_k^B. \end{aligned}$$
(34)

Numerical Scheme in One Dimension

For a one-dimensional hyperbolic balance law

$$\begin{aligned} \mathbf{W }_t+(\mathbf{F }(\mathbf{W }))_x = \mathbf{S }, \; \; \mathbf{W }_t + A(\mathbf{W })\mathbf{W }_x=\mathbf{S }(\mathbf{W }), \end{aligned}$$
(35)

the upwind scheme [32] becomes

$$\begin{aligned} \mathbf{W }_i^{n+1}=\mathbf{W }_i^n-\dfrac{\Delta t}{\Delta x} \left\{ A^+_{i-\frac{1}{2}}\left( \mathbf{W }_i^n-\mathbf{W }_{i-1}^n\right) - \Delta x \; \mathbf{S }_{i-\frac{1}{2}}^++ A^-_{i+\frac{1}{2}}\left( \mathbf{W }_{i+1}^n-\mathbf{W }_{i}^n\right) - \Delta x \;\mathbf{S }_{i+\frac{1}{2}}^- \right\} . \end{aligned}$$
(36)

Here,

$$\begin{aligned} A^+\Delta \mathbf{W } -\Delta x \; \mathbf{S }^+= \displaystyle {\sum _{\lambda _k > 0}} (\alpha _k \lambda _k - \beta _k) \mathbf{r }_k ~, \qquad A^-\Delta \mathbf{W } -\Delta x \; \mathbf{S }^-= \displaystyle {\sum _{\lambda _k \le 0} } (\alpha _k \lambda _k - \beta _k) \mathbf{r }_k \end{aligned}$$
(37)

where \(\lambda _k\) and \(\mathbf{r }_k\) are the eigenvalues and eigenvectors of some local linearization of the flux jacobian, to be specified, and \(\alpha _k\) and \(\beta _k\) are the wave strengths associated with the flux gradient and the source

$$\begin{aligned} \Delta \mathbf{W }=\sum _{k}\alpha _k \mathbf{r }_k , \qquad \Delta x \, \mathbf{S }=\sum _{k}\beta _k \mathbf{r }_k. \end{aligned}$$
(38)

A superbee limiter has been used as described in [24] to make the numerical method second order accurate. The primitive formulation is applied in a number of cells near the contact discontinuity, and the scheme is second order accurate. The same happens to the conservative formulation away from the contact discontinuity. Formally, the order of accuracy could be affected only at the cells where the switch between formulations occurs. An entropy fix as in [24] have also been included. Such extensions do not not affect any of the properties described for the numerical scheme such as conservation or well balance. In the primitive formulation, the second order extension of the numerical scheme does not affect the preservation of the Riemann invariants up across a contact discontinuity. In such cases, the amplitudes in (37) vanish and the same happens when the second order correction is included.

3.2 Local Linearizations for the 1-D Model

Roe Matrices

In the setting above, the vector of conserved variables is \(\mathbf{W }=(\rho h,\rho hu,h)^T\). For simplicity, we show the derivation of the Roe matrix in the one-dimensional case, leaving the two-dimensional version to Appendix A. We systematically derive Roe matrices using the following idea. The coefficient matrix A appears when we decompose the momentum and density flux gradients quasi-linearly in derivatives of the conserved variables

$$\begin{aligned} \begin{array}{lll} \partial _x \left( \rho h u^2+\frac{g}{2} \rho h^2 \right) &{}= &{} \left( \frac{g}{2} h-u^2 \right) \partial _x (\rho h)+2u \partial _x(\rho h u)+\frac{g}{2} \rho h \partial _x (h), \\ \partial _x (h u) &{} = &{} -u/\rho \partial _x (\rho h)+1/\rho \partial _x(\rho hu)+u\partial _x (h). \end{array} \end{aligned}$$

One would like to repeat such decomposition by replacing derivatives by finite differences and the quantities in front of each derivative with a corresponding average/linearization. The manipulation of the flux differences to go from the conservative to the quasi-linear form at a discrete level is then done with the aid of the discrete expression

$$\begin{aligned} \Delta (ab) = a^\alpha \Delta b+ b_\alpha \Delta a, \; \text { where } a^\alpha =\alpha a_\ell +(1-\alpha )a_r, b_\alpha =(1-\alpha ) b_\ell +\alpha b_r, 0 \le \alpha \le 1. \end{aligned}$$
(39)

Particularly, we will focus on the values \(\alpha = \frac{1}{2}\) and \(\alpha = \frac{\sqrt{(\rho h)_\ell }}{\sqrt{(\rho h)_\ell }+\sqrt{(\rho h)_r}}\), resulting in the following two special averages

$$\begin{aligned} \overline{(\cdot )} = \frac{(\cdot )_\ell +(\cdot )_r}{2}, \text { and }\; \; \widehat{(\cdot )} = \frac{\sqrt{(\rho h)_\ell } (\cdot )_\ell + \sqrt{(\rho h)_r} (\cdot )_r}{\sqrt{(\rho h)_\ell }+\sqrt{(\rho h)_r}}. \end{aligned}$$
(40)

Applying the relation (39) to each component of the flux, we get

$$\begin{aligned} \Delta \left( \rho hu^2+\frac{g}{2}\rho h^2 \right) = \left( \frac{g}{2} \overline{h}-\widehat{u}^2 \right) \Delta (\rho h)+2 \widehat{u} \Delta (\rho h u) +\frac{g}{2} \overline{(\rho h)} \Delta (h), \end{aligned}$$
(41)

where \(\overline{ \rho h}=\frac{(\rho h)_\ell +(\rho h)_r}{2}\) and \(\widehat{u} = \frac{\sqrt{(\rho h)_\ell }u_\ell +\sqrt{(\rho h)_r} u_r}{\sqrt{(\rho h)_\ell }+\sqrt{(\rho h)_r}} = u^\alpha \) for \(\alpha =\frac{\sqrt{(\rho h)_\ell }}{\sqrt{(\rho h)_\ell }+\sqrt{(\rho h)_r}}\). We note that in the case where \(\rho \) is constant we recover the familiar expression \(\Delta (hu^2+gh/2)=(g\bar{h}-\widehat{u}^2)\Delta h+2\widehat{u}\Delta (hu)\).

Similarly, the last entry of the flux difference decomposes as

$$\begin{aligned} \Delta (hu) = h_\alpha \Delta u +u^\alpha \Delta h. \end{aligned}$$
(42)

Defining \(\widehat{1/\rho } = \frac{(h)_\alpha }{(\rho h)_\alpha }=\frac{\sqrt{(\rho h)_\ell }(1/\rho )_\ell +\sqrt{(\rho h)_r}(1/\rho )_r}{\sqrt{(\rho h)_\ell }+\sqrt{(\rho h)_r}}\), and using \((\rho h)_\alpha \Delta u= \Delta (\rho hu)- \widehat{u} \Delta (\rho h)\), we get

$$\begin{aligned} \Delta (hu) = -\widehat{u} \widehat{1/\rho } \Delta (\rho h)+\widehat{ 1/\rho } \Delta (\rho hu)+\widehat{u} \Delta h. \end{aligned}$$
(43)

The Roe matrix reads

$$\begin{aligned} A(\mathbf{W }_\ell , \mathbf{W }_r) = \begin{pmatrix} 0 &{} 1 &{} 0 \\ \frac{g}{2} \overline{h} -\widehat{u}^2 &{} 2 \widehat{u} &{} \frac{g}{2} \overline{ \rho h} \\ -\widehat{u} \widehat{ 1/\rho } &{} \widehat{1/\rho } &{} \widehat{u} \end{pmatrix}. \end{aligned}$$
(44)

The linearization for the corresponding eigensystem becomes

$$\begin{aligned} \widehat{ \mathbf{R } }= \begin{pmatrix} 1 &{} 1 &{} 1 \\ \widehat{u} - {\tilde{c}} &{} \widehat{u} &{} \widehat{u}+{\tilde{c}} \\ \widehat{1/\rho } &{} -\frac{\overline{h}}{\overline{ \rho h}} &{} \widehat{1/\rho } \end{pmatrix},\; \; \widehat{\Lambda }= \begin{pmatrix} \widehat{u} - {\tilde{c}} &{} 0 &{} 0 \\ 0 &{} \widehat{u} &{} 0 \\ 0 &{} 0 &{} \widehat{u}+{\tilde{c}} \end{pmatrix}, \end{aligned}$$
(45)

where

$$\begin{aligned} {\tilde{c}} = \sqrt{ \frac{g}{2} \left[ \overline{h} +\overline{\rho h} \widehat{1/\rho } \right] } \end{aligned}$$
(46)

is the linearized speed of propagation.

The primitive Eqs. (26) are in non-conservative form, and they are used near a degenerate field. For simplicity, we use the same averages as above.

Well-Balance Property

One still needs to choose a linearization for the source terms, and that will be done with considerations of well balance. The linearization in the source term will be chosen so that it balances with the flux differences in a steady state at rest. Such equilibrium occurs when \(h+B = \text {Constant}, u=0, \rho =\text {Constant}\) and appear due to a simple balance between the source term and the flux gradient. An appropriate discretization of the source term will ensure the exact balancing at the discrete level. In a lake at rest, \(\Delta h = -\Delta B\), which implies

$$\begin{aligned} \Delta \left( \frac{g}{2} \rho h^2 \right) = g \overline{\rho h} \Delta h = -\rho g\bar{h} \Delta B, \end{aligned}$$
(47)

when \(\rho \) is constant. The source term \(-g\rho h B_x\) in the conservative formulation must reduce to the above expression when \(\rho \) is constant. A convenient linearization for such source term that reaches the goals and also gives simplified expressions for the amplitudes is \(-\bar{\rho }\; {\tilde{c}}^2 \Delta B\). Similarly, the source term in the non-conservative formulation is easily linearized as \(-g \Delta B\).

The proposed numerical scheme is (36)–(38), with the local linearization \( \lambda _1 = \widehat{u} - {\tilde{c}}, \lambda _2 = \widehat{u}, \lambda _3 = \widehat{u}+{\tilde{c}}\),

$$\begin{aligned} \mathbf{R }^\text {c} = \begin{pmatrix} 1 &{} 1 &{} 1 \\ \widehat{u}- {\tilde{c}} &{} \widehat{u} &{} \widehat{u} + {\tilde{c}} \\ \widehat{1/\rho } &{} -\frac{\overline{h}}{\overline{\rho h}} &{} \widehat{1/\rho } \end{pmatrix}, \mathbf{R }^\text {nc} = \begin{pmatrix} {\tilde{c}} &{} 0 &{} {\tilde{c}}\\ - \overline{\rho h} {\tilde{c}}^2 &{} 0 &{} \overline{\rho h} {\tilde{c}}^2 \\ 0 &{} 1 &{} 0 \end{pmatrix}, \end{aligned}$$
(48)

and

$$\begin{aligned} \begin{array}{llllllllllll} \alpha _1^\text {c} &{} = &{} \dfrac{\left( \widehat{u}+ \frac{g}{2} \frac{\overline{h}}{{\tilde{c}}} \right) \Delta (\rho h) -\Delta (\rho hu) + \frac{g}{2}\frac{\overline{\rho h}}{{\tilde{c}}} \Delta h }{2{\tilde{c}}}, &{} \alpha _1^\text {nc} &{} = &{} \frac{\overline{\rho h} {\tilde{c}} \Delta u-\Delta p}{2\overline{\rho h} {\tilde{c}}^2}, &{} \beta _1^\text {c} &{} = &{} \frac{\bar{\rho }{\tilde{c}}\Delta B}{2}, &{} \beta _1^\text {nc} &{} = &{} -\frac{g \Delta B}{2 {\tilde{c}}}, \\ \alpha _2^\text {c} &{} = &{} -\dfrac{({\tilde{c}} - \frac{g}{2} \frac{\overline{h}}{{\tilde{c}}} ) \Delta (\rho h)-\frac{g}{2} \frac{\overline{\rho h}}{{\tilde{c}}} \Delta h}{{\tilde{c}}}, &{} \alpha _2^\text {nc} &{} = &{} \Delta \rho , &{} \beta _2^\text {c} &{} = &{} 0, &{}\beta _2^\text {nc} &{} = &{} 0, \\ \alpha _3^\text {c} &{} = &{} - \dfrac{(\widehat{u} - \frac{g}{2} \frac{\overline{h}}{{\tilde{c}}})\Delta (\rho h) -\Delta (\rho h u) - \frac{g}{2}\frac{\overline{\rho h}}{{\tilde{c}}} \Delta h }{2{\tilde{c}}}~, &{}\alpha _3^\text {nc} &{} = &{} \frac{\overline{\rho h} {\tilde{c}}\Delta u+\Delta p}{2\overline{\rho h} {\tilde{c}}^2}, &{}\beta _3^\text {c} &{} = &{} - \frac{\bar{\rho }{\tilde{c}} \Delta B}{2}, &{}\beta _3^\text {nc} &{} = &{} -\frac{g \Delta B}{2{\tilde{c}}}. \end{array} \end{aligned}$$
(49)

We note that in the case where \(\rho \) is constant we recover the standard expressions for 1-D shallow water system. Namely, the amplitude for the second wave vanishes and the first and third expression in the numerator of the first and third amplitude combine into one. The spectral information for the 2-D system is displayed in Appendix A.

3.3 Summary of the One-Dimensional Numerical Scheme

The upwind scheme is summarized as follows. The solution is updated as

$$\begin{aligned} \mathbf{W }_i^{n+1}=\mathbf{W }_i^n-\dfrac{\Delta t}{\Delta x} \left\{ A^+_{i-\frac{1}{2}}\left( \mathbf{W }_i^n-\mathbf{W }_{i-1}^n\right) - \Delta x \; \mathbf{S }_{i-\frac{1}{2}}^++ A^-_{i+\frac{1}{2}}\left( \mathbf{W }_{i+1}^n-\mathbf{W }_{i}^n\right) - \Delta x \;\mathbf{S }_{i+\frac{1}{2}}^- \right\} . \end{aligned}$$

Here,

$$\begin{aligned} A^+\Delta \mathbf{W } -\Delta x \; \mathbf{S }^+= \displaystyle {\sum _{\lambda _k > 0}} (\alpha _k \lambda _k - \beta _k) \mathbf{r }_k ~, \qquad A^-\Delta \mathbf{W } -\Delta x \; \mathbf{S }^-= \displaystyle {\sum _{\lambda _k \le 0} } (\alpha _k \lambda _k - \beta _k) \mathbf{r }_k \end{aligned}$$

If the jump in density near cell i does not exceed a threshold, i.e., if \(\max _{i-1 \le i' \le i+1}( |\rho _{i'+1}-\rho _{i'}| ) < \rho _o\), then

$$\begin{aligned} \mathbf{W }= \begin{pmatrix} \rho h \\ \rho h u \\ h \end{pmatrix}, \mathbf{r }_1 = \begin{pmatrix} 1 \\ \widehat{u}- {\tilde{c}} \\ \widehat{1/\rho } \end{pmatrix}, \mathbf{r }_2 = \begin{pmatrix} 1 \\ \widehat{u} \\ -\frac{\overline{h}}{\overline{\rho h}} \end{pmatrix}, \mathbf{r }_3 = \begin{pmatrix} 1 \\ \widehat{u} + {\tilde{c}}\\ \widehat{1/\rho } \end{pmatrix}, \end{aligned}$$
$$\begin{aligned} \begin{array}{lllllllll} \lambda _1 &{} = &{} \widehat{u} - {\tilde{c}}, &{}\alpha _1 &{} = &{} \dfrac{\left( \widehat{u}+ \frac{g}{2} \frac{\overline{h}}{{\tilde{c}}} \right) \Delta (\rho h) -\Delta (\rho hu) + \frac{g}{2}\frac{\overline{\rho h}}{{\tilde{c}}} \Delta h }{2{\tilde{c}}}~, &{} \beta _1 &{} = &{} \frac{\bar{\rho }{\tilde{c}}\Delta B}{2},\\ \lambda _2 &{} = &{} \widehat{u}, &{} \alpha _2 &{} = &{} -\dfrac{({\tilde{c}} - \frac{g}{2} \frac{\overline{h}}{{\tilde{c}}} ) \Delta (\rho h)-\frac{g}{2} \frac{\overline{\rho h}}{{\tilde{c}}} \Delta h}{{\tilde{c}}}, &{} \beta _2 &{} = &{} 0,\\ \lambda _3 &{} = &{} \widehat{u}+{\tilde{c}}, &{} \alpha _3 &{} = &{} - \dfrac{(\widehat{u} - \frac{g}{2} \frac{\overline{h}}{{\tilde{c}}})\Delta (\rho h) -\Delta (\rho h u) - \frac{g}{2}\frac{\overline{\rho h}}{{\tilde{c}}} \Delta h }{2{\tilde{c}}}~, &{} \beta _3 &{} = &{} - \frac{\bar{\rho }{\tilde{c}} \Delta B}{2}, \end{array} \end{aligned}$$

If the jump in the density exceed the chosen threshold ( \(\max _{i-1 \le i' \le i+1}( |\rho _{i'+1}-\rho _{i'}| ) \ge \rho _o\) ), then

$$\begin{aligned} \mathbf{W } = \begin{pmatrix} u \\ p \\ \rho \end{pmatrix}, \mathbf{r }_1 = \begin{pmatrix} {\tilde{c}} \\ - \overline{\rho h} {\tilde{c}}^2 \\ 0 \end{pmatrix} \mathbf{r }_1 = \begin{pmatrix} 0 \\ 0 \\ 1 \end{pmatrix} \mathbf{r }_1 = \begin{pmatrix} {\tilde{c}}\\ \overline{\rho h} {\tilde{c}}^2 \\ 0 \end{pmatrix} \end{aligned}$$
$$\begin{aligned} \begin{array}{llllllllllll} \lambda _1 &{} = &{} \widehat{u} - {\tilde{c}}, &{} \alpha _1 &{} = &{} \frac{\overline{\rho h} {\tilde{c}} \Delta u-\Delta p}{2\overline{\rho h} {\tilde{c}}^2}, &{} \beta _1 &{} = &{} -\frac{g \Delta B}{2 {\tilde{c}}}, \\ \lambda _2 &{} = &{} \widehat{u}, &{} \alpha _2 &{} = &{} \Delta \rho , &{} \beta _2 &{} = &{} 0, \\ \lambda _3 &{} = &{} \widehat{u}+{\tilde{c}}, &{} \alpha _3 &{} = &{} \frac{\overline{\rho h} {\tilde{c}}\Delta u+\Delta p}{2\overline{\rho h} {\tilde{c}}^2}, &{} \beta _3 &{} = &{} -\frac{g \Delta B}{2{\tilde{c}}}. \end{array} \end{aligned}$$

Here the threshold and averages are given by Eqs. (28), (40), (46). In addition, the second order extension and entropy fix is conducted as in [24].

4 One-Dimensional Numerical Results

A set of numerical tests shown in this segment of the manuscript is aimed at illustrating the merits of the scheme. In the results that follow we demonstrate that the scheme is very precise near shock waves, contact discontinuities, that it is conservative, and that it respects steady states at rest and non-standard steady states associated with the contact discontinuity due to the horizontal density gradients.

4.1 Case: Interface Data

Fig. 1
figure 1

Exact (blue solid line) and numerical (dotted red line) solutions for the Riemann problem with initial conditions given in (50). Top: conservative formulation. Bottom: primitive formulation. In each sequence: we show total height (left), velocity (middle left), density (middle right) and pressure (right). The resolution here is \(\Delta x = 20/200\) (Color figure online)

Spurious oscillations in the pressure and velocity caused by the inability of numerical schemes to preserve their equilibrium near interfaces with density jumps has been discussed in previous sections. A hybrid strategy had been proposed to better resolve the flow in those areas. The first numerical test looks upon this phenomenon and considers interface data in a Riemann problem. That is, the initial conditions are

$$\begin{aligned} (h,u,\rho ) (x) = \left\{ \begin{array}{ll} (h_\ell ,u_\ell ,\rho _\ell ) &{} \text {if} \,\, {-}{10}< x \le 0 \\ \\ (h_r,u_r,\rho _r) &{} \text {if} \,\, 0 < x \le 10, \\ \\ \end{array} \right. \end{aligned}$$

in the domain \([-10,10]\) with flat topography \(B=0\), and left and right states connected through a contact discontinuity where u and p remain constant across it. In particular, we define

$$\begin{aligned} \begin{array}{lllllllll} h_\ell &{} = &{} 13.41, &{} u_\ell &{} = &{} 5, &{} \rho _\ell &{} = &{} 0.1 ,\\ h_r &{} = &{} 3, &{} u_r &{} = &{} 5, &{} \rho _r &{} = &{} 2, \end{array} \end{aligned}$$
(50)

which represents a moving interface. If the interface was stationary (\(u_\ell = u_r =0\)), then the standard numerical scheme would preserve the data by conservation. In a moving interface, the conservative formulation is not capable of maintaining the equilibrium. The primitive formulation is a more suitable set of equations to consider. Any consistent numerical scheme recognizes such interface data and respects the Riemann invariants. In this particular test, there are no shock waves where the conservative variables would be necessary. We use the Riemann invariants in the entire domain.

The numerical results are shown in Fig. 1 at \(t = 1\), using 200 grid points and free boundary conditions. Here \(g=1\). The conservative formulation was used to compute the results in the top side. That is, the numerical method summarized in Sect. 3.3 is used with \(W=(\rho h , \rho hu , h)^T\) only, and no switch to the primitive variables is done. The exact (blue solid line) and numerical (red dotted line) results are shown for the total height (left), velocity (middle left), density (middle right) and vertically integrated pressure (right). As expected, the pressure and velocity do not remain constant, and spurious oscillations appear for the conservative formulation. The alternative primitive formulation is shown in the bottom panels. No shock waves are present and the primitive formulation can be used in the entire domain. That is, the numerical method summarized in Sect. 3.3 is used with \(W=(u, p ,\rho )^T\) only, and no switch to the conservative variables is done. We observe a constant velocity and pressure when we use the (hup) variables. We observe that the density variation in the ocean is much smaller than the density difference used here. The chosen parameter regime where the density jump is strong is away from the regime observed in the ocean. The numerical error in this interfaces is much smaller when the jump in the density is weak. The choice for the current test is aimed at illustrating the situation in strong density jumps and the way to correct it. Other potential applications may involve stronger density jumps than those in stratified flows. Furthermore, one can apply the hybrid strategy here to the model in [11] with horizontal temperature gradients where the interfaces can be much stronger. The only purpose of the exercise here is to show that the strategy works.

A more quantitative comparison between the conservative and primitive formulations can be done by computing the relative error. That is, for any quantity q and a reference quantity \(q_\text {ref}\) that can be the exact solution if available, the relative error is

$$\begin{aligned} \text {err} = (q-q_\text {ref})/q_\text {ref}. \end{aligned}$$
(51)

In the present test, the normalized \(L^2\) norm of the relative errors for \(h,u,\rho ,p\) are \(6.9\times 10^{-2}, 7.6\times 10^{-3},5.4\times 10^{-1},2.5\times 10^{-2}\) for the conservative formulation and \(7.6\times 10^{-2},4.9\times 10^{-17}, 1.1,2.1\times 10^{-16}\) for the primitive formulation respectively. We note that the hybrid scheme improves the results, specially in the velocity and pressure variables. In particular, the velocity and pressure are computed exactly with the hybrid technique, to machine precision. The profile across the jump is typical in any numerical method and no significant improvement is added with the primitive formulation. The purpose of the primitive formulation is aimed at avoiding large spurious oscillations in the velocity and pressure that can contaminate the rest of the solution in more general initial conditions.

4.2 Case: Riemann Problem with Left Rarefaction, Contact Discontinuity and Right Shock Waves

Fig. 2
figure 2

Exact (blue solid line) and numerical (dotted red line) solutions for the Riemann problem with initial conditions given in (52). Top: conservative formulation. Bottom: primitive formulation. In each sequence: we show total height (left), velocity (middle left), density (middle right) and pressure (right). The asterisks in the density plot indicates what cells are classified as being close the interface. The resolution here is \(\Delta x = 20/200\) (Color figure online)

A more challenging Riemann problem where spurious oscillations appear is one where shock and rarefactions waves are included. The primitive variables are not appropriate anymore near shock waves. As a result, a switch between primitive and conservative variables is required, as summarized in Sect. 3.3. Near interface data the primitive variables are used, and the conservative quantities everywhere else. We use the following initial conditions for illustration:

$$\begin{aligned} \begin{array}{lllllllll} h_\ell &{} = &{} 33.0416 , &{} u_\ell &{} = &{} 5.9484, &{} \rho _\ell &{} = &{} 0.1 ,\\ h_r &{} = &{} 4, &{} u_r &{} = &{} 6.5, &{} \rho _r &{} = &{} 4, \end{array} \end{aligned}$$
(52)

with corresponding Riemann solution consisting of a left rarefaction fan, followed by a contact discontinuity and a right shock wave. Here \(g=10\). Figure 2 shows the exact solution (solid blue line) and the numerical approximation (dotted red line) for comparison. The conservative formulation is shown in the top panel and the hybrid alternative in the bottom, in the same sequence as in Fig. 1. Free boundary conditions are used here. From the exact solution we notice a left rarefaction wave and right shock wave. In the conservative formulation (top panels), we identify significant pressure and velocity oscillations originated near the interface and contaminating the rest of the solution. The problem with the pressure and velocity oscillations near the interface intensifies when the pressure is strong, as it occurs in the case study considered here. Such oscillations do not go away when the resolution is improved. We also point out that the total height and density do not seem to be affected by the oscillations in the other fields. The numerical results obtained by the hybrid formulation are shown in the bottom panel. The improvement is evident, specially in the pressure and velocity.

Since a switch between the conservative and the primitive variables is needed when shock waves form, one has to trace the interface. One way to do so is by monitoring the density differences between cells. When the differences exceed a threshold we identify that cell as being near an interface and switch to the primitive variables in the evolution of that cell. In the present work, we say that cell i is near an interface if condition (27) is met with \(\rho _o = \frac{1}{10} |\rho _r-\rho _\ell | \), which is consistent with (28). Here \(\rho _\ell ,\rho _r\) are given in Eq. (52). Such cells are plotted with “*” signs in the bottom–middle–right panel in Fig. 2. The interface is very well captured with the above algorithm and the switch is unnoticeable. The normalized \(L^2\) norm of the relative errors for \(h,u,\rho \) and p are \(8.7 \times 10^{-2}, 2.3 \times 10^{-2}, 5.2 \times 10^{-1}, 2.9\times 10^{-2}\) for the conservative formulation and \(7.6 \times 10^{-2}, 9.7\times 10^{-3},1.3, 1.8\times 10^{-2}\) for the hybrid formulation, respectively. The main improvement of the hybrid formulation is near the contact discontinuity. The improvement in the velocity and pressure is significant when the hybrid formulation is used. The conservative formulation does not correctly computes the pressure and velocity near the contact discontinuity and contaminates the solution in other parts of the domain. The total height and density are already well approximated by the conservative formulation. The hybrid formulation also provides good results overall and it actually improves the approximation of total height near the rarefaction wave in the first family.

4.3 Case: Perturbation of a Steady State

Fig. 3
figure 3

Initial perturbation (blue solid line) and numerical evolution (dotted red line) for the initial conditions (53) with \(\epsilon = 0.1\). Each row shows different times \(t = 0.6,3,6,30\). In each row, we show total height (left), velocity (middle left), density (middle right) and pressure (right). The resolution here is \(\Delta x = 20/400\) (Color figure online)

Typical case studies for 1-D shallow water systems include perturbations to steady states at rest or more general ones. General steady states in the regular shallow water equations appear when a delicate balance between flux gradients and the corresponding source terms occurs. When horizontal density gradients are incorporated, a new class of steady states emerge even in a flat topography and zero velocity, when the water depth and density are related to each other to compensate for a constant pressure. Consider the domain \([-10,10]\), the topography \(B(x) = (0.2-0.05 (x+5)^2) \chi _{[-7,-3]}(x)\), where \(\chi _{[a,b]}\) is the characteristic function in the interval [ab] , and \(g=10\). The initial conditions we choose for such scenario is

$$\begin{aligned} (h,u,\rho ) (x) = \left\{ \begin{array}{ll} (h_\text {out}-B(x)+\epsilon \chi _{[-9,-8]}(x), \; 0 \;,1) &{} \text {if} \,\, -10< x \le 0 \\ \\ (h_\text {out}-(x/50)^2 (x-9)^2 , \; 0 \; , (2/g)p_\text {out}/h(x)^2) &{} \text {if} \,\, 0< x \le 9, \\ \\ h_\text {out}, \; 0 \; , (2/g)p_\text {out}/h(x)^2) &{} \text {if} \,\, 9 < x \le 10, \end{array} \right. \end{aligned}$$
(53)

where \(h_\text {out} = 0.6, \rho _\text {out} = 0.9\) and \(p_\text {out} = (g/2) \rho _\text {out} h_\text {out}^2\) are the water depth, density and pressure at the boundaries, and \(\epsilon \) is a perturbation’s amplitude. The density in this case does not vary more than 6%, which is closer to values we encounter in stratified flows. We note that when there is no perturbation \(\epsilon = 0\), we get a steady-state composed of two distinguished areas. The left side of the boundary \(-10 \le x \le 0\) consists of a steady state at rest with a constant density (\(h+B = 0.6, u = 0, \rho = 0.9\)). The right-hand side of the domain (\(0 \le x \le 10\)) consists of a flat bottom topography with varying water depth and density in balance so as to keep the pressure constant (\(B = 0, u = 0, p = (g/2)\rho h^2 = 1.62\)). Small perturbations to steady states is a challenging test for schemes that are not in balance.

Figure 3 shows the evolution of a small perturbation to the steady state (\(\epsilon =0.1\)) using the initial conditions (53). We impose Dirichlet boundary conditions \(h_\text {out} = 0.6, u_\text {pout} = 0,\rho _\text {out} = 0.9\). As the perturbation evolves, it passes through the two areas where the total height is constant on the left, and where the pressure is constant on the right. At \(t=30\), the perturbation leaves the computational domain and recover a steady state.

Fig. 4
figure 4

Initial perturbation (blue solid line) and numerical evolution (dotted red line) for the initial conditions (53) with \(\epsilon = 0.5\). Top left: total height. Top right: velocity. Bottom left: density. Bottom right: pressure. The resolution here is \(\Delta x = 20/400\) (Color figure online)

We point out that although the solution is converging to a steady state, it is not necessarily the same state we started with. This is a qualitative difference in the behaviour compared to the standard shallow water equations, where a given topography, energy, discharge, and boundary conditions completely determines the steady state. On the contrary, here there are infinitely many steady states arbitrarily close to the initial one satisfying the same boundary conditions. For any depth h, one can compute a corresponding \(\rho \) to give a constant pressure. To exemplify this situation, a larger perturbation (\(\epsilon = 0.5\)) for (53) is considered. The initial condition and converging steady state are compared in Fig. 4 at \(t =30\). As one can observe, there is a significant difference between the initial condition and the steady-state solution at the final time. This occurs despite the fact that the pressure is constant in the right-hand-side and the total height is constant in the left-hand-side, confirming that is is a steady state.

5 Two-Dimensional Numerical Results

We now consider the 2-D dynamics with the numerical scheme in Sect. 3.1, with the details provided in Appendix A for the current system. The first two test cases are taken from example 5 and 6 in [11].

5.1 Hybrid Steady State

The details of our first two-dimensional simulation is as follows. The topography in the domain \((x,y) \in [-1,1] \times [-1,1] \) is given as

$$\begin{aligned} B(x,y) = \left\{ \begin{array}{lll} \frac{1}{2} \exp \left( -100 \left( x+\frac{1}{2} \right) ^2 -100 \left( y+\frac{1}{2} \right) ^2 \right) &{} \text { if } &{} -1< x \le 0 \\ \\ \frac{1}{2} \exp \left( -100 \left( x-\frac{1}{2} \right) ^2 -100 \left( y-\frac{1}{2} \right) ^2 \right) &{} \text { if } &{} 0 < x \le 1. \end{array} \right. \end{aligned}$$
(54)

The gravitational constant is chosen \(g=1\). The initial conditions are

$$\begin{aligned} (h,u,v,\rho )(x,y,t=0) = \left\{ \begin{array}{lll} \left( 1/\sqrt{0.9}-B(x,y),0,0,0.9 \right) &{} \text { if } &{} x^2+y^2 \le \frac{1}{4} \\ \\ \left( 1-B(x,y),0,0,1 \right) &{} &{} \text {otherwise.} \end{array} \right. \end{aligned}$$
(55)
Fig. 5
figure 5

Contours of total height (\(w=h+B\)), density and pressure in the left, middle and right panels respectively at time \(t=0.3\) for the initial conditions in (55), and topography in (54). The resolution here is \(\Delta x = 2/100,\Delta y = 2/100\)

We note that the initial conditions above correspond to a steady state, consisting of two types of equilibrium. The topography consists of two Gaussian functions with centers at \((x,y) = \pm (1/2,1/2)\). Outside the circle of radius \(r = 0.5\) and center at the origin, the total height \(w = h+B\) is constant, the velocity field is zero and the density is constant. The initial conditions in that part of the domain correspond to a steady state at rest as in Eq. (10). On the other hand, inside the circle the topography is very small, the depth \(h \approx 1/\sqrt{0.9}\) is approximately uniform, and the pressure \(p = \frac{1}{2} g \rho h^2 \approx 1/2\) is almost constant. Since the velocity field is zero, the state inside the circle is a steady state corresponding to Eq. (14). Thus, the initial conditions in this numerical test is a hybrid steady state, composed of the two types of equilibrium solutions. We chose a weak jump in the density to stay closer to more realistic values in oceanic flows. However, the well-balance property is valid for all parameter regimes.

We also note that while the steady state outside the circle corresponds to a contact discontinuity, it is stationary. The well-balance property actually enables its preservation. As a result, we do not even need the hybrid strategy to preserve this initial condition. Figure 5 shows contours of the numerical solution at time \(t=0.3\) with resolution \(\Delta x = 2/100,\Delta y = 2/100\). We observe no noise in the contours due to the well-balance property.

5.2 Perturbation of a Hybrid Steady State

Fig. 6
figure 6

Top: Height, density and pressure plotted versus (xy) at time \(t=0.3\) in the left, middle and right panels respectively. Bottom: contours of the corresponding quantities in the top panel. Here, the initial conditions are given by Eq. (56), and the resolution is \(\Delta x = \Delta y = 2/200\)

A perturbation of the hybrid steady state in the previous section is analyzed here for completeness. The topography is given by Eq. (54), and the same gravitational constant \(g=1\) is used. The initial conditions are taken analogously from example 7 in [11]

$$\begin{aligned} (h,u,v,\rho )(x,y,t=0) = \left\{ \begin{array}{ll} (1+0.1-B(x,y),0,0,0.9) &{}\text { if }\,\, 0.01< x^2+y^2 \le 0.09, \\ \\ (1-B(x,y),0,0,0.9) &{}\text { if } \,\, 0.09 < x^2+y^2 \le 0.25 \\ &{} \text { or } \,\, x^2+y^2 \le 0.01, \\ \\ (1-B(x,y),0,0,1)&{} \text {otherwise. } \\ \end{array} \right. \end{aligned}$$
(56)

Figure 6 shows the numerical solution of the initial conditions in (56) at time \(t=0.3\) with resolution \(\Delta x = \Delta y = 2/200\). We note a correct evolution of the initial perturbation. In case of strong density interfaces and without the hybrid strategy, the contours in the bottom row would not be as symmetric.

Fig. 7
figure 7

Height, density and pressure plotted versus (xy) at time \(t=0.15\) in the left, middle and right panels respectively. The initial conditions are given in Eq. (57). Here \(\Delta x = \Delta y = 2/200\), and the hybrid strategy is implemented here

Fig. 8
figure 8

Two-dimensional numerical results for the initial conditions in Eq. (59). Top: topography and total height at \(t=0,0.1,0.2,1\), where the colors indicate the density \(\rho \). Bottom: velocity field at \(t=0,0.1,0.2,1\)

5.3 Radial Dam Break Over Flat Bottom

As a last comparison with the examples in [11], we now analyze a radial dam break problem. The topography is chosen flat \(B=0\), \(g=1\), and the initial conditions is

$$\begin{aligned} (h,u,v,p)(x,y,t-0) = \left\{ \begin{array}{lll} (2,0,0,0.9) &{} \text { if } &{} x^2+y^2 \le 0.25 \\ \\ (1,0,0,1) &{} &{} \text { otherwise.} \end{array} \right. \end{aligned}$$
(57)

As it was explained in [11], once the dam is removed, a shock wave travels radially, while a rarefaction wave moves inward and a contact discontinuity wave stays between the other two. Figure 7 (top panels) shows the three types of waves in the height (left), density (middle) and pressure (right). The 3D plot of the pressure exhibits a flat region near the middle wave, well resolving the contact discontinuity. The contact discontinuity is weak due to the weak density interface. However, the scheme works well in all parameter regimes. A radial expansion is observed in the numerical results, as a response to the dam break.

5.4 Coherent Structure Created by Density Fluctuations

The last numerical experiment consists of putting a region of heavier fluid in the middle of the domain. The topography is composed of three bumps surrounding the heavier fluid. The purpose is to analyze the interactions of the density fluctuations with the topography. The topography in this exercise is given by

$$\begin{aligned} \begin{array}{lll} B(x,y) &{} = &{} \max \left( 1-9 ( x - 0.5 )^2 - 9 y^2,0 \right) + \max \left( 1-9 ( x - 1.5 )^2 - 9 (y-0.5)^2,0 \right) \\ &{} &{} + \max \left( 1-9 ( x - 1.5 )^2 - 9 (y+0.5)^2,0 \right) , \end{array} \end{aligned}$$
(58)

which represents three bumps with centers at \((0.5,0),(1.5,\pm 0.5)\), radius 1 / 3 and height 1. Initially,

$$\begin{aligned} \begin{array}{lll} h(x,y,t=0) &{} = &{} 1.5-B(x,y) \\ u(x,y,t=0) &{} = &{} 0 \\ v(x,y,t=0) &{} = &{} 0 \\ \rho (x,y,t=0) &{} = &{} 0.9+0.1 \max ( 1 - 9 (x-1)^2 - 9 y^2,0), \end{array} \end{aligned}$$
(59)

which represents a flow that is initially at rest and with a higher density in between the three bumps. Here \(g=10\).

Figure 8 shows the evolution of the total height \(h+B\) and velocity field (uv) at \(t=0,0.1,0.2,1\). The density is indicated by colors in the total height’s plot. At \(t=0\), the flow has constant height and zero velocity. In the absence of density gradients, the flow is a steady state and no fluid motions are generated. Instead, the region of water with higher density in the middle of the three bumps causes a radial expansion which interacts with the topography, as observed at time \(t=0.1\) (middle left column). The solution at time \(t=0.2\) is shown in the middle right panel. The radial expansion quickly propagates and leaves the domain. We note that besides the radial expansion, a coherent dipole structure has formed in the middle. This structure appears as a result of the interactions between the density interface and the position of the three bumps. The bump in the back projects a flow of water that is forced to pass through the middle of the other two bumps, generating two vortices with a streak in the middle of the two poles. The coherent dipole structure persist at time \(t=1\). Coherent structures like the dipole above have been observed in different atmospheric and oceanic flows. For instance, although it was done with a Boussinesq model, s-vortices have been studied in [26] as a response of geostrophic adjustment when a patch of a well mixed fluid appears in the ocean.

6 Conclusions

In this work, the shallow water equations with density gradients are considered. The system is hyperbolic, and the additional wave associated to interfaces between regions of water with density jumps is a contact discontinuity. This field is degenerate and standard numerical methods do not preserve the invariants in that field. An upwind scheme is derived with a hybrid component to recognize such states is presented. One- and two- dimensional numerical results were included to show the merits of the scheme. Riemann problems with standard and hybrid strategies are compared to demonstrate the advantage of the alternative technique. Two dimensional numerical results test the algorithm in steady states that consists of a combination of lakes at rest with no density gradients and regions where the flow is not at rest but has constant pressure and it is associated to contact waves. An example of a radial break problem was included. Formation of coherent structures as a result of the interactions between density fluctuations with the topography was analyzed.