\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 \hyperlink{namespacemom__lateral__boundary__diffusion_section_method2}{Method \#1\+: Along layer} (default);
\item \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 \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 \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 \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 \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 \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 \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 \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 \hyperlink{namespacemom__lateral__boundary__diffusion_a6c98f54ad462ab45918fdccc0b403948}{harmonic\+\_\+mean} (h1, h2)
\begin{DoxyCompactList}\small\item\em Calculate the harmonic mean of two quantities See \hyperlink{namespacemom__lateral__boundary__diffusion_section_harmonic_mean}{Harmonic Mean}. \end{DoxyCompactList}\item 
subroutine, public \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 \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 \hyperlink{namespacemom__lateral__boundary__diffusion_section_method1}{Along layer approach (Method \#1)}. \end{DoxyCompactList}\item 
subroutine \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 \hyperlink{namespacemom__lateral__boundary__diffusion_section_method2}{Bulk layer approach (Method \#2)}. \end{DoxyCompactList}\item 
logical function, public \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 \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 \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 \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 \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) \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{\tt in}  & {\em boundary} & S\+U\+R\+F\+A\+CE or B\+O\+T\+T\+OM \mbox{[}nondim\mbox{]}\\
\hline
\mbox{\tt in}  & {\em nk} & Number of layers \mbox{[}nondim\mbox{]}\\
\hline
\mbox{\tt in}  & {\em h} & Layer thicknesses of the column \mbox{[}H $\sim$$>$ m or kg m-\/2\mbox{]}\\
\hline
\mbox{\tt 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{\tt out}  & {\em k\+\_\+top} & Index of the first layer within the boundary\\
\hline
\mbox{\tt 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{\tt out}  & {\em k\+\_\+bot} & Index of the last layer within the boundary\\
\hline
\mbox{\tt 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}
375   \textcolor{keywordtype}{integer},             \textcolor{keywordtype}{intent(in   )} :: boundary\textcolor{comment}{ !< SURFACE or BOTTOM                       [nondim]}
376   \textcolor{keywordtype}{integer},             \textcolor{keywordtype}{intent(in   )} :: nk\textcolor{comment}{       !< Number of layers                        [nondim]}
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]}
378   \textcolor{keywordtype}{real},                \textcolor{keywordtype}{intent(in   )} :: hbl\textcolor{comment}{      !< Thickness of the boundary layer         [H ~> m or kg
       m-2]}
379 \textcolor{comment}{                                                 !! If surface, with respect to zbl\_ref = 0.}
380 \textcolor{comment}{                                                 !! If bottom, with respect to zbl\_ref = SUM(h)}
381   \textcolor{keywordtype}{integer},             \textcolor{keywordtype}{intent(  out)} :: k\_top\textcolor{comment}{    !< Index of the first layer within the boundary}
382   \textcolor{keywordtype}{real},                \textcolor{keywordtype}{intent(  out)} :: zeta\_top\textcolor{comment}{ !< Distance from the top of a layer to the intersection of
       the}
383 \textcolor{comment}{                                                 !! top extent of the boundary layer (0 at top, 1 at
       bottom)  [nondim]}
384   \textcolor{keywordtype}{integer},             \textcolor{keywordtype}{intent(  out)} :: k\_bot\textcolor{comment}{    !< Index of the last layer within the boundary}
385   \textcolor{keywordtype}{real},                \textcolor{keywordtype}{intent(  out)} :: zeta\_bot\textcolor{comment}{ !< Distance of the lower layer to the boundary layer depth}
386 \textcolor{comment}{                                                 !! (0 at top, 1 at bottom)  [nondim]}
387   \textcolor{comment}{! Local variables}
388   \textcolor{keywordtype}{real} :: htot \textcolor{comment}{! Summed thickness [H ~> m or kg m-2]}
389   \textcolor{keywordtype}{integer} :: k
390   \textcolor{comment}{! Surface boundary layer}
391   \textcolor{keywordflow}{if} ( boundary == surface ) \textcolor{keywordflow}{then}
392     k\_top = 1
393     zeta\_top = 0.
394     htot = 0.
395     k\_bot = 1
396     zeta\_bot = 0.
397     \textcolor{keywordflow}{if} (hbl == 0.) \textcolor{keywordflow}{return}
398     \textcolor{keywordflow}{if} (hbl >= sum(h(:))) \textcolor{keywordflow}{then}
399       k\_bot = nk
400       zeta\_bot = 1.
401       \textcolor{keywordflow}{return}
402 \textcolor{keywordflow}{    endif}
403     \textcolor{keywordflow}{do} k=1,nk
404       htot = htot + h(k)
405       \textcolor{keywordflow}{if} ( htot >= hbl) \textcolor{keywordflow}{then}
406         k\_bot = k
407         zeta\_bot = 1 - (htot - hbl)/h(k)
408         \textcolor{keywordflow}{return}
409 \textcolor{keywordflow}{      endif}
410 \textcolor{keywordflow}{    enddo}
411   \textcolor{comment}{! Bottom boundary layer}
412   \textcolor{keywordflow}{elseif} ( boundary == bottom ) \textcolor{keywordflow}{then}
413     k\_top = nk
414     zeta\_top = 1.
415     k\_bot = nk
416     zeta\_bot = 0.
417     htot = 0.
418     \textcolor{keywordflow}{if} (hbl == 0.) \textcolor{keywordflow}{return}
419     \textcolor{keywordflow}{if} (hbl >= sum(h(:))) \textcolor{keywordflow}{then}
420       k\_top = 1
421       zeta\_top = 1.
422       \textcolor{keywordflow}{return}
423 \textcolor{keywordflow}{    endif}
424     \textcolor{keywordflow}{do} k=nk,1,-1
425       htot = htot + h(k)
426       \textcolor{keywordflow}{if} (htot >= hbl) \textcolor{keywordflow}{then}
427         k\_top = k
428         zeta\_top = 1 - (htot - hbl)/h(k)
429         \textcolor{keywordflow}{return}
430 \textcolor{keywordflow}{      endif}
431 \textcolor{keywordflow}{    enddo}
432   \textcolor{keywordflow}{else}
433     \textcolor{keyword}{call }mom\_error(fatal,\textcolor{stringliteral}{"Houston, we've had a problem in boundary\_k\_range"})
434 \textcolor{keywordflow}{  endif}
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}
312   \textcolor{keywordtype}{integer}             :: boundary\textcolor{comment}{          !< SURFACE or BOTTOM                                    
       [nondim]}
313   \textcolor{keywordtype}{integer}             :: nk\textcolor{comment}{                !< Number of layers                                     
       [nondim]}
314   \textcolor{keywordtype}{integer}             :: deg\textcolor{comment}{               !< Degree of polynomial                                 
       [nondim]}
315   \textcolor{keywordtype}{real}, \textcolor{keywordtype}{dimension(nk)} :: h\textcolor{comment}{                 !< Layer thicknesses                                     [H ~> m
       or kg m-2]}
316   \textcolor{keywordtype}{real}                :: hblt\textcolor{comment}{              !< Depth of the boundary layer                           [H ~> m
       or kg m-2]}
317   \textcolor{keywordtype}{real}, \textcolor{keywordtype}{dimension(nk)} :: phi\textcolor{comment}{               !< Scalar quantity}
318   \textcolor{keywordtype}{real}, \textcolor{keywordtype}{dimension(nk,2)}     :: ppoly0\_e\textcolor{comment}{    !< Edge value of polynomial}
319   \textcolor{keywordtype}{real}, \textcolor{keywordtype}{dimension(nk,deg+1)} :: ppoly0\_coefs\textcolor{comment}{!< Coefficients of polynomial}
320   \textcolor{keywordtype}{integer}                   :: method\textcolor{comment}{      !< Remapping scheme to use}
321 
322   \textcolor{keywordtype}{integer}             :: k\_top\textcolor{comment}{             !< Index of the first layer within the boundary}
323   \textcolor{keywordtype}{real}                :: zeta\_top\textcolor{comment}{          !< Fraction of the layer encompassed by the bottom boundary
       layer}
324 \textcolor{comment}{                                           !! (0 if none, 1. if all). For the surface, this is always 0.
       because}
325 \textcolor{comment}{                                           !! integration starts at the surface                    
       [nondim]}
326   \textcolor{keywordtype}{integer}             :: k\_bot\textcolor{comment}{             !< Index of the last layer within the boundary}
327   \textcolor{keywordtype}{real}                :: zeta\_bot\textcolor{comment}{          !< Fraction of the layer encompassed by the surface boundary
       layer}
328 \textcolor{comment}{                                           !! (0 if none, 1. if all). For the bottom boundary layer, this
       is always 1.}
329 \textcolor{comment}{                                           !! because integration starts at the bottom             
       [nondim]}
330   \textcolor{comment}{! Local variables}
331   \textcolor{keywordtype}{real}    :: htot\textcolor{comment}{ !< Running sum of the thicknesses (top to bottom)}
332   \textcolor{keywordtype}{integer} :: k\textcolor{comment}{    !< k indice}
333 
334 
335   htot = 0.
336   bulk\_average = 0.
337   \textcolor{keywordflow}{if} (hblt == 0.) \textcolor{keywordflow}{return}
338   \textcolor{keywordflow}{if} (boundary == surface) \textcolor{keywordflow}{then}
339     htot = (h(k\_bot) * zeta\_bot)
340     bulk\_average = average\_value\_ppoly( nk, phi, ppoly0\_e, ppoly0\_coefs, method, k\_bot, 0., zeta\_bot) * 
      htot
341     \textcolor{keywordflow}{do} k = k\_bot-1,1,-1
342       bulk\_average = bulk\_average + phi(k)*h(k)
343       htot = htot + h(k)
344 \textcolor{keywordflow}{    enddo}
345   \textcolor{keywordflow}{elseif} (boundary == bottom) \textcolor{keywordflow}{then}
346     htot = (h(k\_top) * zeta\_top)
347     \textcolor{comment}{! (note 1-zeta\_top because zeta\_top is the fraction of the layer)}
348     bulk\_average = average\_value\_ppoly( nk, phi, ppoly0\_e, ppoly0\_coefs, method, k\_top, (1.-zeta\_top), 1.) 
      * htot
349     \textcolor{keywordflow}{do} k = k\_top+1,nk
350       bulk\_average = bulk\_average + phi(k)*h(k)
351       htot = htot + h(k)
352 \textcolor{keywordflow}{    enddo}
353   \textcolor{keywordflow}{else}
354     \textcolor{keyword}{call }mom\_error(fatal, \textcolor{stringliteral}{"bulk\_average: a valid boundary type must be provided."})
355 \textcolor{keywordflow}{  endif}
356 
357   bulk\_average = bulk\_average / hblt
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 \hyperlink{namespacemom__lateral__boundary__diffusion_section_method2}{Bulk layer approach (Method \#2)}. 


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


\begin{DoxyParams}[1]{Parameters}
\mbox{\tt in}  & {\em boundary} & Which boundary layer S\+U\+R\+F\+A\+CE or B\+O\+T\+T\+OM \mbox{[}nondim\mbox{]}\\
\hline
\mbox{\tt in}  & {\em nk} & Number of layers \mbox{[}nondim\mbox{]}\\
\hline
\mbox{\tt in}  & {\em deg} & order of the polynomial reconstruction \mbox{[}nondim\mbox{]}\\
\hline
\mbox{\tt in}  & {\em h\+\_\+l} & Layer thickness (left) \mbox{[}H $\sim$$>$ m or kg m-\/2\mbox{]}\\
\hline
\mbox{\tt in}  & {\em h\+\_\+r} & Layer thickness (right) \mbox{[}H $\sim$$>$ m or kg m-\/2\mbox{]}\\
\hline
\mbox{\tt in}  & {\em hbl\+\_\+l} & Thickness of the boundary boundary layer (left) \mbox{[}H $\sim$$>$ m or kg m-\/2\mbox{]}\\
\hline
\mbox{\tt in}  & {\em hbl\+\_\+r} & Thickness of the boundary boundary layer (right) \mbox{[}H $\sim$$>$ m or kg m-\/2\mbox{]}\\
\hline
\mbox{\tt in}  & {\em area\+\_\+l} & Area of the horizontal grid (left) \mbox{[}L2 $\sim$$>$ m2\mbox{]}\\
\hline
\mbox{\tt in}  & {\em area\+\_\+r} & Area of the horizontal grid (right) \mbox{[}L2 $\sim$$>$ m2\mbox{]}\\
\hline
\mbox{\tt in}  & {\em phi\+\_\+l} & Tracer values (left) \mbox{[}conc\mbox{]}\\
\hline
\mbox{\tt in}  & {\em phi\+\_\+r} & Tracer values (right) \mbox{[}conc\mbox{]}\\
\hline
\mbox{\tt in}  & {\em ppoly0\+\_\+coefs\+\_\+l} & Tracer reconstruction (left) \mbox{[}conc\mbox{]}\\
\hline
\mbox{\tt in}  & {\em ppoly0\+\_\+coefs\+\_\+r} & Tracer reconstruction (right) \mbox{[}conc\mbox{]}\\
\hline
\mbox{\tt in}  & {\em ppoly0\+\_\+e\+\_\+l} & Polynomial edge values (left) \mbox{[}nondim\mbox{]}\\
\hline
\mbox{\tt in}  & {\em ppoly0\+\_\+e\+\_\+r} & Polynomial edge values (right) \mbox{[}nondim\mbox{]}\\
\hline
\mbox{\tt in}  & {\em method} & Method of polynomial integration \mbox{[}nondim\mbox{]}\\
\hline
\mbox{\tt in}  & {\em khtr\+\_\+u} & Horizontal diffusivities times delta t at a velocity point \mbox{[}L2 $\sim$$>$ m2\mbox{]}\\
\hline
\mbox{\tt out}  & {\em f\+\_\+layer} & Layerwise diffusive flux at U-\/ or V-\/point \mbox{[}H L2 conc $\sim$$>$ m3 conc\mbox{]}\\
\hline
\mbox{\tt 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}
444 
445   \textcolor{keywordtype}{integer},                   \textcolor{keywordtype}{intent(in   )}       :: boundary\textcolor{comment}{ !< Which boundary layer SURFACE or BOTTOM 
       [nondim]}
446   \textcolor{keywordtype}{integer},                   \textcolor{keywordtype}{intent(in   )}       :: nk\textcolor{comment}{       !< Number of layers                       
       [nondim]}
447   \textcolor{keywordtype}{integer},                   \textcolor{keywordtype}{intent(in   )}       :: deg\textcolor{comment}{      !< order of the polynomial reconstruction 
       [nondim]}
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]}
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]}
450   \textcolor{keywordtype}{real},                      \textcolor{keywordtype}{intent(in   )}       :: hbl\_l\textcolor{comment}{    !< Thickness of the boundary boundary}
451 \textcolor{comment}{                                                                       !! layer (left)              [H ~> m
       or kg m-2]}
452   \textcolor{keywordtype}{real},                      \textcolor{keywordtype}{intent(in   )}       :: hbl\_r\textcolor{comment}{    !< Thickness of the boundary boundary}
453 \textcolor{comment}{                                                             !! layer (right)                       [H ~> m
       or kg m-2]}
454   \textcolor{keywordtype}{real},                      \textcolor{keywordtype}{intent(in   )}       :: area\_l\textcolor{comment}{   !< Area of the horizontal grid (left)  [L2 ~>
       m2]}
455   \textcolor{keywordtype}{real},                      \textcolor{keywordtype}{intent(in   )}       :: area\_r\textcolor{comment}{   !< Area of the horizontal grid (right) [L2 ~>
       m2]}
456   \textcolor{keywordtype}{real}, \textcolor{keywordtype}{dimension(nk)},       \textcolor{keywordtype}{intent(in   )}       :: phi\_l\textcolor{comment}{    !< Tracer values (left)                [conc]}
457   \textcolor{keywordtype}{real}, \textcolor{keywordtype}{dimension(nk)},       \textcolor{keywordtype}{intent(in   )}       :: phi\_r\textcolor{comment}{    !< Tracer values (right)               [conc]}
458   \textcolor{keywordtype}{real}, \textcolor{keywordtype}{dimension(nk,deg+1)}, \textcolor{keywordtype}{intent(in   )}       :: ppoly0\_coefs\_l\textcolor{comment}{ !< Tracer reconstruction (left)  [conc]}
459   \textcolor{keywordtype}{real}, \textcolor{keywordtype}{dimension(nk,deg+1)}, \textcolor{keywordtype}{intent(in   )}       :: ppoly0\_coefs\_r\textcolor{comment}{ !< Tracer reconstruction (right) [conc]}
460   \textcolor{keywordtype}{real}, \textcolor{keywordtype}{dimension(nk,2)},     \textcolor{keywordtype}{intent(in   )}       :: ppoly0\_e\_l\textcolor{comment}{ !< Polynomial edge values (left)    
       [nondim]}
461   \textcolor{keywordtype}{real}, \textcolor{keywordtype}{dimension(nk,2)},     \textcolor{keywordtype}{intent(in   )}       :: ppoly0\_e\_r\textcolor{comment}{ !< Polynomial edge values (right)   
       [nondim]}
462   \textcolor{keywordtype}{integer},                   \textcolor{keywordtype}{intent(in   )}       :: method\textcolor{comment}{   !< Method of polynomial integration   
       [nondim]}
463   \textcolor{keywordtype}{real},                      \textcolor{keywordtype}{intent(in   )}       :: khtr\_u\textcolor{comment}{   !< Horizontal diffusivities times delta t}
464 \textcolor{comment}{                                                             !! at a velocity point [L2 ~> m2]}
465   \textcolor{keywordtype}{real}, \textcolor{keywordtype}{dimension(nk)},       \textcolor{keywordtype}{intent(  out)}       :: f\_layer\textcolor{comment}{  !< Layerwise diffusive flux at U- or V-point}
466 \textcolor{comment}{                                                             !! [H L2 conc ~> m3 conc]}
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}
468 \textcolor{comment}{                                                             !! the boundary layer}
469   \textcolor{comment}{! Local variables}
470   \textcolor{keywordtype}{real}, \textcolor{keywordtype}{dimension(nk)} :: h\_means\textcolor{comment}{              !< Calculate the layer-wise harmonic means           [H ~> m
       or kg m-2]}
471   \textcolor{keywordtype}{real}                :: khtr\_avg\textcolor{comment}{             !< Thickness-weighted diffusivity at the u-point     [m^2
       s^-1]}
472 \textcolor{comment}{                                              !! This is just to remind developers that khtr\_avg should be}
473 \textcolor{comment}{                                              !! computed once khtr is 3D.}
474   \textcolor{keywordtype}{real}                :: heff\textcolor{comment}{                 !< Harmonic mean of layer thicknesses           [H ~> m or kg
       m-2]}
475   \textcolor{keywordtype}{real}                :: inv\_heff\textcolor{comment}{             !< Inverse of the harmonic mean of layer thicknesses}
476 \textcolor{comment}{                                              !!  [H-1 ~> m-1 or m2 kg-1]}
477   \textcolor{keywordtype}{real}                :: phi\_l\_avg, phi\_r\_avg\textcolor{comment}{ !< Bulk, thickness-weighted tracer averages (left and right
       column)}
478 \textcolor{comment}{                                              !!                                                   [conc
       m^-3 ]}
479   \textcolor{keywordtype}{real}    :: htot\textcolor{comment}{                      !< Total column thickness [H ~> m or kg m-2]}
480   \textcolor{keywordtype}{real}    :: heff\_tot\textcolor{comment}{                  !< Total effective column thickness in the transition layer [m]}
481   \textcolor{keywordtype}{integer} :: k, k\_bot\_min, k\_top\_max\textcolor{comment}{   !< k-indices, min and max for bottom and top, respectively}
482   \textcolor{keywordtype}{integer} :: k\_bot\_max, k\_top\_min\textcolor{comment}{      !< k-indices, max and min for bottom and top, respectively}
483   \textcolor{keywordtype}{integer} :: k\_bot\_diff, k\_top\_diff\textcolor{comment}{    !< different between left and right k-indices for bottom and top,
       respectively}
484   \textcolor{keywordtype}{integer} :: k\_top\_l, k\_bot\_l\textcolor{comment}{          !< k-indices left}
485   \textcolor{keywordtype}{integer} :: k\_top\_r, k\_bot\_r\textcolor{comment}{          !< k-indices right}
486   \textcolor{keywordtype}{real}    :: zeta\_top\_l, zeta\_top\_r\textcolor{comment}{    !< distance from the top of a layer to the boundary}
487 \textcolor{comment}{                                       !! layer depth                                     [nondim]}
488   \textcolor{keywordtype}{real}    :: zeta\_bot\_l, zeta\_bot\_r\textcolor{comment}{    !< distance from the bottom of a layer to the boundary}
489 \textcolor{comment}{                                       !!layer depth                                      [nondim]}
490   \textcolor{keywordtype}{real}    :: h\_work\_l, h\_work\_r\textcolor{comment}{  !< dummy variables}
491   \textcolor{keywordtype}{real}    :: hbl\_min\textcolor{comment}{             !< minimum BLD (left and right)                          [m]}
492   \textcolor{keywordtype}{real}    :: wgt\textcolor{comment}{                 !< weight to be used in the linear transition to the interior [nondim]}
493   \textcolor{keywordtype}{real}    :: a\textcolor{comment}{                   !< coefficient to be used in the linear transition to the interior
       [nondim]}
494   \textcolor{keywordtype}{logical} :: linear\textcolor{comment}{              !< True if apply a linear transition}
495 
496   f\_layer(:) = 0.0
497   \textcolor{keywordflow}{if} (hbl\_l == 0. .or. hbl\_r == 0.) \textcolor{keywordflow}{then}
498     \textcolor{keywordflow}{return}
499 \textcolor{keywordflow}{  endif}
500 
501   linear = .false.
502   \textcolor{keywordflow}{if} (\textcolor{keyword}{PRESENT}(linear\_decay)) \textcolor{keywordflow}{then}
503     linear = linear\_decay
504 \textcolor{keywordflow}{  endif}
505 
506   \textcolor{comment}{! Calculate vertical indices containing the boundary layer}
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)
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)
509 
510   \textcolor{keywordflow}{if} (boundary == surface) \textcolor{keywordflow}{then}
511     k\_bot\_min = min(k\_bot\_l, k\_bot\_r)
512     k\_bot\_max = max(k\_bot\_l, k\_bot\_r)
513     k\_bot\_diff = (k\_bot\_max - k\_bot\_min)
514 
515     \textcolor{comment}{! make sure left and right k indices span same range}
516     \textcolor{keywordflow}{if} (k\_bot\_min .ne. k\_bot\_l) \textcolor{keywordflow}{then}
517       k\_bot\_l = k\_bot\_min
518       zeta\_bot\_l = 1.0
519 \textcolor{keywordflow}{    endif}
520     \textcolor{keywordflow}{if} (k\_bot\_min .ne. k\_bot\_r) \textcolor{keywordflow}{then}
521       k\_bot\_r= k\_bot\_min
522       zeta\_bot\_r = 1.0
523 \textcolor{keywordflow}{    endif}
524 
525     h\_work\_l = (h\_l(k\_bot\_l) * zeta\_bot\_l)
526     h\_work\_r = (h\_r(k\_bot\_r) * zeta\_bot\_r)
527 
528     phi\_l\_avg = average\_value\_ppoly( nk, phi\_l, ppoly0\_e\_l, ppoly0\_coefs\_l, method, k\_bot\_l, 0., zeta\_bot\_l
      )
529     phi\_r\_avg = average\_value\_ppoly( nk, phi\_r, ppoly0\_e\_r, ppoly0\_coefs\_r, method, k\_bot\_r, 0., zeta\_bot\_r
      )
530     heff = harmonic\_mean(h\_work\_l, h\_work\_r)
531     \textcolor{comment}{! tracer flux where the minimum BLD intersets layer}
532     \textcolor{comment}{! GMM, khtr\_avg should be computed once khtr is 3D}
533     \textcolor{keywordflow}{if} ((linear) .and. (k\_bot\_diff .gt. 1)) \textcolor{keywordflow}{then}
534       \textcolor{comment}{! apply linear decay at the base of hbl}
535       \textcolor{keywordflow}{do} k = k\_bot\_min,1,-1
536         heff = harmonic\_mean(h\_l(k), h\_r(k))
537         f\_layer(k) = -(heff * khtr\_u) * (phi\_r(k) - phi\_l(k))
538 \textcolor{keywordflow}{      enddo}
539       \textcolor{comment}{! heff\_total}
540       heff\_tot = 0.0
541       \textcolor{keywordflow}{do} k = k\_bot\_min+1,k\_bot\_max, 1
542         heff\_tot = heff\_tot + harmonic\_mean(h\_l(k), h\_r(k))
543 \textcolor{keywordflow}{      enddo}
544 
545       a = -1.0/heff\_tot
546       heff\_tot = 0.0
547       \textcolor{keywordflow}{do} k = k\_bot\_min+1,k\_bot\_max, 1
548         heff = harmonic\_mean(h\_l(k), h\_r(k))
549         wgt = (a*(heff\_tot + (heff * 0.5))) + 1.0
550         f\_layer(k) = -(heff * khtr\_u) * (phi\_r(k) - phi\_l(k)) * wgt
551         heff\_tot = heff\_tot + heff
552 \textcolor{keywordflow}{      enddo}
553     \textcolor{keywordflow}{else}
554       f\_layer(k\_bot\_min) = -(heff * khtr\_u) * (phi\_r\_avg - phi\_l\_avg)
555       \textcolor{keywordflow}{do} k = k\_bot\_min-1,1,-1
556         heff = harmonic\_mean(h\_l(k), h\_r(k))
557         f\_layer(k) = -(heff * khtr\_u) * (phi\_r(k) - phi\_l(k))
558 \textcolor{keywordflow}{      enddo}
559 \textcolor{keywordflow}{    endif}
560 \textcolor{keywordflow}{  endif}
561 
562   \textcolor{keywordflow}{if} (boundary == bottom) \textcolor{keywordflow}{then}
563     \textcolor{comment}{! TODO: GMM add option to apply linear decay}
564     k\_top\_max = max(k\_top\_l, k\_top\_r)
565     \textcolor{comment}{! make sure left and right k indices span same range}
566     \textcolor{keywordflow}{if} (k\_top\_max .ne. k\_top\_l) \textcolor{keywordflow}{then}
567       k\_top\_l = k\_top\_max
568       zeta\_top\_l = 1.0
569 \textcolor{keywordflow}{    endif}
570     \textcolor{keywordflow}{if} (k\_top\_max .ne. k\_top\_r) \textcolor{keywordflow}{then}
571       k\_top\_r= k\_top\_max
572       zeta\_top\_r = 1.0
573 \textcolor{keywordflow}{    endif}
574 
575     h\_work\_l = (h\_l(k\_top\_l) * zeta\_top\_l)
576     h\_work\_r = (h\_r(k\_top\_r) * zeta\_top\_r)
577 
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)
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)
580     heff = harmonic\_mean(h\_work\_l, h\_work\_r)
581 
582     \textcolor{comment}{! tracer flux where the minimum BLD intersets layer}
583     f\_layer(k\_top\_max) = (-heff * khtr\_u) * (phi\_r\_avg - phi\_l\_avg)
584 
585     \textcolor{keywordflow}{do} k = k\_top\_max+1,nk
586       heff = harmonic\_mean(h\_l(k), h\_r(k))
587       f\_layer(k) = -(heff * khtr\_u) * (phi\_r(k) - phi\_l(k))
588 \textcolor{keywordflow}{    enddo}
589 \textcolor{keywordflow}{  endif}
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 \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}
364   \textcolor{keywordtype}{real} :: h1\textcolor{comment}{ !< Scalar quantity}
365   \textcolor{keywordtype}{real} :: h2\textcolor{comment}{ !< Scalar quantity}
366   \textcolor{keywordflow}{if} (h1 + h2 == 0.) \textcolor{keywordflow}{then}
367     harmonic\_mean = 0.
368   \textcolor{keywordflow}{else}
369     harmonic\_mean = 2.*(h1*h2)/(h1+h2)
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(\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{\tt in,out}  & {\em g} & Grid type\\
\hline
\mbox{\tt in}  & {\em gv} & ocean vertical grid structure\\
\hline
\mbox{\tt in}  & {\em us} & A dimensional unit scaling type\\
\hline
\mbox{\tt in}  & {\em h} & Layer thickness \mbox{[}H $\sim$$>$ m or kg m-\/2\mbox{]}\\
\hline
\mbox{\tt in}  & {\em coef\+\_\+x} & dt $\ast$ Kh $\ast$ dy / dx at u-\/points \mbox{[}L2 $\sim$$>$ m2\mbox{]}\\
\hline
\mbox{\tt in}  & {\em coef\+\_\+y} & dt $\ast$ Kh $\ast$ dx / dy at v-\/points \mbox{[}L2 $\sim$$>$ m2\mbox{]}\\
\hline
\mbox{\tt in}  & {\em dt} & Tracer time step $\ast$ I\+\_\+numitts (I\+\_\+numitts in tracer\+\_\+hordiff)\\
\hline
 & {\em reg} & Tracer registry\\
\hline
\mbox{\tt 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}
138   \textcolor{keywordtype}{type}(ocean\_grid\_type),                \textcolor{keywordtype}{intent(inout)} :: g\textcolor{comment}{   !< Grid type}
139   \textcolor{keywordtype}{type}(verticalgrid\_type),              \textcolor{keywordtype}{intent(in)}    :: gv\textcolor{comment}{  !< ocean vertical grid structure}
140   \textcolor{keywordtype}{type}(unit\_scale\_type),                \textcolor{keywordtype}{intent(in)}    :: us\textcolor{comment}{  !< A dimensional unit scaling type}
141   \textcolor{keywordtype}{real}, \textcolor{keywordtype}{dimension(SZI\_(G),SZJ\_(G),SZK\_(G))}, &
142                                         \textcolor{keywordtype}{intent(in)}    :: h\textcolor{comment}{      !< Layer thickness [H ~> m or kg m-2]}
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]}
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]}
145   \textcolor{keywordtype}{real},                                 \textcolor{keywordtype}{intent(in)}    :: dt\textcolor{comment}{     !< Tracer time step * I\_numitts}
146 \textcolor{comment}{                                                                !! (I\_numitts in tracer\_hordiff)}
147   \textcolor{keywordtype}{type}(tracer\_registry\_type),           \textcolor{keywordtype}{pointer}       :: reg\textcolor{comment}{    !< Tracer registry}
148   \textcolor{keywordtype}{type}(lateral\_boundary\_diffusion\_cs),  \textcolor{keywordtype}{intent(in)}    :: cs\textcolor{comment}{     !< Control structure for this module}
149 
150   \textcolor{comment}{! Local variables}
151   \textcolor{keywordtype}{real}, \textcolor{keywordtype}{dimension(SZI\_(G),SZJ\_(G))} :: hbl\textcolor{comment}{                           !< bnd. layer depth [H ~> m or kg m-2]}
152   \textcolor{keywordtype}{real}, \textcolor{keywordtype}{dimension(SZI\_(G),SZJ\_(G),SZK\_(G),CS%deg+1)} :: ppoly0\_coefs\textcolor{comment}{ !< Coefficients of polynomial}
153   \textcolor{keywordtype}{real}, \textcolor{keywordtype}{dimension(SZI\_(G),SZJ\_(G),SZK\_(G),2)}        :: ppoly0\_e\textcolor{comment}{     !< Edge values from reconstructions}
154   \textcolor{keywordtype}{real}, \textcolor{keywordtype}{dimension(SZK\_(G),CS%deg+1)}                 :: ppoly\_s\textcolor{comment}{      !< Slopes from reconstruction
       (placeholder)}
155   \textcolor{keywordtype}{real}, \textcolor{keywordtype}{dimension(SZIB\_(G),SZJ\_(G),SZK\_(G))} :: uflx\textcolor{comment}{        !< Zonal flux of tracer [conc m^3]}
156   \textcolor{keywordtype}{real}, \textcolor{keywordtype}{dimension(SZIB\_(G),SZJ\_(G))}         :: uflx\_bulk\textcolor{comment}{   !< Total calculated bulk-layer u-flux for the
       tracer}
157   \textcolor{keywordtype}{real}, \textcolor{keywordtype}{dimension(SZI\_(G),SZJB\_(G),SZK\_(G))} :: vflx\textcolor{comment}{        !< Meridional flux of tracer [conc m^3]}
158   \textcolor{keywordtype}{real}, \textcolor{keywordtype}{dimension(SZI\_(G),SZJB\_(G))}         :: vflx\_bulk\textcolor{comment}{   !< Total calculated bulk-layer v-flux for the
       tracer}
159   \textcolor{keywordtype}{real}, \textcolor{keywordtype}{dimension(SZIB\_(G),SZJ\_(G))}         :: uwork\_2d\textcolor{comment}{    !< Layer summed u-flux transport}
160   \textcolor{keywordtype}{real}, \textcolor{keywordtype}{dimension(SZI\_(G),SZJB\_(G))}         :: vwork\_2d\textcolor{comment}{    !< Layer summed v-flux transport}
161   \textcolor{keywordtype}{real}, \textcolor{keywordtype}{dimension(SZI\_(G),SZJ\_(G),G%ke)}     :: tendency\textcolor{comment}{    !< tendency array for diagn}
162   \textcolor{keywordtype}{real}, \textcolor{keywordtype}{dimension(SZI\_(G),SZJ\_(G))}          :: tendency\_2d\textcolor{comment}{ !< depth integrated content tendency for diagn}
163   \textcolor{keywordtype}{type}(tracer\_type), \textcolor{keywordtype}{pointer}                :: tracer => null() \textcolor{comment}{!< Pointer to the current tracer}
164   \textcolor{keywordtype}{integer} :: remap\_method\textcolor{comment}{ !< Reconstruction method}
165   \textcolor{keywordtype}{integer} :: i,j,k,m\textcolor{comment}{      !< indices to loop over}
166   \textcolor{keywordtype}{real}    :: idt\textcolor{comment}{          !< inverse of the time step [s-1]}
167 
168   idt = 1./dt
169   hbl(:,:) = 0.
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)
171   \textcolor{keywordflow}{if} (\textcolor{keyword}{ASSOCIATED}(cs%energetic\_PBL\_CSp)) &
172     \textcolor{keyword}{call }energetic\_pbl\_get\_mld(cs%energetic\_PBL\_CSp, hbl, g, us, m\_to\_mld\_units=gv%m\_to\_H)
173 
174   \textcolor{keyword}{call }pass\_var(hbl,g%Domain)
175   \textcolor{keywordflow}{do} m = 1,reg%ntr
176     tracer => reg%tr(m)
177 
178     \textcolor{comment}{! for diagnostics}
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}
180       tendency(:,:,:) = 0.0
181 \textcolor{keywordflow}{    endif}
182 
183     \textcolor{comment}{! Interpolate state to interface}
184     \textcolor{keywordflow}{do} j=g%jsc-1,g%jec+1 ; \textcolor{keywordflow}{do} i=g%isc-1,g%iec+1
185       \textcolor{keyword}{call }build\_reconstructions\_1d( cs%remap\_CS, g%ke, h(i,j,:), tracer%t(i,j,:), ppoly0\_coefs(i,j,:,:), &
186                                      ppoly0\_e(i,j,:,:), ppoly\_s, remap\_method, gv%H\_subroundoff, gv
      %H\_subroundoff)
187 \textcolor{keywordflow}{    enddo} ;\textcolor{keywordflow}{ enddo}
188 
189     \textcolor{comment}{! Diffusive fluxes in the i-direction}
190     uflx(:,:,:) = 0.
191     vflx(:,:,:) = 0.
192     uflx\_bulk(:,:) = 0.
193     vflx\_bulk(:,:) = 0.
194 
195     \textcolor{comment}{! Method #1 (layer by layer)}
196     \textcolor{keywordflow}{if} (cs%method == 1) \textcolor{keywordflow}{then}
197       \textcolor{keywordflow}{do} j=g%jsc,g%jec
198         \textcolor{keywordflow}{do} i=g%isc-1,g%iec
199           \textcolor{keywordflow}{if} (g%mask2dCu(i,j)>0.) \textcolor{keywordflow}{then}
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),  &
201               g%areaT(i,j), g%areaT(i+1,j), tracer%t(i,j,:), tracer%t(i+1,j,:), ppoly0\_coefs(i,j,:,:),    &
202               ppoly0\_coefs(i+1,j,:,:), ppoly0\_e(i,j,:,:), ppoly0\_e(i+1,j,:,:), remap\_method, coef\_x(i,j), &
203               uflx(i,j,:), cs%linear)
204 \textcolor{keywordflow}{          endif}
205 \textcolor{keywordflow}{        enddo}
206 \textcolor{keywordflow}{      enddo}
207       \textcolor{keywordflow}{do} j=g%jsc-1,g%jec
208         \textcolor{keywordflow}{do} i=g%isc,g%iec
209           \textcolor{keywordflow}{if} (g%mask2dCv(i,j)>0.) \textcolor{keywordflow}{then}
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),  &
211               g%areaT(i,j), g%areaT(i,j+1), tracer%t(i,j,:), tracer%t(i,j+1,:), ppoly0\_coefs(i,j,:,:),    &
212               ppoly0\_coefs(i,j+1,:,:), ppoly0\_e(i,j,:,:), ppoly0\_e(i,j+1,:,:), remap\_method, coef\_y(i,j), &
213               vflx(i,j,:), cs%linear)
214 \textcolor{keywordflow}{          endif}
215 \textcolor{keywordflow}{        enddo}
216 \textcolor{keywordflow}{      enddo}
217 
218     \textcolor{comment}{! Method #2 (bulk approach)}
219     \textcolor{keywordflow}{elseif} (cs%method == 2) \textcolor{keywordflow}{then}
220       \textcolor{keywordflow}{do} j=g%jsc,g%jec
221         \textcolor{keywordflow}{do} i=g%isc-1,g%iec
222           \textcolor{keywordflow}{if} (g%mask2dCu(i,j)>0.) \textcolor{keywordflow}{then}
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), &
224               g%areaT(i,j), g%areaT(i+1,j), tracer%t(i,j,:), tracer%t(i+1,j,:),                         &
225               ppoly0\_coefs(i,j,:,:), ppoly0\_coefs(i+1,j,:,:), ppoly0\_e(i,j,:,:),                        &
226               ppoly0\_e(i+1,j,:,:), remap\_method, coef\_x(i,j), uflx\_bulk(i,j), uflx(i,j,:), cs%limiter,  &
227               cs%linear)
228 \textcolor{keywordflow}{          endif}
229 \textcolor{keywordflow}{        enddo}
230 \textcolor{keywordflow}{      enddo}
231       \textcolor{keywordflow}{do} j=g%jsc-1,g%jec
232         \textcolor{keywordflow}{do} i=g%isc,g%iec
233           \textcolor{keywordflow}{if} (g%mask2dCv(i,j)>0.) \textcolor{keywordflow}{then}
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), &
235               g%areaT(i,j), g%areaT(i,j+1), tracer%t(i,j,:), tracer%t(i,j+1,:),                         &
236               ppoly0\_coefs(i,j,:,:), ppoly0\_coefs(i,j+1,:,:), ppoly0\_e(i,j,:,:),                        &
237               ppoly0\_e(i,j+1,:,:), remap\_method, coef\_y(i,j), vflx\_bulk(i,j), vflx(i,j,:), cs%limiter,  &
238               cs%linear)
239 \textcolor{keywordflow}{          endif}
240 \textcolor{keywordflow}{        enddo}
241 \textcolor{keywordflow}{      enddo}
242       \textcolor{comment}{! Post tracer bulk diags}
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)
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)
245 \textcolor{keywordflow}{    endif}
246 
247     \textcolor{comment}{! Update the tracer fluxes}
248     \textcolor{keywordflow}{do} k=1,gv%ke ; \textcolor{keywordflow}{do} j=g%jsc,g%jec ; \textcolor{keywordflow}{do} i=g%isc,g%iec
249       \textcolor{keywordflow}{if} (g%mask2dT(i,j)>0.) \textcolor{keywordflow}{then}
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)
       ) ))* &
251                           (g%IareaT(i,j)/( h(i,j,k) + gv%H\_subroundoff))
252 
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}
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
255 \textcolor{keywordflow}{        endif}
256 
257 \textcolor{keywordflow}{      endif}
258 \textcolor{keywordflow}{    enddo} ;\textcolor{keywordflow}{ enddo} ;\textcolor{keywordflow}{ enddo}
259 
260     \textcolor{comment}{! Post the tracer diagnostics}
261     \textcolor{keywordflow}{if} (tracer%id\_lbd\_dfx>0)      \textcolor{keyword}{call }post\_data(tracer%id\_lbd\_dfx, uflx*idt, cs%diag)
262     \textcolor{keywordflow}{if} (tracer%id\_lbd\_dfy>0)      \textcolor{keyword}{call }post\_data(tracer%id\_lbd\_dfy, vflx*idt, cs%diag)
263     \textcolor{keywordflow}{if} (tracer%id\_lbd\_dfx\_2d>0) \textcolor{keywordflow}{then}
264       uwork\_2d(:,:) = 0.
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
266         uwork\_2d(i,j) = uwork\_2d(i,j) + (uflx(i,j,k) * idt)
267 \textcolor{keywordflow}{      enddo} ;\textcolor{keywordflow}{ enddo} ;\textcolor{keywordflow}{ enddo}
268       \textcolor{keyword}{call }post\_data(tracer%id\_lbd\_dfx\_2d, uwork\_2d, cs%diag)
269 \textcolor{keywordflow}{    endif}
270 
271     \textcolor{keywordflow}{if} (tracer%id\_lbd\_dfy\_2d>0) \textcolor{keywordflow}{then}
272       vwork\_2d(:,:) = 0.
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
274         vwork\_2d(i,j) = vwork\_2d(i,j) + (vflx(i,j,k) * idt)
275 \textcolor{keywordflow}{      enddo} ;\textcolor{keywordflow}{ enddo} ;\textcolor{keywordflow}{ enddo}
276       \textcolor{keyword}{call }post\_data(tracer%id\_lbd\_dfy\_2d, vwork\_2d, cs%diag)
277 \textcolor{keywordflow}{    endif}
278 
279     \textcolor{comment}{! post tendency of tracer content}
280     \textcolor{keywordflow}{if} (tracer%id\_lbdxy\_cont > 0) \textcolor{keywordflow}{then}
281       \textcolor{keyword}{call }post\_data(tracer%id\_lbdxy\_cont, tendency, cs%diag)
282 \textcolor{keywordflow}{    endif}
283 
284     \textcolor{comment}{! post depth summed tendency for tracer content}
285     \textcolor{keywordflow}{if} (tracer%id\_lbdxy\_cont\_2d > 0) \textcolor{keywordflow}{then}
286       tendency\_2d(:,:) = 0.
287       \textcolor{keywordflow}{do} j=g%jsc,g%jec ; \textcolor{keywordflow}{do} i=g%isc,g%iec
288         \textcolor{keywordflow}{do} k=1,gv%ke
289           tendency\_2d(i,j) = tendency\_2d(i,j) + tendency(i,j,k)
290 \textcolor{keywordflow}{        enddo}
291 \textcolor{keywordflow}{      enddo} ;\textcolor{keywordflow}{ enddo}
292       \textcolor{keyword}{call }post\_data(tracer%id\_lbdxy\_cont\_2d, tendency\_2d, cs%diag)
293 \textcolor{keywordflow}{    endif}
294 
295     \textcolor{comment}{! post tendency of tracer concentration; this step must be}
296     \textcolor{comment}{! done after posting tracer content tendency, since we alter}
297     \textcolor{comment}{! the tendency array and its units.}
298     \textcolor{keywordflow}{if} (tracer%id\_lbdxy\_conc > 0) \textcolor{keywordflow}{then}
299       \textcolor{keywordflow}{do} k=1,gv%ke ; \textcolor{keywordflow}{do} j=g%jsc,g%jec ; \textcolor{keywordflow}{do} i=g%isc,g%iec
300         tendency(i,j,k) =  tendency(i,j,k) / ( h(i,j,k) + gv%H\_subroundoff )
301 \textcolor{keywordflow}{      enddo} ;\textcolor{keywordflow}{ enddo} ;\textcolor{keywordflow}{ enddo}
302       \textcolor{keyword}{call }post\_data(tracer%id\_lbdxy\_conc, tendency, cs%diag)
303 \textcolor{keywordflow}{    endif}
304 
305 \textcolor{keywordflow}{  enddo}
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(\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{\tt in}  & {\em time} & Time structure\\
\hline
\mbox{\tt in}  & {\em g} & Grid structure\\
\hline
\mbox{\tt in}  & {\em param\+\_\+file} & Parameter file structure\\
\hline
\mbox{\tt 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}
68   \textcolor{keywordtype}{type}(time\_type), \textcolor{keywordtype}{target},          \textcolor{keywordtype}{intent(in)}    :: time\textcolor{comment}{          !< Time structure}
69   \textcolor{keywordtype}{type}(ocean\_grid\_type),            \textcolor{keywordtype}{intent(in)}    :: g\textcolor{comment}{             !< Grid structure}
70   \textcolor{keywordtype}{type}(param\_file\_type),            \textcolor{keywordtype}{intent(in)}    :: param\_file\textcolor{comment}{    !< Parameter file structure}
71   \textcolor{keywordtype}{type}(diag\_ctrl), \textcolor{keywordtype}{target},          \textcolor{keywordtype}{intent(inout)} :: diag\textcolor{comment}{          !< Diagnostics control structure}
72   \textcolor{keywordtype}{type}(diabatic\_cs),                \textcolor{keywordtype}{pointer}       :: diabatic\_csp\textcolor{comment}{  !< KPP control structure needed to get
       BLD}
73   \textcolor{keywordtype}{type}(lateral\_boundary\_diffusion\_cs), \textcolor{keywordtype}{pointer}    :: cs\textcolor{comment}{            !< Lateral boundary mixing control
       structure}
74 
75   \textcolor{comment}{! local variables}
76   \textcolor{keywordtype}{character(len=80)}  :: string  \textcolor{comment}{! Temporary strings}
77   \textcolor{keywordtype}{logical} :: boundary\_extrap
78 
79   \textcolor{keywordflow}{if} (\textcolor{keyword}{ASSOCIATED}(cs)) \textcolor{keywordflow}{then}
80     \textcolor{keyword}{call }mom\_error(fatal, \textcolor{stringliteral}{"lateral\_boundary\_diffusion\_init called with associated control structure."})
81     \textcolor{keywordflow}{return}
82 \textcolor{keywordflow}{  endif}
83 
84   \textcolor{comment}{! Log this module and master switch for turning it on/off}
85   \textcolor{keyword}{call }get\_param(param\_file, mdl, \textcolor{stringliteral}{"USE\_LATERAL\_BOUNDARY\_DIFFUSION"}, lateral\_boundary\_diffusion\_init, &
86                  default=.false., do\_not\_log=.true.)
87   \textcolor{keyword}{call }log\_version(param\_file, mdl, version, &
88            \textcolor{stringliteral}{"This module implements lateral diffusion of tracers near boundaries"}, &
89            all\_default=.not.lateral\_boundary\_diffusion\_init)
90   \textcolor{keyword}{call }get\_param(param\_file, mdl, \textcolor{stringliteral}{"USE\_LATERAL\_BOUNDARY\_DIFFUSION"}, lateral\_boundary\_diffusion\_init, &
91                  \textcolor{stringliteral}{"If true, enables the lateral boundary tracer's diffusion module."}, &
92                  default=.false.)
93 
94   \textcolor{keywordflow}{if} (.not. lateral\_boundary\_diffusion\_init) \textcolor{keywordflow}{return}
95 
96   \textcolor{keyword}{allocate}(cs)
97   cs%diag => diag
98   \textcolor{keyword}{call }extract\_diabatic\_member(diabatic\_csp, kpp\_csp=cs%KPP\_CSp)
99   \textcolor{keyword}{call }extract\_diabatic\_member(diabatic\_csp, energetic\_pbl\_csp=cs%energetic\_PBL\_CSp)
100 
101   cs%surface\_boundary\_scheme = -1
102   \textcolor{keywordflow}{if} ( .not. \textcolor{keyword}{ASSOCIATED}(cs%energetic\_PBL\_CSp) .and. .not. \textcolor{keyword}{ASSOCIATED}(cs%KPP\_CSp) ) \textcolor{keywordflow}{then}
103     \textcolor{keyword}{call }mom\_error(fatal,\textcolor{stringliteral}{"Lateral boundary diffusion is true, but no valid boundary layer scheme was found"}
      )
104 \textcolor{keywordflow}{  endif}
105 
106   \textcolor{comment}{! Read all relevant parameters and write them to the model log.}
107   \textcolor{keyword}{call }get\_param(param\_file, mdl, \textcolor{stringliteral}{"LATERAL\_BOUNDARY\_METHOD"}, cs%method, &
108                  \textcolor{stringliteral}{"Determine how to apply boundary lateral diffusion of tracers: \(\backslash\)n"}//&
109                  \textcolor{stringliteral}{"1. Along layer approach \(\backslash\)n"}//&
110                  \textcolor{stringliteral}{"2. Bulk layer approach (this option is not recommended)"}, default=1)
111   \textcolor{keywordflow}{if} (cs%method == 2) \textcolor{keywordflow}{then}
112     \textcolor{keyword}{call }get\_param(param\_file, mdl, \textcolor{stringliteral}{"APPLY\_LIMITER"}, cs%limiter, &
113                    \textcolor{stringliteral}{"If True, apply a flux limiter in the LBD. This is only available \(\backslash\)n"}//&
114                    \textcolor{stringliteral}{"when LATERAL\_BOUNDARY\_METHOD=2."}, default=.false.)
115 \textcolor{keywordflow}{  endif}
116   \textcolor{keyword}{call }get\_param(param\_file, mdl, \textcolor{stringliteral}{"LBD\_LINEAR\_TRANSITION"}, cs%linear, &
117                  \textcolor{stringliteral}{"If True, apply a linear transition at the base/top of the boundary. \(\backslash\)n"}//&
118                  \textcolor{stringliteral}{"The flux will be fully applied at k=k\_min and zero at k=k\_max."}, default=.false.)
119   \textcolor{keyword}{call }get\_param(param\_file, mdl, \textcolor{stringliteral}{"LBD\_BOUNDARY\_EXTRAP"}, boundary\_extrap, &
120                  \textcolor{stringliteral}{"Use boundary extrapolation in LBD code"}, &
121                  default=.false.)
122   \textcolor{keyword}{call }get\_param(param\_file, mdl, \textcolor{stringliteral}{"LBD\_REMAPPING\_SCHEME"}, string, &
123                  \textcolor{stringliteral}{"This sets the reconstruction scheme used "}//&
124                  \textcolor{stringliteral}{"for vertical remapping for all variables. "}//&
125                  \textcolor{stringliteral}{"It can be one of the following schemes: "}//&
126                  trim(remappingschemesdoc), default=remappingdefaultscheme)
127   \textcolor{keyword}{call }initialize\_remapping( cs%remap\_CS, string, boundary\_extrapolation = boundary\_extrap )
128   \textcolor{keyword}{call }extract\_member\_remapping\_cs(cs%remap\_CS, degree=cs%deg)
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{\tt 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}
807   \textcolor{keywordtype}{logical},               \textcolor{keywordtype}{intent(in)} :: verbose\textcolor{comment}{ !< If true, output additional information for debugging unit
       tests}
808 
809   \textcolor{comment}{! Local variables}
810   \textcolor{keywordtype}{integer}, \textcolor{keywordtype}{parameter}    :: nk = 2               \textcolor{comment}{! Number of layers}
811   \textcolor{keywordtype}{integer}, \textcolor{keywordtype}{parameter}    :: deg = 1              \textcolor{comment}{! Degree of reconstruction (linear here)}
812   \textcolor{keywordtype}{integer}, \textcolor{keywordtype}{parameter}    :: method = 1           \textcolor{comment}{! Method used for integrating polynomials}
813   \textcolor{keywordtype}{real}, \textcolor{keywordtype}{dimension(nk)}   :: phi\_l, phi\_r         \textcolor{comment}{! Tracer values (left and right column)             [
       nondim m^-3 ]}
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)}
815   \textcolor{keywordtype}{real}, \textcolor{keywordtype}{dimension(nk,deg+1)} :: phi\_pp\_l, phi\_pp\_r   \textcolor{comment}{! Coefficients for the linear pseudo-reconstructions}
816                                                 \textcolor{comment}{!                                                   [
       nondim m^-3 ]}
817 
818   \textcolor{keywordtype}{real}, \textcolor{keywordtype}{dimension(nk,2)} :: ppoly0\_e\_l, ppoly0\_e\_r\textcolor{comment}{! Polynomial edge values (left and right)         
       [concentration]}
819   \textcolor{keywordtype}{real}, \textcolor{keywordtype}{dimension(nk)}   :: h\_l, h\_r             \textcolor{comment}{! Layer thickness (left and right)                  [m]}
820   \textcolor{keywordtype}{real}                  :: khtr\_u               \textcolor{comment}{! Horizontal diffusivities at U-point               [m^2
       s^-1]}
821   \textcolor{keywordtype}{real}                  :: hbl\_l, hbl\_r         \textcolor{comment}{! Depth of the boundary layer (left and right)      [m]}
822   \textcolor{keywordtype}{real}                  :: f\_bulk               \textcolor{comment}{! Total diffusive flux across the U point           [nondim
       s^-1]}
823   \textcolor{keywordtype}{real}, \textcolor{keywordtype}{dimension(nk)}   :: f\_layer              \textcolor{comment}{! Diffusive flux within each layer at U-point       [nondim
       s^-1]}
824   \textcolor{keywordtype}{real}                  :: h\_u, hblt\_u          \textcolor{comment}{! Thickness at the u-point                          [m]}
825   \textcolor{keywordtype}{real}                  :: khtr\_avg             \textcolor{comment}{! Thickness-weighted diffusivity at the u-point     [m^2
       s^-1]}
826   \textcolor{keywordtype}{real}                  :: heff                 \textcolor{comment}{! Harmonic mean of layer thicknesses                [m]}
827   \textcolor{keywordtype}{real}                  :: inv\_heff             \textcolor{comment}{! Inverse of the harmonic mean of layer thicknesses [m^[-1]}
828   \textcolor{keywordtype}{character(len=120)}    :: test\_name            \textcolor{comment}{! Title of the unit test}
829   \textcolor{keywordtype}{integer}               :: k\_top                \textcolor{comment}{! Index of cell containing top of boundary}
830   \textcolor{keywordtype}{real}                  :: zeta\_top             \textcolor{comment}{! Nondimension position}
831   \textcolor{keywordtype}{integer}               :: k\_bot                \textcolor{comment}{! Index of cell containing bottom of boundary}
832   \textcolor{keywordtype}{real}                  :: zeta\_bot             \textcolor{comment}{! Nondimension position}
833   \textcolor{keywordtype}{real}                  :: area\_l,area\_r        \textcolor{comment}{! Area of grid cell [m^2]}
834   area\_l = 1.; area\_r = 1. \textcolor{comment}{! Set to unity for all unit tests}
835 
836   near\_boundary\_unit\_tests = .false.
837 
838   \textcolor{comment}{! Unit tests for boundary\_k\_range}
839   test\_name = \textcolor{stringliteral}{'Surface boundary spans the entire top cell'}
840   h\_l = (/5.,5./)
841   \textcolor{keyword}{call }boundary\_k\_range(surface, nk, h\_l, 5., k\_top, zeta\_top, k\_bot, zeta\_bot)
842   near\_boundary\_unit\_tests = near\_boundary\_unit\_tests .or. &
843                              test\_boundary\_k\_range(k\_top, zeta\_top, k\_bot, zeta\_bot, 1, 0., 1, 1., 
      test\_name, verbose)
844 
845   test\_name = \textcolor{stringliteral}{'Surface boundary spans the entire column'}
846   h\_l = (/5.,5./)
847   \textcolor{keyword}{call }boundary\_k\_range(surface, nk, h\_l, 10., k\_top, zeta\_top, k\_bot, zeta\_bot)
848   near\_boundary\_unit\_tests = near\_boundary\_unit\_tests .or. &
849                              test\_boundary\_k\_range(k\_top, zeta\_top, k\_bot, zeta\_bot, 1, 0., 2, 1., 
      test\_name, verbose)
850 
851   test\_name = \textcolor{stringliteral}{'Bottom boundary spans the entire bottom cell'}
852   h\_l = (/5.,5./)
853   \textcolor{keyword}{call }boundary\_k\_range(bottom, nk, h\_l, 5., k\_top, zeta\_top, k\_bot, zeta\_bot)
854   near\_boundary\_unit\_tests = near\_boundary\_unit\_tests .or. &
855                              test\_boundary\_k\_range(k\_top, zeta\_top, k\_bot, zeta\_bot, 2, 1., 2, 0., 
      test\_name, verbose)
856 
857   test\_name = \textcolor{stringliteral}{'Bottom boundary spans the entire column'}
858   h\_l = (/5.,5./)
859   \textcolor{keyword}{call }boundary\_k\_range(bottom, nk, h\_l, 10., k\_top, zeta\_top, k\_bot, zeta\_bot)
860   near\_boundary\_unit\_tests = near\_boundary\_unit\_tests .or. &
861                              test\_boundary\_k\_range(k\_top, zeta\_top, k\_bot, zeta\_bot, 1, 1., 2, 0., 
      test\_name, verbose)
862 
863   test\_name = \textcolor{stringliteral}{'Surface boundary intersects second layer'}
864   h\_l = (/10.,10./)
865   \textcolor{keyword}{call }boundary\_k\_range(surface, nk, h\_l, 17.5, k\_top, zeta\_top, k\_bot, zeta\_bot)
866   near\_boundary\_unit\_tests = near\_boundary\_unit\_tests .or. &
867                              test\_boundary\_k\_range(k\_top, zeta\_top, k\_bot, zeta\_bot, 1, 0., 2, 0.75, 
      test\_name, verbose)
868 
869   test\_name = \textcolor{stringliteral}{'Surface boundary intersects first layer'}
870   h\_l = (/10.,10./)
871   \textcolor{keyword}{call }boundary\_k\_range(surface, nk, h\_l, 2.5, k\_top, zeta\_top, k\_bot, zeta\_bot)
872   near\_boundary\_unit\_tests = near\_boundary\_unit\_tests .or. &
873                              test\_boundary\_k\_range(k\_top, zeta\_top, k\_bot, zeta\_bot, 1, 0., 1, 0.25, 
      test\_name, verbose)
874 
875   test\_name = \textcolor{stringliteral}{'Surface boundary is deeper than column thickness'}
876   h\_l = (/10.,10./)
877   \textcolor{keyword}{call }boundary\_k\_range(surface, nk, h\_l, 21.0, k\_top, zeta\_top, k\_bot, zeta\_bot)
878   near\_boundary\_unit\_tests = near\_boundary\_unit\_tests .or. &
879                              test\_boundary\_k\_range(k\_top, zeta\_top, k\_bot, zeta\_bot, 1, 0., 2, 1., 
      test\_name, verbose)
880 
881   test\_name = \textcolor{stringliteral}{'Bottom boundary intersects first layer'}
882   h\_l = (/10.,10./)
883   \textcolor{keyword}{call }boundary\_k\_range(bottom, nk, h\_l, 17.5, k\_top, zeta\_top, k\_bot, zeta\_bot)
884   near\_boundary\_unit\_tests = near\_boundary\_unit\_tests .or. &
885                              test\_boundary\_k\_range(k\_top, zeta\_top, k\_bot, zeta\_bot, 1, 0.75, 2, 0., 
      test\_name, verbose)
886 
887   test\_name = \textcolor{stringliteral}{'Bottom boundary intersects second layer'}
888   h\_l = (/10.,10./)
889   \textcolor{keyword}{call }boundary\_k\_range(bottom, nk, h\_l, 2.5, k\_top, zeta\_top, k\_bot, zeta\_bot)
890   near\_boundary\_unit\_tests = near\_boundary\_unit\_tests .or. &
891                              test\_boundary\_k\_range(k\_top, zeta\_top, k\_bot, zeta\_bot, 2, 0.25, 2, 0., 
      test\_name, verbose)
892 
893   \textcolor{comment}{! All cases in this section have hbl which are equal to the column thicknesses}
894   test\_name = \textcolor{stringliteral}{'Equal hbl and same layer thicknesses (gradient from right to left)'}
895   hbl\_l = 10; hbl\_r = 10
896   h\_l = (/5.,5./) ; h\_r = (/5.,5./)
897   phi\_l = (/0.,0./) ; phi\_r = (/1.,1./)
898   phi\_pp\_l(1,1) = 0.; phi\_pp\_l(1,2) = 0.
899   phi\_pp\_l(2,1) = 0.; phi\_pp\_l(2,2) = 0.
900   phi\_pp\_r(1,1) = 1.; phi\_pp\_r(1,2) = 0.
901   phi\_pp\_r(2,1) = 1.; phi\_pp\_r(2,2) = 0.
902   ppoly0\_e\_l(1,1) = 0.; ppoly0\_e\_l(1,2) = 0.
903   ppoly0\_e\_l(2,1) = 0.; ppoly0\_e\_l(2,2) = 0.
904   ppoly0\_e\_r(1,1) = 1.; ppoly0\_e\_r(1,2) = 1.
905   ppoly0\_e\_r(2,1) = 1.; ppoly0\_e\_r(2,2) = 1.
906   khtr\_u = 1.
907   \textcolor{comment}{! Without limiter}
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, &
909                                     ppoly0\_e\_l, ppoly0\_e\_r, method, khtr\_u, f\_bulk, f\_layer)
910   near\_boundary\_unit\_tests = near\_boundary\_unit\_tests .or. &
911                              test\_layer\_fluxes( verbose, nk, test\_name, f\_layer, (/-5.0,-5.0/) )
912 
913   \textcolor{comment}{! same as above, but with limiter}
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, &
915                                     ppoly0\_e\_l, ppoly0\_e\_r, method, khtr\_u, f\_bulk, f\_layer, .true.)
916   near\_boundary\_unit\_tests = near\_boundary\_unit\_tests .or. &
917                              test\_layer\_fluxes( verbose, nk, test\_name, f\_layer, (/-1.0,-1.0/) )
918 
919   test\_name = \textcolor{stringliteral}{'Equal hbl and same layer thicknesses (gradient from left to right)'}
920   hbl\_l = 10.; hbl\_r = 10.
921   h\_l = (/5.,5./) ; h\_r = (/5.,5./)
922   phi\_l = (/1.,1./) ; phi\_r = (/0.,0./)
923   phi\_pp\_l(1,1) = 1.; phi\_pp\_l(1,2) = 0.
924   phi\_pp\_l(2,1) = 1.; phi\_pp\_l(2,2) = 0.
925   phi\_pp\_r(1,1) = 0.; phi\_pp\_r(1,2) = 0.
926   phi\_pp\_r(2,1) = 0.; phi\_pp\_r(2,2) = 0.
927   ppoly0\_e\_l(1,1) = 1.; ppoly0\_e\_l(1,2) = 1.
928   ppoly0\_e\_l(2,1) = 1.; ppoly0\_e\_l(2,2) = 1.
929   ppoly0\_e\_r(1,1) = 0.; ppoly0\_e\_r(1,2) = 0.
930   ppoly0\_e\_r(2,1) = 0.; ppoly0\_e\_r(2,2) = 0.
931   khtr\_u = 1.
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,&
933                                     ppoly0\_e\_l, ppoly0\_e\_r, method, khtr\_u, f\_bulk, f\_layer)
934   near\_boundary\_unit\_tests = near\_boundary\_unit\_tests .or. &
935                              test\_layer\_fluxes( verbose, nk, test\_name, f\_layer, (/5.0,5.0/) )
936 
937   test\_name = \textcolor{stringliteral}{'Equal hbl and same layer thicknesses (no gradient)'}
938   hbl\_l = 10; hbl\_r = 10
939   h\_l = (/5.,5./) ; h\_r = (/5.,5./)
940   phi\_l = (/1.,1./) ; phi\_r = (/1.,1./)
941   phi\_pp\_l(1,1) = 1.; phi\_pp\_l(1,2) = 0.
942   phi\_pp\_l(2,1) = 1.; phi\_pp\_l(2,2) = 0.
943   phi\_pp\_r(1,1) = 1.; phi\_pp\_r(1,2) = 0.
944   phi\_pp\_r(2,1) = 1.; phi\_pp\_r(2,2) = 0.
945   ppoly0\_e\_l(1,1) = 1.; ppoly0\_e\_l(1,2) = 1.
946   ppoly0\_e\_l(2,1) = 1.; ppoly0\_e\_l(2,2) = 1.
947   ppoly0\_e\_r(1,1) = 1.; ppoly0\_e\_r(1,2) = 1.
948   ppoly0\_e\_r(2,1) = 1.; ppoly0\_e\_r(2,2) = 1.
949   khtr\_u = 1.
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,&
951                                     ppoly0\_e\_l, ppoly0\_e\_r, method, khtr\_u, f\_bulk, f\_layer)
952   near\_boundary\_unit\_tests = near\_boundary\_unit\_tests .or. &
953                              test\_layer\_fluxes( verbose, nk, test\_name, f\_layer, (/0.0,0.0/) )
954 
955   test\_name = \textcolor{stringliteral}{'Equal hbl and different layer thicknesses (gradient right to left)'}
956   hbl\_l = 16.; hbl\_r = 16.
957   h\_l = (/10.,6./) ; h\_r = (/6.,10./)
958   phi\_l = (/0.,0./) ; phi\_r = (/1.,1./)
959   phi\_pp\_l(1,1) = 0.; phi\_pp\_l(1,2) = 0.
960   phi\_pp\_l(2,1) = 0.; phi\_pp\_l(2,2) = 0.
961   phi\_pp\_r(1,1) = 1.; phi\_pp\_r(1,2) = 0.
962   phi\_pp\_r(2,1) = 1.; phi\_pp\_r(2,2) = 0.
963   ppoly0\_e\_l(1,1) = 0.; ppoly0\_e\_l(1,2) = 0.
964   ppoly0\_e\_l(2,1) = 0.; ppoly0\_e\_l(2,2) = 0.
965   ppoly0\_e\_r(1,1) = 1.; ppoly0\_e\_r(1,2) = 1.
966   ppoly0\_e\_r(2,1) = 1.; ppoly0\_e\_r(2,2) = 1.
967   khtr\_u = 1.
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,&
969                                     ppoly0\_e\_l, ppoly0\_e\_r, method, khtr\_u, f\_bulk, f\_layer)
970   near\_boundary\_unit\_tests = near\_boundary\_unit\_tests .or. &
971                              test\_layer\_fluxes( verbose, nk, test\_name, f\_layer, (/-8.0,-8.0/) )
972 
973   test\_name = \textcolor{stringliteral}{'Equal hbl and same layer thicknesses (diagonal tracer values)'}
974   hbl\_l = 10.; hbl\_r = 10.
975   h\_l = (/5.,5./) ; h\_r = (/5.,5./)
976   phi\_l = (/1.,0./) ; phi\_r = (/0.,1./)
977   phi\_pp\_l(1,1) = 1.; phi\_pp\_l(1,2) = 0.
978   phi\_pp\_l(2,1) = 0.; phi\_pp\_l(2,2) = 0.
979   phi\_pp\_r(1,1) = 0.; phi\_pp\_r(1,2) = 0.
980   phi\_pp\_r(2,1) = 1.; phi\_pp\_r(2,2) = 0.
981   ppoly0\_e\_l(1,1) = 1.; ppoly0\_e\_l(1,2) = 1.
982   ppoly0\_e\_l(2,1) = 0.; ppoly0\_e\_l(2,2) = 0.
983   ppoly0\_e\_r(1,1) = 0.; ppoly0\_e\_r(1,2) = 0.
984   ppoly0\_e\_r(2,1) = 1.; ppoly0\_e\_r(2,2) = 1.
985   khtr\_u = 1.
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,&
987                                     ppoly0\_e\_l, ppoly0\_e\_r, method, khtr\_u, f\_bulk, f\_layer)
988   near\_boundary\_unit\_tests = near\_boundary\_unit\_tests .or. &
989                              test\_layer\_fluxes( verbose, nk, test\_name, f\_layer, (/0.0,0.0/) )
990 
991   test\_name = \textcolor{stringliteral}{'Different hbl and different layer thicknesses (gradient from right to left)'}
992   hbl\_l = 12; hbl\_r = 20
993   h\_l = (/6.,6./) ; h\_r = (/10.,10./)
994   phi\_l = (/0.,0./) ; phi\_r = (/1.,1./)
995   phi\_pp\_l(1,1) = 0.; phi\_pp\_l(1,2) = 0.
996   phi\_pp\_l(2,1) = 0.; phi\_pp\_l(2,2) = 0.
997   phi\_pp\_r(1,1) = 1.; phi\_pp\_r(1,2) = 0.
998   phi\_pp\_r(2,1) = 1.; phi\_pp\_r(2,2) = 0.
999   ppoly0\_e\_l(1,1) = 0.; ppoly0\_e\_l(1,2) = 0.
1000   ppoly0\_e\_l(2,1) = 0.; ppoly0\_e\_l(2,2) = 0.
1001   ppoly0\_e\_r(1,1) = 1.; ppoly0\_e\_r(1,2) = 1.
1002   ppoly0\_e\_r(2,1) = 1.; ppoly0\_e\_r(2,2) = 1.
1003   khtr\_u = 1.
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,&
1005                                     ppoly0\_e\_l, ppoly0\_e\_r, method, khtr\_u, f\_bulk, f\_layer)
1006   near\_boundary\_unit\_tests = near\_boundary\_unit\_tests .or. &
1007                              test\_layer\_fluxes( verbose, nk, test\_name, f\_layer, (/-7.5,-7.5/) )
1008 
1009   \textcolor{comment}{! Cases where hbl < column thickness (polynomial coefficients specified for pseudo-linear reconstruction)}
1010 
1011   test\_name = \textcolor{stringliteral}{'hbl < column thickness, hbl same, constant concentration each column'}
1012   hbl\_l = 2; hbl\_r = 2
1013   h\_l = (/1.,2./) ; h\_r = (/1.,2./)
1014   phi\_l = (/0.,0./) ; phi\_r = (/1.,1./)
1015   phi\_pp\_l(1,1) = 0.; phi\_pp\_l(1,2) = 0.
1016   phi\_pp\_l(2,1) = 0.; phi\_pp\_l(2,2) = 0.
1017   phi\_pp\_r(1,1) = 1.; phi\_pp\_r(1,2) = 0.
1018   phi\_pp\_r(2,1) = 1.; phi\_pp\_r(2,2) = 0.
1019   ppoly0\_e\_l(1,1) = 0.; ppoly0\_e\_l(1,2) = 0.
1020   ppoly0\_e\_l(2,1) = 0.; ppoly0\_e\_l(2,2) = 0.
1021   ppoly0\_e\_r(1,1) = 1.; ppoly0\_e\_r(1,2) = 1.
1022   ppoly0\_e\_r(2,1) = 1.; ppoly0\_e\_r(2,2) = 1.
1023   khtr\_u = 1.
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,&
1025                                     ppoly0\_e\_l, ppoly0\_e\_r, method, khtr\_u, f\_bulk, f\_layer)
1026   near\_boundary\_unit\_tests = near\_boundary\_unit\_tests .or. &
1027                              test\_layer\_fluxes( verbose, nk, test\_name, f\_layer, (/-1.,-1./) )
1028 
1029   test\_name = \textcolor{stringliteral}{'hbl < column thickness, hbl same, linear profile right'}
1030   hbl\_l = 2; hbl\_r = 2
1031   h\_l = (/1.,2./) ; h\_r = (/1.,2./)
1032   phi\_l = (/0.,0./) ; phi\_r = (/0.5,2./)
1033   phi\_pp\_l(1,1) = 0.; phi\_pp\_l(1,2) = 0.
1034   phi\_pp\_l(2,1) = 0.; phi\_pp\_l(2,2) = 0.
1035   phi\_pp\_r(1,1) = 0.; phi\_pp\_r(1,2) = 1.
1036   phi\_pp\_r(2,1) = 1.; phi\_pp\_r(2,2) = 2.
1037   khtr\_u = 1.
1038   ppoly0\_e\_l(1,1) = 0.; ppoly0\_e\_l(1,2) = 0.
1039   ppoly0\_e\_l(2,1) = 0.; ppoly0\_e\_l(2,2) = 0.
1040   ppoly0\_e\_r(1,1) = 0.; ppoly0\_e\_r(1,2) = 1.
1041   ppoly0\_e\_r(2,1) = 1.; ppoly0\_e\_r(2,2) = 3.
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,&
1043                                     ppoly0\_e\_l, ppoly0\_e\_r, method, khtr\_u, f\_bulk, f\_layer)
1044   near\_boundary\_unit\_tests = near\_boundary\_unit\_tests .or. &
1045                              test\_layer\_fluxes( verbose, nk, test\_name, f\_layer, (/-1.,-1./) )
1046 
1047   test\_name = \textcolor{stringliteral}{'hbl < column thickness, hbl same, linear profile right, khtr=2'}
1048   hbl\_l = 2; hbl\_r = 2
1049   h\_l = (/1.,2./) ; h\_r = (/1.,2./)
1050   phi\_l = (/0.,0./) ; phi\_r = (/0.5,2./)
1051   phi\_pp\_l(1,1) = 0.; phi\_pp\_l(1,2) = 0.
1052   phi\_pp\_l(2,1) = 0.; phi\_pp\_l(2,2) = 0.
1053   phi\_pp\_r(1,1) = 0.; phi\_pp\_r(1,2) = 1.
1054   phi\_pp\_r(2,1) = 1.; phi\_pp\_r(2,2) = 2.
1055   khtr\_u = 2.
1056   ppoly0\_e\_l(1,1) = 0.; ppoly0\_e\_l(1,2) = 0.
1057   ppoly0\_e\_l(2,1) = 0.; ppoly0\_e\_l(2,2) = 0.
1058   ppoly0\_e\_r(1,1) = 0.; ppoly0\_e\_r(1,2) = 1.
1059   ppoly0\_e\_r(2,1) = 1.; ppoly0\_e\_r(2,2) = 3.
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
      , &
1061                                     phi\_pp\_r, ppoly0\_e\_l, ppoly0\_e\_r, method, khtr\_u, f\_layer)
1062   near\_boundary\_unit\_tests = near\_boundary\_unit\_tests .or. &
1063                              test\_layer\_fluxes( verbose, nk, test\_name, f\_layer, (/-1.,-3./) )
1064 
1065   \textcolor{comment}{! unit tests for layer by layer method}
1066   test\_name = \textcolor{stringliteral}{'Different hbl and different column thicknesses (gradient from right to left)'}
1067   hbl\_l = 12; hbl\_r = 20
1068   h\_l = (/6.,6./) ; h\_r = (/10.,10./)
1069   phi\_l = (/0.,0./) ; phi\_r = (/1.,1./)
1070   phi\_pp\_l(1,1) = 0.; phi\_pp\_l(1,2) = 0.
1071   phi\_pp\_l(2,1) = 0.; phi\_pp\_l(2,2) = 0.
1072   phi\_pp\_r(1,1) = 1.; phi\_pp\_r(1,2) = 0.
1073   phi\_pp\_r(2,1) = 1.; phi\_pp\_r(2,2) = 0.
1074   ppoly0\_e\_l(1,1) = 0.; ppoly0\_e\_l(1,2) = 0.
1075   ppoly0\_e\_l(2,1) = 0.; ppoly0\_e\_l(2,2) = 0.
1076   ppoly0\_e\_r(1,1) = 1.; ppoly0\_e\_r(1,2) = 1.
1077   ppoly0\_e\_r(2,1) = 1.; ppoly0\_e\_r(2,2) = 1.
1078   khtr\_u = 1.
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
      , &
1080                                     phi\_pp\_r, ppoly0\_e\_l, ppoly0\_e\_r, method, khtr\_u, f\_layer)
1081   near\_boundary\_unit\_tests = near\_boundary\_unit\_tests .or. &
1082                              test\_layer\_fluxes( verbose, nk, test\_name, f\_layer, (/-7.5,-7.5/) )
1083 
1084   test\_name = \textcolor{stringliteral}{'Different hbl and different column thicknesses (linear profile right)'}
1085 
1086   hbl\_l = 15; hbl\_r = 6
1087   h\_l = (/10.,10./) ; h\_r = (/12.,10./)
1088   phi\_l = (/0.,0./) ; phi\_r = (/1.,3./)
1089   phi\_pp\_l(1,1) = 0.; phi\_pp\_l(1,2) = 0.
1090   phi\_pp\_l(2,1) = 0.; phi\_pp\_l(2,2) = 0.
1091   phi\_pp\_r(1,1) = 0.; phi\_pp\_r(1,2) = 2.
1092   phi\_pp\_r(2,1) = 2.; phi\_pp\_r(2,2) = 2.
1093   ppoly0\_e\_l(1,1) = 0.; ppoly0\_e\_l(1,2) = 0.
1094   ppoly0\_e\_l(2,1) = 0.; ppoly0\_e\_l(2,2) = 0.
1095   ppoly0\_e\_r(1,1) = 0.; ppoly0\_e\_r(1,2) = 2.
1096   ppoly0\_e\_r(2,1) = 2.; ppoly0\_e\_r(2,2) = 4.
1097   khtr\_u = 1.
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
      , &
1099                                     phi\_pp\_r, ppoly0\_e\_l, ppoly0\_e\_r, method, khtr\_u, f\_layer)
1100   near\_boundary\_unit\_tests = near\_boundary\_unit\_tests .or. &
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}
1133   \textcolor{keywordtype}{integer} :: k\_top\textcolor{comment}{               !< Index of cell containing top of boundary}
1134   \textcolor{keywordtype}{real}    :: zeta\_top\textcolor{comment}{            !< Nondimension position}
1135   \textcolor{keywordtype}{integer} :: k\_bot\textcolor{comment}{               !< Index of cell containing bottom of boundary}
1136   \textcolor{keywordtype}{real}    :: zeta\_bot\textcolor{comment}{            !< Nondimension position}
1137   \textcolor{keywordtype}{integer} :: k\_top\_ans\textcolor{comment}{           !< Index of cell containing top of boundary}
1138   \textcolor{keywordtype}{real}    :: zeta\_top\_ans\textcolor{comment}{        !< Nondimension position}
1139   \textcolor{keywordtype}{integer} :: k\_bot\_ans\textcolor{comment}{           !< Index of cell containing bottom of boundary}
1140   \textcolor{keywordtype}{real}    :: zeta\_bot\_ans\textcolor{comment}{        !< Nondimension position}
1141   \textcolor{keywordtype}{character(len=80)} :: test\_name\textcolor{comment}{ !< Name of the unit test}
1142   \textcolor{keywordtype}{logical} :: verbose\textcolor{comment}{             !< If true always print output}
1143 
1144   \textcolor{keywordtype}{integer}, \textcolor{keywordtype}{parameter} :: stdunit = stdout
1145 
1146   test\_boundary\_k\_range = k\_top .ne. k\_top\_ans
1147   test\_boundary\_k\_range = test\_boundary\_k\_range .or. (zeta\_top .ne. zeta\_top\_ans)
1148   test\_boundary\_k\_range = test\_boundary\_k\_range .or. (k\_bot .ne. k\_bot\_ans)
1149   test\_boundary\_k\_range = test\_boundary\_k\_range .or. (zeta\_bot .ne. zeta\_bot\_ans)
1150 
1151   \textcolor{keywordflow}{if} (test\_boundary\_k\_range) \textcolor{keyword}{write}(stdunit,*) \textcolor{stringliteral}{"UNIT TEST FAILED: "}, test\_name
1152   \textcolor{keywordflow}{if} (test\_boundary\_k\_range .or. verbose) \textcolor{keywordflow}{then}
1153     \textcolor{keyword}{write}(stdunit,20) \textcolor{stringliteral}{"k\_top"}, k\_top, \textcolor{stringliteral}{"k\_top\_ans"}, k\_top\_ans
1154     \textcolor{keyword}{write}(stdunit,20) \textcolor{stringliteral}{"k\_bot"}, k\_bot, \textcolor{stringliteral}{"k\_bot\_ans"}, k\_bot\_ans
1155     \textcolor{keyword}{write}(stdunit,30) \textcolor{stringliteral}{"zeta\_top"}, zeta\_top, \textcolor{stringliteral}{"zeta\_top\_ans"}, zeta\_top\_ans
1156     \textcolor{keyword}{write}(stdunit,30) \textcolor{stringliteral}{"zeta\_bot"}, zeta\_bot, \textcolor{stringliteral}{"zeta\_bot\_ans"}, zeta\_bot\_ans
1157 \textcolor{keywordflow}{  endif}
1158 
1159   20 \textcolor{keyword}{format}(a,\textcolor{stringliteral}{"="},i3,x,a,\textcolor{stringliteral}{"="},i3)
1160   30 \textcolor{keyword}{format}(a,\textcolor{stringliteral}{"="},f20.16,x,a,\textcolor{stringliteral}{"="},f20.16)
1161 
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{\tt in}  & {\em verbose} & If true, write results to stdout\\
\hline
\mbox{\tt in}  & {\em test\+\_\+name} & Brief description of the unit test\\
\hline
\mbox{\tt in}  & {\em nk} & Number of layers\\
\hline
\mbox{\tt in}  & {\em f\+\_\+calc} & Fluxes of the unitless tracer from the algorithm \mbox{[}s$^\wedge$-\/1\mbox{]}\\
\hline
\mbox{\tt 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}
1107   \textcolor{keywordtype}{logical},                    \textcolor{keywordtype}{intent(in)} :: verbose\textcolor{comment}{   !< If true, write results to stdout}
1108   \textcolor{keywordtype}{character(len=80)},          \textcolor{keywordtype}{intent(in)} :: test\_name\textcolor{comment}{ !< Brief description of the unit test}
1109   \textcolor{keywordtype}{integer},                    \textcolor{keywordtype}{intent(in)} :: nk\textcolor{comment}{        !< Number of layers}
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^-1]}
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^-1]}
1112   \textcolor{comment}{! Local variables}
1113   \textcolor{keywordtype}{integer} :: k
1114   \textcolor{keywordtype}{integer}, \textcolor{keywordtype}{parameter} :: stdunit = stdout
1115 
1116   test\_layer\_fluxes = .false.
1117   \textcolor{keywordflow}{do} k=1,nk
1118     \textcolor{keywordflow}{if} ( f\_calc(k) /= f\_ans(k) ) \textcolor{keywordflow}{then}
1119       test\_layer\_fluxes = .true.
1120       \textcolor{keyword}{write}(stdunit,*) \textcolor{stringliteral}{"MOM\_lateral\_boundary\_diffusion, UNIT TEST FAILED: "}, test\_name
1121       \textcolor{keyword}{write}(stdunit,10) k, f\_calc(k), f\_ans(k)
1122     \textcolor{keywordflow}{elseif} (verbose) \textcolor{keywordflow}{then}
1123       \textcolor{keyword}{write}(stdunit,10) k, f\_calc(k), f\_ans(k)
1124 \textcolor{keywordflow}{    endif}
1125 \textcolor{keywordflow}{  enddo}
1126 
1127 10 \textcolor{keyword}{format}(\textcolor{stringliteral}{"Layer="},i3,\textcolor{stringliteral}{" F\_calc="},f20.16,\textcolor{stringliteral}{" F\_ans"},f20.16)
\end{DoxyCode}
