\hypertarget{namespacemom__lateral__boundary__diffusion}{}\section{mom\+\_\+lateral\+\_\+boundary\+\_\+diffusion Module Reference}
\label{namespacemom__lateral__boundary__diffusion}\index{mom\_lateral\_boundary\_diffusion@{mom\_lateral\_boundary\_diffusion}}


\subsection{Detailed Description}
Calculates and applies diffusive fluxes as a parameterization of lateral mixing (non-\/neutral) by mesoscale eddies near the top and bottom (to be implemented) boundary layers of the ocean. 

\hypertarget{namespacemom__lateral__boundary__diffusion_section_LBD}{}\subsection{The Lateral Boundary Diffusion (\+L\+B\+D) framework}\label{namespacemom__lateral__boundary__diffusion_section_LBD}
The L\+BD framework accounts for the effects of diabatic mesoscale fluxes within surface and bottom boundary layers. Unlike the equivalent adiabatic fluxes, which is applied along neutral density surfaces, L\+BD is purely horizontal.

The bottom boundary layer fluxes remain to be implemented, although most of the steps needed to do so have already been added and tested.

Boundary lateral diffusion can be applied using one of the three methods\+:


\begin{DoxyItemize}
\item \mbox{\hyperlink{namespacemom__lateral__boundary__diffusion_section_method2}{Method \#1\+: Along layer}} (default);
\item \mbox{\hyperlink{namespacemom__lateral__boundary__diffusion_section_method1}{Method \#2\+: Bulk layer}};
\end{DoxyItemize}

A brief summary of these methods is provided below.\hypertarget{namespacemom__lateral__boundary__diffusion_section_method1}{}\subsubsection{Along layer approach (\+Method \#1)}\label{namespacemom__lateral__boundary__diffusion_section_method1}
This is the recommended and more straight forward method where diffusion is applied layer by layer using only information from neighboring cells.

Step \#1\+: compute vertical indices containing boundary layer (boundary\+\_\+k\+\_\+range). For the T\+OP boundary layer, these are\+:

k\+\_\+top, k\+\_\+bot, zeta\+\_\+top, zeta\+\_\+bot

Step \#2\+: calculate the diffusive flux at each layer\+:

\[ F_{k} = -KHTR \times h_{eff}(k) \times (\phi_R(k) - \phi_L(k)), \] where h\+\_\+eff is the \mbox{\hyperlink{namespacemom__lateral__boundary__diffusion_section_harmonic_mean}{harmonic mean}} of the layer thickness in the left and right columns. This method does not require a limiter since K\+H\+TR is already limted based on a diffusive C\+FL condition prior to the call of this module.

Step \#3\+: option to linearly decay the flux from k\+\_\+bot\+\_\+min to k\+\_\+bot\+\_\+max\+:

If L\+B\+D\+\_\+\+L\+I\+N\+E\+A\+R\+\_\+\+T\+R\+A\+N\+S\+I\+T\+I\+ON = True and k\+\_\+bot\+\_\+diff $>$ 1, the diffusive flux will decay linearly between the top interface of the layer containing the minimum boundary layer depth (k\+\_\+bot\+\_\+min) and the lower interface of the layer containing the maximum layer depth (k\+\_\+bot\+\_\+max).\hypertarget{namespacemom__lateral__boundary__diffusion_section_method2}{}\subsubsection{Bulk layer approach (\+Method \#2)}\label{namespacemom__lateral__boundary__diffusion_section_method2}
Apply the lateral boundary diffusive fluxes calculated from a \textquotesingle{}bulk model\textquotesingle{}.This is a lower order representation (Kraus-\/\+Turner like approach) which assumes that eddies are acting along well mixed layers (i.\+e., eddies do not know care about vertical tracer gradients within the boundary layer).

Step \#1\+: compute vertical indices containing boundary layer (boundary\+\_\+k\+\_\+range). For the T\+OP boundary layer, these are\+:

k\+\_\+top, k\+\_\+bot, zeta\+\_\+top, zeta\+\_\+bot

Step \#2\+: compute bulk averages (thickness weighted) tracer averages (phi\+\_\+L and phi\+\_\+R), then calculate the bulk diffusive flux (F\+\_\+\{bulk\})\+:

\[ F_{bulk} = -KHTR \times h_{eff} \times (\phi_R - \phi_L), \] where h\+\_\+eff is the \mbox{\hyperlink{namespacemom__lateral__boundary__diffusion_section_harmonic_mean}{harmonic mean}} of the boundary layer depth in the left and right columns ( \[ HBL_L \] and \[ HBL_R \], respectively).

Step \#3\+: decompose F\+\_\+bulk onto individual layers\+:

\[ F_{layer}(k) = F_{bulk} \times h_{frac}(k) , \]

where h\+\_\+\{frac\} is

\[ h_{frac}(k) = h_u(k) \times \frac{1}{\sum(h_u)}. \]

h\+\_\+u is the \mbox{\hyperlink{namespacemom__lateral__boundary__diffusion_section_harmonic_mean}{harmonic mean}} of thicknesses at each layer. Special care (layer reconstruction) must be taken at k\+\_\+min = min(k\+\_\+bot\+L, k\+\_\+bot\+\_\+\+R).

Step \#4\+: option to linearly decay the flux from k\+\_\+bot\+\_\+min to k\+\_\+bot\+\_\+max\+:

If L\+B\+D\+\_\+\+L\+I\+N\+E\+A\+R\+\_\+\+T\+R\+A\+N\+S\+I\+T\+I\+ON = True and k\+\_\+bot\+\_\+diff $>$ 1, the diffusive flux will decay linearly between the top interface of the layer containing the minimum boundary layer depth (k\+\_\+bot\+\_\+min) and the lower interface of the layer containing the maximum layer depth (k\+\_\+bot\+\_\+max).

Step \#5\+: limit the tracer flux so that 1) only down-\/gradient fluxes are applied, and 2) the flux cannot be larger than F\+\_\+max, which is defined using the tracer gradient\+:

\[ F_{max} = -0.2 \times [(V_R(k) \times \phi_R(k)) - (V_L(k) \times \phi_L(k))], \] where V is the cell volume. Why 0.\+2? t=0 t=inf 0 .2 0 1 0 .2.\+2.\+2 0 .2\hypertarget{namespacemom__lateral__boundary__diffusion_section_harmonic_mean}{}\subsubsection{Harmonic Mean}\label{namespacemom__lateral__boundary__diffusion_section_harmonic_mean}
The harmonic mean (HM) betwen h1 and h2 is defined as\+:

\[ HM = \frac{2 \times h1 \times h2}{h1 + h2} \] \subsection*{Data Types}
\begin{DoxyCompactItemize}
\item 
type \mbox{\hyperlink{structmom__lateral__boundary__diffusion_1_1lateral__boundary__diffusion__cs}{lateral\+\_\+boundary\+\_\+diffusion\+\_\+cs}}
\begin{DoxyCompactList}\small\item\em Sets parameters for lateral boundary mixing module. \end{DoxyCompactList}\end{DoxyCompactItemize}
\subsection*{Functions/\+Subroutines}
\begin{DoxyCompactItemize}
\item 
logical function, public \mbox{\hyperlink{namespacemom__lateral__boundary__diffusion_a4eb098abd02dbf022558e4bedfe9cdef}{lateral\+\_\+boundary\+\_\+diffusion\+\_\+init}} (Time, G, param\+\_\+file, diag, diabatic\+\_\+\+C\+Sp, CS)
\begin{DoxyCompactList}\small\item\em Initialization routine that reads runtime parameters and sets up pointers to other control structures that might be needed for lateral boundary diffusion. \end{DoxyCompactList}\item 
subroutine, public \mbox{\hyperlink{namespacemom__lateral__boundary__diffusion_afac71bffe2368a84b543f4d7f60703e0}{lateral\+\_\+boundary\+\_\+diffusion}} (G, GV, US, h, Coef\+\_\+x, Coef\+\_\+y, dt, Reg, CS)
\begin{DoxyCompactList}\small\item\em Driver routine for calculating lateral diffusive fluxes near the top and bottom boundaries. Two different methods are available\+: Method 1\+: lower order representation, calculate fluxes from bulk layer integrated quantities. Method 2\+: more straight forward, diffusion is applied layer by layer using only information from neighboring cells. \end{DoxyCompactList}\item 
real function \mbox{\hyperlink{namespacemom__lateral__boundary__diffusion_a764405ce85234799f6b81be25a8df1b7}{bulk\+\_\+average}} (boundary, nk, deg, h, h\+B\+LT, phi, ppoly0\+\_\+E, ppoly0\+\_\+coefs, method, k\+\_\+top, zeta\+\_\+top, k\+\_\+bot, zeta\+\_\+bot)
\item 
real function \mbox{\hyperlink{namespacemom__lateral__boundary__diffusion_a6c98f54ad462ab45918fdccc0b403948}{harmonic\+\_\+mean}} (h1, h2)
\begin{DoxyCompactList}\small\item\em Calculate the harmonic mean of two quantities See \mbox{\hyperlink{namespacemom__lateral__boundary__diffusion_section_harmonic_mean}{Harmonic Mean}}. \end{DoxyCompactList}\item 
subroutine, public \mbox{\hyperlink{namespacemom__lateral__boundary__diffusion_a9cd84e0a8f4ddaba3c8ece5f149c7a9f}{boundary\+\_\+k\+\_\+range}} (boundary, nk, h, hbl, k\+\_\+top, zeta\+\_\+top, k\+\_\+bot, zeta\+\_\+bot)
\begin{DoxyCompactList}\small\item\em Find the k-\/index range corresponding to the layers that are within the boundary-\/layer region. \end{DoxyCompactList}\item 
subroutine \mbox{\hyperlink{namespacemom__lateral__boundary__diffusion_ae8390123e94524264b952483ef9d79f8}{fluxes\+\_\+layer\+\_\+method}} (boundary, nk, deg, h\+\_\+L, h\+\_\+R, hbl\+\_\+L, hbl\+\_\+R, area\+\_\+L, area\+\_\+R, phi\+\_\+L, phi\+\_\+R, ppoly0\+\_\+coefs\+\_\+L, ppoly0\+\_\+coefs\+\_\+R, ppoly0\+\_\+\+E\+\_\+L, ppoly0\+\_\+\+E\+\_\+R, method, khtr\+\_\+u, F\+\_\+layer, linear\+\_\+decay)
\begin{DoxyCompactList}\small\item\em Calculate the lateral boundary diffusive fluxes using the layer by layer method. See \mbox{\hyperlink{namespacemom__lateral__boundary__diffusion_section_method1}{Along layer approach (Method \#1)}}. \end{DoxyCompactList}\item 
subroutine \mbox{\hyperlink{namespacemom__lateral__boundary__diffusion_a4c19afd5acc655501aebc2ec1a4fe396}{fluxes\+\_\+bulk\+\_\+method}} (boundary, nk, deg, h\+\_\+L, h\+\_\+R, hbl\+\_\+L, hbl\+\_\+R, area\+\_\+L, area\+\_\+R, phi\+\_\+L, phi\+\_\+R, ppoly0\+\_\+coefs\+\_\+L, ppoly0\+\_\+coefs\+\_\+R, ppoly0\+\_\+\+E\+\_\+L, ppoly0\+\_\+\+E\+\_\+R, method, khtr\+\_\+u, F\+\_\+bulk, F\+\_\+layer, F\+\_\+limit, linear\+\_\+decay)
\begin{DoxyCompactList}\small\item\em Apply the lateral boundary diffusive fluxes calculated from a \textquotesingle{}bulk model\textquotesingle{} See \mbox{\hyperlink{namespacemom__lateral__boundary__diffusion_section_method2}{Bulk layer approach (Method \#2)}}. \end{DoxyCompactList}\item 
logical function, public \mbox{\hyperlink{namespacemom__lateral__boundary__diffusion_a5590830aab282e34bcd5d4df052d4578}{near\+\_\+boundary\+\_\+unit\+\_\+tests}} (verbose)
\begin{DoxyCompactList}\small\item\em Unit tests for near-\/boundary horizontal mixing. \end{DoxyCompactList}\item 
logical function \mbox{\hyperlink{namespacemom__lateral__boundary__diffusion_a9c689c24bc59f46aa960b33119fe7e59}{test\+\_\+layer\+\_\+fluxes}} (verbose, nk, test\+\_\+name, F\+\_\+calc, F\+\_\+ans)
\begin{DoxyCompactList}\small\item\em Returns true if output of near-\/boundary unit tests does not match correct computed values and conditionally writes results to stream. \end{DoxyCompactList}\item 
logical function \mbox{\hyperlink{namespacemom__lateral__boundary__diffusion_ac7d1d46aeb36ab434b1a6533b47246ce}{test\+\_\+boundary\+\_\+k\+\_\+range}} (k\+\_\+top, zeta\+\_\+top, k\+\_\+bot, zeta\+\_\+bot, k\+\_\+top\+\_\+ans, zeta\+\_\+top\+\_\+ans, k\+\_\+bot\+\_\+ans, zeta\+\_\+bot\+\_\+ans, test\+\_\+name, verbose)
\begin{DoxyCompactList}\small\item\em Return true if output of unit tests for boundary\+\_\+k\+\_\+range does not match answers. \end{DoxyCompactList}\end{DoxyCompactItemize}
\subsection*{Variables}
\begin{DoxyCompactItemize}
\item 
\mbox{\Hypertarget{namespacemom__lateral__boundary__diffusion_ace1430e08cc68a474c478e53f955c715}\label{namespacemom__lateral__boundary__diffusion_ace1430e08cc68a474c478e53f955c715}} 
integer, parameter, public \mbox{\hyperlink{namespacemom__lateral__boundary__diffusion_ace1430e08cc68a474c478e53f955c715}{surface}} = -\/1
\begin{DoxyCompactList}\small\item\em Set a value that corresponds to the surface bopundary. \end{DoxyCompactList}\item 
\mbox{\Hypertarget{namespacemom__lateral__boundary__diffusion_a2d5308bf15dc0816cdbef33287152b4a}\label{namespacemom__lateral__boundary__diffusion_a2d5308bf15dc0816cdbef33287152b4a}} 
integer, parameter, public \mbox{\hyperlink{namespacemom__lateral__boundary__diffusion_a2d5308bf15dc0816cdbef33287152b4a}{bottom}} = 1
\begin{DoxyCompactList}\small\item\em Set a value that corresponds to the bottom boundary. \end{DoxyCompactList}\item 
\mbox{\Hypertarget{namespacemom__lateral__boundary__diffusion_a61c6b3e00d03dafc0c7625788a787b10}\label{namespacemom__lateral__boundary__diffusion_a61c6b3e00d03dafc0c7625788a787b10}} 
character(len=40) \mbox{\hyperlink{namespacemom__lateral__boundary__diffusion_a61c6b3e00d03dafc0c7625788a787b10}{mdl}} = \char`\"{}M\+O\+M\+\_\+lateral\+\_\+boundary\+\_\+diffusion\char`\"{}
\begin{DoxyCompactList}\small\item\em Name of this module. \end{DoxyCompactList}\end{DoxyCompactItemize}


\subsection{Function/\+Subroutine Documentation}
\mbox{\Hypertarget{namespacemom__lateral__boundary__diffusion_a9cd84e0a8f4ddaba3c8ece5f149c7a9f}\label{namespacemom__lateral__boundary__diffusion_a9cd84e0a8f4ddaba3c8ece5f149c7a9f}} 
\index{mom\_lateral\_boundary\_diffusion@{mom\_lateral\_boundary\_diffusion}!boundary\_k\_range@{boundary\_k\_range}}
\index{boundary\_k\_range@{boundary\_k\_range}!mom\_lateral\_boundary\_diffusion@{mom\_lateral\_boundary\_diffusion}}
\subsubsection{\texorpdfstring{boundary\_k\_range()}{boundary\_k\_range()}}
{\footnotesize\ttfamily subroutine, public mom\+\_\+lateral\+\_\+boundary\+\_\+diffusion\+::boundary\+\_\+k\+\_\+range (\begin{DoxyParamCaption}\item[{integer, intent(in)}]{boundary,  }\item[{integer, intent(in)}]{nk,  }\item[{real, dimension(nk), intent(in)}]{h,  }\item[{real, intent(in)}]{hbl,  }\item[{integer, intent(out)}]{k\+\_\+top,  }\item[{real, intent(out)}]{zeta\+\_\+top,  }\item[{integer, intent(out)}]{k\+\_\+bot,  }\item[{real, intent(out)}]{zeta\+\_\+bot }\end{DoxyParamCaption})}



Find the k-\/index range corresponding to the layers that are within the boundary-\/layer region. 


\begin{DoxyParams}[1]{Parameters}
\mbox{\texttt{ in}}  & {\em boundary} & S\+U\+R\+F\+A\+CE or B\+O\+T\+T\+OM \mbox{[}nondim\mbox{]} \\
\hline
\mbox{\texttt{ in}}  & {\em nk} & Number of layers \mbox{[}nondim\mbox{]} \\
\hline
\mbox{\texttt{ in}}  & {\em h} & Layer thicknesses of the column \mbox{[}H $\sim$$>$ m or kg m-\/2\mbox{]} \\
\hline
\mbox{\texttt{ in}}  & {\em hbl} & Thickness of the boundary layer \mbox{[}H $\sim$$>$ m or kg m-\/2\mbox{]} If surface, with respect to zbl\+\_\+ref = 0. If bottom, with respect to zbl\+\_\+ref = S\+U\+M(h) \\
\hline
\mbox{\texttt{ out}}  & {\em k\+\_\+top} & Index of the first layer within the boundary \\
\hline
\mbox{\texttt{ out}}  & {\em zeta\+\_\+top} & Distance from the top of a layer to the intersection of the top extent of the boundary layer (0 at top, 1 at bottom) \mbox{[}nondim\mbox{]} \\
\hline
\mbox{\texttt{ out}}  & {\em k\+\_\+bot} & Index of the last layer within the boundary \\
\hline
\mbox{\texttt{ out}}  & {\em zeta\+\_\+bot} & Distance of the lower layer to the boundary layer depth (0 at top, 1 at bottom) \mbox{[}nondim\mbox{]} \\
\hline
\end{DoxyParams}


Definition at line 375 of file M\+O\+M\+\_\+lateral\+\_\+boundary\+\_\+diffusion.\+F90.


\begin{DoxyCode}{0}
\DoxyCodeLine{375   \textcolor{keywordtype}{integer},             \textcolor{keywordtype}{intent(in   )} :: boundary\textcolor{comment}{ !< SURFACE or BOTTOM                       [nondim]}}
\DoxyCodeLine{376   \textcolor{keywordtype}{integer},             \textcolor{keywordtype}{intent(in   )} :: nk\textcolor{comment}{       !< Number of layers                        [nondim]}}
\DoxyCodeLine{377 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(nk)}, \textcolor{keywordtype}{intent(in   )} :: h\textcolor{comment}{        !< Layer thicknesses of the column         [H ~> m or kg m-2]}}
\DoxyCodeLine{378 \textcolor{keywordtype}{  real},                \textcolor{keywordtype}{intent(in   )} :: hbl\textcolor{comment}{      !< Thickness of the boundary layer         [H ~> m or kg m-2]}}
\DoxyCodeLine{379 \textcolor{comment}{                                                 !! If surface, with respect to zbl\_ref = 0.}}
\DoxyCodeLine{380 \textcolor{comment}{                                                 !! If bottom, with respect to zbl\_ref = SUM(h)}}
\DoxyCodeLine{381   \textcolor{keywordtype}{integer},             \textcolor{keywordtype}{intent(  out)} :: k\_top\textcolor{comment}{    !< Index of the first layer within the boundary}}
\DoxyCodeLine{382 \textcolor{keywordtype}{  real},                \textcolor{keywordtype}{intent(  out)} :: zeta\_top\textcolor{comment}{ !< Distance from the top of a layer to the intersection of the}}
\DoxyCodeLine{383 \textcolor{comment}{                                                 !! top extent of the boundary layer (0 at top, 1 at bottom)  [nondim]}}
\DoxyCodeLine{384   \textcolor{keywordtype}{integer},             \textcolor{keywordtype}{intent(  out)} :: k\_bot\textcolor{comment}{    !< Index of the last layer within the boundary}}
\DoxyCodeLine{385 \textcolor{keywordtype}{  real},                \textcolor{keywordtype}{intent(  out)} :: zeta\_bot\textcolor{comment}{ !< Distance of the lower layer to the boundary layer depth}}
\DoxyCodeLine{386 \textcolor{comment}{                                                 !! (0 at top, 1 at bottom)  [nondim]}}
\DoxyCodeLine{387   \textcolor{comment}{! Local variables}}
\DoxyCodeLine{388 \textcolor{keywordtype}{  real} :: htot \textcolor{comment}{! Summed thickness [H ~> m or kg m-2]}}
\DoxyCodeLine{389   \textcolor{keywordtype}{integer} :: k}
\DoxyCodeLine{390   \textcolor{comment}{! Surface boundary layer}}
\DoxyCodeLine{391   \textcolor{keywordflow}{if} ( boundary == surface ) \textcolor{keywordflow}{then}}
\DoxyCodeLine{392     k\_top = 1}
\DoxyCodeLine{393     zeta\_top = 0.}
\DoxyCodeLine{394     htot = 0.}
\DoxyCodeLine{395     k\_bot = 1}
\DoxyCodeLine{396     zeta\_bot = 0.}
\DoxyCodeLine{397     \textcolor{keywordflow}{if} (hbl == 0.) \textcolor{keywordflow}{return}}
\DoxyCodeLine{398     \textcolor{keywordflow}{if} (hbl >= sum(h(:))) \textcolor{keywordflow}{then}}
\DoxyCodeLine{399       k\_bot = nk}
\DoxyCodeLine{400       zeta\_bot = 1.}
\DoxyCodeLine{401       \textcolor{keywordflow}{return}}
\DoxyCodeLine{402 \textcolor{keywordflow}{    endif}}
\DoxyCodeLine{403     \textcolor{keywordflow}{do} k=1,nk}
\DoxyCodeLine{404       htot = htot + h(k)}
\DoxyCodeLine{405       \textcolor{keywordflow}{if} ( htot >= hbl) \textcolor{keywordflow}{then}}
\DoxyCodeLine{406         k\_bot = k}
\DoxyCodeLine{407         zeta\_bot = 1 - (htot - hbl)/h(k)}
\DoxyCodeLine{408         \textcolor{keywordflow}{return}}
\DoxyCodeLine{409 \textcolor{keywordflow}{      endif}}
\DoxyCodeLine{410 \textcolor{keywordflow}{    enddo}}
\DoxyCodeLine{411   \textcolor{comment}{! Bottom boundary layer}}
\DoxyCodeLine{412   \textcolor{keywordflow}{elseif} ( boundary == bottom ) \textcolor{keywordflow}{then}}
\DoxyCodeLine{413     k\_top = nk}
\DoxyCodeLine{414     zeta\_top = 1.}
\DoxyCodeLine{415     k\_bot = nk}
\DoxyCodeLine{416     zeta\_bot = 0.}
\DoxyCodeLine{417     htot = 0.}
\DoxyCodeLine{418     \textcolor{keywordflow}{if} (hbl == 0.) \textcolor{keywordflow}{return}}
\DoxyCodeLine{419     \textcolor{keywordflow}{if} (hbl >= sum(h(:))) \textcolor{keywordflow}{then}}
\DoxyCodeLine{420       k\_top = 1}
\DoxyCodeLine{421       zeta\_top = 1.}
\DoxyCodeLine{422       \textcolor{keywordflow}{return}}
\DoxyCodeLine{423 \textcolor{keywordflow}{    endif}}
\DoxyCodeLine{424     \textcolor{keywordflow}{do} k=nk,1,-1}
\DoxyCodeLine{425       htot = htot + h(k)}
\DoxyCodeLine{426       \textcolor{keywordflow}{if} (htot >= hbl) \textcolor{keywordflow}{then}}
\DoxyCodeLine{427         k\_top = k}
\DoxyCodeLine{428         zeta\_top = 1 - (htot - hbl)/h(k)}
\DoxyCodeLine{429         \textcolor{keywordflow}{return}}
\DoxyCodeLine{430 \textcolor{keywordflow}{      endif}}
\DoxyCodeLine{431 \textcolor{keywordflow}{    enddo}}
\DoxyCodeLine{432   \textcolor{keywordflow}{else}}
\DoxyCodeLine{433     \textcolor{keyword}{call }mom\_error(fatal,\textcolor{stringliteral}{"Houston, we've had a problem in boundary\_k\_range"})}
\DoxyCodeLine{434 \textcolor{keywordflow}{  endif}}
\DoxyCodeLine{435 }

\end{DoxyCode}
\mbox{\Hypertarget{namespacemom__lateral__boundary__diffusion_a764405ce85234799f6b81be25a8df1b7}\label{namespacemom__lateral__boundary__diffusion_a764405ce85234799f6b81be25a8df1b7}} 
\index{mom\_lateral\_boundary\_diffusion@{mom\_lateral\_boundary\_diffusion}!bulk\_average@{bulk\_average}}
\index{bulk\_average@{bulk\_average}!mom\_lateral\_boundary\_diffusion@{mom\_lateral\_boundary\_diffusion}}
\subsubsection{\texorpdfstring{bulk\_average()}{bulk\_average()}}
{\footnotesize\ttfamily real function mom\+\_\+lateral\+\_\+boundary\+\_\+diffusion\+::bulk\+\_\+average (\begin{DoxyParamCaption}\item[{integer}]{boundary,  }\item[{integer}]{nk,  }\item[{integer}]{deg,  }\item[{real, dimension(nk)}]{h,  }\item[{real}]{h\+B\+LT,  }\item[{real, dimension(nk)}]{phi,  }\item[{real, dimension(nk,2)}]{ppoly0\+\_\+E,  }\item[{real, dimension(nk,deg+1)}]{ppoly0\+\_\+coefs,  }\item[{integer}]{method,  }\item[{integer}]{k\+\_\+top,  }\item[{real}]{zeta\+\_\+top,  }\item[{integer}]{k\+\_\+bot,  }\item[{real}]{zeta\+\_\+bot }\end{DoxyParamCaption})\hspace{0.3cm}{\ttfamily [private]}}


\begin{DoxyParams}{Parameters}
{\em boundary} & S\+U\+R\+F\+A\+CE or B\+O\+T\+T\+OM \mbox{[}nondim\mbox{]}\\
\hline
{\em nk} & Number of layers \mbox{[}nondim\mbox{]}\\
\hline
{\em deg} & Degree of polynomial \mbox{[}nondim\mbox{]}\\
\hline
{\em h} & Layer thicknesses \mbox{[}H $\sim$$>$ m or kg m-\/2\mbox{]}\\
\hline
{\em hblt} & Depth of the boundary layer \mbox{[}H $\sim$$>$ m or kg m-\/2\mbox{]}\\
\hline
{\em phi} & Scalar quantity\\
\hline
{\em ppoly0\+\_\+e} & Edge value of polynomial\\
\hline
{\em ppoly0\+\_\+coefs} & Coefficients of polynomial\\
\hline
{\em method} & Remapping scheme to use\\
\hline
{\em k\+\_\+top} & Index of the first layer within the boundary\\
\hline
{\em zeta\+\_\+top} & Fraction of the layer encompassed by the bottom boundary layer (0 if none, 1. if all). For the surface, this is always 0. because integration starts at the surface \mbox{[}nondim\mbox{]}\\
\hline
{\em k\+\_\+bot} & Index of the last layer within the boundary\\
\hline
{\em zeta\+\_\+bot} & Fraction of the layer encompassed by the surface boundary layer (0 if none, 1. if all). For the bottom boundary layer, this is always 1. because integration starts at the bottom \mbox{[}nondim\mbox{]} \\
\hline
\end{DoxyParams}


Definition at line 312 of file M\+O\+M\+\_\+lateral\+\_\+boundary\+\_\+diffusion.\+F90.


\begin{DoxyCode}{0}
\DoxyCodeLine{312   \textcolor{keywordtype}{integer}             :: boundary\textcolor{comment}{          !< SURFACE or BOTTOM                                     [nondim]}}
\DoxyCodeLine{313   \textcolor{keywordtype}{integer}             :: nk\textcolor{comment}{                !< Number of layers                                      [nondim]}}
\DoxyCodeLine{314   \textcolor{keywordtype}{integer}             :: deg\textcolor{comment}{               !< Degree of polynomial                                  [nondim]}}
\DoxyCodeLine{315 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(nk)} :: h\textcolor{comment}{                 !< Layer thicknesses                                     [H ~> m or kg m-2]}}
\DoxyCodeLine{316 \textcolor{keywordtype}{  real}                :: hBLT\textcolor{comment}{              !< Depth of the boundary layer                           [H ~> m or kg m-2]}}
\DoxyCodeLine{317 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(nk)} :: phi\textcolor{comment}{               !< Scalar quantity}}
\DoxyCodeLine{318 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(nk,2)}     :: ppoly0\_E\textcolor{comment}{    !< Edge value of polynomial}}
\DoxyCodeLine{319 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(nk,deg+1)} :: ppoly0\_coefs\textcolor{comment}{!< Coefficients of polynomial}}
\DoxyCodeLine{320   \textcolor{keywordtype}{integer}                   :: method\textcolor{comment}{      !< Remapping scheme to use}}
\DoxyCodeLine{321 }
\DoxyCodeLine{322   \textcolor{keywordtype}{integer}             :: k\_top\textcolor{comment}{             !< Index of the first layer within the boundary}}
\DoxyCodeLine{323 \textcolor{keywordtype}{  real}                :: zeta\_top\textcolor{comment}{          !< Fraction of the layer encompassed by the bottom boundary layer}}
\DoxyCodeLine{324 \textcolor{comment}{                                           !! (0 if none, 1. if all). For the surface, this is always 0. because}}
\DoxyCodeLine{325 \textcolor{comment}{                                           !! integration starts at the surface                     [nondim]}}
\DoxyCodeLine{326   \textcolor{keywordtype}{integer}             :: k\_bot\textcolor{comment}{             !< Index of the last layer within the boundary}}
\DoxyCodeLine{327 \textcolor{keywordtype}{  real}                :: zeta\_bot\textcolor{comment}{          !< Fraction of the layer encompassed by the surface boundary layer}}
\DoxyCodeLine{328 \textcolor{comment}{                                           !! (0 if none, 1. if all). For the bottom boundary layer, this is always 1.}}
\DoxyCodeLine{329 \textcolor{comment}{                                           !! because integration starts at the bottom              [nondim]}}
\DoxyCodeLine{330   \textcolor{comment}{! Local variables}}
\DoxyCodeLine{331 \textcolor{keywordtype}{  real}    :: htot\textcolor{comment}{ !< Running sum of the thicknesses (top to bottom)}}
\DoxyCodeLine{332   \textcolor{keywordtype}{integer} :: k\textcolor{comment}{    !< k indice}}
\DoxyCodeLine{333 }
\DoxyCodeLine{334 }
\DoxyCodeLine{335   htot = 0.}
\DoxyCodeLine{336   bulk\_average = 0.}
\DoxyCodeLine{337   \textcolor{keywordflow}{if} (hblt == 0.) \textcolor{keywordflow}{return}}
\DoxyCodeLine{338   \textcolor{keywordflow}{if} (boundary == surface) \textcolor{keywordflow}{then}}
\DoxyCodeLine{339     htot = (h(k\_bot) * zeta\_bot)}
\DoxyCodeLine{340     bulk\_average = average\_value\_ppoly( nk, phi, ppoly0\_e, ppoly0\_coefs, method, k\_bot, 0., zeta\_bot) * htot}
\DoxyCodeLine{341     \textcolor{keywordflow}{do} k = k\_bot-1,1,-1}
\DoxyCodeLine{342       bulk\_average = bulk\_average + phi(k)*h(k)}
\DoxyCodeLine{343       htot = htot + h(k)}
\DoxyCodeLine{344 \textcolor{keywordflow}{    enddo}}
\DoxyCodeLine{345   \textcolor{keywordflow}{elseif} (boundary == bottom) \textcolor{keywordflow}{then}}
\DoxyCodeLine{346     htot = (h(k\_top) * zeta\_top)}
\DoxyCodeLine{347     \textcolor{comment}{! (note 1-zeta\_top because zeta\_top is the fraction of the layer)}}
\DoxyCodeLine{348     bulk\_average = average\_value\_ppoly( nk, phi, ppoly0\_e, ppoly0\_coefs, method, k\_top, (1.-zeta\_top), 1.) * htot}
\DoxyCodeLine{349     \textcolor{keywordflow}{do} k = k\_top+1,nk}
\DoxyCodeLine{350       bulk\_average = bulk\_average + phi(k)*h(k)}
\DoxyCodeLine{351       htot = htot + h(k)}
\DoxyCodeLine{352 \textcolor{keywordflow}{    enddo}}
\DoxyCodeLine{353   \textcolor{keywordflow}{else}}
\DoxyCodeLine{354     \textcolor{keyword}{call }mom\_error(fatal, \textcolor{stringliteral}{"bulk\_average: a valid boundary type must be provided."})}
\DoxyCodeLine{355 \textcolor{keywordflow}{  endif}}
\DoxyCodeLine{356 }
\DoxyCodeLine{357   bulk\_average = bulk\_average / hblt}
\DoxyCodeLine{358 }

\end{DoxyCode}
\mbox{\Hypertarget{namespacemom__lateral__boundary__diffusion_a4c19afd5acc655501aebc2ec1a4fe396}\label{namespacemom__lateral__boundary__diffusion_a4c19afd5acc655501aebc2ec1a4fe396}} 
\index{mom\_lateral\_boundary\_diffusion@{mom\_lateral\_boundary\_diffusion}!fluxes\_bulk\_method@{fluxes\_bulk\_method}}
\index{fluxes\_bulk\_method@{fluxes\_bulk\_method}!mom\_lateral\_boundary\_diffusion@{mom\_lateral\_boundary\_diffusion}}
\subsubsection{\texorpdfstring{fluxes\_bulk\_method()}{fluxes\_bulk\_method()}}
{\footnotesize\ttfamily subroutine mom\+\_\+lateral\+\_\+boundary\+\_\+diffusion\+::fluxes\+\_\+bulk\+\_\+method (\begin{DoxyParamCaption}\item[{integer, intent(in)}]{boundary,  }\item[{integer, intent(in)}]{nk,  }\item[{integer, intent(in)}]{deg,  }\item[{real, dimension(nk), intent(in)}]{h\+\_\+L,  }\item[{real, dimension(nk), intent(in)}]{h\+\_\+R,  }\item[{real, intent(in)}]{hbl\+\_\+L,  }\item[{real, intent(in)}]{hbl\+\_\+R,  }\item[{real, intent(in)}]{area\+\_\+L,  }\item[{real, intent(in)}]{area\+\_\+R,  }\item[{real, dimension(nk), intent(in)}]{phi\+\_\+L,  }\item[{real, dimension(nk), intent(in)}]{phi\+\_\+R,  }\item[{real, dimension(nk,deg+1), intent(in)}]{ppoly0\+\_\+coefs\+\_\+L,  }\item[{real, dimension(nk,deg+1), intent(in)}]{ppoly0\+\_\+coefs\+\_\+R,  }\item[{real, dimension(nk,2), intent(in)}]{ppoly0\+\_\+\+E\+\_\+L,  }\item[{real, dimension(nk,2), intent(in)}]{ppoly0\+\_\+\+E\+\_\+R,  }\item[{integer, intent(in)}]{method,  }\item[{real, intent(in)}]{khtr\+\_\+u,  }\item[{real, intent(out)}]{F\+\_\+bulk,  }\item[{real, dimension(nk), intent(out)}]{F\+\_\+layer,  }\item[{logical, intent(in), optional}]{F\+\_\+limit,  }\item[{logical, intent(in), optional}]{linear\+\_\+decay }\end{DoxyParamCaption})\hspace{0.3cm}{\ttfamily [private]}}



Apply the lateral boundary diffusive fluxes calculated from a \textquotesingle{}bulk model\textquotesingle{} See \mbox{\hyperlink{namespacemom__lateral__boundary__diffusion_section_method2}{Bulk layer approach (Method \#2)}}. 


\begin{DoxyParams}[1]{Parameters}
\mbox{\texttt{ in}}  & {\em boundary} & Which boundary layer S\+U\+R\+F\+A\+CE or B\+O\+T\+T\+OM \mbox{[}nondim\mbox{]} \\
\hline
\mbox{\texttt{ in}}  & {\em nk} & Number of layers \mbox{[}nondim\mbox{]} \\
\hline
\mbox{\texttt{ in}}  & {\em deg} & order of the polynomial reconstruction \mbox{[}nondim\mbox{]} \\
\hline
\mbox{\texttt{ in}}  & {\em h\+\_\+l} & Layer thickness (left) \mbox{[}H $\sim$$>$ m or kg m-\/2\mbox{]} \\
\hline
\mbox{\texttt{ in}}  & {\em h\+\_\+r} & Layer thickness (right) \mbox{[}H $\sim$$>$ m or kg m-\/2\mbox{]} \\
\hline
\mbox{\texttt{ in}}  & {\em hbl\+\_\+l} & Thickness of the boundary boundary layer (left) \mbox{[}H $\sim$$>$ m or kg m-\/2\mbox{]} \\
\hline
\mbox{\texttt{ in}}  & {\em hbl\+\_\+r} & Thickness of the boundary boundary layer (left) \mbox{[}H $\sim$$>$ m or kg m-\/2\mbox{]} \\
\hline
\mbox{\texttt{ in}}  & {\em area\+\_\+l} & Area of the horizontal grid (left) \mbox{[}L2 $\sim$$>$ m2\mbox{]} \\
\hline
\mbox{\texttt{ in}}  & {\em area\+\_\+r} & Area of the horizontal grid (right) \mbox{[}L2 $\sim$$>$ m2\mbox{]} \\
\hline
\mbox{\texttt{ in}}  & {\em phi\+\_\+l} & Tracer values (left) \mbox{[}conc\mbox{]} \\
\hline
\mbox{\texttt{ in}}  & {\em phi\+\_\+r} & Tracer values (right) \mbox{[}conc\mbox{]} \\
\hline
\mbox{\texttt{ in}}  & {\em ppoly0\+\_\+coefs\+\_\+l} & Tracer reconstruction (left) \mbox{[}conc\mbox{]} \\
\hline
\mbox{\texttt{ in}}  & {\em ppoly0\+\_\+coefs\+\_\+r} & Tracer reconstruction (right) \mbox{[}conc\mbox{]} \\
\hline
\mbox{\texttt{ in}}  & {\em ppoly0\+\_\+e\+\_\+l} & Polynomial edge values (left) \mbox{[}nondim\mbox{]} \\
\hline
\mbox{\texttt{ in}}  & {\em ppoly0\+\_\+e\+\_\+r} & Polynomial edge values (right) \mbox{[}nondim\mbox{]} \\
\hline
\mbox{\texttt{ in}}  & {\em method} & Method of polynomial integration \mbox{[}nondim\mbox{]} \\
\hline
\mbox{\texttt{ in}}  & {\em khtr\+\_\+u} & Horizontal diffusivities times delta t at a velocity point \mbox{[}L2 $\sim$$>$ m2\mbox{]} \\
\hline
\mbox{\texttt{ out}}  & {\em f\+\_\+bulk} & The bulk mixed layer lateral flux \mbox{[}H L2 conc $\sim$$>$ m3 conc\mbox{]} \\
\hline
\mbox{\texttt{ out}}  & {\em f\+\_\+layer} & Layerwise diffusive flux at U-\/ or V-\/point \mbox{[}H L2 conc $\sim$$>$ m3 conc\mbox{]} \\
\hline
\mbox{\texttt{ in}}  & {\em f\+\_\+limit} & If True, apply a limiter \\
\hline
\mbox{\texttt{ in}}  & {\em linear\+\_\+decay} & If True, apply a linear transition at the base of the boundary layer \\
\hline
\end{DoxyParams}


Definition at line 598 of file M\+O\+M\+\_\+lateral\+\_\+boundary\+\_\+diffusion.\+F90.


\begin{DoxyCode}{0}
\DoxyCodeLine{598 }
\DoxyCodeLine{599   \textcolor{keywordtype}{integer},                   \textcolor{keywordtype}{intent(in   )}       :: boundary\textcolor{comment}{ !< Which boundary layer SURFACE or BOTTOM  [nondim]}}
\DoxyCodeLine{600   \textcolor{keywordtype}{integer},                   \textcolor{keywordtype}{intent(in   )}       :: nk\textcolor{comment}{       !< Number of layers                        [nondim]}}
\DoxyCodeLine{601   \textcolor{keywordtype}{integer},                   \textcolor{keywordtype}{intent(in   )}       :: deg\textcolor{comment}{      !< order of the polynomial reconstruction  [nondim]}}
\DoxyCodeLine{602 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(nk)},       \textcolor{keywordtype}{intent(in   )}       :: h\_L\textcolor{comment}{      !< Layer thickness (left)              [H ~> m or kg m-2]}}
\DoxyCodeLine{603 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(nk)},       \textcolor{keywordtype}{intent(in   )}       :: h\_R\textcolor{comment}{      !< Layer thickness (right)             [H ~> m or kg m-2]}}
\DoxyCodeLine{604 \textcolor{keywordtype}{  real},                      \textcolor{keywordtype}{intent(in   )}       :: hbl\_L\textcolor{comment}{    !< Thickness of the boundary boundary}}
\DoxyCodeLine{605 \textcolor{comment}{                                                                       !! layer (left)              [H ~> m or kg m-2]}}
\DoxyCodeLine{606 \textcolor{keywordtype}{  real},                      \textcolor{keywordtype}{intent(in   )}       :: hbl\_R\textcolor{comment}{    !< Thickness of the boundary boundary}}
\DoxyCodeLine{607 \textcolor{comment}{                                                             !! layer (left)                        [H ~> m or kg m-2]}}
\DoxyCodeLine{608 \textcolor{keywordtype}{  real},                      \textcolor{keywordtype}{intent(in   )}       :: area\_L\textcolor{comment}{   !< Area of the horizontal grid (left)  [L2 ~> m2]}}
\DoxyCodeLine{609 \textcolor{keywordtype}{  real},                      \textcolor{keywordtype}{intent(in   )}       :: area\_R\textcolor{comment}{   !< Area of the horizontal grid (right) [L2 ~> m2]}}
\DoxyCodeLine{610 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(nk)},       \textcolor{keywordtype}{intent(in   )}       :: phi\_L\textcolor{comment}{    !< Tracer values (left)                [conc]}}
\DoxyCodeLine{611 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(nk)},       \textcolor{keywordtype}{intent(in   )}       :: phi\_R\textcolor{comment}{    !< Tracer values (right)               [conc]}}
\DoxyCodeLine{612 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(nk,deg+1)}, \textcolor{keywordtype}{intent(in   )}       :: ppoly0\_coefs\_L\textcolor{comment}{ !< Tracer reconstruction (left)  [conc]}}
\DoxyCodeLine{613 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(nk,deg+1)}, \textcolor{keywordtype}{intent(in   )}       :: ppoly0\_coefs\_R\textcolor{comment}{ !< Tracer reconstruction (right) [conc]}}
\DoxyCodeLine{614 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(nk,2)},     \textcolor{keywordtype}{intent(in   )}       :: ppoly0\_E\_L\textcolor{comment}{ !< Polynomial edge values (left)     [nondim]}}
\DoxyCodeLine{615 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(nk,2)},     \textcolor{keywordtype}{intent(in   )}       :: ppoly0\_E\_R\textcolor{comment}{ !< Polynomial edge values (right)    [nondim]}}
\DoxyCodeLine{616   \textcolor{keywordtype}{integer},                   \textcolor{keywordtype}{intent(in   )}       :: method\textcolor{comment}{   !< Method of polynomial integration    [nondim]}}
\DoxyCodeLine{617 \textcolor{keywordtype}{  real},                      \textcolor{keywordtype}{intent(in   )}       :: khtr\_u\textcolor{comment}{   !< Horizontal diffusivities times delta t}}
\DoxyCodeLine{618 \textcolor{comment}{                                                             !! at a velocity point [L2 ~> m2]}}
\DoxyCodeLine{619 \textcolor{keywordtype}{  real},                      \textcolor{keywordtype}{intent(  out)}       :: F\_bulk\textcolor{comment}{   !< The bulk mixed layer lateral flux}}
\DoxyCodeLine{620 \textcolor{comment}{                                                             !! [H L2 conc ~> m3 conc]}}
\DoxyCodeLine{621 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(nk)},       \textcolor{keywordtype}{intent(  out)}       :: F\_layer\textcolor{comment}{  !< Layerwise diffusive flux at U- or V-point}}
\DoxyCodeLine{622 \textcolor{comment}{                                                             !! [H L2 conc ~> m3 conc]}}
\DoxyCodeLine{623   \textcolor{keywordtype}{logical}, \textcolor{keywordtype}{optional},         \textcolor{keywordtype}{intent(in   )}       :: F\_limit\textcolor{comment}{  !< If True, apply a limiter}}
\DoxyCodeLine{624   \textcolor{keywordtype}{logical}, \textcolor{keywordtype}{optional},         \textcolor{keywordtype}{intent(in   )}       :: linear\_decay\textcolor{comment}{ !< If True, apply a linear transition at the base of}}
\DoxyCodeLine{625 \textcolor{comment}{                                                             !! the boundary layer}}
\DoxyCodeLine{626 }
\DoxyCodeLine{627   \textcolor{comment}{! Local variables}}
\DoxyCodeLine{628 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(nk)} :: h\_means\textcolor{comment}{              !< Calculate the layer-wise harmonic means           [H ~> m or kg m-2]}}
\DoxyCodeLine{629 \textcolor{keywordtype}{  real}                :: khtr\_avg\textcolor{comment}{             !< Thickness-weighted diffusivity at the u-point     [m\string^2 s\string^-1]}}
\DoxyCodeLine{630 \textcolor{comment}{                                              !! This is just to remind developers that khtr\_avg should be}}
\DoxyCodeLine{631 \textcolor{comment}{                                              !! computed once khtr is 3D.}}
\DoxyCodeLine{632 \textcolor{keywordtype}{  real}                :: heff\textcolor{comment}{                 !< Harmonic mean of layer thicknesses                [H ~> m or kg m-2]}}
\DoxyCodeLine{633 \textcolor{keywordtype}{  real}                :: heff\_tot\textcolor{comment}{             !< Total effective column thickness in the transition layer [m]}}
\DoxyCodeLine{634 \textcolor{keywordtype}{  real}                :: inv\_heff\textcolor{comment}{             !< Inverse of the harmonic mean of layer thicknesses}}
\DoxyCodeLine{635 \textcolor{comment}{                                              !! [H-1 ~> m-1 or m2 kg-1]}}
\DoxyCodeLine{636 \textcolor{keywordtype}{  real}                :: phi\_L\_avg, phi\_R\_avg\textcolor{comment}{ !< Bulk, thickness-weighted tracer averages (left and right column)}}
\DoxyCodeLine{637 \textcolor{comment}{                                              !!                                                   [conc m\string^-3 ]}}
\DoxyCodeLine{638 \textcolor{keywordtype}{  real}    :: htot                             \textcolor{comment}{! Total column thickness [H ~> m or kg m-2]}}
\DoxyCodeLine{639   \textcolor{keywordtype}{integer} :: k, k\_min, k\_max\textcolor{comment}{                  !< k-indices, min and max for top and bottom, respectively}}
\DoxyCodeLine{640   \textcolor{keywordtype}{integer} :: k\_diff\textcolor{comment}{                           !< difference between k\_max and k\_min}}
\DoxyCodeLine{641   \textcolor{keywordtype}{integer} :: k\_top\_L, k\_bot\_L\textcolor{comment}{                 !< k-indices left}}
\DoxyCodeLine{642   \textcolor{keywordtype}{integer} :: k\_top\_R, k\_bot\_R\textcolor{comment}{                 !< k-indices right}}
\DoxyCodeLine{643 \textcolor{keywordtype}{  real}    :: zeta\_top\_L, zeta\_top\_R\textcolor{comment}{           !< distance from the top of a layer to the}}
\DoxyCodeLine{644 \textcolor{comment}{                                              !! boundary layer   [nondim]}}
\DoxyCodeLine{645 \textcolor{keywordtype}{  real}    :: zeta\_bot\_L, zeta\_bot\_R\textcolor{comment}{           !< distance from the bottom of a layer to the}}
\DoxyCodeLine{646 \textcolor{comment}{                                              !! boundary layer   [nondim]}}
\DoxyCodeLine{647 \textcolor{keywordtype}{  real}    :: h\_work\_L, h\_work\_R\textcolor{comment}{               !< dummy variables}}
\DoxyCodeLine{648 \textcolor{keywordtype}{  real}    :: F\_max\textcolor{comment}{                            !< The maximum amount of flux that can leave a}}
\DoxyCodeLine{649 \textcolor{comment}{                                              !! cell  [m\string^3 conc]}}
\DoxyCodeLine{650   \textcolor{keywordtype}{logical} :: limiter\textcolor{comment}{                          !< True if flux limiter should be applied}}
\DoxyCodeLine{651   \textcolor{keywordtype}{logical} :: linear\textcolor{comment}{                           !< True if apply a linear transition}}
\DoxyCodeLine{652 \textcolor{keywordtype}{  real}    :: hfrac\textcolor{comment}{                            !< Layer fraction wrt sum of all layers [nondim]}}
\DoxyCodeLine{653 \textcolor{keywordtype}{  real}    :: dphi\textcolor{comment}{                             !< tracer gradient                      [conc m\string^-3]}}
\DoxyCodeLine{654 \textcolor{keywordtype}{  real}    :: wgt\textcolor{comment}{                              !< weight to be used in the linear transition to the}}
\DoxyCodeLine{655 \textcolor{comment}{                                              !! interior [nondim]}}
\DoxyCodeLine{656 \textcolor{keywordtype}{  real}    :: a\textcolor{comment}{                                !< coefficient to be used in the linear transition to the}}
\DoxyCodeLine{657 \textcolor{comment}{                                              !! interior [nondim]}}
\DoxyCodeLine{658 }
\DoxyCodeLine{659   f\_bulk = 0.}
\DoxyCodeLine{660   f\_layer(:) = 0.}
\DoxyCodeLine{661   \textcolor{keywordflow}{if} (hbl\_l == 0. .or. hbl\_r == 0.) \textcolor{keywordflow}{then}}
\DoxyCodeLine{662     \textcolor{keywordflow}{return}}
\DoxyCodeLine{663 \textcolor{keywordflow}{  endif}}
\DoxyCodeLine{664 }
\DoxyCodeLine{665   limiter = .false.}
\DoxyCodeLine{666   \textcolor{keywordflow}{if} (\textcolor{keyword}{PRESENT}(f\_limit)) \textcolor{keywordflow}{then}}
\DoxyCodeLine{667     limiter = f\_limit}
\DoxyCodeLine{668 \textcolor{keywordflow}{  endif}}
\DoxyCodeLine{669   linear = .false.}
\DoxyCodeLine{670   \textcolor{keywordflow}{if} (\textcolor{keyword}{PRESENT}(linear\_decay)) \textcolor{keywordflow}{then}}
\DoxyCodeLine{671     linear = linear\_decay}
\DoxyCodeLine{672 \textcolor{keywordflow}{  endif}}
\DoxyCodeLine{673 }
\DoxyCodeLine{674   \textcolor{comment}{! Calculate vertical indices containing the boundary layer}}
\DoxyCodeLine{675   \textcolor{keyword}{call }boundary\_k\_range(boundary, nk, h\_l, hbl\_l, k\_top\_l, zeta\_top\_l, k\_bot\_l, zeta\_bot\_l)}
\DoxyCodeLine{676   \textcolor{keyword}{call }boundary\_k\_range(boundary, nk, h\_r, hbl\_r, k\_top\_r, zeta\_top\_r, k\_bot\_r, zeta\_bot\_r)}
\DoxyCodeLine{677 }
\DoxyCodeLine{678   \textcolor{comment}{! Calculate bulk averages of various quantities}}
\DoxyCodeLine{679   phi\_l\_avg  = bulk\_average(boundary, nk, deg, h\_l, hbl\_l, phi\_l, ppoly0\_e\_l, ppoly0\_coefs\_l, method, k\_top\_l, \&}
\DoxyCodeLine{680                             zeta\_top\_l, k\_bot\_l, zeta\_bot\_l)}
\DoxyCodeLine{681   phi\_r\_avg  = bulk\_average(boundary, nk, deg, h\_r, hbl\_r, phi\_r, ppoly0\_e\_r, ppoly0\_coefs\_r, method, k\_top\_r, \&}
\DoxyCodeLine{682                             zeta\_top\_r, k\_bot\_r, zeta\_bot\_r)}
\DoxyCodeLine{683   \textcolor{comment}{! Calculate the 'bulk' diffusive flux from the bulk averaged quantities}}
\DoxyCodeLine{684   \textcolor{comment}{! GMM, khtr\_avg should be computed once khtr is 3D}}
\DoxyCodeLine{685   heff = harmonic\_mean(hbl\_l, hbl\_r)}
\DoxyCodeLine{686   f\_bulk = -(khtr\_u * heff) * (phi\_r\_avg - phi\_l\_avg)}
\DoxyCodeLine{687   \textcolor{comment}{! Calculate the layerwise sum of the vertical effective thickness. This is different than the heff calculated}}
\DoxyCodeLine{688   \textcolor{comment}{! above, but is used as a way to decompose the fluxes onto the individual layers}}
\DoxyCodeLine{689   h\_means(:) = 0.}
\DoxyCodeLine{690   \textcolor{keywordflow}{if} (boundary == surface) \textcolor{keywordflow}{then}}
\DoxyCodeLine{691     k\_min = min(k\_bot\_l, k\_bot\_r)}
\DoxyCodeLine{692     k\_max = max(k\_bot\_l, k\_bot\_r)}
\DoxyCodeLine{693     k\_diff = (k\_max - k\_min)}
\DoxyCodeLine{694     \textcolor{keywordflow}{if} ((linear) .and. (k\_diff .gt. 1)) \textcolor{keywordflow}{then}}
\DoxyCodeLine{695       \textcolor{keywordflow}{do} k=1,k\_min}
\DoxyCodeLine{696         h\_means(k) = harmonic\_mean(h\_l(k),h\_r(k))}
\DoxyCodeLine{697 \textcolor{keywordflow}{      enddo}}
\DoxyCodeLine{698       \textcolor{comment}{! heff\_total}}
\DoxyCodeLine{699       heff\_tot = 0.0}
\DoxyCodeLine{700       \textcolor{keywordflow}{do} k = k\_min+1,k\_max, 1}
\DoxyCodeLine{701         heff\_tot = heff\_tot + harmonic\_mean(h\_l(k), h\_r(k))}
\DoxyCodeLine{702 \textcolor{keywordflow}{      enddo}}
\DoxyCodeLine{703 }
\DoxyCodeLine{704       a = -1.0/heff\_tot}
\DoxyCodeLine{705       heff\_tot = 0.0}
\DoxyCodeLine{706       \textcolor{comment}{! fluxes will decay linearly at base of hbl}}
\DoxyCodeLine{707       \textcolor{keywordflow}{do} k = k\_min+1,k\_max, 1}
\DoxyCodeLine{708         heff = harmonic\_mean(h\_l(k), h\_r(k))}
\DoxyCodeLine{709         wgt = (a*(heff\_tot + (heff * 0.5))) + 1.0}
\DoxyCodeLine{710         h\_means(k) = harmonic\_mean(h\_l(k), h\_r(k)) * wgt}
\DoxyCodeLine{711         heff\_tot = heff\_tot + heff}
\DoxyCodeLine{712 \textcolor{keywordflow}{      enddo}}
\DoxyCodeLine{713     \textcolor{keywordflow}{else}}
\DoxyCodeLine{714       \textcolor{comment}{! left hand side}}
\DoxyCodeLine{715       \textcolor{keywordflow}{if} (k\_bot\_l == k\_min) \textcolor{keywordflow}{then}}
\DoxyCodeLine{716         h\_work\_l = h\_l(k\_min) * zeta\_bot\_l}
\DoxyCodeLine{717       \textcolor{keywordflow}{else}}
\DoxyCodeLine{718         h\_work\_l = h\_l(k\_min)}
\DoxyCodeLine{719 \textcolor{keywordflow}{      endif}}
\DoxyCodeLine{720 }
\DoxyCodeLine{721       \textcolor{comment}{! right hand side}}
\DoxyCodeLine{722       \textcolor{keywordflow}{if} (k\_bot\_r == k\_min) \textcolor{keywordflow}{then}}
\DoxyCodeLine{723         h\_work\_r = h\_r(k\_min) * zeta\_bot\_r}
\DoxyCodeLine{724       \textcolor{keywordflow}{else}}
\DoxyCodeLine{725         h\_work\_r = h\_r(k\_min)}
\DoxyCodeLine{726 \textcolor{keywordflow}{      endif}}
\DoxyCodeLine{727 }
\DoxyCodeLine{728       h\_means(k\_min) = harmonic\_mean(h\_work\_l,h\_work\_r)}
\DoxyCodeLine{729 }
\DoxyCodeLine{730       \textcolor{keywordflow}{do} k=1,k\_min-1}
\DoxyCodeLine{731         h\_means(k) = harmonic\_mean(h\_l(k),h\_r(k))}
\DoxyCodeLine{732 \textcolor{keywordflow}{      enddo}}
\DoxyCodeLine{733 \textcolor{keywordflow}{    endif}}
\DoxyCodeLine{734 }
\DoxyCodeLine{735   \textcolor{keywordflow}{elseif} (boundary == bottom) \textcolor{keywordflow}{then}}
\DoxyCodeLine{736     \textcolor{comment}{!TODO, GMM linear decay is not implemented here}}
\DoxyCodeLine{737     k\_max = max(k\_top\_l, k\_top\_r)}
\DoxyCodeLine{738     \textcolor{comment}{! left hand side}}
\DoxyCodeLine{739     \textcolor{keywordflow}{if} (k\_top\_l == k\_max) \textcolor{keywordflow}{then}}
\DoxyCodeLine{740       h\_work\_l = h\_l(k\_max) * zeta\_top\_l}
\DoxyCodeLine{741     \textcolor{keywordflow}{else}}
\DoxyCodeLine{742       h\_work\_l = h\_l(k\_max)}
\DoxyCodeLine{743 \textcolor{keywordflow}{    endif}}
\DoxyCodeLine{744 }
\DoxyCodeLine{745     \textcolor{comment}{! right hand side}}
\DoxyCodeLine{746     \textcolor{keywordflow}{if} (k\_top\_r == k\_max) \textcolor{keywordflow}{then}}
\DoxyCodeLine{747       h\_work\_r = h\_r(k\_max) * zeta\_top\_r}
\DoxyCodeLine{748     \textcolor{keywordflow}{else}}
\DoxyCodeLine{749       h\_work\_r = h\_r(k\_max)}
\DoxyCodeLine{750 \textcolor{keywordflow}{    endif}}
\DoxyCodeLine{751 }
\DoxyCodeLine{752     h\_means(k\_max) = harmonic\_mean(h\_work\_l,h\_work\_r)}
\DoxyCodeLine{753 }
\DoxyCodeLine{754     \textcolor{keywordflow}{do} k=nk,k\_max+1,-1}
\DoxyCodeLine{755       h\_means(k) = harmonic\_mean(h\_l(k),h\_r(k))}
\DoxyCodeLine{756 \textcolor{keywordflow}{    enddo}}
\DoxyCodeLine{757 \textcolor{keywordflow}{  endif}}
\DoxyCodeLine{758 }
\DoxyCodeLine{759   \textcolor{keywordflow}{if} ( sum(h\_means) == 0. .or. f\_bulk == 0.) \textcolor{keywordflow}{then}}
\DoxyCodeLine{760     \textcolor{keywordflow}{return}}
\DoxyCodeLine{761   \textcolor{comment}{! Decompose the bulk flux onto the individual layers}}
\DoxyCodeLine{762   \textcolor{keywordflow}{else}}
\DoxyCodeLine{763     \textcolor{comment}{! Initialize remaining thickness}}
\DoxyCodeLine{764     inv\_heff = 1./sum(h\_means)}
\DoxyCodeLine{765     \textcolor{keywordflow}{do} k=1,nk}
\DoxyCodeLine{766       \textcolor{keywordflow}{if} ((h\_means(k) > 0.) .and. (phi\_l(k) /= phi\_r(k))) \textcolor{keywordflow}{then}}
\DoxyCodeLine{767         hfrac = h\_means(k)*inv\_heff}
\DoxyCodeLine{768         f\_layer(k) = f\_bulk * hfrac}
\DoxyCodeLine{769 }
\DoxyCodeLine{770         \textcolor{keywordflow}{if} (limiter) \textcolor{keywordflow}{then}}
\DoxyCodeLine{771           \textcolor{comment}{! limit the flux to 0.2 of the tracer *gradient*}}
\DoxyCodeLine{772           \textcolor{comment}{! Why 0.2?}}
\DoxyCodeLine{773           \textcolor{comment}{!  t=0         t=inf}}
\DoxyCodeLine{774           \textcolor{comment}{!   0           .2}}
\DoxyCodeLine{775           \textcolor{comment}{! 0 1 0       .2.2.2}}
\DoxyCodeLine{776           \textcolor{comment}{!   0           .2}}
\DoxyCodeLine{777           \textcolor{comment}{!}}
\DoxyCodeLine{778           f\_max = -0.2 * ((area\_r*(phi\_r(k)*h\_r(k)))-(area\_l*(phi\_l(k)*h\_r(k))))}
\DoxyCodeLine{779 }
\DoxyCodeLine{780           \textcolor{comment}{! check if bulk flux (or F\_layer) and F\_max have same direction}}
\DoxyCodeLine{781           \textcolor{keywordflow}{if} ( sign(1.,f\_bulk) == sign(1., f\_max)) \textcolor{keywordflow}{then}}
\DoxyCodeLine{782             \textcolor{comment}{! Apply flux limiter calculated above}}
\DoxyCodeLine{783             \textcolor{keywordflow}{if} (f\_max >= 0.) \textcolor{keywordflow}{then}}
\DoxyCodeLine{784               f\_layer(k) = min(f\_layer(k),f\_max)}
\DoxyCodeLine{785             \textcolor{keywordflow}{else}}
\DoxyCodeLine{786               f\_layer(k) = max(f\_layer(k),f\_max)}
\DoxyCodeLine{787 \textcolor{keywordflow}{            endif}}
\DoxyCodeLine{788           \textcolor{keywordflow}{else}}
\DoxyCodeLine{789             \textcolor{comment}{! do not apply a flux on this layer}}
\DoxyCodeLine{790             f\_layer(k) = 0.}
\DoxyCodeLine{791 \textcolor{keywordflow}{          endif}}
\DoxyCodeLine{792         \textcolor{keywordflow}{else}}
\DoxyCodeLine{793           dphi = -(phi\_r(k) - phi\_l(k))}
\DoxyCodeLine{794           \textcolor{keywordflow}{if} (.not. sign(1.,f\_bulk) == sign(1., dphi)) \textcolor{keywordflow}{then}}
\DoxyCodeLine{795             \textcolor{comment}{! upgradient, do not apply a flux on this layer}}
\DoxyCodeLine{796             f\_layer(k) = 0.}
\DoxyCodeLine{797 \textcolor{keywordflow}{          endif}}
\DoxyCodeLine{798 \textcolor{keywordflow}{        endif} \textcolor{comment}{! limited}}
\DoxyCodeLine{799 \textcolor{keywordflow}{      endif}}
\DoxyCodeLine{800 \textcolor{keywordflow}{    enddo}}
\DoxyCodeLine{801 \textcolor{keywordflow}{  endif}}
\DoxyCodeLine{802 }

\end{DoxyCode}
\mbox{\Hypertarget{namespacemom__lateral__boundary__diffusion_ae8390123e94524264b952483ef9d79f8}\label{namespacemom__lateral__boundary__diffusion_ae8390123e94524264b952483ef9d79f8}} 
\index{mom\_lateral\_boundary\_diffusion@{mom\_lateral\_boundary\_diffusion}!fluxes\_layer\_method@{fluxes\_layer\_method}}
\index{fluxes\_layer\_method@{fluxes\_layer\_method}!mom\_lateral\_boundary\_diffusion@{mom\_lateral\_boundary\_diffusion}}
\subsubsection{\texorpdfstring{fluxes\_layer\_method()}{fluxes\_layer\_method()}}
{\footnotesize\ttfamily subroutine mom\+\_\+lateral\+\_\+boundary\+\_\+diffusion\+::fluxes\+\_\+layer\+\_\+method (\begin{DoxyParamCaption}\item[{integer, intent(in)}]{boundary,  }\item[{integer, intent(in)}]{nk,  }\item[{integer, intent(in)}]{deg,  }\item[{real, dimension(nk), intent(in)}]{h\+\_\+L,  }\item[{real, dimension(nk), intent(in)}]{h\+\_\+R,  }\item[{real, intent(in)}]{hbl\+\_\+L,  }\item[{real, intent(in)}]{hbl\+\_\+R,  }\item[{real, intent(in)}]{area\+\_\+L,  }\item[{real, intent(in)}]{area\+\_\+R,  }\item[{real, dimension(nk), intent(in)}]{phi\+\_\+L,  }\item[{real, dimension(nk), intent(in)}]{phi\+\_\+R,  }\item[{real, dimension(nk,deg+1), intent(in)}]{ppoly0\+\_\+coefs\+\_\+L,  }\item[{real, dimension(nk,deg+1), intent(in)}]{ppoly0\+\_\+coefs\+\_\+R,  }\item[{real, dimension(nk,2), intent(in)}]{ppoly0\+\_\+\+E\+\_\+L,  }\item[{real, dimension(nk,2), intent(in)}]{ppoly0\+\_\+\+E\+\_\+R,  }\item[{integer, intent(in)}]{method,  }\item[{real, intent(in)}]{khtr\+\_\+u,  }\item[{real, dimension(nk), intent(out)}]{F\+\_\+layer,  }\item[{logical, intent(in), optional}]{linear\+\_\+decay }\end{DoxyParamCaption})\hspace{0.3cm}{\ttfamily [private]}}



Calculate the lateral boundary diffusive fluxes using the layer by layer method. See \mbox{\hyperlink{namespacemom__lateral__boundary__diffusion_section_method1}{Along layer approach (Method \#1)}}. 


\begin{DoxyParams}[1]{Parameters}
\mbox{\texttt{ in}}  & {\em boundary} & Which boundary layer S\+U\+R\+F\+A\+CE or B\+O\+T\+T\+OM \mbox{[}nondim\mbox{]} \\
\hline
\mbox{\texttt{ in}}  & {\em nk} & Number of layers \mbox{[}nondim\mbox{]} \\
\hline
\mbox{\texttt{ in}}  & {\em deg} & order of the polynomial reconstruction \mbox{[}nondim\mbox{]} \\
\hline
\mbox{\texttt{ in}}  & {\em h\+\_\+l} & Layer thickness (left) \mbox{[}H $\sim$$>$ m or kg m-\/2\mbox{]} \\
\hline
\mbox{\texttt{ in}}  & {\em h\+\_\+r} & Layer thickness (right) \mbox{[}H $\sim$$>$ m or kg m-\/2\mbox{]} \\
\hline
\mbox{\texttt{ in}}  & {\em hbl\+\_\+l} & Thickness of the boundary boundary layer (left) \mbox{[}H $\sim$$>$ m or kg m-\/2\mbox{]} \\
\hline
\mbox{\texttt{ in}}  & {\em hbl\+\_\+r} & Thickness of the boundary boundary layer (right) \mbox{[}H $\sim$$>$ m or kg m-\/2\mbox{]} \\
\hline
\mbox{\texttt{ in}}  & {\em area\+\_\+l} & Area of the horizontal grid (left) \mbox{[}L2 $\sim$$>$ m2\mbox{]} \\
\hline
\mbox{\texttt{ in}}  & {\em area\+\_\+r} & Area of the horizontal grid (right) \mbox{[}L2 $\sim$$>$ m2\mbox{]} \\
\hline
\mbox{\texttt{ in}}  & {\em phi\+\_\+l} & Tracer values (left) \mbox{[}conc\mbox{]} \\
\hline
\mbox{\texttt{ in}}  & {\em phi\+\_\+r} & Tracer values (right) \mbox{[}conc\mbox{]} \\
\hline
\mbox{\texttt{ in}}  & {\em ppoly0\+\_\+coefs\+\_\+l} & Tracer reconstruction (left) \mbox{[}conc\mbox{]} \\
\hline
\mbox{\texttt{ in}}  & {\em ppoly0\+\_\+coefs\+\_\+r} & Tracer reconstruction (right) \mbox{[}conc\mbox{]} \\
\hline
\mbox{\texttt{ in}}  & {\em ppoly0\+\_\+e\+\_\+l} & Polynomial edge values (left) \mbox{[}nondim\mbox{]} \\
\hline
\mbox{\texttt{ in}}  & {\em ppoly0\+\_\+e\+\_\+r} & Polynomial edge values (right) \mbox{[}nondim\mbox{]} \\
\hline
\mbox{\texttt{ in}}  & {\em method} & Method of polynomial integration \mbox{[}nondim\mbox{]} \\
\hline
\mbox{\texttt{ in}}  & {\em khtr\+\_\+u} & Horizontal diffusivities times delta t at a velocity point \mbox{[}L2 $\sim$$>$ m2\mbox{]} \\
\hline
\mbox{\texttt{ out}}  & {\em f\+\_\+layer} & Layerwise diffusive flux at U-\/ or V-\/point \mbox{[}H L2 conc $\sim$$>$ m3 conc\mbox{]} \\
\hline
\mbox{\texttt{ in}}  & {\em linear\+\_\+decay} & If True, apply a linear transition at the base of the boundary layer \\
\hline
\end{DoxyParams}


Definition at line 444 of file M\+O\+M\+\_\+lateral\+\_\+boundary\+\_\+diffusion.\+F90.


\begin{DoxyCode}{0}
\DoxyCodeLine{444 }
\DoxyCodeLine{445   \textcolor{keywordtype}{integer},                   \textcolor{keywordtype}{intent(in   )}       :: boundary\textcolor{comment}{ !< Which boundary layer SURFACE or BOTTOM  [nondim]}}
\DoxyCodeLine{446   \textcolor{keywordtype}{integer},                   \textcolor{keywordtype}{intent(in   )}       :: nk\textcolor{comment}{       !< Number of layers                        [nondim]}}
\DoxyCodeLine{447   \textcolor{keywordtype}{integer},                   \textcolor{keywordtype}{intent(in   )}       :: deg\textcolor{comment}{      !< order of the polynomial reconstruction  [nondim]}}
\DoxyCodeLine{448 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(nk)},       \textcolor{keywordtype}{intent(in   )}       :: h\_L\textcolor{comment}{      !< Layer thickness (left)              [H ~> m or kg m-2]}}
\DoxyCodeLine{449 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(nk)},       \textcolor{keywordtype}{intent(in   )}       :: h\_R\textcolor{comment}{      !< Layer thickness (right)             [H ~> m or kg m-2]}}
\DoxyCodeLine{450 \textcolor{keywordtype}{  real},                      \textcolor{keywordtype}{intent(in   )}       :: hbl\_L\textcolor{comment}{    !< Thickness of the boundary boundary}}
\DoxyCodeLine{451 \textcolor{comment}{                                                                       !! layer (left)              [H ~> m or kg m-2]}}
\DoxyCodeLine{452 \textcolor{keywordtype}{  real},                      \textcolor{keywordtype}{intent(in   )}       :: hbl\_R\textcolor{comment}{    !< Thickness of the boundary boundary}}
\DoxyCodeLine{453 \textcolor{comment}{                                                             !! layer (right)                       [H ~> m or kg m-2]}}
\DoxyCodeLine{454 \textcolor{keywordtype}{  real},                      \textcolor{keywordtype}{intent(in   )}       :: area\_L\textcolor{comment}{   !< Area of the horizontal grid (left)  [L2 ~> m2]}}
\DoxyCodeLine{455 \textcolor{keywordtype}{  real},                      \textcolor{keywordtype}{intent(in   )}       :: area\_R\textcolor{comment}{   !< Area of the horizontal grid (right) [L2 ~> m2]}}
\DoxyCodeLine{456 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(nk)},       \textcolor{keywordtype}{intent(in   )}       :: phi\_L\textcolor{comment}{    !< Tracer values (left)                [conc]}}
\DoxyCodeLine{457 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(nk)},       \textcolor{keywordtype}{intent(in   )}       :: phi\_R\textcolor{comment}{    !< Tracer values (right)               [conc]}}
\DoxyCodeLine{458 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(nk,deg+1)}, \textcolor{keywordtype}{intent(in   )}       :: ppoly0\_coefs\_L\textcolor{comment}{ !< Tracer reconstruction (left)  [conc]}}
\DoxyCodeLine{459 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(nk,deg+1)}, \textcolor{keywordtype}{intent(in   )}       :: ppoly0\_coefs\_R\textcolor{comment}{ !< Tracer reconstruction (right) [conc]}}
\DoxyCodeLine{460 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(nk,2)},     \textcolor{keywordtype}{intent(in   )}       :: ppoly0\_E\_L\textcolor{comment}{ !< Polynomial edge values (left)     [nondim]}}
\DoxyCodeLine{461 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(nk,2)},     \textcolor{keywordtype}{intent(in   )}       :: ppoly0\_E\_R\textcolor{comment}{ !< Polynomial edge values (right)    [nondim]}}
\DoxyCodeLine{462   \textcolor{keywordtype}{integer},                   \textcolor{keywordtype}{intent(in   )}       :: method\textcolor{comment}{   !< Method of polynomial integration    [nondim]}}
\DoxyCodeLine{463 \textcolor{keywordtype}{  real},                      \textcolor{keywordtype}{intent(in   )}       :: khtr\_u\textcolor{comment}{   !< Horizontal diffusivities times delta t}}
\DoxyCodeLine{464 \textcolor{comment}{                                                             !! at a velocity point [L2 ~> m2]}}
\DoxyCodeLine{465 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(nk)},       \textcolor{keywordtype}{intent(  out)}       :: F\_layer\textcolor{comment}{  !< Layerwise diffusive flux at U- or V-point}}
\DoxyCodeLine{466 \textcolor{comment}{                                                             !! [H L2 conc ~> m3 conc]}}
\DoxyCodeLine{467   \textcolor{keywordtype}{logical}, \textcolor{keywordtype}{optional},         \textcolor{keywordtype}{intent(in   )}       :: linear\_decay\textcolor{comment}{ !< If True, apply a linear transition at the base of}}
\DoxyCodeLine{468 \textcolor{comment}{                                                             !! the boundary layer}}
\DoxyCodeLine{469   \textcolor{comment}{! Local variables}}
\DoxyCodeLine{470 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(nk)} :: h\_means\textcolor{comment}{              !< Calculate the layer-wise harmonic means           [H ~> m or kg m-2]}}
\DoxyCodeLine{471 \textcolor{keywordtype}{  real}                :: khtr\_avg\textcolor{comment}{             !< Thickness-weighted diffusivity at the u-point     [m\string^2 s\string^-1]}}
\DoxyCodeLine{472 \textcolor{comment}{                                              !! This is just to remind developers that khtr\_avg should be}}
\DoxyCodeLine{473 \textcolor{comment}{                                              !! computed once khtr is 3D.}}
\DoxyCodeLine{474 \textcolor{keywordtype}{  real}                :: heff\textcolor{comment}{                 !< Harmonic mean of layer thicknesses           [H ~> m or kg m-2]}}
\DoxyCodeLine{475 \textcolor{keywordtype}{  real}                :: inv\_heff\textcolor{comment}{             !< Inverse of the harmonic mean of layer thicknesses}}
\DoxyCodeLine{476 \textcolor{comment}{                                              !!  [H-1 ~> m-1 or m2 kg-1]}}
\DoxyCodeLine{477 \textcolor{keywordtype}{  real}                :: phi\_L\_avg, phi\_R\_avg\textcolor{comment}{ !< Bulk, thickness-weighted tracer averages (left and right column)}}
\DoxyCodeLine{478 \textcolor{comment}{                                              !!                                                   [conc m\string^-3 ]}}
\DoxyCodeLine{479 \textcolor{keywordtype}{  real}    :: htot\textcolor{comment}{                      !< Total column thickness [H ~> m or kg m-2]}}
\DoxyCodeLine{480 \textcolor{keywordtype}{  real}    :: heff\_tot\textcolor{comment}{                  !< Total effective column thickness in the transition layer [m]}}
\DoxyCodeLine{481   \textcolor{keywordtype}{integer} :: k, k\_bot\_min, k\_top\_max\textcolor{comment}{   !< k-indices, min and max for bottom and top, respectively}}
\DoxyCodeLine{482   \textcolor{keywordtype}{integer} :: k\_bot\_max, k\_top\_min\textcolor{comment}{      !< k-indices, max and min for bottom and top, respectively}}
\DoxyCodeLine{483   \textcolor{keywordtype}{integer} :: k\_bot\_diff, k\_top\_diff\textcolor{comment}{    !< different between left and right k-indices for bottom and top, respectively}}
\DoxyCodeLine{484   \textcolor{keywordtype}{integer} :: k\_top\_L, k\_bot\_L\textcolor{comment}{          !< k-indices left}}
\DoxyCodeLine{485   \textcolor{keywordtype}{integer} :: k\_top\_R, k\_bot\_R\textcolor{comment}{          !< k-indices right}}
\DoxyCodeLine{486 \textcolor{keywordtype}{  real}    :: zeta\_top\_L, zeta\_top\_R\textcolor{comment}{    !< distance from the top of a layer to the boundary}}
\DoxyCodeLine{487 \textcolor{comment}{                                       !! layer depth                                     [nondim]}}
\DoxyCodeLine{488 \textcolor{keywordtype}{  real}    :: zeta\_bot\_L, zeta\_bot\_R\textcolor{comment}{    !< distance from the bottom of a layer to the boundary}}
\DoxyCodeLine{489 \textcolor{comment}{                                       !!layer depth                                      [nondim]}}
\DoxyCodeLine{490 \textcolor{keywordtype}{  real}    :: h\_work\_L, h\_work\_R\textcolor{comment}{  !< dummy variables}}
\DoxyCodeLine{491 \textcolor{keywordtype}{  real}    :: hbl\_min\textcolor{comment}{             !< minimum BLD (left and right)                          [m]}}
\DoxyCodeLine{492 \textcolor{keywordtype}{  real}    :: wgt\textcolor{comment}{                 !< weight to be used in the linear transition to the interior [nondim]}}
\DoxyCodeLine{493 \textcolor{keywordtype}{  real}    :: a\textcolor{comment}{                   !< coefficient to be used in the linear transition to the interior [nondim]}}
\DoxyCodeLine{494   \textcolor{keywordtype}{logical} :: linear\textcolor{comment}{              !< True if apply a linear transition}}
\DoxyCodeLine{495 }
\DoxyCodeLine{496   f\_layer(:) = 0.0}
\DoxyCodeLine{497   \textcolor{keywordflow}{if} (hbl\_l == 0. .or. hbl\_r == 0.) \textcolor{keywordflow}{then}}
\DoxyCodeLine{498     \textcolor{keywordflow}{return}}
\DoxyCodeLine{499 \textcolor{keywordflow}{  endif}}
\DoxyCodeLine{500 }
\DoxyCodeLine{501   linear = .false.}
\DoxyCodeLine{502   \textcolor{keywordflow}{if} (\textcolor{keyword}{PRESENT}(linear\_decay)) \textcolor{keywordflow}{then}}
\DoxyCodeLine{503     linear = linear\_decay}
\DoxyCodeLine{504 \textcolor{keywordflow}{  endif}}
\DoxyCodeLine{505 }
\DoxyCodeLine{506   \textcolor{comment}{! Calculate vertical indices containing the boundary layer}}
\DoxyCodeLine{507   \textcolor{keyword}{call }boundary\_k\_range(boundary, nk, h\_l, hbl\_l, k\_top\_l, zeta\_top\_l, k\_bot\_l, zeta\_bot\_l)}
\DoxyCodeLine{508   \textcolor{keyword}{call }boundary\_k\_range(boundary, nk, h\_r, hbl\_r, k\_top\_r, zeta\_top\_r, k\_bot\_r, zeta\_bot\_r)}
\DoxyCodeLine{509 }
\DoxyCodeLine{510   \textcolor{keywordflow}{if} (boundary == surface) \textcolor{keywordflow}{then}}
\DoxyCodeLine{511     k\_bot\_min = min(k\_bot\_l, k\_bot\_r)}
\DoxyCodeLine{512     k\_bot\_max = max(k\_bot\_l, k\_bot\_r)}
\DoxyCodeLine{513     k\_bot\_diff = (k\_bot\_max - k\_bot\_min)}
\DoxyCodeLine{514 }
\DoxyCodeLine{515     \textcolor{comment}{! make sure left and right k indices span same range}}
\DoxyCodeLine{516     \textcolor{keywordflow}{if} (k\_bot\_min .ne. k\_bot\_l) \textcolor{keywordflow}{then}}
\DoxyCodeLine{517       k\_bot\_l = k\_bot\_min}
\DoxyCodeLine{518       zeta\_bot\_l = 1.0}
\DoxyCodeLine{519 \textcolor{keywordflow}{    endif}}
\DoxyCodeLine{520     \textcolor{keywordflow}{if} (k\_bot\_min .ne. k\_bot\_r) \textcolor{keywordflow}{then}}
\DoxyCodeLine{521       k\_bot\_r= k\_bot\_min}
\DoxyCodeLine{522       zeta\_bot\_r = 1.0}
\DoxyCodeLine{523 \textcolor{keywordflow}{    endif}}
\DoxyCodeLine{524 }
\DoxyCodeLine{525     h\_work\_l = (h\_l(k\_bot\_l) * zeta\_bot\_l)}
\DoxyCodeLine{526     h\_work\_r = (h\_r(k\_bot\_r) * zeta\_bot\_r)}
\DoxyCodeLine{527 }
\DoxyCodeLine{528     phi\_l\_avg = average\_value\_ppoly( nk, phi\_l, ppoly0\_e\_l, ppoly0\_coefs\_l, method, k\_bot\_l, 0., zeta\_bot\_l)}
\DoxyCodeLine{529     phi\_r\_avg = average\_value\_ppoly( nk, phi\_r, ppoly0\_e\_r, ppoly0\_coefs\_r, method, k\_bot\_r, 0., zeta\_bot\_r)}
\DoxyCodeLine{530     heff = harmonic\_mean(h\_work\_l, h\_work\_r)}
\DoxyCodeLine{531     \textcolor{comment}{! tracer flux where the minimum BLD intersets layer}}
\DoxyCodeLine{532     \textcolor{comment}{! GMM, khtr\_avg should be computed once khtr is 3D}}
\DoxyCodeLine{533     \textcolor{keywordflow}{if} ((linear) .and. (k\_bot\_diff .gt. 1)) \textcolor{keywordflow}{then}}
\DoxyCodeLine{534       \textcolor{comment}{! apply linear decay at the base of hbl}}
\DoxyCodeLine{535       \textcolor{keywordflow}{do} k = k\_bot\_min,1,-1}
\DoxyCodeLine{536         heff = harmonic\_mean(h\_l(k), h\_r(k))}
\DoxyCodeLine{537         f\_layer(k) = -(heff * khtr\_u) * (phi\_r(k) - phi\_l(k))}
\DoxyCodeLine{538 \textcolor{keywordflow}{      enddo}}
\DoxyCodeLine{539       \textcolor{comment}{! heff\_total}}
\DoxyCodeLine{540       heff\_tot = 0.0}
\DoxyCodeLine{541       \textcolor{keywordflow}{do} k = k\_bot\_min+1,k\_bot\_max, 1}
\DoxyCodeLine{542         heff\_tot = heff\_tot + harmonic\_mean(h\_l(k), h\_r(k))}
\DoxyCodeLine{543 \textcolor{keywordflow}{      enddo}}
\DoxyCodeLine{544 }
\DoxyCodeLine{545       a = -1.0/heff\_tot}
\DoxyCodeLine{546       heff\_tot = 0.0}
\DoxyCodeLine{547       \textcolor{keywordflow}{do} k = k\_bot\_min+1,k\_bot\_max, 1}
\DoxyCodeLine{548         heff = harmonic\_mean(h\_l(k), h\_r(k))}
\DoxyCodeLine{549         wgt = (a*(heff\_tot + (heff * 0.5))) + 1.0}
\DoxyCodeLine{550         f\_layer(k) = -(heff * khtr\_u) * (phi\_r(k) - phi\_l(k)) * wgt}
\DoxyCodeLine{551         heff\_tot = heff\_tot + heff}
\DoxyCodeLine{552 \textcolor{keywordflow}{      enddo}}
\DoxyCodeLine{553     \textcolor{keywordflow}{else}}
\DoxyCodeLine{554       f\_layer(k\_bot\_min) = -(heff * khtr\_u) * (phi\_r\_avg - phi\_l\_avg)}
\DoxyCodeLine{555       \textcolor{keywordflow}{do} k = k\_bot\_min-1,1,-1}
\DoxyCodeLine{556         heff = harmonic\_mean(h\_l(k), h\_r(k))}
\DoxyCodeLine{557         f\_layer(k) = -(heff * khtr\_u) * (phi\_r(k) - phi\_l(k))}
\DoxyCodeLine{558 \textcolor{keywordflow}{      enddo}}
\DoxyCodeLine{559 \textcolor{keywordflow}{    endif}}
\DoxyCodeLine{560 \textcolor{keywordflow}{  endif}}
\DoxyCodeLine{561 }
\DoxyCodeLine{562   \textcolor{keywordflow}{if} (boundary == bottom) \textcolor{keywordflow}{then}}
\DoxyCodeLine{563     \textcolor{comment}{! TODO: GMM add option to apply linear decay}}
\DoxyCodeLine{564     k\_top\_max = max(k\_top\_l, k\_top\_r)}
\DoxyCodeLine{565     \textcolor{comment}{! make sure left and right k indices span same range}}
\DoxyCodeLine{566     \textcolor{keywordflow}{if} (k\_top\_max .ne. k\_top\_l) \textcolor{keywordflow}{then}}
\DoxyCodeLine{567       k\_top\_l = k\_top\_max}
\DoxyCodeLine{568       zeta\_top\_l = 1.0}
\DoxyCodeLine{569 \textcolor{keywordflow}{    endif}}
\DoxyCodeLine{570     \textcolor{keywordflow}{if} (k\_top\_max .ne. k\_top\_r) \textcolor{keywordflow}{then}}
\DoxyCodeLine{571       k\_top\_r= k\_top\_max}
\DoxyCodeLine{572       zeta\_top\_r = 1.0}
\DoxyCodeLine{573 \textcolor{keywordflow}{    endif}}
\DoxyCodeLine{574 }
\DoxyCodeLine{575     h\_work\_l = (h\_l(k\_top\_l) * zeta\_top\_l)}
\DoxyCodeLine{576     h\_work\_r = (h\_r(k\_top\_r) * zeta\_top\_r)}
\DoxyCodeLine{577 }
\DoxyCodeLine{578     phi\_l\_avg = average\_value\_ppoly( nk, phi\_l, ppoly0\_e\_l, ppoly0\_coefs\_l, method, k\_top\_l, 1.0-zeta\_top\_l, 1.0)}
\DoxyCodeLine{579     phi\_r\_avg = average\_value\_ppoly( nk, phi\_r, ppoly0\_e\_r, ppoly0\_coefs\_r, method, k\_top\_r, 1.0-zeta\_top\_r, 1.0)}
\DoxyCodeLine{580     heff = harmonic\_mean(h\_work\_l, h\_work\_r)}
\DoxyCodeLine{581 }
\DoxyCodeLine{582     \textcolor{comment}{! tracer flux where the minimum BLD intersets layer}}
\DoxyCodeLine{583     f\_layer(k\_top\_max) = (-heff * khtr\_u) * (phi\_r\_avg - phi\_l\_avg)}
\DoxyCodeLine{584 }
\DoxyCodeLine{585     \textcolor{keywordflow}{do} k = k\_top\_max+1,nk}
\DoxyCodeLine{586       heff = harmonic\_mean(h\_l(k), h\_r(k))}
\DoxyCodeLine{587       f\_layer(k) = -(heff * khtr\_u) * (phi\_r(k) - phi\_l(k))}
\DoxyCodeLine{588 \textcolor{keywordflow}{    enddo}}
\DoxyCodeLine{589 \textcolor{keywordflow}{  endif}}
\DoxyCodeLine{590 }

\end{DoxyCode}
\mbox{\Hypertarget{namespacemom__lateral__boundary__diffusion_a6c98f54ad462ab45918fdccc0b403948}\label{namespacemom__lateral__boundary__diffusion_a6c98f54ad462ab45918fdccc0b403948}} 
\index{mom\_lateral\_boundary\_diffusion@{mom\_lateral\_boundary\_diffusion}!harmonic\_mean@{harmonic\_mean}}
\index{harmonic\_mean@{harmonic\_mean}!mom\_lateral\_boundary\_diffusion@{mom\_lateral\_boundary\_diffusion}}
\subsubsection{\texorpdfstring{harmonic\_mean()}{harmonic\_mean()}}
{\footnotesize\ttfamily real function mom\+\_\+lateral\+\_\+boundary\+\_\+diffusion\+::harmonic\+\_\+mean (\begin{DoxyParamCaption}\item[{real}]{h1,  }\item[{real}]{h2 }\end{DoxyParamCaption})\hspace{0.3cm}{\ttfamily [private]}}



Calculate the harmonic mean of two quantities See \mbox{\hyperlink{namespacemom__lateral__boundary__diffusion_section_harmonic_mean}{Harmonic Mean}}. 


\begin{DoxyParams}{Parameters}
{\em h1} & Scalar quantity \\
\hline
{\em h2} & Scalar quantity \\
\hline
\end{DoxyParams}


Definition at line 364 of file M\+O\+M\+\_\+lateral\+\_\+boundary\+\_\+diffusion.\+F90.


\begin{DoxyCode}{0}
\DoxyCodeLine{364 \textcolor{keywordtype}{  real} :: h1\textcolor{comment}{ !< Scalar quantity}}
\DoxyCodeLine{365 \textcolor{keywordtype}{  real} :: h2\textcolor{comment}{ !< Scalar quantity}}
\DoxyCodeLine{366   \textcolor{keywordflow}{if} (h1 + h2 == 0.) \textcolor{keywordflow}{then}}
\DoxyCodeLine{367     harmonic\_mean = 0.}
\DoxyCodeLine{368   \textcolor{keywordflow}{else}}
\DoxyCodeLine{369     harmonic\_mean = 2.*(h1*h2)/(h1+h2)}
\DoxyCodeLine{370 \textcolor{keywordflow}{  endif}}

\end{DoxyCode}
\mbox{\Hypertarget{namespacemom__lateral__boundary__diffusion_afac71bffe2368a84b543f4d7f60703e0}\label{namespacemom__lateral__boundary__diffusion_afac71bffe2368a84b543f4d7f60703e0}} 
\index{mom\_lateral\_boundary\_diffusion@{mom\_lateral\_boundary\_diffusion}!lateral\_boundary\_diffusion@{lateral\_boundary\_diffusion}}
\index{lateral\_boundary\_diffusion@{lateral\_boundary\_diffusion}!mom\_lateral\_boundary\_diffusion@{mom\_lateral\_boundary\_diffusion}}
\subsubsection{\texorpdfstring{lateral\_boundary\_diffusion()}{lateral\_boundary\_diffusion()}}
{\footnotesize\ttfamily subroutine, public mom\+\_\+lateral\+\_\+boundary\+\_\+diffusion\+::lateral\+\_\+boundary\+\_\+diffusion (\begin{DoxyParamCaption}\item[{type(ocean\+\_\+grid\+\_\+type), intent(inout)}]{G,  }\item[{type(verticalgrid\+\_\+type), intent(in)}]{GV,  }\item[{type(unit\+\_\+scale\+\_\+type), intent(in)}]{US,  }\item[{real, dimension( g \%isd\+: g \%ied, g \%jsd\+: g \%jed, g \%ke), intent(in)}]{h,  }\item[{real, dimension( g \%isdb\+: g \%iedb, g \%jsd\+: g \%jed), intent(in)}]{Coef\+\_\+x,  }\item[{real, dimension( g \%isd\+: g \%ied, g \%jsdb\+: g \%jedb), intent(in)}]{Coef\+\_\+y,  }\item[{real, intent(in)}]{dt,  }\item[{type(tracer\+\_\+registry\+\_\+type), pointer}]{Reg,  }\item[{type(\mbox{\hyperlink{structmom__lateral__boundary__diffusion_1_1lateral__boundary__diffusion__cs}{lateral\+\_\+boundary\+\_\+diffusion\+\_\+cs}}), intent(in)}]{CS }\end{DoxyParamCaption})}



Driver routine for calculating lateral diffusive fluxes near the top and bottom boundaries. Two different methods are available\+: Method 1\+: lower order representation, calculate fluxes from bulk layer integrated quantities. Method 2\+: more straight forward, diffusion is applied layer by layer using only information from neighboring cells. 


\begin{DoxyParams}[1]{Parameters}
\mbox{\texttt{ in,out}}  & {\em g} & Grid type \\
\hline
\mbox{\texttt{ in}}  & {\em gv} & ocean vertical grid structure \\
\hline
\mbox{\texttt{ in}}  & {\em us} & A dimensional unit scaling type \\
\hline
\mbox{\texttt{ in}}  & {\em h} & Layer thickness \mbox{[}H $\sim$$>$ m or kg m-\/2\mbox{]} \\
\hline
\mbox{\texttt{ in}}  & {\em coef\+\_\+x} & dt $\ast$ Kh $\ast$ dy / dx at u-\/points \mbox{[}L2 $\sim$$>$ m2\mbox{]} \\
\hline
\mbox{\texttt{ in}}  & {\em coef\+\_\+y} & dt $\ast$ Kh $\ast$ dx / dy at v-\/points \mbox{[}L2 $\sim$$>$ m2\mbox{]} \\
\hline
\mbox{\texttt{ in}}  & {\em dt} & Tracer time step $\ast$ I\+\_\+numitts (I\+\_\+numitts in tracer\+\_\+hordiff) \\
\hline
 & {\em reg} & Tracer registry \\
\hline
\mbox{\texttt{ in}}  & {\em cs} & Control structure for this module \\
\hline
\end{DoxyParams}


Definition at line 138 of file M\+O\+M\+\_\+lateral\+\_\+boundary\+\_\+diffusion.\+F90.


\begin{DoxyCode}{0}
\DoxyCodeLine{138   \textcolor{keywordtype}{type}(ocean\_grid\_type),                \textcolor{keywordtype}{intent(inout)} :: G\textcolor{comment}{   !< Grid type}}
\DoxyCodeLine{139   \textcolor{keywordtype}{type}(verticalGrid\_type),              \textcolor{keywordtype}{intent(in)}    :: GV\textcolor{comment}{  !< ocean vertical grid structure}}
\DoxyCodeLine{140   \textcolor{keywordtype}{type}(unit\_scale\_type),                \textcolor{keywordtype}{intent(in)}    :: US\textcolor{comment}{  !< A dimensional unit scaling type}}
\DoxyCodeLine{141 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(SZI\_(G),SZJ\_(G),SZK\_(G))}, \&}
\DoxyCodeLine{142                                         \textcolor{keywordtype}{intent(in)}    :: h\textcolor{comment}{      !< Layer thickness [H ~> m or kg m-2]}}
\DoxyCodeLine{143 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(SZIB\_(G),SZJ\_(G))},    \textcolor{keywordtype}{intent(in)}    :: Coef\_x\textcolor{comment}{ !< dt * Kh * dy / dx at u-points [L2 ~> m2]}}
\DoxyCodeLine{144 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(SZI\_(G),SZJB\_(G))},    \textcolor{keywordtype}{intent(in)}    :: Coef\_y\textcolor{comment}{ !< dt * Kh * dx / dy at v-points [L2 ~> m2]}}
\DoxyCodeLine{145 \textcolor{keywordtype}{  real},                                 \textcolor{keywordtype}{intent(in)}    :: dt\textcolor{comment}{     !< Tracer time step * I\_numitts}}
\DoxyCodeLine{146 \textcolor{comment}{                                                                !! (I\_numitts in tracer\_hordiff)}}
\DoxyCodeLine{147   \textcolor{keywordtype}{type}(tracer\_registry\_type),           \textcolor{keywordtype}{pointer}       :: Reg\textcolor{comment}{    !< Tracer registry}}
\DoxyCodeLine{148   \textcolor{keywordtype}{type}(lateral\_boundary\_diffusion\_CS),  \textcolor{keywordtype}{intent(in)}    :: CS\textcolor{comment}{     !< Control structure for this module}}
\DoxyCodeLine{149 }
\DoxyCodeLine{150   \textcolor{comment}{! Local variables}}
\DoxyCodeLine{151 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(SZI\_(G),SZJ\_(G))} :: hbl\textcolor{comment}{                           !< bnd. layer depth [H ~> m or kg m-2]}}
\DoxyCodeLine{152 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(SZI\_(G),SZJ\_(G),SZK\_(G),CS\%deg+1)} :: ppoly0\_coefs\textcolor{comment}{ !< Coefficients of polynomial}}
\DoxyCodeLine{153 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(SZI\_(G),SZJ\_(G),SZK\_(G),2)}        :: ppoly0\_E\textcolor{comment}{     !< Edge values from reconstructions}}
\DoxyCodeLine{154 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(SZK\_(G),CS\%deg+1)}                 :: ppoly\_S\textcolor{comment}{      !< Slopes from reconstruction (placeholder)}}
\DoxyCodeLine{155 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(SZIB\_(G),SZJ\_(G),SZK\_(G))} :: uFlx\textcolor{comment}{        !< Zonal flux of tracer [conc m\string^3]}}
\DoxyCodeLine{156 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(SZIB\_(G),SZJ\_(G))}         :: uFLx\_bulk\textcolor{comment}{   !< Total calculated bulk-layer u-flux for the tracer}}
\DoxyCodeLine{157 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(SZI\_(G),SZJB\_(G),SZK\_(G))} :: vFlx\textcolor{comment}{        !< Meridional flux of tracer [conc m\string^3]}}
\DoxyCodeLine{158 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(SZI\_(G),SZJB\_(G))}         :: vFlx\_bulk\textcolor{comment}{   !< Total calculated bulk-layer v-flux for the tracer}}
\DoxyCodeLine{159 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(SZIB\_(G),SZJ\_(G))}         :: uwork\_2d\textcolor{comment}{    !< Layer summed u-flux transport}}
\DoxyCodeLine{160 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(SZI\_(G),SZJB\_(G))}         :: vwork\_2d\textcolor{comment}{    !< Layer summed v-flux transport}}
\DoxyCodeLine{161 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(SZI\_(G),SZJ\_(G),G\%ke)}     :: tendency\textcolor{comment}{    !< tendency array for diagn}}
\DoxyCodeLine{162 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(SZI\_(G),SZJ\_(G))}          :: tendency\_2d\textcolor{comment}{ !< depth integrated content tendency for diagn}}
\DoxyCodeLine{163   \textcolor{keywordtype}{type}(tracer\_type), \textcolor{keywordtype}{pointer}                :: Tracer => null() \textcolor{comment}{!< Pointer to the current tracer}}
\DoxyCodeLine{164   \textcolor{keywordtype}{integer} :: remap\_method\textcolor{comment}{ !< Reconstruction method}}
\DoxyCodeLine{165   \textcolor{keywordtype}{integer} :: i,j,k,m\textcolor{comment}{      !< indices to loop over}}
\DoxyCodeLine{166 \textcolor{keywordtype}{  real}    :: Idt\textcolor{comment}{          !< inverse of the time step [s-1]}}
\DoxyCodeLine{167 }
\DoxyCodeLine{168   idt = 1./dt}
\DoxyCodeLine{169   hbl(:,:) = 0.}
\DoxyCodeLine{170   \textcolor{keywordflow}{if} (\textcolor{keyword}{ASSOCIATED}(cs\%KPP\_CSp)) \textcolor{keyword}{call }kpp\_get\_bld(cs\%KPP\_CSp, hbl, g, us, m\_to\_bld\_units=gv\%m\_to\_H)}
\DoxyCodeLine{171   \textcolor{keywordflow}{if} (\textcolor{keyword}{ASSOCIATED}(cs\%energetic\_PBL\_CSp)) \&}
\DoxyCodeLine{172     \textcolor{keyword}{call }energetic\_pbl\_get\_mld(cs\%energetic\_PBL\_CSp, hbl, g, us, m\_to\_mld\_units=gv\%m\_to\_H)}
\DoxyCodeLine{173 }
\DoxyCodeLine{174   \textcolor{keyword}{call }pass\_var(hbl,g\%Domain)}
\DoxyCodeLine{175   \textcolor{keywordflow}{do} m = 1,reg\%ntr}
\DoxyCodeLine{176     tracer => reg\%tr(m)}
\DoxyCodeLine{177 }
\DoxyCodeLine{178     \textcolor{comment}{! for diagnostics}}
\DoxyCodeLine{179     \textcolor{keywordflow}{if} (tracer\%id\_lbdxy\_conc > 0 .or. tracer\%id\_lbdxy\_cont > 0 .or. tracer\%id\_lbdxy\_cont\_2d > 0) \textcolor{keywordflow}{then}}
\DoxyCodeLine{180       tendency(:,:,:) = 0.0}
\DoxyCodeLine{181 \textcolor{keywordflow}{    endif}}
\DoxyCodeLine{182 }
\DoxyCodeLine{183     \textcolor{comment}{! Interpolate state to interface}}
\DoxyCodeLine{184     \textcolor{keywordflow}{do} j=g\%jsc-1,g\%jec+1 ; \textcolor{keywordflow}{do} i=g\%isc-1,g\%iec+1}
\DoxyCodeLine{185       \textcolor{keyword}{call }build\_reconstructions\_1d( cs\%remap\_CS, g\%ke, h(i,j,:), tracer\%t(i,j,:), ppoly0\_coefs(i,j,:,:), \&}
\DoxyCodeLine{186                                      ppoly0\_e(i,j,:,:), ppoly\_s, remap\_method, gv\%H\_subroundoff, gv\%H\_subroundoff)}
\DoxyCodeLine{187 \textcolor{keywordflow}{    enddo} ;\textcolor{keywordflow}{ enddo}}
\DoxyCodeLine{188 }
\DoxyCodeLine{189     \textcolor{comment}{! Diffusive fluxes in the i-direction}}
\DoxyCodeLine{190     uflx(:,:,:) = 0.}
\DoxyCodeLine{191     vflx(:,:,:) = 0.}
\DoxyCodeLine{192     uflx\_bulk(:,:) = 0.}
\DoxyCodeLine{193     vflx\_bulk(:,:) = 0.}
\DoxyCodeLine{194 }
\DoxyCodeLine{195     \textcolor{comment}{! Method \#1 (layer by layer)}}
\DoxyCodeLine{196     \textcolor{keywordflow}{if} (cs\%method == 1) \textcolor{keywordflow}{then}}
\DoxyCodeLine{197       \textcolor{keywordflow}{do} j=g\%jsc,g\%jec}
\DoxyCodeLine{198         \textcolor{keywordflow}{do} i=g\%isc-1,g\%iec}
\DoxyCodeLine{199           \textcolor{keywordflow}{if} (g\%mask2dCu(i,j)>0.) \textcolor{keywordflow}{then}}
\DoxyCodeLine{200             \textcolor{keyword}{call }fluxes\_layer\_method(surface, gv\%ke, cs\%deg, h(i,j,:), h(i+1,j,:), hbl(i,j), hbl(i+1,j),  \&}
\DoxyCodeLine{201               g\%areaT(i,j), g\%areaT(i+1,j), tracer\%t(i,j,:), tracer\%t(i+1,j,:), ppoly0\_coefs(i,j,:,:),    \&}
\DoxyCodeLine{202               ppoly0\_coefs(i+1,j,:,:), ppoly0\_e(i,j,:,:), ppoly0\_e(i+1,j,:,:), remap\_method, coef\_x(i,j), \&}
\DoxyCodeLine{203               uflx(i,j,:), cs\%linear)}
\DoxyCodeLine{204 \textcolor{keywordflow}{          endif}}
\DoxyCodeLine{205 \textcolor{keywordflow}{        enddo}}
\DoxyCodeLine{206 \textcolor{keywordflow}{      enddo}}
\DoxyCodeLine{207       \textcolor{keywordflow}{do} j=g\%jsc-1,g\%jec}
\DoxyCodeLine{208         \textcolor{keywordflow}{do} i=g\%isc,g\%iec}
\DoxyCodeLine{209           \textcolor{keywordflow}{if} (g\%mask2dCv(i,j)>0.) \textcolor{keywordflow}{then}}
\DoxyCodeLine{210             \textcolor{keyword}{call }fluxes\_layer\_method(surface, gv\%ke, cs\%deg, h(i,j,:), h(i,j+1,:), hbl(i,j), hbl(i,j+1),  \&}
\DoxyCodeLine{211               g\%areaT(i,j), g\%areaT(i,j+1), tracer\%t(i,j,:), tracer\%t(i,j+1,:), ppoly0\_coefs(i,j,:,:),    \&}
\DoxyCodeLine{212               ppoly0\_coefs(i,j+1,:,:), ppoly0\_e(i,j,:,:), ppoly0\_e(i,j+1,:,:), remap\_method, coef\_y(i,j), \&}
\DoxyCodeLine{213               vflx(i,j,:), cs\%linear)}
\DoxyCodeLine{214 \textcolor{keywordflow}{          endif}}
\DoxyCodeLine{215 \textcolor{keywordflow}{        enddo}}
\DoxyCodeLine{216 \textcolor{keywordflow}{      enddo}}
\DoxyCodeLine{217 }
\DoxyCodeLine{218     \textcolor{comment}{! Method \#2 (bulk approach)}}
\DoxyCodeLine{219     \textcolor{keywordflow}{elseif} (cs\%method == 2) \textcolor{keywordflow}{then}}
\DoxyCodeLine{220       \textcolor{keywordflow}{do} j=g\%jsc,g\%jec}
\DoxyCodeLine{221         \textcolor{keywordflow}{do} i=g\%isc-1,g\%iec}
\DoxyCodeLine{222           \textcolor{keywordflow}{if} (g\%mask2dCu(i,j)>0.) \textcolor{keywordflow}{then}}
\DoxyCodeLine{223             \textcolor{keyword}{call }fluxes\_bulk\_method(surface, gv\%ke, cs\%deg, h(i,j,:), h(i+1,j,:), hbl(i,j), hbl(i+1,j), \&}
\DoxyCodeLine{224               g\%areaT(i,j), g\%areaT(i+1,j), tracer\%t(i,j,:), tracer\%t(i+1,j,:),                         \&}
\DoxyCodeLine{225               ppoly0\_coefs(i,j,:,:), ppoly0\_coefs(i+1,j,:,:), ppoly0\_e(i,j,:,:),                        \&}
\DoxyCodeLine{226               ppoly0\_e(i+1,j,:,:), remap\_method, coef\_x(i,j), uflx\_bulk(i,j), uflx(i,j,:), cs\%limiter,  \&}
\DoxyCodeLine{227               cs\%linear)}
\DoxyCodeLine{228 \textcolor{keywordflow}{          endif}}
\DoxyCodeLine{229 \textcolor{keywordflow}{        enddo}}
\DoxyCodeLine{230 \textcolor{keywordflow}{      enddo}}
\DoxyCodeLine{231       \textcolor{keywordflow}{do} j=g\%jsc-1,g\%jec}
\DoxyCodeLine{232         \textcolor{keywordflow}{do} i=g\%isc,g\%iec}
\DoxyCodeLine{233           \textcolor{keywordflow}{if} (g\%mask2dCv(i,j)>0.) \textcolor{keywordflow}{then}}
\DoxyCodeLine{234             \textcolor{keyword}{call }fluxes\_bulk\_method(surface, gv\%ke, cs\%deg, h(i,j,:), h(i,j+1,:), hbl(i,j), hbl(i,j+1), \&}
\DoxyCodeLine{235               g\%areaT(i,j), g\%areaT(i,j+1), tracer\%t(i,j,:), tracer\%t(i,j+1,:),                         \&}
\DoxyCodeLine{236               ppoly0\_coefs(i,j,:,:), ppoly0\_coefs(i,j+1,:,:), ppoly0\_e(i,j,:,:),                        \&}
\DoxyCodeLine{237               ppoly0\_e(i,j+1,:,:), remap\_method, coef\_y(i,j), vflx\_bulk(i,j), vflx(i,j,:), cs\%limiter,  \&}
\DoxyCodeLine{238               cs\%linear)}
\DoxyCodeLine{239 \textcolor{keywordflow}{          endif}}
\DoxyCodeLine{240 \textcolor{keywordflow}{        enddo}}
\DoxyCodeLine{241 \textcolor{keywordflow}{      enddo}}
\DoxyCodeLine{242       \textcolor{comment}{! Post tracer bulk diags}}
\DoxyCodeLine{243       \textcolor{keywordflow}{if} (tracer\%id\_lbd\_bulk\_dfx>0) \textcolor{keyword}{call }post\_data(tracer\%id\_lbd\_bulk\_dfx, uflx\_bulk*idt, cs\%diag)}
\DoxyCodeLine{244       \textcolor{keywordflow}{if} (tracer\%id\_lbd\_bulk\_dfy>0) \textcolor{keyword}{call }post\_data(tracer\%id\_lbd\_bulk\_dfy, vflx\_bulk*idt, cs\%diag)}
\DoxyCodeLine{245 \textcolor{keywordflow}{    endif}}
\DoxyCodeLine{246 }
\DoxyCodeLine{247     \textcolor{comment}{! Update the tracer fluxes}}
\DoxyCodeLine{248     \textcolor{keywordflow}{do} k=1,gv\%ke ; \textcolor{keywordflow}{do} j=g\%jsc,g\%jec ; \textcolor{keywordflow}{do} i=g\%isc,g\%iec}
\DoxyCodeLine{249       \textcolor{keywordflow}{if} (g\%mask2dT(i,j)>0.) \textcolor{keywordflow}{then}}
\DoxyCodeLine{250         tracer\%t(i,j,k) = tracer\%t(i,j,k) + (( (uflx(i-1,j,k)-uflx(i,j,k)) ) + ( (vflx(i,j-1,k)-vflx(i,j,k) ) ))* \&}
\DoxyCodeLine{251                           (g\%IareaT(i,j)/( h(i,j,k) + gv\%H\_subroundoff))}
\DoxyCodeLine{252 }
\DoxyCodeLine{253         \textcolor{keywordflow}{if} (tracer\%id\_lbdxy\_conc > 0  .or. tracer\%id\_lbdxy\_cont > 0 .or. tracer\%id\_lbdxy\_cont\_2d > 0 ) \textcolor{keywordflow}{then}}
\DoxyCodeLine{254           tendency(i,j,k) = (( (uflx(i-1,j,k)-uflx(i,j,k)) ) + ( (vflx(i,j-1,k)-vflx(i,j,k) ) )) * g\%IareaT(i,j) * idt}
\DoxyCodeLine{255 \textcolor{keywordflow}{        endif}}
\DoxyCodeLine{256 }
\DoxyCodeLine{257 \textcolor{keywordflow}{      endif}}
\DoxyCodeLine{258 \textcolor{keywordflow}{    enddo} ;\textcolor{keywordflow}{ enddo} ;\textcolor{keywordflow}{ enddo}}
\DoxyCodeLine{259 }
\DoxyCodeLine{260     \textcolor{comment}{! Post the tracer diagnostics}}
\DoxyCodeLine{261     \textcolor{keywordflow}{if} (tracer\%id\_lbd\_dfx>0)      \textcolor{keyword}{call }post\_data(tracer\%id\_lbd\_dfx, uflx*idt, cs\%diag)}
\DoxyCodeLine{262     \textcolor{keywordflow}{if} (tracer\%id\_lbd\_dfy>0)      \textcolor{keyword}{call }post\_data(tracer\%id\_lbd\_dfy, vflx*idt, cs\%diag)}
\DoxyCodeLine{263     \textcolor{keywordflow}{if} (tracer\%id\_lbd\_dfx\_2d>0) \textcolor{keywordflow}{then}}
\DoxyCodeLine{264       uwork\_2d(:,:) = 0.}
\DoxyCodeLine{265       \textcolor{keywordflow}{do} k=1,gv\%ke ; \textcolor{keywordflow}{do} j=g\%jsc,g\%jec ; \textcolor{keywordflow}{do} i=g\%isc-1,g\%iec}
\DoxyCodeLine{266         uwork\_2d(i,j) = uwork\_2d(i,j) + (uflx(i,j,k) * idt)}
\DoxyCodeLine{267 \textcolor{keywordflow}{      enddo} ;\textcolor{keywordflow}{ enddo} ;\textcolor{keywordflow}{ enddo}}
\DoxyCodeLine{268       \textcolor{keyword}{call }post\_data(tracer\%id\_lbd\_dfx\_2d, uwork\_2d, cs\%diag)}
\DoxyCodeLine{269 \textcolor{keywordflow}{    endif}}
\DoxyCodeLine{270 }
\DoxyCodeLine{271     \textcolor{keywordflow}{if} (tracer\%id\_lbd\_dfy\_2d>0) \textcolor{keywordflow}{then}}
\DoxyCodeLine{272       vwork\_2d(:,:) = 0.}
\DoxyCodeLine{273       \textcolor{keywordflow}{do} k=1,gv\%ke ; \textcolor{keywordflow}{do} j=g\%jsc-1,g\%jec ; \textcolor{keywordflow}{do} i=g\%isc,g\%iec}
\DoxyCodeLine{274         vwork\_2d(i,j) = vwork\_2d(i,j) + (vflx(i,j,k) * idt)}
\DoxyCodeLine{275 \textcolor{keywordflow}{      enddo} ;\textcolor{keywordflow}{ enddo} ;\textcolor{keywordflow}{ enddo}}
\DoxyCodeLine{276       \textcolor{keyword}{call }post\_data(tracer\%id\_lbd\_dfy\_2d, vwork\_2d, cs\%diag)}
\DoxyCodeLine{277 \textcolor{keywordflow}{    endif}}
\DoxyCodeLine{278 }
\DoxyCodeLine{279     \textcolor{comment}{! post tendency of tracer content}}
\DoxyCodeLine{280     \textcolor{keywordflow}{if} (tracer\%id\_lbdxy\_cont > 0) \textcolor{keywordflow}{then}}
\DoxyCodeLine{281       \textcolor{keyword}{call }post\_data(tracer\%id\_lbdxy\_cont, tendency, cs\%diag)}
\DoxyCodeLine{282 \textcolor{keywordflow}{    endif}}
\DoxyCodeLine{283 }
\DoxyCodeLine{284     \textcolor{comment}{! post depth summed tendency for tracer content}}
\DoxyCodeLine{285     \textcolor{keywordflow}{if} (tracer\%id\_lbdxy\_cont\_2d > 0) \textcolor{keywordflow}{then}}
\DoxyCodeLine{286       tendency\_2d(:,:) = 0.}
\DoxyCodeLine{287       \textcolor{keywordflow}{do} j=g\%jsc,g\%jec ; \textcolor{keywordflow}{do} i=g\%isc,g\%iec}
\DoxyCodeLine{288         \textcolor{keywordflow}{do} k=1,gv\%ke}
\DoxyCodeLine{289           tendency\_2d(i,j) = tendency\_2d(i,j) + tendency(i,j,k)}
\DoxyCodeLine{290 \textcolor{keywordflow}{        enddo}}
\DoxyCodeLine{291 \textcolor{keywordflow}{      enddo} ;\textcolor{keywordflow}{ enddo}}
\DoxyCodeLine{292       \textcolor{keyword}{call }post\_data(tracer\%id\_lbdxy\_cont\_2d, tendency\_2d, cs\%diag)}
\DoxyCodeLine{293 \textcolor{keywordflow}{    endif}}
\DoxyCodeLine{294 }
\DoxyCodeLine{295     \textcolor{comment}{! post tendency of tracer concentration; this step must be}}
\DoxyCodeLine{296     \textcolor{comment}{! done after posting tracer content tendency, since we alter}}
\DoxyCodeLine{297     \textcolor{comment}{! the tendency array and its units.}}
\DoxyCodeLine{298     \textcolor{keywordflow}{if} (tracer\%id\_lbdxy\_conc > 0) \textcolor{keywordflow}{then}}
\DoxyCodeLine{299       \textcolor{keywordflow}{do} k=1,gv\%ke ; \textcolor{keywordflow}{do} j=g\%jsc,g\%jec ; \textcolor{keywordflow}{do} i=g\%isc,g\%iec}
\DoxyCodeLine{300         tendency(i,j,k) =  tendency(i,j,k) / ( h(i,j,k) + gv\%H\_subroundoff )}
\DoxyCodeLine{301 \textcolor{keywordflow}{      enddo} ;\textcolor{keywordflow}{ enddo} ;\textcolor{keywordflow}{ enddo}}
\DoxyCodeLine{302       \textcolor{keyword}{call }post\_data(tracer\%id\_lbdxy\_conc, tendency, cs\%diag)}
\DoxyCodeLine{303 \textcolor{keywordflow}{    endif}}
\DoxyCodeLine{304 }
\DoxyCodeLine{305 \textcolor{keywordflow}{  enddo}}
\DoxyCodeLine{306 }

\end{DoxyCode}
\mbox{\Hypertarget{namespacemom__lateral__boundary__diffusion_a4eb098abd02dbf022558e4bedfe9cdef}\label{namespacemom__lateral__boundary__diffusion_a4eb098abd02dbf022558e4bedfe9cdef}} 
\index{mom\_lateral\_boundary\_diffusion@{mom\_lateral\_boundary\_diffusion}!lateral\_boundary\_diffusion\_init@{lateral\_boundary\_diffusion\_init}}
\index{lateral\_boundary\_diffusion\_init@{lateral\_boundary\_diffusion\_init}!mom\_lateral\_boundary\_diffusion@{mom\_lateral\_boundary\_diffusion}}
\subsubsection{\texorpdfstring{lateral\_boundary\_diffusion\_init()}{lateral\_boundary\_diffusion\_init()}}
{\footnotesize\ttfamily logical function, public mom\+\_\+lateral\+\_\+boundary\+\_\+diffusion\+::lateral\+\_\+boundary\+\_\+diffusion\+\_\+init (\begin{DoxyParamCaption}\item[{type(time\+\_\+type), intent(in), target}]{Time,  }\item[{type(ocean\+\_\+grid\+\_\+type), intent(in)}]{G,  }\item[{type(param\+\_\+file\+\_\+type), intent(in)}]{param\+\_\+file,  }\item[{type(diag\+\_\+ctrl), intent(inout), target}]{diag,  }\item[{type(diabatic\+\_\+cs), pointer}]{diabatic\+\_\+\+C\+Sp,  }\item[{type(\mbox{\hyperlink{structmom__lateral__boundary__diffusion_1_1lateral__boundary__diffusion__cs}{lateral\+\_\+boundary\+\_\+diffusion\+\_\+cs}}), pointer}]{CS }\end{DoxyParamCaption})}



Initialization routine that reads runtime parameters and sets up pointers to other control structures that might be needed for lateral boundary diffusion. 


\begin{DoxyParams}[1]{Parameters}
\mbox{\texttt{ in}}  & {\em time} & Time structure \\
\hline
\mbox{\texttt{ in}}  & {\em g} & Grid structure \\
\hline
\mbox{\texttt{ in}}  & {\em param\+\_\+file} & Parameter file structure \\
\hline
\mbox{\texttt{ in,out}}  & {\em diag} & Diagnostics control structure \\
\hline
 & {\em diabatic\+\_\+csp} & K\+PP control structure needed to get B\+LD \\
\hline
 & {\em cs} & Lateral boundary mixing control structure \\
\hline
\end{DoxyParams}


Definition at line 68 of file M\+O\+M\+\_\+lateral\+\_\+boundary\+\_\+diffusion.\+F90.


\begin{DoxyCode}{0}
\DoxyCodeLine{68   \textcolor{keywordtype}{type}(time\_type), \textcolor{keywordtype}{target},          \textcolor{keywordtype}{intent(in)}    :: Time\textcolor{comment}{          !< Time structure}}
\DoxyCodeLine{69   \textcolor{keywordtype}{type}(ocean\_grid\_type),            \textcolor{keywordtype}{intent(in)}    :: G\textcolor{comment}{             !< Grid structure}}
\DoxyCodeLine{70   \textcolor{keywordtype}{type}(param\_file\_type),            \textcolor{keywordtype}{intent(in)}    :: param\_file\textcolor{comment}{    !< Parameter file structure}}
\DoxyCodeLine{71   \textcolor{keywordtype}{type}(diag\_ctrl), \textcolor{keywordtype}{target},          \textcolor{keywordtype}{intent(inout)} :: diag\textcolor{comment}{          !< Diagnostics control structure}}
\DoxyCodeLine{72   \textcolor{keywordtype}{type}(diabatic\_CS),                \textcolor{keywordtype}{pointer}       :: diabatic\_CSp\textcolor{comment}{  !< KPP control structure needed to get BLD}}
\DoxyCodeLine{73   \textcolor{keywordtype}{type}(lateral\_boundary\_diffusion\_CS), \textcolor{keywordtype}{pointer}    :: CS\textcolor{comment}{            !< Lateral boundary mixing control structure}}
\DoxyCodeLine{74 }
\DoxyCodeLine{75   \textcolor{comment}{! local variables}}
\DoxyCodeLine{76   \textcolor{keywordtype}{character(len=80)}  :: string  \textcolor{comment}{! Temporary strings}}
\DoxyCodeLine{77   \textcolor{keywordtype}{logical} :: boundary\_extrap}
\DoxyCodeLine{78 }
\DoxyCodeLine{79   \textcolor{keywordflow}{if} (\textcolor{keyword}{ASSOCIATED}(cs)) \textcolor{keywordflow}{then}}
\DoxyCodeLine{80     \textcolor{keyword}{call }mom\_error(fatal, \textcolor{stringliteral}{"lateral\_boundary\_diffusion\_init called with associated control structure."})}
\DoxyCodeLine{81     \textcolor{keywordflow}{return}}
\DoxyCodeLine{82 \textcolor{keywordflow}{  endif}}
\DoxyCodeLine{83 }
\DoxyCodeLine{84   \textcolor{comment}{! Log this module and master switch for turning it on/off}}
\DoxyCodeLine{85   \textcolor{keyword}{call }get\_param(param\_file, mdl, \textcolor{stringliteral}{"USE\_LATERAL\_BOUNDARY\_DIFFUSION"}, lateral\_boundary\_diffusion\_init, \&}
\DoxyCodeLine{86                  default=.false., do\_not\_log=.true.)}
\DoxyCodeLine{87   \textcolor{keyword}{call }log\_version(param\_file, mdl, version, \&}
\DoxyCodeLine{88            \textcolor{stringliteral}{"This module implements lateral diffusion of tracers near boundaries"}, \&}
\DoxyCodeLine{89            all\_default=.not.lateral\_boundary\_diffusion\_init)}
\DoxyCodeLine{90   \textcolor{keyword}{call }get\_param(param\_file, mdl, \textcolor{stringliteral}{"USE\_LATERAL\_BOUNDARY\_DIFFUSION"}, lateral\_boundary\_diffusion\_init, \&}
\DoxyCodeLine{91                  \textcolor{stringliteral}{"If true, enables the lateral boundary tracer's diffusion module."}, \&}
\DoxyCodeLine{92                  default=.false.)}
\DoxyCodeLine{93 }
\DoxyCodeLine{94   \textcolor{keywordflow}{if} (.not. lateral\_boundary\_diffusion\_init) \textcolor{keywordflow}{return}}
\DoxyCodeLine{95 }
\DoxyCodeLine{96   \textcolor{keyword}{allocate}(cs)}
\DoxyCodeLine{97   cs\%diag => diag}
\DoxyCodeLine{98   \textcolor{keyword}{call }extract\_diabatic\_member(diabatic\_csp, kpp\_csp=cs\%KPP\_CSp)}
\DoxyCodeLine{99   \textcolor{keyword}{call }extract\_diabatic\_member(diabatic\_csp, energetic\_pbl\_csp=cs\%energetic\_PBL\_CSp)}
\DoxyCodeLine{100 }
\DoxyCodeLine{101   cs\%surface\_boundary\_scheme = -1}
\DoxyCodeLine{102   \textcolor{keywordflow}{if} ( .not. \textcolor{keyword}{ASSOCIATED}(cs\%energetic\_PBL\_CSp) .and. .not. \textcolor{keyword}{ASSOCIATED}(cs\%KPP\_CSp) ) \textcolor{keywordflow}{then}}
\DoxyCodeLine{103     \textcolor{keyword}{call }mom\_error(fatal,\textcolor{stringliteral}{"Lateral boundary diffusion is true, but no valid boundary layer scheme was found"})}
\DoxyCodeLine{104 \textcolor{keywordflow}{  endif}}
\DoxyCodeLine{105 }
\DoxyCodeLine{106   \textcolor{comment}{! Read all relevant parameters and write them to the model log.}}
\DoxyCodeLine{107   \textcolor{keyword}{call }get\_param(param\_file, mdl, \textcolor{stringliteral}{"LATERAL\_BOUNDARY\_METHOD"}, cs\%method, \&}
\DoxyCodeLine{108                  \textcolor{stringliteral}{"Determine how to apply boundary lateral diffusion of tracers: \(\backslash\)n"}//\&}
\DoxyCodeLine{109                  \textcolor{stringliteral}{"1. Along layer approach \(\backslash\)n"}//\&}
\DoxyCodeLine{110                  \textcolor{stringliteral}{"2. Bulk layer approach (this option is not recommended)"}, default=1)}
\DoxyCodeLine{111   \textcolor{keywordflow}{if} (cs\%method == 2) \textcolor{keywordflow}{then}}
\DoxyCodeLine{112     \textcolor{keyword}{call }get\_param(param\_file, mdl, \textcolor{stringliteral}{"APPLY\_LIMITER"}, cs\%limiter, \&}
\DoxyCodeLine{113                    \textcolor{stringliteral}{"If True, apply a flux limiter in the LBD. This is only available \(\backslash\)n"}//\&}
\DoxyCodeLine{114                    \textcolor{stringliteral}{"when LATERAL\_BOUNDARY\_METHOD=2."}, default=.false.)}
\DoxyCodeLine{115 \textcolor{keywordflow}{  endif}}
\DoxyCodeLine{116   \textcolor{keyword}{call }get\_param(param\_file, mdl, \textcolor{stringliteral}{"LBD\_LINEAR\_TRANSITION"}, cs\%linear, \&}
\DoxyCodeLine{117                  \textcolor{stringliteral}{"If True, apply a linear transition at the base/top of the boundary. \(\backslash\)n"}//\&}
\DoxyCodeLine{118                  \textcolor{stringliteral}{"The flux will be fully applied at k=k\_min and zero at k=k\_max."}, default=.false.)}
\DoxyCodeLine{119   \textcolor{keyword}{call }get\_param(param\_file, mdl, \textcolor{stringliteral}{"LBD\_BOUNDARY\_EXTRAP"}, boundary\_extrap, \&}
\DoxyCodeLine{120                  \textcolor{stringliteral}{"Use boundary extrapolation in LBD code"}, \&}
\DoxyCodeLine{121                  default=.false.)}
\DoxyCodeLine{122   \textcolor{keyword}{call }get\_param(param\_file, mdl, \textcolor{stringliteral}{"LBD\_REMAPPING\_SCHEME"}, string, \&}
\DoxyCodeLine{123                  \textcolor{stringliteral}{"This sets the reconstruction scheme used "}//\&}
\DoxyCodeLine{124                  \textcolor{stringliteral}{"for vertical remapping for all variables. "}//\&}
\DoxyCodeLine{125                  \textcolor{stringliteral}{"It can be one of the following schemes: "}//\&}
\DoxyCodeLine{126                  trim(remappingschemesdoc), default=remappingdefaultscheme)}
\DoxyCodeLine{127   \textcolor{keyword}{call }initialize\_remapping( cs\%remap\_CS, string, boundary\_extrapolation = boundary\_extrap )}
\DoxyCodeLine{128   \textcolor{keyword}{call }extract\_member\_remapping\_cs(cs\%remap\_CS, degree=cs\%deg)}
\DoxyCodeLine{129 }

\end{DoxyCode}
\mbox{\Hypertarget{namespacemom__lateral__boundary__diffusion_a5590830aab282e34bcd5d4df052d4578}\label{namespacemom__lateral__boundary__diffusion_a5590830aab282e34bcd5d4df052d4578}} 
\index{mom\_lateral\_boundary\_diffusion@{mom\_lateral\_boundary\_diffusion}!near\_boundary\_unit\_tests@{near\_boundary\_unit\_tests}}
\index{near\_boundary\_unit\_tests@{near\_boundary\_unit\_tests}!mom\_lateral\_boundary\_diffusion@{mom\_lateral\_boundary\_diffusion}}
\subsubsection{\texorpdfstring{near\_boundary\_unit\_tests()}{near\_boundary\_unit\_tests()}}
{\footnotesize\ttfamily logical function, public mom\+\_\+lateral\+\_\+boundary\+\_\+diffusion\+::near\+\_\+boundary\+\_\+unit\+\_\+tests (\begin{DoxyParamCaption}\item[{logical, intent(in)}]{verbose }\end{DoxyParamCaption})}



Unit tests for near-\/boundary horizontal mixing. 


\begin{DoxyParams}[1]{Parameters}
\mbox{\texttt{ in}}  & {\em verbose} & If true, output additional information for debugging unit tests \\
\hline
\end{DoxyParams}


Definition at line 807 of file M\+O\+M\+\_\+lateral\+\_\+boundary\+\_\+diffusion.\+F90.


\begin{DoxyCode}{0}
\DoxyCodeLine{807   \textcolor{keywordtype}{logical},               \textcolor{keywordtype}{intent(in)} :: verbose\textcolor{comment}{ !< If true, output additional information for debugging unit tests}}
\DoxyCodeLine{808 }
\DoxyCodeLine{809   \textcolor{comment}{! Local variables}}
\DoxyCodeLine{810   \textcolor{keywordtype}{integer}, \textcolor{keywordtype}{parameter}    :: nk = 2               \textcolor{comment}{! Number of layers}}
\DoxyCodeLine{811   \textcolor{keywordtype}{integer}, \textcolor{keywordtype}{parameter}    :: deg = 1              \textcolor{comment}{! Degree of reconstruction (linear here)}}
\DoxyCodeLine{812   \textcolor{keywordtype}{integer}, \textcolor{keywordtype}{parameter}    :: method = 1           \textcolor{comment}{! Method used for integrating polynomials}}
\DoxyCodeLine{813 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(nk)}   :: phi\_L, phi\_R         \textcolor{comment}{! Tracer values (left and right column)             [ nondim m\string^-3 ]}}
\DoxyCodeLine{814 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(nk)}   :: phi\_L\_avg, phi\_R\_avg \textcolor{comment}{! Bulk, thickness-weighted tracer averages (left and right column)}}
\DoxyCodeLine{815 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(nk,deg+1)} :: phi\_pp\_L, phi\_pp\_R   \textcolor{comment}{! Coefficients for the linear pseudo-reconstructions}}
\DoxyCodeLine{816                                                 \textcolor{comment}{!                                                   [ nondim m\string^-3 ]}}
\DoxyCodeLine{817 }
\DoxyCodeLine{818 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(nk,2)} :: ppoly0\_E\_L, ppoly0\_E\_R\textcolor{comment}{! Polynomial edge values (left and right)          [concentration]}}
\DoxyCodeLine{819 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(nk)}   :: h\_L, h\_R             \textcolor{comment}{! Layer thickness (left and right)                  [m]}}
\DoxyCodeLine{820 \textcolor{keywordtype}{  real}                  :: khtr\_u               \textcolor{comment}{! Horizontal diffusivities at U-point               [m\string^2 s\string^-1]}}
\DoxyCodeLine{821 \textcolor{keywordtype}{  real}                  :: hbl\_L, hbl\_R         \textcolor{comment}{! Depth of the boundary layer (left and right)      [m]}}
\DoxyCodeLine{822 \textcolor{keywordtype}{  real}                  :: F\_bulk               \textcolor{comment}{! Total diffusive flux across the U point           [nondim s\string^-1]}}
\DoxyCodeLine{823 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(nk)}   :: F\_layer              \textcolor{comment}{! Diffusive flux within each layer at U-point       [nondim s\string^-1]}}
\DoxyCodeLine{824 \textcolor{keywordtype}{  real}                  :: h\_u, hblt\_u          \textcolor{comment}{! Thickness at the u-point                          [m]}}
\DoxyCodeLine{825 \textcolor{keywordtype}{  real}                  :: khtr\_avg             \textcolor{comment}{! Thickness-weighted diffusivity at the u-point     [m\string^2 s\string^-1]}}
\DoxyCodeLine{826 \textcolor{keywordtype}{  real}                  :: heff                 \textcolor{comment}{! Harmonic mean of layer thicknesses                [m]}}
\DoxyCodeLine{827 \textcolor{keywordtype}{  real}                  :: inv\_heff             \textcolor{comment}{! Inverse of the harmonic mean of layer thicknesses [m\string^[-1]}}
\DoxyCodeLine{828   \textcolor{keywordtype}{character(len=120)}    :: test\_name            \textcolor{comment}{! Title of the unit test}}
\DoxyCodeLine{829   \textcolor{keywordtype}{integer}               :: k\_top                \textcolor{comment}{! Index of cell containing top of boundary}}
\DoxyCodeLine{830 \textcolor{keywordtype}{  real}                  :: zeta\_top             \textcolor{comment}{! Nondimension position}}
\DoxyCodeLine{831   \textcolor{keywordtype}{integer}               :: k\_bot                \textcolor{comment}{! Index of cell containing bottom of boundary}}
\DoxyCodeLine{832 \textcolor{keywordtype}{  real}                  :: zeta\_bot             \textcolor{comment}{! Nondimension position}}
\DoxyCodeLine{833 \textcolor{keywordtype}{  real}                  :: area\_L,area\_R        \textcolor{comment}{! Area of grid cell [m\string^2]}}
\DoxyCodeLine{834   area\_l = 1.; area\_r = 1. \textcolor{comment}{! Set to unity for all unit tests}}
\DoxyCodeLine{835 }
\DoxyCodeLine{836   near\_boundary\_unit\_tests = .false.}
\DoxyCodeLine{837 }
\DoxyCodeLine{838   \textcolor{comment}{! Unit tests for boundary\_k\_range}}
\DoxyCodeLine{839   test\_name = \textcolor{stringliteral}{'Surface boundary spans the entire top cell'}}
\DoxyCodeLine{840   h\_l = (/5.,5./)}
\DoxyCodeLine{841   \textcolor{keyword}{call }boundary\_k\_range(surface, nk, h\_l, 5., k\_top, zeta\_top, k\_bot, zeta\_bot)}
\DoxyCodeLine{842   near\_boundary\_unit\_tests = near\_boundary\_unit\_tests .or. \&}
\DoxyCodeLine{843                              test\_boundary\_k\_range(k\_top, zeta\_top, k\_bot, zeta\_bot, 1, 0., 1, 1., test\_name, verbose)}
\DoxyCodeLine{844 }
\DoxyCodeLine{845   test\_name = \textcolor{stringliteral}{'Surface boundary spans the entire column'}}
\DoxyCodeLine{846   h\_l = (/5.,5./)}
\DoxyCodeLine{847   \textcolor{keyword}{call }boundary\_k\_range(surface, nk, h\_l, 10., k\_top, zeta\_top, k\_bot, zeta\_bot)}
\DoxyCodeLine{848   near\_boundary\_unit\_tests = near\_boundary\_unit\_tests .or. \&}
\DoxyCodeLine{849                              test\_boundary\_k\_range(k\_top, zeta\_top, k\_bot, zeta\_bot, 1, 0., 2, 1., test\_name, verbose)}
\DoxyCodeLine{850 }
\DoxyCodeLine{851   test\_name = \textcolor{stringliteral}{'Bottom boundary spans the entire bottom cell'}}
\DoxyCodeLine{852   h\_l = (/5.,5./)}
\DoxyCodeLine{853   \textcolor{keyword}{call }boundary\_k\_range(bottom, nk, h\_l, 5., k\_top, zeta\_top, k\_bot, zeta\_bot)}
\DoxyCodeLine{854   near\_boundary\_unit\_tests = near\_boundary\_unit\_tests .or. \&}
\DoxyCodeLine{855                              test\_boundary\_k\_range(k\_top, zeta\_top, k\_bot, zeta\_bot, 2, 1., 2, 0., test\_name, verbose)}
\DoxyCodeLine{856 }
\DoxyCodeLine{857   test\_name = \textcolor{stringliteral}{'Bottom boundary spans the entire column'}}
\DoxyCodeLine{858   h\_l = (/5.,5./)}
\DoxyCodeLine{859   \textcolor{keyword}{call }boundary\_k\_range(bottom, nk, h\_l, 10., k\_top, zeta\_top, k\_bot, zeta\_bot)}
\DoxyCodeLine{860   near\_boundary\_unit\_tests = near\_boundary\_unit\_tests .or. \&}
\DoxyCodeLine{861                              test\_boundary\_k\_range(k\_top, zeta\_top, k\_bot, zeta\_bot, 1, 1., 2, 0., test\_name, verbose)}
\DoxyCodeLine{862 }
\DoxyCodeLine{863   test\_name = \textcolor{stringliteral}{'Surface boundary intersects second layer'}}
\DoxyCodeLine{864   h\_l = (/10.,10./)}
\DoxyCodeLine{865   \textcolor{keyword}{call }boundary\_k\_range(surface, nk, h\_l, 17.5, k\_top, zeta\_top, k\_bot, zeta\_bot)}
\DoxyCodeLine{866   near\_boundary\_unit\_tests = near\_boundary\_unit\_tests .or. \&}
\DoxyCodeLine{867                              test\_boundary\_k\_range(k\_top, zeta\_top, k\_bot, zeta\_bot, 1, 0., 2, 0.75, test\_name, verbose)}
\DoxyCodeLine{868 }
\DoxyCodeLine{869   test\_name = \textcolor{stringliteral}{'Surface boundary intersects first layer'}}
\DoxyCodeLine{870   h\_l = (/10.,10./)}
\DoxyCodeLine{871   \textcolor{keyword}{call }boundary\_k\_range(surface, nk, h\_l, 2.5, k\_top, zeta\_top, k\_bot, zeta\_bot)}
\DoxyCodeLine{872   near\_boundary\_unit\_tests = near\_boundary\_unit\_tests .or. \&}
\DoxyCodeLine{873                              test\_boundary\_k\_range(k\_top, zeta\_top, k\_bot, zeta\_bot, 1, 0., 1, 0.25, test\_name, verbose)}
\DoxyCodeLine{874 }
\DoxyCodeLine{875   test\_name = \textcolor{stringliteral}{'Surface boundary is deeper than column thickness'}}
\DoxyCodeLine{876   h\_l = (/10.,10./)}
\DoxyCodeLine{877   \textcolor{keyword}{call }boundary\_k\_range(surface, nk, h\_l, 21.0, k\_top, zeta\_top, k\_bot, zeta\_bot)}
\DoxyCodeLine{878   near\_boundary\_unit\_tests = near\_boundary\_unit\_tests .or. \&}
\DoxyCodeLine{879                              test\_boundary\_k\_range(k\_top, zeta\_top, k\_bot, zeta\_bot, 1, 0., 2, 1., test\_name, verbose)}
\DoxyCodeLine{880 }
\DoxyCodeLine{881   test\_name = \textcolor{stringliteral}{'Bottom boundary intersects first layer'}}
\DoxyCodeLine{882   h\_l = (/10.,10./)}
\DoxyCodeLine{883   \textcolor{keyword}{call }boundary\_k\_range(bottom, nk, h\_l, 17.5, k\_top, zeta\_top, k\_bot, zeta\_bot)}
\DoxyCodeLine{884   near\_boundary\_unit\_tests = near\_boundary\_unit\_tests .or. \&}
\DoxyCodeLine{885                              test\_boundary\_k\_range(k\_top, zeta\_top, k\_bot, zeta\_bot, 1, 0.75, 2, 0., test\_name, verbose)}
\DoxyCodeLine{886 }
\DoxyCodeLine{887   test\_name = \textcolor{stringliteral}{'Bottom boundary intersects second layer'}}
\DoxyCodeLine{888   h\_l = (/10.,10./)}
\DoxyCodeLine{889   \textcolor{keyword}{call }boundary\_k\_range(bottom, nk, h\_l, 2.5, k\_top, zeta\_top, k\_bot, zeta\_bot)}
\DoxyCodeLine{890   near\_boundary\_unit\_tests = near\_boundary\_unit\_tests .or. \&}
\DoxyCodeLine{891                              test\_boundary\_k\_range(k\_top, zeta\_top, k\_bot, zeta\_bot, 2, 0.25, 2, 0., test\_name, verbose)}
\DoxyCodeLine{892 }
\DoxyCodeLine{893   \textcolor{comment}{! All cases in this section have hbl which are equal to the column thicknesses}}
\DoxyCodeLine{894   test\_name = \textcolor{stringliteral}{'Equal hbl and same layer thicknesses (gradient from right to left)'}}
\DoxyCodeLine{895   hbl\_l = 10; hbl\_r = 10}
\DoxyCodeLine{896   h\_l = (/5.,5./) ; h\_r = (/5.,5./)}
\DoxyCodeLine{897   phi\_l = (/0.,0./) ; phi\_r = (/1.,1./)}
\DoxyCodeLine{898   phi\_pp\_l(1,1) = 0.; phi\_pp\_l(1,2) = 0.}
\DoxyCodeLine{899   phi\_pp\_l(2,1) = 0.; phi\_pp\_l(2,2) = 0.}
\DoxyCodeLine{900   phi\_pp\_r(1,1) = 1.; phi\_pp\_r(1,2) = 0.}
\DoxyCodeLine{901   phi\_pp\_r(2,1) = 1.; phi\_pp\_r(2,2) = 0.}
\DoxyCodeLine{902   ppoly0\_e\_l(1,1) = 0.; ppoly0\_e\_l(1,2) = 0.}
\DoxyCodeLine{903   ppoly0\_e\_l(2,1) = 0.; ppoly0\_e\_l(2,2) = 0.}
\DoxyCodeLine{904   ppoly0\_e\_r(1,1) = 1.; ppoly0\_e\_r(1,2) = 1.}
\DoxyCodeLine{905   ppoly0\_e\_r(2,1) = 1.; ppoly0\_e\_r(2,2) = 1.}
\DoxyCodeLine{906   khtr\_u = 1.}
\DoxyCodeLine{907   \textcolor{comment}{! Without limiter}}
\DoxyCodeLine{908   \textcolor{keyword}{call }fluxes\_bulk\_method(surface, nk, deg, h\_l, h\_r, hbl\_l, hbl\_r, area\_l, area\_r, phi\_l, phi\_r, phi\_pp\_l, phi\_pp\_r, \&}
\DoxyCodeLine{909                                     ppoly0\_e\_l, ppoly0\_e\_r, method, khtr\_u, f\_bulk, f\_layer)}
\DoxyCodeLine{910   near\_boundary\_unit\_tests = near\_boundary\_unit\_tests .or. \&}
\DoxyCodeLine{911                              test\_layer\_fluxes( verbose, nk, test\_name, f\_layer, (/-5.0,-5.0/) )}
\DoxyCodeLine{912 }
\DoxyCodeLine{913   \textcolor{comment}{! same as above, but with limiter}}
\DoxyCodeLine{914   \textcolor{keyword}{call }fluxes\_bulk\_method(surface, nk, deg, h\_l, h\_r, hbl\_l, hbl\_r, area\_l, area\_r, phi\_l, phi\_r, phi\_pp\_l, phi\_pp\_r, \&}
\DoxyCodeLine{915                                     ppoly0\_e\_l, ppoly0\_e\_r, method, khtr\_u, f\_bulk, f\_layer, .true.)}
\DoxyCodeLine{916   near\_boundary\_unit\_tests = near\_boundary\_unit\_tests .or. \&}
\DoxyCodeLine{917                              test\_layer\_fluxes( verbose, nk, test\_name, f\_layer, (/-1.0,-1.0/) )}
\DoxyCodeLine{918 }
\DoxyCodeLine{919   test\_name = \textcolor{stringliteral}{'Equal hbl and same layer thicknesses (gradient from left to right)'}}
\DoxyCodeLine{920   hbl\_l = 10.; hbl\_r = 10.}
\DoxyCodeLine{921   h\_l = (/5.,5./) ; h\_r = (/5.,5./)}
\DoxyCodeLine{922   phi\_l = (/1.,1./) ; phi\_r = (/0.,0./)}
\DoxyCodeLine{923   phi\_pp\_l(1,1) = 1.; phi\_pp\_l(1,2) = 0.}
\DoxyCodeLine{924   phi\_pp\_l(2,1) = 1.; phi\_pp\_l(2,2) = 0.}
\DoxyCodeLine{925   phi\_pp\_r(1,1) = 0.; phi\_pp\_r(1,2) = 0.}
\DoxyCodeLine{926   phi\_pp\_r(2,1) = 0.; phi\_pp\_r(2,2) = 0.}
\DoxyCodeLine{927   ppoly0\_e\_l(1,1) = 1.; ppoly0\_e\_l(1,2) = 1.}
\DoxyCodeLine{928   ppoly0\_e\_l(2,1) = 1.; ppoly0\_e\_l(2,2) = 1.}
\DoxyCodeLine{929   ppoly0\_e\_r(1,1) = 0.; ppoly0\_e\_r(1,2) = 0.}
\DoxyCodeLine{930   ppoly0\_e\_r(2,1) = 0.; ppoly0\_e\_r(2,2) = 0.}
\DoxyCodeLine{931   khtr\_u = 1.}
\DoxyCodeLine{932   \textcolor{keyword}{call }fluxes\_bulk\_method(surface, nk, deg, h\_l, h\_r, hbl\_l, hbl\_r, area\_l, area\_r, phi\_l, phi\_r, phi\_pp\_l, phi\_pp\_r,\&}
\DoxyCodeLine{933                                     ppoly0\_e\_l, ppoly0\_e\_r, method, khtr\_u, f\_bulk, f\_layer)}
\DoxyCodeLine{934   near\_boundary\_unit\_tests = near\_boundary\_unit\_tests .or. \&}
\DoxyCodeLine{935                              test\_layer\_fluxes( verbose, nk, test\_name, f\_layer, (/5.0,5.0/) )}
\DoxyCodeLine{936 }
\DoxyCodeLine{937   test\_name = \textcolor{stringliteral}{'Equal hbl and same layer thicknesses (no gradient)'}}
\DoxyCodeLine{938   hbl\_l = 10; hbl\_r = 10}
\DoxyCodeLine{939   h\_l = (/5.,5./) ; h\_r = (/5.,5./)}
\DoxyCodeLine{940   phi\_l = (/1.,1./) ; phi\_r = (/1.,1./)}
\DoxyCodeLine{941   phi\_pp\_l(1,1) = 1.; phi\_pp\_l(1,2) = 0.}
\DoxyCodeLine{942   phi\_pp\_l(2,1) = 1.; phi\_pp\_l(2,2) = 0.}
\DoxyCodeLine{943   phi\_pp\_r(1,1) = 1.; phi\_pp\_r(1,2) = 0.}
\DoxyCodeLine{944   phi\_pp\_r(2,1) = 1.; phi\_pp\_r(2,2) = 0.}
\DoxyCodeLine{945   ppoly0\_e\_l(1,1) = 1.; ppoly0\_e\_l(1,2) = 1.}
\DoxyCodeLine{946   ppoly0\_e\_l(2,1) = 1.; ppoly0\_e\_l(2,2) = 1.}
\DoxyCodeLine{947   ppoly0\_e\_r(1,1) = 1.; ppoly0\_e\_r(1,2) = 1.}
\DoxyCodeLine{948   ppoly0\_e\_r(2,1) = 1.; ppoly0\_e\_r(2,2) = 1.}
\DoxyCodeLine{949   khtr\_u = 1.}
\DoxyCodeLine{950   \textcolor{keyword}{call }fluxes\_bulk\_method(surface, nk, deg, h\_l, h\_r, hbl\_l, hbl\_r, area\_l, area\_r, phi\_l, phi\_r, phi\_pp\_l, phi\_pp\_r,\&}
\DoxyCodeLine{951                                     ppoly0\_e\_l, ppoly0\_e\_r, method, khtr\_u, f\_bulk, f\_layer)}
\DoxyCodeLine{952   near\_boundary\_unit\_tests = near\_boundary\_unit\_tests .or. \&}
\DoxyCodeLine{953                              test\_layer\_fluxes( verbose, nk, test\_name, f\_layer, (/0.0,0.0/) )}
\DoxyCodeLine{954 }
\DoxyCodeLine{955   test\_name = \textcolor{stringliteral}{'Equal hbl and different layer thicknesses (gradient right to left)'}}
\DoxyCodeLine{956   hbl\_l = 16.; hbl\_r = 16.}
\DoxyCodeLine{957   h\_l = (/10.,6./) ; h\_r = (/6.,10./)}
\DoxyCodeLine{958   phi\_l = (/0.,0./) ; phi\_r = (/1.,1./)}
\DoxyCodeLine{959   phi\_pp\_l(1,1) = 0.; phi\_pp\_l(1,2) = 0.}
\DoxyCodeLine{960   phi\_pp\_l(2,1) = 0.; phi\_pp\_l(2,2) = 0.}
\DoxyCodeLine{961   phi\_pp\_r(1,1) = 1.; phi\_pp\_r(1,2) = 0.}
\DoxyCodeLine{962   phi\_pp\_r(2,1) = 1.; phi\_pp\_r(2,2) = 0.}
\DoxyCodeLine{963   ppoly0\_e\_l(1,1) = 0.; ppoly0\_e\_l(1,2) = 0.}
\DoxyCodeLine{964   ppoly0\_e\_l(2,1) = 0.; ppoly0\_e\_l(2,2) = 0.}
\DoxyCodeLine{965   ppoly0\_e\_r(1,1) = 1.; ppoly0\_e\_r(1,2) = 1.}
\DoxyCodeLine{966   ppoly0\_e\_r(2,1) = 1.; ppoly0\_e\_r(2,2) = 1.}
\DoxyCodeLine{967   khtr\_u = 1.}
\DoxyCodeLine{968   \textcolor{keyword}{call }fluxes\_bulk\_method(surface, nk, deg, h\_l, h\_r, hbl\_l, hbl\_r, area\_l, area\_r, phi\_l, phi\_r, phi\_pp\_l, phi\_pp\_r,\&}
\DoxyCodeLine{969                                     ppoly0\_e\_l, ppoly0\_e\_r, method, khtr\_u, f\_bulk, f\_layer)}
\DoxyCodeLine{970   near\_boundary\_unit\_tests = near\_boundary\_unit\_tests .or. \&}
\DoxyCodeLine{971                              test\_layer\_fluxes( verbose, nk, test\_name, f\_layer, (/-8.0,-8.0/) )}
\DoxyCodeLine{972 }
\DoxyCodeLine{973   test\_name = \textcolor{stringliteral}{'Equal hbl and same layer thicknesses (diagonal tracer values)'}}
\DoxyCodeLine{974   hbl\_l = 10.; hbl\_r = 10.}
\DoxyCodeLine{975   h\_l = (/5.,5./) ; h\_r = (/5.,5./)}
\DoxyCodeLine{976   phi\_l = (/1.,0./) ; phi\_r = (/0.,1./)}
\DoxyCodeLine{977   phi\_pp\_l(1,1) = 1.; phi\_pp\_l(1,2) = 0.}
\DoxyCodeLine{978   phi\_pp\_l(2,1) = 0.; phi\_pp\_l(2,2) = 0.}
\DoxyCodeLine{979   phi\_pp\_r(1,1) = 0.; phi\_pp\_r(1,2) = 0.}
\DoxyCodeLine{980   phi\_pp\_r(2,1) = 1.; phi\_pp\_r(2,2) = 0.}
\DoxyCodeLine{981   ppoly0\_e\_l(1,1) = 1.; ppoly0\_e\_l(1,2) = 1.}
\DoxyCodeLine{982   ppoly0\_e\_l(2,1) = 0.; ppoly0\_e\_l(2,2) = 0.}
\DoxyCodeLine{983   ppoly0\_e\_r(1,1) = 0.; ppoly0\_e\_r(1,2) = 0.}
\DoxyCodeLine{984   ppoly0\_e\_r(2,1) = 1.; ppoly0\_e\_r(2,2) = 1.}
\DoxyCodeLine{985   khtr\_u = 1.}
\DoxyCodeLine{986   \textcolor{keyword}{call }fluxes\_bulk\_method(surface, nk, deg, h\_l, h\_r, hbl\_l, hbl\_r, area\_l, area\_r, phi\_l, phi\_r, phi\_pp\_l, phi\_pp\_r,\&}
\DoxyCodeLine{987                                     ppoly0\_e\_l, ppoly0\_e\_r, method, khtr\_u, f\_bulk, f\_layer)}
\DoxyCodeLine{988   near\_boundary\_unit\_tests = near\_boundary\_unit\_tests .or. \&}
\DoxyCodeLine{989                              test\_layer\_fluxes( verbose, nk, test\_name, f\_layer, (/0.0,0.0/) )}
\DoxyCodeLine{990 }
\DoxyCodeLine{991   test\_name = \textcolor{stringliteral}{'Different hbl and different layer thicknesses (gradient from right to left)'}}
\DoxyCodeLine{992   hbl\_l = 12; hbl\_r = 20}
\DoxyCodeLine{993   h\_l = (/6.,6./) ; h\_r = (/10.,10./)}
\DoxyCodeLine{994   phi\_l = (/0.,0./) ; phi\_r = (/1.,1./)}
\DoxyCodeLine{995   phi\_pp\_l(1,1) = 0.; phi\_pp\_l(1,2) = 0.}
\DoxyCodeLine{996   phi\_pp\_l(2,1) = 0.; phi\_pp\_l(2,2) = 0.}
\DoxyCodeLine{997   phi\_pp\_r(1,1) = 1.; phi\_pp\_r(1,2) = 0.}
\DoxyCodeLine{998   phi\_pp\_r(2,1) = 1.; phi\_pp\_r(2,2) = 0.}
\DoxyCodeLine{999   ppoly0\_e\_l(1,1) = 0.; ppoly0\_e\_l(1,2) = 0.}
\DoxyCodeLine{1000   ppoly0\_e\_l(2,1) = 0.; ppoly0\_e\_l(2,2) = 0.}
\DoxyCodeLine{1001   ppoly0\_e\_r(1,1) = 1.; ppoly0\_e\_r(1,2) = 1.}
\DoxyCodeLine{1002   ppoly0\_e\_r(2,1) = 1.; ppoly0\_e\_r(2,2) = 1.}
\DoxyCodeLine{1003   khtr\_u = 1.}
\DoxyCodeLine{1004   \textcolor{keyword}{call }fluxes\_bulk\_method(surface, nk, deg, h\_l, h\_r, hbl\_l, hbl\_r, area\_l, area\_r, phi\_l, phi\_r, phi\_pp\_l, phi\_pp\_r,\&}
\DoxyCodeLine{1005                                     ppoly0\_e\_l, ppoly0\_e\_r, method, khtr\_u, f\_bulk, f\_layer)}
\DoxyCodeLine{1006   near\_boundary\_unit\_tests = near\_boundary\_unit\_tests .or. \&}
\DoxyCodeLine{1007                              test\_layer\_fluxes( verbose, nk, test\_name, f\_layer, (/-7.5,-7.5/) )}
\DoxyCodeLine{1008 }
\DoxyCodeLine{1009   \textcolor{comment}{! Cases where hbl < column thickness (polynomial coefficients specified for pseudo-linear reconstruction)}}
\DoxyCodeLine{1010 }
\DoxyCodeLine{1011   test\_name = \textcolor{stringliteral}{'hbl < column thickness, hbl same, constant concentration each column'}}
\DoxyCodeLine{1012   hbl\_l = 2; hbl\_r = 2}
\DoxyCodeLine{1013   h\_l = (/1.,2./) ; h\_r = (/1.,2./)}
\DoxyCodeLine{1014   phi\_l = (/0.,0./) ; phi\_r = (/1.,1./)}
\DoxyCodeLine{1015   phi\_pp\_l(1,1) = 0.; phi\_pp\_l(1,2) = 0.}
\DoxyCodeLine{1016   phi\_pp\_l(2,1) = 0.; phi\_pp\_l(2,2) = 0.}
\DoxyCodeLine{1017   phi\_pp\_r(1,1) = 1.; phi\_pp\_r(1,2) = 0.}
\DoxyCodeLine{1018   phi\_pp\_r(2,1) = 1.; phi\_pp\_r(2,2) = 0.}
\DoxyCodeLine{1019   ppoly0\_e\_l(1,1) = 0.; ppoly0\_e\_l(1,2) = 0.}
\DoxyCodeLine{1020   ppoly0\_e\_l(2,1) = 0.; ppoly0\_e\_l(2,2) = 0.}
\DoxyCodeLine{1021   ppoly0\_e\_r(1,1) = 1.; ppoly0\_e\_r(1,2) = 1.}
\DoxyCodeLine{1022   ppoly0\_e\_r(2,1) = 1.; ppoly0\_e\_r(2,2) = 1.}
\DoxyCodeLine{1023   khtr\_u = 1.}
\DoxyCodeLine{1024   \textcolor{keyword}{call }fluxes\_bulk\_method(surface, nk, deg, h\_l, h\_r, hbl\_l, hbl\_r, area\_l, area\_r, phi\_l, phi\_r, phi\_pp\_l, phi\_pp\_r,\&}
\DoxyCodeLine{1025                                     ppoly0\_e\_l, ppoly0\_e\_r, method, khtr\_u, f\_bulk, f\_layer)}
\DoxyCodeLine{1026   near\_boundary\_unit\_tests = near\_boundary\_unit\_tests .or. \&}
\DoxyCodeLine{1027                              test\_layer\_fluxes( verbose, nk, test\_name, f\_layer, (/-1.,-1./) )}
\DoxyCodeLine{1028 }
\DoxyCodeLine{1029   test\_name = \textcolor{stringliteral}{'hbl < column thickness, hbl same, linear profile right'}}
\DoxyCodeLine{1030   hbl\_l = 2; hbl\_r = 2}
\DoxyCodeLine{1031   h\_l = (/1.,2./) ; h\_r = (/1.,2./)}
\DoxyCodeLine{1032   phi\_l = (/0.,0./) ; phi\_r = (/0.5,2./)}
\DoxyCodeLine{1033   phi\_pp\_l(1,1) = 0.; phi\_pp\_l(1,2) = 0.}
\DoxyCodeLine{1034   phi\_pp\_l(2,1) = 0.; phi\_pp\_l(2,2) = 0.}
\DoxyCodeLine{1035   phi\_pp\_r(1,1) = 0.; phi\_pp\_r(1,2) = 1.}
\DoxyCodeLine{1036   phi\_pp\_r(2,1) = 1.; phi\_pp\_r(2,2) = 2.}
\DoxyCodeLine{1037   khtr\_u = 1.}
\DoxyCodeLine{1038   ppoly0\_e\_l(1,1) = 0.; ppoly0\_e\_l(1,2) = 0.}
\DoxyCodeLine{1039   ppoly0\_e\_l(2,1) = 0.; ppoly0\_e\_l(2,2) = 0.}
\DoxyCodeLine{1040   ppoly0\_e\_r(1,1) = 0.; ppoly0\_e\_r(1,2) = 1.}
\DoxyCodeLine{1041   ppoly0\_e\_r(2,1) = 1.; ppoly0\_e\_r(2,2) = 3.}
\DoxyCodeLine{1042   \textcolor{keyword}{call }fluxes\_bulk\_method(surface, nk, deg, h\_l, h\_r, hbl\_l, hbl\_r, area\_l, area\_r, phi\_l, phi\_r, phi\_pp\_l, phi\_pp\_r,\&}
\DoxyCodeLine{1043                                     ppoly0\_e\_l, ppoly0\_e\_r, method, khtr\_u, f\_bulk, f\_layer)}
\DoxyCodeLine{1044   near\_boundary\_unit\_tests = near\_boundary\_unit\_tests .or. \&}
\DoxyCodeLine{1045                              test\_layer\_fluxes( verbose, nk, test\_name, f\_layer, (/-1.,-1./) )}
\DoxyCodeLine{1046 }
\DoxyCodeLine{1047   test\_name = \textcolor{stringliteral}{'hbl < column thickness, hbl same, linear profile right, khtr=2'}}
\DoxyCodeLine{1048   hbl\_l = 2; hbl\_r = 2}
\DoxyCodeLine{1049   h\_l = (/1.,2./) ; h\_r = (/1.,2./)}
\DoxyCodeLine{1050   phi\_l = (/0.,0./) ; phi\_r = (/0.5,2./)}
\DoxyCodeLine{1051   phi\_pp\_l(1,1) = 0.; phi\_pp\_l(1,2) = 0.}
\DoxyCodeLine{1052   phi\_pp\_l(2,1) = 0.; phi\_pp\_l(2,2) = 0.}
\DoxyCodeLine{1053   phi\_pp\_r(1,1) = 0.; phi\_pp\_r(1,2) = 1.}
\DoxyCodeLine{1054   phi\_pp\_r(2,1) = 1.; phi\_pp\_r(2,2) = 2.}
\DoxyCodeLine{1055   khtr\_u = 2.}
\DoxyCodeLine{1056   ppoly0\_e\_l(1,1) = 0.; ppoly0\_e\_l(1,2) = 0.}
\DoxyCodeLine{1057   ppoly0\_e\_l(2,1) = 0.; ppoly0\_e\_l(2,2) = 0.}
\DoxyCodeLine{1058   ppoly0\_e\_r(1,1) = 0.; ppoly0\_e\_r(1,2) = 1.}
\DoxyCodeLine{1059   ppoly0\_e\_r(2,1) = 1.; ppoly0\_e\_r(2,2) = 3.}
\DoxyCodeLine{1060   \textcolor{keyword}{call }fluxes\_layer\_method(surface, nk, deg, h\_l, h\_r, hbl\_l, hbl\_r, area\_l, area\_r, phi\_l, phi\_r, phi\_pp\_l, \&}
\DoxyCodeLine{1061                                     phi\_pp\_r, ppoly0\_e\_l, ppoly0\_e\_r, method, khtr\_u, f\_layer)}
\DoxyCodeLine{1062   near\_boundary\_unit\_tests = near\_boundary\_unit\_tests .or. \&}
\DoxyCodeLine{1063                              test\_layer\_fluxes( verbose, nk, test\_name, f\_layer, (/-1.,-3./) )}
\DoxyCodeLine{1064 }
\DoxyCodeLine{1065   \textcolor{comment}{! unit tests for layer by layer method}}
\DoxyCodeLine{1066   test\_name = \textcolor{stringliteral}{'Different hbl and different column thicknesses (gradient from right to left)'}}
\DoxyCodeLine{1067   hbl\_l = 12; hbl\_r = 20}
\DoxyCodeLine{1068   h\_l = (/6.,6./) ; h\_r = (/10.,10./)}
\DoxyCodeLine{1069   phi\_l = (/0.,0./) ; phi\_r = (/1.,1./)}
\DoxyCodeLine{1070   phi\_pp\_l(1,1) = 0.; phi\_pp\_l(1,2) = 0.}
\DoxyCodeLine{1071   phi\_pp\_l(2,1) = 0.; phi\_pp\_l(2,2) = 0.}
\DoxyCodeLine{1072   phi\_pp\_r(1,1) = 1.; phi\_pp\_r(1,2) = 0.}
\DoxyCodeLine{1073   phi\_pp\_r(2,1) = 1.; phi\_pp\_r(2,2) = 0.}
\DoxyCodeLine{1074   ppoly0\_e\_l(1,1) = 0.; ppoly0\_e\_l(1,2) = 0.}
\DoxyCodeLine{1075   ppoly0\_e\_l(2,1) = 0.; ppoly0\_e\_l(2,2) = 0.}
\DoxyCodeLine{1076   ppoly0\_e\_r(1,1) = 1.; ppoly0\_e\_r(1,2) = 1.}
\DoxyCodeLine{1077   ppoly0\_e\_r(2,1) = 1.; ppoly0\_e\_r(2,2) = 1.}
\DoxyCodeLine{1078   khtr\_u = 1.}
\DoxyCodeLine{1079   \textcolor{keyword}{call }fluxes\_layer\_method(surface, nk, deg, h\_l, h\_r, hbl\_l, hbl\_r, area\_l, area\_r, phi\_l, phi\_r, phi\_pp\_l, \&}
\DoxyCodeLine{1080                                     phi\_pp\_r, ppoly0\_e\_l, ppoly0\_e\_r, method, khtr\_u, f\_layer)}
\DoxyCodeLine{1081   near\_boundary\_unit\_tests = near\_boundary\_unit\_tests .or. \&}
\DoxyCodeLine{1082                              test\_layer\_fluxes( verbose, nk, test\_name, f\_layer, (/-7.5,-7.5/) )}
\DoxyCodeLine{1083 }
\DoxyCodeLine{1084   test\_name = \textcolor{stringliteral}{'Different hbl and different column thicknesses (linear profile right)'}}
\DoxyCodeLine{1085 }
\DoxyCodeLine{1086   hbl\_l = 15; hbl\_r = 6}
\DoxyCodeLine{1087   h\_l = (/10.,10./) ; h\_r = (/12.,10./)}
\DoxyCodeLine{1088   phi\_l = (/0.,0./) ; phi\_r = (/1.,3./)}
\DoxyCodeLine{1089   phi\_pp\_l(1,1) = 0.; phi\_pp\_l(1,2) = 0.}
\DoxyCodeLine{1090   phi\_pp\_l(2,1) = 0.; phi\_pp\_l(2,2) = 0.}
\DoxyCodeLine{1091   phi\_pp\_r(1,1) = 0.; phi\_pp\_r(1,2) = 2.}
\DoxyCodeLine{1092   phi\_pp\_r(2,1) = 2.; phi\_pp\_r(2,2) = 2.}
\DoxyCodeLine{1093   ppoly0\_e\_l(1,1) = 0.; ppoly0\_e\_l(1,2) = 0.}
\DoxyCodeLine{1094   ppoly0\_e\_l(2,1) = 0.; ppoly0\_e\_l(2,2) = 0.}
\DoxyCodeLine{1095   ppoly0\_e\_r(1,1) = 0.; ppoly0\_e\_r(1,2) = 2.}
\DoxyCodeLine{1096   ppoly0\_e\_r(2,1) = 2.; ppoly0\_e\_r(2,2) = 4.}
\DoxyCodeLine{1097   khtr\_u = 1.}
\DoxyCodeLine{1098   \textcolor{keyword}{call }fluxes\_layer\_method(surface, nk, deg, h\_l, h\_r, hbl\_l, hbl\_r, area\_l, area\_r, phi\_l, phi\_r, phi\_pp\_l, \&}
\DoxyCodeLine{1099                                     phi\_pp\_r, ppoly0\_e\_l, ppoly0\_e\_r, method, khtr\_u, f\_layer)}
\DoxyCodeLine{1100   near\_boundary\_unit\_tests = near\_boundary\_unit\_tests .or. \&}
\DoxyCodeLine{1101                              test\_layer\_fluxes( verbose, nk, test\_name, f\_layer, (/-3.75,0.0/) )}

\end{DoxyCode}
\mbox{\Hypertarget{namespacemom__lateral__boundary__diffusion_ac7d1d46aeb36ab434b1a6533b47246ce}\label{namespacemom__lateral__boundary__diffusion_ac7d1d46aeb36ab434b1a6533b47246ce}} 
\index{mom\_lateral\_boundary\_diffusion@{mom\_lateral\_boundary\_diffusion}!test\_boundary\_k\_range@{test\_boundary\_k\_range}}
\index{test\_boundary\_k\_range@{test\_boundary\_k\_range}!mom\_lateral\_boundary\_diffusion@{mom\_lateral\_boundary\_diffusion}}
\subsubsection{\texorpdfstring{test\_boundary\_k\_range()}{test\_boundary\_k\_range()}}
{\footnotesize\ttfamily logical function mom\+\_\+lateral\+\_\+boundary\+\_\+diffusion\+::test\+\_\+boundary\+\_\+k\+\_\+range (\begin{DoxyParamCaption}\item[{integer}]{k\+\_\+top,  }\item[{real}]{zeta\+\_\+top,  }\item[{integer}]{k\+\_\+bot,  }\item[{real}]{zeta\+\_\+bot,  }\item[{integer}]{k\+\_\+top\+\_\+ans,  }\item[{real}]{zeta\+\_\+top\+\_\+ans,  }\item[{integer}]{k\+\_\+bot\+\_\+ans,  }\item[{real}]{zeta\+\_\+bot\+\_\+ans,  }\item[{character(len=80)}]{test\+\_\+name,  }\item[{logical}]{verbose }\end{DoxyParamCaption})\hspace{0.3cm}{\ttfamily [private]}}



Return true if output of unit tests for boundary\+\_\+k\+\_\+range does not match answers. 


\begin{DoxyParams}{Parameters}
{\em k\+\_\+top} & Index of cell containing top of boundary \\
\hline
{\em zeta\+\_\+top} & Nondimension position \\
\hline
{\em k\+\_\+bot} & Index of cell containing bottom of boundary \\
\hline
{\em zeta\+\_\+bot} & Nondimension position \\
\hline
{\em k\+\_\+top\+\_\+ans} & Index of cell containing top of boundary \\
\hline
{\em zeta\+\_\+top\+\_\+ans} & Nondimension position \\
\hline
{\em k\+\_\+bot\+\_\+ans} & Index of cell containing bottom of boundary \\
\hline
{\em zeta\+\_\+bot\+\_\+ans} & Nondimension position \\
\hline
{\em test\+\_\+name} & Name of the unit test \\
\hline
{\em verbose} & If true always print output \\
\hline
\end{DoxyParams}


Definition at line 1133 of file M\+O\+M\+\_\+lateral\+\_\+boundary\+\_\+diffusion.\+F90.


\begin{DoxyCode}{0}
\DoxyCodeLine{1133   \textcolor{keywordtype}{integer} :: k\_top\textcolor{comment}{               !< Index of cell containing top of boundary}}
\DoxyCodeLine{1134 \textcolor{keywordtype}{  real}    :: zeta\_top\textcolor{comment}{            !< Nondimension position}}
\DoxyCodeLine{1135   \textcolor{keywordtype}{integer} :: k\_bot\textcolor{comment}{               !< Index of cell containing bottom of boundary}}
\DoxyCodeLine{1136 \textcolor{keywordtype}{  real}    :: zeta\_bot\textcolor{comment}{            !< Nondimension position}}
\DoxyCodeLine{1137   \textcolor{keywordtype}{integer} :: k\_top\_ans\textcolor{comment}{           !< Index of cell containing top of boundary}}
\DoxyCodeLine{1138 \textcolor{keywordtype}{  real}    :: zeta\_top\_ans\textcolor{comment}{        !< Nondimension position}}
\DoxyCodeLine{1139   \textcolor{keywordtype}{integer} :: k\_bot\_ans\textcolor{comment}{           !< Index of cell containing bottom of boundary}}
\DoxyCodeLine{1140 \textcolor{keywordtype}{  real}    :: zeta\_bot\_ans\textcolor{comment}{        !< Nondimension position}}
\DoxyCodeLine{1141   \textcolor{keywordtype}{character(len=80)} :: test\_name\textcolor{comment}{ !< Name of the unit test}}
\DoxyCodeLine{1142   \textcolor{keywordtype}{logical} :: verbose\textcolor{comment}{             !< If true always print output}}
\DoxyCodeLine{1143 }
\DoxyCodeLine{1144   \textcolor{keywordtype}{integer}, \textcolor{keywordtype}{parameter} :: stdunit = stdout}
\DoxyCodeLine{1145 }
\DoxyCodeLine{1146   test\_boundary\_k\_range = k\_top .ne. k\_top\_ans}
\DoxyCodeLine{1147   test\_boundary\_k\_range = test\_boundary\_k\_range .or. (zeta\_top .ne. zeta\_top\_ans)}
\DoxyCodeLine{1148   test\_boundary\_k\_range = test\_boundary\_k\_range .or. (k\_bot .ne. k\_bot\_ans)}
\DoxyCodeLine{1149   test\_boundary\_k\_range = test\_boundary\_k\_range .or. (zeta\_bot .ne. zeta\_bot\_ans)}
\DoxyCodeLine{1150 }
\DoxyCodeLine{1151   \textcolor{keywordflow}{if} (test\_boundary\_k\_range) \textcolor{keyword}{write}(stdunit,*) \textcolor{stringliteral}{"UNIT TEST FAILED: "}, test\_name}
\DoxyCodeLine{1152   \textcolor{keywordflow}{if} (test\_boundary\_k\_range .or. verbose) \textcolor{keywordflow}{then}}
\DoxyCodeLine{1153     \textcolor{keyword}{write}(stdunit,20) \textcolor{stringliteral}{"k\_top"}, k\_top, \textcolor{stringliteral}{"k\_top\_ans"}, k\_top\_ans}
\DoxyCodeLine{1154     \textcolor{keyword}{write}(stdunit,20) \textcolor{stringliteral}{"k\_bot"}, k\_bot, \textcolor{stringliteral}{"k\_bot\_ans"}, k\_bot\_ans}
\DoxyCodeLine{1155     \textcolor{keyword}{write}(stdunit,30) \textcolor{stringliteral}{"zeta\_top"}, zeta\_top, \textcolor{stringliteral}{"zeta\_top\_ans"}, zeta\_top\_ans}
\DoxyCodeLine{1156     \textcolor{keyword}{write}(stdunit,30) \textcolor{stringliteral}{"zeta\_bot"}, zeta\_bot, \textcolor{stringliteral}{"zeta\_bot\_ans"}, zeta\_bot\_ans}
\DoxyCodeLine{1157 \textcolor{keywordflow}{  endif}}
\DoxyCodeLine{1158 }
\DoxyCodeLine{1159   20 \textcolor{keyword}{format}(a,\textcolor{stringliteral}{"="},i3,x,a,\textcolor{stringliteral}{"="},i3)}
\DoxyCodeLine{1160   30 \textcolor{keyword}{format}(a,\textcolor{stringliteral}{"="},f20.16,x,a,\textcolor{stringliteral}{"="},f20.16)}
\DoxyCodeLine{1161 }
\DoxyCodeLine{1162 }

\end{DoxyCode}
\mbox{\Hypertarget{namespacemom__lateral__boundary__diffusion_a9c689c24bc59f46aa960b33119fe7e59}\label{namespacemom__lateral__boundary__diffusion_a9c689c24bc59f46aa960b33119fe7e59}} 
\index{mom\_lateral\_boundary\_diffusion@{mom\_lateral\_boundary\_diffusion}!test\_layer\_fluxes@{test\_layer\_fluxes}}
\index{test\_layer\_fluxes@{test\_layer\_fluxes}!mom\_lateral\_boundary\_diffusion@{mom\_lateral\_boundary\_diffusion}}
\subsubsection{\texorpdfstring{test\_layer\_fluxes()}{test\_layer\_fluxes()}}
{\footnotesize\ttfamily logical function mom\+\_\+lateral\+\_\+boundary\+\_\+diffusion\+::test\+\_\+layer\+\_\+fluxes (\begin{DoxyParamCaption}\item[{logical, intent(in)}]{verbose,  }\item[{integer, intent(in)}]{nk,  }\item[{character(len=80), intent(in)}]{test\+\_\+name,  }\item[{real, dimension(nk), intent(in)}]{F\+\_\+calc,  }\item[{real, dimension(nk), intent(in)}]{F\+\_\+ans }\end{DoxyParamCaption})\hspace{0.3cm}{\ttfamily [private]}}



Returns true if output of near-\/boundary unit tests does not match correct computed values and conditionally writes results to stream. 


\begin{DoxyParams}[1]{Parameters}
\mbox{\texttt{ in}}  & {\em verbose} & If true, write results to stdout \\
\hline
\mbox{\texttt{ in}}  & {\em test\+\_\+name} & Brief description of the unit test \\
\hline
\mbox{\texttt{ in}}  & {\em nk} & Number of layers \\
\hline
\mbox{\texttt{ in}}  & {\em f\+\_\+calc} & Fluxes of the unitless tracer from the algorithm \mbox{[}s$^\wedge$-\/1\mbox{]} \\
\hline
\mbox{\texttt{ in}}  & {\em f\+\_\+ans} & Fluxes of the unitless tracer calculated by hand \mbox{[}s$^\wedge$-\/1\mbox{]} \\
\hline
\end{DoxyParams}


Definition at line 1107 of file M\+O\+M\+\_\+lateral\+\_\+boundary\+\_\+diffusion.\+F90.


\begin{DoxyCode}{0}
\DoxyCodeLine{1107   \textcolor{keywordtype}{logical},                    \textcolor{keywordtype}{intent(in)} :: verbose\textcolor{comment}{   !< If true, write results to stdout}}
\DoxyCodeLine{1108   \textcolor{keywordtype}{character(len=80)},          \textcolor{keywordtype}{intent(in)} :: test\_name\textcolor{comment}{ !< Brief description of the unit test}}
\DoxyCodeLine{1109   \textcolor{keywordtype}{integer},                    \textcolor{keywordtype}{intent(in)} :: nk\textcolor{comment}{        !< Number of layers}}
\DoxyCodeLine{1110 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(nk)},        \textcolor{keywordtype}{intent(in)} :: F\_calc\textcolor{comment}{    !< Fluxes of the unitless tracer from the algorithm [s\string^-1]}}
\DoxyCodeLine{1111 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(nk)},        \textcolor{keywordtype}{intent(in)} :: F\_ans\textcolor{comment}{     !< Fluxes of the unitless tracer calculated by hand [s\string^-1]}}
\DoxyCodeLine{1112   \textcolor{comment}{! Local variables}}
\DoxyCodeLine{1113   \textcolor{keywordtype}{integer} :: k}
\DoxyCodeLine{1114   \textcolor{keywordtype}{integer}, \textcolor{keywordtype}{parameter} :: stdunit = stdout}
\DoxyCodeLine{1115 }
\DoxyCodeLine{1116   test\_layer\_fluxes = .false.}
\DoxyCodeLine{1117   \textcolor{keywordflow}{do} k=1,nk}
\DoxyCodeLine{1118     \textcolor{keywordflow}{if} ( f\_calc(k) /= f\_ans(k) ) \textcolor{keywordflow}{then}}
\DoxyCodeLine{1119       test\_layer\_fluxes = .true.}
\DoxyCodeLine{1120       \textcolor{keyword}{write}(stdunit,*) \textcolor{stringliteral}{"MOM\_lateral\_boundary\_diffusion, UNIT TEST FAILED: "}, test\_name}
\DoxyCodeLine{1121       \textcolor{keyword}{write}(stdunit,10) k, f\_calc(k), f\_ans(k)}
\DoxyCodeLine{1122     \textcolor{keywordflow}{elseif} (verbose) \textcolor{keywordflow}{then}}
\DoxyCodeLine{1123       \textcolor{keyword}{write}(stdunit,10) k, f\_calc(k), f\_ans(k)}
\DoxyCodeLine{1124 \textcolor{keywordflow}{    endif}}
\DoxyCodeLine{1125 \textcolor{keywordflow}{  enddo}}
\DoxyCodeLine{1126 }
\DoxyCodeLine{1127 10 \textcolor{keyword}{format}(\textcolor{stringliteral}{"Layer="},i3,\textcolor{stringliteral}{" F\_calc="},f20.16,\textcolor{stringliteral}{" F\_ans"},f20.16)}

\end{DoxyCode}
