\hypertarget{namespacemom__cvmix__conv}{}\doxysection{mom\+\_\+cvmix\+\_\+conv Module Reference}
\label{namespacemom__cvmix__conv}\index{mom\_cvmix\_conv@{mom\_cvmix\_conv}}


\doxysubsection{Detailed Description}
Interface to C\+V\+Mix convection scheme. \doxysubsection*{Data Types}
\begin{DoxyCompactItemize}
\item 
type \mbox{\hyperlink{structmom__cvmix__conv_1_1cvmix__conv__cs}{cvmix\+\_\+conv\+\_\+cs}}
\begin{DoxyCompactList}\small\item\em Control structure including parameters for C\+V\+Mix convection. \end{DoxyCompactList}\end{DoxyCompactItemize}
\doxysubsection*{Functions/\+Subroutines}
\begin{DoxyCompactItemize}
\item 
logical function, public \mbox{\hyperlink{namespacemom__cvmix__conv_a96b32166eb7623c206f18549da8224ca}{cvmix\+\_\+conv\+\_\+init}} (Time, G, GV, US, param\+\_\+file, diag, CS)
\begin{DoxyCompactList}\small\item\em Initialized the C\+V\+Mix convection mixing routine. \end{DoxyCompactList}\item 
subroutine, public \mbox{\hyperlink{namespacemom__cvmix__conv_ace5bb8e12704ee4d46e4cfb67e6f63f8}{calculate\+\_\+cvmix\+\_\+conv}} (h, tv, G, GV, US, CS, hbl, Kd, Kv, Kd\+\_\+aux)
\begin{DoxyCompactList}\small\item\em Subroutine for calculating enhanced diffusivity/viscosity due to convection via C\+V\+Mix. \end{DoxyCompactList}\item 
logical function, public \mbox{\hyperlink{namespacemom__cvmix__conv_a5e741c84ad14fae3e5801d00a9867bba}{cvmix\+\_\+conv\+\_\+is\+\_\+used}} (param\+\_\+file)
\begin{DoxyCompactList}\small\item\em Reads the parameter \char`\"{}\+U\+S\+E\+\_\+\+C\+V\+Mix\+\_\+\+C\+O\+N\+V\+E\+C\+T\+I\+O\+N\char`\"{} and returns state. This function allows other modules to know whether this parameterization will be used without needing to duplicate the log entry. \end{DoxyCompactList}\item 
subroutine, public \mbox{\hyperlink{namespacemom__cvmix__conv_a4f35df3a407ded91cd67384a14da3a3c}{cvmix\+\_\+conv\+\_\+end}} (CS)
\begin{DoxyCompactList}\small\item\em Clear pointers and dealocate memory. \end{DoxyCompactList}\end{DoxyCompactItemize}
\doxysubsection*{Variables}
\begin{DoxyCompactItemize}
\item 
\mbox{\Hypertarget{namespacemom__cvmix__conv_a877a4beb2eff515d903a17b5779adbee}\label{namespacemom__cvmix__conv_a877a4beb2eff515d903a17b5779adbee}} 
character(len=40) \mbox{\hyperlink{namespacemom__cvmix__conv_a877a4beb2eff515d903a17b5779adbee}{mdl}} = \char`\"{}M\+O\+M\+\_\+\+C\+V\+Mix\+\_\+conv\char`\"{}
\begin{DoxyCompactList}\small\item\em This module\textquotesingle{}s name. \end{DoxyCompactList}\end{DoxyCompactItemize}


\doxysubsection{Function/\+Subroutine Documentation}
\mbox{\Hypertarget{namespacemom__cvmix__conv_ace5bb8e12704ee4d46e4cfb67e6f63f8}\label{namespacemom__cvmix__conv_ace5bb8e12704ee4d46e4cfb67e6f63f8}} 
\index{mom\_cvmix\_conv@{mom\_cvmix\_conv}!calculate\_cvmix\_conv@{calculate\_cvmix\_conv}}
\index{calculate\_cvmix\_conv@{calculate\_cvmix\_conv}!mom\_cvmix\_conv@{mom\_cvmix\_conv}}
\doxysubsubsection{\texorpdfstring{calculate\_cvmix\_conv()}{calculate\_cvmix\_conv()}}
{\footnotesize\ttfamily subroutine, public mom\+\_\+cvmix\+\_\+conv\+::calculate\+\_\+cvmix\+\_\+conv (\begin{DoxyParamCaption}\item[{real, dimension( g \%isd\+: g \%ied, g \%jsd\+: g \%jed, gv \%ke), intent(in)}]{h,  }\item[{type(thermo\+\_\+var\+\_\+ptrs), intent(in)}]{tv,  }\item[{type(ocean\+\_\+grid\+\_\+type), intent(in)}]{G,  }\item[{type(verticalgrid\+\_\+type), intent(in)}]{GV,  }\item[{type(unit\+\_\+scale\+\_\+type), intent(in)}]{US,  }\item[{type(\mbox{\hyperlink{structmom__cvmix__conv_1_1cvmix__conv__cs}{cvmix\+\_\+conv\+\_\+cs}}), pointer}]{CS,  }\item[{real, dimension( g \%isd\+: g \%ied, g \%jsd\+: g \%jed), intent(in)}]{hbl,  }\item[{real, dimension( g \%isd\+: g \%ied, g \%jsd\+: g \%jed, g \%ke+1), intent(inout), optional}]{Kd,  }\item[{real, dimension( g \%isd\+: g \%ied, g \%jsd\+: g \%jed, g \%ke+1), intent(inout), optional}]{Kv,  }\item[{real, dimension( g \%isd\+: g \%ied, g \%jsd\+: g \%jed, g \%ke+1), intent(inout), optional}]{Kd\+\_\+aux }\end{DoxyParamCaption})}



Subroutine for calculating enhanced diffusivity/viscosity due to convection via C\+V\+Mix. 


\begin{DoxyParams}[1]{Parameters}
\mbox{\texttt{ in}}  & {\em g} & Grid structure. \\
\hline
\mbox{\texttt{ in}}  & {\em gv} & Vertical grid structure. \\
\hline
\mbox{\texttt{ in}}  & {\em us} & A dimensional unit scaling type \\
\hline
\mbox{\texttt{ in}}  & {\em h} & Layer thickness \mbox{[}H $\sim$$>$ m or kg m-\/2\mbox{]}. \\
\hline
\mbox{\texttt{ in}}  & {\em tv} & Thermodynamics structure. \\
\hline
 & {\em cs} & The control structure returned by a previous call to C\+V\+Mix\+\_\+conv\+\_\+init. \\
\hline
\mbox{\texttt{ in}}  & {\em hbl} & Depth of ocean boundary layer \mbox{[}Z $\sim$$>$ m\mbox{]} \\
\hline
\mbox{\texttt{ in,out}}  & {\em kd} & Diapycnal diffusivity at each interface that \\
\hline
\mbox{\texttt{ in,out}}  & {\em kv} & Viscosity at each interface that will be \\
\hline
\mbox{\texttt{ in,out}}  & {\em kd\+\_\+aux} & A second diapycnal diffusivity at each \\
\hline
\end{DoxyParams}


Definition at line 142 of file M\+O\+M\+\_\+\+C\+V\+Mix\+\_\+conv.\+F90.


\begin{DoxyCode}{0}
\DoxyCodeLine{143 }
\DoxyCodeLine{144   \textcolor{keywordtype}{type}(ocean\_grid\_type),                     \textcolor{keywordtype}{intent(in)}  :: G\textcolor{comment}{  !< Grid structure.}}
\DoxyCodeLine{145   \textcolor{keywordtype}{type}(verticalGrid\_type),                   \textcolor{keywordtype}{intent(in)}  :: GV\textcolor{comment}{ !< Vertical grid structure.}}
\DoxyCodeLine{146   \textcolor{keywordtype}{type}(unit\_scale\_type),                     \textcolor{keywordtype}{intent(in)}  :: US\textcolor{comment}{ !< A dimensional unit scaling type}}
\DoxyCodeLine{147 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(SZI\_(G),SZJ\_(G),SZK\_(GV))}, \textcolor{keywordtype}{intent(in)}  :: h\textcolor{comment}{  !< Layer thickness [H \string~> m or kg m-\/2].}}
\DoxyCodeLine{148   \textcolor{keywordtype}{type}(thermo\_var\_ptrs),                     \textcolor{keywordtype}{intent(in)}  :: tv\textcolor{comment}{ !< Thermodynamics structure.}}
\DoxyCodeLine{149   \textcolor{keywordtype}{type}(CVMix\_conv\_cs),                       \textcolor{keywordtype}{pointer}     :: CS\textcolor{comment}{ !< The control structure returned}}
\DoxyCodeLine{150 \textcolor{comment}{                                                                !! by a previous call to CVMix\_conv\_init.}}
\DoxyCodeLine{151 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(SZI\_(G),SZJ\_(G))},          \textcolor{keywordtype}{intent(in)}  :: hbl\textcolor{comment}{ !< Depth of ocean boundary layer [Z \string~> m]}}
\DoxyCodeLine{152 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(SZI\_(G),SZJ\_(G),SZK\_(G)+1)}, \&}
\DoxyCodeLine{153                                    \textcolor{keywordtype}{optional}, \textcolor{keywordtype}{intent(inout)} :: Kd\textcolor{comment}{ !< Diapycnal diffusivity at each interface that}}
\DoxyCodeLine{154 \textcolor{comment}{                                                                 !! will be incremented here [Z2 T-\/1 \string~> m2 s-\/1].}}
\DoxyCodeLine{155 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(SZI\_(G),SZJ\_(G),SZK\_(G)+1)}, \&}
\DoxyCodeLine{156                                    \textcolor{keywordtype}{optional}, \textcolor{keywordtype}{intent(inout)} :: KV\textcolor{comment}{ !< Viscosity at each interface that will be}}
\DoxyCodeLine{157 \textcolor{comment}{                                                                 !! incremented here [Z2 T-\/1 \string~> m2 s-\/1].}}
\DoxyCodeLine{158 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(SZI\_(G),SZJ\_(G),SZK\_(G)+1)}, \&}
\DoxyCodeLine{159                                    \textcolor{keywordtype}{optional}, \textcolor{keywordtype}{intent(inout)} :: Kd\_aux\textcolor{comment}{ !< A second diapycnal diffusivity at each}}
\DoxyCodeLine{160 \textcolor{comment}{                                                                 !! interface that will also be incremented}}
\DoxyCodeLine{161 \textcolor{comment}{                                                                 !! here [Z2 T-\/1 \string~> m2 s-\/1].}}
\DoxyCodeLine{162 }
\DoxyCodeLine{163   \textcolor{comment}{! local variables}}
\DoxyCodeLine{164 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(SZK\_(GV))} :: rho\_lwr\textcolor{comment}{ !< Adiabatic Water Density, this is a dummy}}
\DoxyCodeLine{165 \textcolor{comment}{                                       !! variable since here convection is always}}
\DoxyCodeLine{166 \textcolor{comment}{                                       !! computed based on Brunt Vaisala.}}
\DoxyCodeLine{167 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(SZK\_(GV))} :: rho\_1d\textcolor{comment}{  !< water density in a column, this is also}}
\DoxyCodeLine{168 \textcolor{comment}{                                       !! a dummy variable, same reason as above.}}
\DoxyCodeLine{169 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(SZK\_(GV)+1)} :: N2\textcolor{comment}{    !< Squared buoyancy frequency [s-\/2]}}
\DoxyCodeLine{170 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(SZK\_(GV)+1)} :: kv\_col\textcolor{comment}{ !< Viscosities at interfaces in the column [m2 s-\/1]}}
\DoxyCodeLine{171 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(SZK\_(GV)+1)} :: kd\_col\textcolor{comment}{ !< Diffusivities at interfaces in the column [m2 s-\/1]}}
\DoxyCodeLine{172 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(SZK\_(GV)+1)} :: iFaceHeight\textcolor{comment}{ !< Height of interfaces [m]}}
\DoxyCodeLine{173 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(SZK\_(GV))}   :: cellHeight\textcolor{comment}{  !< Height of cell centers [m]}}
\DoxyCodeLine{174 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(SZI\_(G),SZJ\_(G),SZK\_(GV)+1)} :: \&}
\DoxyCodeLine{175     kd\_conv, \&                         !< Diffusivity added by convection for diagnostics [Z2 T-\/1 \string~> m2 s-\/1]}
\DoxyCodeLine{176     kv\_conv, \&                         !< Viscosity added by convection for diagnostics [Z2 T-\/1 \string~> m2 s-\/1]}
\DoxyCodeLine{177     N2\_3d\textcolor{comment}{                              !< Squared buoyancy frequency for diagnostics [N-\/2 \string~> s-\/2]}}
\DoxyCodeLine{178   \textcolor{keywordtype}{integer} :: kOBL\textcolor{comment}{                      !< level of OBL extent}}
\DoxyCodeLine{179 \textcolor{keywordtype}{  real} :: g\_o\_rho0  \textcolor{comment}{! Gravitational acceleration divided by density times unit convserion factors}}
\DoxyCodeLine{180                     \textcolor{comment}{! [Z s-\/2 R-\/1 \string~> m4 s-\/2 kg-\/1]}}
\DoxyCodeLine{181 \textcolor{keywordtype}{  real} :: pref      \textcolor{comment}{! Interface pressures [R L2 T-\/2 \string~> Pa]}}
\DoxyCodeLine{182 \textcolor{keywordtype}{  real} :: rhok, rhokm1 \textcolor{comment}{! In situ densities of the layers above and below at the interface pressure [R \string~> kg m-\/3]}}
\DoxyCodeLine{183 \textcolor{keywordtype}{  real} :: hbl\_KPP   \textcolor{comment}{! The depth of the ocean boundary as used by KPP [m]}}
\DoxyCodeLine{184 \textcolor{keywordtype}{  real} :: dz        \textcolor{comment}{! A thickness [Z \string~> m]}}
\DoxyCodeLine{185 \textcolor{keywordtype}{  real} :: dh, hcorr \textcolor{comment}{! Two thicknesses [m]}}
\DoxyCodeLine{186   \textcolor{keywordtype}{integer} :: i, j, k}
\DoxyCodeLine{187 }
\DoxyCodeLine{188   g\_o\_rho0 = us\%L\_to\_Z**2*us\%s\_to\_T**2 * gv\%g\_Earth / gv\%Rho0}
\DoxyCodeLine{189 }
\DoxyCodeLine{190   \textcolor{comment}{! initialize dummy variables}}
\DoxyCodeLine{191   rho\_lwr(:) = 0.0 ; rho\_1d(:) = 0.0}
\DoxyCodeLine{192 }
\DoxyCodeLine{193   \textcolor{comment}{! set N2 to zero at the top-\/ and bottom-\/most interfaces}}
\DoxyCodeLine{194   n2(1) = 0.0 ; n2(gv\%ke+1) = 0.0}
\DoxyCodeLine{195 }
\DoxyCodeLine{196   \textcolor{keywordflow}{if} (cs\%id\_N2 > 0) n2\_3d(:,:,:) = 0.0}
\DoxyCodeLine{197   \textcolor{keywordflow}{if} (cs\%id\_kv\_conv > 0) kv\_conv(:,:,:) = 0.0}
\DoxyCodeLine{198   \textcolor{keywordflow}{if} (cs\%id\_kd\_conv > 0) kd\_conv(:,:,:) = 0.0}
\DoxyCodeLine{199 }
\DoxyCodeLine{200   \textcolor{keywordflow}{do} j = g\%jsc, g\%jec}
\DoxyCodeLine{201     \textcolor{keywordflow}{do} i = g\%isc, g\%iec}
\DoxyCodeLine{202 }
\DoxyCodeLine{203       \textcolor{comment}{! skip calling at land points}}
\DoxyCodeLine{204       \textcolor{comment}{!if (G\%mask2dT(i,j) == 0.) cycle}}
\DoxyCodeLine{205 }
\DoxyCodeLine{206       pref = 0. ; \textcolor{keywordflow}{if} (\textcolor{keyword}{associated}(tv\%p\_surf)) pref = tv\%p\_surf(i,j)}
\DoxyCodeLine{207       \textcolor{comment}{! Compute Brunt-\/Vaisala frequency (static stability) on interfaces}}
\DoxyCodeLine{208       \textcolor{keywordflow}{do} k=2,gv\%ke}
\DoxyCodeLine{209 }
\DoxyCodeLine{210         \textcolor{comment}{! pRef is pressure at interface between k and km1 [R L2 T-\/2 \string~> Pa].}}
\DoxyCodeLine{211         pref = pref + (gv\%H\_to\_RZ*gv\%g\_Earth) * h(i,j,k)}
\DoxyCodeLine{212         \textcolor{keyword}{call }calculate\_density(tv\%t(i,j,k), tv\%s(i,j,k), pref, rhok, tv\%eqn\_of\_state)}
\DoxyCodeLine{213         \textcolor{keyword}{call }calculate\_density(tv\%t(i,j,k-\/1), tv\%s(i,j,k-\/1), pref, rhokm1, tv\%eqn\_of\_state)}
\DoxyCodeLine{214 }
\DoxyCodeLine{215         dz = ((0.5*(h(i,j,k-\/1) + h(i,j,k))+gv\%H\_subroundoff)*gv\%H\_to\_Z)}
\DoxyCodeLine{216         n2(k) = g\_o\_rho0 * (rhok -\/ rhokm1) / dz \textcolor{comment}{! Can be negative}}
\DoxyCodeLine{217 }
\DoxyCodeLine{218 \textcolor{keywordflow}{      enddo}}
\DoxyCodeLine{219 }
\DoxyCodeLine{220       ifaceheight(1) = 0.0 \textcolor{comment}{! BBL is all relative to the surface}}
\DoxyCodeLine{221       hcorr = 0.0}
\DoxyCodeLine{222       \textcolor{comment}{! compute heights at cell center and interfaces}}
\DoxyCodeLine{223       \textcolor{keywordflow}{do} k=1,gv\%ke}
\DoxyCodeLine{224         dh = h(i,j,k) * gv\%H\_to\_m \textcolor{comment}{! Nominal thickness to use for increment, in the units used by CVMix.}}
\DoxyCodeLine{225         dh = dh + hcorr \textcolor{comment}{! Take away the accumulated error (could temporarily make dh<0)}}
\DoxyCodeLine{226         hcorr = min( dh -\/ cs\%min\_thickness, 0. ) \textcolor{comment}{! If inflating then hcorr<0}}
\DoxyCodeLine{227         dh = max( dh, cs\%min\_thickness ) \textcolor{comment}{! Limit increment dh>=min\_thickness}}
\DoxyCodeLine{228         cellheight(k)    = ifaceheight(k) -\/ 0.5 * dh}
\DoxyCodeLine{229         ifaceheight(k+1) = ifaceheight(k) -\/ dh}
\DoxyCodeLine{230 \textcolor{keywordflow}{      enddo}}
\DoxyCodeLine{231 }
\DoxyCodeLine{232       \textcolor{comment}{! gets index of the level and interface above hbl}}
\DoxyCodeLine{233       hbl\_kpp = us\%Z\_to\_m*hbl(i,j)  \textcolor{comment}{! Convert to the units used by CVMix.}}
\DoxyCodeLine{234       kobl = cvmix\_kpp\_compute\_kobl\_depth(ifaceheight, cellheight, hbl\_kpp)}
\DoxyCodeLine{235 }
\DoxyCodeLine{236       kv\_col(:) = 0.0 ; kd\_col(:) = 0.0}
\DoxyCodeLine{237       \textcolor{keyword}{call }cvmix\_coeffs\_conv(mdiff\_out=kv\_col(:), \&}
\DoxyCodeLine{238                              tdiff\_out=kd\_col(:), \&}
\DoxyCodeLine{239                              nsqr=n2(:), \&}
\DoxyCodeLine{240                              dens=rho\_1d(:), \&}
\DoxyCodeLine{241                              dens\_lwr=rho\_lwr(:), \&}
\DoxyCodeLine{242                              nlev=gv\%ke,    \&}
\DoxyCodeLine{243                              max\_nlev=gv\%ke, \&}
\DoxyCodeLine{244                              obl\_ind=kobl)}
\DoxyCodeLine{245 }
\DoxyCodeLine{246       \textcolor{keywordflow}{if} (\textcolor{keyword}{present}(kd)) \textcolor{keywordflow}{then}}
\DoxyCodeLine{247         \textcolor{comment}{! Increment the diffusivity outside of the boundary layer.}}
\DoxyCodeLine{248         \textcolor{keywordflow}{do} k=max(1,kobl+1),gv\%ke+1}
\DoxyCodeLine{249           kd(i,j,k) = kd(i,j,k) + us\%m2\_s\_to\_Z2\_T * kd\_col(k)}
\DoxyCodeLine{250 \textcolor{keywordflow}{        enddo}}
\DoxyCodeLine{251 \textcolor{keywordflow}{      endif}}
\DoxyCodeLine{252       \textcolor{keywordflow}{if} (\textcolor{keyword}{present}(kd\_aux)) \textcolor{keywordflow}{then}}
\DoxyCodeLine{253         \textcolor{comment}{! Increment the other diffusivity outside of the boundary layer.}}
\DoxyCodeLine{254         \textcolor{keywordflow}{do} k=max(1,kobl+1),gv\%ke+1}
\DoxyCodeLine{255           kd\_aux(i,j,k) = kd\_aux(i,j,k) + us\%m2\_s\_to\_Z2\_T * kd\_col(k)}
\DoxyCodeLine{256 \textcolor{keywordflow}{        enddo}}
\DoxyCodeLine{257 \textcolor{keywordflow}{      endif}}
\DoxyCodeLine{258 }
\DoxyCodeLine{259       \textcolor{keywordflow}{if} (\textcolor{keyword}{present}(kv)) \textcolor{keywordflow}{then}}
\DoxyCodeLine{260         \textcolor{comment}{! Increment the viscosity outside of the boundary layer.}}
\DoxyCodeLine{261         \textcolor{keywordflow}{do} k=max(1,kobl+1),gv\%ke+1}
\DoxyCodeLine{262           kv(i,j,k) = kv(i,j,k) + us\%m2\_s\_to\_Z2\_T * kv\_col(k)}
\DoxyCodeLine{263 \textcolor{keywordflow}{        enddo}}
\DoxyCodeLine{264 \textcolor{keywordflow}{      endif}}
\DoxyCodeLine{265 }
\DoxyCodeLine{266       \textcolor{comment}{! Store 3-\/d arrays for diagnostics.}}
\DoxyCodeLine{267       \textcolor{keywordflow}{if} (cs\%id\_kv\_conv > 0) \textcolor{keywordflow}{then}}
\DoxyCodeLine{268         \textcolor{comment}{! Do not apply mixing due to convection within the boundary layer}}
\DoxyCodeLine{269         \textcolor{keywordflow}{do} k=max(1,kobl+1),gv\%ke+1}
\DoxyCodeLine{270           kv\_conv(i,j,k) = us\%m2\_s\_to\_Z2\_T * kv\_col(k)}
\DoxyCodeLine{271 \textcolor{keywordflow}{        enddo}}
\DoxyCodeLine{272 \textcolor{keywordflow}{      endif}}
\DoxyCodeLine{273       \textcolor{keywordflow}{if} (cs\%id\_kd\_conv > 0) \textcolor{keywordflow}{then}}
\DoxyCodeLine{274         \textcolor{comment}{! Do not apply mixing due to convection within the boundary layer}}
\DoxyCodeLine{275         \textcolor{keywordflow}{do} k=max(1,kobl+1),gv\%ke+1}
\DoxyCodeLine{276           kd\_conv(i,j,k) = us\%m2\_s\_to\_Z2\_T * kd\_col(k)}
\DoxyCodeLine{277 \textcolor{keywordflow}{        enddo}}
\DoxyCodeLine{278 \textcolor{keywordflow}{      endif}}
\DoxyCodeLine{279 }
\DoxyCodeLine{280       \textcolor{keywordflow}{if} (cs\%id\_N2 > 0) \textcolor{keywordflow}{then} ; \textcolor{keywordflow}{do} k=2,gv\%ke ; n2\_3d(i,j,k) = us\%T\_to\_s**2*n2(k) ;\textcolor{keywordflow}{ enddo} ;\textcolor{keywordflow}{ endif}}
\DoxyCodeLine{281 }
\DoxyCodeLine{282 \textcolor{keywordflow}{    enddo}}
\DoxyCodeLine{283 \textcolor{keywordflow}{  enddo}}
\DoxyCodeLine{284 }
\DoxyCodeLine{285   \textcolor{keywordflow}{if} (cs\%debug) \textcolor{keywordflow}{then}}
\DoxyCodeLine{286     \textcolor{comment}{! if (CS\%id\_N2 > 0) call hchksum(N2\_3d, "MOM\_CVMix\_conv: N2",G\%HI,haloshift=0)}}
\DoxyCodeLine{287     \textcolor{comment}{! if (CS\%id\_kd\_conv > 0) \&}}
\DoxyCodeLine{288     \textcolor{comment}{!   call hchksum(Kd\_conv, "MOM\_CVMix\_conv: Kd\_conv", G\%HI, haloshift=0, scale=US\%Z2\_T\_to\_m2\_s)}}
\DoxyCodeLine{289     \textcolor{comment}{! if (CS\%id\_kv\_conv > 0) \&}}
\DoxyCodeLine{290     \textcolor{comment}{!   call hchksum(Kv\_conv, "MOM\_CVMix\_conv: Kv\_conv", G\%HI, haloshift=0, scale=US\%m2\_s\_to\_Z2\_T)}}
\DoxyCodeLine{291     \textcolor{keywordflow}{if} (\textcolor{keyword}{present}(kd)) \textcolor{keyword}{call }hchksum(kv, \textcolor{stringliteral}{"MOM\_CVMix\_conv: Kd"}, g\%HI, haloshift=0, scale=us\%m2\_s\_to\_Z2\_T)}
\DoxyCodeLine{292     \textcolor{keywordflow}{if} (\textcolor{keyword}{present}(kv)) \textcolor{keyword}{call }hchksum(kv, \textcolor{stringliteral}{"MOM\_CVMix\_conv: Kv"}, g\%HI, haloshift=0, scale=us\%m2\_s\_to\_Z2\_T)}
\DoxyCodeLine{293 \textcolor{keywordflow}{  endif}}
\DoxyCodeLine{294 }
\DoxyCodeLine{295   \textcolor{comment}{! send diagnostics to post\_data}}
\DoxyCodeLine{296   \textcolor{keywordflow}{if} (cs\%id\_N2 > 0) \textcolor{keyword}{call }post\_data(cs\%id\_N2, n2\_3d, cs\%diag)}
\DoxyCodeLine{297   \textcolor{keywordflow}{if} (cs\%id\_kd\_conv > 0) \textcolor{keyword}{call }post\_data(cs\%id\_kd\_conv, kd\_conv, cs\%diag)}
\DoxyCodeLine{298   \textcolor{keywordflow}{if} (cs\%id\_kv\_conv > 0) \textcolor{keyword}{call }post\_data(cs\%id\_kv\_conv, kv\_conv, cs\%diag)}
\DoxyCodeLine{299 }

\end{DoxyCode}
\mbox{\Hypertarget{namespacemom__cvmix__conv_a4f35df3a407ded91cd67384a14da3a3c}\label{namespacemom__cvmix__conv_a4f35df3a407ded91cd67384a14da3a3c}} 
\index{mom\_cvmix\_conv@{mom\_cvmix\_conv}!cvmix\_conv\_end@{cvmix\_conv\_end}}
\index{cvmix\_conv\_end@{cvmix\_conv\_end}!mom\_cvmix\_conv@{mom\_cvmix\_conv}}
\doxysubsubsection{\texorpdfstring{cvmix\_conv\_end()}{cvmix\_conv\_end()}}
{\footnotesize\ttfamily subroutine, public mom\+\_\+cvmix\+\_\+conv\+::cvmix\+\_\+conv\+\_\+end (\begin{DoxyParamCaption}\item[{type(\mbox{\hyperlink{structmom__cvmix__conv_1_1cvmix__conv__cs}{cvmix\+\_\+conv\+\_\+cs}}), pointer}]{CS }\end{DoxyParamCaption})}



Clear pointers and dealocate memory. 


\begin{DoxyParams}{Parameters}
{\em cs} & Control structure for this module that will be deallocated in this subroutine \\
\hline
\end{DoxyParams}


Definition at line 313 of file M\+O\+M\+\_\+\+C\+V\+Mix\+\_\+conv.\+F90.


\begin{DoxyCode}{0}
\DoxyCodeLine{314   \textcolor{keywordtype}{type}(CVMix\_conv\_cs), \textcolor{keywordtype}{pointer} :: CS\textcolor{comment}{ !< Control structure for this module that}}
\DoxyCodeLine{315 \textcolor{comment}{                                     !! will be deallocated in this subroutine}}
\DoxyCodeLine{316 }
\DoxyCodeLine{317   \textcolor{keywordflow}{if} (.not. \textcolor{keyword}{associated}(cs)) \textcolor{keywordflow}{return}}
\DoxyCodeLine{318 }
\DoxyCodeLine{319   \textcolor{keyword}{deallocate}(cs)}
\DoxyCodeLine{320 }

\end{DoxyCode}
\mbox{\Hypertarget{namespacemom__cvmix__conv_a96b32166eb7623c206f18549da8224ca}\label{namespacemom__cvmix__conv_a96b32166eb7623c206f18549da8224ca}} 
\index{mom\_cvmix\_conv@{mom\_cvmix\_conv}!cvmix\_conv\_init@{cvmix\_conv\_init}}
\index{cvmix\_conv\_init@{cvmix\_conv\_init}!mom\_cvmix\_conv@{mom\_cvmix\_conv}}
\doxysubsubsection{\texorpdfstring{cvmix\_conv\_init()}{cvmix\_conv\_init()}}
{\footnotesize\ttfamily logical function, public mom\+\_\+cvmix\+\_\+conv\+::cvmix\+\_\+conv\+\_\+init (\begin{DoxyParamCaption}\item[{type(time\+\_\+type), intent(in)}]{Time,  }\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(param\+\_\+file\+\_\+type), intent(in)}]{param\+\_\+file,  }\item[{type(diag\+\_\+ctrl), intent(inout), target}]{diag,  }\item[{type(\mbox{\hyperlink{structmom__cvmix__conv_1_1cvmix__conv__cs}{cvmix\+\_\+conv\+\_\+cs}}), pointer}]{CS }\end{DoxyParamCaption})}



Initialized the C\+V\+Mix convection mixing routine. 


\begin{DoxyParams}[1]{Parameters}
\mbox{\texttt{ in}}  & {\em time} & The current time. \\
\hline
\mbox{\texttt{ in}}  & {\em g} & Grid structure. \\
\hline
\mbox{\texttt{ in}}  & {\em gv} & Vertical grid structure. \\
\hline
\mbox{\texttt{ in}}  & {\em us} & A dimensional unit scaling type \\
\hline
\mbox{\texttt{ in}}  & {\em param\+\_\+file} & Run-\/time parameter file handle \\
\hline
\mbox{\texttt{ in,out}}  & {\em diag} & Diagnostics control structure. \\
\hline
 & {\em cs} & This module\textquotesingle{}s control structure. \\
\hline
\end{DoxyParams}


Definition at line 50 of file M\+O\+M\+\_\+\+C\+V\+Mix\+\_\+conv.\+F90.


\begin{DoxyCode}{0}
\DoxyCodeLine{51 }
\DoxyCodeLine{52   \textcolor{keywordtype}{type}(time\_type),         \textcolor{keywordtype}{intent(in)}    :: Time\textcolor{comment}{       !< The current time.}}
\DoxyCodeLine{53   \textcolor{keywordtype}{type}(ocean\_grid\_type),   \textcolor{keywordtype}{intent(in)}    :: G\textcolor{comment}{          !< Grid structure.}}
\DoxyCodeLine{54   \textcolor{keywordtype}{type}(verticalGrid\_type), \textcolor{keywordtype}{intent(in)}    :: GV\textcolor{comment}{         !< Vertical grid structure.}}
\DoxyCodeLine{55   \textcolor{keywordtype}{type}(unit\_scale\_type),   \textcolor{keywordtype}{intent(in)}    :: US\textcolor{comment}{         !< A dimensional unit scaling type}}
\DoxyCodeLine{56   \textcolor{keywordtype}{type}(param\_file\_type),   \textcolor{keywordtype}{intent(in)}    :: param\_file\textcolor{comment}{ !< Run-\/time parameter file handle}}
\DoxyCodeLine{57   \textcolor{keywordtype}{type}(diag\_ctrl), \textcolor{keywordtype}{target}, \textcolor{keywordtype}{intent(inout)} :: diag\textcolor{comment}{       !< Diagnostics control structure.}}
\DoxyCodeLine{58   \textcolor{keywordtype}{type}(CVMix\_conv\_cs),     \textcolor{keywordtype}{pointer}       :: CS\textcolor{comment}{         !< This module's control structure.}}
\DoxyCodeLine{59   \textcolor{comment}{! Local variables}}
\DoxyCodeLine{60 \textcolor{keywordtype}{  real}    :: prandtl\_conv\textcolor{comment}{ !< Turbulent Prandtl number used in convective instabilities.}}
\DoxyCodeLine{61   \textcolor{keywordtype}{logical} :: useEPBL\textcolor{comment}{      !< If True, use the ePBL boundary layer scheme.}}
\DoxyCodeLine{62 }
\DoxyCodeLine{63 \textcolor{comment}{! This include declares and sets the variable "version".}}
\DoxyCodeLine{64 \textcolor{preprocessor}{\#include "version\_variable.h"}}
\DoxyCodeLine{65 \textcolor{preprocessor}{}}
\DoxyCodeLine{66   \textcolor{keywordflow}{if} (\textcolor{keyword}{associated}(cs)) \textcolor{keywordflow}{then}}
\DoxyCodeLine{67     \textcolor{keyword}{call }mom\_error(warning, \textcolor{stringliteral}{"CVMix\_conv\_init called with an associated "}// \&}
\DoxyCodeLine{68                             \textcolor{stringliteral}{"control structure."})}
\DoxyCodeLine{69     \textcolor{keywordflow}{return}}
\DoxyCodeLine{70 \textcolor{keywordflow}{  endif}}
\DoxyCodeLine{71   \textcolor{keyword}{allocate}(cs)}
\DoxyCodeLine{72 }
\DoxyCodeLine{73   \textcolor{comment}{! Read parameters}}
\DoxyCodeLine{74   \textcolor{keyword}{call }get\_param(param\_file, mdl, \textcolor{stringliteral}{"USE\_CVMix\_CONVECTION"}, cvmix\_conv\_init, default=.false., do\_not\_log=.true.)}
\DoxyCodeLine{75   \textcolor{keyword}{call }log\_version(param\_file, mdl, version, \&}
\DoxyCodeLine{76            \textcolor{stringliteral}{"Parameterization of enhanced mixing due to convection via CVMix"}, \&}
\DoxyCodeLine{77            all\_default=.not.cvmix\_conv\_init)}
\DoxyCodeLine{78   \textcolor{keyword}{call }get\_param(param\_file, mdl, \textcolor{stringliteral}{"USE\_CVMix\_CONVECTION"}, cvmix\_conv\_init, \&}
\DoxyCodeLine{79                  \textcolor{stringliteral}{"If true, turns on the enhanced mixing due to convection "}//\&}
\DoxyCodeLine{80                  \textcolor{stringliteral}{"via CVMix. This scheme increases diapycnal diffs./viscs. "}//\&}
\DoxyCodeLine{81                  \textcolor{stringliteral}{"at statically unstable interfaces. Relevant parameters are "}//\&}
\DoxyCodeLine{82                  \textcolor{stringliteral}{"contained in the CVMix\_CONVECTION\% parameter block."}, \&}
\DoxyCodeLine{83                  default=.false.)}
\DoxyCodeLine{84 }
\DoxyCodeLine{85   \textcolor{keywordflow}{if} (.not. cvmix\_conv\_init) \textcolor{keywordflow}{return}}
\DoxyCodeLine{86 }
\DoxyCodeLine{87   \textcolor{keyword}{call }get\_param(param\_file, mdl, \textcolor{stringliteral}{"ENERGETICS\_SFC\_PBL"}, useepbl, default=.false., \&}
\DoxyCodeLine{88                 do\_not\_log=.true.)}
\DoxyCodeLine{89 }
\DoxyCodeLine{90   \textcolor{comment}{! Warn user if EPBL is being used, since in this case mixing due to convection will}}
\DoxyCodeLine{91   \textcolor{comment}{! be aplied in the boundary layer}}
\DoxyCodeLine{92   \textcolor{keywordflow}{if} (useepbl) \textcolor{keywordflow}{then}}
\DoxyCodeLine{93      \textcolor{keyword}{call }mom\_error(warning, \textcolor{stringliteral}{'MOM\_CVMix\_conv\_init: '}// \&}
\DoxyCodeLine{94            \textcolor{stringliteral}{'CVMix convection may not be properly applied when ENERGETICS\_SFC\_PBL = True'}//\&}
\DoxyCodeLine{95            \textcolor{stringliteral}{'as convective mixing might occur in the boundary layer.'})}
\DoxyCodeLine{96 \textcolor{keywordflow}{  endif}}
\DoxyCodeLine{97 }
\DoxyCodeLine{98   \textcolor{keyword}{call }get\_param(param\_file, mdl, \textcolor{stringliteral}{'DEBUG'}, cs\%debug, default=.false., do\_not\_log=.true.)}
\DoxyCodeLine{99 }
\DoxyCodeLine{100   \textcolor{keyword}{call }get\_param(param\_file, mdl, \textcolor{stringliteral}{'MIN\_THICKNESS'}, cs\%min\_thickness, default=0.001, do\_not\_log=.true.)}
\DoxyCodeLine{101 }
\DoxyCodeLine{102   \textcolor{keyword}{call }openparameterblock(param\_file,\textcolor{stringliteral}{'CVMix\_CONVECTION'})}
\DoxyCodeLine{103 }
\DoxyCodeLine{104   \textcolor{keyword}{call }get\_param(param\_file, mdl, \textcolor{stringliteral}{"PRANDTL\_CONV"}, prandtl\_conv, \&}
\DoxyCodeLine{105                  \textcolor{stringliteral}{"The turbulent Prandtl number applied to convective "}//\&}
\DoxyCodeLine{106                  \textcolor{stringliteral}{"instabilities (i.e., used to convert KD\_CONV into KV\_CONV)"}, \&}
\DoxyCodeLine{107                  units=\textcolor{stringliteral}{"nondim"}, default=1.0)}
\DoxyCodeLine{108 }
\DoxyCodeLine{109   \textcolor{keyword}{call }get\_param(param\_file, mdl, \textcolor{stringliteral}{'KD\_CONV'}, cs\%kd\_conv\_const, \&}
\DoxyCodeLine{110                  \textcolor{stringliteral}{"Diffusivity used in convective regime. Corresponding viscosity "}//\&}
\DoxyCodeLine{111                  \textcolor{stringliteral}{"(KV\_CONV) will be set to KD\_CONV * PRANDTL\_TURB."}, \&}
\DoxyCodeLine{112                  units=\textcolor{stringliteral}{'m2/s'}, default=1.00)}
\DoxyCodeLine{113 }
\DoxyCodeLine{114   \textcolor{keyword}{call }get\_param(param\_file, mdl, \textcolor{stringliteral}{'BV\_SQR\_CONV'}, cs\%bv\_sqr\_conv, \&}
\DoxyCodeLine{115                  \textcolor{stringliteral}{"Threshold for squared buoyancy frequency needed to trigger "}//\&}
\DoxyCodeLine{116                  \textcolor{stringliteral}{"Brunt-\/Vaisala parameterization."}, \&}
\DoxyCodeLine{117                  units=\textcolor{stringliteral}{'1/s\string^2'}, default=0.0)}
\DoxyCodeLine{118 }
\DoxyCodeLine{119   \textcolor{keyword}{call }closeparameterblock(param\_file)}
\DoxyCodeLine{120 }
\DoxyCodeLine{121   \textcolor{comment}{! set kv\_conv\_const based on kd\_conv\_const and prandtl\_conv}}
\DoxyCodeLine{122   cs\%kv\_conv\_const = cs\%kd\_conv\_const * prandtl\_conv}
\DoxyCodeLine{123 }
\DoxyCodeLine{124   \textcolor{comment}{! Register diagnostics}}
\DoxyCodeLine{125   cs\%diag => diag}
\DoxyCodeLine{126   cs\%id\_N2 = register\_diag\_field(\textcolor{stringliteral}{'ocean\_model'}, \textcolor{stringliteral}{'N2\_conv'}, diag\%axesTi, time, \&}
\DoxyCodeLine{127       \textcolor{stringliteral}{'Square of Brunt-\/Vaisala frequency used by MOM\_CVMix\_conv module'}, \textcolor{stringliteral}{'1/s2'}, conversion=us\%s\_to\_T**2)}
\DoxyCodeLine{128   cs\%id\_kd\_conv = register\_diag\_field(\textcolor{stringliteral}{'ocean\_model'}, \textcolor{stringliteral}{'kd\_conv'}, diag\%axesTi, time, \&}
\DoxyCodeLine{129       \textcolor{stringliteral}{'Additional diffusivity added by MOM\_CVMix\_conv module'}, \textcolor{stringliteral}{'m2/s'}, conversion=us\%Z2\_T\_to\_m2\_s)}
\DoxyCodeLine{130   cs\%id\_kv\_conv = register\_diag\_field(\textcolor{stringliteral}{'ocean\_model'}, \textcolor{stringliteral}{'kv\_conv'}, diag\%axesTi, time, \&}
\DoxyCodeLine{131       \textcolor{stringliteral}{'Additional viscosity added by MOM\_CVMix\_conv module'}, \textcolor{stringliteral}{'m2/s'}, conversion=us\%Z2\_T\_to\_m2\_s)}
\DoxyCodeLine{132 }
\DoxyCodeLine{133   \textcolor{keyword}{call }cvmix\_init\_conv(convect\_diff=cs\%kd\_conv\_const, \&}
\DoxyCodeLine{134                        convect\_visc=cs\%kv\_conv\_const, \&}
\DoxyCodeLine{135                        lbruntvaisala=.true.,    \&}
\DoxyCodeLine{136                        bvsqr\_convect=cs\%bv\_sqr\_conv)}
\DoxyCodeLine{137 }

\end{DoxyCode}
\mbox{\Hypertarget{namespacemom__cvmix__conv_a5e741c84ad14fae3e5801d00a9867bba}\label{namespacemom__cvmix__conv_a5e741c84ad14fae3e5801d00a9867bba}} 
\index{mom\_cvmix\_conv@{mom\_cvmix\_conv}!cvmix\_conv\_is\_used@{cvmix\_conv\_is\_used}}
\index{cvmix\_conv\_is\_used@{cvmix\_conv\_is\_used}!mom\_cvmix\_conv@{mom\_cvmix\_conv}}
\doxysubsubsection{\texorpdfstring{cvmix\_conv\_is\_used()}{cvmix\_conv\_is\_used()}}
{\footnotesize\ttfamily logical function, public mom\+\_\+cvmix\+\_\+conv\+::cvmix\+\_\+conv\+\_\+is\+\_\+used (\begin{DoxyParamCaption}\item[{type(param\+\_\+file\+\_\+type), intent(in)}]{param\+\_\+file }\end{DoxyParamCaption})}



Reads the parameter \char`\"{}\+U\+S\+E\+\_\+\+C\+V\+Mix\+\_\+\+C\+O\+N\+V\+E\+C\+T\+I\+O\+N\char`\"{} and returns state. This function allows other modules to know whether this parameterization will be used without needing to duplicate the log entry. 


\begin{DoxyParams}[1]{Parameters}
\mbox{\texttt{ in}}  & {\em param\+\_\+file} & A structure to parse for run-\/time parameters \\
\hline
\end{DoxyParams}


Definition at line 305 of file M\+O\+M\+\_\+\+C\+V\+Mix\+\_\+conv.\+F90.


\begin{DoxyCode}{0}
\DoxyCodeLine{306   \textcolor{keywordtype}{type}(param\_file\_type), \textcolor{keywordtype}{intent(in)} :: param\_file\textcolor{comment}{ !< A structure to parse for run-\/time parameters}}
\DoxyCodeLine{307   \textcolor{keyword}{call }get\_param(param\_file, mdl, \textcolor{stringliteral}{"USE\_CVMix\_CONVECTION"}, cvmix\_conv\_is\_used, \&}
\DoxyCodeLine{308                  default=.false., do\_not\_log = .true.)}
\DoxyCodeLine{309 }

\end{DoxyCode}
