\hypertarget{namespacemom__ale__sponge}{}\section{mom\+\_\+ale\+\_\+sponge Module Reference}
\label{namespacemom__ale__sponge}\index{mom\+\_\+ale\+\_\+sponge@{mom\+\_\+ale\+\_\+sponge}}


\subsection{Detailed Description}
This module contains the routines used to apply sponge layers when using the A\+LE mode. 

Applying sponges requires the following\+:
\begin{DoxyEnumerate}
\item initialize\+\_\+\+A\+L\+E\+\_\+sponge
\item set\+\_\+up\+\_\+\+A\+L\+E\+\_\+sponge\+\_\+field (tracers) and set\+\_\+up\+\_\+\+A\+L\+E\+\_\+sponge\+\_\+vel\+\_\+field (vel)
\item apply\+\_\+\+A\+L\+E\+\_\+sponge
\item init\+\_\+\+A\+L\+E\+\_\+sponge\+\_\+diags (not being used for now)
\item A\+L\+E\+\_\+sponge\+\_\+end (not being used for now) 
\end{DoxyEnumerate}\subsection*{Data Types}
\begin{DoxyCompactItemize}
\item 
type \hyperlink{structmom__ale__sponge_1_1ale__sponge__cs}{ale\+\_\+sponge\+\_\+cs}
\begin{DoxyCompactList}\small\item\em A\+LE sponge control structure. \end{DoxyCompactList}\item 
interface \hyperlink{interfacemom__ale__sponge_1_1initialize__ale__sponge}{initialize\+\_\+ale\+\_\+sponge}
\begin{DoxyCompactList}\small\item\em Ddetermine the number of points which are within sponges in this computational domain. \end{DoxyCompactList}\item 
type \hyperlink{structmom__ale__sponge_1_1p2d}{p2d}
\begin{DoxyCompactList}\small\item\em A structure for creating arrays of pointers to 2D arrays with extra gridding information. \end{DoxyCompactList}\item 
type \hyperlink{structmom__ale__sponge_1_1p3d}{p3d}
\begin{DoxyCompactList}\small\item\em A structure for creating arrays of pointers to 3D arrays with extra gridding information. \end{DoxyCompactList}\item 
interface \hyperlink{interfacemom__ale__sponge_1_1set__up__ale__sponge__field}{set\+\_\+up\+\_\+ale\+\_\+sponge\+\_\+field}
\begin{DoxyCompactList}\small\item\em Store the reference profile at h points for a variable. \end{DoxyCompactList}\item 
interface \hyperlink{interfacemom__ale__sponge_1_1set__up__ale__sponge__vel__field}{set\+\_\+up\+\_\+ale\+\_\+sponge\+\_\+vel\+\_\+field}
\begin{DoxyCompactList}\small\item\em This subroutine stores the reference profile at u and v points for a vector. \end{DoxyCompactList}\end{DoxyCompactItemize}
\subsection*{Functions/\+Subroutines}
\begin{DoxyCompactItemize}
\item 
subroutine \hyperlink{namespacemom__ale__sponge_a15129d167423dc162d22ef7cf4742651}{initialize\+\_\+ale\+\_\+sponge\+\_\+fixed} (Iresttime, G, param\+\_\+file, CS, data\+\_\+h, nz\+\_\+data)
\begin{DoxyCompactList}\small\item\em This subroutine determines the number of points which are within sponges in this computational domain. Only points that have positive values of Iresttime and which mask2dT indicates are ocean points are included in the sponges. It also stores the target interface heights. \end{DoxyCompactList}\item 
integer function, public \hyperlink{namespacemom__ale__sponge_a30b98598d25129c9fbb6e7c4b3480e7a}{get\+\_\+ale\+\_\+sponge\+\_\+nz\+\_\+data} (CS)
\begin{DoxyCompactList}\small\item\em Return the number of layers in the data with a fixed A\+LE sponge, or 0 if there are no sponge columns on this PE. \end{DoxyCompactList}\item 
subroutine, public \hyperlink{namespacemom__ale__sponge_a56eb18da6c1d40f6abb544e5b7114293}{get\+\_\+ale\+\_\+sponge\+\_\+thicknesses} (G, data\+\_\+h, sponge\+\_\+mask, CS)
\begin{DoxyCompactList}\small\item\em Return the thicknesses used for the data with a fixed A\+LE sponge. \end{DoxyCompactList}\item 
subroutine \hyperlink{namespacemom__ale__sponge_a0febb96fb2fd40a72580d078ca023098}{initialize\+\_\+ale\+\_\+sponge\+\_\+varying} (Iresttime, G, param\+\_\+file, CS)
\begin{DoxyCompactList}\small\item\em This subroutine determines the number of points which are to be restoref in the computational domain. Only points that have positive values of Iresttime and which mask2dT indicates are ocean points are included in the sponges. \end{DoxyCompactList}\item 
subroutine, public \hyperlink{namespacemom__ale__sponge_aed1ab3e7a8063222f1c9b0d3d2336cbe}{init\+\_\+ale\+\_\+sponge\+\_\+diags} (Time, G, diag, CS)
\begin{DoxyCompactList}\small\item\em Initialize diagnostics for the A\+L\+E\+\_\+sponge module. \end{DoxyCompactList}\item 
subroutine \hyperlink{namespacemom__ale__sponge_a7b00598b2cf45b865f56515ed5d2ed0a}{set\+\_\+up\+\_\+ale\+\_\+sponge\+\_\+field\+\_\+fixed} (sp\+\_\+val, G, f\+\_\+ptr, CS)
\begin{DoxyCompactList}\small\item\em This subroutine stores the reference profile at h points for the variable whose address is given by f\+\_\+ptr. \end{DoxyCompactList}\item 
subroutine \hyperlink{namespacemom__ale__sponge_a5222905f5cfddd07b77e05428e88dd85}{set\+\_\+up\+\_\+ale\+\_\+sponge\+\_\+field\+\_\+varying} (filename, fieldname, Time, G, GV, US, f\+\_\+ptr, CS)
\begin{DoxyCompactList}\small\item\em This subroutine stores the reference profile at h points for the variable whose address is given by filename and fieldname. \end{DoxyCompactList}\item 
subroutine \hyperlink{namespacemom__ale__sponge_a6eb21c5a149d573ba0d67fdb3a932115}{set\+\_\+up\+\_\+ale\+\_\+sponge\+\_\+vel\+\_\+field\+\_\+fixed} (u\+\_\+val, v\+\_\+val, G, u\+\_\+ptr, v\+\_\+ptr, CS)
\begin{DoxyCompactList}\small\item\em This subroutine stores the reference profile at u and v points for the variable whose address is given by u\+\_\+ptr and v\+\_\+ptr. \end{DoxyCompactList}\item 
subroutine \hyperlink{namespacemom__ale__sponge_a551051d11b239eeef807fb88ab31aba6}{set\+\_\+up\+\_\+ale\+\_\+sponge\+\_\+vel\+\_\+field\+\_\+varying} (filename\+\_\+u, fieldname\+\_\+u, filename\+\_\+v, fieldname\+\_\+v, Time, G, US, CS, u\+\_\+ptr, v\+\_\+ptr)
\begin{DoxyCompactList}\small\item\em This subroutine stores the reference profile at uand v points for the variable whose address is given by u\+\_\+ptr and v\+\_\+ptr. \end{DoxyCompactList}\item 
subroutine, public \hyperlink{namespacemom__ale__sponge_a1f297a8680a56b92ad1ac4e09f375d05}{apply\+\_\+ale\+\_\+sponge} (h, dt, G, GV, US, CS, Time)
\begin{DoxyCompactList}\small\item\em This subroutine applies damping to the layers thicknesses, temp, salt and a variety of tracers for every column where there is damping. \end{DoxyCompactList}\item 
subroutine, public \hyperlink{namespacemom__ale__sponge_a0c718798e303111ea3110d5ff07bad5c}{rotate\+\_\+ale\+\_\+sponge} (sponge\+\_\+in, G\+\_\+in, sponge, G, turns, param\+\_\+file)
\begin{DoxyCompactList}\small\item\em Rotate the A\+LE sponge fields from the input to the model index map. \end{DoxyCompactList}\item 
subroutine, public \hyperlink{namespacemom__ale__sponge_ab843ab7a29e992d83973c8f9ad6003b1}{update\+\_\+ale\+\_\+sponge\+\_\+field} (sponge, p\+\_\+old, G, GV, p\+\_\+new)
\begin{DoxyCompactList}\small\item\em Scan the A\+LE sponge variables and replace a prescribed pointer to a new value. \end{DoxyCompactList}\item 
subroutine, public \hyperlink{namespacemom__ale__sponge_ada4339e461d4b916fc4585ed6fa1482c}{ale\+\_\+sponge\+\_\+end} (CS)
\begin{DoxyCompactList}\small\item\em This subroutine deallocates any memory associated with the A\+L\+E\+\_\+sponge module. \end{DoxyCompactList}\end{DoxyCompactItemize}


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



This subroutine deallocates any memory associated with the A\+L\+E\+\_\+sponge module. 


\begin{DoxyParams}{Parameters}
{\em cs} & A pointer to the control structure that is set by a previous call to initialize\+\_\+\+A\+L\+E\+\_\+sponge. \\
\hline
\end{DoxyParams}


Definition at line 1169 of file M\+O\+M\+\_\+\+A\+L\+E\+\_\+sponge.\+F90.


\begin{DoxyCode}
1169   \textcolor{keywordtype}{type}(ale\_sponge\_cs), \textcolor{keywordtype}{pointer} :: cs\textcolor{comment}{ !< A pointer to the control structure that is}
1170 \textcolor{comment}{                                     !! set by a previous call to initialize\_ALE\_sponge.}
1171 
1172   \textcolor{keywordtype}{integer} :: m
1173 
1174   \textcolor{keywordflow}{if} (.not.\textcolor{keyword}{associated}(cs)) \textcolor{keywordflow}{return}
1175 
1176   \textcolor{keywordflow}{if} (\textcolor{keyword}{associated}(cs%col\_i)) \textcolor{keyword}{deallocate}(cs%col\_i)
1177   \textcolor{keywordflow}{if} (\textcolor{keyword}{associated}(cs%col\_i\_u)) \textcolor{keyword}{deallocate}(cs%col\_i\_u)
1178   \textcolor{keywordflow}{if} (\textcolor{keyword}{associated}(cs%col\_i\_v)) \textcolor{keyword}{deallocate}(cs%col\_i\_v)
1179   \textcolor{keywordflow}{if} (\textcolor{keyword}{associated}(cs%col\_j)) \textcolor{keyword}{deallocate}(cs%col\_j)
1180   \textcolor{keywordflow}{if} (\textcolor{keyword}{associated}(cs%col\_j\_u)) \textcolor{keyword}{deallocate}(cs%col\_j\_u)
1181   \textcolor{keywordflow}{if} (\textcolor{keyword}{associated}(cs%col\_j\_v)) \textcolor{keyword}{deallocate}(cs%col\_j\_v)
1182 
1183   \textcolor{keywordflow}{if} (\textcolor{keyword}{associated}(cs%Iresttime\_col)) \textcolor{keyword}{deallocate}(cs%Iresttime\_col)
1184   \textcolor{keywordflow}{if} (\textcolor{keyword}{associated}(cs%Iresttime\_col\_u)) \textcolor{keyword}{deallocate}(cs%Iresttime\_col\_u)
1185   \textcolor{keywordflow}{if} (\textcolor{keyword}{associated}(cs%Iresttime\_col\_v)) \textcolor{keyword}{deallocate}(cs%Iresttime\_col\_v)
1186 
1187   \textcolor{keywordflow}{do} m=1,cs%fldno
1188     \textcolor{keywordflow}{if} (\textcolor{keyword}{associated}(cs%Ref\_val(cs%fldno)%p)) \textcolor{keyword}{deallocate}(cs%Ref\_val(cs%fldno)%p)
1189 \textcolor{keywordflow}{  enddo}
1190 
1191   \textcolor{keyword}{deallocate}(cs)
1192 
\end{DoxyCode}
\mbox{\Hypertarget{namespacemom__ale__sponge_a1f297a8680a56b92ad1ac4e09f375d05}\label{namespacemom__ale__sponge_a1f297a8680a56b92ad1ac4e09f375d05}} 
\index{mom\+\_\+ale\+\_\+sponge@{mom\+\_\+ale\+\_\+sponge}!apply\+\_\+ale\+\_\+sponge@{apply\+\_\+ale\+\_\+sponge}}
\index{apply\+\_\+ale\+\_\+sponge@{apply\+\_\+ale\+\_\+sponge}!mom\+\_\+ale\+\_\+sponge@{mom\+\_\+ale\+\_\+sponge}}
\subsubsection{\texorpdfstring{apply\+\_\+ale\+\_\+sponge()}{apply\_ale\_sponge()}}
{\footnotesize\ttfamily subroutine, public mom\+\_\+ale\+\_\+sponge\+::apply\+\_\+ale\+\_\+sponge (\begin{DoxyParamCaption}\item[{real, dimension(szi\+\_\+(g),szj\+\_\+(g),szk\+\_\+(gv)), intent(inout)}]{h,  }\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__ale__sponge_1_1ale__sponge__cs}{ale\+\_\+sponge\+\_\+cs}), pointer}]{CS,  }\item[{type(time\+\_\+type), intent(in), optional}]{Time }\end{DoxyParamCaption})}



This subroutine applies damping to the layers thicknesses, temp, salt and a variety of tracers for every column where there is damping. 


\begin{DoxyParams}[1]{Parameters}
\mbox{\tt in,out}  & {\em g} & The ocean\textquotesingle{}s grid structure (in).\\
\hline
\mbox{\tt in}  & {\em gv} & ocean vertical grid structure\\
\hline
\mbox{\tt in}  & {\em us} & A dimensional unit scaling type\\
\hline
\mbox{\tt in,out}  & {\em h} & Layer thickness \mbox{[}H $\sim$$>$ m or kg m-\/2\mbox{]} (in)\\
\hline
\mbox{\tt in}  & {\em dt} & The amount of time covered by this call \mbox{[}T $\sim$$>$ s\mbox{]}.\\
\hline
 & {\em cs} & A pointer to the control structure for this module that is set by a previous call to initialize\+\_\+\+A\+L\+E\+\_\+sponge (in).\\
\hline
\mbox{\tt in}  & {\em time} & The current model date \\
\hline
\end{DoxyParams}


Definition at line 788 of file M\+O\+M\+\_\+\+A\+L\+E\+\_\+sponge.\+F90.


\begin{DoxyCode}
788   \textcolor{keywordtype}{type}(ocean\_grid\_type),     \textcolor{keywordtype}{intent(inout)} :: g\textcolor{comment}{  !< The ocean's grid structure (in).}
789   \textcolor{keywordtype}{type}(verticalgrid\_type),   \textcolor{keywordtype}{intent(in)}    :: gv\textcolor{comment}{ !< ocean vertical grid structure}
790   \textcolor{keywordtype}{type}(unit\_scale\_type),     \textcolor{keywordtype}{intent(in)}    :: us\textcolor{comment}{ !< A dimensional unit scaling type}
791   \textcolor{keywordtype}{real}, \textcolor{keywordtype}{dimension(SZI\_(G),SZJ\_(G),SZK\_(GV))}, &
792                              \textcolor{keywordtype}{intent(inout)} :: h\textcolor{comment}{  !< Layer thickness [H ~> m or kg m-2] (in)}
793   \textcolor{keywordtype}{real},                      \textcolor{keywordtype}{intent(in)}    :: dt\textcolor{comment}{ !< The amount of time covered by this call [T ~> s].}
794   \textcolor{keywordtype}{type}(ale\_sponge\_cs),       \textcolor{keywordtype}{pointer}       :: cs\textcolor{comment}{ !< A pointer to the control structure for this module}
795 \textcolor{comment}{                                                 !! that is set by a previous call to initialize\_ALE\_sponge
       (in).}
796   \textcolor{keywordtype}{type}(time\_type), \textcolor{keywordtype}{optional}, \textcolor{keywordtype}{intent(in)}    :: time\textcolor{comment}{ !< The current model date}
797 
798   \textcolor{keywordtype}{real} :: damp                                  \textcolor{comment}{! The timestep times the local damping coefficient
       [nondim].}
799   \textcolor{keywordtype}{real} :: i1pdamp                               \textcolor{comment}{! I1pdamp is 1/(1 + damp). [nondim].}
800   \textcolor{keywordtype}{real} :: m\_to\_z                                \textcolor{comment}{! A unit conversion factor from m to Z.}
801   \textcolor{keywordtype}{real}, \textcolor{keywordtype}{allocatable}, \textcolor{keywordtype}{dimension(:)} :: tmp\_val2   \textcolor{comment}{! data values on the original grid}
802   \textcolor{keywordtype}{real}, \textcolor{keywordtype}{dimension(SZK\_(G))} :: tmp\_val1          \textcolor{comment}{! data values remapped to model grid}
803   \textcolor{keywordtype}{real} :: hu(szib\_(g), szj\_(g), szk\_(g))        \textcolor{comment}{! A temporary array for h at u pts}
804   \textcolor{keywordtype}{real} :: hv(szi\_(g), szjb\_(g), szk\_(g))        \textcolor{comment}{! A temporary array for h at v pts}
805   \textcolor{keywordtype}{real}, \textcolor{keywordtype}{allocatable}, \textcolor{keywordtype}{dimension(:,:,:)} :: sp\_val \textcolor{comment}{! A temporary array for fields}
806   \textcolor{keywordtype}{real}, \textcolor{keywordtype}{allocatable}, \textcolor{keywordtype}{dimension(:,:,:)} :: mask\_z \textcolor{comment}{! A temporary array for field mask at h pts}
807   \textcolor{keywordtype}{real}, \textcolor{keywordtype}{dimension(:)}, \textcolor{keywordtype}{allocatable} :: hsrc       \textcolor{comment}{! Source thicknesses [Z ~> m].}
808   \textcolor{comment}{! Local variables for ALE remapping}
809   \textcolor{keywordtype}{real}, \textcolor{keywordtype}{dimension(:)}, \textcolor{keywordtype}{allocatable} :: tmpt1d
810   \textcolor{keywordtype}{integer} :: c, m, nkmb, i, j, k, is, ie, js, je, nz, nz\_data
811   \textcolor{keywordtype}{integer} :: col, total\_sponge\_cols
812   \textcolor{keywordtype}{real}, \textcolor{keywordtype}{allocatable}, \textcolor{keywordtype}{dimension(:)}, \textcolor{keywordtype}{target} :: z\_in, z\_edges\_in
813   \textcolor{keywordtype}{real} :: missing\_value
814   \textcolor{keywordtype}{real} :: h\_neglect, h\_neglect\_edge
815   \textcolor{keywordtype}{real} :: ztopofcell, zbottomofcell \textcolor{comment}{! Heights [Z ~> m].}
816   \textcolor{keywordtype}{integer} :: npoints
817 
818   is = g%isc ; ie = g%iec ; js = g%jsc ; je = g%jec ; nz = g%ke
819   \textcolor{keywordflow}{if} (.not.\textcolor{keyword}{associated}(cs)) \textcolor{keywordflow}{return}
820 
821   \textcolor{keywordflow}{if} (.not.cs%remap\_answers\_2018) \textcolor{keywordflow}{then}
822     h\_neglect = gv%H\_subroundoff ; h\_neglect\_edge = gv%H\_subroundoff
823   \textcolor{keywordflow}{elseif} (gv%Boussinesq) \textcolor{keywordflow}{then}
824     h\_neglect = gv%m\_to\_H*1.0e-30 ; h\_neglect\_edge = gv%m\_to\_H*1.0e-10
825   \textcolor{keywordflow}{else}
826     h\_neglect = gv%kg\_m2\_to\_H*1.0e-30 ; h\_neglect\_edge = gv%kg\_m2\_to\_H*1.0e-10
827 \textcolor{keywordflow}{  endif}
828 
829   \textcolor{keywordflow}{if} (cs%time\_varying\_sponges) \textcolor{keywordflow}{then}
830     \textcolor{keywordflow}{if} (.not. \textcolor{keyword}{present}(time)) &
831       \textcolor{keyword}{call }mom\_error(fatal,\textcolor{stringliteral}{"apply\_ALE\_sponge: No time information provided"})
832     \textcolor{keywordflow}{do} m=1,cs%fldno
833        nz\_data = cs%Ref\_val(m)%nz\_data
834        \textcolor{keyword}{allocate}(sp\_val(g%isd:g%ied,g%jsd:g%jed,1:nz\_data))
835        \textcolor{keyword}{allocate}(mask\_z(g%isd:g%ied,g%jsd:g%jed,1:nz\_data))
836        sp\_val(:,:,:) = 0.0
837        mask\_z(:,:,:) = 0.0
838        \textcolor{keyword}{call }horiz\_interp\_and\_extrap\_tracer(cs%Ref\_val(m)%id, time, 1.0, g, sp\_val, mask\_z, z\_in, &
839                       z\_edges\_in,  missing\_value, .true., .false., .false., &
840                       spongeongrid=cs%SpongeDataOngrid, m\_to\_z=us%m\_to\_Z, &
841                       answers\_2018=cs%hor\_regrid\_answers\_2018)
842        \textcolor{keyword}{allocate}( hsrc(nz\_data) )
843        \textcolor{keyword}{allocate}( tmpt1d(nz\_data) )
844        \textcolor{keywordflow}{do} c=1,cs%num\_col
845           i = cs%col\_i(c) ; j = cs%col\_j(c)
846           cs%Ref\_val(m)%p(1:nz\_data,c) = sp\_val(i,j,1:nz\_data)
847           \textcolor{comment}{! Build the source grid}
848           ztopofcell = 0. ; zbottomofcell = 0. ; npoints = 0; hsrc(:) = 0.0; tmpt1d(:) = -99.9
849           \textcolor{keywordflow}{do} k=1,nz\_data
850              \textcolor{keywordflow}{if} (mask\_z(cs%col\_i(c),cs%col\_j(c),k) == 1.0) \textcolor{keywordflow}{then}
851                 zbottomofcell = -min( z\_edges\_in(k+1), g%bathyT(cs%col\_i(c),cs%col\_j(c)) )
852                 tmpt1d(k) = sp\_val(cs%col\_i(c),cs%col\_j(c),k)
853              \textcolor{keywordflow}{elseif} (k>1) \textcolor{keywordflow}{then}
854                 zbottomofcell = -g%bathyT(cs%col\_i(c),cs%col\_j(c))
855                 tmpt1d(k) = tmpt1d(k-1)
856              \textcolor{keywordflow}{else} \textcolor{comment}{! This next block should only ever be reached over land}
857                 tmpt1d(k) = -99.9
858 \textcolor{keywordflow}{             endif}
859              hsrc(k) = ztopofcell - zbottomofcell
860              \textcolor{keywordflow}{if} (hsrc(k)>0.) npoints = npoints + 1
861              ztopofcell = zbottomofcell \textcolor{comment}{! Bottom becomes top for next value of k}
862 \textcolor{keywordflow}{          enddo}
863           \textcolor{comment}{! In case data is deeper than model}
864           hsrc(nz\_data) = hsrc(nz\_data) + ( ztopofcell + g%bathyT(cs%col\_i(c),cs%col\_j(c)) )
865           cs%Ref\_val(cs%fldno)%h(1:nz\_data,c) = gv%Z\_to\_H*hsrc(1:nz\_data)
866           cs%Ref\_val(cs%fldno)%p(1:nz\_data,c) = tmpt1d(1:nz\_data)
867           \textcolor{keywordflow}{do} k=2,nz\_data
868              \textcolor{comment}{!          if (mask\_z(i,j,k)==0.) &}
869              \textcolor{keywordflow}{if} (cs%Ref\_val(m)%h(k,c) <= 0.001*gv%m\_to\_H) &
870                   \textcolor{comment}{! some confusion here about why the masks are not correct returning from horiz\_interp}
871                   \textcolor{comment}{! reverting to using a minimum thickness criteria}
872                   cs%Ref\_val(m)%p(k,c) = cs%Ref\_val(m)%p(k-1,c)
873 \textcolor{keywordflow}{          enddo}
874 \textcolor{keywordflow}{      enddo}
875       \textcolor{keyword}{deallocate}(sp\_val, mask\_z, hsrc, tmpt1d)
876 \textcolor{keywordflow}{    enddo}
877   \textcolor{keywordflow}{else}
878     nz\_data = cs%nz\_data
879 \textcolor{keywordflow}{  endif}
880 
881   \textcolor{keyword}{allocate}(tmp\_val2(nz\_data))
882   \textcolor{keywordflow}{do} m=1,cs%fldno
883     \textcolor{keywordflow}{do} c=1,cs%num\_col
884 \textcolor{comment}{! c is an index for the next 3 lines but a multiplier for the rest of the loop}
885 \textcolor{comment}{! Therefore we use c as per C code and increment the index where necessary.}
886       i = cs%col\_i(c) ; j = cs%col\_j(c)
887       damp = dt * cs%Iresttime\_col(c)
888       i1pdamp = 1.0 / (1.0 + damp)
889       tmp\_val2(1:nz\_data) = cs%Ref\_val(m)%p(1:nz\_data,c)
890       \textcolor{keywordflow}{if} (cs%time\_varying\_sponges) \textcolor{keywordflow}{then}
891         \textcolor{keyword}{call }remapping\_core\_h(cs%remap\_cs, nz\_data, cs%Ref\_val(m)%h(1:nz\_data,c), tmp\_val2, &
892                               cs%nz, h(i,j,:), tmp\_val1, h\_neglect, h\_neglect\_edge)
893       \textcolor{keywordflow}{else}
894         \textcolor{keyword}{call }remapping\_core\_h(cs%remap\_cs,nz\_data, cs%Ref\_h%p(1:nz\_data,c), tmp\_val2, &
895                               cs%nz, h(i,j,:), tmp\_val1, h\_neglect, h\_neglect\_edge)
896 \textcolor{keywordflow}{      endif}
897       \textcolor{comment}{!Backward Euler method}
898       cs%var(m)%p(i,j,1:cs%nz) = i1pdamp * (cs%var(m)%p(i,j,1:cs%nz) + tmp\_val1 * damp)
899 \textcolor{keywordflow}{    enddo}
900 \textcolor{keywordflow}{  enddo}
901 
902   \textcolor{comment}{! for debugging}
903   \textcolor{comment}{!c=CS%num\_col}
904   \textcolor{comment}{!do m=1,CS%fldno}
905   \textcolor{comment}{!   write(*,*) 'APPLY SPONGE,m,CS%Ref\_h(:,c),h(i,j,:),tmp\_val2,tmp\_val1',&}
906   \textcolor{comment}{!               m,CS%Ref\_h(:,c),h(i,j,:),tmp\_val2,tmp\_val1}
907   \textcolor{comment}{!enddo}
908 
909   \textcolor{keywordflow}{if} (cs%sponge\_uv) \textcolor{keywordflow}{then}
910     \textcolor{comment}{! u points}
911     \textcolor{keywordflow}{do} j=cs%jsc,cs%jec; \textcolor{keywordflow}{do} i=cs%iscB,cs%iecB; \textcolor{keywordflow}{do} k=1,nz
912       hu(i,j,k) = 0.5 * (h(i,j,k) + h(i+1,j,k))
913 \textcolor{keywordflow}{    enddo} ;\textcolor{keywordflow}{ enddo} ;\textcolor{keywordflow}{ enddo}
914     \textcolor{keywordflow}{if} (cs%time\_varying\_sponges) \textcolor{keywordflow}{then}
915       \textcolor{keywordflow}{if} (.not. \textcolor{keyword}{present}(time)) &
916          \textcolor{keyword}{call }mom\_error(fatal,\textcolor{stringliteral}{"apply\_ALE\_sponge: No time information provided"})
917 
918       nz\_data = cs%Ref\_val\_u%nz\_data
919       \textcolor{keyword}{allocate}(sp\_val(g%isdB:g%iedB,g%jsd:g%jed,1:nz\_data))
920       \textcolor{keyword}{allocate}(mask\_z(g%isdB:g%iedB,g%jsd:g%jed,1:nz\_data))
921       \textcolor{comment}{! Interpolate from the external horizontal grid and in time}
922       \textcolor{keyword}{call }horiz\_interp\_and\_extrap\_tracer(cs%Ref\_val\_u%id, time, 1.0, g, sp\_val, mask\_z, z\_in, &
923                                           z\_edges\_in, missing\_value, .true., .false., .false., &
924                                           m\_to\_z=us%m\_to\_Z, answers\_2018=cs%hor\_regrid\_answers\_2018)
925 \textcolor{comment}{!     call pass\_var(sp\_val,G%Domain)}
926 \textcolor{comment}{!     call pass\_var(mask\_z,G%Domain)}
927       \textcolor{keywordflow}{do} c=1,cs%num\_col
928         \textcolor{comment}{! c is an index for the next 3 lines but a multiplier for the rest of the loop}
929         \textcolor{comment}{! Therefore we use c as per C code and increment the index where necessary.}
930         i = cs%col\_i(c) ; j = cs%col\_j(c)
931         cs%Ref\_val\_u%p(1:nz\_data,c) = sp\_val(i,j,1:nz\_data)
932 \textcolor{keywordflow}{      enddo}
933 
934       \textcolor{keyword}{deallocate} (sp\_val, mask\_z)
935 
936       nz\_data = cs%Ref\_val\_v%nz\_data
937       \textcolor{keyword}{allocate}(sp\_val(g%isd:g%ied,g%jsdB:g%jedB,1:nz\_data))
938       \textcolor{keyword}{allocate}(mask\_z(g%isd:g%ied,g%jsdB:g%jedB,1:nz\_data))
939       \textcolor{comment}{! Interpolate from the external horizontal grid and in time}
940       \textcolor{keyword}{call }horiz\_interp\_and\_extrap\_tracer(cs%Ref\_val\_v%id, time, 1.0, g, sp\_val, mask\_z, z\_in, &
941                                           z\_edges\_in, missing\_value, .true., .false., .false., &
942                                           m\_to\_z=us%m\_to\_Z, answers\_2018=cs%hor\_regrid\_answers\_2018)
943 
944 \textcolor{comment}{!     call pass\_var(sp\_val,G%Domain)}
945 \textcolor{comment}{!     call pass\_var(mask\_z,G%Domain)}
946 
947       \textcolor{keywordflow}{do} c=1,cs%num\_col
948         \textcolor{comment}{! c is an index for the next 3 lines but a multiplier for the rest of the loop}
949         \textcolor{comment}{! Therefore we use c as per C code and increment the index where necessary.}
950         i = cs%col\_i(c) ; j = cs%col\_j(c)
951         cs%Ref\_val\_v%p(1:nz\_data,c) = sp\_val(i,j,1:nz\_data)
952 \textcolor{keywordflow}{      enddo}
953 
954       \textcolor{keyword}{deallocate} (sp\_val, mask\_z)
955 
956     \textcolor{keywordflow}{else}
957       nz\_data = cs%nz\_data
958 \textcolor{keywordflow}{    endif}
959 
960     \textcolor{keywordflow}{do} c=1,cs%num\_col\_u
961       i = cs%col\_i\_u(c) ; j = cs%col\_j\_u(c)
962       damp = dt * cs%Iresttime\_col\_u(c)
963       i1pdamp = 1.0 / (1.0 + damp)
964       \textcolor{keywordflow}{if} (cs%time\_varying\_sponges) nz\_data = cs%Ref\_val(m)%nz\_data
965       tmp\_val2(1:nz\_data) = cs%Ref\_val\_u%p(1:nz\_data,c)
966       \textcolor{keywordflow}{if} (cs%time\_varying\_sponges) \textcolor{keywordflow}{then}
967         \textcolor{keyword}{call }remapping\_core\_h(cs%remap\_cs, nz\_data, cs%Ref\_val\_u%h(:,c), tmp\_val2, &
968                  cs%nz, hu(i,j,:), tmp\_val1, h\_neglect, h\_neglect\_edge)
969       \textcolor{keywordflow}{else}
970         \textcolor{keyword}{call }remapping\_core\_h(cs%remap\_cs, nz\_data, cs%Ref\_hu%p(:,c), tmp\_val2, &
971                  cs%nz, hu(i,j,:), tmp\_val1, h\_neglect, h\_neglect\_edge)
972 \textcolor{keywordflow}{      endif}
973       \textcolor{comment}{!Backward Euler method}
974       cs%var\_u%p(i,j,:) = i1pdamp * (cs%var\_u%p(i,j,:) + tmp\_val1 * damp)
975 \textcolor{keywordflow}{    enddo}
976 
977     \textcolor{comment}{! v points}
978     \textcolor{keywordflow}{do} j=cs%jscB,cs%jecB; \textcolor{keywordflow}{do} i=cs%isc,cs%iec; \textcolor{keywordflow}{do} k=1,nz
979       hv(i,j,k) = 0.5 * (h(i,j,k) + h(i,j+1,k))
980 \textcolor{keywordflow}{    enddo} ;\textcolor{keywordflow}{ enddo} ;\textcolor{keywordflow}{ enddo}
981 
982     \textcolor{keywordflow}{do} c=1,cs%num\_col\_v
983       i = cs%col\_i\_v(c) ; j = cs%col\_j\_v(c)
984       damp = dt * cs%Iresttime\_col\_v(c)
985       i1pdamp = 1.0 / (1.0 + damp)
986       tmp\_val2(1:nz\_data) = cs%Ref\_val\_v%p(1:nz\_data,c)
987       \textcolor{keywordflow}{if} (cs%time\_varying\_sponges) \textcolor{keywordflow}{then}
988         \textcolor{keyword}{call }remapping\_core\_h(cs%remap\_cs, cs%nz\_data, cs%Ref\_val\_v%h(:,c), tmp\_val2, &
989                  cs%nz, hv(i,j,:), tmp\_val1, h\_neglect, h\_neglect\_edge)
990       \textcolor{keywordflow}{else}
991         \textcolor{keyword}{call }remapping\_core\_h(cs%remap\_cs, cs%nz\_data, cs%Ref\_hv%p(:,c), tmp\_val2, &
992                  cs%nz, hv(i,j,:), tmp\_val1, h\_neglect, h\_neglect\_edge)
993 \textcolor{keywordflow}{      endif}
994       \textcolor{comment}{!Backward Euler method}
995       cs%var\_v%p(i,j,:) = i1pdamp * (cs%var\_v%p(i,j,:) + tmp\_val1 * damp)
996 \textcolor{keywordflow}{    enddo}
997 
998 \textcolor{keywordflow}{  endif}
999 
1000   \textcolor{keyword}{deallocate}(tmp\_val2)
1001 
\end{DoxyCode}
\mbox{\Hypertarget{namespacemom__ale__sponge_a30b98598d25129c9fbb6e7c4b3480e7a}\label{namespacemom__ale__sponge_a30b98598d25129c9fbb6e7c4b3480e7a}} 
\index{mom\+\_\+ale\+\_\+sponge@{mom\+\_\+ale\+\_\+sponge}!get\+\_\+ale\+\_\+sponge\+\_\+nz\+\_\+data@{get\+\_\+ale\+\_\+sponge\+\_\+nz\+\_\+data}}
\index{get\+\_\+ale\+\_\+sponge\+\_\+nz\+\_\+data@{get\+\_\+ale\+\_\+sponge\+\_\+nz\+\_\+data}!mom\+\_\+ale\+\_\+sponge@{mom\+\_\+ale\+\_\+sponge}}
\subsubsection{\texorpdfstring{get\+\_\+ale\+\_\+sponge\+\_\+nz\+\_\+data()}{get\_ale\_sponge\_nz\_data()}}
{\footnotesize\ttfamily integer function, public mom\+\_\+ale\+\_\+sponge\+::get\+\_\+ale\+\_\+sponge\+\_\+nz\+\_\+data (\begin{DoxyParamCaption}\item[{type(\hyperlink{structmom__ale__sponge_1_1ale__sponge__cs}{ale\+\_\+sponge\+\_\+cs}), pointer}]{CS }\end{DoxyParamCaption})}



Return the number of layers in the data with a fixed A\+LE sponge, or 0 if there are no sponge columns on this PE. 


\begin{DoxyParams}{Parameters}
{\em cs} & A pointer that is set to point to the control structure for the A\+L\+E\+\_\+sponge module.\\
\hline
\end{DoxyParams}
\begin{DoxyReturn}{Returns}
The number of layers in the fixed sponge data. 
\end{DoxyReturn}


Definition at line 347 of file M\+O\+M\+\_\+\+A\+L\+E\+\_\+sponge.\+F90.


\begin{DoxyCode}
347   \textcolor{keywordtype}{type}(ale\_sponge\_cs),   \textcolor{keywordtype}{pointer}       :: cs\textcolor{comment}{ !< A pointer that is set to point to the control}
348 \textcolor{comment}{                                             !! structure for the ALE\_sponge module.}
349   \textcolor{keywordtype}{integer} :: get\_ale\_sponge\_nz\_data\textcolor{comment}{  !< The number of layers in the fixed sponge data.}
350 
351   \textcolor{keywordflow}{if} (\textcolor{keyword}{associated}(cs)) \textcolor{keywordflow}{then}
352     get\_ale\_sponge\_nz\_data = cs%nz\_data
353   \textcolor{keywordflow}{else}
354     get\_ale\_sponge\_nz\_data = 0
355 \textcolor{keywordflow}{  endif}
\end{DoxyCode}
\mbox{\Hypertarget{namespacemom__ale__sponge_a56eb18da6c1d40f6abb544e5b7114293}\label{namespacemom__ale__sponge_a56eb18da6c1d40f6abb544e5b7114293}} 
\index{mom\+\_\+ale\+\_\+sponge@{mom\+\_\+ale\+\_\+sponge}!get\+\_\+ale\+\_\+sponge\+\_\+thicknesses@{get\+\_\+ale\+\_\+sponge\+\_\+thicknesses}}
\index{get\+\_\+ale\+\_\+sponge\+\_\+thicknesses@{get\+\_\+ale\+\_\+sponge\+\_\+thicknesses}!mom\+\_\+ale\+\_\+sponge@{mom\+\_\+ale\+\_\+sponge}}
\subsubsection{\texorpdfstring{get\+\_\+ale\+\_\+sponge\+\_\+thicknesses()}{get\_ale\_sponge\_thicknesses()}}
{\footnotesize\ttfamily subroutine, public mom\+\_\+ale\+\_\+sponge\+::get\+\_\+ale\+\_\+sponge\+\_\+thicknesses (\begin{DoxyParamCaption}\item[{type(ocean\+\_\+grid\+\_\+type), intent(in)}]{G,  }\item[{real, dimension(\+:,\+:,\+:), intent(inout), allocatable}]{data\+\_\+h,  }\item[{logical, dimension(szi\+\_\+(g),szj\+\_\+(g)), intent(out)}]{sponge\+\_\+mask,  }\item[{type(\hyperlink{structmom__ale__sponge_1_1ale__sponge__cs}{ale\+\_\+sponge\+\_\+cs}), pointer}]{CS }\end{DoxyParamCaption})}



Return the thicknesses used for the data with a fixed A\+LE sponge. 


\begin{DoxyParams}[1]{Parameters}
\mbox{\tt in}  & {\em g} & The ocean\textquotesingle{}s grid structure (in).\\
\hline
\mbox{\tt in,out}  & {\em data\+\_\+h} & The thicknesses of the sponge input layers \mbox{[}H $\sim$$>$ m or kg m-\/2\mbox{]}.\\
\hline
\mbox{\tt out}  & {\em sponge\+\_\+mask} & A logical mask that is true where\\
\hline
 & {\em cs} & A pointer that is set to point to the control structure for the A\+L\+E\+\_\+sponge module. \\
\hline
\end{DoxyParams}


Definition at line 360 of file M\+O\+M\+\_\+\+A\+L\+E\+\_\+sponge.\+F90.


\begin{DoxyCode}
360   \textcolor{keywordtype}{type}(ocean\_grid\_type), \textcolor{keywordtype}{intent(in)}    :: g\textcolor{comment}{ !< The ocean's grid structure (in).}
361   \textcolor{keywordtype}{real}, \textcolor{keywordtype}{allocatable}, \textcolor{keywordtype}{dimension(:,:,:)}, &
362                          \textcolor{keywordtype}{intent(inout)} :: data\_h\textcolor{comment}{ !< The thicknesses of the sponge input layers [H ~> m or
       kg m-2].}
363   \textcolor{keywordtype}{logical}, \textcolor{keywordtype}{dimension(SZI\_(G),SZJ\_(G))}, &
364                          \textcolor{keywordtype}{intent(out)}   :: sponge\_mask\textcolor{comment}{ !< A logical mask that is true where}
365 \textcolor{comment}{                                                 !! sponges are being applied.}
366   \textcolor{keywordtype}{type}(ale\_sponge\_cs),   \textcolor{keywordtype}{pointer}       :: cs\textcolor{comment}{ !< A pointer that is set to point to the control}
367 \textcolor{comment}{                                             !! structure for the ALE\_sponge module.}
368   \textcolor{keywordtype}{integer} :: c, i, j, k
369 
370   \textcolor{keywordflow}{if} (\textcolor{keyword}{allocated}(data\_h)) \textcolor{keyword}{call }mom\_error(fatal, &
371     \textcolor{stringliteral}{"get\_ALE\_sponge\_thicknesses called with an allocated data\_h."})
372 
373   \textcolor{keywordflow}{if} (.not.\textcolor{keyword}{associated}(cs)) \textcolor{keywordflow}{then}
374     \textcolor{comment}{! There are no sponge points on this PE.}
375     \textcolor{keyword}{allocate}(data\_h(g%isd:g%ied,g%jsd:g%jed,1)) ; data\_h(:,:,:) = -1.0
376     sponge\_mask(:,:) = .false.
377     \textcolor{keywordflow}{return}
378 \textcolor{keywordflow}{  endif}
379 
380   \textcolor{keyword}{allocate}(data\_h(g%isd:g%ied,g%jsd:g%jed,cs%nz\_data)) ; data\_h(:,:,:) = -1.0
381   sponge\_mask(:,:) = .false.
382 
383   \textcolor{keywordflow}{do} c=1,cs%num\_col
384     i = cs%col\_i(c) ; j = cs%col\_j(c)
385     sponge\_mask(i,j) = .true.
386     \textcolor{keywordflow}{do} k=1,cs%nz\_data
387       data\_h(i,j,k) = cs%Ref\_h%p(k,c)
388 \textcolor{keywordflow}{    enddo}
389 \textcolor{keywordflow}{  enddo}
390 
\end{DoxyCode}
\mbox{\Hypertarget{namespacemom__ale__sponge_aed1ab3e7a8063222f1c9b0d3d2336cbe}\label{namespacemom__ale__sponge_aed1ab3e7a8063222f1c9b0d3d2336cbe}} 
\index{mom\+\_\+ale\+\_\+sponge@{mom\+\_\+ale\+\_\+sponge}!init\+\_\+ale\+\_\+sponge\+\_\+diags@{init\+\_\+ale\+\_\+sponge\+\_\+diags}}
\index{init\+\_\+ale\+\_\+sponge\+\_\+diags@{init\+\_\+ale\+\_\+sponge\+\_\+diags}!mom\+\_\+ale\+\_\+sponge@{mom\+\_\+ale\+\_\+sponge}}
\subsubsection{\texorpdfstring{init\+\_\+ale\+\_\+sponge\+\_\+diags()}{init\_ale\_sponge\_diags()}}
{\footnotesize\ttfamily subroutine, public mom\+\_\+ale\+\_\+sponge\+::init\+\_\+ale\+\_\+sponge\+\_\+diags (\begin{DoxyParamCaption}\item[{type(time\+\_\+type), intent(in), target}]{Time,  }\item[{type(ocean\+\_\+grid\+\_\+type), intent(in)}]{G,  }\item[{type(diag\+\_\+ctrl), intent(inout), target}]{diag,  }\item[{type(\hyperlink{structmom__ale__sponge_1_1ale__sponge__cs}{ale\+\_\+sponge\+\_\+cs}), pointer}]{CS }\end{DoxyParamCaption})}



Initialize diagnostics for the A\+L\+E\+\_\+sponge module. 


\begin{DoxyParams}[1]{Parameters}
\mbox{\tt in}  & {\em time} & The current model time\\
\hline
\mbox{\tt in}  & {\em g} & The ocean\textquotesingle{}s grid structure\\
\hline
\mbox{\tt in,out}  & {\em diag} & A structure that is used to regulate diagnostic output.\\
\hline
 & {\em cs} & A\+LE sponge control structure \\
\hline
\end{DoxyParams}


Definition at line 549 of file M\+O\+M\+\_\+\+A\+L\+E\+\_\+sponge.\+F90.


\begin{DoxyCode}
549   \textcolor{keywordtype}{type}(time\_type), \textcolor{keywordtype}{target}, \textcolor{keywordtype}{intent(in)}    :: time\textcolor{comment}{ !< The current model time}
550   \textcolor{keywordtype}{type}(ocean\_grid\_type),   \textcolor{keywordtype}{intent(in)}    :: g\textcolor{comment}{    !< The ocean's grid structure}
551   \textcolor{keywordtype}{type}(diag\_ctrl), \textcolor{keywordtype}{target}, \textcolor{keywordtype}{intent(inout)} :: diag\textcolor{comment}{ !< A structure that is used to regulate diagnostic}
552 \textcolor{comment}{                                                 !! output.}
553   \textcolor{keywordtype}{type}(ale\_sponge\_cs),     \textcolor{keywordtype}{pointer}       :: cs\textcolor{comment}{   !< ALE sponge control structure}
554 
555   \textcolor{keywordflow}{if} (.not.\textcolor{keyword}{associated}(cs)) \textcolor{keywordflow}{return}
556 
557   cs%diag => diag
558 
\end{DoxyCode}
\mbox{\Hypertarget{namespacemom__ale__sponge_a15129d167423dc162d22ef7cf4742651}\label{namespacemom__ale__sponge_a15129d167423dc162d22ef7cf4742651}} 
\index{mom\+\_\+ale\+\_\+sponge@{mom\+\_\+ale\+\_\+sponge}!initialize\+\_\+ale\+\_\+sponge\+\_\+fixed@{initialize\+\_\+ale\+\_\+sponge\+\_\+fixed}}
\index{initialize\+\_\+ale\+\_\+sponge\+\_\+fixed@{initialize\+\_\+ale\+\_\+sponge\+\_\+fixed}!mom\+\_\+ale\+\_\+sponge@{mom\+\_\+ale\+\_\+sponge}}
\subsubsection{\texorpdfstring{initialize\+\_\+ale\+\_\+sponge\+\_\+fixed()}{initialize\_ale\_sponge\_fixed()}}
{\footnotesize\ttfamily subroutine mom\+\_\+ale\+\_\+sponge\+::initialize\+\_\+ale\+\_\+sponge\+\_\+fixed (\begin{DoxyParamCaption}\item[{real, dimension(szi\+\_\+(g),szj\+\_\+(g)), intent(in)}]{Iresttime,  }\item[{type(ocean\+\_\+grid\+\_\+type), intent(in)}]{G,  }\item[{type(param\+\_\+file\+\_\+type), intent(in)}]{param\+\_\+file,  }\item[{type(\hyperlink{structmom__ale__sponge_1_1ale__sponge__cs}{ale\+\_\+sponge\+\_\+cs}), pointer}]{CS,  }\item[{real, dimension(szi\+\_\+(g),szj\+\_\+(g),nz\+\_\+data), intent(in)}]{data\+\_\+h,  }\item[{integer, intent(in)}]{nz\+\_\+data }\end{DoxyParamCaption})}



This subroutine determines the number of points which are within sponges in this computational domain. Only points that have positive values of Iresttime and which mask2dT indicates are ocean points are included in the sponges. It also stores the target interface heights. 


\begin{DoxyParams}[1]{Parameters}
\mbox{\tt in}  & {\em g} & The ocean\textquotesingle{}s grid structure.\\
\hline
\mbox{\tt in}  & {\em nz\+\_\+data} & The total number of sponge input layers.\\
\hline
\mbox{\tt in}  & {\em iresttime} & The inverse of the restoring time \mbox{[}T-\/1 $\sim$$>$ s-\/1\mbox{]}.\\
\hline
\mbox{\tt in}  & {\em param\+\_\+file} & A structure indicating the open file to parse for model parameter values.\\
\hline
 & {\em cs} & A pointer that is set to point to the control structure for this module (in/out).\\
\hline
\mbox{\tt in}  & {\em data\+\_\+h} & The thicknesses of the sponge input layers \mbox{[}H $\sim$$>$ m or kg m-\/2\mbox{]}. \\
\hline
\end{DoxyParams}


Definition at line 149 of file M\+O\+M\+\_\+\+A\+L\+E\+\_\+sponge.\+F90.


\begin{DoxyCode}
149 
150   \textcolor{keywordtype}{type}(ocean\_grid\_type),            \textcolor{keywordtype}{intent(in)} :: g\textcolor{comment}{ !< The ocean's grid structure.}
151   \textcolor{keywordtype}{integer},                          \textcolor{keywordtype}{intent(in)} :: nz\_data\textcolor{comment}{ !< The total number of sponge input layers.}
152   \textcolor{keywordtype}{real}, \textcolor{keywordtype}{dimension(SZI\_(G),SZJ\_(G))}, \textcolor{keywordtype}{intent(in)} :: iresttime\textcolor{comment}{ !< The inverse of the restoring time [T-1 ~>
       s-1].}
153   \textcolor{keywordtype}{type}(param\_file\_type),            \textcolor{keywordtype}{intent(in)} :: param\_file\textcolor{comment}{ !< A structure indicating the open file}
154 \textcolor{comment}{                                                             !! to parse for model parameter values.}
155   \textcolor{keywordtype}{type}(ale\_sponge\_cs),              \textcolor{keywordtype}{pointer}    :: cs\textcolor{comment}{ !< A pointer that is set to point to the control}
156 \textcolor{comment}{                                                     !! structure for this module (in/out).}
157   \textcolor{keywordtype}{real}, \textcolor{keywordtype}{dimension(SZI\_(G),SZJ\_(G),nz\_data)}, \textcolor{keywordtype}{intent(in)} :: data\_h\textcolor{comment}{ !< The thicknesses of the sponge}
158 \textcolor{comment}{                                                     !! input layers [H ~> m or kg m-2].}
159 
160 
161 \textcolor{comment}{! This include declares and sets the variable "version".}
162 \textcolor{preprocessor}{#include "version\_variable.h"}
163 \textcolor{preprocessor}{}  \textcolor{keywordtype}{character(len=40)}  :: mdl = \textcolor{stringliteral}{"MOM\_sponge"}  \textcolor{comment}{! This module's name.}
164   \textcolor{keywordtype}{logical} :: use\_sponge
165   \textcolor{keywordtype}{real}, \textcolor{keywordtype}{allocatable}, \textcolor{keywordtype}{dimension(:,:,:)} :: data\_hu\textcolor{comment}{ !< thickness at u points [H ~> m or kg m-2]}
166   \textcolor{keywordtype}{real}, \textcolor{keywordtype}{allocatable}, \textcolor{keywordtype}{dimension(:,:,:)} :: data\_hv\textcolor{comment}{ !< thickness at v points [H ~> m or kg m-2]}
167   \textcolor{keywordtype}{real}, \textcolor{keywordtype}{allocatable}, \textcolor{keywordtype}{dimension(:,:)} :: iresttime\_u\textcolor{comment}{ !< inverse of the restoring time at u points [T-1 ~>
       s-1]}
168   \textcolor{keywordtype}{real}, \textcolor{keywordtype}{allocatable}, \textcolor{keywordtype}{dimension(:,:)} :: iresttime\_v\textcolor{comment}{ !< inverse of the restoring time at v points [T-1 ~>
       s-1]}
169   \textcolor{keywordtype}{logical} :: bndextrapolation = .true. \textcolor{comment}{! If true, extrapolate boundaries}
170   \textcolor{keywordtype}{logical} :: default\_2018\_answers
171   \textcolor{keywordtype}{integer} :: i, j, k, col, total\_sponge\_cols, total\_sponge\_cols\_u, total\_sponge\_cols\_v
172   \textcolor{keywordtype}{character(len=10)}  :: remapscheme
173   \textcolor{keywordflow}{if} (\textcolor{keyword}{associated}(cs)) \textcolor{keywordflow}{then}
174     \textcolor{keyword}{call }mom\_error(warning, \textcolor{stringliteral}{"initialize\_ALE\_sponge\_fixed called with an associated "}// &
175                             \textcolor{stringliteral}{"control structure."})
176     \textcolor{keywordflow}{return}
177 \textcolor{keywordflow}{  endif}
178 
179 \textcolor{comment}{! Set default, read and log parameters}
180   \textcolor{keyword}{call }log\_version(param\_file, mdl, version, \textcolor{stringliteral}{""})
181   \textcolor{keyword}{call }get\_param(param\_file, mdl, \textcolor{stringliteral}{"SPONGE"}, use\_sponge, &
182                  \textcolor{stringliteral}{"If true, sponges may be applied anywhere in the domain. "}//&
183                  \textcolor{stringliteral}{"The exact location and properties of those sponges are "}//&
184                  \textcolor{stringliteral}{"specified from MOM\_initialization.F90."}, default=.false.)
185 
186   \textcolor{keywordflow}{if} (.not.use\_sponge) \textcolor{keywordflow}{return}
187 
188   \textcolor{keyword}{allocate}(cs)
189 
190   \textcolor{keyword}{call }get\_param(param\_file, mdl, \textcolor{stringliteral}{"SPONGE\_UV"}, cs%sponge\_uv, &
191                  \textcolor{stringliteral}{"Apply sponges in u and v, in addition to tracers."}, &
192                  default=.false.)
193 
194   \textcolor{keyword}{call }get\_param(param\_file, mdl, \textcolor{stringliteral}{"REMAPPING\_SCHEME"}, remapscheme, &
195                  \textcolor{stringliteral}{"This sets the reconstruction scheme used "}//&
196                  \textcolor{stringliteral}{" for vertical remapping for all variables."}, &
197                  default=\textcolor{stringliteral}{"PLM"}, do\_not\_log=.true.)
198 
199   \textcolor{keyword}{call }get\_param(param\_file, mdl, \textcolor{stringliteral}{"BOUNDARY\_EXTRAPOLATION"}, bndextrapolation, &
200                  \textcolor{stringliteral}{"When defined, a proper high-order reconstruction "}//&
201                  \textcolor{stringliteral}{"scheme is used within boundary cells rather "}//&
202                  \textcolor{stringliteral}{"than PCM. E.g., if PPM is used for remapping, a "}//&
203                  \textcolor{stringliteral}{"PPM reconstruction will also be used within boundary cells."}, &
204                  default=.false., do\_not\_log=.true.)
205   \textcolor{keyword}{call }get\_param(param\_file, mdl, \textcolor{stringliteral}{"DEFAULT\_2018\_ANSWERS"}, default\_2018\_answers, &
206                  \textcolor{stringliteral}{"This sets the default value for the various \_2018\_ANSWERS parameters."}, &
207                  default=.false.)
208   \textcolor{keyword}{call }get\_param(param\_file, mdl, \textcolor{stringliteral}{"REMAPPING\_2018\_ANSWERS"}, cs%remap\_answers\_2018, &
209                  \textcolor{stringliteral}{"If true, use the order of arithmetic and expressions that recover the "}//&
210                  \textcolor{stringliteral}{"answers from the end of 2018.  Otherwise, use updated and more robust "}//&
211                  \textcolor{stringliteral}{"forms of the same expressions."}, default=default\_2018\_answers)
212   \textcolor{keyword}{call }get\_param(param\_file, mdl, \textcolor{stringliteral}{"HOR\_REGRID\_2018\_ANSWERS"}, cs%hor\_regrid\_answers\_2018, &
213                  \textcolor{stringliteral}{"If true, use the order of arithmetic for horizonal regridding that recovers "}//&
214                  \textcolor{stringliteral}{"the answers from the end of 2018.  Otherwise, use rotationally symmetric "}//&
215                  \textcolor{stringliteral}{"forms of the same expressions."}, default=default\_2018\_answers)
216 
217   cs%time\_varying\_sponges = .false.
218   cs%nz = g%ke
219   cs%isc = g%isc ; cs%iec = g%iec ; cs%jsc = g%jsc ; cs%jec = g%jec
220   cs%isd = g%isd ; cs%ied = g%ied ; cs%jsd = g%jsd ; cs%jed = g%jed
221   cs%iscB = g%iscB ; cs%iecB = g%iecB; cs%jscB = g%jscB ; cs%jecB = g%jecB
222 
223   \textcolor{comment}{! number of columns to be restored}
224   cs%num\_col = 0 ; cs%fldno = 0
225   \textcolor{keywordflow}{do} j=g%jsc,g%jec ; \textcolor{keywordflow}{do} i=g%isc,g%iec
226     \textcolor{keywordflow}{if} ((iresttime(i,j)>0.0) .and. (g%mask2dT(i,j)>0)) &
227       cs%num\_col = cs%num\_col + 1
228 \textcolor{keywordflow}{  enddo} ;\textcolor{keywordflow}{ enddo}
229 
230   \textcolor{keywordflow}{if} (cs%num\_col > 0) \textcolor{keywordflow}{then}
231     \textcolor{keyword}{allocate}(cs%Iresttime\_col(cs%num\_col)) ; cs%Iresttime\_col = 0.0
232     \textcolor{keyword}{allocate}(cs%col\_i(cs%num\_col))         ; cs%col\_i = 0
233     \textcolor{keyword}{allocate}(cs%col\_j(cs%num\_col))         ; cs%col\_j = 0
234     \textcolor{comment}{! pass indices, restoring time to the CS structure}
235     col = 1
236     \textcolor{keywordflow}{do} j=g%jsc,g%jec ; \textcolor{keywordflow}{do} i=g%isc,g%iec
237       \textcolor{keywordflow}{if} ((iresttime(i,j)>0.0) .and. (g%mask2dT(i,j)>0)) \textcolor{keywordflow}{then}
238         cs%col\_i(col) = i ; cs%col\_j(col) = j
239         cs%Iresttime\_col(col) = iresttime(i,j)
240         col = col +1
241 \textcolor{keywordflow}{      endif}
242 \textcolor{keywordflow}{    enddo} ;\textcolor{keywordflow}{ enddo}
243     \textcolor{comment}{! same for total number of arbritary layers and correspondent data}
244     cs%nz\_data = nz\_data
245     \textcolor{keyword}{allocate}(cs%Ref\_h%p(cs%nz\_data,cs%num\_col))
246     \textcolor{keywordflow}{do} col=1,cs%num\_col ; \textcolor{keywordflow}{do} k=1,cs%nz\_data
247       cs%Ref\_h%p(k,col) = data\_h(cs%col\_i(col),cs%col\_j(col),k)
248 \textcolor{keywordflow}{    enddo} ;\textcolor{keywordflow}{ enddo}
249 \textcolor{keywordflow}{  endif}
250 
251   total\_sponge\_cols = cs%num\_col
252   \textcolor{keyword}{call }sum\_across\_pes(total\_sponge\_cols)
253 
254 \textcolor{comment}{! Call the constructor for remapping control structure}
255   \textcolor{keyword}{call }initialize\_remapping(cs%remap\_cs, remapscheme, boundary\_extrapolation=bndextrapolation, &
256                             answers\_2018=cs%remap\_answers\_2018)
257 
258   \textcolor{keyword}{call }log\_param(param\_file, mdl, \textcolor{stringliteral}{"!Total sponge columns at h points"}, total\_sponge\_cols, &
259                  \textcolor{stringliteral}{"The total number of columns where sponges are applied at h points."}, like\_default=.true.)
260 
261   \textcolor{keywordflow}{if} (cs%sponge\_uv) \textcolor{keywordflow}{then}
262 
263     \textcolor{keyword}{allocate}(data\_hu(g%isdB:g%iedB,g%jsd:g%jed,nz\_data)) ; data\_hu(:,:,:) = 0.0
264     \textcolor{keyword}{allocate}(data\_hv(g%isd:g%ied,g%jsdB:g%jedB,nz\_data)) ; data\_hv(:,:,:) = 0.0
265     \textcolor{keyword}{allocate}(iresttime\_u(g%isdB:g%iedB,g%jsd:g%jed)) ; iresttime\_u(:,:) = 0.0
266     \textcolor{keyword}{allocate}(iresttime\_v(g%isd:g%ied,g%jsdB:g%jedB)) ; iresttime\_v(:,:) = 0.0
267 
268     \textcolor{comment}{! u points}
269     cs%num\_col\_u = 0 ; \textcolor{comment}{!CS%fldno\_u = 0}
270     \textcolor{keywordflow}{do} j=cs%jsc,cs%jec ; \textcolor{keywordflow}{do} i=cs%iscB,cs%iecB
271        data\_hu(i,j,:) = 0.5 * (data\_h(i,j,:) + data\_h(i+1,j,:))
272        iresttime\_u(i,j) = 0.5 * (iresttime(i,j) + iresttime(i+1,j))
273        \textcolor{keywordflow}{if} ((iresttime\_u(i,j)>0.0) .and. (g%mask2dCu(i,j)>0)) &
274           cs%num\_col\_u = cs%num\_col\_u + 1
275 \textcolor{keywordflow}{    enddo} ;\textcolor{keywordflow}{ enddo}
276 
277     \textcolor{keywordflow}{if} (cs%num\_col\_u > 0) \textcolor{keywordflow}{then}
278 
279        \textcolor{keyword}{allocate}(cs%Iresttime\_col\_u(cs%num\_col\_u)) ; cs%Iresttime\_col\_u(:) = 0.0
280        \textcolor{keyword}{allocate}(cs%col\_i\_u(cs%num\_col\_u))         ; cs%col\_i\_u(:) = 0
281        \textcolor{keyword}{allocate}(cs%col\_j\_u(cs%num\_col\_u))         ; cs%col\_j\_u(:) = 0
282 
283        \textcolor{comment}{! pass indices, restoring time to the CS structure}
284        col = 1
285        \textcolor{keywordflow}{do} j=cs%jsc,cs%jec ; \textcolor{keywordflow}{do} i=cs%iscB,cs%iecB
286          \textcolor{keywordflow}{if} ((iresttime\_u(i,j)>0.0) .and. (g%mask2dCu(i,j)>0)) \textcolor{keywordflow}{then}
287            cs%col\_i\_u(col) = i ; cs%col\_j\_u(col) = j
288            cs%Iresttime\_col\_u(col) = iresttime\_u(i,j)
289            col = col + 1
290 \textcolor{keywordflow}{         endif}
291 \textcolor{keywordflow}{       enddo} ;\textcolor{keywordflow}{ enddo}
292 
293        \textcolor{comment}{! same for total number of arbritary layers and correspondent data}
294 
295        \textcolor{keyword}{allocate}(cs%Ref\_hu%p(cs%nz\_data,cs%num\_col\_u))
296        \textcolor{keywordflow}{do} col=1,cs%num\_col\_u ; \textcolor{keywordflow}{do} k=1,cs%nz\_data
297          cs%Ref\_hu%p(k,col) = data\_hu(cs%col\_i\_u(col),cs%col\_j\_u(col),k)
298 \textcolor{keywordflow}{       enddo} ;\textcolor{keywordflow}{ enddo}
299 \textcolor{keywordflow}{    endif}
300     total\_sponge\_cols\_u = cs%num\_col\_u
301     \textcolor{keyword}{call }sum\_across\_pes(total\_sponge\_cols\_u)
302     \textcolor{keyword}{call }log\_param(param\_file, mdl, \textcolor{stringliteral}{"!Total sponge columns at u points"}, total\_sponge\_cols\_u, &
303                 \textcolor{stringliteral}{"The total number of columns where sponges are applied at u points."}, like\_default=.true.)
304 
305     \textcolor{comment}{! v points}
306     cs%num\_col\_v = 0 ; \textcolor{comment}{!CS%fldno\_v = 0}
307     \textcolor{keywordflow}{do} j=cs%jscB,cs%jecB; \textcolor{keywordflow}{do} i=cs%isc,cs%iec
308       data\_hv(i,j,:) = 0.5 * (data\_h(i,j,:) + data\_h(i,j+1,:))
309       iresttime\_v(i,j) = 0.5 * (iresttime(i,j) + iresttime(i,j+1))
310       \textcolor{keywordflow}{if} ((iresttime\_v(i,j)>0.0) .and. (g%mask2dCv(i,j)>0)) &
311         cs%num\_col\_v = cs%num\_col\_v + 1
312 \textcolor{keywordflow}{    enddo} ;\textcolor{keywordflow}{ enddo}
313 
314     \textcolor{keywordflow}{if} (cs%num\_col\_v > 0) \textcolor{keywordflow}{then}
315 
316       \textcolor{keyword}{allocate}(cs%Iresttime\_col\_v(cs%num\_col\_v)) ; cs%Iresttime\_col\_v = 0.0
317       \textcolor{keyword}{allocate}(cs%col\_i\_v(cs%num\_col\_v))         ; cs%col\_i\_v = 0
318       \textcolor{keyword}{allocate}(cs%col\_j\_v(cs%num\_col\_v))         ; cs%col\_j\_v = 0
319 
320       \textcolor{comment}{! pass indices, restoring time to the CS structure}
321       col = 1
322       \textcolor{keywordflow}{do} j=cs%jscB,cs%jecB ; \textcolor{keywordflow}{do} i=cs%isc,cs%iec
323         \textcolor{keywordflow}{if} ((iresttime\_v(i,j)>0.0) .and. (g%mask2dCv(i,j)>0)) \textcolor{keywordflow}{then}
324           cs%col\_i\_v(col) = i ; cs%col\_j\_v(col) = j
325           cs%Iresttime\_col\_v(col) = iresttime\_v(i,j)
326           col = col + 1
327 \textcolor{keywordflow}{        endif}
328 \textcolor{keywordflow}{      enddo} ;\textcolor{keywordflow}{ enddo}
329 
330       \textcolor{comment}{! same for total number of arbritary layers and correspondent data}
331       \textcolor{keyword}{allocate}(cs%Ref\_hv%p(cs%nz\_data,cs%num\_col\_v))
332       \textcolor{keywordflow}{do} col=1,cs%num\_col\_v ; \textcolor{keywordflow}{do} k=1,cs%nz\_data
333         cs%Ref\_hv%p(k,col) = data\_hv(cs%col\_i\_v(col),cs%col\_j\_v(col),k)
334 \textcolor{keywordflow}{      enddo} ;\textcolor{keywordflow}{ enddo}
335 \textcolor{keywordflow}{    endif}
336     total\_sponge\_cols\_v = cs%num\_col\_v
337     \textcolor{keyword}{call }sum\_across\_pes(total\_sponge\_cols\_v)
338     \textcolor{keyword}{call }log\_param(param\_file, mdl, \textcolor{stringliteral}{"!Total sponge columns at v points"}, total\_sponge\_cols\_v, &
339                  \textcolor{stringliteral}{"The total number of columns where sponges are applied at v points."}, like\_default=.true.)
340 \textcolor{keywordflow}{  endif}
341 
\end{DoxyCode}
\mbox{\Hypertarget{namespacemom__ale__sponge_a0febb96fb2fd40a72580d078ca023098}\label{namespacemom__ale__sponge_a0febb96fb2fd40a72580d078ca023098}} 
\index{mom\+\_\+ale\+\_\+sponge@{mom\+\_\+ale\+\_\+sponge}!initialize\+\_\+ale\+\_\+sponge\+\_\+varying@{initialize\+\_\+ale\+\_\+sponge\+\_\+varying}}
\index{initialize\+\_\+ale\+\_\+sponge\+\_\+varying@{initialize\+\_\+ale\+\_\+sponge\+\_\+varying}!mom\+\_\+ale\+\_\+sponge@{mom\+\_\+ale\+\_\+sponge}}
\subsubsection{\texorpdfstring{initialize\+\_\+ale\+\_\+sponge\+\_\+varying()}{initialize\_ale\_sponge\_varying()}}
{\footnotesize\ttfamily subroutine mom\+\_\+ale\+\_\+sponge\+::initialize\+\_\+ale\+\_\+sponge\+\_\+varying (\begin{DoxyParamCaption}\item[{real, dimension( g \%isd\+: g \%ied, g \%jsd\+: g \%jed), intent(in)}]{Iresttime,  }\item[{type(ocean\+\_\+grid\+\_\+type), intent(in)}]{G,  }\item[{type(param\+\_\+file\+\_\+type), intent(in)}]{param\+\_\+file,  }\item[{type(\hyperlink{structmom__ale__sponge_1_1ale__sponge__cs}{ale\+\_\+sponge\+\_\+cs}), pointer}]{CS }\end{DoxyParamCaption})\hspace{0.3cm}{\ttfamily [private]}}



This subroutine determines the number of points which are to be restoref in the computational domain. Only points that have positive values of Iresttime and which mask2dT indicates are ocean points are included in the sponges. 


\begin{DoxyParams}[1]{Parameters}
\mbox{\tt in}  & {\em g} & The ocean\textquotesingle{}s grid structure.\\
\hline
\mbox{\tt in}  & {\em iresttime} & The inverse of the restoring time \mbox{[}T-\/1 $\sim$$>$ s-\/1\mbox{]}.\\
\hline
\mbox{\tt in}  & {\em param\+\_\+file} & A structure indicating the open file to parse for model parameter values.\\
\hline
 & {\em cs} & A pointer that is set to point to the control structure for this module (in/out). \\
\hline
\end{DoxyParams}


Definition at line 397 of file M\+O\+M\+\_\+\+A\+L\+E\+\_\+sponge.\+F90.


\begin{DoxyCode}
397 
398   \textcolor{keywordtype}{type}(ocean\_grid\_type),            \textcolor{keywordtype}{intent(in)} :: g\textcolor{comment}{ !< The ocean's grid structure.}
399   \textcolor{keywordtype}{real}, \textcolor{keywordtype}{dimension(SZI\_(G),SZJ\_(G))}, \textcolor{keywordtype}{intent(in)} :: iresttime\textcolor{comment}{ !< The inverse of the restoring time [T-1 ~>
       s-1].}
400   \textcolor{keywordtype}{type}(param\_file\_type),            \textcolor{keywordtype}{intent(in)} :: param\_file\textcolor{comment}{ !< A structure indicating the open file to
       parse}
401 \textcolor{comment}{                                                             !! for model parameter values.}
402   \textcolor{keywordtype}{type}(ale\_sponge\_cs),              \textcolor{keywordtype}{pointer}    :: cs\textcolor{comment}{ !< A pointer that is set to point to the control}
403 \textcolor{comment}{                                                     !! structure for this module (in/out).}
404 
405 \textcolor{comment}{! This include declares and sets the variable "version".}
406 \textcolor{preprocessor}{#include "version\_variable.h"}
407 \textcolor{preprocessor}{}  \textcolor{keywordtype}{character(len=40)}  :: mdl = \textcolor{stringliteral}{"MOM\_sponge"}  \textcolor{comment}{! This module's name.}
408   \textcolor{keywordtype}{logical} :: use\_sponge
409     \textcolor{keywordtype}{real}, \textcolor{keywordtype}{allocatable}, \textcolor{keywordtype}{dimension(:,:)} :: iresttime\_u\textcolor{comment}{ !< inverse of the restoring time at u points [T-1 ~>
       s-1]}
410   \textcolor{keywordtype}{real}, \textcolor{keywordtype}{allocatable}, \textcolor{keywordtype}{dimension(:,:)} :: iresttime\_v\textcolor{comment}{ !< inverse of the restoring time at v points [T-1 ~>
       s-1]}
411   \textcolor{keywordtype}{logical} :: bndextrapolation = .true. \textcolor{comment}{! If true, extrapolate boundaries}
412   \textcolor{keywordtype}{logical} :: default\_2018\_answers
413   \textcolor{keywordtype}{logical} :: spongedataongrid = .false.
414   \textcolor{keywordtype}{integer} :: i, j, k, col, total\_sponge\_cols, total\_sponge\_cols\_u, total\_sponge\_cols\_v
415   \textcolor{keywordtype}{character(len=10)}  :: remapscheme
416 
417   \textcolor{keywordflow}{if} (\textcolor{keyword}{associated}(cs)) \textcolor{keywordflow}{then}
418     \textcolor{keyword}{call }mom\_error(warning, \textcolor{stringliteral}{"initialize\_ALE\_sponge\_varying called with an associated "}// &
419                             \textcolor{stringliteral}{"control structure."})
420     \textcolor{keywordflow}{return}
421 \textcolor{keywordflow}{  endif}
422 \textcolor{comment}{! Set default, read and log parameters}
423   \textcolor{keyword}{call }log\_version(param\_file, mdl, version, \textcolor{stringliteral}{""})
424   \textcolor{keyword}{call }get\_param(param\_file, mdl, \textcolor{stringliteral}{"SPONGE"}, use\_sponge, &
425                  \textcolor{stringliteral}{"If true, sponges may be applied anywhere in the domain. "}//&
426                  \textcolor{stringliteral}{"The exact location and properties of those sponges are "}//&
427                  \textcolor{stringliteral}{"specified from MOM\_initialization.F90."}, default=.false.)
428   \textcolor{keywordflow}{if} (.not.use\_sponge) \textcolor{keywordflow}{return}
429   \textcolor{keyword}{allocate}(cs)
430   \textcolor{keyword}{call }get\_param(param\_file, mdl, \textcolor{stringliteral}{"SPONGE\_UV"}, cs%sponge\_uv, &
431                  \textcolor{stringliteral}{"Apply sponges in u and v, in addition to tracers."}, &
432                  default=.false.)
433   \textcolor{keyword}{call }get\_param(param\_file, mdl, \textcolor{stringliteral}{"REMAPPING\_SCHEME"}, remapscheme, &
434                  \textcolor{stringliteral}{"This sets the reconstruction scheme used "}//&
435                  \textcolor{stringliteral}{" for vertical remapping for all variables."}, &
436                  default=\textcolor{stringliteral}{"PLM"}, do\_not\_log=.true.)
437   \textcolor{keyword}{call }get\_param(param\_file, mdl, \textcolor{stringliteral}{"BOUNDARY\_EXTRAPOLATION"}, bndextrapolation, &
438                  \textcolor{stringliteral}{"When defined, a proper high-order reconstruction "}//&
439                  \textcolor{stringliteral}{"scheme is used within boundary cells rather "}//&
440                  \textcolor{stringliteral}{"than PCM. E.g., if PPM is used for remapping, a "}//&
441                  \textcolor{stringliteral}{"PPM reconstruction will also be used within boundary cells."}, &
442                  default=.false., do\_not\_log=.true.)
443   \textcolor{keyword}{call }get\_param(param\_file, mdl, \textcolor{stringliteral}{"DEFAULT\_2018\_ANSWERS"}, default\_2018\_answers, &
444                  \textcolor{stringliteral}{"This sets the default value for the various \_2018\_ANSWERS parameters."}, &
445                  default=.false.)
446   \textcolor{keyword}{call }get\_param(param\_file, mdl, \textcolor{stringliteral}{"REMAPPING\_2018\_ANSWERS"}, cs%remap\_answers\_2018, &
447                  \textcolor{stringliteral}{"If true, use the order of arithmetic and expressions that recover the "}//&
448                  \textcolor{stringliteral}{"answers from the end of 2018.  Otherwise, use updated and more robust "}//&
449                  \textcolor{stringliteral}{"forms of the same expressions."}, default=default\_2018\_answers)
450   \textcolor{keyword}{call }get\_param(param\_file, mdl, \textcolor{stringliteral}{"SPONGE\_DATA\_ONGRID"}, cs%spongeDataOngrid, &
451                  \textcolor{stringliteral}{"When defined, the incoming sponge data are "}//&
452                  \textcolor{stringliteral}{"assumed to be on the model grid "} , &
453                  default=.false.)
454   cs%time\_varying\_sponges = .true.
455   cs%nz = g%ke
456   cs%isc = g%isc ; cs%iec = g%iec ; cs%jsc = g%jsc ; cs%jec = g%jec
457   cs%isd = g%isd ; cs%ied = g%ied ; cs%jsd = g%jsd ; cs%jed = g%jed
458   cs%iscB = g%iscB ; cs%iecB = g%iecB; cs%jscB = g%jscB ; cs%jecB = g%jecB
459 
460   \textcolor{comment}{! number of columns to be restored}
461   cs%num\_col = 0 ; cs%fldno = 0
462   \textcolor{keywordflow}{do} j=g%jsc,g%jec ; \textcolor{keywordflow}{do} i=g%isc,g%iec
463     \textcolor{keywordflow}{if} ((iresttime(i,j)>0.0) .and. (g%mask2dT(i,j)>0)) &
464       cs%num\_col = cs%num\_col + 1
465 \textcolor{keywordflow}{  enddo} ;\textcolor{keywordflow}{ enddo}
466   \textcolor{keywordflow}{if} (cs%num\_col > 0) \textcolor{keywordflow}{then}
467     \textcolor{keyword}{allocate}(cs%Iresttime\_col(cs%num\_col)) ; cs%Iresttime\_col = 0.0
468     \textcolor{keyword}{allocate}(cs%col\_i(cs%num\_col))         ; cs%col\_i = 0
469     \textcolor{keyword}{allocate}(cs%col\_j(cs%num\_col))         ; cs%col\_j = 0
470     \textcolor{comment}{! pass indices, restoring time to the CS structure}
471     col = 1
472     \textcolor{keywordflow}{do} j=g%jsc,g%jec ; \textcolor{keywordflow}{do} i=g%isc,g%iec
473       \textcolor{keywordflow}{if} ((iresttime(i,j)>0.0) .and. (g%mask2dT(i,j)>0)) \textcolor{keywordflow}{then}
474         cs%col\_i(col) = i ; cs%col\_j(col) = j
475         cs%Iresttime\_col(col) = iresttime(i,j)
476         col = col +1
477 \textcolor{keywordflow}{      endif}
478 \textcolor{keywordflow}{    enddo} ;\textcolor{keywordflow}{ enddo}
479 \textcolor{keywordflow}{  endif}
480   total\_sponge\_cols = cs%num\_col
481   \textcolor{keyword}{call }sum\_across\_pes(total\_sponge\_cols)
482 
483 \textcolor{comment}{! Call the constructor for remapping control structure}
484   \textcolor{keyword}{call }initialize\_remapping(cs%remap\_cs, remapscheme, boundary\_extrapolation=bndextrapolation, &
485                             answers\_2018=cs%remap\_answers\_2018)
486   \textcolor{keyword}{call }log\_param(param\_file, mdl, \textcolor{stringliteral}{"!Total sponge columns at h points"}, total\_sponge\_cols, &
487                  \textcolor{stringliteral}{"The total number of columns where sponges are applied at h points."}, like\_default=.true.)
488   \textcolor{keywordflow}{if} (cs%sponge\_uv) \textcolor{keywordflow}{then}
489     \textcolor{keyword}{allocate}(iresttime\_u(g%isdB:g%iedB,g%jsd:g%jed)) ; iresttime\_u(:,:) = 0.0
490     \textcolor{keyword}{allocate}(iresttime\_v(g%isd:g%ied,g%jsdB:g%jedB)) ; iresttime\_v(:,:) = 0.0
491     \textcolor{comment}{! u points}
492     cs%num\_col\_u = 0 ; \textcolor{comment}{!CS%fldno\_u = 0}
493     \textcolor{keywordflow}{do} j=cs%jsc,cs%jec; \textcolor{keywordflow}{do} i=cs%iscB,cs%iecB
494       iresttime\_u(i,j) = 0.5 * (iresttime(i,j) + iresttime(i+1,j))
495       \textcolor{keywordflow}{if} ((iresttime\_u(i,j)>0.0) .and. (g%mask2dCu(i,j)>0)) &
496         cs%num\_col\_u = cs%num\_col\_u + 1
497 \textcolor{keywordflow}{    enddo} ;\textcolor{keywordflow}{ enddo}
498     \textcolor{keywordflow}{if} (cs%num\_col\_u > 0) \textcolor{keywordflow}{then}
499       \textcolor{keyword}{allocate}(cs%Iresttime\_col\_u(cs%num\_col\_u)) ; cs%Iresttime\_col\_u = 0.0
500       \textcolor{keyword}{allocate}(cs%col\_i\_u(cs%num\_col\_u))         ; cs%col\_i\_u = 0
501       \textcolor{keyword}{allocate}(cs%col\_j\_u(cs%num\_col\_u))         ; cs%col\_j\_u = 0
502       \textcolor{comment}{! pass indices, restoring time to the CS structure}
503       col = 1
504       \textcolor{keywordflow}{do} j=cs%jsc,cs%jec ; \textcolor{keywordflow}{do} i=cs%iscB,cs%iecB
505         \textcolor{keywordflow}{if} ((iresttime\_u(i,j)>0.0) .and. (g%mask2dCu(i,j)>0)) \textcolor{keywordflow}{then}
506           cs%col\_i\_u(col) = i ; cs%col\_j\_u(col) = j
507           cs%Iresttime\_col\_u(col) = iresttime\_u(i,j)
508           col = col +1
509 \textcolor{keywordflow}{        endif}
510 \textcolor{keywordflow}{      enddo} ;\textcolor{keywordflow}{ enddo}
511       \textcolor{comment}{! same for total number of arbritary layers and correspondent data}
512 \textcolor{keywordflow}{    endif}
513     total\_sponge\_cols\_u = cs%num\_col\_u
514     \textcolor{keyword}{call }sum\_across\_pes(total\_sponge\_cols\_u)
515     \textcolor{keyword}{call }log\_param(param\_file, mdl, \textcolor{stringliteral}{"!Total sponge columns at u points"}, total\_sponge\_cols\_u, &
516                 \textcolor{stringliteral}{"The total number of columns where sponges are applied at u points."}, like\_default=.true.)
517     \textcolor{comment}{! v points}
518     cs%num\_col\_v = 0 ; \textcolor{comment}{!CS%fldno\_v = 0}
519     \textcolor{keywordflow}{do} j=cs%jscB,cs%jecB; \textcolor{keywordflow}{do} i=cs%isc,cs%iec
520       iresttime\_v(i,j) = 0.5 * (iresttime(i,j) + iresttime(i,j+1))
521       \textcolor{keywordflow}{if} ((iresttime\_v(i,j)>0.0) .and. (g%mask2dCv(i,j)>0)) &
522         cs%num\_col\_v = cs%num\_col\_v + 1
523 \textcolor{keywordflow}{    enddo} ;\textcolor{keywordflow}{ enddo}
524     \textcolor{keywordflow}{if} (cs%num\_col\_v > 0) \textcolor{keywordflow}{then}
525       \textcolor{keyword}{allocate}(cs%Iresttime\_col\_v(cs%num\_col\_v)) ; cs%Iresttime\_col\_v = 0.0
526       \textcolor{keyword}{allocate}(cs%col\_i\_v(cs%num\_col\_v))         ; cs%col\_i\_v = 0
527       \textcolor{keyword}{allocate}(cs%col\_j\_v(cs%num\_col\_v))         ; cs%col\_j\_v = 0
528       \textcolor{comment}{! pass indices, restoring time to the CS structure}
529       col = 1
530       \textcolor{keywordflow}{do} j=cs%jscB,cs%jecB ; \textcolor{keywordflow}{do} i=cs%isc,cs%iec
531         \textcolor{keywordflow}{if} ((iresttime\_v(i,j)>0.0) .and. (g%mask2dCv(i,j)>0)) \textcolor{keywordflow}{then}
532           cs%col\_i\_v(col) = i ; cs%col\_j\_v(col) = j
533           cs%Iresttime\_col\_v(col) = iresttime\_v(i,j)
534           col = col +1
535 \textcolor{keywordflow}{        endif}
536 \textcolor{keywordflow}{      enddo} ;\textcolor{keywordflow}{ enddo}
537 \textcolor{keywordflow}{    endif}
538     total\_sponge\_cols\_v = cs%num\_col\_v
539     \textcolor{keyword}{call }sum\_across\_pes(total\_sponge\_cols\_v)
540     \textcolor{keyword}{call }log\_param(param\_file, mdl, \textcolor{stringliteral}{"!Total sponge columns at v points"}, total\_sponge\_cols\_v, &
541                 \textcolor{stringliteral}{"The total number of columns where sponges are applied at v points."}, like\_default=.true.)
542 \textcolor{keywordflow}{  endif}
543 
\end{DoxyCode}
\mbox{\Hypertarget{namespacemom__ale__sponge_a0c718798e303111ea3110d5ff07bad5c}\label{namespacemom__ale__sponge_a0c718798e303111ea3110d5ff07bad5c}} 
\index{mom\+\_\+ale\+\_\+sponge@{mom\+\_\+ale\+\_\+sponge}!rotate\+\_\+ale\+\_\+sponge@{rotate\+\_\+ale\+\_\+sponge}}
\index{rotate\+\_\+ale\+\_\+sponge@{rotate\+\_\+ale\+\_\+sponge}!mom\+\_\+ale\+\_\+sponge@{mom\+\_\+ale\+\_\+sponge}}
\subsubsection{\texorpdfstring{rotate\+\_\+ale\+\_\+sponge()}{rotate\_ale\_sponge()}}
{\footnotesize\ttfamily subroutine, public mom\+\_\+ale\+\_\+sponge\+::rotate\+\_\+ale\+\_\+sponge (\begin{DoxyParamCaption}\item[{type(\hyperlink{structmom__ale__sponge_1_1ale__sponge__cs}{ale\+\_\+sponge\+\_\+cs}), intent(in)}]{sponge\+\_\+in,  }\item[{type(ocean\+\_\+grid\+\_\+type), intent(in)}]{G\+\_\+in,  }\item[{type(\hyperlink{structmom__ale__sponge_1_1ale__sponge__cs}{ale\+\_\+sponge\+\_\+cs}), pointer}]{sponge,  }\item[{type(ocean\+\_\+grid\+\_\+type), intent(in)}]{G,  }\item[{integer, intent(in)}]{turns,  }\item[{type(param\+\_\+file\+\_\+type), intent(in)}]{param\+\_\+file }\end{DoxyParamCaption})}



Rotate the A\+LE sponge fields from the input to the model index map. 


\begin{DoxyParams}[1]{Parameters}
\mbox{\tt in}  & {\em sponge\+\_\+in} & The control structure for this module with the original grid rotation\\
\hline
\mbox{\tt in}  & {\em g\+\_\+in} & The ocean\textquotesingle{}s grid structure with the original rotation.\\
\hline
 & {\em sponge} & A pointer to the control that will be set up with the new grid rotation\\
\hline
\mbox{\tt in}  & {\em g} & The ocean\textquotesingle{}s grid structure with the new rotation.\\
\hline
\mbox{\tt in}  & {\em turns} & The number of 90-\/degree turns between grids\\
\hline
\mbox{\tt in}  & {\em param\+\_\+file} & A structure indicating the open file to parse for model parameter values. \\
\hline
\end{DoxyParams}


Definition at line 1006 of file M\+O\+M\+\_\+\+A\+L\+E\+\_\+sponge.\+F90.


\begin{DoxyCode}
1006   \textcolor{keywordtype}{type}(ale\_sponge\_cs),   \textcolor{keywordtype}{intent(in)} :: sponge\_in\textcolor{comment}{ !< The control structure for this module with the}
1007 \textcolor{comment}{                                                 !! original grid rotation}
1008   \textcolor{keywordtype}{type}(ocean\_grid\_type), \textcolor{keywordtype}{intent(in)} :: g\_in\textcolor{comment}{      !< The ocean's grid structure with the original rotation.}
1009   \textcolor{keywordtype}{type}(ale\_sponge\_cs),   \textcolor{keywordtype}{pointer}    :: sponge\textcolor{comment}{    !< A pointer to the control that will be set up with}
1010 \textcolor{comment}{                                                 !! the new grid rotation}
1011   \textcolor{keywordtype}{type}(ocean\_grid\_type), \textcolor{keywordtype}{intent(in)} :: g\textcolor{comment}{         !< The ocean's grid structure with the new rotation.}
1012   \textcolor{keywordtype}{integer},               \textcolor{keywordtype}{intent(in)} :: turns\textcolor{comment}{     !< The number of 90-degree turns between grids}
1013   \textcolor{keywordtype}{type}(param\_file\_type), \textcolor{keywordtype}{intent(in)} :: param\_file\textcolor{comment}{ !< A structure indicating the open file}
1014 \textcolor{comment}{                                                 !! to parse for model parameter values.}
1015 
1016   \textcolor{comment}{! First part: Index construction}
1017   \textcolor{comment}{!   1. Reconstruct Iresttime(:,:) from sponge\_in}
1018   \textcolor{comment}{!   2. rotate Iresttime(:,:)}
1019   \textcolor{comment}{!   3. Call initialize\_ALE\_sponge using new grid and rotated Iresttime(:,:)}
1020   \textcolor{comment}{! All the index adjustment should follow from the Iresttime rotation}
1021 
1022   \textcolor{keywordtype}{real}, \textcolor{keywordtype}{dimension(:,:)}, \textcolor{keywordtype}{allocatable} :: iresttime\_in, iresttime
1023   \textcolor{keywordtype}{real}, \textcolor{keywordtype}{dimension(:,:,:)}, \textcolor{keywordtype}{allocatable} :: data\_h\_in, data\_h
1024   \textcolor{keywordtype}{real}, \textcolor{keywordtype}{dimension(:,:,:)}, \textcolor{keywordtype}{allocatable} :: sp\_val\_in, sp\_val
1025   \textcolor{keywordtype}{real}, \textcolor{keywordtype}{dimension(:,:,:)}, \textcolor{keywordtype}{pointer} :: sp\_ptr => null()
1026   \textcolor{keywordtype}{integer} :: c, c\_i, c\_j
1027   \textcolor{keywordtype}{integer} :: k, nz\_data
1028   \textcolor{keywordtype}{integer} :: n
1029   \textcolor{keywordtype}{logical} :: fixed\_sponge
1030 
1031   fixed\_sponge = .not. sponge\_in%time\_varying\_sponges
1032   \textcolor{comment}{! NOTE: nz\_data is only conditionally set when fixed\_sponge is true.}
1033 
1034   \textcolor{keyword}{allocate}(iresttime\_in(g\_in%isd:g\_in%ied, g\_in%jsd:g\_in%jed))
1035   \textcolor{keyword}{allocate}(iresttime(g%isd:g%ied, g%jsd:g%jed))
1036   iresttime\_in(:,:) = 0.0
1037 
1038   \textcolor{keywordflow}{if} (fixed\_sponge) \textcolor{keywordflow}{then}
1039     nz\_data = sponge\_in%nz\_data
1040     \textcolor{keyword}{allocate}(data\_h\_in(g\_in%isd:g\_in%ied, g\_in%jsd:g\_in%jed, nz\_data))
1041     \textcolor{keyword}{allocate}(data\_h(g%isd:g%ied, g%jsd:g%jed, nz\_data))
1042     data\_h\_in(:,:,:) = 0.
1043 \textcolor{keywordflow}{  endif}
1044 
1045   \textcolor{comment}{! Re-populate the 2D Iresttime and data\_h arrays on the original grid}
1046   \textcolor{keywordflow}{do} c=1,sponge\_in%num\_col
1047     c\_i = sponge\_in%col\_i(c)
1048     c\_j = sponge\_in%col\_j(c)
1049     iresttime\_in(c\_i, c\_j) = sponge\_in%Iresttime\_col(c)
1050     \textcolor{keywordflow}{if} (fixed\_sponge) \textcolor{keywordflow}{then}
1051       \textcolor{keywordflow}{do} k = 1, nz\_data
1052         data\_h(c\_i, c\_j, k) = sponge\_in%Ref\_h%p(k,c)
1053 \textcolor{keywordflow}{      enddo}
1054 \textcolor{keywordflow}{    endif}
1055 \textcolor{keywordflow}{  enddo}
1056 
1057   \textcolor{keyword}{call }rotate\_array(iresttime\_in, turns, iresttime)
1058   \textcolor{keywordflow}{if} (fixed\_sponge) \textcolor{keywordflow}{then}
1059     \textcolor{keyword}{call }rotate\_array(data\_h\_in, turns, data\_h)
1060     \textcolor{keyword}{call }initialize\_ale\_sponge\_fixed(iresttime, g, param\_file, sponge, &
1061                                      data\_h, nz\_data)
1062   \textcolor{keywordflow}{else}
1063     \textcolor{keyword}{call }initialize\_ale\_sponge\_varying(iresttime, g, param\_file, sponge)
1064 \textcolor{keywordflow}{  endif}
1065 
1066   \textcolor{keyword}{deallocate}(iresttime\_in)
1067   \textcolor{keyword}{deallocate}(iresttime)
1068   \textcolor{keywordflow}{if} (fixed\_sponge) \textcolor{keywordflow}{then}
1069     \textcolor{keyword}{deallocate}(data\_h\_in)
1070     \textcolor{keyword}{deallocate}(data\_h)
1071 \textcolor{keywordflow}{  endif}
1072 
1073   \textcolor{comment}{! Second part: Provide rotated fields for which relaxation is applied}
1074 
1075   sponge%fldno = sponge\_in%fldno
1076 
1077   \textcolor{keywordflow}{if} (fixed\_sponge) \textcolor{keywordflow}{then}
1078     \textcolor{keyword}{allocate}(sp\_val\_in(g\_in%isd:g\_in%ied, g\_in%jsd:g\_in%jed, nz\_data))
1079     \textcolor{keyword}{allocate}(sp\_val(g%isd:g%ied, g%jsd:g%jed, nz\_data))
1080 \textcolor{keywordflow}{  endif}
1081 
1082   \textcolor{keywordflow}{do} n=1,sponge\_in%fldno
1083     \textcolor{comment}{! Assume that tracers are pointers and are remapped in other functions(?)}
1084     sp\_ptr => sponge\_in%var(n)%p
1085     \textcolor{keywordflow}{if} (fixed\_sponge) \textcolor{keywordflow}{then}
1086       sp\_val\_in(:,:,:) = 0.0
1087       \textcolor{keywordflow}{do} c = 1, sponge\_in%num\_col
1088         c\_i = sponge\_in%col\_i(c)
1089         c\_j = sponge\_in%col\_j(c)
1090         \textcolor{keywordflow}{do} k = 1, nz\_data
1091           sp\_val\_in(c\_i, c\_j, k) = sponge\_in%Ref\_val(n)%p(k,c)
1092 \textcolor{keywordflow}{        enddo}
1093 \textcolor{keywordflow}{      enddo}
1094 
1095       \textcolor{keyword}{call }rotate\_array(sp\_val\_in, turns, sp\_val)
1096 
1097       \textcolor{comment}{! NOTE: This points sp\_val with the unrotated field.  See note below.}
1098       \textcolor{keyword}{call }set\_up\_ale\_sponge\_field(sp\_val, g, sp\_ptr, sponge)
1099 
1100       \textcolor{keyword}{deallocate}(sp\_val\_in)
1101     \textcolor{keywordflow}{else}
1102       \textcolor{comment}{! We don't want to repeat FMS init in set\_up\_ALE\_sponge\_field\_varying()}
1103       \textcolor{comment}{! (time\_interp\_external\_init, init\_external\_field, etc), so we manually}
1104       \textcolor{comment}{! do a portion of this function below.}
1105       sponge%Ref\_val(n)%id = sponge\_in%Ref\_val(n)%id
1106       sponge%Ref\_val(n)%num\_tlevs = sponge\_in%Ref\_val(n)%num\_tlevs
1107 
1108       nz\_data = sponge\_in%Ref\_val(n)%nz\_data
1109       sponge%Ref\_val(n)%nz\_data = nz\_data
1110 
1111       \textcolor{keyword}{allocate}(sponge%Ref\_val(n)%p(nz\_data, sponge\_in%num\_col))
1112       \textcolor{keyword}{allocate}(sponge%Ref\_val(n)%h(nz\_data, sponge\_in%num\_col))
1113       sponge%Ref\_val(n)%p(:,:) = 0.0
1114       sponge%Ref\_val(n)%h(:,:) = 0.0
1115 
1116       \textcolor{comment}{! TODO: There is currently no way to associate a generic field pointer to}
1117       \textcolor{comment}{!   its rotated equivalent without introducing a new data structure which}
1118       \textcolor{comment}{!   explicitly tracks the pairing.}
1119       \textcolor{comment}{!}
1120       \textcolor{comment}{!   As a temporary fix, we store the pointer to the unrotated field in}
1121       \textcolor{comment}{!   the rotated sponge, and use this reference to replace the pointer}
1122       \textcolor{comment}{!   to the rotated field update\_ALE\_sponge field.}
1123       \textcolor{comment}{!}
1124       \textcolor{comment}{!   This makes a lot of unverifiable assumptions, and should not be}
1125       \textcolor{comment}{!   considered the final solution.}
1126       sponge%var(n)%p => sp\_ptr
1127 \textcolor{keywordflow}{    endif}
1128 \textcolor{keywordflow}{  enddo}
1129 
1130   \textcolor{comment}{! TODO: var\_u and var\_v sponge dampling is not yet supported.}
1131   \textcolor{keywordflow}{if} (\textcolor{keyword}{associated}(sponge\_in%var\_u%p) .or. \textcolor{keyword}{associated}(sponge\_in%var\_v%p)) &
1132     \textcolor{keyword}{call }mom\_error(fatal, \textcolor{stringliteral}{"Rotation of ALE sponge velocities is not yet "} &
1133       // \textcolor{stringliteral}{"implemented."})
1134 
1135   \textcolor{comment}{! Transfer any existing diag\_CS reference pointer}
1136   sponge%diag => sponge\_in%diag
1137 
1138   \textcolor{comment}{! NOTE: initialize\_ALE\_sponge\_* resolves remap\_cs}
\end{DoxyCode}
\mbox{\Hypertarget{namespacemom__ale__sponge_a7b00598b2cf45b865f56515ed5d2ed0a}\label{namespacemom__ale__sponge_a7b00598b2cf45b865f56515ed5d2ed0a}} 
\index{mom\+\_\+ale\+\_\+sponge@{mom\+\_\+ale\+\_\+sponge}!set\+\_\+up\+\_\+ale\+\_\+sponge\+\_\+field\+\_\+fixed@{set\+\_\+up\+\_\+ale\+\_\+sponge\+\_\+field\+\_\+fixed}}
\index{set\+\_\+up\+\_\+ale\+\_\+sponge\+\_\+field\+\_\+fixed@{set\+\_\+up\+\_\+ale\+\_\+sponge\+\_\+field\+\_\+fixed}!mom\+\_\+ale\+\_\+sponge@{mom\+\_\+ale\+\_\+sponge}}
\subsubsection{\texorpdfstring{set\+\_\+up\+\_\+ale\+\_\+sponge\+\_\+field\+\_\+fixed()}{set\_up\_ale\_sponge\_field\_fixed()}}
{\footnotesize\ttfamily subroutine mom\+\_\+ale\+\_\+sponge\+::set\+\_\+up\+\_\+ale\+\_\+sponge\+\_\+field\+\_\+fixed (\begin{DoxyParamCaption}\item[{real, dimension( g \%isd\+: g \%ied, g \%jsd\+: g \%jed,cs\%nz\+\_\+data), intent(in)}]{sp\+\_\+val,  }\item[{type(ocean\+\_\+grid\+\_\+type), intent(in)}]{G,  }\item[{real, dimension( g \%isd\+: g \%ied, g \%jsd\+: g \%jed, g \%ke), intent(in), target}]{f\+\_\+ptr,  }\item[{type(\hyperlink{structmom__ale__sponge_1_1ale__sponge__cs}{ale\+\_\+sponge\+\_\+cs}), pointer}]{CS }\end{DoxyParamCaption})\hspace{0.3cm}{\ttfamily [private]}}



This subroutine stores the reference profile at h points for the variable whose address is given by f\+\_\+ptr. 


\begin{DoxyParams}[1]{Parameters}
\mbox{\tt in}  & {\em g} & Grid structure\\
\hline
 & {\em cs} & A\+LE sponge control structure (in/out).\\
\hline
\mbox{\tt in}  & {\em sp\+\_\+val} & Field to be used in the sponge, it has arbitrary number of layers.\\
\hline
\mbox{\tt in}  & {\em f\+\_\+ptr} & Pointer to the field to be damped \\
\hline
\end{DoxyParams}


Definition at line 564 of file M\+O\+M\+\_\+\+A\+L\+E\+\_\+sponge.\+F90.


\begin{DoxyCode}
564   \textcolor{keywordtype}{type}(ocean\_grid\_type), \textcolor{keywordtype}{intent(in)} :: g\textcolor{comment}{  !< Grid structure}
565   \textcolor{keywordtype}{type}(ale\_sponge\_cs),   \textcolor{keywordtype}{pointer}    :: cs\textcolor{comment}{ !< ALE sponge control structure (in/out).}
566   \textcolor{keywordtype}{real}, \textcolor{keywordtype}{dimension(SZI\_(G),SZJ\_(G),CS%nz\_data)}, &
567                          \textcolor{keywordtype}{intent(in)} :: sp\_val\textcolor{comment}{ !< Field to be used in the sponge, it has arbitrary number of
       layers.}
568   \textcolor{keywordtype}{real}, \textcolor{keywordtype}{dimension(SZI\_(G),SZJ\_(G),SZK\_(G))}, &
569                  \textcolor{keywordtype}{target}, \textcolor{keywordtype}{intent(in)} :: f\_ptr\textcolor{comment}{ !< Pointer to the field to be damped}
570 
571   \textcolor{keywordtype}{integer} :: j, k, col
572   \textcolor{keywordtype}{character(len=256)} :: mesg \textcolor{comment}{! String for error messages}
573 
574   \textcolor{keywordflow}{if} (.not.\textcolor{keyword}{associated}(cs)) \textcolor{keywordflow}{return}
575 
576   cs%fldno = cs%fldno + 1
577 
578   \textcolor{keywordflow}{if} (cs%fldno > max\_fields\_) \textcolor{keywordflow}{then}
579     \textcolor{keyword}{write}(mesg,\textcolor{stringliteral}{'("Increase MAX\_FIELDS\_ to at least ",I3," in MOM\_memory.h or decrease &}
580 \textcolor{stringliteral}{}\textcolor{stringliteral}{           &the number of fields to be damped in the call to &}
581 \textcolor{stringliteral}{}\textcolor{stringliteral}{           &initialize\_ALE\_sponge." )'}) cs%fldno
582     \textcolor{keyword}{call }mom\_error(fatal,\textcolor{stringliteral}{"set\_up\_ALE\_sponge\_field: "}//mesg)
583 \textcolor{keywordflow}{  endif}
584 
585   \textcolor{comment}{! stores the reference profile}
586   \textcolor{keyword}{allocate}(cs%Ref\_val(cs%fldno)%p(cs%nz\_data,cs%num\_col))
587   cs%Ref\_val(cs%fldno)%p(:,:) = 0.0
588   \textcolor{keywordflow}{do} col=1,cs%num\_col
589     \textcolor{keywordflow}{do} k=1,cs%nz\_data
590       cs%Ref\_val(cs%fldno)%p(k,col) = sp\_val(cs%col\_i(col),cs%col\_j(col),k)
591 \textcolor{keywordflow}{    enddo}
592 \textcolor{keywordflow}{  enddo}
593 
594   cs%var(cs%fldno)%p => f\_ptr
595 
\end{DoxyCode}
\mbox{\Hypertarget{namespacemom__ale__sponge_a5222905f5cfddd07b77e05428e88dd85}\label{namespacemom__ale__sponge_a5222905f5cfddd07b77e05428e88dd85}} 
\index{mom\+\_\+ale\+\_\+sponge@{mom\+\_\+ale\+\_\+sponge}!set\+\_\+up\+\_\+ale\+\_\+sponge\+\_\+field\+\_\+varying@{set\+\_\+up\+\_\+ale\+\_\+sponge\+\_\+field\+\_\+varying}}
\index{set\+\_\+up\+\_\+ale\+\_\+sponge\+\_\+field\+\_\+varying@{set\+\_\+up\+\_\+ale\+\_\+sponge\+\_\+field\+\_\+varying}!mom\+\_\+ale\+\_\+sponge@{mom\+\_\+ale\+\_\+sponge}}
\subsubsection{\texorpdfstring{set\+\_\+up\+\_\+ale\+\_\+sponge\+\_\+field\+\_\+varying()}{set\_up\_ale\_sponge\_field\_varying()}}
{\footnotesize\ttfamily subroutine mom\+\_\+ale\+\_\+sponge\+::set\+\_\+up\+\_\+ale\+\_\+sponge\+\_\+field\+\_\+varying (\begin{DoxyParamCaption}\item[{character(len=$\ast$), intent(in)}]{filename,  }\item[{character(len=$\ast$), intent(in)}]{fieldname,  }\item[{type(time\+\_\+type), intent(in)}]{Time,  }\item[{type(ocean\+\_\+grid\+\_\+type), intent(in)}]{G,  }\item[{type(verticalgrid\+\_\+type), intent(in)}]{GV,  }\item[{type(unit\+\_\+scale\+\_\+type), intent(in)}]{US,  }\item[{real, dimension( g \%isd\+: g \%ied, g \%jsd\+: g \%jed, gv \%ke), intent(in), target}]{f\+\_\+ptr,  }\item[{type(\hyperlink{structmom__ale__sponge_1_1ale__sponge__cs}{ale\+\_\+sponge\+\_\+cs}), pointer}]{CS }\end{DoxyParamCaption})\hspace{0.3cm}{\ttfamily [private]}}



This subroutine stores the reference profile at h points for the variable whose address is given by filename and fieldname. 


\begin{DoxyParams}[1]{Parameters}
\mbox{\tt in}  & {\em filename} & The name of the file with the time varying field data\\
\hline
\mbox{\tt in}  & {\em fieldname} & The name of the field in the file with the time varying field data\\
\hline
\mbox{\tt in}  & {\em time} & The current model time\\
\hline
\mbox{\tt in}  & {\em g} & Grid structure (in).\\
\hline
\mbox{\tt in}  & {\em gv} & ocean vertical grid structure\\
\hline
\mbox{\tt in}  & {\em us} & A dimensional unit scaling type\\
\hline
\mbox{\tt in}  & {\em f\+\_\+ptr} & Pointer to the field to be damped (in).\\
\hline
 & {\em cs} & Sponge control structure (in/out). \\
\hline
\end{DoxyParams}


Definition at line 601 of file M\+O\+M\+\_\+\+A\+L\+E\+\_\+sponge.\+F90.


\begin{DoxyCode}
601   \textcolor{keywordtype}{character(len=*)},        \textcolor{keywordtype}{intent(in)} :: filename\textcolor{comment}{ !< The name of the file with the}
602 \textcolor{comment}{                                                  !! time varying field data}
603   \textcolor{keywordtype}{character(len=*)},        \textcolor{keywordtype}{intent(in)} :: fieldname\textcolor{comment}{ !< The name of the field in the file}
604 \textcolor{comment}{                                                  !! with the time varying field data}
605   \textcolor{keywordtype}{type}(time\_type),         \textcolor{keywordtype}{intent(in)} :: time\textcolor{comment}{  !< The current model time}
606   \textcolor{keywordtype}{type}(ocean\_grid\_type),   \textcolor{keywordtype}{intent(in)} :: g\textcolor{comment}{     !< Grid structure (in).}
607   \textcolor{keywordtype}{type}(verticalgrid\_type), \textcolor{keywordtype}{intent(in)} :: gv\textcolor{comment}{    !< ocean vertical grid structure}
608   \textcolor{keywordtype}{type}(unit\_scale\_type),   \textcolor{keywordtype}{intent(in)} :: us\textcolor{comment}{    !< A dimensional unit scaling type}
609   \textcolor{keywordtype}{real}, \textcolor{keywordtype}{dimension(SZI\_(G),SZJ\_(G),SZK\_(GV))}, &
610                    \textcolor{keywordtype}{target}, \textcolor{keywordtype}{intent(in)} :: f\_ptr\textcolor{comment}{ !< Pointer to the field to be damped (in).}
611   \textcolor{keywordtype}{type}(ale\_sponge\_cs),     \textcolor{keywordtype}{pointer}    :: cs\textcolor{comment}{    !< Sponge control structure (in/out).}
612 
613   \textcolor{comment}{! Local variables}
614   \textcolor{keywordtype}{real}, \textcolor{keywordtype}{allocatable}, \textcolor{keywordtype}{dimension(:,:,:)} :: sp\_val\textcolor{comment}{ !< Field to be used in the sponge}
615   \textcolor{keywordtype}{real}, \textcolor{keywordtype}{allocatable}, \textcolor{keywordtype}{dimension(:,:,:)} :: mask\_z\textcolor{comment}{ !< Field mask for the sponge data}
616   \textcolor{keywordtype}{real}, \textcolor{keywordtype}{allocatable}, \textcolor{keywordtype}{dimension(:)}, \textcolor{keywordtype}{target} :: z\_in, z\_edges\_in \textcolor{comment}{! Heights [Z ~> m].}
617   \textcolor{keywordtype}{real} :: missing\_value
618   \textcolor{keywordtype}{integer} :: j, k, col
619   \textcolor{keywordtype}{integer} :: isd,ied,jsd,jed
620   \textcolor{keywordtype}{integer} :: npoints
621   \textcolor{keywordtype}{integer}, \textcolor{keywordtype}{dimension(4)} :: fld\_sz
622   \textcolor{keywordtype}{integer} :: nz\_data\textcolor{comment}{ !< the number of vertical levels in this input field}
623   \textcolor{keywordtype}{character(len=256)} :: mesg \textcolor{comment}{! String for error messages}
624   \textcolor{comment}{! Local variables for ALE remapping}
625   \textcolor{keywordtype}{real}, \textcolor{keywordtype}{dimension(:)}, \textcolor{keywordtype}{allocatable} :: tmpt1d
626   \textcolor{keywordtype}{real} :: ztopofcell, zbottomofcell \textcolor{comment}{! Heights [Z ~> m].}
627   \textcolor{keywordtype}{type}(remapping\_cs) :: remapcs \textcolor{comment}{! Remapping parameters and work arrays}
628 
629   \textcolor{keywordflow}{if} (.not.\textcolor{keyword}{associated}(cs)) \textcolor{keywordflow}{return}
630   \textcolor{comment}{! initialize time interpolator module}
631   \textcolor{keyword}{call }time\_interp\_external\_init()
632   isd = g%isd; ied = g%ied; jsd = g%jsd; jed = g%jed
633   cs%fldno = cs%fldno + 1
634   \textcolor{keywordflow}{if} (cs%fldno > max\_fields\_) \textcolor{keywordflow}{then}
635     \textcolor{keyword}{write}(mesg,\textcolor{stringliteral}{'("Increase MAX\_FIELDS\_ to at least ",I3," in MOM\_memory.h or decrease &}
636 \textcolor{stringliteral}{}\textcolor{stringliteral}{           &the number of fields to be damped in the call to &}
637 \textcolor{stringliteral}{}\textcolor{stringliteral}{           &initialize\_ALE\_sponge." )'}) cs%fldno
638     \textcolor{keyword}{call }mom\_error(fatal,\textcolor{stringliteral}{"set\_up\_ALE\_sponge\_field: "}//mesg)
639 \textcolor{keywordflow}{  endif}
640   \textcolor{comment}{! get a unique time interp id for this field. If sponge data is ongrid, then setup}
641   \textcolor{comment}{! to only read on the computational domain}
642   \textcolor{keywordflow}{if} (cs%spongeDataOngrid) \textcolor{keywordflow}{then}
643     cs%Ref\_val(cs%fldno)%id = init\_external\_field(filename, fieldname,domain=g%Domain%mpp\_domain)
644   \textcolor{keywordflow}{else}
645     cs%Ref\_val(cs%fldno)%id = init\_external\_field(filename, fieldname)
646 \textcolor{keywordflow}{  endif}
647   fld\_sz(1:4)=-1
648   fld\_sz = get\_external\_field\_size(cs%Ref\_val(cs%fldno)%id)
649   nz\_data = fld\_sz(3)
650   cs%Ref\_val(cs%fldno)%nz\_data = nz\_data \textcolor{comment}{!< individual sponge fields may reside on a different vertical
       grid}
651   cs%Ref\_val(cs%fldno)%num\_tlevs = fld\_sz(4)
652   \textcolor{comment}{! initializes the target profile array for this field}
653   \textcolor{comment}{! for all columns which will be masked}
654   \textcolor{keyword}{allocate}(cs%Ref\_val(cs%fldno)%p(nz\_data,cs%num\_col))
655   cs%Ref\_val(cs%fldno)%p(:,:) = 0.0
656   \textcolor{keyword}{allocate}( cs%Ref\_val(cs%fldno)%h(nz\_data,cs%num\_col) )
657   cs%Ref\_val(cs%fldno)%h(:,:) = 0.0
658   cs%var(cs%fldno)%p => f\_ptr
659 
660 
\end{DoxyCode}
\mbox{\Hypertarget{namespacemom__ale__sponge_a6eb21c5a149d573ba0d67fdb3a932115}\label{namespacemom__ale__sponge_a6eb21c5a149d573ba0d67fdb3a932115}} 
\index{mom\+\_\+ale\+\_\+sponge@{mom\+\_\+ale\+\_\+sponge}!set\+\_\+up\+\_\+ale\+\_\+sponge\+\_\+vel\+\_\+field\+\_\+fixed@{set\+\_\+up\+\_\+ale\+\_\+sponge\+\_\+vel\+\_\+field\+\_\+fixed}}
\index{set\+\_\+up\+\_\+ale\+\_\+sponge\+\_\+vel\+\_\+field\+\_\+fixed@{set\+\_\+up\+\_\+ale\+\_\+sponge\+\_\+vel\+\_\+field\+\_\+fixed}!mom\+\_\+ale\+\_\+sponge@{mom\+\_\+ale\+\_\+sponge}}
\subsubsection{\texorpdfstring{set\+\_\+up\+\_\+ale\+\_\+sponge\+\_\+vel\+\_\+field\+\_\+fixed()}{set\_up\_ale\_sponge\_vel\_field\_fixed()}}
{\footnotesize\ttfamily subroutine mom\+\_\+ale\+\_\+sponge\+::set\+\_\+up\+\_\+ale\+\_\+sponge\+\_\+vel\+\_\+field\+\_\+fixed (\begin{DoxyParamCaption}\item[{real, dimension( g \%isdb\+: g \%iedb, g \%jsd\+: g \%jed,cs\%nz\+\_\+data), intent(in)}]{u\+\_\+val,  }\item[{real, dimension( g \%isd\+: g \%ied, g \%jsdb\+: g \%jedb,cs\%nz\+\_\+data), intent(in)}]{v\+\_\+val,  }\item[{type(ocean\+\_\+grid\+\_\+type), intent(in)}]{G,  }\item[{real, dimension( g \%isdb\+: g \%iedb, g \%jsd\+: g \%jed, g \%ke), intent(in), target}]{u\+\_\+ptr,  }\item[{real, dimension( g \%isd\+: g \%ied, g \%jsdb\+: g \%jedb, g \%ke), intent(in), target}]{v\+\_\+ptr,  }\item[{type(\hyperlink{structmom__ale__sponge_1_1ale__sponge__cs}{ale\+\_\+sponge\+\_\+cs}), pointer}]{CS }\end{DoxyParamCaption})\hspace{0.3cm}{\ttfamily [private]}}



This subroutine stores the reference profile at u and v points for the variable whose address is given by u\+\_\+ptr and v\+\_\+ptr. 


\begin{DoxyParams}[1]{Parameters}
\mbox{\tt in}  & {\em g} & Grid structure (in).\\
\hline
 & {\em cs} & Sponge structure (in/out).\\
\hline
\mbox{\tt in}  & {\em u\+\_\+val} & u field to be used in the sponge, it has arbritary number of layers.\\
\hline
\mbox{\tt in}  & {\em v\+\_\+val} & v field to be used in the sponge, it has arbritary number of layers.\\
\hline
\mbox{\tt in}  & {\em u\+\_\+ptr} & u pointer to the field to be damped\\
\hline
\mbox{\tt in}  & {\em v\+\_\+ptr} & v pointer to the field to be damped \\
\hline
\end{DoxyParams}


Definition at line 666 of file M\+O\+M\+\_\+\+A\+L\+E\+\_\+sponge.\+F90.


\begin{DoxyCode}
666   \textcolor{keywordtype}{type}(ocean\_grid\_type), \textcolor{keywordtype}{intent(in)} :: g\textcolor{comment}{  !< Grid structure (in).}
667   \textcolor{keywordtype}{type}(ale\_sponge\_cs),   \textcolor{keywordtype}{pointer}    :: cs\textcolor{comment}{ !< Sponge structure (in/out).}
668   \textcolor{keywordtype}{real}, \textcolor{keywordtype}{dimension(SZIB\_(G),SZJ\_(G),CS%nz\_data)}, &
669                          \textcolor{keywordtype}{intent(in)} :: u\_val\textcolor{comment}{ !< u field to be used in the sponge, it has arbritary number
       of layers.}
670   \textcolor{keywordtype}{real}, \textcolor{keywordtype}{dimension(SZI\_(G),SZJB\_(G),CS%nz\_data)}, &
671                          \textcolor{keywordtype}{intent(in)} :: v\_val\textcolor{comment}{ !< v field to be used in the sponge, it has arbritary number
       of layers.}
672   \textcolor{keywordtype}{real}, \textcolor{keywordtype}{dimension(SZIB\_(G),SZJ\_(G),SZK\_(G))}, \textcolor{keywordtype}{target}, \textcolor{keywordtype}{intent(in)} :: u\_ptr\textcolor{comment}{ !< u pointer to the field to be
       damped}
673   \textcolor{keywordtype}{real}, \textcolor{keywordtype}{dimension(SZI\_(G),SZJB\_(G),SZK\_(G))}, \textcolor{keywordtype}{target}, \textcolor{keywordtype}{intent(in)} :: v\_ptr\textcolor{comment}{ !< v pointer to the field to be
       damped}
674 
675   \textcolor{keywordtype}{integer} :: j, k, col
676   \textcolor{keywordtype}{character(len=256)} :: mesg \textcolor{comment}{! String for error messages}
677 
678   \textcolor{keywordflow}{if} (.not.\textcolor{keyword}{associated}(cs)) \textcolor{keywordflow}{return}
679 
680   \textcolor{comment}{! stores the reference profile}
681   \textcolor{keyword}{allocate}(cs%Ref\_val\_u%p(cs%nz\_data,cs%num\_col\_u))
682   cs%Ref\_val\_u%p(:,:) = 0.0
683   \textcolor{keywordflow}{do} col=1,cs%num\_col\_u
684     \textcolor{keywordflow}{do} k=1,cs%nz\_data
685       cs%Ref\_val\_u%p(k,col) = u\_val(cs%col\_i\_u(col),cs%col\_j\_u(col),k)
686 \textcolor{keywordflow}{    enddo}
687 \textcolor{keywordflow}{  enddo}
688   cs%var\_u%p => u\_ptr
689   \textcolor{keyword}{allocate}(cs%Ref\_val\_v%p(cs%nz\_data,cs%num\_col\_v))
690   cs%Ref\_val\_v%p(:,:) = 0.0
691   \textcolor{keywordflow}{do} col=1,cs%num\_col\_v
692     \textcolor{keywordflow}{do} k=1,cs%nz\_data
693       cs%Ref\_val\_v%p(k,col) = v\_val(cs%col\_i\_v(col),cs%col\_j\_v(col),k)
694 \textcolor{keywordflow}{    enddo}
695 \textcolor{keywordflow}{  enddo}
696   cs%var\_v%p => v\_ptr
697 
\end{DoxyCode}
\mbox{\Hypertarget{namespacemom__ale__sponge_a551051d11b239eeef807fb88ab31aba6}\label{namespacemom__ale__sponge_a551051d11b239eeef807fb88ab31aba6}} 
\index{mom\+\_\+ale\+\_\+sponge@{mom\+\_\+ale\+\_\+sponge}!set\+\_\+up\+\_\+ale\+\_\+sponge\+\_\+vel\+\_\+field\+\_\+varying@{set\+\_\+up\+\_\+ale\+\_\+sponge\+\_\+vel\+\_\+field\+\_\+varying}}
\index{set\+\_\+up\+\_\+ale\+\_\+sponge\+\_\+vel\+\_\+field\+\_\+varying@{set\+\_\+up\+\_\+ale\+\_\+sponge\+\_\+vel\+\_\+field\+\_\+varying}!mom\+\_\+ale\+\_\+sponge@{mom\+\_\+ale\+\_\+sponge}}
\subsubsection{\texorpdfstring{set\+\_\+up\+\_\+ale\+\_\+sponge\+\_\+vel\+\_\+field\+\_\+varying()}{set\_up\_ale\_sponge\_vel\_field\_varying()}}
{\footnotesize\ttfamily subroutine mom\+\_\+ale\+\_\+sponge\+::set\+\_\+up\+\_\+ale\+\_\+sponge\+\_\+vel\+\_\+field\+\_\+varying (\begin{DoxyParamCaption}\item[{character(len=$\ast$), intent(in)}]{filename\+\_\+u,  }\item[{character(len=$\ast$), intent(in)}]{fieldname\+\_\+u,  }\item[{character(len=$\ast$), intent(in)}]{filename\+\_\+v,  }\item[{character(len=$\ast$), intent(in)}]{fieldname\+\_\+v,  }\item[{type(time\+\_\+type), intent(in)}]{Time,  }\item[{type(ocean\+\_\+grid\+\_\+type), intent(inout)}]{G,  }\item[{type(unit\+\_\+scale\+\_\+type), intent(in)}]{US,  }\item[{type(\hyperlink{structmom__ale__sponge_1_1ale__sponge__cs}{ale\+\_\+sponge\+\_\+cs}), pointer}]{CS,  }\item[{real, dimension( g \%isdb\+: g \%iedb, g \%jsd\+: g \%jed, g \%ke), intent(in), target}]{u\+\_\+ptr,  }\item[{real, dimension( g \%isd\+: g \%ied, g \%jsdb\+: g \%jedb, g \%ke), intent(in), target}]{v\+\_\+ptr }\end{DoxyParamCaption})\hspace{0.3cm}{\ttfamily [private]}}



This subroutine stores the reference profile at uand v points for the variable whose address is given by u\+\_\+ptr and v\+\_\+ptr. 


\begin{DoxyParams}[1]{Parameters}
\mbox{\tt in}  & {\em filename\+\_\+u} & File name for u field\\
\hline
\mbox{\tt in}  & {\em fieldname\+\_\+u} & Name of u variable in file\\
\hline
\mbox{\tt in}  & {\em filename\+\_\+v} & File name for v field\\
\hline
\mbox{\tt in}  & {\em fieldname\+\_\+v} & Name of v variable in file\\
\hline
\mbox{\tt in}  & {\em time} & Model time\\
\hline
\mbox{\tt in,out}  & {\em g} & Ocean grid (in)\\
\hline
\mbox{\tt in}  & {\em us} & A dimensional unit scaling type\\
\hline
 & {\em cs} & Sponge structure (in/out).\\
\hline
\mbox{\tt in}  & {\em u\+\_\+ptr} & u pointer to the field to be damped (in).\\
\hline
\mbox{\tt in}  & {\em v\+\_\+ptr} & v pointer to the field to be damped (in). \\
\hline
\end{DoxyParams}


Definition at line 704 of file M\+O\+M\+\_\+\+A\+L\+E\+\_\+sponge.\+F90.


\begin{DoxyCode}
704   \textcolor{keywordtype}{character(len=*)}, \textcolor{keywordtype}{intent(in)}    :: filename\_u\textcolor{comment}{  !< File name for u field}
705   \textcolor{keywordtype}{character(len=*)}, \textcolor{keywordtype}{intent(in)}    :: fieldname\_u\textcolor{comment}{ !< Name of u variable in file}
706   \textcolor{keywordtype}{character(len=*)}, \textcolor{keywordtype}{intent(in)}    :: filename\_v\textcolor{comment}{  !< File name for v field}
707   \textcolor{keywordtype}{character(len=*)}, \textcolor{keywordtype}{intent(in)}    :: fieldname\_v\textcolor{comment}{ !< Name of v variable in file}
708   \textcolor{keywordtype}{type}(time\_type),  \textcolor{keywordtype}{intent(in)}    :: time\textcolor{comment}{        !< Model time}
709   \textcolor{keywordtype}{type}(ocean\_grid\_type), \textcolor{keywordtype}{intent(inout)} :: g\textcolor{comment}{      !< Ocean grid (in)}
710   \textcolor{keywordtype}{type}(unit\_scale\_type), \textcolor{keywordtype}{intent(in)}    :: us\textcolor{comment}{     !< A dimensional unit scaling type}
711   \textcolor{keywordtype}{type}(ale\_sponge\_cs), \textcolor{keywordtype}{pointer}    :: cs\textcolor{comment}{          !< Sponge structure (in/out).}
712   \textcolor{keywordtype}{real}, \textcolor{keywordtype}{dimension(SZIB\_(G),SZJ\_(G),SZK\_(G))}, \textcolor{keywordtype}{target}, \textcolor{keywordtype}{intent(in)} :: u\_ptr\textcolor{comment}{ !< u pointer to the field to be
       damped (in).}
713   \textcolor{keywordtype}{real}, \textcolor{keywordtype}{dimension(SZI\_(G),SZJB\_(G),SZK\_(G))}, \textcolor{keywordtype}{target}, \textcolor{keywordtype}{intent(in)} :: v\_ptr\textcolor{comment}{ !< v pointer to the field to be
       damped (in).}
714   \textcolor{comment}{! Local variables}
715   \textcolor{keywordtype}{real}, \textcolor{keywordtype}{allocatable}, \textcolor{keywordtype}{dimension(:,:,:)} :: u\_val\textcolor{comment}{ !< U field to be used in the sponge.}
716   \textcolor{keywordtype}{real}, \textcolor{keywordtype}{allocatable}, \textcolor{keywordtype}{dimension(:,:,:)} :: mask\_u\textcolor{comment}{ !< U field mask for the sponge data.}
717   \textcolor{keywordtype}{real}, \textcolor{keywordtype}{allocatable}, \textcolor{keywordtype}{dimension(:,:,:)} :: v\_val\textcolor{comment}{ !< V field to be used in the sponge.}
718   \textcolor{keywordtype}{real}, \textcolor{keywordtype}{allocatable}, \textcolor{keywordtype}{dimension(:,:,:)} :: mask\_v\textcolor{comment}{ !< V field mask for the sponge data.}
719 
720   \textcolor{keywordtype}{real}, \textcolor{keywordtype}{allocatable}, \textcolor{keywordtype}{dimension(:)}, \textcolor{keywordtype}{target} :: z\_in, z\_edges\_in
721   \textcolor{keywordtype}{real} :: missing\_value
722 
723   \textcolor{keywordtype}{integer} :: j, k, col
724   \textcolor{keywordtype}{integer} :: isd, ied, jsd, jed
725   \textcolor{keywordtype}{integer} :: isdb, iedb, jsdb, jedb
726   \textcolor{keywordtype}{integer}, \textcolor{keywordtype}{dimension(4)} :: fld\_sz
727   \textcolor{keywordtype}{character(len=256)} :: mesg \textcolor{comment}{! String for error messages}
728 
729   \textcolor{keywordflow}{if} (.not.\textcolor{keyword}{associated}(cs)) \textcolor{keywordflow}{return}
730 
731   isd = g%isd; ied = g%ied; jsd = g%jsd; jed = g%jed
732   isdb = g%isdB; iedb = g%iedB; jsdb = g%jsdB; jedb = g%jedB
733   \textcolor{comment}{! get a unique id for this field which will allow us to return an array}
734   \textcolor{comment}{! containing time-interpolated values from an external file corresponding}
735   \textcolor{comment}{! to the current model date.}
736   cs%Ref\_val\_u%id = init\_external\_field(filename\_u, fieldname\_u)
737   fld\_sz(1:4)=-1
738   fld\_sz = get\_external\_field\_size(cs%Ref\_val\_u%id)
739   cs%Ref\_val\_u%nz\_data = fld\_sz(3)
740   cs%Ref\_val\_u%num\_tlevs = fld\_sz(4)
741   cs%Ref\_val\_v%id = init\_external\_field(filename\_v, fieldname\_v)
742   fld\_sz(1:4)=-1
743   fld\_sz = get\_external\_field\_size(cs%Ref\_val\_v%id)
744   cs%Ref\_val\_v%nz\_data = fld\_sz(3)
745   cs%Ref\_val\_v%num\_tlevs = fld\_sz(4)
746   \textcolor{keyword}{allocate}( u\_val(isdb:iedb,jsd:jed, fld\_sz(3)) )
747   \textcolor{keyword}{allocate}( mask\_u(isdb:iedb,jsd:jed, fld\_sz(3)) )
748   \textcolor{keyword}{allocate}( v\_val(isd:ied,jsdb:jedb, fld\_sz(3)) )
749   \textcolor{keyword}{allocate}( mask\_v(isd:ied,jsdb:jedb, fld\_sz(3)) )
750   \textcolor{comment}{! Interpolate external file data to the model grid}
751   \textcolor{comment}{! I am hard-wiring this call to assume that the input grid is zonally re-entrant}
752   \textcolor{comment}{! In the future, this should be generalized using an interface to return the}
753   \textcolor{comment}{! modulo attribute of the zonal axis (mjh).}
754   \textcolor{keyword}{call }horiz\_interp\_and\_extrap\_tracer(cs%Ref\_val\_u%id, time, 1.0, g, u\_val, mask\_u, z\_in, z\_edges\_in, &
755                                       missing\_value, .true., .false., .false., m\_to\_z=us%m\_to\_Z, &
756                                       answers\_2018=cs%hor\_regrid\_answers\_2018)
757   \textcolor{comment}{!!! TODO: add a velocity interface! (mjh)}
758   \textcolor{comment}{! Interpolate external file data to the model grid}
759   \textcolor{comment}{! I am hard-wiring this call to assume that the input grid is zonally re-entrant}
760   \textcolor{comment}{! In the future, this should be generalized using an interface to return the}
761   \textcolor{comment}{! modulo attribute of the zonal axis (mjh).}
762   \textcolor{keyword}{call }horiz\_interp\_and\_extrap\_tracer(cs%Ref\_val\_v%id, time, 1.0, g, v\_val, mask\_v, z\_in, z\_edges\_in, &
763                                       missing\_value, .true., .false., .false., m\_to\_z=us%m\_to\_Z, &
764                                       answers\_2018=cs%hor\_regrid\_answers\_2018)
765   \textcolor{comment}{! stores the reference profile}
766   \textcolor{keyword}{allocate}(cs%Ref\_val\_u%p(fld\_sz(3),cs%num\_col\_u))
767   cs%Ref\_val\_u%p(:,:) = 0.0
768   \textcolor{keywordflow}{do} col=1,cs%num\_col\_u
769     \textcolor{keywordflow}{do} k=1,fld\_sz(3)
770       cs%Ref\_val\_u%p(k,col) = u\_val(cs%col\_i\_u(col),cs%col\_j\_u(col),k)
771 \textcolor{keywordflow}{    enddo}
772 \textcolor{keywordflow}{  enddo}
773   cs%var\_u%p => u\_ptr
774   \textcolor{keyword}{allocate}(cs%Ref\_val\_v%p(fld\_sz(3),cs%num\_col\_v))
775   cs%Ref\_val\_v%p(:,:) = 0.0
776   \textcolor{keywordflow}{do} col=1,cs%num\_col\_v
777     \textcolor{keywordflow}{do} k=1,fld\_sz(3)
778       cs%Ref\_val\_v%p(k,col) = v\_val(cs%col\_i\_v(col),cs%col\_j\_v(col),k)
779 \textcolor{keywordflow}{    enddo}
780 \textcolor{keywordflow}{  enddo}
781   cs%var\_v%p => v\_ptr
782 
\end{DoxyCode}
\mbox{\Hypertarget{namespacemom__ale__sponge_ab843ab7a29e992d83973c8f9ad6003b1}\label{namespacemom__ale__sponge_ab843ab7a29e992d83973c8f9ad6003b1}} 
\index{mom\+\_\+ale\+\_\+sponge@{mom\+\_\+ale\+\_\+sponge}!update\+\_\+ale\+\_\+sponge\+\_\+field@{update\+\_\+ale\+\_\+sponge\+\_\+field}}
\index{update\+\_\+ale\+\_\+sponge\+\_\+field@{update\+\_\+ale\+\_\+sponge\+\_\+field}!mom\+\_\+ale\+\_\+sponge@{mom\+\_\+ale\+\_\+sponge}}
\subsubsection{\texorpdfstring{update\+\_\+ale\+\_\+sponge\+\_\+field()}{update\_ale\_sponge\_field()}}
{\footnotesize\ttfamily subroutine, public mom\+\_\+ale\+\_\+sponge\+::update\+\_\+ale\+\_\+sponge\+\_\+field (\begin{DoxyParamCaption}\item[{type(\hyperlink{structmom__ale__sponge_1_1ale__sponge__cs}{ale\+\_\+sponge\+\_\+cs}), pointer}]{sponge,  }\item[{real, dimension(\+:,\+:,\+:), intent(in), target}]{p\+\_\+old,  }\item[{type(ocean\+\_\+grid\+\_\+type), intent(in)}]{G,  }\item[{type(verticalgrid\+\_\+type), intent(in)}]{GV,  }\item[{real, dimension( g \%isd\+: g \%ied, g \%jsd\+: g \%jed, gv \%ke), intent(in), target}]{p\+\_\+new }\end{DoxyParamCaption})}



Scan the A\+LE sponge variables and replace a prescribed pointer to a new value. 


\begin{DoxyParams}[1]{Parameters}
 & {\em sponge} & A pointer to the control structure for this module that is set by a previous call to initialize\+\_\+\+A\+L\+E\+\_\+sponge.\\
\hline
\mbox{\tt in}  & {\em p\+\_\+old} & The previous array of target values\\
\hline
\mbox{\tt in}  & {\em g} & The updated ocean grid structure\\
\hline
\mbox{\tt in}  & {\em gv} & ocean vertical grid structure\\
\hline
\mbox{\tt in}  & {\em p\+\_\+new} & The new array of target values \\
\hline
\end{DoxyParams}


Definition at line 1147 of file M\+O\+M\+\_\+\+A\+L\+E\+\_\+sponge.\+F90.


\begin{DoxyCode}
1147   \textcolor{keywordtype}{type}(ale\_sponge\_cs),     \textcolor{keywordtype}{pointer}    :: sponge\textcolor{comment}{ !< A pointer to the control structure for this module}
1148 \textcolor{comment}{                                               !! that is set by a previous call to initialize\_ALE\_sponge.}
1149   \textcolor{keywordtype}{real}, \textcolor{keywordtype}{dimension(:,:,:)}, &
1150                    \textcolor{keywordtype}{target}, \textcolor{keywordtype}{intent(in)} :: p\_old\textcolor{comment}{ !< The previous array of target values}
1151   \textcolor{keywordtype}{type}(ocean\_grid\_type),   \textcolor{keywordtype}{intent(in)} :: g\textcolor{comment}{     !< The updated ocean grid structure}
1152   \textcolor{keywordtype}{type}(verticalgrid\_type), \textcolor{keywordtype}{intent(in)} :: gv\textcolor{comment}{    !< ocean vertical grid structure}
1153   \textcolor{keywordtype}{real}, \textcolor{keywordtype}{dimension(SZI\_(G),SZJ\_(G),SZK\_(GV))}, &
1154                    \textcolor{keywordtype}{target}, \textcolor{keywordtype}{intent(in)} :: p\_new\textcolor{comment}{ !< The new array of target values}
1155 
1156   \textcolor{keywordtype}{integer} :: n
1157 
1158   \textcolor{keywordflow}{do} n=1,sponge%fldno
1159     \textcolor{keywordflow}{if} (\textcolor{keyword}{associated}(sponge%var(n)%p, p\_old)) sponge%var(n)%p => p\_new
1160 \textcolor{keywordflow}{  enddo}
1161 
\end{DoxyCode}
