\hypertarget{namespacedense__water__initialization}{}\section{dense\+\_\+water\+\_\+initialization Module Reference}
\label{namespacedense__water__initialization}\index{dense\+\_\+water\+\_\+initialization@{dense\+\_\+water\+\_\+initialization}}


\subsection{Detailed Description}
Initialization routines for the dense water formation and overflow experiment. 

This experiment consists of a shelf accumulating dense water, which spills over an upward slope and a sill, before flowing down a slope into an open ocean region. It\textquotesingle{}s intended as a test of one of the motivating situations for the adaptive coordinate.

The nondimensional widths of the 5 regions are controlled by the {\ttfamily D\+E\+N\+S\+E\+\_\+\+W\+A\+T\+E\+R\+\_\+\+D\+O\+M\+A\+I\+N\+\_\+\+P\+A\+R\+A\+MS}, and the heights of the sill and shelf as a fraction of the total domain depth are controlled by {\ttfamily D\+E\+N\+S\+E\+\_\+\+W\+A\+T\+E\+R\+\_\+\+S\+I\+L\+L\+\_\+\+H\+E\+I\+G\+HT} and {\ttfamily D\+E\+N\+S\+E\+\_\+\+W\+A\+T\+E\+R\+\_\+\+S\+H\+E\+L\+F\+\_\+\+H\+E\+I\+G\+HT}.

The density in the domain is governed by a linear equation of state, and is set up with a mixed layer of non-\/dimensional depth {\ttfamily D\+E\+N\+S\+E\+\_\+\+W\+A\+T\+E\+R\+\_\+\+M\+LD} below which there is a linear stratification from {\ttfamily S\+\_\+\+R\+EF}, increasing by {\ttfamily S\+\_\+\+R\+A\+N\+GE} to the bottom.

To force the experiment, there are sponges on the inflow and outflow of the domain. The inflow sponge has a salinity anomaly of {\ttfamily D\+E\+N\+S\+E\+\_\+\+W\+A\+T\+E\+R\+\_\+\+E\+A\+S\+T\+\_\+\+S\+P\+O\+N\+G\+E\+\_\+\+S\+A\+LT} through the entire depth. The outflow sponge simply restores to the initial condition. Both sponges have controllable widths and restoring timescales. \subsection*{Functions/\+Subroutines}
\begin{DoxyCompactItemize}
\item 
subroutine, public \hyperlink{namespacedense__water__initialization_ae2a5062c406c66b1917f2ad564d4a5e6}{dense\+\_\+water\+\_\+initialize\+\_\+topography} (D, G, param\+\_\+file, max\+\_\+depth)
\begin{DoxyCompactList}\small\item\em Initialize the topography field for the dense water experiment. \end{DoxyCompactList}\item 
subroutine, public \hyperlink{namespacedense__water__initialization_a0e1384953bfbb302a7b93dd7abb6cb7b}{dense\+\_\+water\+\_\+initialize\+\_\+ts} (G, GV, param\+\_\+file, eqn\+\_\+of\+\_\+state, T, S, h, just\+\_\+read\+\_\+params)
\begin{DoxyCompactList}\small\item\em Initialize the temperature and salinity for the dense water experiment. \end{DoxyCompactList}\item 
subroutine, public \hyperlink{namespacedense__water__initialization_aa663ab693084a07cf066806d6b529c14}{dense\+\_\+water\+\_\+initialize\+\_\+sponges} (G, GV, US, tv, param\+\_\+file, use\+\_\+\+A\+LE, C\+Sp, A\+C\+Sp)
\begin{DoxyCompactList}\small\item\em Initialize the restoring sponges for the dense water experiment. \end{DoxyCompactList}\end{DoxyCompactItemize}
\subsection*{Variables}
\begin{DoxyCompactItemize}
\item 
\mbox{\Hypertarget{namespacedense__water__initialization_a8996fccad16389cd1b688f83ebf3a630}\label{namespacedense__water__initialization_a8996fccad16389cd1b688f83ebf3a630}} 
character(len=40) \hyperlink{namespacedense__water__initialization_a8996fccad16389cd1b688f83ebf3a630}{mdl} = \char`\"{}dense\+\_\+water\+\_\+initialization\char`\"{}
\begin{DoxyCompactList}\small\item\em Module name. \end{DoxyCompactList}\item 
\mbox{\Hypertarget{namespacedense__water__initialization_a2411cd7a7a8c202a345e66ae25a6f5a0}\label{namespacedense__water__initialization_a2411cd7a7a8c202a345e66ae25a6f5a0}} 
real, parameter \hyperlink{namespacedense__water__initialization_a2411cd7a7a8c202a345e66ae25a6f5a0}{default\+\_\+sill} = 0.\+2
\begin{DoxyCompactList}\small\item\em Default depth of the sill \mbox{[}nondim\mbox{]}. \end{DoxyCompactList}\item 
\mbox{\Hypertarget{namespacedense__water__initialization_aa43e2347923c52d91a9ca2fc07b49949}\label{namespacedense__water__initialization_aa43e2347923c52d91a9ca2fc07b49949}} 
real, parameter \hyperlink{namespacedense__water__initialization_aa43e2347923c52d91a9ca2fc07b49949}{default\+\_\+shelf} = 0.\+4
\begin{DoxyCompactList}\small\item\em Default depth of the shelf \mbox{[}nondim\mbox{]}. \end{DoxyCompactList}\item 
\mbox{\Hypertarget{namespacedense__water__initialization_a8dde2a4823fdb9aa5e4911dcb965176f}\label{namespacedense__water__initialization_a8dde2a4823fdb9aa5e4911dcb965176f}} 
real, parameter \hyperlink{namespacedense__water__initialization_a8dde2a4823fdb9aa5e4911dcb965176f}{default\+\_\+mld} = 0.\+25
\begin{DoxyCompactList}\small\item\em Default depth of the mixed layer \mbox{[}nondim\mbox{]}. \end{DoxyCompactList}\end{DoxyCompactItemize}


\subsection{Function/\+Subroutine Documentation}
\mbox{\Hypertarget{namespacedense__water__initialization_aa663ab693084a07cf066806d6b529c14}\label{namespacedense__water__initialization_aa663ab693084a07cf066806d6b529c14}} 
\index{dense\+\_\+water\+\_\+initialization@{dense\+\_\+water\+\_\+initialization}!dense\+\_\+water\+\_\+initialize\+\_\+sponges@{dense\+\_\+water\+\_\+initialize\+\_\+sponges}}
\index{dense\+\_\+water\+\_\+initialize\+\_\+sponges@{dense\+\_\+water\+\_\+initialize\+\_\+sponges}!dense\+\_\+water\+\_\+initialization@{dense\+\_\+water\+\_\+initialization}}
\subsubsection{\texorpdfstring{dense\+\_\+water\+\_\+initialize\+\_\+sponges()}{dense\_water\_initialize\_sponges()}}
{\footnotesize\ttfamily subroutine, public dense\+\_\+water\+\_\+initialization\+::dense\+\_\+water\+\_\+initialize\+\_\+sponges (\begin{DoxyParamCaption}\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(thermo\+\_\+var\+\_\+ptrs), intent(in)}]{tv,  }\item[{type(param\+\_\+file\+\_\+type), intent(in)}]{param\+\_\+file,  }\item[{logical, intent(in)}]{use\+\_\+\+A\+LE,  }\item[{type(sponge\+\_\+cs), pointer}]{C\+Sp,  }\item[{type(ale\+\_\+sponge\+\_\+cs), pointer}]{A\+C\+Sp }\end{DoxyParamCaption})}



Initialize the restoring sponges for the dense water experiment. 


\begin{DoxyParams}[1]{Parameters}
\mbox{\tt in}  & {\em g} & Horizontal grid control structure\\
\hline
\mbox{\tt in}  & {\em gv} & Vertical grid control structure\\
\hline
\mbox{\tt in}  & {\em us} & A dimensional unit scaling type\\
\hline
\mbox{\tt in}  & {\em tv} & Thermodynamic variables\\
\hline
\mbox{\tt in}  & {\em param\+\_\+file} & Parameter file structure\\
\hline
\mbox{\tt in}  & {\em use\+\_\+ale} & A\+LE flag\\
\hline
 & {\em csp} & Layered sponge control structure pointer\\
\hline
 & {\em acsp} & A\+LE sponge control structure pointer \\
\hline
\end{DoxyParams}


Definition at line 156 of file dense\+\_\+water\+\_\+initialization.\+F90.


\begin{DoxyCode}
156   \textcolor{keywordtype}{type}(ocean\_grid\_type),   \textcolor{keywordtype}{intent(in)} :: g\textcolor{comment}{ !< Horizontal grid control structure}
157   \textcolor{keywordtype}{type}(verticalgrid\_type), \textcolor{keywordtype}{intent(in)} :: gv\textcolor{comment}{ !< Vertical grid control structure}
158   \textcolor{keywordtype}{type}(unit\_scale\_type),   \textcolor{keywordtype}{intent(in)} :: us\textcolor{comment}{ !< A dimensional unit scaling type}
159   \textcolor{keywordtype}{type}(thermo\_var\_ptrs),   \textcolor{keywordtype}{intent(in)} :: tv\textcolor{comment}{ !< Thermodynamic variables}
160   \textcolor{keywordtype}{type}(param\_file\_type),   \textcolor{keywordtype}{intent(in)} :: param\_file\textcolor{comment}{ !< Parameter file structure}
161   \textcolor{keywordtype}{logical},                 \textcolor{keywordtype}{intent(in)} :: use\_ale\textcolor{comment}{ !< ALE flag}
162   \textcolor{keywordtype}{type}(sponge\_cs),         \textcolor{keywordtype}{pointer}    :: csp\textcolor{comment}{ !< Layered sponge control structure pointer}
163   \textcolor{keywordtype}{type}(ale\_sponge\_cs),     \textcolor{keywordtype}{pointer}    :: acsp\textcolor{comment}{ !< ALE sponge control structure pointer}
164   \textcolor{comment}{! Local variables}
165   \textcolor{keywordtype}{real} :: west\_sponge\_time\_scale, east\_sponge\_time\_scale \textcolor{comment}{! Sponge timescales [T ~> s]}
166   \textcolor{keywordtype}{real} :: west\_sponge\_width, east\_sponge\_width
167 
168   \textcolor{keywordtype}{real}, \textcolor{keywordtype}{dimension(SZI\_(G),SZJ\_(G))} :: idamp \textcolor{comment}{! inverse damping timescale [T-1 ~> s-1]}
169   \textcolor{keywordtype}{real}, \textcolor{keywordtype}{dimension(SZI\_(G),SZJ\_(G),SZK\_(GV))} :: h  \textcolor{comment}{! sponge thicknesses [H ~> m or kg m-2]}
170   \textcolor{keywordtype}{real}, \textcolor{keywordtype}{dimension(SZI\_(G),SZJ\_(G),SZK\_(GV))} :: t  \textcolor{comment}{! sponge temperature [degC]}
171   \textcolor{keywordtype}{real}, \textcolor{keywordtype}{dimension(SZI\_(G),SZJ\_(G),SZK\_(GV))} :: s  \textcolor{comment}{! sponge salinity [ppt]}
172   \textcolor{keywordtype}{real}, \textcolor{keywordtype}{dimension(SZK\_(GV)+1)} :: e0, eta1d \textcolor{comment}{! interface positions for ALE sponge [Z ~> m]}
173 
174   \textcolor{keywordtype}{integer} :: i, j, k, nz
175   \textcolor{keywordtype}{real} :: x, zi, zmid, dist
176   \textcolor{keywordtype}{real} :: mld, s\_ref, s\_range, s\_dense, t\_ref, sill\_height
177 
178   nz = gv%ke
179 
180   \textcolor{keyword}{call }get\_param(param\_file, mdl, \textcolor{stringliteral}{"DENSE\_WATER\_WEST\_SPONGE\_TIME\_SCALE"}, west\_sponge\_time\_scale, &
181        \textcolor{stringliteral}{"The time scale on the west (outflow) of the domain for restoring. If zero, the sponge is disabled."}
      , &
182        units=\textcolor{stringliteral}{"s"}, default=0., scale=us%s\_to\_T)
183   \textcolor{keyword}{call }get\_param(param\_file, mdl, \textcolor{stringliteral}{"DENSE\_WATER\_WEST\_SPONGE\_WIDTH"}, west\_sponge\_width, &
184        \textcolor{stringliteral}{"The fraction of the domain in which the western (outflow) sponge is active."}, &
185        units=\textcolor{stringliteral}{"nondim"}, default=0.1)
186   \textcolor{keyword}{call }get\_param(param\_file, mdl, \textcolor{stringliteral}{"DENSE\_WATER\_EAST\_SPONGE\_TIME\_SCALE"}, east\_sponge\_time\_scale, &
187        \textcolor{stringliteral}{"The time scale on the east (outflow) of the domain for restoring. If zero, the sponge is disabled."}
      , &
188        units=\textcolor{stringliteral}{"s"}, default=0., scale=us%s\_to\_T)
189   \textcolor{keyword}{call }get\_param(param\_file, mdl, \textcolor{stringliteral}{"DENSE\_WATER\_EAST\_SPONGE\_WIDTH"}, east\_sponge\_width, &
190        \textcolor{stringliteral}{"The fraction of the domain in which the eastern (outflow) sponge is active."}, &
191        units=\textcolor{stringliteral}{"nondim"}, default=0.1)
192 
193   \textcolor{keyword}{call }get\_param(param\_file, mdl, \textcolor{stringliteral}{"DENSE\_WATER\_EAST\_SPONGE\_SALT"}, s\_dense, &
194        \textcolor{stringliteral}{"Salt anomaly of the dense water being formed in the overflow region."}, &
195        units=\textcolor{stringliteral}{"1e-3"}, default=4.0)
196 
197   \textcolor{keyword}{call }get\_param(param\_file, mdl, \textcolor{stringliteral}{"DENSE\_WATER\_MLD"}, mld, default=default\_mld, do\_not\_log=.true.)
198   \textcolor{keyword}{call }get\_param(param\_file, mdl, \textcolor{stringliteral}{"DENSE\_WATER\_SILL\_HEIGHT"}, sill\_height, default=default\_sill, do\_not\_log=
      .true.)
199 
200   \textcolor{keyword}{call }get\_param(param\_file, mdl, \textcolor{stringliteral}{"S\_REF"}, s\_ref, default=35.0, do\_not\_log=.true.)
201   \textcolor{keyword}{call }get\_param(param\_file, mdl, \textcolor{stringliteral}{"S\_RANGE"}, s\_range, do\_not\_log=.true.)
202   \textcolor{keyword}{call }get\_param(param\_file, mdl, \textcolor{stringliteral}{"T\_REF"}, t\_ref, do\_not\_log=.true.)
203 
204   \textcolor{comment}{! no active sponges}
205   \textcolor{keywordflow}{if} (west\_sponge\_time\_scale <= 0. .and. east\_sponge\_time\_scale <= 0.) \textcolor{keywordflow}{return}
206 
207   \textcolor{comment}{! everywhere is initially unsponged}
208   idamp(:,:) = 0.0
209 
210   \textcolor{keywordflow}{do} j = g%jsc, g%jec
211     \textcolor{keywordflow}{do} i = g%isc,g%iec
212       \textcolor{keywordflow}{if} (g%mask2dT(i,j) > 0.) \textcolor{keywordflow}{then}
213         \textcolor{comment}{! nondimensional x position}
214         x = (g%geoLonT(i,j) - g%west\_lon) / g%len\_lon
215 
216         \textcolor{keywordflow}{if} (west\_sponge\_time\_scale > 0. .and. x < west\_sponge\_width) \textcolor{keywordflow}{then}
217           dist = 1. - x / west\_sponge\_width
218           \textcolor{comment}{! scale restoring by depth into sponge}
219           idamp(i,j) = 1. / west\_sponge\_time\_scale * max(0., min(1., dist))
220         \textcolor{keywordflow}{elseif} (east\_sponge\_time\_scale > 0. .and. x > (1. - east\_sponge\_width)) \textcolor{keywordflow}{then}
221           dist = 1. - (1. - x) / east\_sponge\_width
222           idamp(i,j) = 1. / east\_sponge\_time\_scale * max(0., min(1., dist))
223 \textcolor{keywordflow}{        endif}
224 \textcolor{keywordflow}{      endif}
225 \textcolor{keywordflow}{    enddo}
226 \textcolor{keywordflow}{  enddo}
227 
228   \textcolor{keywordflow}{if} (use\_ale) \textcolor{keywordflow}{then}
229     \textcolor{comment}{! construct a uniform grid for the sponge}
230     \textcolor{keywordflow}{do} k = 1,nz
231       e0(k) = -g%max\_depth * (\textcolor{keywordtype}{real(k - 1)} / \textcolor{keywordtype}{real}(nz))
232 \textcolor{keywordflow}{    enddo}
233     e0(nz+1) = -g%max\_depth
234 
235     \textcolor{keywordflow}{do} j = g%jsc,g%jec
236       \textcolor{keywordflow}{do} i = g%isc,g%iec
237         eta1d(nz+1) = -g%bathyT(i,j)
238         \textcolor{keywordflow}{do} k = nz,1,-1
239           eta1d(k) = e0(k)
240 
241           \textcolor{keywordflow}{if} (eta1d(k) < (eta1d(k+1) + gv%Angstrom\_Z)) \textcolor{keywordflow}{then}
242             \textcolor{comment}{! is this layer vanished?}
243             eta1d(k) = eta1d(k+1) + gv%Angstrom\_Z
244             h(i,j,k) = gv%Angstrom\_H
245           \textcolor{keywordflow}{else}
246             h(i,j,k) = gv%Z\_to\_H * (eta1d(k) - eta1d(k+1))
247 \textcolor{keywordflow}{          endif}
248 \textcolor{keywordflow}{        enddo}
249 \textcolor{keywordflow}{      enddo}
250 \textcolor{keywordflow}{    enddo}
251 
252     \textcolor{keyword}{call }initialize\_ale\_sponge(idamp, g, param\_file, acsp, h, nz)
253 
254     \textcolor{comment}{! construct temperature and salinity for the sponge}
255     \textcolor{comment}{! start with initial condition}
256     t(:,:,:) = t\_ref
257     s(:,:,:) = s\_ref
258 
259     \textcolor{keywordflow}{do} j = g%jsc,g%jec
260       \textcolor{keywordflow}{do} i = g%isc,g%iec
261         zi = 0.
262         x = (g%geoLonT(i,j) - g%west\_lon) / g%len\_lon
263         \textcolor{keywordflow}{do} k = 1,nz
264           \textcolor{comment}{! nondimensional middle of layer}
265           zmid = zi + 0.5 * h(i,j,k) / (gv%Z\_to\_H * g%max\_depth)
266 
267           \textcolor{keywordflow}{if} (x > (1. - east\_sponge\_width)) \textcolor{keywordflow}{then}
268             \textcolor{comment}{!if (zmid >= 0.9 * sill\_height) &}
269                  s(i,j,k) = s\_ref + s\_dense
270           \textcolor{keywordflow}{else}
271             \textcolor{comment}{! linear between bottom of mixed layer and bottom}
272             \textcolor{keywordflow}{if} (zmid >= mld) &
273                  s(i,j,k) = s\_ref + s\_range * (zmid - mld) / (1.0 - mld)
274 \textcolor{keywordflow}{          endif}
275 
276           zi = zi + h(i,j,k) / (gv%Z\_to\_H * g%max\_depth)
277 \textcolor{keywordflow}{        enddo}
278 \textcolor{keywordflow}{      enddo}
279 \textcolor{keywordflow}{    enddo}
280 
281     \textcolor{keywordflow}{if} (\textcolor{keyword}{associated}(tv%T)) \textcolor{keyword}{call }set\_up\_ale\_sponge\_field(t, g, tv%T, acsp)
282     \textcolor{keywordflow}{if} (\textcolor{keyword}{associated}(tv%S)) \textcolor{keyword}{call }set\_up\_ale\_sponge\_field(s, g, tv%S, acsp)
283   \textcolor{keywordflow}{else}
284     \textcolor{keyword}{call }mom\_error(fatal, \textcolor{stringliteral}{"dense\_water\_initialize\_sponges: trying to use non ALE sponge"})
285 \textcolor{keywordflow}{  endif}
\end{DoxyCode}
\mbox{\Hypertarget{namespacedense__water__initialization_ae2a5062c406c66b1917f2ad564d4a5e6}\label{namespacedense__water__initialization_ae2a5062c406c66b1917f2ad564d4a5e6}} 
\index{dense\+\_\+water\+\_\+initialization@{dense\+\_\+water\+\_\+initialization}!dense\+\_\+water\+\_\+initialize\+\_\+topography@{dense\+\_\+water\+\_\+initialize\+\_\+topography}}
\index{dense\+\_\+water\+\_\+initialize\+\_\+topography@{dense\+\_\+water\+\_\+initialize\+\_\+topography}!dense\+\_\+water\+\_\+initialization@{dense\+\_\+water\+\_\+initialization}}
\subsubsection{\texorpdfstring{dense\+\_\+water\+\_\+initialize\+\_\+topography()}{dense\_water\_initialize\_topography()}}
{\footnotesize\ttfamily subroutine, public dense\+\_\+water\+\_\+initialization\+::dense\+\_\+water\+\_\+initialize\+\_\+topography (\begin{DoxyParamCaption}\item[{real, dimension(g\%isd\+:g\%ied,g\%jsd\+:g\%jed), intent(out)}]{D,  }\item[{type(dyn\+\_\+horgrid\+\_\+type), intent(in)}]{G,  }\item[{type(param\+\_\+file\+\_\+type), intent(in)}]{param\+\_\+file,  }\item[{real, intent(in)}]{max\+\_\+depth }\end{DoxyParamCaption})}



Initialize the topography field for the dense water experiment. 


\begin{DoxyParams}[1]{Parameters}
\mbox{\tt in}  & {\em g} & The dynamic horizontal grid type\\
\hline
\mbox{\tt out}  & {\em d} & Ocean bottom depth in the units of depth\+\_\+max\\
\hline
\mbox{\tt in}  & {\em param\+\_\+file} & Parameter file structure\\
\hline
\mbox{\tt in}  & {\em max\+\_\+depth} & Maximum ocean depth in arbitrary units \\
\hline
\end{DoxyParams}


Definition at line 36 of file dense\+\_\+water\+\_\+initialization.\+F90.


\begin{DoxyCode}
36   \textcolor{keywordtype}{type}(dyn\_horgrid\_type),  \textcolor{keywordtype}{intent(in)}  :: g\textcolor{comment}{ !< The dynamic horizontal grid type}
37   \textcolor{keywordtype}{real}, \textcolor{keywordtype}{dimension(G%isd:G%ied,G%jsd:G%jed)}, &
38                            \textcolor{keywordtype}{intent(out)} :: d\textcolor{comment}{ !< Ocean bottom depth in the units of depth\_max}
39   \textcolor{keywordtype}{type}(param\_file\_type),   \textcolor{keywordtype}{intent(in)}  :: param\_file\textcolor{comment}{ !< Parameter file structure}
40   \textcolor{keywordtype}{real},                    \textcolor{keywordtype}{intent(in)}  :: max\_depth\textcolor{comment}{ !< Maximum ocean depth in arbitrary units}
41 
42   \textcolor{comment}{! Local variables}
43   \textcolor{keywordtype}{real}, \textcolor{keywordtype}{dimension(5)} :: domain\_params \textcolor{comment}{! nondimensional widths of all domain sections}
44   \textcolor{keywordtype}{real} :: sill\_frac, shelf\_frac
45   \textcolor{keywordtype}{integer} :: i, j
46   \textcolor{keywordtype}{real} :: x
47 
48   \textcolor{keyword}{call }get\_param(param\_file, mdl, \textcolor{stringliteral}{"DENSE\_WATER\_DOMAIN\_PARAMS"}, domain\_params, &
49        \textcolor{stringliteral}{"Fractional widths of all the domain sections for the dense water experiment.\(\backslash\)n"}//&
50        \textcolor{stringliteral}{"As a 5-element vector:\(\backslash\)n"}//&
51        \textcolor{stringliteral}{"  - open ocean, the section at maximum depth\(\backslash\)n"}//&
52        \textcolor{stringliteral}{"  - downslope, the downward overflow slope\(\backslash\)n"}//&
53        \textcolor{stringliteral}{"  - sill separating downslope from upslope\(\backslash\)n"}//&
54        \textcolor{stringliteral}{"  - upslope, the upward slope accumulating dense water\(\backslash\)n"}//&
55        \textcolor{stringliteral}{"  - the shelf in the dense formation region."}, &
56        units=\textcolor{stringliteral}{"nondim"}, fail\_if\_missing=.true.)
57   \textcolor{keyword}{call }get\_param(param\_file, mdl, \textcolor{stringliteral}{"DENSE\_WATER\_SILL\_DEPTH"}, sill\_frac, &
58        \textcolor{stringliteral}{"Depth of the sill separating downslope from upslope, as fraction of basin depth."}, &
59        units=\textcolor{stringliteral}{"nondim"}, default=default\_sill)
60   \textcolor{keyword}{call }get\_param(param\_file, mdl, \textcolor{stringliteral}{"DENSE\_WATER\_SHELF\_DEPTH"}, shelf\_frac, &
61        \textcolor{stringliteral}{"Depth of the shelf region accumulating dense water for overflow, as fraction of basin depth."}, &
62        units=\textcolor{stringliteral}{"nondim"}, default=default\_shelf)
63 
64   \textcolor{keywordflow}{do} i = 2, 5
65     \textcolor{comment}{! turn widths into positions}
66     domain\_params(i) = domain\_params(i-1) + domain\_params(i)
67 \textcolor{keywordflow}{  enddo}
68 
69   \textcolor{keywordflow}{do} j = g%jsc,g%jec
70     \textcolor{keywordflow}{do} i = g%isc,g%iec
71       \textcolor{comment}{! compute normalised zonal coordinate}
72       x = (g%geoLonT(i,j) - g%west\_lon) / g%len\_lon
73 
74       \textcolor{keywordflow}{if} (x <= domain\_params(1)) \textcolor{keywordflow}{then}
75         \textcolor{comment}{! open ocean region}
76         d(i,j) = max\_depth
77       \textcolor{keywordflow}{elseif} (x <= domain\_params(2)) \textcolor{keywordflow}{then}
78         \textcolor{comment}{! downslope region, linear}
79         d(i,j) = max\_depth - (1.0 - sill\_frac) * max\_depth * &
80              (x - domain\_params(1)) / (domain\_params(2) - domain\_params(1))
81       \textcolor{keywordflow}{elseif} (x <= domain\_params(3)) \textcolor{keywordflow}{then}
82         \textcolor{comment}{! sill region}
83         d(i,j) = sill\_frac * max\_depth
84       \textcolor{keywordflow}{elseif} (x <= domain\_params(4)) \textcolor{keywordflow}{then}
85         \textcolor{comment}{! upslope region}
86         d(i,j) = sill\_frac * max\_depth + (shelf\_frac - sill\_frac) * max\_depth * &
87              (x - domain\_params(3)) / (domain\_params(4) - domain\_params(3))
88       \textcolor{keywordflow}{else}
89         \textcolor{comment}{! shelf region}
90         d(i,j) = shelf\_frac * max\_depth
91 \textcolor{keywordflow}{      endif}
92 \textcolor{keywordflow}{    enddo}
93 \textcolor{keywordflow}{  enddo}
94 
\end{DoxyCode}
\mbox{\Hypertarget{namespacedense__water__initialization_a0e1384953bfbb302a7b93dd7abb6cb7b}\label{namespacedense__water__initialization_a0e1384953bfbb302a7b93dd7abb6cb7b}} 
\index{dense\+\_\+water\+\_\+initialization@{dense\+\_\+water\+\_\+initialization}!dense\+\_\+water\+\_\+initialize\+\_\+ts@{dense\+\_\+water\+\_\+initialize\+\_\+ts}}
\index{dense\+\_\+water\+\_\+initialize\+\_\+ts@{dense\+\_\+water\+\_\+initialize\+\_\+ts}!dense\+\_\+water\+\_\+initialization@{dense\+\_\+water\+\_\+initialization}}
\subsubsection{\texorpdfstring{dense\+\_\+water\+\_\+initialize\+\_\+ts()}{dense\_water\_initialize\_ts()}}
{\footnotesize\ttfamily subroutine, public dense\+\_\+water\+\_\+initialization\+::dense\+\_\+water\+\_\+initialize\+\_\+ts (\begin{DoxyParamCaption}\item[{type(ocean\+\_\+grid\+\_\+type), intent(in)}]{G,  }\item[{type(verticalgrid\+\_\+type), intent(in)}]{GV,  }\item[{type(param\+\_\+file\+\_\+type), intent(in)}]{param\+\_\+file,  }\item[{type(eos\+\_\+type), pointer}]{eqn\+\_\+of\+\_\+state,  }\item[{real, dimension( g \%isd\+: g \%ied, g \%jsd\+: g \%jed, gv \%ke), intent(out)}]{T,  }\item[{real, dimension( g \%isd\+: g \%ied, g \%jsd\+: g \%jed, gv \%ke), intent(out)}]{S,  }\item[{real, dimension( g \%isd\+: g \%ied, g \%jsd\+: g \%jed, gv \%ke), intent(in)}]{h,  }\item[{logical, intent(in), optional}]{just\+\_\+read\+\_\+params }\end{DoxyParamCaption})}



Initialize the temperature and salinity for the dense water experiment. 


\begin{DoxyParams}[1]{Parameters}
\mbox{\tt in}  & {\em g} & Horizontal grid control structure\\
\hline
\mbox{\tt in}  & {\em gv} & Vertical grid control structure\\
\hline
\mbox{\tt in}  & {\em param\+\_\+file} & Parameter file structure\\
\hline
 & {\em eqn\+\_\+of\+\_\+state} & E\+OS structure\\
\hline
\mbox{\tt out}  & {\em t} & Output temperature \mbox{[}degC\mbox{]}\\
\hline
\mbox{\tt out}  & {\em s} & Output salinity \mbox{[}ppt\mbox{]}\\
\hline
\mbox{\tt in}  & {\em h} & Layer thicknesses \mbox{[}H $\sim$$>$ m or kg m-\/2\mbox{]}\\
\hline
\mbox{\tt in}  & {\em just\+\_\+read\+\_\+params} & If present and true, this call will only read parameters without changing h. \\
\hline
\end{DoxyParams}


Definition at line 99 of file dense\+\_\+water\+\_\+initialization.\+F90.


\begin{DoxyCode}
99   \textcolor{keywordtype}{type}(ocean\_grid\_type),                     \textcolor{keywordtype}{intent(in)}  :: g\textcolor{comment}{ !< Horizontal grid control structure}
100   \textcolor{keywordtype}{type}(verticalgrid\_type),                   \textcolor{keywordtype}{intent(in)}  :: gv\textcolor{comment}{ !< Vertical grid control structure}
101   \textcolor{keywordtype}{type}(param\_file\_type),                     \textcolor{keywordtype}{intent(in)}  :: param\_file\textcolor{comment}{ !< Parameter file structure}
102   \textcolor{keywordtype}{type}(eos\_type),                            \textcolor{keywordtype}{pointer}     :: eqn\_of\_state\textcolor{comment}{ !< EOS structure}
103   \textcolor{keywordtype}{real}, \textcolor{keywordtype}{dimension(SZI\_(G),SZJ\_(G),SZK\_(GV))}, \textcolor{keywordtype}{intent(out)} :: t\textcolor{comment}{ !< Output temperature [degC]}
104   \textcolor{keywordtype}{real}, \textcolor{keywordtype}{dimension(SZI\_(G),SZJ\_(G),SZK\_(GV))}, \textcolor{keywordtype}{intent(out)} :: s\textcolor{comment}{ !< Output salinity [ppt]}
105   \textcolor{keywordtype}{real}, \textcolor{keywordtype}{dimension(SZI\_(G),SZJ\_(G),SZK\_(GV))}, \textcolor{keywordtype}{intent(in)}  :: h\textcolor{comment}{ !< Layer thicknesses [H ~> m or kg m-2]}
106   \textcolor{keywordtype}{logical},       \textcolor{keywordtype}{optional}, \textcolor{keywordtype}{intent(in)}  :: just\_read\_params\textcolor{comment}{ !< If present and true, this call will}
107 \textcolor{comment}{                                                      !! only read parameters without changing h.}
108   \textcolor{comment}{! Local variables}
109   \textcolor{keywordtype}{real} :: mld, s\_ref, s\_range, t\_ref
110   \textcolor{keywordtype}{real} :: zi, zmid
111   \textcolor{keywordtype}{logical} :: just\_read    \textcolor{comment}{! If true, just read parameters but set nothing.}
112   \textcolor{keywordtype}{integer} :: i, j, k, nz
113 
114   nz = gv%ke
115 
116   just\_read = .false. ; \textcolor{keywordflow}{if} (\textcolor{keyword}{present}(just\_read\_params)) just\_read = just\_read\_params
117 
118   \textcolor{keyword}{call }get\_param(param\_file, mdl, \textcolor{stringliteral}{"DENSE\_WATER\_MLD"}, mld, &
119        \textcolor{stringliteral}{"Depth of unstratified mixed layer as a fraction of the water column."}, &
120        units=\textcolor{stringliteral}{"nondim"}, default=default\_mld, do\_not\_log=just\_read)
121   \textcolor{keyword}{call }get\_param(param\_file, mdl, \textcolor{stringliteral}{"S\_REF"}, s\_ref, \textcolor{stringliteral}{'Reference salinity'}, &
122                  default=35.0, units=\textcolor{stringliteral}{'1e-3'}, do\_not\_log=just\_read)
123   \textcolor{keyword}{call }get\_param(param\_file, mdl,\textcolor{stringliteral}{"T\_REF"}, t\_ref, \textcolor{stringliteral}{'Reference temperature'}, units=\textcolor{stringliteral}{'degC'}, &
124                 fail\_if\_missing=.not.just\_read, do\_not\_log=just\_read)
125   \textcolor{keyword}{call }get\_param(param\_file, mdl,\textcolor{stringliteral}{"S\_RANGE"}, s\_range, \textcolor{stringliteral}{'Initial salinity range'}, &
126                 units=\textcolor{stringliteral}{'1e-3'}, default=2.0, do\_not\_log=just\_read)
127 
128   \textcolor{keywordflow}{if} (just\_read) \textcolor{keywordflow}{return} \textcolor{comment}{! All run-time parameters have been read, so return.}
129 
130   \textcolor{comment}{! uniform temperature everywhere}
131   t(:,:,:) = t\_ref
132 
133   \textcolor{keywordflow}{do} j = g%jsc,g%jec
134     \textcolor{keywordflow}{do} i = g%isc,g%iec
135       zi = 0.
136       \textcolor{keywordflow}{do} k = 1,nz
137         \textcolor{comment}{! nondimensional middle of layer}
138         zmid = zi + 0.5 * h(i,j,k) / (gv%Z\_to\_H * g%max\_depth)
139 
140         \textcolor{keywordflow}{if} (zmid < mld) \textcolor{keywordflow}{then}
141           \textcolor{comment}{! use reference salinity in the mixed layer}
142           s(i,j,k) = s\_ref
143         \textcolor{keywordflow}{else}
144           \textcolor{comment}{! linear between bottom of mixed layer and bottom}
145           s(i,j,k) = s\_ref + s\_range * (zmid - mld) / (1.0 - mld)
146 \textcolor{keywordflow}{        endif}
147 
148         zi = zi + h(i,j,k) / (gv%Z\_to\_H * g%max\_depth)
149 \textcolor{keywordflow}{      enddo}
150 \textcolor{keywordflow}{    enddo}
151 \textcolor{keywordflow}{  enddo}
\end{DoxyCode}
