\documentclass[11pt,fleqn]{article}

% PS Tricks
\usepackage{pstricks}

% AMS math extensions
\usepackage{amsmath,bm}
\usepackage{amssymb}

% Block Array
%\usepackage{blkarray}

% Use different colors
\usepackage{color}

% bibliography style
\usepackage{natbib}
\bibliographystyle{ams}
\bibpunct{(}{)}{;}{a}{}{,}

% changes margins to 1'' on each side
\addtolength{\oddsidemargin}{-.875in}
\addtolength{\evensidemargin}{-.875in}
\addtolength{\textwidth}{1.75in}
%\addtolength{\topmargin}{-.875in}
\addtolength{\topmargin}{-.4375in}
\addtolength{\textheight}{1.75in}

% prevents indenting of paragraphs
\setlength{\parskip}{\baselineskip}
\setlength{\parindent}{0em}
\setlength{\mathindent}{1em}

% change line spacing
\renewcommand{\baselinestretch}{1.7}

% new commands
\newcommand{\ptlder}[2]{\frac{\partial #1}{\partial #2}}
\newcommand{\totder}[2]{\frac{d #1}{d #2}}
\newcommand{\inverse}[1]{\frac{1}{#1}}
\newcommand{\Grad}{\vec{\nabla}}
\newcommand{\Laplacian}{\nabla^{2}}
\newcommand{\Div}{\vec{\nabla}\cdot}
\newcommand{\Curl}{\vec{\nabla}\times}
\newcommand{\ptlsqd}[2]{\frac{\partial^{2} #1}{\partial #2^{2}}}
\newcommand{\totsqd}[2]{\frac{d^{2} #1}{d #2^{2}}}

% provide lists with tight line spacing
\usepackage{mdwlist}

\begin{document}

\begin{flushright} \today \end{flushright}

\vspace*{.1in}
\begin{center}  {\Large\bf Equations for CLUBB}  \end{center}
\vspace*{.1in}

\section{Predictive equations}

\begin{equation}
\label{eq_um}
\ptlder{\bar{u}}{t}
= \underbrace{ - \bar{w}\ptlder{\bar{u}}{z} }_{ma}
  \underbrace{ - f (v_g - \bar{v}) }_{cf/gf}
  \underbrace{ - \inverse{\rho_{s}}\ptlder{\rho_{s}\overline{u'w'}}{z} }_{ta}
  + \left. \ptlder{\bar{u}}{t} \right|_{\rm{ls}}
  + \left. \ptlder{\bar{u}}{t} \right|_{\rm{ndg}}
  + \left. \ptlder{\bar{u}}{t} \right|_{\rm{sdmp}}
\end{equation}
%
\begin{equation}
\label{eq_vm}
\ptlder{\bar{v}}{t}
= \underbrace{ - \bar{w}\ptlder{\bar{v}}{z} }_{ma}
  \underbrace{ + f (u_g - \bar{u}) }_{cf/gf}
  \underbrace{ - \inverse{\rho_{s}}\ptlder{\rho_{s}\overline{v'w'}}{z} }_{ta}
  + \left. \ptlder{\bar{v}}{t} \right|_{\rm{ls}}
  + \left. \ptlder{\bar{v}}{t} \right|_{\rm{ndg}}
  + \left. \ptlder{\bar{v}}{t} \right|_{\rm{sdmp}}
\end{equation}
%
\begin{equation}
\label{eq_rtm}
\ptlder{\bar{r}_t}{t}
= \underbrace{ - \bar{w}\ptlder{\bar{r}_t}{z} }_{ma}
  \underbrace{ - \inverse{\rho_{s}}\ptlder{\rho_{s}\overline{w'r'_t}}{z} }_{ta}
  + \left. \ptlder{\bar{r}_t}{t} \right|_{\rm{ls}}
  + \left. \ptlder{\bar{r}_t}{t} \right|_{\rm{cl}}
  + \left. \ptlder{\bar{r}_t}{t} \right|_{\rm{mfl}}
  + \left. \ptlder{\bar{r}_t}{t} \right|_{\rm{tacl}}
  + \left. \ptlder{\bar{r}_t}{t} \right|_{\rm{sdmp}}
\end{equation}
%
\begin{equation}
\label{eq_thlm}
\ptlder{\bar{\theta}_l}{t}
= \underbrace{ - \bar{w}\ptlder{\bar{\theta}_l}{z} }_{ma}
  \underbrace{ - \inverse{\rho_{s}}\ptlder{\rho_{s}\overline{w'\theta'_l}}{z} }_{ta}
  + \bar{R}
  + \left. \ptlder{\bar{\theta}_l}{t} \right|_{\rm{ls}}
  + \left. \ptlder{\bar{\theta}_l}{t} \right|_{\rm{cl}}
  + \left. \ptlder{\bar{\theta}_l}{t} \right|_{\rm{mfl}}
  + \left. \ptlder{\bar{\theta}_l}{t} \right|_{\rm{tacl}}
  + \left. \ptlder{\bar{\theta}_l}{t} \right|_{\rm{sdmp}}
\end{equation}
%
\begin{equation}
\label{eq_wp2}
\begin{split}
\ptlder{\overline{w^{'2}}}{t}
=& \underbrace{ - \bar{w}\ptlder{\overline{w^{'2}}}{z} }_{ma}
   \underbrace{ - \inverse{\rho_{s}}\ptlder{\rho_{s}\overline{w^{'3}}}{z} }_{ta}
   \underbrace{ - 2\overline{w^{'2}}\ptlder{\bar{w}}{z} }_{ac}
   \underbrace{ + \frac{2g}{\theta_{vs}} \overline{w'\theta'_v} }_{bp}
   \underbrace{ - \frac{C_4}{\tau} \left( \overline{w^{'2}} -\frac{2}{3}\bar{e} \right) }_{pr1} \\
 & \underbrace{ - C_5
     \left(
       - 2\overline{w^{'2}}\ptlder{\bar{w}}{z}
       + \frac{2g}{\theta_{vs}} \overline{w'\theta'_v}
     \right) }_{pr2}
   \underbrace{ + \frac{2}{3} C_5
     \left(
       \frac{g}{\theta_{vs}} \overline{w'\theta'_v}
       - \overline{u'w'}\ptlder{\bar{u}}{z}
       - \overline{v'w'}\ptlder{\bar{v}}{z}
     \right) }_{pr3} \\
 & \underbrace{ - \dfrac{C_1}{\tau} \left(   \overline{w^{'2}}
                              - \left. w \right|_{\rm{tol}}^{2} \right) }_{dp1}
   \underbrace{ + \ptlder{}{z} \left[ \left( K_{w1} + \nu_1 \right)
                         \ptlder{}{z} \overline{w^{'2}}
                  \right] }_{dp2}
   + \left. \ptlder{\overline{w^{'2}}}{t} \right|_{\rm{pd}}
   + \left. \ptlder{\overline{w^{'2}}}{t} \right|_{\rm{cl}}
\end{split}
\end{equation}
%
\begin{equation}
\label{eq_rtp2}
\begin{split}
\ptlder{\overline{r_t^{'2}}}{t}
=& \underbrace{ - \bar{w}\ptlder{\overline{r^{'2}_t}}{z} }_{ma}
   \underbrace{ - \inverse{\rho_{s}}\ptlder{\rho_{s}\overline{w'r_t^{'2}}}{z} }_{ta}
   \underbrace{ - 2\overline{w'r'_t}\ptlder{\bar{r}_t}{z} }_{tp}
   \underbrace{ - \dfrac{C_2}{\tau} \left(   \overline{r_t^{'2}}
                              - \left. r_t \right|_{\rm{tol}}^{2} \right) }_{dp1} \\
 & \underbrace{ + \ptlder{}{z} \left[ \left( K_{w2} + \nu_2 \right)
                         \ptlder{}{z} \overline{r_t^{'2}}
                  \right] }_{dp2}
   + \left. \ptlder{\overline{r_t^{'2}}}{t} \right|_{\rm{pd}}
   + \left. \ptlder{\overline{r_t^{'2}}}{t} \right|_{\rm{cl}}
\end{split}
\end{equation}
%
\begin{equation}
\label{eq_thlp2}
\begin{split}
\ptlder{\overline{\theta_l^{'2}}}{t}
=& \underbrace{ - \bar{w}\ptlder{\overline{\theta^{'2}_l}}{z} }_{ma}
   \underbrace{ - \inverse{\rho_{s}}\ptlder{\rho_{s}\overline{w'\theta_l^{'2}}}{z} }_{ta}
   \underbrace{ - 2\overline{w'\theta'_l}\ptlder{\bar{\theta}_l}{z} }_{tp}
   \underbrace{ - \dfrac{C_2}{\tau} \left(   \overline{\theta_l^{'2}}
                              - \left. \theta_l \right|_{\rm{tol}}^{2} \right) }_{dp1} \\
 & \underbrace{ + \ptlder{}{z} \left[ \left( K_{w2} + \nu_2 \right)
                         \ptlder{}{z} \overline{\theta_l^{'2}}
                  \right] }_{dp2}
   + \left. \ptlder{\overline{\theta_l^{'2}}}{t} \right|_{\rm{pd}}
   + \left. \ptlder{\overline{\theta_l^{'2}}}{t} \right|_{\rm{cl}}
\end{split}
\end{equation}
%
\begin{equation}
\label{eq_rtpthlp}
\begin{split}
\ptlder{\overline{r'_t\theta'_l}}{t}
= & \underbrace{ - \bar{w}\ptlder{\overline{r'_t\theta'_l}}{z} }_{ma}
    \underbrace{ - \inverse{\rho_{s}}\ptlder{\rho_{s}\overline{w'r'_t\theta'_l}}{z} }_{ta}
    \underbrace{ - \overline{w'r'_t}\ptlder{\bar{\theta}_l}{z} }_{tp1}
    \underbrace{ - \overline{w'\theta'_l}\ptlder{\bar{r}_t}{z} }_{tp2}
    \underbrace{ - \dfrac{C_2}{\tau} \overline{r_t' \theta_l'} }_{dp1} \\
    & \underbrace{ + \ptlder{}{z} \left[ \left( K_{w2} + \nu_2 \right)
                            \ptlder{}{z} \overline{r_t' \theta_l'}
                     \right] }_{dp2}
    + \left. \ptlder{\overline{r'_t\theta'_l}}{t} \right|_{\rm{cl}}
\end{split}
\end{equation}
%
\begin{equation}
\label{eq_wprtp}
\begin{split}
\ptlder{\overline{w'r'_t}}{t}
= & \underbrace{ - \bar{w}\ptlder{\overline{w'r'_t}}{z} }_{ma}
    \underbrace{ - \inverse{\rho_{s}}\ptlder{\rho_{s}\overline{w^{'2}r'_t}}{z} }_{ta}
    \underbrace{ - \overline{w^{'2}}\ptlder{\bar{r}_t}{z} }_{tp}
    \underbrace{ - \overline{w'r'_t}\ptlder{\bar{w}}{z} }_{ac}
    \underbrace{ + \frac{g}{\theta_{vs}} \overline{r'_t\theta'_v} }_{bp}
    \underbrace{ - \frac{C_6}{\tau}\overline{w'r'_t} }_{pr1} \\
  & \underbrace{ + C_7 \overline{w'r'_t}\ptlder{\bar{w}}{z} }_{pr2}
    \underbrace{ - C_7 \frac{g}{\theta_{vs}} \overline{r'_t\theta'_v} }_{pr3}
    \underbrace{ + \ptlder{}{z} \left[ \left( K_{w6} + \nu_6 \right)
                          \ptlder{}{z} \overline{w'r'_t}
                   \right] }_{dp1}
    + \left. \ptlder{\overline{w'r'_t}}{t} \right|_{\rm{sicl}}
    + \left. \ptlder{\overline{w'r'_t}}{t} \right|_{\rm{cl}}
    + \left. \ptlder{\overline{w'r'_t}}{t} \right|_{\rm{mfl}}
\end{split}
\end{equation}
%
\begin{equation}
\label{eq_wpthlp}
\begin{split}
\ptlder{\overline{w'\theta'_l}}{t}
= & \underbrace{ - \bar{w}\ptlder{\overline{w'\theta'_l}}{z} }_{ma}
    \underbrace{ - \inverse{\rho_{s}}\ptlder{\rho_{s}\overline{w^{'2}\theta'_l}}{z} }_{ta}
    \underbrace{ - \overline{w^{'2}}\ptlder{\bar{\theta}_l}{z} }_{tp}
    \underbrace{ - \overline{w'\theta'_l}\ptlder{\bar{w}}{z} }_{ac}
    \underbrace{ + \frac{g}{\theta_{vs}} \overline{\theta'_l\theta'_v} }_{bp}
    \underbrace{ - \frac{C_6}{\tau}\overline{w'\theta'_l} }_{pr1} \\
  & \underbrace{ + C_7 \overline{w'\theta'_l}\ptlder{\bar{w}}{z} }_{pr2}
    \underbrace{ - C_7 \frac{g}{\theta_{vs}} \overline{\theta'_l\theta'_v} }_{pr3}
    \underbrace{ + \ptlder{}{z} \left[ \left( K_{w6} + \nu_6 \right)
                          \ptlder{}{z} \overline{w'\theta'_l}
                   \right] }_{dp1}
    + \left. \ptlder{\overline{w'\theta'_l}}{t} \right|_{\rm{sicl}}
    + \left. \ptlder{\overline{w'\theta'_l}}{t} \right|_{\rm{cl}}
    + \left. \ptlder{\overline{w'\theta'_l}}{t} \right|_{\rm{mfl}}
\end{split}
\end{equation}
%
\begin{equation}
\label{eq_wp3}
\begin{split}
\ptlder{\overline{w^{'3}}}{t}
= & \underbrace{ - \bar{w}\ptlder{\overline{w^{'3}}}{z} }_{ma}
    \underbrace{ - \inverse{\rho_{s}}\ptlder{\rho_{s}\overline{w^{'4}}}{z} }_{ta}
    \underbrace{ + 3\frac{\overline{w^{'2}}}{\rho_{s}}\ptlder{\rho_{s}\overline{w^{'2}}}{z} }_{tp}
    \underbrace{ - 3\overline{w^{'3}}\ptlder{\bar{w}}{z} }_{ac}
    \underbrace{ + \frac{3g}{\theta_{vs}} \overline{w^{'2}\theta'_v} }_{bp1} \\
  & \underbrace{ - C_{15} K_m \left(
                           \frac{g}{\theta_{vs}} \ptlder{ \overline{w'\theta'_v} }{z}
			-\left(
                             \ptlder{\left(\overline{u'w'} \ptlder{\bar{u}}{z}\right)}{z}
                            +\ptlder{\left(\overline{v'w'} \ptlder{\bar{v}}{z}\right)}{z}
			\right) \right)
               }_{bp2} \\
  & \underbrace{ - \frac{C_8}{\tau}\left( C_{8b} \, Skw^4 + 1 \right) \overline{w^{'3}} }_{pr1}
    \underbrace{ - C_{11} \left(
                 - 3 \overline{w^{'3}}\ptlder{\bar{w}}{z}
                 + \frac{3g}{\theta_{vs}} \overline{w^{'2}\theta'_v}
             \right) }_{pr2}
    \underbrace{ + \ptlder{}{z} \left[ \left( K_{w8} + \nu_8 \right)
                          \ptlder{}{z} \overline{w^{'3}}
                   \right] }_{dp1}
    + \left. \ptlder{\overline{w^{'3}}}{t} \right|_{\rm{cl}}
\end{split}
\end{equation}
%
where $\bar{R}$ is the radiative heating rate, $f$ the Coriolis parameter, and
$u_g$ and $v_g$ the geostrophic winds.  Furthermore,
$\left. \ptlder{\bar{r}_t}{t} \right|_{\rm ls}$ and
$\left. \ptlder{\bar{\theta}_l}{t} \right|_{\rm ls}$ are large-scale moisture
and temperature forcings, respectively, and $g$ is acceleration due to gravity.   The set of
equations is an anelastic set of equations, where $\rho_{s}$ is the dry, static,
base-state density, which only changes with respect to altitude; and where
$\theta_{vs}$ is the dry, base-state $\theta_{v}$, which also only changes with
respect to altitude.  Threshold values of the variances are established, such that
$\left. w \right|_{\rm{tol}}^{2}$ is the minimum threshold value for
$\overline{w^{'2}}$;  $\left. r_t \right|_{\rm{tol}}^{2}$ is the minimum
threshold value for $\overline{r_t^{'2}}$; and
$\left. \theta_l \right|_{\rm{tol}}^{2}$ is the minimum threshold value for
$\overline{\theta_l^{'2}}$.  The subscript $\left.\right|_{\rm{pd}}$ stands for
the rate of change due to the positive-definite hole-filling scheme, the
subscript $\left.\right|_{\rm{sicl}}$ stands for the rate of change due to the
semi-implicit clipping scheme, the subscript $\left.\right|_{\rm{cl}}$
stands for the rate of change due to completely explicit clipping,  the subscript
$\left.\right|_{\rm{mfl}}$ denotes adjustments from the monotonic flux limiter, the subscript
the $\left.\right|_{\rm{tacl}}$  denotes turbulent advection clipping, and finally the subscript
$\left.\right|_{\rm{sdmp}}$ denotes sponge layer damping.

If the model does not predict any higher-order moments of the
horizontal winds, we assume that the turbulence kinetic energy, $\bar{e}$,
is proportional to the vertical velocity variance $\overline{w^{'2}}$:
%
\begin{equation}
\label{eq_tke}
\bar{e} = \frac{3}{2} \overline{w^{'2}}.
\end{equation}
%

Alternatively, if higher-order moments of the horizontal winds are computed,
then turbulence kinetic energy, $\bar{e}$, is a function of the vertical
velocity variance $\overline{w^{'2}}$,
latitudinal wind variance $\overline{v^{'2}}$, and
longitudinal wind variance $\overline{u^{'2}}$:
%
\begin{equation}
\label{eq_aniso_tke}
\bar{e} = \frac{1}{2}
  \left(
    \overline{w^{'2}}+\overline{u^{'2}}+\overline{v^{'2}}
  \right).
\end{equation}
%
% Note: formulae for u'^2  v'^2 pp. 2430
In the second case, the horizontal wind variance terms are determined as in
\citet{bougeault1981a} and given by the equations:
%
\begin{equation}
\begin{split}
\label{eq_up2}
\ptlder{\overline{u^{'2}}}{t}
= & \underbrace{ - \bar{w}\ptlder{\overline{u^{'2}}}{z} }_{ma}
    \underbrace{ - \inverse{\rho_{s}}\ptlder{\rho_{s}\overline{w'u^{'2}}}{z} }_{ta}
    \underbrace{ - \left(1 - C_{5} \right) 2\overline{u'w'}\ptlder{\bar{u}}{z} }_{tp}
    \underbrace{ - \frac{2}{3}
%\epsilon
                  C_{14} \frac{\bar{e}}{\tau}
               }_{pr1} \\
    & \underbrace{ + \frac{2}{3} C_{5}
      \left(
        \frac{g}{\theta_{vs}} \overline{w'\theta'_v}
        - \overline{u'w'}\ptlder{\bar{u}}{z}
        - \overline{v'w'}\ptlder{\bar{v}}{z}
      \right) }_{pr2}
    \underbrace{ - \dfrac{C_4}{\tau} \left( \overline{u^{'2}} - \frac{2}{3} \bar{e} \right) }_{dp1} \\
    & + \underbrace{ \ptlder{}{z} \left[ \left( K_{w9} + \nu_9 \right)
                          \ptlder{}{z} \overline{u^{'2}}
                   \right] }_{dp2}
    + \left. \ptlder{\overline{u^{'2}}}{t} \right|_{\rm{pd}}
    + \left. \ptlder{\overline{u^{'2}}}{t} \right|_{\rm{cl}}
\end{split}
\end{equation}
%

%
\begin{equation}
\begin{split}
\label{eq_vp2}
\ptlder{\overline{v^{'2}}}{t}
= & \underbrace{ - \bar{w}\ptlder{\overline{v^{'2}}}{z} }_{ma}
    \underbrace{ - \inverse{\rho_{s}}\ptlder{\rho_{s}\overline{w'v^{'2}}}{z} }_{ta}
    \underbrace{ - \left(1 - C_{5} \right) 2\overline{v'w'}\ptlder{\bar{v}}{z} }_{tp}
    \underbrace{ - \frac{2}{3}
%\epsilon
                  C_{14} \frac{\bar{e}}{\tau}
               }_{pr1} \\
    & \underbrace{ + \frac{2}{3} C_{5}
      \left(
        \frac{g}{\theta_{vs}} \overline{w'\theta'_v}
        - \overline{u'w'}\ptlder{\bar{u}}{z}
        - \overline{v'w'}\ptlder{\bar{v}}{z}
      \right) }_{pr2}
     \underbrace{ - \dfrac{C_4}{\tau} \left( \overline{v^{'2}} - \frac{2}{3} \bar{e} \right) }_{dp1} \\
    & + \underbrace{ \ptlder{}{z} \left[ \left( K_{w9} + \nu_9 \right)
                          \ptlder{}{z} \overline{v^{'2}}
                   \right] }_{dp2}
    + \left. \ptlder{\overline{v^{'2}}}{t} \right|_{\rm{pd}}
    + \left. \ptlder{\overline{v^{'2}}}{t} \right|_{\rm{cl}}
\end{split}
\end{equation}
%

Where, $\epsilon$ in \citet{bougeault1981b}, the dissipation of $\bar{e}$, has been defined in CLUBB by the equation:
\begin{equation}
\epsilon = C_{14} \frac{\bar{e}}{\tau}
\end{equation}

The time scale $\tau$ is:
%
\begin{equation}
\label{eq_tau}
\tau = \left\{
\begin{array}{ll}
\displaystyle \frac{L}{\sqrt{\, \overline{e} \,}};
& L / \sqrt{\, \overline{e} \,} \leqslant \tau_{\rm max} \\
\displaystyle \tau_{\rm max};
&  L / \sqrt{\, \overline{e} \,} > \tau_{\rm max}
\end{array}
\right. \hbox{ .}
\end{equation}
%
% This is no longer true
%Additionally, $\tau$ is set to a minimum value $\tau_{\rm min}$
%whenever $\overline{w'^2} \leqslant 0.005$ m$^2$ s$^{-2}$.

The momentum fluxes are closed using a down gradient approach:
%
\begin{subequations}
\begin{equation}
\label{eq_upwp}
\overline{u'w'} = -K_m \ptlder{\bar{u}}{z}
\end{equation}
%
\begin{equation}
\label{eq_vpwp}
\overline{v'w'} = -K_m \ptlder{\bar{v}}{z}
\end{equation}
\end{subequations}
%
The momentum fluxes, $\overline{u'w'}$ and $\overline{v'w'}$, are also subject
to completely explicit clipping.  The turbulent-transfer coefficient $K_m$ is
given by:
%
\begin{equation}
\label{eq_Km}
K_m = c_K \, L \, \overline{e}^{\, 1/2} .
\end{equation}
%
$c_K = c_{\mu}^{\, 1/4} = 0.548$ in \citet{duynkerke1987a}, but CLUBB reduces the value to better fit LES output.

%The eddy diffusivity coefficient $K_w$ is
%%
%\begin{equation}
%\label{eq_Kw}
%K_w = 0.22 \, L \, \overline{e}^{\, 1/2}.
%\end{equation}

The eddy diffusivity coefficients in Equation~(\ref{eq_wp2}) through
Equation~(\ref{eq_wp3}) and in Equations (\ref{eq_up2}) and (\ref{eq_vp2})
are as follows:
\begin{displaymath}
\begin{split}
& K_{w1} = c_{K1} K_m + \left. c_{Ksqd} \, \overline{w^{'2}}^{\, 2}
                        \right|_{\mathrm{3 \ pnt \ avg}} \\
& K_{w2} = c_{K2} K_m + \left. c_{Ksqd} \, \lambda
                        \right|_{\mathrm{3 \ pnt \ avg}} \\
& K_{w6} = c_{K6} K_m + \left. c_{Ksqd} \, \phi
                        \right|_{\mathrm{3 \ pnt \ avg}} \\
& K_{w8} = c_{K8} K_m + \left. c_{Ksqd} \, \overline{w^{'3}}^{\, 2}
                        \right|_{\mathrm{3 \ pnt \ avg}} \\
& K_{w9} = c_{K9} K_m + \left. c_{Ksqd} \, \eta
                        \right|_{\mathrm{3 \ pnt \ avg}}
\end{split}
\end{displaymath}
%
where $\lambda$ is $10^{12} \, \overline{r_t^{'2}}^{\, 2}$ for
Equation~(\ref{eq_rtp2}), $\overline{\theta_l^{'2}}^{\, 2}$ for
Equation~(\ref{eq_thlp2}), and $10^6 \, \overline{r_t'\theta_l'}^{\, 2}$
for Equation~(\ref{eq_rtpthlp});
$\phi$ is $10^6 \, \overline{w'r_t'}^{\, 2}$ for Equation~(\ref{eq_wprtp})
and $\overline{w'\theta_l'}^{\, 2}$ for Equation~(\ref{eq_wpthlp}); and
$\eta$ is $\overline{u^{'2}}^{\, 2}$ for Equation~(\ref{eq_up2}) and
$\overline{v^{'2}}^{\, 2}$ for Equation~(\ref{eq_vp2}).
%
%The specific values of the constants $C_i$ and $\nu_i$
%are as follows: $C_1 = 2.5$; $C_2 = 1.0$; $C_4 = 5.2$; $C_5 = 0.3$;
%$C_6 = 6.0$; $C_7 = 0.1$; $C_8 = 3.0$; $C_{11} = 0.75$; $C_{14} = 1.0$;
%$\nu_1 = \nu_8 = \nu_9 = 20 \hbox{ (m$^2$/s)}$;
%and $\nu_2 = \nu_6 = 5 \hbox{ (m$^2$/s)}$.  In addition, the specific
%values of the constants $c_{Ki}$ are as follows:  $c_{K1} = 0$;
%$c_{K2} = 0$; $c_{K6} = 0$; $c_{K8} = 0.5$; $c_{K9} = 0$; and $c_{Ksqd} = 10$.

\section{PDF closure}

Details of the PDF closure can be found in \citet{larson2005a}, hereafter
referred to as LG. We only briefly summarize key aspects here.

\subsection{Transport terms}

The transport terms appearing in Eqs (\ref{eq_um})-(\ref{eq_wp3}) are
closed as follows. First, we define $c_{w\theta_l}$ and $c_{wr_t}$
as in Eqs (LG15) and (LG16):
%
\begin{equation}
\label{eq_cwthl}
c_{w\theta_l}
= \frac{ \overline{w'\theta_l'} }
       { \sqrt{\overline{w'^2}}\sqrt{\overline{\theta_l'^2}} }
\end{equation}
%
\begin{equation}
\label{eq_cwrt}
c_{wr_t}
= \frac{ \overline{w'r_t'} }
       { \sqrt{\overline{w'^2}}\sqrt{\overline{r_t'^2}} }
\end{equation}
%
The width of the individual $w$ plumes is given by (LG37):
%
\begin{equation}
\label{eq_sc}
\tilde{\sigma}^2_w
= \gamma \left[ 1 - \max\left( c^2_{w\theta_l}, c^2_{wr_t} \right) \right]
\end{equation}
%
We define the following quantities in order to simplify the notation:
%
\begin{equation}
\label{eq_a1}
a_1 = \frac{1}{ (1-\tilde{\sigma}_w^2) }
\end{equation}
%
\begin{equation}
\label{eq_a2}
a_2 = \frac{1}{ (1-\tilde{\sigma}_w^2)^2 }
\end{equation}
%
\begin{equation}
\label{eq_a3}
a_3 = 3 \tilde{\sigma}_w^4
      + 6 ( 1 - \tilde{\sigma}_w^2 ) \tilde{\sigma}_w^2
      + ( 1 - \tilde{\sigma}_w^2 )^2
      - 3
\end{equation}
%
The turbulence moment $\overline{w'^4}$ is given by (LG40):
%
\begin{equation}
\label{eq_wp4}
\overline{w^{'4}}
= \overline{w^{'2}}^2
  \left( a_3 + 3 \right)
+ a_1 \frac{ \overline{w^{'3}}^2 }{ \overline{w^{'2}} }
\end{equation}
%
The flux transport terms are given by (LG42):
%
\begin{equation}
\label{eq_wp2thlp}
\overline{w^{'2}\theta_l'}
= a_1 \frac{\overline{w^{'3}}}{\overline{w^{'2}}} \,
  \overline{w'\theta_l'}
\end{equation}
%
\begin{equation}
\label{eq_wp2rtp}
\overline{w^{'2}r_t'}
= a_1 \frac{\overline{w^{'3}}}{\overline{w^{'2}}} \,
  \overline{w'r_t'}
\end{equation}
%
The variance transport terms follow (LG46):
%
\begin{equation}
\label{eq_wpthlp2}
\begin{split}
\overline{w'\theta_l^{'2}}
& =
    \frac{1}{3} \beta
    a_1 \frac{\overline{w^{'3}}}{\overline{w^{'2}}} \overline{\theta_l^{'2}}
  + \left( 1 - \frac{1}{3}\beta \right)
    a_2 \frac{\overline{w^{'3}}}{\overline{w^{'2}}^2} \overline{w'\theta_l'}^2 \,
\end{split}
\end{equation}
%
\begin{equation}
\label{eq_wprtp2}
\begin{split}
\overline{w'r_t^{'2}}
& =
    \frac{1}{3} \beta
    a_1 \frac{\overline{w^{'3}}}{\overline{w^{'2}}} \overline{r_t^{'2}}
  + \left( 1 - \frac{1}{3}\beta \right)
    a_2 \frac{\overline{w^{'3}}}{\overline{w^{'2}}^2} \overline{w'r_t'}^2 \,
\end{split}
\end{equation}
%
Finally, the covariance term is obtained substituting (LG56) into (LG48):
%
\begin{equation}
\label{eq_wprtpthlp}
\begin{split}
\overline{w'r_t'\theta'_l}
& =
    \frac{1}{3} \beta
    a_1 \frac{\overline{w^{'3}}}{\overline{w^{'2}}} \,
    \overline{r_t'\theta'_l}
  + \left( 1 - \frac{1}{3}\beta \right)
    a_2 \frac{\overline{w^{'3}}}{\overline{w^{'2}}^2}
    \overline{w'r_t'} \, \overline{w'\theta_l'}
\end{split}
\end{equation}
%
In the anisotropic case, the horizontal wind variance terms are obtained by:
%
\begin{equation}
\label{eq_wpup2}
\begin{split}
\overline{w'u^{'2}}
& =
    \frac{1}{3} \beta
    a_1 \frac{\overline{w^{'3}}}{\overline{w^{'2}}} \overline{u^{'2}}
  + \left( 1 - \frac{1}{3}\beta \right)
    a_2 \frac{\overline{w^{'3}}}{\overline{w^{'2}}^2} \overline{w'u'}^2 \,
\end{split}
\end{equation}
%
\begin{equation}
\label{eq_wpvp2}
\begin{split}
\overline{w'v^{'2}}
& =
    \frac{1}{3} \beta
    a_1 \frac{\overline{w^{'3}}}{\overline{w^{'2}}} \overline{v^{'2}}
  + \left( 1 - \frac{1}{3}\beta \right)
    a_2 \frac{\overline{w^{'3}}}{\overline{w^{'2}}^2} \overline{w'v'}^2 \,
\end{split}
\end{equation}
%

\subsection{Buoyancy terms}

There are more unclosed terms involving $\theta_v$. They are
$\overline{w'\theta'_v}$, $\overline{r'_t\theta'_v}$,
$\overline{\theta'_l\theta'_v}$, and $\overline{w^{'2}\theta'_v}$ and can be
written as:
%
\begin{equation}
\overline{\chi'\theta'_v}
= \overline{\chi'\theta'_l}
+ \underbrace{ \frac{1-\epsilon_0}{\epsilon_0} \theta_0
             }_{\equiv A \, (\approx \, 200 K)}
  \overline{\chi'r'_t}
+ \underbrace{
   \left(
     \frac{L_v}{c_p} \left( \frac{p_0}{p} \right)^{R_d/c_p}
     - \frac{1}{\epsilon_0}\theta_0
   \right) }_{\equiv B \, (\approx \, 2000 K)}
  \overline{\chi'r'_l} \hbox{ ,}
\end{equation}
%
where $\chi'$ represents $w'$, $r'_t$, $\theta'_l$,  $w^{'2}$, or
a passive scalar.
Here $\epsilon_0 = R_d/R_v$, $R_d$ is the gas constant of dry air,
$R_v$ is the gas constant of water vapor, $L_v$ is the latent heat
of vaporization, $c_p$ is the heat capacity of air,
and $p_0$ is a reference pressure. The correlations involving
liquid water ($\overline{\chi'r'_l}$) can be computed for the given
family of PDFs (see next section).

\section{Cloud properties}

The cloud properties, such as cloud fraction, mean liquid water
and correlations involving liquid water ($\overline{\chi'r'_l}$)
are obtained from the PDF. To do so, a certain number of properties
are computed for each Gaussian ($i=1,2$):
%
\begin{equation}
T_{li} = \theta_{li} \left( \frac{p}{p_0} \right)^{R_d/c_p}
\end{equation}
%
\begin{equation}
\label{eq:rs_def}
r_{si} = \frac{R_d}{R_v}\; \frac{e_s(T_{li})}{p-[1-(R_d/R_v)] e_s(T_{li})}
\end{equation}
%
\begin{equation}
\label{eq:beta_def}
\beta_i =
\frac{R_d}{R_v} \left( \frac{L}{R_d T_{li}} \right)
\left( \frac{L}{c_p T_{li}} \right)
\end{equation}
%
\begin{equation}
\label{eq:s_def}
s_i = r_{ti} - r_{si}\frac{1+\beta_i r_{ti}}{1+\beta_i r_{si}}
\end{equation}
%
\begin{equation}
c_{r_{ti}} = \frac{1}{1 + \beta_i r_{si}}
\end{equation}
%
\begin{equation}
c_{\theta_{li}}
= \frac{1 + \beta_i r_{ti}}
       {[1 + \beta_i r_{si}]^2}
  \frac{c_p}{L} \beta_i r_{si}
  \left( \frac{p}{p_0} \right)^{R_d/c_p}
\end{equation}
%
\begin{equation}
\sigma_{si}^2
= c_{\theta_{li}}^2 \sigma_{\theta_{li}}^2
+ c_{r_{ti}}^2 \sigma_{r_{ti}}^2
- 2 c_{\theta_{li}} \sigma_{\theta_{li}}
    c_{r_{ti}} \sigma_{r_{ti}} r_{r_t \theta_l}
\end{equation}
%
\begin{equation}
\label{eq:C_gauss}
C_i = \frac{1}{2}
      \left[
        1 + \mathrm{erf} \left( \frac{s_i}{\sqrt{2}\sigma_{si}} \right)
      \right]
\end{equation}
%
\begin{equation}
\label{eq:rl_gauss}
r_{li}
= s_i C_i
+ \frac{\sigma_{si}}{\sqrt{2\pi}}
  \exp \left[
         -\frac{1}{2}\left( \frac{s_i}{\sigma_{si}} \right)^2
       \right]
\end{equation}
%
where $C_i$ and $r_{li}$ are the cloud fractions and liquid water of
each individual Gaussian.

The layer-averaged cloud properties are given by:
%
\begin{equation}
\overline{C} = a C_1 + (1-a) C_2
\end{equation}
%
\begin{equation}
\overline{r_l} = a r_{l1} + (1-a) r_{l2}
\end{equation}
%
\begin{equation}
\overline{w'r_l'} = a (w_1-\bar{w}) r_{l1} + (1-a) (w_2-\bar{w}) r_{l2}
\end{equation}
%
\begin{equation}
\overline{w^{'2}r_l'}
= a \left( (w_1-\bar{w})^2 + \sigma_{w1}^2 \right) r_{l1}
+ (1-a) \left( (w_2-\bar{w})^2 + \sigma_{w2}^2 \right) r_{l2}
- \overline{w^{'2}} \left( a r_{l1} + (1-a) r_{l2} \right)
\end{equation}
%
\begin{equation}
\begin{split}
\overline{\theta_l'r_l'}
=& a \left[
       (\theta_{l1} - \bar{\theta}_l ) r_{l1}
       - C_1
         \left(
           c_{\theta_{l1}} \sigma_{\theta_{l1}}^2
           - r_{r_t \theta_l} c_{r_{t1}} \sigma_{r_{t1}} \sigma_{\theta_{l1}}
         \right)
     \right] \\
&+ (1-a) \left[
           (\theta_{l2} - \bar{\theta}_l ) r_{l2}
           - C_2
             \left(
               c_{\theta_{l2}} \sigma_{\theta_{l2}}^2
               - r_{r_t \theta_l} c_{r_{t2}} \sigma_{r_{t2}} \sigma_{\theta_{l2}}
             \right)
         \right]
\end{split}
\end{equation}
%
\begin{equation}
\begin{split}
\overline{r_t'r_l'}
=& a
   \left[
     (r_{t1} - \bar{r}_t ) r_{l1}
     + C_1
       \left(
         c_{r_{t1}} \sigma_{r_{t1}}^2
         - r_{r_t \theta_l} c_{\theta_{l1}} \sigma_{r_{t1}} \sigma_{\theta_{l1}}
       \right)
   \right]\\
&+ (1-a)
   \left[
     (r_{t2} - \bar{r}_t ) r_{l2}
     + C_2
       \left(
         c_{r_{t2}} \sigma_{r_{t2}}^2
         - r_{r_t \theta_l} c_{\theta_{l2}} \sigma_{r_{t2}} \sigma_{\theta_{l2}}
       \right)
   \right]
\end{split}
\end{equation}

\section{Steady-state solutions for the variances}

\subsection{ $\overline{r_t^{'2}}$ and $\overline{\theta_l^{'2}}$ }

Start with (\ref{eq_rtp2}) (for simplicity, neglect the
$\left.\right|_{\rm{pd}}$ and $\left.\right|_{\rm{cl}}$ terms), substitute
(\ref{eq_wprtp2}), assume steady-state and rearrange:
%
\begin{equation}
\begin{split}
\label{eq_rtp2_ss}
& \dfrac{C_2}{\tau} \overline{r_t^{'2}}
+ \bar{w}\ptlder{\overline{r^{'2}_t}}{z}
+ \frac{1}{3} \beta
   \ptlder{}{z}
     \left(
       a_1
       \frac{\overline{w^{'3}}}{\overline{w^{'2}}} \,
       \overline{r_t^{'2}}
     \right)
- \ptlder{}{z} \left[ \left( K_{w2} + \nu_2 \right)
                      \ptlder{}{z} \overline{r_t^{'2}}
               \right]  \\
=& - \left( 1 - \frac{1}{3}\beta \right)
       \ptlder{}{z}
         \left(
           a_2
           \frac{\overline{w^{'3}}}{\overline{w^{'2}}^2} \,
           \overline{w'r_t'}^2
         \right)
   - 2 \, \overline{w'r'_t} \, \ptlder{\bar{r}_t}{z}
   + \dfrac{C_2}{\tau} \left. r_t \right|_{\rm{tol}}^{2}
\end{split}
\end{equation}
%
The goal is to recast (\ref{eq_rtp2_ss}) so that $\overline{r_t^{'2}}$
can be computed using a tridiagonal solver:
%
\begin{displaymath}
\underbrace{
\begin{bmatrix}
\phantom{(x,x)} & (1,2) & \cdots & (1,\mathrm{nzmax}-1) & (1,\mathrm{nzmax}) \\
(2,1)           & (2,2) & \cdots & (2,\mathrm{nzmax}-1) & (2,\mathrm{nzmax}) \\
(3,1)           & (3,2) & \cdots & (3,\mathrm{nzmax}-1) & \phantom{(x,nzmax)}\\
\end{bmatrix}}_{\mathtt{LHS} \textrm{(Stored in compact format)}}
\begin{bmatrix}
\mathtt{rtp2}(1) \\
\mathtt{rtp2}(2) \\
\vdots \\
\mathtt{rtp2}(\mathrm{nzmax}-1) \\
\mathtt{rtp2}(\mathrm{nzmax}) \\
\end{bmatrix}
=
\underbrace{
\begin{bmatrix}
(1) \\
(2) \\
\vdots \\
(\mathrm{nzmax-1}) \\
(\mathrm{nzmax}) \\
\end{bmatrix}}_{\mathtt{RHS}}
\end{displaymath}
%
\begin{equation}
\mathtt{ lhs(3,k) \, rtp2(k-1) + lhs(2,k) \, rtp2(k) + lhs(1,k) \, rtp2(k+1) = rhs(k) }
\end{equation}
%
We now compute the contributions of each term in (\ref{eq_rtp2_ss}) to
$\mathtt{lhs(3,k)}$, $\mathtt{lhs(2,k)}$, $\mathtt{lhs(1,k)}$,
and $\mathtt{rhs(k)}$.

\subsubsection{Term 1:  dp1, implicit component}

\begin{equation}
\mathtt{ lhs(2,k) = lhs(2,k) + \frac{C_2}{taum(k)} }
\end{equation}

\subsubsection{Term 2:  ma}

\begin{equation}
\begin{split}
& \left. \bar{w}\ptlder{\overline{q^{'2}_t}}{z} \right|_{\mathtt{zm(k)}} \\
=& \mathtt{ \frac{wmm(k)}{dzm(k)}
   \left(
     \frac{1}{2} \left( rtp2(k)+rtp2(k+1) \right)
     - \frac{1}{2} \left( rtp2(k-1)+rtp2(k) \right)
   \right) } \\
=& \mathtt{ \frac{wmm(k)}{2 dzm(k)} rtp2(k+1) - \frac{wmm(k)}{2 dzm(k)} rtp2(k-1) }
\end{split}
\end{equation}

Separating out the contributions:
%
\begin{equation}
\begin{split}
& \mathtt{ lhs(3,k) = lhs(3,k) - \frac{wmm(k)}{2 dzm(k)} } \\
& \mathtt{ lhs(1,k) = lhs(1,k) + \frac{wmm(k)}{2 dzm(k)} }
\end{split}
\end{equation}

\subsubsection{Term 3:  ta, implicit component}

\begin{equation}
\begin{split}
& \left.
  \frac{1}{3} \beta
   \ptlder{}{z}
     \left(
       a_1
       \frac{\overline{w^{'3}}}{\overline{w^{'2}}} \,
       \overline{r_t^{'2}}
     \right)
   \right|_{\mathtt{zm(k)}} \\
&= \mathtt{
    \frac{\beta}{6 dzm(k)}
    \bigg[ \frac{\left(a1m(k)+a1m(k+1)\right) wp3(k+1) \left(rtp2(k)+rtp2(k+1) \right)}
                {\max\left(wp2(k)+wp2(k+1),2\epsilon\right)} } \\
&  \mathtt{ \quad \quad \quad \quad \quad \quad
          -\frac{\left(a1m(k-1)+a1m(k)\right) wp3(k) \left(rtp2(k-1)+rtp2(k) \right)}
                {\max\left(wp2(k-1)+wp2(k),2\epsilon\right)}
    \bigg]
    }
\end{split}
\end{equation}
%
Separating out the contributions:
%
\begin{equation}
\begin{split}
& \mathtt{
   lhs(3,k) = lhs(3,k) - \frac{\beta}{6 dzm(k)}
                 \frac{\left(a1m(k-1)+a1m(k)\right) wp3(k)}
                      {\max\left(wp2(k-1)+wp2(k),2\epsilon\right)}
  } \\
& \mathtt{
   lhs(2,k) = lhs(2,k) + \frac{\beta}{6 dzm(k)}
                 \left(
                   \frac{\left(a1m(k)+a1m(k+1)\right) wp3(k+1)}
                        {\max\left(wp2(k)+wp2(k+1),2\epsilon\right)}
                  -\frac{\left(a1m(k-1)+a1m(k)\right) wp3(k)}
                        {\max\left(wp2(k-1)+wp2(k),2\epsilon\right)}
                 \right)
  } \\
& \mathtt{
   lhs(1,k) = lhs(1,k) + \frac{\beta}{6 dzm(k)}
                 \frac{\left(a1m(k)+a1m(k+1)\right) wp3(k+1)}
                      {\max\left(wp2(k)+wp2(k+1),2\epsilon\right)}
  }
\end{split}
\end{equation}
%
In order to increase numerical stability in the model, $a_{1}$ has been brought
outside of the derivative.  This is not mathematically correct, but it does
help to increase stability.  Brian Griffin.  Feb. 21, 2008.
%
\begin{equation}
\begin{split}
& \left.
  a_1
  \frac{1}{3} \beta
   \ptlder{}{z}
     \left(
       \frac{\overline{w^{'3}}}{\overline{w^{'2}}} \,
       \overline{r_t^{'2}}
     \right)
   \right|_{\mathtt{zm(k)}} \\
&= \mathtt{
    a1m(k)
    \frac{\beta}{3 dzm(k)}
    \bigg[ \frac{wp3(k+1) \left(rtp2(k)+rtp2(k+1) \right)}
                {\max\left(wp2(k)+wp2(k+1),2\epsilon\right)}
          -\frac{wp3(k) \left(rtp2(k-1)+rtp2(k) \right)}
                {\max\left(wp2(k-1)+wp2(k),2\epsilon\right)}
    \bigg]
    }
\end{split}
\end{equation}
%
Separating out the contributions:
%
\begin{equation}
\begin{split}
& \mathtt{
   lhs(3,k) = lhs(3,k) - a1m(k)\frac{\beta}{3 dzm(k)}
                 \frac{wp3(k)}
                      {\max\left(wp2(k-1)+wp2(k),2\epsilon\right)}
  } \\
& \mathtt{
   lhs(2,k) = lhs(2,k) + a1m(k)\frac{\beta}{3 dzm(k)}
                 \left(
                   \frac{wp3(k+1)}
                        {\max\left(wp2(k)+wp2(k+1),2\epsilon\right)}
                  -\frac{wp3(k)}
                        {\max\left(wp2(k-1)+wp2(k),2\epsilon\right)}
                 \right)
  } \\
& \mathtt{
   lhs(1,k) = lhs(1,k) + a1m(k)\frac{\beta}{3 dzm(k)}
                 \frac{wp3(k+1)}
                      {\max\left(wp2(k)+wp2(k+1),2\epsilon\right)}
  }
\end{split}
\end{equation}

\subsubsection{Term 4:  dp2}

\begin{equation}
\begin{split}
& - \ptlder{}{z} \left[ \left( K_{w2} + \nu_2 \right)
                        \ptlder{}{z} \overline{q_t^{'2}}
                 \right]  \\
 &= \mathtt{
    -\frac{1}{dzm(k)}
     \bigg( \frac{ \left( Kw2(k+1) + \nu_2 \right)
                   \left( rtp2(k+1) - rtp2(k) \right)} {dzt(k+1)}  }  \\
 &  \mathtt{ \qquad \qquad \qquad \quad
           -\frac{ \left( Kw2(k) + \nu_2 \right)
                   \left( rtp2(k) - rtp2(k-1) \right)} {dzt(k)}
     \bigg)
    }
\end{split}
\end{equation}
%
Separating out the contributions:
%
\begin{equation}
\begin{split}
&\mathtt{lhs(3,k) = lhs(3,k) - \frac{Kw2(k)+\nu_2}{dzm(k)dzt(k)} } \\
&\mathtt{lhs(2,k) = lhs(2,k) + \frac{1}{dzm(k)}
                               \left(   \frac{Kw2(k+1)+\nu_2}{dzt(k+1)}
                                      + \frac{Kw2(k)+\nu_2}{dzt(k)} \right) } \\
&\mathtt{lhs(1,k) = lhs(1,k) - \frac{Kw2(k+1)+\nu_2}{dzm(k)dzt(k+1)} }
\end{split}
\end{equation}

\subsubsection{Term 5:  ta, explicit component}

\begin{equation}
\begin{split}
& - \left. \left( 1 - \frac{1}{3}\beta \right)
       \ptlder{}{z}
         \left(
           a_2
           \frac{\overline{w^{'3}}}{\overline{w^{'2}}^2} \,
           \overline{w'q_t'}^2
         \right) \right|_{\mathtt{zm(k)}} \\
=& \mathtt{
   - \frac{1 - \frac{1}{3}\beta}{4 dzm(k)}
     \bigg[ \frac{\left(a1m(k)+a1m(k+1)\right)^2 wp3(k+1) \left(wprtp(k)+wprtp(k+1)\right)^2}
                 {\max\left(wp2(k)+wp2(k+1),2\epsilon\right)^2} } \\
 & \mathtt{ \quad \quad \quad \quad \quad \quad
           -\frac{\left(a1m(k-1)+a1m(k)\right)^2 wp3(k) \left(wprtp(k-1)+wprtp(k)\right)^2}
                 {\max\left(wp2(k-1)+wp2(k),2\epsilon\right)^2}
     \bigg]
   }
\end{split}
\end{equation}
%
Separating out the contributions:
%
\begin{equation}
\begin{split}
&\mathtt{rhs(k)} \\
=& \mathtt{
   rhs(k)
   - \frac{1 - \frac{1}{3}\beta}{4 dzm(k)}
     \bigg[ \frac{\left(a1m(k)+a1m(k+1)\right)^2 wp3(k+1) \left(wprtp(k)+wprtp(k+1)\right)^2}
                 {\max\left(wp2(k)+wp2(k+1),2\epsilon\right)^2} } \\
 & \mathtt{ \quad \quad \quad \quad \quad \quad \quad \quad
           -\frac{\left(a1m(k-1)+a1m(k)\right)^2 wp3(k) \left(wprtp(k-1)+wprtp(k)\right)^2}
                 {\max\left(wp2(k-1)+wp2(k),2\epsilon\right)^2}
     \bigg]
   }
\end{split}
\end{equation}
%
In order to increase numerical stability in the model, $a_{1}$ has been brought
outside of the derivative.  This is not mathematically correct, but it does
help to increase stability.  Brian Griffin.  Feb. 21, 2008.
%
\begin{equation}
\begin{split}
& - \left. a_2 \left( 1 - \frac{1}{3}\beta \right)
       \ptlder{}{z}
         \left(
           \frac{\overline{w^{'3}}}{\overline{w^{'2}}^2} \,
           \overline{w'r_t'}^2
         \right) \right|_{\mathtt{zm(k)}} \\
=& \mathtt{
   - a1m(k)^{2}\frac{1 - \frac{1}{3}\beta}{dzm(k)}
     \bigg[ \frac{wp3(k+1) \left(wprtp(k)+wprtp(k+1)\right)^2}
                 {\max\left(wp2(k)+wp2(k+1),2\epsilon\right)^2} } \\
 & \mathtt{ \quad \quad \quad \quad \quad \quad \quad \quad
           -\frac{wp3(k) \left(wprtp(k-1)+wprtp(k)\right)^2}
                 {\max\left(wp2(k-1)+wp2(k),2\epsilon\right)^2}
     \bigg]
   }
\end{split}
\end{equation}
%
Separating out the contributions:
%
\begin{equation}
\begin{split}
&\mathtt{rhs(k)} \\
=& \mathtt{
   rhs(k)
   - a1m(k)^{2}\frac{1 - \frac{1}{3}\beta}{dzm(k)}
     \bigg[ \frac{wp3(k+1) \left(wprtp(k)+wprtp(k+1)\right)^2}
                 {\max\left(wp2(k)+wp2(k+1),2\epsilon\right)^2} } \\
 & \mathtt{ \quad \quad \quad \quad \qquad \qquad \qquad \qquad
           -\frac{wp3(k) \left(wprtp(k-1)+wprtp(k)\right)^2}
                 {\max\left(wp2(k-1)+wp2(k),2\epsilon\right)^2}
     \bigg]
   }
\end{split}
\end{equation}

\subsubsection{Term 6:  tp}

\begin{equation}
\begin{split}
&\left. - 2 \, \overline{w'r'_t} \, \ptlder{\bar{r}_t}{z} \right|_{\mathtt{zm(k)}}
 = \mathtt{ - 2 wprtp(k) \frac{rtm(k+1)-rtm(k)}{dzm(k)} }
\end{split}
\end{equation}
%
Separating out the contributions:
%
\begin{equation}
\begin{split}
&\mathtt{rhs(k) = rhs(k) - 2 wprtp(k) \frac{rtm(k+1)-rtm(k)}{dzm(k)} }
\end{split}
\end{equation}

\subsubsection{Term 7:  dp1, explicit component}

\begin{equation}
\mathtt{ rhs(k) = rhs(k) + \frac{C_2}{taum(k)} rttol^{2} }
\end{equation}

\subsection{ $\overline{q_t'\theta_l'}$  }

Start with (\ref{eq_rtpthlp}) (for simplicity, neglect the
$\left.\right|_{\rm{cl}}$ term), substitute (\ref{eq_wprtpthlp}), assume
steady-state and rearrange:
%
\begin{equation}
\label{eq_rtpthlp_ss}
\begin{split}
& \frac{C_2}{\tau} \overline{r_t' \theta_l'}
+ \bar{w}\ptlder{\overline{r'_t\theta'_l}}{z}
+ \frac{1}{3} \beta
   \ptlder{}{z}
     \left(
       a_1
       \frac{\overline{w^{'3}}}{\overline{w^{'2}}} \,
       \overline{r_t'\theta_l'}
     \right)
- \ptlder{}{z} \left[ \left( K_{w2} + \nu_2 \right)
                      \ptlder{}{z} \overline{r_t^{'}\theta_l^{'}}
               \right]  \\
=&
   - \left( 1 - \frac{1}{3}\beta \right)
      \ptlder{}{z}
        \left(
          a_2
          \frac{\overline{w^{'3}}}{\overline{w^{'2}}^2} \,
          \overline{w'r_t'} \, \overline{w'\theta_l'}
        \right)
   - \overline{w'r'_t}\ptlder{\bar{\theta}_l}{z}
   - \overline{w'\theta'_l}\ptlder{\bar{r}_t}{z} \\
\end{split}
\end{equation}
%
As for the variances, the goal is to recast (\ref{eq_rtpthlp_ss}) so that
$\overline{r_t'\theta_l'}$ can be computed using a tridiagonal solver:
%
\begin{equation}
\mathtt{ lhs(3,k) \, rtpthlp(k-1) + lhs(2,k) \, rtpthlp(k) + lhs(1,k) \, rtpthlp(k+1) = rhs(k) }
\end{equation}
%
We now compute the contributions of each term in (\ref{eq_rtpthlp_ss}) to
$\mathtt{lhs(3,k)}$, $\mathtt{lhs(2,k)}$, $\mathtt{lhs(1,k)}$,
and $\mathtt{rhs(k)}$.

\subsubsection{Term 1:  dp1}

\begin{equation}
\mathtt{ lhs(2,k) = lhs(2,k) + \frac{C_2}{taum(k)} }
\end{equation}

\subsubsection{Term 2:  ma}

\begin{equation}
\begin{split}
& \left. \bar{w}\ptlder{\overline{r_t^{'}\theta_l^{'}}}{z} \right|_{\mathtt{zm(k)}} \\
=& \mathtt{ \frac{wmm(k)}{dzm(k)}
   \left(
     \frac{1}{2} \left( rtpthlp(k)+rtpthlp(k+1) \right)
     - \frac{1}{2} \left( rtpthlp(k-1)+rtpthlp(k) \right)
   \right) } \\
=& \mathtt{ \frac{wmm(k)}{2 dzm(k)} rtpthlp(k+1) - \frac{wmm(k)}{2 dzm(k)} rtpthlp(k-1) }
\end{split}
\end{equation}

Separating out the contributions:
%
\begin{equation}
\begin{split}
& \mathtt{ lhs(3,k) = lhs(3,k) - \frac{wmm(k)}{2 dzm(k)} } \\
& \mathtt{ lhs(1,k) = lhs(1,k) + \frac{wmm(k)}{2 dzm(k)} }
\end{split}
\end{equation}

\subsubsection{Term 3:  ta, implicit component}

\begin{equation}
\begin{split}
& \left.
  \frac{1}{3} \beta
   \ptlder{}{z}
     \left(
       a_1
       \frac{\overline{w^{'3}}}{\overline{w^{'2}}} \,
       \overline{r_t^{'}\theta_l^{'}}
     \right)
   \right|_{\mathtt{zm(k)}} \\
&= \mathtt{
    \frac{\beta}{6 dzm(k)}
    \bigg[ \frac{\left(a1m(k)+a1m(k+1)\right) wp3(k+1) \left(rtpthlp(k)+rtpthlp(k+1) \right)}
                {\max\left(wp2(k)+wp2(k+1),2\epsilon\right)} } \\
&  \mathtt{ \quad \quad \quad \quad \quad \quad
          -\frac{\left(a1m(k-1)+a1m(k)\right) wp3(k) \left(rtpthlp(k-1)+rtpthlp(k) \right)}
                {\max\left(wp2(k-1)+wp2(k),2\epsilon\right)}
    \bigg]
    }
\end{split}
\end{equation}
%
Separating out the contributions:
%
\begin{equation}
\begin{split}
& \mathtt{
   lhs(3,k) = lhs(3,k) - \frac{\beta}{6 dzm(k)}
                 \frac{\left(a1m(k-1)+a1m(k)\right) wp3(k)}
                      {\max\left(wp2(k-1)+wp2(k),2\epsilon\right)}
  } \\
& \mathtt{
   lhs(2,k) = lhs(2,k) + \frac{\beta}{6 dzm(k)}
                 \left(
                   \frac{\left(a1m(k)+a1m(k+1)\right) wp3(k+1)}
                        {\max\left(wp2(k)+wp2(k+1),2\epsilon\right)}
                  -\frac{\left(a1m(k-1)+a1m(k)\right) wp3(k)}
                        {\max\left(wp2(k-1)+wp2(k),2\epsilon\right)}
                 \right)
  } \\
& \mathtt{
   lhs(1,k) = lhs(1,k) + \frac{\beta}{6 dzm(k)}
                 \frac{\left(a1m(k)+a1m(k+1)\right) wp3(k+1)}
                      {\max\left(wp2(k)+wp2(k+1),2\epsilon\right)}
  }
\end{split}
\end{equation}
%
In order to increase numerical stability in the model, $a_{1}$ has been brought
outside of the derivative.  This is not mathematically correct, but it does
help to increase stability.  Brian Griffin.  Feb. 21, 2008.
%
\begin{equation}
\begin{split}
& \left.
  a_1
  \frac{1}{3} \beta
   \ptlder{}{z}
     \left(
       \frac{\overline{w^{'3}}}{\overline{w^{'2}}} \,
       \overline{r_t^{'}\theta_l^{'}}
     \right)
   \right|_{\mathtt{zm(k)}} \\
&= \mathtt{
    a1m(k)
    \frac{\beta}{3 dzm(k)}
    \bigg[ \frac{wp3(k+1) \left(rtpthlp(k)+rtpthlp(k+1) \right)}
                {\max\left(wp2(k)+wp2(k+1),2\epsilon\right)} } \\
&  \mathtt{ \quad \quad \quad \quad \quad \quad \quad \quad \quad
          -\frac{wp3(k) \left(rtpthlp(k-1)+rtpthlp(k) \right)}
                {\max\left(wp2(k-1)+wp2(k),2\epsilon\right)}
    \bigg]
    }
\end{split}
\end{equation}
%
Separating out the contributions:
%
\begin{equation}
\begin{split}
& \mathtt{
   lhs(3,k) = lhs(3,k) - a1m(k)\frac{\beta}{3 dzm(k)}
                 \frac{wp3(k)}
                      {\max\left(wp2(k-1)+wp2(k),2\epsilon\right)}
  } \\
& \mathtt{
   lhs(2,k) = lhs(2,k) + a1m(k)\frac{\beta}{3 dzm(k)}
                 \left(
                   \frac{wp3(k+1)}
                        {\max\left(wp2(k)+wp2(k+1),2\epsilon\right)}
                  -\frac{wp3(k)}
                        {\max\left(wp2(k-1)+wp2(k),2\epsilon\right)}
                 \right)
  } \\
& \mathtt{
   lhs(1,k) = lhs(1,k) + a1m(k)\frac{\beta}{3 dzm(k)}
                 \frac{wp3(k+1)}
                      {\max\left(wp2(k)+wp2(k+1),2\epsilon\right)}
  }
\end{split}
\end{equation}

\subsubsection{Term 4:  dp2}

\begin{equation}
\begin{split}
& - \ptlder{}{z} \left[ \left( K_{w2} + \nu_2 \right)
                        \ptlder{}{z} \overline{r_t'\theta_l'}
                 \right]  \\
 &= \mathtt{
    -\frac{1}{dzm(k)}
     \bigg( \frac{ \left( Kw2(k+1) + \nu_2 \right)
                   \left( rtpthlp(k+1) - rtpthlp(k) \right)} {dzt(k+1)}  }  \\
 &  \mathtt{ \qquad \qquad \qquad \quad
           -\frac{ \left( Kw2(k) + \nu_2 \right)
                   \left( rtpthlp(k) - rtpthlp(k-1) \right)} {dzt(k)}
     \bigg)
    }
\end{split}
\end{equation}
%
Separating out the contributions:
%
\begin{equation}
\begin{split}
&\mathtt{lhs(3,k) = lhs(3,k) - \frac{Kw2(k)+\nu_2}{dzm(k)dzt(k)} } \\
&\mathtt{lhs(2,k) = lhs(2,k) + \frac{1}{dzm(k)}
                               \left(   \frac{Kw2(k+1)+\nu_2}{dzt(k+1)}
                                      + \frac{Kw2(k)+\nu_2}{dzt(k)} \right) } \\
&\mathtt{lhs(1,k) = lhs(1,k) - \frac{Kw2(k+1)+\nu_2}{dzm(k)dzt(k+1)} }
\end{split}
\end{equation}

\subsubsection{Term 5:  ta, explicit component}

\begin{equation}
\begin{split}
& - \left. \left( 1 - \frac{1}{3}\beta \right)
       \ptlder{}{z}
         \left(
           a_2
           \frac{\overline{w^{'3}}}{\overline{w^{'2}}^2} \,
           \overline{w'r_t'} \; \overline{w'\theta_l'}
         \right) \right|_{\mathtt{zm(k)}} \\
=& \mathtt{
   - \frac{1 - \frac{1}{3}\beta}{4 dzm(k)} } \\
 & \mathtt{
     \times \bigg[ \frac{\left(a1m(k)+a1m(k+1)\right)^2 wp3(k+1)
                  \left(wprtp(k)+wprtp(k+1)\right)\left(wpthlp(k)+wpthlp(k+1)\right)}
                 {\max\left(wp2(k)+wp2(k+1),2\epsilon\right)^2} } \\
 & \mathtt{ \quad \quad
           -\frac{\left(a1m(k-1)+a1m(k)\right)^2 wp3(k)
                  \left(wprtp(k-1)+wprtp(k)\right)\left(wpthlp(k-1)+wpthlp(k)\right)}
                 {\max\left(wp2(k-1)+wp2(k),2\epsilon\right)^2}
     \bigg]
   }
\end{split}
\end{equation}
%
Separating out the contributions:
%
\begin{equation}
\begin{split}
\mathtt{rhs(k)} =& \mathtt{rhs(k)} \\
 & \mathtt{ - \frac{1 - \frac{1}{3}\beta}{4 dzm(k)} } \\
 & \mathtt{ \times
      \bigg[ \frac{\left(a1m(k)+a1m(k+1)\right)^2 wp3(k+1)
                   \left(wprtp(k)+wprtp(k+1)\right)
                   \left(wpthlp(k)+wpthlp(k+1)\right)}
                  {\max\left(wp2(k)+wp2(k+1),2\epsilon\right)^2} } \\
 & \mathtt{ \quad \quad
            -\frac{\left(a1m(k-1)+a1m(k)\right)^2 wp3(k)
                   \left(wprtp(k-1)+wprtp(k)\right)
                   \left(wpthlp(k-1)+wpthlp(k)\right)}
                  {\max\left(wp2(k-1)+wp2(k),2\epsilon\right)^2}
      \bigg]
   }
\end{split}
\end{equation}
%
In order to increase numerical stability in the model, $a_{1}$ has been brought
outside of the derivative.  This is not mathematically correct, but it does
help to increase stability.  Brian Griffin.  Feb. 21, 2008.
%
\begin{equation}
\begin{split}
& - \left. a_2 \left( 1 - \frac{1}{3}\beta \right)
       \ptlder{}{z}
         \left(
           \frac{\overline{w^{'3}}}{\overline{w^{'2}}^2} \,
           \overline{w'r_t'} \; \overline{w'\theta_l'}
         \right) \right|_{\mathtt{zm(k)}} \\
=& \mathtt{
   - a1m(k)^{2}\frac{1 - \frac{1}{3}\beta}{dzm(k)} } \\
 & \mathtt{
     \times \bigg[ \frac{wp3(k+1)
                         \left(wprtp(k)+wprtp(k+1)\right)
                         \left(wpthlp(k)+wpthlp(k+1)\right)}
                        {\max\left(wp2(k)+wp2(k+1),2\epsilon\right)^2} } \\
 & \mathtt{ \quad \quad
                  -\frac{wp3(k)
                         \left(wprtp(k-1)+wprtp(k)\right)
                         \left(wpthlp(k-1)+wpthlp(k)\right)}
                        {\max\left(wp2(k-1)+wp2(k),2\epsilon\right)^2}
            \bigg]
   }
\end{split}
\end{equation}
%
Separating out the contributions:
%
\begin{equation}
\begin{split}
\mathtt{rhs(k)} =& \mathtt{rhs(k)} \\
 & \mathtt{ - a1m(k)^{2}\frac{1 - \frac{1}{3}\beta}{dzm(k)} } \\
 & \mathtt{ \times
      \bigg[ \frac{wp3(k+1)
                   \left(wprtp(k)+wprtp(k+1)\right)
                   \left(wpthlp(k)+wpthlp(k+1)\right)}
                  {\max\left(wp2(k)+wp2(k+1),2\epsilon\right)^2} } \\
 & \mathtt{ \quad \quad
            -\frac{wp3(k)
                   \left(wprtp(k-1)+wprtp(k)\right)
                   \left(wpthlp(k-1)+wpthlp(k)\right)}
                  {\max\left(wp2(k-1)+wp2(k),2\epsilon\right)^2}
      \bigg]
   }
\end{split}
\end{equation}

\subsubsection{Terms 6 and 7:  tp1 and tp2, respectively}

\begin{equation}
\begin{split}
&\left. -\,\overline{w'q'_t} \, \ptlder{\bar{\theta}_l}{z} \right|_{\mathtt{zm(k)}}
 \left. -\,\overline{w'\theta'_l} \, \ptlder{\bar{q}_t}{z} \right|_{\mathtt{zm(k)}} \\
&= \mathtt{ - wprtp(k) \frac{thlm(k+1)-thlm(k)}{dzm(k)} }
   \mathtt{ - wpthlp(k) \frac{rtm(k+1)-rtm(k)}{dzm(k)} }
\end{split}
\end{equation}
%
Separating out the contributions:
%
\begin{equation}
\begin{split}
&\mathtt{rhs(k) = rhs(k) - wprtp(k) \frac{thlm(k+1)-thlm(k)}{dzm(k)}
                     - wpthlp(k) \frac{rtm(k+1)-rtm(k)}{dzm(k)} }
\end{split}
\end{equation}

\section{Implicit solutions for the means and fluxes}

$\bar{r}_t$ and $\overline{w'r_t'}$ can be solved simultaneously and
implicitly.
Start with eqs (\ref{eq_rtm}), (\ref{eq_wprtp}) (for simplicity, neglect the
$\left.\right|_{\rm{sicl}}$ and $\left.\right|_{\rm{cl}}$ terms), and substitute
expression for the transport term (\ref{eq_wp2rtp}):
%
\begin{equation}
\ptlder{\bar{r}_t}{t}
= - \bar{w}\ptlder{\bar{r}_t}{z}
  - \ptlder{}{z}\overline{w'r'_t}
  + \left. \ptlder{\bar{r}_t}{t} \right|_{\rm ls}
\end{equation}
%
\begin{equation}
\begin{split}
\ptlder{\overline{w'r'_t}}{t}
= & - \bar{w}\ptlder{\overline{w'r'_t}}{z}
    - \ptlder{}{z}
      \left(
               a_1 \,
               \frac{\overline{w^{'3}}}{\overline{w^{'2}}} \,
               \overline{w'r_t'}
      \right)
    - \overline{w^{'2}}\ptlder{\bar{r}_t}{z}
    - (1-C_7) \overline{w'r'_t}\ptlder{\bar{w}}{z}
    + (1-C_7) \frac{g}{\theta_0} \overline{r'_t\theta'_v} \\
  & - \frac{C_6}{\tau}\overline{w'r'_t}
    + \ptlder{}{z} \left[ \left( K_{w6} + \nu_6 \right)
                          \ptlder{}{z} \overline{w'r'_t}
                   \right]
\end{split}
\end{equation}
%
After discretizing the time derivative and rearranging terms:
%
\begin{equation}
\label{eq_rxm2}
\begin{split}
& \frac{\bar{r}_t^{\, t+\Delta t}}{\Delta t}
  + \bar{w}\ptlder{\bar{r}_t^{\, t+\Delta t}}{z}
  + \ptlder{}{z}\overline{w'r'_t}^{\, t+\Delta t} \\
& = \frac{\bar{r}_t^{\, t}}{\Delta t}
  + \left. \ptlder{\bar{r}_t}{t} \right|_{\rm ls}
\end{split}
\end{equation}
%
\begin{equation}
\label{eq_wprxp2}
\begin{split}
& \frac{\overline{w'r'_t}^{\, t+\Delta t}}{\Delta t}
  + \bar{w}\ptlder{}{z}\overline{w'r'_t}^{\, t+\Delta t}
  + \ptlder{}{z}
    \left(
             a_1 \,
             \frac{\overline{w^{'3}}}{\overline{w^{'2}}} \,
             \overline{w'r_t'}^{\, t+\Delta t}
    \right)
  + \overline{w^{'2}}\ptlder{\bar{r}_t^{\, t+\Delta t}}{z} \\
& + (1-C_7) \overline{w'r'_t}^{\, t+\Delta t}\ptlder{\bar{w}}{z}
  + \frac{C_6}{\tau}\overline{w'r'_t}^{\, t+\Delta t}
  - \ptlder{}{z} \left[ \left( K_{w6} + \nu_6 \right)
                        \ptlder{}{z} \overline{w'r'_t}^{\, t+\Delta t}
                 \right]  \\
& = \frac{\overline{w'r'_t}^{\, t}}{\Delta t}
    + (1-C_7) \frac{g}{\theta_0} \overline{r'_t\theta'_v}^{\, t}
\end{split}
\end{equation}
%
The LHSs of (\ref{eq_rxm2})-(\ref{eq_wprxp2}) are linear in $\bar{r}_t$
and $\overline{w'r'_t}$ and can therefore be rewritten in matrix form:
%
\begin{equation}
\underbrace{
\left( \begin{smallmatrix}
  \cdots
  & \bar{r_t}^{\, \mathrm{impl.}}_{\, k}
  & \overline{w'r'_t}^{\, \mathrm{impl.}}_{\, k}
  & \bar{r_t}^{\, \mathrm{impl.}}_{\, k+1}
  & \overline{w'r'_t}^{\, \mathrm{impl.}}_{\, k+1}
  & \bar{r_t}^{\, \mathrm{impl.}}_{\, k+2}
  & \overline{w'r'_t}^{\, \mathrm{impl.}}_{\, k+2}
  & \cdots \\
  \cdots
  & \overline{w'r'_t}^{\, \mathrm{impl.}}_{\, k-1}
  & \bar{r_t}^{\, \mathrm{impl.}}_{\, k}
  & \overline{w'r'_t}^{\, \mathrm{impl.}}_{\, k}
  & \bar{r_t}^{\, \mathrm{impl.}}_{\, k+1}
  & \overline{w'r'_t}^{\, \mathrm{impl.}}_{\, k+1}
  & \bar{r_t}^{\, \mathrm{impl.}}_{\, k+2}
  & \cdots \\
  \cdots
  & \bar{r_t}^{\, \mathrm{impl.}}_{\, k-1}
  & \overline{w'r'_t}^{\, \mathrm{impl.}}_{\, k-1}
  & \bar{r_t}^{\, \mathrm{impl.}}_{\, k}
  & \overline{w'r'_t}^{\, \mathrm{impl.}}_{\, k}
  & \bar{r_t}^{\, \mathrm{impl.}}_{\, k+1}
  & \overline{w'r'_t}^{\, \mathrm{impl.}}_{\, k+1}
  & \cdots \\
  \cdots
  & \overline{w'r'_t}^{\, \mathrm{impl.}}_{\, k-2}
  & \bar{r_t}^{\, \mathrm{impl.}}_{\, k-1}
  & \overline{w'r'_t}^{\, \mathrm{impl.}}_{\, k-1}
  & \bar{r_t}^{\, \mathrm{impl.}}_{\, k}
  & \overline{w'r'_t}^{\, \mathrm{impl.}}_{\, k}
  & \bar{r_t}^{\, \mathrm{impl.}}_{\, k+1}
  & \cdots \\
  \cdots
  & \bar{r_t}^{\, \mathrm{impl.}}_{\, k-2}
  & \overline{w'r'_t}^{\, \mathrm{impl.}}_{\, k-2}
  & \bar{r_t}^{\, \mathrm{impl.}}_{\, k-1}
  & \overline{w'r'_t}^{\, \mathrm{impl.}}_{\, k-1}
  & \bar{r_t}^{\, \mathrm{impl.}}_{\, k}
  & \overline{w'r'_t}^{\, \mathrm{impl.}}_{\, k}
  & \cdots
\end{smallmatrix} \right) }_{\mathtt{LHS}\textrm{(Stored in compact format)}}
\left( \begin{array}{l}
  \hfill \vdots \hfill \\
  \bar{r_t}^{\, t+\Delta t}_{\, k-1} \\
  \overline{w'r'_t}^{\, t+\Delta t}_{\, k-1} \\
  \bar{r_t}^{\, t+\Delta t}_{\, k} \\
  \overline{w'r'_t}^{\, t+\Delta t}_{\, k} \\
  \bar{r_t}^{\, t+\Delta t}_{\, k+1} \\
  \overline{w'r'_t}^{\, t+\Delta t}_{\, k+1} \\
  \hfill \vdots \hfill
\end{array} \right)
=
\underbrace{
\left( \begin{smallmatrix}
  \hfill \vdots \hfill \\
  \bar{r_t}^{\, \mathrm{expl.}}_{\, k-1} \\
  \overline{w'r'_t}^{\,\mathrm{expl.}}_{\, k-1} \\
  \bar{r_t}^{\, \mathrm{expl.}}_{\, k} \\
  \overline{w'r'_t}^{\,\mathrm{expl.}}_{\, k} \\
  \bar{r_t}^{\, \mathrm{expl.}}_{\, k+1} \\
  \overline{w'r'_t}^{\,\mathrm{expl.}}_{\, k+1} \\
  \hfill \vdots \hfill
\end{smallmatrix} \right) }_{\mathtt{RHS}}
\end{equation}
%
The matrix $lhs$ is obtained by vertical discretization of the LHSs,
and the vector $rhs$ by discretization of the RHSs. $lhs$ is band-diagonal
with two rows above and two below the main diagonal. $lhs$ is stored
in compact form in an array with dimensions $\mathtt{(5, 2\,nzmax)}$.
$rhs$ is a vector with dimension $\mathtt{(2\,nzmax)}$.
$lhs$ can be inverted efficiently using an LU decomposition algorithm for
band diagonal matrices.
The construction of the matrix $lhs$ and vector $rhs$ are as follows.

First, we compute
the finite difference equivalent to (\ref{eq_rxm2}):
%
\begin{equation}
\label{eq_rxm3}
\begin{split}
& \mathtt{
   \frac{rtm^{new}(k)}{dt}
   + \frac{wmt(k)}{2dzt(k)} rtm^{new}(k+1)
   - \frac{wmt(k)}{2dzt(k)} rtm^{new}(k-1)
   + \frac{wprtp^{new}(k)}{dzt(k)}
   - \frac{wprtp^{new}(k-1)}{dzt(k)} } \\
=& \mathtt{
   \frac{rtm(k)}{dt} + rtm\_ls(k)
  }
\end{split}
\end{equation}
%
Contributions to $lhs$ from (\ref{eq_rxm3}) are:
%
\begin{equation}
\begin{split}
& \mathtt{
  lhs(5,k\_xm) = lhs(5,k\_xm) - \frac{wmt(k)}{2dzt(k)}
  }
\end{split}
\end{equation}
%
\begin{equation}
\begin{split}
& \mathtt{
  lhs(4,k\_xm) = lhs(4,k\_xm) - \frac{1}{dzt(k)}
  }
\end{split}
\end{equation}
%
\begin{equation}
\begin{split}
& \mathtt{
  lhs(3,k\_xm) = lhs(3,k\_xm) + \frac{1}{dt}
  }
\end{split}
\end{equation}
%
\begin{equation}
\begin{split}
& \mathtt{
  lhs(2,k\_xm) = lhs(2,k\_xm) + \frac{1}{dzt(k)}
  }
\end{split}
\end{equation}
%
\begin{equation}
\begin{split}
& \mathtt{
  lhs(1,k\_xm) = lhs(1,k\_xm) + \frac{wmt(k)}{2dzt(k)}
  }
\end{split}
\end{equation}
%
Contributions to $rhs$ from (\ref{eq_rxm3}) are:
%
\begin{equation}
\begin{split}
& \mathtt{
  rhs(k\_xm) = rhs(k\_xm) + \frac{rtm(k)}{dt} + rtm\_ls(k)
  }
\end{split}
\end{equation}
%
where $\mathtt{k\_xm = 2 k - 1}$.

We now write
the finite difference equivalent to (\ref{eq_wprxp2}):
%
\begin{equation}
\label{eq_wprxp3}
\begin{split}
& \mathtt{
  \frac{wprtp^{new}(k)}{dt}
  + \frac{wmm(k)}{2 dzm(k)} wprtp^{new}(k+1)
  - \frac{wmm(k)}{2 dzm(k)} wprtp^{new}(k-1)
  } \\
& \mathtt{
  + \frac{1}{2 dzm(k)}
    \bigg[ -\frac{\left(a1m(k-1)+a1m(k)\right) wp3(k)}
                 {\max\left(wp2(k-1)+wp2(k),2\epsilon\right)}
            wprtp^{new}(k-1)
  } \\
& \mathtt{ \quad \quad \quad \quad \quad
          + \left(
             \frac{\left(a1m(k)+a1m(k+1)\right) wp3(k+1)}
                 {\max\left(wp2(k)+wp2(k+1),2\epsilon\right)}
            -\frac{\left(a1m(k-1)+a1m(k)\right) wp3(k)}
                 {\max\left(wp2(k-1)+wp2(k),2\epsilon\right)}
            \right)
            wprtp^{new}(k)
  } \\
& \mathtt{ \quad \quad \quad \quad \quad
           + \frac{\left(a1m(k)+a1m(k+1)\right) wp3(k+1)}
                 {\max\left(wp2(k)+wp2(k+1),2\epsilon\right)}
            wprtp^{new}(k+1)
    \bigg]
  } \\
& \mathtt{
  + wp2(k) \, \frac{rtm^{new}(k+1)-rtm^{new}(k)}{dzm(k)}
  + (1-C_7) \, wprtp^{new}(k) \, \frac{wmt(k+1)-wmt(k)}{dzm(k)}
  } \\
& \mathtt{
  + \frac{C_6}{taum(k)} \, wprtp^{new}(k)
  } \\
& \mathtt{
  - \frac{Kw6(k)+\nu_6}{dzm(k)dzt(k)} wprtp^{new}(k-1)
  } \\
& \mathtt{
  + \frac{1}{dzm(k)} \left(   \frac{Kw6(k+1)+\nu_6}{dzt(k+1)}
                            + \frac{Kw6(k)+\nu_6}{dzt(k)} \right) wprtp^{new}(k)
  } \\
& \mathtt{
  - \frac{Kw6(k+1)+\nu_6}{dzm(k)dzt(k+1)} wprtp^{new}(k+1)
  } \\
=& \mathtt{ \frac{wprtp(k)}{dt} + (1-C_7) \frac{g}{\theta_0} rtpthvp(k) }
\end{split}
\end{equation}
%
Contributions to $lhs$ from (\ref{eq_wprxp3}) are:
%
\begin{equation}
\begin{split}
&  \mathtt{ lhs(5,k\_wpxp) = lhs(5,k\_wpxp) } \\
&  \mathtt{
- \frac{wmm(k)}{2 dzm(k)}
- \frac{1}{2 dzm(k)}
  \frac{\left(a1m(k-1)+a1m(k)\right) wp3(k)}
       {\max\left(wp2(k-1)+wp2(k),2\epsilon\right)}
- \frac{Kw6(k)+\nu_6}{dzm(k)dzt(k)}
  }
\end{split}
\end{equation}
%
\begin{equation}
\begin{split}
&  \mathtt{ lhs(4,k\_wpxp) = lhs(4,k\_wpxp) -\frac{wp2(k)}{dzm(k)} }
\end{split}
\end{equation}
%
\begin{equation}
\begin{split}
&  \mathtt{ lhs(3,k\_wpxp) = lhs(3,k\_wpxp) } \\
&  \mathtt{
+ \frac{1}{dt}
+ \frac{1}{2 dzm(k)}
  \left(
   \frac{\left(a1m(k)+a1m(k+1)\right) wp3(k+1)}
       {\max\left(wp2(k)+wp2(k+1),2\epsilon\right)}
  -\frac{\left(a1m(k-1)+a1m(k)\right) wp3(k)}
       {\max\left(wp2(k-1)+wp2(k),2\epsilon\right)}
  \right)
   } \\
&  \mathtt{
+ (1-C_7) \, \frac{wmt(k+1)-wmt(k)}{dzm(k)}
+ \frac{C_6}{taum(k)}
+ \frac{1}{dzm(k)} \left(   \frac{Kw6(k+1)+\nu_6}{dzt(k+1)}
                          + \frac{Kw6(k)+\nu_6}{dzt(k)} \right)
   }
\end{split}
\end{equation}
%
\begin{equation}
\begin{split}
&  \mathtt{ lhs(2,k\_wpxp) = lhs(2,k\_wpxp) +\frac{wp2(k)}{dzm(k)} }
\end{split}
\end{equation}
%
\begin{equation}
\begin{split}
&  \mathtt{ lhs(1,k\_wpxp) = lhs(1,k\_wpxp) } \\
&  \mathtt{
+ \frac{wmm(k)}{2 dzm(k)}
+ \frac{1}{2 dzm(k)}
  \frac{\left(a1m(k)+a1m(k+1)\right) wp3(k+1)}
       {\max\left(wp2(k)+wp2(k+1),2\epsilon\right)}
- \frac{Kw6(k+1)+\nu_6}{dzm(k)dzt(k+1)}
  }
\end{split}
\end{equation}

Contributions to $rhs$ from (\ref{eq_wprxp3}) are:
%
\begin{equation}
\begin{split}
& \mathtt{
  rhs(k\_wpxp)
= rhs(k\_wpxp)
+ \frac{wprtp(k)}{dt}
+ (1-C_7) \frac{g}{\theta_0} rtpthvp(k) }
\end{split}
\end{equation}
%
where $\mathtt{k\_wpxp = 2 k}$.

The procedure for solving implicitly for $\bar{\theta}_l$
and $\overline{w'\theta_l'}$ is identical. It leads to the same matrix
$lhs$, so $lhs$ needs to be inverted only once.

\section{Implicit solution for the vertical velocity moments}

Start with equations (\ref{eq_wp2}) and (\ref{eq_wp3}) (for simplicity, neglect
the $\left.\right|_{\rm{pd}}$ and $\left.\right|_{\rm{cl}}$ terms):
%
\begin{equation}
\label{eq_wp2b}
\begin{split}
\ptlder{\overline{w^{'2}}}{t}
=& - \bar{w}\ptlder{\overline{w^{'2}}}{z}
   - \ptlder{\overline{w^{'3}}}{z}
   - 2\overline{w^{'2}}\ptlder{\bar{w}}{z}
   + \frac{2g}{\theta_0} \overline{w'\theta'_v} \\
 & - \frac{C_4}{\tau} \left( \overline{w^{'2}} -\frac{2}{3}\bar{e} \right)
   - C_5
     \left(
       - 2\overline{w^{'2}}\ptlder{\bar{w}}{z}
       + \frac{2g}{\theta_0} \overline{w'\theta'_v}
     \right)
   + \frac{2}{3} C_5
     \left(
       \frac{g}{\theta_0} \overline{w'\theta'_v}
       - \overline{u'w'}\ptlder{\bar{u}}{z}
       - \overline{v'w'}\ptlder{\bar{v}}{z}
     \right) \\
 & - \dfrac{C_1}{\tau} \left(   \overline{w^{'2}}
                              - \left. w \right|_{\rm{tol}}^{2} \right)
   + \ptlder{}{z} \left[ \left( K_{w1} + \nu_1 \right)
                         \ptlder{}{z} \overline{w^{'2}}
                  \right]
\end{split}
\end{equation}
%
\begin{equation}
\label{eq_wp3b}
\begin{split}
\ptlder{\overline{w^{'3}}}{t}
= & - \bar{w}\ptlder{\overline{w^{'3}}}{z}
    - \ptlder{\overline{w^{'4}}}{z}
    + 3\overline{w^{'2}}\ptlder{\overline{w^{'2}}}{z}
    - 3\overline{w^{'3}}\ptlder{\bar{w}}{z}
    + \frac{3g}{\theta_0} \overline{w^{'2}\theta'_v} \\
  & - \frac{C_8}{\tau}\left( C_{8b} \, Skw^4 + 1 \right) \overline{w^{'3}}
    - C_{11} \left(
                - 3 \overline{w^{'3}}\ptlder{\bar{w}}{z}
                + \frac{3g}{\theta_0} \overline{w^{'2}\theta'_v}
             \right)
    + \ptlder{}{z} \left[ \left( K_{w8} + \nu_8 \right)
                          \ptlder{}{z} \overline{w^{'3}}
                   \right]
\end{split}
\end{equation}
%
Using (\ref{eq_wp4}), we can rewrite the transport and production terms
in (\ref{eq_wp3b}):
%
\begin{equation}
\begin{split}
& - \ptlder{\overline{w^{'4}}}{z}
  + 3\overline{w^{'2}}\ptlder{\overline{w^{'2}}}{z} \\
& = - \ptlder{}{z}
         \left( \overline{w^{'4}} -\frac{3}{2}\overline{w^{'2}}^2 \right) \\
& = - \ptlder{}{z}
      \left( \tilde{a}_3 \overline{w^{'2}}^2 \right)
    - \ptlder{}{z}
      \left( a_1 \frac{ \overline{w^{'3}}^2 }{ \overline{w^{'2}} } \right)
\end{split}
\end{equation}
%
where $\tilde{a}_3 = a_3 +3/2$.  Rearranging terms and making use of (\ref{eq_tke}):
%
\begin{equation}
\label{eq_wp2c}
\begin{split}
& \ptlder{\overline{w^{'2}}}{t}
  + \bar{w}\ptlder{\overline{w^{'2}}}{z}
  + \ptlder{\overline{w^{'3}}}{z}
  + \dfrac{C_1}{\tau} \overline{w^{'2}}
  - \ptlder{}{z} \left[ \left( K_{w1} + \nu_1 \right)
                        \ptlder{}{z} \overline{w^{'2}}
                 \right]  \\
& =
  + ( 1 - C_5 ) \frac{2g}{\theta_0} \overline{w'\theta'_v}
  - 2 ( 1 - C_5 ) \overline{w^{'2}}\ptlder{\bar{w}}{z}
  + \dfrac{C_1}{\tau} \left. w \right|_{\rm{tol}}^{2}
  + \frac{2}{3} C_5
     \left(
       \frac{g}{\theta_0} \overline{w'\theta'_v}
       - \overline{u'w'}\ptlder{\bar{u}}{z}
       - \overline{v'w'}\ptlder{\bar{v}}{z}
     \right) \\
\end{split}
\end{equation}
%
\begin{equation}
\label{eq_wp3c}
\begin{split}
& \ptlder{\overline{w^{'3}}}{t}
   + \bar{w}\ptlder{\overline{w^{'3}}}{z}
   - \ptlder{}{z} \left[ \left( K_{w8} + \nu_8 \right)
                         \ptlder{}{z} \overline{w^{'3}}
                  \right]
  + \frac{C_8}{\tau}\left( C_{8b} \, Skw^4 + 1 \right) \overline{w^{'3}} \\
& \qquad
  + \ptlder{}{z} \left( \tilde{a}_3 \overline{w^{'2}}^2 \right)
  + \ptlder{}{z}
       \left(
          a_1 \frac{ \overline{w^{'3}}^2 }{ \overline{w^{'2}} }
       \right) \\
& =
  + (1 - C_{11}) \frac{3g}{\theta_0} \overline{w^{'2}\theta'_v}
  - 3 ( 1 - C_{11} ) \overline{w^{'3}}\ptlder{\bar{w}}{z} \\
\end{split}
\end{equation}
%

\subsection{$\overline{w^{'2}}$}

Terms on the LHS of (\ref{eq_wp2c}) are treated fully implicitly, except
for the diffusion term which is treated with a Crank-Nicholson time step.
Terms on the RHS explicitly:
%
\begin{equation}
\label{eq_wp2d}
\begin{split}
& \frac{\overline{w^{'2}}^{t+\Delta t}}{\Delta t}
  + \bar{w}\ptlder{\overline{w^{'2}}^{t+\Delta t}}{z}
  + \ptlder{\overline{w^{'3}}^{t+\Delta t}}{z}
  + \dfrac{C_1}{\tau} \overline{w^{'2}}^{t+\Delta t}
  - \frac{1}{2} \ptlder{}{z} \left[ \left( K_{w1} + \nu_1 \right)
                                    \ptlder{}{z} \overline{w^{'2}}^{t+\Delta t}
                             \right]  \\
&=
  \frac{\overline{w^{'2}}^{t}}{\Delta t}
  + \frac{1}{2} \ptlder{}{z} \left[ \left( K_{w1} + \nu_1 \right)
                                    \ptlder{}{z} \overline{w^{'2}}^{t}
                             \right]
  + \left. \overline{w^{'2}} \right|_{\rm expl}
\end{split}
\end{equation}
%
where
%
\begin{equation}
\label{eq_wp2t}
\begin{split}
\left. \overline{w^{'2}} \right|_{\rm expl}
=&
   + ( 1 - C_5 ) \frac{2g}{\theta_0} \overline{w'\theta'_v}^{t}
   - 2 ( 1 - C_5 ) \overline{w^{'2}}^{t}\ptlder{\bar{w}}{z}
   + \dfrac{C_1}{\tau} \left. w \right|_{\rm{tol}}^{2} \\
 & + \frac{2}{3} C_5
      \left(
        \frac{g}{\theta_0} \overline{w'\theta'_v}
        - \overline{u'w'}\ptlder{\bar{u}}{z}
        - \overline{v'w'}\ptlder{\bar{v}}{z}
      \right)^{t}
\end{split}
\end{equation}
%
The next step consists of writing the finite difference equivalent to
(\ref{eq_wp2d}):
%
\begin{equation}
\label{eq_wp2e}
\begin{split}
& \mathtt{
  \frac{wp2^{new}(k)}{dt}
+ wmm(k) \frac{wp2^{new}(k+1) - wp2^{new}(k-1)}{2 \ dzm(k)}
  } \\
& \mathtt{
+ \frac{wp3^{new}(k+1) - wp3^{new}(k)}{dzm(k)}
+ \frac{C_1}{taum(k)} wp2^{new}(k)
  } \\
& \mathtt{
  -\frac{Kw1(k)+\nu_1}{2 dzm(k)dzt(k)} wp2^{new}(k-1)
  } \\
& \mathtt{
  +\frac{1}{2 dzm(k)} \left(  \frac{Kw1(k+1)+\nu_1}{dzt(k+1)}
                            + \frac{Kw1(k)+\nu_1}{dzt(k)} \right) wp2^{new}(k)
  } \\
& \mathtt{
  -\frac{Kw1(k+1)+\nu_1}{2 dzm(k)dzt(k+1)} wp2^{new}(k+1)
  } \\
=& \mathtt{
  \frac{wp2(k)}{dt}
  } \\
& \mathtt{
  +\frac{Kw1(k)+\nu_1}{2 dzm(k)dzt(k)} wp2(k-1)
  } \\
& \mathtt{
  -\frac{1}{2 dzm(k)} \left(  \frac{Kw1(k+1)+\nu_1}{dzt(k+1)}
                            + \frac{Kw1(k)+\nu_1}{dzt(k)} \right) wp2(k)
  } \\
& \mathtt{
  +\frac{Kw1(k+1)+\nu_1}{2 dzm(k)dzt(k+1)} wp2(k+1)
  } \\
& \mathtt{
  + wp2t(k)
  }
\end{split}
\end{equation}
%
where $\mathtt{wp2t(k)}$ is the finite difference equivalent to (\ref{eq_wp2t})
at level $\mathtt{zm(k)}$.

\subsubsection{Using an anisotropic solution for the horizontal wind}

As an alternative to assuming $\bar{e} = \frac{3}{2} \overline{w^{'2}}$, we
can calculate $\overline{v^{'2}}$ and $\overline{u^{'2}}$ and then
compute $\bar{e}$ accordingly.  The term with a $C_4$ coefficient in
$\overline{w^{'2}}$ equation is then non-zero and must be accounted for.
Starting with
the $5^{\mathrm{th}}$ term of the original $\overline{w^{'2}}$ equation:

\begin{equation}
\begin{split}
\ptlder{\overline{w^{'2}}}{t} =
  \, \cdots \,
  - \frac{C_4}{\tau} \left( \overline{w^{'2}} - \frac{2}{3} \bar{e} \right)
  \, \cdots
\end{split}
\end{equation}
%

From which we obtain the finite difference equivalent:
%
\begin{equation}
\begin{split}
& \left.
  - \frac{C_4}{\tau}
    \left( \overline{w^{'2}} - \frac{2}{3} \bar{e}
    \right)
  \right|_{\mathtt{zm(k)}} \\
&= \mathtt{ -\frac{C_4}{taum(k)}
    \left(
      wp2(k) - \frac{2}{3} em(k)
    \right)
   } \\
&= \mathtt{ -\frac{C_4}{taum(k)}
             \left(
               wp2(k) - \frac{wp2(k) + up2(k) + vp2(k)}{3}
             \right)
          } \\
&= \mathtt{ -\frac{2 \, C_4 \, wp2(k)}{3 taum(k)} + \frac{C_4 \left( up2(k) + vp2(k) \right)}{3 taum(k)} }
\end{split}
\end{equation}
%

Separating out the contributions:
%
\begin{equation}
\begin{split}
& \mathtt{
  lhs(3,k\_wp2) = lhs(3,k\_wp2) + \frac{C_4 \left( up2(k) + vp2(k) \right)}{3 taum(k) }
  } \\
& \mathtt{
  rhs(k\_wp2) = rhs(k\_wp2) + \frac{2 \, C_4 \, wp2(k) }{3 taum(k)}
  }
\end{split}
\end{equation}

\subsection{$\overline{w^{'3}}$}

The first two terms on the LHS of (\ref{eq_wp3c}) (i.e. mean advection dissipation )
are treated implicitly, and
the last three terms on the LHS are teated semi-implicitly (they are linearized
and the linearized portion is treated implicitly, the rest explicitly).
The terms on the RHS are treated fully explicit discretization. Let's focus first on the third term on the LHS,
$L_3$:
%
\begin{equation}
\label{eq_l3a}
L_3
\equiv \frac{C_8}{\tau}\left( C_{8b} \, Skw^4 + 1 \right) \overline{w^{'3}}
=   \frac{C_8}{\tau}
    \left(  C_{8b} \, \frac{\overline{w^{'3}}^5}{\overline{w^{'2}}^6}
          + \overline{w^{'3}}
    \right)
\end{equation}
%
We linearize $L_3$ with respect to $\overline{w^{'3}}$:
%
\begin{equation}
\label{eq_l3b}
L_3 \left( \overline{w^{'3}}^{t+\Delta t} \right)
\approx L_3 \left( \overline{w^{'3}}^{t} \right)
+ \left. \ptlder{L_3}{\overline{w^{'3}}} \right|_{t}
  \left( \overline{w^{'3}}^{t+\Delta t} - \overline{w^{'3}}^{t} \right)
\end{equation}
%
where
%
\begin{equation}
\label{eq_l3c}
\left. \ptlder{L_3}{\overline{w^{'3}}} \right|_{t}
=   \frac{C_8}{\tau}
    \left(  5 \, C_{8b} \, \frac{\overline{w^{'3}}^4}{\overline{w^{'2}}^6}
          + 1
    \right)
\end{equation}
%
Combining (\ref{eq_l3a}), (\ref{eq_l3c}) with (\ref{eq_l3b}):
%
\begin{equation}
\label{eq_l3d}
\begin{split}
& L_3 \left( \overline{w^{'3}}^{t+\Delta t} \right) \\
&=   \frac{C_8}{\tau}
      \left(  C_{8b} \, \frac{{\overline{w^{'3}}^t}^5}{{\overline{w^{'2}}^t}^6}
            + \overline{w^{'3}}^t
      \right)
   + \frac{C_8}{\tau}
     \left(  5 \, C_{8b} \, \frac{{\overline{w^{'3}}^t}^4}{{\overline{w^{'2}}^t}^6}
           + 1
     \right)
     \left( \overline{w^{'3}}^{t + \Delta t} - \overline{w^{'3}}^t \right)  \\
&= - \frac{C_8}{\tau}
      \left(  4 \, C_{8b} \, {Skw^t}^4 \right) \overline{w^{'3}}^t
   + \frac{C_8}{\tau}
     \left(  5 \, C_{8b} \, {Skw^t}^4 + 1 \right)
      \overline{w^{'3}}^{t + \Delta t}
\end{split}
\end{equation}
%
For reasons of numerical stability we now linearize the fourth term on the LHS
in a formulation that is fully implicit
(\ref{eq_wp3c}):
%
\begin{equation}
\label{eq_l4a}
\begin{split}
& \ptlder{}{z} \left[ \tilde{a}_3 \left(\overline{w^{'2}}^{t+\Delta t}\right)^2 \right] \\
&\approx  \ptlder{}{z}
    \left[
      \tilde{a}_3 {\overline{w^{'2}}^t}^2
      + 2 \tilde{a}_3 \overline{w^{'2}}^t
              \left( \overline{w^{'2}}^{t+\Delta t} - \overline{w^{'2}}^{t} \right)
    \right] \\
&= \ptlder{}{z} \left( 2 \tilde{a}_3 \overline{w^{'2}}^t \, \overline{w^{'2}}^{t+\Delta t} \right)
 - \ptlder{}{z} \left( \tilde{a}_3 {\overline{w^{'2}}^t}^2 \right)
\end{split}
\end{equation}
%
We repeat for the fifth term on the LHS of (\ref{eq_wp3c}):
%
\begin{equation}
\label{eq_l5a}
\begin{split}
& \ptlder{}{z}
     \left(
        a_1 \frac{ \left( {\overline{w^{'3}}^{t + \Delta t}}\right)^2 }
                 { \overline{w^{'2}}^t }
     \right) \\
&\approx
  \ptlder{}{z}
  \left[
    a_1 \frac{ \left( {\overline{w^{'3}}^t}\right)^2 }
             { \overline{w^{'2}}^t }
  + 2 a_1 \frac{ \overline{w^{'3}}^t }{ \overline{w^{'2}}^t }
          \left( \overline{w^{'3}}^{t+\Delta t} - \overline{w^{'3}}^{t} \right)
  \right] \\
&=
  \ptlder{}{z}
  \left(
    2 a_1 \frac{ \overline{w^{'3}}^t \, \overline{w^{'3}}^{t+\Delta t} }
               { \overline{w^{'2}}^t }
  \right)
- \ptlder{}{z}
  \left(
    a_1 \frac{ \left( {\overline{w^{'3}}^t}\right)^2 }
             { \overline{w^{'2}}^t }
  \right) \\
\end{split}
\end{equation}
%
We can now assemble the time discrete equivalent to (\ref{eq_wp3c}) using
(\ref{eq_l3d}), (\ref{eq_l4a}) and (\ref{eq_l5a}):
%
\begin{equation}
\label{eq_wp3d}
\begin{split}
& \frac{\overline{w^{'3}}^{t+\Delta t}}{\Delta t}
+ \bar{w}\ptlder{\overline{w^{'3}}^{t+\Delta t}}{z}
- \frac{1}{2}\ptlder{}{z} \left[ \left( K_{w8} + \nu_8 \right)
                                 \ptlder{}{z} \overline{w^{'3}}^{t+\Delta t}
                          \right]
+ \frac{C_8}{\tau}
   \left(  5 \, C_{8b} \, {Skw^t}^4 + 1 \right)
   \overline{w^{'3}}^{t + \Delta t}
\\ &
+ \ptlder{}{z} \left( \tilde{a}_3 \overline{w^{'2}}^t \, \overline{w^{'2}}^{t+\Delta t} \right)
+ \ptlder{}{z}
  \left(
    a_1 \frac{ \overline{w^{'3}}^t \, \overline{w^{'3}}^{t+\Delta t} }
             { \overline{w^{'2}}^t }
  \right)
\\
&=
  \frac{\overline{w^{'3}}^{t}}{\Delta t}
  + \frac{1}{2}\ptlder{}{z} \left[ \left( K_{w8} + \nu_8 \right)
                                   \ptlder{}{z} \overline{w^{'3}}^{t}
                            \right]
  +  \frac{C_8}{\tau}
      \left( 4 \, C_{8b} \, {Skw^t}^4 \right) \overline{w^{'3}}^t
  + \left. \overline{w^{'3}} \right|_{\rm expl}
\end{split}
\end{equation}
%
where
%
\begin{equation}
\label{eq_wp3t}
\left. \overline{w^{'3}} \right|_{\rm expl}
=
  + (1 - C_{11}) \frac{3g}{\theta_0} \overline{w^{'2}\theta'_v}^t
  - 3 ( 1 - C_{11} ) \overline{w^{'3}}^t\ptlder{\bar{w}}{z}
\end{equation}
%
Finally, we derive the finite difference form of (\ref{eq_wp3d}):
%
\begin{equation}
\label{eq_wp3e}
\begin{split}
& \mathtt{
  \frac{wp3^{new}(k)}{dt}
  + wmt(k) \frac{wp3^{new}(k+1)-wp3^{new}(k-1)}{2 \ dzt(k)}
  } \\
& \mathtt{
  - \frac{1}{2dzt(k)}
    \bigg(
            \left(Kw8(k)+\nu_8\right)
            \frac{wp3^{new}(k+1)-wp3^{new}(k)}{dzm(k)} }  \\
& \mathtt{ \qquad \qquad \qquad \qquad
          - \left(Kw8(k-1)+\nu_8\right)
            \frac{wp3^{new}(k)-wp3^{new}(k-1)}{dzm(k-1)}
    \bigg)
  } \\
& \mathtt{
+ \frac{C_8}{taut(k)}
   \left(  5 \, C_{8b} \, {Skwt(k)}^4 + 1 \right) wp3^{new}(k)
  } \\
& \mathtt{
  + \frac{1}{dzt(k)}
    \left(a3m(k) wp2(k) wp2^{new}(k) - a3m(k-1) wp2(k-1) wp2^{new}(k-1) \right)
  } \\
& \mathtt{
  + \frac{1}{2 \, dzt(k)}
    \bigg(
      \frac{ a1m(k)
             \left(wp3(k)+wp3(k+1)\right)
             \left(wp3^{new}(k)+wp3^{new}(k+1)\right) }
           { \max\left( wp2(k), \epsilon \right) }
  } \\
& \mathtt{ \quad \quad \quad \quad \quad \quad
     -\frac{ a1m(k-1)
             \left(wp3(k-1)+wp3(k)\right)
             \left(wp3^{new}(k-1)+wp3^{new}(k)\right) }
           { \max\left( wp2(k-1), \epsilon \right) }
    \bigg)
  } \\
=& \mathtt{
  \frac{wp3(k)}{dt}
  + \frac{1}{2dzt(k)}
    \bigg(
            \left(Kw8(k)+\nu_8\right)
            \frac{wp3(k+1)-wp3(k)}{dzm(k)} }  \\
& \mathtt{ \qquad \qquad \qquad \qquad \qquad
          - \left(Kw8(k-1)+\nu_8\right)
            \frac{wp3(k)-wp3(k-1)}{dzm(k-1)}
    \bigg)
  } \\
& \mathtt{
+ \frac{C_8}{taut(k)}
   \left( 4 \, C_{8b} \, {Skwt(k)}^4 \right) wp3(k) + wp3t(k) }
\end{split}
\end{equation}
%
where $\mathtt{wp3t(k)}$ is the finite difference equivalent to (\ref{eq_wp3t})
at level $\mathtt{zt(k)}$.
%

In order to increase numerical stability in the model, $a_{1}$ has been brought
outside of the derivative.  Besides $a_{1}$, $a_{3}$ has been previously brought
outside of the derivative for the same purpose.  This is not mathematically
correct, but it does help to increase stability.  Brian Griffin.  Feb. 21, 2008.
%
\begin{equation}
\begin{split}
& \mathtt{
  \frac{wp3^{new}(k)}{dt}
  + wmt(k) \frac{wp3^{new}(k+1)-wp3^{new}(k-1)}{2 \ dzt(k)}
  } \\
& \mathtt{
  - \frac{1}{2dzt(k)}
    \bigg(
            \left(Kw8(k)+\nu_8\right)
            \frac{wp3^{new}(k+1)-wp3^{new}(k)}{dzm(k)} }  \\
& \mathtt{ \qquad \qquad \qquad \qquad
          - \left(Kw8(k-1)+\nu_8\right)
            \frac{wp3^{new}(k)-wp3^{new}(k-1)}{dzm(k-1)}
    \bigg)
  } \\
& \mathtt{
+ \frac{C_8}{taut(k)}
   \left(  5 \, C_{8b} \, {Skwt(k)}^4 + 1 \right) wp3^{new}(k)
  } \\
& \mathtt{
  + \left(\frac{a3m(k)+a3m(k-1)}{2}\right) \frac{2}{dzt(k)}
    \left(wp2(k) wp2^{new}(k) - wp2(k-1) wp2^{new}(k-1) \right)
  } \\
& \mathtt{
  + \left(\frac{a1m(k)+a1m(k-1)}{2}\right) \frac{1}{2 \, dzt(k)}
    \bigg(
      \frac{ \left(wp3(k)+wp3(k+1)\right)
             \left(wp3^{new}(k)+wp3^{new}(k+1)\right) }
           { \max\left( wp2(k), \epsilon \right) }
  } \\
& \mathtt{ \qquad \qquad \qquad \qquad \qquad \qquad \qquad \qquad
     -\frac{ \left(wp3(k-1)+wp3(k)\right)
             \left(wp3^{new}(k-1)+wp3^{new}(k)\right) }
           { \max\left( wp2(k-1), \epsilon \right) }
    \bigg)
  } \\
=& \mathtt{
  \frac{wp3(k)}{dt}
  + \frac{1}{2dzt(k)}
    \bigg(
            \left(Kw8(k)+\nu_8\right)
            \frac{wp3(k+1)-wp3(k)}{dzm(k)} }  \\
& \mathtt{ \qquad \qquad \qquad \qquad \qquad
          - \left(Kw8(k-1)+\nu_8\right)
            \frac{wp3(k)-wp3(k-1)}{dzm(k-1)}
    \bigg)
  } \\
& \mathtt{
+ \frac{C_8}{taut(k)}
   \left( 4 \, C_{8b} \, {Skwt(k)}^4 \right) wp3(k)
  } \\
& \mathtt{
  + \left(\frac{a3m(k)+a3m(k-1)}{2}\right) \frac{wp2(k)^2 - wp2(k-1)^2 }
                                                {dzt(k)}
  } \\
& \mathtt{
  + \left(\frac{a1m(k)+a1m(k-1)}{2}\right) \frac{1}{4 \, dzt(k)}
    \bigg(
      \frac{ \left(wp3(k)+wp3(k+1)\right)^2 }
           { \max\left( wp2(k), \epsilon \right) }
     -\frac{ \left(wp3(k-1)+wp3(k)\right)^2 }
           { \max\left( wp2(k-1), \epsilon \right) }
    \bigg)
  } \\
& \mathtt{
+ wp3t(k)
  }
\end{split}
\end{equation}

\subsection{Matrix form}

The final step is to rewrite (\ref{eq_wp2e}) and (\ref{eq_wp3e}) in matrix
form:
%
\begin{equation}
\begin{split}
&
\underbrace{
\left( \begin{smallmatrix}
  \cdots  %1
  & \mathtt{wp3^{impl}(k)\phantom{+0} }
  & \mathtt{wp2^{impl}(k)\phantom{+0} }
  & \mathtt{wp3^{impl}(k+1) }
  & \mathtt{wp2^{impl}(k+1) }
  & \mathtt{wp3^{impl}(k+2) }
  & \mathtt{wp2^{impl}(k+2) }
  & \cdots \\
  \cdots  %2
  & \mathtt{wp2^{impl}(k-1) }
  & \mathtt{wp3^{impl}(k)\phantom{+0} }
  & \mathtt{wp2^{impl}(k)\phantom{+0} }
  & \mathtt{wp3^{impl}(k+1) }
  & \mathtt{wp2^{impl}(k+1) }
  & \mathtt{wp3^{impl}(k+2) }
  & \cdots \\
  \cdots %3
  & \mathtt{wp3^{impl}(k-1) }
  & \mathtt{wp2^{impl}(k-1) }
  & \mathtt{wp3^{impl}(k)\phantom{+0} }
  & \mathtt{wp2^{impl}(k)\phantom{+0} }
  & \mathtt{wp3^{impl}(k+1) }
  & \mathtt{wp2^{impl}(k+1) }
  & \cdots \\
  \cdots %4
  & \mathtt{wp2^{impl}(k-2) }
  & \mathtt{wp3^{impl}(k-1) }
  & \mathtt{wp2^{impl}(k-1) }
  & \mathtt{wp3^{impl}(k)\phantom{+0} }
  & \mathtt{wp2^{impl}(k)\phantom{+0} }
  & \mathtt{wp3^{impl}(k+1) }
  & \cdots \\
  \cdots %5
  & \mathtt{wp3^{impl}(k-2) }
  & \mathtt{wp2^{impl}(k-2) }
  & \mathtt{wp3^{impl}(k-1) }
  & \mathtt{wp2^{impl}(k-1) }
  & \mathtt{wp3^{impl}(k)\phantom{+0} }
  & \mathtt{wp2^{impl}(k)\phantom{+0} }
  & \cdots
\end{smallmatrix} \right) }_{\mathtt{LHS_{wp23}}\textrm{(Stored in compact format)}}
\left( \begin{array}{l}
  \hfill \vdots \hfill \\
  \mathtt{ wp3^{new}(k-1) } \\
  \mathtt{ wp2^{new}(k-1) } \\
  \mathtt{ wp3^{new}(k)   } \\
  \mathtt{ wp2^{new}(k)   } \\
  \mathtt{ wp3^{new}(k+1) } \\
  \mathtt{ wp2^{new}(k+1) } \\
  \hfill \vdots \hfill
\end{array} \right)
\\ = &
\underbrace{
\left( \begin{smallmatrix}
  \hfill \vdots \hfill \\
  \mathtt{ wp3^{expl}(k-1) } \\
  \mathtt{ wp2^{expl}(k-1) } \\
  \mathtt{ wp3^{expl}(k)\phantom{+0} } \\
  \mathtt{ wp2^{expl}(k)\phantom{+0} } \\
  \mathtt{ wp3^{expl}(k+1) } \\
  \mathtt{ wp2^{expl}(k+1) } \\
  \hfill \vdots \hfill
\end{smallmatrix} \right) }_{ \mathtt{RHS}_{\mathtt{wp23}}}
\end{split}
\end{equation}
%
$lhs_{\mathtt{wp23}}$ is a band-diagonal matrix with two rows above and two below
the main diagonal. $lhs_{\mathtt{wp23}}$ is stored in compact form in an array
with dimensions $\mathtt{(5,2\,nzmax)}$. $rhs_{\mathtt{wp23}}$ is a vector
with dimension $\mathtt{(2\,nzmax)}$. $lhs_{\mathtt{wp23}}$ can be inverted
efficiently using a LU decomposition algorithm for band diagonal matrices.

Contributions to $lhs_{\mathtt{wp23}}$ from (\ref{eq_wp2e}):
%
\begin{equation}
\mathtt{ lhs(k\_wp2,5) = lhs(k\_wp2,5) -\frac{Kw1(k)+\nu_1}{2 dzm(k)dzt(k)}
                                       -\frac{ wmm(k) }{ 2 \ dzm(k) }
       }
\end{equation}
%
\begin{equation}
\mathtt{ lhs(k\_wp2,4) = lhs(k\_wp2,4) - \frac{1}{dzm(k)} }
\end{equation}
%
\begin{equation}
\mathtt{
 lhs(k\_wp2,3)
 = lhs(k\_wp2,3)
 +\frac{1}{dt}
 +\frac{C_1}{taum(k)}
 +\frac{1}{2 dzm(k)} \left(  \frac{Kw1(k+1)+\nu_1}{dzt(k+1)}
                           + \frac{Kw1(k)+\nu_1}{dzt(k)} \right) }
\end{equation}
%
\begin{equation}
\mathtt{ lhs(k\_wp2,2) = lhs(k\_wp2,2) + \frac{1}{dzm(k)} }
\end{equation}
%
\begin{equation}
\mathtt{ lhs(k\_wp2,1) = lhs(k\_wp2,1) -\frac{Kw1(k+1)+\nu_1}{2 dzm(k)dzt(k+1)}
                                       +\frac{ wmm(k) }{ 2 \ dzm(k) }
       }
\end{equation}
%
Contributions to $rhs_{\mathtt{wp23}}$ from (\ref{eq_wp2e}):
%
\begin{equation}
\begin{split}
& \mathtt{ rhs(k\_wp2) = rhs(k\_wp2) } \\
& \mathtt{
  +\frac{wp2(k)}{dt}
  } \\
& \mathtt{
  +\frac{Kw1(k)+\nu_1}{2 dzm(k)dzt(k)} wp2(k-1)
  } \\
& \mathtt{
  -\frac{1}{2 dzm(k)} \left(  \frac{Kw1(k+1)+\nu_1}{dzt(k+1)}
                            + \frac{Kw1(k)+\nu_1}{dzt(k)} \right) wp2(k)
  } \\
& \mathtt{
  +\frac{Kw1(k+1)+\nu_1}{2 dzm(k)dzt(k+1)} wp2(k+1)
  } \\
& \mathtt{
  + wp2t(k)
 }
\end{split}
\end{equation}
%
where
%
\begin{equation}
\mathtt{ k\_wp2 = 2 k}
\end{equation}
%
Contributions to $lhs_{\mathtt{wp23}}$ from (\ref{eq_wp3e}):
%
\begin{equation}
\begin{split}
& \mathtt{ lhs(k\_wp3,5) = lhs(k\_wp3,5) }\\
& \mathtt{
- \frac{Kw8(k-1)+\nu_8}{2 dzt(k)dzm(k-1)}
- \frac{ wmt(k) }{ 2 \ dzt(k) }
- \frac{1}{2 \, dzt(k)}
  \frac{ a1m(k-1)
         \left(wp3(k-1)+wp3(k)\right) }
       { \max\left( wp2(k-1), \epsilon \right) }
}
\end{split}
\end{equation}
%
\begin{equation}
\begin{split}
& \mathtt{ lhs(k\_wp3,4) = lhs(k\_wp3,4)
  - \frac{2 a3m(k-1) wp2(k-1)}{dzt(k)}
  }
\end{split}
\end{equation}
%
\begin{equation}
\begin{split}
& \mathtt{ lhs(k\_wp3,3) = lhs(k\_wp3,3) }\\
& \mathtt{
+ \frac{1}{dt}
+ \frac{C_8}{taut(k)}
   \left(  5 \, C_{8b} \, {Skwt(k)}^4 + 1 \right)
+ \frac{1}{2 dzt(k)} \left(  \frac{Kw8(k)+\nu_8}{dzm(k)}
                           + \frac{Kw8(k-1)+\nu_8}{dzm(k-1)} \right)
} \\
& \mathtt{
+ \frac{1}{2 \, dzt(k)}
  \bigg(
    \frac{ a1m(k)
           \left(wp3(k)+wp3(k+1)\right) }
         { \max\left( wp2(k), \epsilon \right) }
  - \frac{ a1m(k-1)
           \left(wp3(k-1)+wp3(k)\right) }
         { \max\left( wp2(k-1), \epsilon \right) }
  \bigg)
}
\end{split}
\end{equation}
%
\begin{equation}
\begin{split}
& \mathtt{ lhs(k\_wp3,2) = lhs(k\_wp3,2)
  + \frac{2 a3m(k) wp2(k)}{dzt(k)}
  }
\end{split}
\end{equation}
%
\begin{equation}
\begin{split}
& \mathtt{ lhs(k\_wp3,1) = lhs(k\_wp3,1) }\\
& \mathtt{
- \frac{Kw8(k)+\nu_8}{2 dzt(k)dzm(k)}
+ \frac{ wmt(k) }{ 2 \ dzt(k) }
+ \frac{1}{2 \, dzt(k)}
  \frac{ a1m(k) \left(wp3(k)+wp3(k+1)\right) }
       { \max\left( wp2(k), \epsilon \right) }
}
\end{split}
\end{equation}
%
Contributions to $rhs_{\mathtt{wp23}}$ from (\ref{eq_wp3e}):
%
\begin{equation}
\begin{split}
& \mathtt{ rhs(k\_wp3) = rhs(k\_wp3) } \\
& \mathtt{
  + \frac{wp3(k)}{dt}
  + \frac{1}{2dzt(k)}
      \bigg(
              \left(Kw8(k)+\nu_8\right)
              \frac{wp3(k+1)-wp3(k)}{dzm(k)} }  \\
& \mathtt{ \qquad \qquad \qquad \qquad \qquad
            - \left(Kw8(k-1)+\nu_8\right)
              \frac{wp3(k)-wp3(k-1)}{dzm(k-1)}
      \bigg)
  } \\
& \mathtt{
+ \frac{C_8}{taut(k)}
   \left( 4 \, C_{8b} \, {Skwt(k)}^4 \right) wp3(k)
  } \\
& \mathtt{
  + \frac{a3m(k) wp2(k)^2 - a3m(k-1) wp2(k-1)^2 }
         {dzt(k)}
  } \\
& \mathtt{
  + \frac{1}{4 \, dzt(k)}
    \bigg(
      \frac{ a1m(k)
             \left(wp3(k)+wp3(k+1)\right)^2 }
           { \max\left( wp2(k), \epsilon \right) }
     -\frac{ a1m(k-1)
             \left(wp3(k-1)+wp3(k)\right)^2 }
           { \max\left( wp2(k-1), \epsilon \right) }
    \bigg)
  } \\
& \mathtt{
+ wp3t(k)
  }
\end{split}
\end{equation}
%
where
%
\begin{equation}
\mathtt{ k\_wp3 = 2 k - 1}
\end{equation}
%
In order to increase numerical stability in the model, $a_{1}$ has been brought
outside of the derivative.  Besides $a_{1}$, $a_{3}$ has been previously brought
outside of the derivative for the same purpose.  This is not mathematically
correct, but it does help to increase stability.  Brian Griffin.  Feb. 21, 2008.
%
Contributions to $lhs_{\mathtt{wp23}}$ from (\ref{eq_wp3e}):
%
\begin{equation}
\begin{split}
& \mathtt{ lhs(k\_wp3,5) = lhs(k\_wp3,5) }\\
& \mathtt{
- \frac{Kw8(k-1)+\nu_8}{2 dzt(k)dzm(k-1)}
- \frac{ wmt(k) }{ 2 \ dzt(k) }
- \left(\frac{a1m(k)+a1m(k-1)}{2}\right) \frac{1}{2 \, dzt(k)}
  \frac{ \left(wp3(k-1)+wp3(k)\right) }
       { \max\left( wp2(k-1), \epsilon \right) }
}
\end{split}
\end{equation}
%
\begin{equation}
\begin{split}
& \mathtt{ lhs(k\_wp3,4) = lhs(k\_wp3,4)
  - \left(\frac{a3m(k)+a3m(k-1)}{2}\right) \frac{2 wp2(k-1)}{dzt(k)}
  }
\end{split}
\end{equation}
%
\begin{equation}
\begin{split}
& \mathtt{ lhs(k\_wp3,3) = lhs(k\_wp3,3) }\\
& \mathtt{
+ \frac{1}{dt}
+ \frac{C_8}{taut(k)}
   \left(  5 \, C_{8b} \, {Skwt(k)}^4 + 1 \right)
+ \frac{1}{2 dzt(k)} \left(  \frac{Kw8(k)+\nu_8}{dzm(k)}
                           + \frac{Kw8(k-1)+\nu_8}{dzm(k-1)} \right)
} \\
& \mathtt{
+ \left(\frac{a1m(k)+a1m(k-1)}{2}\right) \frac{1}{2 \, dzt(k)}
  \bigg(
    \frac{ \left(wp3(k)+wp3(k+1)\right) }
         { \max\left( wp2(k), \epsilon \right) }
  - \frac{ \left(wp3(k-1)+wp3(k)\right) }
         { \max\left( wp2(k-1), \epsilon \right) }
  \bigg)
}
\end{split}
\end{equation}
%
\begin{equation}
\begin{split}
& \mathtt{ lhs(k\_wp3,2) = lhs(k\_wp3,2)
  + \left(\frac{a3m(k)+a3m(k-1)}{2}\right) \frac{2 wp2(k)}{dzt(k)}
  }
\end{split}
\end{equation}
%
\begin{equation}
\begin{split}
& \mathtt{ lhs(k\_wp3,1) = lhs(k\_wp3,1) }\\
& \mathtt{
- \frac{Kw8(k)+\nu_8}{2 dzt(k)dzm(k)}
+ \frac{ wmt(k) }{ 2 \ dzt(k) }
+ \left(\frac{a1m(k)+a1m(k-1)}{2}\right) \frac{1}{2 \, dzt(k)}
  \frac{ \left(wp3(k)+wp3(k+1)\right) }
       { \max\left( wp2(k), \epsilon \right) }
}
\end{split}
\end{equation}
%
Contributions to $rhs_{\mathtt{wp23}}$ from (\ref{eq_wp3e}):
%
\begin{equation}
\begin{split}
& \mathtt{ rhs(k\_wp3) = rhs(k\_wp3) } \\
& \mathtt{
  + \frac{wp3(k)}{dt}
  + \frac{1}{2dzt(k)}
      \bigg(
              \left(Kw8(k)+\nu_8\right)
              \frac{wp3(k+1)-wp3(k)}{dzm(k)} }  \\
& \mathtt{ \qquad \qquad \qquad \qquad \qquad
            - \left(Kw8(k-1)+\nu_8\right)
              \frac{wp3(k)-wp3(k-1)}{dzm(k-1)}
      \bigg)
  } \\
& \mathtt{
+ \frac{C_8}{taut(k)}
   \left( 4 \, C_{8b} \, {Skwt(k)}^4 \right) wp3(k)
  } \\
& \mathtt{
  + \left(\frac{a3m(k)+a3m(k-1)}{2}\right) \frac{wp2(k)^2 - wp2(k-1)^2 }
                                                {dzt(k)}
  } \\
& \mathtt{
  + \left(\frac{a1m(k)+a1m(k-1)}{2}\right) \frac{1}{4 \, dzt(k)}
    \bigg(
      \frac{ \left(wp3(k)+wp3(k+1)\right)^2 }
           { \max\left( wp2(k), \epsilon \right) }
     -\frac{ \left(wp3(k-1)+wp3(k)\right)^2 }
           { \max\left( wp2(k-1), \epsilon \right) }
    \bigg)
  } \\
& \mathtt{
+ wp3t(k)
  }
\end{split}
\end{equation}

\section{High-order Solution to the Horizontal Wind}
As an alternative to assuming $\bar{e} = \frac{3}{2}\overline{w^{'2}}$,
we can obtain an anisotropic solution using a semi-implicit discretization for
$\overline{u^{'2}}$ and $\overline{v^{'2}}$.
Similarly to (\ref{eq_rtp2}), start with equations (\ref{eq_up2}) and
(\ref{eq_vp2}) (for simplicity, neglect the $\left.\right|_{\rm{pd}}$ and
$\left.\right|_{\rm{cl}}$ terms), substitute (\ref{eq_wpup2}) and
(\ref{eq_wpvp2}) respectively.

\subsection{$\overline{u^{'2}}$}
Assume a steady-state and rearrange $\overline{u^{'2}}$ for a semi-implicit
solution to obtain:

\begin{equation}
\begin{split}
\label{eq_up2_ss}
& \underbrace{
  \dfrac{C_4}{\tau}
  \left(
    \overline{u^{'2}} - \frac{2}{3} \bar{e}
  \right)}_{dp1}
  \underbrace{
   + \frac{2}{3}
     \left(
        C_{14} \frac{\bar{e}}{\tau}
     \right)}_{pr1}
  \underbrace{
+ \bar{w}\ptlder{\overline{u^{'2}}}{z} }_{ma}
  \underbrace{
+ \frac{1}{3} \beta
   \ptlder{}{z}
     \left(
       a_1
       \frac{\overline{w^{'3}}}{\overline{w^{'2}}} \,
       \overline{u^{'2}}
     \right) }_{ta}
  \underbrace{
- \ptlder{}{z} \left[ \left( K_{w9} + \nu_9 \right)
                      \ptlder{}{z} \overline{u^{'2}}
               \right] }_{dp2}  \\
=&   \underbrace{
   - \left( 1 - \frac{1}{3}\beta \right)
       \ptlder{}{z}
         \left(
           a_2
           \frac{\overline{w^{'3}}}{\overline{w^{'2}}^2} \,
           \overline{w'u'}^2
         \right) }_{ta}
     \underbrace{
   - 2 (1 - C_{5} ) \, \overline{w'u'} \, \ptlder{\bar{u}}{z} }_{tp} \\
 &   \underbrace{
   + \frac{2}{3} C_5
     \left(
       \frac{g}{\theta_0} \overline{w'\theta'_v}
       - \overline{u'w'}\ptlder{\bar{u}}{z}
       - \overline{v'w'}\ptlder{\bar{v}}{z}
     \right) }_{pr2}
\end{split}
\end{equation}

As in the case of $\overline{r_t^{'2}}$ and $\overline{\theta_l^{'2}}$, the
horizontal wind variance terms are solved using a tridiagonal matrix.

\subsubsection{Terms 1 and 2:  dp1 and pr1, respectively}
%
\begin{equation}
\begin{split}
 & \left. \frac{C_4}{\tau}
    \left(
      \overline{u^{'2}} - \frac{2}{3} \bar{e}
    \right)
   + \frac{2}{3} C_{14} \frac{\bar{e}}{\tau} \right|_{\mathtt{zm(k)}} \\
=& \mathtt{
   \frac{C_4}{taum(k)} up2(k)
   -\frac{C_4}{taum(k)} \frac{2}{3} em(k)
   + \frac{2}{3} C_{14} \frac{em(k)}{taum(k)}
    } \\
=& \mathtt{
   \frac{C_4}{taum(k)} up2(k) - \frac{2}{3} em(k)
   \left(
     \frac{C_4}{taum(k)} - \frac{C_{14}}{taum(k)}
   \right)
   } \\
=& \mathtt{
   \frac{C_4}{taum(k)} up2(k) - \frac{2}{3}
   \left[
     \frac{up2(k) + vp2(k) + wp2(k)}{2}
   \right]
   \left(
     \frac{C_4}{taum(k)} - \frac{C_{14}}{taum(k)}
   \right)
   } \\
=& \mathtt{
   up2(k)
   \frac{1}{3} \left(
      \frac{2 C_4 + C_{14}}{taum(k)}
   \right)
 - \left(
     \frac{1}{3}
     \left(
        C_4 - C_{14}
     \right)
     \left(
        \frac{vp2(k) + wp2(k)}{taum(k)}
     \right)
   \right)
   }
\end{split}
\end{equation}
%

Separating out the contributions:
%
\begin{equation}
\begin{split}
& \mathtt{
  lhs(2,k) = lhs(2,k) + \frac{2 C_{4} + C_{14}}{3 taum(k)}
  } \\
& \mathtt{
  rhs(k) = rhs(k) + \frac{1}{3}
  \left(
    C_4 - C_{14}
  \right)
  \left(
    \frac{vp2(k) + wp2(k)}{taum(k)}
  \right)
  }
\end{split}
\end{equation}
%

\subsubsection{Term 3:  ma}

%
\begin{equation}
\begin{split}
& \left. \bar{w}\ptlder{\overline{u^{'2}}}{z} \right|_{\mathtt{zm(k)}} \\
=& \mathtt{ \frac{wmm(k)}{dzm(k)}
   \left(
     \frac{1}{2} \left( up2(k)+up2(k+1) \right)
     - \frac{1}{2} \left( up2(k-1)+up2(k) \right)
   \right) } \\
=& \mathtt{ \frac{wmm(k)}{2 dzm(k)} up2(k+1) - \frac{wmm(k)}{2 dzm(k)} up2(k-1) }
\end{split}
\end{equation}
%

Separating out the contributions:
%
\begin{equation}
\begin{split}
& \mathtt{ lhs(1,k) = lhs(1,k) + \frac{wmm(k)}{2 dzm(k)} } \\
& \mathtt{ lhs(3,k) = lhs(3,k) - \frac{wmm(k)}{2 dzm(k)} }
\end{split}
\end{equation}
%

\subsubsection{Term 4:  ta, implicit component}
%
\begin{equation}
\begin{split}
& \left.
  \frac{1}{3} \beta
   \ptlder{}{z}
     \left(
       a_1
       \frac{\overline{w^{'3}}}{\overline{w^{'2}}} \,
       \overline{u^{'2}}
     \right)
   \right|_{\mathtt{zm(k)}} \\
&= \mathtt{
    \frac{\beta}{6 dzm(k)}
    \bigg[ \frac{\left(a1m(k)+a1m(k+1)\right) wp3(k+1) \left(up2(k)+up2(k+1) \right)}
                {\max\left(wp2(k)+wp2(k+1),2\epsilon\right)} } \\
&  \mathtt{ \quad \quad \quad \quad \quad \quad
          -\frac{\left(a1m(k-1)+a1m(k)\right) wp3(k) \left(up2(k-1)+up2(k) \right)}
                {\max\left(wp2(k-1)+wp2(k),2\epsilon\right)}
    \bigg]
    }
\end{split}
\end{equation}
%
Separating out the contributions:
%
\begin{equation}
\begin{split}
& \mathtt{
   lhs(3,k) = lhs(3,k) - \frac{\beta}{6 dzm(k)}
                         \frac{\left(a1m(k-1)+a1m(k)\right) wp3(k)}
                      {\max\left(wp2(k-1)+wp2(k),2\epsilon\right)}
  } \\
& \mathtt{
   lhs(2,k) = lhs(2,k) + \frac{\beta}{6 dzm(k)}
                 \left(
                   \frac{\left(a1m(k)+a1m(k+1)\right) wp3(k+1)}
                        {\max\left(wp2(k)+wp2(k+1),2\epsilon\right)}
                  -\frac{\left(a1m(k-1)+a1m(k)\right) wp3(k)}
                        {\max\left(wp2(k-1)+wp2(k),2\epsilon\right)}
                 \right)
  } \\
& \mathtt{
   lhs(1,k) = lhs(1,k) + \frac{\beta}{6 dzm(k)}
                 \frac{\left(a1m(k)+a1m(k+1)\right) wp3(k+1)}
                      {\max\left(wp2(k)+wp2(k+1),2\epsilon\right)}
  }
\end{split}
\end{equation}
%
In order to increase numerical stability in the model, $a_{1}$ has been brought
outside of the derivative.  This is not mathematically correct, but it does
help to increase stability.  Brian Griffin.  Feb. 21, 2008.
%
\begin{equation}
\begin{split}
& \left.
  a_1
  \frac{1}{3} \beta
   \ptlder{}{z}
     \left(
       \frac{\overline{w^{'3}}}{\overline{w^{'2}}} \,
       \overline{u^{'2}}
     \right)
   \right|_{\mathtt{zm(k)}} \\
&= \mathtt{
    a1m(k)\frac{\beta}{3 dzm(k)}
    \bigg[ \frac{wp3(k+1) \left(up2(k)+up2(k+1) \right)}
                {\max\left(wp2(k)+wp2(k+1),2\epsilon\right)}
          -\frac{wp3(k) \left(up2(k-1)+up2(k) \right)}
                {\max\left(wp2(k-1)+wp2(k),2\epsilon\right)}
    \bigg]
    }
\end{split}
\end{equation}
%
Separating out the contributions:
%
\begin{equation}
\begin{split}
& \mathtt{
   lhs(3,k) = lhs(3,k) - a1m(k)\frac{\beta}{3 dzm(k)}
                         \frac{wp3(k)}
                              {\max\left(wp2(k-1)+wp2(k),2\epsilon\right)}
  } \\
& \mathtt{
   lhs(2,k) = lhs(2,k) + a1m(k)\frac{\beta}{3 dzm(k)}
                         \left(
                           \frac{wp3(k+1)}
                                {\max\left(wp2(k)+wp2(k+1),2\epsilon\right)}
                          -\frac{wp3(k)}
                                {\max\left(wp2(k-1)+wp2(k),2\epsilon\right)}
                         \right)
  } \\
& \mathtt{
   lhs(1,k) = lhs(1,k) + a1m(k)\frac{\beta}{3 dzm(k)}
                         \frac{wp3(k+1)}
                              {\max\left(wp2(k)+wp2(k+1),2\epsilon\right)}
  }
\end{split}
\end{equation}

\subsubsection{Term 5:  dp2}
%
\begin{equation}
\begin{split}
& \left. - \ptlder{}{z} \left[ \left( K_{w9} + \nu_9 \right)
                               \ptlder{}{z} \overline{u^{'2}}
                        \right] \right|_{\mathtt{zm(k)}}  \\
 &= \mathtt{
    -\frac{1}{dzm(k)}
     \bigg( \frac{ \left( Kw9(k+1) + \nu_9 \right)
                   \left( up2(k+1) - up2(k) \right)} {dzt(k+1)}
           -\frac{ \left( Kw9(k) + \nu_9 \right)
                   \left( up2(k) - up2(k-1) \right)} {dzt(k)}
     \bigg)
    }
\end{split}
\end{equation}
%
Separating out the contributions:
%
\begin{equation}
\begin{split}
&\mathtt{lhs(3,k) = lhs(3,k) - \frac{Kw9(k)+\nu_9}{dzm(k)dzt(k)} } \\
&\mathtt{lhs(2,k) = lhs(2,k) + \frac{1}{dzm(k)}
                               \left(   \frac{Kw9(k+1)+\nu_9}{dzt(k+1)}
                                      + \frac{Kw9(k)+\nu_9}{dzt(k)} \right) } \\
&\mathtt{lhs(1,k) = lhs(1,k) - \frac{Kw9(k+1)+\nu_9}{dzm(k)dzt(k+1)} }
\end{split}
\end{equation}
%

\subsubsection{Term 6:  ta, explicit component}
%
\begin{equation}
\begin{split}
& - \left. \left( 1 - \frac{1}{3}\beta \right)
       \ptlder{}{z}
         \left(
           a_2
           \frac{\overline{w^{'3}}}{\overline{w^{'2}}^2} \,
           \overline{w'u'}^2
         \right) \right|_{\mathtt{zm(k)}} \\
=& \mathtt{
   - \frac{1 - \frac{1}{3}\beta}{4 dzm(k)}
     \bigg[ \frac{\left(a1m(k)+a1m(k+1)\right)^2 wp3(k+1) \left(upwp(k)+upwp(k+1)\right)^2}
                 {\max\left(wp2(k)+wp2(k+1),2\epsilon\right)^2} } \\
 & \mathtt{ \quad \quad \quad \quad \quad \quad
           -\frac{\left(a1m(k-1)+a1m(k)\right)^2 wp3(k) \left(upwp(k-1)+upwp(k)\right)^2}
                 {\max\left(wp2(k-1)+wp2(k),2\epsilon\right)^2}
     \bigg]
   }
\end{split}
\end{equation}
%
Separating out the contributions:
%
\begin{equation}
\begin{split}
&\mathtt{rhs(k)} \\
=& \mathtt{
   rhs(k)
   - \frac{1 - \frac{1}{3}\beta}{4 dzm(k)}
     \bigg[ \frac{\left(a1m(k)+a1m(k+1)\right)^2 wp3(k+1) \left(upwp(k)+upwp(k+1)\right)^2}
                 {\max\left(wp2(k)+wp2(k+1),2\epsilon\right)^2} } \\
 & \mathtt{ \quad \quad \quad \quad \quad \quad \quad \quad
           -\frac{\left(a1m(k-1)+a1m(k)\right)^2 wp3(k) \left(upwp(k-1)+upwp(k)\right)^2}
                 {\max\left(wp2(k-1)+wp2(k),2\epsilon\right)^2}
     \bigg]
   }
\end{split}
\end{equation}
%
In order to increase numerical stability in the model, $a_{1}$ has been brought
outside of the derivative.  This is not mathematically correct, but it does
help to increase stability.  Brian Griffin.  Feb. 21, 2008.
%
\begin{equation}
\begin{split}
& - \left. a_2 \left( 1 - \frac{1}{3}\beta \right)
       \ptlder{}{z}
         \left(
           \frac{\overline{w^{'3}}}{\overline{w^{'2}}^2} \,
           \overline{w'u'}^2
         \right) \right|_{\mathtt{zm(k)}} \\
=& \mathtt{
   - a1m(k)^{2} \frac{1 - \frac{1}{3}\beta}{dzm(k)}
     \bigg[ \frac{wp3(k+1) \left(upwp(k)+upwp(k+1)\right)^2}
                 {\max\left(wp2(k)+wp2(k+1),2\epsilon\right)^2} } \\
 & \mathtt{ \quad \quad \quad \quad \qquad \qquad
           -\frac{wp3(k) \left(upwp(k-1)+upwp(k)\right)^2}
                 {\max\left(wp2(k-1)+wp2(k),2\epsilon\right)^2}
     \bigg]
   }
\end{split}
\end{equation}
%
Separating out the contributions:
%
\begin{equation}
\begin{split}
&\mathtt{rhs(k)} \\
=& \mathtt{
   rhs(k)
   - a1m(k)^{2} \frac{1 - \frac{1}{3}\beta}{dzm(k)}
     \bigg[ \frac{wp3(k+1) \left(upwp(k)+upwp(k+1)\right)^2}
                 {\max\left(wp2(k)+wp2(k+1),2\epsilon\right)^2} } \\
 & \mathtt{ \quad \quad \quad \quad \qquad \qquad \qquad \qquad
           -\frac{wp3(k) \left(upwp(k-1)+upwp(k)\right)^2}
                 {\max\left(wp2(k-1)+wp2(k),2\epsilon\right)^2}
     \bigg]
   }
\end{split}
\end{equation}

\subsubsection{Term 7:  tp}
%
\begin{equation}
\begin{split}
&\left. - 2 \, \left( 1 - C_5 \right) \, \overline{w'u'} \, \ptlder{\bar{u}}{z} \right|_{\mathtt{zm(k)}}
 = \mathtt{ - 2 \left( 1 - C_5 \right) upwp(k) \frac{um(k+1)-um(k)}{dzm(k)} }
\end{split}
\end{equation}
%

Separating out the contributions:
%
\begin{equation}
\begin{split}
&\mathtt{rhs(k) = rhs(k) - 2 \left(1 - C_5\right) upwp(k) \frac{um(k+1)-um(k)}{dzm(k)} }
\end{split}
\end{equation}
%

\subsubsection{Term 8:  pr2}
%
\begin{equation}
\begin{split}
&  \frac{2}{3} C_5
   \left(
      \frac{g}{\theta_0} \overline{w'\theta'_v}
      - \overline{u'w'}\ptlder{\bar{u}}{z}
      - \overline{v'w'}\ptlder{\bar{v}}{z}
   \right) \left. \right|_{\mathtt{zm(k)}} \\
=& \mathtt{
   \frac{2}{3} C_5
   \left(
   \frac{grav}{T0} wpthvp(k)
   - upwp(k) \frac{um(k+1)-um(k)}{dzm(k)}
   - vpwp(k) \frac{vm(k+1)-vm(k)}{dzm(k)}
   \right)
   }
\end{split}
\end{equation}

Separating out the contributions:
%
\begin{equation}
\begin{split}
&\mathtt{rhs(k) = rhs(k) + \frac{2}{3} C_5
  \left(
    \frac{grav}{T0} wpthvp(k)
       - upwp(k) \frac{um(k+1)-um(k)}{dzm(k)}
       - vpwp(k) \frac{vm(k+1)-vm(k)}{dzm(k)}
  \right)}
\end{split}
\end{equation}
%

\subsection{$\overline{v^{'2}}$}
As in $\overline{u^{'2}}$ assume a steady-state and rearrange $\overline{u^{'2}}$ for a
semi-implicit solution to obtain:

\begin{equation}
\begin{split}
\label{eq_vp2_ss}
& \dfrac{C_4}{\tau}
  \left(
    \overline{v^{'2}} - \frac{2}{3} \bar{e}
  \right)
  + \frac{2}{3}
     \left(
        C_{14} \frac{\bar{e}}{\tau}
     \right)
+ \bar{w}\ptlder{\overline{v^{'2}}}{z}
+ \frac{1}{3} \beta
   \ptlder{}{z}
     \left(
       a_1
       \frac{\overline{w^{'3}}}{\overline{w^{'2}}} \,
       \overline{v^{'2}}
     \right)
- \ptlder{}{z} \left[ \left( K_{w9} + \nu_9 \right)
                      \ptlder{}{z} \overline{v^{'2}}
               \right]  \\
=& - \left( 1 - \frac{1}{3}\beta \right)
       \ptlder{}{z}
         \left(
           a_2
           \frac{\overline{w^{'3}}}{\overline{w^{'2}}^2} \,
           \overline{w'v'}^2
         \right)
   - 2 (1 - C_{5} ) \, \overline{w'v'} \, \ptlder{\bar{v}}{z} \\
 & + \frac{2}{3} C_5
     \left(
       \frac{g}{\theta_0} \overline{w'\theta'_v}
       - \overline{u'w'}\ptlder{\bar{u}}{z}
       - \overline{v'w'}\ptlder{\bar{v}}{z}
     \right)
\end{split}
\end{equation}

The discretization for $\overline{v^{'2}}$ follows in the same way as $\overline{u^{'2}}$.

\section{Grid Configuration}

Figure \ref{grid} shows the vertical grid configuration for CLUBB.
The grid consists of two types of levels: $\mathtt{zm}$ and $\mathtt{zt}$.
Predictive mean variables and third order moments reside on the
thermodynamic levels ($\mathtt{zt}$). Second and fourth order moments
reside on the momentum levels ($\mathtt{zm}$).
%
% - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
%
\begin{figure}[htp]
\vspace*{19cm}
\begin{center}
%
\psline[linewidth=2pt](-4,18)(4,18)
\rput*[b]{0}(0,17.8){zm(nzmax)}
%
\psline[linewidth=2pt,linestyle=dotted,dotsep=2pt](-4,17)(4,17)
\rput*[b]{0}(0,16.8){zt(nzmax)}
%
\psline[linewidth=2pt](-4,16)(4,16)
\rput*[b]{0}(0,15.8){zm(nzmax-1)}
%
\psline[linewidth=2pt,linestyle=dotted,dotsep=2pt](-4,15)(4,15)
\rput*[b]{0}(0,14.8){zt(nzmax-1)}
%
%
\psline[linewidth=2pt](-4,12)(4,12)
\rput*[b]{0}(0,11.8){zm(k+1)}
%
\psline[linewidth=2pt,linestyle=dotted,dotsep=2pt](-4,11)(4,11)
\rput*[b]{0}(0,10.8){zt(k+1)}
%
\psline[linewidth=2pt](-4,10)(4,10)
\rput*[b]{0}(0,9.8){zm(k)}
%
\psline[linewidth=2pt,linestyle=dotted,dotsep=2pt](-4,9)(4,9)
\rput*[b]{0}(0,8.8){zt(k)}
%
\psline[linewidth=2pt](-4,8)(4,8)
\rput*[b]{0}(0,7.8){zm(k-1)}
%
\psline[linewidth=2pt,linestyle=dotted,dotsep=2pt](-4,7)(4,7)
\rput*[b]{0}(0,6.8){zt(k-1)}
%
\psline[linewidth=2pt](-4,6)(4,6)
\rput*[b]{0}(0,5.8){zm(k-2)}
%
%
\psline[linewidth=2pt](-4,3)(4,3)
\rput*[b]{0}(0,2.8){zm(2)}
\rput*[bl]{0}(1.7,2.8){$\overline{w^{'2}}$, $\overline{w'\theta_l'}$,
$\overline{w'r_t'}$, $\overline{w^{'4}}$, $\ldots$}
%
\psline[linewidth=2pt,linestyle=dotted,dotsep=2pt](-4,2)(4,2)
\rput*[b]{0}(0,1.8){zt(2)}
\rput*[bl]{0}(1.7,1.8){$\bar{u}$, $\bar{v}$, $\bar{\theta}_l$, $\bar{q}_t$,
$\overline{w^{'3}}$, $\overline{w^{'2}\theta_v'}$, $\ldots$}
%
\pspolygon[linestyle=none,fillstyle=crosshatch,hatchwidth=0.1pt,hatchsep=3pt]
(-4,0.5)(4,0.5)(4,1)(-4,1)
\psline[linewidth=2pt](-4,1)(4,1)
\rput*[b]{0}(0,0.8){zm(1)}
\rput*[bl]{0}(4.2,0.6){Surface}
%
\psline[linewidth=2pt,linestyle=dotted,dotsep=2pt](-4,0)(4,0)
\rput*[b]{0}(0,-0.2){zt(1)}
%
\psline[linewidth=3pt,linestyle=dotted,dotsep=8pt](0,3.5)(0,5.5)
\psline[linewidth=3pt,linestyle=dotted,dotsep=8pt](0,12.5)(0,14.5)
%
% delta zt
%
\psline[]{|-|}(5,16)(5,18)
\rput*[b]{0}(5,16.8){$\Delta$zt(nzmax)}
%
\psline[]{|-|}(5,10)(5,12)
\rput*[b]{0}(5,10.8){$\Delta$zt(k+1)}
%
\psline[]{|-|}(5,8)(5,10)
\rput*[b]{0}(5,8.8){$\Delta$zt(k)}
%
\psline[]{|-|}(5,6)(5,8)
\rput*[b]{0}(5,6.8){$\Delta$zt(k-1)}
%
% delta zm
%
\psline[]{|-|}(-5,15)(-5,17)
\rput*[b]{0}(-5,15.8){$\Delta$zm(nzmax-1)}
%
\psline[]{|-|}(-5,9)(-5,11)
\rput*[b]{0}(-5,9.8){$\Delta$zm(k)}
%
\psline[]{|-|}(-5,7)(-5,9)
\rput*[b]{0}(-5,7.8){$\Delta$zm(k-1)}
%
\end{center}
%\vspace*{1cm}
\caption{Vertical grid configuration}
\label{grid}
\end{figure}

\pagebreak

% Vertical grid configuration for stretched grid.
\subsection{Stretched (unevenly-spaced) grid configuration}

The grid setup is compatible with a stretched (unevenly-spaced) grid
configuration.  Thus, the distance between successive vertical grid levels may
not always be constant.

%Stretched (unevenly-spaced) grid defined on momentum levels
The following diagram is an example of a stretched grid that is defined on
momentum levels.  The thermodynamic levels are placed exactly halfway between
the momentum levels.  However, the momentum levels do not fall halfway between
the thermodynamic levels.
% Diagram of stretched grid defined on momentum levels.
%
\begin{figure}[htp]
\vspace*{6cm}
\begin{center}
%
\psline[linewidth=2pt](-4,5.5)(4,5.5)
\rput*[b]{0}(0,5.3){zm(k+1)}
%
\psline[linewidth=2pt,linestyle=dotted,dotsep=2pt](-4,4)(4,4)
\rput*[b]{0}(0,3.8){zt(k+1)}
%
\psline[linewidth=2pt](-4,2.5)(4,2.5)
\rput*[b]{0}(0,2.3){zm(k)}
%
\psline[linewidth=2pt,linestyle=dotted,dotsep=2pt](-4,1.5)(4,1.5)
\rput*[b]{0}(0,1.3){zt(k)}
%
\psline[linewidth=2pt](-4,0.5)(4,0.5)
\rput*[b]{0}(0,0.3){zm(k-1)}
%
\end{center}
\end{figure}

%Stretched (unevenly-spaced) grid defined on thermodynamic levels
The following diagram is an example of a stretched grid that is defined on
thermodynamic levels.  The momentum levels are placed exactly halfway between
the thermodynamic levels.  However, the thermodynamic levels do not fall halfway
between the momentum levels.
% Diagram of stretched grid defined on thermodynamic levels.
%
\begin{figure}[htp]
\vspace*{6cm}
\begin{center}
%
\psline[linewidth=2pt,linestyle=dotted,dotsep=2pt](-4,5.5)(4,5.5)
\rput*[b]{0}(0,5.3){zt(k+1)}
%
\psline[linewidth=2pt](-4,4)(4,4)
\rput*[b]{0}(0,3.8){zm(k)}
%
\psline[linewidth=2pt,linestyle=dotted,dotsep=2pt](-4,2.5)(4,2.5)
\rput*[b]{0}(0,2.3){zt(k)}
%
\psline[linewidth=2pt](-4,1.5)(4,1.5)
\rput*[b]{0}(0,1.3){zm(k-1)}
%
\psline[linewidth=2pt,linestyle=dotted,dotsep=2pt](-4,0.5)(4,0.5)
\rput*[b]{0}(0,0.3){zt(k-1)}
%
\end{center}
\end{figure}

\pagebreak

% Generalized grid functions
\subsection{Generalized grid functions}

Each variable in the CLUBB parameterization resides at certain discrete points
in the vertical, whether the points be on momentum levels or on thermodynamic
levels.  The values of each variable are considered to behave in a linear
fashion in the sections between the levels where each variable resides.  Thus,
linear interpolation is used to find the values of a variable at the levels
where it does not reside.  Since a variable is considered to behave linearly
between two successive levels where it resides, the linear derivative of that
variable at any point in the section between two successive levels where it
resides is always the same.

Any future computer code written for use in the CLUBB parameterization should
use interpolation formulas consistent with a stretched grid.  The simplest way
to do so is to use the appropriate equation listed below in
equations~\ref{eq_zm2zt} through~\ref{eq_zt2zm_imp_lower}.
Interpolations should not be handled in the form of:
$( \mathtt{var_m(k)} + \mathtt{var_m(k-1)} ) / 2$; nor in the form of:
$0.5 \times ( \mathtt{var_t(k+1)} + \mathtt{var_t(k)} )$.  Rather, all explicit
interpolations should use the appropriate equation from
equations~\ref{eq_zm2zt}, \ref{eq_zm2zt_ext}, \ref{eq_zt2zm},
or~\ref{eq_zt2zm_ext}; while interpolations for a variable being solved for
implicitly in the model code should use the appropriate equation set from
equations~\ref{eq_zm2zt_imp_upper} and \ref{eq_zm2zt_imp_lower}, or
\ref{eq_zt2zm_imp_upper} and~\ref{eq_zt2zm_imp_lower}.  The formula for a
linear derivative is the same whether an evenly-spaced grid or stretched grid
is in use.

\subsubsection{Momentum grid levels to thermodynamic grid levels}

A standard linear interpolation formula, equation~\ref{eq_zm2zt}, is used to
interpolate a variable that resides on momentum levels, $\mathtt{var_m}$, to
thermodynamic levels (as $\mathtt{var_t}$) on any type of grid configuration.
\begin{equation}
\label{eq_zm2zt}
\mathtt{var_t(k)}
   = \left( \frac{ \mathtt{var_m(k)} - \mathtt{var_m(k-1)} }
                 { \mathtt{zm(k)} - \mathtt{zm(k-1)} } \right)
     \Big( \mathtt{zt(k)} - \mathtt{zm(k-1)} \Big)
     + \mathtt{var_m(k-1)}
\end{equation}
When converting a variable from momentum levels to thermodynamic levels, there
is one instance on the grid, at the lowermost level ($\mathtt{k=1}$), where
a linear extension, equation~\ref{eq_zm2zt_ext}, is required.
\begin{equation}
\label{eq_zm2zt_ext}
\mathtt{var_t(1)}
   = \left( \frac{ \mathtt{var_m(2)} - \mathtt{var_m(1)} }
                 { \mathtt{zm(2)} - \mathtt{zm(1)} } \right)
     \Big( \mathtt{zt(1)} - \mathtt{zm(1)} \Big)
     + \mathtt{var_m(1)}
\end{equation}
When a variable that is being solved for implicitly in an equation is also being
interpolated from momentum levels to intermediate thermodynamic levels, the
interpolation formulas listed above will not work.  Rather, interpolation
weights are necessary.  The weight of the upper momentum level
(index~$\mathtt{k}$) on the intermediate thermodynamic level
(index~$\mathtt{k}$) is found according to equation~\ref{eq_zm2zt_imp_upper}.
\begin{equation}
\label{eq_zm2zt_imp_upper}
\mathtt{weights\_zm2zt(m\_above,k)}
   = \left( \frac{ \mathtt{zt(k)} - \mathtt{zm(k-1)} }
                 { \mathtt{zm(k)} - \mathtt{zm(k-1)} } \right)
\end{equation}
The weight of the lower momentum level (index~$\mathtt{k-1}$) on the
intermediate thermodynamic level (index~$\mathtt{k}$) is found according to
equation~\ref{eq_zm2zt_imp_lower}.
\begin{equation}
\label{eq_zm2zt_imp_lower}
\mathtt{weights\_zm2zt(m\_below,k)}
   = 1 - \left( \frac{ \mathtt{zt(k)} - \mathtt{zm(k-1)} }
                     { \mathtt{zm(k)} - \mathtt{zm(k-1)} } \right)
\end{equation}

\subsubsection{Thermodynamic grid levels to momentum grid levels}

A standard linear interpolation formula, equation~\ref{eq_zt2zm}, is used to
interpolate a variable that resides on thermodynamic levels, $\mathtt{var_t}$,
to momentum levels (as $\mathtt{var_m}$) on any type of grid configuration.
\begin{equation}
\label{eq_zt2zm}
\mathtt{var_m(k)}
   = \left( \frac{ \mathtt{var_t(k+1)} - \mathtt{var_t(k)} }
                 { \mathtt{zt(k+1)} - \mathtt{zt(k)} } \right)
     \Big( \mathtt{zm(k)} - \mathtt{zt(k)} \Big)
     + \mathtt{var_t(k)}
\end{equation}
When converting a variable from thermodynamic levels to momentum levels, there
is one instance on the grid, at the uppermost level ($\mathtt{k=nzmax}$), where
a linear extension, equation~\ref{eq_zt2zm_ext}, is required.
\begin{equation}
\label{eq_zt2zm_ext}
\mathtt{var_m(nzmax)}
   = \left( \frac{ \mathtt{var_t(nzmax)} - \mathtt{var_t(nzmax-1)} }
                 { \mathtt{zt(nzmax)} - \mathtt{zt(nzmax-1)} } \right)
     \Big( \mathtt{zm(nzmax)} - \mathtt{zt(nzmax)} \Big)
     + \mathtt{var_t(nzmax)}
\end{equation}
When a variable that is being solved for implicitly in an equation is also being
interpolated from thermodynamic levels to intermediate momentum levels, the
interpolation formulas listed above will not work.  Rather, interpolation
weights are necessary.  The weight of the upper thermodynamic level
(index~$\mathtt{k+1}$) on the intermediate momentum level (index~$\mathtt{k}$)
is found according to equation~\ref{eq_zt2zm_imp_upper}.
\begin{equation}
\label{eq_zt2zm_imp_upper}
\mathtt{weights\_zt2zm(t\_above,k)}
   = \left( \frac{ \mathtt{zm(k)} - \mathtt{zt(k)} }
                 { \mathtt{zt(k+1)} - \mathtt{zt(k)} } \right)
\end{equation}
The weight of the lower thermodynamic level (index~$\mathtt{k}$) on the
intermediate momentum level (index~$\mathtt{k}$) is found according to
equation~\ref{eq_zt2zm_imp_lower}.
\begin{equation}
\label{eq_zt2zm_imp_lower}
\mathtt{weights\_zt2zm(t\_below,k)}
   = 1 - \left( \frac{ \mathtt{zm(k)} - \mathtt{zt(k)} }
                     { \mathtt{zt(k+1)} - \mathtt{zt(k)} } \right)
\end{equation}

\pagebreak

\section{Predictive equations in Conjunction with Host Model}

The CLUBB parameterization can be used in conjunction with a larger host model.
Some of the main predictive equations (Eqns. \ref{eq_um}, \ref{eq_vm},
\ref{eq_rtm}, and \ref{eq_thlm}) have to be divided in the following manner:
%
\begin{equation}
\ptlder{\color{red}\bar{u}}{t}
= {\color{magenta}- \bar{w}\ptlder{\bar{u}}{z}}
  {\color{magenta}- f (v_g - \bar{v})}
  - \ptlder{}{z}{\color{blue}\overline{u'w'}}
\end{equation}
%
\begin{equation}
\ptlder{\color{red}\bar{v}}{t}
= {\color{magenta}- \bar{w}\ptlder{\bar{v}}{z}}
  {\color{magenta}+ f (u_g - \bar{u})}
  - \ptlder{}{z}{\color{blue}\overline{v'w'}}
\end{equation}
%
\begin{equation}
\ptlder{\color{red}\bar{q}_t}{t}
= {\color{magenta}- \bar{w}\ptlder{\bar{q}_t}{z}}
  - \ptlder{}{z}{\color{blue}\overline{w'q'_t}}
  {\color{magenta}+ \left. \ptlder{\bar{q}_t}{t} \right|_{\rm ls}}
\end{equation}
%
\begin{equation}
\ptlder{\color{red}\bar{\theta}_l}{t}
= {\color{magenta}- \bar{w}\ptlder{\bar{\theta}_l}{z}}
  - \ptlder{}{z}{\color{blue}\overline{w'\theta'_l}}
  {\color{magenta}+ \bar{R}}
  {\color{magenta}+ \left. \ptlder{\bar{\theta}_l}{t} \right|_{\rm ls}}
\end{equation}
%
{\color{red}The variables in red, $\bar{u}$, $\bar{v}$, $\bar{q}_t$, and
$\bar{\theta}_l$, are supplied from the host model to the CLUBB parameterization.}
{\color{blue}The variables in blue, $\overline{u'w'}$, $\overline{v'w'}$,
$\overline{w'q'_t}$, and $\overline{w'\theta'_l}$, are computed in the CLUBB
parameterization and then sent back to the host model.  The vertical
derivatives of these variables are then used to effect the time tendencies of
their related variables.}  {\color{magenta}The terms listed in magenta, which
include the vertical mean advection terms, the coriolis terms, the radiative
heating term, and the large-scale moisture and temperature forcings, are terms
that are usually calculated in CLUBB when CLUBB does not run with any host model.
However, in cases where a host model is involved, the host model should
calculate all of these terms.}  As before, $\bar{R}$ is the radiative heating
rate, $f$ the Coriolis parameter and $u_g$, $v_g$ the geostrophic winds.
$\left. \ptlder{\bar{q}_t}{t} \right|_{\rm ls}$ and
$\left. \ptlder{\bar{\theta}_l}{t} \right|_{\rm ls}$ are
large-scale moisture and temperature forcings.

The $\ptlder{\overline{w^{'2}}}{t}$ equation (eq. \ref{eq_wp2}),
the $\ptlder{\overline{r_t^{'2}}}{t}$ equation (eq. \ref{eq_rtp2}),
the $\ptlder{\overline{\theta_l^{'2}}}{t}$ equation (eq. \ref{eq_thlp2}),
the $\ptlder{\overline{q'_t\theta'_l}}{t}$ equation (eq. \ref{eq_rtpthlp}),
the $\ptlder{\overline{w'q'_t}}{t}$ equation (eq. \ref{eq_wprtp}),
the $\ptlder{\overline{w'\theta'_t}}{t}$ equation (eq. \ref{eq_wpthlp}),
and the $\ptlder{\overline{w^{'3}}}{t}$ equation (eq. \ref{eq_wp3})
all remain unchanged.  All of these variables are computed and used completely
within the structure of the CLUBB parameterization.

Within the structure of a computer code, the CLUBB parameterization requires that
the values of certain variables be saved at all grid points for use during the
next timestep.  Since the CLUBB parameterization is a one-dimensional
parameterization (in the vertical), or a single-column parameterization, a
three-dimensional host model must call the CLUBB parameterization once for every
grid column that it has.  Therefore, the values of all these variables must be
saved from timestep to timestep at every grid point in the three dimensions.

The variables that need to be saved as such are the following:
\begin{center}
\begin{tabular} {|l|c|c|}
\hline
\multicolumn{3}{|c|}{On the momentum (or full) levels}\\\hline
Description&Variable&Variable name in CLUBB code\\\hline
Turbulent Flux of $\theta_l$&$\overline{w'\theta'_l}$&wpthlp\\\hline
Turbulent Flux of $r_t$&$\overline{w'r'_t}$&wprtp\\\hline
Variance of $w$&$\overline{w^{'2}}$&wp2\\\hline
Variance of $u$&$\overline{u'^2}$&up2\\\hline
Variance of $v$&$\overline{v'^2}$&vp2\\\hline
Variance of $r_t$&$\overline{r^{'2}_t}$&rtp2\\\hline
Variance of $\theta_l$&$\overline{\theta^{'2}_l}$&thlp2\\\hline
Covariance of $r_t$ and $\theta_l$&$\overline{r'_t\theta'_l}$&rtpthlp\\\hline
Covariance of $u$ and $w$&$\overline{u'w'}$&upwp\\\hline
Covariance of $v$ and $w$&$\overline{v'w'}$&vpwp\\\hline
Time scale&$\tau$&taum\\\hline
Width of the individual $w$ plumes&$\tilde{\sigma}^2_w$&sigma\_sqd\_w\\\hline
\multicolumn{3}{|c|}{On the thermodynamic (or half) levels}\\\hline
Description&Variable&Variable name in CLUBB code\\\hline
Third-order Moment of $w$&$\overline{w^{'3}}$&wp3\\\hline
Eddy-diffusivity &$K_{w}$&Kh\_zt\\\hline
Cloud water mixing ratio&$\overline{r_c}$&rcm\\\hline
Cloud fraction&cf&cloud\_frac\\\hline
\end{tabular}
\end{center}
It is only necessary to save cloud water mixing ratio from timestep to timestep
if the host model would need information on the subgrid value of that variable.
It is also necessary to provide CLUBB with information on cloud water mixing
ratio for the initial timestep of the run.  Cloud fraction is usually saved for
output purposes only.

% - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
%

\section{SILHS}

SILHS picks sample points from a joint probability distribution. In CLUBB, SILHS
is used to account for subgrid variability in physical processes such as
microphysics.

Mathematically, the goal of SILHS is to numerically approximate integrals of the
following form:
\begin{equation}
\int h(\mathbf{x}) P(\mathbf{x}) d\mathbf{x} \label{SILHS integral form}
\end{equation}
where $P(\mathbf{x})$ is the PDF that describes CLUBB's joint probability
distribution of variables, and $h(\mathbf{x})$ is a function of some or all of
these variables. In other words, we want to compute the average value of
$h(\mathbf{x})$ over the entire domain.

Briefly, SILHS performs the following tasks to numerically approximate
\eqref{SILHS integral form}:
\begin{enumerate}
\item Choose a set of uniform sample points at one vertical level. Currently,
the vertical level chosen is where cloud water is maximized. The uniform sample
is picked using the Latin hypercube algorithm in order to reduce variance.
\item Vertically correlate these uniform sample points to the other vertical
levels in CLUBB. Vertical correlation is based on the spacing between vertical
levels, CLUBB's length scale, and an emperical constant.
\item Transform the uniform sample points to CLUBB's PDF. At this point, SILHS
has produced a set of subcolumns drawn from the PDF $P(\mathbf{x})$ in
\eqref{SILHS integral form} (or, in the case of importance sampling, a related
PDF, as described below).
\item Evaluate the function $h(\mathbf{x})$ using each of the SILHS sample
points. Compute an average of these values to get an estimate of the average
value of $h(\mathbf{x})$ over the distribution.
\end{enumerate}

The following sections discuss these tasks in depth.

\subsection{CLUBB's PDF}

In CLUBB, SILHS draws sample points from CLUBB's PDF, which has the following
form.

\begin{gather}
\begin{split}
P(\mathbf{x}) = \sum_{m=1}^{N_\mathrm{comp}} \xi_{(m)}\ [\ & f_{p(m)}
 P_{(m)}(\chi,\eta,w,N_{cn},\mathbf{hm})\ + \\
& (1-f_{p(m)})\ \delta(\mathbf{hm})\ P_{(m)}(\chi,\eta,w,N_{cn})\ ]
\end{split}
\label{CLUBB PDF}
\end{gather}

The PDF has $N_\mathrm{comp}$ components; currently, in CLUBB, $N_\mathrm{comp}
= 2$. Each component $m$ has a weight $\xi_{(m)}$, where
$\sum_{m=1}^{N_\mathrm{comp}} \xi_{(m)} = 1$. In each component, a fraction
$f_{p(m)}$ of the component is allowed to contain precipitation, where $0 \le
f_{p(m)} \le 1$. The vector $\mathbf{hm}$ contains hydrometeor species (e.g.,
rain, snow). The exact type and number of hydrometeors depends on the
microphysics scheme used.

In the portions of the PDF that contain precipitation,
$P_{(m)}(\chi,\eta,w,N_{cn},\mathbf{hm})$ is a joint normal-lognormal
distribution, where $\chi$, $\eta$, and $w$ are normally distributed, and
$N_{cn}$ and all the variables in $\mathbf{hm}$ are lognormally distributed. In
the parts of the PDF that don't contain precipitation,
$P_{(m)}(\chi,\eta,w,N_{cn})$ is a joint normal-lognormal distribution, just
like before, but all the hydrometeors are zero, rather than lognormally
distributed.  ($\delta(\mathbf{hm})$ is short for
$\delta(\mathrm{hm}_1)\delta(\mathrm{hm}_2)\cdots\delta(\mathrm{hm}_n)$).

Let $d$ be the total number of variates in the PDF (the four fixed ones plus the
number of hydrometeors). The key parameters associated with \eqref{CLUBB PDF},
which must be supplied to SILHS, are:

\begin{enumerate}
\item The weight of each PDF component, $\xi_{(m)}$, and the precipitation
fraction in each component, $f_{p(m)}$.

\item $\bm{\mu}_{(m)}$: a vector of $d$ means corresponding to each variate in
the PDF, for a given PDF component. These means are ``normalized'', which means
that for the lognormal variates, the corresponding mean that appears in
$\bm{\mu}_{(m)}$ is the mean of the natural logarithm of the variate. Also,
these are in-precipitation means. This means that in the portion of the PDF that
contains precipitation, $P_{(m)}(\chi,\eta,w,N_{cn},\mathbf{hm})$ is distributed
such that each (normalized) variate has a mean given by $\bm{\mu}_{(m)}$.
Outside of precipitation, the four variates of $P_{(m)}(\chi,\eta,w,N_{cn})$
have means corresponding to $\bm{\mu}_{(m)}$, but the hydrometeors are zero, and
so have a mean of zero.

\item $\bm{\sigma}_{(m)}$: a vector of $d$ in-precipitation normalized standard
deviations for a given PDF component.

\item $\bm{\Sigma}_{(m)}$: a $d\times d$ correlation matrix, where
$\bm{\Sigma}_{(m)i,j}$ is the in-precipitation, normalized correlation between the
$i$\textsuperscript{th} and $j$\textsuperscript{th} variates (in PDF component
$m$).
\end{enumerate}

It is easy to draw sample points directly from a joint normal-lognormal
distribution. A simple way to draw sample points from \eqref{CLUBB PDF} is to
draw samples from one of the joint normal-lognormal PDFs indicated in the
equation (one of the $P_{(m)}$ functions). How often to sample from each
distribution is decided by the weights $\xi_{(m)}$ and $f_{p(m)}$. To do this,
\eqref{CLUBB PDF} can be written in terms of two new variates: $u_{d+1}$ and
$u_{d+2}$. The two variates are uniformly distributed, with $0 \le
u_{d+1},u_{d+2} \le 1$. The variate $u_{d+1}$ is used to determine the PDF
component to sample from, and $u_{d+2}$ determines whether to sample from the
portion of the PDF with precipitation. The PDF in \eqref{CLUBB PDF} can then be
written as follows:
\begin{equation}
P(\chi,\eta,w,N_{cn},\mathbf{hm},u_{d+1},u_{d+2}) =
\begin{cases}
P_{(m(u_{d+1}))}(\chi,\eta,w,N_{cn},\mathbf{hm}) & u_{d+2} < f_{p(m(u_{d+1}))}
\\ \delta(\mathbf{hm}) P_{(m(u_{d+1}))}(\chi,\eta,w,N_{cn}) & u_{d+2} \ge
f_{p(m(u_{d+1}))}
\end{cases}
\label{CLUBB PDF with uniform}
\end{equation}
where $m(u_{d+1})$ is a function that associates $u_{d+1}$ with a PDF component.
In CLUBB's two-component case, the function can simply be defined as:
\begin{equation}
m(u_{d+1}) =
\begin{cases}
1 & u_{d+1} < \xi_1 \\
2 & u_{d+1} \ge \xi_1
\end{cases}
\end{equation}

\subsection{Generation of Points in Uniform Space}

As a first step, sample points are picked from a uniform distribution. One
uniform variate is picked for each variate in the PDF.

As a variance reduction technique, SILHS employs Latin hypercube sampling. The
basic idea of this algorithm is to stratify each distribution variate into
several equally-sized regions, and ensure that each region is sampled. The
algorithm, which is described in \citet{larson2005supplying}, is implemented as
follows.

Let $N_s$ be the number of SILHS sample points used. Each of the $d+2$ uniform
variates is split into $N_s$ sections: $\left(0,\frac{1}{N_s}\right),
\left(\frac{1}{N_s},\frac{2}{N_s}\right), \ldots,
\left(\frac{N_s-1}{N_s},1\right)$. Next, for each variate, an independent
permutation of the integers $\left(0,1,\ldots,N_s-1\right)$ is chosen,
corresponding to the $N_s$ sections of the variate. These $d+2$ permutations
form a $N_s\times \left(d+2\right)$ matrix, $\bm{\Pi}$, where each column of the
matrix, $\bm{\Pi}_{\left(1\ldots N_s\right),j}$ is the permutation corresponding
to the $j$\textsuperscript{th} variate. Finally, we form another $N_s\times
\left(d+2\right)$ matrix, $\mathbf{U}$, each element of which is a random
uniform number between $0$ and $1$. The purpose of the matrix $\mathbf{U}$ is to
choose uniformly a value within each section. Our sample matrix, $\mathbf{V}$,
is then given by:
\begin{equation}
\mathbf{V} = \frac{1}{N_s}\left(\bm{\Pi} + \mathbf{U}\right)
\end{equation}

Each of the $N_s$ rows of $\mathbf{V}$ is a SILHS sample. In a given row of
$\mathbf{V}$, the value in each of the $\left(d+2\right)$ columns is the sample
value of the corresponding variate in the PDF. Note that using this method, the
association of sections between the variates is scrambled. For example, one
sample might contain a sample of one variate in the 2\textsuperscript{nd}
section and a sample of another variate in the 5\textsuperscript{th} section.

SILHS also has an option that splits a SILHS sample over multiple timesteps. To
use this feature, the user specifies an integer, $N_t$, which is an integer
multiple of $N_s$. Then, the Latin hypercube algorithm, as described above,
generates $N_t$ points instead of $N_s$ points. $N_s$ of these points are
used (without replacement) each timestep, until $\frac{N_t}{N_s}$ timesteps have
elapsed, at which point the samples are regenerated.

\subsection{Importance Sampling}

Importance sampling is another technique used in SILHS for variance reduction.
The basic idea is to sample some parts of the PDF (the ``important'' regions)
more often than they would normally be sampled.

First, the PDF is split into a set of disjoint categories, $C_j$. These
categories, which span the entire PDF, are currently defined as follows:
\begin{enumerate*}
\item In cloud, in precipitation, in mixture component 1 \\
($\chi > 0$,\quad$u_{d+2} < f_{p(1)}$,\quad$u_{d+1} < \xi_1$)
\item In cloud, in precipitation, in mixture component 2 \\
($\chi > 0$,\quad$u_{d+2} < f_{p(2)}$,\quad$u_{d+1} \ge \xi_1$)
\item Out of cloud, in precipitation, in mixture component 1 \\
($\chi \le 0$,\quad$u_{d+2} < f_{p(1)}$,\quad$u_{d+1} < \xi_1$)
\item Out of cloud, in precipitation, in mixture component 2 \\
($\chi \le 0$,\quad$u_{d+2} < f_{p(2)}$,\quad$u_{d+1} \ge \xi_1$)
\item In cloud, out of precipitation, in mixture component 1 \\
($\chi > 0$,\quad$u_{d+2} \ge f_{p(1)}$,\quad$u_{d+1} < \xi_1$)
\item In cloud, out of precipitation, in mixture component 2 \\
($\chi > 0$,\quad$u_{d+2} \ge f_{p(2)}$,\quad$u_{d+1} \ge \xi_1$)
\item Out of cloud, out of precipitation, in mixture component 1 \\
($\chi \le 0$,\quad$u_{d+2} \ge f_{p(1)}$,\quad$u_{d+1} < \xi_1$)
\item Out of cloud, out of precipitation, in mixture component 2 \\
($\chi \le 0$,\quad$u_{d+2} \ge f_{p(2)}$,\quad$u_{d+1} \ge \xi_1$)
\end{enumerate*}

Each category $C_j$ is associated with a certain amount of PDF mass, called the
category's ``PDF probability'' and denoted as:
\begin{equation}
p_j = \int \mathbf{1}_j(\mathbf{x}) P(\mathbf{x}) d\mathbf{x}
\end{equation}
where $\mathbf{1}_j(\mathbf{x})$ is the indicator function of $C_j$:
\begin{equation}
\mathbf{1}_j(\mathbf{x}) =
\begin{cases}
1 & \mathbf{x} \in C_j \\
0 & \mathbf{x} \notin C_j
\end{cases}
\end{equation}

Since the categories $C_j$ span the entire PDF, we have:
\begin{equation}
\sum_{j=1}^{N_c} p_j = 1
\end{equation}
where $N_c$ is the number of categories (currently eight in CLUBB).

It can be assumed, without loss of generality, that $p_j > 0$ for all
categories, because in any category where $p_j = 0$, the corresponding potion of
the integral in \eqref{SILHS integral form} is zero, so the region of the PDF
belonging to that category can simply be left out of the integral.

It is worth noting that in general, the PDF masses $p_j$ might not always be
easy to compute. In the case of SILHS, because of the simple definitions of the
categories (given above) and the independence of cloud and precipitation, these
masses can be computed using information already provided to SILHS. For example,
the mass of category 1, where there is cloud and precipitation in mixture
component 1, is given simply by
\begin{equation}
p_1 = f_{c(1)} f_{p(1)} \zeta_1 .
\end{equation}

Next, we prescribe for each category another probability, $S_j$, called the
category's ``prescribed probability''. The probabilities must be prescribed such
that
\begin{equation}
\sum_{j=1}^{N_c} S_j = 1
\end{equation}
The prescribed probability $S_j$ of a given category is the probability that any
sample will fall in that category. In other words, it is the expected fraction
of sample points in the category. Therefore, intuitively, it is advantageous to
prescribe the probabilities such that the categories that are ``important'' for
a desired process are sampled more often than the unimportant categories.

We want to generate sample points such that the expected fraction of sample
points in the category $C_j$ is $S_j$ rather than $p_j$. In order to do this,
we define a set of new functions:
\[ L_j(\mathbf{x}) =
   \begin{cases}
      \frac{p_j}{S_j} & \mathbf{x}\in C_j \\
      0 & \text{otherwise}
   \end{cases}
\]
We then rewrite the integral given in \eqref{SILHS integral form} as:
\begin{equation}
 \int h(\mathbf{x}) P(\mathbf{x}) d\mathbf{x} =
  \sum\limits_{j=1}^{N_c}\int h(\mathbf{x}) L_j(\mathbf{x}) Q_j(\mathbf{x})
  d\mathbf{x}
 \label{SILHS integral rewrite}
\end{equation}
where
\[Q_j(\mathbf{x}) =
   \begin{cases}
      \frac{P(\mathbf{x})}{L_j(\mathbf{x})} & \mathbf{x}\in C_j \\
      0 & \text{otherwise}
   \end{cases}
\]

Here, $Q_j(\mathbf{x})$ is a set of new ``quasi-PDFs'' that has been resized to
fit our prescribed probabililties. Each $Q_j(\mathbf{x})$ has area $S_j$ for
$j=1,...,N_c$. We can easily verify this:

\begin{align}
\int Q_j(\mathbf{x}) d\mathbf{x} &= \int_{C_j} \frac{P(\mathbf{x})}{L_j(\mathbf{x})} d\mathbf{x} \\
 &= \frac{S_j}{p_j} \int_{C_j} P(\mathbf{x}) d\mathbf{x} \\
 &= \frac{S_j}{p_j} p_j \\
 &= S_j
\end{align}

Now, instead of drawing points from the $P(\mathbf{x})$ distribution and
evaluate the function $h(\mathbf{x})$, we draw points from the $Q(\mathbf{x})$
distribution, where
\begin{equation}
Q(\mathbf{x}) = \sum_{j=1}^{N_c} Q_j(\mathbf{x})
\label{SILHS definition of Q}
\end{equation}
and evaluate the function $h(\mathbf{x}) L_j(\mathbf{x})$.

Based on the integral form given in \eqref{SILHS integral rewrite}, each sample
$h(\mathbf{x}_i)$ needs to be multiplied by $L_j(\mathbf{x}_i)$. This factor is
referred to as the sample point ``weight''. Each sample point has a weight,
denoted as:
\begin{equation}
 \omega_{i} = \sum\limits_{j=1}^{N_c} \omega_{ij}
\end{equation}
where
\begin{equation}
\omega_{ij} = L_j(\mathbf{x}_i) = \frac{p_j}{S_j}\ \mathbf{1}_j(\mathbf{x}_i)
\label{SILHS importance weights def}
\end{equation}
for $i=1,...,N_s$ and $j=1,...,N_c$.

So if $\mathbf{x}_i \in C_{j'}$ for some category $j'$, then
\begin{equation}
 \omega_{i} = \frac{p_{j'}}{S_{j'}}
\end{equation}
Thus each sample point $\mathbf{x}_i$ gets associated with the weight
$\omega_i$ that corresponds to the category that $\mathbf{x}_i$ belongs to.

\subsection{Vertical Correlation of Samples}

At this point, a collection of sample points have been generated for a single
vertical level. Each vertical level in CLUBB has its own PDF, each of the form
given in \eqref{CLUBB PDF}. In principle, we could simply repeat the above
process for every vertical level. We would generate a collection of single-level
sample points for each vertical level, and arbitrarily match the samples among
the vertical levels in order to form subcolumn samples. However, it is found
emperically that this ``random overlap'' assumption does not match what happens
in nature.

Each subcolumn physically represents a vertical column in space. It is found
that there is some degree of vertical overlap in space. That is, in many cases,
the values of sample points are similar between adjacent vertical levels.

In SILHS, this is mimiked by influencing the vertical correlation between
uniform sample points. The process is as follows. First, a vertical level,
$k_s$, is chosen to begin sampling (this variable is known as
\texttt{k\_lh\_start} in the code. Next, the vertical correlation $\rho_k$
(\texttt{vert\_corr} in code) is defined for each vertical level $k$ as:
\begin{equation}
\rho_k = \exp\left(\frac{-\alpha\ \Delta z_k}{L}\right)
\end{equation}
where $L$ is the CLUBB's length scale, $\Delta z_k$ is the vertical spacing
between grid levels at level $k$, and $\alpha$ is a parameter, known in the code
as \texttt{vert\_decorr\_coef}, that controls how correlated fields are in the
vertical. Intuitively, it can be seen that if $\alpha = 0$, then $\rho_k = 1$,
and this corresponds to maximum vertical correlation (or maximal overlap). As
$\alpha \rightarrow \infty$, $\rho_k \rightarrow 0$, and this corresponds to
zero vertical correlation (or random overlap).

The next step is to correlate each of the $d+2$ uniform sample points in the
vertical. For $1 \le k < k_s$, we set
\begin{equation}
u_{k}^{'} = u_{k+1} + u^* \left(1-\rho_k\right)
\end{equation}
where $u_{k+1}$ is the uniform sample at the height level immediately above $k$,
and $u^*$ is a uniform random number in the range $(-1,1)$. For $k_s < k \le
\texttt{nzmax}$,
\begin{equation}
u_{k}^{'} = u_{k-1} + u^* \left(1-\rho_k\right)
\end{equation}

Depending on the value of $u^*$, there is a possibility that $u_{k}^{'}$ is not
in the range $(0,1)$, and so the value might need to be folded back into the
correct range. The actual uniform variate, $u_k$, is set to be a corrected
version of $u_{k}^{'}$. Specifically,
\begin{equation}
u_k =
\begin{cases}
2 - u_{k}^{'} & u_{k}^{'} > 1 \\
| u_{k}^{'} | & u_{k}^{'} < 0 \\
u_{k}^{'} & 0 \le u_{k}^{'} \le 1
\end{cases}
\end{equation}

\subsection{Transformation to Desired Distribution}

Each sample must now be transformed to be a sample from the PDF in \eqref{CLUBB
PDF}. First, the sample values of $u_{d+1}$ and $u_{d+2}$ are used to determine
a joint normal-lognormal distribution to sample from, as in \eqref{CLUBB PDF
with uniform}. Next, the uniform values of the sample, excluding the $u_{d+1}$
and $u_{d+2}$ variates, are transformed to an uncorrelated standard normal
sample using the inverse cumulative distribution function of the standard normal
distribution:
\begin{equation}
\mathbf{Z} = \Phi^{-1} (\mathbf{u}) =
\left(
\begin{array}{c}
\Phi^{-1} (u_1) \\
\Phi^{-1} (u_2) \\
\vdots          \\
\Phi^{-1} (u_d)
\end{array}
\right)
\end{equation}

A well known result is that given a vector of uncorrelated standard normal
values, a sample following the desired joint normal distribution (say,
$\mathbf{x}_\mathrm{norm}$) can be obtained using the following formula:
\begin{equation}
\mathbf{x}_\mathrm{norm} = \mathbf{L}\mathbf{Z} + \bm{\mu}
\end{equation}
where $\mathbf{L}$ is a matrix that satisfies
\begin{equation}
\mathbf{\Sigma} = \mathbf{L} \mathbf{L}^\mathbf{T}
\end{equation}
and $\mathbf{\Sigma}$ is the covariance matrix of the joint distribution. One
way to calculate such a matrix $\mathbf{L}$ is to use an algorithm called the
Cholesky decomposition.

In SILHS, instead of the Cholesky decomposition of the covariance matrix, we
have the decomposition of the correlation matrix. The decomposition of the
covariance matrix is found by multiplying each element of each row of
correlation decomposition by the standard deviation of the associated variate.
Mathematically,
\begin{equation}
\mathbf{L} = \left(\mathbf{I}_d \bm{\sigma}\right) \mathbf{L}_\mathrm{corr}
\end{equation}
where $\mathbf{I}_d$ is the $d\times d$ identity matrix and $\bm{\sigma}$ is the
vector of standard deviations.

The last step is to transform from a joint normal distribution to a joint
normal-lognormal distribution. This can be done by applying the exponential
function to each log-normally distributed variate in the sample (while the
normally distributed variates remain the same).
\begin{equation}
\mathbf{x} =
\begin{array}{cc}
% \begin{blockarray}{cc}
% \begin{block}{(c)c}
x_{\mathrm{norm},1} & \chi \\
x_{\mathrm{norm},2} & \eta \\
x_{\mathrm{norm},3} & w \\
\exp(x_{\mathrm{norm},4}) & N_{cn} \\
\exp(x_{\mathrm{norm},5}) & \mathrm{hm}_1 \\
\vdots & \\
\exp(x_{\mathrm{norm},d}) & \mathrm{hm}_n \\
% \end{block}
% \end{blockarray}
\end{array}
\end{equation}

\subsection{Integrating over a PDF using SILHS}

When importance sampling is used, the sample points are picked according to the
distribution given by the PDF $Q(\mathbf{x})$, as defined in \eqref{SILHS
definition of Q}. The weight of each sample point, denoted as $\omega_i$, is
given in \eqref{SILHS importance weights def}. When importance sampling is not
used, the sample points are not weighted, or
\begin{equation}
\omega_i = 1
\end{equation}

Given SILHS sample points picked according to the distribution given by the
PDF $Q(\mathbf{x})$, an integral in the form of \eqref{SILHS integral form} can
be approximated using the following formulas. To integrate over the entire PDF,
use:
\begin{equation}
\int h(\mathbf{x}) P(\mathbf{x}) d\mathbf{x} \approx \frac{1}{N_s}
\sum_{i=1}^{N_s} \omega_i h(\mathbf{x}_i) \label{SILHS integral estimator}
\end{equation}
where $\mathbf{x}_i$ is the $i$\textsuperscript{th} sample point and $N_s$ is
the total number of sample points.

The estimator in \eqref{SILHS integral estimator} gives the mean of
$h(\mathbf{x})$ over the entire PDF. To determine the mean over some subset
$A$ of the PDF, the following formula should be used:
\begin{equation}
\int h(\mathbf{x})\mathbf{1}_A(\mathbf{x}) P(\mathbf{x}) d\mathbf{x}
\approx \frac{1}{N_s}\sum_{i=1}^{N_s} \omega_i
h(\mathbf{x}_i) \mathbf{1}_A(\mathbf{x}_i)
\end{equation}
However, note that this equation will implicitly be scaled by $p_A$. To
compute a normalized version of the integral, the following could be used
instead:
\begin{equation}
\frac{1}{p_A}
\int h(\mathbf{x})\mathbf{1}_A(\mathbf{x}) P(\mathbf{x}) d\mathbf{x}
\approx \frac{1}{p_A}\frac{1}{N_s}\sum_{i=1}^{N_s} \omega_i
h(\mathbf{x}_i) \mathbf{1}_A(\mathbf{x}_i)
\end{equation}

\subsection{Optimal Allocation of Sample Points}

The hope of using the importance sampling method is that our new function will
have less variance than the old one. The variance of the new function is given
by:
\begin{equation}
v = \int\left[h(\mathbf{x})L(\mathbf{x})\right]^2 Q(\mathbf{x})d\mathbf{x}
- \mu^2
\end{equation}

We can split the integral up over our importance categories.
\begin{align}
v &= \sum_{j=1}^{N_c} \left\{ \int\left[h(\mathbf{x})L(\mathbf{x})\right]^2
\mathbf{1}_j(\mathbf{x}) Q(\mathbf{x})
d\mathbf{x} \right\} - \mu^2 \\
&= \sum_{j=1}^{N_c} \left\{\left(\frac{p_j}{S_j}\right)^2
\int\left[h(\mathbf{x})\right]^2 \mathbf{1}_j(\mathbf{x})
\left(\frac{S_j}{p_j}\right) P(\mathbf{x})\ d\mathbf{x} \right\} - \mu^2 \\
&= \sum_{j=1}^{N_c} \left\{ \left(\frac{p_j}{S_j}\right)
\int\left[h(\mathbf{x})\right]^2\mathbf{1}_j(\mathbf{x}) P(\mathbf{x})\
d\mathbf{x} \right\} - \mu^2 \label{SILHS importance variance simplified}
\end{align}

It is interesting to ask how we might choose our sample probabilities $S_j$ such
that \eqref{SILHS importance variance simplified} is minimized. For convenience,
let $u_j=\int\left[h(\mathbf{x})\right]^2\mathbf{1}_j(\mathbf{x})P(\mathbf{x})\
d\mathbf{x}$. Then we write \eqref{SILHS importance variance simplified} as
\begin{equation}
v = \left(\sum_{j=1}^{N_c} \frac{p_j u_j}{S_j}\right) - \mu^2
\end{equation}
The probabilities $S_j$ must add to one, so we can write this as:
\begin{equation}
v = \left(\sum_{j=1}^{N_c-1} \frac{p_j u_j}{S_j}\right) + \frac{p_{N_c}
u_{N_c}}{1 - \sum_{j=1}^{N_c-1} S_j} - \mu^2
\end{equation}

To optimize this, we take the $N_c-1$ partial derivitives of $v$ with respect to
$S_j$ and set them all equal to zero.
\begin{gather}
\frac{\partial v}{\partial S_j} = -\frac{p_j u_j}{S_j^2} + \frac{p_{N_c}
u_{N_c}}{\left(1 - \sum_{j=1}^{N_c-1} S_j\right)^2} = 0 \\
\frac{p_j u_j}{S_j^2} = \frac{p_{N_c}
u_{N_c}}{\left(1 - \sum_{j=1}^{N_c-1} S_j\right)^2} \\
\frac{p_j u_j}{S_j^2} = \frac{p_{N_c}u_{N_c}}{S_{N_c}^2} \\
\frac{\sqrt{p_j u_j}}{S_j} = \frac{\sqrt{p_{N_c}u_{N_c}}}{S_{N_c}}
\end{gather}

So, in each category, the sample probability $S_j$ should be proportional to
$\sqrt{p_j u_j}$. If we let
\begin{equation}
\alpha = \frac{S_j}{\sqrt{p_j u_j}} \label{alpha def}
\end{equation}
and impose the constraint that the sample probabilities add to one, we have
\begin{gather}
\sum_{j=1}^{N_c} \alpha\sqrt{p_j u_j} = 1 \\
\alpha = \frac{1}{\sum_{i=j}^{N_c} \sqrt{p_j u_j}} \label{alpha solved}
\end{gather}
Substituting \eqref{alpha solved} into \eqref{alpha def}, we find that
\begin{equation}
S_j = \frac{\sqrt{p_j u_j}}{\sum_{j^*=1}^{N_c}\sqrt{p_{j^*} u_{j^*}}}
\end{equation}

% - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
%

% Bibliography
\clearpage
\bibliography{bibabbr}

\end{document}