\hypertarget{namespacekelvin__initialization}{}\section{kelvin\+\_\+initialization Module Reference}
\label{namespacekelvin__initialization}\index{kelvin\+\_\+initialization@{kelvin\+\_\+initialization}}


\subsection{Detailed Description}
Configures the model for the Kelvin wave experiment. 

Kelvin = coastally-\/trapped Kelvin waves from the R\+O\+MS examples. Initialize with level surfaces and drive the wave in at the west, radiate out at the east. \subsection*{Data Types}
\begin{DoxyCompactItemize}
\item 
type \hyperlink{structkelvin__initialization_1_1kelvin__obc__cs}{kelvin\+\_\+obc\+\_\+cs}
\begin{DoxyCompactList}\small\item\em Control structure for Kelvin wave open boundaries. \end{DoxyCompactList}\end{DoxyCompactItemize}
\subsection*{Functions/\+Subroutines}
\begin{DoxyCompactItemize}
\item 
logical function, public \hyperlink{namespacekelvin__initialization_a987148fd20c38f1f4897661a39c3120e}{register\+\_\+kelvin\+\_\+obc} (param\+\_\+file, CS, O\+B\+C\+\_\+\+Reg)
\begin{DoxyCompactList}\small\item\em Add Kelvin wave to O\+BC registry. \end{DoxyCompactList}\item 
subroutine, public \hyperlink{namespacekelvin__initialization_a9c8e0745879d099cef92df7f16c67f9c}{kelvin\+\_\+obc\+\_\+end} (CS)
\begin{DoxyCompactList}\small\item\em Clean up the Kelvin wave O\+BC from registry. \end{DoxyCompactList}\item 
subroutine, public \hyperlink{namespacekelvin__initialization_abddff8dbfe770caf9b7d5564b3a0fc6d}{kelvin\+\_\+initialize\+\_\+topography} (D, G, param\+\_\+file, max\+\_\+depth, US)
\begin{DoxyCompactList}\small\item\em This subroutine sets up the Kelvin topography and land mask. \end{DoxyCompactList}\item 
subroutine, public \hyperlink{namespacekelvin__initialization_a39f47303961021f5605578c00722add2}{kelvin\+\_\+set\+\_\+obc\+\_\+data} (O\+BC, CS, G, GV, US, h, Time)
\begin{DoxyCompactList}\small\item\em This subroutine sets the properties of flow at open boundary conditions. \end{DoxyCompactList}\end{DoxyCompactItemize}


\subsection{Function/\+Subroutine Documentation}
\mbox{\Hypertarget{namespacekelvin__initialization_abddff8dbfe770caf9b7d5564b3a0fc6d}\label{namespacekelvin__initialization_abddff8dbfe770caf9b7d5564b3a0fc6d}} 
\index{kelvin\+\_\+initialization@{kelvin\+\_\+initialization}!kelvin\+\_\+initialize\+\_\+topography@{kelvin\+\_\+initialize\+\_\+topography}}
\index{kelvin\+\_\+initialize\+\_\+topography@{kelvin\+\_\+initialize\+\_\+topography}!kelvin\+\_\+initialization@{kelvin\+\_\+initialization}}
\subsubsection{\texorpdfstring{kelvin\+\_\+initialize\+\_\+topography()}{kelvin\_initialize\_topography()}}
{\footnotesize\ttfamily subroutine, public kelvin\+\_\+initialization\+::kelvin\+\_\+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,  }\item[{type(unit\+\_\+scale\+\_\+type), intent(in), optional}]{US }\end{DoxyParamCaption})}



This subroutine sets up the Kelvin topography and land mask. 


\begin{DoxyParams}[1]{Parameters}
\mbox{\tt in}  & {\em g} & The dynamic horizontal grid type\\
\hline
\mbox{\tt out}  & {\em d} & Ocean bottom depth in m or Z if US is present\\
\hline
\mbox{\tt in}  & {\em param\+\_\+file} & Parameter file structure\\
\hline
\mbox{\tt in}  & {\em max\+\_\+depth} & Maximum model depth in the units of D\\
\hline
\mbox{\tt in}  & {\em us} & A dimensional unit scaling type \\
\hline
\end{DoxyParams}


Definition at line 121 of file Kelvin\+\_\+initialization.\+F90.


\begin{DoxyCode}
121   \textcolor{keywordtype}{type}(dyn\_horgrid\_type),          \textcolor{keywordtype}{intent(in)}  :: g\textcolor{comment}{ !< The dynamic horizontal grid type}
122   \textcolor{keywordtype}{real}, \textcolor{keywordtype}{dimension(G%isd:G%ied,G%jsd:G%jed)}, &
123                                    \textcolor{keywordtype}{intent(out)} :: d\textcolor{comment}{ !< Ocean bottom depth in m or Z if US is present}
124   \textcolor{keywordtype}{type}(param\_file\_type),           \textcolor{keywordtype}{intent(in)}  :: param\_file\textcolor{comment}{ !< Parameter file structure}
125   \textcolor{keywordtype}{real},                            \textcolor{keywordtype}{intent(in)}  :: max\_depth\textcolor{comment}{ !< Maximum model depth in the units of D}
126   \textcolor{keywordtype}{type}(unit\_scale\_type), \textcolor{keywordtype}{optional}, \textcolor{keywordtype}{intent(in)}  :: us\textcolor{comment}{ !< A dimensional unit scaling type}
127 
128   \textcolor{comment}{! Local variables}
129   \textcolor{keywordtype}{character(len=40)}  :: mdl = \textcolor{stringliteral}{"Kelvin\_initialize\_topography"} \textcolor{comment}{! This subroutine's name.}
130   \textcolor{keywordtype}{real} :: m\_to\_z  \textcolor{comment}{! A dimensional rescaling factor.}
131   \textcolor{keywordtype}{real} :: min\_depth \textcolor{comment}{! The minimum and maximum depths [Z ~> m].}
132   \textcolor{keywordtype}{real} :: pi \textcolor{comment}{! 3.1415...}
133   \textcolor{keywordtype}{real} :: coast\_offset1, coast\_offset2, coast\_angle, right\_angle
134   \textcolor{keywordtype}{integer} :: i, j
135 
136   \textcolor{keyword}{call }mom\_mesg(\textcolor{stringliteral}{"  Kelvin\_initialization.F90, Kelvin\_initialize\_topography: setting topography"}, 5)
137 
138   m\_to\_z = 1.0 ; \textcolor{keywordflow}{if} (\textcolor{keyword}{present}(us)) m\_to\_z = us%m\_to\_Z
139 
140   \textcolor{keyword}{call }get\_param(param\_file, mdl, \textcolor{stringliteral}{"MINIMUM\_DEPTH"}, min\_depth, &
141                  \textcolor{stringliteral}{"The minimum depth of the ocean."}, units=\textcolor{stringliteral}{"m"}, default=0.0, scale=m\_to\_z)
142   \textcolor{keyword}{call }get\_param(param\_file, mdl, \textcolor{stringliteral}{"ROTATED\_COAST\_OFFSET\_1"}, coast\_offset1, &
143                  default=100.0, do\_not\_log=.true.)
144   \textcolor{keyword}{call }get\_param(param\_file, mdl, \textcolor{stringliteral}{"ROTATED\_COAST\_OFFSET\_2"}, coast\_offset2, &
145                  default=10.0, do\_not\_log=.true.)
146   \textcolor{keyword}{call }get\_param(param\_file, mdl, \textcolor{stringliteral}{"ROTATED\_COAST\_ANGLE"}, coast\_angle, &
147                  default=11.3, do\_not\_log=.true.)
148 
149   coast\_angle = coast\_angle * (atan(1.0)/45.) \textcolor{comment}{! Convert to radians}
150   right\_angle = 2 * atan(1.0)
151 
152   \textcolor{keywordflow}{do} j=g%jsc,g%jec ; \textcolor{keywordflow}{do} i=g%isc,g%iec
153     d(i,j) = max\_depth
154     \textcolor{comment}{! Southern side}
155     \textcolor{keywordflow}{if} ((g%geoLonT(i,j) - g%west\_lon > coast\_offset1) .AND. &
156         (atan2(g%geoLatT(i,j) - g%south\_lat + coast\_offset2, &
157          g%geoLonT(i,j) - g%west\_lon - coast\_offset1) < coast\_angle)) &
158       d(i,j) = 0.5*min\_depth
159     \textcolor{comment}{! Northern side}
160     \textcolor{keywordflow}{if} ((g%geoLonT(i,j) - g%west\_lon < g%len\_lon - coast\_offset1) .AND. &
161         (atan2(g%len\_lat + g%south\_lat + coast\_offset2 - g%geoLatT(i,j), &
162          g%len\_lon + g%west\_lon - coast\_offset1 - g%geoLonT(i,j)) < coast\_angle)) &
163       d(i,j) = 0.5*min\_depth
164 
165     \textcolor{keywordflow}{if} (d(i,j) > max\_depth) d(i,j) = max\_depth
166     \textcolor{keywordflow}{if} (d(i,j) < min\_depth) d(i,j) = 0.5*min\_depth
167 \textcolor{keywordflow}{  enddo} ;\textcolor{keywordflow}{ enddo}
168 
\end{DoxyCode}
\mbox{\Hypertarget{namespacekelvin__initialization_a9c8e0745879d099cef92df7f16c67f9c}\label{namespacekelvin__initialization_a9c8e0745879d099cef92df7f16c67f9c}} 
\index{kelvin\+\_\+initialization@{kelvin\+\_\+initialization}!kelvin\+\_\+obc\+\_\+end@{kelvin\+\_\+obc\+\_\+end}}
\index{kelvin\+\_\+obc\+\_\+end@{kelvin\+\_\+obc\+\_\+end}!kelvin\+\_\+initialization@{kelvin\+\_\+initialization}}
\subsubsection{\texorpdfstring{kelvin\+\_\+obc\+\_\+end()}{kelvin\_obc\_end()}}
{\footnotesize\ttfamily subroutine, public kelvin\+\_\+initialization\+::kelvin\+\_\+obc\+\_\+end (\begin{DoxyParamCaption}\item[{type(\hyperlink{structkelvin__initialization_1_1kelvin__obc__cs}{kelvin\+\_\+obc\+\_\+cs}), pointer}]{CS }\end{DoxyParamCaption})}



Clean up the Kelvin wave O\+BC from registry. 


\begin{DoxyParams}{Parameters}
{\em cs} & Kelvin wave control structure. \\
\hline
\end{DoxyParams}


Definition at line 111 of file Kelvin\+\_\+initialization.\+F90.


\begin{DoxyCode}
111   \textcolor{keywordtype}{type}(kelvin\_obc\_cs), \textcolor{keywordtype}{pointer}    :: cs\textcolor{comment}{         !< Kelvin wave control structure.}
112 
113   \textcolor{keywordflow}{if} (\textcolor{keyword}{associated}(cs)) \textcolor{keywordflow}{then}
114     \textcolor{keyword}{deallocate}(cs)
115 \textcolor{keywordflow}{  endif}
\end{DoxyCode}
\mbox{\Hypertarget{namespacekelvin__initialization_a39f47303961021f5605578c00722add2}\label{namespacekelvin__initialization_a39f47303961021f5605578c00722add2}} 
\index{kelvin\+\_\+initialization@{kelvin\+\_\+initialization}!kelvin\+\_\+set\+\_\+obc\+\_\+data@{kelvin\+\_\+set\+\_\+obc\+\_\+data}}
\index{kelvin\+\_\+set\+\_\+obc\+\_\+data@{kelvin\+\_\+set\+\_\+obc\+\_\+data}!kelvin\+\_\+initialization@{kelvin\+\_\+initialization}}
\subsubsection{\texorpdfstring{kelvin\+\_\+set\+\_\+obc\+\_\+data()}{kelvin\_set\_obc\_data()}}
{\footnotesize\ttfamily subroutine, public kelvin\+\_\+initialization\+::kelvin\+\_\+set\+\_\+obc\+\_\+data (\begin{DoxyParamCaption}\item[{type(ocean\+\_\+obc\+\_\+type), pointer}]{O\+BC,  }\item[{type(\hyperlink{structkelvin__initialization_1_1kelvin__obc__cs}{kelvin\+\_\+obc\+\_\+cs}), pointer}]{CS,  }\item[{type(ocean\+\_\+grid\+\_\+type), intent(in)}]{G,  }\item[{type(verticalgrid\+\_\+type), intent(in)}]{GV,  }\item[{type(unit\+\_\+scale\+\_\+type), intent(in)}]{US,  }\item[{real, dimension(szi\+\_\+(g),szj\+\_\+(g),szk\+\_\+(g)), intent(in)}]{h,  }\item[{type(time\+\_\+type), intent(in)}]{Time }\end{DoxyParamCaption})}



This subroutine sets the properties of flow at open boundary conditions. 


\begin{DoxyParams}[1]{Parameters}
 & {\em obc} & This open boundary condition type specifies whether, where, and what open boundary conditions are used.\\
\hline
 & {\em cs} & Kelvin wave control structure.\\
\hline
\mbox{\tt in}  & {\em g} & The ocean\textquotesingle{}s grid structure.\\
\hline
\mbox{\tt in}  & {\em gv} & The ocean\textquotesingle{}s vertical grid structure.\\
\hline
\mbox{\tt in}  & {\em us} & A dimensional unit scaling type\\
\hline
\mbox{\tt in}  & {\em h} & layer thickness \mbox{[}H $\sim$$>$ m or kg m-\/2\mbox{]}.\\
\hline
\mbox{\tt in}  & {\em time} & model time. \\
\hline
\end{DoxyParams}


Definition at line 173 of file Kelvin\+\_\+initialization.\+F90.


\begin{DoxyCode}
173   \textcolor{keywordtype}{type}(ocean\_obc\_type),    \textcolor{keywordtype}{pointer}    :: obc\textcolor{comment}{  !< This open boundary condition type specifies}
174 \textcolor{comment}{                                              !! whether, where, and what open boundary}
175 \textcolor{comment}{                                              !! conditions are used.}
176   \textcolor{keywordtype}{type}(kelvin\_obc\_cs),     \textcolor{keywordtype}{pointer}    :: cs\textcolor{comment}{   !< Kelvin wave control structure.}
177   \textcolor{keywordtype}{type}(ocean\_grid\_type),   \textcolor{keywordtype}{intent(in)} :: g\textcolor{comment}{    !< The ocean's grid structure.}
178   \textcolor{keywordtype}{type}(verticalgrid\_type), \textcolor{keywordtype}{intent(in)} :: gv\textcolor{comment}{   !< The ocean's vertical grid structure.}
179   \textcolor{keywordtype}{type}(unit\_scale\_type),   \textcolor{keywordtype}{intent(in)} :: us\textcolor{comment}{    !< A dimensional unit scaling type}
180   \textcolor{keywordtype}{real}, \textcolor{keywordtype}{dimension(SZI\_(G),SZJ\_(G),SZK\_(G))}, \textcolor{keywordtype}{intent(in)} :: h\textcolor{comment}{ !< layer thickness [H ~> m or kg m-2].}
181   \textcolor{keywordtype}{type}(time\_type),         \textcolor{keywordtype}{intent(in)} :: time\textcolor{comment}{ !< model time.}
182 
183   \textcolor{comment}{! The following variables are used to set up the transport in the Kelvin example.}
184   \textcolor{keywordtype}{real} :: time\_sec, cff
185   \textcolor{keywordtype}{real} :: n0           \textcolor{comment}{! Brunt-Vaisala frequency [s-1]}
186   \textcolor{keywordtype}{real} :: plx\textcolor{comment}{          !< Longshore wave parameter}
187   \textcolor{keywordtype}{real} :: pmz\textcolor{comment}{          !< Vertical wave parameter}
188   \textcolor{keywordtype}{real} :: lambda\textcolor{comment}{       !< Offshore decay scale}
189   \textcolor{keywordtype}{real} :: omega\textcolor{comment}{        !< Wave frequency [s-1]}
190   \textcolor{keywordtype}{real} :: pi
191   \textcolor{keywordtype}{integer} :: i, j, k, n, is, ie, js, je, isd, ied, jsd, jed, nz
192   \textcolor{keywordtype}{integer} :: isdb, iedb, jsdb, jedb
193   \textcolor{keywordtype}{real}    :: fac, x, y, x1, y1
194   \textcolor{keywordtype}{real}    :: val1, val2, sina, cosa
195   \textcolor{keywordtype}{type}(obc\_segment\_type), \textcolor{keywordtype}{pointer} :: segment => null()
196 
197   is = g%isc ; ie = g%iec ; js = g%jsc ; je = g%jec ; nz = g%ke
198   isd = g%isd ; ied = g%ied ; jsd = g%jsd ; jed = g%jed
199   isdb = g%IsdB ; iedb = g%IedB ; jsdb = g%JsdB ; jedb = g%JedB
200 
201   \textcolor{keywordflow}{if} (.not.\textcolor{keyword}{associated}(obc)) \textcolor{keyword}{call }mom\_error(fatal, \textcolor{stringliteral}{'Kelvin\_initialization.F90: '}// &
202         \textcolor{stringliteral}{'Kelvin\_set\_OBC\_data() was called but OBC type was not initialized!'})
203 
204   time\_sec = time\_type\_to\_real(time)
205   pi = 4.0*atan(1.0)
206   fac = 1.0
207 
208   \textcolor{keywordflow}{if} (cs%mode == 0) \textcolor{keywordflow}{then}
209     omega = 2.0 * pi / (12.42 * 3600.0)      \textcolor{comment}{! M2 Tide period}
210     val1 = us%m\_to\_Z * sin(omega * time\_sec)
211   \textcolor{keywordflow}{else}
212     n0 = us%L\_to\_m*us%s\_to\_T * sqrt((cs%rho\_range / cs%rho\_0) * gv%g\_Earth * (us%m\_to\_Z * cs%H0))
213     \textcolor{comment}{! Two wavelengths in domain}
214     plx = 4.0 * pi / g%len\_lon
215     pmz = pi * cs%mode / cs%H0
216     lambda = pmz * cs%F\_0 / n0
217     omega = cs%F\_0 * plx / lambda
218 
219     \textcolor{comment}{! lambda = PI * CS%mode * CS%F\_0 / (CS%H0 * N0)}
220     \textcolor{comment}{! omega = (4.0 * CS%H0 * N0)  / (CS%mode * G%len\_lon)}
221 \textcolor{keywordflow}{  endif}
222 
223   sina = sin(cs%coast\_angle)
224   cosa = cos(cs%coast\_angle)
225   \textcolor{keywordflow}{do} n=1,obc%number\_of\_segments
226     segment => obc%segment(n)
227     \textcolor{keywordflow}{if} (.not. segment%on\_pe) cycle
228     \textcolor{comment}{! Apply values to the inflow end only.}
229     \textcolor{keywordflow}{if} (segment%direction == obc\_direction\_e) cycle
230     \textcolor{keywordflow}{if} (segment%direction == obc\_direction\_n) cycle
231 
232     \textcolor{comment}{! This should be somewhere else...}
233     segment%Velocity\_nudging\_timescale\_in = 1.0/(0.3*86400)
234 
235     \textcolor{keywordflow}{if} (segment%direction == obc\_direction\_w) \textcolor{keywordflow}{then}
236       isdb = segment%HI%IsdB ; iedb = segment%HI%IedB
237       jsd = segment%HI%jsd ; jed = segment%HI%jed
238       jsdb = segment%HI%JsdB ; jedb = segment%HI%JedB
239       \textcolor{keywordflow}{do} j=jsd,jed ; \textcolor{keywordflow}{do} i=isdb,iedb
240         x1 = 1000. * g%geoLonCu(i,j)
241         y1 = 1000. * g%geoLatCu(i,j)
242         x = (x1 - cs%coast\_offset1) * cosa + y1 * sina
243         y = - (x1 - cs%coast\_offset1) * sina + y1 * cosa
244         \textcolor{keywordflow}{if} (cs%mode == 0) \textcolor{keywordflow}{then}
245           \textcolor{comment}{! Use inside bathymetry}
246           cff = sqrt(gv%g\_Earth * g%bathyT(i+1,j) )
247           val2 = fac * exp(- us%T\_to\_s*cs%F\_0 * us%m\_to\_L*y / cff)
248           segment%eta(i,j) = val2 * cos(omega * time\_sec)
249           segment%normal\_vel\_bt(i,j) = (val2 * (val1 * cff * cosa / &
250                  (g%bathyT(i+1,j) )) )
251           \textcolor{keywordflow}{if} (segment%nudged) \textcolor{keywordflow}{then}
252             \textcolor{keywordflow}{do} k=1,nz
253               segment%nudged\_normal\_vel(i,j,k) = (val2 * (val1 * cff * cosa / &
254                      (g%bathyT(i+1,j))) )
255 \textcolor{keywordflow}{            enddo}
256           \textcolor{keywordflow}{elseif} (segment%specified) \textcolor{keywordflow}{then}
257             \textcolor{keywordflow}{do} k=1,nz
258               segment%normal\_vel(i,j,k) = (val2 * (val1 * cff * cosa / &
259                      (g%bathyT(i+1,j) )) )
260               segment%normal\_trans(i,j,k) = segment%normal\_vel(i,j,k) * h(i+1,j,k) * g%dyCu(i,j)
261 \textcolor{keywordflow}{            enddo}
262 \textcolor{keywordflow}{          endif}
263         \textcolor{keywordflow}{else}
264           \textcolor{comment}{! Not rotated yet}
265           segment%eta(i,j) = 0.0
266           segment%normal\_vel\_bt(i,j) = 0.0
267           \textcolor{keywordflow}{if} (segment%nudged) \textcolor{keywordflow}{then}
268             \textcolor{keywordflow}{do} k=1,nz
269               segment%nudged\_normal\_vel(i,j,k) = us%m\_s\_to\_L\_T * fac * lambda / cs%F\_0 * &
270                    exp(- lambda * y) * cos(pi * cs%mode * (k - 0.5) / nz) * &
271                    cos(omega * time\_sec)
272 \textcolor{keywordflow}{            enddo}
273           \textcolor{keywordflow}{elseif} (segment%specified) \textcolor{keywordflow}{then}
274             \textcolor{keywordflow}{do} k=1,nz
275               segment%normal\_vel(i,j,k) = us%m\_s\_to\_L\_T * fac * lambda / cs%F\_0 * &
276                    exp(- lambda * y) * cos(pi * cs%mode * (k - 0.5) / nz) * &
277                    cos(omega * time\_sec)
278               segment%normal\_trans(i,j,k) = segment%normal\_vel(i,j,k) * h(i+1,j,k) * g%dyCu(i,j)
279 \textcolor{keywordflow}{            enddo}
280 \textcolor{keywordflow}{          endif}
281 \textcolor{keywordflow}{        endif}
282 \textcolor{keywordflow}{      enddo} ;\textcolor{keywordflow}{ enddo}
283       \textcolor{keywordflow}{if} (\textcolor{keyword}{associated}(segment%tangential\_vel)) \textcolor{keywordflow}{then}
284         \textcolor{keywordflow}{do} j=jsdb+1,jedb-1 ; \textcolor{keywordflow}{do} i=isdb,iedb
285           x1 = 1000. * g%geoLonBu(i,j)
286           y1 = 1000. * g%geoLatBu(i,j)
287           x = (x1 - cs%coast\_offset1) * cosa + y1 * sina
288           y = - (x1 - cs%coast\_offset1) * sina + y1 * cosa
289           cff =sqrt(gv%g\_Earth * g%bathyT(i+1,j) )
290           val2 = fac * exp(- us%T\_to\_s*cs%F\_0 * us%m\_to\_L*y / cff)
291           \textcolor{keywordflow}{if} (cs%mode == 0) \textcolor{keywordflow}{then} ; \textcolor{keywordflow}{do} k=1,nz
292             segment%tangential\_vel(i,j,k) = (val1 * val2 * cff * sina) / &
293                ( 0.5*(g%bathyT(i+1,j+1) +  g%bathyT(i+1,j) ) )
294 
295 \textcolor{keywordflow}{          enddo} ;\textcolor{keywordflow}{ endif}
296 \textcolor{keywordflow}{        enddo} ;\textcolor{keywordflow}{ enddo}
297 \textcolor{keywordflow}{      endif}
298     \textcolor{keywordflow}{else} \textcolor{comment}{! Must be south}
299       isd = segment%HI%isd ; ied = segment%HI%ied
300       jsdb = segment%HI%JsdB ; jedb = segment%HI%JedB
301       \textcolor{keywordflow}{do} j=jsdb,jedb ; \textcolor{keywordflow}{do} i=isd,ied
302         x1 = 1000. * g%geoLonCv(i,j)
303         y1 = 1000. * g%geoLatCv(i,j)
304         x = (x1 - cs%coast\_offset1) * cosa + y1 * sina
305         y = - (x1 - cs%coast\_offset1) * sina + y1 * cosa
306         \textcolor{keywordflow}{if} (cs%mode == 0) \textcolor{keywordflow}{then}
307           cff = sqrt(gv%g\_Earth * g%bathyT(i,j+1) )
308           val2 = fac * exp(- 0.5 * (g%CoriolisBu(i,j) + g%CoriolisBu(i-1,j)) * us%m\_to\_L*y / cff)
309           segment%eta(i,j) = val2 * cos(omega * time\_sec)
310           segment%normal\_vel\_bt(i,j) = us%L\_T\_to\_m\_s * (val1 * cff * sina / &
311                  (g%bathyT(i,j+1) )) * val2
312           \textcolor{keywordflow}{if} (segment%nudged) \textcolor{keywordflow}{then}
313             \textcolor{keywordflow}{do} k=1,nz
314               segment%nudged\_normal\_vel(i,j,k) = us%L\_T\_to\_m\_s * (val1 * cff * sina / &
315                      (g%bathyT(i,j+1) )) * val2
316 \textcolor{keywordflow}{            enddo}
317           \textcolor{keywordflow}{elseif} (segment%specified) \textcolor{keywordflow}{then}
318             \textcolor{keywordflow}{do} k=1,nz
319               segment%normal\_vel(i,j,k) = us%L\_T\_to\_m\_s * (val1 * cff * sina / &
320                      (g%bathyT(i,j+1) )) * val2
321               segment%normal\_trans(i,j,k) = segment%normal\_vel(i,j,k) * h(i,j+1,k) * g%dxCv(i,j)
322 \textcolor{keywordflow}{            enddo}
323 \textcolor{keywordflow}{          endif}
324         \textcolor{keywordflow}{else}
325           \textcolor{comment}{! Not rotated yet}
326           segment%eta(i,j) = 0.0
327           segment%normal\_vel\_bt(i,j) = 0.0
328           \textcolor{keywordflow}{if} (segment%nudged) \textcolor{keywordflow}{then}
329             \textcolor{keywordflow}{do} k=1,nz
330               segment%nudged\_normal\_vel(i,j,k) = us%m\_s\_to\_L\_T*fac * lambda / cs%F\_0 * &
331                    exp(- lambda * y) * cos(pi * cs%mode * (k - 0.5) / nz) * cosa
332 \textcolor{keywordflow}{            enddo}
333           \textcolor{keywordflow}{elseif} (segment%specified) \textcolor{keywordflow}{then}
334             \textcolor{keywordflow}{do} k=1,nz
335               segment%normal\_vel(i,j,k) = us%m\_s\_to\_L\_T*fac * lambda / cs%F\_0 * &
336                    exp(- lambda * y) * cos(pi * cs%mode * (k - 0.5) / nz) * cosa
337               segment%normal\_trans(i,j,k) = segment%normal\_vel(i,j,k) * h(i,j+1,k) * g%dxCv(i,j)
338 \textcolor{keywordflow}{            enddo}
339 \textcolor{keywordflow}{          endif}
340 \textcolor{keywordflow}{        endif}
341 \textcolor{keywordflow}{      enddo} ;\textcolor{keywordflow}{ enddo}
342       \textcolor{keywordflow}{if} (\textcolor{keyword}{associated}(segment%tangential\_vel)) \textcolor{keywordflow}{then}
343         \textcolor{keywordflow}{do} j=jsdb,jedb ; \textcolor{keywordflow}{do} i=isdb+1,iedb-1
344           x1 = 1000. * g%geoLonBu(i,j)
345           y1 = 1000. * g%geoLatBu(i,j)
346           x = (x1 - cs%coast\_offset1) * cosa + y1 * sina
347           y = - (x1 - cs%coast\_offset1) * sina + y1 * cosa
348           cff = sqrt(gv%g\_Earth * g%bathyT(i,j+1) )
349           val2 = fac * exp(- 0.5 * (g%CoriolisBu(i,j) + g%CoriolisBu(i-1,j)) * us%m\_to\_L*y / cff)
350           \textcolor{keywordflow}{if} (cs%mode == 0) \textcolor{keywordflow}{then} ; \textcolor{keywordflow}{do} k=1,nz
351             segment%tangential\_vel(i,j,k) = ((val1 * val2 * cff * sina) / &
352                 ( 0.5*((g%bathyT(i+1,j+1)) + g%bathyT(i,j+1))) )
353 \textcolor{keywordflow}{          enddo} ;\textcolor{keywordflow}{ endif}
354 \textcolor{keywordflow}{        enddo} ;\textcolor{keywordflow}{ enddo}
355 \textcolor{keywordflow}{      endif}
356 \textcolor{keywordflow}{    endif}
357 \textcolor{keywordflow}{  enddo}
358 
\end{DoxyCode}
\mbox{\Hypertarget{namespacekelvin__initialization_a987148fd20c38f1f4897661a39c3120e}\label{namespacekelvin__initialization_a987148fd20c38f1f4897661a39c3120e}} 
\index{kelvin\+\_\+initialization@{kelvin\+\_\+initialization}!register\+\_\+kelvin\+\_\+obc@{register\+\_\+kelvin\+\_\+obc}}
\index{register\+\_\+kelvin\+\_\+obc@{register\+\_\+kelvin\+\_\+obc}!kelvin\+\_\+initialization@{kelvin\+\_\+initialization}}
\subsubsection{\texorpdfstring{register\+\_\+kelvin\+\_\+obc()}{register\_kelvin\_obc()}}
{\footnotesize\ttfamily logical function, public kelvin\+\_\+initialization\+::register\+\_\+kelvin\+\_\+obc (\begin{DoxyParamCaption}\item[{type(param\+\_\+file\+\_\+type), intent(in)}]{param\+\_\+file,  }\item[{type(\hyperlink{structkelvin__initialization_1_1kelvin__obc__cs}{kelvin\+\_\+obc\+\_\+cs}), pointer}]{CS,  }\item[{type(obc\+\_\+registry\+\_\+type), pointer}]{O\+B\+C\+\_\+\+Reg }\end{DoxyParamCaption})}



Add Kelvin wave to O\+BC registry. 


\begin{DoxyParams}[1]{Parameters}
\mbox{\tt in}  & {\em param\+\_\+file} & parameter file.\\
\hline
 & {\em cs} & Kelvin wave control structure.\\
\hline
 & {\em obc\+\_\+reg} & O\+BC registry. \\
\hline
\end{DoxyParams}


Definition at line 54 of file Kelvin\+\_\+initialization.\+F90.


\begin{DoxyCode}
54   \textcolor{keywordtype}{type}(param\_file\_type),    \textcolor{keywordtype}{intent(in)} :: param\_file\textcolor{comment}{ !< parameter file.}
55   \textcolor{keywordtype}{type}(kelvin\_obc\_cs),      \textcolor{keywordtype}{pointer}    :: cs\textcolor{comment}{         !< Kelvin wave control structure.}
56   \textcolor{keywordtype}{type}(obc\_registry\_type),  \textcolor{keywordtype}{pointer}    :: obc\_reg\textcolor{comment}{    !< OBC registry.}
57 
58   \textcolor{comment}{! Local variables}
59   \textcolor{keywordtype}{logical} :: register\_kelvin\_obc
60   \textcolor{keywordtype}{character(len=40)}  :: mdl = \textcolor{stringliteral}{"register\_Kelvin\_OBC"}\textcolor{comment}{  !< This subroutine's name.}
61   \textcolor{keywordtype}{character(len=32)}  :: casename = \textcolor{stringliteral}{"Kelvin wave"}\textcolor{comment}{     !< This case's name.}
62   \textcolor{keywordtype}{character(len=200)} :: config
63 
64   \textcolor{keywordflow}{if} (\textcolor{keyword}{associated}(cs)) \textcolor{keywordflow}{then}
65     \textcolor{keyword}{call }mom\_error(warning, \textcolor{stringliteral}{"register\_Kelvin\_OBC called with an "}// &
66                             \textcolor{stringliteral}{"associated control structure."})
67     \textcolor{keywordflow}{return}
68 \textcolor{keywordflow}{  endif}
69   \textcolor{keyword}{allocate}(cs)
70 
71   \textcolor{keyword}{call }log\_version(param\_file, mdl, version, \textcolor{stringliteral}{""})
72   \textcolor{keyword}{call }get\_param(param\_file, mdl, \textcolor{stringliteral}{"KELVIN\_WAVE\_MODE"}, cs%mode, &
73                  \textcolor{stringliteral}{"Vertical Kelvin wave mode imposed at upstream open boundary."}, &
74                  default=0)
75   \textcolor{keyword}{call }get\_param(param\_file, mdl, \textcolor{stringliteral}{"F\_0"}, cs%F\_0, &
76                  default=0.0, do\_not\_log=.true.)
77   \textcolor{keyword}{call }get\_param(param\_file, mdl, \textcolor{stringliteral}{"TOPO\_CONFIG"}, config, do\_not\_log=.true.)
78   \textcolor{keywordflow}{if} (trim(config) == \textcolor{stringliteral}{"Kelvin"}) \textcolor{keywordflow}{then}
79     \textcolor{keyword}{call }get\_param(param\_file, mdl, \textcolor{stringliteral}{"ROTATED\_COAST\_OFFSET\_1"}, cs%coast\_offset1, &
80                    \textcolor{stringliteral}{"The distance along the southern and northern boundaries "}//&
81                    \textcolor{stringliteral}{"at which the coasts angle in."}, &
82                    units=\textcolor{stringliteral}{"km"}, default=100.0)
83     \textcolor{keyword}{call }get\_param(param\_file, mdl, \textcolor{stringliteral}{"ROTATED\_COAST\_OFFSET\_2"}, cs%coast\_offset2, &
84                    \textcolor{stringliteral}{"The distance from the southern and northern boundaries "}//&
85                    \textcolor{stringliteral}{"at which the coasts angle in."}, &
86                    units=\textcolor{stringliteral}{"km"}, default=10.0)
87     \textcolor{keyword}{call }get\_param(param\_file, mdl, \textcolor{stringliteral}{"ROTATED\_COAST\_ANGLE"}, cs%coast\_angle, &
88                    \textcolor{stringliteral}{"The angle of the southern bondary beyond X=ROTATED\_COAST\_OFFSET."}, &
89                    units=\textcolor{stringliteral}{"degrees"}, default=11.3)
90     cs%coast\_angle = cs%coast\_angle * (atan(1.0)/45.) \textcolor{comment}{! Convert to radians}
91     cs%coast\_offset1 = cs%coast\_offset1 * 1.e3          \textcolor{comment}{! Convert to m}
92     cs%coast\_offset2 = cs%coast\_offset2 * 1.e3          \textcolor{comment}{! Convert to m}
93 \textcolor{keywordflow}{  endif}
94   \textcolor{keywordflow}{if} (cs%mode /= 0) \textcolor{keywordflow}{then}
95     \textcolor{keyword}{call }get\_param(param\_file, mdl, \textcolor{stringliteral}{"DENSITY\_RANGE"}, cs%rho\_range, &
96                    default=2.0, do\_not\_log=.true.)
97     \textcolor{keyword}{call }get\_param(param\_file, mdl, \textcolor{stringliteral}{"RHO\_0"}, cs%rho\_0, &
98                    default=1035.0, do\_not\_log=.true.)
99     \textcolor{keyword}{call }get\_param(param\_file, mdl, \textcolor{stringliteral}{"MAXIMUM\_DEPTH"}, cs%H0, &
100                    default=1000.0, do\_not\_log=.true.)
101 \textcolor{keywordflow}{  endif}
102 
103   \textcolor{comment}{! Register the Kelvin open boundary.}
104   \textcolor{keyword}{call }register\_obc(casename, param\_file, obc\_reg)
105   register\_kelvin\_obc = .true.
106 
\end{DoxyCode}
