\hypertarget{namespacemom__bkgnd__mixing}{}\section{mom\+\_\+bkgnd\+\_\+mixing Module Reference}
\label{namespacemom__bkgnd__mixing}\index{mom\_bkgnd\_mixing@{mom\_bkgnd\_mixing}}


\subsection{Detailed Description}
Interface to background mixing schemes, including the Bryan and Lewis (1979) which is applied via C\+V\+Mix. \subsection*{Data Types}
\begin{DoxyCompactItemize}
\item 
type \mbox{\hyperlink{structmom__bkgnd__mixing_1_1bkgnd__mixing__cs}{bkgnd\+\_\+mixing\+\_\+cs}}
\begin{DoxyCompactList}\small\item\em Control structure including parameters for this module. \end{DoxyCompactList}\end{DoxyCompactItemize}
\subsection*{Functions/\+Subroutines}
\begin{DoxyCompactItemize}
\item 
subroutine, public \mbox{\hyperlink{namespacemom__bkgnd__mixing_a39f3b89ba376a8266a5c61fa126a7580}{bkgnd\+\_\+mixing\+\_\+init}} (Time, G, GV, US, param\+\_\+file, diag, CS)
\begin{DoxyCompactList}\small\item\em Initialize the background mixing routine. \end{DoxyCompactList}\item 
subroutine, public \mbox{\hyperlink{namespacemom__bkgnd__mixing_ab03cc867c234bc3d0a1d07a3f1513483}{calculate\+\_\+bkgnd\+\_\+mixing}} (h, tv, N2\+\_\+lay, Kd\+\_\+lay, Kd\+\_\+int, Kv\+\_\+bkgnd, j, G, GV, US, CS)
\begin{DoxyCompactList}\small\item\em Calculates the vertical background diffusivities/viscosities. \end{DoxyCompactList}\item 
logical function \mbox{\hyperlink{namespacemom__bkgnd__mixing_a213f9ed7daae9b060fb781c74de824dc}{cvmix\+\_\+bkgnd\+\_\+is\+\_\+used}} (param\+\_\+file)
\begin{DoxyCompactList}\small\item\em Reads the parameter \char`\"{}\+U\+S\+E\+\_\+\+C\+V\+Mix\+\_\+\+B\+A\+C\+K\+G\+R\+O\+U\+N\+D\char`\"{} and returns state. This function allows other modules to know whether this parameterization will be used without needing to duplicate the log entry. \end{DoxyCompactList}\item 
subroutine \mbox{\hyperlink{namespacemom__bkgnd__mixing_a829d5b6f715c06b6566a49271d4a7217}{check\+\_\+bkgnd\+\_\+scheme}} (CS, str)
\begin{DoxyCompactList}\small\item\em Sets CSbkgnd\+\_\+scheme\+\_\+str to check whether multiple background diffusivity schemes are activated. The string is also for error/log messages. \end{DoxyCompactList}\item 
subroutine, public \mbox{\hyperlink{namespacemom__bkgnd__mixing_a1d7ebcf89d3ec5dfff1bb7977a7eb08c}{bkgnd\+\_\+mixing\+\_\+end}} (CS)
\begin{DoxyCompactList}\small\item\em Clear pointers and dealocate memory. \end{DoxyCompactList}\end{DoxyCompactItemize}
\subsection*{Variables}
\begin{DoxyCompactItemize}
\item 
\mbox{\Hypertarget{namespacemom__bkgnd__mixing_ab29f7955c49a49c1ed5b2a3808a6fa9e}\label{namespacemom__bkgnd__mixing_ab29f7955c49a49c1ed5b2a3808a6fa9e}} 
character(len=40) \mbox{\hyperlink{namespacemom__bkgnd__mixing_ab29f7955c49a49c1ed5b2a3808a6fa9e}{mdl}} = \char`\"{}M\+O\+M\+\_\+bkgnd\+\_\+mixing\char`\"{}
\begin{DoxyCompactList}\small\item\em This module\textquotesingle{}s name. \end{DoxyCompactList}\end{DoxyCompactItemize}


\subsection{Function/\+Subroutine Documentation}
\mbox{\Hypertarget{namespacemom__bkgnd__mixing_a1d7ebcf89d3ec5dfff1bb7977a7eb08c}\label{namespacemom__bkgnd__mixing_a1d7ebcf89d3ec5dfff1bb7977a7eb08c}} 
\index{mom\_bkgnd\_mixing@{mom\_bkgnd\_mixing}!bkgnd\_mixing\_end@{bkgnd\_mixing\_end}}
\index{bkgnd\_mixing\_end@{bkgnd\_mixing\_end}!mom\_bkgnd\_mixing@{mom\_bkgnd\_mixing}}
\subsubsection{\texorpdfstring{bkgnd\_mixing\_end()}{bkgnd\_mixing\_end()}}
{\footnotesize\ttfamily subroutine, public mom\+\_\+bkgnd\+\_\+mixing\+::bkgnd\+\_\+mixing\+\_\+end (\begin{DoxyParamCaption}\item[{type(\mbox{\hyperlink{structmom__bkgnd__mixing_1_1bkgnd__mixing__cs}{bkgnd\+\_\+mixing\+\_\+cs}}), pointer}]{CS }\end{DoxyParamCaption})}



Clear pointers and dealocate memory. 


\begin{DoxyParams}{Parameters}
{\em cs} & Control structure for this module that will be deallocated in this subroutine \\
\hline
\end{DoxyParams}


Definition at line 548 of file M\+O\+M\+\_\+bkgnd\+\_\+mixing.\+F90.


\begin{DoxyCode}{0}
\DoxyCodeLine{548   \textcolor{keywordtype}{type}(bkgnd\_mixing\_cs), \textcolor{keywordtype}{pointer} :: CS\textcolor{comment}{ !< Control structure for this module that}}
\DoxyCodeLine{549 \textcolor{comment}{                                       !! will be deallocated in this subroutine}}
\DoxyCodeLine{550 }
\DoxyCodeLine{551   \textcolor{keywordflow}{if} (.not. \textcolor{keyword}{associated}(cs)) \textcolor{keywordflow}{return}}
\DoxyCodeLine{552   \textcolor{keyword}{deallocate}(cs)}
\DoxyCodeLine{553 }

\end{DoxyCode}
\mbox{\Hypertarget{namespacemom__bkgnd__mixing_a39f3b89ba376a8266a5c61fa126a7580}\label{namespacemom__bkgnd__mixing_a39f3b89ba376a8266a5c61fa126a7580}} 
\index{mom\_bkgnd\_mixing@{mom\_bkgnd\_mixing}!bkgnd\_mixing\_init@{bkgnd\_mixing\_init}}
\index{bkgnd\_mixing\_init@{bkgnd\_mixing\_init}!mom\_bkgnd\_mixing@{mom\_bkgnd\_mixing}}
\subsubsection{\texorpdfstring{bkgnd\_mixing\_init()}{bkgnd\_mixing\_init()}}
{\footnotesize\ttfamily subroutine, public mom\+\_\+bkgnd\+\_\+mixing\+::bkgnd\+\_\+mixing\+\_\+init (\begin{DoxyParamCaption}\item[{type(time\+\_\+type), intent(in)}]{Time,  }\item[{type(ocean\+\_\+grid\+\_\+type), intent(in)}]{G,  }\item[{type(verticalgrid\+\_\+type), intent(in)}]{GV,  }\item[{type(unit\+\_\+scale\+\_\+type), intent(in)}]{US,  }\item[{type(param\+\_\+file\+\_\+type), intent(in)}]{param\+\_\+file,  }\item[{type(diag\+\_\+ctrl), intent(inout), target}]{diag,  }\item[{type(\mbox{\hyperlink{structmom__bkgnd__mixing_1_1bkgnd__mixing__cs}{bkgnd\+\_\+mixing\+\_\+cs}}), pointer}]{CS }\end{DoxyParamCaption})}



Initialize the background mixing routine. 


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


Definition at line 114 of file M\+O\+M\+\_\+bkgnd\+\_\+mixing.\+F90.


\begin{DoxyCode}{0}
\DoxyCodeLine{114 }
\DoxyCodeLine{115   \textcolor{keywordtype}{type}(time\_type),         \textcolor{keywordtype}{intent(in)}    :: Time\textcolor{comment}{       !< The current time.}}
\DoxyCodeLine{116   \textcolor{keywordtype}{type}(ocean\_grid\_type),   \textcolor{keywordtype}{intent(in)}    :: G\textcolor{comment}{          !< Grid structure.}}
\DoxyCodeLine{117   \textcolor{keywordtype}{type}(verticalGrid\_type), \textcolor{keywordtype}{intent(in)}    :: GV\textcolor{comment}{         !< Vertical grid structure.}}
\DoxyCodeLine{118   \textcolor{keywordtype}{type}(unit\_scale\_type),   \textcolor{keywordtype}{intent(in)}    :: US\textcolor{comment}{         !< A dimensional unit scaling type}}
\DoxyCodeLine{119   \textcolor{keywordtype}{type}(param\_file\_type),   \textcolor{keywordtype}{intent(in)}    :: param\_file\textcolor{comment}{ !< Run-time parameter file handle}}
\DoxyCodeLine{120   \textcolor{keywordtype}{type}(diag\_ctrl), \textcolor{keywordtype}{target}, \textcolor{keywordtype}{intent(inout)} :: diag\textcolor{comment}{       !< Diagnostics control structure.}}
\DoxyCodeLine{121   \textcolor{keywordtype}{type}(bkgnd\_mixing\_cs),    \textcolor{keywordtype}{pointer}      :: CS\textcolor{comment}{         !< This module's control structure.}}
\DoxyCodeLine{122 }
\DoxyCodeLine{123   \textcolor{comment}{! Local variables}}
\DoxyCodeLine{124 \textcolor{keywordtype}{  real} :: Kv                    \textcolor{comment}{! The interior vertical viscosity [Z2 T-1 ~> m2 s-1] - read to set Prandtl}}
\DoxyCodeLine{125                                 \textcolor{comment}{! number unless it is provided as a parameter}}
\DoxyCodeLine{126 \textcolor{keywordtype}{  real} :: prandtl\_bkgnd\_comp    \textcolor{comment}{! Kv/CS\%Kd. Gets compared with user-specified prandtl\_bkgnd.}}
\DoxyCodeLine{127 }
\DoxyCodeLine{128 \textcolor{comment}{! This include declares and sets the variable "version".}}
\DoxyCodeLine{129 \textcolor{preprocessor}{\#include "version\_variable.h"}}
\DoxyCodeLine{130 \textcolor{preprocessor}{}}
\DoxyCodeLine{131   \textcolor{keywordflow}{if} (\textcolor{keyword}{associated}(cs)) \textcolor{keywordflow}{then}}
\DoxyCodeLine{132     \textcolor{keyword}{call }mom\_error(warning, \textcolor{stringliteral}{"bkgnd\_mixing\_init called with an associated "}// \&}
\DoxyCodeLine{133                             \textcolor{stringliteral}{"control structure."})}
\DoxyCodeLine{134     \textcolor{keywordflow}{return}}
\DoxyCodeLine{135 \textcolor{keywordflow}{  endif}}
\DoxyCodeLine{136   \textcolor{keyword}{allocate}(cs)}
\DoxyCodeLine{137 }
\DoxyCodeLine{138   \textcolor{comment}{! Read parameters}}
\DoxyCodeLine{139   \textcolor{keyword}{call }log\_version(param\_file, mdl, version, \&}
\DoxyCodeLine{140     \textcolor{stringliteral}{"Adding static vertical background mixing coefficients"})}
\DoxyCodeLine{141 }
\DoxyCodeLine{142   \textcolor{keyword}{call }get\_param(param\_file, mdl, \textcolor{stringliteral}{"KD"}, cs\%Kd, \&}
\DoxyCodeLine{143                  \textcolor{stringliteral}{"The background diapycnal diffusivity of density in the "}//\&}
\DoxyCodeLine{144                  \textcolor{stringliteral}{"interior. Zero or the molecular value, ~1e-7 m2 s-1, "}//\&}
\DoxyCodeLine{145                  \textcolor{stringliteral}{"may be used."}, default=0.0, units=\textcolor{stringliteral}{"m2 s-1"}, scale=us\%m2\_s\_to\_Z2\_T)}
\DoxyCodeLine{146 }
\DoxyCodeLine{147   \textcolor{keyword}{call }get\_param(param\_file, mdl, \textcolor{stringliteral}{"KV"}, kv, \&}
\DoxyCodeLine{148                  \textcolor{stringliteral}{"The background kinematic viscosity in the interior. "}//\&}
\DoxyCodeLine{149                  \textcolor{stringliteral}{"The molecular value, ~1e-6 m2 s-1, may be used."}, \&}
\DoxyCodeLine{150                  units=\textcolor{stringliteral}{"m2 s-1"}, scale=us\%m2\_s\_to\_Z2\_T, fail\_if\_missing=.true.)}
\DoxyCodeLine{151 }
\DoxyCodeLine{152   \textcolor{keyword}{call }get\_param(param\_file, mdl, \textcolor{stringliteral}{"KD\_MIN"}, cs\%Kd\_min, \&}
\DoxyCodeLine{153                  \textcolor{stringliteral}{"The minimum diapycnal diffusivity."}, \&}
\DoxyCodeLine{154                  units=\textcolor{stringliteral}{"m2 s-1"}, default=0.01*cs\%Kd*us\%Z2\_T\_to\_m2\_s, scale=us\%m2\_s\_to\_Z2\_T)}
\DoxyCodeLine{155 }
\DoxyCodeLine{156   \textcolor{comment}{! The following is needed to set one of the choices of vertical background mixing}}
\DoxyCodeLine{157 }
\DoxyCodeLine{158   \textcolor{comment}{! BULKMIXEDLAYER is not always defined (e.g., CM2G63L), so the following line by passes}}
\DoxyCodeLine{159   \textcolor{comment}{! the need to include BULKMIXEDLAYER in MOM\_input}}
\DoxyCodeLine{160   cs\%bulkmixedlayer = (gv\%nkml > 0)}
\DoxyCodeLine{161   \textcolor{keywordflow}{if} (cs\%bulkmixedlayer) \textcolor{keywordflow}{then}}
\DoxyCodeLine{162     \textcolor{comment}{! Check that Kdml is not set when using bulk mixed layer}}
\DoxyCodeLine{163     \textcolor{keyword}{call }get\_param(param\_file, mdl, \textcolor{stringliteral}{"KDML"}, cs\%Kdml, default=-1.)}
\DoxyCodeLine{164     \textcolor{keywordflow}{if} (cs\%Kdml>0.) \textcolor{keyword}{call }mom\_error(fatal, \&}
\DoxyCodeLine{165                  \textcolor{stringliteral}{"bkgnd\_mixing\_init: KDML cannot be set when using bulk mixed layer."})}
\DoxyCodeLine{166     cs\%Kdml = cs\%Kd \textcolor{comment}{! This is not used with a bulk mixed layer, but also cannot be a NaN.}}
\DoxyCodeLine{167   \textcolor{keywordflow}{else}}
\DoxyCodeLine{168     \textcolor{keyword}{call }get\_param(param\_file, mdl, \textcolor{stringliteral}{"KDML"}, cs\%Kdml, \&}
\DoxyCodeLine{169                  \textcolor{stringliteral}{"If BULKMIXEDLAYER is false, KDML is the elevated "}//\&}
\DoxyCodeLine{170                  \textcolor{stringliteral}{"diapycnal diffusivity in the topmost HMIX of fluid. "}//\&}
\DoxyCodeLine{171                  \textcolor{stringliteral}{"KDML is only used if BULKMIXEDLAYER is false."}, \&}
\DoxyCodeLine{172                  units=\textcolor{stringliteral}{"m2 s-1"}, default=cs\%Kd*us\%Z2\_T\_to\_m2\_s, scale=us\%m2\_s\_to\_Z2\_T)}
\DoxyCodeLine{173     \textcolor{keyword}{call }get\_param(param\_file, mdl, \textcolor{stringliteral}{"HMIX\_FIXED"}, cs\%Hmix, \&}
\DoxyCodeLine{174                  \textcolor{stringliteral}{"The prescribed depth over which the near-surface "}//\&}
\DoxyCodeLine{175                  \textcolor{stringliteral}{"viscosity and diffusivity are elevated when the bulk "}//\&}
\DoxyCodeLine{176                  \textcolor{stringliteral}{"mixed layer is not used."}, units=\textcolor{stringliteral}{"m"}, scale=us\%m\_to\_Z, fail\_if\_missing=.true.)}
\DoxyCodeLine{177 \textcolor{keywordflow}{  endif}}
\DoxyCodeLine{178 }
\DoxyCodeLine{179   \textcolor{keyword}{call }get\_param(param\_file, mdl, \textcolor{stringliteral}{'DEBUG'}, cs\%debug, default=.false., do\_not\_log=.true.)}
\DoxyCodeLine{180 }
\DoxyCodeLine{181 \textcolor{comment}{!  call openParameterBlock(param\_file,'MOM\_BACKGROUND\_MIXING')}}
\DoxyCodeLine{182 }
\DoxyCodeLine{183   \textcolor{keyword}{call }get\_param(param\_file, mdl, \textcolor{stringliteral}{"BRYAN\_LEWIS\_DIFFUSIVITY"}, cs\%Bryan\_Lewis\_diffusivity, \&}
\DoxyCodeLine{184                  \textcolor{stringliteral}{"If true, use a Bryan \& Lewis (JGR 1979) like tanh "}//\&}
\DoxyCodeLine{185                  \textcolor{stringliteral}{"profile of background diapycnal diffusivity with depth. "}//\&}
\DoxyCodeLine{186                  \textcolor{stringliteral}{"This is done via CVMix."}, default=.false.)}
\DoxyCodeLine{187 }
\DoxyCodeLine{188   \textcolor{keywordflow}{if} (cs\%Bryan\_Lewis\_diffusivity) \textcolor{keywordflow}{then}}
\DoxyCodeLine{189     \textcolor{keyword}{call }check\_bkgnd\_scheme(cs, \textcolor{stringliteral}{"BRYAN\_LEWIS\_DIFFUSIVITY"})}
\DoxyCodeLine{190 }
\DoxyCodeLine{191     \textcolor{keyword}{call }get\_param(param\_file, mdl, \textcolor{stringliteral}{"BRYAN\_LEWIS\_C1"}, cs\%Bryan\_Lewis\_c1, \&}
\DoxyCodeLine{192                    \textcolor{stringliteral}{"The vertical diffusivity values for Bryan-Lewis profile at |z|=D."}, \&}
\DoxyCodeLine{193                    units=\textcolor{stringliteral}{"m2 s-1"}, fail\_if\_missing=.true.)}
\DoxyCodeLine{194 }
\DoxyCodeLine{195     \textcolor{keyword}{call }get\_param(param\_file, mdl, \textcolor{stringliteral}{"BRYAN\_LEWIS\_C2"}, cs\%Bryan\_Lewis\_c2, \&}
\DoxyCodeLine{196                    \textcolor{stringliteral}{"The amplitude of variation in diffusivity for the Bryan-Lewis profile"}, \&}
\DoxyCodeLine{197                    units=\textcolor{stringliteral}{"m2 s-1"}, fail\_if\_missing=.true.)}
\DoxyCodeLine{198 }
\DoxyCodeLine{199     \textcolor{keyword}{call }get\_param(param\_file, mdl, \textcolor{stringliteral}{"BRYAN\_LEWIS\_C3"}, cs\%Bryan\_Lewis\_c3, \&}
\DoxyCodeLine{200                    \textcolor{stringliteral}{"The inverse length scale for transition region in the Bryan-Lewis profile"}, \&}
\DoxyCodeLine{201                    units=\textcolor{stringliteral}{"m-1"}, fail\_if\_missing=.true.)}
\DoxyCodeLine{202 }
\DoxyCodeLine{203     \textcolor{keyword}{call }get\_param(param\_file, mdl, \textcolor{stringliteral}{"BRYAN\_LEWIS\_C4"}, cs\%Bryan\_Lewis\_c4, \&}
\DoxyCodeLine{204                    \textcolor{stringliteral}{"The depth where diffusivity is BRYAN\_LEWIS\_C1 in the Bryan-Lewis profile"},\&}
\DoxyCodeLine{205                    units=\textcolor{stringliteral}{"m"}, fail\_if\_missing=.true.)}
\DoxyCodeLine{206 }
\DoxyCodeLine{207 \textcolor{keywordflow}{  endif} \textcolor{comment}{! CS\%Bryan\_Lewis\_diffusivity}}
\DoxyCodeLine{208 }
\DoxyCodeLine{209   \textcolor{keyword}{call }get\_param(param\_file, mdl, \textcolor{stringliteral}{"HORIZ\_VARYING\_BACKGROUND"}, cs\%horiz\_varying\_background, \&}
\DoxyCodeLine{210                  \textcolor{stringliteral}{"If true, apply vertically uniform, latitude-dependent background "}//\&}
\DoxyCodeLine{211                  \textcolor{stringliteral}{"diffusivity, as described in Danabasoglu et al., 2012"}, \&}
\DoxyCodeLine{212                  default=.false.)}
\DoxyCodeLine{213 }
\DoxyCodeLine{214   \textcolor{keywordflow}{if} (cs\%horiz\_varying\_background) \textcolor{keywordflow}{then}}
\DoxyCodeLine{215     \textcolor{keyword}{call }check\_bkgnd\_scheme(cs, \textcolor{stringliteral}{"HORIZ\_VARYING\_BACKGROUND"})}
\DoxyCodeLine{216 }
\DoxyCodeLine{217     \textcolor{keyword}{call }get\_param(param\_file, mdl, \textcolor{stringliteral}{"BCKGRND\_VDC1"}, cs\%bckgrnd\_vdc1, \&}
\DoxyCodeLine{218                    \textcolor{stringliteral}{"Background diffusivity (Ledwell) when HORIZ\_VARYING\_BACKGROUND=True"}, \&}
\DoxyCodeLine{219                    units=\textcolor{stringliteral}{"m2 s-1"},default = 0.16e-04, scale=us\%m2\_s\_to\_Z2\_T)}
\DoxyCodeLine{220 }
\DoxyCodeLine{221     \textcolor{keyword}{call }get\_param(param\_file, mdl, \textcolor{stringliteral}{"BCKGRND\_VDC\_EQ"}, cs\%bckgrnd\_vdc\_eq, \&}
\DoxyCodeLine{222                    \textcolor{stringliteral}{"Equatorial diffusivity (Gregg) when HORIZ\_VARYING\_BACKGROUND=True"}, \&}
\DoxyCodeLine{223                    units=\textcolor{stringliteral}{"m2 s-1"},default = 0.01e-04, scale=us\%m2\_s\_to\_Z2\_T)}
\DoxyCodeLine{224 }
\DoxyCodeLine{225     \textcolor{keyword}{call }get\_param(param\_file, mdl, \textcolor{stringliteral}{"BCKGRND\_VDC\_PSIM"}, cs\%bckgrnd\_vdc\_psim, \&}
\DoxyCodeLine{226                    \textcolor{stringliteral}{"Max. PSI induced diffusivity (MacKinnon) when HORIZ\_VARYING\_BACKGROUND=True"}, \&}
\DoxyCodeLine{227                    units=\textcolor{stringliteral}{"m2 s-1"},default = 0.13e-4, scale=us\%m2\_s\_to\_Z2\_T)}
\DoxyCodeLine{228 }
\DoxyCodeLine{229     \textcolor{keyword}{call }get\_param(param\_file, mdl, \textcolor{stringliteral}{"BCKGRND\_VDC\_BAN"}, cs\%bckgrnd\_vdc\_Banda, \&}
\DoxyCodeLine{230                    \textcolor{stringliteral}{"Banda Sea diffusivity (Gordon) when HORIZ\_VARYING\_BACKGROUND=True"}, \&}
\DoxyCodeLine{231                    units=\textcolor{stringliteral}{"m2 s-1"},default = 1.0e-4, scale=us\%m2\_s\_to\_Z2\_T)}
\DoxyCodeLine{232 \textcolor{keywordflow}{  endif}}
\DoxyCodeLine{233 }
\DoxyCodeLine{234   \textcolor{keyword}{call }get\_param(param\_file, mdl, \textcolor{stringliteral}{"PRANDTL\_BKGND"}, cs\%prandtl\_bkgnd, \&}
\DoxyCodeLine{235                  \textcolor{stringliteral}{"Turbulent Prandtl number used to convert vertical "}//\&}
\DoxyCodeLine{236                  \textcolor{stringliteral}{"background diffusivities into viscosities."}, \&}
\DoxyCodeLine{237                  units=\textcolor{stringliteral}{"nondim"}, default=1.0)}
\DoxyCodeLine{238 }
\DoxyCodeLine{239   \textcolor{keywordflow}{if} (cs\%Bryan\_Lewis\_diffusivity .or. cs\%horiz\_varying\_background) \textcolor{keywordflow}{then}}
\DoxyCodeLine{240     prandtl\_bkgnd\_comp = cs\%prandtl\_bkgnd}
\DoxyCodeLine{241     \textcolor{keywordflow}{if} (cs\%Kd /= 0.0) prandtl\_bkgnd\_comp = kv / cs\%Kd}
\DoxyCodeLine{242 }
\DoxyCodeLine{243     \textcolor{keywordflow}{if} ( abs(cs\%prandtl\_bkgnd - prandtl\_bkgnd\_comp)>1.e-14) \textcolor{keywordflow}{then}}
\DoxyCodeLine{244       \textcolor{keyword}{call }mom\_error(fatal, \textcolor{stringliteral}{"bkgnd\_mixing\_init: The provided KD, KV and PRANDTL\_BKGND values "}//\&}
\DoxyCodeLine{245                             \textcolor{stringliteral}{"are incompatible. The following must hold: KD*PRANDTL\_BKGND==KV"})}
\DoxyCodeLine{246 \textcolor{keywordflow}{    endif}}
\DoxyCodeLine{247 \textcolor{keywordflow}{  endif}}
\DoxyCodeLine{248 }
\DoxyCodeLine{249   \textcolor{keyword}{call }get\_param(param\_file, mdl, \textcolor{stringliteral}{"HENYEY\_IGW\_BACKGROUND"}, cs\%Henyey\_IGW\_background, \&}
\DoxyCodeLine{250                  \textcolor{stringliteral}{"If true, use a latitude-dependent scaling for the near "}//\&}
\DoxyCodeLine{251                  \textcolor{stringliteral}{"surface background diffusivity, as described in "}//\&}
\DoxyCodeLine{252                  \textcolor{stringliteral}{"Harrison \& Hallberg, JPO 2008."}, default=.false.)}
\DoxyCodeLine{253   \textcolor{keywordflow}{if} (cs\%Henyey\_IGW\_background) \textcolor{keyword}{call }check\_bkgnd\_scheme(cs, \textcolor{stringliteral}{"HENYEY\_IGW\_BACKGROUND"})}
\DoxyCodeLine{254 }
\DoxyCodeLine{255 }
\DoxyCodeLine{256   \textcolor{keyword}{call }get\_param(param\_file, mdl, \textcolor{stringliteral}{"HENYEY\_IGW\_BACKGROUND\_NEW"}, cs\%Henyey\_IGW\_background\_new, \&}
\DoxyCodeLine{257                  \textcolor{stringliteral}{"If true, use a better latitude-dependent scaling for the "}//\&}
\DoxyCodeLine{258                  \textcolor{stringliteral}{"background diffusivity, as described in "}//\&}
\DoxyCodeLine{259                  \textcolor{stringliteral}{"Harrison \& Hallberg, JPO 2008."}, default=.false.)}
\DoxyCodeLine{260   \textcolor{keywordflow}{if} (cs\%Henyey\_IGW\_background\_new) \textcolor{keyword}{call }check\_bkgnd\_scheme(cs, \textcolor{stringliteral}{"HENYEY\_IGW\_BACKGROUND\_NEW"})}
\DoxyCodeLine{261 }
\DoxyCodeLine{262   \textcolor{keywordflow}{if} (cs\%Kd>0.0 .and. (trim(cs\%bkgnd\_scheme\_str)==\textcolor{stringliteral}{"BRYAN\_LEWIS\_DIFFUSIVITY"} .or.\&}
\DoxyCodeLine{263                           trim(cs\%bkgnd\_scheme\_str)==\textcolor{stringliteral}{"HORIZ\_VARYING\_BACKGROUND"} )) \textcolor{keywordflow}{then}}
\DoxyCodeLine{264     \textcolor{keyword}{call }mom\_error(warning, \textcolor{stringliteral}{"bkgnd\_mixing\_init: a nonzero constant background "}//\&}
\DoxyCodeLine{265          \textcolor{stringliteral}{"diffusivity (KD) is specified along with "}//trim(cs\%bkgnd\_scheme\_str))}
\DoxyCodeLine{266 \textcolor{keywordflow}{  endif}}
\DoxyCodeLine{267 }
\DoxyCodeLine{268   \textcolor{keywordflow}{if} (cs\%Henyey\_IGW\_background) \textcolor{keywordflow}{then}}
\DoxyCodeLine{269     \textcolor{keyword}{call }get\_param(param\_file, mdl, \textcolor{stringliteral}{"HENYEY\_N0\_2OMEGA"}, cs\%N0\_2Omega, \&}
\DoxyCodeLine{270                   \textcolor{stringliteral}{"The ratio of the typical Buoyancy frequency to twice "}//\&}
\DoxyCodeLine{271                   \textcolor{stringliteral}{"the Earth's rotation period, used with the Henyey "}//\&}
\DoxyCodeLine{272                   \textcolor{stringliteral}{"scaling from the mixing."}, units=\textcolor{stringliteral}{"nondim"}, default=20.0)}
\DoxyCodeLine{273     \textcolor{keyword}{call }get\_param(param\_file, mdl, \textcolor{stringliteral}{"OMEGA"}, cs\%omega, \&}
\DoxyCodeLine{274                  \textcolor{stringliteral}{"The rotation rate of the earth."}, units=\textcolor{stringliteral}{"s-1"}, \&}
\DoxyCodeLine{275                  default=7.2921e-5, scale=us\%T\_to\_s)}
\DoxyCodeLine{276 \textcolor{keywordflow}{  endif}}
\DoxyCodeLine{277 }
\DoxyCodeLine{278   \textcolor{keyword}{call }get\_param(param\_file, mdl, \textcolor{stringliteral}{"KD\_TANH\_LAT\_FN"}, cs\%Kd\_tanh\_lat\_fn, \&}
\DoxyCodeLine{279                  \textcolor{stringliteral}{"If true, use a tanh dependence of Kd\_sfc on latitude, "}//\&}
\DoxyCodeLine{280                  \textcolor{stringliteral}{"like CM2.1/CM2M.  There is no physical justification "}//\&}
\DoxyCodeLine{281                  \textcolor{stringliteral}{"for this form, and it can not be used with "}//\&}
\DoxyCodeLine{282                  \textcolor{stringliteral}{"HENYEY\_IGW\_BACKGROUND."}, default=.false.)}
\DoxyCodeLine{283 }
\DoxyCodeLine{284   \textcolor{keywordflow}{if} (cs\%Kd\_tanh\_lat\_fn) \&}
\DoxyCodeLine{285     \textcolor{keyword}{call }get\_param(param\_file, mdl, \textcolor{stringliteral}{"KD\_TANH\_LAT\_SCALE"}, cs\%Kd\_tanh\_lat\_scale, \&}
\DoxyCodeLine{286                  \textcolor{stringliteral}{"A nondimensional scaling for the range ofdiffusivities "}//\&}
\DoxyCodeLine{287                  \textcolor{stringliteral}{"with KD\_TANH\_LAT\_FN. Valid values are in the range of "}//\&}
\DoxyCodeLine{288                  \textcolor{stringliteral}{"-2 to 2; 0.4 reproduces CM2M."}, units=\textcolor{stringliteral}{"nondim"}, default=0.0)}
\DoxyCodeLine{289 }
\DoxyCodeLine{290   \textcolor{keywordflow}{if} (cs\%Henyey\_IGW\_background .and. cs\%Kd\_tanh\_lat\_fn) \textcolor{keyword}{call }mom\_error(fatal, \&}
\DoxyCodeLine{291     \textcolor{stringliteral}{"MOM\_bkgnd\_mixing: KD\_TANH\_LAT\_FN can not be used with HENYEY\_IGW\_BACKGROUND."})}
\DoxyCodeLine{292 }
\DoxyCodeLine{293   cs\%Kd\_via\_Kdml\_bug = .false.}
\DoxyCodeLine{294   \textcolor{keywordflow}{if} ((cs\%Kd /= cs\%Kdml) .and. .not.(cs\%Kd\_tanh\_lat\_fn .or. cs\%bulkmixedlayer .or. \&}
\DoxyCodeLine{295                                      cs\%Henyey\_IGW\_background .or. cs\%Henyey\_IGW\_background\_new .or. \&}
\DoxyCodeLine{296                                      cs\%horiz\_varying\_background .or. cs\%Bryan\_Lewis\_diffusivity)) \textcolor{keywordflow}{then}}
\DoxyCodeLine{297     \textcolor{keyword}{call }get\_param(param\_file, mdl, \textcolor{stringliteral}{"KD\_BACKGROUND\_VIA\_KDML\_BUG"}, cs\%Kd\_via\_Kdml\_bug, \&}
\DoxyCodeLine{298                  \textcolor{stringliteral}{"If true and KDML /= KD and several other conditions apply, the background "}//\&}
\DoxyCodeLine{299                  \textcolor{stringliteral}{"diffusivity is set incorrectly using a bug that was introduced in March, 2018."}, \&}
\DoxyCodeLine{300                  default=.true.)  \textcolor{comment}{! The default should be changed to false and this parameter obsoleted.}}
\DoxyCodeLine{301 \textcolor{keywordflow}{  endif}}
\DoxyCodeLine{302 }
\DoxyCodeLine{303 \textcolor{comment}{!  call closeParameterBlock(param\_file)}}
\DoxyCodeLine{304 }

\end{DoxyCode}
\mbox{\Hypertarget{namespacemom__bkgnd__mixing_ab03cc867c234bc3d0a1d07a3f1513483}\label{namespacemom__bkgnd__mixing_ab03cc867c234bc3d0a1d07a3f1513483}} 
\index{mom\_bkgnd\_mixing@{mom\_bkgnd\_mixing}!calculate\_bkgnd\_mixing@{calculate\_bkgnd\_mixing}}
\index{calculate\_bkgnd\_mixing@{calculate\_bkgnd\_mixing}!mom\_bkgnd\_mixing@{mom\_bkgnd\_mixing}}
\subsubsection{\texorpdfstring{calculate\_bkgnd\_mixing()}{calculate\_bkgnd\_mixing()}}
{\footnotesize\ttfamily subroutine, public mom\+\_\+bkgnd\+\_\+mixing\+::calculate\+\_\+bkgnd\+\_\+mixing (\begin{DoxyParamCaption}\item[{real, dimension( g \%isd\+: g \%ied, g \%jsd\+: g \%jed, gv \%ke), intent(in)}]{h,  }\item[{type(thermo\+\_\+var\+\_\+ptrs), intent(in)}]{tv,  }\item[{real, dimension( g \%isd\+: g \%ied, gv \%ke), intent(in)}]{N2\+\_\+lay,  }\item[{real, dimension( g \%isd\+: g \%ied, gv \%ke), intent(out)}]{Kd\+\_\+lay,  }\item[{real, dimension( g \%isd\+: g \%ied, gv \%ke+1), intent(out)}]{Kd\+\_\+int,  }\item[{real, dimension( g \%isd\+: g \%ied, gv \%ke+1), intent(out)}]{Kv\+\_\+bkgnd,  }\item[{integer, intent(in)}]{j,  }\item[{type(ocean\+\_\+grid\+\_\+type), intent(in)}]{G,  }\item[{type(verticalgrid\+\_\+type), intent(in)}]{GV,  }\item[{type(unit\+\_\+scale\+\_\+type), intent(in)}]{US,  }\item[{type(\mbox{\hyperlink{structmom__bkgnd__mixing_1_1bkgnd__mixing__cs}{bkgnd\+\_\+mixing\+\_\+cs}}), pointer}]{CS }\end{DoxyParamCaption})}



Calculates the vertical background diffusivities/viscosities. 


\begin{DoxyParams}[1]{Parameters}
\mbox{\texttt{ in}}  & {\em g} & Grid structure. \\
\hline
\mbox{\texttt{ in}}  & {\em gv} & Vertical grid structure. \\
\hline
\mbox{\texttt{ in}}  & {\em h} & Layer thickness \mbox{[}H $\sim$$>$ m or kg m-\/2\mbox{]}. \\
\hline
\mbox{\texttt{ in}}  & {\em tv} & Thermodynamics structure. \\
\hline
\mbox{\texttt{ in}}  & {\em n2\+\_\+lay} & squared buoyancy frequency associated with layers \mbox{[}T-\/2 $\sim$$>$ s-\/2\mbox{]} \\
\hline
\mbox{\texttt{ out}}  & {\em kd\+\_\+lay} & The background diapycnal diffusivity of each layer \mbox{[}Z2 T-\/1 $\sim$$>$ m2 s-\/1\mbox{]}. \\
\hline
\mbox{\texttt{ out}}  & {\em kd\+\_\+int} & The background diapycnal diffusivity of each interface \mbox{[}Z2 T-\/1 $\sim$$>$ m2 s-\/1\mbox{]}. \\
\hline
\mbox{\texttt{ out}}  & {\em kv\+\_\+bkgnd} & The background vertical viscosity at each interface \mbox{[}Z2 T-\/1 $\sim$$>$ m2 s-\/1\mbox{]} \\
\hline
\mbox{\texttt{ in}}  & {\em j} & Meridional grid index \\
\hline
\mbox{\texttt{ in}}  & {\em us} & A dimensional unit scaling type \\
\hline
 & {\em cs} & The control structure returned by a previous call to bkgnd\+\_\+mixing\+\_\+init. \\
\hline
\end{DoxyParams}


Definition at line 309 of file M\+O\+M\+\_\+bkgnd\+\_\+mixing.\+F90.


\begin{DoxyCode}{0}
\DoxyCodeLine{309 }
\DoxyCodeLine{310   \textcolor{keywordtype}{type}(ocean\_grid\_type),                     \textcolor{keywordtype}{intent(in)}    :: G\textcolor{comment}{   !< Grid structure.}}
\DoxyCodeLine{311   \textcolor{keywordtype}{type}(verticalGrid\_type),                   \textcolor{keywordtype}{intent(in)}    :: GV\textcolor{comment}{  !< Vertical grid structure.}}
\DoxyCodeLine{312 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(SZI\_(G),SZJ\_(G),SZK\_(GV))}, \textcolor{keywordtype}{intent(in)}    :: h\textcolor{comment}{   !< Layer thickness [H ~> m or kg m-2].}}
\DoxyCodeLine{313   \textcolor{keywordtype}{type}(thermo\_var\_ptrs),                     \textcolor{keywordtype}{intent(in)}    :: tv\textcolor{comment}{  !< Thermodynamics structure.}}
\DoxyCodeLine{314 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(SZI\_(G),SZK\_(GV))},         \textcolor{keywordtype}{intent(in)}    :: N2\_lay\textcolor{comment}{ !< squared buoyancy frequency associated}}
\DoxyCodeLine{315 \textcolor{comment}{                                                                  !! with layers [T-2 ~> s-2]}}
\DoxyCodeLine{316 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(SZI\_(G),SZK\_(GV))},         \textcolor{keywordtype}{intent(out)}   :: Kd\_lay\textcolor{comment}{ !< The background diapycnal diffusivity}}
\DoxyCodeLine{317 \textcolor{comment}{                                                                  !! of each layer [Z2 T-1 ~> m2 s-1].}}
\DoxyCodeLine{318 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(SZI\_(G),SZK\_(GV)+1)},       \textcolor{keywordtype}{intent(out)}   :: Kd\_int\textcolor{comment}{ !< The background diapycnal diffusivity}}
\DoxyCodeLine{319 \textcolor{comment}{                                                                  !! of each interface [Z2 T-1 ~> m2 s-1].}}
\DoxyCodeLine{320 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(SZI\_(G),SZK\_(GV)+1)},       \textcolor{keywordtype}{intent(out)}   :: Kv\_bkgnd\textcolor{comment}{ !< The background vertical viscosity at}}
\DoxyCodeLine{321 \textcolor{comment}{                                                                  !! each interface [Z2 T-1 ~> m2 s-1]}}
\DoxyCodeLine{322   \textcolor{keywordtype}{integer},                                   \textcolor{keywordtype}{intent(in)}    :: j\textcolor{comment}{   !< Meridional grid index}}
\DoxyCodeLine{323   \textcolor{keywordtype}{type}(unit\_scale\_type),                     \textcolor{keywordtype}{intent(in)}    :: US\textcolor{comment}{  !< A dimensional unit scaling type}}
\DoxyCodeLine{324   \textcolor{keywordtype}{type}(bkgnd\_mixing\_cs),                     \textcolor{keywordtype}{pointer}       :: CS\textcolor{comment}{  !< The control structure returned by}}
\DoxyCodeLine{325 \textcolor{comment}{                                                                  !! a previous call to bkgnd\_mixing\_init.}}
\DoxyCodeLine{326 }
\DoxyCodeLine{327   \textcolor{comment}{! local variables}}
\DoxyCodeLine{328 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(SZK\_(GV)+1)} :: depth\_int\textcolor{comment}{  !< Distance from surface of the interfaces [m]}}
\DoxyCodeLine{329 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(SZK\_(GV)+1)} :: Kd\_col\textcolor{comment}{     !< Diffusivities at the interfaces [m2 s-1]}}
\DoxyCodeLine{330 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(SZK\_(GV)+1)} :: Kv\_col\textcolor{comment}{     !< Viscosities at the interfaces [m2 s-1]}}
\DoxyCodeLine{331 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(SZI\_(G))}    :: Kd\_sfc\textcolor{comment}{     !< Surface value of the diffusivity [Z2 T-1 ~> m2 s-1]}}
\DoxyCodeLine{332 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(SZI\_(G))}    :: depth\textcolor{comment}{      !< Distance from surface of an interface [Z ~> m]}}
\DoxyCodeLine{333 \textcolor{keywordtype}{  real} :: depth\_c\textcolor{comment}{    !< depth of the center of a layer [Z ~> m]}}
\DoxyCodeLine{334 \textcolor{keywordtype}{  real} :: I\_Hmix\textcolor{comment}{     !< inverse of fixed mixed layer thickness [Z-1 ~> m-1]}}
\DoxyCodeLine{335 \textcolor{keywordtype}{  real} :: I\_2Omega\textcolor{comment}{   !< 1/(2 Omega) [T ~> s]}}
\DoxyCodeLine{336 \textcolor{keywordtype}{  real} :: N\_2Omega   \textcolor{comment}{!  The ratio of the stratification to the Earth's rotation rate [nondim]}}
\DoxyCodeLine{337 \textcolor{keywordtype}{  real} :: N02\_N2     \textcolor{comment}{!  The ratio a reference stratification to the actual stratification [nondim]}}
\DoxyCodeLine{338 \textcolor{keywordtype}{  real} :: I\_x30\textcolor{comment}{      !< 2/acos(2) = 1/(sin(30 deg) * acosh(1/sin(30 deg)))}}
\DoxyCodeLine{339 \textcolor{keywordtype}{  real} :: deg\_to\_rad\textcolor{comment}{ !< factor converting degrees to radians, pi/180.}}
\DoxyCodeLine{340 \textcolor{keywordtype}{  real} :: abs\_sinlat\textcolor{comment}{ !< absolute value of sine of latitude [nondim]}}
\DoxyCodeLine{341 \textcolor{keywordtype}{  real} :: min\_sinlat \textcolor{comment}{! The minimum value of the sine of latitude [nondim]}}
\DoxyCodeLine{342 \textcolor{keywordtype}{  real} :: bckgrnd\_vdc\_psin\textcolor{comment}{ !< PSI diffusivity in northern hemisphere [Z2 T-1 ~> m2 s-1]}}
\DoxyCodeLine{343 \textcolor{keywordtype}{  real} :: bckgrnd\_vdc\_psis\textcolor{comment}{ !< PSI diffusivity in southern hemisphere [Z2 T-1 ~> m2 s-1]}}
\DoxyCodeLine{344   \textcolor{keywordtype}{integer} :: i, k, is, ie, js, je, nz}
\DoxyCodeLine{345 }
\DoxyCodeLine{346   is  = g\%isc ; ie  = g\%iec ; js  = g\%jsc ; je  = g\%jec ; nz = g\%ke}
\DoxyCodeLine{347 }
\DoxyCodeLine{348   \textcolor{comment}{! set some parameters}}
\DoxyCodeLine{349   deg\_to\_rad = atan(1.0)/45.0 \textcolor{comment}{! = PI/180}}
\DoxyCodeLine{350   min\_sinlat = 1.e-10}
\DoxyCodeLine{351 }
\DoxyCodeLine{352   \textcolor{comment}{! Start with a constant value that may be replaced below.}}
\DoxyCodeLine{353   kd\_lay(:,:) = cs\%Kd}
\DoxyCodeLine{354   kv\_bkgnd(:,:) = 0.0}
\DoxyCodeLine{355 }
\DoxyCodeLine{356   \textcolor{comment}{! Set up the background diffusivity.}}
\DoxyCodeLine{357   \textcolor{keywordflow}{if} (cs\%Bryan\_Lewis\_diffusivity) \textcolor{keywordflow}{then}}
\DoxyCodeLine{358 }
\DoxyCodeLine{359     \textcolor{keywordflow}{do} i=is,ie}
\DoxyCodeLine{360       depth\_int(1) = 0.0}
\DoxyCodeLine{361       \textcolor{keywordflow}{do} k=2,nz+1}
\DoxyCodeLine{362         depth\_int(k) = depth\_int(k-1) + gv\%H\_to\_m*h(i,j,k-1)}
\DoxyCodeLine{363 \textcolor{keywordflow}{      enddo}}
\DoxyCodeLine{364 }
\DoxyCodeLine{365       \textcolor{keyword}{call }cvmix\_init\_bkgnd(max\_nlev=nz, \&}
\DoxyCodeLine{366                             zw = depth\_int(:), \&  \textcolor{comment}{!< interface depths relative to the surface in m, must be positive.}}
\DoxyCodeLine{367                             bl1 = cs\%Bryan\_Lewis\_c1, \&}
\DoxyCodeLine{368                             bl2 = cs\%Bryan\_Lewis\_c2, \&}
\DoxyCodeLine{369                             bl3 = cs\%Bryan\_Lewis\_c3, \&}
\DoxyCodeLine{370                             bl4 = cs\%Bryan\_Lewis\_c4, \&}
\DoxyCodeLine{371                             prandtl = cs\%prandtl\_bkgnd)}
\DoxyCodeLine{372 }
\DoxyCodeLine{373       kd\_col(:) = 0.0 ; kv\_col(:) = 0.0  \textcolor{comment}{! Is this line necessary?}}
\DoxyCodeLine{374       \textcolor{keyword}{call }cvmix\_coeffs\_bkgnd(mdiff\_out=kv\_col, tdiff\_out=kd\_col, nlev=nz, max\_nlev=nz)}
\DoxyCodeLine{375 }
\DoxyCodeLine{376       \textcolor{comment}{! Update Kd and Kv.}}
\DoxyCodeLine{377       \textcolor{keywordflow}{do} k=1,nz+1}
\DoxyCodeLine{378         kv\_bkgnd(i,k) = us\%m2\_s\_to\_Z2\_T*kv\_col(k)}
\DoxyCodeLine{379         kd\_int(i,k) = us\%m2\_s\_to\_Z2\_T*kd\_col(k)}
\DoxyCodeLine{380 \textcolor{keywordflow}{      enddo}}
\DoxyCodeLine{381       \textcolor{keywordflow}{do} k=1,nz}
\DoxyCodeLine{382         kd\_lay(i,k) = kd\_lay(i,k) + 0.5 * us\%m2\_s\_to\_Z2\_T * (kd\_col(k) + kd\_col(k+1))}
\DoxyCodeLine{383 \textcolor{keywordflow}{      enddo}}
\DoxyCodeLine{384 \textcolor{keywordflow}{    enddo} \textcolor{comment}{! i loop}}
\DoxyCodeLine{385 }
\DoxyCodeLine{386   \textcolor{keywordflow}{elseif} (cs\%horiz\_varying\_background) \textcolor{keywordflow}{then}}
\DoxyCodeLine{387     \textcolor{comment}{!\#\#\# Note that there are lots of hard-coded parameters (mostly latitudes and longitudes) here.}}
\DoxyCodeLine{388     \textcolor{keywordflow}{do} i=is,ie}
\DoxyCodeLine{389       bckgrnd\_vdc\_psis = cs\%bckgrnd\_vdc\_psim * exp(-(0.4*(g\%geoLatT(i,j)+28.9))**2)}
\DoxyCodeLine{390       bckgrnd\_vdc\_psin = cs\%bckgrnd\_vdc\_psim * exp(-(0.4*(g\%geoLatT(i,j)-28.9))**2)}
\DoxyCodeLine{391       kd\_int(i,1) = (cs\%bckgrnd\_vdc\_eq + bckgrnd\_vdc\_psin) + bckgrnd\_vdc\_psis}
\DoxyCodeLine{392 }
\DoxyCodeLine{393       \textcolor{keywordflow}{if} (g\%geoLatT(i,j) < -10.0) \textcolor{keywordflow}{then}}
\DoxyCodeLine{394         kd\_int(i,1) = kd\_int(i,1) + cs\%bckgrnd\_vdc1}
\DoxyCodeLine{395       \textcolor{keywordflow}{elseif} (g\%geoLatT(i,j) <= 10.0) \textcolor{keywordflow}{then}}
\DoxyCodeLine{396         kd\_int(i,1) = kd\_int(i,1) + cs\%bckgrnd\_vdc1 * (g\%geoLatT(i,j)/10.0)**2}
\DoxyCodeLine{397       \textcolor{keywordflow}{else}}
\DoxyCodeLine{398         kd\_int(i,1) = kd\_int(i,1) + cs\%bckgrnd\_vdc1}
\DoxyCodeLine{399 \textcolor{keywordflow}{      endif}}
\DoxyCodeLine{400 }
\DoxyCodeLine{401       \textcolor{comment}{! North Banda Sea}}
\DoxyCodeLine{402       \textcolor{keywordflow}{if} ( (g\%geoLatT(i,j) < -1.0)  .and. (g\%geoLatT(i,j) > -4.0) .and. \&}
\DoxyCodeLine{403            ( mod(g\%geoLonT(i,j)+360.0,360.0) > 103.0) .and. \&}
\DoxyCodeLine{404            ( mod(g\%geoLonT(i,j)+360.0,360.0) < 134.0) ) \textcolor{keywordflow}{then}}
\DoxyCodeLine{405         kd\_int(i,1) = cs\%bckgrnd\_vdc\_Banda}
\DoxyCodeLine{406 \textcolor{keywordflow}{      endif}}
\DoxyCodeLine{407 }
\DoxyCodeLine{408       \textcolor{comment}{! Middle Banda Sea}}
\DoxyCodeLine{409       \textcolor{keywordflow}{if} ( (g\%geoLatT(i,j) <= -4.0) .and. (g\%geoLatT(i,j) > -7.0) .and. \&}
\DoxyCodeLine{410            ( mod(g\%geoLonT(i,j)+360.0,360.0) > 106.0) .and. \&}
\DoxyCodeLine{411            ( mod(g\%geoLonT(i,j)+360.0,360.0) < 140.0) ) \textcolor{keywordflow}{then}}
\DoxyCodeLine{412         kd\_int(i,1) = cs\%bckgrnd\_vdc\_Banda}
\DoxyCodeLine{413 \textcolor{keywordflow}{      endif}}
\DoxyCodeLine{414 }
\DoxyCodeLine{415       \textcolor{comment}{! South Banda Sea}}
\DoxyCodeLine{416       \textcolor{keywordflow}{if} ( (g\%geoLatT(i,j) <= -7.0) .and. (g\%geoLatT(i,j) > -8.3) .and. \&}
\DoxyCodeLine{417            ( mod(g\%geoLonT(i,j)+360.0,360.0) > 111.0) .and. \&}
\DoxyCodeLine{418            ( mod(g\%geoLonT(i,j)+360.0,360.0) < 142.0) ) \textcolor{keywordflow}{then}}
\DoxyCodeLine{419         kd\_int(i,1) = cs\%bckgrnd\_vdc\_Banda}
\DoxyCodeLine{420 \textcolor{keywordflow}{      endif}}
\DoxyCodeLine{421 }
\DoxyCodeLine{422 \textcolor{keywordflow}{    enddo}}
\DoxyCodeLine{423     \textcolor{comment}{! Update interior values of Kd and Kv (uniform profile; no interpolation needed)}}
\DoxyCodeLine{424     \textcolor{keywordflow}{do} k=1,nz+1 ; \textcolor{keywordflow}{do} i=is,ie}
\DoxyCodeLine{425       kd\_int(i,k) = kd\_int(i,1)}
\DoxyCodeLine{426       kv\_bkgnd(i,k) = kd\_int(i,1) * cs\%prandtl\_bkgnd}
\DoxyCodeLine{427 \textcolor{keywordflow}{    enddo} ;\textcolor{keywordflow}{ enddo}}
\DoxyCodeLine{428     \textcolor{keywordflow}{do} k=1,nz ; \textcolor{keywordflow}{do} i=is,ie}
\DoxyCodeLine{429       kd\_lay(i,k) = kd\_int(i,1)}
\DoxyCodeLine{430 \textcolor{keywordflow}{    enddo} ;\textcolor{keywordflow}{ enddo}}
\DoxyCodeLine{431 }
\DoxyCodeLine{432   \textcolor{keywordflow}{elseif} (cs\%Henyey\_IGW\_background\_new) \textcolor{keywordflow}{then}}
\DoxyCodeLine{433     i\_x30 = 2.0 / invcosh(cs\%N0\_2Omega*2.0) \textcolor{comment}{! This is evaluated at 30 deg.}}
\DoxyCodeLine{434     i\_2omega = 0.5 / cs\%omega}
\DoxyCodeLine{435     \textcolor{keywordflow}{do} k=1,nz ; \textcolor{keywordflow}{do} i=is,ie}
\DoxyCodeLine{436       abs\_sinlat = max(min\_sinlat, abs(sin(g\%geoLatT(i,j)*deg\_to\_rad)))}
\DoxyCodeLine{437       n\_2omega = max(abs\_sinlat, sqrt(n2\_lay(i,k))*i\_2omega)}
\DoxyCodeLine{438       n02\_n2 = (cs\%N0\_2Omega/n\_2omega)**2}
\DoxyCodeLine{439       kd\_lay(i,k) = max(cs\%Kd\_min, cs\%Kd * \&}
\DoxyCodeLine{440            ((abs\_sinlat * invcosh(n\_2omega/abs\_sinlat)) * i\_x30)*n02\_n2)}
\DoxyCodeLine{441 \textcolor{keywordflow}{    enddo} ;\textcolor{keywordflow}{ enddo}}
\DoxyCodeLine{442     \textcolor{comment}{! Update Kd\_int and Kv\_bkgnd, based on Kd\_lay.  These might be just used for diagnostic purposes.}}
\DoxyCodeLine{443     \textcolor{keywordflow}{do} i=is,ie}
\DoxyCodeLine{444       kd\_int(i,1) = 0.0; kv\_bkgnd(i,1) = 0.0}
\DoxyCodeLine{445       kd\_int(i,nz+1) = 0.0; kv\_bkgnd(i,nz+1) = 0.0}
\DoxyCodeLine{446 \textcolor{keywordflow}{    enddo}}
\DoxyCodeLine{447     \textcolor{keywordflow}{do} k=2,nz ; \textcolor{keywordflow}{do} i=is,ie}
\DoxyCodeLine{448       kd\_int(i,k) = 0.5*(kd\_lay(i,k-1) + kd\_lay(i,k))}
\DoxyCodeLine{449       kv\_bkgnd(i,k) = kd\_int(i,k) * cs\%prandtl\_bkgnd}
\DoxyCodeLine{450 \textcolor{keywordflow}{    enddo} ;\textcolor{keywordflow}{ enddo}}
\DoxyCodeLine{451   \textcolor{keywordflow}{else}}
\DoxyCodeLine{452     \textcolor{comment}{! Set a potentially spatially varying surface value of diffusivity.}}
\DoxyCodeLine{453     \textcolor{keywordflow}{if} (cs\%Henyey\_IGW\_background) \textcolor{keywordflow}{then}}
\DoxyCodeLine{454       i\_x30 = 2.0 / invcosh(cs\%N0\_2Omega*2.0) \textcolor{comment}{! This is evaluated at 30 deg.}}
\DoxyCodeLine{455       \textcolor{keywordflow}{do} i=is,ie}
\DoxyCodeLine{456         abs\_sinlat = abs(sin(g\%geoLatT(i,j)*deg\_to\_rad))}
\DoxyCodeLine{457         kd\_sfc(i) = max(cs\%Kd\_min, cs\%Kd * \&}
\DoxyCodeLine{458              ((abs\_sinlat * invcosh(cs\%N0\_2Omega / max(min\_sinlat, abs\_sinlat))) * i\_x30) )}
\DoxyCodeLine{459 \textcolor{keywordflow}{      enddo}}
\DoxyCodeLine{460     \textcolor{keywordflow}{elseif} (cs\%Kd\_tanh\_lat\_fn) \textcolor{keywordflow}{then}}
\DoxyCodeLine{461       \textcolor{keywordflow}{do} i=is,ie}
\DoxyCodeLine{462         \textcolor{comment}{!   The transition latitude and latitude range are hard-scaled here, since}}
\DoxyCodeLine{463         \textcolor{comment}{! this is not really intended for wide-spread use, but rather for}}
\DoxyCodeLine{464         \textcolor{comment}{! comparison with CM2M / CM2.1 settings.}}
\DoxyCodeLine{465         kd\_sfc(i) = max(cs\%Kd\_min, cs\%Kd * (1.0 + \&}
\DoxyCodeLine{466             cs\%Kd\_tanh\_lat\_scale * 0.5*tanh((abs(g\%geoLatT(i,j)) - 35.0)/5.0) ))}
\DoxyCodeLine{467 \textcolor{keywordflow}{      enddo}}
\DoxyCodeLine{468     \textcolor{keywordflow}{else} \textcolor{comment}{! Use a spatially constant surface value.}}
\DoxyCodeLine{469       \textcolor{keywordflow}{do} i=is,ie}
\DoxyCodeLine{470         kd\_sfc(i) = cs\%Kd}
\DoxyCodeLine{471 \textcolor{keywordflow}{      enddo}}
\DoxyCodeLine{472 \textcolor{keywordflow}{    endif}}
\DoxyCodeLine{473 }
\DoxyCodeLine{474     \textcolor{comment}{! Now set background diffusivies based on these surface values, possibly with vertical structure.}}
\DoxyCodeLine{475     \textcolor{keywordflow}{if} ((.not.cs\%bulkmixedlayer) .and. (cs\%Kd /= cs\%Kdml)) \textcolor{keywordflow}{then}}
\DoxyCodeLine{476       \textcolor{comment}{! This is a crude way to put in a diffusive boundary layer without an explicit boundary}}
\DoxyCodeLine{477       \textcolor{comment}{! layer turbulence scheme.  It should not be used for any realistic ocean models.}}
\DoxyCodeLine{478       i\_hmix = 1.0 / (cs\%Hmix + gv\%H\_subroundoff*gv\%H\_to\_Z)}
\DoxyCodeLine{479       \textcolor{keywordflow}{do} i=is,ie ; depth(i) = 0.0 ;\textcolor{keywordflow}{ enddo}}
\DoxyCodeLine{480       \textcolor{keywordflow}{do} k=1,nz ; \textcolor{keywordflow}{do} i=is,ie}
\DoxyCodeLine{481         depth\_c = depth(i) + 0.5*gv\%H\_to\_Z*h(i,j,k)}
\DoxyCodeLine{482         \textcolor{keywordflow}{if} (cs\%Kd\_via\_Kdml\_bug) \textcolor{keywordflow}{then}}
\DoxyCodeLine{483           \textcolor{comment}{! These two lines should update Kd\_lay, not Kd\_int.  They were correctly working on the}}
\DoxyCodeLine{484           \textcolor{comment}{! same variables until MOM6 commit 7a818716 (PR\#750), which was added on March 26, 2018.}}
\DoxyCodeLine{485           \textcolor{keywordflow}{if} (depth\_c <= cs\%Hmix) \textcolor{keywordflow}{then} ; kd\_int(i,k) = cs\%Kdml}
\DoxyCodeLine{486           \textcolor{keywordflow}{elseif} (depth\_c >= 2.0*cs\%Hmix) \textcolor{keywordflow}{then} ; kd\_int(i,k) = kd\_sfc(i)}
\DoxyCodeLine{487           \textcolor{keywordflow}{else}}
\DoxyCodeLine{488             kd\_lay(i,k) = ((kd\_sfc(i) - cs\%Kdml) * i\_hmix) * depth\_c + (2.0*cs\%Kdml - kd\_sfc(i))}
\DoxyCodeLine{489 \textcolor{keywordflow}{          endif}}
\DoxyCodeLine{490         \textcolor{keywordflow}{else}}
\DoxyCodeLine{491           \textcolor{keywordflow}{if} (depth\_c <= cs\%Hmix) \textcolor{keywordflow}{then} ; kd\_lay(i,k) = cs\%Kdml}
\DoxyCodeLine{492           \textcolor{keywordflow}{elseif} (depth\_c >= 2.0*cs\%Hmix) \textcolor{keywordflow}{then} ; kd\_lay(i,k) = kd\_sfc(i)}
\DoxyCodeLine{493           \textcolor{keywordflow}{else}}
\DoxyCodeLine{494             kd\_lay(i,k) = ((kd\_sfc(i) - cs\%Kdml) * i\_hmix) * depth\_c + (2.0*cs\%Kdml - kd\_sfc(i))}
\DoxyCodeLine{495 \textcolor{keywordflow}{          endif}}
\DoxyCodeLine{496 \textcolor{keywordflow}{        endif}}
\DoxyCodeLine{497 }
\DoxyCodeLine{498         depth(i) = depth(i) + gv\%H\_to\_Z*h(i,j,k)}
\DoxyCodeLine{499 \textcolor{keywordflow}{      enddo} ;\textcolor{keywordflow}{ enddo}}
\DoxyCodeLine{500 }
\DoxyCodeLine{501     \textcolor{keywordflow}{else} \textcolor{comment}{! There is no vertical structure to the background diffusivity.}}
\DoxyCodeLine{502       \textcolor{keywordflow}{do} k=1,nz ; \textcolor{keywordflow}{do} i=is,ie}
\DoxyCodeLine{503         kd\_lay(i,k) = kd\_sfc(i)}
\DoxyCodeLine{504 \textcolor{keywordflow}{      enddo} ;\textcolor{keywordflow}{ enddo}}
\DoxyCodeLine{505 \textcolor{keywordflow}{    endif}}
\DoxyCodeLine{506 }
\DoxyCodeLine{507     \textcolor{comment}{! Update Kd\_int and Kv\_bkgnd, based on Kd\_lay.  These might be just used for diagnostic purposes.}}
\DoxyCodeLine{508     \textcolor{keywordflow}{do} i=is,ie}
\DoxyCodeLine{509       kd\_int(i,1) = 0.0; kv\_bkgnd(i,1) = 0.0}
\DoxyCodeLine{510       kd\_int(i,nz+1) = 0.0; kv\_bkgnd(i,nz+1) = 0.0}
\DoxyCodeLine{511 \textcolor{keywordflow}{    enddo}}
\DoxyCodeLine{512     \textcolor{keywordflow}{do} k=2,nz ; \textcolor{keywordflow}{do} i=is,ie}
\DoxyCodeLine{513       kd\_int(i,k) = 0.5*(kd\_lay(i,k-1) + kd\_lay(i,k))}
\DoxyCodeLine{514       kv\_bkgnd(i,k) = kd\_int(i,k) * cs\%prandtl\_bkgnd}
\DoxyCodeLine{515 \textcolor{keywordflow}{    enddo} ;\textcolor{keywordflow}{ enddo}}
\DoxyCodeLine{516 \textcolor{keywordflow}{  endif}}
\DoxyCodeLine{517 }

\end{DoxyCode}
\mbox{\Hypertarget{namespacemom__bkgnd__mixing_a829d5b6f715c06b6566a49271d4a7217}\label{namespacemom__bkgnd__mixing_a829d5b6f715c06b6566a49271d4a7217}} 
\index{mom\_bkgnd\_mixing@{mom\_bkgnd\_mixing}!check\_bkgnd\_scheme@{check\_bkgnd\_scheme}}
\index{check\_bkgnd\_scheme@{check\_bkgnd\_scheme}!mom\_bkgnd\_mixing@{mom\_bkgnd\_mixing}}
\subsubsection{\texorpdfstring{check\_bkgnd\_scheme()}{check\_bkgnd\_scheme()}}
{\footnotesize\ttfamily subroutine mom\+\_\+bkgnd\+\_\+mixing\+::check\+\_\+bkgnd\+\_\+scheme (\begin{DoxyParamCaption}\item[{type(\mbox{\hyperlink{structmom__bkgnd__mixing_1_1bkgnd__mixing__cs}{bkgnd\+\_\+mixing\+\_\+cs}}), pointer}]{CS,  }\item[{character(len=$\ast$), intent(in)}]{str }\end{DoxyParamCaption})\hspace{0.3cm}{\ttfamily [private]}}



Sets CSbkgnd\+\_\+scheme\+\_\+str to check whether multiple background diffusivity schemes are activated. The string is also for error/log messages. 


\begin{DoxyParams}[1]{Parameters}
 & {\em cs} & Control structure \\
\hline
\mbox{\texttt{ in}}  & {\em str} & Background scheme identifier deducted from M\+O\+M\+\_\+input parameters \\
\hline
\end{DoxyParams}


Definition at line 533 of file M\+O\+M\+\_\+bkgnd\+\_\+mixing.\+F90.


\begin{DoxyCode}{0}
\DoxyCodeLine{533   \textcolor{keywordtype}{type}(bkgnd\_mixing\_cs), \textcolor{keywordtype}{pointer} :: CS\textcolor{comment}{  !< Control structure}}
\DoxyCodeLine{534   \textcolor{keywordtype}{character(len=*)}, \textcolor{keywordtype}{intent(in)}   :: str\textcolor{comment}{ !< Background scheme identifier deducted from MOM\_input}}
\DoxyCodeLine{535 \textcolor{comment}{                                        !! parameters}}
\DoxyCodeLine{536 }
\DoxyCodeLine{537   \textcolor{keywordflow}{if} (trim(cs\%bkgnd\_scheme\_str)==\textcolor{stringliteral}{"none"}) \textcolor{keywordflow}{then}}
\DoxyCodeLine{538     cs\%bkgnd\_scheme\_str = str}
\DoxyCodeLine{539   \textcolor{keywordflow}{else}}
\DoxyCodeLine{540     \textcolor{keyword}{call }mom\_error(fatal, \textcolor{stringliteral}{"bkgnd\_mixing\_init: Cannot activate both "}//trim(str)//\textcolor{stringliteral}{" and "}//\&}
\DoxyCodeLine{541                    trim(cs\%bkgnd\_scheme\_str)//\textcolor{stringliteral}{"."})}
\DoxyCodeLine{542 \textcolor{keywordflow}{  endif}}
\DoxyCodeLine{543 }

\end{DoxyCode}
\mbox{\Hypertarget{namespacemom__bkgnd__mixing_a213f9ed7daae9b060fb781c74de824dc}\label{namespacemom__bkgnd__mixing_a213f9ed7daae9b060fb781c74de824dc}} 
\index{mom\_bkgnd\_mixing@{mom\_bkgnd\_mixing}!cvmix\_bkgnd\_is\_used@{cvmix\_bkgnd\_is\_used}}
\index{cvmix\_bkgnd\_is\_used@{cvmix\_bkgnd\_is\_used}!mom\_bkgnd\_mixing@{mom\_bkgnd\_mixing}}
\subsubsection{\texorpdfstring{cvmix\_bkgnd\_is\_used()}{cvmix\_bkgnd\_is\_used()}}
{\footnotesize\ttfamily logical function mom\+\_\+bkgnd\+\_\+mixing\+::cvmix\+\_\+bkgnd\+\_\+is\+\_\+used (\begin{DoxyParamCaption}\item[{type(param\+\_\+file\+\_\+type), intent(in)}]{param\+\_\+file }\end{DoxyParamCaption})\hspace{0.3cm}{\ttfamily [private]}}



Reads the parameter \char`\"{}\+U\+S\+E\+\_\+\+C\+V\+Mix\+\_\+\+B\+A\+C\+K\+G\+R\+O\+U\+N\+D\char`\"{} and returns state. This function allows other modules to know whether this parameterization will be used without needing to duplicate the log entry. 


\begin{DoxyParams}[1]{Parameters}
\mbox{\texttt{ in}}  & {\em param\+\_\+file} & A structure to parse for run-\/time parameters \\
\hline
\end{DoxyParams}


Definition at line 524 of file M\+O\+M\+\_\+bkgnd\+\_\+mixing.\+F90.


\begin{DoxyCode}{0}
\DoxyCodeLine{524   \textcolor{keywordtype}{type}(param\_file\_type), \textcolor{keywordtype}{intent(in)} :: param\_file\textcolor{comment}{ !< A structure to parse for run-time parameters}}
\DoxyCodeLine{525   \textcolor{keyword}{call }get\_param(param\_file, mdl, \textcolor{stringliteral}{"USE\_CVMix\_BACKGROUND"}, cvmix\_bkgnd\_is\_used, \&}
\DoxyCodeLine{526                  default=.false., do\_not\_log = .true.)}
\DoxyCodeLine{527 }

\end{DoxyCode}
