\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 \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 \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 \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 \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 \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 \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) \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(\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 551 of file M\+O\+M\+\_\+bkgnd\+\_\+mixing.\+F90.


\begin{DoxyCode}
551   \textcolor{keywordtype}{type}(bkgnd\_mixing\_cs), \textcolor{keywordtype}{pointer} :: cs\textcolor{comment}{ !< Control structure for this module that}
552 \textcolor{comment}{                                       !! will be deallocated in this subroutine}
553 
554   \textcolor{keywordflow}{if} (.not. \textcolor{keyword}{associated}(cs)) \textcolor{keywordflow}{return}
555   \textcolor{keyword}{deallocate}(cs)
556 
\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(\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 
241     prandtl\_bkgnd\_comp = cs%prandtl\_bkgnd
242     \textcolor{keywordflow}{if} (cs%Kd /= 0.0) prandtl\_bkgnd\_comp = kv/cs%Kd
243 
244     \textcolor{keywordflow}{if} ( abs(cs%prandtl\_bkgnd - prandtl\_bkgnd\_comp)>1.e-14) \textcolor{keywordflow}{then}
245       \textcolor{keyword}{call }mom\_error(fatal,\textcolor{stringliteral}{"set\_diffusivity\_init: The provided KD, KV,"}//&
246                            \textcolor{stringliteral}{"and PRANDTL\_BKGND values are incompatible. The following "}//&
247                            \textcolor{stringliteral}{"must hold: KD*PRANDTL\_BKGND==KV"})
248 \textcolor{keywordflow}{    endif}
249 
250 \textcolor{keywordflow}{  endif}
251 
252   \textcolor{keyword}{call }get\_param(param\_file, mdl, \textcolor{stringliteral}{"HENYEY\_IGW\_BACKGROUND"}, cs%Henyey\_IGW\_background, &
253                  \textcolor{stringliteral}{"If true, use a latitude-dependent scaling for the near "}//&
254                  \textcolor{stringliteral}{"surface background diffusivity, as described in "}//&
255                  \textcolor{stringliteral}{"Harrison & Hallberg, JPO 2008."}, default=.false.)
256   \textcolor{keywordflow}{if} (cs%Henyey\_IGW\_background) \textcolor{keyword}{call }check\_bkgnd\_scheme(cs, \textcolor{stringliteral}{"HENYEY\_IGW\_BACKGROUND"})
257 
258 
259   \textcolor{keyword}{call }get\_param(param\_file, mdl, \textcolor{stringliteral}{"HENYEY\_IGW\_BACKGROUND\_NEW"}, cs%Henyey\_IGW\_background\_new, &
260                  \textcolor{stringliteral}{"If true, use a better latitude-dependent scaling for the "}//&
261                  \textcolor{stringliteral}{"background diffusivity, as described in "}//&
262                  \textcolor{stringliteral}{"Harrison & Hallberg, JPO 2008."}, default=.false.)
263   \textcolor{keywordflow}{if} (cs%Henyey\_IGW\_background\_new) \textcolor{keyword}{call }check\_bkgnd\_scheme(cs, \textcolor{stringliteral}{"HENYEY\_IGW\_BACKGROUND\_NEW"})
264 
265   \textcolor{keywordflow}{if} (cs%Kd>0.0 .and. (trim(cs%bkgnd\_scheme\_str)==\textcolor{stringliteral}{"BRYAN\_LEWIS\_DIFFUSIVITY"} .or.&
266                           trim(cs%bkgnd\_scheme\_str)==\textcolor{stringliteral}{"HORIZ\_VARYING\_BACKGROUND"} )) \textcolor{keywordflow}{then}
267     \textcolor{keyword}{call }mom\_error(warning, \textcolor{stringliteral}{"set\_diffusivity\_init: a nonzero constant background "}//&
268          \textcolor{stringliteral}{"diffusivity (KD) is specified along with "}//trim(cs%bkgnd\_scheme\_str))
269 \textcolor{keywordflow}{  endif}
270 
271   \textcolor{keywordflow}{if} (cs%Henyey\_IGW\_background) \textcolor{keywordflow}{then}
272     \textcolor{keyword}{call }get\_param(param\_file, mdl, \textcolor{stringliteral}{"HENYEY\_N0\_2OMEGA"}, cs%N0\_2Omega, &
273                   \textcolor{stringliteral}{"The ratio of the typical Buoyancy frequency to twice "}//&
274                   \textcolor{stringliteral}{"the Earth's rotation period, used with the Henyey "}//&
275                   \textcolor{stringliteral}{"scaling from the mixing."}, units=\textcolor{stringliteral}{"nondim"}, default=20.0)
276     \textcolor{keyword}{call }get\_param(param\_file, mdl, \textcolor{stringliteral}{"OMEGA"}, cs%omega, &
277                  \textcolor{stringliteral}{"The rotation rate of the earth."}, units=\textcolor{stringliteral}{"s-1"}, &
278                  default=7.2921e-5, scale=us%T\_to\_s)
279 \textcolor{keywordflow}{  endif}
280 
281   \textcolor{keyword}{call }get\_param(param\_file, mdl, \textcolor{stringliteral}{"KD\_TANH\_LAT\_FN"}, cs%Kd\_tanh\_lat\_fn, &
282                  \textcolor{stringliteral}{"If true, use a tanh dependence of Kd\_sfc on latitude, "}//&
283                  \textcolor{stringliteral}{"like CM2.1/CM2M.  There is no physical justification "}//&
284                  \textcolor{stringliteral}{"for this form, and it can not be used with "}//&
285                  \textcolor{stringliteral}{"HENYEY\_IGW\_BACKGROUND."}, default=.false.)
286 
287   \textcolor{keywordflow}{if} (cs%Kd\_tanh\_lat\_fn) &
288     \textcolor{keyword}{call }get\_param(param\_file, mdl, \textcolor{stringliteral}{"KD\_TANH\_LAT\_SCALE"}, cs%Kd\_tanh\_lat\_scale, &
289                  \textcolor{stringliteral}{"A nondimensional scaling for the range ofdiffusivities "}//&
290                  \textcolor{stringliteral}{"with KD\_TANH\_LAT\_FN. Valid values are in the range of "}//&
291                  \textcolor{stringliteral}{"-2 to 2; 0.4 reproduces CM2M."}, units=\textcolor{stringliteral}{"nondim"}, default=0.0)
292 
293   \textcolor{keywordflow}{if} (cs%Henyey\_IGW\_background .and. cs%Kd\_tanh\_lat\_fn) \textcolor{keyword}{call }mom\_error(fatal, &
294     \textcolor{stringliteral}{"MOM\_bkgnd\_mixing: KD\_TANH\_LAT\_FN can not be used with HENYEY\_IGW\_BACKGROUND."})
295 
296   cs%Kd\_via\_Kdml\_bug = .false.
297   \textcolor{keywordflow}{if} ((cs%Kd /= cs%Kdml) .and. .not.(cs%Kd\_tanh\_lat\_fn .or. cs%bulkmixedlayer .or. &
298                                      cs%Henyey\_IGW\_background .or. cs%Henyey\_IGW\_background\_new .or. &
299                                      cs%horiz\_varying\_background .or. cs%Bryan\_Lewis\_diffusivity)) \textcolor{keywordflow}{then}
300     \textcolor{keyword}{call }get\_param(param\_file, mdl, \textcolor{stringliteral}{"KD\_BACKGROUND\_VIA\_KDML\_BUG"}, cs%Kd\_via\_Kdml\_bug, &
301                  \textcolor{stringliteral}{"If true and KDML /= KD and several other conditions apply, the background "}//&
302                  \textcolor{stringliteral}{"diffusivity is set incorrectly using a bug that was introduced in March, 2018."}, &
303                  default=.true.)  \textcolor{comment}{! The default should be changed to false and this parameter obsoleted.}
304 \textcolor{keywordflow}{  endif}
305 
306 \textcolor{comment}{!  call closeParameterBlock(param\_file)}
307 
\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(\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 312 of file M\+O\+M\+\_\+bkgnd\+\_\+mixing.\+F90.


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


\begin{DoxyCode}
536   \textcolor{keywordtype}{type}(bkgnd\_mixing\_cs), \textcolor{keywordtype}{pointer} :: cs\textcolor{comment}{  !< Control structure}
537   \textcolor{keywordtype}{character(len=*)}, \textcolor{keywordtype}{intent(in)}   :: str\textcolor{comment}{ !< Background scheme identifier deducted from MOM\_input}
538 \textcolor{comment}{                                        !! parameters}
539 
540   \textcolor{keywordflow}{if} (trim(cs%bkgnd\_scheme\_str)==\textcolor{stringliteral}{"none"}) \textcolor{keywordflow}{then}
541     cs%bkgnd\_scheme\_str = str
542   \textcolor{keywordflow}{else}
543     \textcolor{keyword}{call }mom\_error(fatal, \textcolor{stringliteral}{"set\_diffusivity\_init: Cannot activate both "}//trim(str)//\textcolor{stringliteral}{" and "}//&
544                    trim(cs%bkgnd\_scheme\_str)//\textcolor{stringliteral}{"."})
545 \textcolor{keywordflow}{  endif}
546 
\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 527 of file M\+O\+M\+\_\+bkgnd\+\_\+mixing.\+F90.


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