\hypertarget{namespacemom__cvmix__kpp}{}\section{mom\+\_\+cvmix\+\_\+kpp Module Reference}
\label{namespacemom__cvmix__kpp}\index{mom\+\_\+cvmix\+\_\+kpp@{mom\+\_\+cvmix\+\_\+kpp}}


\subsection{Detailed Description}
Provides the K-\/\+Profile Parameterization (K\+PP) of Large et al., 1994, via C\+V\+Mix. \subsection*{Data Types}
\begin{DoxyCompactItemize}
\item 
type \hyperlink{structmom__cvmix__kpp_1_1kpp__cs}{kpp\+\_\+cs}
\begin{DoxyCompactList}\small\item\em Control structure for containing K\+PP parameters/data. \end{DoxyCompactList}\end{DoxyCompactItemize}
\subsection*{Functions/\+Subroutines}
\begin{DoxyCompactItemize}
\item 
logical function, public \hyperlink{namespacemom__cvmix__kpp_ada767f6da63b74348a7461eb1d12c5d6}{kpp\+\_\+init} (param\+File, G, GV, US, diag, Time, CS, passive, Waves)
\begin{DoxyCompactList}\small\item\em Initialize the C\+V\+Mix K\+PP module and set up diagnostics Returns True if K\+PP is to be used, False otherwise. \end{DoxyCompactList}\item 
subroutine, public \hyperlink{namespacemom__cvmix__kpp_a94d77471726028da980fd9f998b4173f}{kpp\+\_\+calculate} (CS, G, GV, US, h, u\+Star, buoy\+Flux, Kt, Ks, Kv, non\+Local\+Trans\+Heat, non\+Local\+Trans\+Scalar, waves)
\begin{DoxyCompactList}\small\item\em K\+PP vertical diffusivity/viscosity and non-\/local tracer transport. \end{DoxyCompactList}\item 
subroutine, public \hyperlink{namespacemom__cvmix__kpp_aa91f493f6da97da3536d0f4d47cb442c}{kpp\+\_\+compute\+\_\+bld} (CS, G, GV, US, h, Temp, Salt, u, v, tv, u\+Star, buoy\+Flux, Waves)
\begin{DoxyCompactList}\small\item\em Compute O\+BL depth. \end{DoxyCompactList}\item 
subroutine \hyperlink{namespacemom__cvmix__kpp_a8662fdd6328fdec67691ced27f03e049}{kpp\+\_\+smooth\+\_\+bld} (CS, G, GV, h)
\begin{DoxyCompactList}\small\item\em Apply a 1-\/1-\/4-\/1-\/1 Laplacian filter one time on B\+LD to reduce any horizontal two-\/grid-\/point noise. \end{DoxyCompactList}\item 
subroutine, public \hyperlink{namespacemom__cvmix__kpp_abcb80984f564e5aaf4567aaead111734}{kpp\+\_\+get\+\_\+bld} (CS, B\+LD, G, US, m\+\_\+to\+\_\+\+B\+L\+D\+\_\+units)
\begin{DoxyCompactList}\small\item\em Copies K\+PP surface boundary layer depth into B\+LD, in units of \mbox{[}Z $\sim$$>$ m\mbox{]} unless other units are specified. \end{DoxyCompactList}\item 
subroutine, public \hyperlink{namespacemom__cvmix__kpp_a54093ca1cac897785c965c00efa12fe6}{kpp\+\_\+nonlocaltransport\+\_\+temp} (CS, G, GV, h, non\+Local\+Trans, surf\+Flux, dt, scalar, C\+\_\+p)
\begin{DoxyCompactList}\small\item\em Apply K\+PP non-\/local transport of surface fluxes for temperature. \end{DoxyCompactList}\item 
subroutine, public \hyperlink{namespacemom__cvmix__kpp_abebacc1ae8c13149d816a60ff2e824b6}{kpp\+\_\+nonlocaltransport\+\_\+saln} (CS, G, GV, h, non\+Local\+Trans, surf\+Flux, dt, scalar)
\begin{DoxyCompactList}\small\item\em Apply K\+PP non-\/local transport of surface fluxes for salinity. This routine is a useful prototype for other material tracers. \end{DoxyCompactList}\item 
subroutine, public \hyperlink{namespacemom__cvmix__kpp_ab64722f48cd1d20a4c5bfc74ad602326}{kpp\+\_\+end} (CS)
\begin{DoxyCompactList}\small\item\em Clear pointers, deallocate memory. \end{DoxyCompactList}\end{DoxyCompactItemize}
\subsection*{Variables}
\begin{DoxyCompactItemize}
\item 
\mbox{\Hypertarget{namespacemom__cvmix__kpp_afe095f912beb51eb5710dbd68cc42dab}\label{namespacemom__cvmix__kpp_afe095f912beb51eb5710dbd68cc42dab}} 
integer, parameter, private \hyperlink{namespacemom__cvmix__kpp_afe095f912beb51eb5710dbd68cc42dab}{nlt\+\_\+shape\+\_\+cvmix} = 0
\begin{DoxyCompactList}\small\item\em Use the C\+V\+Mix profile. \end{DoxyCompactList}\item 
\mbox{\Hypertarget{namespacemom__cvmix__kpp_a306be669f441bd2b242e1303f59dfa5e}\label{namespacemom__cvmix__kpp_a306be669f441bd2b242e1303f59dfa5e}} 
integer, parameter, private \hyperlink{namespacemom__cvmix__kpp_a306be669f441bd2b242e1303f59dfa5e}{nlt\+\_\+shape\+\_\+linear} = 1
\begin{DoxyCompactList}\small\item\em Linear, $ G(\sigma) = 1-\sigma $. \end{DoxyCompactList}\item 
\mbox{\Hypertarget{namespacemom__cvmix__kpp_a82f43a1532d552db2ba495d16d3928a0}\label{namespacemom__cvmix__kpp_a82f43a1532d552db2ba495d16d3928a0}} 
integer, parameter, private \hyperlink{namespacemom__cvmix__kpp_a82f43a1532d552db2ba495d16d3928a0}{nlt\+\_\+shape\+\_\+parabolic} = 2
\begin{DoxyCompactList}\small\item\em Parabolic, $ G(\sigma) = (1-\sigma)^2 $. \end{DoxyCompactList}\item 
\mbox{\Hypertarget{namespacemom__cvmix__kpp_a70bd2978b36d6b3aa9aa625c03c03f0a}\label{namespacemom__cvmix__kpp_a70bd2978b36d6b3aa9aa625c03c03f0a}} 
integer, parameter, private \hyperlink{namespacemom__cvmix__kpp_a70bd2978b36d6b3aa9aa625c03c03f0a}{nlt\+\_\+shape\+\_\+cubic} = 3
\begin{DoxyCompactList}\small\item\em Cubic, $ G(\sigma) = 1 + (2\sigma-3) \sigma^2$. \end{DoxyCompactList}\item 
\mbox{\Hypertarget{namespacemom__cvmix__kpp_a9b5190793b228cf859a34c4a173fbe77}\label{namespacemom__cvmix__kpp_a9b5190793b228cf859a34c4a173fbe77}} 
integer, parameter, private \hyperlink{namespacemom__cvmix__kpp_a9b5190793b228cf859a34c4a173fbe77}{nlt\+\_\+shape\+\_\+cubic\+\_\+lmd} = 4
\begin{DoxyCompactList}\small\item\em Original shape, $ G(\sigma) = \frac{27}{4} \sigma (1-\sigma)^2 $. \end{DoxyCompactList}\item 
\mbox{\Hypertarget{namespacemom__cvmix__kpp_a16884cc2e9d4bdb9c5fedc0bc3f23056}\label{namespacemom__cvmix__kpp_a16884cc2e9d4bdb9c5fedc0bc3f23056}} 
integer, parameter, private \hyperlink{namespacemom__cvmix__kpp_a16884cc2e9d4bdb9c5fedc0bc3f23056}{sw\+\_\+method\+\_\+all\+\_\+sw} = 0
\begin{DoxyCompactList}\small\item\em Use all shortwave radiation. \end{DoxyCompactList}\item 
\mbox{\Hypertarget{namespacemom__cvmix__kpp_afbc1dc214273291361c246545118665b}\label{namespacemom__cvmix__kpp_afbc1dc214273291361c246545118665b}} 
integer, parameter, private \hyperlink{namespacemom__cvmix__kpp_afbc1dc214273291361c246545118665b}{sw\+\_\+method\+\_\+mxl\+\_\+sw} = 1
\begin{DoxyCompactList}\small\item\em Use shortwave radiation absorbed in mixing layer. \end{DoxyCompactList}\item 
\mbox{\Hypertarget{namespacemom__cvmix__kpp_a8577785b93b4c59c3d16c920af7a9064}\label{namespacemom__cvmix__kpp_a8577785b93b4c59c3d16c920af7a9064}} 
integer, parameter, private \hyperlink{namespacemom__cvmix__kpp_a8577785b93b4c59c3d16c920af7a9064}{sw\+\_\+method\+\_\+lv1\+\_\+sw} = 2
\begin{DoxyCompactList}\small\item\em Use shortwave radiation absorbed in layer 1. \end{DoxyCompactList}\item 
\mbox{\Hypertarget{namespacemom__cvmix__kpp_a31fec7101872773e8704b39fbab011ed}\label{namespacemom__cvmix__kpp_a31fec7101872773e8704b39fbab011ed}} 
integer, parameter, private \hyperlink{namespacemom__cvmix__kpp_a31fec7101872773e8704b39fbab011ed}{lt\+\_\+k\+\_\+constant} = 1
\begin{DoxyCompactList}\small\item\em Constant enhance K through column. \end{DoxyCompactList}\item 
\mbox{\Hypertarget{namespacemom__cvmix__kpp_aabd55e341dc321fac17b08fdadff4451}\label{namespacemom__cvmix__kpp_aabd55e341dc321fac17b08fdadff4451}} 
integer, parameter, private \hyperlink{namespacemom__cvmix__kpp_aabd55e341dc321fac17b08fdadff4451}{lt\+\_\+k\+\_\+scaled} = 2
\begin{DoxyCompactList}\small\item\em Enhance K scales with G(sigma) \end{DoxyCompactList}\item 
\mbox{\Hypertarget{namespacemom__cvmix__kpp_ac38b6557079872047ac625d722546fee}\label{namespacemom__cvmix__kpp_ac38b6557079872047ac625d722546fee}} 
integer, parameter, private \hyperlink{namespacemom__cvmix__kpp_ac38b6557079872047ac625d722546fee}{lt\+\_\+k\+\_\+mode\+\_\+constant} = 1
\begin{DoxyCompactList}\small\item\em Prescribed enhancement for K. \end{DoxyCompactList}\item 
\mbox{\Hypertarget{namespacemom__cvmix__kpp_a6dbc98c4e4582ea2cc4c3f2253bbd5e7}\label{namespacemom__cvmix__kpp_a6dbc98c4e4582ea2cc4c3f2253bbd5e7}} 
integer, parameter, private \hyperlink{namespacemom__cvmix__kpp_a6dbc98c4e4582ea2cc4c3f2253bbd5e7}{lt\+\_\+k\+\_\+mode\+\_\+vr12} = 2
\begin{DoxyCompactList}\small\item\em Enhancement for K based on. \end{DoxyCompactList}\item 
\mbox{\Hypertarget{namespacemom__cvmix__kpp_ac917e24dabaab72de04483c5b5813741}\label{namespacemom__cvmix__kpp_ac917e24dabaab72de04483c5b5813741}} 
integer, parameter, private \hyperlink{namespacemom__cvmix__kpp_ac917e24dabaab72de04483c5b5813741}{lt\+\_\+k\+\_\+mode\+\_\+rw16} = 3
\begin{DoxyCompactList}\small\item\em Enhancement for K based on. \end{DoxyCompactList}\item 
\mbox{\Hypertarget{namespacemom__cvmix__kpp_ad15c2df92a8faefdf658ed817298b460}\label{namespacemom__cvmix__kpp_ad15c2df92a8faefdf658ed817298b460}} 
integer, parameter, private \hyperlink{namespacemom__cvmix__kpp_ad15c2df92a8faefdf658ed817298b460}{lt\+\_\+vt2\+\_\+mode\+\_\+constant} = 1
\begin{DoxyCompactList}\small\item\em Prescribed enhancement for Vt2. \end{DoxyCompactList}\item 
\mbox{\Hypertarget{namespacemom__cvmix__kpp_a6cb86c81a9d5827900ec5167bb5bac27}\label{namespacemom__cvmix__kpp_a6cb86c81a9d5827900ec5167bb5bac27}} 
integer, parameter, private \hyperlink{namespacemom__cvmix__kpp_a6cb86c81a9d5827900ec5167bb5bac27}{lt\+\_\+vt2\+\_\+mode\+\_\+vr12} = 2
\begin{DoxyCompactList}\small\item\em Enhancement for Vt2 based on. \end{DoxyCompactList}\item 
\mbox{\Hypertarget{namespacemom__cvmix__kpp_a28ed11256ee4b98cb15530e600e558cf}\label{namespacemom__cvmix__kpp_a28ed11256ee4b98cb15530e600e558cf}} 
integer, parameter, private \hyperlink{namespacemom__cvmix__kpp_a28ed11256ee4b98cb15530e600e558cf}{lt\+\_\+vt2\+\_\+mode\+\_\+rw16} = 3
\begin{DoxyCompactList}\small\item\em Enhancement for Vt2 based on. \end{DoxyCompactList}\item 
\mbox{\Hypertarget{namespacemom__cvmix__kpp_acfee181fef7d13f856d2135e52936144}\label{namespacemom__cvmix__kpp_acfee181fef7d13f856d2135e52936144}} 
integer, parameter, private \hyperlink{namespacemom__cvmix__kpp_acfee181fef7d13f856d2135e52936144}{lt\+\_\+vt2\+\_\+mode\+\_\+lf17} = 4
\begin{DoxyCompactList}\small\item\em Enhancement for Vt2 based on. \end{DoxyCompactList}\end{DoxyCompactItemize}
\textbf{ }\par
\begin{DoxyCompactItemize}
\item 
\mbox{\Hypertarget{namespacemom__cvmix__kpp_a4652355fbcaf1eec2461acecacaf0e2a}\label{namespacemom__cvmix__kpp_a4652355fbcaf1eec2461acecacaf0e2a}} 
integer \hyperlink{namespacemom__cvmix__kpp_a4652355fbcaf1eec2461acecacaf0e2a}{id\+\_\+clock\+\_\+kpp\+\_\+calc}
\begin{DoxyCompactList}\small\item\em C\+PU time clocks. \end{DoxyCompactList}\item 
\mbox{\Hypertarget{namespacemom__cvmix__kpp_a67506339c76d74ed0fb283379f67b69e}\label{namespacemom__cvmix__kpp_a67506339c76d74ed0fb283379f67b69e}} 
integer \hyperlink{namespacemom__cvmix__kpp_a67506339c76d74ed0fb283379f67b69e}{id\+\_\+clock\+\_\+kpp\+\_\+compute\+\_\+bld}
\begin{DoxyCompactList}\small\item\em C\+PU time clocks. \end{DoxyCompactList}\item 
\mbox{\Hypertarget{namespacemom__cvmix__kpp_a127c4c8149f7fb5f01f9fa0f95a1a7b5}\label{namespacemom__cvmix__kpp_a127c4c8149f7fb5f01f9fa0f95a1a7b5}} 
integer \hyperlink{namespacemom__cvmix__kpp_a127c4c8149f7fb5f01f9fa0f95a1a7b5}{id\+\_\+clock\+\_\+kpp\+\_\+smoothing}
\begin{DoxyCompactList}\small\item\em C\+PU time clocks. \end{DoxyCompactList}\end{DoxyCompactItemize}



\subsection{Function/\+Subroutine Documentation}
\mbox{\Hypertarget{namespacemom__cvmix__kpp_a94d77471726028da980fd9f998b4173f}\label{namespacemom__cvmix__kpp_a94d77471726028da980fd9f998b4173f}} 
\index{mom\+\_\+cvmix\+\_\+kpp@{mom\+\_\+cvmix\+\_\+kpp}!kpp\+\_\+calculate@{kpp\+\_\+calculate}}
\index{kpp\+\_\+calculate@{kpp\+\_\+calculate}!mom\+\_\+cvmix\+\_\+kpp@{mom\+\_\+cvmix\+\_\+kpp}}
\subsubsection{\texorpdfstring{kpp\+\_\+calculate()}{kpp\_calculate()}}
{\footnotesize\ttfamily subroutine, public mom\+\_\+cvmix\+\_\+kpp\+::kpp\+\_\+calculate (\begin{DoxyParamCaption}\item[{type(\hyperlink{structmom__cvmix__kpp_1_1kpp__cs}{kpp\+\_\+cs}), pointer}]{CS,  }\item[{type(ocean\+\_\+grid\+\_\+type), intent(in)}]{G,  }\item[{type(verticalgrid\+\_\+type), intent(in)}]{GV,  }\item[{type(unit\+\_\+scale\+\_\+type), intent(in)}]{US,  }\item[{real, dimension(szi\+\_\+(g),szj\+\_\+(g),szk\+\_\+(g)), intent(in)}]{h,  }\item[{real, dimension(szi\+\_\+(g),szj\+\_\+(g)), intent(in)}]{u\+Star,  }\item[{real, dimension(szi\+\_\+(g),szj\+\_\+(g),szk\+\_\+(g)+1), intent(in)}]{buoy\+Flux,  }\item[{real, dimension(szi\+\_\+(g),szj\+\_\+(g),szk\+\_\+(g)+1), intent(inout)}]{Kt,  }\item[{real, dimension(szi\+\_\+(g),szj\+\_\+(g),szk\+\_\+(g)+1), intent(inout)}]{Ks,  }\item[{real, dimension(szi\+\_\+(g),szj\+\_\+(g),szk\+\_\+(g)+1), intent(inout)}]{Kv,  }\item[{real, dimension(szi\+\_\+(g),szj\+\_\+(g),szk\+\_\+(g)+1), intent(inout)}]{non\+Local\+Trans\+Heat,  }\item[{real, dimension(szi\+\_\+(g),szj\+\_\+(g),szk\+\_\+(g)+1), intent(inout)}]{non\+Local\+Trans\+Scalar,  }\item[{type(wave\+\_\+parameters\+\_\+cs), optional, pointer}]{waves }\end{DoxyParamCaption})}



K\+PP vertical diffusivity/viscosity and non-\/local tracer transport. 


\begin{DoxyParams}[1]{Parameters}
 & {\em cs} & Control structure\\
\hline
\mbox{\tt in}  & {\em g} & Ocean grid\\
\hline
\mbox{\tt in}  & {\em gv} & Ocean vertical grid\\
\hline
\mbox{\tt in}  & {\em us} & A dimensional unit scaling type\\
\hline
 & {\em waves} & Wave CS\\
\hline
\mbox{\tt in}  & {\em h} & Layer/level thicknesses \mbox{[}H $\sim$$>$ m or kg m-\/2\mbox{]}\\
\hline
\mbox{\tt in}  & {\em ustar} & Surface friction velocity \mbox{[}Z T-\/1 $\sim$$>$ m s-\/1\mbox{]}\\
\hline
\mbox{\tt in}  & {\em buoyflux} & Surface buoyancy flux \mbox{[}L2 T-\/3 $\sim$$>$ m2 s-\/3\mbox{]}\\
\hline
\mbox{\tt in,out}  & {\em kt} & (in) Vertical diffusivity of heat w/o K\+PP (out) Vertical diffusivity including K\+PP \mbox{[}Z2 T-\/1 $\sim$$>$ m2 s-\/1\mbox{]}\\
\hline
\mbox{\tt in,out}  & {\em ks} & (in) Vertical diffusivity of salt w/o K\+PP (out) Vertical diffusivity including K\+PP \mbox{[}Z2 T-\/1 $\sim$$>$ m2 s-\/1\mbox{]}\\
\hline
\mbox{\tt in,out}  & {\em kv} & (in) Vertical viscosity w/o K\+PP (out) Vertical viscosity including K\+PP \mbox{[}Z2 T-\/1 $\sim$$>$ m2 s-\/1\mbox{]}\\
\hline
\mbox{\tt in,out}  & {\em nonlocaltransheat} & Temp non-\/local transport \mbox{[}m s-\/1\mbox{]}\\
\hline
\mbox{\tt in,out}  & {\em nonlocaltransscalar} & scalar non-\/local transport \mbox{[}m s-\/1\mbox{]} \\
\hline
\end{DoxyParams}


Definition at line 604 of file M\+O\+M\+\_\+\+C\+V\+Mix\+\_\+\+K\+P\+P.\+F90.


\begin{DoxyCode}
604 
605   \textcolor{comment}{! Arguments}
606   \textcolor{keywordtype}{type}(kpp\_cs),                               \textcolor{keywordtype}{pointer}       :: cs\textcolor{comment}{    !< Control structure}
607   \textcolor{keywordtype}{type}(ocean\_grid\_type),                      \textcolor{keywordtype}{intent(in)}    :: g\textcolor{comment}{     !< Ocean grid}
608   \textcolor{keywordtype}{type}(verticalgrid\_type),                    \textcolor{keywordtype}{intent(in)}    :: gv\textcolor{comment}{    !< Ocean vertical grid}
609   \textcolor{keywordtype}{type}(unit\_scale\_type),                      \textcolor{keywordtype}{intent(in)}    :: us\textcolor{comment}{    !< A dimensional unit scaling type}
610   \textcolor{keywordtype}{type}(wave\_parameters\_cs),         \textcolor{keywordtype}{optional}, \textcolor{keywordtype}{pointer}       :: waves\textcolor{comment}{ !< Wave CS}
611   \textcolor{keywordtype}{real}, \textcolor{keywordtype}{dimension(SZI\_(G),SZJ\_(G),SZK\_(G))},   \textcolor{keywordtype}{intent(in)}    :: h\textcolor{comment}{     !< Layer/level thicknesses [H ~> m or
       kg m-2]}
612   \textcolor{keywordtype}{real}, \textcolor{keywordtype}{dimension(SZI\_(G),SZJ\_(G))},           \textcolor{keywordtype}{intent(in)}    :: ustar\textcolor{comment}{ !< Surface friction velocity [Z T-1 ~>
       m s-1]}
613   \textcolor{keywordtype}{real}, \textcolor{keywordtype}{dimension(SZI\_(G),SZJ\_(G),SZK\_(G)+1)}, \textcolor{keywordtype}{intent(in)}    :: buoyflux\textcolor{comment}{ !< Surface buoyancy flux [L2 T-3 ~>
       m2 s-3]}
614   \textcolor{keywordtype}{real}, \textcolor{keywordtype}{dimension(SZI\_(G),SZJ\_(G),SZK\_(G)+1)}, \textcolor{keywordtype}{intent(inout)} :: kt\textcolor{comment}{   !< (in)  Vertical diffusivity of heat
       w/o KPP}
615 \textcolor{comment}{                                                                    !! (out) Vertical diffusivity including
       KPP}
616 \textcolor{comment}{                                                                    !!       [Z2 T-1 ~> m2 s-1]}
617   \textcolor{keywordtype}{real}, \textcolor{keywordtype}{dimension(SZI\_(G),SZJ\_(G),SZK\_(G)+1)}, \textcolor{keywordtype}{intent(inout)} :: ks\textcolor{comment}{   !< (in)  Vertical diffusivity of salt
       w/o KPP}
618 \textcolor{comment}{                                                                    !! (out) Vertical diffusivity including
       KPP}
619 \textcolor{comment}{                                                                    !!       [Z2 T-1 ~> m2 s-1]}
620   \textcolor{keywordtype}{real}, \textcolor{keywordtype}{dimension(SZI\_(G),SZJ\_(G),SZK\_(G)+1)}, \textcolor{keywordtype}{intent(inout)} :: kv\textcolor{comment}{   !< (in)  Vertical viscosity w/o KPP}
621 \textcolor{comment}{                                                                    !! (out) Vertical viscosity including
       KPP}
622 \textcolor{comment}{                                                                    !!       [Z2 T-1 ~> m2 s-1]}
623   \textcolor{keywordtype}{real}, \textcolor{keywordtype}{dimension(SZI\_(G),SZJ\_(G),SZK\_(G)+1)}, \textcolor{keywordtype}{intent(inout)} :: nonlocaltransheat\textcolor{comment}{   !< Temp non-local
       transport [m s-1]}
624   \textcolor{keywordtype}{real}, \textcolor{keywordtype}{dimension(SZI\_(G),SZJ\_(G),SZK\_(G)+1)}, \textcolor{keywordtype}{intent(inout)} :: nonlocaltransscalar\textcolor{comment}{ !< scalar non-local
       transport [m s-1]}
625 
626 \textcolor{comment}{! Local variables}
627   \textcolor{keywordtype}{integer} :: i, j, k                             \textcolor{comment}{! Loop indices}
628   \textcolor{keywordtype}{real}, \textcolor{keywordtype}{dimension( G%ke )}     :: cellheight      \textcolor{comment}{! Cell center heights referenced to surface [m] (negative
       in ocean)}
629   \textcolor{keywordtype}{real}, \textcolor{keywordtype}{dimension( G%ke+1 )}   :: ifaceheight     \textcolor{comment}{! Interface heights referenced to surface [m] (negative in
       ocean)}
630   \textcolor{keywordtype}{real}, \textcolor{keywordtype}{dimension( G%ke+1, 2)} :: kdiffusivity    \textcolor{comment}{! Vertical diffusivity at interfaces [m2 s-1]}
631   \textcolor{keywordtype}{real}, \textcolor{keywordtype}{dimension( G%ke+1 )}   :: kviscosity      \textcolor{comment}{! Vertical viscosity at interfaces [m2 s-1]}
632   \textcolor{keywordtype}{real}, \textcolor{keywordtype}{dimension( G%ke+1, 2)} :: nonlocaltrans   \textcolor{comment}{! Non-local transport for heat/salt at interfaces [nondim]}
633 
634   \textcolor{keywordtype}{real} :: surffricvel, surfbuoyflux
635   \textcolor{keywordtype}{real} :: sigma, sigmaratio
636   \textcolor{keywordtype}{real} :: buoy\_scale \textcolor{comment}{! A unit conversion factor for buoyancy fluxes [m2 T3 L-2 s-3 ~> nondim]}
637   \textcolor{keywordtype}{real} :: dh    \textcolor{comment}{! The local thickness used for calculating interface positions [m]}
638   \textcolor{keywordtype}{real} :: hcorr \textcolor{comment}{! A cumulative correction arising from inflation of vanished layers [m]}
639 
640   \textcolor{comment}{! For Langmuir Calculations}
641   \textcolor{keywordtype}{real} :: langenhk     \textcolor{comment}{! Langmuir enhancement for mixing coefficient}
642 
643 
644   \textcolor{keywordflow}{if} (cs%debug) \textcolor{keywordflow}{then}
645     \textcolor{keyword}{call }hchksum(h, \textcolor{stringliteral}{"KPP in: h"},g%HI,haloshift=0, scale=gv%H\_to\_m)
646     \textcolor{keyword}{call }hchksum(ustar, \textcolor{stringliteral}{"KPP in: uStar"},g%HI,haloshift=0, scale=us%Z\_to\_m*us%s\_to\_T)
647     \textcolor{keyword}{call }hchksum(buoyflux, \textcolor{stringliteral}{"KPP in: buoyFlux"},g%HI,haloshift=0)
648     \textcolor{keyword}{call }hchksum(kt, \textcolor{stringliteral}{"KPP in: Kt"},g%HI,haloshift=0, scale=us%Z2\_T\_to\_m2\_s)
649     \textcolor{keyword}{call }hchksum(ks, \textcolor{stringliteral}{"KPP in: Ks"},g%HI,haloshift=0, scale=us%Z2\_T\_to\_m2\_s)
650 \textcolor{keywordflow}{  endif}
651 
652   nonlocaltrans(:,:) = 0.0
653 
654   \textcolor{keywordflow}{if} (cs%id\_Kd\_in > 0) \textcolor{keyword}{call }post\_data(cs%id\_Kd\_in, kt, cs%diag)
655 
656   \textcolor{keyword}{call }cpu\_clock\_begin(id\_clock\_kpp\_calc)
657   buoy\_scale = us%L\_to\_m**2*us%s\_to\_T**3
658 
659   \textcolor{comment}{!$OMP parallel do default(none) firstprivate(nonLocalTrans)                               &}
660   \textcolor{comment}{!$OMP                           private(surfFricVel, iFaceHeight, hcorr, dh, cellHeight,  &}
661   \textcolor{comment}{!$OMP                           surfBuoyFlux, Kdiffusivity, Kviscosity, LangEnhK, sigma,  &}
662   \textcolor{comment}{!$OMP                           sigmaRatio)                                               &}
663   \textcolor{comment}{!$OMP                           shared(G, GV, CS, US, uStar, h, buoy\_scale, buoyFlux, Kt, &}
664   \textcolor{comment}{!$OMP                           Ks, Kv, nonLocalTransHeat, nonLocalTransScalar, waves)}
665   \textcolor{comment}{! loop over horizontal points on processor}
666   \textcolor{keywordflow}{do} j = g%jsc, g%jec
667     \textcolor{keywordflow}{do} i = g%isc, g%iec
668 
669       \textcolor{comment}{! skip calling KPP for land points}
670       \textcolor{keywordflow}{if} (g%mask2dT(i,j)==0.) cycle
671 
672       \textcolor{comment}{! things independent of position within the column}
673       surffricvel = us%Z\_to\_m*us%s\_to\_T * ustar(i,j)
674 
675       ifaceheight(1) = 0.0 \textcolor{comment}{! BBL is all relative to the surface}
676       hcorr = 0.
677       \textcolor{keywordflow}{do} k=1,g%ke
678 
679         \textcolor{comment}{! cell center and cell bottom in meters (negative values in the ocean)}
680         dh = h(i,j,k) * gv%H\_to\_m \textcolor{comment}{! Nominal thickness to use for increment}
681         dh = dh + hcorr \textcolor{comment}{! Take away the accumulated error (could temporarily make dh<0)}
682         hcorr = min( dh - cs%min\_thickness, 0. ) \textcolor{comment}{! If inflating then hcorr<0}
683         dh = max( dh, cs%min\_thickness ) \textcolor{comment}{! Limit increment dh>=min\_thickness}
684         cellheight(k)    = ifaceheight(k) - 0.5 * dh
685         ifaceheight(k+1) = ifaceheight(k) - dh
686 
687 \textcolor{keywordflow}{      enddo} \textcolor{comment}{! k-loop finishes}
688 
689       surfbuoyflux = buoy\_scale*buoyflux(i,j,1) \textcolor{comment}{! This is only used in kpp\_compute\_OBL\_depth to limit}
690                                      \textcolor{comment}{! h to Monin-Obukov (default is false, ie. not used)}
691 
692       \textcolor{comment}{! Call CVMix/KPP to obtain OBL diffusivities, viscosities and non-local transports}
693 
694       \textcolor{comment}{! Unlike LMD94, we do not match to interior diffusivities. If using the original}
695       \textcolor{comment}{! LMD94 shape function, not matching is equivalent to matching to a zero diffusivity.}
696 
697       \textcolor{comment}{!BGR/ Add option for use of surface buoyancy flux with total sw flux.}
698       \textcolor{keywordflow}{if} (cs%SW\_METHOD == sw\_method\_all\_sw) \textcolor{keywordflow}{then}
699          surfbuoyflux = buoy\_scale * buoyflux(i,j,1)
700       \textcolor{keywordflow}{elseif} (cs%SW\_METHOD == sw\_method\_mxl\_sw) \textcolor{keywordflow}{then}
701          \textcolor{comment}{! We know the actual buoyancy flux into the OBL}
702          surfbuoyflux  = buoy\_scale * (buoyflux(i,j,1) - buoyflux(i,j,int(cs%kOBL(i,j))+1))
703       \textcolor{keywordflow}{elseif} (cs%SW\_METHOD == sw\_method\_lv1\_sw) \textcolor{keywordflow}{then}
704          surfbuoyflux  = buoy\_scale * (buoyflux(i,j,1) - buoyflux(i,j,2))
705 \textcolor{keywordflow}{      endif}
706 
707       \textcolor{comment}{! If option "MatchBoth" is selected in CVMix, MOM should be capable of matching.}
708       \textcolor{keywordflow}{if} (.not. (cs%MatchTechnique == \textcolor{stringliteral}{'MatchBoth'})) \textcolor{keywordflow}{then}
709          kdiffusivity(:,:) = 0. \textcolor{comment}{! Diffusivities for heat and salt [m2 s-1]}
710          kviscosity(:)     = 0. \textcolor{comment}{! Viscosity [m2 s-1]}
711       \textcolor{keywordflow}{else}
712          kdiffusivity(:,1) = us%Z2\_T\_to\_m2\_s * kt(i,j,:)
713          kdiffusivity(:,2) = us%Z2\_T\_to\_m2\_s * ks(i,j,:)
714          kviscosity(:) = us%Z2\_T\_to\_m2\_s * kv(i,j,:)
715 \textcolor{keywordflow}{      endif}
716 
717       \textcolor{keyword}{call }cvmix\_coeffs\_kpp(kviscosity(:),        & \textcolor{comment}{! (inout) Total viscosity [m2 s-1]}
718                             kdiffusivity(:,1), & \textcolor{comment}{! (inout) Total heat diffusivity [m2 s-1]}
719                             kdiffusivity(:,2), & \textcolor{comment}{! (inout) Total salt diffusivity [m2 s-1]}
720                             ifaceheight,       & \textcolor{comment}{! (in) Height of interfaces [m]}
721                             cellheight,        & \textcolor{comment}{! (in) Height of level centers [m]}
722                             kviscosity(:),        & \textcolor{comment}{! (in) Original viscosity [m2 s-1]}
723                             kdiffusivity(:,1), & \textcolor{comment}{! (in) Original heat diffusivity [m2 s-1]}
724                             kdiffusivity(:,2), & \textcolor{comment}{! (in) Original salt diffusivity [m2 s-1]}
725                             cs%OBLdepth(i,j),  & \textcolor{comment}{! (in) OBL depth [m]}
726                             cs%kOBL(i,j),      & \textcolor{comment}{! (in) level (+fraction) of OBL extent}
727                             nonlocaltrans(:,1),& \textcolor{comment}{! (out) Non-local heat transport [nondim]}
728                             nonlocaltrans(:,2),& \textcolor{comment}{! (out) Non-local salt transport [nondim]}
729                             surffricvel,       & \textcolor{comment}{! (in) Turbulent friction velocity at surface [m s-1]}
730                             surfbuoyflux,      & \textcolor{comment}{! (in) Buoyancy flux at surface [m2 s-3]}
731                             g%ke,              & \textcolor{comment}{! (in) Number of levels to compute coeffs for}
732                             g%ke,              & \textcolor{comment}{! (in) Number of levels in array shape}
733                             cvmix\_kpp\_params\_user=cs%KPP\_params )
734 
735       \textcolor{comment}{! safety check, Kviscosity and Kdiffusivity must be >= 0}
736       \textcolor{keywordflow}{do} k=1, g%ke+1
737         \textcolor{keywordflow}{if} (kviscosity(k) < 0. .or. kdiffusivity(k,1) < 0.) \textcolor{keywordflow}{then}
738           \textcolor{keyword}{call }mom\_error(fatal,\textcolor{stringliteral}{"KPP\_calculate, after CVMix\_coeffs\_kpp: "}// &
739                    \textcolor{stringliteral}{"Negative vertical viscosity or diffusivity has been detected. "} // &
740                    \textcolor{stringliteral}{"This is likely related to the choice of MATCH\_TECHNIQUE and INTERP\_TYPE2."} //&
741                    \textcolor{stringliteral}{"You might consider using the default options for these parameters."} )
742 \textcolor{keywordflow}{        endif}
743 \textcolor{keywordflow}{      enddo}
744 
745       \textcolor{keywordflow}{IF} (cs%LT\_K\_ENHANCEMENT) \textcolor{keywordflow}{then}
746         \textcolor{keywordflow}{if} (cs%LT\_K\_METHOD==lt\_k\_mode\_constant) \textcolor{keywordflow}{then}
747            langenhk = cs%KPP\_K\_ENH\_FAC
748         \textcolor{keywordflow}{elseif} (cs%LT\_K\_METHOD==lt\_k\_mode\_vr12) \textcolor{keywordflow}{then}
749            \textcolor{comment}{! Added minimum value for La\_SL, so removed maximum value for LangEnhK.}
750            langenhk = sqrt(1.+(1.5*cs%La\_SL(i,j))**(-2) + &
751                 (5.4*cs%La\_SL(i,j))**(-4))
752         \textcolor{keywordflow}{elseif} (cs%LT\_K\_METHOD==lt\_k\_mode\_rw16) \textcolor{keywordflow}{then}
753           \textcolor{comment}{!This maximum value is proposed in Reichl et al., 2016 JPO formula}
754           langenhk = min(2.25, 1. + 1./cs%La\_SL(i,j))
755         \textcolor{keywordflow}{else}
756            \textcolor{comment}{!This shouldn't be reached.}
757            \textcolor{comment}{!call MOM\_error(WARNING,"Unexpected behavior in MOM\_CVMix\_KPP, see error in LT\_K\_ENHANCEMENT")}
758            langenhk = 1.0
759 \textcolor{keywordflow}{        endif}
760         \textcolor{keywordflow}{do} k=1,g%ke
761           \textcolor{keywordflow}{if} (cs%LT\_K\_SHAPE== lt\_k\_constant) \textcolor{keywordflow}{then}
762             \textcolor{keywordflow}{if} (cs%id\_EnhK > 0) cs%EnhK(i,j,:) = langenhk
763             kdiffusivity(k,1) = kdiffusivity(k,1) * langenhk
764             kdiffusivity(k,2) = kdiffusivity(k,2) * langenhk
765             kviscosity(k)     = kviscosity(k)   * langenhk
766           \textcolor{keywordflow}{elseif} (cs%LT\_K\_SHAPE == lt\_k\_scaled) \textcolor{keywordflow}{then}
767             sigma = min(1.0,-ifaceheight(k)/cs%OBLdepth(i,j))
768             sigmaratio = sigma * (1. - sigma)**2 / 0.148148037
769             \textcolor{keywordflow}{if} (cs%id\_EnhK > 0) cs%EnhK(i,j,k) = (1.0 + (langenhk - 1.)*sigmaratio)
770             kdiffusivity(k,1) = kdiffusivity(k,1) * ( 1. + &
771                                 ( langenhk - 1.)*sigmaratio)
772             kdiffusivity(k,2) = kdiffusivity(k,2) * ( 1. + &
773                                 ( langenhk - 1.)*sigmaratio)
774             kviscosity(k) = kviscosity(k) * ( 1. + &
775                                 ( langenhk - 1.)*sigmaratio)
776 \textcolor{keywordflow}{          endif}
777 \textcolor{keywordflow}{        enddo}
778 \textcolor{keywordflow}{      endif}
779 
780       \textcolor{comment}{! Over-write CVMix NLT shape function with one of the following choices.}
781       \textcolor{comment}{! The CVMix code has yet to update for thse options, so we compute in MOM6.}
782       \textcolor{comment}{! Note that nonLocalTrans = Cs * G(sigma) (LMD94 notation), with}
783       \textcolor{comment}{! Cs = 6.32739901508.}
784       \textcolor{comment}{! Start do-loop at k=2, since k=1 is ocean surface (sigma=0)}
785       \textcolor{comment}{! and we do not wish to double-count the surface forcing.}
786       \textcolor{comment}{! Only compute nonlocal transport for 0 <= sigma <= 1.}
787       \textcolor{comment}{! MOM6 recommended shape is the parabolic; it gives deeper boundary layer}
788       \textcolor{comment}{! and no spurious extrema.}
789       \textcolor{keywordflow}{if} (surfbuoyflux < 0.0) \textcolor{keywordflow}{then}
790         \textcolor{keywordflow}{if} (cs%NLT\_shape == nlt\_shape\_cubic) \textcolor{keywordflow}{then}
791           \textcolor{keywordflow}{do} k = 2, g%ke
792             sigma = min(1.0,-ifaceheight(k)/cs%OBLdepth(i,j))
793             nonlocaltrans(k,1) = (1.0 - sigma)**2 * (1.0 + 2.0*sigma) \textcolor{comment}{!*}
794             nonlocaltrans(k,2) = nonlocaltrans(k,1)
795 \textcolor{keywordflow}{          enddo}
796         \textcolor{keywordflow}{elseif} (cs%NLT\_shape == nlt\_shape\_parabolic) \textcolor{keywordflow}{then}
797           \textcolor{keywordflow}{do} k = 2, g%ke
798             sigma = min(1.0,-ifaceheight(k)/cs%OBLdepth(i,j))
799             nonlocaltrans(k,1) = (1.0 - sigma)**2 \textcolor{comment}{!*CS%CS2}
800             nonlocaltrans(k,2) = nonlocaltrans(k,1)
801 \textcolor{keywordflow}{          enddo}
802         \textcolor{keywordflow}{elseif} (cs%NLT\_shape == nlt\_shape\_linear) \textcolor{keywordflow}{then}
803           \textcolor{keywordflow}{do} k = 2, g%ke
804             sigma = min(1.0,-ifaceheight(k)/cs%OBLdepth(i,j))
805             nonlocaltrans(k,1) = (1.0 - sigma)\textcolor{comment}{!*CS%CS2}
806             nonlocaltrans(k,2) = nonlocaltrans(k,1)
807 \textcolor{keywordflow}{          enddo}
808         \textcolor{keywordflow}{elseif} (cs%NLT\_shape == nlt\_shape\_cubic\_lmd) \textcolor{keywordflow}{then}
809           \textcolor{comment}{! Sanity check (should agree with CVMix result using simple matching)}
810           \textcolor{keywordflow}{do} k = 2, g%ke
811             sigma = min(1.0,-ifaceheight(k)/cs%OBLdepth(i,j))
812             nonlocaltrans(k,1) = cs%CS2 * sigma*(1.0 -sigma)**2
813             nonlocaltrans(k,2) = nonlocaltrans(k,1)
814 \textcolor{keywordflow}{          enddo}
815 \textcolor{keywordflow}{        endif}
816 \textcolor{keywordflow}{      endif}
817 
818       \textcolor{comment}{! we apply nonLocalTrans in subroutines}
819       \textcolor{comment}{! KPP\_NonLocalTransport\_temp and KPP\_NonLocalTransport\_saln}
820       nonlocaltransheat(i,j,:)   = nonlocaltrans(:,1) \textcolor{comment}{! temp}
821       nonlocaltransscalar(i,j,:) = nonlocaltrans(:,2) \textcolor{comment}{! saln}
822 
823       \textcolor{comment}{! set the KPP diffusivity and viscosity to zero for testing purposes}
824       \textcolor{keywordflow}{if} (cs%KPPzeroDiffusivity) \textcolor{keywordflow}{then}
825          kdiffusivity(:,1) = 0.0
826          kdiffusivity(:,2) = 0.0
827          kviscosity(:)     = 0.0
828 \textcolor{keywordflow}{      endif}
829 
830 
831       \textcolor{comment}{! compute unresolved squared velocity for diagnostics}
832       \textcolor{keywordflow}{if} (cs%id\_Vt2 > 0) \textcolor{keywordflow}{then}
833 \textcolor{comment}{!BGR Now computing VT2 above so can modify for LT}
834 \textcolor{comment}{!    therefore, don't repeat this operation here}
835 \textcolor{comment}{!        CS%Vt2(i,j,:) = CVmix\_kpp\_compute\_unresolved\_shear( &}
836 \textcolor{comment}{!                    cellHeight(1:G%ke),                 & ! Depth of cell center [m]}
837 \textcolor{comment}{!                    ws\_cntr=Ws\_1d,                      & ! Turbulent velocity scale profile, at centers
       [m s-1]}
838 \textcolor{comment}{!                    N\_iface=CS%N(i,j,:),                & ! Buoyancy frequency at interface [s-1]}
839 \textcolor{comment}{!                    CVmix\_kpp\_params\_user=CS%KPP\_params ) ! KPP parameters}
840 \textcolor{keywordflow}{      endif}
841 
842       \textcolor{comment}{! Copy 1d data into 3d diagnostic arrays}
843       \textcolor{comment}{!/ grabbing obldepth\_0d for next time step.}
844       cs%OBLdepthprev(i,j)=cs%OBLdepth(i,j)
845       \textcolor{keywordflow}{if} (cs%id\_sigma > 0) \textcolor{keywordflow}{then}
846         cs%sigma(i,j,:)  = 0.
847         \textcolor{keywordflow}{if} (cs%OBLdepth(i,j)>0.)   cs%sigma(i,j,:)  = -ifaceheight/cs%OBLdepth(i,j)
848 \textcolor{keywordflow}{      endif}
849       \textcolor{keywordflow}{if} (cs%id\_Kt\_KPP > 0)   cs%Kt\_KPP(i,j,:) = kdiffusivity(:,1)
850       \textcolor{keywordflow}{if} (cs%id\_Ks\_KPP > 0)   cs%Ks\_KPP(i,j,:) = kdiffusivity(:,2)
851       \textcolor{keywordflow}{if} (cs%id\_Kv\_KPP > 0)   cs%Kv\_KPP(i,j,:) = kviscosity(:)
852 
853       \textcolor{comment}{! Update output of routine}
854       \textcolor{keywordflow}{if} (.not. cs%passiveMode) \textcolor{keywordflow}{then}
855         \textcolor{keywordflow}{if} (cs%KPPisAdditive) \textcolor{keywordflow}{then}
856           \textcolor{keywordflow}{do} k=1, g%ke+1
857             kt(i,j,k) = kt(i,j,k) + us%m2\_s\_to\_Z2\_T * kdiffusivity(k,1)
858             ks(i,j,k) = ks(i,j,k) + us%m2\_s\_to\_Z2\_T * kdiffusivity(k,2)
859             kv(i,j,k) = kv(i,j,k) + us%m2\_s\_to\_Z2\_T * kviscosity(k)
860             \textcolor{keywordflow}{if} (cs%Stokes\_Mixing) waves%KvS(i,j,k) = kv(i,j,k)
861 \textcolor{keywordflow}{          enddo}
862         \textcolor{keywordflow}{else} \textcolor{comment}{! KPP replaces prior diffusivity when former is non-zero}
863           \textcolor{keywordflow}{do} k=1, g%ke+1
864             \textcolor{keywordflow}{if} (kdiffusivity(k,1) /= 0.) kt(i,j,k) = us%m2\_s\_to\_Z2\_T * kdiffusivity(k,1)
865             \textcolor{keywordflow}{if} (kdiffusivity(k,2) /= 0.) ks(i,j,k) = us%m2\_s\_to\_Z2\_T * kdiffusivity(k,2)
866             \textcolor{keywordflow}{if} (kviscosity(k) /= 0.) kv(i,j,k) = us%m2\_s\_to\_Z2\_T * kviscosity(k)
867             \textcolor{keywordflow}{if} (cs%Stokes\_Mixing) waves%KvS(i,j,k) = kv(i,j,k)
868 \textcolor{keywordflow}{          enddo}
869 \textcolor{keywordflow}{        endif}
870 \textcolor{keywordflow}{      endif}
871 
872 
873     \textcolor{comment}{! end of the horizontal do-loops over the vertical columns}
874 \textcolor{keywordflow}{    enddo} \textcolor{comment}{! i}
875 \textcolor{keywordflow}{  enddo} \textcolor{comment}{! j}
876 
877   \textcolor{keyword}{call }cpu\_clock\_end(id\_clock\_kpp\_calc)
878 
879   \textcolor{keywordflow}{if} (cs%debug) \textcolor{keywordflow}{then}
880     \textcolor{keyword}{call }hchksum(kt, \textcolor{stringliteral}{"KPP out: Kt"}, g%HI, haloshift=0, scale=us%Z2\_T\_to\_m2\_s)
881     \textcolor{keyword}{call }hchksum(ks, \textcolor{stringliteral}{"KPP out: Ks"}, g%HI, haloshift=0, scale=us%Z2\_T\_to\_m2\_s)
882 \textcolor{keywordflow}{  endif}
883 
884   \textcolor{comment}{! send diagnostics to post\_data}
885   \textcolor{keywordflow}{if} (cs%id\_OBLdepth > 0) \textcolor{keyword}{call }post\_data(cs%id\_OBLdepth, cs%OBLdepth,        cs%diag)
886   \textcolor{keywordflow}{if} (cs%id\_OBLdepth\_original > 0) \textcolor{keyword}{call }post\_data(cs%id\_OBLdepth\_original,cs%OBLdepth\_original,cs%diag)
887   \textcolor{keywordflow}{if} (cs%id\_sigma    > 0) \textcolor{keyword}{call }post\_data(cs%id\_sigma,    cs%sigma,           cs%diag)
888   \textcolor{keywordflow}{if} (cs%id\_Ws       > 0) \textcolor{keyword}{call }post\_data(cs%id\_Ws,       cs%Ws,              cs%diag)
889   \textcolor{keywordflow}{if} (cs%id\_Vt2      > 0) \textcolor{keyword}{call }post\_data(cs%id\_Vt2,      cs%Vt2,             cs%diag)
890   \textcolor{keywordflow}{if} (cs%id\_uStar    > 0) \textcolor{keyword}{call }post\_data(cs%id\_uStar,    ustar,              cs%diag)
891   \textcolor{keywordflow}{if} (cs%id\_buoyFlux > 0) \textcolor{keyword}{call }post\_data(cs%id\_buoyFlux, buoyflux,           cs%diag)
892   \textcolor{keywordflow}{if} (cs%id\_Kt\_KPP   > 0) \textcolor{keyword}{call }post\_data(cs%id\_Kt\_KPP,   cs%Kt\_KPP,          cs%diag)
893   \textcolor{keywordflow}{if} (cs%id\_Ks\_KPP   > 0) \textcolor{keyword}{call }post\_data(cs%id\_Ks\_KPP,   cs%Ks\_KPP,          cs%diag)
894   \textcolor{keywordflow}{if} (cs%id\_Kv\_KPP   > 0) \textcolor{keyword}{call }post\_data(cs%id\_Kv\_KPP,   cs%Kv\_KPP,          cs%diag)
895   \textcolor{keywordflow}{if} (cs%id\_NLTt     > 0) \textcolor{keyword}{call }post\_data(cs%id\_NLTt,     nonlocaltransheat,  cs%diag)
896   \textcolor{keywordflow}{if} (cs%id\_NLTs     > 0) \textcolor{keyword}{call }post\_data(cs%id\_NLTs,     nonlocaltransscalar,cs%diag)
897 
898 
\end{DoxyCode}
\mbox{\Hypertarget{namespacemom__cvmix__kpp_aa91f493f6da97da3536d0f4d47cb442c}\label{namespacemom__cvmix__kpp_aa91f493f6da97da3536d0f4d47cb442c}} 
\index{mom\+\_\+cvmix\+\_\+kpp@{mom\+\_\+cvmix\+\_\+kpp}!kpp\+\_\+compute\+\_\+bld@{kpp\+\_\+compute\+\_\+bld}}
\index{kpp\+\_\+compute\+\_\+bld@{kpp\+\_\+compute\+\_\+bld}!mom\+\_\+cvmix\+\_\+kpp@{mom\+\_\+cvmix\+\_\+kpp}}
\subsubsection{\texorpdfstring{kpp\+\_\+compute\+\_\+bld()}{kpp\_compute\_bld()}}
{\footnotesize\ttfamily subroutine, public mom\+\_\+cvmix\+\_\+kpp\+::kpp\+\_\+compute\+\_\+bld (\begin{DoxyParamCaption}\item[{type(\hyperlink{structmom__cvmix__kpp_1_1kpp__cs}{kpp\+\_\+cs}), pointer}]{CS,  }\item[{type(ocean\+\_\+grid\+\_\+type), intent(inout)}]{G,  }\item[{type(verticalgrid\+\_\+type), intent(in)}]{GV,  }\item[{type(unit\+\_\+scale\+\_\+type), intent(in)}]{US,  }\item[{real, dimension(szi\+\_\+(g),szj\+\_\+(g),szk\+\_\+(g)), intent(in)}]{h,  }\item[{real, dimension(szi\+\_\+(g),szj\+\_\+(g),szk\+\_\+(g)), intent(in)}]{Temp,  }\item[{real, dimension(szi\+\_\+(g),szj\+\_\+(g),szk\+\_\+(g)), intent(in)}]{Salt,  }\item[{real, dimension(szib\+\_\+(g),szj\+\_\+(g),szk\+\_\+(g)), intent(in)}]{u,  }\item[{real, dimension(szi\+\_\+(g),szjb\+\_\+(g),szk\+\_\+(g)), intent(in)}]{v,  }\item[{type(thermo\+\_\+var\+\_\+ptrs), intent(in)}]{tv,  }\item[{real, dimension(szi\+\_\+(g),szj\+\_\+(g)), intent(in)}]{u\+Star,  }\item[{real, dimension(szi\+\_\+(g),szj\+\_\+(g),szk\+\_\+(g)+1), intent(in)}]{buoy\+Flux,  }\item[{type(wave\+\_\+parameters\+\_\+cs), optional, pointer}]{Waves }\end{DoxyParamCaption})}



Compute O\+BL depth. 


\begin{DoxyParams}[1]{Parameters}
 & {\em cs} & Control structure\\
\hline
\mbox{\tt in,out}  & {\em g} & Ocean grid\\
\hline
\mbox{\tt in}  & {\em gv} & Ocean vertical grid\\
\hline
\mbox{\tt in}  & {\em us} & A dimensional unit scaling type\\
\hline
\mbox{\tt in}  & {\em h} & Layer/level thicknesses \mbox{[}H $\sim$$>$ m or kg m-\/2\mbox{]}\\
\hline
\mbox{\tt in}  & {\em temp} & potential/cons temp \mbox{[}degC\mbox{]}\\
\hline
\mbox{\tt in}  & {\em salt} & Salinity \mbox{[}ppt\mbox{]}\\
\hline
\mbox{\tt in}  & {\em u} & Velocity i-\/component \mbox{[}L T-\/1 $\sim$$>$ m s-\/1\mbox{]}\\
\hline
\mbox{\tt in}  & {\em v} & Velocity j-\/component \mbox{[}L T-\/1 $\sim$$>$ m s-\/1\mbox{]}\\
\hline
\mbox{\tt in}  & {\em tv} & Thermodynamics structure.\\
\hline
\mbox{\tt in}  & {\em ustar} & Surface friction velocity \mbox{[}Z T-\/1 $\sim$$>$ m s-\/1\mbox{]}\\
\hline
\mbox{\tt in}  & {\em buoyflux} & Surface buoyancy flux \mbox{[}L2 T-\/3 $\sim$$>$ m2 s-\/3\mbox{]}\\
\hline
 & {\em waves} & Wave CS \\
\hline
\end{DoxyParams}


Definition at line 904 of file M\+O\+M\+\_\+\+C\+V\+Mix\+\_\+\+K\+P\+P.\+F90.


\begin{DoxyCode}
904 
905   \textcolor{comment}{! Arguments}
906   \textcolor{keywordtype}{type}(kpp\_cs),                               \textcolor{keywordtype}{pointer}       :: cs\textcolor{comment}{    !< Control structure}
907   \textcolor{keywordtype}{type}(ocean\_grid\_type),                      \textcolor{keywordtype}{intent(inout)} :: g\textcolor{comment}{     !< Ocean grid}
908   \textcolor{keywordtype}{type}(verticalgrid\_type),                    \textcolor{keywordtype}{intent(in)}    :: gv\textcolor{comment}{    !< Ocean vertical grid}
909   \textcolor{keywordtype}{type}(unit\_scale\_type),                      \textcolor{keywordtype}{intent(in)}    :: us\textcolor{comment}{    !< A dimensional unit scaling type}
910   \textcolor{keywordtype}{real}, \textcolor{keywordtype}{dimension(SZI\_(G),SZJ\_(G),SZK\_(G))},   \textcolor{keywordtype}{intent(in)}    :: h\textcolor{comment}{     !< Layer/level thicknesses [H ~> m or
       kg m-2]}
911   \textcolor{keywordtype}{real}, \textcolor{keywordtype}{dimension(SZI\_(G),SZJ\_(G),SZK\_(G))},   \textcolor{keywordtype}{intent(in)}    :: temp\textcolor{comment}{  !< potential/cons temp [degC]}
912   \textcolor{keywordtype}{real}, \textcolor{keywordtype}{dimension(SZI\_(G),SZJ\_(G),SZK\_(G))},   \textcolor{keywordtype}{intent(in)}    :: salt\textcolor{comment}{  !< Salinity [ppt]}
913   \textcolor{keywordtype}{real}, \textcolor{keywordtype}{dimension(SZIB\_(G),SZJ\_(G),SZK\_(G))},  \textcolor{keywordtype}{intent(in)}    :: u\textcolor{comment}{     !< Velocity i-component [L T-1 ~> m
       s-1]}
914   \textcolor{keywordtype}{real}, \textcolor{keywordtype}{dimension(SZI\_(G),SZJB\_(G),SZK\_(G))},  \textcolor{keywordtype}{intent(in)}    :: v\textcolor{comment}{     !< Velocity j-component [L T-1 ~> m
       s-1]}
915   \textcolor{keywordtype}{type}(thermo\_var\_ptrs),                      \textcolor{keywordtype}{intent(in)}    :: tv\textcolor{comment}{    !< Thermodynamics structure.}
916   \textcolor{keywordtype}{real}, \textcolor{keywordtype}{dimension(SZI\_(G),SZJ\_(G))},           \textcolor{keywordtype}{intent(in)}    :: ustar\textcolor{comment}{ !< Surface friction velocity [Z T-1 ~>
       m s-1]}
917   \textcolor{keywordtype}{real}, \textcolor{keywordtype}{dimension(SZI\_(G),SZJ\_(G),SZK\_(G)+1)}, \textcolor{keywordtype}{intent(in)}    :: buoyflux\textcolor{comment}{ !< Surface buoyancy flux [L2 T-3 ~>
       m2 s-3]}
918   \textcolor{keywordtype}{type}(wave\_parameters\_cs),         \textcolor{keywordtype}{optional}, \textcolor{keywordtype}{pointer}       :: waves\textcolor{comment}{ !< Wave CS}
919 
920   \textcolor{comment}{! Local variables}
921   \textcolor{keywordtype}{integer} :: i, j, k, km1                        \textcolor{comment}{! Loop indices}
922   \textcolor{keywordtype}{real}, \textcolor{keywordtype}{dimension( G%ke )}     :: cellheight      \textcolor{comment}{! Cell center heights referenced to surface [m] (negative
       in ocean)}
923   \textcolor{keywordtype}{real}, \textcolor{keywordtype}{dimension( G%ke+1 )}   :: ifaceheight     \textcolor{comment}{! Interface heights referenced to surface [m] (negative in
       ocean)}
924   \textcolor{keywordtype}{real}, \textcolor{keywordtype}{dimension( G%ke+1 )}   :: n2\_1d           \textcolor{comment}{! Brunt-Vaisala frequency squared, at interfaces [s-2]}
925   \textcolor{keywordtype}{real}, \textcolor{keywordtype}{dimension( G%ke )}     :: ws\_1d           \textcolor{comment}{! Profile of vertical velocity scale for scalars [m s-1]}
926   \textcolor{keywordtype}{real}, \textcolor{keywordtype}{dimension( G%ke )}     :: deltarho        \textcolor{comment}{! delta Rho in numerator of Bulk Ri number [R ~> kg m-3]}
927   \textcolor{keywordtype}{real}, \textcolor{keywordtype}{dimension( G%ke )}     :: deltau2         \textcolor{comment}{! square of delta U (shear) in denominator of Bulk Ri [m2
       s-2]}
928   \textcolor{keywordtype}{real}, \textcolor{keywordtype}{dimension( G%ke )}     :: surfbuoyflux2
929   \textcolor{keywordtype}{real}, \textcolor{keywordtype}{dimension( G%ke )}     :: bulkri\_1d       \textcolor{comment}{! Bulk Richardson number for each layer}
930 
931   \textcolor{comment}{! for EOS calculation}
932   \textcolor{keywordtype}{real}, \textcolor{keywordtype}{dimension( 3*G%ke )}   :: rho\_1d   \textcolor{comment}{! A column of densities [R ~> kg m-3]}
933   \textcolor{keywordtype}{real}, \textcolor{keywordtype}{dimension( 3*G%ke )}   :: pres\_1d  \textcolor{comment}{! A column of pressures [R L2 T-2 ~> Pa]}
934   \textcolor{keywordtype}{real}, \textcolor{keywordtype}{dimension( 3*G%ke )}   :: temp\_1d
935   \textcolor{keywordtype}{real}, \textcolor{keywordtype}{dimension( 3*G%ke )}   :: salt\_1d
936 
937   \textcolor{keywordtype}{real} :: surffricvel, surfbuoyflux, coriolis
938   \textcolor{keywordtype}{real} :: gorho  \textcolor{comment}{! Gravitational acceleration divided by density in MKS units [m R-1 s-2 ~> m4 kg-1 s-2]}
939   \textcolor{keywordtype}{real} :: pref   \textcolor{comment}{! The interface pressure [R L2 T-2 ~> Pa]}
940   \textcolor{keywordtype}{real} :: rho1, rhok, uk, vk, sigma, sigmaratio
941 
942   \textcolor{keywordtype}{real} :: zbottomminusoffset   \textcolor{comment}{! Height of bottom plus a little bit [m]}
943   \textcolor{keywordtype}{real} :: sldepth\_0d           \textcolor{comment}{! Surface layer depth = surf\_layer\_ext*OBLdepth.}
944   \textcolor{keywordtype}{real} :: htot                 \textcolor{comment}{! Running sum of thickness used in the surface layer average [m]}
945   \textcolor{keywordtype}{real} :: buoy\_scale           \textcolor{comment}{! A unit conversion factor for buoyancy fluxes [m2 T3 L-2 s-3 ~> nondim]}
946   \textcolor{keywordtype}{real} :: delh                 \textcolor{comment}{! Thickness of a layer [m]}
947   \textcolor{keywordtype}{real} :: surfhtemp, surftemp  \textcolor{comment}{! Integral and average of temp over the surface layer}
948   \textcolor{keywordtype}{real} :: surfhsalt, surfsalt  \textcolor{comment}{! Integral and average of saln over the surface layer}
949   \textcolor{keywordtype}{real} :: surfhu, surfu        \textcolor{comment}{! Integral and average of u over the surface layer}
950   \textcolor{keywordtype}{real} :: surfhv, surfv        \textcolor{comment}{! Integral and average of v over the surface layer}
951   \textcolor{keywordtype}{real} :: dh    \textcolor{comment}{! The local thickness used for calculating interface positions [m]}
952   \textcolor{keywordtype}{real} :: hcorr \textcolor{comment}{! A cumulative correction arising from inflation of vanished layers [m]}
953   \textcolor{keywordtype}{integer} :: kk, ksfc, ktmp
954 
955   \textcolor{comment}{! For Langmuir Calculations}
956   \textcolor{keywordtype}{real} :: langenhw     \textcolor{comment}{! Langmuir enhancement for turbulent velocity scale}
957   \textcolor{keywordtype}{real}, \textcolor{keywordtype}{dimension(G%ke)} :: langenhvt2   \textcolor{comment}{! Langmuir enhancement for unresolved shear}
958   \textcolor{keywordtype}{real}, \textcolor{keywordtype}{dimension(G%ke)} :: u\_h, v\_h
959   \textcolor{keywordtype}{real} :: mld\_guess, la
960   \textcolor{keywordtype}{real} :: surfhus, surfhvs, surfus, surfvs, wavedir, currentdir
961   \textcolor{keywordtype}{real} :: varup, vardn, m, varlo, varavg
962   \textcolor{keywordtype}{real} :: h10pct, h20pct,cmnfact, usx20pct, usy20pct, enhvt2
963   \textcolor{keywordtype}{integer} :: b
964   \textcolor{keywordtype}{real} :: wst
965 
966 
967   \textcolor{keywordflow}{if} (cs%debug) \textcolor{keywordflow}{then}
968     \textcolor{keyword}{call }hchksum(salt, \textcolor{stringliteral}{"KPP in: S"},g%HI,haloshift=0)
969     \textcolor{keyword}{call }hchksum(temp, \textcolor{stringliteral}{"KPP in: T"},g%HI,haloshift=0)
970     \textcolor{keyword}{call }hchksum(u, \textcolor{stringliteral}{"KPP in: u"},g%HI,haloshift=0)
971     \textcolor{keyword}{call }hchksum(v, \textcolor{stringliteral}{"KPP in: v"},g%HI,haloshift=0)
972 \textcolor{keywordflow}{  endif}
973 
974   \textcolor{keyword}{call }cpu\_clock\_begin(id\_clock\_kpp\_compute\_bld)
975 
976   \textcolor{comment}{! some constants}
977   gorho = us%L\_T\_to\_m\_s**2*us%m\_to\_Z * gv%g\_Earth / gv%Rho0
978   buoy\_scale = us%L\_to\_m**2*us%s\_to\_T**3
979 
980   \textcolor{comment}{! loop over horizontal points on processor}
981   \textcolor{comment}{!$OMP parallel do default(none) private(surfFricVel, iFaceHeight, hcorr, dh, cellHeight,  &}
982   \textcolor{comment}{!$OMP                           surfBuoyFlux, U\_H, V\_H, Coriolis, pRef, SLdepth\_0d,       &}
983   \textcolor{comment}{!$OMP                           ksfc, surfHtemp, surfHsalt, surfHu, surfHv, surfHuS,      &}
984   \textcolor{comment}{!$OMP                           surfHvS, hTot, delH, surftemp, surfsalt, surfu, surfv,    &}
985   \textcolor{comment}{!$OMP                           surfUs, surfVs, Uk, Vk, deltaU2, km1, kk, pres\_1D,        &}
986   \textcolor{comment}{!$OMP                           Temp\_1D, salt\_1D, surfBuoyFlux2, MLD\_GUESS, LA, rho\_1D,   &}
987   \textcolor{comment}{!$OMP                           deltarho, N2\_1d, ws\_1d, LangEnhVT2, enhvt2, wst,          &}
988   \textcolor{comment}{!$OMP                           BulkRi\_1d, zBottomMinusOffset) &}
989   \textcolor{comment}{!$OMP                           shared(G, GV, CS, US, uStar, h, buoy\_scale, buoyFlux,     &}
990   \textcolor{comment}{!$OMP                           Temp, Salt, waves, tv, GoRho, u, v)}
991   \textcolor{keywordflow}{do} j = g%jsc, g%jec
992     \textcolor{keywordflow}{do} i = g%isc, g%iec
993 
994       \textcolor{comment}{! skip calling KPP for land points}
995       \textcolor{keywordflow}{if} (g%mask2dT(i,j)==0.) cycle
996 
997       \textcolor{keywordflow}{do} k=1,g%ke
998         u\_h(k) = 0.5 * us%L\_T\_to\_m\_s*(u(i,j,k)+u(i-1,j,k))
999         v\_h(k) = 0.5 * us%L\_T\_to\_m\_s*(v(i,j,k)+v(i,j-1,k))
1000 \textcolor{keywordflow}{      enddo}
1001 
1002       \textcolor{comment}{! things independent of position within the column}
1003       coriolis = 0.25*us%s\_to\_T*( (g%CoriolisBu(i,j)   + g%CoriolisBu(i-1,j-1)) + &
1004                                   (g%CoriolisBu(i-1,j) + g%CoriolisBu(i,j-1)) )
1005       surffricvel = us%Z\_to\_m*us%s\_to\_T * ustar(i,j)
1006 
1007       \textcolor{comment}{! Bullk Richardson number computed for each cell in a column,}
1008       \textcolor{comment}{! assuming OBLdepth = grid cell depth. After Rib(k) is}
1009       \textcolor{comment}{! known for the column, then CVMix interpolates to find}
1010       \textcolor{comment}{! the actual OBLdepth. This approach avoids need to iterate}
1011       \textcolor{comment}{! on the OBLdepth calculation. It follows that used in MOM5}
1012       \textcolor{comment}{! and POP.}
1013       ifaceheight(1) = 0.0 \textcolor{comment}{! BBL is all relative to the surface}
1014       pref = 0. ; \textcolor{keywordflow}{if} (\textcolor{keyword}{associated}(tv%p\_surf)) pref = tv%p\_surf(i,j)
1015       hcorr = 0.
1016       \textcolor{keywordflow}{do} k=1,g%ke
1017 
1018         \textcolor{comment}{! cell center and cell bottom in meters (negative values in the ocean)}
1019         dh = h(i,j,k) * gv%H\_to\_m \textcolor{comment}{! Nominal thickness to use for increment}
1020         dh = dh + hcorr \textcolor{comment}{! Take away the accumulated error (could temporarily make dh<0)}
1021         hcorr = min( dh - cs%min\_thickness, 0. ) \textcolor{comment}{! If inflating then hcorr<0}
1022         dh = max( dh, cs%min\_thickness ) \textcolor{comment}{! Limit increment dh>=min\_thickness}
1023         cellheight(k)    = ifaceheight(k) - 0.5 * dh
1024         ifaceheight(k+1) = ifaceheight(k) - dh
1025 
1026         \textcolor{comment}{! find ksfc for cell where "surface layer" sits}
1027         sldepth\_0d = cs%surf\_layer\_ext*max( max(-cellheight(k),-ifaceheight(2) ), cs%minOBLdepth )
1028         ksfc = k
1029         \textcolor{keywordflow}{do} ktmp = 1,k
1030           \textcolor{keywordflow}{if} (-1.0*ifaceheight(ktmp+1) >= sldepth\_0d) \textcolor{keywordflow}{then}
1031             ksfc = ktmp
1032             \textcolor{keywordflow}{exit}
1033 \textcolor{keywordflow}{          endif}
1034 \textcolor{keywordflow}{        enddo}
1035 
1036         \textcolor{comment}{! average temp, saln, u, v over surface layer}
1037         \textcolor{comment}{! use C-grid average to get u,v on T-points.}
1038         surfhtemp=0.0
1039         surfhsalt=0.0
1040         surfhu   =0.0
1041         surfhv   =0.0
1042         surfhus  =0.0
1043         surfhvs  =0.0
1044         htot     =0.0
1045         \textcolor{keywordflow}{do} ktmp = 1,ksfc
1046 
1047           \textcolor{comment}{! SLdepth\_0d can be between cell interfaces}
1048           delh = min( max(0.0, sldepth\_0d - htot), h(i,j,ktmp)*gv%H\_to\_m )
1049 
1050           \textcolor{comment}{! surface layer thickness}
1051           htot = htot + delh
1052 
1053           \textcolor{comment}{! surface averaged fields}
1054           surfhtemp = surfhtemp + temp(i,j,ktmp) * delh
1055           surfhsalt = surfhsalt + salt(i,j,ktmp) * delh
1056           surfhu    = surfhu + 0.5*us%L\_T\_to\_m\_s*(u(i,j,ktmp)+u(i-1,j,ktmp)) * delh
1057           surfhv    = surfhv + 0.5*us%L\_T\_to\_m\_s*(v(i,j,ktmp)+v(i,j-1,ktmp)) * delh
1058           \textcolor{keywordflow}{if} (cs%Stokes\_Mixing) \textcolor{keywordflow}{then}
1059             surfhus = surfhus + 0.5*(waves%US\_x(i,j,ktmp)+waves%US\_x(i-1,j,ktmp)) * delh
1060             surfhvs = surfhvs + 0.5*(waves%US\_y(i,j,ktmp)+waves%US\_y(i,j-1,ktmp)) * delh
1061 \textcolor{keywordflow}{          endif}
1062 
1063 \textcolor{keywordflow}{        enddo}
1064         surftemp = surfhtemp / htot
1065         surfsalt = surfhsalt / htot
1066         surfu    = surfhu    / htot
1067         surfv    = surfhv    / htot
1068         surfus   = surfhus   / htot
1069         surfvs   = surfhvs   / htot
1070 
1071         \textcolor{comment}{! vertical shear between present layer and}
1072         \textcolor{comment}{! surface layer averaged surfU,surfV.}
1073         \textcolor{comment}{! C-grid average to get Uk and Vk on T-points.}
1074         uk         = 0.5*us%L\_T\_to\_m\_s*(u(i,j,k)+u(i-1,j,k)) - surfu
1075         vk         = 0.5*us%L\_T\_to\_m\_s*(v(i,j,k)+v(i,j-1,k)) - surfv
1076 
1077         \textcolor{keywordflow}{if} (cs%Stokes\_Mixing) \textcolor{keywordflow}{then}
1078           \textcolor{comment}{! If momentum is mixed down the Stokes drift gradient, then}
1079           \textcolor{comment}{!  the Stokes drift must be included in the bulk Richardson number}
1080           \textcolor{comment}{!  calculation.}
1081           uk =  uk + (0.5*(waves%Us\_x(i,j,k)+waves%US\_x(i-1,j,k)) -surfus )
1082           vk =  vk + (0.5*(waves%Us\_y(i,j,k)+waves%Us\_y(i,j-1,k)) -surfvs )
1083 \textcolor{keywordflow}{        endif}
1084 
1085         deltau2(k) = uk**2 + vk**2
1086 
1087         \textcolor{comment}{! pressure, temp, and saln for EOS}
1088         \textcolor{comment}{! kk+1 = surface fields}
1089         \textcolor{comment}{! kk+2 = k fields}
1090         \textcolor{comment}{! kk+3 = km1 fields}
1091         km1  = max(1, k-1)
1092         kk   = 3*(k-1)
1093         pres\_1d(kk+1) = pref
1094         pres\_1d(kk+2) = pref
1095         pres\_1d(kk+3) = pref
1096         temp\_1d(kk+1) = surftemp
1097         temp\_1d(kk+2) = temp(i,j,k)
1098         temp\_1d(kk+3) = temp(i,j,km1)
1099         salt\_1d(kk+1) = surfsalt
1100         salt\_1d(kk+2) = salt(i,j,k)
1101         salt\_1d(kk+3) = salt(i,j,km1)
1102 
1103         \textcolor{comment}{! pRef is pressure at interface between k and km1 [R L2 T-2 ~> Pa].}
1104         \textcolor{comment}{! iterate pRef for next pass through k-loop.}
1105         pref = pref + (gv%g\_Earth * gv%H\_to\_RZ) * h(i,j,k)
1106 
1107         \textcolor{comment}{! this difference accounts for penetrating SW}
1108         surfbuoyflux2(k) = buoy\_scale * (buoyflux(i,j,1) - buoyflux(i,j,k+1))
1109 
1110 \textcolor{keywordflow}{      enddo} \textcolor{comment}{! k-loop finishes}
1111 
1112       \textcolor{keywordflow}{if} (cs%LT\_K\_ENHANCEMENT .or. cs%LT\_VT2\_ENHANCEMENT) \textcolor{keywordflow}{then}
1113         mld\_guess = max( 1.*us%m\_to\_Z, abs(us%m\_to\_Z*cs%OBLdepthprev(i,j) ) )
1114         \textcolor{keyword}{call }get\_langmuir\_number(la, g, gv, us, mld\_guess, ustar(i,j), i, j, &
1115                                  h=h(i,j,:), u\_h=u\_h, v\_h=v\_h, waves=waves)
1116         cs%La\_SL(i,j)=la
1117 \textcolor{keywordflow}{      endif}
1118 
1119 
1120       \textcolor{comment}{! compute in-situ density}
1121       \textcolor{keyword}{call }calculate\_density(temp\_1d, salt\_1d, pres\_1d, rho\_1d, tv%eqn\_of\_state)
1122 
1123       \textcolor{comment}{! N2 (can be negative) and N (non-negative) on interfaces.}
1124       \textcolor{comment}{! deltaRho is non-local rho difference used for bulk Richardson number.}
1125       \textcolor{comment}{! CS%N is local N (with floor) used for unresolved shear calculation.}
1126       \textcolor{keywordflow}{do} k = 1, g%ke
1127         km1 = max(1, k-1)
1128         kk = 3*(k-1)
1129         deltarho(k) = rho\_1d(kk+2) - rho\_1d(kk+1)
1130         n2\_1d(k)    = (gorho * (rho\_1d(kk+2) - rho\_1d(kk+3)) ) / &
1131                       ((0.5*(h(i,j,km1) + h(i,j,k))+gv%H\_subroundoff)*gv%H\_to\_m)
1132         cs%N(i,j,k)     = sqrt( max( n2\_1d(k), 0.) )
1133 \textcolor{keywordflow}{      enddo}
1134       n2\_1d(g%ke+1 ) = 0.0
1135       cs%N(i,j,g%ke+1 )  = 0.0
1136 
1137       \textcolor{comment}{! turbulent velocity scales w\_s and w\_m computed at the cell centers.}
1138       \textcolor{comment}{! Note that if sigma > CS%surf\_layer\_ext, then CVMix\_kpp\_compute\_turbulent\_scales}
1139       \textcolor{comment}{! computes w\_s and w\_m velocity scale at sigma=CS%surf\_layer\_ext. So we only pass}
1140       \textcolor{comment}{! sigma=CS%surf\_layer\_ext for this calculation.}
1141       \textcolor{keyword}{call }cvmix\_kpp\_compute\_turbulent\_scales( &
1142         cs%surf\_layer\_ext, & \textcolor{comment}{! (in)  Normalized surface layer depth; sigma = CS%surf\_layer\_ext}
1143         -cellheight,       & \textcolor{comment}{! (in)  Assume here that OBL depth [m] = -cellHeight(k)}
1144         surfbuoyflux2,     & \textcolor{comment}{! (in)  Buoyancy flux at surface [m2 s-3]}
1145         surffricvel,       & \textcolor{comment}{! (in)  Turbulent friction velocity at surface [m s-1]}
1146         w\_s=ws\_1d,         & \textcolor{comment}{! (out) Turbulent velocity scale profile [m s-1]}
1147         cvmix\_kpp\_params\_user=cs%KPP\_params )
1148 
1149       \textcolor{comment}{!Compute CVMix VT2}
1150       cs%Vt2(i,j,:) = cvmix\_kpp\_compute\_unresolved\_shear( &
1151                       zt\_cntr=cellheight(1:g%ke),         & \textcolor{comment}{! Depth of cell center [m]}
1152                       ws\_cntr=ws\_1d,                      & \textcolor{comment}{! Turbulent velocity scale profile, at centers
       [m s-1]}
1153                       n\_iface=cs%N(i,j,:),                & \textcolor{comment}{! Buoyancy frequency at interface [s-1]}
1154                     cvmix\_kpp\_params\_user=cs%KPP\_params ) \textcolor{comment}{! KPP parameters}
1155 
1156       \textcolor{comment}{!Modify CVMix VT2}
1157       \textcolor{keywordflow}{IF} (cs%LT\_VT2\_ENHANCEMENT) \textcolor{keywordflow}{then}
1158         \textcolor{keywordflow}{IF} (cs%LT\_VT2\_METHOD==lt\_vt2\_mode\_constant) \textcolor{keywordflow}{then}
1159           \textcolor{keywordflow}{do} k=1,g%ke
1160             langenhvt2(k) = cs%KPP\_VT2\_ENH\_FAC
1161 \textcolor{keywordflow}{          enddo}
1162         \textcolor{keywordflow}{elseif} (cs%LT\_VT2\_METHOD==lt\_vt2\_mode\_vr12) \textcolor{keywordflow}{then}
1163           \textcolor{comment}{!Introduced minimum value for La\_SL, so maximum value for enhvt2 is removed.}
1164           enhvt2 = sqrt(1.+(1.5*cs%La\_SL(i,j))**(-2) + &
1165                    (5.4*cs%La\_SL(i,j))**(-4))
1166           \textcolor{keywordflow}{do} k=1,g%ke
1167              langenhvt2(k) = enhvt2
1168 \textcolor{keywordflow}{          enddo}
1169         \textcolor{keywordflow}{elseif} (cs%LT\_VT2\_METHOD==lt\_vt2\_mode\_rw16) \textcolor{keywordflow}{then}
1170           \textcolor{comment}{!Introduced minimum value for La\_SL, so maximum value for enhvt2 is removed.}
1171           enhvt2 = 1. + 2.3*cs%La\_SL(i,j)**(-0.5)
1172           \textcolor{keywordflow}{do} k=1,g%ke
1173             langenhvt2(k) = enhvt2
1174 \textcolor{keywordflow}{          enddo}
1175         \textcolor{keywordflow}{elseif} (cs%LT\_VT2\_METHOD==lt\_vt2\_mode\_lf17) \textcolor{keywordflow}{then}
1176           cs%CS=cvmix\_get\_kpp\_real(\textcolor{stringliteral}{'c\_s'},cs%KPP\_params)
1177           \textcolor{keywordflow}{do} k=1,g%ke
1178             wst = (max(0.,-buoy\_scale*buoyflux(i,j,1))*(-cellheight(k)))**(1./3.)
1179             langenhvt2(k) = sqrt((0.15*wst**3. + 0.17*surffricvel**3.* &
1180                  (1.+0.49*cs%La\_SL(i,j)**(-2.)))  / &
1181                  (0.2*ws\_1d(k)**3/(cs%cs*cs%surf\_layer\_ext*cs%vonKarman**4.)))
1182 \textcolor{keywordflow}{          enddo}
1183         \textcolor{keywordflow}{else}
1184            \textcolor{comment}{!This shouldn't be reached.}
1185            \textcolor{comment}{!call MOM\_error(WARNING,"Unexpected behavior in MOM\_CVMix\_KPP, see error in Vt2")}
1186            langenhvt2(:) = 1.0
1187 \textcolor{keywordflow}{        endif}
1188       \textcolor{keywordflow}{else}
1189         langenhvt2(:) = 1.0
1190 \textcolor{keywordflow}{      endif}
1191 
1192       \textcolor{keywordflow}{do} k=1,g%ke
1193         cs%Vt2(i,j,k)=cs%Vt2(i,j,k)*langenhvt2(k)
1194         \textcolor{keywordflow}{if} (cs%id\_EnhVt2 > 0) cs%EnhVt2(i,j,k)=langenhvt2(k)
1195 \textcolor{keywordflow}{      enddo}
1196 
1197       \textcolor{comment}{! Calculate Bulk Richardson number from eq (21) of LMD94}
1198       bulkri\_1d = cvmix\_kpp\_compute\_bulk\_richardson( &
1199                   zt\_cntr = cellheight(1:g%ke),      & \textcolor{comment}{! Depth of cell center [m]}
1200                   delta\_buoy\_cntr=gorho*deltarho,    & \textcolor{comment}{! Bulk buoyancy difference, Br-B(z) [s-1]}
1201                   delta\_vsqr\_cntr=deltau2,           & \textcolor{comment}{! Square of resolved velocity difference [m2 s-2]}
1202                   vt\_sqr\_cntr=cs%Vt2(i,j,:),         &
1203                   ws\_cntr=ws\_1d,                     & \textcolor{comment}{! Turbulent velocity scale profile [m s-1]}
1204                   n\_iface=cs%N(i,j,:))               \textcolor{comment}{! Buoyancy frequency [s-1]}
1205 
1206 
1207       surfbuoyflux = buoy\_scale * buoyflux(i,j,1) \textcolor{comment}{! This is only used in kpp\_compute\_OBL\_depth to limit}
1208                                      \textcolor{comment}{! h to Monin-Obukov (default is false, ie. not used)}
1209 
1210       \textcolor{keyword}{call }cvmix\_kpp\_compute\_obl\_depth( &
1211         bulkri\_1d,              & \textcolor{comment}{! (in) Bulk Richardson number}
1212         ifaceheight,            & \textcolor{comment}{! (in) Height of interfaces [m]}
1213         cs%OBLdepth(i,j),       & \textcolor{comment}{! (out) OBL depth [m]}
1214         cs%kOBL(i,j),           & \textcolor{comment}{! (out) level (+fraction) of OBL extent}
1215         zt\_cntr=cellheight,     & \textcolor{comment}{! (in) Height of cell centers [m]}
1216         surf\_fric=surffricvel,  & \textcolor{comment}{! (in) Turbulent friction velocity at surface [m s-1]}
1217         surf\_buoy=surfbuoyflux, & \textcolor{comment}{! (in) Buoyancy flux at surface [m2 s-3]}
1218         coriolis=coriolis,      & \textcolor{comment}{! (in) Coriolis parameter [s-1]}
1219         cvmix\_kpp\_params\_user=cs%KPP\_params ) \textcolor{comment}{! KPP parameters}
1220 
1221       \textcolor{comment}{! A hack to avoid KPP reaching the bottom. It was needed during development}
1222       \textcolor{comment}{! because KPP was unable to handle vanishingly small layers near the bottom.}
1223       \textcolor{keywordflow}{if} (cs%deepOBLoffset>0.) \textcolor{keywordflow}{then}
1224         zbottomminusoffset = ifaceheight(g%ke+1) + min(cs%deepOBLoffset,-0.1*ifaceheight(g%ke+1))
1225         cs%OBLdepth(i,j) = min( cs%OBLdepth(i,j), -zbottomminusoffset )
1226 \textcolor{keywordflow}{      endif}
1227 
1228       \textcolor{comment}{! apply some constraints on OBLdepth}
1229       \textcolor{keywordflow}{if}(cs%fixedOBLdepth)  cs%OBLdepth(i,j) = cs%fixedOBLdepth\_value
1230       cs%OBLdepth(i,j) = max( cs%OBLdepth(i,j), -ifaceheight(2) )      \textcolor{comment}{! no shallower than top layer}
1231       cs%OBLdepth(i,j) = min( cs%OBLdepth(i,j), -ifaceheight(g%ke+1) ) \textcolor{comment}{! no deeper than bottom}
1232       cs%kOBL(i,j)     = cvmix\_kpp\_compute\_kobl\_depth( ifaceheight, cellheight, cs%OBLdepth(i,j) )
1233 
1234 
1235       \textcolor{comment}{! recompute wscale for diagnostics, now that we in fact know boundary layer depth}
1236       \textcolor{comment}{!BGR consider if LTEnhancement is wanted for diagnostics}
1237       \textcolor{keywordflow}{if} (cs%id\_Ws > 0) \textcolor{keywordflow}{then}
1238           \textcolor{keyword}{call }cvmix\_kpp\_compute\_turbulent\_scales( &
1239             -cellheight/cs%OBLdepth(i,j),          & \textcolor{comment}{! (in)  Normalized boundary layer coordinate}
1240             cs%OBLdepth(i,j),                      & \textcolor{comment}{! (in)  OBL depth [m]}
1241             surfbuoyflux,                          & \textcolor{comment}{! (in)  Buoyancy flux at surface [m2 s-3]}
1242             surffricvel,                           & \textcolor{comment}{! (in)  Turbulent friction velocity at surface [m s-1]}
1243             w\_s=ws\_1d,                             & \textcolor{comment}{! (out) Turbulent velocity scale profile [m s-1]}
1244             cvmix\_kpp\_params\_user=cs%KPP\_params)     \textcolor{comment}{!       KPP parameters}
1245           cs%Ws(i,j,:) = ws\_1d(:)
1246 \textcolor{keywordflow}{      endif}
1247 
1248       \textcolor{comment}{! Diagnostics}
1249       \textcolor{keywordflow}{if} (cs%id\_N2     > 0)   cs%N2(i,j,:)     = n2\_1d(:)
1250       \textcolor{keywordflow}{if} (cs%id\_BulkDrho > 0) cs%dRho(i,j,:)   = deltarho(:)
1251       \textcolor{keywordflow}{if} (cs%id\_BulkRi > 0)   cs%BulkRi(i,j,:) = bulkri\_1d(:)
1252       \textcolor{keywordflow}{if} (cs%id\_BulkUz2 > 0)  cs%Uz2(i,j,:)    = deltau2(:)
1253       \textcolor{keywordflow}{if} (cs%id\_Tsurf  > 0)   cs%Tsurf(i,j)    = surftemp
1254       \textcolor{keywordflow}{if} (cs%id\_Ssurf  > 0)   cs%Ssurf(i,j)    = surfsalt
1255       \textcolor{keywordflow}{if} (cs%id\_Usurf  > 0)   cs%Usurf(i,j)    = surfu
1256       \textcolor{keywordflow}{if} (cs%id\_Vsurf  > 0)   cs%Vsurf(i,j)    = surfv
1257 
1258 \textcolor{keywordflow}{    enddo}
1259 \textcolor{keywordflow}{  enddo}
1260 
1261   \textcolor{keyword}{call }cpu\_clock\_end(id\_clock\_kpp\_compute\_bld)
1262 
1263   \textcolor{comment}{! send diagnostics to post\_data}
1264   \textcolor{keywordflow}{if} (cs%id\_BulkRi   > 0) \textcolor{keyword}{call }post\_data(cs%id\_BulkRi,   cs%BulkRi,          cs%diag)
1265   \textcolor{keywordflow}{if} (cs%id\_N        > 0) \textcolor{keyword}{call }post\_data(cs%id\_N,        cs%N,               cs%diag)
1266   \textcolor{keywordflow}{if} (cs%id\_N2       > 0) \textcolor{keyword}{call }post\_data(cs%id\_N2,       cs%N2,              cs%diag)
1267   \textcolor{keywordflow}{if} (cs%id\_Tsurf    > 0) \textcolor{keyword}{call }post\_data(cs%id\_Tsurf,    cs%Tsurf,           cs%diag)
1268   \textcolor{keywordflow}{if} (cs%id\_Ssurf    > 0) \textcolor{keyword}{call }post\_data(cs%id\_Ssurf,    cs%Ssurf,           cs%diag)
1269   \textcolor{keywordflow}{if} (cs%id\_Usurf    > 0) \textcolor{keyword}{call }post\_data(cs%id\_Usurf,    cs%Usurf,           cs%diag)
1270   \textcolor{keywordflow}{if} (cs%id\_Vsurf    > 0) \textcolor{keyword}{call }post\_data(cs%id\_Vsurf,    cs%Vsurf,           cs%diag)
1271   \textcolor{keywordflow}{if} (cs%id\_BulkDrho > 0) \textcolor{keyword}{call }post\_data(cs%id\_BulkDrho, cs%dRho,            cs%diag)
1272   \textcolor{keywordflow}{if} (cs%id\_BulkUz2  > 0) \textcolor{keyword}{call }post\_data(cs%id\_BulkUz2,  cs%Uz2,             cs%diag)
1273   \textcolor{keywordflow}{if} (cs%id\_EnhK     > 0) \textcolor{keyword}{call }post\_data(cs%id\_EnhK,     cs%EnhK,            cs%diag)
1274   \textcolor{keywordflow}{if} (cs%id\_EnhVt2   > 0) \textcolor{keyword}{call }post\_data(cs%id\_EnhVt2,   cs%EnhVt2,          cs%diag)
1275   \textcolor{keywordflow}{if} (cs%id\_La\_SL    > 0) \textcolor{keyword}{call }post\_data(cs%id\_La\_SL,    cs%La\_SL,           cs%diag)
1276 
1277   \textcolor{comment}{! BLD smoothing:}
1278   \textcolor{keywordflow}{if} (cs%n\_smooth > 0) \textcolor{keyword}{call }kpp\_smooth\_bld(cs,g,gv,h)
1279 
\end{DoxyCode}
\mbox{\Hypertarget{namespacemom__cvmix__kpp_ab64722f48cd1d20a4c5bfc74ad602326}\label{namespacemom__cvmix__kpp_ab64722f48cd1d20a4c5bfc74ad602326}} 
\index{mom\+\_\+cvmix\+\_\+kpp@{mom\+\_\+cvmix\+\_\+kpp}!kpp\+\_\+end@{kpp\+\_\+end}}
\index{kpp\+\_\+end@{kpp\+\_\+end}!mom\+\_\+cvmix\+\_\+kpp@{mom\+\_\+cvmix\+\_\+kpp}}
\subsubsection{\texorpdfstring{kpp\+\_\+end()}{kpp\_end()}}
{\footnotesize\ttfamily subroutine, public mom\+\_\+cvmix\+\_\+kpp\+::kpp\+\_\+end (\begin{DoxyParamCaption}\item[{type(\hyperlink{structmom__cvmix__kpp_1_1kpp__cs}{kpp\+\_\+cs}), pointer}]{CS }\end{DoxyParamCaption})}



Clear pointers, deallocate memory. 


\begin{DoxyParams}{Parameters}
{\em cs} & Control structure \\
\hline
\end{DoxyParams}


Definition at line 1514 of file M\+O\+M\+\_\+\+C\+V\+Mix\+\_\+\+K\+P\+P.\+F90.


\begin{DoxyCode}
1514   \textcolor{keywordtype}{type}(kpp\_cs), \textcolor{keywordtype}{pointer} :: cs\textcolor{comment}{ !< Control structure}
1515 
1516   \textcolor{keywordflow}{if} (.not.\textcolor{keyword}{associated}(cs)) \textcolor{keywordflow}{return}
1517 
1518   \textcolor{keyword}{deallocate}(cs)
1519 
\end{DoxyCode}
\mbox{\Hypertarget{namespacemom__cvmix__kpp_abcb80984f564e5aaf4567aaead111734}\label{namespacemom__cvmix__kpp_abcb80984f564e5aaf4567aaead111734}} 
\index{mom\+\_\+cvmix\+\_\+kpp@{mom\+\_\+cvmix\+\_\+kpp}!kpp\+\_\+get\+\_\+bld@{kpp\+\_\+get\+\_\+bld}}
\index{kpp\+\_\+get\+\_\+bld@{kpp\+\_\+get\+\_\+bld}!mom\+\_\+cvmix\+\_\+kpp@{mom\+\_\+cvmix\+\_\+kpp}}
\subsubsection{\texorpdfstring{kpp\+\_\+get\+\_\+bld()}{kpp\_get\_bld()}}
{\footnotesize\ttfamily subroutine, public mom\+\_\+cvmix\+\_\+kpp\+::kpp\+\_\+get\+\_\+bld (\begin{DoxyParamCaption}\item[{type(\hyperlink{structmom__cvmix__kpp_1_1kpp__cs}{kpp\+\_\+cs}), pointer}]{CS,  }\item[{real, dimension( g \%isd\+: g \%ied, g \%jsd\+: g \%jed), intent(inout)}]{B\+LD,  }\item[{type(ocean\+\_\+grid\+\_\+type), intent(in)}]{G,  }\item[{type(unit\+\_\+scale\+\_\+type), intent(in)}]{US,  }\item[{real, intent(in), optional}]{m\+\_\+to\+\_\+\+B\+L\+D\+\_\+units }\end{DoxyParamCaption})}



Copies K\+PP surface boundary layer depth into B\+LD, in units of \mbox{[}Z $\sim$$>$ m\mbox{]} unless other units are specified. 


\begin{DoxyParams}[1]{Parameters}
 & {\em cs} & Control structure for this module\\
\hline
\mbox{\tt in}  & {\em g} & Grid structure\\
\hline
\mbox{\tt in}  & {\em us} & A dimensional unit scaling type\\
\hline
\mbox{\tt in,out}  & {\em bld} & Boundary layer depth \mbox{[}Z $\sim$$>$ m\mbox{]} or other units\\
\hline
\mbox{\tt in}  & {\em m\+\_\+to\+\_\+bld\+\_\+units} & A conversion factor from meters to the desired units for B\+LD \\
\hline
\end{DoxyParams}


Definition at line 1367 of file M\+O\+M\+\_\+\+C\+V\+Mix\+\_\+\+K\+P\+P.\+F90.


\begin{DoxyCode}
1367   \textcolor{keywordtype}{type}(kpp\_cs),                     \textcolor{keywordtype}{pointer}     :: cs\textcolor{comment}{  !< Control structure for}
1368 \textcolor{comment}{                                                       !! this module}
1369   \textcolor{keywordtype}{type}(ocean\_grid\_type),            \textcolor{keywordtype}{intent(in)}  :: g\textcolor{comment}{   !< Grid structure}
1370   \textcolor{keywordtype}{type}(unit\_scale\_type),            \textcolor{keywordtype}{intent(in)}  :: us\textcolor{comment}{  !< A dimensional unit scaling type}
1371   \textcolor{keywordtype}{real}, \textcolor{keywordtype}{dimension(SZI\_(G),SZJ\_(G))}, \textcolor{keywordtype}{intent(inout)} :: bld\textcolor{comment}{ !< Boundary layer depth [Z ~> m] or other units}
1372   \textcolor{keywordtype}{real},                   \textcolor{keywordtype}{optional}, \textcolor{keywordtype}{intent(in)}  :: m\_to\_bld\_units\textcolor{comment}{ !< A conversion factor from meters}
1373 \textcolor{comment}{                                                       !! to the desired units for BLD}
1374   \textcolor{comment}{! Local variables}
1375   \textcolor{keywordtype}{real} :: scale  \textcolor{comment}{! A dimensional rescaling factor}
1376   \textcolor{keywordtype}{integer} :: i,j
1377 
1378   scale = us%m\_to\_Z ; \textcolor{keywordflow}{if} (\textcolor{keyword}{present}(m\_to\_bld\_units)) scale = m\_to\_bld\_units
1379 
1380   \textcolor{comment}{!$OMP parallel do default(none) shared(BLD, CS, G, scale)}
1381   \textcolor{keywordflow}{do} j = g%jsc, g%jec ; \textcolor{keywordflow}{do} i = g%isc, g%iec
1382     bld(i,j) = scale * cs%OBLdepth(i,j)
1383 \textcolor{keywordflow}{  enddo} ;\textcolor{keywordflow}{ enddo}
1384 
\end{DoxyCode}
\mbox{\Hypertarget{namespacemom__cvmix__kpp_ada767f6da63b74348a7461eb1d12c5d6}\label{namespacemom__cvmix__kpp_ada767f6da63b74348a7461eb1d12c5d6}} 
\index{mom\+\_\+cvmix\+\_\+kpp@{mom\+\_\+cvmix\+\_\+kpp}!kpp\+\_\+init@{kpp\+\_\+init}}
\index{kpp\+\_\+init@{kpp\+\_\+init}!mom\+\_\+cvmix\+\_\+kpp@{mom\+\_\+cvmix\+\_\+kpp}}
\subsubsection{\texorpdfstring{kpp\+\_\+init()}{kpp\_init()}}
{\footnotesize\ttfamily logical function, public mom\+\_\+cvmix\+\_\+kpp\+::kpp\+\_\+init (\begin{DoxyParamCaption}\item[{type(param\+\_\+file\+\_\+type), intent(in)}]{param\+File,  }\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(diag\+\_\+ctrl), intent(in), target}]{diag,  }\item[{type(time\+\_\+type), intent(in)}]{Time,  }\item[{type(\hyperlink{structmom__cvmix__kpp_1_1kpp__cs}{kpp\+\_\+cs}), pointer}]{CS,  }\item[{logical, intent(out), optional}]{passive,  }\item[{type(wave\+\_\+parameters\+\_\+cs), optional, pointer}]{Waves }\end{DoxyParamCaption})}



Initialize the C\+V\+Mix K\+PP module and set up diagnostics Returns True if K\+PP is to be used, False otherwise. 


\begin{DoxyParams}[1]{Parameters}
\mbox{\tt in}  & {\em paramfile} & File parser\\
\hline
\mbox{\tt in}  & {\em g} & Ocean grid\\
\hline
\mbox{\tt in}  & {\em gv} & Vertical grid structure.\\
\hline
\mbox{\tt in}  & {\em us} & A dimensional unit scaling type\\
\hline
\mbox{\tt in}  & {\em diag} & Diagnostics\\
\hline
\mbox{\tt in}  & {\em time} & Model time\\
\hline
 & {\em cs} & Control structure\\
\hline
\mbox{\tt out}  & {\em passive} & Copy of passive\+Mode\\
\hline
 & {\em waves} & Wave CS \\
\hline
\end{DoxyParams}


Definition at line 185 of file M\+O\+M\+\_\+\+C\+V\+Mix\+\_\+\+K\+P\+P.\+F90.


\begin{DoxyCode}
185 
186   \textcolor{comment}{! Arguments}
187   \textcolor{keywordtype}{type}(param\_file\_type),   \textcolor{keywordtype}{intent(in)}    :: paramfile\textcolor{comment}{ !< File parser}
188   \textcolor{keywordtype}{type}(ocean\_grid\_type),   \textcolor{keywordtype}{intent(in)}    :: g\textcolor{comment}{         !< Ocean grid}
189   \textcolor{keywordtype}{type}(verticalgrid\_type), \textcolor{keywordtype}{intent(in)}    :: gv\textcolor{comment}{        !< Vertical grid structure.}
190   \textcolor{keywordtype}{type}(unit\_scale\_type),   \textcolor{keywordtype}{intent(in)}    :: us\textcolor{comment}{        !< A dimensional unit scaling type}
191   \textcolor{keywordtype}{type}(diag\_ctrl), \textcolor{keywordtype}{target}, \textcolor{keywordtype}{intent(in)}    :: diag\textcolor{comment}{      !< Diagnostics}
192   \textcolor{keywordtype}{type}(time\_type),         \textcolor{keywordtype}{intent(in)}    :: time\textcolor{comment}{      !< Model time}
193   \textcolor{keywordtype}{type}(kpp\_cs),            \textcolor{keywordtype}{pointer}       :: cs\textcolor{comment}{        !< Control structure}
194   \textcolor{keywordtype}{logical},       \textcolor{keywordtype}{optional}, \textcolor{keywordtype}{intent(out)}   :: passive\textcolor{comment}{   !< Copy of %passiveMode}
195   \textcolor{keywordtype}{type}(wave\_parameters\_cs), \textcolor{keywordtype}{optional}, \textcolor{keywordtype}{pointer} :: waves\textcolor{comment}{ !< Wave CS}
196 
197   \textcolor{comment}{! Local variables}
198 \textcolor{preprocessor}{# include "version\_variable.h"}
199 \textcolor{preprocessor}{}  \textcolor{keywordtype}{character(len=40)} :: mdl = \textcolor{stringliteral}{'MOM\_CVMix\_KPP'}\textcolor{comment}{ !< name of this module}
200   \textcolor{keywordtype}{character(len=20)} :: string\textcolor{comment}{          !< local temporary string}
201   \textcolor{keywordtype}{logical} :: cs\_is\_one=.false.         \textcolor{comment}{!< Logical for setting Cs based on Non-local}
202   \textcolor{keywordtype}{logical} :: lnodgat1=.false.          \textcolor{comment}{!< True => G'(1) = 0 (shape function)}
203 \textcolor{comment}{                                       !! False => compute G'(1) as in LMD94}
204   \textcolor{keywordflow}{if} (\textcolor{keyword}{associated}(cs)) \textcolor{keyword}{call }mom\_error(fatal, \textcolor{stringliteral}{'MOM\_CVMix\_KPP, KPP\_init: '}// &
205            \textcolor{stringliteral}{'Control structure has already been initialized'})
206 
207   \textcolor{comment}{! Read parameters}
208   \textcolor{keyword}{call }get\_param(paramfile, mdl, \textcolor{stringliteral}{"USE\_KPP"}, kpp\_init, default=.false., do\_not\_log=.true.)
209   \textcolor{keyword}{call }log\_version(paramfile, mdl, version, \textcolor{stringliteral}{'This is the MOM wrapper to CVMix:KPP\(\backslash\)n'} // &
210             \textcolor{stringliteral}{'See http://cvmix.github.io/'}, all\_default=.not.kpp\_init)
211   \textcolor{keyword}{call }get\_param(paramfile, mdl, \textcolor{stringliteral}{"USE\_KPP"}, kpp\_init, &
212                  \textcolor{stringliteral}{"If true, turns on the [CVMix] KPP scheme of Large et al., 1994, "}// &
213                  \textcolor{stringliteral}{"to calculate diffusivities and non-local transport in the OBL."},     &
214                  default=.false.)
215   \textcolor{comment}{! Forego remainder of initialization if not using this scheme}
216   \textcolor{keywordflow}{if} (.not. kpp\_init) \textcolor{keywordflow}{return}
217   \textcolor{keyword}{allocate}(cs)
218 
219   \textcolor{keyword}{call }openparameterblock(paramfile,\textcolor{stringliteral}{'KPP'})
220   \textcolor{keyword}{call }get\_param(paramfile, mdl, \textcolor{stringliteral}{'PASSIVE'}, cs%passiveMode,           &
221                  \textcolor{stringliteral}{'If True, puts KPP into a passive-diagnostic mode.'}, &
222                   default=.false.)
223   \textcolor{comment}{!BGR: Note using PASSIVE for KPP creates warning for PASSIVE from Convection}
224   \textcolor{comment}{!     should we create a separate flag?}
225   \textcolor{keywordflow}{if} (\textcolor{keyword}{present}(passive)) passive=cs%passiveMode \textcolor{comment}{! This is passed back to the caller so}
226                                                \textcolor{comment}{! the caller knows to not use KPP output}
227   \textcolor{keyword}{call }get\_param(paramfile, mdl, \textcolor{stringliteral}{'APPLY\_NONLOCAL\_TRANSPORT'}, cs%applyNonLocalTrans,  &
228                  \textcolor{stringliteral}{'If True, applies the non-local transport to heat and scalars. '}//  &
229                  \textcolor{stringliteral}{'If False, calculates the non-local transport and tendencies but '}//&
230                  \textcolor{stringliteral}{'purely for diagnostic purposes.'},                                   &
231                  default=.not. cs%passiveMode)
232   \textcolor{keyword}{call }get\_param(paramfile, mdl, \textcolor{stringliteral}{'N\_SMOOTH'}, cs%n\_smooth,  &
233                  \textcolor{stringliteral}{'The number of times the 1-1-4-1-1 Laplacian filter is applied on '}//  &
234                  \textcolor{stringliteral}{'OBL depth.'},   &
235                  default=0)
236   \textcolor{keywordflow}{if} (cs%n\_smooth > g%domain%nihalo) \textcolor{keywordflow}{then}
237     \textcolor{keyword}{call }mom\_error(fatal,\textcolor{stringliteral}{'KPP smoothing number (N\_SMOOTH) cannot be greater than NIHALO.'})
238   \textcolor{keywordflow}{elseif} (cs%n\_smooth > g%domain%njhalo) \textcolor{keywordflow}{then}
239     \textcolor{keyword}{call }mom\_error(fatal,\textcolor{stringliteral}{'KPP smoothing number (N\_SMOOTH) cannot be greater than NJHALO.'})
240 \textcolor{keywordflow}{  endif}
241   \textcolor{keywordflow}{if} (cs%n\_smooth > 0) \textcolor{keywordflow}{then}
242     \textcolor{keyword}{call }get\_param(paramfile, mdl, \textcolor{stringliteral}{'DEEPEN\_ONLY\_VIA\_SMOOTHING'}, cs%deepen\_only,  &
243                    \textcolor{stringliteral}{'If true, apply OBLdepth smoothing at a cell only if the OBLdepth '}// &
244                    \textcolor{stringliteral}{'gets deeper via smoothing.'},   &
245                    default=.false.)
246     id\_clock\_kpp\_smoothing = cpu\_clock\_id(\textcolor{stringliteral}{'(Ocean KPP BLD smoothing)'}, grain=clock\_routine)
247 \textcolor{keywordflow}{  endif}
248   \textcolor{keyword}{call }get\_param(paramfile, mdl, \textcolor{stringliteral}{'RI\_CRIT'}, cs%Ri\_crit,                            &
249                  \textcolor{stringliteral}{'Critical bulk Richardson number used to define depth of the '}// &
250                  \textcolor{stringliteral}{'surface Ocean Boundary Layer (OBL).'},                            &
251                  units=\textcolor{stringliteral}{'nondim'}, default=0.3)
252   \textcolor{keyword}{call }get\_param(paramfile, mdl, \textcolor{stringliteral}{'VON\_KARMAN'}, cs%vonKarman, &
253                  \textcolor{stringliteral}{'von Karman constant.'},                     &
254                  units=\textcolor{stringliteral}{'nondim'}, default=0.40)
255   \textcolor{keyword}{call }get\_param(paramfile, mdl, \textcolor{stringliteral}{'ENHANCE\_DIFFUSION'}, cs%enhance\_diffusion,              &
256                  \textcolor{stringliteral}{'If True, adds enhanced diffusion at the based of the boundary layer.'}, &
257                  default=.true.)
258   \textcolor{keyword}{call }get\_param(paramfile, mdl, \textcolor{stringliteral}{'INTERP\_TYPE'}, cs%interpType,           &
259                  \textcolor{stringliteral}{'Type of interpolation to determine the OBL depth.\(\backslash\)n'}// &
260                  \textcolor{stringliteral}{'Allowed types are: linear, quadratic, cubic.'},         &
261                  default=\textcolor{stringliteral}{'quadratic'})
262   \textcolor{keyword}{call }get\_param(paramfile, mdl, \textcolor{stringliteral}{'INTERP\_TYPE2'}, cs%interpType2,           &
263                  \textcolor{stringliteral}{'Type of interpolation to compute diff and visc at OBL\_depth.\(\backslash\)n'}// &
264                  \textcolor{stringliteral}{'Allowed types are: linear, quadratic, cubic or LMD94.'},         &
265                  default=\textcolor{stringliteral}{'LMD94'})
266   \textcolor{keyword}{call }get\_param(paramfile, mdl, \textcolor{stringliteral}{'COMPUTE\_EKMAN'}, cs%computeEkman,             &
267                  \textcolor{stringliteral}{'If True, limit OBL depth to be no deeper than Ekman depth.'}, &
268                  default=.false.)
269   \textcolor{keyword}{call }get\_param(paramfile, mdl, \textcolor{stringliteral}{'COMPUTE\_MONIN\_OBUKHOV'}, cs%computeMoninObukhov, &
270                  \textcolor{stringliteral}{'If True, limit the OBL depth to be no deeper than '}//          &
271                  \textcolor{stringliteral}{'Monin-Obukhov depth.'},                                          &
272                  default=.false.)
273   \textcolor{keyword}{call }get\_param(paramfile, mdl, \textcolor{stringliteral}{'CS'}, cs%cs,                        &
274                  \textcolor{stringliteral}{'Parameter for computing velocity scale function.'}, &
275                  units=\textcolor{stringliteral}{'nondim'}, default=98.96)
276   \textcolor{keyword}{call }get\_param(paramfile, mdl, \textcolor{stringliteral}{'CS2'}, cs%cs2,                        &
277                  \textcolor{stringliteral}{'Parameter for computing non-local term.'}, &
278                  units=\textcolor{stringliteral}{'nondim'}, default=6.32739901508)
279   \textcolor{keyword}{call }get\_param(paramfile, mdl, \textcolor{stringliteral}{'DEEP\_OBL\_OFFSET'}, cs%deepOBLoffset,                             &
280                  \textcolor{stringliteral}{'If non-zero, the distance above the bottom to which the OBL is clipped '}//     &
281                  \textcolor{stringliteral}{'if it would otherwise reach the bottom. The smaller of this and 0.1D is used.'}, &
282                  units=\textcolor{stringliteral}{'m'},default=0.)
283   \textcolor{keyword}{call }get\_param(paramfile, mdl, \textcolor{stringliteral}{'FIXED\_OBLDEPTH'}, cs%fixedOBLdepth,       &
284                  \textcolor{stringliteral}{'If True, fix the OBL depth to FIXED\_OBLDEPTH\_VALUE '}//  &
285                  \textcolor{stringliteral}{'rather than using the OBL depth from CVMix. '}//         &
286                  \textcolor{stringliteral}{'This option is just for testing purposes.'},              &
287                  default=.false.)
288   \textcolor{keyword}{call }get\_param(paramfile, mdl, \textcolor{stringliteral}{'FIXED\_OBLDEPTH\_VALUE'}, cs%fixedOBLdepth\_value,  &
289                  \textcolor{stringliteral}{'Value for the fixed OBL depth when fixedOBLdepth==True. '}//   &
290                  \textcolor{stringliteral}{'This parameter is for just for testing purposes. '}//          &
291                  \textcolor{stringliteral}{'It will over-ride the OBLdepth computed from CVMix.'},           &
292                  units=\textcolor{stringliteral}{'m'},default=30.0)
293   \textcolor{keyword}{call }get\_param(paramfile, mdl, \textcolor{stringliteral}{'SURF\_LAYER\_EXTENT'}, cs%surf\_layer\_ext,   &
294                  \textcolor{stringliteral}{'Fraction of OBL depth considered in the surface layer.'}, &
295                  units=\textcolor{stringliteral}{'nondim'},default=0.10)
296   \textcolor{keyword}{call }get\_param(paramfile, mdl, \textcolor{stringliteral}{'MINIMUM\_OBL\_DEPTH'}, cs%minOBLdepth,                            &
297                  \textcolor{stringliteral}{'If non-zero, a minimum depth to use for KPP OBL depth. Independent of '}//     &
298                  \textcolor{stringliteral}{'this parameter, the OBL depth is always at least as deep as the first layer.'}, &
299                  units=\textcolor{stringliteral}{'m'},default=0.)
300   \textcolor{keyword}{call }get\_param(paramfile, mdl, \textcolor{stringliteral}{'MINIMUM\_VT2'}, cs%minVtsqr,                                   &
301                  \textcolor{stringliteral}{'Min of the unresolved velocity Vt2 used in Rib CVMix calculation.\(\backslash\)n'}//  &
302                  \textcolor{stringliteral}{'Scaling: MINIMUM\_VT2 = const1*d*N*ws, with d=1m, N=1e-5/s, ws=1e-6 m/s.'},    &
303                  units=\textcolor{stringliteral}{'m2/s2'},default=1e-10)
304 
305 \textcolor{comment}{! smg: for removal below}
306   \textcolor{keyword}{call }get\_param(paramfile, mdl, \textcolor{stringliteral}{'CORRECT\_SURFACE\_LAYER\_AVERAGE'}, cs%correctSurfLayerAvg,   &
307                  \textcolor{stringliteral}{'If true, applies a correction step to the averaging of surface layer '}// &
308                  \textcolor{stringliteral}{'properties. This option is obsolete.'}, default=.false.)
309   \textcolor{keywordflow}{if} (cs%correctSurfLayerAvg) &
310     \textcolor{keyword}{call }mom\_error(fatal,\textcolor{stringliteral}{'Correct surface layer average disabled in code.  To recover \(\backslash\)n'}// &
311                        \textcolor{stringliteral}{' feature will require code intervention.'})
312   \textcolor{keyword}{call }get\_param(paramfile, mdl, \textcolor{stringliteral}{'FIRST\_GUESS\_SURFACE\_LAYER\_DEPTH'}, cs%surfLayerDepth,              &
313                  \textcolor{stringliteral}{'The first guess at the depth of the surface layer used for averaging '}//         &
314                  \textcolor{stringliteral}{'the surface layer properties. If =0, the top model level properties '}//          &
315                  \textcolor{stringliteral}{'will be used for the surface layer. If CORRECT\_SURFACE\_LAYER\_AVERAGE=True, a '}// &
316                  \textcolor{stringliteral}{'subsequent correction is applied. This parameter is obsolete'}, units=\textcolor{stringliteral}{'m'}, default=0.)
317 \textcolor{comment}{! smg: for removal above}
318 
319   \textcolor{keyword}{call }get\_param(paramfile, mdl, \textcolor{stringliteral}{'NLT\_SHAPE'}, string, &
320                  \textcolor{stringliteral}{'MOM6 method to set nonlocal transport profile. '}//                          &
321                  \textcolor{stringliteral}{'Over-rides the result from CVMix.  Allowed values are: \(\backslash\)n'}//                 &
322                  \textcolor{stringliteral}{'\(\backslash\)t CVMix     - Uses the profiles from CVMix specified by MATCH\_TECHNIQUE\(\backslash\)n'}//&
323                  \textcolor{stringliteral}{'\(\backslash\)t LINEAR    - A linear profile, 1-sigma\(\backslash\)n'}//                                &
324                  \textcolor{stringliteral}{'\(\backslash\)t PARABOLIC - A parablic profile, (1-sigma)^2\(\backslash\)n'}//                          &
325                  \textcolor{stringliteral}{'\(\backslash\)t CUBIC     - A cubic profile, (1-sigma)^2(1+2*sigma)\(\backslash\)n'}//                  &
326                  \textcolor{stringliteral}{'\(\backslash\)t CUBIC\_LMD - The original KPP profile'},                                    &
327                  default=\textcolor{stringliteral}{'CVMix'})
328   \textcolor{keywordflow}{select case} ( trim(string) )
329     \textcolor{keywordflow}{case} (\textcolor{stringliteral}{"CVMix"})     ; cs%NLT\_shape = nlt\_shape\_cvmix
330     \textcolor{keywordflow}{case} (\textcolor{stringliteral}{"LINEAR"})    ; cs%NLT\_shape = nlt\_shape\_linear
331     \textcolor{keywordflow}{case} (\textcolor{stringliteral}{"PARABOLIC"}) ; cs%NLT\_shape = nlt\_shape\_parabolic
332     \textcolor{keywordflow}{case} (\textcolor{stringliteral}{"CUBIC"})     ; cs%NLT\_shape = nlt\_shape\_cubic
333     \textcolor{keywordflow}{case} (\textcolor{stringliteral}{"CUBIC\_LMD"}) ; cs%NLT\_shape = nlt\_shape\_cubic\_lmd
334 \textcolor{keywordflow}{    case default} ; \textcolor{keyword}{call }mom\_error(fatal,\textcolor{stringliteral}{"KPP\_init: "}// &
335                    \textcolor{stringliteral}{"Unrecognized NLT\_SHAPE option"}//trim(string))
336 \textcolor{keywordflow}{  end select}
337   \textcolor{keyword}{call }get\_param(paramfile, mdl, \textcolor{stringliteral}{'MATCH\_TECHNIQUE'}, cs%MatchTechnique,                                    &
338                  \textcolor{stringliteral}{'CVMix method to set profile function for diffusivity and NLT, '}//                      &
339                  \textcolor{stringliteral}{'as well as matching across OBL base. Allowed values are: \(\backslash\)n'}//                          &
340                  \textcolor{stringliteral}{'\(\backslash\)t SimpleShapes      = sigma*(1-sigma)^2 for both diffusivity and NLT\(\backslash\)n'}//              &
341                  \textcolor{stringliteral}{'\(\backslash\)t MatchGradient     = sigma*(1-sigma)^2 for NLT; diffusivity profile from matching\(\backslash\)n'}//&
342                  \textcolor{stringliteral}{'\(\backslash\)t MatchBoth         = match gradient for both diffusivity and NLT\(\backslash\)n'}//                 &
343                  \textcolor{stringliteral}{'\(\backslash\)t ParabolicNonLocal = sigma*(1-sigma)^2 for diffusivity; (1-sigma)^2 for NLT'},         &
344                  default=\textcolor{stringliteral}{'SimpleShapes'})
345   \textcolor{keywordflow}{if} (cs%MatchTechnique == \textcolor{stringliteral}{'ParabolicNonLocal'}) \textcolor{keywordflow}{then}
346     \textcolor{comment}{! This forces Cs2 (Cs in non-local computation) to equal 1 for parabolic non-local option.}
347     \textcolor{comment}{!  May be used during CVMix initialization.}
348     cs\_is\_one=.true.
349 \textcolor{keywordflow}{  endif}
350   \textcolor{keywordflow}{if} (cs%MatchTechnique == \textcolor{stringliteral}{'ParabolicNonLocal'} .or. cs%MatchTechnique == \textcolor{stringliteral}{'SimpleShapes'}) \textcolor{keywordflow}{then}
351     \textcolor{comment}{! if gradient won't be matched, lnoDGat1=.true.}
352     lnodgat1=.true.
353 \textcolor{keywordflow}{  endif}
354 
355   \textcolor{comment}{! safety check to avoid negative diff/visc}
356   \textcolor{keywordflow}{if} (cs%MatchTechnique == \textcolor{stringliteral}{'MatchBoth'} .and. (cs%interpType2 == \textcolor{stringliteral}{'cubic'} .or. &
357       cs%interpType2 == \textcolor{stringliteral}{'quadratic'})) \textcolor{keywordflow}{then}
358     \textcolor{keyword}{call }mom\_error(fatal,\textcolor{stringliteral}{"If MATCH\_TECHNIQUE=MatchBoth, INTERP\_TYPE2 must be set to \(\backslash\)n"}//&
359                \textcolor{stringliteral}{"linear or LMD94 (recommended) to avoid negative viscosity and diffusivity.\(\backslash\)n"}//&
360                \textcolor{stringliteral}{"Please select one of these valid options."} )
361 \textcolor{keywordflow}{  endif}
362 
363   \textcolor{keyword}{call }get\_param(paramfile, mdl, \textcolor{stringliteral}{'KPP\_ZERO\_DIFFUSIVITY'}, cs%KPPzeroDiffusivity,            &
364                  \textcolor{stringliteral}{'If True, zeroes the KPP diffusivity and viscosity; for testing purpose.'},&
365                  default=.false.)
366   \textcolor{keyword}{call }get\_param(paramfile, mdl, \textcolor{stringliteral}{'KPP\_IS\_ADDITIVE'}, cs%KPPisAdditive,                &
367                  \textcolor{stringliteral}{'If true, adds KPP diffusivity to diffusivity from other schemes.\(\backslash\)n'}//&
368                  \textcolor{stringliteral}{'If false, KPP is the only diffusivity wherever KPP is non-zero.'},  &
369                  default=.true.)
370   \textcolor{keyword}{call }get\_param(paramfile, mdl, \textcolor{stringliteral}{'KPP\_SHORTWAVE\_METHOD'},string,                      &
371                  \textcolor{stringliteral}{'Determines contribution of shortwave radiation to KPP surface '}// &
372                  \textcolor{stringliteral}{'buoyancy flux.  Options include:\(\backslash\)n'}//                             &
373                  \textcolor{stringliteral}{'  ALL\_SW: use total shortwave radiation\(\backslash\)n'}//                      &
374                  \textcolor{stringliteral}{'  MXL\_SW: use shortwave radiation absorbed by mixing layer\(\backslash\)n'}//  &
375                  \textcolor{stringliteral}{'  LV1\_SW: use shortwave radiation absorbed by top model layer'},  &
376                  default=\textcolor{stringliteral}{'MXL\_SW'})
377   \textcolor{keywordflow}{select case} ( trim(string) )
378     \textcolor{keywordflow}{case} (\textcolor{stringliteral}{"ALL\_SW"}) ; cs%SW\_METHOD = sw\_method\_all\_sw
379     \textcolor{keywordflow}{case} (\textcolor{stringliteral}{"MXL\_SW"}) ; cs%SW\_METHOD = sw\_method\_mxl\_sw
380     \textcolor{keywordflow}{case} (\textcolor{stringliteral}{"LV1\_SW"}) ; cs%SW\_METHOD = sw\_method\_lv1\_sw
381 \textcolor{keywordflow}{    case default} ; \textcolor{keyword}{call }mom\_error(fatal,\textcolor{stringliteral}{"KPP\_init: "}// &
382                    \textcolor{stringliteral}{"Unrecognized KPP\_SHORTWAVE\_METHOD option"}//trim(string))
383 \textcolor{keywordflow}{  end select}
384   \textcolor{keyword}{call }get\_param(paramfile, mdl, \textcolor{stringliteral}{'CVMix\_ZERO\_H\_WORK\_AROUND'}, cs%min\_thickness,                           &
385                  \textcolor{stringliteral}{'A minimum thickness used to avoid division by small numbers in the vicinity '}//       &
386                  \textcolor{stringliteral}{'of vanished layers. This is independent of MIN\_THICKNESS used in other parts of MOM.'}, &
387                  units=\textcolor{stringliteral}{'m'}, default=0.)
388 
389 \textcolor{comment}{!/BGR: New options for including Langmuir effects}
390 \textcolor{comment}{!/ 1. Options related to enhancing the mixing coefficient}
391   \textcolor{keyword}{call }get\_param(paramfile, mdl, \textcolor{stringliteral}{"USE\_KPP\_LT\_K"}, cs%LT\_K\_Enhancement, &
392        \textcolor{stringliteral}{'Flag for Langmuir turbulence enhancement of turbulent'}//&
393        \textcolor{stringliteral}{'mixing coefficient.'}, units=\textcolor{stringliteral}{""}, default=.false.)
394   \textcolor{keyword}{call }get\_param(paramfile, mdl, \textcolor{stringliteral}{"STOKES\_MIXING"}, cs%STOKES\_MIXING, &
395        \textcolor{stringliteral}{'Flag for Langmuir turbulence enhancement of turbulent'}//&
396        \textcolor{stringliteral}{'mixing coefficient.'}, units=\textcolor{stringliteral}{""}, default=.false.)
397   \textcolor{keywordflow}{if} (cs%LT\_K\_Enhancement) \textcolor{keywordflow}{then}
398     \textcolor{keyword}{call }get\_param(paramfile, mdl, \textcolor{stringliteral}{'KPP\_LT\_K\_SHAPE'}, string,                 &
399                  \textcolor{stringliteral}{'Vertical dependence of LT enhancement of mixing. '}//     &
400                  \textcolor{stringliteral}{'Valid options are: \(\backslash\)n'}//                                   &
401                  \textcolor{stringliteral}{'\(\backslash\)t CONSTANT = Constant value for full OBL\(\backslash\)n'}//             &
402                  \textcolor{stringliteral}{'\(\backslash\)t SCALED   = Varies based on normalized shape function.'}, &
403                  default=\textcolor{stringliteral}{'CONSTANT'})
404     \textcolor{keywordflow}{select case} ( trim(string))
405       \textcolor{keywordflow}{case} (\textcolor{stringliteral}{"CONSTANT"}) ; cs%LT\_K\_SHAPE = lt\_k\_constant
406       \textcolor{keywordflow}{case} (\textcolor{stringliteral}{"SCALED"})   ; cs%LT\_K\_SHAPE = lt\_k\_scaled
407 \textcolor{keywordflow}{      case default} ; \textcolor{keyword}{call }mom\_error(fatal,\textcolor{stringliteral}{"KPP\_init: "}//&
408                     \textcolor{stringliteral}{"Unrecognized KPP\_LT\_K\_SHAPE option: "}//trim(string))
409 \textcolor{keywordflow}{    end select}
410     \textcolor{keyword}{call }get\_param(paramfile, mdl, \textcolor{stringliteral}{"KPP\_LT\_K\_METHOD"}, string ,                   &
411                    \textcolor{stringliteral}{'Method to enhance mixing coefficient in KPP. '}//           &
412                    \textcolor{stringliteral}{'Valid options are: \(\backslash\)n'}//                                     &
413                    \textcolor{stringliteral}{'\(\backslash\)t CONSTANT = Constant value (KPP\_K\_ENH\_FAC) \(\backslash\)n'}//           &
414                    \textcolor{stringliteral}{'\(\backslash\)t VR12     = Function of Langmuir number based on VR12\(\backslash\)n'}// &
415                    \textcolor{stringliteral}{'\(\backslash\)t RW16     = Function of Langmuir number based on RW16'},    &
416                    default=\textcolor{stringliteral}{'CONSTANT'})
417     \textcolor{keywordflow}{select case} ( trim(string))
418       \textcolor{keywordflow}{case} (\textcolor{stringliteral}{"CONSTANT"}) ; cs%LT\_K\_METHOD = lt\_k\_mode\_constant
419       \textcolor{keywordflow}{case} (\textcolor{stringliteral}{"VR12"})     ; cs%LT\_K\_METHOD = lt\_k\_mode\_vr12
420       \textcolor{keywordflow}{case} (\textcolor{stringliteral}{"RW16"})     ; cs%LT\_K\_METHOD = lt\_k\_mode\_rw16
421 \textcolor{keywordflow}{      case default}      ; \textcolor{keyword}{call }mom\_error(fatal,\textcolor{stringliteral}{"KPP\_init: "}//&
422                     \textcolor{stringliteral}{"Unrecognized KPP\_LT\_K\_METHOD option: "}//trim(string))
423 \textcolor{keywordflow}{    end select}
424     \textcolor{keywordflow}{if} (cs%LT\_K\_METHOD==lt\_k\_mode\_constant) \textcolor{keywordflow}{then}
425       \textcolor{keyword}{call }get\_param(paramfile, mdl, \textcolor{stringliteral}{"KPP\_K\_ENH\_FAC"},cs%KPP\_K\_ENH\_FAC ,     &
426                    \textcolor{stringliteral}{'Constant value to enhance mixing coefficient in KPP.'},  &
427                    default=1.0)
428 \textcolor{keywordflow}{    endif}
429 \textcolor{keywordflow}{  endif}
430 \textcolor{comment}{!/ 2. Options related to enhancing the unresolved Vt2/entrainment in Rib}
431   \textcolor{keyword}{call }get\_param(paramfile, mdl, \textcolor{stringliteral}{"USE\_KPP\_LT\_VT2"}, cs%LT\_Vt2\_Enhancement, &
432        \textcolor{stringliteral}{'Flag for Langmuir turbulence enhancement of Vt2'}//&
433        \textcolor{stringliteral}{'in Bulk Richardson Number.'}, units=\textcolor{stringliteral}{""}, default=.false.)
434   \textcolor{keywordflow}{if} (cs%LT\_Vt2\_Enhancement) \textcolor{keywordflow}{then}
435     \textcolor{keyword}{call }get\_param(paramfile, mdl, \textcolor{stringliteral}{"KPP\_LT\_VT2\_METHOD"},string ,                  &
436                    \textcolor{stringliteral}{'Method to enhance Vt2 in KPP. '}//                          &
437                    \textcolor{stringliteral}{'Valid options are: \(\backslash\)n'}//                                     &
438                    \textcolor{stringliteral}{'\(\backslash\)t CONSTANT = Constant value (KPP\_VT2\_ENH\_FAC) \(\backslash\)n'}//         &
439                    \textcolor{stringliteral}{'\(\backslash\)t VR12     = Function of Langmuir number based on VR12\(\backslash\)n'}// &
440                    \textcolor{stringliteral}{'\(\backslash\)t RW16     = Function of Langmuir number based on RW16\(\backslash\)n'}// &
441                    \textcolor{stringliteral}{'\(\backslash\)t LF17     = Function of Langmuir number based on LF17'},    &
442                    default=\textcolor{stringliteral}{'CONSTANT'})
443     \textcolor{keywordflow}{select case} ( trim(string))
444       \textcolor{keywordflow}{case} (\textcolor{stringliteral}{"CONSTANT"}) ; cs%LT\_VT2\_METHOD = lt\_vt2\_mode\_constant
445       \textcolor{keywordflow}{case} (\textcolor{stringliteral}{"VR12"})     ; cs%LT\_VT2\_METHOD = lt\_vt2\_mode\_vr12
446       \textcolor{keywordflow}{case} (\textcolor{stringliteral}{"RW16"})     ; cs%LT\_VT2\_METHOD = lt\_vt2\_mode\_rw16
447       \textcolor{keywordflow}{case} (\textcolor{stringliteral}{"LF17"})     ; cs%LT\_VT2\_METHOD = lt\_vt2\_mode\_lf17
448 \textcolor{keywordflow}{      case default}      ; \textcolor{keyword}{call }mom\_error(fatal,\textcolor{stringliteral}{"KPP\_init: "}//&
449                     \textcolor{stringliteral}{"Unrecognized KPP\_LT\_VT2\_METHOD option: "}//trim(string))
450 \textcolor{keywordflow}{    end select}
451     \textcolor{keywordflow}{if} (cs%LT\_VT2\_METHOD==lt\_vt2\_mode\_constant) \textcolor{keywordflow}{then}
452       \textcolor{keyword}{call }get\_param(paramfile, mdl, \textcolor{stringliteral}{"KPP\_VT2\_ENH\_FAC"},cs%KPP\_VT2\_ENH\_FAC ,     &
453                    \textcolor{stringliteral}{'Constant value to enhance VT2 in KPP.'},  &
454                    default=1.0)
455 \textcolor{keywordflow}{    endif}
456 \textcolor{keywordflow}{  endif}
457 
458   \textcolor{keyword}{call }closeparameterblock(paramfile)
459   \textcolor{keyword}{call }get\_param(paramfile, mdl, \textcolor{stringliteral}{'DEBUG'}, cs%debug, default=.false., do\_not\_log=.true.)
460 
461   \textcolor{keyword}{call }cvmix\_init\_kpp( ri\_crit=cs%Ri\_crit,                 &
462                        minobldepth=cs%minOBLdepth,         &
463                        minvtsqr=cs%minVtsqr,               &
464                        vonkarman=cs%vonKarman,             &
465                        surf\_layer\_ext=cs%surf\_layer\_ext,   &
466                        interp\_type=cs%interpType,          &
467                        interp\_type2=cs%interpType2,        &
468                        lekman=cs%computeEkman,             &
469                        lmonob=cs%computeMoninObukhov,      &
470                        matchtechnique=cs%MatchTechnique,   &
471                        lenhanced\_diff=cs%enhance\_diffusion,&
472                        lnonzero\_surf\_nonlocal=cs\_is\_one   ,&
473                        lnodgat1=lnodgat1                  ,&
474                        cvmix\_kpp\_params\_user=cs%KPP\_params )
475 
476   \textcolor{comment}{! Register diagnostics}
477   cs%diag => diag
478   cs%id\_OBLdepth = register\_diag\_field(\textcolor{stringliteral}{'ocean\_model'}, \textcolor{stringliteral}{'KPP\_OBLdepth'}, diag%axesT1, time, &
479       \textcolor{stringliteral}{'Thickness of the surface Ocean Boundary Layer calculated by [CVMix] KPP'}, \textcolor{stringliteral}{'meter'}, &
480       cmor\_field\_name=\textcolor{stringliteral}{'oml'}, cmor\_long\_name=\textcolor{stringliteral}{'ocean\_mixed\_layer\_thickness\_defined\_by\_mixing\_scheme'}, &
481       cmor\_units=\textcolor{stringliteral}{'m'}, cmor\_standard\_name=\textcolor{stringliteral}{'Ocean Mixed Layer Thickness Defined by Mixing Scheme'})
482       \textcolor{comment}{! CMOR names are placeholders; must be modified by time period}
483       \textcolor{comment}{! for CMOR compliance. Diag manager will be used for omlmax and}
484       \textcolor{comment}{! omldamax.}
485   \textcolor{keywordflow}{if} (cs%n\_smooth > 0) \textcolor{keywordflow}{then}
486     cs%id\_OBLdepth\_original = register\_diag\_field(\textcolor{stringliteral}{'ocean\_model'}, \textcolor{stringliteral}{'KPP\_OBLdepth\_original'}, diag%axesT1, time
      , &
487         \textcolor{stringliteral}{'Thickness of the surface Ocean Boundary Layer without smoothing calculated by [CVMix] KPP'}, \textcolor{stringliteral}{
      'meter'}, &
488         cmor\_field\_name=\textcolor{stringliteral}{'oml'}, cmor\_long\_name=\textcolor{stringliteral}{'ocean\_mixed\_layer\_thickness\_defined\_by\_mixing\_scheme'}, &
489         cmor\_units=\textcolor{stringliteral}{'m'}, cmor\_standard\_name=\textcolor{stringliteral}{'Ocean Mixed Layer Thickness Defined by Mixing Scheme'})
490 \textcolor{keywordflow}{  endif}
491   cs%id\_BulkDrho = register\_diag\_field(\textcolor{stringliteral}{'ocean\_model'}, \textcolor{stringliteral}{'KPP\_BulkDrho'}, diag%axesTL, time, &
492       \textcolor{stringliteral}{'Bulk difference in density used in Bulk Richardson number, as used by [CVMix] KPP'}, &
493       \textcolor{stringliteral}{'kg/m3'}, conversion=us%R\_to\_kg\_m3)
494   cs%id\_BulkUz2 = register\_diag\_field(\textcolor{stringliteral}{'ocean\_model'}, \textcolor{stringliteral}{'KPP\_BulkUz2'}, diag%axesTL, time, &
495       \textcolor{stringliteral}{'Square of bulk difference in resolved velocity used in Bulk Richardson number via [CVMix] KPP'}, \textcolor{stringliteral}{
      'm2/s2'})
496   cs%id\_BulkRi = register\_diag\_field(\textcolor{stringliteral}{'ocean\_model'}, \textcolor{stringliteral}{'KPP\_BulkRi'}, diag%axesTL, time, &
497       \textcolor{stringliteral}{'Bulk Richardson number used to find the OBL depth used by [CVMix] KPP'}, \textcolor{stringliteral}{'nondim'})
498   cs%id\_Sigma = register\_diag\_field(\textcolor{stringliteral}{'ocean\_model'}, \textcolor{stringliteral}{'KPP\_sigma'}, diag%axesTi, time, &
499       \textcolor{stringliteral}{'Sigma coordinate used by [CVMix] KPP'}, \textcolor{stringliteral}{'nondim'})
500   cs%id\_Ws = register\_diag\_field(\textcolor{stringliteral}{'ocean\_model'}, \textcolor{stringliteral}{'KPP\_Ws'}, diag%axesTL, time, &
501       \textcolor{stringliteral}{'Turbulent vertical velocity scale for scalars used by [CVMix] KPP'}, \textcolor{stringliteral}{'m/s'})
502   cs%id\_N = register\_diag\_field(\textcolor{stringliteral}{'ocean\_model'}, \textcolor{stringliteral}{'KPP\_N'}, diag%axesTi, time, &
503       \textcolor{stringliteral}{'(Adjusted) Brunt-Vaisala frequency used by [CVMix] KPP'}, \textcolor{stringliteral}{'1/s'})
504   cs%id\_N2 = register\_diag\_field(\textcolor{stringliteral}{'ocean\_model'}, \textcolor{stringliteral}{'KPP\_N2'}, diag%axesTi, time, &
505       \textcolor{stringliteral}{'Square of Brunt-Vaisala frequency used by [CVMix] KPP'}, \textcolor{stringliteral}{'1/s2'})
506   cs%id\_Vt2 = register\_diag\_field(\textcolor{stringliteral}{'ocean\_model'}, \textcolor{stringliteral}{'KPP\_Vt2'}, diag%axesTL, time, &
507       \textcolor{stringliteral}{'Unresolved shear turbulence used by [CVMix] KPP'}, \textcolor{stringliteral}{'m2/s2'})
508   cs%id\_uStar = register\_diag\_field(\textcolor{stringliteral}{'ocean\_model'}, \textcolor{stringliteral}{'KPP\_uStar'}, diag%axesT1, time, &
509       \textcolor{stringliteral}{'Friction velocity, u*, as used by [CVMix] KPP'}, \textcolor{stringliteral}{'m/s'}, conversion=us%Z\_to\_m*us%s\_to\_T)
510   cs%id\_buoyFlux = register\_diag\_field(\textcolor{stringliteral}{'ocean\_model'}, \textcolor{stringliteral}{'KPP\_buoyFlux'}, diag%axesTi, time, &
511       \textcolor{stringliteral}{'Surface (and penetrating) buoyancy flux, as used by [CVMix] KPP'}, \textcolor{stringliteral}{'m2/s3'}, conversion=us%L\_to\_m**2*
      us%s\_to\_T**3)
512   cs%id\_QminusSW = register\_diag\_field(\textcolor{stringliteral}{'ocean\_model'}, \textcolor{stringliteral}{'KPP\_QminusSW'}, diag%axesT1, time, &
513       \textcolor{stringliteral}{'Net temperature flux ignoring short-wave, as used by [CVMix] KPP'}, \textcolor{stringliteral}{'K m/s'})
514   cs%id\_netS = register\_diag\_field(\textcolor{stringliteral}{'ocean\_model'}, \textcolor{stringliteral}{'KPP\_netSalt'}, diag%axesT1, time, &
515       \textcolor{stringliteral}{'Effective net surface salt flux, as used by [CVMix] KPP'}, \textcolor{stringliteral}{'ppt m/s'})
516   cs%id\_Kt\_KPP = register\_diag\_field(\textcolor{stringliteral}{'ocean\_model'}, \textcolor{stringliteral}{'KPP\_Kheat'}, diag%axesTi, time, &
517       \textcolor{stringliteral}{'Heat diffusivity due to KPP, as calculated by [CVMix] KPP'}, \textcolor{stringliteral}{'m2/s'})
518   cs%id\_Kd\_in = register\_diag\_field(\textcolor{stringliteral}{'ocean\_model'}, \textcolor{stringliteral}{'KPP\_Kd\_in'}, diag%axesTi, time, &
519       \textcolor{stringliteral}{'Diffusivity passed to KPP'}, \textcolor{stringliteral}{'m2/s'}, conversion=us%Z2\_T\_to\_m2\_s)
520   cs%id\_Ks\_KPP = register\_diag\_field(\textcolor{stringliteral}{'ocean\_model'}, \textcolor{stringliteral}{'KPP\_Ksalt'}, diag%axesTi, time, &
521       \textcolor{stringliteral}{'Salt diffusivity due to KPP, as calculated by [CVMix] KPP'}, \textcolor{stringliteral}{'m2/s'})
522   cs%id\_Kv\_KPP = register\_diag\_field(\textcolor{stringliteral}{'ocean\_model'}, \textcolor{stringliteral}{'KPP\_Kv'}, diag%axesTi, time, &
523       \textcolor{stringliteral}{'Vertical viscosity due to KPP, as calculated by [CVMix] KPP'}, \textcolor{stringliteral}{'m2/s'})
524   cs%id\_NLTt = register\_diag\_field(\textcolor{stringliteral}{'ocean\_model'}, \textcolor{stringliteral}{'KPP\_NLtransport\_heat'}, diag%axesTi, time, &
525       \textcolor{stringliteral}{'Non-local transport (Cs*G(sigma)) for heat, as calculated by [CVMix] KPP'}, \textcolor{stringliteral}{'nondim'})
526   cs%id\_NLTs = register\_diag\_field(\textcolor{stringliteral}{'ocean\_model'}, \textcolor{stringliteral}{'KPP\_NLtransport\_salt'}, diag%axesTi, time, &
527       \textcolor{stringliteral}{'Non-local tranpsort (Cs*G(sigma)) for scalars, as calculated by [CVMix] KPP'}, \textcolor{stringliteral}{'nondim'})
528   cs%id\_NLT\_dTdt = register\_diag\_field(\textcolor{stringliteral}{'ocean\_model'}, \textcolor{stringliteral}{'KPP\_NLT\_dTdt'}, diag%axesTL, time, &
529       \textcolor{stringliteral}{'Temperature tendency due to non-local transport of heat, as calculated by [CVMix] KPP'}, \textcolor{stringliteral}{'K/s'})
530   cs%id\_NLT\_dSdt = register\_diag\_field(\textcolor{stringliteral}{'ocean\_model'}, \textcolor{stringliteral}{'KPP\_NLT\_dSdt'}, diag%axesTL, time, &
531       \textcolor{stringliteral}{'Salinity tendency due to non-local transport of salt, as calculated by [CVMix] KPP'}, \textcolor{stringliteral}{'ppt/s'})
532   cs%id\_NLT\_temp\_budget = register\_diag\_field(\textcolor{stringliteral}{'ocean\_model'}, \textcolor{stringliteral}{'KPP\_NLT\_temp\_budget'}, diag%axesTL, time, &
533       \textcolor{stringliteral}{'Heat content change due to non-local transport, as calculated by [CVMix] KPP'}, \textcolor{stringliteral}{'W/m^2'})
534   cs%id\_NLT\_saln\_budget = register\_diag\_field(\textcolor{stringliteral}{'ocean\_model'}, \textcolor{stringliteral}{'KPP\_NLT\_saln\_budget'}, diag%axesTL, time, &
535       \textcolor{stringliteral}{'Salt content change due to non-local transport, as calculated by [CVMix] KPP'}, \textcolor{stringliteral}{'kg/(sec*m^2)'})
536   cs%id\_Tsurf = register\_diag\_field(\textcolor{stringliteral}{'ocean\_model'}, \textcolor{stringliteral}{'KPP\_Tsurf'}, diag%axesT1, time, &
537       \textcolor{stringliteral}{'Temperature of surface layer (10% of OBL depth) as passed to [CVMix] KPP'}, \textcolor{stringliteral}{'C'})
538   cs%id\_Ssurf = register\_diag\_field(\textcolor{stringliteral}{'ocean\_model'}, \textcolor{stringliteral}{'KPP\_Ssurf'}, diag%axesT1, time, &
539       \textcolor{stringliteral}{'Salinity of surface layer (10% of OBL depth) as passed to [CVMix] KPP'}, \textcolor{stringliteral}{'ppt'})
540   cs%id\_Usurf = register\_diag\_field(\textcolor{stringliteral}{'ocean\_model'}, \textcolor{stringliteral}{'KPP\_Usurf'}, diag%axesCu1, time, &
541       \textcolor{stringliteral}{'i-component flow of surface layer (10% of OBL depth) as passed to [CVMix] KPP'}, \textcolor{stringliteral}{'m/s'})
542   cs%id\_Vsurf = register\_diag\_field(\textcolor{stringliteral}{'ocean\_model'}, \textcolor{stringliteral}{'KPP\_Vsurf'}, diag%axesCv1, time, &
543       \textcolor{stringliteral}{'j-component flow of surface layer (10% of OBL depth) as passed to [CVMix] KPP'}, \textcolor{stringliteral}{'m/s'})
544   cs%id\_EnhK = register\_diag\_field(\textcolor{stringliteral}{'ocean\_model'}, \textcolor{stringliteral}{'EnhK'}, diag%axesTI, time, &
545       \textcolor{stringliteral}{'Langmuir number enhancement to K as used by [CVMix] KPP'},\textcolor{stringliteral}{'nondim'})
546   cs%id\_EnhVt2 = register\_diag\_field(\textcolor{stringliteral}{'ocean\_model'}, \textcolor{stringliteral}{'EnhVt2'}, diag%axesTL, time, &
547       \textcolor{stringliteral}{'Langmuir number enhancement to Vt2 as used by [CVMix] KPP'},\textcolor{stringliteral}{'nondim'})
548   cs%id\_La\_SL = register\_diag\_field(\textcolor{stringliteral}{'ocean\_model'}, \textcolor{stringliteral}{'KPP\_La\_SL'}, diag%axesT1, time, &
549       \textcolor{stringliteral}{'Surface-layer Langmuir number computed in [CVMix] KPP'},\textcolor{stringliteral}{'nondim'})
550 
551   \textcolor{keyword}{allocate}( cs%N( szi\_(g), szj\_(g), szk\_(g)+1 ) )
552   cs%N(:,:,:) = 0.
553   \textcolor{keyword}{allocate}( cs%OBLdepth( szi\_(g), szj\_(g) ) )
554   cs%OBLdepth(:,:) = 0.
555   \textcolor{keyword}{allocate}( cs%kOBL( szi\_(g), szj\_(g) ) )
556   cs%kOBL(:,:) = 0.
557   \textcolor{keyword}{allocate}( cs%La\_SL( szi\_(g), szj\_(g) ) )
558   cs%La\_SL(:,:) = 0.
559   \textcolor{keyword}{allocate}( cs%Vt2( szi\_(g), szj\_(g), szk\_(g) ) )
560   cs%Vt2(:,:,:) = 0.
561   \textcolor{keywordflow}{if} (cs%id\_OBLdepth\_original > 0) \textcolor{keyword}{allocate}( cs%OBLdepth\_original( szi\_(g), szj\_(g) ) )
562 
563   \textcolor{keyword}{allocate}( cs%OBLdepthprev( szi\_(g), szj\_(g) ) ) ; cs%OBLdepthprev(:,:) = 0.0
564   \textcolor{keywordflow}{if} (cs%id\_BulkDrho > 0) \textcolor{keyword}{allocate}( cs%dRho( szi\_(g), szj\_(g), szk\_(g) ) )
565   \textcolor{keywordflow}{if} (cs%id\_BulkDrho > 0) cs%dRho(:,:,:) = 0.
566   \textcolor{keywordflow}{if} (cs%id\_BulkUz2 > 0)  \textcolor{keyword}{allocate}( cs%Uz2( szi\_(g), szj\_(g), szk\_(g) ) )
567   \textcolor{keywordflow}{if} (cs%id\_BulkUz2 > 0)  cs%Uz2(:,:,:) = 0.
568   \textcolor{keywordflow}{if} (cs%id\_BulkRi > 0)   \textcolor{keyword}{allocate}( cs%BulkRi( szi\_(g), szj\_(g), szk\_(g) ) )
569   \textcolor{keywordflow}{if} (cs%id\_BulkRi > 0)   cs%BulkRi(:,:,:) = 0.
570   \textcolor{keywordflow}{if} (cs%id\_Sigma > 0)    \textcolor{keyword}{allocate}( cs%sigma( szi\_(g), szj\_(g), szk\_(g)+1 ) )
571   \textcolor{keywordflow}{if} (cs%id\_Sigma > 0)    cs%sigma(:,:,:) = 0.
572   \textcolor{keywordflow}{if} (cs%id\_Ws > 0)       \textcolor{keyword}{allocate}( cs%Ws( szi\_(g), szj\_(g), szk\_(g) ) )
573   \textcolor{keywordflow}{if} (cs%id\_Ws > 0)       cs%Ws(:,:,:) = 0.
574   \textcolor{keywordflow}{if} (cs%id\_N2 > 0)       \textcolor{keyword}{allocate}( cs%N2( szi\_(g), szj\_(g), szk\_(g)+1 ) )
575   \textcolor{keywordflow}{if} (cs%id\_N2 > 0)       cs%N2(:,:,:) = 0.
576   \textcolor{keywordflow}{if} (cs%id\_Kt\_KPP > 0)   \textcolor{keyword}{allocate}( cs%Kt\_KPP( szi\_(g), szj\_(g), szk\_(g)+1 ) )
577   \textcolor{keywordflow}{if} (cs%id\_Kt\_KPP > 0)   cs%Kt\_KPP(:,:,:) = 0.
578   \textcolor{keywordflow}{if} (cs%id\_Ks\_KPP > 0)   \textcolor{keyword}{allocate}( cs%Ks\_KPP( szi\_(g), szj\_(g), szk\_(g)+1 ) )
579   \textcolor{keywordflow}{if} (cs%id\_Ks\_KPP > 0)   cs%Ks\_KPP(:,:,:) = 0.
580   \textcolor{keywordflow}{if} (cs%id\_Kv\_KPP > 0)   \textcolor{keyword}{allocate}( cs%Kv\_KPP( szi\_(g), szj\_(g), szk\_(g)+1 ) )
581   \textcolor{keywordflow}{if} (cs%id\_Kv\_KPP > 0)   cs%Kv\_KPP(:,:,:) = 0.
582   \textcolor{keywordflow}{if} (cs%id\_Tsurf > 0)    \textcolor{keyword}{allocate}( cs%Tsurf( szi\_(g), szj\_(g)) )
583   \textcolor{keywordflow}{if} (cs%id\_Tsurf > 0)    cs%Tsurf(:,:) = 0.
584   \textcolor{keywordflow}{if} (cs%id\_Ssurf > 0)    \textcolor{keyword}{allocate}( cs%Ssurf( szi\_(g), szj\_(g)) )
585   \textcolor{keywordflow}{if} (cs%id\_Ssurf > 0)    cs%Ssurf(:,:) = 0.
586   \textcolor{keywordflow}{if} (cs%id\_Usurf > 0)    \textcolor{keyword}{allocate}( cs%Usurf( szib\_(g), szj\_(g)) )
587   \textcolor{keywordflow}{if} (cs%id\_Usurf > 0)    cs%Usurf(:,:) = 0.
588   \textcolor{keywordflow}{if} (cs%id\_Vsurf > 0)    \textcolor{keyword}{allocate}( cs%Vsurf( szi\_(g), szjb\_(g)) )
589   \textcolor{keywordflow}{if} (cs%id\_Vsurf > 0)    cs%Vsurf(:,:) = 0.
590   \textcolor{keywordflow}{if} (cs%id\_EnhVt2 > 0)    \textcolor{keyword}{allocate}( cs%EnhVt2( szi\_(g), szj\_(g), szk\_(g)) )
591   \textcolor{keywordflow}{if} (cs%id\_EnhVt2 > 0)    cs%EnhVt2(:,:,:) = 0.
592   \textcolor{keywordflow}{if} (cs%id\_EnhK > 0)    \textcolor{keyword}{allocate}( cs%EnhK( szi\_(g), szj\_(g), szk\_(g)+1 ) )
593   \textcolor{keywordflow}{if} (cs%id\_EnhK > 0)    cs%EnhK(:,:,:) = 0.
594 
595   id\_clock\_kpp\_calc = cpu\_clock\_id(\textcolor{stringliteral}{'Ocean KPP calculate)'}, grain=clock\_module)
596   id\_clock\_kpp\_compute\_bld = cpu\_clock\_id(\textcolor{stringliteral}{'(Ocean KPP comp BLD)'}, grain=clock\_routine)
597 
\end{DoxyCode}
\mbox{\Hypertarget{namespacemom__cvmix__kpp_abebacc1ae8c13149d816a60ff2e824b6}\label{namespacemom__cvmix__kpp_abebacc1ae8c13149d816a60ff2e824b6}} 
\index{mom\+\_\+cvmix\+\_\+kpp@{mom\+\_\+cvmix\+\_\+kpp}!kpp\+\_\+nonlocaltransport\+\_\+saln@{kpp\+\_\+nonlocaltransport\+\_\+saln}}
\index{kpp\+\_\+nonlocaltransport\+\_\+saln@{kpp\+\_\+nonlocaltransport\+\_\+saln}!mom\+\_\+cvmix\+\_\+kpp@{mom\+\_\+cvmix\+\_\+kpp}}
\subsubsection{\texorpdfstring{kpp\+\_\+nonlocaltransport\+\_\+saln()}{kpp\_nonlocaltransport\_saln()}}
{\footnotesize\ttfamily subroutine, public mom\+\_\+cvmix\+\_\+kpp\+::kpp\+\_\+nonlocaltransport\+\_\+saln (\begin{DoxyParamCaption}\item[{type(\hyperlink{structmom__cvmix__kpp_1_1kpp__cs}{kpp\+\_\+cs}), intent(in)}]{CS,  }\item[{type(ocean\+\_\+grid\+\_\+type), intent(in)}]{G,  }\item[{type(verticalgrid\+\_\+type), intent(in)}]{GV,  }\item[{real, dimension( g \%isd\+: g \%ied, g \%jsd\+: g \%jed, g \%ke), intent(in)}]{h,  }\item[{real, dimension( g \%isd\+: g \%ied, g \%jsd\+: g \%jed, g \%ke+1), intent(in)}]{non\+Local\+Trans,  }\item[{real, dimension( g \%isd\+: g \%ied, g \%jsd\+: g \%jed), intent(in)}]{surf\+Flux,  }\item[{real, intent(in)}]{dt,  }\item[{real, dimension( g \%isd\+: g \%ied, g \%jsd\+: g \%jed, g \%ke), intent(inout)}]{scalar }\end{DoxyParamCaption})}



Apply K\+PP non-\/local transport of surface fluxes for salinity. This routine is a useful prototype for other material tracers. 


\begin{DoxyParams}[1]{Parameters}
\mbox{\tt in}  & {\em cs} & Control structure\\
\hline
\mbox{\tt in}  & {\em g} & Ocean grid\\
\hline
\mbox{\tt in}  & {\em gv} & Ocean vertical grid\\
\hline
\mbox{\tt in}  & {\em h} & Layer/level thickness \mbox{[}H $\sim$$>$ m or kg m-\/2\mbox{]}\\
\hline
\mbox{\tt in}  & {\em nonlocaltrans} & Non-\/local transport \mbox{[}nondim\mbox{]}\\
\hline
\mbox{\tt in}  & {\em surfflux} & Surface flux of scalar \mbox{[}conc H s-\/1 $\sim$$>$ conc m s-\/1 or conc kg m-\/2 s-\/1\mbox{]}\\
\hline
\mbox{\tt in}  & {\em dt} & Time-\/step \mbox{[}s\mbox{]}\\
\hline
\mbox{\tt in,out}  & {\em scalar} & Scalar (scalar units \mbox{[}conc\mbox{]}) \\
\hline
\end{DoxyParams}


Definition at line 1452 of file M\+O\+M\+\_\+\+C\+V\+Mix\+\_\+\+K\+P\+P.\+F90.


\begin{DoxyCode}
1452 
1453   \textcolor{keywordtype}{type}(kpp\_cs),                               \textcolor{keywordtype}{intent(in)}    :: cs\textcolor{comment}{            !< Control structure}
1454   \textcolor{keywordtype}{type}(ocean\_grid\_type),                      \textcolor{keywordtype}{intent(in)}    :: g\textcolor{comment}{             !< Ocean grid}
1455   \textcolor{keywordtype}{type}(verticalgrid\_type),                    \textcolor{keywordtype}{intent(in)}    :: gv\textcolor{comment}{            !< Ocean vertical grid}
1456   \textcolor{keywordtype}{real}, \textcolor{keywordtype}{dimension(SZI\_(G),SZJ\_(G),SZK\_(G))},   \textcolor{keywordtype}{intent(in)}    :: h\textcolor{comment}{             !< Layer/level thickness [H ~>
       m or kg m-2]}
1457   \textcolor{keywordtype}{real}, \textcolor{keywordtype}{dimension(SZI\_(G),SZJ\_(G),SZK\_(G)+1)}, \textcolor{keywordtype}{intent(in)}    :: nonlocaltrans\textcolor{comment}{ !< Non-local transport
       [nondim]}
1458   \textcolor{keywordtype}{real}, \textcolor{keywordtype}{dimension(SZI\_(G),SZJ\_(G))},           \textcolor{keywordtype}{intent(in)}    :: surfflux\textcolor{comment}{      !< Surface flux of scalar}
1459 \textcolor{comment}{                                                                        !! [conc H s-1 ~> conc m s-1 or
       conc kg m-2 s-1]}
1460   \textcolor{keywordtype}{real},                                       \textcolor{keywordtype}{intent(in)}    :: dt\textcolor{comment}{            !< Time-step [s]}
1461   \textcolor{keywordtype}{real}, \textcolor{keywordtype}{dimension(SZI\_(G),SZJ\_(G),SZK\_(G))},   \textcolor{keywordtype}{intent(inout)} :: scalar\textcolor{comment}{        !< Scalar (scalar units
       [conc])}
1462 
1463   \textcolor{keywordtype}{integer} :: i, j, k
1464   \textcolor{keywordtype}{real}, \textcolor{keywordtype}{dimension( SZI\_(G), SZJ\_(G), SZK\_(G) )} :: dtracer
1465 
1466 
1467   dtracer(:,:,:) = 0.0
1468   \textcolor{comment}{!$OMP parallel do default(none) shared(dtracer, nonLocalTrans, h, G, GV, surfFlux)}
1469   \textcolor{keywordflow}{do} k = 1, g%ke
1470     \textcolor{keywordflow}{do} j = g%jsc, g%jec
1471       \textcolor{keywordflow}{do} i = g%isc, g%iec
1472         dtracer(i,j,k) = ( nonlocaltrans(i,j,k) - nonlocaltrans(i,j,k+1) ) / &
1473                          ( h(i,j,k) + gv%H\_subroundoff ) * surfflux(i,j)
1474 \textcolor{keywordflow}{      enddo}
1475 \textcolor{keywordflow}{    enddo}
1476 \textcolor{keywordflow}{  enddo}
1477 
1478   \textcolor{comment}{!  Update tracer due to non-local redistribution of surface flux}
1479   \textcolor{keywordflow}{if} (cs%applyNonLocalTrans) \textcolor{keywordflow}{then}
1480     \textcolor{comment}{!$OMP parallel do default(none) shared(G, dt, scalar, dtracer)}
1481     \textcolor{keywordflow}{do} k = 1, g%ke
1482       \textcolor{keywordflow}{do} j = g%jsc, g%jec
1483         \textcolor{keywordflow}{do} i = g%isc, g%iec
1484           scalar(i,j,k) = scalar(i,j,k) + dt * dtracer(i,j,k)
1485 \textcolor{keywordflow}{        enddo}
1486 \textcolor{keywordflow}{      enddo}
1487 \textcolor{keywordflow}{    enddo}
1488 \textcolor{keywordflow}{  endif}
1489 
1490   \textcolor{comment}{! Diagnostics}
1491   \textcolor{keywordflow}{if} (cs%id\_netS            > 0) \textcolor{keyword}{call }post\_data(cs%id\_netS,     surfflux, cs%diag)
1492   \textcolor{keywordflow}{if} (cs%id\_NLT\_dSdt        > 0) \textcolor{keyword}{call }post\_data(cs%id\_NLT\_dSdt, dtracer,  cs%diag)
1493   \textcolor{keywordflow}{if} (cs%id\_NLT\_saln\_budget > 0) \textcolor{keywordflow}{then}
1494     dtracer(:,:,:) = 0.0
1495     \textcolor{comment}{!$OMP parallel do default(none) shared(G, GV, dtracer, nonLocalTrans, surfFlux)}
1496     \textcolor{keywordflow}{do} k = 1, g%ke
1497       \textcolor{keywordflow}{do} j = g%jsc, g%jec
1498         \textcolor{keywordflow}{do} i = g%isc, g%iec
1499           dtracer(i,j,k) = (nonlocaltrans(i,j,k) - nonlocaltrans(i,j,k+1)) * &
1500                            surfflux(i,j) * gv%H\_to\_kg\_m2
1501 \textcolor{keywordflow}{        enddo}
1502 \textcolor{keywordflow}{      enddo}
1503 \textcolor{keywordflow}{    enddo}
1504     \textcolor{keyword}{call }post\_data(cs%id\_NLT\_saln\_budget, dtracer, cs%diag)
1505 \textcolor{keywordflow}{  endif}
1506 
\end{DoxyCode}
\mbox{\Hypertarget{namespacemom__cvmix__kpp_a54093ca1cac897785c965c00efa12fe6}\label{namespacemom__cvmix__kpp_a54093ca1cac897785c965c00efa12fe6}} 
\index{mom\+\_\+cvmix\+\_\+kpp@{mom\+\_\+cvmix\+\_\+kpp}!kpp\+\_\+nonlocaltransport\+\_\+temp@{kpp\+\_\+nonlocaltransport\+\_\+temp}}
\index{kpp\+\_\+nonlocaltransport\+\_\+temp@{kpp\+\_\+nonlocaltransport\+\_\+temp}!mom\+\_\+cvmix\+\_\+kpp@{mom\+\_\+cvmix\+\_\+kpp}}
\subsubsection{\texorpdfstring{kpp\+\_\+nonlocaltransport\+\_\+temp()}{kpp\_nonlocaltransport\_temp()}}
{\footnotesize\ttfamily subroutine, public mom\+\_\+cvmix\+\_\+kpp\+::kpp\+\_\+nonlocaltransport\+\_\+temp (\begin{DoxyParamCaption}\item[{type(\hyperlink{structmom__cvmix__kpp_1_1kpp__cs}{kpp\+\_\+cs}), intent(in)}]{CS,  }\item[{type(ocean\+\_\+grid\+\_\+type), intent(in)}]{G,  }\item[{type(verticalgrid\+\_\+type), intent(in)}]{GV,  }\item[{real, dimension( g \%isd\+: g \%ied, g \%jsd\+: g \%jed, g \%ke), intent(in)}]{h,  }\item[{real, dimension( g \%isd\+: g \%ied, g \%jsd\+: g \%jed, g \%ke+1), intent(in)}]{non\+Local\+Trans,  }\item[{real, dimension( g \%isd\+: g \%ied, g \%jsd\+: g \%jed), intent(in)}]{surf\+Flux,  }\item[{real, intent(in)}]{dt,  }\item[{real, dimension( g \%isd\+: g \%ied, g \%jsd\+: g \%jed, g \%ke), intent(inout)}]{scalar,  }\item[{real, intent(in)}]{C\+\_\+p }\end{DoxyParamCaption})}



Apply K\+PP non-\/local transport of surface fluxes for temperature. 


\begin{DoxyParams}[1]{Parameters}
\mbox{\tt in}  & {\em cs} & Control structure\\
\hline
\mbox{\tt in}  & {\em g} & Ocean grid\\
\hline
\mbox{\tt in}  & {\em gv} & Ocean vertical grid\\
\hline
\mbox{\tt in}  & {\em h} & Layer/level thickness \mbox{[}H $\sim$$>$ m or kg m-\/2\mbox{]}\\
\hline
\mbox{\tt in}  & {\em nonlocaltrans} & Non-\/local transport \mbox{[}nondim\mbox{]}\\
\hline
\mbox{\tt in}  & {\em surfflux} & Surface flux of scalar \mbox{[}conc H s-\/1 $\sim$$>$ conc m s-\/1 or conc kg m-\/2 s-\/1\mbox{]}\\
\hline
\mbox{\tt in}  & {\em dt} & Time-\/step \mbox{[}s\mbox{]}\\
\hline
\mbox{\tt in,out}  & {\em scalar} & temperature\\
\hline
\mbox{\tt in}  & {\em c\+\_\+p} & Seawater specific heat capacity \mbox{[}J kg-\/1 deg\+C-\/1\mbox{]} \\
\hline
\end{DoxyParams}


Definition at line 1390 of file M\+O\+M\+\_\+\+C\+V\+Mix\+\_\+\+K\+P\+P.\+F90.


\begin{DoxyCode}
1390 
1391   \textcolor{keywordtype}{type}(kpp\_cs),                               \textcolor{keywordtype}{intent(in)}    :: cs\textcolor{comment}{     !< Control structure}
1392   \textcolor{keywordtype}{type}(ocean\_grid\_type),                      \textcolor{keywordtype}{intent(in)}    :: g\textcolor{comment}{      !< Ocean grid}
1393   \textcolor{keywordtype}{type}(verticalgrid\_type),                    \textcolor{keywordtype}{intent(in)}    :: gv\textcolor{comment}{     !< Ocean vertical grid}
1394   \textcolor{keywordtype}{real}, \textcolor{keywordtype}{dimension(SZI\_(G),SZJ\_(G),SZK\_(G))},   \textcolor{keywordtype}{intent(in)}    :: h\textcolor{comment}{      !< Layer/level thickness [H ~> m or
       kg m-2]}
1395   \textcolor{keywordtype}{real}, \textcolor{keywordtype}{dimension(SZI\_(G),SZJ\_(G),SZK\_(G)+1)}, \textcolor{keywordtype}{intent(in)}    :: nonlocaltrans\textcolor{comment}{ !< Non-local transport
       [nondim]}
1396   \textcolor{keywordtype}{real}, \textcolor{keywordtype}{dimension(SZI\_(G),SZJ\_(G))},           \textcolor{keywordtype}{intent(in)}    :: surfflux\textcolor{comment}{  !< Surface flux of scalar}
1397 \textcolor{comment}{                                                                      !! [conc H s-1 ~> conc m s-1 or conc
       kg m-2 s-1]}
1398   \textcolor{keywordtype}{real},                                       \textcolor{keywordtype}{intent(in)}    :: dt\textcolor{comment}{     !< Time-step [s]}
1399   \textcolor{keywordtype}{real}, \textcolor{keywordtype}{dimension(SZI\_(G),SZJ\_(G),SZK\_(G))},   \textcolor{keywordtype}{intent(inout)} :: scalar\textcolor{comment}{ !< temperature}
1400   \textcolor{keywordtype}{real},                                       \textcolor{keywordtype}{intent(in)}    :: c\_p\textcolor{comment}{    !< Seawater specific heat capacity [J
       kg-1 degC-1]}
1401 
1402   \textcolor{keywordtype}{integer} :: i, j, k
1403   \textcolor{keywordtype}{real}, \textcolor{keywordtype}{dimension( SZI\_(G), SZJ\_(G), SZK\_(G) )} :: dtracer
1404 
1405 
1406   dtracer(:,:,:) = 0.0
1407   \textcolor{comment}{!$OMP parallel do default(none) shared(dtracer, nonLocalTrans, h, G, GV, surfFlux)}
1408   \textcolor{keywordflow}{do} k = 1, g%ke
1409     \textcolor{keywordflow}{do} j = g%jsc, g%jec
1410       \textcolor{keywordflow}{do} i = g%isc, g%iec
1411         dtracer(i,j,k) = ( nonlocaltrans(i,j,k) - nonlocaltrans(i,j,k+1) ) / &
1412                          ( h(i,j,k) + gv%H\_subroundoff ) * surfflux(i,j)
1413 \textcolor{keywordflow}{      enddo}
1414 \textcolor{keywordflow}{    enddo}
1415 \textcolor{keywordflow}{  enddo}
1416 
1417   \textcolor{comment}{!  Update tracer due to non-local redistribution of surface flux}
1418   \textcolor{keywordflow}{if} (cs%applyNonLocalTrans) \textcolor{keywordflow}{then}
1419     \textcolor{comment}{!$OMP parallel do default(none) shared(dt, scalar, dtracer, G)}
1420     \textcolor{keywordflow}{do} k = 1, g%ke
1421       \textcolor{keywordflow}{do} j = g%jsc, g%jec
1422         \textcolor{keywordflow}{do} i = g%isc, g%iec
1423           scalar(i,j,k) = scalar(i,j,k) + dt * dtracer(i,j,k)
1424 \textcolor{keywordflow}{        enddo}
1425 \textcolor{keywordflow}{      enddo}
1426 \textcolor{keywordflow}{    enddo}
1427 \textcolor{keywordflow}{  endif}
1428 
1429   \textcolor{comment}{! Diagnostics}
1430   \textcolor{keywordflow}{if} (cs%id\_QminusSW        > 0) \textcolor{keyword}{call }post\_data(cs%id\_QminusSW, surfflux, cs%diag)
1431   \textcolor{keywordflow}{if} (cs%id\_NLT\_dTdt        > 0) \textcolor{keyword}{call }post\_data(cs%id\_NLT\_dTdt, dtracer,  cs%diag)
1432   \textcolor{keywordflow}{if} (cs%id\_NLT\_temp\_budget > 0) \textcolor{keywordflow}{then}
1433     dtracer(:,:,:) = 0.0
1434     \textcolor{comment}{!$OMP parallel do default(none) shared(dtracer, nonLocalTrans, surfFlux, C\_p, G, GV)}
1435     \textcolor{keywordflow}{do} k = 1, g%ke
1436       \textcolor{keywordflow}{do} j = g%jsc, g%jec
1437         \textcolor{keywordflow}{do} i = g%isc, g%iec
1438           dtracer(i,j,k) = (nonlocaltrans(i,j,k) - nonlocaltrans(i,j,k+1)) * &
1439                            surfflux(i,j) * c\_p * gv%H\_to\_kg\_m2
1440 \textcolor{keywordflow}{        enddo}
1441 \textcolor{keywordflow}{      enddo}
1442 \textcolor{keywordflow}{    enddo}
1443     \textcolor{keyword}{call }post\_data(cs%id\_NLT\_temp\_budget, dtracer, cs%diag)
1444 \textcolor{keywordflow}{  endif}
1445 
\end{DoxyCode}
\mbox{\Hypertarget{namespacemom__cvmix__kpp_a8662fdd6328fdec67691ced27f03e049}\label{namespacemom__cvmix__kpp_a8662fdd6328fdec67691ced27f03e049}} 
\index{mom\+\_\+cvmix\+\_\+kpp@{mom\+\_\+cvmix\+\_\+kpp}!kpp\+\_\+smooth\+\_\+bld@{kpp\+\_\+smooth\+\_\+bld}}
\index{kpp\+\_\+smooth\+\_\+bld@{kpp\+\_\+smooth\+\_\+bld}!mom\+\_\+cvmix\+\_\+kpp@{mom\+\_\+cvmix\+\_\+kpp}}
\subsubsection{\texorpdfstring{kpp\+\_\+smooth\+\_\+bld()}{kpp\_smooth\_bld()}}
{\footnotesize\ttfamily subroutine mom\+\_\+cvmix\+\_\+kpp\+::kpp\+\_\+smooth\+\_\+bld (\begin{DoxyParamCaption}\item[{type(\hyperlink{structmom__cvmix__kpp_1_1kpp__cs}{kpp\+\_\+cs}), pointer}]{CS,  }\item[{type(ocean\+\_\+grid\+\_\+type), intent(inout)}]{G,  }\item[{type(verticalgrid\+\_\+type), intent(in)}]{GV,  }\item[{real, dimension( g \%isd\+: g \%ied, g \%jsd\+: g \%jed, g \%ke), intent(in)}]{h }\end{DoxyParamCaption})\hspace{0.3cm}{\ttfamily [private]}}



Apply a 1-\/1-\/4-\/1-\/1 Laplacian filter one time on B\+LD to reduce any horizontal two-\/grid-\/point noise. 


\begin{DoxyParams}[1]{Parameters}
 & {\em cs} & Control structure\\
\hline
\mbox{\tt in,out}  & {\em g} & Ocean grid\\
\hline
\mbox{\tt in}  & {\em gv} & Ocean vertical grid\\
\hline
\mbox{\tt in}  & {\em h} & Layer/level thicknesses \mbox{[}H $\sim$$>$ m or kg m-\/2\mbox{]} \\
\hline
\end{DoxyParams}


Definition at line 1285 of file M\+O\+M\+\_\+\+C\+V\+Mix\+\_\+\+K\+P\+P.\+F90.


\begin{DoxyCode}
1285   \textcolor{comment}{! Arguments}
1286   \textcolor{keywordtype}{type}(kpp\_cs),                           \textcolor{keywordtype}{pointer}       :: cs\textcolor{comment}{   !< Control structure}
1287   \textcolor{keywordtype}{type}(ocean\_grid\_type),                  \textcolor{keywordtype}{intent(inout)} :: g\textcolor{comment}{    !< Ocean grid}
1288   \textcolor{keywordtype}{type}(verticalgrid\_type),                \textcolor{keywordtype}{intent(in)}    :: gv\textcolor{comment}{   !< Ocean vertical grid}
1289   \textcolor{keywordtype}{real}, \textcolor{keywordtype}{dimension(SZI\_(G),SZJ\_(G),SZK\_(G))},  \textcolor{keywordtype}{intent(in)} :: h\textcolor{comment}{    !< Layer/level thicknesses [H ~> m or kg
       m-2]}
1290 
1291   \textcolor{comment}{! local}
1292   \textcolor{keywordtype}{real}, \textcolor{keywordtype}{dimension(SZI\_(G),SZJ\_(G))} :: obldepth\_prev     \textcolor{comment}{! OBLdepth before s.th smoothing iteration}
1293   \textcolor{keywordtype}{real}, \textcolor{keywordtype}{dimension( G%ke )}          :: cellheight        \textcolor{comment}{! Cell center heights referenced to surface [m]}
1294                                                         \textcolor{comment}{! (negative in the ocean)}
1295   \textcolor{keywordtype}{real}, \textcolor{keywordtype}{dimension( G%ke+1 )}        :: ifaceheight       \textcolor{comment}{! Interface heights referenced to surface [m]}
1296                                                         \textcolor{comment}{! (negative in the ocean)}
1297   \textcolor{keywordtype}{real} :: wc, ww, we, wn, ws \textcolor{comment}{! averaging weights for smoothing}
1298   \textcolor{keywordtype}{real} :: dh                 \textcolor{comment}{! The local thickness used for calculating interface positions [m]}
1299   \textcolor{keywordtype}{real} :: hcorr              \textcolor{comment}{! A cumulative correction arising from inflation of vanished layers [m]}
1300   \textcolor{keywordtype}{integer} :: i, j, k, s
1301 
1302   \textcolor{keyword}{call }cpu\_clock\_begin(id\_clock\_kpp\_smoothing)
1303 
1304   \textcolor{comment}{! Update halos}
1305   \textcolor{keyword}{call }pass\_var(cs%OBLdepth, g%Domain, halo=cs%n\_smooth)
1306 
1307   \textcolor{keywordflow}{if} (cs%id\_OBLdepth\_original > 0) cs%OBLdepth\_original = cs%OBLdepth
1308 
1309   \textcolor{keywordflow}{do} s=1,cs%n\_smooth
1310 
1311     obldepth\_prev = cs%OBLdepth
1312 
1313     \textcolor{comment}{! apply smoothing on OBL depth}
1314     \textcolor{comment}{!$OMP parallel do default(none) shared(G, GV, CS, h, OBLdepth\_prev) &}
1315     \textcolor{comment}{!$OMP                           private(wc, ww, we, wn, ws, dh, hcorr, cellHeight, iFaceHeight)}
1316     \textcolor{keywordflow}{do} j = g%jsc, g%jec
1317       \textcolor{keywordflow}{do} i = g%isc, g%iec
1318 
1319          \textcolor{comment}{! skip land points}
1320         \textcolor{keywordflow}{if} (g%mask2dT(i,j)==0.) cycle
1321 
1322         ifaceheight(1) = 0.0 \textcolor{comment}{! BBL is all relative to the surface}
1323         hcorr = 0.
1324         \textcolor{keywordflow}{do} k=1,g%ke
1325 
1326           \textcolor{comment}{! cell center and cell bottom in meters (negative values in the ocean)}
1327           dh = h(i,j,k) * gv%H\_to\_m \textcolor{comment}{! Nominal thickness to use for increment}
1328           dh = dh + hcorr \textcolor{comment}{! Take away the accumulated error (could temporarily make dh<0)}
1329           hcorr = min( dh - cs%min\_thickness, 0. ) \textcolor{comment}{! If inflating then hcorr<0}
1330           dh = max( dh, cs%min\_thickness ) \textcolor{comment}{! Limit increment dh>=min\_thickness}
1331           cellheight(k)    = ifaceheight(k) - 0.5 * dh
1332           ifaceheight(k+1) = ifaceheight(k) - dh
1333 \textcolor{keywordflow}{        enddo}
1334 
1335         \textcolor{comment}{! compute weights}
1336         ww = 0.125 * g%mask2dT(i-1,j)
1337         we = 0.125 * g%mask2dT(i+1,j)
1338         ws = 0.125 * g%mask2dT(i,j-1)
1339         wn = 0.125 * g%mask2dT(i,j+1)
1340         wc = 1.0 - (ww+we+wn+ws)
1341 
1342         cs%OBLdepth(i,j) =  wc * obldepth\_prev(i,j)   &
1343                           + ww * obldepth\_prev(i-1,j) &
1344                           + we * obldepth\_prev(i+1,j) &
1345                           + ws * obldepth\_prev(i,j-1) &
1346                           + wn * obldepth\_prev(i,j+1)
1347 
1348         \textcolor{comment}{! Apply OBLdepth smoothing at a cell only if the OBLdepth gets deeper via smoothing.}
1349         \textcolor{keywordflow}{if} (cs%deepen\_only) cs%OBLdepth(i,j) = max(cs%OBLdepth(i,j), obldepth\_prev(i,j))
1350 
1351         \textcolor{comment}{! prevent OBL depths deeper than the bathymetric depth}
1352         cs%OBLdepth(i,j) = min( cs%OBLdepth(i,j), -ifaceheight(g%ke+1) ) \textcolor{comment}{! no deeper than bottom}
1353         cs%kOBL(i,j)     = cvmix\_kpp\_compute\_kobl\_depth( ifaceheight, cellheight, cs%OBLdepth(i,j) )
1354 \textcolor{keywordflow}{      enddo}
1355 \textcolor{keywordflow}{    enddo}
1356 
1357 \textcolor{keywordflow}{  enddo} \textcolor{comment}{! s-loop}
1358 
1359   \textcolor{keyword}{call }cpu\_clock\_end(id\_clock\_kpp\_smoothing)
1360 
\end{DoxyCode}
