\hypertarget{namespacemom__tracer__diabatic}{}\section{mom\+\_\+tracer\+\_\+diabatic Module Reference}
\label{namespacemom__tracer__diabatic}\index{mom\_tracer\_diabatic@{mom\_tracer\_diabatic}}


\subsection{Detailed Description}
This module contains routines that implement physical fluxes of tracers (e.\+g. due to surface fluxes or mixing). These are intended to be called from call\+\_\+tracer\+\_\+column\+\_\+fns in the \mbox{\hyperlink{namespaceMOM__tracer__flow__control}{M\+O\+M\+\_\+tracer\+\_\+flow\+\_\+control}} module. \subsection*{Functions/\+Subroutines}
\begin{DoxyCompactItemize}
\item 
subroutine, public \mbox{\hyperlink{namespacemom__tracer__diabatic_ac5d57973547cc4ed3a89808d3910943e}{tracer\+\_\+vertdiff}} (h\+\_\+old, ea, eb, dt, tr, G, GV, sfc\+\_\+flux, btm\+\_\+flux, btm\+\_\+reservoir, sink\+\_\+rate, convert\+\_\+flux\+\_\+in)
\begin{DoxyCompactList}\small\item\em This subroutine solves a tridiagonal equation for the final tracer concentrations after the dual-\/entrainments, and possibly sinking or surface and bottom sources, are applied. The sinking is implemented with an fully implicit upwind advection scheme. Alternate time units can be used for the timestep, surface and bottom fluxes and sink\+\_\+rate provided they are all consistent. \end{DoxyCompactList}\item 
subroutine, public \mbox{\hyperlink{namespacemom__tracer__diabatic_ad4d3d4de0f2b84c15bccc5eb2f767df3}{applytracerboundaryfluxesinout}} (G, GV, Tr, dt, fluxes, h, evap\+\_\+\+C\+F\+L\+\_\+limit, minimum\+\_\+forcing\+\_\+depth, in\+\_\+flux\+\_\+optional, out\+\_\+flux\+\_\+optional, update\+\_\+h\+\_\+opt)
\begin{DoxyCompactList}\small\item\em This routine is modeled after apply\+Boundary\+Fluxes\+In\+Out in \mbox{\hyperlink{MOM__diabatic__aux_8F90_source}{M\+O\+M\+\_\+diabatic\+\_\+aux.\+F90}} N\+O\+TE\+: Please note that in this routine sfc\+\_\+flux gets set to zero to ensure that the surface flux of the tracer does not get applied again during a subsequent call to tracer\+\_\+vertdif. \end{DoxyCompactList}\end{DoxyCompactItemize}


\subsection{Function/\+Subroutine Documentation}
\mbox{\Hypertarget{namespacemom__tracer__diabatic_ad4d3d4de0f2b84c15bccc5eb2f767df3}\label{namespacemom__tracer__diabatic_ad4d3d4de0f2b84c15bccc5eb2f767df3}} 
\index{mom\_tracer\_diabatic@{mom\_tracer\_diabatic}!applytracerboundaryfluxesinout@{applytracerboundaryfluxesinout}}
\index{applytracerboundaryfluxesinout@{applytracerboundaryfluxesinout}!mom\_tracer\_diabatic@{mom\_tracer\_diabatic}}
\subsubsection{\texorpdfstring{applytracerboundaryfluxesinout()}{applytracerboundaryfluxesinout()}}
{\footnotesize\ttfamily subroutine, public mom\+\_\+tracer\+\_\+diabatic\+::applytracerboundaryfluxesinout (\begin{DoxyParamCaption}\item[{type(ocean\+\_\+grid\+\_\+type), intent(in)}]{G,  }\item[{type(verticalgrid\+\_\+type), intent(in)}]{GV,  }\item[{real, dimension(szi\+\_\+(g),szj\+\_\+(g),szk\+\_\+(g)), intent(inout)}]{Tr,  }\item[{real, intent(in)}]{dt,  }\item[{type(forcing), intent(in)}]{fluxes,  }\item[{real, dimension(szi\+\_\+(g),szj\+\_\+(g),szk\+\_\+(g)), intent(inout)}]{h,  }\item[{real, intent(in)}]{evap\+\_\+\+C\+F\+L\+\_\+limit,  }\item[{real, intent(in)}]{minimum\+\_\+forcing\+\_\+depth,  }\item[{real, dimension(szi\+\_\+(g),szj\+\_\+(g)), intent(in), optional}]{in\+\_\+flux\+\_\+optional,  }\item[{real, dimension(szi\+\_\+(g),szj\+\_\+(g)), intent(in), optional}]{out\+\_\+flux\+\_\+optional,  }\item[{logical, intent(in), optional}]{update\+\_\+h\+\_\+opt }\end{DoxyParamCaption})}



This routine is modeled after apply\+Boundary\+Fluxes\+In\+Out in \mbox{\hyperlink{MOM__diabatic__aux_8F90_source}{M\+O\+M\+\_\+diabatic\+\_\+aux.\+F90}} N\+O\+TE\+: Please note that in this routine sfc\+\_\+flux gets set to zero to ensure that the surface flux of the tracer does not get applied again during a subsequent call to tracer\+\_\+vertdif. 


\begin{DoxyParams}[1]{Parameters}
\mbox{\texttt{ in}}  & {\em g} & Grid structure \\
\hline
\mbox{\texttt{ in}}  & {\em gv} & ocean vertical grid structure \\
\hline
\mbox{\texttt{ in,out}}  & {\em tr} & Tracer concentration on T-\/cell \\
\hline
\mbox{\texttt{ in}}  & {\em dt} & Time-\/step over which forcing is applied \mbox{[}T $\sim$$>$ s\mbox{]} \\
\hline
\mbox{\texttt{ in}}  & {\em fluxes} & Surface fluxes container \\
\hline
\mbox{\texttt{ in,out}}  & {\em h} & Layer thickness \mbox{[}H $\sim$$>$ m or kg m-\/2\mbox{]} \\
\hline
\mbox{\texttt{ in}}  & {\em evap\+\_\+cfl\+\_\+limit} & Limit on the fraction of the water that can be fluxed out of the top layer in a timestep \mbox{[}nondim\mbox{]} \\
\hline
\mbox{\texttt{ in}}  & {\em minimum\+\_\+forcing\+\_\+depth} & The smallest depth over which fluxes can be applied \mbox{[}H $\sim$$>$ m or kg m-\/2\mbox{]} \\
\hline
\mbox{\texttt{ in}}  & {\em in\+\_\+flux\+\_\+optional} & The total time-\/integrated amount of tracer that enters with freshwater \\
\hline
\mbox{\texttt{ in}}  & {\em out\+\_\+flux\+\_\+optional} & The total time-\/integrated amount of tracer that leaves with freshwater \\
\hline
\mbox{\texttt{ in}}  & {\em update\+\_\+h\+\_\+opt} & Optional flag to determine whether h should be updated \\
\hline
\end{DoxyParams}


Definition at line 230 of file M\+O\+M\+\_\+tracer\+\_\+diabatic.\+F90.


\begin{DoxyCode}{0}
\DoxyCodeLine{230 }
\DoxyCodeLine{231   \textcolor{keywordtype}{type}(ocean\_grid\_type),                      \textcolor{keywordtype}{intent(in   )} :: G\textcolor{comment}{  !< Grid structure}}
\DoxyCodeLine{232   \textcolor{keywordtype}{type}(verticalGrid\_type),                    \textcolor{keywordtype}{intent(in   )} :: GV\textcolor{comment}{ !< ocean vertical grid structure}}
\DoxyCodeLine{233 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(SZI\_(G),SZJ\_(G),SZK\_(G))},   \textcolor{keywordtype}{intent(inout)} :: Tr\textcolor{comment}{ !< Tracer concentration on T-cell}}
\DoxyCodeLine{234 \textcolor{keywordtype}{  real},                                       \textcolor{keywordtype}{intent(in   )} :: dt\textcolor{comment}{ !< Time-step over which forcing is applied [T ~> s]}}
\DoxyCodeLine{235   \textcolor{keywordtype}{type}(forcing),                              \textcolor{keywordtype}{intent(in   )} :: fluxes\textcolor{comment}{ !< Surface fluxes container}}
\DoxyCodeLine{236 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(SZI\_(G),SZJ\_(G),SZK\_(G))},   \textcolor{keywordtype}{intent(inout)} :: h\textcolor{comment}{  !< Layer thickness [H ~> m or kg m-2]}}
\DoxyCodeLine{237 \textcolor{keywordtype}{  real},                                       \textcolor{keywordtype}{intent(in   )} :: evap\_CFL\_limit\textcolor{comment}{ !< Limit on the fraction of the}}
\DoxyCodeLine{238 \textcolor{comment}{                                                                  !! water that can be fluxed out of the top}}
\DoxyCodeLine{239 \textcolor{comment}{                                                                  !! layer in a timestep [nondim]}}
\DoxyCodeLine{240 \textcolor{keywordtype}{  real},                                       \textcolor{keywordtype}{intent(in   )} :: minimum\_forcing\_depth\textcolor{comment}{ !< The smallest depth over}}
\DoxyCodeLine{241 \textcolor{comment}{                                                                  !! which fluxes can be applied [H ~> m or kg m-2]}}
\DoxyCodeLine{242 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(SZI\_(G),SZJ\_(G))}, \textcolor{keywordtype}{optional}, \textcolor{keywordtype}{intent(in   )} :: in\_flux\_optional\textcolor{comment}{ !< The total time-integrated}}
\DoxyCodeLine{243 \textcolor{comment}{                                                                  !! amount of tracer that enters with freshwater}}
\DoxyCodeLine{244 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(SZI\_(G),SZJ\_(G))}, \textcolor{keywordtype}{optional}, \textcolor{keywordtype}{intent(in)} :: out\_flux\_optional\textcolor{comment}{ !< The total time-integrated}}
\DoxyCodeLine{245 \textcolor{comment}{                                                                  !! amount of tracer that leaves with freshwater}}
\DoxyCodeLine{246   \textcolor{keywordtype}{logical},                          \textcolor{keywordtype}{optional}, \textcolor{keywordtype}{intent(in)} :: update\_h\_opt\textcolor{comment}{  !< Optional flag to determine whether}}
\DoxyCodeLine{247 \textcolor{comment}{                                                                  !! h should be updated}}
\DoxyCodeLine{248 }
\DoxyCodeLine{249   \textcolor{keywordtype}{integer}, \textcolor{keywordtype}{parameter} :: maxGroundings = 5}
\DoxyCodeLine{250   \textcolor{keywordtype}{integer} :: numberOfGroundings, iGround(maxGroundings), jGround(maxGroundings)}
\DoxyCodeLine{251 \textcolor{keywordtype}{  real} :: H\_limit\_fluxes, IforcingDepthScale}
\DoxyCodeLine{252 \textcolor{keywordtype}{  real} :: dThickness, dTracer}
\DoxyCodeLine{253 \textcolor{keywordtype}{  real} :: fractionOfForcing, hOld, Ithickness}
\DoxyCodeLine{254 \textcolor{keywordtype}{  real} :: RivermixConst  \textcolor{comment}{! A constant used in implementing river mixing [Pa s].}}
\DoxyCodeLine{255 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(SZI\_(G))} :: \&}
\DoxyCodeLine{256     netMassInOut, \&  \textcolor{comment}{! surface water fluxes [H ~> m or kg m-2] over time step}}
\DoxyCodeLine{257     netMassIn,    \&  \textcolor{comment}{! mass entering ocean surface [H ~> m or kg m-2] over a time step}}
\DoxyCodeLine{258     netMassOut       \textcolor{comment}{! mass leaving ocean surface [H ~> m or kg m-2] over a time step}}
\DoxyCodeLine{259 }
\DoxyCodeLine{260 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(SZI\_(G), SZK\_(G))} :: h2d, Tr2d}
\DoxyCodeLine{261 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(SZI\_(G),SZJ\_(G))}  :: in\_flux  \textcolor{comment}{! The total time-integrated amount of tracer!}}
\DoxyCodeLine{262                                                    \textcolor{comment}{! that enters with freshwater}}
\DoxyCodeLine{263 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(SZI\_(G),SZJ\_(G))}  :: out\_flux \textcolor{comment}{! The total time-integrated amount of tracer!}}
\DoxyCodeLine{264                                                     \textcolor{comment}{! that leaves with freshwater}}
\DoxyCodeLine{265 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(SZI\_(G))}          :: in\_flux\_1d, out\_flux\_1d}
\DoxyCodeLine{266 \textcolor{keywordtype}{  real}                              :: hGrounding(maxGroundings)}
\DoxyCodeLine{267 \textcolor{keywordtype}{  real}    :: Tr\_in}
\DoxyCodeLine{268   \textcolor{keywordtype}{logical} :: update\_h}
\DoxyCodeLine{269   \textcolor{keywordtype}{integer} :: i, j, is, ie, js, je, k, nz, n, nsw}
\DoxyCodeLine{270   \textcolor{keywordtype}{character(len=45)} :: mesg}
\DoxyCodeLine{271 }
\DoxyCodeLine{272   is = g\%isc ; ie = g\%iec ; js = g\%jsc ; je = g\%jec ; nz = g\%ke}
\DoxyCodeLine{273 }
\DoxyCodeLine{274   \textcolor{comment}{! If no freshwater fluxes, nothing needs to be done in this routine}}
\DoxyCodeLine{275   \textcolor{keywordflow}{if} ( (.not. \textcolor{keyword}{associated}(fluxes\%netMassIn)) .or. (.not. \textcolor{keyword}{associated}(fluxes\%netMassOut)) ) \textcolor{keywordflow}{return}}
\DoxyCodeLine{276 }
\DoxyCodeLine{277   in\_flux(:,:) = 0.0 ; out\_flux(:,:) = 0.0}
\DoxyCodeLine{278   \textcolor{keywordflow}{if} (\textcolor{keyword}{present}(in\_flux\_optional)) \textcolor{keywordflow}{then}}
\DoxyCodeLine{279     \textcolor{keywordflow}{do} j=js,je ; \textcolor{keywordflow}{do} i=is,ie}
\DoxyCodeLine{280       in\_flux(i,j) = in\_flux\_optional(i,j)}
\DoxyCodeLine{281 \textcolor{keywordflow}{    enddo} ;\textcolor{keywordflow}{ enddo}}
\DoxyCodeLine{282 \textcolor{keywordflow}{  endif}}
\DoxyCodeLine{283   \textcolor{keywordflow}{if} (\textcolor{keyword}{present}(out\_flux\_optional)) \textcolor{keywordflow}{then}}
\DoxyCodeLine{284     \textcolor{keywordflow}{do} j=js,je ; \textcolor{keywordflow}{do} i=is,ie}
\DoxyCodeLine{285       out\_flux(i,j) = out\_flux\_optional(i,j)}
\DoxyCodeLine{286 \textcolor{keywordflow}{    enddo} ;\textcolor{keywordflow}{ enddo}}
\DoxyCodeLine{287 \textcolor{keywordflow}{  endif}}
\DoxyCodeLine{288 }
\DoxyCodeLine{289   \textcolor{keywordflow}{if} (\textcolor{keyword}{present}(update\_h\_opt)) \textcolor{keywordflow}{then}}
\DoxyCodeLine{290     update\_h = update\_h\_opt}
\DoxyCodeLine{291   \textcolor{keywordflow}{else}}
\DoxyCodeLine{292     update\_h = .true.}
\DoxyCodeLine{293 \textcolor{keywordflow}{  endif}}
\DoxyCodeLine{294 }
\DoxyCodeLine{295   numberofgroundings = 0}
\DoxyCodeLine{296 }
\DoxyCodeLine{297 \textcolor{comment}{!\$OMP parallel do default(none) shared(is,ie,js,je,nz,h,Tr,G,GV,fluxes,dt,    \&}}
\DoxyCodeLine{298 \textcolor{comment}{!\$OMP                                  IforcingDepthScale,minimum\_forcing\_depth, \&}}
\DoxyCodeLine{299 \textcolor{comment}{!\$OMP                                  numberOfGroundings,iGround,jGround,update\_h, \&}}
\DoxyCodeLine{300 \textcolor{comment}{!\$OMP                                  in\_flux,out\_flux,hGrounding,evap\_CFL\_limit) \&}}
\DoxyCodeLine{301 \textcolor{comment}{!\$OMP                          private(h2d,Tr2d,netMassInOut,netMassOut,      \&}}
\DoxyCodeLine{302 \textcolor{comment}{!\$OMP                                  in\_flux\_1d,out\_flux\_1d,fractionOfForcing,     \&}}
\DoxyCodeLine{303 \textcolor{comment}{!\$OMP                                  dThickness,dTracer,hOld,Ithickness,           \&}}
\DoxyCodeLine{304 \textcolor{comment}{!\$OMP                                  netMassIn, Tr\_in)}}
\DoxyCodeLine{305 }
\DoxyCodeLine{306   \textcolor{comment}{! Work in vertical slices for efficiency}}
\DoxyCodeLine{307   \textcolor{keywordflow}{do} j=js,je}
\DoxyCodeLine{308 }
\DoxyCodeLine{309     \textcolor{comment}{! Copy state into 2D-slice arrays}}
\DoxyCodeLine{310     \textcolor{keywordflow}{do} k=1,nz ; \textcolor{keywordflow}{do} i=is,ie}
\DoxyCodeLine{311       h2d(i,k) = h(i,j,k)}
\DoxyCodeLine{312       tr2d(i,k) = tr(i,j,k)}
\DoxyCodeLine{313 \textcolor{keywordflow}{    enddo} ;\textcolor{keywordflow}{ enddo}}
\DoxyCodeLine{314 }
\DoxyCodeLine{315     \textcolor{keywordflow}{do} i = is,ie}
\DoxyCodeLine{316       in\_flux\_1d(i) = in\_flux(i,j)}
\DoxyCodeLine{317       out\_flux\_1d(i) = out\_flux(i,j)}
\DoxyCodeLine{318 \textcolor{keywordflow}{    enddo}}
\DoxyCodeLine{319     \textcolor{comment}{! The surface forcing is contained in the fluxes type.}}
\DoxyCodeLine{320     \textcolor{comment}{! We aggregate the thermodynamic forcing for a time step into the following:}}
\DoxyCodeLine{321     \textcolor{comment}{! These should have been set and stored during a call to applyBoundaryFluxesInOut}}
\DoxyCodeLine{322     \textcolor{comment}{! netMassIn    = net mass entering at ocean surface over a timestep}}
\DoxyCodeLine{323     \textcolor{comment}{! netMassOut   = net mass leaving ocean surface [H ~> m or kg m-2] over a time step.}}
\DoxyCodeLine{324     \textcolor{comment}{!                netMassOut < 0 means mass leaves ocean.}}
\DoxyCodeLine{325 }
\DoxyCodeLine{326     \textcolor{comment}{! Note here that the aggregateFW flag has already been taken care of in the call to}}
\DoxyCodeLine{327     \textcolor{comment}{! applyBoundaryFluxesInOut}}
\DoxyCodeLine{328     \textcolor{keywordflow}{do} i=is,ie}
\DoxyCodeLine{329         netmassout(i) = fluxes\%netMassOut(i,j)}
\DoxyCodeLine{330         netmassin(i)  = fluxes\%netMassIn(i,j)}
\DoxyCodeLine{331 \textcolor{keywordflow}{    enddo}}
\DoxyCodeLine{332 }
\DoxyCodeLine{333     \textcolor{comment}{! Apply the surface boundary fluxes in three steps:}}
\DoxyCodeLine{334     \textcolor{comment}{! A/ update concentration from mass entering the ocean}}
\DoxyCodeLine{335     \textcolor{comment}{! B/ update concentration from mass leaving ocean.}}
\DoxyCodeLine{336     \textcolor{keywordflow}{do} i=is,ie}
\DoxyCodeLine{337       \textcolor{keywordflow}{if} (g\%mask2dT(i,j)>0.) \textcolor{keywordflow}{then}}
\DoxyCodeLine{338 }
\DoxyCodeLine{339         \textcolor{comment}{! A/ Update tracer due to incoming mass flux.}}
\DoxyCodeLine{340         \textcolor{keywordflow}{do} k=1,1}
\DoxyCodeLine{341 }
\DoxyCodeLine{342           \textcolor{comment}{! Change in state due to forcing}}
\DoxyCodeLine{343           dthickness = netmassin(i) \textcolor{comment}{! Since we are adding mass, we can use all of it}}
\DoxyCodeLine{344           dtracer = 0.}
\DoxyCodeLine{345 }
\DoxyCodeLine{346           \textcolor{comment}{! Update the forcing by the part to be consumed within the present k-layer.}}
\DoxyCodeLine{347           \textcolor{comment}{! If fractionOfForcing = 1, then updated netMassIn, netHeat, and netSalt vanish.}}
\DoxyCodeLine{348           netmassin(i) = netmassin(i) - dthickness}
\DoxyCodeLine{349           dtracer = dtracer + in\_flux\_1d(i)}
\DoxyCodeLine{350           in\_flux\_1d(i) = 0.0}
\DoxyCodeLine{351 }
\DoxyCodeLine{352           \textcolor{comment}{! Update state}}
\DoxyCodeLine{353           hold     = h2d(i,k)               \textcolor{comment}{! Keep original thickness in hand}}
\DoxyCodeLine{354           h2d(i,k) = h2d(i,k) + dthickness  \textcolor{comment}{! New thickness}}
\DoxyCodeLine{355           \textcolor{keywordflow}{if} (h2d(i,k) > 0.0) \textcolor{keywordflow}{then}}
\DoxyCodeLine{356             ithickness  = 1.0/h2d(i,k)      \textcolor{comment}{! Inverse new thickness}}
\DoxyCodeLine{357             \textcolor{comment}{! The "if"s below avoid changing T/S by roundoff unnecessarily}}
\DoxyCodeLine{358             \textcolor{keywordflow}{if} (dthickness /= 0. .or. dtracer /= 0.) tr2d(i,k) = (hold*tr2d(i,k)+ dtracer)*ithickness}
\DoxyCodeLine{359 \textcolor{keywordflow}{          endif}}
\DoxyCodeLine{360 }
\DoxyCodeLine{361 \textcolor{keywordflow}{        enddo} \textcolor{comment}{! k=1,1}}
\DoxyCodeLine{362 }
\DoxyCodeLine{363         \textcolor{comment}{! B/ Update tracer from mass leaving ocean}}
\DoxyCodeLine{364         \textcolor{keywordflow}{do} k=1,nz}
\DoxyCodeLine{365 }
\DoxyCodeLine{366           \textcolor{comment}{! Place forcing into this layer if this layer has nontrivial thickness.}}
\DoxyCodeLine{367           \textcolor{comment}{! For layers thin relative to 1/IforcingDepthScale, then distribute}}
\DoxyCodeLine{368           \textcolor{comment}{! forcing into deeper layers.}}
\DoxyCodeLine{369           iforcingdepthscale = 1. / max(gv\%H\_subroundoff, minimum\_forcing\_depth - netmassout(i) )}
\DoxyCodeLine{370           \textcolor{comment}{! fractionOfForcing = 1.0, unless h2d is less than IforcingDepthScale.}}
\DoxyCodeLine{371           fractionofforcing = min(1.0, h2d(i,k)*iforcingdepthscale)}
\DoxyCodeLine{372 }
\DoxyCodeLine{373           \textcolor{comment}{! In the case with (-1)*netMassOut*fractionOfForcing greater than cfl*h, we}}
\DoxyCodeLine{374           \textcolor{comment}{! limit the forcing applied to this cell, leaving the remaining forcing to}}
\DoxyCodeLine{375           \textcolor{comment}{! be distributed downwards.}}
\DoxyCodeLine{376           \textcolor{keywordflow}{if} (-fractionofforcing*netmassout(i) > evap\_cfl\_limit*h2d(i,k)) \textcolor{keywordflow}{then}}
\DoxyCodeLine{377             fractionofforcing = -evap\_cfl\_limit*h2d(i,k)/netmassout(i)}
\DoxyCodeLine{378 \textcolor{keywordflow}{          endif}}
\DoxyCodeLine{379 }
\DoxyCodeLine{380           \textcolor{comment}{! Change in state due to forcing}}
\DoxyCodeLine{381           dthickness = max( fractionofforcing*netmassout(i), -h2d(i,k) )}
\DoxyCodeLine{382           \textcolor{comment}{! Note this is slightly different to how salt is currently treated}}
\DoxyCodeLine{383           dtracer =  fractionofforcing*out\_flux\_1d(i)}
\DoxyCodeLine{384 }
\DoxyCodeLine{385           \textcolor{comment}{! Update the forcing by the part to be consumed within the present k-layer.}}
\DoxyCodeLine{386           \textcolor{comment}{! If fractionOfForcing = 1, then new netMassOut vanishes.}}
\DoxyCodeLine{387           netmassout(i) = netmassout(i) - dthickness}
\DoxyCodeLine{388           out\_flux\_1d(i) = out\_flux\_1d(i) - dtracer}
\DoxyCodeLine{389 }
\DoxyCodeLine{390           \textcolor{comment}{! Update state by the appropriate increment.}}
\DoxyCodeLine{391           hold     = h2d(i,k)               \textcolor{comment}{! Keep original thickness in hand}}
\DoxyCodeLine{392           h2d(i,k) = h2d(i,k) + dthickness  \textcolor{comment}{! New thickness}}
\DoxyCodeLine{393           \textcolor{keywordflow}{if} (h2d(i,k) > 0.) \textcolor{keywordflow}{then}}
\DoxyCodeLine{394             ithickness  = 1.0/h2d(i,k) \textcolor{comment}{! Inverse of new thickness}}
\DoxyCodeLine{395             tr2d(i,k)    = (hold*tr2d(i,k) + dtracer)*ithickness}
\DoxyCodeLine{396 \textcolor{keywordflow}{          endif}}
\DoxyCodeLine{397 }
\DoxyCodeLine{398 \textcolor{keywordflow}{        enddo} \textcolor{comment}{! k}}
\DoxyCodeLine{399 }
\DoxyCodeLine{400 \textcolor{keywordflow}{      endif}}
\DoxyCodeLine{401 }
\DoxyCodeLine{402       \textcolor{comment}{! If anything remains after the k-loop, then we have grounded out, which is a problem.}}
\DoxyCodeLine{403       \textcolor{keywordflow}{if} (abs(in\_flux\_1d(i))+abs(out\_flux\_1d(i)) /= 0.0) \textcolor{keywordflow}{then}}
\DoxyCodeLine{404 \textcolor{comment}{!\$OMP critical}}
\DoxyCodeLine{405         numberofgroundings = numberofgroundings +1}
\DoxyCodeLine{406         \textcolor{keywordflow}{if} (numberofgroundings<=maxgroundings) \textcolor{keywordflow}{then}}
\DoxyCodeLine{407           iground(numberofgroundings) = i \textcolor{comment}{! Record i,j location of event for}}
\DoxyCodeLine{408           jground(numberofgroundings) = j \textcolor{comment}{! warning message}}
\DoxyCodeLine{409           hgrounding(numberofgroundings) = abs(in\_flux\_1d(i))+abs(out\_flux\_1d(i))}
\DoxyCodeLine{410 \textcolor{keywordflow}{        endif}}
\DoxyCodeLine{411 \textcolor{comment}{!\$OMP end critical}}
\DoxyCodeLine{412 \textcolor{keywordflow}{      endif}}
\DoxyCodeLine{413 }
\DoxyCodeLine{414 \textcolor{keywordflow}{    enddo} \textcolor{comment}{! i}}
\DoxyCodeLine{415 }
\DoxyCodeLine{416     \textcolor{comment}{! Step C/ copy updated tracer concentration from the 2d slice now back into model state.}}
\DoxyCodeLine{417     \textcolor{keywordflow}{do} k=1,nz ; \textcolor{keywordflow}{do} i=is,ie}
\DoxyCodeLine{418       tr(i,j,k) = tr2d(i,k)}
\DoxyCodeLine{419 \textcolor{keywordflow}{    enddo} ;\textcolor{keywordflow}{ enddo}}
\DoxyCodeLine{420 }
\DoxyCodeLine{421     \textcolor{keywordflow}{if} (update\_h) \textcolor{keywordflow}{then}}
\DoxyCodeLine{422       \textcolor{keywordflow}{do} k=1,nz ; \textcolor{keywordflow}{do} i=is,ie}
\DoxyCodeLine{423         h(i,j,k) = h2d(i,k)}
\DoxyCodeLine{424 \textcolor{keywordflow}{      enddo} ;\textcolor{keywordflow}{ enddo}}
\DoxyCodeLine{425 \textcolor{keywordflow}{    endif}}
\DoxyCodeLine{426 }
\DoxyCodeLine{427 \textcolor{keywordflow}{  enddo} \textcolor{comment}{! j-loop finish}}
\DoxyCodeLine{428 }
\DoxyCodeLine{429   \textcolor{keywordflow}{if} (numberofgroundings>0) \textcolor{keywordflow}{then}}
\DoxyCodeLine{430     \textcolor{keywordflow}{do} i = 1, min(numberofgroundings, maxgroundings)}
\DoxyCodeLine{431       \textcolor{keyword}{write}(mesg(1:45),\textcolor{stringliteral}{'(3es15.3)'}) g\%geoLonT( iground(i), jground(i) ), \&}
\DoxyCodeLine{432                              g\%geoLatT( iground(i), jground(i)) , hgrounding(i)}
\DoxyCodeLine{433       \textcolor{keyword}{call }mom\_error(warning, \textcolor{stringliteral}{"MOM\_tracer\_diabatic.F90, applyTracerBoundaryFluxesInOut(): "}//\&}
\DoxyCodeLine{434                               \textcolor{stringliteral}{"Tracer created. x,y,dh= "}//trim(mesg), all\_print=.true.)}
\DoxyCodeLine{435 \textcolor{keywordflow}{    enddo}}
\DoxyCodeLine{436 }
\DoxyCodeLine{437     \textcolor{keywordflow}{if} (numberofgroundings - maxgroundings > 0) \textcolor{keywordflow}{then}}
\DoxyCodeLine{438       \textcolor{keyword}{write}(mesg, \textcolor{stringliteral}{'(i4)'}) numberofgroundings - maxgroundings}
\DoxyCodeLine{439       \textcolor{keyword}{call }mom\_error(warning, \textcolor{stringliteral}{"MOM\_tracer\_vertical.F90, applyTracerBoundaryFluxesInOut(): "}//\&}
\DoxyCodeLine{440                               trim(mesg) // \textcolor{stringliteral}{" groundings remaining"})}
\DoxyCodeLine{441 \textcolor{keywordflow}{    endif}}
\DoxyCodeLine{442 \textcolor{keywordflow}{  endif}}
\DoxyCodeLine{443 }

\end{DoxyCode}
\mbox{\Hypertarget{namespacemom__tracer__diabatic_ac5d57973547cc4ed3a89808d3910943e}\label{namespacemom__tracer__diabatic_ac5d57973547cc4ed3a89808d3910943e}} 
\index{mom\_tracer\_diabatic@{mom\_tracer\_diabatic}!tracer\_vertdiff@{tracer\_vertdiff}}
\index{tracer\_vertdiff@{tracer\_vertdiff}!mom\_tracer\_diabatic@{mom\_tracer\_diabatic}}
\subsubsection{\texorpdfstring{tracer\_vertdiff()}{tracer\_vertdiff()}}
{\footnotesize\ttfamily subroutine, public mom\+\_\+tracer\+\_\+diabatic\+::tracer\+\_\+vertdiff (\begin{DoxyParamCaption}\item[{real, dimension( g \%isd\+: g \%ied, g \%jsd\+: g \%jed, gv \%ke), intent(in)}]{h\+\_\+old,  }\item[{real, dimension( g \%isd\+: g \%ied, g \%jsd\+: g \%jed, gv \%ke), intent(in)}]{ea,  }\item[{real, dimension( g \%isd\+: g \%ied, g \%jsd\+: g \%jed, gv \%ke), intent(in)}]{eb,  }\item[{real, intent(in)}]{dt,  }\item[{real, dimension( g \%isd\+: g \%ied, g \%jsd\+: g \%jed, gv \%ke), intent(inout)}]{tr,  }\item[{type(ocean\+\_\+grid\+\_\+type), intent(in)}]{G,  }\item[{type(verticalgrid\+\_\+type), intent(in)}]{GV,  }\item[{real, dimension( g \%isd\+: g \%ied, g \%jsd\+: g \%jed), intent(in), optional}]{sfc\+\_\+flux,  }\item[{real, dimension( g \%isd\+: g \%ied, g \%jsd\+: g \%jed), intent(in), optional}]{btm\+\_\+flux,  }\item[{real, dimension( g \%isd\+: g \%ied, g \%jsd\+: g \%jed), intent(inout), optional}]{btm\+\_\+reservoir,  }\item[{real, intent(in), optional}]{sink\+\_\+rate,  }\item[{logical, intent(in), optional}]{convert\+\_\+flux\+\_\+in }\end{DoxyParamCaption})}



This subroutine solves a tridiagonal equation for the final tracer concentrations after the dual-\/entrainments, and possibly sinking or surface and bottom sources, are applied. The sinking is implemented with an fully implicit upwind advection scheme. Alternate time units can be used for the timestep, surface and bottom fluxes and sink\+\_\+rate provided they are all consistent. 


\begin{DoxyParams}[1]{Parameters}
\mbox{\texttt{ in}}  & {\em g} & ocean grid structure \\
\hline
\mbox{\texttt{ in}}  & {\em gv} & ocean vertical grid structure \\
\hline
\mbox{\texttt{ in}}  & {\em h\+\_\+old} & layer thickness before entrainment \mbox{[}H $\sim$$>$ m or kg m-\/2\mbox{]} \\
\hline
\mbox{\texttt{ in}}  & {\em ea} & amount of fluid entrained from the layer above \mbox{[}H $\sim$$>$ m or kg m-\/2\mbox{]} \\
\hline
\mbox{\texttt{ in}}  & {\em eb} & amount of fluid entrained from the layer below \mbox{[}H $\sim$$>$ m or kg m-\/2\mbox{]} \\
\hline
\mbox{\texttt{ in,out}}  & {\em tr} & tracer concentration in concentration units \mbox{[}CU\mbox{]} \\
\hline
\mbox{\texttt{ in}}  & {\em dt} & amount of time covered by this call \mbox{[}T $\sim$$>$ s\mbox{]} \\
\hline
\mbox{\texttt{ in}}  & {\em sfc\+\_\+flux} & surface flux of the tracer in units of \mbox{[}CU kg m-\/2 T-\/1 $\sim$$>$ CU kg m-\/2 s-\/1\mbox{]} or \mbox{[}CU H $\sim$$>$ CU m or CU kg m-\/2\mbox{]} if convert\+\_\+flux\+\_\+in is .false. \\
\hline
\mbox{\texttt{ in}}  & {\em btm\+\_\+flux} & The (negative upward) bottom flux of the tracer in \mbox{[}CU kg m-\/2 T-\/1 $\sim$$>$ CU kg m-\/2 s-\/1\mbox{]} or \mbox{[}CU H $\sim$$>$ CU m or CU kg m-\/2\mbox{]} if \\
\hline
\mbox{\texttt{ in,out}}  & {\em btm\+\_\+reservoir} & amount of tracer in a bottom reservoir \mbox{[}CU kg m-\/2\mbox{]}; formerly \mbox{[}CU m\mbox{]} \\
\hline
\mbox{\texttt{ in}}  & {\em sink\+\_\+rate} & rate at which the tracer sinks \mbox{[}m T-\/1 $\sim$$>$ m s-\/1\mbox{]} \\
\hline
\mbox{\texttt{ in}}  & {\em convert\+\_\+flux\+\_\+in} & True if the specified sfc\+\_\+flux needs to be integrated in time \\
\hline
\end{DoxyParams}


Definition at line 27 of file M\+O\+M\+\_\+tracer\+\_\+diabatic.\+F90.


\begin{DoxyCode}{0}
\DoxyCodeLine{27   \textcolor{keywordtype}{type}(ocean\_grid\_type),                     \textcolor{keywordtype}{intent(in)}    :: G\textcolor{comment}{      !< ocean grid structure}}
\DoxyCodeLine{28   \textcolor{keywordtype}{type}(verticalGrid\_type),                   \textcolor{keywordtype}{intent(in)}    :: GV\textcolor{comment}{     !< ocean vertical grid structure}}
\DoxyCodeLine{29 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(SZI\_(G),SZJ\_(G),SZK\_(GV))}, \textcolor{keywordtype}{intent(in)}    :: h\_old\textcolor{comment}{  !< layer thickness before entrainment}}
\DoxyCodeLine{30 \textcolor{comment}{                                                                     !! [H ~> m or kg m-2]}}
\DoxyCodeLine{31 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(SZI\_(G),SZJ\_(G),SZK\_(GV))}, \textcolor{keywordtype}{intent(in)}    :: ea\textcolor{comment}{     !< amount of fluid entrained from the layer}}
\DoxyCodeLine{32 \textcolor{comment}{                                                                     !! above [H ~> m or kg m-2]}}
\DoxyCodeLine{33 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(SZI\_(G),SZJ\_(G),SZK\_(GV))}, \textcolor{keywordtype}{intent(in)}    :: eb\textcolor{comment}{     !< amount of fluid entrained from the layer}}
\DoxyCodeLine{34 \textcolor{comment}{                                                                     !! below [H ~> m or kg m-2]}}
\DoxyCodeLine{35 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(SZI\_(G),SZJ\_(G),SZK\_(GV))}, \textcolor{keywordtype}{intent(inout)} :: tr\textcolor{comment}{     !< tracer concentration in concentration units [CU]}}
\DoxyCodeLine{36 \textcolor{keywordtype}{  real},                                      \textcolor{keywordtype}{intent(in)}    :: dt\textcolor{comment}{     !< amount of time covered by this call [T ~> s]}}
\DoxyCodeLine{37 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(SZI\_(G),SZJ\_(G))}, \textcolor{keywordtype}{optional},\textcolor{keywordtype}{intent(in)}    :: sfc\_flux\textcolor{comment}{ !< surface flux of the tracer in units of}}
\DoxyCodeLine{38 \textcolor{comment}{                                                                     !! [CU kg m-2 T-1 ~> CU kg m-2 s-1] or}}
\DoxyCodeLine{39 \textcolor{comment}{                                                                     !! [CU H ~> CU m or CU kg m-2] if}}
\DoxyCodeLine{40 \textcolor{comment}{                                                                     !! convert\_flux\_in is .false.}}
\DoxyCodeLine{41 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(SZI\_(G),SZJ\_(G))}, \textcolor{keywordtype}{optional},\textcolor{keywordtype}{intent(in)}    :: btm\_flux\textcolor{comment}{ !< The (negative upward) bottom flux of the}}
\DoxyCodeLine{42 \textcolor{comment}{                                                                     !! tracer in [CU kg m-2 T-1 ~> CU kg m-2 s-1] or}}
\DoxyCodeLine{43 \textcolor{comment}{                                                                     !! [CU H ~> CU m or CU kg m-2] if}}
\DoxyCodeLine{44 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(SZI\_(G),SZJ\_(G))}, \textcolor{keywordtype}{optional},\textcolor{keywordtype}{intent(inout)} :: btm\_reservoir\textcolor{comment}{ !< amount of tracer in a bottom reservoir}}
\DoxyCodeLine{45 \textcolor{comment}{                                                                     !! [CU kg m-2]; formerly [CU m]}}
\DoxyCodeLine{46 \textcolor{keywordtype}{  real},                             \textcolor{keywordtype}{optional},\textcolor{keywordtype}{intent(in)}    :: sink\_rate\textcolor{comment}{ !< rate at which the tracer sinks}}
\DoxyCodeLine{47 \textcolor{comment}{                                                                     !! [m T-1 ~> m s-1]}}
\DoxyCodeLine{48   \textcolor{keywordtype}{logical},                          \textcolor{keywordtype}{optional},\textcolor{keywordtype}{intent(in)}    :: convert\_flux\_in\textcolor{comment}{ !< True if the specified sfc\_flux needs}}
\DoxyCodeLine{49 \textcolor{comment}{                                                                     !! to be integrated in time}}
\DoxyCodeLine{50 }
\DoxyCodeLine{51   \textcolor{comment}{! local variables}}
\DoxyCodeLine{52 \textcolor{keywordtype}{  real} :: sink\_dist\textcolor{comment}{ !< The distance the tracer sinks in a time step [H ~> m or kg m-2].}}
\DoxyCodeLine{53 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(SZI\_(G),SZJ\_(G))} :: \&}
\DoxyCodeLine{54     sfc\_src, \&      !< The time-integrated surface source of the tracer [CU H ~> CU m or CU kg m-2].}
\DoxyCodeLine{55     btm\_src\textcolor{comment}{         !< The time-integrated bottom source of the tracer [CU H ~> CU m or CU kg m-2].}}
\DoxyCodeLine{56 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(SZI\_(G))} :: \&}
\DoxyCodeLine{57     b1, \&           !< b1 is used by the tridiagonal solver [H-1 ~> m-1 or m2 kg-1].}
\DoxyCodeLine{58     d1              \textcolor{comment}{!! d1=1-c1 is used by the tridiagonal solver, nondimensional.}}
\DoxyCodeLine{59 \textcolor{keywordtype}{  real} :: c1(SZI\_(G),SZK\_(GV))\textcolor{comment}{    !< c1 is used by the tridiagonal solver [nondim].}}
\DoxyCodeLine{60 \textcolor{keywordtype}{  real} :: h\_minus\_dsink(SZI\_(G),SZK\_(GV))\textcolor{comment}{ !< The layer thickness minus the}}
\DoxyCodeLine{61 \textcolor{comment}{                    !! difference in sinking rates across the layer [H ~> m or kg m-2].}}
\DoxyCodeLine{62 \textcolor{comment}{                    !! By construction, 0 <= h\_minus\_dsink < h\_work.}}
\DoxyCodeLine{63 \textcolor{keywordtype}{  real} :: sink(SZI\_(G),SZK\_(GV)+1)\textcolor{comment}{ !< The tracer's sinking distances at the}}
\DoxyCodeLine{64 \textcolor{comment}{                    !! interfaces, limited to prevent characteristics from}}
\DoxyCodeLine{65 \textcolor{comment}{                    !! crossing within a single timestep [H ~> m or kg m-2].}}
\DoxyCodeLine{66 \textcolor{keywordtype}{  real} :: b\_denom\_1\textcolor{comment}{ !< The first term in the denominator of b1 [H ~> m or kg m-2].}}
\DoxyCodeLine{67 \textcolor{keywordtype}{  real} :: h\_tr\textcolor{comment}{      !< h\_tr is h at tracer points with a h\_neglect added to}}
\DoxyCodeLine{68 \textcolor{comment}{                    !! ensure positive definiteness [H ~> m or kg m-2].}}
\DoxyCodeLine{69 \textcolor{keywordtype}{  real} :: h\_neglect\textcolor{comment}{ !< A thickness that is so small it is usually lost}}
\DoxyCodeLine{70 \textcolor{comment}{                    !! in roundoff and can be neglected [H ~> m or kg m-2].}}
\DoxyCodeLine{71   \textcolor{keywordtype}{logical} :: convert\_flux = .true.}
\DoxyCodeLine{72 }
\DoxyCodeLine{73 }
\DoxyCodeLine{74   \textcolor{keywordtype}{integer} :: i, j, k, is, ie, js, je, nz}
\DoxyCodeLine{75   is = g\%isc ; ie = g\%iec ; js = g\%jsc ; je = g\%jec ; nz = gv\%ke}
\DoxyCodeLine{76 }
\DoxyCodeLine{77   \textcolor{keywordflow}{if} (nz == 1) \textcolor{keywordflow}{then}}
\DoxyCodeLine{78     \textcolor{keyword}{call }mom\_error(warning, \textcolor{stringliteral}{"MOM\_tracer\_diabatic.F90, tracer\_vertdiff called "}//\&}
\DoxyCodeLine{79                             \textcolor{stringliteral}{"with only one vertical level"})}
\DoxyCodeLine{80     \textcolor{keywordflow}{return}}
\DoxyCodeLine{81 \textcolor{keywordflow}{  endif}}
\DoxyCodeLine{82 }
\DoxyCodeLine{83   \textcolor{keywordflow}{if} (\textcolor{keyword}{present}(convert\_flux\_in)) convert\_flux = convert\_flux\_in}
\DoxyCodeLine{84   h\_neglect = gv\%H\_subroundoff}
\DoxyCodeLine{85   sink\_dist = 0.0}
\DoxyCodeLine{86   \textcolor{keywordflow}{if} (\textcolor{keyword}{present}(sink\_rate)) sink\_dist = (dt*sink\_rate) * gv\%m\_to\_H}
\DoxyCodeLine{87 \textcolor{comment}{!\$OMP parallel default(none) shared(is,ie,js,je,sfc\_src,btm\_src,sfc\_flux,dt,G,GV,btm\_flux, \&}}
\DoxyCodeLine{88 \textcolor{comment}{!\$OMP                               sink\_rate,btm\_reservoir,nz,sink\_dist,ea,      \&}}
\DoxyCodeLine{89 \textcolor{comment}{!\$OMP                               h\_old,convert\_flux,h\_neglect,eb,tr) \&}}
\DoxyCodeLine{90 \textcolor{comment}{!\$OMP                       private(sink,h\_minus\_dsink,b\_denom\_1,b1,d1,h\_tr,c1)}}
\DoxyCodeLine{91 \textcolor{comment}{!\$OMP do}}
\DoxyCodeLine{92   \textcolor{keywordflow}{do} j=js,je; \textcolor{keywordflow}{do} i=is,ie ; sfc\_src(i,j) = 0.0 ; btm\_src(i,j) = 0.0 ;\textcolor{keywordflow}{ enddo} ;\textcolor{keywordflow}{ enddo}}
\DoxyCodeLine{93   \textcolor{keywordflow}{if} (\textcolor{keyword}{present}(sfc\_flux)) \textcolor{keywordflow}{then}}
\DoxyCodeLine{94     \textcolor{keywordflow}{if} (convert\_flux) \textcolor{keywordflow}{then}}
\DoxyCodeLine{95 \textcolor{comment}{!\$OMP do}}
\DoxyCodeLine{96       \textcolor{keywordflow}{do} j = js, je; \textcolor{keywordflow}{do} i = is,ie}
\DoxyCodeLine{97         sfc\_src(i,j) = (sfc\_flux(i,j)*dt) * gv\%kg\_m2\_to\_H}
\DoxyCodeLine{98 \textcolor{keywordflow}{      enddo} ;\textcolor{keywordflow}{ enddo}}
\DoxyCodeLine{99     \textcolor{keywordflow}{else}}
\DoxyCodeLine{100 \textcolor{comment}{!\$OMP do}}
\DoxyCodeLine{101       \textcolor{keywordflow}{do} j = js, je; \textcolor{keywordflow}{do} i = is,ie}
\DoxyCodeLine{102         sfc\_src(i,j) = sfc\_flux(i,j)}
\DoxyCodeLine{103 \textcolor{keywordflow}{      enddo} ;\textcolor{keywordflow}{ enddo}}
\DoxyCodeLine{104 \textcolor{keywordflow}{    endif}}
\DoxyCodeLine{105 \textcolor{keywordflow}{  endif}}
\DoxyCodeLine{106   \textcolor{keywordflow}{if} (\textcolor{keyword}{present}(btm\_flux)) \textcolor{keywordflow}{then}}
\DoxyCodeLine{107     \textcolor{keywordflow}{if} (convert\_flux) \textcolor{keywordflow}{then}}
\DoxyCodeLine{108 \textcolor{comment}{!\$OMP do}}
\DoxyCodeLine{109       \textcolor{keywordflow}{do} j = js, je; \textcolor{keywordflow}{do} i = is,ie}
\DoxyCodeLine{110         btm\_src(i,j) = (btm\_flux(i,j)*dt) * gv\%kg\_m2\_to\_H}
\DoxyCodeLine{111 \textcolor{keywordflow}{      enddo} ;\textcolor{keywordflow}{ enddo}}
\DoxyCodeLine{112     \textcolor{keywordflow}{else}}
\DoxyCodeLine{113 \textcolor{comment}{!\$OMP do}}
\DoxyCodeLine{114       \textcolor{keywordflow}{do} j = js, je; \textcolor{keywordflow}{do} i = is,ie}
\DoxyCodeLine{115         btm\_src(i,j) = btm\_flux(i,j)}
\DoxyCodeLine{116 \textcolor{keywordflow}{      enddo} ;\textcolor{keywordflow}{ enddo}}
\DoxyCodeLine{117 \textcolor{keywordflow}{    endif}}
\DoxyCodeLine{118 \textcolor{keywordflow}{  endif}}
\DoxyCodeLine{119 }
\DoxyCodeLine{120   \textcolor{keywordflow}{if} (\textcolor{keyword}{present}(sink\_rate)) \textcolor{keywordflow}{then}}
\DoxyCodeLine{121 \textcolor{comment}{!\$OMP do}}
\DoxyCodeLine{122     \textcolor{keywordflow}{do} j=js,je}
\DoxyCodeLine{123       \textcolor{comment}{! Find the sinking rates at all interfaces, limiting them if necesary}}
\DoxyCodeLine{124       \textcolor{comment}{! so that the characteristics do not cross within a timestep.}}
\DoxyCodeLine{125       \textcolor{comment}{!   If a non-constant sinking rate were used, that would be incorprated}}
\DoxyCodeLine{126       \textcolor{comment}{! here.}}
\DoxyCodeLine{127       \textcolor{keywordflow}{if} (\textcolor{keyword}{present}(btm\_reservoir)) \textcolor{keywordflow}{then}}
\DoxyCodeLine{128         \textcolor{keywordflow}{do} i=is,ie ; sink(i,nz+1) = sink\_dist ;\textcolor{keywordflow}{ enddo}}
\DoxyCodeLine{129         \textcolor{keywordflow}{do} k=2,nz ; \textcolor{keywordflow}{do} i=is,ie}
\DoxyCodeLine{130           sink(i,k) = sink\_dist ; h\_minus\_dsink(i,k) = h\_old(i,j,k)}
\DoxyCodeLine{131 \textcolor{keywordflow}{        enddo} ;\textcolor{keywordflow}{ enddo}}
\DoxyCodeLine{132       \textcolor{keywordflow}{else}}
\DoxyCodeLine{133         \textcolor{keywordflow}{do} i=is,ie ; sink(i,nz+1) = 0.0 ;\textcolor{keywordflow}{ enddo}}
\DoxyCodeLine{134         \textcolor{comment}{! Find the limited sinking distance at the interfaces.}}
\DoxyCodeLine{135         \textcolor{keywordflow}{do} k=nz,2,-1 ; \textcolor{keywordflow}{do} i=is,ie}
\DoxyCodeLine{136           \textcolor{keywordflow}{if} (sink(i,k+1) >= sink\_dist) \textcolor{keywordflow}{then}}
\DoxyCodeLine{137             sink(i,k) = sink\_dist}
\DoxyCodeLine{138             h\_minus\_dsink(i,k) = h\_old(i,j,k) + (sink(i,k+1) - sink(i,k))}
\DoxyCodeLine{139           \textcolor{keywordflow}{elseif} (sink(i,k+1) + h\_old(i,j,k) < sink\_dist) \textcolor{keywordflow}{then}}
\DoxyCodeLine{140             sink(i,k) = sink(i,k+1) + h\_old(i,j,k)}
\DoxyCodeLine{141             h\_minus\_dsink(i,k) = 0.0}
\DoxyCodeLine{142           \textcolor{keywordflow}{else}}
\DoxyCodeLine{143             sink(i,k) = sink\_dist}
\DoxyCodeLine{144             h\_minus\_dsink(i,k) = (h\_old(i,j,k) + sink(i,k+1)) - sink(i,k)}
\DoxyCodeLine{145 \textcolor{keywordflow}{          endif}}
\DoxyCodeLine{146 \textcolor{keywordflow}{        enddo} ;\textcolor{keywordflow}{ enddo}}
\DoxyCodeLine{147 \textcolor{keywordflow}{      endif}}
\DoxyCodeLine{148       \textcolor{keywordflow}{do} i=is,ie}
\DoxyCodeLine{149         sink(i,1) = 0.0 ; h\_minus\_dsink(i,1) = (h\_old(i,j,1) + sink(i,2))}
\DoxyCodeLine{150 \textcolor{keywordflow}{      enddo}}
\DoxyCodeLine{151 }
\DoxyCodeLine{152       \textcolor{comment}{! Now solve the tridiagonal equation for the tracer concentrations.}}
\DoxyCodeLine{153       \textcolor{keywordflow}{do} i=is,ie ; \textcolor{keywordflow}{if} (g\%mask2dT(i,j) > 0.5) \textcolor{keywordflow}{then}}
\DoxyCodeLine{154         b\_denom\_1 = h\_minus\_dsink(i,1) + ea(i,j,1) + h\_neglect}
\DoxyCodeLine{155         b1(i) = 1.0 / (b\_denom\_1 + eb(i,j,1))}
\DoxyCodeLine{156         d1(i) = b\_denom\_1 * b1(i)}
\DoxyCodeLine{157         h\_tr = h\_old(i,j,1) + h\_neglect}
\DoxyCodeLine{158         tr(i,j,1) = (b1(i)*h\_tr)*tr(i,j,1) + sfc\_src(i,j)}
\DoxyCodeLine{159 \textcolor{keywordflow}{      endif} ;\textcolor{keywordflow}{ enddo}}
\DoxyCodeLine{160       \textcolor{keywordflow}{do} k=2,nz-1 ; \textcolor{keywordflow}{do} i=is,ie ; \textcolor{keywordflow}{if} (g\%mask2dT(i,j) > 0.5) \textcolor{keywordflow}{then}}
\DoxyCodeLine{161         c1(i,k) = eb(i,j,k-1) * b1(i)}
\DoxyCodeLine{162         b\_denom\_1 = h\_minus\_dsink(i,k) + d1(i) * (ea(i,j,k) + sink(i,k)) + \&}
\DoxyCodeLine{163                     h\_neglect}
\DoxyCodeLine{164         b1(i) = 1.0 / (b\_denom\_1 + eb(i,j,k))}
\DoxyCodeLine{165         d1(i) = b\_denom\_1 * b1(i)}
\DoxyCodeLine{166         h\_tr = h\_old(i,j,k) + h\_neglect}
\DoxyCodeLine{167         tr(i,j,k) = b1(i) * (h\_tr * tr(i,j,k) + \&}
\DoxyCodeLine{168                              (ea(i,j,k) + sink(i,k)) * tr(i,j,k-1))}
\DoxyCodeLine{169 \textcolor{keywordflow}{      endif} ;\textcolor{keywordflow}{ enddo} ;\textcolor{keywordflow}{ enddo}}
\DoxyCodeLine{170       \textcolor{keywordflow}{do} i=is,ie ; \textcolor{keywordflow}{if} (g\%mask2dT(i,j) > 0.5) \textcolor{keywordflow}{then}}
\DoxyCodeLine{171         c1(i,nz) = eb(i,j,nz-1) * b1(i)}
\DoxyCodeLine{172         b\_denom\_1 = h\_minus\_dsink(i,nz) + d1(i) * (ea(i,j,nz) + sink(i,nz)) + \&}
\DoxyCodeLine{173                     h\_neglect}
\DoxyCodeLine{174         b1(i) = 1.0 / (b\_denom\_1 + eb(i,j,nz))}
\DoxyCodeLine{175         h\_tr = h\_old(i,j,nz) + h\_neglect}
\DoxyCodeLine{176         tr(i,j,nz) = b1(i) * ((h\_tr * tr(i,j,nz) + btm\_src(i,j)) + \&}
\DoxyCodeLine{177                               (ea(i,j,nz) + sink(i,nz)) * tr(i,j,nz-1))}
\DoxyCodeLine{178 \textcolor{keywordflow}{      endif} ;\textcolor{keywordflow}{ enddo}}
\DoxyCodeLine{179       \textcolor{keywordflow}{if} (\textcolor{keyword}{present}(btm\_reservoir)) \textcolor{keywordflow}{then} ; \textcolor{keywordflow}{do} i=is,ie ; \textcolor{keywordflow}{if} (g\%mask2dT(i,j)>0.5) \textcolor{keywordflow}{then}}
\DoxyCodeLine{180         btm\_reservoir(i,j) = btm\_reservoir(i,j) + \&}
\DoxyCodeLine{181                              (sink(i,nz+1)*tr(i,j,nz)) * gv\%H\_to\_kg\_m2}
\DoxyCodeLine{182 \textcolor{keywordflow}{      endif} ;\textcolor{keywordflow}{ enddo} ;\textcolor{keywordflow}{ endif}}
\DoxyCodeLine{183 }
\DoxyCodeLine{184       \textcolor{keywordflow}{do} k=nz-1,1,-1 ; \textcolor{keywordflow}{do} i=is,ie ; \textcolor{keywordflow}{if} (g\%mask2dT(i,j) > 0.5) \textcolor{keywordflow}{then}}
\DoxyCodeLine{185         tr(i,j,k) = tr(i,j,k) + c1(i,k+1)*tr(i,j,k+1)}
\DoxyCodeLine{186 \textcolor{keywordflow}{      endif} ;\textcolor{keywordflow}{ enddo} ;\textcolor{keywordflow}{ enddo}}
\DoxyCodeLine{187 \textcolor{keywordflow}{    enddo}}
\DoxyCodeLine{188   \textcolor{keywordflow}{else}}
\DoxyCodeLine{189 \textcolor{comment}{!\$OMP do}}
\DoxyCodeLine{190     \textcolor{keywordflow}{do} j=js,je}
\DoxyCodeLine{191       \textcolor{keywordflow}{do} i=is,ie ; \textcolor{keywordflow}{if} (g\%mask2dT(i,j) > -0.5) \textcolor{keywordflow}{then}}
\DoxyCodeLine{192         h\_tr = h\_old(i,j,1) + h\_neglect}
\DoxyCodeLine{193         b\_denom\_1 = h\_tr + ea(i,j,1)}
\DoxyCodeLine{194         b1(i) = 1.0 / (b\_denom\_1 + eb(i,j,1))}
\DoxyCodeLine{195         d1(i) = h\_tr * b1(i)}
\DoxyCodeLine{196         tr(i,j,1) = (b1(i)*h\_tr)*tr(i,j,1) + sfc\_src(i,j)}
\DoxyCodeLine{197 \textcolor{keywordflow}{       endif}}
\DoxyCodeLine{198 \textcolor{keywordflow}{      enddo}}
\DoxyCodeLine{199       \textcolor{keywordflow}{do} k=2,nz-1 ; \textcolor{keywordflow}{do} i=is,ie ; \textcolor{keywordflow}{if} (g\%mask2dT(i,j) > -0.5) \textcolor{keywordflow}{then}}
\DoxyCodeLine{200         c1(i,k) = eb(i,j,k-1) * b1(i)}
\DoxyCodeLine{201         h\_tr = h\_old(i,j,k) + h\_neglect}
\DoxyCodeLine{202         b\_denom\_1 = h\_tr + d1(i) * ea(i,j,k)}
\DoxyCodeLine{203         b1(i) = 1.0 / (b\_denom\_1 + eb(i,j,k))}
\DoxyCodeLine{204         d1(i) = b\_denom\_1 * b1(i)}
\DoxyCodeLine{205         tr(i,j,k) = b1(i) * (h\_tr * tr(i,j,k) + ea(i,j,k) * tr(i,j,k-1))}
\DoxyCodeLine{206 \textcolor{keywordflow}{      endif} ;\textcolor{keywordflow}{ enddo} ;\textcolor{keywordflow}{ enddo}}
\DoxyCodeLine{207       \textcolor{keywordflow}{do} i=is,ie ; \textcolor{keywordflow}{if} (g\%mask2dT(i,j) > -0.5) \textcolor{keywordflow}{then}}
\DoxyCodeLine{208         c1(i,nz) = eb(i,j,nz-1) * b1(i)}
\DoxyCodeLine{209         h\_tr = h\_old(i,j,nz) + h\_neglect}
\DoxyCodeLine{210         b\_denom\_1 = h\_tr + d1(i)*ea(i,j,nz)}
\DoxyCodeLine{211         b1(i) = 1.0 / ( b\_denom\_1 + eb(i,j,nz))}
\DoxyCodeLine{212         tr(i,j,nz) = b1(i) * (( h\_tr * tr(i,j,nz) + btm\_src(i,j)) + \&}
\DoxyCodeLine{213                               ea(i,j,nz) * tr(i,j,nz-1))}
\DoxyCodeLine{214 \textcolor{keywordflow}{      endif} ;\textcolor{keywordflow}{ enddo}}
\DoxyCodeLine{215       \textcolor{keywordflow}{do} k=nz-1,1,-1 ; \textcolor{keywordflow}{do} i=is,ie ; \textcolor{keywordflow}{if} (g\%mask2dT(i,j) > -0.5) \textcolor{keywordflow}{then}}
\DoxyCodeLine{216         tr(i,j,k) = tr(i,j,k) + c1(i,k+1)*tr(i,j,k+1)}
\DoxyCodeLine{217 \textcolor{keywordflow}{      endif} ;\textcolor{keywordflow}{ enddo} ;\textcolor{keywordflow}{ enddo}}
\DoxyCodeLine{218 \textcolor{keywordflow}{    enddo}}
\DoxyCodeLine{219 \textcolor{keywordflow}{  endif}}
\DoxyCodeLine{220 }
\DoxyCodeLine{221 \textcolor{comment}{!\$OMP end parallel}}
\DoxyCodeLine{222 }

\end{DoxyCode}
