\hypertarget{namespacemom__lateral__mixing__coeffs}{}\section{mom\+\_\+lateral\+\_\+mixing\+\_\+coeffs Module Reference}
\label{namespacemom__lateral__mixing__coeffs}\index{mom\+\_\+lateral\+\_\+mixing\+\_\+coeffs@{mom\+\_\+lateral\+\_\+mixing\+\_\+coeffs}}


\subsection{Detailed Description}
Variable mixing coefficients. 

This module provides a container for various factors used in prescribing diffusivities, that are a function of the state (in particular the stratification and isoneutral slopes).\hypertarget{namespacemom__lateral__mixing__coeffs_section_Resolution_Function}{}\subsection{The resolution function}\label{namespacemom__lateral__mixing__coeffs_section_Resolution_Function}
The resolution function is expressed in terms of the ratio of grid-\/spacing to deformation radius. The square of the resolution parameter is

\[ R^2 = \frac{L_d^2}{\Delta^2} = \frac{ c_g^2 }{ f^2 \Delta^2 + c_g \beta \Delta^2 } \]

where the grid spacing is calculated as

\[ \Delta^2 = \Delta x^2 + \Delta y^2 . \]

\begin{DoxyRefDesc}{Todo}
\item[\mbox{\hyperlink{todo__todo000002}{Todo}}]Check this reference to Bob on/off paper. The resolution function used in scaling diffusivities (Hallberg, 2010) is\end{DoxyRefDesc}


\[ r(\Delta,L_d) = \frac{1}{1+(\alpha R)^p} \]

The resolution function can be applied independently to thickness diffusion (module \mbox{\hyperlink{namespacemom__thickness__diffuse}{mom\+\_\+thickness\+\_\+diffuse}}), tracer diffusion (mom\+\_\+tracer\+\_\+hordiff) lateral viscosity (\mbox{\hyperlink{namespacemom__hor__visc}{mom\+\_\+hor\+\_\+visc}}).

Robert Hallberg, 2013\+: Using a resolution function to regulate parameterizations of oceanic mesoscale eddy effects. Ocean Modelling, 71, pp 92-\/103. \href{http://dx.doi.org/10.1016/j.ocemod.2013.08.007}{\tt http\+://dx.\+doi.\+org/10.\+1016/j.\+ocemod.\+2013.\+08.\+007}

\tabulinesep=1mm
\begin{longtabu} spread 0pt [c]{*{2}{|X[-1]}|}
\hline
\rowcolor{\tableheadbgcolor}\textbf{ Symbol  }&\textbf{ Module parameter   }\\\cline{1-2}
\endfirsthead
\hline
\endfoot
\hline
\rowcolor{\tableheadbgcolor}\textbf{ Symbol  }&\textbf{ Module parameter   }\\\cline{1-2}
\endhead
-\/  &{\ttfamily U\+S\+E\+\_\+\+V\+A\+R\+I\+A\+B\+L\+E\+\_\+\+M\+I\+X\+I\+NG}   \\\cline{1-2}
-\/  &{\ttfamily R\+E\+S\+O\+L\+N\+\_\+\+S\+C\+A\+L\+E\+D\+\_\+\+KH}   \\\cline{1-2}
-\/  &{\ttfamily R\+E\+S\+O\+L\+N\+\_\+\+S\+C\+A\+L\+E\+D\+\_\+\+K\+H\+TH}   \\\cline{1-2}
-\/  &{\ttfamily R\+E\+S\+O\+L\+N\+\_\+\+S\+C\+A\+L\+E\+D\+\_\+\+K\+H\+TR}   \\\cline{1-2}
$ \alpha $  &{\ttfamily K\+H\+\_\+\+R\+E\+S\+\_\+\+S\+C\+A\+L\+E\+\_\+\+C\+O\+EF} (for thickness and tracer diffusivity)   \\\cline{1-2}
$ p $  &{\ttfamily K\+H\+\_\+\+R\+E\+S\+\_\+\+F\+N\+\_\+\+P\+O\+W\+ER} (for thickness and tracer diffusivity)   \\\cline{1-2}
$ \alpha $  &{\ttfamily V\+I\+S\+C\+\_\+\+R\+E\+S\+\_\+\+S\+C\+A\+L\+E\+\_\+\+C\+O\+EF} (for lateral viscosity)   \\\cline{1-2}
$ p $  &{\ttfamily V\+I\+S\+C\+\_\+\+R\+E\+S\+\_\+\+F\+N\+\_\+\+P\+O\+W\+ER} (for lateral viscosity)   \\\cline{1-2}
-\/  &{\ttfamily G\+I\+L\+L\+\_\+\+E\+Q\+U\+A\+T\+O\+R\+I\+A\+L\+\_\+\+LD}   \\\cline{1-2}
\end{longtabu}
\hypertarget{namespacemom__lateral__mixing__coeffs_section_Vicbeck}{}\subsection{Visbeck diffusivity}\label{namespacemom__lateral__mixing__coeffs_section_Vicbeck}
This module also calculates factors used in setting the thickness diffusivity similar to a Visbeck et al., 1997, scheme. The factors are combined in \mbox{\hyperlink{namespacemom__thickness__diffuse_a8a538b778a567f489bfd9c5eadeeebef}{mom\+\_\+thickness\+\_\+diffuse\+::thickness\+\_\+diffuse()}} but calculated in this module.

\[ \kappa_h = \alpha_s L_s^2 S N \]

where $S$ is the magnitude of the isoneutral slope and $N$ is the Brunt-\/\+Vaisala frequency.

Visbeck, Marshall, Haine and Spall, 1997\+: Specification of Eddy Transfer Coefficients in Coarse-\/\+Resolution Ocean Circulation Models. J. Phys. Oceanogr. \href{http://dx.doi.org/10.1175/1520-0485(1997)027%3C0381:SOETCI%3E2.0.CO;2}{\tt http\+://dx.\+doi.\+org/10.\+1175/1520-\/0485(1997)027\%3\+C0381\+:\+S\+O\+E\+T\+C\+I\%3\+E2.\+0.\+C\+O;2}

\tabulinesep=1mm
\begin{longtabu} spread 0pt [c]{*{2}{|X[-1]}|}
\hline
\rowcolor{\tableheadbgcolor}\textbf{ Symbol  }&\textbf{ Module parameter   }\\\cline{1-2}
\endfirsthead
\hline
\endfoot
\hline
\rowcolor{\tableheadbgcolor}\textbf{ Symbol  }&\textbf{ Module parameter   }\\\cline{1-2}
\endhead
-\/  &{\ttfamily U\+S\+E\+\_\+\+V\+A\+R\+I\+A\+B\+L\+E\+\_\+\+M\+I\+X\+I\+NG}   \\\cline{1-2}
$ \alpha_s $  &{\ttfamily K\+H\+T\+H\+\_\+\+S\+L\+O\+P\+E\+\_\+\+C\+FF} (for \mbox{\hyperlink{namespacemom__thickness__diffuse}{mom\+\_\+thickness\+\_\+diffuse}} module)   \\\cline{1-2}
$ \alpha_s $  &{\ttfamily K\+H\+T\+R\+\_\+\+S\+L\+O\+P\+E\+\_\+\+C\+FF} (for mom\+\_\+tracer\+\_\+hordiff module)   \\\cline{1-2}
$ L_{s} $  &{\ttfamily V\+I\+S\+B\+E\+C\+K\+\_\+\+L\+\_\+\+S\+C\+A\+LE}   \\\cline{1-2}
$ S_{max} $  &{\ttfamily V\+I\+S\+B\+E\+C\+K\+\_\+\+M\+A\+X\+\_\+\+S\+L\+O\+PE}   \\\cline{1-2}
\end{longtabu}
\hypertarget{namespacemom__lateral__mixing__coeffs_section_vertical_structure_khth}{}\subsection{Vertical structure function for Kh\+Th}\label{namespacemom__lateral__mixing__coeffs_section_vertical_structure_khth}
The thickness diffusivity can be prescribed a vertical distribution with the shape of the equivalent barotropic velocity mode. The structure function is stored in the control structure for thie module (\mbox{\hyperlink{structmom__lateral__mixing__coeffs_1_1varmix__cs}{varmix\+\_\+cs}}) but is calculated using subroutines in \mbox{\hyperlink{namespacemom__wave__speed}{mom\+\_\+wave\+\_\+speed}}.

\tabulinesep=1mm
\begin{longtabu} spread 0pt [c]{*{2}{|X[-1]}|}
\hline
\rowcolor{\tableheadbgcolor}\textbf{ Symbol  }&\textbf{ Module parameter   }\\\cline{1-2}
\endfirsthead
\hline
\endfoot
\hline
\rowcolor{\tableheadbgcolor}\textbf{ Symbol  }&\textbf{ Module parameter   }\\\cline{1-2}
\endhead
-\/  &{\ttfamily K\+H\+T\+H\+\_\+\+U\+S\+E\+\_\+\+E\+B\+T\+\_\+\+S\+T\+R\+U\+CT}   \\\cline{1-2}
\end{longtabu}
\subsection*{Data Types}
\begin{DoxyCompactItemize}
\item 
type \mbox{\hyperlink{structmom__lateral__mixing__coeffs_1_1varmix__cs}{varmix\+\_\+cs}}
\begin{DoxyCompactList}\small\item\em Variable mixing coefficients. \end{DoxyCompactList}\end{DoxyCompactItemize}
\subsection*{Functions/\+Subroutines}
\begin{DoxyCompactItemize}
\item 
subroutine, public \mbox{\hyperlink{namespacemom__lateral__mixing__coeffs_a6e09cc5b57817576a6ba61b9c630f608}{calc\+\_\+depth\+\_\+function}} (G, CS)
\begin{DoxyCompactList}\small\item\em Calculates the non-\/dimensional depth functions. \end{DoxyCompactList}\item 
subroutine, public \mbox{\hyperlink{namespacemom__lateral__mixing__coeffs_a8652c5651033573cfd6f09b789d64713}{calc\+\_\+resoln\+\_\+function}} (h, tv, G, GV, US, CS)
\begin{DoxyCompactList}\small\item\em Calculates and stores the non-\/dimensional resolution functions. \end{DoxyCompactList}\item 
subroutine, public \mbox{\hyperlink{namespacemom__lateral__mixing__coeffs_a1afa768a2df4c937842247cea00d184a}{calc\+\_\+slope\+\_\+functions}} (h, tv, dt, G, GV, US, CS, O\+BC)
\begin{DoxyCompactList}\small\item\em Calculates and stores functions of isopycnal slopes, e.\+g. Sx, Sy, S$\ast$N, mostly used in the Visbeck et al. style scaling of diffusivity. \end{DoxyCompactList}\item 
subroutine \mbox{\hyperlink{namespacemom__lateral__mixing__coeffs_ac7307f59d005a7b45a642f94eee7c8be}{calc\+\_\+visbeck\+\_\+coeffs}} (h, slope\+\_\+x, slope\+\_\+y, N2\+\_\+u, N2\+\_\+v, G, GV, US, CS, O\+BC)
\begin{DoxyCompactList}\small\item\em Calculates factors used when setting diffusivity coefficients similar to Visbeck et al. \end{DoxyCompactList}\item 
subroutine \mbox{\hyperlink{namespacemom__lateral__mixing__coeffs_a9947860318104ed1662ff4f9d671f92d}{calc\+\_\+slope\+\_\+functions\+\_\+using\+\_\+just\+\_\+e}} (h, G, GV, US, CS, e, calculate\+\_\+slopes, O\+BC)
\begin{DoxyCompactList}\small\item\em The original calc\+\_\+slope\+\_\+function() that calculated slopes using interface positions only, not accounting for density variations. \end{DoxyCompactList}\item 
subroutine, public \mbox{\hyperlink{namespacemom__lateral__mixing__coeffs_a212e9e850d4db8f321e0398f4090fee0}{calc\+\_\+qg\+\_\+leith\+\_\+viscosity}} (CS, G, GV, US, h, k, div\+\_\+xx\+\_\+dx, div\+\_\+xx\+\_\+dy, vort\+\_\+xy\+\_\+dx, vort\+\_\+xy\+\_\+dy)
\begin{DoxyCompactList}\small\item\em Calculates the Leith Laplacian and bi-\/harmonic viscosity coefficients. \end{DoxyCompactList}\item 
subroutine, public \mbox{\hyperlink{namespacemom__lateral__mixing__coeffs_a1070a864ca570c00f483a8617afca133}{varmix\+\_\+init}} (Time, G, GV, US, param\+\_\+file, diag, CS)
\begin{DoxyCompactList}\small\item\em Initializes the variables mixing coefficients container. \end{DoxyCompactList}\end{DoxyCompactItemize}


\subsection{Function/\+Subroutine Documentation}
\mbox{\Hypertarget{namespacemom__lateral__mixing__coeffs_a6e09cc5b57817576a6ba61b9c630f608}\label{namespacemom__lateral__mixing__coeffs_a6e09cc5b57817576a6ba61b9c630f608}} 
\index{mom\+\_\+lateral\+\_\+mixing\+\_\+coeffs@{mom\+\_\+lateral\+\_\+mixing\+\_\+coeffs}!calc\+\_\+depth\+\_\+function@{calc\+\_\+depth\+\_\+function}}
\index{calc\+\_\+depth\+\_\+function@{calc\+\_\+depth\+\_\+function}!mom\+\_\+lateral\+\_\+mixing\+\_\+coeffs@{mom\+\_\+lateral\+\_\+mixing\+\_\+coeffs}}
\subsubsection{\texorpdfstring{calc\+\_\+depth\+\_\+function()}{calc\_depth\_function()}}
{\footnotesize\ttfamily subroutine, public mom\+\_\+lateral\+\_\+mixing\+\_\+coeffs\+::calc\+\_\+depth\+\_\+function (\begin{DoxyParamCaption}\item[{type(ocean\+\_\+grid\+\_\+type), intent(in)}]{G,  }\item[{type(\mbox{\hyperlink{structmom__lateral__mixing__coeffs_1_1varmix__cs}{varmix\+\_\+cs}}), pointer}]{CS }\end{DoxyParamCaption})}



Calculates the non-\/dimensional depth functions. 


\begin{DoxyParams}[1]{Parameters}
\mbox{\tt in}  & {\em g} & Ocean grid structure\\
\hline
 & {\em cs} & Variable mixing coefficients \\
\hline
\end{DoxyParams}


Definition at line 157 of file M\+O\+M\+\_\+lateral\+\_\+mixing\+\_\+coeffs.\+F90.


\begin{DoxyCode}
157   \textcolor{keywordtype}{type}(ocean\_grid\_type),                    \textcolor{keywordtype}{intent(in)} :: G\textcolor{comment}{  !< Ocean grid structure}
158   \textcolor{keywordtype}{type}(VarMix\_CS),                          \textcolor{keywordtype}{pointer}       :: CS\textcolor{comment}{ !< Variable mixing coefficients}
159 
160   \textcolor{comment}{! Local variables}
161   \textcolor{keywordtype}{integer} :: is, ie, js, je, Isq, Ieq, Jsq, Jeq
162   \textcolor{keywordtype}{integer} :: i, j
163   \textcolor{keywordtype}{real}    :: H0 \textcolor{comment}{! local variable for reference depth}
164   \textcolor{keywordtype}{real}    :: expo \textcolor{comment}{! exponent used in the depth dependent scaling}
165   is = g%isc ; ie = g%iec ; js = g%jsc ; je = g%jec
166   isq = g%IscB ; ieq = g%IecB ; jsq = g%JscB ; jeq = g%JecB
167 
168   \textcolor{keywordflow}{if} (.not. \textcolor{keyword}{associated}(cs)) \textcolor{keyword}{call }mom\_error(fatal, \textcolor{stringliteral}{"calc\_depth\_function:"}// &
169          \textcolor{stringliteral}{"Module must be initialized before it is used."})
170   \textcolor{keywordflow}{if} (.not. cs%calculate\_depth\_fns) \textcolor{keywordflow}{return}
171   \textcolor{keywordflow}{if} (.not. \textcolor{keyword}{associated}(cs%Depth\_fn\_u)) \textcolor{keyword}{call }mom\_error(fatal, &
172     \textcolor{stringliteral}{"calc\_depth\_function: %Depth\_fn\_u is not associated with Depth\_scaled\_KhTh."})
173   \textcolor{keywordflow}{if} (.not. \textcolor{keyword}{associated}(cs%Depth\_fn\_v)) \textcolor{keyword}{call }mom\_error(fatal, &
174     \textcolor{stringliteral}{"calc\_depth\_function: %Depth\_fn\_v is not associated with Depth\_scaled\_KhTh."})
175 
176   h0 = cs%depth\_scaled\_khth\_h0
177   expo = cs%depth\_scaled\_khth\_exp
178 \textcolor{comment}{!$OMP do}
179   \textcolor{keywordflow}{do} j=js,je ; \textcolor{keywordflow}{do} i=is-1,ieq
180     cs%Depth\_fn\_u(i,j) = (min(1.0, 0.5*(g%bathyT(i,j) + g%bathyT(i+1,j))/h0))**expo
181 \textcolor{keywordflow}{  enddo} ;\textcolor{keywordflow}{ enddo}
182 \textcolor{comment}{!$OMP do}
183   \textcolor{keywordflow}{do} j=js-1,jeq ; \textcolor{keywordflow}{do} i=is,ie
184     cs%Depth\_fn\_v(i,j) = (min(1.0, 0.5*(g%bathyT(i,j) + g%bathyT(i,j+1))/h0))**expo
185 \textcolor{keywordflow}{  enddo} ;\textcolor{keywordflow}{ enddo}
186 
\end{DoxyCode}
\mbox{\Hypertarget{namespacemom__lateral__mixing__coeffs_a212e9e850d4db8f321e0398f4090fee0}\label{namespacemom__lateral__mixing__coeffs_a212e9e850d4db8f321e0398f4090fee0}} 
\index{mom\+\_\+lateral\+\_\+mixing\+\_\+coeffs@{mom\+\_\+lateral\+\_\+mixing\+\_\+coeffs}!calc\+\_\+qg\+\_\+leith\+\_\+viscosity@{calc\+\_\+qg\+\_\+leith\+\_\+viscosity}}
\index{calc\+\_\+qg\+\_\+leith\+\_\+viscosity@{calc\+\_\+qg\+\_\+leith\+\_\+viscosity}!mom\+\_\+lateral\+\_\+mixing\+\_\+coeffs@{mom\+\_\+lateral\+\_\+mixing\+\_\+coeffs}}
\subsubsection{\texorpdfstring{calc\+\_\+qg\+\_\+leith\+\_\+viscosity()}{calc\_qg\_leith\_viscosity()}}
{\footnotesize\ttfamily subroutine, public mom\+\_\+lateral\+\_\+mixing\+\_\+coeffs\+::calc\+\_\+qg\+\_\+leith\+\_\+viscosity (\begin{DoxyParamCaption}\item[{type(\mbox{\hyperlink{structmom__lateral__mixing__coeffs_1_1varmix__cs}{varmix\+\_\+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(inout)}]{h,  }\item[{integer, intent(in)}]{k,  }\item[{real, dimension(szib\+\_\+(g),szj\+\_\+(g)), intent(in)}]{div\+\_\+xx\+\_\+dx,  }\item[{real, dimension(szi\+\_\+(g),szjb\+\_\+(g)), intent(in)}]{div\+\_\+xx\+\_\+dy,  }\item[{real, dimension(szi\+\_\+(g),szjb\+\_\+(g)), intent(inout)}]{vort\+\_\+xy\+\_\+dx,  }\item[{real, dimension(szib\+\_\+(g),szj\+\_\+(g)), intent(inout)}]{vort\+\_\+xy\+\_\+dy }\end{DoxyParamCaption})}



Calculates the Leith Laplacian and bi-\/harmonic viscosity coefficients. 


\begin{DoxyParams}[1]{Parameters}
 & {\em cs} & Variable mixing coefficients\\
\hline
\mbox{\tt in}  & {\em g} & Ocean grid structure\\
\hline
\mbox{\tt in}  & {\em gv} & The ocean\textquotesingle{}s vertical grid structure.\\
\hline
\mbox{\tt in}  & {\em us} & A dimensional unit scaling type\\
\hline
\mbox{\tt in,out}  & {\em h} & Layer thickness \mbox{[}H $\sim$$>$ m or kg m-\/2\mbox{]}\\
\hline
\mbox{\tt in}  & {\em k} & Layer for which to calculate vorticity magnitude\\
\hline
\mbox{\tt in}  & {\em div\+\_\+xx\+\_\+dx} & x-\/derivative of horizontal divergence (d/dx(du/dx + dv/dy)) \mbox{[}L-\/1 T-\/1 $\sim$$>$ m-\/1 s-\/1\mbox{]}\\
\hline
\mbox{\tt in}  & {\em div\+\_\+xx\+\_\+dy} & y-\/derivative of horizontal divergence (d/dy(du/dx + dv/dy)) \mbox{[}L-\/1 T-\/1 $\sim$$>$ m-\/1 s-\/1\mbox{]}\\
\hline
\mbox{\tt in,out}  & {\em vort\+\_\+xy\+\_\+dx} & x-\/derivative of vertical vorticity (d/dx(dv/dx -\/ du/dy)) \mbox{[}L-\/1 T-\/1 $\sim$$>$ m-\/1 s-\/1\mbox{]}\\
\hline
\mbox{\tt in,out}  & {\em vort\+\_\+xy\+\_\+dy} & y-\/derivative of vertical vorticity (d/dy(dv/dx -\/ du/dy)) \mbox{[}L-\/1 T-\/1 $\sim$$>$ m-\/1 s-\/1\mbox{]} \\
\hline
\end{DoxyParams}


Definition at line 808 of file M\+O\+M\+\_\+lateral\+\_\+mixing\+\_\+coeffs.\+F90.


\begin{DoxyCode}
808   \textcolor{keywordtype}{type}(VarMix\_CS),                           \textcolor{keywordtype}{pointer}     :: CS\textcolor{comment}{ !< Variable mixing coefficients}
809   \textcolor{keywordtype}{type}(ocean\_grid\_type),                     \textcolor{keywordtype}{intent(in)}  :: G\textcolor{comment}{  !< Ocean grid structure}
810   \textcolor{keywordtype}{type}(verticalGrid\_type),                   \textcolor{keywordtype}{intent(in)}  :: GV\textcolor{comment}{ !< The ocean's vertical grid structure.}
811   \textcolor{keywordtype}{type}(unit\_scale\_type),                     \textcolor{keywordtype}{intent(in)}  :: US\textcolor{comment}{   !< A dimensional unit scaling type}
812   \textcolor{keywordtype}{real}, \textcolor{keywordtype}{dimension(SZI\_(G),SZJ\_(G),SZK\_(G))},  \textcolor{keywordtype}{intent(inout)} :: h\textcolor{comment}{ !< Layer thickness [H ~> m or kg m-2]}
813   \textcolor{keywordtype}{integer},                                   \textcolor{keywordtype}{intent(in)}  :: k\textcolor{comment}{  !< Layer for which to calculate vorticity
       magnitude}
814   \textcolor{keywordtype}{real}, \textcolor{keywordtype}{dimension(SZIB\_(G),SZJ\_(G))},         \textcolor{keywordtype}{intent(in)}  :: div\_xx\_dx\textcolor{comment}{  !< x-derivative of horizontal
       divergence}
815 \textcolor{comment}{                                                                 !! (d/dx(du/dx + dv/dy)) [L-1 T-1 ~> m-1
       s-1]}
816   \textcolor{keywordtype}{real}, \textcolor{keywordtype}{dimension(SZI\_(G),SZJB\_(G))},         \textcolor{keywordtype}{intent(in)}  :: div\_xx\_dy\textcolor{comment}{  !< y-derivative of horizontal
       divergence}
817 \textcolor{comment}{                                                                 !! (d/dy(du/dx + dv/dy)) [L-1 T-1 ~> m-1
       s-1]}
818   \textcolor{keywordtype}{real}, \textcolor{keywordtype}{dimension(SZI\_(G),SZJB\_(G))},         \textcolor{keywordtype}{intent(inout)} :: vort\_xy\_dx\textcolor{comment}{ !< x-derivative of vertical
       vorticity}
819 \textcolor{comment}{                                                                 !! (d/dx(dv/dx - du/dy)) [L-1 T-1 ~> m-1
       s-1]}
820   \textcolor{keywordtype}{real}, \textcolor{keywordtype}{dimension(SZIB\_(G),SZJ\_(G))},         \textcolor{keywordtype}{intent(inout)} :: vort\_xy\_dy\textcolor{comment}{ !< y-derivative of vertical
       vorticity}
821 \textcolor{comment}{                                                                 !! (d/dy(dv/dx - du/dy)) [L-1 T-1 ~> m-1
       s-1]}
822   \textcolor{comment}{! Local variables}
823   \textcolor{keywordtype}{real}, \textcolor{keywordtype}{dimension(SZI\_(G),SZJB\_(G))} :: &
824     dslopey\_dz, & \textcolor{comment}{! z-derivative of y-slope at v-points [Z-1 ~> m-1]}
825     h\_at\_v,     & \textcolor{comment}{! Thickness at v-points [H ~> m or kg m-2]}
826     beta\_v,     & \textcolor{comment}{! Beta at v-points [T-1 L-1 ~> s-1 m-1]}
827     grad\_vort\_mag\_v, & \textcolor{comment}{! Magnitude of vorticity gradient at v-points [T-1 L-1 ~> s-1 m-1]}
828     grad\_div\_mag\_v     \textcolor{comment}{! Magnitude of divergence gradient at v-points [T-1 L-1 ~> s-1 m-1]}
829 
830   \textcolor{keywordtype}{real}, \textcolor{keywordtype}{dimension(SZIB\_(G),SZJ\_(G))} :: &
831     dslopex\_dz, & \textcolor{comment}{! z-derivative of x-slope at u-points [Z-1 ~> m-1]}
832     h\_at\_u,     & \textcolor{comment}{! Thickness at u-points [H ~> m or kg m-2]}
833     beta\_u,     & \textcolor{comment}{! Beta at u-points [T-1 L-1 ~> s-1 m-1]}
834     grad\_vort\_mag\_u, & \textcolor{comment}{! Magnitude of vorticity gradient at u-points [T-1 L-1 ~> s-1 m-1]}
835     grad\_div\_mag\_u     \textcolor{comment}{! Magnitude of divergence gradient at u-points [T-1 L-1 ~> s-1 m-1]}
836   \textcolor{keywordtype}{real} :: h\_at\_slope\_above \textcolor{comment}{! The thickness above [H ~> m or kg m-2]}
837   \textcolor{keywordtype}{real} :: h\_at\_slope\_below \textcolor{comment}{! The thickness below [H ~> m or kg m-2]}
838   \textcolor{keywordtype}{real} :: Ih \textcolor{comment}{! The inverse of a combination of thicknesses [H-1 ~> m-1 or m2 kg-1]}
839   \textcolor{keywordtype}{real} :: f  \textcolor{comment}{! A copy of the Coriolis parameter [T-1 ~> s-1]}
840   \textcolor{keywordtype}{integer} :: i, j, is, ie, js, je, Isq, Ieq, Jsq, Jeq,nz
841   \textcolor{keywordtype}{real} :: inv\_PI3
842 
843   is  = g%isc  ; ie  = g%iec  ; js  = g%jsc  ; je  = g%jec
844   isq = g%IscB ; ieq = g%IecB ; jsq = g%JscB ; jeq = g%JecB
845   nz = g%ke
846 
847   inv\_pi3 = 1.0/((4.0*atan(1.0))**3)
848 
849   \textcolor{keywordflow}{if} ((k > 1) .and. (k < nz)) \textcolor{keywordflow}{then}
850 
851     \textcolor{keywordflow}{do} j=js-1,je+1 ; \textcolor{keywordflow}{do} i=is-2,ieq+1
852       h\_at\_slope\_above = 2. * ( h(i,j,k-1) * h(i+1,j,k-1) ) * ( h(i,j,k) * h(i+1,j,k) ) / &
853                          ( ( h(i,j,k-1) * h(i+1,j,k-1) ) * ( h(i,j,k) + h(i+1,j,k) ) &
854                          + ( h(i,j,k) * h(i+1,j,k) ) * ( h(i,j,k-1) + h(i+1,j,k-1) ) + gv%H\_subroundoff )
855       h\_at\_slope\_below = 2. * ( h(i,j,k) * h(i+1,j,k) ) * ( h(i,j,k+1) * h(i+1,j,k+1) ) / &
856                          ( ( h(i,j,k) * h(i+1,j,k) ) * ( h(i,j,k+1) + h(i+1,j,k+1) ) &
857                          + ( h(i,j,k+1) * h(i+1,j,k+1) ) * ( h(i,j,k) + h(i+1,j,k) ) + gv%H\_subroundoff )
858       ih = 1./ ( ( h\_at\_slope\_above + h\_at\_slope\_below + gv%H\_subroundoff ) * gv%H\_to\_Z )
859       dslopex\_dz(i,j) = 2. * ( cs%slope\_x(i,j,k) - cs%slope\_x(i,j,k+1) ) * ih
860       h\_at\_u(i,j) = 2. * ( h\_at\_slope\_above * h\_at\_slope\_below ) * ih
861 \textcolor{keywordflow}{    enddo} ;\textcolor{keywordflow}{ enddo}
862 
863     \textcolor{keywordflow}{do} j=js-2,jeq+1 ; \textcolor{keywordflow}{do} i=is-1,ie+1
864       h\_at\_slope\_above = 2. * ( h(i,j,k-1) * h(i,j+1,k-1) ) * ( h(i,j,k) * h(i,j+1,k) ) / &
865                          ( ( h(i,j,k-1) * h(i,j+1,k-1) ) * ( h(i,j,k) + h(i,j+1,k) ) &
866                          + ( h(i,j,k) * h(i,j+1,k) ) * ( h(i,j,k-1) + h(i,j+1,k-1) ) + gv%H\_subroundoff )
867       h\_at\_slope\_below = 2. * ( h(i,j,k) * h(i,j+1,k) ) * ( h(i,j,k+1) * h(i,j+1,k+1) ) / &
868                          ( ( h(i,j,k) * h(i,j+1,k) ) * ( h(i,j,k+1) + h(i,j+1,k+1) ) &
869                          + ( h(i,j,k+1) * h(i,j+1,k+1) ) * ( h(i,j,k) + h(i,j+1,k) ) + gv%H\_subroundoff )
870       ih = 1./ ( ( h\_at\_slope\_above + h\_at\_slope\_below + gv%H\_subroundoff ) * gv%H\_to\_Z )
871       dslopey\_dz(i,j) = 2. * ( cs%slope\_y(i,j,k) - cs%slope\_y(i,j,k+1) ) * ih
872       h\_at\_v(i,j) = 2. * ( h\_at\_slope\_above * h\_at\_slope\_below ) * ih
873 \textcolor{keywordflow}{    enddo} ;\textcolor{keywordflow}{ enddo}
874 
875     \textcolor{keywordflow}{do} j=js-1,je ; \textcolor{keywordflow}{do} i=is-1,ieq+1
876       f = 0.5 * ( g%CoriolisBu(i,j) + g%CoriolisBu(i-1,j) )
877       vort\_xy\_dx(i,j) = vort\_xy\_dx(i,j) - f * us%L\_to\_Z * &
878             ( ( h\_at\_u(i,j) * dslopex\_dz(i,j) + h\_at\_u(i-1,j+1) * dslopex\_dz(i-1,j+1) ) &
879             + ( h\_at\_u(i-1,j) * dslopex\_dz(i-1,j) + h\_at\_u(i,j+1) * dslopex\_dz(i,j+1) ) ) / &
880               ( ( h\_at\_u(i,j) + h\_at\_u(i-1,j+1) ) + ( h\_at\_u(i-1,j) + h\_at\_u(i,j+1) ) + gv%H\_subroundoff)
881 \textcolor{keywordflow}{    enddo} ;\textcolor{keywordflow}{ enddo}
882 
883     \textcolor{keywordflow}{do} j=js-1,jeq+1 ; \textcolor{keywordflow}{do} i=is-1,ie
884       f = 0.5 * ( g%CoriolisBu(i,j) + g%CoriolisBu(i,j-1) )
885       vort\_xy\_dy(i,j) = vort\_xy\_dy(i,j) - f * us%L\_to\_Z * &
886             ( ( h\_at\_v(i,j) * dslopey\_dz(i,j) + h\_at\_v(i+1,j-1) * dslopey\_dz(i+1,j-1) ) &
887             + ( h\_at\_v(i,j-1) * dslopey\_dz(i,j-1) + h\_at\_v(i+1,j) * dslopey\_dz(i+1,j) ) ) / &
888               ( ( h\_at\_v(i,j) + h\_at\_v(i+1,j-1) ) + ( h\_at\_v(i,j-1) + h\_at\_v(i+1,j) ) + gv%H\_subroundoff)
889 \textcolor{keywordflow}{    enddo} ;\textcolor{keywordflow}{ enddo}
890 \textcolor{keywordflow}{  endif} \textcolor{comment}{! k > 1}
891 
892   \textcolor{keywordflow}{if} (cs%use\_QG\_Leith\_GM) \textcolor{keywordflow}{then}
893 
894     \textcolor{keywordflow}{do} j=js,je ; \textcolor{keywordflow}{do} i=is-1,ieq
895       grad\_vort\_mag\_u(i,j) = sqrt(vort\_xy\_dy(i,j)**2  + (0.25*((vort\_xy\_dx(i,j) + vort\_xy\_dx(i+1,j-1)) &
896                                                              + (vort\_xy\_dx(i+1,j) + vort\_xy\_dx(i,j-1))))**2
      )
897       grad\_div\_mag\_u(i,j) = sqrt(div\_xx\_dx(i,j)**2  + (0.25*((div\_xx\_dy(i,j) + div\_xx\_dy(i+1,j-1)) &
898                                                            + (div\_xx\_dy(i+1,j) + div\_xx\_dy(i,j-1))))**2)
899       \textcolor{keywordflow}{if} (cs%use\_beta\_in\_QG\_Leith) \textcolor{keywordflow}{then}
900         beta\_u(i,j) = sqrt((0.5*(g%dF\_dx(i,j)+g%dF\_dx(i+1,j))**2) + &
901                           (0.5*(g%dF\_dy(i,j)+g%dF\_dy(i+1,j))**2))
902         cs%KH\_u\_QG(i,j,k) = min(grad\_vort\_mag\_u(i,j) + grad\_div\_mag\_u(i,j), 3.0*beta\_u(i,j)) * &
903                             cs%Laplac3\_const\_u(i,j) * inv\_pi3
904       \textcolor{keywordflow}{else}
905         cs%KH\_u\_QG(i,j,k) = (grad\_vort\_mag\_u(i,j) + grad\_div\_mag\_u(i,j)) * &
906                             cs%Laplac3\_const\_u(i,j) * inv\_pi3
907 \textcolor{keywordflow}{      endif}
908 \textcolor{keywordflow}{    enddo} ;\textcolor{keywordflow}{ enddo}
909 
910     \textcolor{keywordflow}{do} j=js-1,jeq ; \textcolor{keywordflow}{do} i=is,ie
911       grad\_vort\_mag\_v(i,j) = sqrt(vort\_xy\_dx(i,j)**2  + (0.25*((vort\_xy\_dy(i,j) + vort\_xy\_dy(i-1,j+1)) &
912                                                              + (vort\_xy\_dy(i,j+1) + vort\_xy\_dy(i-1,j))))**2
      )
913       grad\_div\_mag\_v(i,j) = sqrt(div\_xx\_dy(i,j)**2  + (0.25*((div\_xx\_dx(i,j) + div\_xx\_dx(i-1,j+1)) &
914                                                            + (div\_xx\_dx(i,j+1) + div\_xx\_dx(i-1,j))))**2)
915       \textcolor{keywordflow}{if} (cs%use\_beta\_in\_QG\_Leith) \textcolor{keywordflow}{then}
916         beta\_v(i,j) = sqrt((0.5*(g%dF\_dx(i,j)+g%dF\_dx(i,j+1))**2) + &
917                           (0.5*(g%dF\_dy(i,j)+g%dF\_dy(i,j+1))**2))
918         cs%KH\_v\_QG(i,j,k) = min(grad\_vort\_mag\_v(i,j) + grad\_div\_mag\_v(i,j), 3.0*beta\_v(i,j)) * &
919                             cs%Laplac3\_const\_v(i,j) * inv\_pi3
920       \textcolor{keywordflow}{else}
921         cs%KH\_v\_QG(i,j,k) = (grad\_vort\_mag\_v(i,j) + grad\_div\_mag\_v(i,j)) * &
922                             cs%Laplac3\_const\_v(i,j) * inv\_pi3
923 \textcolor{keywordflow}{      endif}
924 \textcolor{keywordflow}{    enddo} ;\textcolor{keywordflow}{ enddo}
925     \textcolor{comment}{! post diagnostics}
926 
927     \textcolor{keywordflow}{if} (k==nz) \textcolor{keywordflow}{then}
928       \textcolor{keywordflow}{if} (cs%id\_KH\_v\_QG > 0)  \textcolor{keyword}{call }post\_data(cs%id\_KH\_v\_QG, cs%KH\_v\_QG, cs%diag)
929       \textcolor{keywordflow}{if} (cs%id\_KH\_u\_QG > 0)  \textcolor{keyword}{call }post\_data(cs%id\_KH\_u\_QG, cs%KH\_u\_QG, cs%diag)
930 \textcolor{keywordflow}{    endif}
931 \textcolor{keywordflow}{  endif}
932 
\end{DoxyCode}
\mbox{\Hypertarget{namespacemom__lateral__mixing__coeffs_a8652c5651033573cfd6f09b789d64713}\label{namespacemom__lateral__mixing__coeffs_a8652c5651033573cfd6f09b789d64713}} 
\index{mom\+\_\+lateral\+\_\+mixing\+\_\+coeffs@{mom\+\_\+lateral\+\_\+mixing\+\_\+coeffs}!calc\+\_\+resoln\+\_\+function@{calc\+\_\+resoln\+\_\+function}}
\index{calc\+\_\+resoln\+\_\+function@{calc\+\_\+resoln\+\_\+function}!mom\+\_\+lateral\+\_\+mixing\+\_\+coeffs@{mom\+\_\+lateral\+\_\+mixing\+\_\+coeffs}}
\subsubsection{\texorpdfstring{calc\+\_\+resoln\+\_\+function()}{calc\_resoln\_function()}}
{\footnotesize\ttfamily subroutine, public mom\+\_\+lateral\+\_\+mixing\+\_\+coeffs\+::calc\+\_\+resoln\+\_\+function (\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[{type(ocean\+\_\+grid\+\_\+type), intent(inout)}]{G,  }\item[{type(verticalgrid\+\_\+type), intent(in)}]{GV,  }\item[{type(unit\+\_\+scale\+\_\+type), intent(in)}]{US,  }\item[{type(\mbox{\hyperlink{structmom__lateral__mixing__coeffs_1_1varmix__cs}{varmix\+\_\+cs}}), pointer}]{CS }\end{DoxyParamCaption})}



Calculates and stores the non-\/dimensional resolution functions. 


\begin{DoxyParams}[1]{Parameters}
\mbox{\tt in,out}  & {\em g} & Ocean grid structure\\
\hline
\mbox{\tt in}  & {\em h} & Layer thickness \mbox{[}H $\sim$$>$ m or kg m-\/2\mbox{]}\\
\hline
\mbox{\tt in}  & {\em tv} & Thermodynamic variables\\
\hline
\mbox{\tt in}  & {\em gv} & Vertical grid structure\\
\hline
\mbox{\tt in}  & {\em us} & A dimensional unit scaling type\\
\hline
 & {\em cs} & Variable mixing coefficients \\
\hline
\end{DoxyParams}


Definition at line 191 of file M\+O\+M\+\_\+lateral\+\_\+mixing\+\_\+coeffs.\+F90.


\begin{DoxyCode}
191   \textcolor{keywordtype}{type}(ocean\_grid\_type),                    \textcolor{keywordtype}{intent(inout)} :: G\textcolor{comment}{  !< Ocean grid structure}
192   \textcolor{keywordtype}{real}, \textcolor{keywordtype}{dimension(SZI\_(G),SZJ\_(G),SZK\_(G))}, \textcolor{keywordtype}{intent(in)}    :: h\textcolor{comment}{  !< Layer thickness [H ~> m or kg m-2]}
193   \textcolor{keywordtype}{type}(thermo\_var\_ptrs),                    \textcolor{keywordtype}{intent(in)}    :: tv\textcolor{comment}{ !< Thermodynamic variables}
194   \textcolor{keywordtype}{type}(verticalGrid\_type),                  \textcolor{keywordtype}{intent(in)}    :: GV\textcolor{comment}{ !< Vertical grid structure}
195   \textcolor{keywordtype}{type}(unit\_scale\_type),                    \textcolor{keywordtype}{intent(in)}    :: US\textcolor{comment}{ !< A dimensional unit scaling type}
196   \textcolor{keywordtype}{type}(VarMix\_CS),                          \textcolor{keywordtype}{pointer}       :: CS\textcolor{comment}{ !< Variable mixing coefficients}
197 
198   \textcolor{comment}{! Local variables}
199   \textcolor{comment}{! Depending on the power-function being used, dimensional rescaling may be limited, so some}
200   \textcolor{comment}{! of the following variables have units that depend on that power.}
201   \textcolor{keywordtype}{real} :: cg1\_q  \textcolor{comment}{! The gravity wave speed interpolated to q points [L T-1 ~> m s-1] or [m s-1].}
202   \textcolor{keywordtype}{real} :: cg1\_u  \textcolor{comment}{! The gravity wave speed interpolated to u points [L T-1 ~> m s-1] or [m s-1].}
203   \textcolor{keywordtype}{real} :: cg1\_v  \textcolor{comment}{! The gravity wave speed interpolated to v points [L T-1 ~> m s-1] or [m s-1].}
204   \textcolor{keywordtype}{real} :: dx\_term \textcolor{comment}{! A term in the denominator [L2 T-2 ~> m2 s-2] or [m2 s-2]}
205   \textcolor{keywordtype}{integer} :: power\_2
206   \textcolor{keywordtype}{integer} :: is, ie, js, je, Isq, Ieq, Jsq, Jeq, nz
207   \textcolor{keywordtype}{integer} :: i, j, k
208   is = g%isc ; ie = g%iec ; js = g%jsc ; je = g%jec ; nz = g%ke
209   isq = g%IscB ; ieq = g%IecB ; jsq = g%JscB ; jeq = g%JecB
210 
211   \textcolor{keywordflow}{if} (.not. \textcolor{keyword}{associated}(cs)) \textcolor{keyword}{call }mom\_error(fatal, \textcolor{stringliteral}{"calc\_resoln\_function:"}// &
212          \textcolor{stringliteral}{"Module must be initialized before it is used."})
213   \textcolor{keywordflow}{if} (cs%calculate\_cg1) \textcolor{keywordflow}{then}
214     \textcolor{keywordflow}{if} (.not. \textcolor{keyword}{associated}(cs%cg1)) \textcolor{keyword}{call }mom\_error(fatal, &
215       \textcolor{stringliteral}{"calc\_resoln\_function: %cg1 is not associated with Resoln\_scaled\_Kh."})
216     \textcolor{keywordflow}{if} (cs%khth\_use\_ebt\_struct) \textcolor{keywordflow}{then}
217       \textcolor{keywordflow}{if} (.not. \textcolor{keyword}{associated}(cs%ebt\_struct)) \textcolor{keyword}{call }mom\_error(fatal, &
218         \textcolor{stringliteral}{"calc\_resoln\_function: %ebt\_struct is not associated with RESOLN\_USE\_EBT."})
219       \textcolor{keywordflow}{if} (cs%Resoln\_use\_ebt) \textcolor{keywordflow}{then}
220         \textcolor{comment}{! Both resolution fn and vertical structure are using EBT}
221         \textcolor{keyword}{call }wave\_speed(h, tv, g, gv, us, cs%cg1, cs%wave\_speed\_CSp, modal\_structure=cs%ebt\_struct)
222       \textcolor{keywordflow}{else}
223         \textcolor{comment}{! Use EBT to get vertical structure first and then re-calculate cg1 using first baroclinic mode}
224         \textcolor{keyword}{call }wave\_speed(h, tv, g, gv, us, cs%cg1, cs%wave\_speed\_CSp, modal\_structure=cs%ebt\_struct, &
225                         use\_ebt\_mode=.true.)
226         \textcolor{keyword}{call }wave\_speed(h, tv, g, gv, us, cs%cg1, cs%wave\_speed\_CSp)
227 \textcolor{keywordflow}{      endif}
228       \textcolor{keyword}{call }pass\_var(cs%ebt\_struct, g%Domain)
229     \textcolor{keywordflow}{else}
230       \textcolor{keyword}{call }wave\_speed(h, tv, g, gv, us, cs%cg1, cs%wave\_speed\_CSp)
231 \textcolor{keywordflow}{    endif}
232 
233     \textcolor{keyword}{call }create\_group\_pass(cs%pass\_cg1, cs%cg1, g%Domain)
234     \textcolor{keyword}{call }do\_group\_pass(cs%pass\_cg1, g%Domain)
235 \textcolor{keywordflow}{  endif}
236 
237   \textcolor{comment}{! Calculate and store the ratio between deformation radius and grid-spacing}
238   \textcolor{comment}{! at h-points [nondim].}
239   \textcolor{keywordflow}{if} (cs%calculate\_rd\_dx) \textcolor{keywordflow}{then}
240     \textcolor{keywordflow}{if} (.not. \textcolor{keyword}{associated}(cs%Rd\_dx\_h)) \textcolor{keyword}{call }mom\_error(fatal, &
241       \textcolor{stringliteral}{"calc\_resoln\_function: %Rd\_dx\_h is not associated with calculate\_rd\_dx."})
242     \textcolor{comment}{!$OMP parallel do default(shared)}
243     \textcolor{keywordflow}{do} j=js-1,je+1 ; \textcolor{keywordflow}{do} i=is-1,ie+1
244       cs%Rd\_dx\_h(i,j) = cs%cg1(i,j) / &
245             (sqrt(cs%f2\_dx2\_h(i,j) + cs%cg1(i,j)*cs%beta\_dx2\_h(i,j)))
246 \textcolor{keywordflow}{    enddo} ;\textcolor{keywordflow}{ enddo}
247     \textcolor{keywordflow}{if} (query\_averaging\_enabled(cs%diag)) \textcolor{keywordflow}{then}
248       \textcolor{keywordflow}{if} (cs%id\_Rd\_dx > 0) \textcolor{keyword}{call }post\_data(cs%id\_Rd\_dx, cs%Rd\_dx\_h, cs%diag)
249 \textcolor{keywordflow}{    endif}
250 \textcolor{keywordflow}{  endif}
251 
252   \textcolor{keywordflow}{if} (.not. cs%calculate\_res\_fns) \textcolor{keywordflow}{return}
253 
254   \textcolor{keywordflow}{if} (.not. \textcolor{keyword}{associated}(cs%Res\_fn\_h)) \textcolor{keyword}{call }mom\_error(fatal, &
255     \textcolor{stringliteral}{"calc\_resoln\_function: %Res\_fn\_h is not associated with Resoln\_scaled\_Kh."})
256   \textcolor{keywordflow}{if} (.not. \textcolor{keyword}{associated}(cs%Res\_fn\_q)) \textcolor{keyword}{call }mom\_error(fatal, &
257     \textcolor{stringliteral}{"calc\_resoln\_function: %Res\_fn\_q is not associated with Resoln\_scaled\_Kh."})
258   \textcolor{keywordflow}{if} (.not. \textcolor{keyword}{associated}(cs%Res\_fn\_u)) \textcolor{keyword}{call }mom\_error(fatal, &
259     \textcolor{stringliteral}{"calc\_resoln\_function: %Res\_fn\_u is not associated with Resoln\_scaled\_Kh."})
260   \textcolor{keywordflow}{if} (.not. \textcolor{keyword}{associated}(cs%Res\_fn\_v)) \textcolor{keyword}{call }mom\_error(fatal, &
261     \textcolor{stringliteral}{"calc\_resoln\_function: %Res\_fn\_v is not associated with Resoln\_scaled\_Kh."})
262   \textcolor{keywordflow}{if} (.not. \textcolor{keyword}{associated}(cs%f2\_dx2\_h)) \textcolor{keyword}{call }mom\_error(fatal, &
263     \textcolor{stringliteral}{"calc\_resoln\_function: %f2\_dx2\_h is not associated with Resoln\_scaled\_Kh."})
264   \textcolor{keywordflow}{if} (.not. \textcolor{keyword}{associated}(cs%f2\_dx2\_q)) \textcolor{keyword}{call }mom\_error(fatal, &
265     \textcolor{stringliteral}{"calc\_resoln\_function: %f2\_dx2\_q is not associated with Resoln\_scaled\_Kh."})
266   \textcolor{keywordflow}{if} (.not. \textcolor{keyword}{associated}(cs%f2\_dx2\_u)) \textcolor{keyword}{call }mom\_error(fatal, &
267     \textcolor{stringliteral}{"calc\_resoln\_function: %f2\_dx2\_u is not associated with Resoln\_scaled\_Kh."})
268   \textcolor{keywordflow}{if} (.not. \textcolor{keyword}{associated}(cs%f2\_dx2\_v)) \textcolor{keyword}{call }mom\_error(fatal, &
269     \textcolor{stringliteral}{"calc\_resoln\_function: %f2\_dx2\_v is not associated with Resoln\_scaled\_Kh."})
270   \textcolor{keywordflow}{if} (.not. \textcolor{keyword}{associated}(cs%beta\_dx2\_h)) \textcolor{keyword}{call }mom\_error(fatal, &
271     \textcolor{stringliteral}{"calc\_resoln\_function: %beta\_dx2\_h is not associated with Resoln\_scaled\_Kh."})
272   \textcolor{keywordflow}{if} (.not. \textcolor{keyword}{associated}(cs%beta\_dx2\_q)) \textcolor{keyword}{call }mom\_error(fatal, &
273     \textcolor{stringliteral}{"calc\_resoln\_function: %beta\_dx2\_q is not associated with Resoln\_scaled\_Kh."})
274   \textcolor{keywordflow}{if} (.not. \textcolor{keyword}{associated}(cs%beta\_dx2\_u)) \textcolor{keyword}{call }mom\_error(fatal, &
275     \textcolor{stringliteral}{"calc\_resoln\_function: %beta\_dx2\_u is not associated with Resoln\_scaled\_Kh."})
276   \textcolor{keywordflow}{if} (.not. \textcolor{keyword}{associated}(cs%beta\_dx2\_v)) \textcolor{keyword}{call }mom\_error(fatal, &
277     \textcolor{stringliteral}{"calc\_resoln\_function: %beta\_dx2\_v is not associated with Resoln\_scaled\_Kh."})
278 
279   \textcolor{comment}{!   Do this calculation on the extent used in MOM\_hor\_visc.F90, and}
280   \textcolor{comment}{! MOM\_tracer.F90 so that no halo update is needed.}
281 
282 \textcolor{comment}{!$OMP parallel default(none) shared(is,ie,js,je,Ieq,Jeq,CS,US) &}
283 \textcolor{comment}{!$OMP                       private(dx\_term,cg1\_q,power\_2,cg1\_u,cg1\_v)}
284   \textcolor{keywordflow}{if} (cs%Res\_fn\_power\_visc >= 100) \textcolor{keywordflow}{then}
285 \textcolor{comment}{!$OMP do}
286     \textcolor{keywordflow}{do} j=js-1,je+1 ; \textcolor{keywordflow}{do} i=is-1,ie+1
287       dx\_term = cs%f2\_dx2\_h(i,j) + cs%cg1(i,j)*cs%beta\_dx2\_h(i,j)
288       \textcolor{keywordflow}{if} ((cs%Res\_coef\_visc * cs%cg1(i,j))**2 > dx\_term) \textcolor{keywordflow}{then}
289         cs%Res\_fn\_h(i,j) = 0.0
290       \textcolor{keywordflow}{else}
291         cs%Res\_fn\_h(i,j) = 1.0
292 \textcolor{keywordflow}{      endif}
293 \textcolor{keywordflow}{    enddo} ;\textcolor{keywordflow}{ enddo}
294 \textcolor{comment}{!$OMP do}
295     \textcolor{keywordflow}{do} j=js-1,jeq ; \textcolor{keywordflow}{do} i=is-1,ieq
296       cg1\_q = 0.25 * ((cs%cg1(i,j) + cs%cg1(i+1,j+1)) + (cs%cg1(i+1,j) + cs%cg1(i,j+1)))
297       dx\_term = cs%f2\_dx2\_q(i,j) +  cg1\_q * cs%beta\_dx2\_q(i,j)
298       \textcolor{keywordflow}{if} ((cs%Res\_coef\_visc * cg1\_q)**2 > dx\_term) \textcolor{keywordflow}{then}
299         cs%Res\_fn\_q(i,j) = 0.0
300       \textcolor{keywordflow}{else}
301         cs%Res\_fn\_q(i,j) = 1.0
302 \textcolor{keywordflow}{      endif}
303 \textcolor{keywordflow}{    enddo} ;\textcolor{keywordflow}{ enddo}
304   \textcolor{keywordflow}{elseif} (cs%Res\_fn\_power\_visc == 2) \textcolor{keywordflow}{then}
305 \textcolor{comment}{!$OMP do}
306     \textcolor{keywordflow}{do} j=js-1,je+1 ; \textcolor{keywordflow}{do} i=is-1,ie+1
307       dx\_term = cs%f2\_dx2\_h(i,j) + cs%cg1(i,j)*cs%beta\_dx2\_h(i,j)
308       cs%Res\_fn\_h(i,j) = dx\_term / (dx\_term + (cs%Res\_coef\_visc * cs%cg1(i,j))**2)
309 \textcolor{keywordflow}{    enddo} ;\textcolor{keywordflow}{ enddo}
310 \textcolor{comment}{!$OMP do}
311     \textcolor{keywordflow}{do} j=js-1,jeq ; \textcolor{keywordflow}{do} i=is-1,ieq
312       cg1\_q = 0.25 * ((cs%cg1(i,j) + cs%cg1(i+1,j+1)) + (cs%cg1(i+1,j) + cs%cg1(i,j+1)))
313       dx\_term = cs%f2\_dx2\_q(i,j) +  cg1\_q * cs%beta\_dx2\_q(i,j)
314       cs%Res\_fn\_q(i,j) = dx\_term / (dx\_term + (cs%Res\_coef\_visc * cg1\_q)**2)
315 \textcolor{keywordflow}{    enddo} ;\textcolor{keywordflow}{ enddo}
316   \textcolor{keywordflow}{elseif} (mod(cs%Res\_fn\_power\_visc, 2) == 0) \textcolor{keywordflow}{then}
317     power\_2 = cs%Res\_fn\_power\_visc / 2
318 \textcolor{comment}{!$OMP do}
319     \textcolor{keywordflow}{do} j=js-1,je+1 ; \textcolor{keywordflow}{do} i=is-1,ie+1
320       dx\_term = (us%L\_T\_to\_m\_s**2*(cs%f2\_dx2\_h(i,j) + cs%cg1(i,j)*cs%beta\_dx2\_h(i,j)))**power\_2
321       cs%Res\_fn\_h(i,j) = dx\_term / &
322           (dx\_term + (cs%Res\_coef\_visc * us%L\_T\_to\_m\_s*cs%cg1(i,j))**cs%Res\_fn\_power\_visc)
323 \textcolor{keywordflow}{    enddo} ;\textcolor{keywordflow}{ enddo}
324 \textcolor{comment}{!$OMP do}
325     \textcolor{keywordflow}{do} j=js-1,jeq ; \textcolor{keywordflow}{do} i=is-1,ieq
326       cg1\_q = 0.25 * ((cs%cg1(i,j) + cs%cg1(i+1,j+1)) + (cs%cg1(i+1,j) + cs%cg1(i,j+1)))
327       dx\_term = (us%L\_T\_to\_m\_s**2*(cs%f2\_dx2\_q(i,j) + cg1\_q * cs%beta\_dx2\_q(i,j)))**power\_2
328       cs%Res\_fn\_q(i,j) = dx\_term / &
329           (dx\_term + (cs%Res\_coef\_visc * us%L\_T\_to\_m\_s*cg1\_q)**cs%Res\_fn\_power\_visc)
330 \textcolor{keywordflow}{    enddo} ;\textcolor{keywordflow}{ enddo}
331   \textcolor{keywordflow}{else}
332 \textcolor{comment}{!$OMP do}
333     \textcolor{keywordflow}{do} j=js-1,je+1 ; \textcolor{keywordflow}{do} i=is-1,ie+1
334       dx\_term = (us%L\_T\_to\_m\_s*sqrt(cs%f2\_dx2\_h(i,j) + &
335                                     cs%cg1(i,j)*cs%beta\_dx2\_h(i,j)))**cs%Res\_fn\_power\_visc
336       cs%Res\_fn\_h(i,j) = dx\_term / &
337          (dx\_term + (cs%Res\_coef\_visc * us%L\_T\_to\_m\_s*cs%cg1(i,j))**cs%Res\_fn\_power\_visc)
338 \textcolor{keywordflow}{    enddo} ;\textcolor{keywordflow}{ enddo}
339 \textcolor{comment}{!$OMP do}
340     \textcolor{keywordflow}{do} j=js-1,jeq ; \textcolor{keywordflow}{do} i=is-1,ieq
341       cg1\_q = 0.25 * ((cs%cg1(i,j) + cs%cg1(i+1,j+1)) + (cs%cg1(i+1,j) + cs%cg1(i,j+1)))
342       dx\_term = (us%L\_T\_to\_m\_s*sqrt(cs%f2\_dx2\_q(i,j) + &
343                                     cg1\_q * cs%beta\_dx2\_q(i,j)))**cs%Res\_fn\_power\_visc
344       cs%Res\_fn\_q(i,j) = dx\_term / &
345           (dx\_term + (cs%Res\_coef\_visc * us%L\_T\_to\_m\_s*cg1\_q)**cs%Res\_fn\_power\_visc)
346 \textcolor{keywordflow}{    enddo} ;\textcolor{keywordflow}{ enddo}
347 \textcolor{keywordflow}{  endif}
348 
349   \textcolor{keywordflow}{if} (cs%interpolate\_Res\_fn) \textcolor{keywordflow}{then}
350     \textcolor{keywordflow}{do} j=js,je ; \textcolor{keywordflow}{do} i=is-1,ieq
351       cs%Res\_fn\_u(i,j) = 0.5*(cs%Res\_fn\_h(i,j) + cs%Res\_fn\_h(i+1,j))
352 \textcolor{keywordflow}{    enddo} ;\textcolor{keywordflow}{ enddo}
353     \textcolor{keywordflow}{do} j=js-1,jeq ; \textcolor{keywordflow}{do} i=is,ie
354       cs%Res\_fn\_v(i,j) = 0.5*(cs%Res\_fn\_h(i,j) + cs%Res\_fn\_h(i,j+1))
355 \textcolor{keywordflow}{    enddo} ;\textcolor{keywordflow}{ enddo}
356   \textcolor{keywordflow}{else} \textcolor{comment}{! .not.CS%interpolate\_Res\_fn}
357     \textcolor{keywordflow}{if} (cs%Res\_fn\_power\_khth >= 100) \textcolor{keywordflow}{then}
358 \textcolor{comment}{!$OMP do}
359       \textcolor{keywordflow}{do} j=js,je ; \textcolor{keywordflow}{do} i=is-1,ieq
360         cg1\_u = 0.5 * (cs%cg1(i,j) + cs%cg1(i+1,j))
361         dx\_term = cs%f2\_dx2\_u(i,j) + cg1\_u * cs%beta\_dx2\_u(i,j)
362         \textcolor{keywordflow}{if} ((cs%Res\_coef\_khth * cg1\_u)**2 > dx\_term) \textcolor{keywordflow}{then}
363           cs%Res\_fn\_u(i,j) = 0.0
364         \textcolor{keywordflow}{else}
365           cs%Res\_fn\_u(i,j) = 1.0
366 \textcolor{keywordflow}{        endif}
367 \textcolor{keywordflow}{      enddo} ;\textcolor{keywordflow}{ enddo}
368 \textcolor{comment}{!$OMP do}
369       \textcolor{keywordflow}{do} j=js-1,jeq ; \textcolor{keywordflow}{do} i=is,ie
370         cg1\_v = 0.5 * (cs%cg1(i,j) + cs%cg1(i,j+1))
371         dx\_term = cs%f2\_dx2\_v(i,j) + cg1\_v * cs%beta\_dx2\_v(i,j)
372         \textcolor{keywordflow}{if} ((cs%Res\_coef\_khth * cg1\_v)**2 > dx\_term) \textcolor{keywordflow}{then}
373           cs%Res\_fn\_v(i,j) = 0.0
374         \textcolor{keywordflow}{else}
375           cs%Res\_fn\_v(i,j) = 1.0
376 \textcolor{keywordflow}{        endif}
377 \textcolor{keywordflow}{      enddo} ;\textcolor{keywordflow}{ enddo}
378     \textcolor{keywordflow}{elseif} (cs%Res\_fn\_power\_khth == 2) \textcolor{keywordflow}{then}
379 \textcolor{comment}{!$OMP do}
380       \textcolor{keywordflow}{do} j=js,je ; \textcolor{keywordflow}{do} i=is-1,ieq
381         cg1\_u = 0.5 * (cs%cg1(i,j) + cs%cg1(i+1,j))
382         dx\_term = cs%f2\_dx2\_u(i,j) + cg1\_u * cs%beta\_dx2\_u(i,j)
383         cs%Res\_fn\_u(i,j) = dx\_term / (dx\_term + (cs%Res\_coef\_khth * cg1\_u)**2)
384 \textcolor{keywordflow}{      enddo} ;\textcolor{keywordflow}{ enddo}
385 \textcolor{comment}{!$OMP do}
386       \textcolor{keywordflow}{do} j=js-1,jeq ; \textcolor{keywordflow}{do} i=is,ie
387         cg1\_v = 0.5 * (cs%cg1(i,j) + cs%cg1(i,j+1))
388         dx\_term = cs%f2\_dx2\_v(i,j) + cg1\_v * cs%beta\_dx2\_v(i,j)
389         cs%Res\_fn\_v(i,j) = dx\_term / (dx\_term + (cs%Res\_coef\_khth * cg1\_v)**2)
390 \textcolor{keywordflow}{      enddo} ;\textcolor{keywordflow}{ enddo}
391     \textcolor{keywordflow}{elseif} (mod(cs%Res\_fn\_power\_khth, 2) == 0) \textcolor{keywordflow}{then}
392       power\_2 = cs%Res\_fn\_power\_khth / 2
393 \textcolor{comment}{!$OMP do}
394       \textcolor{keywordflow}{do} j=js,je ; \textcolor{keywordflow}{do} i=is-1,ieq
395         cg1\_u = 0.5 * (cs%cg1(i,j) + cs%cg1(i+1,j))
396         dx\_term = (us%L\_T\_to\_m\_s**2 * (cs%f2\_dx2\_u(i,j) + cg1\_u * cs%beta\_dx2\_u(i,j)))**power\_2
397         cs%Res\_fn\_u(i,j) = dx\_term / &
398             (dx\_term + (cs%Res\_coef\_khth * us%L\_T\_to\_m\_s*cg1\_u)**cs%Res\_fn\_power\_khth)
399 \textcolor{keywordflow}{      enddo} ;\textcolor{keywordflow}{ enddo}
400 \textcolor{comment}{!$OMP do}
401       \textcolor{keywordflow}{do} j=js-1,jeq ; \textcolor{keywordflow}{do} i=is,ie
402         cg1\_v = 0.5 * (cs%cg1(i,j) + cs%cg1(i,j+1))
403         dx\_term = (us%L\_T\_to\_m\_s**2 * (cs%f2\_dx2\_v(i,j) + cg1\_v * cs%beta\_dx2\_v(i,j)))**power\_2
404         cs%Res\_fn\_v(i,j) = dx\_term / &
405             (dx\_term + (cs%Res\_coef\_khth * us%L\_T\_to\_m\_s*cg1\_v)**cs%Res\_fn\_power\_khth)
406 \textcolor{keywordflow}{      enddo} ;\textcolor{keywordflow}{ enddo}
407     \textcolor{keywordflow}{else}
408 \textcolor{comment}{!$OMP do}
409       \textcolor{keywordflow}{do} j=js,je ; \textcolor{keywordflow}{do} i=is-1,ieq
410         cg1\_u = 0.5 * (cs%cg1(i,j) + cs%cg1(i+1,j))
411         dx\_term = (us%L\_T\_to\_m\_s*sqrt(cs%f2\_dx2\_u(i,j) + &
412                                       cg1\_u * cs%beta\_dx2\_u(i,j)))**cs%Res\_fn\_power\_khth
413         cs%Res\_fn\_u(i,j) = dx\_term / &
414             (dx\_term + (cs%Res\_coef\_khth * us%L\_T\_to\_m\_s*cg1\_u)**cs%Res\_fn\_power\_khth)
415 \textcolor{keywordflow}{      enddo} ;\textcolor{keywordflow}{ enddo}
416 \textcolor{comment}{!$OMP do}
417       \textcolor{keywordflow}{do} j=js-1,jeq ; \textcolor{keywordflow}{do} i=is,ie
418         cg1\_v = 0.5 * (cs%cg1(i,j) + cs%cg1(i,j+1))
419         dx\_term = (us%L\_T\_to\_m\_s*sqrt(cs%f2\_dx2\_v(i,j) + &
420                                       cg1\_v * cs%beta\_dx2\_v(i,j)))**cs%Res\_fn\_power\_khth
421         cs%Res\_fn\_v(i,j) = dx\_term / &
422             (dx\_term + (cs%Res\_coef\_khth * us%L\_T\_to\_m\_s*cg1\_v)**cs%Res\_fn\_power\_khth)
423 \textcolor{keywordflow}{      enddo} ;\textcolor{keywordflow}{ enddo}
424 \textcolor{keywordflow}{    endif}
425 \textcolor{keywordflow}{  endif}
426 \textcolor{comment}{!$OMP end parallel}
427 
428   \textcolor{keywordflow}{if} (query\_averaging\_enabled(cs%diag)) \textcolor{keywordflow}{then}
429     \textcolor{keywordflow}{if} (cs%id\_Res\_fn > 0) \textcolor{keyword}{call }post\_data(cs%id\_Res\_fn, cs%Res\_fn\_h, cs%diag)
430 \textcolor{keywordflow}{  endif}
431 
\end{DoxyCode}
\mbox{\Hypertarget{namespacemom__lateral__mixing__coeffs_a1afa768a2df4c937842247cea00d184a}\label{namespacemom__lateral__mixing__coeffs_a1afa768a2df4c937842247cea00d184a}} 
\index{mom\+\_\+lateral\+\_\+mixing\+\_\+coeffs@{mom\+\_\+lateral\+\_\+mixing\+\_\+coeffs}!calc\+\_\+slope\+\_\+functions@{calc\+\_\+slope\+\_\+functions}}
\index{calc\+\_\+slope\+\_\+functions@{calc\+\_\+slope\+\_\+functions}!mom\+\_\+lateral\+\_\+mixing\+\_\+coeffs@{mom\+\_\+lateral\+\_\+mixing\+\_\+coeffs}}
\subsubsection{\texorpdfstring{calc\+\_\+slope\+\_\+functions()}{calc\_slope\_functions()}}
{\footnotesize\ttfamily subroutine, public mom\+\_\+lateral\+\_\+mixing\+\_\+coeffs\+::calc\+\_\+slope\+\_\+functions (\begin{DoxyParamCaption}\item[{real, dimension( g \%isd\+: g \%ied, g \%jsd\+: g \%jed, g \%ke), intent(inout)}]{h,  }\item[{type(thermo\+\_\+var\+\_\+ptrs), intent(in)}]{tv,  }\item[{real, intent(in)}]{dt,  }\item[{type(ocean\+\_\+grid\+\_\+type), intent(inout)}]{G,  }\item[{type(verticalgrid\+\_\+type), intent(in)}]{GV,  }\item[{type(unit\+\_\+scale\+\_\+type), intent(in)}]{US,  }\item[{type(\mbox{\hyperlink{structmom__lateral__mixing__coeffs_1_1varmix__cs}{varmix\+\_\+cs}}), pointer}]{CS,  }\item[{type(ocean\+\_\+obc\+\_\+type), optional, pointer}]{O\+BC }\end{DoxyParamCaption})}



Calculates and stores functions of isopycnal slopes, e.\+g. Sx, Sy, S$\ast$N, mostly used in the Visbeck et al. style scaling of diffusivity. 


\begin{DoxyParams}[1]{Parameters}
\mbox{\tt in,out}  & {\em g} & Ocean grid structure\\
\hline
\mbox{\tt in}  & {\em gv} & Vertical grid structure\\
\hline
\mbox{\tt in}  & {\em us} & A dimensional unit scaling type\\
\hline
\mbox{\tt in,out}  & {\em h} & Layer thickness \mbox{[}H $\sim$$>$ m or kg m-\/2\mbox{]}\\
\hline
\mbox{\tt in}  & {\em tv} & Thermodynamic variables\\
\hline
\mbox{\tt in}  & {\em dt} & Time increment \mbox{[}T $\sim$$>$ s\mbox{]}\\
\hline
 & {\em cs} & Variable mixing coefficients\\
\hline
 & {\em obc} & Open boundaries control structure. \\
\hline
\end{DoxyParams}


Definition at line 437 of file M\+O\+M\+\_\+lateral\+\_\+mixing\+\_\+coeffs.\+F90.


\begin{DoxyCode}
437   \textcolor{keywordtype}{type}(ocean\_grid\_type),                    \textcolor{keywordtype}{intent(inout)} :: G\textcolor{comment}{  !< Ocean grid structure}
438   \textcolor{keywordtype}{type}(verticalGrid\_type),                  \textcolor{keywordtype}{intent(in)}    :: GV\textcolor{comment}{ !< Vertical grid structure}
439   \textcolor{keywordtype}{type}(unit\_scale\_type),                    \textcolor{keywordtype}{intent(in)}    :: US\textcolor{comment}{ !< A dimensional unit scaling type}
440   \textcolor{keywordtype}{real}, \textcolor{keywordtype}{dimension(SZI\_(G),SZJ\_(G),SZK\_(G))}, \textcolor{keywordtype}{intent(inout)} :: h\textcolor{comment}{  !< Layer thickness [H ~> m or kg m-2]}
441   \textcolor{keywordtype}{type}(thermo\_var\_ptrs),                    \textcolor{keywordtype}{intent(in)}    :: tv\textcolor{comment}{ !< Thermodynamic variables}
442   \textcolor{keywordtype}{real},                                     \textcolor{keywordtype}{intent(in)}    :: dt\textcolor{comment}{ !< Time increment [T ~> s]}
443   \textcolor{keywordtype}{type}(VarMix\_CS),                          \textcolor{keywordtype}{pointer}       :: CS\textcolor{comment}{ !< Variable mixing coefficients}
444   \textcolor{keywordtype}{type}(ocean\_OBC\_type),           \textcolor{keywordtype}{optional}, \textcolor{keywordtype}{pointer}       :: OBC\textcolor{comment}{ !< Open boundaries control structure.}
445   \textcolor{comment}{! Local variables}
446   \textcolor{keywordtype}{real}, \textcolor{keywordtype}{dimension(SZI\_(G), SZJ\_(G), SZK\_(G)+1)} :: &
447     e             \textcolor{comment}{! The interface heights relative to mean sea level [Z ~> m].}
448   \textcolor{keywordtype}{real}, \textcolor{keywordtype}{dimension(SZIB\_(G), SZJ\_(G), SZK\_(G)+1)} :: N2\_u \textcolor{comment}{! Square of Brunt-Vaisala freq at u-points [T-2 ~>
       s-2]}
449   \textcolor{keywordtype}{real}, \textcolor{keywordtype}{dimension(SZI\_(G), SZJB\_(G), SZK\_(G)+1)} :: N2\_v \textcolor{comment}{! Square of Brunt-Vaisala freq at v-points [T-2 ~>
       s-2]}
450 
451   \textcolor{keywordflow}{if} (.not. \textcolor{keyword}{associated}(cs)) \textcolor{keyword}{call }mom\_error(fatal, \textcolor{stringliteral}{"MOM\_lateral\_mixing\_coeffs.F90, calc\_slope\_functions:"}//&
452          \textcolor{stringliteral}{"Module must be initialized before it is used."})
453 
454   \textcolor{keywordflow}{if} (cs%calculate\_Eady\_growth\_rate) \textcolor{keywordflow}{then}
455     \textcolor{keyword}{call }find\_eta(h, tv, g, gv, us, e, halo\_size=2)
456     \textcolor{keywordflow}{if} (cs%use\_stored\_slopes) \textcolor{keywordflow}{then}
457       \textcolor{keyword}{call }calc\_isoneutral\_slopes(g, gv, us, h, e, tv, dt*cs%kappa\_smooth, &
458                                   cs%slope\_x, cs%slope\_y, n2\_u, n2\_v, 1, obc=obc)
459       \textcolor{keyword}{call }calc\_visbeck\_coeffs(h, cs%slope\_x, cs%slope\_y, n2\_u, n2\_v, g, gv, us, cs, obc=obc)
460 \textcolor{comment}{!     call calc\_slope\_functions\_using\_just\_e(h, G, CS, e, .false.)}
461     \textcolor{keywordflow}{else}
462       \textcolor{comment}{!call calc\_isoneutral\_slopes(G, GV, h, e, tv, dt*CS%kappa\_smooth, CS%slope\_x, CS%slope\_y)}
463       \textcolor{keyword}{call }calc\_slope\_functions\_using\_just\_e(h, g, gv, us, cs, e, .true., obc=obc)
464 \textcolor{keywordflow}{    endif}
465 \textcolor{keywordflow}{  endif}
466 
467   \textcolor{keywordflow}{if} (query\_averaging\_enabled(cs%diag)) \textcolor{keywordflow}{then}
468     \textcolor{keywordflow}{if} (cs%id\_SN\_u > 0) \textcolor{keyword}{call }post\_data(cs%id\_SN\_u, cs%SN\_u, cs%diag)
469     \textcolor{keywordflow}{if} (cs%id\_SN\_v > 0) \textcolor{keyword}{call }post\_data(cs%id\_SN\_v, cs%SN\_v, cs%diag)
470     \textcolor{keywordflow}{if} (cs%id\_L2u > 0)  \textcolor{keyword}{call }post\_data(cs%id\_L2u, cs%L2u, cs%diag)
471     \textcolor{keywordflow}{if} (cs%id\_L2v > 0)  \textcolor{keyword}{call }post\_data(cs%id\_L2v, cs%L2v, cs%diag)
472     \textcolor{keywordflow}{if} (cs%calculate\_Eady\_growth\_rate .and. cs%use\_stored\_slopes) \textcolor{keywordflow}{then}
473       \textcolor{keywordflow}{if} (cs%id\_N2\_u > 0) \textcolor{keyword}{call }post\_data(cs%id\_N2\_u, n2\_u, cs%diag)
474       \textcolor{keywordflow}{if} (cs%id\_N2\_v > 0) \textcolor{keyword}{call }post\_data(cs%id\_N2\_v, n2\_v, cs%diag)
475 \textcolor{keywordflow}{    endif}
476 \textcolor{keywordflow}{  endif}
477 
\end{DoxyCode}
\mbox{\Hypertarget{namespacemom__lateral__mixing__coeffs_a9947860318104ed1662ff4f9d671f92d}\label{namespacemom__lateral__mixing__coeffs_a9947860318104ed1662ff4f9d671f92d}} 
\index{mom\+\_\+lateral\+\_\+mixing\+\_\+coeffs@{mom\+\_\+lateral\+\_\+mixing\+\_\+coeffs}!calc\+\_\+slope\+\_\+functions\+\_\+using\+\_\+just\+\_\+e@{calc\+\_\+slope\+\_\+functions\+\_\+using\+\_\+just\+\_\+e}}
\index{calc\+\_\+slope\+\_\+functions\+\_\+using\+\_\+just\+\_\+e@{calc\+\_\+slope\+\_\+functions\+\_\+using\+\_\+just\+\_\+e}!mom\+\_\+lateral\+\_\+mixing\+\_\+coeffs@{mom\+\_\+lateral\+\_\+mixing\+\_\+coeffs}}
\subsubsection{\texorpdfstring{calc\+\_\+slope\+\_\+functions\+\_\+using\+\_\+just\+\_\+e()}{calc\_slope\_functions\_using\_just\_e()}}
{\footnotesize\ttfamily subroutine mom\+\_\+lateral\+\_\+mixing\+\_\+coeffs\+::calc\+\_\+slope\+\_\+functions\+\_\+using\+\_\+just\+\_\+e (\begin{DoxyParamCaption}\item[{real, dimension( g \%isd\+: g \%ied, g \%jsd\+: g \%jed, g \%ke), intent(inout)}]{h,  }\item[{type(ocean\+\_\+grid\+\_\+type), intent(inout)}]{G,  }\item[{type(verticalgrid\+\_\+type), intent(in)}]{GV,  }\item[{type(unit\+\_\+scale\+\_\+type), intent(in)}]{US,  }\item[{type(\mbox{\hyperlink{structmom__lateral__mixing__coeffs_1_1varmix__cs}{varmix\+\_\+cs}}), pointer}]{CS,  }\item[{real, dimension( g \%isd\+: g \%ied, g \%jsd\+: g \%jed, g \%ke+1), intent(in)}]{e,  }\item[{logical, intent(in)}]{calculate\+\_\+slopes,  }\item[{type(ocean\+\_\+obc\+\_\+type), optional, pointer}]{O\+BC }\end{DoxyParamCaption})\hspace{0.3cm}{\ttfamily [private]}}



The original calc\+\_\+slope\+\_\+function() that calculated slopes using interface positions only, not accounting for density variations. 


\begin{DoxyParams}[1]{Parameters}
\mbox{\tt in,out}  & {\em g} & Ocean grid structure\\
\hline
\mbox{\tt in,out}  & {\em h} & Layer thickness \mbox{[}H $\sim$$>$ m or kg m-\/2\mbox{]}\\
\hline
\mbox{\tt in}  & {\em gv} & Vertical grid structure\\
\hline
\mbox{\tt in}  & {\em us} & A dimensional unit scaling type\\
\hline
 & {\em cs} & Variable mixing coefficients\\
\hline
\mbox{\tt in}  & {\em e} & Interface position \mbox{[}Z $\sim$$>$ m\mbox{]}\\
\hline
\mbox{\tt in}  & {\em calculate\+\_\+slopes} & If true, calculate slopes internally otherwise use slopes stored in CS\\
\hline
 & {\em obc} & Open boundaries control structure. \\
\hline
\end{DoxyParams}


Definition at line 647 of file M\+O\+M\+\_\+lateral\+\_\+mixing\+\_\+coeffs.\+F90.


\begin{DoxyCode}
647   \textcolor{keywordtype}{type}(ocean\_grid\_type),                      \textcolor{keywordtype}{intent(inout)} :: G\textcolor{comment}{  !< Ocean grid structure}
648   \textcolor{keywordtype}{real}, \textcolor{keywordtype}{dimension(SZI\_(G),SZJ\_(G),SZK\_(G))},   \textcolor{keywordtype}{intent(inout)} :: h\textcolor{comment}{  !< Layer thickness [H ~> m or kg m-2]}
649   \textcolor{keywordtype}{type}(verticalGrid\_type),                    \textcolor{keywordtype}{intent(in)}    :: GV\textcolor{comment}{ !< Vertical grid structure}
650   \textcolor{keywordtype}{type}(unit\_scale\_type),                      \textcolor{keywordtype}{intent(in)}    :: US\textcolor{comment}{ !< A dimensional unit scaling type}
651   \textcolor{keywordtype}{type}(VarMix\_CS),                            \textcolor{keywordtype}{pointer}       :: CS\textcolor{comment}{ !< Variable mixing coefficients}
652   \textcolor{keywordtype}{real}, \textcolor{keywordtype}{dimension(SZI\_(G),SZJ\_(G),SZK\_(G)+1)}, \textcolor{keywordtype}{intent(in)}    :: e\textcolor{comment}{  !< Interface position [Z ~> m]}
653   \textcolor{keywordtype}{logical},                                    \textcolor{keywordtype}{intent(in)}    :: calculate\_slopes\textcolor{comment}{ !< If true, calculate
       slopes internally}
654 \textcolor{comment}{                                                                  !! otherwise use slopes stored in CS}
655   \textcolor{keywordtype}{type}(ocean\_OBC\_type),             \textcolor{keywordtype}{optional}, \textcolor{keywordtype}{pointer}       :: OBC\textcolor{comment}{ !< Open boundaries control structure.}
656   \textcolor{comment}{! Local variables}
657   \textcolor{keywordtype}{real} :: E\_x(SZIB\_(G), SZJ\_(G))  \textcolor{comment}{! X-slope of interface at u points [nondim] (for diagnostics)}
658   \textcolor{keywordtype}{real} :: E\_y(SZI\_(G), SZJB\_(G))  \textcolor{comment}{! Y-slope of interface at v points [nondim] (for diagnostics)}
659   \textcolor{keywordtype}{real} :: H\_cutoff      \textcolor{comment}{! Local estimate of a minimum thickness for masking [H ~> m or kg m-2]}
660   \textcolor{keywordtype}{real} :: h\_neglect     \textcolor{comment}{! A thickness that is so small it is usually lost}
661                         \textcolor{comment}{! in roundoff and can be neglected [H ~> m or kg m-2].}
662   \textcolor{keywordtype}{real} :: S2            \textcolor{comment}{! Interface slope squared [nondim]}
663   \textcolor{keywordtype}{real} :: N2            \textcolor{comment}{! Brunt-Vaisala frequency squared [T-2 ~> s-2]}
664   \textcolor{keywordtype}{real} :: Hup, Hdn      \textcolor{comment}{! Thickness from above, below [H ~> m or kg m-2]}
665   \textcolor{keywordtype}{real} :: H\_geom        \textcolor{comment}{! The geometric mean of Hup*Hdn [H ~> m or kg m-2].}
666   \textcolor{keywordtype}{real} :: one\_meter     \textcolor{comment}{! One meter in thickness units [H ~> m or kg m-2].}
667   \textcolor{keywordtype}{integer} :: is, ie, js, je, nz
668   \textcolor{keywordtype}{integer} :: i, j, k, kb\_max
669   \textcolor{keywordtype}{integer} :: l\_seg
670   \textcolor{keywordtype}{real}    :: S2N2\_u\_local(SZIB\_(G), SZJ\_(G),SZK\_(G))
671   \textcolor{keywordtype}{real}    :: S2N2\_v\_local(SZI\_(G), SZJB\_(G),SZK\_(G))
672   \textcolor{keywordtype}{logical} :: local\_open\_u\_BC, local\_open\_v\_BC
673 
674   \textcolor{keywordflow}{if} (.not. \textcolor{keyword}{associated}(cs)) \textcolor{keyword}{call }mom\_error(fatal, \textcolor{stringliteral}{"calc\_slope\_function:"}// &
675          \textcolor{stringliteral}{"Module must be initialized before it is used."})
676   \textcolor{keywordflow}{if} (.not. cs%calculate\_Eady\_growth\_rate) \textcolor{keywordflow}{return}
677   \textcolor{keywordflow}{if} (.not. \textcolor{keyword}{associated}(cs%SN\_u)) \textcolor{keyword}{call }mom\_error(fatal, \textcolor{stringliteral}{"calc\_slope\_function:"}// &
678          \textcolor{stringliteral}{"%SN\_u is not associated with use\_variable\_mixing."})
679   \textcolor{keywordflow}{if} (.not. \textcolor{keyword}{associated}(cs%SN\_v)) \textcolor{keyword}{call }mom\_error(fatal, \textcolor{stringliteral}{"calc\_slope\_function:"}// &
680          \textcolor{stringliteral}{"%SN\_v is not associated with use\_variable\_mixing."})
681 
682   is = g%isc ; ie = g%iec ; js = g%jsc ; je = g%jec ; nz = g%ke
683 
684   local\_open\_u\_bc = .false.
685   local\_open\_v\_bc = .false.
686   \textcolor{keywordflow}{if} (\textcolor{keyword}{present}(obc)) \textcolor{keywordflow}{then} ; \textcolor{keywordflow}{if} (\textcolor{keyword}{associated}(obc)) \textcolor{keywordflow}{then}
687     local\_open\_u\_bc = obc%open\_u\_BCs\_exist\_globally
688     local\_open\_v\_bc = obc%open\_v\_BCs\_exist\_globally
689 \textcolor{keywordflow}{  endif} ;\textcolor{keywordflow}{ endif}
690 
691   one\_meter = 1.0 * gv%m\_to\_H
692   h\_neglect = gv%H\_subroundoff
693   h\_cutoff = \textcolor{keywordtype}{real(2*nz)} * (GV%Angstrom\_H + h\_neglect)
694 
695   \textcolor{comment}{! To set the length scale based on the deformation radius, use wave\_speed to}
696   \textcolor{comment}{! calculate the first-mode gravity wave speed and then blend the equatorial}
697   \textcolor{comment}{! and midlatitude deformation radii, using calc\_resoln\_function as a template.}
698 
699   \textcolor{comment}{!$OMP parallel do default(shared) private(E\_x,E\_y,S2,Hdn,Hup,H\_geom,N2)}
700   \textcolor{keywordflow}{do} k=nz,cs%VarMix\_Ktop,-1
701 
702     \textcolor{keywordflow}{if} (calculate\_slopes) \textcolor{keywordflow}{then}
703       \textcolor{comment}{! Calculate the interface slopes E\_x and E\_y and u- and v- points respectively}
704       \textcolor{keywordflow}{do} j=js-1,je+1 ; \textcolor{keywordflow}{do} i=is-1,ie
705         e\_x(i,j) = us%Z\_to\_L*(e(i+1,j,k)-e(i,j,k))*g%IdxCu(i,j)
706         \textcolor{comment}{! Mask slopes where interface intersects topography}
707         \textcolor{keywordflow}{if} (min(h(i,j,k),h(i+1,j,k)) < h\_cutoff) e\_x(i,j) = 0.
708 \textcolor{keywordflow}{      enddo} ;\textcolor{keywordflow}{ enddo}
709       \textcolor{keywordflow}{do} j=js-1,je ; \textcolor{keywordflow}{do} i=is-1,ie+1
710         e\_y(i,j) = us%Z\_to\_L*(e(i,j+1,k)-e(i,j,k))*g%IdyCv(i,j)
711         \textcolor{comment}{! Mask slopes where interface intersects topography}
712         \textcolor{keywordflow}{if} (min(h(i,j,k),h(i,j+1,k)) < h\_cutoff) e\_y(i,j) = 0.
713 \textcolor{keywordflow}{      enddo} ;\textcolor{keywordflow}{ enddo}
714     \textcolor{keywordflow}{else}
715       \textcolor{keywordflow}{do} j=js-1,je+1 ; \textcolor{keywordflow}{do} i=is-1,ie
716         e\_x(i,j) = cs%slope\_x(i,j,k)
717         \textcolor{keywordflow}{if} (min(h(i,j,k),h(i+1,j,k)) < h\_cutoff) e\_x(i,j) = 0.
718 \textcolor{keywordflow}{      enddo} ;\textcolor{keywordflow}{ enddo}
719       \textcolor{keywordflow}{do} j=js-1,je ; \textcolor{keywordflow}{do} i=is-1,ie+1
720         e\_y(i,j) = cs%slope\_y(i,j,k)
721         \textcolor{keywordflow}{if} (min(h(i,j,k),h(i,j+1,k)) < h\_cutoff) e\_y(i,j) = 0.
722 \textcolor{keywordflow}{      enddo} ;\textcolor{keywordflow}{ enddo}
723 \textcolor{keywordflow}{    endif}
724 
725     \textcolor{comment}{! Calculate N*S*h from this layer and add to the sum}
726     \textcolor{keywordflow}{do} j=js,je ; \textcolor{keywordflow}{do} i=is-1,ie
727       s2 = ( e\_x(i,j)**2  + 0.25*( &
728             (e\_y(i,j)**2+e\_y(i+1,j-1)**2)+(e\_y(i+1,j)**2+e\_y(i,j-1)**2) ) )
729       hdn = 2.*h(i,j,k)*h(i,j,k-1) / (h(i,j,k) + h(i,j,k-1) + h\_neglect)
730       hup = 2.*h(i+1,j,k)*h(i+1,j,k-1) / (h(i+1,j,k) + h(i+1,j,k-1) + h\_neglect)
731       h\_geom = sqrt(hdn*hup)
732       n2 = gv%g\_prime(k)*us%L\_to\_Z**2 / (gv%H\_to\_Z * max(hdn,hup,one\_meter))
733       \textcolor{keywordflow}{if} (min(h(i,j,k-1), h(i+1,j,k-1), h(i,j,k), h(i+1,j,k)) < h\_cutoff) &
734         s2 = 0.0
735       s2n2\_u\_local(i,j,k) = (h\_geom * gv%H\_to\_Z) * s2 * n2
736 \textcolor{keywordflow}{    enddo} ;\textcolor{keywordflow}{ enddo}
737     \textcolor{keywordflow}{do} j=js-1,je ; \textcolor{keywordflow}{do} i=is,ie
738       s2 = ( e\_y(i,j)**2  + 0.25*( &
739             (e\_x(i,j)**2+e\_x(i-1,j+1)**2)+(e\_x(i,j+1)**2+e\_x(i-1,j)**2) ) )
740       hdn = 2.*h(i,j,k)*h(i,j,k-1) / (h(i,j,k) + h(i,j,k-1) + h\_neglect)
741       hup = 2.*h(i,j+1,k)*h(i,j+1,k-1) / (h(i,j+1,k) + h(i,j+1,k-1) + h\_neglect)
742       h\_geom = sqrt(hdn*hup)
743       n2 = gv%g\_prime(k)*us%L\_to\_Z**2 / (gv%H\_to\_Z * max(hdn,hup,one\_meter))
744       \textcolor{keywordflow}{if} (min(h(i,j,k-1), h(i,j+1,k-1), h(i,j,k), h(i,j+1,k)) < h\_cutoff) &
745         s2 = 0.0
746       s2n2\_v\_local(i,j,k) = (h\_geom * gv%H\_to\_Z) * s2 * n2
747 \textcolor{keywordflow}{    enddo} ;\textcolor{keywordflow}{ enddo}
748 
749 \textcolor{keywordflow}{  enddo} \textcolor{comment}{! k}
750   \textcolor{comment}{!$OMP parallel do default(shared)}
751   \textcolor{keywordflow}{do} j=js,je
752     \textcolor{keywordflow}{do} i=is-1,ie ; cs%SN\_u(i,j) = 0.0 ;\textcolor{keywordflow}{ enddo}
753     \textcolor{keywordflow}{do} k=nz,cs%VarMix\_Ktop,-1 ; \textcolor{keywordflow}{do} i=is-1,ie
754       cs%SN\_u(i,j) = cs%SN\_u(i,j) + s2n2\_u\_local(i,j,k)
755 \textcolor{keywordflow}{    enddo} ;\textcolor{keywordflow}{ enddo}
756     \textcolor{comment}{! SN above contains S^2*N^2*H, convert to vertical average of S*N}
757     \textcolor{keywordflow}{do} i=is-1,ie
758       \textcolor{comment}{!SN\_u(I,j) = sqrt( SN\_u(I,j) / ( max(G%bathyT(I,j), G%bathyT(I+1,j)) + GV%Angstrom\_Z ) ))}
759       \textcolor{comment}{!The code below behaves better than the line above. Not sure why? AJA}
760       \textcolor{keywordflow}{if} ( min(g%bathyT(i,j), g%bathyT(i+1,j)) > h\_cutoff*gv%H\_to\_Z ) \textcolor{keywordflow}{then}
761         cs%SN\_u(i,j) = g%mask2dCu(i,j) * sqrt( cs%SN\_u(i,j) / &
762                                                (max(g%bathyT(i,j), g%bathyT(i+1,j))) )
763       \textcolor{keywordflow}{else}
764         cs%SN\_u(i,j) = 0.0
765 \textcolor{keywordflow}{      endif}
766       \textcolor{keywordflow}{if} (local\_open\_u\_bc) \textcolor{keywordflow}{then}
767         l\_seg = obc%segnum\_u(i,j)
768 
769         \textcolor{keywordflow}{if} (l\_seg /= obc\_none) \textcolor{keywordflow}{then}
770           \textcolor{keywordflow}{if} (obc%segment(l\_seg)%open) \textcolor{keywordflow}{then}
771             cs%SN\_u(i,j) = 0.
772 \textcolor{keywordflow}{          endif}
773 \textcolor{keywordflow}{        endif}
774 \textcolor{keywordflow}{      endif}
775 \textcolor{keywordflow}{    enddo}
776 \textcolor{keywordflow}{  enddo}
777   \textcolor{comment}{!$OMP parallel do default(shared)}
778   \textcolor{keywordflow}{do} j=js-1,je
779     \textcolor{keywordflow}{do} i=is,ie ; cs%SN\_v(i,j) = 0.0 ;\textcolor{keywordflow}{ enddo}
780     \textcolor{keywordflow}{do} k=nz,cs%VarMix\_Ktop,-1 ; \textcolor{keywordflow}{do} i=is,ie
781       cs%SN\_v(i,j) = cs%SN\_v(i,j) + s2n2\_v\_local(i,j,k)
782 \textcolor{keywordflow}{    enddo} ;\textcolor{keywordflow}{ enddo}
783     \textcolor{keywordflow}{do} i=is,ie
784       \textcolor{comment}{!SN\_v(i,J) = sqrt( SN\_v(i,J) / ( max(G%bathyT(i,J), G%bathyT(i,J+1)) + GV%Angstrom\_Z ) ))}
785       \textcolor{comment}{!The code below behaves better than the line above. Not sure why? AJA}
786       \textcolor{keywordflow}{if} ( min(g%bathyT(i,j), g%bathyT(i+1,j)) > h\_cutoff*gv%H\_to\_Z ) \textcolor{keywordflow}{then}
787         cs%SN\_v(i,j) = g%mask2dCv(i,j) * sqrt( cs%SN\_v(i,j) / &
788                                                (max(g%bathyT(i,j), g%bathyT(i,j+1))) )
789       \textcolor{keywordflow}{else}
790         cs%SN\_v(i,j) = 0.0
791 \textcolor{keywordflow}{      endif}
792       \textcolor{keywordflow}{if} (local\_open\_v\_bc) \textcolor{keywordflow}{then}
793         l\_seg = obc%segnum\_v(i,j)
794 
795         \textcolor{keywordflow}{if} (l\_seg /= obc\_none) \textcolor{keywordflow}{then}
796           \textcolor{keywordflow}{if} (obc%segment(obc%segnum\_v(i,j))%open) \textcolor{keywordflow}{then}
797             cs%SN\_v(i,j) = 0.
798 \textcolor{keywordflow}{          endif}
799 \textcolor{keywordflow}{        endif}
800 \textcolor{keywordflow}{      endif}
801 \textcolor{keywordflow}{    enddo}
802 \textcolor{keywordflow}{  enddo}
803 
\end{DoxyCode}
\mbox{\Hypertarget{namespacemom__lateral__mixing__coeffs_ac7307f59d005a7b45a642f94eee7c8be}\label{namespacemom__lateral__mixing__coeffs_ac7307f59d005a7b45a642f94eee7c8be}} 
\index{mom\+\_\+lateral\+\_\+mixing\+\_\+coeffs@{mom\+\_\+lateral\+\_\+mixing\+\_\+coeffs}!calc\+\_\+visbeck\+\_\+coeffs@{calc\+\_\+visbeck\+\_\+coeffs}}
\index{calc\+\_\+visbeck\+\_\+coeffs@{calc\+\_\+visbeck\+\_\+coeffs}!mom\+\_\+lateral\+\_\+mixing\+\_\+coeffs@{mom\+\_\+lateral\+\_\+mixing\+\_\+coeffs}}
\subsubsection{\texorpdfstring{calc\+\_\+visbeck\+\_\+coeffs()}{calc\_visbeck\_coeffs()}}
{\footnotesize\ttfamily subroutine mom\+\_\+lateral\+\_\+mixing\+\_\+coeffs\+::calc\+\_\+visbeck\+\_\+coeffs (\begin{DoxyParamCaption}\item[{real, dimension( g \%isd\+: g \%ied, g \%jsd\+: g \%jed, g \%ke), intent(in)}]{h,  }\item[{real, dimension( g \%isdb\+: g \%iedb, g \%jsd\+: g \%jed, g \%ke+1), intent(in)}]{slope\+\_\+x,  }\item[{real, dimension( g \%isd\+: g \%ied, g \%jsdb\+: g \%jedb, g \%ke+1), intent(in)}]{slope\+\_\+y,  }\item[{real, dimension( g \%isdb\+: g \%iedb, g \%jsd\+: g \%jed, g \%ke+1), intent(in)}]{N2\+\_\+u,  }\item[{real, dimension( g \%isd\+: g \%ied, g \%jsdb\+: g \%jedb, g \%ke+1), intent(in)}]{N2\+\_\+v,  }\item[{type(ocean\+\_\+grid\+\_\+type), intent(inout)}]{G,  }\item[{type(verticalgrid\+\_\+type), intent(in)}]{GV,  }\item[{type(unit\+\_\+scale\+\_\+type), intent(in)}]{US,  }\item[{type(\mbox{\hyperlink{structmom__lateral__mixing__coeffs_1_1varmix__cs}{varmix\+\_\+cs}}), pointer}]{CS,  }\item[{type(ocean\+\_\+obc\+\_\+type), optional, pointer}]{O\+BC }\end{DoxyParamCaption})\hspace{0.3cm}{\ttfamily [private]}}



Calculates factors used when setting diffusivity coefficients similar to Visbeck et al. 


\begin{DoxyParams}[1]{Parameters}
\mbox{\tt in,out}  & {\em g} & Ocean grid structure\\
\hline
\mbox{\tt in}  & {\em gv} & Vertical grid structure\\
\hline
\mbox{\tt in}  & {\em h} & Layer thickness \mbox{[}H $\sim$$>$ m or kg m-\/2\mbox{]}\\
\hline
\mbox{\tt in}  & {\em slope\+\_\+x} & Zonal isoneutral slope\\
\hline
\mbox{\tt in}  & {\em n2\+\_\+u} & Buoyancy (Brunt-\/\+Vaisala) frequency at u-\/points \mbox{[}T-\/2 $\sim$$>$ s-\/2\mbox{]}\\
\hline
\mbox{\tt in}  & {\em slope\+\_\+y} & Meridional isoneutral slope\\
\hline
\mbox{\tt in}  & {\em n2\+\_\+v} & Buoyancy (Brunt-\/\+Vaisala) frequency at v-\/points \mbox{[}T-\/2 $\sim$$>$ s-\/2\mbox{]}\\
\hline
\mbox{\tt in}  & {\em us} & A dimensional unit scaling type\\
\hline
 & {\em cs} & Variable mixing coefficients\\
\hline
 & {\em obc} & Open boundaries control structure. \\
\hline
\end{DoxyParams}


Definition at line 482 of file M\+O\+M\+\_\+lateral\+\_\+mixing\+\_\+coeffs.\+F90.


\begin{DoxyCode}
482   \textcolor{keywordtype}{type}(ocean\_grid\_type),                       \textcolor{keywordtype}{intent(inout)} :: G\textcolor{comment}{  !< Ocean grid structure}
483   \textcolor{keywordtype}{type}(verticalGrid\_type),                     \textcolor{keywordtype}{intent(in)}    :: GV\textcolor{comment}{ !< Vertical grid structure}
484   \textcolor{keywordtype}{real}, \textcolor{keywordtype}{dimension(SZI\_(G),SZJ\_(G),SZK\_(G))},    \textcolor{keywordtype}{intent(in)}    :: h\textcolor{comment}{  !< Layer thickness [H ~> m or kg m-2]}
485   \textcolor{keywordtype}{real}, \textcolor{keywordtype}{dimension(SZIB\_(G),SZJ\_(G),SZK\_(G)+1)}, \textcolor{keywordtype}{intent(in)}    :: slope\_x\textcolor{comment}{ !< Zonal isoneutral slope}
486   \textcolor{keywordtype}{real}, \textcolor{keywordtype}{dimension(SZIB\_(G),SZJ\_(G),SZK\_(G)+1)}, \textcolor{keywordtype}{intent(in)}    :: N2\_u\textcolor{comment}{    !< Buoyancy (Brunt-Vaisala)
       frequency}
487 \textcolor{comment}{                                                                        !! at u-points [T-2 ~> s-2]}
488   \textcolor{keywordtype}{real}, \textcolor{keywordtype}{dimension(SZI\_(G),SZJB\_(G),SZK\_(G)+1)}, \textcolor{keywordtype}{intent(in)}    :: slope\_y\textcolor{comment}{ !< Meridional isoneutral slope}
489   \textcolor{keywordtype}{real}, \textcolor{keywordtype}{dimension(SZI\_(G),SZJB\_(G),SZK\_(G)+1)}, \textcolor{keywordtype}{intent(in)}    :: N2\_v\textcolor{comment}{    !< Buoyancy (Brunt-Vaisala)
       frequency}
490 \textcolor{comment}{                                                                        !! at v-points [T-2 ~> s-2]}
491   \textcolor{keywordtype}{type}(unit\_scale\_type),                       \textcolor{keywordtype}{intent(in)}    :: US\textcolor{comment}{ !< A dimensional unit scaling type}
492   \textcolor{keywordtype}{type}(VarMix\_CS),                             \textcolor{keywordtype}{pointer}       :: CS\textcolor{comment}{ !< Variable mixing coefficients}
493   \textcolor{keywordtype}{type}(ocean\_OBC\_type),              \textcolor{keywordtype}{optional}, \textcolor{keywordtype}{pointer}       :: OBC\textcolor{comment}{ !< Open boundaries control structure.}
494 
495   \textcolor{comment}{! Local variables}
496   \textcolor{keywordtype}{real} :: S2            \textcolor{comment}{! Interface slope squared [nondim]}
497   \textcolor{keywordtype}{real} :: N2            \textcolor{comment}{! Positive buoyancy frequency or zero [T-2 ~> s-2]}
498   \textcolor{keywordtype}{real} :: Hup, Hdn      \textcolor{comment}{! Thickness from above, below [H ~> m or kg m-2]}
499   \textcolor{keywordtype}{real} :: H\_geom        \textcolor{comment}{! The geometric mean of Hup*Hdn [H ~> m or kg m-2].}
500   \textcolor{keywordtype}{integer} :: is, ie, js, je, nz
501   \textcolor{keywordtype}{integer} :: i, j, k, kb\_max
502   \textcolor{keywordtype}{integer} :: l\_seg
503   \textcolor{keywordtype}{real} :: S2max, wNE, wSE, wSW, wNW
504   \textcolor{keywordtype}{real} :: H\_u(SZIB\_(G)), H\_v(SZI\_(G))
505   \textcolor{keywordtype}{real} :: S2\_u(SZIB\_(G), SZJ\_(G))
506   \textcolor{keywordtype}{real} :: S2\_v(SZI\_(G), SZJB\_(G))
507   \textcolor{keywordtype}{logical} :: local\_open\_u\_BC, local\_open\_v\_BC
508 
509   \textcolor{keywordflow}{if} (.not. \textcolor{keyword}{associated}(cs)) \textcolor{keyword}{call }mom\_error(fatal, \textcolor{stringliteral}{"calc\_slope\_function:"}// &
510          \textcolor{stringliteral}{"Module must be initialized before it is used."})
511   \textcolor{keywordflow}{if} (.not. cs%calculate\_Eady\_growth\_rate) \textcolor{keywordflow}{return}
512   \textcolor{keywordflow}{if} (.not. \textcolor{keyword}{associated}(cs%SN\_u)) \textcolor{keyword}{call }mom\_error(fatal, \textcolor{stringliteral}{"calc\_slope\_function:"}// &
513          \textcolor{stringliteral}{"%SN\_u is not associated with use\_variable\_mixing."})
514   \textcolor{keywordflow}{if} (.not. \textcolor{keyword}{associated}(cs%SN\_v)) \textcolor{keyword}{call }mom\_error(fatal, \textcolor{stringliteral}{"calc\_slope\_function:"}// &
515          \textcolor{stringliteral}{"%SN\_v is not associated with use\_variable\_mixing."})
516 
517   is = g%isc ; ie = g%iec ; js = g%jsc ; je = g%jec ; nz = g%ke
518 
519   local\_open\_u\_bc = .false.
520   local\_open\_v\_bc = .false.
521   \textcolor{keywordflow}{if} (\textcolor{keyword}{present}(obc)) \textcolor{keywordflow}{then} ; \textcolor{keywordflow}{if} (\textcolor{keyword}{associated}(obc)) \textcolor{keywordflow}{then}
522     local\_open\_u\_bc = obc%open\_u\_BCs\_exist\_globally
523     local\_open\_v\_bc = obc%open\_v\_BCs\_exist\_globally
524 \textcolor{keywordflow}{  endif} ;\textcolor{keywordflow}{ endif}
525 
526   s2max = cs%Visbeck\_S\_max**2
527 
528   \textcolor{comment}{!$OMP parallel do default(shared)}
529   \textcolor{keywordflow}{do} j=js-1,je+1 ; \textcolor{keywordflow}{do} i=is-1,ie+1
530     cs%SN\_u(i,j) = 0.0
531     cs%SN\_v(i,j) = 0.0
532 \textcolor{keywordflow}{  enddo} ;\textcolor{keywordflow}{ enddo}
533 
534   \textcolor{comment}{! To set the length scale based on the deformation radius, use wave\_speed to}
535   \textcolor{comment}{! calculate the first-mode gravity wave speed and then blend the equatorial}
536   \textcolor{comment}{! and midlatitude deformation radii, using calc\_resoln\_function as a template.}
537 
538   \textcolor{comment}{!$OMP parallel do default(shared) private(S2,H\_u,Hdn,Hup,H\_geom,N2,wNE,wSE,wSW,wNW)}
539   \textcolor{keywordflow}{do} j = js,je
540     \textcolor{keywordflow}{do} i=is-1,ie
541       cs%SN\_u(i,j) = 0. ; h\_u(i) = 0. ; s2\_u(i,j) = 0.
542 \textcolor{keywordflow}{    enddo}
543     \textcolor{keywordflow}{do} k=2,nz ; \textcolor{keywordflow}{do} i=is-1,ie
544       hdn = sqrt( h(i,j,k) * h(i+1,j,k) )
545       hup = sqrt( h(i,j,k-1) * h(i+1,j,k-1) )
546       h\_geom = sqrt( hdn * hup )
547      \textcolor{comment}{!H\_geom = H\_geom * sqrt(N2) ! WKB-ish}
548      \textcolor{comment}{!H\_geom = H\_geom * N2       ! WKB-ish}
549       wse = g%mask2dCv(i+1,j-1) * ( (h(i+1,j,k)*h(i+1,j-1,k)) * (h(i+1,j,k-1)*h(i+1,j-1,k-1)) )
550       wnw = g%mask2dCv(i  ,j  ) * ( (h(i  ,j,k)*h(i  ,j+1,k)) * (h(i  ,j,k-1)*h(i  ,j+1,k-1)) )
551       wne = g%mask2dCv(i+1,j  ) * ( (h(i+1,j,k)*h(i+1,j+1,k)) * (h(i+1,j,k-1)*h(i+1,j+1,k-1)) )
552       wsw = g%mask2dCv(i  ,j-1) * ( (h(i  ,j,k)*h(i  ,j-1,k)) * (h(i  ,j,k-1)*h(i  ,j-1,k-1)) )
553       s2 =  slope\_x(i,j,k)**2 + &
554               ((wnw*slope\_y(i,j,k)**2 + wse*slope\_y(i+1,j-1,k)**2) + &
555                (wne*slope\_y(i+1,j,k)**2 + wsw*slope\_y(i,j-1,k)**2) ) / &
556               ( ((wse+wnw) + (wne+wsw)) + gv%H\_subroundoff**4 )
557       \textcolor{keywordflow}{if} (s2max>0.) s2 = s2 * s2max / (s2 + s2max) \textcolor{comment}{! Limit S2}
558 
559       n2 = max(0., n2\_u(i,j,k))
560       cs%SN\_u(i,j) = cs%SN\_u(i,j) + sqrt( s2*n2 )*h\_geom
561       s2\_u(i,j) = s2\_u(i,j) + s2*h\_geom
562       h\_u(i) = h\_u(i) + h\_geom
563 \textcolor{keywordflow}{    enddo} ;\textcolor{keywordflow}{ enddo}
564     \textcolor{keywordflow}{do} i=is-1,ie
565       \textcolor{keywordflow}{if} (h\_u(i)>0.) \textcolor{keywordflow}{then}
566         cs%SN\_u(i,j) = g%mask2dCu(i,j) * cs%SN\_u(i,j) / h\_u(i)
567         s2\_u(i,j) =  g%mask2dCu(i,j) * s2\_u(i,j) / h\_u(i)
568       \textcolor{keywordflow}{else}
569         cs%SN\_u(i,j) = 0.
570 \textcolor{keywordflow}{      endif}
571       \textcolor{keywordflow}{if} (local\_open\_u\_bc) \textcolor{keywordflow}{then}
572         l\_seg = obc%segnum\_u(i,j)
573 
574         \textcolor{keywordflow}{if} (l\_seg /= obc\_none) \textcolor{keywordflow}{then}
575           \textcolor{keywordflow}{if} (obc%segment(l\_seg)%open) \textcolor{keywordflow}{then}
576             cs%SN\_u(i,j) = 0.
577 \textcolor{keywordflow}{          endif}
578 \textcolor{keywordflow}{        endif}
579 \textcolor{keywordflow}{      endif}
580 \textcolor{keywordflow}{    enddo}
581 \textcolor{keywordflow}{  enddo}
582 
583   \textcolor{comment}{!$OMP parallel do default(shared) private(S2,H\_v,Hdn,Hup,H\_geom,N2,wNE,wSE,wSW,wNW)}
584   \textcolor{keywordflow}{do} j = js-1,je
585     \textcolor{keywordflow}{do} i=is,ie
586       cs%SN\_v(i,j) = 0. ; h\_v(i) = 0. ; s2\_v(i,j) = 0.
587 \textcolor{keywordflow}{    enddo}
588     \textcolor{keywordflow}{do} k=2,nz ; \textcolor{keywordflow}{do} i=is,ie
589       hdn = sqrt( h(i,j,k) * h(i,j+1,k) )
590       hup = sqrt( h(i,j,k-1) * h(i,j+1,k-1) )
591       h\_geom = sqrt( hdn * hup )
592      \textcolor{comment}{!H\_geom = H\_geom * sqrt(N2) ! WKB-ish}
593      \textcolor{comment}{!H\_geom = H\_geom * N2       ! WKB-ish}
594       wse = g%mask2dCu(i,j)     * ( (h(i,j  ,k)*h(i+1,j  ,k)) * (h(i,j  ,k-1)*h(i+1,j  ,k-1)) )
595       wnw = g%mask2dCu(i-1,j+1) * ( (h(i,j+1,k)*h(i-1,j+1,k)) * (h(i,j+1,k-1)*h(i-1,j+1,k-1)) )
596       wne = g%mask2dCu(i,j+1)   * ( (h(i,j+1,k)*h(i+1,j+1,k)) * (h(i,j+1,k-1)*h(i+1,j+1,k-1)) )
597       wsw = g%mask2dCu(i-1,j)   * ( (h(i,j  ,k)*h(i-1,j  ,k)) * (h(i,j  ,k-1)*h(i-1,j  ,k-1)) )
598       s2 = slope\_y(i,j,k)**2 + &
599              ((wse*slope\_x(i,j,k)**2 + wnw*slope\_x(i-1,j+1,k)**2) + &
600               (wne*slope\_x(i,j+1,k)**2 + wsw*slope\_x(i-1,j,k)**2) ) / &
601              ( ((wse+wnw) + (wne+wsw)) + gv%H\_subroundoff**4 )
602       \textcolor{keywordflow}{if} (s2max>0.) s2 = s2 * s2max / (s2 + s2max) \textcolor{comment}{! Limit S2}
603 
604       n2 = max(0., n2\_v(i,j,k))
605       cs%SN\_v(i,j) = cs%SN\_v(i,j) + sqrt( s2*n2 )*h\_geom
606       s2\_v(i,j) = s2\_v(i,j) + s2*h\_geom
607       h\_v(i) = h\_v(i) + h\_geom
608 \textcolor{keywordflow}{    enddo} ;\textcolor{keywordflow}{ enddo}
609     \textcolor{keywordflow}{do} i=is,ie
610       \textcolor{keywordflow}{if} (h\_v(i)>0.) \textcolor{keywordflow}{then}
611         cs%SN\_v(i,j) = g%mask2dCv(i,j) * cs%SN\_v(i,j) / h\_v(i)
612         s2\_v(i,j) = g%mask2dCv(i,j) * s2\_v(i,j) / h\_v(i)
613       \textcolor{keywordflow}{else}
614         cs%SN\_v(i,j) = 0.
615 \textcolor{keywordflow}{      endif}
616       \textcolor{keywordflow}{if} (local\_open\_v\_bc) \textcolor{keywordflow}{then}
617         l\_seg = obc%segnum\_v(i,j)
618 
619         \textcolor{keywordflow}{if} (l\_seg /= obc\_none) \textcolor{keywordflow}{then}
620           \textcolor{keywordflow}{if} (obc%segment(obc%segnum\_v(i,j))%open) \textcolor{keywordflow}{then}
621             cs%SN\_v(i,j) = 0.
622 \textcolor{keywordflow}{          endif}
623 \textcolor{keywordflow}{        endif}
624 \textcolor{keywordflow}{      endif}
625 \textcolor{keywordflow}{    enddo}
626 \textcolor{keywordflow}{  enddo}
627 
628 \textcolor{comment}{! Offer diagnostic fields for averaging.}
629   \textcolor{keywordflow}{if} (query\_averaging\_enabled(cs%diag)) \textcolor{keywordflow}{then}
630     \textcolor{keywordflow}{if} (cs%id\_S2\_u > 0) \textcolor{keyword}{call }post\_data(cs%id\_S2\_u, s2\_u, cs%diag)
631     \textcolor{keywordflow}{if} (cs%id\_S2\_v > 0) \textcolor{keyword}{call }post\_data(cs%id\_S2\_v, s2\_v, cs%diag)
632 \textcolor{keywordflow}{  endif}
633 
634   \textcolor{keywordflow}{if} (cs%debug) \textcolor{keywordflow}{then}
635     \textcolor{keyword}{call }uvchksum(\textcolor{stringliteral}{"calc\_Visbeck\_coeffs slope\_[xy]"}, slope\_x, slope\_y, g%HI, haloshift=1)
636     \textcolor{keyword}{call }uvchksum(\textcolor{stringliteral}{"calc\_Visbeck\_coeffs N2\_u, N2\_v"}, n2\_u, n2\_v, g%HI, &
637                   scale=us%s\_to\_T**2, scalar\_pair=.true.)
638     \textcolor{keyword}{call }uvchksum(\textcolor{stringliteral}{"calc\_Visbeck\_coeffs SN\_[uv]"}, cs%SN\_u, cs%SN\_v, g%HI, &
639                   scale=us%s\_to\_T, scalar\_pair=.true.)
640 \textcolor{keywordflow}{  endif}
641 
\end{DoxyCode}
\mbox{\Hypertarget{namespacemom__lateral__mixing__coeffs_a1070a864ca570c00f483a8617afca133}\label{namespacemom__lateral__mixing__coeffs_a1070a864ca570c00f483a8617afca133}} 
\index{mom\+\_\+lateral\+\_\+mixing\+\_\+coeffs@{mom\+\_\+lateral\+\_\+mixing\+\_\+coeffs}!varmix\+\_\+init@{varmix\+\_\+init}}
\index{varmix\+\_\+init@{varmix\+\_\+init}!mom\+\_\+lateral\+\_\+mixing\+\_\+coeffs@{mom\+\_\+lateral\+\_\+mixing\+\_\+coeffs}}
\subsubsection{\texorpdfstring{varmix\+\_\+init()}{varmix\_init()}}
{\footnotesize\ttfamily subroutine, public mom\+\_\+lateral\+\_\+mixing\+\_\+coeffs\+::varmix\+\_\+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__lateral__mixing__coeffs_1_1varmix__cs}{varmix\+\_\+cs}}), pointer}]{CS }\end{DoxyParamCaption})}



Initializes the variables mixing coefficients container. 


\begin{DoxyParams}[1]{Parameters}
\mbox{\tt in}  & {\em time} & Current model time\\
\hline
\mbox{\tt in}  & {\em g} & Ocean grid structure\\
\hline
\mbox{\tt in}  & {\em gv} & The ocean\textquotesingle{}s vertical grid structure\\
\hline
\mbox{\tt in}  & {\em us} & A dimensional unit scaling type\\
\hline
\mbox{\tt in}  & {\em param\+\_\+file} & Parameter file handles\\
\hline
\mbox{\tt in,out}  & {\em diag} & Diagnostics control structure\\
\hline
 & {\em cs} & Variable mixing coefficients \\
\hline
\end{DoxyParams}


Definition at line 937 of file M\+O\+M\+\_\+lateral\+\_\+mixing\+\_\+coeffs.\+F90.


\begin{DoxyCode}
937   \textcolor{keywordtype}{type}(time\_type),            \textcolor{keywordtype}{intent(in)} :: Time\textcolor{comment}{ !< Current model time}
938   \textcolor{keywordtype}{type}(ocean\_grid\_type),      \textcolor{keywordtype}{intent(in)} :: G\textcolor{comment}{    !< Ocean grid structure}
939   \textcolor{keywordtype}{type}(verticalGrid\_type),    \textcolor{keywordtype}{intent(in)} :: GV\textcolor{comment}{   !< The ocean's vertical grid structure}
940   \textcolor{keywordtype}{type}(unit\_scale\_type),      \textcolor{keywordtype}{intent(in)} :: US\textcolor{comment}{   !< A dimensional unit scaling type}
941   \textcolor{keywordtype}{type}(param\_file\_type),      \textcolor{keywordtype}{intent(in)} :: param\_file\textcolor{comment}{ !< Parameter file handles}
942   \textcolor{keywordtype}{type}(diag\_ctrl), \textcolor{keywordtype}{target}, \textcolor{keywordtype}{intent(inout)} :: diag\textcolor{comment}{ !< Diagnostics control structure}
943   \textcolor{keywordtype}{type}(VarMix\_CS),               \textcolor{keywordtype}{pointer} :: CS\textcolor{comment}{   !< Variable mixing coefficients}
944   \textcolor{comment}{! Local variables}
945   \textcolor{keywordtype}{real} :: KhTr\_Slope\_Cff, KhTh\_Slope\_Cff, oneOrTwo
946   \textcolor{keywordtype}{real} :: N2\_filter\_depth  \textcolor{comment}{! A depth below which stratification is treated as monotonic when}
947                            \textcolor{comment}{! calculating the first-mode wave speed [Z ~> m]}
948   \textcolor{keywordtype}{real} :: KhTr\_passivity\_coeff
949   \textcolor{keywordtype}{real} :: absurdly\_small\_freq  \textcolor{comment}{! A miniscule frequency that is used to avoid division by 0 [T-1 ~> s-1]. 
       The}
950              \textcolor{comment}{! default value is roughly (pi / (the age of the universe)).}
951   \textcolor{keywordtype}{logical} :: Gill\_equatorial\_Ld, use\_FGNV\_streamfn, use\_MEKE, in\_use
952   \textcolor{keywordtype}{logical} :: default\_2018\_answers, remap\_answers\_2018
953   \textcolor{keywordtype}{real} :: MLE\_front\_length
954   \textcolor{keywordtype}{real} :: Leith\_Lap\_const      \textcolor{comment}{! The non-dimensional coefficient in the Leith viscosity}
955   \textcolor{keywordtype}{real} :: grid\_sp\_u2, grid\_sp\_v2 \textcolor{comment}{! Intermediate quantities for Leith metrics [L2 ~> m2]}
956   \textcolor{keywordtype}{real} :: grid\_sp\_u3, grid\_sp\_v3 \textcolor{comment}{! Intermediate quantities for Leith metrics [L3 ~> m3]}
957   \textcolor{keywordtype}{real} :: wave\_speed\_min      \textcolor{comment}{! A floor in the first mode speed below which 0 is returned [L T-1 ~> m s-1]}
958   \textcolor{keywordtype}{real} :: wave\_speed\_tol      \textcolor{comment}{! The fractional tolerance for finding the wave speeds [nondim]}
959   \textcolor{keywordtype}{logical} :: better\_speed\_est \textcolor{comment}{! If true, use a more robust estimate of the first}
960                               \textcolor{comment}{! mode wave speed as the starting point for iterations.}
961 \textcolor{comment}{! This include declares and sets the variable "version".}
962 \textcolor{preprocessor}{# include "version\_variable.h"}
963 \textcolor{preprocessor}{}  \textcolor{keywordtype}{character(len=40)}  :: mdl = \textcolor{stringliteral}{"MOM\_lateral\_mixing\_coeffs"} \textcolor{comment}{! This module's name.}
964   \textcolor{keywordtype}{integer} :: is, ie, js, je, Isq, Ieq, Jsq, Jeq, i, j
965   \textcolor{keywordtype}{integer} :: isd, ied, jsd, jed, IsdB, IedB, JsdB, JedB
966   is = g%isc ; ie = g%iec ; js = g%jsc ; je = g%jec
967   isq = g%IscB ; ieq = g%IecB ; jsq = g%JscB ; jeq = g%JecB
968   isd = g%isd ; ied = g%ied ; jsd = g%jsd ; jed = g%jed
969   isdb = g%IsdB ; iedb = g%IedB ; jsdb = g%JsdB ; jedb = g%JedB
970 
971   \textcolor{keywordflow}{if} (\textcolor{keyword}{associated}(cs)) \textcolor{keywordflow}{then}
972     \textcolor{keyword}{call }mom\_error(warning, \textcolor{stringliteral}{"VarMix\_init called with an associated "}// &
973                              \textcolor{stringliteral}{"control structure."})
974     \textcolor{keywordflow}{return}
975 \textcolor{keywordflow}{  endif}
976 
977   \textcolor{keyword}{allocate}(cs)
978   in\_use = .false. \textcolor{comment}{! Set to true to avoid deallocating}
979   cs%diag => diag \textcolor{comment}{! Diagnostics pointer}
980   cs%calculate\_cg1 = .false.
981   cs%calculate\_Rd\_dx = .false.
982   cs%calculate\_res\_fns = .false.
983   cs%calculate\_Eady\_growth\_rate = .false.
984   cs%calculate\_depth\_fns = .false.
985   \textcolor{comment}{! Read all relevant parameters and write them to the model log.}
986   \textcolor{keyword}{call }log\_version(param\_file, mdl, version, \textcolor{stringliteral}{""})
987   \textcolor{keyword}{call }get\_param(param\_file, mdl, \textcolor{stringliteral}{"USE\_VARIABLE\_MIXING"}, cs%use\_variable\_mixing,&
988                  \textcolor{stringliteral}{"If true, the variable mixing code will be called.  This "}//&
989                  \textcolor{stringliteral}{"allows diagnostics to be created even if the scheme is "}//&
990                  \textcolor{stringliteral}{"not used.  If KHTR\_SLOPE\_CFF>0 or  KhTh\_Slope\_Cff>0, "}//&
991                  \textcolor{stringliteral}{"this is set to true regardless of what is in the "}//&
992                  \textcolor{stringliteral}{"parameter file."}, default=.false.)
993   \textcolor{keyword}{call }get\_param(param\_file, mdl, \textcolor{stringliteral}{"USE\_VISBECK"}, cs%use\_Visbeck,&
994                  \textcolor{stringliteral}{"If true, use the Visbeck et al. (1997) formulation for \(\backslash\)n"}//&
995                  \textcolor{stringliteral}{"thickness diffusivity."}, default=.false.)
996   \textcolor{keyword}{call }get\_param(param\_file, mdl, \textcolor{stringliteral}{"RESOLN\_SCALED\_KH"}, cs%Resoln\_scaled\_Kh, &
997                  \textcolor{stringliteral}{"If true, the Laplacian lateral viscosity is scaled away "}//&
998                  \textcolor{stringliteral}{"when the first baroclinic deformation radius is well "}//&
999                  \textcolor{stringliteral}{"resolved."}, default=.false.)
1000   \textcolor{keyword}{call }get\_param(param\_file, mdl, \textcolor{stringliteral}{"DEPTH\_SCALED\_KHTH"}, cs%Depth\_scaled\_KhTh, &
1001                  \textcolor{stringliteral}{"If true, KHTH is scaled away when the depth is shallower"}//&
1002                  \textcolor{stringliteral}{"than a reference depth: KHTH = MIN(1,H/H0)**N * KHTH, "}//&
1003                  \textcolor{stringliteral}{"where H0 is a reference depth, controlled via DEPTH\_SCALED\_KHTH\_H0, "}//&
1004                  \textcolor{stringliteral}{"and the exponent (N) is controlled via DEPTH\_SCALED\_KHTH\_EXP."},&
1005                  default=.false.)
1006   \textcolor{keyword}{call }get\_param(param\_file, mdl, \textcolor{stringliteral}{"RESOLN\_SCALED\_KHTH"}, cs%Resoln\_scaled\_KhTh, &
1007                  \textcolor{stringliteral}{"If true, the interface depth diffusivity is scaled away "}//&
1008                  \textcolor{stringliteral}{"when the first baroclinic deformation radius is well "}//&
1009                  \textcolor{stringliteral}{"resolved."}, default=.false.)
1010   \textcolor{keyword}{call }get\_param(param\_file, mdl, \textcolor{stringliteral}{"RESOLN\_SCALED\_KHTR"}, cs%Resoln\_scaled\_KhTr, &
1011                  \textcolor{stringliteral}{"If true, the epipycnal tracer diffusivity is scaled "}//&
1012                  \textcolor{stringliteral}{"away when the first baroclinic deformation radius is "}//&
1013                  \textcolor{stringliteral}{"well resolved."}, default=.false.)
1014   \textcolor{keyword}{call }get\_param(param\_file, mdl, \textcolor{stringliteral}{"RESOLN\_USE\_EBT"}, cs%Resoln\_use\_ebt, &
1015                  \textcolor{stringliteral}{"If true, uses the equivalent barotropic wave speed instead "}//&
1016                  \textcolor{stringliteral}{"of first baroclinic wave for calculating the resolution fn."},&
1017                  default=.false.)
1018   \textcolor{keyword}{call }get\_param(param\_file, mdl, \textcolor{stringliteral}{"KHTH\_USE\_EBT\_STRUCT"}, cs%khth\_use\_ebt\_struct, &
1019                  \textcolor{stringliteral}{"If true, uses the equivalent barotropic structure "}//&
1020                  \textcolor{stringliteral}{"as the vertical structure of thickness diffusivity."},&
1021                  default=.false.)
1022   \textcolor{keyword}{call }get\_param(param\_file, mdl, \textcolor{stringliteral}{"KHTH\_SLOPE\_CFF"}, khth\_slope\_cff, &
1023                  \textcolor{stringliteral}{"The nondimensional coefficient in the Visbeck formula "}//&
1024                  \textcolor{stringliteral}{"for the interface depth diffusivity"}, units=\textcolor{stringliteral}{"nondim"}, &
1025                  default=0.0)
1026   \textcolor{keyword}{call }get\_param(param\_file, mdl, \textcolor{stringliteral}{"KHTR\_SLOPE\_CFF"}, khtr\_slope\_cff, &
1027                  \textcolor{stringliteral}{"The nondimensional coefficient in the Visbeck formula "}//&
1028                  \textcolor{stringliteral}{"for the epipycnal tracer diffusivity"}, units=\textcolor{stringliteral}{"nondim"}, &
1029                  default=0.0)
1030   \textcolor{keyword}{call }get\_param(param\_file, mdl, \textcolor{stringliteral}{"USE\_STORED\_SLOPES"}, cs%use\_stored\_slopes,&
1031                  \textcolor{stringliteral}{"If true, the isopycnal slopes are calculated once and "}//&
1032                  \textcolor{stringliteral}{"stored for re-use. This uses more memory but avoids calling "}//&
1033                  \textcolor{stringliteral}{"the equation of state more times than should be necessary."}, &
1034                  default=.false.)
1035   \textcolor{keyword}{call }get\_param(param\_file, mdl, \textcolor{stringliteral}{"VERY\_SMALL\_FREQUENCY"}, absurdly\_small\_freq, &
1036                  \textcolor{stringliteral}{"A miniscule frequency that is used to avoid division by 0.  The default "}//&
1037                  \textcolor{stringliteral}{"value is roughly (pi / (the age of the universe))."}, &
1038                  default=1.0e-17, units=\textcolor{stringliteral}{"s-1"}, scale=us%T\_to\_s)
1039   \textcolor{keyword}{call }get\_param(param\_file, mdl, \textcolor{stringliteral}{"KHTH\_USE\_FGNV\_STREAMFUNCTION"}, use\_fgnv\_streamfn, &
1040                  default=.false., do\_not\_log=.true.)
1041   cs%calculate\_cg1 = cs%calculate\_cg1 .or. use\_fgnv\_streamfn
1042   \textcolor{keyword}{call }get\_param(param\_file, mdl, \textcolor{stringliteral}{"USE\_MEKE"}, use\_meke, &
1043                  default=.false., do\_not\_log=.true.)
1044   cs%calculate\_Rd\_dx = cs%calculate\_Rd\_dx .or. use\_meke
1045   cs%calculate\_Eady\_growth\_rate = cs%calculate\_Eady\_growth\_rate .or. use\_meke
1046   \textcolor{keyword}{call }get\_param(param\_file, mdl, \textcolor{stringliteral}{"KHTR\_PASSIVITY\_COEFF"}, khtr\_passivity\_coeff, &
1047                  default=0., do\_not\_log=.true.)
1048   cs%calculate\_Rd\_dx = cs%calculate\_Rd\_dx .or. (khtr\_passivity\_coeff>0.)
1049   \textcolor{keyword}{call }get\_param(param\_file, mdl, \textcolor{stringliteral}{"MLE\_FRONT\_LENGTH"}, mle\_front\_length, &
1050                  default=0., do\_not\_log=.true.)
1051   cs%calculate\_Rd\_dx = cs%calculate\_Rd\_dx .or. (mle\_front\_length>0.)
1052 
1053   \textcolor{keyword}{call }get\_param(param\_file, mdl, \textcolor{stringliteral}{"DEBUG"}, cs%debug, default=.false., do\_not\_log=.true.)
1054 
1055 
1056   \textcolor{keywordflow}{if} (cs%Resoln\_use\_ebt .or. cs%khth\_use\_ebt\_struct) \textcolor{keywordflow}{then}
1057     in\_use = .true.
1058     \textcolor{keyword}{call }get\_param(param\_file, mdl, \textcolor{stringliteral}{"RESOLN\_N2\_FILTER\_DEPTH"}, n2\_filter\_depth, &
1059                  \textcolor{stringliteral}{"The depth below which N2 is monotonized to avoid stratification "}//&
1060                  \textcolor{stringliteral}{"artifacts from altering the equivalent barotropic mode structure."},&
1061                  units=\textcolor{stringliteral}{"m"}, default=2000., scale=us%m\_to\_Z)
1062     \textcolor{keyword}{allocate}(cs%ebt\_struct(isd:ied,jsd:jed,g%ke)) ; cs%ebt\_struct(:,:,:) = 0.0
1063 \textcolor{keywordflow}{  endif}
1064 
1065   \textcolor{keywordflow}{if} (khtr\_slope\_cff>0. .or. khth\_slope\_cff>0.) \textcolor{keywordflow}{then}
1066     cs%calculate\_Eady\_growth\_rate = .true.
1067     \textcolor{keyword}{call }get\_param(param\_file, mdl, \textcolor{stringliteral}{"VISBECK\_MAX\_SLOPE"}, cs%Visbeck\_S\_max, &
1068           \textcolor{stringliteral}{"If non-zero, is an upper bound on slopes used in the "}//&
1069           \textcolor{stringliteral}{"Visbeck formula for diffusivity. This does not affect the "}//&
1070           \textcolor{stringliteral}{"isopycnal slope calculation used within thickness diffusion."},  &
1071           units=\textcolor{stringliteral}{"nondim"}, default=0.0)
1072 \textcolor{keywordflow}{  endif}
1073 
1074   \textcolor{keywordflow}{if} (cs%use\_stored\_slopes) \textcolor{keywordflow}{then}
1075     in\_use = .true.
1076     \textcolor{keyword}{allocate}(cs%slope\_x(isdb:iedb,jsd:jed,g%ke+1)) ; cs%slope\_x(:,:,:) = 0.0
1077     \textcolor{keyword}{allocate}(cs%slope\_y(isd:ied,jsdb:jedb,g%ke+1)) ; cs%slope\_y(:,:,:) = 0.0
1078     \textcolor{keyword}{call }get\_param(param\_file, mdl, \textcolor{stringliteral}{"KD\_SMOOTH"}, cs%kappa\_smooth, &
1079                  \textcolor{stringliteral}{"A diapycnal diffusivity that is used to interpolate "}//&
1080                  \textcolor{stringliteral}{"more sensible values of T & S into thin layers."}, &
1081                  units=\textcolor{stringliteral}{"m2 s-1"}, default=1.0e-6, scale=us%m\_to\_Z**2*us%T\_to\_s)
1082 \textcolor{keywordflow}{  endif}
1083 
1084   \textcolor{keywordflow}{if} (cs%calculate\_Eady\_growth\_rate) \textcolor{keywordflow}{then}
1085     in\_use = .true.
1086     \textcolor{keyword}{allocate}(cs%SN\_u(isdb:iedb,jsd:jed)) ; cs%SN\_u(:,:) = 0.0
1087     \textcolor{keyword}{allocate}(cs%SN\_v(isd:ied,jsdb:jedb)) ; cs%SN\_v(:,:) = 0.0
1088     cs%id\_SN\_u = register\_diag\_field(\textcolor{stringliteral}{'ocean\_model'}, \textcolor{stringliteral}{'SN\_u'}, diag%axesCu1, time, &
1089        \textcolor{stringliteral}{'Inverse eddy time-scale, S*N, at u-points'}, \textcolor{stringliteral}{'s-1'}, conversion=us%s\_to\_T)
1090     cs%id\_SN\_v = register\_diag\_field(\textcolor{stringliteral}{'ocean\_model'}, \textcolor{stringliteral}{'SN\_v'}, diag%axesCv1, time, &
1091        \textcolor{stringliteral}{'Inverse eddy time-scale, S*N, at v-points'}, \textcolor{stringliteral}{'s-1'}, conversion=us%s\_to\_T)
1092     \textcolor{keyword}{call }get\_param(param\_file, mdl, \textcolor{stringliteral}{"VARMIX\_KTOP"}, cs%VarMix\_Ktop, &
1093                  \textcolor{stringliteral}{"The layer number at which to start vertical integration "}//&
1094                  \textcolor{stringliteral}{"of S*N for purposes of finding the Eady growth rate."}, &
1095                  units=\textcolor{stringliteral}{"nondim"}, default=2)
1096 \textcolor{keywordflow}{  endif}
1097 
1098   \textcolor{keywordflow}{if} (khtr\_slope\_cff>0. .or. khth\_slope\_cff>0.) \textcolor{keywordflow}{then}
1099     in\_use = .true.
1100     \textcolor{keyword}{call }get\_param(param\_file, mdl, \textcolor{stringliteral}{"VISBECK\_L\_SCALE"}, cs%Visbeck\_L\_scale, &
1101                  \textcolor{stringliteral}{"The fixed length scale in the Visbeck formula."}, units=\textcolor{stringliteral}{"m"}, &
1102                  default=0.0)
1103     \textcolor{keyword}{allocate}(cs%L2u(isdb:iedb,jsd:jed)) ; cs%L2u(:,:) = 0.0
1104     \textcolor{keyword}{allocate}(cs%L2v(isd:ied,jsdb:jedb)) ; cs%L2v(:,:) = 0.0
1105     \textcolor{keywordflow}{if} (cs%Visbeck\_L\_scale<0) \textcolor{keywordflow}{then}
1106       \textcolor{keywordflow}{do} j=js,je ; \textcolor{keywordflow}{do} i=is-1,ieq
1107         cs%L2u(i,j) = cs%Visbeck\_L\_scale**2 * g%areaCu(i,j)
1108 \textcolor{keyword}{      end}do; enddo
1109       \textcolor{keywordflow}{do} j=js-1,jeq ; \textcolor{keywordflow}{do} i=is,ie
1110         cs%L2v(i,j) = cs%Visbeck\_L\_scale**2 * g%areaCv(i,j)
1111 \textcolor{keyword}{      end}do; enddo
1112     \textcolor{keywordflow}{else}
1113       cs%L2u(:,:) = us%m\_to\_L**2*cs%Visbeck\_L\_scale**2
1114       cs%L2v(:,:) = us%m\_to\_L**2*cs%Visbeck\_L\_scale**2
1115 \textcolor{keywordflow}{    endif}
1116 
1117     cs%id\_L2u = register\_diag\_field(\textcolor{stringliteral}{'ocean\_model'}, \textcolor{stringliteral}{'L2u'}, diag%axesCu1, time, &
1118        \textcolor{stringliteral}{'Length scale squared for mixing coefficient, at u-points'}, &
1119        \textcolor{stringliteral}{'m2'}, conversion=us%L\_to\_m**2)
1120     cs%id\_L2v = register\_diag\_field(\textcolor{stringliteral}{'ocean\_model'}, \textcolor{stringliteral}{'L2v'}, diag%axesCv1, time, &
1121        \textcolor{stringliteral}{'Length scale squared for mixing coefficient, at v-points'}, &
1122        \textcolor{stringliteral}{'m2'}, conversion=us%L\_to\_m**2)
1123 \textcolor{keywordflow}{  endif}
1124 
1125   \textcolor{keywordflow}{if} (cs%calculate\_Eady\_growth\_rate .and. cs%use\_stored\_slopes) \textcolor{keywordflow}{then}
1126     cs%id\_N2\_u = register\_diag\_field(\textcolor{stringliteral}{'ocean\_model'}, \textcolor{stringliteral}{'N2\_u'}, diag%axesCui, time, &
1127          \textcolor{stringliteral}{'Square of Brunt-Vaisala frequency, N^2, at u-points, as used in Visbeck et al.'}, &
1128          \textcolor{stringliteral}{'s-2'}, conversion=us%s\_to\_T**2)
1129     cs%id\_N2\_v = register\_diag\_field(\textcolor{stringliteral}{'ocean\_model'}, \textcolor{stringliteral}{'N2\_v'}, diag%axesCvi, time, &
1130          \textcolor{stringliteral}{'Square of Brunt-Vaisala frequency, N^2, at v-points, as used in Visbeck et al.'}, &
1131          \textcolor{stringliteral}{'s-2'}, conversion=us%s\_to\_T**2)
1132 \textcolor{keywordflow}{  endif}
1133   \textcolor{keywordflow}{if} (cs%use\_stored\_slopes) \textcolor{keywordflow}{then}
1134     cs%id\_S2\_u = register\_diag\_field(\textcolor{stringliteral}{'ocean\_model'}, \textcolor{stringliteral}{'S2\_u'}, diag%axesCu1, time, &
1135          \textcolor{stringliteral}{'Depth average square of slope magnitude, S^2, at u-points, as used in Visbeck et al.'}, \textcolor{stringliteral}{'nondim'})
1136     cs%id\_S2\_v = register\_diag\_field(\textcolor{stringliteral}{'ocean\_model'}, \textcolor{stringliteral}{'S2\_v'}, diag%axesCv1, time, &
1137          \textcolor{stringliteral}{'Depth average square of slope magnitude, S^2, at v-points, as used in Visbeck et al.'}, \textcolor{stringliteral}{'nondim'})
1138 \textcolor{keywordflow}{  endif}
1139 
1140   oneortwo = 1.0
1141   \textcolor{keywordflow}{if} (cs%Resoln\_scaled\_Kh .or. cs%Resoln\_scaled\_KhTh .or. cs%Resoln\_scaled\_KhTr) \textcolor{keywordflow}{then}
1142     cs%calculate\_Rd\_dx = .true.
1143     cs%calculate\_res\_fns = .true.
1144     \textcolor{keyword}{allocate}(cs%Res\_fn\_h(isd:ied,jsd:jed))       ; cs%Res\_fn\_h(:,:) = 0.0
1145     \textcolor{keyword}{allocate}(cs%Res\_fn\_q(isdb:iedb,jsdb:jedb))   ; cs%Res\_fn\_q(:,:) = 0.0
1146     \textcolor{keyword}{allocate}(cs%Res\_fn\_u(isdb:iedb,jsd:jed))     ; cs%Res\_fn\_u(:,:) = 0.0
1147     \textcolor{keyword}{allocate}(cs%Res\_fn\_v(isd:ied,jsdb:jedb))     ; cs%Res\_fn\_v(:,:) = 0.0
1148     \textcolor{keyword}{allocate}(cs%beta\_dx2\_q(isdb:iedb,jsdb:jedb)) ; cs%beta\_dx2\_q(:,:) = 0.0
1149     \textcolor{keyword}{allocate}(cs%beta\_dx2\_u(isdb:iedb,jsd:jed))   ; cs%beta\_dx2\_u(:,:) = 0.0
1150     \textcolor{keyword}{allocate}(cs%beta\_dx2\_v(isd:ied,jsdb:jedb))   ; cs%beta\_dx2\_v(:,:) = 0.0
1151     \textcolor{keyword}{allocate}(cs%f2\_dx2\_q(isdb:iedb,jsdb:jedb))   ; cs%f2\_dx2\_q(:,:) = 0.0
1152     \textcolor{keyword}{allocate}(cs%f2\_dx2\_u(isdb:iedb,jsd:jed))     ; cs%f2\_dx2\_u(:,:) = 0.0
1153     \textcolor{keyword}{allocate}(cs%f2\_dx2\_v(isd:ied,jsdb:jedb))     ; cs%f2\_dx2\_v(:,:) = 0.0
1154 
1155     cs%id\_Res\_fn = register\_diag\_field(\textcolor{stringliteral}{'ocean\_model'}, \textcolor{stringliteral}{'Res\_fn'}, diag%axesT1, time, &
1156        \textcolor{stringliteral}{'Resolution function for scaling diffusivities'}, \textcolor{stringliteral}{'nondim'})
1157 
1158     \textcolor{keyword}{call }get\_param(param\_file, mdl, \textcolor{stringliteral}{"KH\_RES\_SCALE\_COEF"}, cs%Res\_coef\_khth, &
1159                  \textcolor{stringliteral}{"A coefficient that determines how KhTh is scaled away if "}//&
1160                  \textcolor{stringliteral}{"RESOLN\_SCALED\_... is true, as "}//&
1161                  \textcolor{stringliteral}{"F = 1 / (1 + (KH\_RES\_SCALE\_COEF*Rd/dx)^KH\_RES\_FN\_POWER)."}, &
1162                  units=\textcolor{stringliteral}{"nondim"}, default=1.0)
1163     \textcolor{keyword}{call }get\_param(param\_file, mdl, \textcolor{stringliteral}{"KH\_RES\_FN\_POWER"}, cs%Res\_fn\_power\_khth, &
1164                  \textcolor{stringliteral}{"The power of dx/Ld in the Kh resolution function.  Any "}//&
1165                  \textcolor{stringliteral}{"positive integer may be used, although even integers "}//&
1166                  \textcolor{stringliteral}{"are more efficient to calculate.  Setting this greater "}//&
1167                  \textcolor{stringliteral}{"than 100 results in a step-function being used."}, &
1168                  units=\textcolor{stringliteral}{"nondim"}, default=2)
1169     \textcolor{keyword}{call }get\_param(param\_file, mdl, \textcolor{stringliteral}{"VISC\_RES\_SCALE\_COEF"}, cs%Res\_coef\_visc, &
1170                  \textcolor{stringliteral}{"A coefficient that determines how Kh is scaled away if "}//&
1171                  \textcolor{stringliteral}{"RESOLN\_SCALED\_... is true, as "}//&
1172                  \textcolor{stringliteral}{"F = 1 / (1 + (KH\_RES\_SCALE\_COEF*Rd/dx)^KH\_RES\_FN\_POWER). "}//&
1173                  \textcolor{stringliteral}{"This function affects lateral viscosity, Kh, and not KhTh."}, &
1174                  units=\textcolor{stringliteral}{"nondim"}, default=cs%Res\_coef\_khth)
1175     \textcolor{keyword}{call }get\_param(param\_file, mdl, \textcolor{stringliteral}{"VISC\_RES\_FN\_POWER"}, cs%Res\_fn\_power\_visc, &
1176                  \textcolor{stringliteral}{"The power of dx/Ld in the Kh resolution function.  Any "}//&
1177                  \textcolor{stringliteral}{"positive integer may be used, although even integers "}//&
1178                  \textcolor{stringliteral}{"are more efficient to calculate.  Setting this greater "}//&
1179                  \textcolor{stringliteral}{"than 100 results in a step-function being used. "}//&
1180                  \textcolor{stringliteral}{"This function affects lateral viscosity, Kh, and not KhTh."}, &
1181                  units=\textcolor{stringliteral}{"nondim"}, default=cs%Res\_fn\_power\_khth)
1182     \textcolor{keyword}{call }get\_param(param\_file, mdl, \textcolor{stringliteral}{"INTERPOLATE\_RES\_FN"}, cs%interpolate\_Res\_fn, &
1183                  \textcolor{stringliteral}{"If true, interpolate the resolution function to the "}//&
1184                  \textcolor{stringliteral}{"velocity points from the thickness points; otherwise "}//&
1185                  \textcolor{stringliteral}{"interpolate the wave speed and calculate the resolution "}//&
1186                  \textcolor{stringliteral}{"function independently at each point."}, default=.false.)
1187     \textcolor{keywordflow}{if} (cs%interpolate\_Res\_fn) \textcolor{keywordflow}{then}
1188       \textcolor{keywordflow}{if} (cs%Res\_coef\_visc /= cs%Res\_coef\_khth) \textcolor{keyword}{call }mom\_error(fatal, &
1189            \textcolor{stringliteral}{"MOM\_lateral\_mixing\_coeffs.F90, VarMix\_init:"}//&
1190            \textcolor{stringliteral}{"When INTERPOLATE\_RES\_FN=True, VISC\_RES\_FN\_POWER must equal KH\_RES\_SCALE\_COEF."})
1191       \textcolor{keywordflow}{if} (cs%Res\_fn\_power\_visc /= cs%Res\_fn\_power\_khth) \textcolor{keyword}{call }mom\_error(fatal, &
1192            \textcolor{stringliteral}{"MOM\_lateral\_mixing\_coeffs.F90, VarMix\_init:"}//&
1193            \textcolor{stringliteral}{"When INTERPOLATE\_RES\_FN=True, VISC\_RES\_FN\_POWER must equal KH\_RES\_FN\_POWER."})
1194 \textcolor{keywordflow}{    endif}
1195     \textcolor{keyword}{call }get\_param(param\_file, mdl, \textcolor{stringliteral}{"GILL\_EQUATORIAL\_LD"}, gill\_equatorial\_ld, &
1196                  \textcolor{stringliteral}{"If true, uses Gill's definition of the baroclinic "}//&
1197                  \textcolor{stringliteral}{"equatorial deformation radius, otherwise, if false, use "}//&
1198                  \textcolor{stringliteral}{"Pedlosky's definition. These definitions differ by a factor "}//&
1199                  \textcolor{stringliteral}{"of 2 in front of the beta term in the denominator. Gill's "}//&
1200                  \textcolor{stringliteral}{"is the more appropriate definition."}, default=.true.)
1201     \textcolor{keywordflow}{if} (gill\_equatorial\_ld) \textcolor{keywordflow}{then}
1202       oneortwo = 2.0
1203 \textcolor{keywordflow}{    endif}
1204 
1205     \textcolor{keywordflow}{do} j=js-1,jeq ; \textcolor{keywordflow}{do} i=is-1,ieq
1206       cs%f2\_dx2\_q(i,j) = (g%dxBu(i,j)**2 + g%dyBu(i,j)**2) * &
1207                          max(g%CoriolisBu(i,j)**2, absurdly\_small\_freq**2)
1208       cs%beta\_dx2\_q(i,j) = oneortwo * ((g%dxBu(i,j))**2 + (g%dyBu(i,j))**2) * (sqrt(0.5 * &
1209           ( (((g%CoriolisBu(i,j)-g%CoriolisBu(i-1,j)) * g%IdxCv(i,j))**2 + &
1210              ((g%CoriolisBu(i+1,j)-g%CoriolisBu(i,j)) * g%IdxCv(i+1,j))**2) + &
1211             (((g%CoriolisBu(i,j)-g%CoriolisBu(i,j-1)) * g%IdyCu(i,j))**2 + &
1212              ((g%CoriolisBu(i,j+1)-g%CoriolisBu(i,j)) * g%IdyCu(i,j+1))**2) ) ))
1213 \textcolor{keywordflow}{    enddo} ;\textcolor{keywordflow}{ enddo}
1214 
1215     \textcolor{keywordflow}{do} j=js,je ; \textcolor{keywordflow}{do} i=is-1,ieq
1216       cs%f2\_dx2\_u(i,j) = (g%dxCu(i,j)**2 + g%dyCu(i,j)**2) * &
1217           max(0.5* (g%CoriolisBu(i,j)**2+g%CoriolisBu(i,j-1)**2), absurdly\_small\_freq**2)
1218       cs%beta\_dx2\_u(i,j) = oneortwo * ((g%dxCu(i,j))**2 + (g%dyCu(i,j))**2) * (sqrt( &
1219           0.25*( (((g%CoriolisBu(i,j-1)-g%CoriolisBu(i-1,j-1)) * g%IdxCv(i,j-1))**2 + &
1220                   ((g%CoriolisBu(i+1,j)-g%CoriolisBu(i,j)) * g%IdxCv(i+1,j))**2) + &
1221                  (((g%CoriolisBu(i+1,j-1)-g%CoriolisBu(i,j-1)) * g%IdxCv(i+1,j-1))**2 + &
1222                   ((g%CoriolisBu(i,j)-g%CoriolisBu(i-1,j)) * g%IdxCv(i,j))**2) ) + &
1223                   ((g%CoriolisBu(i,j)-g%CoriolisBu(i,j-1)) * g%IdyCu(i,j))**2 ))
1224 \textcolor{keywordflow}{    enddo} ;\textcolor{keywordflow}{ enddo}
1225 
1226     \textcolor{keywordflow}{do} j=js-1,jeq ; \textcolor{keywordflow}{do} i=is,ie
1227       cs%f2\_dx2\_v(i,j) = ((g%dxCv(i,j))**2 + (g%dyCv(i,j))**2) * &
1228           max(0.5*(g%CoriolisBu(i,j)**2+g%CoriolisBu(i-1,j)**2), absurdly\_small\_freq**2)
1229       cs%beta\_dx2\_v(i,j) = oneortwo * ((g%dxCv(i,j))**2 + (g%dyCv(i,j))**2) * (sqrt( &
1230           ((g%CoriolisBu(i,j)-g%CoriolisBu(i-1,j)) * g%IdxCv(i,j))**2 + &
1231           0.25*( (((g%CoriolisBu(i,j)-g%CoriolisBu(i,j-1)) * g%IdyCu(i,j))**2 + &
1232                   ((g%CoriolisBu(i-1,j+1)-g%CoriolisBu(i-1,j)) * g%IdyCu(i-1,j+1))**2) + &
1233                  (((g%CoriolisBu(i,j+1)-g%CoriolisBu(i,j)) * g%IdyCu(i,j+1))**2 + &
1234                   ((g%CoriolisBu(i-1,j)-g%CoriolisBu(i-1,j-1)) * g%IdyCu(i-1,j))**2) ) ))
1235 \textcolor{keywordflow}{    enddo} ;\textcolor{keywordflow}{ enddo}
1236 
1237 \textcolor{keywordflow}{  endif}
1238 
1239   \textcolor{keywordflow}{if} (cs%Depth\_scaled\_KhTh) \textcolor{keywordflow}{then}
1240     cs%calculate\_depth\_fns = .true.
1241     \textcolor{keyword}{allocate}(cs%Depth\_fn\_u(isdb:iedb,jsd:jed))     ; cs%Depth\_fn\_u(:,:) = 0.0
1242     \textcolor{keyword}{allocate}(cs%Depth\_fn\_v(isd:ied,jsdb:jedb))     ; cs%Depth\_fn\_v(:,:) = 0.0
1243     \textcolor{keyword}{call }get\_param(param\_file, mdl, \textcolor{stringliteral}{"DEPTH\_SCALED\_KHTH\_H0"}, cs%depth\_scaled\_khth\_h0, &
1244     \textcolor{stringliteral}{"The depth above which KHTH is scaled away."},&
1245     units=\textcolor{stringliteral}{"m"}, default=1000.)
1246     \textcolor{keyword}{call }get\_param(param\_file, mdl, \textcolor{stringliteral}{"DEPTH\_SCALED\_KHTH\_EXP"}, cs%depth\_scaled\_khth\_exp, &
1247     \textcolor{stringliteral}{"The exponent used in the depth dependent scaling function for KHTH."},&
1248     units=\textcolor{stringliteral}{"nondim"}, default=3.0)
1249 \textcolor{keywordflow}{  endif}
1250 
1251   \textcolor{comment}{! Resolution %Rd\_dx\_h}
1252   cs%id\_Rd\_dx = register\_diag\_field(\textcolor{stringliteral}{'ocean\_model'}, \textcolor{stringliteral}{'Rd\_dx'}, diag%axesT1, time, &
1253        \textcolor{stringliteral}{'Ratio between deformation radius and grid spacing'}, \textcolor{stringliteral}{'m m-1'})
1254   cs%calculate\_Rd\_dx = cs%calculate\_Rd\_dx .or. (cs%id\_Rd\_dx>0)
1255 
1256   \textcolor{keywordflow}{if} (cs%calculate\_Rd\_dx) \textcolor{keywordflow}{then}
1257     cs%calculate\_cg1 = .true. \textcolor{comment}{! We will need %cg1}
1258     \textcolor{keyword}{allocate}(cs%Rd\_dx\_h(isd:ied,jsd:jed))   ; cs%Rd\_dx\_h(:,:) = 0.0
1259     \textcolor{keyword}{allocate}(cs%beta\_dx2\_h(isd:ied,jsd:jed)); cs%beta\_dx2\_h(:,:) = 0.0
1260     \textcolor{keyword}{allocate}(cs%f2\_dx2\_h(isd:ied,jsd:jed))  ; cs%f2\_dx2\_h(:,:) = 0.0
1261     \textcolor{keywordflow}{do} j=js-1,je+1 ; \textcolor{keywordflow}{do} i=is-1,ie+1
1262       cs%f2\_dx2\_h(i,j) = (g%dxT(i,j)**2 + g%dyT(i,j)**2) * &
1263           max(0.25 * ((g%CoriolisBu(i,j)**2 + g%CoriolisBu(i-1,j-1)**2) + &
1264                       (g%CoriolisBu(i-1,j)**2 + g%CoriolisBu(i,j-1)**2)), &
1265               absurdly\_small\_freq**2)
1266       cs%beta\_dx2\_h(i,j) = oneortwo * ((g%dxT(i,j))**2 + (g%dyT(i,j))**2) * (sqrt(0.5 * &
1267           ( (((g%CoriolisBu(i,j)-g%CoriolisBu(i-1,j)) * g%IdxCv(i,j))**2 + &
1268              ((g%CoriolisBu(i,j-1)-g%CoriolisBu(i-1,j-1)) * g%IdxCv(i,j-1))**2) + &
1269             (((g%CoriolisBu(i,j)-g%CoriolisBu(i,j-1)) * g%IdyCu(i,j))**2 + &
1270              ((g%CoriolisBu(i-1,j)-g%CoriolisBu(i-1,j-1)) * g%IdyCu(i-1,j))**2) ) ))
1271 \textcolor{keywordflow}{    enddo} ;\textcolor{keywordflow}{ enddo}
1272 \textcolor{keywordflow}{  endif}
1273 
1274   \textcolor{keywordflow}{if} (cs%calculate\_cg1) \textcolor{keywordflow}{then}
1275     in\_use = .true.
1276     \textcolor{keyword}{allocate}(cs%cg1(isd:ied,jsd:jed)) ; cs%cg1(:,:) = 0.0
1277     \textcolor{keyword}{call }get\_param(param\_file, mdl, \textcolor{stringliteral}{"DEFAULT\_2018\_ANSWERS"}, default\_2018\_answers, &
1278                  \textcolor{stringliteral}{"This sets the default value for the various \_2018\_ANSWERS parameters."}, &
1279                  default=.false.)
1280     \textcolor{keyword}{call }get\_param(param\_file, mdl, \textcolor{stringliteral}{"REMAPPING\_2018\_ANSWERS"}, remap\_answers\_2018, &
1281                  \textcolor{stringliteral}{"If true, use the order of arithmetic and expressions that recover the "}//&
1282                  \textcolor{stringliteral}{"answers from the end of 2018.  Otherwise, use updated and more robust "}//&
1283                  \textcolor{stringliteral}{"forms of the same expressions."}, default=default\_2018\_answers)
1284     \textcolor{keyword}{call }get\_param(param\_file, mdl, \textcolor{stringliteral}{"INTERNAL\_WAVE\_SPEED\_TOL"}, wave\_speed\_tol, &
1285                  \textcolor{stringliteral}{"The fractional tolerance for finding the wave speeds."}, &
1286                  units=\textcolor{stringliteral}{"nondim"}, default=0.001)
1287     \textcolor{comment}{!### Set defaults so that wave\_speed\_min*wave\_speed\_tol >= 1e-9 m s-1}
1288     \textcolor{keyword}{call }get\_param(param\_file, mdl, \textcolor{stringliteral}{"INTERNAL\_WAVE\_SPEED\_MIN"}, wave\_speed\_min, &
1289                  \textcolor{stringliteral}{"A floor in the first mode speed below which 0 used instead."}, &
1290                  units=\textcolor{stringliteral}{"m s-1"}, default=0.0, scale=us%m\_s\_to\_L\_T)
1291     \textcolor{keyword}{call }get\_param(param\_file, mdl, \textcolor{stringliteral}{"INTERNAL\_WAVE\_SPEED\_BETTER\_EST"}, better\_speed\_est, &
1292                  \textcolor{stringliteral}{"If true, use a more robust estimate of the first mode wave speed as the "}//&
1293                  \textcolor{stringliteral}{"starting point for iterations."}, default=.false.) \textcolor{comment}{!### Change the default.}
1294     \textcolor{keyword}{call }wave\_speed\_init(cs%wave\_speed\_CSp, use\_ebt\_mode=cs%Resoln\_use\_ebt, &
1295                          mono\_n2\_depth=n2\_filter\_depth, remap\_answers\_2018=remap\_answers\_2018, &
1296                          better\_speed\_est=better\_speed\_est, min\_speed=wave\_speed\_min, &
1297                          wave\_speed\_tol=wave\_speed\_tol)
1298 \textcolor{keywordflow}{  endif}
1299 
1300   \textcolor{comment}{! Leith parameters}
1301   \textcolor{keyword}{call }get\_param(param\_file, mdl, \textcolor{stringliteral}{"USE\_QG\_LEITH\_GM"}, cs%use\_QG\_Leith\_GM, &
1302                \textcolor{stringliteral}{"If true, use the QG Leith viscosity as the GM coefficient."}, &
1303                default=.false.)
1304 
1305   \textcolor{keywordflow}{if} (cs%Use\_QG\_Leith\_GM) \textcolor{keywordflow}{then}
1306     \textcolor{keyword}{call }get\_param(param\_file, mdl, \textcolor{stringliteral}{"LEITH\_LAP\_CONST"}, leith\_lap\_const, &
1307                \textcolor{stringliteral}{"The nondimensional Laplacian Leith constant, \(\backslash\)n"}//&
1308                \textcolor{stringliteral}{"often set to 1.0"}, units=\textcolor{stringliteral}{"nondim"}, default=0.0)
1309 
1310     \textcolor{keyword}{call }get\_param(param\_file, mdl, \textcolor{stringliteral}{"USE\_BETA\_IN\_LEITH"}, cs%use\_beta\_in\_QG\_Leith, &
1311                \textcolor{stringliteral}{"If true, include the beta term in the Leith nonlinear eddy viscosity."}, &
1312                default=.true.)
1313 
1314     alloc\_(cs%Laplac3\_const\_u(isdb:iedb,jsd:jed)) ; cs%Laplac3\_const\_u(:,:) = 0.0
1315     alloc\_(cs%Laplac3\_const\_v(isd:ied,jsdb:jedb)) ; cs%Laplac3\_const\_v(:,:) = 0.0
1316     alloc\_(cs%KH\_u\_QG(isdb:iedb,jsd:jed,g%ke)) ; cs%KH\_u\_QG(:,:,:) = 0.0
1317     alloc\_(cs%KH\_v\_QG(isd:ied,jsdb:jedb,g%ke)) ; cs%KH\_v\_QG(:,:,:) = 0.0
1318     \textcolor{comment}{! register diagnostics}
1319 
1320     cs%id\_KH\_u\_QG = register\_diag\_field(\textcolor{stringliteral}{'ocean\_model'}, \textcolor{stringliteral}{'KH\_u\_QG'}, diag%axesCuL, time, &
1321        \textcolor{stringliteral}{'Horizontal viscosity from Leith QG, at u-points'}, \textcolor{stringliteral}{'m2 s-1'}, conversion=us%L\_to\_m**2*us%s\_to\_T)
1322     cs%id\_KH\_v\_QG = register\_diag\_field(\textcolor{stringliteral}{'ocean\_model'}, \textcolor{stringliteral}{'KH\_v\_QG'}, diag%axesCvL, time, &
1323        \textcolor{stringliteral}{'Horizontal viscosity from Leith QG, at v-points'}, \textcolor{stringliteral}{'m2 s-1'}, conversion=us%L\_to\_m**2*us%s\_to\_T)
1324 
1325     \textcolor{keywordflow}{do} j=jsq,jeq+1 ; \textcolor{keywordflow}{do} i=is-1,ieq
1326       \textcolor{comment}{! Static factors in the Leith schemes}
1327       grid\_sp\_u2 = g%dyCu(i,j)*g%dxCu(i,j)
1328       grid\_sp\_u3 = grid\_sp\_u2*sqrt(grid\_sp\_u2)
1329       cs%Laplac3\_const\_u(i,j) = leith\_lap\_const * grid\_sp\_u3
1330 \textcolor{keywordflow}{    enddo} ;\textcolor{keywordflow}{ enddo}
1331     \textcolor{keywordflow}{do} j=js-1,jeq ; \textcolor{keywordflow}{do} i=isq,ieq+1
1332       \textcolor{comment}{! Static factors in the Leith schemes}
1333       grid\_sp\_v2 = g%dyCv(i,j)*g%dxCv(i,j)
1334       grid\_sp\_v3 = grid\_sp\_v2*sqrt(grid\_sp\_v2)
1335       cs%Laplac3\_const\_v(i,j) = leith\_lap\_const * grid\_sp\_v3
1336 \textcolor{keywordflow}{    enddo} ;\textcolor{keywordflow}{ enddo}
1337 
1338     \textcolor{keywordflow}{if} (.not. cs%use\_stored\_slopes) \textcolor{keyword}{call }mom\_error(fatal, &
1339            \textcolor{stringliteral}{"MOM\_lateral\_mixing\_coeffs.F90, VarMix\_init:"}//&
1340            \textcolor{stringliteral}{"USE\_STORED\_SLOPES must be True when using QG Leith."})
1341 \textcolor{keywordflow}{  endif}
1342 
1343   \textcolor{comment}{! If nothing is being stored in this class then deallocate}
1344   \textcolor{keywordflow}{if} (in\_use) \textcolor{keywordflow}{then}
1345     cs%use\_variable\_mixing = .true.
1346   \textcolor{keywordflow}{else}
1347     \textcolor{keyword}{deallocate}(cs)
1348     \textcolor{keywordflow}{return}
1349 \textcolor{keywordflow}{  endif}
1350 
\end{DoxyCode}
