\hypertarget{namespacemom__tracer__advect}{}\section{mom\+\_\+tracer\+\_\+advect Module Reference}
\label{namespacemom__tracer__advect}\index{mom\+\_\+tracer\+\_\+advect@{mom\+\_\+tracer\+\_\+advect}}


\subsection{Detailed Description}
This module contains the subroutines that advect tracers along coordinate surfaces. 

This program contains the subroutines that advect tracers horizontally (i.\+e. along layers).\hypertarget{namespacemom__tracer__advect_section_mom_advect_intro}{}\subsection{section\+\_\+mom\+\_\+advect\+\_\+intro}\label{namespacemom__tracer__advect_section_mom_advect_intro}

\begin{DoxyItemize}
\item advect\+\_\+tracer advects tracer concentrations using a combination of the modified flux advection scheme from Easter (Mon. Wea. Rev., 1993) with tracer distributions given by the monotonic modified van Leer scheme proposed by Lin et al. (Mon. Wea. Rev., 1994). This scheme conserves the total amount of tracer while avoiding spurious maxima and minima of the tracer concentration. If a higher order accuracy scheme is needed, suggest monotonic piecewise parabolic method, as described in Carpenter et al. (M\+WR, 1990).
\item advect\+\_\+tracer has 4 arguments, described below. This subroutine determines the volume of a layer in a grid cell at the previous instance when the tracer concentration was changed, so it is essential that the volume fluxes should be correct. It is also important that the tracer advection occurs before each calculation of the diabatic forcing. 
\end{DoxyItemize}\subsection*{Data Types}
\begin{DoxyCompactItemize}
\item 
type \mbox{\hyperlink{structmom__tracer__advect_1_1tracer__advect__cs}{tracer\+\_\+advect\+\_\+cs}}
\begin{DoxyCompactList}\small\item\em Control structure for this module. \end{DoxyCompactList}\end{DoxyCompactItemize}
\subsection*{Functions/\+Subroutines}
\begin{DoxyCompactItemize}
\item 
subroutine, public \mbox{\hyperlink{namespacemom__tracer__advect_a28a6e28170a8d4f34337a1a202e0d902}{advect\+\_\+tracer}} (h\+\_\+end, uhtr, vhtr, O\+BC, dt, G, GV, US, CS, Reg, h\+\_\+prev\+\_\+opt, max\+\_\+iter\+\_\+in, x\+\_\+first\+\_\+in, uhr\+\_\+out, vhr\+\_\+out, h\+\_\+out)
\begin{DoxyCompactList}\small\item\em This routine time steps the tracer concentration using a monotonic, conservative, weakly diffusive scheme. \end{DoxyCompactList}\item 
subroutine \mbox{\hyperlink{namespacemom__tracer__advect_a07f6e664b3346db7f9ddbcd4b4d6c8f4}{advect\+\_\+x}} (Tr, hprev, uhr, uh\+\_\+neglect, O\+BC, domore\+\_\+u, ntr, Idt, is, ie, js, je, k, G, GV, US, use\+P\+PM, use\+Huynh)
\begin{DoxyCompactList}\small\item\em This subroutine does 1-\/d flux-\/form advection in the zonal direction using a monotonic piecewise linear scheme. \end{DoxyCompactList}\item 
subroutine \mbox{\hyperlink{namespacemom__tracer__advect_a20a82831fad6aa07cb946aeadbbfdda9}{advect\+\_\+y}} (Tr, hprev, vhr, vh\+\_\+neglect, O\+BC, domore\+\_\+v, ntr, Idt, is, ie, js, je, k, G, GV, US, use\+P\+PM, use\+Huynh)
\begin{DoxyCompactList}\small\item\em This subroutine does 1-\/d flux-\/form advection using a monotonic piecewise linear scheme. \end{DoxyCompactList}\item 
subroutine, public \mbox{\hyperlink{namespacemom__tracer__advect_aacf9cdc544c9c3a188d6e3e9a0d7b9df}{tracer\+\_\+advect\+\_\+init}} (Time, G, US, param\+\_\+file, diag, CS)
\begin{DoxyCompactList}\small\item\em Initialize lateral tracer advection module. \end{DoxyCompactList}\item 
subroutine, public \mbox{\hyperlink{namespacemom__tracer__advect_a2e466a8a34546bb9265a74ff0209df47}{tracer\+\_\+advect\+\_\+end}} (CS)
\begin{DoxyCompactList}\small\item\em Close the tracer advection module. \end{DoxyCompactList}\end{DoxyCompactItemize}
\subsection*{Variables}
\textbf{ }\par
\begin{DoxyCompactItemize}
\item 
\mbox{\Hypertarget{namespacemom__tracer__advect_a951134d3dcb3508f71abb05dc39837cc}\label{namespacemom__tracer__advect_a951134d3dcb3508f71abb05dc39837cc}} 
integer \mbox{\hyperlink{namespacemom__tracer__advect_a951134d3dcb3508f71abb05dc39837cc}{id\+\_\+clock\+\_\+advect}}
\begin{DoxyCompactList}\small\item\em C\+PU time clocks. \end{DoxyCompactList}\item 
\mbox{\Hypertarget{namespacemom__tracer__advect_a6590ebd9b76b6d5fea6d13e2deb0c271}\label{namespacemom__tracer__advect_a6590ebd9b76b6d5fea6d13e2deb0c271}} 
integer \mbox{\hyperlink{namespacemom__tracer__advect_a6590ebd9b76b6d5fea6d13e2deb0c271}{id\+\_\+clock\+\_\+pass}}
\begin{DoxyCompactList}\small\item\em C\+PU time clocks. \end{DoxyCompactList}\item 
\mbox{\Hypertarget{namespacemom__tracer__advect_a4f1598f314da682e38e10f560bb94428}\label{namespacemom__tracer__advect_a4f1598f314da682e38e10f560bb94428}} 
integer \mbox{\hyperlink{namespacemom__tracer__advect_a4f1598f314da682e38e10f560bb94428}{id\+\_\+clock\+\_\+sync}}
\begin{DoxyCompactList}\small\item\em C\+PU time clocks. \end{DoxyCompactList}\end{DoxyCompactItemize}



\subsection{Function/\+Subroutine Documentation}
\mbox{\Hypertarget{namespacemom__tracer__advect_a28a6e28170a8d4f34337a1a202e0d902}\label{namespacemom__tracer__advect_a28a6e28170a8d4f34337a1a202e0d902}} 
\index{mom\+\_\+tracer\+\_\+advect@{mom\+\_\+tracer\+\_\+advect}!advect\+\_\+tracer@{advect\+\_\+tracer}}
\index{advect\+\_\+tracer@{advect\+\_\+tracer}!mom\+\_\+tracer\+\_\+advect@{mom\+\_\+tracer\+\_\+advect}}
\subsubsection{\texorpdfstring{advect\+\_\+tracer()}{advect\_tracer()}}
{\footnotesize\ttfamily subroutine, public mom\+\_\+tracer\+\_\+advect\+::advect\+\_\+tracer (\begin{DoxyParamCaption}\item[{real, dimension( g \%isd\+: g \%ied, g \%jsd\+: g \%jed, g \%ke), intent(in)}]{h\+\_\+end,  }\item[{real, dimension( g \%isdb\+: g \%iedb, g \%jsd\+: g \%jed, g \%ke), intent(in)}]{uhtr,  }\item[{real, dimension( g \%isd\+: g \%ied, g \%jsdb\+: g \%jedb, g \%ke), intent(in)}]{vhtr,  }\item[{type(ocean\+\_\+obc\+\_\+type), pointer}]{O\+BC,  }\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__tracer__advect_1_1tracer__advect__cs}{tracer\+\_\+advect\+\_\+cs}}), pointer}]{CS,  }\item[{type(tracer\+\_\+registry\+\_\+type), pointer}]{Reg,  }\item[{real, dimension( g \%isd\+: g \%ied, g \%jsd\+: g \%jed, g \%ke), intent(in), optional}]{h\+\_\+prev\+\_\+opt,  }\item[{integer, intent(in), optional}]{max\+\_\+iter\+\_\+in,  }\item[{logical, intent(in), optional}]{x\+\_\+first\+\_\+in,  }\item[{real, dimension( g \%isdb\+: g \%iedb, g \%jsd\+: g \%jed, g \%ke), intent(out), optional}]{uhr\+\_\+out,  }\item[{real, dimension( g \%isd\+: g \%ied, g \%jsdb\+: g \%jedb, g \%ke), intent(out), optional}]{vhr\+\_\+out,  }\item[{real, dimension( g \%isd\+: g \%ied, g \%jsd\+: g \%jed, g \%ke), intent(out), optional}]{h\+\_\+out }\end{DoxyParamCaption})}



This routine time steps the tracer concentration using a monotonic, conservative, weakly diffusive scheme. 


\begin{DoxyParams}[1]{Parameters}
\mbox{\tt in,out}  & {\em g} & ocean grid structure\\
\hline
\mbox{\tt in}  & {\em gv} & ocean vertical grid structure\\
\hline
\mbox{\tt in}  & {\em h\+\_\+end} & layer thickness after advection \mbox{[}H $\sim$$>$ m or kg m-\/2\mbox{]}\\
\hline
\mbox{\tt in}  & {\em uhtr} & accumulated volume/mass flux through zonal face \mbox{[}H L2 $\sim$$>$ m3 or kg\mbox{]}\\
\hline
\mbox{\tt in}  & {\em vhtr} & accumulated volume/mass flux through merid face \mbox{[}H L2 $\sim$$>$ m3 or kg\mbox{]}\\
\hline
 & {\em obc} & specifies whether, where, and what O\+B\+Cs are used\\
\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} & control structure for module\\
\hline
 & {\em reg} & pointer to tracer registry\\
\hline
\mbox{\tt in}  & {\em h\+\_\+prev\+\_\+opt} & layer thickness before advection \mbox{[}H $\sim$$>$ m or kg m-\/2\mbox{]}\\
\hline
\mbox{\tt in}  & {\em max\+\_\+iter\+\_\+in} & The maximum number of iterations\\
\hline
\mbox{\tt in}  & {\em x\+\_\+first\+\_\+in} & If present, indicate whether to update first in the x-\/ or y-\/direction.\\
\hline
\mbox{\tt out}  & {\em uhr\+\_\+out} & accumulated volume/mass flux through zonal face\\
\hline
\mbox{\tt out}  & {\em vhr\+\_\+out} & accumulated volume/mass flux through merid face\\
\hline
\mbox{\tt out}  & {\em h\+\_\+out} & layer thickness before advection \mbox{[}H $\sim$$>$ m or kg m-\/2\mbox{]} \\
\hline
\end{DoxyParams}


Definition at line 52 of file M\+O\+M\+\_\+tracer\+\_\+advect.\+F90.


\begin{DoxyCode}
52   \textcolor{keywordtype}{type}(ocean\_grid\_type),   \textcolor{keywordtype}{intent(inout)} :: G\textcolor{comment}{     !< ocean grid structure}
53   \textcolor{keywordtype}{type}(verticalGrid\_type), \textcolor{keywordtype}{intent(in)}    :: GV\textcolor{comment}{    !< ocean vertical grid structure}
54   \textcolor{keywordtype}{real}, \textcolor{keywordtype}{dimension(SZI\_(G),SZJ\_(G),SZK\_(G))}, &
55                            \textcolor{keywordtype}{intent(in)}    :: h\_end\textcolor{comment}{ !< layer thickness after advection [H ~> m or kg m-2]}
56   \textcolor{keywordtype}{real}, \textcolor{keywordtype}{dimension(SZIB\_(G),SZJ\_(G),SZK\_(G))}, &
57                            \textcolor{keywordtype}{intent(in)}    :: uhtr\textcolor{comment}{  !< accumulated volume/mass flux through zonal face [H L2
       ~> m3 or kg]}
58   \textcolor{keywordtype}{real}, \textcolor{keywordtype}{dimension(SZI\_(G),SZJB\_(G),SZK\_(G))}, &
59                            \textcolor{keywordtype}{intent(in)}    :: vhtr\textcolor{comment}{  !< accumulated volume/mass flux through merid face [H L2
       ~> m3 or kg]}
60   \textcolor{keywordtype}{type}(ocean\_OBC\_type),    \textcolor{keywordtype}{pointer}       :: OBC\textcolor{comment}{   !< specifies whether, where, and what OBCs are used}
61   \textcolor{keywordtype}{real},                    \textcolor{keywordtype}{intent(in)}    :: dt\textcolor{comment}{    !< time increment [T ~> s]}
62   \textcolor{keywordtype}{type}(unit\_scale\_type),   \textcolor{keywordtype}{intent(in)}    :: US\textcolor{comment}{    !< A dimensional unit scaling type}
63   \textcolor{keywordtype}{type}(tracer\_advect\_CS),  \textcolor{keywordtype}{pointer}       :: CS\textcolor{comment}{    !< control structure for module}
64   \textcolor{keywordtype}{type}(tracer\_registry\_type), \textcolor{keywordtype}{pointer}    :: Reg\textcolor{comment}{   !< pointer to tracer registry}
65   \textcolor{keywordtype}{real}, \textcolor{keywordtype}{dimension(SZI\_(G),SZJ\_(G),SZK\_(G))},  &
66                  \textcolor{keywordtype}{optional}, \textcolor{keywordtype}{intent(in)}    :: h\_prev\_opt\textcolor{comment}{ !< layer thickness before advection [H ~> m or kg
       m-2]}
67   \textcolor{keywordtype}{integer},       \textcolor{keywordtype}{optional}, \textcolor{keywordtype}{intent(in)}    :: max\_iter\_in\textcolor{comment}{ !< The maximum number of iterations}
68   \textcolor{keywordtype}{logical},       \textcolor{keywordtype}{optional}, \textcolor{keywordtype}{intent(in)}    :: x\_first\_in\textcolor{comment}{ !< If present, indicate whether to update}
69 \textcolor{comment}{                                                  !! first in the x- or y-direction.}
70   \textcolor{keywordtype}{real}, \textcolor{keywordtype}{dimension(SZIB\_(G),SZJ\_(G),SZK\_(G))}, &
71                  \textcolor{keywordtype}{optional}, \textcolor{keywordtype}{intent(out)}    :: uhr\_out\textcolor{comment}{  !< accumulated volume/mass flux through zonal face}
72 \textcolor{comment}{                                                  !! [H L2 ~> m3 or kg]}
73   \textcolor{keywordtype}{real}, \textcolor{keywordtype}{dimension(SZI\_(G),SZJB\_(G),SZK\_(G))}, &
74                  \textcolor{keywordtype}{optional}, \textcolor{keywordtype}{intent(out)}    :: vhr\_out\textcolor{comment}{  !< accumulated volume/mass flux through merid face}
75 \textcolor{comment}{                                                  !! [H L2 ~> m3 or kg]}
76   \textcolor{keywordtype}{real}, \textcolor{keywordtype}{dimension(SZI\_(G),SZJ\_(G),SZK\_(G))},  &
77                  \textcolor{keywordtype}{optional}, \textcolor{keywordtype}{intent(out)}    :: h\_out\textcolor{comment}{ !< layer thickness before advection [H ~> m or kg m-2]}
78 
79   \textcolor{keywordtype}{type}(tracer\_type) :: Tr(MAX\_FIELDS\_) \textcolor{comment}{! The array of registered tracers}
80   \textcolor{keywordtype}{real}, \textcolor{keywordtype}{dimension(SZI\_(G),SZJ\_(G),SZK\_(G))} :: &
81     hprev           \textcolor{comment}{! cell volume at the end of previous tracer change [H L2 ~> m3 or kg]}
82   \textcolor{keywordtype}{real}, \textcolor{keywordtype}{dimension(SZIB\_(G),SZJ\_(G),SZK\_(G))} :: &
83     uhr             \textcolor{comment}{! The remaining zonal thickness flux [H L2 ~> m3 or kg]}
84   \textcolor{keywordtype}{real}, \textcolor{keywordtype}{dimension(SZI\_(G),SZJB\_(G),SZK\_(G))} :: &
85     vhr             \textcolor{comment}{! The remaining meridional thickness fluxes [H L2 ~> m3 or kg]}
86   \textcolor{keywordtype}{real} :: uh\_neglect(SZIB\_(G),SZJ\_(G)) \textcolor{comment}{! uh\_neglect and vh\_neglect are the}
87   \textcolor{keywordtype}{real} :: vh\_neglect(SZI\_(G),SZJB\_(G)) \textcolor{comment}{! magnitude of remaining transports that}
88                                        \textcolor{comment}{! can be simply discarded [H L2 ~> m3 or kg].}
89 
90   \textcolor{keywordtype}{real} :: landvolfill                   \textcolor{comment}{! An arbitrary? nonzero cell volume [H L2 ~> m3 or kg].}
91   \textcolor{keywordtype}{real} :: Idt                           \textcolor{comment}{! 1/dt [T-1 ~> s-1].}
92   \textcolor{keywordtype}{logical} :: domore\_u(SZJ\_(G),SZK\_(G))  \textcolor{comment}{! domore\_\_ indicate whether there is more}
93   \textcolor{keywordtype}{logical} :: domore\_v(SZJB\_(G),SZK\_(G)) \textcolor{comment}{! advection to be done in the corresponding}
94                                         \textcolor{comment}{! row or column.}
95   \textcolor{keywordtype}{logical} :: x\_first            \textcolor{comment}{! If true, advect in the x-direction first.}
96   \textcolor{keywordtype}{integer} :: max\_iter           \textcolor{comment}{! maximum number of iterations in each layer}
97   \textcolor{keywordtype}{integer} :: domore\_k(SZK\_(G))
98   \textcolor{keywordtype}{integer} :: stencil            \textcolor{comment}{! stencil of the advection scheme}
99   \textcolor{keywordtype}{integer} :: nsten\_halo         \textcolor{comment}{! number of stencils that fit in the halos}
100   \textcolor{keywordtype}{integer} :: i, j, k, m, is, ie, js, je, isd, ied, jsd, jed, nz, itt, ntr, do\_any
101   \textcolor{keywordtype}{integer} :: isv, iev, jsv, jev \textcolor{comment}{! The valid range of the indices.}
102   \textcolor{keywordtype}{integer} :: IsdB, IedB, JsdB, JedB
103 
104   domore\_u(:,:) = .false.
105   domore\_v(:,:) = .false.
106   is  = g%isc ; ie  = g%iec ; js  = g%jsc ; je  = g%jec ; nz = gv%ke
107   isd = g%isd ; ied = g%ied ; jsd = g%jsd ; jed = g%jed
108   isdb = g%IsdB ; iedb = g%IedB ; jsdb = g%JsdB ; jedb = g%JedB
109   landvolfill = 1.0e-20         \textcolor{comment}{! This is arbitrary, but must be positive.}
110   stencil = 2                   \textcolor{comment}{! The scheme's stencil; 2 for PLM and PPM:H3}
111 
112   \textcolor{keywordflow}{if} (.not. \textcolor{keyword}{associated}(cs)) \textcolor{keyword}{call }mom\_error(fatal, \textcolor{stringliteral}{"MOM\_tracer\_advect: "}// &
113        \textcolor{stringliteral}{"tracer\_advect\_init must be called before advect\_tracer."})
114   \textcolor{keywordflow}{if} (.not. \textcolor{keyword}{associated}(reg)) \textcolor{keyword}{call }mom\_error(fatal, \textcolor{stringliteral}{"MOM\_tracer\_advect: "}// &
115        \textcolor{stringliteral}{"register\_tracer must be called before advect\_tracer."})
116   \textcolor{keywordflow}{if} (reg%ntr==0) \textcolor{keywordflow}{return}
117   \textcolor{keyword}{call }cpu\_clock\_begin(id\_clock\_advect)
118   x\_first = (mod(g%first\_direction,2) == 0)
119 
120   \textcolor{comment}{! increase stencil size for Colella & Woodward PPM}
121   \textcolor{keywordflow}{if} (cs%usePPM .and. .not. cs%useHuynh) stencil = 3
122 
123   ntr = reg%ntr
124   \textcolor{keywordflow}{do} m=1,ntr ; tr(m) = reg%Tr(m) ;\textcolor{keywordflow}{ enddo}
125   idt = 1.0 / dt
126 
127   max\_iter = 2*int(ceiling(dt/cs%dt)) + 1
128 
129   \textcolor{keywordflow}{if} (\textcolor{keyword}{present}(max\_iter\_in)) max\_iter = max\_iter\_in
130   \textcolor{keywordflow}{if} (\textcolor{keyword}{present}(x\_first\_in))  x\_first = x\_first\_in
131   \textcolor{keyword}{call }cpu\_clock\_begin(id\_clock\_pass)
132   \textcolor{keyword}{call }create\_group\_pass(cs%pass\_uhr\_vhr\_t\_hprev, uhr, vhr, g%Domain)
133   \textcolor{keyword}{call }create\_group\_pass(cs%pass\_uhr\_vhr\_t\_hprev, hprev, g%Domain)
134   \textcolor{keywordflow}{do} m=1,ntr
135     \textcolor{keyword}{call }create\_group\_pass(cs%pass\_uhr\_vhr\_t\_hprev, tr(m)%t, g%Domain)
136 \textcolor{keywordflow}{  enddo}
137   \textcolor{keyword}{call }cpu\_clock\_end(id\_clock\_pass)
138 
139 \textcolor{comment}{!$OMP parallel default(none) shared(nz,jsd,jed,IsdB,IedB,uhr,jsdB,jedB,Isd,Ied,vhr, &}
140 \textcolor{comment}{!$OMP                               hprev,domore\_k,js,je,is,ie,uhtr,vhtr,G,GV,h\_end,&}
141 \textcolor{comment}{!$OMP                               uh\_neglect,vh\_neglect,ntr,Tr,h\_prev\_opt)}
142 
143   \textcolor{comment}{! This initializes the halos of uhr and vhr because pass\_vector might do}
144   \textcolor{comment}{! calculations on them, even though they are never used.}
145   \textcolor{comment}{!$OMP do}
146   \textcolor{keywordflow}{do} k=1,nz
147     \textcolor{keywordflow}{do} j=jsd,jed ; \textcolor{keywordflow}{do} i=isdb,iedb ; uhr(i,j,k) = 0.0 ;\textcolor{keywordflow}{ enddo} ;\textcolor{keywordflow}{ enddo}
148     \textcolor{keywordflow}{do} j=jsdb,jedb ; \textcolor{keywordflow}{do} i=isd,ied ; vhr(i,j,k) = 0.0 ;\textcolor{keywordflow}{ enddo} ;\textcolor{keywordflow}{ enddo}
149     \textcolor{keywordflow}{do} j=jsd,jed ; \textcolor{keywordflow}{do} i=isd,ied ; hprev(i,j,k) = 0.0 ;\textcolor{keywordflow}{ enddo} ;\textcolor{keywordflow}{ enddo}
150     domore\_k(k)=1
151     \textcolor{comment}{!  Put the remaining (total) thickness fluxes into uhr and vhr.}
152     \textcolor{keywordflow}{do} j=js,je ; \textcolor{keywordflow}{do} i=is-1,ie ; uhr(i,j,k) = uhtr(i,j,k) ;\textcolor{keywordflow}{ enddo} ;\textcolor{keywordflow}{ enddo}
153     \textcolor{keywordflow}{do} j=js-1,je ; \textcolor{keywordflow}{do} i=is,ie ; vhr(i,j,k) = vhtr(i,j,k) ;\textcolor{keywordflow}{ enddo} ;\textcolor{keywordflow}{ enddo}
154     \textcolor{keywordflow}{if} (.not. \textcolor{keyword}{present}(h\_prev\_opt)) \textcolor{keywordflow}{then}
155     \textcolor{comment}{!   This loop reconstructs the thickness field the last time that the}
156     \textcolor{comment}{! tracers were updated, probably just after the diabatic forcing.  A useful}
157     \textcolor{comment}{! diagnostic could be to compare this reconstruction with that older value.}
158       \textcolor{keywordflow}{do} i=is,ie ; \textcolor{keywordflow}{do} j=js,je
159         hprev(i,j,k) = max(0.0, g%areaT(i,j)*h\_end(i,j,k) + &
160              ((uhr(i,j,k) - uhr(i-1,j,k)) + (vhr(i,j,k) - vhr(i,j-1,k))))
161     \textcolor{comment}{! In the case that the layer is now dramatically thinner than it was previously,}
162     \textcolor{comment}{! add a bit of mass to avoid truncation errors.  This will lead to}
163     \textcolor{comment}{! non-conservation of tracers}
164         hprev(i,j,k) = hprev(i,j,k) + &
165                        max(0.0, 1.0e-13*hprev(i,j,k) - g%areaT(i,j)*h\_end(i,j,k))
166 \textcolor{keywordflow}{      enddo} ;\textcolor{keywordflow}{ enddo}
167     \textcolor{keywordflow}{else}
168       \textcolor{keywordflow}{do} i=is,ie ; \textcolor{keywordflow}{do} j=js,je
169         hprev(i,j,k) = h\_prev\_opt(i,j,k)
170 \textcolor{keywordflow}{      enddo} ;\textcolor{keywordflow}{ enddo}
171 \textcolor{keywordflow}{    endif}
172 \textcolor{keywordflow}{  enddo}
173 
174 
175   \textcolor{comment}{!$OMP do}
176   \textcolor{keywordflow}{do} j=jsd,jed ; \textcolor{keywordflow}{do} i=isd,ied-1
177     uh\_neglect(i,j) = gv%H\_subroundoff * min(g%areaT(i,j), g%areaT(i+1,j))
178 \textcolor{keywordflow}{  enddo} ;\textcolor{keywordflow}{ enddo}
179   \textcolor{comment}{!$OMP do}
180   \textcolor{keywordflow}{do} j=jsd,jed-1 ; \textcolor{keywordflow}{do} i=isd,ied
181     vh\_neglect(i,j) = gv%H\_subroundoff * min(g%areaT(i,j), g%areaT(i,j+1))
182 \textcolor{keywordflow}{  enddo} ;\textcolor{keywordflow}{ enddo}
183 
184   \textcolor{comment}{! initialize diagnostic fluxes and tendencies}
185   \textcolor{comment}{!$OMP do}
186   \textcolor{keywordflow}{do} m=1,ntr
187     \textcolor{keywordflow}{if} (\textcolor{keyword}{associated}(tr(m)%ad\_x)) \textcolor{keywordflow}{then}
188       \textcolor{keywordflow}{do} k=1,nz ; \textcolor{keywordflow}{do} j=jsd,jed ; \textcolor{keywordflow}{do} i=isd,ied
189         tr(m)%ad\_x(i,j,k) = 0.0
190 \textcolor{keywordflow}{      enddo} ;\textcolor{keywordflow}{ enddo} ;\textcolor{keywordflow}{ enddo}
191 \textcolor{keywordflow}{    endif}
192     \textcolor{keywordflow}{if} (\textcolor{keyword}{associated}(tr(m)%ad\_y)) \textcolor{keywordflow}{then}
193       \textcolor{keywordflow}{do} k=1,nz ; \textcolor{keywordflow}{do} j=jsd,jed ; \textcolor{keywordflow}{do} i=isd,ied
194         tr(m)%ad\_y(i,j,k) = 0.0
195 \textcolor{keywordflow}{      enddo} ;\textcolor{keywordflow}{ enddo} ;\textcolor{keywordflow}{ enddo}
196 \textcolor{keywordflow}{    endif}
197     \textcolor{keywordflow}{if} (\textcolor{keyword}{associated}(tr(m)%advection\_xy)) \textcolor{keywordflow}{then}
198       \textcolor{keywordflow}{do} k=1,nz ; \textcolor{keywordflow}{do} j=jsd,jed ; \textcolor{keywordflow}{do} i=isd,ied
199         tr(m)%advection\_xy(i,j,k) = 0.0
200 \textcolor{keywordflow}{      enddo} ;\textcolor{keywordflow}{ enddo} ;\textcolor{keywordflow}{ enddo}
201 \textcolor{keywordflow}{    endif}
202     \textcolor{keywordflow}{if} (\textcolor{keyword}{associated}(tr(m)%ad2d\_x)) \textcolor{keywordflow}{then}
203       \textcolor{keywordflow}{do} j=jsd,jed ; \textcolor{keywordflow}{do} i=isd,ied ; tr(m)%ad2d\_x(i,j) = 0.0 ;\textcolor{keywordflow}{ enddo} ;\textcolor{keywordflow}{ enddo}
204 \textcolor{keywordflow}{    endif}
205     \textcolor{keywordflow}{if} (\textcolor{keyword}{associated}(tr(m)%ad2d\_y)) \textcolor{keywordflow}{then}
206       \textcolor{keywordflow}{do} j=jsd,jed ; \textcolor{keywordflow}{do} i=isd,ied ; tr(m)%ad2d\_y(i,j) = 0.0 ;\textcolor{keywordflow}{ enddo} ;\textcolor{keywordflow}{ enddo}
207 \textcolor{keywordflow}{    endif}
208 \textcolor{keywordflow}{  enddo}
209   \textcolor{comment}{!$OMP end parallel}
210 
211   isv = is ; iev = ie ; jsv = js ; jev = je
212 
213   \textcolor{keywordflow}{do} itt=1,max\_iter
214 
215     \textcolor{keywordflow}{if} (isv > is-stencil) \textcolor{keywordflow}{then}
216       \textcolor{keyword}{call }do\_group\_pass(cs%pass\_uhr\_vhr\_t\_hprev, g%Domain, clock=id\_clock\_pass)
217 
218       nsten\_halo = min(is-isd,ied-ie,js-jsd,jed-je)/stencil
219       isv = is-nsten\_halo*stencil ; jsv = js-nsten\_halo*stencil
220       iev = ie+nsten\_halo*stencil ; jev = je+nsten\_halo*stencil
221       \textcolor{comment}{! Reevaluate domore\_u & domore\_v unless the valid range is the same size as}
222       \textcolor{comment}{! before.  Also, do this if there is Strang splitting.}
223       \textcolor{keywordflow}{if} ((nsten\_halo > 1) .or. (itt==1)) \textcolor{keywordflow}{then}
224         \textcolor{comment}{!$OMP parallel do default(shared)}
225         \textcolor{keywordflow}{do} k=1,nz ; \textcolor{keywordflow}{if} (domore\_k(k) > 0) \textcolor{keywordflow}{then}
226           \textcolor{keywordflow}{do} j=jsv,jev ; \textcolor{keywordflow}{if} (.not.domore\_u(j,k)) \textcolor{keywordflow}{then}
227             \textcolor{keywordflow}{do} i=isv+stencil-1,iev-stencil; \textcolor{keywordflow}{if} (uhr(i,j,k) /= 0.0) \textcolor{keywordflow}{then}
228               domore\_u(j,k) = .true. ; \textcolor{keywordflow}{exit}
229 \textcolor{keywordflow}{            endif} ;\textcolor{keywordflow}{ enddo} \textcolor{comment}{! i-loop}
230 \textcolor{keywordflow}{          endif} ;\textcolor{keywordflow}{ enddo}
231           \textcolor{keywordflow}{do} j=jsv+stencil-1,jev-stencil ; \textcolor{keywordflow}{if} (.not.domore\_v(j,k)) \textcolor{keywordflow}{then}
232             \textcolor{keywordflow}{do} i=isv+stencil,iev-stencil; \textcolor{keywordflow}{if} (vhr(i,j,k) /= 0.0) \textcolor{keywordflow}{then}
233               domore\_v(j,k) = .true. ; \textcolor{keywordflow}{exit}
234 \textcolor{keywordflow}{            endif} ;\textcolor{keywordflow}{ enddo} \textcolor{comment}{! i-loop}
235 \textcolor{keywordflow}{          endif} ;\textcolor{keywordflow}{ enddo}
236 
237           \textcolor{comment}{!   At this point, domore\_k is global.  Change it so that it indicates}
238           \textcolor{comment}{! whether any work is needed on a layer on this processor.}
239           domore\_k(k) = 0
240           \textcolor{keywordflow}{do} j=jsv,jev ; \textcolor{keywordflow}{if} (domore\_u(j,k)) domore\_k(k) = 1 ;\textcolor{keywordflow}{ enddo}
241           \textcolor{keywordflow}{do} j=jsv+stencil-1,jev-stencil ; \textcolor{keywordflow}{if} (domore\_v(j,k)) domore\_k(k) = 1 ;\textcolor{keywordflow}{ enddo}
242 
243 \textcolor{keywordflow}{        endif} ;\textcolor{keywordflow}{ enddo} \textcolor{comment}{! k-loop}
244 \textcolor{keywordflow}{      endif}
245 \textcolor{keywordflow}{    endif}
246 
247     \textcolor{comment}{! Set the range of valid points after this iteration.}
248     isv = isv + stencil ; iev = iev - stencil
249     jsv = jsv + stencil ; jev = jev - stencil
250 
251     \textcolor{comment}{!  To ensure positive definiteness of the thickness at each iteration, the}
252     \textcolor{comment}{!  mass fluxes out of each layer are checked each step, and limited to keep}
253     \textcolor{comment}{!  the thicknesses positive.  This means that several iterations may be required}
254     \textcolor{comment}{!  for all the transport to happen.  The sum over domore\_k keeps the processors}
255     \textcolor{comment}{!  synchronized.  This may not be very efficient, but it should be reliable.}
256 
257     \textcolor{comment}{!$OMP parallel default(shared)}
258 
259     \textcolor{keywordflow}{if} (x\_first) \textcolor{keywordflow}{then}
260 
261       \textcolor{comment}{!$OMP do ordered}
262       \textcolor{keywordflow}{do} k=1,nz ; \textcolor{keywordflow}{if} (domore\_k(k) > 0) \textcolor{keywordflow}{then}
263         \textcolor{comment}{! First, advect zonally.}
264         \textcolor{keyword}{call }advect\_x(tr, hprev, uhr, uh\_neglect, obc, domore\_u, ntr, idt, &
265                       isv, iev, jsv-stencil, jev+stencil, k, g, gv, us, cs%usePPM, cs%useHuynh)
266 \textcolor{keywordflow}{      endif} ;\textcolor{keywordflow}{ enddo}
267 
268       \textcolor{comment}{!$OMP do ordered}
269       \textcolor{keywordflow}{do} k=1,nz ; \textcolor{keywordflow}{if} (domore\_k(k) > 0) \textcolor{keywordflow}{then}
270         \textcolor{comment}{!  Next, advect meridionally.}
271         \textcolor{keyword}{call }advect\_y(tr, hprev, vhr, vh\_neglect, obc, domore\_v, ntr, idt, &
272                       isv, iev, jsv, jev, k, g, gv, us, cs%usePPM, cs%useHuynh)
273 
274         \textcolor{comment}{! Update domore\_k(k) for the next iteration}
275         domore\_k(k) = 0
276         \textcolor{keywordflow}{do} j=jsv-stencil,jev+stencil ; \textcolor{keywordflow}{if} (domore\_u(j,k)) domore\_k(k) = 1 ;\textcolor{keywordflow}{ enddo}
277         \textcolor{keywordflow}{do} j=jsv-1,jev ; \textcolor{keywordflow}{if} (domore\_v(j,k)) domore\_k(k) = 1 ;\textcolor{keywordflow}{ enddo}
278 
279 \textcolor{keywordflow}{      endif} ;\textcolor{keywordflow}{ enddo}
280 
281     \textcolor{keywordflow}{else}
282 
283       \textcolor{comment}{!$OMP do ordered}
284       \textcolor{keywordflow}{do} k=1,nz ; \textcolor{keywordflow}{if} (domore\_k(k) > 0) \textcolor{keywordflow}{then}
285         \textcolor{comment}{! First, advect meridionally.}
286         \textcolor{keyword}{call }advect\_y(tr, hprev, vhr, vh\_neglect, obc, domore\_v, ntr, idt, &
287                       isv-stencil, iev+stencil, jsv, jev, k, g, gv, us, cs%usePPM, cs%useHuynh)
288 \textcolor{keywordflow}{      endif} ;\textcolor{keywordflow}{ enddo}
289 
290       \textcolor{comment}{!$OMP do ordered}
291       \textcolor{keywordflow}{do} k=1,nz ; \textcolor{keywordflow}{if} (domore\_k(k) > 0) \textcolor{keywordflow}{then}
292         \textcolor{comment}{! Next, advect zonally.}
293         \textcolor{keyword}{call }advect\_x(tr, hprev, uhr, uh\_neglect, obc, domore\_u, ntr, idt, &
294                       isv, iev, jsv, jev, k, g, gv, us, cs%usePPM, cs%useHuynh)
295 
296         \textcolor{comment}{! Update domore\_k(k) for the next iteration}
297         domore\_k(k) = 0
298         \textcolor{keywordflow}{do} j=jsv,jev ; \textcolor{keywordflow}{if} (domore\_u(j,k)) domore\_k(k) = 1 ;\textcolor{keywordflow}{ enddo}
299         \textcolor{keywordflow}{do} j=jsv-1,jev ; \textcolor{keywordflow}{if} (domore\_v(j,k)) domore\_k(k) = 1 ;\textcolor{keywordflow}{ enddo}
300 \textcolor{keywordflow}{      endif} ;\textcolor{keywordflow}{ enddo}
301 
302 \textcolor{keywordflow}{    endif} \textcolor{comment}{! x\_first}
303 
304     \textcolor{comment}{!$OMP end parallel}
305 
306     \textcolor{comment}{! If the advection just isn't finishing after max\_iter, move on.}
307     \textcolor{keywordflow}{if} (itt >= max\_iter) \textcolor{keywordflow}{then}
308       \textcolor{keywordflow}{exit}
309 \textcolor{keywordflow}{    endif}
310 
311     \textcolor{comment}{! Exit if there are no layers that need more iterations.}
312     \textcolor{keywordflow}{if} (isv > is-stencil) \textcolor{keywordflow}{then}
313       do\_any = 0
314       \textcolor{keyword}{call }cpu\_clock\_begin(id\_clock\_sync)
315       \textcolor{keyword}{call }sum\_across\_pes(domore\_k(:), nz)
316       \textcolor{keyword}{call }cpu\_clock\_end(id\_clock\_sync)
317       \textcolor{keywordflow}{do} k=1,nz ; do\_any = do\_any + domore\_k(k) ;\textcolor{keywordflow}{ enddo}
318       \textcolor{keywordflow}{if} (do\_any == 0) \textcolor{keywordflow}{then}
319         \textcolor{keywordflow}{exit}
320 \textcolor{keywordflow}{      endif}
321 
322 \textcolor{keywordflow}{    endif}
323 
324 \textcolor{keywordflow}{  enddo} \textcolor{comment}{! Iterations loop}
325 
326   \textcolor{keywordflow}{if} (\textcolor{keyword}{present}(uhr\_out)) uhr\_out(:,:,:) = uhr(:,:,:)
327   \textcolor{keywordflow}{if} (\textcolor{keyword}{present}(vhr\_out)) vhr\_out(:,:,:) = vhr(:,:,:)
328   \textcolor{keywordflow}{if} (\textcolor{keyword}{present}(h\_out)) h\_out(:,:,:) = hprev(:,:,:)
329 
330   \textcolor{keyword}{call }cpu\_clock\_end(id\_clock\_advect)
331 
\end{DoxyCode}
\mbox{\Hypertarget{namespacemom__tracer__advect_a07f6e664b3346db7f9ddbcd4b4d6c8f4}\label{namespacemom__tracer__advect_a07f6e664b3346db7f9ddbcd4b4d6c8f4}} 
\index{mom\+\_\+tracer\+\_\+advect@{mom\+\_\+tracer\+\_\+advect}!advect\+\_\+x@{advect\+\_\+x}}
\index{advect\+\_\+x@{advect\+\_\+x}!mom\+\_\+tracer\+\_\+advect@{mom\+\_\+tracer\+\_\+advect}}
\subsubsection{\texorpdfstring{advect\+\_\+x()}{advect\_x()}}
{\footnotesize\ttfamily subroutine mom\+\_\+tracer\+\_\+advect\+::advect\+\_\+x (\begin{DoxyParamCaption}\item[{type(tracer\+\_\+type), dimension(ntr), intent(inout)}]{Tr,  }\item[{real, dimension( g \%isd\+: g \%ied, g \%jsd\+: g \%jed, g \%ke), intent(inout)}]{hprev,  }\item[{real, dimension( g \%isdb\+: g \%iedb, g \%jsd\+: g \%jed, g \%ke), intent(inout)}]{uhr,  }\item[{real, dimension( g \%isdb\+: g \%iedb, g \%jsd\+: g \%jed), intent(in)}]{uh\+\_\+neglect,  }\item[{type(ocean\+\_\+obc\+\_\+type), pointer}]{O\+BC,  }\item[{logical, dimension( g \%jsd\+: g \%jed, g \%ke), intent(inout)}]{domore\+\_\+u,  }\item[{integer, intent(in)}]{ntr,  }\item[{real, intent(in)}]{Idt,  }\item[{integer, intent(in)}]{is,  }\item[{integer, intent(in)}]{ie,  }\item[{integer, intent(in)}]{js,  }\item[{integer, intent(in)}]{je,  }\item[{integer, intent(in)}]{k,  }\item[{type(ocean\+\_\+grid\+\_\+type), intent(inout)}]{G,  }\item[{type(verticalgrid\+\_\+type), intent(in)}]{GV,  }\item[{type(unit\+\_\+scale\+\_\+type), intent(in)}]{US,  }\item[{logical, intent(in)}]{use\+P\+PM,  }\item[{logical, intent(in)}]{use\+Huynh }\end{DoxyParamCaption})\hspace{0.3cm}{\ttfamily [private]}}



This subroutine does 1-\/d flux-\/form advection in the zonal direction using a monotonic piecewise linear scheme. 


\begin{DoxyParams}[1]{Parameters}
\mbox{\tt in,out}  & {\em g} & The ocean\textquotesingle{}s grid structure\\
\hline
\mbox{\tt in}  & {\em gv} & The ocean\textquotesingle{}s vertical grid structure\\
\hline
\mbox{\tt in,out}  & {\em tr} & The array of registered tracers to work on\\
\hline
\mbox{\tt in,out}  & {\em hprev} & cell volume at the end of previous tracer change \mbox{[}H L2 $\sim$$>$ m3 or kg\mbox{]}\\
\hline
\mbox{\tt in,out}  & {\em uhr} & accumulated volume/mass flux through the zonal face \mbox{[}H L2 $\sim$$>$ m3 or kg\mbox{]}\\
\hline
\mbox{\tt in}  & {\em uh\+\_\+neglect} & A tiny zonal mass flux that can be neglected \mbox{[}H L2 $\sim$$>$ m3 or kg\mbox{]}\\
\hline
 & {\em obc} & specifies whether, where, and what O\+B\+Cs are used\\
\hline
\mbox{\tt in,out}  & {\em domore\+\_\+u} & If true, there is more advection to be done in this u-\/row\\
\hline
\mbox{\tt in}  & {\em idt} & The inverse of dt \mbox{[}T-\/1 $\sim$$>$ s-\/1\mbox{]}\\
\hline
\mbox{\tt in}  & {\em ntr} & The number of tracers\\
\hline
\mbox{\tt in}  & {\em is} & The starting tracer i-\/index to work on\\
\hline
\mbox{\tt in}  & {\em ie} & The ending tracer i-\/index to work on\\
\hline
\mbox{\tt in}  & {\em js} & The starting tracer j-\/index to work on\\
\hline
\mbox{\tt in}  & {\em je} & The ending tracer j-\/index to work on\\
\hline
\mbox{\tt in}  & {\em k} & The k-\/level to work on\\
\hline
\mbox{\tt in}  & {\em us} & A dimensional unit scaling type\\
\hline
\mbox{\tt in}  & {\em useppm} & If true, use P\+PM instead of P\+LM\\
\hline
\mbox{\tt in}  & {\em usehuynh} & If true, use the Huynh scheme for P\+PM interface values \\
\hline
\end{DoxyParams}


Definition at line 339 of file M\+O\+M\+\_\+tracer\+\_\+advect.\+F90.


\begin{DoxyCode}
339   \textcolor{keywordtype}{type}(ocean\_grid\_type),                     \textcolor{keywordtype}{intent(inout)} :: G\textcolor{comment}{    !< The ocean's grid structure}
340   \textcolor{keywordtype}{type}(verticalGrid\_type),                   \textcolor{keywordtype}{intent(in)}    :: GV\textcolor{comment}{   !< The ocean's vertical grid structure}
341   \textcolor{keywordtype}{type}(tracer\_type), \textcolor{keywordtype}{dimension(ntr)},         \textcolor{keywordtype}{intent(inout)} :: Tr\textcolor{comment}{   !< The array of registered tracers to
       work on}
342   \textcolor{keywordtype}{real}, \textcolor{keywordtype}{dimension(SZI\_(G),SZJ\_(G),SZK\_(G))},  \textcolor{keywordtype}{intent(inout)} :: hprev\textcolor{comment}{ !< cell volume at the end of previous}
343 \textcolor{comment}{                                                                  !! tracer change [H L2 ~> m3 or kg]}
344   \textcolor{keywordtype}{real}, \textcolor{keywordtype}{dimension(SZIB\_(G),SZJ\_(G),SZK\_(G))}, \textcolor{keywordtype}{intent(inout)} :: uhr\textcolor{comment}{ !< accumulated volume/mass flux through}
345 \textcolor{comment}{                                                                  !! the zonal face [H L2 ~> m3 or kg]}
346    \textcolor{keywordtype}{real}, \textcolor{keywordtype}{dimension(SZIB\_(G),SZJ\_(G))},        \textcolor{keywordtype}{intent(in)}    :: uh\_neglect\textcolor{comment}{ !< A tiny zonal mass flux that can}
347 \textcolor{comment}{                                                                  !! be neglected [H L2 ~> m3 or kg]}
348   \textcolor{keywordtype}{type}(ocean\_OBC\_type),                      \textcolor{keywordtype}{pointer}       :: OBC\textcolor{comment}{ !< specifies whether, where, and what
       OBCs are used}
349   \textcolor{keywordtype}{logical}, \textcolor{keywordtype}{dimension(SZJ\_(G),SZK\_(G))},       \textcolor{keywordtype}{intent(inout)} :: domore\_u\textcolor{comment}{ !< If true, there is more advection
       to be}
350 \textcolor{comment}{                                                                  !! done in this u-row}
351   \textcolor{keywordtype}{real},                                      \textcolor{keywordtype}{intent(in)}    :: Idt\textcolor{comment}{ !< The inverse of dt [T-1 ~> s-1]}
352   \textcolor{keywordtype}{integer},                                   \textcolor{keywordtype}{intent(in)}    :: ntr\textcolor{comment}{ !< The number of tracers}
353   \textcolor{keywordtype}{integer},                                   \textcolor{keywordtype}{intent(in)}    :: is\textcolor{comment}{  !< The starting tracer i-index to work on}
354   \textcolor{keywordtype}{integer},                                   \textcolor{keywordtype}{intent(in)}    :: ie\textcolor{comment}{  !< The ending tracer i-index to work on}
355   \textcolor{keywordtype}{integer},                                   \textcolor{keywordtype}{intent(in)}    :: js\textcolor{comment}{  !< The starting tracer j-index to work on}
356   \textcolor{keywordtype}{integer},                                   \textcolor{keywordtype}{intent(in)}    :: je\textcolor{comment}{  !< The ending tracer j-index to work on}
357   \textcolor{keywordtype}{integer},                                   \textcolor{keywordtype}{intent(in)}    :: k\textcolor{comment}{   !< The k-level to work on}
358   \textcolor{keywordtype}{type}(unit\_scale\_type),                     \textcolor{keywordtype}{intent(in)}    :: US\textcolor{comment}{  !< A dimensional unit scaling type}
359   \textcolor{keywordtype}{logical},                                   \textcolor{keywordtype}{intent(in)}    :: usePPM\textcolor{comment}{ !< If true, use PPM instead of PLM}
360   \textcolor{keywordtype}{logical},                                   \textcolor{keywordtype}{intent(in)}    :: useHuynh\textcolor{comment}{ !< If true, use the Huynh scheme}
361 \textcolor{comment}{                                                                     !! for PPM interface values}
362 
363   \textcolor{keywordtype}{real}, \textcolor{keywordtype}{dimension(SZI\_(G),ntr)} :: &
364     slope\_x             \textcolor{comment}{! The concentration slope per grid point [conc].}
365   \textcolor{keywordtype}{real}, \textcolor{keywordtype}{dimension(SZIB\_(G),SZJ\_(G),ntr)} :: &
366     flux\_x              \textcolor{comment}{! The tracer flux across a boundary [H L2 conc ~> m3 conc or kg conc].}
367   \textcolor{keywordtype}{real}, \textcolor{keywordtype}{dimension(SZI\_(G),ntr)} :: &
368     T\_tmp               \textcolor{comment}{! The copy of the tracer concentration at constant i,k [H m2 conc ~> m3 conc or kg
       conc].}
369 
370   \textcolor{keywordtype}{real} :: maxslope      \textcolor{comment}{! The maximum concentration slope per grid point}
371                         \textcolor{comment}{! consistent with monotonicity [conc].}
372   \textcolor{keywordtype}{real} :: hup, hlos     \textcolor{comment}{! hup is the upwind volume, hlos is the}
373                         \textcolor{comment}{! part of that volume that might be lost}
374                         \textcolor{comment}{! due to advection out the other side of}
375                         \textcolor{comment}{! the grid box, both in [H L2 ~> m3 or kg].}
376   \textcolor{keywordtype}{real} :: uhh(SZIB\_(G)) \textcolor{comment}{! The zonal flux that occurs during the}
377                         \textcolor{comment}{! current iteration [H L2 ~> m3 or kg].}
378   \textcolor{keywordtype}{real}, \textcolor{keywordtype}{dimension(SZIB\_(G))} :: &
379     hlst, &             \textcolor{comment}{! Work variable [H L2 ~> m3 or kg].}
380     Ihnew, &            \textcolor{comment}{! Work variable [H-1 L-2 ~> m-3 or kg-1].}
381     CFL                 \textcolor{comment}{! The absolute value of the advective upwind-cell CFL number [nondim].}
382   \textcolor{keywordtype}{real} :: min\_h         \textcolor{comment}{! The minimum thickness that can be realized during}
383                         \textcolor{comment}{! any of the passes [H ~> m or kg m-2].}
384   \textcolor{keywordtype}{real} :: tiny\_h        \textcolor{comment}{! The smallest numerically invertable thickness [H ~> m or kg m-2].}
385   \textcolor{keywordtype}{real} :: h\_neglect     \textcolor{comment}{! A thickness that is so small it is usually lost}
386                         \textcolor{comment}{! in roundoff and can be neglected [H ~> m or kg m-2].}
387   \textcolor{keywordtype}{logical} :: do\_i(SZIB\_(G),SZJ\_(G))     \textcolor{comment}{! If true, work on given points.}
388   \textcolor{keywordtype}{logical} :: do\_any\_i
389   \textcolor{keywordtype}{integer} :: i, j, m, n, i\_up, stencil
390   \textcolor{keywordtype}{real} :: aR, aL, dMx, dMn, Tp, Tc, Tm, dA, mA, a6
391   \textcolor{keywordtype}{real} :: fac1,u\_L\_in,u\_L\_out  \textcolor{comment}{! terms used for time-stepping OBC reservoirs}
392   \textcolor{keywordtype}{type}(OBC\_segment\_type), \textcolor{keywordtype}{pointer} :: segment=>null()
393   \textcolor{keywordtype}{logical} :: usePLMslope
394   \textcolor{keywordtype}{logical}, \textcolor{keywordtype}{dimension(SZJ\_(G),SZK\_(G))} :: domore\_u\_initial
395 
396   \textcolor{comment}{! keep a local copy of the initial values of domore\_u, which is to be used when computing ad2d\_x}
397   \textcolor{comment}{! diagnostic at the end of this subroutine.}
398   domore\_u\_initial = domore\_u
399 
400   useplmslope = .not. (useppm .and. usehuynh)
401   \textcolor{comment}{! stencil for calculating slope values}
402   stencil = 1
403   \textcolor{keywordflow}{if} (useppm .and. .not. usehuynh) stencil = 2
404 
405   min\_h = 0.1*gv%Angstrom\_H
406   tiny\_h = tiny(min\_h)
407   h\_neglect = gv%H\_subroundoff
408 
409   \textcolor{keywordflow}{do} i=is-1,ie ; cfl(i) = 0.0 ;\textcolor{keywordflow}{ enddo}
410 
411   \textcolor{keywordflow}{do} j=js,je ; \textcolor{keywordflow}{if} (domore\_u(j,k)) \textcolor{keywordflow}{then}
412     domore\_u(j,k) = .false.
413 
414     \textcolor{comment}{! Calculate the i-direction profiles (slopes) of each tracer that is being advected.}
415     \textcolor{keywordflow}{if} (useplmslope) \textcolor{keywordflow}{then}
416       \textcolor{keywordflow}{do} m=1,ntr ; \textcolor{keywordflow}{do} i=is-stencil,ie+stencil
417        \textcolor{comment}{!if (ABS(Tr(m)%t(i+1,j,k)-Tr(m)%t(i,j,k)) < &}
418        \textcolor{comment}{!    ABS(Tr(m)%t(i,j,k)-Tr(m)%t(i-1,j,k))) then}
419        \textcolor{comment}{!  maxslope = 4.0*(Tr(m)%t(i+1,j,k)-Tr(m)%t(i,j,k))}
420        \textcolor{comment}{!else}
421        \textcolor{comment}{!  maxslope = 4.0*(Tr(m)%t(i,j,k)-Tr(m)%t(i-1,j,k))}
422        \textcolor{comment}{!endif}
423        \textcolor{comment}{!if ((Tr(m)%t(i+1,j,k)-Tr(m)%t(i,j,k)) * (Tr(m)%t(i,j,k)-Tr(m)%t(i-1,j,k)) < 0.0) then}
424        \textcolor{comment}{!  slope\_x(i,m) = 0.0}
425        \textcolor{comment}{!elseif (ABS(Tr(m)%t(i+1,j,k)-Tr(m)%t(i-1,j,k))<ABS(maxslope)) then}
426        \textcolor{comment}{!  slope\_x(i,m) = G%mask2dCu(I,j)*G%mask2dCu(I-1,j) * &}
427        \textcolor{comment}{!                 0.5*(Tr(m)%t(i+1,j,k)-Tr(m)%t(i-1,j,k))}
428        \textcolor{comment}{!else}
429        \textcolor{comment}{!  slope\_x(i,m) = G%mask2dCu(I,j)*G%mask2dCu(I-1,j) * 0.5*maxslope}
430        \textcolor{comment}{!endif}
431         tp = tr(m)%t(i+1,j,k) ; tc = tr(m)%t(i,j,k) ; tm = tr(m)%t(i-1,j,k)
432         dmx = max( tp, tc, tm ) - tc
433         dmn= tc - min( tp, tc, tm )
434         slope\_x(i,m) = g%mask2dCu(i,j)*g%mask2dCu(i-1,j) * &
435             sign( min(0.5*abs(tp-tm), 2.0*dmx, 2.0*dmn), tp-tm )
436 \textcolor{keywordflow}{      enddo} ;\textcolor{keywordflow}{ enddo}
437 \textcolor{keywordflow}{    endif} \textcolor{comment}{! usePLMslope}
438 
439     \textcolor{comment}{! make a copy of the tracers in case values need to be overridden for OBCs}
440     \textcolor{keywordflow}{do} m = 1,ntr
441       \textcolor{keywordflow}{do} i=g%isd,g%ied
442         t\_tmp(i,m) = tr(m)%t(i,j,k)
443 \textcolor{keywordflow}{      enddo}
444 \textcolor{keywordflow}{    enddo}
445     \textcolor{comment}{! loop through open boundaries and recalculate flux terms}
446     \textcolor{keywordflow}{if} (\textcolor{keyword}{associated}(obc)) \textcolor{keywordflow}{then} ; \textcolor{keywordflow}{if} (obc%OBC\_pe) \textcolor{keywordflow}{then}
447        \textcolor{keywordflow}{do} n=1,obc%number\_of\_segments
448          segment=>obc%segment(n)
449          \textcolor{keywordflow}{if} (.not. \textcolor{keyword}{associated}(segment%tr\_Reg)) cycle
450          \textcolor{keywordflow}{if} (segment%is\_E\_or\_W) \textcolor{keywordflow}{then}
451            \textcolor{keywordflow}{if} (j>=segment%HI%jsd .and. j<=segment%HI%jed) \textcolor{keywordflow}{then}
452               i = segment%HI%IsdB
453               \textcolor{keywordflow}{do} m = 1,ntr \textcolor{comment}{! replace tracers with OBC values}
454                 \textcolor{keywordflow}{if} (\textcolor{keyword}{associated}(segment%tr\_Reg%Tr(m)%tres)) \textcolor{keywordflow}{then}
455                    \textcolor{keywordflow}{if} (segment%direction == obc\_direction\_w) \textcolor{keywordflow}{then}
456                       t\_tmp(i,m) = segment%tr\_Reg%Tr(m)%tres(i,j,k)
457                    \textcolor{keywordflow}{else}
458                       t\_tmp(i+1,m) = segment%tr\_Reg%Tr(m)%tres(i,j,k)
459 \textcolor{keywordflow}{                   endif}
460                 \textcolor{keywordflow}{else}
461                    \textcolor{keywordflow}{if} (segment%direction == obc\_direction\_w) \textcolor{keywordflow}{then}
462                       t\_tmp(i,m) = segment%tr\_Reg%Tr(m)%OBC\_inflow\_conc
463                    \textcolor{keywordflow}{else}
464                       t\_tmp(i+1,m) = segment%tr\_Reg%Tr(m)%OBC\_inflow\_conc
465 \textcolor{keywordflow}{                   endif}
466 \textcolor{keywordflow}{                endif}
467 \textcolor{keywordflow}{              enddo}
468               \textcolor{keywordflow}{do} m = 1,ntr \textcolor{comment}{! Apply update tracer values for slope calculation}
469                 \textcolor{keywordflow}{do} i=segment%HI%IsdB-1,segment%HI%IsdB+1
470                   tp = t\_tmp(i+1,m) ; tc = t\_tmp(i,m) ; tm = t\_tmp(i-1,m)
471                   dmx = max( tp, tc, tm ) - tc
472                   dmn= tc - min( tp, tc, tm )
473                   slope\_x(i,m) = g%mask2dCu(i,j)*g%mask2dCu(i-1,j) * &
474                        sign( min(0.5*abs(tp-tm), 2.0*dmx, 2.0*dmn), tp-tm )
475 \textcolor{keywordflow}{                enddo}
476 \textcolor{keywordflow}{              enddo}
477 
478 \textcolor{keywordflow}{           endif}
479 \textcolor{keywordflow}{         endif}
480 \textcolor{keywordflow}{       enddo}
481 \textcolor{keyword}{    end}if; endif
482 
483 
484     \textcolor{comment}{! Calculate the i-direction fluxes of each tracer, using as much}
485     \textcolor{comment}{! the minimum of the remaining mass flux (uhr) and the half the mass}
486     \textcolor{comment}{! in the cell plus whatever part of its half of the mass flux that}
487     \textcolor{comment}{! the flux through the other side does not require.}
488     \textcolor{keywordflow}{do} i=is-1,ie
489       \textcolor{keywordflow}{if} ((uhr(i,j,k) == 0.0) .or. &
490           ((uhr(i,j,k) < 0.0) .and. (hprev(i+1,j,k) <= tiny\_h)) .or. &
491           ((uhr(i,j,k) > 0.0) .and. (hprev(i,j,k) <= tiny\_h)) ) \textcolor{keywordflow}{then}
492         uhh(i) = 0.0
493         cfl(i) = 0.0
494       \textcolor{keywordflow}{elseif} (uhr(i,j,k) < 0.0) \textcolor{keywordflow}{then}
495         hup = hprev(i+1,j,k) - g%areaT(i+1,j)*min\_h
496         hlos = max(0.0, uhr(i+1,j,k))
497         \textcolor{keywordflow}{if} ((((hup - hlos) + uhr(i,j,k)) < 0.0) .and. &
498             ((0.5*hup + uhr(i,j,k)) < 0.0)) \textcolor{keywordflow}{then}
499           uhh(i) = min(-0.5*hup, -hup+hlos, 0.0)
500           domore\_u(j,k) = .true.
501         \textcolor{keywordflow}{else}
502           uhh(i) = uhr(i,j,k)
503 \textcolor{keywordflow}{        endif}
504         cfl(i) = - uhh(i) / (hprev(i+1,j,k))  \textcolor{comment}{! CFL is positive}
505       \textcolor{keywordflow}{else}
506         hup = hprev(i,j,k) - g%areaT(i,j)*min\_h
507         hlos = max(0.0, -uhr(i-1,j,k))
508         \textcolor{keywordflow}{if} ((((hup - hlos) - uhr(i,j,k)) < 0.0) .and. &
509             ((0.5*hup - uhr(i,j,k)) < 0.0)) \textcolor{keywordflow}{then}
510           uhh(i) = max(0.5*hup, hup-hlos, 0.0)
511           domore\_u(j,k) = .true.
512         \textcolor{keywordflow}{else}
513           uhh(i) = uhr(i,j,k)
514 \textcolor{keywordflow}{        endif}
515         cfl(i) = uhh(i) / (hprev(i,j,k))  \textcolor{comment}{! CFL is positive}
516 \textcolor{keywordflow}{      endif}
517 \textcolor{keywordflow}{    enddo}
518 
519 
520     \textcolor{keywordflow}{if} (useppm) \textcolor{keywordflow}{then}
521       \textcolor{keywordflow}{do} m=1,ntr ; \textcolor{keywordflow}{do} i=is-1,ie
522         \textcolor{comment}{! centre cell depending on upstream direction}
523         \textcolor{keywordflow}{if} (uhh(i) >= 0.0) \textcolor{keywordflow}{then}
524           i\_up = i
525         \textcolor{keywordflow}{else}
526           i\_up = i+1
527 \textcolor{keywordflow}{        endif}
528 
529         \textcolor{comment}{! Implementation of PPM-H3}
530         tp = t\_tmp(i\_up+1,m) ; tc = t\_tmp(i\_up,m) ; tm = t\_tmp(i\_up-1,m)
531 
532         \textcolor{keywordflow}{if} (usehuynh) \textcolor{keywordflow}{then}
533           al = ( 5.*tc + ( 2.*tm - tp ) )/6. \textcolor{comment}{! H3 estimate}
534           al = max( min(tc,tm), al) ; al = min( max(tc,tm), al) \textcolor{comment}{! Bound}
535           ar = ( 5.*tc + ( 2.*tp - tm ) )/6. \textcolor{comment}{! H3 estimate}
536           ar = max( min(tc,tp), ar) ; ar = min( max(tc,tp), ar) \textcolor{comment}{! Bound}
537         \textcolor{keywordflow}{else}
538           al = 0.5 * ((tm + tc) + (slope\_x(i\_up-1,m) - slope\_x(i\_up,m)) / 3.)
539           ar = 0.5 * ((tc + tp) + (slope\_x(i\_up,m) - slope\_x(i\_up+1,m)) / 3.)
540 \textcolor{keywordflow}{        endif}
541 
542         da = ar - al ; ma = 0.5*( ar + al )
543         \textcolor{keywordflow}{if} (g%mask2dCu(i\_up,j)*g%mask2dCu(i\_up-1,j)*(tp-tc)*(tc-tm) <= 0.) \textcolor{keywordflow}{then}
544           al = tc ; ar = tc \textcolor{comment}{! PCM for local extremum and bounadry cells}
545         \textcolor{keywordflow}{elseif} ( da*(tc-ma) > (da*da)/6. ) \textcolor{keywordflow}{then}
546           al = 3.*tc - 2.*ar
547         \textcolor{keywordflow}{elseif} ( da*(tc-ma) < - (da*da)/6. ) \textcolor{keywordflow}{then}
548           ar = 3.*tc - 2.*al
549 \textcolor{keywordflow}{        endif}
550 
551         a6 = 6.*tc - 3. * (ar + al) \textcolor{comment}{! Curvature}
552 
553         \textcolor{keywordflow}{if} (uhh(i) >= 0.0) \textcolor{keywordflow}{then}
554           flux\_x(i,j,m) = uhh(i)*( ar - 0.5 * cfl(i) * ( &
555                ( ar - al ) - a6 * ( 1. - 2./3. * cfl(i) ) ) )
556         \textcolor{keywordflow}{else}
557           flux\_x(i,j,m) = uhh(i)*( al + 0.5 * cfl(i) * ( &
558                ( ar - al ) + a6 * ( 1. - 2./3. * cfl(i) ) ) )
559 \textcolor{keywordflow}{        endif}
560 \textcolor{keywordflow}{      enddo} ;\textcolor{keywordflow}{ enddo}
561     \textcolor{keywordflow}{else} \textcolor{comment}{! PLM}
562       \textcolor{keywordflow}{do} m=1,ntr ; \textcolor{keywordflow}{do} i=is-1,ie
563         \textcolor{keywordflow}{if} (uhh(i) >= 0.0) \textcolor{keywordflow}{then}
564           \textcolor{comment}{! Indirect implementation of PLM}
565          \textcolor{comment}{!aL = Tr(m)%t(i,j,k) - 0.5 * slope\_x(i,m)}
566          \textcolor{comment}{!aR = Tr(m)%t(i,j,k) + 0.5 * slope\_x(i,m)}
567          \textcolor{comment}{!flux\_x(I,j,m) = uhh(I)*( aR - 0.5 * (aR-aL) * CFL(I) )}
568           \textcolor{comment}{! Alternative implementation of PLM}
569           tc = t\_tmp(i,m)
570           flux\_x(i,j,m) = uhh(i)*( tc + 0.5 * slope\_x(i,m) * ( 1. - cfl(i) ) )
571         \textcolor{keywordflow}{else}
572           \textcolor{comment}{! Indirect implementation of PLM}
573          \textcolor{comment}{!aL = Tr(m)%t(i+1,j,k) - 0.5 * slope\_x(i+1,m)}
574          \textcolor{comment}{!aR = Tr(m)%t(i+1,j,k) + 0.5 * slope\_x(i+1,m)}
575          \textcolor{comment}{!flux\_x(I,j,m) = uhh(I)*( aL + 0.5 * (aR-aL) * CFL(I) )}
576           \textcolor{comment}{! Alternative implementation of PLM}
577           tc = t\_tmp(i+1,m)
578           flux\_x(i,j,m) = uhh(i)*( tc - 0.5 * slope\_x(i+1,m) * ( 1. - cfl(i) ) )
579 \textcolor{keywordflow}{        endif}
580 \textcolor{keywordflow}{      enddo} ;\textcolor{keywordflow}{ enddo}
581 \textcolor{keywordflow}{    endif} \textcolor{comment}{! usePPM}
582 
583     \textcolor{keywordflow}{if} (\textcolor{keyword}{associated}(obc)) \textcolor{keywordflow}{then} ; \textcolor{keywordflow}{if} (obc%OBC\_pe) \textcolor{keywordflow}{then}
584       \textcolor{keywordflow}{if} (obc%specified\_u\_BCs\_exist\_globally .or. obc%open\_u\_BCs\_exist\_globally) \textcolor{keywordflow}{then}
585         \textcolor{keywordflow}{do} n=1,obc%number\_of\_segments
586           segment=>obc%segment(n)
587           \textcolor{keywordflow}{if} (.not. \textcolor{keyword}{associated}(segment%tr\_Reg)) cycle
588           \textcolor{keywordflow}{if} (segment%is\_E\_or\_W) \textcolor{keywordflow}{then}
589             \textcolor{keywordflow}{if} (j>=segment%HI%jsd .and. j<=segment%HI%jed) \textcolor{keywordflow}{then}
590               i = segment%HI%IsdB
591               \textcolor{comment}{! Tracer fluxes are set to prescribed values only for inflows from masked areas.}
592               \textcolor{comment}{! Now changing to simply fixed inflows.}
593               \textcolor{keywordflow}{if} ((uhr(i,j,k) > 0.0) .and. (segment%direction == obc\_direction\_w) .or. &
594                  (uhr(i,j,k) < 0.0) .and. (segment%direction == obc\_direction\_e)) \textcolor{keywordflow}{then}
595                 uhh(i) = uhr(i,j,k)
596               \textcolor{comment}{! should the reservoir evolve for this case Kate ?? - Nope}
597                 \textcolor{keywordflow}{do} m=1,ntr
598                   \textcolor{keywordflow}{if} (\textcolor{keyword}{associated}(segment%tr\_Reg%Tr(m)%tres)) \textcolor{keywordflow}{then}
599                     flux\_x(i,j,m) = uhh(i)*segment%tr\_Reg%Tr(m)%tres(i,j,k)
600                   \textcolor{keywordflow}{else} ; flux\_x(i,j,m) = uhh(i)*segment%tr\_Reg%Tr(m)%OBC\_inflow\_conc ;\textcolor{keywordflow}{ endif}
601 \textcolor{keywordflow}{                enddo}
602 \textcolor{keywordflow}{              endif}
603 \textcolor{keywordflow}{            endif}
604 \textcolor{keywordflow}{          endif}
605 \textcolor{keywordflow}{        enddo}
606 \textcolor{keywordflow}{      endif}
607 
608       \textcolor{keywordflow}{if} (obc%open\_u\_BCs\_exist\_globally) \textcolor{keywordflow}{then}
609         \textcolor{keywordflow}{do} n=1,obc%number\_of\_segments
610           segment=>obc%segment(n)
611           i = segment%HI%IsdB
612           \textcolor{keywordflow}{if} (segment%is\_E\_or\_W .and. (j >= segment%HI%jsd .and. j<= segment%HI%jed)) \textcolor{keywordflow}{then}
613             \textcolor{keywordflow}{if} (segment%specified) cycle
614             \textcolor{keywordflow}{if} (.not. \textcolor{keyword}{associated}(segment%tr\_Reg)) cycle
615 
616             \textcolor{comment}{! Tracer fluxes are set to prescribed values only for inflows from masked areas.}
617             \textcolor{keywordflow}{if} ((uhr(i,j,k) > 0.0) .and. (g%mask2dT(i,j) < 0.5) .or. &
618                (uhr(i,j,k) < 0.0) .and. (g%mask2dT(i+1,j) < 0.5)) \textcolor{keywordflow}{then}
619               uhh(i) = uhr(i,j,k)
620               \textcolor{keywordflow}{do} m=1,ntr
621                 \textcolor{keywordflow}{if} (\textcolor{keyword}{associated}(segment%tr\_Reg%Tr(m)%tres)) \textcolor{keywordflow}{then}
622                   flux\_x(i,j,m) = uhh(i)*segment%tr\_Reg%Tr(m)%tres(i,j,k)
623                 else; flux\_x(i,j,m) = uhh(i)*segment%tr\_Reg%Tr(m)%OBC\_inflow\_conc;\textcolor{keywordflow}{ endif}
624 \textcolor{keywordflow}{              enddo}
625 \textcolor{keywordflow}{            endif}
626 \textcolor{keywordflow}{          endif}
627 \textcolor{keywordflow}{        enddo}
628 \textcolor{keywordflow}{      endif}
629 \textcolor{keywordflow}{    endif} ;\textcolor{keywordflow}{ endif}
630 
631     \textcolor{comment}{! Calculate new tracer concentration in each cell after accounting}
632     \textcolor{comment}{! for the i-direction fluxes.}
633     \textcolor{keywordflow}{do} i=is-1,ie
634       uhr(i,j,k) = uhr(i,j,k) - uhh(i)
635       \textcolor{keywordflow}{if} (abs(uhr(i,j,k)) < uh\_neglect(i,j)) uhr(i,j,k) = 0.0
636 \textcolor{keywordflow}{    enddo}
637     \textcolor{keywordflow}{do} i=is,ie
638       \textcolor{keywordflow}{if} ((uhh(i) /= 0.0) .or. (uhh(i-1) /= 0.0)) \textcolor{keywordflow}{then}
639         do\_i(i,j) = .true.
640         hlst(i) = hprev(i,j,k)
641         hprev(i,j,k) = hprev(i,j,k) - (uhh(i) - uhh(i-1))
642         \textcolor{keywordflow}{if} (hprev(i,j,k) <= 0.0) \textcolor{keywordflow}{then} ; do\_i(i,j) = .false.
643         \textcolor{keywordflow}{elseif} (hprev(i,j,k) < h\_neglect*g%areaT(i,j)) \textcolor{keywordflow}{then}
644           hlst(i) = hlst(i) + (h\_neglect*g%areaT(i,j) - hprev(i,j,k))
645           ihnew(i) = 1.0 / (h\_neglect*g%areaT(i,j))
646         \textcolor{keywordflow}{else} ;  ihnew(i) = 1.0 / hprev(i,j,k) ;\textcolor{keywordflow}{ endif}
647       \textcolor{keywordflow}{else}
648         do\_i(i,j) = .false.
649 \textcolor{keywordflow}{      endif}
650 \textcolor{keywordflow}{    enddo}
651 
652     \textcolor{comment}{! update tracer concentration from i-flux and save some diagnostics}
653     \textcolor{keywordflow}{do} m=1,ntr
654 
655       \textcolor{comment}{! update tracer}
656       \textcolor{keywordflow}{do} i=is,ie
657         \textcolor{keywordflow}{if} (do\_i(i,j)) \textcolor{keywordflow}{then}
658           \textcolor{keywordflow}{if} (ihnew(i) > 0.0) \textcolor{keywordflow}{then}
659             tr(m)%t(i,j,k) = (tr(m)%t(i,j,k) * hlst(i) - &
660                               (flux\_x(i,j,m) - flux\_x(i-1,j,m))) * ihnew(i)
661 \textcolor{keywordflow}{          endif}
662 \textcolor{keywordflow}{        endif}
663 \textcolor{keywordflow}{      enddo}
664 
665       \textcolor{comment}{! diagnostics}
666       \textcolor{keywordflow}{if} (\textcolor{keyword}{associated}(tr(m)%ad\_x)) \textcolor{keywordflow}{then} ; \textcolor{keywordflow}{do} i=is,ie ; \textcolor{keywordflow}{if} (do\_i(i,j)) \textcolor{keywordflow}{then}
667         tr(m)%ad\_x(i,j,k) = tr(m)%ad\_x(i,j,k) + flux\_x(i,j,m)*idt
668 \textcolor{keywordflow}{      endif} ;\textcolor{keywordflow}{ enddo} ;\textcolor{keywordflow}{ endif}
669 
670       \textcolor{comment}{! diagnose convergence of flux\_x (do not use the Ihnew(i) part of the logic).}
671       \textcolor{comment}{! division by areaT to get into W/m2 for heat and kg/(s*m2) for salt.}
672       \textcolor{keywordflow}{if} (\textcolor{keyword}{associated}(tr(m)%advection\_xy)) \textcolor{keywordflow}{then}
673         \textcolor{keywordflow}{do} i=is,ie ; \textcolor{keywordflow}{if} (do\_i(i,j)) \textcolor{keywordflow}{then}
674           tr(m)%advection\_xy(i,j,k) = tr(m)%advection\_xy(i,j,k) - (flux\_x(i,j,m) - flux\_x(i-1,j,m)) * &
675                                           idt * g%IareaT(i,j)
676 \textcolor{keywordflow}{        endif} ;\textcolor{keywordflow}{ enddo}
677 \textcolor{keywordflow}{      endif}
678 
679 \textcolor{keywordflow}{    enddo}
680 
681 \textcolor{keywordflow}{  endif}
682 
683 
684 \textcolor{keywordflow}{  enddo} \textcolor{comment}{! End of j-loop.}
685 
686   \textcolor{comment}{! compute ad2d\_x diagnostic outside above j-loop so as to make the summation ordered when OMP is active.}
687 
688   \textcolor{comment}{!$OMP ordered}
689   \textcolor{keywordflow}{do} j=js,je ; \textcolor{keywordflow}{if} (domore\_u\_initial(j,k)) \textcolor{keywordflow}{then}
690     \textcolor{keywordflow}{do} m=1,ntr
691       \textcolor{keywordflow}{if} (\textcolor{keyword}{associated}(tr(m)%ad2d\_x)) \textcolor{keywordflow}{then} ; \textcolor{keywordflow}{do} i=is,ie ; \textcolor{keywordflow}{if} (do\_i(i,j)) \textcolor{keywordflow}{then}
692         tr(m)%ad2d\_x(i,j) = tr(m)%ad2d\_x(i,j) + flux\_x(i,j,m)*idt
693 \textcolor{keywordflow}{      endif} ;\textcolor{keywordflow}{ enddo} ;\textcolor{keywordflow}{ endif}
694 \textcolor{keywordflow}{    enddo}
695 \textcolor{keywordflow}{  endif} ;\textcolor{keywordflow}{ enddo} \textcolor{comment}{! End of j-loop.}
696   \textcolor{comment}{!$OMP end ordered}
697 
\end{DoxyCode}
\mbox{\Hypertarget{namespacemom__tracer__advect_a20a82831fad6aa07cb946aeadbbfdda9}\label{namespacemom__tracer__advect_a20a82831fad6aa07cb946aeadbbfdda9}} 
\index{mom\+\_\+tracer\+\_\+advect@{mom\+\_\+tracer\+\_\+advect}!advect\+\_\+y@{advect\+\_\+y}}
\index{advect\+\_\+y@{advect\+\_\+y}!mom\+\_\+tracer\+\_\+advect@{mom\+\_\+tracer\+\_\+advect}}
\subsubsection{\texorpdfstring{advect\+\_\+y()}{advect\_y()}}
{\footnotesize\ttfamily subroutine mom\+\_\+tracer\+\_\+advect\+::advect\+\_\+y (\begin{DoxyParamCaption}\item[{type(tracer\+\_\+type), dimension(ntr), intent(inout)}]{Tr,  }\item[{real, dimension( g \%isd\+: g \%ied, g \%jsd\+: g \%jed, g \%ke), intent(inout)}]{hprev,  }\item[{real, dimension( g \%isd\+: g \%ied, g \%jsdb\+: g \%jedb, g \%ke), intent(inout)}]{vhr,  }\item[{real, dimension( g \%isd\+: g \%ied, g \%jsdb\+: g \%jedb), intent(inout)}]{vh\+\_\+neglect,  }\item[{type(ocean\+\_\+obc\+\_\+type), pointer}]{O\+BC,  }\item[{logical, dimension( g \%jsdb\+: g \%jedb, g \%ke), intent(inout)}]{domore\+\_\+v,  }\item[{integer, intent(in)}]{ntr,  }\item[{real, intent(in)}]{Idt,  }\item[{integer, intent(in)}]{is,  }\item[{integer, intent(in)}]{ie,  }\item[{integer, intent(in)}]{js,  }\item[{integer, intent(in)}]{je,  }\item[{integer, intent(in)}]{k,  }\item[{type(ocean\+\_\+grid\+\_\+type), intent(inout)}]{G,  }\item[{type(verticalgrid\+\_\+type), intent(in)}]{GV,  }\item[{type(unit\+\_\+scale\+\_\+type), intent(in)}]{US,  }\item[{logical, intent(in)}]{use\+P\+PM,  }\item[{logical, intent(in)}]{use\+Huynh }\end{DoxyParamCaption})\hspace{0.3cm}{\ttfamily [private]}}



This subroutine does 1-\/d flux-\/form advection using a monotonic piecewise linear scheme. 


\begin{DoxyParams}[1]{Parameters}
\mbox{\tt in,out}  & {\em g} & The ocean\textquotesingle{}s grid structure\\
\hline
\mbox{\tt in}  & {\em gv} & The ocean\textquotesingle{}s vertical grid structure\\
\hline
\mbox{\tt in,out}  & {\em tr} & The array of registered tracers to work on\\
\hline
\mbox{\tt in,out}  & {\em hprev} & cell volume at the end of previous tracer change \mbox{[}H L2 $\sim$$>$ m3 or kg\mbox{]}\\
\hline
\mbox{\tt in,out}  & {\em vhr} & accumulated volume/mass flux through the meridional face \mbox{[}H L2 $\sim$$>$ m3 or kg\mbox{]}\\
\hline
\mbox{\tt in,out}  & {\em vh\+\_\+neglect} & A tiny meridional mass flux that can be neglected \mbox{[}H L2 $\sim$$>$ m3 or kg\mbox{]}\\
\hline
 & {\em obc} & specifies whether, where, and what O\+B\+Cs are used\\
\hline
\mbox{\tt in,out}  & {\em domore\+\_\+v} & If true, there is more advection to be done in this v-\/row\\
\hline
\mbox{\tt in}  & {\em idt} & The inverse of dt \mbox{[}T-\/1 $\sim$$>$ s-\/1\mbox{]}\\
\hline
\mbox{\tt in}  & {\em ntr} & The number of tracers\\
\hline
\mbox{\tt in}  & {\em is} & The starting tracer i-\/index to work on\\
\hline
\mbox{\tt in}  & {\em ie} & The ending tracer i-\/index to work on\\
\hline
\mbox{\tt in}  & {\em js} & The starting tracer j-\/index to work on\\
\hline
\mbox{\tt in}  & {\em je} & The ending tracer j-\/index to work on\\
\hline
\mbox{\tt in}  & {\em k} & The k-\/level to work on\\
\hline
\mbox{\tt in}  & {\em us} & A dimensional unit scaling type\\
\hline
\mbox{\tt in}  & {\em useppm} & If true, use P\+PM instead of P\+LM\\
\hline
\mbox{\tt in}  & {\em usehuynh} & If true, use the Huynh scheme for P\+PM interface values \\
\hline
\end{DoxyParams}


Definition at line 704 of file M\+O\+M\+\_\+tracer\+\_\+advect.\+F90.


\begin{DoxyCode}
704   \textcolor{keywordtype}{type}(ocean\_grid\_type),                     \textcolor{keywordtype}{intent(inout)} :: G\textcolor{comment}{    !< The ocean's grid structure}
705   \textcolor{keywordtype}{type}(verticalGrid\_type),                   \textcolor{keywordtype}{intent(in)}    :: GV\textcolor{comment}{   !< The ocean's vertical grid structure}
706   \textcolor{keywordtype}{type}(tracer\_type), \textcolor{keywordtype}{dimension(ntr)},         \textcolor{keywordtype}{intent(inout)} :: Tr\textcolor{comment}{   !< The array of registered tracers to
       work on}
707   \textcolor{keywordtype}{real}, \textcolor{keywordtype}{dimension(SZI\_(G),SZJ\_(G),SZK\_(G))},  \textcolor{keywordtype}{intent(inout)} :: hprev\textcolor{comment}{ !< cell volume at the end of previous}
708 \textcolor{comment}{                                                                  !! tracer change [H L2 ~> m3 or kg]}
709   \textcolor{keywordtype}{real}, \textcolor{keywordtype}{dimension(SZI\_(G),SZJB\_(G),SZK\_(G))}, \textcolor{keywordtype}{intent(inout)} :: vhr\textcolor{comment}{ !< accumulated volume/mass flux through}
710 \textcolor{comment}{                                                                  !! the meridional face [H L2 ~> m3 or kg]}
711   \textcolor{keywordtype}{real}, \textcolor{keywordtype}{dimension(SZI\_(G),SZJB\_(G))},         \textcolor{keywordtype}{intent(inout)} :: vh\_neglect\textcolor{comment}{ !< A tiny meridional mass flux
       that can}
712 \textcolor{comment}{                                                                  !! be neglected [H L2 ~> m3 or kg]}
713   \textcolor{keywordtype}{type}(ocean\_OBC\_type),                      \textcolor{keywordtype}{pointer}       :: OBC\textcolor{comment}{ !< specifies whether, where, and what
       OBCs are used}
714   \textcolor{keywordtype}{logical}, \textcolor{keywordtype}{dimension(SZJB\_(G),SZK\_(G))},      \textcolor{keywordtype}{intent(inout)} :: domore\_v\textcolor{comment}{ !< If true, there is more advection
       to be}
715 \textcolor{comment}{                                                                  !! done in this v-row}
716   \textcolor{keywordtype}{real},                                      \textcolor{keywordtype}{intent(in)}    :: Idt\textcolor{comment}{ !< The inverse of dt [T-1 ~> s-1]}
717   \textcolor{keywordtype}{integer},                                   \textcolor{keywordtype}{intent(in)}    :: ntr\textcolor{comment}{ !< The number of tracers}
718   \textcolor{keywordtype}{integer},                                   \textcolor{keywordtype}{intent(in)}    :: is\textcolor{comment}{  !< The starting tracer i-index to work on}
719   \textcolor{keywordtype}{integer},                                   \textcolor{keywordtype}{intent(in)}    :: ie\textcolor{comment}{  !< The ending tracer i-index to work on}
720   \textcolor{keywordtype}{integer},                                   \textcolor{keywordtype}{intent(in)}    :: js\textcolor{comment}{  !< The starting tracer j-index to work on}
721   \textcolor{keywordtype}{integer},                                   \textcolor{keywordtype}{intent(in)}    :: je\textcolor{comment}{  !< The ending tracer j-index to work on}
722   \textcolor{keywordtype}{integer},                                   \textcolor{keywordtype}{intent(in)}    :: k\textcolor{comment}{   !< The k-level to work on}
723   \textcolor{keywordtype}{type}(unit\_scale\_type),                     \textcolor{keywordtype}{intent(in)}    :: US\textcolor{comment}{  !< A dimensional unit scaling type}
724   \textcolor{keywordtype}{logical},                                   \textcolor{keywordtype}{intent(in)}    :: usePPM\textcolor{comment}{ !< If true, use PPM instead of PLM}
725   \textcolor{keywordtype}{logical},                                   \textcolor{keywordtype}{intent(in)}    :: useHuynh\textcolor{comment}{ !< If true, use the Huynh scheme}
726 \textcolor{comment}{                                                                     !! for PPM interface values}
727 
728   \textcolor{keywordtype}{real}, \textcolor{keywordtype}{dimension(SZI\_(G),ntr,SZJ\_(G))} :: &
729     slope\_y                     \textcolor{comment}{! The concentration slope per grid point [conc].}
730   \textcolor{keywordtype}{real}, \textcolor{keywordtype}{dimension(SZI\_(G),ntr,SZJB\_(G))} :: &
731        flux\_y                      \textcolor{comment}{! The tracer flux across a boundary [H m2 conc ~> m3 conc or kg conc].}
732   \textcolor{keywordtype}{real}, \textcolor{keywordtype}{dimension(SZI\_(G),ntr,SZJB\_(G))} :: &
733     T\_tmp               \textcolor{comment}{! The copy of the tracer concentration at constant i,k [H m2 conc ~> m3 conc or kg
       conc].}
734   \textcolor{keywordtype}{real} :: maxslope              \textcolor{comment}{! The maximum concentration slope per grid point}
735                                 \textcolor{comment}{! consistent with monotonicity [conc].}
736   \textcolor{keywordtype}{real} :: vhh(SZI\_(G),SZJB\_(G)) \textcolor{comment}{! The meridional flux that occurs during the}
737                                 \textcolor{comment}{! current iteration [H L2 ~> m3 or kg].}
738   \textcolor{keywordtype}{real} :: hup, hlos             \textcolor{comment}{! hup is the upwind volume, hlos is the}
739                                 \textcolor{comment}{! part of that volume that might be lost}
740                                 \textcolor{comment}{! due to advection out the other side of}
741                                 \textcolor{comment}{! the grid box, both in  [H L2 ~> m3 or kg].}
742   \textcolor{keywordtype}{real}, \textcolor{keywordtype}{dimension(SZIB\_(G))} :: &
743     hlst, &             \textcolor{comment}{! Work variable [H L2 ~> m3 or kg].}
744     Ihnew, &            \textcolor{comment}{! Work variable [H-1 L-2 ~> m-3 or kg-1].}
745     CFL                 \textcolor{comment}{! The absolute value of the advective upwind-cell CFL number [nondim].}
746   \textcolor{keywordtype}{real} :: min\_h         \textcolor{comment}{! The minimum thickness that can be realized during}
747                         \textcolor{comment}{! any of the passes [H ~> m or kg m-2].}
748   \textcolor{keywordtype}{real} :: tiny\_h        \textcolor{comment}{! The smallest numerically invertable thickness [H ~> m or kg m-2].}
749   \textcolor{keywordtype}{real} :: h\_neglect     \textcolor{comment}{! A thickness that is so small it is usually lost}
750                         \textcolor{comment}{! in roundoff and can be neglected [H ~> m or kg m-2].}
751   \textcolor{keywordtype}{logical} :: do\_j\_tr(SZJ\_(G))   \textcolor{comment}{! If true, calculate the tracer profiles.}
752   \textcolor{keywordtype}{logical} :: do\_i(SZIB\_(G), SZJ\_(G))     \textcolor{comment}{! If true, work on given points.}
753   \textcolor{keywordtype}{logical} :: do\_any\_i
754   \textcolor{keywordtype}{integer} :: i, j, j2, m, n, j\_up, stencil
755   \textcolor{keywordtype}{real} :: aR, aL, dMx, dMn, Tp, Tc, Tm, dA, mA, a6
756   \textcolor{keywordtype}{real} :: fac1,v\_L\_in,v\_L\_out  \textcolor{comment}{! terms used for time-stepping OBC reservoirs}
757   \textcolor{keywordtype}{type}(OBC\_segment\_type), \textcolor{keywordtype}{pointer} :: segment=>null()
758   \textcolor{keywordtype}{logical} :: usePLMslope
759 
760   useplmslope = .not. (useppm .and. usehuynh)
761   \textcolor{comment}{! stencil for calculating slope values}
762   stencil = 1
763   \textcolor{keywordflow}{if} (useppm .and. .not. usehuynh) stencil = 2
764 
765   min\_h = 0.1*gv%Angstrom\_H
766   tiny\_h = tiny(min\_h)
767   h\_neglect = gv%H\_subroundoff
768 
769   \textcolor{comment}{! We conditionally perform work on tracer points: calculating the PLM slope,}
770   \textcolor{comment}{! and updating tracer concentration within a cell}
771   \textcolor{comment}{! this depends on whether there is a flux which would affect this tracer point,}
772   \textcolor{comment}{! as indicated by domore\_v. In the case of PPM reconstruction, a flux requires}
773   \textcolor{comment}{! slope calculations at the two tracer points on either side (as indicated by}
774   \textcolor{comment}{! the stencil variable), so we account for this with the do\_j\_tr flag array}
775   \textcolor{comment}{!}
776   \textcolor{comment}{! Note: this does lead to unnecessary work in updating tracer concentrations,}
777   \textcolor{comment}{! since that doesn't need a wider stencil with the PPM advection scheme, but}
778   \textcolor{comment}{! this would require an additional loop, etc.}
779   do\_j\_tr(:) = .false.
780   \textcolor{keywordflow}{do} j=js-1,je ; \textcolor{keywordflow}{if} (domore\_v(j,k)) \textcolor{keywordflow}{then} ; \textcolor{keywordflow}{do} j2=1-stencil,stencil ; do\_j\_tr(j+j2) = .true. ;\textcolor{keywordflow}{ enddo} ;\textcolor{keywordflow}{ endif}
       ;\textcolor{keywordflow}{ enddo}
781 
782   \textcolor{comment}{! Calculate the j-direction profiles (slopes) of each tracer that}
783   \textcolor{comment}{! is being advected.}
784   \textcolor{keywordflow}{if} (useplmslope) \textcolor{keywordflow}{then}
785     \textcolor{keywordflow}{do} j=js-stencil,je+stencil ; \textcolor{keywordflow}{if} (do\_j\_tr(j)) \textcolor{keywordflow}{then} ; \textcolor{keywordflow}{do} m=1,ntr ; \textcolor{keywordflow}{do} i=is,ie
786       \textcolor{comment}{!if (ABS(Tr(m)%t(i,j+1,k)-Tr(m)%t(i,j,k)) < &}
787       \textcolor{comment}{!    ABS(Tr(m)%t(i,j,k)-Tr(m)%t(i,j-1,k))) then}
788       \textcolor{comment}{!  maxslope = 4.0*(Tr(m)%t(i,j+1,k)-Tr(m)%t(i,j,k))}
789       \textcolor{comment}{!else}
790       \textcolor{comment}{!  maxslope = 4.0*(Tr(m)%t(i,j,k)-Tr(m)%t(i,j-1,k))}
791       \textcolor{comment}{!endif}
792       \textcolor{comment}{!if ((Tr(m)%t(i,j+1,k)-Tr(m)%t(i,j,k))*(Tr(m)%t(i,j,k)-Tr(m)%t(i,j-1,k)) < 0.0) then}
793       \textcolor{comment}{!  slope\_y(i,m,j) = 0.0}
794       \textcolor{comment}{!elseif (ABS(Tr(m)%t(i,j+1,k)-Tr(m)%t(i,j-1,k))<ABS(maxslope)) then}
795       \textcolor{comment}{!  slope\_y(i,m,j) = G%mask2dCv(i,J) * G%mask2dCv(i,J-1) * &}
796       \textcolor{comment}{!                 0.5*(Tr(m)%t(i,j+1,k)-Tr(m)%t(i,j-1,k))}
797       \textcolor{comment}{!else}
798       \textcolor{comment}{!  slope\_y(i,m,j) = G%mask2dCv(i,J) * G%mask2dCv(i,J-1) * 0.5*maxslope}
799       \textcolor{comment}{!endif}
800        tp = tr(m)%t(i,j+1,k) ; tc = tr(m)%t(i,j,k) ; tm = tr(m)%t(i,j-1,k)
801        dmx = max( tp, tc, tm ) - tc
802        dmn= tc - min( tp, tc, tm )
803        slope\_y(i,m,j) = g%mask2dCv(i,j)*g%mask2dCv(i,j-1) * &
804            sign( min(0.5*abs(tp-tm), 2.0*dmx, 2.0*dmn), tp-tm )
805 \textcolor{keywordflow}{    enddo} ;\textcolor{keywordflow}{ enddo} ;\textcolor{keywordflow}{ endif} ;\textcolor{keywordflow}{ enddo} \textcolor{comment}{! End of i-, m-, & j- loops.}
806 \textcolor{keywordflow}{  endif} \textcolor{comment}{! usePLMslope}
807 
808 
809   \textcolor{comment}{! make a copy of the tracers in case values need to be overridden for OBCs}
810 
811   \textcolor{keywordflow}{do} j=g%jsd,g%jed ; \textcolor{keywordflow}{do} m=1,ntr ; \textcolor{keywordflow}{do} i=g%isd,g%ied
812     t\_tmp(i,m,j) = tr(m)%t(i,j,k)
813 \textcolor{keywordflow}{  enddo} ;\textcolor{keywordflow}{ enddo} ;\textcolor{keywordflow}{ enddo}
814 
815   \textcolor{comment}{! loop through open boundaries and recalculate flux terms}
816   \textcolor{keywordflow}{if} (\textcolor{keyword}{associated}(obc)) \textcolor{keywordflow}{then} ; \textcolor{keywordflow}{if} (obc%OBC\_pe) \textcolor{keywordflow}{then}
817      \textcolor{keywordflow}{do} n=1,obc%number\_of\_segments
818        segment=>obc%segment(n)
819        \textcolor{keywordflow}{if} (.not. \textcolor{keyword}{associated}(segment%tr\_Reg)) cycle
820        \textcolor{keywordflow}{do} i=is,ie
821          \textcolor{keywordflow}{if} (segment%is\_N\_or\_S) \textcolor{keywordflow}{then}
822            \textcolor{keywordflow}{if} (i>=segment%HI%isd .and. i<=segment%HI%ied) \textcolor{keywordflow}{then}
823               j = segment%HI%JsdB
824               \textcolor{keywordflow}{do} m = 1,ntr \textcolor{comment}{! replace tracers with OBC values}
825                 \textcolor{keywordflow}{if} (\textcolor{keyword}{associated}(segment%tr\_Reg%Tr(m)%tres)) \textcolor{keywordflow}{then}
826                    \textcolor{keywordflow}{if} (segment%direction == obc\_direction\_s) \textcolor{keywordflow}{then}
827                       t\_tmp(i,m,j) = segment%tr\_Reg%Tr(m)%tres(i,j,k)
828                    \textcolor{keywordflow}{else}
829                       t\_tmp(i,m,j+1) = segment%tr\_Reg%Tr(m)%tres(i,j,k)
830 \textcolor{keywordflow}{                   endif}
831                 \textcolor{keywordflow}{else}
832                    \textcolor{keywordflow}{if} (segment%direction == obc\_direction\_s) \textcolor{keywordflow}{then}
833                       t\_tmp(i,m,j) = segment%tr\_Reg%Tr(m)%OBC\_inflow\_conc
834                    \textcolor{keywordflow}{else}
835                       t\_tmp(i,m,j+1) = segment%tr\_Reg%Tr(m)%OBC\_inflow\_conc
836 \textcolor{keywordflow}{                   endif}
837 \textcolor{keywordflow}{                endif}
838 \textcolor{keywordflow}{              enddo}
839               \textcolor{keywordflow}{do} m = 1,ntr \textcolor{comment}{! Apply update tracer values for slope calculation}
840                 \textcolor{keywordflow}{do} j=segment%HI%JsdB-1,segment%HI%JsdB+1
841                   tp = t\_tmp(i,m,j+1) ; tc = t\_tmp(i,m,j) ; tm = t\_tmp(i,m,j-1)
842                   dmx = max( tp, tc, tm ) - tc
843                   dmn= tc - min( tp, tc, tm )
844                   slope\_y(i,m,j) = g%mask2dCv(i,j)*g%mask2dCv(i,j-1) * &
845                        sign( min(0.5*abs(tp-tm), 2.0*dmx, 2.0*dmn), tp-tm )
846 \textcolor{keywordflow}{                enddo}
847 \textcolor{keywordflow}{              enddo}
848 \textcolor{keywordflow}{           endif}
849 \textcolor{keywordflow}{         endif} \textcolor{comment}{! is\_N\_S}
850 \textcolor{keywordflow}{       enddo} \textcolor{comment}{! i-loop}
851 \textcolor{keywordflow}{     enddo} \textcolor{comment}{! segment loop}
852 \textcolor{keyword}{  end}if; endif
853 
854   \textcolor{comment}{! Calculate the j-direction fluxes of each tracer, using as much}
855   \textcolor{comment}{! the minimum of the remaining mass flux (vhr) and the half the mass}
856   \textcolor{comment}{! in the cell plus whatever part of its half of the mass flux that}
857   \textcolor{comment}{! the flux through the other side does not require.}
858   \textcolor{keywordflow}{do} j=js-1,je ; \textcolor{keywordflow}{if} (domore\_v(j,k)) \textcolor{keywordflow}{then}
859     domore\_v(j,k) = .false.
860 
861     \textcolor{keywordflow}{do} i=is,ie
862       \textcolor{keywordflow}{if} ((vhr(i,j,k) == 0.0) .or. &
863           ((vhr(i,j,k) < 0.0) .and. (hprev(i,j+1,k) <= tiny\_h)) .or. &
864           ((vhr(i,j,k) > 0.0) .and. (hprev(i,j,k) <= tiny\_h)) ) \textcolor{keywordflow}{then}
865         vhh(i,j) = 0.0
866         cfl(i) = 0.0
867       \textcolor{keywordflow}{elseif} (vhr(i,j,k) < 0.0) \textcolor{keywordflow}{then}
868         hup = hprev(i,j+1,k) - g%areaT(i,j+1)*min\_h
869         hlos = max(0.0, vhr(i,j+1,k))
870         \textcolor{keywordflow}{if} ((((hup - hlos) + vhr(i,j,k)) < 0.0) .and. &
871             ((0.5*hup + vhr(i,j,k)) < 0.0)) \textcolor{keywordflow}{then}
872           vhh(i,j) = min(-0.5*hup, -hup+hlos, 0.0)
873           domore\_v(j,k) = .true.
874         \textcolor{keywordflow}{else}
875           vhh(i,j) = vhr(i,j,k)
876 \textcolor{keywordflow}{        endif}
877         cfl(i) = - vhh(i,j) / hprev(i,j+1,k)  \textcolor{comment}{! CFL is positive}
878       \textcolor{keywordflow}{else}
879         hup = hprev(i,j,k) - g%areaT(i,j)*min\_h
880         hlos = max(0.0, -vhr(i,j-1,k))
881         \textcolor{keywordflow}{if} ((((hup - hlos) - vhr(i,j,k)) < 0.0) .and. &
882             ((0.5*hup - vhr(i,j,k)) < 0.0)) \textcolor{keywordflow}{then}
883           vhh(i,j) = max(0.5*hup, hup-hlos, 0.0)
884           domore\_v(j,k) = .true.
885         \textcolor{keywordflow}{else}
886           vhh(i,j) = vhr(i,j,k)
887 \textcolor{keywordflow}{        endif}
888         cfl(i) = vhh(i,j) / hprev(i,j,k)  \textcolor{comment}{! CFL is positive}
889 \textcolor{keywordflow}{      endif}
890 \textcolor{keywordflow}{    enddo}
891 
892     \textcolor{keywordflow}{if} (useppm) \textcolor{keywordflow}{then}
893       \textcolor{keywordflow}{do} m=1,ntr ; \textcolor{keywordflow}{do} i=is,ie
894         \textcolor{comment}{! centre cell depending on upstream direction}
895         \textcolor{keywordflow}{if} (vhh(i,j) >= 0.0) \textcolor{keywordflow}{then}
896           j\_up = j
897         \textcolor{keywordflow}{else}
898           j\_up = j + 1
899 \textcolor{keywordflow}{        endif}
900 
901         \textcolor{comment}{! Implementation of PPM-H3}
902         tp = t\_tmp(i,m,j\_up+1) ; tc = t\_tmp(i,m,j\_up) ; tm = t\_tmp(i,m,j\_up-1)
903 
904         \textcolor{keywordflow}{if} (usehuynh) \textcolor{keywordflow}{then}
905           al = ( 5.*tc + ( 2.*tm - tp ) )/6. \textcolor{comment}{! H3 estimate}
906           al = max( min(tc,tm), al) ; al = min( max(tc,tm), al) \textcolor{comment}{! Bound}
907           ar = ( 5.*tc + ( 2.*tp - tm ) )/6. \textcolor{comment}{! H3 estimate}
908           ar = max( min(tc,tp), ar) ; ar = min( max(tc,tp), ar) \textcolor{comment}{! Bound}
909         \textcolor{keywordflow}{else}
910           al = 0.5 * ((tm + tc) + (slope\_y(i,m,j\_up-1) - slope\_y(i,m,j\_up)) / 3.)
911           ar = 0.5 * ((tc + tp) + (slope\_y(i,m,j\_up) - slope\_y(i,m,j\_up+1)) / 3.)
912 \textcolor{keywordflow}{        endif}
913 
914         da = ar - al ; ma = 0.5*( ar + al )
915         \textcolor{keywordflow}{if} (g%mask2dCv(i,j\_up)*g%mask2dCv(i,j\_up-1)*(tp-tc)*(tc-tm) <= 0.) \textcolor{keywordflow}{then}
916           al = tc ; ar = tc \textcolor{comment}{! PCM for local extremum and bounadry cells}
917         \textcolor{keywordflow}{elseif} ( da*(tc-ma) > (da*da)/6. ) \textcolor{keywordflow}{then}
918           al = 3.*tc - 2.*ar
919         \textcolor{keywordflow}{elseif} ( da*(tc-ma) < - (da*da)/6. ) \textcolor{keywordflow}{then}
920           ar = 3.*tc - 2.*al
921 \textcolor{keywordflow}{        endif}
922 
923         a6 = 6.*tc - 3. * (ar + al) \textcolor{comment}{! Curvature}
924 
925         \textcolor{keywordflow}{if} (vhh(i,j) >= 0.0) \textcolor{keywordflow}{then}
926           flux\_y(i,m,j) = vhh(i,j)*( ar - 0.5 * cfl(i) * ( &
927                ( ar - al ) - a6 * ( 1. - 2./3. * cfl(i) ) ) )
928         \textcolor{keywordflow}{else}
929           flux\_y(i,m,j) = vhh(i,j)*( al + 0.5 * cfl(i) * ( &
930                ( ar - al ) + a6 * ( 1. - 2./3. * cfl(i) ) ) )
931 \textcolor{keywordflow}{        endif}
932 \textcolor{keywordflow}{      enddo} ;\textcolor{keywordflow}{ enddo}
933     \textcolor{keywordflow}{else} \textcolor{comment}{! PLM}
934       \textcolor{keywordflow}{do} m=1,ntr ; \textcolor{keywordflow}{do} i=is,ie
935         \textcolor{keywordflow}{if} (vhh(i,j) >= 0.0) \textcolor{keywordflow}{then}
936           \textcolor{comment}{! Indirect implementation of PLM}
937          \textcolor{comment}{!aL = Tr(m)%t(i,j,k) - 0.5 * slope\_y(i,m,j)}
938          \textcolor{comment}{!aR = Tr(m)%t(i,j,k) + 0.5 * slope\_y(i,m,j)}
939          \textcolor{comment}{!flux\_y(i,m,J) = vhh(i,J)*( aR - 0.5 * (aR-aL) * CFL(i) )}
940           \textcolor{comment}{! Alternative implementation of PLM}
941           tc = t\_tmp(i,m,j)
942           flux\_y(i,m,j) = vhh(i,j)*( tc + 0.5 * slope\_y(i,m,j) * ( 1. - cfl(i) ) )
943         \textcolor{keywordflow}{else}
944           \textcolor{comment}{! Indirect implementation of PLM}
945          \textcolor{comment}{!aL = Tr(m)%t(i,j+1,k) - 0.5 * slope\_y(i,m,j+1)}
946          \textcolor{comment}{!aR = Tr(m)%t(i,j+1,k) + 0.5 * slope\_y(i,m,j+1)}
947          \textcolor{comment}{!flux\_y(i,m,J) = vhh(i,J)*( aL + 0.5 * (aR-aL) * CFL(i) )}
948           \textcolor{comment}{! Alternative implementation of PLM}
949           tc = t\_tmp(i,m,j+1)
950           flux\_y(i,m,j) = vhh(i,j)*( tc - 0.5 * slope\_y(i,m,j+1) * ( 1. - cfl(i) ) )
951 \textcolor{keywordflow}{        endif}
952 \textcolor{keywordflow}{      enddo} ;\textcolor{keywordflow}{ enddo}
953 \textcolor{keywordflow}{    endif} \textcolor{comment}{! usePPM}
954 
955     \textcolor{keywordflow}{if} (\textcolor{keyword}{associated}(obc)) \textcolor{keywordflow}{then} ; \textcolor{keywordflow}{if} (obc%OBC\_pe) \textcolor{keywordflow}{then}
956       \textcolor{keywordflow}{if} (obc%specified\_v\_BCs\_exist\_globally .or. obc%open\_v\_BCs\_exist\_globally) \textcolor{keywordflow}{then}
957         \textcolor{keywordflow}{do} n=1,obc%number\_of\_segments
958           segment=>obc%segment(n)
959           \textcolor{keywordflow}{if} (.not. segment%specified) cycle
960           \textcolor{keywordflow}{if} (.not. \textcolor{keyword}{associated}(segment%tr\_Reg)) cycle
961           \textcolor{keywordflow}{if} (obc%segment(n)%is\_N\_or\_S) \textcolor{keywordflow}{then}
962             \textcolor{keywordflow}{if} (j >= segment%HI%JsdB .and. j<= segment%HI%JedB) \textcolor{keywordflow}{then}
963               \textcolor{keywordflow}{do} i=segment%HI%isd,segment%HI%ied
964                 \textcolor{comment}{! Tracer fluxes are set to prescribed values only for inflows from masked areas.}
965                 \textcolor{comment}{! Now changing to simply fixed inflows.}
966                 \textcolor{keywordflow}{if} ((vhr(i,j,k) > 0.0) .and. (segment%direction == obc\_direction\_s) .or. &
967                    (vhr(i,j,k) < 0.0) .and. (segment%direction == obc\_direction\_n)) \textcolor{keywordflow}{then}
968                   vhh(i,j) = vhr(i,j,k)
969                   \textcolor{keywordflow}{do} m=1,ntr
970                     \textcolor{keywordflow}{if} (\textcolor{keyword}{associated}(segment%tr\_Reg%Tr(m)%t)) \textcolor{keywordflow}{then}
971                       flux\_y(i,m,j) = vhh(i,j)*obc%segment(n)%tr\_Reg%Tr(m)%tres(i,j,k)
972                     \textcolor{keywordflow}{else} ; flux\_y(i,m,j) = vhh(i,j)*obc%segment(n)%tr\_Reg%Tr(m)%OBC\_inflow\_conc ;\textcolor{keywordflow}{ endif}
973 \textcolor{keywordflow}{                  enddo}
974 \textcolor{keywordflow}{                endif}
975 \textcolor{keywordflow}{              enddo}
976 \textcolor{keywordflow}{            endif}
977 \textcolor{keywordflow}{          endif}
978 \textcolor{keywordflow}{        enddo}
979 \textcolor{keywordflow}{      endif}
980 
981       \textcolor{keywordflow}{if} (obc%open\_v\_BCs\_exist\_globally) \textcolor{keywordflow}{then}
982         \textcolor{keywordflow}{do} n=1,obc%number\_of\_segments
983           segment=>obc%segment(n)
984           \textcolor{keywordflow}{if} (segment%specified) cycle
985           \textcolor{keywordflow}{if} (.not. \textcolor{keyword}{associated}(segment%tr\_Reg)) cycle
986           \textcolor{keywordflow}{if} (segment%is\_N\_or\_S .and. (j >= segment%HI%JsdB .and. j<= segment%HI%JedB)) \textcolor{keywordflow}{then}
987             \textcolor{keywordflow}{do} i=segment%HI%isd,segment%HI%ied
988               \textcolor{comment}{! Tracer fluxes are set to prescribed values only for inflows from masked areas.}
989               \textcolor{keywordflow}{if} ((vhr(i,j,k) > 0.0) .and. (g%mask2dT(i,j) < 0.5) .or. &
990                   (vhr(i,j,k) < 0.0) .and. (g%mask2dT(i,j+1) < 0.5)) \textcolor{keywordflow}{then}
991                 vhh(i,j) = vhr(i,j,k)
992                 \textcolor{keywordflow}{do} m=1,ntr
993                   \textcolor{keywordflow}{if} (\textcolor{keyword}{associated}(segment%tr\_Reg%Tr(m)%t)) \textcolor{keywordflow}{then}
994                     flux\_y(i,m,j) = vhh(i,j)*segment%tr\_Reg%Tr(m)%tres(i,j,k)
995                   \textcolor{keywordflow}{else} ; flux\_y(i,m,j) = vhh(i,j)*segment%tr\_Reg%Tr(m)%OBC\_inflow\_conc ;\textcolor{keywordflow}{ endif}
996 \textcolor{keywordflow}{                enddo}
997 \textcolor{keywordflow}{              endif}
998 \textcolor{keywordflow}{            enddo}
999 \textcolor{keywordflow}{          endif}
1000 \textcolor{keywordflow}{        enddo}
1001 \textcolor{keywordflow}{      endif}
1002 \textcolor{keyword}{    end}if; endif
1003 
1004   \textcolor{keywordflow}{else} \textcolor{comment}{! not domore\_v.}
1005     \textcolor{keywordflow}{do} i=is,ie ; vhh(i,j) = 0.0 ;\textcolor{keywordflow}{ enddo}
1006     \textcolor{keywordflow}{do} m=1,ntr ; \textcolor{keywordflow}{do} i=is,ie ; flux\_y(i,m,j) = 0.0 ;\textcolor{keywordflow}{ enddo} ;\textcolor{keywordflow}{ enddo}
1007 \textcolor{keywordflow}{  endif} ;\textcolor{keywordflow}{ enddo} \textcolor{comment}{! End of j-loop}
1008 
1009   \textcolor{keywordflow}{do} j=js-1,je ; \textcolor{keywordflow}{do} i=is,ie
1010     vhr(i,j,k) = vhr(i,j,k) - vhh(i,j)
1011     \textcolor{keywordflow}{if} (abs(vhr(i,j,k)) < vh\_neglect(i,j)) vhr(i,j,k) = 0.0
1012 \textcolor{keywordflow}{  enddo} ;\textcolor{keywordflow}{ enddo}
1013 
1014   \textcolor{comment}{! Calculate new tracer concentration in each cell after accounting}
1015   \textcolor{comment}{! for the j-direction fluxes.}
1016   \textcolor{keywordflow}{do} j=js,je ; \textcolor{keywordflow}{if} (do\_j\_tr(j)) \textcolor{keywordflow}{then}
1017     \textcolor{keywordflow}{do} i=is,ie
1018       \textcolor{keywordflow}{if} ((vhh(i,j) /= 0.0) .or. (vhh(i,j-1) /= 0.0)) \textcolor{keywordflow}{then}
1019         do\_i(i,j) = .true.
1020         hlst(i) = hprev(i,j,k)
1021         hprev(i,j,k) = max(hprev(i,j,k) - (vhh(i,j) - vhh(i,j-1)), 0.0)
1022         \textcolor{keywordflow}{if} (hprev(i,j,k) <= 0.0) \textcolor{keywordflow}{then} ; do\_i(i,j) = .false.
1023         \textcolor{keywordflow}{elseif} (hprev(i,j,k) < h\_neglect*g%areaT(i,j)) \textcolor{keywordflow}{then}
1024           hlst(i) = hlst(i) + (h\_neglect*g%areaT(i,j) - hprev(i,j,k))
1025           ihnew(i) = 1.0 / (h\_neglect*g%areaT(i,j))
1026         \textcolor{keywordflow}{else} ;  ihnew(i) = 1.0 / hprev(i,j,k) ;\textcolor{keywordflow}{ endif}
1027       \textcolor{keywordflow}{else} ; do\_i(i,j) = .false. ;\textcolor{keywordflow}{ endif}
1028 \textcolor{keywordflow}{    enddo}
1029 
1030     \textcolor{comment}{! update tracer and save some diagnostics}
1031     \textcolor{keywordflow}{do} m=1,ntr
1032       \textcolor{keywordflow}{do} i=is,ie ; \textcolor{keywordflow}{if} (do\_i(i,j)) \textcolor{keywordflow}{then}
1033         tr(m)%t(i,j,k) = (tr(m)%t(i,j,k) * hlst(i) - &
1034                           (flux\_y(i,m,j) - flux\_y(i,m,j-1))) * ihnew(i)
1035 \textcolor{keywordflow}{      endif} ;\textcolor{keywordflow}{ enddo}
1036 
1037       \textcolor{comment}{! diagnostics}
1038       \textcolor{keywordflow}{if} (\textcolor{keyword}{associated}(tr(m)%ad\_y)) \textcolor{keywordflow}{then} ; \textcolor{keywordflow}{do} i=is,ie ; \textcolor{keywordflow}{if} (do\_i(i,j)) \textcolor{keywordflow}{then}
1039         tr(m)%ad\_y(i,j,k) = tr(m)%ad\_y(i,j,k) + flux\_y(i,m,j)*idt
1040 \textcolor{keywordflow}{      endif} ;\textcolor{keywordflow}{ enddo} ;\textcolor{keywordflow}{ endif}
1041 
1042       \textcolor{comment}{! diagnose convergence of flux\_y and add to convergence of flux\_x.}
1043       \textcolor{comment}{! division by areaT to get into W/m2 for heat and kg/(s*m2) for salt.}
1044       \textcolor{keywordflow}{if} (\textcolor{keyword}{associated}(tr(m)%advection\_xy)) \textcolor{keywordflow}{then}
1045         \textcolor{keywordflow}{do} i=is,ie ; \textcolor{keywordflow}{if} (do\_i(i,j)) \textcolor{keywordflow}{then}
1046           tr(m)%advection\_xy(i,j,k) = tr(m)%advection\_xy(i,j,k) - (flux\_y(i,m,j) - flux\_y(i,m,j-1))* idt * 
      &
1047                                           g%IareaT(i,j)
1048 \textcolor{keywordflow}{        endif} ;\textcolor{keywordflow}{ enddo}
1049 \textcolor{keywordflow}{      endif}
1050 
1051 \textcolor{keywordflow}{    enddo}
1052 \textcolor{keywordflow}{  endif} ;\textcolor{keywordflow}{ enddo} \textcolor{comment}{! End of j-loop.}
1053 
1054   \textcolor{comment}{! compute ad2d\_y diagnostic outside above j-loop so as to make the summation ordered when OMP is active.}
1055 
1056   \textcolor{comment}{!$OMP ordered}
1057   \textcolor{keywordflow}{do} j=js,je ; \textcolor{keywordflow}{if} (do\_j\_tr(j)) \textcolor{keywordflow}{then}
1058     \textcolor{keywordflow}{do} m=1,ntr
1059       \textcolor{keywordflow}{if} (\textcolor{keyword}{associated}(tr(m)%ad2d\_y)) \textcolor{keywordflow}{then} ; \textcolor{keywordflow}{do} i=is,ie ; \textcolor{keywordflow}{if} (do\_i(i,j)) \textcolor{keywordflow}{then}
1060         tr(m)%ad2d\_y(i,j) = tr(m)%ad2d\_y(i,j) + flux\_y(i,m,j)*idt
1061 \textcolor{keywordflow}{      endif} ;\textcolor{keywordflow}{ enddo} ;\textcolor{keywordflow}{ endif}
1062 \textcolor{keywordflow}{    enddo}
1063 \textcolor{keywordflow}{  endif} ;\textcolor{keywordflow}{ enddo} \textcolor{comment}{! End of j-loop.}
1064   \textcolor{comment}{!$OMP end ordered}
1065 
\end{DoxyCode}
\mbox{\Hypertarget{namespacemom__tracer__advect_a2e466a8a34546bb9265a74ff0209df47}\label{namespacemom__tracer__advect_a2e466a8a34546bb9265a74ff0209df47}} 
\index{mom\+\_\+tracer\+\_\+advect@{mom\+\_\+tracer\+\_\+advect}!tracer\+\_\+advect\+\_\+end@{tracer\+\_\+advect\+\_\+end}}
\index{tracer\+\_\+advect\+\_\+end@{tracer\+\_\+advect\+\_\+end}!mom\+\_\+tracer\+\_\+advect@{mom\+\_\+tracer\+\_\+advect}}
\subsubsection{\texorpdfstring{tracer\+\_\+advect\+\_\+end()}{tracer\_advect\_end()}}
{\footnotesize\ttfamily subroutine, public mom\+\_\+tracer\+\_\+advect\+::tracer\+\_\+advect\+\_\+end (\begin{DoxyParamCaption}\item[{type(\mbox{\hyperlink{structmom__tracer__advect_1_1tracer__advect__cs}{tracer\+\_\+advect\+\_\+cs}}), pointer}]{CS }\end{DoxyParamCaption})}



Close the tracer advection module. 


\begin{DoxyParams}{Parameters}
{\em cs} & module control structure \\
\hline
\end{DoxyParams}


Definition at line 1125 of file M\+O\+M\+\_\+tracer\+\_\+advect.\+F90.


\begin{DoxyCode}
1125   \textcolor{keywordtype}{type}(tracer\_advect\_CS), \textcolor{keywordtype}{pointer} :: CS\textcolor{comment}{  !< module control structure}
1126 
1127   \textcolor{keywordflow}{if} (\textcolor{keyword}{associated}(cs)) \textcolor{keyword}{deallocate}(cs)
1128 
\end{DoxyCode}
\mbox{\Hypertarget{namespacemom__tracer__advect_aacf9cdc544c9c3a188d6e3e9a0d7b9df}\label{namespacemom__tracer__advect_aacf9cdc544c9c3a188d6e3e9a0d7b9df}} 
\index{mom\+\_\+tracer\+\_\+advect@{mom\+\_\+tracer\+\_\+advect}!tracer\+\_\+advect\+\_\+init@{tracer\+\_\+advect\+\_\+init}}
\index{tracer\+\_\+advect\+\_\+init@{tracer\+\_\+advect\+\_\+init}!mom\+\_\+tracer\+\_\+advect@{mom\+\_\+tracer\+\_\+advect}}
\subsubsection{\texorpdfstring{tracer\+\_\+advect\+\_\+init()}{tracer\_advect\_init()}}
{\footnotesize\ttfamily subroutine, public mom\+\_\+tracer\+\_\+advect\+::tracer\+\_\+advect\+\_\+init (\begin{DoxyParamCaption}\item[{type(time\+\_\+type), intent(in), target}]{Time,  }\item[{type(ocean\+\_\+grid\+\_\+type), intent(in)}]{G,  }\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__tracer__advect_1_1tracer__advect__cs}{tracer\+\_\+advect\+\_\+cs}}), pointer}]{CS }\end{DoxyParamCaption})}



Initialize lateral tracer advection module. 


\begin{DoxyParams}[1]{Parameters}
\mbox{\tt in}  & {\em time} & current model time\\
\hline
\mbox{\tt in}  & {\em g} & ocean grid structure\\
\hline
\mbox{\tt in}  & {\em us} & A dimensional unit scaling type\\
\hline
\mbox{\tt in}  & {\em param\+\_\+file} & open file to parse for model parameters\\
\hline
\mbox{\tt in,out}  & {\em diag} & regulates diagnostic output\\
\hline
 & {\em cs} & module control structure \\
\hline
\end{DoxyParams}


Definition at line 1070 of file M\+O\+M\+\_\+tracer\+\_\+advect.\+F90.


\begin{DoxyCode}
1070   \textcolor{keywordtype}{type}(time\_type), \textcolor{keywordtype}{target}, \textcolor{keywordtype}{intent(in)}    :: Time\textcolor{comment}{        !< current model time}
1071   \textcolor{keywordtype}{type}(ocean\_grid\_type),   \textcolor{keywordtype}{intent(in)}    :: G\textcolor{comment}{           !< ocean grid structure}
1072   \textcolor{keywordtype}{type}(unit\_scale\_type),   \textcolor{keywordtype}{intent(in)}    :: US\textcolor{comment}{          !< A dimensional unit scaling type}
1073   \textcolor{keywordtype}{type}(param\_file\_type),   \textcolor{keywordtype}{intent(in)}    :: param\_file\textcolor{comment}{  !< open file to parse for model parameters}
1074   \textcolor{keywordtype}{type}(diag\_ctrl), \textcolor{keywordtype}{target}, \textcolor{keywordtype}{intent(inout)} :: diag\textcolor{comment}{        !< regulates diagnostic output}
1075   \textcolor{keywordtype}{type}(tracer\_advect\_CS),  \textcolor{keywordtype}{pointer}       :: CS\textcolor{comment}{          !< module control structure}
1076 
1077   \textcolor{keywordtype}{integer}, \textcolor{keywordtype}{save} :: init\_calls = 0
1078 
1079   \textcolor{comment}{! This include declares and sets the variable "version".}
1080 \textcolor{preprocessor}{# include "version\_variable.h"}
1081 \textcolor{preprocessor}{}  \textcolor{keywordtype}{character(len=40)}  :: mdl = \textcolor{stringliteral}{"MOM\_tracer\_advect"} \textcolor{comment}{! This module's name.}
1082   \textcolor{keywordtype}{character(len=256)} :: mesg    \textcolor{comment}{! Message for error messages.}
1083 
1084   \textcolor{keywordflow}{if} (\textcolor{keyword}{associated}(cs)) \textcolor{keywordflow}{then}
1085     \textcolor{keyword}{call }mom\_error(warning, \textcolor{stringliteral}{"tracer\_advect\_init called with associated control structure."})
1086     \textcolor{keywordflow}{return}
1087 \textcolor{keywordflow}{  endif}
1088   \textcolor{keyword}{allocate}(cs)
1089 
1090   cs%diag => diag
1091 
1092   \textcolor{comment}{! Read all relevant parameters and write them to the model log.}
1093   \textcolor{keyword}{call }log\_version(param\_file, mdl, version, \textcolor{stringliteral}{""})
1094   \textcolor{keyword}{call }get\_param(param\_file, mdl, \textcolor{stringliteral}{"DT"}, cs%dt, fail\_if\_missing=.true., &
1095           desc=\textcolor{stringliteral}{"The (baroclinic) dynamics time step."}, units=\textcolor{stringliteral}{"s"}, scale=us%s\_to\_T)
1096   \textcolor{keyword}{call }get\_param(param\_file, mdl, \textcolor{stringliteral}{"DEBUG"}, cs%debug, default=.false.)
1097   \textcolor{keyword}{call }get\_param(param\_file, mdl, \textcolor{stringliteral}{"TRACER\_ADVECTION\_SCHEME"}, mesg, &
1098           desc=\textcolor{stringliteral}{"The horizontal transport scheme for tracers:\(\backslash\)n"}//&
1099           \textcolor{stringliteral}{"  PLM    - Piecewise Linear Method\(\backslash\)n"}//&
1100           \textcolor{stringliteral}{"  PPM:H3 - Piecewise Parabolic Method (Huyhn 3rd order)\(\backslash\)n"}// &
1101           \textcolor{stringliteral}{"  PPM    - Piecewise Parabolic Method (Colella-Woodward)"} &
1102           , default=\textcolor{stringliteral}{'PLM'})
1103   \textcolor{keywordflow}{select case} (trim(mesg))
1104     \textcolor{keywordflow}{case} (\textcolor{stringliteral}{"PLM"})
1105       cs%usePPM = .false.
1106     \textcolor{keywordflow}{case} (\textcolor{stringliteral}{"PPM:H3"})
1107       cs%usePPM = .true.
1108       cs%useHuynh = .true.
1109     \textcolor{keywordflow}{case} (\textcolor{stringliteral}{"PPM"})
1110       cs%usePPM = .true.
1111       cs%useHuynh = .false.
1112 \textcolor{keywordflow}{    case default}
1113       \textcolor{keyword}{call }mom\_error(fatal, \textcolor{stringliteral}{"MOM\_tracer\_advect, tracer\_advect\_init: "}//&
1114            \textcolor{stringliteral}{"Unknown TRACER\_ADVECTION\_SCHEME = "}//trim(mesg))
1115 \textcolor{keywordflow}{  end select}
1116 
1117   id\_clock\_advect = cpu\_clock\_id(\textcolor{stringliteral}{'(Ocean advect tracer)'}, grain=clock\_module)
1118   id\_clock\_pass = cpu\_clock\_id(\textcolor{stringliteral}{'(Ocean tracer halo updates)'}, grain=clock\_routine)
1119   id\_clock\_sync = cpu\_clock\_id(\textcolor{stringliteral}{'(Ocean tracer global synch)'}, grain=clock\_routine)
1120 
\end{DoxyCode}
