\hypertarget{Discrete_PG_section_PG}{}\doxysection{Pressure Gradient Term}\label{Discrete_PG_section_PG}
Following \cite{adcroft2008}, the horizontal momentum equation in the general coordinate $r$ can be written as\+: \[ \frac{\partial \vec{u}}{\partial t} + \nabla_r \Phi + \alpha \nabla_r p = \cal{F} \] where the vector $\cal{F}$ represents all the forcing terms other than the pressure gradient. Here, $\vec{u}$ is the horizontal component of the velocity, $\Phi$ is the geopotential\+: \[ \Phi = gz \] $\alpha = 1/\rho$ is the specific volume and $p$ is the pressure. The gradient operator is a gradient along the coordinate surface $r$.

M\+O\+M6 offers two options, an older one using a Montgomery potential as described in \cite{hallberg1997} and \cite{sun1999}. However, it can have the instability described in \cite{hallberg2005}. The version described here is that in \cite{adcroft2008} and is the recommended option (A\+N\+A\+L\+Y\+T\+I\+C\+\_\+\+F\+V\+\_\+\+P\+GF = True). The paper describes the Boussinesq form while the code supports that and also a non-\/\+Boussinesq form.

In two dimensions ( $x$ and $p$), we can integrate the zonal component of the momentum equation above over a finite volume\+:

\begin{eqnarray} - \int dx \int dp \frac{\partial u}{\partial t} &= \int dx \int dp \left. \frac{\partial \Phi}{\partial x}\right|_p \\ &= \int_{p_{br}}^{p_{tr}} \Phi dp + \int_{p_{tr}}^{p_{tl}} \Phi dp + \int_{p_{tl}}^{p_{bl}} \Phi dp &+ \int_{p_{bl}}^{p_{br}} \Phi dp \label{eq:PG_loop} \end{eqnarray}

We convert to line integrals thanks to the Leibniz rule. See the figure for the location of the line integral ranges\+:

 \begin{DoxyImage}\includegraphics[width=\textwidth,height=\textheight/2,keepaspectratio=true]{PG_loop.png}\doxyfigcaption{Schematic of the finite volume used for integrating the $u$-component of momentum. The thermodynamic variables $\theta$ and $s$ reside on the sides of the depicted volume and are considered uniform for the vertical extent of the volume but with linear variation in the horizontal. The volume is depicted in $(x, p)$ space so $p$ is linear around the volume but $\Phi$ can vary arbitrarily along the edges.}\end{DoxyImage}

The only approximations made are (i) that the potential temperature $\theta$ and the salinity $s$ can be represented continuously in the vertical within each layer although discontinuities between layers are allowed and (ii) that $\theta$ and $s$ can be represented continuously along each layer. M\+O\+M6 has options for piecewise constant (P\+CM), piecewise linear (P\+LM), and piecewise parabolic (P\+PM) in the vertical.

If we use the Wright equation of state (\cite{wright1997}), we can integrate the above integrals analytically. This equation of state can be written as\+:

\[ \alpha(s, \theta, p) = A(s, \theta) + \frac{\lambda(s, \theta)}{P(s, \theta) + p} \]

where $A, \lambda$ and $P$ are functions only of $s$ and $\theta$. The integral form of hydrostatic balance is\+:

\[ \Phi(p_t) - \Phi(p_b) = \int_{p_t}^{p_b} \alpha(s, \theta, p) dp \]

Assuming piecewise constant values for $\theta$ and $s$ and the above equation of state, we get\+: \begin{eqnarray} \Phi(p_t) - \Phi(p_b) &= \int_{p_t}^{p_b} \alpha(s, \theta, p) dp \\ &= (p_b - p_t) A + \lambda \ln \left| \frac{P + p_b}{P + p_t} \right| \\ &= \Delta p \left( A + \frac{\lambda}{P + \overline{p}} \frac{1}{2 \epsilon} \ln \left| \frac{1 + \epsilon}{1 - \epsilon} \right| \right) \label{eq:PG_vert} \end{eqnarray} which is the exact solution for the continuum only if $\theta$ and $s$ are uniform in the interval $p_t$ to $p_b$. Here, we have introduced the variables\+: \[ \Delta p = p_b - p_t \] \[ \overline{p} = \frac{1}{2}(p_t + p_b) \] and \[ \epsilon = \frac{\Delta p}{2 (P + \overline{p})} \] We will show later that $\epsilon \ll 1$. Note the series expansion\+:

\[ \frac{1}{2 \epsilon} \ln \left| \frac{1 + \epsilon}{1 - \epsilon} \right| = \sum_{n=1}^\infty \frac{\epsilon^{2n-2}}{2n - 1} = 1 + \frac{\epsilon^2}{3} + \frac{\epsilon^4}{5} + \cdots \forall |\epsilon | \leq 1 \]

Typical values for the deep ocean with 100 m layer thickness are $6 \times 10^8$ Pa and $10^6$ Pa, respectively, yielding $\epsilon \sim 8 \times 10^{-4}$ and a corresponding accuracy in the geopotential height calculation of $\frac{\lambda \epsilon^3}{g} \sim 10^{-5}$ m. For this value of $\epsilon$, the series converges with just three terms. In M\+O\+M6, we use series rather than the intrinsic log function , since the log is machine dependent and insufficiently accurate. In extreme circumstances, $\Delta p \sim 6 \times 10^7$ Pa (limited by the depth of the ocean) for which $\epsilon \sim 0.04$ with geopotential height errors of order 1 m. In this case, the series converges to machine precision with six terms.

The finite volume acceleration is expression terms of four integrals around the volume, $\int \Phi dp$. The side integrals can be calculated by direct integration of \ref{eq:PG_vert}, which gives\+: \begin{eqnarray} \int_{p_t}^{p_b} \Phi dp &= \Delta p \left( \Phi_b + \frac{1}{2} A \Delta p + \lambda \left( 1 - \frac{1 - \epsilon}{2 \epsilon} \ln \left| \frac{1 + \epsilon}{1 - \epsilon} \right| \right) \right) \\ &= \Delta p \left( \Phi_b + \frac{1}{2} A \Delta p + \lambda \left( 1 - (1 - \epsilon) \left( 1 + \frac{\epsilon^2}{3} + \frac{\epsilon^4}{5} + \cdots \right) \right) \right) \\ &= \Delta p \left( \Phi_b + \frac{1}{2} A \Delta p + \lambda \left( \epsilon - (1 - \epsilon) \epsilon^2 \left( \frac{1}{3} + \frac{\epsilon^2}{5} + \cdots \right) \right) \right) \end{eqnarray} where $\Phi, \Delta p, P, A$ and $\lambda$ are each evaluated on the left or right side of the volume.

The top and bottom integrals in \ref{eq:PG_loop} must allow for the effect of varying $\theta$ and $s$ on $A, \lambda$ and $P$. We evaluate these integrals numerically using sixth-\/order quadrature; Boole\textquotesingle{}s rule requires evaluating the coefficients in the equation of state at five points, two of which have already been evaluated for the side integrals. For efficiency, we linearly interpolate the coefficients $A, P$ and $\lambda$ between the end points, which seems to make very little difference to the solution. We also verified that tenth-\/order quadrature makes little difference to the solution. The values of the top and bottom integrals are carried upward in a hydrostatic-\/like integration, obtained as follows\+:

\begin{eqnarray} \int_{p_{tl}}^{p_{tr}} \Phi_t dp &= (p_{tr} - p_{tl}) \int_0^1 \Phi_t dx \\ &= (p_{tr} - p_{tl}) \int_0^1 \left( \Phi_b + A(x) \Delta p(x) + \lambda (x) \ln \left| \frac{1 + \epsilon (x)}{1 - \epsilon (x)} \right| \right) dx \\ &= (p_{tr} - p_{tl}) \int_0^1 \Phi_b dx \\ &+ \int_0^1 \Delta p(x) \left( A(x) + \frac{\lambda (x)}{P(x) + \overline{p} (x)} \sum_{n=1}^\infty \frac{\epsilon^{2n-2}}{2n-1} \right) dx \end{eqnarray}

The first integral is either known from the top integral of the layer below or the boundary condition at the ocean bottom. The second integral is evaluated numerically.

All the above definite integrals are specific to the Wright equation of state; the use of a different equation of state requires analytic integration of the appropriate equations. We have found, however, that high-\/order numerical integration appears to be sufficient. Although the numerical implementation is more general (allowing the use of arbitrary equations of state), it is significantly more expensive and so we advocate the analytic implementation for efficiency. 