\hypertarget{namespacemom__mixed__layer__restrat}{}\section{mom\+\_\+mixed\+\_\+layer\+\_\+restrat Module Reference}
\label{namespacemom__mixed__layer__restrat}\index{mom\+\_\+mixed\+\_\+layer\+\_\+restrat@{mom\+\_\+mixed\+\_\+layer\+\_\+restrat}}


\subsection{Detailed Description}
Parameterization of mixed layer restratification by unresolved mixed-\/layer eddies. 

\hypertarget{namespacemom__mixed__layer__restrat_section_mle}{}\subsection{Mixed-\/layer eddy parameterization module}\label{namespacemom__mixed__layer__restrat_section_mle}
The subroutines in this file implement a parameterization of unresolved viscous mixed layer restratification of the mixed layer as described in Fox-\/\+Kemper et al., 2008, and whose impacts are described in Fox-\/\+Kemper et al., 2011. This is derived in part from the older parameterization that is described in Hallberg (Aha Hulikoa, 2003), which this new parameterization surpasses, which in turn is based on the sub-\/inertial mixed layer theory of Young (J\+PO, 1994). There is no net horizontal volume transport due to this parameterization, and no direct effect below the mixed layer.

This parameterization sets the restratification timescale to agree with high-\/resolution studies of mixed layer restratification.

The run-\/time parameter F\+O\+X\+\_\+\+K\+E\+M\+P\+E\+R\+\_\+\+M\+L\+\_\+\+R\+E\+S\+T\+R\+A\+T\+\_\+\+C\+O\+EF is a non-\/dimensional number of order a few tens, proportional to the ratio of the deformation radius or the grid scale (whichever is smaller to the dominant horizontal length-\/scale of the sub-\/meso-\/scale mixed layer instabilities.\hypertarget{namespacemom__mixed__layer__restrat_section_mle_nutshell}{}\subsubsection{\char`\"{}\+Sub-\/meso\char`\"{} in a nutshell}\label{namespacemom__mixed__layer__restrat_section_mle_nutshell}
The parameterization is colloquially referred to as \char`\"{}sub-\/meso\char`\"{}.

The original Fox-\/\+Kemper et al., (2008b) paper proposed a quasi-\/\+Stokes advection described by the stream function (eq. 5 of Fox-\/\+Kemper et al., 2011)\+: \[ {\bf \Psi}_o = C_e \frac{ H^2 \nabla \bar{b} \times \hat{\bf z} }{ |f| } \mu(z) \]

where the vertical profile function is \[ \mu(z) = \max \left\{ 0, \left[ 1 - \left(\frac{2z}{H}+1\right)^2 \right] \left[ 1 + \frac{5}{21} \left(\frac{2z}{H}+1\right)^2 \right] \right\} \] and $ H $ is the mixed-\/layer depth, $ f $ is the local Coriolis parameter, $ C_e \sim 0.06-0.08 $ and $ \nabla \bar{b} $ is a depth mean buoyancy gradient averaged over the mixed layer.

For use in coarse-\/resolution models, an upscaling of the buoyancy gradients and adaption for the equator leads to the following parameterization (eq. 6 of Fox-\/\+Kemper et al., 2011)\+: \[ {\bf \Psi} = C_e \Gamma_\Delta \frac{\Delta s}{l_f} \frac{ H^2 \nabla \bar{b} \times \hat{\bf z} } { \sqrt{ f^2 + \tau^{-2}} } \mu(z) \] where $ \Delta s $ is the minimum of grid-\/scale and deformation radius, $ l_f $ is the width of the mixed-\/layer fronts, and $ \Gamma_\Delta=1 $. $ \tau $ is a time-\/scale for mixing momentum across the mixed layer. $ l_f $ is thought to be of order hundreds of meters.

The upscaling factor $ \frac{\Delta s}{l_f} $ can be a global constant, model parameter F\+O\+X\+\_\+\+K\+E\+M\+P\+E\+R\+\_\+\+M\+L\+\_\+\+R\+E\+S\+T\+R\+AT, so that in practice the parameterization is\+: \[ {\bf \Psi} = C_e \Gamma_\Delta \frac{ H^2 \nabla \bar{b} \times \hat{\bf z} }{ \sqrt{ f^2 + \tau^{-2}} } \mu(z) \] with non-\/unity $ \Gamma_\Delta $.

$ C_e $ is hard-\/coded as 0.\+0625. $ \tau $ is calculated from the surface friction velocity $ u^* $. \begin{DoxyRefDesc}{Todo}
\item[\mbox{\hyperlink{todo__todo000003}{Todo}}]Explain expression for momentum mixing time-\/scale.\end{DoxyRefDesc}
\hypertarget{namespacemom__mixed__layer__restrat_section_mle_filtering}{}\subsubsection{Time-\/filtering of mixed-\/layer depth}\label{namespacemom__mixed__layer__restrat_section_mle_filtering}
Using the instantaneous mixed-\/layer depth is inconsistent with the finite life-\/time of mixed-\/layer instabilities. We provide a one-\/sided running-\/mean filter of mixed-\/layer depth, $ H $, of the form\+: \[ \bar{H} \leftarrow \max \left( H, \frac{ \Delta t H + \tau_h \bar{H} }{ \Delta t + \tau_h } \right) \] which allows the effective mixed-\/layer depth seen by the parameterization, $\bar{H}$, to instantaneously deepen but to decay with time-\/scale $ \tau_h $. $ \bar{H} $ is substituted for $ H $ in the above equations.\hypertarget{namespacemom__mixed__layer__restrat_section_mle_mld}{}\subsubsection{Defining the mixed-\/layer-\/depth}\label{namespacemom__mixed__layer__restrat_section_mle_mld}
If the parameter M\+L\+E\+\_\+\+U\+S\+E\+\_\+\+P\+B\+L\+\_\+\+M\+LD=True then the mixed-\/layer depth is defined/diagnosed by the boundary-\/layer parameterization (e.\+g. e\+P\+BL, K\+PP, etc.).

If the parameter M\+L\+E\+\_\+\+U\+S\+E\+\_\+\+P\+B\+L\+\_\+\+M\+LD=False then the mixed-\/layer depth is diagnosed in this module as the depth of a given density difference, $ \Delta \rho $, with the surface where the density difference is the parameter M\+L\+E\+\_\+\+D\+E\+N\+S\+I\+T\+Y\+\_\+\+D\+I\+FF.\hypertarget{namespacemom__mixed__layer__restrat_section_mle_ref}{}\subsubsection{References}\label{namespacemom__mixed__layer__restrat_section_mle_ref}
Fox-\/\+Kemper, B., Ferrari, R. and Hallberg, R., 2008\+: Parameterization of Mixed Layer Eddies. Part I\+: Theory and Diagnosis J. Phys. Oceangraphy, 38 (6), p1145-\/1165. \href{https://doi.org/10.1175/2007JPO3792.1}{\tt https\+://doi.\+org/10.\+1175/2007\+J\+P\+O3792.\+1}

Fox-\/\+Kemper, B. and Ferrari, R. 2008\+: Parameterization of Mixed Layer Eddies. Part II\+: Prognosis and Impact J. Phys. Oceangraphy, 38 (6), p1166-\/1179. \href{https://doi.org/10.1175/2007JPO3788.1}{\tt https\+://doi.\+org/10.\+1175/2007\+J\+P\+O3788.\+1}

B. Fox-\/\+Kemper, G. Danabasoglu, R. Ferrari, S.\+M. Griffies, R.\+W. Hallberg, M.\+M. Holland, M.\+E. Maltrud, S. Peacock, and B.\+L. Samuels, 2011\+: Parameterization of mixed layer eddies. I\+II\+: Implementation and impact in global ocean climate simulations. Ocean Modell., 39(1), p61-\/78. \href{https://doi.org/10.1016/j.ocemod.2010.09.002}{\tt https\+://doi.\+org/10.\+1016/j.\+ocemod.\+2010.\+09.\+002}

\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
$ \Gamma_\Delta $  &F\+O\+X\+\_\+\+K\+E\+M\+P\+E\+R\+\_\+\+M\+L\+\_\+\+R\+E\+S\+T\+R\+AT   \\\cline{1-2}
$ l_f $  &M\+L\+E\+\_\+\+F\+R\+O\+N\+T\+\_\+\+L\+E\+N\+G\+TH   \\\cline{1-2}
$ \tau_h $  &M\+L\+E\+\_\+\+M\+L\+D\+\_\+\+D\+E\+C\+A\+Y\+\_\+\+T\+I\+ME   \\\cline{1-2}
$ \Delta \rho $  &M\+L\+E\+\_\+\+D\+E\+N\+S\+I\+T\+Y\+\_\+\+D\+I\+FF   \\\cline{1-2}
\end{longtabu}
\subsection*{Data Types}
\begin{DoxyCompactItemize}
\item 
type \mbox{\hyperlink{structmom__mixed__layer__restrat_1_1mixedlayer__restrat__cs}{mixedlayer\+\_\+restrat\+\_\+cs}}
\begin{DoxyCompactList}\small\item\em Control structure for \mbox{\hyperlink{namespacemom__mixed__layer__restrat}{mom\+\_\+mixed\+\_\+layer\+\_\+restrat}}. \end{DoxyCompactList}\end{DoxyCompactItemize}
\subsection*{Functions/\+Subroutines}
\begin{DoxyCompactItemize}
\item 
subroutine, public \mbox{\hyperlink{namespacemom__mixed__layer__restrat_a9dfb1879cd5a1ef890f3fc329f961ea0}{mixedlayer\+\_\+restrat}} (h, uhtr, vhtr, tv, forces, dt, M\+LD, Var\+Mix, G, GV, US, CS)
\begin{DoxyCompactList}\small\item\em Driver for the mixed-\/layer restratification parameterization. The code branches between two different implementations depending on whether the bulk-\/mixed layer or a general coordinate are in use. \end{DoxyCompactList}\item 
subroutine \mbox{\hyperlink{namespacemom__mixed__layer__restrat_a9c6bee98536870b0b6c2bd317c00c684}{mixedlayer\+\_\+restrat\+\_\+general}} (h, uhtr, vhtr, tv, forces, dt, M\+L\+D\+\_\+in, Var\+Mix, G, GV, US, CS)
\begin{DoxyCompactList}\small\item\em Calculates a restratifying flow in the mixed layer. \end{DoxyCompactList}\item 
subroutine \mbox{\hyperlink{namespacemom__mixed__layer__restrat_ac01281bf39b6fa7e469919c30c26aedb}{mixedlayer\+\_\+restrat\+\_\+bml}} (h, uhtr, vhtr, tv, forces, dt, G, GV, US, CS)
\begin{DoxyCompactList}\small\item\em Calculates a restratifying flow assuming a 2-\/layer bulk mixed layer. \end{DoxyCompactList}\item 
logical function, public \mbox{\hyperlink{namespacemom__mixed__layer__restrat_a89b89663722cc9047a3bb238a4bfa09a}{mixedlayer\+\_\+restrat\+\_\+init}} (Time, G, GV, US, param\+\_\+file, diag, CS, restart\+\_\+\+CS)
\begin{DoxyCompactList}\small\item\em Initialize the mixed layer restratification module. \end{DoxyCompactList}\item 
subroutine, public \mbox{\hyperlink{namespacemom__mixed__layer__restrat_aea597553dfa98cc7c972784f476ad3fc}{mixedlayer\+\_\+restrat\+\_\+register\+\_\+restarts}} (HI, param\+\_\+file, CS, restart\+\_\+\+CS)
\begin{DoxyCompactList}\small\item\em Allocate and register fields in the mixed layer restratification structure for restarts. \end{DoxyCompactList}\end{DoxyCompactItemize}
\subsection*{Variables}
\begin{DoxyCompactItemize}
\item 
\mbox{\Hypertarget{namespacemom__mixed__layer__restrat_a0524d9152be26e538ed4da505942ebd2}\label{namespacemom__mixed__layer__restrat_a0524d9152be26e538ed4da505942ebd2}} 
character(len=40) \mbox{\hyperlink{namespacemom__mixed__layer__restrat_a0524d9152be26e538ed4da505942ebd2}{mdl}} = \char`\"{}M\+O\+M\+\_\+mixed\+\_\+layer\+\_\+restrat\char`\"{}
\begin{DoxyCompactList}\small\item\em This module\textquotesingle{}s name. \end{DoxyCompactList}\end{DoxyCompactItemize}


\subsection{Function/\+Subroutine Documentation}
\mbox{\Hypertarget{namespacemom__mixed__layer__restrat_a9dfb1879cd5a1ef890f3fc329f961ea0}\label{namespacemom__mixed__layer__restrat_a9dfb1879cd5a1ef890f3fc329f961ea0}} 
\index{mom\+\_\+mixed\+\_\+layer\+\_\+restrat@{mom\+\_\+mixed\+\_\+layer\+\_\+restrat}!mixedlayer\+\_\+restrat@{mixedlayer\+\_\+restrat}}
\index{mixedlayer\+\_\+restrat@{mixedlayer\+\_\+restrat}!mom\+\_\+mixed\+\_\+layer\+\_\+restrat@{mom\+\_\+mixed\+\_\+layer\+\_\+restrat}}
\subsubsection{\texorpdfstring{mixedlayer\+\_\+restrat()}{mixedlayer\_restrat()}}
{\footnotesize\ttfamily subroutine, public mom\+\_\+mixed\+\_\+layer\+\_\+restrat\+::mixedlayer\+\_\+restrat (\begin{DoxyParamCaption}\item[{real, dimension(szi\+\_\+(g),szj\+\_\+(g),szk\+\_\+(g)), intent(inout)}]{h,  }\item[{real, dimension(szib\+\_\+(g),szj\+\_\+(g),szk\+\_\+(g)), intent(inout)}]{uhtr,  }\item[{real, dimension(szi\+\_\+(g),szjb\+\_\+(g),szk\+\_\+(g)), intent(inout)}]{vhtr,  }\item[{type(thermo\+\_\+var\+\_\+ptrs), intent(in)}]{tv,  }\item[{type(mech\+\_\+forcing), intent(in)}]{forces,  }\item[{real, intent(in)}]{dt,  }\item[{real, dimension(\+:,\+:), pointer}]{M\+LD,  }\item[{type(varmix\+\_\+cs), pointer}]{Var\+Mix,  }\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(\mbox{\hyperlink{structmom__mixed__layer__restrat_1_1mixedlayer__restrat__cs}{mixedlayer\+\_\+restrat\+\_\+cs}}), pointer}]{CS }\end{DoxyParamCaption})}



Driver for the mixed-\/layer restratification parameterization. The code branches between two different implementations depending on whether the bulk-\/mixed layer or a general coordinate are in use. 


\begin{DoxyParams}[1]{Parameters}
\mbox{\tt in,out}  & {\em g} & Ocean grid structure\\
\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,out}  & {\em h} & Layer thickness \mbox{[}H $\sim$$>$ m or kg m-\/2\mbox{]}\\
\hline
\mbox{\tt in,out}  & {\em uhtr} & Accumulated zonal mass flux \mbox{[}H L2 $\sim$$>$ m3 or kg\mbox{]}\\
\hline
\mbox{\tt in,out}  & {\em vhtr} & Accumulated meridional mass flux \mbox{[}H L2 $\sim$$>$ m3 or kg\mbox{]}\\
\hline
\mbox{\tt in}  & {\em tv} & Thermodynamic variables structure\\
\hline
\mbox{\tt in}  & {\em forces} & A structure with the driving mechanical forces\\
\hline
\mbox{\tt in}  & {\em dt} & Time increment \mbox{[}T $\sim$$>$ s\mbox{]}\\
\hline
 & {\em mld} & Mixed layer depth provided by the P\+BL scheme \mbox{[}Z $\sim$$>$ m\mbox{]}\\
\hline
 & {\em varmix} & Container for derived fields\\
\hline
 & {\em cs} & Module control structure \\
\hline
\end{DoxyParams}


Definition at line 91 of file M\+O\+M\+\_\+mixed\+\_\+layer\+\_\+restrat.\+F90.


\begin{DoxyCode}
91   \textcolor{keywordtype}{type}(ocean\_grid\_type),                     \textcolor{keywordtype}{intent(inout)} :: G\textcolor{comment}{      !< Ocean grid structure}
92   \textcolor{keywordtype}{type}(verticalGrid\_type),                   \textcolor{keywordtype}{intent(in)}    :: GV\textcolor{comment}{     !< Ocean vertical grid structure}
93   \textcolor{keywordtype}{type}(unit\_scale\_type),                     \textcolor{keywordtype}{intent(in)}    :: US\textcolor{comment}{     !< A dimensional unit scaling type}
94   \textcolor{keywordtype}{real}, \textcolor{keywordtype}{dimension(SZI\_(G),SZJ\_(G),SZK\_(G))},  \textcolor{keywordtype}{intent(inout)} :: h\textcolor{comment}{      !< Layer thickness [H ~> m or kg m-2]}
95   \textcolor{keywordtype}{real}, \textcolor{keywordtype}{dimension(SZIB\_(G),SZJ\_(G),SZK\_(G))}, \textcolor{keywordtype}{intent(inout)} :: uhtr\textcolor{comment}{   !< Accumulated zonal mass flux}
96 \textcolor{comment}{                                                                     !! [H L2 ~> m3 or kg]}
97   \textcolor{keywordtype}{real}, \textcolor{keywordtype}{dimension(SZI\_(G),SZJB\_(G),SZK\_(G))}, \textcolor{keywordtype}{intent(inout)} :: vhtr\textcolor{comment}{   !< Accumulated meridional mass flux}
98 \textcolor{comment}{                                                                     !! [H L2 ~> m3 or kg]}
99   \textcolor{keywordtype}{type}(thermo\_var\_ptrs),                     \textcolor{keywordtype}{intent(in)}    :: tv\textcolor{comment}{     !< Thermodynamic variables structure}
100   \textcolor{keywordtype}{type}(mech\_forcing),                        \textcolor{keywordtype}{intent(in)}    :: forces\textcolor{comment}{ !< A structure with the driving
       mechanical forces}
101   \textcolor{keywordtype}{real},                                      \textcolor{keywordtype}{intent(in)}    :: dt\textcolor{comment}{     !< Time increment [T ~> s]}
102   \textcolor{keywordtype}{real}, \textcolor{keywordtype}{dimension(:,:)},                      \textcolor{keywordtype}{pointer}       :: MLD\textcolor{comment}{    !< Mixed layer depth provided by the}
103 \textcolor{comment}{                                                                     !! PBL scheme [Z ~> m]}
104   \textcolor{keywordtype}{type}(VarMix\_CS),                           \textcolor{keywordtype}{pointer}       :: VarMix\textcolor{comment}{ !< Container for derived fields}
105   \textcolor{keywordtype}{type}(mixedlayer\_restrat\_CS),               \textcolor{keywordtype}{pointer}       :: CS\textcolor{comment}{     !< Module control structure}
106 
107   \textcolor{keywordflow}{if} (.not. \textcolor{keyword}{associated}(cs)) \textcolor{keyword}{call }mom\_error(fatal, \textcolor{stringliteral}{"MOM\_mixedlayer\_restrat: "}// &
108          \textcolor{stringliteral}{"Module must be initialized before it is used."})
109 
110   \textcolor{keywordflow}{if} (gv%nkml>0) \textcolor{keywordflow}{then}
111     \textcolor{keyword}{call }mixedlayer\_restrat\_bml(h, uhtr, vhtr, tv, forces, dt, g, gv, us, cs)
112   \textcolor{keywordflow}{else}
113     \textcolor{keyword}{call }mixedlayer\_restrat\_general(h, uhtr, vhtr, tv, forces, dt, mld, varmix, g, gv, us, cs)
114 \textcolor{keywordflow}{  endif}
115 
\end{DoxyCode}
\mbox{\Hypertarget{namespacemom__mixed__layer__restrat_ac01281bf39b6fa7e469919c30c26aedb}\label{namespacemom__mixed__layer__restrat_ac01281bf39b6fa7e469919c30c26aedb}} 
\index{mom\+\_\+mixed\+\_\+layer\+\_\+restrat@{mom\+\_\+mixed\+\_\+layer\+\_\+restrat}!mixedlayer\+\_\+restrat\+\_\+bml@{mixedlayer\+\_\+restrat\+\_\+bml}}
\index{mixedlayer\+\_\+restrat\+\_\+bml@{mixedlayer\+\_\+restrat\+\_\+bml}!mom\+\_\+mixed\+\_\+layer\+\_\+restrat@{mom\+\_\+mixed\+\_\+layer\+\_\+restrat}}
\subsubsection{\texorpdfstring{mixedlayer\+\_\+restrat\+\_\+bml()}{mixedlayer\_restrat\_bml()}}
{\footnotesize\ttfamily subroutine mom\+\_\+mixed\+\_\+layer\+\_\+restrat\+::mixedlayer\+\_\+restrat\+\_\+bml (\begin{DoxyParamCaption}\item[{real, dimension(szi\+\_\+(g),szj\+\_\+(g),szk\+\_\+(g)), intent(inout)}]{h,  }\item[{real, dimension(szib\+\_\+(g),szj\+\_\+(g),szk\+\_\+(g)), intent(inout)}]{uhtr,  }\item[{real, dimension(szi\+\_\+(g),szjb\+\_\+(g),szk\+\_\+(g)), intent(inout)}]{vhtr,  }\item[{type(thermo\+\_\+var\+\_\+ptrs), intent(in)}]{tv,  }\item[{type(mech\+\_\+forcing), intent(in)}]{forces,  }\item[{real, intent(in)}]{dt,  }\item[{type(ocean\+\_\+grid\+\_\+type), intent(in)}]{G,  }\item[{type(verticalgrid\+\_\+type), intent(in)}]{GV,  }\item[{type(unit\+\_\+scale\+\_\+type), intent(in)}]{US,  }\item[{type(\mbox{\hyperlink{structmom__mixed__layer__restrat_1_1mixedlayer__restrat__cs}{mixedlayer\+\_\+restrat\+\_\+cs}}), pointer}]{CS }\end{DoxyParamCaption})\hspace{0.3cm}{\ttfamily [private]}}



Calculates a restratifying flow assuming a 2-\/layer bulk mixed layer. 


\begin{DoxyParams}[1]{Parameters}
\mbox{\tt in}  & {\em g} & Ocean grid structure\\
\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,out}  & {\em h} & Layer thickness \mbox{[}H $\sim$$>$ m or kg m-\/2\mbox{]}\\
\hline
\mbox{\tt in,out}  & {\em uhtr} & Accumulated zonal mass flux \mbox{[}H L2 $\sim$$>$ m3 or kg\mbox{]}\\
\hline
\mbox{\tt in,out}  & {\em vhtr} & Accumulated meridional mass flux \mbox{[}H L2 $\sim$$>$ m3 or kg\mbox{]}\\
\hline
\mbox{\tt in}  & {\em tv} & Thermodynamic variables structure\\
\hline
\mbox{\tt in}  & {\em forces} & A structure with the driving mechanical forces\\
\hline
\mbox{\tt in}  & {\em dt} & Time increment \mbox{[}T $\sim$$>$ s\mbox{]}\\
\hline
 & {\em cs} & Module control structure \\
\hline
\end{DoxyParams}


Definition at line 563 of file M\+O\+M\+\_\+mixed\+\_\+layer\+\_\+restrat.\+F90.


\begin{DoxyCode}
563   \textcolor{keywordtype}{type}(ocean\_grid\_type),                     \textcolor{keywordtype}{intent(in)}    :: G\textcolor{comment}{      !< Ocean grid structure}
564   \textcolor{keywordtype}{type}(verticalGrid\_type),                   \textcolor{keywordtype}{intent(in)}    :: GV\textcolor{comment}{     !< Ocean vertical grid structure}
565   \textcolor{keywordtype}{type}(unit\_scale\_type),                     \textcolor{keywordtype}{intent(in)}    :: US\textcolor{comment}{     !< A dimensional unit scaling type}
566   \textcolor{keywordtype}{real}, \textcolor{keywordtype}{dimension(SZI\_(G),SZJ\_(G),SZK\_(G))},  \textcolor{keywordtype}{intent(inout)} :: h\textcolor{comment}{      !< Layer thickness [H ~> m or kg m-2]}
567   \textcolor{keywordtype}{real}, \textcolor{keywordtype}{dimension(SZIB\_(G),SZJ\_(G),SZK\_(G))}, \textcolor{keywordtype}{intent(inout)} :: uhtr\textcolor{comment}{   !< Accumulated zonal mass flux}
568 \textcolor{comment}{                                                                     !!   [H L2 ~> m3 or kg]}
569   \textcolor{keywordtype}{real}, \textcolor{keywordtype}{dimension(SZI\_(G),SZJB\_(G),SZK\_(G))}, \textcolor{keywordtype}{intent(inout)} :: vhtr\textcolor{comment}{   !< Accumulated meridional mass flux}
570 \textcolor{comment}{                                                                     !!   [H L2 ~> m3 or kg]}
571   \textcolor{keywordtype}{type}(thermo\_var\_ptrs),                     \textcolor{keywordtype}{intent(in)}    :: tv\textcolor{comment}{     !< Thermodynamic variables structure}
572   \textcolor{keywordtype}{type}(mech\_forcing),                        \textcolor{keywordtype}{intent(in)}    :: forces\textcolor{comment}{ !< A structure with the driving
       mechanical forces}
573   \textcolor{keywordtype}{real},                                      \textcolor{keywordtype}{intent(in)}    :: dt\textcolor{comment}{     !< Time increment [T ~> s]}
574   \textcolor{keywordtype}{type}(mixedlayer\_restrat\_CS),               \textcolor{keywordtype}{pointer}       :: CS\textcolor{comment}{     !< Module control structure}
575   \textcolor{comment}{! Local variables}
576   \textcolor{keywordtype}{real} :: uhml(SZIB\_(G),SZJ\_(G),SZK\_(G)) \textcolor{comment}{! zonal mixed layer transport [H L2 T-1 ~> m3 s-1 or kg s-1]}
577   \textcolor{keywordtype}{real} :: vhml(SZI\_(G),SZJB\_(G),SZK\_(G)) \textcolor{comment}{! merid mixed layer transport [H L2 T-1 ~> m3 s-1 or kg s-1]}
578   \textcolor{keywordtype}{real}, \textcolor{keywordtype}{dimension(SZI\_(G),SZJ\_(G),SZK\_(G))} :: &
579     h\_avail               \textcolor{comment}{! The volume available for diffusion out of each face of each}
580                           \textcolor{comment}{! sublayer of the mixed layer, divided by dt [H L2 T-1 ~> m3 s-1 or kg s-1].}
581   \textcolor{keywordtype}{real}, \textcolor{keywordtype}{dimension(SZI\_(G),SZJ\_(G))} :: &
582     htot, &               \textcolor{comment}{! The sum of the thicknesses of layers in the mixed layer [H ~> m or kg m-2]}
583     Rml\_av                \textcolor{comment}{! g\_Rho0 times the average mixed layer density [L2 Z-1 T-2 ~> m s-2]}
584   \textcolor{keywordtype}{real} :: g\_Rho0          \textcolor{comment}{! G\_Earth/Rho0 [L2 Z-1 T-2 R-1 ~> m4 s-2 kg-1]}
585   \textcolor{keywordtype}{real} :: Rho0(SZI\_(G))   \textcolor{comment}{! Potential density relative to the surface [R ~> kg m-3]}
586   \textcolor{keywordtype}{real} :: p0(SZI\_(G))     \textcolor{comment}{! A pressure of 0 [R L2 T-2 ~> Pa]}
587 
588   \textcolor{keywordtype}{real} :: h\_vel           \textcolor{comment}{! htot interpolated onto velocity points [Z ~> m]. (The units are not H.)}
589   \textcolor{keywordtype}{real} :: absf            \textcolor{comment}{! absolute value of f, interpolated to velocity points [T-1 ~> s-1]}
590   \textcolor{keywordtype}{real} :: u\_star          \textcolor{comment}{! surface friction velocity, interpolated to velocity points [Z T-1 ~> m s-1].}
591   \textcolor{keywordtype}{real} :: mom\_mixrate     \textcolor{comment}{! rate at which momentum is homogenized within mixed layer [T-1 ~> s-1]}
592   \textcolor{keywordtype}{real} :: timescale       \textcolor{comment}{! mixing growth timescale [T ~> s]}
593   \textcolor{keywordtype}{real} :: h\_neglect       \textcolor{comment}{! tiny thickness usually lost in roundoff and can be neglected [H ~> m or kg m-2]}
594   \textcolor{keywordtype}{real} :: dz\_neglect      \textcolor{comment}{! tiny thickness that usually lost in roundoff and can be neglected [Z ~> m]}
595   \textcolor{keywordtype}{real} :: I4dt            \textcolor{comment}{! 1/(4 dt) [T-1 ~> s-1]}
596   \textcolor{keywordtype}{real} :: I2htot          \textcolor{comment}{! Twice the total mixed layer thickness at velocity points [H ~> m or kg m-2]}
597   \textcolor{keywordtype}{real} :: z\_topx2         \textcolor{comment}{! depth of the top of a layer at velocity points [H ~> m or kg m-2]}
598   \textcolor{keywordtype}{real} :: hx2             \textcolor{comment}{! layer thickness at velocity points [H ~> m or kg m-2]}
599   \textcolor{keywordtype}{real} :: a(SZK\_(G))      \textcolor{comment}{! A non-dimensional value relating the overall flux}
600                           \textcolor{comment}{! magnitudes (uDml & vDml) to the realized flux in a}
601                           \textcolor{comment}{! layer.  The vertical sum of a() through the pieces of}
602                           \textcolor{comment}{! the mixed layer must be 0.}
603   \textcolor{keywordtype}{real} :: uDml(SZIB\_(G))  \textcolor{comment}{! The zonal and meridional volume fluxes in the upper}
604   \textcolor{keywordtype}{real} :: vDml(SZI\_(G))   \textcolor{comment}{! half of the mixed layer [H L2 T-1 ~> m3 s-1 or kg s-1].}
605   \textcolor{keywordtype}{real} :: utimescale\_diag(SZIB\_(G),SZJ\_(G)) \textcolor{comment}{! The restratification timescales}
606   \textcolor{keywordtype}{real} :: vtimescale\_diag(SZI\_(G),SZJB\_(G)) \textcolor{comment}{! in the zonal and meridional}
607                                             \textcolor{comment}{! directions [T ~> s], stored in 2-D}
608                                             \textcolor{comment}{! arrays for diagnostic purposes.}
609   \textcolor{keywordtype}{real} :: uDml\_diag(SZIB\_(G),SZJ\_(G)), vDml\_diag(SZI\_(G),SZJB\_(G))
610   \textcolor{keywordtype}{logical} :: use\_EOS    \textcolor{comment}{! If true, density is calculated from T & S using an equation of state.}
611 
612   \textcolor{keywordtype}{integer}, \textcolor{keywordtype}{dimension(2)} :: EOSdom \textcolor{comment}{! The i-computational domain for the equation of state}
613   \textcolor{keywordtype}{integer} :: i, j, k, is, ie, js, je, Isq, Ieq, Jsq, Jeq, nz, nkml
614   is  = g%isc  ; ie  = g%iec  ; js  = g%jsc  ; je  = g%jec ; nz = g%ke
615   isq = g%IscB ; ieq = g%IecB ; jsq = g%JscB ; jeq = g%JecB ; nkml = gv%nkml
616 
617   \textcolor{keywordflow}{if} (.not. \textcolor{keyword}{associated}(cs)) \textcolor{keyword}{call }mom\_error(fatal, \textcolor{stringliteral}{"MOM\_mixedlayer\_restrat: "}// &
618          \textcolor{stringliteral}{"Module must be initialized before it is used."})
619   \textcolor{keywordflow}{if} ((nkml<2) .or. (cs%ml\_restrat\_coef<=0.0)) \textcolor{keywordflow}{return}
620 
621   udml(:)    = 0.0 ; vdml(:) = 0.0
622   i4dt       = 0.25 / dt
623   g\_rho0     = gv%g\_Earth / gv%Rho0
624   use\_eos    = \textcolor{keyword}{associated}(tv%eqn\_of\_state)
625   h\_neglect  = gv%H\_subroundoff
626   dz\_neglect = gv%H\_subroundoff*gv%H\_to\_Z
627 
628   \textcolor{keywordflow}{if} (.not.use\_eos) \textcolor{keyword}{call }mom\_error(fatal, \textcolor{stringliteral}{"MOM\_mixedlayer\_restrat: "}// &
629          \textcolor{stringliteral}{"An equation of state must be used with this module."})
630 
631   \textcolor{comment}{! Fix this later for nkml >= 3.}
632 
633   p0(:) = 0.0
634   eosdom(:) = eos\_domain(g%HI, halo=1)
635 \textcolor{comment}{!$OMP parallel default(none) shared(is,ie,js,je,G,GV,US,htot,Rml\_av,tv,p0,h,h\_avail,EOSdom, &}
636 \textcolor{comment}{!$OMP                               h\_neglect,g\_Rho0,I4dt,CS,uhml,uhtr,dt,vhml,vhtr,   &}
637 \textcolor{comment}{!$OMP                               utimescale\_diag,vtimescale\_diag,forces,dz\_neglect, &}
638 \textcolor{comment}{!$OMP                               uDml\_diag,vDml\_diag,nkml)                          &}
639 \textcolor{comment}{!$OMP                       private(Rho0,h\_vel,u\_star,absf,mom\_mixrate,timescale,      &}
640 \textcolor{comment}{!$OMP                               I2htot,z\_topx2,hx2,a)                              &}
641 \textcolor{comment}{!$OMP                       firstprivate(uDml,vDml)}
642 \textcolor{comment}{!$OMP do}
643   \textcolor{keywordflow}{do} j=js-1,je+1
644     \textcolor{keywordflow}{do} i=is-1,ie+1
645       htot(i,j) = 0.0 ; rml\_av(i,j) = 0.0
646 \textcolor{keywordflow}{    enddo}
647     \textcolor{keywordflow}{do} k=1,nkml
648       \textcolor{keyword}{call }calculate\_density(tv%T(:,j,k), tv%S(:,j,k), p0, rho0(:), tv%eqn\_of\_state, eosdom)
649       \textcolor{keywordflow}{do} i=is-1,ie+1
650         rml\_av(i,j) = rml\_av(i,j) + h(i,j,k)*rho0(i)
651         htot(i,j) = htot(i,j) + h(i,j,k)
652         h\_avail(i,j,k) = max(i4dt*g%areaT(i,j)*(h(i,j,k)-gv%Angstrom\_H),0.0)
653 \textcolor{keywordflow}{      enddo}
654 \textcolor{keywordflow}{    enddo}
655 
656     \textcolor{keywordflow}{do} i=is-1,ie+1
657       rml\_av(i,j) = (g\_rho0*rml\_av(i,j)) / (htot(i,j) + h\_neglect)
658 \textcolor{keywordflow}{    enddo}
659 \textcolor{keywordflow}{  enddo}
660 
661 \textcolor{comment}{! TO DO:}
662 \textcolor{comment}{!   1. Mixing extends below the mixing layer to the mixed layer.  Find it!}
663 \textcolor{comment}{!   2. Add exponential tail to stream-function?}
664 
665 \textcolor{comment}{!   U - Component}
666 \textcolor{comment}{!$OMP do}
667   \textcolor{keywordflow}{do} j=js,je; \textcolor{keywordflow}{do} i=is-1,ie
668     h\_vel = 0.5*(htot(i,j) + htot(i+1,j)) * gv%H\_to\_Z
669 
670     u\_star = 0.5*(forces%ustar(i,j) + forces%ustar(i+1,j))
671     absf = 0.5*(abs(g%CoriolisBu(i,j-1)) + abs(g%CoriolisBu(i,j)))
672     \textcolor{comment}{! peak ML visc: u\_star * 0.41 * (h\_ml*u\_star)/(absf*h\_ml + 4.0*u\_star)}
673     \textcolor{comment}{! momentum mixing rate: pi^2*visc/h\_ml^2}
674     \textcolor{comment}{! 0.41 is the von Karmen constant, 9.8696 = pi^2.}
675     mom\_mixrate = (0.41*9.8696)*u\_star**2 / &
676                   (absf*h\_vel**2 + 4.0*(h\_vel+dz\_neglect)*u\_star)
677     timescale = 0.0625 * (absf + 2.0*mom\_mixrate) / (absf**2 + mom\_mixrate**2)
678 
679     timescale = timescale * cs%ml\_restrat\_coef
680 \textcolor{comment}{!      timescale = timescale*(2?)*(L\_def/L\_MLI) * min(EKE/MKE,1.0 + (G%dyCv(i,j)/L\_def)**2)}
681 
682     udml(i) = timescale * g%mask2dCu(i,j)*g%dyCu(i,j)*g%IdxCu(i,j) * &
683         (rml\_av(i+1,j)-rml\_av(i,j)) * (h\_vel**2 * gv%Z\_to\_H)
684 
685     \textcolor{keywordflow}{if} (udml(i) == 0) \textcolor{keywordflow}{then}
686       \textcolor{keywordflow}{do} k=1,nkml ; uhml(i,j,k) = 0.0 ;\textcolor{keywordflow}{ enddo}
687     \textcolor{keywordflow}{else}
688       i2htot = 1.0 / (htot(i,j) + htot(i+1,j) + h\_neglect)
689       z\_topx2 = 0.0
690       \textcolor{comment}{! a(k) relates the sublayer transport to uDml with a linear profile.}
691       \textcolor{comment}{! The sum of a(k) through the mixed layers must be 0.}
692       \textcolor{keywordflow}{do} k=1,nkml
693         hx2 = (h(i,j,k) + h(i+1,j,k) + h\_neglect)
694         a(k) = (hx2 * i2htot) * (2.0 - 4.0*(z\_topx2+0.5*hx2)*i2htot)
695         z\_topx2 = z\_topx2 + hx2
696         \textcolor{keywordflow}{if} (a(k)*udml(i) > 0.0) \textcolor{keywordflow}{then}
697           \textcolor{keywordflow}{if} (a(k)*udml(i) > h\_avail(i,j,k)) udml(i) = h\_avail(i,j,k) / a(k)
698         \textcolor{keywordflow}{else}
699           \textcolor{keywordflow}{if} (-a(k)*udml(i) > h\_avail(i+1,j,k)) udml(i) = -h\_avail(i+1,j,k)/a(k)
700 \textcolor{keywordflow}{        endif}
701 \textcolor{keywordflow}{      enddo}
702       \textcolor{keywordflow}{do} k=1,nkml
703         uhml(i,j,k) = a(k)*udml(i)
704         uhtr(i,j,k) = uhtr(i,j,k) + uhml(i,j,k)*dt
705 \textcolor{keywordflow}{      enddo}
706 \textcolor{keywordflow}{    endif}
707 
708     udml\_diag(i,j) = udml(i)
709     utimescale\_diag(i,j) = timescale
710 \textcolor{keyword}{  end}do; enddo
711 
712 \textcolor{comment}{!  V- component}
713 \textcolor{comment}{!$OMP do}
714   \textcolor{keywordflow}{do} j=js-1,je ; \textcolor{keywordflow}{do} i=is,ie
715     h\_vel = 0.5*(htot(i,j) + htot(i,j+1)) * gv%H\_to\_Z
716 
717     u\_star = 0.5*(forces%ustar(i,j) + forces%ustar(i,j+1))
718     absf = 0.5*(abs(g%CoriolisBu(i-1,j)) + abs(g%CoriolisBu(i,j)))
719     \textcolor{comment}{! peak ML visc: u\_star * 0.41 * (h\_ml*u\_star)/(absf*h\_ml + 4.0*u\_star)}
720     \textcolor{comment}{! momentum mixing rate: pi^2*visc/h\_ml^2}
721     \textcolor{comment}{! 0.41 is the von Karmen constant, 9.8696 = pi^2.}
722     mom\_mixrate = (0.41*9.8696)*u\_star**2 / &
723                   (absf*h\_vel**2 + 4.0*(h\_vel+dz\_neglect)*u\_star)
724     timescale = 0.0625 * (absf + 2.0*mom\_mixrate) / (absf**2 + mom\_mixrate**2)
725 
726     timescale = timescale * cs%ml\_restrat\_coef
727 \textcolor{comment}{!     timescale = timescale*(2?)*(L\_def/L\_MLI) * min(EKE/MKE,1.0 + (G%dyCv(i,j)/L\_def)**2)}
728 
729     vdml(i) = timescale * g%mask2dCv(i,j)*g%dxCv(i,j)*g%IdyCv(i,j) * &
730         (rml\_av(i,j+1)-rml\_av(i,j)) * (h\_vel**2 * gv%Z\_to\_H)
731     \textcolor{keywordflow}{if} (vdml(i) == 0) \textcolor{keywordflow}{then}
732       \textcolor{keywordflow}{do} k=1,nkml ; vhml(i,j,k) = 0.0 ;\textcolor{keywordflow}{ enddo}
733     \textcolor{keywordflow}{else}
734       i2htot = 1.0 / (htot(i,j) + htot(i,j+1) + h\_neglect)
735       z\_topx2 = 0.0
736       \textcolor{comment}{! a(k) relates the sublayer transport to vDml with a linear profile.}
737       \textcolor{comment}{! The sum of a(k) through the mixed layers must be 0.}
738       \textcolor{keywordflow}{do} k=1,nkml
739         hx2 = (h(i,j,k) + h(i,j+1,k) + h\_neglect)
740         a(k) = (hx2 * i2htot) * (2.0 - 4.0*(z\_topx2+0.5*hx2)*i2htot)
741         z\_topx2 = z\_topx2 + hx2
742         \textcolor{keywordflow}{if} (a(k)*vdml(i) > 0.0) \textcolor{keywordflow}{then}
743           \textcolor{keywordflow}{if} (a(k)*vdml(i) > h\_avail(i,j,k)) vdml(i) = h\_avail(i,j,k) / a(k)
744         \textcolor{keywordflow}{else}
745           \textcolor{keywordflow}{if} (-a(k)*vdml(i) > h\_avail(i,j+1,k)) vdml(i) = -h\_avail(i,j+1,k)/a(k)
746 \textcolor{keywordflow}{        endif}
747 \textcolor{keywordflow}{      enddo}
748       \textcolor{keywordflow}{do} k=1,nkml
749         vhml(i,j,k) = a(k)*vdml(i)
750         vhtr(i,j,k) = vhtr(i,j,k) + vhml(i,j,k)*dt
751 \textcolor{keywordflow}{      enddo}
752 \textcolor{keywordflow}{    endif}
753 
754     vtimescale\_diag(i,j) = timescale
755     vdml\_diag(i,j) = vdml(i)
756 \textcolor{keyword}{  end}do; enddo
757 
758 \textcolor{comment}{!$OMP do}
759   \textcolor{keywordflow}{do} j=js,je ; \textcolor{keywordflow}{do} k=1,nkml ; \textcolor{keywordflow}{do} i=is,ie
760     h(i,j,k) = h(i,j,k) - dt*g%IareaT(i,j) * &
761         ((uhml(i,j,k) - uhml(i-1,j,k)) + (vhml(i,j,k) - vhml(i,j-1,k)))
762 \textcolor{keywordflow}{  enddo} ;\textcolor{keywordflow}{ enddo} ;\textcolor{keywordflow}{ enddo}
763 \textcolor{comment}{!$OMP end parallel}
764 
765   \textcolor{comment}{! Whenever thickness changes let the diag manager know, target grids}
766   \textcolor{comment}{! for vertical remapping may need to be regenerated.}
767   \textcolor{keywordflow}{if} (cs%id\_uhml > 0 .or. cs%id\_vhml > 0) &
768     \textcolor{comment}{! Remapped uhml and vhml require east/north halo updates of h}
769     \textcolor{keyword}{call }pass\_var(h, g%domain, to\_west+to\_south+omit\_corners, halo=1)
770   \textcolor{keyword}{call }diag\_update\_remap\_grids(cs%diag)
771 
772   \textcolor{comment}{! Offer diagnostic fields for averaging.}
773   \textcolor{keywordflow}{if} (query\_averaging\_enabled(cs%diag) .and. &
774     ((cs%id\_urestrat\_time > 0)  .or. (cs%id\_vrestrat\_time > 0))) \textcolor{keywordflow}{then}
775     \textcolor{keyword}{call }post\_data(cs%id\_urestrat\_time, utimescale\_diag, cs%diag)
776     \textcolor{keyword}{call }post\_data(cs%id\_vrestrat\_time, vtimescale\_diag, cs%diag)
777 \textcolor{keywordflow}{  endif}
778   \textcolor{keywordflow}{if} (query\_averaging\_enabled(cs%diag) .and. &
779       ((cs%id\_uhml>0) .or. (cs%id\_vhml>0))) \textcolor{keywordflow}{then}
780     \textcolor{keywordflow}{do} k=nkml+1,nz
781       \textcolor{keywordflow}{do} j=js,je ; \textcolor{keywordflow}{do} i=isq,ieq ; uhml(i,j,k) = 0.0 ;\textcolor{keywordflow}{ enddo} ;\textcolor{keywordflow}{ enddo}
782       \textcolor{keywordflow}{do} j=jsq,jeq ; \textcolor{keywordflow}{do} i=is,ie ; vhml(i,j,k) = 0.0 ;\textcolor{keywordflow}{ enddo} ;\textcolor{keywordflow}{ enddo}
783 \textcolor{keywordflow}{    enddo}
784     \textcolor{keywordflow}{if} (cs%id\_uhml > 0) \textcolor{keyword}{call }post\_data(cs%id\_uhml, uhml,      cs%diag)
785     \textcolor{keywordflow}{if} (cs%id\_vhml > 0) \textcolor{keyword}{call }post\_data(cs%id\_vhml, vhml,      cs%diag)
786     \textcolor{keywordflow}{if} (cs%id\_MLD  > 0) \textcolor{keyword}{call }post\_data(cs%id\_MLD,  htot,      cs%diag)
787     \textcolor{keywordflow}{if} (cs%id\_Rml  > 0) \textcolor{keyword}{call }post\_data(cs%id\_Rml,  rml\_av,    cs%diag)
788     \textcolor{keywordflow}{if} (cs%id\_uDml > 0) \textcolor{keyword}{call }post\_data(cs%id\_uDml, udml\_diag, cs%diag)
789     \textcolor{keywordflow}{if} (cs%id\_vDml > 0) \textcolor{keyword}{call }post\_data(cs%id\_vDml, vdml\_diag, cs%diag)
790 \textcolor{keywordflow}{  endif}
791 
\end{DoxyCode}
\mbox{\Hypertarget{namespacemom__mixed__layer__restrat_a9c6bee98536870b0b6c2bd317c00c684}\label{namespacemom__mixed__layer__restrat_a9c6bee98536870b0b6c2bd317c00c684}} 
\index{mom\+\_\+mixed\+\_\+layer\+\_\+restrat@{mom\+\_\+mixed\+\_\+layer\+\_\+restrat}!mixedlayer\+\_\+restrat\+\_\+general@{mixedlayer\+\_\+restrat\+\_\+general}}
\index{mixedlayer\+\_\+restrat\+\_\+general@{mixedlayer\+\_\+restrat\+\_\+general}!mom\+\_\+mixed\+\_\+layer\+\_\+restrat@{mom\+\_\+mixed\+\_\+layer\+\_\+restrat}}
\subsubsection{\texorpdfstring{mixedlayer\+\_\+restrat\+\_\+general()}{mixedlayer\_restrat\_general()}}
{\footnotesize\ttfamily subroutine mom\+\_\+mixed\+\_\+layer\+\_\+restrat\+::mixedlayer\+\_\+restrat\+\_\+general (\begin{DoxyParamCaption}\item[{real, dimension(szi\+\_\+(g),szj\+\_\+(g),szk\+\_\+(g)), intent(inout)}]{h,  }\item[{real, dimension(szib\+\_\+(g),szj\+\_\+(g),szk\+\_\+(g)), intent(inout)}]{uhtr,  }\item[{real, dimension(szi\+\_\+(g),szjb\+\_\+(g),szk\+\_\+(g)), intent(inout)}]{vhtr,  }\item[{type(thermo\+\_\+var\+\_\+ptrs), intent(in)}]{tv,  }\item[{type(mech\+\_\+forcing), intent(in)}]{forces,  }\item[{real, intent(in)}]{dt,  }\item[{real, dimension(\+:,\+:), pointer}]{M\+L\+D\+\_\+in,  }\item[{type(varmix\+\_\+cs), pointer}]{Var\+Mix,  }\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(\mbox{\hyperlink{structmom__mixed__layer__restrat_1_1mixedlayer__restrat__cs}{mixedlayer\+\_\+restrat\+\_\+cs}}), pointer}]{CS }\end{DoxyParamCaption})\hspace{0.3cm}{\ttfamily [private]}}



Calculates a restratifying flow in the mixed layer. 


\begin{DoxyParams}[1]{Parameters}
\mbox{\tt in,out}  & {\em g} & Ocean grid structure\\
\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,out}  & {\em h} & Layer thickness \mbox{[}H $\sim$$>$ m or kg m-\/2\mbox{]}\\
\hline
\mbox{\tt in,out}  & {\em uhtr} & Accumulated zonal mass flux \mbox{[}H L2 $\sim$$>$ m3 or kg\mbox{]}\\
\hline
\mbox{\tt in,out}  & {\em vhtr} & Accumulated meridional mass flux \mbox{[}H L2 $\sim$$>$ m3 or kg\mbox{]}\\
\hline
\mbox{\tt in}  & {\em tv} & Thermodynamic variables structure\\
\hline
\mbox{\tt in}  & {\em forces} & A structure with the driving mechanical forces\\
\hline
\mbox{\tt in}  & {\em dt} & Time increment \mbox{[}T $\sim$$>$ s\mbox{]}\\
\hline
 & {\em mld\+\_\+in} & Mixed layer depth provided by the P\+BL scheme \mbox{[}Z $\sim$$>$ m\mbox{]} (not H)\\
\hline
 & {\em varmix} & Container for derived fields\\
\hline
 & {\em cs} & Module control structure \\
\hline
\end{DoxyParams}


Definition at line 120 of file M\+O\+M\+\_\+mixed\+\_\+layer\+\_\+restrat.\+F90.


\begin{DoxyCode}
120   \textcolor{comment}{! Arguments}
121   \textcolor{keywordtype}{type}(ocean\_grid\_type),                     \textcolor{keywordtype}{intent(inout)} :: G\textcolor{comment}{      !< Ocean grid structure}
122   \textcolor{keywordtype}{type}(verticalGrid\_type),                   \textcolor{keywordtype}{intent(in)}    :: GV\textcolor{comment}{     !< Ocean vertical grid structure}
123   \textcolor{keywordtype}{type}(unit\_scale\_type),                     \textcolor{keywordtype}{intent(in)}    :: US\textcolor{comment}{     !< A dimensional unit scaling type}
124   \textcolor{keywordtype}{real}, \textcolor{keywordtype}{dimension(SZI\_(G),SZJ\_(G),SZK\_(G))},  \textcolor{keywordtype}{intent(inout)} :: h\textcolor{comment}{      !< Layer thickness [H ~> m or kg m-2]}
125   \textcolor{keywordtype}{real}, \textcolor{keywordtype}{dimension(SZIB\_(G),SZJ\_(G),SZK\_(G))}, \textcolor{keywordtype}{intent(inout)} :: uhtr\textcolor{comment}{   !< Accumulated zonal mass flux}
126 \textcolor{comment}{                                                                     !!   [H L2 ~> m3 or kg]}
127   \textcolor{keywordtype}{real}, \textcolor{keywordtype}{dimension(SZI\_(G),SZJB\_(G),SZK\_(G))}, \textcolor{keywordtype}{intent(inout)} :: vhtr\textcolor{comment}{   !< Accumulated meridional mass flux}
128 \textcolor{comment}{                                                                     !!   [H L2 ~> m3 or kg]}
129   \textcolor{keywordtype}{type}(thermo\_var\_ptrs),                     \textcolor{keywordtype}{intent(in)}    :: tv\textcolor{comment}{     !< Thermodynamic variables structure}
130   \textcolor{keywordtype}{type}(mech\_forcing),                        \textcolor{keywordtype}{intent(in)}    :: forces\textcolor{comment}{ !< A structure with the driving
       mechanical forces}
131   \textcolor{keywordtype}{real},                                      \textcolor{keywordtype}{intent(in)}    :: dt\textcolor{comment}{     !< Time increment [T ~> s]}
132   \textcolor{keywordtype}{real}, \textcolor{keywordtype}{dimension(:,:)},                      \textcolor{keywordtype}{pointer}       :: MLD\_in\textcolor{comment}{ !< Mixed layer depth provided by the}
133 \textcolor{comment}{                                                                     !! PBL scheme [Z ~> m] (not H)}
134   \textcolor{keywordtype}{type}(VarMix\_CS),                           \textcolor{keywordtype}{pointer}       :: VarMix\textcolor{comment}{ !< Container for derived fields}
135   \textcolor{keywordtype}{type}(mixedlayer\_restrat\_CS),               \textcolor{keywordtype}{pointer}       :: CS\textcolor{comment}{     !< Module control structure}
136   \textcolor{comment}{! Local variables}
137   \textcolor{keywordtype}{real} :: uhml(SZIB\_(G),SZJ\_(G),SZK\_(G)) \textcolor{comment}{! zonal mixed layer transport [H L2 T-1 ~> m3 s-1 or kg s-1]}
138   \textcolor{keywordtype}{real} :: vhml(SZI\_(G),SZJB\_(G),SZK\_(G)) \textcolor{comment}{! merid mixed layer transport [H L2 T-1 ~> m3 s-1 or kg s-1]}
139   \textcolor{keywordtype}{real}, \textcolor{keywordtype}{dimension(SZI\_(G),SZJ\_(G),SZK\_(G))} :: &
140     h\_avail               \textcolor{comment}{! The volume available for diffusion out of each face of each}
141                           \textcolor{comment}{! sublayer of the mixed layer, divided by dt [H L2 T-1 ~> m3 s-1 or kg s-1].}
142   \textcolor{keywordtype}{real}, \textcolor{keywordtype}{dimension(SZI\_(G),SZJ\_(G))} :: &
143     MLD\_fast, &           \textcolor{comment}{! Mixed layer depth actually used in MLE restratification parameterization [H ~>
       m or kg m-2]}
144     htot\_fast, &          \textcolor{comment}{! The sum of the thicknesses of layers in the mixed layer [H ~> m or kg m-2]}
145     Rml\_av\_fast, &        \textcolor{comment}{! g\_Rho0 times the average mixed layer density [L2 Z-1 T-2 ~> m s-2]}
146     MLD\_slow, &           \textcolor{comment}{! Mixed layer depth actually used in MLE restratification parameterization [H ~>
       m or kg m-2]}
147     htot\_slow, &          \textcolor{comment}{! The sum of the thicknesses of layers in the mixed layer [H ~> m or kg m-2]}
148     Rml\_av\_slow           \textcolor{comment}{! g\_Rho0 times the average mixed layer density [L2 Z-1 T-2 ~> m s-2]}
149   \textcolor{keywordtype}{real} :: g\_Rho0          \textcolor{comment}{! G\_Earth/Rho0 [L2 Z-1 T-2 R-1 ~> m4 s-2 kg-1]}
150   \textcolor{keywordtype}{real} :: rho\_ml(SZI\_(G)) \textcolor{comment}{! Potential density relative to the surface [R ~> kg m-3]}
151   \textcolor{keywordtype}{real} :: p0(SZI\_(G))     \textcolor{comment}{! A pressure of 0 [R L2 T-2 ~> Pa]}
152 
153   \textcolor{keywordtype}{real} :: h\_vel           \textcolor{comment}{! htot interpolated onto velocity points [Z ~> m] (not H).}
154   \textcolor{keywordtype}{real} :: absf            \textcolor{comment}{! absolute value of f, interpolated to velocity points [T-1 ~> s-1]}
155   \textcolor{keywordtype}{real} :: u\_star          \textcolor{comment}{! surface friction velocity, interpolated to velocity points [Z T-1 ~> m s-1].}
156   \textcolor{keywordtype}{real} :: mom\_mixrate     \textcolor{comment}{! rate at which momentum is homogenized within mixed layer [T-1 ~> s-1]}
157   \textcolor{keywordtype}{real} :: timescale       \textcolor{comment}{! mixing growth timescale [T ~> s]}
158   \textcolor{keywordtype}{real} :: h\_neglect       \textcolor{comment}{! tiny thickness usually lost in roundoff so can be neglected [H ~> m or kg m-2]}
159   \textcolor{keywordtype}{real} :: dz\_neglect      \textcolor{comment}{! A tiny thickness that is usually lost in roundoff so can be neglected [Z ~> m]}
160   \textcolor{keywordtype}{real} :: I4dt            \textcolor{comment}{! 1/(4 dt) [T-1 ~> s-1]}
161   \textcolor{keywordtype}{real} :: Ihtot,Ihtot\_slow\textcolor{comment}{! Inverses of the total mixed layer thickness [H-1 ~> m-1 or m2 kg-1]}
162   \textcolor{keywordtype}{real} :: a(SZK\_(G))      \textcolor{comment}{! A non-dimensional value relating the overall flux}
163                           \textcolor{comment}{! magnitudes (uDml & vDml) to the realized flux in a}
164                           \textcolor{comment}{! layer.  The vertical sum of a() through the pieces of}
165                           \textcolor{comment}{! the mixed layer must be 0.}
166   \textcolor{keywordtype}{real} :: b(SZK\_(G))      \textcolor{comment}{! As for a(k) but for the slow-filtered MLD}
167   \textcolor{keywordtype}{real} :: uDml(SZIB\_(G))  \textcolor{comment}{! The zonal and meridional volume fluxes in the upper}
168   \textcolor{keywordtype}{real} :: vDml(SZI\_(G))   \textcolor{comment}{! half of the mixed layer [H L2 T-1 ~> m3 s-1 or kg s-1].}
169   \textcolor{keywordtype}{real} :: uDml\_slow(SZIB\_(G))  \textcolor{comment}{! The zonal and meridional volume fluxes in the upper}
170   \textcolor{keywordtype}{real} :: vDml\_slow(SZI\_(G))   \textcolor{comment}{! half of the mixed layer [H L2 T-1 ~> m3 s-1 or kg s-1].}
171   \textcolor{keywordtype}{real} :: utimescale\_diag(SZIB\_(G),SZJ\_(G)) \textcolor{comment}{! restratification timescales in the zonal and}
172   \textcolor{keywordtype}{real} :: vtimescale\_diag(SZI\_(G),SZJB\_(G)) \textcolor{comment}{! meridional directions [T ~> s], stored in 2-D arrays}
173                                             \textcolor{comment}{! for diagnostic purposes.}
174   \textcolor{keywordtype}{real} :: uDml\_diag(SZIB\_(G),SZJ\_(G)), vDml\_diag(SZI\_(G),SZJB\_(G))
175   \textcolor{keywordtype}{real}, \textcolor{keywordtype}{dimension(SZI\_(G))} :: rhoSurf, deltaRhoAtKm1, deltaRhoAtK \textcolor{comment}{! Densities [R ~> kg m-3]}
176   \textcolor{keywordtype}{real}, \textcolor{keywordtype}{dimension(SZI\_(G))} :: dK, dKm1 \textcolor{comment}{! Depths of layer centers [H ~> m or kg m-2].}
177   \textcolor{keywordtype}{real}, \textcolor{keywordtype}{dimension(SZI\_(G))} :: pRef\_MLD \textcolor{comment}{! A reference pressure for calculating the mixed layer}
178                                        \textcolor{comment}{! densities [R L2 T-2 ~> Pa].}
179   \textcolor{keywordtype}{real}, \textcolor{keywordtype}{dimension(SZI\_(G))} :: rhoAtK, rho1, d1, pRef\_N2 \textcolor{comment}{! Used for N2}
180   \textcolor{keywordtype}{real} :: aFac, bFac \textcolor{comment}{! Nondimensional ratios [nondim]}
181   \textcolor{keywordtype}{real} :: ddRho    \textcolor{comment}{! A density difference [R ~> kg m-3]}
182   \textcolor{keywordtype}{real} :: hAtVel, zpa, zpb, dh, res\_scaling\_fac
183   \textcolor{keywordtype}{real} :: I\_LFront \textcolor{comment}{! The inverse of the frontal length scale [L-1 ~> m-1]}
184   \textcolor{keywordtype}{logical} :: line\_is\_empty, keep\_going, res\_upscale
185   \textcolor{keywordtype}{integer}, \textcolor{keywordtype}{dimension(2)} :: EOSdom \textcolor{comment}{! The i-computational domain for the equation of state}
186   \textcolor{keywordtype}{integer} :: i, j, k, is, ie, js, je, Isq, Ieq, Jsq, Jeq, nz
187 
188   \textcolor{keywordtype}{real} :: PSI, PSI1, z, BOTTOP, XP, DD \textcolor{comment}{! For the following statement functions}
189   \textcolor{comment}{! Stream function as a function of non-dimensional position within mixed-layer (F77 statement function)}
190   \textcolor{comment}{!PSI1(z) = max(0., (1. - (2.*z+1.)**2 ) )}
191   psi1(z) = max(0., (1. - (2.*z+1.)**2 ) * (1. + (5./21.)*(2.*z+1.)**2) )
192   bottop(z) = 0.5*(1.-sign(1.,z+0.5)) \textcolor{comment}{! =0 for z>-0.5, =1 for z<-0.5}
193   xp(z) = max(0., min(1., (-z-0.5)*2./(1.+2.*cs%MLE\_tail\_dh) ) )
194   dd(z) = (1.-3.*(xp(z)**2)+2.*(xp(z)**3))**(1.+2.*cs%MLE\_tail\_dh)
195   psi(z) = max( psi1(z), dd(z)*bottop(z) ) \textcolor{comment}{! Combines original PSI1 with tail}
196 
197   is  = g%isc  ; ie  = g%iec  ; js  = g%jsc  ; je  = g%jec ; nz = g%ke
198   isq = g%IscB ; ieq = g%IecB ; jsq = g%JscB ; jeq = g%JecB
199 
200   \textcolor{keywordflow}{if} (.not.\textcolor{keyword}{associated}(tv%eqn\_of\_state)) \textcolor{keyword}{call }mom\_error(fatal, \textcolor{stringliteral}{"MOM\_mixedlayer\_restrat: "}// &
201          \textcolor{stringliteral}{"An equation of state must be used with this module."})
202   \textcolor{keywordflow}{if} (.not.\textcolor{keyword}{associated}(varmix) .and. cs%front\_length>0.) \textcolor{keyword}{call }mom\_error(fatal, \textcolor{stringliteral}{"MOM\_mixedlayer\_restrat: "}// 
      &
203          \textcolor{stringliteral}{"The resolution argument, Rd/dx, was not associated."})
204 
205   \textcolor{keywordflow}{if} (cs%MLE\_density\_diff > 0.) \textcolor{keywordflow}{then} \textcolor{comment}{! We need to calculate a mixed layer depth, MLD.}
206     \textcolor{comment}{!! TODO: use derivatives and mid-MLD pressure. Currently this is sigma-0. -AJA}
207     pref\_mld(:) = 0.
208     eosdom(:) = eos\_domain(g%HI, halo=1)
209     \textcolor{keywordflow}{do} j = js-1, je+1
210       dk(:) = 0.5 * h(:,j,1) \textcolor{comment}{! Depth of center of surface layer}
211       \textcolor{keyword}{call }calculate\_density(tv%T(:,j,1), tv%S(:,j,1), pref\_mld, rhosurf, tv%eqn\_of\_state, eosdom)
212       deltarhoatk(:) = 0.
213       mld\_fast(:,j) = 0.
214       \textcolor{keywordflow}{do} k = 2, nz
215         dkm1(:) = dk(:) \textcolor{comment}{! Depth of center of layer K-1}
216         dk(:) = dk(:) + 0.5 * ( h(:,j,k) + h(:,j,k-1) ) \textcolor{comment}{! Depth of center of layer K}
217         \textcolor{comment}{! Mixed-layer depth, using sigma-0 (surface reference pressure)}
218         deltarhoatkm1(:) = deltarhoatk(:) \textcolor{comment}{! Store value from previous iteration of K}
219         \textcolor{keyword}{call }calculate\_density(tv%T(:,j,k), tv%S(:,j,k), pref\_mld, deltarhoatk, tv%eqn\_of\_state, eosdom)
220         \textcolor{keywordflow}{do} i = is-1,ie+1
221           deltarhoatk(i) = deltarhoatk(i) - rhosurf(i) \textcolor{comment}{! Density difference between layer K and surface}
222 \textcolor{keywordflow}{        enddo}
223         \textcolor{keywordflow}{do} i = is-1, ie+1
224           ddrho = deltarhoatk(i) - deltarhoatkm1(i)
225           \textcolor{keywordflow}{if} ((mld\_fast(i,j)==0.) .and. (ddrho>0.) .and. &
226               (deltarhoatkm1(i)<cs%MLE\_density\_diff) .and. (deltarhoatk(i)>=cs%MLE\_density\_diff)) \textcolor{keywordflow}{then}
227             afac = ( cs%MLE\_density\_diff - deltarhoatkm1(i) ) / ddrho
228             mld\_fast(i,j) = dk(i) * afac + dkm1(i) * (1. - afac)
229 \textcolor{keywordflow}{          endif}
230 \textcolor{keywordflow}{        enddo} \textcolor{comment}{! i-loop}
231 \textcolor{keywordflow}{      enddo} \textcolor{comment}{! k-loop}
232       \textcolor{keywordflow}{do} i = is-1, ie+1
233         mld\_fast(i,j) = cs%MLE\_MLD\_stretch * mld\_fast(i,j)
234         \textcolor{keywordflow}{if} ((mld\_fast(i,j)==0.) .and. (deltarhoatk(i)<cs%MLE\_density\_diff)) &
235           mld\_fast(i,j) = dk(i) \textcolor{comment}{! Assume mixing to the bottom}
236 \textcolor{keywordflow}{      enddo}
237 \textcolor{keywordflow}{    enddo} \textcolor{comment}{! j-loop}
238   \textcolor{keywordflow}{elseif} (cs%MLE\_use\_PBL\_MLD) \textcolor{keywordflow}{then}
239     \textcolor{keywordflow}{if} (.not. \textcolor{keyword}{associated}(mld\_in)) \textcolor{keyword}{call }mom\_error(fatal, \textcolor{stringliteral}{"MOM\_mixedlayer\_restrat: "}// &
240          \textcolor{stringliteral}{"Argument MLD\_in was not associated!"})
241     \textcolor{keywordflow}{do} j = js-1, je+1 ; \textcolor{keywordflow}{do} i = is-1, ie+1
242       mld\_fast(i,j) = (cs%MLE\_MLD\_stretch * gv%Z\_to\_H) * mld\_in(i,j)
243 \textcolor{keywordflow}{    enddo} ;\textcolor{keywordflow}{ enddo}
244   \textcolor{keywordflow}{else}
245     \textcolor{keyword}{call }mom\_error(fatal, \textcolor{stringliteral}{"MOM\_mixedlayer\_restrat: "}// &
246          \textcolor{stringliteral}{"No MLD to use for MLE parameterization."})
247 \textcolor{keywordflow}{  endif}
248 
249   \textcolor{comment}{! Apply time filter (to remove diurnal cycle)}
250   \textcolor{keywordflow}{if} (cs%MLE\_MLD\_decay\_time>0.) \textcolor{keywordflow}{then}
251     \textcolor{keywordflow}{if} (cs%debug) \textcolor{keywordflow}{then}
252       \textcolor{keyword}{call }hchksum(cs%MLD\_filtered, \textcolor{stringliteral}{'mixed\_layer\_restrat: MLD\_filtered'}, g%HI, haloshift=1, scale=gv%H\_to\_m
      )
253       \textcolor{keyword}{call }hchksum(mld\_in, \textcolor{stringliteral}{'mixed\_layer\_restrat: MLD in'}, g%HI, haloshift=1, scale=us%Z\_to\_m)
254 \textcolor{keywordflow}{    endif}
255     afac = cs%MLE\_MLD\_decay\_time / ( dt + cs%MLE\_MLD\_decay\_time )
256     bfac = dt / ( dt + cs%MLE\_MLD\_decay\_time )
257     \textcolor{keywordflow}{do} j = js-1, je+1 ; \textcolor{keywordflow}{do} i = is-1, ie+1
258       \textcolor{comment}{! Expression bFac*MLD\_fast(i,j) + aFac*CS%MLD\_filtered(i,j) is the time-filtered}
259       \textcolor{comment}{! (running mean) of MLD. The max() allows the "running mean" to be reset}
260       \textcolor{comment}{! instantly to a deeper MLD.}
261       cs%MLD\_filtered(i,j) = max( mld\_fast(i,j), bfac*mld\_fast(i,j) + afac*cs%MLD\_filtered(i,j) )
262       mld\_fast(i,j) = cs%MLD\_filtered(i,j)
263 \textcolor{keywordflow}{    enddo} ;\textcolor{keywordflow}{ enddo}
264 \textcolor{keywordflow}{  endif}
265 
266   \textcolor{comment}{! Apply slower time filter (to remove seasonal cycle) on already filtered MLD\_fast}
267   \textcolor{keywordflow}{if} (cs%MLE\_MLD\_decay\_time2>0.) \textcolor{keywordflow}{then}
268     \textcolor{keywordflow}{if} (cs%debug) \textcolor{keywordflow}{then}
269       \textcolor{keyword}{call }hchksum(cs%MLD\_filtered\_slow,\textcolor{stringliteral}{'mixed\_layer\_restrat: MLD\_filtered\_slow'},g%HI,haloshift=1,scale=gv
      %H\_to\_m)
270       \textcolor{keyword}{call }hchksum(mld\_fast,\textcolor{stringliteral}{'mixed\_layer\_restrat: MLD fast'},g%HI,haloshift=1,scale=gv%H\_to\_m)
271 \textcolor{keywordflow}{    endif}
272     afac = cs%MLE\_MLD\_decay\_time2 / ( dt + cs%MLE\_MLD\_decay\_time2 )
273     bfac = dt / ( dt + cs%MLE\_MLD\_decay\_time2 )
274     \textcolor{keywordflow}{do} j = js-1, je+1 ; \textcolor{keywordflow}{do} i = is-1, ie+1
275       \textcolor{comment}{! Expression bFac*MLD\_fast(i,j) + aFac*CS%MLD\_filtered(i,j) is the time-filtered}
276       \textcolor{comment}{! (running mean) of MLD. The max() allows the "running mean" to be reset}
277       \textcolor{comment}{! instantly to a deeper MLD.}
278       cs%MLD\_filtered\_slow(i,j) = max( mld\_fast(i,j), bfac*mld\_fast(i,j) + afac*cs%MLD\_filtered\_slow(i,j) )
279       mld\_slow(i,j) = cs%MLD\_filtered\_slow(i,j)
280 \textcolor{keywordflow}{    enddo} ;\textcolor{keywordflow}{ enddo}
281   \textcolor{keywordflow}{else}
282     \textcolor{keywordflow}{do} j = js-1, je+1 ; \textcolor{keywordflow}{do} i = is-1, ie+1
283       mld\_slow(i,j) = mld\_fast(i,j)
284 \textcolor{keywordflow}{    enddo} ;\textcolor{keywordflow}{ enddo}
285 \textcolor{keywordflow}{  endif}
286 
287   udml(:) = 0.0 ; vdml(:) = 0.0
288   udml\_slow(:) = 0.0 ; vdml\_slow(:) = 0.0
289   i4dt = 0.25 / dt
290   g\_rho0 = gv%g\_Earth / gv%Rho0
291   h\_neglect = gv%H\_subroundoff
292   dz\_neglect = gv%H\_subroundoff*gv%H\_to\_Z
293   \textcolor{keywordflow}{if} (cs%front\_length>0.) \textcolor{keywordflow}{then}
294     res\_upscale = .true.
295     i\_lfront = 1. / cs%front\_length
296   \textcolor{keywordflow}{else}
297     res\_upscale = .false.
298 \textcolor{keywordflow}{  endif}
299 
300   p0(:) = 0.0
301   eosdom(:) = eos\_domain(g%HI, halo=1)
302 \textcolor{comment}{!$OMP parallel default(none) shared(is,ie,js,je,G,GV,US,htot\_fast,Rml\_av\_fast,tv,p0,h,h\_avail,&}
303 \textcolor{comment}{!$OMP                               h\_neglect,g\_Rho0,I4dt,CS,uhml,uhtr,dt,vhml,vhtr,EOSdom,   &}
304 \textcolor{comment}{!$OMP                               utimescale\_diag,vtimescale\_diag,forces,dz\_neglect, &}
305 \textcolor{comment}{!$OMP                               htot\_slow,MLD\_slow,Rml\_av\_slow,VarMix,I\_LFront,    &}
306 \textcolor{comment}{!$OMP                               res\_upscale, nz,MLD\_fast,uDml\_diag,vDml\_diag)      &}
307 \textcolor{comment}{!$OMP                       private(rho\_ml,h\_vel,u\_star,absf,mom\_mixrate,timescale,    &}
308 \textcolor{comment}{!$OMP                               line\_is\_empty, keep\_going,res\_scaling\_fac,         &}
309 \textcolor{comment}{!$OMP                               a,IhTot,b,Ihtot\_slow,zpb,hAtVel,zpa,dh)            &}
310 \textcolor{comment}{!$OMP                       firstprivate(uDml,vDml,uDml\_slow,vDml\_slow)}
311 \textcolor{comment}{!$OMP do}
312   \textcolor{keywordflow}{do} j=js-1,je+1
313     \textcolor{keywordflow}{do} i=is-1,ie+1
314       htot\_fast(i,j) = 0.0 ; rml\_av\_fast(i,j) = 0.0
315       htot\_slow(i,j) = 0.0 ; rml\_av\_slow(i,j) = 0.0
316 \textcolor{keywordflow}{    enddo}
317     keep\_going = .true.
318     \textcolor{keywordflow}{do} k=1,nz
319       \textcolor{keywordflow}{do} i=is-1,ie+1
320         h\_avail(i,j,k) = max(i4dt*g%areaT(i,j)*(h(i,j,k)-gv%Angstrom\_H),0.0)
321 \textcolor{keywordflow}{      enddo}
322       \textcolor{keywordflow}{if} (keep\_going) \textcolor{keywordflow}{then}
323         \textcolor{keyword}{call }calculate\_density(tv%T(:,j,k), tv%S(:,j,k), p0, rho\_ml(:), tv%eqn\_of\_state, eosdom)
324         line\_is\_empty = .true.
325         \textcolor{keywordflow}{do} i=is-1,ie+1
326           \textcolor{keywordflow}{if} (htot\_fast(i,j) < mld\_fast(i,j)) \textcolor{keywordflow}{then}
327             dh = min( h(i,j,k), mld\_fast(i,j)-htot\_fast(i,j) )
328             rml\_av\_fast(i,j) = rml\_av\_fast(i,j) + dh*rho\_ml(i)
329             htot\_fast(i,j) = htot\_fast(i,j) + dh
330             line\_is\_empty = .false.
331 \textcolor{keywordflow}{          endif}
332           \textcolor{keywordflow}{if} (htot\_slow(i,j) < mld\_slow(i,j)) \textcolor{keywordflow}{then}
333             dh = min( h(i,j,k), mld\_slow(i,j)-htot\_slow(i,j) )
334             rml\_av\_slow(i,j) = rml\_av\_slow(i,j) + dh*rho\_ml(i)
335             htot\_slow(i,j) = htot\_slow(i,j) + dh
336             line\_is\_empty = .false.
337 \textcolor{keywordflow}{          endif}
338 \textcolor{keywordflow}{        enddo}
339         \textcolor{keywordflow}{if} (line\_is\_empty) keep\_going=.false.
340 \textcolor{keywordflow}{      endif}
341 \textcolor{keywordflow}{    enddo}
342 
343     \textcolor{keywordflow}{do} i=is-1,ie+1
344       rml\_av\_fast(i,j) = -(g\_rho0*rml\_av\_fast(i,j)) / (htot\_fast(i,j) + h\_neglect)
345       rml\_av\_slow(i,j) = -(g\_rho0*rml\_av\_slow(i,j)) / (htot\_slow(i,j) + h\_neglect)
346 \textcolor{keywordflow}{    enddo}
347 \textcolor{keywordflow}{  enddo}
348 
349   \textcolor{keywordflow}{if} (cs%debug) \textcolor{keywordflow}{then}
350     \textcolor{keyword}{call }hchksum(h,\textcolor{stringliteral}{'mixed\_layer\_restrat: h'}, g%HI, haloshift=1, scale=gv%H\_to\_m)
351     \textcolor{keyword}{call }hchksum(forces%ustar,\textcolor{stringliteral}{'mixed\_layer\_restrat: u*'}, g%HI, haloshift=1, scale=us%Z\_to\_m*us%s\_to\_T)
352     \textcolor{keyword}{call }hchksum(mld\_fast,\textcolor{stringliteral}{'mixed\_layer\_restrat: MLD'}, g%HI, haloshift=1, scale=gv%H\_to\_m)
353     \textcolor{keyword}{call }hchksum(rml\_av\_fast,\textcolor{stringliteral}{'mixed\_layer\_restrat: rml'}, g%HI, haloshift=1, &
354                  scale=us%m\_to\_Z*us%L\_T\_to\_m\_s**2)
355 \textcolor{keywordflow}{  endif}
356 
357 \textcolor{comment}{! TO DO:}
358 \textcolor{comment}{!   1. Mixing extends below the mixing layer to the mixed layer.  Find it!}
359 \textcolor{comment}{!   2. Add exponential tail to stream-function?}
360 
361 \textcolor{comment}{!   U - Component}
362 \textcolor{comment}{!$OMP do}
363   \textcolor{keywordflow}{do} j=js,je ; \textcolor{keywordflow}{do} i=is-1,ie
364     u\_star = 0.5*(forces%ustar(i,j) + forces%ustar(i+1,j))
365     absf = 0.5*(abs(g%CoriolisBu(i,j-1)) + abs(g%CoriolisBu(i,j)))
366     \textcolor{comment}{! If needed, res\_scaling\_fac = min( ds, L\_d ) / l\_f}
367     \textcolor{keywordflow}{if} (res\_upscale) res\_scaling\_fac = &
368           ( sqrt( 0.5 * ( g%dxCu(i,j)**2 + g%dyCu(i,j)**2 ) ) * i\_lfront ) &
369           * min( 1., 0.5*( varmix%Rd\_dx\_h(i,j) + varmix%Rd\_dx\_h(i+1,j) ) )
370 
371     \textcolor{comment}{! peak ML visc: u\_star * 0.41 * (h\_ml*u\_star)/(absf*h\_ml + 4.0*u\_star)}
372     \textcolor{comment}{! momentum mixing rate: pi^2*visc/h\_ml^2}
373     \textcolor{comment}{! 0.41 is the von Karmen constant, 9.8696 = pi^2.}
374     h\_vel = 0.5*((htot\_fast(i,j) + htot\_fast(i+1,j)) + h\_neglect) * gv%H\_to\_Z
375     mom\_mixrate = (0.41*9.8696)*u\_star**2 / &
376                   (absf*h\_vel**2 + 4.0*(h\_vel+dz\_neglect)*u\_star)
377     timescale = 0.0625 * (absf + 2.0*mom\_mixrate) / (absf**2 + mom\_mixrate**2)
378     timescale = timescale * cs%ml\_restrat\_coef
379     \textcolor{keywordflow}{if} (res\_upscale) timescale = timescale * res\_scaling\_fac
380     udml(i) = timescale * g%mask2dCu(i,j)*g%dyCu(i,j)*g%IdxCu(i,j) * &
381         (rml\_av\_fast(i+1,j)-rml\_av\_fast(i,j)) * (h\_vel**2 * gv%Z\_to\_H)
382     \textcolor{comment}{! As above but using the slow filtered MLD}
383     h\_vel = 0.5*((htot\_slow(i,j) + htot\_slow(i+1,j)) + h\_neglect) * gv%H\_to\_Z
384     mom\_mixrate = (0.41*9.8696)*u\_star**2 / &
385                   (absf*h\_vel**2 + 4.0*(h\_vel+dz\_neglect)*u\_star)
386     timescale = 0.0625 * (absf + 2.0*mom\_mixrate) / (absf**2 + mom\_mixrate**2)
387     timescale = timescale * cs%ml\_restrat\_coef2
388     \textcolor{keywordflow}{if} (res\_upscale) timescale = timescale * res\_scaling\_fac
389     udml\_slow(i) = timescale * g%mask2dCu(i,j)*g%dyCu(i,j)*g%IdxCu(i,j) * &
390         (rml\_av\_slow(i+1,j)-rml\_av\_slow(i,j)) * (h\_vel**2 * gv%Z\_to\_H)
391 
392     \textcolor{keywordflow}{if} (udml(i) + udml\_slow(i) == 0.) \textcolor{keywordflow}{then}
393       \textcolor{keywordflow}{do} k=1,nz ; uhml(i,j,k) = 0.0 ;\textcolor{keywordflow}{ enddo}
394     \textcolor{keywordflow}{else}
395       ihtot = 2.0 / ((htot\_fast(i,j) + htot\_fast(i+1,j)) + h\_neglect)
396       ihtot\_slow = 2.0 / ((htot\_slow(i,j) + htot\_slow(i+1,j)) + h\_neglect)
397       zpa = 0.0 ; zpb = 0.0
398       \textcolor{comment}{! a(k) relates the sublayer transport to uDml with a linear profile.}
399       \textcolor{comment}{! The sum of a(k) through the mixed layers must be 0.}
400       \textcolor{keywordflow}{do} k=1,nz
401         hatvel = 0.5*(h(i,j,k) + h(i+1,j,k))
402         a(k) = psi(zpa)                     \textcolor{comment}{! Psi(z/MLD) for upper interface}
403         zpa = zpa - (hatvel * ihtot)        \textcolor{comment}{! z/H for lower interface}
404         a(k) = a(k) - psi(zpa)              \textcolor{comment}{! Transport profile}
405         \textcolor{comment}{! Limit magnitude (uDml) if it would violate CFL}
406         \textcolor{keywordflow}{if} (a(k)*udml(i) > 0.0) \textcolor{keywordflow}{then}
407           \textcolor{keywordflow}{if} (a(k)*udml(i) > h\_avail(i,j,k)) udml(i) = h\_avail(i,j,k) / a(k)
408         \textcolor{keywordflow}{elseif} (a(k)*udml(i) < 0.0) \textcolor{keywordflow}{then}
409           \textcolor{keywordflow}{if} (-a(k)*udml(i) > h\_avail(i+1,j,k)) udml(i) = -h\_avail(i+1,j,k) / a(k)
410 \textcolor{keywordflow}{        endif}
411 \textcolor{keywordflow}{      enddo}
412       \textcolor{keywordflow}{do} k=1,nz
413         \textcolor{comment}{! Transport for slow-filtered MLD}
414         hatvel = 0.5*(h(i,j,k) + h(i+1,j,k))
415         b(k) = psi(zpb)                     \textcolor{comment}{! Psi(z/MLD) for upper interface}
416         zpb = zpb - (hatvel * ihtot\_slow)   \textcolor{comment}{! z/H for lower interface}
417         b(k) = b(k) - psi(zpb)              \textcolor{comment}{! Transport profile}
418         \textcolor{comment}{! Limit magnitude (uDml\_slow) if it would violate CFL when added to uDml}
419         \textcolor{keywordflow}{if} (b(k)*udml\_slow(i) > 0.0) \textcolor{keywordflow}{then}
420           \textcolor{keywordflow}{if} (b(k)*udml\_slow(i) > h\_avail(i,j,k) - a(k)*udml(i)) &
421              udml\_slow(i) = max( 0., h\_avail(i,j,k) - a(k)*udml(i) ) / b(k)
422         \textcolor{keywordflow}{elseif} (b(k)*udml\_slow(i) < 0.0) \textcolor{keywordflow}{then}
423           \textcolor{keywordflow}{if} (-b(k)*udml\_slow(i) > h\_avail(i+1,j,k) + a(k)*udml(i)) &
424              udml\_slow(i) = -max( 0., h\_avail(i+1,j,k) + a(k)*udml(i) ) / b(k)
425 \textcolor{keywordflow}{        endif}
426 \textcolor{keywordflow}{      enddo}
427       \textcolor{keywordflow}{do} k=1,nz
428         uhml(i,j,k) = a(k)*udml(i) + b(k)*udml\_slow(i)
429         uhtr(i,j,k) = uhtr(i,j,k) + uhml(i,j,k)*dt
430 \textcolor{keywordflow}{      enddo}
431 \textcolor{keywordflow}{    endif}
432 
433     utimescale\_diag(i,j) = timescale
434     udml\_diag(i,j) = udml(i)
435 \textcolor{keywordflow}{  enddo} ;\textcolor{keywordflow}{ enddo}
436 
437 \textcolor{comment}{!  V- component}
438 \textcolor{comment}{!$OMP do}
439   \textcolor{keywordflow}{do} j=js-1,je ; \textcolor{keywordflow}{do} i=is,ie
440     u\_star = 0.5*(forces%ustar(i,j) + forces%ustar(i,j+1))
441     absf = 0.5*(abs(g%CoriolisBu(i-1,j)) + abs(g%CoriolisBu(i,j)))
442     \textcolor{comment}{! If needed, res\_scaling\_fac = min( ds, L\_d ) / l\_f}
443     \textcolor{keywordflow}{if} (res\_upscale) res\_scaling\_fac = &
444           ( sqrt( 0.5 * ( (g%dxCv(i,j))**2 + (g%dyCv(i,j))**2 ) ) * i\_lfront ) &
445           * min( 1., 0.5*( varmix%Rd\_dx\_h(i,j) + varmix%Rd\_dx\_h(i,j+1) ) )
446 
447     \textcolor{comment}{! peak ML visc: u\_star * 0.41 * (h\_ml*u\_star)/(absf*h\_ml + 4.0*u\_star)}
448     \textcolor{comment}{! momentum mixing rate: pi^2*visc/h\_ml^2}
449     \textcolor{comment}{! 0.41 is the von Karmen constant, 9.8696 = pi^2.}
450     h\_vel = 0.5*((htot\_fast(i,j) + htot\_fast(i,j+1)) + h\_neglect) * gv%H\_to\_Z
451     mom\_mixrate = (0.41*9.8696)*u\_star**2 / &
452                   (absf*h\_vel**2 + 4.0*(h\_vel+dz\_neglect)*u\_star)
453     timescale = 0.0625 * (absf + 2.0*mom\_mixrate) / (absf**2 + mom\_mixrate**2)
454     timescale = timescale * cs%ml\_restrat\_coef
455     \textcolor{keywordflow}{if} (res\_upscale) timescale = timescale * res\_scaling\_fac
456     vdml(i) = timescale * g%mask2dCv(i,j)*g%dxCv(i,j)*g%IdyCv(i,j) * &
457         (rml\_av\_fast(i,j+1)-rml\_av\_fast(i,j)) * (h\_vel**2 * gv%Z\_to\_H)
458     \textcolor{comment}{! As above but using the slow filtered MLD}
459     h\_vel = 0.5*((htot\_slow(i,j) + htot\_slow(i,j+1)) + h\_neglect) * gv%H\_to\_Z
460     mom\_mixrate = (0.41*9.8696)*u\_star**2 / &
461                   (absf*h\_vel**2 + 4.0*(h\_vel+dz\_neglect)*u\_star)
462     timescale = 0.0625 * (absf + 2.0*mom\_mixrate) / (absf**2 + mom\_mixrate**2)
463     timescale = timescale * cs%ml\_restrat\_coef2
464     \textcolor{keywordflow}{if} (res\_upscale) timescale = timescale * res\_scaling\_fac
465     vdml\_slow(i) = timescale * g%mask2dCv(i,j)*g%dxCv(i,j)*g%IdyCv(i,j) * &
466         (rml\_av\_slow(i,j+1)-rml\_av\_slow(i,j)) * (h\_vel**2 * gv%Z\_to\_H)
467 
468     \textcolor{keywordflow}{if} (vdml(i) + vdml\_slow(i) == 0.) \textcolor{keywordflow}{then}
469       \textcolor{keywordflow}{do} k=1,nz ; vhml(i,j,k) = 0.0 ;\textcolor{keywordflow}{ enddo}
470     \textcolor{keywordflow}{else}
471       ihtot = 2.0 / ((htot\_fast(i,j) + htot\_fast(i,j+1)) + h\_neglect)
472       ihtot\_slow = 2.0 / ((htot\_slow(i,j) + htot\_slow(i,j+1)) + h\_neglect)
473       zpa = 0.0 ; zpb = 0.0
474       \textcolor{comment}{! a(k) relates the sublayer transport to vDml with a linear profile.}
475       \textcolor{comment}{! The sum of a(k) through the mixed layers must be 0.}
476       \textcolor{keywordflow}{do} k=1,nz
477         hatvel = 0.5*(h(i,j,k) + h(i,j+1,k))
478         a(k) = psi( zpa )                   \textcolor{comment}{! Psi(z/MLD) for upper interface}
479         zpa = zpa - (hatvel * ihtot)        \textcolor{comment}{! z/H for lower interface}
480         a(k) = a(k) - psi( zpa )            \textcolor{comment}{! Transport profile}
481         \textcolor{comment}{! Limit magnitude (vDml) if it would violate CFL}
482         \textcolor{keywordflow}{if} (a(k)*vdml(i) > 0.0) \textcolor{keywordflow}{then}
483           \textcolor{keywordflow}{if} (a(k)*vdml(i) > h\_avail(i,j,k)) vdml(i) = h\_avail(i,j,k) / a(k)
484         \textcolor{keywordflow}{elseif} (a(k)*vdml(i) < 0.0) \textcolor{keywordflow}{then}
485           \textcolor{keywordflow}{if} (-a(k)*vdml(i) > h\_avail(i,j+1,k)) vdml(i) = -h\_avail(i,j+1,k) / a(k)
486 \textcolor{keywordflow}{        endif}
487 \textcolor{keywordflow}{      enddo}
488       \textcolor{keywordflow}{do} k=1,nz
489         \textcolor{comment}{! Transport for slow-filtered MLD}
490         hatvel = 0.5*(h(i,j,k) + h(i,j+1,k))
491         b(k) = psi(zpb)                     \textcolor{comment}{! Psi(z/MLD) for upper interface}
492         zpb = zpb - (hatvel * ihtot\_slow)   \textcolor{comment}{! z/H for lower interface}
493         b(k) = b(k) - psi(zpb)              \textcolor{comment}{! Transport profile}
494         \textcolor{comment}{! Limit magnitude (vDml\_slow) if it would violate CFL when added to vDml}
495         \textcolor{keywordflow}{if} (b(k)*vdml\_slow(i) > 0.0) \textcolor{keywordflow}{then}
496           \textcolor{keywordflow}{if} (b(k)*vdml\_slow(i) > h\_avail(i,j,k) - a(k)*vdml(i)) &
497              vdml\_slow(i) = max( 0., h\_avail(i,j,k) - a(k)*vdml(i) ) / b(k)
498         \textcolor{keywordflow}{elseif} (b(k)*vdml\_slow(i) < 0.0) \textcolor{keywordflow}{then}
499           \textcolor{keywordflow}{if} (-b(k)*vdml\_slow(i) > h\_avail(i,j+1,k) + a(k)*vdml(i)) &
500              vdml\_slow(i) = -max( 0., h\_avail(i,j+1,k) + a(k)*vdml(i) ) / b(k)
501 \textcolor{keywordflow}{        endif}
502 \textcolor{keywordflow}{      enddo}
503       \textcolor{keywordflow}{do} k=1,nz
504         vhml(i,j,k) = a(k)*vdml(i) + b(k)*vdml\_slow(i)
505         vhtr(i,j,k) = vhtr(i,j,k) + vhml(i,j,k)*dt
506 \textcolor{keywordflow}{      enddo}
507 \textcolor{keywordflow}{    endif}
508 
509     vtimescale\_diag(i,j) = timescale
510     vdml\_diag(i,j) = vdml(i)
511 \textcolor{keywordflow}{  enddo} ;\textcolor{keywordflow}{ enddo}
512 
513 \textcolor{comment}{!$OMP do}
514   \textcolor{keywordflow}{do} j=js,je ; \textcolor{keywordflow}{do} k=1,nz ; \textcolor{keywordflow}{do} i=is,ie
515     h(i,j,k) = h(i,j,k) - dt*g%IareaT(i,j) * &
516         ((uhml(i,j,k) - uhml(i-1,j,k)) + (vhml(i,j,k) - vhml(i,j-1,k)))
517 \textcolor{keywordflow}{  enddo} ;\textcolor{keywordflow}{ enddo} ;\textcolor{keywordflow}{ enddo}
518 \textcolor{comment}{!$OMP end parallel}
519 
520   \textcolor{comment}{! Whenever thickness changes let the diag manager know, target grids}
521   \textcolor{comment}{! for vertical remapping may need to be regenerated.}
522   \textcolor{keywordflow}{if} (cs%id\_uhml > 0 .or. cs%id\_vhml > 0) &
523     \textcolor{comment}{! Remapped uhml and vhml require east/north halo updates of h}
524     \textcolor{keyword}{call }pass\_var(h, g%domain, to\_west+to\_south+omit\_corners, halo=1)
525   \textcolor{keyword}{call }diag\_update\_remap\_grids(cs%diag)
526 
527   \textcolor{comment}{! Offer diagnostic fields for averaging.}
528   \textcolor{keywordflow}{if} (query\_averaging\_enabled(cs%diag)) \textcolor{keywordflow}{then}
529     \textcolor{keywordflow}{if} (cs%id\_urestrat\_time > 0) \textcolor{keyword}{call }post\_data(cs%id\_urestrat\_time, utimescale\_diag, cs%diag)
530     \textcolor{keywordflow}{if} (cs%id\_vrestrat\_time > 0) \textcolor{keyword}{call }post\_data(cs%id\_vrestrat\_time, vtimescale\_diag, cs%diag)
531     \textcolor{keywordflow}{if} (cs%id\_uhml          > 0) \textcolor{keyword}{call }post\_data(cs%id\_uhml, uhml, cs%diag)
532     \textcolor{keywordflow}{if} (cs%id\_vhml          > 0) \textcolor{keyword}{call }post\_data(cs%id\_vhml, vhml, cs%diag)
533     \textcolor{keywordflow}{if} (cs%id\_MLD           > 0) \textcolor{keyword}{call }post\_data(cs%id\_MLD, mld\_fast, cs%diag)
534     \textcolor{keywordflow}{if} (cs%id\_Rml           > 0) \textcolor{keyword}{call }post\_data(cs%id\_Rml, rml\_av\_fast, cs%diag)
535     \textcolor{keywordflow}{if} (cs%id\_uDml          > 0) \textcolor{keyword}{call }post\_data(cs%id\_uDml, udml\_diag, cs%diag)
536     \textcolor{keywordflow}{if} (cs%id\_vDml          > 0) \textcolor{keyword}{call }post\_data(cs%id\_vDml, vdml\_diag, cs%diag)
537 
538     \textcolor{keywordflow}{if} (cs%id\_uml > 0) \textcolor{keywordflow}{then}
539       \textcolor{keywordflow}{do} j=js,je ; \textcolor{keywordflow}{do} i=is-1,ie
540         h\_vel = 0.5*((htot\_fast(i,j) + htot\_fast(i+1,j)) + h\_neglect)
541         udml\_diag(i,j) = udml\_diag(i,j) / (0.01*h\_vel) * g%IdyCu(i,j) * (psi(0.)-psi(-.01))
542 \textcolor{keywordflow}{      enddo} ;\textcolor{keywordflow}{ enddo}
543       \textcolor{keyword}{call }post\_data(cs%id\_uml, udml\_diag, cs%diag)
544 \textcolor{keywordflow}{    endif}
545     \textcolor{keywordflow}{if} (cs%id\_vml > 0) \textcolor{keywordflow}{then}
546       \textcolor{keywordflow}{do} j=js-1,je ; \textcolor{keywordflow}{do} i=is,ie
547         h\_vel = 0.5*((htot\_fast(i,j) + htot\_fast(i,j+1)) + h\_neglect)
548         vdml\_diag(i,j) = vdml\_diag(i,j) / (0.01*h\_vel) * g%IdxCv(i,j) * (psi(0.)-psi(-.01))
549 \textcolor{keywordflow}{      enddo} ;\textcolor{keywordflow}{ enddo}
550       \textcolor{keyword}{call }post\_data(cs%id\_vml, vdml\_diag, cs%diag)
551 \textcolor{keywordflow}{    endif}
552 \textcolor{keywordflow}{  endif}
553   \textcolor{comment}{! Whenever thickness changes let the diag manager know, target grids}
554   \textcolor{comment}{! for vertical remapping may need to be regenerated.}
555   \textcolor{comment}{! This needs to happen after the H update and before the next post\_data.}
556   \textcolor{keyword}{call }diag\_update\_remap\_grids(cs%diag)
557 
\end{DoxyCode}
\mbox{\Hypertarget{namespacemom__mixed__layer__restrat_a89b89663722cc9047a3bb238a4bfa09a}\label{namespacemom__mixed__layer__restrat_a89b89663722cc9047a3bb238a4bfa09a}} 
\index{mom\+\_\+mixed\+\_\+layer\+\_\+restrat@{mom\+\_\+mixed\+\_\+layer\+\_\+restrat}!mixedlayer\+\_\+restrat\+\_\+init@{mixedlayer\+\_\+restrat\+\_\+init}}
\index{mixedlayer\+\_\+restrat\+\_\+init@{mixedlayer\+\_\+restrat\+\_\+init}!mom\+\_\+mixed\+\_\+layer\+\_\+restrat@{mom\+\_\+mixed\+\_\+layer\+\_\+restrat}}
\subsubsection{\texorpdfstring{mixedlayer\+\_\+restrat\+\_\+init()}{mixedlayer\_restrat\_init()}}
{\footnotesize\ttfamily logical function, public mom\+\_\+mixed\+\_\+layer\+\_\+restrat\+::mixedlayer\+\_\+restrat\+\_\+init (\begin{DoxyParamCaption}\item[{type(time\+\_\+type), intent(in)}]{Time,  }\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(param\+\_\+file\+\_\+type), intent(in)}]{param\+\_\+file,  }\item[{type(diag\+\_\+ctrl), intent(inout), target}]{diag,  }\item[{type(\mbox{\hyperlink{structmom__mixed__layer__restrat_1_1mixedlayer__restrat__cs}{mixedlayer\+\_\+restrat\+\_\+cs}}), pointer}]{CS,  }\item[{type(mom\+\_\+restart\+\_\+cs), pointer}]{restart\+\_\+\+CS }\end{DoxyParamCaption})}



Initialize the mixed layer restratification module. 


\begin{DoxyParams}[1]{Parameters}
\mbox{\tt in}  & {\em time} & Current model time\\
\hline
\mbox{\tt in,out}  & {\em g} & Ocean grid structure\\
\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 param\+\_\+file} & Parameter file to parse\\
\hline
\mbox{\tt in,out}  & {\em diag} & Regulate diagnostics\\
\hline
 & {\em cs} & Module control structure\\
\hline
 & {\em restart\+\_\+cs} & A pointer to the restart control structure \\
\hline
\end{DoxyParams}


Definition at line 797 of file M\+O\+M\+\_\+mixed\+\_\+layer\+\_\+restrat.\+F90.


\begin{DoxyCode}
797   \textcolor{keywordtype}{type}(time\_type),             \textcolor{keywordtype}{intent(in)}    :: Time\textcolor{comment}{       !< Current model time}
798   \textcolor{keywordtype}{type}(ocean\_grid\_type),       \textcolor{keywordtype}{intent(inout)} :: G\textcolor{comment}{          !< Ocean grid structure}
799   \textcolor{keywordtype}{type}(verticalGrid\_type),     \textcolor{keywordtype}{intent(in)}    :: GV\textcolor{comment}{         !< Ocean vertical grid structure}
800   \textcolor{keywordtype}{type}(unit\_scale\_type),       \textcolor{keywordtype}{intent(in)}    :: US\textcolor{comment}{         !< A dimensional unit scaling type}
801   \textcolor{keywordtype}{type}(param\_file\_type),       \textcolor{keywordtype}{intent(in)}    :: param\_file\textcolor{comment}{ !< Parameter file to parse}
802   \textcolor{keywordtype}{type}(diag\_ctrl), \textcolor{keywordtype}{target},     \textcolor{keywordtype}{intent(inout)} :: diag\textcolor{comment}{       !< Regulate diagnostics}
803   \textcolor{keywordtype}{type}(mixedlayer\_restrat\_CS), \textcolor{keywordtype}{pointer}       :: CS\textcolor{comment}{         !< Module control structure}
804   \textcolor{keywordtype}{type}(MOM\_restart\_CS),        \textcolor{keywordtype}{pointer}       :: restart\_CS\textcolor{comment}{ !< A pointer to the restart control structure}
805 
806   \textcolor{comment}{! Local variables}
807   \textcolor{keywordtype}{real} :: H\_rescale  \textcolor{comment}{! A rescaling factor for thicknesses from the representation in}
808                      \textcolor{comment}{! a restart file to the internal representation in this run.}
809   \textcolor{keywordtype}{real} :: flux\_to\_kg\_per\_s \textcolor{comment}{! A unit conversion factor for fluxes.}
810   \textcolor{comment}{! This include declares and sets the variable "version".}
811 \textcolor{preprocessor}{# include "version\_variable.h"}
812 \textcolor{preprocessor}{}  \textcolor{keywordtype}{integer} :: i, j
813 
814   \textcolor{comment}{! Read all relevant parameters and write them to the model log.}
815   \textcolor{keyword}{call }get\_param(param\_file, mdl, \textcolor{stringliteral}{"MIXEDLAYER\_RESTRAT"}, mixedlayer\_restrat\_init, &
816              default=.false., do\_not\_log=.true.)
817   \textcolor{keyword}{call }log\_version(param\_file, mdl, version, \textcolor{stringliteral}{""}, all\_default=.not.mixedlayer\_restrat\_init)
818   \textcolor{keyword}{call }get\_param(param\_file, mdl, \textcolor{stringliteral}{"MIXEDLAYER\_RESTRAT"}, mixedlayer\_restrat\_init, &
819              \textcolor{stringliteral}{"If true, a density-gradient dependent re-stratifying "}//&
820              \textcolor{stringliteral}{"flow is imposed in the mixed layer. Can be used in ALE mode "}//&
821              \textcolor{stringliteral}{"without restriction but in layer mode can only be used if "}//&
822              \textcolor{stringliteral}{"BULKMIXEDLAYER is true."}, default=.false.)
823   \textcolor{keywordflow}{if} (.not. mixedlayer\_restrat\_init) \textcolor{keywordflow}{return}
824 
825   \textcolor{keywordflow}{if} (.not.\textcolor{keyword}{associated}(cs)) \textcolor{keywordflow}{then}
826     \textcolor{keyword}{call }mom\_error(fatal, \textcolor{stringliteral}{"mixedlayer\_restrat\_init called without an associated control structure."})
827 \textcolor{keywordflow}{  endif}
828 
829   \textcolor{comment}{! Nonsense values to cause problems when these parameters are not used}
830   cs%MLE\_MLD\_decay\_time = -9.e9*us%s\_to\_T
831   cs%MLE\_density\_diff = -9.e9*us%kg\_m3\_to\_R
832   cs%MLE\_tail\_dh = -9.e9
833   cs%MLE\_use\_PBL\_MLD = .false.
834   cs%MLE\_MLD\_stretch = -9.e9
835 
836   \textcolor{keyword}{call }get\_param(param\_file, mdl, \textcolor{stringliteral}{"DEBUG"}, cs%debug, default=.false., do\_not\_log=.true.)
837   \textcolor{keyword}{call }get\_param(param\_file, mdl, \textcolor{stringliteral}{"FOX\_KEMPER\_ML\_RESTRAT\_COEF"}, cs%ml\_restrat\_coef, &
838              \textcolor{stringliteral}{"A nondimensional coefficient that is proportional to "}//&
839              \textcolor{stringliteral}{"the ratio of the deformation radius to the dominant "}//&
840              \textcolor{stringliteral}{"lengthscale of the submesoscale mixed layer "}//&
841              \textcolor{stringliteral}{"instabilities, times the minimum of the ratio of the "}//&
842              \textcolor{stringliteral}{"mesoscale eddy kinetic energy to the large-scale "}//&
843              \textcolor{stringliteral}{"geostrophic kinetic energy or 1 plus the square of the "}//&
844              \textcolor{stringliteral}{"grid spacing over the deformation radius, as detailed "}//&
845              \textcolor{stringliteral}{"by Fox-Kemper et al. (2010)"}, units=\textcolor{stringliteral}{"nondim"}, default=0.0)
846   \textcolor{comment}{! We use GV%nkml to distinguish between the old and new implementation of MLE.}
847   \textcolor{comment}{! The old implementation only works for the layer model with nkml>0.}
848   \textcolor{keywordflow}{if} (gv%nkml==0) \textcolor{keywordflow}{then}
849     \textcolor{keyword}{call }get\_param(param\_file, mdl, \textcolor{stringliteral}{"FOX\_KEMPER\_ML\_RESTRAT\_COEF2"}, cs%ml\_restrat\_coef2, &
850              \textcolor{stringliteral}{"As for FOX\_KEMPER\_ML\_RESTRAT\_COEF but used in a second application "}//&
851              \textcolor{stringliteral}{"of the MLE restratification parameterization."}, units=\textcolor{stringliteral}{"nondim"}, default=0.0)
852     \textcolor{keyword}{call }get\_param(param\_file, mdl, \textcolor{stringliteral}{"MLE\_FRONT\_LENGTH"}, cs%front\_length, &
853              \textcolor{stringliteral}{"If non-zero, is the frontal-length scale used to calculate the "}//&
854              \textcolor{stringliteral}{"upscaling of buoyancy gradients that is otherwise represented "}//&
855              \textcolor{stringliteral}{"by the parameter FOX\_KEMPER\_ML\_RESTRAT\_COEF. If MLE\_FRONT\_LENGTH is "}//&
856              \textcolor{stringliteral}{"non-zero, it is recommended to set FOX\_KEMPER\_ML\_RESTRAT\_COEF=1.0."},&
857              units=\textcolor{stringliteral}{"m"}, default=0.0, scale=us%m\_to\_L)
858     \textcolor{keyword}{call }get\_param(param\_file, mdl, \textcolor{stringliteral}{"MLE\_USE\_PBL\_MLD"}, cs%MLE\_use\_PBL\_MLD, &
859              \textcolor{stringliteral}{"If true, the MLE parameterization will use the mixed-layer "}//&
860              \textcolor{stringliteral}{"depth provided by the active PBL parameterization. If false, "}//&
861              \textcolor{stringliteral}{"MLE will estimate a MLD based on a density difference with the "}//&
862              \textcolor{stringliteral}{"surface using the parameter MLE\_DENSITY\_DIFF."}, default=.false.)
863     \textcolor{keyword}{call }get\_param(param\_file, mdl, \textcolor{stringliteral}{"MLE\_MLD\_DECAY\_TIME"}, cs%MLE\_MLD\_decay\_time, &
864              \textcolor{stringliteral}{"The time-scale for a running-mean filter applied to the mixed-layer "}//&
865              \textcolor{stringliteral}{"depth used in the MLE restratification parameterization. When "}//&
866              \textcolor{stringliteral}{"the MLD deepens below the current running-mean the running-mean "}//&
867              \textcolor{stringliteral}{"is instantaneously set to the current MLD."}, units=\textcolor{stringliteral}{"s"}, default=0., scale=us%s\_to\_T)
868     \textcolor{keyword}{call }get\_param(param\_file, mdl, \textcolor{stringliteral}{"MLE\_MLD\_DECAY\_TIME2"}, cs%MLE\_MLD\_decay\_time2, &
869              \textcolor{stringliteral}{"The time-scale for a running-mean filter applied to the filtered "}//&
870              \textcolor{stringliteral}{"mixed-layer depth used in a second MLE restratification parameterization. "}//&
871              \textcolor{stringliteral}{"When the MLD deepens below the current running-mean the running-mean "}//&
872              \textcolor{stringliteral}{"is instantaneously set to the current MLD."}, units=\textcolor{stringliteral}{"s"}, default=0., scale=us%s\_to\_T)
873     \textcolor{keywordflow}{if} (.not. cs%MLE\_use\_PBL\_MLD) \textcolor{keywordflow}{then}
874       \textcolor{keyword}{call }get\_param(param\_file, mdl, \textcolor{stringliteral}{"MLE\_DENSITY\_DIFF"}, cs%MLE\_density\_diff, &
875              \textcolor{stringliteral}{"Density difference used to detect the mixed-layer "}//&
876              \textcolor{stringliteral}{"depth used for the mixed-layer eddy parameterization "}//&
877              \textcolor{stringliteral}{"by Fox-Kemper et al. (2010)"}, units=\textcolor{stringliteral}{"kg/m3"}, default=0.03, scale=us%kg\_m3\_to\_R)
878 \textcolor{keywordflow}{    endif}
879     \textcolor{keyword}{call }get\_param(param\_file, mdl, \textcolor{stringliteral}{"MLE\_TAIL\_DH"}, cs%MLE\_tail\_dh, &
880              \textcolor{stringliteral}{"Fraction by which to extend the mixed-layer restratification "}//&
881              \textcolor{stringliteral}{"depth used for a smoother stream function at the base of "}//&
882              \textcolor{stringliteral}{"the mixed-layer."}, units=\textcolor{stringliteral}{"nondim"}, default=0.0)
883     \textcolor{keyword}{call }get\_param(param\_file, mdl, \textcolor{stringliteral}{"MLE\_MLD\_STRETCH"}, cs%MLE\_MLD\_stretch, &
884              \textcolor{stringliteral}{"A scaling coefficient for stretching/shrinking the MLD "}//&
885              \textcolor{stringliteral}{"used in the MLE scheme. This simply multiplies MLD wherever used."},&
886              units=\textcolor{stringliteral}{"nondim"}, default=1.0)
887 \textcolor{keywordflow}{  endif}
888 
889   cs%diag => diag
890 
891   flux\_to\_kg\_per\_s = gv%H\_to\_kg\_m2 * us%L\_to\_m**2 * us%s\_to\_T
892 
893   cs%id\_uhml = register\_diag\_field(\textcolor{stringliteral}{'ocean\_model'}, \textcolor{stringliteral}{'uhml'}, diag%axesCuL, time, &
894       \textcolor{stringliteral}{'Zonal Thickness Flux to Restratify Mixed Layer'}, \textcolor{stringliteral}{'kg s-1'}, &
895       conversion=flux\_to\_kg\_per\_s, y\_cell\_method=\textcolor{stringliteral}{'sum'}, v\_extensive=.true.)
896   cs%id\_vhml = register\_diag\_field(\textcolor{stringliteral}{'ocean\_model'}, \textcolor{stringliteral}{'vhml'}, diag%axesCvL, time, &
897       \textcolor{stringliteral}{'Meridional Thickness Flux to Restratify Mixed Layer'}, \textcolor{stringliteral}{'kg s-1'}, &
898       conversion=flux\_to\_kg\_per\_s, x\_cell\_method=\textcolor{stringliteral}{'sum'}, v\_extensive=.true.)
899   cs%id\_urestrat\_time = register\_diag\_field(\textcolor{stringliteral}{'ocean\_model'}, \textcolor{stringliteral}{'MLu\_restrat\_time'}, diag%axesCu1, time, &
900       \textcolor{stringliteral}{'Mixed Layer Zonal Restratification Timescale'}, \textcolor{stringliteral}{'s'}, conversion=us%T\_to\_s)
901   cs%id\_vrestrat\_time = register\_diag\_field(\textcolor{stringliteral}{'ocean\_model'}, \textcolor{stringliteral}{'MLv\_restrat\_time'}, diag%axesCv1, time, &
902       \textcolor{stringliteral}{'Mixed Layer Meridional Restratification Timescale'}, \textcolor{stringliteral}{'s'}, conversion=us%T\_to\_s)
903   cs%id\_MLD = register\_diag\_field(\textcolor{stringliteral}{'ocean\_model'}, \textcolor{stringliteral}{'MLD\_restrat'}, diag%axesT1, time, &
904       \textcolor{stringliteral}{'Mixed Layer Depth as used in the mixed-layer restratification parameterization'}, \textcolor{stringliteral}{'m'}, &
905       conversion=gv%H\_to\_m)
906   cs%id\_Rml = register\_diag\_field(\textcolor{stringliteral}{'ocean\_model'}, \textcolor{stringliteral}{'ML\_buoy\_restrat'}, diag%axesT1, time, &
907       \textcolor{stringliteral}{'Mixed Layer Buoyancy as used in the mixed-layer restratification parameterization'}, &
908       \textcolor{stringliteral}{'m s2'}, conversion=us%m\_to\_Z*(us%L\_to\_m**2)*(us%s\_to\_T**2))
909   cs%id\_uDml = register\_diag\_field(\textcolor{stringliteral}{'ocean\_model'}, \textcolor{stringliteral}{'udml\_restrat'}, diag%axesCu1, time, &
910       \textcolor{stringliteral}{'Transport stream function amplitude for zonal restratification of mixed layer'}, &
911       \textcolor{stringliteral}{'m3 s-1'}, conversion=gv%H\_to\_m*(us%L\_to\_m**2)*us%s\_to\_T)
912   cs%id\_vDml = register\_diag\_field(\textcolor{stringliteral}{'ocean\_model'}, \textcolor{stringliteral}{'vdml\_restrat'}, diag%axesCv1, time, &
913       \textcolor{stringliteral}{'Transport stream function amplitude for meridional restratification of mixed layer'}, &
914       \textcolor{stringliteral}{'m3 s-1'}, conversion=gv%H\_to\_m*(us%L\_to\_m**2)*us%s\_to\_T)
915   cs%id\_uml = register\_diag\_field(\textcolor{stringliteral}{'ocean\_model'}, \textcolor{stringliteral}{'uml\_restrat'}, diag%axesCu1, time, &
916       \textcolor{stringliteral}{'Surface zonal velocity component of mixed layer restratification'}, &
917       \textcolor{stringliteral}{'m s-1'}, conversion=us%L\_T\_to\_m\_s)
918   cs%id\_vml = register\_diag\_field(\textcolor{stringliteral}{'ocean\_model'}, \textcolor{stringliteral}{'vml\_restrat'}, diag%axesCv1, time, &
919       \textcolor{stringliteral}{'Surface meridional velocity component of mixed layer restratification'}, &
920       \textcolor{stringliteral}{'m s-1'}, conversion=us%L\_T\_to\_m\_s)
921 
922   \textcolor{comment}{! Rescale variables from restart files if the internal dimensional scalings have changed.}
923   \textcolor{keywordflow}{if} (cs%MLE\_MLD\_decay\_time>0. .or. cs%MLE\_MLD\_decay\_time2>0.) \textcolor{keywordflow}{then}
924     \textcolor{keywordflow}{if} (query\_initialized(cs%MLD\_filtered, \textcolor{stringliteral}{"MLD\_MLE\_filtered"}, restart\_cs) .and. &
925         (gv%m\_to\_H\_restart /= 0.0) .and. (gv%m\_to\_H\_restart /= gv%m\_to\_H)) \textcolor{keywordflow}{then}
926       h\_rescale = gv%m\_to\_H / gv%m\_to\_H\_restart
927       \textcolor{keywordflow}{do} j=g%jsc,g%jec ; \textcolor{keywordflow}{do} i=g%isc,g%iec
928         cs%MLD\_filtered(i,j) = h\_rescale * cs%MLD\_filtered(i,j)
929 \textcolor{keywordflow}{      enddo} ;\textcolor{keywordflow}{ enddo}
930 \textcolor{keywordflow}{    endif}
931 \textcolor{keywordflow}{  endif}
932   \textcolor{keywordflow}{if} (cs%MLE\_MLD\_decay\_time2>0.) \textcolor{keywordflow}{then}
933     \textcolor{keywordflow}{if} (query\_initialized(cs%MLD\_filtered\_slow, \textcolor{stringliteral}{"MLD\_MLE\_filtered\_slow"}, restart\_cs) .and. &
934         (gv%m\_to\_H\_restart /= 0.0) .and. (gv%m\_to\_H\_restart /= gv%m\_to\_H)) \textcolor{keywordflow}{then}
935       h\_rescale = gv%m\_to\_H / gv%m\_to\_H\_restart
936       \textcolor{keywordflow}{do} j=g%jsc,g%jec ; \textcolor{keywordflow}{do} i=g%isc,g%iec
937         cs%MLD\_filtered\_slow(i,j) = h\_rescale * cs%MLD\_filtered\_slow(i,j)
938 \textcolor{keywordflow}{      enddo} ;\textcolor{keywordflow}{ enddo}
939 \textcolor{keywordflow}{    endif}
940 \textcolor{keywordflow}{  endif}
941 
942   \textcolor{comment}{! If MLD\_filtered is being used, we need to update halo regions after a restart}
943   \textcolor{keywordflow}{if} (\textcolor{keyword}{associated}(cs%MLD\_filtered)) \textcolor{keyword}{call }pass\_var(cs%MLD\_filtered, g%domain)
944 
\end{DoxyCode}
\mbox{\Hypertarget{namespacemom__mixed__layer__restrat_aea597553dfa98cc7c972784f476ad3fc}\label{namespacemom__mixed__layer__restrat_aea597553dfa98cc7c972784f476ad3fc}} 
\index{mom\+\_\+mixed\+\_\+layer\+\_\+restrat@{mom\+\_\+mixed\+\_\+layer\+\_\+restrat}!mixedlayer\+\_\+restrat\+\_\+register\+\_\+restarts@{mixedlayer\+\_\+restrat\+\_\+register\+\_\+restarts}}
\index{mixedlayer\+\_\+restrat\+\_\+register\+\_\+restarts@{mixedlayer\+\_\+restrat\+\_\+register\+\_\+restarts}!mom\+\_\+mixed\+\_\+layer\+\_\+restrat@{mom\+\_\+mixed\+\_\+layer\+\_\+restrat}}
\subsubsection{\texorpdfstring{mixedlayer\+\_\+restrat\+\_\+register\+\_\+restarts()}{mixedlayer\_restrat\_register\_restarts()}}
{\footnotesize\ttfamily subroutine, public mom\+\_\+mixed\+\_\+layer\+\_\+restrat\+::mixedlayer\+\_\+restrat\+\_\+register\+\_\+restarts (\begin{DoxyParamCaption}\item[{type(hor\+\_\+index\+\_\+type), intent(in)}]{HI,  }\item[{type(param\+\_\+file\+\_\+type), intent(in)}]{param\+\_\+file,  }\item[{type(\mbox{\hyperlink{structmom__mixed__layer__restrat_1_1mixedlayer__restrat__cs}{mixedlayer\+\_\+restrat\+\_\+cs}}), pointer}]{CS,  }\item[{type(mom\+\_\+restart\+\_\+cs), pointer}]{restart\+\_\+\+CS }\end{DoxyParamCaption})}



Allocate and register fields in the mixed layer restratification structure for restarts. 


\begin{DoxyParams}[1]{Parameters}
\mbox{\tt in}  & {\em hi} & Horizontal index structure\\
\hline
\mbox{\tt in}  & {\em param\+\_\+file} & Parameter file to parse\\
\hline
 & {\em cs} & Module control structure\\
\hline
 & {\em restart\+\_\+cs} & A pointer to the restart control structure \\
\hline
\end{DoxyParams}


Definition at line 949 of file M\+O\+M\+\_\+mixed\+\_\+layer\+\_\+restrat.\+F90.


\begin{DoxyCode}
949   \textcolor{comment}{! Arguments}
950   \textcolor{keywordtype}{type}(hor\_index\_type),        \textcolor{keywordtype}{intent(in)}    :: HI\textcolor{comment}{         !< Horizontal index structure}
951   \textcolor{keywordtype}{type}(param\_file\_type),       \textcolor{keywordtype}{intent(in)}    :: param\_file\textcolor{comment}{ !< Parameter file to parse}
952   \textcolor{keywordtype}{type}(mixedlayer\_restrat\_CS), \textcolor{keywordtype}{pointer}       :: CS\textcolor{comment}{         !< Module control structure}
953   \textcolor{keywordtype}{type}(MOM\_restart\_CS),        \textcolor{keywordtype}{pointer}       :: restart\_CS\textcolor{comment}{ !< A pointer to the restart control structure}
954   \textcolor{comment}{! Local variables}
955   \textcolor{keywordtype}{type}(vardesc) :: vd
956   \textcolor{keywordtype}{logical} :: mixedlayer\_restrat\_init
957 
958   \textcolor{comment}{! Check to see if this module will be used}
959   \textcolor{keyword}{call }get\_param(param\_file, mdl, \textcolor{stringliteral}{"MIXEDLAYER\_RESTRAT"}, mixedlayer\_restrat\_init, &
960              default=.false., do\_not\_log=.true.)
961   \textcolor{keywordflow}{if} (.not. mixedlayer\_restrat\_init) \textcolor{keywordflow}{return}
962 
963   \textcolor{comment}{! Allocate the control structure. CS will be later populated by mixedlayer\_restrat\_init()}
964   \textcolor{keywordflow}{if} (\textcolor{keyword}{associated}(cs)) \textcolor{keyword}{call }mom\_error(fatal, &
965        \textcolor{stringliteral}{"mixedlayer\_restrat\_register\_restarts called with an associated control structure."})
966   \textcolor{keyword}{allocate}(cs)
967 
968   \textcolor{keyword}{call }get\_param(param\_file, mdl, \textcolor{stringliteral}{"MLE\_MLD\_DECAY\_TIME"}, cs%MLE\_MLD\_decay\_time, &
969                  default=0., do\_not\_log=.true.)
970   \textcolor{keyword}{call }get\_param(param\_file, mdl, \textcolor{stringliteral}{"MLE\_MLD\_DECAY\_TIME2"}, cs%MLE\_MLD\_decay\_time2, &
971                  default=0., do\_not\_log=.true.)
972   \textcolor{keywordflow}{if} (cs%MLE\_MLD\_decay\_time>0. .or. cs%MLE\_MLD\_decay\_time2>0.) \textcolor{keywordflow}{then}
973     \textcolor{comment}{! CS%MLD\_filtered is used to keep a running mean of the PBL's actively mixed MLD.}
974     \textcolor{keyword}{allocate}(cs%MLD\_filtered(hi%isd:hi%ied,hi%jsd:hi%jed)) ; cs%MLD\_filtered(:,:) = 0.
975     vd = var\_desc(\textcolor{stringliteral}{"MLD\_MLE\_filtered"},\textcolor{stringliteral}{"m"},\textcolor{stringliteral}{"Time-filtered MLD for use in MLE"}, &
976                   hor\_grid=\textcolor{stringliteral}{'h'}, z\_grid=\textcolor{stringliteral}{'1'})
977     \textcolor{keyword}{call }register\_restart\_field(cs%MLD\_filtered, vd, .false., restart\_cs)
978 \textcolor{keywordflow}{  endif}
979   \textcolor{keywordflow}{if} (cs%MLE\_MLD\_decay\_time2>0.) \textcolor{keywordflow}{then}
980     \textcolor{comment}{! CS%MLD\_filtered\_slow is used to keep a running mean of the PBL's seasonal or winter MLD.}
981     \textcolor{keyword}{allocate}(cs%MLD\_filtered\_slow(hi%isd:hi%ied,hi%jsd:hi%jed)) ; cs%MLD\_filtered\_slow(:,:) = 0.
982     vd = var\_desc(\textcolor{stringliteral}{"MLD\_MLE\_filtered\_slow"},\textcolor{stringliteral}{"m"},\textcolor{stringliteral}{"c Slower time-filtered MLD for use in MLE"}, &
983                   hor\_grid=\textcolor{stringliteral}{'h'}, z\_grid=\textcolor{stringliteral}{'1'})
984     \textcolor{keyword}{call }register\_restart\_field(cs%MLD\_filtered\_slow, vd, .false., restart\_cs)
985 \textcolor{keywordflow}{  endif}
986 
\end{DoxyCode}
