\hypertarget{namespacemom__meke}{}\section{mom\+\_\+meke Module Reference}
\label{namespacemom__meke}\index{mom\+\_\+meke@{mom\+\_\+meke}}


Implements the Mesoscale Eddy Kinetic Energy framework with topographic beta effect included in computing beta in Rhines scale.  


\subsection*{Data Types}
\begin{DoxyCompactItemize}
\item 
type \hyperlink{structmom__meke_1_1meke__cs}{meke\+\_\+cs}
\begin{DoxyCompactList}\small\item\em Control structure that contains M\+E\+KE parameters and diagnostics handles. \end{DoxyCompactList}\end{DoxyCompactItemize}
\subsection*{Functions/\+Subroutines}
\begin{DoxyCompactItemize}
\item 
subroutine, public \hyperlink{namespacemom__meke_a5f752f097ddeba7071e1703110e51bc2}{step\+\_\+forward\+\_\+meke} (M\+E\+KE, h, S\+N\+\_\+u, S\+N\+\_\+v, visc, dt, G, GV, US, CS, hu, hv)
\begin{DoxyCompactList}\small\item\em Integrates forward-\/in-\/time the M\+E\+KE eddy energy equation. See \hyperlink{namespacemom__meke_section_MEKE_equations}{M\+E\+KE equations}. \end{DoxyCompactList}\item 
subroutine \hyperlink{namespacemom__meke_a0ef9a8bcdf705b544db9b8c28a5e6a56}{meke\+\_\+equilibrium} (CS, M\+E\+KE, G, GV, US, S\+N\+\_\+u, S\+N\+\_\+v, drag\+\_\+rate\+\_\+visc, I\+\_\+mass)
\begin{DoxyCompactList}\small\item\em Calculates the equilibrium solutino where the source depends only on M\+E\+KE diffusivity and there is no lateral diffusion of M\+E\+KE. Results is in M\+E\+KEM\+E\+KE. \end{DoxyCompactList}\item 
subroutine \hyperlink{namespacemom__meke_a843244b0cc72a08489920dcda464b063}{meke\+\_\+equilibrium\+\_\+restoring} (CS, G, US, S\+N\+\_\+u, S\+N\+\_\+v)
\item 
subroutine \hyperlink{namespacemom__meke_a8180d5d0cacf48bcbdffead9e6a06efd}{meke\+\_\+lengthscales} (CS, M\+E\+KE, G, GV, US, S\+N\+\_\+u, S\+N\+\_\+v, E\+KE, bottom\+Fac2, barotr\+Fac2, Lmix\+Scale)
\begin{DoxyCompactList}\small\item\em Calculates the eddy mixing length scale and $\gamma_b$ and $\gamma_t$ functions that are ratios of either bottom or barotropic eddy energy to the column eddy energy, respectively. See \hyperlink{namespacemom__meke_section_MEKE_equations}{M\+E\+KE equations}. \end{DoxyCompactList}\item 
subroutine \hyperlink{namespacemom__meke_aed5885cde342caa59b2b9cde72a3e1e7}{meke\+\_\+lengthscales\+\_\+0d} (CS, US, area, beta, depth, Rd\+\_\+dx, SN, E\+KE, bottom\+Fac2, barotr\+Fac2, Lmix\+Scale, Lrhines, Leady)
\begin{DoxyCompactList}\small\item\em Calculates the eddy mixing length scale and $\gamma_b$ and $\gamma_t$ functions that are ratios of either bottom or barotropic eddy energy to the column eddy energy, respectively. See \hyperlink{namespacemom__meke_section_MEKE_equations}{M\+E\+KE equations}. \end{DoxyCompactList}\item 
logical function, public \hyperlink{namespacemom__meke_a099f1cfad37430ef1bd60972a92b1be4}{meke\+\_\+init} (Time, G, US, param\+\_\+file, diag, CS, M\+E\+KE, restart\+\_\+\+CS)
\begin{DoxyCompactList}\small\item\em Initializes the M\+O\+M\+\_\+\+M\+E\+KE module and reads parameters. Returns True if module is to be used, otherwise returns False. \end{DoxyCompactList}\item 
subroutine, public \hyperlink{namespacemom__meke_a1900316331157e48f1a6029bac63fbd0}{meke\+\_\+alloc\+\_\+register\+\_\+restart} (HI, param\+\_\+file, M\+E\+KE, restart\+\_\+\+CS)
\begin{DoxyCompactList}\small\item\em Allocates memory and register restart fields for the M\+O\+M\+\_\+\+M\+E\+KE module. \end{DoxyCompactList}\item 
subroutine, public \hyperlink{namespacemom__meke_acc007bf1aa24263f699b059d3e9cc6eb}{meke\+\_\+end} (M\+E\+KE, CS)
\begin{DoxyCompactList}\small\item\em Deallocates any variables allocated in M\+E\+K\+E\+\_\+init or M\+E\+K\+E\+\_\+alloc\+\_\+register\+\_\+restart. \end{DoxyCompactList}\end{DoxyCompactItemize}


\subsection{Detailed Description}
Implements the Mesoscale Eddy Kinetic Energy framework with topographic beta effect included in computing beta in Rhines scale. 

\hypertarget{namespacemom__meke_section_MEKE}{}\subsection{The Mesoscale Eddy Kinetic Energy (\+M\+E\+K\+E) framework}\label{namespacemom__meke_section_MEKE}
The M\+E\+KE framework accounts for the mean potential energy removed by the first order closures used to parameterize mesoscale eddies. It requires closure at the second order, namely dissipation and transport of eddy energy.

Monitoring the sub-\/grid scale eddy energy budget provides a means to predict a sub-\/grid eddy-\/velocity scale which can be used in the lower order closures.\hypertarget{namespacemom__meke_section_MEKE_equations}{}\subsubsection{M\+E\+K\+E equations}\label{namespacemom__meke_section_MEKE_equations}
The eddy kinetic energy equation is\+: \[ \partial_{\tilde{t}} E = \overbrace{ \dot{E}_b + \gamma_\eta \dot{E}_\eta + \gamma_v \dot{E}_v }^\text{sources} - \overbrace{ ( \lambda + C_d | U_d | \gamma_b^2 ) E }^\text{local dissipation} + \overbrace{ \nabla \cdot ( ( \kappa_E + \gamma_M \kappa_M ) \nabla E - \kappa_4 \nabla^3 E ) }^\text{smoothing} \] where $ E $ is the eddy kinetic energy (variable {\ttfamily M\+E\+KE}) with units of m\textsuperscript{2}s\textsuperscript{-\/2}, and $\tilde{t} = a t$ is a scaled time. The non-\/dimensional factor $ a\geq 1 $ is used to accelerate towards equilibrium.

The M\+E\+KE equation is two-\/dimensional and obtained by depth averaging the the three-\/dimensional eddy energy equation. In the following expressions $ \left< \phi \right> = \frac{1}{H} \int^\eta_{-D} \phi \, dz $ maps three dimensional terms into the two-\/dimensional quantities needed.\hypertarget{namespacemom__meke_section_MEKE_source_terms}{}\paragraph{M\+E\+K\+E source terms}\label{namespacemom__meke_section_MEKE_source_terms}
The source term $ \dot{E}_b $ is a constant background source of energy intended to avoid the limit $E\rightarrow 0$.

The \char`\"{}\+G\+M\char`\"{} source term \[ \dot{E}_\eta = - \left< \overline{w^\prime b^\prime} \right> = \left< \kappa_h N^2S^2 \right> \approx \left< \kappa_h g\prime |\nabla_\sigma \eta|^2 \right>\] equals the mean potential energy removed by the Gent-\/\+Mc\+Williams closure, and is excluded/included in the M\+E\+KE budget by the efficiency parameter $ \gamma_\eta \in [0,1] $.

The \char`\"{}frictional\char`\"{} source term \[ \dot{E}_{v} = \left< \partial_i u_j \tau_{ij} \right> \] equals the mean kinetic energy removed by lateral viscous fluxes, and is excluded/included in the M\+E\+KE budget by the efficiency parameter $ \gamma_v \in [0,1] $.\hypertarget{namespacemom__meke_section_MEKE_dissipation_terms}{}\paragraph{M\+E\+K\+E dissipation terms}\label{namespacemom__meke_section_MEKE_dissipation_terms}
The local dissipation of $ E $ is parameterized through a linear damping, $\lambda$, and bottom drag, $ C_d | U_d | \gamma_b^2 $. The $ \gamma_b $ accounts for the weak projection of the column-\/mean eddy velocty to the bottom. In other words, the bottom velocity is estimated as $ \gamma_b U_e $. The bottom drag coefficient, $ C_d $ is the same as that used in the bottom friction in the mean model equations.

The bottom drag velocity scale, $ U_d $, has contributions from the resolved state and $ E $\+: \[ U_d = \sqrt{ U_b^2 + |u|^2_{z=-D} + |\gamma_b U_e|^2 } .\] where the eddy velocity scale, $ U_e $, is given by\+: \[ U_e = \sqrt{ 2 E } .\] $ U_b $ is a constant background bottom velocity scale and is typically not used (i.\+e. set to zero).

Following Jansen et al., 2015, the projection of eddy energy on to the bottom is given by the ratio of bottom energy to column mean energy\+: \[ \gamma_b^2 = \frac{E_b}{E} = \gamma_{d0} + \left( 1 + c_{b} \frac{L_d}{L_f} \right)^{-\frac{4}{5}} , \] \[ \gamma_b^2 \leftarrow \max{\left( \gamma_b^2, \gamma_{min}^2 \right)} . \]\hypertarget{namespacemom__meke_section_MEKE_smoothing}{}\subsubsection{M\+E\+K\+E smoothing terms}\label{namespacemom__meke_section_MEKE_smoothing}
$ E $ is laterally diffused by a diffusivity $ \kappa_E + \gamma_M \kappa_M $ where $ \kappa_E $ is a constant diffusivity and the term $ \gamma_M \kappa_M $ is a \char`\"{}self diffusion\char`\"{} using the diffusivity calculated in the section \hyperlink{namespacemom__meke_section_MEKE_diffusivity}{Diffusivity derived from M\+E\+KE}. $ \kappa_4 $ is a constant bi-\/harmonic diffusivity.\hypertarget{namespacemom__meke_section_MEKE_diffusivity}{}\subsubsection{Diffusivity derived from M\+E\+KE}\label{namespacemom__meke_section_MEKE_diffusivity}
The predicted eddy velocity scale, $ U_e $, can be combined with a mixing length scale to form a diffusivity. The primary use of a M\+E\+KE derived diffusivity is for use in thickness diffusion (module mom\+\_\+thickness\+\_\+diffuse) and optionally in along isopycnal mixing of tracers (module mom\+\_\+tracer\+\_\+hor\+\_\+diff). The original form used (enabled with M\+E\+K\+E\+\_\+\+O\+L\+D\+\_\+\+L\+S\+C\+A\+LE=True)\+:

\[ \kappa_M = \gamma_\kappa \sqrt{ \gamma_t^2 U_e^2 A_\Delta } \]

where $ A_\Delta $ is the area of the grid cell. Following Jansen et al., 2015, we now use

\[ \kappa_M = \gamma_\kappa l_M \sqrt{ \gamma_t^2 U_e^2 } \]

where $ \gamma_\kappa \in [0,1] $ is a non-\/dimensional factor and, following Jansen et al., 2015, $\gamma_t^2$ is the ratio of barotropic eddy energy to column mean eddy energy given by \[ \gamma_t^2 = \frac{E_t}{E} = \left( 1 + c_{t} \frac{L_d}{L_f} \right)^{-\frac{1}{4}} , \] \[ \gamma_t^2 \leftarrow \max{\left( \gamma_t^2, \gamma_{min}^2 \right)} . \]

The length-\/scale is a configurable combination of multiple length scales\+:

\[ l_M = \left( \frac{\alpha_d}{L_d} + \frac{\alpha_f}{L_f} + \frac{\alpha_R}{L_R} + \frac{\alpha_e}{L_e} + \frac{\alpha_\Delta}{L_\Delta} + \frac{\delta[L_c]}{L_c} \right)^{-1} \]

where

\begin{eqnarray*} L_d & = & \sqrt{\frac{c_g^2}{f^2+2\beta c_g}} \sim \frac{ c_g }{f} \\\\ L_R & = & \sqrt{\frac{U_e}{\beta^*}} \\\\ L_e & = & \frac{U_e}{|S| N} \\\\ L_f & = & \frac{H}{c_d} \\\\ L_\Delta & = & \sqrt{A_\Delta} . \end{eqnarray*}

$L_c$ is a constant and $\delta[L_c]$ is the impulse function so that the term $\frac{\delta[L_c]}{L_c}$ evaluates to $\frac{1}{L_c}$ when $L_c$ is non-\/zero but is dropped if $L_c=0$.

$\beta^*$ is the effective $\beta$ that combines both the planetary vorticity gradient (i.\+e. $\beta=\nabla f$) and the topographic $\beta$ effect, with the latter weighed by a weighting constant, $c_\beta$, that varies from 0 to 1, so that $c_\beta=0$ means the topographic $\beta$ effect is ignored, while $c_\beta=1$ means it is fully considered. The new $\beta^*$ therefore takes the form of

\[ \beta^* = \sqrt{( \partial_xf - c_\beta\frac{f}{D}\partial_xD )^2 + ( \partial_yf - c_\beta\frac{f}{D}\partial_yD )^2} \] where $D$ is water column depth at T points.\hypertarget{namespacemom__meke_section_MEKE_viscosity}{}\subsubsection{Viscosity derived from M\+E\+KE}\label{namespacemom__meke_section_MEKE_viscosity}
As for $ \kappa_M $, the predicted eddy velocity scale can be used to form a harmonic eddy viscosity,

\[ \kappa_u = \gamma_u \sqrt{ U_e^2 A_\Delta } \]

as well as a biharmonic eddy viscosity,

\[ \kappa_4 = \gamma_4 \sqrt{ U_e^2 A_\Delta^3 } \]\hypertarget{namespacemom__meke_section_MEKE_limit_case}{}\subsubsection{Limit cases for local source-\/dissipative balance}\label{namespacemom__meke_section_MEKE_limit_case}
Note that in steady-\/state (or when $ a>>1 $) and there is no diffusion of $ E $ then \[ \overline{E} \approx \frac{ \dot{E}_b + \gamma_\eta \dot{E}_\eta + \gamma_v \dot{E}_v }{ \lambda + C_d|U_d|\gamma_b^2 } . \]

In the linear drag limit, where $ U_e << \min(U_b, |u|_{z=-D}, C_d^{-1}\lambda) $, the equilibrium becomes $ \overline{E} \approx \frac{ \dot{E}_b + \gamma_\eta \dot{E}_\eta + \gamma_v \dot{E}_v }{ \lambda + C_d \sqrt{ U_b^2 + |u|^2_{z=-D} } } $.

In the nonlinear drag limit, where $ U_e >> \max(U_b, |u|_{z=-D}, C_d^{-1}\lambda) $, the equilibrium becomes $ \overline{E} \approx \left( \frac{ \dot{E}_b + \gamma_\eta \dot{E}_\eta + \gamma_v \dot{E}_v }{ \sqrt{2} C_d \gamma_b^3 } \right)^\frac{2}{3} $.\hypertarget{namespacemom__meke_section_MEKE_module_parameters}{}\paragraph{M\+E\+K\+E module parameters}\label{namespacemom__meke_section_MEKE_module_parameters}
\tabulinesep=1mm
\begin{longtabu} spread 0pt [c]{*{2}{|X[-1]}|}
\hline
\rowcolor{\tableheadbgcolor}\textbf{ Symbol }&\textbf{ Module parameter  }\\\cline{1-2}
\endfirsthead
\hline
\endfoot
\hline
\rowcolor{\tableheadbgcolor}\textbf{ Symbol }&\textbf{ Module parameter  }\\\cline{1-2}
\endhead
-\/ &{\ttfamily U\+S\+E\+\_\+\+M\+E\+KE} \\\cline{1-2}
$ a $ &{\ttfamily M\+E\+K\+E\+\_\+\+D\+T\+S\+C\+A\+LE} \\\cline{1-2}
$ \dot{E}_b $ &{\ttfamily M\+E\+K\+E\+\_\+\+B\+G\+S\+RC} \\\cline{1-2}
$ \gamma_\eta $ &{\ttfamily M\+E\+K\+E\+\_\+\+G\+M\+C\+O\+E\+FF} \\\cline{1-2}
$ \gamma_v $ &{\ttfamily M\+E\+K\+E\+\_\+\+Fr\+C\+O\+E\+FF} \\\cline{1-2}
$ \lambda $ &{\ttfamily M\+E\+K\+E\+\_\+\+D\+A\+M\+P\+I\+NG} \\\cline{1-2}
$ U_b $ &{\ttfamily M\+E\+K\+E\+\_\+\+U\+S\+C\+A\+LE} \\\cline{1-2}
$ \gamma_{d0} $ &{\ttfamily M\+E\+K\+E\+\_\+\+C\+D\+\_\+\+S\+C\+A\+LE} \\\cline{1-2}
$ c_{b} $ &{\ttfamily M\+E\+K\+E\+\_\+\+CB} \\\cline{1-2}
$ c_{t} $ &{\ttfamily M\+E\+K\+E\+\_\+\+CT} \\\cline{1-2}
$ \kappa_E $ &{\ttfamily M\+E\+K\+E\+\_\+\+KH} \\\cline{1-2}
$ \kappa_4 $ &{\ttfamily M\+E\+K\+E\+\_\+\+K4} \\\cline{1-2}
$ \gamma_\kappa $ &{\ttfamily M\+E\+K\+E\+\_\+\+K\+H\+C\+O\+E\+FF} \\\cline{1-2}
$ \gamma_M $ &{\ttfamily M\+E\+K\+E\+\_\+\+K\+H\+M\+E\+K\+E\+\_\+\+F\+AC} \\\cline{1-2}
$ \gamma_u $ &{\ttfamily M\+E\+K\+E\+\_\+\+V\+I\+S\+C\+O\+S\+I\+T\+Y\+\_\+\+C\+O\+E\+F\+F\+\_\+\+KU} \\\cline{1-2}
$ \gamma_4 $ &{\ttfamily M\+E\+K\+E\+\_\+\+V\+I\+S\+C\+O\+S\+I\+T\+Y\+\_\+\+C\+O\+E\+F\+F\+\_\+\+AU} \\\cline{1-2}
$ \gamma_{min}^2 $&{\ttfamily M\+E\+K\+E\+\_\+\+M\+I\+N\+\_\+\+G\+A\+M\+M\+A2} \\\cline{1-2}
$ \alpha_d $ &{\ttfamily M\+E\+K\+E\+\_\+\+A\+L\+P\+H\+A\+\_\+\+D\+E\+F\+O\+RM} \\\cline{1-2}
$ \alpha_f $ &{\ttfamily M\+E\+K\+E\+\_\+\+A\+L\+P\+H\+A\+\_\+\+F\+R\+I\+CT} \\\cline{1-2}
$ \alpha_R $ &{\ttfamily M\+E\+K\+E\+\_\+\+A\+L\+P\+H\+A\+\_\+\+R\+H\+I\+N\+ES} \\\cline{1-2}
$ \alpha_e $ &{\ttfamily M\+E\+K\+E\+\_\+\+A\+L\+P\+H\+A\+\_\+\+E\+A\+DY} \\\cline{1-2}
$ \alpha_\Delta $ &{\ttfamily M\+E\+K\+E\+\_\+\+A\+L\+P\+H\+A\+\_\+\+G\+R\+ID} \\\cline{1-2}
$ L_c $ &{\ttfamily M\+E\+K\+E\+\_\+\+F\+I\+X\+E\+D\+\_\+\+M\+I\+X\+I\+N\+G\+\_\+\+L\+E\+N\+G\+TH} \\\cline{1-2}
$ c_\beta $ &{\ttfamily M\+E\+K\+E\+\_\+\+T\+O\+P\+O\+G\+R\+A\+P\+H\+I\+C\+\_\+\+B\+E\+TA} \\\cline{1-2}
-\/ &{\ttfamily M\+E\+K\+E\+\_\+\+K\+H\+T\+H\+\_\+\+F\+AC} \\\cline{1-2}
-\/ &{\ttfamily M\+E\+K\+E\+\_\+\+K\+H\+T\+R\+\_\+\+F\+AC} \\\cline{1-2}
\end{longtabu}
\tabulinesep=1mm
\begin{longtabu} spread 0pt [c]{*{2}{|X[-1]}|}
\hline
\rowcolor{\tableheadbgcolor}\textbf{ Symbol }&\textbf{ Model parameter  }\\\cline{1-2}
\endfirsthead
\hline
\endfoot
\hline
\rowcolor{\tableheadbgcolor}\textbf{ Symbol }&\textbf{ Model parameter  }\\\cline{1-2}
\endhead
$ C_d $ &{\ttfamily C\+D\+R\+AG} \\\cline{1-2}
\end{longtabu}
\hypertarget{namespacemom__meke_section_MEKE_references}{}\subsubsection{References}\label{namespacemom__meke_section_MEKE_references}
Jansen, M. F., A. J. Adcroft, R. Hallberg, and I. M. Held, 2015\+: Parameterization of eddy fluxes based on a mesoscale energy budget. Ocean Modelling, 92, 28--41, \href{http://doi.org/10.1016/j.ocemod.2015.05.007}{\tt http\+://doi.\+org/10.\+1016/j.\+ocemod.\+2015.\+05.\+007} .

Marshall, D. P., and A. J. Adcroft, 2010\+: Parameterization of ocean eddies\+: Potential vorticity mixing, energetics and Arnold first stability theorem. Ocean Modelling, 32, 188--204, \href{http://doi.org/10.1016/j.ocemod.2010.02.001}{\tt http\+://doi.\+org/10.\+1016/j.\+ocemod.\+2010.\+02.\+001} . 

\subsection{Function/\+Subroutine Documentation}
\mbox{\Hypertarget{namespacemom__meke_a1900316331157e48f1a6029bac63fbd0}\label{namespacemom__meke_a1900316331157e48f1a6029bac63fbd0}} 
\index{mom\+\_\+meke@{mom\+\_\+meke}!meke\+\_\+alloc\+\_\+register\+\_\+restart@{meke\+\_\+alloc\+\_\+register\+\_\+restart}}
\index{meke\+\_\+alloc\+\_\+register\+\_\+restart@{meke\+\_\+alloc\+\_\+register\+\_\+restart}!mom\+\_\+meke@{mom\+\_\+meke}}
\subsubsection{\texorpdfstring{meke\+\_\+alloc\+\_\+register\+\_\+restart()}{meke\_alloc\_register\_restart()}}
{\footnotesize\ttfamily subroutine, public mom\+\_\+meke\+::meke\+\_\+alloc\+\_\+register\+\_\+restart (\begin{DoxyParamCaption}\item[{type(hor\+\_\+index\+\_\+type), intent(in)}]{HI,  }\item[{type(param\+\_\+file\+\_\+type), intent(in)}]{param\+\_\+file,  }\item[{type(meke\+\_\+type), pointer}]{M\+E\+KE,  }\item[{type(mom\+\_\+restart\+\_\+cs), pointer}]{restart\+\_\+\+CS }\end{DoxyParamCaption})}



Allocates memory and register restart fields for the M\+O\+M\+\_\+\+M\+E\+KE module. 


\begin{DoxyParams}[1]{Parameters}
\mbox{\tt in}  & {\em hi} & Horizontal index structure\\
\hline
\mbox{\tt in}  & {\em param\+\_\+file} & Parameter file parser structure.\\
\hline
 & {\em meke} & A structure with M\+E\+K\+E-\/related fields.\\
\hline
 & {\em restart\+\_\+cs} & Restart control structure for M\+O\+M\+\_\+\+M\+E\+KE. \\
\hline
\end{DoxyParams}


Definition at line \hyperlink{MOM__MEKE_8F90_source_l01347}{1347} of file \hyperlink{MOM__MEKE_8F90_source}{M\+O\+M\+\_\+\+M\+E\+K\+E.\+F90}.


\begin{DoxyCode}
01347 \textcolor{comment}{! Arguments}
01348   \textcolor{keywordtype}{type}(hor\_index\_type),  \textcolor{keywordtype}{intent(in)}    :: hi\textcolor{comment}{         !< Horizontal index structure}
01349   \textcolor{keywordtype}{type}(param\_file\_type), \textcolor{keywordtype}{intent(in)}    :: param\_file\textcolor{comment}{ !< Parameter file parser structure.}
01350   \textcolor{keywordtype}{type}(meke\_type),       \textcolor{keywordtype}{pointer}       :: meke\textcolor{comment}{       !< A structure with MEKE-related fields.}
01351   \textcolor{keywordtype}{type}(mom\_restart\_cs),  \textcolor{keywordtype}{pointer}       :: restart\_cs\textcolor{comment}{ !< Restart control structure for MOM\_MEKE.}
01352 \textcolor{comment}{! Local variables}
01353   \textcolor{keywordtype}{type}(vardesc) :: vd
01354   \textcolor{keywordtype}{real} :: meke\_gmcoeff, meke\_frcoeff, meke\_gmecoeff, meke\_khcoeff, meke\_visccoeff\_ku, meke\_visccoeff\_au
01355   \textcolor{keywordtype}{logical} :: use\_kh\_in\_meke
01356   \textcolor{keywordtype}{logical} :: usemeke
01357   \textcolor{keywordtype}{integer} :: isd, ied, jsd, jed
01358 
01359 \textcolor{comment}{! Determine whether this module will be used}
01360   usemeke = .false.; \textcolor{keyword}{call }read\_param(param\_file,\textcolor{stringliteral}{"USE\_MEKE"},usemeke)
01361 
01362 \textcolor{comment}{! Read these parameters to determine what should be in the restarts}
01363   meke\_gmcoeff =-1.; \textcolor{keyword}{call }read\_param(param\_file,\textcolor{stringliteral}{"MEKE\_GMCOEFF"},meke\_gmcoeff)
01364   meke\_frcoeff =-1.; \textcolor{keyword}{call }read\_param(param\_file,\textcolor{stringliteral}{"MEKE\_FRCOEFF"},meke\_frcoeff)
01365   meke\_gmecoeff =-1.; \textcolor{keyword}{call }read\_param(param\_file,\textcolor{stringliteral}{"MEKE\_GMECOEFF"},meke\_gmecoeff)
01366   meke\_khcoeff =1.; \textcolor{keyword}{call }read\_param(param\_file,\textcolor{stringliteral}{"MEKE\_KHCOEFF"},meke\_khcoeff)
01367   meke\_visccoeff\_ku =0.; \textcolor{keyword}{call }read\_param(param\_file,\textcolor{stringliteral}{"MEKE\_VISCOSITY\_COEFF\_KU"},meke\_visccoeff\_ku)
01368   meke\_visccoeff\_au =0.; \textcolor{keyword}{call }read\_param(param\_file,\textcolor{stringliteral}{"MEKE\_VISCOSITY\_COEFF\_AU"},meke\_visccoeff\_au)
01369   use\_kh\_in\_meke = .false.; \textcolor{keyword}{call }read\_param(param\_file,\textcolor{stringliteral}{"USE\_KH\_IN\_MEKE"}, use\_kh\_in\_meke)
01370 \textcolor{comment}{! Allocate control structure}
01371   \textcolor{keywordflow}{if} (\textcolor{keyword}{associated}(meke)) \textcolor{keywordflow}{then}
01372     \textcolor{keyword}{call }mom\_error(warning, \textcolor{stringliteral}{"MEKE\_alloc\_register\_restart called with an associated "}// &
01373                              \textcolor{stringliteral}{"MEKE type."})
01374     \textcolor{keywordflow}{return}
01375   else; \textcolor{keyword}{allocate}(meke);\textcolor{keywordflow}{ endif}
01376 
01377   \textcolor{keywordflow}{if} (.not. usemeke) \textcolor{keywordflow}{return}
01378 
01379 \textcolor{comment}{! Allocate memory}
01380   \textcolor{keyword}{call }mom\_mesg(\textcolor{stringliteral}{"MEKE\_alloc\_register\_restart: allocating and registering"}, 5)
01381   isd = hi%isd ; ied = hi%ied ; jsd = hi%jsd ; jed = hi%jed
01382   \textcolor{keyword}{allocate}(meke%MEKE(isd:ied,jsd:jed)) ; meke%MEKE(:,:) = 0.0
01383   vd = var\_desc(\textcolor{stringliteral}{"MEKE"}, \textcolor{stringliteral}{"m2 s-2"}, hor\_grid=\textcolor{stringliteral}{'h'}, z\_grid=\textcolor{stringliteral}{'1'}, &
01384            longname=\textcolor{stringliteral}{"Mesoscale Eddy Kinetic Energy"})
01385   \textcolor{keyword}{call }register\_restart\_field(meke%MEKE, vd, .false., restart\_cs)
01386   \textcolor{keywordflow}{if} (meke\_gmcoeff>=0.) \textcolor{keywordflow}{then}
01387     \textcolor{keyword}{allocate}(meke%GM\_src(isd:ied,jsd:jed)) ; meke%GM\_src(:,:) = 0.0
01388 \textcolor{keywordflow}{  endif}
01389   \textcolor{keywordflow}{if} (meke\_frcoeff>=0. .or. meke\_gmecoeff>=0.)  \textcolor{keywordflow}{then}
01390     \textcolor{keyword}{allocate}(meke%mom\_src(isd:ied,jsd:jed)) ; meke%mom\_src(:,:) = 0.0
01391 \textcolor{keywordflow}{  endif}
01392   \textcolor{keywordflow}{if} (meke\_gmecoeff>=0.) \textcolor{keywordflow}{then}
01393     \textcolor{keyword}{allocate}(meke%GME\_snk(isd:ied,jsd:jed)) ; meke%GME\_snk(:,:) = 0.0
01394 \textcolor{keywordflow}{  endif}
01395   \textcolor{keywordflow}{if} (meke\_khcoeff>=0.) \textcolor{keywordflow}{then}
01396     \textcolor{keyword}{allocate}(meke%Kh(isd:ied,jsd:jed)) ; meke%Kh(:,:) = 0.0
01397     vd = var\_desc(\textcolor{stringliteral}{"MEKE\_Kh"}, \textcolor{stringliteral}{"m2 s-1"}, hor\_grid=\textcolor{stringliteral}{'h'}, z\_grid=\textcolor{stringliteral}{'1'}, &
01398              longname=\textcolor{stringliteral}{"Lateral diffusivity from Mesoscale Eddy Kinetic Energy"})
01399     \textcolor{keyword}{call }register\_restart\_field(meke%Kh, vd, .false., restart\_cs)
01400 \textcolor{keywordflow}{  endif}
01401   \textcolor{keyword}{allocate}(meke%Rd\_dx\_h(isd:ied,jsd:jed)) ; meke%Rd\_dx\_h(:,:) = 0.0
01402   \textcolor{keywordflow}{if} (meke\_visccoeff\_ku/=0.) \textcolor{keywordflow}{then}
01403     \textcolor{keyword}{allocate}(meke%Ku(isd:ied,jsd:jed)) ; meke%Ku(:,:) = 0.0
01404     vd = var\_desc(\textcolor{stringliteral}{"MEKE\_Ku"}, \textcolor{stringliteral}{"m2 s-1"}, hor\_grid=\textcolor{stringliteral}{'h'}, z\_grid=\textcolor{stringliteral}{'1'}, &
01405              longname=\textcolor{stringliteral}{"Lateral viscosity from Mesoscale Eddy Kinetic Energy"})
01406     \textcolor{keyword}{call }register\_restart\_field(meke%Ku, vd, .false., restart\_cs)
01407 \textcolor{keywordflow}{  endif}
01408   \textcolor{keywordflow}{if} (use\_kh\_in\_meke) \textcolor{keywordflow}{then}
01409     \textcolor{keyword}{allocate}(meke%Kh\_diff(isd:ied,jsd:jed)) ; meke%Kh\_diff(:,:) = 0.0
01410     vd = var\_desc(\textcolor{stringliteral}{"MEKE\_Kh\_diff"}, \textcolor{stringliteral}{"m2 s-1"},hor\_grid=\textcolor{stringliteral}{'h'},z\_grid=\textcolor{stringliteral}{'1'}, &
01411              longname=\textcolor{stringliteral}{"Copy of thickness diffusivity for diffusing MEKE"})
01412     \textcolor{keyword}{call }register\_restart\_field(meke%Kh\_diff, vd, .false., restart\_cs)
01413 \textcolor{keywordflow}{  endif}
01414 
01415   \textcolor{keywordflow}{if} (meke\_visccoeff\_au/=0.) \textcolor{keywordflow}{then}
01416     \textcolor{keyword}{allocate}(meke%Au(isd:ied,jsd:jed)) ; meke%Au(:,:) = 0.0
01417     vd = var\_desc(\textcolor{stringliteral}{"MEKE\_Au"}, \textcolor{stringliteral}{"m4 s-1"}, hor\_grid=\textcolor{stringliteral}{'h'}, z\_grid=\textcolor{stringliteral}{'1'}, &
01418              longname=\textcolor{stringliteral}{"Lateral biharmonic viscosity from Mesoscale Eddy Kinetic Energy"})
01419     \textcolor{keyword}{call }register\_restart\_field(meke%Au, vd, .false., restart\_cs)
01420 \textcolor{keywordflow}{  endif}
01421 
\end{DoxyCode}
\mbox{\Hypertarget{namespacemom__meke_acc007bf1aa24263f699b059d3e9cc6eb}\label{namespacemom__meke_acc007bf1aa24263f699b059d3e9cc6eb}} 
\index{mom\+\_\+meke@{mom\+\_\+meke}!meke\+\_\+end@{meke\+\_\+end}}
\index{meke\+\_\+end@{meke\+\_\+end}!mom\+\_\+meke@{mom\+\_\+meke}}
\subsubsection{\texorpdfstring{meke\+\_\+end()}{meke\_end()}}
{\footnotesize\ttfamily subroutine, public mom\+\_\+meke\+::meke\+\_\+end (\begin{DoxyParamCaption}\item[{type(meke\+\_\+type), pointer}]{M\+E\+KE,  }\item[{type(\hyperlink{structmom__meke_1_1meke__cs}{meke\+\_\+cs}), pointer}]{CS }\end{DoxyParamCaption})}



Deallocates any variables allocated in M\+E\+K\+E\+\_\+init or M\+E\+K\+E\+\_\+alloc\+\_\+register\+\_\+restart. 


\begin{DoxyParams}{Parameters}
{\em meke} & A structure with M\+E\+K\+E-\/related fields.\\
\hline
{\em cs} & The control structure for M\+O\+M\+\_\+\+M\+E\+KE. \\
\hline
\end{DoxyParams}


Definition at line \hyperlink{MOM__MEKE_8F90_source_l01427}{1427} of file \hyperlink{MOM__MEKE_8F90_source}{M\+O\+M\+\_\+\+M\+E\+K\+E.\+F90}.


\begin{DoxyCode}
01427   \textcolor{keywordtype}{type}(meke\_type), \textcolor{keywordtype}{pointer} :: meke\textcolor{comment}{ !< A structure with MEKE-related fields.}
01428   \textcolor{keywordtype}{type}(meke\_cs),   \textcolor{keywordtype}{pointer} :: cs\textcolor{comment}{   !< The control structure for MOM\_MEKE.}
01429 
01430   \textcolor{keywordflow}{if} (\textcolor{keyword}{associated}(cs)) \textcolor{keyword}{deallocate}(cs)
01431 
01432   \textcolor{keywordflow}{if} (.not.\textcolor{keyword}{associated}(meke)) \textcolor{keywordflow}{return}
01433 
01434   \textcolor{keywordflow}{if} (\textcolor{keyword}{associated}(meke%MEKE)) \textcolor{keyword}{deallocate}(meke%MEKE)
01435   \textcolor{keywordflow}{if} (\textcolor{keyword}{associated}(meke%GM\_src)) \textcolor{keyword}{deallocate}(meke%GM\_src)
01436   \textcolor{keywordflow}{if} (\textcolor{keyword}{associated}(meke%mom\_src)) \textcolor{keyword}{deallocate}(meke%mom\_src)
01437   \textcolor{keywordflow}{if} (\textcolor{keyword}{associated}(meke%GME\_snk)) \textcolor{keyword}{deallocate}(meke%GME\_snk)
01438   \textcolor{keywordflow}{if} (\textcolor{keyword}{associated}(meke%Kh)) \textcolor{keyword}{deallocate}(meke%Kh)
01439   \textcolor{keywordflow}{if} (\textcolor{keyword}{associated}(meke%Kh\_diff)) \textcolor{keyword}{deallocate}(meke%Kh\_diff)
01440   \textcolor{keywordflow}{if} (\textcolor{keyword}{associated}(meke%Ku)) \textcolor{keyword}{deallocate}(meke%Ku)
01441   \textcolor{keywordflow}{if} (\textcolor{keyword}{associated}(meke%Au)) \textcolor{keyword}{deallocate}(meke%Au)
01442   \textcolor{keyword}{deallocate}(meke)
01443 
\end{DoxyCode}
\mbox{\Hypertarget{namespacemom__meke_a0ef9a8bcdf705b544db9b8c28a5e6a56}\label{namespacemom__meke_a0ef9a8bcdf705b544db9b8c28a5e6a56}} 
\index{mom\+\_\+meke@{mom\+\_\+meke}!meke\+\_\+equilibrium@{meke\+\_\+equilibrium}}
\index{meke\+\_\+equilibrium@{meke\+\_\+equilibrium}!mom\+\_\+meke@{mom\+\_\+meke}}
\subsubsection{\texorpdfstring{meke\+\_\+equilibrium()}{meke\_equilibrium()}}
{\footnotesize\ttfamily subroutine mom\+\_\+meke\+::meke\+\_\+equilibrium (\begin{DoxyParamCaption}\item[{type(\hyperlink{structmom__meke_1_1meke__cs}{meke\+\_\+cs}), pointer}]{CS,  }\item[{type(meke\+\_\+type), pointer}]{M\+E\+KE,  }\item[{type(ocean\+\_\+grid\+\_\+type), intent(inout)}]{G,  }\item[{type(verticalgrid\+\_\+type), intent(in)}]{GV,  }\item[{type(unit\+\_\+scale\+\_\+type), intent(in)}]{US,  }\item[{real, dimension( g \%isdb\+: g \%iedb, g \%jsd\+: g \%jed), intent(in)}]{S\+N\+\_\+u,  }\item[{real, dimension( g \%isd\+: g \%ied, g \%jsdb\+: g \%jedb), intent(in)}]{S\+N\+\_\+v,  }\item[{real, dimension( g \%isd\+: g \%ied, g \%jsd\+: g \%jed), intent(in)}]{drag\+\_\+rate\+\_\+visc,  }\item[{real, dimension( g \%isd\+: g \%ied, g \%jsd\+: g \%jed), intent(in)}]{I\+\_\+mass }\end{DoxyParamCaption})\hspace{0.3cm}{\ttfamily [private]}}



Calculates the equilibrium solutino where the source depends only on M\+E\+KE diffusivity and there is no lateral diffusion of M\+E\+KE. Results is in M\+E\+KEM\+E\+KE. 


\begin{DoxyParams}[1]{Parameters}
\mbox{\tt in,out}  & {\em g} & Ocean grid.\\
\hline
\mbox{\tt in}  & {\em gv} & Ocean vertical grid structure.\\
\hline
\mbox{\tt in}  & {\em us} & A dimensional unit scaling type\\
\hline
 & {\em cs} & M\+E\+KE control structure.\\
\hline
 & {\em meke} & A structure with M\+E\+KE data.\\
\hline
\mbox{\tt in}  & {\em sn\+\_\+u} & Eady growth rate at u-\/points \mbox{[}T-\/1 $\sim$$>$ s-\/1\mbox{]}.\\
\hline
\mbox{\tt in}  & {\em sn\+\_\+v} & Eady growth rate at v-\/points \mbox{[}T-\/1 $\sim$$>$ s-\/1\mbox{]}.\\
\hline
\mbox{\tt in}  & {\em drag\+\_\+rate\+\_\+visc} & Mean flow velocity contribution to the M\+E\+KE drag rate \mbox{[}L T-\/1 $\sim$$>$ m s-\/1\mbox{]}\\
\hline
\mbox{\tt in}  & {\em i\+\_\+mass} & Inverse of column mass \mbox{[}R-\/1 Z-\/1 $\sim$$>$ m2 kg-\/1\mbox{]}. \\
\hline
\end{DoxyParams}


Definition at line \hyperlink{MOM__MEKE_8F90_source_l00644}{644} of file \hyperlink{MOM__MEKE_8F90_source}{M\+O\+M\+\_\+\+M\+E\+K\+E.\+F90}.



References \hyperlink{namespacemom__meke_aed5885cde342caa59b2b9cde72a3e1e7}{meke\+\_\+lengthscales\+\_\+0d()}.



Referenced by \hyperlink{namespacemom__meke_a5f752f097ddeba7071e1703110e51bc2}{step\+\_\+forward\+\_\+meke()}.


\begin{DoxyCode}
00644   \textcolor{keywordtype}{type}(ocean\_grid\_type),             \textcolor{keywordtype}{intent(inout)} :: g\textcolor{comment}{    !< Ocean grid.}
00645   \textcolor{keywordtype}{type}(verticalgrid\_type),           \textcolor{keywordtype}{intent(in)}    :: gv\textcolor{comment}{   !< Ocean vertical grid structure.}
00646   \textcolor{keywordtype}{type}(unit\_scale\_type),             \textcolor{keywordtype}{intent(in)}    :: us\textcolor{comment}{   !< A dimensional unit scaling type}
00647   \textcolor{keywordtype}{type}(meke\_cs),                     \textcolor{keywordtype}{pointer}       :: cs\textcolor{comment}{   !< MEKE control structure.}
00648   \textcolor{keywordtype}{type}(meke\_type),                   \textcolor{keywordtype}{pointer}       :: meke\textcolor{comment}{ !< A structure with MEKE data.}
00649   \textcolor{keywordtype}{real}, \textcolor{keywordtype}{dimension(SZIB\_(G),SZJ\_(G))}, \textcolor{keywordtype}{intent(in)}    :: sn\_u\textcolor{comment}{ !< Eady growth rate at u-points [T-1 ~> s-1].}
00650   \textcolor{keywordtype}{real}, \textcolor{keywordtype}{dimension(SZI\_(G),SZJB\_(G))}, \textcolor{keywordtype}{intent(in)}    :: sn\_v\textcolor{comment}{ !< Eady growth rate at v-points [T-1 ~> s-1].}
00651   \textcolor{keywordtype}{real}, \textcolor{keywordtype}{dimension(SZI\_(G),SZJ\_(G))},  \textcolor{keywordtype}{intent(in)}    :: drag\_rate\_visc\textcolor{comment}{ !< Mean flow velocity contribution}
00652 \textcolor{comment}{                                                           !! to the MEKE drag rate [L T-1 ~> m s-1]}
00653   \textcolor{keywordtype}{real}, \textcolor{keywordtype}{dimension(SZI\_(G),SZJ\_(G))},  \textcolor{keywordtype}{intent(in)}    :: i\_mass\textcolor{comment}{  !< Inverse of column mass [R-1 Z-1 ~> m2
       kg-1].}
00654   \textcolor{comment}{! Local variables}
00655   \textcolor{keywordtype}{real} :: beta \textcolor{comment}{! Combined topograpic and planetary vorticity gradient [T-1 L-1 ~> s-1 m-1]}
00656   \textcolor{keywordtype}{real} :: sn   \textcolor{comment}{! The local Eady growth rate [T-1 ~> s-1]}
00657   \textcolor{keywordtype}{real} :: bottomfac2, barotrfac2    \textcolor{comment}{! Vertical structure factors [nondim]}
00658   \textcolor{keywordtype}{real} :: lmixscale, lrhines, leady \textcolor{comment}{! Various mixing length scales [L ~> m]}
00659   \textcolor{keywordtype}{real} :: i\_h, khcoeff
00660   \textcolor{keywordtype}{real} :: kh    \textcolor{comment}{! A lateral diffusivity [L2 T-1 ~> m2 s-1]}
00661   \textcolor{keywordtype}{real} :: ubg2  \textcolor{comment}{! Background (tidal?) velocity squared [L2 T-2 ~> m2 s-2]}
00662   \textcolor{keywordtype}{real} :: cd2
00663   \textcolor{keywordtype}{real} :: drag\_rate \textcolor{comment}{! The MEKE spindown timescale due to bottom drag [T-1 ~> s-1].}
00664   \textcolor{keywordtype}{real} :: src   \textcolor{comment}{! The sum of MEKE sources [L2 T-3 ~> W kg-1]}
00665   \textcolor{keywordtype}{real} :: ldamping  \textcolor{comment}{! The MEKE damping rate [T-1 ~> s-1].}
00666   \textcolor{keywordtype}{real} :: eke, ekemin, ekemax, ekeerr \textcolor{comment}{! [L2 T-2 ~> m2 s-2]}
00667   \textcolor{keywordtype}{real} :: resid, resmin, resmax \textcolor{comment}{! Residuals [L2 T-3 ~> W kg-1]}
00668   \textcolor{keywordtype}{real} :: fath    \textcolor{comment}{! Coriolis parameter at h points; to compute topographic beta [T-1 ~> s-1]}
00669   \textcolor{keywordtype}{real} :: beta\_topo\_x, beta\_topo\_y    \textcolor{comment}{! Topographic PV gradients in x and y [T-1 L-1 ~> s-1 m-1]}
00670   \textcolor{keywordtype}{integer} :: i, j, is, ie, js, je, n1, n2
00671   \textcolor{keywordtype}{real} :: tolerance \textcolor{comment}{! Width of EKE bracket [L2 T-2 ~> m2 s-2].}
00672   \textcolor{keywordtype}{logical} :: usesecant, debugiteration
00673 
00674   \textcolor{keywordtype}{real} :: lgrid, ldeform, lfrict
00675 
00676   is = g%isc ; ie = g%iec ; js = g%jsc ; je = g%jec
00677 
00678   debugiteration = .false.
00679   khcoeff = cs%MEKE\_KhCoeff
00680   ubg2 = cs%MEKE\_Uscale**2
00681   cd2 = cs%cdrag**2
00682   tolerance = 1.0e-12*us%m\_s\_to\_L\_T**2
00683 
00684 \textcolor{comment}{!$OMP do}
00685   \textcolor{keywordflow}{do} j=js,je ; \textcolor{keywordflow}{do} i=is,ie
00686     \textcolor{comment}{! SN = 0.25*max( (SN\_u(I,j) + SN\_u(I-1,j)) + (SN\_v(i,J) + SN\_v(i,J-1)), 0.)}
00687     \textcolor{comment}{! This avoids extremes values in equilibrium solution due to bad values in SN\_u, SN\_v}
00688     sn = min(sn\_u(i,j), sn\_u(i-1,j), sn\_v(i,j), sn\_v(i,j-1))
00689 
00690     \textcolor{keywordflow}{if} (cs%MEKE\_equilibrium\_alt) \textcolor{keywordflow}{then}
00691       meke%MEKE(i,j) = (cs%MEKE\_GEOMETRIC\_alpha * sn * us%Z\_to\_m*g%bathyT(i,j))**2 / cd2
00692     \textcolor{keywordflow}{else}
00693       fath = 0.25*((g%CoriolisBu(i,j) + g%CoriolisBu(i-1,j-1)) + &
00694                    (g%CoriolisBu(i-1,j) + g%CoriolisBu(i,j-1))) \textcolor{comment}{! Coriolis parameter at h points}
00695 
00696       \textcolor{comment}{! Since zero-bathymetry cells are masked, this avoids calculations on land}
00697       \textcolor{keywordflow}{if} (cs%MEKE\_topographic\_beta == 0. .or. g%bathyT(i,j) == 0.) \textcolor{keywordflow}{then}
00698         beta\_topo\_x = 0. ; beta\_topo\_y = 0.
00699       \textcolor{keywordflow}{else}
00700         \textcolor{comment}{!### Consider different combinations of these estimates of topographic beta, and the use}
00701         \textcolor{comment}{!    of the water column thickness instead of the bathymetric depth.}
00702         beta\_topo\_x = -cs%MEKE\_topographic\_beta * fath * 0.5 * ( &
00703                       (g%bathyT(i+1,j)-g%bathyT(i,j)) * g%IdxCu(i,j)  &
00704                   / max(g%bathyT(i+1,j),g%bathyT(i,j), gv%H\_subroundoff) &
00705               +       (g%bathyT(i,j)-g%bathyT(i-1,j)) * g%IdxCu(i-1,j) &
00706                   / max(g%bathyT(i,j),g%bathyT(i-1,j), gv%H\_subroundoff) )
00707         beta\_topo\_y = -cs%MEKE\_topographic\_beta * fath * 0.5 * ( &
00708                       (g%bathyT(i,j+1)-g%bathyT(i,j)) * g%IdyCv(i,j)  &
00709                   / max(g%bathyT(i,j+1),g%bathyT(i,j), gv%H\_subroundoff) + &
00710                       (g%bathyT(i,j)-g%bathyT(i,j-1)) * g%IdyCv(i,j-1) &
00711                   / max(g%bathyT(i,j),g%bathyT(i,j-1), gv%H\_subroundoff) )
00712 \textcolor{keywordflow}{      endif}
00713       beta =  sqrt((g%dF\_dx(i,j) + beta\_topo\_x)**2 + &
00714                    (g%dF\_dy(i,j) + beta\_topo\_y)**2 )
00715 
00716       i\_h = us%L\_to\_Z*gv%Rho0 * i\_mass(i,j)
00717 
00718       \textcolor{keywordflow}{if} (khcoeff*sn*i\_h>0.) \textcolor{keywordflow}{then}
00719         \textcolor{comment}{! Solve resid(E) = 0, where resid = Kh(E) * (SN)^2 - damp\_rate(E) E}
00720         ekemin = 0.   \textcolor{comment}{! Use the trivial root as the left bracket}
00721         resmin = 0.   \textcolor{comment}{! Need to detect direction of left residual}
00722         ekemax = 0.01*us%m\_s\_to\_L\_T**2 \textcolor{comment}{! First guess at right bracket}
00723         usesecant = .false. \textcolor{comment}{! Start using a bisection method}
00724 
00725         \textcolor{comment}{! First find right bracket for which resid<0}
00726         resid = 1.0*us%m\_to\_L**2*us%T\_to\_s**3 ; n1 = 0
00727         \textcolor{keywordflow}{do} \textcolor{keywordflow}{while} (resid>0.)
00728           n1 = n1 + 1
00729           eke = ekemax
00730           \textcolor{keyword}{call }meke\_lengthscales\_0d(cs, us, g%areaT(i,j), beta, g%bathyT(i,j), &
00731                                     meke%Rd\_dx\_h(i,j), sn, eke, &
00732                                     bottomfac2, barotrfac2, lmixscale, lrhines, leady)
00733           \textcolor{comment}{! TODO: Should include resolution function in Kh}
00734           kh = (khcoeff * sqrt(2.*barotrfac2*eke) * lmixscale)
00735           src = kh * (sn * sn)
00736           drag\_rate = i\_h * sqrt(drag\_rate\_visc(i,j)**2 + cd2 * ( 2.0*bottomfac2*eke + ubg2 ) )
00737           ldamping = cs%MEKE\_damping + drag\_rate * bottomfac2
00738           resid = src - ldamping * eke
00739           \textcolor{comment}{! if (debugIteration) then}
00740           \textcolor{comment}{!   write(0,*) n1, 'EKE=',EKE,'resid=',resid}
00741           \textcolor{comment}{!   write(0,*) 'EKEmin=',EKEmin,'ResMin=',ResMin}
00742           \textcolor{comment}{!   write(0,*) 'src=',src,'ldamping=',ldamping}
00743           \textcolor{comment}{!   write(0,*) 'gamma-b=',bottomFac2,'gamma-t=',barotrFac2}
00744           \textcolor{comment}{!   write(0,*) 'drag\_visc=',drag\_rate\_visc(i,j),'Ubg2=',Ubg2}
00745           \textcolor{comment}{! endif}
00746           \textcolor{keywordflow}{if} (resid>0.) \textcolor{keywordflow}{then}    \textcolor{comment}{! EKE is to the left of the root}
00747             ekemin = eke        \textcolor{comment}{! so we move the left bracket here}
00748             ekemax = 10. * eke  \textcolor{comment}{! and guess again for the right bracket}
00749             \textcolor{keywordflow}{if} (resid<resmin) usesecant = .true.
00750             resmin = resid
00751             \textcolor{keywordflow}{if} (ekemax > 2.e17*us%m\_s\_to\_L\_T**2) \textcolor{keywordflow}{then}
00752               \textcolor{keywordflow}{if} (debugiteration) stop \textcolor{stringliteral}{'Something has gone very wrong'}
00753               debugiteration = .true.
00754               resid = 1. ; n1 = 0
00755               ekemin = 0. ; resmin = 0.
00756               ekemax = 0.01*us%m\_s\_to\_L\_T**2
00757               usesecant = .false.
00758 \textcolor{keywordflow}{            endif}
00759 \textcolor{keywordflow}{          endif}
00760 \textcolor{keywordflow}{        enddo} \textcolor{comment}{! while(resid>0.) searching for right bracket}
00761         resmax = resid
00762 
00763         \textcolor{comment}{! Bisect the bracket}
00764         n2 = 0 ; ekeerr = ekemax - ekemin
00765         \textcolor{keywordflow}{do} \textcolor{keywordflow}{while} (ekeerr > tolerance)
00766           n2 = n2 + 1
00767           \textcolor{keywordflow}{if} (usesecant) \textcolor{keywordflow}{then}
00768             eke = ekemin + (ekemax - ekemin) * (resmin / (resmin - resmax))
00769           \textcolor{keywordflow}{else}
00770             eke = 0.5 * (ekemin + ekemax)
00771 \textcolor{keywordflow}{          endif}
00772           ekeerr = min( eke-ekemin, ekemax-eke )
00773           \textcolor{comment}{! TODO: Should include resolution function in Kh}
00774           kh = (khcoeff * sqrt(2.*barotrfac2*eke) * lmixscale)
00775           src = kh * (sn * sn)
00776           drag\_rate = i\_h * sqrt( drag\_rate\_visc(i,j)**2 + cd2 * ( 2.0*bottomfac2*eke + ubg2 ) )
00777           ldamping = cs%MEKE\_damping + drag\_rate * bottomfac2
00778           resid = src - ldamping * eke
00779           \textcolor{keywordflow}{if} (usesecant .and. resid>resmin) usesecant = .false.
00780           \textcolor{keywordflow}{if} (resid>0.) \textcolor{keywordflow}{then}              \textcolor{comment}{! EKE is to the left of the root}
00781             ekemin = eke                  \textcolor{comment}{! so we move the left bracket here}
00782             \textcolor{keywordflow}{if} (resid<resmin) usesecant = .true.
00783             resmin = resid                \textcolor{comment}{! Save this for the secant method}
00784           \textcolor{keywordflow}{elseif} (resid<0.) \textcolor{keywordflow}{then}          \textcolor{comment}{! EKE is to the right of the root}
00785             ekemax = eke                  \textcolor{comment}{! so we move the right bracket here}
00786             resmax = resid                \textcolor{comment}{! Save this for the secant method}
00787           \textcolor{keywordflow}{else}
00788             \textcolor{keywordflow}{exit}                          \textcolor{comment}{! resid=0 => EKE is exactly at the root}
00789 \textcolor{keywordflow}{          endif}
00790           \textcolor{keywordflow}{if} (n2>200) stop \textcolor{stringliteral}{'Failing to converge?'}
00791 \textcolor{keywordflow}{        enddo} \textcolor{comment}{! while(EKEmax-EKEmin>tolerance)}
00792 
00793       \textcolor{keywordflow}{else}
00794         eke = 0.
00795 \textcolor{keywordflow}{      endif}
00796       meke%MEKE(i,j) = eke
00797 \textcolor{keywordflow}{    endif}
00798 \textcolor{keywordflow}{  enddo} ;\textcolor{keywordflow}{ enddo}
00799 
\end{DoxyCode}
\mbox{\Hypertarget{namespacemom__meke_a843244b0cc72a08489920dcda464b063}\label{namespacemom__meke_a843244b0cc72a08489920dcda464b063}} 
\index{mom\+\_\+meke@{mom\+\_\+meke}!meke\+\_\+equilibrium\+\_\+restoring@{meke\+\_\+equilibrium\+\_\+restoring}}
\index{meke\+\_\+equilibrium\+\_\+restoring@{meke\+\_\+equilibrium\+\_\+restoring}!mom\+\_\+meke@{mom\+\_\+meke}}
\subsubsection{\texorpdfstring{meke\+\_\+equilibrium\+\_\+restoring()}{meke\_equilibrium\_restoring()}}
{\footnotesize\ttfamily subroutine mom\+\_\+meke\+::meke\+\_\+equilibrium\+\_\+restoring (\begin{DoxyParamCaption}\item[{type(\hyperlink{structmom__meke_1_1meke__cs}{meke\+\_\+cs}), pointer}]{CS,  }\item[{type(ocean\+\_\+grid\+\_\+type), intent(inout)}]{G,  }\item[{type(unit\+\_\+scale\+\_\+type), intent(in)}]{US,  }\item[{real, dimension( g \%isdb\+: g \%iedb, g \%jsd\+: g \%jed), intent(in)}]{S\+N\+\_\+u,  }\item[{real, dimension( g \%isd\+: g \%ied, g \%jsdb\+: g \%jedb), intent(in)}]{S\+N\+\_\+v }\end{DoxyParamCaption})\hspace{0.3cm}{\ttfamily [private]}}


\begin{DoxyParams}[1]{Parameters}
\mbox{\tt in,out}  & {\em g} & Ocean grid.\\
\hline
\mbox{\tt in}  & {\em us} & A dimensional unit scaling type.\\
\hline
 & {\em cs} & M\+E\+KE control structure.\\
\hline
\mbox{\tt in}  & {\em sn\+\_\+u} & Eady growth rate at u-\/points \mbox{[}T-\/1 $\sim$$>$ s-\/1\mbox{]}.\\
\hline
\mbox{\tt in}  & {\em sn\+\_\+v} & Eady growth rate at v-\/points \mbox{[}T-\/1 $\sim$$>$ s-\/1\mbox{]}. \\
\hline
\end{DoxyParams}


Definition at line \hyperlink{MOM__MEKE_8F90_source_l00806}{806} of file \hyperlink{MOM__MEKE_8F90_source}{M\+O\+M\+\_\+\+M\+E\+K\+E.\+F90}.



Referenced by \hyperlink{namespacemom__meke_a5f752f097ddeba7071e1703110e51bc2}{step\+\_\+forward\+\_\+meke()}.


\begin{DoxyCode}
00806   \textcolor{keywordtype}{type}(ocean\_grid\_type),             \textcolor{keywordtype}{intent(inout)} :: g\textcolor{comment}{    !< Ocean grid.}
00807   \textcolor{keywordtype}{type}(unit\_scale\_type),             \textcolor{keywordtype}{intent(in)}    :: us\textcolor{comment}{   !< A dimensional unit scaling type.}
00808   \textcolor{keywordtype}{type}(meke\_cs),                     \textcolor{keywordtype}{pointer}       :: cs\textcolor{comment}{   !< MEKE control structure.}
00809   \textcolor{keywordtype}{real}, \textcolor{keywordtype}{dimension(SZIB\_(G),SZJ\_(G))}, \textcolor{keywordtype}{intent(in)}    :: sn\_u\textcolor{comment}{ !< Eady growth rate at u-points [T-1 ~> s-1].}
00810   \textcolor{keywordtype}{real}, \textcolor{keywordtype}{dimension(SZI\_(G),SZJB\_(G))}, \textcolor{keywordtype}{intent(in)}    :: sn\_v\textcolor{comment}{ !< Eady growth rate at v-points [T-1 ~> s-1].}
00811   \textcolor{comment}{! Local variables}
00812   \textcolor{keywordtype}{real} :: sn                      \textcolor{comment}{! The local Eady growth rate [T-1 ~> s-1]}
00813   \textcolor{keywordtype}{integer} :: i, j, is, ie, js, je \textcolor{comment}{! local indices}
00814   \textcolor{keywordtype}{real} :: cd2                     \textcolor{comment}{! bottom drag}
00815 
00816   is = g%isc ; ie = g%iec ; js = g%jsc ; je = g%jec
00817   cd2 = cs%cdrag**2
00818 
00819   \textcolor{keywordflow}{if} (.not. \textcolor{keyword}{associated}(cs%equilibrium\_value)) \textcolor{keyword}{allocate}(cs%equilibrium\_value(szi\_(g),szj\_(g)))
00820   cs%equilibrium\_value(:,:) = 0.0
00821 
00822 \textcolor{comment}{!$OMP do}
00823   \textcolor{keywordflow}{do} j=js,je ; \textcolor{keywordflow}{do} i=is,ie
00824     \textcolor{comment}{! SN = 0.25*max( (SN\_u(I,j) + SN\_u(I-1,j)) + (SN\_v(i,J) + SN\_v(i,J-1)), 0.)}
00825     \textcolor{comment}{! This avoids extremes values in equilibrium solution due to bad values in SN\_u, SN\_v}
00826     sn = min(sn\_u(i,j), sn\_u(i-1,j), sn\_v(i,j), sn\_v(i,j-1))
00827     cs%equilibrium\_value(i,j) = (cs%MEKE\_GEOMETRIC\_alpha * sn * us%Z\_to\_m*g%bathyT(i,j))**2 / cd2
00828 \textcolor{keywordflow}{  enddo} ;\textcolor{keywordflow}{ enddo}
00829 
00830   \textcolor{keywordflow}{if} (cs%id\_MEKE\_equilibrium>0) \textcolor{keyword}{call }post\_data(cs%id\_MEKE\_equilibrium, cs%equilibrium\_value, cs%diag)
00831 
\end{DoxyCode}
\mbox{\Hypertarget{namespacemom__meke_a099f1cfad37430ef1bd60972a92b1be4}\label{namespacemom__meke_a099f1cfad37430ef1bd60972a92b1be4}} 
\index{mom\+\_\+meke@{mom\+\_\+meke}!meke\+\_\+init@{meke\+\_\+init}}
\index{meke\+\_\+init@{meke\+\_\+init}!mom\+\_\+meke@{mom\+\_\+meke}}
\subsubsection{\texorpdfstring{meke\+\_\+init()}{meke\_init()}}
{\footnotesize\ttfamily logical function, public mom\+\_\+meke\+::meke\+\_\+init (\begin{DoxyParamCaption}\item[{type(time\+\_\+type), intent(in)}]{Time,  }\item[{type(ocean\+\_\+grid\+\_\+type), intent(inout)}]{G,  }\item[{type(unit\+\_\+scale\+\_\+type), intent(in)}]{US,  }\item[{type(param\+\_\+file\+\_\+type), intent(in)}]{param\+\_\+file,  }\item[{type(diag\+\_\+ctrl), intent(inout), target}]{diag,  }\item[{type(\hyperlink{structmom__meke_1_1meke__cs}{meke\+\_\+cs}), pointer}]{CS,  }\item[{type(meke\+\_\+type), pointer}]{M\+E\+KE,  }\item[{type(mom\+\_\+restart\+\_\+cs), pointer}]{restart\+\_\+\+CS }\end{DoxyParamCaption})}



Initializes the M\+O\+M\+\_\+\+M\+E\+KE module and reads parameters. Returns True if module is to be used, otherwise returns False. 


\begin{DoxyParams}[1]{Parameters}
\mbox{\tt in}  & {\em time} & The current model time.\\
\hline
\mbox{\tt in,out}  & {\em g} & The ocean\textquotesingle{}s grid structure.\\
\hline
\mbox{\tt in}  & {\em us} & A dimensional unit scaling type\\
\hline
\mbox{\tt in}  & {\em param\+\_\+file} & Parameter file parser structure.\\
\hline
\mbox{\tt in,out}  & {\em diag} & Diagnostics structure.\\
\hline
 & {\em cs} & M\+E\+KE control structure.\\
\hline
 & {\em meke} & M\+E\+K\+E-\/related fields.\\
\hline
 & {\em restart\+\_\+cs} & Restart control structure for M\+O\+M\+\_\+\+M\+E\+KE. \\
\hline
\end{DoxyParams}


Definition at line \hyperlink{MOM__MEKE_8F90_source_l00984}{984} of file \hyperlink{MOM__MEKE_8F90_source}{M\+O\+M\+\_\+\+M\+E\+K\+E.\+F90}.


\begin{DoxyCode}
00984   \textcolor{keywordtype}{type}(time\_type),         \textcolor{keywordtype}{intent(in)}    :: time\textcolor{comment}{       !< The current model time.}
00985   \textcolor{keywordtype}{type}(ocean\_grid\_type),   \textcolor{keywordtype}{intent(inout)} :: g\textcolor{comment}{          !< The ocean's grid structure.}
00986   \textcolor{keywordtype}{type}(unit\_scale\_type),   \textcolor{keywordtype}{intent(in)}    :: us\textcolor{comment}{         !< A dimensional unit scaling type}
00987   \textcolor{keywordtype}{type}(param\_file\_type),   \textcolor{keywordtype}{intent(in)}    :: param\_file\textcolor{comment}{ !< Parameter file parser structure.}
00988   \textcolor{keywordtype}{type}(diag\_ctrl), \textcolor{keywordtype}{target}, \textcolor{keywordtype}{intent(inout)} :: diag\textcolor{comment}{       !< Diagnostics structure.}
00989   \textcolor{keywordtype}{type}(meke\_cs),           \textcolor{keywordtype}{pointer}       :: cs\textcolor{comment}{         !< MEKE control structure.}
00990   \textcolor{keywordtype}{type}(meke\_type),         \textcolor{keywordtype}{pointer}       :: meke\textcolor{comment}{       !< MEKE-related fields.}
00991   \textcolor{keywordtype}{type}(mom\_restart\_cs),    \textcolor{keywordtype}{pointer}       :: restart\_cs\textcolor{comment}{ !< Restart control structure for MOM\_MEKE.}
00992 
00993   \textcolor{comment}{! Local variables}
00994   \textcolor{keywordtype}{real}    :: i\_t\_rescale   \textcolor{comment}{! A rescaling factor for time from the internal representation in this}
00995                            \textcolor{comment}{! run to the representation in a restart file.}
00996   \textcolor{keywordtype}{real}    :: l\_rescale     \textcolor{comment}{! A rescaling factor for length from the internal representation in this}
00997                            \textcolor{comment}{! run to the representation in a restart file.}
00998   \textcolor{keywordtype}{real}    :: meke\_restoring\_timescale \textcolor{comment}{! The timescale used to nudge MEKE toward its equilibrium value.}
00999   \textcolor{keywordtype}{real} :: cdrag            \textcolor{comment}{! The default bottom drag coefficient [nondim].}
01000   \textcolor{keywordtype}{integer} :: i, j, is, ie, js, je, isd, ied, jsd, jed
01001   \textcolor{keywordtype}{logical} :: laplacian, biharmonic, usevarmix, coldstart
01002   \textcolor{comment}{! This include declares and sets the variable "version".}
01003 \textcolor{preprocessor}{# include "version\_variable.h"}
01004 \textcolor{preprocessor}{}  \textcolor{keywordtype}{character(len=40)}  :: mdl = \textcolor{stringliteral}{"MOM\_MEKE"} \textcolor{comment}{! This module's name.}
01005 
01006   is = g%isc ; ie = g%iec ; js = g%jsc ; je = g%jec
01007   isd = g%isd ; ied = g%ied ; jsd = g%jsd ; jed = g%jed
01008 
01009   \textcolor{comment}{! Determine whether this module will be used}
01010   \textcolor{keyword}{call }get\_param(param\_file, mdl, \textcolor{stringliteral}{"USE\_MEKE"}, meke\_init, default=.false., do\_not\_log=.true.)
01011   \textcolor{keyword}{call }log\_version(param\_file, mdl, version, \textcolor{stringliteral}{""}, all\_default=.not.meke\_init)
01012   \textcolor{keyword}{call }get\_param(param\_file, mdl, \textcolor{stringliteral}{"USE\_MEKE"}, meke\_init, &
01013                  \textcolor{stringliteral}{"If true, turns on the MEKE scheme which calculates "}// &
01014                  \textcolor{stringliteral}{"a sub-grid mesoscale eddy kinetic energy budget."}, &
01015                  default=.false.)
01016   \textcolor{keywordflow}{if} (.not. meke\_init) \textcolor{keywordflow}{return}
01017 
01018   \textcolor{keywordflow}{if} (.not. \textcolor{keyword}{associated}(meke)) \textcolor{keywordflow}{then}
01019     \textcolor{comment}{! The MEKE structure should have been allocated in MEKE\_alloc\_register\_restart()}
01020     \textcolor{keyword}{call }mom\_error(warning, \textcolor{stringliteral}{"MEKE\_init called with NO associated "}// &
01021                             \textcolor{stringliteral}{"MEKE-type structure."})
01022     \textcolor{keywordflow}{return}
01023 \textcolor{keywordflow}{  endif}
01024   \textcolor{keywordflow}{if} (\textcolor{keyword}{associated}(cs)) \textcolor{keywordflow}{then}
01025     \textcolor{keyword}{call }mom\_error(warning, &
01026       \textcolor{stringliteral}{"MEKE\_init called with an associated control structure."})
01027     \textcolor{keywordflow}{return}
01028   \textcolor{keywordflow}{else} ; \textcolor{keyword}{allocate}(cs) ;\textcolor{keywordflow}{ endif}
01029 
01030   \textcolor{keyword}{call }mom\_mesg(\textcolor{stringliteral}{"MEKE\_init: reading parameters "}, 5)
01031 
01032   \textcolor{comment}{! Read all relevant parameters and write them to the model log.}
01033   \textcolor{keyword}{call }get\_param(param\_file, mdl, \textcolor{stringliteral}{"MEKE\_DAMPING"}, cs%MEKE\_damping, &
01034                  \textcolor{stringliteral}{"The local depth-independent MEKE dissipation rate."}, &
01035                  units=\textcolor{stringliteral}{"s-1"}, default=0.0, scale=us%T\_to\_s)
01036   \textcolor{keyword}{call }get\_param(param\_file, mdl, \textcolor{stringliteral}{"MEKE\_CD\_SCALE"}, cs%MEKE\_Cd\_scale, &
01037                  \textcolor{stringliteral}{"The ratio of the bottom eddy velocity to the column mean "}//&
01038                  \textcolor{stringliteral}{"eddy velocity, i.e. sqrt(2*MEKE). This should be less than 1 "}//&
01039                  \textcolor{stringliteral}{"to account for the surface intensification of MEKE."}, &
01040                  units=\textcolor{stringliteral}{"nondim"}, default=0.)
01041   \textcolor{keyword}{call }get\_param(param\_file, mdl, \textcolor{stringliteral}{"MEKE\_CB"}, cs%MEKE\_Cb, &
01042                  \textcolor{stringliteral}{"A coefficient in the expression for the ratio of bottom projected "}//&
01043                  \textcolor{stringliteral}{"eddy energy and mean column energy (see Jansen et al. 2015)."},&
01044                  units=\textcolor{stringliteral}{"nondim"}, default=25.)
01045   \textcolor{keyword}{call }get\_param(param\_file, mdl, \textcolor{stringliteral}{"MEKE\_MIN\_GAMMA2"}, cs%MEKE\_min\_gamma, &
01046                  \textcolor{stringliteral}{"The minimum allowed value of gamma\_b^2."},&
01047                  units=\textcolor{stringliteral}{"nondim"}, default=0.0001)
01048   \textcolor{keyword}{call }get\_param(param\_file, mdl, \textcolor{stringliteral}{"MEKE\_CT"}, cs%MEKE\_Ct, &
01049                  \textcolor{stringliteral}{"A coefficient in the expression for the ratio of barotropic "}//&
01050                  \textcolor{stringliteral}{"eddy energy and mean column energy (see Jansen et al. 2015)."},&
01051                  units=\textcolor{stringliteral}{"nondim"}, default=50.)
01052   \textcolor{keyword}{call }get\_param(param\_file, mdl, \textcolor{stringliteral}{"MEKE\_GMCOEFF"}, cs%MEKE\_GMcoeff, &
01053                  \textcolor{stringliteral}{"The efficiency of the conversion of potential energy "}//&
01054                  \textcolor{stringliteral}{"into MEKE by the thickness mixing parameterization. "}//&
01055                  \textcolor{stringliteral}{"If MEKE\_GMCOEFF is negative, this conversion is not "}//&
01056                  \textcolor{stringliteral}{"used or calculated."}, units=\textcolor{stringliteral}{"nondim"}, default=-1.0)
01057   \textcolor{keyword}{call }get\_param(param\_file, mdl, \textcolor{stringliteral}{"MEKE\_GEOMETRIC"}, cs%MEKE\_GEOMETRIC, &
01058                  \textcolor{stringliteral}{"If MEKE\_GEOMETRIC is true, uses the GM coefficient formulation "}//&
01059                  \textcolor{stringliteral}{"from the GEOMETRIC framework (Marshall et al., 2012)."}, default=.false.)
01060   \textcolor{keyword}{call }get\_param(param\_file, mdl, \textcolor{stringliteral}{"MEKE\_GEOMETRIC\_ALPHA"}, cs%MEKE\_GEOMETRIC\_alpha, &
01061                  \textcolor{stringliteral}{"The nondimensional coefficient governing the efficiency of the GEOMETRIC \(\backslash\)n"}//&
01062                  \textcolor{stringliteral}{"thickness diffusion."}, units=\textcolor{stringliteral}{"nondim"}, default=0.05)
01063   \textcolor{keyword}{call }get\_param(param\_file, mdl, \textcolor{stringliteral}{"MEKE\_EQUILIBRIUM\_ALT"}, cs%MEKE\_equilibrium\_alt, &
01064                  \textcolor{stringliteral}{"If true, use an alternative formula for computing the (equilibrium)"}//&
01065                  \textcolor{stringliteral}{"initial value of MEKE."}, default=.false.)
01066   \textcolor{keyword}{call }get\_param(param\_file, mdl, \textcolor{stringliteral}{"MEKE\_EQUILIBRIUM\_RESTORING"}, cs%MEKE\_equilibrium\_restoring, &
01067                  \textcolor{stringliteral}{"If true, restore MEKE back to its equilibrium value, which is calculated at "}//&
01068                  \textcolor{stringliteral}{"each time step."}, default=.false.)
01069   \textcolor{keywordflow}{if} (cs%MEKE\_equilibrium\_restoring) \textcolor{keywordflow}{then}
01070     \textcolor{keyword}{call }get\_param(param\_file, mdl, \textcolor{stringliteral}{"MEKE\_RESTORING\_TIMESCALE"}, meke\_restoring\_timescale, &
01071                    \textcolor{stringliteral}{"The timescale used to nudge MEKE toward its equilibrium value."}, units=\textcolor{stringliteral}{"s"}, &
01072                    default=1e6, scale=us%T\_to\_s)
01073     cs%MEKE\_restoring\_rate = 1.0 / meke\_restoring\_timescale
01074 \textcolor{keywordflow}{  endif}
01075 
01076   \textcolor{keyword}{call }get\_param(param\_file, mdl, \textcolor{stringliteral}{"MEKE\_FRCOEFF"}, cs%MEKE\_FrCoeff, &
01077                  \textcolor{stringliteral}{"The efficiency of the conversion of mean energy into "}//&
01078                  \textcolor{stringliteral}{"MEKE.  If MEKE\_FRCOEFF is negative, this conversion "}//&
01079                  \textcolor{stringliteral}{"is not used or calculated."}, units=\textcolor{stringliteral}{"nondim"}, default=-1.0)
01080   \textcolor{keyword}{call }get\_param(param\_file, mdl, \textcolor{stringliteral}{"MEKE\_GMECOEFF"}, cs%MEKE\_GMECoeff, &
01081                  \textcolor{stringliteral}{"The efficiency of the conversion of MEKE into mean energy "}//&
01082                  \textcolor{stringliteral}{"by GME.  If MEKE\_GMECOEFF is negative, this conversion "}//&
01083                  \textcolor{stringliteral}{"is not used or calculated."}, units=\textcolor{stringliteral}{"nondim"}, default=-1.0)
01084   \textcolor{keyword}{call }get\_param(param\_file, mdl, \textcolor{stringliteral}{"MEKE\_BGSRC"}, cs%MEKE\_BGsrc, &
01085                  \textcolor{stringliteral}{"A background energy source for MEKE."}, units=\textcolor{stringliteral}{"W kg-1"}, &
01086                  default=0.0, scale=us%m\_to\_L**2*us%T\_to\_s**3)
01087   \textcolor{keyword}{call }get\_param(param\_file, mdl, \textcolor{stringliteral}{"MEKE\_KH"}, cs%MEKE\_Kh, &
01088                  \textcolor{stringliteral}{"A background lateral diffusivity of MEKE. "}//&
01089                  \textcolor{stringliteral}{"Use a negative value to not apply lateral diffusion to MEKE."}, &
01090                  units=\textcolor{stringliteral}{"m2 s-1"}, default=-1.0, scale=us%m\_to\_L**2*us%T\_to\_s)
01091   \textcolor{keyword}{call }get\_param(param\_file, mdl, \textcolor{stringliteral}{"MEKE\_K4"}, cs%MEKE\_K4, &
01092                  \textcolor{stringliteral}{"A lateral bi-harmonic diffusivity of MEKE. "}//&
01093                  \textcolor{stringliteral}{"Use a negative value to not apply bi-harmonic diffusion to MEKE."}, &
01094                  units=\textcolor{stringliteral}{"m4 s-1"}, default=-1.0, scale=us%m\_to\_L**4*us%T\_to\_s)
01095   \textcolor{keyword}{call }get\_param(param\_file, mdl, \textcolor{stringliteral}{"MEKE\_DTSCALE"}, cs%MEKE\_dtScale, &
01096                  \textcolor{stringliteral}{"A scaling factor to accelerate the time evolution of MEKE."}, &
01097                  units=\textcolor{stringliteral}{"nondim"}, default=1.0)
01098   \textcolor{keyword}{call }get\_param(param\_file, mdl, \textcolor{stringliteral}{"MEKE\_KHCOEFF"}, cs%MEKE\_KhCoeff, &
01099                  \textcolor{stringliteral}{"A scaling factor in the expression for eddy diffusivity "}//&
01100                  \textcolor{stringliteral}{"which is otherwise proportional to the MEKE velocity- "}//&
01101                  \textcolor{stringliteral}{"scale times an eddy mixing-length. This factor "}//&
01102                  \textcolor{stringliteral}{"must be >0 for MEKE to contribute to the thickness/ "}//&
01103                  \textcolor{stringliteral}{"and tracer diffusivity in the rest of the model."}, &
01104                  units=\textcolor{stringliteral}{"nondim"}, default=1.0)
01105   \textcolor{keyword}{call }get\_param(param\_file, mdl, \textcolor{stringliteral}{"MEKE\_USCALE"}, cs%MEKE\_Uscale, &
01106                  \textcolor{stringliteral}{"The background velocity that is combined with MEKE to "}//&
01107                  \textcolor{stringliteral}{"calculate the bottom drag."}, units=\textcolor{stringliteral}{"m s-1"}, default=0.0, scale=us%m\_s\_to\_L\_T)
01108   \textcolor{keyword}{call }get\_param(param\_file, mdl, \textcolor{stringliteral}{"MEKE\_GM\_SRC\_ALT"}, cs%GM\_src\_alt, &
01109                  \textcolor{stringliteral}{"If true, use the GM energy conversion form S^2*N^2*kappa rather "}//&
01110                  \textcolor{stringliteral}{"than the streamfunction for the MEKE GM source term."}, default=.false.)
01111   \textcolor{keyword}{call }get\_param(param\_file, mdl, \textcolor{stringliteral}{"MEKE\_VISC\_DRAG"}, cs%visc\_drag, &
01112                  \textcolor{stringliteral}{"If true, use the vertvisc\_type to calculate the bottom "}//&
01113                  \textcolor{stringliteral}{"drag acting on MEKE."}, default=.true.)
01114   \textcolor{keyword}{call }get\_param(param\_file, mdl, \textcolor{stringliteral}{"MEKE\_KHTH\_FAC"}, meke%KhTh\_fac, &
01115                  \textcolor{stringliteral}{"A factor that maps MEKE%Kh to KhTh."}, units=\textcolor{stringliteral}{"nondim"}, &
01116                  default=0.0)
01117   \textcolor{keyword}{call }get\_param(param\_file, mdl, \textcolor{stringliteral}{"MEKE\_KHTR\_FAC"}, meke%KhTr\_fac, &
01118                  \textcolor{stringliteral}{"A factor that maps MEKE%Kh to KhTr."}, units=\textcolor{stringliteral}{"nondim"}, &
01119                  default=0.0)
01120   \textcolor{keyword}{call }get\_param(param\_file, mdl, \textcolor{stringliteral}{"MEKE\_KHMEKE\_FAC"}, cs%KhMEKE\_Fac, &
01121                  \textcolor{stringliteral}{"A factor that maps MEKE%Kh to Kh for MEKE itself."}, &
01122                  units=\textcolor{stringliteral}{"nondim"}, default=0.0)
01123   \textcolor{keyword}{call }get\_param(param\_file, mdl, \textcolor{stringliteral}{"MEKE\_OLD\_LSCALE"}, cs%use\_old\_lscale, &
01124                  \textcolor{stringliteral}{"If true, use the old formula for length scale which is "}//&
01125                  \textcolor{stringliteral}{"a function of grid spacing and deformation radius."},  &
01126                  default=.false.)
01127   \textcolor{keyword}{call }get\_param(param\_file, mdl, \textcolor{stringliteral}{"MEKE\_MIN\_LSCALE"}, cs%use\_min\_lscale, &
01128                  \textcolor{stringliteral}{"If true, use a strict minimum of provided length scales "}//&
01129                  \textcolor{stringliteral}{"rather than harmonic mean."},  &
01130                  default=.false.)
01131   \textcolor{keyword}{call }get\_param(param\_file, mdl, \textcolor{stringliteral}{"MEKE\_RD\_MAX\_SCALE"}, cs%Rd\_as\_max\_scale, &
01132                  \textcolor{stringliteral}{"If true, the length scale used by MEKE is the minimum of "}//&
01133                  \textcolor{stringliteral}{"the deformation radius or grid-spacing. Only used if "}//&
01134                  \textcolor{stringliteral}{"MEKE\_OLD\_LSCALE=True"}, units=\textcolor{stringliteral}{"nondim"}, default=.false.)
01135   \textcolor{keyword}{call }get\_param(param\_file, mdl, \textcolor{stringliteral}{"MEKE\_VISCOSITY\_COEFF\_KU"}, cs%viscosity\_coeff\_Ku, &
01136                  \textcolor{stringliteral}{"If non-zero, is the scaling coefficient in the expression for"}//&
01137                  \textcolor{stringliteral}{"viscosity used to parameterize harmonic lateral momentum mixing by"}//&
01138                  \textcolor{stringliteral}{"unresolved eddies represented by MEKE. Can be negative to"}//&
01139                  \textcolor{stringliteral}{"represent backscatter from the unresolved eddies."}, &
01140                  units=\textcolor{stringliteral}{"nondim"}, default=0.0)
01141   \textcolor{keyword}{call }get\_param(param\_file, mdl, \textcolor{stringliteral}{"MEKE\_VISCOSITY\_COEFF\_AU"}, cs%viscosity\_coeff\_Au, &
01142                  \textcolor{stringliteral}{"If non-zero, is the scaling coefficient in the expression for"}//&
01143                  \textcolor{stringliteral}{"viscosity used to parameterize biharmonic lateral momentum mixing by"}//&
01144                  \textcolor{stringliteral}{"unresolved eddies represented by MEKE. Can be negative to"}//&
01145                  \textcolor{stringliteral}{"represent backscatter from the unresolved eddies."}, &
01146                  units=\textcolor{stringliteral}{"nondim"}, default=0.0)
01147   \textcolor{keyword}{call }get\_param(param\_file, mdl, \textcolor{stringliteral}{"MEKE\_FIXED\_MIXING\_LENGTH"}, cs%Lfixed, &
01148                  \textcolor{stringliteral}{"If positive, is a fixed length contribution to the expression "}//&
01149                  \textcolor{stringliteral}{"for mixing length used in MEKE-derived diffusivity."}, &
01150                  units=\textcolor{stringliteral}{"m"}, default=0.0, scale=us%m\_to\_L)
01151   \textcolor{keyword}{call }get\_param(param\_file, mdl, \textcolor{stringliteral}{"MEKE\_ALPHA\_DEFORM"}, cs%aDeform, &
01152                  \textcolor{stringliteral}{"If positive, is a coefficient weighting the deformation scale "}//&
01153                  \textcolor{stringliteral}{"in the expression for mixing length used in MEKE-derived diffusivity."}, &
01154                  units=\textcolor{stringliteral}{"nondim"}, default=0.0)
01155   \textcolor{keyword}{call }get\_param(param\_file, mdl, \textcolor{stringliteral}{"MEKE\_ALPHA\_RHINES"}, cs%aRhines, &
01156                  \textcolor{stringliteral}{"If positive, is a coefficient weighting the Rhines scale "}//&
01157                  \textcolor{stringliteral}{"in the expression for mixing length used in MEKE-derived diffusivity."}, &
01158                  units=\textcolor{stringliteral}{"nondim"}, default=0.0)
01159   \textcolor{keyword}{call }get\_param(param\_file, mdl, \textcolor{stringliteral}{"MEKE\_ALPHA\_EADY"}, cs%aEady, &
01160                  \textcolor{stringliteral}{"If positive, is a coefficient weighting the Eady length scale "}//&
01161                  \textcolor{stringliteral}{"in the expression for mixing length used in MEKE-derived diffusivity."}, &
01162                  units=\textcolor{stringliteral}{"nondim"}, default=0.0)
01163   \textcolor{keyword}{call }get\_param(param\_file, mdl, \textcolor{stringliteral}{"MEKE\_ALPHA\_FRICT"}, cs%aFrict, &
01164                  \textcolor{stringliteral}{"If positive, is a coefficient weighting the frictional arrest scale "}//&
01165                  \textcolor{stringliteral}{"in the expression for mixing length used in MEKE-derived diffusivity."}, &
01166                  units=\textcolor{stringliteral}{"nondim"}, default=0.0)
01167   \textcolor{keyword}{call }get\_param(param\_file, mdl, \textcolor{stringliteral}{"MEKE\_ALPHA\_GRID"}, cs%aGrid, &
01168                  \textcolor{stringliteral}{"If positive, is a coefficient weighting the grid-spacing as a scale "}//&
01169                  \textcolor{stringliteral}{"in the expression for mixing length used in MEKE-derived diffusivity."}, &
01170                  units=\textcolor{stringliteral}{"nondim"}, default=0.0)
01171   \textcolor{keyword}{call }get\_param(param\_file, mdl, \textcolor{stringliteral}{"MEKE\_COLD\_START"}, coldstart, &
01172                  \textcolor{stringliteral}{"If true, initialize EKE to zero. Otherwise a local equilibrium solution "}//&
01173                  \textcolor{stringliteral}{"is used as an initial condition for EKE."}, default=.false.)
01174   \textcolor{keyword}{call }get\_param(param\_file, mdl, \textcolor{stringliteral}{"MEKE\_BACKSCAT\_RO\_C"}, meke%backscatter\_Ro\_c, &
01175                  \textcolor{stringliteral}{"The coefficient in the Rossby number function for scaling the biharmonic "}//&
01176                  \textcolor{stringliteral}{"frictional energy source. Setting to non-zero enables the Rossby number function."}, &
01177                  units=\textcolor{stringliteral}{"nondim"}, default=0.0)
01178   \textcolor{keyword}{call }get\_param(param\_file, mdl, \textcolor{stringliteral}{"MEKE\_BACKSCAT\_RO\_POW"}, meke%backscatter\_Ro\_pow, &
01179                  \textcolor{stringliteral}{"The power in the Rossby number function for scaling the biharmonic "}//&
01180                  \textcolor{stringliteral}{"frictional energy source."}, units=\textcolor{stringliteral}{"nondim"}, default=0.0)
01181   \textcolor{keyword}{call }get\_param(param\_file, mdl, \textcolor{stringliteral}{"MEKE\_ADVECTION\_FACTOR"}, cs%MEKE\_advection\_factor, &
01182                  \textcolor{stringliteral}{"A scale factor in front of advection of eddy energy. Zero turns advection off. "}//&
01183                  \textcolor{stringliteral}{"Using unity would be normal but other values could accommodate a mismatch "}//&
01184                  \textcolor{stringliteral}{"between the advecting barotropic flow and the vertical structure of MEKE."}, &
01185                  units=\textcolor{stringliteral}{"nondim"}, default=0.0)
01186   \textcolor{keyword}{call }get\_param(param\_file, mdl, \textcolor{stringliteral}{"MEKE\_TOPOGRAPHIC\_BETA"}, cs%MEKE\_topographic\_beta, &
01187                  \textcolor{stringliteral}{"A scale factor to determine how much topographic beta is weighed in "} //&
01188                  \textcolor{stringliteral}{"computing beta in the expression of Rhines scale. Use 1 if full "}//&
01189                  \textcolor{stringliteral}{"topographic beta effect is considered; use 0 if it's completely ignored."}, &
01190                  units=\textcolor{stringliteral}{"nondim"}, default=0.0)
01191 
01192   \textcolor{comment}{! Nonlocal module parameters}
01193   \textcolor{keyword}{call }get\_param(param\_file, mdl, \textcolor{stringliteral}{"CDRAG"}, cdrag, &
01194                  \textcolor{stringliteral}{"CDRAG is the drag coefficient relating the magnitude of "}//&
01195                  \textcolor{stringliteral}{"the velocity field to the bottom stress."}, units=\textcolor{stringliteral}{"nondim"}, &
01196                  default=0.003)
01197   \textcolor{keyword}{call }get\_param(param\_file, mdl, \textcolor{stringliteral}{"MEKE\_CDRAG"}, cs%cdrag, &
01198                  \textcolor{stringliteral}{"Drag coefficient relating the magnitude of the velocity "}//&
01199                  \textcolor{stringliteral}{"field to the bottom stress in MEKE."}, units=\textcolor{stringliteral}{"nondim"}, &
01200                  default=cdrag)
01201   \textcolor{keyword}{call }get\_param(param\_file, mdl, \textcolor{stringliteral}{"LAPLACIAN"}, laplacian, default=.false., do\_not\_log=.true.)
01202   \textcolor{keyword}{call }get\_param(param\_file, mdl, \textcolor{stringliteral}{"BIHARMONIC"}, biharmonic, default=.false., do\_not\_log=.true.)
01203 
01204   \textcolor{keywordflow}{if} (cs%viscosity\_coeff\_Ku/=0. .and. .not. laplacian) \textcolor{keyword}{call }mom\_error(fatal, &
01205                  \textcolor{stringliteral}{"LAPLACIAN must be true if MEKE\_VISCOSITY\_COEFF\_KU is true."})
01206 
01207   \textcolor{keywordflow}{if} (cs%viscosity\_coeff\_Au/=0. .and. .not. biharmonic) \textcolor{keyword}{call }mom\_error(fatal, &
01208                  \textcolor{stringliteral}{"BIHARMONIC must be true if MEKE\_VISCOSITY\_COEFF\_AU is true."})
01209 
01210   \textcolor{keyword}{call }get\_param(param\_file, mdl, \textcolor{stringliteral}{"DEBUG"}, cs%debug, default=.false., do\_not\_log=.true.)
01211 
01212   \textcolor{comment}{! Identify if any lateral diffusive processes are active}
01213   cs%kh\_flux\_enabled = .false.
01214   \textcolor{keywordflow}{if} ((cs%MEKE\_KH >= 0.0)  .or. (cs%KhMEKE\_FAC > 0.0) .or. (cs%MEKE\_advection\_factor > 0.0)) &
01215     cs%kh\_flux\_enabled = .true.
01216 
01217 \textcolor{comment}{! Register fields for output from this module.}
01218   cs%diag => diag
01219   cs%id\_MEKE = register\_diag\_field(\textcolor{stringliteral}{'ocean\_model'}, \textcolor{stringliteral}{'MEKE'}, diag%axesT1, time, &
01220      \textcolor{stringliteral}{'Mesoscale Eddy Kinetic Energy'}, \textcolor{stringliteral}{'m2 s-2'}, conversion=us%L\_T\_to\_m\_s**2)
01221   \textcolor{keywordflow}{if} (.not. \textcolor{keyword}{associated}(meke%MEKE)) cs%id\_MEKE = -1
01222   cs%id\_Kh = register\_diag\_field(\textcolor{stringliteral}{'ocean\_model'}, \textcolor{stringliteral}{'MEKE\_KH'}, diag%axesT1, time, &
01223      \textcolor{stringliteral}{'MEKE derived diffusivity'}, \textcolor{stringliteral}{'m2 s-1'}, conversion=us%L\_to\_m**2*us%s\_to\_T)
01224   \textcolor{keywordflow}{if} (.not. \textcolor{keyword}{associated}(meke%Kh)) cs%id\_Kh = -1
01225   cs%id\_Ku = register\_diag\_field(\textcolor{stringliteral}{'ocean\_model'}, \textcolor{stringliteral}{'MEKE\_KU'}, diag%axesT1, time, &
01226      \textcolor{stringliteral}{'MEKE derived lateral viscosity'}, \textcolor{stringliteral}{'m2 s-1'}, conversion=us%L\_to\_m**2*us%s\_to\_T)
01227   \textcolor{keywordflow}{if} (.not. \textcolor{keyword}{associated}(meke%Ku)) cs%id\_Ku = -1
01228   cs%id\_Au = register\_diag\_field(\textcolor{stringliteral}{'ocean\_model'}, \textcolor{stringliteral}{'MEKE\_AU'}, diag%axesT1, time, &
01229      \textcolor{stringliteral}{'MEKE derived lateral biharmonic viscosity'}, \textcolor{stringliteral}{'m4 s-1'}, conversion=us%L\_to\_m**4*us%s\_to\_T)
01230   \textcolor{keywordflow}{if} (.not. \textcolor{keyword}{associated}(meke%Au)) cs%id\_Au = -1
01231   cs%id\_Ue = register\_diag\_field(\textcolor{stringliteral}{'ocean\_model'}, \textcolor{stringliteral}{'MEKE\_Ue'}, diag%axesT1, time, &
01232      \textcolor{stringliteral}{'MEKE derived eddy-velocity scale'}, \textcolor{stringliteral}{'m s-1'}, conversion=us%L\_T\_to\_m\_s)
01233   \textcolor{keywordflow}{if} (.not. \textcolor{keyword}{associated}(meke%MEKE)) cs%id\_Ue = -1
01234   cs%id\_Ub = register\_diag\_field(\textcolor{stringliteral}{'ocean\_model'}, \textcolor{stringliteral}{'MEKE\_Ub'}, diag%axesT1, time, &
01235      \textcolor{stringliteral}{'MEKE derived bottom eddy-velocity scale'}, \textcolor{stringliteral}{'m s-1'}, conversion=us%L\_T\_to\_m\_s)
01236   \textcolor{keywordflow}{if} (.not. \textcolor{keyword}{associated}(meke%MEKE)) cs%id\_Ub = -1
01237   cs%id\_Ut = register\_diag\_field(\textcolor{stringliteral}{'ocean\_model'}, \textcolor{stringliteral}{'MEKE\_Ut'}, diag%axesT1, time, &
01238      \textcolor{stringliteral}{'MEKE derived barotropic eddy-velocity scale'}, \textcolor{stringliteral}{'m s-1'}, conversion=us%L\_T\_to\_m\_s)
01239   \textcolor{keywordflow}{if} (.not. \textcolor{keyword}{associated}(meke%MEKE)) cs%id\_Ut = -1
01240   cs%id\_src = register\_diag\_field(\textcolor{stringliteral}{'ocean\_model'}, \textcolor{stringliteral}{'MEKE\_src'}, diag%axesT1, time, &
01241      \textcolor{stringliteral}{'MEKE energy source'}, \textcolor{stringliteral}{'m2 s-3'}, conversion=(us%L\_T\_to\_m\_s**2)*us%s\_to\_T)
01242   cs%id\_decay = register\_diag\_field(\textcolor{stringliteral}{'ocean\_model'}, \textcolor{stringliteral}{'MEKE\_decay'}, diag%axesT1, time, &
01243      \textcolor{stringliteral}{'MEKE decay rate'}, \textcolor{stringliteral}{'s-1'}, conversion=us%s\_to\_T)
01244   cs%id\_GM\_src = register\_diag\_field(\textcolor{stringliteral}{'ocean\_model'}, \textcolor{stringliteral}{'MEKE\_GM\_src'}, diag%axesT1, time, &
01245      \textcolor{stringliteral}{'MEKE energy available from thickness mixing'}, &
01246      \textcolor{stringliteral}{'W m-2'}, conversion=us%RZ3\_T3\_to\_W\_m2*us%L\_to\_Z**2)
01247   \textcolor{keywordflow}{if} (.not. \textcolor{keyword}{associated}(meke%GM\_src)) cs%id\_GM\_src = -1
01248   cs%id\_mom\_src = register\_diag\_field(\textcolor{stringliteral}{'ocean\_model'}, \textcolor{stringliteral}{'MEKE\_mom\_src'},diag%axesT1, time, &
01249      \textcolor{stringliteral}{'MEKE energy available from momentum'}, &
01250      \textcolor{stringliteral}{'W m-2'}, conversion=us%RZ3\_T3\_to\_W\_m2*us%L\_to\_Z**2)
01251   \textcolor{keywordflow}{if} (.not. \textcolor{keyword}{associated}(meke%mom\_src)) cs%id\_mom\_src = -1
01252   cs%id\_GME\_snk = register\_diag\_field(\textcolor{stringliteral}{'ocean\_model'}, \textcolor{stringliteral}{'MEKE\_GME\_snk'},diag%axesT1, time, &
01253      \textcolor{stringliteral}{'MEKE energy lost to GME backscatter'}, &
01254      \textcolor{stringliteral}{'W m-2'}, conversion=us%RZ3\_T3\_to\_W\_m2*us%L\_to\_Z**2)
01255   \textcolor{keywordflow}{if} (.not. \textcolor{keyword}{associated}(meke%GME\_snk)) cs%id\_GME\_snk = -1
01256   cs%id\_Le = register\_diag\_field(\textcolor{stringliteral}{'ocean\_model'}, \textcolor{stringliteral}{'MEKE\_Le'}, diag%axesT1, time, &
01257      \textcolor{stringliteral}{'Eddy mixing length used in the MEKE derived eddy diffusivity'}, \textcolor{stringliteral}{'m'}, conversion=us%L\_to\_m)
01258   cs%id\_Lrhines = register\_diag\_field(\textcolor{stringliteral}{'ocean\_model'}, \textcolor{stringliteral}{'MEKE\_Lrhines'}, diag%axesT1, time, &
01259      \textcolor{stringliteral}{'Rhines length scale used in the MEKE derived eddy diffusivity'}, \textcolor{stringliteral}{'m'}, conversion=us%L\_to\_m)
01260   cs%id\_Leady = register\_diag\_field(\textcolor{stringliteral}{'ocean\_model'}, \textcolor{stringliteral}{'MEKE\_Leady'}, diag%axesT1, time, &
01261      \textcolor{stringliteral}{'Eady length scale used in the MEKE derived eddy diffusivity'}, \textcolor{stringliteral}{'m'}, conversion=us%L\_to\_m)
01262   cs%id\_gamma\_b = register\_diag\_field(\textcolor{stringliteral}{'ocean\_model'}, \textcolor{stringliteral}{'MEKE\_gamma\_b'}, diag%axesT1, time, &
01263      \textcolor{stringliteral}{'Ratio of bottom-projected eddy velocity to column-mean eddy velocity'}, \textcolor{stringliteral}{'nondim'})
01264   cs%id\_gamma\_t = register\_diag\_field(\textcolor{stringliteral}{'ocean\_model'}, \textcolor{stringliteral}{'MEKE\_gamma\_t'}, diag%axesT1, time, &
01265      \textcolor{stringliteral}{'Ratio of barotropic eddy velocity to column-mean eddy velocity'}, \textcolor{stringliteral}{'nondim'})
01266 
01267   \textcolor{keywordflow}{if} (cs%kh\_flux\_enabled) \textcolor{keywordflow}{then}
01268     cs%id\_KhMEKE\_u = register\_diag\_field(\textcolor{stringliteral}{'ocean\_model'}, \textcolor{stringliteral}{'KHMEKE\_u'}, diag%axesCu1, time, &
01269      \textcolor{stringliteral}{'Zonal diffusivity of MEKE'}, \textcolor{stringliteral}{'m2 s-1'}, conversion=us%L\_to\_m**2*us%s\_to\_T)
01270     cs%id\_KhMEKE\_v = register\_diag\_field(\textcolor{stringliteral}{'ocean\_model'}, \textcolor{stringliteral}{'KHMEKE\_v'}, diag%axesCv1, time, &
01271      \textcolor{stringliteral}{'Meridional diffusivity of MEKE'}, \textcolor{stringliteral}{'m2 s-1'}, conversion=us%L\_to\_m**2*us%s\_to\_T)
01272 \textcolor{keywordflow}{  endif}
01273 
01274   \textcolor{keywordflow}{if} (cs%MEKE\_equilibrium\_restoring) \textcolor{keywordflow}{then}
01275     cs%id\_MEKE\_equilibrium = register\_diag\_field(\textcolor{stringliteral}{'ocean\_model'}, \textcolor{stringliteral}{'MEKE\_equilibrium'}, diag%axesT1, time, &
01276      \textcolor{stringliteral}{'Equilibrated Mesoscale Eddy Kinetic Energy'}, \textcolor{stringliteral}{'m2 s-2'}, conversion=us%L\_T\_to\_m\_s**2)
01277 \textcolor{keywordflow}{  endif}
01278 
01279   cs%id\_clock\_pass = cpu\_clock\_id(\textcolor{stringliteral}{'(Ocean continuity halo updates)'}, grain=clock\_routine)
01280 
01281   \textcolor{comment}{! Detect whether this instance of MEKE\_init() is at the beginning of a run}
01282   \textcolor{comment}{! or after a restart. If at the beginning, we will initialize MEKE to a local}
01283   \textcolor{comment}{! equilibrium.}
01284   cs%initialize = .not.query\_initialized(meke%MEKE, \textcolor{stringliteral}{"MEKE"}, restart\_cs)
01285   \textcolor{keywordflow}{if} (coldstart) cs%initialize = .false.
01286   \textcolor{keywordflow}{if} (cs%initialize) \textcolor{keyword}{call }mom\_error(warning, &
01287                        \textcolor{stringliteral}{"MEKE\_init: Initializing MEKE with a local equilibrium balance."})
01288 
01289   \textcolor{comment}{! Account for possible changes in dimensional scaling for variables that have been}
01290   \textcolor{comment}{! read from a restart file.}
01291   i\_t\_rescale = 1.0
01292   \textcolor{keywordflow}{if} ((us%s\_to\_T\_restart /= 0.0) .and. (us%s\_to\_T\_restart /= us%s\_to\_T)) &
01293     i\_t\_rescale = us%s\_to\_T\_restart / us%s\_to\_T
01294   l\_rescale = 1.0
01295   \textcolor{keywordflow}{if} ((us%m\_to\_L\_restart /= 0.0) .and. (us%m\_to\_L\_restart /= us%m\_to\_L)) &
01296     l\_rescale = us%m\_to\_L / us%m\_to\_L\_restart
01297 
01298   \textcolor{keywordflow}{if} (l\_rescale*i\_t\_rescale /= 1.0) \textcolor{keywordflow}{then}
01299     \textcolor{keywordflow}{if} (\textcolor{keyword}{associated}(meke%MEKE)) \textcolor{keywordflow}{then} ; \textcolor{keywordflow}{if} (query\_initialized(meke%MEKE, \textcolor{stringliteral}{"MEKE\_MEKE"}, restart\_cs)) \textcolor{keywordflow}{then}
01300       \textcolor{keywordflow}{do} j=js,je ; \textcolor{keywordflow}{do} i=is,ie
01301         meke%MEKE(i,j) = l\_rescale*i\_t\_rescale * meke%MEKE(i,j)
01302 \textcolor{keywordflow}{      enddo} ;\textcolor{keywordflow}{ enddo}
01303 \textcolor{keywordflow}{    endif} ;\textcolor{keywordflow}{ endif}
01304 \textcolor{keywordflow}{  endif}
01305   \textcolor{keywordflow}{if} (l\_rescale**2*i\_t\_rescale /= 1.0) \textcolor{keywordflow}{then}
01306     \textcolor{keywordflow}{if} (\textcolor{keyword}{associated}(meke%Kh)) \textcolor{keywordflow}{then} ; \textcolor{keywordflow}{if} (query\_initialized(meke%Kh, \textcolor{stringliteral}{"MEKE\_Kh"}, restart\_cs)) \textcolor{keywordflow}{then}
01307       \textcolor{keywordflow}{do} j=js,je ; \textcolor{keywordflow}{do} i=is,ie
01308         meke%Kh(i,j) = l\_rescale**2*i\_t\_rescale * meke%Kh(i,j)
01309 \textcolor{keywordflow}{      enddo} ;\textcolor{keywordflow}{ enddo}
01310 \textcolor{keywordflow}{    endif} ;\textcolor{keywordflow}{ endif}
01311     \textcolor{keywordflow}{if} (\textcolor{keyword}{associated}(meke%Ku)) \textcolor{keywordflow}{then} ; \textcolor{keywordflow}{if} (query\_initialized(meke%Ku, \textcolor{stringliteral}{"MEKE\_Ku"}, restart\_cs)) \textcolor{keywordflow}{then}
01312       \textcolor{keywordflow}{do} j=js,je ; \textcolor{keywordflow}{do} i=is,ie
01313         meke%Ku(i,j) = l\_rescale**2*i\_t\_rescale * meke%Ku(i,j)
01314 \textcolor{keywordflow}{      enddo} ;\textcolor{keywordflow}{ enddo}
01315 \textcolor{keywordflow}{    endif} ;\textcolor{keywordflow}{ endif}
01316     \textcolor{keywordflow}{if} (\textcolor{keyword}{associated}(meke%Kh\_diff)) \textcolor{keywordflow}{then} ; \textcolor{keywordflow}{if} (query\_initialized(meke%Kh, \textcolor{stringliteral}{"MEKE\_Kh\_diff"}, restart\_cs)) \textcolor{keywordflow}{then}
01317       \textcolor{keywordflow}{do} j=js,je ; \textcolor{keywordflow}{do} i=is,ie
01318         meke%Kh\_diff(i,j) = l\_rescale**2*i\_t\_rescale * meke%Kh\_diff(i,j)
01319 \textcolor{keywordflow}{      enddo} ;\textcolor{keywordflow}{ enddo}
01320 \textcolor{keywordflow}{    endif} ;\textcolor{keywordflow}{ endif}
01321 \textcolor{keywordflow}{  endif}
01322   \textcolor{keywordflow}{if} (l\_rescale**4*i\_t\_rescale /= 1.0) \textcolor{keywordflow}{then}
01323     \textcolor{keywordflow}{if} (\textcolor{keyword}{associated}(meke%Au)) \textcolor{keywordflow}{then} ; \textcolor{keywordflow}{if} (query\_initialized(meke%Au, \textcolor{stringliteral}{"MEKE\_Au"}, restart\_cs)) \textcolor{keywordflow}{then}
01324       \textcolor{keywordflow}{do} j=js,je ; \textcolor{keywordflow}{do} i=is,ie
01325         meke%Au(i,j) = l\_rescale**4*i\_t\_rescale * meke%Au(i,j)
01326 \textcolor{keywordflow}{      enddo} ;\textcolor{keywordflow}{ enddo}
01327 \textcolor{keywordflow}{    endif} ;\textcolor{keywordflow}{ endif}
01328 \textcolor{keywordflow}{  endif}
01329 
01330   \textcolor{comment}{! Set up group passes.  In the case of a restart, these fields need a halo update now.}
01331   \textcolor{keywordflow}{if} (\textcolor{keyword}{associated}(meke%MEKE)) \textcolor{keywordflow}{then}
01332     \textcolor{keyword}{call }create\_group\_pass(cs%pass\_MEKE, meke%MEKE, g%Domain)
01333     \textcolor{keywordflow}{if} (\textcolor{keyword}{associated}(meke%Kh\_diff)) \textcolor{keyword}{call }create\_group\_pass(cs%pass\_MEKE, meke%Kh\_diff, g%Domain)
01334     \textcolor{keywordflow}{if} (.not.cs%initialize) \textcolor{keyword}{call }do\_group\_pass(cs%pass\_MEKE, g%Domain)
01335 \textcolor{keywordflow}{  endif}
01336   \textcolor{keywordflow}{if} (\textcolor{keyword}{associated}(meke%Kh)) \textcolor{keyword}{call }create\_group\_pass(cs%pass\_Kh, meke%Kh, g%Domain)
01337   \textcolor{keywordflow}{if} (\textcolor{keyword}{associated}(meke%Ku)) \textcolor{keyword}{call }create\_group\_pass(cs%pass\_Kh, meke%Ku, g%Domain)
01338   \textcolor{keywordflow}{if} (\textcolor{keyword}{associated}(meke%Au)) \textcolor{keyword}{call }create\_group\_pass(cs%pass\_Kh, meke%Au, g%Domain)
01339 
01340   \textcolor{keywordflow}{if} (\textcolor{keyword}{associated}(meke%Kh) .or. \textcolor{keyword}{associated}(meke%Ku) .or. \textcolor{keyword}{associated}(meke%Au)) &
01341     \textcolor{keyword}{call }do\_group\_pass(cs%pass\_Kh, g%Domain)
01342 
\end{DoxyCode}
\mbox{\Hypertarget{namespacemom__meke_a8180d5d0cacf48bcbdffead9e6a06efd}\label{namespacemom__meke_a8180d5d0cacf48bcbdffead9e6a06efd}} 
\index{mom\+\_\+meke@{mom\+\_\+meke}!meke\+\_\+lengthscales@{meke\+\_\+lengthscales}}
\index{meke\+\_\+lengthscales@{meke\+\_\+lengthscales}!mom\+\_\+meke@{mom\+\_\+meke}}
\subsubsection{\texorpdfstring{meke\+\_\+lengthscales()}{meke\_lengthscales()}}
{\footnotesize\ttfamily subroutine mom\+\_\+meke\+::meke\+\_\+lengthscales (\begin{DoxyParamCaption}\item[{type(\hyperlink{structmom__meke_1_1meke__cs}{meke\+\_\+cs}), pointer}]{CS,  }\item[{type(meke\+\_\+type), pointer}]{M\+E\+KE,  }\item[{type(ocean\+\_\+grid\+\_\+type), intent(inout)}]{G,  }\item[{type(verticalgrid\+\_\+type), intent(in)}]{GV,  }\item[{type(unit\+\_\+scale\+\_\+type), intent(in)}]{US,  }\item[{real, dimension( g \%isdb\+: g \%iedb, g \%jsd\+: g \%jed), intent(in)}]{S\+N\+\_\+u,  }\item[{real, dimension( g \%isd\+: g \%ied, g \%jsdb\+: g \%jedb), intent(in)}]{S\+N\+\_\+v,  }\item[{real, dimension( g \%isd\+: g \%ied, g \%jsd\+: g \%jed), intent(in)}]{E\+KE,  }\item[{real, dimension( g \%isd\+: g \%ied, g \%jsd\+: g \%jed), intent(out)}]{bottom\+Fac2,  }\item[{real, dimension( g \%isd\+: g \%ied, g \%jsd\+: g \%jed), intent(out)}]{barotr\+Fac2,  }\item[{real, dimension( g \%isd\+: g \%ied, g \%jsd\+: g \%jed), intent(out)}]{Lmix\+Scale }\end{DoxyParamCaption})\hspace{0.3cm}{\ttfamily [private]}}



Calculates the eddy mixing length scale and $\gamma_b$ and $\gamma_t$ functions that are ratios of either bottom or barotropic eddy energy to the column eddy energy, respectively. See \hyperlink{namespacemom__meke_section_MEKE_equations}{M\+E\+KE equations}. 


\begin{DoxyParams}[1]{Parameters}
 & {\em cs} & M\+E\+KE control structure.\\
\hline
 & {\em meke} & M\+E\+KE data.\\
\hline
\mbox{\tt in,out}  & {\em g} & Ocean grid.\\
\hline
\mbox{\tt in}  & {\em gv} & Ocean vertical grid structure.\\
\hline
\mbox{\tt in}  & {\em us} & A dimensional unit scaling type\\
\hline
\mbox{\tt in}  & {\em sn\+\_\+u} & Eady growth rate at u-\/points \mbox{[}T-\/1 $\sim$$>$ s-\/1\mbox{]}.\\
\hline
\mbox{\tt in}  & {\em sn\+\_\+v} & Eady growth rate at v-\/points \mbox{[}T-\/1 $\sim$$>$ s-\/1\mbox{]}.\\
\hline
\mbox{\tt in}  & {\em eke} & Eddy kinetic energy \mbox{[}L2 T-\/2 $\sim$$>$ m2 s-\/2\mbox{]}.\\
\hline
\mbox{\tt out}  & {\em bottomfac2} & gamma\+\_\+b$^\wedge$2\\
\hline
\mbox{\tt out}  & {\em barotrfac2} & gamma\+\_\+t$^\wedge$2\\
\hline
\mbox{\tt out}  & {\em lmixscale} & Eddy mixing length \mbox{[}L $\sim$$>$ m\mbox{]}. \\
\hline
\end{DoxyParams}


Definition at line \hyperlink{MOM__MEKE_8F90_source_l00839}{839} of file \hyperlink{MOM__MEKE_8F90_source}{M\+O\+M\+\_\+\+M\+E\+K\+E.\+F90}.



References \hyperlink{namespacemom__meke_aed5885cde342caa59b2b9cde72a3e1e7}{meke\+\_\+lengthscales\+\_\+0d()}.



Referenced by \hyperlink{namespacemom__meke_a5f752f097ddeba7071e1703110e51bc2}{step\+\_\+forward\+\_\+meke()}.


\begin{DoxyCode}
00839   \textcolor{keywordtype}{type}(meke\_cs),                     \textcolor{keywordtype}{pointer}       :: cs\textcolor{comment}{   !< MEKE control structure.}
00840   \textcolor{keywordtype}{type}(meke\_type),                   \textcolor{keywordtype}{pointer}       :: meke\textcolor{comment}{ !< MEKE data.}
00841   \textcolor{keywordtype}{type}(ocean\_grid\_type),             \textcolor{keywordtype}{intent(inout)} :: g\textcolor{comment}{    !< Ocean grid.}
00842   \textcolor{keywordtype}{type}(verticalgrid\_type),           \textcolor{keywordtype}{intent(in)}    :: gv\textcolor{comment}{   !< Ocean vertical grid structure.}
00843   \textcolor{keywordtype}{type}(unit\_scale\_type),             \textcolor{keywordtype}{intent(in)}    :: us\textcolor{comment}{   !< A dimensional unit scaling type}
00844   \textcolor{keywordtype}{real}, \textcolor{keywordtype}{dimension(SZIB\_(G),SZJ\_(G))}, \textcolor{keywordtype}{intent(in)}    :: sn\_u\textcolor{comment}{ !< Eady growth rate at u-points [T-1 ~> s-1].}
00845   \textcolor{keywordtype}{real}, \textcolor{keywordtype}{dimension(SZI\_(G),SZJB\_(G))}, \textcolor{keywordtype}{intent(in)}    :: sn\_v\textcolor{comment}{ !< Eady growth rate at v-points [T-1 ~> s-1].}
00846   \textcolor{keywordtype}{real}, \textcolor{keywordtype}{dimension(SZI\_(G),SZJ\_(G))},  \textcolor{keywordtype}{intent(in)}    :: eke\textcolor{comment}{  !< Eddy kinetic energy [L2 T-2 ~> m2 s-2].}
00847   \textcolor{keywordtype}{real}, \textcolor{keywordtype}{dimension(SZI\_(G),SZJ\_(G))},  \textcolor{keywordtype}{intent(out)}   :: bottomfac2\textcolor{comment}{ !< gamma\_b^2}
00848   \textcolor{keywordtype}{real}, \textcolor{keywordtype}{dimension(SZI\_(G),SZJ\_(G))},  \textcolor{keywordtype}{intent(out)}   :: barotrfac2\textcolor{comment}{ !< gamma\_t^2}
00849   \textcolor{keywordtype}{real}, \textcolor{keywordtype}{dimension(SZI\_(G),SZJ\_(G))},  \textcolor{keywordtype}{intent(out)}   :: lmixscale\textcolor{comment}{ !< Eddy mixing length [L ~> m].}
00850   \textcolor{comment}{! Local variables}
00851   \textcolor{keywordtype}{real}, \textcolor{keywordtype}{dimension(SZI\_(G),SZJ\_(G))} :: lrhines, leady  \textcolor{comment}{! Possible mixing length scales [L ~> m]}
00852   \textcolor{keywordtype}{real} :: beta \textcolor{comment}{! Combined topograpic and planetary vorticity gradient [T-1 L-1 ~> s-1 m-1]}
00853   \textcolor{keywordtype}{real} :: sn   \textcolor{comment}{! The local Eady growth rate [T-1 ~> s-1]}
00854   \textcolor{keywordtype}{real} :: fath \textcolor{comment}{! Coriolis parameter at h points [T-1 ~> s-1]}
00855   \textcolor{keywordtype}{real} :: beta\_topo\_x, beta\_topo\_y  \textcolor{comment}{! Topographic PV gradients in x and y [T-1 L-1 ~> s-1 m-1]}
00856   \textcolor{keywordtype}{integer} :: i, j, is, ie, js, je
00857 
00858   is = g%isc ; ie = g%iec ; js = g%jsc ; je = g%jec
00859 
00860 \textcolor{comment}{!$OMP do}
00861   \textcolor{keywordflow}{do} j=js,je ; \textcolor{keywordflow}{do} i=is,ie
00862     \textcolor{keywordflow}{if} (.not.cs%use\_old\_lscale) \textcolor{keywordflow}{then}
00863       \textcolor{keywordflow}{if} (cs%aEady > 0.) \textcolor{keywordflow}{then}
00864         sn = 0.25 * ( (sn\_u(i,j) + sn\_u(i-1,j)) + (sn\_v(i,j) + sn\_v(i,j-1)) )
00865       \textcolor{keywordflow}{else}
00866         sn = 0.
00867 \textcolor{keywordflow}{      endif}
00868       fath = 0.25* ( ( g%CoriolisBu(i,j) + g%CoriolisBu(i-1,j-1) ) + &
00869                      ( g%CoriolisBu(i-1,j) + g%CoriolisBu(i,j-1) ) )  \textcolor{comment}{! Coriolis parameter at h points}
00870 
00871       \textcolor{comment}{! If bathyT is zero, then a division by zero FPE will be raised.  In this}
00872       \textcolor{comment}{! case, we apply Adcroft's rule of reciprocals and set the term to zero.}
00873       \textcolor{comment}{! Since zero-bathymetry cells are masked, this should not affect values.}
00874       \textcolor{keywordflow}{if} (cs%MEKE\_topographic\_beta == 0. .or. g%bathyT(i,j) == 0.0) \textcolor{keywordflow}{then}
00875         beta\_topo\_x = 0. ; beta\_topo\_y = 0.
00876       \textcolor{keywordflow}{else}
00877         \textcolor{comment}{!### Consider different combinations of these estimates of topographic beta, and the use}
00878         \textcolor{comment}{!    of the water column thickness instead of the bathymetric depth.}
00879         beta\_topo\_x = -cs%MEKE\_topographic\_beta * fath * 0.5 * ( &
00880                       (g%bathyT(i+1,j)-g%bathyT(i,j)) * g%IdxCu(i,j)  &
00881                  / max(g%bathyT(i+1,j),g%bathyT(i,j), gv%H\_subroundoff) &
00882               +       (g%bathyT(i,j)-g%bathyT(i-1,j)) * g%IdxCu(i-1,j) &
00883                  / max(g%bathyT(i,j),g%bathyT(i-1,j), gv%H\_subroundoff) )
00884         beta\_topo\_y = -cs%MEKE\_topographic\_beta * fath * 0.5 * ( &
00885                       (g%bathyT(i,j+1)-g%bathyT(i,j)) * g%IdyCv(i,j)  &
00886                  / max(g%bathyT(i,j+1),g%bathyT(i,j), gv%H\_subroundoff) + &
00887                       (g%bathyT(i,j)-g%bathyT(i,j-1)) * g%IdyCv(i,j-1) &
00888                  / max(g%bathyT(i,j),g%bathyT(i,j-1), gv%H\_subroundoff) )
00889 \textcolor{keywordflow}{      endif}
00890       beta =  sqrt((g%dF\_dx(i,j) + beta\_topo\_x)**2 + &
00891                    (g%dF\_dy(i,j) + beta\_topo\_y)**2 )
00892 
00893     \textcolor{keywordflow}{else}
00894       beta = 0.
00895 \textcolor{keywordflow}{    endif}
00896     \textcolor{comment}{! Returns bottomFac2, barotrFac2 and LmixScale}
00897     \textcolor{keyword}{call }meke\_lengthscales\_0d(cs, us, g%areaT(i,j), beta, g%bathyT(i,j),  &
00898                               meke%Rd\_dx\_h(i,j), sn, meke%MEKE(i,j), &
00899                               bottomfac2(i,j), barotrfac2(i,j), lmixscale(i,j), &
00900                               lrhines(i,j), leady(i,j))
00901 \textcolor{keywordflow}{  enddo} ;\textcolor{keywordflow}{ enddo}
00902   \textcolor{keywordflow}{if} (cs%id\_Lrhines>0) \textcolor{keyword}{call }post\_data(cs%id\_LRhines, lrhines, cs%diag)
00903   \textcolor{keywordflow}{if} (cs%id\_Leady>0) \textcolor{keyword}{call }post\_data(cs%id\_LEady, leady, cs%diag)
00904 
\end{DoxyCode}
\mbox{\Hypertarget{namespacemom__meke_aed5885cde342caa59b2b9cde72a3e1e7}\label{namespacemom__meke_aed5885cde342caa59b2b9cde72a3e1e7}} 
\index{mom\+\_\+meke@{mom\+\_\+meke}!meke\+\_\+lengthscales\+\_\+0d@{meke\+\_\+lengthscales\+\_\+0d}}
\index{meke\+\_\+lengthscales\+\_\+0d@{meke\+\_\+lengthscales\+\_\+0d}!mom\+\_\+meke@{mom\+\_\+meke}}
\subsubsection{\texorpdfstring{meke\+\_\+lengthscales\+\_\+0d()}{meke\_lengthscales\_0d()}}
{\footnotesize\ttfamily subroutine mom\+\_\+meke\+::meke\+\_\+lengthscales\+\_\+0d (\begin{DoxyParamCaption}\item[{type(\hyperlink{structmom__meke_1_1meke__cs}{meke\+\_\+cs}), pointer}]{CS,  }\item[{type(unit\+\_\+scale\+\_\+type), intent(in)}]{US,  }\item[{real, intent(in)}]{area,  }\item[{real, intent(in)}]{beta,  }\item[{real, intent(in)}]{depth,  }\item[{real, intent(in)}]{Rd\+\_\+dx,  }\item[{real, intent(in)}]{SN,  }\item[{real, intent(in)}]{E\+KE,  }\item[{real, intent(out)}]{bottom\+Fac2,  }\item[{real, intent(out)}]{barotr\+Fac2,  }\item[{real, intent(out)}]{Lmix\+Scale,  }\item[{real, intent(out)}]{Lrhines,  }\item[{real, intent(out)}]{Leady }\end{DoxyParamCaption})\hspace{0.3cm}{\ttfamily [private]}}



Calculates the eddy mixing length scale and $\gamma_b$ and $\gamma_t$ functions that are ratios of either bottom or barotropic eddy energy to the column eddy energy, respectively. See \hyperlink{namespacemom__meke_section_MEKE_equations}{M\+E\+KE equations}. 


\begin{DoxyParams}[1]{Parameters}
 & {\em cs} & M\+E\+KE control structure.\\
\hline
\mbox{\tt in}  & {\em us} & A dimensional unit scaling type\\
\hline
\mbox{\tt in}  & {\em area} & Grid cell area \mbox{[}L2 $\sim$$>$ m2\mbox{]}\\
\hline
\mbox{\tt in}  & {\em beta} & Planetary beta = $\vert$grad F$\vert$ \mbox{[}T-\/1 L-\/1 $\sim$$>$ s-\/1 m-\/1\mbox{]}\\
\hline
\mbox{\tt in}  & {\em depth} & Ocean depth \mbox{[}Z $\sim$$>$ m\mbox{]}\\
\hline
\mbox{\tt in}  & {\em rd\+\_\+dx} & Resolution Ld/dx \mbox{[}nondim\mbox{]}.\\
\hline
\mbox{\tt in}  & {\em sn} & Eady growth rate \mbox{[}T-\/1 $\sim$$>$ s-\/1\mbox{]}.\\
\hline
\mbox{\tt in}  & {\em eke} & Eddy kinetic energy \mbox{[}L2 T-\/2 $\sim$$>$ m2 s-\/2\mbox{]}.\\
\hline
\mbox{\tt out}  & {\em bottomfac2} & gamma\+\_\+b$^\wedge$2\\
\hline
\mbox{\tt out}  & {\em barotrfac2} & gamma\+\_\+t$^\wedge$2\\
\hline
\mbox{\tt out}  & {\em lmixscale} & Eddy mixing length \mbox{[}L $\sim$$>$ m\mbox{]}.\\
\hline
\mbox{\tt out}  & {\em lrhines} & Rhines length scale \mbox{[}L $\sim$$>$ m\mbox{]}.\\
\hline
\mbox{\tt out}  & {\em leady} & Eady length scale \mbox{[}L $\sim$$>$ m\mbox{]}. \\
\hline
\end{DoxyParams}


Definition at line \hyperlink{MOM__MEKE_8F90_source_l00912}{912} of file \hyperlink{MOM__MEKE_8F90_source}{M\+O\+M\+\_\+\+M\+E\+K\+E.\+F90}.



Referenced by \hyperlink{namespacemom__meke_a0ef9a8bcdf705b544db9b8c28a5e6a56}{meke\+\_\+equilibrium()}, and \hyperlink{namespacemom__meke_a8180d5d0cacf48bcbdffead9e6a06efd}{meke\+\_\+lengthscales()}.


\begin{DoxyCode}
00912   \textcolor{keywordtype}{type}(meke\_cs), \textcolor{keywordtype}{pointer}       :: cs\textcolor{comment}{         !< MEKE control structure.}
00913   \textcolor{keywordtype}{type}(unit\_scale\_type), \textcolor{keywordtype}{intent(in)} :: us\textcolor{comment}{    !< A dimensional unit scaling type}
00914   \textcolor{keywordtype}{real},          \textcolor{keywordtype}{intent(in)}    :: area\textcolor{comment}{       !< Grid cell area [L2 ~> m2]}
00915   \textcolor{keywordtype}{real},          \textcolor{keywordtype}{intent(in)}    :: beta\textcolor{comment}{       !< Planetary beta = |grad F| [T-1 L-1 ~> s-1 m-1]}
00916   \textcolor{keywordtype}{real},          \textcolor{keywordtype}{intent(in)}    :: depth\textcolor{comment}{      !< Ocean depth [Z ~> m]}
00917   \textcolor{keywordtype}{real},          \textcolor{keywordtype}{intent(in)}    :: rd\_dx\textcolor{comment}{      !< Resolution Ld/dx [nondim].}
00918   \textcolor{keywordtype}{real},          \textcolor{keywordtype}{intent(in)}    :: sn\textcolor{comment}{         !< Eady growth rate [T-1 ~> s-1].}
00919   \textcolor{keywordtype}{real},          \textcolor{keywordtype}{intent(in)}    :: eke\textcolor{comment}{        !< Eddy kinetic energy [L2 T-2 ~> m2 s-2].}
00920 \textcolor{comment}{!  real,          intent(in)    :: Z\_to\_L     !< A conversion factor from depth units (Z) to}
00921 \textcolor{comment}{!                                             !! the units for lateral distances (L).}
00922   \textcolor{keywordtype}{real},          \textcolor{keywordtype}{intent(out)}   :: bottomfac2\textcolor{comment}{ !< gamma\_b^2}
00923   \textcolor{keywordtype}{real},          \textcolor{keywordtype}{intent(out)}   :: barotrfac2\textcolor{comment}{ !< gamma\_t^2}
00924   \textcolor{keywordtype}{real},          \textcolor{keywordtype}{intent(out)}   :: lmixscale\textcolor{comment}{  !< Eddy mixing length [L ~> m].}
00925   \textcolor{keywordtype}{real},          \textcolor{keywordtype}{intent(out)}   :: lrhines\textcolor{comment}{    !< Rhines length scale [L ~> m].}
00926   \textcolor{keywordtype}{real},          \textcolor{keywordtype}{intent(out)}   :: leady\textcolor{comment}{      !< Eady length scale [L ~> m].}
00927   \textcolor{comment}{! Local variables}
00928   \textcolor{keywordtype}{real} :: lgrid, ldeform, lfrict \textcolor{comment}{! Length scales [L ~> m]}
00929   \textcolor{keywordtype}{real} :: ue  \textcolor{comment}{! An eddy velocity [L T-1 ~> m s-1]}
00930 
00931   \textcolor{comment}{! Length scale for MEKE derived diffusivity}
00932   lgrid = sqrt(area)               \textcolor{comment}{! Grid scale}
00933   ldeform = lgrid * rd\_dx          \textcolor{comment}{! Deformation scale}
00934   lfrict = (us%Z\_to\_L * depth) / cs%cdrag  \textcolor{comment}{! Frictional arrest scale}
00935   \textcolor{comment}{! gamma\_b^2 is the ratio of bottom eddy energy to mean column eddy energy}
00936   \textcolor{comment}{! used in calculating bottom drag}
00937   bottomfac2 = cs%MEKE\_CD\_SCALE**2
00938   \textcolor{keywordflow}{if} (lfrict*cs%MEKE\_Cb>0.) bottomfac2 = bottomfac2 + 1./( 1. + cs%MEKE\_Cb*(ldeform/lfrict) )**0.8
00939   bottomfac2 = max(bottomfac2, cs%MEKE\_min\_gamma)
00940   \textcolor{comment}{! gamma\_t^2 is the ratio of barotropic eddy energy to mean column eddy energy}
00941   \textcolor{comment}{! used in the velocity scale for diffusivity}
00942   barotrfac2 = 1.
00943   \textcolor{keywordflow}{if} (lfrict*cs%MEKE\_Ct>0.) barotrfac2 = 1. / ( 1. + cs%MEKE\_Ct*(ldeform/lfrict) )**0.25
00944   barotrfac2 = max(barotrfac2, cs%MEKE\_min\_gamma)
00945   \textcolor{keywordflow}{if} (cs%use\_old\_lscale) \textcolor{keywordflow}{then}
00946     \textcolor{keywordflow}{if} (cs%Rd\_as\_max\_scale) \textcolor{keywordflow}{then}
00947       lmixscale = min(ldeform, lgrid) \textcolor{comment}{! The smaller of Ld or dx}
00948     \textcolor{keywordflow}{else}
00949       lmixscale = lgrid
00950 \textcolor{keywordflow}{    endif}
00951   \textcolor{keywordflow}{else}
00952     ue = sqrt( 2.0 * max( 0., barotrfac2*eke ) ) \textcolor{comment}{! Barotropic eddy flow scale}
00953     lrhines = sqrt( ue / max( beta, 1.e-30*us%T\_to\_s*us%L\_to\_m ) )       \textcolor{comment}{! Rhines scale}
00954     \textcolor{keywordflow}{if} (cs%aEady > 0.) \textcolor{keywordflow}{then}
00955       leady = ue / max( sn, 1.e-15*us%T\_to\_s ) \textcolor{comment}{! Bound Eady time-scale < 1e15 seconds}
00956     \textcolor{keywordflow}{else}
00957       leady = 0.
00958 \textcolor{keywordflow}{    endif}
00959     \textcolor{keywordflow}{if} (cs%use\_min\_lscale) \textcolor{keywordflow}{then}
00960       lmixscale = 1.e7
00961       \textcolor{keywordflow}{if} (cs%aDeform*ldeform > 0.) lmixscale = min(lmixscale,cs%aDeform*ldeform)
00962       \textcolor{keywordflow}{if} (cs%aFrict *lfrict  > 0.) lmixscale = min(lmixscale,cs%aFrict *lfrict)
00963       \textcolor{keywordflow}{if} (cs%aRhines*lrhines > 0.) lmixscale = min(lmixscale,cs%aRhines*lrhines)
00964       \textcolor{keywordflow}{if} (cs%aEady  *leady   > 0.) lmixscale = min(lmixscale,cs%aEady  *leady)
00965       \textcolor{keywordflow}{if} (cs%aGrid  *lgrid   > 0.) lmixscale = min(lmixscale,cs%aGrid  *lgrid)
00966       \textcolor{keywordflow}{if} (cs%Lfixed          > 0.) lmixscale = min(lmixscale,cs%Lfixed)
00967     \textcolor{keywordflow}{else}
00968       lmixscale = 0.
00969       \textcolor{keywordflow}{if} (cs%aDeform*ldeform > 0.) lmixscale = lmixscale + 1./(cs%aDeform*ldeform)
00970       \textcolor{keywordflow}{if} (cs%aFrict *lfrict  > 0.) lmixscale = lmixscale + 1./(cs%aFrict *lfrict)
00971       \textcolor{keywordflow}{if} (cs%aRhines*lrhines > 0.) lmixscale = lmixscale + 1./(cs%aRhines*lrhines)
00972       \textcolor{keywordflow}{if} (cs%aEady  *leady   > 0.) lmixscale = lmixscale + 1./(cs%aEady  *leady)
00973       \textcolor{keywordflow}{if} (cs%aGrid  *lgrid   > 0.) lmixscale = lmixscale + 1./(cs%aGrid  *lgrid)
00974       \textcolor{keywordflow}{if} (cs%Lfixed          > 0.) lmixscale = lmixscale + 1./cs%Lfixed
00975       \textcolor{keywordflow}{if} (lmixscale > 0.) lmixscale = 1. / lmixscale
00976 \textcolor{keywordflow}{    endif}
00977 \textcolor{keywordflow}{  endif}
00978 
\end{DoxyCode}
\mbox{\Hypertarget{namespacemom__meke_a5f752f097ddeba7071e1703110e51bc2}\label{namespacemom__meke_a5f752f097ddeba7071e1703110e51bc2}} 
\index{mom\+\_\+meke@{mom\+\_\+meke}!step\+\_\+forward\+\_\+meke@{step\+\_\+forward\+\_\+meke}}
\index{step\+\_\+forward\+\_\+meke@{step\+\_\+forward\+\_\+meke}!mom\+\_\+meke@{mom\+\_\+meke}}
\subsubsection{\texorpdfstring{step\+\_\+forward\+\_\+meke()}{step\_forward\_meke()}}
{\footnotesize\ttfamily subroutine, public mom\+\_\+meke\+::step\+\_\+forward\+\_\+meke (\begin{DoxyParamCaption}\item[{type(meke\+\_\+type), pointer}]{M\+E\+KE,  }\item[{real, dimension( g \%isd\+: g \%ied, g \%jsd\+: g \%jed, g \%ke), intent(in)}]{h,  }\item[{real, dimension( g \%isdb\+: g \%iedb, g \%jsd\+: g \%jed), intent(in)}]{S\+N\+\_\+u,  }\item[{real, dimension( g \%isd\+: g \%ied, g \%jsdb\+: g \%jedb), intent(in)}]{S\+N\+\_\+v,  }\item[{type(vertvisc\+\_\+type), intent(in)}]{visc,  }\item[{real, intent(in)}]{dt,  }\item[{type(ocean\+\_\+grid\+\_\+type), intent(inout)}]{G,  }\item[{type(verticalgrid\+\_\+type), intent(in)}]{GV,  }\item[{type(unit\+\_\+scale\+\_\+type), intent(in)}]{US,  }\item[{type(\hyperlink{structmom__meke_1_1meke__cs}{meke\+\_\+cs}), pointer}]{CS,  }\item[{real, dimension( g \%isdb\+: g \%iedb, g \%jsd\+: g \%jed, g \%ke), intent(in)}]{hu,  }\item[{real, dimension( g \%isd\+: g \%ied, g \%jsdb\+: g \%jedb, g \%ke), intent(in)}]{hv }\end{DoxyParamCaption})}



Integrates forward-\/in-\/time the M\+E\+KE eddy energy equation. See \hyperlink{namespacemom__meke_section_MEKE_equations}{M\+E\+KE equations}. 


\begin{DoxyParams}[1]{Parameters}
 & {\em meke} & M\+E\+KE data.\\
\hline
\mbox{\tt in,out}  & {\em g} & Ocean grid.\\
\hline
\mbox{\tt in}  & {\em gv} & Ocean vertical grid structure.\\
\hline
\mbox{\tt in}  & {\em us} & A dimensional unit scaling type\\
\hline
\mbox{\tt in}  & {\em h} & Layer thickness \mbox{[}H $\sim$$>$ m or kg m-\/2\mbox{]}.\\
\hline
\mbox{\tt in}  & {\em sn\+\_\+u} & Eady growth rate at u-\/points \mbox{[}T-\/1 $\sim$$>$ s-\/1\mbox{]}.\\
\hline
\mbox{\tt in}  & {\em sn\+\_\+v} & Eady growth rate at v-\/points \mbox{[}T-\/1 $\sim$$>$ s-\/1\mbox{]}.\\
\hline
\mbox{\tt in}  & {\em visc} & The vertical viscosity type.\\
\hline
\mbox{\tt in}  & {\em dt} & Model(baroclinic) time-\/step \mbox{[}T $\sim$$>$ s\mbox{]}.\\
\hline
 & {\em cs} & M\+E\+KE control structure.\\
\hline
\mbox{\tt in}  & {\em hu} & Accumlated zonal mass flux \mbox{[}H L2 $\sim$$>$ m3 or kg\mbox{]}.\\
\hline
\mbox{\tt in}  & {\em hv} & Accumlated meridional mass flux \mbox{[}H L2 $\sim$$>$ m3 or kg\mbox{]} \\
\hline
\end{DoxyParams}


Definition at line \hyperlink{MOM__MEKE_8F90_source_l00112}{112} of file \hyperlink{MOM__MEKE_8F90_source}{M\+O\+M\+\_\+\+M\+E\+K\+E.\+F90}.



References \hyperlink{namespacemom__meke_a0ef9a8bcdf705b544db9b8c28a5e6a56}{meke\+\_\+equilibrium()}, \hyperlink{namespacemom__meke_a843244b0cc72a08489920dcda464b063}{meke\+\_\+equilibrium\+\_\+restoring()}, and \hyperlink{namespacemom__meke_a8180d5d0cacf48bcbdffead9e6a06efd}{meke\+\_\+lengthscales()}.


\begin{DoxyCode}
00112   \textcolor{keywordtype}{type}(meke\_type),                          \textcolor{keywordtype}{pointer}       :: meke\textcolor{comment}{ !< MEKE data.}
00113   \textcolor{keywordtype}{type}(ocean\_grid\_type),                    \textcolor{keywordtype}{intent(inout)} :: g\textcolor{comment}{    !< Ocean grid.}
00114   \textcolor{keywordtype}{type}(verticalgrid\_type),                  \textcolor{keywordtype}{intent(in)}    :: gv\textcolor{comment}{   !< Ocean vertical grid structure.}
00115   \textcolor{keywordtype}{type}(unit\_scale\_type),                    \textcolor{keywordtype}{intent(in)}    :: us\textcolor{comment}{   !< A dimensional unit scaling type}
00116   \textcolor{keywordtype}{real}, \textcolor{keywordtype}{dimension(SZI\_(G),SZJ\_(G),SZK\_(G))}, \textcolor{keywordtype}{intent(in)}    :: h\textcolor{comment}{    !< Layer thickness [H ~> m or kg m-2].}
00117   \textcolor{keywordtype}{real}, \textcolor{keywordtype}{dimension(SZIB\_(G),SZJ\_(G))},        \textcolor{keywordtype}{intent(in)}    :: sn\_u\textcolor{comment}{ !< Eady growth rate at u-points [T-1 ~>
       s-1].}
00118   \textcolor{keywordtype}{real}, \textcolor{keywordtype}{dimension(SZI\_(G),SZJB\_(G))},        \textcolor{keywordtype}{intent(in)}    :: sn\_v\textcolor{comment}{ !< Eady growth rate at v-points [T-1 ~>
       s-1].}
00119   \textcolor{keywordtype}{type}(vertvisc\_type),                      \textcolor{keywordtype}{intent(in)}    :: visc\textcolor{comment}{ !< The vertical viscosity type.}
00120   \textcolor{keywordtype}{real},                                     \textcolor{keywordtype}{intent(in)}    :: dt\textcolor{comment}{   !< Model(baroclinic) time-step [T ~> s].}
00121   \textcolor{keywordtype}{type}(meke\_cs),                            \textcolor{keywordtype}{pointer}       :: cs\textcolor{comment}{   !< MEKE control structure.}
00122   \textcolor{keywordtype}{real}, \textcolor{keywordtype}{dimension(SZIB\_(G),SZJ\_(G),SZK\_(G))}, \textcolor{keywordtype}{intent(in)}   :: hu\textcolor{comment}{   !< Accumlated zonal mass flux [H L2 ~> m3
       or kg].}
00123   \textcolor{keywordtype}{real}, \textcolor{keywordtype}{dimension(SZI\_(G),SZJB\_(G),SZK\_(G))}, \textcolor{keywordtype}{intent(in)}   :: hv\textcolor{comment}{   !< Accumlated meridional mass flux [H L2
       ~> m3 or kg]}
00124 
00125   \textcolor{comment}{! Local variables}
00126   \textcolor{keywordtype}{real}, \textcolor{keywordtype}{dimension(SZI\_(G),SZJ\_(G))} :: &
00127     mass, &         \textcolor{comment}{! The total mass of the water column [R Z ~> kg m-2].}
00128     i\_mass, &       \textcolor{comment}{! The inverse of mass [R-1 Z-1 ~> m2 kg-1].}
00129     src, &          \textcolor{comment}{! The sum of all MEKE sources [L2 T-3 ~> W kg-1] (= m2 s-3).}
00130     meke\_decay, &   \textcolor{comment}{! A diagnostic of the MEKE decay timescale [T-1 ~> s-1].}
00131     drag\_rate\_visc, & \textcolor{comment}{! Near-bottom velocity contribution to bottom dratg [L T-1 ~> m s-1]}
00132     drag\_rate, &    \textcolor{comment}{! The MEKE spindown timescale due to bottom drag [T-1 ~> s-1].}
00133     drag\_rate\_j15, &  \textcolor{comment}{! The MEKE spindown timescale due to bottom drag with the Jansen 2015 scheme.}
00134                     \textcolor{comment}{! Unfortunately, as written the units seem inconsistent. [T-1 ~> s-1].}
00135     del2meke, &     \textcolor{comment}{! Laplacian of MEKE, used for bi-harmonic diffusion [T-2 ~> s-2].}
00136     del4meke, &     \textcolor{comment}{! Time-integrated MEKE tendency arising from the biharmonic of MEKE [L2 T-2 ~> m2 s-2].}
00137     lmixscale, &    \textcolor{comment}{! Eddy mixing length [L ~> m].}
00138     barotrfac2, &   \textcolor{comment}{! Ratio of EKE\_barotropic / EKE [nondim]}
00139     bottomfac2, &   \textcolor{comment}{! Ratio of EKE\_bottom / EKE [nondim]}
00140     tmp             \textcolor{comment}{! Temporary variable for diagnostic computation}
00141 
00142   \textcolor{keywordtype}{real}, \textcolor{keywordtype}{dimension(SZIB\_(G),SZJ\_(G))} :: &
00143     meke\_uflux, &   \textcolor{comment}{! The zonal advective and diffusive flux of MEKE with units of [R Z L4 T-3 ~> kg m-2
       s-3].}
00144                     \textcolor{comment}{! In one place, MEKE\_uflux is used as temporary work space with units of [L2 T-2 ~> m2
       s-2].}
00145     kh\_u, &         \textcolor{comment}{! The zonal diffusivity that is actually used [L2 T-1 ~> m2 s-1].}
00146     barohu, &       \textcolor{comment}{! Depth integrated accumulated zonal mass flux [R Z L2 ~> kg].}
00147     drag\_vel\_u      \textcolor{comment}{! A (vertical) viscosity associated with bottom drag at}
00148                     \textcolor{comment}{! u-points [Z T-1 ~> m s-1].}
00149   \textcolor{keywordtype}{real}, \textcolor{keywordtype}{dimension(SZI\_(G),SZJB\_(G))} :: &
00150     meke\_vflux, &   \textcolor{comment}{! The meridional advective and diffusive flux of MEKE with units of [R Z L4 T-3 ~> kg
       m-2 s-3].}
00151                     \textcolor{comment}{! In one place, MEKE\_vflux is used as temporary work space with units of [L2 T-2 ~> m2
       s-2].}
00152     kh\_v, &         \textcolor{comment}{! The meridional diffusivity that is actually used [L2 T-1 ~> m2 s-1].}
00153     barohv, &       \textcolor{comment}{! Depth integrated accumulated meridional mass flux [R Z L2 ~> kg].}
00154     drag\_vel\_v      \textcolor{comment}{! A (vertical) viscosity associated with bottom drag at}
00155                     \textcolor{comment}{! v-points [Z T-1 ~> m s-1].}
00156   \textcolor{keywordtype}{real} :: kh\_here   \textcolor{comment}{! The local horizontal viscosity [L2 T-1 ~> m2 s-1]}
00157   \textcolor{keywordtype}{real} :: inv\_kh\_max \textcolor{comment}{! The inverse of the local horizontal viscosity [T L-2 ~> s m-2]}
00158   \textcolor{keywordtype}{real} :: k4\_here   \textcolor{comment}{! The local horizontal biharmonic viscosity [L4 T-1 ~> m4 s-1]}
00159   \textcolor{keywordtype}{real} :: inv\_k4\_max \textcolor{comment}{! The inverse of the local horizontal biharmonic viscosity [T L-4 ~> s m-4]}
00160   \textcolor{keywordtype}{real} :: cdrag2
00161   \textcolor{keywordtype}{real} :: advfac    \textcolor{comment}{! The product of the advection scaling factor and 1/dt [T-1 ~> s-1]}
00162   \textcolor{keywordtype}{real} :: mass\_neglect \textcolor{comment}{! A negligible mass [R Z ~> kg m-2].}
00163   \textcolor{keywordtype}{real} :: ldamping  \textcolor{comment}{! The MEKE damping rate [T-1 ~> s-1].}
00164   \textcolor{keywordtype}{real} :: rho0      \textcolor{comment}{! A density used to convert mass to distance [R ~> kg m-3].}
00165   \textcolor{keywordtype}{real} :: sdt       \textcolor{comment}{! dt to use locally [T ~> s] (could be scaled to accelerate)}
00166   \textcolor{keywordtype}{real} :: sdt\_damp  \textcolor{comment}{! dt for damping [T ~> s] (sdt could be split).}
00167   \textcolor{keywordtype}{logical} :: use\_drag\_rate \textcolor{comment}{! Flag to indicate drag\_rate is finite}
00168   \textcolor{keywordtype}{integer} :: i, j, k, is, ie, js, je, isq, ieq, jsq, jeq, nz
00169 
00170   is = g%isc ; ie = g%iec ; js = g%jsc ; je = g%jec ; nz = g%ke
00171   isq = g%IscB ; ieq = g%IecB ; jsq = g%JscB ; jeq = g%JecB
00172 
00173   \textcolor{keywordflow}{if} (.not.\textcolor{keyword}{associated}(cs)) \textcolor{keyword}{call }mom\_error(fatal, &
00174          \textcolor{stringliteral}{"MOM\_MEKE: Module must be initialized before it is used."})
00175   \textcolor{keywordflow}{if} (.not.\textcolor{keyword}{associated}(meke)) \textcolor{keyword}{call }mom\_error(fatal, &
00176          \textcolor{stringliteral}{"MOM\_MEKE: MEKE must be initialized before it is used."})
00177 
00178   \textcolor{keywordflow}{if} ((cs%MEKE\_damping > 0.0) .or. (cs%MEKE\_Cd\_scale > 0.0) .or. (cs%MEKE\_Cb>0.) &
00179       .or. cs%visc\_drag) \textcolor{keywordflow}{then}
00180     use\_drag\_rate = .true.
00181   \textcolor{keywordflow}{else}
00182     use\_drag\_rate = .false.
00183 \textcolor{keywordflow}{  endif}
00184 
00185   \textcolor{comment}{! Only integrate the MEKE equations if MEKE is required.}
00186   \textcolor{keywordflow}{if} (.not.\textcolor{keyword}{associated}(meke%MEKE)) \textcolor{keywordflow}{then}
00187 \textcolor{comment}{!   call MOM\_error(FATAL, "MOM\_MEKE: MEKE%MEKE is not associated!")}
00188     \textcolor{keywordflow}{return}
00189 \textcolor{keywordflow}{  endif}
00190 
00191     \textcolor{keywordflow}{if} (cs%debug) \textcolor{keywordflow}{then}
00192       \textcolor{keywordflow}{if} (\textcolor{keyword}{associated}(meke%mom\_src)) &
00193         \textcolor{keyword}{call }hchksum(meke%mom\_src, \textcolor{stringliteral}{'MEKE mom\_src'}, g%HI, scale=us%RZ3\_T3\_to\_W\_m2*us%L\_to\_Z**2)
00194       \textcolor{keywordflow}{if} (\textcolor{keyword}{associated}(meke%GME\_snk)) &
00195         \textcolor{keyword}{call }hchksum(meke%GME\_snk, \textcolor{stringliteral}{'MEKE GME\_snk'}, g%HI, scale=us%RZ3\_T3\_to\_W\_m2*us%L\_to\_Z**2)
00196       \textcolor{keywordflow}{if} (\textcolor{keyword}{associated}(meke%GM\_src)) &
00197         \textcolor{keyword}{call }hchksum(meke%GM\_src, \textcolor{stringliteral}{'MEKE GM\_src'}, g%HI, scale=us%RZ3\_T3\_to\_W\_m2*us%L\_to\_Z**2)
00198       \textcolor{keywordflow}{if} (\textcolor{keyword}{associated}(meke%MEKE)) \textcolor{keyword}{call }hchksum(meke%MEKE, \textcolor{stringliteral}{'MEKE MEKE'}, g%HI, scale=us%L\_T\_to\_m\_s**2)
00199       \textcolor{keyword}{call }uvchksum(\textcolor{stringliteral}{"MEKE SN\_[uv]"}, sn\_u, sn\_v, g%HI, scale=us%s\_to\_T, &
00200                     scalar\_pair=.true.)
00201       \textcolor{keyword}{call }uvchksum(\textcolor{stringliteral}{"MEKE h[uv]"}, hu, hv, g%HI, haloshift=1, &
00202                     scale=gv%H\_to\_m*(us%L\_to\_m**2))
00203 \textcolor{keywordflow}{    endif}
00204 
00205     sdt = dt*cs%MEKE\_dtScale \textcolor{comment}{! Scaled dt to use for time-stepping}
00206     rho0 = gv%Rho0
00207     mass\_neglect = gv%H\_to\_RZ * gv%H\_subroundoff
00208     cdrag2 = cs%cdrag**2
00209 
00210     \textcolor{comment}{! With a depth-dependent (and possibly strong) damping, it seems}
00211     \textcolor{comment}{! advisable to use Strang splitting between the damping and diffusion.}
00212     sdt\_damp = sdt ; \textcolor{keywordflow}{if} (cs%MEKE\_KH >= 0.0 .or. cs%MEKE\_K4 >= 0.) sdt\_damp = 0.5*sdt
00213 
00214     \textcolor{comment}{! Calculate depth integrated mass exchange if doing advection [R Z L2 ~> kg]}
00215     \textcolor{keywordflow}{if} (cs%MEKE\_advection\_factor>0.) \textcolor{keywordflow}{then}
00216       \textcolor{keywordflow}{do} j=js,je ; \textcolor{keywordflow}{do} i=is-1,ie
00217         barohu(i,j) = 0.
00218 \textcolor{keywordflow}{      enddo} ;\textcolor{keywordflow}{ enddo}
00219       \textcolor{keywordflow}{do} k=1,nz
00220         \textcolor{keywordflow}{do} j=js,je ; \textcolor{keywordflow}{do} i=is-1,ie
00221           barohu(i,j) = hu(i,j,k) * gv%H\_to\_RZ
00222 \textcolor{keywordflow}{        enddo} ;\textcolor{keywordflow}{ enddo}
00223 \textcolor{keywordflow}{      enddo}
00224       \textcolor{keywordflow}{do} j=js-1,je ; \textcolor{keywordflow}{do} i=is,ie
00225         barohv(i,j) = 0.
00226 \textcolor{keywordflow}{      enddo} ;\textcolor{keywordflow}{ enddo}
00227       \textcolor{keywordflow}{do} k=1,nz
00228         \textcolor{keywordflow}{do} j=js-1,je ; \textcolor{keywordflow}{do} i=is,ie
00229           barohv(i,j) = hv(i,j,k) * gv%H\_to\_RZ
00230 \textcolor{keywordflow}{        enddo} ;\textcolor{keywordflow}{ enddo}
00231 \textcolor{keywordflow}{      enddo}
00232 \textcolor{keywordflow}{    endif}
00233 
00234     \textcolor{keywordflow}{if} (cs%MEKE\_Cd\_scale == 0.0 .and. .not. cs%visc\_drag) \textcolor{keywordflow}{then}
00235       \textcolor{comment}{!$OMP parallel do default(shared) private(ldamping)}
00236       \textcolor{keywordflow}{do} j=js,je ; \textcolor{keywordflow}{do} i=is,ie
00237         drag\_rate(i,j) = 0. ; drag\_rate\_j15(i,j) = 0.
00238 \textcolor{keywordflow}{      enddo} ;\textcolor{keywordflow}{ enddo}
00239 \textcolor{keywordflow}{    endif}
00240 
00241     \textcolor{comment}{! Calculate drag\_rate\_visc(i,j) which accounts for the model bottom mean flow}
00242     \textcolor{keywordflow}{if} (cs%visc\_drag) \textcolor{keywordflow}{then}
00243       \textcolor{comment}{!$OMP parallel do default(shared)}
00244       \textcolor{keywordflow}{do} j=js,je ; \textcolor{keywordflow}{do} i=is-1,ie
00245         drag\_vel\_u(i,j) = 0.0
00246         \textcolor{keywordflow}{if} ((g%mask2dCu(i,j) > 0.0) .and. (visc%bbl\_thick\_u(i,j) > 0.0)) &
00247           drag\_vel\_u(i,j) = visc%Kv\_bbl\_u(i,j) / visc%bbl\_thick\_u(i,j)
00248 \textcolor{keywordflow}{      enddo} ;\textcolor{keywordflow}{ enddo}
00249       \textcolor{comment}{!$OMP parallel do default(shared)}
00250       \textcolor{keywordflow}{do} j=js-1,je ; \textcolor{keywordflow}{do} i=is,ie
00251         drag\_vel\_v(i,j) = 0.0
00252         \textcolor{keywordflow}{if} ((g%mask2dCv(i,j) > 0.0) .and. (visc%bbl\_thick\_v(i,j) > 0.0)) &
00253           drag\_vel\_v(i,j) = visc%Kv\_bbl\_v(i,j) / visc%bbl\_thick\_v(i,j)
00254 \textcolor{keywordflow}{      enddo} ;\textcolor{keywordflow}{ enddo}
00255 
00256       \textcolor{comment}{!$OMP parallel do default(shared)}
00257       \textcolor{keywordflow}{do} j=js,je ; \textcolor{keywordflow}{do} i=is,ie
00258         drag\_rate\_visc(i,j) = (0.25*g%IareaT(i,j) * us%Z\_to\_L * &
00259                 ((g%areaCu(i-1,j)*drag\_vel\_u(i-1,j) + &
00260                   g%areaCu(i,j)*drag\_vel\_u(i,j)) + &
00261                  (g%areaCv(i,j-1)*drag\_vel\_v(i,j-1) + &
00262                   g%areaCv(i,j)*drag\_vel\_v(i,j)) ) )
00263 \textcolor{keywordflow}{      enddo} ;\textcolor{keywordflow}{ enddo}
00264     \textcolor{keywordflow}{else}
00265       \textcolor{comment}{!$OMP parallel do default(shared)}
00266       \textcolor{keywordflow}{do} j=js,je ; \textcolor{keywordflow}{do} i=is,ie
00267         drag\_rate\_visc(i,j) = 0.
00268 \textcolor{keywordflow}{      enddo} ;\textcolor{keywordflow}{ enddo}
00269 \textcolor{keywordflow}{    endif}
00270 
00271     \textcolor{comment}{!$OMP parallel do default(shared)}
00272     \textcolor{keywordflow}{do} j=js-1,je+1
00273       \textcolor{keywordflow}{do} i=is-1,ie+1 ; mass(i,j) = 0.0 ;\textcolor{keywordflow}{ enddo}
00274       \textcolor{keywordflow}{do} k=1,nz ; \textcolor{keywordflow}{do} i=is-1,ie+1
00275         mass(i,j) = mass(i,j) + g%mask2dT(i,j) * (gv%H\_to\_RZ * h(i,j,k)) \textcolor{comment}{! [R Z ~> kg m-2]}
00276 \textcolor{keywordflow}{      enddo} ;\textcolor{keywordflow}{ enddo}
00277       \textcolor{keywordflow}{do} i=is-1,ie+1
00278         i\_mass(i,j) = 0.0
00279         \textcolor{keywordflow}{if} (mass(i,j) > 0.0) i\_mass(i,j) = 1.0 / mass(i,j) \textcolor{comment}{! [R-1 Z-1 ~> m2 kg-1]}
00280 \textcolor{keywordflow}{      enddo}
00281 \textcolor{keywordflow}{    enddo}
00282 
00283     \textcolor{keywordflow}{if} (cs%initialize) \textcolor{keywordflow}{then}
00284       \textcolor{keyword}{call }meke\_equilibrium(cs, meke, g, gv, us, sn\_u, sn\_v, drag\_rate\_visc, i\_mass)
00285       cs%initialize = .false.
00286 \textcolor{keywordflow}{    endif}
00287 
00288     \textcolor{comment}{! Calculates bottomFac2, barotrFac2 and LmixScale}
00289     \textcolor{keyword}{call }meke\_lengthscales(cs, meke, g, gv, us, sn\_u, sn\_v, meke%MEKE, bottomfac2, barotrfac2, lmixscale)
00290     \textcolor{keywordflow}{if} (cs%debug) \textcolor{keywordflow}{then}
00291       \textcolor{keywordflow}{if} (cs%visc\_drag) &
00292         \textcolor{keyword}{call }uvchksum(\textcolor{stringliteral}{"MEKE drag\_vel\_[uv]"}, drag\_vel\_u, drag\_vel\_v, g%HI, &
00293                       scale=us%Z\_to\_m*us%s\_to\_T, scalar\_pair=.true.)
00294       \textcolor{keyword}{call }hchksum(mass, \textcolor{stringliteral}{'MEKE mass'},g%HI,haloshift=1, scale=us%RZ\_to\_kg\_m2)
00295       \textcolor{keyword}{call }hchksum(drag\_rate\_visc, \textcolor{stringliteral}{'MEKE drag\_rate\_visc'}, g%HI, scale=us%L\_T\_to\_m\_s)
00296       \textcolor{keyword}{call }hchksum(bottomfac2, \textcolor{stringliteral}{'MEKE bottomFac2'}, g%HI)
00297       \textcolor{keyword}{call }hchksum(barotrfac2, \textcolor{stringliteral}{'MEKE barotrFac2'}, g%HI)
00298       \textcolor{keyword}{call }hchksum(lmixscale, \textcolor{stringliteral}{'MEKE LmixScale'}, g%HI,scale=us%L\_to\_m)
00299 \textcolor{keywordflow}{    endif}
00300 
00301     \textcolor{comment}{! Aggregate sources of MEKE (background, frictional and GM)}
00302     \textcolor{comment}{!$OMP parallel do default(shared)}
00303     \textcolor{keywordflow}{do} j=js,je ; \textcolor{keywordflow}{do} i=is,ie
00304       src(i,j) = cs%MEKE\_BGsrc
00305 \textcolor{keywordflow}{    enddo} ;\textcolor{keywordflow}{ enddo}
00306 
00307     \textcolor{keywordflow}{if} (\textcolor{keyword}{associated}(meke%mom\_src)) \textcolor{keywordflow}{then}
00308       \textcolor{comment}{!$OMP parallel do default(shared)}
00309       \textcolor{keywordflow}{do} j=js,je ; \textcolor{keywordflow}{do} i=is,ie
00310         src(i,j) = src(i,j) - cs%MEKE\_FrCoeff*i\_mass(i,j)*meke%mom\_src(i,j)
00311 \textcolor{keywordflow}{      enddo} ;\textcolor{keywordflow}{ enddo}
00312 \textcolor{keywordflow}{    endif}
00313 
00314     \textcolor{keywordflow}{if} (\textcolor{keyword}{associated}(meke%GME\_snk)) \textcolor{keywordflow}{then}
00315       \textcolor{comment}{!$OMP parallel do default(shared)}
00316       \textcolor{keywordflow}{do} j=js,je ; \textcolor{keywordflow}{do} i=is,ie
00317         src(i,j) = src(i,j) - cs%MEKE\_GMECoeff*i\_mass(i,j)*meke%GME\_snk(i,j)
00318 \textcolor{keywordflow}{      enddo} ;\textcolor{keywordflow}{ enddo}
00319 \textcolor{keywordflow}{    endif}
00320 
00321     \textcolor{keywordflow}{if} (\textcolor{keyword}{associated}(meke%GM\_src)) \textcolor{keywordflow}{then}
00322       \textcolor{keywordflow}{if} (cs%GM\_src\_alt) \textcolor{keywordflow}{then}
00323         \textcolor{comment}{!$OMP parallel do default(shared)}
00324         \textcolor{keywordflow}{do} j=js,je ; \textcolor{keywordflow}{do} i=is,ie
00325           src(i,j) = src(i,j) - cs%MEKE\_GMcoeff*meke%GM\_src(i,j) / &
00326                      (gv%Rho0 * max(1.0*us%m\_to\_Z, g%bathyT(i,j)))
00327 \textcolor{keywordflow}{        enddo} ;\textcolor{keywordflow}{ enddo}
00328       \textcolor{keywordflow}{else}
00329         \textcolor{comment}{!$OMP parallel do default(shared)}
00330         \textcolor{keywordflow}{do} j=js,je ; \textcolor{keywordflow}{do} i=is,ie
00331           src(i,j) = src(i,j) - cs%MEKE\_GMcoeff*i\_mass(i,j)*meke%GM\_src(i,j)
00332 \textcolor{keywordflow}{        enddo} ;\textcolor{keywordflow}{ enddo}
00333 \textcolor{keywordflow}{      endif}
00334 \textcolor{keywordflow}{    endif}
00335 
00336     \textcolor{keywordflow}{if} (cs%MEKE\_equilibrium\_restoring) \textcolor{keywordflow}{then}
00337       \textcolor{keyword}{call }meke\_equilibrium\_restoring(cs, g, us, sn\_u, sn\_v)
00338       \textcolor{keywordflow}{do} j=js,je ; \textcolor{keywordflow}{do} i=is,ie
00339         src(i,j) = src(i,j) - cs%MEKE\_restoring\_rate*(meke%MEKE(i,j) - cs%equilibrium\_value(i,j))
00340 \textcolor{keywordflow}{      enddo} ;\textcolor{keywordflow}{ enddo}
00341 \textcolor{keywordflow}{    endif}
00342 
00343     \textcolor{comment}{! Increase EKE by a full time-steps worth of source}
00344     \textcolor{comment}{!$OMP parallel do default(shared)}
00345     \textcolor{keywordflow}{do} j=js,je ; \textcolor{keywordflow}{do} i=is,ie
00346       meke%MEKE(i,j) = (meke%MEKE(i,j) + sdt*src(i,j))*g%mask2dT(i,j)
00347 \textcolor{keywordflow}{    enddo} ;\textcolor{keywordflow}{ enddo}
00348 
00349     \textcolor{keywordflow}{if} (use\_drag\_rate) \textcolor{keywordflow}{then}
00350       \textcolor{comment}{! Calculate a viscous drag rate (includes BBL contributions from mean flow and eddies)}
00351       \textcolor{comment}{!$OMP parallel do default(shared)}
00352       \textcolor{keywordflow}{do} j=js,je ; \textcolor{keywordflow}{do} i=is,ie
00353         drag\_rate(i,j) = (us%L\_to\_Z*rho0 * i\_mass(i,j)) * sqrt( drag\_rate\_visc(i,j)**2 + &
00354                  cdrag2 * ( max(0.0, 2.0*bottomfac2(i,j)*meke%MEKE(i,j)) + cs%MEKE\_Uscale**2 ) )
00355 \textcolor{keywordflow}{      enddo} ;\textcolor{keywordflow}{ enddo}
00356 \textcolor{keywordflow}{    endif}
00357 
00358     \textcolor{comment}{! First stage of Strang splitting}
00359     \textcolor{comment}{!$OMP parallel do default(shared)}
00360     \textcolor{keywordflow}{do} j=js,je ; \textcolor{keywordflow}{do} i=is,ie
00361       ldamping = cs%MEKE\_damping + drag\_rate(i,j) * bottomfac2(i,j)
00362       \textcolor{keywordflow}{if} (meke%MEKE(i,j) < 0.) ldamping = 0.
00363       \textcolor{comment}{! notice that the above line ensures a damping only if MEKE is positive,}
00364       \textcolor{comment}{! while leaving MEKE unchanged if it is negative}
00365       meke%MEKE(i,j) =  meke%MEKE(i,j) / (1.0 + sdt\_damp*ldamping)
00366       meke\_decay(i,j) = ldamping*g%mask2dT(i,j)
00367 \textcolor{keywordflow}{    enddo} ;\textcolor{keywordflow}{ enddo}
00368 
00369     \textcolor{keywordflow}{if} (cs%kh\_flux\_enabled .or. cs%MEKE\_K4 >= 0.0) \textcolor{keywordflow}{then}
00370       \textcolor{comment}{! Update MEKE in the halos for lateral or bi-harmonic diffusion}
00371       \textcolor{keyword}{call }cpu\_clock\_begin(cs%id\_clock\_pass)
00372       \textcolor{keyword}{call }do\_group\_pass(cs%pass\_MEKE, g%Domain)
00373       \textcolor{keyword}{call }cpu\_clock\_end(cs%id\_clock\_pass)
00374 \textcolor{keywordflow}{    endif}
00375 
00376     \textcolor{keywordflow}{if} (cs%MEKE\_K4 >= 0.0) \textcolor{keywordflow}{then}
00377       \textcolor{comment}{! Calculate Laplacian of MEKE using MEKE\_uflux and MEKE\_vflux as temporary work space.}
00378       \textcolor{comment}{!$OMP parallel do default(shared)}
00379       \textcolor{keywordflow}{do} j=js-1,je+1 ; \textcolor{keywordflow}{do} i=is-2,ie+1
00380         \textcolor{comment}{! MEKE\_uflux is used here as workspace with units of [L2 T-2 ~> m2 s-2].}
00381         meke\_uflux(i,j) = ((g%dy\_Cu(i,j)*g%IdxCu(i,j)) * g%mask2dCu(i,j)) * &
00382             (meke%MEKE(i+1,j) - meke%MEKE(i,j))
00383       \textcolor{comment}{! This would have units of [R Z L2 T-2 ~> kg s-2]}
00384       \textcolor{comment}{! MEKE\_uflux(I,j) = ((G%dy\_Cu(I,j)*G%IdxCu(I,j)) * &}
00385       \textcolor{comment}{!     ((2.0*mass(i,j)*mass(i+1,j)) / ((mass(i,j)+mass(i+1,j)) + mass\_neglect)) ) * &}
00386       \textcolor{comment}{!     (MEKE%MEKE(i+1,j) - MEKE%MEKE(i,j))}
00387 \textcolor{keywordflow}{      enddo} ;\textcolor{keywordflow}{ enddo}
00388       \textcolor{comment}{!$OMP parallel do default(shared)}
00389       \textcolor{keywordflow}{do} j=js-2,je+1 ; \textcolor{keywordflow}{do} i=is-1,ie+1
00390         \textcolor{comment}{! MEKE\_vflux is used here as workspace with units of [L2 T-2 ~> m2 s-2].}
00391         meke\_vflux(i,j) = ((g%dx\_Cv(i,j)*g%IdyCv(i,j)) * g%mask2dCv(i,j)) * &
00392             (meke%MEKE(i,j+1) - meke%MEKE(i,j))
00393       \textcolor{comment}{! This would have units of [R Z L2 T-2 ~> kg s-2]}
00394       \textcolor{comment}{! MEKE\_vflux(i,J) = ((G%dx\_Cv(i,J)*G%IdyCv(i,J)) * &}
00395       \textcolor{comment}{!     ((2.0*mass(i,j)*mass(i,j+1)) / ((mass(i,j)+mass(i,j+1)) + mass\_neglect)) ) * &}
00396       \textcolor{comment}{!     (MEKE%MEKE(i,j+1) - MEKE%MEKE(i,j))}
00397 \textcolor{keywordflow}{      enddo} ;\textcolor{keywordflow}{ enddo}
00398 
00399       \textcolor{comment}{!$OMP parallel do default(shared)}
00400       \textcolor{keywordflow}{do} j=js-1,je+1 ; \textcolor{keywordflow}{do} i=is-1,ie+1 \textcolor{comment}{! del2MEKE has units [T-2 ~> s-2].}
00401         del2meke(i,j) = g%IareaT(i,j) * &
00402             ((meke\_uflux(i,j) - meke\_uflux(i-1,j)) + (meke\_vflux(i,j) - meke\_vflux(i,j-1)))
00403 \textcolor{keywordflow}{      enddo} ;\textcolor{keywordflow}{ enddo}
00404 
00405       \textcolor{comment}{! Bi-harmonic diffusion of MEKE}
00406       \textcolor{comment}{!$OMP parallel do default(shared) private(K4\_here,Inv\_K4\_max)}
00407       \textcolor{keywordflow}{do} j=js,je ; \textcolor{keywordflow}{do} i=is-1,ie
00408         k4\_here = cs%MEKE\_K4 \textcolor{comment}{! [L4 T-1 ~> m4 s-1]}
00409         \textcolor{comment}{! Limit Kh to avoid CFL violations.}
00410         inv\_k4\_max = 64.0 * sdt * ((g%dy\_Cu(i,j)*g%IdxCu(i,j)) * &
00411                      max(g%IareaT(i,j), g%IareaT(i+1,j)))**2
00412         \textcolor{keywordflow}{if} (k4\_here*inv\_k4\_max > 0.3) k4\_here = 0.3 / inv\_k4\_max
00413 
00414         \textcolor{comment}{! Here the units of MEKE\_uflux are [R Z L4 T-3 ~> kg m2 s-3].}
00415         meke\_uflux(i,j) = ((k4\_here * (g%dy\_Cu(i,j)*g%IdxCu(i,j))) * &
00416             ((2.0*mass(i,j)*mass(i+1,j)) / ((mass(i,j)+mass(i+1,j)) + mass\_neglect)) ) * &
00417             (del2meke(i+1,j) - del2meke(i,j))
00418 \textcolor{keywordflow}{      enddo} ;\textcolor{keywordflow}{ enddo}
00419       \textcolor{comment}{!$OMP parallel do default(shared) private(K4\_here,Inv\_K4\_max)}
00420       \textcolor{keywordflow}{do} j=js-1,je ; \textcolor{keywordflow}{do} i=is,ie
00421         k4\_here = cs%MEKE\_K4 \textcolor{comment}{! [L4 T-1 ~> m4 s-1]}
00422         inv\_k4\_max = 64.0 * sdt * ((g%dx\_Cv(i,j)*g%IdyCv(i,j)) * max(g%IareaT(i,j), g%IareaT(i,j+1)))**2
00423         \textcolor{keywordflow}{if} (k4\_here*inv\_k4\_max > 0.3) k4\_here = 0.3 / inv\_k4\_max
00424 
00425         \textcolor{comment}{! Here the units of MEKE\_vflux are [R Z L4 T-3 ~> kg m2 s-3].}
00426         meke\_vflux(i,j) = ((k4\_here * (g%dx\_Cv(i,j)*g%IdyCv(i,j))) * &
00427             ((2.0*mass(i,j)*mass(i,j+1)) / ((mass(i,j)+mass(i,j+1)) + mass\_neglect)) ) * &
00428             (del2meke(i,j+1) - del2meke(i,j))
00429 \textcolor{keywordflow}{      enddo} ;\textcolor{keywordflow}{ enddo}
00430       \textcolor{comment}{! Store change in MEKE arising from the bi-harmonic in del4MEKE [L2 T-2 ~> m2 s-2].}
00431       \textcolor{comment}{!$OMP parallel do default(shared)}
00432       \textcolor{keywordflow}{do} j=js,je ; \textcolor{keywordflow}{do} i=is,ie
00433         del4meke(i,j) = (sdt*(g%IareaT(i,j)*i\_mass(i,j))) * &
00434             ((meke\_uflux(i-1,j) - meke\_uflux(i,j)) + &
00435              (meke\_vflux(i,j-1) - meke\_vflux(i,j)))
00436 \textcolor{keywordflow}{      enddo} ;\textcolor{keywordflow}{ enddo}
00437 \textcolor{keywordflow}{    endif} \textcolor{comment}{!}
00438 
00439     \textcolor{keywordflow}{if} (cs%kh\_flux\_enabled) \textcolor{keywordflow}{then}
00440       \textcolor{comment}{! Lateral diffusion of MEKE}
00441       kh\_here = max(0., cs%MEKE\_Kh)
00442       \textcolor{comment}{!$OMP parallel do default(shared) firstprivate(Kh\_here) private(Inv\_Kh\_max)}
00443       \textcolor{keywordflow}{do} j=js,je ; \textcolor{keywordflow}{do} i=is-1,ie
00444         \textcolor{comment}{! Limit Kh to avoid CFL violations.}
00445         \textcolor{keywordflow}{if} (\textcolor{keyword}{associated}(meke%Kh)) &
00446           kh\_here = max(0., cs%MEKE\_Kh) + &
00447               cs%KhMEKE\_Fac*0.5*(meke%Kh(i,j)+meke%Kh(i+1,j))
00448         \textcolor{keywordflow}{if} (\textcolor{keyword}{associated}(meke%Kh\_diff)) &
00449           kh\_here = max(0.,cs%MEKE\_Kh) + &
00450               cs%KhMEKE\_Fac*0.5*(meke%Kh\_diff(i,j)+meke%Kh\_diff(i+1,j))
00451         inv\_kh\_max = 2.0*sdt * ((g%dy\_Cu(i,j)*g%IdxCu(i,j)) * &
00452                      max(g%IareaT(i,j),g%IareaT(i+1,j)))
00453         \textcolor{keywordflow}{if} (kh\_here*inv\_kh\_max > 0.25) kh\_here = 0.25 / inv\_kh\_max
00454         kh\_u(i,j) = kh\_here
00455 
00456         \textcolor{comment}{! Here the units of MEKE\_uflux and MEKE\_vflux are [R Z L4 T-3 ~> kg m2 s-3].}
00457         meke\_uflux(i,j) = ((kh\_here * (g%dy\_Cu(i,j)*g%IdxCu(i,j))) * &
00458             ((2.0*mass(i,j)*mass(i+1,j)) / ((mass(i,j)+mass(i+1,j)) + mass\_neglect)) ) * &
00459             (meke%MEKE(i,j) - meke%MEKE(i+1,j))
00460 \textcolor{keywordflow}{      enddo} ;\textcolor{keywordflow}{ enddo}
00461       \textcolor{comment}{!$OMP parallel do default(shared) firstprivate(Kh\_here) private(Inv\_Kh\_max)}
00462       \textcolor{keywordflow}{do} j=js-1,je ; \textcolor{keywordflow}{do} i=is,ie
00463         \textcolor{keywordflow}{if} (\textcolor{keyword}{associated}(meke%Kh)) &
00464           kh\_here = max(0.,cs%MEKE\_Kh) + cs%KhMEKE\_Fac * 0.5*(meke%Kh(i,j)+meke%Kh(i,j+1))
00465         \textcolor{keywordflow}{if} (\textcolor{keyword}{associated}(meke%Kh\_diff)) &
00466           kh\_here = max(0.,cs%MEKE\_Kh) + cs%KhMEKE\_Fac * 0.5*(meke%Kh\_diff(i,j)+meke%Kh\_diff(i,j+1))
00467         inv\_kh\_max = 2.0*sdt * ((g%dx\_Cv(i,j)*g%IdyCv(i,j)) * max(g%IareaT(i,j),g%IareaT(i,j+1)))
00468         \textcolor{keywordflow}{if} (kh\_here*inv\_kh\_max > 0.25) kh\_here = 0.25 / inv\_kh\_max
00469         kh\_v(i,j) = kh\_here
00470 
00471         \textcolor{comment}{! Here the units of MEKE\_uflux and MEKE\_vflux are [R Z L4 T-3 ~> kg m2 s-3].}
00472         meke\_vflux(i,j) = ((kh\_here * (g%dx\_Cv(i,j)*g%IdyCv(i,j))) * &
00473             ((2.0*mass(i,j)*mass(i,j+1)) / ((mass(i,j)+mass(i,j+1)) + mass\_neglect)) ) * &
00474             (meke%MEKE(i,j) - meke%MEKE(i,j+1))
00475 \textcolor{keywordflow}{      enddo} ;\textcolor{keywordflow}{ enddo}
00476       \textcolor{keywordflow}{if} (cs%MEKE\_advection\_factor>0.) \textcolor{keywordflow}{then}
00477         advfac = cs%MEKE\_advection\_factor / sdt \textcolor{comment}{! [T-1 ~> s-1]}
00478         \textcolor{comment}{!$OMP parallel do default(shared)}
00479         \textcolor{keywordflow}{do} j=js,je ; \textcolor{keywordflow}{do} i=is-1,ie
00480           \textcolor{comment}{! Here the units of the quantities added to MEKE\_uflux are [R Z L4 T-3 ~> kg m2 s-3].}
00481           \textcolor{keywordflow}{if} (barohu(i,j)>0.) \textcolor{keywordflow}{then}
00482             meke\_uflux(i,j) = meke\_uflux(i,j) + barohu(i,j)*meke%MEKE(i,j)*advfac
00483           \textcolor{keywordflow}{elseif} (barohu(i,j)<0.) \textcolor{keywordflow}{then}
00484             meke\_uflux(i,j) = meke\_uflux(i,j) + barohu(i,j)*meke%MEKE(i+1,j)*advfac
00485 \textcolor{keywordflow}{          endif}
00486 \textcolor{keywordflow}{        enddo} ;\textcolor{keywordflow}{ enddo}
00487         \textcolor{comment}{!$OMP parallel do default(shared)}
00488         \textcolor{keywordflow}{do} j=js-1,je ; \textcolor{keywordflow}{do} i=is,ie
00489           \textcolor{comment}{! Here the units of the quantities added to MEKE\_vflux are [R Z L4 T-3 ~> kg m2 s-3].}
00490           \textcolor{keywordflow}{if} (barohv(i,j)>0.) \textcolor{keywordflow}{then}
00491             meke\_vflux(i,j) = meke\_vflux(i,j) + barohv(i,j)*meke%MEKE(i,j)*advfac
00492           \textcolor{keywordflow}{elseif} (barohv(i,j)<0.) \textcolor{keywordflow}{then}
00493             meke\_vflux(i,j) = meke\_vflux(i,j) + barohv(i,j)*meke%MEKE(i,j+1)*advfac
00494 \textcolor{keywordflow}{          endif}
00495 \textcolor{keywordflow}{        enddo} ;\textcolor{keywordflow}{ enddo}
00496 \textcolor{keywordflow}{      endif}
00497 
00498       \textcolor{comment}{!$OMP parallel do default(shared)}
00499       \textcolor{keywordflow}{do} j=js,je ; \textcolor{keywordflow}{do} i=is,ie
00500         meke%MEKE(i,j) = meke%MEKE(i,j) + (sdt*(g%IareaT(i,j)*i\_mass(i,j))) * &
00501             ((meke\_uflux(i-1,j) - meke\_uflux(i,j)) + &
00502              (meke\_vflux(i,j-1) - meke\_vflux(i,j)))
00503 \textcolor{keywordflow}{      enddo} ;\textcolor{keywordflow}{ enddo}
00504 \textcolor{keywordflow}{    endif} \textcolor{comment}{! MEKE\_KH>0}
00505 
00506     \textcolor{comment}{! Add on bi-harmonic tendency}
00507     \textcolor{keywordflow}{if} (cs%MEKE\_K4 >= 0.0) \textcolor{keywordflow}{then}
00508       \textcolor{comment}{!$OMP parallel do default(shared)}
00509       \textcolor{keywordflow}{do} j=js,je ; \textcolor{keywordflow}{do} i=is,ie
00510         meke%MEKE(i,j) = meke%MEKE(i,j) + del4meke(i,j)
00511 \textcolor{keywordflow}{      enddo} ;\textcolor{keywordflow}{ enddo}
00512 \textcolor{keywordflow}{    endif}
00513 
00514     \textcolor{comment}{! Second stage of Strang splitting}
00515     \textcolor{keywordflow}{if} (cs%MEKE\_KH >= 0.0 .or. cs%MEKE\_K4 >= 0.0) \textcolor{keywordflow}{then}
00516       \textcolor{keywordflow}{if} (sdt>sdt\_damp) \textcolor{keywordflow}{then}
00517         \textcolor{comment}{! Recalculate the drag rate, since MEKE has changed.}
00518         \textcolor{keywordflow}{if} (use\_drag\_rate) \textcolor{keywordflow}{then}
00519           \textcolor{comment}{!$OMP parallel do default(shared)}
00520           \textcolor{keywordflow}{do} j=js,je ; \textcolor{keywordflow}{do} i=is,ie
00521             drag\_rate(i,j) = (us%L\_to\_Z*rho0 * i\_mass(i,j)) * sqrt( drag\_rate\_visc(i,j)**2 + &
00522                    cdrag2 * ( max(0.0, 2.0*bottomfac2(i,j)*meke%MEKE(i,j)) + cs%MEKE\_Uscale**2 ) )
00523 \textcolor{keywordflow}{          enddo} ;\textcolor{keywordflow}{ enddo}
00524           \textcolor{comment}{!$OMP parallel do default(shared)}
00525           \textcolor{keywordflow}{do} j=js,je ; \textcolor{keywordflow}{do} i=is,ie
00526             ldamping = cs%MEKE\_damping + drag\_rate(i,j) * bottomfac2(i,j)
00527             \textcolor{keywordflow}{if} (meke%MEKE(i,j) < 0.) ldamping = 0.
00528             \textcolor{comment}{! notice that the above line ensures a damping only if MEKE is positive,}
00529             \textcolor{comment}{! while leaving MEKE unchanged if it is negative}
00530             meke%MEKE(i,j) =  meke%MEKE(i,j) / (1.0 + sdt\_damp*ldamping)
00531             meke\_decay(i,j) = ldamping*g%mask2dT(i,j)
00532 \textcolor{keywordflow}{          enddo} ;\textcolor{keywordflow}{ enddo}
00533 \textcolor{keywordflow}{        endif}
00534 \textcolor{keywordflow}{      endif}
00535 \textcolor{keywordflow}{    endif} \textcolor{comment}{! MEKE\_KH>=0}
00536 
00537  \textcolor{comment}{!   do j=js,je ; do i=is,ie}
00538  \textcolor{comment}{!     MEKE%MEKE(i,j) =  MAX(MEKE%MEKE(i,j),0.0)}
00539  \textcolor{comment}{!   enddo ; enddo}
00540 
00541     \textcolor{keyword}{call }cpu\_clock\_begin(cs%id\_clock\_pass)
00542     \textcolor{keyword}{call }do\_group\_pass(cs%pass\_MEKE, g%Domain)
00543     \textcolor{keyword}{call }cpu\_clock\_end(cs%id\_clock\_pass)
00544 
00545     \textcolor{comment}{! Calculate diffusivity for main model to use}
00546     \textcolor{keywordflow}{if} (cs%MEKE\_KhCoeff>0.) \textcolor{keywordflow}{then}
00547       \textcolor{keywordflow}{if} (.not.cs%MEKE\_GEOMETRIC) \textcolor{keywordflow}{then}
00548         \textcolor{keywordflow}{if} (cs%use\_old\_lscale) \textcolor{keywordflow}{then}
00549           \textcolor{keywordflow}{if} (cs%Rd\_as\_max\_scale) \textcolor{keywordflow}{then}
00550             \textcolor{comment}{!$OMP parallel do default(shared)}
00551             \textcolor{keywordflow}{do} j=js,je ; \textcolor{keywordflow}{do} i=is,ie
00552               meke%Kh(i,j) = (cs%MEKE\_KhCoeff * &
00553                          sqrt(2.*max(0.,barotrfac2(i,j)*meke%MEKE(i,j))*g%areaT(i,j)) ) * &
00554                          min(meke%Rd\_dx\_h(i,j), 1.0)
00555 \textcolor{keywordflow}{            enddo} ;\textcolor{keywordflow}{ enddo}
00556           \textcolor{keywordflow}{else}
00557             \textcolor{comment}{!$OMP parallel do default(shared)}
00558             \textcolor{keywordflow}{do} j=js,je ; \textcolor{keywordflow}{do} i=is,ie
00559               meke%Kh(i,j) = cs%MEKE\_KhCoeff * &
00560                   sqrt(2.*max(0., barotrfac2(i,j)*meke%MEKE(i,j))*g%areaT(i,j))
00561 \textcolor{keywordflow}{            enddo} ;\textcolor{keywordflow}{ enddo}
00562 \textcolor{keywordflow}{          endif}
00563         \textcolor{keywordflow}{else}
00564           \textcolor{comment}{!$OMP parallel do default(shared)}
00565           \textcolor{keywordflow}{do} j=js,je ; \textcolor{keywordflow}{do} i=is,ie
00566             meke%Kh(i,j) = cs%MEKE\_KhCoeff * &
00567                 sqrt(2.*max(0., barotrfac2(i,j)*meke%MEKE(i,j))) * lmixscale(i,j)
00568 \textcolor{keywordflow}{          enddo} ;\textcolor{keywordflow}{ enddo}
00569 \textcolor{keywordflow}{        endif}
00570 \textcolor{keywordflow}{      endif}
00571 \textcolor{keywordflow}{    endif}
00572 
00573     \textcolor{comment}{! Calculate viscosity for the main model to use}
00574     \textcolor{keywordflow}{if} (cs%viscosity\_coeff\_Ku /=0.) \textcolor{keywordflow}{then}
00575       \textcolor{keywordflow}{do} j=js,je ; \textcolor{keywordflow}{do} i=is,ie
00576         meke%Ku(i,j) = cs%viscosity\_coeff\_Ku * sqrt(2.*max(0.,meke%MEKE(i,j))) * lmixscale(i,j)
00577 \textcolor{keywordflow}{      enddo} ;\textcolor{keywordflow}{ enddo}
00578 \textcolor{keywordflow}{    endif}
00579 
00580     \textcolor{keywordflow}{if} (cs%viscosity\_coeff\_Au /=0.) \textcolor{keywordflow}{then}
00581       \textcolor{keywordflow}{do} j=js,je ; \textcolor{keywordflow}{do} i=is,ie
00582         meke%Au(i,j) = cs%viscosity\_coeff\_Au * sqrt(2.*max(0.,meke%MEKE(i,j))) * lmixscale(i,j)**3
00583 \textcolor{keywordflow}{      enddo} ;\textcolor{keywordflow}{ enddo}
00584 \textcolor{keywordflow}{    endif}
00585 
00586     \textcolor{keywordflow}{if} (\textcolor{keyword}{associated}(meke%Kh) .or. \textcolor{keyword}{associated}(meke%Ku) .or. \textcolor{keyword}{associated}(meke%Au)) \textcolor{keywordflow}{then}
00587       \textcolor{keyword}{call }cpu\_clock\_begin(cs%id\_clock\_pass)
00588       \textcolor{keyword}{call }do\_group\_pass(cs%pass\_Kh, g%Domain)
00589       \textcolor{keyword}{call }cpu\_clock\_end(cs%id\_clock\_pass)
00590 \textcolor{keywordflow}{    endif}
00591 
00592     \textcolor{comment}{! Offer fields for averaging.}
00593     \textcolor{keywordflow}{if} (any([cs%id\_Ue, cs%id\_Ub, cs%id\_Ut] > 0)) &
00594       tmp(:,:) = 0.
00595     \textcolor{keywordflow}{if} (cs%id\_MEKE>0) \textcolor{keyword}{call }post\_data(cs%id\_MEKE, meke%MEKE, cs%diag)
00596     \textcolor{keywordflow}{if} (cs%id\_Ue>0) \textcolor{keywordflow}{then}
00597       \textcolor{keywordflow}{do} j=js,je ; \textcolor{keywordflow}{do} i=is,ie
00598         tmp(i,j) = sqrt(max(0., 2. * meke%MEKE(i,j)))
00599 \textcolor{keywordflow}{      enddo} ;\textcolor{keywordflow}{ enddo}
00600       \textcolor{keyword}{call }post\_data(cs%id\_Ue, tmp, cs%diag)
00601 \textcolor{keywordflow}{    endif}
00602     \textcolor{keywordflow}{if} (cs%id\_Ub>0) \textcolor{keywordflow}{then}
00603       \textcolor{keywordflow}{do} j=js,je ; \textcolor{keywordflow}{do} i=is,ie
00604         tmp(i,j) = sqrt(max(0., 2. * meke%MEKE(i,j) * bottomfac2(i,j)))
00605 \textcolor{keywordflow}{      enddo} ;\textcolor{keywordflow}{ enddo}
00606       \textcolor{keyword}{call }post\_data(cs%id\_Ub, tmp, cs%diag)
00607 \textcolor{keywordflow}{    endif}
00608     \textcolor{keywordflow}{if} (cs%id\_Ut>0) \textcolor{keywordflow}{then}
00609       \textcolor{keywordflow}{do} j=js,je ; \textcolor{keywordflow}{do} i=is,ie
00610         tmp(i,j) = sqrt(max(0., 2. * meke%MEKE(i,j) * barotrfac2(i,j)))
00611 \textcolor{keywordflow}{      enddo} ;\textcolor{keywordflow}{ enddo}
00612       \textcolor{keyword}{call }post\_data(cs%id\_Ut, tmp, cs%diag)
00613 \textcolor{keywordflow}{    endif}
00614     \textcolor{keywordflow}{if} (cs%id\_Kh>0) \textcolor{keyword}{call }post\_data(cs%id\_Kh, meke%Kh, cs%diag)
00615     \textcolor{keywordflow}{if} (cs%id\_Ku>0) \textcolor{keyword}{call }post\_data(cs%id\_Ku, meke%Ku, cs%diag)
00616     \textcolor{keywordflow}{if} (cs%id\_Au>0) \textcolor{keyword}{call }post\_data(cs%id\_Au, meke%Au, cs%diag)
00617     \textcolor{keywordflow}{if} (cs%id\_KhMEKE\_u>0) \textcolor{keyword}{call }post\_data(cs%id\_KhMEKE\_u, kh\_u, cs%diag)
00618     \textcolor{keywordflow}{if} (cs%id\_KhMEKE\_v>0) \textcolor{keyword}{call }post\_data(cs%id\_KhMEKE\_v, kh\_v, cs%diag)
00619     \textcolor{keywordflow}{if} (cs%id\_src>0) \textcolor{keyword}{call }post\_data(cs%id\_src, src, cs%diag)
00620     \textcolor{keywordflow}{if} (cs%id\_decay>0) \textcolor{keyword}{call }post\_data(cs%id\_decay, meke\_decay, cs%diag)
00621     \textcolor{keywordflow}{if} (cs%id\_GM\_src>0) \textcolor{keyword}{call }post\_data(cs%id\_GM\_src, meke%GM\_src, cs%diag)
00622     \textcolor{keywordflow}{if} (cs%id\_mom\_src>0) \textcolor{keyword}{call }post\_data(cs%id\_mom\_src, meke%mom\_src, cs%diag)
00623     \textcolor{keywordflow}{if} (cs%id\_GME\_snk>0) \textcolor{keyword}{call }post\_data(cs%id\_GME\_snk, meke%GME\_snk, cs%diag)
00624     \textcolor{keywordflow}{if} (cs%id\_Le>0) \textcolor{keyword}{call }post\_data(cs%id\_Le, lmixscale, cs%diag)
00625     \textcolor{keywordflow}{if} (cs%id\_gamma\_b>0) \textcolor{keywordflow}{then}
00626       \textcolor{keywordflow}{do} j=js,je ; \textcolor{keywordflow}{do} i=is,ie
00627         bottomfac2(i,j) = sqrt(bottomfac2(i,j))
00628 \textcolor{keywordflow}{      enddo} ;\textcolor{keywordflow}{ enddo}
00629       \textcolor{keyword}{call }post\_data(cs%id\_gamma\_b, bottomfac2, cs%diag)
00630 \textcolor{keywordflow}{    endif}
00631     \textcolor{keywordflow}{if} (cs%id\_gamma\_t>0) \textcolor{keywordflow}{then}
00632       \textcolor{keywordflow}{do} j=js,je ; \textcolor{keywordflow}{do} i=is,ie
00633         barotrfac2(i,j) = sqrt(barotrfac2(i,j))
00634 \textcolor{keywordflow}{      enddo} ;\textcolor{keywordflow}{ enddo}
00635       \textcolor{keyword}{call }post\_data(cs%id\_gamma\_t, barotrfac2, cs%diag)
00636 \textcolor{keywordflow}{    endif}
00637 
\end{DoxyCode}
