\hypertarget{namespacemom__geothermal}{}\section{mom\+\_\+geothermal Module Reference}
\label{namespacemom__geothermal}\index{mom\+\_\+geothermal@{mom\+\_\+geothermal}}


\subsection{Detailed Description}
Implemented geothermal heating at the ocean bottom. 

Geothermal heating can be added either in a layered isopycnal mode, in which the heating raises the density of the layer to the target density of the layer above, and then moves the water into that layer, or in a simple Eulerian mode, in which the bottommost G\+E\+O\+T\+H\+E\+R\+M\+A\+L\+\_\+\+T\+H\+I\+C\+K\+N\+E\+SS are heated. Geothermal heating will also provide a buoyant source of bottom T\+KE that can be used to further mix the near-\/bottom water. In cold fresh water lakes where heating increases density, water should be moved into deeper layers, but this is not implemented yet. \subsection*{Data Types}
\begin{DoxyCompactItemize}
\item 
type \hyperlink{structmom__geothermal_1_1geothermal__cs}{geothermal\+\_\+cs}
\begin{DoxyCompactList}\small\item\em Control structure for geothermal heating. \end{DoxyCompactList}\end{DoxyCompactItemize}
\subsection*{Functions/\+Subroutines}
\begin{DoxyCompactItemize}
\item 
subroutine, public \hyperlink{namespacemom__geothermal_a6982c9c83861b01e9ea07ce7215c2b7a}{geothermal\+\_\+entraining} (h, tv, dt, ea, eb, G, GV, US, CS, halo)
\begin{DoxyCompactList}\small\item\em Applies geothermal heating, including the movement of water between isopycnal layers to match the target densities. The heating is applied to the bottommost layers that occur within G\+E\+O\+T\+H\+E\+R\+M\+A\+L\+\_\+\+T\+H\+I\+C\+K\+N\+E\+SS of the bottom. If the partial derivative of the coordinate density with temperature is positive or very small, the layers are simply heated in place. Any heat that can not be applied to the ocean is returned (W\+H\+E\+RE)? \end{DoxyCompactList}\item 
subroutine, public \hyperlink{namespacemom__geothermal_a7cd5e2623232156804903f100daa6e88}{geothermal\+\_\+in\+\_\+place} (h, tv, dt, G, GV, US, CS, halo)
\begin{DoxyCompactList}\small\item\em Applies geothermal heating to the bottommost layers that occur within G\+E\+O\+T\+H\+E\+R\+M\+A\+L\+\_\+\+T\+H\+I\+C\+K\+N\+E\+SS of the bottom, by simply heating the water in place. Any heat that can not be applied to the ocean is returned (W\+H\+E\+RE)? \end{DoxyCompactList}\item 
subroutine, public \hyperlink{namespacemom__geothermal_a1b764e98a70404c9a13909f01068389c}{geothermal\+\_\+init} (Time, G, GV, US, param\+\_\+file, diag, CS, use\+A\+L\+Ealgorithm)
\begin{DoxyCompactList}\small\item\em Initialize parameters and allocate memory associated with the geothermal heating module. \end{DoxyCompactList}\item 
subroutine, public \hyperlink{namespacemom__geothermal_a0e5ab44d9a44f7b9f16e14c812f87141}{geothermal\+\_\+end} (CS)
\begin{DoxyCompactList}\small\item\em Clean up and deallocate memory associated with the geothermal heating module. \end{DoxyCompactList}\end{DoxyCompactItemize}


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



Clean up and deallocate memory associated with the geothermal heating module. 


\begin{DoxyParams}{Parameters}
{\em cs} & Geothermal heating control structure that will be deallocated in this subroutine. \\
\hline
\end{DoxyParams}


Definition at line 611 of file M\+O\+M\+\_\+geothermal.\+F90.


\begin{DoxyCode}
611   \textcolor{keywordtype}{type}(geothermal\_cs), \textcolor{keywordtype}{pointer} :: cs\textcolor{comment}{ !< Geothermal heating control structure that}
612 \textcolor{comment}{                                     !! will be deallocated in this subroutine.}
613 
614   \textcolor{keywordflow}{if} (\textcolor{keyword}{associated}(cs%geo\_heat)) \textcolor{keyword}{deallocate}(cs%geo\_heat)
615   \textcolor{keywordflow}{if} (\textcolor{keyword}{associated}(cs)) \textcolor{keyword}{deallocate}(cs)
\end{DoxyCode}
\mbox{\Hypertarget{namespacemom__geothermal_a6982c9c83861b01e9ea07ce7215c2b7a}\label{namespacemom__geothermal_a6982c9c83861b01e9ea07ce7215c2b7a}} 
\index{mom\+\_\+geothermal@{mom\+\_\+geothermal}!geothermal\+\_\+entraining@{geothermal\+\_\+entraining}}
\index{geothermal\+\_\+entraining@{geothermal\+\_\+entraining}!mom\+\_\+geothermal@{mom\+\_\+geothermal}}
\subsubsection{\texorpdfstring{geothermal\+\_\+entraining()}{geothermal\_entraining()}}
{\footnotesize\ttfamily subroutine, public mom\+\_\+geothermal\+::geothermal\+\_\+entraining (\begin{DoxyParamCaption}\item[{real, dimension(szi\+\_\+(g),szj\+\_\+(g),szk\+\_\+(g)), intent(inout)}]{h,  }\item[{type(thermo\+\_\+var\+\_\+ptrs), intent(inout)}]{tv,  }\item[{real, intent(in)}]{dt,  }\item[{real, dimension(szi\+\_\+(g),szj\+\_\+(g),szk\+\_\+(g)), intent(inout)}]{ea,  }\item[{real, dimension(szi\+\_\+(g),szj\+\_\+(g),szk\+\_\+(g)), intent(inout)}]{eb,  }\item[{type(ocean\+\_\+grid\+\_\+type), intent(inout)}]{G,  }\item[{type(verticalgrid\+\_\+type), intent(in)}]{GV,  }\item[{type(unit\+\_\+scale\+\_\+type), intent(in)}]{US,  }\item[{type(\hyperlink{structmom__geothermal_1_1geothermal__cs}{geothermal\+\_\+cs}), pointer}]{CS,  }\item[{integer, intent(in), optional}]{halo }\end{DoxyParamCaption})}



Applies geothermal heating, including the movement of water between isopycnal layers to match the target densities. The heating is applied to the bottommost layers that occur within G\+E\+O\+T\+H\+E\+R\+M\+A\+L\+\_\+\+T\+H\+I\+C\+K\+N\+E\+SS of the bottom. If the partial derivative of the coordinate density with temperature is positive or very small, the layers are simply heated in place. Any heat that can not be applied to the ocean is returned (W\+H\+E\+RE)? 


\begin{DoxyParams}[1]{Parameters}
\mbox{\tt in,out}  & {\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,out}  & {\em h} & Layer thicknesses \mbox{[}H $\sim$$>$ m or kg m-\/2\mbox{]}\\
\hline
\mbox{\tt in,out}  & {\em tv} & A structure containing pointers to any available thermodynamic fields. Absent fields have N\+U\+LL ptrs.\\
\hline
\mbox{\tt in}  & {\em dt} & Time increment \mbox{[}T $\sim$$>$ s\mbox{]}.\\
\hline
\mbox{\tt in,out}  & {\em ea} & The amount of fluid moved downward into a layer; this should be increased due to mixed layer detrainment \mbox{[}H $\sim$$>$ m or kg m-\/2\mbox{]}\\
\hline
\mbox{\tt in,out}  & {\em eb} & The amount of fluid moved upward into a layer; this should be increased due to mixed layer entrainment \mbox{[}H $\sim$$>$ m or kg m-\/2\mbox{]}.\\
\hline
\mbox{\tt in}  & {\em us} & A dimensional unit scaling type\\
\hline
 & {\em cs} & The control structure returned by a previous call to geothermal\+\_\+init.\\
\hline
\mbox{\tt in}  & {\em halo} & Halo width over which to work \\
\hline
\end{DoxyParams}


Definition at line 54 of file M\+O\+M\+\_\+geothermal.\+F90.


\begin{DoxyCode}
54   \textcolor{keywordtype}{type}(ocean\_grid\_type),                    \textcolor{keywordtype}{intent(inout)} :: g\textcolor{comment}{  !< The ocean's grid structure.}
55   \textcolor{keywordtype}{type}(verticalgrid\_type),                  \textcolor{keywordtype}{intent(in)}    :: gv\textcolor{comment}{ !< The ocean's vertical grid structure.}
56   \textcolor{keywordtype}{real}, \textcolor{keywordtype}{dimension(SZI\_(G),SZJ\_(G),SZK\_(G))}, \textcolor{keywordtype}{intent(inout)} :: h\textcolor{comment}{  !< Layer thicknesses [H ~> m or kg m-2]}
57   \textcolor{keywordtype}{type}(thermo\_var\_ptrs),                    \textcolor{keywordtype}{intent(inout)} :: tv\textcolor{comment}{ !< A structure containing pointers}
58 \textcolor{comment}{                                                                !! to any available thermodynamic}
59 \textcolor{comment}{                                                                !! fields. Absent fields have NULL}
60 \textcolor{comment}{                                                                !! ptrs.}
61   \textcolor{keywordtype}{real},                                     \textcolor{keywordtype}{intent(in)}    :: dt\textcolor{comment}{ !< Time increment [T ~> s].}
62   \textcolor{keywordtype}{real}, \textcolor{keywordtype}{dimension(SZI\_(G),SZJ\_(G),SZK\_(G))}, \textcolor{keywordtype}{intent(inout)} :: ea\textcolor{comment}{ !< The amount of fluid moved}
63 \textcolor{comment}{                                                                !! downward into a layer; this}
64 \textcolor{comment}{                                                                !! should be increased due to mixed}
65 \textcolor{comment}{                                                                !! layer detrainment [H ~> m or kg m-2]}
66   \textcolor{keywordtype}{real}, \textcolor{keywordtype}{dimension(SZI\_(G),SZJ\_(G),SZK\_(G))}, \textcolor{keywordtype}{intent(inout)} :: eb\textcolor{comment}{ !< The amount of fluid moved upward}
67 \textcolor{comment}{                                                                !! into a layer; this should be}
68 \textcolor{comment}{                                                                !! increased due to mixed layer}
69 \textcolor{comment}{                                                                !! entrainment [H ~> m or kg m-2].}
70   \textcolor{keywordtype}{type}(unit\_scale\_type),                    \textcolor{keywordtype}{intent(in)}    :: us\textcolor{comment}{ !< A dimensional unit scaling type}
71   \textcolor{keywordtype}{type}(geothermal\_cs),                      \textcolor{keywordtype}{pointer}       :: cs\textcolor{comment}{ !< The control structure returned by}
72 \textcolor{comment}{                                                                !! a previous call to}
73 \textcolor{comment}{                                                                !! geothermal\_init.}
74   \textcolor{keywordtype}{integer},                        \textcolor{keywordtype}{optional}, \textcolor{keywordtype}{intent(in)}    :: halo\textcolor{comment}{ !< Halo width over which to work}
75   \textcolor{comment}{! Local variables}
76   \textcolor{keywordtype}{real}, \textcolor{keywordtype}{dimension(SZI\_(G))} :: &
77     heat\_rem,  & \textcolor{comment}{! remaining heat [H degC ~> m degC or kg degC m-2]}
78     h\_geo\_rem, & \textcolor{comment}{! remaining thickness to apply geothermal heating [H ~> m or kg m-2]}
79     rcv\_bl,    & \textcolor{comment}{! coordinate density in the deepest variable density layer [R ~> kg m-3]}
80     p\_ref        \textcolor{comment}{! coordinate densities reference pressure [R L2 T-2 ~> Pa]}
81 
82   \textcolor{keywordtype}{real}, \textcolor{keywordtype}{dimension(2)} :: &
83     t2, s2, &   \textcolor{comment}{! temp and saln in the present and target layers [degC] and [ppt]}
84     drcv\_dt\_, & \textcolor{comment}{! partial derivative of coordinate density wrt temp [R degC-1 ~> kg m-3 degC-1]}
85     drcv\_ds\_    \textcolor{comment}{! partial derivative of coordinate density wrt saln [R ppt-1 ~> kg m-3 ppt-1]}
86 
87   \textcolor{keywordtype}{real} :: angstrom, h\_neglect  \textcolor{comment}{! small thicknesses [H ~> m or kg m-2]}
88   \textcolor{keywordtype}{real} :: rcv           \textcolor{comment}{! coordinate density of present layer [R ~> kg m-3]}
89   \textcolor{keywordtype}{real} :: rcv\_tgt       \textcolor{comment}{! coordinate density of target layer [R ~> kg m-3]}
90   \textcolor{keywordtype}{real} :: drcv          \textcolor{comment}{! difference between Rcv and Rcv\_tgt [R ~> kg m-3]}
91   \textcolor{keywordtype}{real} :: drcv\_dt       \textcolor{comment}{! partial derivative of coordinate density wrt temp}
92                         \textcolor{comment}{! in the present layer [R degC-1 ~> kg m-3 degC-1]; usually negative}
93   \textcolor{keywordtype}{real} :: h\_heated      \textcolor{comment}{! thickness that is being heated [H ~> m or kg m-2]}
94   \textcolor{keywordtype}{real} :: heat\_avail    \textcolor{comment}{! heating available for the present layer [degC H ~> degC m or degC kg m-2]}
95   \textcolor{keywordtype}{real} :: heat\_in\_place \textcolor{comment}{! heating to warm present layer w/o movement between layers}
96                         \textcolor{comment}{! [degC H ~> degC m or degC kg m-2]}
97   \textcolor{keywordtype}{real} :: heat\_trans    \textcolor{comment}{! heating available to move water from present layer to target}
98                         \textcolor{comment}{! layer [degC H ~> degC m or degC kg m-2]}
99   \textcolor{keywordtype}{real} :: heating       \textcolor{comment}{! heating used to move water from present layer to target layer}
100                         \textcolor{comment}{! [degC H ~> degC m or degC kg m-2]}
101                         \textcolor{comment}{! 0 <= heating <= heat\_trans}
102   \textcolor{keywordtype}{real} :: h\_transfer    \textcolor{comment}{! thickness moved between layers [H ~> m or kg m-2]}
103   \textcolor{keywordtype}{real} :: wt\_in\_place   \textcolor{comment}{! relative weighting that goes from 0 to 1 [nondim]}
104   \textcolor{keywordtype}{real} :: i\_h           \textcolor{comment}{! inverse thickness [H-1 ~> m-1 or m2 kg-1]}
105   \textcolor{keywordtype}{real} :: dtemp         \textcolor{comment}{! temperature increase in a layer [degC]}
106   \textcolor{keywordtype}{real} :: irho\_cp       \textcolor{comment}{! inverse of heat capacity per unit layer volume}
107                         \textcolor{comment}{! [degC H Q-1 R-1 Z-1 ~> degC m3 J-1 or degC kg J-1]}
108 
109   \textcolor{keywordtype}{real}, \textcolor{keywordtype}{dimension(SZI\_(G),SZJ\_(G),SZK\_(G))} :: t\_old   \textcolor{comment}{! Temperature of each layer}
110                                                       \textcolor{comment}{! before any heat is added,}
111                                                       \textcolor{comment}{! for diagnostics [degC]}
112   \textcolor{keywordtype}{real}, \textcolor{keywordtype}{dimension(SZI\_(G),SZJ\_(G),SZK\_(G))} :: h\_old   \textcolor{comment}{! Thickness of each layer}
113                                                       \textcolor{comment}{! before any heat is added,}
114                                                       \textcolor{comment}{! for diagnostics [H ~> m or kg m-2]}
115   \textcolor{keywordtype}{real}, \textcolor{keywordtype}{dimension(SZI\_(G),SZJ\_(G),SZK\_(G))} :: work\_3d \textcolor{comment}{! Scratch variable used to}
116                                                       \textcolor{comment}{! calculate change in heat}
117                                                       \textcolor{comment}{! due to geothermal}
118   \textcolor{keywordtype}{real} :: idt           \textcolor{comment}{! inverse of the timestep [T-1 ~> s-1]}
119 
120   \textcolor{keywordtype}{logical} :: do\_i(szi\_(g))
121   \textcolor{keywordtype}{logical} :: compute\_h\_old, compute\_t\_old
122   \textcolor{keywordtype}{integer} :: i, j, k, is, ie, js, je, nz, k2, i2
123   \textcolor{keywordtype}{integer} :: isj, iej, num\_left, nkmb, k\_tgt
124 
125   is = g%isc ; ie = g%iec ; js = g%jsc ; je = g%jec ; nz = g%ke
126   \textcolor{keywordflow}{if} (\textcolor{keyword}{present}(halo)) \textcolor{keywordflow}{then}
127     is = g%isc-halo ; ie = g%iec+halo ; js = g%jsc-halo ; je = g%jec+halo
128 \textcolor{keywordflow}{  endif}
129 
130   \textcolor{keywordflow}{if} (.not. \textcolor{keyword}{associated}(cs)) \textcolor{keyword}{call }mom\_error(fatal, \textcolor{stringliteral}{"MOM\_geothermal: "}//&
131          \textcolor{stringliteral}{"Module must be initialized before it is used."})
132   \textcolor{keywordflow}{if} (.not.cs%apply\_geothermal) \textcolor{keywordflow}{return}
133 
134   nkmb      = gv%nk\_rho\_varies
135   irho\_cp   = 1.0 / (gv%H\_to\_RZ * tv%C\_p)
136   angstrom  = gv%Angstrom\_H
137   h\_neglect = gv%H\_subroundoff
138   p\_ref(:)  = tv%P\_Ref
139   idt       = 1.0 / dt
140 
141   \textcolor{keywordflow}{if} (.not.\textcolor{keyword}{associated}(tv%T)) \textcolor{keyword}{call }mom\_error(fatal, \textcolor{stringliteral}{"MOM geothermal\_entraining: "}//&
142       \textcolor{stringliteral}{"Geothermal heating can only be applied if T & S are state variables."})
143 
144 \textcolor{comment}{!  do j=js,je ; do i=is,ie}
145 \textcolor{comment}{!    resid(i,j) = tv%internal\_heat(i,j)}
146 \textcolor{comment}{!  enddo ; enddo}
147 
148   \textcolor{comment}{! Conditionals for tracking diagnostic depdendencies}
149   compute\_h\_old = cs%id\_internal\_heat\_h\_tendency > 0 &
150                   .or. cs%id\_internal\_heat\_heat\_tendency > 0 &
151                   .or. cs%id\_internal\_heat\_temp\_tendency > 0
152 
153   compute\_t\_old = cs%id\_internal\_heat\_heat\_tendency > 0 &
154                   .or. cs%id\_internal\_heat\_temp\_tendency > 0
155 
156   \textcolor{keywordflow}{if} (cs%id\_internal\_heat\_heat\_tendency > 0) work\_3d(:,:,:) = 0.0
157 
158   \textcolor{keywordflow}{if} (compute\_h\_old .or. compute\_t\_old) \textcolor{keywordflow}{then} ; \textcolor{keywordflow}{do} k=1,nz ; \textcolor{keywordflow}{do} j=js,je ; \textcolor{keywordflow}{do} i=is,ie
159     \textcolor{comment}{! Save temperature and thickness before any changes are made (for diagnostics)}
160     h\_old(i,j,k) = h(i,j,k)
161     t\_old(i,j,k) = tv%T(i,j,k)
162 \textcolor{keywordflow}{  enddo} ;\textcolor{keywordflow}{ enddo} ;\textcolor{keywordflow}{ enddo} ;\textcolor{keywordflow}{ endif}
163 
164 \textcolor{comment}{!$OMP parallel do default(none) shared(is,ie,js,je,G,GV,US,CS,dt,Irho\_cp,nkmb,tv, &}
165 \textcolor{comment}{!$OMP                                  p\_Ref,h,Angstrom,nz,H\_neglect,eb,          &}
166 \textcolor{comment}{!$OMP                                  h\_old,T\_old,work\_3d,Idt)                   &}
167 \textcolor{comment}{!$OMP                          private(heat\_rem,do\_i,h\_geo\_rem,num\_left,          &}
168 \textcolor{comment}{!$OMP                                  isj,iej,Rcv\_BL,h\_heated,heat\_avail,k\_tgt,  &}
169 \textcolor{comment}{!$OMP                                  Rcv\_tgt,Rcv,dRcv\_dT,T2,S2,dRcv\_dT\_,        &}
170 \textcolor{comment}{!$OMP                                  dRcv\_dS\_,heat\_in\_place,heat\_trans,         &}
171 \textcolor{comment}{!$OMP                                  wt\_in\_place,dTemp,dRcv,h\_transfer,heating, &}
172 \textcolor{comment}{!$OMP                                  I\_h)}
173 
174   \textcolor{keywordflow}{do} j=js,je
175     \textcolor{comment}{! 1. Only work on columns that are being heated.}
176     \textcolor{comment}{! 2. Find the deepest layer with any mass.}
177     \textcolor{comment}{! 3. Find the partial derivative of locally referenced potential density}
178     \textcolor{comment}{!  and coordinate density with temperature, and the density of the layer}
179     \textcolor{comment}{!  and the layer above.}
180     \textcolor{comment}{! 4. Heat a portion of the bottommost layer until it matches the target}
181     \textcolor{comment}{!    density of the layer above, and move it.}
182     \textcolor{comment}{! 4a. In the case of variable density layers, heat but do not move.}
183     \textcolor{comment}{! 5. If there is still heat left over, repeat for the next layer up.}
184     \textcolor{comment}{! This subroutine updates thickness, T & S, and increments eb accordingly.}
185 
186     \textcolor{comment}{! 6. If there is not enough mass in the ocean, pass some of the heat up}
187     \textcolor{comment}{!    from the ocean via the frazil field?}
188 
189     num\_left = 0
190     \textcolor{keywordflow}{do} i=is,ie
191       heat\_rem(i) = g%mask2dT(i,j) * (cs%geo\_heat(i,j) * (dt*irho\_cp))
192       do\_i(i) = .true. ; \textcolor{keywordflow}{if} (heat\_rem(i) <= 0.0) do\_i(i) = .false.
193       \textcolor{keywordflow}{if} (do\_i(i)) num\_left = num\_left + 1
194       h\_geo\_rem(i) = cs%Geothermal\_thick
195 \textcolor{keywordflow}{    enddo}
196     \textcolor{keywordflow}{if} (num\_left == 0) cycle
197 
198     \textcolor{comment}{! Find the first and last columns that need to be worked on.}
199     isj = ie+1 ; \textcolor{keywordflow}{do} i=is,ie ; \textcolor{keywordflow}{if} (do\_i(i)) \textcolor{keywordflow}{then} ; isj = i ; \textcolor{keywordflow}{exit} ;\textcolor{keywordflow}{ endif} ;\textcolor{keywordflow}{ enddo}
200     iej = is-1 ; \textcolor{keywordflow}{do} i=ie,is,-1 ; \textcolor{keywordflow}{if} (do\_i(i)) \textcolor{keywordflow}{then} ; iej = i ; \textcolor{keywordflow}{exit} ;\textcolor{keywordflow}{ endif} ;\textcolor{keywordflow}{ enddo}
201 
202     \textcolor{keywordflow}{if} (nkmb > 0) \textcolor{keywordflow}{then}
203       \textcolor{keyword}{call }calculate\_density(tv%T(:,j,nkmb), tv%S(:,j,nkmb), p\_ref(:), rcv\_bl(:), &
204                              tv%eqn\_of\_state, (/isj-(g%isd-1),iej-(g%isd-1)/) )
205     \textcolor{keywordflow}{else}
206       rcv\_bl(:) = -1.0
207 \textcolor{keywordflow}{    endif}
208 
209     \textcolor{keywordflow}{do} k=nz,1,-1
210       \textcolor{keywordflow}{do} i=isj,iej ; \textcolor{keywordflow}{if} (do\_i(i)) \textcolor{keywordflow}{then}
211 
212         \textcolor{keywordflow}{if} (h(i,j,k) > angstrom) \textcolor{keywordflow}{then}
213           \textcolor{keywordflow}{if} ((h(i,j,k)-angstrom) >= h\_geo\_rem(i)) \textcolor{keywordflow}{then}
214             h\_heated = h\_geo\_rem(i)
215             heat\_avail = heat\_rem(i)
216             h\_geo\_rem(i) = 0.0
217           \textcolor{keywordflow}{else}
218             h\_heated = (h(i,j,k)-angstrom)
219             heat\_avail = heat\_rem(i) * (h\_heated / &
220                                         (h\_geo\_rem(i) + h\_neglect))
221             h\_geo\_rem(i) = h\_geo\_rem(i) - h\_heated
222 \textcolor{keywordflow}{          endif}
223 
224           \textcolor{keywordflow}{if} (k<=nkmb .or. nkmb<=0) \textcolor{keywordflow}{then}
225             \textcolor{comment}{! Simply heat the layer; convective adjustment occurs later}
226             \textcolor{comment}{! if necessary.}
227             k\_tgt = k
228           \textcolor{keywordflow}{elseif} ((k==nkmb+1) .or. (gv%Rlay(k-1) < rcv\_bl(i))) \textcolor{keywordflow}{then}
229             \textcolor{comment}{! Add enough heat to match the lowest buffer layer density.}
230             k\_tgt = nkmb
231             rcv\_tgt = rcv\_bl(i)
232           \textcolor{keywordflow}{else}
233             \textcolor{comment}{! Add enough heat to match the target density of layer k-1.}
234             k\_tgt = k-1
235             rcv\_tgt = gv%Rlay(k-1)
236 \textcolor{keywordflow}{          endif}
237 
238           \textcolor{keywordflow}{if} (k<=nkmb .or. nkmb<=0) \textcolor{keywordflow}{then}
239             rcv = 0.0 ; drcv\_dt = 0.0 \textcolor{comment}{! Is this OK?}
240           \textcolor{keywordflow}{else}
241             \textcolor{keyword}{call }calculate\_density(tv%T(i,j,k), tv%S(i,j,k), tv%P\_Ref, &
242                          rcv, tv%eqn\_of\_state)
243             t2(1) = tv%T(i,j,k) ; s2(1) = tv%S(i,j,k)
244             t2(2) = tv%T(i,j,k\_tgt) ; s2(2) = tv%S(i,j,k\_tgt)
245             \textcolor{keyword}{call }calculate\_density\_derivs(t2(:), s2(:), p\_ref(:), drcv\_dt\_, drcv\_ds\_, &
246                          tv%eqn\_of\_state, (/1,2/) )
247             drcv\_dt = 0.5*(drcv\_dt\_(1) + drcv\_dt\_(2))
248 \textcolor{keywordflow}{          endif}
249 
250           \textcolor{keywordflow}{if} ((drcv\_dt >= 0.0) .or. (k<=nkmb .or. nkmb<=0)) \textcolor{keywordflow}{then}
251             \textcolor{comment}{! This applies to variable density layers.}
252             heat\_in\_place = heat\_avail
253             heat\_trans = 0.0
254           \textcolor{keywordflow}{elseif} (drcv\_dt <= cs%dRcv\_dT\_inplace) \textcolor{keywordflow}{then}
255             \textcolor{comment}{! This is the option that usually applies in isopycnal coordinates.}
256             heat\_in\_place = min(heat\_avail, max(0.0, h(i,j,k) * &
257                                             ((gv%Rlay(k)-rcv) / drcv\_dt)))
258             heat\_trans = heat\_avail - heat\_in\_place
259           \textcolor{keywordflow}{else}
260             \textcolor{comment}{! wt\_in\_place should go from 0 to 1.}
261             wt\_in\_place = (cs%dRcv\_dT\_inplace - drcv\_dt) / cs%dRcv\_dT\_inplace
262             heat\_in\_place = max(wt\_in\_place*heat\_avail, &
263                                 h(i,j,k) * ((gv%Rlay(k)-rcv) / drcv\_dt) )
264             heat\_trans = heat\_avail - heat\_in\_place
265 \textcolor{keywordflow}{          endif}
266 
267           \textcolor{keywordflow}{if} (heat\_in\_place > 0.0) \textcolor{keywordflow}{then}
268             \textcolor{comment}{! This applies to variable density layers. In isopycnal coordinates}
269             \textcolor{comment}{! this only arises for relatively fresh water near the freezing}
270             \textcolor{comment}{! point, in which case heating in place will eventually cause things}
271             \textcolor{comment}{! to sort themselves out, if only because the water will warm to}
272             \textcolor{comment}{! the temperature of maximum density.}
273             dtemp = heat\_in\_place / (h(i,j,k) + h\_neglect)
274             tv%T(i,j,k) = tv%T(i,j,k) + dtemp
275             heat\_rem(i) = heat\_rem(i) - heat\_in\_place
276             rcv = rcv + drcv\_dt * dtemp
277 \textcolor{keywordflow}{          endif}
278 
279           \textcolor{keywordflow}{if} (heat\_trans > 0.0) \textcolor{keywordflow}{then}
280             \textcolor{comment}{! The second expression might never be used, but will avoid}
281             \textcolor{comment}{! division by 0.}
282             drcv = max(rcv - rcv\_tgt, 0.0)
283 
284             \textcolor{comment}{!   dTemp = -dRcv / dRcv\_dT}
285             \textcolor{comment}{!   h\_transfer = min(heat\_rem(i) / dTemp, h(i,j,k)-Angstrom)}
286             \textcolor{keywordflow}{if} ((-drcv\_dt * heat\_trans) >= drcv * (h(i,j,k)-angstrom)) \textcolor{keywordflow}{then}
287               h\_transfer = h(i,j,k) - angstrom
288               heating = (h\_transfer * drcv) / (-drcv\_dt)
289               \textcolor{comment}{! Since not all the heat has been applied, return the fraction}
290               \textcolor{comment}{! of the layer thickness that has not yet been fully heated to}
291               \textcolor{comment}{! the h\_geo\_rem.}
292               h\_geo\_rem(i) = h\_geo\_rem(i) + h\_heated * &
293                       ((heat\_avail - (heating + heat\_in\_place)) / heat\_avail)
294             \textcolor{keywordflow}{else}
295               h\_transfer = (-drcv\_dt * heat\_trans) / drcv
296               heating = heat\_trans
297 \textcolor{keywordflow}{            endif}
298             heat\_rem(i) = heat\_rem(i) - heating
299 
300             i\_h = 1.0 / ((h(i,j,k\_tgt) + h\_neglect) + h\_transfer)
301             tv%T(i,j,k\_tgt) = ((h(i,j,k\_tgt) + h\_neglect) * tv%T(i,j,k\_tgt) + &
302                                (h\_transfer * tv%T(i,j,k) + heating)) * i\_h
303             tv%S(i,j,k\_tgt) = ((h(i,j,k\_tgt) + h\_neglect) * tv%S(i,j,k\_tgt) + &
304                                h\_transfer * tv%S(i,j,k)) * i\_h
305 
306             h(i,j,k) = h(i,j,k) - h\_transfer
307             h(i,j,k\_tgt) = h(i,j,k\_tgt) + h\_transfer
308             eb(i,j,k\_tgt) = eb(i,j,k\_tgt) + h\_transfer
309             \textcolor{keywordflow}{if} (k\_tgt < k-1) \textcolor{keywordflow}{then}
310               \textcolor{keywordflow}{do} k2 = k\_tgt+1,k-1
311                 eb(i,j,k2) = eb(i,j,k2) + h\_transfer
312 \textcolor{keywordflow}{              enddo}
313 \textcolor{keywordflow}{            endif}
314 \textcolor{keywordflow}{          endif}
315 
316           \textcolor{keywordflow}{if} (heat\_rem(i) <= 0.0) \textcolor{keywordflow}{then}
317             do\_i(i) = .false. ; num\_left = num\_left-1
318             \textcolor{comment}{! For efficiency, uncomment these?}
319             \textcolor{comment}{! if ((i==isj) .and. (num\_left > 0)) then ; do i2=isj+1,iej ; if (do\_i(i2)) then}
320             \textcolor{comment}{!   isj = i2 ; exit ! Set the new starting value.}
321             \textcolor{comment}{! endif ; enddo ; endif}
322             \textcolor{comment}{! if ((i==iej) .and. (num\_left > 0)) then ; do i2=iej-1,isj,-1 ; if (do\_i(i2)) then}
323             \textcolor{comment}{!   iej = i2 ; exit ! Set the new ending value.}
324             \textcolor{comment}{! endif ; enddo ; endif}
325 \textcolor{keywordflow}{          endif}
326 \textcolor{keywordflow}{        endif}
327 
328         \textcolor{comment}{! Calculate heat tendency due to addition and transfer of internal heat}
329         \textcolor{keywordflow}{if} (cs%id\_internal\_heat\_heat\_tendency > 0) \textcolor{keywordflow}{then}
330           work\_3d(i,j,k) = ((gv%H\_to\_RZ*tv%C\_p) * idt) * (h(i,j,k) * tv%T(i,j,k) - h\_old(i,j,k) * t\_old(i,j
      ,k))
331 \textcolor{keywordflow}{        endif}
332 
333 \textcolor{keywordflow}{      endif} ;\textcolor{keywordflow}{ enddo}
334       \textcolor{keywordflow}{if} (num\_left <= 0) \textcolor{keywordflow}{exit}
335 \textcolor{keywordflow}{    enddo} \textcolor{comment}{! k-loop}
336 
337     \textcolor{keywordflow}{if} (\textcolor{keyword}{associated}(tv%internal\_heat)) \textcolor{keywordflow}{then} ; \textcolor{keywordflow}{do} i=is,ie
338       tv%internal\_heat(i,j) = tv%internal\_heat(i,j) + gv%H\_to\_RZ * &
339            (g%mask2dT(i,j) * (cs%geo\_heat(i,j) * (dt*irho\_cp)) - heat\_rem(i))
340 \textcolor{keywordflow}{    enddo} ;\textcolor{keywordflow}{ endif}
341 \textcolor{keywordflow}{  enddo} \textcolor{comment}{! j-loop}
342 
343   \textcolor{comment}{! Post diagnostic of 3D tendencies (heat, temperature, and thickness) due to internal heat}
344   \textcolor{keywordflow}{if} (cs%id\_internal\_heat\_heat\_tendency > 0) \textcolor{keywordflow}{then}
345     \textcolor{keyword}{call }post\_data(cs%id\_internal\_heat\_heat\_tendency, work\_3d, cs%diag, alt\_h=h\_old)
346 \textcolor{keywordflow}{  endif}
347   \textcolor{keywordflow}{if} (cs%id\_internal\_heat\_temp\_tendency > 0) \textcolor{keywordflow}{then}
348     \textcolor{keywordflow}{do} k=1,nz ; \textcolor{keywordflow}{do} j=js,je ; \textcolor{keywordflow}{do} i=is,ie
349       work\_3d(i,j,k) = idt * (tv%T(i,j,k) - t\_old(i,j,k))
350 \textcolor{keyword}{    end}do; enddo; enddo
351     \textcolor{keyword}{call }post\_data(cs%id\_internal\_heat\_temp\_tendency, work\_3d, cs%diag, alt\_h=h\_old)
352 \textcolor{keywordflow}{  endif}
353   \textcolor{keywordflow}{if} (cs%id\_internal\_heat\_h\_tendency > 0) \textcolor{keywordflow}{then}
354     \textcolor{keywordflow}{do} k=1,nz ; \textcolor{keywordflow}{do} j=js,je ; \textcolor{keywordflow}{do} i=is,ie
355       work\_3d(i,j,k) = idt * (h(i,j,k) - h\_old(i,j,k))
356 \textcolor{keywordflow}{    enddo} ;\textcolor{keywordflow}{ enddo} ;\textcolor{keywordflow}{ enddo}
357     \textcolor{keyword}{call }post\_data(cs%id\_internal\_heat\_h\_tendency, work\_3d, cs%diag, alt\_h=h\_old)
358 \textcolor{keywordflow}{  endif}
359 
360 \textcolor{comment}{!  do j=js,je ; do i=is,ie}
361 \textcolor{comment}{!    resid(i,j) = tv%internal\_heat(i,j) - resid(i,j) - GV%H\_to\_RZ * &}
362 \textcolor{comment}{!           (G%mask2dT(i,j) * (CS%geo\_heat(i,j) * (dt*Irho\_cp)))}
363 \textcolor{comment}{!  enddo ; enddo}
364 
\end{DoxyCode}
\mbox{\Hypertarget{namespacemom__geothermal_a7cd5e2623232156804903f100daa6e88}\label{namespacemom__geothermal_a7cd5e2623232156804903f100daa6e88}} 
\index{mom\+\_\+geothermal@{mom\+\_\+geothermal}!geothermal\+\_\+in\+\_\+place@{geothermal\+\_\+in\+\_\+place}}
\index{geothermal\+\_\+in\+\_\+place@{geothermal\+\_\+in\+\_\+place}!mom\+\_\+geothermal@{mom\+\_\+geothermal}}
\subsubsection{\texorpdfstring{geothermal\+\_\+in\+\_\+place()}{geothermal\_in\_place()}}
{\footnotesize\ttfamily subroutine, public mom\+\_\+geothermal\+::geothermal\+\_\+in\+\_\+place (\begin{DoxyParamCaption}\item[{real, dimension(szi\+\_\+(g),szj\+\_\+(g),szk\+\_\+(g)), intent(in)}]{h,  }\item[{type(thermo\+\_\+var\+\_\+ptrs), intent(inout)}]{tv,  }\item[{real, intent(in)}]{dt,  }\item[{type(ocean\+\_\+grid\+\_\+type), intent(inout)}]{G,  }\item[{type(verticalgrid\+\_\+type), intent(in)}]{GV,  }\item[{type(unit\+\_\+scale\+\_\+type), intent(in)}]{US,  }\item[{type(\hyperlink{structmom__geothermal_1_1geothermal__cs}{geothermal\+\_\+cs}), pointer}]{CS,  }\item[{integer, intent(in), optional}]{halo }\end{DoxyParamCaption})}



Applies geothermal heating to the bottommost layers that occur within G\+E\+O\+T\+H\+E\+R\+M\+A\+L\+\_\+\+T\+H\+I\+C\+K\+N\+E\+SS of the bottom, by simply heating the water in place. Any heat that can not be applied to the ocean is returned (W\+H\+E\+RE)? 


\begin{DoxyParams}[1]{Parameters}
\mbox{\tt in,out}  & {\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 h} & Layer thicknesses \mbox{[}H $\sim$$>$ m or kg m-\/2\mbox{]}\\
\hline
\mbox{\tt in,out}  & {\em tv} & A structure containing pointers to any available thermodynamic fields. Absent fields have N\+U\+LL ptrs.\\
\hline
\mbox{\tt in}  & {\em dt} & Time increment \mbox{[}T $\sim$$>$ s\mbox{]}.\\
\hline
\mbox{\tt in}  & {\em us} & A dimensional unit scaling type\\
\hline
 & {\em cs} & The control structure returned by a previous call to geothermal\+\_\+init.\\
\hline
\mbox{\tt in}  & {\em halo} & Halo width over which to work \\
\hline
\end{DoxyParams}


Definition at line 371 of file M\+O\+M\+\_\+geothermal.\+F90.


\begin{DoxyCode}
371   \textcolor{keywordtype}{type}(ocean\_grid\_type),                    \textcolor{keywordtype}{intent(inout)} :: g\textcolor{comment}{  !< The ocean's grid structure.}
372   \textcolor{keywordtype}{type}(verticalgrid\_type),                  \textcolor{keywordtype}{intent(in)}    :: gv\textcolor{comment}{ !< The ocean's vertical grid structure.}
373   \textcolor{keywordtype}{real}, \textcolor{keywordtype}{dimension(SZI\_(G),SZJ\_(G),SZK\_(G))}, \textcolor{keywordtype}{intent(in)}    :: h\textcolor{comment}{  !< Layer thicknesses [H ~> m or kg m-2]}
374   \textcolor{keywordtype}{type}(thermo\_var\_ptrs),                    \textcolor{keywordtype}{intent(inout)} :: tv\textcolor{comment}{ !< A structure containing pointers}
375 \textcolor{comment}{                                                                !! to any available thermodynamic}
376 \textcolor{comment}{                                                                !! fields. Absent fields have NULL}
377 \textcolor{comment}{                                                                !! ptrs.}
378   \textcolor{keywordtype}{real},                                     \textcolor{keywordtype}{intent(in)}    :: dt\textcolor{comment}{ !< Time increment [T ~> s].}
379   \textcolor{keywordtype}{type}(unit\_scale\_type),                    \textcolor{keywordtype}{intent(in)}    :: us\textcolor{comment}{ !< A dimensional unit scaling type}
380   \textcolor{keywordtype}{type}(geothermal\_cs),                      \textcolor{keywordtype}{pointer}       :: cs\textcolor{comment}{ !< The control structure returned by}
381 \textcolor{comment}{                                                                !! a previous call to geothermal\_init.}
382   \textcolor{keywordtype}{integer},                        \textcolor{keywordtype}{optional}, \textcolor{keywordtype}{intent(in)}    :: halo\textcolor{comment}{ !< Halo width over which to work}
383 
384   \textcolor{comment}{! Local variables}
385   \textcolor{keywordtype}{real}, \textcolor{keywordtype}{dimension(SZI\_(G))} :: &
386     heat\_rem,  & \textcolor{comment}{! remaining heat [H degC ~> m degC or kg degC m-2]}
387     h\_geo\_rem    \textcolor{comment}{! remaining thickness to apply geothermal heating [H ~> m or kg m-2]}
388 
389   \textcolor{keywordtype}{real} :: angstrom, h\_neglect  \textcolor{comment}{! small thicknesses [H ~> m or kg m-2]}
390   \textcolor{keywordtype}{real} :: heat\_here     \textcolor{comment}{! heating applied to the present layer [degC H ~> degC m or degC kg m-2]}
391   \textcolor{keywordtype}{real} :: dtemp         \textcolor{comment}{! temperature increase in a layer [degC]}
392   \textcolor{keywordtype}{real} :: irho\_cp       \textcolor{comment}{! inverse of heat capacity per unit layer volume}
393                         \textcolor{comment}{! [degC H Q-1 R-1 Z-1 ~> degC m3 J-1 or degC kg J-1]}
394 
395   \textcolor{keywordtype}{real}, \textcolor{keywordtype}{dimension(SZI\_(G),SZJ\_(G),SZK\_(G))} :: &
396     dtdt\_diag           \textcolor{comment}{! Diagnostic of temperature tendency [degC T-1 ~> degC s-1] which might be}
397                         \textcolor{comment}{! converted into a layer-integrated heat tendency [Q R Z T-1 ~> W m-2]}
398   \textcolor{keywordtype}{real} :: idt           \textcolor{comment}{! inverse of the timestep [T-1 ~> s-1]}
399   \textcolor{keywordtype}{logical} :: do\_any     \textcolor{comment}{! True if there is more to be done on the current j-row.}
400   \textcolor{keywordtype}{logical} :: calc\_diags \textcolor{comment}{! True if diagnostic tendencies are needed.}
401   \textcolor{keywordtype}{integer} :: i, j, k, is, ie, js, je, nz, i2, isj, iej
402 
403   is = g%isc ; ie = g%iec ; js = g%jsc ; je = g%jec ; nz = g%ke
404   \textcolor{keywordflow}{if} (\textcolor{keyword}{present}(halo)) \textcolor{keywordflow}{then}
405     is = g%isc-halo ; ie = g%iec+halo ; js = g%jsc-halo ; je = g%jec+halo
406 \textcolor{keywordflow}{  endif}
407 
408   \textcolor{keywordflow}{if} (.not. \textcolor{keyword}{associated}(cs)) \textcolor{keyword}{call }mom\_error(fatal, \textcolor{stringliteral}{"MOM\_geothermal: "}//&
409          \textcolor{stringliteral}{"Module must be initialized before it is used."})
410   \textcolor{keywordflow}{if} (.not.cs%apply\_geothermal) \textcolor{keywordflow}{return}
411 
412   irho\_cp   = 1.0 / (gv%H\_to\_RZ * tv%C\_p)
413   angstrom  = gv%Angstrom\_H
414   h\_neglect = gv%H\_subroundoff
415   idt       = 1.0 / dt
416 
417   \textcolor{keywordflow}{if} (.not.\textcolor{keyword}{associated}(tv%T)) \textcolor{keyword}{call }mom\_error(fatal, \textcolor{stringliteral}{"MOM geothermal\_in\_place: "}//&
418       \textcolor{stringliteral}{"Geothermal heating can only be applied if T & S are state variables."})
419 
420 \textcolor{comment}{!  do i=is,ie ; do j=js,je}
421 \textcolor{comment}{!    resid(i,j) = tv%internal\_heat(i,j)}
422 \textcolor{comment}{!  enddo ; enddo}
423 
424   \textcolor{comment}{! Conditionals for tracking diagnostic depdendencies}
425   calc\_diags = (cs%id\_internal\_heat\_heat\_tendency > 0) .or. (cs%id\_internal\_heat\_temp\_tendency > 0)
426 
427   \textcolor{keywordflow}{if} (calc\_diags) dtdt\_diag(:,:,:) = 0.0
428 
429   \textcolor{comment}{!$OMP parallel do default(shared) private(heat\_rem,do\_any,h\_geo\_rem,isj,iej,heat\_here,dTemp)}
430   \textcolor{keywordflow}{do} j=js,je
431     \textcolor{comment}{! Only work on columns that are being heated, and heat the near-bottom water.}
432 
433     \textcolor{comment}{! If there is not enough mass in the ocean, pass some of the heat up}
434     \textcolor{comment}{! from the ocean via the frazil field?}
435 
436     do\_any = .false.
437     \textcolor{keywordflow}{do} i=is,ie
438       heat\_rem(i) = g%mask2dT(i,j) * (cs%geo\_heat(i,j) * (dt*irho\_cp))
439       \textcolor{keywordflow}{if} (heat\_rem(i) > 0.0) do\_any = .true.
440       h\_geo\_rem(i) = cs%Geothermal\_thick
441 \textcolor{keywordflow}{    enddo}
442     \textcolor{keywordflow}{if} (.not.do\_any) cycle
443 
444     \textcolor{comment}{! Find the first and last columns that need to be worked on.}
445     isj = ie+1 ; \textcolor{keywordflow}{do} i=is,ie ; \textcolor{keywordflow}{if} (heat\_rem(i) > 0.0) \textcolor{keywordflow}{then} ; isj = i ; \textcolor{keywordflow}{exit} ;\textcolor{keywordflow}{ endif} ;\textcolor{keywordflow}{ enddo}
446     iej = is-1 ; \textcolor{keywordflow}{do} i=ie,is,-1 ; \textcolor{keywordflow}{if} (heat\_rem(i) > 0.0) \textcolor{keywordflow}{then} ; iej = i ; \textcolor{keywordflow}{exit} ;\textcolor{keywordflow}{ endif} ;\textcolor{keywordflow}{ enddo}
447 
448     \textcolor{keywordflow}{do} k=nz,1,-1
449       do\_any = .false.
450       \textcolor{keywordflow}{do} i=isj,iej
451         \textcolor{keywordflow}{if} ((heat\_rem(i) > 0.0) .and. (h(i,j,k) > angstrom)) \textcolor{keywordflow}{then}
452           \textcolor{comment}{! Apply some or all of the remaining heat to this layer.}
453           \textcolor{comment}{! Convective adjustment occurs outside of this module if necessary.}
454           \textcolor{keywordflow}{if} ((h(i,j,k)-angstrom) >= h\_geo\_rem(i)) \textcolor{keywordflow}{then}
455             heat\_here = heat\_rem(i)
456             h\_geo\_rem(i) = 0.0
457             heat\_rem(i) = 0.0
458           \textcolor{keywordflow}{else}
459             heat\_here = heat\_rem(i) * ((h(i,j,k)-angstrom) / (h\_geo\_rem(i) + h\_neglect))
460             h\_geo\_rem(i) = h\_geo\_rem(i) - (h(i,j,k)-angstrom)
461             heat\_rem(i) = heat\_rem(i) - heat\_here
462 \textcolor{keywordflow}{          endif}
463 
464           dtemp = heat\_here / (h(i,j,k) + h\_neglect)
465           tv%T(i,j,k) = tv%T(i,j,k) + dtemp
466           \textcolor{keywordflow}{if} (calc\_diags) dtdt\_diag(i,j,k) = dtemp * idt
467 \textcolor{keywordflow}{        endif}
468 
469         \textcolor{keywordflow}{if} (heat\_rem(i) > 0.0) do\_any= .true.
470 \textcolor{keywordflow}{      enddo}
471 
472       \textcolor{keywordflow}{if} (.not.do\_any) \textcolor{keywordflow}{exit}
473 \textcolor{keywordflow}{    enddo} \textcolor{comment}{! k-loop}
474 
475     \textcolor{keywordflow}{if} (\textcolor{keyword}{associated}(tv%internal\_heat)) \textcolor{keywordflow}{then} ; \textcolor{keywordflow}{do} i=is,ie
476       tv%internal\_heat(i,j) = tv%internal\_heat(i,j) + gv%H\_to\_RZ * &
477            (g%mask2dT(i,j) * (cs%geo\_heat(i,j) * (dt*irho\_cp)) - heat\_rem(i))
478 \textcolor{keywordflow}{    enddo} ;\textcolor{keywordflow}{ endif}
479 \textcolor{keywordflow}{  enddo} \textcolor{comment}{! j-loop}
480 
481   \textcolor{comment}{! Post diagnostics of 3D tendencies of heat and temperature due to geothermal heat}
482   \textcolor{keywordflow}{if} (cs%id\_internal\_heat\_temp\_tendency > 0) \textcolor{keywordflow}{then}
483     \textcolor{keyword}{call }post\_data(cs%id\_internal\_heat\_temp\_tendency, dtdt\_diag, cs%diag, alt\_h=h)
484 \textcolor{keywordflow}{  endif}
485   \textcolor{keywordflow}{if} (cs%id\_internal\_heat\_heat\_tendency > 0) \textcolor{keywordflow}{then}
486     \textcolor{keywordflow}{do} k=1,nz ; \textcolor{keywordflow}{do} j=js,je ; \textcolor{keywordflow}{do} i=is,ie
487       \textcolor{comment}{! Dangerously reuse dTdt\_diag for a related variable with different units, going from}
488       \textcolor{comment}{! units of [degC T-1 ~> degC s-1] to units of [Q R Z T-1 ~> W m-2]}
489       dtdt\_diag(i,j,k) = (gv%H\_to\_RZ*tv%C\_p) * (h(i,j,k) * dtdt\_diag(i,j,k))
490 \textcolor{keywordflow}{    enddo} ;\textcolor{keywordflow}{ enddo} ;\textcolor{keywordflow}{ enddo}
491     \textcolor{keyword}{call }post\_data(cs%id\_internal\_heat\_heat\_tendency, dtdt\_diag, cs%diag, alt\_h=h)
492 \textcolor{keywordflow}{  endif}
493 
494 \textcolor{comment}{!  do j=js,je ; do i=is,ie}
495 \textcolor{comment}{!    resid(i,j) = tv%internal\_heat(i,j) - resid(i,j) - GV%H\_to\_RZ * &}
496 \textcolor{comment}{!           (G%mask2dT(i,j) * (CS%geo\_heat(i,j) * (dt*Irho\_cp)))}
497 \textcolor{comment}{!  enddo ; enddo}
498 
\end{DoxyCode}
\mbox{\Hypertarget{namespacemom__geothermal_a1b764e98a70404c9a13909f01068389c}\label{namespacemom__geothermal_a1b764e98a70404c9a13909f01068389c}} 
\index{mom\+\_\+geothermal@{mom\+\_\+geothermal}!geothermal\+\_\+init@{geothermal\+\_\+init}}
\index{geothermal\+\_\+init@{geothermal\+\_\+init}!mom\+\_\+geothermal@{mom\+\_\+geothermal}}
\subsubsection{\texorpdfstring{geothermal\+\_\+init()}{geothermal\_init()}}
{\footnotesize\ttfamily subroutine, public mom\+\_\+geothermal\+::geothermal\+\_\+init (\begin{DoxyParamCaption}\item[{type(time\+\_\+type), intent(in), target}]{Time,  }\item[{type(ocean\+\_\+grid\+\_\+type), intent(inout)}]{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__geothermal_1_1geothermal__cs}{geothermal\+\_\+cs}), pointer}]{CS,  }\item[{logical, intent(in), optional}]{use\+A\+L\+Ealgorithm }\end{DoxyParamCaption})}



Initialize parameters and allocate memory associated with the geothermal heating module. 


\begin{DoxyParams}[1]{Parameters}
\mbox{\tt in}  & {\em time} & Current model time.\\
\hline
\mbox{\tt in,out}  & {\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 param\+\_\+file} & A structure to parse for run-\/time parameters.\\
\hline
\mbox{\tt in,out}  & {\em diag} & Structure used to regulate diagnostic output.\\
\hline
 & {\em cs} & Pointer pointing to the module control structure.\\
\hline
\mbox{\tt in}  & {\em usealealgorithm} & logical for whether to use A\+LE remapping \\
\hline
\end{DoxyParams}


Definition at line 503 of file M\+O\+M\+\_\+geothermal.\+F90.


\begin{DoxyCode}
503   \textcolor{keywordtype}{type}(time\_type), \textcolor{keywordtype}{target}, \textcolor{keywordtype}{intent(in)}    :: time\textcolor{comment}{ !< Current model time.}
504   \textcolor{keywordtype}{type}(ocean\_grid\_type),   \textcolor{keywordtype}{intent(inout)} :: g\textcolor{comment}{    !< The ocean's grid structure.}
505   \textcolor{keywordtype}{type}(verticalgrid\_type), \textcolor{keywordtype}{intent(in)}    :: gv\textcolor{comment}{   !< The ocean's vertical grid structure.}
506   \textcolor{keywordtype}{type}(unit\_scale\_type),   \textcolor{keywordtype}{intent(in)}    :: us\textcolor{comment}{   !< A dimensional unit scaling type}
507   \textcolor{keywordtype}{type}(param\_file\_type),   \textcolor{keywordtype}{intent(in)}    :: param\_file\textcolor{comment}{ !< A structure to parse for run-time}
508 \textcolor{comment}{                                                 !! parameters.}
509   \textcolor{keywordtype}{type}(diag\_ctrl), \textcolor{keywordtype}{target}, \textcolor{keywordtype}{intent(inout)} :: diag\textcolor{comment}{ !< Structure used to regulate diagnostic output.}
510   \textcolor{keywordtype}{type}(geothermal\_cs),     \textcolor{keywordtype}{pointer}       :: cs\textcolor{comment}{   !< Pointer pointing to the module control}
511 \textcolor{comment}{                                                 !! structure.}
512   \textcolor{keywordtype}{logical},       \textcolor{keywordtype}{optional}, \textcolor{keywordtype}{intent(in)}    :: usealealgorithm\textcolor{comment}{  !< logical for whether to use ALE remapping}
513 
514 \textcolor{comment}{! This include declares and sets the variable "version".}
515 \textcolor{preprocessor}{#include "version\_variable.h"}
516 \textcolor{preprocessor}{}  \textcolor{keywordtype}{character(len=40)}  :: mdl = \textcolor{stringliteral}{"MOM\_geothermal"}  \textcolor{comment}{! module name}
517   \textcolor{keywordtype}{character(len=48)}  :: thickness\_units
518   \textcolor{comment}{! Local variables}
519   \textcolor{keywordtype}{character(len=200)} :: inputdir, geo\_file, filename, geotherm\_var
520   \textcolor{keywordtype}{real} :: geo\_scale  \textcolor{comment}{! A constant heat flux or dimensionally rescaled geothermal flux scaling factor}
521                      \textcolor{comment}{! [Q R Z T-1 ~> W m-2] or [Q R Z m2 s J-1 T-1 ~> 1]}
522   \textcolor{keywordtype}{integer} :: i, j, isd, ied, jsd, jed, id
523   isd = g%isd ; ied = g%ied ; jsd = g%jsd ; jed = g%jed
524 
525   \textcolor{keywordflow}{if} (\textcolor{keyword}{associated}(cs)) \textcolor{keywordflow}{then}
526     \textcolor{keyword}{call }mom\_error(warning, \textcolor{stringliteral}{"geothermal\_init called with an associated"}// &
527                             \textcolor{stringliteral}{"associated control structure."})
528     \textcolor{keywordflow}{return}
529   \textcolor{keywordflow}{else} ; \textcolor{keyword}{allocate}(cs) ;\textcolor{keywordflow}{ endif}
530 
531   cs%diag => diag
532   cs%Time => time
533 
534   \textcolor{comment}{! write parameters to the model log.}
535   \textcolor{keyword}{call }log\_version(param\_file, mdl, version, \textcolor{stringliteral}{""})
536   \textcolor{keyword}{call }get\_param(param\_file, mdl, \textcolor{stringliteral}{"GEOTHERMAL\_SCALE"}, geo\_scale, &
537                  \textcolor{stringliteral}{"The constant geothermal heat flux, a rescaling "}//&
538                  \textcolor{stringliteral}{"factor for the heat flux read from GEOTHERMAL\_FILE, or "}//&
539                  \textcolor{stringliteral}{"0 to disable the geothermal heating."}, &
540                  units=\textcolor{stringliteral}{"W m-2 or various"}, default=0.0, scale=us%W\_m2\_to\_QRZ\_T)
541   cs%apply\_geothermal = .not.(geo\_scale == 0.0)
542   \textcolor{keywordflow}{if} (.not.cs%apply\_geothermal) \textcolor{keywordflow}{return}
543 
544   \textcolor{keyword}{call }safe\_alloc\_ptr(cs%geo\_heat, isd, ied, jsd, jed) ; cs%geo\_heat(:,:) = 0.0
545 
546   \textcolor{keyword}{call }get\_param(param\_file, mdl, \textcolor{stringliteral}{"GEOTHERMAL\_FILE"}, geo\_file, &
547                  \textcolor{stringliteral}{"The file from which the geothermal heating is to be "}//&
548                  \textcolor{stringliteral}{"read, or blank to use a constant heating rate."}, default=\textcolor{stringliteral}{" "})
549   \textcolor{keyword}{call }get\_param(param\_file, mdl, \textcolor{stringliteral}{"GEOTHERMAL\_THICKNESS"}, cs%geothermal\_thick, &
550                  \textcolor{stringliteral}{"The thickness over which to apply geothermal heating."}, &
551                  units=\textcolor{stringliteral}{"m"}, default=0.1, scale=gv%m\_to\_H)
552   \textcolor{keyword}{call }get\_param(param\_file, mdl, \textcolor{stringliteral}{"GEOTHERMAL\_DRHO\_DT\_INPLACE"}, cs%dRcv\_dT\_inplace, &
553                  \textcolor{stringliteral}{"The value of drho\_dT above which geothermal heating "}//&
554                  \textcolor{stringliteral}{"simply heats water in place instead of moving it between "}//&
555                  \textcolor{stringliteral}{"isopycnal layers.  This must be negative."}, &
556                  units=\textcolor{stringliteral}{"kg m-3 K-1"}, scale=us%kg\_m3\_to\_R, default=-0.01)
557   \textcolor{keywordflow}{if} (cs%dRcv\_dT\_inplace >= 0.0) \textcolor{keyword}{call }mom\_error(fatal, \textcolor{stringliteral}{"geothermal\_init: "}//&
558          \textcolor{stringliteral}{"GEOTHERMAL\_DRHO\_DT\_INPLACE must be negative."})
559 
560   \textcolor{keywordflow}{if} (len\_trim(geo\_file) >= 1) \textcolor{keywordflow}{then}
561     \textcolor{keyword}{call }get\_param(param\_file, mdl, \textcolor{stringliteral}{"INPUTDIR"}, inputdir, default=\textcolor{stringliteral}{"."})
562     inputdir = slasher(inputdir)
563     filename = trim(inputdir)//trim(geo\_file)
564     \textcolor{keyword}{call }log\_param(param\_file, mdl, \textcolor{stringliteral}{"INPUTDIR/GEOTHERMAL\_FILE"}, filename)
565     \textcolor{keyword}{call }get\_param(param\_file, mdl, \textcolor{stringliteral}{"GEOTHERMAL\_VARNAME"}, geotherm\_var, &
566                  \textcolor{stringliteral}{"The name of the geothermal heating variable in "}//&
567                  \textcolor{stringliteral}{"GEOTHERMAL\_FILE."}, default=\textcolor{stringliteral}{"geo\_heat"})
568     \textcolor{keyword}{call }mom\_read\_data(filename, trim(geotherm\_var), cs%geo\_heat, g%Domain)
569     \textcolor{keywordflow}{do} j=jsd,jed ; \textcolor{keywordflow}{do} i=isd,ied
570       cs%geo\_heat(i,j) = (g%mask2dT(i,j) * geo\_scale) * cs%geo\_heat(i,j)
571 \textcolor{keywordflow}{    enddo} ;\textcolor{keywordflow}{ enddo}
572   \textcolor{keywordflow}{else}
573     \textcolor{keywordflow}{do} j=jsd,jed ; \textcolor{keywordflow}{do} i=isd,ied
574       cs%geo\_heat(i,j) = g%mask2dT(i,j) * geo\_scale
575 \textcolor{keywordflow}{    enddo} ;\textcolor{keywordflow}{ enddo}
576 \textcolor{keywordflow}{  endif}
577   \textcolor{keyword}{call }pass\_var(cs%geo\_heat, g%domain)
578 
579   thickness\_units = get\_thickness\_units(gv)
580 
581   \textcolor{comment}{! post the static geothermal heating field}
582   id = register\_static\_field(\textcolor{stringliteral}{'ocean\_model'}, \textcolor{stringliteral}{'geo\_heat'}, diag%axesT1,   &
583         \textcolor{stringliteral}{'Geothermal heat flux into ocean'}, \textcolor{stringliteral}{'W m-2'}, conversion=us%QRZ\_T\_to\_W\_m2, &
584         cmor\_field\_name=\textcolor{stringliteral}{'hfgeou'}, cmor\_units=\textcolor{stringliteral}{'W m-2'},                  &
585         cmor\_standard\_name=\textcolor{stringliteral}{'upward\_geothermal\_heat\_flux\_at\_sea\_floor'}, &
586         cmor\_long\_name=\textcolor{stringliteral}{'Upward geothermal heat flux at sea floor'}, &
587         x\_cell\_method=\textcolor{stringliteral}{'mean'}, y\_cell\_method=\textcolor{stringliteral}{'mean'}, area\_cell\_method=\textcolor{stringliteral}{'mean'})
588   \textcolor{keywordflow}{if} (id > 0) \textcolor{keyword}{call }post\_data(id, cs%geo\_heat, diag, .true.)
589 
590   \textcolor{comment}{! Diagnostic for tendencies due to internal heat (in 3d)}
591   cs%id\_internal\_heat\_heat\_tendency=register\_diag\_field(\textcolor{stringliteral}{'ocean\_model'}, &
592         \textcolor{stringliteral}{'internal\_heat\_heat\_tendency'}, diag%axesTL, time,              &
593         \textcolor{stringliteral}{'Heat tendency (in 3D) due to internal (geothermal) sources'},  &
594         \textcolor{stringliteral}{'W m-2'}, conversion=us%QRZ\_T\_to\_W\_m2, v\_extensive=.true.)
595   cs%id\_internal\_heat\_temp\_tendency=register\_diag\_field(\textcolor{stringliteral}{'ocean\_model'}, &
596         \textcolor{stringliteral}{'internal\_heat\_temp\_tendency'}, diag%axesTL, time,              &
597         \textcolor{stringliteral}{'Temperature tendency (in 3D) due to internal (geothermal) sources'}, &
598         \textcolor{stringliteral}{'degC s-1'}, conversion=us%s\_to\_T, v\_extensive=.true.)
599   \textcolor{keywordflow}{if} (\textcolor{keyword}{present}(usealealgorithm)) \textcolor{keywordflow}{then} ; \textcolor{keywordflow}{if} (.not.usealealgorithm) \textcolor{keywordflow}{then}
600     \textcolor{comment}{! Do not offer this diagnostic if heating will be in place.}
601     cs%id\_internal\_heat\_h\_tendency=register\_diag\_field(\textcolor{stringliteral}{'ocean\_model'},    &
602         \textcolor{stringliteral}{'internal\_heat\_h\_tendency'}, diag%axesTL, time,                &
603         \textcolor{stringliteral}{'Thickness tendency (in 3D) due to internal (geothermal) sources'}, &
604         trim(thickness\_units), conversion=gv%H\_to\_MKS*us%s\_to\_T, v\_extensive=.true.)
605 \textcolor{keywordflow}{  endif} ;\textcolor{keywordflow}{ endif}
606 
\end{DoxyCode}
