\hypertarget{namespacemom__internal__tides}{}\section{mom\+\_\+internal\+\_\+tides Module Reference}
\label{namespacemom__internal__tides}\index{mom\+\_\+internal\+\_\+tides@{mom\+\_\+internal\+\_\+tides}}


\subsection{Detailed Description}
Subroutines that use the ray-\/tracing equations to propagate the internal tide energy density. 

\begin{DoxyAuthor}{Author}
Benjamin Mater \& Robert Hallberg, 2015 
\end{DoxyAuthor}
\subsection*{Data Types}
\begin{DoxyCompactItemize}
\item 
type \hyperlink{structmom__internal__tides_1_1int__tide__cs}{int\+\_\+tide\+\_\+cs}
\begin{DoxyCompactList}\small\item\em This control structure has parameters for the M\+O\+M\+\_\+internal\+\_\+tides module. \end{DoxyCompactList}\item 
type \hyperlink{structmom__internal__tides_1_1loop__bounds__type}{loop\+\_\+bounds\+\_\+type}
\begin{DoxyCompactList}\small\item\em A structure with the active energy loop bounds. \end{DoxyCompactList}\end{DoxyCompactItemize}
\subsection*{Functions/\+Subroutines}
\begin{DoxyCompactItemize}
\item 
subroutine, public \hyperlink{namespacemom__internal__tides_aeeeea20ff7fe971846b7539d377f4389}{propagate\+\_\+int\+\_\+tide} (h, tv, cn, T\+K\+E\+\_\+itidal\+\_\+input, vel\+\_\+bt\+Tide, Nb, dt, G, GV, US, CS)
\begin{DoxyCompactList}\small\item\em Calls subroutines in this file that are needed to refract, propagate, and dissipate energy density of the internal tide. \end{DoxyCompactList}\item 
subroutine \hyperlink{namespacemom__internal__tides_a9e8e7b153aef9049c2217658821e3178}{sum\+\_\+en} (G, CS, En, label)
\begin{DoxyCompactList}\small\item\em Checks for energy conservation on computational domain. \end{DoxyCompactList}\item 
subroutine \hyperlink{namespacemom__internal__tides_a73ad407c5ea74fc20e58810937d2addf}{itidal\+\_\+lowmode\+\_\+loss} (G, US, CS, Nb, Ub, En, T\+K\+E\+\_\+loss\+\_\+fixed, T\+K\+E\+\_\+loss, dt, full\+\_\+halos)
\begin{DoxyCompactList}\small\item\em Calculates the energy lost from the propagating internal tide due to scattering over small-\/scale roughness along the lines of Jayne \& St. Laurent (2001). \end{DoxyCompactList}\item 
subroutine, public \hyperlink{namespacemom__internal__tides_aab59eb7eb4e4f422294ed62a97a6a75b}{get\+\_\+lowmode\+\_\+loss} (i, j, G, CS, mechanism, T\+K\+E\+\_\+loss\+\_\+sum)
\begin{DoxyCompactList}\small\item\em This subroutine extracts the energy lost from the propagating internal which has been summed across all angles, frequencies, and modes for a given mechanism and location. \end{DoxyCompactList}\item 
subroutine \hyperlink{namespacemom__internal__tides_a0814f61fee53f0941061056641132493}{refract} (En, cn, freq, dt, G, US, N\+Angle, use\+\_\+\+P\+P\+Mang)
\begin{DoxyCompactList}\small\item\em Implements refraction on the internal waves at a single frequency. \end{DoxyCompactList}\item 
subroutine \hyperlink{namespacemom__internal__tides_ae34593443ab6362445946e9d75528155}{ppm\+\_\+angular\+\_\+advect} (En2d, C\+F\+L\+\_\+ang, Flux\+\_\+\+En, N\+Angle, dt, halo\+\_\+ang)
\begin{DoxyCompactList}\small\item\em This subroutine calculates the 1-\/d flux for advection in angular space using a monotonic piecewise parabolic scheme. This needs to be called from within i and j spatial loops. \end{DoxyCompactList}\item 
subroutine \hyperlink{namespacemom__internal__tides_af70118539fe63af49c203de9bdfafe8a}{propagate} (En, cn, freq, dt, G, US, CS, N\+Angle)
\begin{DoxyCompactList}\small\item\em Propagates internal waves at a single frequency. \end{DoxyCompactList}\item 
subroutine \hyperlink{namespacemom__internal__tides_a66c9354cfdcde3d06a2ebe8775572d23}{propagate\+\_\+corner\+\_\+spread} (En, energized\+\_\+wedge, N\+Angle, speed, dt, G, CS, LB)
\begin{DoxyCompactList}\small\item\em This subroutine does first-\/order corner advection. It was written with the hopes of smoothing out the garden sprinkler effect, but is too numerically diffusive to be of much use as of yet. It is not yet compatible with reflection schemes (B\+DM). \end{DoxyCompactList}\item 
subroutine \hyperlink{namespacemom__internal__tides_a0b300e27b0ec984bfe8b9afe4e89f8ab}{propagate\+\_\+x} (En, speed\+\_\+x, Cgx\+\_\+av, d\+Cgx, dt, G, US, Nangle, CS, LB)
\begin{DoxyCompactList}\small\item\em Propagates the internal wave energy in the logical x-\/direction. \end{DoxyCompactList}\item 
subroutine \hyperlink{namespacemom__internal__tides_ae1a31a7f0db2b05c1d863f022b799c7b}{propagate\+\_\+y} (En, speed\+\_\+y, Cgy\+\_\+av, d\+Cgy, dt, G, US, Nangle, CS, LB)
\begin{DoxyCompactList}\small\item\em Propagates the internal wave energy in the logical y-\/direction. \end{DoxyCompactList}\item 
subroutine \hyperlink{namespacemom__internal__tides_a5470c5a9a8fea70664dbf793c48cef65}{zonal\+\_\+flux\+\_\+en} (u, h, hL, hR, uh, dt, G, US, j, ish, ieh, vol\+\_\+\+C\+FL)
\begin{DoxyCompactList}\small\item\em Evaluates the zonal mass or volume fluxes in a layer. \end{DoxyCompactList}\item 
subroutine \hyperlink{namespacemom__internal__tides_aa1b6ca95d1076457e3b7ca32942be143}{merid\+\_\+flux\+\_\+en} (v, h, hL, hR, vh, dt, G, US, J, ish, ieh, vol\+\_\+\+C\+FL)
\begin{DoxyCompactList}\small\item\em Evaluates the meridional mass or volume fluxes in a layer. \end{DoxyCompactList}\item 
subroutine \hyperlink{namespacemom__internal__tides_a6c622bfe3863b8fcea98c78104477491}{reflect} (En, N\+Angle, CS, G, LB)
\begin{DoxyCompactList}\small\item\em Reflection of the internal waves at a single frequency. \end{DoxyCompactList}\item 
subroutine \hyperlink{namespacemom__internal__tides_a0a20d26531e245a26385d1c056b6a5b6}{teleport} (En, N\+Angle, CS, G, LB)
\begin{DoxyCompactList}\small\item\em Moves energy across lines of partial reflection to prevent reflection of energy that is supposed to get across. \end{DoxyCompactList}\item 
subroutine \hyperlink{namespacemom__internal__tides_a6643978290bfd9080c1218c338acd605}{correct\+\_\+halo\+\_\+rotation} (En, test, G, N\+Angle)
\begin{DoxyCompactList}\small\item\em Rotates points in the halos where required to accommodate changes in grid orientation, such as at the tripolar fold. \end{DoxyCompactList}\item 
subroutine \hyperlink{namespacemom__internal__tides_afa863318cc960c0be08672731ce6f225}{ppm\+\_\+reconstruction\+\_\+x} (h\+\_\+in, h\+\_\+l, h\+\_\+r, G, LB, simple\+\_\+2nd)
\begin{DoxyCompactList}\small\item\em Calculates left/right edge values for P\+PM reconstruction in x-\/direction. \end{DoxyCompactList}\item 
subroutine \hyperlink{namespacemom__internal__tides_a6c3dc6d74dfd6e5b13d5f710899be278}{ppm\+\_\+reconstruction\+\_\+y} (h\+\_\+in, h\+\_\+l, h\+\_\+r, G, LB, simple\+\_\+2nd)
\begin{DoxyCompactList}\small\item\em Calculates left/right edge valus for P\+PM reconstruction in y-\/direction. \end{DoxyCompactList}\item 
subroutine \hyperlink{namespacemom__internal__tides_a16dd5b071e0fc87eb04c32f602c08aa5}{ppm\+\_\+limit\+\_\+pos} (h\+\_\+in, h\+\_\+L, h\+\_\+R, h\+\_\+min, G, iis, iie, jis, jie)
\begin{DoxyCompactList}\small\item\em Limits the left/right edge values of the P\+PM reconstruction to give a reconstruction that is positive-\/definite. Here this is reinterpreted as giving a constant thickness if the mean thickness is less than h\+\_\+min, with a minimum of h\+\_\+min otherwise. \end{DoxyCompactList}\item 
subroutine, public \hyperlink{namespacemom__internal__tides_a48431ac355c6fa3de7548bfdec620eb0}{internal\+\_\+tides\+\_\+init} (Time, G, GV, US, param\+\_\+file, diag, CS)
\begin{DoxyCompactList}\small\item\em This subroutine initializes the internal tides module. \end{DoxyCompactList}\item 
subroutine, public \hyperlink{namespacemom__internal__tides_ad4a7f6d606c46123f12b39dd98f71b37}{internal\+\_\+tides\+\_\+end} (CS)
\begin{DoxyCompactList}\small\item\em This subroutine deallocates the memory associated with the internal tides control structure. \end{DoxyCompactList}\end{DoxyCompactItemize}


\subsection{Function/\+Subroutine Documentation}
\mbox{\Hypertarget{namespacemom__internal__tides_a6643978290bfd9080c1218c338acd605}\label{namespacemom__internal__tides_a6643978290bfd9080c1218c338acd605}} 
\index{mom\+\_\+internal\+\_\+tides@{mom\+\_\+internal\+\_\+tides}!correct\+\_\+halo\+\_\+rotation@{correct\+\_\+halo\+\_\+rotation}}
\index{correct\+\_\+halo\+\_\+rotation@{correct\+\_\+halo\+\_\+rotation}!mom\+\_\+internal\+\_\+tides@{mom\+\_\+internal\+\_\+tides}}
\subsubsection{\texorpdfstring{correct\+\_\+halo\+\_\+rotation()}{correct\_halo\_rotation()}}
{\footnotesize\ttfamily subroutine mom\+\_\+internal\+\_\+tides\+::correct\+\_\+halo\+\_\+rotation (\begin{DoxyParamCaption}\item[{real, dimension(\+:,\+:,\+:,\+:,\+:), intent(inout)}]{En,  }\item[{real, dimension(szi\+\_\+(g),szj\+\_\+(g),2), intent(in)}]{test,  }\item[{type(ocean\+\_\+grid\+\_\+type), intent(in)}]{G,  }\item[{integer, intent(in)}]{N\+Angle }\end{DoxyParamCaption})\hspace{0.3cm}{\ttfamily [private]}}



Rotates points in the halos where required to accommodate changes in grid orientation, such as at the tripolar fold. 


\begin{DoxyParams}[1]{Parameters}
\mbox{\tt in}  & {\em g} & The ocean\textquotesingle{}s grid structure\\
\hline
\mbox{\tt in,out}  & {\em en} & The internal gravity wave energy density as a function of space, angular orientation, frequency, and vertical mode \mbox{[}R Z3 T-\/2 $\sim$$>$ J m-\/2\mbox{]}.\\
\hline
\mbox{\tt in}  & {\em test} & An x-\/unit vector that has been passed through\\
\hline
\mbox{\tt in}  & {\em nangle} & The number of wave orientations in the discretized wave energy spectrum. \\
\hline
\end{DoxyParams}


Definition at line 1812 of file M\+O\+M\+\_\+internal\+\_\+tides.\+F90.


\begin{DoxyCode}
1812   \textcolor{keywordtype}{type}(ocean\_grid\_type),      \textcolor{keywordtype}{intent(in)}    :: g\textcolor{comment}{    !< The ocean's grid structure}
1813   \textcolor{keywordtype}{real}, \textcolor{keywordtype}{dimension(:,:,:,:,:)}, \textcolor{keywordtype}{intent(inout)} :: en\textcolor{comment}{   !< The internal gravity wave energy density as a}
1814 \textcolor{comment}{                                       !! function of space, angular orientation, frequency,}
1815 \textcolor{comment}{                                       !! and vertical mode [R Z3 T-2 ~> J m-2].}
1816   \textcolor{keywordtype}{real}, \textcolor{keywordtype}{dimension(SZI\_(G),SZJ\_(G),2)}, &
1817                               \textcolor{keywordtype}{intent(in)}    :: test\textcolor{comment}{ !< An x-unit vector that has been passed through}
1818 \textcolor{comment}{                                       !! the halo updates, to enable the rotation of the}
1819 \textcolor{comment}{                                       !! wave energies in the halo region to be corrected.}
1820   \textcolor{keywordtype}{integer},                    \textcolor{keywordtype}{intent(in)}    :: nangle\textcolor{comment}{ !< The number of wave orientations in the}
1821 \textcolor{comment}{                                                      !! discretized wave energy spectrum.}
1822   \textcolor{comment}{! Local variables}
1823   \textcolor{keywordtype}{real}, \textcolor{keywordtype}{dimension(G%isd:G%ied,NAngle)} :: en2d
1824   \textcolor{keywordtype}{integer}, \textcolor{keywordtype}{dimension(G%isd:G%ied)} :: a\_shift
1825   \textcolor{keywordtype}{integer} :: i\_first, i\_last, a\_new
1826   \textcolor{keywordtype}{integer} :: a, i, j, isd, ied, jsd, jed, m, fr
1827   \textcolor{keywordtype}{character(len=160)} :: mesg  \textcolor{comment}{! The text of an error message}
1828   isd = g%isd ; ied = g%ied ; jsd = g%jsd ; jed = g%jed
1829 
1830   \textcolor{keywordflow}{do} j=jsd,jed
1831     i\_first = ied+1 ; i\_last = isd-1
1832     \textcolor{keywordflow}{do} i=isd,ied
1833       a\_shift(i) = 0
1834       \textcolor{keywordflow}{if} (test(i,j,1) /= 1.0) \textcolor{keywordflow}{then}
1835         \textcolor{keywordflow}{if} (i<i\_first) i\_first = i
1836         \textcolor{keywordflow}{if} (i>i\_last) i\_last = i
1837 
1838         \textcolor{keywordflow}{if} (test(i,j,1) == -1.0) \textcolor{keywordflow}{then} ; a\_shift(i) = nangle/2
1839         \textcolor{keywordflow}{elseif} (test(i,j,2) == 1.0) \textcolor{keywordflow}{then} ; a\_shift(i) = -nangle/4
1840         \textcolor{keywordflow}{elseif} (test(i,j,2) == -1.0) \textcolor{keywordflow}{then} ; a\_shift(i) = nangle/4
1841         \textcolor{keywordflow}{else}
1842           \textcolor{keyword}{write}(mesg,\textcolor{stringliteral}{'("Unrecognized rotation test vector ",2ES9.2," at ",F7.2," E, ",&}
1843 \textcolor{stringliteral}{}\textcolor{stringliteral}{                       &F7.2," N; i,j=",2i4)'}) &
1844                 test(i,j,1), test(i,j,2), g%GeoLonT(i,j), g%GeoLatT(i,j), i, j
1845           \textcolor{keyword}{call }mom\_error(fatal, mesg)
1846 \textcolor{keywordflow}{        endif}
1847 \textcolor{keywordflow}{      endif}
1848 \textcolor{keywordflow}{    enddo}
1849 
1850     \textcolor{keywordflow}{if} (i\_first <= i\_last) \textcolor{keywordflow}{then}
1851       \textcolor{comment}{! At least one point in this row needs to be rotated.}
1852       \textcolor{keywordflow}{do} m=1,\textcolor{keyword}{size}(en,5) ; \textcolor{keywordflow}{do} fr=1,\textcolor{keyword}{size}(en,4)
1853         \textcolor{keywordflow}{do} a=1,nangle ; \textcolor{keywordflow}{do} i=i\_first,i\_last ; \textcolor{keywordflow}{if} (a\_shift(i) /= 0) \textcolor{keywordflow}{then}
1854           a\_new = a + a\_shift(i)
1855           \textcolor{keywordflow}{if} (a\_new < 1) a\_new = a\_new + nangle
1856           \textcolor{keywordflow}{if} (a\_new > nangle) a\_new = a\_new - nangle
1857           en2d(i,a\_new) = en(i,j,a,fr,m)
1858 \textcolor{keywordflow}{        endif} ;\textcolor{keywordflow}{ enddo} ;\textcolor{keywordflow}{ enddo}
1859         \textcolor{keywordflow}{do} a=1,nangle ; \textcolor{keywordflow}{do} i=i\_first,i\_last ; \textcolor{keywordflow}{if} (a\_shift(i) /= 0) \textcolor{keywordflow}{then}
1860           en(i,j,a,fr,m) = en2d(i,a)
1861 \textcolor{keywordflow}{        endif} ;\textcolor{keywordflow}{ enddo} ;\textcolor{keywordflow}{ enddo}
1862 \textcolor{keywordflow}{      enddo} ;\textcolor{keywordflow}{ enddo}
1863 \textcolor{keywordflow}{    endif}
1864 \textcolor{keywordflow}{  enddo}
\end{DoxyCode}
\mbox{\Hypertarget{namespacemom__internal__tides_aab59eb7eb4e4f422294ed62a97a6a75b}\label{namespacemom__internal__tides_aab59eb7eb4e4f422294ed62a97a6a75b}} 
\index{mom\+\_\+internal\+\_\+tides@{mom\+\_\+internal\+\_\+tides}!get\+\_\+lowmode\+\_\+loss@{get\+\_\+lowmode\+\_\+loss}}
\index{get\+\_\+lowmode\+\_\+loss@{get\+\_\+lowmode\+\_\+loss}!mom\+\_\+internal\+\_\+tides@{mom\+\_\+internal\+\_\+tides}}
\subsubsection{\texorpdfstring{get\+\_\+lowmode\+\_\+loss()}{get\_lowmode\_loss()}}
{\footnotesize\ttfamily subroutine, public mom\+\_\+internal\+\_\+tides\+::get\+\_\+lowmode\+\_\+loss (\begin{DoxyParamCaption}\item[{integer, intent(in)}]{i,  }\item[{integer, intent(in)}]{j,  }\item[{type(ocean\+\_\+grid\+\_\+type), intent(in)}]{G,  }\item[{type(\hyperlink{structmom__internal__tides_1_1int__tide__cs}{int\+\_\+tide\+\_\+cs}), pointer}]{CS,  }\item[{character(len=$\ast$), intent(in)}]{mechanism,  }\item[{real, intent(out)}]{T\+K\+E\+\_\+loss\+\_\+sum }\end{DoxyParamCaption})}



This subroutine extracts the energy lost from the propagating internal which has been summed across all angles, frequencies, and modes for a given mechanism and location. 

It can be called from another module to get values from this module\textquotesingle{}s (private) CS.


\begin{DoxyParams}[1]{Parameters}
\mbox{\tt in}  & {\em i} & The i-\/index of the value to be reported.\\
\hline
\mbox{\tt in}  & {\em j} & The j-\/index of the value to be reported.\\
\hline
\mbox{\tt in}  & {\em g} & The ocean\textquotesingle{}s grid structure\\
\hline
 & {\em cs} & The control structure returned by a previous call to int\+\_\+tide\+\_\+init.\\
\hline
\mbox{\tt in}  & {\em mechanism} & The named mechanism of loss to return\\
\hline
\mbox{\tt out}  & {\em tke\+\_\+loss\+\_\+sum} & Total energy loss rate due to specified mechanism \mbox{[}R Z3 T-\/3 $\sim$$>$ W m-\/2\mbox{]}. \\
\hline
\end{DoxyParams}


Definition at line 728 of file M\+O\+M\+\_\+internal\+\_\+tides.\+F90.


\begin{DoxyCode}
728   \textcolor{keywordtype}{integer},               \textcolor{keywordtype}{intent(in)}  :: i\textcolor{comment}{   !< The i-index of the value to be reported.}
729   \textcolor{keywordtype}{integer},               \textcolor{keywordtype}{intent(in)}  :: j\textcolor{comment}{   !< The j-index of the value to be reported.}
730   \textcolor{keywordtype}{type}(ocean\_grid\_type), \textcolor{keywordtype}{intent(in)}  :: g\textcolor{comment}{   !< The ocean's grid structure}
731   \textcolor{keywordtype}{type}(int\_tide\_cs),     \textcolor{keywordtype}{pointer}     :: cs\textcolor{comment}{  !< The control structure returned by a}
732 \textcolor{comment}{                                            !! previous call to int\_tide\_init.}
733   \textcolor{keywordtype}{character(len=*)},      \textcolor{keywordtype}{intent(in)}  :: mechanism\textcolor{comment}{    !< The named mechanism of loss to return}
734   \textcolor{keywordtype}{real},                  \textcolor{keywordtype}{intent(out)} :: tke\_loss\_sum\textcolor{comment}{ !< Total energy loss rate due to specified}
735 \textcolor{comment}{                                                     !! mechanism [R Z3 T-3 ~> W m-2].}
736 
737   \textcolor{keywordflow}{if} (mechanism == \textcolor{stringliteral}{'LeakDrag'}) tke\_loss\_sum = cs%tot\_leak\_loss(i,j)   \textcolor{comment}{! not used for mixing yet}
738   \textcolor{keywordflow}{if} (mechanism == \textcolor{stringliteral}{'QuadDrag'}) tke\_loss\_sum = cs%tot\_quad\_loss(i,j)   \textcolor{comment}{! not used for mixing yet}
739   \textcolor{keywordflow}{if} (mechanism == \textcolor{stringliteral}{'WaveDrag'}) tke\_loss\_sum = cs%tot\_itidal\_loss(i,j) \textcolor{comment}{! currently used for mixing}
740   \textcolor{keywordflow}{if} (mechanism == \textcolor{stringliteral}{'Froude'})   tke\_loss\_sum = cs%tot\_Froude\_loss(i,j) \textcolor{comment}{! not used for mixing yet}
741 
\end{DoxyCode}
\mbox{\Hypertarget{namespacemom__internal__tides_ad4a7f6d606c46123f12b39dd98f71b37}\label{namespacemom__internal__tides_ad4a7f6d606c46123f12b39dd98f71b37}} 
\index{mom\+\_\+internal\+\_\+tides@{mom\+\_\+internal\+\_\+tides}!internal\+\_\+tides\+\_\+end@{internal\+\_\+tides\+\_\+end}}
\index{internal\+\_\+tides\+\_\+end@{internal\+\_\+tides\+\_\+end}!mom\+\_\+internal\+\_\+tides@{mom\+\_\+internal\+\_\+tides}}
\subsubsection{\texorpdfstring{internal\+\_\+tides\+\_\+end()}{internal\_tides\_end()}}
{\footnotesize\ttfamily subroutine, public mom\+\_\+internal\+\_\+tides\+::internal\+\_\+tides\+\_\+end (\begin{DoxyParamCaption}\item[{type(\hyperlink{structmom__internal__tides_1_1int__tide__cs}{int\+\_\+tide\+\_\+cs}), pointer}]{CS }\end{DoxyParamCaption})}



This subroutine deallocates the memory associated with the internal tides control structure. 


\begin{DoxyParams}{Parameters}
{\em cs} & A pointer to the control structure returned by a previous call to internal\+\_\+tides\+\_\+init, it will be deallocated here. \\
\hline
\end{DoxyParams}


Definition at line 2549 of file M\+O\+M\+\_\+internal\+\_\+tides.\+F90.


\begin{DoxyCode}
2549   \textcolor{keywordtype}{type}(int\_tide\_cs), \textcolor{keywordtype}{pointer} :: cs\textcolor{comment}{  !< A pointer to the control structure returned by a previous}
2550 \textcolor{comment}{                                    !! call to internal\_tides\_init, it will be deallocated here.}
2551 
2552   \textcolor{keywordflow}{if} (\textcolor{keyword}{associated}(cs)) \textcolor{keywordflow}{then}
2553     \textcolor{keywordflow}{if} (\textcolor{keyword}{associated}(cs%En)) \textcolor{keyword}{deallocate}(cs%En)
2554     \textcolor{keywordflow}{if} (\textcolor{keyword}{allocated}(cs%frequency)) \textcolor{keyword}{deallocate}(cs%frequency)
2555     \textcolor{keywordflow}{if} (\textcolor{keyword}{allocated}(cs%id\_En\_mode)) \textcolor{keyword}{deallocate}(cs%id\_En\_mode)
2556     \textcolor{keywordflow}{if} (\textcolor{keyword}{allocated}(cs%id\_Ub\_mode)) \textcolor{keyword}{deallocate}(cs%id\_Ub\_mode)
2557     \textcolor{keywordflow}{if} (\textcolor{keyword}{allocated}(cs%id\_cp\_mode)) \textcolor{keyword}{deallocate}(cs%id\_cp\_mode)
2558     \textcolor{keyword}{deallocate}(cs)
2559 \textcolor{keywordflow}{  endif}
2560   cs => null()
\end{DoxyCode}
\mbox{\Hypertarget{namespacemom__internal__tides_a48431ac355c6fa3de7548bfdec620eb0}\label{namespacemom__internal__tides_a48431ac355c6fa3de7548bfdec620eb0}} 
\index{mom\+\_\+internal\+\_\+tides@{mom\+\_\+internal\+\_\+tides}!internal\+\_\+tides\+\_\+init@{internal\+\_\+tides\+\_\+init}}
\index{internal\+\_\+tides\+\_\+init@{internal\+\_\+tides\+\_\+init}!mom\+\_\+internal\+\_\+tides@{mom\+\_\+internal\+\_\+tides}}
\subsubsection{\texorpdfstring{internal\+\_\+tides\+\_\+init()}{internal\_tides\_init()}}
{\footnotesize\ttfamily subroutine, public mom\+\_\+internal\+\_\+tides\+::internal\+\_\+tides\+\_\+init (\begin{DoxyParamCaption}\item[{type(time\+\_\+type), intent(in), target}]{Time,  }\item[{type(ocean\+\_\+grid\+\_\+type), intent(inout)}]{G,  }\item[{type(verticalgrid\+\_\+type), intent(in)}]{GV,  }\item[{type(unit\+\_\+scale\+\_\+type), intent(in)}]{US,  }\item[{type(param\+\_\+file\+\_\+type), intent(in)}]{param\+\_\+file,  }\item[{type(diag\+\_\+ctrl), intent(in), target}]{diag,  }\item[{type(\hyperlink{structmom__internal__tides_1_1int__tide__cs}{int\+\_\+tide\+\_\+cs}), pointer}]{CS }\end{DoxyParamCaption})}



This subroutine initializes the internal tides module. 


\begin{DoxyParams}[1]{Parameters}
\mbox{\tt in}  & {\em time} & The current model time.\\
\hline
\mbox{\tt in,out}  & {\em g} & The ocean\textquotesingle{}s grid structure.\\
\hline
\mbox{\tt in}  & {\em gv} & The ocean\textquotesingle{}s vertical grid structure.\\
\hline
\mbox{\tt in}  & {\em us} & A dimensional unit scaling type\\
\hline
\mbox{\tt in}  & {\em param\+\_\+file} & A structure to parse for run-\/time parameters.\\
\hline
\mbox{\tt in}  & {\em diag} & A structure that is used to regulate diagnostic output.\\
\hline
 & {\em cs} & A pointer that is set to point to the control structure for this module. \\
\hline
\end{DoxyParams}


Definition at line 2102 of file M\+O\+M\+\_\+internal\+\_\+tides.\+F90.


\begin{DoxyCode}
2102   \textcolor{keywordtype}{type}(time\_type), \textcolor{keywordtype}{target},   \textcolor{keywordtype}{intent(in)}    :: time\textcolor{comment}{ !< The current model time.}
2103   \textcolor{keywordtype}{type}(ocean\_grid\_type),     \textcolor{keywordtype}{intent(inout)} :: g\textcolor{comment}{    !< The ocean's grid structure.}
2104   \textcolor{keywordtype}{type}(verticalgrid\_type),   \textcolor{keywordtype}{intent(in)}    :: gv\textcolor{comment}{   !< The ocean's vertical grid structure.}
2105   \textcolor{keywordtype}{type}(unit\_scale\_type),     \textcolor{keywordtype}{intent(in)}    :: us\textcolor{comment}{   !< A dimensional unit scaling type}
2106   \textcolor{keywordtype}{type}(param\_file\_type),     \textcolor{keywordtype}{intent(in)}    :: param\_file\textcolor{comment}{ !< A structure to parse for run-time}
2107 \textcolor{comment}{                                                   !! parameters.}
2108   \textcolor{keywordtype}{type}(diag\_ctrl), \textcolor{keywordtype}{target},   \textcolor{keywordtype}{intent(in)}    :: diag\textcolor{comment}{ !< A structure that is used to regulate}
2109 \textcolor{comment}{                                                   !! diagnostic output.}
2110   \textcolor{keywordtype}{type}(int\_tide\_cs),\textcolor{keywordtype}{pointer}                :: cs\textcolor{comment}{   !< A pointer that is set to point to the control}
2111 \textcolor{comment}{                                                   !! structure for this module.}
2112   \textcolor{comment}{! Local variables}
2113   \textcolor{keywordtype}{real}                              :: angle\_size \textcolor{comment}{! size of wedges, rad}
2114   \textcolor{keywordtype}{real}, \textcolor{keywordtype}{allocatable}                 :: angles(:)  \textcolor{comment}{! orientations of wedge centers, rad}
2115   \textcolor{keywordtype}{real}, \textcolor{keywordtype}{allocatable}, \textcolor{keywordtype}{dimension(:,:)} :: h2         \textcolor{comment}{! topographic roughness scale, m^2}
2116   \textcolor{keywordtype}{real}                              :: kappa\_itides, kappa\_h2\_factor
2117                                                   \textcolor{comment}{! characteristic topographic wave number}
2118                                                   \textcolor{comment}{! and a scaling factor}
2119   \textcolor{keywordtype}{real}, \textcolor{keywordtype}{allocatable}                 :: ridge\_temp(:,:)
2120                                                   \textcolor{comment}{! array for temporary storage of flags}
2121                                                   \textcolor{comment}{! of cells with double-reflecting ridges}
2122   \textcolor{keywordtype}{logical}                           :: use\_int\_tides, use\_temperature
2123   \textcolor{keywordtype}{real}    :: period\_1  \textcolor{comment}{! The period of the gravest modeled mode [T ~> s]}
2124   \textcolor{keywordtype}{integer} :: num\_angle, num\_freq, num\_mode, m, fr
2125   \textcolor{keywordtype}{integer} :: isd, ied, jsd, jed, a, id\_ang, i, j
2126   \textcolor{keywordtype}{type}(axes\_grp) :: axes\_ang
2127   \textcolor{comment}{! This include declares and sets the variable "version".}
2128 \textcolor{preprocessor}{#include "version\_variable.h"}
2129 \textcolor{preprocessor}{}  \textcolor{keywordtype}{character(len=40)}  :: mdl = \textcolor{stringliteral}{"MOM\_internal\_tides"} \textcolor{comment}{! This module's name.}
2130   \textcolor{keywordtype}{character(len=16)}, \textcolor{keywordtype}{dimension(8)} :: freq\_name
2131   \textcolor{keywordtype}{character(len=40)}  :: var\_name
2132   \textcolor{keywordtype}{character(len=160)} :: var\_descript
2133   \textcolor{keywordtype}{character(len=200)} :: filename
2134   \textcolor{keywordtype}{character(len=200)} :: refl\_angle\_file, land\_mask\_file
2135   \textcolor{keywordtype}{character(len=200)} :: refl\_pref\_file, refl\_dbl\_file
2136   \textcolor{keywordtype}{character(len=200)} :: dy\_cu\_file, dx\_cv\_file
2137   \textcolor{keywordtype}{character(len=200)} :: h2\_file
2138 
2139   isd = g%isd ; ied = g%ied ; jsd = g%jsd ; jed = g%jed
2140 
2141   \textcolor{keywordflow}{if} (\textcolor{keyword}{associated}(cs)) \textcolor{keywordflow}{then}
2142     \textcolor{keyword}{call }mom\_error(warning, \textcolor{stringliteral}{"internal\_tides\_init called "}//&
2143                              \textcolor{stringliteral}{"with an associated control structure."})
2144     \textcolor{keywordflow}{return}
2145   \textcolor{keywordflow}{else}
2146     \textcolor{keyword}{allocate}(cs)
2147 \textcolor{keywordflow}{  endif}
2148 
2149   use\_int\_tides = .false.
2150   \textcolor{keyword}{call }read\_param(param\_file, \textcolor{stringliteral}{"INTERNAL\_TIDES"}, use\_int\_tides)
2151   cs%do\_int\_tides = use\_int\_tides
2152   \textcolor{keywordflow}{if} (.not.use\_int\_tides) \textcolor{keywordflow}{return}
2153 
2154   use\_temperature = .true.
2155   \textcolor{keyword}{call }read\_param(param\_file, \textcolor{stringliteral}{"ENABLE\_THERMODYNAMICS"}, use\_temperature)
2156   \textcolor{keywordflow}{if} (.not.use\_temperature) \textcolor{keyword}{call }mom\_error(fatal, &
2157     \textcolor{stringliteral}{"register\_int\_tide\_restarts: internal\_tides only works with "}//&
2158     \textcolor{stringliteral}{"ENABLE\_THERMODYNAMICS defined."})
2159 
2160   \textcolor{comment}{! Set number of frequencies, angles, and modes to consider}
2161   num\_freq = 1 ; num\_angle = 24 ; num\_mode = 1
2162   \textcolor{keyword}{call }read\_param(param\_file, \textcolor{stringliteral}{"INTERNAL\_TIDE\_FREQS"}, num\_freq)
2163   \textcolor{keyword}{call }read\_param(param\_file, \textcolor{stringliteral}{"INTERNAL\_TIDE\_ANGLES"}, num\_angle)
2164   \textcolor{keyword}{call }read\_param(param\_file, \textcolor{stringliteral}{"INTERNAL\_TIDE\_MODES"}, num\_mode)
2165   \textcolor{keywordflow}{if} (.not.((num\_freq > 0) .and. (num\_angle > 0) .and. (num\_mode > 0))) \textcolor{keywordflow}{return}
2166   cs%nFreq = num\_freq ; cs%nAngle = num\_angle ; cs%nMode = num\_mode
2167 
2168   \textcolor{comment}{! Allocate energy density array}
2169   \textcolor{keyword}{allocate}(cs%En(isd:ied, jsd:jed, num\_angle, num\_freq, num\_mode))
2170   cs%En(:,:,:,:,:) = 0.0
2171 
2172   \textcolor{comment}{! Allocate phase speed array}
2173   \textcolor{keyword}{allocate}(cs%cp(isd:ied, jsd:jed, num\_freq, num\_mode))
2174   cs%cp(:,:,:,:) = 0.0
2175 
2176   \textcolor{comment}{! Allocate and populate frequency array (each a multiple of first for now)}
2177   \textcolor{keyword}{allocate}(cs%frequency(num\_freq))
2178   \textcolor{keyword}{call }get\_param(param\_file, mdl, \textcolor{stringliteral}{"FIRST\_MODE\_PERIOD"}, period\_1, units=\textcolor{stringliteral}{"s"}, scale=us%s\_to\_T)
2179   \textcolor{keywordflow}{do} fr=1,num\_freq
2180     cs%frequency(fr) = (8.0*atan(1.0) * (\textcolor{keywordtype}{real}(fr)) / period\_1) \textcolor{comment}{! ADDED BDM}
2181 \textcolor{keywordflow}{  enddo}
2182 
2183   \textcolor{comment}{! Read all relevant parameters and write them to the model log.}
2184 
2185   cs%Time => time \textcolor{comment}{! direct a pointer to the current model time target}
2186 
2187   \textcolor{keyword}{call }get\_param(param\_file, mdl, \textcolor{stringliteral}{"INPUTDIR"}, cs%inputdir, default=\textcolor{stringliteral}{"."})
2188                  cs%inputdir = slasher(cs%inputdir)
2189 
2190   \textcolor{keyword}{call }log\_version(param\_file, mdl, version, \textcolor{stringliteral}{""})
2191 
2192   \textcolor{keyword}{call }get\_param(param\_file, mdl, \textcolor{stringliteral}{"INTERNAL\_TIDE\_FREQS"}, num\_freq, &
2193                  \textcolor{stringliteral}{"The number of distinct internal tide frequency bands "}//&
2194                  \textcolor{stringliteral}{"that will be calculated."}, default=1)
2195   \textcolor{keyword}{call }get\_param(param\_file, mdl, \textcolor{stringliteral}{"INTERNAL\_TIDE\_MODES"}, num\_mode, &
2196                  \textcolor{stringliteral}{"The number of distinct internal tide modes "}//&
2197                  \textcolor{stringliteral}{"that will be calculated."}, default=1)
2198   \textcolor{keyword}{call }get\_param(param\_file, mdl, \textcolor{stringliteral}{"INTERNAL\_TIDE\_ANGLES"}, num\_angle, &
2199                  \textcolor{stringliteral}{"The number of angular resolution bands for the internal "}//&
2200                  \textcolor{stringliteral}{"tide calculations."}, default=24)
2201 
2202   \textcolor{keywordflow}{if} (use\_int\_tides) \textcolor{keywordflow}{then}
2203     \textcolor{keywordflow}{if} ((num\_freq <= 0) .and. (num\_mode <= 0) .and. (num\_angle <= 0)) \textcolor{keywordflow}{then}
2204       \textcolor{keyword}{call }mom\_error(warning, \textcolor{stringliteral}{"Internal tides were enabled, but the number "}//&
2205              \textcolor{stringliteral}{"of requested frequencies, modes and angles were not all positive."})
2206       \textcolor{keywordflow}{return}
2207 \textcolor{keywordflow}{    endif}
2208   \textcolor{keywordflow}{else}
2209     \textcolor{keywordflow}{if} ((num\_freq > 0) .and. (num\_mode > 0) .and. (num\_angle > 0)) \textcolor{keywordflow}{then}
2210       \textcolor{keyword}{call }mom\_error(warning, \textcolor{stringliteral}{"Internal tides were not enabled, even though "}//&
2211              \textcolor{stringliteral}{"the number of requested frequencies, modes and angles were all "}//&
2212              \textcolor{stringliteral}{"positive."})
2213       \textcolor{keywordflow}{return}
2214 \textcolor{keywordflow}{    endif}
2215 \textcolor{keywordflow}{  endif}
2216 
2217   \textcolor{keywordflow}{if} (cs%NFreq /= num\_freq) \textcolor{keyword}{call }mom\_error(fatal, \textcolor{stringliteral}{"Internal\_tides\_init: "}//&
2218       \textcolor{stringliteral}{"Inconsistent number of frequencies."})
2219   \textcolor{keywordflow}{if} (cs%NAngle /= num\_angle) \textcolor{keyword}{call }mom\_error(fatal, \textcolor{stringliteral}{"Internal\_tides\_init: "}//&
2220       \textcolor{stringliteral}{"Inconsistent number of angles."})
2221   \textcolor{keywordflow}{if} (cs%NMode /= num\_mode) \textcolor{keyword}{call }mom\_error(fatal, \textcolor{stringliteral}{"Internal\_tides\_init: "}//&
2222       \textcolor{stringliteral}{"Inconsistent number of modes."})
2223   \textcolor{keywordflow}{if} (4*(num\_angle/4) /= num\_angle) \textcolor{keyword}{call }mom\_error(fatal, &
2224     \textcolor{stringliteral}{"Internal\_tides\_init: INTERNAL\_TIDE\_ANGLES must be a multiple of 4."})
2225 
2226   cs%diag => diag
2227 
2228   \textcolor{keyword}{call }get\_param(param\_file, mdl, \textcolor{stringliteral}{"INTERNAL\_TIDE\_DECAY\_RATE"}, cs%decay\_rate, &
2229                  \textcolor{stringliteral}{"The rate at which internal tide energy is lost to the "}//&
2230                  \textcolor{stringliteral}{"interior ocean internal wave field."}, &
2231                  units=\textcolor{stringliteral}{"s-1"}, default=0.0, scale=us%T\_to\_s)
2232   \textcolor{keyword}{call }get\_param(param\_file, mdl, \textcolor{stringliteral}{"INTERNAL\_TIDE\_VOLUME\_BASED\_CFL"}, cs%vol\_CFL, &
2233                  \textcolor{stringliteral}{"If true, use the ratio of the open face lengths to the "}//&
2234                  \textcolor{stringliteral}{"tracer cell areas when estimating CFL numbers in the "}//&
2235                  \textcolor{stringliteral}{"internal tide code."}, default=.false.)
2236   \textcolor{keyword}{call }get\_param(param\_file, mdl, \textcolor{stringliteral}{"INTERNAL\_TIDE\_CORNER\_ADVECT"}, cs%corner\_adv, &
2237                  \textcolor{stringliteral}{"If true, internal tide ray-tracing advection uses a "}//&
2238                  \textcolor{stringliteral}{"corner-advection scheme rather than PPM."}, default=.false.)
2239   \textcolor{keyword}{call }get\_param(param\_file, mdl, \textcolor{stringliteral}{"INTERNAL\_TIDE\_SIMPLE\_2ND\_PPM"}, cs%simple\_2nd, &
2240                  \textcolor{stringliteral}{"If true, CONTINUITY\_PPM uses a simple 2nd order "}//&
2241                  \textcolor{stringliteral}{"(arithmetic mean) interpolation of the edge values. "}//&
2242                  \textcolor{stringliteral}{"This may give better PV conservation properties. While "}//&
2243                  \textcolor{stringliteral}{"it formally reduces the accuracy of the continuity "}//&
2244                  \textcolor{stringliteral}{"solver itself in the strongly advective limit, it does "}//&
2245                  \textcolor{stringliteral}{"not reduce the overall order of accuracy of the dynamic "}//&
2246                  \textcolor{stringliteral}{"core."}, default=.false.)
2247   \textcolor{keyword}{call }get\_param(param\_file, mdl, \textcolor{stringliteral}{"INTERNAL\_TIDE\_UPWIND\_1ST"}, cs%upwind\_1st, &
2248                  \textcolor{stringliteral}{"If true, the internal tide ray-tracing advection uses "}//&
2249                  \textcolor{stringliteral}{"1st-order upwind advection.  This scheme is highly "}//&
2250                  \textcolor{stringliteral}{"continuity solver.  This scheme is highly "}//&
2251                  \textcolor{stringliteral}{"diffusive but may be useful for debugging."}, default=.false.)
2252   \textcolor{keyword}{call }get\_param(param\_file, mdl, \textcolor{stringliteral}{"INTERNAL\_TIDE\_BACKGROUND\_DRAG"}, &
2253                  cs%apply\_background\_drag, \textcolor{stringliteral}{"If true, the internal tide "}//&
2254                  \textcolor{stringliteral}{"ray-tracing advection uses a background drag term as a sink."},&
2255                  default=.false.)
2256   \textcolor{keyword}{call }get\_param(param\_file, mdl, \textcolor{stringliteral}{"INTERNAL\_TIDE\_QUAD\_DRAG"}, cs%apply\_bottom\_drag, &
2257                  \textcolor{stringliteral}{"If true, the internal tide ray-tracing advection uses "}//&
2258                  \textcolor{stringliteral}{"a quadratic bottom drag term as a sink."}, default=.false.)
2259   \textcolor{keyword}{call }get\_param(param\_file, mdl, \textcolor{stringliteral}{"INTERNAL\_TIDE\_WAVE\_DRAG"}, cs%apply\_wave\_drag, &
2260                  \textcolor{stringliteral}{"If true, apply scattering due to small-scale roughness as a sink."}, &
2261                  default=.false.)
2262   \textcolor{keyword}{call }get\_param(param\_file, mdl, \textcolor{stringliteral}{"INTERNAL\_TIDE\_FROUDE\_DRAG"}, cs%apply\_Froude\_drag, &
2263                  \textcolor{stringliteral}{"If true, apply wave breaking as a sink."}, &
2264                  default=.false.)
2265   \textcolor{keyword}{call }get\_param(param\_file, mdl, \textcolor{stringliteral}{"CDRAG"}, cs%cdrag, &
2266                  \textcolor{stringliteral}{"CDRAG is the drag coefficient relating the magnitude of "}//&
2267                  \textcolor{stringliteral}{"the velocity field to the bottom stress."}, units=\textcolor{stringliteral}{"nondim"}, &
2268                  default=0.003)
2269   \textcolor{keyword}{call }get\_param(param\_file, mdl, \textcolor{stringliteral}{"INTERNAL\_TIDE\_ENERGIZED\_ANGLE"}, cs%energized\_angle, &
2270                  \textcolor{stringliteral}{"If positive, only one angular band of the internal tides "}//&
2271                  \textcolor{stringliteral}{"gets all of the energy.  (This is for debugging.)"}, default=-1)
2272   \textcolor{keyword}{call }get\_param(param\_file, mdl, \textcolor{stringliteral}{"USE\_PPM\_ANGULAR"}, cs%use\_PPMang, &
2273                  \textcolor{stringliteral}{"If true, use PPM for advection of energy in angular space."}, &
2274                  default=.false.)
2275   \textcolor{keyword}{call }get\_param(param\_file, mdl, \textcolor{stringliteral}{"GAMMA\_ITIDES"}, cs%q\_itides, &
2276                  \textcolor{stringliteral}{"The fraction of the internal tidal energy that is "}//&
2277                  \textcolor{stringliteral}{"dissipated locally with INT\_TIDE\_DISSIPATION. "}//&
2278                  \textcolor{stringliteral}{"THIS NAME COULD BE BETTER."}, &
2279                  units=\textcolor{stringliteral}{"nondim"}, default=0.3333)
2280   \textcolor{keyword}{call }get\_param(param\_file, mdl, \textcolor{stringliteral}{"KAPPA\_ITIDES"}, kappa\_itides, &
2281                \textcolor{stringliteral}{"A topographic wavenumber used with INT\_TIDE\_DISSIPATION. "}//&
2282                \textcolor{stringliteral}{"The default is 2pi/10 km, as in St.Laurent et al. 2002."}, &
2283                units=\textcolor{stringliteral}{"m-1"}, default=8.e-4*atan(1.0), scale=us%L\_to\_m)
2284   \textcolor{keyword}{call }get\_param(param\_file, mdl, \textcolor{stringliteral}{"KAPPA\_H2\_FACTOR"}, kappa\_h2\_factor, &
2285                \textcolor{stringliteral}{"A scaling factor for the roughness amplitude with n"}//&
2286                \textcolor{stringliteral}{"INT\_TIDE\_DISSIPATION."},  units=\textcolor{stringliteral}{"nondim"}, default=1.0)
2287 
2288   \textcolor{comment}{! Allocate various arrays needed for loss rates}
2289   \textcolor{keyword}{allocate}(h2(isd:ied,jsd:jed)) ; h2(:,:) = 0.0
2290   \textcolor{keyword}{allocate}(cs%TKE\_itidal\_loss\_fixed(isd:ied,jsd:jed))
2291     cs%TKE\_itidal\_loss\_fixed = 0.0
2292   \textcolor{keyword}{allocate}(cs%TKE\_leak\_loss(isd:ied,jsd:jed,num\_angle,num\_freq,num\_mode))
2293     cs%TKE\_leak\_loss(:,:,:,:,:) = 0.0
2294   \textcolor{keyword}{allocate}(cs%TKE\_quad\_loss(isd:ied,jsd:jed,num\_angle,num\_freq,num\_mode))
2295     cs%TKE\_quad\_loss(:,:,:,:,:) = 0.0
2296   \textcolor{keyword}{allocate}(cs%TKE\_itidal\_loss(isd:ied,jsd:jed,num\_angle,num\_freq,num\_mode))
2297     cs%TKE\_itidal\_loss(:,:,:,:,:) = 0.0
2298   \textcolor{keyword}{allocate}(cs%TKE\_Froude\_loss(isd:ied,jsd:jed,num\_angle,num\_freq,num\_mode))
2299     cs%TKE\_Froude\_loss(:,:,:,:,:) = 0.0
2300   \textcolor{keyword}{allocate}(cs%tot\_leak\_loss(isd:ied,jsd:jed))   ; cs%tot\_leak\_loss(:,:) = 0.0
2301   \textcolor{keyword}{allocate}(cs%tot\_quad\_loss(isd:ied,jsd:jed) )  ; cs%tot\_quad\_loss(:,:) = 0.0
2302   \textcolor{keyword}{allocate}(cs%tot\_itidal\_loss(isd:ied,jsd:jed)) ; cs%tot\_itidal\_loss(:,:) = 0.0
2303   \textcolor{keyword}{allocate}(cs%tot\_Froude\_loss(isd:ied,jsd:jed)) ; cs%tot\_Froude\_loss(:,:) = 0.0
2304 
2305   \textcolor{comment}{! Compute the fixed part of the bottom drag loss from baroclinic modes}
2306   \textcolor{keyword}{call }get\_param(param\_file, mdl, \textcolor{stringliteral}{"H2\_FILE"}, h2\_file, &
2307           \textcolor{stringliteral}{"The path to the file containing the sub-grid-scale "}//&
2308           \textcolor{stringliteral}{"topographic roughness amplitude with INT\_TIDE\_DISSIPATION."}, &
2309           fail\_if\_missing=.true.)
2310   filename = trim(cs%inputdir) // trim(h2\_file)
2311   \textcolor{keyword}{call }log\_param(param\_file, mdl, \textcolor{stringliteral}{"INPUTDIR/H2\_FILE"}, filename)
2312   \textcolor{keyword}{call }mom\_read\_data(filename, \textcolor{stringliteral}{'h2'}, h2, g%domain, timelevel=1, scale=us%m\_to\_Z)
2313   \textcolor{keywordflow}{do} j=g%jsc,g%jec ; \textcolor{keywordflow}{do} i=g%isc,g%iec
2314     \textcolor{comment}{! Restrict rms topo to 10 percent of column depth.}
2315     h2(i,j) = min(0.01*(g%bathyT(i,j))**2, h2(i,j))
2316     \textcolor{comment}{! Compute the fixed part; units are [R L-2 Z3 ~> kg m-2] here}
2317     \textcolor{comment}{! will be multiplied by N and the squared near-bottom velocity to get into [R Z3 T-3 ~> W m-2]}
2318     cs%TKE\_itidal\_loss\_fixed(i,j) = 0.5*kappa\_h2\_factor*gv%Rho0 * us%L\_to\_Z*kappa\_itides * h2(i,j)
2319 \textcolor{keywordflow}{  enddo} ;\textcolor{keywordflow}{ enddo}
2320 
2321   \textcolor{keyword}{deallocate}(h2)
2322 
2323   \textcolor{comment}{! Read in prescribed coast/ridge/shelf angles from file}
2324   \textcolor{keyword}{call }get\_param(param\_file, mdl, \textcolor{stringliteral}{"REFL\_ANGLE\_FILE"}, refl\_angle\_file, &
2325                \textcolor{stringliteral}{"The path to the file containing the local angle of "}//&
2326                \textcolor{stringliteral}{"the coastline/ridge/shelf with respect to the equator."}, &
2327                fail\_if\_missing=.false., default=\textcolor{stringliteral}{''})
2328   filename = trim(cs%inputdir) // trim(refl\_angle\_file)
2329   \textcolor{keyword}{allocate}(cs%refl\_angle(isd:ied,jsd:jed)) ; cs%refl\_angle(:,:) = cs%nullangle
2330   \textcolor{keywordflow}{if} (file\_exists(filename, g%domain)) \textcolor{keywordflow}{then}
2331     \textcolor{keyword}{call }log\_param(param\_file, mdl, \textcolor{stringliteral}{"INPUTDIR/REFL\_ANGLE\_FILE"}, filename)
2332     \textcolor{keyword}{call }mom\_read\_data(filename, \textcolor{stringliteral}{'refl\_angle'}, cs%refl\_angle, &
2333                        g%domain, timelevel=1)
2334   \textcolor{keywordflow}{else}
2335     \textcolor{keywordflow}{if} (trim(refl\_angle\_file) /= \textcolor{stringliteral}{''} ) \textcolor{keyword}{call }mom\_error(fatal, &
2336                                                      \textcolor{stringliteral}{"REFL\_ANGLE\_FILE: "}//trim(filename)//\textcolor{stringliteral}{" not found"})
2337 \textcolor{keywordflow}{  endif}
2338   \textcolor{comment}{! replace NANs with null value}
2339   \textcolor{keywordflow}{do} j=g%jsc,g%jec ; \textcolor{keywordflow}{do} i=g%isc,g%iec
2340     \textcolor{keywordflow}{if} (is\_nan(cs%refl\_angle(i,j))) cs%refl\_angle(i,j) = cs%nullangle
2341 \textcolor{keywordflow}{  enddo} ;\textcolor{keywordflow}{ enddo}
2342   \textcolor{keyword}{call }pass\_var(cs%refl\_angle,g%domain)
2343 
2344   \textcolor{comment}{! Read in prescribed partial reflection coefficients from file}
2345   \textcolor{keyword}{call }get\_param(param\_file, mdl, \textcolor{stringliteral}{"REFL\_PREF\_FILE"}, refl\_pref\_file, &
2346                \textcolor{stringliteral}{"The path to the file containing the reflection coefficients."}, &
2347                fail\_if\_missing=.false., default=\textcolor{stringliteral}{''})
2348   filename = trim(cs%inputdir) // trim(refl\_pref\_file)
2349   \textcolor{keyword}{allocate}(cs%refl\_pref(isd:ied,jsd:jed)) ; cs%refl\_pref(:,:) = 1.0
2350   \textcolor{keywordflow}{if} (file\_exists(filename, g%domain)) \textcolor{keywordflow}{then}
2351     \textcolor{keyword}{call }log\_param(param\_file, mdl, \textcolor{stringliteral}{"INPUTDIR/REFL\_PREF\_FILE"}, filename)
2352     \textcolor{keyword}{call }mom\_read\_data(filename, \textcolor{stringliteral}{'refl\_pref'}, cs%refl\_pref, g%domain, timelevel=1)
2353   \textcolor{keywordflow}{else}
2354     \textcolor{keywordflow}{if} (trim(refl\_pref\_file) /= \textcolor{stringliteral}{''} ) \textcolor{keyword}{call }mom\_error(fatal, &
2355                                                     \textcolor{stringliteral}{"REFL\_PREF\_FILE: "}//trim(filename)//\textcolor{stringliteral}{" not found"})
2356 \textcolor{keywordflow}{  endif}
2357   \textcolor{comment}{!CS%refl\_pref = CS%refl\_pref*1 ! adjust partial reflection if desired}
2358   \textcolor{keyword}{call }pass\_var(cs%refl\_pref,g%domain)
2359 
2360   \textcolor{comment}{! Tag reflection cells with partial reflection (done here for speed)}
2361   \textcolor{keyword}{allocate}(cs%refl\_pref\_logical(isd:ied,jsd:jed)) ; cs%refl\_pref\_logical(:,:) = .false.
2362   \textcolor{keywordflow}{do} j=jsd,jed
2363     \textcolor{keywordflow}{do} i=isd,ied
2364       \textcolor{comment}{! flag cells with partial reflection}
2365       \textcolor{keywordflow}{if} (cs%refl\_angle(i,j) /= cs%nullangle .and. &
2366         cs%refl\_pref(i,j) < 1.0 .and. cs%refl\_pref(i,j) > 0.0) \textcolor{keywordflow}{then}
2367         cs%refl\_pref\_logical(i,j) = .true.
2368 \textcolor{keywordflow}{      endif}
2369 \textcolor{keywordflow}{    enddo}
2370 \textcolor{keywordflow}{  enddo}
2371 
2372   \textcolor{comment}{! Read in double-reflective (ridge) tags from file}
2373   \textcolor{keyword}{call }get\_param(param\_file, mdl, \textcolor{stringliteral}{"REFL\_DBL\_FILE"}, refl\_dbl\_file, &
2374                \textcolor{stringliteral}{"The path to the file containing the double-reflective ridge tags."}, &
2375                fail\_if\_missing=.false., default=\textcolor{stringliteral}{''})
2376   filename = trim(cs%inputdir) // trim(refl\_dbl\_file)
2377   \textcolor{keyword}{allocate}(ridge\_temp(isd:ied,jsd:jed)) ; ridge\_temp(:,:) = 0.0
2378   \textcolor{keywordflow}{if} (file\_exists(filename, g%domain)) \textcolor{keywordflow}{then}
2379     \textcolor{keyword}{call }log\_param(param\_file, mdl, \textcolor{stringliteral}{"INPUTDIR/REFL\_DBL\_FILE"}, filename)
2380     \textcolor{keyword}{call }mom\_read\_data(filename, \textcolor{stringliteral}{'refl\_dbl'}, ridge\_temp, g%domain, timelevel=1)
2381   \textcolor{keywordflow}{else}
2382     \textcolor{keywordflow}{if} (trim(refl\_dbl\_file) /= \textcolor{stringliteral}{''} ) \textcolor{keyword}{call }mom\_error(fatal, &
2383                                                    \textcolor{stringliteral}{"REFL\_DBL\_FILE: "}//trim(filename)//\textcolor{stringliteral}{" not found"})
2384 \textcolor{keywordflow}{  endif}
2385   \textcolor{keyword}{call }pass\_var(ridge\_temp,g%domain)
2386   \textcolor{keyword}{allocate}(cs%refl\_dbl(isd:ied,jsd:jed)) ; cs%refl\_dbl(:,:) = .false.
2387   \textcolor{keywordflow}{do} i=isd,ied; \textcolor{keywordflow}{do} j=jsd,jed
2388     \textcolor{keywordflow}{if} (ridge\_temp(i,j) == 1) then; cs%refl\_dbl(i,j) = .true.
2389     \textcolor{keywordflow}{else} ; cs%refl\_dbl(i,j) = .false. ;\textcolor{keywordflow}{ endif}
2390 \textcolor{keywordflow}{  enddo} ;\textcolor{keywordflow}{ enddo}
2391 
2392   \textcolor{comment}{! Read in prescribed land mask from file (if overwriting -BDM).}
2393   \textcolor{comment}{! This should be done in MOM\_initialize\_topography subroutine}
2394   \textcolor{comment}{! defined in MOM\_fixed\_initialization.F90 (BDM)}
2395   \textcolor{comment}{!call get\_param(param\_file, mdl, "LAND\_MASK\_FILE", land\_mask\_file, &}
2396   \textcolor{comment}{!             "The path to the file containing the land mask.", &}
2397   \textcolor{comment}{!             fail\_if\_missing=.false.)}
2398   \textcolor{comment}{!filename = trim(CS%inputdir) // trim(land\_mask\_file)}
2399   \textcolor{comment}{!call log\_param(param\_file, mdl, "INPUTDIR/LAND\_MASK\_FILE", filename)}
2400   \textcolor{comment}{!G%mask2dCu(:,:) = 1 ; G%mask2dCv(:,:) = 1 ; G%mask2dT(:,:)  = 1}
2401   \textcolor{comment}{!call MOM\_read\_data(filename, 'land\_mask', G%mask2dCu, G%domain, timelevel=1)}
2402   \textcolor{comment}{!call MOM\_read\_data(filename, 'land\_mask', G%mask2dCv, G%domain, timelevel=1)}
2403   \textcolor{comment}{!call MOM\_read\_data(filename, 'land\_mask', G%mask2dT, G%domain, timelevel=1)}
2404   \textcolor{comment}{!call pass\_vector(G%mask2dCu, G%mask2dCv, G%domain, To\_All+Scalar\_Pair, CGRID\_NE)}
2405   \textcolor{comment}{!call pass\_var(G%mask2dT,G%domain)}
2406 
2407   \textcolor{comment}{! Read in prescribed partial east face blockages from file (if overwriting -BDM)}
2408   \textcolor{comment}{!call get\_param(param\_file, mdl, "dy\_Cu\_FILE", dy\_Cu\_file, &}
2409   \textcolor{comment}{!             "The path to the file containing the east face blockages.", &}
2410   \textcolor{comment}{!             fail\_if\_missing=.false.)}
2411   \textcolor{comment}{!filename = trim(CS%inputdir) // trim(dy\_Cu\_file)}
2412   \textcolor{comment}{!call log\_param(param\_file, mdl, "INPUTDIR/dy\_Cu\_FILE", filename)}
2413   \textcolor{comment}{!G%dy\_Cu(:,:) = 0.0}
2414   \textcolor{comment}{!call MOM\_read\_data(filename, 'dy\_Cu', G%dy\_Cu, G%domain, timelevel=1, scale=US%m\_to\_L)}
2415 
2416   \textcolor{comment}{! Read in prescribed partial north face blockages from file (if overwriting -BDM)}
2417   \textcolor{comment}{!call get\_param(param\_file, mdl, "dx\_Cv\_FILE", dx\_Cv\_file, &}
2418   \textcolor{comment}{!             "The path to the file containing the north face blockages.", &}
2419   \textcolor{comment}{!             fail\_if\_missing=.false.)}
2420   \textcolor{comment}{!filename = trim(CS%inputdir) // trim(dx\_Cv\_file)}
2421   \textcolor{comment}{!call log\_param(param\_file, mdl, "INPUTDIR/dx\_Cv\_FILE", filename)}
2422   \textcolor{comment}{!G%dx\_Cv(:,:) = 0.0}
2423   \textcolor{comment}{!call MOM\_read\_data(filename, 'dx\_Cv', G%dx\_Cv, G%domain, timelevel=1, scale=US%m\_to\_L)}
2424   \textcolor{comment}{!call pass\_vector(G%dy\_Cu, G%dx\_Cv, G%domain, To\_All+Scalar\_Pair, CGRID\_NE)}
2425 
2426   \textcolor{comment}{! Register maps of reflection parameters}
2427   cs%id\_refl\_ang = register\_diag\_field(\textcolor{stringliteral}{'ocean\_model'}, \textcolor{stringliteral}{'refl\_angle'}, diag%axesT1, &
2428                  time, \textcolor{stringliteral}{'Local angle of coastline/ridge/shelf with respect to equator'}, \textcolor{stringliteral}{'rad'})
2429   cs%id\_refl\_pref = register\_diag\_field(\textcolor{stringliteral}{'ocean\_model'}, \textcolor{stringliteral}{'refl\_pref'}, diag%axesT1, &
2430                  time, \textcolor{stringliteral}{'Partial reflection coefficients'}, \textcolor{stringliteral}{''})
2431   cs%id\_dx\_Cv = register\_diag\_field(\textcolor{stringliteral}{'ocean\_model'}, \textcolor{stringliteral}{'dx\_Cv'}, diag%axesT1, &
2432                  time, \textcolor{stringliteral}{'North face unblocked width'}, \textcolor{stringliteral}{'m'}, conversion=us%L\_to\_m)
2433   cs%id\_dy\_Cu = register\_diag\_field(\textcolor{stringliteral}{'ocean\_model'}, \textcolor{stringliteral}{'dy\_Cu'}, diag%axesT1, &
2434                  time, \textcolor{stringliteral}{'East face unblocked width'}, \textcolor{stringliteral}{'m'}, conversion=us%L\_to\_m)
2435   cs%id\_land\_mask = register\_diag\_field(\textcolor{stringliteral}{'ocean\_model'}, \textcolor{stringliteral}{'land\_mask'}, diag%axesT1, &
2436                  time, \textcolor{stringliteral}{'Land mask'}, \textcolor{stringliteral}{'logical'})            \textcolor{comment}{! used if overriding (BDM)}
2437   \textcolor{comment}{! Output reflection parameters as diags here (not needed every timestep)}
2438   \textcolor{keywordflow}{if} (cs%id\_refl\_ang > 0)   \textcolor{keyword}{call }post\_data(cs%id\_refl\_ang, cs%refl\_angle, cs%diag)
2439   \textcolor{keywordflow}{if} (cs%id\_refl\_pref > 0)  \textcolor{keyword}{call }post\_data(cs%id\_refl\_pref, cs%refl\_pref, cs%diag)
2440   \textcolor{keywordflow}{if} (cs%id\_dx\_Cv > 0)      \textcolor{keyword}{call }post\_data(cs%id\_dx\_Cv, g%dx\_Cv, cs%diag)
2441   \textcolor{keywordflow}{if} (cs%id\_dy\_Cu > 0)      \textcolor{keyword}{call }post\_data(cs%id\_dy\_Cu, g%dy\_Cu, cs%diag)
2442   \textcolor{keywordflow}{if} (cs%id\_land\_mask > 0)  \textcolor{keyword}{call }post\_data(cs%id\_land\_mask, g%mask2dT, cs%diag)
2443 
2444   \textcolor{comment}{! Register 2-D energy density (summed over angles, freq, modes)}
2445   cs%id\_tot\_En = register\_diag\_field(\textcolor{stringliteral}{'ocean\_model'}, \textcolor{stringliteral}{'ITide\_tot\_En'}, diag%axesT1, &
2446                  time, \textcolor{stringliteral}{'Internal tide total energy density'}, &
2447                  \textcolor{stringliteral}{'J m-2'}, conversion=us%RZ3\_T3\_to\_W\_m2*us%T\_to\_s)
2448   \textcolor{comment}{! Register 2-D drag scale used for quadratic bottom drag}
2449   cs%id\_itide\_drag = register\_diag\_field(\textcolor{stringliteral}{'ocean\_model'}, \textcolor{stringliteral}{'ITide\_drag'}, diag%axesT1, &
2450                  time, \textcolor{stringliteral}{'Interior and bottom drag internal tide decay timescale'}, \textcolor{stringliteral}{'s-1'}, conversion=us
      %s\_to\_T)
2451   \textcolor{comment}{!Register 2-D energy input into internal tides}
2452   cs%id\_TKE\_itidal\_input = register\_diag\_field(\textcolor{stringliteral}{'ocean\_model'}, \textcolor{stringliteral}{'TKE\_itidal\_input'}, diag%axesT1, &
2453                  time, \textcolor{stringliteral}{'Conversion from barotropic to baroclinic tide, '}//&
2454                  \textcolor{stringliteral}{'a fraction of which goes into rays'}, &
2455                  \textcolor{stringliteral}{'W m-2'}, conversion=us%RZ3\_T3\_to\_W\_m2)
2456   \textcolor{comment}{! Register 2-D energy losses (summed over angles, freq, modes)}
2457   cs%id\_tot\_leak\_loss = register\_diag\_field(\textcolor{stringliteral}{'ocean\_model'}, \textcolor{stringliteral}{'ITide\_tot\_leak\_loss'}, diag%axesT1, &
2458                 time, \textcolor{stringliteral}{'Internal tide energy loss to background drag'}, &
2459                 \textcolor{stringliteral}{'W m-2'}, conversion=us%RZ3\_T3\_to\_W\_m2)
2460   cs%id\_tot\_quad\_loss = register\_diag\_field(\textcolor{stringliteral}{'ocean\_model'}, \textcolor{stringliteral}{'ITide\_tot\_quad\_loss'}, diag%axesT1, &
2461                 time, \textcolor{stringliteral}{'Internal tide energy loss to bottom drag'}, &
2462                 \textcolor{stringliteral}{'W m-2'}, conversion=us%RZ3\_T3\_to\_W\_m2)
2463   cs%id\_tot\_itidal\_loss = register\_diag\_field(\textcolor{stringliteral}{'ocean\_model'}, \textcolor{stringliteral}{'ITide\_tot\_itidal\_loss'}, diag%axesT1, &
2464                 time, \textcolor{stringliteral}{'Internal tide energy loss to wave drag'}, &
2465                 \textcolor{stringliteral}{'W m-2'}, conversion=us%RZ3\_T3\_to\_W\_m2)
2466   cs%id\_tot\_Froude\_loss = register\_diag\_field(\textcolor{stringliteral}{'ocean\_model'}, \textcolor{stringliteral}{'ITide\_tot\_Froude\_loss'}, diag%axesT1, &
2467                 time, \textcolor{stringliteral}{'Internal tide energy loss to wave breaking'}, &
2468                 \textcolor{stringliteral}{'W m-2'}, conversion=us%RZ3\_T3\_to\_W\_m2)
2469   cs%id\_tot\_allprocesses\_loss = register\_diag\_field(\textcolor{stringliteral}{'ocean\_model'}, \textcolor{stringliteral}{'ITide\_tot\_allprocesses\_loss'}, diag
      %axesT1, &
2470                 time, \textcolor{stringliteral}{'Internal tide energy loss summed over all processes'}, &
2471                 \textcolor{stringliteral}{'W m-2'}, conversion=us%RZ3\_T3\_to\_W\_m2)
2472 
2473   \textcolor{keyword}{allocate}(cs%id\_En\_mode(cs%nFreq,cs%nMode)) ; cs%id\_En\_mode(:,:) = -1
2474   \textcolor{keyword}{allocate}(cs%id\_En\_ang\_mode(cs%nFreq,cs%nMode)) ; cs%id\_En\_ang\_mode(:,:) = -1
2475   \textcolor{keyword}{allocate}(cs%id\_itidal\_loss\_mode(cs%nFreq,cs%nMode)) ; cs%id\_itidal\_loss\_mode(:,:) = -1
2476   \textcolor{keyword}{allocate}(cs%id\_allprocesses\_loss\_mode(cs%nFreq,cs%nMode)) ; cs%id\_allprocesses\_loss\_mode(:,:) = -1
2477   \textcolor{keyword}{allocate}(cs%id\_itidal\_loss\_ang\_mode(cs%nFreq,cs%nMode)) ; cs%id\_itidal\_loss\_ang\_mode(:,:) = -1
2478   \textcolor{keyword}{allocate}(cs%id\_Ub\_mode(cs%nFreq,cs%nMode)) ; cs%id\_Ub\_mode(:,:) = -1
2479   \textcolor{keyword}{allocate}(cs%id\_cp\_mode(cs%nFreq,cs%nMode)) ; cs%id\_cp\_mode(:,:) = -1
2480 
2481   \textcolor{keyword}{allocate}(angles(cs%NAngle)) ; angles(:) = 0.0
2482   angle\_size = (8.0*atan(1.0)) / (\textcolor{keywordtype}{real}(num\_angle))
2483   \textcolor{keywordflow}{do} a=1,num\_angle ; angles(a) = (\textcolor{keywordtype}{real(a)} - 1) * angle\_size ; enddo
2484 
2485   id\_ang = diag\_axis\_init(\textcolor{stringliteral}{"angle"}, angles, \textcolor{stringliteral}{"Radians"}, \textcolor{stringliteral}{"N"}, \textcolor{stringliteral}{"Angular Orienation of Fluxes"})
2486   \textcolor{keyword}{call }define\_axes\_group(diag, (/ diag%axesT1%handles(1), diag%axesT1%handles(2), id\_ang /), axes\_ang)
2487 
2488   \textcolor{keywordflow}{do} fr=1,cs%nFreq ; \textcolor{keyword}{write}(freq\_name(fr), \textcolor{stringliteral}{'("freq",i1)'}) fr ;\textcolor{keywordflow}{ enddo}
2489   \textcolor{keywordflow}{do} m=1,cs%nMode ; \textcolor{keywordflow}{do} fr=1,cs%nFreq
2490     \textcolor{comment}{! Register 2-D energy density (summed over angles) for each freq and mode}
2491     \textcolor{keyword}{write}(var\_name, \textcolor{stringliteral}{'("Itide\_En\_freq",i1,"\_mode",i1)'}) fr, m
2492     \textcolor{keyword}{write}(var\_descript, \textcolor{stringliteral}{'("Internal tide energy density in frequency ",i1," mode ",i1)'}) fr, m
2493     cs%id\_En\_mode(fr,m) = register\_diag\_field(\textcolor{stringliteral}{'ocean\_model'}, var\_name, &
2494                  diag%axesT1, time, var\_descript, \textcolor{stringliteral}{'J m-2'}, conversion=us%RZ3\_T3\_to\_W\_m2*us%T\_to\_s)
2495     \textcolor{keyword}{call }mom\_mesg(\textcolor{stringliteral}{"Registering "}//trim(var\_name)//\textcolor{stringliteral}{", Described as: "}//var\_descript, 5)
2496 
2497     \textcolor{comment}{! Register 3-D (i,j,a) energy density for each freq and mode}
2498     \textcolor{keyword}{write}(var\_name, \textcolor{stringliteral}{'("Itide\_En\_ang\_freq",i1,"\_mode",i1)'}) fr, m
2499     \textcolor{keyword}{write}(var\_descript, \textcolor{stringliteral}{'("Internal tide angular energy density in frequency ",i1," mode ",i1)'}) fr, m
2500     cs%id\_En\_ang\_mode(fr,m) = register\_diag\_field(\textcolor{stringliteral}{'ocean\_model'}, var\_name, &
2501                  axes\_ang, time, var\_descript, \textcolor{stringliteral}{'J m-2 band-1'}, conversion=us%RZ3\_T3\_to\_W\_m2*us%T\_to\_s)
2502     \textcolor{keyword}{call }mom\_mesg(\textcolor{stringliteral}{"Registering "}//trim(var\_name)//\textcolor{stringliteral}{", Described as: "}//var\_descript, 5)
2503 
2504     \textcolor{comment}{! Register 2-D energy loss (summed over angles) for each freq and mode}
2505     \textcolor{comment}{! wave-drag only}
2506     \textcolor{keyword}{write}(var\_name, \textcolor{stringliteral}{'("Itide\_wavedrag\_loss\_freq",i1,"\_mode",i1)'}) fr, m
2507     \textcolor{keyword}{write}(var\_descript, \textcolor{stringliteral}{'("Internal tide energy loss due to wave-drag from frequency ",i1," mode ",i1)'}) fr
      , m
2508     cs%id\_itidal\_loss\_mode(fr,m) = register\_diag\_field(\textcolor{stringliteral}{'ocean\_model'}, var\_name, &
2509                  diag%axesT1, time, var\_descript, \textcolor{stringliteral}{'W m-2'}, conversion=us%RZ3\_T3\_to\_W\_m2)
2510     \textcolor{keyword}{call }mom\_mesg(\textcolor{stringliteral}{"Registering "}//trim(var\_name)//\textcolor{stringliteral}{", Described as: "}//var\_descript, 5)
2511     \textcolor{comment}{! all loss processes}
2512     \textcolor{keyword}{write}(var\_name, \textcolor{stringliteral}{'("Itide\_allprocesses\_loss\_freq",i1,"\_mode",i1)'}) fr, m
2513     \textcolor{keyword}{write}(var\_descript, \textcolor{stringliteral}{'("Internal tide energy loss due to all processes from frequency ",i1," mode ",i1)'}
      ) fr, m
2514     cs%id\_allprocesses\_loss\_mode(fr,m) = register\_diag\_field(\textcolor{stringliteral}{'ocean\_model'}, var\_name, &
2515                  diag%axesT1, time, var\_descript, \textcolor{stringliteral}{'W m-2'}, conversion=us%RZ3\_T3\_to\_W\_m2)
2516     \textcolor{keyword}{call }mom\_mesg(\textcolor{stringliteral}{"Registering "}//trim(var\_name)//\textcolor{stringliteral}{", Described as: "}//var\_descript, 5)
2517 
2518     \textcolor{comment}{! Register 3-D (i,j,a) energy loss for each freq and mode}
2519     \textcolor{comment}{! wave-drag only}
2520     \textcolor{keyword}{write}(var\_name, \textcolor{stringliteral}{'("Itide\_wavedrag\_loss\_ang\_freq",i1,"\_mode",i1)'}) fr, m
2521     \textcolor{keyword}{write}(var\_descript, \textcolor{stringliteral}{'("Internal tide energy loss due to wave-drag from frequency ",i1," mode ",i1)'}) fr
      , m
2522     cs%id\_itidal\_loss\_ang\_mode(fr,m) = register\_diag\_field(\textcolor{stringliteral}{'ocean\_model'}, var\_name, &
2523                  axes\_ang, time, var\_descript, \textcolor{stringliteral}{'W m-2 band-1'}, conversion=us%RZ3\_T3\_to\_W\_m2)
2524     \textcolor{keyword}{call }mom\_mesg(\textcolor{stringliteral}{"Registering "}//trim(var\_name)//\textcolor{stringliteral}{", Described as: "}//var\_descript, 5)
2525 
2526     \textcolor{comment}{! Register 2-D period-averaged near-bottom horizonal velocity for each freq and mode}
2527     \textcolor{keyword}{write}(var\_name, \textcolor{stringliteral}{'("Itide\_Ub\_freq",i1,"\_mode",i1)'}) fr, m
2528     \textcolor{keyword}{write}(var\_descript, \textcolor{stringliteral}{'("Near-bottom horizonal velocity for frequency ",i1," mode ",i1)'}) fr, m
2529     cs%id\_Ub\_mode(fr,m) = register\_diag\_field(\textcolor{stringliteral}{'ocean\_model'}, var\_name, &
2530                  diag%axesT1, time, var\_descript, \textcolor{stringliteral}{'m s-1'}, conversion=us%L\_T\_to\_m\_s)
2531     \textcolor{keyword}{call }mom\_mesg(\textcolor{stringliteral}{"Registering "}//trim(var\_name)//\textcolor{stringliteral}{", Described as: "}//var\_descript, 5)
2532 
2533     \textcolor{comment}{! Register 2-D horizonal phase velocity for each freq and mode}
2534     \textcolor{keyword}{write}(var\_name, \textcolor{stringliteral}{'("Itide\_cp\_freq",i1,"\_mode",i1)'}) fr, m
2535     \textcolor{keyword}{write}(var\_descript, \textcolor{stringliteral}{'("Horizonal phase velocity for frequency ",i1," mode ",i1)'}) fr, m
2536     cs%id\_cp\_mode(fr,m) = register\_diag\_field(\textcolor{stringliteral}{'ocean\_model'}, var\_name, &
2537                  diag%axesT1, time, var\_descript, \textcolor{stringliteral}{'m s-1'}, conversion=us%L\_T\_to\_m\_s)
2538     \textcolor{keyword}{call }mom\_mesg(\textcolor{stringliteral}{"Registering "}//trim(var\_name)//\textcolor{stringliteral}{", Described as: "}//var\_descript, 5)
2539 
2540 \textcolor{keywordflow}{  enddo} ;\textcolor{keywordflow}{ enddo}
2541 
2542   \textcolor{comment}{! Initialize wave\_structure (not sure if this should be here - BDM)}
2543   \textcolor{keyword}{call }wave\_structure\_init(time, g, param\_file, diag, cs%wave\_structure\_CSp)
2544 
\end{DoxyCode}
\mbox{\Hypertarget{namespacemom__internal__tides_a73ad407c5ea74fc20e58810937d2addf}\label{namespacemom__internal__tides_a73ad407c5ea74fc20e58810937d2addf}} 
\index{mom\+\_\+internal\+\_\+tides@{mom\+\_\+internal\+\_\+tides}!itidal\+\_\+lowmode\+\_\+loss@{itidal\+\_\+lowmode\+\_\+loss}}
\index{itidal\+\_\+lowmode\+\_\+loss@{itidal\+\_\+lowmode\+\_\+loss}!mom\+\_\+internal\+\_\+tides@{mom\+\_\+internal\+\_\+tides}}
\subsubsection{\texorpdfstring{itidal\+\_\+lowmode\+\_\+loss()}{itidal\_lowmode\_loss()}}
{\footnotesize\ttfamily subroutine mom\+\_\+internal\+\_\+tides\+::itidal\+\_\+lowmode\+\_\+loss (\begin{DoxyParamCaption}\item[{type(ocean\+\_\+grid\+\_\+type), intent(in)}]{G,  }\item[{type(unit\+\_\+scale\+\_\+type), intent(in)}]{US,  }\item[{type(\hyperlink{structmom__internal__tides_1_1int__tide__cs}{int\+\_\+tide\+\_\+cs}), pointer}]{CS,  }\item[{real, dimension(g\%isd\+:g\%ied,g\%jsd\+:g\%jed), intent(in)}]{Nb,  }\item[{real, dimension(g\%isd\+:g\%ied,g\%jsd\+:g\%jed,cs\%nfreq,cs\%nmode), intent(inout)}]{Ub,  }\item[{real, dimension(g\%isd\+:g\%ied,g\%jsd\+:g\%jed,cs\%nangle,cs\%nfreq,cs\%nmode), intent(inout)}]{En,  }\item[{real, dimension(g\%isd\+:g\%ied,g\%jsd\+:g\%jed), intent(in)}]{T\+K\+E\+\_\+loss\+\_\+fixed,  }\item[{real, dimension(g\%isd\+:g\%ied,g\%jsd\+:g\%jed,cs\%nangle,cs\%nfreq,cs\%nmode), intent(out)}]{T\+K\+E\+\_\+loss,  }\item[{real, intent(in)}]{dt,  }\item[{logical, intent(in), optional}]{full\+\_\+halos }\end{DoxyParamCaption})\hspace{0.3cm}{\ttfamily [private]}}



Calculates the energy lost from the propagating internal tide due to scattering over small-\/scale roughness along the lines of Jayne \& St. Laurent (2001). 


\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
 & {\em cs} & The control structure returned by a previous call to int\+\_\+tide\+\_\+init.\\
\hline
\mbox{\tt in}  & {\em nb} & Near-\/bottom stratification \mbox{[}T-\/1 $\sim$$>$ s-\/1\mbox{]}.\\
\hline
\mbox{\tt in,out}  & {\em ub} & R\+MS (over one period) near-\/bottom horizontal\\
\hline
\mbox{\tt in}  & {\em tke\+\_\+loss\+\_\+fixed} & Fixed part of energy loss \mbox{[}R L-\/2 Z3 $\sim$$>$ kg m-\/2\mbox{]}\\
\hline
\mbox{\tt in,out}  & {\em en} & Energy density of the internal waves \mbox{[}R Z3 T-\/2 $\sim$$>$ J m-\/2\mbox{]}.\\
\hline
\mbox{\tt out}  & {\em tke\+\_\+loss} & Energy loss rate \mbox{[}R Z3 T-\/3 $\sim$$>$ W m-\/2\mbox{]}\\
\hline
\mbox{\tt in}  & {\em dt} & Time increment \mbox{[}T $\sim$$>$ s\mbox{]}.\\
\hline
\mbox{\tt in}  & {\em full\+\_\+halos} & If true, do the calculation over the entirecomputational domain. \\
\hline
\end{DoxyParams}


Definition at line 636 of file M\+O\+M\+\_\+internal\+\_\+tides.\+F90.


\begin{DoxyCode}
636   \textcolor{keywordtype}{type}(ocean\_grid\_type),     \textcolor{keywordtype}{intent(in)}    :: g\textcolor{comment}{  !< The ocean's grid structure.}
637   \textcolor{keywordtype}{type}(unit\_scale\_type),     \textcolor{keywordtype}{intent(in)}    :: us\textcolor{comment}{ !< A dimensional unit scaling type}
638   \textcolor{keywordtype}{type}(int\_tide\_cs),         \textcolor{keywordtype}{pointer}       :: cs\textcolor{comment}{ !< The control structure returned by a}
639 \textcolor{comment}{                                                 !! previous call to int\_tide\_init.}
640   \textcolor{keywordtype}{real}, \textcolor{keywordtype}{dimension(G%isd:G%ied,G%jsd:G%jed)}, &
641                              \textcolor{keywordtype}{intent(in)}    :: nb\textcolor{comment}{ !< Near-bottom stratification [T-1 ~> s-1].}
642   \textcolor{keywordtype}{real}, \textcolor{keywordtype}{dimension(G%isd:G%ied,G%jsd:G%jed,CS%nFreq,CS%nMode)}, &
643                              \textcolor{keywordtype}{intent(inout)} :: ub\textcolor{comment}{ !< RMS (over one period) near-bottom horizontal}
644 \textcolor{comment}{                                                 !! mode velocity [L T-1 ~> m s-1].}
645   \textcolor{keywordtype}{real}, \textcolor{keywordtype}{dimension(G%isd:G%ied,G%jsd:G%jed)}, &
646                              \textcolor{keywordtype}{intent(in)} :: tke\_loss\_fixed\textcolor{comment}{ !< Fixed part of energy loss [R L-2 Z3 ~> kg m-2]}
647 \textcolor{comment}{                                                 !! (rho*kappa*h^2).}
648   \textcolor{keywordtype}{real}, \textcolor{keywordtype}{dimension(G%isd:G%ied,G%jsd:G%jed,CS%NAngle,CS%nFreq,CS%nMode)}, &
649                              \textcolor{keywordtype}{intent(inout)} :: en\textcolor{comment}{ !< Energy density of the internal waves [R Z3 T-2 ~> J
       m-2].}
650   \textcolor{keywordtype}{real}, \textcolor{keywordtype}{dimension(G%isd:G%ied,G%jsd:G%jed,CS%NAngle,CS%nFreq,CS%nMode)}, &
651                              \textcolor{keywordtype}{intent(out)}   :: tke\_loss\textcolor{comment}{    !< Energy loss rate [R Z3 T-3 ~> W m-2]}
652 \textcolor{comment}{                                                 !! (q*rho*kappa*h^2*N*U^2).}
653   \textcolor{keywordtype}{real},                      \textcolor{keywordtype}{intent(in)}    :: dt\textcolor{comment}{ !< Time increment [T ~> s].}
654   \textcolor{keywordtype}{logical},\textcolor{keywordtype}{optional},          \textcolor{keywordtype}{intent(in)}    :: full\_halos\textcolor{comment}{  !< If true, do the calculation over the}
655 \textcolor{comment}{                                                 !! entirecomputational domain.}
656   \textcolor{comment}{! Local variables}
657   \textcolor{keywordtype}{integer} :: j,i,m,fr,a, is, ie, js, je
658   \textcolor{keywordtype}{real}    :: en\_tot          \textcolor{comment}{! energy for a given mode, frequency, and point summed over angles [R Z3 T-2
       ~> J m-2]}
659   \textcolor{keywordtype}{real}    :: tke\_loss\_tot    \textcolor{comment}{! dissipation for a given mode, frequency, and point summed over angles [R Z3
       T-3 ~> W m-2]}
660   \textcolor{keywordtype}{real}    :: tke\_sum\_check   \textcolor{comment}{! temporary for check summing}
661   \textcolor{keywordtype}{real}    :: frac\_per\_sector \textcolor{comment}{! fraction of energy in each wedge}
662   \textcolor{keywordtype}{real}    :: q\_itides        \textcolor{comment}{! fraction of energy actually lost to mixing (remainder, 1-q, is}
663                              \textcolor{comment}{! assumed to stay in propagating mode for now - BDM)}
664   \textcolor{keywordtype}{real}    :: loss\_rate       \textcolor{comment}{! approximate loss rate for implicit calc [T-1 ~> s-1]}
665   \textcolor{keywordtype}{real}    :: en\_negl         \textcolor{comment}{! negilibly small number to prevent division by zero}
666 
667   is = g%isc ; ie = g%iec ; js = g%jsc ; je = g%jec
668 
669   q\_itides = cs%q\_itides
670   en\_negl = 1e-30*us%kg\_m3\_to\_R*us%m\_to\_Z**3*us%T\_to\_s**2
671 
672   \textcolor{keywordflow}{if} (\textcolor{keyword}{present}(full\_halos)) \textcolor{keywordflow}{then} ; \textcolor{keywordflow}{if} (full\_halos) \textcolor{keywordflow}{then}
673     is = g%isd ; ie = g%ied ; js = g%jsd ; je = g%jed
674 \textcolor{keywordflow}{  endif} ;\textcolor{keywordflow}{ endif}
675 
676   \textcolor{keywordflow}{do} j=js,je ; \textcolor{keywordflow}{do} i=is,ie ; \textcolor{keywordflow}{do} m=1,cs%nMode ; \textcolor{keywordflow}{do} fr=1,cs%nFreq
677 
678     \textcolor{comment}{! Sum energy across angles}
679     en\_tot = 0.0
680     \textcolor{keywordflow}{do} a=1,cs%nAngle
681       en\_tot = en\_tot + en(i,j,a,fr,m)
682 \textcolor{keywordflow}{    enddo}
683 
684     \textcolor{comment}{! Calculate TKE loss rate; units of [R Z3 T-3 ~> W m-2] here.}
685     tke\_loss\_tot = q\_itides * tke\_loss\_fixed(i,j) * nb(i,j) * ub(i,j,fr,m)**2
686 
687     \textcolor{comment}{! Update energy remaining (this is a pseudo implicit calc)}
688     \textcolor{comment}{! (E(t+1)-E(t))/dt = -TKE\_loss(E(t+1)/E(t)), which goes to zero as E(t+1) goes to zero}
689     \textcolor{keywordflow}{if} (en\_tot > 0.0) \textcolor{keywordflow}{then}
690       \textcolor{keywordflow}{do} a=1,cs%nAngle
691         frac\_per\_sector = en(i,j,a,fr,m)/en\_tot
692         tke\_loss(i,j,a,fr,m) = frac\_per\_sector*tke\_loss\_tot           \textcolor{comment}{! Wm-2}
693         loss\_rate = tke\_loss(i,j,a,fr,m) / (en(i,j,a,fr,m) + en\_negl) \textcolor{comment}{! [T-1 ~> s-1]}
694         en(i,j,a,fr,m) = en(i,j,a,fr,m) / (1.0 + dt*loss\_rate)
695 \textcolor{keywordflow}{      enddo}
696     \textcolor{keywordflow}{else}
697       \textcolor{comment}{! no loss if no energy}
698       tke\_loss(i,j,:,fr,m) = 0.0
699 \textcolor{keywordflow}{    endif}
700 
701     \textcolor{comment}{! Update energy remaining (this is the old explicit calc)}
702     \textcolor{comment}{!if (En\_tot > 0.0) then}
703     \textcolor{comment}{!  do a=1,CS%nAngle}
704     \textcolor{comment}{!    frac\_per\_sector = En(i,j,a,fr,m)/En\_tot}
705     \textcolor{comment}{!    TKE\_loss(i,j,a,fr,m) = frac\_per\_sector*TKE\_loss\_tot}
706     \textcolor{comment}{!    if (TKE\_loss(i,j,a,fr,m)*dt <= En(i,j,a,fr,m))then}
707     \textcolor{comment}{!      En(i,j,a,fr,m) = En(i,j,a,fr,m) - TKE\_loss(i,j,a,fr,m)*dt}
708     \textcolor{comment}{!    else}
709     \textcolor{comment}{!      call MOM\_error(WARNING, "itidal\_lowmode\_loss: energy loss greater than avalable, "// &}
710     \textcolor{comment}{!                        " setting En to zero.", all\_print=.true.)}
711     \textcolor{comment}{!      En(i,j,a,fr,m) = 0.0}
712     \textcolor{comment}{!    endif}
713     \textcolor{comment}{!  enddo}
714     \textcolor{comment}{!else}
715     \textcolor{comment}{!  ! no loss if no energy}
716     \textcolor{comment}{!  TKE\_loss(i,j,:,fr,m) = 0.0}
717     \textcolor{comment}{!endif}
718 
719 \textcolor{keywordflow}{  enddo} ;\textcolor{keywordflow}{ enddo} ;\textcolor{keywordflow}{ enddo} ;\textcolor{keywordflow}{ enddo}
720 
\end{DoxyCode}
\mbox{\Hypertarget{namespacemom__internal__tides_aa1b6ca95d1076457e3b7ca32942be143}\label{namespacemom__internal__tides_aa1b6ca95d1076457e3b7ca32942be143}} 
\index{mom\+\_\+internal\+\_\+tides@{mom\+\_\+internal\+\_\+tides}!merid\+\_\+flux\+\_\+en@{merid\+\_\+flux\+\_\+en}}
\index{merid\+\_\+flux\+\_\+en@{merid\+\_\+flux\+\_\+en}!mom\+\_\+internal\+\_\+tides@{mom\+\_\+internal\+\_\+tides}}
\subsubsection{\texorpdfstring{merid\+\_\+flux\+\_\+en()}{merid\_flux\_en()}}
{\footnotesize\ttfamily subroutine mom\+\_\+internal\+\_\+tides\+::merid\+\_\+flux\+\_\+en (\begin{DoxyParamCaption}\item[{real, dimension( g \%isd\+: g \%ied), intent(in)}]{v,  }\item[{real, dimension( g \%isd\+: g \%ied, g \%jsd\+: g \%jed), intent(in)}]{h,  }\item[{real, dimension( g \%isd\+: g \%ied, g \%jsd\+: g \%jed), intent(in)}]{hL,  }\item[{real, dimension( g \%isd\+: g \%ied, g \%jsd\+: g \%jed), intent(in)}]{hR,  }\item[{real, dimension( g \%isd\+: g \%ied), intent(inout)}]{vh,  }\item[{real, intent(in)}]{dt,  }\item[{type(ocean\+\_\+grid\+\_\+type), intent(in)}]{G,  }\item[{type(unit\+\_\+scale\+\_\+type), intent(in)}]{US,  }\item[{integer, intent(in)}]{J,  }\item[{integer, intent(in)}]{ish,  }\item[{integer, intent(in)}]{ieh,  }\item[{logical, intent(in)}]{vol\+\_\+\+C\+FL }\end{DoxyParamCaption})\hspace{0.3cm}{\ttfamily [private]}}



Evaluates the meridional mass or volume fluxes in a layer. 


\begin{DoxyParams}[1]{Parameters}
\mbox{\tt in}  & {\em g} & The ocean\textquotesingle{}s grid structure.\\
\hline
\mbox{\tt in}  & {\em v} & The meridional velocity \mbox{[}L T-\/1 $\sim$$>$ m s-\/1\mbox{]}.\\
\hline
\mbox{\tt in}  & {\em h} & Energy density used to calculate the fluxes \mbox{[}R Z3 T-\/2 $\sim$$>$ J m-\/2\mbox{]}.\\
\hline
\mbox{\tt in}  & {\em hl} & Left-\/ Energy densities in the reconstruction \mbox{[}R Z3 T-\/2 $\sim$$>$ J m-\/2\mbox{]}.\\
\hline
\mbox{\tt in}  & {\em hr} & Right-\/ Energy densities in the reconstruction \mbox{[}R Z3 T-\/2 $\sim$$>$ J m-\/2\mbox{]}.\\
\hline
\mbox{\tt in,out}  & {\em vh} & The meridional energy transport \mbox{[}R Z3 L2 T-\/3 $\sim$$>$ J s-\/1\mbox{]}.\\
\hline
\mbox{\tt in}  & {\em dt} & Time increment \mbox{[}T $\sim$$>$ s\mbox{]}.\\
\hline
\mbox{\tt in}  & {\em us} & A dimensional unit scaling type\\
\hline
\mbox{\tt in}  & {\em j} & The j-\/index to work on.\\
\hline
\mbox{\tt in}  & {\em ish} & The start i-\/index range to work on.\\
\hline
\mbox{\tt in}  & {\em ieh} & The end i-\/index range to work on.\\
\hline
\mbox{\tt in}  & {\em vol\+\_\+cfl} & If true, rescale the ratio of face areas to the cell areas when estimating the C\+FL number. \\
\hline
\end{DoxyParams}


Definition at line 1559 of file M\+O\+M\+\_\+internal\+\_\+tides.\+F90.


\begin{DoxyCode}
1559   \textcolor{keywordtype}{type}(ocean\_grid\_type),            \textcolor{keywordtype}{intent(in)}    :: g\textcolor{comment}{  !< The ocean's grid structure.}
1560   \textcolor{keywordtype}{real}, \textcolor{keywordtype}{dimension(SZI\_(G))},         \textcolor{keywordtype}{intent(in)}    :: v\textcolor{comment}{  !< The meridional velocity [L T-1 ~> m s-1].}
1561   \textcolor{keywordtype}{real}, \textcolor{keywordtype}{dimension(SZI\_(G),SZJ\_(G))}, \textcolor{keywordtype}{intent(in)}    :: h\textcolor{comment}{  !< Energy density used to calculate the}
1562 \textcolor{comment}{                                                        !! fluxes [R Z3 T-2 ~> J m-2].}
1563   \textcolor{keywordtype}{real}, \textcolor{keywordtype}{dimension(SZI\_(G),SZJ\_(G))}, \textcolor{keywordtype}{intent(in)}    :: hl\textcolor{comment}{ !< Left- Energy densities in the}
1564 \textcolor{comment}{                                                        !! reconstruction [R Z3 T-2 ~> J m-2].}
1565   \textcolor{keywordtype}{real}, \textcolor{keywordtype}{dimension(SZI\_(G),SZJ\_(G))}, \textcolor{keywordtype}{intent(in)}    :: hr\textcolor{comment}{ !< Right- Energy densities in the}
1566 \textcolor{comment}{                                                        !! reconstruction [R Z3 T-2 ~> J m-2].}
1567   \textcolor{keywordtype}{real}, \textcolor{keywordtype}{dimension(SZI\_(G))},         \textcolor{keywordtype}{intent(inout)} :: vh\textcolor{comment}{ !< The meridional energy transport [R Z3 L2 T-3 ~>
       J s-1].}
1568   \textcolor{keywordtype}{real},                             \textcolor{keywordtype}{intent(in)}    :: dt\textcolor{comment}{ !< Time increment [T ~> s].}
1569   \textcolor{keywordtype}{type}(unit\_scale\_type),            \textcolor{keywordtype}{intent(in)}    :: us\textcolor{comment}{ !< A dimensional unit scaling type}
1570   \textcolor{keywordtype}{integer},                          \textcolor{keywordtype}{intent(in)}    :: j\textcolor{comment}{  !< The j-index to work on.}
1571   \textcolor{keywordtype}{integer},                          \textcolor{keywordtype}{intent(in)}    :: ish\textcolor{comment}{ !< The start i-index range to work on.}
1572   \textcolor{keywordtype}{integer},                          \textcolor{keywordtype}{intent(in)}    :: ieh\textcolor{comment}{ !< The end i-index range to work on.}
1573   \textcolor{keywordtype}{logical},                          \textcolor{keywordtype}{intent(in)}    :: vol\_cfl\textcolor{comment}{ !< If true, rescale the ratio of face}
1574 \textcolor{comment}{                                                        !! areas to the cell areas when estimating}
1575 \textcolor{comment}{                                                        !! the CFL number.}
1576   \textcolor{comment}{! Local variables}
1577   \textcolor{keywordtype}{real} :: cfl \textcolor{comment}{! The CFL number based on the local velocity and grid spacing [nondim].}
1578   \textcolor{keywordtype}{real} :: curv\_3 \textcolor{comment}{! A measure of the energy density curvature over a grid length [R Z3 T-2 ~> J m-2]}
1579   \textcolor{keywordtype}{integer} :: i
1580 
1581   \textcolor{keywordflow}{do} i=ish,ieh
1582     \textcolor{keywordflow}{if} (v(i) > 0.0) \textcolor{keywordflow}{then}
1583       \textcolor{keywordflow}{if} (vol\_cfl) \textcolor{keywordflow}{then} ; cfl = (v(i) * dt) * (g%dx\_Cv(i,j) * g%IareaT(i,j))
1584       \textcolor{keywordflow}{else} ; cfl = v(i) * dt * g%IdyT(i,j) ;\textcolor{keywordflow}{ endif}
1585       curv\_3 = hl(i,j) + hr(i,j) - 2.0*h(i,j)
1586       vh(i) = g%dx\_Cv(i,j) * v(i) * ( hr(i,j) + cfl * &
1587           (0.5*(hl(i,j) - hr(i,j)) + curv\_3*(cfl - 1.5)) )
1588     \textcolor{keywordflow}{elseif} (v(i) < 0.0) \textcolor{keywordflow}{then}
1589       \textcolor{keywordflow}{if} (vol\_cfl) \textcolor{keywordflow}{then} ; cfl = (-v(i) * dt) * (g%dx\_Cv(i,j) * g%IareaT(i,j+1))
1590       \textcolor{keywordflow}{else} ; cfl = -v(i) * dt * g%IdyT(i,j+1) ;\textcolor{keywordflow}{ endif}
1591       curv\_3 = hl(i,j+1) + hr(i,j+1) - 2.0*h(i,j+1)
1592       vh(i) = g%dx\_Cv(i,j) * v(i) * ( hl(i,j+1) + cfl * &
1593           (0.5*(hr(i,j+1)-hl(i,j+1)) + curv\_3*(cfl - 1.5)) )
1594     \textcolor{keywordflow}{else}
1595       vh(i) = 0.0
1596 \textcolor{keywordflow}{    endif}
1597 \textcolor{keywordflow}{  enddo}
\end{DoxyCode}
\mbox{\Hypertarget{namespacemom__internal__tides_ae34593443ab6362445946e9d75528155}\label{namespacemom__internal__tides_ae34593443ab6362445946e9d75528155}} 
\index{mom\+\_\+internal\+\_\+tides@{mom\+\_\+internal\+\_\+tides}!ppm\+\_\+angular\+\_\+advect@{ppm\+\_\+angular\+\_\+advect}}
\index{ppm\+\_\+angular\+\_\+advect@{ppm\+\_\+angular\+\_\+advect}!mom\+\_\+internal\+\_\+tides@{mom\+\_\+internal\+\_\+tides}}
\subsubsection{\texorpdfstring{ppm\+\_\+angular\+\_\+advect()}{ppm\_angular\_advect()}}
{\footnotesize\ttfamily subroutine mom\+\_\+internal\+\_\+tides\+::ppm\+\_\+angular\+\_\+advect (\begin{DoxyParamCaption}\item[{real, dimension(1-\/halo\+\_\+ang\+:nangle+halo\+\_\+ang), intent(in)}]{En2d,  }\item[{real, dimension(1-\/halo\+\_\+ang\+:nangle+halo\+\_\+ang), intent(in)}]{C\+F\+L\+\_\+ang,  }\item[{real, dimension(0\+:nangle), intent(out)}]{Flux\+\_\+\+En,  }\item[{integer, intent(in)}]{N\+Angle,  }\item[{real, intent(in)}]{dt,  }\item[{integer, intent(in)}]{halo\+\_\+ang }\end{DoxyParamCaption})\hspace{0.3cm}{\ttfamily [private]}}



This subroutine calculates the 1-\/d flux for advection in angular space using a monotonic piecewise parabolic scheme. This needs to be called from within i and j spatial loops. 


\begin{DoxyParams}[1]{Parameters}
\mbox{\tt in}  & {\em nangle} & The number of wave orientations in the discretized wave energy spectrum.\\
\hline
\mbox{\tt in}  & {\em dt} & Time increment \mbox{[}T $\sim$$>$ s\mbox{]}.\\
\hline
\mbox{\tt in}  & {\em halo\+\_\+ang} & The halo size in angular space\\
\hline
\mbox{\tt in}  & {\em en2d} & The internal gravity wave energy density as a\\
\hline
\mbox{\tt in}  & {\em cfl\+\_\+ang} & The C\+FL number of the energy advection across angles\\
\hline
\mbox{\tt out}  & {\em flux\+\_\+en} & The time integrated internal wave energy flux across angles \mbox{[}R Z3 T-\/2 $\sim$$>$ J m-\/2\mbox{]}. \\
\hline
\end{DoxyParams}


Definition at line 876 of file M\+O\+M\+\_\+internal\+\_\+tides.\+F90.


\begin{DoxyCode}
876   \textcolor{keywordtype}{integer},                   \textcolor{keywordtype}{intent(in)}    :: nangle\textcolor{comment}{  !< The number of wave orientations in the}
877 \textcolor{comment}{                                                      !! discretized wave energy spectrum.}
878   \textcolor{keywordtype}{real},                      \textcolor{keywordtype}{intent(in)}    :: dt\textcolor{comment}{      !< Time increment [T ~> s].}
879   \textcolor{keywordtype}{integer},                   \textcolor{keywordtype}{intent(in)}    :: halo\_ang\textcolor{comment}{ !< The halo size in angular space}
880   \textcolor{keywordtype}{real}, \textcolor{keywordtype}{dimension(1-halo\_ang:NAngle+halo\_ang)},   &
881                              \textcolor{keywordtype}{intent(in)}    :: en2d\textcolor{comment}{    !< The internal gravity wave energy density as a}
882 \textcolor{comment}{                                                      !! function of angular resolution [R Z3 T-2 ~> J
       m-2].}
883   \textcolor{keywordtype}{real}, \textcolor{keywordtype}{dimension(1-halo\_ang:NAngle+halo\_ang)},   &
884                              \textcolor{keywordtype}{intent(in)}    :: cfl\_ang\textcolor{comment}{ !< The CFL number of the energy advection across
       angles}
885   \textcolor{keywordtype}{real}, \textcolor{keywordtype}{dimension(0:NAngle)}, \textcolor{keywordtype}{intent(out)}   :: flux\_en\textcolor{comment}{ !< The time integrated internal wave energy flux}
886 \textcolor{comment}{                                                      !! across angles  [R Z3 T-2 ~> J m-2].}
887   \textcolor{comment}{! Local variables}
888   \textcolor{keywordtype}{real} :: flux
889   \textcolor{keywordtype}{real} :: u\_ang        \textcolor{comment}{! Angular propagation speed [Rad T-1 ~> Rad s-1]}
890   \textcolor{keywordtype}{real} :: angle\_size   \textcolor{comment}{! The size of each orientation wedge in radians [Rad]}
891   \textcolor{keywordtype}{real} :: i\_angle\_size \textcolor{comment}{! The inverse of the the orientation wedges [Rad-1]}
892   \textcolor{keywordtype}{real} :: i\_dt         \textcolor{comment}{! The inverse of the timestep [T-1 ~> s-1]}
893   \textcolor{keywordtype}{real} :: ar, al       \textcolor{comment}{! Left and right edge estimates of energy density [R Z3 T-2 rad-1 ~> J m-2 rad-1]}
894   \textcolor{keywordtype}{real} :: dmx, dmn
895   \textcolor{keywordtype}{real} :: ep, ec, em   \textcolor{comment}{! Mean angular energy density for three successive wedges in angular}
896                        \textcolor{comment}{! orientation [R Z3 T-2 rad-1 ~> J m-2 rad-1]}
897   \textcolor{keywordtype}{real} :: da, curv\_3   \textcolor{comment}{! Difference and curvature of energy density [R Z3 T-2 rad-1 ~> J m-2 rad-1]}
898   \textcolor{keywordtype}{real}, \textcolor{keywordtype}{parameter} :: onesixth = 1.0/6.0  \textcolor{comment}{! One sixth [nondim]}
899   \textcolor{keywordtype}{integer} :: a
900 
901   i\_dt = 1 / dt
902   angle\_size = (8.0*atan(1.0)) / (\textcolor{keywordtype}{real}(nangle))
903   i\_angle\_size = 1 / angle\_size
904   flux\_en(:) = 0
905 
906   \textcolor{keywordflow}{do} a=0,nangle
907     u\_ang = cfl\_ang(a)*angle\_size*i\_dt
908     \textcolor{keywordflow}{if} (u\_ang >= 0.0) \textcolor{keywordflow}{then}
909       \textcolor{comment}{! Implementation of PPM-H3}
910       \textcolor{comment}{! Convert wedge-integrated energy density into angular energy densities for three successive}
911       \textcolor{comment}{! wedges around the source wedge for this flux [R Z3 T-2 rad-1 ~> J m-2 rad-1].}
912       ep = en2d(a+1)*i\_angle\_size
913       ec = en2d(a)  *i\_angle\_size
914       em = en2d(a-1)*i\_angle\_size
915       \textcolor{comment}{! Calculate and bound edge values of energy density.}
916       al = ( 5.*ec + ( 2.*em - ep ) ) * onesixth \textcolor{comment}{! H3 estimate}
917       al = max( min(ec,em), al) ; al = min( max(ec,em), al) \textcolor{comment}{! Bound}
918       ar = ( 5.*ec + ( 2.*ep - em ) ) * onesixth \textcolor{comment}{! H3 estimate}
919       ar = max( min(ec,ep), ar) ; ar = min( max(ec,ep), ar) \textcolor{comment}{! Bound}
920       da = ar - al
921       \textcolor{keywordflow}{if} ((ep-ec)*(ec-em) <= 0.) \textcolor{keywordflow}{then}
922         al = ec ; ar = ec    \textcolor{comment}{! use PCM for local extremum}
923       \textcolor{keywordflow}{elseif} ( 3.0*da*(2.*ec - (ar + al)) > (da*da) ) \textcolor{keywordflow}{then}
924         al = 3.*ec - 2.*ar   \textcolor{comment}{! Flatten the profile to move the extremum to the left edge}
925       \textcolor{keywordflow}{elseif} ( 3.0*da*(2.*ec - (ar + al)) < - (da*da) ) \textcolor{keywordflow}{then}
926         ar = 3.*ec - 2.*al   \textcolor{comment}{! Flatten the profile to move the extremum to the right edge}
927 \textcolor{keywordflow}{      endif}
928       curv\_3 = (ar + al) - 2.0*ec \textcolor{comment}{! Curvature}
929       \textcolor{comment}{! Calculate angular flux rate [R Z3 T-3 ~> W m-2]}
930       flux = u\_ang*( ar + cfl\_ang(a) * ( 0.5*(al - ar) + curv\_3 * (cfl\_ang(a) - 1.5) ) )
931       \textcolor{comment}{! Calculate amount of energy fluxed between wedges [R Z3 T-2 ~> J m-2]}
932       flux\_en(a) = dt * flux
933       \textcolor{comment}{!Flux\_En(A) = (dt * I\_Angle\_size) * flux}
934     \textcolor{keywordflow}{else}
935       \textcolor{comment}{! Implementation of PPM-H3}
936       \textcolor{comment}{! Convert wedge-integrated energy density into angular energy densities for three successive}
937       \textcolor{comment}{! wedges around the source wedge for this flux [R Z3 T-2 rad-1 ~> J m-2 rad-1].}
938       ep = en2d(a+2)*i\_angle\_size
939       ec = en2d(a+1)*i\_angle\_size
940       em = en2d(a)  *i\_angle\_size
941       \textcolor{comment}{! Calculate and bound edge values of energy density.}
942       al = ( 5.*ec + ( 2.*em - ep ) ) * onesixth \textcolor{comment}{! H3 estimate}
943       al = max( min(ec,em), al) ; al = min( max(ec,em), al) \textcolor{comment}{! Bound}
944       ar = ( 5.*ec + ( 2.*ep - em ) ) * onesixth \textcolor{comment}{! H3 estimate}
945       ar = max( min(ec,ep), ar) ; ar = min( max(ec,ep), ar) \textcolor{comment}{! Bound}
946       da = ar - al
947       \textcolor{keywordflow}{if} ((ep-ec)*(ec-em) <= 0.) \textcolor{keywordflow}{then}
948         al = ec ; ar = ec    \textcolor{comment}{! use PCM for local extremum}
949       \textcolor{keywordflow}{elseif} ( 3.0*da*(2.*ec - (ar + al)) > (da*da) ) \textcolor{keywordflow}{then}
950         al = 3.*ec - 2.*ar   \textcolor{comment}{! Flatten the profile to move the extremum to the left edge}
951       \textcolor{keywordflow}{elseif} ( 3.0*da*(2.*ec - (ar + al)) < - (da*da) ) \textcolor{keywordflow}{then}
952         ar = 3.*ec - 2.*al   \textcolor{comment}{! Flatten the profile to move the extremum to the right edge}
953 \textcolor{keywordflow}{      endif}
954       curv\_3 = (ar + al) - 2.0*ec \textcolor{comment}{! Curvature}
955       \textcolor{comment}{! Calculate angular flux rate [R Z3 T-3 ~> W m-2]}
956       \textcolor{comment}{! Note that CFL\_ang is negative here, so it looks odd compared with equivalent expressions.}
957       flux = u\_ang*( al - cfl\_ang(a) * ( 0.5*(ar - al) + curv\_3 * (-cfl\_ang(a) - 1.5) ) )
958       \textcolor{comment}{! Calculate amount of energy fluxed between wedges [R Z3 T-2 ~> J m-2]}
959       flux\_en(a) = dt * flux
960       \textcolor{comment}{!Flux\_En(A) = (dt * I\_Angle\_size) * flux}
961 \textcolor{keywordflow}{    endif}
962 \textcolor{keywordflow}{  enddo}
\end{DoxyCode}
\mbox{\Hypertarget{namespacemom__internal__tides_a16dd5b071e0fc87eb04c32f602c08aa5}\label{namespacemom__internal__tides_a16dd5b071e0fc87eb04c32f602c08aa5}} 
\index{mom\+\_\+internal\+\_\+tides@{mom\+\_\+internal\+\_\+tides}!ppm\+\_\+limit\+\_\+pos@{ppm\+\_\+limit\+\_\+pos}}
\index{ppm\+\_\+limit\+\_\+pos@{ppm\+\_\+limit\+\_\+pos}!mom\+\_\+internal\+\_\+tides@{mom\+\_\+internal\+\_\+tides}}
\subsubsection{\texorpdfstring{ppm\+\_\+limit\+\_\+pos()}{ppm\_limit\_pos()}}
{\footnotesize\ttfamily subroutine mom\+\_\+internal\+\_\+tides\+::ppm\+\_\+limit\+\_\+pos (\begin{DoxyParamCaption}\item[{real, dimension( g \%isd\+: g \%ied, g \%jsd\+: g \%jed), intent(in)}]{h\+\_\+in,  }\item[{real, dimension( g \%isd\+: g \%ied, g \%jsd\+: g \%jed), intent(inout)}]{h\+\_\+L,  }\item[{real, dimension( g \%isd\+: g \%ied, g \%jsd\+: g \%jed), intent(inout)}]{h\+\_\+R,  }\item[{real, intent(in)}]{h\+\_\+min,  }\item[{type(ocean\+\_\+grid\+\_\+type), intent(in)}]{G,  }\item[{integer, intent(in)}]{iis,  }\item[{integer, intent(in)}]{iie,  }\item[{integer, intent(in)}]{jis,  }\item[{integer, intent(in)}]{jie }\end{DoxyParamCaption})\hspace{0.3cm}{\ttfamily [private]}}



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


\begin{DoxyParams}[1]{Parameters}
\mbox{\tt in}  & {\em g} & The ocean\textquotesingle{}s grid structure.\\
\hline
\mbox{\tt in}  & {\em h\+\_\+in} & Thickness of layer (2D).\\
\hline
\mbox{\tt in,out}  & {\em h\+\_\+l} & Left edge value (2D).\\
\hline
\mbox{\tt in,out}  & {\em h\+\_\+r} & Right edge value (2D).\\
\hline
\mbox{\tt in}  & {\em h\+\_\+min} & The minimum thickness that can be obtained by a concave parabolic fit.\\
\hline
\mbox{\tt in}  & {\em iis} & Start i-\/index for computations\\
\hline
\mbox{\tt in}  & {\em iie} & End i-\/index for computations\\
\hline
\mbox{\tt in}  & {\em jis} & Start j-\/index for computations\\
\hline
\mbox{\tt in}  & {\em jie} & End j-\/index for computations \\
\hline
\end{DoxyParams}


Definition at line 2022 of file M\+O\+M\+\_\+internal\+\_\+tides.\+F90.


\begin{DoxyCode}
2022   \textcolor{keywordtype}{type}(ocean\_grid\_type),            \textcolor{keywordtype}{intent(in)}     :: g\textcolor{comment}{     !< The ocean's grid structure.}
2023   \textcolor{keywordtype}{real}, \textcolor{keywordtype}{dimension(SZI\_(G),SZJ\_(G))}, \textcolor{keywordtype}{intent(in)}     :: h\_in\textcolor{comment}{  !< Thickness of layer (2D).}
2024   \textcolor{keywordtype}{real}, \textcolor{keywordtype}{dimension(SZI\_(G),SZJ\_(G))}, \textcolor{keywordtype}{intent(inout)}  :: h\_l\textcolor{comment}{   !< Left edge value (2D).}
2025   \textcolor{keywordtype}{real}, \textcolor{keywordtype}{dimension(SZI\_(G),SZJ\_(G))}, \textcolor{keywordtype}{intent(inout)}  :: h\_r\textcolor{comment}{   !< Right edge value (2D).}
2026   \textcolor{keywordtype}{real},                             \textcolor{keywordtype}{intent(in)}     :: h\_min\textcolor{comment}{ !< The minimum thickness that can be}
2027 \textcolor{comment}{                                                            !! obtained by a concave parabolic fit.}
2028   \textcolor{keywordtype}{integer},                          \textcolor{keywordtype}{intent(in)}     :: iis\textcolor{comment}{   !< Start i-index for computations}
2029   \textcolor{keywordtype}{integer},                          \textcolor{keywordtype}{intent(in)}     :: iie\textcolor{comment}{   !< End i-index for computations}
2030   \textcolor{keywordtype}{integer},                          \textcolor{keywordtype}{intent(in)}     :: jis\textcolor{comment}{   !< Start j-index for computations}
2031   \textcolor{keywordtype}{integer},                          \textcolor{keywordtype}{intent(in)}     :: jie\textcolor{comment}{   !< End j-index for computations}
2032   \textcolor{comment}{! Local variables}
2033   \textcolor{keywordtype}{real}    :: curv, dh, scale
2034   \textcolor{keywordtype}{character(len=256)} :: mesg  \textcolor{comment}{! The text of an error message}
2035   \textcolor{keywordtype}{integer} :: i,j
2036 
2037   \textcolor{keywordflow}{do} j=jis,jie ; \textcolor{keywordflow}{do} i=iis,iie
2038     \textcolor{comment}{! This limiter prevents undershooting minima within the domain with}
2039     \textcolor{comment}{! values less than h\_min.}
2040     curv = 3.0*(h\_l(i,j) + h\_r(i,j) - 2.0*h\_in(i,j))
2041     \textcolor{keywordflow}{if} (curv > 0.0) \textcolor{keywordflow}{then} \textcolor{comment}{! Only minima are limited.}
2042       dh = h\_r(i,j) - h\_l(i,j)
2043       \textcolor{keywordflow}{if} (abs(dh) < curv) \textcolor{keywordflow}{then} \textcolor{comment}{! The parabola's minimum is within the cell.}
2044         \textcolor{keywordflow}{if} (h\_in(i,j) <= h\_min) \textcolor{keywordflow}{then}
2045           h\_l(i,j) = h\_in(i,j) ; h\_r(i,j) = h\_in(i,j)
2046         \textcolor{keywordflow}{elseif} (12.0*curv*(h\_in(i,j) - h\_min) < (curv**2 + 3.0*dh**2)) \textcolor{keywordflow}{then}
2047           \textcolor{comment}{! The minimum value is h\_in - (curv^2 + 3*dh^2)/(12*curv), and must}
2048           \textcolor{comment}{! be limited in this case.  0 < scale < 1.}
2049           scale = 12.0*curv*(h\_in(i,j) - h\_min) / (curv**2 + 3.0*dh**2)
2050           h\_l(i,j) = h\_in(i,j) + scale*(h\_l(i,j) - h\_in(i,j))
2051           h\_r(i,j) = h\_in(i,j) + scale*(h\_r(i,j) - h\_in(i,j))
2052 \textcolor{keywordflow}{        endif}
2053 \textcolor{keywordflow}{      endif}
2054 \textcolor{keywordflow}{    endif}
2055 \textcolor{keywordflow}{  enddo} ;\textcolor{keywordflow}{ enddo}
\end{DoxyCode}
\mbox{\Hypertarget{namespacemom__internal__tides_afa863318cc960c0be08672731ce6f225}\label{namespacemom__internal__tides_afa863318cc960c0be08672731ce6f225}} 
\index{mom\+\_\+internal\+\_\+tides@{mom\+\_\+internal\+\_\+tides}!ppm\+\_\+reconstruction\+\_\+x@{ppm\+\_\+reconstruction\+\_\+x}}
\index{ppm\+\_\+reconstruction\+\_\+x@{ppm\+\_\+reconstruction\+\_\+x}!mom\+\_\+internal\+\_\+tides@{mom\+\_\+internal\+\_\+tides}}
\subsubsection{\texorpdfstring{ppm\+\_\+reconstruction\+\_\+x()}{ppm\_reconstruction\_x()}}
{\footnotesize\ttfamily subroutine mom\+\_\+internal\+\_\+tides\+::ppm\+\_\+reconstruction\+\_\+x (\begin{DoxyParamCaption}\item[{real, dimension( g \%isd\+: g \%ied, g \%jsd\+: g \%jed), intent(in)}]{h\+\_\+in,  }\item[{real, dimension( g \%isd\+: g \%ied, g \%jsd\+: g \%jed), intent(out)}]{h\+\_\+l,  }\item[{real, dimension( g \%isd\+: g \%ied, g \%jsd\+: g \%jed), intent(out)}]{h\+\_\+r,  }\item[{type(ocean\+\_\+grid\+\_\+type), intent(in)}]{G,  }\item[{type(\hyperlink{structmom__internal__tides_1_1loop__bounds__type}{loop\+\_\+bounds\+\_\+type}), intent(in)}]{LB,  }\item[{logical, intent(in), optional}]{simple\+\_\+2nd }\end{DoxyParamCaption})\hspace{0.3cm}{\ttfamily [private]}}



Calculates left/right edge values for P\+PM reconstruction in x-\/direction. 


\begin{DoxyParams}[1]{Parameters}
\mbox{\tt in}  & {\em g} & The ocean\textquotesingle{}s grid structure.\\
\hline
\mbox{\tt in}  & {\em h\+\_\+in} & Energy density in a sector (2D).\\
\hline
\mbox{\tt out}  & {\em h\+\_\+l} & Left edge value of reconstruction (2D).\\
\hline
\mbox{\tt out}  & {\em h\+\_\+r} & Right edge value of reconstruction (2D).\\
\hline
\mbox{\tt in}  & {\em lb} & A structure with the active loop bounds.\\
\hline
\mbox{\tt in}  & {\em simple\+\_\+2nd} & If true, use the arithmetic mean energy densities as default edge values for a simple 2nd order scheme. \\
\hline
\end{DoxyParams}


Definition at line 1869 of file M\+O\+M\+\_\+internal\+\_\+tides.\+F90.


\begin{DoxyCode}
1869   \textcolor{keywordtype}{type}(ocean\_grid\_type),            \textcolor{keywordtype}{intent(in)}  :: g\textcolor{comment}{    !< The ocean's grid structure.}
1870   \textcolor{keywordtype}{real}, \textcolor{keywordtype}{dimension(SZI\_(G),SZJ\_(G))}, \textcolor{keywordtype}{intent(in)}  :: h\_in\textcolor{comment}{ !< Energy density in a sector (2D).}
1871   \textcolor{keywordtype}{real}, \textcolor{keywordtype}{dimension(SZI\_(G),SZJ\_(G))}, \textcolor{keywordtype}{intent(out)} :: h\_l\textcolor{comment}{  !< Left edge value of reconstruction (2D).}
1872   \textcolor{keywordtype}{real}, \textcolor{keywordtype}{dimension(SZI\_(G),SZJ\_(G))}, \textcolor{keywordtype}{intent(out)} :: h\_r\textcolor{comment}{  !< Right edge value of reconstruction (2D).}
1873   \textcolor{keywordtype}{type}(loop\_bounds\_type),           \textcolor{keywordtype}{intent(in)}  :: lb\textcolor{comment}{   !< A structure with the active loop bounds.}
1874   \textcolor{keywordtype}{logical}, \textcolor{keywordtype}{optional},                \textcolor{keywordtype}{intent(in)}  :: simple\_2nd\textcolor{comment}{ !< If true, use the arithmetic mean}
1875 \textcolor{comment}{                                                        !! energy densities as default edge values}
1876 \textcolor{comment}{                                                        !! for a simple 2nd order scheme.}
1877   \textcolor{comment}{! Local variables}
1878   \textcolor{keywordtype}{real}, \textcolor{keywordtype}{dimension(SZI\_(G),SZJ\_(G))}  :: slp \textcolor{comment}{! The slopes.}
1879   \textcolor{keywordtype}{real}, \textcolor{keywordtype}{parameter} :: onesixth = 1./6.
1880   \textcolor{keywordtype}{real} :: h\_ip1, h\_im1
1881   \textcolor{keywordtype}{real} :: dmx, dmn
1882   \textcolor{keywordtype}{logical} :: use\_cw84, use\_2nd
1883   \textcolor{keywordtype}{character(len=256)} :: mesg  \textcolor{comment}{! The text of an error message}
1884   \textcolor{keywordtype}{integer} :: i, j, isl, iel, jsl, jel, stencil
1885 
1886   use\_2nd = .false. ; \textcolor{keywordflow}{if} (\textcolor{keyword}{present}(simple\_2nd)) use\_2nd = simple\_2nd
1887   isl = lb%ish-1 ; iel = lb%ieh+1 ; jsl = lb%jsh ; jel = lb%jeh
1888 
1889   \textcolor{comment}{! This is the stencil of the reconstruction, not the scheme overall.}
1890   stencil = 2 ; \textcolor{keywordflow}{if} (use\_2nd) stencil = 1
1891 
1892   \textcolor{keywordflow}{if} ((isl-stencil < g%isd) .or. (iel+stencil > g%ied)) \textcolor{keywordflow}{then}
1893     \textcolor{keyword}{write}(mesg,\textcolor{stringliteral}{'("In MOM\_internal\_tides, PPM\_reconstruction\_x called with a ", &}
1894 \textcolor{stringliteral}{}\textcolor{stringliteral}{               & "x-halo that needs to be increased by ",i2,".")'}) &
1895                stencil + max(g%isd-isl,iel-g%ied)
1896     \textcolor{keyword}{call }mom\_error(fatal,mesg)
1897 \textcolor{keywordflow}{  endif}
1898   \textcolor{keywordflow}{if} ((jsl < g%jsd) .or. (jel > g%jed)) \textcolor{keywordflow}{then}
1899     \textcolor{keyword}{write}(mesg,\textcolor{stringliteral}{'("In MOM\_internal\_tides, PPM\_reconstruction\_x called with a ", &}
1900 \textcolor{stringliteral}{}\textcolor{stringliteral}{               & "y-halo that needs to be increased by ",i2,".")'}) &
1901                max(g%jsd-jsl,jel-g%jed)
1902     \textcolor{keyword}{call }mom\_error(fatal,mesg)
1903 \textcolor{keywordflow}{  endif}
1904 
1905   \textcolor{keywordflow}{if} (use\_2nd) \textcolor{keywordflow}{then}
1906     \textcolor{keywordflow}{do} j=jsl,jel ; \textcolor{keywordflow}{do} i=isl,iel
1907       h\_im1 = g%mask2dT(i-1,j) * h\_in(i-1,j) + (1.0-g%mask2dT(i-1,j)) * h\_in(i,j)
1908       h\_ip1 = g%mask2dT(i+1,j) * h\_in(i+1,j) + (1.0-g%mask2dT(i+1,j)) * h\_in(i,j)
1909       h\_l(i,j) = 0.5*( h\_im1 + h\_in(i,j) )
1910       h\_r(i,j) = 0.5*( h\_ip1 + h\_in(i,j) )
1911 \textcolor{keywordflow}{    enddo} ;\textcolor{keywordflow}{ enddo}
1912   \textcolor{keywordflow}{else}
1913     \textcolor{keywordflow}{do} j=jsl,jel ; \textcolor{keywordflow}{do} i=isl-1,iel+1
1914       \textcolor{keywordflow}{if} ((g%mask2dT(i-1,j) * g%mask2dT(i,j) * g%mask2dT(i+1,j)) == 0.0) \textcolor{keywordflow}{then}
1915         slp(i,j) = 0.0
1916       \textcolor{keywordflow}{else}
1917         \textcolor{comment}{! This uses a simple 2nd order slope.}
1918         slp(i,j) = 0.5 * (h\_in(i+1,j) - h\_in(i-1,j))
1919         \textcolor{comment}{! Monotonic constraint, see Eq. B2 in Lin 1994, MWR (132)}
1920         dmx = max(h\_in(i+1,j), h\_in(i-1,j), h\_in(i,j)) - h\_in(i,j)
1921         dmn = h\_in(i,j) - min(h\_in(i+1,j), h\_in(i-1,j), h\_in(i,j))
1922         slp(i,j) = sign(1.,slp(i,j)) * min(abs(slp(i,j)), 2. * min(dmx, dmn))
1923                 \textcolor{comment}{! * (G%mask2dT(i-1,j) * G%mask2dT(i,j) * G%mask2dT(i+1,j))}
1924 \textcolor{keywordflow}{      endif}
1925 \textcolor{keywordflow}{    enddo} ;\textcolor{keywordflow}{ enddo}
1926 
1927     \textcolor{keywordflow}{do} j=jsl,jel ; \textcolor{keywordflow}{do} i=isl,iel
1928       \textcolor{comment}{! Neighboring values should take into account any boundaries.  The 3}
1929       \textcolor{comment}{! following sets of expressions are equivalent.}
1930     \textcolor{comment}{! h\_im1 = h\_in(i-1,j,k) ; if (G%mask2dT(i-1,j) < 0.5) h\_im1 = h\_in(i,j)}
1931     \textcolor{comment}{! h\_ip1 = h\_in(i+1,j,k) ; if (G%mask2dT(i+1,j) < 0.5) h\_ip1 = h\_in(i,j)}
1932       h\_im1 = g%mask2dT(i-1,j) * h\_in(i-1,j) + (1.0-g%mask2dT(i-1,j)) * h\_in(i,j)
1933       h\_ip1 = g%mask2dT(i+1,j) * h\_in(i+1,j) + (1.0-g%mask2dT(i+1,j)) * h\_in(i,j)
1934       \textcolor{comment}{! Left/right values following Eq. B2 in Lin 1994, MWR (132)}
1935       h\_l(i,j) = 0.5*( h\_im1 + h\_in(i,j) ) + onesixth*( slp(i-1,j) - slp(i,j) )
1936       h\_r(i,j) = 0.5*( h\_ip1 + h\_in(i,j) ) + onesixth*( slp(i,j) - slp(i+1,j) )
1937 \textcolor{keywordflow}{    enddo} ;\textcolor{keywordflow}{ enddo}
1938 \textcolor{keywordflow}{  endif}
1939 
1940   \textcolor{keyword}{call }ppm\_limit\_pos(h\_in, h\_l, h\_r, 0.0, g, isl, iel, jsl, jel)
\end{DoxyCode}
\mbox{\Hypertarget{namespacemom__internal__tides_a6c3dc6d74dfd6e5b13d5f710899be278}\label{namespacemom__internal__tides_a6c3dc6d74dfd6e5b13d5f710899be278}} 
\index{mom\+\_\+internal\+\_\+tides@{mom\+\_\+internal\+\_\+tides}!ppm\+\_\+reconstruction\+\_\+y@{ppm\+\_\+reconstruction\+\_\+y}}
\index{ppm\+\_\+reconstruction\+\_\+y@{ppm\+\_\+reconstruction\+\_\+y}!mom\+\_\+internal\+\_\+tides@{mom\+\_\+internal\+\_\+tides}}
\subsubsection{\texorpdfstring{ppm\+\_\+reconstruction\+\_\+y()}{ppm\_reconstruction\_y()}}
{\footnotesize\ttfamily subroutine mom\+\_\+internal\+\_\+tides\+::ppm\+\_\+reconstruction\+\_\+y (\begin{DoxyParamCaption}\item[{real, dimension(szi\+\_\+(g),szj\+\_\+(g)), intent(in)}]{h\+\_\+in,  }\item[{real, dimension(szi\+\_\+(g),szj\+\_\+(g)), intent(out)}]{h\+\_\+l,  }\item[{real, dimension(szi\+\_\+(g),szj\+\_\+(g)), intent(out)}]{h\+\_\+r,  }\item[{type(ocean\+\_\+grid\+\_\+type), intent(in)}]{G,  }\item[{type(\hyperlink{structmom__internal__tides_1_1loop__bounds__type}{loop\+\_\+bounds\+\_\+type}), intent(in)}]{LB,  }\item[{logical, intent(in), optional}]{simple\+\_\+2nd }\end{DoxyParamCaption})\hspace{0.3cm}{\ttfamily [private]}}



Calculates left/right edge valus for P\+PM reconstruction in y-\/direction. 


\begin{DoxyParams}[1]{Parameters}
\mbox{\tt in}  & {\em g} & The ocean\textquotesingle{}s grid structure.\\
\hline
\mbox{\tt in}  & {\em h\+\_\+in} & Energy density in a sector (2D).\\
\hline
\mbox{\tt out}  & {\em h\+\_\+l} & Left edge value of reconstruction (2D).\\
\hline
\mbox{\tt out}  & {\em h\+\_\+r} & Right edge value of reconstruction (2D).\\
\hline
\mbox{\tt in}  & {\em lb} & A structure with the active loop bounds.\\
\hline
\mbox{\tt in}  & {\em simple\+\_\+2nd} & If true, use the arithmetic mean energy densities as default edge values for a simple 2nd order scheme. \\
\hline
\end{DoxyParams}


Definition at line 1945 of file M\+O\+M\+\_\+internal\+\_\+tides.\+F90.


\begin{DoxyCode}
1945   \textcolor{keywordtype}{type}(ocean\_grid\_type),            \textcolor{keywordtype}{intent(in)}  :: g\textcolor{comment}{    !< The ocean's grid structure.}
1946   \textcolor{keywordtype}{real}, \textcolor{keywordtype}{dimension(SZI\_(G),SZJ\_(G))}, \textcolor{keywordtype}{intent(in)}  :: h\_in\textcolor{comment}{ !< Energy density in a sector (2D).}
1947   \textcolor{keywordtype}{real}, \textcolor{keywordtype}{dimension(SZI\_(G),SZJ\_(G))}, \textcolor{keywordtype}{intent(out)} :: h\_l\textcolor{comment}{  !< Left edge value of reconstruction (2D).}
1948   \textcolor{keywordtype}{real}, \textcolor{keywordtype}{dimension(SZI\_(G),SZJ\_(G))}, \textcolor{keywordtype}{intent(out)} :: h\_r\textcolor{comment}{  !< Right edge value of reconstruction (2D).}
1949   \textcolor{keywordtype}{type}(loop\_bounds\_type),           \textcolor{keywordtype}{intent(in)}  :: lb\textcolor{comment}{   !< A structure with the active loop bounds.}
1950   \textcolor{keywordtype}{logical}, \textcolor{keywordtype}{optional},                \textcolor{keywordtype}{intent(in)}  :: simple\_2nd\textcolor{comment}{ !< If true, use the arithmetic mean}
1951 \textcolor{comment}{                                                        !! energy densities as default edge values}
1952 \textcolor{comment}{                                                        !! for a simple 2nd order scheme.}
1953   \textcolor{comment}{! Local variables}
1954   \textcolor{keywordtype}{real}, \textcolor{keywordtype}{dimension(SZI\_(G),SZJ\_(G))}  :: slp \textcolor{comment}{! The slopes.}
1955   \textcolor{keywordtype}{real}, \textcolor{keywordtype}{parameter} :: onesixth = 1./6.
1956   \textcolor{keywordtype}{real} :: h\_jp1, h\_jm1
1957   \textcolor{keywordtype}{real} :: dmx, dmn
1958   \textcolor{keywordtype}{logical} :: use\_2nd
1959   \textcolor{keywordtype}{character(len=256)} :: mesg  \textcolor{comment}{! The text of an error message}
1960   \textcolor{keywordtype}{integer} :: i, j, isl, iel, jsl, jel, stencil
1961 
1962   use\_2nd = .false. ; \textcolor{keywordflow}{if} (\textcolor{keyword}{present}(simple\_2nd)) use\_2nd = simple\_2nd
1963   isl = lb%ish ; iel = lb%ieh ; jsl = lb%jsh-1 ; jel = lb%jeh+1
1964 
1965   \textcolor{comment}{! This is the stencil of the reconstruction, not the scheme overall.}
1966   stencil = 2 ; \textcolor{keywordflow}{if} (use\_2nd) stencil = 1
1967 
1968   \textcolor{keywordflow}{if} ((isl < g%isd) .or. (iel > g%ied)) \textcolor{keywordflow}{then}
1969     \textcolor{keyword}{write}(mesg,\textcolor{stringliteral}{'("In MOM\_internal\_tides, PPM\_reconstruction\_y called with a ", &}
1970 \textcolor{stringliteral}{}\textcolor{stringliteral}{               & "x-halo that needs to be increased by ",i2,".")'}) &
1971                max(g%isd-isl,iel-g%ied)
1972     \textcolor{keyword}{call }mom\_error(fatal,mesg)
1973 \textcolor{keywordflow}{  endif}
1974   \textcolor{keywordflow}{if} ((jsl-stencil < g%jsd) .or. (jel+stencil > g%jed)) \textcolor{keywordflow}{then}
1975     \textcolor{keyword}{write}(mesg,\textcolor{stringliteral}{'("In MOM\_internal\_tides, PPM\_reconstruction\_y called with a ", &}
1976 \textcolor{stringliteral}{}\textcolor{stringliteral}{                 & "y-halo that needs to be increased by ",i2,".")'}) &
1977                  stencil + max(g%jsd-jsl,jel-g%jed)
1978     \textcolor{keyword}{call }mom\_error(fatal,mesg)
1979 \textcolor{keywordflow}{  endif}
1980 
1981   \textcolor{keywordflow}{if} (use\_2nd) \textcolor{keywordflow}{then}
1982     \textcolor{keywordflow}{do} j=jsl,jel ; \textcolor{keywordflow}{do} i=isl,iel
1983       h\_jm1 = g%mask2dT(i,j-1) * h\_in(i,j-1) + (1.0-g%mask2dT(i,j-1)) * h\_in(i,j)
1984       h\_jp1 = g%mask2dT(i,j+1) * h\_in(i,j+1) + (1.0-g%mask2dT(i,j+1)) * h\_in(i,j)
1985       h\_l(i,j) = 0.5*( h\_jm1 + h\_in(i,j) )
1986       h\_r(i,j) = 0.5*( h\_jp1 + h\_in(i,j) )
1987 \textcolor{keywordflow}{    enddo} ;\textcolor{keywordflow}{ enddo}
1988   \textcolor{keywordflow}{else}
1989     \textcolor{keywordflow}{do} j=jsl-1,jel+1 ; \textcolor{keywordflow}{do} i=isl,iel
1990       \textcolor{keywordflow}{if} ((g%mask2dT(i,j-1) * g%mask2dT(i,j) * g%mask2dT(i,j+1)) == 0.0) \textcolor{keywordflow}{then}
1991         slp(i,j) = 0.0
1992       \textcolor{keywordflow}{else}
1993         \textcolor{comment}{! This uses a simple 2nd order slope.}
1994         slp(i,j) = 0.5 * (h\_in(i,j+1) - h\_in(i,j-1))
1995         \textcolor{comment}{! Monotonic constraint, see Eq. B2 in Lin 1994, MWR (132)}
1996         dmx = max(h\_in(i,j+1), h\_in(i,j-1), h\_in(i,j)) - h\_in(i,j)
1997         dmn = h\_in(i,j) - min(h\_in(i,j+1), h\_in(i,j-1), h\_in(i,j))
1998         slp(i,j) = sign(1.,slp(i,j)) * min(abs(slp(i,j)), 2. * min(dmx, dmn))
1999                 \textcolor{comment}{! * (G%mask2dT(i,j-1) * G%mask2dT(i,j) * G%mask2dT(i,j+1))}
2000 \textcolor{keywordflow}{      endif}
2001 \textcolor{keywordflow}{    enddo} ;\textcolor{keywordflow}{ enddo}
2002 
2003     \textcolor{keywordflow}{do} j=jsl,jel ; \textcolor{keywordflow}{do} i=isl,iel
2004       \textcolor{comment}{! Neighboring values should take into account any boundaries.  The 3}
2005       \textcolor{comment}{! following sets of expressions are equivalent.}
2006       h\_jm1 = g%mask2dT(i,j-1) * h\_in(i,j-1) + (1.0-g%mask2dT(i,j-1)) * h\_in(i,j)
2007       h\_jp1 = g%mask2dT(i,j+1) * h\_in(i,j+1) + (1.0-g%mask2dT(i,j+1)) * h\_in(i,j)
2008       \textcolor{comment}{! Left/right values following Eq. B2 in Lin 1994, MWR (132)}
2009       h\_l(i,j) = 0.5*( h\_jm1 + h\_in(i,j) ) + onesixth*( slp(i,j-1) - slp(i,j) )
2010       h\_r(i,j) = 0.5*( h\_jp1 + h\_in(i,j) ) + onesixth*( slp(i,j) - slp(i,j+1) )
2011 \textcolor{keywordflow}{    enddo} ;\textcolor{keywordflow}{ enddo}
2012 \textcolor{keywordflow}{  endif}
2013 
2014   \textcolor{keyword}{call }ppm\_limit\_pos(h\_in, h\_l, h\_r, 0.0, g, isl, iel, jsl, jel)
\end{DoxyCode}
\mbox{\Hypertarget{namespacemom__internal__tides_af70118539fe63af49c203de9bdfafe8a}\label{namespacemom__internal__tides_af70118539fe63af49c203de9bdfafe8a}} 
\index{mom\+\_\+internal\+\_\+tides@{mom\+\_\+internal\+\_\+tides}!propagate@{propagate}}
\index{propagate@{propagate}!mom\+\_\+internal\+\_\+tides@{mom\+\_\+internal\+\_\+tides}}
\subsubsection{\texorpdfstring{propagate()}{propagate()}}
{\footnotesize\ttfamily subroutine mom\+\_\+internal\+\_\+tides\+::propagate (\begin{DoxyParamCaption}\item[{real, dimension(g\%isd\+:g\%ied,g\%jsd\+:g\%jed,nangle), intent(inout)}]{En,  }\item[{real, dimension(g\%isd\+:g\%ied,g\%jsd\+:g\%jed), intent(in)}]{cn,  }\item[{real, intent(in)}]{freq,  }\item[{real, intent(in)}]{dt,  }\item[{type(ocean\+\_\+grid\+\_\+type), intent(inout)}]{G,  }\item[{type(unit\+\_\+scale\+\_\+type), intent(in)}]{US,  }\item[{type(\hyperlink{structmom__internal__tides_1_1int__tide__cs}{int\+\_\+tide\+\_\+cs}), pointer}]{CS,  }\item[{integer, intent(in)}]{N\+Angle }\end{DoxyParamCaption})\hspace{0.3cm}{\ttfamily [private]}}



Propagates internal waves at a single frequency. 


\begin{DoxyParams}[1]{Parameters}
\mbox{\tt in,out}  & {\em g} & The ocean\textquotesingle{}s grid structure.\\
\hline
\mbox{\tt in}  & {\em nangle} & The number of wave orientations in the discretized wave energy spectrum.\\
\hline
\mbox{\tt in,out}  & {\em en} & The internal gravity wave energy density as a\\
\hline
\mbox{\tt in}  & {\em cn} & Baroclinic mode speed \mbox{[}L T-\/1 $\sim$$>$ m s-\/1\mbox{]}.\\
\hline
\mbox{\tt in}  & {\em freq} & Wave frequency \mbox{[}T-\/1 $\sim$$>$ s-\/1\mbox{]}.\\
\hline
\mbox{\tt in}  & {\em dt} & Time step \mbox{[}T $\sim$$>$ s\mbox{]}.\\
\hline
\mbox{\tt in}  & {\em us} & A dimensional unit scaling type\\
\hline
 & {\em cs} & The control structure returned by a previous call to int\+\_\+tide\+\_\+init. \\
\hline
\end{DoxyParams}


Definition at line 967 of file M\+O\+M\+\_\+internal\+\_\+tides.\+F90.


\begin{DoxyCode}
967   \textcolor{keywordtype}{type}(ocean\_grid\_type), \textcolor{keywordtype}{intent(inout)} :: g\textcolor{comment}{    !< The ocean's grid structure.}
968   \textcolor{keywordtype}{integer},               \textcolor{keywordtype}{intent(in)}    :: nangle\textcolor{comment}{ !< The number of wave orientations in the}
969 \textcolor{comment}{                                               !! discretized wave energy spectrum.}
970   \textcolor{keywordtype}{real}, \textcolor{keywordtype}{dimension(G%isd:G%ied,G%jsd:G%jed,NAngle)}, &
971                          \textcolor{keywordtype}{intent(inout)} :: en\textcolor{comment}{   !< The internal gravity wave energy density as a}
972 \textcolor{comment}{                                               !! function of space and angular resolution,}
973 \textcolor{comment}{                                               !! [R Z3 T-2 ~> J m-2].}
974   \textcolor{keywordtype}{real}, \textcolor{keywordtype}{dimension(G%isd:G%ied,G%jsd:G%jed)},        &
975                          \textcolor{keywordtype}{intent(in)}    :: cn\textcolor{comment}{   !< Baroclinic mode speed [L T-1 ~> m s-1].}
976   \textcolor{keywordtype}{real},                  \textcolor{keywordtype}{intent(in)}    :: freq\textcolor{comment}{ !< Wave frequency [T-1 ~> s-1].}
977   \textcolor{keywordtype}{real},                  \textcolor{keywordtype}{intent(in)}    :: dt\textcolor{comment}{   !< Time step [T ~> s].}
978   \textcolor{keywordtype}{type}(unit\_scale\_type), \textcolor{keywordtype}{intent(in)}    :: us\textcolor{comment}{   !< A dimensional unit scaling type}
979   \textcolor{keywordtype}{type}(int\_tide\_cs),     \textcolor{keywordtype}{pointer}       :: cs\textcolor{comment}{   !< The control structure returned by a}
980 \textcolor{comment}{                                               !! previous call to int\_tide\_init.}
981   \textcolor{comment}{! Local variables}
982   \textcolor{keywordtype}{real}, \textcolor{keywordtype}{dimension(G%IsdB:G%IedB,G%JsdB:G%JedB)} :: &
983     speed  \textcolor{comment}{! The magnitude of the group velocity at the q points for corner adv [L T-1 ~> m s-1].}
984   \textcolor{keywordtype}{integer}, \textcolor{keywordtype}{parameter} :: stencil = 2
985   \textcolor{keywordtype}{real}, \textcolor{keywordtype}{dimension(SZIB\_(G),SZJ\_(G))} :: &
986     speed\_x  \textcolor{comment}{! The magnitude of the group velocity at the Cu points [L T-1 ~> m s-1].}
987   \textcolor{keywordtype}{real}, \textcolor{keywordtype}{dimension(SZI\_(G),SZJB\_(G))} :: &
988     speed\_y  \textcolor{comment}{! The magnitude of the group velocity at the Cv points [L T-1 ~> m s-1].}
989   \textcolor{keywordtype}{real}, \textcolor{keywordtype}{dimension(0:NAngle)} :: &
990     cos\_angle, sin\_angle
991   \textcolor{keywordtype}{real}, \textcolor{keywordtype}{dimension(NAngle)} :: &
992     cgx\_av, cgy\_av, dcgx, dcgy
993   \textcolor{keywordtype}{real} :: f2   \textcolor{comment}{! The squared Coriolis parameter [T-2 ~> s-2].}
994   \textcolor{keywordtype}{real} :: angle\_size, i\_angle\_size, angle
995   \textcolor{keywordtype}{real} :: ifreq \textcolor{comment}{! The inverse of the frequency [T ~> s]}
996   \textcolor{keywordtype}{real} :: freq2 \textcolor{comment}{! The frequency squared [T-2 ~> s-2]}
997   \textcolor{keywordtype}{type}(loop\_bounds\_type) :: lb
998   \textcolor{keywordtype}{integer} :: is, ie, js, je, asd, aed, na
999   \textcolor{keywordtype}{integer} :: ish, ieh, jsh, jeh
1000   \textcolor{keywordtype}{integer} :: i, j, a
1001 
1002   is = g%isc ; ie = g%iec ; js = g%jsc ; je = g%jec ; na = \textcolor{keyword}{size}(en,3)
1003   asd = 1-stencil ; aed = nangle+stencil
1004 
1005   ifreq = 1.0 / freq
1006   freq2 = freq**2
1007 
1008   \textcolor{comment}{! Define loop bounds: Need extensions on j-loop so propagate\_y}
1009   \textcolor{comment}{! (done after propagate\_x) will have updated values in the halo}
1010   \textcolor{comment}{! for correct PPM reconstruction. Use if no teleporting and}
1011   \textcolor{comment}{! no pass\_var between propagate\_x and propagate\_y.}
1012   \textcolor{comment}{!jsh = js-3 ; jeh = je+3 ; ish = is ; ieh = ie}
1013 
1014   \textcolor{comment}{! Define loop bounds: Need 1-pt extensions on loops because}
1015   \textcolor{comment}{! teleporting eats up a halo point. Use if teleporting.}
1016   \textcolor{comment}{! Also requires pass\_var before propagate\_y.}
1017   jsh = js-1 ; jeh = je+1 ; ish = is-1 ; ieh = ie+1
1018 
1019   angle\_size = (8.0*atan(1.0)) / \textcolor{keywordtype}{real}(nangle)
1020   i\_angle\_size = 1.0 / angle\_size
1021 
1022   \textcolor{keywordflow}{if} (cs%corner\_adv) \textcolor{keywordflow}{then}
1023     \textcolor{comment}{! IMPLEMENT CORNER ADVECTION IN HORIZONTAL--------------------}
1024     \textcolor{comment}{! FIND AVERAGE GROUP VELOCITY (SPEED) AT CELL CORNERS}
1025     \textcolor{comment}{! NOTE: THIS HAS NOT BE ADAPTED FOR REFLECTION YET (BDM)!!}
1026     \textcolor{comment}{! Fix indexing here later}
1027     speed(:,:) = 0.0
1028     \textcolor{keywordflow}{do} j=jsh-1,jeh ; \textcolor{keywordflow}{do} i=ish-1,ieh
1029       f2 = g%CoriolisBu(i,j)**2
1030       speed(i,j) = 0.25*(cn(i,j) + cn(i+1,j) + cn(i+1,j+1) + cn(i,j+1)) * &
1031                      sqrt(max(freq2 - f2, 0.0)) * ifreq
1032 \textcolor{keywordflow}{    enddo} ;\textcolor{keywordflow}{ enddo}
1033     \textcolor{keywordflow}{do} a=1,na
1034       \textcolor{comment}{! Apply the propagation WITH CORNER ADVECTION/FINITE VOLUME APPROACH.}
1035       lb%jsh = js ; lb%jeh = je ; lb%ish = is ; lb%ieh = ie
1036       \textcolor{keyword}{call }propagate\_corner\_spread(en(:,:,a), a, nangle, speed, dt, g, cs, lb)
1037 \textcolor{keywordflow}{    enddo} \textcolor{comment}{! a-loop}
1038   \textcolor{keywordflow}{else}
1039     \textcolor{comment}{! IMPLEMENT PPM ADVECTION IN HORIZONTAL-----------------------}
1040     \textcolor{comment}{! These could be in the control structure, as they do not vary.}
1041     \textcolor{keywordflow}{do} a=0,na
1042       \textcolor{comment}{! These are the angles at the cell edges...}
1043       angle = (\textcolor{keywordtype}{real(A)} - 0.5) * angle\_size
1044       cos\_angle(a) = cos(angle) ; sin\_angle(a) = sin(angle)
1045 \textcolor{keywordflow}{    enddo}
1046 
1047     \textcolor{keywordflow}{do} a=1,na
1048       cgx\_av(a) = (sin\_angle(a) - sin\_angle(a-1)) * i\_angle\_size
1049       cgy\_av(a) = -(cos\_angle(a) - cos\_angle(a-1)) * i\_angle\_size
1050       dcgx(a) = sqrt(0.5 + 0.5*(sin\_angle(a)*cos\_angle(a) - &
1051                                 sin\_angle(a-1)*cos\_angle(a-1)) * i\_angle\_size - &
1052                      cgx\_av(a)**2)
1053       dcgy(a) = sqrt(0.5 - 0.5*(sin\_angle(a)*cos\_angle(a) - &
1054                                 sin\_angle(a-1)*cos\_angle(a-1)) * i\_angle\_size - &
1055                      cgy\_av(a)**2)
1056 \textcolor{keywordflow}{    enddo}
1057 
1058     \textcolor{keywordflow}{do} j=jsh,jeh ; \textcolor{keywordflow}{do} i=ish-1,ieh
1059       f2 = 0.5 * (g%CoriolisBu(i,j)**2 + g%CoriolisBu(i,j-1)**2)
1060       speed\_x(i,j) = 0.5*(cn(i,j) + cn(i+1,j)) * g%mask2dCu(i,j) * &
1061                      sqrt(max(freq2 - f2, 0.0)) * ifreq
1062 \textcolor{keywordflow}{    enddo} ;\textcolor{keywordflow}{ enddo}
1063     \textcolor{keywordflow}{do} j=jsh-1,jeh ; \textcolor{keywordflow}{do} i=ish,ieh
1064       f2 = 0.5 * (g%CoriolisBu(i,j)**2 + g%CoriolisBu(i-1,j)**2)
1065       speed\_y(i,j) = 0.5*(cn(i,j) + cn(i,j+1)) * g%mask2dCv(i,j) * &
1066                      sqrt(max(freq2 - f2, 0.0)) * ifreq
1067 \textcolor{keywordflow}{    enddo} ;\textcolor{keywordflow}{ enddo}
1068 
1069     \textcolor{comment}{! Apply propagation in x-direction (reflection included)}
1070     lb%jsh = jsh ; lb%jeh = jeh ; lb%ish = ish ; lb%ieh = ieh
1071     \textcolor{keyword}{call }propagate\_x(en, speed\_x, cgx\_av, dcgx, dt, g, us, cs%nAngle, cs, lb)
1072 
1073     \textcolor{comment}{! Check for energy conservation on computational domain (for debugging)}
1074     \textcolor{comment}{!call sum\_En(G, CS, En, 'post-propagate\_x')}
1075 
1076     \textcolor{comment}{! Update halos}
1077     \textcolor{keyword}{call }pass\_var(en, g%domain)
1078 
1079     \textcolor{comment}{! Apply propagation in y-direction (reflection included)}
1080     \textcolor{comment}{! LB%jsh = js ; LB%jeh = je ; LB%ish = is ; LB%ieh = ie ! Use if no teleport}
1081     lb%jsh = jsh ; lb%jeh = jeh ; lb%ish = ish ; lb%ieh = ieh
1082     \textcolor{keyword}{call }propagate\_y(en, speed\_y, cgy\_av, dcgy, dt, g, us, cs%nAngle, cs, lb)
1083 
1084     \textcolor{comment}{! Check for energy conservation on computational domain (for debugging)}
1085     \textcolor{comment}{!call sum\_En(G, CS, En, 'post-propagate\_y')}
1086 \textcolor{keywordflow}{  endif}
1087 
\end{DoxyCode}
\mbox{\Hypertarget{namespacemom__internal__tides_a66c9354cfdcde3d06a2ebe8775572d23}\label{namespacemom__internal__tides_a66c9354cfdcde3d06a2ebe8775572d23}} 
\index{mom\+\_\+internal\+\_\+tides@{mom\+\_\+internal\+\_\+tides}!propagate\+\_\+corner\+\_\+spread@{propagate\+\_\+corner\+\_\+spread}}
\index{propagate\+\_\+corner\+\_\+spread@{propagate\+\_\+corner\+\_\+spread}!mom\+\_\+internal\+\_\+tides@{mom\+\_\+internal\+\_\+tides}}
\subsubsection{\texorpdfstring{propagate\+\_\+corner\+\_\+spread()}{propagate\_corner\_spread()}}
{\footnotesize\ttfamily subroutine mom\+\_\+internal\+\_\+tides\+::propagate\+\_\+corner\+\_\+spread (\begin{DoxyParamCaption}\item[{real, dimension(g\%isd\+:g\%ied,g\%jsd\+:g\%jed), intent(inout)}]{En,  }\item[{integer, intent(in)}]{energized\+\_\+wedge,  }\item[{integer, intent(in)}]{N\+Angle,  }\item[{real, dimension(g\%isdb\+:g\%iedb,g\%jsd\+:g\%jed), intent(in)}]{speed,  }\item[{real, intent(in)}]{dt,  }\item[{type(ocean\+\_\+grid\+\_\+type), intent(in)}]{G,  }\item[{type(\hyperlink{structmom__internal__tides_1_1int__tide__cs}{int\+\_\+tide\+\_\+cs}), pointer}]{CS,  }\item[{type(\hyperlink{structmom__internal__tides_1_1loop__bounds__type}{loop\+\_\+bounds\+\_\+type}), intent(in)}]{LB }\end{DoxyParamCaption})\hspace{0.3cm}{\ttfamily [private]}}



This subroutine does first-\/order corner advection. It was written with the hopes of smoothing out the garden sprinkler effect, but is too numerically diffusive to be of much use as of yet. It is not yet compatible with reflection schemes (B\+DM). 


\begin{DoxyParams}[1]{Parameters}
\mbox{\tt in}  & {\em g} & The ocean\textquotesingle{}s grid structure.\\
\hline
\mbox{\tt in,out}  & {\em en} & The energy density integrated over an angular\\
\hline
\mbox{\tt in}  & {\em speed} & The magnitude of the group velocity at the cell\\
\hline
\mbox{\tt in}  & {\em energized\+\_\+wedge} & Index of current ray direction.\\
\hline
\mbox{\tt in}  & {\em nangle} & The number of wave orientations in the discretized wave energy spectrum.\\
\hline
\mbox{\tt in}  & {\em dt} & Time increment \mbox{[}T $\sim$$>$ s\mbox{]}.\\
\hline
 & {\em cs} & The control structure returned by a previous call to continuity\+\_\+\+P\+P\+M\+\_\+init.\\
\hline
\mbox{\tt in}  & {\em lb} & A structure with the active energy loop bounds. \\
\hline
\end{DoxyParams}


Definition at line 1094 of file M\+O\+M\+\_\+internal\+\_\+tides.\+F90.


\begin{DoxyCode}
1094   \textcolor{keywordtype}{type}(ocean\_grid\_type),  \textcolor{keywordtype}{intent(in)}    :: g\textcolor{comment}{     !< The ocean's grid structure.}
1095   \textcolor{keywordtype}{real}, \textcolor{keywordtype}{dimension(G%isd:G%ied,G%jsd:G%jed)},   &
1096                           \textcolor{keywordtype}{intent(inout)} :: en\textcolor{comment}{    !< The energy density integrated over an angular}
1097 \textcolor{comment}{                                                 !! band [R Z3 T-2 ~> J m-2].}
1098   \textcolor{keywordtype}{real}, \textcolor{keywordtype}{dimension(G%IsdB:G%IedB,G%Jsd:G%Jed)}, &
1099                           \textcolor{keywordtype}{intent(in)}    :: speed\textcolor{comment}{ !< The magnitude of the group velocity at the cell}
1100 \textcolor{comment}{                                                 !! corner points [L T-1 ~> m s-1].}
1101   \textcolor{keywordtype}{integer},                \textcolor{keywordtype}{intent(in)}    :: energized\_wedge\textcolor{comment}{ !< Index of current ray direction.}
1102   \textcolor{keywordtype}{integer},                \textcolor{keywordtype}{intent(in)}    :: nangle\textcolor{comment}{ !< The number of wave orientations in the}
1103 \textcolor{comment}{                                                 !! discretized wave energy spectrum.}
1104   \textcolor{keywordtype}{real},                   \textcolor{keywordtype}{intent(in)}    :: dt\textcolor{comment}{    !< Time increment [T ~> s].}
1105   \textcolor{keywordtype}{type}(int\_tide\_cs),      \textcolor{keywordtype}{pointer}       :: cs\textcolor{comment}{    !< The control structure returned by a previous}
1106 \textcolor{comment}{                                                 !! call to continuity\_PPM\_init.}
1107   \textcolor{keywordtype}{type}(loop\_bounds\_type), \textcolor{keywordtype}{intent(in)}    :: lb\textcolor{comment}{    !< A structure with the active energy loop bounds.}
1108   \textcolor{comment}{! Local variables}
1109   \textcolor{keywordtype}{integer} :: i, j, k, ish, ieh, jsh, jeh, m
1110   \textcolor{keywordtype}{real} :: twopi, angle\_size
1111   \textcolor{keywordtype}{real} :: energized\_angle \textcolor{comment}{! angle through center of current wedge}
1112   \textcolor{keywordtype}{real} :: theta \textcolor{comment}{! angle at edge of wedge}
1113   \textcolor{keywordtype}{real} :: nsubrays     \textcolor{comment}{! number of sub-rays for averaging}
1114                        \textcolor{comment}{! count includes the two rays that bound the current wedge,}
1115                        \textcolor{comment}{! i.e. those at -dtheta/2 and +dtheta/2 from energized angle}
1116   \textcolor{keywordtype}{real} :: i\_nsubwedges \textcolor{comment}{! inverse of number of sub-wedges}
1117   \textcolor{keywordtype}{real} :: cos\_thetadt, sin\_thetadt \textcolor{comment}{! cos(theta)*dt, sin(theta)*dt}
1118   \textcolor{keywordtype}{real} :: xne,xnw,xsw,xse,yne,ynw,ysw,yse \textcolor{comment}{! corner point coordinates of advected fluid parcel}
1119   \textcolor{keywordtype}{real} :: cfl\_xne,cfl\_xnw,cfl\_xsw,cfl\_xse,cfl\_yne,cfl\_ynw,cfl\_ysw,cfl\_yse,cfl\_max
1120   \textcolor{keywordtype}{real} :: xn,xs,xe,xw,yn,ys,ye,yw \textcolor{comment}{! intersection point coordinates of parcel edges and grid}
1121   \textcolor{keywordtype}{real} :: xcrn,ycrn \textcolor{comment}{! grid point contained within advected fluid parcel}
1122   \textcolor{keywordtype}{real} :: xg,yg \textcolor{comment}{! grid point of interest}
1123   \textcolor{keywordtype}{real} :: slopen,slopew,slopes,slopee, bn,bw,bs,be \textcolor{comment}{! parameters defining parcel sides}
1124   \textcolor{keywordtype}{real} :: ane,an,anw,aw,asw,as,ase,ae,ac \textcolor{comment}{! sub-areas of advected parcel}
1125   \textcolor{keywordtype}{real} :: a\_total \textcolor{comment}{! total area of advected parcel}
1126   \textcolor{keywordtype}{real} :: a1,a2,a3,a4 \textcolor{comment}{! areas used in calculating polygon areas (sub-areas) of advected parcel}
1127   \textcolor{keywordtype}{real}, \textcolor{keywordtype}{dimension(G%IsdB:G%IedB,G%Jsd:G%Jed)} :: x,y \textcolor{comment}{! coordinates of cell corners}
1128   \textcolor{keywordtype}{real}, \textcolor{keywordtype}{dimension(G%IsdB:G%IedB,G%Jsd:G%Jed)} :: idx,idy \textcolor{comment}{! inverse of dx,dy at cell corners}
1129   \textcolor{keywordtype}{real}, \textcolor{keywordtype}{dimension(G%IsdB:G%IedB,G%Jsd:G%Jed)} :: dx,dy \textcolor{comment}{! dx,dy at cell corners}
1130   \textcolor{keywordtype}{real}, \textcolor{keywordtype}{dimension(2)} :: e\_new \textcolor{comment}{! Energy in cell after advection for subray [R Z3 T-2 ~> J m-2]; set size}
1131                               \textcolor{comment}{! here to define Nsubrays - this should be made an input option later!}
1132 
1133   ish = lb%ish ; ieh = lb%ieh ; jsh = lb%jsh ; jeh = lb%jeh
1134   twopi = (8.0*atan(1.0))
1135   nsubrays = \textcolor{keywordtype}{real}(size(e\_new))
1136   i\_nsubwedges = 1./(nsubrays - 1)
1137 
1138   angle\_size = twopi / \textcolor{keywordtype}{real}(nangle)
1139   energized\_angle = angle\_size * \textcolor{keywordtype}{real(energized\_wedge - 1)} \textcolor{comment}{! for a=1 aligned with x-axis}
1140   \textcolor{comment}{!energized\_angle = Angle\_size * real(energized\_wedge - 1) + 2.0*Angle\_size !}
1141   \textcolor{comment}{!energized\_angle = Angle\_size * real(energized\_wedge - 1) + 0.5*Angle\_size !}
1142   \textcolor{keywordflow}{do} j=jsh-1,jeh ; \textcolor{keywordflow}{do} i=ish-1,ieh
1143     \textcolor{comment}{! This will only work for a Cartesian grid for which G%geoLonBu is in the same units has dx.}
1144     \textcolor{comment}{! This needs to be extensively revised to work for a general grid.}
1145     x(i,j) = g%US%m\_to\_L*g%geoLonBu(i,j)
1146     y(i,j) = g%US%m\_to\_L*g%geoLatBu(i,j)
1147     idx(i,j) = g%IdxBu(i,j) ; dx(i,j) = g%dxBu(i,j)
1148     idy(i,j) = g%IdyBu(i,j) ; dy(i,j) = g%dyBu(i,j)
1149 \textcolor{keywordflow}{  enddo} ;\textcolor{keywordflow}{ enddo}
1150 
1151   \textcolor{keywordflow}{do} j=jsh,jeh ; \textcolor{keywordflow}{do} i=ish,ieh
1152     \textcolor{keywordflow}{do} m=1,int(nsubrays)
1153       theta = energized\_angle - 0.5*angle\_size + \textcolor{keywordtype}{real}(m - 1)*angle\_size*i\_nsubwedges
1154       \textcolor{keywordflow}{if} (theta < 0.0) \textcolor{keywordflow}{then}
1155         theta = theta + twopi
1156       \textcolor{keywordflow}{elseif} (theta > twopi) \textcolor{keywordflow}{then}
1157         theta = theta - twopi
1158 \textcolor{keywordflow}{      endif}
1159       cos\_thetadt = cos(theta)*dt
1160       sin\_thetadt = sin(theta)*dt
1161 
1162       \textcolor{comment}{! corner point coordinates of advected fluid parcel ----------}
1163       xg = x(i,j); yg = y(i,j)
1164       xne = xg - speed(i,j)*cos\_thetadt
1165       yne = yg - speed(i,j)*sin\_thetadt
1166       cfl\_xne = (xg-xne)*idx(i,j)
1167       cfl\_yne = (yg-yne)*idy(i,j)
1168 
1169       xg = x(i-1,j); yg = y(i-1,j)
1170       xnw = xg - speed(i-1,j)*cos\_thetadt
1171       ynw = yg - speed(i-1,j)*sin\_thetadt
1172       cfl\_xnw = (xg-xnw)*idx(i-1,j)
1173       cfl\_ynw = (yg-ynw)*idy(i-1,j)
1174 
1175       xg = x(i-1,j-1); yg = y(i-1,j-1)
1176       xsw = xg - speed(i-1,j-1)*cos\_thetadt
1177       ysw = yg - speed(i-1,j-1)*sin\_thetadt
1178       cfl\_xsw = (xg-xsw)*idx(i-1,j-1)
1179       cfl\_ysw = (yg-ysw)*idy(i-1,j-1)
1180 
1181       xg = x(i,j-1); yg = y(i,j-1)
1182       xse = xg - speed(i,j-1)*cos\_thetadt
1183       yse = yg - speed(i,j-1)*sin\_thetadt
1184       cfl\_xse = (xg-xse)*idx(i,j-1)
1185       cfl\_yse = (yg-yse)*idy(i,j-1)
1186 
1187       cfl\_max = max(abs(cfl\_xne),abs(cfl\_xnw),abs(cfl\_xsw), &
1188                     abs(cfl\_xse),abs(cfl\_yne),abs(cfl\_ynw), &
1189                     abs(cfl\_ysw),abs(cfl\_yse))
1190       \textcolor{keywordflow}{if} (cfl\_max > 1.0) \textcolor{keywordflow}{then}
1191         \textcolor{keyword}{call }mom\_error(warning, \textcolor{stringliteral}{"propagate\_corner\_spread: CFL exceeds 1."}, .true.)
1192 \textcolor{keywordflow}{      endif}
1193 
1194       \textcolor{comment}{! intersection point coordinates of parcel edges and cell edges ---}
1195       \textcolor{keywordflow}{if} (0.0 <= theta .and. theta < 0.25*twopi) \textcolor{keywordflow}{then}
1196           xn = x(i-1,j-1)
1197           yw = y(i-1,j-1)
1198       \textcolor{keywordflow}{elseif} (0.25*twopi <= theta .and. theta < 0.5*twopi) \textcolor{keywordflow}{then}
1199           xn = x(i,j-1)
1200           yw = y(i,j-1)
1201       \textcolor{keywordflow}{elseif} (0.5*twopi <= theta .and. theta < 0.75*twopi) \textcolor{keywordflow}{then}
1202           xn = x(i,j)
1203           yw = y(i,j)
1204       \textcolor{keywordflow}{elseif} (0.75*twopi <= theta .and. theta <= 1.00*twopi) \textcolor{keywordflow}{then}
1205           xn = x(i-1,j)
1206           yw = y(i-1,j)
1207 \textcolor{keywordflow}{      endif}
1208       xs = xn
1209       ye = yw
1210 
1211       \textcolor{comment}{! north intersection}
1212       slopen = (yne - ynw)/(xne - xnw)
1213       bn = -slopen*xne + yne
1214       yn = slopen*xn + bn
1215       \textcolor{comment}{! west intersection}
1216       \textcolor{keywordflow}{if} (xnw == xsw) \textcolor{keywordflow}{then}
1217         xw = xnw
1218       \textcolor{keywordflow}{else}
1219         slopew = (ynw - ysw)/(xnw - xsw)
1220         bw = -slopew*xnw + ynw
1221         xw = (yw - bw)/slopew
1222 \textcolor{keywordflow}{      endif}
1223       \textcolor{comment}{! south intersection}
1224       slopes = (ysw - yse)/(xsw - xse)
1225       bs = -slopes*xsw + ysw
1226       ys = slopes*xs + bs
1227       \textcolor{comment}{! east intersection}
1228       \textcolor{keywordflow}{if} (xne == xse) \textcolor{keywordflow}{then}
1229         xe = xne
1230       \textcolor{keywordflow}{else}
1231         slopee = (yse - yne)/(xse - xne)
1232         be = -slopee*xse + yse
1233         xe = (ye - be)/slopee
1234 \textcolor{keywordflow}{      endif}
1235 
1236       \textcolor{comment}{! areas --------------------------------------------}
1237       ane = 0.0; an = 0.0; anw = 0.0; \textcolor{comment}{! initialize areas}
1238       aw = 0.0; asw = 0.0; as = 0.0; \textcolor{comment}{! initialize areas}
1239       ase = 0.0; ae = 0.0; ac = 0.0; \textcolor{comment}{! initialize areas}
1240       \textcolor{keywordflow}{if} (0.0 <= theta .and. theta < 0.25*twopi) \textcolor{keywordflow}{then}
1241           xcrn = x(i-1,j-1); ycrn = y(i-1,j-1)
1242           \textcolor{comment}{! west area}
1243           a1 = (yn - ycrn)*(0.5*(xn + xcrn))
1244           a2 = (ycrn - yw)*(0.5*(xcrn + xw))
1245           a3 = (yw - ynw)*(0.5*(xw + xnw))
1246           a4 = (ynw - yn)*(0.5*(xnw + xn))
1247           aw = a1 + a2 + a3 + a4
1248           \textcolor{comment}{! southwest area}
1249           a1 = (ycrn - ys)*(0.5*(xcrn + xs))
1250           a2 = (ys - ysw)*(0.5*(xs + xsw))
1251           a3 = (ysw - yw)*(0.5*(xsw + xw))
1252           a4 = (yw - ycrn)*(0.5*(xw + xcrn))
1253           asw = a1 + a2 + a3 + a4
1254           \textcolor{comment}{! south area}
1255           a1 = (ye - yse)*(0.5*(xe + xse))
1256           a2 = (yse - ys)*(0.5*(xse + xs))
1257           a3 = (ys - ycrn)*(0.5*(xs + xcrn))
1258           a4 = (ycrn - ye)*(0.5*(xcrn + xe))
1259           as = a1 + a2 + a3 + a4
1260           \textcolor{comment}{! area within cell}
1261           a1 = (yne - ye)*(0.5*(xne + xe))
1262           a2 = (ye - ycrn)*(0.5*(xe + xcrn))
1263           a3 = (ycrn - yn)*(0.5*(xcrn + xn))
1264           a4 = (yn - yne)*(0.5*(xn + xne))
1265           ac = a1 + a2 + a3 + a4
1266       \textcolor{keywordflow}{elseif} (0.25*twopi <= theta .and. theta < 0.5*twopi) \textcolor{keywordflow}{then}
1267           xcrn = x(i,j-1); ycrn = y(i,j-1)
1268           \textcolor{comment}{! south area}
1269           a1 = (ycrn - ys)*(0.5*(xcrn + xs))
1270           a2 = (ys - ysw)*(0.5*(xs + xsw))
1271           a3 = (ysw - yw)*(0.5*(xsw + xw))
1272           a4 = (yw - ycrn)*(0.5*(xw + xcrn))
1273           as = a1 + a2 + a3 + a4
1274           \textcolor{comment}{! southeast area}
1275           a1 = (ye - yse)*(0.5*(xe + xse))
1276           a2 = (yse - ys)*(0.5*(xse + xs))
1277           a3 = (ys - ycrn)*(0.5*(xs + xcrn))
1278           a4 = (ycrn - ye)*(0.5*(xcrn + xe))
1279           ase = a1 + a2 + a3 + a4
1280           \textcolor{comment}{! east area}
1281           a1 = (yne - ye)*(0.5*(xne + xe))
1282           a2 = (ye - ycrn)*(0.5*(xe + xcrn))
1283           a3 = (ycrn - yn)*(0.5*(xcrn + xn))
1284           a4 = (yn - yne)*(0.5*(xn + xne))
1285           ae = a1 + a2 + a3 + a4
1286           \textcolor{comment}{! area within cell}
1287           a1 = (yn - ycrn)*(0.5*(xn + xcrn))
1288           a2 = (ycrn - yw)*(0.5*(xcrn + xw))
1289           a3 = (yw - ynw)*(0.5*(xw + xnw))
1290           a4 = (ynw - yn)*(0.5*(xnw + xn))
1291           ac = a1 + a2 + a3 + a4
1292       \textcolor{keywordflow}{elseif} (0.5*twopi <= theta .and. theta < 0.75*twopi) \textcolor{keywordflow}{then}
1293           xcrn = x(i,j); ycrn = y(i,j)
1294           \textcolor{comment}{! east area}
1295           a1 = (ye - yse)*(0.5*(xe + xse))
1296           a2 = (yse - ys)*(0.5*(xse + xs))
1297           a3 = (ys - ycrn)*(0.5*(xs + xcrn))
1298           a4 = (ycrn - ye)*(0.5*(xcrn + xe))
1299           ae = a1 + a2 + a3 + a4
1300           \textcolor{comment}{! northeast area}
1301           a1 = (yne - ye)*(0.5*(xne + xe))
1302           a2 = (ye - ycrn)*(0.5*(xe + xcrn))
1303           a3 = (ycrn - yn)*(0.5*(xcrn + xn))
1304           a4 = (yn - yne)*(0.5*(xn + xne))
1305           ane = a1 + a2 + a3 + a4
1306           \textcolor{comment}{! north area}
1307           a1 = (yn - ycrn)*(0.5*(xn + xcrn))
1308           a2 = (ycrn - yw)*(0.5*(xcrn + xw))
1309           a3 = (yw - ynw)*(0.5*(xw + xnw))
1310           a4 = (ynw - yn)*(0.5*(xnw + xn))
1311           an = a1 + a2 + a3 + a4
1312           \textcolor{comment}{! area within cell}
1313           a1 = (ycrn - ys)*(0.5*(xcrn + xs))
1314           a2 = (ys - ysw)*(0.5*(xs + xsw))
1315           a3 = (ysw - yw)*(0.5*(xsw + xw))
1316           a4 = (yw - ycrn)*(0.5*(xw + xcrn))
1317           ac = a1 + a2 + a3 + a4
1318       \textcolor{keywordflow}{elseif} (0.75*twopi <= theta .and. theta <= 1.00*twopi) \textcolor{keywordflow}{then}
1319           xcrn = x(i-1,j); ycrn = y(i-1,j)
1320           \textcolor{comment}{! north area}
1321           a1 = (yne - ye)*(0.5*(xne + xe))
1322           a2 = (ye - ycrn)*(0.5*(xe + xcrn))
1323           a3 = (ycrn - yn)*(0.5*(xcrn + xn))
1324           a4 = (yn - yne)*(0.5*(xn + xne))
1325           an = a1 + a2 + a3 + a4
1326           \textcolor{comment}{! northwest area}
1327           a1 = (yn - ycrn)*(0.5*(xn + xcrn))
1328           a2 = (ycrn - yw)*(0.5*(xcrn + xw))
1329           a3 = (yw - ynw)*(0.5*(xw + xnw))
1330           a4 = (ynw - yn)*(0.5*(xnw + xn))
1331           anw = a1 + a2 + a3 + a4
1332           \textcolor{comment}{! west area}
1333           a1 = (ycrn - ys)*(0.5*(xcrn + xs))
1334           a2 = (ys - ysw)*(0.5*(xs + xsw))
1335           a3 = (ysw - yw)*(0.5*(xsw + xw))
1336           a4 = (yw - ycrn)*(0.5*(xw + xcrn))
1337           aw = a1 + a2 + a3 + a4
1338           \textcolor{comment}{! area within cell}
1339           a1 = (ye - yse)*(0.5*(xe + xse))
1340           a2 = (yse - ys)*(0.5*(xse + xs))
1341           a3 = (ys - ycrn)*(0.5*(xs + xcrn))
1342           a4 = (ycrn - ye)*(0.5*(xcrn + xe))
1343           ac = a1 + a2 + a3 + a4
1344 \textcolor{keywordflow}{      endif}
1345 
1346       \textcolor{comment}{! energy weighting ----------------------------------------}
1347       a\_total = ane + an + anw + aw + asw + as + ase + ae + ac
1348       e\_new(m) = (ane*en(i+1,j+1) + an*en(i,j+1) + anw*en(i-1,j+1) + &
1349                   aw*en(i-1,j) + asw*en(i-1,j-1) + as*en(i,j-1) + &
1350                   ase*en(i+1,j-1) + ae*en(i+1,j) + ac*en(i,j)) / (dx(i,j)*dy(i,j))
1351 \textcolor{keywordflow}{    enddo} \textcolor{comment}{! m-loop}
1352     \textcolor{comment}{! update energy in cell}
1353     en(i,j) = sum(e\_new)/nsubrays
1354 \textcolor{keywordflow}{  enddo} ;\textcolor{keywordflow}{ enddo}
\end{DoxyCode}
\mbox{\Hypertarget{namespacemom__internal__tides_aeeeea20ff7fe971846b7539d377f4389}\label{namespacemom__internal__tides_aeeeea20ff7fe971846b7539d377f4389}} 
\index{mom\+\_\+internal\+\_\+tides@{mom\+\_\+internal\+\_\+tides}!propagate\+\_\+int\+\_\+tide@{propagate\+\_\+int\+\_\+tide}}
\index{propagate\+\_\+int\+\_\+tide@{propagate\+\_\+int\+\_\+tide}!mom\+\_\+internal\+\_\+tides@{mom\+\_\+internal\+\_\+tides}}
\subsubsection{\texorpdfstring{propagate\+\_\+int\+\_\+tide()}{propagate\_int\_tide()}}
{\footnotesize\ttfamily subroutine, public mom\+\_\+internal\+\_\+tides\+::propagate\+\_\+int\+\_\+tide (\begin{DoxyParamCaption}\item[{real, dimension(szi\+\_\+(g),szj\+\_\+(g),szk\+\_\+(g)), intent(in)}]{h,  }\item[{type(thermo\+\_\+var\+\_\+ptrs), intent(in)}]{tv,  }\item[{real, dimension(szi\+\_\+(g),szj\+\_\+(g),cs\%nmode), intent(in)}]{cn,  }\item[{real, dimension(szi\+\_\+(g),szj\+\_\+(g)), intent(in)}]{T\+K\+E\+\_\+itidal\+\_\+input,  }\item[{real, dimension(szi\+\_\+(g),szj\+\_\+(g)), intent(in)}]{vel\+\_\+bt\+Tide,  }\item[{real, dimension(szi\+\_\+(g),szj\+\_\+(g)), intent(in)}]{Nb,  }\item[{real, intent(in)}]{dt,  }\item[{type(ocean\+\_\+grid\+\_\+type), intent(inout)}]{G,  }\item[{type(verticalgrid\+\_\+type), intent(in)}]{GV,  }\item[{type(unit\+\_\+scale\+\_\+type), intent(in)}]{US,  }\item[{type(\hyperlink{structmom__internal__tides_1_1int__tide__cs}{int\+\_\+tide\+\_\+cs}), pointer}]{CS }\end{DoxyParamCaption})}



Calls subroutines in this file that are needed to refract, propagate, and dissipate energy density of the internal tide. 


\begin{DoxyParams}[1]{Parameters}
\mbox{\tt in,out}  & {\em g} & The ocean\textquotesingle{}s grid structure.\\
\hline
\mbox{\tt in}  & {\em gv} & The ocean\textquotesingle{}s vertical grid structure.\\
\hline
\mbox{\tt in}  & {\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 tv} & Pointer to thermodynamic variables (needed for wave structure).\\
\hline
\mbox{\tt in}  & {\em tke\+\_\+itidal\+\_\+input} & The energy input to the internal waves \mbox{[}R Z3 T-\/3 $\sim$$>$ W m-\/2\mbox{]}.\\
\hline
\mbox{\tt in}  & {\em vel\+\_\+bttide} & Barotropic velocity read from file \mbox{[}L T-\/1 $\sim$$>$ m s-\/1\mbox{]}.\\
\hline
\mbox{\tt in}  & {\em nb} & Near-\/bottom buoyancy frequency \mbox{[}T-\/1 $\sim$$>$ s-\/1\mbox{]}.\\
\hline
\mbox{\tt in}  & {\em dt} & Length of time over which to advance the internal tides \mbox{[}T $\sim$$>$ s\mbox{]}.\\
\hline
 & {\em cs} & The control structure returned by a previous call to int\+\_\+tide\+\_\+init.\\
\hline
\mbox{\tt in}  & {\em cn} & The internal wave speeds of each \\
\hline
\end{DoxyParams}


Definition at line 154 of file M\+O\+M\+\_\+internal\+\_\+tides.\+F90.


\begin{DoxyCode}
154   \textcolor{keywordtype}{type}(ocean\_grid\_type),            \textcolor{keywordtype}{intent(inout)} :: g\textcolor{comment}{  !< The ocean's grid structure.}
155   \textcolor{keywordtype}{type}(verticalgrid\_type),          \textcolor{keywordtype}{intent(in)}    :: gv\textcolor{comment}{ !< The ocean's vertical grid structure.}
156   \textcolor{keywordtype}{type}(unit\_scale\_type),            \textcolor{keywordtype}{intent(in)}    :: us\textcolor{comment}{ !< A dimensional unit scaling type}
157   \textcolor{keywordtype}{real}, \textcolor{keywordtype}{dimension(SZI\_(G),SZJ\_(G),SZK\_(G))}, &
158                                     \textcolor{keywordtype}{intent(in)}    :: h\textcolor{comment}{  !< Layer thicknesses [H ~> m or kg m-2]}
159   \textcolor{keywordtype}{type}(thermo\_var\_ptrs),            \textcolor{keywordtype}{intent(in)}    :: tv\textcolor{comment}{ !< Pointer to thermodynamic variables}
160 \textcolor{comment}{                                                        !! (needed for wave structure).}
161   \textcolor{keywordtype}{real}, \textcolor{keywordtype}{dimension(SZI\_(G),SZJ\_(G))}, \textcolor{keywordtype}{intent(in)}    :: tke\_itidal\_input\textcolor{comment}{ !< The energy input to the}
162 \textcolor{comment}{                                                        !! internal waves [R Z3 T-3 ~> W m-2].}
163   \textcolor{keywordtype}{real}, \textcolor{keywordtype}{dimension(SZI\_(G),SZJ\_(G))}, \textcolor{keywordtype}{intent(in)}    :: vel\_bttide\textcolor{comment}{ !< Barotropic velocity read}
164 \textcolor{comment}{                                                        !! from file [L T-1 ~> m s-1].}
165   \textcolor{keywordtype}{real}, \textcolor{keywordtype}{dimension(SZI\_(G),SZJ\_(G))}, \textcolor{keywordtype}{intent(in)}    :: nb\textcolor{comment}{ !< Near-bottom buoyancy frequency [T-1 ~> s-1].}
166   \textcolor{keywordtype}{real},                             \textcolor{keywordtype}{intent(in)}    :: dt\textcolor{comment}{ !< Length of time over which to advance}
167 \textcolor{comment}{                                                        !! the internal tides [T ~> s].}
168   \textcolor{keywordtype}{type}(int\_tide\_cs),                \textcolor{keywordtype}{pointer}       :: cs\textcolor{comment}{ !< The control structure returned by a}
169 \textcolor{comment}{                                                        !! previous call to int\_tide\_init.}
170   \textcolor{keywordtype}{real}, \textcolor{keywordtype}{dimension(SZI\_(G),SZJ\_(G),CS%nMode)}, &
171                                     \textcolor{keywordtype}{intent(in)}    :: cn\textcolor{comment}{ !< The internal wave speeds of each}
172 \textcolor{comment}{                                                        !! mode [L T-1 ~> m s-1].}
173   \textcolor{comment}{! Local variables}
174   \textcolor{keywordtype}{real}, \textcolor{keywordtype}{dimension(SZI\_(G),SZJ\_(G),2)} :: &
175     test
176   \textcolor{keywordtype}{real}, \textcolor{keywordtype}{dimension(SZI\_(G),SZJ\_(G),CS%nFreq,CS%nMode)} :: &
177     tot\_en\_mode, & \textcolor{comment}{! energy summed over angles only [R Z3 T-2 ~> J m-2]}
178     ub, &          \textcolor{comment}{! near-bottom horizontal velocity of wave (modal) [L T-1 ~> m s-1]}
179     umax           \textcolor{comment}{! Maximum horizontal velocity of wave (modal) [L T-1 ~> m s-1]}
180   \textcolor{keywordtype}{real}, \textcolor{keywordtype}{dimension(SZI\_(G),SZJB\_(G))} :: &
181     flux\_heat\_y, &
182     flux\_prec\_y
183   \textcolor{keywordtype}{real}, \textcolor{keywordtype}{dimension(SZI\_(G),SZJ\_(G))} :: &
184     tot\_en, &      \textcolor{comment}{! energy summed over angles, modes, frequencies [R Z3 T-2 ~> J m-2]}
185     tot\_leak\_loss, tot\_quad\_loss, tot\_itidal\_loss, tot\_froude\_loss, tot\_allprocesses\_loss, &
186                    \textcolor{comment}{! energy loss rates summed over angle, freq, and mode [R Z3 T-3 ~> W m-2]}
187     drag\_scale, &  \textcolor{comment}{! bottom drag scale [T-1 ~> s-1]}
188     itidal\_loss\_mode, allprocesses\_loss\_mode
189                    \textcolor{comment}{! energy loss rates for a given mode and frequency (summed over angles) [R Z3 T-3 ~> W
       m-2]}
190   \textcolor{keywordtype}{real} :: frac\_per\_sector, f2, kmag2
191   \textcolor{keywordtype}{real} :: i\_d\_here \textcolor{comment}{! The inverse of the local depth [Z-1 ~> m-1]}
192   \textcolor{keywordtype}{real} :: i\_rho0  \textcolor{comment}{! The inverse fo the Boussinesq density [R-1 ~> m3 kg-1]}
193   \textcolor{keywordtype}{real} :: freq2 \textcolor{comment}{! The frequency squared [T-2 ~> s-2]}
194   \textcolor{keywordtype}{real} :: c\_phase \textcolor{comment}{! The phase speed [L T-1 ~> m s-1]}
195   \textcolor{keywordtype}{real} :: loss\_rate  \textcolor{comment}{! An energy loss rate [T-1 ~> s-1]}
196   \textcolor{keywordtype}{real} :: fr2\_max
197   \textcolor{keywordtype}{real} :: cn\_subro        \textcolor{comment}{! A tiny wave speed to prevent division by zero [L T-1 ~> m s-1]}
198   \textcolor{keywordtype}{real} :: en\_new, en\_check                           \textcolor{comment}{! Energies for debugging [R Z3 T-2 ~> J m-2]}
199   \textcolor{keywordtype}{real} :: en\_initial, delta\_e\_check                  \textcolor{comment}{! Energies for debugging [R Z3 T-2 ~> J m-2]}
200   \textcolor{keywordtype}{real} :: tke\_froude\_loss\_check, tke\_froude\_loss\_tot \textcolor{comment}{! Energy losses for debugging [R Z3 T-3 ~> W m-2]}
201   \textcolor{keywordtype}{character(len=160)} :: mesg  \textcolor{comment}{! The text of an error message}
202   \textcolor{keywordtype}{integer} :: a, m, fr, i, j, is, ie, js, je, isd, ied, jsd, jed, nangle, nzm
203   \textcolor{keywordtype}{integer} :: id\_g, jd\_g         \textcolor{comment}{! global (decomp-invar) indices (for debugging)}
204   \textcolor{keywordtype}{type}(group\_pass\_type), \textcolor{keywordtype}{save} :: pass\_test, pass\_en
205 
206   \textcolor{keywordflow}{if} (.not.\textcolor{keyword}{associated}(cs)) \textcolor{keywordflow}{return}
207   is = g%isc ; ie = g%iec ; js = g%jsc ; je = g%jec
208   isd = g%isd ; ied = g%ied ; jsd = g%jsd ; jed = g%jed ; nangle = cs%NAngle
209   i\_rho0 = 1.0 / gv%Rho0
210   cn\_subro = 1e-100*us%m\_s\_to\_L\_T  \textcolor{comment}{! The hard-coded value here might need to increase.}
211 
212   \textcolor{comment}{! Set the wave speeds for the modes, using cg(n) ~ cg(1)/n.**********************}
213   \textcolor{comment}{! This is wrong, of course, but it works reasonably in some cases.}
214   \textcolor{comment}{! Uncomment if wave\_speed is not used to calculate the true values (BDM).}
215   \textcolor{comment}{!do m=1,CS%nMode ; do j=jsd,jed ; do i=isd,ied}
216   \textcolor{comment}{!  cn(i,j,m) = cn(i,j,1) / real(m)}
217   \textcolor{comment}{!enddo ; enddo ; enddo}
218 
219   \textcolor{comment}{! Add the forcing.***************************************************************}
220   \textcolor{keywordflow}{if} (cs%energized\_angle <= 0) \textcolor{keywordflow}{then}
221     frac\_per\_sector = 1.0 / \textcolor{keywordtype}{real}(cs%nangle * cs%nmode * cs%nfreq)
222     \textcolor{keywordflow}{do} m=1,cs%nMode ; \textcolor{keywordflow}{do} fr=1,cs%nFreq ; \textcolor{keywordflow}{do} a=1,cs%nAngle ; \textcolor{keywordflow}{do} j=js,je ; \textcolor{keywordflow}{do} i=is,ie
223       f2 = 0.25*((g%CoriolisBu(i,j)**2 + g%CoriolisBu(i-1,j-1)**2) + &
224                  (g%CoriolisBu(i-1,j)**2 + g%CoriolisBu(i,j-1)**2))
225       \textcolor{keywordflow}{if} (cs%frequency(fr)**2 > f2) &
226         cs%En(i,j,a,fr,m) = cs%En(i,j,a,fr,m) + dt*frac\_per\_sector*(1.0-cs%q\_itides) * &
227                             tke\_itidal\_input(i,j)
228 \textcolor{keywordflow}{    enddo} ;\textcolor{keywordflow}{ enddo} ;\textcolor{keywordflow}{ enddo} ;\textcolor{keywordflow}{ enddo} ;\textcolor{keywordflow}{ enddo}
229   \textcolor{keywordflow}{elseif} (cs%energized\_angle <= cs%nAngle) \textcolor{keywordflow}{then}
230     frac\_per\_sector = 1.0 / \textcolor{keywordtype}{real}(cs%nmode * cs%nfreq)
231     a = cs%energized\_angle
232     \textcolor{keywordflow}{do} m=1,cs%nMode ; \textcolor{keywordflow}{do} fr=1,cs%nFreq ; \textcolor{keywordflow}{do} j=js,je ; \textcolor{keywordflow}{do} i=is,ie
233       f2 = 0.25*((g%CoriolisBu(i,j)**2 + g%CoriolisBu(i-1,j-1)**2) + &
234                  (g%CoriolisBu(i-1,j)**2 + g%CoriolisBu(i,j-1)**2))
235       \textcolor{keywordflow}{if} (cs%frequency(fr)**2 > f2) &
236         cs%En(i,j,a,fr,m) = cs%En(i,j,a,fr,m) + dt*frac\_per\_sector*(1.0-cs%q\_itides) * &
237                             tke\_itidal\_input(i,j)
238 \textcolor{keywordflow}{    enddo} ;\textcolor{keywordflow}{ enddo} ;\textcolor{keywordflow}{ enddo} ;\textcolor{keywordflow}{ enddo}
239   \textcolor{keywordflow}{else}
240     \textcolor{keyword}{call }mom\_error(warning, \textcolor{stringliteral}{"Internal tide energy is being put into a angular "}//&
241                             \textcolor{stringliteral}{"band that does not exist."})
242 \textcolor{keywordflow}{  endif}
243 
244   \textcolor{comment}{! Pass a test vector to check for grid rotation in the halo updates.}
245   \textcolor{keywordflow}{do} j=jsd,jed ; \textcolor{keywordflow}{do} i=isd,ied ; test(i,j,1) = 1.0 ; test(i,j,2) = 0.0 ;\textcolor{keywordflow}{ enddo} ;\textcolor{keywordflow}{ enddo}
246   \textcolor{keywordflow}{do} m=1,cs%nMode ; \textcolor{keywordflow}{do} fr=1,cs%nFreq
247     \textcolor{keyword}{call }create\_group\_pass(pass\_en, cs%En(:,:,:,fr,m), g%domain)
248 \textcolor{keywordflow}{  enddo} ;\textcolor{keywordflow}{ enddo}
249   \textcolor{keyword}{call }create\_group\_pass(pass\_test, test(:,:,1), test(:,:,2), g%domain, stagger=agrid)
250   \textcolor{keyword}{call }start\_group\_pass(pass\_test, g%domain)
251 
252   \textcolor{comment}{! Apply half the refraction.}
253   \textcolor{keywordflow}{do} m=1,cs%nMode ; \textcolor{keywordflow}{do} fr=1,cs%nFreq
254     \textcolor{keyword}{call }refract(cs%En(:,:,:,fr,m), cn(:,:,m), cs%frequency(fr), 0.5*dt, &
255                  g, us, cs%nAngle, cs%use\_PPMang)
256 \textcolor{keywordflow}{  enddo} ;\textcolor{keywordflow}{ enddo}
257 
258   \textcolor{comment}{! Check for En<0 - for debugging, delete later}
259   \textcolor{keywordflow}{do} m=1,cs%NMode ; \textcolor{keywordflow}{do} fr=1,cs%Nfreq ; \textcolor{keywordflow}{do} a=1,cs%nAngle
260     \textcolor{keywordflow}{do} j=js,je ; \textcolor{keywordflow}{do} i=is,ie
261       \textcolor{keywordflow}{if} (cs%En(i,j,a,fr,m)<0.0) \textcolor{keywordflow}{then}
262         id\_g = i + g%idg\_offset ; jd\_g = j + g%jdg\_offset \textcolor{comment}{! for debugging}
263         \textcolor{keyword}{write}(mesg,*) \textcolor{stringliteral}{'After first refraction: En<0.0 at ig='}, id\_g, \textcolor{stringliteral}{', jg='}, jd\_g, &
264                       \textcolor{stringliteral}{'En='},cs%En(i,j,a,fr,m)
265         \textcolor{keyword}{call }mom\_error(warning, \textcolor{stringliteral}{"propagate\_int\_tide: "}//trim(mesg))
266         cs%En(i,j,a,fr,m) = 0.0
267 \textcolor{comment}{!        call MOM\_error(FATAL, "propagate\_int\_tide: stopped due to negative energy.")}
268 \textcolor{keywordflow}{      endif}
269 \textcolor{keywordflow}{    enddo} ;\textcolor{keywordflow}{ enddo}
270 \textcolor{keywordflow}{  enddo} ;\textcolor{keywordflow}{ enddo} ;\textcolor{keywordflow}{ enddo}
271 
272   \textcolor{keyword}{call }do\_group\_pass(pass\_en, g%domain)
273 
274   \textcolor{keyword}{call }complete\_group\_pass(pass\_test, g%domain)
275 
276   \textcolor{comment}{! Rotate points in the halos as necessary.}
277   \textcolor{keyword}{call }correct\_halo\_rotation(cs%En, test, g, cs%nAngle)
278 
279   \textcolor{comment}{! Propagate the waves.}
280   \textcolor{keywordflow}{do} m=1,cs%NMode ; \textcolor{keywordflow}{do} fr=1,cs%Nfreq
281     \textcolor{keyword}{call }propagate(cs%En(:,:,:,fr,m), cn(:,:,m), cs%frequency(fr), dt, &
282                    g, us, cs, cs%NAngle)
283 \textcolor{keywordflow}{  enddo} ;\textcolor{keywordflow}{ enddo}
284 
285   \textcolor{comment}{! Check for En<0 - for debugging, delete later}
286   \textcolor{keywordflow}{do} m=1,cs%NMode ; \textcolor{keywordflow}{do} fr=1,cs%Nfreq ; \textcolor{keywordflow}{do} a=1,cs%nAngle
287     \textcolor{keywordflow}{do} j=js,je ; \textcolor{keywordflow}{do} i=is,ie
288       \textcolor{keywordflow}{if} (cs%En(i,j,a,fr,m)<0.0) \textcolor{keywordflow}{then}
289         id\_g = i + g%idg\_offset ; jd\_g = j + g%jdg\_offset
290         \textcolor{keywordflow}{if} (abs(cs%En(i,j,a,fr,m))>1.0) \textcolor{keywordflow}{then} \textcolor{comment}{! only print if large}
291           \textcolor{keyword}{write}(mesg,*)  \textcolor{stringliteral}{'After propagation: En<0.0 at ig='}, id\_g, \textcolor{stringliteral}{', jg='}, jd\_g, &
292                          \textcolor{stringliteral}{'En='}, cs%En(i,j,a,fr,m)
293           \textcolor{keyword}{call }mom\_error(warning, \textcolor{stringliteral}{"propagate\_int\_tide: "}//trim(mesg))
294 \textcolor{comment}{!          call MOM\_error(FATAL, "propagate\_int\_tide: stopped due to negative energy.")}
295 \textcolor{keywordflow}{        endif}
296         cs%En(i,j,a,fr,m) = 0.0
297 \textcolor{keywordflow}{      endif}
298 \textcolor{keywordflow}{    enddo} ;\textcolor{keywordflow}{ enddo}
299 \textcolor{keywordflow}{  enddo} ;\textcolor{keywordflow}{ enddo} ;\textcolor{keywordflow}{ enddo}
300 
301   \textcolor{comment}{! Apply the other half of the refraction.}
302   \textcolor{keywordflow}{do} m=1,cs%NMode ; \textcolor{keywordflow}{do} fr=1,cs%Nfreq
303     \textcolor{keyword}{call }refract(cs%En(:,:,:,fr,m), cn(:,:,m), cs%frequency(fr), 0.5*dt, &
304                  g, us, cs%NAngle, cs%use\_PPMang)
305 \textcolor{keywordflow}{  enddo} ;\textcolor{keywordflow}{ enddo}
306 
307   \textcolor{comment}{! Check for En<0 - for debugging, delete later}
308   \textcolor{keywordflow}{do} m=1,cs%NMode ; \textcolor{keywordflow}{do} fr=1,cs%Nfreq ; \textcolor{keywordflow}{do} a=1,cs%nAngle
309     \textcolor{keywordflow}{do} j=js,je ; \textcolor{keywordflow}{do} i=is,ie
310       \textcolor{keywordflow}{if} (cs%En(i,j,a,fr,m)<0.0) \textcolor{keywordflow}{then}
311         id\_g = i + g%idg\_offset ; jd\_g = j + g%jdg\_offset \textcolor{comment}{! for debugging}
312         \textcolor{keyword}{write}(mesg,*) \textcolor{stringliteral}{'After second refraction: En<0.0 at ig='}, id\_g, \textcolor{stringliteral}{', jg='}, jd\_g, &
313                       \textcolor{stringliteral}{'En='},cs%En(i,j,a,fr,m)
314         \textcolor{keyword}{call }mom\_error(warning, \textcolor{stringliteral}{"propagate\_int\_tide: "}//trim(mesg))
315         cs%En(i,j,a,fr,m) = 0.0
316 \textcolor{comment}{!        call MOM\_error(FATAL, "propagate\_int\_tide: stopped due to negative energy.")}
317 \textcolor{keywordflow}{      endif}
318 \textcolor{keywordflow}{    enddo} ;\textcolor{keywordflow}{ enddo}
319 \textcolor{keywordflow}{  enddo} ;\textcolor{keywordflow}{ enddo} ;\textcolor{keywordflow}{ enddo}
320 
321   \textcolor{comment}{! Apply various dissipation mechanisms.}
322   \textcolor{keywordflow}{if} (cs%apply\_background\_drag .or. cs%apply\_bottom\_drag &
323       .or. cs%apply\_wave\_drag .or. cs%apply\_Froude\_drag &
324       .or. (cs%id\_tot\_En > 0)) \textcolor{keywordflow}{then}
325     tot\_en(:,:) = 0.0
326     tot\_en\_mode(:,:,:,:) = 0.0
327     \textcolor{keywordflow}{do} m=1,cs%NMode ; \textcolor{keywordflow}{do} fr=1,cs%Nfreq
328       \textcolor{keywordflow}{do} j=jsd,jed ; \textcolor{keywordflow}{do} i=isd,ied ; \textcolor{keywordflow}{do} a=1,cs%nAngle
329         tot\_en(i,j) = tot\_en(i,j) + cs%En(i,j,a,fr,m)
330         tot\_en\_mode(i,j,fr,m) = tot\_en\_mode(i,j,fr,m) + cs%En(i,j,a,fr,m)
331 \textcolor{keywordflow}{      enddo} ;\textcolor{keywordflow}{ enddo} ;\textcolor{keywordflow}{ enddo}
332 \textcolor{keywordflow}{    enddo} ;\textcolor{keywordflow}{ enddo}
333 \textcolor{keywordflow}{  endif}
334 
335   \textcolor{comment}{! Extract the energy for mixing due to misc. processes (background leakage)------}
336   \textcolor{keywordflow}{if} (cs%apply\_background\_drag) \textcolor{keywordflow}{then}
337     \textcolor{keywordflow}{do} m=1,cs%nMode ; \textcolor{keywordflow}{do} fr=1,cs%nFreq ; \textcolor{keywordflow}{do} a=1,cs%nAngle ; \textcolor{keywordflow}{do} j=jsd,jed ; \textcolor{keywordflow}{do} i=isd,ied
338     \textcolor{comment}{! Calculate loss rate and apply loss over the time step ; apply the same drag timescale}
339     \textcolor{comment}{! to each En component (technically not correct; fix later)}
340     cs%TKE\_leak\_loss(i,j,a,fr,m)  = cs%En(i,j,a,fr,m) * cs%decay\_rate \textcolor{comment}{! loss rate [R Z3 T-3 ~> W m-2]}
341     cs%En(i,j,a,fr,m) = cs%En(i,j,a,fr,m) / (1.0 + dt * cs%decay\_rate) \textcolor{comment}{! implicit update}
342 \textcolor{keywordflow}{    enddo} ;\textcolor{keywordflow}{ enddo} ;\textcolor{keywordflow}{ enddo} ;\textcolor{keywordflow}{ enddo} ;\textcolor{keywordflow}{ enddo}
343 \textcolor{keywordflow}{  endif}
344   \textcolor{comment}{! Check for En<0 - for debugging, delete later}
345   \textcolor{keywordflow}{do} m=1,cs%NMode ; \textcolor{keywordflow}{do} fr=1,cs%Nfreq ; \textcolor{keywordflow}{do} a=1,cs%nAngle
346     \textcolor{keywordflow}{do} j=js,je ; \textcolor{keywordflow}{do} i=is,ie
347       \textcolor{keywordflow}{if} (cs%En(i,j,a,fr,m)<0.0) \textcolor{keywordflow}{then}
348         id\_g = i + g%idg\_offset ; jd\_g = j + g%jdg\_offset \textcolor{comment}{! for debugging}
349         \textcolor{keyword}{write}(mesg,*) \textcolor{stringliteral}{'After leak loss: En<0.0 at ig='}, id\_g, \textcolor{stringliteral}{', jg='}, jd\_g, &
350                       \textcolor{stringliteral}{'En='},cs%En(i,j,a,fr,m)
351         \textcolor{keyword}{call }mom\_error(warning, \textcolor{stringliteral}{"propagate\_int\_tide: "}//trim(mesg), all\_print=.true.)
352         cs%En(i,j,a,fr,m) = 0.0
353 \textcolor{comment}{!       call MOM\_error(FATAL, "propagate\_int\_tide: stopped due to negative energy.")}
354 \textcolor{keywordflow}{      endif}
355 \textcolor{keywordflow}{    enddo} ;\textcolor{keywordflow}{ enddo}
356 \textcolor{keywordflow}{  enddo} ;\textcolor{keywordflow}{ enddo} ;\textcolor{keywordflow}{ enddo}
357 
358   \textcolor{comment}{! Extract the energy for mixing due to bottom drag-------------------------------}
359   \textcolor{keywordflow}{if} (cs%apply\_bottom\_drag) \textcolor{keywordflow}{then}
360     \textcolor{keywordflow}{do} j=jsd,jed ; \textcolor{keywordflow}{do} i=isd,ied
361       \textcolor{comment}{! Note the 1 m dimensional scale here.  Should this be a parameter?}
362       i\_d\_here = 1.0 / (max(g%bathyT(i,j), 1.0*us%m\_to\_Z))
363       drag\_scale(i,j) = cs%cdrag * sqrt(max(0.0, us%L\_to\_Z**2*vel\_bttide(i,j)**2 + &
364                         tot\_en(i,j) * i\_rho0 * i\_d\_here)) * i\_d\_here
365 \textcolor{keywordflow}{    enddo} ;\textcolor{keywordflow}{ enddo}
366     \textcolor{keywordflow}{do} m=1,cs%nMode ; \textcolor{keywordflow}{do} fr=1,cs%nFreq ; \textcolor{keywordflow}{do} a=1,cs%nAngle ; \textcolor{keywordflow}{do} j=jsd,jed ; \textcolor{keywordflow}{do} i=isd,ied
367       \textcolor{comment}{! Calculate loss rate and apply loss over the time step ; apply the same drag timescale}
368       \textcolor{comment}{! to each En component (technically not correct; fix later)}
369       cs%TKE\_quad\_loss(i,j,a,fr,m)  = cs%En(i,j,a,fr,m) * drag\_scale(i,j) \textcolor{comment}{! loss rate}
370       cs%En(i,j,a,fr,m) = cs%En(i,j,a,fr,m) / (1.0 + dt * drag\_scale(i,j)) \textcolor{comment}{! implicit update}
371 \textcolor{keywordflow}{    enddo} ;\textcolor{keywordflow}{ enddo} ;\textcolor{keywordflow}{ enddo} ;\textcolor{keywordflow}{ enddo} ;\textcolor{keywordflow}{ enddo}
372 \textcolor{keywordflow}{  endif}
373   \textcolor{comment}{! Check for En<0 - for debugging, delete later}
374   \textcolor{keywordflow}{do} m=1,cs%NMode ; \textcolor{keywordflow}{do} fr=1,cs%Nfreq ; \textcolor{keywordflow}{do} a=1,cs%nAngle
375     \textcolor{keywordflow}{do} j=js,je ; \textcolor{keywordflow}{do} i=is,ie
376       \textcolor{keywordflow}{if} (cs%En(i,j,a,fr,m)<0.0) \textcolor{keywordflow}{then}
377         id\_g = i + g%idg\_offset ; jd\_g = j + g%jdg\_offset \textcolor{comment}{! for debugging}
378         \textcolor{keyword}{write}(mesg,*) \textcolor{stringliteral}{'After bottom loss: En<0.0 at ig='}, id\_g, \textcolor{stringliteral}{', jg='}, jd\_g, &
379                       \textcolor{stringliteral}{'En='},cs%En(i,j,a,fr,m)
380         \textcolor{keyword}{call }mom\_error(warning, \textcolor{stringliteral}{"propagate\_int\_tide: "}//trim(mesg), all\_print=.true.)
381         cs%En(i,j,a,fr,m) = 0.0
382 \textcolor{comment}{!       call MOM\_error(FATAL, "propagate\_int\_tide: stopped due to negative energy.")}
383         \textcolor{comment}{!stop}
384 \textcolor{keywordflow}{      endif}
385 \textcolor{keywordflow}{    enddo} ;\textcolor{keywordflow}{ enddo}
386 \textcolor{keywordflow}{  enddo} ;\textcolor{keywordflow}{ enddo} ;\textcolor{keywordflow}{ enddo}
387 
388   \textcolor{comment}{! Extract the energy for mixing due to scattering (wave-drag)--------------------}
389   \textcolor{comment}{! still need to allow a portion of the extracted energy to go to higher modes.}
390   \textcolor{comment}{! First, find velocity profiles}
391   \textcolor{keywordflow}{if} (cs%apply\_wave\_drag .or. cs%apply\_Froude\_drag) \textcolor{keywordflow}{then}
392     \textcolor{keywordflow}{do} m=1,cs%NMode ; \textcolor{keywordflow}{do} fr=1,cs%Nfreq
393       \textcolor{comment}{! Calculate modal structure for given mode and frequency}
394       \textcolor{keyword}{call }wave\_structure(h, tv, g, gv, us, cn(:,:,m), m, cs%frequency(fr), &
395                           cs%wave\_structure\_CSp, tot\_en\_mode(:,:,fr,m), full\_halos=.true.)
396       \textcolor{comment}{! Pick out near-bottom and max horizontal baroclinic velocity values at each point}
397       \textcolor{keywordflow}{do} j=jsd,jed ; \textcolor{keywordflow}{do} i=isd,ied
398         id\_g = i + g%idg\_offset ; jd\_g = j + g%jdg\_offset \textcolor{comment}{! for debugging}
399         nzm = cs%wave\_structure\_CSp%num\_intfaces(i,j)
400         ub(i,j,fr,m) = cs%wave\_structure\_CSp%Uavg\_profile(i,j,nzm)
401         umax(i,j,fr,m) = maxval(cs%wave\_structure\_CSp%Uavg\_profile(i,j,1:nzm))
402 \textcolor{keywordflow}{      enddo} ;\textcolor{keywordflow}{ enddo} \textcolor{comment}{! i-loop, j-loop}
403 \textcolor{keywordflow}{    enddo} ;\textcolor{keywordflow}{ enddo} \textcolor{comment}{! fr-loop, m-loop}
404 \textcolor{keywordflow}{  endif} \textcolor{comment}{! apply\_wave or \_Froude\_drag (Ub or Umax needed)}
405   \textcolor{comment}{! Finally, apply loss}
406   \textcolor{keywordflow}{if} (cs%apply\_wave\_drag) \textcolor{keywordflow}{then}
407     \textcolor{comment}{! Calculate loss rate and apply loss over the time step}
408     \textcolor{keyword}{call }itidal\_lowmode\_loss(g, us, cs, nb, ub, cs%En, cs%TKE\_itidal\_loss\_fixed, &
409                              cs%TKE\_itidal\_loss, dt, full\_halos=.false.)
410 \textcolor{keywordflow}{  endif}
411   \textcolor{comment}{! Check for En<0 - for debugging, delete later}
412   \textcolor{keywordflow}{do} m=1,cs%NMode ; \textcolor{keywordflow}{do} fr=1,cs%Nfreq ; \textcolor{keywordflow}{do} a=1,cs%nAngle
413     \textcolor{keywordflow}{do} j=js,je ; \textcolor{keywordflow}{do} i=is,ie
414       \textcolor{keywordflow}{if} (cs%En(i,j,a,fr,m)<0.0) \textcolor{keywordflow}{then}
415         id\_g = i + g%idg\_offset ; jd\_g = j + g%jdg\_offset \textcolor{comment}{! for debugging}
416         \textcolor{keyword}{write}(mesg,*) \textcolor{stringliteral}{'After wave drag loss: En<0.0 at ig='}, id\_g, \textcolor{stringliteral}{', jg='}, jd\_g, &
417                       \textcolor{stringliteral}{'En='},cs%En(i,j,a,fr,m)
418         \textcolor{keyword}{call }mom\_error(warning, \textcolor{stringliteral}{"propagate\_int\_tide: "}//trim(mesg), all\_print=.true.)
419         cs%En(i,j,a,fr,m) = 0.0
420 \textcolor{comment}{!       call MOM\_error(FATAL, "propagate\_int\_tide: stopped due to negative energy.")}
421 \textcolor{keywordflow}{      endif}
422 \textcolor{keywordflow}{    enddo} ;\textcolor{keywordflow}{ enddo}
423 \textcolor{keywordflow}{  enddo} ;\textcolor{keywordflow}{ enddo} ;\textcolor{keywordflow}{ enddo}
424 
425   \textcolor{comment}{! Extract the energy for mixing due to wave breaking-----------------------------}
426   \textcolor{keywordflow}{if} (cs%apply\_Froude\_drag) \textcolor{keywordflow}{then}
427     \textcolor{comment}{! Pick out maximum baroclinic velocity values; calculate Fr=max(u)/cg}
428     \textcolor{keywordflow}{do} m=1,cs%NMode ; \textcolor{keywordflow}{do} fr=1,cs%Nfreq
429       freq2 = cs%frequency(fr)**2
430       \textcolor{keywordflow}{do} j=jsd,jed ; \textcolor{keywordflow}{do} i=isd,ied
431         id\_g = i + g%idg\_offset ; jd\_g = j + g%jdg\_offset \textcolor{comment}{! for debugging}
432         \textcolor{comment}{! Calculate horizontal phase velocity magnitudes}
433         f2 = 0.25*((g%CoriolisBu(i,j)**2 + g%CoriolisBu(i-1,j-1)**2) + &
434                    (g%CoriolisBu(i-1,j)**2 + g%CoriolisBu(i,j-1)**2))
435         kmag2 = (freq2 - f2) / (cn(i,j,m)**2 + cn\_subro**2)
436         c\_phase = 0.0
437         \textcolor{keywordflow}{if} (kmag2 > 0.0) \textcolor{keywordflow}{then}
438           c\_phase = sqrt(freq2/kmag2)
439           nzm = cs%wave\_structure\_CSp%num\_intfaces(i,j)
440           fr2\_max = (umax(i,j,fr,m) / c\_phase)**2
441           \textcolor{comment}{! Dissipate energy if Fr>1; done here with an arbitrary time scale}
442           \textcolor{keywordflow}{if} (fr2\_max > 1.0) \textcolor{keywordflow}{then}
443             en\_initial = sum(cs%En(i,j,:,fr,m)) \textcolor{comment}{! for debugging}
444             \textcolor{comment}{! Calculate effective decay rate [T-1 ~> s-1] if breaking occurs over a time step}
445             loss\_rate = (1.0 - fr2\_max) / (fr2\_max * dt)
446             \textcolor{keywordflow}{do} a=1,cs%nAngle
447               \textcolor{comment}{! Determine effective dissipation rate (Wm-2)}
448               cs%TKE\_Froude\_loss(i,j,a,fr,m) = cs%En(i,j,a,fr,m) * abs(loss\_rate)
449               \textcolor{comment}{! Update energy}
450               en\_new = cs%En(i,j,a,fr,m)/fr2\_max \textcolor{comment}{! for debugging}
451               en\_check = cs%En(i,j,a,fr,m) - cs%TKE\_Froude\_loss(i,j,a,fr,m)*dt \textcolor{comment}{! for debugging}
452               \textcolor{comment}{! Re-scale (reduce) energy due to breaking}
453               cs%En(i,j,a,fr,m) = cs%En(i,j,a,fr,m)/fr2\_max
454               \textcolor{comment}{! Check (for debugging only)}
455               \textcolor{keywordflow}{if} (abs(en\_new - en\_check) > 1e-10*us%kg\_m3\_to\_R*us%m\_to\_Z**3*us%T\_to\_s**2) \textcolor{keywordflow}{then}
456                 \textcolor{keyword}{call }mom\_error(warning, \textcolor{stringliteral}{"MOM\_internal\_tides: something is wrong with Fr-breaking."}, &
457                                all\_print=.true.)
458                 \textcolor{keyword}{write}(mesg,*) \textcolor{stringliteral}{"En\_new="}, en\_new , \textcolor{stringliteral}{"En\_check="}, en\_check
459                 \textcolor{keyword}{call }mom\_error(warning, \textcolor{stringliteral}{"MOM\_internal\_tides: "}//trim(mesg), all\_print=.true.)
460 \textcolor{keywordflow}{              endif}
461 \textcolor{keywordflow}{            enddo}
462             \textcolor{comment}{! Check (for debugging)}
463             delta\_e\_check = en\_initial - sum(cs%En(i,j,:,fr,m))
464             tke\_froude\_loss\_check = abs(delta\_e\_check)/dt
465             tke\_froude\_loss\_tot = sum(cs%TKE\_Froude\_loss(i,j,:,fr,m))
466             \textcolor{keywordflow}{if} (abs(tke\_froude\_loss\_check - tke\_froude\_loss\_tot) > 1e-10) \textcolor{keywordflow}{then}
467               \textcolor{keyword}{call }mom\_error(warning, \textcolor{stringliteral}{"MOM\_internal\_tides: something is wrong with Fr energy update."}, &
468                              all\_print=.true.)
469               \textcolor{keyword}{write}(mesg,*) \textcolor{stringliteral}{"TKE\_Froude\_loss\_check="}, tke\_froude\_loss\_check, &
470                             \textcolor{stringliteral}{"TKE\_Froude\_loss\_tot="}, tke\_froude\_loss\_tot
471               \textcolor{keyword}{call }mom\_error(warning, \textcolor{stringliteral}{"MOM\_internal\_tides: "}//trim(mesg), all\_print=.true.)
472 \textcolor{keywordflow}{            endif}
473 \textcolor{keywordflow}{          endif} \textcolor{comment}{! Fr2>1}
474 \textcolor{keywordflow}{        endif} \textcolor{comment}{! Kmag2>0}
475         cs%cp(i,j,fr,m) = c\_phase
476 \textcolor{keywordflow}{      enddo} ;\textcolor{keywordflow}{ enddo}
477 \textcolor{keywordflow}{    enddo} ;\textcolor{keywordflow}{ enddo}
478 \textcolor{keywordflow}{  endif}
479   \textcolor{comment}{! Check for En<0 - for debugging, delete later}
480   \textcolor{keywordflow}{do} m=1,cs%NMode ; \textcolor{keywordflow}{do} fr=1,cs%Nfreq ; \textcolor{keywordflow}{do} a=1,cs%nAngle
481     \textcolor{keywordflow}{do} j=js,je ; \textcolor{keywordflow}{do} i=is,ie
482       \textcolor{keywordflow}{if} (cs%En(i,j,a,fr,m)<0.0) \textcolor{keywordflow}{then}
483         id\_g = i + g%idg\_offset ; jd\_g = j + g%jdg\_offset
484         \textcolor{keyword}{write}(mesg,*) \textcolor{stringliteral}{'After Froude loss: En<0.0 at ig='}, id\_g, \textcolor{stringliteral}{', jg='}, jd\_g, &
485                       \textcolor{stringliteral}{'En='},cs%En(i,j,a,fr,m)
486         \textcolor{keyword}{call }mom\_error(warning, \textcolor{stringliteral}{"propagate\_int\_tide: "}//trim(mesg), all\_print=.true.)
487         cs%En(i,j,a,fr,m) = 0.0
488 \textcolor{comment}{!       call MOM\_error(FATAL, "propagate\_int\_tide: stopped due to negative energy.")}
489         \textcolor{comment}{!stop}
490 \textcolor{keywordflow}{      endif}
491 \textcolor{keywordflow}{    enddo} ;\textcolor{keywordflow}{ enddo}
492 \textcolor{keywordflow}{  enddo} ;\textcolor{keywordflow}{ enddo} ;\textcolor{keywordflow}{ enddo}
493 
494   \textcolor{comment}{! Check for energy conservation on computational domain.*************************}
495   \textcolor{keywordflow}{do} m=1,cs%NMode ; \textcolor{keywordflow}{do} fr=1,cs%Nfreq
496     \textcolor{keyword}{call }sum\_en(g,cs,cs%En(:,:,:,fr,m),\textcolor{stringliteral}{'prop\_int\_tide'})
497 \textcolor{keywordflow}{  enddo} ;\textcolor{keywordflow}{ enddo}
498 
499   \textcolor{comment}{! Output diagnostics.************************************************************}
500   \textcolor{keywordflow}{if} (query\_averaging\_enabled(cs%diag)) \textcolor{keywordflow}{then}
501     \textcolor{comment}{! Output two-dimensional diagnostistics}
502     \textcolor{keywordflow}{if} (cs%id\_tot\_En > 0)     \textcolor{keyword}{call }post\_data(cs%id\_tot\_En, tot\_en, cs%diag)
503     \textcolor{keywordflow}{if} (cs%id\_itide\_drag > 0) \textcolor{keyword}{call }post\_data(cs%id\_itide\_drag, drag\_scale, cs%diag)
504     \textcolor{keywordflow}{if} (cs%id\_TKE\_itidal\_input > 0) \textcolor{keyword}{call }post\_data(cs%id\_TKE\_itidal\_input, &
505                                                    tke\_itidal\_input, cs%diag)
506 
507     \textcolor{comment}{! Output 2-D energy density (summed over angles) for each freq and mode}
508     \textcolor{keywordflow}{do} m=1,cs%NMode ; \textcolor{keywordflow}{do} fr=1,cs%Nfreq ; \textcolor{keywordflow}{if} (cs%id\_En\_mode(fr,m) > 0) \textcolor{keywordflow}{then}
509       tot\_en(:,:) = 0.0
510       \textcolor{keywordflow}{do} a=1,cs%nAngle ; \textcolor{keywordflow}{do} j=js,je ; \textcolor{keywordflow}{do} i=is,ie
511         tot\_en(i,j) = tot\_en(i,j) + cs%En(i,j,a,fr,m)
512 \textcolor{keywordflow}{      enddo} ;\textcolor{keywordflow}{ enddo} ;\textcolor{keywordflow}{ enddo}
513       \textcolor{keyword}{call }post\_data(cs%id\_En\_mode(fr,m), tot\_en, cs%diag)
514 \textcolor{keywordflow}{    endif} ;\textcolor{keywordflow}{ enddo} ;\textcolor{keywordflow}{ enddo}
515 
516     \textcolor{comment}{! Output 3-D (i,j,a) energy density for each freq and mode}
517     \textcolor{keywordflow}{do} m=1,cs%NMode ; \textcolor{keywordflow}{do} fr=1,cs%Nfreq ; \textcolor{keywordflow}{if} (cs%id\_En\_ang\_mode(fr,m) > 0) \textcolor{keywordflow}{then}
518       \textcolor{keyword}{call }post\_data(cs%id\_En\_ang\_mode(fr,m), cs%En(:,:,:,fr,m) , cs%diag)
519 \textcolor{keywordflow}{    endif} ;\textcolor{keywordflow}{ enddo} ;\textcolor{keywordflow}{ enddo}
520 
521     \textcolor{comment}{! Output 2-D energy loss (summed over angles, freq, modes)}
522     tot\_leak\_loss(:,:)   = 0.0
523     tot\_quad\_loss(:,:)   = 0.0
524     tot\_itidal\_loss(:,:) = 0.0
525     tot\_froude\_loss(:,:) = 0.0
526     tot\_allprocesses\_loss(:,:) = 0.0
527     \textcolor{keywordflow}{do} m=1,cs%NMode ; \textcolor{keywordflow}{do} fr=1,cs%Nfreq ; \textcolor{keywordflow}{do} a=1,cs%nAngle ; \textcolor{keywordflow}{do} j=js,je ; \textcolor{keywordflow}{do} i=is,ie
528       tot\_leak\_loss(i,j)   = tot\_leak\_loss(i,j)   + cs%TKE\_leak\_loss(i,j,a,fr,m)
529       tot\_quad\_loss(i,j)   = tot\_quad\_loss(i,j)   + cs%TKE\_quad\_loss(i,j,a,fr,m)
530       tot\_itidal\_loss(i,j) = tot\_itidal\_loss(i,j) + cs%TKE\_itidal\_loss(i,j,a,fr,m)
531       tot\_froude\_loss(i,j) = tot\_froude\_loss(i,j) + cs%TKE\_Froude\_loss(i,j,a,fr,m)
532 \textcolor{keywordflow}{    enddo} ;\textcolor{keywordflow}{ enddo} ;\textcolor{keywordflow}{ enddo} ;\textcolor{keywordflow}{ enddo} ;\textcolor{keywordflow}{ enddo}
533     \textcolor{keywordflow}{do} j=js,je ; \textcolor{keywordflow}{do} i=is,ie
534       tot\_allprocesses\_loss(i,j) = tot\_leak\_loss(i,j) + tot\_quad\_loss(i,j) + &
535                           tot\_itidal\_loss(i,j) + tot\_froude\_loss(i,j)
536 \textcolor{keywordflow}{    enddo} ;\textcolor{keywordflow}{ enddo}
537     cs%tot\_leak\_loss         = tot\_leak\_loss
538     cs%tot\_quad\_loss         = tot\_quad\_loss
539     cs%tot\_itidal\_loss       = tot\_itidal\_loss
540     cs%tot\_Froude\_loss       = tot\_froude\_loss
541     cs%tot\_allprocesses\_loss = tot\_allprocesses\_loss
542     \textcolor{keywordflow}{if} (cs%id\_tot\_leak\_loss > 0) \textcolor{keywordflow}{then}
543       \textcolor{keyword}{call }post\_data(cs%id\_tot\_leak\_loss, tot\_leak\_loss, cs%diag)
544 \textcolor{keywordflow}{    endif}
545     \textcolor{keywordflow}{if} (cs%id\_tot\_quad\_loss > 0) \textcolor{keywordflow}{then}
546       \textcolor{keyword}{call }post\_data(cs%id\_tot\_quad\_loss, tot\_quad\_loss, cs%diag)
547 \textcolor{keywordflow}{    endif}
548     \textcolor{keywordflow}{if} (cs%id\_tot\_itidal\_loss > 0) \textcolor{keywordflow}{then}
549       \textcolor{keyword}{call }post\_data(cs%id\_tot\_itidal\_loss, tot\_itidal\_loss, cs%diag)
550 \textcolor{keywordflow}{    endif}
551     \textcolor{keywordflow}{if} (cs%id\_tot\_Froude\_loss > 0) \textcolor{keywordflow}{then}
552       \textcolor{keyword}{call }post\_data(cs%id\_tot\_Froude\_loss, tot\_froude\_loss, cs%diag)
553 \textcolor{keywordflow}{    endif}
554     \textcolor{keywordflow}{if} (cs%id\_tot\_allprocesses\_loss > 0) \textcolor{keywordflow}{then}
555       \textcolor{keyword}{call }post\_data(cs%id\_tot\_allprocesses\_loss, tot\_allprocesses\_loss, cs%diag)
556 \textcolor{keywordflow}{    endif}
557 
558     \textcolor{comment}{! Output 2-D energy loss (summed over angles) for each freq and mode}
559     \textcolor{keywordflow}{do} m=1,cs%NMode ; \textcolor{keywordflow}{do} fr=1,cs%Nfreq
560     \textcolor{keywordflow}{if} (cs%id\_itidal\_loss\_mode(fr,m) > 0 .or. cs%id\_allprocesses\_loss\_mode(fr,m) > 0) \textcolor{keywordflow}{then}
561       itidal\_loss\_mode(:,:) = 0.0 \textcolor{comment}{! wave-drag processes (could do others as well)}
562       allprocesses\_loss\_mode(:,:) = 0.0 \textcolor{comment}{! all processes summed together}
563       \textcolor{keywordflow}{do} a=1,cs%nAngle ; \textcolor{keywordflow}{do} j=js,je ; \textcolor{keywordflow}{do} i=is,ie
564         itidal\_loss\_mode(i,j)       = itidal\_loss\_mode(i,j) + cs%TKE\_itidal\_loss(i,j,a,fr,m)
565         allprocesses\_loss\_mode(i,j) = allprocesses\_loss\_mode(i,j) + &
566                                  cs%TKE\_leak\_loss(i,j,a,fr,m) + cs%TKE\_quad\_loss(i,j,a,fr,m) + &
567                                  cs%TKE\_itidal\_loss(i,j,a,fr,m) + cs%TKE\_Froude\_loss(i,j,a,fr,m)
568 \textcolor{keywordflow}{      enddo} ;\textcolor{keywordflow}{ enddo} ;\textcolor{keywordflow}{ enddo}
569       \textcolor{keyword}{call }post\_data(cs%id\_itidal\_loss\_mode(fr,m), itidal\_loss\_mode, cs%diag)
570       \textcolor{keyword}{call }post\_data(cs%id\_allprocesses\_loss\_mode(fr,m), allprocesses\_loss\_mode, cs%diag)
571 \textcolor{keywordflow}{    endif} ;\textcolor{keywordflow}{ enddo} ;\textcolor{keywordflow}{ enddo}
572 
573     \textcolor{comment}{! Output 3-D (i,j,a) energy loss for each freq and mode}
574     \textcolor{keywordflow}{do} m=1,cs%NMode ; \textcolor{keywordflow}{do} fr=1,cs%Nfreq ; \textcolor{keywordflow}{if} (cs%id\_itidal\_loss\_ang\_mode(fr,m) > 0) \textcolor{keywordflow}{then}
575       \textcolor{keyword}{call }post\_data(cs%id\_itidal\_loss\_ang\_mode(fr,m), cs%TKE\_itidal\_loss(:,:,:,fr,m) , cs%diag)
576 \textcolor{keywordflow}{    endif} ;\textcolor{keywordflow}{ enddo} ;\textcolor{keywordflow}{ enddo}
577 
578     \textcolor{comment}{! Output 2-D period-averaged horizontal near-bottom mode velocity for each freq and mode}
579     \textcolor{keywordflow}{do} m=1,cs%NMode ; \textcolor{keywordflow}{do} fr=1,cs%Nfreq ; \textcolor{keywordflow}{if} (cs%id\_Ub\_mode(fr,m) > 0) \textcolor{keywordflow}{then}
580       \textcolor{keyword}{call }post\_data(cs%id\_Ub\_mode(fr,m), ub(:,:,fr,m), cs%diag)
581 \textcolor{keywordflow}{    endif} ;\textcolor{keywordflow}{ enddo} ;\textcolor{keywordflow}{ enddo}
582 
583     \textcolor{comment}{! Output 2-D horizontal phase velocity for each freq and mode}
584     \textcolor{keywordflow}{do} m=1,cs%NMode ; \textcolor{keywordflow}{do} fr=1,cs%Nfreq ; \textcolor{keywordflow}{if} (cs%id\_cp\_mode(fr,m) > 0) \textcolor{keywordflow}{then}
585       \textcolor{keyword}{call }post\_data(cs%id\_cp\_mode(fr,m), cs%cp(:,:,fr,m), cs%diag)
586 \textcolor{keywordflow}{    endif} ;\textcolor{keywordflow}{ enddo} ;\textcolor{keywordflow}{ enddo}
587 
588 \textcolor{keywordflow}{  endif}
589 
\end{DoxyCode}
\mbox{\Hypertarget{namespacemom__internal__tides_a0b300e27b0ec984bfe8b9afe4e89f8ab}\label{namespacemom__internal__tides_a0b300e27b0ec984bfe8b9afe4e89f8ab}} 
\index{mom\+\_\+internal\+\_\+tides@{mom\+\_\+internal\+\_\+tides}!propagate\+\_\+x@{propagate\+\_\+x}}
\index{propagate\+\_\+x@{propagate\+\_\+x}!mom\+\_\+internal\+\_\+tides@{mom\+\_\+internal\+\_\+tides}}
\subsubsection{\texorpdfstring{propagate\+\_\+x()}{propagate\_x()}}
{\footnotesize\ttfamily subroutine mom\+\_\+internal\+\_\+tides\+::propagate\+\_\+x (\begin{DoxyParamCaption}\item[{real, dimension(g\%isd\+:g\%ied,g\%jsd\+:g\%jed,nangle), intent(inout)}]{En,  }\item[{real, dimension(g\%isdb\+:g\%iedb,g\%jsd\+:g\%jed), intent(in)}]{speed\+\_\+x,  }\item[{real, dimension(nangle), intent(in)}]{Cgx\+\_\+av,  }\item[{real, dimension(nangle), intent(in)}]{d\+Cgx,  }\item[{real, intent(in)}]{dt,  }\item[{type(ocean\+\_\+grid\+\_\+type), intent(in)}]{G,  }\item[{type(unit\+\_\+scale\+\_\+type), intent(in)}]{US,  }\item[{integer, intent(in)}]{Nangle,  }\item[{type(\hyperlink{structmom__internal__tides_1_1int__tide__cs}{int\+\_\+tide\+\_\+cs}), pointer}]{CS,  }\item[{type(\hyperlink{structmom__internal__tides_1_1loop__bounds__type}{loop\+\_\+bounds\+\_\+type}), intent(in)}]{LB }\end{DoxyParamCaption})\hspace{0.3cm}{\ttfamily [private]}}



Propagates the internal wave energy in the logical x-\/direction. 


\begin{DoxyParams}[1]{Parameters}
\mbox{\tt in}  & {\em g} & The ocean\textquotesingle{}s grid structure.\\
\hline
\mbox{\tt in}  & {\em nangle} & The number of wave orientations in the discretized wave energy spectrum.\\
\hline
\mbox{\tt in,out}  & {\em en} & The energy density integrated over an angular\\
\hline
\mbox{\tt in}  & {\em speed\+\_\+x} & The magnitude of the group velocity at the\\
\hline
\mbox{\tt in}  & {\em cgx\+\_\+av} & The average x-\/projection in each angular band.\\
\hline
\mbox{\tt in}  & {\em dcgx} & The difference in x-\/projections between the edges of each angular band.\\
\hline
\mbox{\tt in}  & {\em dt} & Time increment \mbox{[}T $\sim$$>$ s\mbox{]}.\\
\hline
\mbox{\tt in}  & {\em us} & A dimensional unit scaling type\\
\hline
 & {\em cs} & The control structure returned by a previous call to continuity\+\_\+\+P\+P\+M\+\_\+init.\\
\hline
\mbox{\tt in}  & {\em lb} & A structure with the active energy loop bounds. \\
\hline
\end{DoxyParams}


Definition at line 1359 of file M\+O\+M\+\_\+internal\+\_\+tides.\+F90.


\begin{DoxyCode}
1359   \textcolor{keywordtype}{type}(ocean\_grid\_type),   \textcolor{keywordtype}{intent(in)}    :: g\textcolor{comment}{  !< The ocean's grid structure.}
1360   \textcolor{keywordtype}{integer},                 \textcolor{keywordtype}{intent(in)}    :: nangle\textcolor{comment}{ !< The number of wave orientations in the}
1361 \textcolor{comment}{                                               !! discretized wave energy spectrum.}
1362   \textcolor{keywordtype}{real}, \textcolor{keywordtype}{dimension(G%isd:G%ied,G%jsd:G%jed,Nangle)},   &
1363                            \textcolor{keywordtype}{intent(inout)} :: en\textcolor{comment}{ !< The energy density integrated over an angular}
1364 \textcolor{comment}{                                               !! band [R Z3 T-2 ~> J m-2].}
1365   \textcolor{keywordtype}{real}, \textcolor{keywordtype}{dimension(G%IsdB:G%IedB,G%jsd:G%jed)},        &
1366                            \textcolor{keywordtype}{intent(in)}    :: speed\_x\textcolor{comment}{ !< The magnitude of the group velocity at the}
1367 \textcolor{comment}{                                               !! Cu points [L T-1 ~> m s-1].}
1368   \textcolor{keywordtype}{real}, \textcolor{keywordtype}{dimension(Nangle)}, \textcolor{keywordtype}{intent(in)}    :: cgx\_av\textcolor{comment}{ !< The average x-projection in each angular band.}
1369   \textcolor{keywordtype}{real}, \textcolor{keywordtype}{dimension(Nangle)}, \textcolor{keywordtype}{intent(in)}    :: dcgx\textcolor{comment}{ !< The difference in x-projections between the}
1370 \textcolor{comment}{                                               !! edges of each angular band.}
1371   \textcolor{keywordtype}{real},                    \textcolor{keywordtype}{intent(in)}    :: dt\textcolor{comment}{ !< Time increment [T ~> s].}
1372   \textcolor{keywordtype}{type}(unit\_scale\_type),   \textcolor{keywordtype}{intent(in)}    :: us\textcolor{comment}{ !< A dimensional unit scaling type}
1373   \textcolor{keywordtype}{type}(int\_tide\_cs),       \textcolor{keywordtype}{pointer}       :: cs\textcolor{comment}{ !< The control structure returned by a previous call}
1374 \textcolor{comment}{                                               !! to continuity\_PPM\_init.}
1375   \textcolor{keywordtype}{type}(loop\_bounds\_type),  \textcolor{keywordtype}{intent(in)}    :: lb\textcolor{comment}{ !< A structure with the active energy loop bounds.}
1376   \textcolor{comment}{! Local variables}
1377   \textcolor{keywordtype}{real}, \textcolor{keywordtype}{dimension(SZI\_(G),SZJ\_(G))} :: &
1378     enl, enr    \textcolor{comment}{! Left and right face energy densities [R Z3 T-2 ~> J m-2].}
1379   \textcolor{keywordtype}{real}, \textcolor{keywordtype}{dimension(SZIB\_(G),SZJ\_(G))} :: &
1380     flux\_x      \textcolor{comment}{! The internal wave energy flux [J T-1 ~> J s-1].}
1381   \textcolor{keywordtype}{real}, \textcolor{keywordtype}{dimension(SZIB\_(G))} :: &
1382     cg\_p, cg\_m, flux1, flux2
1383   \textcolor{comment}{!real, dimension(SZI\_(G),SZJB\_(G),Nangle) :: En\_m, En\_p}
1384   \textcolor{keywordtype}{real}, \textcolor{keywordtype}{dimension(SZI\_(G),SZJB\_(G),Nangle)} :: &
1385     fdt\_m, fdt\_p\textcolor{comment}{! Left and right energy fluxes [J]}
1386   \textcolor{keywordtype}{integer} :: i, j, k, ish, ieh, jsh, jeh, a
1387 
1388   ish = lb%ish ; ieh = lb%ieh ; jsh = lb%jsh ; jeh = lb%jeh
1389   \textcolor{keywordflow}{do} a=1,nangle
1390   \textcolor{comment}{! This sets EnL and EnR.}
1391     \textcolor{keywordflow}{if} (cs%upwind\_1st) \textcolor{keywordflow}{then}
1392       \textcolor{keywordflow}{do} j=jsh,jeh ; \textcolor{keywordflow}{do} i=ish-1,ieh+1
1393         enl(i,j) = en(i,j,a) ; enr(i,j) = en(i,j,a)
1394 \textcolor{keywordflow}{      enddo} ;\textcolor{keywordflow}{ enddo}
1395     \textcolor{keywordflow}{else}
1396       \textcolor{keyword}{call }ppm\_reconstruction\_x(en(:,:,a), enl, enr, g, lb, simple\_2nd=cs%simple\_2nd)
1397 \textcolor{keywordflow}{    endif}
1398 
1399     \textcolor{keywordflow}{do} j=jsh,jeh
1400       \textcolor{comment}{! This is done once with single speed (GARDEN SPRINKLER EFFECT POSSIBLE)}
1401       \textcolor{keywordflow}{do} i=ish-1,ieh
1402         cg\_p(i) = speed\_x(i,j) * (cgx\_av(a))
1403 \textcolor{keywordflow}{      enddo}
1404       \textcolor{keyword}{call }zonal\_flux\_en(cg\_p, en(:,j,a), enl(:,j), enr(:,j), flux1, &
1405                          dt, g, us, j, ish, ieh, cs%vol\_CFL)
1406       \textcolor{keywordflow}{do} i=ish-1,ieh ; flux\_x(i,j) = flux1(i);\textcolor{keywordflow}{ enddo}
1407 \textcolor{keywordflow}{    enddo}
1408 
1409     \textcolor{keywordflow}{do} j=jsh,jeh ; \textcolor{keywordflow}{do} i=ish,ieh
1410       fdt\_m(i,j,a) = dt*flux\_x(i-1,j) \textcolor{comment}{! left face influx  (J)}
1411       fdt\_p(i,j,a) = -dt*flux\_x(i,j)  \textcolor{comment}{! right face influx (J)}
1412 \textcolor{keywordflow}{    enddo} ;\textcolor{keywordflow}{ enddo}
1413 
1414 \textcolor{keywordflow}{  enddo} \textcolor{comment}{! a-loop}
1415 
1416   \textcolor{comment}{! Only reflect newly arrived energy; existing energy in incident wedge is not reflected}
1417   \textcolor{comment}{! and will eventually propagate out of cell. (This code only reflects if En > 0.)}
1418   \textcolor{keyword}{call }reflect(fdt\_m, nangle, cs, g, lb)
1419   \textcolor{keyword}{call }teleport(fdt\_m, nangle, cs, g, lb)
1420   \textcolor{keyword}{call }reflect(fdt\_p, nangle, cs, g, lb)
1421   \textcolor{keyword}{call }teleport(fdt\_p, nangle, cs, g, lb)
1422 
1423   \textcolor{comment}{! Update reflected energy [R Z3 T-2 ~> J m-2]}
1424   \textcolor{keywordflow}{do} a=1,nangle ; \textcolor{keywordflow}{do} j=jsh,jeh ; \textcolor{keywordflow}{do} i=ish,ieh
1425     \textcolor{comment}{!  if ((En(i,j,a) + G%IareaT(i,j)*(Fdt\_m(i,j,a) + Fdt\_p(i,j,a))) < 0.0) & ! for debugging}
1426     \textcolor{comment}{!    call MOM\_error(FATAL, "propagate\_x: OutFlux>Available")}
1427     en(i,j,a) = en(i,j,a) + g%IareaT(i,j)*(fdt\_m(i,j,a) + fdt\_p(i,j,a))
1428 \textcolor{keywordflow}{  enddo} ;\textcolor{keywordflow}{ enddo} ;\textcolor{keywordflow}{ enddo}
1429 
\end{DoxyCode}
\mbox{\Hypertarget{namespacemom__internal__tides_ae1a31a7f0db2b05c1d863f022b799c7b}\label{namespacemom__internal__tides_ae1a31a7f0db2b05c1d863f022b799c7b}} 
\index{mom\+\_\+internal\+\_\+tides@{mom\+\_\+internal\+\_\+tides}!propagate\+\_\+y@{propagate\+\_\+y}}
\index{propagate\+\_\+y@{propagate\+\_\+y}!mom\+\_\+internal\+\_\+tides@{mom\+\_\+internal\+\_\+tides}}
\subsubsection{\texorpdfstring{propagate\+\_\+y()}{propagate\_y()}}
{\footnotesize\ttfamily subroutine mom\+\_\+internal\+\_\+tides\+::propagate\+\_\+y (\begin{DoxyParamCaption}\item[{real, dimension(g\%isd\+:g\%ied,g\%jsd\+:g\%jed,nangle), intent(inout)}]{En,  }\item[{real, dimension(g\%isd\+:g\%ied,g\%jsdb\+:g\%jedb), intent(in)}]{speed\+\_\+y,  }\item[{real, dimension(nangle), intent(in)}]{Cgy\+\_\+av,  }\item[{real, dimension(nangle), intent(in)}]{d\+Cgy,  }\item[{real, intent(in)}]{dt,  }\item[{type(ocean\+\_\+grid\+\_\+type), intent(in)}]{G,  }\item[{type(unit\+\_\+scale\+\_\+type), intent(in)}]{US,  }\item[{integer, intent(in)}]{Nangle,  }\item[{type(\hyperlink{structmom__internal__tides_1_1int__tide__cs}{int\+\_\+tide\+\_\+cs}), pointer}]{CS,  }\item[{type(\hyperlink{structmom__internal__tides_1_1loop__bounds__type}{loop\+\_\+bounds\+\_\+type}), intent(in)}]{LB }\end{DoxyParamCaption})\hspace{0.3cm}{\ttfamily [private]}}



Propagates the internal wave energy in the logical y-\/direction. 


\begin{DoxyParams}[1]{Parameters}
\mbox{\tt in}  & {\em g} & The ocean\textquotesingle{}s grid structure.\\
\hline
\mbox{\tt in}  & {\em nangle} & The number of wave orientations in the discretized wave energy spectrum.\\
\hline
\mbox{\tt in,out}  & {\em en} & The energy density integrated over an angular\\
\hline
\mbox{\tt in}  & {\em speed\+\_\+y} & The magnitude of the group velocity at the\\
\hline
\mbox{\tt in}  & {\em cgy\+\_\+av} & The average y-\/projection in each angular band.\\
\hline
\mbox{\tt in}  & {\em dcgy} & The difference in y-\/projections between the edges of each angular band.\\
\hline
\mbox{\tt in}  & {\em dt} & Time increment \mbox{[}T $\sim$$>$ s\mbox{]}.\\
\hline
\mbox{\tt in}  & {\em us} & A dimensional unit scaling type\\
\hline
 & {\em cs} & The control structure returned by a previous call to continuity\+\_\+\+P\+P\+M\+\_\+init.\\
\hline
\mbox{\tt in}  & {\em lb} & A structure with the active energy loop bounds. \\
\hline
\end{DoxyParams}


Definition at line 1434 of file M\+O\+M\+\_\+internal\+\_\+tides.\+F90.


\begin{DoxyCode}
1434   \textcolor{keywordtype}{type}(ocean\_grid\_type),   \textcolor{keywordtype}{intent(in)}    :: g\textcolor{comment}{  !< The ocean's grid structure.}
1435   \textcolor{keywordtype}{integer},                 \textcolor{keywordtype}{intent(in)}    :: nangle\textcolor{comment}{ !< The number of wave orientations in the}
1436 \textcolor{comment}{                                               !! discretized wave energy spectrum.}
1437   \textcolor{keywordtype}{real}, \textcolor{keywordtype}{dimension(G%isd:G%ied,G%jsd:G%jed,Nangle)}, &
1438                            \textcolor{keywordtype}{intent(inout)} :: en\textcolor{comment}{ !< The energy density integrated over an angular}
1439 \textcolor{comment}{                                               !! band [R Z3 T-2 ~> J m-2].}
1440   \textcolor{keywordtype}{real}, \textcolor{keywordtype}{dimension(G%isd:G%ied,G%JsdB:G%JedB)},      &
1441                            \textcolor{keywordtype}{intent(in)}    :: speed\_y\textcolor{comment}{ !< The magnitude of the group velocity at the}
1442 \textcolor{comment}{                                               !! Cv points [L T-1 ~> m s-1].}
1443   \textcolor{keywordtype}{real}, \textcolor{keywordtype}{dimension(Nangle)}, \textcolor{keywordtype}{intent(in)}    :: cgy\_av\textcolor{comment}{ !< The average y-projection in each angular band.}
1444   \textcolor{keywordtype}{real}, \textcolor{keywordtype}{dimension(Nangle)}, \textcolor{keywordtype}{intent(in)}    :: dcgy\textcolor{comment}{ !< The difference in y-projections between the}
1445 \textcolor{comment}{                                               !! edges of each angular band.}
1446   \textcolor{keywordtype}{real},                    \textcolor{keywordtype}{intent(in)}    :: dt\textcolor{comment}{ !< Time increment [T ~> s].}
1447   \textcolor{keywordtype}{type}(unit\_scale\_type),   \textcolor{keywordtype}{intent(in)}    :: us\textcolor{comment}{ !< A dimensional unit scaling type}
1448   \textcolor{keywordtype}{type}(int\_tide\_cs),       \textcolor{keywordtype}{pointer}       :: cs\textcolor{comment}{ !< The control structure returned by a previous call}
1449 \textcolor{comment}{                                               !! to continuity\_PPM\_init.}
1450   \textcolor{keywordtype}{type}(loop\_bounds\_type),  \textcolor{keywordtype}{intent(in)}    :: lb\textcolor{comment}{ !< A structure with the active energy loop bounds.}
1451   \textcolor{comment}{! Local variables}
1452   \textcolor{keywordtype}{real}, \textcolor{keywordtype}{dimension(SZI\_(G),SZJ\_(G))} :: &
1453     enl, enr    \textcolor{comment}{! South and north face energy densities [R Z3 T-2 ~> J m-2].}
1454   \textcolor{keywordtype}{real}, \textcolor{keywordtype}{dimension(SZI\_(G),SZJB\_(G))} :: &
1455     flux\_y      \textcolor{comment}{! The internal wave energy flux [J T-1 ~> J s-1].}
1456   \textcolor{keywordtype}{real}, \textcolor{keywordtype}{dimension(SZI\_(G))} :: &
1457     cg\_p, cg\_m, flux1, flux2
1458   \textcolor{comment}{!real, dimension(SZI\_(G),SZJB\_(G),Nangle) :: En\_m, En\_p}
1459   \textcolor{keywordtype}{real}, \textcolor{keywordtype}{dimension(SZI\_(G),SZJB\_(G),Nangle)} :: &
1460     fdt\_m, fdt\_p\textcolor{comment}{! South and north energy fluxes [J]}
1461   \textcolor{keywordtype}{character(len=160)} :: mesg  \textcolor{comment}{! The text of an error message}
1462   \textcolor{keywordtype}{integer} :: i, j, k, ish, ieh, jsh, jeh, a
1463 
1464   ish = lb%ish ; ieh = lb%ieh ; jsh = lb%jsh ; jeh = lb%jeh
1465   \textcolor{keywordflow}{do} a=1,nangle
1466     \textcolor{comment}{! This sets EnL and EnR.}
1467     \textcolor{keywordflow}{if} (cs%upwind\_1st) \textcolor{keywordflow}{then}
1468       \textcolor{keywordflow}{do} j=jsh-1,jeh+1 ; \textcolor{keywordflow}{do} i=ish,ieh
1469         enl(i,j) = en(i,j,a) ; enr(i,j) = en(i,j,a)
1470 \textcolor{keywordflow}{      enddo} ;\textcolor{keywordflow}{ enddo}
1471     \textcolor{keywordflow}{else}
1472       \textcolor{keyword}{call }ppm\_reconstruction\_y(en(:,:,a), enl, enr, g, lb, simple\_2nd=cs%simple\_2nd)
1473 \textcolor{keywordflow}{    endif}
1474 
1475     \textcolor{keywordflow}{do} j=jsh-1,jeh
1476       \textcolor{comment}{!   This is done once with single speed (GARDEN SPRINKLER EFFECT POSSIBLE)}
1477       \textcolor{keywordflow}{do} i=ish,ieh
1478         cg\_p(i) = speed\_y(i,j) * (cgy\_av(a))
1479 \textcolor{keywordflow}{      enddo}
1480       \textcolor{keyword}{call }merid\_flux\_en(cg\_p, en(:,:,a), enl(:,:), enr(:,:), flux1, &
1481                          dt, g, us, j, ish, ieh, cs%vol\_CFL)
1482       \textcolor{keywordflow}{do} i=ish,ieh ; flux\_y(i,j) = flux1(i);\textcolor{keywordflow}{ enddo}
1483 \textcolor{keywordflow}{    enddo}
1484 
1485     \textcolor{keywordflow}{do} j=jsh,jeh ; \textcolor{keywordflow}{do} i=ish,ieh
1486       fdt\_m(i,j,a) = dt*flux\_y(i,j-1) \textcolor{comment}{! south face influx (J)}
1487       fdt\_p(i,j,a) = -dt*flux\_y(i,j)  \textcolor{comment}{! north face influx (J)}
1488       \textcolor{comment}{!if ((En(i,j,a) + G%IareaT(i,j)*(Fdt\_m(i,j,a) + Fdt\_p(i,j,a))) < 0.0) then ! for debugging}
1489       \textcolor{comment}{!  call MOM\_error(WARNING, "propagate\_y: OutFlux>Available prior to reflection", .true.)}
1490       \textcolor{comment}{!  write(mesg,*) "flux\_y\_south=",flux\_y(i,J-1),"flux\_y\_north=",flux\_y(i,J),"En=",En(i,j,a), &}
1491       \textcolor{comment}{!           "cn\_south=", speed\_y(i,J-1) * (Cgy\_av(a)), "cn\_north=", speed\_y(i,J) * (Cgy\_av(a))}
1492       \textcolor{comment}{!  call MOM\_error(WARNING, mesg, .true.)}
1493       \textcolor{comment}{!endif}
1494 \textcolor{keywordflow}{    enddo} ;\textcolor{keywordflow}{ enddo}
1495 
1496 \textcolor{keywordflow}{  enddo} \textcolor{comment}{! a-loop}
1497 
1498   \textcolor{comment}{! Only reflect newly arrived energy; existing energy in incident wedge is not reflected}
1499   \textcolor{comment}{! and will eventually propagate out of cell. (This code only reflects if En > 0.)}
1500   \textcolor{keyword}{call }reflect(fdt\_m, nangle, cs, g, lb)
1501   \textcolor{keyword}{call }teleport(fdt\_m, nangle, cs, g, lb)
1502   \textcolor{keyword}{call }reflect(fdt\_p, nangle, cs, g, lb)
1503   \textcolor{keyword}{call }teleport(fdt\_p, nangle, cs, g, lb)
1504 
1505   \textcolor{comment}{! Update reflected energy [R Z3 T-2 ~> J m-2]}
1506   \textcolor{keywordflow}{do} a=1,nangle ; \textcolor{keywordflow}{do} j=jsh,jeh ; \textcolor{keywordflow}{do} i=ish,ieh
1507     \textcolor{comment}{!  if ((En(i,j,a) + G%IareaT(i,j)*(Fdt\_m(i,j,a) + Fdt\_p(i,j,a))) < 0.0) & ! for debugging}
1508     \textcolor{comment}{!    call MOM\_error(FATAL, "propagate\_y: OutFlux>Available", .true.)}
1509     en(i,j,a) = en(i,j,a) + g%IareaT(i,j)*(fdt\_m(i,j,a) + fdt\_p(i,j,a))
1510 \textcolor{keywordflow}{  enddo} ;\textcolor{keywordflow}{ enddo} ;\textcolor{keywordflow}{ enddo}
1511 
\end{DoxyCode}
\mbox{\Hypertarget{namespacemom__internal__tides_a6c622bfe3863b8fcea98c78104477491}\label{namespacemom__internal__tides_a6c622bfe3863b8fcea98c78104477491}} 
\index{mom\+\_\+internal\+\_\+tides@{mom\+\_\+internal\+\_\+tides}!reflect@{reflect}}
\index{reflect@{reflect}!mom\+\_\+internal\+\_\+tides@{mom\+\_\+internal\+\_\+tides}}
\subsubsection{\texorpdfstring{reflect()}{reflect()}}
{\footnotesize\ttfamily subroutine mom\+\_\+internal\+\_\+tides\+::reflect (\begin{DoxyParamCaption}\item[{real, dimension(g\%isd\+:g\%ied,g\%jsd\+:g\%jed,nangle), intent(inout)}]{En,  }\item[{integer, intent(in)}]{N\+Angle,  }\item[{type(\hyperlink{structmom__internal__tides_1_1int__tide__cs}{int\+\_\+tide\+\_\+cs}), pointer}]{CS,  }\item[{type(ocean\+\_\+grid\+\_\+type), intent(in)}]{G,  }\item[{type(\hyperlink{structmom__internal__tides_1_1loop__bounds__type}{loop\+\_\+bounds\+\_\+type}), intent(in)}]{LB }\end{DoxyParamCaption})\hspace{0.3cm}{\ttfamily [private]}}



Reflection of the internal waves at a single frequency. 


\begin{DoxyParams}[1]{Parameters}
\mbox{\tt in}  & {\em g} & The ocean\textquotesingle{}s grid structure\\
\hline
\mbox{\tt in}  & {\em nangle} & The number of wave orientations in the discretized wave energy spectrum.\\
\hline
\mbox{\tt in,out}  & {\em en} & The internal gravity wave energy density as a\\
\hline
 & {\em cs} & The control structure returned by a previous call to int\+\_\+tide\+\_\+init.\\
\hline
\mbox{\tt in}  & {\em lb} & A structure with the active energy loop bounds. \\
\hline
\end{DoxyParams}


Definition at line 1602 of file M\+O\+M\+\_\+internal\+\_\+tides.\+F90.


\begin{DoxyCode}
1602   \textcolor{keywordtype}{type}(ocean\_grid\_type),  \textcolor{keywordtype}{intent(in)}    :: g\textcolor{comment}{  !< The ocean's grid structure}
1603   \textcolor{keywordtype}{integer},                \textcolor{keywordtype}{intent(in)}    :: nangle\textcolor{comment}{ !< The number of wave orientations in the}
1604 \textcolor{comment}{                                              !! discretized wave energy spectrum.}
1605   \textcolor{keywordtype}{real}, \textcolor{keywordtype}{dimension(G%isd:G%ied,G%jsd:G%jed,NAngle)}, &
1606                           \textcolor{keywordtype}{intent(inout)} :: en\textcolor{comment}{ !< The internal gravity wave energy density as a}
1607 \textcolor{comment}{                                              !! function of space and angular resolution}
1608 \textcolor{comment}{                                              !! [R Z3 T-2 ~> J m-2].}
1609   \textcolor{keywordtype}{type}(int\_tide\_cs),      \textcolor{keywordtype}{pointer}       :: cs\textcolor{comment}{ !< The control structure returned by a}
1610 \textcolor{comment}{                                              !! previous call to int\_tide\_init.}
1611   \textcolor{keywordtype}{type}(loop\_bounds\_type), \textcolor{keywordtype}{intent(in)}    :: lb\textcolor{comment}{ !< A structure with the active energy loop bounds.}
1612   \textcolor{comment}{! Local variables}
1613   \textcolor{keywordtype}{real}, \textcolor{keywordtype}{dimension(G%isd:G%ied,G%jsd:G%jed)} :: angle\_c
1614                                            \textcolor{comment}{! angle of boundary wrt equator [rad]}
1615   \textcolor{keywordtype}{real}, \textcolor{keywordtype}{dimension(G%isd:G%ied,G%jsd:G%jed)} :: part\_refl
1616                                            \textcolor{comment}{! fraction of wave energy reflected}
1617                                            \textcolor{comment}{! values should collocate with angle\_c [nondim]}
1618   \textcolor{keywordtype}{logical}, \textcolor{keywordtype}{dimension(G%isd:G%ied,G%jsd:G%jed)} :: ridge
1619                                            \textcolor{comment}{! tags of cells with double reflection}
1620 
1621   \textcolor{keywordtype}{real}    :: twopi                         \textcolor{comment}{! 2*pi = 6.2831853... [nondim]}
1622   \textcolor{keywordtype}{real}    :: angle\_size                    \textcolor{comment}{! size of beam wedge [rad]}
1623   \textcolor{keywordtype}{real}    :: angle\_wall                    \textcolor{comment}{! angle of coast/ridge/shelf wrt equator [rad]}
1624   \textcolor{keywordtype}{real}, \textcolor{keywordtype}{dimension(1:NAngle)} :: angle\_i     \textcolor{comment}{! angle of incident ray wrt equator [rad]}
1625   \textcolor{keywordtype}{real}    :: angle\_r                       \textcolor{comment}{! angle of reflected ray wrt equator [rad]}
1626   \textcolor{keywordtype}{real}, \textcolor{keywordtype}{dimension(1:Nangle)} :: en\_reflected
1627   \textcolor{keywordtype}{integer} :: i, j, a, a\_r, na
1628   \textcolor{comment}{!integer :: isd, ied, jsd, jed   ! start and end local indices on data domain}
1629   \textcolor{comment}{!                                ! (values include halos)}
1630   \textcolor{keywordtype}{integer} :: isc, iec, jsc, jec   \textcolor{comment}{! start and end local indices on PE}
1631                                   \textcolor{comment}{! (values exclude halos)}
1632   \textcolor{keywordtype}{integer} :: ish, ieh, jsh, jeh   \textcolor{comment}{! start and end local indices on data domain}
1633                                   \textcolor{comment}{! leaving out outdated halo points (march in)}
1634 
1635   \textcolor{comment}{!isd = G%isd  ; ied = G%ied  ; jsd = G%jsd  ; jed = G%jed}
1636   isc = g%isc  ; iec = g%iec  ; jsc = g%jsc  ; jec = g%jec
1637   ish = lb%ish ; ieh = lb%ieh ; jsh = lb%jsh ; jeh = lb%jeh
1638 
1639   twopi = 8.0*atan(1.0)
1640   angle\_size = twopi / (\textcolor{keywordtype}{real}(nangle))
1641 
1642   \textcolor{keywordflow}{do} a=1,nangle
1643     \textcolor{comment}{! These are the angles at the cell centers}
1644     \textcolor{comment}{! (should do this elsewhere since doesn't change with time)}
1645     angle\_i(a) = angle\_size * \textcolor{keywordtype}{real(a - 1)} \textcolor{comment}{! for a=1 aligned with x-axis}
1646 \textcolor{keywordflow}{  enddo}
1647 
1648   angle\_c   = cs%refl\_angle
1649   part\_refl = cs%refl\_pref
1650   ridge     = cs%refl\_dbl
1651   en\_reflected(:) = 0.0
1652 
1653   \textcolor{keywordflow}{do} j=jsh,jeh ; \textcolor{keywordflow}{do} i=ish,ieh
1654     \textcolor{comment}{! redistribute energy in angular space if ray will hit boundary}
1655     \textcolor{comment}{! i.e., if energy is in a reflecting cell}
1656     \textcolor{keywordflow}{if} (angle\_c(i,j) /= cs%nullangle) \textcolor{keywordflow}{then}
1657       \textcolor{keywordflow}{do} a=1,nangle ; \textcolor{keywordflow}{if} (en(i,j,a) > 0.0) \textcolor{keywordflow}{then}
1658         \textcolor{keywordflow}{if} (sin(angle\_i(a) - angle\_c(i,j)) >= 0.0) \textcolor{keywordflow}{then}
1659           \textcolor{comment}{! if ray is incident, keep specified boundary angle}
1660           angle\_wall = angle\_c(i,j)
1661         \textcolor{keywordflow}{elseif} (ridge(i,j)) \textcolor{keywordflow}{then}
1662          \textcolor{comment}{! if ray is not incident but in ridge cell, use complementary angle}
1663          angle\_wall = angle\_c(i,j) + 0.5*twopi
1664           \textcolor{keywordflow}{if} (angle\_wall > twopi) \textcolor{keywordflow}{then}
1665             angle\_wall = angle\_wall - twopi*floor(abs(angle\_wall)/twopi)
1666           \textcolor{keywordflow}{elseif} (angle\_wall < 0.0) \textcolor{keywordflow}{then}
1667             angle\_wall = angle\_wall + twopi*ceiling(abs(angle\_wall)/twopi)
1668 \textcolor{keywordflow}{          endif}
1669         \textcolor{keywordflow}{else}
1670           \textcolor{comment}{! if ray is not incident and not in a ridge cell, keep specified angle}
1671           angle\_wall = angle\_c(i,j)
1672 \textcolor{keywordflow}{        endif}
1673 
1674         \textcolor{comment}{! do reflection}
1675         \textcolor{keywordflow}{if} (sin(angle\_i(a) - angle\_wall) >= 0.0) \textcolor{keywordflow}{then}
1676           angle\_r = 2.0*angle\_wall - angle\_i(a)
1677           \textcolor{keywordflow}{if} (angle\_r > twopi) \textcolor{keywordflow}{then}
1678             angle\_r = angle\_r - twopi*floor(abs(angle\_r)/twopi)
1679           \textcolor{keywordflow}{elseif} (angle\_r < 0.0) \textcolor{keywordflow}{then}
1680             angle\_r = angle\_r + twopi*ceiling(abs(angle\_r)/twopi)
1681 \textcolor{keywordflow}{          endif}
1682           a\_r = nint(angle\_r/angle\_size) + 1
1683           \textcolor{keywordflow}{do} \textcolor{keywordflow}{while} (a\_r > nangle) ; a\_r = a\_r - nangle ;\textcolor{keywordflow}{ enddo}
1684           \textcolor{keywordflow}{if} (a /= a\_r) \textcolor{keywordflow}{then}
1685             en\_reflected(a\_r) = part\_refl(i,j)*en(i,j,a)
1686             en(i,j,a)   = (1.0-part\_refl(i,j))*en(i,j,a)
1687 \textcolor{keywordflow}{          endif}
1688 \textcolor{keywordflow}{        endif}
1689 \textcolor{keywordflow}{      endif} ;\textcolor{keywordflow}{ enddo} \textcolor{comment}{! a-loop}
1690       \textcolor{keywordflow}{do} a=1,nangle
1691         en(i,j,a) = en(i,j,a) + en\_reflected(a)
1692         en\_reflected(a) = 0.0
1693 \textcolor{keywordflow}{      enddo} \textcolor{comment}{! a-loop}
1694 \textcolor{keywordflow}{    endif}
1695 \textcolor{keywordflow}{  enddo} ;\textcolor{keywordflow}{ enddo} \textcolor{comment}{! i- and j-loops}
1696 
1697   \textcolor{comment}{! Check to make sure no energy gets onto land (only run for debugging)}
1698   \textcolor{comment}{! do a=1,NAngle ; do j=jsc,jec ; do i=isc,iec}
1699   \textcolor{comment}{!   if (En(i,j,a) > 0.001 .and. G%mask2dT(i,j) == 0) then}
1700   \textcolor{comment}{!     write (mesg,*) 'En=', En(i,j,a), 'a=', a, 'ig\_g=',i+G%idg\_offset, 'jg\_g=',j+G%jdg\_offset}
1701   \textcolor{comment}{!     call MOM\_error(FATAL, "reflect: Energy detected out of bounds: "//trim(mesg), .true.)}
1702   \textcolor{comment}{!   endif}
1703   \textcolor{comment}{! enddo ; enddo ; enddo}
1704 
\end{DoxyCode}
\mbox{\Hypertarget{namespacemom__internal__tides_a0814f61fee53f0941061056641132493}\label{namespacemom__internal__tides_a0814f61fee53f0941061056641132493}} 
\index{mom\+\_\+internal\+\_\+tides@{mom\+\_\+internal\+\_\+tides}!refract@{refract}}
\index{refract@{refract}!mom\+\_\+internal\+\_\+tides@{mom\+\_\+internal\+\_\+tides}}
\subsubsection{\texorpdfstring{refract()}{refract()}}
{\footnotesize\ttfamily subroutine mom\+\_\+internal\+\_\+tides\+::refract (\begin{DoxyParamCaption}\item[{real, dimension(g\%isd\+:g\%ied,g\%jsd\+:g\%jed,nangle), intent(inout)}]{En,  }\item[{real, dimension(g\%isd\+:g\%ied,g\%jsd\+:g\%jed), intent(in)}]{cn,  }\item[{real, intent(in)}]{freq,  }\item[{real, intent(in)}]{dt,  }\item[{type(ocean\+\_\+grid\+\_\+type), intent(in)}]{G,  }\item[{type(unit\+\_\+scale\+\_\+type), intent(in)}]{US,  }\item[{integer, intent(in)}]{N\+Angle,  }\item[{logical, intent(in)}]{use\+\_\+\+P\+P\+Mang }\end{DoxyParamCaption})\hspace{0.3cm}{\ttfamily [private]}}



Implements refraction on the internal waves at a single frequency. 


\begin{DoxyParams}[1]{Parameters}
\mbox{\tt in}  & {\em g} & The ocean\textquotesingle{}s grid structure.\\
\hline
\mbox{\tt in}  & {\em nangle} & The number of wave orientations in the discretized wave energy spectrum.\\
\hline
\mbox{\tt in,out}  & {\em en} & The internal gravity wave energy density as a\\
\hline
\mbox{\tt in}  & {\em cn} & Baroclinic mode speed \mbox{[}L T-\/1 $\sim$$>$ m s-\/1\mbox{]}.\\
\hline
\mbox{\tt in}  & {\em freq} & Wave frequency \mbox{[}T-\/1 $\sim$$>$ s-\/1\mbox{]}.\\
\hline
\mbox{\tt in}  & {\em dt} & Time step \mbox{[}T $\sim$$>$ s\mbox{]}.\\
\hline
\mbox{\tt in}  & {\em us} & A dimensional unit scaling type\\
\hline
\mbox{\tt in}  & {\em use\+\_\+ppmang} & If true, use P\+PM for advection rather than upwind. \\
\hline
\end{DoxyParams}


Definition at line 746 of file M\+O\+M\+\_\+internal\+\_\+tides.\+F90.


\begin{DoxyCode}
746   \textcolor{keywordtype}{type}(ocean\_grid\_type), \textcolor{keywordtype}{intent(in)}    :: g\textcolor{comment}{    !< The ocean's grid structure.}
747   \textcolor{keywordtype}{integer},               \textcolor{keywordtype}{intent(in)}    :: nangle\textcolor{comment}{ !< The number of wave orientations in the}
748 \textcolor{comment}{                                               !! discretized wave energy spectrum.}
749   \textcolor{keywordtype}{real}, \textcolor{keywordtype}{dimension(G%isd:G%ied,G%jsd:G%jed,NAngle)}, &
750                          \textcolor{keywordtype}{intent(inout)} :: en\textcolor{comment}{   !< The internal gravity wave energy density as a}
751 \textcolor{comment}{                                               !! function of space and angular resolution,}
752 \textcolor{comment}{                                               !! [R Z3 T-2 ~> J m-2].}
753   \textcolor{keywordtype}{real}, \textcolor{keywordtype}{dimension(G%isd:G%ied,G%jsd:G%jed)},        &
754                          \textcolor{keywordtype}{intent(in)}    :: cn\textcolor{comment}{   !< Baroclinic mode speed [L T-1 ~> m s-1].}
755   \textcolor{keywordtype}{real},                  \textcolor{keywordtype}{intent(in)}    :: freq\textcolor{comment}{ !< Wave frequency [T-1 ~> s-1].}
756   \textcolor{keywordtype}{real},                  \textcolor{keywordtype}{intent(in)}    :: dt\textcolor{comment}{   !< Time step [T ~> s].}
757   \textcolor{keywordtype}{type}(unit\_scale\_type), \textcolor{keywordtype}{intent(in)}    :: us\textcolor{comment}{   !< A dimensional unit scaling type}
758   \textcolor{keywordtype}{logical},               \textcolor{keywordtype}{intent(in)}    :: use\_ppmang\textcolor{comment}{ !< If true, use PPM for advection rather}
759 \textcolor{comment}{                                               !! than upwind.}
760   \textcolor{comment}{! Local variables}
761   \textcolor{keywordtype}{integer}, \textcolor{keywordtype}{parameter} :: stencil = 2
762   \textcolor{keywordtype}{real}, \textcolor{keywordtype}{dimension(SZI\_(G),1-stencil:NAngle+stencil)} :: &
763     en2d
764   \textcolor{keywordtype}{real}, \textcolor{keywordtype}{dimension(1-stencil:NAngle+stencil)} :: &
765     cos\_angle, sin\_angle
766   \textcolor{keywordtype}{real}, \textcolor{keywordtype}{dimension(SZI\_(G))} :: &
767     dk\_dt\_kmag, dl\_dt\_kmag
768   \textcolor{keywordtype}{real}, \textcolor{keywordtype}{dimension(SZI\_(G),0:nAngle)} :: &
769     flux\_e
770   \textcolor{keywordtype}{real}, \textcolor{keywordtype}{dimension(SZI\_(G),SZJ\_(G),1-stencil:NAngle+stencil)} :: &
771     cfl\_ang
772   \textcolor{keywordtype}{real} :: f2              \textcolor{comment}{! The squared Coriolis parameter [T-2 ~> s-2].}
773   \textcolor{keywordtype}{real} :: favg            \textcolor{comment}{! The average Coriolis parameter at a point [T-1 ~> s-1].}
774   \textcolor{keywordtype}{real} :: df\_dy, df\_dx    \textcolor{comment}{! The x- and y- gradients of the Coriolis parameter [T-1 L-1 ~> s-1 m-1].}
775   \textcolor{keywordtype}{real} :: dlncn\_dx        \textcolor{comment}{! The x-gradient of the wave speed divided by itself [L-1 ~> m-1].}
776   \textcolor{keywordtype}{real} :: dlncn\_dy        \textcolor{comment}{! The y-gradient of the wave speed divided by itself [L-1 ~> m-1].}
777   \textcolor{keywordtype}{real} :: angle\_size, dt\_angle\_size, angle
778   \textcolor{keywordtype}{real} :: ifreq, kmag2, i\_kmag
779   \textcolor{keywordtype}{real} :: cn\_subro        \textcolor{comment}{! A tiny wave speed to prevent division by zero [L T-1 ~> m s-1]}
780   \textcolor{keywordtype}{integer} :: is, ie, js, je, asd, aed, na
781   \textcolor{keywordtype}{integer} :: i, j, a
782 
783   is = g%isc ; ie = g%iec ; js = g%jsc ; je = g%jec ; na = \textcolor{keyword}{size}(en,3)
784   asd = 1-stencil ; aed = nangle+stencil
785 
786   ifreq = 1.0 / freq
787   cn\_subro = 1e-100*us%m\_s\_to\_L\_T  \textcolor{comment}{! The hard-coded value here might need to increase.}
788   angle\_size = (8.0*atan(1.0)) / (\textcolor{keywordtype}{real}(nangle))
789   dt\_angle\_size = dt / angle\_size
790 
791   \textcolor{keywordflow}{do} a=asd,aed
792     angle = (\textcolor{keywordtype}{real(A)} - 0.5) * angle\_size
793     cos\_angle(a) = cos(angle) ; sin\_angle(a) = sin(angle)
794 \textcolor{keywordflow}{  enddo}
795 
796   \textcolor{comment}{!### There should also be refraction due to cn.grad(grid\_orientation).}
797   cfl\_ang(:,:,:) = 0.0
798   \textcolor{keywordflow}{do} j=js,je
799   \textcolor{comment}{! Copy En into angle space with halos.}
800     \textcolor{keywordflow}{do} a=1,na ; \textcolor{keywordflow}{do} i=is,ie
801       en2d(i,a) = en(i,j,a)
802 \textcolor{keywordflow}{    enddo} ;\textcolor{keywordflow}{ enddo}
803     \textcolor{keywordflow}{do} a=asd,0 ; \textcolor{keywordflow}{do} i=is,ie
804       en2d(i,a) = en2d(i,a+nangle)
805       en2d(i,nangle+stencil+a) = en2d(i,stencil+a)
806 \textcolor{keywordflow}{    enddo} ;\textcolor{keywordflow}{ enddo}
807 
808   \textcolor{comment}{! Do the refraction.}
809     \textcolor{keywordflow}{do} i=is,ie
810       f2 = 0.25* ((g%CoriolisBu(i,j)**2 + g%CoriolisBu(i-1,j-1)**2) + &
811                  (g%CoriolisBu(i,j-1)**2 + g%CoriolisBu(i-1,j)**2))
812       favg = 0.25*((g%CoriolisBu(i,j) + g%CoriolisBu(i-1,j-1)) + &
813                    (g%CoriolisBu(i,j-1) + g%CoriolisBu(i-1,j)))
814       df\_dx = 0.5*((g%CoriolisBu(i,j) + g%CoriolisBu(i,j-1)) - &
815                     (g%CoriolisBu(i-1,j) + g%CoriolisBu(i-1,j-1))) * g%IdxT(i,j)
816       dlncn\_dx = 0.5*( g%IdxCu(i,j) * (cn(i+1,j) - cn(i,j)) / &
817                        (0.5*(cn(i+1,j) + cn(i,j)) + cn\_subro) + &
818                        g%IdxCu(i-1,j) * (cn(i,j) - cn(i-1,j)) / &
819                        (0.5*(cn(i,j) + cn(i-1,j)) + cn\_subro) )
820       df\_dy = 0.5*((g%CoriolisBu(i,j) + g%CoriolisBu(i-1,j)) - &
821                    (g%CoriolisBu(i,j-1) + g%CoriolisBu(i-1,j-1))) * g%IdyT(i,j)
822       dlncn\_dy = 0.5*( g%IdyCv(i,j) * (cn(i,j+1) - cn(i,j)) / &
823                        (0.5*(cn(i,j+1) + cn(i,j)) + cn\_subro) + &
824                        g%IdyCv(i,j-1) * (cn(i,j) - cn(i,j-1)) / &
825                        (0.5*(cn(i,j) + cn(i,j-1)) + cn\_subro) )
826       kmag2 = (freq**2 - f2) / (cn(i,j)**2 + cn\_subro**2)
827       \textcolor{keywordflow}{if} (kmag2 > 0.0) \textcolor{keywordflow}{then}
828         i\_kmag = 1.0 / sqrt(kmag2)
829         dk\_dt\_kmag(i) = -ifreq * (favg*df\_dx + (freq**2 - f2) * dlncn\_dx) * i\_kmag
830         dl\_dt\_kmag(i) = -ifreq * (favg*df\_dy + (freq**2 - f2) * dlncn\_dy) * i\_kmag
831       \textcolor{keywordflow}{else}
832         dk\_dt\_kmag(i) = 0.0
833         dl\_dt\_kmag(i) = 0.0
834 \textcolor{keywordflow}{      endif}
835 \textcolor{keywordflow}{    enddo}
836 
837     \textcolor{comment}{! Determine the energy fluxes in angular orientation space.}
838     \textcolor{keywordflow}{do} a=asd,aed ; \textcolor{keywordflow}{do} i=is,ie
839       cfl\_ang(i,j,a) = (cos\_angle(a) * dl\_dt\_kmag(i) - sin\_angle(a) * dk\_dt\_kmag(i)) * dt\_angle\_size
840       \textcolor{keywordflow}{if} (abs(cfl\_ang(i,j,a)) > 1.0) \textcolor{keywordflow}{then}
841         \textcolor{keyword}{call }mom\_error(warning, \textcolor{stringliteral}{"refract: CFL exceeds 1."}, .true.)
842         \textcolor{keywordflow}{if} (cfl\_ang(i,j,a) > 0.0) \textcolor{keywordflow}{then} ; cfl\_ang(i,j,a) = 1.0 ; \textcolor{keywordflow}{else} ; cfl\_ang(i,j,a) = -1.0 ;\textcolor{keywordflow}{ endif}
843 \textcolor{keywordflow}{      endif}
844 \textcolor{keywordflow}{    enddo} ;\textcolor{keywordflow}{ enddo}
845 
846     \textcolor{comment}{! Advect in angular space}
847     \textcolor{keywordflow}{if} (.not.use\_ppmang) \textcolor{keywordflow}{then}
848       \textcolor{comment}{! Use simple upwind}
849       \textcolor{keywordflow}{do}  a=0,na ; \textcolor{keywordflow}{do} i=is,ie
850         \textcolor{keywordflow}{if} (cfl\_ang(i,j,a) > 0.0) \textcolor{keywordflow}{then}
851           flux\_e(i,a) = cfl\_ang(i,j,a) * en2d(i,a)
852         \textcolor{keywordflow}{else}
853           flux\_e(i,a) = cfl\_ang(i,j,a) * en2d(i,a+1)
854 \textcolor{keywordflow}{        endif}
855 \textcolor{keywordflow}{      enddo} ;\textcolor{keywordflow}{ enddo}
856     \textcolor{keywordflow}{else}
857       \textcolor{comment}{! Use PPM}
858       \textcolor{keywordflow}{do} i=is,ie
859         \textcolor{keyword}{call }ppm\_angular\_advect(en2d(i,:),cfl\_ang(i,j,:),flux\_e(i,:),nangle,dt,stencil)
860 \textcolor{keywordflow}{      enddo}
861 \textcolor{keywordflow}{    endif}
862 
863   \textcolor{comment}{! Update and copy back to En.}
864     \textcolor{keywordflow}{do} a=1,na ; \textcolor{keywordflow}{do} i=is,ie
865       \textcolor{comment}{!if (En2d(i,a)+(Flux\_E(i,A-1)-Flux\_E(i,A)) < 0.0) then ! for debugging}
866       \textcolor{comment}{!  call MOM\_error(FATAL, "refract: OutFlux>Available")}
867       \textcolor{comment}{!endif}
868       en(i,j,a) = en2d(i,a) + (flux\_e(i,a-1) - flux\_e(i,a))
869 \textcolor{keywordflow}{    enddo} ;\textcolor{keywordflow}{ enddo}
870 \textcolor{keywordflow}{  enddo} \textcolor{comment}{! j-loop}
\end{DoxyCode}
\mbox{\Hypertarget{namespacemom__internal__tides_a9e8e7b153aef9049c2217658821e3178}\label{namespacemom__internal__tides_a9e8e7b153aef9049c2217658821e3178}} 
\index{mom\+\_\+internal\+\_\+tides@{mom\+\_\+internal\+\_\+tides}!sum\+\_\+en@{sum\+\_\+en}}
\index{sum\+\_\+en@{sum\+\_\+en}!mom\+\_\+internal\+\_\+tides@{mom\+\_\+internal\+\_\+tides}}
\subsubsection{\texorpdfstring{sum\+\_\+en()}{sum\_en()}}
{\footnotesize\ttfamily subroutine mom\+\_\+internal\+\_\+tides\+::sum\+\_\+en (\begin{DoxyParamCaption}\item[{type(ocean\+\_\+grid\+\_\+type), intent(in)}]{G,  }\item[{type(\hyperlink{structmom__internal__tides_1_1int__tide__cs}{int\+\_\+tide\+\_\+cs}), pointer}]{CS,  }\item[{real, dimension(g\%isd\+:g\%ied,g\%jsd\+:g\%jed,cs\%nangle), intent(in)}]{En,  }\item[{character(len=$\ast$), intent(in)}]{label }\end{DoxyParamCaption})\hspace{0.3cm}{\ttfamily [private]}}



Checks for energy conservation on computational domain. 


\begin{DoxyParams}[1]{Parameters}
\mbox{\tt in}  & {\em g} & The ocean\textquotesingle{}s grid structure.\\
\hline
 & {\em cs} & The control structure returned by a previous call to int\+\_\+tide\+\_\+init.\\
\hline
\mbox{\tt in}  & {\em en} & The energy density of the internal tides \mbox{[}R Z3 T-\/2 $\sim$$>$ J m-\/2\mbox{]}.\\
\hline
\mbox{\tt in}  & {\em label} & A label to use in error messages \\
\hline
\end{DoxyParams}


Definition at line 594 of file M\+O\+M\+\_\+internal\+\_\+tides.\+F90.


\begin{DoxyCode}
594   \textcolor{keywordtype}{type}(ocean\_grid\_type),  \textcolor{keywordtype}{intent(in)} :: g\textcolor{comment}{  !< The ocean's grid structure.}
595   \textcolor{keywordtype}{type}(int\_tide\_cs),      \textcolor{keywordtype}{pointer}    :: cs\textcolor{comment}{ !< The control structure returned by a}
596 \textcolor{comment}{                                           !! previous call to int\_tide\_init.}
597   \textcolor{keywordtype}{real}, \textcolor{keywordtype}{dimension(G%isd:G%ied,G%jsd:G%jed,CS%NAngle)}, &
598                           \textcolor{keywordtype}{intent(in)} :: en\textcolor{comment}{ !< The energy density of the internal tides [R Z3 T-2 ~> J m-2].}
599   \textcolor{keywordtype}{character(len=*)},       \textcolor{keywordtype}{intent(in)} :: label\textcolor{comment}{ !< A label to use in error messages}
600   \textcolor{comment}{! Local variables}
601   \textcolor{keywordtype}{real} :: en\_sum   \textcolor{comment}{! The total energy [R Z3 T-2 ~> J m-2]}
602   \textcolor{keywordtype}{real} :: tmpforsumming
603   \textcolor{keywordtype}{integer} :: m,fr,a
604   \textcolor{comment}{! real :: En\_sum\_diff, En\_sum\_pdiff}
605   \textcolor{comment}{! character(len=160) :: mesg  ! The text of an error message}
606   \textcolor{comment}{! real :: days}
607 
608   en\_sum = 0.0
609   tmpforsumming = 0.0
610   \textcolor{keywordflow}{do} a=1,cs%nAngle
611     tmpforsumming = global\_area\_mean(en(:,:,a),g)*g%areaT\_global
612     en\_sum = en\_sum + tmpforsumming
613 \textcolor{keywordflow}{  enddo}
614   cs%En\_sum = en\_sum
615   \textcolor{comment}{!En\_sum\_diff = En\_sum - CS%En\_sum}
616   \textcolor{comment}{!if (CS%En\_sum /= 0.0) then}
617   \textcolor{comment}{!  En\_sum\_pdiff= (En\_sum\_diff/CS%En\_sum)*100.0}
618   \textcolor{comment}{!else}
619   \textcolor{comment}{!  En\_sum\_pdiff= 0.0}
620   \textcolor{comment}{!endif}
621   \textcolor{comment}{!! Print to screen}
622   \textcolor{comment}{!if (is\_root\_pe()) then}
623   \textcolor{comment}{!  days = time\_type\_to\_real(CS%Time) / 86400.0}
624   \textcolor{comment}{!  write(mesg,*) trim(label)//': days =', days, ', En\_sum=', En\_sum, &}
625   \textcolor{comment}{!                ', En\_sum\_diff=', En\_sum\_diff, ', Percent change=', En\_sum\_pdiff, '%'}
626   \textcolor{comment}{!  call MOM\_mesg(mesg)}
627   \textcolor{comment}{!if (is\_root\_pe() .and. (abs(En\_sum\_pdiff) > 1.0)) &}
628   \textcolor{comment}{!  call MOM\_error(FATAL, "Run stopped due to excessive internal tide energy change.")}
629   \textcolor{comment}{!endif}
630 
\end{DoxyCode}
\mbox{\Hypertarget{namespacemom__internal__tides_a0a20d26531e245a26385d1c056b6a5b6}\label{namespacemom__internal__tides_a0a20d26531e245a26385d1c056b6a5b6}} 
\index{mom\+\_\+internal\+\_\+tides@{mom\+\_\+internal\+\_\+tides}!teleport@{teleport}}
\index{teleport@{teleport}!mom\+\_\+internal\+\_\+tides@{mom\+\_\+internal\+\_\+tides}}
\subsubsection{\texorpdfstring{teleport()}{teleport()}}
{\footnotesize\ttfamily subroutine mom\+\_\+internal\+\_\+tides\+::teleport (\begin{DoxyParamCaption}\item[{real, dimension(g\%isd\+:g\%ied,g\%jsd\+:g\%jed,nangle), intent(inout)}]{En,  }\item[{integer, intent(in)}]{N\+Angle,  }\item[{type(\hyperlink{structmom__internal__tides_1_1int__tide__cs}{int\+\_\+tide\+\_\+cs}), pointer}]{CS,  }\item[{type(ocean\+\_\+grid\+\_\+type), intent(in)}]{G,  }\item[{type(\hyperlink{structmom__internal__tides_1_1loop__bounds__type}{loop\+\_\+bounds\+\_\+type}), intent(in)}]{LB }\end{DoxyParamCaption})\hspace{0.3cm}{\ttfamily [private]}}



Moves energy across lines of partial reflection to prevent reflection of energy that is supposed to get across. 


\begin{DoxyParams}[1]{Parameters}
\mbox{\tt in}  & {\em g} & The ocean\textquotesingle{}s grid structure.\\
\hline
\mbox{\tt in}  & {\em nangle} & The number of wave orientations in the discretized wave energy spectrum.\\
\hline
\mbox{\tt in,out}  & {\em en} & The internal gravity wave energy density as a\\
\hline
 & {\em cs} & The control structure returned by a previous call to int\+\_\+tide\+\_\+init.\\
\hline
\mbox{\tt in}  & {\em lb} & A structure with the active energy loop bounds. \\
\hline
\end{DoxyParams}


Definition at line 1710 of file M\+O\+M\+\_\+internal\+\_\+tides.\+F90.


\begin{DoxyCode}
1710   \textcolor{keywordtype}{type}(ocean\_grid\_type),  \textcolor{keywordtype}{intent(in)}    :: g\textcolor{comment}{  !< The ocean's grid structure.}
1711   \textcolor{keywordtype}{integer},                \textcolor{keywordtype}{intent(in)}    :: nangle\textcolor{comment}{ !< The number of wave orientations in the}
1712 \textcolor{comment}{                                              !! discretized wave energy spectrum.}
1713   \textcolor{keywordtype}{real}, \textcolor{keywordtype}{dimension(G%isd:G%ied,G%jsd:G%jed,NAngle)}, &
1714                           \textcolor{keywordtype}{intent(inout)} :: en\textcolor{comment}{ !< The internal gravity wave energy density as a}
1715 \textcolor{comment}{                                              !! function of space and angular resolution}
1716 \textcolor{comment}{                                              !! [R Z3 T-2 ~> J m-2].}
1717   \textcolor{keywordtype}{type}(int\_tide\_cs),      \textcolor{keywordtype}{pointer}       :: cs\textcolor{comment}{ !< The control structure returned by a}
1718 \textcolor{comment}{                                              !! previous call to int\_tide\_init.}
1719   \textcolor{keywordtype}{type}(loop\_bounds\_type), \textcolor{keywordtype}{intent(in)}    :: lb\textcolor{comment}{ !< A structure with the active energy loop bounds.}
1720   \textcolor{comment}{! Local variables}
1721   \textcolor{keywordtype}{real}, \textcolor{keywordtype}{dimension(G%isd:G%ied,G%jsd:G%jed)}    :: angle\_c
1722                                               \textcolor{comment}{! angle of boundary wrt equator [rad]}
1723   \textcolor{keywordtype}{real}, \textcolor{keywordtype}{dimension(G%isd:G%ied,G%jsd:G%jed)}    :: part\_refl
1724                                               \textcolor{comment}{! fraction of wave energy reflected}
1725                                               \textcolor{comment}{! values should collocate with angle\_c [nondim]}
1726   \textcolor{keywordtype}{logical}, \textcolor{keywordtype}{dimension(G%isd:G%ied,G%jsd:G%jed)} :: pref\_cell
1727                                               \textcolor{comment}{! flag for partial reflection}
1728   \textcolor{keywordtype}{logical}, \textcolor{keywordtype}{dimension(G%isd:G%ied,G%jsd:G%jed)} :: ridge
1729                                               \textcolor{comment}{! tags of cells with double reflection}
1730   \textcolor{keywordtype}{real}                        :: twopi      \textcolor{comment}{! 2*pi = 6.2831853... [nondim]}
1731   \textcolor{keywordtype}{real}                        :: angle\_size \textcolor{comment}{! size of beam wedge [rad]}
1732   \textcolor{keywordtype}{real}, \textcolor{keywordtype}{dimension(1:NAngle)}   :: angle\_i    \textcolor{comment}{! angle of incident ray wrt equator [rad]}
1733   \textcolor{keywordtype}{real}, \textcolor{keywordtype}{dimension(1:NAngle)}   :: cos\_angle, sin\_angle
1734   \textcolor{keywordtype}{real}                        :: en\_tele    \textcolor{comment}{! energy to be "teleported" [R Z3 T-2 ~> J m-2]}
1735   \textcolor{keywordtype}{character(len=160)} :: mesg  \textcolor{comment}{! The text of an error message}
1736   \textcolor{keywordtype}{integer} :: i, j, a
1737   \textcolor{comment}{!integer :: isd, ied, jsd, jed    ! start and end local indices on data domain}
1738   \textcolor{comment}{!                                 ! (values include halos)}
1739   \textcolor{comment}{!integer :: isc, iec, jsc, jec    ! start and end local indices on PE}
1740   \textcolor{comment}{!                                 ! (values exclude halos)}
1741   \textcolor{keywordtype}{integer} :: ish, ieh, jsh, jeh     \textcolor{comment}{! start and end local indices on data domain}
1742                                     \textcolor{comment}{! leaving out outdated halo points (march in)}
1743   \textcolor{keywordtype}{integer} :: id\_g, jd\_g             \textcolor{comment}{! global (decomp-invar) indices}
1744   \textcolor{keywordtype}{integer} :: jos, ios               \textcolor{comment}{! offsets}
1745   \textcolor{keywordtype}{real}    :: cos\_normal, sin\_normal, angle\_wall
1746                                     \textcolor{comment}{! cos/sin of cross-ridge normal, ridge angle}
1747 
1748   \textcolor{comment}{!isd = G%isd  ; ied = G%ied  ; jsd = G%jsd  ; jed = G%jed}
1749   \textcolor{comment}{!isc = G%isc  ; iec = G%iec  ; jsc = G%jsc  ; jec = G%jec}
1750   ish = lb%ish ; ieh = lb%ieh ; jsh = lb%jsh ; jeh = lb%jeh
1751 
1752   twopi = 8.0*atan(1.0)
1753   angle\_size = twopi / (\textcolor{keywordtype}{real}(nangle))
1754 
1755   \textcolor{keywordflow}{do} a=1,nangle
1756     \textcolor{comment}{! These are the angles at the cell centers}
1757     \textcolor{comment}{! (should do this elsewhere since doesn't change with time)}
1758     angle\_i(a) = angle\_size * \textcolor{keywordtype}{real(a - 1)} \textcolor{comment}{! for a=1 aligned with x-axis}
1759     cos\_angle(a) = cos(angle\_i(a)) ; sin\_angle(a) = sin(angle\_i(a))
1760 \textcolor{keywordflow}{  enddo}
1761 
1762   angle\_c   = cs%refl\_angle
1763   part\_refl = cs%refl\_pref
1764   pref\_cell = cs%refl\_pref\_logical
1765   ridge     = cs%refl\_dbl
1766 
1767   \textcolor{keywordflow}{do} j=jsh,jeh
1768     \textcolor{keywordflow}{do} i=ish,ieh
1769       id\_g = i + g%idg\_offset ; jd\_g = j + g%jdg\_offset
1770       \textcolor{keywordflow}{if} (pref\_cell(i,j)) \textcolor{keywordflow}{then}
1771         \textcolor{keywordflow}{do} a=1,nangle
1772           \textcolor{keywordflow}{if} (en(i,j,a) > 0) \textcolor{keywordflow}{then}
1773             \textcolor{comment}{! if ray is incident, keep specified boundary angle}
1774             \textcolor{keywordflow}{if} (sin(angle\_i(a) - angle\_c(i,j)) >= 0.0) \textcolor{keywordflow}{then}
1775               angle\_wall = angle\_c(i,j)
1776             \textcolor{comment}{! if ray is not incident but in ridge cell, use complementary angle}
1777             \textcolor{keywordflow}{elseif} (ridge(i,j)) \textcolor{keywordflow}{then}
1778               angle\_wall = angle\_c(i,j) + 0.5*twopi
1779             \textcolor{comment}{! if ray is not incident and not in a ridge cell, keep specified angle}
1780             \textcolor{keywordflow}{else}
1781               angle\_wall = angle\_c(i,j)
1782 \textcolor{keywordflow}{            endif}
1783             \textcolor{comment}{! teleport if incident}
1784             \textcolor{keywordflow}{if} (sin(angle\_i(a) - angle\_wall) >= 0.0) \textcolor{keywordflow}{then}
1785               en\_tele = en(i,j,a)
1786               cos\_normal = cos(angle\_wall + 0.25*twopi)
1787               sin\_normal = sin(angle\_wall + 0.25*twopi)
1788               \textcolor{comment}{! find preferred zonal offset based on shelf/ridge angle}
1789               ios = int(sign(1.,cos\_normal))
1790               \textcolor{comment}{! find preferred meridional offset based on shelf/ridge angle}
1791               jos = int(sign(1.,sin\_normal))
1792               \textcolor{comment}{! find receptive ocean cell in direction of offset}
1793               \textcolor{keywordflow}{if} (.not. pref\_cell(i+ios,j+jos)) \textcolor{keywordflow}{then}
1794                 en(i,j,a) = en(i,j,a) - en\_tele
1795                 en(i+ios,j+jos,a) = en(i+ios,j+jos,a) + en\_tele
1796               \textcolor{keywordflow}{else}
1797                 \textcolor{keyword}{write}(mesg,*) \textcolor{stringliteral}{'idg='},id\_g,\textcolor{stringliteral}{'jd\_g='},jd\_g,\textcolor{stringliteral}{'a='},a
1798                 \textcolor{keyword}{call }mom\_error(fatal, \textcolor{stringliteral}{"teleport: no receptive ocean cell at "}//trim(mesg), .true.)
1799 \textcolor{keywordflow}{              endif}
1800 \textcolor{keywordflow}{            endif} \textcolor{comment}{! incidence check}
1801 \textcolor{keywordflow}{          endif} \textcolor{comment}{! energy check}
1802 \textcolor{keywordflow}{        enddo} \textcolor{comment}{! a-loop}
1803 \textcolor{keywordflow}{      endif} \textcolor{comment}{! pref check}
1804 \textcolor{keywordflow}{    enddo} \textcolor{comment}{! i-loop}
1805 \textcolor{keywordflow}{  enddo} \textcolor{comment}{! j-loop}
1806 
\end{DoxyCode}
\mbox{\Hypertarget{namespacemom__internal__tides_a5470c5a9a8fea70664dbf793c48cef65}\label{namespacemom__internal__tides_a5470c5a9a8fea70664dbf793c48cef65}} 
\index{mom\+\_\+internal\+\_\+tides@{mom\+\_\+internal\+\_\+tides}!zonal\+\_\+flux\+\_\+en@{zonal\+\_\+flux\+\_\+en}}
\index{zonal\+\_\+flux\+\_\+en@{zonal\+\_\+flux\+\_\+en}!mom\+\_\+internal\+\_\+tides@{mom\+\_\+internal\+\_\+tides}}
\subsubsection{\texorpdfstring{zonal\+\_\+flux\+\_\+en()}{zonal\_flux\_en()}}
{\footnotesize\ttfamily subroutine mom\+\_\+internal\+\_\+tides\+::zonal\+\_\+flux\+\_\+en (\begin{DoxyParamCaption}\item[{real, dimension(szib\+\_\+(g)), intent(in)}]{u,  }\item[{real, dimension(szi\+\_\+(g)), intent(in)}]{h,  }\item[{real, dimension(szi\+\_\+(g)), intent(in)}]{hL,  }\item[{real, dimension(szi\+\_\+(g)), intent(in)}]{hR,  }\item[{real, dimension(szib\+\_\+(g)), intent(inout)}]{uh,  }\item[{real, intent(in)}]{dt,  }\item[{type(ocean\+\_\+grid\+\_\+type), intent(in)}]{G,  }\item[{type(unit\+\_\+scale\+\_\+type), intent(in)}]{US,  }\item[{integer, intent(in)}]{j,  }\item[{integer, intent(in)}]{ish,  }\item[{integer, intent(in)}]{ieh,  }\item[{logical, intent(in)}]{vol\+\_\+\+C\+FL }\end{DoxyParamCaption})\hspace{0.3cm}{\ttfamily [private]}}



Evaluates the zonal mass or volume fluxes in a layer. 


\begin{DoxyParams}[1]{Parameters}
\mbox{\tt in}  & {\em g} & The ocean\textquotesingle{}s grid structure.\\
\hline
\mbox{\tt in}  & {\em u} & The zonal velocity \mbox{[}L T-\/1 $\sim$$>$ m s-\/1\mbox{]}.\\
\hline
\mbox{\tt in}  & {\em h} & Energy density used to calculate the fluxes \mbox{[}R Z3 T-\/2 $\sim$$>$ J m-\/2\mbox{]}.\\
\hline
\mbox{\tt in}  & {\em hl} & Left-\/ Energy densities in the reconstruction \mbox{[}R Z3 T-\/2 $\sim$$>$ J m-\/2\mbox{]}.\\
\hline
\mbox{\tt in}  & {\em hr} & Right-\/ Energy densities in the reconstruction \mbox{[}R Z3 T-\/2 $\sim$$>$ J m-\/2\mbox{]}.\\
\hline
\mbox{\tt in,out}  & {\em uh} & The zonal energy transport \mbox{[}R Z3 L2 T-\/3 $\sim$$>$ J s-\/1\mbox{]}.\\
\hline
\mbox{\tt in}  & {\em dt} & Time increment \mbox{[}T $\sim$$>$ s\mbox{]}.\\
\hline
\mbox{\tt in}  & {\em us} & A dimensional unit scaling type\\
\hline
\mbox{\tt in}  & {\em j} & The j-\/index to work on.\\
\hline
\mbox{\tt in}  & {\em ish} & The start i-\/index range to work on.\\
\hline
\mbox{\tt in}  & {\em ieh} & The end i-\/index range to work on.\\
\hline
\mbox{\tt in}  & {\em vol\+\_\+cfl} & If true, rescale the ratio of face areas to the cell areas when estimating the C\+FL number. \\
\hline
\end{DoxyParams}


Definition at line 1516 of file M\+O\+M\+\_\+internal\+\_\+tides.\+F90.


\begin{DoxyCode}
1516   \textcolor{keywordtype}{type}(ocean\_grid\_type),     \textcolor{keywordtype}{intent(in)}    :: g\textcolor{comment}{  !< The ocean's grid structure.}
1517   \textcolor{keywordtype}{real}, \textcolor{keywordtype}{dimension(SZIB\_(G))}, \textcolor{keywordtype}{intent(in)}    :: u\textcolor{comment}{  !< The zonal velocity [L T-1 ~> m s-1].}
1518   \textcolor{keywordtype}{real}, \textcolor{keywordtype}{dimension(SZI\_(G))},  \textcolor{keywordtype}{intent(in)}    :: h\textcolor{comment}{  !< Energy density used to calculate the fluxes}
1519 \textcolor{comment}{                                                 !! [R Z3 T-2 ~> J m-2].}
1520   \textcolor{keywordtype}{real}, \textcolor{keywordtype}{dimension(SZI\_(G))},  \textcolor{keywordtype}{intent(in)}    :: hl\textcolor{comment}{ !< Left- Energy densities in the reconstruction}
1521 \textcolor{comment}{                                                 !! [R Z3 T-2 ~> J m-2].}
1522   \textcolor{keywordtype}{real}, \textcolor{keywordtype}{dimension(SZI\_(G))},  \textcolor{keywordtype}{intent(in)}    :: hr\textcolor{comment}{ !< Right- Energy densities in the reconstruction}
1523 \textcolor{comment}{                                                 !! [R Z3 T-2 ~> J m-2].}
1524   \textcolor{keywordtype}{real}, \textcolor{keywordtype}{dimension(SZIB\_(G))}, \textcolor{keywordtype}{intent(inout)} :: uh\textcolor{comment}{ !< The zonal energy transport [R Z3 L2 T-3 ~> J s-1].}
1525   \textcolor{keywordtype}{real},                      \textcolor{keywordtype}{intent(in)}    :: dt\textcolor{comment}{ !< Time increment [T ~> s].}
1526   \textcolor{keywordtype}{type}(unit\_scale\_type),     \textcolor{keywordtype}{intent(in)}    :: us\textcolor{comment}{ !< A dimensional unit scaling type}
1527   \textcolor{keywordtype}{integer},                   \textcolor{keywordtype}{intent(in)}    :: j\textcolor{comment}{  !< The j-index to work on.}
1528   \textcolor{keywordtype}{integer},                   \textcolor{keywordtype}{intent(in)}    :: ish\textcolor{comment}{ !< The start i-index range to work on.}
1529   \textcolor{keywordtype}{integer},                   \textcolor{keywordtype}{intent(in)}    :: ieh\textcolor{comment}{ !< The end i-index range to work on.}
1530   \textcolor{keywordtype}{logical},                   \textcolor{keywordtype}{intent(in)}    :: vol\_cfl\textcolor{comment}{ !< If true, rescale the ratio of face areas to}
1531 \textcolor{comment}{                                                 !! the cell areas when estimating the CFL number.}
1532   \textcolor{comment}{! Local variables}
1533   \textcolor{keywordtype}{real} :: cfl  \textcolor{comment}{! The CFL number based on the local velocity and grid spacing [nondim].}
1534   \textcolor{keywordtype}{real} :: curv\_3 \textcolor{comment}{! A measure of the energy density curvature over a grid length [R Z3 T-2 ~> J m-2]}
1535   \textcolor{keywordtype}{integer} :: i
1536 
1537   \textcolor{keywordflow}{do} i=ish-1,ieh
1538     \textcolor{comment}{! Set new values of uh and duhdu.}
1539     \textcolor{keywordflow}{if} (u(i) > 0.0) \textcolor{keywordflow}{then}
1540       \textcolor{keywordflow}{if} (vol\_cfl) \textcolor{keywordflow}{then} ; cfl = (u(i) * dt) * (g%dy\_Cu(i,j) * g%IareaT(i,j))
1541       \textcolor{keywordflow}{else} ; cfl = u(i) * dt * g%IdxT(i,j) ;\textcolor{keywordflow}{ endif}
1542       curv\_3 = (hl(i) + hr(i)) - 2.0*h(i)
1543       uh(i) = g%dy\_Cu(i,j) * u(i) * &
1544           (hr(i) + cfl * (0.5*(hl(i) - hr(i)) + curv\_3*(cfl - 1.5)))
1545     \textcolor{keywordflow}{elseif} (u(i) < 0.0) \textcolor{keywordflow}{then}
1546       \textcolor{keywordflow}{if} (vol\_cfl) \textcolor{keywordflow}{then} ; cfl = (-u(i) * dt) * (g%dy\_Cu(i,j) * g%IareaT(i+1,j))
1547       \textcolor{keywordflow}{else} ; cfl = -u(i) * dt * g%IdxT(i+1,j) ;\textcolor{keywordflow}{ endif}
1548       curv\_3 = (hl(i+1) + hr(i+1)) - 2.0*h(i+1)
1549       uh(i) = g%dy\_Cu(i,j) * u(i) * &
1550           (hl(i+1) + cfl * (0.5*(hr(i+1)-hl(i+1)) + curv\_3*(cfl - 1.5)))
1551     \textcolor{keywordflow}{else}
1552       uh(i) = 0.0
1553 \textcolor{keywordflow}{    endif}
1554 \textcolor{keywordflow}{  enddo}
\end{DoxyCode}
