\hypertarget{namespacemom__full__convection}{}\section{mom\+\_\+full\+\_\+convection Module Reference}
\label{namespacemom__full__convection}\index{mom\_full\_convection@{mom\_full\_convection}}


\subsection{Detailed Description}
Does full convective adjustment of unstable regions via a strong diffusivity. \subsection*{Functions/\+Subroutines}
\begin{DoxyCompactItemize}
\item 
subroutine, public \mbox{\hyperlink{namespacemom__full__convection_aee19e41a18bd855cd01c4ebf4eefcaad}{full\+\_\+convection}} (G, GV, US, h, tv, T\+\_\+adj, S\+\_\+adj, p\+\_\+surf, Kddt\+\_\+smooth, Kddt\+\_\+convect, halo)
\begin{DoxyCompactList}\small\item\em Calculate new temperatures and salinities that have been subject to full convective mixing. \end{DoxyCompactList}\item 
logical function \mbox{\hyperlink{namespacemom__full__convection_a2d2d4f8f10e25a0d9dc9bdfbf6729fe0}{is\+\_\+unstable}} (d\+Rho\+\_\+dT, d\+Rho\+\_\+dS, h\+\_\+a, h\+\_\+b, mix\+\_\+A, mix\+\_\+B, T\+\_\+a, T\+\_\+b, S\+\_\+a, S\+\_\+b, Te\+\_\+aa, Te\+\_\+bb, Se\+\_\+aa, Se\+\_\+bb, d\+\_\+A, d\+\_\+B)
\begin{DoxyCompactList}\small\item\em This function returns True if the profiles around the given interface will be statically unstable after mixing above below. The arguments are the ocean state above and below, including partial calculations from a tridiagonal solver. \end{DoxyCompactList}\item 
subroutine \mbox{\hyperlink{namespacemom__full__convection_af762a0514a81af81b0acc7553dbcffe3}{smoothed\+\_\+drdt\+\_\+drds}} (h, tv, Kddt, d\+R\+\_\+dT, d\+R\+\_\+dS, G, GV, US, j, p\+\_\+surf, halo)
\begin{DoxyCompactList}\small\item\em Returns the partial derivatives of locally referenced potential density with temperature and salinity after the properties have been smoothed with a small constant diffusivity. \end{DoxyCompactList}\end{DoxyCompactItemize}


\subsection{Function/\+Subroutine Documentation}
\mbox{\Hypertarget{namespacemom__full__convection_aee19e41a18bd855cd01c4ebf4eefcaad}\label{namespacemom__full__convection_aee19e41a18bd855cd01c4ebf4eefcaad}} 
\index{mom\_full\_convection@{mom\_full\_convection}!full\_convection@{full\_convection}}
\index{full\_convection@{full\_convection}!mom\_full\_convection@{mom\_full\_convection}}
\subsubsection{\texorpdfstring{full\_convection()}{full\_convection()}}
{\footnotesize\ttfamily subroutine, public mom\+\_\+full\+\_\+convection\+::full\+\_\+convection (\begin{DoxyParamCaption}\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( g \%isd\+: g \%ied, g \%jsd\+: g \%jed, g \%ke), intent(in)}]{h,  }\item[{type(thermo\+\_\+var\+\_\+ptrs), intent(in)}]{tv,  }\item[{real, dimension( g \%isd\+: g \%ied, g \%jsd\+: g \%jed, g \%ke), intent(out)}]{T\+\_\+adj,  }\item[{real, dimension( g \%isd\+: g \%ied, g \%jsd\+: g \%jed, g \%ke), intent(out)}]{S\+\_\+adj,  }\item[{real, dimension(\+:,\+:), pointer}]{p\+\_\+surf,  }\item[{real, intent(in)}]{Kddt\+\_\+smooth,  }\item[{real, intent(in), optional}]{Kddt\+\_\+convect,  }\item[{integer, intent(in), optional}]{halo }\end{DoxyParamCaption})}



Calculate new temperatures and salinities that have been subject to full convective mixing. 


\begin{DoxyParams}[1]{Parameters}
\mbox{\texttt{ in}}  & {\em g} & The ocean\textquotesingle{}s grid structure \\
\hline
\mbox{\texttt{ in}}  & {\em gv} & The ocean\textquotesingle{}s vertical grid structure \\
\hline
\mbox{\texttt{ in}}  & {\em us} & A dimensional unit scaling type \\
\hline
\mbox{\texttt{ in}}  & {\em h} & Layer thicknesses \mbox{[}H $\sim$$>$ m or kg m-\/2\mbox{]} \\
\hline
\mbox{\texttt{ in}}  & {\em tv} & A structure pointing to various thermodynamic variables \\
\hline
\mbox{\texttt{ out}}  & {\em t\+\_\+adj} & Adjusted potential temperature \mbox{[}degC\mbox{]}. \\
\hline
\mbox{\texttt{ out}}  & {\em s\+\_\+adj} & Adjusted salinity \mbox{[}ppt\mbox{]}. \\
\hline
 & {\em p\+\_\+surf} & The pressure at the ocean surface \mbox{[}R L2 T-\/2 $\sim$$>$ Pa\mbox{]} (or N\+U\+LL). \\
\hline
\mbox{\texttt{ in}}  & {\em kddt\+\_\+smooth} & A smoothing vertical diffusivity times a timestep \mbox{[}H2 $\sim$$>$ m2 or kg2 m-\/4\mbox{]}. \\
\hline
\mbox{\texttt{ in}}  & {\em kddt\+\_\+convect} & A large convecting vertical diffusivity times a timestep \mbox{[}H2 $\sim$$>$ m2 or kg2 m-\/4\mbox{]}. \\
\hline
\mbox{\texttt{ in}}  & {\em halo} & Halo width over which to compute \\
\hline
\end{DoxyParams}


Definition at line 23 of file M\+O\+M\+\_\+full\+\_\+convection.\+F90.


\begin{DoxyCode}{0}
\DoxyCodeLine{23   \textcolor{keywordtype}{type}(ocean\_grid\_type),   \textcolor{keywordtype}{intent(in)}    :: G\textcolor{comment}{     !< The ocean's grid structure}}
\DoxyCodeLine{24   \textcolor{keywordtype}{type}(verticalGrid\_type), \textcolor{keywordtype}{intent(in)}    :: GV\textcolor{comment}{    !< The ocean's vertical grid structure}}
\DoxyCodeLine{25   \textcolor{keywordtype}{type}(unit\_scale\_type),   \textcolor{keywordtype}{intent(in)}    :: US\textcolor{comment}{   !< A dimensional unit scaling type}}
\DoxyCodeLine{26 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(SZI\_(G),SZJ\_(G),SZK\_(G))}, \&}
\DoxyCodeLine{27                            \textcolor{keywordtype}{intent(in)}    :: h\textcolor{comment}{     !< Layer thicknesses [H ~> m or kg m-2]}}
\DoxyCodeLine{28   \textcolor{keywordtype}{type}(thermo\_var\_ptrs),   \textcolor{keywordtype}{intent(in)}    :: tv\textcolor{comment}{    !< A structure pointing to various}}
\DoxyCodeLine{29 \textcolor{comment}{                                                  !! thermodynamic variables}}
\DoxyCodeLine{30 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(SZI\_(G),SZJ\_(G),SZK\_(G))}, \&}
\DoxyCodeLine{31                            \textcolor{keywordtype}{intent(out)}   :: T\_adj\textcolor{comment}{ !< Adjusted potential temperature [degC].}}
\DoxyCodeLine{32 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(SZI\_(G),SZJ\_(G),SZK\_(G))}, \&}
\DoxyCodeLine{33                            \textcolor{keywordtype}{intent(out)}   :: S\_adj\textcolor{comment}{ !< Adjusted salinity [ppt].}}
\DoxyCodeLine{34 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(:,:)},    \textcolor{keywordtype}{pointer}       :: p\_surf\textcolor{comment}{ !< The pressure at the ocean surface [R L2 T-2 ~> Pa] (or NULL).}}
\DoxyCodeLine{35 \textcolor{keywordtype}{  real},                    \textcolor{keywordtype}{intent(in)}    :: Kddt\_smooth\textcolor{comment}{  !< A smoothing vertical}}
\DoxyCodeLine{36 \textcolor{comment}{                                                  !! diffusivity times a timestep [H2 ~> m2 or kg2 m-4].}}
\DoxyCodeLine{37 \textcolor{keywordtype}{  real},          \textcolor{keywordtype}{optional}, \textcolor{keywordtype}{intent(in)}    :: Kddt\_convect\textcolor{comment}{ !< A large convecting vertical}}
\DoxyCodeLine{38 \textcolor{comment}{                                                  !! diffusivity times a timestep [H2 ~> m2 or kg2 m-4].}}
\DoxyCodeLine{39   \textcolor{keywordtype}{integer},       \textcolor{keywordtype}{optional}, \textcolor{keywordtype}{intent(in)}    :: halo\textcolor{comment}{  !< Halo width over which to compute}}
\DoxyCodeLine{40 }
\DoxyCodeLine{41   \textcolor{comment}{! Local variables}}
\DoxyCodeLine{42 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(SZI\_(G),SZK\_(G)+1)} :: \&}
\DoxyCodeLine{43     dRho\_dT, \&  \textcolor{comment}{! The derivative of density with temperature [R degC-1 ~> kg m-3 degC-1]}}
\DoxyCodeLine{44     dRho\_dS     \textcolor{comment}{! The derivative of density with salinity [R ppt-1 ~> kg m-3 ppt-1].}}
\DoxyCodeLine{45 \textcolor{keywordtype}{  real} :: h\_neglect, h0 \textcolor{comment}{! A thickness that is so small it is usually lost}}
\DoxyCodeLine{46                         \textcolor{comment}{! in roundoff and can be neglected [H ~> m or kg m-2].}}
\DoxyCodeLine{47 \textcolor{comment}{! logical :: use\_EOS    ! If true, density is calculated from T \& S using an equation of state.}}
\DoxyCodeLine{48 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(SZI\_(G),SZK0\_(G))} :: \&}
\DoxyCodeLine{49     Te\_a, \& \textcolor{comment}{! A partially updated temperature estimate including the influnce from}}
\DoxyCodeLine{50             \textcolor{comment}{! mixing with layers above rescaled by a factor of d\_a [degC].}}
\DoxyCodeLine{51             \textcolor{comment}{! This array is discreted on tracer cells, but contains an extra}}
\DoxyCodeLine{52             \textcolor{comment}{! layer at the top for algorithmic convenience.}}
\DoxyCodeLine{53     se\_a    \textcolor{comment}{! A partially updated salinity estimate including the influnce from}}
\DoxyCodeLine{54             \textcolor{comment}{! mixing with layers above rescaled by a factor of d\_a [ppt].}}
\DoxyCodeLine{55             \textcolor{comment}{! This array is discreted on tracer cells, but contains an extra}}
\DoxyCodeLine{56             \textcolor{comment}{! layer at the top for algorithmic convenience.}}
\DoxyCodeLine{57 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(SZI\_(G),SZK\_(G)+1)} :: \&}
\DoxyCodeLine{58     Te\_b, \& \textcolor{comment}{! A partially updated temperature estimate including the influnce from}}
\DoxyCodeLine{59             \textcolor{comment}{! mixing with layers below rescaled by a factor of d\_b [degC].}}
\DoxyCodeLine{60             \textcolor{comment}{! This array is discreted on tracer cells, but contains an extra}}
\DoxyCodeLine{61             \textcolor{comment}{! layer at the bottom for algorithmic convenience.}}
\DoxyCodeLine{62     se\_b    \textcolor{comment}{! A partially updated salinity estimate including the influnce from}}
\DoxyCodeLine{63             \textcolor{comment}{! mixing with layers below rescaled by a factor of d\_b [ppt].}}
\DoxyCodeLine{64             \textcolor{comment}{! This array is discreted on tracer cells, but contains an extra}}
\DoxyCodeLine{65             \textcolor{comment}{! layer at the bottom for algorithmic convenience.}}
\DoxyCodeLine{66 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(SZI\_(G),SZK\_(G)+1)} :: \&}
\DoxyCodeLine{67     c\_a, \&  \textcolor{comment}{! The fractional influence of the properties of the layer below}}
\DoxyCodeLine{68             \textcolor{comment}{! in the final properies with a downward-first solver, nondim.}}
\DoxyCodeLine{69     d\_a, \&  \textcolor{comment}{! The fractional influence of the properties of the layer in question}}
\DoxyCodeLine{70             \textcolor{comment}{! and layers above in the final properies with a downward-first solver, nondim.}}
\DoxyCodeLine{71             \textcolor{comment}{! d\_a = 1.0 - c\_a}}
\DoxyCodeLine{72     c\_b, \&  \textcolor{comment}{! The fractional influence of the properties of the layer above}}
\DoxyCodeLine{73             \textcolor{comment}{! in the final properies with a upward-first solver, nondim.}}
\DoxyCodeLine{74     d\_b     \textcolor{comment}{! The fractional influence of the properties of the layer in question}}
\DoxyCodeLine{75             \textcolor{comment}{! and layers below in the final properies with a upward-first solver, nondim.}}
\DoxyCodeLine{76             \textcolor{comment}{! d\_b = 1.0 - c\_b}}
\DoxyCodeLine{77 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(SZI\_(G),SZK\_(G)+1)} :: \&}
\DoxyCodeLine{78     mix\textcolor{comment}{     !< The amount of mixing across the interface between layers [H ~> m or kg m-2].}}
\DoxyCodeLine{79 \textcolor{keywordtype}{  real} :: mix\_len  \textcolor{comment}{! The length-scale of mixing, when it is active [H ~> m or kg m-2]}}
\DoxyCodeLine{80 \textcolor{keywordtype}{  real} :: h\_b, h\_a \textcolor{comment}{! The thicknessses of the layers above and below an interface [H ~> m or kg m-2]}}
\DoxyCodeLine{81 \textcolor{keywordtype}{  real} :: b\_b, b\_a \textcolor{comment}{! Inverse pivots used by the tridiagonal solver [H-1 ~> m-1 or m2 kg-1].}}
\DoxyCodeLine{82 }
\DoxyCodeLine{83 \textcolor{keywordtype}{  real} :: kap\_dt\_x2 \textcolor{comment}{! The product of 2*kappa*dt [H2 ~> m2 or kg2 m-4].}}
\DoxyCodeLine{84 }
\DoxyCodeLine{85   \textcolor{keywordtype}{logical}, \textcolor{keywordtype}{dimension(SZI\_(G))} :: do\_i \textcolor{comment}{! Do more work on this column.}}
\DoxyCodeLine{86   \textcolor{keywordtype}{logical}, \textcolor{keywordtype}{dimension(SZI\_(G))} :: last\_down \textcolor{comment}{! The last setup pass was downward.}}
\DoxyCodeLine{87   \textcolor{keywordtype}{integer}, \textcolor{keywordtype}{dimension(SZI\_(G))} :: change\_ct \textcolor{comment}{! The number of interfaces where the}}
\DoxyCodeLine{88                          \textcolor{comment}{! mixing has changed this iteration.}}
\DoxyCodeLine{89   \textcolor{keywordtype}{integer} :: changed\_col \textcolor{comment}{! The number of colums whose mixing changed.}}
\DoxyCodeLine{90   \textcolor{keywordtype}{integer} :: i, j, k, is, ie, js, je, nz, itt}
\DoxyCodeLine{91 }
\DoxyCodeLine{92   \textcolor{keywordflow}{if} (\textcolor{keyword}{present}(halo)) \textcolor{keywordflow}{then}}
\DoxyCodeLine{93     is = g\%isc-halo ; ie = g\%iec+halo ; js = g\%jsc-halo ; je = g\%jec+halo}
\DoxyCodeLine{94   \textcolor{keywordflow}{else}}
\DoxyCodeLine{95     is = g\%isc ; ie = g\%iec ; js = g\%jsc ; je = g\%jec}
\DoxyCodeLine{96 \textcolor{keywordflow}{  endif}}
\DoxyCodeLine{97   nz = g\%ke}
\DoxyCodeLine{98 }
\DoxyCodeLine{99   \textcolor{keywordflow}{if} (.not.\textcolor{keyword}{associated}(tv\%eqn\_of\_state)) \textcolor{keywordflow}{return}}
\DoxyCodeLine{100 }
\DoxyCodeLine{101   h\_neglect = gv\%H\_subroundoff}
\DoxyCodeLine{102   kap\_dt\_x2 = 0.0}
\DoxyCodeLine{103   \textcolor{keywordflow}{if} (\textcolor{keyword}{present}(kddt\_convect)) kap\_dt\_x2 = 2.0*kddt\_convect}
\DoxyCodeLine{104   mix\_len = (1.0e20 * nz) * (g\%max\_depth * gv\%Z\_to\_H)}
\DoxyCodeLine{105   h0 = 1.0e-16*sqrt(kddt\_smooth) + h\_neglect}
\DoxyCodeLine{106 }
\DoxyCodeLine{107   \textcolor{keywordflow}{do} j=js,je}
\DoxyCodeLine{108     mix(:,:) = 0.0 ; d\_b(:,:) = 1.0}
\DoxyCodeLine{109     \textcolor{comment}{! These would be Te\_b(:,:) = tv\%T(:,j,:), etc., but the values are not used}}
\DoxyCodeLine{110     te\_b(:,:) = 0.0 ; se\_b(:,:) = 0.0}
\DoxyCodeLine{111 }
\DoxyCodeLine{112     \textcolor{keyword}{call }smoothed\_drdt\_drds(h, tv, kddt\_smooth, drho\_dt, drho\_ds, g, gv, us, j, p\_surf, halo)}
\DoxyCodeLine{113 }
\DoxyCodeLine{114     \textcolor{keywordflow}{do} i=is,ie}
\DoxyCodeLine{115       do\_i(i) = (g\%mask2dT(i,j) > 0.0)}
\DoxyCodeLine{116 }
\DoxyCodeLine{117       d\_a(i,1) = 1.0}
\DoxyCodeLine{118       last\_down(i) = .true. \textcolor{comment}{! This is set for debuggers.}}
\DoxyCodeLine{119       \textcolor{comment}{! These are extra values are used for convenience in the stability test}}
\DoxyCodeLine{120       te\_a(i,0) = 0.0 ; se\_a(i,0) = 0.0}
\DoxyCodeLine{121 \textcolor{keywordflow}{    enddo}}
\DoxyCodeLine{122 }
\DoxyCodeLine{123     \textcolor{keywordflow}{do} itt=1,nz \textcolor{comment}{! At least 2 interfaces will change with each full pass, or the}}
\DoxyCodeLine{124                 \textcolor{comment}{! iterations stop, so the maximum count of nz is very conservative.}}
\DoxyCodeLine{125 }
\DoxyCodeLine{126       \textcolor{keywordflow}{do} i=is,ie ; change\_ct(i) = 0 ;\textcolor{keywordflow}{ enddo}}
\DoxyCodeLine{127       \textcolor{comment}{! Move down the water column, finding unstable interfaces, and building up the}}
\DoxyCodeLine{128       \textcolor{comment}{! temporary arrays for the tridiagonal solver.}}
\DoxyCodeLine{129       \textcolor{keywordflow}{do} k=2,nz ; \textcolor{keywordflow}{do} i=is,ie ; \textcolor{keywordflow}{if} (do\_i(i)) \textcolor{keywordflow}{then}}
\DoxyCodeLine{130 }
\DoxyCodeLine{131         h\_a = h(i,j,k-1) + h\_neglect ; h\_b = h(i,j,k) + h\_neglect}
\DoxyCodeLine{132         \textcolor{keywordflow}{if} (mix(i,k) <= 0.0) \textcolor{keywordflow}{then}}
\DoxyCodeLine{133           \textcolor{keywordflow}{if} (is\_unstable(drho\_dt(i,k), drho\_ds(i,k), h\_a, h\_b, mix(i,k-1), mix(i,k+1), \&}
\DoxyCodeLine{134                           tv\%T(i,j,k-1), tv\%T(i,j,k), tv\%S(i,j,k-1), tv\%S(i,j,k), \&}
\DoxyCodeLine{135                           te\_a(i,k-2), te\_b(i,k+1), se\_a(i,k-2), se\_b(i,k+1), \&}
\DoxyCodeLine{136                           d\_a(i,k-1), d\_b(i,k+1))) \textcolor{keywordflow}{then}}
\DoxyCodeLine{137             mix(i,k) = mix\_len}
\DoxyCodeLine{138             \textcolor{keywordflow}{if} (kap\_dt\_x2 > 0.0) mix(i,k) = kap\_dt\_x2 / ((h(i,j,k-1)+h(i,j,k)) + h0)}
\DoxyCodeLine{139             change\_ct(i) = change\_ct(i) + 1}
\DoxyCodeLine{140 \textcolor{keywordflow}{          endif}}
\DoxyCodeLine{141 \textcolor{keywordflow}{        endif}}
\DoxyCodeLine{142 }
\DoxyCodeLine{143         b\_a = 1.0 / ((h\_a + d\_a(i,k-1)*mix(i,k-1)) + mix(i,k))}
\DoxyCodeLine{144         \textcolor{keywordflow}{if} (mix(i,k) <= 0.0) \textcolor{keywordflow}{then}}
\DoxyCodeLine{145           c\_a(i,k) = 0.0 ; d\_a(i,k) = 1.0}
\DoxyCodeLine{146         \textcolor{keywordflow}{else}}
\DoxyCodeLine{147           d\_a(i,k) = b\_a * (h\_a + d\_a(i,k-1)*mix(i,k-1)) \textcolor{comment}{! = 1.0-c\_a(i,K)}}
\DoxyCodeLine{148           c\_a(i,k) = 1.0 ; \textcolor{keywordflow}{if} (d\_a(i,k) > epsilon(b\_a)) c\_a(i,k) = b\_a * mix(i,k)}
\DoxyCodeLine{149 \textcolor{keywordflow}{        endif}}
\DoxyCodeLine{150 }
\DoxyCodeLine{151         \textcolor{keywordflow}{if} (k>2) \textcolor{keywordflow}{then}}
\DoxyCodeLine{152           te\_a(i,k-1) = b\_a * (h\_a*tv\%T(i,j,k-1) + mix(i,k-1)*te\_a(i,k-2))}
\DoxyCodeLine{153           se\_a(i,k-1) = b\_a * (h\_a*tv\%S(i,j,k-1) + mix(i,k-1)*se\_a(i,k-2))}
\DoxyCodeLine{154         \textcolor{keywordflow}{else}}
\DoxyCodeLine{155           te\_a(i,k-1) = b\_a * (h\_a*tv\%T(i,j,k-1))}
\DoxyCodeLine{156           se\_a(i,k-1) = b\_a * (h\_a*tv\%S(i,j,k-1))}
\DoxyCodeLine{157 \textcolor{keywordflow}{        endif}}
\DoxyCodeLine{158 \textcolor{keywordflow}{      endif} ;\textcolor{keywordflow}{ enddo} ;\textcolor{keywordflow}{ enddo}}
\DoxyCodeLine{159 }
\DoxyCodeLine{160       \textcolor{comment}{! Determine which columns might have further instabilities.}}
\DoxyCodeLine{161       changed\_col = 0}
\DoxyCodeLine{162       \textcolor{keywordflow}{do} i=is,ie ; \textcolor{keywordflow}{if} (do\_i(i)) \textcolor{keywordflow}{then}}
\DoxyCodeLine{163         \textcolor{keywordflow}{if} (change\_ct(i) == 0) \textcolor{keywordflow}{then}}
\DoxyCodeLine{164           last\_down(i) = .true. ; do\_i(i) = .false.}
\DoxyCodeLine{165         \textcolor{keywordflow}{else}}
\DoxyCodeLine{166           changed\_col = changed\_col + 1 ; change\_ct(i) = 0}
\DoxyCodeLine{167 \textcolor{keywordflow}{        endif}}
\DoxyCodeLine{168 \textcolor{keywordflow}{      endif} ;\textcolor{keywordflow}{ enddo}}
\DoxyCodeLine{169       \textcolor{keywordflow}{if} (changed\_col == 0) \textcolor{keywordflow}{exit} \textcolor{comment}{! No more columns are unstable.}}
\DoxyCodeLine{170 }
\DoxyCodeLine{171       \textcolor{comment}{! This is the same as above, but with the direction reversed (bottom to top)}}
\DoxyCodeLine{172       \textcolor{keywordflow}{do} k=nz,2,-1 ; \textcolor{keywordflow}{do} i=is,ie ; \textcolor{keywordflow}{if} (do\_i(i)) \textcolor{keywordflow}{then}}
\DoxyCodeLine{173 }
\DoxyCodeLine{174         h\_a = h(i,j,k-1) + h\_neglect ; h\_b = h(i,j,k) + h\_neglect}
\DoxyCodeLine{175         \textcolor{keywordflow}{if} (mix(i,k) <= 0.0) \textcolor{keywordflow}{then}}
\DoxyCodeLine{176           \textcolor{keywordflow}{if} (is\_unstable(drho\_dt(i,k), drho\_ds(i,k), h\_a, h\_b, mix(i,k-1), mix(i,k+1), \&}
\DoxyCodeLine{177                           tv\%T(i,j,k-1), tv\%T(i,j,k), tv\%S(i,j,k-1), tv\%S(i,j,k), \&}
\DoxyCodeLine{178                           te\_a(i,k-2), te\_b(i,k+1), se\_a(i,k-2), se\_b(i,k+1), \&}
\DoxyCodeLine{179                           d\_a(i,k-1), d\_b(i,k+1))) \textcolor{keywordflow}{then}}
\DoxyCodeLine{180             mix(i,k) = mix\_len}
\DoxyCodeLine{181             \textcolor{keywordflow}{if} (kap\_dt\_x2 > 0.0) mix(i,k) = kap\_dt\_x2 / ((h(i,j,k-1)+h(i,j,k)) + h0)}
\DoxyCodeLine{182             change\_ct(i) = change\_ct(i) + 1}
\DoxyCodeLine{183 \textcolor{keywordflow}{          endif}}
\DoxyCodeLine{184 \textcolor{keywordflow}{        endif}}
\DoxyCodeLine{185 }
\DoxyCodeLine{186         b\_b = 1.0 / ((h\_b + d\_b(i,k+1)*mix(i,k+1)) + mix(i,k))}
\DoxyCodeLine{187         \textcolor{keywordflow}{if} (mix(i,k) <= 0.0) \textcolor{keywordflow}{then}}
\DoxyCodeLine{188           c\_b(i,k) = 0.0 ; d\_b(i,k) = 1.0}
\DoxyCodeLine{189         \textcolor{keywordflow}{else}}
\DoxyCodeLine{190           d\_b(i,k) = b\_b * (h\_b + d\_b(i,k+1)*mix(i,k+1)) \textcolor{comment}{! = 1.0-c\_b(i,K)}}
\DoxyCodeLine{191           c\_b(i,k) = 1.0 ; \textcolor{keywordflow}{if} (d\_b(i,k) > epsilon(b\_b)) c\_b(i,k) = b\_b * mix(i,k)}
\DoxyCodeLine{192 \textcolor{keywordflow}{        endif}}
\DoxyCodeLine{193 }
\DoxyCodeLine{194         \textcolor{keywordflow}{if} (k<nz) \textcolor{keywordflow}{then}}
\DoxyCodeLine{195           te\_b(i,k) = b\_b * (h\_b*tv\%T(i,j,k) + mix(i,k+1)*te\_b(i,k+1))}
\DoxyCodeLine{196           se\_b(i,k) = b\_b * (h\_b*tv\%S(i,j,k) + mix(i,k+1)*se\_b(i,k+1))}
\DoxyCodeLine{197         \textcolor{keywordflow}{else}}
\DoxyCodeLine{198           te\_b(i,k) = b\_b * (h\_b*tv\%T(i,j,k))}
\DoxyCodeLine{199           se\_b(i,k) = b\_b * (h\_b*tv\%S(i,j,k))}
\DoxyCodeLine{200 \textcolor{keywordflow}{        endif}}
\DoxyCodeLine{201 \textcolor{keywordflow}{      endif} ;\textcolor{keywordflow}{ enddo} ;\textcolor{keywordflow}{ enddo}}
\DoxyCodeLine{202 }
\DoxyCodeLine{203       \textcolor{comment}{! Determine which columns might have further instabilities.}}
\DoxyCodeLine{204       changed\_col = 0}
\DoxyCodeLine{205       \textcolor{keywordflow}{do} i=is,ie ; \textcolor{keywordflow}{if} (do\_i(i)) \textcolor{keywordflow}{then}}
\DoxyCodeLine{206         \textcolor{keywordflow}{if} (change\_ct(i) == 0) \textcolor{keywordflow}{then}}
\DoxyCodeLine{207           last\_down(i) = .false. ; do\_i(i) = .false.}
\DoxyCodeLine{208         \textcolor{keywordflow}{else}}
\DoxyCodeLine{209           changed\_col = changed\_col + 1 ; change\_ct(i) = 0}
\DoxyCodeLine{210 \textcolor{keywordflow}{        endif}}
\DoxyCodeLine{211 \textcolor{keywordflow}{      endif} ;\textcolor{keywordflow}{ enddo}}
\DoxyCodeLine{212       \textcolor{keywordflow}{if} (changed\_col == 0) \textcolor{keywordflow}{exit} \textcolor{comment}{! No more columns are unstable.}}
\DoxyCodeLine{213 }
\DoxyCodeLine{214 \textcolor{keywordflow}{    enddo}  \textcolor{comment}{! End of iterations, all columns are now stable.}}
\DoxyCodeLine{215 }
\DoxyCodeLine{216     \textcolor{comment}{! Do the final return pass on the columns where the penultimate pass was downward.}}
\DoxyCodeLine{217     \textcolor{keywordflow}{do} i=is,ie ; do\_i(i) = ((g\%mask2dT(i,j) > 0.0) .and. last\_down(i)) ;\textcolor{keywordflow}{ enddo}}
\DoxyCodeLine{218     \textcolor{keywordflow}{do} i=is,ie ; \textcolor{keywordflow}{if} (do\_i(i)) \textcolor{keywordflow}{then}}
\DoxyCodeLine{219       h\_a = h(i,j,nz) + h\_neglect}
\DoxyCodeLine{220       b\_a = 1.0 / (h\_a + d\_a(i,nz)*mix(i,nz))}
\DoxyCodeLine{221       t\_adj(i,j,nz) = b\_a * (h\_a*tv\%T(i,j,nz) + mix(i,nz)*te\_a(i,nz-1))}
\DoxyCodeLine{222       s\_adj(i,j,nz) = b\_a * (h\_a*tv\%S(i,j,nz) + mix(i,nz)*se\_a(i,nz-1))}
\DoxyCodeLine{223 \textcolor{keywordflow}{    endif} ;\textcolor{keywordflow}{ enddo}}
\DoxyCodeLine{224     \textcolor{keywordflow}{do} k=nz-1,1,-1 ; \textcolor{keywordflow}{do} i=is,ie ; \textcolor{keywordflow}{if} (do\_i(i)) \textcolor{keywordflow}{then}}
\DoxyCodeLine{225       t\_adj(i,j,k) = te\_a(i,k) + c\_a(i,k+1)*t\_adj(i,j,k+1)}
\DoxyCodeLine{226       s\_adj(i,j,k) = se\_a(i,k) + c\_a(i,k+1)*s\_adj(i,j,k+1)}
\DoxyCodeLine{227 \textcolor{keywordflow}{    endif} ;\textcolor{keywordflow}{ enddo} ;\textcolor{keywordflow}{ enddo}}
\DoxyCodeLine{228 }
\DoxyCodeLine{229     \textcolor{keywordflow}{do} i=is,ie ; \textcolor{keywordflow}{if} (do\_i(i)) \textcolor{keywordflow}{then}}
\DoxyCodeLine{230       k = 1 \textcolor{comment}{! A hook for debugging.}}
\DoxyCodeLine{231 \textcolor{keywordflow}{    endif} ;\textcolor{keywordflow}{ enddo}}
\DoxyCodeLine{232 }
\DoxyCodeLine{233     \textcolor{comment}{! Do the final return pass on the columns where the penultimate pass was upward.}}
\DoxyCodeLine{234     \textcolor{comment}{! Also do a simple copy of T \& S values on land points.}}
\DoxyCodeLine{235     \textcolor{keywordflow}{do} i=is,ie}
\DoxyCodeLine{236       do\_i(i) = ((g\%mask2dT(i,j) > 0.0) .and. .not.last\_down(i))}
\DoxyCodeLine{237       \textcolor{keywordflow}{if} (do\_i(i)) \textcolor{keywordflow}{then}}
\DoxyCodeLine{238         h\_b = h(i,j,1) + h\_neglect}
\DoxyCodeLine{239         b\_b = 1.0 / (h\_b + d\_b(i,2)*mix(i,2))}
\DoxyCodeLine{240         t\_adj(i,j,1) = b\_b * (h\_b*tv\%T(i,j,1) + mix(i,2)*te\_b(i,2))}
\DoxyCodeLine{241         s\_adj(i,j,1) = b\_b * (h\_b*tv\%S(i,j,1) + mix(i,2)*se\_b(i,2))}
\DoxyCodeLine{242       \textcolor{keywordflow}{elseif} (g\%mask2dT(i,j) <= 0.0) \textcolor{keywordflow}{then}}
\DoxyCodeLine{243         t\_adj(i,j,1) = tv\%T(i,j,1) ; s\_adj(i,j,1) = tv\%S(i,j,1)}
\DoxyCodeLine{244 \textcolor{keywordflow}{      endif}}
\DoxyCodeLine{245 \textcolor{keywordflow}{    enddo}}
\DoxyCodeLine{246     \textcolor{keywordflow}{do} k=2,nz ; \textcolor{keywordflow}{do} i=is,ie}
\DoxyCodeLine{247       \textcolor{keywordflow}{if} (do\_i(i)) \textcolor{keywordflow}{then}}
\DoxyCodeLine{248         t\_adj(i,j,k) = te\_b(i,k) + c\_b(i,k)*t\_adj(i,j,k-1)}
\DoxyCodeLine{249         s\_adj(i,j,k) = se\_b(i,k) + c\_b(i,k)*s\_adj(i,j,k-1)}
\DoxyCodeLine{250       \textcolor{keywordflow}{elseif} (g\%mask2dT(i,j) <= 0.0) \textcolor{keywordflow}{then}}
\DoxyCodeLine{251         t\_adj(i,j,k) = tv\%T(i,j,k) ; s\_adj(i,j,k) = tv\%S(i,j,k)}
\DoxyCodeLine{252 \textcolor{keywordflow}{      endif}}
\DoxyCodeLine{253 \textcolor{keywordflow}{    enddo} ;\textcolor{keywordflow}{ enddo}}
\DoxyCodeLine{254 }
\DoxyCodeLine{255     \textcolor{keywordflow}{do} i=is,ie ; \textcolor{keywordflow}{if} (do\_i(i)) \textcolor{keywordflow}{then}}
\DoxyCodeLine{256       k = 1 \textcolor{comment}{! A hook for debugging.}}
\DoxyCodeLine{257 \textcolor{keywordflow}{    endif} ;\textcolor{keywordflow}{ enddo}}
\DoxyCodeLine{258 }
\DoxyCodeLine{259 \textcolor{keywordflow}{  enddo} \textcolor{comment}{! j-loop}}
\DoxyCodeLine{260 }
\DoxyCodeLine{261   k = 1 \textcolor{comment}{! A hook for debugging.}}
\DoxyCodeLine{262 }
\DoxyCodeLine{263   \textcolor{comment}{! The following set of expressions for the final values are derived from the the partial}}
\DoxyCodeLine{264   \textcolor{comment}{! updates for the estimated temperatures and salinities around an interface, then directly}}
\DoxyCodeLine{265   \textcolor{comment}{! solving for the final temperatures and salinities.  They are here for later reference}}
\DoxyCodeLine{266   \textcolor{comment}{! and to document an intermediate step in the stability calculation.}}
\DoxyCodeLine{267     \textcolor{comment}{! hp\_a = (h\_a + d\_a(i,K-1)*mix(i,K-1))}}
\DoxyCodeLine{268     \textcolor{comment}{! hp\_b = (h\_b + d\_b(i,K+1)*mix(i,K+1))}}
\DoxyCodeLine{269     \textcolor{comment}{! b2\_c = 1.0 / (hp\_a*hp\_b + (hp\_a + hp\_b) * mix(i,K))}}
\DoxyCodeLine{270     \textcolor{comment}{! Th\_a = h\_a*tv\%T(i,j,k-1) + mix(i,K-1)*Te\_a(i,k-2)}}
\DoxyCodeLine{271     \textcolor{comment}{! Th\_b = h\_b*tv\%T(i,j,k)   + mix(i,K+1)*Te\_b(i,k+1)}}
\DoxyCodeLine{272     \textcolor{comment}{! T\_fin(i,k)   = ( (hp\_a + mix(i,K)) * Th\_b  + Th\_a * mix(i,K) ) * b2\_c}}
\DoxyCodeLine{273     \textcolor{comment}{! T\_fin(i,k-1) = ( (hp\_b + mix(i,K)) * Th\_a  + Th\_b * mix(i,K) ) * b2\_c}}
\DoxyCodeLine{274     \textcolor{comment}{! Sh\_a = h\_a*tv\%S(i,j,k-1) + mix(i,K-1)*Se\_a(i,k-2)}}
\DoxyCodeLine{275     \textcolor{comment}{! Sh\_b = h\_b*tv\%S(i,j,k)   + mix(i,K+1)*Se\_b(i,k+1)}}
\DoxyCodeLine{276     \textcolor{comment}{! S\_fin(i,k)   = ( (hp\_a + mix(i,K)) * Sh\_b  + Sh\_a * mix(i,K) ) * b2\_c}}
\DoxyCodeLine{277     \textcolor{comment}{! S\_fin(i,k-1) = ( (hp\_b + mix(i,K)) * Sh\_a  + Sh\_b * mix(i,K) ) * b2\_c}}
\DoxyCodeLine{278 }

\end{DoxyCode}
\mbox{\Hypertarget{namespacemom__full__convection_a2d2d4f8f10e25a0d9dc9bdfbf6729fe0}\label{namespacemom__full__convection_a2d2d4f8f10e25a0d9dc9bdfbf6729fe0}} 
\index{mom\_full\_convection@{mom\_full\_convection}!is\_unstable@{is\_unstable}}
\index{is\_unstable@{is\_unstable}!mom\_full\_convection@{mom\_full\_convection}}
\subsubsection{\texorpdfstring{is\_unstable()}{is\_unstable()}}
{\footnotesize\ttfamily logical function mom\+\_\+full\+\_\+convection\+::is\+\_\+unstable (\begin{DoxyParamCaption}\item[{real, intent(in)}]{d\+Rho\+\_\+dT,  }\item[{real, intent(in)}]{d\+Rho\+\_\+dS,  }\item[{real, intent(in)}]{h\+\_\+a,  }\item[{real, intent(in)}]{h\+\_\+b,  }\item[{real, intent(in)}]{mix\+\_\+A,  }\item[{real, intent(in)}]{mix\+\_\+B,  }\item[{real, intent(in)}]{T\+\_\+a,  }\item[{real, intent(in)}]{T\+\_\+b,  }\item[{real, intent(in)}]{S\+\_\+a,  }\item[{real, intent(in)}]{S\+\_\+b,  }\item[{real, intent(in)}]{Te\+\_\+aa,  }\item[{real, intent(in)}]{Te\+\_\+bb,  }\item[{real, intent(in)}]{Se\+\_\+aa,  }\item[{real, intent(in)}]{Se\+\_\+bb,  }\item[{real, intent(in)}]{d\+\_\+A,  }\item[{real, intent(in)}]{d\+\_\+B }\end{DoxyParamCaption})\hspace{0.3cm}{\ttfamily [private]}}



This function returns True if the profiles around the given interface will be statically unstable after mixing above below. The arguments are the ocean state above and below, including partial calculations from a tridiagonal solver. 


\begin{DoxyParams}[1]{Parameters}
\mbox{\texttt{ in}}  & {\em drho\+\_\+dt} & The derivative of in situ density with temperature \mbox{[}R deg\+C-\/1 $\sim$$>$ kg m-\/3 deg\+C-\/1\mbox{]} \\
\hline
\mbox{\texttt{ in}}  & {\em drho\+\_\+ds} & The derivative of in situ density with salinity \mbox{[}R ppt-\/1 $\sim$$>$ kg m-\/3 ppt-\/1\mbox{]} \\
\hline
\mbox{\texttt{ in}}  & {\em h\+\_\+a} & The thickness of the layer above \mbox{[}H $\sim$$>$ m or kg m-\/2\mbox{]} \\
\hline
\mbox{\texttt{ in}}  & {\em h\+\_\+b} & The thickness of the layer below \mbox{[}H $\sim$$>$ m or kg m-\/2\mbox{]} \\
\hline
\mbox{\texttt{ in}}  & {\em mix\+\_\+a} & The time integrated mixing rate of the interface above \mbox{[}H $\sim$$>$ m or kg m-\/2\mbox{]} \\
\hline
\mbox{\texttt{ in}}  & {\em mix\+\_\+b} & The time integrated mixing rate of the interface below \mbox{[}H $\sim$$>$ m or kg m-\/2\mbox{]} \\
\hline
\mbox{\texttt{ in}}  & {\em t\+\_\+a} & The initial temperature of the layer above \mbox{[}degC\mbox{]} \\
\hline
\mbox{\texttt{ in}}  & {\em t\+\_\+b} & The initial temperature of the layer below \mbox{[}degC\mbox{]} \\
\hline
\mbox{\texttt{ in}}  & {\em s\+\_\+a} & The initial salinity of the layer below \mbox{[}ppt\mbox{]} \\
\hline
\mbox{\texttt{ in}}  & {\em s\+\_\+b} & The initial salinity of the layer below \mbox{[}ppt\mbox{]} \\
\hline
\mbox{\texttt{ in}}  & {\em te\+\_\+aa} & The estimated temperature two layers above rescaled by d\+\_\+A \mbox{[}degC\mbox{]} \\
\hline
\mbox{\texttt{ in}}  & {\em te\+\_\+bb} & The estimated temperature two layers below rescaled by d\+\_\+B \mbox{[}degC\mbox{]} \\
\hline
\mbox{\texttt{ in}}  & {\em se\+\_\+aa} & The estimated salinity two layers above rescaled by d\+\_\+A \mbox{[}ppt\mbox{]} \\
\hline
\mbox{\texttt{ in}}  & {\em se\+\_\+bb} & The estimated salinity two layers below rescaled by d\+\_\+B \mbox{[}ppt\mbox{]} \\
\hline
\mbox{\texttt{ in}}  & {\em d\+\_\+a} & The rescaling dependency across the interface above, nondim. \\
\hline
\mbox{\texttt{ in}}  & {\em d\+\_\+b} & The rescaling dependency across the interface below, nondim. \\
\hline
\end{DoxyParams}
\begin{DoxyReturn}{Returns}
The return value, true if the profile is statically unstable around the interface in question. 
\end{DoxyReturn}


Definition at line 286 of file M\+O\+M\+\_\+full\+\_\+convection.\+F90.


\begin{DoxyCode}{0}
\DoxyCodeLine{286 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{intent(in)} :: dRho\_dT\textcolor{comment}{ !< The derivative of in situ density with temperature [R degC-1 ~> kg m-3 degC-1]}}
\DoxyCodeLine{287 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{intent(in)} :: dRho\_dS\textcolor{comment}{ !< The derivative of in situ density with salinity [R ppt-1 ~> kg m-3 ppt-1]}}
\DoxyCodeLine{288 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{intent(in)} :: h\_a\textcolor{comment}{     !< The thickness of the layer above [H ~> m or kg m-2]}}
\DoxyCodeLine{289 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{intent(in)} :: h\_b\textcolor{comment}{     !< The thickness of the layer below [H ~> m or kg m-2]}}
\DoxyCodeLine{290 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{intent(in)} :: mix\_A\textcolor{comment}{   !< The time integrated mixing rate of the interface above [H ~> m or kg m-2]}}
\DoxyCodeLine{291 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{intent(in)} :: mix\_B\textcolor{comment}{   !< The time integrated mixing rate of the interface below [H ~> m or kg m-2]}}
\DoxyCodeLine{292 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{intent(in)} :: T\_a\textcolor{comment}{     !< The initial temperature of the layer above [degC]}}
\DoxyCodeLine{293 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{intent(in)} :: T\_b\textcolor{comment}{     !< The initial temperature of the layer below [degC]}}
\DoxyCodeLine{294 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{intent(in)} :: S\_a\textcolor{comment}{     !< The initial salinity of the layer below [ppt]}}
\DoxyCodeLine{295 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{intent(in)} :: S\_b\textcolor{comment}{     !< The initial salinity of the layer below [ppt]}}
\DoxyCodeLine{296 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{intent(in)} :: Te\_aa\textcolor{comment}{   !< The estimated temperature two layers above rescaled by d\_A [degC]}}
\DoxyCodeLine{297 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{intent(in)} :: Te\_bb\textcolor{comment}{   !< The estimated temperature two layers below rescaled by d\_B [degC]}}
\DoxyCodeLine{298 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{intent(in)} :: Se\_aa\textcolor{comment}{   !< The estimated salinity two layers above rescaled by d\_A [ppt]}}
\DoxyCodeLine{299 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{intent(in)} :: Se\_bb\textcolor{comment}{   !< The estimated salinity two layers below rescaled by d\_B [ppt]}}
\DoxyCodeLine{300 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{intent(in)} :: d\_A\textcolor{comment}{     !< The rescaling dependency across the interface above, nondim.}}
\DoxyCodeLine{301 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{intent(in)} :: d\_B\textcolor{comment}{     !< The rescaling dependency across the interface below, nondim.}}
\DoxyCodeLine{302   \textcolor{keywordtype}{logical} :: is\_unstable\textcolor{comment}{ !< The return value, true if the profile is statically unstable}}
\DoxyCodeLine{303 \textcolor{comment}{                         !! around the interface in question.}}
\DoxyCodeLine{304 }
\DoxyCodeLine{305   \textcolor{comment}{! These expressions for the local stability are long, but they have been carefully}}
\DoxyCodeLine{306   \textcolor{comment}{! grouped for accuracy even when the mixing rates are huge or tiny, and common}}
\DoxyCodeLine{307   \textcolor{comment}{! positive definite factors that would appear in the final expression for the}}
\DoxyCodeLine{308   \textcolor{comment}{! locally referenced potential density difference across an interface have been omitted.}}
\DoxyCodeLine{309   is\_unstable = (drho\_dt * ((h\_a * h\_b * (t\_b - t\_a) + \&}
\DoxyCodeLine{310                              mix\_a*mix\_b * (d\_a*te\_bb - d\_b*te\_aa)) + \&}
\DoxyCodeLine{311                             (h\_a*mix\_b * (te\_bb - d\_b*t\_a) + \&}
\DoxyCodeLine{312                              h\_b*mix\_a * (d\_a*t\_b - te\_aa)) ) + \&}
\DoxyCodeLine{313                  drho\_ds * ((h\_a * h\_b * (s\_b - s\_a) + \&}
\DoxyCodeLine{314                              mix\_a*mix\_b * (d\_a*se\_bb - d\_b*se\_aa)) + \&}
\DoxyCodeLine{315                             (h\_a*mix\_b * (se\_bb - d\_b*s\_a) + \&}
\DoxyCodeLine{316                              h\_b*mix\_a * (d\_a*s\_b - se\_aa)) ) < 0.0)}

\end{DoxyCode}
\mbox{\Hypertarget{namespacemom__full__convection_af762a0514a81af81b0acc7553dbcffe3}\label{namespacemom__full__convection_af762a0514a81af81b0acc7553dbcffe3}} 
\index{mom\_full\_convection@{mom\_full\_convection}!smoothed\_drdt\_drds@{smoothed\_drdt\_drds}}
\index{smoothed\_drdt\_drds@{smoothed\_drdt\_drds}!mom\_full\_convection@{mom\_full\_convection}}
\subsubsection{\texorpdfstring{smoothed\_drdt\_drds()}{smoothed\_drdt\_drds()}}
{\footnotesize\ttfamily subroutine mom\+\_\+full\+\_\+convection\+::smoothed\+\_\+drdt\+\_\+drds (\begin{DoxyParamCaption}\item[{real, dimension( g \%isd\+: g \%ied, g \%jsd\+: g \%jed, g \%ke), intent(in)}]{h,  }\item[{type(thermo\+\_\+var\+\_\+ptrs), intent(in)}]{tv,  }\item[{real, intent(in)}]{Kddt,  }\item[{real, dimension( g \%isd\+: g \%ied, g \%ke+1), intent(out)}]{d\+R\+\_\+dT,  }\item[{real, dimension( g \%isd\+: g \%ied, g \%ke+1), intent(out)}]{d\+R\+\_\+dS,  }\item[{type(ocean\+\_\+grid\+\_\+type), intent(in)}]{G,  }\item[{type(verticalgrid\+\_\+type), intent(in)}]{GV,  }\item[{type(unit\+\_\+scale\+\_\+type), intent(in)}]{US,  }\item[{integer, intent(in)}]{j,  }\item[{real, dimension(\+:,\+:), pointer}]{p\+\_\+surf,  }\item[{integer, intent(in), optional}]{halo }\end{DoxyParamCaption})\hspace{0.3cm}{\ttfamily [private]}}



Returns the partial derivatives of locally referenced potential density with temperature and salinity after the properties have been smoothed with a small constant diffusivity. 


\begin{DoxyParams}[1]{Parameters}
\mbox{\texttt{ in}}  & {\em g} & The ocean\textquotesingle{}s grid structure \\
\hline
\mbox{\texttt{ in}}  & {\em gv} & The ocean\textquotesingle{}s vertical grid structure \\
\hline
\mbox{\texttt{ in}}  & {\em h} & Layer thicknesses \mbox{[}H $\sim$$>$ m or kg m-\/2\mbox{]} \\
\hline
\mbox{\texttt{ in}}  & {\em tv} & A structure pointing to various thermodynamic variables \\
\hline
\mbox{\texttt{ in}}  & {\em kddt} & A diffusivity times a time increment \mbox{[}H2 $\sim$$>$ m2 or kg2 m-\/4\mbox{]}. \\
\hline
\mbox{\texttt{ out}}  & {\em dr\+\_\+dt} & Derivative of locally referenced \\
\hline
\mbox{\texttt{ out}}  & {\em dr\+\_\+ds} & Derivative of locally referenced \\
\hline
\mbox{\texttt{ in}}  & {\em us} & A dimensional unit scaling type \\
\hline
\mbox{\texttt{ in}}  & {\em j} & The j-\/point to work on. \\
\hline
 & {\em p\+\_\+surf} & The pressure at the ocean surface \mbox{[}R L2 T-\/2 $\sim$$>$ Pa\mbox{]}. \\
\hline
\mbox{\texttt{ in}}  & {\em halo} & Halo width over which to compute \\
\hline
\end{DoxyParams}


Definition at line 323 of file M\+O\+M\+\_\+full\+\_\+convection.\+F90.


\begin{DoxyCode}{0}
\DoxyCodeLine{323   \textcolor{keywordtype}{type}(ocean\_grid\_type),   \textcolor{keywordtype}{intent(in)}  :: G\textcolor{comment}{    !< The ocean's grid structure}}
\DoxyCodeLine{324   \textcolor{keywordtype}{type}(verticalGrid\_type), \textcolor{keywordtype}{intent(in)}  :: GV\textcolor{comment}{   !< The ocean's vertical grid structure}}
\DoxyCodeLine{325 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(SZI\_(G),SZJ\_(G),SZK\_(G))}, \&}
\DoxyCodeLine{326                            \textcolor{keywordtype}{intent(in)}  :: h\textcolor{comment}{    !< Layer thicknesses [H ~> m or kg m-2]}}
\DoxyCodeLine{327   \textcolor{keywordtype}{type}(thermo\_var\_ptrs),   \textcolor{keywordtype}{intent(in)}  :: tv\textcolor{comment}{   !< A structure pointing to various}}
\DoxyCodeLine{328 \textcolor{comment}{                                               !! thermodynamic variables}}
\DoxyCodeLine{329 \textcolor{keywordtype}{  real},                    \textcolor{keywordtype}{intent(in)}  :: Kddt\textcolor{comment}{ !< A diffusivity times a time increment [H2 ~> m2 or kg2 m-4].}}
\DoxyCodeLine{330 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(SZI\_(G),SZK\_(G)+1)}, \&}
\DoxyCodeLine{331                            \textcolor{keywordtype}{intent(out)} :: dR\_dT\textcolor{comment}{ !< Derivative of locally referenced}}
\DoxyCodeLine{332 \textcolor{comment}{                                               !! potential density with temperature [R degC-1 ~> kg m-3 degC-1]}}
\DoxyCodeLine{333 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(SZI\_(G),SZK\_(G)+1)}, \&}
\DoxyCodeLine{334                            \textcolor{keywordtype}{intent(out)} :: dR\_dS\textcolor{comment}{ !< Derivative of locally referenced}}
\DoxyCodeLine{335 \textcolor{comment}{                                               !! potential density with salinity [R degC-1 ~> kg m-3 ppt-1]}}
\DoxyCodeLine{336   \textcolor{keywordtype}{type}(unit\_scale\_type),   \textcolor{keywordtype}{intent(in)}  :: US\textcolor{comment}{   !< A dimensional unit scaling type}}
\DoxyCodeLine{337   \textcolor{keywordtype}{integer},                 \textcolor{keywordtype}{intent(in)}  :: j\textcolor{comment}{    !< The j-point to work on.}}
\DoxyCodeLine{338 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(:,:)},    \textcolor{keywordtype}{pointer}     :: p\_surf\textcolor{comment}{ !< The pressure at the ocean surface [R L2 T-2 ~> Pa].}}
\DoxyCodeLine{339   \textcolor{keywordtype}{integer},       \textcolor{keywordtype}{optional}, \textcolor{keywordtype}{intent(in)}  :: halo\textcolor{comment}{ !< Halo width over which to compute}}
\DoxyCodeLine{340 }
\DoxyCodeLine{341   \textcolor{comment}{! Local variables}}
\DoxyCodeLine{342 \textcolor{keywordtype}{  real} :: mix(SZI\_(G),SZK\_(G)+1)   \textcolor{comment}{! The diffusive mixing length (kappa*dt)/dz}}
\DoxyCodeLine{343                                    \textcolor{comment}{! between layers within in a timestep [H ~> m or kg m-2].}}
\DoxyCodeLine{344 \textcolor{keywordtype}{  real} :: b1(SZI\_(G)), d1(SZI\_(G)) \textcolor{comment}{! b1, c1, and d1 are variables used by the}}
\DoxyCodeLine{345 \textcolor{keywordtype}{  real} :: c1(SZI\_(G),SZK\_(G))      \textcolor{comment}{! tridiagonal solver.}}
\DoxyCodeLine{346 \textcolor{keywordtype}{  real} :: T\_f(SZI\_(G),SZK\_(G))     \textcolor{comment}{! Filtered temperatures [degC]}}
\DoxyCodeLine{347 \textcolor{keywordtype}{  real} :: S\_f(SZI\_(G),SZK\_(G))     \textcolor{comment}{! Filtered salinities [ppt]}}
\DoxyCodeLine{348 \textcolor{keywordtype}{  real} :: pres(SZI\_(G))            \textcolor{comment}{! Interface pressures [R L2 T-2 ~> Pa].}}
\DoxyCodeLine{349 \textcolor{keywordtype}{  real} :: T\_EOS(SZI\_(G))           \textcolor{comment}{! Filtered and vertically averaged temperatures [degC]}}
\DoxyCodeLine{350 \textcolor{keywordtype}{  real} :: S\_EOS(SZI\_(G))           \textcolor{comment}{! Filtered and vertically averaged salinities [ppt]}}
\DoxyCodeLine{351 \textcolor{keywordtype}{  real} :: kap\_dt\_x2                \textcolor{comment}{! The product of 2*kappa*dt [H2 ~> m2 or kg2 m-4].}}
\DoxyCodeLine{352 \textcolor{keywordtype}{  real} :: h\_neglect, h0            \textcolor{comment}{! Negligible thicknesses to allow for zero thicknesses,}}
\DoxyCodeLine{353                                    \textcolor{comment}{! [H ~> m or kg m-2].}}
\DoxyCodeLine{354 \textcolor{keywordtype}{  real} :: h\_tr                     \textcolor{comment}{! The thickness at tracer points, plus h\_neglect [H ~> m or kg m-2].}}
\DoxyCodeLine{355   \textcolor{keywordtype}{integer}, \textcolor{keywordtype}{dimension(2)} :: EOSdom \textcolor{comment}{! The i-computational domain for the equation of state}}
\DoxyCodeLine{356   \textcolor{keywordtype}{integer} :: i, k, is, ie, nz}
\DoxyCodeLine{357 }
\DoxyCodeLine{358   \textcolor{keywordflow}{if} (\textcolor{keyword}{present}(halo)) \textcolor{keywordflow}{then}}
\DoxyCodeLine{359     is = g\%isc-halo ; ie = g\%iec+halo}
\DoxyCodeLine{360   \textcolor{keywordflow}{else}}
\DoxyCodeLine{361     is = g\%isc ; ie = g\%iec}
\DoxyCodeLine{362 \textcolor{keywordflow}{  endif}}
\DoxyCodeLine{363   nz = g\%ke}
\DoxyCodeLine{364 }
\DoxyCodeLine{365   h\_neglect = gv\%H\_subroundoff}
\DoxyCodeLine{366   kap\_dt\_x2 = 2.0*kddt}
\DoxyCodeLine{367 }
\DoxyCodeLine{368   \textcolor{keywordflow}{if} (kddt <= 0.0) \textcolor{keywordflow}{then}}
\DoxyCodeLine{369     \textcolor{keywordflow}{do} k=1,nz ; \textcolor{keywordflow}{do} i=is,ie}
\DoxyCodeLine{370       t\_f(i,k) = tv\%T(i,j,k) ; s\_f(i,k) = tv\%S(i,j,k)}
\DoxyCodeLine{371 \textcolor{keywordflow}{    enddo} ;\textcolor{keywordflow}{ enddo}}
\DoxyCodeLine{372   \textcolor{keywordflow}{else}}
\DoxyCodeLine{373     h0 = 1.0e-16*sqrt(kddt) + h\_neglect}
\DoxyCodeLine{374     \textcolor{keywordflow}{do} i=is,ie}
\DoxyCodeLine{375       mix(i,2) = kap\_dt\_x2 / ((h(i,j,1)+h(i,j,2)) + h0)}
\DoxyCodeLine{376 }
\DoxyCodeLine{377       h\_tr = h(i,j,1) + h\_neglect}
\DoxyCodeLine{378       b1(i) = 1.0 / (h\_tr + mix(i,2))}
\DoxyCodeLine{379       d1(i) = b1(i) * h(i,j,1)}
\DoxyCodeLine{380       t\_f(i,1) = (b1(i)*h\_tr)*tv\%T(i,j,1)}
\DoxyCodeLine{381       s\_f(i,1) = (b1(i)*h\_tr)*tv\%S(i,j,1)}
\DoxyCodeLine{382 \textcolor{keywordflow}{    enddo}}
\DoxyCodeLine{383     \textcolor{keywordflow}{do} k=2,nz-1 ; \textcolor{keywordflow}{do} i=is,ie}
\DoxyCodeLine{384       mix(i,k+1) = kap\_dt\_x2 / ((h(i,j,k)+h(i,j,k+1)) + h0)}
\DoxyCodeLine{385 }
\DoxyCodeLine{386       c1(i,k) = mix(i,k) * b1(i)}
\DoxyCodeLine{387       h\_tr = h(i,j,k) + h\_neglect}
\DoxyCodeLine{388       b1(i) = 1.0 / ((h\_tr + d1(i)*mix(i,k)) + mix(i,k+1))}
\DoxyCodeLine{389       d1(i) = b1(i) * (h\_tr + d1(i)*mix(i,k))}
\DoxyCodeLine{390       t\_f(i,k) = b1(i) * (h\_tr*tv\%T(i,j,k) + mix(i,k)*t\_f(i,k-1))}
\DoxyCodeLine{391       s\_f(i,k) = b1(i) * (h\_tr*tv\%S(i,j,k) + mix(i,k)*s\_f(i,k-1))}
\DoxyCodeLine{392 \textcolor{keywordflow}{    enddo} ;\textcolor{keywordflow}{ enddo}}
\DoxyCodeLine{393     \textcolor{keywordflow}{do} i=is,ie}
\DoxyCodeLine{394       c1(i,nz) = mix(i,nz) * b1(i)}
\DoxyCodeLine{395       h\_tr = h(i,j,nz) + h\_neglect}
\DoxyCodeLine{396       b1(i) = 1.0 / (h\_tr + d1(i)*mix(i,nz))}
\DoxyCodeLine{397       t\_f(i,nz) = b1(i) * (h\_tr*tv\%T(i,j,nz) + mix(i,nz)*t\_f(i,nz-1))}
\DoxyCodeLine{398       s\_f(i,nz) = b1(i) * (h\_tr*tv\%S(i,j,nz) + mix(i,nz)*s\_f(i,nz-1))}
\DoxyCodeLine{399 \textcolor{keywordflow}{    enddo}}
\DoxyCodeLine{400     \textcolor{keywordflow}{do} k=nz-1,1,-1 ; \textcolor{keywordflow}{do} i=is,ie}
\DoxyCodeLine{401       t\_f(i,k) = t\_f(i,k) + c1(i,k+1)*t\_f(i,k+1)}
\DoxyCodeLine{402       s\_f(i,k) = s\_f(i,k) + c1(i,k+1)*s\_f(i,k+1)}
\DoxyCodeLine{403 \textcolor{keywordflow}{    enddo} ;\textcolor{keywordflow}{ enddo}}
\DoxyCodeLine{404 \textcolor{keywordflow}{  endif}}
\DoxyCodeLine{405 }
\DoxyCodeLine{406   \textcolor{keywordflow}{if} (\textcolor{keyword}{associated}(p\_surf)) \textcolor{keywordflow}{then}}
\DoxyCodeLine{407     \textcolor{keywordflow}{do} i=is,ie ; pres(i) = p\_surf(i,j) ;\textcolor{keywordflow}{ enddo}}
\DoxyCodeLine{408   \textcolor{keywordflow}{else}}
\DoxyCodeLine{409     \textcolor{keywordflow}{do} i=is,ie ; pres(i) = 0.0 ;\textcolor{keywordflow}{ enddo}}
\DoxyCodeLine{410 \textcolor{keywordflow}{  endif}}
\DoxyCodeLine{411   eosdom(:) = eos\_domain(g\%HI, halo)}
\DoxyCodeLine{412   \textcolor{keyword}{call }calculate\_density\_derivs(t\_f(:,1), s\_f(:,1), pres, dr\_dt(:,1), dr\_ds(:,1), tv\%eqn\_of\_state, eosdom)}
\DoxyCodeLine{413   \textcolor{keywordflow}{do} i=is,ie ; pres(i) = pres(i) + h(i,j,1)*(gv\%H\_to\_RZ*gv\%g\_Earth) ;\textcolor{keywordflow}{ enddo}}
\DoxyCodeLine{414   \textcolor{keywordflow}{do} k=2,nz}
\DoxyCodeLine{415     \textcolor{keywordflow}{do} i=is,ie}
\DoxyCodeLine{416       t\_eos(i) = 0.5*(t\_f(i,k-1) + t\_f(i,k))}
\DoxyCodeLine{417       s\_eos(i) = 0.5*(s\_f(i,k-1) + s\_f(i,k))}
\DoxyCodeLine{418 \textcolor{keywordflow}{    enddo}}
\DoxyCodeLine{419     \textcolor{keyword}{call }calculate\_density\_derivs(t\_eos, s\_eos, pres, dr\_dt(:,k), dr\_ds(:,k), tv\%eqn\_of\_state, eosdom)}
\DoxyCodeLine{420     \textcolor{keywordflow}{do} i=is,ie ; pres(i) = pres(i) + h(i,j,k)*(gv\%H\_to\_RZ*gv\%g\_Earth) ;\textcolor{keywordflow}{ enddo}}
\DoxyCodeLine{421 \textcolor{keywordflow}{  enddo}}
\DoxyCodeLine{422   \textcolor{keyword}{call }calculate\_density\_derivs(t\_f(:,nz), s\_f(:,nz), pres, dr\_dt(:,nz+1), dr\_ds(:,nz+1), \&}
\DoxyCodeLine{423                                 tv\%eqn\_of\_state, eosdom)}
\DoxyCodeLine{424 }

\end{DoxyCode}
