\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 \mbox{\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 \mbox{\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 \mbox{\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 \mbox{\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 \mbox{\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(\mbox{\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}{0}
\DoxyCodeLine{611   \textcolor{keywordtype}{type}(geothermal\_CS), \textcolor{keywordtype}{pointer} :: CS\textcolor{comment}{ !< Geothermal heating control structure that}}
\DoxyCodeLine{612 \textcolor{comment}{                                     !! will be deallocated in this subroutine.}}
\DoxyCodeLine{613 }
\DoxyCodeLine{614   \textcolor{keywordflow}{if} (\textcolor{keyword}{associated}(cs\%geo\_heat)) \textcolor{keyword}{deallocate}(cs\%geo\_heat)}
\DoxyCodeLine{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(\mbox{\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{\texttt{ in,out}}  & {\em g} & The ocean\textquotesingle{}s grid structure. \\
\hline
\mbox{\texttt{ in}}  & {\em gv} & The ocean\textquotesingle{}s vertical grid structure. \\
\hline
\mbox{\texttt{ in,out}}  & {\em h} & Layer thicknesses \mbox{[}H $\sim$$>$ m or kg m-\/2\mbox{]} \\
\hline
\mbox{\texttt{ in,out}}  & {\em tv} & A structure containing pointers to any available thermodynamic fields. Absent fields have N\+U\+LL ptrs. \\
\hline
\mbox{\texttt{ in}}  & {\em dt} & Time increment \mbox{[}T $\sim$$>$ s\mbox{]}. \\
\hline
\mbox{\texttt{ 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{\texttt{ 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{\texttt{ in}}  & {\em us} & A dimensional unit scaling type \\
\hline
 & {\em cs} & The control structure returned by a previous call to geothermal\+\_\+init. \\
\hline
\mbox{\texttt{ 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}{0}
\DoxyCodeLine{54   \textcolor{keywordtype}{type}(ocean\_grid\_type),                    \textcolor{keywordtype}{intent(inout)} :: G\textcolor{comment}{  !< The ocean's grid structure.}}
\DoxyCodeLine{55   \textcolor{keywordtype}{type}(verticalGrid\_type),                  \textcolor{keywordtype}{intent(in)}    :: GV\textcolor{comment}{ !< The ocean's vertical grid structure.}}
\DoxyCodeLine{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]}}
\DoxyCodeLine{57   \textcolor{keywordtype}{type}(thermo\_var\_ptrs),                    \textcolor{keywordtype}{intent(inout)} :: tv\textcolor{comment}{ !< A structure containing pointers}}
\DoxyCodeLine{58 \textcolor{comment}{                                                                !! to any available thermodynamic}}
\DoxyCodeLine{59 \textcolor{comment}{                                                                !! fields. Absent fields have NULL}}
\DoxyCodeLine{60 \textcolor{comment}{                                                                !! ptrs.}}
\DoxyCodeLine{61 \textcolor{keywordtype}{  real},                                     \textcolor{keywordtype}{intent(in)}    :: dt\textcolor{comment}{ !< Time increment [T ~> s].}}
\DoxyCodeLine{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}}
\DoxyCodeLine{63 \textcolor{comment}{                                                                !! downward into a layer; this}}
\DoxyCodeLine{64 \textcolor{comment}{                                                                !! should be increased due to mixed}}
\DoxyCodeLine{65 \textcolor{comment}{                                                                !! layer detrainment [H ~> m or kg m-2]}}
\DoxyCodeLine{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}}
\DoxyCodeLine{67 \textcolor{comment}{                                                                !! into a layer; this should be}}
\DoxyCodeLine{68 \textcolor{comment}{                                                                !! increased due to mixed layer}}
\DoxyCodeLine{69 \textcolor{comment}{                                                                !! entrainment [H ~> m or kg m-2].}}
\DoxyCodeLine{70   \textcolor{keywordtype}{type}(unit\_scale\_type),                    \textcolor{keywordtype}{intent(in)}    :: US\textcolor{comment}{ !< A dimensional unit scaling type}}
\DoxyCodeLine{71   \textcolor{keywordtype}{type}(geothermal\_CS),                      \textcolor{keywordtype}{pointer}       :: CS\textcolor{comment}{ !< The control structure returned by}}
\DoxyCodeLine{72 \textcolor{comment}{                                                                !! a previous call to}}
\DoxyCodeLine{73 \textcolor{comment}{                                                                !! geothermal\_init.}}
\DoxyCodeLine{74   \textcolor{keywordtype}{integer},                        \textcolor{keywordtype}{optional}, \textcolor{keywordtype}{intent(in)}    :: halo\textcolor{comment}{ !< Halo width over which to work}}
\DoxyCodeLine{75   \textcolor{comment}{! Local variables}}
\DoxyCodeLine{76 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(SZI\_(G))} :: \&}
\DoxyCodeLine{77     heat\_rem,  \& \textcolor{comment}{! remaining heat [H degC ~> m degC or kg degC m-2]}}
\DoxyCodeLine{78     h\_geo\_rem, \& \textcolor{comment}{! remaining thickness to apply geothermal heating [H ~> m or kg m-2]}}
\DoxyCodeLine{79     Rcv\_BL,    \& \textcolor{comment}{! coordinate density in the deepest variable density layer [R ~> kg m-3]}}
\DoxyCodeLine{80     p\_ref        \textcolor{comment}{! coordinate densities reference pressure [R L2 T-2 ~> Pa]}}
\DoxyCodeLine{81 }
\DoxyCodeLine{82 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(2)} :: \&}
\DoxyCodeLine{83     T2, S2, \&   \textcolor{comment}{! temp and saln in the present and target layers [degC] and [ppt]}}
\DoxyCodeLine{84     dRcv\_dT\_, \& \textcolor{comment}{! partial derivative of coordinate density wrt temp [R degC-1 ~> kg m-3 degC-1]}}
\DoxyCodeLine{85     dRcv\_dS\_    \textcolor{comment}{! partial derivative of coordinate density wrt saln [R ppt-1 ~> kg m-3 ppt-1]}}
\DoxyCodeLine{86 }
\DoxyCodeLine{87 \textcolor{keywordtype}{  real} :: Angstrom, H\_neglect  \textcolor{comment}{! small thicknesses [H ~> m or kg m-2]}}
\DoxyCodeLine{88 \textcolor{keywordtype}{  real} :: Rcv           \textcolor{comment}{! coordinate density of present layer [R ~> kg m-3]}}
\DoxyCodeLine{89 \textcolor{keywordtype}{  real} :: Rcv\_tgt       \textcolor{comment}{! coordinate density of target layer [R ~> kg m-3]}}
\DoxyCodeLine{90 \textcolor{keywordtype}{  real} :: dRcv          \textcolor{comment}{! difference between Rcv and Rcv\_tgt [R ~> kg m-3]}}
\DoxyCodeLine{91 \textcolor{keywordtype}{  real} :: dRcv\_dT       \textcolor{comment}{! partial derivative of coordinate density wrt temp}}
\DoxyCodeLine{92                         \textcolor{comment}{! in the present layer [R degC-1 ~> kg m-3 degC-1]; usually negative}}
\DoxyCodeLine{93 \textcolor{keywordtype}{  real} :: h\_heated      \textcolor{comment}{! thickness that is being heated [H ~> m or kg m-2]}}
\DoxyCodeLine{94 \textcolor{keywordtype}{  real} :: heat\_avail    \textcolor{comment}{! heating available for the present layer [degC H ~> degC m or degC kg m-2]}}
\DoxyCodeLine{95 \textcolor{keywordtype}{  real} :: heat\_in\_place \textcolor{comment}{! heating to warm present layer w/o movement between layers}}
\DoxyCodeLine{96                         \textcolor{comment}{! [degC H ~> degC m or degC kg m-2]}}
\DoxyCodeLine{97 \textcolor{keywordtype}{  real} :: heat\_trans    \textcolor{comment}{! heating available to move water from present layer to target}}
\DoxyCodeLine{98                         \textcolor{comment}{! layer [degC H ~> degC m or degC kg m-2]}}
\DoxyCodeLine{99 \textcolor{keywordtype}{  real} :: heating       \textcolor{comment}{! heating used to move water from present layer to target layer}}
\DoxyCodeLine{100                         \textcolor{comment}{! [degC H ~> degC m or degC kg m-2]}}
\DoxyCodeLine{101                         \textcolor{comment}{! 0 <= heating <= heat\_trans}}
\DoxyCodeLine{102 \textcolor{keywordtype}{  real} :: h\_transfer    \textcolor{comment}{! thickness moved between layers [H ~> m or kg m-2]}}
\DoxyCodeLine{103 \textcolor{keywordtype}{  real} :: wt\_in\_place   \textcolor{comment}{! relative weighting that goes from 0 to 1 [nondim]}}
\DoxyCodeLine{104 \textcolor{keywordtype}{  real} :: I\_h           \textcolor{comment}{! inverse thickness [H-1 ~> m-1 or m2 kg-1]}}
\DoxyCodeLine{105 \textcolor{keywordtype}{  real} :: dTemp         \textcolor{comment}{! temperature increase in a layer [degC]}}
\DoxyCodeLine{106 \textcolor{keywordtype}{  real} :: Irho\_cp       \textcolor{comment}{! inverse of heat capacity per unit layer volume}}
\DoxyCodeLine{107                         \textcolor{comment}{! [degC H Q-1 R-1 Z-1 ~> degC m3 J-1 or degC kg J-1]}}
\DoxyCodeLine{108 }
\DoxyCodeLine{109 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(SZI\_(G),SZJ\_(G),SZK\_(G))} :: T\_old   \textcolor{comment}{! Temperature of each layer}}
\DoxyCodeLine{110                                                       \textcolor{comment}{! before any heat is added,}}
\DoxyCodeLine{111                                                       \textcolor{comment}{! for diagnostics [degC]}}
\DoxyCodeLine{112 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(SZI\_(G),SZJ\_(G),SZK\_(G))} :: h\_old   \textcolor{comment}{! Thickness of each layer}}
\DoxyCodeLine{113                                                       \textcolor{comment}{! before any heat is added,}}
\DoxyCodeLine{114                                                       \textcolor{comment}{! for diagnostics [H ~> m or kg m-2]}}
\DoxyCodeLine{115 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(SZI\_(G),SZJ\_(G),SZK\_(G))} :: work\_3d \textcolor{comment}{! Scratch variable used to}}
\DoxyCodeLine{116                                                       \textcolor{comment}{! calculate change in heat}}
\DoxyCodeLine{117                                                       \textcolor{comment}{! due to geothermal}}
\DoxyCodeLine{118 \textcolor{keywordtype}{  real} :: Idt           \textcolor{comment}{! inverse of the timestep [T-1 ~> s-1]}}
\DoxyCodeLine{119 }
\DoxyCodeLine{120   \textcolor{keywordtype}{logical} :: do\_i(SZI\_(G))}
\DoxyCodeLine{121   \textcolor{keywordtype}{logical} :: compute\_h\_old, compute\_T\_old}
\DoxyCodeLine{122   \textcolor{keywordtype}{integer} :: i, j, k, is, ie, js, je, nz, k2, i2}
\DoxyCodeLine{123   \textcolor{keywordtype}{integer} :: isj, iej, num\_left, nkmb, k\_tgt}
\DoxyCodeLine{124 }
\DoxyCodeLine{125   is = g\%isc ; ie = g\%iec ; js = g\%jsc ; je = g\%jec ; nz = g\%ke}
\DoxyCodeLine{126   \textcolor{keywordflow}{if} (\textcolor{keyword}{present}(halo)) \textcolor{keywordflow}{then}}
\DoxyCodeLine{127     is = g\%isc-halo ; ie = g\%iec+halo ; js = g\%jsc-halo ; je = g\%jec+halo}
\DoxyCodeLine{128 \textcolor{keywordflow}{  endif}}
\DoxyCodeLine{129 }
\DoxyCodeLine{130   \textcolor{keywordflow}{if} (.not. \textcolor{keyword}{associated}(cs)) \textcolor{keyword}{call }mom\_error(fatal, \textcolor{stringliteral}{"MOM\_geothermal: "}//\&}
\DoxyCodeLine{131          \textcolor{stringliteral}{"Module must be initialized before it is used."})}
\DoxyCodeLine{132   \textcolor{keywordflow}{if} (.not.cs\%apply\_geothermal) \textcolor{keywordflow}{return}}
\DoxyCodeLine{133 }
\DoxyCodeLine{134   nkmb      = gv\%nk\_rho\_varies}
\DoxyCodeLine{135   irho\_cp   = 1.0 / (gv\%H\_to\_RZ * tv\%C\_p)}
\DoxyCodeLine{136   angstrom  = gv\%Angstrom\_H}
\DoxyCodeLine{137   h\_neglect = gv\%H\_subroundoff}
\DoxyCodeLine{138   p\_ref(:)  = tv\%P\_Ref}
\DoxyCodeLine{139   idt       = 1.0 / dt}
\DoxyCodeLine{140 }
\DoxyCodeLine{141   \textcolor{keywordflow}{if} (.not.\textcolor{keyword}{associated}(tv\%T)) \textcolor{keyword}{call }mom\_error(fatal, \textcolor{stringliteral}{"MOM geothermal\_entraining: "}//\&}
\DoxyCodeLine{142       \textcolor{stringliteral}{"Geothermal heating can only be applied if T \& S are state variables."})}
\DoxyCodeLine{143 }
\DoxyCodeLine{144 \textcolor{comment}{!  do j=js,je ; do i=is,ie}}
\DoxyCodeLine{145 \textcolor{comment}{!    resid(i,j) = tv\%internal\_heat(i,j)}}
\DoxyCodeLine{146 \textcolor{comment}{!  enddo ; enddo}}
\DoxyCodeLine{147 }
\DoxyCodeLine{148   \textcolor{comment}{! Conditionals for tracking diagnostic depdendencies}}
\DoxyCodeLine{149   compute\_h\_old = cs\%id\_internal\_heat\_h\_tendency > 0 \&}
\DoxyCodeLine{150                   .or. cs\%id\_internal\_heat\_heat\_tendency > 0 \&}
\DoxyCodeLine{151                   .or. cs\%id\_internal\_heat\_temp\_tendency > 0}
\DoxyCodeLine{152 }
\DoxyCodeLine{153   compute\_t\_old = cs\%id\_internal\_heat\_heat\_tendency > 0 \&}
\DoxyCodeLine{154                   .or. cs\%id\_internal\_heat\_temp\_tendency > 0}
\DoxyCodeLine{155 }
\DoxyCodeLine{156   \textcolor{keywordflow}{if} (cs\%id\_internal\_heat\_heat\_tendency > 0) work\_3d(:,:,:) = 0.0}
\DoxyCodeLine{157 }
\DoxyCodeLine{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}
\DoxyCodeLine{159     \textcolor{comment}{! Save temperature and thickness before any changes are made (for diagnostics)}}
\DoxyCodeLine{160     h\_old(i,j,k) = h(i,j,k)}
\DoxyCodeLine{161     t\_old(i,j,k) = tv\%T(i,j,k)}
\DoxyCodeLine{162 \textcolor{keywordflow}{  enddo} ;\textcolor{keywordflow}{ enddo} ;\textcolor{keywordflow}{ enddo} ;\textcolor{keywordflow}{ endif}}
\DoxyCodeLine{163 }
\DoxyCodeLine{164 \textcolor{comment}{!\$OMP parallel do default(none) shared(is,ie,js,je,G,GV,US,CS,dt,Irho\_cp,nkmb,tv, \&}}
\DoxyCodeLine{165 \textcolor{comment}{!\$OMP                                  p\_Ref,h,Angstrom,nz,H\_neglect,eb,          \&}}
\DoxyCodeLine{166 \textcolor{comment}{!\$OMP                                  h\_old,T\_old,work\_3d,Idt)                   \&}}
\DoxyCodeLine{167 \textcolor{comment}{!\$OMP                          private(heat\_rem,do\_i,h\_geo\_rem,num\_left,          \&}}
\DoxyCodeLine{168 \textcolor{comment}{!\$OMP                                  isj,iej,Rcv\_BL,h\_heated,heat\_avail,k\_tgt,  \&}}
\DoxyCodeLine{169 \textcolor{comment}{!\$OMP                                  Rcv\_tgt,Rcv,dRcv\_dT,T2,S2,dRcv\_dT\_,        \&}}
\DoxyCodeLine{170 \textcolor{comment}{!\$OMP                                  dRcv\_dS\_,heat\_in\_place,heat\_trans,         \&}}
\DoxyCodeLine{171 \textcolor{comment}{!\$OMP                                  wt\_in\_place,dTemp,dRcv,h\_transfer,heating, \&}}
\DoxyCodeLine{172 \textcolor{comment}{!\$OMP                                  I\_h)}}
\DoxyCodeLine{173 }
\DoxyCodeLine{174   \textcolor{keywordflow}{do} j=js,je}
\DoxyCodeLine{175     \textcolor{comment}{! 1. Only work on columns that are being heated.}}
\DoxyCodeLine{176     \textcolor{comment}{! 2. Find the deepest layer with any mass.}}
\DoxyCodeLine{177     \textcolor{comment}{! 3. Find the partial derivative of locally referenced potential density}}
\DoxyCodeLine{178     \textcolor{comment}{!  and coordinate density with temperature, and the density of the layer}}
\DoxyCodeLine{179     \textcolor{comment}{!  and the layer above.}}
\DoxyCodeLine{180     \textcolor{comment}{! 4. Heat a portion of the bottommost layer until it matches the target}}
\DoxyCodeLine{181     \textcolor{comment}{!    density of the layer above, and move it.}}
\DoxyCodeLine{182     \textcolor{comment}{! 4a. In the case of variable density layers, heat but do not move.}}
\DoxyCodeLine{183     \textcolor{comment}{! 5. If there is still heat left over, repeat for the next layer up.}}
\DoxyCodeLine{184     \textcolor{comment}{! This subroutine updates thickness, T \& S, and increments eb accordingly.}}
\DoxyCodeLine{185 }
\DoxyCodeLine{186     \textcolor{comment}{! 6. If there is not enough mass in the ocean, pass some of the heat up}}
\DoxyCodeLine{187     \textcolor{comment}{!    from the ocean via the frazil field?}}
\DoxyCodeLine{188 }
\DoxyCodeLine{189     num\_left = 0}
\DoxyCodeLine{190     \textcolor{keywordflow}{do} i=is,ie}
\DoxyCodeLine{191       heat\_rem(i) = g\%mask2dT(i,j) * (cs\%geo\_heat(i,j) * (dt*irho\_cp))}
\DoxyCodeLine{192       do\_i(i) = .true. ; \textcolor{keywordflow}{if} (heat\_rem(i) <= 0.0) do\_i(i) = .false.}
\DoxyCodeLine{193       \textcolor{keywordflow}{if} (do\_i(i)) num\_left = num\_left + 1}
\DoxyCodeLine{194       h\_geo\_rem(i) = cs\%Geothermal\_thick}
\DoxyCodeLine{195 \textcolor{keywordflow}{    enddo}}
\DoxyCodeLine{196     \textcolor{keywordflow}{if} (num\_left == 0) cycle}
\DoxyCodeLine{197 }
\DoxyCodeLine{198     \textcolor{comment}{! Find the first and last columns that need to be worked on.}}
\DoxyCodeLine{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}}
\DoxyCodeLine{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}}
\DoxyCodeLine{201 }
\DoxyCodeLine{202     \textcolor{keywordflow}{if} (nkmb > 0) \textcolor{keywordflow}{then}}
\DoxyCodeLine{203       \textcolor{keyword}{call }calculate\_density(tv\%T(:,j,nkmb), tv\%S(:,j,nkmb), p\_ref(:), rcv\_bl(:), \&}
\DoxyCodeLine{204                              tv\%eqn\_of\_state, (/isj-(g\%isd-1),iej-(g\%isd-1)/) )}
\DoxyCodeLine{205     \textcolor{keywordflow}{else}}
\DoxyCodeLine{206       rcv\_bl(:) = -1.0}
\DoxyCodeLine{207 \textcolor{keywordflow}{    endif}}
\DoxyCodeLine{208 }
\DoxyCodeLine{209     \textcolor{keywordflow}{do} k=nz,1,-1}
\DoxyCodeLine{210       \textcolor{keywordflow}{do} i=isj,iej ; \textcolor{keywordflow}{if} (do\_i(i)) \textcolor{keywordflow}{then}}
\DoxyCodeLine{211 }
\DoxyCodeLine{212         \textcolor{keywordflow}{if} (h(i,j,k) > angstrom) \textcolor{keywordflow}{then}}
\DoxyCodeLine{213           \textcolor{keywordflow}{if} ((h(i,j,k)-angstrom) >= h\_geo\_rem(i)) \textcolor{keywordflow}{then}}
\DoxyCodeLine{214             h\_heated = h\_geo\_rem(i)}
\DoxyCodeLine{215             heat\_avail = heat\_rem(i)}
\DoxyCodeLine{216             h\_geo\_rem(i) = 0.0}
\DoxyCodeLine{217           \textcolor{keywordflow}{else}}
\DoxyCodeLine{218             h\_heated = (h(i,j,k)-angstrom)}
\DoxyCodeLine{219             heat\_avail = heat\_rem(i) * (h\_heated / \&}
\DoxyCodeLine{220                                         (h\_geo\_rem(i) + h\_neglect))}
\DoxyCodeLine{221             h\_geo\_rem(i) = h\_geo\_rem(i) - h\_heated}
\DoxyCodeLine{222 \textcolor{keywordflow}{          endif}}
\DoxyCodeLine{223 }
\DoxyCodeLine{224           \textcolor{keywordflow}{if} (k<=nkmb .or. nkmb<=0) \textcolor{keywordflow}{then}}
\DoxyCodeLine{225             \textcolor{comment}{! Simply heat the layer; convective adjustment occurs later}}
\DoxyCodeLine{226             \textcolor{comment}{! if necessary.}}
\DoxyCodeLine{227             k\_tgt = k}
\DoxyCodeLine{228           \textcolor{keywordflow}{elseif} ((k==nkmb+1) .or. (gv\%Rlay(k-1) < rcv\_bl(i))) \textcolor{keywordflow}{then}}
\DoxyCodeLine{229             \textcolor{comment}{! Add enough heat to match the lowest buffer layer density.}}
\DoxyCodeLine{230             k\_tgt = nkmb}
\DoxyCodeLine{231             rcv\_tgt = rcv\_bl(i)}
\DoxyCodeLine{232           \textcolor{keywordflow}{else}}
\DoxyCodeLine{233             \textcolor{comment}{! Add enough heat to match the target density of layer k-1.}}
\DoxyCodeLine{234             k\_tgt = k-1}
\DoxyCodeLine{235             rcv\_tgt = gv\%Rlay(k-1)}
\DoxyCodeLine{236 \textcolor{keywordflow}{          endif}}
\DoxyCodeLine{237 }
\DoxyCodeLine{238           \textcolor{keywordflow}{if} (k<=nkmb .or. nkmb<=0) \textcolor{keywordflow}{then}}
\DoxyCodeLine{239             rcv = 0.0 ; drcv\_dt = 0.0 \textcolor{comment}{! Is this OK?}}
\DoxyCodeLine{240           \textcolor{keywordflow}{else}}
\DoxyCodeLine{241             \textcolor{keyword}{call }calculate\_density(tv\%T(i,j,k), tv\%S(i,j,k), tv\%P\_Ref, \&}
\DoxyCodeLine{242                          rcv, tv\%eqn\_of\_state)}
\DoxyCodeLine{243             t2(1) = tv\%T(i,j,k) ; s2(1) = tv\%S(i,j,k)}
\DoxyCodeLine{244             t2(2) = tv\%T(i,j,k\_tgt) ; s2(2) = tv\%S(i,j,k\_tgt)}
\DoxyCodeLine{245             \textcolor{keyword}{call }calculate\_density\_derivs(t2(:), s2(:), p\_ref(:), drcv\_dt\_, drcv\_ds\_, \&}
\DoxyCodeLine{246                          tv\%eqn\_of\_state, (/1,2/) )}
\DoxyCodeLine{247             drcv\_dt = 0.5*(drcv\_dt\_(1) + drcv\_dt\_(2))}
\DoxyCodeLine{248 \textcolor{keywordflow}{          endif}}
\DoxyCodeLine{249 }
\DoxyCodeLine{250           \textcolor{keywordflow}{if} ((drcv\_dt >= 0.0) .or. (k<=nkmb .or. nkmb<=0)) \textcolor{keywordflow}{then}}
\DoxyCodeLine{251             \textcolor{comment}{! This applies to variable density layers.}}
\DoxyCodeLine{252             heat\_in\_place = heat\_avail}
\DoxyCodeLine{253             heat\_trans = 0.0}
\DoxyCodeLine{254           \textcolor{keywordflow}{elseif} (drcv\_dt <= cs\%dRcv\_dT\_inplace) \textcolor{keywordflow}{then}}
\DoxyCodeLine{255             \textcolor{comment}{! This is the option that usually applies in isopycnal coordinates.}}
\DoxyCodeLine{256             heat\_in\_place = min(heat\_avail, max(0.0, h(i,j,k) * \&}
\DoxyCodeLine{257                                             ((gv\%Rlay(k)-rcv) / drcv\_dt)))}
\DoxyCodeLine{258             heat\_trans = heat\_avail - heat\_in\_place}
\DoxyCodeLine{259           \textcolor{keywordflow}{else}}
\DoxyCodeLine{260             \textcolor{comment}{! wt\_in\_place should go from 0 to 1.}}
\DoxyCodeLine{261             wt\_in\_place = (cs\%dRcv\_dT\_inplace - drcv\_dt) / cs\%dRcv\_dT\_inplace}
\DoxyCodeLine{262             heat\_in\_place = max(wt\_in\_place*heat\_avail, \&}
\DoxyCodeLine{263                                 h(i,j,k) * ((gv\%Rlay(k)-rcv) / drcv\_dt) )}
\DoxyCodeLine{264             heat\_trans = heat\_avail - heat\_in\_place}
\DoxyCodeLine{265 \textcolor{keywordflow}{          endif}}
\DoxyCodeLine{266 }
\DoxyCodeLine{267           \textcolor{keywordflow}{if} (heat\_in\_place > 0.0) \textcolor{keywordflow}{then}}
\DoxyCodeLine{268             \textcolor{comment}{! This applies to variable density layers. In isopycnal coordinates}}
\DoxyCodeLine{269             \textcolor{comment}{! this only arises for relatively fresh water near the freezing}}
\DoxyCodeLine{270             \textcolor{comment}{! point, in which case heating in place will eventually cause things}}
\DoxyCodeLine{271             \textcolor{comment}{! to sort themselves out, if only because the water will warm to}}
\DoxyCodeLine{272             \textcolor{comment}{! the temperature of maximum density.}}
\DoxyCodeLine{273             dtemp = heat\_in\_place / (h(i,j,k) + h\_neglect)}
\DoxyCodeLine{274             tv\%T(i,j,k) = tv\%T(i,j,k) + dtemp}
\DoxyCodeLine{275             heat\_rem(i) = heat\_rem(i) - heat\_in\_place}
\DoxyCodeLine{276             rcv = rcv + drcv\_dt * dtemp}
\DoxyCodeLine{277 \textcolor{keywordflow}{          endif}}
\DoxyCodeLine{278 }
\DoxyCodeLine{279           \textcolor{keywordflow}{if} (heat\_trans > 0.0) \textcolor{keywordflow}{then}}
\DoxyCodeLine{280             \textcolor{comment}{! The second expression might never be used, but will avoid}}
\DoxyCodeLine{281             \textcolor{comment}{! division by 0.}}
\DoxyCodeLine{282             drcv = max(rcv - rcv\_tgt, 0.0)}
\DoxyCodeLine{283 }
\DoxyCodeLine{284             \textcolor{comment}{!   dTemp = -dRcv / dRcv\_dT}}
\DoxyCodeLine{285             \textcolor{comment}{!   h\_transfer = min(heat\_rem(i) / dTemp, h(i,j,k)-Angstrom)}}
\DoxyCodeLine{286             \textcolor{keywordflow}{if} ((-drcv\_dt * heat\_trans) >= drcv * (h(i,j,k)-angstrom)) \textcolor{keywordflow}{then}}
\DoxyCodeLine{287               h\_transfer = h(i,j,k) - angstrom}
\DoxyCodeLine{288               heating = (h\_transfer * drcv) / (-drcv\_dt)}
\DoxyCodeLine{289               \textcolor{comment}{! Since not all the heat has been applied, return the fraction}}
\DoxyCodeLine{290               \textcolor{comment}{! of the layer thickness that has not yet been fully heated to}}
\DoxyCodeLine{291               \textcolor{comment}{! the h\_geo\_rem.}}
\DoxyCodeLine{292               h\_geo\_rem(i) = h\_geo\_rem(i) + h\_heated * \&}
\DoxyCodeLine{293                       ((heat\_avail - (heating + heat\_in\_place)) / heat\_avail)}
\DoxyCodeLine{294             \textcolor{keywordflow}{else}}
\DoxyCodeLine{295               h\_transfer = (-drcv\_dt * heat\_trans) / drcv}
\DoxyCodeLine{296               heating = heat\_trans}
\DoxyCodeLine{297 \textcolor{keywordflow}{            endif}}
\DoxyCodeLine{298             heat\_rem(i) = heat\_rem(i) - heating}
\DoxyCodeLine{299 }
\DoxyCodeLine{300             i\_h = 1.0 / ((h(i,j,k\_tgt) + h\_neglect) + h\_transfer)}
\DoxyCodeLine{301             tv\%T(i,j,k\_tgt) = ((h(i,j,k\_tgt) + h\_neglect) * tv\%T(i,j,k\_tgt) + \&}
\DoxyCodeLine{302                                (h\_transfer * tv\%T(i,j,k) + heating)) * i\_h}
\DoxyCodeLine{303             tv\%S(i,j,k\_tgt) = ((h(i,j,k\_tgt) + h\_neglect) * tv\%S(i,j,k\_tgt) + \&}
\DoxyCodeLine{304                                h\_transfer * tv\%S(i,j,k)) * i\_h}
\DoxyCodeLine{305 }
\DoxyCodeLine{306             h(i,j,k) = h(i,j,k) - h\_transfer}
\DoxyCodeLine{307             h(i,j,k\_tgt) = h(i,j,k\_tgt) + h\_transfer}
\DoxyCodeLine{308             eb(i,j,k\_tgt) = eb(i,j,k\_tgt) + h\_transfer}
\DoxyCodeLine{309             \textcolor{keywordflow}{if} (k\_tgt < k-1) \textcolor{keywordflow}{then}}
\DoxyCodeLine{310               \textcolor{keywordflow}{do} k2 = k\_tgt+1,k-1}
\DoxyCodeLine{311                 eb(i,j,k2) = eb(i,j,k2) + h\_transfer}
\DoxyCodeLine{312 \textcolor{keywordflow}{              enddo}}
\DoxyCodeLine{313 \textcolor{keywordflow}{            endif}}
\DoxyCodeLine{314 \textcolor{keywordflow}{          endif}}
\DoxyCodeLine{315 }
\DoxyCodeLine{316           \textcolor{keywordflow}{if} (heat\_rem(i) <= 0.0) \textcolor{keywordflow}{then}}
\DoxyCodeLine{317             do\_i(i) = .false. ; num\_left = num\_left-1}
\DoxyCodeLine{318             \textcolor{comment}{! For efficiency, uncomment these?}}
\DoxyCodeLine{319             \textcolor{comment}{! if ((i==isj) .and. (num\_left > 0)) then ; do i2=isj+1,iej ; if (do\_i(i2)) then}}
\DoxyCodeLine{320             \textcolor{comment}{!   isj = i2 ; exit ! Set the new starting value.}}
\DoxyCodeLine{321             \textcolor{comment}{! endif ; enddo ; endif}}
\DoxyCodeLine{322             \textcolor{comment}{! if ((i==iej) .and. (num\_left > 0)) then ; do i2=iej-1,isj,-1 ; if (do\_i(i2)) then}}
\DoxyCodeLine{323             \textcolor{comment}{!   iej = i2 ; exit ! Set the new ending value.}}
\DoxyCodeLine{324             \textcolor{comment}{! endif ; enddo ; endif}}
\DoxyCodeLine{325 \textcolor{keywordflow}{          endif}}
\DoxyCodeLine{326 \textcolor{keywordflow}{        endif}}
\DoxyCodeLine{327 }
\DoxyCodeLine{328         \textcolor{comment}{! Calculate heat tendency due to addition and transfer of internal heat}}
\DoxyCodeLine{329         \textcolor{keywordflow}{if} (cs\%id\_internal\_heat\_heat\_tendency > 0) \textcolor{keywordflow}{then}}
\DoxyCodeLine{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))}
\DoxyCodeLine{331 \textcolor{keywordflow}{        endif}}
\DoxyCodeLine{332 }
\DoxyCodeLine{333 \textcolor{keywordflow}{      endif} ;\textcolor{keywordflow}{ enddo}}
\DoxyCodeLine{334       \textcolor{keywordflow}{if} (num\_left <= 0) \textcolor{keywordflow}{exit}}
\DoxyCodeLine{335 \textcolor{keywordflow}{    enddo} \textcolor{comment}{! k-loop}}
\DoxyCodeLine{336 }
\DoxyCodeLine{337     \textcolor{keywordflow}{if} (\textcolor{keyword}{associated}(tv\%internal\_heat)) \textcolor{keywordflow}{then} ; \textcolor{keywordflow}{do} i=is,ie}
\DoxyCodeLine{338       tv\%internal\_heat(i,j) = tv\%internal\_heat(i,j) + gv\%H\_to\_RZ * \&}
\DoxyCodeLine{339            (g\%mask2dT(i,j) * (cs\%geo\_heat(i,j) * (dt*irho\_cp)) - heat\_rem(i))}
\DoxyCodeLine{340 \textcolor{keywordflow}{    enddo} ;\textcolor{keywordflow}{ endif}}
\DoxyCodeLine{341 \textcolor{keywordflow}{  enddo} \textcolor{comment}{! j-loop}}
\DoxyCodeLine{342 }
\DoxyCodeLine{343   \textcolor{comment}{! Post diagnostic of 3D tendencies (heat, temperature, and thickness) due to internal heat}}
\DoxyCodeLine{344   \textcolor{keywordflow}{if} (cs\%id\_internal\_heat\_heat\_tendency > 0) \textcolor{keywordflow}{then}}
\DoxyCodeLine{345     \textcolor{keyword}{call }post\_data(cs\%id\_internal\_heat\_heat\_tendency, work\_3d, cs\%diag, alt\_h=h\_old)}
\DoxyCodeLine{346 \textcolor{keywordflow}{  endif}}
\DoxyCodeLine{347   \textcolor{keywordflow}{if} (cs\%id\_internal\_heat\_temp\_tendency > 0) \textcolor{keywordflow}{then}}
\DoxyCodeLine{348     \textcolor{keywordflow}{do} k=1,nz ; \textcolor{keywordflow}{do} j=js,je ; \textcolor{keywordflow}{do} i=is,ie}
\DoxyCodeLine{349       work\_3d(i,j,k) = idt * (tv\%T(i,j,k) - t\_old(i,j,k))}
\DoxyCodeLine{350 \textcolor{keyword}{    end}do; enddo; enddo}
\DoxyCodeLine{351     \textcolor{keyword}{call }post\_data(cs\%id\_internal\_heat\_temp\_tendency, work\_3d, cs\%diag, alt\_h=h\_old)}
\DoxyCodeLine{352 \textcolor{keywordflow}{  endif}}
\DoxyCodeLine{353   \textcolor{keywordflow}{if} (cs\%id\_internal\_heat\_h\_tendency > 0) \textcolor{keywordflow}{then}}
\DoxyCodeLine{354     \textcolor{keywordflow}{do} k=1,nz ; \textcolor{keywordflow}{do} j=js,je ; \textcolor{keywordflow}{do} i=is,ie}
\DoxyCodeLine{355       work\_3d(i,j,k) = idt * (h(i,j,k) - h\_old(i,j,k))}
\DoxyCodeLine{356 \textcolor{keywordflow}{    enddo} ;\textcolor{keywordflow}{ enddo} ;\textcolor{keywordflow}{ enddo}}
\DoxyCodeLine{357     \textcolor{keyword}{call }post\_data(cs\%id\_internal\_heat\_h\_tendency, work\_3d, cs\%diag, alt\_h=h\_old)}
\DoxyCodeLine{358 \textcolor{keywordflow}{  endif}}
\DoxyCodeLine{359 }
\DoxyCodeLine{360 \textcolor{comment}{!  do j=js,je ; do i=is,ie}}
\DoxyCodeLine{361 \textcolor{comment}{!    resid(i,j) = tv\%internal\_heat(i,j) - resid(i,j) - GV\%H\_to\_RZ * \&}}
\DoxyCodeLine{362 \textcolor{comment}{!           (G\%mask2dT(i,j) * (CS\%geo\_heat(i,j) * (dt*Irho\_cp)))}}
\DoxyCodeLine{363 \textcolor{comment}{!  enddo ; enddo}}
\DoxyCodeLine{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(\mbox{\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{\texttt{ in,out}}  & {\em g} & The ocean\textquotesingle{}s grid structure. \\
\hline
\mbox{\texttt{ in}}  & {\em gv} & The ocean\textquotesingle{}s vertical grid structure. \\
\hline
\mbox{\texttt{ in}}  & {\em h} & Layer thicknesses \mbox{[}H $\sim$$>$ m or kg m-\/2\mbox{]} \\
\hline
\mbox{\texttt{ in,out}}  & {\em tv} & A structure containing pointers to any available thermodynamic fields. Absent fields have N\+U\+LL ptrs. \\
\hline
\mbox{\texttt{ in}}  & {\em dt} & Time increment \mbox{[}T $\sim$$>$ s\mbox{]}. \\
\hline
\mbox{\texttt{ in}}  & {\em us} & A dimensional unit scaling type \\
\hline
 & {\em cs} & The control structure returned by a previous call to geothermal\+\_\+init. \\
\hline
\mbox{\texttt{ 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}{0}
\DoxyCodeLine{371   \textcolor{keywordtype}{type}(ocean\_grid\_type),                    \textcolor{keywordtype}{intent(inout)} :: G\textcolor{comment}{  !< The ocean's grid structure.}}
\DoxyCodeLine{372   \textcolor{keywordtype}{type}(verticalGrid\_type),                  \textcolor{keywordtype}{intent(in)}    :: GV\textcolor{comment}{ !< The ocean's vertical grid structure.}}
\DoxyCodeLine{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]}}
\DoxyCodeLine{374   \textcolor{keywordtype}{type}(thermo\_var\_ptrs),                    \textcolor{keywordtype}{intent(inout)} :: tv\textcolor{comment}{ !< A structure containing pointers}}
\DoxyCodeLine{375 \textcolor{comment}{                                                                !! to any available thermodynamic}}
\DoxyCodeLine{376 \textcolor{comment}{                                                                !! fields. Absent fields have NULL}}
\DoxyCodeLine{377 \textcolor{comment}{                                                                !! ptrs.}}
\DoxyCodeLine{378 \textcolor{keywordtype}{  real},                                     \textcolor{keywordtype}{intent(in)}    :: dt\textcolor{comment}{ !< Time increment [T ~> s].}}
\DoxyCodeLine{379   \textcolor{keywordtype}{type}(unit\_scale\_type),                    \textcolor{keywordtype}{intent(in)}    :: US\textcolor{comment}{ !< A dimensional unit scaling type}}
\DoxyCodeLine{380   \textcolor{keywordtype}{type}(geothermal\_CS),                      \textcolor{keywordtype}{pointer}       :: CS\textcolor{comment}{ !< The control structure returned by}}
\DoxyCodeLine{381 \textcolor{comment}{                                                                !! a previous call to geothermal\_init.}}
\DoxyCodeLine{382   \textcolor{keywordtype}{integer},                        \textcolor{keywordtype}{optional}, \textcolor{keywordtype}{intent(in)}    :: halo\textcolor{comment}{ !< Halo width over which to work}}
\DoxyCodeLine{383 }
\DoxyCodeLine{384   \textcolor{comment}{! Local variables}}
\DoxyCodeLine{385 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(SZI\_(G))} :: \&}
\DoxyCodeLine{386     heat\_rem,  \& \textcolor{comment}{! remaining heat [H degC ~> m degC or kg degC m-2]}}
\DoxyCodeLine{387     h\_geo\_rem    \textcolor{comment}{! remaining thickness to apply geothermal heating [H ~> m or kg m-2]}}
\DoxyCodeLine{388 }
\DoxyCodeLine{389 \textcolor{keywordtype}{  real} :: Angstrom, H\_neglect  \textcolor{comment}{! small thicknesses [H ~> m or kg m-2]}}
\DoxyCodeLine{390 \textcolor{keywordtype}{  real} :: heat\_here     \textcolor{comment}{! heating applied to the present layer [degC H ~> degC m or degC kg m-2]}}
\DoxyCodeLine{391 \textcolor{keywordtype}{  real} :: dTemp         \textcolor{comment}{! temperature increase in a layer [degC]}}
\DoxyCodeLine{392 \textcolor{keywordtype}{  real} :: Irho\_cp       \textcolor{comment}{! inverse of heat capacity per unit layer volume}}
\DoxyCodeLine{393                         \textcolor{comment}{! [degC H Q-1 R-1 Z-1 ~> degC m3 J-1 or degC kg J-1]}}
\DoxyCodeLine{394 }
\DoxyCodeLine{395 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(SZI\_(G),SZJ\_(G),SZK\_(G))} :: \&}
\DoxyCodeLine{396     dTdt\_diag           \textcolor{comment}{! Diagnostic of temperature tendency [degC T-1 ~> degC s-1] which might be}}
\DoxyCodeLine{397                         \textcolor{comment}{! converted into a layer-integrated heat tendency [Q R Z T-1 ~> W m-2]}}
\DoxyCodeLine{398 \textcolor{keywordtype}{  real} :: Idt           \textcolor{comment}{! inverse of the timestep [T-1 ~> s-1]}}
\DoxyCodeLine{399   \textcolor{keywordtype}{logical} :: do\_any     \textcolor{comment}{! True if there is more to be done on the current j-row.}}
\DoxyCodeLine{400   \textcolor{keywordtype}{logical} :: calc\_diags \textcolor{comment}{! True if diagnostic tendencies are needed.}}
\DoxyCodeLine{401   \textcolor{keywordtype}{integer} :: i, j, k, is, ie, js, je, nz, i2, isj, iej}
\DoxyCodeLine{402 }
\DoxyCodeLine{403   is = g\%isc ; ie = g\%iec ; js = g\%jsc ; je = g\%jec ; nz = g\%ke}
\DoxyCodeLine{404   \textcolor{keywordflow}{if} (\textcolor{keyword}{present}(halo)) \textcolor{keywordflow}{then}}
\DoxyCodeLine{405     is = g\%isc-halo ; ie = g\%iec+halo ; js = g\%jsc-halo ; je = g\%jec+halo}
\DoxyCodeLine{406 \textcolor{keywordflow}{  endif}}
\DoxyCodeLine{407 }
\DoxyCodeLine{408   \textcolor{keywordflow}{if} (.not. \textcolor{keyword}{associated}(cs)) \textcolor{keyword}{call }mom\_error(fatal, \textcolor{stringliteral}{"MOM\_geothermal: "}//\&}
\DoxyCodeLine{409          \textcolor{stringliteral}{"Module must be initialized before it is used."})}
\DoxyCodeLine{410   \textcolor{keywordflow}{if} (.not.cs\%apply\_geothermal) \textcolor{keywordflow}{return}}
\DoxyCodeLine{411 }
\DoxyCodeLine{412   irho\_cp   = 1.0 / (gv\%H\_to\_RZ * tv\%C\_p)}
\DoxyCodeLine{413   angstrom  = gv\%Angstrom\_H}
\DoxyCodeLine{414   h\_neglect = gv\%H\_subroundoff}
\DoxyCodeLine{415   idt       = 1.0 / dt}
\DoxyCodeLine{416 }
\DoxyCodeLine{417   \textcolor{keywordflow}{if} (.not.\textcolor{keyword}{associated}(tv\%T)) \textcolor{keyword}{call }mom\_error(fatal, \textcolor{stringliteral}{"MOM geothermal\_in\_place: "}//\&}
\DoxyCodeLine{418       \textcolor{stringliteral}{"Geothermal heating can only be applied if T \& S are state variables."})}
\DoxyCodeLine{419 }
\DoxyCodeLine{420 \textcolor{comment}{!  do i=is,ie ; do j=js,je}}
\DoxyCodeLine{421 \textcolor{comment}{!    resid(i,j) = tv\%internal\_heat(i,j)}}
\DoxyCodeLine{422 \textcolor{comment}{!  enddo ; enddo}}
\DoxyCodeLine{423 }
\DoxyCodeLine{424   \textcolor{comment}{! Conditionals for tracking diagnostic depdendencies}}
\DoxyCodeLine{425   calc\_diags = (cs\%id\_internal\_heat\_heat\_tendency > 0) .or. (cs\%id\_internal\_heat\_temp\_tendency > 0)}
\DoxyCodeLine{426 }
\DoxyCodeLine{427   \textcolor{keywordflow}{if} (calc\_diags) dtdt\_diag(:,:,:) = 0.0}
\DoxyCodeLine{428 }
\DoxyCodeLine{429   \textcolor{comment}{!\$OMP parallel do default(shared) private(heat\_rem,do\_any,h\_geo\_rem,isj,iej,heat\_here,dTemp)}}
\DoxyCodeLine{430   \textcolor{keywordflow}{do} j=js,je}
\DoxyCodeLine{431     \textcolor{comment}{! Only work on columns that are being heated, and heat the near-bottom water.}}
\DoxyCodeLine{432 }
\DoxyCodeLine{433     \textcolor{comment}{! If there is not enough mass in the ocean, pass some of the heat up}}
\DoxyCodeLine{434     \textcolor{comment}{! from the ocean via the frazil field?}}
\DoxyCodeLine{435 }
\DoxyCodeLine{436     do\_any = .false.}
\DoxyCodeLine{437     \textcolor{keywordflow}{do} i=is,ie}
\DoxyCodeLine{438       heat\_rem(i) = g\%mask2dT(i,j) * (cs\%geo\_heat(i,j) * (dt*irho\_cp))}
\DoxyCodeLine{439       \textcolor{keywordflow}{if} (heat\_rem(i) > 0.0) do\_any = .true.}
\DoxyCodeLine{440       h\_geo\_rem(i) = cs\%Geothermal\_thick}
\DoxyCodeLine{441 \textcolor{keywordflow}{    enddo}}
\DoxyCodeLine{442     \textcolor{keywordflow}{if} (.not.do\_any) cycle}
\DoxyCodeLine{443 }
\DoxyCodeLine{444     \textcolor{comment}{! Find the first and last columns that need to be worked on.}}
\DoxyCodeLine{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}}
\DoxyCodeLine{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}}
\DoxyCodeLine{447 }
\DoxyCodeLine{448     \textcolor{keywordflow}{do} k=nz,1,-1}
\DoxyCodeLine{449       do\_any = .false.}
\DoxyCodeLine{450       \textcolor{keywordflow}{do} i=isj,iej}
\DoxyCodeLine{451         \textcolor{keywordflow}{if} ((heat\_rem(i) > 0.0) .and. (h(i,j,k) > angstrom)) \textcolor{keywordflow}{then}}
\DoxyCodeLine{452           \textcolor{comment}{! Apply some or all of the remaining heat to this layer.}}
\DoxyCodeLine{453           \textcolor{comment}{! Convective adjustment occurs outside of this module if necessary.}}
\DoxyCodeLine{454           \textcolor{keywordflow}{if} ((h(i,j,k)-angstrom) >= h\_geo\_rem(i)) \textcolor{keywordflow}{then}}
\DoxyCodeLine{455             heat\_here = heat\_rem(i)}
\DoxyCodeLine{456             h\_geo\_rem(i) = 0.0}
\DoxyCodeLine{457             heat\_rem(i) = 0.0}
\DoxyCodeLine{458           \textcolor{keywordflow}{else}}
\DoxyCodeLine{459             heat\_here = heat\_rem(i) * ((h(i,j,k)-angstrom) / (h\_geo\_rem(i) + h\_neglect))}
\DoxyCodeLine{460             h\_geo\_rem(i) = h\_geo\_rem(i) - (h(i,j,k)-angstrom)}
\DoxyCodeLine{461             heat\_rem(i) = heat\_rem(i) - heat\_here}
\DoxyCodeLine{462 \textcolor{keywordflow}{          endif}}
\DoxyCodeLine{463 }
\DoxyCodeLine{464           dtemp = heat\_here / (h(i,j,k) + h\_neglect)}
\DoxyCodeLine{465           tv\%T(i,j,k) = tv\%T(i,j,k) + dtemp}
\DoxyCodeLine{466           \textcolor{keywordflow}{if} (calc\_diags) dtdt\_diag(i,j,k) = dtemp * idt}
\DoxyCodeLine{467 \textcolor{keywordflow}{        endif}}
\DoxyCodeLine{468 }
\DoxyCodeLine{469         \textcolor{keywordflow}{if} (heat\_rem(i) > 0.0) do\_any= .true.}
\DoxyCodeLine{470 \textcolor{keywordflow}{      enddo}}
\DoxyCodeLine{471 }
\DoxyCodeLine{472       \textcolor{keywordflow}{if} (.not.do\_any) \textcolor{keywordflow}{exit}}
\DoxyCodeLine{473 \textcolor{keywordflow}{    enddo} \textcolor{comment}{! k-loop}}
\DoxyCodeLine{474 }
\DoxyCodeLine{475     \textcolor{keywordflow}{if} (\textcolor{keyword}{associated}(tv\%internal\_heat)) \textcolor{keywordflow}{then} ; \textcolor{keywordflow}{do} i=is,ie}
\DoxyCodeLine{476       tv\%internal\_heat(i,j) = tv\%internal\_heat(i,j) + gv\%H\_to\_RZ * \&}
\DoxyCodeLine{477            (g\%mask2dT(i,j) * (cs\%geo\_heat(i,j) * (dt*irho\_cp)) - heat\_rem(i))}
\DoxyCodeLine{478 \textcolor{keywordflow}{    enddo} ;\textcolor{keywordflow}{ endif}}
\DoxyCodeLine{479 \textcolor{keywordflow}{  enddo} \textcolor{comment}{! j-loop}}
\DoxyCodeLine{480 }
\DoxyCodeLine{481   \textcolor{comment}{! Post diagnostics of 3D tendencies of heat and temperature due to geothermal heat}}
\DoxyCodeLine{482   \textcolor{keywordflow}{if} (cs\%id\_internal\_heat\_temp\_tendency > 0) \textcolor{keywordflow}{then}}
\DoxyCodeLine{483     \textcolor{keyword}{call }post\_data(cs\%id\_internal\_heat\_temp\_tendency, dtdt\_diag, cs\%diag, alt\_h=h)}
\DoxyCodeLine{484 \textcolor{keywordflow}{  endif}}
\DoxyCodeLine{485   \textcolor{keywordflow}{if} (cs\%id\_internal\_heat\_heat\_tendency > 0) \textcolor{keywordflow}{then}}
\DoxyCodeLine{486     \textcolor{keywordflow}{do} k=1,nz ; \textcolor{keywordflow}{do} j=js,je ; \textcolor{keywordflow}{do} i=is,ie}
\DoxyCodeLine{487       \textcolor{comment}{! Dangerously reuse dTdt\_diag for a related variable with different units, going from}}
\DoxyCodeLine{488       \textcolor{comment}{! units of [degC T-1 ~> degC s-1] to units of [Q R Z T-1 ~> W m-2]}}
\DoxyCodeLine{489       dtdt\_diag(i,j,k) = (gv\%H\_to\_RZ*tv\%C\_p) * (h(i,j,k) * dtdt\_diag(i,j,k))}
\DoxyCodeLine{490 \textcolor{keywordflow}{    enddo} ;\textcolor{keywordflow}{ enddo} ;\textcolor{keywordflow}{ enddo}}
\DoxyCodeLine{491     \textcolor{keyword}{call }post\_data(cs\%id\_internal\_heat\_heat\_tendency, dtdt\_diag, cs\%diag, alt\_h=h)}
\DoxyCodeLine{492 \textcolor{keywordflow}{  endif}}
\DoxyCodeLine{493 }
\DoxyCodeLine{494 \textcolor{comment}{!  do j=js,je ; do i=is,ie}}
\DoxyCodeLine{495 \textcolor{comment}{!    resid(i,j) = tv\%internal\_heat(i,j) - resid(i,j) - GV\%H\_to\_RZ * \&}}
\DoxyCodeLine{496 \textcolor{comment}{!           (G\%mask2dT(i,j) * (CS\%geo\_heat(i,j) * (dt*Irho\_cp)))}}
\DoxyCodeLine{497 \textcolor{comment}{!  enddo ; enddo}}
\DoxyCodeLine{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(\mbox{\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{\texttt{ in}}  & {\em time} & Current model time. \\
\hline
\mbox{\texttt{ in,out}}  & {\em g} & The ocean\textquotesingle{}s grid structure. \\
\hline
\mbox{\texttt{ in}}  & {\em gv} & The ocean\textquotesingle{}s vertical grid structure. \\
\hline
\mbox{\texttt{ in}}  & {\em us} & A dimensional unit scaling type \\
\hline
\mbox{\texttt{ in}}  & {\em param\+\_\+file} & A structure to parse for run-\/time parameters. \\
\hline
\mbox{\texttt{ in,out}}  & {\em diag} & Structure used to regulate diagnostic output. \\
\hline
 & {\em cs} & Pointer pointing to the module control structure. \\
\hline
\mbox{\texttt{ 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}{0}
\DoxyCodeLine{503   \textcolor{keywordtype}{type}(time\_type), \textcolor{keywordtype}{target}, \textcolor{keywordtype}{intent(in)}    :: Time\textcolor{comment}{ !< Current model time.}}
\DoxyCodeLine{504   \textcolor{keywordtype}{type}(ocean\_grid\_type),   \textcolor{keywordtype}{intent(inout)} :: G\textcolor{comment}{    !< The ocean's grid structure.}}
\DoxyCodeLine{505   \textcolor{keywordtype}{type}(verticalGrid\_type), \textcolor{keywordtype}{intent(in)}    :: GV\textcolor{comment}{   !< The ocean's vertical grid structure.}}
\DoxyCodeLine{506   \textcolor{keywordtype}{type}(unit\_scale\_type),   \textcolor{keywordtype}{intent(in)}    :: US\textcolor{comment}{   !< A dimensional unit scaling type}}
\DoxyCodeLine{507   \textcolor{keywordtype}{type}(param\_file\_type),   \textcolor{keywordtype}{intent(in)}    :: param\_file\textcolor{comment}{ !< A structure to parse for run-time}}
\DoxyCodeLine{508 \textcolor{comment}{                                                 !! parameters.}}
\DoxyCodeLine{509   \textcolor{keywordtype}{type}(diag\_ctrl), \textcolor{keywordtype}{target}, \textcolor{keywordtype}{intent(inout)} :: diag\textcolor{comment}{ !< Structure used to regulate diagnostic output.}}
\DoxyCodeLine{510   \textcolor{keywordtype}{type}(geothermal\_CS),     \textcolor{keywordtype}{pointer}       :: CS\textcolor{comment}{   !< Pointer pointing to the module control}}
\DoxyCodeLine{511 \textcolor{comment}{                                                 !! structure.}}
\DoxyCodeLine{512   \textcolor{keywordtype}{logical},       \textcolor{keywordtype}{optional}, \textcolor{keywordtype}{intent(in)}    :: useALEalgorithm\textcolor{comment}{  !< logical for whether to use ALE remapping}}
\DoxyCodeLine{513 }
\DoxyCodeLine{514 \textcolor{comment}{! This include declares and sets the variable "version".}}
\DoxyCodeLine{515 \textcolor{preprocessor}{\#include "version\_variable.h"}}
\DoxyCodeLine{516 \textcolor{preprocessor}{}  \textcolor{keywordtype}{character(len=40)}  :: mdl = \textcolor{stringliteral}{"MOM\_geothermal"}  \textcolor{comment}{! module name}}
\DoxyCodeLine{517   \textcolor{keywordtype}{character(len=48)}  :: thickness\_units}
\DoxyCodeLine{518   \textcolor{comment}{! Local variables}}
\DoxyCodeLine{519   \textcolor{keywordtype}{character(len=200)} :: inputdir, geo\_file, filename, geotherm\_var}
\DoxyCodeLine{520 \textcolor{keywordtype}{  real} :: geo\_scale  \textcolor{comment}{! A constant heat flux or dimensionally rescaled geothermal flux scaling factor}}
\DoxyCodeLine{521                      \textcolor{comment}{! [Q R Z T-1 ~> W m-2] or [Q R Z m2 s J-1 T-1 ~> 1]}}
\DoxyCodeLine{522   \textcolor{keywordtype}{integer} :: i, j, isd, ied, jsd, jed, id}
\DoxyCodeLine{523   isd = g\%isd ; ied = g\%ied ; jsd = g\%jsd ; jed = g\%jed}
\DoxyCodeLine{524 }
\DoxyCodeLine{525   \textcolor{keywordflow}{if} (\textcolor{keyword}{associated}(cs)) \textcolor{keywordflow}{then}}
\DoxyCodeLine{526     \textcolor{keyword}{call }mom\_error(warning, \textcolor{stringliteral}{"geothermal\_init called with an associated"}// \&}
\DoxyCodeLine{527                             \textcolor{stringliteral}{"associated control structure."})}
\DoxyCodeLine{528     \textcolor{keywordflow}{return}}
\DoxyCodeLine{529   \textcolor{keywordflow}{else} ; \textcolor{keyword}{allocate}(cs) ;\textcolor{keywordflow}{ endif}}
\DoxyCodeLine{530 }
\DoxyCodeLine{531   cs\%diag => diag}
\DoxyCodeLine{532   cs\%Time => time}
\DoxyCodeLine{533 }
\DoxyCodeLine{534   \textcolor{comment}{! write parameters to the model log.}}
\DoxyCodeLine{535   \textcolor{keyword}{call }log\_version(param\_file, mdl, version, \textcolor{stringliteral}{""})}
\DoxyCodeLine{536   \textcolor{keyword}{call }get\_param(param\_file, mdl, \textcolor{stringliteral}{"GEOTHERMAL\_SCALE"}, geo\_scale, \&}
\DoxyCodeLine{537                  \textcolor{stringliteral}{"The constant geothermal heat flux, a rescaling "}//\&}
\DoxyCodeLine{538                  \textcolor{stringliteral}{"factor for the heat flux read from GEOTHERMAL\_FILE, or "}//\&}
\DoxyCodeLine{539                  \textcolor{stringliteral}{"0 to disable the geothermal heating."}, \&}
\DoxyCodeLine{540                  units=\textcolor{stringliteral}{"W m-2 or various"}, default=0.0, scale=us\%W\_m2\_to\_QRZ\_T)}
\DoxyCodeLine{541   cs\%apply\_geothermal = .not.(geo\_scale == 0.0)}
\DoxyCodeLine{542   \textcolor{keywordflow}{if} (.not.cs\%apply\_geothermal) \textcolor{keywordflow}{return}}
\DoxyCodeLine{543 }
\DoxyCodeLine{544   \textcolor{keyword}{call }safe\_alloc\_ptr(cs\%geo\_heat, isd, ied, jsd, jed) ; cs\%geo\_heat(:,:) = 0.0}
\DoxyCodeLine{545 }
\DoxyCodeLine{546   \textcolor{keyword}{call }get\_param(param\_file, mdl, \textcolor{stringliteral}{"GEOTHERMAL\_FILE"}, geo\_file, \&}
\DoxyCodeLine{547                  \textcolor{stringliteral}{"The file from which the geothermal heating is to be "}//\&}
\DoxyCodeLine{548                  \textcolor{stringliteral}{"read, or blank to use a constant heating rate."}, default=\textcolor{stringliteral}{" "})}
\DoxyCodeLine{549   \textcolor{keyword}{call }get\_param(param\_file, mdl, \textcolor{stringliteral}{"GEOTHERMAL\_THICKNESS"}, cs\%geothermal\_thick, \&}
\DoxyCodeLine{550                  \textcolor{stringliteral}{"The thickness over which to apply geothermal heating."}, \&}
\DoxyCodeLine{551                  units=\textcolor{stringliteral}{"m"}, default=0.1, scale=gv\%m\_to\_H)}
\DoxyCodeLine{552   \textcolor{keyword}{call }get\_param(param\_file, mdl, \textcolor{stringliteral}{"GEOTHERMAL\_DRHO\_DT\_INPLACE"}, cs\%dRcv\_dT\_inplace, \&}
\DoxyCodeLine{553                  \textcolor{stringliteral}{"The value of drho\_dT above which geothermal heating "}//\&}
\DoxyCodeLine{554                  \textcolor{stringliteral}{"simply heats water in place instead of moving it between "}//\&}
\DoxyCodeLine{555                  \textcolor{stringliteral}{"isopycnal layers.  This must be negative."}, \&}
\DoxyCodeLine{556                  units=\textcolor{stringliteral}{"kg m-3 K-1"}, scale=us\%kg\_m3\_to\_R, default=-0.01)}
\DoxyCodeLine{557   \textcolor{keywordflow}{if} (cs\%dRcv\_dT\_inplace >= 0.0) \textcolor{keyword}{call }mom\_error(fatal, \textcolor{stringliteral}{"geothermal\_init: "}//\&}
\DoxyCodeLine{558          \textcolor{stringliteral}{"GEOTHERMAL\_DRHO\_DT\_INPLACE must be negative."})}
\DoxyCodeLine{559 }
\DoxyCodeLine{560   \textcolor{keywordflow}{if} (len\_trim(geo\_file) >= 1) \textcolor{keywordflow}{then}}
\DoxyCodeLine{561     \textcolor{keyword}{call }get\_param(param\_file, mdl, \textcolor{stringliteral}{"INPUTDIR"}, inputdir, default=\textcolor{stringliteral}{"."})}
\DoxyCodeLine{562     inputdir = slasher(inputdir)}
\DoxyCodeLine{563     filename = trim(inputdir)//trim(geo\_file)}
\DoxyCodeLine{564     \textcolor{keyword}{call }log\_param(param\_file, mdl, \textcolor{stringliteral}{"INPUTDIR/GEOTHERMAL\_FILE"}, filename)}
\DoxyCodeLine{565     \textcolor{keyword}{call }get\_param(param\_file, mdl, \textcolor{stringliteral}{"GEOTHERMAL\_VARNAME"}, geotherm\_var, \&}
\DoxyCodeLine{566                  \textcolor{stringliteral}{"The name of the geothermal heating variable in "}//\&}
\DoxyCodeLine{567                  \textcolor{stringliteral}{"GEOTHERMAL\_FILE."}, default=\textcolor{stringliteral}{"geo\_heat"})}
\DoxyCodeLine{568     \textcolor{keyword}{call }mom\_read\_data(filename, trim(geotherm\_var), cs\%geo\_heat, g\%Domain)}
\DoxyCodeLine{569     \textcolor{keywordflow}{do} j=jsd,jed ; \textcolor{keywordflow}{do} i=isd,ied}
\DoxyCodeLine{570       cs\%geo\_heat(i,j) = (g\%mask2dT(i,j) * geo\_scale) * cs\%geo\_heat(i,j)}
\DoxyCodeLine{571 \textcolor{keywordflow}{    enddo} ;\textcolor{keywordflow}{ enddo}}
\DoxyCodeLine{572   \textcolor{keywordflow}{else}}
\DoxyCodeLine{573     \textcolor{keywordflow}{do} j=jsd,jed ; \textcolor{keywordflow}{do} i=isd,ied}
\DoxyCodeLine{574       cs\%geo\_heat(i,j) = g\%mask2dT(i,j) * geo\_scale}
\DoxyCodeLine{575 \textcolor{keywordflow}{    enddo} ;\textcolor{keywordflow}{ enddo}}
\DoxyCodeLine{576 \textcolor{keywordflow}{  endif}}
\DoxyCodeLine{577   \textcolor{keyword}{call }pass\_var(cs\%geo\_heat, g\%domain)}
\DoxyCodeLine{578 }
\DoxyCodeLine{579   thickness\_units = get\_thickness\_units(gv)}
\DoxyCodeLine{580 }
\DoxyCodeLine{581   \textcolor{comment}{! post the static geothermal heating field}}
\DoxyCodeLine{582   id = register\_static\_field(\textcolor{stringliteral}{'ocean\_model'}, \textcolor{stringliteral}{'geo\_heat'}, diag\%axesT1,   \&}
\DoxyCodeLine{583         \textcolor{stringliteral}{'Geothermal heat flux into ocean'}, \textcolor{stringliteral}{'W m-2'}, conversion=us\%QRZ\_T\_to\_W\_m2, \&}
\DoxyCodeLine{584         cmor\_field\_name=\textcolor{stringliteral}{'hfgeou'}, cmor\_units=\textcolor{stringliteral}{'W m-2'},                  \&}
\DoxyCodeLine{585         cmor\_standard\_name=\textcolor{stringliteral}{'upward\_geothermal\_heat\_flux\_at\_sea\_floor'}, \&}
\DoxyCodeLine{586         cmor\_long\_name=\textcolor{stringliteral}{'Upward geothermal heat flux at sea floor'}, \&}
\DoxyCodeLine{587         x\_cell\_method=\textcolor{stringliteral}{'mean'}, y\_cell\_method=\textcolor{stringliteral}{'mean'}, area\_cell\_method=\textcolor{stringliteral}{'mean'})}
\DoxyCodeLine{588   \textcolor{keywordflow}{if} (id > 0) \textcolor{keyword}{call }post\_data(id, cs\%geo\_heat, diag, .true.)}
\DoxyCodeLine{589 }
\DoxyCodeLine{590   \textcolor{comment}{! Diagnostic for tendencies due to internal heat (in 3d)}}
\DoxyCodeLine{591   cs\%id\_internal\_heat\_heat\_tendency=register\_diag\_field(\textcolor{stringliteral}{'ocean\_model'}, \&}
\DoxyCodeLine{592         \textcolor{stringliteral}{'internal\_heat\_heat\_tendency'}, diag\%axesTL, time,              \&}
\DoxyCodeLine{593         \textcolor{stringliteral}{'Heat tendency (in 3D) due to internal (geothermal) sources'},  \&}
\DoxyCodeLine{594         \textcolor{stringliteral}{'W m-2'}, conversion=us\%QRZ\_T\_to\_W\_m2, v\_extensive=.true.)}
\DoxyCodeLine{595   cs\%id\_internal\_heat\_temp\_tendency=register\_diag\_field(\textcolor{stringliteral}{'ocean\_model'}, \&}
\DoxyCodeLine{596         \textcolor{stringliteral}{'internal\_heat\_temp\_tendency'}, diag\%axesTL, time,              \&}
\DoxyCodeLine{597         \textcolor{stringliteral}{'Temperature tendency (in 3D) due to internal (geothermal) sources'}, \&}
\DoxyCodeLine{598         \textcolor{stringliteral}{'degC s-1'}, conversion=us\%s\_to\_T, v\_extensive=.true.)}
\DoxyCodeLine{599   \textcolor{keywordflow}{if} (\textcolor{keyword}{present}(usealealgorithm)) \textcolor{keywordflow}{then} ; \textcolor{keywordflow}{if} (.not.usealealgorithm) \textcolor{keywordflow}{then}}
\DoxyCodeLine{600     \textcolor{comment}{! Do not offer this diagnostic if heating will be in place.}}
\DoxyCodeLine{601     cs\%id\_internal\_heat\_h\_tendency=register\_diag\_field(\textcolor{stringliteral}{'ocean\_model'},    \&}
\DoxyCodeLine{602         \textcolor{stringliteral}{'internal\_heat\_h\_tendency'}, diag\%axesTL, time,                \&}
\DoxyCodeLine{603         \textcolor{stringliteral}{'Thickness tendency (in 3D) due to internal (geothermal) sources'}, \&}
\DoxyCodeLine{604         trim(thickness\_units), conversion=gv\%H\_to\_MKS*us\%s\_to\_T, v\_extensive=.true.)}
\DoxyCodeLine{605 \textcolor{keywordflow}{  endif} ;\textcolor{keywordflow}{ endif}}
\DoxyCodeLine{606 }

\end{DoxyCode}
