\hypertarget{namespacemom__tidal__mixing}{}\section{mom\+\_\+tidal\+\_\+mixing Module Reference}
\label{namespacemom__tidal__mixing}\index{mom\+\_\+tidal\+\_\+mixing@{mom\+\_\+tidal\+\_\+mixing}}


\subsection{Detailed Description}
Interface to vertical tidal mixing schemes including C\+V\+Mix tidal mixing. \subsection*{Data Types}
\begin{DoxyCompactItemize}
\item 
type \mbox{\hyperlink{structmom__tidal__mixing_1_1tidal__mixing__cs}{tidal\+\_\+mixing\+\_\+cs}}
\begin{DoxyCompactList}\small\item\em Control structure with parameters for the tidal mixing module. \end{DoxyCompactList}\item 
type \mbox{\hyperlink{structmom__tidal__mixing_1_1tidal__mixing__diags}{tidal\+\_\+mixing\+\_\+diags}}
\begin{DoxyCompactList}\small\item\em Containers for tidal mixing diagnostics. \end{DoxyCompactList}\end{DoxyCompactItemize}
\subsection*{Functions/\+Subroutines}
\begin{DoxyCompactItemize}
\item 
logical function, public \mbox{\hyperlink{namespacemom__tidal__mixing_a6278fe41ef74ac23ba02ae1540104c5f}{tidal\+\_\+mixing\+\_\+init}} (Time, G, GV, US, param\+\_\+file, diag, CS)
\begin{DoxyCompactList}\small\item\em Initializes internal tidal dissipation scheme for diapycnal mixing. \end{DoxyCompactList}\item 
subroutine, public \mbox{\hyperlink{namespacemom__tidal__mixing_abf084268fd9c71f20880838d2bce7e3e}{calculate\+\_\+tidal\+\_\+mixing}} (h, N2\+\_\+bot, j, T\+K\+E\+\_\+to\+\_\+\+Kd, max\+\_\+\+T\+KE, G, GV, US, CS, N2\+\_\+lay, N2\+\_\+int, Kd\+\_\+lay, Kd\+\_\+int, Kd\+\_\+max, Kv)
\begin{DoxyCompactList}\small\item\em Depending on whether or not C\+V\+Mix is active, calls the associated subroutine to compute internal tidal dissipation and to add the effect of internal-\/tide-\/driven mixing to the layer or interface diffusivities. \end{DoxyCompactList}\item 
subroutine \mbox{\hyperlink{namespacemom__tidal__mixing_af9e675f60c60606f767d4bb1321dba2c}{calculate\+\_\+cvmix\+\_\+tidal}} (h, j, G, GV, US, CS, N2\+\_\+int, Kd\+\_\+lay, Kd\+\_\+int, Kv)
\begin{DoxyCompactList}\small\item\em Calls the C\+V\+Mix routines to compute tidal dissipation and to add the effect of internal-\/tide-\/driven mixing to the interface diffusivities. \end{DoxyCompactList}\item 
subroutine \mbox{\hyperlink{namespacemom__tidal__mixing_aa8f8da6657f71aaef15f3cbe4e5f521d}{add\+\_\+int\+\_\+tide\+\_\+diffusivity}} (h, N2\+\_\+bot, j, T\+K\+E\+\_\+to\+\_\+\+Kd, max\+\_\+\+T\+KE, G, GV, US, CS, N2\+\_\+lay, Kd\+\_\+lay, Kd\+\_\+int, Kd\+\_\+max)
\begin{DoxyCompactList}\small\item\em This subroutine adds the effect of internal-\/tide-\/driven mixing to the layer diffusivities. The mechanisms considered are (1) local dissipation of internal waves generated by the barotropic flow (\char`\"{}itidal\char`\"{}), (2) local dissipation of internal waves generated by the propagating low modes (rays) of the internal tide (\char`\"{}lowmode\char`\"{}), and (3) local dissipation of internal lee waves. Will eventually need to add diffusivity due to other wave-\/breaking processes (e.\+g. Bottom friction, Froude-\/number-\/depending breaking, P\+SI, etc.). \end{DoxyCompactList}\item 
subroutine, public \mbox{\hyperlink{namespacemom__tidal__mixing_a7d2dfb64df35957d1252ce841c0cdf43}{setup\+\_\+tidal\+\_\+diagnostics}} (G, CS)
\begin{DoxyCompactList}\small\item\em Sets up diagnostics arrays for tidal mixing. \end{DoxyCompactList}\item 
subroutine, public \mbox{\hyperlink{namespacemom__tidal__mixing_af6fabb2bc6e4aabd3187938bda8098ec}{post\+\_\+tidal\+\_\+diagnostics}} (G, GV, h, CS)
\begin{DoxyCompactList}\small\item\em This subroutine offers up diagnostics of the tidal mixing. \end{DoxyCompactList}\item 
subroutine, public \mbox{\hyperlink{namespacemom__tidal__mixing_a31fc0b55d7766de2d21fb529e491de13}{tidal\+\_\+mixing\+\_\+h\+\_\+amp}} (h\+\_\+amp, G, j, CS)
\begin{DoxyCompactList}\small\item\em This subroutine returns a zonal slice of the topographic roughness amplitudes. \end{DoxyCompactList}\item 
subroutine \mbox{\hyperlink{namespacemom__tidal__mixing_adfd3a137ee6402fdcdfb7c46711e0e23}{read\+\_\+tidal\+\_\+energy}} (G, US, tidal\+\_\+energy\+\_\+type, tidal\+\_\+energy\+\_\+file, CS)
\begin{DoxyCompactList}\small\item\em This subroutine read tidal energy inputs from a file. \end{DoxyCompactList}\item 
subroutine \mbox{\hyperlink{namespacemom__tidal__mixing_a30a24b88982a5134253679d9484b3708}{read\+\_\+tidal\+\_\+constituents}} (G, US, tidal\+\_\+energy\+\_\+file, CS)
\begin{DoxyCompactList}\small\item\em This subroutine reads tidal input energy from a file by constituent. \end{DoxyCompactList}\item 
subroutine, public \mbox{\hyperlink{namespacemom__tidal__mixing_a4ec08e118dea2ecbac7e719ed73acc70}{tidal\+\_\+mixing\+\_\+end}} (CS)
\begin{DoxyCompactList}\small\item\em Clear pointers and deallocate memory. \end{DoxyCompactList}\end{DoxyCompactItemize}
\subsection*{Variables}
\textbf{ }\par
\begin{DoxyCompactItemize}
\item 
\mbox{\Hypertarget{namespacemom__tidal__mixing_a7d67c30f468c9f4c8d97bfe2e3341bff}\label{namespacemom__tidal__mixing_a7d67c30f468c9f4c8d97bfe2e3341bff}} 
character $\ast$(20), parameter \mbox{\hyperlink{namespacemom__tidal__mixing_a7d67c30f468c9f4c8d97bfe2e3341bff}{stlaurent\+\_\+profile\+\_\+string}} = \char`\"{}S\+T\+L\+A\+U\+R\+E\+N\+T\+\_\+02\char`\"{}
\begin{DoxyCompactList}\small\item\em Coded parmameters for specifying mixing schemes. \end{DoxyCompactList}\item 
\mbox{\Hypertarget{namespacemom__tidal__mixing_ab6b1348f160c8cab37a087b10cf11e7f}\label{namespacemom__tidal__mixing_ab6b1348f160c8cab37a087b10cf11e7f}} 
character $\ast$(20), parameter \mbox{\hyperlink{namespacemom__tidal__mixing_ab6b1348f160c8cab37a087b10cf11e7f}{polzin\+\_\+profile\+\_\+string}} = \char`\"{}P\+O\+L\+Z\+I\+N\+\_\+09\char`\"{}
\begin{DoxyCompactList}\small\item\em Coded parmameters for specifying mixing schemes. \end{DoxyCompactList}\item 
\mbox{\Hypertarget{namespacemom__tidal__mixing_a507b1bb394ac4788c09657334b682297}\label{namespacemom__tidal__mixing_a507b1bb394ac4788c09657334b682297}} 
integer, parameter \mbox{\hyperlink{namespacemom__tidal__mixing_a507b1bb394ac4788c09657334b682297}{stlaurent\+\_\+02}} = 1
\begin{DoxyCompactList}\small\item\em Coded parmameters for specifying mixing schemes. \end{DoxyCompactList}\item 
\mbox{\Hypertarget{namespacemom__tidal__mixing_afed6c5ada4d2eeb610c5c87029d36ac3}\label{namespacemom__tidal__mixing_afed6c5ada4d2eeb610c5c87029d36ac3}} 
integer, parameter \mbox{\hyperlink{namespacemom__tidal__mixing_afed6c5ada4d2eeb610c5c87029d36ac3}{polzin\+\_\+09}} = 2
\begin{DoxyCompactList}\small\item\em Coded parmameters for specifying mixing schemes. \end{DoxyCompactList}\item 
\mbox{\Hypertarget{namespacemom__tidal__mixing_a264f090d7416d0fa6542e7ba51299cbd}\label{namespacemom__tidal__mixing_a264f090d7416d0fa6542e7ba51299cbd}} 
character $\ast$(20), parameter \mbox{\hyperlink{namespacemom__tidal__mixing_a264f090d7416d0fa6542e7ba51299cbd}{simmons\+\_\+scheme\+\_\+string}} = \char`\"{}S\+I\+M\+M\+O\+NS\char`\"{}
\begin{DoxyCompactList}\small\item\em Coded parmameters for specifying mixing schemes. \end{DoxyCompactList}\item 
\mbox{\Hypertarget{namespacemom__tidal__mixing_aa77238da241cd9c94f24a9bd8d3b2fe1}\label{namespacemom__tidal__mixing_aa77238da241cd9c94f24a9bd8d3b2fe1}} 
character $\ast$(20), parameter \mbox{\hyperlink{namespacemom__tidal__mixing_aa77238da241cd9c94f24a9bd8d3b2fe1}{schmittner\+\_\+scheme\+\_\+string}} = \char`\"{}S\+C\+H\+M\+I\+T\+T\+N\+ER\char`\"{}
\begin{DoxyCompactList}\small\item\em Coded parmameters for specifying mixing schemes. \end{DoxyCompactList}\item 
\mbox{\Hypertarget{namespacemom__tidal__mixing_a4e093041fb72f388f962e7a1091c55bf}\label{namespacemom__tidal__mixing_a4e093041fb72f388f962e7a1091c55bf}} 
integer, parameter \mbox{\hyperlink{namespacemom__tidal__mixing_a4e093041fb72f388f962e7a1091c55bf}{simmons}} = 1
\begin{DoxyCompactList}\small\item\em Coded parmameters for specifying mixing schemes. \end{DoxyCompactList}\item 
\mbox{\Hypertarget{namespacemom__tidal__mixing_a96e82abebc8049e136886af73ae99906}\label{namespacemom__tidal__mixing_a96e82abebc8049e136886af73ae99906}} 
integer, parameter \mbox{\hyperlink{namespacemom__tidal__mixing_a96e82abebc8049e136886af73ae99906}{schmittner}} = 2
\begin{DoxyCompactList}\small\item\em Coded parmameters for specifying mixing schemes. \end{DoxyCompactList}\end{DoxyCompactItemize}



\subsection{Function/\+Subroutine Documentation}
\mbox{\Hypertarget{namespacemom__tidal__mixing_aa8f8da6657f71aaef15f3cbe4e5f521d}\label{namespacemom__tidal__mixing_aa8f8da6657f71aaef15f3cbe4e5f521d}} 
\index{mom\+\_\+tidal\+\_\+mixing@{mom\+\_\+tidal\+\_\+mixing}!add\+\_\+int\+\_\+tide\+\_\+diffusivity@{add\+\_\+int\+\_\+tide\+\_\+diffusivity}}
\index{add\+\_\+int\+\_\+tide\+\_\+diffusivity@{add\+\_\+int\+\_\+tide\+\_\+diffusivity}!mom\+\_\+tidal\+\_\+mixing@{mom\+\_\+tidal\+\_\+mixing}}
\subsubsection{\texorpdfstring{add\+\_\+int\+\_\+tide\+\_\+diffusivity()}{add\_int\_tide\_diffusivity()}}
{\footnotesize\ttfamily subroutine mom\+\_\+tidal\+\_\+mixing\+::add\+\_\+int\+\_\+tide\+\_\+diffusivity (\begin{DoxyParamCaption}\item[{real, dimension( g \%isd\+: g \%ied, g \%jsd\+: g \%jed, g \%ke), intent(in)}]{h,  }\item[{real, dimension( g \%isd\+: g \%ied), intent(in)}]{N2\+\_\+bot,  }\item[{integer, intent(in)}]{j,  }\item[{real, dimension( g \%isd\+: g \%ied, g \%ke), intent(in)}]{T\+K\+E\+\_\+to\+\_\+\+Kd,  }\item[{real, dimension( g \%isd\+: g \%ied, g \%ke), intent(in)}]{max\+\_\+\+T\+KE,  }\item[{type(ocean\+\_\+grid\+\_\+type), intent(in)}]{G,  }\item[{type(verticalgrid\+\_\+type), intent(in)}]{GV,  }\item[{type(unit\+\_\+scale\+\_\+type), intent(in)}]{US,  }\item[{type(\mbox{\hyperlink{structmom__tidal__mixing_1_1tidal__mixing__cs}{tidal\+\_\+mixing\+\_\+cs}}), pointer}]{CS,  }\item[{real, dimension( g \%isd\+: g \%ied, g \%ke), intent(in)}]{N2\+\_\+lay,  }\item[{real, dimension( g \%isd\+: g \%ied, g \%ke), intent(inout), optional}]{Kd\+\_\+lay,  }\item[{real, dimension( g \%isd\+: g \%ied, g \%ke+1), intent(inout), optional}]{Kd\+\_\+int,  }\item[{real, intent(in)}]{Kd\+\_\+max }\end{DoxyParamCaption})\hspace{0.3cm}{\ttfamily [private]}}



This subroutine adds the effect of internal-\/tide-\/driven mixing to the layer diffusivities. The mechanisms considered are (1) local dissipation of internal waves generated by the barotropic flow (\char`\"{}itidal\char`\"{}), (2) local dissipation of internal waves generated by the propagating low modes (rays) of the internal tide (\char`\"{}lowmode\char`\"{}), and (3) local dissipation of internal lee waves. Will eventually need to add diffusivity due to other wave-\/breaking processes (e.\+g. Bottom friction, Froude-\/number-\/depending breaking, P\+SI, etc.). 


\begin{DoxyParams}[1]{Parameters}
\mbox{\tt in}  & {\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}  & {\em us} & A dimensional unit scaling type\\
\hline
\mbox{\tt in}  & {\em h} & Layer thicknesses \mbox{[}H $\sim$$>$ m or kg m-\/2\mbox{]}\\
\hline
\mbox{\tt in}  & {\em n2\+\_\+bot} & The near-\/bottom squared buoyancy frequency frequency \mbox{[}T-\/2 $\sim$$>$ s-\/2\mbox{]}.\\
\hline
\mbox{\tt in}  & {\em n2\+\_\+lay} & The squared buoyancy frequency of the layers \mbox{[}T-\/2 $\sim$$>$ s-\/2\mbox{]}.\\
\hline
\mbox{\tt in}  & {\em j} & The j-\/index to work on\\
\hline
\mbox{\tt in}  & {\em tke\+\_\+to\+\_\+kd} & The conversion rate between the T\+KE dissipated within a layer and the diapycnal diffusivity within that layer, usually ($\sim$\+Rho\+\_\+0 / (G\+\_\+\+Earth $\ast$ d\+Rho\+\_\+lay)) \mbox{[}Z2 T-\/1 / Z3 T-\/3 = T2 Z-\/1 $\sim$$>$ s2 m-\/1\mbox{]}\\
\hline
\mbox{\tt in}  & {\em max\+\_\+tke} & The energy required to for a layer to entrain to its maximum realizable thickness \mbox{[}Z3 T-\/3 $\sim$$>$ m3 s-\/3\mbox{]}\\
\hline
 & {\em cs} & The control structure for this module\\
\hline
\mbox{\tt in,out}  & {\em kd\+\_\+lay} & The diapycnal diffusivity in layers \mbox{[}Z2 T-\/1 $\sim$$>$ m2 s-\/1\mbox{]}.\\
\hline
\mbox{\tt in,out}  & {\em kd\+\_\+int} & The diapycnal diffusivity at interfaces\\
\hline
\mbox{\tt in}  & {\em kd\+\_\+max} & The maximum increment for diapycnal diffusivity due to T\+K\+E-\/based processes \mbox{[}Z2 T-\/1 $\sim$$>$ m2 s-\/1\mbox{]}. Set this to a negative value to have no limit. \\
\hline
\end{DoxyParams}


Definition at line 962 of file M\+O\+M\+\_\+tidal\+\_\+mixing.\+F90.


\begin{DoxyCode}
962   \textcolor{keywordtype}{type}(ocean\_grid\_type),            \textcolor{keywordtype}{intent(in)}    :: G\textcolor{comment}{      !< The ocean's grid structure}
963   \textcolor{keywordtype}{type}(verticalGrid\_type),          \textcolor{keywordtype}{intent(in)}    :: GV\textcolor{comment}{     !< The ocean's vertical grid structure}
964   \textcolor{keywordtype}{type}(unit\_scale\_type),            \textcolor{keywordtype}{intent(in)}    :: US\textcolor{comment}{     !< A dimensional unit scaling type}
965   \textcolor{keywordtype}{real}, \textcolor{keywordtype}{dimension(SZI\_(G),SZJ\_(G),SZK\_(G))}, &
966                                     \textcolor{keywordtype}{intent(in)}    :: h\textcolor{comment}{      !< Layer thicknesses [H ~> m or kg m-2]}
967   \textcolor{keywordtype}{real}, \textcolor{keywordtype}{dimension(SZI\_(G))},         \textcolor{keywordtype}{intent(in)}    :: N2\_bot\textcolor{comment}{ !< The near-bottom squared buoyancy frequency}
968 \textcolor{comment}{                                                            !! frequency [T-2 ~> s-2].}
969   \textcolor{keywordtype}{real}, \textcolor{keywordtype}{dimension(SZI\_(G),SZK\_(G))}, \textcolor{keywordtype}{intent(in)}    :: N2\_lay\textcolor{comment}{ !< The squared buoyancy frequency of the}
970 \textcolor{comment}{                                                            !! layers [T-2 ~> s-2].}
971   \textcolor{keywordtype}{integer},                          \textcolor{keywordtype}{intent(in)}    :: j\textcolor{comment}{      !< The j-index to work on}
972   \textcolor{keywordtype}{real}, \textcolor{keywordtype}{dimension(SZI\_(G),SZK\_(G))}, \textcolor{keywordtype}{intent(in)}    :: TKE\_to\_Kd\textcolor{comment}{ !< The conversion rate between the TKE}
973 \textcolor{comment}{                                                            !! dissipated within a layer and the}
974 \textcolor{comment}{                                                            !! diapycnal diffusivity within that layer,}
975 \textcolor{comment}{                                                            !! usually (~Rho\_0 / (G\_Earth * dRho\_lay))}
976 \textcolor{comment}{                                                            !! [Z2 T-1 / Z3 T-3 = T2 Z-1 ~> s2 m-1]}
977   \textcolor{keywordtype}{real}, \textcolor{keywordtype}{dimension(SZI\_(G),SZK\_(G))}, \textcolor{keywordtype}{intent(in)}    :: max\_TKE\textcolor{comment}{ !< The energy required to for a layer to
       entrain}
978 \textcolor{comment}{                                                            !! to its maximum realizable thickness [Z3 T-3
       ~> m3 s-3]}
979   \textcolor{keywordtype}{type}(tidal\_mixing\_cs),            \textcolor{keywordtype}{pointer}       :: CS\textcolor{comment}{     !< The control structure for this module}
980   \textcolor{keywordtype}{real}, \textcolor{keywordtype}{dimension(SZI\_(G),SZK\_(G))}, &
981                           \textcolor{keywordtype}{optional}, \textcolor{keywordtype}{intent(inout)} :: Kd\_lay\textcolor{comment}{ !< The diapycnal diffusivity in layers [Z2 T-1
       ~> m2 s-1].}
982   \textcolor{keywordtype}{real}, \textcolor{keywordtype}{dimension(SZI\_(G),SZK\_(G)+1)}, &
983                           \textcolor{keywordtype}{optional}, \textcolor{keywordtype}{intent(inout)} :: Kd\_int\textcolor{comment}{ !< The diapycnal diffusivity at interfaces}
984 \textcolor{comment}{                                                            !! [Z2 T-1 ~> m2 s-1].}
985   \textcolor{keywordtype}{real},                             \textcolor{keywordtype}{intent(in)}    :: Kd\_max\textcolor{comment}{ !< The maximum increment for diapycnal}
986 \textcolor{comment}{                                                            !! diffusivity due to TKE-based processes}
987 \textcolor{comment}{                                                            !! [Z2 T-1 ~> m2 s-1].}
988 \textcolor{comment}{                                                            !! Set this to a negative value to have no
       limit.}
989 
990   \textcolor{comment}{! local}
991 
992   \textcolor{keywordtype}{real}, \textcolor{keywordtype}{dimension(SZI\_(G))} :: &
993     htot,             & \textcolor{comment}{! total thickness above or below a layer, or the}
994                         \textcolor{comment}{! integrated thickness in the BBL [Z ~> m].}
995     htot\_wkb,         & \textcolor{comment}{! WKB scaled distance from top to bottom [Z ~> m].}
996     tke\_itidal\_bot,   & \textcolor{comment}{! internal tide TKE at ocean bottom [Z3 T-3 ~> m3 s-3]}
997     tke\_niku\_bot,     & \textcolor{comment}{! lee-wave TKE at ocean bottom [Z3 T-3 ~> m3 s-3]}
998     tke\_lowmode\_bot,  & \textcolor{comment}{! internal tide TKE at ocean bottom lost from all remote low modes [Z3 T-3 ~> m3
       s-3] (BDM)}
999     inv\_int,          & \textcolor{comment}{! inverse of TKE decay for int tide over the depth of the ocean [nondim]}
1000     inv\_int\_lee,      & \textcolor{comment}{! inverse of TKE decay for lee waves over the depth of the ocean [nondim]}
1001     inv\_int\_low,      & \textcolor{comment}{! inverse of TKE decay for low modes over the depth of the ocean [nondim] (BDM)}
1002     z0\_polzin,        & \textcolor{comment}{! TKE decay scale in Polzin formulation [Z ~> m].}
1003     z0\_polzin\_scaled, & \textcolor{comment}{! TKE decay scale in Polzin formulation [Z ~> m].}
1004                         \textcolor{comment}{! multiplied by N2\_bot/N2\_meanz to be coherent with the WKB scaled z}
1005                         \textcolor{comment}{! z*=int(N2/N2\_bot) * N2\_bot/N2\_meanz = int(N2/N2\_meanz)}
1006                         \textcolor{comment}{! z0\_Polzin\_scaled = z0\_Polzin * N2\_bot/N2\_meanz}
1007     n2\_meanz,         & \textcolor{comment}{! vertically averaged squared buoyancy frequency [T-2] for WKB scaling}
1008     tke\_itidal\_rem,   & \textcolor{comment}{! remaining internal tide TKE (from barotropic source) [Z3 T-3 ~> m3 s-3]}
1009     tke\_niku\_rem,     & \textcolor{comment}{! remaining lee-wave TKE [Z3 T-3 ~> m3 s-3]}
1010     tke\_lowmode\_rem,  & \textcolor{comment}{! remaining internal tide TKE (from propagating low mode source) [Z3 T-3 ~> m3 s-3]
       (BDM)}
1011     tke\_frac\_top,     & \textcolor{comment}{! fraction of bottom TKE that should appear at top of a layer [nondim]}
1012     tke\_frac\_top\_lee, & \textcolor{comment}{! fraction of bottom TKE that should appear at top of a layer [nondim]}
1013     tke\_frac\_top\_lowmode, &
1014                         \textcolor{comment}{! fraction of bottom TKE that should appear at top of a layer [nondim] (BDM)}
1015     z\_from\_bot,       & \textcolor{comment}{! distance from bottom [Z ~> m].}
1016     z\_from\_bot\_wkb      \textcolor{comment}{! WKB scaled distance from bottom [Z ~> m].}
1017 
1018   \textcolor{keywordtype}{real} :: I\_rho0        \textcolor{comment}{! Inverse of the Boussinesq reference density, i.e. 1 / RHO0 [R-1 ~> m3 kg-1]}
1019   \textcolor{keywordtype}{real} :: Kd\_add        \textcolor{comment}{! diffusivity to add in a layer [Z2 T-1 ~> m2 s-1].}
1020   \textcolor{keywordtype}{real} :: TKE\_itide\_lay \textcolor{comment}{! internal tide TKE imparted to a layer (from barotropic) [Z3 T-3 ~> m3 s-3]}
1021   \textcolor{keywordtype}{real} :: TKE\_Niku\_lay  \textcolor{comment}{! lee-wave TKE imparted to a layer [Z3 T-3 ~> m3 s-3]}
1022   \textcolor{keywordtype}{real} :: TKE\_lowmode\_lay \textcolor{comment}{! internal tide TKE imparted to a layer (from low mode) [Z3 T-3 ~> m3 s-3] (BDM)}
1023   \textcolor{keywordtype}{real} :: frac\_used     \textcolor{comment}{! fraction of TKE that can be used in a layer [nondim]}
1024   \textcolor{keywordtype}{real} :: Izeta         \textcolor{comment}{! inverse of TKE decay scale [Z-1 ~> m-1].}
1025   \textcolor{keywordtype}{real} :: Izeta\_lee     \textcolor{comment}{! inverse of TKE decay scale for lee waves [Z-1 ~> m-1].}
1026   \textcolor{keywordtype}{real} :: z0Ps\_num      \textcolor{comment}{! The numerator of the unlimited z0\_Polzin\_scaled [Z T-3 ~> m s-3].}
1027   \textcolor{keywordtype}{real} :: z0Ps\_denom    \textcolor{comment}{! The denominator of the unlimited z0\_Polzin\_scaled [T-3 ~> s-3].}
1028   \textcolor{keywordtype}{real} :: z0\_psl        \textcolor{comment}{! temporary variable [Z ~> m].}
1029   \textcolor{keywordtype}{real} :: TKE\_lowmode\_tot \textcolor{comment}{! TKE from all low modes [R Z3 T-3 ~> W m-2] (BDM)}
1030 
1031   \textcolor{keywordtype}{logical} :: use\_Polzin, use\_Simmons
1032   \textcolor{keywordtype}{character(len=160)} :: mesg  \textcolor{comment}{! The text of an error message}
1033   \textcolor{keywordtype}{integer} :: i, k, is, ie, nz
1034   \textcolor{keywordtype}{integer} :: a, fr, m
1035   \textcolor{keywordtype}{type}(tidal\_mixing\_diags), \textcolor{keywordtype}{pointer} :: dd => null()
1036 
1037   is = g%isc ; ie = g%iec ; nz = g%ke
1038   dd => cs%dd
1039 
1040   \textcolor{keywordflow}{if} (.not.(cs%Int\_tide\_dissipation .or. cs%Lee\_wave\_dissipation)) \textcolor{keywordflow}{return}
1041 
1042   \textcolor{keywordflow}{do} i=is,ie ; htot(i) = 0.0 ; inv\_int(i) = 0.0 ; inv\_int\_lee(i) = 0.0 ; inv\_int\_low(i) = 0.0 ;\textcolor{keywordflow}{enddo}
1043   \textcolor{keywordflow}{do} k=1,nz ; \textcolor{keywordflow}{do} i=is,ie
1044     htot(i) = htot(i) + gv%H\_to\_Z*h(i,j,k)
1045 \textcolor{keywordflow}{  enddo} ;\textcolor{keywordflow}{ enddo}
1046 
1047   i\_rho0 = 1.0 / (gv%Rho0)
1048 
1049   use\_polzin = ((cs%Int\_tide\_dissipation .and. (cs%int\_tide\_profile == polzin\_09)) .or. &
1050                 (cs%lee\_wave\_dissipation .and. (cs%lee\_wave\_profile == polzin\_09)) .or. &
1051                 (cs%Lowmode\_itidal\_dissipation .and. (cs%int\_tide\_profile == polzin\_09)))
1052   use\_simmons = ((cs%Int\_tide\_dissipation .and. (cs%int\_tide\_profile == stlaurent\_02)) .or. &
1053                  (cs%lee\_wave\_dissipation .and. (cs%lee\_wave\_profile == stlaurent\_02)) .or. &
1054                  (cs%Lowmode\_itidal\_dissipation .and. (cs%int\_tide\_profile == stlaurent\_02)))
1055 
1056   \textcolor{comment}{! Calculate parameters for vertical structure of dissipation}
1057   \textcolor{comment}{! Simmons:}
1058   \textcolor{keywordflow}{if} ( use\_simmons ) \textcolor{keywordflow}{then}
1059     izeta = 1.0 / max(cs%Int\_tide\_decay\_scale, gv%H\_subroundoff*gv%H\_to\_Z)
1060     izeta\_lee = 1.0 / max(cs%Int\_tide\_decay\_scale*cs%Decay\_scale\_factor\_lee, &
1061                           gv%H\_subroundoff*gv%H\_to\_Z)
1062     \textcolor{keywordflow}{do} i=is,ie
1063       cs%Nb(i,j) = sqrt(n2\_bot(i))
1064       \textcolor{keywordflow}{if} (\textcolor{keyword}{associated}(dd%N2\_bot)) dd%N2\_bot(i,j) = n2\_bot(i)
1065       \textcolor{keywordflow}{if} ( cs%Int\_tide\_dissipation ) \textcolor{keywordflow}{then}
1066         \textcolor{keywordflow}{if} (izeta*htot(i) > 1.0e-14) \textcolor{keywordflow}{then} \textcolor{comment}{! L'Hospital's version of Adcroft's reciprocal rule.}
1067           inv\_int(i) = 1.0 / (1.0 - exp(-izeta*htot(i)))
1068 \textcolor{keywordflow}{        endif}
1069 \textcolor{keywordflow}{      endif}
1070       \textcolor{keywordflow}{if} ( cs%Lee\_wave\_dissipation ) \textcolor{keywordflow}{then}
1071         \textcolor{keywordflow}{if} (izeta\_lee*htot(i) > 1.0e-14) \textcolor{keywordflow}{then}  \textcolor{comment}{! L'Hospital's version of Adcroft's reciprocal rule.}
1072           inv\_int\_lee(i) = 1.0 / (1.0 - exp(-izeta\_lee*htot(i)))
1073 \textcolor{keywordflow}{        endif}
1074 \textcolor{keywordflow}{      endif}
1075       \textcolor{keywordflow}{if} ( cs%Lowmode\_itidal\_dissipation) \textcolor{keywordflow}{then}
1076         \textcolor{keywordflow}{if} (izeta*htot(i) > 1.0e-14) \textcolor{keywordflow}{then} \textcolor{comment}{! L'Hospital's version of Adcroft's reciprocal rule.}
1077           inv\_int\_low(i) = 1.0 / (1.0 - exp(-izeta*htot(i)))
1078 \textcolor{keywordflow}{        endif}
1079 \textcolor{keywordflow}{      endif}
1080       z\_from\_bot(i) = gv%H\_to\_Z*h(i,j,nz)
1081 \textcolor{keywordflow}{    enddo}
1082 \textcolor{keywordflow}{  endif} \textcolor{comment}{! Simmons}
1083 
1084   \textcolor{comment}{! Polzin:}
1085   \textcolor{keywordflow}{if} ( use\_polzin ) \textcolor{keywordflow}{then}
1086     \textcolor{comment}{! WKB scaling of the vertical coordinate}
1087     \textcolor{keywordflow}{do} i=is,ie ; n2\_meanz(i) = 0.0 ;\textcolor{keywordflow}{ enddo}
1088     \textcolor{keywordflow}{do} k=1,nz ; \textcolor{keywordflow}{do} i=is,ie
1089       n2\_meanz(i) = n2\_meanz(i) + n2\_lay(i,k) * gv%H\_to\_Z * h(i,j,k)
1090 \textcolor{keywordflow}{    enddo} ;\textcolor{keywordflow}{ enddo}
1091     \textcolor{keywordflow}{do} i=is,ie
1092       n2\_meanz(i) = n2\_meanz(i) / (htot(i) + gv%H\_subroundoff*gv%H\_to\_Z)
1093       \textcolor{keywordflow}{if} (\textcolor{keyword}{associated}(dd%N2\_meanz))  dd%N2\_meanz(i,j) = n2\_meanz(i)
1094 \textcolor{keywordflow}{    enddo}
1095 
1096     \textcolor{comment}{! WKB scaled z*(z=H) z* at the surface using the modified Polzin WKB scaling}
1097     \textcolor{keywordflow}{do} i=is,ie ; htot\_wkb(i) = htot(i) ;\textcolor{keywordflow}{ enddo}
1098 \textcolor{comment}{!    do i=is,ie ; htot\_WKB(i) = 0.0 ; enddo}
1099 \textcolor{comment}{!    do k=1,nz ; do i=is,ie}
1100 \textcolor{comment}{!      htot\_WKB(i) = htot\_WKB(i) + GV%H\_to\_Z*h(i,j,k) * N2\_lay(i,k) / N2\_meanz(i)}
1101 \textcolor{comment}{!    enddo ; enddo}
1102     \textcolor{comment}{! htot\_WKB(i) = htot(i) ! Nearly equivalent and simpler}
1103 
1104     \textcolor{keywordflow}{do} i=is,ie
1105       cs%Nb(i,j) = sqrt(n2\_bot(i))
1106       \textcolor{keywordflow}{if} (cs%answers\_2018) \textcolor{keywordflow}{then}
1107         \textcolor{keywordflow}{if} ((cs%tideamp(i,j) > 0.0) .and. &
1108             (cs%kappa\_itides**2 * cs%h2(i,j) * cs%Nb(i,j)**3 > 1.0e-14*us%T\_to\_s**3) ) \textcolor{keywordflow}{then}
1109           z0\_polzin(i) = cs%Polzin\_decay\_scale\_factor * cs%Nu\_Polzin * &
1110                          cs%Nbotref\_Polzin**2 * cs%tideamp(i,j) / &
1111                        ( cs%kappa\_itides**2 * cs%h2(i,j) * cs%Nb(i,j)**3 )
1112           \textcolor{keywordflow}{if} (z0\_polzin(i) < cs%Polzin\_min\_decay\_scale) &
1113             z0\_polzin(i) = cs%Polzin\_min\_decay\_scale
1114           \textcolor{keywordflow}{if} (n2\_meanz(i) > 1.0e-14*us%T\_to\_s**2  ) \textcolor{keywordflow}{then}
1115             z0\_polzin\_scaled(i) = z0\_polzin(i)*cs%Nb(i,j)**2 / n2\_meanz(i)
1116           \textcolor{keywordflow}{else}
1117             z0\_polzin\_scaled(i) = cs%Polzin\_decay\_scale\_max\_factor * htot(i)
1118 \textcolor{keywordflow}{          endif}
1119           \textcolor{keywordflow}{if} (z0\_polzin\_scaled(i) > (cs%Polzin\_decay\_scale\_max\_factor * htot(i)) ) &
1120             z0\_polzin\_scaled(i) = cs%Polzin\_decay\_scale\_max\_factor * htot(i)
1121         \textcolor{keywordflow}{else}
1122           z0\_polzin(i) = cs%Polzin\_decay\_scale\_max\_factor * htot(i)
1123           z0\_polzin\_scaled(i) = cs%Polzin\_decay\_scale\_max\_factor * htot(i)
1124 \textcolor{keywordflow}{        endif}
1125       \textcolor{keywordflow}{else}
1126         z0ps\_num = (cs%Polzin\_decay\_scale\_factor * cs%Nu\_Polzin * cs%Nbotref\_Polzin**2) * cs%tideamp(i,j)
1127         z0ps\_denom = ( cs%kappa\_itides**2 * cs%h2(i,j) * cs%Nb(i,j) * n2\_meanz(i) )
1128         \textcolor{keywordflow}{if} ((cs%tideamp(i,j) > 0.0) .and. &
1129             (z0ps\_num < z0ps\_denom * cs%Polzin\_decay\_scale\_max\_factor * htot(i))) \textcolor{keywordflow}{then}
1130           z0\_polzin\_scaled(i) = z0ps\_num / z0ps\_denom
1131 
1132           \textcolor{keywordflow}{if} (abs(n2\_meanz(i) * z0\_polzin\_scaled(i)) < &
1133               cs%Nb(i,j)**2 * (cs%Polzin\_decay\_scale\_max\_factor * htot(i))) \textcolor{keywordflow}{then}
1134             z0\_polzin(i) = z0\_polzin\_scaled(i) * (n2\_meanz(i) / cs%Nb(i,j)**2)
1135           \textcolor{keywordflow}{else}
1136             z0\_polzin(i) = cs%Polzin\_decay\_scale\_max\_factor * htot(i)
1137 \textcolor{keywordflow}{          endif}
1138         \textcolor{keywordflow}{else}
1139           z0\_polzin(i) = cs%Polzin\_decay\_scale\_max\_factor * htot(i)
1140           z0\_polzin\_scaled(i) = cs%Polzin\_decay\_scale\_max\_factor * htot(i)
1141 \textcolor{keywordflow}{        endif}
1142 \textcolor{keywordflow}{      endif}
1143 
1144       \textcolor{keywordflow}{if} (\textcolor{keyword}{associated}(dd%Polzin\_decay\_scale)) &
1145         dd%Polzin\_decay\_scale(i,j) = z0\_polzin(i)
1146       \textcolor{keywordflow}{if} (\textcolor{keyword}{associated}(dd%Polzin\_decay\_scale\_scaled)) &
1147         dd%Polzin\_decay\_scale\_scaled(i,j) = z0\_polzin\_scaled(i)
1148       \textcolor{keywordflow}{if} (\textcolor{keyword}{associated}(dd%N2\_bot)) dd%N2\_bot(i,j) = cs%Nb(i,j)*cs%Nb(i,j)
1149 
1150       \textcolor{keywordflow}{if} (cs%answers\_2018) \textcolor{keywordflow}{then}
1151         \textcolor{comment}{! These expressions use dimensional constants to avoid NaN values.}
1152         \textcolor{keywordflow}{if} ( cs%Int\_tide\_dissipation .and. (cs%int\_tide\_profile == polzin\_09) ) \textcolor{keywordflow}{then}
1153           \textcolor{keywordflow}{if} (htot\_wkb(i) > 1.0e-14*us%m\_to\_Z) &
1154             inv\_int(i) = ( z0\_polzin\_scaled(i) / htot\_wkb(i) ) + 1.0
1155 \textcolor{keywordflow}{        endif}
1156         \textcolor{keywordflow}{if} ( cs%lee\_wave\_dissipation .and. (cs%lee\_wave\_profile == polzin\_09) ) \textcolor{keywordflow}{then}
1157           \textcolor{keywordflow}{if} (htot\_wkb(i) > 1.0e-14*us%m\_to\_Z) &
1158             inv\_int\_lee(i) = ( z0\_polzin\_scaled(i)*cs%Decay\_scale\_factor\_lee / htot\_wkb(i) ) + 1.0
1159 \textcolor{keywordflow}{        endif}
1160         \textcolor{keywordflow}{if} ( cs%Lowmode\_itidal\_dissipation .and. (cs%int\_tide\_profile == polzin\_09) ) \textcolor{keywordflow}{then}
1161           \textcolor{keywordflow}{if} (htot\_wkb(i) > 1.0e-14*us%m\_to\_Z) &
1162             inv\_int\_low(i) = ( z0\_polzin\_scaled(i) / htot\_wkb(i) ) + 1.0
1163 \textcolor{keywordflow}{        endif}
1164       \textcolor{keywordflow}{else}
1165         \textcolor{comment}{! These expressions give values of Inv\_int < 10^14 using a variant of Adcroft's reciprocal rule.}
1166         inv\_int(i) = 0.0 ; inv\_int\_lee(i) = 0.0 ; inv\_int\_low(i) = 0.0
1167         \textcolor{keywordflow}{if} ( cs%Int\_tide\_dissipation .and. (cs%int\_tide\_profile == polzin\_09) ) \textcolor{keywordflow}{then}
1168           \textcolor{keywordflow}{if} (z0\_polzin\_scaled(i) < 1.0e14 * htot\_wkb(i)) &
1169             inv\_int(i) = ( z0\_polzin\_scaled(i) / htot\_wkb(i) ) + 1.0
1170 \textcolor{keywordflow}{        endif}
1171         \textcolor{keywordflow}{if} ( cs%lee\_wave\_dissipation .and. (cs%lee\_wave\_profile == polzin\_09) ) \textcolor{keywordflow}{then}
1172           \textcolor{keywordflow}{if} (z0\_polzin\_scaled(i) < 1.0e14 * htot\_wkb(i)) &
1173             inv\_int\_lee(i) = ( z0\_polzin\_scaled(i)*cs%Decay\_scale\_factor\_lee / htot\_wkb(i) ) + 1.0
1174 \textcolor{keywordflow}{        endif}
1175         \textcolor{keywordflow}{if} ( cs%Lowmode\_itidal\_dissipation .and. (cs%int\_tide\_profile == polzin\_09) ) \textcolor{keywordflow}{then}
1176           \textcolor{keywordflow}{if} (z0\_polzin\_scaled(i) < 1.0e14 * htot\_wkb(i)) &
1177             inv\_int\_low(i) = ( z0\_polzin\_scaled(i) / htot\_wkb(i) ) + 1.0
1178 \textcolor{keywordflow}{        endif}
1179 \textcolor{keywordflow}{      endif}
1180 
1181       z\_from\_bot(i) = gv%H\_to\_Z*h(i,j,nz)
1182       \textcolor{comment}{! Use the new formulation for WKB scaling.  N2 is referenced to its vertical mean.}
1183       \textcolor{keywordflow}{if} (cs%answers\_2018) \textcolor{keywordflow}{then}
1184         \textcolor{keywordflow}{if} (n2\_meanz(i) > 1.0e-14*us%T\_to\_s**2 ) \textcolor{keywordflow}{then}
1185           z\_from\_bot\_wkb(i) = gv%H\_to\_Z*h(i,j,nz) * n2\_lay(i,nz) / n2\_meanz(i)
1186         \textcolor{keywordflow}{else} ; z\_from\_bot\_wkb(i) = 0 ;\textcolor{keywordflow}{ endif}
1187       \textcolor{keywordflow}{else}
1188         \textcolor{keywordflow}{if} (gv%H\_to\_Z*h(i,j,nz) * n2\_lay(i,nz) < n2\_meanz(i) * (1.0e14 * htot\_wkb(i))) \textcolor{keywordflow}{then}
1189           z\_from\_bot\_wkb(i) = gv%H\_to\_Z*h(i,j,nz) * n2\_lay(i,nz) / n2\_meanz(i)
1190         \textcolor{keywordflow}{else} ; z\_from\_bot\_wkb(i) = 0 ;\textcolor{keywordflow}{ endif}
1191 \textcolor{keywordflow}{      endif}
1192 \textcolor{keywordflow}{    enddo}
1193 \textcolor{keywordflow}{  endif}  \textcolor{comment}{! Polzin}
1194 
1195   \textcolor{comment}{! Calculate/get dissipation values at bottom}
1196   \textcolor{comment}{! Both Polzin and Simmons:}
1197   \textcolor{keywordflow}{do} i=is,ie
1198     \textcolor{comment}{! Dissipation of locally trapped internal tide (non-propagating high modes)}
1199     tke\_itidal\_bot(i) = min(cs%TKE\_itidal(i,j)*cs%Nb(i,j), cs%TKE\_itide\_max)
1200     \textcolor{keywordflow}{if} (\textcolor{keyword}{associated}(dd%TKE\_itidal\_used)) &
1201       dd%TKE\_itidal\_used(i,j) = tke\_itidal\_bot(i)
1202     tke\_itidal\_bot(i) = (i\_rho0 * cs%Mu\_itides * cs%Gamma\_itides) * tke\_itidal\_bot(i)
1203     \textcolor{comment}{! Dissipation of locally trapped lee waves}
1204     tke\_niku\_bot(i) = 0.0
1205     \textcolor{keywordflow}{if} (cs%Lee\_wave\_dissipation) \textcolor{keywordflow}{then}
1206       tke\_niku\_bot(i) = (i\_rho0 * cs%Mu\_itides * cs%Gamma\_lee) * cs%TKE\_Niku(i,j)
1207 \textcolor{keywordflow}{    endif}
1208     \textcolor{comment}{! Dissipation of propagating internal tide (baroclinic low modes; rays) (BDM)}
1209     tke\_lowmode\_tot    = 0.0
1210     tke\_lowmode\_bot(i) = 0.0
1211     \textcolor{keywordflow}{if} (cs%Lowmode\_itidal\_dissipation) \textcolor{keywordflow}{then}
1212       \textcolor{comment}{! get loss rate due to wave drag on low modes (already multiplied by q)}
1213 
1214       \textcolor{comment}{! TODO: uncomment the following call and fix it}
1215       \textcolor{comment}{!call get\_lowmode\_loss(i,j,G,CS%int\_tide\_CSp,"WaveDrag",TKE\_lowmode\_tot)}
1216       \textcolor{keyword}{write} (mesg,*) \textcolor{stringliteral}{"========"}, \_\_file\_\_, \_\_line\_\_
1217       \textcolor{keyword}{call }mom\_error(fatal,trim(mesg)//\textcolor{stringliteral}{": this block not supported yet. (aa)"})
1218 
1219       tke\_lowmode\_bot(i) = cs%Mu\_itides * i\_rho0 * tke\_lowmode\_tot
1220 \textcolor{keywordflow}{    endif}
1221     \textcolor{comment}{! Vertical energy flux at bottom}
1222     tke\_itidal\_rem(i)  = inv\_int(i)     * tke\_itidal\_bot(i)
1223     tke\_niku\_rem(i)    = inv\_int\_lee(i) * tke\_niku\_bot(i)
1224     tke\_lowmode\_rem(i) = inv\_int\_low(i) * tke\_lowmode\_bot(i)
1225 
1226     \textcolor{keywordflow}{if} (\textcolor{keyword}{associated}(dd%Fl\_itidal)) dd%Fl\_itidal(i,j,nz) = tke\_itidal\_rem(i) \textcolor{comment}{!why is this here? BDM}
1227 \textcolor{keywordflow}{  enddo}
1228 
1229   \textcolor{comment}{! Estimate the work that would be done by mixing in each layer.}
1230   \textcolor{comment}{! Simmons:}
1231   \textcolor{keywordflow}{if} ( use\_simmons ) \textcolor{keywordflow}{then}
1232     \textcolor{keywordflow}{do} k=nz-1,2,-1 ; \textcolor{keywordflow}{do} i=is,ie
1233       \textcolor{keywordflow}{if} (max\_tke(i,k) <= 0.0) cycle
1234       z\_from\_bot(i) = z\_from\_bot(i) + gv%H\_to\_Z*h(i,j,k)
1235 
1236       \textcolor{comment}{! Fraction of bottom flux predicted to reach top of this layer}
1237       tke\_frac\_top(i)         = inv\_int(i)     * exp(-izeta * z\_from\_bot(i))
1238       tke\_frac\_top\_lee(i)     = inv\_int\_lee(i) * exp(-izeta\_lee * z\_from\_bot(i))
1239       tke\_frac\_top\_lowmode(i) = inv\_int\_low(i) * exp(-izeta * z\_from\_bot(i))
1240 
1241       \textcolor{comment}{! Actual influx at bottom of layer minus predicted outflux at top of layer to give}
1242       \textcolor{comment}{! predicted power expended}
1243       tke\_itide\_lay   = tke\_itidal\_rem(i)  - tke\_itidal\_bot(i) * tke\_frac\_top(i)
1244       tke\_niku\_lay    = tke\_niku\_rem(i)    - tke\_niku\_bot(i)   * tke\_frac\_top\_lee(i)
1245       tke\_lowmode\_lay = tke\_lowmode\_rem(i) - tke\_lowmode\_bot(i)* tke\_frac\_top\_lowmode(i)
1246 
1247       \textcolor{comment}{! Actual power expended may be less than predicted if stratification is weak; adjust}
1248       \textcolor{keywordflow}{if} (tke\_itide\_lay + tke\_niku\_lay + tke\_lowmode\_lay > (max\_tke(i,k))) \textcolor{keywordflow}{then}
1249         frac\_used = (max\_tke(i,k)) / (tke\_itide\_lay + tke\_niku\_lay + tke\_lowmode\_lay)
1250         tke\_itide\_lay   = frac\_used * tke\_itide\_lay
1251         tke\_niku\_lay    = frac\_used * tke\_niku\_lay
1252         tke\_lowmode\_lay = frac\_used * tke\_lowmode\_lay
1253 \textcolor{keywordflow}{      endif}
1254 
1255       \textcolor{comment}{! Calculate vertical flux available to bottom of layer above}
1256       tke\_itidal\_rem(i)  = tke\_itidal\_rem(i)  - tke\_itide\_lay
1257       tke\_niku\_rem(i)    = tke\_niku\_rem(i)    - tke\_niku\_lay
1258       tke\_lowmode\_rem(i) = tke\_lowmode\_rem(i) - tke\_lowmode\_lay
1259 
1260       \textcolor{comment}{! Convert power to diffusivity}
1261       kd\_add  = tke\_to\_kd(i,k) * (tke\_itide\_lay + tke\_niku\_lay + tke\_lowmode\_lay)
1262 
1263       \textcolor{keywordflow}{if} (kd\_max >= 0.0) kd\_add = min(kd\_add, kd\_max)
1264       \textcolor{keywordflow}{if} (\textcolor{keyword}{present}(kd\_lay)) \textcolor{keywordflow}{then}
1265         kd\_lay(i,k) = kd\_lay(i,k) + kd\_add
1266 \textcolor{keywordflow}{      endif}
1267 
1268       \textcolor{keywordflow}{if} (\textcolor{keyword}{present}(kd\_int)) \textcolor{keywordflow}{then}
1269         kd\_int(i,k)   = kd\_int(i,k)   + 0.5 * kd\_add
1270         kd\_int(i,k+1) = kd\_int(i,k+1) + 0.5 * kd\_add
1271 \textcolor{keywordflow}{      endif}
1272 
1273       \textcolor{comment}{! diagnostics}
1274       \textcolor{keywordflow}{if} (\textcolor{keyword}{associated}(dd%Kd\_itidal)) \textcolor{keywordflow}{then}
1275         \textcolor{comment}{! If at layers, dd%Kd\_itidal is just TKE\_to\_Kd(i,k) * TKE\_itide\_lay}
1276         \textcolor{comment}{! The following sets the interface diagnostics.}
1277         kd\_add = tke\_to\_kd(i,k) * tke\_itide\_lay
1278         \textcolor{keywordflow}{if} (kd\_max >= 0.0) kd\_add = min(kd\_add, kd\_max)
1279         \textcolor{keywordflow}{if} (k>1)  dd%Kd\_itidal(i,j,k)   = dd%Kd\_itidal(i,j,k)   + 0.5*kd\_add
1280         \textcolor{keywordflow}{if} (k<nz) dd%Kd\_itidal(i,j,k+1) = dd%Kd\_itidal(i,j,k+1) + 0.5*kd\_add
1281 \textcolor{keywordflow}{      endif}
1282       \textcolor{keywordflow}{if} (\textcolor{keyword}{associated}(dd%Kd\_Itidal\_work)) &
1283         dd%Kd\_itidal\_work(i,j,k) = gv%Rho0 * tke\_itide\_lay
1284       \textcolor{keywordflow}{if} (\textcolor{keyword}{associated}(dd%Fl\_itidal)) dd%Fl\_itidal(i,j,k) = tke\_itidal\_rem(i)
1285 
1286       \textcolor{keywordflow}{if} (\textcolor{keyword}{associated}(dd%Kd\_Niku)) \textcolor{keywordflow}{then}
1287         \textcolor{comment}{! If at layers, dd%Kd\_Niku(i,j,K) is just TKE\_to\_Kd(i,k) * TKE\_Niku\_lay}
1288         \textcolor{comment}{! The following sets the interface diagnostics.}
1289         kd\_add = tke\_to\_kd(i,k) * tke\_niku\_lay
1290         \textcolor{keywordflow}{if} (kd\_max >= 0.0) kd\_add = min(kd\_add, kd\_max)
1291         \textcolor{keywordflow}{if} (k>1) dd%Kd\_Niku(i,j,k)    = dd%Kd\_Niku(i,j,k)   + 0.5*kd\_add
1292         \textcolor{keywordflow}{if} (k<nz) dd%Kd\_Niku(i,j,k+1) = dd%Kd\_Niku(i,j,k+1) + 0.5*kd\_add
1293 \textcolor{keywordflow}{      endif}
1294 \textcolor{comment}{!     if (associated(dd%Kd\_Niku)) dd%Kd\_Niku(i,j,K) = TKE\_to\_Kd(i,k) * TKE\_Niku\_lay}
1295       \textcolor{keywordflow}{if} (\textcolor{keyword}{associated}(dd%Kd\_Niku\_work)) &
1296         dd%Kd\_Niku\_work(i,j,k) = gv%Rho0 * tke\_niku\_lay
1297 
1298       \textcolor{keywordflow}{if} (\textcolor{keyword}{associated}(dd%Kd\_lowmode)) \textcolor{keywordflow}{then}
1299         \textcolor{comment}{! If at layers, dd%Kd\_lowmode is just TKE\_to\_Kd(i,k) * TKE\_lowmode\_lay}
1300         \textcolor{comment}{! The following sets the interface diagnostics.}
1301         kd\_add = tke\_to\_kd(i,k) * tke\_lowmode\_lay
1302         \textcolor{keywordflow}{if} (kd\_max >= 0.0) kd\_add = min(kd\_add, kd\_max)
1303         \textcolor{keywordflow}{if} (k>1)  dd%Kd\_lowmode(i,j,k)   = dd%Kd\_lowmode(i,j,k)   + 0.5*kd\_add
1304         \textcolor{keywordflow}{if} (k<nz) dd%Kd\_lowmode(i,j,k+1) = dd%Kd\_lowmode(i,j,k+1) + 0.5*kd\_add
1305 \textcolor{keywordflow}{      endif}
1306       \textcolor{keywordflow}{if} (\textcolor{keyword}{associated}(dd%Kd\_lowmode\_work)) &
1307         dd%Kd\_lowmode\_work(i,j,k) = gv%Rho0 * tke\_lowmode\_lay
1308       \textcolor{keywordflow}{if} (\textcolor{keyword}{associated}(dd%Fl\_lowmode)) dd%Fl\_lowmode(i,j,k) = tke\_lowmode\_rem(i)
1309 
1310 \textcolor{keywordflow}{    enddo} ;\textcolor{keywordflow}{ enddo}
1311 \textcolor{keywordflow}{  endif} \textcolor{comment}{! Simmons}
1312 
1313   \textcolor{comment}{! Polzin:}
1314   \textcolor{keywordflow}{if} ( use\_polzin ) \textcolor{keywordflow}{then}
1315     \textcolor{keywordflow}{do} k=nz-1,2,-1 ; \textcolor{keywordflow}{do} i=is,ie
1316       \textcolor{keywordflow}{if} (max\_tke(i,k) <= 0.0) cycle
1317       z\_from\_bot(i) = z\_from\_bot(i) + gv%H\_to\_Z*h(i,j,k)
1318       \textcolor{keywordflow}{if} (cs%answers\_2018) \textcolor{keywordflow}{then}
1319         \textcolor{keywordflow}{if} (n2\_meanz(i) > 1.0e-14*us%T\_to\_s**2 ) \textcolor{keywordflow}{then}
1320           z\_from\_bot\_wkb(i) = z\_from\_bot\_wkb(i) &
1321               + gv%H\_to\_Z * h(i,j,k) * n2\_lay(i,k) / n2\_meanz(i)
1322         \textcolor{keywordflow}{else} ; z\_from\_bot\_wkb(i) = 0 ;\textcolor{keywordflow}{ endif}
1323       \textcolor{keywordflow}{else}
1324         \textcolor{keywordflow}{if} (gv%H\_to\_Z*h(i,j,k) * n2\_lay(i,k) < (1.0e14 * htot\_wkb(i)) * n2\_meanz(i)) \textcolor{keywordflow}{then}
1325           z\_from\_bot\_wkb(i) = z\_from\_bot\_wkb(i) + &
1326              gv%H\_to\_Z*h(i,j,k) * n2\_lay(i,k) / n2\_meanz(i)
1327 \textcolor{keywordflow}{        endif}
1328 \textcolor{keywordflow}{      endif}
1329 
1330       \textcolor{comment}{! Fraction of bottom flux predicted to reach top of this layer}
1331       tke\_frac\_top(i)     = ( inv\_int(i) * z0\_polzin\_scaled(i) ) / &
1332                             ( z0\_polzin\_scaled(i) + z\_from\_bot\_wkb(i) )
1333       z0\_psl = z0\_polzin\_scaled(i)*cs%Decay\_scale\_factor\_lee
1334       tke\_frac\_top\_lee(i) = (inv\_int\_lee(i) * z0\_psl) / (z0\_psl + z\_from\_bot\_wkb(i))
1335       tke\_frac\_top\_lowmode(i) = ( inv\_int\_low(i) * z0\_polzin\_scaled(i) ) / &
1336                             ( z0\_polzin\_scaled(i) + z\_from\_bot\_wkb(i) )
1337 
1338       \textcolor{comment}{! Actual influx at bottom of layer minus predicted outflux at top of layer to give}
1339       \textcolor{comment}{! predicted power expended}
1340       tke\_itide\_lay   = tke\_itidal\_rem(i)  - tke\_itidal\_bot(i) *tke\_frac\_top(i)
1341       tke\_niku\_lay    = tke\_niku\_rem(i)    - tke\_niku\_bot(i)   * tke\_frac\_top\_lee(i)
1342       tke\_lowmode\_lay = tke\_lowmode\_rem(i) - tke\_lowmode\_bot(i)*tke\_frac\_top\_lowmode(i)
1343 
1344       \textcolor{comment}{! Actual power expended may be less than predicted if stratification is weak; adjust}
1345       \textcolor{keywordflow}{if} (tke\_itide\_lay + tke\_niku\_lay + tke\_lowmode\_lay > (max\_tke(i,k))) \textcolor{keywordflow}{then}
1346         frac\_used = (max\_tke(i,k)) / (tke\_itide\_lay + tke\_niku\_lay + tke\_lowmode\_lay)
1347         tke\_itide\_lay   = frac\_used * tke\_itide\_lay
1348         tke\_niku\_lay    = frac\_used * tke\_niku\_lay
1349         tke\_lowmode\_lay = frac\_used * tke\_lowmode\_lay
1350 \textcolor{keywordflow}{      endif}
1351 
1352       \textcolor{comment}{! Calculate vertical flux available to bottom of layer above}
1353       tke\_itidal\_rem(i)  = tke\_itidal\_rem(i)  - tke\_itide\_lay
1354       tke\_niku\_rem(i)    = tke\_niku\_rem(i)    - tke\_niku\_lay
1355       tke\_lowmode\_rem(i) = tke\_lowmode\_rem(i) - tke\_lowmode\_lay
1356 
1357       \textcolor{comment}{! Convert power to diffusivity}
1358       kd\_add  = tke\_to\_kd(i,k) * (tke\_itide\_lay + tke\_niku\_lay + tke\_lowmode\_lay)
1359 
1360       \textcolor{keywordflow}{if} (kd\_max >= 0.0) kd\_add = min(kd\_add, kd\_max)
1361       \textcolor{keywordflow}{if} (\textcolor{keyword}{present}(kd\_lay)) \textcolor{keywordflow}{then}
1362         kd\_lay(i,k) = kd\_lay(i,k) + kd\_add
1363 \textcolor{keywordflow}{      endif}
1364 
1365       \textcolor{keywordflow}{if} (\textcolor{keyword}{present}(kd\_int)) \textcolor{keywordflow}{then}
1366         kd\_int(i,k)   = kd\_int(i,k)   + 0.5 * kd\_add
1367         kd\_int(i,k+1) = kd\_int(i,k+1) + 0.5 * kd\_add
1368 \textcolor{keywordflow}{      endif}
1369 
1370       \textcolor{comment}{! diagnostics}
1371       \textcolor{keywordflow}{if} (\textcolor{keyword}{associated}(dd%Kd\_itidal)) \textcolor{keywordflow}{then}
1372         \textcolor{comment}{! If at layers, this is just dd%Kd\_itidal(i,j,K) = TKE\_to\_Kd(i,k) * TKE\_itide\_lay}
1373         \textcolor{comment}{! The following sets the interface diagnostics.}
1374         kd\_add = tke\_to\_kd(i,k) * tke\_itide\_lay
1375         \textcolor{keywordflow}{if} (kd\_max >= 0.0) kd\_add = min(kd\_add, kd\_max)
1376         \textcolor{keywordflow}{if} (k>1)  dd%Kd\_itidal(i,j,k)   = dd%Kd\_itidal(i,j,k)   + 0.5*kd\_add
1377         \textcolor{keywordflow}{if} (k<nz) dd%Kd\_itidal(i,j,k+1) = dd%Kd\_itidal(i,j,k+1) + 0.5*kd\_add
1378 \textcolor{keywordflow}{      endif}
1379       \textcolor{keywordflow}{if} (\textcolor{keyword}{associated}(dd%Kd\_Itidal\_work)) &
1380         dd%Kd\_itidal\_work(i,j,k) = gv%Rho0 * tke\_itide\_lay
1381       \textcolor{keywordflow}{if} (\textcolor{keyword}{associated}(dd%Fl\_itidal)) dd%Fl\_itidal(i,j,k) = tke\_itidal\_rem(i)
1382 
1383       \textcolor{keywordflow}{if} (\textcolor{keyword}{associated}(dd%Kd\_Niku)) \textcolor{keywordflow}{then}
1384         \textcolor{comment}{! If at layers, this is just dd%Kd\_Niku(i,j,K) = TKE\_to\_Kd(i,k) * TKE\_Niku\_lay}
1385         \textcolor{comment}{! The following sets the interface diagnostics.}
1386         kd\_add = tke\_to\_kd(i,k) * tke\_niku\_lay
1387         \textcolor{keywordflow}{if} (kd\_max >= 0.0) kd\_add = min(kd\_add, kd\_max)
1388         \textcolor{keywordflow}{if} (k>1) dd%Kd\_Niku(i,j,k)    = dd%Kd\_Niku(i,j,k)   + 0.5*kd\_add
1389         \textcolor{keywordflow}{if} (k<nz) dd%Kd\_Niku(i,j,k+1) = dd%Kd\_Niku(i,j,k+1) + 0.5*kd\_add
1390 \textcolor{keywordflow}{      endif}
1391    \textcolor{comment}{!  if (associated(dd%Kd\_Niku)) dd%Kd\_Niku(i,j,K) = TKE\_to\_Kd(i,k) * TKE\_Niku\_lay}
1392       \textcolor{keywordflow}{if} (\textcolor{keyword}{associated}(dd%Kd\_Niku\_work)) dd%Kd\_Niku\_work(i,j,k) = gv%Rho0 * tke\_niku\_lay
1393 
1394       \textcolor{keywordflow}{if} (\textcolor{keyword}{associated}(dd%Kd\_lowmode)) \textcolor{keywordflow}{then}
1395         \textcolor{comment}{! If at layers, dd%Kd\_lowmode is just TKE\_to\_Kd(i,k) * TKE\_lowmode\_lay}
1396         \textcolor{comment}{! The following sets the interface diagnostics.}
1397         kd\_add = tke\_to\_kd(i,k) * tke\_lowmode\_lay
1398         \textcolor{keywordflow}{if} (kd\_max >= 0.0) kd\_add = min(kd\_add, kd\_max)
1399         \textcolor{keywordflow}{if} (k>1)  dd%Kd\_lowmode(i,j,k)   = dd%Kd\_lowmode(i,j,k)   + 0.5*kd\_add
1400         \textcolor{keywordflow}{if} (k<nz) dd%Kd\_lowmode(i,j,k+1) = dd%Kd\_lowmode(i,j,k+1) + 0.5*kd\_add
1401 \textcolor{keywordflow}{      endif}
1402       \textcolor{keywordflow}{if} (\textcolor{keyword}{associated}(dd%Kd\_lowmode\_work)) &
1403         dd%Kd\_lowmode\_work(i,j,k) = gv%Rho0 * tke\_lowmode\_lay
1404       \textcolor{keywordflow}{if} (\textcolor{keyword}{associated}(dd%Fl\_lowmode)) dd%Fl\_lowmode(i,j,k) = tke\_lowmode\_rem(i)
1405 
1406 \textcolor{keywordflow}{    enddo} ;\textcolor{keywordflow}{ enddo}
1407 \textcolor{keywordflow}{  endif} \textcolor{comment}{! Polzin}
1408 
\end{DoxyCode}
\mbox{\Hypertarget{namespacemom__tidal__mixing_af9e675f60c60606f767d4bb1321dba2c}\label{namespacemom__tidal__mixing_af9e675f60c60606f767d4bb1321dba2c}} 
\index{mom\+\_\+tidal\+\_\+mixing@{mom\+\_\+tidal\+\_\+mixing}!calculate\+\_\+cvmix\+\_\+tidal@{calculate\+\_\+cvmix\+\_\+tidal}}
\index{calculate\+\_\+cvmix\+\_\+tidal@{calculate\+\_\+cvmix\+\_\+tidal}!mom\+\_\+tidal\+\_\+mixing@{mom\+\_\+tidal\+\_\+mixing}}
\subsubsection{\texorpdfstring{calculate\+\_\+cvmix\+\_\+tidal()}{calculate\_cvmix\_tidal()}}
{\footnotesize\ttfamily subroutine mom\+\_\+tidal\+\_\+mixing\+::calculate\+\_\+cvmix\+\_\+tidal (\begin{DoxyParamCaption}\item[{real, dimension( g \%isd\+: g \%ied, g \%jsd\+: g \%jed, g \%ke), intent(in)}]{h,  }\item[{integer, intent(in)}]{j,  }\item[{type(ocean\+\_\+grid\+\_\+type), intent(in)}]{G,  }\item[{type(verticalgrid\+\_\+type), intent(in)}]{GV,  }\item[{type(unit\+\_\+scale\+\_\+type), intent(in)}]{US,  }\item[{type(\mbox{\hyperlink{structmom__tidal__mixing_1_1tidal__mixing__cs}{tidal\+\_\+mixing\+\_\+cs}}), pointer}]{CS,  }\item[{real, dimension( g \%isd\+: g \%ied, g \%ke+1), intent(in)}]{N2\+\_\+int,  }\item[{real, dimension( g \%isd\+: g \%ied, g \%ke), intent(inout), optional}]{Kd\+\_\+lay,  }\item[{real, dimension( g \%isd\+: g \%ied, g \%ke+1), intent(inout), optional}]{Kd\+\_\+int,  }\item[{real, dimension(\+:,\+:,\+:), pointer}]{Kv }\end{DoxyParamCaption})\hspace{0.3cm}{\ttfamily [private]}}



Calls the C\+V\+Mix routines to compute tidal dissipation and to add the effect of internal-\/tide-\/driven mixing to the interface diffusivities. 


\begin{DoxyParams}[1]{Parameters}
\mbox{\tt in}  & {\em j} & The j-\/index to work on\\
\hline
\mbox{\tt in}  & {\em g} & Grid structure.\\
\hline
\mbox{\tt in}  & {\em gv} & ocean vertical grid structure\\
\hline
\mbox{\tt in}  & {\em us} & A dimensional unit scaling type\\
\hline
 & {\em cs} & This module\textquotesingle{}s control structure.\\
\hline
\mbox{\tt in}  & {\em n2\+\_\+int} & The squared buoyancy frequency at the interfaces \mbox{[}T-\/2 $\sim$$>$ s-\/2\mbox{]}.\\
\hline
\mbox{\tt in}  & {\em h} & Layer thicknesses \mbox{[}H $\sim$$>$ m or kg m-\/2\mbox{]}.\\
\hline
\mbox{\tt in,out}  & {\em kd\+\_\+lay} & The diapycnal diffusivity in the layers \mbox{[}Z2 T-\/1 $\sim$$>$ m2 s-\/1\mbox{]}.\\
\hline
\mbox{\tt in,out}  & {\em kd\+\_\+int} & The diapycnal diffusivity at interfaces \mbox{[}Z2 T-\/1 $\sim$$>$ m2 s-\/1\mbox{]}.\\
\hline
 & {\em kv} & The \char`\"{}slow\char`\"{} vertical viscosity at each interface (not layer!) \mbox{[}Z2 T-\/1 $\sim$$>$ m2 s-\/1\mbox{]}. \\
\hline
\end{DoxyParams}


Definition at line 718 of file M\+O\+M\+\_\+tidal\+\_\+mixing.\+F90.


\begin{DoxyCode}
718   \textcolor{keywordtype}{integer},                 \textcolor{keywordtype}{intent(in)}    :: j\textcolor{comment}{     !< The j-index to work on}
719   \textcolor{keywordtype}{type}(ocean\_grid\_type),   \textcolor{keywordtype}{intent(in)}    :: G\textcolor{comment}{     !< Grid structure.}
720   \textcolor{keywordtype}{type}(verticalGrid\_type), \textcolor{keywordtype}{intent(in)}    :: GV\textcolor{comment}{    !< ocean vertical grid structure}
721   \textcolor{keywordtype}{type}(unit\_scale\_type),   \textcolor{keywordtype}{intent(in)}    :: US\textcolor{comment}{    !< A dimensional unit scaling type}
722   \textcolor{keywordtype}{type}(tidal\_mixing\_cs),   \textcolor{keywordtype}{pointer}       :: CS\textcolor{comment}{    !< This module's control structure.}
723   \textcolor{keywordtype}{real}, \textcolor{keywordtype}{dimension(SZI\_(G),SZK\_(G)+1)}, \textcolor{keywordtype}{intent(in)} :: N2\_int\textcolor{comment}{ !< The squared buoyancy}
724 \textcolor{comment}{                                                  !! frequency at the interfaces [T-2 ~> s-2].}
725   \textcolor{keywordtype}{real}, \textcolor{keywordtype}{dimension(SZI\_(G),SZJ\_(G),SZK\_(G))}, &
726                            \textcolor{keywordtype}{intent(in)}    :: h\textcolor{comment}{     !< Layer thicknesses [H ~> m or kg m-2].}
727   \textcolor{keywordtype}{real}, \textcolor{keywordtype}{dimension(SZI\_(G),SZK\_(G))}, &
728                  \textcolor{keywordtype}{optional}, \textcolor{keywordtype}{intent(inout)} :: Kd\_lay\textcolor{comment}{!< The diapycnal diffusivity in the layers [Z2 T-1 ~> m2
       s-1].}
729   \textcolor{keywordtype}{real}, \textcolor{keywordtype}{dimension(SZI\_(G),SZK\_(G)+1)}, &
730                  \textcolor{keywordtype}{optional}, \textcolor{keywordtype}{intent(inout)} :: Kd\_int\textcolor{comment}{!< The diapycnal diffusivity at interfaces [Z2 T-1 ~> m2
       s-1].}
731   \textcolor{keywordtype}{real}, \textcolor{keywordtype}{dimension(:,:,:)},  \textcolor{keywordtype}{pointer}       :: Kv\textcolor{comment}{    !< The "slow" vertical viscosity at each interface}
732 \textcolor{comment}{                                                  !! (not layer!) [Z2 T-1 ~> m2 s-1].}
733   \textcolor{comment}{! Local variables}
734   \textcolor{keywordtype}{real}, \textcolor{keywordtype}{dimension(SZK\_(G)+1)} :: Kd\_tidal    \textcolor{comment}{! tidal diffusivity [m2 s-1]}
735   \textcolor{keywordtype}{real}, \textcolor{keywordtype}{dimension(SZK\_(G)+1)} :: Kv\_tidal    \textcolor{comment}{! tidal viscosity [m2 s-1]}
736   \textcolor{keywordtype}{real}, \textcolor{keywordtype}{dimension(SZK\_(G)+1)} :: vert\_dep    \textcolor{comment}{! vertical deposition}
737   \textcolor{keywordtype}{real}, \textcolor{keywordtype}{dimension(SZK\_(G)+1)} :: iFaceHeight \textcolor{comment}{! Height of interfaces [m]}
738   \textcolor{keywordtype}{real}, \textcolor{keywordtype}{dimension(SZK\_(G)+1)} :: SchmittnerSocn
739   \textcolor{keywordtype}{real}, \textcolor{keywordtype}{dimension(SZK\_(G))}   :: cellHeight  \textcolor{comment}{! Height of cell centers [m]}
740   \textcolor{keywordtype}{real}, \textcolor{keywordtype}{dimension(SZK\_(G))}   :: tidal\_qe\_md \textcolor{comment}{! Tidal dissipation energy interpolated from 3d input}
741                                             \textcolor{comment}{! to model coordinates}
742   \textcolor{keywordtype}{real}, \textcolor{keywordtype}{dimension(SZK\_(G)+1)} :: N2\_int\_i    \textcolor{comment}{! De-scaled interface buoyancy frequency [s-2]}
743   \textcolor{keywordtype}{real}, \textcolor{keywordtype}{dimension(SZK\_(G))}   :: Schmittner\_coeff
744   \textcolor{keywordtype}{real}, \textcolor{keywordtype}{dimension(SZK\_(G))}   :: h\_m         \textcolor{comment}{! Cell thickness [m]}
745   \textcolor{keywordtype}{real}, \textcolor{keywordtype}{allocatable}, \textcolor{keywordtype}{dimension(:,:)} :: exp\_hab\_zetar
746 
747   \textcolor{keywordtype}{integer} :: i, k, is, ie
748   \textcolor{keywordtype}{real} :: dh, hcorr, Simmons\_coeff
749   \textcolor{keywordtype}{real}, \textcolor{keywordtype}{parameter} :: rho\_fw = 1000.0 \textcolor{comment}{! fresh water density [kg/m^3]}
750                                      \textcolor{comment}{! TODO: when coupled, get this from CESM (SHR\_CONST\_RHOFW)}
751   \textcolor{keywordtype}{type}(tidal\_mixing\_diags), \textcolor{keywordtype}{pointer} :: dd => null()
752 
753   is  = g%isc ; ie  = g%iec
754   dd => cs%dd
755 
756   \textcolor{keywordflow}{select case} (cs%CVMix\_tidal\_scheme)
757   \textcolor{keywordflow}{case} (simmons)
758     \textcolor{keywordflow}{do} i=is,ie
759 
760       \textcolor{keywordflow}{if} (g%mask2dT(i,j)<1) cycle
761 
762       ifaceheight = 0.0 \textcolor{comment}{! BBL is all relative to the surface}
763       hcorr = 0.0
764       \textcolor{keywordflow}{do} k=1,g%ke
765         \textcolor{comment}{! cell center and cell bottom in meters (negative values in the ocean)}
766         dh = h(i,j,k) * gv%H\_to\_m \textcolor{comment}{! Nominal thickness to use for increment, rescaled to m for use by CVMix.}
767         dh = dh + hcorr \textcolor{comment}{! Take away the accumulated error (could temporarily make dh<0)}
768         hcorr = min( dh - cs%min\_thickness, 0. ) \textcolor{comment}{! If inflating then hcorr<0}
769         dh = max( dh, cs%min\_thickness ) \textcolor{comment}{! Limit increment dh>=min\_thickness}
770         cellheight(k)    = ifaceheight(k) - 0.5 * dh
771         ifaceheight(k+1) = ifaceheight(k) - dh
772 \textcolor{keywordflow}{      enddo}
773 
774       \textcolor{keyword}{call }cvmix\_compute\_simmons\_invariant( nlev                    = g%ke,                &
775                                             energy\_flux             = cs%tidal\_qe\_2d(i,j), &
776                                             rho                     = rho\_fw,              &
777                                             simmonscoeff            = simmons\_coeff,       &
778                                             vertdep                 = vert\_dep,            &
779                                             zw                      = ifaceheight,         &
780                                             zt                      = cellheight,          &
781                                             cvmix\_tidal\_params\_user = cs%CVMix\_tidal\_params)
782 
783       \textcolor{comment}{! Since we pass tidal\_qe\_2d=(CS%Gamma\_itides)*tidal\_energy\_flux\_2d, and not tidal\_energy\_flux\_2d in}
784       \textcolor{comment}{! above subroutine call, we divide Simmons\_coeff by CS%Gamma\_itides as a corrective step:}
785       \textcolor{comment}{! TODO: (CS%Gamma\_itides)*tidal\_energy\_flux\_2d is unnecessary, directly use tidal\_energy\_flux\_2d}
786       simmons\_coeff = simmons\_coeff / cs%Gamma\_itides
787 
788 
789       \textcolor{comment}{! XXX: Temporary de-scaling of N2\_int(i,:) into a temporary variable}
790       \textcolor{keywordflow}{do} k=1,g%ke+1
791         n2\_int\_i(k) = us%s\_to\_T**2 * n2\_int(i,k)
792 \textcolor{keywordflow}{      enddo}
793 
794       \textcolor{keyword}{call }cvmix\_coeffs\_tidal( mdiff\_out               = kv\_tidal,            &
795                                tdiff\_out               = kd\_tidal,            &
796                                nsqr                    = n2\_int\_i,            &
797                                oceandepth              = -ifaceheight(g%ke+1),&
798                                simmonscoeff            = simmons\_coeff,       &
799                                vert\_dep                = vert\_dep,            &
800                                nlev                    = g%ke,                &
801                                max\_nlev                = g%ke,                &
802                                cvmix\_params            = cs%CVMix\_glb\_params, &
803                                cvmix\_tidal\_params\_user = cs%CVMix\_tidal\_params)
804 
805       \textcolor{comment}{! Update diffusivity}
806       \textcolor{keywordflow}{if} (\textcolor{keyword}{present}(kd\_lay)) \textcolor{keywordflow}{then}
807         \textcolor{keywordflow}{do} k=1,g%ke
808           kd\_lay(i,k) = kd\_lay(i,k) + 0.5 * us%m2\_s\_to\_Z2\_T * (kd\_tidal(k) + kd\_tidal(k+1))
809 \textcolor{keywordflow}{        enddo}
810 \textcolor{keywordflow}{      endif}
811       \textcolor{keywordflow}{if} (\textcolor{keyword}{present}(kd\_int)) \textcolor{keywordflow}{then}
812         \textcolor{keywordflow}{do} k=1,g%ke+1
813           kd\_int(i,k) = kd\_int(i,k) +  (us%m2\_s\_to\_Z2\_T * kd\_tidal(k))
814 \textcolor{keywordflow}{        enddo}
815 \textcolor{keywordflow}{      endif}
816       \textcolor{comment}{! Update viscosity with the proper unit conversion.}
817       \textcolor{keywordflow}{if} (\textcolor{keyword}{associated}(kv)) \textcolor{keywordflow}{then}
818         \textcolor{keywordflow}{do} k=1,g%ke+1
819           kv(i,j,k) = kv(i,j,k) + us%m2\_s\_to\_Z2\_T * kv\_tidal(k)  \textcolor{comment}{! Rescale from m2 s-1 to Z2 T-1.}
820 \textcolor{keywordflow}{        enddo}
821 \textcolor{keywordflow}{      endif}
822 
823       \textcolor{comment}{! diagnostics}
824       \textcolor{keywordflow}{if} (\textcolor{keyword}{associated}(dd%Kd\_itidal)) \textcolor{keywordflow}{then}
825         dd%Kd\_itidal(i,j,:) = us%m2\_s\_to\_Z2\_T*kd\_tidal(:)
826 \textcolor{keywordflow}{      endif}
827       \textcolor{keywordflow}{if} (\textcolor{keyword}{associated}(dd%N2\_int)) \textcolor{keywordflow}{then}
828         dd%N2\_int(i,j,:) = n2\_int(i,:)
829 \textcolor{keywordflow}{      endif}
830       \textcolor{keywordflow}{if} (\textcolor{keyword}{associated}(dd%Simmons\_coeff\_2d)) \textcolor{keywordflow}{then}
831         dd%Simmons\_coeff\_2d(i,j) = simmons\_coeff
832 \textcolor{keywordflow}{      endif}
833       \textcolor{keywordflow}{if} (\textcolor{keyword}{associated}(dd%vert\_dep\_3d)) \textcolor{keywordflow}{then}
834         dd%vert\_dep\_3d(i,j,:) = vert\_dep(:)
835 \textcolor{keywordflow}{      endif}
836 
837 \textcolor{keywordflow}{    enddo} \textcolor{comment}{! i=is,ie}
838 
839   \textcolor{keywordflow}{case} (schmittner)
840 
841     \textcolor{comment}{! TODO: correct exp\_hab\_zetar shapes in CVMix\_compute\_Schmittner\_invariant}
842     \textcolor{comment}{! and CVMix\_compute\_SchmittnerCoeff low subroutines}
843 
844     \textcolor{keyword}{allocate}(exp\_hab\_zetar(g%ke+1,g%ke+1))
845 
846     \textcolor{keywordflow}{do} i=is,ie
847 
848       \textcolor{keywordflow}{if} (g%mask2dT(i,j)<1) cycle
849 
850       ifaceheight = 0.0 \textcolor{comment}{! BBL is all relative to the surface}
851       hcorr = 0.0
852       \textcolor{keywordflow}{do} k=1,g%ke
853         h\_m(k) = h(i,j,k)*gv%H\_to\_m  \textcolor{comment}{! Rescale thicknesses to m for use by CVmix.}
854         \textcolor{comment}{! cell center and cell bottom in meters (negative values in the ocean)}
855         dh = h\_m(k) + hcorr \textcolor{comment}{! Nominal thickness less the accumulated error (could temporarily make dh<0)}
856         hcorr = min( dh - cs%min\_thickness, 0. ) \textcolor{comment}{! If inflating then hcorr<0}
857         dh = max( dh, cs%min\_thickness ) \textcolor{comment}{! Limit increment dh>=min\_thickness}
858         cellheight(k)    = ifaceheight(k) - 0.5 * dh
859         ifaceheight(k+1) = ifaceheight(k) - dh
860 \textcolor{keywordflow}{      enddo}
861 
862       schmittnersocn = 0.0 \textcolor{comment}{! TODO: compute this}
863 
864       \textcolor{comment}{! form the time-invariant part of Schmittner coefficient term}
865       \textcolor{keyword}{call }cvmix\_compute\_schmittner\_invariant(nlev                    = g%ke,           &
866                                               vertdep                 = vert\_dep,       &
867                                               efficiency              = cs%Mu\_itides,   &
868                                               rho                     = rho\_fw,         &
869                                               exp\_hab\_zetar           = exp\_hab\_zetar,  &
870                                               zw                      = ifaceheight,    &
871                                               cvmix\_tidal\_params\_user = cs%CVMix\_tidal\_params)
872                   \textcolor{comment}{!TODO: in above call, there is no need to pass efficiency, since it gets}
873                   \textcolor{comment}{! passed via CVMix\_init\_tidal and stored in CVMix\_tidal\_params. Change}
874                   \textcolor{comment}{! CVMix API to prevent this redundancy.}
875 
876       \textcolor{comment}{! remap from input z coordinate to model coordinate:}
877       tidal\_qe\_md = 0.0
878       \textcolor{keyword}{call }remapping\_core\_h(cs%remap\_cs, \textcolor{keyword}{size}(cs%h\_src), cs%h\_src, cs%tidal\_qe\_3d\_in(i,j,:), &
879                             g%ke, h\_m, tidal\_qe\_md)
880 
881       \textcolor{comment}{! form the Schmittner coefficient that is based on 3D q*E, which is formed from}
882       \textcolor{comment}{! summing q\_i*TidalConstituent\_i over the number of constituents.}
883       \textcolor{keyword}{call }cvmix\_compute\_schmittnercoeff( nlev                    = g%ke,               &
884                                           energy\_flux             = tidal\_qe\_md(:),     &
885                                           rho                     = rho\_fw,             &
886                                           schmittnercoeff         = schmittner\_coeff,   &
887                                           exp\_hab\_zetar           = exp\_hab\_zetar,      &
888                                           cvmix\_tidal\_params\_user = cs%CVMix\_tidal\_params)
889 
890       \textcolor{comment}{! XXX: Temporary de-scaling of N2\_int(i,:) into a temporary variable}
891       \textcolor{keywordflow}{do} k=1,g%ke+1
892         n2\_int\_i(k) = us%s\_to\_T**2 * n2\_int(i,k)
893 \textcolor{keywordflow}{      enddo}
894 
895       \textcolor{keyword}{call }cvmix\_coeffs\_tidal\_schmittner( mdiff\_out               = kv\_tidal,             &
896                                           tdiff\_out               = kd\_tidal,             &
897                                           nsqr                    = n2\_int\_i,             &
898                                           oceandepth              = -ifaceheight(g%ke+1), &
899                                           vert\_dep                = vert\_dep,             &
900                                           nlev                    = g%ke,                 &
901                                           max\_nlev                = g%ke,                 &
902                                           schmittnercoeff         = schmittner\_coeff,     &
903                                           schmittnersouthernocean = schmittnersocn,       &
904                                           cvmix\_params            = cs%CVMix\_glb\_params,  &
905                                           cvmix\_tidal\_params\_user = cs%CVMix\_tidal\_params)
906 
907       \textcolor{comment}{! Update diffusivity}
908       \textcolor{keywordflow}{if} (\textcolor{keyword}{present}(kd\_lay)) \textcolor{keywordflow}{then}
909         \textcolor{keywordflow}{do} k=1,g%ke
910           kd\_lay(i,k) = kd\_lay(i,k) + 0.5 * us%m2\_s\_to\_Z2\_T * (kd\_tidal(k) + kd\_tidal(k+1))
911 \textcolor{keywordflow}{        enddo}
912 \textcolor{keywordflow}{      endif}
913       \textcolor{keywordflow}{if} (\textcolor{keyword}{present}(kd\_int)) \textcolor{keywordflow}{then}
914         \textcolor{keywordflow}{do} k=1,g%ke+1
915           kd\_int(i,k) = kd\_int(i,k) +  (us%m2\_s\_to\_Z2\_T * kd\_tidal(k))
916 \textcolor{keywordflow}{        enddo}
917 \textcolor{keywordflow}{      endif}
918 
919       \textcolor{comment}{! Update viscosity}
920       \textcolor{keywordflow}{if} (\textcolor{keyword}{associated}(kv)) \textcolor{keywordflow}{then}
921         \textcolor{keywordflow}{do} k=1,g%ke+1
922           kv(i,j,k) = kv(i,j,k) + us%m2\_s\_to\_Z2\_T * kv\_tidal(k)   \textcolor{comment}{! Rescale from m2 s-1 to Z2 T-1.}
923 \textcolor{keywordflow}{        enddo}
924 \textcolor{keywordflow}{      endif}
925 
926       \textcolor{comment}{! diagnostics}
927       \textcolor{keywordflow}{if} (\textcolor{keyword}{associated}(dd%Kd\_itidal)) \textcolor{keywordflow}{then}
928         dd%Kd\_itidal(i,j,:) = us%m2\_s\_to\_Z2\_T*kd\_tidal(:)
929 \textcolor{keywordflow}{      endif}
930       \textcolor{keywordflow}{if} (\textcolor{keyword}{associated}(dd%N2\_int)) \textcolor{keywordflow}{then}
931         dd%N2\_int(i,j,:) = n2\_int(i,:)
932 \textcolor{keywordflow}{      endif}
933       \textcolor{keywordflow}{if} (\textcolor{keyword}{associated}(dd%Schmittner\_coeff\_3d)) \textcolor{keywordflow}{then}
934         dd%Schmittner\_coeff\_3d(i,j,:) = schmittner\_coeff(:)
935 \textcolor{keywordflow}{      endif}
936       \textcolor{keywordflow}{if} (\textcolor{keyword}{associated}(dd%tidal\_qe\_md)) \textcolor{keywordflow}{then}
937         dd%tidal\_qe\_md(i,j,:) = tidal\_qe\_md(:)
938 \textcolor{keywordflow}{      endif}
939       \textcolor{keywordflow}{if} (\textcolor{keyword}{associated}(dd%vert\_dep\_3d)) \textcolor{keywordflow}{then}
940         dd%vert\_dep\_3d(i,j,:) = vert\_dep(:)
941 \textcolor{keywordflow}{      endif}
942 \textcolor{keywordflow}{    enddo} \textcolor{comment}{! i=is,ie}
943 
944     \textcolor{keyword}{deallocate}(exp\_hab\_zetar)
945 
946 \textcolor{keywordflow}{  case default}
947      \textcolor{keyword}{call }mom\_error(fatal, \textcolor{stringliteral}{"tidal\_mixing\_init: Unrecognized setting "}// &
948          \textcolor{stringliteral}{"#define CVMIX\_TIDAL\_SCHEME found in input file."})
949 \textcolor{keywordflow}{  end select}
950 
\end{DoxyCode}
\mbox{\Hypertarget{namespacemom__tidal__mixing_abf084268fd9c71f20880838d2bce7e3e}\label{namespacemom__tidal__mixing_abf084268fd9c71f20880838d2bce7e3e}} 
\index{mom\+\_\+tidal\+\_\+mixing@{mom\+\_\+tidal\+\_\+mixing}!calculate\+\_\+tidal\+\_\+mixing@{calculate\+\_\+tidal\+\_\+mixing}}
\index{calculate\+\_\+tidal\+\_\+mixing@{calculate\+\_\+tidal\+\_\+mixing}!mom\+\_\+tidal\+\_\+mixing@{mom\+\_\+tidal\+\_\+mixing}}
\subsubsection{\texorpdfstring{calculate\+\_\+tidal\+\_\+mixing()}{calculate\_tidal\_mixing()}}
{\footnotesize\ttfamily subroutine, public mom\+\_\+tidal\+\_\+mixing\+::calculate\+\_\+tidal\+\_\+mixing (\begin{DoxyParamCaption}\item[{real, dimension(szi\+\_\+(g),szj\+\_\+(g),szk\+\_\+(g)), intent(in)}]{h,  }\item[{real, dimension(szi\+\_\+(g)), intent(in)}]{N2\+\_\+bot,  }\item[{integer, intent(in)}]{j,  }\item[{real, dimension(szi\+\_\+(g),szk\+\_\+(g)), intent(in)}]{T\+K\+E\+\_\+to\+\_\+\+Kd,  }\item[{real, dimension(szi\+\_\+(g),szk\+\_\+(g)), intent(in)}]{max\+\_\+\+T\+KE,  }\item[{type(ocean\+\_\+grid\+\_\+type), intent(in)}]{G,  }\item[{type(verticalgrid\+\_\+type), intent(in)}]{GV,  }\item[{type(unit\+\_\+scale\+\_\+type), intent(in)}]{US,  }\item[{type(\mbox{\hyperlink{structmom__tidal__mixing_1_1tidal__mixing__cs}{tidal\+\_\+mixing\+\_\+cs}}), pointer}]{CS,  }\item[{real, dimension(szi\+\_\+(g),szk\+\_\+(g)), intent(in)}]{N2\+\_\+lay,  }\item[{real, dimension(szi\+\_\+(g),szk\+\_\+(g)+1), intent(in)}]{N2\+\_\+int,  }\item[{real, dimension(szi\+\_\+(g),szk\+\_\+(g)), intent(inout), optional}]{Kd\+\_\+lay,  }\item[{real, dimension(szi\+\_\+(g),szk\+\_\+(g)+1), intent(inout), optional}]{Kd\+\_\+int,  }\item[{real, intent(in)}]{Kd\+\_\+max,  }\item[{real, dimension(\+:,\+:,\+:), pointer}]{Kv }\end{DoxyParamCaption})}



Depending on whether or not C\+V\+Mix is active, calls the associated subroutine to compute internal tidal dissipation and to add the effect of internal-\/tide-\/driven mixing to the layer or interface diffusivities. 


\begin{DoxyParams}[1]{Parameters}
\mbox{\tt in}  & {\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}  & {\em us} & A dimensional unit scaling type\\
\hline
\mbox{\tt in}  & {\em h} & Layer thicknesses \mbox{[}H $\sim$$>$ m or kg m-\/2\mbox{]}\\
\hline
\mbox{\tt in}  & {\em n2\+\_\+bot} & The near-\/bottom squared buoyancy frequency \mbox{[}T-\/2 $\sim$$>$ s-\/2\mbox{]}.\\
\hline
\mbox{\tt in}  & {\em n2\+\_\+lay} & The squared buoyancy frequency of the layers \mbox{[}T-\/2 $\sim$$>$ s-\/2\mbox{]}.\\
\hline
\mbox{\tt in}  & {\em n2\+\_\+int} & The squared buoyancy frequency at the interfaces \mbox{[}T-\/2 $\sim$$>$ s-\/2\mbox{]}.\\
\hline
\mbox{\tt in}  & {\em j} & The j-\/index to work on\\
\hline
\mbox{\tt in}  & {\em tke\+\_\+to\+\_\+kd} & The conversion rate between the T\+KE dissipated within a layer and the diapycnal diffusivity within that layer, usually ($\sim$\+Rho\+\_\+0 / (G\+\_\+\+Earth $\ast$ d\+Rho\+\_\+lay)) \mbox{[}Z2 T-\/1 / Z3 T-\/3 = T2 Z-\/1 $\sim$$>$ s2 m-\/1\mbox{]}\\
\hline
\mbox{\tt in}  & {\em max\+\_\+tke} & The energy required to for a layer to entrain to its maximum realizable thickness \mbox{[}Z3 T-\/3 $\sim$$>$ m3 s-\/3\mbox{]}\\
\hline
 & {\em cs} & The control structure for this module\\
\hline
\mbox{\tt in,out}  & {\em kd\+\_\+lay} & The diapycnal diffusivity in layers \mbox{[}Z2 T-\/1 $\sim$$>$ m2 s-\/1\mbox{]}.\\
\hline
\mbox{\tt in,out}  & {\em kd\+\_\+int} & The diapycnal diffusivity at interfaces,\\
\hline
\mbox{\tt in}  & {\em kd\+\_\+max} & The maximum increment for diapycnal diffusivity due to T\+K\+E-\/based processes, \mbox{[}Z2 T-\/1 $\sim$$>$ m2 s-\/1\mbox{]}. Set this to a negative value to have no limit.\\
\hline
 & {\em kv} & The \char`\"{}slow\char`\"{} vertical viscosity at each interface (not layer!) \mbox{[}Z2 T-\/1 $\sim$$>$ m2 s-\/1\mbox{]}. \\
\hline
\end{DoxyParams}


Definition at line 672 of file M\+O\+M\+\_\+tidal\+\_\+mixing.\+F90.


\begin{DoxyCode}
672   \textcolor{keywordtype}{type}(ocean\_grid\_type),            \textcolor{keywordtype}{intent(in)}    :: G\textcolor{comment}{      !< The ocean's grid structure}
673   \textcolor{keywordtype}{type}(verticalGrid\_type),          \textcolor{keywordtype}{intent(in)}    :: GV\textcolor{comment}{     !< The ocean's vertical grid structure}
674   \textcolor{keywordtype}{type}(unit\_scale\_type),            \textcolor{keywordtype}{intent(in)}    :: US\textcolor{comment}{     !< A dimensional unit scaling type}
675   \textcolor{keywordtype}{real}, \textcolor{keywordtype}{dimension(SZI\_(G),SZJ\_(G),SZK\_(G))}, &
676                                     \textcolor{keywordtype}{intent(in)}    :: h\textcolor{comment}{      !< Layer thicknesses [H ~> m or kg m-2]}
677   \textcolor{keywordtype}{real}, \textcolor{keywordtype}{dimension(SZI\_(G))},         \textcolor{keywordtype}{intent(in)}    :: N2\_bot\textcolor{comment}{ !< The near-bottom squared buoyancy}
678 \textcolor{comment}{                                                            !! frequency [T-2 ~> s-2].}
679   \textcolor{keywordtype}{real}, \textcolor{keywordtype}{dimension(SZI\_(G),SZK\_(G))}, \textcolor{keywordtype}{intent(in)}    :: N2\_lay\textcolor{comment}{ !< The squared buoyancy frequency of the}
680 \textcolor{comment}{                                                            !! layers [T-2 ~> s-2].}
681   \textcolor{keywordtype}{real}, \textcolor{keywordtype}{dimension(SZI\_(G),SZK\_(G)+1)}, \textcolor{keywordtype}{intent(in)}  :: N2\_int\textcolor{comment}{ !< The squared buoyancy frequency at the}
682 \textcolor{comment}{                                                            !! interfaces [T-2 ~> s-2].}
683   \textcolor{keywordtype}{integer},                          \textcolor{keywordtype}{intent(in)}    :: j\textcolor{comment}{      !< The j-index to work on}
684   \textcolor{keywordtype}{real}, \textcolor{keywordtype}{dimension(SZI\_(G),SZK\_(G))}, \textcolor{keywordtype}{intent(in)}    :: TKE\_to\_Kd\textcolor{comment}{ !< The conversion rate between the TKE}
685 \textcolor{comment}{                                                            !! dissipated within a layer and the}
686 \textcolor{comment}{                                                            !! diapycnal diffusivity within that layer,}
687 \textcolor{comment}{                                                            !! usually (~Rho\_0 / (G\_Earth * dRho\_lay))}
688 \textcolor{comment}{                                                            !! [Z2 T-1 / Z3 T-3 = T2 Z-1 ~> s2 m-1]}
689   \textcolor{keywordtype}{real}, \textcolor{keywordtype}{dimension(SZI\_(G),SZK\_(G))}, \textcolor{keywordtype}{intent(in)}    :: max\_TKE\textcolor{comment}{ !< The energy required to for a layer to
       entrain}
690 \textcolor{comment}{                                                            !! to its maximum realizable thickness [Z3 T-3
       ~> m3 s-3]}
691   \textcolor{keywordtype}{type}(tidal\_mixing\_cs),            \textcolor{keywordtype}{pointer}       :: CS\textcolor{comment}{     !< The control structure for this module}
692   \textcolor{keywordtype}{real}, \textcolor{keywordtype}{dimension(SZI\_(G),SZK\_(G))}, &
693                           \textcolor{keywordtype}{optional}, \textcolor{keywordtype}{intent(inout)} :: Kd\_lay\textcolor{comment}{ !< The diapycnal diffusivity in layers [Z2 T-1
       ~> m2 s-1].}
694   \textcolor{keywordtype}{real}, \textcolor{keywordtype}{dimension(SZI\_(G),SZK\_(G)+1)}, &
695                           \textcolor{keywordtype}{optional}, \textcolor{keywordtype}{intent(inout)} :: Kd\_int\textcolor{comment}{ !< The diapycnal diffusivity at interfaces,}
696 \textcolor{comment}{                                                            !! [Z2 T-1 ~> m2 s-1].}
697   \textcolor{keywordtype}{real},                             \textcolor{keywordtype}{intent(in)}    :: Kd\_max\textcolor{comment}{ !< The maximum increment for diapycnal}
698 \textcolor{comment}{                                                            !! diffusivity due to TKE-based processes,}
699 \textcolor{comment}{                                                            !! [Z2 T-1 ~> m2 s-1].}
700 \textcolor{comment}{                                                            !! Set this to a negative value to have no
       limit.}
701   \textcolor{keywordtype}{real}, \textcolor{keywordtype}{dimension(:,:,:)},           \textcolor{keywordtype}{pointer}       :: Kv\textcolor{comment}{     !< The "slow" vertical viscosity at each
       interface}
702 \textcolor{comment}{                                                            !! (not layer!) [Z2 T-1 ~> m2 s-1].}
703 
704   \textcolor{keywordflow}{if} (cs%Int\_tide\_dissipation .or. cs%Lee\_wave\_dissipation .or. cs%Lowmode\_itidal\_dissipation) \textcolor{keywordflow}{then}
705     \textcolor{keywordflow}{if} (cs%use\_CVMix\_tidal) \textcolor{keywordflow}{then}
706       \textcolor{keyword}{call }calculate\_cvmix\_tidal(h, j, g, gv, us, cs, n2\_int, kd\_lay, kd\_int, kv)
707     \textcolor{keywordflow}{else}
708       \textcolor{keyword}{call }add\_int\_tide\_diffusivity(h, n2\_bot, j, tke\_to\_kd, max\_tke, &
709                                     g, gv, us, cs, n2\_lay, kd\_lay, kd\_int, kd\_max)
710 \textcolor{keywordflow}{    endif}
711 \textcolor{keywordflow}{  endif}
\end{DoxyCode}
\mbox{\Hypertarget{namespacemom__tidal__mixing_af6fabb2bc6e4aabd3187938bda8098ec}\label{namespacemom__tidal__mixing_af6fabb2bc6e4aabd3187938bda8098ec}} 
\index{mom\+\_\+tidal\+\_\+mixing@{mom\+\_\+tidal\+\_\+mixing}!post\+\_\+tidal\+\_\+diagnostics@{post\+\_\+tidal\+\_\+diagnostics}}
\index{post\+\_\+tidal\+\_\+diagnostics@{post\+\_\+tidal\+\_\+diagnostics}!mom\+\_\+tidal\+\_\+mixing@{mom\+\_\+tidal\+\_\+mixing}}
\subsubsection{\texorpdfstring{post\+\_\+tidal\+\_\+diagnostics()}{post\_tidal\_diagnostics()}}
{\footnotesize\ttfamily subroutine, public mom\+\_\+tidal\+\_\+mixing\+::post\+\_\+tidal\+\_\+diagnostics (\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(in)}]{h,  }\item[{type(\mbox{\hyperlink{structmom__tidal__mixing_1_1tidal__mixing__cs}{tidal\+\_\+mixing\+\_\+cs}}), pointer}]{CS }\end{DoxyParamCaption})}



This subroutine offers up diagnostics of the tidal mixing. 


\begin{DoxyParams}[1]{Parameters}
\mbox{\tt in}  & {\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}  & {\em h} & Layer thicknesses \mbox{[}H $\sim$$>$ m or kg m-\/2\mbox{]}.\\
\hline
 & {\em cs} & The control structure for this module \\
\hline
\end{DoxyParams}


Definition at line 1498 of file M\+O\+M\+\_\+tidal\+\_\+mixing.\+F90.


\begin{DoxyCode}
1498   \textcolor{keywordtype}{type}(ocean\_grid\_type),    \textcolor{keywordtype}{intent(in)}   :: G\textcolor{comment}{   !< The ocean's grid structure}
1499   \textcolor{keywordtype}{type}(verticalGrid\_type),  \textcolor{keywordtype}{intent(in)}   :: GV\textcolor{comment}{  !< The ocean's vertical grid structure.}
1500   \textcolor{keywordtype}{real}, \textcolor{keywordtype}{dimension(SZI\_(G),SZJ\_(G),SZK\_(G))},  &
1501                             \textcolor{keywordtype}{intent(in)}   :: h\textcolor{comment}{   !< Layer thicknesses [H ~> m or kg m-2].}
1502   \textcolor{keywordtype}{type}(tidal\_mixing\_cs),    \textcolor{keywordtype}{pointer}      :: CS\textcolor{comment}{  !< The control structure for this module}
1503 
1504   \textcolor{comment}{! local}
1505   \textcolor{keywordtype}{type}(tidal\_mixing\_diags), \textcolor{keywordtype}{pointer} :: dd => null()
1506 
1507   dd => cs%dd
1508 
1509   \textcolor{keywordflow}{if} (cs%Int\_tide\_dissipation .or. cs%Lee\_wave\_dissipation .or. cs%Lowmode\_itidal\_dissipation) \textcolor{keywordflow}{then}
1510     \textcolor{keywordflow}{if} (cs%id\_TKE\_itidal  > 0) \textcolor{keyword}{call }post\_data(cs%id\_TKE\_itidal,  dd%TKE\_itidal\_used, cs%diag)
1511     \textcolor{keywordflow}{if} (cs%id\_TKE\_leewave > 0) \textcolor{keyword}{call }post\_data(cs%id\_TKE\_leewave, cs%TKE\_Niku,        cs%diag)
1512     \textcolor{keywordflow}{if} (cs%id\_Nb          > 0) \textcolor{keyword}{call }post\_data(cs%id\_Nb,      cs%Nb,      cs%diag)
1513     \textcolor{keywordflow}{if} (cs%id\_N2\_bot      > 0) \textcolor{keyword}{call }post\_data(cs%id\_N2\_bot,  dd%N2\_bot,  cs%diag)
1514     \textcolor{keywordflow}{if} (cs%id\_N2\_meanz    > 0) \textcolor{keyword}{call }post\_data(cs%id\_N2\_meanz,dd%N2\_meanz,cs%diag)
1515 
1516     \textcolor{keywordflow}{if} (cs%id\_Fl\_itidal > 0) \textcolor{keyword}{call }post\_data(cs%id\_Fl\_itidal, dd%Fl\_itidal, cs%diag)
1517     \textcolor{keywordflow}{if} (cs%id\_Kd\_itidal > 0) \textcolor{keyword}{call }post\_data(cs%id\_Kd\_itidal, dd%Kd\_itidal, cs%diag)
1518     \textcolor{keywordflow}{if} (cs%id\_Kd\_Niku   > 0) \textcolor{keyword}{call }post\_data(cs%id\_Kd\_Niku,   dd%Kd\_Niku,   cs%diag)
1519     \textcolor{keywordflow}{if} (cs%id\_Kd\_lowmode> 0) \textcolor{keyword}{call }post\_data(cs%id\_Kd\_lowmode, dd%Kd\_lowmode, cs%diag)
1520     \textcolor{keywordflow}{if} (cs%id\_Fl\_lowmode> 0) \textcolor{keyword}{call }post\_data(cs%id\_Fl\_lowmode, dd%Fl\_lowmode, cs%diag)
1521 
1522     \textcolor{keywordflow}{if} (cs%id\_N2\_int> 0)        \textcolor{keyword}{call }post\_data(cs%id\_N2\_int, dd%N2\_int, cs%diag)
1523     \textcolor{keywordflow}{if} (cs%id\_vert\_dep> 0)      \textcolor{keyword}{call }post\_data(cs%id\_vert\_dep, dd%vert\_dep\_3d, cs%diag)
1524     \textcolor{keywordflow}{if} (cs%id\_Simmons\_coeff> 0) \textcolor{keyword}{call }post\_data(cs%id\_Simmons\_coeff, dd%Simmons\_coeff\_2d, cs%diag)
1525     \textcolor{keywordflow}{if} (cs%id\_Schmittner\_coeff> 0) \textcolor{keyword}{call }post\_data(cs%id\_Schmittner\_coeff, dd%Schmittner\_coeff\_3d, cs%diag)
1526     \textcolor{keywordflow}{if} (cs%id\_tidal\_qe\_md> 0) \textcolor{keyword}{call }post\_data(cs%id\_tidal\_qe\_md, dd%tidal\_qe\_md, cs%diag)
1527 
1528     \textcolor{keywordflow}{if} (cs%id\_Kd\_Itidal\_Work > 0) &
1529       \textcolor{keyword}{call }post\_data(cs%id\_Kd\_Itidal\_Work, dd%Kd\_Itidal\_Work, cs%diag)
1530     \textcolor{keywordflow}{if} (cs%id\_Kd\_Niku\_Work > 0) \textcolor{keyword}{call }post\_data(cs%id\_Kd\_Niku\_Work, dd%Kd\_Niku\_Work, cs%diag)
1531     \textcolor{keywordflow}{if} (cs%id\_Kd\_Lowmode\_Work > 0) &
1532       \textcolor{keyword}{call }post\_data(cs%id\_Kd\_Lowmode\_Work, dd%Kd\_Lowmode\_Work, cs%diag)
1533 
1534     \textcolor{keywordflow}{if} (cs%id\_Polzin\_decay\_scale > 0 ) &
1535       \textcolor{keyword}{call }post\_data(cs%id\_Polzin\_decay\_scale, dd%Polzin\_decay\_scale, cs%diag)
1536     \textcolor{keywordflow}{if} (cs%id\_Polzin\_decay\_scale\_scaled > 0 ) &
1537       \textcolor{keyword}{call }post\_data(cs%id\_Polzin\_decay\_scale\_scaled, dd%Polzin\_decay\_scale\_scaled, cs%diag)
1538 \textcolor{keywordflow}{  endif}
1539 
1540   \textcolor{keywordflow}{if} (\textcolor{keyword}{associated}(dd%Kd\_itidal)) \textcolor{keyword}{deallocate}(dd%Kd\_itidal)
1541   \textcolor{keywordflow}{if} (\textcolor{keyword}{associated}(dd%Kd\_lowmode)) \textcolor{keyword}{deallocate}(dd%Kd\_lowmode)
1542   \textcolor{keywordflow}{if} (\textcolor{keyword}{associated}(dd%Fl\_itidal)) \textcolor{keyword}{deallocate}(dd%Fl\_itidal)
1543   \textcolor{keywordflow}{if} (\textcolor{keyword}{associated}(dd%Fl\_lowmode)) \textcolor{keyword}{deallocate}(dd%Fl\_lowmode)
1544   \textcolor{keywordflow}{if} (\textcolor{keyword}{associated}(dd%Polzin\_decay\_scale)) \textcolor{keyword}{deallocate}(dd%Polzin\_decay\_scale)
1545   \textcolor{keywordflow}{if} (\textcolor{keyword}{associated}(dd%Polzin\_decay\_scale\_scaled)) \textcolor{keyword}{deallocate}(dd%Polzin\_decay\_scale\_scaled)
1546   \textcolor{keywordflow}{if} (\textcolor{keyword}{associated}(dd%N2\_bot)) \textcolor{keyword}{deallocate}(dd%N2\_bot)
1547   \textcolor{keywordflow}{if} (\textcolor{keyword}{associated}(dd%N2\_meanz)) \textcolor{keyword}{deallocate}(dd%N2\_meanz)
1548   \textcolor{keywordflow}{if} (\textcolor{keyword}{associated}(dd%Kd\_Niku)) \textcolor{keyword}{deallocate}(dd%Kd\_Niku)
1549   \textcolor{keywordflow}{if} (\textcolor{keyword}{associated}(dd%Kd\_Niku\_work)) \textcolor{keyword}{deallocate}(dd%Kd\_Niku\_work)
1550   \textcolor{keywordflow}{if} (\textcolor{keyword}{associated}(dd%Kd\_Itidal\_Work))  \textcolor{keyword}{deallocate}(dd%Kd\_Itidal\_Work)
1551   \textcolor{keywordflow}{if} (\textcolor{keyword}{associated}(dd%Kd\_Lowmode\_Work)) \textcolor{keyword}{deallocate}(dd%Kd\_Lowmode\_Work)
1552   \textcolor{keywordflow}{if} (\textcolor{keyword}{associated}(dd%TKE\_itidal\_used)) \textcolor{keyword}{deallocate}(dd%TKE\_itidal\_used)
1553   \textcolor{keywordflow}{if} (\textcolor{keyword}{associated}(dd%N2\_int)) \textcolor{keyword}{deallocate}(dd%N2\_int)
1554   \textcolor{keywordflow}{if} (\textcolor{keyword}{associated}(dd%vert\_dep\_3d)) \textcolor{keyword}{deallocate}(dd%vert\_dep\_3d)
1555   \textcolor{keywordflow}{if} (\textcolor{keyword}{associated}(dd%Simmons\_coeff\_2d)) \textcolor{keyword}{deallocate}(dd%Simmons\_coeff\_2d)
1556   \textcolor{keywordflow}{if} (\textcolor{keyword}{associated}(dd%Schmittner\_coeff\_3d)) \textcolor{keyword}{deallocate}(dd%Schmittner\_coeff\_3d)
1557   \textcolor{keywordflow}{if} (\textcolor{keyword}{associated}(dd%tidal\_qe\_md)) \textcolor{keyword}{deallocate}(dd%tidal\_qe\_md)
1558 
\end{DoxyCode}
\mbox{\Hypertarget{namespacemom__tidal__mixing_a30a24b88982a5134253679d9484b3708}\label{namespacemom__tidal__mixing_a30a24b88982a5134253679d9484b3708}} 
\index{mom\+\_\+tidal\+\_\+mixing@{mom\+\_\+tidal\+\_\+mixing}!read\+\_\+tidal\+\_\+constituents@{read\+\_\+tidal\+\_\+constituents}}
\index{read\+\_\+tidal\+\_\+constituents@{read\+\_\+tidal\+\_\+constituents}!mom\+\_\+tidal\+\_\+mixing@{mom\+\_\+tidal\+\_\+mixing}}
\subsubsection{\texorpdfstring{read\+\_\+tidal\+\_\+constituents()}{read\_tidal\_constituents()}}
{\footnotesize\ttfamily subroutine mom\+\_\+tidal\+\_\+mixing\+::read\+\_\+tidal\+\_\+constituents (\begin{DoxyParamCaption}\item[{type(ocean\+\_\+grid\+\_\+type), intent(in)}]{G,  }\item[{type(unit\+\_\+scale\+\_\+type), intent(in)}]{US,  }\item[{character(len=200), intent(in)}]{tidal\+\_\+energy\+\_\+file,  }\item[{type(\mbox{\hyperlink{structmom__tidal__mixing_1_1tidal__mixing__cs}{tidal\+\_\+mixing\+\_\+cs}}), pointer}]{CS }\end{DoxyParamCaption})\hspace{0.3cm}{\ttfamily [private]}}



This subroutine reads tidal input energy from a file by constituent. 


\begin{DoxyParams}[1]{Parameters}
\mbox{\tt in}  & {\em g} & The ocean\textquotesingle{}s grid structure\\
\hline
\mbox{\tt in}  & {\em us} & A dimensional unit scaling type\\
\hline
\mbox{\tt in}  & {\em tidal\+\_\+energy\+\_\+file} & The file from which to read tidal energy inputs\\
\hline
 & {\em cs} & The control structure for this module \\
\hline
\end{DoxyParams}


Definition at line 1612 of file M\+O\+M\+\_\+tidal\+\_\+mixing.\+F90.


\begin{DoxyCode}
1612   \textcolor{keywordtype}{type}(ocean\_grid\_type), \textcolor{keywordtype}{intent(in)} :: G\textcolor{comment}{    !< The ocean's grid structure}
1613   \textcolor{keywordtype}{type}(unit\_scale\_type), \textcolor{keywordtype}{intent(in)} :: US\textcolor{comment}{   !< A dimensional unit scaling type}
1614   \textcolor{keywordtype}{character(len=200)},    \textcolor{keywordtype}{intent(in)} :: tidal\_energy\_file\textcolor{comment}{ !< The file from which to read tidal energy inputs}
1615   \textcolor{keywordtype}{type}(tidal\_mixing\_cs), \textcolor{keywordtype}{pointer}    :: CS\textcolor{comment}{   !< The control structure for this module}
1616 
1617   \textcolor{comment}{! local variables}
1618   \textcolor{keywordtype}{real}, \textcolor{keywordtype}{parameter} :: C1\_3 = 1.0/3.0
1619   \textcolor{keywordtype}{real}, \textcolor{keywordtype}{dimension(SZI\_(G),SZJ\_(G))} :: &
1620     tidal\_qk1, &  \textcolor{comment}{! qk1 coefficient used in Schmittner & Egbert}
1621     tidal\_qo1     \textcolor{comment}{! qo1 coefficient used in Schmittner & Egbert}
1622   \textcolor{keywordtype}{real}, \textcolor{keywordtype}{allocatable}, \textcolor{keywordtype}{dimension(:)} :: &
1623     z\_t, &        \textcolor{comment}{! depth from surface to midpoint of input layer [Z]}
1624     z\_w           \textcolor{comment}{! depth from surface to top of input layer [Z]}
1625   \textcolor{keywordtype}{real}, \textcolor{keywordtype}{allocatable}, \textcolor{keywordtype}{dimension(:,:,:)} :: &
1626     tc\_m2, &      \textcolor{comment}{! input lunar semidiurnal tidal energy flux [W/m^2]}
1627     tc\_s2, &      \textcolor{comment}{! input solar semidiurnal tidal energy flux [W/m^2]}
1628     tc\_k1, &      \textcolor{comment}{! input lunar diurnal tidal energy flux [W/m^2]}
1629     tc\_o1         \textcolor{comment}{! input lunar diurnal tidal energy flux [W/m^2]}
1630   \textcolor{keywordtype}{integer}, \textcolor{keywordtype}{dimension(4)} :: nz\_in
1631   \textcolor{keywordtype}{integer}               :: k, is, ie, js, je, isd, ied, jsd, jed, i, j
1632 
1633   is = g%isc ; ie = g%iec ; js = g%jsc ; je = g%jec
1634   isd = g%isd ; ied = g%ied ; jsd = g%jsd ; jed = g%jed
1635 
1636   \textcolor{comment}{! get number of input levels:}
1637   \textcolor{keyword}{call }field\_size(tidal\_energy\_file, \textcolor{stringliteral}{'z\_t'}, nz\_in)
1638 
1639   \textcolor{comment}{! allocate local variables}
1640   \textcolor{keyword}{allocate}(z\_t(nz\_in(1)), z\_w(nz\_in(1)) )
1641   \textcolor{keyword}{allocate}(tc\_m2(isd:ied,jsd:jed,nz\_in(1)), &
1642            tc\_s2(isd:ied,jsd:jed,nz\_in(1)), &
1643            tc\_k1(isd:ied,jsd:jed,nz\_in(1)), &
1644            tc\_o1(isd:ied,jsd:jed,nz\_in(1)) )
1645 
1646   \textcolor{comment}{! allocate CS variables associated with 3d tidal energy dissipation}
1647   \textcolor{keywordflow}{if} (.not. \textcolor{keyword}{allocated}(cs%tidal\_qe\_3d\_in)) \textcolor{keyword}{allocate}(cs%tidal\_qe\_3d\_in(isd:ied,jsd:jed,nz\_in(1)))
1648   \textcolor{keywordflow}{if} (.not. \textcolor{keyword}{allocated}(cs%h\_src))          \textcolor{keyword}{allocate}(cs%h\_src(nz\_in(1)))
1649 
1650   \textcolor{comment}{! read in tidal constituents}
1651   \textcolor{keyword}{call }mom\_read\_data(tidal\_energy\_file, \textcolor{stringliteral}{'M2'}, tc\_m2, g%domain)
1652   \textcolor{keyword}{call }mom\_read\_data(tidal\_energy\_file, \textcolor{stringliteral}{'S2'}, tc\_s2, g%domain)
1653   \textcolor{keyword}{call }mom\_read\_data(tidal\_energy\_file, \textcolor{stringliteral}{'K1'}, tc\_k1, g%domain)
1654   \textcolor{keyword}{call }mom\_read\_data(tidal\_energy\_file, \textcolor{stringliteral}{'O1'}, tc\_o1, g%domain)
1655   \textcolor{comment}{! Note the hard-coded assumption that z\_t and z\_w in the file are in centimeters.}
1656   \textcolor{keyword}{call }mom\_read\_data(tidal\_energy\_file, \textcolor{stringliteral}{'z\_t'}, z\_t, scale=100.0*us%m\_to\_Z)
1657   \textcolor{keyword}{call }mom\_read\_data(tidal\_energy\_file, \textcolor{stringliteral}{'z\_w'}, z\_w, scale=100.0*us%m\_to\_Z)
1658 
1659   \textcolor{keywordflow}{do} j=js,je ; \textcolor{keywordflow}{do} i=is,ie
1660     \textcolor{keywordflow}{if} (abs(g%geoLatT(i,j)) < 30.0) \textcolor{keywordflow}{then}
1661       tidal\_qk1(i,j) = c1\_3
1662       tidal\_qo1(i,j) = c1\_3
1663     \textcolor{keywordflow}{else}
1664       tidal\_qk1(i,j) = 1.0
1665       tidal\_qo1(i,j) = 1.0
1666 \textcolor{keywordflow}{    endif}
1667 \textcolor{keywordflow}{  enddo} ;\textcolor{keywordflow}{ enddo}
1668 
1669   cs%tidal\_qe\_3d\_in(:,:,:) = 0.0
1670   \textcolor{keywordflow}{do} k=1,nz\_in(1)
1671     \textcolor{comment}{! Store the input cell thickness in m for use with CVmix.}
1672     cs%h\_src(k) = us%Z\_to\_m*(z\_t(k)-z\_w(k))*2.0
1673     \textcolor{comment}{! form tidal\_qe\_3d\_in from weighted tidal constituents}
1674     \textcolor{keywordflow}{do} j=js,je ; \textcolor{keywordflow}{do} i=is,ie
1675       \textcolor{keywordflow}{if} ((z\_t(k) <= g%bathyT(i,j)) .and. (z\_w(k) > cs%tidal\_diss\_lim\_tc)) &
1676         cs%tidal\_qe\_3d\_in(i,j,k) = c1\_3*tc\_m2(i,j,k) + c1\_3*tc\_s2(i,j,k) + &
1677                 tidal\_qk1(i,j)*tc\_k1(i,j,k) + tidal\_qo1(i,j)*tc\_o1(i,j,k)
1678 \textcolor{keywordflow}{    enddo} ;\textcolor{keywordflow}{ enddo}
1679 \textcolor{keywordflow}{  enddo}
1680 
1681   \textcolor{comment}{!open(unit=1905,file="out\_1905.txt",access="APPEND")}
1682   \textcolor{comment}{!do j=G%jsd,G%jed}
1683   \textcolor{comment}{!  do i=isd,ied}
1684   \textcolor{comment}{!    if ( i+G%idg\_offset .eq. 90 .and. j+G%jdg\_offset .eq. 126) then}
1685   \textcolor{comment}{!      write(1905,*) "-------------------------------------------"}
1686   \textcolor{comment}{!      do k=50,nz\_in(1)}
1687   \textcolor{comment}{!          write(1905,*) i,j,k}
1688   \textcolor{comment}{!          write(1905,*) CS%tidal\_qe\_3d\_in(i,j,k), tc\_m2(i,j,k)}
1689   \textcolor{comment}{!          write(1905,*) z\_t(k), G%bathyT(i,j), z\_w(k),CS%tidal\_diss\_lim\_tc}
1690   \textcolor{comment}{!      end do}
1691   \textcolor{comment}{!    endif}
1692   \textcolor{comment}{!  enddo}
1693   \textcolor{comment}{!enddo}
1694   \textcolor{comment}{!close(1905)}
1695 
1696   \textcolor{comment}{! test if qE is positive}
1697   \textcolor{keywordflow}{if} (any(cs%tidal\_qe\_3d\_in<0.0)) \textcolor{keywordflow}{then}
1698     \textcolor{keyword}{call }mom\_error(fatal, \textcolor{stringliteral}{"read\_tidal\_constituents: Negative tidal\_qe\_3d\_in terms."})
1699 \textcolor{keywordflow}{  endif}
1700 
1701   \textcolor{comment}{!! collapse 3D q*E to 2D q*E}
1702   \textcolor{comment}{!CS%tidal\_qe\_2d(:,:) = 0.0}
1703   \textcolor{comment}{!do k=1,nz\_in(1) ; do j=js,je ; do i=is,ie}
1704   \textcolor{comment}{!  if (z\_t(k) <= G%bathyT(i,j)) &}
1705   \textcolor{comment}{!    CS%tidal\_qe\_2d(i,j) = CS%tidal\_qe\_2d(i,j) + CS%tidal\_qe\_3d\_in(i,j,k)}
1706   \textcolor{comment}{!enddo ; enddo ; enddo}
1707 
1708   \textcolor{comment}{! initialize input remapping:}
1709   \textcolor{keyword}{call }initialize\_remapping(cs%remap\_cs, remapping\_scheme=\textcolor{stringliteral}{"PLM"}, &
1710                             boundary\_extrapolation=.false., check\_remapping=cs%debug, &
1711                             answers\_2018=cs%remap\_answers\_2018)
1712 
1713   \textcolor{keyword}{deallocate}(tc\_m2)
1714   \textcolor{keyword}{deallocate}(tc\_s2)
1715   \textcolor{keyword}{deallocate}(tc\_k1)
1716   \textcolor{keyword}{deallocate}(tc\_o1)
1717   \textcolor{keyword}{deallocate}(z\_t)
1718   \textcolor{keyword}{deallocate}(z\_w)
1719 
\end{DoxyCode}
\mbox{\Hypertarget{namespacemom__tidal__mixing_adfd3a137ee6402fdcdfb7c46711e0e23}\label{namespacemom__tidal__mixing_adfd3a137ee6402fdcdfb7c46711e0e23}} 
\index{mom\+\_\+tidal\+\_\+mixing@{mom\+\_\+tidal\+\_\+mixing}!read\+\_\+tidal\+\_\+energy@{read\+\_\+tidal\+\_\+energy}}
\index{read\+\_\+tidal\+\_\+energy@{read\+\_\+tidal\+\_\+energy}!mom\+\_\+tidal\+\_\+mixing@{mom\+\_\+tidal\+\_\+mixing}}
\subsubsection{\texorpdfstring{read\+\_\+tidal\+\_\+energy()}{read\_tidal\_energy()}}
{\footnotesize\ttfamily subroutine mom\+\_\+tidal\+\_\+mixing\+::read\+\_\+tidal\+\_\+energy (\begin{DoxyParamCaption}\item[{type(ocean\+\_\+grid\+\_\+type), intent(in)}]{G,  }\item[{type(unit\+\_\+scale\+\_\+type), intent(in)}]{US,  }\item[{character(len=20), intent(in)}]{tidal\+\_\+energy\+\_\+type,  }\item[{character(len=200), intent(in)}]{tidal\+\_\+energy\+\_\+file,  }\item[{type(\mbox{\hyperlink{structmom__tidal__mixing_1_1tidal__mixing__cs}{tidal\+\_\+mixing\+\_\+cs}}), pointer}]{CS }\end{DoxyParamCaption})\hspace{0.3cm}{\ttfamily [private]}}



This subroutine read tidal energy inputs from a file. 


\begin{DoxyParams}[1]{Parameters}
\mbox{\tt in}  & {\em g} & The ocean\textquotesingle{}s grid structure\\
\hline
\mbox{\tt in}  & {\em us} & A dimensional unit scaling type\\
\hline
\mbox{\tt in}  & {\em tidal\+\_\+energy\+\_\+type} & The type of tidal energy inputs to read\\
\hline
\mbox{\tt in}  & {\em tidal\+\_\+energy\+\_\+file} & The file from which to read tidalinputs\\
\hline
 & {\em cs} & The control structure for this module \\
\hline
\end{DoxyParams}


Definition at line 1582 of file M\+O\+M\+\_\+tidal\+\_\+mixing.\+F90.


\begin{DoxyCode}
1582   \textcolor{keywordtype}{type}(ocean\_grid\_type),   \textcolor{keywordtype}{intent(in)} :: G\textcolor{comment}{    !< The ocean's grid structure}
1583   \textcolor{keywordtype}{type}(unit\_scale\_type),   \textcolor{keywordtype}{intent(in)} :: US\textcolor{comment}{   !< A dimensional unit scaling type}
1584   \textcolor{keywordtype}{character(len=20)},       \textcolor{keywordtype}{intent(in)} :: tidal\_energy\_type\textcolor{comment}{ !< The type of tidal energy inputs to read}
1585   \textcolor{keywordtype}{character(len=200)},      \textcolor{keywordtype}{intent(in)} :: tidal\_energy\_file\textcolor{comment}{ !< The file from which to read tidalinputs}
1586   \textcolor{keywordtype}{type}(tidal\_mixing\_cs),   \textcolor{keywordtype}{pointer}    :: CS\textcolor{comment}{   !< The control structure for this module}
1587   \textcolor{comment}{! local}
1588   \textcolor{keywordtype}{integer} :: i, j, isd, ied, jsd, jed, nz
1589   \textcolor{keywordtype}{real}, \textcolor{keywordtype}{allocatable}, \textcolor{keywordtype}{dimension(:,:)} :: tidal\_energy\_flux\_2d \textcolor{comment}{! input tidal energy flux at T-grid points [W
       m-2]}
1590 
1591   isd = g%isd ; ied = g%ied ; jsd = g%jsd ; jed = g%jed ; nz = g%ke
1592 
1593   \textcolor{keywordflow}{select case} (uppercase(tidal\_energy\_type(1:4)))
1594   \textcolor{keywordflow}{case} (\textcolor{stringliteral}{'JAYN'}) \textcolor{comment}{! Jayne 2009}
1595     \textcolor{keywordflow}{if} (.not. \textcolor{keyword}{allocated}(cs%tidal\_qe\_2d)) \textcolor{keyword}{allocate}(cs%tidal\_qe\_2d(isd:ied,jsd:jed))
1596     \textcolor{keyword}{allocate}(tidal\_energy\_flux\_2d(isd:ied,jsd:jed))
1597     \textcolor{keyword}{call }mom\_read\_data(tidal\_energy\_file,\textcolor{stringliteral}{'wave\_dissipation'},tidal\_energy\_flux\_2d, g%domain)
1598     \textcolor{keywordflow}{do} j=g%jsc,g%jec ; \textcolor{keywordflow}{do} i=g%isc,g%iec
1599       cs%tidal\_qe\_2d(i,j) = cs%Gamma\_itides * tidal\_energy\_flux\_2d(i,j)
1600 \textcolor{keywordflow}{    enddo} ;\textcolor{keywordflow}{ enddo}
1601     \textcolor{keyword}{deallocate}(tidal\_energy\_flux\_2d)
1602   \textcolor{keywordflow}{case} (\textcolor{stringliteral}{'ER03'}) \textcolor{comment}{! Egbert & Ray 2003}
1603     \textcolor{keyword}{call }read\_tidal\_constituents(g, us, tidal\_energy\_file, cs)
1604 \textcolor{keywordflow}{  case default}
1605     \textcolor{keyword}{call }mom\_error(fatal, \textcolor{stringliteral}{"read\_tidal\_energy: Unknown tidal energy file type."})
1606 \textcolor{keywordflow}{  end select}
1607 
\end{DoxyCode}
\mbox{\Hypertarget{namespacemom__tidal__mixing_a7d2dfb64df35957d1252ce841c0cdf43}\label{namespacemom__tidal__mixing_a7d2dfb64df35957d1252ce841c0cdf43}} 
\index{mom\+\_\+tidal\+\_\+mixing@{mom\+\_\+tidal\+\_\+mixing}!setup\+\_\+tidal\+\_\+diagnostics@{setup\+\_\+tidal\+\_\+diagnostics}}
\index{setup\+\_\+tidal\+\_\+diagnostics@{setup\+\_\+tidal\+\_\+diagnostics}!mom\+\_\+tidal\+\_\+mixing@{mom\+\_\+tidal\+\_\+mixing}}
\subsubsection{\texorpdfstring{setup\+\_\+tidal\+\_\+diagnostics()}{setup\_tidal\_diagnostics()}}
{\footnotesize\ttfamily subroutine, public mom\+\_\+tidal\+\_\+mixing\+::setup\+\_\+tidal\+\_\+diagnostics (\begin{DoxyParamCaption}\item[{type(ocean\+\_\+grid\+\_\+type), intent(in)}]{G,  }\item[{type(\mbox{\hyperlink{structmom__tidal__mixing_1_1tidal__mixing__cs}{tidal\+\_\+mixing\+\_\+cs}}), pointer}]{CS }\end{DoxyParamCaption})}



Sets up diagnostics arrays for tidal mixing. 


\begin{DoxyParams}[1]{Parameters}
\mbox{\tt in}  & {\em g} & The ocean\textquotesingle{}s grid structure\\
\hline
 & {\em cs} & The control structure for this module \\
\hline
\end{DoxyParams}


Definition at line 1413 of file M\+O\+M\+\_\+tidal\+\_\+mixing.\+F90.


\begin{DoxyCode}
1413   \textcolor{keywordtype}{type}(ocean\_grid\_type), \textcolor{keywordtype}{intent(in)} :: G\textcolor{comment}{  !< The ocean's grid structure}
1414   \textcolor{keywordtype}{type}(tidal\_mixing\_cs), \textcolor{keywordtype}{pointer}    :: CS\textcolor{comment}{ !< The control structure for this module}
1415 
1416   \textcolor{comment}{! local}
1417   \textcolor{keywordtype}{integer} :: isd, ied, jsd, jed, nz
1418   \textcolor{keywordtype}{type}(tidal\_mixing\_diags), \textcolor{keywordtype}{pointer} :: dd => null()
1419 
1420   isd = g%isd; ied = g%ied; jsd = g%jsd; jed = g%jed; nz = g%ke
1421   dd => cs%dd
1422 
1423   \textcolor{keywordflow}{if} ((cs%id\_Kd\_itidal > 0) .or. (cs%id\_Kd\_Itidal\_work > 0)) \textcolor{keywordflow}{then}
1424     \textcolor{keyword}{allocate}(dd%Kd\_itidal(isd:ied,jsd:jed,nz+1)) ; dd%Kd\_itidal(:,:,:) = 0.0
1425 \textcolor{keywordflow}{  endif}
1426   \textcolor{keywordflow}{if} ((cs%id\_Kd\_lowmode > 0) .or. (cs%id\_Kd\_lowmode\_work > 0)) \textcolor{keywordflow}{then}
1427     \textcolor{keyword}{allocate}(dd%Kd\_lowmode(isd:ied,jsd:jed,nz+1)) ; dd%Kd\_lowmode(:,:,:) = 0.0
1428 \textcolor{keywordflow}{  endif}
1429   \textcolor{keywordflow}{if} ( (cs%id\_Fl\_itidal > 0) ) \textcolor{keywordflow}{then}
1430     \textcolor{keyword}{allocate}(dd%Fl\_itidal(isd:ied,jsd:jed,nz+1)) ; dd%Fl\_itidal(:,:,:) = 0.0
1431 \textcolor{keywordflow}{  endif}
1432   \textcolor{keywordflow}{if} ( (cs%id\_Fl\_lowmode > 0) ) \textcolor{keywordflow}{then}
1433     \textcolor{keyword}{allocate}(dd%Fl\_lowmode(isd:ied,jsd:jed,nz+1)) ; dd%Fl\_lowmode(:,:,:) = 0.0
1434 \textcolor{keywordflow}{  endif}
1435   \textcolor{keywordflow}{if} ( (cs%id\_Polzin\_decay\_scale > 0) ) \textcolor{keywordflow}{then}
1436     \textcolor{keyword}{allocate}(dd%Polzin\_decay\_scale(isd:ied,jsd:jed))
1437     dd%Polzin\_decay\_scale(:,:) = 0.0
1438 \textcolor{keywordflow}{  endif}
1439   \textcolor{keywordflow}{if} ( (cs%id\_N2\_bot > 0) ) \textcolor{keywordflow}{then}
1440     \textcolor{keyword}{allocate}(dd%N2\_bot(isd:ied,jsd:jed)) ; dd%N2\_bot(:,:) = 0.0
1441 \textcolor{keywordflow}{  endif}
1442   \textcolor{keywordflow}{if} ( (cs%id\_N2\_meanz > 0) ) \textcolor{keywordflow}{then}
1443     \textcolor{keyword}{allocate}(dd%N2\_meanz(isd:ied,jsd:jed)) ; dd%N2\_meanz(:,:) = 0.0
1444 \textcolor{keywordflow}{  endif}
1445   \textcolor{keywordflow}{if} ( (cs%id\_Polzin\_decay\_scale\_scaled > 0) ) \textcolor{keywordflow}{then}
1446     \textcolor{keyword}{allocate}(dd%Polzin\_decay\_scale\_scaled(isd:ied,jsd:jed))
1447     dd%Polzin\_decay\_scale\_scaled(:,:) = 0.0
1448 \textcolor{keywordflow}{  endif}
1449   \textcolor{keywordflow}{if} ((cs%id\_Kd\_Niku > 0) .or. (cs%id\_Kd\_Niku\_work > 0)) \textcolor{keywordflow}{then}
1450     \textcolor{keyword}{allocate}(dd%Kd\_Niku(isd:ied,jsd:jed,nz+1)) ; dd%Kd\_Niku(:,:,:) = 0.0
1451 \textcolor{keywordflow}{  endif}
1452   \textcolor{keywordflow}{if} (cs%id\_Kd\_Niku\_work > 0) \textcolor{keywordflow}{then}
1453     \textcolor{keyword}{allocate}(dd%Kd\_Niku\_work(isd:ied,jsd:jed,nz)) ; dd%Kd\_Niku\_work(:,:,:) = 0.0
1454 \textcolor{keywordflow}{  endif}
1455   \textcolor{keywordflow}{if} (cs%id\_Kd\_Itidal\_work > 0) \textcolor{keywordflow}{then}
1456     \textcolor{keyword}{allocate}(dd%Kd\_Itidal\_work(isd:ied,jsd:jed,nz))
1457     dd%Kd\_Itidal\_work(:,:,:) = 0.0
1458 \textcolor{keywordflow}{  endif}
1459   \textcolor{keywordflow}{if} (cs%id\_Kd\_Lowmode\_Work > 0) \textcolor{keywordflow}{then}
1460     \textcolor{keyword}{allocate}(dd%Kd\_Lowmode\_Work(isd:ied,jsd:jed,nz))
1461     dd%Kd\_Lowmode\_Work(:,:,:) = 0.0
1462 \textcolor{keywordflow}{  endif}
1463   \textcolor{keywordflow}{if} (cs%id\_TKE\_itidal > 0) \textcolor{keywordflow}{then}
1464     \textcolor{keyword}{allocate}(dd%TKE\_Itidal\_used(isd:ied,jsd:jed)) ; dd%TKE\_Itidal\_used(:,:) = 0.
1465 \textcolor{keywordflow}{  endif}
1466   \textcolor{comment}{! additional diags for CVMix}
1467   \textcolor{keywordflow}{if} (cs%id\_N2\_int > 0) \textcolor{keywordflow}{then}
1468     \textcolor{keyword}{allocate}(dd%N2\_int(isd:ied,jsd:jed,nz+1)) ; dd%N2\_int(:,:,:) = 0.0
1469 \textcolor{keywordflow}{  endif}
1470   \textcolor{keywordflow}{if} (cs%id\_Simmons\_coeff > 0) \textcolor{keywordflow}{then}
1471     \textcolor{keywordflow}{if} (cs%CVMix\_tidal\_scheme .ne. simmons) \textcolor{keywordflow}{then}
1472       \textcolor{keyword}{call }mom\_error(fatal, \textcolor{stringliteral}{"setup\_tidal\_diagnostics: Simmons\_coeff diagnostics is available "}//&
1473                             \textcolor{stringliteral}{"only when CVMix\_tidal\_scheme is Simmons"})
1474 \textcolor{keywordflow}{    endif}
1475     \textcolor{keyword}{allocate}(dd%Simmons\_coeff\_2d(isd:ied,jsd:jed)) ; dd%Simmons\_coeff\_2d(:,:) = 0.0
1476 \textcolor{keywordflow}{  endif}
1477   \textcolor{keywordflow}{if} (cs%id\_vert\_dep > 0) \textcolor{keywordflow}{then}
1478     \textcolor{keyword}{allocate}(dd%vert\_dep\_3d(isd:ied,jsd:jed,nz+1)) ; dd%vert\_dep\_3d(:,:,:) = 0.0
1479 \textcolor{keywordflow}{  endif}
1480   \textcolor{keywordflow}{if} (cs%id\_Schmittner\_coeff > 0) \textcolor{keywordflow}{then}
1481     \textcolor{keywordflow}{if} (cs%CVMix\_tidal\_scheme .ne. schmittner) \textcolor{keywordflow}{then}
1482       \textcolor{keyword}{call }mom\_error(fatal, \textcolor{stringliteral}{"setup\_tidal\_diagnostics: Schmittner\_coeff diagnostics is available "}//&
1483                             \textcolor{stringliteral}{"only when CVMix\_tidal\_scheme is Schmittner."})
1484 \textcolor{keywordflow}{    endif}
1485     \textcolor{keyword}{allocate}(dd%Schmittner\_coeff\_3d(isd:ied,jsd:jed,nz)) ; dd%Schmittner\_coeff\_3d(:,:,:) = 0.0
1486 \textcolor{keywordflow}{  endif}
1487   \textcolor{keywordflow}{if} (cs%id\_tidal\_qe\_md > 0) \textcolor{keywordflow}{then}
1488     \textcolor{keywordflow}{if} (cs%CVMix\_tidal\_scheme .ne. schmittner) \textcolor{keywordflow}{then}
1489       \textcolor{keyword}{call }mom\_error(fatal, \textcolor{stringliteral}{"setup\_tidal\_diagnostics: tidal\_qe\_md diagnostics is available "}//&
1490                             \textcolor{stringliteral}{"only when CVMix\_tidal\_scheme is Schmittner."})
1491 \textcolor{keywordflow}{    endif}
1492     \textcolor{keyword}{allocate}(dd%tidal\_qe\_md(isd:ied,jsd:jed,nz)) ; dd%tidal\_qe\_md(:,:,:) = 0.0
1493 \textcolor{keywordflow}{  endif}
\end{DoxyCode}
\mbox{\Hypertarget{namespacemom__tidal__mixing_a4ec08e118dea2ecbac7e719ed73acc70}\label{namespacemom__tidal__mixing_a4ec08e118dea2ecbac7e719ed73acc70}} 
\index{mom\+\_\+tidal\+\_\+mixing@{mom\+\_\+tidal\+\_\+mixing}!tidal\+\_\+mixing\+\_\+end@{tidal\+\_\+mixing\+\_\+end}}
\index{tidal\+\_\+mixing\+\_\+end@{tidal\+\_\+mixing\+\_\+end}!mom\+\_\+tidal\+\_\+mixing@{mom\+\_\+tidal\+\_\+mixing}}
\subsubsection{\texorpdfstring{tidal\+\_\+mixing\+\_\+end()}{tidal\_mixing\_end()}}
{\footnotesize\ttfamily subroutine, public mom\+\_\+tidal\+\_\+mixing\+::tidal\+\_\+mixing\+\_\+end (\begin{DoxyParamCaption}\item[{type(\mbox{\hyperlink{structmom__tidal__mixing_1_1tidal__mixing__cs}{tidal\+\_\+mixing\+\_\+cs}}), pointer}]{CS }\end{DoxyParamCaption})}



Clear pointers and deallocate memory. 


\begin{DoxyParams}{Parameters}
{\em cs} & This module\textquotesingle{}s control structure, which will be deallocated in this routine. \\
\hline
\end{DoxyParams}


Definition at line 1724 of file M\+O\+M\+\_\+tidal\+\_\+mixing.\+F90.


\begin{DoxyCode}
1724   \textcolor{keywordtype}{type}(tidal\_mixing\_cs), \textcolor{keywordtype}{pointer} :: CS\textcolor{comment}{ !< This module's control structure, which}
1725 \textcolor{comment}{                                       !! will be deallocated in this routine.}
1726 
1727   \textcolor{keywordflow}{if} (.not.\textcolor{keyword}{associated}(cs)) \textcolor{keywordflow}{return}
1728 
1729   \textcolor{comment}{!TODO deallocate all the dynamically allocated members here ...}
1730   \textcolor{keywordflow}{if} (\textcolor{keyword}{allocated}(cs%tidal\_qe\_2d))    \textcolor{keyword}{deallocate}(cs%tidal\_qe\_2d)
1731   \textcolor{keywordflow}{if} (\textcolor{keyword}{allocated}(cs%tidal\_qe\_3d\_in)) \textcolor{keyword}{deallocate}(cs%tidal\_qe\_3d\_in)
1732   \textcolor{keywordflow}{if} (\textcolor{keyword}{allocated}(cs%h\_src))          \textcolor{keyword}{deallocate}(cs%h\_src)
1733   \textcolor{keyword}{deallocate}(cs%dd)
1734   \textcolor{keyword}{deallocate}(cs)
1735 
\end{DoxyCode}
\mbox{\Hypertarget{namespacemom__tidal__mixing_a31fc0b55d7766de2d21fb529e491de13}\label{namespacemom__tidal__mixing_a31fc0b55d7766de2d21fb529e491de13}} 
\index{mom\+\_\+tidal\+\_\+mixing@{mom\+\_\+tidal\+\_\+mixing}!tidal\+\_\+mixing\+\_\+h\+\_\+amp@{tidal\+\_\+mixing\+\_\+h\+\_\+amp}}
\index{tidal\+\_\+mixing\+\_\+h\+\_\+amp@{tidal\+\_\+mixing\+\_\+h\+\_\+amp}!mom\+\_\+tidal\+\_\+mixing@{mom\+\_\+tidal\+\_\+mixing}}
\subsubsection{\texorpdfstring{tidal\+\_\+mixing\+\_\+h\+\_\+amp()}{tidal\_mixing\_h\_amp()}}
{\footnotesize\ttfamily subroutine, public mom\+\_\+tidal\+\_\+mixing\+::tidal\+\_\+mixing\+\_\+h\+\_\+amp (\begin{DoxyParamCaption}\item[{real, dimension( g \%isd\+: g \%ied), intent(out)}]{h\+\_\+amp,  }\item[{type(ocean\+\_\+grid\+\_\+type), intent(in)}]{G,  }\item[{integer, intent(in)}]{j,  }\item[{type(\mbox{\hyperlink{structmom__tidal__mixing_1_1tidal__mixing__cs}{tidal\+\_\+mixing\+\_\+cs}}), pointer}]{CS }\end{DoxyParamCaption})}



This subroutine returns a zonal slice of the topographic roughness amplitudes. 


\begin{DoxyParams}[1]{Parameters}
\mbox{\tt in}  & {\em g} & The ocean\textquotesingle{}s grid structure\\
\hline
\mbox{\tt out}  & {\em h\+\_\+amp} & The topographic roughness amplitude \mbox{[}Z $\sim$$>$ m\mbox{]}\\
\hline
\mbox{\tt in}  & {\em j} & j-\/index of the row to work on\\
\hline
 & {\em cs} & The control structure for this module \\
\hline
\end{DoxyParams}


Definition at line 1563 of file M\+O\+M\+\_\+tidal\+\_\+mixing.\+F90.


\begin{DoxyCode}
1563   \textcolor{keywordtype}{type}(ocean\_grid\_type),    \textcolor{keywordtype}{intent(in)}  :: G\textcolor{comment}{     !< The ocean's grid structure}
1564   \textcolor{keywordtype}{real}, \textcolor{keywordtype}{dimension(SZI\_(G))}, \textcolor{keywordtype}{intent(out)} :: h\_amp\textcolor{comment}{ !< The topographic roughness amplitude [Z ~> m]}
1565   \textcolor{keywordtype}{integer},                  \textcolor{keywordtype}{intent(in)}  :: j\textcolor{comment}{     !< j-index of the row to work on}
1566   \textcolor{keywordtype}{type}(tidal\_mixing\_cs),    \textcolor{keywordtype}{pointer}     :: CS\textcolor{comment}{    !< The control structure for this module}
1567 
1568   \textcolor{keywordtype}{integer} :: i
1569 
1570   h\_amp(:) = 0.0
1571   \textcolor{keywordflow}{if} ( cs%Int\_tide\_dissipation .and. .not. cs%use\_CVMix\_tidal ) \textcolor{keywordflow}{then}
1572     \textcolor{keywordflow}{do} i=g%isc,g%iec
1573       h\_amp(i) = sqrt(cs%h2(i,j))
1574 \textcolor{keywordflow}{    enddo}
1575 \textcolor{keywordflow}{  endif}
1576 
\end{DoxyCode}
\mbox{\Hypertarget{namespacemom__tidal__mixing_a6278fe41ef74ac23ba02ae1540104c5f}\label{namespacemom__tidal__mixing_a6278fe41ef74ac23ba02ae1540104c5f}} 
\index{mom\+\_\+tidal\+\_\+mixing@{mom\+\_\+tidal\+\_\+mixing}!tidal\+\_\+mixing\+\_\+init@{tidal\+\_\+mixing\+\_\+init}}
\index{tidal\+\_\+mixing\+\_\+init@{tidal\+\_\+mixing\+\_\+init}!mom\+\_\+tidal\+\_\+mixing@{mom\+\_\+tidal\+\_\+mixing}}
\subsubsection{\texorpdfstring{tidal\+\_\+mixing\+\_\+init()}{tidal\_mixing\_init()}}
{\footnotesize\ttfamily logical function, public mom\+\_\+tidal\+\_\+mixing\+::tidal\+\_\+mixing\+\_\+init (\begin{DoxyParamCaption}\item[{type(time\+\_\+type), intent(in)}]{Time,  }\item[{type(ocean\+\_\+grid\+\_\+type), intent(in)}]{G,  }\item[{type(verticalgrid\+\_\+type), intent(in)}]{GV,  }\item[{type(unit\+\_\+scale\+\_\+type), intent(in)}]{US,  }\item[{type(param\+\_\+file\+\_\+type), intent(in)}]{param\+\_\+file,  }\item[{type(diag\+\_\+ctrl), intent(inout), target}]{diag,  }\item[{type(\mbox{\hyperlink{structmom__tidal__mixing_1_1tidal__mixing__cs}{tidal\+\_\+mixing\+\_\+cs}}), pointer}]{CS }\end{DoxyParamCaption})}



Initializes internal tidal dissipation scheme for diapycnal mixing. 


\begin{DoxyParams}[1]{Parameters}
\mbox{\tt in}  & {\em time} & The current time.\\
\hline
\mbox{\tt in}  & {\em g} & Grid structure.\\
\hline
\mbox{\tt in}  & {\em gv} & Vertical grid structure.\\
\hline
\mbox{\tt in}  & {\em us} & A dimensional unit scaling type\\
\hline
\mbox{\tt in}  & {\em param\+\_\+file} & Run-\/time parameter file handle\\
\hline
\mbox{\tt in,out}  & {\em diag} & Diagnostics control structure.\\
\hline
 & {\em cs} & This module\textquotesingle{}s control structure. \\
\hline
\end{DoxyParams}
T\+O\+DO\+: add units 

Definition at line 213 of file M\+O\+M\+\_\+tidal\+\_\+mixing.\+F90.


\begin{DoxyCode}
213   \textcolor{keywordtype}{type}(time\_type),          \textcolor{keywordtype}{intent(in)}    :: Time\textcolor{comment}{       !< The current time.}
214   \textcolor{keywordtype}{type}(ocean\_grid\_type),    \textcolor{keywordtype}{intent(in)}    :: G\textcolor{comment}{          !< Grid structure.}
215   \textcolor{keywordtype}{type}(verticalGrid\_type),  \textcolor{keywordtype}{intent(in)}    :: GV\textcolor{comment}{         !< Vertical grid structure.}
216   \textcolor{keywordtype}{type}(unit\_scale\_type),    \textcolor{keywordtype}{intent(in)}    :: US\textcolor{comment}{         !< A dimensional unit scaling type}
217   \textcolor{keywordtype}{type}(param\_file\_type),    \textcolor{keywordtype}{intent(in)}    :: param\_file\textcolor{comment}{ !< Run-time parameter file handle}
218   \textcolor{keywordtype}{type}(diag\_ctrl), \textcolor{keywordtype}{target},  \textcolor{keywordtype}{intent(inout)} :: diag\textcolor{comment}{       !< Diagnostics control structure.}
219   \textcolor{keywordtype}{type}(tidal\_mixing\_cs),    \textcolor{keywordtype}{pointer}       :: CS\textcolor{comment}{         !< This module's control structure.}
220 
221   \textcolor{comment}{! Local variables}
222   \textcolor{keywordtype}{logical} :: read\_tideamp
223   \textcolor{keywordtype}{logical} :: default\_2018\_answers
224   \textcolor{keywordtype}{character(len=20)}  :: tmpstr, int\_tide\_profile\_str
225   \textcolor{keywordtype}{character(len=20)}  :: CVMix\_tidal\_scheme\_str, tidal\_energy\_type
226   \textcolor{keywordtype}{character(len=200)} :: filename, h2\_file, Niku\_TKE\_input\_file
227   \textcolor{keywordtype}{character(len=200)} :: tidal\_energy\_file, tideamp\_file
228   \textcolor{keywordtype}{real} :: utide, hamp, prandtl\_tidal, max\_frac\_rough
229   \textcolor{keywordtype}{real} :: Niku\_scale \textcolor{comment}{! local variable for scaling the Nikurashin TKE flux data}
230   \textcolor{keywordtype}{integer} :: i, j, is, ie, js, je
231   \textcolor{keywordtype}{integer} :: isd, ied, jsd, jed
232   \textcolor{comment}{! This include declares and sets the variable "version".}
233 \textcolor{preprocessor}{# include "version\_variable.h"}
234 \textcolor{preprocessor}{}  \textcolor{keywordtype}{character(len=40)}  :: mdl = \textcolor{stringliteral}{"MOM\_tidal\_mixing"}\textcolor{comment}{     !< This module's name.}
235 
236   \textcolor{keywordflow}{if} (\textcolor{keyword}{associated}(cs)) \textcolor{keywordflow}{then}
237     \textcolor{keyword}{call }mom\_error(warning, \textcolor{stringliteral}{"tidal\_mixing\_init called when control structure "}// &
238                             \textcolor{stringliteral}{"is already associated."})
239     \textcolor{keywordflow}{return}
240 \textcolor{keywordflow}{  endif}
241   \textcolor{keyword}{allocate}(cs)
242   \textcolor{keyword}{allocate}(cs%dd)
243 
244   cs%debug = cs%debug.and.is\_root\_pe()
245 
246   is  = g%isc ; ie  = g%iec ; js  = g%jsc ; je  = g%jec
247   isd = g%isd ; ied = g%ied ; jsd = g%jsd ; jed = g%jed
248 
249   cs%diag => diag
250 
251   \textcolor{comment}{! Read parameters}
252   \textcolor{keyword}{call }get\_param(param\_file, mdl, \textcolor{stringliteral}{"USE\_CVMix\_TIDAL"}, cs%use\_CVMix\_tidal, &
253                  default=.false., do\_not\_log=.true.)
254   \textcolor{keyword}{call }get\_param(param\_file, mdl, \textcolor{stringliteral}{"INT\_TIDE\_DISSIPATION"}, cs%int\_tide\_dissipation, &
255                  default=cs%use\_CVMix\_tidal, do\_not\_log=.true.)
256   \textcolor{keyword}{call }log\_version(param\_file, mdl, version, &
257                  \textcolor{stringliteral}{"Vertical Tidal Mixing Parameterization"}, &
258                  all\_default=.not.(cs%use\_CVMix\_tidal .or. cs%int\_tide\_dissipation))
259   \textcolor{keyword}{call }get\_param(param\_file, mdl, \textcolor{stringliteral}{"USE\_CVMix\_TIDAL"}, cs%use\_CVMix\_tidal, &
260                  \textcolor{stringliteral}{"If true, turns on tidal mixing via CVMix"}, &
261                  default=.false.)
262 
263   \textcolor{keyword}{call }get\_param(param\_file, mdl, \textcolor{stringliteral}{"INPUTDIR"}, cs%inputdir, default=\textcolor{stringliteral}{"."},do\_not\_log=.true.)
264   cs%inputdir = slasher(cs%inputdir)
265   \textcolor{keyword}{call }get\_param(param\_file, mdl, \textcolor{stringliteral}{"INT\_TIDE\_DISSIPATION"}, cs%int\_tide\_dissipation, &
266                  \textcolor{stringliteral}{"If true, use an internal tidal dissipation scheme to "}//&
267                  \textcolor{stringliteral}{"drive diapycnal mixing, along the lines of St. Laurent "}//&
268                  \textcolor{stringliteral}{"et al. (2002) and Simmons et al. (2004)."}, default=cs%use\_CVMix\_tidal)
269 
270   \textcolor{comment}{! return if tidal mixing is inactive}
271   tidal\_mixing\_init = cs%int\_tide\_dissipation
272   \textcolor{keywordflow}{if} (.not. tidal\_mixing\_init) \textcolor{keywordflow}{return}
273 
274   \textcolor{keyword}{call }get\_param(param\_file, mdl, \textcolor{stringliteral}{"DEFAULT\_2018\_ANSWERS"}, default\_2018\_answers, &
275                  \textcolor{stringliteral}{"This sets the default value for the various \_2018\_ANSWERS parameters."}, &
276                  default=.false.)
277   \textcolor{keyword}{call }get\_param(param\_file, mdl, \textcolor{stringliteral}{"TIDAL\_MIXING\_2018\_ANSWERS"}, cs%answers\_2018, &
278                  \textcolor{stringliteral}{"If true, use the order of arithmetic and expressions that recover the "}//&
279                  \textcolor{stringliteral}{"answers from the end of 2018.  Otherwise, use updated and more robust "}//&
280                  \textcolor{stringliteral}{"forms of the same expressions."}, default=default\_2018\_answers)
281   \textcolor{keyword}{call }get\_param(param\_file, mdl, \textcolor{stringliteral}{"REMAPPING\_2018\_ANSWERS"}, cs%remap\_answers\_2018, &
282                  \textcolor{stringliteral}{"If true, use the order of arithmetic and expressions that recover the "}//&
283                  \textcolor{stringliteral}{"answers from the end of 2018.  Otherwise, use updated and more robust "}//&
284                  \textcolor{stringliteral}{"forms of the same expressions."}, default=default\_2018\_answers)
285 
286   \textcolor{keywordflow}{if} (cs%int\_tide\_dissipation) \textcolor{keywordflow}{then}
287 
288     \textcolor{comment}{! Read in CVMix tidal scheme if CVMix tidal mixing is on}
289     \textcolor{keywordflow}{if} (cs%use\_CVMix\_tidal) \textcolor{keywordflow}{then}
290       \textcolor{keyword}{call }get\_param(param\_file, mdl, \textcolor{stringliteral}{"CVMIX\_TIDAL\_SCHEME"}, cvmix\_tidal\_scheme\_str, &
291                  \textcolor{stringliteral}{"CVMIX\_TIDAL\_SCHEME selects the CVMix tidal mixing "}//&
292                  \textcolor{stringliteral}{"scheme with INT\_TIDE\_DISSIPATION. Valid values are:\(\backslash\)n"}//&
293                  \textcolor{stringliteral}{"\(\backslash\)t SIMMONS - Use the Simmons et al (2004) tidal \(\backslash\)n"}//&
294                  \textcolor{stringliteral}{"\(\backslash\)t                mixing scheme.\(\backslash\)n"}//&
295                  \textcolor{stringliteral}{"\(\backslash\)t SCHMITTNER - Use the Schmittner et al (2014) tidal \(\backslash\)n"}//&
296                  \textcolor{stringliteral}{"\(\backslash\)t                mixing scheme."}, &
297                  default=simmons\_scheme\_string)
298       cvmix\_tidal\_scheme\_str = uppercase(cvmix\_tidal\_scheme\_str)
299 
300       \textcolor{keywordflow}{select case} (cvmix\_tidal\_scheme\_str)
301         \textcolor{keywordflow}{case} (simmons\_scheme\_string)    ; cs%CVMix\_tidal\_scheme = simmons
302         \textcolor{keywordflow}{case} (schmittner\_scheme\_string) ; cs%CVMix\_tidal\_scheme = schmittner
303 \textcolor{keywordflow}{        case default}
304         \textcolor{keyword}{call }mom\_error(fatal, \textcolor{stringliteral}{"tidal\_mixing\_init: Unrecognized setting "}// &
305             \textcolor{stringliteral}{"#define CVMIX\_TIDAL\_SCHEME "}//trim(cvmix\_tidal\_scheme\_str)//\textcolor{stringliteral}{" found in input file."})
306 \textcolor{keywordflow}{      end select}
307 \textcolor{keywordflow}{    endif} \textcolor{comment}{! CS%use\_CVMix\_tidal}
308 
309     \textcolor{comment}{! Read in vertical profile of tidal energy dissipation}
310     \textcolor{keywordflow}{if} ( cs%CVMix\_tidal\_scheme.eq.schmittner .or. .not. cs%use\_CVMix\_tidal) \textcolor{keywordflow}{then}
311       \textcolor{keyword}{call }get\_param(param\_file, mdl, \textcolor{stringliteral}{"INT\_TIDE\_PROFILE"}, int\_tide\_profile\_str, &
312                    \textcolor{stringliteral}{"INT\_TIDE\_PROFILE selects the vertical profile of energy "}//&
313                    \textcolor{stringliteral}{"dissipation with INT\_TIDE\_DISSIPATION. Valid values are:\(\backslash\)n"}//&
314                    \textcolor{stringliteral}{"\(\backslash\)t STLAURENT\_02 - Use the St. Laurent et al exponential \(\backslash\)n"}//&
315                    \textcolor{stringliteral}{"\(\backslash\)t                decay profile.\(\backslash\)n"}//&
316                    \textcolor{stringliteral}{"\(\backslash\)t POLZIN\_09 - Use the Polzin WKB-stretched algebraic \(\backslash\)n"}//&
317                    \textcolor{stringliteral}{"\(\backslash\)t                decay profile."}, &
318                    default=stlaurent\_profile\_string)
319       int\_tide\_profile\_str = uppercase(int\_tide\_profile\_str)
320 
321       \textcolor{keywordflow}{select case} (int\_tide\_profile\_str)
322         \textcolor{keywordflow}{case} (stlaurent\_profile\_string)   ; cs%int\_tide\_profile = stlaurent\_02
323         \textcolor{keywordflow}{case} (polzin\_profile\_string)      ; cs%int\_tide\_profile = polzin\_09
324 \textcolor{keywordflow}{        case default}
325           \textcolor{keyword}{call }mom\_error(fatal, \textcolor{stringliteral}{"tidal\_mixing\_init: Unrecognized setting "}// &
326               \textcolor{stringliteral}{"#define INT\_TIDE\_PROFILE "}//trim(int\_tide\_profile\_str)//\textcolor{stringliteral}{" found in input file."})
327 \textcolor{keywordflow}{      end select}
328 \textcolor{keywordflow}{    endif}
329 
330   \textcolor{keywordflow}{elseif} (cs%use\_CVMix\_tidal) \textcolor{keywordflow}{then}
331         \textcolor{keyword}{call }mom\_error(fatal, \textcolor{stringliteral}{"tidal\_mixing\_init: Cannot set INT\_TIDE\_DISSIPATION to False "}// &
332             \textcolor{stringliteral}{"when USE\_CVMix\_TIDAL is set to True."})
333 \textcolor{keywordflow}{  endif}
334 
335   \textcolor{keyword}{call }get\_param(param\_file, mdl, \textcolor{stringliteral}{"LEE\_WAVE\_DISSIPATION"}, cs%Lee\_wave\_dissipation, &
336                  \textcolor{stringliteral}{"If true, use an lee wave driven dissipation scheme to "}//&
337                  \textcolor{stringliteral}{"drive diapycnal mixing, along the lines of Nikurashin "}//&
338                  \textcolor{stringliteral}{"(2010) and using the St. Laurent et al. (2002) "}//&
339                  \textcolor{stringliteral}{"and Simmons et al. (2004) vertical profile"}, default=.false.)
340   \textcolor{keywordflow}{if} (cs%lee\_wave\_dissipation) \textcolor{keywordflow}{then}
341     \textcolor{keywordflow}{if} (cs%use\_CVMix\_tidal) \textcolor{keywordflow}{then}
342         \textcolor{keyword}{call }mom\_error(fatal, \textcolor{stringliteral}{"tidal\_mixing\_init: Lee wave driven dissipation scheme cannot "}// &
343             \textcolor{stringliteral}{"be used when CVMix tidal mixing scheme is active."})
344 \textcolor{keywordflow}{    endif}
345     \textcolor{keyword}{call }get\_param(param\_file, mdl, \textcolor{stringliteral}{"LEE\_WAVE\_PROFILE"}, tmpstr, &
346                  \textcolor{stringliteral}{"LEE\_WAVE\_PROFILE selects the vertical profile of energy "}//&
347                  \textcolor{stringliteral}{"dissipation with LEE\_WAVE\_DISSIPATION. Valid values are:\(\backslash\)n"}//&
348                  \textcolor{stringliteral}{"\(\backslash\)t STLAURENT\_02 - Use the St. Laurent et al exponential \(\backslash\)n"}//&
349                  \textcolor{stringliteral}{"\(\backslash\)t                decay profile.\(\backslash\)n"}//&
350                  \textcolor{stringliteral}{"\(\backslash\)t POLZIN\_09 - Use the Polzin WKB-stretched algebraic \(\backslash\)n"}//&
351                  \textcolor{stringliteral}{"\(\backslash\)t                decay profile."}, &
352                  default=stlaurent\_profile\_string)
353     tmpstr = uppercase(tmpstr)
354     \textcolor{keywordflow}{select case} (tmpstr)
355       \textcolor{keywordflow}{case} (stlaurent\_profile\_string) ; cs%lee\_wave\_profile = stlaurent\_02
356       \textcolor{keywordflow}{case} (polzin\_profile\_string) ; cs%lee\_wave\_profile = polzin\_09
357 \textcolor{keywordflow}{      case default}
358         \textcolor{keyword}{call }mom\_error(fatal, \textcolor{stringliteral}{"tidal\_mixing\_init: Unrecognized setting "}// &
359             \textcolor{stringliteral}{"#define LEE\_WAVE\_PROFILE "}//trim(tmpstr)//\textcolor{stringliteral}{" found in input file."})
360 \textcolor{keywordflow}{    end select}
361 \textcolor{keywordflow}{  endif}
362 
363   \textcolor{keyword}{call }get\_param(param\_file, mdl, \textcolor{stringliteral}{"INT\_TIDE\_LOWMODE\_DISSIPATION"}, cs%Lowmode\_itidal\_dissipation, &
364                  \textcolor{stringliteral}{"If true, consider mixing due to breaking low modes that "}//&
365                  \textcolor{stringliteral}{"have been remotely generated; as with itidal drag on the "}//&
366                  \textcolor{stringliteral}{"barotropic tide, use an internal tidal dissipation scheme to "}//&
367                  \textcolor{stringliteral}{"drive diapycnal mixing, along the lines of St. Laurent "}//&
368                  \textcolor{stringliteral}{"et al. (2002) and Simmons et al. (2004)."}, default=.false.)
369 
370   \textcolor{keywordflow}{if} ((cs%Int\_tide\_dissipation .and. (cs%int\_tide\_profile == polzin\_09)) .or. &
371       (cs%lee\_wave\_dissipation .and. (cs%lee\_wave\_profile == polzin\_09))) \textcolor{keywordflow}{then}
372     \textcolor{keywordflow}{if} (cs%use\_CVMix\_tidal) \textcolor{keywordflow}{then}
373         \textcolor{keyword}{call }mom\_error(fatal, \textcolor{stringliteral}{"tidal\_mixing\_init: Polzin scheme cannot "}// &
374             \textcolor{stringliteral}{"be used when CVMix tidal mixing scheme is active."})
375 \textcolor{keywordflow}{    endif}
376     \textcolor{keyword}{call }get\_param(param\_file, mdl, \textcolor{stringliteral}{"NU\_POLZIN"}, cs%Nu\_Polzin, &
377                  \textcolor{stringliteral}{"When the Polzin decay profile is used, this is a "}//&
378                  \textcolor{stringliteral}{"non-dimensional constant in the expression for the "}//&
379                  \textcolor{stringliteral}{"vertical scale of decay for the tidal energy dissipation."}, &
380                  units=\textcolor{stringliteral}{"nondim"}, default=0.0697)
381     \textcolor{keyword}{call }get\_param(param\_file, mdl, \textcolor{stringliteral}{"NBOTREF\_POLZIN"}, cs%Nbotref\_Polzin, &
382                  \textcolor{stringliteral}{"When the Polzin decay profile is used, this is the "}//&
383                  \textcolor{stringliteral}{"reference value of the buoyancy frequency at the ocean "}//&
384                  \textcolor{stringliteral}{"bottom in the Polzin formulation for the vertical "}//&
385                  \textcolor{stringliteral}{"scale of decay for the tidal energy dissipation."}, &
386                  units=\textcolor{stringliteral}{"s-1"}, default=9.61e-4, scale=us%T\_to\_s)
387     \textcolor{keyword}{call }get\_param(param\_file, mdl, \textcolor{stringliteral}{"POLZIN\_DECAY\_SCALE\_FACTOR"}, &
388                  cs%Polzin\_decay\_scale\_factor, &
389                  \textcolor{stringliteral}{"When the Polzin decay profile is used, this is a "}//&
390                  \textcolor{stringliteral}{"scale factor for the vertical scale of decay of the tidal "}//&
391                  \textcolor{stringliteral}{"energy dissipation."}, default=1.0, units=\textcolor{stringliteral}{"nondim"})
392     \textcolor{keyword}{call }get\_param(param\_file, mdl, \textcolor{stringliteral}{"POLZIN\_SCALE\_MAX\_FACTOR"}, &
393                  cs%Polzin\_decay\_scale\_max\_factor, &
394                  \textcolor{stringliteral}{"When the Polzin decay profile is used, this is a factor "}//&
395                  \textcolor{stringliteral}{"to limit the vertical scale of decay of the tidal "}//&
396                  \textcolor{stringliteral}{"energy dissipation to POLZIN\_DECAY\_SCALE\_MAX\_FACTOR "}//&
397                  \textcolor{stringliteral}{"times the depth of the ocean."}, units=\textcolor{stringliteral}{"nondim"}, default=1.0)
398     \textcolor{keyword}{call }get\_param(param\_file, mdl, \textcolor{stringliteral}{"POLZIN\_MIN\_DECAY\_SCALE"}, cs%Polzin\_min\_decay\_scale, &
399                  \textcolor{stringliteral}{"When the Polzin decay profile is used, this is the "}//&
400                  \textcolor{stringliteral}{"minimum vertical decay scale for the vertical profile\(\backslash\)n"}//&
401                  \textcolor{stringliteral}{"of internal tide dissipation with the Polzin (2009) formulation"}, &
402                  units=\textcolor{stringliteral}{"m"}, default=0.0, scale=us%m\_to\_Z)
403 \textcolor{keywordflow}{  endif}
404 
405   \textcolor{keywordflow}{if} (cs%Int\_tide\_dissipation .or. cs%Lee\_wave\_dissipation) \textcolor{keywordflow}{then}
406     \textcolor{keyword}{call }get\_param(param\_file, mdl, \textcolor{stringliteral}{"INT\_TIDE\_DECAY\_SCALE"}, cs%Int\_tide\_decay\_scale, &
407                  \textcolor{stringliteral}{"The decay scale away from the bottom for tidal TKE with "}//&
408                  \textcolor{stringliteral}{"the new coding when INT\_TIDE\_DISSIPATION is used."}, &
409                  \textcolor{comment}{!units="m", default=0.0)}
410                  units=\textcolor{stringliteral}{"m"}, default=500.0, scale=us%m\_to\_Z)  \textcolor{comment}{! TODO: confirm this new default}
411     \textcolor{keyword}{call }get\_param(param\_file, mdl, \textcolor{stringliteral}{"MU\_ITIDES"}, cs%Mu\_itides, &
412                  \textcolor{stringliteral}{"A dimensionless turbulent mixing efficiency used with "}//&
413                  \textcolor{stringliteral}{"INT\_TIDE\_DISSIPATION, often 0.2."}, units=\textcolor{stringliteral}{"nondim"}, default=0.2)
414     \textcolor{keyword}{call }get\_param(param\_file, mdl, \textcolor{stringliteral}{"GAMMA\_ITIDES"}, cs%Gamma\_itides, &
415                  \textcolor{stringliteral}{"The fraction of the internal tidal energy that is "}//&
416                  \textcolor{stringliteral}{"dissipated locally with INT\_TIDE\_DISSIPATION. "}//&
417                  \textcolor{stringliteral}{"THIS NAME COULD BE BETTER."}, &
418                  units=\textcolor{stringliteral}{"nondim"}, default=0.3333)
419     \textcolor{keyword}{call }get\_param(param\_file, mdl, \textcolor{stringliteral}{"MIN\_ZBOT\_ITIDES"}, cs%min\_zbot\_itides, &
420                  \textcolor{stringliteral}{"Turn off internal tidal dissipation when the total "}//&
421                  \textcolor{stringliteral}{"ocean depth is less than this value."}, units=\textcolor{stringliteral}{"m"}, default=0.0, scale=us%m\_to\_Z)
422 \textcolor{keywordflow}{  endif}
423 
424   \textcolor{keywordflow}{if} ( (cs%Int\_tide\_dissipation .or. cs%Lee\_wave\_dissipation) .and. &
425         .not. cs%use\_CVMix\_tidal) \textcolor{keywordflow}{then}
426 
427     \textcolor{keyword}{call }safe\_alloc\_ptr(cs%Nb,isd,ied,jsd,jed)
428     \textcolor{keyword}{call }safe\_alloc\_ptr(cs%h2,isd,ied,jsd,jed)
429     \textcolor{keyword}{call }safe\_alloc\_ptr(cs%TKE\_itidal,isd,ied,jsd,jed)
430     \textcolor{keyword}{call }safe\_alloc\_ptr(cs%mask\_itidal,isd,ied,jsd,jed) ; cs%mask\_itidal(:,:) = 1.0
431 
432     \textcolor{keyword}{call }get\_param(param\_file, mdl, \textcolor{stringliteral}{"KAPPA\_ITIDES"}, cs%kappa\_itides, &
433                  \textcolor{stringliteral}{"A topographic wavenumber used with INT\_TIDE\_DISSIPATION. "}//&
434                  \textcolor{stringliteral}{"The default is 2pi/10 km, as in St.Laurent et al. 2002."}, &
435                  units=\textcolor{stringliteral}{"m-1"}, default=8.e-4*atan(1.0), scale=us%Z\_to\_m)
436 
437     \textcolor{keyword}{call }get\_param(param\_file, mdl, \textcolor{stringliteral}{"UTIDE"}, cs%utide, &
438                  \textcolor{stringliteral}{"The constant tidal amplitude used with INT\_TIDE\_DISSIPATION."}, &
439                  units=\textcolor{stringliteral}{"m s-1"}, default=0.0, scale=us%m\_to\_Z*us%T\_to\_s)
440     \textcolor{keyword}{call }safe\_alloc\_ptr(cs%tideamp,is,ie,js,je) ; cs%tideamp(:,:) = cs%utide
441 
442     \textcolor{keyword}{call }get\_param(param\_file, mdl, \textcolor{stringliteral}{"KAPPA\_H2\_FACTOR"}, cs%kappa\_h2\_factor, &
443                  \textcolor{stringliteral}{"A scaling factor for the roughness amplitude with "}//&
444                  \textcolor{stringliteral}{"INT\_TIDE\_DISSIPATION."},  units=\textcolor{stringliteral}{"nondim"}, default=1.0)
445     \textcolor{keyword}{call }get\_param(param\_file, mdl, \textcolor{stringliteral}{"TKE\_ITIDE\_MAX"}, cs%TKE\_itide\_max, &
446                  \textcolor{stringliteral}{"The maximum internal tide energy source available to mix "}//&
447                  \textcolor{stringliteral}{"above the bottom boundary layer with INT\_TIDE\_DISSIPATION."}, &
448                  units=\textcolor{stringliteral}{"W m-2"}, default=1.0e3, scale=us%W\_m2\_to\_RZ3\_T3)
449 
450     \textcolor{keyword}{call }get\_param(param\_file, mdl, \textcolor{stringliteral}{"READ\_TIDEAMP"}, read\_tideamp, &
451                  \textcolor{stringliteral}{"If true, read a file (given by TIDEAMP\_FILE) containing "}//&
452                  \textcolor{stringliteral}{"the tidal amplitude with INT\_TIDE\_DISSIPATION."}, default=.false.)
453     \textcolor{keywordflow}{if} (read\_tideamp) \textcolor{keywordflow}{then}
454       \textcolor{keywordflow}{if} (cs%use\_CVMix\_tidal) \textcolor{keywordflow}{then}
455           \textcolor{keyword}{call }mom\_error(fatal, \textcolor{stringliteral}{"tidal\_mixing\_init: Tidal amplitude files are "}// &
456               \textcolor{stringliteral}{"not compatible with CVMix tidal mixing. "})
457 \textcolor{keywordflow}{      endif}
458       \textcolor{keyword}{call }get\_param(param\_file, mdl, \textcolor{stringliteral}{"TIDEAMP\_FILE"}, tideamp\_file, &
459                  \textcolor{stringliteral}{"The path to the file containing the spatially varying "}//&
460                  \textcolor{stringliteral}{"tidal amplitudes with INT\_TIDE\_DISSIPATION."}, default=\textcolor{stringliteral}{"tideamp.nc"})
461       filename = trim(cs%inputdir) // trim(tideamp\_file)
462       \textcolor{keyword}{call }log\_param(param\_file, mdl, \textcolor{stringliteral}{"INPUTDIR/TIDEAMP\_FILE"}, filename)
463       \textcolor{keyword}{call }mom\_read\_data(filename, \textcolor{stringliteral}{'tideamp'}, cs%tideamp, g%domain, timelevel=1, scale=us%m\_to\_Z*us%T\_to\_s)
464 \textcolor{keywordflow}{    endif}
465 
466     \textcolor{keyword}{call }get\_param(param\_file, mdl, \textcolor{stringliteral}{"H2\_FILE"}, h2\_file, &
467                  \textcolor{stringliteral}{"The path to the file containing the sub-grid-scale "}//&
468                  \textcolor{stringliteral}{"topographic roughness amplitude with INT\_TIDE\_DISSIPATION."}, &
469                  fail\_if\_missing=(.not.cs%use\_CVMix\_tidal))
470     filename = trim(cs%inputdir) // trim(h2\_file)
471     \textcolor{keyword}{call }log\_param(param\_file, mdl, \textcolor{stringliteral}{"INPUTDIR/H2\_FILE"}, filename)
472     \textcolor{keyword}{call }mom\_read\_data(filename, \textcolor{stringliteral}{'h2'}, cs%h2, g%domain, timelevel=1, scale=us%m\_to\_Z**2)
473 
474     \textcolor{keyword}{call }get\_param(param\_file, mdl, \textcolor{stringliteral}{"FRACTIONAL\_ROUGHNESS\_MAX"}, max\_frac\_rough, &
475                  \textcolor{stringliteral}{"The maximum topographic roughness amplitude as a fraction of the mean depth, "}//&
476                  \textcolor{stringliteral}{"or a negative value for no limitations on roughness."}, &
477                  units=\textcolor{stringliteral}{"nondim"}, default=0.1)
478 
479     \textcolor{keywordflow}{do} j=js,je ; \textcolor{keywordflow}{do} i=is,ie
480       \textcolor{keywordflow}{if} (g%bathyT(i,j) < cs%min\_zbot\_itides) cs%mask\_itidal(i,j) = 0.0
481       cs%tideamp(i,j) = cs%tideamp(i,j) * cs%mask\_itidal(i,j) * g%mask2dT(i,j)
482 
483       \textcolor{comment}{! Restrict rms topo to a fraction (often 10 percent) of the column depth.}
484       \textcolor{keywordflow}{if} (cs%answers\_2018 .and. (max\_frac\_rough >= 0.0)) \textcolor{keywordflow}{then}
485         hamp = min(max\_frac\_rough*g%bathyT(i,j), sqrt(cs%h2(i,j)))
486         cs%h2(i,j) = hamp*hamp
487       \textcolor{keywordflow}{else}
488         \textcolor{keywordflow}{if} (max\_frac\_rough >= 0.0) &
489           cs%h2(i,j) = min((max\_frac\_rough*g%bathyT(i,j))**2, cs%h2(i,j))
490 \textcolor{keywordflow}{      endif}
491 
492       utide = cs%tideamp(i,j)
493       \textcolor{comment}{! Compute the fixed part of internal tidal forcing.}
494       \textcolor{comment}{! The units here are [R Z3 T-2 ~> J m-2 = kg s-2] here.}
495       cs%TKE\_itidal(i,j) = 0.5 * cs%kappa\_h2\_factor * gv%Rho0 * &
496            cs%kappa\_itides * cs%h2(i,j) * utide*utide
497 \textcolor{keywordflow}{    enddo} ;\textcolor{keywordflow}{ enddo}
498 
499 \textcolor{keywordflow}{  endif}
500 
501   \textcolor{keywordflow}{if} (cs%Lee\_wave\_dissipation) \textcolor{keywordflow}{then}
502 
503     \textcolor{keyword}{call }get\_param(param\_file, mdl, \textcolor{stringliteral}{"NIKURASHIN\_TKE\_INPUT\_FILE"},niku\_tke\_input\_file, &
504                  \textcolor{stringliteral}{"The path to the file containing the TKE input from lee "}//&
505                  \textcolor{stringliteral}{"wave driven mixing. Used with LEE\_WAVE\_DISSIPATION."}, &
506                  fail\_if\_missing=.true.)
507     \textcolor{keyword}{call }get\_param(param\_file, mdl, \textcolor{stringliteral}{"NIKURASHIN\_SCALE"},niku\_scale, &
508                  \textcolor{stringliteral}{"A non-dimensional factor by which to scale the lee-wave "}//&
509                  \textcolor{stringliteral}{"driven TKE input. Used with LEE\_WAVE\_DISSIPATION."}, &
510                  units=\textcolor{stringliteral}{"nondim"}, default=1.0)
511 
512     filename = trim(cs%inputdir) // trim(niku\_tke\_input\_file)
513     \textcolor{keyword}{call }log\_param(param\_file, mdl, \textcolor{stringliteral}{"INPUTDIR/NIKURASHIN\_TKE\_INPUT\_FILE"}, &
514                    filename)
515     \textcolor{keyword}{call }safe\_alloc\_ptr(cs%TKE\_Niku,is,ie,js,je) ; cs%TKE\_Niku(:,:) = 0.0
516     \textcolor{keyword}{call }mom\_read\_data(filename, \textcolor{stringliteral}{'TKE\_input'}, cs%TKE\_Niku, g%domain, timelevel=1, &  \textcolor{comment}{! ??? timelevel -aja}
517                        scale=niku\_scale*us%W\_m2\_to\_RZ3\_T3)
518 
519     \textcolor{keyword}{call }get\_param(param\_file, mdl, \textcolor{stringliteral}{"GAMMA\_NIKURASHIN"},cs%Gamma\_lee, &
520                  \textcolor{stringliteral}{"The fraction of the lee wave energy that is dissipated "}//&
521                  \textcolor{stringliteral}{"locally with LEE\_WAVE\_DISSIPATION."}, units=\textcolor{stringliteral}{"nondim"}, &
522                  default=0.3333)
523     \textcolor{keyword}{call }get\_param(param\_file, mdl, \textcolor{stringliteral}{"DECAY\_SCALE\_FACTOR\_LEE"},cs%Decay\_scale\_factor\_lee, &
524                  \textcolor{stringliteral}{"Scaling for the vertical decay scaleof the local "}//&
525                  \textcolor{stringliteral}{"dissipation of lee waves dissipation."}, units=\textcolor{stringliteral}{"nondim"}, &
526                  default=1.0)
527   \textcolor{keywordflow}{else}
528     cs%Decay\_scale\_factor\_lee = -9.e99 \textcolor{comment}{! This should never be used if CS%Lee\_wave\_dissipation = False}
529 \textcolor{keywordflow}{  endif}
530 
531   \textcolor{comment}{! Configure CVMix}
532   \textcolor{keywordflow}{if} (cs%use\_CVMix\_tidal) \textcolor{keywordflow}{then}
533 
534     \textcolor{comment}{! Read in CVMix params}
535     \textcolor{comment}{!call openParameterBlock(param\_file,'CVMix\_TIDAL')}
536     \textcolor{keyword}{call }get\_param(param\_file, mdl, \textcolor{stringliteral}{"TIDAL\_MAX\_COEF"}, cs%tidal\_max\_coef, &
537                    \textcolor{stringliteral}{"largest acceptable value for tidal diffusivity"}, &
538                    units=\textcolor{stringliteral}{"m^2/s"}, default=50e-4) \textcolor{comment}{! the default is 50e-4 in CVMix, 100e-4 in POP.}
539     \textcolor{keyword}{call }get\_param(param\_file, mdl, \textcolor{stringliteral}{"TIDAL\_DISS\_LIM\_TC"}, cs%tidal\_diss\_lim\_tc, &
540                    \textcolor{stringliteral}{"Min allowable depth for dissipation for tidal-energy-constituent data. "}//&
541                    \textcolor{stringliteral}{"No dissipation contribution is applied above TIDAL\_DISS\_LIM\_TC."}, &
542                    units=\textcolor{stringliteral}{"m"}, default=0.0, scale=us%m\_to\_Z)
543     \textcolor{keyword}{call }get\_param(param\_file, mdl, \textcolor{stringliteral}{"TIDAL\_ENERGY\_FILE"},tidal\_energy\_file, &
544                  \textcolor{stringliteral}{"The path to the file containing tidal energy "}//&
545                  \textcolor{stringliteral}{"dissipation. Used with CVMix tidal mixing schemes."}, &
546                  fail\_if\_missing=.true.)
547     \textcolor{keyword}{call }get\_param(param\_file, mdl, \textcolor{stringliteral}{'MIN\_THICKNESS'}, cs%min\_thickness, default=0.001, &
548                    do\_not\_log=.true.)
549     \textcolor{keyword}{call }get\_param(param\_file, mdl, \textcolor{stringliteral}{"PRANDTL\_TIDAL"}, prandtl\_tidal, &
550                    \textcolor{stringliteral}{"Prandtl number used by CVMix tidal mixing schemes "}//&
551                    \textcolor{stringliteral}{"to convert vertical diffusivities into viscosities."}, &
552                     units=\textcolor{stringliteral}{"nondim"}, default=1.0, &
553                    do\_not\_log=.true.)
554     \textcolor{keyword}{call }cvmix\_put(cs%CVMix\_glb\_params,\textcolor{stringliteral}{'Prandtl'},prandtl\_tidal)
555 
556     tidal\_energy\_file = trim(cs%inputdir) // trim(tidal\_energy\_file)
557     \textcolor{keyword}{call }get\_param(param\_file, mdl, \textcolor{stringliteral}{"TIDAL\_ENERGY\_TYPE"},tidal\_energy\_type, &
558                  \textcolor{stringliteral}{"The type of input tidal energy flux dataset. Valid values are"}//&
559                    \textcolor{stringliteral}{"\(\backslash\)t Jayne\(\backslash\)n"}//&
560                    \textcolor{stringliteral}{"\(\backslash\)t ER03 \(\backslash\)n"},&
561                  fail\_if\_missing=.true.)
562     \textcolor{comment}{! Check whether tidal energy input format and CVMix tidal mixing scheme are consistent}
563     \textcolor{keywordflow}{if} ( .not. ( &
564           (uppercase(tidal\_energy\_type(1:4)).eq.\textcolor{stringliteral}{'JAYN'} .and. cs%CVMix\_tidal\_scheme.eq.simmons).or. &
565           (uppercase(tidal\_energy\_type(1:4)).eq.\textcolor{stringliteral}{'ER03'} .and. cs%CVMix\_tidal\_scheme.eq.schmittner) ) )\textcolor{keywordflow}{then}
566         \textcolor{keyword}{call }mom\_error(fatal, \textcolor{stringliteral}{"tidal\_mixing\_init: Tidal energy file type ("}//&
567                       trim(tidal\_energy\_type)//\textcolor{stringliteral}{") is incompatible with CVMix tidal "}//&
568                       \textcolor{stringliteral}{" mixing scheme: "}//trim(cvmix\_tidal\_scheme\_str) )
569 \textcolor{keywordflow}{    endif}
570     cvmix\_tidal\_scheme\_str = lowercase(cvmix\_tidal\_scheme\_str)
571 
572     \textcolor{comment}{! Set up CVMix}
573     \textcolor{keyword}{call }cvmix\_init\_tidal(cvmix\_tidal\_params\_user = cs%CVMix\_tidal\_params,    &
574                           mix\_scheme              = cvmix\_tidal\_scheme\_str,   &
575                           efficiency              = cs%Mu\_itides,             &
576                           vertical\_decay\_scale    = cs%int\_tide\_decay\_scale*us%Z\_to\_m,  &
577                           max\_coefficient         = cs%tidal\_max\_coef,        &
578                           local\_mixing\_frac       = cs%Gamma\_itides,          &
579                           depth\_cutoff            = cs%min\_zbot\_itides*us%Z\_to\_m)
580 
581     \textcolor{keyword}{call }read\_tidal\_energy(g, us, tidal\_energy\_type, tidal\_energy\_file, cs)
582 
583     \textcolor{comment}{!call closeParameterBlock(param\_file)}
584 
585 \textcolor{keywordflow}{  endif} \textcolor{comment}{! CVMix on}
586 
587   \textcolor{comment}{! Register Diagnostics fields}
588 
589   \textcolor{keywordflow}{if} (cs%Int\_tide\_dissipation .or. cs%Lee\_wave\_dissipation .or. &
590       cs%Lowmode\_itidal\_dissipation) \textcolor{keywordflow}{then}
591 
592     cs%id\_Kd\_itidal = register\_diag\_field(\textcolor{stringliteral}{'ocean\_model'},\textcolor{stringliteral}{'Kd\_itides'},diag%axesTi,time, &
593          \textcolor{stringliteral}{'Internal Tide Driven Diffusivity'}, \textcolor{stringliteral}{'m2 s-1'}, conversion=us%Z2\_T\_to\_m2\_s)
594 
595     \textcolor{keywordflow}{if} (cs%use\_CVMix\_tidal) \textcolor{keywordflow}{then}
596       cs%id\_N2\_int = register\_diag\_field(\textcolor{stringliteral}{'ocean\_model'},\textcolor{stringliteral}{'N2\_int'},diag%axesTi,time, &
597           \textcolor{stringliteral}{'Bouyancy frequency squared, at interfaces'}, \textcolor{stringliteral}{'s-2'}, conversion=us%s\_to\_T**2)\textcolor{comment}{}
598 \textcolor{comment}{      !> TODO: add units}
599       cs%id\_Simmons\_coeff = register\_diag\_field(\textcolor{stringliteral}{'ocean\_model'},\textcolor{stringliteral}{'Simmons\_coeff'},diag%axesT1,time, &
600            \textcolor{stringliteral}{'time-invariant portion of the tidal mixing coefficient using the Simmons'}, \textcolor{stringliteral}{''})
601       cs%id\_Schmittner\_coeff = register\_diag\_field(\textcolor{stringliteral}{'ocean\_model'},\textcolor{stringliteral}{'Schmittner\_coeff'},diag%axesTL,time, &
602            \textcolor{stringliteral}{'time-invariant portion of the tidal mixing coefficient using the Schmittner'}, \textcolor{stringliteral}{''})
603       cs%id\_tidal\_qe\_md = register\_diag\_field(\textcolor{stringliteral}{'ocean\_model'},\textcolor{stringliteral}{'tidal\_qe\_md'},diag%axesTL,time, &
604            \textcolor{stringliteral}{'input tidal energy dissipated locally interpolated to model vertical coordinates'}, \textcolor{stringliteral}{''})
605       cs%id\_vert\_dep = register\_diag\_field(\textcolor{stringliteral}{'ocean\_model'},\textcolor{stringliteral}{'vert\_dep'},diag%axesTi,time, &
606            \textcolor{stringliteral}{'vertical deposition function needed for Simmons et al tidal  mixing'}, \textcolor{stringliteral}{''})
607 
608     \textcolor{keywordflow}{else}
609       cs%id\_TKE\_itidal = register\_diag\_field(\textcolor{stringliteral}{'ocean\_model'},\textcolor{stringliteral}{'TKE\_itidal'},diag%axesT1,time, &
610           \textcolor{stringliteral}{'Internal Tide Driven Turbulent Kinetic Energy'}, &
611           \textcolor{stringliteral}{'W m-2'}, conversion=us%RZ3\_T3\_to\_W\_m2)
612       cs%id\_Nb = register\_diag\_field(\textcolor{stringliteral}{'ocean\_model'},\textcolor{stringliteral}{'Nb'},diag%axesT1,time, &
613            \textcolor{stringliteral}{'Bottom Buoyancy Frequency'}, \textcolor{stringliteral}{'s-1'}, conversion=us%s\_to\_T)
614 
615       cs%id\_Kd\_lowmode = register\_diag\_field(\textcolor{stringliteral}{'ocean\_model'},\textcolor{stringliteral}{'Kd\_lowmode'},diag%axesTi,time, &
616            \textcolor{stringliteral}{'Internal Tide Driven Diffusivity (from propagating low modes)'}, &
617            \textcolor{stringliteral}{'m2 s-1'}, conversion=us%Z2\_T\_to\_m2\_s)
618 
619       cs%id\_Fl\_itidal = register\_diag\_field(\textcolor{stringliteral}{'ocean\_model'},\textcolor{stringliteral}{'Fl\_itides'},diag%axesTi,time, &
620           \textcolor{stringliteral}{'Vertical flux of tidal turbulent dissipation'}, &
621           \textcolor{stringliteral}{'m3 s-3'}, conversion=(us%Z\_to\_m**3*us%s\_to\_T**3))
622 
623       cs%id\_Fl\_lowmode = register\_diag\_field(\textcolor{stringliteral}{'ocean\_model'},\textcolor{stringliteral}{'Fl\_lowmode'},diag%axesTi,time, &
624            \textcolor{stringliteral}{'Vertical flux of tidal turbulent dissipation (from propagating low modes)'}, &
625            \textcolor{stringliteral}{'m3 s-3'}, conversion=(us%Z\_to\_m**3*us%s\_to\_T**3))
626 
627       cs%id\_Polzin\_decay\_scale = register\_diag\_field(\textcolor{stringliteral}{'ocean\_model'},\textcolor{stringliteral}{'Polzin\_decay\_scale'},diag%axesT1,time, &
628            \textcolor{stringliteral}{'Vertical decay scale for the tidal turbulent dissipation with Polzin scheme'}, &
629            \textcolor{stringliteral}{'m'}, conversion=us%Z\_to\_m)
630 
631       cs%id\_Polzin\_decay\_scale\_scaled = register\_diag\_field(\textcolor{stringliteral}{'ocean\_model'}, &
632            \textcolor{stringliteral}{'Polzin\_decay\_scale\_scaled'}, diag%axesT1, time, &
633            \textcolor{stringliteral}{'Vertical decay scale for the tidal turbulent dissipation with Polzin scheme, '}// &
634            \textcolor{stringliteral}{'scaled by N2\_bot/N2\_meanz'}, \textcolor{stringliteral}{'m'}, conversion=us%Z\_to\_m)
635 
636       cs%id\_N2\_bot = register\_diag\_field(\textcolor{stringliteral}{'ocean\_model'},\textcolor{stringliteral}{'N2\_b'},diag%axesT1,time, &
637            \textcolor{stringliteral}{'Bottom Buoyancy frequency squared'}, \textcolor{stringliteral}{'s-2'}, conversion=us%s\_to\_T**2)
638 
639       cs%id\_N2\_meanz = register\_diag\_field(\textcolor{stringliteral}{'ocean\_model'},\textcolor{stringliteral}{'N2\_meanz'}, diag%axesT1, time, &
640            \textcolor{stringliteral}{'Buoyancy frequency squared averaged over the water column'}, \textcolor{stringliteral}{'s-2'}, conversion=us%s\_to\_T**2)
641 
642       cs%id\_Kd\_Itidal\_Work = register\_diag\_field(\textcolor{stringliteral}{'ocean\_model'},\textcolor{stringliteral}{'Kd\_Itidal\_Work'},diag%axesTL,time, &
643            \textcolor{stringliteral}{'Work done by Internal Tide Diapycnal Mixing'}, &
644            \textcolor{stringliteral}{'W m-2'}, conversion=us%RZ3\_T3\_to\_W\_m2)
645 
646       cs%id\_Kd\_Niku\_Work = register\_diag\_field(\textcolor{stringliteral}{'ocean\_model'},\textcolor{stringliteral}{'Kd\_Nikurashin\_Work'},diag%axesTL,time, &
647            \textcolor{stringliteral}{'Work done by Nikurashin Lee Wave Drag Scheme'}, &
648            \textcolor{stringliteral}{'W m-2'}, conversion=us%RZ3\_T3\_to\_W\_m2)
649 
650       cs%id\_Kd\_Lowmode\_Work = register\_diag\_field(\textcolor{stringliteral}{'ocean\_model'},\textcolor{stringliteral}{'Kd\_Lowmode\_Work'},diag%axesTL,time, &
651            \textcolor{stringliteral}{'Work done by Internal Tide Diapycnal Mixing (low modes)'}, &
652            \textcolor{stringliteral}{'W m-2'}, conversion=us%RZ3\_T3\_to\_W\_m2)
653 
654       \textcolor{keywordflow}{if} (cs%Lee\_wave\_dissipation) \textcolor{keywordflow}{then}
655         cs%id\_TKE\_leewave = register\_diag\_field(\textcolor{stringliteral}{'ocean\_model'},\textcolor{stringliteral}{'TKE\_leewave'},diag%axesT1,time, &
656             \textcolor{stringliteral}{'Lee wave Driven Turbulent Kinetic Energy'}, &
657             \textcolor{stringliteral}{'W m-2'}, conversion=us%RZ3\_T3\_to\_W\_m2)
658         cs%id\_Kd\_Niku = register\_diag\_field(\textcolor{stringliteral}{'ocean\_model'},\textcolor{stringliteral}{'Kd\_Nikurashin'},diag%axesTi,time, &
659             \textcolor{stringliteral}{'Lee Wave Driven Diffusivity'}, \textcolor{stringliteral}{'m2 s-1'}, conversion=us%Z2\_T\_to\_m2\_s)
660 \textcolor{keywordflow}{      endif}
661 \textcolor{keywordflow}{    endif} \textcolor{comment}{! S%use\_CVMix\_tidal}
662 \textcolor{keywordflow}{  endif}
663 
\end{DoxyCode}
