\hypertarget{namespacemom__continuity__ppm}{}\section{mom\+\_\+continuity\+\_\+ppm Module Reference}
\label{namespacemom__continuity__ppm}\index{mom\+\_\+continuity\+\_\+ppm@{mom\+\_\+continuity\+\_\+ppm}}


\subsection{Detailed Description}
Solve the layer continuity equation using the P\+PM method for layer fluxes. 

This module contains the subroutines that advect layer thickness. The scheme here uses a Piecewise-\/\+Parabolic method with a positive definite limiter. \subsection*{Data Types}
\begin{DoxyCompactItemize}
\item 
type \mbox{\hyperlink{structmom__continuity__ppm_1_1continuity__ppm__cs}{continuity\+\_\+ppm\+\_\+cs}}
\begin{DoxyCompactList}\small\item\em Control structure for \mbox{\hyperlink{namespacemom__continuity__ppm}{mom\+\_\+continuity\+\_\+ppm}}. \end{DoxyCompactList}\item 
type \mbox{\hyperlink{structmom__continuity__ppm_1_1loop__bounds__type}{loop\+\_\+bounds\+\_\+type}}
\begin{DoxyCompactList}\small\item\em A container for loop bounds. \end{DoxyCompactList}\end{DoxyCompactItemize}
\subsection*{Functions/\+Subroutines}
\begin{DoxyCompactItemize}
\item 
subroutine, public \mbox{\hyperlink{namespacemom__continuity__ppm_a665851a49a4bde77b4ef5e25332947f6}{continuity\+\_\+ppm}} (u, v, hin, h, uh, vh, dt, G, GV, US, CS, uhbt, vhbt, O\+BC, visc\+\_\+rem\+\_\+u, visc\+\_\+rem\+\_\+v, u\+\_\+cor, v\+\_\+cor, B\+T\+\_\+cont)
\begin{DoxyCompactList}\small\item\em Time steps the layer thicknesses, using a monotonically limit, directionally split P\+PM scheme, based on Lin (1994). \end{DoxyCompactList}\item 
subroutine \mbox{\hyperlink{namespacemom__continuity__ppm_a5f5d6764ed315043d3b91b209db5c0a0}{zonal\+\_\+mass\+\_\+flux}} (u, h\+\_\+in, uh, dt, G, GV, US, CS, LB, uhbt, O\+BC, visc\+\_\+rem\+\_\+u, u\+\_\+cor, B\+T\+\_\+cont)
\begin{DoxyCompactList}\small\item\em Calculates the mass or volume fluxes through the zonal faces, and other related quantities. \end{DoxyCompactList}\item 
subroutine \mbox{\hyperlink{namespacemom__continuity__ppm_a713196d0cfe6cb4cc8a91239a8dba02d}{zonal\+\_\+flux\+\_\+layer}} (u, h, h\+\_\+L, h\+\_\+R, uh, duhdu, visc\+\_\+rem, dt, G, US, j, ish, ieh, do\+\_\+I, vol\+\_\+\+C\+FL, O\+BC)
\begin{DoxyCompactList}\small\item\em Evaluates the zonal mass or volume fluxes in a layer. \end{DoxyCompactList}\item 
subroutine \mbox{\hyperlink{namespacemom__continuity__ppm_a9e76825c96ffca1ae0e84469ab46029b}{zonal\+\_\+face\+\_\+thickness}} (u, h, h\+\_\+L, h\+\_\+R, h\+\_\+u, dt, G, US, LB, vol\+\_\+\+C\+FL, marginal, visc\+\_\+rem\+\_\+u, O\+BC)
\begin{DoxyCompactList}\small\item\em Sets the effective interface thickness at each zonal velocity point. \end{DoxyCompactList}\item 
subroutine \mbox{\hyperlink{namespacemom__continuity__ppm_afad3f82b9824a13d3fe8792496e9b769}{zonal\+\_\+flux\+\_\+adjust}} (u, h\+\_\+in, h\+\_\+L, h\+\_\+R, uhbt, uh\+\_\+tot\+\_\+0, duhdu\+\_\+tot\+\_\+0, du, du\+\_\+max\+\_\+\+C\+FL, du\+\_\+min\+\_\+\+C\+FL, dt, G, US, CS, visc\+\_\+rem, j, ish, ieh, do\+\_\+\+I\+\_\+in, full\+\_\+precision, uh\+\_\+3d, O\+BC)
\begin{DoxyCompactList}\small\item\em Returns the barotropic velocity adjustment that gives the desired barotropic (layer-\/summed) transport. \end{DoxyCompactList}\item 
subroutine \mbox{\hyperlink{namespacemom__continuity__ppm_a30e5aef71acbeef6afe5f6cf1ea30dcc}{set\+\_\+zonal\+\_\+bt\+\_\+cont}} (u, h\+\_\+in, h\+\_\+L, h\+\_\+R, B\+T\+\_\+cont, uh\+\_\+tot\+\_\+0, duhdu\+\_\+tot\+\_\+0, du\+\_\+max\+\_\+\+C\+FL, du\+\_\+min\+\_\+\+C\+FL, dt, G, US, CS, visc\+\_\+rem, visc\+\_\+rem\+\_\+max, j, ish, ieh, do\+\_\+I)
\begin{DoxyCompactList}\small\item\em Sets a structure that describes the zonal barotropic volume or mass fluxes as a function of barotropic flow to agree closely with the sum of the layer\textquotesingle{}s transports. \end{DoxyCompactList}\item 
subroutine \mbox{\hyperlink{namespacemom__continuity__ppm_ae64c4b7cd1756aa3c121fbcf637d5cae}{meridional\+\_\+mass\+\_\+flux}} (v, h\+\_\+in, vh, dt, G, GV, US, CS, LB, vhbt, O\+BC, visc\+\_\+rem\+\_\+v, v\+\_\+cor, B\+T\+\_\+cont)
\begin{DoxyCompactList}\small\item\em Calculates the mass or volume fluxes through the meridional faces, and other related quantities. \end{DoxyCompactList}\item 
subroutine \mbox{\hyperlink{namespacemom__continuity__ppm_ac00aefda40cb9e22013e99cad342bb63}{merid\+\_\+flux\+\_\+layer}} (v, h, h\+\_\+L, h\+\_\+R, vh, dvhdv, visc\+\_\+rem, dt, G, US, J, ish, ieh, do\+\_\+I, vol\+\_\+\+C\+FL, O\+BC)
\begin{DoxyCompactList}\small\item\em Evaluates the meridional mass or volume fluxes in a layer. \end{DoxyCompactList}\item 
subroutine \mbox{\hyperlink{namespacemom__continuity__ppm_a293f7ab5bfd8f3f6a5a50903b05b6411}{merid\+\_\+face\+\_\+thickness}} (v, h, h\+\_\+L, h\+\_\+R, h\+\_\+v, dt, G, US, LB, vol\+\_\+\+C\+FL, marginal, visc\+\_\+rem\+\_\+v, O\+BC)
\begin{DoxyCompactList}\small\item\em Sets the effective interface thickness at each meridional velocity point. \end{DoxyCompactList}\item 
subroutine \mbox{\hyperlink{namespacemom__continuity__ppm_a6deb1b7de418a17cacd60dabc262ba29}{meridional\+\_\+flux\+\_\+adjust}} (v, h\+\_\+in, h\+\_\+L, h\+\_\+R, vhbt, vh\+\_\+tot\+\_\+0, dvhdv\+\_\+tot\+\_\+0, dv, dv\+\_\+max\+\_\+\+C\+FL, dv\+\_\+min\+\_\+\+C\+FL, dt, G, US, CS, visc\+\_\+rem, j, ish, ieh, do\+\_\+\+I\+\_\+in, full\+\_\+precision, vh\+\_\+3d, O\+BC)
\begin{DoxyCompactList}\small\item\em Returns the barotropic velocity adjustment that gives the desired barotropic (layer-\/summed) transport. \end{DoxyCompactList}\item 
subroutine \mbox{\hyperlink{namespacemom__continuity__ppm_a77c6806e82a3634fff7b7480f77c2f02}{set\+\_\+merid\+\_\+bt\+\_\+cont}} (v, h\+\_\+in, h\+\_\+L, h\+\_\+R, B\+T\+\_\+cont, vh\+\_\+tot\+\_\+0, dvhdv\+\_\+tot\+\_\+0, dv\+\_\+max\+\_\+\+C\+FL, dv\+\_\+min\+\_\+\+C\+FL, dt, G, US, CS, visc\+\_\+rem, visc\+\_\+rem\+\_\+max, j, ish, ieh, do\+\_\+I)
\begin{DoxyCompactList}\small\item\em Sets of a structure that describes the meridional barotropic volume or mass fluxes as a function of barotropic flow to agree closely with the sum of the layer\textquotesingle{}s transports. \end{DoxyCompactList}\item 
subroutine \mbox{\hyperlink{namespacemom__continuity__ppm_a9a7eac2a9b17d0e9ee9ca0a27d2f8fb6}{ppm\+\_\+reconstruction\+\_\+x}} (h\+\_\+in, h\+\_\+L, h\+\_\+R, G, LB, h\+\_\+min, monotonic, simple\+\_\+2nd, O\+BC)
\begin{DoxyCompactList}\small\item\em Calculates left/right edge values for P\+PM reconstruction. \end{DoxyCompactList}\item 
subroutine \mbox{\hyperlink{namespacemom__continuity__ppm_af71fa5f7f4b849ec735e2049df2d0693}{ppm\+\_\+reconstruction\+\_\+y}} (h\+\_\+in, h\+\_\+L, h\+\_\+R, G, LB, h\+\_\+min, monotonic, simple\+\_\+2nd, O\+BC)
\begin{DoxyCompactList}\small\item\em Calculates left/right edge values for P\+PM reconstruction. \end{DoxyCompactList}\item 
subroutine \mbox{\hyperlink{namespacemom__continuity__ppm_a870edb0c5b2cb0464899430b6651260c}{ppm\+\_\+limit\+\_\+pos}} (h\+\_\+in, h\+\_\+L, h\+\_\+R, h\+\_\+min, G, iis, iie, jis, jie)
\begin{DoxyCompactList}\small\item\em This subroutine limits the left/right edge values of the P\+PM reconstruction to give a reconstruction that is positive-\/definite. Here this is reinterpreted as giving a constant thickness if the mean thickness is less than h\+\_\+min, with a minimum of h\+\_\+min otherwise. \end{DoxyCompactList}\item 
subroutine \mbox{\hyperlink{namespacemom__continuity__ppm_ab03786fff2550dd61282356608fc1352}{ppm\+\_\+limit\+\_\+cw84}} (h\+\_\+in, h\+\_\+L, h\+\_\+R, G, iis, iie, jis, jie)
\begin{DoxyCompactList}\small\item\em This subroutine limits the left/right edge values of the P\+PM reconstruction according to the monotonic prescription of Colella and Woodward, 1984. \end{DoxyCompactList}\item 
real function \mbox{\hyperlink{namespacemom__continuity__ppm_adf02002cf5951d7610b8643d2d401585}{ratio\+\_\+max}} (a, b, maxrat)
\begin{DoxyCompactList}\small\item\em Return the maximum ratio of a/b or maxrat. \end{DoxyCompactList}\item 
subroutine, public \mbox{\hyperlink{namespacemom__continuity__ppm_a832c506364bca555b36409a91e0f5906}{continuity\+\_\+ppm\+\_\+init}} (Time, G, GV, US, param\+\_\+file, diag, CS)
\begin{DoxyCompactList}\small\item\em Initializes \mbox{\hyperlink{structmom__continuity__ppm_1_1continuity__ppm__cs}{continuity\+\_\+ppm\+\_\+cs}}. \end{DoxyCompactList}\item 
integer function, public \mbox{\hyperlink{namespacemom__continuity__ppm_a3e3ee193ee52b65a1413808eea703aee}{continuity\+\_\+ppm\+\_\+stencil}} (CS)
\begin{DoxyCompactList}\small\item\em continuity\+\_\+\+P\+P\+M\+\_\+stencil returns the continuity solver stencil size \end{DoxyCompactList}\item 
subroutine, public \mbox{\hyperlink{namespacemom__continuity__ppm_a38ffbfd81e4bef4c789429fb843ed7cc}{continuity\+\_\+ppm\+\_\+end}} (CS)
\begin{DoxyCompactList}\small\item\em Destructor for \mbox{\hyperlink{structmom__continuity__ppm_1_1continuity__ppm__cs}{continuity\+\_\+ppm\+\_\+cs}}. \end{DoxyCompactList}\end{DoxyCompactItemize}
\subsection*{Variables}
\textbf{ }\par
\begin{DoxyCompactItemize}
\item 
\mbox{\Hypertarget{namespacemom__continuity__ppm_a6002197c46343ec4d08cab937db87586}\label{namespacemom__continuity__ppm_a6002197c46343ec4d08cab937db87586}} 
integer \mbox{\hyperlink{namespacemom__continuity__ppm_a6002197c46343ec4d08cab937db87586}{id\+\_\+clock\+\_\+update}}
\begin{DoxyCompactList}\small\item\em C\+PU time clock I\+Ds. \end{DoxyCompactList}\item 
\mbox{\Hypertarget{namespacemom__continuity__ppm_a4b409d0d89dbdbbea05f4a3ade088902}\label{namespacemom__continuity__ppm_a4b409d0d89dbdbbea05f4a3ade088902}} 
integer \mbox{\hyperlink{namespacemom__continuity__ppm_a4b409d0d89dbdbbea05f4a3ade088902}{id\+\_\+clock\+\_\+correct}}
\begin{DoxyCompactList}\small\item\em C\+PU time clock I\+Ds. \end{DoxyCompactList}\end{DoxyCompactItemize}



\subsection{Function/\+Subroutine Documentation}
\mbox{\Hypertarget{namespacemom__continuity__ppm_a665851a49a4bde77b4ef5e25332947f6}\label{namespacemom__continuity__ppm_a665851a49a4bde77b4ef5e25332947f6}} 
\index{mom\+\_\+continuity\+\_\+ppm@{mom\+\_\+continuity\+\_\+ppm}!continuity\+\_\+ppm@{continuity\+\_\+ppm}}
\index{continuity\+\_\+ppm@{continuity\+\_\+ppm}!mom\+\_\+continuity\+\_\+ppm@{mom\+\_\+continuity\+\_\+ppm}}
\subsubsection{\texorpdfstring{continuity\+\_\+ppm()}{continuity\_ppm()}}
{\footnotesize\ttfamily subroutine, public mom\+\_\+continuity\+\_\+ppm\+::continuity\+\_\+ppm (\begin{DoxyParamCaption}\item[{real, dimension( g \%isdb\+: g \%iedb, g \%jsd\+: g \%jed, g \%ke), intent(in)}]{u,  }\item[{real, dimension( g \%isd\+: g \%ied, g \%jsdb\+: g \%jedb, g \%ke), intent(in)}]{v,  }\item[{real, dimension( g \%isd\+: g \%ied, g \%jsd\+: g \%jed, g \%ke), intent(in)}]{hin,  }\item[{real, dimension( g \%isd\+: g \%ied, g \%jsd\+: g \%jed, g \%ke), intent(inout)}]{h,  }\item[{real, dimension( g \%isdb\+: g \%iedb, g \%jsd\+: g \%jed, g \%ke), intent(out)}]{uh,  }\item[{real, dimension( g \%isd\+: g \%ied, g \%jsdb\+: g \%jedb, g \%ke), intent(out)}]{vh,  }\item[{real, intent(in)}]{dt,  }\item[{type(ocean\+\_\+grid\+\_\+type), intent(inout)}]{G,  }\item[{type(verticalgrid\+\_\+type), intent(in)}]{GV,  }\item[{type(unit\+\_\+scale\+\_\+type), intent(in)}]{US,  }\item[{type(\mbox{\hyperlink{structmom__continuity__ppm_1_1continuity__ppm__cs}{continuity\+\_\+ppm\+\_\+cs}}), pointer}]{CS,  }\item[{real, dimension( g \%isdb\+: g \%iedb, g \%jsd\+: g \%jed), intent(in), optional}]{uhbt,  }\item[{real, dimension( g \%isd\+: g \%ied, g \%jsdb\+: g \%jedb), intent(in), optional}]{vhbt,  }\item[{type(ocean\+\_\+obc\+\_\+type), optional, pointer}]{O\+BC,  }\item[{real, dimension( g \%isdb\+: g \%iedb, g \%jsd\+: g \%jed, g \%ke), intent(in), optional}]{visc\+\_\+rem\+\_\+u,  }\item[{real, dimension(szi\+\_\+(g),szjb\+\_\+(g),szk\+\_\+(g)), intent(in), optional}]{visc\+\_\+rem\+\_\+v,  }\item[{real, dimension( g \%isdb\+: g \%iedb, g \%jsd\+: g \%jed, g \%ke), intent(out), optional}]{u\+\_\+cor,  }\item[{real, dimension( g \%isd\+: g \%ied, g \%jsdb\+: g \%jedb, g \%ke), intent(out), optional}]{v\+\_\+cor,  }\item[{type(bt\+\_\+cont\+\_\+type), optional, pointer}]{B\+T\+\_\+cont }\end{DoxyParamCaption})}



Time steps the layer thicknesses, using a monotonically limit, directionally split P\+PM scheme, based on Lin (1994). 


\begin{DoxyParams}[1]{Parameters}
\mbox{\tt in,out}  & {\em g} & The ocean\textquotesingle{}s grid structure.\\
\hline
 & {\em cs} & Module\textquotesingle{}s control structure.\\
\hline
\mbox{\tt in}  & {\em u} & Zonal velocity \mbox{[}L T-\/1 $\sim$$>$ m s-\/1\mbox{]}.\\
\hline
\mbox{\tt in}  & {\em v} & Meridional velocity \mbox{[}L T-\/1 $\sim$$>$ m s-\/1\mbox{]}.\\
\hline
\mbox{\tt in}  & {\em hin} & Initial layer thickness \mbox{[}H $\sim$$>$ m or kg m-\/2\mbox{]}.\\
\hline
\mbox{\tt in,out}  & {\em h} & Final layer thickness \mbox{[}H $\sim$$>$ m or kg m-\/2\mbox{]}.\\
\hline
\mbox{\tt out}  & {\em uh} & Zonal volume flux, u$\ast$h$\ast$dy \mbox{[}H L2 T-\/1 $\sim$$>$ m3 s-\/1 or kg s-\/1\mbox{]}.\\
\hline
\mbox{\tt out}  & {\em vh} & Meridional volume flux, v$\ast$h$\ast$dx \mbox{[}H L2 T-\/1 $\sim$$>$ m3 s-\/1 or kg s-\/1\mbox{]}.\\
\hline
\mbox{\tt in}  & {\em dt} & Time increment \mbox{[}T $\sim$$>$ s\mbox{]}.\\
\hline
\mbox{\tt in}  & {\em gv} & Vertical grid structure.\\
\hline
\mbox{\tt in}  & {\em us} & A dimensional unit scaling type\\
\hline
\mbox{\tt in}  & {\em uhbt} & The summed volume flux through zonal faces\\
\hline
\mbox{\tt in}  & {\em vhbt} & The summed volume flux through meridional faces\\
\hline
 & {\em obc} & Open boundaries control structure.\\
\hline
\mbox{\tt in}  & {\em visc\+\_\+rem\+\_\+u} & The fraction of zonal momentum originally in a layer that remains after a time-\/step of viscosity, and the fraction of a time-\/step\textquotesingle{}s worth of a barotropic acceleration that a layer experiences after viscosity is applied. Non-\/dimensional between 0 (at the bottom) and 1 (far above the bottom).\\
\hline
\mbox{\tt in}  & {\em visc\+\_\+rem\+\_\+v} & The fraction of meridional momentum originally in a layer that remains after a time-\/step of viscosity, and the fraction of a time-\/step\textquotesingle{}s worth of a barotropic acceleration that a layer experiences after viscosity is applied. Non-\/dimensional between 0 (at the bottom) and 1 (far above the bottom).\\
\hline
\mbox{\tt out}  & {\em u\+\_\+cor} & The zonal velocities that give uhbt as the depth-\/integrated transport \mbox{[}L T-\/1 $\sim$$>$ m s-\/1\mbox{]}.\\
\hline
\mbox{\tt out}  & {\em v\+\_\+cor} & The meridional velocities that give vhbt as the depth-\/integrated transport \mbox{[}L T-\/1 $\sim$$>$ m s-\/1\mbox{]}.\\
\hline
 & {\em bt\+\_\+cont} & A structure with elements that describe the effective open face areas as a function of barotropic flow. \\
\hline
\end{DoxyParams}


Definition at line 78 of file M\+O\+M\+\_\+continuity\+\_\+\+P\+P\+M.\+F90.


\begin{DoxyCode}
78   \textcolor{keywordtype}{type}(ocean\_grid\_type),   \textcolor{keywordtype}{intent(inout)} :: G\textcolor{comment}{   !< The ocean's grid structure.}
79   \textcolor{keywordtype}{type}(continuity\_PPM\_CS), \textcolor{keywordtype}{pointer}       :: CS\textcolor{comment}{  !< Module's control structure.}
80   \textcolor{keywordtype}{real}, \textcolor{keywordtype}{dimension(SZIB\_(G),SZJ\_(G),SZK\_(G))}, &
81                            \textcolor{keywordtype}{intent(in)}    :: u\textcolor{comment}{   !< Zonal velocity [L T-1 ~> m s-1].}
82   \textcolor{keywordtype}{real}, \textcolor{keywordtype}{dimension(SZI\_(G),SZJB\_(G),SZK\_(G))}, &
83                            \textcolor{keywordtype}{intent(in)}    :: v\textcolor{comment}{   !< Meridional velocity [L T-1 ~> m s-1].}
84   \textcolor{keywordtype}{real}, \textcolor{keywordtype}{dimension(SZI\_(G),SZJ\_(G),SZK\_(G))},  &
85                            \textcolor{keywordtype}{intent(in)}    :: hin\textcolor{comment}{ !< Initial layer thickness [H ~> m or kg m-2].}
86   \textcolor{keywordtype}{real}, \textcolor{keywordtype}{dimension(SZI\_(G),SZJ\_(G),SZK\_(G))},  &
87                            \textcolor{keywordtype}{intent(inout)} :: h\textcolor{comment}{   !< Final layer thickness [H ~> m or kg m-2].}
88   \textcolor{keywordtype}{real}, \textcolor{keywordtype}{dimension(SZIB\_(G),SZJ\_(G),SZK\_(G))}, &
89                            \textcolor{keywordtype}{intent(out)}   :: uh\textcolor{comment}{  !< Zonal volume flux, u*h*dy [H L2 T-1 ~> m3 s-1 or kg
       s-1].}
90   \textcolor{keywordtype}{real}, \textcolor{keywordtype}{dimension(SZI\_(G),SZJB\_(G),SZK\_(G))}, &
91                            \textcolor{keywordtype}{intent(out)}   :: vh\textcolor{comment}{  !< Meridional volume flux, v*h*dx [H L2 T-1 ~> m3 s-1 or kg
       s-1].}
92   \textcolor{keywordtype}{real},                    \textcolor{keywordtype}{intent(in)}    :: dt\textcolor{comment}{  !< Time increment [T ~> s].}
93   \textcolor{keywordtype}{type}(verticalGrid\_type), \textcolor{keywordtype}{intent(in)}    :: GV\textcolor{comment}{  !< Vertical grid structure.}
94   \textcolor{keywordtype}{type}(unit\_scale\_type),   \textcolor{keywordtype}{intent(in)}    :: US\textcolor{comment}{   !< A dimensional unit scaling type}
95   \textcolor{keywordtype}{real}, \textcolor{keywordtype}{dimension(SZIB\_(G),SZJ\_(G))}, &
96                  \textcolor{keywordtype}{optional}, \textcolor{keywordtype}{intent(in)}    :: uhbt\textcolor{comment}{ !< The summed volume flux through zonal faces}
97 \textcolor{comment}{                                                 !! [H L2 T-1 ~> m3 s-1 or kg s-1].}
98   \textcolor{keywordtype}{real}, \textcolor{keywordtype}{dimension(SZI\_(G),SZJB\_(G))}, &
99                  \textcolor{keywordtype}{optional}, \textcolor{keywordtype}{intent(in)}    :: vhbt\textcolor{comment}{ !< The summed volume flux through meridional faces}
100 \textcolor{comment}{                                                 !! [H L2 T-1 ~> m3 s-1 or kg s-1].}
101   \textcolor{keywordtype}{type}(ocean\_OBC\_type),  &
102                  \textcolor{keywordtype}{optional}, \textcolor{keywordtype}{pointer}       :: OBC\textcolor{comment}{ !< Open boundaries control structure.}
103   \textcolor{keywordtype}{real}, \textcolor{keywordtype}{dimension(SZIB\_(G),SZJ\_(G),SZK\_(G))}, &
104                  \textcolor{keywordtype}{optional}, \textcolor{keywordtype}{intent(in)}    :: visc\_rem\_u
105                              \textcolor{comment}{!< The fraction of zonal momentum originally}
106 \textcolor{comment}{                             !! in a layer that remains after a time-step of viscosity, and the}
107 \textcolor{comment}{                             !! fraction of a time-step's worth of a barotropic acceleration that}
108 \textcolor{comment}{                             !! a layer experiences after viscosity is applied.}
109 \textcolor{comment}{                             !! Non-dimensional between 0 (at the bottom) and 1 (far above the bottom).}
110   \textcolor{keywordtype}{real}, \textcolor{keywordtype}{dimension(SZI\_(G),SZJB\_(G),SZK\_(G))}, &
111                  \textcolor{keywordtype}{optional}, \textcolor{keywordtype}{intent(in)}    :: visc\_rem\_v
112                              \textcolor{comment}{!< The fraction of meridional momentum originally}
113 \textcolor{comment}{                             !! in a layer that remains after a time-step of viscosity, and the}
114 \textcolor{comment}{                             !! fraction of a time-step's worth of a barotropic acceleration that}
115 \textcolor{comment}{                             !! a layer experiences after viscosity is applied.}
116 \textcolor{comment}{                             !! Non-dimensional between 0 (at the bottom) and 1 (far above the bottom).}
117   \textcolor{keywordtype}{real}, \textcolor{keywordtype}{dimension(SZIB\_(G),SZJ\_(G),SZK\_(G))}, &
118                  \textcolor{keywordtype}{optional}, \textcolor{keywordtype}{intent(out)}   :: u\_cor
119                              \textcolor{comment}{!< The zonal velocities that give uhbt as the depth-integrated transport [L
       T-1 ~> m s-1].}
120   \textcolor{keywordtype}{real}, \textcolor{keywordtype}{dimension(SZI\_(G),SZJB\_(G),SZK\_(G))}, &
121                  \textcolor{keywordtype}{optional}, \textcolor{keywordtype}{intent(out)}   :: v\_cor
122                              \textcolor{comment}{!< The meridional velocities that give vhbt as the depth-integrated}
123 \textcolor{comment}{                             !! transport [L T-1 ~> m s-1].}
124   \textcolor{keywordtype}{type}(BT\_cont\_type), \textcolor{keywordtype}{optional}, \textcolor{keywordtype}{pointer}  :: BT\_cont\textcolor{comment}{ !< A structure with elements that describe}
125 \textcolor{comment}{                             !!  the effective open face areas as a function of barotropic flow.}
126 
127   \textcolor{comment}{! Local variables}
128   \textcolor{keywordtype}{real} :: h\_min  \textcolor{comment}{! The minimum layer thickness [H ~> m or kg m-2].  h\_min could be 0.}
129   \textcolor{keywordtype}{type}(loop\_bounds\_type) :: LB
130   \textcolor{keywordtype}{integer} :: is, ie, js, je, nz, stencil
131   \textcolor{keywordtype}{integer} :: i, j, k
132 
133   \textcolor{keywordtype}{logical} :: x\_first
134   is = g%isc ; ie = g%iec ; js = g%jsc ; je = g%jec ; nz = g%ke
135 
136   h\_min = gv%Angstrom\_H
137 
138   \textcolor{keywordflow}{if} (.not.\textcolor{keyword}{associated}(cs)) \textcolor{keyword}{call }mom\_error(fatal, &
139          \textcolor{stringliteral}{"MOM\_continuity\_PPM: Module must be initialized before it is used."})
140   x\_first = (mod(g%first\_direction,2) == 0)
141 
142   \textcolor{keywordflow}{if} (\textcolor{keyword}{present}(visc\_rem\_u) .neqv. \textcolor{keyword}{present}(visc\_rem\_v)) \textcolor{keyword}{call }mom\_error(fatal, &
143       \textcolor{stringliteral}{"MOM\_continuity\_PPM: Either both visc\_rem\_u and visc\_rem\_v or neither"}// &
144       \textcolor{stringliteral}{" one must be present in call to continuity\_PPM."})
145 
146   stencil = 3 ; \textcolor{keywordflow}{if} (cs%simple\_2nd) stencil = 2 ; \textcolor{keywordflow}{if} (cs%upwind\_1st) stencil = 1
147 
148   \textcolor{keywordflow}{if} (x\_first) \textcolor{keywordflow}{then}
149   \textcolor{comment}{!    First, advect zonally.}
150     lb%ish = g%isc ; lb%ieh = g%iec
151     lb%jsh = g%jsc-stencil ; lb%jeh = g%jec+stencil
152     \textcolor{keyword}{call }zonal\_mass\_flux(u, hin, uh, dt, g, gv, us, cs, lb, uhbt, obc, visc\_rem\_u, u\_cor, bt\_cont)
153 
154     \textcolor{keyword}{call }cpu\_clock\_begin(id\_clock\_update)
155     \textcolor{comment}{!$OMP parallel do default(shared)}
156     \textcolor{keywordflow}{do} k=1,nz ; \textcolor{keywordflow}{do} j=lb%jsh,lb%jeh ; \textcolor{keywordflow}{do} i=lb%ish,lb%ieh
157       h(i,j,k) = hin(i,j,k) - dt * g%IareaT(i,j) * (uh(i,j,k) - uh(i-1,j,k))
158   \textcolor{comment}{!   Uncomment this line to prevent underflow.}
159   \textcolor{comment}{!   if (h(i,j,k) < h\_min) h(i,j,k) = h\_min}
160 \textcolor{keywordflow}{    enddo} ;\textcolor{keywordflow}{ enddo} ;\textcolor{keywordflow}{ enddo}
161     \textcolor{keyword}{call }cpu\_clock\_end(id\_clock\_update)
162 
163     lb%ish = g%isc ; lb%ieh = g%iec ; lb%jsh = g%jsc ; lb%jeh = g%jec
164 
165     \textcolor{comment}{!    Now advect meridionally, using the updated thicknesses to determine}
166     \textcolor{comment}{!  the fluxes.}
167     \textcolor{keyword}{call }meridional\_mass\_flux(v, h, vh, dt, g, gv, us, cs, lb, vhbt, obc, visc\_rem\_v, v\_cor, bt\_cont)
168 
169     \textcolor{keyword}{call }cpu\_clock\_begin(id\_clock\_update)
170     \textcolor{comment}{!$OMP parallel do default(shared)}
171     \textcolor{keywordflow}{do} k=1,nz ; \textcolor{keywordflow}{do} j=lb%jsh,lb%jeh ; \textcolor{keywordflow}{do} i=lb%ish,lb%ieh
172       h(i,j,k) = h(i,j,k) - dt * g%IareaT(i,j) * (vh(i,j,k) - vh(i,j-1,k))
173   \textcolor{comment}{!   This line prevents underflow.}
174       \textcolor{keywordflow}{if} (h(i,j,k) < h\_min) h(i,j,k) = h\_min
175 \textcolor{keywordflow}{    enddo} ;\textcolor{keywordflow}{ enddo} ;\textcolor{keywordflow}{ enddo}
176     \textcolor{keyword}{call }cpu\_clock\_end(id\_clock\_update)
177 
178   \textcolor{keywordflow}{else}  \textcolor{comment}{! .not. x\_first}
179   \textcolor{comment}{!    First, advect meridionally, so set the loop bounds accordingly.}
180     lb%ish = g%isc-stencil ; lb%ieh = g%iec+stencil
181     lb%jsh = g%jsc ; lb%jeh = g%jec
182 
183     \textcolor{keyword}{call }meridional\_mass\_flux(v, hin, vh, dt, g, gv, us, cs, lb, vhbt, obc, visc\_rem\_v, v\_cor, bt\_cont)
184 
185     \textcolor{keyword}{call }cpu\_clock\_begin(id\_clock\_update)
186     \textcolor{comment}{!$OMP parallel do default(shared)}
187     \textcolor{keywordflow}{do} k=1,nz ; \textcolor{keywordflow}{do} j=lb%jsh,lb%jeh ; \textcolor{keywordflow}{do} i=lb%ish,lb%ieh
188       h(i,j,k) = hin(i,j,k) - dt * g%IareaT(i,j) * (vh(i,j,k) - vh(i,j-1,k))
189 \textcolor{keywordflow}{    enddo} ;\textcolor{keywordflow}{ enddo} ;\textcolor{keywordflow}{ enddo}
190     \textcolor{keyword}{call }cpu\_clock\_end(id\_clock\_update)
191 
192   \textcolor{comment}{!    Now advect zonally, using the updated thicknesses to determine}
193   \textcolor{comment}{!  the fluxes.}
194     lb%ish = g%isc ; lb%ieh = g%iec ; lb%jsh = g%jsc ; lb%jeh = g%jec
195     \textcolor{keyword}{call }zonal\_mass\_flux(u, h, uh, dt, g, gv, us, cs, lb, uhbt, obc, visc\_rem\_u, u\_cor, bt\_cont)
196 
197     \textcolor{keyword}{call }cpu\_clock\_begin(id\_clock\_update)
198     \textcolor{comment}{!$OMP parallel do default(shared)}
199     \textcolor{keywordflow}{do} k=1,nz ; \textcolor{keywordflow}{do} j=lb%jsh,lb%jeh ; \textcolor{keywordflow}{do} i=lb%ish,lb%ieh
200       h(i,j,k) = h(i,j,k) - dt * g%IareaT(i,j) * (uh(i,j,k) - uh(i-1,j,k))
201       \textcolor{comment}{! This line prevents underflow.}
202       \textcolor{keywordflow}{if} (h(i,j,k) < h\_min) h(i,j,k) = h\_min
203 \textcolor{keywordflow}{    enddo} ;\textcolor{keywordflow}{ enddo} ;\textcolor{keywordflow}{ enddo}
204     \textcolor{keyword}{call }cpu\_clock\_end(id\_clock\_update)
205 
206 \textcolor{keywordflow}{  endif}
207 
\end{DoxyCode}
\mbox{\Hypertarget{namespacemom__continuity__ppm_a38ffbfd81e4bef4c789429fb843ed7cc}\label{namespacemom__continuity__ppm_a38ffbfd81e4bef4c789429fb843ed7cc}} 
\index{mom\+\_\+continuity\+\_\+ppm@{mom\+\_\+continuity\+\_\+ppm}!continuity\+\_\+ppm\+\_\+end@{continuity\+\_\+ppm\+\_\+end}}
\index{continuity\+\_\+ppm\+\_\+end@{continuity\+\_\+ppm\+\_\+end}!mom\+\_\+continuity\+\_\+ppm@{mom\+\_\+continuity\+\_\+ppm}}
\subsubsection{\texorpdfstring{continuity\+\_\+ppm\+\_\+end()}{continuity\_ppm\_end()}}
{\footnotesize\ttfamily subroutine, public mom\+\_\+continuity\+\_\+ppm\+::continuity\+\_\+ppm\+\_\+end (\begin{DoxyParamCaption}\item[{type(\mbox{\hyperlink{structmom__continuity__ppm_1_1continuity__ppm__cs}{continuity\+\_\+ppm\+\_\+cs}}), pointer}]{CS }\end{DoxyParamCaption})}



Destructor for \mbox{\hyperlink{structmom__continuity__ppm_1_1continuity__ppm__cs}{continuity\+\_\+ppm\+\_\+cs}}. 


\begin{DoxyParams}{Parameters}
{\em cs} & Module\textquotesingle{}s control structure. \\
\hline
\end{DoxyParams}


Definition at line 2335 of file M\+O\+M\+\_\+continuity\+\_\+\+P\+P\+M.\+F90.


\begin{DoxyCode}
2335   \textcolor{keywordtype}{type}(continuity\_PPM\_CS), \textcolor{keywordtype}{pointer} :: CS\textcolor{comment}{   !< Module's control structure.}
2336   \textcolor{keyword}{deallocate}(cs)
\end{DoxyCode}
\mbox{\Hypertarget{namespacemom__continuity__ppm_a832c506364bca555b36409a91e0f5906}\label{namespacemom__continuity__ppm_a832c506364bca555b36409a91e0f5906}} 
\index{mom\+\_\+continuity\+\_\+ppm@{mom\+\_\+continuity\+\_\+ppm}!continuity\+\_\+ppm\+\_\+init@{continuity\+\_\+ppm\+\_\+init}}
\index{continuity\+\_\+ppm\+\_\+init@{continuity\+\_\+ppm\+\_\+init}!mom\+\_\+continuity\+\_\+ppm@{mom\+\_\+continuity\+\_\+ppm}}
\subsubsection{\texorpdfstring{continuity\+\_\+ppm\+\_\+init()}{continuity\_ppm\_init()}}
{\footnotesize\ttfamily subroutine, public mom\+\_\+continuity\+\_\+ppm\+::continuity\+\_\+ppm\+\_\+init (\begin{DoxyParamCaption}\item[{type(time\+\_\+type), intent(in), target}]{Time,  }\item[{type(ocean\+\_\+grid\+\_\+type), intent(in)}]{G,  }\item[{type(verticalgrid\+\_\+type), intent(in)}]{GV,  }\item[{type(unit\+\_\+scale\+\_\+type), intent(in)}]{US,  }\item[{type(param\+\_\+file\+\_\+type), intent(in)}]{param\+\_\+file,  }\item[{type(diag\+\_\+ctrl), intent(inout), target}]{diag,  }\item[{type(\mbox{\hyperlink{structmom__continuity__ppm_1_1continuity__ppm__cs}{continuity\+\_\+ppm\+\_\+cs}}), pointer}]{CS }\end{DoxyParamCaption})}



Initializes \mbox{\hyperlink{structmom__continuity__ppm_1_1continuity__ppm__cs}{continuity\+\_\+ppm\+\_\+cs}}. 


\begin{DoxyParams}[1]{Parameters}
\mbox{\tt in}  & {\em time} & The current model time.\\
\hline
\mbox{\tt in}  & {\em g} & The ocean\textquotesingle{}s grid structure.\\
\hline
\mbox{\tt in}  & {\em gv} & Vertical grid structure.\\
\hline
\mbox{\tt in}  & {\em us} & A dimensional unit scaling type\\
\hline
\mbox{\tt in}  & {\em param\+\_\+file} & A structure indicating the open file to parse for model parameter values.\\
\hline
\mbox{\tt in,out}  & {\em diag} & A structure that is used to regulate diagnostic output.\\
\hline
 & {\em cs} & Module\textquotesingle{}s control structure. \\
\hline
\end{DoxyParams}
This include declares and sets the variable \char`\"{}version\char`\"{}. 

Definition at line 2230 of file M\+O\+M\+\_\+continuity\+\_\+\+P\+P\+M.\+F90.


\begin{DoxyCode}
2230   \textcolor{keywordtype}{type}(time\_type), \textcolor{keywordtype}{target}, \textcolor{keywordtype}{intent(in)}    :: Time\textcolor{comment}{ !< The current model time.}
2231   \textcolor{keywordtype}{type}(ocean\_grid\_type),   \textcolor{keywordtype}{intent(in)}    :: G\textcolor{comment}{    !< The ocean's grid structure.}
2232   \textcolor{keywordtype}{type}(verticalGrid\_type), \textcolor{keywordtype}{intent(in)}    :: GV\textcolor{comment}{   !< Vertical grid structure.}
2233   \textcolor{keywordtype}{type}(unit\_scale\_type),   \textcolor{keywordtype}{intent(in)}    :: US\textcolor{comment}{  !< A dimensional unit scaling type}
2234   \textcolor{keywordtype}{type}(param\_file\_type),   \textcolor{keywordtype}{intent(in)}    :: param\_file\textcolor{comment}{ !< A structure indicating}
2235 \textcolor{comment}{                  !! the open file to parse for model parameter values.}
2236   \textcolor{keywordtype}{type}(diag\_ctrl), \textcolor{keywordtype}{target}, \textcolor{keywordtype}{intent(inout)} :: diag\textcolor{comment}{ !< A structure that is used to}
2237 \textcolor{comment}{                  !! regulate diagnostic output.}
2238   \textcolor{keywordtype}{type}(continuity\_PPM\_CS), \textcolor{keywordtype}{pointer}       :: CS\textcolor{comment}{   !< Module's control structure.}
2239 \textcolor{comment}{!> This include declares and sets the variable "version".}
2240 \textcolor{preprocessor}{#include "version\_variable.h"}
2241 \textcolor{preprocessor}{}  \textcolor{keywordtype}{real} :: tol\_eta\_m  \textcolor{comment}{! An unscaled version of tol\_eta [m].}
2242   \textcolor{keywordtype}{character(len=40)}  :: mdl = \textcolor{stringliteral}{"MOM\_continuity\_PPM"} \textcolor{comment}{! This module's name.}
2243 
2244   \textcolor{keywordflow}{if} (\textcolor{keyword}{associated}(cs)) \textcolor{keywordflow}{then}
2245     \textcolor{keyword}{call }mom\_error(warning, \textcolor{stringliteral}{"continuity\_PPM\_init called with associated control structure."})
2246     \textcolor{keywordflow}{return}
2247 \textcolor{keywordflow}{  endif}
2248   \textcolor{keyword}{allocate}(cs)
2249 
2250 \textcolor{comment}{! Read all relevant parameters and write them to the model log.}
2251   \textcolor{keyword}{call }log\_version(param\_file, mdl, version, \textcolor{stringliteral}{""})
2252   \textcolor{keyword}{call }get\_param(param\_file, mdl, \textcolor{stringliteral}{"MONOTONIC\_CONTINUITY"}, cs%monotonic, &
2253                  \textcolor{stringliteral}{"If true, CONTINUITY\_PPM uses the Colella and Woodward "}//&
2254                  \textcolor{stringliteral}{"monotonic limiter.  The default (false) is to use a "}//&
2255                  \textcolor{stringliteral}{"simple positive definite limiter."}, default=.false.)
2256   \textcolor{keyword}{call }get\_param(param\_file, mdl, \textcolor{stringliteral}{"SIMPLE\_2ND\_PPM\_CONTINUITY"}, cs%simple\_2nd, &
2257                  \textcolor{stringliteral}{"If true, CONTINUITY\_PPM uses a simple 2nd order "}//&
2258                  \textcolor{stringliteral}{"(arithmetic mean) interpolation of the edge values. "}//&
2259                  \textcolor{stringliteral}{"This may give better PV conservation properties. While "}//&
2260                  \textcolor{stringliteral}{"it formally reduces the accuracy of the continuity "}//&
2261                  \textcolor{stringliteral}{"solver itself in the strongly advective limit, it does "}//&
2262                  \textcolor{stringliteral}{"not reduce the overall order of accuracy of the dynamic "}//&
2263                  \textcolor{stringliteral}{"core."}, default=.false.)
2264   \textcolor{keyword}{call }get\_param(param\_file, mdl, \textcolor{stringliteral}{"UPWIND\_1ST\_CONTINUITY"}, cs%upwind\_1st, &
2265                  \textcolor{stringliteral}{"If true, CONTINUITY\_PPM becomes a 1st-order upwind "}//&
2266                  \textcolor{stringliteral}{"continuity solver.  This scheme is highly diffusive "}//&
2267                  \textcolor{stringliteral}{"but may be useful for debugging or in single-column "}//&
2268                  \textcolor{stringliteral}{"mode where its minimal stencil is useful."}, default=.false.)
2269   \textcolor{keyword}{call }get\_param(param\_file, mdl, \textcolor{stringliteral}{"ETA\_TOLERANCE"}, cs%tol\_eta, &
2270                  \textcolor{stringliteral}{"The tolerance for the differences between the "}//&
2271                  \textcolor{stringliteral}{"barotropic and baroclinic estimates of the sea surface "}//&
2272                  \textcolor{stringliteral}{"height due to the fluxes through each face.  The total "}//&
2273                  \textcolor{stringliteral}{"tolerance for SSH is 4 times this value.  The default "}//&
2274                  \textcolor{stringliteral}{"is 0.5*NK*ANGSTROM, and this should not be set less "}//&
2275                  \textcolor{stringliteral}{"than about 10^-15*MAXIMUM\_DEPTH."}, units=\textcolor{stringliteral}{"m"}, scale=gv%m\_to\_H, &
2276                  default=0.5*g%ke*gv%Angstrom\_m, unscaled=tol\_eta\_m)
2277 
2278   \textcolor{comment}{!### ETA\_TOLERANCE\_AUX can be obsoleted.}
2279   \textcolor{keyword}{call }get\_param(param\_file, mdl, \textcolor{stringliteral}{"ETA\_TOLERANCE\_AUX"}, cs%tol\_eta\_aux, &
2280                  \textcolor{stringliteral}{"The tolerance for free-surface height discrepancies "}//&
2281                  \textcolor{stringliteral}{"between the barotropic solution and the sum of the "}//&
2282                  \textcolor{stringliteral}{"layer thicknesses when calculating the auxiliary "}//&
2283                  \textcolor{stringliteral}{"corrected velocities. By default, this is the same as "}//&
2284                  \textcolor{stringliteral}{"ETA\_TOLERANCE, but can be made larger for efficiency."}, &
2285                  units=\textcolor{stringliteral}{"m"}, default=tol\_eta\_m, scale=gv%m\_to\_H)
2286   \textcolor{keyword}{call }get\_param(param\_file, mdl, \textcolor{stringliteral}{"VELOCITY\_TOLERANCE"}, cs%tol\_vel, &
2287                  \textcolor{stringliteral}{"The tolerance for barotropic velocity discrepancies "}//&
2288                  \textcolor{stringliteral}{"between the barotropic solution and  the sum of the "}//&
2289                  \textcolor{stringliteral}{"layer thicknesses."}, units=\textcolor{stringliteral}{"m s-1"}, default=3.0e8, scale=us%m\_s\_to\_L\_T)
2290                  \textcolor{comment}{! The speed of light is the default.}
2291 
2292   \textcolor{keyword}{call }get\_param(param\_file, mdl, \textcolor{stringliteral}{"CONT\_PPM\_AGGRESS\_ADJUST"}, cs%aggress\_adjust,&
2293                  \textcolor{stringliteral}{"If true, allow the adjusted velocities to have a "}//&
2294                  \textcolor{stringliteral}{"relative CFL change up to 0.5."}, default=.false.)
2295   cs%vol\_CFL = cs%aggress\_adjust
2296   \textcolor{keyword}{call }get\_param(param\_file, mdl, \textcolor{stringliteral}{"CONT\_PPM\_VOLUME\_BASED\_CFL"}, cs%vol\_CFL, &
2297                  \textcolor{stringliteral}{"If true, use the ratio of the open face lengths to the "}//&
2298                  \textcolor{stringliteral}{"tracer cell areas when estimating CFL numbers.  The "}//&
2299                  \textcolor{stringliteral}{"default is set by CONT\_PPM\_AGGRESS\_ADJUST."}, &
2300                  default=cs%aggress\_adjust, do\_not\_read=cs%aggress\_adjust)
2301   \textcolor{keyword}{call }get\_param(param\_file, mdl, \textcolor{stringliteral}{"CONTINUITY\_CFL\_LIMIT"}, cs%CFL\_limit\_adjust, &
2302                  \textcolor{stringliteral}{"The maximum CFL of the adjusted velocities."}, units=\textcolor{stringliteral}{"nondim"}, &
2303                  default=0.5)
2304   \textcolor{keyword}{call }get\_param(param\_file, mdl, \textcolor{stringliteral}{"CONT\_PPM\_BETTER\_ITER"}, cs%better\_iter, &
2305                  \textcolor{stringliteral}{"If true, stop corrective iterations using a velocity "}//&
2306                  \textcolor{stringliteral}{"based criterion and only stop if the iteration is "}//&
2307                  \textcolor{stringliteral}{"better than all predecessors."}, default=.true.)
2308   \textcolor{keyword}{call }get\_param(param\_file, mdl, \textcolor{stringliteral}{"CONT\_PPM\_USE\_VISC\_REM\_MAX"}, &
2309                                  cs%use\_visc\_rem\_max, &
2310                  \textcolor{stringliteral}{"If true, use more appropriate limiting bounds for "}//&
2311                  \textcolor{stringliteral}{"corrections in strongly viscous columns."}, default=.true.)
2312   \textcolor{keyword}{call }get\_param(param\_file, mdl, \textcolor{stringliteral}{"CONT\_PPM\_MARGINAL\_FACE\_AREAS"}, cs%marginal\_faces, &
2313                  \textcolor{stringliteral}{"If true, use the marginal face areas from the continuity "}//&
2314                  \textcolor{stringliteral}{"solver for use as the weights in the barotropic solver. "}//&
2315                  \textcolor{stringliteral}{"Otherwise use the transport averaged areas."}, default=.true.)
2316 
2317   cs%diag => diag
2318 
2319   id\_clock\_update = cpu\_clock\_id(\textcolor{stringliteral}{'(Ocean continuity update)'}, grain=clock\_routine)
2320   id\_clock\_correct = cpu\_clock\_id(\textcolor{stringliteral}{'(Ocean continuity correction)'}, grain=clock\_routine)
2321 
\end{DoxyCode}
\mbox{\Hypertarget{namespacemom__continuity__ppm_a3e3ee193ee52b65a1413808eea703aee}\label{namespacemom__continuity__ppm_a3e3ee193ee52b65a1413808eea703aee}} 
\index{mom\+\_\+continuity\+\_\+ppm@{mom\+\_\+continuity\+\_\+ppm}!continuity\+\_\+ppm\+\_\+stencil@{continuity\+\_\+ppm\+\_\+stencil}}
\index{continuity\+\_\+ppm\+\_\+stencil@{continuity\+\_\+ppm\+\_\+stencil}!mom\+\_\+continuity\+\_\+ppm@{mom\+\_\+continuity\+\_\+ppm}}
\subsubsection{\texorpdfstring{continuity\+\_\+ppm\+\_\+stencil()}{continuity\_ppm\_stencil()}}
{\footnotesize\ttfamily integer function, public mom\+\_\+continuity\+\_\+ppm\+::continuity\+\_\+ppm\+\_\+stencil (\begin{DoxyParamCaption}\item[{type(\mbox{\hyperlink{structmom__continuity__ppm_1_1continuity__ppm__cs}{continuity\+\_\+ppm\+\_\+cs}}), pointer}]{CS }\end{DoxyParamCaption})}



continuity\+\_\+\+P\+P\+M\+\_\+stencil returns the continuity solver stencil size 


\begin{DoxyParams}{Parameters}
{\em cs} & Module\textquotesingle{}s control structure.\\
\hline
\end{DoxyParams}
\begin{DoxyReturn}{Returns}
The continuity solver stencil size with the current settings. 
\end{DoxyReturn}


Definition at line 2326 of file M\+O\+M\+\_\+continuity\+\_\+\+P\+P\+M.\+F90.


\begin{DoxyCode}
2326   \textcolor{keywordtype}{type}(continuity\_PPM\_CS), \textcolor{keywordtype}{pointer}       :: CS\textcolor{comment}{  !< Module's control structure.}
2327   \textcolor{keywordtype}{integer} ::  stencil\textcolor{comment}{ !< The continuity solver stencil size with the current settings.}
2328 
2329   stencil = 3 ; \textcolor{keywordflow}{if} (cs%simple\_2nd) stencil = 2 ; \textcolor{keywordflow}{if} (cs%upwind\_1st) stencil = 1
2330 
\end{DoxyCode}
\mbox{\Hypertarget{namespacemom__continuity__ppm_a293f7ab5bfd8f3f6a5a50903b05b6411}\label{namespacemom__continuity__ppm_a293f7ab5bfd8f3f6a5a50903b05b6411}} 
\index{mom\+\_\+continuity\+\_\+ppm@{mom\+\_\+continuity\+\_\+ppm}!merid\+\_\+face\+\_\+thickness@{merid\+\_\+face\+\_\+thickness}}
\index{merid\+\_\+face\+\_\+thickness@{merid\+\_\+face\+\_\+thickness}!mom\+\_\+continuity\+\_\+ppm@{mom\+\_\+continuity\+\_\+ppm}}
\subsubsection{\texorpdfstring{merid\+\_\+face\+\_\+thickness()}{merid\_face\_thickness()}}
{\footnotesize\ttfamily subroutine mom\+\_\+continuity\+\_\+ppm\+::merid\+\_\+face\+\_\+thickness (\begin{DoxyParamCaption}\item[{real, dimension(szi\+\_\+(g),szjb\+\_\+(g),szk\+\_\+(g)), intent(in)}]{v,  }\item[{real, dimension(szi\+\_\+(g),szj\+\_\+(g),szk\+\_\+(g)), intent(in)}]{h,  }\item[{real, dimension(szi\+\_\+(g),szj\+\_\+(g),szk\+\_\+(g)), intent(in)}]{h\+\_\+L,  }\item[{real, dimension(szi\+\_\+(g),szj\+\_\+(g),szk\+\_\+(g)), intent(in)}]{h\+\_\+R,  }\item[{real, dimension(szi\+\_\+(g),szjb\+\_\+(g),szk\+\_\+(g)), intent(inout)}]{h\+\_\+v,  }\item[{real, intent(in)}]{dt,  }\item[{type(ocean\+\_\+grid\+\_\+type), intent(inout)}]{G,  }\item[{type(unit\+\_\+scale\+\_\+type), intent(in)}]{US,  }\item[{type(\mbox{\hyperlink{structmom__continuity__ppm_1_1loop__bounds__type}{loop\+\_\+bounds\+\_\+type}}), intent(in)}]{LB,  }\item[{logical, intent(in)}]{vol\+\_\+\+C\+FL,  }\item[{logical, intent(in)}]{marginal,  }\item[{real, dimension(szi\+\_\+(g),szjb\+\_\+(g),szk\+\_\+(g)), intent(in), optional}]{visc\+\_\+rem\+\_\+v,  }\item[{type(ocean\+\_\+obc\+\_\+type), optional, pointer}]{O\+BC }\end{DoxyParamCaption})\hspace{0.3cm}{\ttfamily [private]}}



Sets the effective interface thickness at each meridional velocity point. 


\begin{DoxyParams}[1]{Parameters}
\mbox{\tt in,out}  & {\em g} & Ocean\textquotesingle{}s grid structure.\\
\hline
\mbox{\tt in}  & {\em v} & Meridional velocity \mbox{[}L T-\/1 $\sim$$>$ m s-\/1\mbox{]}.\\
\hline
\mbox{\tt in}  & {\em h} & Layer thickness used to calculate fluxes, \mbox{[}H $\sim$$>$ m or kg m-\/2\mbox{]}.\\
\hline
\mbox{\tt in}  & {\em h\+\_\+l} & Left thickness in the reconstruction, \mbox{[}H $\sim$$>$ m or kg m-\/2\mbox{]}.\\
\hline
\mbox{\tt in}  & {\em h\+\_\+r} & Right thickness in the reconstruction, \mbox{[}H $\sim$$>$ m or kg m-\/2\mbox{]}.\\
\hline
\mbox{\tt in,out}  & {\em h\+\_\+v} & Thickness at meridional faces, \mbox{[}H $\sim$$>$ m or kg m-\/2\mbox{]}.\\
\hline
\mbox{\tt in}  & {\em dt} & Time increment \mbox{[}T $\sim$$>$ s\mbox{]}.\\
\hline
\mbox{\tt in}  & {\em lb} & Loop bounds structure.\\
\hline
\mbox{\tt in}  & {\em us} & A dimensional unit scaling type\\
\hline
\mbox{\tt in}  & {\em vol\+\_\+cfl} & If true, rescale the ratio of face areas to the cell areas when estimating the C\+FL number.\\
\hline
\mbox{\tt in}  & {\em marginal} & If true, report the marginal face thicknesses; otherwise report transport-\/averaged thicknesses.\\
\hline
\mbox{\tt in}  & {\em visc\+\_\+rem\+\_\+v} & Both the fraction of the momentum originally in a layer that remains after a time-\/step of viscosity, and the fraction of a time-\/step\textquotesingle{}s worth of a barotropic acceleration that a layer experiences after viscosity is applied. Non-\/dimensional between 0 (at the bottom) and 1 (far above the bottom).\\
\hline
 & {\em obc} & Open boundaries control structure. \\
\hline
\end{DoxyParams}


Definition at line 1428 of file M\+O\+M\+\_\+continuity\+\_\+\+P\+P\+M.\+F90.


\begin{DoxyCode}
1428   \textcolor{keywordtype}{type}(ocean\_grid\_type),                     \textcolor{keywordtype}{intent(inout)} :: G\textcolor{comment}{    !< Ocean's grid structure.}
1429   \textcolor{keywordtype}{real}, \textcolor{keywordtype}{dimension(SZI\_(G),SZJB\_(G),SZK\_(G))}, \textcolor{keywordtype}{intent(in)}    :: v\textcolor{comment}{    !< Meridional velocity [L T-1 ~> m s-1].}
1430   \textcolor{keywordtype}{real}, \textcolor{keywordtype}{dimension(SZI\_(G),SZJ\_(G),SZK\_(G))},  \textcolor{keywordtype}{intent(in)}    :: h\textcolor{comment}{    !< Layer thickness used to calculate
       fluxes,}
1431 \textcolor{comment}{                                                                   !! [H ~> m or kg m-2].}
1432   \textcolor{keywordtype}{real}, \textcolor{keywordtype}{dimension(SZI\_(G),SZJ\_(G),SZK\_(G))},  \textcolor{keywordtype}{intent(in)}    :: h\_L\textcolor{comment}{  !< Left thickness in the reconstruction,}
1433 \textcolor{comment}{                                                                   !! [H ~> m or kg m-2].}
1434   \textcolor{keywordtype}{real}, \textcolor{keywordtype}{dimension(SZI\_(G),SZJ\_(G),SZK\_(G))},  \textcolor{keywordtype}{intent(in)}    :: h\_R\textcolor{comment}{  !< Right thickness in the
       reconstruction,}
1435 \textcolor{comment}{                                                                   !! [H ~> m or kg m-2].}
1436   \textcolor{keywordtype}{real}, \textcolor{keywordtype}{dimension(SZI\_(G),SZJB\_(G),SZK\_(G))}, \textcolor{keywordtype}{intent(inout)} :: h\_v\textcolor{comment}{  !< Thickness at meridional faces,}
1437 \textcolor{comment}{                                                                   !! [H ~> m or kg m-2].}
1438   \textcolor{keywordtype}{real},                                      \textcolor{keywordtype}{intent(in)}    :: dt\textcolor{comment}{   !< Time increment [T ~> s].}
1439   \textcolor{keywordtype}{type}(loop\_bounds\_type),                    \textcolor{keywordtype}{intent(in)}    :: LB\textcolor{comment}{   !< Loop bounds structure.}
1440   \textcolor{keywordtype}{type}(unit\_scale\_type),                     \textcolor{keywordtype}{intent(in)}    :: US\textcolor{comment}{   !< A dimensional unit scaling type}
1441   \textcolor{keywordtype}{logical},                                   \textcolor{keywordtype}{intent(in)}    :: vol\_CFL\textcolor{comment}{ !< If true, rescale the ratio}
1442 \textcolor{comment}{                          !! of face areas to the cell areas when estimating the CFL number.}
1443   \textcolor{keywordtype}{logical},                                   \textcolor{keywordtype}{intent(in)}    :: marginal\textcolor{comment}{ !< If true, report the marginal}
1444 \textcolor{comment}{                          !! face thicknesses; otherwise report transport-averaged thicknesses.}
1445   \textcolor{keywordtype}{real}, \textcolor{keywordtype}{dimension(SZI\_(G),SZJB\_(G),SZK\_(G))}, \textcolor{keywordtype}{optional}, \textcolor{keywordtype}{intent(in)} :: visc\_rem\_v\textcolor{comment}{ !< Both the fraction}
1446 \textcolor{comment}{                          !! of the momentum originally in a layer that remains after a time-step of}
1447 \textcolor{comment}{                          !! viscosity, and the fraction of a time-step's worth of a barotropic}
1448 \textcolor{comment}{                          !! acceleration that a layer experiences after viscosity is applied.}
1449 \textcolor{comment}{                          !! Non-dimensional between 0 (at the bottom) and 1 (far above the bottom).}
1450   \textcolor{keywordtype}{type}(ocean\_OBC\_type),            \textcolor{keywordtype}{optional}, \textcolor{keywordtype}{pointer} :: OBC\textcolor{comment}{ !< Open boundaries control structure.}
1451 
1452   \textcolor{comment}{! Local variables}
1453   \textcolor{keywordtype}{real} :: CFL \textcolor{comment}{! The CFL number based on the local velocity and grid spacing [nondim]}
1454   \textcolor{keywordtype}{real} :: curv\_3 \textcolor{comment}{! A measure of the thickness curvature over a grid length,}
1455                  \textcolor{comment}{! with the same units as h [H ~> m or kg m-2] .}
1456   \textcolor{keywordtype}{real} :: h\_avg  \textcolor{comment}{! The average thickness of a flux [H ~> m or kg m-2].}
1457   \textcolor{keywordtype}{real} :: h\_marg \textcolor{comment}{! The marginal thickness of a flux [H ~> m or kg m-2].}
1458   \textcolor{keywordtype}{logical} :: local\_open\_BC
1459   \textcolor{keywordtype}{integer} :: i, j, k, ish, ieh, jsh, jeh, n, nz
1460   ish = lb%ish ; ieh = lb%ieh ; jsh = lb%jsh ; jeh = lb%jeh ; nz = g%ke
1461 
1462   \textcolor{comment}{!$OMP parallel do default(shared) private(CFL,curv\_3,h\_marg,h\_avg)}
1463   \textcolor{keywordflow}{do} k=1,nz ; \textcolor{keywordflow}{do} j=jsh-1,jeh ; \textcolor{keywordflow}{do} i=ish,ieh
1464     \textcolor{keywordflow}{if} (v(i,j,k) > 0.0) \textcolor{keywordflow}{then}
1465       \textcolor{keywordflow}{if} (vol\_cfl) \textcolor{keywordflow}{then} ; cfl = (v(i,j,k) * dt) * (g%dx\_Cv(i,j) * g%IareaT(i,j))
1466       \textcolor{keywordflow}{else} ; cfl = v(i,j,k) * dt * g%IdyT(i,j) ;\textcolor{keywordflow}{ endif}
1467       curv\_3 = h\_l(i,j,k) + h\_r(i,j,k) - 2.0*h(i,j,k)
1468       h\_avg = h\_r(i,j,k) + cfl * (0.5*(h\_l(i,j,k) - h\_r(i,j,k)) + curv\_3*(cfl - 1.5))
1469       h\_marg = h\_r(i,j,k) + cfl * ((h\_l(i,j,k) - h\_r(i,j,k)) + &
1470                                 3.0*curv\_3*(cfl - 1.0))
1471     \textcolor{keywordflow}{elseif} (v(i,j,k) < 0.0) \textcolor{keywordflow}{then}
1472       \textcolor{keywordflow}{if} (vol\_cfl) \textcolor{keywordflow}{then} ; cfl = (-v(i,j,k)*dt) * (g%dx\_Cv(i,j) * g%IareaT(i,j+1))
1473       \textcolor{keywordflow}{else} ; cfl = -v(i,j,k) * dt * g%IdyT(i,j+1) ;\textcolor{keywordflow}{ endif}
1474       curv\_3 = h\_l(i,j+1,k) + h\_r(i,j+1,k) - 2.0*h(i,j+1,k)
1475       h\_avg = h\_l(i,j+1,k) + cfl * (0.5*(h\_r(i,j+1,k)-h\_l(i,j+1,k)) + curv\_3*(cfl - 1.5))
1476       h\_marg = h\_l(i,j+1,k) + cfl * ((h\_r(i,j+1,k)-h\_l(i,j+1,k)) + &
1477                                     3.0*curv\_3*(cfl - 1.0))
1478     \textcolor{keywordflow}{else}
1479       h\_avg = 0.5 * (h\_l(i,j+1,k) + h\_r(i,j,k))
1480       \textcolor{comment}{!   The choice to use the arithmetic mean here is somewhat arbitrariy, but}
1481       \textcolor{comment}{! it should be noted that h\_L(i+1,j,k) and h\_R(i,j,k) are usually the same.}
1482       h\_marg = 0.5 * (h\_l(i,j+1,k) + h\_r(i,j,k))
1483  \textcolor{comment}{!    h\_marg = (2.0 * h\_L(i,j+1,k) * h\_R(i,j,k)) / &}
1484  \textcolor{comment}{!             (h\_L(i,j+1,k) + h\_R(i,j,k) + GV%H\_subroundoff)}
1485 \textcolor{keywordflow}{    endif}
1486 
1487     \textcolor{keywordflow}{if} (marginal) \textcolor{keywordflow}{then} ; h\_v(i,j,k) = h\_marg
1488     \textcolor{keywordflow}{else} ; h\_v(i,j,k) = h\_avg ;\textcolor{keywordflow}{ endif}
1489 \textcolor{keywordflow}{  enddo} ;\textcolor{keywordflow}{ enddo} ;\textcolor{keywordflow}{ enddo}
1490 
1491   \textcolor{keywordflow}{if} (\textcolor{keyword}{present}(visc\_rem\_v)) \textcolor{keywordflow}{then}
1492     \textcolor{comment}{!$OMP parallel do default(shared)}
1493     \textcolor{keywordflow}{do} k=1,nz ; \textcolor{keywordflow}{do} j=jsh-1,jeh ; \textcolor{keywordflow}{do} i=ish,ieh
1494       h\_v(i,j,k) = h\_v(i,j,k) * visc\_rem\_v(i,j,k)
1495 \textcolor{keywordflow}{    enddo} ;\textcolor{keywordflow}{ enddo} ;\textcolor{keywordflow}{ enddo}
1496 \textcolor{keywordflow}{  endif}
1497 
1498   local\_open\_bc = .false.
1499   \textcolor{keywordflow}{if} (\textcolor{keyword}{present}(obc)) \textcolor{keywordflow}{then} ; \textcolor{keywordflow}{if} (\textcolor{keyword}{associated}(obc)) \textcolor{keywordflow}{then}
1500     local\_open\_bc = obc%open\_v\_BCs\_exist\_globally
1501 \textcolor{keywordflow}{  endif} ;\textcolor{keywordflow}{ endif}
1502   \textcolor{keywordflow}{if} (local\_open\_bc) \textcolor{keywordflow}{then}
1503     \textcolor{keywordflow}{do} n = 1, obc%number\_of\_segments
1504       \textcolor{keywordflow}{if} (obc%segment(n)%open .and. obc%segment(n)%is\_N\_or\_S) \textcolor{keywordflow}{then}
1505         j = obc%segment(n)%HI%JsdB
1506         \textcolor{keywordflow}{if} (obc%segment(n)%direction == obc\_direction\_n) \textcolor{keywordflow}{then}
1507           \textcolor{keywordflow}{if} (\textcolor{keyword}{present}(visc\_rem\_v)) \textcolor{keywordflow}{then} ; \textcolor{keywordflow}{do} k=1,nz
1508             \textcolor{keywordflow}{do} i = obc%segment(n)%HI%isd, obc%segment(n)%HI%ied
1509               h\_v(i,j,k) = h(i,j,k) * visc\_rem\_v(i,j,k)
1510 \textcolor{keywordflow}{            enddo}
1511 \textcolor{keywordflow}{          enddo} ; \textcolor{keywordflow}{else} ; \textcolor{keywordflow}{do} k=1,nz
1512             \textcolor{keywordflow}{do} i = obc%segment(n)%HI%isd, obc%segment(n)%HI%ied
1513               h\_v(i,j,k) = h(i,j,k)
1514 \textcolor{keywordflow}{            enddo}
1515 \textcolor{keywordflow}{          enddo} ;\textcolor{keywordflow}{ endif}
1516         \textcolor{keywordflow}{else}
1517           \textcolor{keywordflow}{if} (\textcolor{keyword}{present}(visc\_rem\_v)) \textcolor{keywordflow}{then} ; \textcolor{keywordflow}{do} k=1,nz
1518             \textcolor{keywordflow}{do} i = obc%segment(n)%HI%isd, obc%segment(n)%HI%ied
1519               h\_v(i,j,k) = h(i,j+1,k) * visc\_rem\_v(i,j,k)
1520 \textcolor{keywordflow}{            enddo}
1521 \textcolor{keywordflow}{          enddo} ; \textcolor{keywordflow}{else} ; \textcolor{keywordflow}{do} k=1,nz
1522             \textcolor{keywordflow}{do} i = obc%segment(n)%HI%isd, obc%segment(n)%HI%ied
1523               h\_v(i,j,k) = h(i,j+1,k)
1524 \textcolor{keywordflow}{            enddo}
1525 \textcolor{keywordflow}{          enddo} ;\textcolor{keywordflow}{ endif}
1526 \textcolor{keywordflow}{        endif}
1527 \textcolor{keywordflow}{      endif}
1528 \textcolor{keywordflow}{    enddo}
1529 \textcolor{keywordflow}{  endif}
1530 
\end{DoxyCode}
\mbox{\Hypertarget{namespacemom__continuity__ppm_ac00aefda40cb9e22013e99cad342bb63}\label{namespacemom__continuity__ppm_ac00aefda40cb9e22013e99cad342bb63}} 
\index{mom\+\_\+continuity\+\_\+ppm@{mom\+\_\+continuity\+\_\+ppm}!merid\+\_\+flux\+\_\+layer@{merid\+\_\+flux\+\_\+layer}}
\index{merid\+\_\+flux\+\_\+layer@{merid\+\_\+flux\+\_\+layer}!mom\+\_\+continuity\+\_\+ppm@{mom\+\_\+continuity\+\_\+ppm}}
\subsubsection{\texorpdfstring{merid\+\_\+flux\+\_\+layer()}{merid\_flux\_layer()}}
{\footnotesize\ttfamily subroutine mom\+\_\+continuity\+\_\+ppm\+::merid\+\_\+flux\+\_\+layer (\begin{DoxyParamCaption}\item[{real, dimension(szi\+\_\+(g)), intent(in)}]{v,  }\item[{real, dimension( g \%isd\+: g \%ied, g \%jsd\+: g \%jed), intent(in)}]{h,  }\item[{real, dimension( g \%isd\+: g \%ied, g \%jsd\+: g \%jed), intent(in)}]{h\+\_\+L,  }\item[{real, dimension( g \%isd\+: g \%ied, g \%jsd\+: g \%jed), intent(in)}]{h\+\_\+R,  }\item[{real, dimension( g \%isd\+: g \%ied), intent(inout)}]{vh,  }\item[{real, dimension( g \%isd\+: g \%ied), intent(inout)}]{dvhdv,  }\item[{real, dimension(szi\+\_\+(g)), intent(in)}]{visc\+\_\+rem,  }\item[{real, intent(in)}]{dt,  }\item[{type(ocean\+\_\+grid\+\_\+type), intent(inout)}]{G,  }\item[{type(unit\+\_\+scale\+\_\+type), intent(in)}]{US,  }\item[{integer, intent(in)}]{J,  }\item[{integer, intent(in)}]{ish,  }\item[{integer, intent(in)}]{ieh,  }\item[{logical, dimension( g \%isd\+: g \%ied), intent(in)}]{do\+\_\+I,  }\item[{logical, intent(in)}]{vol\+\_\+\+C\+FL,  }\item[{type(ocean\+\_\+obc\+\_\+type), optional, pointer}]{O\+BC }\end{DoxyParamCaption})\hspace{0.3cm}{\ttfamily [private]}}



Evaluates the meridional mass or volume fluxes in a layer. 


\begin{DoxyParams}[1]{Parameters}
\mbox{\tt in,out}  & {\em g} & Ocean\textquotesingle{}s grid structure.\\
\hline
\mbox{\tt in}  & {\em v} & Meridional velocity \mbox{[}L T-\/1 $\sim$$>$ m s-\/1\mbox{]}.\\
\hline
\mbox{\tt in}  & {\em visc\+\_\+rem} & Both the fraction of the momentum originally in a layer that remains after a time-\/step of viscosity, and the fraction of a time-\/step\textquotesingle{}s worth of a barotropic acceleration that a layer experiences after viscosity is applied. Non-\/dimensional between 0 (at the bottom) and 1 (far above the bottom).\\
\hline
\mbox{\tt in}  & {\em h} & Layer thickness used to calculate fluxes, \mbox{[}H $\sim$$>$ m or kg m-\/2\mbox{]}.\\
\hline
\mbox{\tt in}  & {\em h\+\_\+l} & Left thickness in the reconstruction \mbox{[}H $\sim$$>$ m or kg m-\/2\mbox{]}.\\
\hline
\mbox{\tt in}  & {\em h\+\_\+r} & Right thickness in the reconstruction \mbox{[}H $\sim$$>$ m or kg m-\/2\mbox{]}.\\
\hline
\mbox{\tt in,out}  & {\em vh} & Meridional mass or volume transport \mbox{[}H L2 T-\/1 $\sim$$>$ m3 s-\/1 or kg s-\/1\mbox{]}.\\
\hline
\mbox{\tt in,out}  & {\em dvhdv} & Partial derivative of vh with v \mbox{[}H L $\sim$$>$ m2 or kg m-\/1\mbox{]}.\\
\hline
\mbox{\tt in}  & {\em dt} & Time increment \mbox{[}T $\sim$$>$ s\mbox{]}.\\
\hline
\mbox{\tt in}  & {\em us} & A dimensional unit scaling type\\
\hline
\mbox{\tt in}  & {\em j} & Spatial index.\\
\hline
\mbox{\tt in}  & {\em ish} & Start of index range.\\
\hline
\mbox{\tt in}  & {\em ieh} & End of index range.\\
\hline
\mbox{\tt in}  & {\em do\+\_\+i} & Which i values to work on.\\
\hline
\mbox{\tt in}  & {\em vol\+\_\+cfl} & If true, rescale the ratio of face areas to the cell areas when estimating the C\+FL number.\\
\hline
 & {\em obc} & Open boundaries control structure. \\
\hline
\end{DoxyParams}


Definition at line 1342 of file M\+O\+M\+\_\+continuity\+\_\+\+P\+P\+M.\+F90.


\begin{DoxyCode}
1342   \textcolor{keywordtype}{type}(ocean\_grid\_type),        \textcolor{keywordtype}{intent(inout)} :: G\textcolor{comment}{        !< Ocean's grid structure.}
1343   \textcolor{keywordtype}{real}, \textcolor{keywordtype}{dimension(SZI\_(G))},     \textcolor{keywordtype}{intent(in)}    :: v\textcolor{comment}{        !< Meridional velocity [L T-1 ~> m s-1].}
1344   \textcolor{keywordtype}{real}, \textcolor{keywordtype}{dimension(SZI\_(G))},     \textcolor{keywordtype}{intent(in)}    :: visc\_rem\textcolor{comment}{ !< Both the fraction of the}
1345 \textcolor{comment}{         !! momentum originally in a layer that remains after a time-step}
1346 \textcolor{comment}{         !! of viscosity, and the fraction of a time-step's worth of a barotropic}
1347 \textcolor{comment}{         !! acceleration that a layer experiences after viscosity is applied.}
1348 \textcolor{comment}{         !! Non-dimensional between 0 (at the bottom) and 1 (far above the bottom).}
1349   \textcolor{keywordtype}{real}, \textcolor{keywordtype}{dimension(SZI\_(G),SZJ\_(G))},  \textcolor{keywordtype}{intent(in)} :: h\textcolor{comment}{      !< Layer thickness used to calculate fluxes,}
1350 \textcolor{comment}{                                                          !! [H ~> m or kg m-2].}
1351   \textcolor{keywordtype}{real}, \textcolor{keywordtype}{dimension(SZI\_(G),SZJ\_(G))},  \textcolor{keywordtype}{intent(in)} :: h\_L\textcolor{comment}{    !< Left thickness in the reconstruction}
1352 \textcolor{comment}{                                                          !! [H ~> m or kg m-2].}
1353   \textcolor{keywordtype}{real}, \textcolor{keywordtype}{dimension(SZI\_(G),SZJ\_(G))},  \textcolor{keywordtype}{intent(in)} :: h\_R\textcolor{comment}{    !< Right thickness in the reconstruction}
1354 \textcolor{comment}{                                                          !! [H ~> m or kg m-2].}
1355   \textcolor{keywordtype}{real}, \textcolor{keywordtype}{dimension(SZI\_(G))},     \textcolor{keywordtype}{intent(inout)} :: vh\textcolor{comment}{       !< Meridional mass or volume transport}
1356 \textcolor{comment}{                                                          !! [H L2 T-1 ~> m3 s-1 or kg s-1].}
1357   \textcolor{keywordtype}{real}, \textcolor{keywordtype}{dimension(SZI\_(G))},     \textcolor{keywordtype}{intent(inout)} :: dvhdv\textcolor{comment}{    !< Partial derivative of vh with v}
1358 \textcolor{comment}{                                                          !! [H L ~> m2 or kg m-1].}
1359   \textcolor{keywordtype}{real},                         \textcolor{keywordtype}{intent(in)}    :: dt\textcolor{comment}{       !< Time increment [T ~> s].}
1360   \textcolor{keywordtype}{type}(unit\_scale\_type),        \textcolor{keywordtype}{intent(in)}    :: US\textcolor{comment}{       !< A dimensional unit scaling type}
1361   \textcolor{keywordtype}{integer},                      \textcolor{keywordtype}{intent(in)}    :: j\textcolor{comment}{        !< Spatial index.}
1362   \textcolor{keywordtype}{integer},                      \textcolor{keywordtype}{intent(in)}    :: ish\textcolor{comment}{      !< Start of index range.}
1363   \textcolor{keywordtype}{integer},                      \textcolor{keywordtype}{intent(in)}    :: ieh\textcolor{comment}{      !< End of index range.}
1364   \textcolor{keywordtype}{logical}, \textcolor{keywordtype}{dimension(SZI\_(G))},  \textcolor{keywordtype}{intent(in)}    :: do\_I\textcolor{comment}{     !< Which i values to work on.}
1365   \textcolor{keywordtype}{logical},                      \textcolor{keywordtype}{intent(in)}    :: vol\_CFL\textcolor{comment}{  !< If true, rescale the}
1366 \textcolor{comment}{         !! ratio of face areas to the cell areas when estimating the CFL number.}
1367   \textcolor{keywordtype}{type}(ocean\_OBC\_type), \textcolor{keywordtype}{optional}, \textcolor{keywordtype}{pointer} :: OBC\textcolor{comment}{ !< Open boundaries control structure.}
1368   \textcolor{comment}{! Local variables}
1369   \textcolor{keywordtype}{real} :: CFL \textcolor{comment}{! The CFL number based on the local velocity and grid spacing [nondim]}
1370   \textcolor{keywordtype}{real} :: curv\_3 \textcolor{comment}{! A measure of the thickness curvature over a grid length,}
1371                  \textcolor{comment}{! with the same units as h, i.e. [H ~> m or kg m-2].}
1372   \textcolor{keywordtype}{real} :: h\_marg \textcolor{comment}{! The marginal thickness of a flux [H ~> m or kg m-2].}
1373   \textcolor{keywordtype}{integer} :: i
1374   \textcolor{keywordtype}{integer} :: l\_seg
1375   \textcolor{keywordtype}{logical} :: local\_open\_BC
1376 
1377   local\_open\_bc = .false.
1378   \textcolor{keywordflow}{if} (\textcolor{keyword}{present}(obc)) \textcolor{keywordflow}{then} ; \textcolor{keywordflow}{if} (\textcolor{keyword}{associated}(obc)) \textcolor{keywordflow}{then}
1379     local\_open\_bc = obc%open\_v\_BCs\_exist\_globally
1380 \textcolor{keywordflow}{  endif} ;\textcolor{keywordflow}{ endif}
1381 
1382   \textcolor{keywordflow}{do} i=ish,ieh ; \textcolor{keywordflow}{if} (do\_i(i)) \textcolor{keywordflow}{then}
1383     \textcolor{keywordflow}{if} (v(i) > 0.0) \textcolor{keywordflow}{then}
1384       \textcolor{keywordflow}{if} (vol\_cfl) \textcolor{keywordflow}{then} ; cfl = (v(i) * dt) * (g%dx\_Cv(i,j) * g%IareaT(i,j))
1385       \textcolor{keywordflow}{else} ; cfl = v(i) * dt * g%IdyT(i,j) ;\textcolor{keywordflow}{ endif}
1386       curv\_3 = h\_l(i,j) + h\_r(i,j) - 2.0*h(i,j)
1387       vh(i) = g%dx\_Cv(i,j) * v(i) * ( h\_r(i,j) + cfl * &
1388           (0.5*(h\_l(i,j) - h\_r(i,j)) + curv\_3*(cfl - 1.5)) )
1389       h\_marg = h\_r(i,j) + cfl * ((h\_l(i,j) - h\_r(i,j)) + &
1390                                   3.0*curv\_3*(cfl - 1.0))
1391     \textcolor{keywordflow}{elseif} (v(i) < 0.0) \textcolor{keywordflow}{then}
1392       \textcolor{keywordflow}{if} (vol\_cfl) \textcolor{keywordflow}{then} ; cfl = (-v(i) * dt) * (g%dx\_Cv(i,j) * g%IareaT(i,j+1))
1393       \textcolor{keywordflow}{else} ; cfl = -v(i) * dt * g%IdyT(i,j+1) ;\textcolor{keywordflow}{ endif}
1394       curv\_3 = h\_l(i,j+1) + h\_r(i,j+1) - 2.0*h(i,j+1)
1395       vh(i) = g%dx\_Cv(i,j) * v(i) * ( h\_l(i,j+1) + cfl * &
1396           (0.5*(h\_r(i,j+1)-h\_l(i,j+1)) + curv\_3*(cfl - 1.5)) )
1397       h\_marg = h\_l(i,j+1) + cfl * ((h\_r(i,j+1)-h\_l(i,j+1)) + &
1398                                     3.0*curv\_3*(cfl - 1.0))
1399     \textcolor{keywordflow}{else}
1400       vh(i) = 0.0
1401       h\_marg = 0.5 * (h\_l(i,j+1) + h\_r(i,j))
1402 \textcolor{keywordflow}{    endif}
1403     dvhdv(i) = g%dx\_Cv(i,j) * h\_marg * visc\_rem(i)
1404 \textcolor{keywordflow}{  endif} ;\textcolor{keywordflow}{ enddo}
1405 
1406   \textcolor{keywordflow}{if} (local\_open\_bc) \textcolor{keywordflow}{then}
1407     \textcolor{keywordflow}{do} i=ish,ieh ; \textcolor{keywordflow}{if} (do\_i(i)) \textcolor{keywordflow}{then}
1408       l\_seg = obc%segnum\_v(i,j)
1409 
1410       \textcolor{keywordflow}{if} (l\_seg /= obc\_none) \textcolor{keywordflow}{then}
1411         \textcolor{keywordflow}{if} (obc%segment(l\_seg)%open) \textcolor{keywordflow}{then}
1412           \textcolor{keywordflow}{if} (obc%segment(l\_seg)%direction == obc\_direction\_n) \textcolor{keywordflow}{then}
1413             vh(i) = g%dx\_Cv(i,j) * v(i) * h(i,j)
1414             dvhdv(i) = g%dx\_Cv(i,j) * h(i,j) * visc\_rem(i)
1415           \textcolor{keywordflow}{else}
1416             vh(i) = g%dx\_Cv(i,j) * v(i) * h(i,j+1)
1417             dvhdv(i) = g%dx\_Cv(i,j) * h(i,j+1) * visc\_rem(i)
1418 \textcolor{keywordflow}{          endif}
1419 \textcolor{keywordflow}{        endif}
1420 \textcolor{keywordflow}{      endif}
1421 \textcolor{keywordflow}{    endif} ;\textcolor{keywordflow}{ enddo}
1422 \textcolor{keywordflow}{  endif}
\end{DoxyCode}
\mbox{\Hypertarget{namespacemom__continuity__ppm_a6deb1b7de418a17cacd60dabc262ba29}\label{namespacemom__continuity__ppm_a6deb1b7de418a17cacd60dabc262ba29}} 
\index{mom\+\_\+continuity\+\_\+ppm@{mom\+\_\+continuity\+\_\+ppm}!meridional\+\_\+flux\+\_\+adjust@{meridional\+\_\+flux\+\_\+adjust}}
\index{meridional\+\_\+flux\+\_\+adjust@{meridional\+\_\+flux\+\_\+adjust}!mom\+\_\+continuity\+\_\+ppm@{mom\+\_\+continuity\+\_\+ppm}}
\subsubsection{\texorpdfstring{meridional\+\_\+flux\+\_\+adjust()}{meridional\_flux\_adjust()}}
{\footnotesize\ttfamily subroutine mom\+\_\+continuity\+\_\+ppm\+::meridional\+\_\+flux\+\_\+adjust (\begin{DoxyParamCaption}\item[{real, dimension(szi\+\_\+(g),szjb\+\_\+(g),szk\+\_\+(g)), intent(in)}]{v,  }\item[{real, dimension(szi\+\_\+(g),szj\+\_\+(g),szk\+\_\+(g)), intent(in)}]{h\+\_\+in,  }\item[{real, dimension(szi\+\_\+(g),szj\+\_\+(g),szk\+\_\+(g)), intent(in)}]{h\+\_\+L,  }\item[{real, dimension(szi\+\_\+(g),szj\+\_\+(g),szk\+\_\+(g)), intent(in)}]{h\+\_\+R,  }\item[{real, dimension( g \%isd\+: g \%ied), intent(in), optional}]{vhbt,  }\item[{real, dimension( g \%isd\+: g \%ied), intent(in)}]{vh\+\_\+tot\+\_\+0,  }\item[{real, dimension( g \%isd\+: g \%ied), intent(in)}]{dvhdv\+\_\+tot\+\_\+0,  }\item[{real, dimension( g \%isd\+: g \%ied), intent(out)}]{dv,  }\item[{real, dimension( g \%isd\+: g \%ied), intent(in)}]{dv\+\_\+max\+\_\+\+C\+FL,  }\item[{real, dimension( g \%isd\+: g \%ied), intent(in)}]{dv\+\_\+min\+\_\+\+C\+FL,  }\item[{real, intent(in)}]{dt,  }\item[{type(ocean\+\_\+grid\+\_\+type), intent(inout)}]{G,  }\item[{type(unit\+\_\+scale\+\_\+type), intent(in)}]{US,  }\item[{type(\mbox{\hyperlink{structmom__continuity__ppm_1_1continuity__ppm__cs}{continuity\+\_\+ppm\+\_\+cs}}), pointer}]{CS,  }\item[{real, dimension(szi\+\_\+(g),szk\+\_\+(g)), intent(in)}]{visc\+\_\+rem,  }\item[{integer, intent(in)}]{j,  }\item[{integer, intent(in)}]{ish,  }\item[{integer, intent(in)}]{ieh,  }\item[{logical, dimension(szi\+\_\+(g)), intent(in)}]{do\+\_\+\+I\+\_\+in,  }\item[{logical, intent(in), optional}]{full\+\_\+precision,  }\item[{real, dimension(szi\+\_\+(g),szjb\+\_\+(g),szk\+\_\+(g)), intent(inout), optional}]{vh\+\_\+3d,  }\item[{type(ocean\+\_\+obc\+\_\+type), optional, pointer}]{O\+BC }\end{DoxyParamCaption})\hspace{0.3cm}{\ttfamily [private]}}



Returns the barotropic velocity adjustment that gives the desired barotropic (layer-\/summed) transport. 


\begin{DoxyParams}[1]{Parameters}
\mbox{\tt in,out}  & {\em g} & Ocean\textquotesingle{}s grid structure.\\
\hline
\mbox{\tt in}  & {\em v} & Meridional velocity \mbox{[}L T-\/1 $\sim$$>$ m s-\/1\mbox{]}.\\
\hline
\mbox{\tt in}  & {\em h\+\_\+in} & Layer thickness used to calculate fluxes \mbox{[}H $\sim$$>$ m or kg m-\/2\mbox{]}.\\
\hline
\mbox{\tt in}  & {\em h\+\_\+l} & Left thickness in the reconstruction \mbox{[}H $\sim$$>$ m or kg m-\/2\mbox{]}.\\
\hline
\mbox{\tt in}  & {\em h\+\_\+r} & Right thickness in the reconstruction \mbox{[}H $\sim$$>$ m or kg m-\/2\mbox{]}.\\
\hline
\mbox{\tt in}  & {\em visc\+\_\+rem} & Both the fraction of the momentum originally in a layer that remains after a time-\/step of viscosity, and the fraction of a time-\/step\textquotesingle{}s worth of a barotropic acceleration that a layer experiences after viscosity is applied. Non-\/dimensional between 0 (at the bottom) and 1 (far above the bottom).\\
\hline
\mbox{\tt in}  & {\em vhbt} & The summed volume flux through meridional faces\\
\hline
\mbox{\tt in}  & {\em dv\+\_\+max\+\_\+cfl} & Maximum acceptable value of dv \mbox{[}L T-\/1 $\sim$$>$ m s-\/1\mbox{]}.\\
\hline
\mbox{\tt in}  & {\em dv\+\_\+min\+\_\+cfl} & Minimum acceptable value of dv \mbox{[}L T-\/1 $\sim$$>$ m s-\/1\mbox{]}.\\
\hline
\mbox{\tt in}  & {\em vh\+\_\+tot\+\_\+0} & The summed transport with 0 adjustment \mbox{[}H L2 T-\/1 $\sim$$>$ m3 s-\/1 or kg s-\/1\mbox{]}.\\
\hline
\mbox{\tt in}  & {\em dvhdv\+\_\+tot\+\_\+0} & The partial derivative of dv\+\_\+err with dv at 0 adjustment \mbox{[}H L $\sim$$>$ m2 or kg m-\/1\mbox{]}.\\
\hline
\mbox{\tt out}  & {\em dv} & The barotropic velocity adjustment \mbox{[}L T-\/1 $\sim$$>$ m s-\/1\mbox{]}.\\
\hline
\mbox{\tt in}  & {\em dt} & Time increment \mbox{[}T $\sim$$>$ s\mbox{]}.\\
\hline
\mbox{\tt in}  & {\em us} & A dimensional unit scaling type\\
\hline
 & {\em cs} & This module\textquotesingle{}s control structure.\\
\hline
\mbox{\tt in}  & {\em j} & Spatial index.\\
\hline
\mbox{\tt in}  & {\em ish} & Start of index range.\\
\hline
\mbox{\tt in}  & {\em ieh} & End of index range.\\
\hline
\mbox{\tt in}  & {\em do\+\_\+i\+\_\+in} & A flag indicating which I values to work on.\\
\hline
\mbox{\tt in}  & {\em full\+\_\+precision} & A flag indicating how carefully to iterate. The default is .true. (more accurate).\\
\hline
\mbox{\tt in,out}  & {\em vh\+\_\+3d} & Volume flux through meridional\\
\hline
 & {\em obc} & Open boundaries control structure. \\
\hline
\end{DoxyParams}


Definition at line 1537 of file M\+O\+M\+\_\+continuity\+\_\+\+P\+P\+M.\+F90.


\begin{DoxyCode}
1537   \textcolor{keywordtype}{type}(ocean\_grid\_type),  \textcolor{keywordtype}{intent(inout)} :: G\textcolor{comment}{   !< Ocean's grid structure.}
1538   \textcolor{keywordtype}{real}, \textcolor{keywordtype}{dimension(SZI\_(G),SZJB\_(G),SZK\_(G))}, &
1539                          \textcolor{keywordtype}{intent(in)}    :: v\textcolor{comment}{    !< Meridional velocity [L T-1 ~> m s-1].}
1540   \textcolor{keywordtype}{real}, \textcolor{keywordtype}{dimension(SZI\_(G),SZJ\_(G),SZK\_(G))}, &
1541                          \textcolor{keywordtype}{intent(in)}    :: h\_in\textcolor{comment}{ !< Layer thickness used to calculate fluxes [H ~> m or kg
       m-2].}
1542   \textcolor{keywordtype}{real}, \textcolor{keywordtype}{dimension(SZI\_(G),SZJ\_(G),SZK\_(G))},&
1543                          \textcolor{keywordtype}{intent(in)}    :: h\_L\textcolor{comment}{  !< Left thickness in the reconstruction [H ~> m or kg m-2].}
1544   \textcolor{keywordtype}{real}, \textcolor{keywordtype}{dimension(SZI\_(G),SZJ\_(G),SZK\_(G))}, &
1545                          \textcolor{keywordtype}{intent(in)}    :: h\_R\textcolor{comment}{  !< Right thickness in the reconstruction [H ~> m or kg m-2].}
1546   \textcolor{keywordtype}{real}, \textcolor{keywordtype}{dimension(SZI\_(G),SZK\_(G))}, \textcolor{keywordtype}{intent(in)} :: visc\_rem
1547                              \textcolor{comment}{!< Both the fraction of the momentum originally}
1548 \textcolor{comment}{                             !! in a layer that remains after a time-step of viscosity, and the}
1549 \textcolor{comment}{                             !! fraction of a time-step's worth of a barotropic acceleration that}
1550 \textcolor{comment}{                             !! a layer experiences after viscosity is applied. Non-dimensional}
1551 \textcolor{comment}{                             !! between 0 (at the bottom) and 1 (far above the bottom).}
1552   \textcolor{keywordtype}{real}, \textcolor{keywordtype}{dimension(SZI\_(G))}, &
1553                   \textcolor{keywordtype}{optional}, \textcolor{keywordtype}{intent(in)}    :: vhbt\textcolor{comment}{ !< The summed volume flux through meridional faces}
1554 \textcolor{comment}{                                                  !! [H L2 T-1 ~> m3 s-1 or kg s-1].}
1555   \textcolor{keywordtype}{real}, \textcolor{keywordtype}{dimension(SZI\_(G))}, \textcolor{keywordtype}{intent(in)}    :: dv\_max\_CFL\textcolor{comment}{ !< Maximum acceptable value of dv [L T-1 ~> m s-1].}
1556   \textcolor{keywordtype}{real}, \textcolor{keywordtype}{dimension(SZI\_(G))}, \textcolor{keywordtype}{intent(in)}    :: dv\_min\_CFL\textcolor{comment}{ !< Minimum acceptable value of dv [L T-1 ~> m s-1].}
1557   \textcolor{keywordtype}{real}, \textcolor{keywordtype}{dimension(SZI\_(G))}, \textcolor{keywordtype}{intent(in)}    :: vh\_tot\_0\textcolor{comment}{   !< The summed transport with 0 adjustment}
1558 \textcolor{comment}{                                                        !! [H L2 T-1 ~> m3 s-1 or kg s-1].}
1559   \textcolor{keywordtype}{real}, \textcolor{keywordtype}{dimension(SZI\_(G))}, \textcolor{keywordtype}{intent(in)}    :: dvhdv\_tot\_0\textcolor{comment}{ !< The partial derivative of dv\_err with}
1560 \textcolor{comment}{                                                         !! dv at 0 adjustment [H L ~> m2 or kg m-1].}
1561   \textcolor{keywordtype}{real}, \textcolor{keywordtype}{dimension(SZI\_(G))}, \textcolor{keywordtype}{intent(out)}   :: dv\textcolor{comment}{   !< The barotropic velocity adjustment [L T-1 ~> m s-1].}
1562   \textcolor{keywordtype}{real},                     \textcolor{keywordtype}{intent(in)}    :: dt\textcolor{comment}{   !< Time increment [T ~> s].}
1563   \textcolor{keywordtype}{type}(unit\_scale\_type),    \textcolor{keywordtype}{intent(in)}    :: US\textcolor{comment}{   !< A dimensional unit scaling type}
1564   \textcolor{keywordtype}{type}(continuity\_PPM\_CS),  \textcolor{keywordtype}{pointer}       :: CS\textcolor{comment}{   !< This module's control structure.}
1565   \textcolor{keywordtype}{integer},                  \textcolor{keywordtype}{intent(in)}    :: j\textcolor{comment}{    !< Spatial index.}
1566   \textcolor{keywordtype}{integer},                  \textcolor{keywordtype}{intent(in)}    :: ish\textcolor{comment}{  !< Start of index range.}
1567   \textcolor{keywordtype}{integer},                  \textcolor{keywordtype}{intent(in)}    :: ieh\textcolor{comment}{  !< End of index range.}
1568   \textcolor{keywordtype}{logical}, \textcolor{keywordtype}{dimension(SZI\_(G))}, &
1569                             \textcolor{keywordtype}{intent(in)}    :: do\_I\_in\textcolor{comment}{  !< A flag indicating which I values to work on.}
1570   \textcolor{keywordtype}{logical},        \textcolor{keywordtype}{optional}, \textcolor{keywordtype}{intent(in)}    :: full\_precision\textcolor{comment}{ !< A flag indicating how carefully to}
1571 \textcolor{comment}{                             !! iterate.  The default is .true. (more accurate).}
1572   \textcolor{keywordtype}{real}, \textcolor{keywordtype}{dimension(SZI\_(G),SZJB\_(G),SZK\_(G))}, &
1573                   \textcolor{keywordtype}{optional}, \textcolor{keywordtype}{intent(inout)} :: vh\_3d\textcolor{comment}{ !< Volume flux through meridional}
1574 \textcolor{comment}{                             !! faces = v*h*dx [H L2 T-1 ~> m3 s-1 or kg s-1].}
1575   \textcolor{keywordtype}{type}(ocean\_OBC\_type), \textcolor{keywordtype}{optional}, \textcolor{keywordtype}{pointer} :: OBC\textcolor{comment}{ !< Open boundaries control structure.}
1576   \textcolor{comment}{! Local variables}
1577   \textcolor{keywordtype}{real}, \textcolor{keywordtype}{dimension(SZI\_(G),SZK\_(G))} :: &
1578     vh\_aux, &  \textcolor{comment}{! An auxiliary meridional volume flux [H L2 s-1 ~> m3 s-1 or kg s-1].}
1579     dvhdv      \textcolor{comment}{! Partial derivative of vh with v [H m ~> m2 or kg m-1].}
1580   \textcolor{keywordtype}{real}, \textcolor{keywordtype}{dimension(SZI\_(G))} :: &
1581     vh\_err, &  \textcolor{comment}{! Difference between vhbt and the summed vh [H L2 T-1 ~> m3 s-1 or kg s-1].}
1582     vh\_err\_best, & \textcolor{comment}{! The smallest value of vh\_err found so far [H L2 T-1 ~> m3 s-1 or kg s-1].}
1583     v\_new, &   \textcolor{comment}{! The velocity with the correction added [L T-1 ~> m s-1].}
1584     dvhdv\_tot,&\textcolor{comment}{! Summed partial derivative of vh with u [H L ~> m2 or kg m-1].}
1585     dv\_min, &  \textcolor{comment}{! Min/max limits on dv correction based on CFL limits}
1586     dv\_max     \textcolor{comment}{! and previous iterations [L T-1 ~> m s-1].}
1587   \textcolor{keywordtype}{real} :: dv\_prev \textcolor{comment}{! The previous value of dv [L T-1 ~> m s-1].}
1588   \textcolor{keywordtype}{real} :: ddv    \textcolor{comment}{! The change in dv from the previous iteration [L T-1 ~> m s-1].}
1589   \textcolor{keywordtype}{real} :: tol\_eta \textcolor{comment}{! The tolerance for the current iteration [H ~> m or kg m-2].}
1590   \textcolor{keywordtype}{real} :: tol\_vel \textcolor{comment}{! The tolerance for velocity in the current iteration [L T-1 ~> m s-1].}
1591   \textcolor{keywordtype}{integer} :: i, k, nz, itt, max\_itts = 20
1592   \textcolor{keywordtype}{logical} :: full\_prec, domore, do\_I(SZI\_(G))
1593 
1594   nz = g%ke
1595   full\_prec = .true. ; \textcolor{keywordflow}{if} (\textcolor{keyword}{present}(full\_precision)) full\_prec = full\_precision
1596 
1597   vh\_aux(:,:) = 0.0 ; dvhdv(:,:) = 0.0
1598 
1599   \textcolor{keywordflow}{if} (\textcolor{keyword}{present}(vh\_3d)) \textcolor{keywordflow}{then} ; \textcolor{keywordflow}{do} k=1,nz ; \textcolor{keywordflow}{do} i=ish,ieh
1600     vh\_aux(i,k) = vh\_3d(i,j,k)
1601 \textcolor{keywordflow}{  enddo} ;\textcolor{keywordflow}{ enddo} ;\textcolor{keywordflow}{ endif}
1602 
1603   \textcolor{keywordflow}{do} i=ish,ieh
1604     dv(i) = 0.0 ; do\_i(i) = do\_i\_in(i)
1605     dv\_max(i) = dv\_max\_cfl(i) ; dv\_min(i) = dv\_min\_cfl(i)
1606     vh\_err(i) = vh\_tot\_0(i) - vhbt(i) ; dvhdv\_tot(i) = dvhdv\_tot\_0(i)
1607     vh\_err\_best(i) = abs(vh\_err(i))
1608 \textcolor{keywordflow}{  enddo}
1609 
1610   \textcolor{keywordflow}{do} itt=1,max\_itts
1611     \textcolor{keywordflow}{if} (full\_prec) \textcolor{keywordflow}{then}
1612       \textcolor{keywordflow}{select case} (itt)
1613         \textcolor{keywordflow}{case} (:1) ; tol\_eta = 1e-6 * cs%tol\_eta
1614         \textcolor{keywordflow}{case} (2)  ; tol\_eta = 1e-4 * cs%tol\_eta
1615         \textcolor{keywordflow}{case} (3)  ; tol\_eta = 1e-2 * cs%tol\_eta
1616 \textcolor{keywordflow}{        case default} ; tol\_eta = cs%tol\_eta
1617 \textcolor{keywordflow}{      end select}
1618     \textcolor{keywordflow}{else}
1619       tol\_eta = cs%tol\_eta\_aux ; \textcolor{keywordflow}{if} (itt<=1) tol\_eta = 1e-6 * cs%tol\_eta\_aux
1620 \textcolor{keywordflow}{    endif}
1621     tol\_vel = cs%tol\_vel
1622 
1623     \textcolor{keywordflow}{do} i=ish,ieh
1624       \textcolor{keywordflow}{if} (vh\_err(i) > 0.0) \textcolor{keywordflow}{then} ; dv\_max(i) = dv(i)
1625       \textcolor{keywordflow}{elseif} (vh\_err(i) < 0.0) \textcolor{keywordflow}{then} ; dv\_min(i) = dv(i)
1626       \textcolor{keywordflow}{else} ; do\_i(i) = .false. ;\textcolor{keywordflow}{ endif}
1627 \textcolor{keywordflow}{    enddo}
1628     domore = .false.
1629     \textcolor{keywordflow}{do} i=ish,ieh ; \textcolor{keywordflow}{if} (do\_i(i)) \textcolor{keywordflow}{then}
1630       \textcolor{keywordflow}{if} ((dt * min(g%IareaT(i,j),g%IareaT(i,j+1))*abs(vh\_err(i)) > tol\_eta) .or. &
1631           (cs%better\_iter .and. ((abs(vh\_err(i)) > tol\_vel * dvhdv\_tot(i)) .or. &
1632                                  (abs(vh\_err(i)) > vh\_err\_best(i))) )) \textcolor{keywordflow}{then}
1633         \textcolor{comment}{!   Use Newton's method, provided it stays bounded.  Otherwise bisect}
1634         \textcolor{comment}{! the value with the appropriate bound.}
1635         \textcolor{keywordflow}{if} (full\_prec) \textcolor{keywordflow}{then}
1636           ddv = -vh\_err(i) / dvhdv\_tot(i)
1637           dv\_prev = dv(i)
1638           dv(i) = dv(i) + ddv
1639           \textcolor{keywordflow}{if} (abs(ddv) < 1.0e-15*abs(dv(i))) \textcolor{keywordflow}{then}
1640             do\_i(i) = .false. \textcolor{comment}{! ddv is small enough to quit.}
1641           \textcolor{keywordflow}{elseif} (ddv > 0.0) \textcolor{keywordflow}{then}
1642             \textcolor{keywordflow}{if} (dv(i) >= dv\_max(i)) \textcolor{keywordflow}{then}
1643               dv(i) = 0.5*(dv\_prev + dv\_max(i))
1644               \textcolor{keywordflow}{if} (dv\_max(i) - dv\_prev < 1.0e-15*abs(dv(i))) do\_i(i) = .false.
1645 \textcolor{keywordflow}{            endif}
1646           \textcolor{keywordflow}{else} \textcolor{comment}{! dvv(i) < 0.0}
1647             \textcolor{keywordflow}{if} (dv(i) <= dv\_min(i)) \textcolor{keywordflow}{then}
1648               dv(i) = 0.5*(dv\_prev + dv\_min(i))
1649               \textcolor{keywordflow}{if} (dv\_prev - dv\_min(i) < 1.0e-15*abs(dv(i))) do\_i(i) = .false.
1650 \textcolor{keywordflow}{            endif}
1651 \textcolor{keywordflow}{          endif}
1652         \textcolor{keywordflow}{else}
1653           \textcolor{comment}{!   Use Newton's method, provided it stays bounded, just like above.}
1654           dv(i) = dv(i) - vh\_err(i) / dvhdv\_tot(i)
1655           \textcolor{keywordflow}{if} ((dv(i) >= dv\_max(i)) .or. (dv(i) <= dv\_min(i))) &
1656             dv(i) = 0.5*(dv\_max(i) + dv\_min(i))
1657 \textcolor{keywordflow}{        endif}
1658         \textcolor{keywordflow}{if} (do\_i(i)) domore = .true.
1659       \textcolor{keywordflow}{else}
1660         do\_i(i) = .false.
1661 \textcolor{keywordflow}{      endif}
1662 \textcolor{keywordflow}{    endif} ;\textcolor{keywordflow}{ enddo}
1663     \textcolor{keywordflow}{if} (.not.domore) \textcolor{keywordflow}{exit}
1664 
1665     \textcolor{keywordflow}{if} ((itt < max\_itts) .or. \textcolor{keyword}{present}(vh\_3d)) \textcolor{keywordflow}{then} ; \textcolor{keywordflow}{do} k=1,nz
1666       \textcolor{keywordflow}{do} i=ish,ieh ; v\_new(i) = v(i,j,k) + dv(i) * visc\_rem(i,k) ;\textcolor{keywordflow}{ enddo}
1667       \textcolor{keyword}{call }merid\_flux\_layer(v\_new, h\_in(:,:,k), h\_l(:,:,k), h\_r(:,:,k), &
1668                             vh\_aux(:,k), dvhdv(:,k), visc\_rem(:,k), &
1669                             dt, g, us, j, ish, ieh, do\_i, cs%vol\_CFL, obc)
1670 \textcolor{keywordflow}{    enddo} ;\textcolor{keywordflow}{ endif}
1671 
1672     \textcolor{keywordflow}{if} (itt < max\_itts) \textcolor{keywordflow}{then}
1673       \textcolor{keywordflow}{do} i=ish,ieh
1674         vh\_err(i) = -vhbt(i) ; dvhdv\_tot(i) = 0.0
1675 \textcolor{keywordflow}{      enddo}
1676       \textcolor{keywordflow}{do} k=1,nz ; \textcolor{keywordflow}{do} i=ish,ieh
1677         vh\_err(i) = vh\_err(i) + vh\_aux(i,k)
1678         dvhdv\_tot(i) = dvhdv\_tot(i) + dvhdv(i,k)
1679 \textcolor{keywordflow}{      enddo} ;\textcolor{keywordflow}{ enddo}
1680       \textcolor{keywordflow}{do} i=ish,ieh
1681         vh\_err\_best(i) = min(vh\_err\_best(i), abs(vh\_err(i)))
1682 \textcolor{keywordflow}{      enddo}
1683 \textcolor{keywordflow}{    endif}
1684 \textcolor{keywordflow}{  enddo} \textcolor{comment}{! itt-loop}
1685   \textcolor{comment}{! If there are any faces which have not converged to within the tolerance,}
1686   \textcolor{comment}{! so-be-it, or else use a final upwind correction?}
1687   \textcolor{comment}{! This never seems to happen with 20 iterations as max\_itt.}
1688 
1689   \textcolor{keywordflow}{if} (\textcolor{keyword}{present}(vh\_3d)) \textcolor{keywordflow}{then} ; \textcolor{keywordflow}{do} k=1,nz ; \textcolor{keywordflow}{do} i=ish,ieh
1690     vh\_3d(i,j,k) = vh\_aux(i,k)
1691 \textcolor{keywordflow}{  enddo} ;\textcolor{keywordflow}{ enddo} ;\textcolor{keywordflow}{ endif}
1692 
\end{DoxyCode}
\mbox{\Hypertarget{namespacemom__continuity__ppm_ae64c4b7cd1756aa3c121fbcf637d5cae}\label{namespacemom__continuity__ppm_ae64c4b7cd1756aa3c121fbcf637d5cae}} 
\index{mom\+\_\+continuity\+\_\+ppm@{mom\+\_\+continuity\+\_\+ppm}!meridional\+\_\+mass\+\_\+flux@{meridional\+\_\+mass\+\_\+flux}}
\index{meridional\+\_\+mass\+\_\+flux@{meridional\+\_\+mass\+\_\+flux}!mom\+\_\+continuity\+\_\+ppm@{mom\+\_\+continuity\+\_\+ppm}}
\subsubsection{\texorpdfstring{meridional\+\_\+mass\+\_\+flux()}{meridional\_mass\_flux()}}
{\footnotesize\ttfamily subroutine mom\+\_\+continuity\+\_\+ppm\+::meridional\+\_\+mass\+\_\+flux (\begin{DoxyParamCaption}\item[{real, dimension(szi\+\_\+(g),szjb\+\_\+(g),szk\+\_\+(g)), intent(in)}]{v,  }\item[{real, dimension(szi\+\_\+(g),szj\+\_\+(g),szk\+\_\+(g)), intent(in)}]{h\+\_\+in,  }\item[{real, dimension(szi\+\_\+(g),szjb\+\_\+(g),szk\+\_\+(g)), intent(out)}]{vh,  }\item[{real, intent(in)}]{dt,  }\item[{type(ocean\+\_\+grid\+\_\+type), intent(inout)}]{G,  }\item[{type(verticalgrid\+\_\+type), intent(in)}]{GV,  }\item[{type(unit\+\_\+scale\+\_\+type), intent(in)}]{US,  }\item[{type(\mbox{\hyperlink{structmom__continuity__ppm_1_1continuity__ppm__cs}{continuity\+\_\+ppm\+\_\+cs}}), pointer}]{CS,  }\item[{type(\mbox{\hyperlink{structmom__continuity__ppm_1_1loop__bounds__type}{loop\+\_\+bounds\+\_\+type}}), intent(in)}]{LB,  }\item[{real, dimension(szi\+\_\+(g),szjb\+\_\+(g)), intent(in), optional}]{vhbt,  }\item[{type(ocean\+\_\+obc\+\_\+type), optional, pointer}]{O\+BC,  }\item[{real, dimension( g \%isd\+: g \%ied, g \%jsdb\+: g \%jedb, g \%ke), intent(in), optional}]{visc\+\_\+rem\+\_\+v,  }\item[{real, dimension(szi\+\_\+(g),szjb\+\_\+(g),szk\+\_\+(g)), intent(out), optional}]{v\+\_\+cor,  }\item[{type(bt\+\_\+cont\+\_\+type), optional, pointer}]{B\+T\+\_\+cont }\end{DoxyParamCaption})\hspace{0.3cm}{\ttfamily [private]}}



Calculates the mass or volume fluxes through the meridional faces, and other related quantities. 


\begin{DoxyParams}[1]{Parameters}
\mbox{\tt in,out}  & {\em g} & Ocean\textquotesingle{}s grid structure.\\
\hline
\mbox{\tt in}  & {\em gv} & Ocean\textquotesingle{}s vertical grid structure.\\
\hline
\mbox{\tt in}  & {\em v} & Meridional velocity \mbox{[}L T-\/1 $\sim$$>$ m s-\/1\mbox{]}.\\
\hline
\mbox{\tt in}  & {\em h\+\_\+in} & Layer thickness used to calculate fluxes \mbox{[}H $\sim$$>$ m or kg m-\/2\mbox{]}.\\
\hline
\mbox{\tt out}  & {\em vh} & Volume flux through meridional faces = v$\ast$h$\ast$dx \mbox{[}H m2 s-\/1 $\sim$$>$ m3 s-\/1 or kg s-\/1\mbox{]}.\\
\hline
\mbox{\tt in}  & {\em dt} & Time increment \mbox{[}T $\sim$$>$ s\mbox{]}.\\
\hline
\mbox{\tt in}  & {\em us} & A dimensional unit scaling type\\
\hline
 & {\em cs} & This module\textquotesingle{}s control structure.\+G\\
\hline
\mbox{\tt in}  & {\em lb} & Loop bounds structure.\\
\hline
 & {\em obc} & Open boundary condition type specifies whether, where, and what open boundary conditions are used.\\
\hline
\mbox{\tt in}  & {\em visc\+\_\+rem\+\_\+v} & Both the fraction of the momentum\\
\hline
\mbox{\tt in}  & {\em vhbt} & The summed volume flux through meridional faces \mbox{[}H L2 T-\/1 $\sim$$>$ m3 s-\/1 or kg s-\/1\mbox{]}.\\
\hline
\mbox{\tt out}  & {\em v\+\_\+cor} & The meridional velocitiess (v with a barotropic correction) that give vhbt as the depth-\/integrated transport \mbox{[}L T-\/1 $\sim$$>$ m s-\/1\mbox{]}.\\
\hline
 & {\em bt\+\_\+cont} & A structure with elements that describe the effective open face areas as a function of barotropic flow. \\
\hline
\end{DoxyParams}


Definition at line 1039 of file M\+O\+M\+\_\+continuity\+\_\+\+P\+P\+M.\+F90.


\begin{DoxyCode}
1039   \textcolor{keywordtype}{type}(ocean\_grid\_type),                     \textcolor{keywordtype}{intent(inout)} :: G\textcolor{comment}{    !< Ocean's grid structure.}
1040   \textcolor{keywordtype}{type}(verticalGrid\_type),                   \textcolor{keywordtype}{intent(in)}    :: GV\textcolor{comment}{   !< Ocean's vertical grid structure.}
1041   \textcolor{keywordtype}{real}, \textcolor{keywordtype}{dimension(SZI\_(G),SZJB\_(G),SZK\_(G))}, \textcolor{keywordtype}{intent(in)}    :: v\textcolor{comment}{    !< Meridional velocity [L T-1 ~> m s-1].}
1042   \textcolor{keywordtype}{real},  \textcolor{keywordtype}{dimension(SZI\_(G),SZJ\_(G),SZK\_(G))}, \textcolor{keywordtype}{intent(in)}    :: h\_in\textcolor{comment}{ !< Layer thickness used to}
1043 \textcolor{comment}{                                                                   !! calculate fluxes [H ~> m or kg m-2].}
1044   \textcolor{keywordtype}{real}, \textcolor{keywordtype}{dimension(SZI\_(G),SZJB\_(G),SZK\_(G))}, \textcolor{keywordtype}{intent(out)}   :: vh\textcolor{comment}{   !< Volume flux through meridional}
1045 \textcolor{comment}{                                                                   !! faces = v*h*dx [H m2 s-1 ~> m3 s-1 or
       kg s-1].}
1046   \textcolor{keywordtype}{real},                                      \textcolor{keywordtype}{intent(in)}    :: dt\textcolor{comment}{   !< Time increment [T ~> s].}
1047   \textcolor{keywordtype}{type}(unit\_scale\_type),                     \textcolor{keywordtype}{intent(in)}    :: US\textcolor{comment}{   !< A dimensional unit scaling type}
1048   \textcolor{keywordtype}{type}(continuity\_PPM\_CS),                   \textcolor{keywordtype}{pointer}       :: CS\textcolor{comment}{   !< This module's control structure.G}
1049   \textcolor{keywordtype}{type}(loop\_bounds\_type),                    \textcolor{keywordtype}{intent(in)}    :: LB\textcolor{comment}{   !< Loop bounds structure.}
1050   \textcolor{keywordtype}{type}(ocean\_OBC\_type),            \textcolor{keywordtype}{optional}, \textcolor{keywordtype}{pointer}       :: OBC\textcolor{comment}{  !< Open boundary condition type}
1051 \textcolor{comment}{                                   !! specifies whether, where, and what open boundary conditions are used.}
1052   \textcolor{keywordtype}{real}, \textcolor{keywordtype}{dimension(SZI\_(G),SZJB\_(G),SZK\_(G))}, &
1053                                    \textcolor{keywordtype}{optional}, \textcolor{keywordtype}{intent(in)}    :: visc\_rem\_v\textcolor{comment}{ !< Both the fraction of the
       momentum}
1054 \textcolor{comment}{                                   !! originally in a layer that remains after a time-step of viscosity,}
1055 \textcolor{comment}{                                   !! and the fraction of a time-step's worth of a barotropic acceleration}
1056 \textcolor{comment}{                                   !! that a layer experiences after viscosity is applied.  Nondimensional
       between}
1057 \textcolor{comment}{                                   !! 0 (at the bottom) and 1 (far above the bottom).}
1058   \textcolor{keywordtype}{real}, \textcolor{keywordtype}{dimension(SZI\_(G),SZJB\_(G))}, \textcolor{keywordtype}{optional}, \textcolor{keywordtype}{intent(in)}  :: vhbt\textcolor{comment}{  !< The summed volume flux through}
1059 \textcolor{comment}{                                   !< meridional faces [H L2 T-1 ~> m3 s-1 or kg s-1].}
1060   \textcolor{keywordtype}{real}, \textcolor{keywordtype}{dimension(SZI\_(G),SZJB\_(G),SZK\_(G))}, &
1061                                      \textcolor{keywordtype}{optional}, \textcolor{keywordtype}{intent(out)} :: v\_cor
1062                                    \textcolor{comment}{!< The meridional velocitiess (v with a barotropic correction)}
1063 \textcolor{comment}{                                   !! that give vhbt as the depth-integrated transport [L T-1 ~> m s-1].}
1064   \textcolor{keywordtype}{type}(BT\_cont\_type),              \textcolor{keywordtype}{optional}, \textcolor{keywordtype}{pointer}       :: BT\_cont\textcolor{comment}{ !< A structure with elements that
       describe}
1065 \textcolor{comment}{                                   !! the effective open face areas as a function of barotropic flow.}
1066   \textcolor{comment}{! Local variables}
1067   \textcolor{keywordtype}{real}, \textcolor{keywordtype}{dimension(SZI\_(G),SZK\_(G))} :: &
1068     dvhdv      \textcolor{comment}{! Partial derivative of vh with v [H L ~> m2 or kg m-1].}
1069   \textcolor{keywordtype}{real}, \textcolor{keywordtype}{dimension(SZI\_(G),SZJ\_(G),SZK\_(G))} :: &
1070     h\_L, h\_R   \textcolor{comment}{! Left and right face thicknesses [H ~> m or kg m-2].}
1071   \textcolor{keywordtype}{real}, \textcolor{keywordtype}{dimension(SZI\_(G))} :: &
1072     dv, &      \textcolor{comment}{! Corrective barotropic change in the velocity [L T-1 ~> m s-1].}
1073     dv\_min\_CFL, & \textcolor{comment}{! Min/max limits on dv correction}
1074     dv\_max\_CFL, & \textcolor{comment}{! to avoid CFL violations}
1075     dvhdv\_tot\_0, & \textcolor{comment}{! Summed partial derivative of vh with v [H L ~> m2 or kg m-1].}
1076     vh\_tot\_0, &   \textcolor{comment}{! Summed transport with no barotropic correction [H L2 T-1 ~> m3 s-1 or kg s-1].}
1077     visc\_rem\_max  \textcolor{comment}{! The column maximum of visc\_rem.}
1078   \textcolor{keywordtype}{logical}, \textcolor{keywordtype}{dimension(SZI\_(G))} :: do\_I
1079   \textcolor{keywordtype}{real}, \textcolor{keywordtype}{dimension(SZI\_(G))} :: FAvi  \textcolor{comment}{! A list of sums of meridional face areas [H L ~> m2 or kg m-1].}
1080   \textcolor{keywordtype}{real} :: FA\_v    \textcolor{comment}{! A sum of meridional face areas [H m ~> m2 or kg m-1].}
1081   \textcolor{keywordtype}{real}, \textcolor{keywordtype}{dimension(SZI\_(G),SZK\_(G))} :: &
1082     visc\_rem      \textcolor{comment}{! A 2-D copy of visc\_rem\_v or an array of 1's.}
1083   \textcolor{keywordtype}{real} :: I\_vrm   \textcolor{comment}{! 1.0 / visc\_rem\_max, nondim.}
1084   \textcolor{keywordtype}{real} :: CFL\_dt  \textcolor{comment}{! The maximum CFL ratio of the adjusted velocities divided by}
1085                   \textcolor{comment}{! the time step [T-1 ~> s-1].}
1086   \textcolor{keywordtype}{real} :: I\_dt    \textcolor{comment}{! 1.0 / dt [T-1 ~> s-1].}
1087   \textcolor{keywordtype}{real} :: dv\_lim  \textcolor{comment}{! The velocity change that give a relative CFL of 1 [L T-1 ~> m s-1].}
1088   \textcolor{keywordtype}{real} :: dy\_N, dy\_S \textcolor{comment}{! Effective y-grid spacings to the north and south [L ~> m].}
1089   \textcolor{keywordtype}{integer} :: i, j, k, ish, ieh, jsh, jeh, n, nz
1090   \textcolor{keywordtype}{integer} :: l\_seg
1091   \textcolor{keywordtype}{logical} :: local\_specified\_BC, use\_visc\_rem, set\_BT\_cont, any\_simple\_OBC
1092   \textcolor{keywordtype}{logical} :: local\_Flather\_OBC, is\_simple, local\_open\_BC
1093   \textcolor{keywordtype}{type}(OBC\_segment\_type), \textcolor{keywordtype}{pointer} :: segment => null()
1094 
1095   use\_visc\_rem = \textcolor{keyword}{present}(visc\_rem\_v)
1096   local\_specified\_bc = .false. ; set\_bt\_cont = .false. ; local\_flather\_obc = .false.
1097   local\_open\_bc = .false.
1098   \textcolor{keywordflow}{if} (\textcolor{keyword}{present}(bt\_cont)) set\_bt\_cont = (\textcolor{keyword}{associated}(bt\_cont))
1099   \textcolor{keywordflow}{if} (\textcolor{keyword}{present}(obc)) \textcolor{keywordflow}{then} ; \textcolor{keywordflow}{if} (\textcolor{keyword}{associated}(obc)) \textcolor{keywordflow}{then} ; \textcolor{keywordflow}{if} (obc%OBC\_pe) \textcolor{keywordflow}{then}
1100     local\_specified\_bc = obc%specified\_v\_BCs\_exist\_globally
1101     local\_flather\_obc = obc%Flather\_v\_BCs\_exist\_globally
1102     local\_open\_bc = obc%open\_v\_BCs\_exist\_globally
1103 \textcolor{keywordflow}{  endif} ;\textcolor{keywordflow}{ endif} ;\textcolor{keywordflow}{ endif}
1104   ish = lb%ish ; ieh = lb%ieh ; jsh = lb%jsh ; jeh = lb%jeh ; nz = g%ke
1105 
1106   cfl\_dt = cs%CFL\_limit\_adjust / dt
1107   i\_dt = 1.0 / dt
1108   \textcolor{keywordflow}{if} (cs%aggress\_adjust) cfl\_dt = i\_dt
1109 
1110   \textcolor{keyword}{call }cpu\_clock\_begin(id\_clock\_update)
1111 \textcolor{comment}{!$OMP parallel do default(none) shared(nz,ish,ieh,jsh,jeh,h\_in,h\_L,h\_R,G,GV,LB,CS,visc\_rem,OBC)}
1112   \textcolor{keywordflow}{do} k=1,nz
1113     \textcolor{comment}{! This sets h\_L and h\_R.}
1114     \textcolor{keywordflow}{if} (cs%upwind\_1st) \textcolor{keywordflow}{then}
1115       \textcolor{keywordflow}{do} j=jsh-1,jeh+1 ; \textcolor{keywordflow}{do} i=ish,ieh
1116         h\_l(i,j,k) = h\_in(i,j,k) ; h\_r(i,j,k) = h\_in(i,j,k)
1117 \textcolor{keywordflow}{      enddo} ;\textcolor{keywordflow}{ enddo}
1118     \textcolor{keywordflow}{else}
1119       \textcolor{keyword}{call }ppm\_reconstruction\_y(h\_in(:,:,k), h\_l(:,:,k), h\_r(:,:,k), g, lb, &
1120                                 2.0*gv%Angstrom\_H, cs%monotonic, simple\_2nd=cs%simple\_2nd, obc=obc)
1121 \textcolor{keywordflow}{    endif}
1122     \textcolor{keywordflow}{do} i=ish,ieh ; visc\_rem(i,k) = 1.0 ;\textcolor{keywordflow}{ enddo}
1123 \textcolor{keywordflow}{  enddo}
1124   \textcolor{keyword}{call }cpu\_clock\_end(id\_clock\_update)
1125 
1126   \textcolor{keyword}{call }cpu\_clock\_begin(id\_clock\_correct)
1127 \textcolor{comment}{!$OMP parallel do default(none) shared(ish,ieh,jsh,jeh,nz,v,h\_in,h\_L,h\_R,vh,use\_visc\_rem, &}
1128 \textcolor{comment}{!$OMP                                  visc\_rem\_v,dt,US,G,GV,CS,local\_specified\_BC,OBC,vhbt, &}
1129 \textcolor{comment}{!$OMP                                  set\_BT\_cont,CFL\_dt,I\_dt,v\_cor,BT\_cont, local\_Flather\_OBC ) &}
1130 \textcolor{comment}{!$OMP                          private(do\_I,dvhdv,dv,dv\_max\_CFL,dv\_min\_CFL,vh\_tot\_0,    &}
1131 \textcolor{comment}{!$OMP                                  dvhdv\_tot\_0,visc\_rem\_max,I\_vrm,dv\_lim,dy\_N,      &}
1132 \textcolor{comment}{!$OMP                                  is\_simple,FAvi,dy\_S,any\_simple\_OBC,l\_seg) &}
1133 \textcolor{comment}{!$OMP                     firstprivate(visc\_rem)}
1134   \textcolor{keywordflow}{do} j=jsh-1,jeh
1135     \textcolor{keywordflow}{do} i=ish,ieh ; do\_i(i) = .true. ; visc\_rem\_max(i) = 0.0 ;\textcolor{keywordflow}{ enddo}
1136     \textcolor{comment}{! This sets vh and dvhdv.}
1137     \textcolor{keywordflow}{do} k=1,nz
1138       \textcolor{keywordflow}{if} (use\_visc\_rem) \textcolor{keywordflow}{then} ; \textcolor{keywordflow}{do} i=ish,ieh
1139         visc\_rem(i,k) = visc\_rem\_v(i,j,k)
1140         visc\_rem\_max(i) = max(visc\_rem\_max(i), visc\_rem(i,k))
1141 \textcolor{keywordflow}{      enddo} ;\textcolor{keywordflow}{ endif}
1142       \textcolor{keyword}{call }merid\_flux\_layer(v(:,j,k), h\_in(:,:,k), h\_l(:,:,k), h\_r(:,:,k), &
1143                             vh(:,j,k), dvhdv(:,k), visc\_rem(:,k), &
1144                             dt, g, us, j, ish, ieh, do\_i, cs%vol\_CFL, obc)
1145       \textcolor{keywordflow}{if} (local\_specified\_bc) \textcolor{keywordflow}{then}
1146         \textcolor{keywordflow}{do} i=ish,ieh
1147           l\_seg = obc%segnum\_v(i,j)
1148 
1149           \textcolor{keywordflow}{if} (l\_seg /= obc\_none) \textcolor{keywordflow}{then}
1150             \textcolor{keywordflow}{if} (obc%segment(l\_seg)%specified) &
1151               vh(i,j,k) = obc%segment(l\_seg)%normal\_trans(i,j,k)
1152 \textcolor{keywordflow}{          endif}
1153 \textcolor{keywordflow}{        enddo}
1154 \textcolor{keywordflow}{      endif}
1155 \textcolor{keywordflow}{    enddo} \textcolor{comment}{! k-loop}
1156     \textcolor{keywordflow}{if} ((.not.use\_visc\_rem) .or. (.not.cs%use\_visc\_rem\_max)) \textcolor{keywordflow}{then} ; \textcolor{keywordflow}{do} i=ish,ieh
1157       visc\_rem\_max(i) = 1.0
1158 \textcolor{keywordflow}{    enddo} ;\textcolor{keywordflow}{ endif}
1159 
1160     \textcolor{keywordflow}{if} (\textcolor{keyword}{present}(vhbt) .or. set\_bt\_cont) \textcolor{keywordflow}{then}
1161       \textcolor{comment}{!   Set limits on dv that will keep the CFL number between -1 and 1.}
1162       \textcolor{comment}{! This should be adequate to keep the root bracketed in all cases.}
1163       \textcolor{keywordflow}{do} i=ish,ieh
1164         i\_vrm = 0.0
1165         \textcolor{keywordflow}{if} (visc\_rem\_max(i) > 0.0) i\_vrm = 1.0 / visc\_rem\_max(i)
1166         \textcolor{keywordflow}{if} (cs%vol\_CFL) \textcolor{keywordflow}{then}
1167           dy\_s = ratio\_max(g%areaT(i,j), g%dx\_Cv(i,j), 1000.0*g%dyT(i,j))
1168           dy\_n = ratio\_max(g%areaT(i,j+1), g%dx\_Cv(i,j), 1000.0*g%dyT(i,j+1))
1169         \textcolor{keywordflow}{else} ; dy\_s = g%dyT(i,j) ; dy\_n = g%dyT(i,j+1) ;\textcolor{keywordflow}{ endif}
1170         dv\_max\_cfl(i) = 2.0 * (cfl\_dt * dy\_s) * i\_vrm
1171         dv\_min\_cfl(i) = -2.0 * (cfl\_dt * dy\_n) * i\_vrm
1172         vh\_tot\_0(i) = 0.0 ; dvhdv\_tot\_0(i) = 0.0
1173 \textcolor{keywordflow}{      enddo}
1174       \textcolor{keywordflow}{do} k=1,nz ; \textcolor{keywordflow}{do} i=ish,ieh
1175         dvhdv\_tot\_0(i) = dvhdv\_tot\_0(i) + dvhdv(i,k)
1176         vh\_tot\_0(i) = vh\_tot\_0(i) + vh(i,j,k)
1177 \textcolor{keywordflow}{      enddo} ;\textcolor{keywordflow}{ enddo}
1178 
1179       \textcolor{keywordflow}{if} (use\_visc\_rem) \textcolor{keywordflow}{then}
1180         \textcolor{keywordflow}{if} (cs%aggress\_adjust) \textcolor{keywordflow}{then}
1181           \textcolor{keywordflow}{do} k=1,nz ; \textcolor{keywordflow}{do} i=ish,ieh
1182             \textcolor{keywordflow}{if} (cs%vol\_CFL) \textcolor{keywordflow}{then}
1183               dy\_s = ratio\_max(g%areaT(i,j), g%dx\_Cv(i,j), 1000.0*g%dyT(i,j))
1184               dy\_n = ratio\_max(g%areaT(i,j+1), g%dx\_Cv(i,j), 1000.0*g%dyT(i,j+1))
1185             \textcolor{keywordflow}{else} ; dy\_s = g%dyT(i,j) ; dy\_n = g%dyT(i,j+1) ;\textcolor{keywordflow}{ endif}
1186             dv\_lim = 0.499*((dy\_s*i\_dt - v(i,j,k)) + min(0.0,v(i,j-1,k)))
1187             \textcolor{keywordflow}{if} (dv\_max\_cfl(i) * visc\_rem(i,k) > dv\_lim) &
1188               dv\_max\_cfl(i) = dv\_lim / visc\_rem(i,k)
1189 
1190             dv\_lim = 0.499*((-dy\_n*cfl\_dt - v(i,j,k)) + max(0.0,v(i,j+1,k)))
1191             \textcolor{keywordflow}{if} (dv\_min\_cfl(i) * visc\_rem(i,k) < dv\_lim) &
1192               dv\_min\_cfl(i) = dv\_lim / visc\_rem(i,k)
1193 \textcolor{keywordflow}{          enddo} ;\textcolor{keywordflow}{ enddo}
1194         \textcolor{keywordflow}{else}
1195           \textcolor{keywordflow}{do} k=1,nz ; \textcolor{keywordflow}{do} i=ish,ieh
1196             \textcolor{keywordflow}{if} (cs%vol\_CFL) \textcolor{keywordflow}{then}
1197               dy\_s = ratio\_max(g%areaT(i,j), g%dx\_Cv(i,j), 1000.0*g%dyT(i,j))
1198               dy\_n = ratio\_max(g%areaT(i,j+1), g%dx\_Cv(i,j), 1000.0*g%dyT(i,j+1))
1199             \textcolor{keywordflow}{else} ; dy\_s = g%dyT(i,j) ; dy\_n = g%dyT(i,j+1) ;\textcolor{keywordflow}{ endif}
1200             \textcolor{keywordflow}{if} (dv\_max\_cfl(i) * visc\_rem(i,k) > dy\_s*cfl\_dt - v(i,j,k)) &
1201               dv\_max\_cfl(i) = (dy\_s*cfl\_dt - v(i,j,k)) / visc\_rem(i,k)
1202             \textcolor{keywordflow}{if} (dv\_min\_cfl(i) * visc\_rem(i,k) < -dy\_n*cfl\_dt - v(i,j,k)) &
1203               dv\_min\_cfl(i) = -(dy\_n*cfl\_dt + v(i,j,k)) / visc\_rem(i,k)
1204 \textcolor{keywordflow}{          enddo} ;\textcolor{keywordflow}{ enddo}
1205 \textcolor{keywordflow}{        endif}
1206       \textcolor{keywordflow}{else}
1207         \textcolor{keywordflow}{if} (cs%aggress\_adjust) \textcolor{keywordflow}{then}
1208           \textcolor{keywordflow}{do} k=1,nz ; \textcolor{keywordflow}{do} i=ish,ieh
1209             \textcolor{keywordflow}{if} (cs%vol\_CFL) \textcolor{keywordflow}{then}
1210               dy\_s = ratio\_max(g%areaT(i,j), g%dx\_Cv(i,j), 1000.0*g%dyT(i,j))
1211               dy\_n = ratio\_max(g%areaT(i,j+1), g%dx\_Cv(i,j), 1000.0*g%dyT(i,j+1))
1212             \textcolor{keywordflow}{else} ; dy\_s = g%dyT(i,j) ; dy\_n = g%dyT(i,j+1) ;\textcolor{keywordflow}{ endif}
1213             dv\_max\_cfl(i) = min(dv\_max\_cfl(i), 0.499 * &
1214                         ((dy\_s*i\_dt - v(i,j,k)) + min(0.0,v(i,j-1,k))) )
1215             dv\_min\_cfl(i) = max(dv\_min\_cfl(i), 0.499 * &
1216                         ((-dy\_n*i\_dt - v(i,j,k)) + max(0.0,v(i,j+1,k))) )
1217 \textcolor{keywordflow}{          enddo} ;\textcolor{keywordflow}{ enddo}
1218         \textcolor{keywordflow}{else}
1219           \textcolor{keywordflow}{do} k=1,nz ; \textcolor{keywordflow}{do} i=ish,ieh
1220             \textcolor{keywordflow}{if} (cs%vol\_CFL) \textcolor{keywordflow}{then}
1221               dy\_s = ratio\_max(g%areaT(i,j), g%dx\_Cv(i,j), 1000.0*g%dyT(i,j))
1222               dy\_n = ratio\_max(g%areaT(i,j+1), g%dx\_Cv(i,j), 1000.0*g%dyT(i,j+1))
1223             \textcolor{keywordflow}{else} ; dy\_s = g%dyT(i,j) ; dy\_n = g%dyT(i,j+1) ;\textcolor{keywordflow}{ endif}
1224             dv\_max\_cfl(i) = min(dv\_max\_cfl(i), dy\_s*cfl\_dt - v(i,j,k))
1225             dv\_min\_cfl(i) = max(dv\_min\_cfl(i), -(dy\_n*cfl\_dt + v(i,j,k)))
1226 \textcolor{keywordflow}{          enddo} ;\textcolor{keywordflow}{ enddo}
1227 \textcolor{keywordflow}{        endif}
1228 \textcolor{keywordflow}{      endif}
1229       \textcolor{keywordflow}{do} i=ish,ieh
1230         dv\_max\_cfl(i) = max(dv\_max\_cfl(i),0.0)
1231         dv\_min\_cfl(i) = min(dv\_min\_cfl(i),0.0)
1232 \textcolor{keywordflow}{      enddo}
1233 
1234       any\_simple\_obc = .false.
1235       \textcolor{keywordflow}{if} (\textcolor{keyword}{present}(vhbt) .or. set\_bt\_cont) \textcolor{keywordflow}{then}
1236         \textcolor{keywordflow}{if} (local\_specified\_bc .or. local\_flather\_obc) \textcolor{keywordflow}{then} ; \textcolor{keywordflow}{do} i=ish,ieh
1237           l\_seg = obc%segnum\_v(i,j)
1238 
1239           \textcolor{comment}{! Avoid reconciling barotropic/baroclinic transports if transport is specified}
1240           is\_simple = .false.
1241           \textcolor{keywordflow}{if} (l\_seg /= obc\_none) &
1242             is\_simple = obc%segment(l\_seg)%specified
1243           do\_i(i) = .not.(l\_seg /= obc\_none .and. is\_simple)
1244           any\_simple\_obc = any\_simple\_obc .or. is\_simple
1245 \textcolor{keywordflow}{        enddo} ; \textcolor{keywordflow}{else} ; \textcolor{keywordflow}{do} i=ish,ieh
1246           do\_i(i) = .true.
1247 \textcolor{keywordflow}{        enddo} ;\textcolor{keywordflow}{ endif}
1248 \textcolor{keywordflow}{      endif}
1249 
1250       \textcolor{keywordflow}{if} (\textcolor{keyword}{present}(vhbt)) \textcolor{keywordflow}{then}
1251         \textcolor{keyword}{call }meridional\_flux\_adjust(v, h\_in, h\_l, h\_r, vhbt(:,j), vh\_tot\_0, dvhdv\_tot\_0, dv, &
1252                                dv\_max\_cfl, dv\_min\_cfl, dt, g, us, cs, visc\_rem, &
1253                                j, ish, ieh, do\_i, .true., vh, obc=obc)
1254 
1255         \textcolor{keywordflow}{if} (\textcolor{keyword}{present}(v\_cor)) \textcolor{keywordflow}{then} ; \textcolor{keywordflow}{do} k=1,nz
1256           \textcolor{keywordflow}{do} i=ish,ieh ; v\_cor(i,j,k) = v(i,j,k) + dv(i) * visc\_rem(i,k) ;\textcolor{keywordflow}{ enddo}
1257           \textcolor{keywordflow}{if} (local\_specified\_bc) \textcolor{keywordflow}{then} ; \textcolor{keywordflow}{do} i=ish,ieh
1258             l\_seg = obc%segnum\_v(i,j)
1259 
1260             \textcolor{keywordflow}{if} (l\_seg /= obc\_none) \textcolor{keywordflow}{then}
1261               \textcolor{keywordflow}{if} (obc%segment(obc%segnum\_v(i,j))%specified) &
1262                 v\_cor(i,j,k) = obc%segment(obc%segnum\_v(i,j))%normal\_vel(i,j,k)
1263 \textcolor{keywordflow}{            endif}
1264 \textcolor{keywordflow}{          enddo} ;\textcolor{keywordflow}{ endif}
1265 \textcolor{keywordflow}{        enddo} ;\textcolor{keywordflow}{ endif} \textcolor{comment}{! v-corrected}
1266 \textcolor{keywordflow}{      endif}
1267 
1268       \textcolor{keywordflow}{if} (set\_bt\_cont) \textcolor{keywordflow}{then}
1269         \textcolor{keyword}{call }set\_merid\_bt\_cont(v, h\_in, h\_l, h\_r, bt\_cont, vh\_tot\_0, dvhdv\_tot\_0,&
1270                                dv\_max\_cfl, dv\_min\_cfl, dt, g, us, cs, visc\_rem, &
1271                                visc\_rem\_max, j, ish, ieh, do\_i)
1272         \textcolor{keywordflow}{if} (any\_simple\_obc) \textcolor{keywordflow}{then}
1273           \textcolor{keywordflow}{do} i=ish,ieh
1274             l\_seg = obc%segnum\_v(i,j)
1275 
1276             do\_i(i) = .false.
1277             \textcolor{keywordflow}{if}(l\_seg /= obc\_none) &
1278               do\_i(i) = (obc%segment(l\_seg)%specified)
1279 
1280             \textcolor{keywordflow}{if} (do\_i(i)) favi(i) = gv%H\_subroundoff*g%dx\_Cv(i,j)
1281 \textcolor{keywordflow}{          enddo}
1282           \textcolor{comment}{! NOTE: do\_I(I) should prevent access to segment OBC\_NONE}
1283           \textcolor{keywordflow}{do} k=1,nz ; \textcolor{keywordflow}{do} i=ish,ieh ; \textcolor{keywordflow}{if} (do\_i(i)) \textcolor{keywordflow}{then}
1284             \textcolor{keywordflow}{if} ((abs(obc%segment(obc%segnum\_v(i,j))%normal\_vel(i,j,k)) > 0.0) .and. &
1285                 (obc%segment(obc%segnum\_v(i,j))%specified)) &
1286               favi(i) = favi(i) + obc%segment(obc%segnum\_v(i,j))%normal\_trans(i,j,k) / &
1287                                   obc%segment(obc%segnum\_v(i,j))%normal\_vel(i,j,k)
1288 \textcolor{keywordflow}{          endif} ;\textcolor{keywordflow}{ enddo} ;\textcolor{keywordflow}{ enddo}
1289           \textcolor{keywordflow}{do} i=ish,ieh ; \textcolor{keywordflow}{if} (do\_i(i)) \textcolor{keywordflow}{then}
1290             bt\_cont%FA\_v\_S0(i,j) = favi(i) ; bt\_cont%FA\_v\_N0(i,j) = favi(i)
1291             bt\_cont%FA\_v\_SS(i,j) = favi(i) ; bt\_cont%FA\_v\_NN(i,j) = favi(i)
1292             bt\_cont%vBT\_SS(i,j) = 0.0 ; bt\_cont%vBT\_NN(i,j) = 0.0
1293 \textcolor{keywordflow}{          endif} ;\textcolor{keywordflow}{ enddo}
1294 \textcolor{keywordflow}{        endif}
1295 \textcolor{keywordflow}{      endif} \textcolor{comment}{! set\_BT\_cont}
1296 
1297 \textcolor{keywordflow}{    endif} \textcolor{comment}{! present(vhbt) or set\_BT\_cont}
1298 
1299 \textcolor{keywordflow}{  enddo} \textcolor{comment}{! j-loop}
1300 
1301   \textcolor{keywordflow}{if} (local\_open\_bc .and. set\_bt\_cont) \textcolor{keywordflow}{then}
1302     \textcolor{keywordflow}{do} n = 1, obc%number\_of\_segments
1303       \textcolor{keywordflow}{if} (obc%segment(n)%open .and. obc%segment(n)%is\_N\_or\_S) \textcolor{keywordflow}{then}
1304         j = obc%segment(n)%HI%JsdB
1305         \textcolor{keywordflow}{if} (obc%segment(n)%direction == obc\_direction\_n) \textcolor{keywordflow}{then}
1306           \textcolor{keywordflow}{do} i = obc%segment(n)%HI%Isd, obc%segment(n)%HI%Ied
1307             fa\_v = 0.0
1308             \textcolor{keywordflow}{do} k=1,nz ; fa\_v = fa\_v + h\_in(i,j,k)*g%dx\_Cv(i,j) ;\textcolor{keywordflow}{ enddo}
1309             bt\_cont%FA\_v\_S0(i,j) = fa\_v ; bt\_cont%FA\_v\_N0(i,j) = fa\_v
1310             bt\_cont%FA\_v\_SS(i,j) = fa\_v ; bt\_cont%FA\_v\_NN(i,j) = fa\_v
1311             bt\_cont%vBT\_SS(i,j) = 0.0 ; bt\_cont%vBT\_NN(i,j) = 0.0
1312 \textcolor{keywordflow}{          enddo}
1313         \textcolor{keywordflow}{else}
1314           \textcolor{keywordflow}{do} i = obc%segment(n)%HI%Isd, obc%segment(n)%HI%Ied
1315             fa\_v = 0.0
1316             \textcolor{keywordflow}{do} k=1,nz ; fa\_v = fa\_v + h\_in(i,j+1,k)*g%dx\_Cv(i,j) ;\textcolor{keywordflow}{ enddo}
1317             bt\_cont%FA\_v\_S0(i,j) = fa\_v ; bt\_cont%FA\_v\_N0(i,j) = fa\_v
1318             bt\_cont%FA\_v\_SS(i,j) = fa\_v ; bt\_cont%FA\_v\_NN(i,j) = fa\_v
1319             bt\_cont%vBT\_SS(i,j) = 0.0 ; bt\_cont%vBT\_NN(i,j) = 0.0
1320 \textcolor{keywordflow}{          enddo}
1321 \textcolor{keywordflow}{        endif}
1322 \textcolor{keywordflow}{      endif}
1323 \textcolor{keywordflow}{    enddo}
1324 \textcolor{keywordflow}{  endif}
1325   \textcolor{keyword}{call }cpu\_clock\_end(id\_clock\_correct)
1326 
1327   \textcolor{keywordflow}{if} (set\_bt\_cont) \textcolor{keywordflow}{then} ; \textcolor{keywordflow}{if} (\textcolor{keyword}{allocated}(bt\_cont%h\_v)) \textcolor{keywordflow}{then}
1328     \textcolor{keywordflow}{if} (\textcolor{keyword}{present}(v\_cor)) \textcolor{keywordflow}{then}
1329       \textcolor{keyword}{call }merid\_face\_thickness(v\_cor, h\_in, h\_l, h\_r, bt\_cont%h\_v, dt, g, us, lb, &
1330                                 cs%vol\_CFL, cs%marginal\_faces, visc\_rem\_v, obc)
1331     \textcolor{keywordflow}{else}
1332       \textcolor{keyword}{call }merid\_face\_thickness(v, h\_in, h\_l, h\_r, bt\_cont%h\_v, dt, g, us, lb, &
1333                                 cs%vol\_CFL, cs%marginal\_faces, visc\_rem\_v, obc)
1334 \textcolor{keywordflow}{    endif}
1335 \textcolor{keywordflow}{  endif} ;\textcolor{keywordflow}{ endif}
1336 
\end{DoxyCode}
\mbox{\Hypertarget{namespacemom__continuity__ppm_ab03786fff2550dd61282356608fc1352}\label{namespacemom__continuity__ppm_ab03786fff2550dd61282356608fc1352}} 
\index{mom\+\_\+continuity\+\_\+ppm@{mom\+\_\+continuity\+\_\+ppm}!ppm\+\_\+limit\+\_\+cw84@{ppm\+\_\+limit\+\_\+cw84}}
\index{ppm\+\_\+limit\+\_\+cw84@{ppm\+\_\+limit\+\_\+cw84}!mom\+\_\+continuity\+\_\+ppm@{mom\+\_\+continuity\+\_\+ppm}}
\subsubsection{\texorpdfstring{ppm\+\_\+limit\+\_\+cw84()}{ppm\_limit\_cw84()}}
{\footnotesize\ttfamily subroutine mom\+\_\+continuity\+\_\+ppm\+::ppm\+\_\+limit\+\_\+cw84 (\begin{DoxyParamCaption}\item[{real, dimension(szi\+\_\+(g),szj\+\_\+(g)), intent(in)}]{h\+\_\+in,  }\item[{real, dimension(szi\+\_\+(g),szj\+\_\+(g)), intent(inout)}]{h\+\_\+L,  }\item[{real, dimension(szi\+\_\+(g),szj\+\_\+(g)), intent(inout)}]{h\+\_\+R,  }\item[{type(ocean\+\_\+grid\+\_\+type), intent(in)}]{G,  }\item[{integer, intent(in)}]{iis,  }\item[{integer, intent(in)}]{iie,  }\item[{integer, intent(in)}]{jis,  }\item[{integer, intent(in)}]{jie }\end{DoxyParamCaption})\hspace{0.3cm}{\ttfamily [private]}}



This subroutine limits the left/right edge values of the P\+PM reconstruction according to the monotonic prescription of Colella and Woodward, 1984. 


\begin{DoxyParams}[1]{Parameters}
\mbox{\tt in}  & {\em g} & Ocean\textquotesingle{}s grid structure.\\
\hline
\mbox{\tt in}  & {\em h\+\_\+in} & Layer thickness \mbox{[}H $\sim$$>$ m or kg m-\/2\mbox{]}.\\
\hline
\mbox{\tt in,out}  & {\em h\+\_\+l} & Left thickness in the reconstruction, \mbox{[}H $\sim$$>$ m or kg m-\/2\mbox{]}.\\
\hline
\mbox{\tt in,out}  & {\em h\+\_\+r} & Right thickness in the reconstruction, \mbox{[}H $\sim$$>$ m or kg m-\/2\mbox{]}.\\
\hline
\mbox{\tt in}  & {\em iis} & Start of i index range.\\
\hline
\mbox{\tt in}  & {\em iie} & End of i index range.\\
\hline
\mbox{\tt in}  & {\em jis} & Start of j index range.\\
\hline
\mbox{\tt in}  & {\em jie} & End of j index range. \\
\hline
\end{DoxyParams}


Definition at line 2179 of file M\+O\+M\+\_\+continuity\+\_\+\+P\+P\+M.\+F90.


\begin{DoxyCode}
2179   \textcolor{keywordtype}{type}(ocean\_grid\_type),             \textcolor{keywordtype}{intent(in)}  :: G\textcolor{comment}{     !< Ocean's grid structure.}
2180   \textcolor{keywordtype}{real}, \textcolor{keywordtype}{dimension(SZI\_(G),SZJ\_(G))},  \textcolor{keywordtype}{intent(in)}  :: h\_in\textcolor{comment}{  !< Layer thickness [H ~> m or kg m-2].}
2181   \textcolor{keywordtype}{real}, \textcolor{keywordtype}{dimension(SZI\_(G),SZJ\_(G))},  \textcolor{keywordtype}{intent(inout)} :: h\_L\textcolor{comment}{ !< Left thickness in the reconstruction,}
2182 \textcolor{comment}{                                                          !! [H ~> m or kg m-2].}
2183   \textcolor{keywordtype}{real}, \textcolor{keywordtype}{dimension(SZI\_(G),SZJ\_(G))},  \textcolor{keywordtype}{intent(inout)} :: h\_R\textcolor{comment}{ !< Right thickness in the reconstruction,}
2184 \textcolor{comment}{                                                          !! [H ~> m or kg m-2].}
2185   \textcolor{keywordtype}{integer},                           \textcolor{keywordtype}{intent(in)}  :: iis\textcolor{comment}{   !< Start of i index range.}
2186   \textcolor{keywordtype}{integer},                           \textcolor{keywordtype}{intent(in)}  :: iie\textcolor{comment}{   !< End of i index range.}
2187   \textcolor{keywordtype}{integer},                           \textcolor{keywordtype}{intent(in)}  :: jis\textcolor{comment}{   !< Start of j index range.}
2188   \textcolor{keywordtype}{integer},                           \textcolor{keywordtype}{intent(in)}  :: jie\textcolor{comment}{   !< End of j index range.}
2189 
2190   \textcolor{comment}{! Local variables}
2191   \textcolor{keywordtype}{real}    :: h\_i, RLdiff, RLdiff2, RLmean, FunFac
2192   \textcolor{keywordtype}{character(len=256)} :: mesg
2193   \textcolor{keywordtype}{integer} :: i,j
2194 
2195   \textcolor{keywordflow}{do} j=jis,jie ; \textcolor{keywordflow}{do} i=iis,iie
2196     \textcolor{comment}{! This limiter monotonizes the parabola following}
2197     \textcolor{comment}{! Colella and Woodward, 1984, Eq. 1.10}
2198     h\_i = h\_in(i,j)
2199     \textcolor{keywordflow}{if} ( ( h\_r(i,j) - h\_i ) * ( h\_i - h\_l(i,j) ) <= 0. ) \textcolor{keywordflow}{then}
2200       h\_l(i,j) = h\_i ; h\_r(i,j) = h\_i
2201     \textcolor{keywordflow}{else}
2202       rldiff = h\_r(i,j) - h\_l(i,j)            \textcolor{comment}{! Difference of edge values}
2203       rlmean = 0.5 * ( h\_r(i,j) + h\_l(i,j) )  \textcolor{comment}{! Mean of edge values}
2204       funfac = 6. * rldiff * ( h\_i - rlmean ) \textcolor{comment}{! Some funny factor}
2205       rldiff2 = rldiff * rldiff               \textcolor{comment}{! Square of difference}
2206       \textcolor{keywordflow}{if} ( funfac >  rldiff2 ) h\_l(i,j) = 3. * h\_i - 2. * h\_r(i,j)
2207       \textcolor{keywordflow}{if} ( funfac < -rldiff2 ) h\_r(i,j) = 3. * h\_i - 2. * h\_l(i,j)
2208 \textcolor{keywordflow}{    endif}
2209 \textcolor{keywordflow}{  enddo} ;\textcolor{keywordflow}{ enddo}
2210 
2211   \textcolor{keywordflow}{return}
\end{DoxyCode}
\mbox{\Hypertarget{namespacemom__continuity__ppm_a870edb0c5b2cb0464899430b6651260c}\label{namespacemom__continuity__ppm_a870edb0c5b2cb0464899430b6651260c}} 
\index{mom\+\_\+continuity\+\_\+ppm@{mom\+\_\+continuity\+\_\+ppm}!ppm\+\_\+limit\+\_\+pos@{ppm\+\_\+limit\+\_\+pos}}
\index{ppm\+\_\+limit\+\_\+pos@{ppm\+\_\+limit\+\_\+pos}!mom\+\_\+continuity\+\_\+ppm@{mom\+\_\+continuity\+\_\+ppm}}
\subsubsection{\texorpdfstring{ppm\+\_\+limit\+\_\+pos()}{ppm\_limit\_pos()}}
{\footnotesize\ttfamily subroutine mom\+\_\+continuity\+\_\+ppm\+::ppm\+\_\+limit\+\_\+pos (\begin{DoxyParamCaption}\item[{real, dimension(szi\+\_\+(g),szj\+\_\+(g)), intent(in)}]{h\+\_\+in,  }\item[{real, dimension(szi\+\_\+(g),szj\+\_\+(g)), intent(inout)}]{h\+\_\+L,  }\item[{real, dimension(szi\+\_\+(g),szj\+\_\+(g)), intent(inout)}]{h\+\_\+R,  }\item[{real, intent(in)}]{h\+\_\+min,  }\item[{type(ocean\+\_\+grid\+\_\+type), intent(in)}]{G,  }\item[{integer, intent(in)}]{iis,  }\item[{integer, intent(in)}]{iie,  }\item[{integer, intent(in)}]{jis,  }\item[{integer, intent(in)}]{jie }\end{DoxyParamCaption})\hspace{0.3cm}{\ttfamily [private]}}



This subroutine limits the left/right edge values of the P\+PM reconstruction to give a reconstruction that is positive-\/definite. Here this is reinterpreted as giving a constant thickness if the mean thickness is less than h\+\_\+min, with a minimum of h\+\_\+min otherwise. 


\begin{DoxyParams}[1]{Parameters}
\mbox{\tt in}  & {\em g} & Ocean\textquotesingle{}s grid structure.\\
\hline
\mbox{\tt in}  & {\em h\+\_\+in} & Layer thickness \mbox{[}H $\sim$$>$ m or kg m-\/2\mbox{]}.\\
\hline
\mbox{\tt in,out}  & {\em h\+\_\+l} & Left thickness in the reconstruction \mbox{[}H $\sim$$>$ m or kg m-\/2\mbox{]}.\\
\hline
\mbox{\tt in,out}  & {\em h\+\_\+r} & Right thickness in the reconstruction \mbox{[}H $\sim$$>$ m or kg m-\/2\mbox{]}.\\
\hline
\mbox{\tt in}  & {\em h\+\_\+min} & The minimum thickness that can be obtained by a concave parabolic fit.\\
\hline
\mbox{\tt in}  & {\em iis} & Start of i index range.\\
\hline
\mbox{\tt in}  & {\em iie} & End of i index range.\\
\hline
\mbox{\tt in}  & {\em jis} & Start of j index range.\\
\hline
\mbox{\tt in}  & {\em jie} & End of j index range. \\
\hline
\end{DoxyParams}


Definition at line 2138 of file M\+O\+M\+\_\+continuity\+\_\+\+P\+P\+M.\+F90.


\begin{DoxyCode}
2138   \textcolor{keywordtype}{type}(ocean\_grid\_type),             \textcolor{keywordtype}{intent(in)}  :: G\textcolor{comment}{    !< Ocean's grid structure.}
2139   \textcolor{keywordtype}{real}, \textcolor{keywordtype}{dimension(SZI\_(G),SZJ\_(G))},  \textcolor{keywordtype}{intent(in)}  :: h\_in\textcolor{comment}{ !< Layer thickness [H ~> m or kg m-2].}
2140   \textcolor{keywordtype}{real}, \textcolor{keywordtype}{dimension(SZI\_(G),SZJ\_(G))},  \textcolor{keywordtype}{intent(inout)} :: h\_L\textcolor{comment}{ !< Left thickness in the reconstruction [H ~> m
       or kg m-2].}
2141   \textcolor{keywordtype}{real}, \textcolor{keywordtype}{dimension(SZI\_(G),SZJ\_(G))},  \textcolor{keywordtype}{intent(inout)} :: h\_R\textcolor{comment}{ !< Right thickness in the reconstruction [H ~> m
       or kg m-2].}
2142   \textcolor{keywordtype}{real},                              \textcolor{keywordtype}{intent(in)}  :: h\_min\textcolor{comment}{ !< The minimum thickness}
2143 \textcolor{comment}{                    !! that can be obtained by a concave parabolic fit.}
2144   \textcolor{keywordtype}{integer},                           \textcolor{keywordtype}{intent(in)}  :: iis\textcolor{comment}{      !< Start of i index range.}
2145   \textcolor{keywordtype}{integer},                           \textcolor{keywordtype}{intent(in)}  :: iie\textcolor{comment}{      !< End of i index range.}
2146   \textcolor{keywordtype}{integer},                           \textcolor{keywordtype}{intent(in)}  :: jis\textcolor{comment}{      !< Start of j index range.}
2147   \textcolor{keywordtype}{integer},                           \textcolor{keywordtype}{intent(in)}  :: jie\textcolor{comment}{      !< End of j index range.}
2148 
2149 \textcolor{comment}{! Local variables}
2150   \textcolor{keywordtype}{real}    :: curv, dh, scale
2151   \textcolor{keywordtype}{character(len=256)} :: mesg
2152   \textcolor{keywordtype}{integer} :: i,j
2153 
2154   \textcolor{keywordflow}{do} j=jis,jie ; \textcolor{keywordflow}{do} i=iis,iie
2155     \textcolor{comment}{! This limiter prevents undershooting minima within the domain with}
2156     \textcolor{comment}{! values less than h\_min.}
2157     curv = 3.0*(h\_l(i,j) + h\_r(i,j) - 2.0*h\_in(i,j))
2158     \textcolor{keywordflow}{if} (curv > 0.0) \textcolor{keywordflow}{then} \textcolor{comment}{! Only minima are limited.}
2159       dh = h\_r(i,j) - h\_l(i,j)
2160       \textcolor{keywordflow}{if} (abs(dh) < curv) \textcolor{keywordflow}{then} \textcolor{comment}{! The parabola's minimum is within the cell.}
2161         \textcolor{keywordflow}{if} (h\_in(i,j) <= h\_min) \textcolor{keywordflow}{then}
2162           h\_l(i,j) = h\_in(i,j) ; h\_r(i,j) = h\_in(i,j)
2163         \textcolor{keywordflow}{elseif} (12.0*curv*(h\_in(i,j) - h\_min) < (curv**2 + 3.0*dh**2)) \textcolor{keywordflow}{then}
2164           \textcolor{comment}{! The minimum value is h\_in - (curv^2 + 3*dh^2)/(12*curv), and must}
2165           \textcolor{comment}{! be limited in this case.  0 < scale < 1.}
2166           scale = 12.0*curv*(h\_in(i,j) - h\_min) / (curv**2 + 3.0*dh**2)
2167           h\_l(i,j) = h\_in(i,j) + scale*(h\_l(i,j) - h\_in(i,j))
2168           h\_r(i,j) = h\_in(i,j) + scale*(h\_r(i,j) - h\_in(i,j))
2169 \textcolor{keywordflow}{        endif}
2170 \textcolor{keywordflow}{      endif}
2171 \textcolor{keywordflow}{    endif}
2172 \textcolor{keywordflow}{  enddo} ;\textcolor{keywordflow}{ enddo}
2173 
\end{DoxyCode}
\mbox{\Hypertarget{namespacemom__continuity__ppm_a9a7eac2a9b17d0e9ee9ca0a27d2f8fb6}\label{namespacemom__continuity__ppm_a9a7eac2a9b17d0e9ee9ca0a27d2f8fb6}} 
\index{mom\+\_\+continuity\+\_\+ppm@{mom\+\_\+continuity\+\_\+ppm}!ppm\+\_\+reconstruction\+\_\+x@{ppm\+\_\+reconstruction\+\_\+x}}
\index{ppm\+\_\+reconstruction\+\_\+x@{ppm\+\_\+reconstruction\+\_\+x}!mom\+\_\+continuity\+\_\+ppm@{mom\+\_\+continuity\+\_\+ppm}}
\subsubsection{\texorpdfstring{ppm\+\_\+reconstruction\+\_\+x()}{ppm\_reconstruction\_x()}}
{\footnotesize\ttfamily subroutine mom\+\_\+continuity\+\_\+ppm\+::ppm\+\_\+reconstruction\+\_\+x (\begin{DoxyParamCaption}\item[{real, dimension(szi\+\_\+(g),szj\+\_\+(g)), intent(in)}]{h\+\_\+in,  }\item[{real, dimension(szi\+\_\+(g),szj\+\_\+(g)), intent(out)}]{h\+\_\+L,  }\item[{real, dimension(szi\+\_\+(g),szj\+\_\+(g)), intent(out)}]{h\+\_\+R,  }\item[{type(ocean\+\_\+grid\+\_\+type), intent(in)}]{G,  }\item[{type(\mbox{\hyperlink{structmom__continuity__ppm_1_1loop__bounds__type}{loop\+\_\+bounds\+\_\+type}}), intent(in)}]{LB,  }\item[{real, intent(in)}]{h\+\_\+min,  }\item[{logical, intent(in), optional}]{monotonic,  }\item[{logical, intent(in), optional}]{simple\+\_\+2nd,  }\item[{type(ocean\+\_\+obc\+\_\+type), optional, pointer}]{O\+BC }\end{DoxyParamCaption})\hspace{0.3cm}{\ttfamily [private]}}



Calculates left/right edge values for P\+PM reconstruction. 


\begin{DoxyParams}[1]{Parameters}
\mbox{\tt in}  & {\em g} & Ocean\textquotesingle{}s grid structure.\\
\hline
\mbox{\tt in}  & {\em h\+\_\+in} & Layer thickness \mbox{[}H $\sim$$>$ m or kg m-\/2\mbox{]}.\\
\hline
\mbox{\tt out}  & {\em h\+\_\+l} & Left thickness in the reconstruction, \mbox{[}H $\sim$$>$ m or kg m-\/2\mbox{]}.\\
\hline
\mbox{\tt out}  & {\em h\+\_\+r} & Right thickness in the reconstruction, \mbox{[}H $\sim$$>$ m or kg m-\/2\mbox{]}.\\
\hline
\mbox{\tt in}  & {\em lb} & Active loop bounds structure.\\
\hline
\mbox{\tt in}  & {\em h\+\_\+min} & The minimum thickness that can be obtained by a concave parabolic fit.\\
\hline
\mbox{\tt in}  & {\em monotonic} & If true, use the Colella \& Woodward monotonic limiter. Otherwise use a simple positive-\/definite limiter.\\
\hline
\mbox{\tt in}  & {\em simple\+\_\+2nd} & If true, use the arithmetic mean thicknesses as the default edge values for a simple 2nd order scheme.\\
\hline
 & {\em obc} & Open boundaries control structure. \\
\hline
\end{DoxyParams}


Definition at line 1859 of file M\+O\+M\+\_\+continuity\+\_\+\+P\+P\+M.\+F90.


\begin{DoxyCode}
1859   \textcolor{keywordtype}{type}(ocean\_grid\_type),             \textcolor{keywordtype}{intent(in)}  :: G\textcolor{comment}{    !< Ocean's grid structure.}
1860   \textcolor{keywordtype}{real}, \textcolor{keywordtype}{dimension(SZI\_(G),SZJ\_(G))},  \textcolor{keywordtype}{intent(in)}  :: h\_in\textcolor{comment}{ !< Layer thickness [H ~> m or kg m-2].}
1861   \textcolor{keywordtype}{real}, \textcolor{keywordtype}{dimension(SZI\_(G),SZJ\_(G))},  \textcolor{keywordtype}{intent(out)} :: h\_L\textcolor{comment}{  !< Left thickness in the reconstruction,}
1862 \textcolor{comment}{                                                         !! [H ~> m or kg m-2].}
1863   \textcolor{keywordtype}{real}, \textcolor{keywordtype}{dimension(SZI\_(G),SZJ\_(G))},  \textcolor{keywordtype}{intent(out)} :: h\_R\textcolor{comment}{  !< Right thickness in the reconstruction,}
1864 \textcolor{comment}{                                                         !! [H ~> m or kg m-2].}
1865   \textcolor{keywordtype}{type}(loop\_bounds\_type),            \textcolor{keywordtype}{intent(in)}  :: LB\textcolor{comment}{   !< Active loop bounds structure.}
1866   \textcolor{keywordtype}{real},                              \textcolor{keywordtype}{intent(in)}  :: h\_min\textcolor{comment}{ !< The minimum thickness}
1867 \textcolor{comment}{                    !! that can be obtained by a concave parabolic fit.}
1868   \textcolor{keywordtype}{logical}, \textcolor{keywordtype}{optional},                 \textcolor{keywordtype}{intent(in)}  :: monotonic\textcolor{comment}{ !< If true, use the}
1869 \textcolor{comment}{                    !! Colella & Woodward monotonic limiter.}
1870 \textcolor{comment}{                    !! Otherwise use a simple positive-definite limiter.}
1871   \textcolor{keywordtype}{logical}, \textcolor{keywordtype}{optional},                 \textcolor{keywordtype}{intent(in)}  :: simple\_2nd\textcolor{comment}{ !< If true, use the}
1872 \textcolor{comment}{                    !! arithmetic mean thicknesses as the default edge values}
1873 \textcolor{comment}{                    !! for a simple 2nd order scheme.}
1874   \textcolor{keywordtype}{type}(ocean\_OBC\_type),    \textcolor{keywordtype}{optional}, \textcolor{keywordtype}{pointer}     :: OBC\textcolor{comment}{ !< Open boundaries control structure.}
1875 
1876   \textcolor{comment}{! Local variables with useful mnemonic names.}
1877   \textcolor{keywordtype}{real}, \textcolor{keywordtype}{dimension(SZI\_(G),SZJ\_(G))}  :: slp \textcolor{comment}{! The slopes.}
1878   \textcolor{keywordtype}{real}, \textcolor{keywordtype}{parameter} :: oneSixth = 1./6.
1879   \textcolor{keywordtype}{real} :: h\_ip1, h\_im1
1880   \textcolor{keywordtype}{real} :: dMx, dMn
1881   \textcolor{keywordtype}{logical} :: use\_CW84, use\_2nd
1882   \textcolor{keywordtype}{character(len=256)} :: mesg
1883   \textcolor{keywordtype}{integer} :: i, j, isl, iel, jsl, jel, n, stencil
1884   \textcolor{keywordtype}{logical} :: local\_open\_BC
1885   \textcolor{keywordtype}{type}(OBC\_segment\_type), \textcolor{keywordtype}{pointer} :: segment => null()
1886 
1887   use\_cw84 = .false. ; \textcolor{keywordflow}{if} (\textcolor{keyword}{present}(monotonic)) use\_cw84 = monotonic
1888   use\_2nd = .false. ; \textcolor{keywordflow}{if} (\textcolor{keyword}{present}(simple\_2nd)) use\_2nd = simple\_2nd
1889 
1890   local\_open\_bc = .false.
1891   \textcolor{keywordflow}{if} (\textcolor{keyword}{present}(obc)) \textcolor{keywordflow}{then} ; \textcolor{keywordflow}{if} (\textcolor{keyword}{associated}(obc)) \textcolor{keywordflow}{then}
1892     local\_open\_bc = obc%open\_u\_BCs\_exist\_globally
1893 \textcolor{keywordflow}{  endif} ;\textcolor{keywordflow}{ endif}
1894 
1895   isl = lb%ish-1 ; iel = lb%ieh+1 ; jsl = lb%jsh ; jel = lb%jeh
1896 
1897   \textcolor{comment}{! This is the stencil of the reconstruction, not the scheme overall.}
1898   stencil = 2 ; \textcolor{keywordflow}{if} (use\_2nd) stencil = 1
1899 
1900   \textcolor{keywordflow}{if} ((isl-stencil < g%isd) .or. (iel+stencil > g%ied)) \textcolor{keywordflow}{then}
1901     \textcolor{keyword}{write}(mesg,\textcolor{stringliteral}{'("In MOM\_continuity\_PPM, PPM\_reconstruction\_x called with a ", &}
1902 \textcolor{stringliteral}{}\textcolor{stringliteral}{               & "x-halo that needs to be increased by ",i2,".")'}) &
1903                stencil + max(g%isd-isl,iel-g%ied)
1904     \textcolor{keyword}{call }mom\_error(fatal,mesg)
1905 \textcolor{keywordflow}{  endif}
1906   \textcolor{keywordflow}{if} ((jsl < g%jsd) .or. (jel > g%jed)) \textcolor{keywordflow}{then}
1907     \textcolor{keyword}{write}(mesg,\textcolor{stringliteral}{'("In MOM\_continuity\_PPM, PPM\_reconstruction\_x called with a ", &}
1908 \textcolor{stringliteral}{}\textcolor{stringliteral}{               & "y-halo that needs to be increased by ",i2,".")'}) &
1909                max(g%jsd-jsl,jel-g%jed)
1910     \textcolor{keyword}{call }mom\_error(fatal,mesg)
1911 \textcolor{keywordflow}{  endif}
1912 
1913   \textcolor{keywordflow}{if} (use\_2nd) \textcolor{keywordflow}{then}
1914     \textcolor{keywordflow}{do} j=jsl,jel ; \textcolor{keywordflow}{do} i=isl,iel
1915       h\_im1 = g%mask2dT(i-1,j) * h\_in(i-1,j) + (1.0-g%mask2dT(i-1,j)) * h\_in(i,j)
1916       h\_ip1 = g%mask2dT(i+1,j) * h\_in(i+1,j) + (1.0-g%mask2dT(i+1,j)) * h\_in(i,j)
1917       h\_l(i,j) = 0.5*( h\_im1 + h\_in(i,j) )
1918       h\_r(i,j) = 0.5*( h\_ip1 + h\_in(i,j) )
1919 \textcolor{keywordflow}{    enddo} ;\textcolor{keywordflow}{ enddo}
1920   \textcolor{keywordflow}{else}
1921     \textcolor{keywordflow}{do} j=jsl,jel ; \textcolor{keywordflow}{do} i=isl-1,iel+1
1922       \textcolor{keywordflow}{if} ((g%mask2dT(i-1,j) * g%mask2dT(i,j) * g%mask2dT(i+1,j)) == 0.0) \textcolor{keywordflow}{then}
1923         slp(i,j) = 0.0
1924       \textcolor{keywordflow}{else}
1925         \textcolor{comment}{! This uses a simple 2nd order slope.}
1926         slp(i,j) = 0.5 * (h\_in(i+1,j) - h\_in(i-1,j))
1927         \textcolor{comment}{! Monotonic constraint, see Eq. B2 in Lin 1994, MWR (132)}
1928         dmx = max(h\_in(i+1,j), h\_in(i-1,j), h\_in(i,j)) - h\_in(i,j)
1929         dmn = h\_in(i,j) - min(h\_in(i+1,j), h\_in(i-1,j), h\_in(i,j))
1930         slp(i,j) = sign(1.,slp(i,j)) * min(abs(slp(i,j)), 2. * min(dmx, dmn))
1931                 \textcolor{comment}{! * (G%mask2dT(i-1,j) * G%mask2dT(i,j) * G%mask2dT(i+1,j))}
1932 \textcolor{keywordflow}{      endif}
1933 \textcolor{keywordflow}{    enddo} ;\textcolor{keywordflow}{ enddo}
1934 
1935     \textcolor{keywordflow}{if} (local\_open\_bc) \textcolor{keywordflow}{then}
1936       \textcolor{keywordflow}{do} n=1, obc%number\_of\_segments
1937         segment => obc%segment(n)
1938         \textcolor{keywordflow}{if} (.not. segment%on\_pe) cycle
1939         \textcolor{keywordflow}{if} (segment%direction == obc\_direction\_e .or. &
1940             segment%direction == obc\_direction\_w) \textcolor{keywordflow}{then}
1941           i=segment%HI%IsdB
1942           \textcolor{keywordflow}{do} j=segment%HI%jsd,segment%HI%jed
1943             slp(i+1,j) = 0.0
1944             slp(i,j) = 0.0
1945 \textcolor{keywordflow}{          enddo}
1946 \textcolor{keywordflow}{        endif}
1947 \textcolor{keywordflow}{      enddo}
1948 \textcolor{keywordflow}{    endif}
1949 
1950     \textcolor{keywordflow}{do} j=jsl,jel ; \textcolor{keywordflow}{do} i=isl,iel
1951       \textcolor{comment}{! Neighboring values should take into account any boundaries.  The 3}
1952       \textcolor{comment}{! following sets of expressions are equivalent.}
1953     \textcolor{comment}{! h\_im1 = h\_in(i-1,j,k) ; if (G%mask2dT(i-1,j) < 0.5) h\_im1 = h\_in(i,j)}
1954     \textcolor{comment}{! h\_ip1 = h\_in(i+1,j,k) ; if (G%mask2dT(i+1,j) < 0.5) h\_ip1 = h\_in(i,j)}
1955       h\_im1 = g%mask2dT(i-1,j) * h\_in(i-1,j) + (1.0-g%mask2dT(i-1,j)) * h\_in(i,j)
1956       h\_ip1 = g%mask2dT(i+1,j) * h\_in(i+1,j) + (1.0-g%mask2dT(i+1,j)) * h\_in(i,j)
1957       \textcolor{comment}{! Left/right values following Eq. B2 in Lin 1994, MWR (132)}
1958       h\_l(i,j) = 0.5*( h\_im1 + h\_in(i,j) ) + onesixth*( slp(i-1,j) - slp(i,j) )
1959       h\_r(i,j) = 0.5*( h\_ip1 + h\_in(i,j) ) + onesixth*( slp(i,j) - slp(i+1,j) )
1960 \textcolor{keywordflow}{    enddo} ;\textcolor{keywordflow}{ enddo}
1961 \textcolor{keywordflow}{  endif}
1962 
1963   \textcolor{keywordflow}{if} (local\_open\_bc) \textcolor{keywordflow}{then}
1964     \textcolor{keywordflow}{do} n=1, obc%number\_of\_segments
1965       segment => obc%segment(n)
1966       \textcolor{keywordflow}{if} (.not. segment%on\_pe) cycle
1967       \textcolor{keywordflow}{if} (segment%direction == obc\_direction\_e) \textcolor{keywordflow}{then}
1968         i=segment%HI%IsdB
1969         \textcolor{keywordflow}{do} j=segment%HI%jsd,segment%HI%jed
1970           h\_l(i+1,j) = h\_in(i,j)
1971           h\_r(i+1,j) = h\_in(i,j)
1972           h\_l(i,j) = h\_in(i,j)
1973           h\_r(i,j) = h\_in(i,j)
1974 \textcolor{keywordflow}{        enddo}
1975       \textcolor{keywordflow}{elseif} (segment%direction == obc\_direction\_w) \textcolor{keywordflow}{then}
1976         i=segment%HI%IsdB
1977         \textcolor{keywordflow}{do} j=segment%HI%jsd,segment%HI%jed
1978           h\_l(i,j) = h\_in(i+1,j)
1979           h\_r(i,j) = h\_in(i+1,j)
1980           h\_l(i+1,j) = h\_in(i+1,j)
1981           h\_r(i+1,j) = h\_in(i+1,j)
1982 \textcolor{keywordflow}{        enddo}
1983 \textcolor{keywordflow}{      endif}
1984 \textcolor{keywordflow}{    enddo}
1985 \textcolor{keywordflow}{  endif}
1986 
1987   \textcolor{keywordflow}{if} (use\_cw84) \textcolor{keywordflow}{then}
1988     \textcolor{keyword}{call }ppm\_limit\_cw84(h\_in, h\_l, h\_r, g, isl, iel, jsl, jel)
1989   \textcolor{keywordflow}{else}
1990     \textcolor{keyword}{call }ppm\_limit\_pos(h\_in, h\_l, h\_r, h\_min, g, isl, iel, jsl, jel)
1991 \textcolor{keywordflow}{  endif}
1992 
1993   \textcolor{keywordflow}{return}
\end{DoxyCode}
\mbox{\Hypertarget{namespacemom__continuity__ppm_af71fa5f7f4b849ec735e2049df2d0693}\label{namespacemom__continuity__ppm_af71fa5f7f4b849ec735e2049df2d0693}} 
\index{mom\+\_\+continuity\+\_\+ppm@{mom\+\_\+continuity\+\_\+ppm}!ppm\+\_\+reconstruction\+\_\+y@{ppm\+\_\+reconstruction\+\_\+y}}
\index{ppm\+\_\+reconstruction\+\_\+y@{ppm\+\_\+reconstruction\+\_\+y}!mom\+\_\+continuity\+\_\+ppm@{mom\+\_\+continuity\+\_\+ppm}}
\subsubsection{\texorpdfstring{ppm\+\_\+reconstruction\+\_\+y()}{ppm\_reconstruction\_y()}}
{\footnotesize\ttfamily subroutine mom\+\_\+continuity\+\_\+ppm\+::ppm\+\_\+reconstruction\+\_\+y (\begin{DoxyParamCaption}\item[{real, dimension( g \%isd\+: g \%ied, g \%jsd\+: g \%jed), intent(in)}]{h\+\_\+in,  }\item[{real, dimension( g \%isd\+: g \%ied, g \%jsd\+: g \%jed), intent(out)}]{h\+\_\+L,  }\item[{real, dimension( g \%isd\+: g \%ied, g \%jsd\+: g \%jed), intent(out)}]{h\+\_\+R,  }\item[{type(ocean\+\_\+grid\+\_\+type), intent(in)}]{G,  }\item[{type(\mbox{\hyperlink{structmom__continuity__ppm_1_1loop__bounds__type}{loop\+\_\+bounds\+\_\+type}}), intent(in)}]{LB,  }\item[{real, intent(in)}]{h\+\_\+min,  }\item[{logical, intent(in), optional}]{monotonic,  }\item[{logical, intent(in), optional}]{simple\+\_\+2nd,  }\item[{type(ocean\+\_\+obc\+\_\+type), optional, pointer}]{O\+BC }\end{DoxyParamCaption})\hspace{0.3cm}{\ttfamily [private]}}



Calculates left/right edge values for P\+PM reconstruction. 


\begin{DoxyParams}[1]{Parameters}
\mbox{\tt in}  & {\em g} & Ocean\textquotesingle{}s grid structure.\\
\hline
\mbox{\tt in}  & {\em h\+\_\+in} & Layer thickness \mbox{[}H $\sim$$>$ m or kg m-\/2\mbox{]}.\\
\hline
\mbox{\tt out}  & {\em h\+\_\+l} & Left thickness in the reconstruction, \mbox{[}H $\sim$$>$ m or kg m-\/2\mbox{]}.\\
\hline
\mbox{\tt out}  & {\em h\+\_\+r} & Right thickness in the reconstruction, \mbox{[}H $\sim$$>$ m or kg m-\/2\mbox{]}.\\
\hline
\mbox{\tt in}  & {\em lb} & Active loop bounds structure.\\
\hline
\mbox{\tt in}  & {\em h\+\_\+min} & The minimum thickness that can be obtained by a concave parabolic fit.\\
\hline
\mbox{\tt in}  & {\em monotonic} & If true, use the Colella \& Woodward monotonic limiter. Otherwise use a simple positive-\/definite limiter.\\
\hline
\mbox{\tt in}  & {\em simple\+\_\+2nd} & If true, use the arithmetic mean thicknesses as the default edge values for a simple 2nd order scheme.\\
\hline
 & {\em obc} & Open boundaries control structure. \\
\hline
\end{DoxyParams}


Definition at line 1998 of file M\+O\+M\+\_\+continuity\+\_\+\+P\+P\+M.\+F90.


\begin{DoxyCode}
1998   \textcolor{keywordtype}{type}(ocean\_grid\_type),             \textcolor{keywordtype}{intent(in)}  :: G\textcolor{comment}{    !< Ocean's grid structure.}
1999   \textcolor{keywordtype}{real}, \textcolor{keywordtype}{dimension(SZI\_(G),SZJ\_(G))},  \textcolor{keywordtype}{intent(in)}  :: h\_in\textcolor{comment}{ !< Layer thickness [H ~> m or kg m-2].}
2000   \textcolor{keywordtype}{real}, \textcolor{keywordtype}{dimension(SZI\_(G),SZJ\_(G))},  \textcolor{keywordtype}{intent(out)} :: h\_L\textcolor{comment}{  !< Left thickness in the reconstruction,}
2001 \textcolor{comment}{                                                         !! [H ~> m or kg m-2].}
2002   \textcolor{keywordtype}{real}, \textcolor{keywordtype}{dimension(SZI\_(G),SZJ\_(G))},  \textcolor{keywordtype}{intent(out)} :: h\_R\textcolor{comment}{  !< Right thickness in the reconstruction,}
2003 \textcolor{comment}{                                                         !! [H ~> m or kg m-2].}
2004   \textcolor{keywordtype}{type}(loop\_bounds\_type),            \textcolor{keywordtype}{intent(in)}  :: LB\textcolor{comment}{   !< Active loop bounds structure.}
2005   \textcolor{keywordtype}{real},                              \textcolor{keywordtype}{intent(in)}  :: h\_min\textcolor{comment}{ !< The minimum thickness}
2006 \textcolor{comment}{                    !! that can be obtained by a concave parabolic fit.}
2007   \textcolor{keywordtype}{logical}, \textcolor{keywordtype}{optional},                 \textcolor{keywordtype}{intent(in)}  :: monotonic\textcolor{comment}{ !< If true, use the}
2008 \textcolor{comment}{                    !! Colella & Woodward monotonic limiter.}
2009 \textcolor{comment}{                    !! Otherwise use a simple positive-definite limiter.}
2010   \textcolor{keywordtype}{logical}, \textcolor{keywordtype}{optional},                 \textcolor{keywordtype}{intent(in)}  :: simple\_2nd\textcolor{comment}{ !< If true, use the}
2011 \textcolor{comment}{                    !! arithmetic mean thicknesses as the default edge values}
2012 \textcolor{comment}{                    !! for a simple 2nd order scheme.}
2013   \textcolor{keywordtype}{type}(ocean\_OBC\_type),    \textcolor{keywordtype}{optional}, \textcolor{keywordtype}{pointer}     :: OBC\textcolor{comment}{ !< Open boundaries control structure.}
2014 
2015   \textcolor{comment}{! Local variables with useful mnemonic names.}
2016   \textcolor{keywordtype}{real}, \textcolor{keywordtype}{dimension(SZI\_(G),SZJ\_(G))}  :: slp \textcolor{comment}{! The slopes.}
2017   \textcolor{keywordtype}{real}, \textcolor{keywordtype}{parameter} :: oneSixth = 1./6.
2018   \textcolor{keywordtype}{real} :: h\_jp1, h\_jm1
2019   \textcolor{keywordtype}{real} :: dMx, dMn
2020   \textcolor{keywordtype}{logical} :: use\_CW84, use\_2nd
2021   \textcolor{keywordtype}{character(len=256)} :: mesg
2022   \textcolor{keywordtype}{integer} :: i, j, isl, iel, jsl, jel, n, stencil
2023   \textcolor{keywordtype}{logical} :: local\_open\_BC
2024   \textcolor{keywordtype}{type}(OBC\_segment\_type), \textcolor{keywordtype}{pointer} :: segment => null()
2025 
2026   use\_cw84 = .false. ; \textcolor{keywordflow}{if} (\textcolor{keyword}{present}(monotonic)) use\_cw84 = monotonic
2027   use\_2nd = .false. ; \textcolor{keywordflow}{if} (\textcolor{keyword}{present}(simple\_2nd)) use\_2nd = simple\_2nd
2028 
2029   local\_open\_bc = .false.
2030   \textcolor{keywordflow}{if} (\textcolor{keyword}{present}(obc)) \textcolor{keywordflow}{then} ; \textcolor{keywordflow}{if} (\textcolor{keyword}{associated}(obc)) \textcolor{keywordflow}{then}
2031     local\_open\_bc = obc%open\_v\_BCs\_exist\_globally
2032 \textcolor{keywordflow}{  endif} ;\textcolor{keywordflow}{ endif}
2033 
2034   isl = lb%ish ; iel = lb%ieh ; jsl = lb%jsh-1 ; jel = lb%jeh+1
2035 
2036   \textcolor{comment}{! This is the stencil of the reconstruction, not the scheme overall.}
2037   stencil = 2 ; \textcolor{keywordflow}{if} (use\_2nd) stencil = 1
2038 
2039   \textcolor{keywordflow}{if} ((isl < g%isd) .or. (iel > g%ied)) \textcolor{keywordflow}{then}
2040     \textcolor{keyword}{write}(mesg,\textcolor{stringliteral}{'("In MOM\_continuity\_PPM, PPM\_reconstruction\_y called with a ", &}
2041 \textcolor{stringliteral}{}\textcolor{stringliteral}{               & "x-halo that needs to be increased by ",i2,".")'}) &
2042                max(g%isd-isl,iel-g%ied)
2043     \textcolor{keyword}{call }mom\_error(fatal,mesg)
2044 \textcolor{keywordflow}{  endif}
2045   \textcolor{keywordflow}{if} ((jsl-stencil < g%jsd) .or. (jel+stencil > g%jed)) \textcolor{keywordflow}{then}
2046     \textcolor{keyword}{write}(mesg,\textcolor{stringliteral}{'("In MOM\_continuity\_PPM, PPM\_reconstruction\_y called with a ", &}
2047 \textcolor{stringliteral}{}\textcolor{stringliteral}{                 & "y-halo that needs to be increased by ",i2,".")'}) &
2048                  stencil + max(g%jsd-jsl,jel-g%jed)
2049     \textcolor{keyword}{call }mom\_error(fatal,mesg)
2050 \textcolor{keywordflow}{  endif}
2051 
2052   \textcolor{keywordflow}{if} (use\_2nd) \textcolor{keywordflow}{then}
2053     \textcolor{keywordflow}{do} j=jsl,jel ; \textcolor{keywordflow}{do} i=isl,iel
2054       h\_jm1 = g%mask2dT(i,j-1) * h\_in(i,j-1) + (1.0-g%mask2dT(i,j-1)) * h\_in(i,j)
2055       h\_jp1 = g%mask2dT(i,j+1) * h\_in(i,j+1) + (1.0-g%mask2dT(i,j+1)) * h\_in(i,j)
2056       h\_l(i,j) = 0.5*( h\_jm1 + h\_in(i,j) )
2057       h\_r(i,j) = 0.5*( h\_jp1 + h\_in(i,j) )
2058 \textcolor{keywordflow}{    enddo} ;\textcolor{keywordflow}{ enddo}
2059   \textcolor{keywordflow}{else}
2060     \textcolor{keywordflow}{do} j=jsl-1,jel+1 ; \textcolor{keywordflow}{do} i=isl,iel
2061       \textcolor{keywordflow}{if} ((g%mask2dT(i,j-1) * g%mask2dT(i,j) * g%mask2dT(i,j+1)) == 0.0) \textcolor{keywordflow}{then}
2062         slp(i,j) = 0.0
2063       \textcolor{keywordflow}{else}
2064         \textcolor{comment}{! This uses a simple 2nd order slope.}
2065         slp(i,j) = 0.5 * (h\_in(i,j+1) - h\_in(i,j-1))
2066         \textcolor{comment}{! Monotonic constraint, see Eq. B2 in Lin 1994, MWR (132)}
2067         dmx = max(h\_in(i,j+1), h\_in(i,j-1), h\_in(i,j)) - h\_in(i,j)
2068         dmn = h\_in(i,j) - min(h\_in(i,j+1), h\_in(i,j-1), h\_in(i,j))
2069         slp(i,j) = sign(1.,slp(i,j)) * min(abs(slp(i,j)), 2. * min(dmx, dmn))
2070                 \textcolor{comment}{! * (G%mask2dT(i,j-1) * G%mask2dT(i,j) * G%mask2dT(i,j+1))}
2071 \textcolor{keywordflow}{      endif}
2072 \textcolor{keywordflow}{    enddo} ;\textcolor{keywordflow}{ enddo}
2073 
2074     \textcolor{keywordflow}{if} (local\_open\_bc) \textcolor{keywordflow}{then}
2075       \textcolor{keywordflow}{do} n=1, obc%number\_of\_segments
2076         segment => obc%segment(n)
2077         \textcolor{keywordflow}{if} (.not. segment%on\_pe) cycle
2078         \textcolor{keywordflow}{if} (segment%direction == obc\_direction\_s .or. &
2079             segment%direction == obc\_direction\_n) \textcolor{keywordflow}{then}
2080           j=segment%HI%JsdB
2081           \textcolor{keywordflow}{do} i=segment%HI%isd,segment%HI%ied
2082             slp(i,j+1) = 0.0
2083             slp(i,j) = 0.0
2084 \textcolor{keywordflow}{          enddo}
2085 \textcolor{keywordflow}{        endif}
2086 \textcolor{keywordflow}{      enddo}
2087 \textcolor{keywordflow}{    endif}
2088 
2089     \textcolor{keywordflow}{do} j=jsl,jel ; \textcolor{keywordflow}{do} i=isl,iel
2090       \textcolor{comment}{! Neighboring values should take into account any boundaries.  The 3}
2091       \textcolor{comment}{! following sets of expressions are equivalent.}
2092       h\_jm1 = g%mask2dT(i,j-1) * h\_in(i,j-1) + (1.0-g%mask2dT(i,j-1)) * h\_in(i,j)
2093       h\_jp1 = g%mask2dT(i,j+1) * h\_in(i,j+1) + (1.0-g%mask2dT(i,j+1)) * h\_in(i,j)
2094       \textcolor{comment}{! Left/right values following Eq. B2 in Lin 1994, MWR (132)}
2095       h\_l(i,j) = 0.5*( h\_jm1 + h\_in(i,j) ) + onesixth*( slp(i,j-1) - slp(i,j) )
2096       h\_r(i,j) = 0.5*( h\_jp1 + h\_in(i,j) ) + onesixth*( slp(i,j) - slp(i,j+1) )
2097 \textcolor{keywordflow}{    enddo} ;\textcolor{keywordflow}{ enddo}
2098 \textcolor{keywordflow}{  endif}
2099 
2100   \textcolor{keywordflow}{if} (local\_open\_bc) \textcolor{keywordflow}{then}
2101     \textcolor{keywordflow}{do} n=1, obc%number\_of\_segments
2102       segment => obc%segment(n)
2103       \textcolor{keywordflow}{if} (.not. segment%on\_pe) cycle
2104       \textcolor{keywordflow}{if} (segment%direction == obc\_direction\_n) \textcolor{keywordflow}{then}
2105         j=segment%HI%JsdB
2106         \textcolor{keywordflow}{do} i=segment%HI%isd,segment%HI%ied
2107           h\_l(i,j+1) = h\_in(i,j)
2108           h\_r(i,j+1) = h\_in(i,j)
2109           h\_l(i,j) = h\_in(i,j)
2110           h\_r(i,j) = h\_in(i,j)
2111 \textcolor{keywordflow}{        enddo}
2112       \textcolor{keywordflow}{elseif} (segment%direction == obc\_direction\_s) \textcolor{keywordflow}{then}
2113         j=segment%HI%JsdB
2114         \textcolor{keywordflow}{do} i=segment%HI%isd,segment%HI%ied
2115           h\_l(i,j) = h\_in(i,j+1)
2116           h\_r(i,j) = h\_in(i,j+1)
2117           h\_l(i,j+1) = h\_in(i,j+1)
2118           h\_r(i,j+1) = h\_in(i,j+1)
2119 \textcolor{keywordflow}{        enddo}
2120 \textcolor{keywordflow}{      endif}
2121 \textcolor{keywordflow}{    enddo}
2122 \textcolor{keywordflow}{  endif}
2123 
2124   \textcolor{keywordflow}{if} (use\_cw84) \textcolor{keywordflow}{then}
2125     \textcolor{keyword}{call }ppm\_limit\_cw84(h\_in, h\_l, h\_r, g, isl, iel, jsl, jel)
2126   \textcolor{keywordflow}{else}
2127     \textcolor{keyword}{call }ppm\_limit\_pos(h\_in, h\_l, h\_r, h\_min, g, isl, iel, jsl, jel)
2128 \textcolor{keywordflow}{  endif}
2129 
2130   \textcolor{keywordflow}{return}
\end{DoxyCode}
\mbox{\Hypertarget{namespacemom__continuity__ppm_adf02002cf5951d7610b8643d2d401585}\label{namespacemom__continuity__ppm_adf02002cf5951d7610b8643d2d401585}} 
\index{mom\+\_\+continuity\+\_\+ppm@{mom\+\_\+continuity\+\_\+ppm}!ratio\+\_\+max@{ratio\+\_\+max}}
\index{ratio\+\_\+max@{ratio\+\_\+max}!mom\+\_\+continuity\+\_\+ppm@{mom\+\_\+continuity\+\_\+ppm}}
\subsubsection{\texorpdfstring{ratio\+\_\+max()}{ratio\_max()}}
{\footnotesize\ttfamily real function mom\+\_\+continuity\+\_\+ppm\+::ratio\+\_\+max (\begin{DoxyParamCaption}\item[{real, intent(in)}]{a,  }\item[{real, intent(in)}]{b,  }\item[{real, intent(in)}]{maxrat }\end{DoxyParamCaption})\hspace{0.3cm}{\ttfamily [private]}}



Return the maximum ratio of a/b or maxrat. 


\begin{DoxyParams}[1]{Parameters}
\mbox{\tt in}  & {\em a} & Numerator\\
\hline
\mbox{\tt in}  & {\em b} & Denominator\\
\hline
\mbox{\tt in}  & {\em maxrat} & Maximum value of ratio.\\
\hline
\end{DoxyParams}
\begin{DoxyReturn}{Returns}
Return value. 
\end{DoxyReturn}


Definition at line 2216 of file M\+O\+M\+\_\+continuity\+\_\+\+P\+P\+M.\+F90.


\begin{DoxyCode}
2216   \textcolor{keywordtype}{real}, \textcolor{keywordtype}{intent(in)} :: a\textcolor{comment}{       !< Numerator}
2217   \textcolor{keywordtype}{real}, \textcolor{keywordtype}{intent(in)} :: b\textcolor{comment}{       !< Denominator}
2218   \textcolor{keywordtype}{real}, \textcolor{keywordtype}{intent(in)} :: maxrat\textcolor{comment}{  !< Maximum value of ratio.}
2219   \textcolor{keywordtype}{real} :: ratio\textcolor{comment}{               !< Return value.}
2220 
2221   \textcolor{keywordflow}{if} (abs(a) > abs(maxrat*b)) \textcolor{keywordflow}{then}
2222     ratio = maxrat
2223   \textcolor{keywordflow}{else}
2224     ratio = a / b
2225 \textcolor{keywordflow}{  endif}
\end{DoxyCode}
\mbox{\Hypertarget{namespacemom__continuity__ppm_a77c6806e82a3634fff7b7480f77c2f02}\label{namespacemom__continuity__ppm_a77c6806e82a3634fff7b7480f77c2f02}} 
\index{mom\+\_\+continuity\+\_\+ppm@{mom\+\_\+continuity\+\_\+ppm}!set\+\_\+merid\+\_\+bt\+\_\+cont@{set\+\_\+merid\+\_\+bt\+\_\+cont}}
\index{set\+\_\+merid\+\_\+bt\+\_\+cont@{set\+\_\+merid\+\_\+bt\+\_\+cont}!mom\+\_\+continuity\+\_\+ppm@{mom\+\_\+continuity\+\_\+ppm}}
\subsubsection{\texorpdfstring{set\+\_\+merid\+\_\+bt\+\_\+cont()}{set\_merid\_bt\_cont()}}
{\footnotesize\ttfamily subroutine mom\+\_\+continuity\+\_\+ppm\+::set\+\_\+merid\+\_\+bt\+\_\+cont (\begin{DoxyParamCaption}\item[{real, dimension(szi\+\_\+(g),szjb\+\_\+(g),szk\+\_\+(g)), intent(in)}]{v,  }\item[{real, dimension(szi\+\_\+(g),szj\+\_\+(g),szk\+\_\+(g)), intent(in)}]{h\+\_\+in,  }\item[{real, dimension(szi\+\_\+(g),szj\+\_\+(g),szk\+\_\+(g)), intent(in)}]{h\+\_\+L,  }\item[{real, dimension(szi\+\_\+(g),szj\+\_\+(g),szk\+\_\+(g)), intent(in)}]{h\+\_\+R,  }\item[{type(bt\+\_\+cont\+\_\+type), intent(inout)}]{B\+T\+\_\+cont,  }\item[{real, dimension(szi\+\_\+(g)), intent(in)}]{vh\+\_\+tot\+\_\+0,  }\item[{real, dimension(szi\+\_\+(g)), intent(in)}]{dvhdv\+\_\+tot\+\_\+0,  }\item[{real, dimension(szi\+\_\+(g)), intent(in)}]{dv\+\_\+max\+\_\+\+C\+FL,  }\item[{real, dimension(szi\+\_\+(g)), intent(in)}]{dv\+\_\+min\+\_\+\+C\+FL,  }\item[{real, intent(in)}]{dt,  }\item[{type(ocean\+\_\+grid\+\_\+type), intent(inout)}]{G,  }\item[{type(unit\+\_\+scale\+\_\+type), intent(in)}]{US,  }\item[{type(\mbox{\hyperlink{structmom__continuity__ppm_1_1continuity__ppm__cs}{continuity\+\_\+ppm\+\_\+cs}}), pointer}]{CS,  }\item[{real, dimension( g \%isd\+: g \%ied, g \%ke), intent(in)}]{visc\+\_\+rem,  }\item[{real, dimension(szi\+\_\+(g)), intent(in)}]{visc\+\_\+rem\+\_\+max,  }\item[{integer, intent(in)}]{j,  }\item[{integer, intent(in)}]{ish,  }\item[{integer, intent(in)}]{ieh,  }\item[{logical, dimension(szi\+\_\+(g)), intent(in)}]{do\+\_\+I }\end{DoxyParamCaption})\hspace{0.3cm}{\ttfamily [private]}}



Sets of a structure that describes the meridional barotropic volume or mass fluxes as a function of barotropic flow to agree closely with the sum of the layer\textquotesingle{}s transports. 


\begin{DoxyParams}[1]{Parameters}
\mbox{\tt in,out}  & {\em g} & Ocean\textquotesingle{}s grid structure.\\
\hline
\mbox{\tt in}  & {\em v} & Meridional velocity \mbox{[}L T-\/1 $\sim$$>$ m s-\/1\mbox{]}.\\
\hline
\mbox{\tt in}  & {\em h\+\_\+in} & Layer thickness used to calculate fluxes, \mbox{[}H $\sim$$>$ m or kg m-\/2\mbox{]}.\\
\hline
\mbox{\tt in}  & {\em h\+\_\+l} & Left thickness in the reconstruction, \mbox{[}H $\sim$$>$ m or kg m-\/2\mbox{]}.\\
\hline
\mbox{\tt in}  & {\em h\+\_\+r} & Right thickness in the reconstruction, \mbox{[}H $\sim$$>$ m or kg m-\/2\mbox{]}.\\
\hline
\mbox{\tt in,out}  & {\em bt\+\_\+cont} & A structure with elements that describe the effective open face areas as a function of barotropic flow.\\
\hline
\mbox{\tt in}  & {\em vh\+\_\+tot\+\_\+0} & The summed transport with 0 adjustment \mbox{[}H L2 T-\/1 $\sim$$>$ m3 s-\/1 or kg s-\/1\mbox{]}.\\
\hline
\mbox{\tt in}  & {\em dvhdv\+\_\+tot\+\_\+0} & The partial derivative of du\+\_\+err with dv at 0 adjustment \mbox{[}H L $\sim$$>$ m2 or kg m-\/1\mbox{]}.\\
\hline
\mbox{\tt in}  & {\em dv\+\_\+max\+\_\+cfl} & Maximum acceptable value of dv \mbox{[}L T-\/1 $\sim$$>$ m s-\/1\mbox{]}.\\
\hline
\mbox{\tt in}  & {\em dv\+\_\+min\+\_\+cfl} & Minimum acceptable value of dv \mbox{[}L T-\/1 $\sim$$>$ m s-\/1\mbox{]}.\\
\hline
\mbox{\tt in}  & {\em dt} & Time increment \mbox{[}T $\sim$$>$ s\mbox{]}.\\
\hline
\mbox{\tt in}  & {\em us} & A dimensional unit scaling type\\
\hline
 & {\em cs} & This module\textquotesingle{}s control structure.\\
\hline
\mbox{\tt in}  & {\em visc\+\_\+rem} & Both the fraction of the momentum originally in a layer that remains after a time-\/step of viscosity, and the fraction of a time-\/step\textquotesingle{}s worth of a barotropic acceleration that a layer experiences after viscosity is applied. Non-\/dimensional between 0 (at the bottom) and 1 (far above the bottom).\\
\hline
\mbox{\tt in}  & {\em visc\+\_\+rem\+\_\+max} & Maximum allowable visc\+\_\+rem.\\
\hline
\mbox{\tt in}  & {\em j} & Spatial index.\\
\hline
\mbox{\tt in}  & {\em ish} & Start of index range.\\
\hline
\mbox{\tt in}  & {\em ieh} & End of index range.\\
\hline
\mbox{\tt in}  & {\em do\+\_\+i} & A logical flag indicating which I values to work on. \\
\hline
\end{DoxyParams}


Definition at line 1700 of file M\+O\+M\+\_\+continuity\+\_\+\+P\+P\+M.\+F90.


\begin{DoxyCode}
1700   \textcolor{keywordtype}{type}(ocean\_grid\_type),                     \textcolor{keywordtype}{intent(inout)} :: G\textcolor{comment}{    !< Ocean's grid structure.}
1701   \textcolor{keywordtype}{real}, \textcolor{keywordtype}{dimension(SZI\_(G),SZJB\_(G),SZK\_(G))}, \textcolor{keywordtype}{intent(in)}    :: v\textcolor{comment}{    !< Meridional velocity [L T-1 ~> m s-1].}
1702   \textcolor{keywordtype}{real}, \textcolor{keywordtype}{dimension(SZI\_(G),SZJ\_(G),SZK\_(G))},  \textcolor{keywordtype}{intent(in)}    :: h\_in\textcolor{comment}{ !< Layer thickness used to calculate
       fluxes,}
1703 \textcolor{comment}{                                                                   !! [H ~> m or kg m-2].}
1704   \textcolor{keywordtype}{real}, \textcolor{keywordtype}{dimension(SZI\_(G),SZJ\_(G),SZK\_(G))},  \textcolor{keywordtype}{intent(in)}    :: h\_L\textcolor{comment}{  !< Left thickness in the reconstruction,}
1705 \textcolor{comment}{                                                                   !! [H ~> m or kg m-2].}
1706   \textcolor{keywordtype}{real}, \textcolor{keywordtype}{dimension(SZI\_(G),SZJ\_(G),SZK\_(G))},  \textcolor{keywordtype}{intent(in)}    :: h\_R\textcolor{comment}{  !< Right thickness in the
       reconstruction,}
1707 \textcolor{comment}{                                                                   !! [H ~> m or kg m-2].}
1708   \textcolor{keywordtype}{type}(BT\_cont\_type),                        \textcolor{keywordtype}{intent(inout)} :: BT\_cont\textcolor{comment}{ !< A structure with elements}
1709 \textcolor{comment}{                       !! that describe the effective open face areas as a function of barotropic flow.}
1710   \textcolor{keywordtype}{real}, \textcolor{keywordtype}{dimension(SZI\_(G))},                  \textcolor{keywordtype}{intent(in)}    :: vh\_tot\_0\textcolor{comment}{    !< The summed transport}
1711 \textcolor{comment}{                       !! with 0 adjustment [H L2 T-1 ~> m3 s-1 or kg s-1].}
1712   \textcolor{keywordtype}{real}, \textcolor{keywordtype}{dimension(SZI\_(G))},                  \textcolor{keywordtype}{intent(in)}    :: dvhdv\_tot\_0\textcolor{comment}{ !< The partial derivative}
1713 \textcolor{comment}{                       !! of du\_err with dv at 0 adjustment [H L ~> m2 or kg m-1].}
1714   \textcolor{keywordtype}{real}, \textcolor{keywordtype}{dimension(SZI\_(G))},                  \textcolor{keywordtype}{intent(in)}    :: dv\_max\_CFL\textcolor{comment}{ !< Maximum acceptable value}
1715 \textcolor{comment}{                                                                   !!  of dv [L T-1 ~> m s-1].}
1716   \textcolor{keywordtype}{real}, \textcolor{keywordtype}{dimension(SZI\_(G))},                  \textcolor{keywordtype}{intent(in)}    :: dv\_min\_CFL\textcolor{comment}{ !< Minimum acceptable value}
1717 \textcolor{comment}{                                                                   !!  of dv [L T-1 ~> m s-1].}
1718   \textcolor{keywordtype}{real},                                      \textcolor{keywordtype}{intent(in)}    :: dt\textcolor{comment}{   !< Time increment [T ~> s].}
1719   \textcolor{keywordtype}{type}(unit\_scale\_type),                     \textcolor{keywordtype}{intent(in)}    :: US\textcolor{comment}{   !< A dimensional unit scaling type}
1720   \textcolor{keywordtype}{type}(continuity\_PPM\_CS),                   \textcolor{keywordtype}{pointer}       :: CS\textcolor{comment}{   !< This module's control structure.}
1721   \textcolor{keywordtype}{real}, \textcolor{keywordtype}{dimension(SZI\_(G),SZK\_(G))},          \textcolor{keywordtype}{intent(in)}    :: visc\_rem\textcolor{comment}{ !< Both the fraction of the}
1722 \textcolor{comment}{                       !! momentum originally in a layer that remains after a time-step}
1723 \textcolor{comment}{                       !! of viscosity, and the fraction of a time-step's worth of a barotropic}
1724 \textcolor{comment}{                       !! acceleration that a layer experiences after viscosity is applied.}
1725 \textcolor{comment}{                       !! Non-dimensional between 0 (at the bottom) and 1 (far above the bottom).}
1726   \textcolor{keywordtype}{real}, \textcolor{keywordtype}{dimension(SZI\_(G))},                  \textcolor{keywordtype}{intent(in)}    :: visc\_rem\_max\textcolor{comment}{ !< Maximum allowable visc\_rem.}
1727   \textcolor{keywordtype}{integer},                                   \textcolor{keywordtype}{intent(in)}    :: j\textcolor{comment}{        !< Spatial index.}
1728   \textcolor{keywordtype}{integer},                                   \textcolor{keywordtype}{intent(in)}    :: ish\textcolor{comment}{      !< Start of index range.}
1729   \textcolor{keywordtype}{integer},                                   \textcolor{keywordtype}{intent(in)}    :: ieh\textcolor{comment}{      !< End of index range.}
1730   \textcolor{keywordtype}{logical}, \textcolor{keywordtype}{dimension(SZI\_(G))},               \textcolor{keywordtype}{intent(in)}    :: do\_I\textcolor{comment}{     !< A logical flag indicating}
1731 \textcolor{comment}{                       !! which I values to work on.}
1732   \textcolor{comment}{! Local variables}
1733   \textcolor{keywordtype}{real}, \textcolor{keywordtype}{dimension(SZI\_(G))} :: &
1734     dv0, &        \textcolor{comment}{! The barotropic velocity increment that gives 0 transport [L T-1 ~> m s-1].}
1735     dvL, dvR, &   \textcolor{comment}{! The barotropic velocity increments that give the southerly}
1736                   \textcolor{comment}{! (dvL) and northerly (dvR) test velocities [L T-1 ~> m s-1].}
1737     zeros, &      \textcolor{comment}{! An array of full of 0's.}
1738     dv\_cfl, &     \textcolor{comment}{! The velocity increment that corresponds to CFL\_min [L T-1 ~> m s-1].}
1739     v\_l, v\_r, &   \textcolor{comment}{! The southerly (v\_L), northerly (v\_R), and zero-barotropic}
1740     v\_0, &        \textcolor{comment}{! transport (v\_0) layer test velocities [L T-1 ~> m s-1].}
1741     dvhdv\_l, &    \textcolor{comment}{! The effective layer marginal face areas with the southerly}
1742     dvhdv\_r, &    \textcolor{comment}{! (\_L), northerly (\_R), and zero-barotropic (\_0) test}
1743     dvhdv\_0, &    \textcolor{comment}{! velocities [H L ~> m2 or kg m-1].}
1744     vh\_l, vh\_r, & \textcolor{comment}{! The layer transports with the southerly (\_L), northerly (\_R)}
1745     vh\_0, &       \textcolor{comment}{! and zero-barotropic (\_0) test velocities [H L2 T-1 ~> m3 s-1 or kg s-1].}
1746     famt\_l, famt\_r, & \textcolor{comment}{! The summed effective marginal face areas for the 3}
1747     famt\_0, &     \textcolor{comment}{! test velocities [H m ~> m2 or kg m-1].}
1748     vhtot\_l, &    \textcolor{comment}{! The summed transport with the southerly (vhtot\_L) and}
1749     vhtot\_r       \textcolor{comment}{! and northerly (vhtot\_R) test velocities [H L2 T-1 ~> m3 s-1 or kg s-1].}
1750   \textcolor{keywordtype}{real} :: FA\_0    \textcolor{comment}{! The effective face area with 0 barotropic transport [H L ~> m2 or kg m-1].}
1751   \textcolor{keywordtype}{real} :: FA\_avg  \textcolor{comment}{! The average effective face area [H L ~> m2 or kg m-1], nominally given by}
1752                   \textcolor{comment}{! the realized transport divided by the barotropic velocity.}
1753   \textcolor{keywordtype}{real} :: visc\_rem\_lim \textcolor{comment}{! The larger of visc\_rem and min\_visc\_rem [nondim]  This}
1754                        \textcolor{comment}{! limiting is necessary to keep the inverse of visc\_rem}
1755                        \textcolor{comment}{! from leading to large CFL numbers.}
1756   \textcolor{keywordtype}{real} :: min\_visc\_rem \textcolor{comment}{! The smallest permitted value for visc\_rem that is used}
1757                        \textcolor{comment}{! in finding the barotropic velocity that changes the}
1758                        \textcolor{comment}{! flow direction.  This is necessary to keep the inverse}
1759                        \textcolor{comment}{! of visc\_rem from leading to large CFL numbers.}
1760   \textcolor{keywordtype}{real} :: CFL\_min \textcolor{comment}{! A minimal increment in the CFL to try to ensure that the}
1761                   \textcolor{comment}{! flow is truly upwind [nondim]}
1762   \textcolor{keywordtype}{real} :: Idt     \textcolor{comment}{! The inverse of the time step [T-1 ~> s-1].}
1763   \textcolor{keywordtype}{logical} :: domore
1764   \textcolor{keywordtype}{integer} :: i, k, nz
1765 
1766   nz = g%ke ; idt = 1.0 / dt
1767   min\_visc\_rem = 0.1 ; cfl\_min = 1e-6
1768 
1769  \textcolor{comment}{! Diagnose the zero-transport correction, dv0.}
1770   \textcolor{keywordflow}{do} i=ish,ieh ; zeros(i) = 0.0 ;\textcolor{keywordflow}{ enddo}
1771   \textcolor{keyword}{call }meridional\_flux\_adjust(v, h\_in, h\_l, h\_r, zeros, vh\_tot\_0, dvhdv\_tot\_0, dv0, &
1772                          dv\_max\_cfl, dv\_min\_cfl, dt, g, us, cs, visc\_rem, &
1773                          j, ish, ieh, do\_i, .true.)
1774 
1775   \textcolor{comment}{!   Determine the southerly- and northerly- fluxes.  Choose a sufficiently}
1776   \textcolor{comment}{! negative velocity correction for the northerly-flux, and a sufficiently}
1777   \textcolor{comment}{! positive correction for the southerly-flux.}
1778   domore = .false.
1779   \textcolor{keywordflow}{do} i=ish,ieh ; \textcolor{keywordflow}{if} (do\_i(i)) \textcolor{keywordflow}{then}
1780     domore = .true.
1781     dv\_cfl(i) = (cfl\_min * idt) * g%dyCv(i,j)
1782     dvr(i) = min(0.0,dv0(i) - dv\_cfl(i))
1783     dvl(i) = max(0.0,dv0(i) + dv\_cfl(i))
1784     famt\_l(i) = 0.0 ; famt\_r(i) = 0.0 ; famt\_0(i) = 0.0
1785     vhtot\_l(i) = 0.0 ; vhtot\_r(i) = 0.0
1786 \textcolor{keywordflow}{  endif} ;\textcolor{keywordflow}{ enddo}
1787 
1788   \textcolor{keywordflow}{if} (.not.domore) \textcolor{keywordflow}{then}
1789     \textcolor{keywordflow}{do} k=1,nz ; \textcolor{keywordflow}{do} i=ish,ieh
1790       bt\_cont%FA\_v\_S0(i,j) = 0.0 ; bt\_cont%FA\_v\_SS(i,j) = 0.0
1791       bt\_cont%vBT\_SS(i,j) = 0.0
1792       bt\_cont%FA\_v\_N0(i,j) = 0.0 ; bt\_cont%FA\_v\_NN(i,j) = 0.0
1793       bt\_cont%vBT\_NN(i,j) = 0.0
1794 \textcolor{keywordflow}{    enddo} ;\textcolor{keywordflow}{ enddo}
1795     \textcolor{keywordflow}{return}
1796 \textcolor{keywordflow}{  endif}
1797 
1798   \textcolor{keywordflow}{do} k=1,nz ; \textcolor{keywordflow}{do} i=ish,ieh ; \textcolor{keywordflow}{if} (do\_i(i)) \textcolor{keywordflow}{then}
1799     visc\_rem\_lim = max(visc\_rem(i,k), min\_visc\_rem*visc\_rem\_max(i))
1800     \textcolor{keywordflow}{if} (visc\_rem\_lim > 0.0) \textcolor{keywordflow}{then} \textcolor{comment}{! This is almost always true for ocean points.}
1801       \textcolor{keywordflow}{if} (v(i,j,k) + dvr(i)*visc\_rem\_lim > -dv\_cfl(i)*visc\_rem(i,k)) &
1802         dvr(i) = -(v(i,j,k) + dv\_cfl(i)*visc\_rem(i,k)) / visc\_rem\_lim
1803       \textcolor{keywordflow}{if} (v(i,j,k) + dvl(i)*visc\_rem\_lim < dv\_cfl(i)*visc\_rem(i,k)) &
1804         dvl(i) = -(v(i,j,k) - dv\_cfl(i)*visc\_rem(i,k)) / visc\_rem\_lim
1805 \textcolor{keywordflow}{    endif}
1806 \textcolor{keywordflow}{  endif} ;\textcolor{keywordflow}{ enddo} ;\textcolor{keywordflow}{ enddo}
1807   \textcolor{keywordflow}{do} k=1,nz
1808     \textcolor{keywordflow}{do} i=ish,ieh ; \textcolor{keywordflow}{if} (do\_i(i)) \textcolor{keywordflow}{then}
1809       v\_l(i) = v(i,j,k) + dvl(i) * visc\_rem(i,k)
1810       v\_r(i) = v(i,j,k) + dvr(i) * visc\_rem(i,k)
1811       v\_0(i) = v(i,j,k) + dv0(i) * visc\_rem(i,k)
1812 \textcolor{keywordflow}{    endif} ;\textcolor{keywordflow}{ enddo}
1813     \textcolor{keyword}{call }merid\_flux\_layer(v\_0, h\_in(:,:,k), h\_l(:,:,k), h\_r(:,:,k), vh\_0, dvhdv\_0, &
1814                           visc\_rem(:,k), dt, g, us, j, ish, ieh, do\_i, cs%vol\_CFL)
1815     \textcolor{keyword}{call }merid\_flux\_layer(v\_l, h\_in(:,:,k), h\_l(:,:,k), h\_r(:,:,k), vh\_l, dvhdv\_l, &
1816                           visc\_rem(:,k), dt, g, us, j, ish, ieh, do\_i, cs%vol\_CFL)
1817     \textcolor{keyword}{call }merid\_flux\_layer(v\_r, h\_in(:,:,k), h\_l(:,:,k), h\_r(:,:,k), vh\_r, dvhdv\_r, &
1818                           visc\_rem(:,k), dt, g, us, j, ish, ieh, do\_i, cs%vol\_CFL)
1819     \textcolor{keywordflow}{do} i=ish,ieh ; \textcolor{keywordflow}{if} (do\_i(i)) \textcolor{keywordflow}{then}
1820       famt\_0(i) = famt\_0(i) + dvhdv\_0(i)
1821       famt\_l(i) = famt\_l(i) + dvhdv\_l(i)
1822       famt\_r(i) = famt\_r(i) + dvhdv\_r(i)
1823       vhtot\_l(i) = vhtot\_l(i) + vh\_l(i)
1824       vhtot\_r(i) = vhtot\_r(i) + vh\_r(i)
1825 \textcolor{keywordflow}{    endif} ;\textcolor{keywordflow}{ enddo}
1826 \textcolor{keywordflow}{  enddo}
1827   \textcolor{keywordflow}{do} i=ish,ieh ; \textcolor{keywordflow}{if} (do\_i(i)) \textcolor{keywordflow}{then}
1828     fa\_0 = famt\_0(i) ; fa\_avg = famt\_0(i)
1829     \textcolor{keywordflow}{if} ((dvl(i) - dv0(i)) /= 0.0) &
1830       fa\_avg = vhtot\_l(i) / (dvl(i) - dv0(i))
1831     \textcolor{keywordflow}{if} (fa\_avg > max(fa\_0, famt\_l(i))) \textcolor{keywordflow}{then} ; fa\_avg = max(fa\_0, famt\_l(i))
1832     \textcolor{keywordflow}{elseif} (fa\_avg < min(fa\_0, famt\_l(i))) \textcolor{keywordflow}{then} ; fa\_0 = fa\_avg ;\textcolor{keywordflow}{ endif}
1833     bt\_cont%FA\_v\_S0(i,j) = fa\_0 ; bt\_cont%FA\_v\_SS(i,j) = famt\_l(i)
1834     \textcolor{keywordflow}{if} (abs(fa\_0-famt\_l(i)) <= 1e-12*fa\_0) \textcolor{keywordflow}{then} ; bt\_cont%vBT\_SS(i,j) = 0.0 ; \textcolor{keywordflow}{else}
1835       bt\_cont%vBT\_SS(i,j) = (1.5 * (dvl(i) - dv0(i))) * &
1836                    ((famt\_l(i) - fa\_avg) / (famt\_l(i) - fa\_0))
1837 \textcolor{keywordflow}{    endif}
1838 
1839     fa\_0 = famt\_0(i) ; fa\_avg = famt\_0(i)
1840     \textcolor{keywordflow}{if} ((dvr(i) - dv0(i)) /= 0.0) &
1841       fa\_avg = vhtot\_r(i) / (dvr(i) - dv0(i))
1842     \textcolor{keywordflow}{if} (fa\_avg > max(fa\_0, famt\_r(i))) \textcolor{keywordflow}{then} ; fa\_avg = max(fa\_0, famt\_r(i))
1843     \textcolor{keywordflow}{elseif} (fa\_avg < min(fa\_0, famt\_r(i))) \textcolor{keywordflow}{then} ; fa\_0 = fa\_avg ;\textcolor{keywordflow}{ endif}
1844     bt\_cont%FA\_v\_N0(i,j) = fa\_0 ; bt\_cont%FA\_v\_NN(i,j) = famt\_r(i)
1845     \textcolor{keywordflow}{if} (abs(famt\_r(i) - fa\_0) <= 1e-12*fa\_0) \textcolor{keywordflow}{then} ; bt\_cont%vBT\_NN(i,j) = 0.0 ; \textcolor{keywordflow}{else}
1846       bt\_cont%vBT\_NN(i,j) = (1.5 * (dvr(i) - dv0(i))) * &
1847                    ((famt\_r(i) - fa\_avg) / (famt\_r(i) - fa\_0))
1848 \textcolor{keywordflow}{    endif}
1849   \textcolor{keywordflow}{else}
1850     bt\_cont%FA\_v\_S0(i,j) = 0.0 ; bt\_cont%FA\_v\_SS(i,j) = 0.0
1851     bt\_cont%FA\_v\_N0(i,j) = 0.0 ; bt\_cont%FA\_v\_NN(i,j) = 0.0
1852     bt\_cont%vBT\_SS(i,j) = 0.0 ; bt\_cont%vBT\_NN(i,j) = 0.0
1853 \textcolor{keywordflow}{  endif} ;\textcolor{keywordflow}{ enddo}
1854 
\end{DoxyCode}
\mbox{\Hypertarget{namespacemom__continuity__ppm_a30e5aef71acbeef6afe5f6cf1ea30dcc}\label{namespacemom__continuity__ppm_a30e5aef71acbeef6afe5f6cf1ea30dcc}} 
\index{mom\+\_\+continuity\+\_\+ppm@{mom\+\_\+continuity\+\_\+ppm}!set\+\_\+zonal\+\_\+bt\+\_\+cont@{set\+\_\+zonal\+\_\+bt\+\_\+cont}}
\index{set\+\_\+zonal\+\_\+bt\+\_\+cont@{set\+\_\+zonal\+\_\+bt\+\_\+cont}!mom\+\_\+continuity\+\_\+ppm@{mom\+\_\+continuity\+\_\+ppm}}
\subsubsection{\texorpdfstring{set\+\_\+zonal\+\_\+bt\+\_\+cont()}{set\_zonal\_bt\_cont()}}
{\footnotesize\ttfamily subroutine mom\+\_\+continuity\+\_\+ppm\+::set\+\_\+zonal\+\_\+bt\+\_\+cont (\begin{DoxyParamCaption}\item[{real, dimension( g \%isdb\+: g \%iedb, g \%jsd\+: g \%jed, g \%ke), intent(in)}]{u,  }\item[{real, dimension( g \%isd\+: g \%ied, g \%jsd\+: g \%jed, g \%ke), intent(in)}]{h\+\_\+in,  }\item[{real, dimension( g \%isd\+: g \%ied, g \%jsd\+: g \%jed, g \%ke), intent(in)}]{h\+\_\+L,  }\item[{real, dimension( g \%isd\+: g \%ied, g \%jsd\+: g \%jed, g \%ke), intent(in)}]{h\+\_\+R,  }\item[{type(bt\+\_\+cont\+\_\+type), intent(inout)}]{B\+T\+\_\+cont,  }\item[{real, dimension( g \%isdb\+: g \%iedb), intent(in)}]{uh\+\_\+tot\+\_\+0,  }\item[{real, dimension( g \%isdb\+: g \%iedb), intent(in)}]{duhdu\+\_\+tot\+\_\+0,  }\item[{real, dimension( g \%isdb\+: g \%iedb), intent(in)}]{du\+\_\+max\+\_\+\+C\+FL,  }\item[{real, dimension( g \%isdb\+: g \%iedb), intent(in)}]{du\+\_\+min\+\_\+\+C\+FL,  }\item[{real, intent(in)}]{dt,  }\item[{type(ocean\+\_\+grid\+\_\+type), intent(inout)}]{G,  }\item[{type(unit\+\_\+scale\+\_\+type), intent(in)}]{US,  }\item[{type(\mbox{\hyperlink{structmom__continuity__ppm_1_1continuity__ppm__cs}{continuity\+\_\+ppm\+\_\+cs}}), pointer}]{CS,  }\item[{real, dimension(szib\+\_\+(g),szk\+\_\+(g)), intent(in)}]{visc\+\_\+rem,  }\item[{real, dimension( g \%isdb\+: g \%iedb), intent(in)}]{visc\+\_\+rem\+\_\+max,  }\item[{integer, intent(in)}]{j,  }\item[{integer, intent(in)}]{ish,  }\item[{integer, intent(in)}]{ieh,  }\item[{logical, dimension( g \%isdb\+: g \%iedb), intent(in)}]{do\+\_\+I }\end{DoxyParamCaption})\hspace{0.3cm}{\ttfamily [private]}}



Sets a structure that describes the zonal barotropic volume or mass fluxes as a function of barotropic flow to agree closely with the sum of the layer\textquotesingle{}s transports. 


\begin{DoxyParams}[1]{Parameters}
\mbox{\tt in,out}  & {\em g} & Ocean\textquotesingle{}s grid structure.\\
\hline
\mbox{\tt in}  & {\em u} & Zonal velocity \mbox{[}L T-\/1 $\sim$$>$ m s-\/1\mbox{]}.\\
\hline
\mbox{\tt in}  & {\em h\+\_\+in} & Layer thickness used to calculate fluxes \mbox{[}H $\sim$$>$ m or kg m-\/2\mbox{]}.\\
\hline
\mbox{\tt in}  & {\em h\+\_\+l} & Left thickness in the reconstruction \mbox{[}H $\sim$$>$ m or kg m-\/2\mbox{]}.\\
\hline
\mbox{\tt in}  & {\em h\+\_\+r} & Right thickness in the reconstruction \mbox{[}H $\sim$$>$ m or kg m-\/2\mbox{]}.\\
\hline
\mbox{\tt in,out}  & {\em bt\+\_\+cont} & A structure with elements that describe the effective open face areas as a function of barotropic flow.\\
\hline
\mbox{\tt in}  & {\em uh\+\_\+tot\+\_\+0} & The summed transport with 0 adjustment \mbox{[}H L2 T-\/1 $\sim$$>$ m3 s-\/1 or kg s-\/1\mbox{]}.\\
\hline
\mbox{\tt in}  & {\em duhdu\+\_\+tot\+\_\+0} & The partial derivative of du\+\_\+err with du at 0 adjustment \mbox{[}H L $\sim$$>$ m2 or kg m-\/1\mbox{]}.\\
\hline
\mbox{\tt in}  & {\em du\+\_\+max\+\_\+cfl} & Maximum acceptable value of du \mbox{[}L T-\/1 $\sim$$>$ m s-\/1\mbox{]}.\\
\hline
\mbox{\tt in}  & {\em du\+\_\+min\+\_\+cfl} & Minimum acceptable value of du \mbox{[}L T-\/1 $\sim$$>$ m s-\/1\mbox{]}.\\
\hline
\mbox{\tt in}  & {\em dt} & Time increment \mbox{[}T $\sim$$>$ s\mbox{]}.\\
\hline
\mbox{\tt in}  & {\em us} & A dimensional unit scaling type\\
\hline
 & {\em cs} & This module\textquotesingle{}s control structure.\\
\hline
\mbox{\tt in}  & {\em visc\+\_\+rem} & Both the fraction of the momentum originally in a layer that remains after a time-\/step of viscosity, and the fraction of a time-\/step\textquotesingle{}s worth of a barotropic acceleration that a layer experiences after viscosity is applied. Non-\/dimensional between 0 (at the bottom) and 1 (far above the bottom).\\
\hline
\mbox{\tt in}  & {\em visc\+\_\+rem\+\_\+max} & Maximum allowable visc\+\_\+rem.\\
\hline
\mbox{\tt in}  & {\em j} & Spatial index.\\
\hline
\mbox{\tt in}  & {\em ish} & Start of index range.\\
\hline
\mbox{\tt in}  & {\em ieh} & End of index range.\\
\hline
\mbox{\tt in}  & {\em do\+\_\+i} & A logical flag indicating which I values to work on. \\
\hline
\end{DoxyParams}


Definition at line 877 of file M\+O\+M\+\_\+continuity\+\_\+\+P\+P\+M.\+F90.


\begin{DoxyCode}
877   \textcolor{keywordtype}{type}(ocean\_grid\_type),                     \textcolor{keywordtype}{intent(inout)} :: G\textcolor{comment}{    !< Ocean's grid structure.}
878   \textcolor{keywordtype}{real}, \textcolor{keywordtype}{dimension(SZIB\_(G),SZJ\_(G),SZK\_(G))}, \textcolor{keywordtype}{intent(in)}    :: u\textcolor{comment}{    !< Zonal velocity [L T-1 ~> m s-1].}
879   \textcolor{keywordtype}{real}, \textcolor{keywordtype}{dimension(SZI\_(G),SZJ\_(G),SZK\_(G))},  \textcolor{keywordtype}{intent(in)}    :: h\_in\textcolor{comment}{ !< Layer thickness used to}
880 \textcolor{comment}{                                                                   !! calculate fluxes [H ~> m or kg m-2].}
881   \textcolor{keywordtype}{real}, \textcolor{keywordtype}{dimension(SZI\_(G),SZJ\_(G),SZK\_(G))},  \textcolor{keywordtype}{intent(in)}    :: h\_L\textcolor{comment}{  !< Left thickness in the}
882 \textcolor{comment}{                                                                   !! reconstruction [H ~> m or kg m-2].}
883   \textcolor{keywordtype}{real}, \textcolor{keywordtype}{dimension(SZI\_(G),SZJ\_(G),SZK\_(G))},  \textcolor{keywordtype}{intent(in)}    :: h\_R\textcolor{comment}{  !< Right thickness in the}
884 \textcolor{comment}{                                                                   !! reconstruction [H ~> m or kg m-2].}
885   \textcolor{keywordtype}{type}(BT\_cont\_type),                        \textcolor{keywordtype}{intent(inout)} :: BT\_cont\textcolor{comment}{ !< A structure with elements}
886 \textcolor{comment}{                       !! that describe the effective open face areas as a function of barotropic flow.}
887   \textcolor{keywordtype}{real}, \textcolor{keywordtype}{dimension(SZIB\_(G))},                 \textcolor{keywordtype}{intent(in)}    :: uh\_tot\_0\textcolor{comment}{    !< The summed transport}
888 \textcolor{comment}{                       !! with 0 adjustment [H L2 T-1 ~> m3 s-1 or kg s-1].}
889   \textcolor{keywordtype}{real}, \textcolor{keywordtype}{dimension(SZIB\_(G))},                 \textcolor{keywordtype}{intent(in)}    :: duhdu\_tot\_0\textcolor{comment}{ !< The partial derivative}
890 \textcolor{comment}{                       !! of du\_err with du at 0 adjustment [H L ~> m2 or kg m-1].}
891   \textcolor{keywordtype}{real}, \textcolor{keywordtype}{dimension(SZIB\_(G))},                 \textcolor{keywordtype}{intent(in)}    :: du\_max\_CFL\textcolor{comment}{  !< Maximum acceptable}
892 \textcolor{comment}{                       !! value of du [L T-1 ~> m s-1].}
893   \textcolor{keywordtype}{real}, \textcolor{keywordtype}{dimension(SZIB\_(G))},                 \textcolor{keywordtype}{intent(in)}    :: du\_min\_CFL\textcolor{comment}{  !< Minimum acceptable}
894 \textcolor{comment}{                       !! value of du [L T-1 ~> m s-1].}
895   \textcolor{keywordtype}{real},                                      \textcolor{keywordtype}{intent(in)}    :: dt\textcolor{comment}{   !< Time increment [T ~> s].}
896   \textcolor{keywordtype}{type}(unit\_scale\_type),                     \textcolor{keywordtype}{intent(in)}    :: US\textcolor{comment}{   !< A dimensional unit scaling type}
897   \textcolor{keywordtype}{type}(continuity\_PPM\_CS),                   \textcolor{keywordtype}{pointer}       :: CS\textcolor{comment}{   !< This module's control structure.}
898   \textcolor{keywordtype}{real}, \textcolor{keywordtype}{dimension(SZIB\_(G),SZK\_(G))},         \textcolor{keywordtype}{intent(in)}    :: visc\_rem\textcolor{comment}{ !< Both the fraction of the}
899 \textcolor{comment}{                       !! momentum originally in a layer that remains after a time-step of viscosity, and}
900 \textcolor{comment}{                       !! the fraction of a time-step's worth of a barotropic acceleration that a layer}
901 \textcolor{comment}{                       !! experiences after viscosity is applied.}
902 \textcolor{comment}{                       !! Non-dimensional between 0 (at the bottom) and 1 (far above the bottom).}
903   \textcolor{keywordtype}{real}, \textcolor{keywordtype}{dimension(SZIB\_(G))},                 \textcolor{keywordtype}{intent(in)}    :: visc\_rem\_max\textcolor{comment}{ !< Maximum allowable visc\_rem.}
904   \textcolor{keywordtype}{integer},                                   \textcolor{keywordtype}{intent(in)}    :: j\textcolor{comment}{        !< Spatial index.}
905   \textcolor{keywordtype}{integer},                                   \textcolor{keywordtype}{intent(in)}    :: ish\textcolor{comment}{      !< Start of index range.}
906   \textcolor{keywordtype}{integer},                                   \textcolor{keywordtype}{intent(in)}    :: ieh\textcolor{comment}{      !< End of index range.}
907   \textcolor{keywordtype}{logical}, \textcolor{keywordtype}{dimension(SZIB\_(G))},              \textcolor{keywordtype}{intent(in)}    :: do\_I\textcolor{comment}{     !< A logical flag indicating}
908 \textcolor{comment}{                       !! which I values to work on.}
909   \textcolor{comment}{! Local variables}
910   \textcolor{keywordtype}{real}, \textcolor{keywordtype}{dimension(SZIB\_(G))} :: &
911     du0, &        \textcolor{comment}{! The barotropic velocity increment that gives 0 transport [L T-1 ~> m s-1].}
912     duL, duR, &   \textcolor{comment}{! The barotropic velocity increments that give the westerly}
913                   \textcolor{comment}{! (duL) and easterly (duR) test velocities [L T-1 ~> m s-1].}
914     zeros, &      \textcolor{comment}{! An array of full of 0's.}
915     du\_cfl, &     \textcolor{comment}{! The velocity increment that corresponds to CFL\_min [L T-1 ~> m s-1].}
916     u\_l, u\_r, &   \textcolor{comment}{! The westerly (u\_L), easterly (u\_R), and zero-barotropic}
917     u\_0, &        \textcolor{comment}{! transport (u\_0) layer test velocities [L T-1 ~> m s-1].}
918     duhdu\_l, &    \textcolor{comment}{! The effective layer marginal face areas with the westerly}
919     duhdu\_r, &    \textcolor{comment}{! (\_L), easterly (\_R), and zero-barotropic (\_0) test}
920     duhdu\_0, &    \textcolor{comment}{! velocities [H L ~> m2 or kg m-1].}
921     uh\_l, uh\_r, & \textcolor{comment}{! The layer transports with the westerly (\_L), easterly (\_R),}
922     uh\_0, &       \textcolor{comment}{! and zero-barotropic (\_0) test velocities [H L2 T-1 ~> m3 s-1 or kg s-1].}
923     famt\_l, famt\_r, & \textcolor{comment}{! The summed effective marginal face areas for the 3}
924     famt\_0, &     \textcolor{comment}{! test velocities [H L ~> m2 or kg m-1].}
925     uhtot\_l, &    \textcolor{comment}{! The summed transport with the westerly (uhtot\_L) and}
926     uhtot\_r       \textcolor{comment}{! and easterly (uhtot\_R) test velocities [H L2 T-1 ~> m3 s-1 or kg s-1].}
927   \textcolor{keywordtype}{real} :: FA\_0    \textcolor{comment}{! The effective face area with 0 barotropic transport [L H ~> m2 or kg m].}
928   \textcolor{keywordtype}{real} :: FA\_avg  \textcolor{comment}{! The average effective face area [L H ~> m2 or kg m], nominally given by}
929                   \textcolor{comment}{! the realized transport divided by the barotropic velocity.}
930   \textcolor{keywordtype}{real} :: visc\_rem\_lim \textcolor{comment}{! The larger of visc\_rem and min\_visc\_rem [nondim]  This}
931                        \textcolor{comment}{! limiting is necessary to keep the inverse of visc\_rem}
932                        \textcolor{comment}{! from leading to large CFL numbers.}
933   \textcolor{keywordtype}{real} :: min\_visc\_rem \textcolor{comment}{! The smallest permitted value for visc\_rem that is used}
934                        \textcolor{comment}{! in finding the barotropic velocity that changes the}
935                        \textcolor{comment}{! flow direction.  This is necessary to keep the inverse}
936                        \textcolor{comment}{! of visc\_rem from leading to large CFL numbers.}
937   \textcolor{keywordtype}{real} :: CFL\_min \textcolor{comment}{! A minimal increment in the CFL to try to ensure that the}
938                   \textcolor{comment}{! flow is truly upwind [nondim]}
939   \textcolor{keywordtype}{real} :: Idt     \textcolor{comment}{! The inverse of the time step [T-1 ~> s-1].}
940   \textcolor{keywordtype}{logical} :: domore
941   \textcolor{keywordtype}{integer} :: i, k, nz
942 
943   nz = g%ke ; idt = 1.0 / dt
944   min\_visc\_rem = 0.1 ; cfl\_min = 1e-6
945 
946  \textcolor{comment}{! Diagnose the zero-transport correction, du0.}
947   \textcolor{keywordflow}{do} i=ish-1,ieh ; zeros(i) = 0.0 ;\textcolor{keywordflow}{ enddo}
948   \textcolor{keyword}{call }zonal\_flux\_adjust(u, h\_in, h\_l, h\_r, zeros, uh\_tot\_0, duhdu\_tot\_0, du0, &
949                          du\_max\_cfl, du\_min\_cfl, dt, g, us, cs, visc\_rem, &
950                          j, ish, ieh, do\_i, .true.)
951 
952   \textcolor{comment}{! Determine the westerly- and easterly- fluxes.  Choose a sufficiently}
953   \textcolor{comment}{! negative velocity correction for the easterly-flux, and a sufficiently}
954   \textcolor{comment}{! positive correction for the westerly-flux.}
955   domore = .false.
956   \textcolor{keywordflow}{do} i=ish-1,ieh
957     \textcolor{keywordflow}{if} (do\_i(i)) domore = .true.
958     du\_cfl(i) = (cfl\_min * idt) * g%dxCu(i,j)
959     dur(i) = min(0.0,du0(i) - du\_cfl(i))
960     dul(i) = max(0.0,du0(i) + du\_cfl(i))
961     famt\_l(i) = 0.0 ; famt\_r(i) = 0.0 ; famt\_0(i) = 0.0
962     uhtot\_l(i) = 0.0 ; uhtot\_r(i) = 0.0
963 \textcolor{keywordflow}{  enddo}
964 
965   \textcolor{keywordflow}{if} (.not.domore) \textcolor{keywordflow}{then}
966     \textcolor{keywordflow}{do} k=1,nz ; \textcolor{keywordflow}{do} i=ish-1,ieh
967       bt\_cont%FA\_u\_W0(i,j) = 0.0 ; bt\_cont%FA\_u\_WW(i,j) = 0.0
968       bt\_cont%FA\_u\_E0(i,j) = 0.0 ; bt\_cont%FA\_u\_EE(i,j) = 0.0
969       bt\_cont%uBT\_WW(i,j) = 0.0 ; bt\_cont%uBT\_EE(i,j) = 0.0
970 \textcolor{keywordflow}{    enddo} ;\textcolor{keywordflow}{ enddo}
971     \textcolor{keywordflow}{return}
972 \textcolor{keywordflow}{  endif}
973 
974   \textcolor{keywordflow}{do} k=1,nz ; \textcolor{keywordflow}{do} i=ish-1,ieh ; \textcolor{keywordflow}{if} (do\_i(i)) \textcolor{keywordflow}{then}
975     visc\_rem\_lim = max(visc\_rem(i,k), min\_visc\_rem*visc\_rem\_max(i))
976     \textcolor{keywordflow}{if} (visc\_rem\_lim > 0.0) \textcolor{keywordflow}{then} \textcolor{comment}{! This is almost always true for ocean points.}
977       \textcolor{keywordflow}{if} (u(i,j,k) + dur(i)*visc\_rem\_lim > -du\_cfl(i)*visc\_rem(i,k)) &
978         dur(i) = -(u(i,j,k) + du\_cfl(i)*visc\_rem(i,k)) / visc\_rem\_lim
979       \textcolor{keywordflow}{if} (u(i,j,k) + dul(i)*visc\_rem\_lim < du\_cfl(i)*visc\_rem(i,k)) &
980         dul(i) = -(u(i,j,k) - du\_cfl(i)*visc\_rem(i,k)) / visc\_rem\_lim
981 \textcolor{keywordflow}{    endif}
982 \textcolor{keywordflow}{  endif} ;\textcolor{keywordflow}{ enddo} ;\textcolor{keywordflow}{ enddo}
983 
984   \textcolor{keywordflow}{do} k=1,nz
985     \textcolor{keywordflow}{do} i=ish-1,ieh ; \textcolor{keywordflow}{if} (do\_i(i)) \textcolor{keywordflow}{then}
986       u\_l(i) = u(i,j,k) + dul(i) * visc\_rem(i,k)
987       u\_r(i) = u(i,j,k) + dur(i) * visc\_rem(i,k)
988       u\_0(i) = u(i,j,k) + du0(i) * visc\_rem(i,k)
989 \textcolor{keywordflow}{    endif} ;\textcolor{keywordflow}{ enddo}
990     \textcolor{keyword}{call }zonal\_flux\_layer(u\_0, h\_in(:,j,k), h\_l(:,j,k), h\_r(:,j,k), uh\_0, duhdu\_0, &
991                           visc\_rem(:,k), dt, g, us, j, ish, ieh, do\_i, cs%vol\_CFL)
992     \textcolor{keyword}{call }zonal\_flux\_layer(u\_l, h\_in(:,j,k), h\_l(:,j,k), h\_r(:,j,k), uh\_l, duhdu\_l, &
993                           visc\_rem(:,k), dt, g, us, j, ish, ieh, do\_i, cs%vol\_CFL)
994     \textcolor{keyword}{call }zonal\_flux\_layer(u\_r, h\_in(:,j,k), h\_l(:,j,k), h\_r(:,j,k), uh\_r, duhdu\_r, &
995                           visc\_rem(:,k), dt, g, us, j, ish, ieh, do\_i, cs%vol\_CFL)
996     \textcolor{keywordflow}{do} i=ish-1,ieh ; \textcolor{keywordflow}{if} (do\_i(i)) \textcolor{keywordflow}{then}
997       famt\_0(i) = famt\_0(i) + duhdu\_0(i)
998       famt\_l(i) = famt\_l(i) + duhdu\_l(i)
999       famt\_r(i) = famt\_r(i) + duhdu\_r(i)
1000       uhtot\_l(i) = uhtot\_l(i) + uh\_l(i)
1001       uhtot\_r(i) = uhtot\_r(i) + uh\_r(i)
1002 \textcolor{keywordflow}{    endif} ;\textcolor{keywordflow}{ enddo}
1003 \textcolor{keywordflow}{  enddo}
1004   \textcolor{keywordflow}{do} i=ish-1,ieh ; \textcolor{keywordflow}{if} (do\_i(i)) \textcolor{keywordflow}{then}
1005     fa\_0 = famt\_0(i) ; fa\_avg = famt\_0(i)
1006     \textcolor{keywordflow}{if} ((dul(i) - du0(i)) /= 0.0) &
1007       fa\_avg = uhtot\_l(i) / (dul(i) - du0(i))
1008     \textcolor{keywordflow}{if} (fa\_avg > max(fa\_0, famt\_l(i))) \textcolor{keywordflow}{then} ; fa\_avg = max(fa\_0, famt\_l(i))
1009     \textcolor{keywordflow}{elseif} (fa\_avg < min(fa\_0, famt\_l(i))) \textcolor{keywordflow}{then} ; fa\_0 = fa\_avg ;\textcolor{keywordflow}{ endif}
1010 
1011     bt\_cont%FA\_u\_W0(i,j) = fa\_0 ; bt\_cont%FA\_u\_WW(i,j) = famt\_l(i)
1012     \textcolor{keywordflow}{if} (abs(fa\_0-famt\_l(i)) <= 1e-12*fa\_0) \textcolor{keywordflow}{then} ; bt\_cont%uBT\_WW(i,j) = 0.0 ; \textcolor{keywordflow}{else}
1013       bt\_cont%uBT\_WW(i,j) = (1.5 * (dul(i) - du0(i))) * &
1014                             ((famt\_l(i) - fa\_avg) / (famt\_l(i) - fa\_0))
1015 \textcolor{keywordflow}{    endif}
1016 
1017     fa\_0 = famt\_0(i) ; fa\_avg = famt\_0(i)
1018     \textcolor{keywordflow}{if} ((dur(i) - du0(i)) /= 0.0) &
1019       fa\_avg = uhtot\_r(i) / (dur(i) - du0(i))
1020     \textcolor{keywordflow}{if} (fa\_avg > max(fa\_0, famt\_r(i))) \textcolor{keywordflow}{then} ; fa\_avg = max(fa\_0, famt\_r(i))
1021     \textcolor{keywordflow}{elseif} (fa\_avg < min(fa\_0, famt\_r(i))) \textcolor{keywordflow}{then} ; fa\_0 = fa\_avg ;\textcolor{keywordflow}{ endif}
1022 
1023     bt\_cont%FA\_u\_E0(i,j) = fa\_0 ; bt\_cont%FA\_u\_EE(i,j) = famt\_r(i)
1024     \textcolor{keywordflow}{if} (abs(famt\_r(i) - fa\_0) <= 1e-12*fa\_0) \textcolor{keywordflow}{then} ; bt\_cont%uBT\_EE(i,j) = 0.0 ; \textcolor{keywordflow}{else}
1025       bt\_cont%uBT\_EE(i,j) = (1.5 * (dur(i) - du0(i))) * &
1026                             ((famt\_r(i) - fa\_avg) / (famt\_r(i) - fa\_0))
1027 \textcolor{keywordflow}{    endif}
1028   \textcolor{keywordflow}{else}
1029     bt\_cont%FA\_u\_W0(i,j) = 0.0 ; bt\_cont%FA\_u\_WW(i,j) = 0.0
1030     bt\_cont%FA\_u\_E0(i,j) = 0.0 ; bt\_cont%FA\_u\_EE(i,j) = 0.0
1031     bt\_cont%uBT\_WW(i,j) = 0.0 ; bt\_cont%uBT\_EE(i,j) = 0.0
1032 \textcolor{keywordflow}{  endif} ;\textcolor{keywordflow}{ enddo}
1033 
\end{DoxyCode}
\mbox{\Hypertarget{namespacemom__continuity__ppm_a9e76825c96ffca1ae0e84469ab46029b}\label{namespacemom__continuity__ppm_a9e76825c96ffca1ae0e84469ab46029b}} 
\index{mom\+\_\+continuity\+\_\+ppm@{mom\+\_\+continuity\+\_\+ppm}!zonal\+\_\+face\+\_\+thickness@{zonal\+\_\+face\+\_\+thickness}}
\index{zonal\+\_\+face\+\_\+thickness@{zonal\+\_\+face\+\_\+thickness}!mom\+\_\+continuity\+\_\+ppm@{mom\+\_\+continuity\+\_\+ppm}}
\subsubsection{\texorpdfstring{zonal\+\_\+face\+\_\+thickness()}{zonal\_face\_thickness()}}
{\footnotesize\ttfamily subroutine mom\+\_\+continuity\+\_\+ppm\+::zonal\+\_\+face\+\_\+thickness (\begin{DoxyParamCaption}\item[{real, dimension( g \%isdb\+: g \%iedb, g \%jsd\+: g \%jed, g \%ke), intent(in)}]{u,  }\item[{real, dimension( g \%isd\+: g \%ied, g \%jsd\+: g \%jed, g \%ke), intent(in)}]{h,  }\item[{real, dimension( g \%isd\+: g \%ied, g \%jsd\+: g \%jed, g \%ke), intent(in)}]{h\+\_\+L,  }\item[{real, dimension( g \%isd\+: g \%ied, g \%jsd\+: g \%jed, g \%ke), intent(in)}]{h\+\_\+R,  }\item[{real, dimension( g \%isdb\+: g \%iedb, g \%jsd\+: g \%jed, g \%ke), intent(inout)}]{h\+\_\+u,  }\item[{real, intent(in)}]{dt,  }\item[{type(ocean\+\_\+grid\+\_\+type), intent(inout)}]{G,  }\item[{type(unit\+\_\+scale\+\_\+type), intent(in)}]{US,  }\item[{type(\mbox{\hyperlink{structmom__continuity__ppm_1_1loop__bounds__type}{loop\+\_\+bounds\+\_\+type}}), intent(in)}]{LB,  }\item[{logical, intent(in)}]{vol\+\_\+\+C\+FL,  }\item[{logical, intent(in)}]{marginal,  }\item[{real, dimension( g \%isdb\+: g \%iedb, g \%jsd\+: g \%jed, g \%ke), intent(in), optional}]{visc\+\_\+rem\+\_\+u,  }\item[{type(ocean\+\_\+obc\+\_\+type), optional, pointer}]{O\+BC }\end{DoxyParamCaption})\hspace{0.3cm}{\ttfamily [private]}}



Sets the effective interface thickness at each zonal velocity point. 


\begin{DoxyParams}[1]{Parameters}
\mbox{\tt in,out}  & {\em g} & Ocean\textquotesingle{}s grid structure.\\
\hline
\mbox{\tt in}  & {\em u} & Zonal velocity \mbox{[}L T-\/1 $\sim$$>$ m s-\/1\mbox{]}.\\
\hline
\mbox{\tt in}  & {\em h} & Layer thickness used to calculate fluxes \mbox{[}H $\sim$$>$ m or kg m-\/2\mbox{]}.\\
\hline
\mbox{\tt in}  & {\em h\+\_\+l} & Left thickness in the reconstruction \mbox{[}H $\sim$$>$ m or kg m-\/2\mbox{]}.\\
\hline
\mbox{\tt in}  & {\em h\+\_\+r} & Right thickness in the reconstruction \mbox{[}H $\sim$$>$ m or kg m-\/2\mbox{]}.\\
\hline
\mbox{\tt in,out}  & {\em h\+\_\+u} & Thickness at zonal faces \mbox{[}H $\sim$$>$ m or kg m-\/2\mbox{]}.\\
\hline
\mbox{\tt in}  & {\em dt} & Time increment \mbox{[}T $\sim$$>$ s\mbox{]}.\\
\hline
\mbox{\tt in}  & {\em us} & A dimensional unit scaling type\\
\hline
\mbox{\tt in}  & {\em lb} & Loop bounds structure.\\
\hline
\mbox{\tt in}  & {\em vol\+\_\+cfl} & If true, rescale the ratio of face areas to the cell areas when estimating the C\+FL number.\\
\hline
\mbox{\tt in}  & {\em marginal} & If true, report the marginal face thicknesses; otherwise report transport-\/averaged thicknesses.\\
\hline
\mbox{\tt in}  & {\em visc\+\_\+rem\+\_\+u} & Both the fraction of the momentum originally in a layer that remains after a time-\/step of viscosity, and the fraction of a time-\/step\textquotesingle{}s worth of a barotropic acceleration that a layer experiences after viscosity is applied. Non-\/dimensional between 0 (at the bottom) and 1 (far above the bottom).\\
\hline
 & {\em obc} & Open boundaries control structure. \\
\hline
\end{DoxyParams}


Definition at line 605 of file M\+O\+M\+\_\+continuity\+\_\+\+P\+P\+M.\+F90.


\begin{DoxyCode}
605   \textcolor{keywordtype}{type}(ocean\_grid\_type),                     \textcolor{keywordtype}{intent(inout)} :: G\textcolor{comment}{    !< Ocean's grid structure.}
606   \textcolor{keywordtype}{real}, \textcolor{keywordtype}{dimension(SZIB\_(G),SZJ\_(G),SZK\_(G))}, \textcolor{keywordtype}{intent(in)}    :: u\textcolor{comment}{    !< Zonal velocity [L T-1 ~> m s-1].}
607   \textcolor{keywordtype}{real}, \textcolor{keywordtype}{dimension(SZI\_(G),SZJ\_(G),SZK\_(G))},  \textcolor{keywordtype}{intent(in)}    :: h\textcolor{comment}{    !< Layer thickness used to}
608 \textcolor{comment}{                                                                   !! calculate fluxes [H ~> m or kg m-2].}
609   \textcolor{keywordtype}{real}, \textcolor{keywordtype}{dimension(SZI\_(G),SZJ\_(G),SZK\_(G))},  \textcolor{keywordtype}{intent(in)}    :: h\_L\textcolor{comment}{  !< Left thickness in the}
610 \textcolor{comment}{                                                                   !! reconstruction [H ~> m or kg m-2].}
611   \textcolor{keywordtype}{real}, \textcolor{keywordtype}{dimension(SZI\_(G),SZJ\_(G),SZK\_(G))},  \textcolor{keywordtype}{intent(in)}    :: h\_R\textcolor{comment}{  !< Right thickness in the}
612 \textcolor{comment}{                                                                   !! reconstruction [H ~> m or kg m-2].}
613   \textcolor{keywordtype}{real}, \textcolor{keywordtype}{dimension(SZIB\_(G),SZJ\_(G),SZK\_(G))}, \textcolor{keywordtype}{intent(inout)} :: h\_u\textcolor{comment}{  !< Thickness at zonal faces [H ~> m or
       kg m-2].}
614   \textcolor{keywordtype}{real},                                      \textcolor{keywordtype}{intent(in)}    :: dt\textcolor{comment}{   !< Time increment [T ~> s].}
615   \textcolor{keywordtype}{type}(unit\_scale\_type),                     \textcolor{keywordtype}{intent(in)}    :: US\textcolor{comment}{   !< A dimensional unit scaling type}
616   \textcolor{keywordtype}{type}(loop\_bounds\_type),                    \textcolor{keywordtype}{intent(in)}    :: LB\textcolor{comment}{   !< Loop bounds structure.}
617   \textcolor{keywordtype}{logical},                                   \textcolor{keywordtype}{intent(in)}    :: vol\_CFL\textcolor{comment}{ !< If true, rescale the ratio}
618 \textcolor{comment}{                          !! of face areas to the cell areas when estimating the CFL number.}
619   \textcolor{keywordtype}{logical},                                   \textcolor{keywordtype}{intent(in)}    :: marginal\textcolor{comment}{ !< If true, report the}
620 \textcolor{comment}{                          !! marginal face thicknesses; otherwise report transport-averaged thicknesses.}
621   \textcolor{keywordtype}{real}, \textcolor{keywordtype}{dimension(SZIB\_(G),SZJ\_(G),SZK\_(G))}, &
622                                    \textcolor{keywordtype}{optional}, \textcolor{keywordtype}{intent(in)}    :: visc\_rem\_u
623                           \textcolor{comment}{!< Both the fraction of the momentum originally in a layer that remains after}
624 \textcolor{comment}{                          !! a time-step of viscosity, and the fraction of a time-step's worth of a}
625 \textcolor{comment}{                          !! barotropic acceleration that a layer experiences after viscosity is applied.}
626 \textcolor{comment}{                          !! Non-dimensional between 0 (at the bottom) and 1 (far above the bottom).}
627   \textcolor{keywordtype}{type}(ocean\_OBC\_type),            \textcolor{keywordtype}{optional}, \textcolor{keywordtype}{pointer}       :: OBC\textcolor{comment}{ !< Open boundaries control structure.}
628 
629   \textcolor{comment}{! Local variables}
630   \textcolor{keywordtype}{real} :: CFL  \textcolor{comment}{! The CFL number based on the local velocity and grid spacing [nondim]}
631   \textcolor{keywordtype}{real} :: curv\_3 \textcolor{comment}{! A measure of the thickness curvature over a grid length,}
632                  \textcolor{comment}{! with the same units as h\_in.}
633   \textcolor{keywordtype}{real} :: h\_avg  \textcolor{comment}{! The average thickness of a flux [H ~> m or kg m-2].}
634   \textcolor{keywordtype}{real} :: h\_marg \textcolor{comment}{! The marginal thickness of a flux [H ~> m or kg m-2].}
635   \textcolor{keywordtype}{logical} :: local\_open\_BC
636   \textcolor{keywordtype}{integer} :: i, j, k, ish, ieh, jsh, jeh, nz, n
637   ish = lb%ish ; ieh = lb%ieh ; jsh = lb%jsh ; jeh = lb%jeh ; nz = g%ke
638 
639   \textcolor{comment}{!$OMP parallel do default(shared) private(CFL,curv\_3,h\_marg,h\_avg)}
640   \textcolor{keywordflow}{do} k=1,nz ; \textcolor{keywordflow}{do} j=jsh,jeh ; \textcolor{keywordflow}{do} i=ish-1,ieh
641     \textcolor{keywordflow}{if} (u(i,j,k) > 0.0) \textcolor{keywordflow}{then}
642       \textcolor{keywordflow}{if} (vol\_cfl) \textcolor{keywordflow}{then} ; cfl = (u(i,j,k) * dt) * (g%dy\_Cu(i,j) * g%IareaT(i,j))
643       \textcolor{keywordflow}{else} ; cfl = u(i,j,k) * dt * g%IdxT(i,j) ;\textcolor{keywordflow}{ endif}
644       curv\_3 = h\_l(i,j,k) + h\_r(i,j,k) - 2.0*h(i,j,k)
645       h\_avg = h\_r(i,j,k) + cfl * (0.5*(h\_l(i,j,k) - h\_r(i,j,k)) + curv\_3*(cfl - 1.5))
646       h\_marg = h\_r(i,j,k) + cfl * ((h\_l(i,j,k) - h\_r(i,j,k)) + 3.0*curv\_3*(cfl - 1.0))
647     \textcolor{keywordflow}{elseif} (u(i,j,k) < 0.0) \textcolor{keywordflow}{then}
648       \textcolor{keywordflow}{if} (vol\_cfl) \textcolor{keywordflow}{then} ; cfl = (-u(i,j,k)*dt) * (g%dy\_Cu(i,j) * g%IareaT(i+1,j))
649       \textcolor{keywordflow}{else} ; cfl = -u(i,j,k) * dt * g%IdxT(i+1,j) ;\textcolor{keywordflow}{ endif}
650       curv\_3 = h\_l(i+1,j,k) + h\_r(i+1,j,k) - 2.0*h(i+1,j,k)
651       h\_avg = h\_l(i+1,j,k) + cfl * (0.5*(h\_r(i+1,j,k)-h\_l(i+1,j,k)) + curv\_3*(cfl - 1.5))
652       h\_marg = h\_l(i+1,j,k) + cfl * ((h\_r(i+1,j,k)-h\_l(i+1,j,k)) + &
653                                     3.0*curv\_3*(cfl - 1.0))
654     \textcolor{keywordflow}{else}
655       h\_avg = 0.5 * (h\_l(i+1,j,k) + h\_r(i,j,k))
656       \textcolor{comment}{!   The choice to use the arithmetic mean here is somewhat arbitrariy, but}
657       \textcolor{comment}{! it should be noted that h\_L(i+1,j,k) and h\_R(i,j,k) are usually the same.}
658       h\_marg = 0.5 * (h\_l(i+1,j,k) + h\_r(i,j,k))
659  \textcolor{comment}{!    h\_marg = (2.0 * h\_L(i+1,j,k) * h\_R(i,j,k)) / &}
660  \textcolor{comment}{!             (h\_L(i+1,j,k) + h\_R(i,j,k) + GV%H\_subroundoff)}
661 \textcolor{keywordflow}{    endif}
662 
663     \textcolor{keywordflow}{if} (marginal) \textcolor{keywordflow}{then} ; h\_u(i,j,k) = h\_marg
664     \textcolor{keywordflow}{else} ; h\_u(i,j,k) = h\_avg ;\textcolor{keywordflow}{ endif}
665 \textcolor{keywordflow}{  enddo} ;\textcolor{keywordflow}{ enddo} ;\textcolor{keywordflow}{ enddo}
666   \textcolor{keywordflow}{if} (\textcolor{keyword}{present}(visc\_rem\_u)) \textcolor{keywordflow}{then}
667     \textcolor{comment}{!$OMP parallel do default(shared)}
668     \textcolor{keywordflow}{do} k=1,nz ; \textcolor{keywordflow}{do} j=jsh,jeh ; \textcolor{keywordflow}{do} i=ish-1,ieh
669       h\_u(i,j,k) = h\_u(i,j,k) * visc\_rem\_u(i,j,k)
670 \textcolor{keywordflow}{    enddo} ;\textcolor{keywordflow}{ enddo} ;\textcolor{keywordflow}{ enddo}
671 \textcolor{keywordflow}{  endif}
672 
673   local\_open\_bc = .false.
674   \textcolor{keywordflow}{if} (\textcolor{keyword}{present}(obc)) \textcolor{keywordflow}{then} ; \textcolor{keywordflow}{if} (\textcolor{keyword}{associated}(obc)) \textcolor{keywordflow}{then}
675     local\_open\_bc = obc%open\_u\_BCs\_exist\_globally
676 \textcolor{keywordflow}{  endif} ;\textcolor{keywordflow}{ endif}
677   \textcolor{keywordflow}{if} (local\_open\_bc) \textcolor{keywordflow}{then}
678     \textcolor{keywordflow}{do} n = 1, obc%number\_of\_segments
679       \textcolor{keywordflow}{if} (obc%segment(n)%open .and. obc%segment(n)%is\_E\_or\_W) \textcolor{keywordflow}{then}
680         i = obc%segment(n)%HI%IsdB
681         \textcolor{keywordflow}{if} (obc%segment(n)%direction == obc\_direction\_e) \textcolor{keywordflow}{then}
682           \textcolor{keywordflow}{if} (\textcolor{keyword}{present}(visc\_rem\_u)) \textcolor{keywordflow}{then} ; \textcolor{keywordflow}{do} k=1,nz
683             \textcolor{keywordflow}{do} j = obc%segment(n)%HI%jsd, obc%segment(n)%HI%jed
684               h\_u(i,j,k) = h(i,j,k) * visc\_rem\_u(i,j,k)
685 \textcolor{keywordflow}{            enddo}
686 \textcolor{keywordflow}{          enddo} ; \textcolor{keywordflow}{else} ; \textcolor{keywordflow}{do} k=1,nz
687             \textcolor{keywordflow}{do} j = obc%segment(n)%HI%jsd, obc%segment(n)%HI%jed
688               h\_u(i,j,k) = h(i,j,k)
689 \textcolor{keywordflow}{            enddo}
690 \textcolor{keywordflow}{          enddo} ;\textcolor{keywordflow}{ endif}
691         \textcolor{keywordflow}{else}
692           \textcolor{keywordflow}{if} (\textcolor{keyword}{present}(visc\_rem\_u)) \textcolor{keywordflow}{then} ; \textcolor{keywordflow}{do} k=1,nz
693             \textcolor{keywordflow}{do} j = obc%segment(n)%HI%jsd, obc%segment(n)%HI%jed
694               h\_u(i,j,k) = h(i+1,j,k) * visc\_rem\_u(i,j,k)
695 \textcolor{keywordflow}{            enddo}
696 \textcolor{keywordflow}{          enddo} ; \textcolor{keywordflow}{else} ; \textcolor{keywordflow}{do} k=1,nz
697             \textcolor{keywordflow}{do} j = obc%segment(n)%HI%jsd, obc%segment(n)%HI%jed
698               h\_u(i,j,k) = h(i+1,j,k)
699 \textcolor{keywordflow}{            enddo}
700 \textcolor{keywordflow}{          enddo} ;\textcolor{keywordflow}{ endif}
701 \textcolor{keywordflow}{        endif}
702 \textcolor{keywordflow}{      endif}
703 \textcolor{keywordflow}{    enddo}
704 \textcolor{keywordflow}{  endif}
705 
\end{DoxyCode}
\mbox{\Hypertarget{namespacemom__continuity__ppm_afad3f82b9824a13d3fe8792496e9b769}\label{namespacemom__continuity__ppm_afad3f82b9824a13d3fe8792496e9b769}} 
\index{mom\+\_\+continuity\+\_\+ppm@{mom\+\_\+continuity\+\_\+ppm}!zonal\+\_\+flux\+\_\+adjust@{zonal\+\_\+flux\+\_\+adjust}}
\index{zonal\+\_\+flux\+\_\+adjust@{zonal\+\_\+flux\+\_\+adjust}!mom\+\_\+continuity\+\_\+ppm@{mom\+\_\+continuity\+\_\+ppm}}
\subsubsection{\texorpdfstring{zonal\+\_\+flux\+\_\+adjust()}{zonal\_flux\_adjust()}}
{\footnotesize\ttfamily subroutine mom\+\_\+continuity\+\_\+ppm\+::zonal\+\_\+flux\+\_\+adjust (\begin{DoxyParamCaption}\item[{real, dimension( g \%isdb\+: g \%iedb, g \%jsd\+: g \%jed, g \%ke), intent(in)}]{u,  }\item[{real, dimension( g \%isd\+: g \%ied, g \%jsd\+: g \%jed, g \%ke), intent(in)}]{h\+\_\+in,  }\item[{real, dimension( g \%isd\+: g \%ied, g \%jsd\+: g \%jed, g \%ke), intent(in)}]{h\+\_\+L,  }\item[{real, dimension( g \%isd\+: g \%ied, g \%jsd\+: g \%jed, g \%ke), intent(in)}]{h\+\_\+R,  }\item[{real, dimension(szib\+\_\+(g)), intent(in), optional}]{uhbt,  }\item[{real, dimension(szib\+\_\+(g)), intent(in)}]{uh\+\_\+tot\+\_\+0,  }\item[{real, dimension(szib\+\_\+(g)), intent(in)}]{duhdu\+\_\+tot\+\_\+0,  }\item[{real, dimension(szib\+\_\+(g)), intent(out)}]{du,  }\item[{real, dimension(szib\+\_\+(g)), intent(in)}]{du\+\_\+max\+\_\+\+C\+FL,  }\item[{real, dimension(szib\+\_\+(g)), intent(in)}]{du\+\_\+min\+\_\+\+C\+FL,  }\item[{real, intent(in)}]{dt,  }\item[{type(ocean\+\_\+grid\+\_\+type), intent(inout)}]{G,  }\item[{type(unit\+\_\+scale\+\_\+type), intent(in)}]{US,  }\item[{type(\mbox{\hyperlink{structmom__continuity__ppm_1_1continuity__ppm__cs}{continuity\+\_\+ppm\+\_\+cs}}), pointer}]{CS,  }\item[{real, dimension( g \%isdb\+: g \%iedb, g \%ke), intent(in)}]{visc\+\_\+rem,  }\item[{integer, intent(in)}]{j,  }\item[{integer, intent(in)}]{ish,  }\item[{integer, intent(in)}]{ieh,  }\item[{logical, dimension( g \%isdb\+: g \%iedb), intent(in)}]{do\+\_\+\+I\+\_\+in,  }\item[{logical, intent(in), optional}]{full\+\_\+precision,  }\item[{real, dimension( g \%isdb\+: g \%iedb, g \%jsd\+: g \%jed, g \%ke), intent(inout), optional}]{uh\+\_\+3d,  }\item[{type(ocean\+\_\+obc\+\_\+type), optional, pointer}]{O\+BC }\end{DoxyParamCaption})\hspace{0.3cm}{\ttfamily [private]}}



Returns the barotropic velocity adjustment that gives the desired barotropic (layer-\/summed) transport. 


\begin{DoxyParams}[1]{Parameters}
\mbox{\tt in,out}  & {\em g} & Ocean\textquotesingle{}s grid structure.\\
\hline
\mbox{\tt in}  & {\em u} & Zonal velocity \mbox{[}L T-\/1 $\sim$$>$ m s-\/1\mbox{]}.\\
\hline
\mbox{\tt in}  & {\em h\+\_\+in} & Layer thickness used to calculate fluxes \mbox{[}H $\sim$$>$ m or kg m-\/2\mbox{]}.\\
\hline
\mbox{\tt in}  & {\em h\+\_\+l} & Left thickness in the reconstruction \mbox{[}H $\sim$$>$ m or kg m-\/2\mbox{]}.\\
\hline
\mbox{\tt in}  & {\em h\+\_\+r} & Right thickness in the reconstruction \mbox{[}H $\sim$$>$ m or kg m-\/2\mbox{]}.\\
\hline
\mbox{\tt in}  & {\em visc\+\_\+rem} & Both the fraction of the momentum originally in a layer that remains after a time-\/step of viscosity, and the fraction of a time-\/step\textquotesingle{}s worth of a barotropic acceleration that a layer experiences after viscosity is applied. Non-\/dimensional between 0 (at the bottom) and 1 (far above the bottom).\\
\hline
\mbox{\tt in}  & {\em uhbt} & The summed volume flux through zonal faces \mbox{[}H L2 T-\/1 $\sim$$>$ m3 s-\/1 or kg s-\/1\mbox{]}.\\
\hline
\mbox{\tt in}  & {\em du\+\_\+max\+\_\+cfl} & Maximum acceptable value of du \mbox{[}L T-\/1 $\sim$$>$ m s-\/1\mbox{]}.\\
\hline
\mbox{\tt in}  & {\em du\+\_\+min\+\_\+cfl} & Minimum acceptable value of du \mbox{[}L T-\/1 $\sim$$>$ m s-\/1\mbox{]}.\\
\hline
\mbox{\tt in}  & {\em uh\+\_\+tot\+\_\+0} & The summed transport with 0 adjustment \mbox{[}H L2 T-\/1 $\sim$$>$ m3 s-\/1 or kg s-\/1\mbox{]}.\\
\hline
\mbox{\tt in}  & {\em duhdu\+\_\+tot\+\_\+0} & The partial derivative of du\+\_\+err with du at 0 adjustment \mbox{[}H L $\sim$$>$ m2 or kg m-\/1\mbox{]}.\\
\hline
\mbox{\tt out}  & {\em du} & The barotropic velocity adjustment \mbox{[}L T-\/1 $\sim$$>$ m s-\/1\mbox{]}.\\
\hline
\mbox{\tt in}  & {\em dt} & Time increment \mbox{[}T $\sim$$>$ s\mbox{]}.\\
\hline
\mbox{\tt in}  & {\em us} & A dimensional unit scaling type\\
\hline
 & {\em cs} & This module\textquotesingle{}s control structure.\\
\hline
\mbox{\tt in}  & {\em j} & Spatial index.\\
\hline
\mbox{\tt in}  & {\em ish} & Start of index range.\\
\hline
\mbox{\tt in}  & {\em ieh} & End of index range.\\
\hline
\mbox{\tt in}  & {\em do\+\_\+i\+\_\+in} & A logical flag indicating which I values to work on.\\
\hline
\mbox{\tt in}  & {\em full\+\_\+precision} & A flag indicating how carefully to iterate. The default is .true. (more accurate).\\
\hline
\mbox{\tt in,out}  & {\em uh\+\_\+3d} & Volume flux through zonal faces = u$\ast$h$\ast$dy \mbox{[}H L2 T-\/1 $\sim$$>$ m3 s-\/1 or kg s-\/1\mbox{]}.\\
\hline
 & {\em obc} & Open boundaries control structure. \\
\hline
\end{DoxyParams}


Definition at line 713 of file M\+O\+M\+\_\+continuity\+\_\+\+P\+P\+M.\+F90.


\begin{DoxyCode}
713   \textcolor{keywordtype}{type}(ocean\_grid\_type),                     \textcolor{keywordtype}{intent(inout)} :: G\textcolor{comment}{    !< Ocean's grid structure.}
714   \textcolor{keywordtype}{real}, \textcolor{keywordtype}{dimension(SZIB\_(G),SZJ\_(G),SZK\_(G))}, \textcolor{keywordtype}{intent(in)}    :: u\textcolor{comment}{    !< Zonal velocity [L T-1 ~> m s-1].}
715   \textcolor{keywordtype}{real}, \textcolor{keywordtype}{dimension(SZI\_(G),SZJ\_(G),SZK\_(G))},  \textcolor{keywordtype}{intent(in)}    :: h\_in\textcolor{comment}{ !< Layer thickness used to}
716 \textcolor{comment}{                                                                   !! calculate fluxes [H ~> m or kg m-2].}
717   \textcolor{keywordtype}{real}, \textcolor{keywordtype}{dimension(SZI\_(G),SZJ\_(G),SZK\_(G))},  \textcolor{keywordtype}{intent(in)}    :: h\_L\textcolor{comment}{  !< Left thickness in the}
718 \textcolor{comment}{                                                                   !! reconstruction [H ~> m or kg m-2].}
719   \textcolor{keywordtype}{real}, \textcolor{keywordtype}{dimension(SZI\_(G),SZJ\_(G),SZK\_(G))},  \textcolor{keywordtype}{intent(in)}    :: h\_R\textcolor{comment}{  !< Right thickness in the}
720 \textcolor{comment}{                                                                   !! reconstruction [H ~> m or kg m-2].}
721   \textcolor{keywordtype}{real}, \textcolor{keywordtype}{dimension(SZIB\_(G),SZK\_(G))},         \textcolor{keywordtype}{intent(in)}    :: visc\_rem\textcolor{comment}{ !< Both the fraction of the}
722 \textcolor{comment}{                       !! momentum originally in a layer that remains after a time-step of viscosity, and}
723 \textcolor{comment}{                       !! the fraction of a time-step's worth of a barotropic acceleration that a layer}
724 \textcolor{comment}{                       !! experiences after viscosity is applied.}
725 \textcolor{comment}{                       !! Non-dimensional between 0 (at the bottom) and 1 (far above the bottom).}
726   \textcolor{keywordtype}{real}, \textcolor{keywordtype}{dimension(SZIB\_(G))},       \textcolor{keywordtype}{optional}, \textcolor{keywordtype}{intent(in)}    :: uhbt\textcolor{comment}{ !< The summed volume flux}
727 \textcolor{comment}{                       !! through zonal faces [H L2 T-1 ~> m3 s-1 or kg s-1].}
728 
729   \textcolor{keywordtype}{real}, \textcolor{keywordtype}{dimension(SZIB\_(G))},                 \textcolor{keywordtype}{intent(in)}    :: du\_max\_CFL\textcolor{comment}{  !< Maximum acceptable}
730 \textcolor{comment}{                       !! value of du [L T-1 ~> m s-1].}
731   \textcolor{keywordtype}{real}, \textcolor{keywordtype}{dimension(SZIB\_(G))},                 \textcolor{keywordtype}{intent(in)}    :: du\_min\_CFL\textcolor{comment}{  !< Minimum acceptable}
732 \textcolor{comment}{                       !! value of du [L T-1 ~> m s-1].}
733   \textcolor{keywordtype}{real}, \textcolor{keywordtype}{dimension(SZIB\_(G))},                 \textcolor{keywordtype}{intent(in)}    :: uh\_tot\_0\textcolor{comment}{    !< The summed transport}
734 \textcolor{comment}{                       !! with 0 adjustment [H L2 T-1 ~> m3 s-1 or kg s-1].}
735   \textcolor{keywordtype}{real}, \textcolor{keywordtype}{dimension(SZIB\_(G))},                 \textcolor{keywordtype}{intent(in)}    :: duhdu\_tot\_0\textcolor{comment}{ !< The partial derivative}
736 \textcolor{comment}{                       !! of du\_err with du at 0 adjustment [H L ~> m2 or kg m-1].}
737   \textcolor{keywordtype}{real}, \textcolor{keywordtype}{dimension(SZIB\_(G))},                 \textcolor{keywordtype}{intent(out)}   :: du\textcolor{comment}{ !<}
738 \textcolor{comment}{                       !! The barotropic velocity adjustment [L T-1 ~> m s-1].}
739   \textcolor{keywordtype}{real},                                      \textcolor{keywordtype}{intent(in)}    :: dt\textcolor{comment}{   !< Time increment [T ~> s].}
740   \textcolor{keywordtype}{type}(unit\_scale\_type),                     \textcolor{keywordtype}{intent(in)}    :: US\textcolor{comment}{   !< A dimensional unit scaling type}
741   \textcolor{keywordtype}{type}(continuity\_PPM\_CS),                   \textcolor{keywordtype}{pointer}       :: CS\textcolor{comment}{   !< This module's control structure.}
742   \textcolor{keywordtype}{integer},                                   \textcolor{keywordtype}{intent(in)}    :: j\textcolor{comment}{    !< Spatial index.}
743   \textcolor{keywordtype}{integer},                                   \textcolor{keywordtype}{intent(in)}    :: ish\textcolor{comment}{  !< Start of index range.}
744   \textcolor{keywordtype}{integer},                                   \textcolor{keywordtype}{intent(in)}    :: ieh\textcolor{comment}{  !< End of index range.}
745   \textcolor{keywordtype}{logical}, \textcolor{keywordtype}{dimension(SZIB\_(G))},              \textcolor{keywordtype}{intent(in)}    :: do\_I\_in\textcolor{comment}{     !<}
746 \textcolor{comment}{                       !! A logical flag indicating which I values to work on.}
747   \textcolor{keywordtype}{logical},                         \textcolor{keywordtype}{optional}, \textcolor{keywordtype}{intent(in)}    :: full\_precision\textcolor{comment}{ !<}
748 \textcolor{comment}{                       !! A flag indicating how carefully to iterate.  The}
749 \textcolor{comment}{                       !! default is .true. (more accurate).}
750   \textcolor{keywordtype}{real}, \textcolor{keywordtype}{dimension(SZIB\_(G),SZJ\_(G),SZK\_(G))}, \textcolor{keywordtype}{optional}, \textcolor{keywordtype}{intent(inout)} :: uh\_3d\textcolor{comment}{ !<}
751 \textcolor{comment}{                       !! Volume flux through zonal faces = u*h*dy [H L2 T-1 ~> m3 s-1 or kg s-1].}
752   \textcolor{keywordtype}{type}(ocean\_OBC\_type),            \textcolor{keywordtype}{optional}, \textcolor{keywordtype}{pointer}       :: OBC\textcolor{comment}{ !< Open boundaries control structure.}
753   \textcolor{comment}{! Local variables}
754   \textcolor{keywordtype}{real}, \textcolor{keywordtype}{dimension(SZIB\_(G),SZK\_(G))} :: &
755     uh\_aux, &  \textcolor{comment}{! An auxiliary zonal volume flux [H L2 s-1 ~> m3 s-1 or kg s-1].}
756     duhdu      \textcolor{comment}{! Partial derivative of uh with u [H L ~> m2 or kg m-1].}
757   \textcolor{keywordtype}{real}, \textcolor{keywordtype}{dimension(SZIB\_(G))} :: &
758     uh\_err, &  \textcolor{comment}{! Difference between uhbt and the summed uh [H L2 T-1 ~> m3 s-1 or kg s-1].}
759     uh\_err\_best, & \textcolor{comment}{! The smallest value of uh\_err found so far [H L2 T-1 ~> m3 s-1 or kg s-1].}
760     u\_new, &   \textcolor{comment}{! The velocity with the correction added [L T-1 ~> m s-1].}
761     duhdu\_tot,&\textcolor{comment}{! Summed partial derivative of uh with u [H L ~> m2 or kg m-1].}
762     du\_min, &  \textcolor{comment}{! Min/max limits on du correction based on CFL limits}
763     du\_max     \textcolor{comment}{! and previous iterations [L T-1 ~> m s-1].}
764   \textcolor{keywordtype}{real} :: du\_prev \textcolor{comment}{! The previous value of du [L T-1 ~> m s-1].}
765   \textcolor{keywordtype}{real} :: ddu    \textcolor{comment}{! The change in du from the previous iteration [L T-1 ~> m s-1].}
766   \textcolor{keywordtype}{real} :: tol\_eta \textcolor{comment}{! The tolerance for the current iteration [H ~> m or kg m-2].}
767   \textcolor{keywordtype}{real} :: tol\_vel \textcolor{comment}{! The tolerance for velocity in the current iteration [L T-1 ~> m s-1].}
768   \textcolor{keywordtype}{integer} :: i, k, nz, itt, max\_itts = 20
769   \textcolor{keywordtype}{logical} :: full\_prec, domore, do\_I(SZIB\_(G))
770 
771   nz = g%ke
772   full\_prec = .true. ; \textcolor{keywordflow}{if} (\textcolor{keyword}{present}(full\_precision)) full\_prec = full\_precision
773 
774   uh\_aux(:,:) = 0.0 ; duhdu(:,:) = 0.0
775 
776   \textcolor{keywordflow}{if} (\textcolor{keyword}{present}(uh\_3d)) \textcolor{keywordflow}{then} ; \textcolor{keywordflow}{do} k=1,nz ; \textcolor{keywordflow}{do} i=ish-1,ieh
777     uh\_aux(i,k) = uh\_3d(i,j,k)
778 \textcolor{keywordflow}{  enddo} ;\textcolor{keywordflow}{ enddo} ;\textcolor{keywordflow}{ endif}
779 
780   \textcolor{keywordflow}{do} i=ish-1,ieh
781     du(i) = 0.0 ; do\_i(i) = do\_i\_in(i)
782     du\_max(i) = du\_max\_cfl(i) ; du\_min(i) = du\_min\_cfl(i)
783     uh\_err(i) = uh\_tot\_0(i) - uhbt(i) ; duhdu\_tot(i) = duhdu\_tot\_0(i)
784     uh\_err\_best(i) = abs(uh\_err(i))
785 \textcolor{keywordflow}{  enddo}
786 
787   \textcolor{keywordflow}{do} itt=1,max\_itts
788     \textcolor{keywordflow}{if} (full\_prec) \textcolor{keywordflow}{then}
789       \textcolor{keywordflow}{select case} (itt)
790         \textcolor{keywordflow}{case} (:1) ; tol\_eta = 1e-6 * cs%tol\_eta
791         \textcolor{keywordflow}{case} (2)  ; tol\_eta = 1e-4 * cs%tol\_eta
792         \textcolor{keywordflow}{case} (3)  ; tol\_eta = 1e-2 * cs%tol\_eta
793 \textcolor{keywordflow}{        case default} ; tol\_eta = cs%tol\_eta
794 \textcolor{keywordflow}{      end select}
795     \textcolor{keywordflow}{else}
796       tol\_eta = cs%tol\_eta\_aux ; \textcolor{keywordflow}{if} (itt<=1) tol\_eta = 1e-6 * cs%tol\_eta\_aux
797 \textcolor{keywordflow}{    endif}
798     tol\_vel = cs%tol\_vel
799 
800     \textcolor{keywordflow}{do} i=ish-1,ieh
801       \textcolor{keywordflow}{if} (uh\_err(i) > 0.0) \textcolor{keywordflow}{then} ; du\_max(i) = du(i)
802       \textcolor{keywordflow}{elseif} (uh\_err(i) < 0.0) \textcolor{keywordflow}{then} ; du\_min(i) = du(i)
803       \textcolor{keywordflow}{else} ; do\_i(i) = .false. ;\textcolor{keywordflow}{ endif}
804 \textcolor{keywordflow}{    enddo}
805     domore = .false.
806     \textcolor{keywordflow}{do} i=ish-1,ieh ; \textcolor{keywordflow}{if} (do\_i(i)) \textcolor{keywordflow}{then}
807       \textcolor{keywordflow}{if} ((dt * min(g%IareaT(i,j),g%IareaT(i+1,j))*abs(uh\_err(i)) > tol\_eta) .or. &
808           (cs%better\_iter .and. ((abs(uh\_err(i)) > tol\_vel * duhdu\_tot(i)) .or. &
809                                  (abs(uh\_err(i)) > uh\_err\_best(i))) )) \textcolor{keywordflow}{then}
810         \textcolor{comment}{!   Use Newton's method, provided it stays bounded.  Otherwise bisect}
811         \textcolor{comment}{! the value with the appropriate bound.}
812         \textcolor{keywordflow}{if} (full\_prec) \textcolor{keywordflow}{then}
813           ddu = -uh\_err(i) / duhdu\_tot(i)
814           du\_prev = du(i)
815           du(i) = du(i) + ddu
816           \textcolor{keywordflow}{if} (abs(ddu) < 1.0e-15*abs(du(i))) \textcolor{keywordflow}{then}
817             do\_i(i) = .false. \textcolor{comment}{! ddu is small enough to quit.}
818           \textcolor{keywordflow}{elseif} (ddu > 0.0) \textcolor{keywordflow}{then}
819             \textcolor{keywordflow}{if} (du(i) >= du\_max(i)) \textcolor{keywordflow}{then}
820               du(i) = 0.5*(du\_prev + du\_max(i))
821               \textcolor{keywordflow}{if} (du\_max(i) - du\_prev < 1.0e-15*abs(du(i))) do\_i(i) = .false.
822 \textcolor{keywordflow}{            endif}
823           \textcolor{keywordflow}{else} \textcolor{comment}{! ddu < 0.0}
824             \textcolor{keywordflow}{if} (du(i) <= du\_min(i)) \textcolor{keywordflow}{then}
825               du(i) = 0.5*(du\_prev + du\_min(i))
826               \textcolor{keywordflow}{if} (du\_prev - du\_min(i) < 1.0e-15*abs(du(i))) do\_i(i) = .false.
827 \textcolor{keywordflow}{            endif}
828 \textcolor{keywordflow}{          endif}
829         \textcolor{keywordflow}{else}
830           \textcolor{comment}{!   Use Newton's method, provided it stays bounded, just like above.}
831           du(i) = du(i) - uh\_err(i) / duhdu\_tot(i)
832           \textcolor{keywordflow}{if} ((du(i) >= du\_max(i)) .or. (du(i) <= du\_min(i))) &
833             du(i) = 0.5*(du\_max(i) + du\_min(i))
834 \textcolor{keywordflow}{        endif}
835         \textcolor{keywordflow}{if} (do\_i(i)) domore = .true.
836       \textcolor{keywordflow}{else}
837         do\_i(i) = .false.
838 \textcolor{keywordflow}{      endif}
839 \textcolor{keywordflow}{    endif} ;\textcolor{keywordflow}{ enddo}
840     \textcolor{keywordflow}{if} (.not.domore) \textcolor{keywordflow}{exit}
841 
842     \textcolor{keywordflow}{if} ((itt < max\_itts) .or. \textcolor{keyword}{present}(uh\_3d)) \textcolor{keywordflow}{then} ; \textcolor{keywordflow}{do} k=1,nz
843       \textcolor{keywordflow}{do} i=ish-1,ieh ; u\_new(i) = u(i,j,k) + du(i) * visc\_rem(i,k) ;\textcolor{keywordflow}{ enddo}
844       \textcolor{keyword}{call }zonal\_flux\_layer(u\_new, h\_in(:,j,k), h\_l(:,j,k), h\_r(:,j,k), &
845                             uh\_aux(:,k), duhdu(:,k), visc\_rem(:,k), &
846                             dt, g, us, j, ish, ieh, do\_i, cs%vol\_CFL, obc)
847 \textcolor{keywordflow}{    enddo} ;\textcolor{keywordflow}{ endif}
848 
849     \textcolor{keywordflow}{if} (itt < max\_itts) \textcolor{keywordflow}{then}
850       \textcolor{keywordflow}{do} i=ish-1,ieh
851         uh\_err(i) = -uhbt(i) ; duhdu\_tot(i) = 0.0
852 \textcolor{keywordflow}{      enddo}
853       \textcolor{keywordflow}{do} k=1,nz ; \textcolor{keywordflow}{do} i=ish-1,ieh
854         uh\_err(i) = uh\_err(i) + uh\_aux(i,k)
855         duhdu\_tot(i) = duhdu\_tot(i) + duhdu(i,k)
856 \textcolor{keywordflow}{      enddo} ;\textcolor{keywordflow}{ enddo}
857       \textcolor{keywordflow}{do} i=ish-1,ieh
858         uh\_err\_best(i) = min(uh\_err\_best(i), abs(uh\_err(i)))
859 \textcolor{keywordflow}{      enddo}
860 \textcolor{keywordflow}{    endif}
861 \textcolor{keywordflow}{  enddo} \textcolor{comment}{! itt-loop}
862   \textcolor{comment}{! If there are any faces which have not converged to within the tolerance,}
863   \textcolor{comment}{! so-be-it, or else use a final upwind correction?}
864   \textcolor{comment}{! This never seems to happen with 20 iterations as max\_itt.}
865 
866   \textcolor{keywordflow}{if} (\textcolor{keyword}{present}(uh\_3d)) \textcolor{keywordflow}{then} ; \textcolor{keywordflow}{do} k=1,nz ; \textcolor{keywordflow}{do} i=ish-1,ieh
867     uh\_3d(i,j,k) = uh\_aux(i,k)
868 \textcolor{keywordflow}{  enddo} ;\textcolor{keywordflow}{ enddo} ;\textcolor{keywordflow}{ endif}
869 
\end{DoxyCode}
\mbox{\Hypertarget{namespacemom__continuity__ppm_a713196d0cfe6cb4cc8a91239a8dba02d}\label{namespacemom__continuity__ppm_a713196d0cfe6cb4cc8a91239a8dba02d}} 
\index{mom\+\_\+continuity\+\_\+ppm@{mom\+\_\+continuity\+\_\+ppm}!zonal\+\_\+flux\+\_\+layer@{zonal\+\_\+flux\+\_\+layer}}
\index{zonal\+\_\+flux\+\_\+layer@{zonal\+\_\+flux\+\_\+layer}!mom\+\_\+continuity\+\_\+ppm@{mom\+\_\+continuity\+\_\+ppm}}
\subsubsection{\texorpdfstring{zonal\+\_\+flux\+\_\+layer()}{zonal\_flux\_layer()}}
{\footnotesize\ttfamily subroutine mom\+\_\+continuity\+\_\+ppm\+::zonal\+\_\+flux\+\_\+layer (\begin{DoxyParamCaption}\item[{real, dimension( g \%isdb\+: g \%iedb), intent(in)}]{u,  }\item[{real, dimension(szi\+\_\+(g)), intent(in)}]{h,  }\item[{real, dimension(szi\+\_\+(g)), intent(in)}]{h\+\_\+L,  }\item[{real, dimension(szi\+\_\+(g)), intent(in)}]{h\+\_\+R,  }\item[{real, dimension(szib\+\_\+(g)), intent(inout)}]{uh,  }\item[{real, dimension(szib\+\_\+(g)), intent(inout)}]{duhdu,  }\item[{real, dimension( g \%isdb\+: g \%iedb), intent(in)}]{visc\+\_\+rem,  }\item[{real, intent(in)}]{dt,  }\item[{type(ocean\+\_\+grid\+\_\+type), intent(inout)}]{G,  }\item[{type(unit\+\_\+scale\+\_\+type), intent(in)}]{US,  }\item[{integer, intent(in)}]{j,  }\item[{integer, intent(in)}]{ish,  }\item[{integer, intent(in)}]{ieh,  }\item[{logical, dimension(szib\+\_\+(g)), intent(in)}]{do\+\_\+I,  }\item[{logical, intent(in)}]{vol\+\_\+\+C\+FL,  }\item[{type(ocean\+\_\+obc\+\_\+type), optional, pointer}]{O\+BC }\end{DoxyParamCaption})\hspace{0.3cm}{\ttfamily [private]}}



Evaluates the zonal mass or volume fluxes in a layer. 


\begin{DoxyParams}[1]{Parameters}
\mbox{\tt in,out}  & {\em g} & Ocean\textquotesingle{}s grid structure.\\
\hline
\mbox{\tt in}  & {\em u} & Zonal velocity \mbox{[}L T-\/1 $\sim$$>$ m s-\/1\mbox{]}.\\
\hline
\mbox{\tt in}  & {\em visc\+\_\+rem} & Both the fraction of the momentum originally in a layer that remains after a time-\/step of viscosity, and the fraction of a time-\/step\textquotesingle{}s worth of a barotropic acceleration that a layer experiences after viscosity is applied. Non-\/dimensional between 0 (at the bottom) and 1 (far above the bottom).\\
\hline
\mbox{\tt in}  & {\em h} & Layer thickness \mbox{[}H $\sim$$>$ m or kg m-\/2\mbox{]}.\\
\hline
\mbox{\tt in}  & {\em h\+\_\+l} & Left thickness \mbox{[}H $\sim$$>$ m or kg m-\/2\mbox{]}.\\
\hline
\mbox{\tt in}  & {\em h\+\_\+r} & Right thickness \mbox{[}H $\sim$$>$ m or kg m-\/2\mbox{]}.\\
\hline
\mbox{\tt in,out}  & {\em uh} & Zonal mass or volume transport \mbox{[}H L2 T-\/1 $\sim$$>$ m3 s-\/1 or kg s-\/1\mbox{]}.\\
\hline
\mbox{\tt in,out}  & {\em duhdu} & Partial derivative of uh with u \mbox{[}H L $\sim$$>$ m2 or kg m-\/1\mbox{]}.\\
\hline
\mbox{\tt in}  & {\em dt} & Time increment \mbox{[}T $\sim$$>$ s\mbox{]}.\\
\hline
\mbox{\tt in}  & {\em us} & A dimensional unit scaling type\\
\hline
\mbox{\tt in}  & {\em j} & Spatial index.\\
\hline
\mbox{\tt in}  & {\em ish} & Start of index range.\\
\hline
\mbox{\tt in}  & {\em ieh} & End of index range.\\
\hline
\mbox{\tt in}  & {\em do\+\_\+i} & Which i values to work on.\\
\hline
\mbox{\tt in}  & {\em vol\+\_\+cfl} & If true, rescale the ratio of face areas to the cell areas when estimating the C\+FL number.\\
\hline
 & {\em obc} & Open boundaries control structure. \\
\hline
\end{DoxyParams}


Definition at line 523 of file M\+O\+M\+\_\+continuity\+\_\+\+P\+P\+M.\+F90.


\begin{DoxyCode}
523   \textcolor{keywordtype}{type}(ocean\_grid\_type),        \textcolor{keywordtype}{intent(inout)} :: G\textcolor{comment}{        !< Ocean's grid structure.}
524   \textcolor{keywordtype}{real}, \textcolor{keywordtype}{dimension(SZIB\_(G))},    \textcolor{keywordtype}{intent(in)}    :: u\textcolor{comment}{        !< Zonal velocity [L T-1 ~> m s-1].}
525   \textcolor{keywordtype}{real}, \textcolor{keywordtype}{dimension(SZIB\_(G))},    \textcolor{keywordtype}{intent(in)}    :: visc\_rem\textcolor{comment}{ !< Both the fraction of the}
526 \textcolor{comment}{                        !! momentum originally in a layer that remains after a time-step}
527 \textcolor{comment}{                        !! of viscosity, and the fraction of a time-step's worth of a barotropic}
528 \textcolor{comment}{                        !! acceleration that a layer experiences after viscosity is applied.}
529 \textcolor{comment}{                        !! Non-dimensional between 0 (at the bottom) and 1 (far above the bottom).}
530   \textcolor{keywordtype}{real}, \textcolor{keywordtype}{dimension(SZI\_(G))},     \textcolor{keywordtype}{intent(in)}    :: h\textcolor{comment}{        !< Layer thickness [H ~> m or kg m-2].}
531   \textcolor{keywordtype}{real}, \textcolor{keywordtype}{dimension(SZI\_(G))},     \textcolor{keywordtype}{intent(in)}    :: h\_L\textcolor{comment}{      !< Left thickness [H ~> m or kg m-2].}
532   \textcolor{keywordtype}{real}, \textcolor{keywordtype}{dimension(SZI\_(G))},     \textcolor{keywordtype}{intent(in)}    :: h\_R\textcolor{comment}{      !< Right thickness [H ~> m or kg m-2].}
533   \textcolor{keywordtype}{real}, \textcolor{keywordtype}{dimension(SZIB\_(G))},    \textcolor{keywordtype}{intent(inout)} :: uh\textcolor{comment}{       !< Zonal mass or volume}
534 \textcolor{comment}{                                                          !! transport [H L2 T-1 ~> m3 s-1 or kg s-1].}
535   \textcolor{keywordtype}{real}, \textcolor{keywordtype}{dimension(SZIB\_(G))},    \textcolor{keywordtype}{intent(inout)} :: duhdu\textcolor{comment}{    !< Partial derivative of uh}
536 \textcolor{comment}{                                                          !! with u [H L ~> m2 or kg m-1].}
537   \textcolor{keywordtype}{real},                         \textcolor{keywordtype}{intent(in)}    :: dt\textcolor{comment}{  !< Time increment [T ~> s].}
538   \textcolor{keywordtype}{type}(unit\_scale\_type),        \textcolor{keywordtype}{intent(in)}    :: US\textcolor{comment}{       !< A dimensional unit scaling type}
539   \textcolor{keywordtype}{integer},                      \textcolor{keywordtype}{intent(in)}    :: j\textcolor{comment}{        !< Spatial index.}
540   \textcolor{keywordtype}{integer},                      \textcolor{keywordtype}{intent(in)}    :: ish\textcolor{comment}{      !< Start of index range.}
541   \textcolor{keywordtype}{integer},                      \textcolor{keywordtype}{intent(in)}    :: ieh\textcolor{comment}{      !< End of index range.}
542   \textcolor{keywordtype}{logical}, \textcolor{keywordtype}{dimension(SZIB\_(G))}, \textcolor{keywordtype}{intent(in)}    :: do\_I\textcolor{comment}{     !< Which i values to work on.}
543   \textcolor{keywordtype}{logical},                      \textcolor{keywordtype}{intent(in)}    :: vol\_CFL\textcolor{comment}{  !< If true, rescale the}
544 \textcolor{comment}{          !! ratio of face areas to the cell areas when estimating the CFL number.}
545   \textcolor{keywordtype}{type}(ocean\_OBC\_type), \textcolor{keywordtype}{optional}, \textcolor{keywordtype}{pointer}     :: OBC\textcolor{comment}{ !< Open boundaries control structure.}
546   \textcolor{comment}{! Local variables}
547   \textcolor{keywordtype}{real} :: CFL  \textcolor{comment}{! The CFL number based on the local velocity and grid spacing [nondim]}
548   \textcolor{keywordtype}{real} :: curv\_3 \textcolor{comment}{! A measure of the thickness curvature over a grid length,}
549                  \textcolor{comment}{! with the same units as h\_in.}
550   \textcolor{keywordtype}{real} :: h\_marg \textcolor{comment}{! The marginal thickness of a flux [H ~> m or kg m-2].}
551   \textcolor{keywordtype}{integer} :: i
552   \textcolor{keywordtype}{integer} :: l\_seg
553   \textcolor{keywordtype}{logical} :: local\_open\_BC
554 
555   local\_open\_bc = .false.
556   \textcolor{keywordflow}{if} (\textcolor{keyword}{present}(obc)) \textcolor{keywordflow}{then} ; \textcolor{keywordflow}{if} (\textcolor{keyword}{associated}(obc)) \textcolor{keywordflow}{then}
557     local\_open\_bc = obc%open\_u\_BCs\_exist\_globally
558 \textcolor{keywordflow}{  endif} ;\textcolor{keywordflow}{ endif}
559 
560   \textcolor{keywordflow}{do} i=ish-1,ieh ; \textcolor{keywordflow}{if} (do\_i(i)) \textcolor{keywordflow}{then}
561     \textcolor{comment}{! Set new values of uh and duhdu.}
562     \textcolor{keywordflow}{if} (u(i) > 0.0) \textcolor{keywordflow}{then}
563       \textcolor{keywordflow}{if} (vol\_cfl) \textcolor{keywordflow}{then} ; cfl = (u(i) * dt) * (g%dy\_Cu(i,j) * g%IareaT(i,j))
564       \textcolor{keywordflow}{else} ; cfl = u(i) * dt * g%IdxT(i,j) ;\textcolor{keywordflow}{ endif}
565       curv\_3 = h\_l(i) + h\_r(i) - 2.0*h(i)
566       uh(i) = g%dy\_Cu(i,j) * u(i) * &
567           (h\_r(i) + cfl * (0.5*(h\_l(i) - h\_r(i)) + curv\_3*(cfl - 1.5)))
568       h\_marg = h\_r(i) + cfl * ((h\_l(i) - h\_r(i)) + 3.0*curv\_3*(cfl - 1.0))
569     \textcolor{keywordflow}{elseif} (u(i) < 0.0) \textcolor{keywordflow}{then}
570       \textcolor{keywordflow}{if} (vol\_cfl) \textcolor{keywordflow}{then} ; cfl = (-u(i) * dt) * (g%dy\_Cu(i,j) * g%IareaT(i+1,j))
571       \textcolor{keywordflow}{else} ; cfl = -u(i) * dt * g%IdxT(i+1,j) ;\textcolor{keywordflow}{ endif}
572       curv\_3 = h\_l(i+1) + h\_r(i+1) - 2.0*h(i+1)
573       uh(i) = g%dy\_Cu(i,j) * u(i) * &
574           (h\_l(i+1) + cfl * (0.5*(h\_r(i+1)-h\_l(i+1)) + curv\_3*(cfl - 1.5)))
575       h\_marg = h\_l(i+1) + cfl * ((h\_r(i+1)-h\_l(i+1)) + 3.0*curv\_3*(cfl - 1.0))
576     \textcolor{keywordflow}{else}
577       uh(i) = 0.0
578       h\_marg = 0.5 * (h\_l(i+1) + h\_r(i))
579 \textcolor{keywordflow}{    endif}
580     duhdu(i) = g%dy\_Cu(i,j) * h\_marg * visc\_rem(i)
581 \textcolor{keywordflow}{  endif} ;\textcolor{keywordflow}{ enddo}
582 
583   \textcolor{keywordflow}{if} (local\_open\_bc) \textcolor{keywordflow}{then}
584     \textcolor{keywordflow}{do} i=ish-1,ieh ; \textcolor{keywordflow}{if} (do\_i(i)) \textcolor{keywordflow}{then}
585       l\_seg = obc%segnum\_u(i,j)
586 
587       \textcolor{keywordflow}{if} (l\_seg /= obc\_none) \textcolor{keywordflow}{then}
588         \textcolor{keywordflow}{if} (obc%segment(l\_seg)%open) \textcolor{keywordflow}{then}
589           \textcolor{keywordflow}{if} (obc%segment(l\_seg)%direction == obc\_direction\_e) \textcolor{keywordflow}{then}
590             uh(i) = g%dy\_Cu(i,j) * u(i) * h(i)
591             duhdu(i) = g%dy\_Cu(i,j) * h(i) * visc\_rem(i)
592           \textcolor{keywordflow}{else}
593             uh(i) = g%dy\_Cu(i,j) * u(i) * h(i+1)
594             duhdu(i) = g%dy\_Cu(i,j) * h(i+1) * visc\_rem(i)
595 \textcolor{keywordflow}{          endif}
596 \textcolor{keywordflow}{        endif}
597 \textcolor{keywordflow}{      endif}
598 \textcolor{keywordflow}{    endif} ;\textcolor{keywordflow}{ enddo}
599 \textcolor{keywordflow}{  endif}
\end{DoxyCode}
\mbox{\Hypertarget{namespacemom__continuity__ppm_a5f5d6764ed315043d3b91b209db5c0a0}\label{namespacemom__continuity__ppm_a5f5d6764ed315043d3b91b209db5c0a0}} 
\index{mom\+\_\+continuity\+\_\+ppm@{mom\+\_\+continuity\+\_\+ppm}!zonal\+\_\+mass\+\_\+flux@{zonal\+\_\+mass\+\_\+flux}}
\index{zonal\+\_\+mass\+\_\+flux@{zonal\+\_\+mass\+\_\+flux}!mom\+\_\+continuity\+\_\+ppm@{mom\+\_\+continuity\+\_\+ppm}}
\subsubsection{\texorpdfstring{zonal\+\_\+mass\+\_\+flux()}{zonal\_mass\_flux()}}
{\footnotesize\ttfamily subroutine mom\+\_\+continuity\+\_\+ppm\+::zonal\+\_\+mass\+\_\+flux (\begin{DoxyParamCaption}\item[{real, dimension( g \%isdb\+: g \%iedb, g \%jsd\+: g \%jed, g \%ke), intent(in)}]{u,  }\item[{real, dimension( g \%isd\+: g \%ied, g \%jsd\+: g \%jed, g \%ke), intent(in)}]{h\+\_\+in,  }\item[{real, dimension( g \%isdb\+: g \%iedb, g \%jsd\+: g \%jed, g \%ke), intent(out)}]{uh,  }\item[{real, intent(in)}]{dt,  }\item[{type(ocean\+\_\+grid\+\_\+type), intent(inout)}]{G,  }\item[{type(verticalgrid\+\_\+type), intent(in)}]{GV,  }\item[{type(unit\+\_\+scale\+\_\+type), intent(in)}]{US,  }\item[{type(\mbox{\hyperlink{structmom__continuity__ppm_1_1continuity__ppm__cs}{continuity\+\_\+ppm\+\_\+cs}}), pointer}]{CS,  }\item[{type(\mbox{\hyperlink{structmom__continuity__ppm_1_1loop__bounds__type}{loop\+\_\+bounds\+\_\+type}}), intent(in)}]{LB,  }\item[{real, dimension( g \%isdb\+: g \%iedb, g \%jsd\+: g \%jed), intent(in), optional}]{uhbt,  }\item[{type(ocean\+\_\+obc\+\_\+type), optional, pointer}]{O\+BC,  }\item[{real, dimension(szib\+\_\+(g),szj\+\_\+(g),szk\+\_\+(g)), intent(in), optional}]{visc\+\_\+rem\+\_\+u,  }\item[{real, dimension( g \%isdb\+: g \%iedb, g \%jsd\+: g \%jed, g \%ke), intent(out), optional}]{u\+\_\+cor,  }\item[{type(bt\+\_\+cont\+\_\+type), optional, pointer}]{B\+T\+\_\+cont }\end{DoxyParamCaption})\hspace{0.3cm}{\ttfamily [private]}}



Calculates the mass or volume fluxes through the zonal faces, and other related quantities. 


\begin{DoxyParams}[1]{Parameters}
\mbox{\tt in,out}  & {\em g} & Ocean\textquotesingle{}s grid structure.\\
\hline
\mbox{\tt in}  & {\em gv} & Ocean\textquotesingle{}s vertical grid structure.\\
\hline
\mbox{\tt in}  & {\em u} & Zonal velocity \mbox{[}L T-\/1 $\sim$$>$ m s-\/1\mbox{]}.\\
\hline
\mbox{\tt in}  & {\em h\+\_\+in} & Layer thickness used to calculate fluxes \mbox{[}H $\sim$$>$ m or kg m-\/2\mbox{]}.\\
\hline
\mbox{\tt out}  & {\em uh} & Volume flux through zonal faces = u$\ast$h$\ast$dy\\
\hline
\mbox{\tt in}  & {\em dt} & Time increment \mbox{[}T $\sim$$>$ s\mbox{]}.\\
\hline
\mbox{\tt in}  & {\em us} & A dimensional unit scaling type\\
\hline
 & {\em cs} & This module\textquotesingle{}s control structure.\\
\hline
\mbox{\tt in}  & {\em lb} & Loop bounds structure.\\
\hline
 & {\em obc} & Open boundaries control structure.\\
\hline
\mbox{\tt in}  & {\em visc\+\_\+rem\+\_\+u} & The fraction of zonal momentum originally in a layer that remains after a time-\/step of viscosity, and the fraction of a time-\/step\textquotesingle{}s worth of a barotropic acceleration that a layer experiences after viscosity is applied. Non-\/dimensional between 0 (at the bottom) and 1 (far above the bottom).\\
\hline
\mbox{\tt in}  & {\em uhbt} & The summed volume flux through zonal faces\\
\hline
\mbox{\tt out}  & {\em u\+\_\+cor} & The zonal velocitiess (u with a barotropic correction) that give uhbt as the depth-\/integrated transport, m s-\/1.\\
\hline
 & {\em bt\+\_\+cont} & A structure with elements that describe the effective open face areas as a function of barotropic flow. \\
\hline
\end{DoxyParams}


Definition at line 213 of file M\+O\+M\+\_\+continuity\+\_\+\+P\+P\+M.\+F90.


\begin{DoxyCode}
213   \textcolor{keywordtype}{type}(ocean\_grid\_type),   \textcolor{keywordtype}{intent(inout)} :: G\textcolor{comment}{    !< Ocean's grid structure.}
214   \textcolor{keywordtype}{type}(verticalGrid\_type), \textcolor{keywordtype}{intent(in)}    :: GV\textcolor{comment}{   !< Ocean's vertical grid structure.}
215   \textcolor{keywordtype}{real}, \textcolor{keywordtype}{dimension(SZIB\_(G),SZJ\_(G),SZK\_(G))}, &
216                            \textcolor{keywordtype}{intent(in)}    :: u\textcolor{comment}{    !< Zonal velocity [L T-1 ~> m s-1].}
217   \textcolor{keywordtype}{real},  \textcolor{keywordtype}{dimension(SZI\_(G),SZJ\_(G),SZK\_(G))}, &
218                            \textcolor{keywordtype}{intent(in)}    :: h\_in\textcolor{comment}{ !< Layer thickness used to calculate fluxes [H ~> m or kg
       m-2].}
219   \textcolor{keywordtype}{real}, \textcolor{keywordtype}{dimension(SZIB\_(G),SZJ\_(G),SZK\_(G))}, &
220                            \textcolor{keywordtype}{intent(out)}   :: uh\textcolor{comment}{   !< Volume flux through zonal faces = u*h*dy}
221 \textcolor{comment}{                                                 !! [H L2 T-1 ~> m3 s-1 or kg s-1].}
222   \textcolor{keywordtype}{real},                    \textcolor{keywordtype}{intent(in)}    :: dt\textcolor{comment}{   !< Time increment [T ~> s].}
223   \textcolor{keywordtype}{type}(unit\_scale\_type),   \textcolor{keywordtype}{intent(in)}    :: US\textcolor{comment}{   !< A dimensional unit scaling type}
224   \textcolor{keywordtype}{type}(continuity\_PPM\_CS), \textcolor{keywordtype}{pointer}       :: CS\textcolor{comment}{   !< This module's control structure.}
225   \textcolor{keywordtype}{type}(loop\_bounds\_type),  \textcolor{keywordtype}{intent(in)}    :: LB\textcolor{comment}{   !< Loop bounds structure.}
226   \textcolor{keywordtype}{type}(ocean\_OBC\_type), &
227                  \textcolor{keywordtype}{optional}, \textcolor{keywordtype}{pointer}       :: OBC\textcolor{comment}{  !< Open boundaries control structure.}
228   \textcolor{keywordtype}{real}, \textcolor{keywordtype}{dimension(SZIB\_(G),SZJ\_(G),SZK\_(G))}, &
229                  \textcolor{keywordtype}{optional}, \textcolor{keywordtype}{intent(in)}    :: visc\_rem\_u
230                      \textcolor{comment}{!< The fraction of zonal momentum originally in a layer that remains after a}
231 \textcolor{comment}{                     !! time-step of viscosity, and the fraction of a time-step's worth of a barotropic}
232 \textcolor{comment}{                     !! acceleration that a layer experiences after viscosity is applied.}
233 \textcolor{comment}{                     !! Non-dimensional between 0 (at the bottom) and 1 (far above the bottom).}
234   \textcolor{keywordtype}{real}, \textcolor{keywordtype}{dimension(SZIB\_(G),SZJ\_(G))}, &
235                  \textcolor{keywordtype}{optional}, \textcolor{keywordtype}{intent(in)}    :: uhbt\textcolor{comment}{ !< The summed volume flux through zonal faces}
236 \textcolor{comment}{                                                 !! [H L2 T-1 ~> m3 s-1 or kg s-1].}
237   \textcolor{keywordtype}{real}, \textcolor{keywordtype}{dimension(SZIB\_(G),SZJ\_(G),SZK\_(G))}, &
238                  \textcolor{keywordtype}{optional}, \textcolor{keywordtype}{intent(out)}   :: u\_cor
239                      \textcolor{comment}{!< The zonal velocitiess (u with a barotropic correction)}
240 \textcolor{comment}{                     !! that give uhbt as the depth-integrated transport, m s-1.}
241   \textcolor{keywordtype}{type}(BT\_cont\_type), \textcolor{keywordtype}{optional}, \textcolor{keywordtype}{pointer}  :: BT\_cont\textcolor{comment}{ !< A structure with elements that describe the}
242 \textcolor{comment}{                     !! effective open face areas as a function of barotropic flow.}
243 
244   \textcolor{comment}{! Local variables}
245   \textcolor{keywordtype}{real}, \textcolor{keywordtype}{dimension(SZIB\_(G),SZK\_(G))} :: duhdu \textcolor{comment}{! Partial derivative of uh with u [H L ~> m2 or kg m-1].}
246   \textcolor{keywordtype}{real}, \textcolor{keywordtype}{dimension(SZI\_(G),SZJ\_(G),SZK\_(G))} :: h\_L, h\_R \textcolor{comment}{! Left and right face thicknesses [H ~> m or kg
       m-2].}
247   \textcolor{keywordtype}{real}, \textcolor{keywordtype}{dimension(SZIB\_(G))} :: &
248     du, &      \textcolor{comment}{! Corrective barotropic change in the velocity [L T-1 ~> m s-1].}
249     du\_min\_CFL, & \textcolor{comment}{! Min/max limits on du correction}
250     du\_max\_CFL, & \textcolor{comment}{! to avoid CFL violations}
251     duhdu\_tot\_0, & \textcolor{comment}{! Summed partial derivative of uh with u [H L ~> m2 or kg m-1].}
252     uh\_tot\_0, & \textcolor{comment}{! Summed transport with no barotropic correction [H L2 T-1 ~> m3 s-1 or kg s-1].}
253     visc\_rem\_max  \textcolor{comment}{! The column maximum of visc\_rem.}
254   \textcolor{keywordtype}{logical}, \textcolor{keywordtype}{dimension(SZIB\_(G))} :: do\_I
255   \textcolor{keywordtype}{real}, \textcolor{keywordtype}{dimension(SZIB\_(G),SZK\_(G))} :: &
256     visc\_rem      \textcolor{comment}{! A 2-D copy of visc\_rem\_u or an array of 1's.}
257   \textcolor{keywordtype}{real}, \textcolor{keywordtype}{dimension(SZIB\_(G))} :: FAuI  \textcolor{comment}{! A list of sums of zonal face areas [H L ~> m2 or kg m-1].}
258   \textcolor{keywordtype}{real} :: FA\_u    \textcolor{comment}{! A sum of zonal face areas [H m ~> m2 or kg m-1].}
259   \textcolor{keywordtype}{real} :: I\_vrm   \textcolor{comment}{! 1.0 / visc\_rem\_max, nondim.}
260   \textcolor{keywordtype}{real} :: CFL\_dt  \textcolor{comment}{! The maximum CFL ratio of the adjusted velocities divided by}
261                   \textcolor{comment}{! the time step [T-1 ~> s-1].}
262   \textcolor{keywordtype}{real} :: I\_dt    \textcolor{comment}{! 1.0 / dt [T-1 ~> s-1].}
263   \textcolor{keywordtype}{real} :: du\_lim  \textcolor{comment}{! The velocity change that give a relative CFL of 1 [L T-1 ~> m s-1].}
264   \textcolor{keywordtype}{real} :: dx\_E, dx\_W \textcolor{comment}{! Effective x-grid spacings to the east and west [L ~> m].}
265   \textcolor{keywordtype}{integer} :: i, j, k, ish, ieh, jsh, jeh, n, nz
266   \textcolor{keywordtype}{integer} :: l\_seg
267   \textcolor{keywordtype}{logical} :: local\_specified\_BC, use\_visc\_rem, set\_BT\_cont, any\_simple\_OBC
268   \textcolor{keywordtype}{logical} :: local\_Flather\_OBC, local\_open\_BC, is\_simple
269   \textcolor{keywordtype}{type}(OBC\_segment\_type), \textcolor{keywordtype}{pointer} :: segment => null()
270 
271   use\_visc\_rem = \textcolor{keyword}{present}(visc\_rem\_u)
272   local\_specified\_bc = .false. ; set\_bt\_cont = .false. ; local\_flather\_obc = .false.
273   local\_open\_bc = .false.
274   \textcolor{keywordflow}{if} (\textcolor{keyword}{present}(bt\_cont)) set\_bt\_cont = (\textcolor{keyword}{associated}(bt\_cont))
275   \textcolor{keywordflow}{if} (\textcolor{keyword}{present}(obc)) \textcolor{keywordflow}{then} ; \textcolor{keywordflow}{if} (\textcolor{keyword}{associated}(obc)) \textcolor{keywordflow}{then}
276     local\_specified\_bc = obc%specified\_u\_BCs\_exist\_globally
277     local\_flather\_obc = obc%Flather\_u\_BCs\_exist\_globally
278     local\_open\_bc = obc%open\_u\_BCs\_exist\_globally
279 \textcolor{keywordflow}{  endif} ;\textcolor{keywordflow}{ endif}
280   ish = lb%ish ; ieh = lb%ieh ; jsh = lb%jsh ; jeh = lb%jeh ; nz = g%ke
281 
282   cfl\_dt = cs%CFL\_limit\_adjust / dt
283   i\_dt = 1.0 / dt
284   \textcolor{keywordflow}{if} (cs%aggress\_adjust) cfl\_dt = i\_dt
285 
286   \textcolor{keyword}{call }cpu\_clock\_begin(id\_clock\_update)
287 \textcolor{comment}{!$OMP parallel do default(none) shared(ish,ieh,jsh,jeh,nz,CS,h\_L,h\_in,h\_R,G,GV,LB,visc\_rem,OBC)}
288   \textcolor{keywordflow}{do} k=1,nz
289     \textcolor{comment}{! This sets h\_L and h\_R.}
290     \textcolor{keywordflow}{if} (cs%upwind\_1st) \textcolor{keywordflow}{then}
291       \textcolor{keywordflow}{do} j=jsh,jeh ; \textcolor{keywordflow}{do} i=ish-1,ieh+1
292         h\_l(i,j,k) = h\_in(i,j,k) ; h\_r(i,j,k) = h\_in(i,j,k)
293 \textcolor{keywordflow}{      enddo} ;\textcolor{keywordflow}{ enddo}
294     \textcolor{keywordflow}{else}
295       \textcolor{keyword}{call }ppm\_reconstruction\_x(h\_in(:,:,k), h\_l(:,:,k), h\_r(:,:,k), g, lb, &
296                                 2.0*gv%Angstrom\_H, cs%monotonic, simple\_2nd=cs%simple\_2nd, obc=obc)
297 \textcolor{keywordflow}{    endif}
298     \textcolor{keywordflow}{do} i=ish-1,ieh ; visc\_rem(i,k) = 1.0 ;\textcolor{keywordflow}{ enddo}
299 \textcolor{keywordflow}{  enddo}
300   \textcolor{keyword}{call }cpu\_clock\_end(id\_clock\_update)
301 
302   \textcolor{keyword}{call }cpu\_clock\_begin(id\_clock\_correct)
303 \textcolor{comment}{!$OMP parallel do default(none) shared(ish,ieh,jsh,jeh,nz,u,h\_in,h\_L,h\_R,use\_visc\_rem,visc\_rem\_u,  &}
304 \textcolor{comment}{!$OMP                                  uh,dt,US,G,GV,CS,local\_specified\_BC,OBC,uhbt,set\_BT\_cont,    &}
305 \textcolor{comment}{!$OMP                                  CFL\_dt,I\_dt,u\_cor,BT\_cont, local\_Flather\_OBC) &}
306 \textcolor{comment}{!$OMP                          private(do\_I,duhdu,du,du\_max\_CFL,du\_min\_CFL,uh\_tot\_0,duhdu\_tot\_0, &}
307 \textcolor{comment}{!$OMP                                  is\_simple,FAuI,visc\_rem\_max,I\_vrm,du\_lim,dx\_E,dx\_W, &}
308 \textcolor{comment}{!$OMP                                  any\_simple\_OBC,l\_seg) &}
309 \textcolor{comment}{!$OMP      firstprivate(visc\_rem)}
310   \textcolor{keywordflow}{do} j=jsh,jeh
311     \textcolor{keywordflow}{do} i=ish-1,ieh ; do\_i(i) = .true. ; visc\_rem\_max(i) = 0.0 ;\textcolor{keywordflow}{ enddo}
312     \textcolor{comment}{! Set uh and duhdu.}
313     \textcolor{keywordflow}{do} k=1,nz
314       \textcolor{keywordflow}{if} (use\_visc\_rem) \textcolor{keywordflow}{then} ; \textcolor{keywordflow}{do} i=ish-1,ieh
315         visc\_rem(i,k) = visc\_rem\_u(i,j,k)
316         visc\_rem\_max(i) = max(visc\_rem\_max(i), visc\_rem(i,k))
317 \textcolor{keywordflow}{      enddo} ;\textcolor{keywordflow}{ endif}
318       \textcolor{keyword}{call }zonal\_flux\_layer(u(:,j,k), h\_in(:,j,k), h\_l(:,j,k), h\_r(:,j,k), &
319                             uh(:,j,k), duhdu(:,k), visc\_rem(:,k), &
320                             dt, g, us, j, ish, ieh, do\_i, cs%vol\_CFL, obc)
321       \textcolor{keywordflow}{if} (local\_specified\_bc) \textcolor{keywordflow}{then}
322         \textcolor{keywordflow}{do} i=ish-1,ieh
323           l\_seg = obc%segnum\_u(i,j)
324 
325           \textcolor{keywordflow}{if} (l\_seg /= obc\_none) \textcolor{keywordflow}{then}
326             \textcolor{keywordflow}{if} (obc%segment(l\_seg)%specified) &
327               uh(i,j,k) = obc%segment(l\_seg)%normal\_trans(i,j,k)
328 \textcolor{keywordflow}{          endif}
329 \textcolor{keywordflow}{        enddo}
330 \textcolor{keywordflow}{      endif}
331 \textcolor{keywordflow}{    enddo}
332 
333     \textcolor{keywordflow}{if} ((.not.use\_visc\_rem).or.(.not.cs%use\_visc\_rem\_max)) \textcolor{keywordflow}{then} ; \textcolor{keywordflow}{do} i=ish-1,ieh
334       visc\_rem\_max(i) = 1.0
335 \textcolor{keywordflow}{    enddo} ;\textcolor{keywordflow}{ endif}
336 
337     \textcolor{keywordflow}{if} (\textcolor{keyword}{present}(uhbt) .or. set\_bt\_cont) \textcolor{keywordflow}{then}
338       \textcolor{comment}{!   Set limits on du that will keep the CFL number between -1 and 1.}
339       \textcolor{comment}{! This should be adequate to keep the root bracketed in all cases.}
340       \textcolor{keywordflow}{do} i=ish-1,ieh
341         i\_vrm = 0.0
342         \textcolor{keywordflow}{if} (visc\_rem\_max(i) > 0.0) i\_vrm = 1.0 / visc\_rem\_max(i)
343         \textcolor{keywordflow}{if} (cs%vol\_CFL) \textcolor{keywordflow}{then}
344           dx\_w = ratio\_max(g%areaT(i,j), g%dy\_Cu(i,j), 1000.0*g%dxT(i,j))
345           dx\_e = ratio\_max(g%areaT(i+1,j), g%dy\_Cu(i,j), 1000.0*g%dxT(i+1,j))
346         \textcolor{keywordflow}{else} ; dx\_w = g%dxT(i,j) ; dx\_e = g%dxT(i+1,j) ;\textcolor{keywordflow}{ endif}
347         du\_max\_cfl(i) = 2.0* (cfl\_dt * dx\_w) * i\_vrm
348         du\_min\_cfl(i) = -2.0 * (cfl\_dt * dx\_e) * i\_vrm
349         uh\_tot\_0(i) = 0.0 ; duhdu\_tot\_0(i) = 0.0
350 \textcolor{keywordflow}{      enddo}
351       \textcolor{keywordflow}{do} k=1,nz ; \textcolor{keywordflow}{do} i=ish-1,ieh
352         duhdu\_tot\_0(i) = duhdu\_tot\_0(i) + duhdu(i,k)
353         uh\_tot\_0(i) = uh\_tot\_0(i) + uh(i,j,k)
354 \textcolor{keywordflow}{      enddo} ;\textcolor{keywordflow}{ enddo}
355       \textcolor{keywordflow}{if} (use\_visc\_rem) \textcolor{keywordflow}{then}
356         \textcolor{keywordflow}{if} (cs%aggress\_adjust) \textcolor{keywordflow}{then}
357           \textcolor{keywordflow}{do} k=1,nz ; \textcolor{keywordflow}{do} i=ish-1,ieh
358             \textcolor{keywordflow}{if} (cs%vol\_CFL) \textcolor{keywordflow}{then}
359               dx\_w = ratio\_max(g%areaT(i,j), g%dy\_Cu(i,j), 1000.0*g%dxT(i,j))
360               dx\_e = ratio\_max(g%areaT(i+1,j), g%dy\_Cu(i,j), 1000.0*g%dxT(i+1,j))
361             \textcolor{keywordflow}{else} ; dx\_w = g%dxT(i,j) ; dx\_e = g%dxT(i+1,j) ;\textcolor{keywordflow}{ endif}
362 
363             du\_lim = 0.499*((dx\_w*i\_dt - u(i,j,k)) + min(0.0,u(i-1,j,k)))
364             \textcolor{keywordflow}{if} (du\_max\_cfl(i) * visc\_rem(i,k) > du\_lim) &
365               du\_max\_cfl(i) = du\_lim / visc\_rem(i,k)
366 
367             du\_lim = 0.499*((-dx\_e*i\_dt - u(i,j,k)) + max(0.0,u(i+1,j,k)))
368             \textcolor{keywordflow}{if} (du\_min\_cfl(i) * visc\_rem(i,k) < du\_lim) &
369               du\_min\_cfl(i) = du\_lim / visc\_rem(i,k)
370 \textcolor{keywordflow}{          enddo} ;\textcolor{keywordflow}{ enddo}
371         \textcolor{keywordflow}{else}
372           \textcolor{keywordflow}{do} k=1,nz ; \textcolor{keywordflow}{do} i=ish-1,ieh
373             \textcolor{keywordflow}{if} (cs%vol\_CFL) \textcolor{keywordflow}{then}
374               dx\_w = ratio\_max(g%areaT(i,j), g%dy\_Cu(i,j), 1000.0*g%dxT(i,j))
375               dx\_e = ratio\_max(g%areaT(i+1,j), g%dy\_Cu(i,j), 1000.0*g%dxT(i+1,j))
376             \textcolor{keywordflow}{else} ; dx\_w = g%dxT(i,j) ; dx\_e = g%dxT(i+1,j) ;\textcolor{keywordflow}{ endif}
377 
378             \textcolor{keywordflow}{if} (du\_max\_cfl(i) * visc\_rem(i,k) > dx\_w*cfl\_dt - u(i,j,k)) &
379               du\_max\_cfl(i) = (dx\_w*cfl\_dt - u(i,j,k)) / visc\_rem(i,k)
380             \textcolor{keywordflow}{if} (du\_min\_cfl(i) * visc\_rem(i,k) < -dx\_e*cfl\_dt - u(i,j,k)) &
381               du\_min\_cfl(i) = -(dx\_e*cfl\_dt + u(i,j,k)) / visc\_rem(i,k)
382 \textcolor{keywordflow}{          enddo} ;\textcolor{keywordflow}{ enddo}
383 \textcolor{keywordflow}{        endif}
384       \textcolor{keywordflow}{else}
385         \textcolor{keywordflow}{if} (cs%aggress\_adjust) \textcolor{keywordflow}{then}
386           \textcolor{keywordflow}{do} k=1,nz ; \textcolor{keywordflow}{do} i=ish-1,ieh
387             \textcolor{keywordflow}{if} (cs%vol\_CFL) \textcolor{keywordflow}{then}
388               dx\_w = ratio\_max(g%areaT(i,j), g%dy\_Cu(i,j), 1000.0*g%dxT(i,j))
389               dx\_e = ratio\_max(g%areaT(i+1,j), g%dy\_Cu(i,j), 1000.0*g%dxT(i+1,j))
390             \textcolor{keywordflow}{else} ; dx\_w = g%dxT(i,j) ; dx\_e = g%dxT(i+1,j) ;\textcolor{keywordflow}{ endif}
391 
392             du\_max\_cfl(i) = min(du\_max\_cfl(i), 0.499 * &
393                         ((dx\_w*i\_dt - u(i,j,k)) + min(0.0,u(i-1,j,k))) )
394             du\_min\_cfl(i) = max(du\_min\_cfl(i), 0.499 * &
395                         ((-dx\_e*i\_dt - u(i,j,k)) + max(0.0,u(i+1,j,k))) )
396 \textcolor{keywordflow}{          enddo} ;\textcolor{keywordflow}{ enddo}
397         \textcolor{keywordflow}{else}
398           \textcolor{keywordflow}{do} k=1,nz ; \textcolor{keywordflow}{do} i=ish-1,ieh
399             \textcolor{keywordflow}{if} (cs%vol\_CFL) \textcolor{keywordflow}{then}
400               dx\_w = ratio\_max(g%areaT(i,j), g%dy\_Cu(i,j), 1000.0*g%dxT(i,j))
401               dx\_e = ratio\_max(g%areaT(i+1,j), g%dy\_Cu(i,j), 1000.0*g%dxT(i+1,j))
402             \textcolor{keywordflow}{else} ; dx\_w = g%dxT(i,j) ; dx\_e = g%dxT(i+1,j) ;\textcolor{keywordflow}{ endif}
403 
404             du\_max\_cfl(i) = min(du\_max\_cfl(i), dx\_w*cfl\_dt - u(i,j,k))
405             du\_min\_cfl(i) = max(du\_min\_cfl(i), -(dx\_e*cfl\_dt + u(i,j,k)))
406 \textcolor{keywordflow}{          enddo} ;\textcolor{keywordflow}{ enddo}
407 \textcolor{keywordflow}{        endif}
408 \textcolor{keywordflow}{      endif}
409       \textcolor{keywordflow}{do} i=ish-1,ieh
410         du\_max\_cfl(i) = max(du\_max\_cfl(i),0.0)
411         du\_min\_cfl(i) = min(du\_min\_cfl(i),0.0)
412 \textcolor{keywordflow}{      enddo}
413 
414       any\_simple\_obc = .false.
415       \textcolor{keywordflow}{if} (\textcolor{keyword}{present}(uhbt) .or. set\_bt\_cont) \textcolor{keywordflow}{then}
416         \textcolor{keywordflow}{if} (local\_specified\_bc .or. local\_flather\_obc) \textcolor{keywordflow}{then} ; \textcolor{keywordflow}{do} i=ish-1,ieh
417           l\_seg = obc%segnum\_u(i,j)
418 
419           \textcolor{comment}{! Avoid reconciling barotropic/baroclinic transports if transport is specified}
420           is\_simple = .false.
421           \textcolor{keywordflow}{if} (l\_seg /= obc\_none) &
422             is\_simple = obc%segment(l\_seg)%specified
423           do\_i(i) = .not. (l\_seg /= obc\_none .and. is\_simple)
424           any\_simple\_obc = any\_simple\_obc .or. is\_simple
425 \textcolor{keywordflow}{        enddo} ; \textcolor{keywordflow}{else} ; \textcolor{keywordflow}{do} i=ish-1,ieh
426           do\_i(i) = .true.
427 \textcolor{keywordflow}{        enddo} ;\textcolor{keywordflow}{ endif}
428 \textcolor{keywordflow}{      endif}
429 
430       \textcolor{keywordflow}{if} (\textcolor{keyword}{present}(uhbt)) \textcolor{keywordflow}{then}
431         \textcolor{keyword}{call }zonal\_flux\_adjust(u, h\_in, h\_l, h\_r, uhbt(:,j), uh\_tot\_0, duhdu\_tot\_0, du, &
432                                du\_max\_cfl, du\_min\_cfl, dt, g, us, cs, visc\_rem, &
433                                j, ish, ieh, do\_i, .true., uh, obc=obc)
434 
435         \textcolor{keywordflow}{if} (\textcolor{keyword}{present}(u\_cor)) \textcolor{keywordflow}{then} ; \textcolor{keywordflow}{do} k=1,nz
436           \textcolor{keywordflow}{do} i=ish-1,ieh ; u\_cor(i,j,k) = u(i,j,k) + du(i) * visc\_rem(i,k) ;\textcolor{keywordflow}{ enddo}
437           \textcolor{keywordflow}{if} (local\_specified\_bc) \textcolor{keywordflow}{then} ; \textcolor{keywordflow}{do} i=ish-1,ieh
438             l\_seg = obc%segnum\_u(i,j)
439 
440             \textcolor{keywordflow}{if} (l\_seg /= obc\_none) \textcolor{keywordflow}{then}
441               \textcolor{keywordflow}{if} (obc%segment(l\_seg)%specified) &
442                 u\_cor(i,j,k) = obc%segment(l\_seg)%normal\_vel(i,j,k)
443 \textcolor{keywordflow}{            endif}
444 \textcolor{keywordflow}{          enddo} ;\textcolor{keywordflow}{ endif}
445 \textcolor{keywordflow}{        enddo} ;\textcolor{keywordflow}{ endif} \textcolor{comment}{! u-corrected}
446 
447 \textcolor{keywordflow}{      endif}
448 
449       \textcolor{keywordflow}{if} (set\_bt\_cont) \textcolor{keywordflow}{then}
450         \textcolor{keyword}{call }set\_zonal\_bt\_cont(u, h\_in, h\_l, h\_r, bt\_cont, uh\_tot\_0, duhdu\_tot\_0,&
451                                du\_max\_cfl, du\_min\_cfl, dt, g, us, cs, visc\_rem, &
452                                visc\_rem\_max, j, ish, ieh, do\_i)
453         \textcolor{keywordflow}{if} (any\_simple\_obc) \textcolor{keywordflow}{then}
454           \textcolor{keywordflow}{do} i=ish-1,ieh
455             l\_seg = obc%segnum\_u(i,j)
456 
457             do\_i(i) = .false.
458             \textcolor{keywordflow}{if} (l\_seg /= obc\_none) &
459               do\_i(i) = obc%segment(l\_seg)%specified
460 
461             \textcolor{keywordflow}{if} (do\_i(i)) faui(i) = gv%H\_subroundoff*g%dy\_Cu(i,j)
462 \textcolor{keywordflow}{          enddo}
463           \textcolor{comment}{! NOTE: do\_I(I) should prevent access to segment OBC\_NONE}
464           \textcolor{keywordflow}{do} k=1,nz ; \textcolor{keywordflow}{do} i=ish-1,ieh ; \textcolor{keywordflow}{if} (do\_i(i)) \textcolor{keywordflow}{then}
465             \textcolor{keywordflow}{if} ((abs(obc%segment(obc%segnum\_u(i,j))%normal\_vel(i,j,k)) > 0.0) .and. &
466                 (obc%segment(obc%segnum\_u(i,j))%specified)) &
467               faui(i) = faui(i) + obc%segment(obc%segnum\_u(i,j))%normal\_trans(i,j,k) / &
468                                   obc%segment(obc%segnum\_u(i,j))%normal\_vel(i,j,k)
469 \textcolor{keywordflow}{          endif} ;\textcolor{keywordflow}{ enddo} ;\textcolor{keywordflow}{ enddo}
470           \textcolor{keywordflow}{do} i=ish-1,ieh ; \textcolor{keywordflow}{if} (do\_i(i)) \textcolor{keywordflow}{then}
471             bt\_cont%FA\_u\_W0(i,j) = faui(i) ; bt\_cont%FA\_u\_E0(i,j) = faui(i)
472             bt\_cont%FA\_u\_WW(i,j) = faui(i) ; bt\_cont%FA\_u\_EE(i,j) = faui(i)
473             bt\_cont%uBT\_WW(i,j) = 0.0 ; bt\_cont%uBT\_EE(i,j) = 0.0
474 \textcolor{keywordflow}{          endif} ;\textcolor{keywordflow}{ enddo}
475 \textcolor{keywordflow}{        endif}
476 \textcolor{keywordflow}{      endif} \textcolor{comment}{! set\_BT\_cont}
477 
478 \textcolor{keywordflow}{    endif} \textcolor{comment}{! present(uhbt) or set\_BT\_cont}
479 
480 \textcolor{keywordflow}{  enddo} \textcolor{comment}{! j-loop}
481 
482   \textcolor{keywordflow}{if} (local\_open\_bc .and. set\_bt\_cont) \textcolor{keywordflow}{then}
483     \textcolor{keywordflow}{do} n = 1, obc%number\_of\_segments
484       \textcolor{keywordflow}{if} (obc%segment(n)%open .and. obc%segment(n)%is\_E\_or\_W) \textcolor{keywordflow}{then}
485         i = obc%segment(n)%HI%IsdB
486         \textcolor{keywordflow}{if} (obc%segment(n)%direction == obc\_direction\_e) \textcolor{keywordflow}{then}
487           \textcolor{keywordflow}{do} j = obc%segment(n)%HI%Jsd, obc%segment(n)%HI%Jed
488             fa\_u = 0.0
489             \textcolor{keywordflow}{do} k=1,nz ; fa\_u = fa\_u + h\_in(i,j,k)*g%dy\_Cu(i,j) ;\textcolor{keywordflow}{ enddo}
490             bt\_cont%FA\_u\_W0(i,j) = fa\_u ; bt\_cont%FA\_u\_E0(i,j) = fa\_u
491             bt\_cont%FA\_u\_WW(i,j) = fa\_u ; bt\_cont%FA\_u\_EE(i,j) = fa\_u
492             bt\_cont%uBT\_WW(i,j) = 0.0 ; bt\_cont%uBT\_EE(i,j) = 0.0
493 \textcolor{keywordflow}{          enddo}
494         \textcolor{keywordflow}{else}
495           \textcolor{keywordflow}{do} j = obc%segment(n)%HI%Jsd, obc%segment(n)%HI%Jed
496             fa\_u = 0.0
497             \textcolor{keywordflow}{do} k=1,nz ; fa\_u = fa\_u + h\_in(i+1,j,k)*g%dy\_Cu(i,j) ;\textcolor{keywordflow}{ enddo}
498             bt\_cont%FA\_u\_W0(i,j) = fa\_u ; bt\_cont%FA\_u\_E0(i,j) = fa\_u
499             bt\_cont%FA\_u\_WW(i,j) = fa\_u ; bt\_cont%FA\_u\_EE(i,j) = fa\_u
500             bt\_cont%uBT\_WW(i,j) = 0.0 ; bt\_cont%uBT\_EE(i,j) = 0.0
501 \textcolor{keywordflow}{          enddo}
502 \textcolor{keywordflow}{        endif}
503 \textcolor{keywordflow}{      endif}
504 \textcolor{keywordflow}{    enddo}
505 \textcolor{keywordflow}{  endif}
506   \textcolor{keyword}{call }cpu\_clock\_end(id\_clock\_correct)
507 
508   \textcolor{keywordflow}{if}  (set\_bt\_cont) \textcolor{keywordflow}{then} ; \textcolor{keywordflow}{if} (\textcolor{keyword}{allocated}(bt\_cont%h\_u)) \textcolor{keywordflow}{then}
509     \textcolor{keywordflow}{if} (\textcolor{keyword}{present}(u\_cor)) \textcolor{keywordflow}{then}
510       \textcolor{keyword}{call }zonal\_face\_thickness(u\_cor, h\_in, h\_l, h\_r, bt\_cont%h\_u, dt, g, us, lb, &
511                                 cs%vol\_CFL, cs%marginal\_faces, visc\_rem\_u, obc)
512     \textcolor{keywordflow}{else}
513       \textcolor{keyword}{call }zonal\_face\_thickness(u, h\_in, h\_l, h\_r, bt\_cont%h\_u, dt, g, us, lb, &
514                                 cs%vol\_CFL, cs%marginal\_faces, visc\_rem\_u, obc)
515 \textcolor{keywordflow}{    endif}
516 \textcolor{keywordflow}{  endif} ;\textcolor{keywordflow}{ endif}
517 
\end{DoxyCode}
