\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}
548   \textcolor{keywordtype}{type}(bkgnd\_mixing\_cs), \textcolor{keywordtype}{pointer} :: CS\textcolor{comment}{ !< Control structure for this module that}
549 \textcolor{comment}{                                       !! will be deallocated in this subroutine}
550 
551   \textcolor{keywordflow}{if} (.not. \textcolor{keyword}{associated}(cs)) \textcolor{keywordflow}{return}
552   \textcolor{keyword}{deallocate}(cs)
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{\tt in}  & {\em time} & The current time.\\
\hline
\mbox{\tt in}  & {\em g} & Grid structure.\\
\hline
\mbox{\tt in}  & {\em gv} & Vertical grid structure.\\
\hline
\mbox{\tt in}  & {\em us} & A dimensional unit scaling type\\
\hline
\mbox{\tt in}  & {\em param\+\_\+file} & Run-\/time parameter file handle\\
\hline
\mbox{\tt in,out}  & {\em diag} & Diagnostics control structure.\\
\hline
 & {\em cs} & This module\textquotesingle{}s control structure. \\
\hline
\end{DoxyParams}


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


\begin{DoxyCode}
114 
115   \textcolor{keywordtype}{type}(time\_type),         \textcolor{keywordtype}{intent(in)}    :: Time\textcolor{comment}{       !< The current time.}
116   \textcolor{keywordtype}{type}(ocean\_grid\_type),   \textcolor{keywordtype}{intent(in)}    :: G\textcolor{comment}{          !< Grid structure.}
117   \textcolor{keywordtype}{type}(verticalGrid\_type), \textcolor{keywordtype}{intent(in)}    :: GV\textcolor{comment}{         !< Vertical grid structure.}
118   \textcolor{keywordtype}{type}(unit\_scale\_type),   \textcolor{keywordtype}{intent(in)}    :: US\textcolor{comment}{         !< A dimensional unit scaling type}
119   \textcolor{keywordtype}{type}(param\_file\_type),   \textcolor{keywordtype}{intent(in)}    :: param\_file\textcolor{comment}{ !< Run-time parameter file handle}
120   \textcolor{keywordtype}{type}(diag\_ctrl), \textcolor{keywordtype}{target}, \textcolor{keywordtype}{intent(inout)} :: diag\textcolor{comment}{       !< Diagnostics control structure.}
121   \textcolor{keywordtype}{type}(bkgnd\_mixing\_cs),    \textcolor{keywordtype}{pointer}      :: CS\textcolor{comment}{         !< This module's control structure.}
122 
123   \textcolor{comment}{! Local variables}
124   \textcolor{keywordtype}{real} :: Kv                    \textcolor{comment}{! The interior vertical viscosity [Z2 T-1 ~> m2 s-1] - read to set Prandtl}
125                                 \textcolor{comment}{! number unless it is provided as a parameter}
126   \textcolor{keywordtype}{real} :: prandtl\_bkgnd\_comp    \textcolor{comment}{! Kv/CS%Kd. Gets compared with user-specified prandtl\_bkgnd.}
127 
128 \textcolor{comment}{! This include declares and sets the variable "version".}
129 \textcolor{preprocessor}{#include "version\_variable.h"}
130 \textcolor{preprocessor}{}
131   \textcolor{keywordflow}{if} (\textcolor{keyword}{associated}(cs)) \textcolor{keywordflow}{then}
132     \textcolor{keyword}{call }mom\_error(warning, \textcolor{stringliteral}{"bkgnd\_mixing\_init called with an associated "}// &
133                             \textcolor{stringliteral}{"control structure."})
134     \textcolor{keywordflow}{return}
135 \textcolor{keywordflow}{  endif}
136   \textcolor{keyword}{allocate}(cs)
137 
138   \textcolor{comment}{! Read parameters}
139   \textcolor{keyword}{call }log\_version(param\_file, mdl, version, &
140     \textcolor{stringliteral}{"Adding static vertical background mixing coefficients"})
141 
142   \textcolor{keyword}{call }get\_param(param\_file, mdl, \textcolor{stringliteral}{"KD"}, cs%Kd, &
143                  \textcolor{stringliteral}{"The background diapycnal diffusivity of density in the "}//&
144                  \textcolor{stringliteral}{"interior. Zero or the molecular value, ~1e-7 m2 s-1, "}//&
145                  \textcolor{stringliteral}{"may be used."}, default=0.0, units=\textcolor{stringliteral}{"m2 s-1"}, scale=us%m2\_s\_to\_Z2\_T)
146 
147   \textcolor{keyword}{call }get\_param(param\_file, mdl, \textcolor{stringliteral}{"KV"}, kv, &
148                  \textcolor{stringliteral}{"The background kinematic viscosity in the interior. "}//&
149                  \textcolor{stringliteral}{"The molecular value, ~1e-6 m2 s-1, may be used."}, &
150                  units=\textcolor{stringliteral}{"m2 s-1"}, scale=us%m2\_s\_to\_Z2\_T, fail\_if\_missing=.true.)
151 
152   \textcolor{keyword}{call }get\_param(param\_file, mdl, \textcolor{stringliteral}{"KD\_MIN"}, cs%Kd\_min, &
153                  \textcolor{stringliteral}{"The minimum diapycnal diffusivity."}, &
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)
155 
156   \textcolor{comment}{! The following is needed to set one of the choices of vertical background mixing}
157 
158   \textcolor{comment}{! BULKMIXEDLAYER is not always defined (e.g., CM2G63L), so the following line by passes}
159   \textcolor{comment}{! the need to include BULKMIXEDLAYER in MOM\_input}
160   cs%bulkmixedlayer = (gv%nkml > 0)
161   \textcolor{keywordflow}{if} (cs%bulkmixedlayer) \textcolor{keywordflow}{then}
162     \textcolor{comment}{! Check that Kdml is not set when using bulk mixed layer}
163     \textcolor{keyword}{call }get\_param(param\_file, mdl, \textcolor{stringliteral}{"KDML"}, cs%Kdml, default=-1.)
164     \textcolor{keywordflow}{if} (cs%Kdml>0.) \textcolor{keyword}{call }mom\_error(fatal, &
165                  \textcolor{stringliteral}{"bkgnd\_mixing\_init: KDML cannot be set when using bulk mixed layer."})
166     cs%Kdml = cs%Kd \textcolor{comment}{! This is not used with a bulk mixed layer, but also cannot be a NaN.}
167   \textcolor{keywordflow}{else}
168     \textcolor{keyword}{call }get\_param(param\_file, mdl, \textcolor{stringliteral}{"KDML"}, cs%Kdml, &
169                  \textcolor{stringliteral}{"If BULKMIXEDLAYER is false, KDML is the elevated "}//&
170                  \textcolor{stringliteral}{"diapycnal diffusivity in the topmost HMIX of fluid. "}//&
171                  \textcolor{stringliteral}{"KDML is only used if BULKMIXEDLAYER is false."}, &
172                  units=\textcolor{stringliteral}{"m2 s-1"}, default=cs%Kd*us%Z2\_T\_to\_m2\_s, scale=us%m2\_s\_to\_Z2\_T)
173     \textcolor{keyword}{call }get\_param(param\_file, mdl, \textcolor{stringliteral}{"HMIX\_FIXED"}, cs%Hmix, &
174                  \textcolor{stringliteral}{"The prescribed depth over which the near-surface "}//&
175                  \textcolor{stringliteral}{"viscosity and diffusivity are elevated when the bulk "}//&
176                  \textcolor{stringliteral}{"mixed layer is not used."}, units=\textcolor{stringliteral}{"m"}, scale=us%m\_to\_Z, fail\_if\_missing=.true.)
177 \textcolor{keywordflow}{  endif}
178 
179   \textcolor{keyword}{call }get\_param(param\_file, mdl, \textcolor{stringliteral}{'DEBUG'}, cs%debug, default=.false., do\_not\_log=.true.)
180 
181 \textcolor{comment}{!  call openParameterBlock(param\_file,'MOM\_BACKGROUND\_MIXING')}
182 
183   \textcolor{keyword}{call }get\_param(param\_file, mdl, \textcolor{stringliteral}{"BRYAN\_LEWIS\_DIFFUSIVITY"}, cs%Bryan\_Lewis\_diffusivity, &
184                  \textcolor{stringliteral}{"If true, use a Bryan & Lewis (JGR 1979) like tanh "}//&
185                  \textcolor{stringliteral}{"profile of background diapycnal diffusivity with depth. "}//&
186                  \textcolor{stringliteral}{"This is done via CVMix."}, default=.false.)
187 
188   \textcolor{keywordflow}{if} (cs%Bryan\_Lewis\_diffusivity) \textcolor{keywordflow}{then}
189     \textcolor{keyword}{call }check\_bkgnd\_scheme(cs, \textcolor{stringliteral}{"BRYAN\_LEWIS\_DIFFUSIVITY"})
190 
191     \textcolor{keyword}{call }get\_param(param\_file, mdl, \textcolor{stringliteral}{"BRYAN\_LEWIS\_C1"}, cs%Bryan\_Lewis\_c1, &
192                    \textcolor{stringliteral}{"The vertical diffusivity values for Bryan-Lewis profile at |z|=D."}, &
193                    units=\textcolor{stringliteral}{"m2 s-1"}, fail\_if\_missing=.true.)
194 
195     \textcolor{keyword}{call }get\_param(param\_file, mdl, \textcolor{stringliteral}{"BRYAN\_LEWIS\_C2"}, cs%Bryan\_Lewis\_c2, &
196                    \textcolor{stringliteral}{"The amplitude of variation in diffusivity for the Bryan-Lewis profile"}, &
197                    units=\textcolor{stringliteral}{"m2 s-1"}, fail\_if\_missing=.true.)
198 
199     \textcolor{keyword}{call }get\_param(param\_file, mdl, \textcolor{stringliteral}{"BRYAN\_LEWIS\_C3"}, cs%Bryan\_Lewis\_c3, &
200                    \textcolor{stringliteral}{"The inverse length scale for transition region in the Bryan-Lewis profile"}, &
201                    units=\textcolor{stringliteral}{"m-1"}, fail\_if\_missing=.true.)
202 
203     \textcolor{keyword}{call }get\_param(param\_file, mdl, \textcolor{stringliteral}{"BRYAN\_LEWIS\_C4"}, cs%Bryan\_Lewis\_c4, &
204                    \textcolor{stringliteral}{"The depth where diffusivity is BRYAN\_LEWIS\_C1 in the Bryan-Lewis profile"},&
205                    units=\textcolor{stringliteral}{"m"}, fail\_if\_missing=.true.)
206 
207 \textcolor{keywordflow}{  endif} \textcolor{comment}{! CS%Bryan\_Lewis\_diffusivity}
208 
209   \textcolor{keyword}{call }get\_param(param\_file, mdl, \textcolor{stringliteral}{"HORIZ\_VARYING\_BACKGROUND"}, cs%horiz\_varying\_background, &
210                  \textcolor{stringliteral}{"If true, apply vertically uniform, latitude-dependent background "}//&
211                  \textcolor{stringliteral}{"diffusivity, as described in Danabasoglu et al., 2012"}, &
212                  default=.false.)
213 
214   \textcolor{keywordflow}{if} (cs%horiz\_varying\_background) \textcolor{keywordflow}{then}
215     \textcolor{keyword}{call }check\_bkgnd\_scheme(cs, \textcolor{stringliteral}{"HORIZ\_VARYING\_BACKGROUND"})
216 
217     \textcolor{keyword}{call }get\_param(param\_file, mdl, \textcolor{stringliteral}{"BCKGRND\_VDC1"}, cs%bckgrnd\_vdc1, &
218                    \textcolor{stringliteral}{"Background diffusivity (Ledwell) when HORIZ\_VARYING\_BACKGROUND=True"}, &
219                    units=\textcolor{stringliteral}{"m2 s-1"},default = 0.16e-04, scale=us%m2\_s\_to\_Z2\_T)
220 
221     \textcolor{keyword}{call }get\_param(param\_file, mdl, \textcolor{stringliteral}{"BCKGRND\_VDC\_EQ"}, cs%bckgrnd\_vdc\_eq, &
222                    \textcolor{stringliteral}{"Equatorial diffusivity (Gregg) when HORIZ\_VARYING\_BACKGROUND=True"}, &
223                    units=\textcolor{stringliteral}{"m2 s-1"},default = 0.01e-04, scale=us%m2\_s\_to\_Z2\_T)
224 
225     \textcolor{keyword}{call }get\_param(param\_file, mdl, \textcolor{stringliteral}{"BCKGRND\_VDC\_PSIM"}, cs%bckgrnd\_vdc\_psim, &
226                    \textcolor{stringliteral}{"Max. PSI induced diffusivity (MacKinnon) when HORIZ\_VARYING\_BACKGROUND=True"}, &
227                    units=\textcolor{stringliteral}{"m2 s-1"},default = 0.13e-4, scale=us%m2\_s\_to\_Z2\_T)
228 
229     \textcolor{keyword}{call }get\_param(param\_file, mdl, \textcolor{stringliteral}{"BCKGRND\_VDC\_BAN"}, cs%bckgrnd\_vdc\_Banda, &
230                    \textcolor{stringliteral}{"Banda Sea diffusivity (Gordon) when HORIZ\_VARYING\_BACKGROUND=True"}, &
231                    units=\textcolor{stringliteral}{"m2 s-1"},default = 1.0e-4, scale=us%m2\_s\_to\_Z2\_T)
232 \textcolor{keywordflow}{  endif}
233 
234   \textcolor{keyword}{call }get\_param(param\_file, mdl, \textcolor{stringliteral}{"PRANDTL\_BKGND"}, cs%prandtl\_bkgnd, &
235                  \textcolor{stringliteral}{"Turbulent Prandtl number used to convert vertical "}//&
236                  \textcolor{stringliteral}{"background diffusivities into viscosities."}, &
237                  units=\textcolor{stringliteral}{"nondim"}, default=1.0)
238 
239   \textcolor{keywordflow}{if} (cs%Bryan\_Lewis\_diffusivity .or. cs%horiz\_varying\_background) \textcolor{keywordflow}{then}
240     prandtl\_bkgnd\_comp = cs%prandtl\_bkgnd
241     \textcolor{keywordflow}{if} (cs%Kd /= 0.0) prandtl\_bkgnd\_comp = kv / cs%Kd
242 
243     \textcolor{keywordflow}{if} ( abs(cs%prandtl\_bkgnd - prandtl\_bkgnd\_comp)>1.e-14) \textcolor{keywordflow}{then}
244       \textcolor{keyword}{call }mom\_error(fatal, \textcolor{stringliteral}{"bkgnd\_mixing\_init: The provided KD, KV and PRANDTL\_BKGND values "}//&
245                             \textcolor{stringliteral}{"are incompatible. The following must hold: KD*PRANDTL\_BKGND==KV"})
246 \textcolor{keywordflow}{    endif}
247 \textcolor{keywordflow}{  endif}
248 
249   \textcolor{keyword}{call }get\_param(param\_file, mdl, \textcolor{stringliteral}{"HENYEY\_IGW\_BACKGROUND"}, cs%Henyey\_IGW\_background, &
250                  \textcolor{stringliteral}{"If true, use a latitude-dependent scaling for the near "}//&
251                  \textcolor{stringliteral}{"surface background diffusivity, as described in "}//&
252                  \textcolor{stringliteral}{"Harrison & Hallberg, JPO 2008."}, default=.false.)
253   \textcolor{keywordflow}{if} (cs%Henyey\_IGW\_background) \textcolor{keyword}{call }check\_bkgnd\_scheme(cs, \textcolor{stringliteral}{"HENYEY\_IGW\_BACKGROUND"})
254 
255 
256   \textcolor{keyword}{call }get\_param(param\_file, mdl, \textcolor{stringliteral}{"HENYEY\_IGW\_BACKGROUND\_NEW"}, cs%Henyey\_IGW\_background\_new, &
257                  \textcolor{stringliteral}{"If true, use a better latitude-dependent scaling for the "}//&
258                  \textcolor{stringliteral}{"background diffusivity, as described in "}//&
259                  \textcolor{stringliteral}{"Harrison & Hallberg, JPO 2008."}, default=.false.)
260   \textcolor{keywordflow}{if} (cs%Henyey\_IGW\_background\_new) \textcolor{keyword}{call }check\_bkgnd\_scheme(cs, \textcolor{stringliteral}{"HENYEY\_IGW\_BACKGROUND\_NEW"})
261 
262   \textcolor{keywordflow}{if} (cs%Kd>0.0 .and. (trim(cs%bkgnd\_scheme\_str)==\textcolor{stringliteral}{"BRYAN\_LEWIS\_DIFFUSIVITY"} .or.&
263                           trim(cs%bkgnd\_scheme\_str)==\textcolor{stringliteral}{"HORIZ\_VARYING\_BACKGROUND"} )) \textcolor{keywordflow}{then}
264     \textcolor{keyword}{call }mom\_error(warning, \textcolor{stringliteral}{"bkgnd\_mixing\_init: a nonzero constant background "}//&
265          \textcolor{stringliteral}{"diffusivity (KD) is specified along with "}//trim(cs%bkgnd\_scheme\_str))
266 \textcolor{keywordflow}{  endif}
267 
268   \textcolor{keywordflow}{if} (cs%Henyey\_IGW\_background) \textcolor{keywordflow}{then}
269     \textcolor{keyword}{call }get\_param(param\_file, mdl, \textcolor{stringliteral}{"HENYEY\_N0\_2OMEGA"}, cs%N0\_2Omega, &
270                   \textcolor{stringliteral}{"The ratio of the typical Buoyancy frequency to twice "}//&
271                   \textcolor{stringliteral}{"the Earth's rotation period, used with the Henyey "}//&
272                   \textcolor{stringliteral}{"scaling from the mixing."}, units=\textcolor{stringliteral}{"nondim"}, default=20.0)
273     \textcolor{keyword}{call }get\_param(param\_file, mdl, \textcolor{stringliteral}{"OMEGA"}, cs%omega, &
274                  \textcolor{stringliteral}{"The rotation rate of the earth."}, units=\textcolor{stringliteral}{"s-1"}, &
275                  default=7.2921e-5, scale=us%T\_to\_s)
276 \textcolor{keywordflow}{  endif}
277 
278   \textcolor{keyword}{call }get\_param(param\_file, mdl, \textcolor{stringliteral}{"KD\_TANH\_LAT\_FN"}, cs%Kd\_tanh\_lat\_fn, &
279                  \textcolor{stringliteral}{"If true, use a tanh dependence of Kd\_sfc on latitude, "}//&
280                  \textcolor{stringliteral}{"like CM2.1/CM2M.  There is no physical justification "}//&
281                  \textcolor{stringliteral}{"for this form, and it can not be used with "}//&
282                  \textcolor{stringliteral}{"HENYEY\_IGW\_BACKGROUND."}, default=.false.)
283 
284   \textcolor{keywordflow}{if} (cs%Kd\_tanh\_lat\_fn) &
285     \textcolor{keyword}{call }get\_param(param\_file, mdl, \textcolor{stringliteral}{"KD\_TANH\_LAT\_SCALE"}, cs%Kd\_tanh\_lat\_scale, &
286                  \textcolor{stringliteral}{"A nondimensional scaling for the range ofdiffusivities "}//&
287                  \textcolor{stringliteral}{"with KD\_TANH\_LAT\_FN. Valid values are in the range of "}//&
288                  \textcolor{stringliteral}{"-2 to 2; 0.4 reproduces CM2M."}, units=\textcolor{stringliteral}{"nondim"}, default=0.0)
289 
290   \textcolor{keywordflow}{if} (cs%Henyey\_IGW\_background .and. cs%Kd\_tanh\_lat\_fn) \textcolor{keyword}{call }mom\_error(fatal, &
291     \textcolor{stringliteral}{"MOM\_bkgnd\_mixing: KD\_TANH\_LAT\_FN can not be used with HENYEY\_IGW\_BACKGROUND."})
292 
293   cs%Kd\_via\_Kdml\_bug = .false.
294   \textcolor{keywordflow}{if} ((cs%Kd /= cs%Kdml) .and. .not.(cs%Kd\_tanh\_lat\_fn .or. cs%bulkmixedlayer .or. &
295                                      cs%Henyey\_IGW\_background .or. cs%Henyey\_IGW\_background\_new .or. &
296                                      cs%horiz\_varying\_background .or. cs%Bryan\_Lewis\_diffusivity)) \textcolor{keywordflow}{then}
297     \textcolor{keyword}{call }get\_param(param\_file, mdl, \textcolor{stringliteral}{"KD\_BACKGROUND\_VIA\_KDML\_BUG"}, cs%Kd\_via\_Kdml\_bug, &
298                  \textcolor{stringliteral}{"If true and KDML /= KD and several other conditions apply, the background "}//&
299                  \textcolor{stringliteral}{"diffusivity is set incorrectly using a bug that was introduced in March, 2018."}, &
300                  default=.true.)  \textcolor{comment}{! The default should be changed to false and this parameter obsoleted.}
301 \textcolor{keywordflow}{  endif}
302 
303 \textcolor{comment}{!  call closeParameterBlock(param\_file)}
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{\tt in}  & {\em g} & Grid structure.\\
\hline
\mbox{\tt in}  & {\em gv} & Vertical grid structure.\\
\hline
\mbox{\tt in}  & {\em h} & Layer thickness \mbox{[}H $\sim$$>$ m or kg m-\/2\mbox{]}.\\
\hline
\mbox{\tt in}  & {\em tv} & Thermodynamics structure.\\
\hline
\mbox{\tt in}  & {\em n2\+\_\+lay} & squared buoyancy frequency associated with layers \mbox{[}T-\/2 $\sim$$>$ s-\/2\mbox{]}\\
\hline
\mbox{\tt out}  & {\em kd\+\_\+lay} & The background diapycnal diffusivity of each layer \mbox{[}Z2 T-\/1 $\sim$$>$ m2 s-\/1\mbox{]}.\\
\hline
\mbox{\tt out}  & {\em kd\+\_\+int} & The background diapycnal diffusivity of each interface \mbox{[}Z2 T-\/1 $\sim$$>$ m2 s-\/1\mbox{]}.\\
\hline
\mbox{\tt out}  & {\em kv\+\_\+bkgnd} & The background vertical viscosity at each interface \mbox{[}Z2 T-\/1 $\sim$$>$ m2 s-\/1\mbox{]}\\
\hline
\mbox{\tt in}  & {\em j} & Meridional grid index\\
\hline
\mbox{\tt 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}
309 
310   \textcolor{keywordtype}{type}(ocean\_grid\_type),                     \textcolor{keywordtype}{intent(in)}    :: G\textcolor{comment}{   !< Grid structure.}
311   \textcolor{keywordtype}{type}(verticalGrid\_type),                   \textcolor{keywordtype}{intent(in)}    :: GV\textcolor{comment}{  !< Vertical grid structure.}
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].}
313   \textcolor{keywordtype}{type}(thermo\_var\_ptrs),                     \textcolor{keywordtype}{intent(in)}    :: tv\textcolor{comment}{  !< Thermodynamics structure.}
314   \textcolor{keywordtype}{real}, \textcolor{keywordtype}{dimension(SZI\_(G),SZK\_(GV))},         \textcolor{keywordtype}{intent(in)}    :: N2\_lay\textcolor{comment}{ !< squared buoyancy frequency
       associated}
315 \textcolor{comment}{                                                                  !! with layers [T-2 ~> s-2]}
316   \textcolor{keywordtype}{real}, \textcolor{keywordtype}{dimension(SZI\_(G),SZK\_(GV))},         \textcolor{keywordtype}{intent(out)}   :: Kd\_lay\textcolor{comment}{ !< The background diapycnal
       diffusivity}
317 \textcolor{comment}{                                                                  !! of each layer [Z2 T-1 ~> m2 s-1].}
318   \textcolor{keywordtype}{real}, \textcolor{keywordtype}{dimension(SZI\_(G),SZK\_(GV)+1)},       \textcolor{keywordtype}{intent(out)}   :: Kd\_int\textcolor{comment}{ !< The background diapycnal
       diffusivity}
319 \textcolor{comment}{                                                                  !! of each interface [Z2 T-1 ~> m2 s-1].}
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}
321 \textcolor{comment}{                                                                  !! each interface [Z2 T-1 ~> m2 s-1]}
322   \textcolor{keywordtype}{integer},                                   \textcolor{keywordtype}{intent(in)}    :: j\textcolor{comment}{   !< Meridional grid index}
323   \textcolor{keywordtype}{type}(unit\_scale\_type),                     \textcolor{keywordtype}{intent(in)}    :: US\textcolor{comment}{  !< A dimensional unit scaling type}
324   \textcolor{keywordtype}{type}(bkgnd\_mixing\_cs),                     \textcolor{keywordtype}{pointer}       :: CS\textcolor{comment}{  !< The control structure returned by}
325 \textcolor{comment}{                                                                  !! a previous call to bkgnd\_mixing\_init.}
326 
327   \textcolor{comment}{! local variables}
328   \textcolor{keywordtype}{real}, \textcolor{keywordtype}{dimension(SZK\_(GV)+1)} :: depth\_int\textcolor{comment}{  !< Distance from surface of the interfaces [m]}
329   \textcolor{keywordtype}{real}, \textcolor{keywordtype}{dimension(SZK\_(GV)+1)} :: Kd\_col\textcolor{comment}{     !< Diffusivities at the interfaces [m2 s-1]}
330   \textcolor{keywordtype}{real}, \textcolor{keywordtype}{dimension(SZK\_(GV)+1)} :: Kv\_col\textcolor{comment}{     !< Viscosities at the interfaces [m2 s-1]}
331   \textcolor{keywordtype}{real}, \textcolor{keywordtype}{dimension(SZI\_(G))}    :: Kd\_sfc\textcolor{comment}{     !< Surface value of the diffusivity [Z2 T-1 ~> m2 s-1]}
332   \textcolor{keywordtype}{real}, \textcolor{keywordtype}{dimension(SZI\_(G))}    :: depth\textcolor{comment}{      !< Distance from surface of an interface [Z ~> m]}
333   \textcolor{keywordtype}{real} :: depth\_c\textcolor{comment}{    !< depth of the center of a layer [Z ~> m]}
334   \textcolor{keywordtype}{real} :: I\_Hmix\textcolor{comment}{     !< inverse of fixed mixed layer thickness [Z-1 ~> m-1]}
335   \textcolor{keywordtype}{real} :: I\_2Omega\textcolor{comment}{   !< 1/(2 Omega) [T ~> s]}
336   \textcolor{keywordtype}{real} :: N\_2Omega   \textcolor{comment}{!  The ratio of the stratification to the Earth's rotation rate [nondim]}
337   \textcolor{keywordtype}{real} :: N02\_N2     \textcolor{comment}{!  The ratio a reference stratification to the actual stratification [nondim]}
338   \textcolor{keywordtype}{real} :: I\_x30\textcolor{comment}{      !< 2/acos(2) = 1/(sin(30 deg) * acosh(1/sin(30 deg)))}
339   \textcolor{keywordtype}{real} :: deg\_to\_rad\textcolor{comment}{ !< factor converting degrees to radians, pi/180.}
340   \textcolor{keywordtype}{real} :: abs\_sinlat\textcolor{comment}{ !< absolute value of sine of latitude [nondim]}
341   \textcolor{keywordtype}{real} :: min\_sinlat \textcolor{comment}{! The minimum value of the sine of latitude [nondim]}
342   \textcolor{keywordtype}{real} :: bckgrnd\_vdc\_psin\textcolor{comment}{ !< PSI diffusivity in northern hemisphere [Z2 T-1 ~> m2 s-1]}
343   \textcolor{keywordtype}{real} :: bckgrnd\_vdc\_psis\textcolor{comment}{ !< PSI diffusivity in southern hemisphere [Z2 T-1 ~> m2 s-1]}
344   \textcolor{keywordtype}{integer} :: i, k, is, ie, js, je, nz
345 
346   is  = g%isc ; ie  = g%iec ; js  = g%jsc ; je  = g%jec ; nz = g%ke
347 
348   \textcolor{comment}{! set some parameters}
349   deg\_to\_rad = atan(1.0)/45.0 \textcolor{comment}{! = PI/180}
350   min\_sinlat = 1.e-10
351 
352   \textcolor{comment}{! Start with a constant value that may be replaced below.}
353   kd\_lay(:,:) = cs%Kd
354   kv\_bkgnd(:,:) = 0.0
355 
356   \textcolor{comment}{! Set up the background diffusivity.}
357   \textcolor{keywordflow}{if} (cs%Bryan\_Lewis\_diffusivity) \textcolor{keywordflow}{then}
358 
359     \textcolor{keywordflow}{do} i=is,ie
360       depth\_int(1) = 0.0
361       \textcolor{keywordflow}{do} k=2,nz+1
362         depth\_int(k) = depth\_int(k-1) + gv%H\_to\_m*h(i,j,k-1)
363 \textcolor{keywordflow}{      enddo}
364 
365       \textcolor{keyword}{call }cvmix\_init\_bkgnd(max\_nlev=nz, &
366                             zw = depth\_int(:), &  \textcolor{comment}{!< interface depths relative to the surface in m, must be
       positive.}
367                             bl1 = cs%Bryan\_Lewis\_c1, &
368                             bl2 = cs%Bryan\_Lewis\_c2, &
369                             bl3 = cs%Bryan\_Lewis\_c3, &
370                             bl4 = cs%Bryan\_Lewis\_c4, &
371                             prandtl = cs%prandtl\_bkgnd)
372 
373       kd\_col(:) = 0.0 ; kv\_col(:) = 0.0  \textcolor{comment}{! Is this line necessary?}
374       \textcolor{keyword}{call }cvmix\_coeffs\_bkgnd(mdiff\_out=kv\_col, tdiff\_out=kd\_col, nlev=nz, max\_nlev=nz)
375 
376       \textcolor{comment}{! Update Kd and Kv.}
377       \textcolor{keywordflow}{do} k=1,nz+1
378         kv\_bkgnd(i,k) = us%m2\_s\_to\_Z2\_T*kv\_col(k)
379         kd\_int(i,k) = us%m2\_s\_to\_Z2\_T*kd\_col(k)
380 \textcolor{keywordflow}{      enddo}
381       \textcolor{keywordflow}{do} k=1,nz
382         kd\_lay(i,k) = kd\_lay(i,k) + 0.5 * us%m2\_s\_to\_Z2\_T * (kd\_col(k) + kd\_col(k+1))
383 \textcolor{keywordflow}{      enddo}
384 \textcolor{keywordflow}{    enddo} \textcolor{comment}{! i loop}
385 
386   \textcolor{keywordflow}{elseif} (cs%horiz\_varying\_background) \textcolor{keywordflow}{then}
387     \textcolor{comment}{!### Note that there are lots of hard-coded parameters (mostly latitudes and longitudes) here.}
388     \textcolor{keywordflow}{do} i=is,ie
389       bckgrnd\_vdc\_psis = cs%bckgrnd\_vdc\_psim * exp(-(0.4*(g%geoLatT(i,j)+28.9))**2)
390       bckgrnd\_vdc\_psin = cs%bckgrnd\_vdc\_psim * exp(-(0.4*(g%geoLatT(i,j)-28.9))**2)
391       kd\_int(i,1) = (cs%bckgrnd\_vdc\_eq + bckgrnd\_vdc\_psin) + bckgrnd\_vdc\_psis
392 
393       \textcolor{keywordflow}{if} (g%geoLatT(i,j) < -10.0) \textcolor{keywordflow}{then}
394         kd\_int(i,1) = kd\_int(i,1) + cs%bckgrnd\_vdc1
395       \textcolor{keywordflow}{elseif} (g%geoLatT(i,j) <= 10.0) \textcolor{keywordflow}{then}
396         kd\_int(i,1) = kd\_int(i,1) + cs%bckgrnd\_vdc1 * (g%geoLatT(i,j)/10.0)**2
397       \textcolor{keywordflow}{else}
398         kd\_int(i,1) = kd\_int(i,1) + cs%bckgrnd\_vdc1
399 \textcolor{keywordflow}{      endif}
400 
401       \textcolor{comment}{! North Banda Sea}
402       \textcolor{keywordflow}{if} ( (g%geoLatT(i,j) < -1.0)  .and. (g%geoLatT(i,j) > -4.0) .and. &
403            ( mod(g%geoLonT(i,j)+360.0,360.0) > 103.0) .and. &
404            ( mod(g%geoLonT(i,j)+360.0,360.0) < 134.0) ) \textcolor{keywordflow}{then}
405         kd\_int(i,1) = cs%bckgrnd\_vdc\_Banda
406 \textcolor{keywordflow}{      endif}
407 
408       \textcolor{comment}{! Middle Banda Sea}
409       \textcolor{keywordflow}{if} ( (g%geoLatT(i,j) <= -4.0) .and. (g%geoLatT(i,j) > -7.0) .and. &
410            ( mod(g%geoLonT(i,j)+360.0,360.0) > 106.0) .and. &
411            ( mod(g%geoLonT(i,j)+360.0,360.0) < 140.0) ) \textcolor{keywordflow}{then}
412         kd\_int(i,1) = cs%bckgrnd\_vdc\_Banda
413 \textcolor{keywordflow}{      endif}
414 
415       \textcolor{comment}{! South Banda Sea}
416       \textcolor{keywordflow}{if} ( (g%geoLatT(i,j) <= -7.0) .and. (g%geoLatT(i,j) > -8.3) .and. &
417            ( mod(g%geoLonT(i,j)+360.0,360.0) > 111.0) .and. &
418            ( mod(g%geoLonT(i,j)+360.0,360.0) < 142.0) ) \textcolor{keywordflow}{then}
419         kd\_int(i,1) = cs%bckgrnd\_vdc\_Banda
420 \textcolor{keywordflow}{      endif}
421 
422 \textcolor{keywordflow}{    enddo}
423     \textcolor{comment}{! Update interior values of Kd and Kv (uniform profile; no interpolation needed)}
424     \textcolor{keywordflow}{do} k=1,nz+1 ; \textcolor{keywordflow}{do} i=is,ie
425       kd\_int(i,k) = kd\_int(i,1)
426       kv\_bkgnd(i,k) = kd\_int(i,1) * cs%prandtl\_bkgnd
427 \textcolor{keywordflow}{    enddo} ;\textcolor{keywordflow}{ enddo}
428     \textcolor{keywordflow}{do} k=1,nz ; \textcolor{keywordflow}{do} i=is,ie
429       kd\_lay(i,k) = kd\_int(i,1)
430 \textcolor{keywordflow}{    enddo} ;\textcolor{keywordflow}{ enddo}
431 
432   \textcolor{keywordflow}{elseif} (cs%Henyey\_IGW\_background\_new) \textcolor{keywordflow}{then}
433     i\_x30 = 2.0 / invcosh(cs%N0\_2Omega*2.0) \textcolor{comment}{! This is evaluated at 30 deg.}
434     i\_2omega = 0.5 / cs%omega
435     \textcolor{keywordflow}{do} k=1,nz ; \textcolor{keywordflow}{do} i=is,ie
436       abs\_sinlat = max(min\_sinlat, abs(sin(g%geoLatT(i,j)*deg\_to\_rad)))
437       n\_2omega = max(abs\_sinlat, sqrt(n2\_lay(i,k))*i\_2omega)
438       n02\_n2 = (cs%N0\_2Omega/n\_2omega)**2
439       kd\_lay(i,k) = max(cs%Kd\_min, cs%Kd * &
440            ((abs\_sinlat * invcosh(n\_2omega/abs\_sinlat)) * i\_x30)*n02\_n2)
441 \textcolor{keywordflow}{    enddo} ;\textcolor{keywordflow}{ enddo}
442     \textcolor{comment}{! Update Kd\_int and Kv\_bkgnd, based on Kd\_lay.  These might be just used for diagnostic purposes.}
443     \textcolor{keywordflow}{do} i=is,ie
444       kd\_int(i,1) = 0.0; kv\_bkgnd(i,1) = 0.0
445       kd\_int(i,nz+1) = 0.0; kv\_bkgnd(i,nz+1) = 0.0
446 \textcolor{keywordflow}{    enddo}
447     \textcolor{keywordflow}{do} k=2,nz ; \textcolor{keywordflow}{do} i=is,ie
448       kd\_int(i,k) = 0.5*(kd\_lay(i,k-1) + kd\_lay(i,k))
449       kv\_bkgnd(i,k) = kd\_int(i,k) * cs%prandtl\_bkgnd
450 \textcolor{keywordflow}{    enddo} ;\textcolor{keywordflow}{ enddo}
451   \textcolor{keywordflow}{else}
452     \textcolor{comment}{! Set a potentially spatially varying surface value of diffusivity.}
453     \textcolor{keywordflow}{if} (cs%Henyey\_IGW\_background) \textcolor{keywordflow}{then}
454       i\_x30 = 2.0 / invcosh(cs%N0\_2Omega*2.0) \textcolor{comment}{! This is evaluated at 30 deg.}
455       \textcolor{keywordflow}{do} i=is,ie
456         abs\_sinlat = abs(sin(g%geoLatT(i,j)*deg\_to\_rad))
457         kd\_sfc(i) = max(cs%Kd\_min, cs%Kd * &
458              ((abs\_sinlat * invcosh(cs%N0\_2Omega / max(min\_sinlat, abs\_sinlat))) * i\_x30) )
459 \textcolor{keywordflow}{      enddo}
460     \textcolor{keywordflow}{elseif} (cs%Kd\_tanh\_lat\_fn) \textcolor{keywordflow}{then}
461       \textcolor{keywordflow}{do} i=is,ie
462         \textcolor{comment}{!   The transition latitude and latitude range are hard-scaled here, since}
463         \textcolor{comment}{! this is not really intended for wide-spread use, but rather for}
464         \textcolor{comment}{! comparison with CM2M / CM2.1 settings.}
465         kd\_sfc(i) = max(cs%Kd\_min, cs%Kd * (1.0 + &
466             cs%Kd\_tanh\_lat\_scale * 0.5*tanh((abs(g%geoLatT(i,j)) - 35.0)/5.0) ))
467 \textcolor{keywordflow}{      enddo}
468     \textcolor{keywordflow}{else} \textcolor{comment}{! Use a spatially constant surface value.}
469       \textcolor{keywordflow}{do} i=is,ie
470         kd\_sfc(i) = cs%Kd
471 \textcolor{keywordflow}{      enddo}
472 \textcolor{keywordflow}{    endif}
473 
474     \textcolor{comment}{! Now set background diffusivies based on these surface values, possibly with vertical structure.}
475     \textcolor{keywordflow}{if} ((.not.cs%bulkmixedlayer) .and. (cs%Kd /= cs%Kdml)) \textcolor{keywordflow}{then}
476       \textcolor{comment}{! This is a crude way to put in a diffusive boundary layer without an explicit boundary}
477       \textcolor{comment}{! layer turbulence scheme.  It should not be used for any realistic ocean models.}
478       i\_hmix = 1.0 / (cs%Hmix + gv%H\_subroundoff*gv%H\_to\_Z)
479       \textcolor{keywordflow}{do} i=is,ie ; depth(i) = 0.0 ;\textcolor{keywordflow}{ enddo}
480       \textcolor{keywordflow}{do} k=1,nz ; \textcolor{keywordflow}{do} i=is,ie
481         depth\_c = depth(i) + 0.5*gv%H\_to\_Z*h(i,j,k)
482         \textcolor{keywordflow}{if} (cs%Kd\_via\_Kdml\_bug) \textcolor{keywordflow}{then}
483           \textcolor{comment}{! These two lines should update Kd\_lay, not Kd\_int.  They were correctly working on the}
484           \textcolor{comment}{! same variables until MOM6 commit 7a818716 (PR#750), which was added on March 26, 2018.}
485           \textcolor{keywordflow}{if} (depth\_c <= cs%Hmix) \textcolor{keywordflow}{then} ; kd\_int(i,k) = cs%Kdml
486           \textcolor{keywordflow}{elseif} (depth\_c >= 2.0*cs%Hmix) \textcolor{keywordflow}{then} ; kd\_int(i,k) = kd\_sfc(i)
487           \textcolor{keywordflow}{else}
488             kd\_lay(i,k) = ((kd\_sfc(i) - cs%Kdml) * i\_hmix) * depth\_c + (2.0*cs%Kdml - kd\_sfc(i))
489 \textcolor{keywordflow}{          endif}
490         \textcolor{keywordflow}{else}
491           \textcolor{keywordflow}{if} (depth\_c <= cs%Hmix) \textcolor{keywordflow}{then} ; kd\_lay(i,k) = cs%Kdml
492           \textcolor{keywordflow}{elseif} (depth\_c >= 2.0*cs%Hmix) \textcolor{keywordflow}{then} ; kd\_lay(i,k) = kd\_sfc(i)
493           \textcolor{keywordflow}{else}
494             kd\_lay(i,k) = ((kd\_sfc(i) - cs%Kdml) * i\_hmix) * depth\_c + (2.0*cs%Kdml - kd\_sfc(i))
495 \textcolor{keywordflow}{          endif}
496 \textcolor{keywordflow}{        endif}
497 
498         depth(i) = depth(i) + gv%H\_to\_Z*h(i,j,k)
499 \textcolor{keywordflow}{      enddo} ;\textcolor{keywordflow}{ enddo}
500 
501     \textcolor{keywordflow}{else} \textcolor{comment}{! There is no vertical structure to the background diffusivity.}
502       \textcolor{keywordflow}{do} k=1,nz ; \textcolor{keywordflow}{do} i=is,ie
503         kd\_lay(i,k) = kd\_sfc(i)
504 \textcolor{keywordflow}{      enddo} ;\textcolor{keywordflow}{ enddo}
505 \textcolor{keywordflow}{    endif}
506 
507     \textcolor{comment}{! Update Kd\_int and Kv\_bkgnd, based on Kd\_lay.  These might be just used for diagnostic purposes.}
508     \textcolor{keywordflow}{do} i=is,ie
509       kd\_int(i,1) = 0.0; kv\_bkgnd(i,1) = 0.0
510       kd\_int(i,nz+1) = 0.0; kv\_bkgnd(i,nz+1) = 0.0
511 \textcolor{keywordflow}{    enddo}
512     \textcolor{keywordflow}{do} k=2,nz ; \textcolor{keywordflow}{do} i=is,ie
513       kd\_int(i,k) = 0.5*(kd\_lay(i,k-1) + kd\_lay(i,k))
514       kv\_bkgnd(i,k) = kd\_int(i,k) * cs%prandtl\_bkgnd
515 \textcolor{keywordflow}{    enddo} ;\textcolor{keywordflow}{ enddo}
516 \textcolor{keywordflow}{  endif}
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{\tt 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}
533   \textcolor{keywordtype}{type}(bkgnd\_mixing\_cs), \textcolor{keywordtype}{pointer} :: CS\textcolor{comment}{  !< Control structure}
534   \textcolor{keywordtype}{character(len=*)}, \textcolor{keywordtype}{intent(in)}   :: str\textcolor{comment}{ !< Background scheme identifier deducted from MOM\_input}
535 \textcolor{comment}{                                        !! parameters}
536 
537   \textcolor{keywordflow}{if} (trim(cs%bkgnd\_scheme\_str)==\textcolor{stringliteral}{"none"}) \textcolor{keywordflow}{then}
538     cs%bkgnd\_scheme\_str = str
539   \textcolor{keywordflow}{else}
540     \textcolor{keyword}{call }mom\_error(fatal, \textcolor{stringliteral}{"bkgnd\_mixing\_init: Cannot activate both "}//trim(str)//\textcolor{stringliteral}{" and "}//&
541                    trim(cs%bkgnd\_scheme\_str)//\textcolor{stringliteral}{"."})
542 \textcolor{keywordflow}{  endif}
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{\tt 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}
524   \textcolor{keywordtype}{type}(param\_file\_type), \textcolor{keywordtype}{intent(in)} :: param\_file\textcolor{comment}{ !< A structure to parse for run-time parameters}
525   \textcolor{keyword}{call }get\_param(param\_file, mdl, \textcolor{stringliteral}{"USE\_CVMix\_BACKGROUND"}, cvmix\_bkgnd\_is\_used, &
526                  default=.false., do\_not\_log = .true.)
527 
\end{DoxyCode}
