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


\subsection{Detailed Description}
Implements sponge regions in isopycnal mode. 

By Robert Hallberg, March 1999-\/\+June 2000.

This program contains the subroutines that implement sponge regions, in which the stratification and water mass properties are damped toward some profiles. There are three externally callable subroutines in this file.

initialize\+\_\+sponge determines the mapping from the model variables into the arrays of damped columns. This remapping is done for efficiency and to conserve memory. Only columns which have positive inverse damping times and which are deeper than a supplied depth are placed in sponges. The inverse damping time is also stored in this subroutine, and memory is allocated for all of the reference profiles which will subsequently be provided through calls to set\+\_\+up\+\_\+sponge\+\_\+field. The first two arguments are a two-\/dimensional array containing the damping rates, and the interface heights to damp towards.

set\+\_\+up\+\_\+sponge\+\_\+field is called to provide a reference profile and the location of the field that will be damped back toward that reference profile. A third argument, the number of layers in the field is also provided, but this should always be nz.

Apply\+\_\+sponge damps all of the fields that have been registered with set\+\_\+up\+\_\+sponge\+\_\+field toward their reference profiles. The four arguments are the thickness to be damped, the amount of time over which the damping occurs, and arrays to which the movement of fluid into a layer from above and below will be added. The effect on momentum of the sponge may be accounted for later using the movement of water recorded in these later arrays. \subsection*{Data Types}
\begin{DoxyCompactItemize}
\item 
type \hyperlink{structmom__sponge_1_1p2d}{p2d}
\begin{DoxyCompactList}\small\item\em A structure for creating arrays of pointers to 2D arrays. \end{DoxyCompactList}\item 
type \hyperlink{structmom__sponge_1_1p3d}{p3d}
\begin{DoxyCompactList}\small\item\em A structure for creating arrays of pointers to 3D arrays. \end{DoxyCompactList}\item 
type \hyperlink{structmom__sponge_1_1sponge__cs}{sponge\+\_\+cs}
\begin{DoxyCompactList}\small\item\em This control structure holds memory and parameters for the M\+O\+M\+\_\+sponge module. \end{DoxyCompactList}\end{DoxyCompactItemize}
\subsection*{Functions/\+Subroutines}
\begin{DoxyCompactItemize}
\item 
subroutine, public \hyperlink{namespacemom__sponge_a2c3c6a03d98c13221031af667b42428d}{initialize\+\_\+sponge} (Iresttime, int\+\_\+height, G, param\+\_\+file, CS, GV, Iresttime\+\_\+i\+\_\+mean, int\+\_\+height\+\_\+i\+\_\+mean)
\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 
subroutine, public \hyperlink{namespacemom__sponge_ad4b2c0efb73f14a43936a11b39027f57}{init\+\_\+sponge\+\_\+diags} (Time, G, GV, US, diag, CS)
\begin{DoxyCompactList}\small\item\em This subroutine sets up diagnostics for the sponges. It is separate from initialize\+\_\+sponge because it requires fields that are not readily available where initialize\+\_\+sponge is called. \end{DoxyCompactList}\item 
subroutine, public \hyperlink{namespacemom__sponge_af3da4a8b352c4130919d7bfedf1a5a3e}{set\+\_\+up\+\_\+sponge\+\_\+field} (sp\+\_\+val, f\+\_\+ptr, G, nlay, CS, sp\+\_\+val\+\_\+i\+\_\+mean)
\begin{DoxyCompactList}\small\item\em This subroutine stores the reference profile for the variable whose address is given by f\+\_\+ptr. nlay is the number of layers in this variable. \end{DoxyCompactList}\item 
subroutine, public \hyperlink{namespacemom__sponge_ac5a144fffdfc612c6e3de802261cc85c}{set\+\_\+up\+\_\+sponge\+\_\+ml\+\_\+density} (sp\+\_\+val, G, CS, sp\+\_\+val\+\_\+i\+\_\+mean)
\begin{DoxyCompactList}\small\item\em This subroutine stores the reference value for mixed layer density. It is handled differently from other values because it is only used in determining which layers can be inflated. \end{DoxyCompactList}\item 
subroutine, public \hyperlink{namespacemom__sponge_a0b8b22a1b577bdcf336c8d22b85b45d7}{apply\+\_\+sponge} (h, dt, G, GV, US, ea, eb, CS, Rcv\+\_\+ml)
\begin{DoxyCompactList}\small\item\em This subroutine applies damping to the layers thicknesses, mixed layer buoyancy, and a variety of tracers for every column where there is damping. \end{DoxyCompactList}\item 
subroutine, public \hyperlink{namespacemom__sponge_a9b62e032925716da3a7b099364ddd720}{sponge\+\_\+end} (CS)
\begin{DoxyCompactList}\small\item\em This call deallocates any memory in the sponge control structure. \end{DoxyCompactList}\end{DoxyCompactItemize}


\subsection{Function/\+Subroutine Documentation}
\mbox{\Hypertarget{namespacemom__sponge_a0b8b22a1b577bdcf336c8d22b85b45d7}\label{namespacemom__sponge_a0b8b22a1b577bdcf336c8d22b85b45d7}} 
\index{mom\+\_\+sponge@{mom\+\_\+sponge}!apply\+\_\+sponge@{apply\+\_\+sponge}}
\index{apply\+\_\+sponge@{apply\+\_\+sponge}!mom\+\_\+sponge@{mom\+\_\+sponge}}
\subsubsection{\texorpdfstring{apply\+\_\+sponge()}{apply\_sponge()}}
{\footnotesize\ttfamily subroutine, public mom\+\_\+sponge\+::apply\+\_\+sponge (\begin{DoxyParamCaption}\item[{real, dimension(szi\+\_\+(g),szj\+\_\+(g),szk\+\_\+(g)), 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[{real, dimension(szi\+\_\+(g),szj\+\_\+(g),szk\+\_\+(g)), intent(inout)}]{ea,  }\item[{real, dimension(szi\+\_\+(g),szj\+\_\+(g),szk\+\_\+(g)), intent(inout)}]{eb,  }\item[{type(\hyperlink{structmom__sponge_1_1sponge__cs}{sponge\+\_\+cs}), pointer}]{CS,  }\item[{real, dimension(szi\+\_\+(g),szj\+\_\+(g)), intent(inout), optional}]{Rcv\+\_\+ml }\end{DoxyParamCaption})}



This subroutine applies damping to the layers thicknesses, mixed layer buoyancy, 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\\
\hline
\mbox{\tt in}  & {\em gv} & The ocean\textquotesingle{}s vertical grid structure\\
\hline
\mbox{\tt in}  & {\em us} & A dimensional unit scaling type\\
\hline
\mbox{\tt in,out}  & {\em h} & Layer thicknesses \mbox{[}H $\sim$$>$ m or kg m-\/2\mbox{]}\\
\hline
\mbox{\tt in}  & {\em dt} & The amount of time covered by this call \mbox{[}T $\sim$$>$ s\mbox{]}.\\
\hline
\mbox{\tt in,out}  & {\em ea} & An array to which the amount of fluid entrained\\
\hline
\mbox{\tt in,out}  & {\em eb} & An array to which the amount of fluid entrained\\
\hline
 & {\em cs} & A pointer to the control structure for this module that is set by a previous call to initialize\+\_\+sponge.\\
\hline
\mbox{\tt in,out}  & {\em rcv\+\_\+ml} & The coordinate density of the mixed layer \mbox{[}R $\sim$$>$ kg m-\/3\mbox{]}. \\
\hline
\end{DoxyParams}


Definition at line 324 of file M\+O\+M\+\_\+sponge.\+F90.


\begin{DoxyCode}
324   \textcolor{keywordtype}{type}(ocean\_grid\_type),   \textcolor{keywordtype}{intent(inout)} :: g\textcolor{comment}{   !< The ocean's grid structure}
325   \textcolor{keywordtype}{type}(verticalgrid\_type), \textcolor{keywordtype}{intent(in)}    :: gv\textcolor{comment}{  !< The ocean's vertical grid structure}
326   \textcolor{keywordtype}{type}(unit\_scale\_type),   \textcolor{keywordtype}{intent(in)}    :: us\textcolor{comment}{  !< A dimensional unit scaling type}
327   \textcolor{keywordtype}{real}, \textcolor{keywordtype}{dimension(SZI\_(G),SZJ\_(G),SZK\_(G))}, &
328                            \textcolor{keywordtype}{intent(inout)} :: h\textcolor{comment}{   !< Layer thicknesses [H ~> m or kg m-2]}
329   \textcolor{keywordtype}{real},                    \textcolor{keywordtype}{intent(in)}    :: dt\textcolor{comment}{  !< The amount of time covered by this call [T ~> s].}
330   \textcolor{keywordtype}{real}, \textcolor{keywordtype}{dimension(SZI\_(G),SZJ\_(G),SZK\_(G))}, &
331                            \textcolor{keywordtype}{intent(inout)} :: ea\textcolor{comment}{  !< An array to which the amount of fluid entrained}
332 \textcolor{comment}{                                                !! from the layer above during this call will be}
333 \textcolor{comment}{                                                !! added [H ~> m or kg m-2].}
334   \textcolor{keywordtype}{real}, \textcolor{keywordtype}{dimension(SZI\_(G),SZJ\_(G),SZK\_(G))}, &
335                            \textcolor{keywordtype}{intent(inout)} :: eb\textcolor{comment}{  !< An array to which the amount of fluid entrained}
336 \textcolor{comment}{                                                !! from the layer below during this call will be}
337 \textcolor{comment}{                                                !! added [H ~> m or kg m-2].}
338   \textcolor{keywordtype}{type}(sponge\_cs),         \textcolor{keywordtype}{pointer}       :: cs\textcolor{comment}{  !< A pointer to the control structure for this module}
339 \textcolor{comment}{                                                !! that is set by a previous call to initialize\_sponge.}
340   \textcolor{keywordtype}{real}, \textcolor{keywordtype}{dimension(SZI\_(G),SZJ\_(G))}, &
341                  \textcolor{keywordtype}{optional}, \textcolor{keywordtype}{intent(inout)} :: rcv\_ml\textcolor{comment}{ !<  The coordinate density of the mixed layer [R ~> kg
       m-3].}
342 
343 \textcolor{comment}{! This subroutine applies damping to the layers thicknesses, mixed}
344 \textcolor{comment}{! layer buoyancy, and a variety of tracers for every column where}
345 \textcolor{comment}{! there is damping.}
346 
347   \textcolor{comment}{! Local variables}
348   \textcolor{keywordtype}{real}, \textcolor{keywordtype}{dimension(SZI\_(G), SZJ\_(G), SZK\_(G)+1)} :: &
349     w\_int, &       \textcolor{comment}{! Water moved upward across an interface within a timestep,}
350                    \textcolor{comment}{! [H ~> m or kg m-2].}
351     e\_d            \textcolor{comment}{! Interface heights that are dilated to have a value of 0}
352                    \textcolor{comment}{! at the surface [Z ~> m].}
353   \textcolor{keywordtype}{real}, \textcolor{keywordtype}{dimension(SZI\_(G), SZJ\_(G))} :: &
354     eta\_anom, &    \textcolor{comment}{! Anomalies in the interface height, relative to the i-mean}
355                    \textcolor{comment}{! target value [Z ~> m].}
356     fld\_anom       \textcolor{comment}{! Anomalies in a tracer concentration, relative to the}
357                    \textcolor{comment}{! i-mean target value.}
358   \textcolor{keywordtype}{real}, \textcolor{keywordtype}{dimension(SZJ\_(G), SZK\_(G)+1)} :: &
359     eta\_mean\_anom  \textcolor{comment}{! The i-mean interface height anomalies [Z ~> m].}
360   \textcolor{keywordtype}{real}, \textcolor{keywordtype}{allocatable}, \textcolor{keywordtype}{dimension(:,:,:)} :: &
361     fld\_mean\_anom  \textcolor{comment}{! THe i-mean tracer concentration anomalies.}
362   \textcolor{keywordtype}{real}, \textcolor{keywordtype}{dimension(SZI\_(G), SZK\_(G)+1)} :: &
363     h\_above, &     \textcolor{comment}{! The total thickness above an interface [H ~> m or kg m-2].}
364     h\_below        \textcolor{comment}{! The total thickness below an interface [H ~> m or kg m-2].}
365   \textcolor{keywordtype}{real}, \textcolor{keywordtype}{dimension(SZI\_(G))} :: &
366     dilate         \textcolor{comment}{! A nondimensional factor by which to dilate layers to}
367                    \textcolor{comment}{! give 0 at the surface [nondim].}
368 
369   \textcolor{keywordtype}{real} :: e(szk\_(g)+1)  \textcolor{comment}{! The interface heights [Z ~> m], usually negative.}
370   \textcolor{keywordtype}{real} :: e0       \textcolor{comment}{! The height of the free surface [Z ~> m].}
371   \textcolor{keywordtype}{real} :: e\_str    \textcolor{comment}{! A nondimensional amount by which the reference}
372                    \textcolor{comment}{! profile must be stretched for the free surfaces}
373                    \textcolor{comment}{! heights in the two profiles to agree.}
374   \textcolor{keywordtype}{real} :: w        \textcolor{comment}{! The thickness of water moving upward through an}
375                    \textcolor{comment}{! interface within 1 timestep [H ~> m or kg m-2].}
376   \textcolor{keywordtype}{real} :: wm       \textcolor{comment}{! wm is w if w is negative and 0 otherwise [H ~> m or kg m-2].}
377   \textcolor{keywordtype}{real} :: wb       \textcolor{comment}{! w at the interface below a layer [H ~> m or kg m-2].}
378   \textcolor{keywordtype}{real} :: wpb      \textcolor{comment}{! wpb is wb if wb is positive and 0 otherwise [H ~> m or kg m-2].}
379   \textcolor{keywordtype}{real} :: ea\_k, eb\_k \textcolor{comment}{! [H ~> m or kg m-2]}
380   \textcolor{keywordtype}{real} :: damp     \textcolor{comment}{! The timestep times the local damping  coefficient [nondim].}
381   \textcolor{keywordtype}{real} :: i1pdamp  \textcolor{comment}{! I1pdamp is 1/(1 + damp). [nondim]}
382   \textcolor{keywordtype}{real} :: damp\_1pdamp \textcolor{comment}{! damp\_1pdamp is damp/(1 + damp). [nondim]}
383   \textcolor{keywordtype}{real} :: idt      \textcolor{comment}{! 1.0/dt times a height unit conversion factor [m H-1 T-1 ~> s-1 or m3 kg-1 s-1].}
384   \textcolor{keywordtype}{integer} :: c, m, nkmb, i, j, k, is, ie, js, je, nz
385   is = g%isc ; ie = g%iec ; js = g%jsc ; je = g%jec ; nz = g%ke
386 
387   \textcolor{keywordflow}{if} (.not.\textcolor{keyword}{associated}(cs)) \textcolor{keywordflow}{return}
388   \textcolor{keywordflow}{if} (cs%bulkmixedlayer) nkmb = gv%nk\_rho\_varies
389   \textcolor{keywordflow}{if} (cs%bulkmixedlayer .and. (.not.\textcolor{keyword}{present}(rcv\_ml))) &
390     \textcolor{keyword}{call }mom\_error(fatal, \textcolor{stringliteral}{"Rml must be provided to apply\_sponge when using "}//&
391                            \textcolor{stringliteral}{"a bulk mixed layer."})
392 
393   \textcolor{keywordflow}{if} ((cs%id\_w\_sponge > 0) .or. cs%do\_i\_mean\_sponge) \textcolor{keywordflow}{then}
394     \textcolor{keywordflow}{do} k=1,nz+1 ; \textcolor{keywordflow}{do} j=js,je ; \textcolor{keywordflow}{do} i=is,ie
395       w\_int(i,j,k) = 0.0
396 \textcolor{keywordflow}{    enddo} ;\textcolor{keywordflow}{ enddo} ;\textcolor{keywordflow}{ enddo}
397 \textcolor{keywordflow}{  endif}
398 
399   \textcolor{keywordflow}{if} (cs%do\_i\_mean\_sponge) \textcolor{keywordflow}{then}
400     \textcolor{comment}{! Apply forcing to restore the zonal-mean properties to prescribed values.}
401 
402     \textcolor{keywordflow}{if} (cs%bulkmixedlayer) \textcolor{keyword}{call }mom\_error(fatal, \textcolor{stringliteral}{"apply\_sponge is not yet set up to "}//&
403                   \textcolor{stringliteral}{"work properly with i-mean sponges and a bulk mixed layer."})
404 
405     \textcolor{keywordflow}{do} j=js,je ; \textcolor{keywordflow}{do} i=is,ie ; e\_d(i,j,nz+1) = -g%bathyT(i,j) ;\textcolor{keywordflow}{ enddo} ;\textcolor{keywordflow}{ enddo}
406     \textcolor{keywordflow}{do} k=nz,1,-1 ; \textcolor{keywordflow}{do} j=js,je ; \textcolor{keywordflow}{do} i=is,ie
407       e\_d(i,j,k) = e\_d(i,j,k+1) + h(i,j,k)*gv%H\_to\_Z
408 \textcolor{keywordflow}{    enddo} ;\textcolor{keywordflow}{ enddo} ;\textcolor{keywordflow}{ enddo}
409     \textcolor{keywordflow}{do} j=js,je
410       \textcolor{keywordflow}{do} i=is,ie
411         dilate(i) = g%bathyT(i,j) / (e\_d(i,j,1) + g%bathyT(i,j))
412 \textcolor{keywordflow}{      enddo}
413       \textcolor{keywordflow}{do} k=1,nz+1 ; \textcolor{keywordflow}{do} i=is,ie
414         e\_d(i,j,k) = dilate(i) * (e\_d(i,j,k) + g%bathyT(i,j)) - g%bathyT(i,j)
415 \textcolor{keywordflow}{      enddo} ;\textcolor{keywordflow}{ enddo}
416 \textcolor{keywordflow}{    enddo}
417 
418     \textcolor{keywordflow}{do} k=2,nz
419       \textcolor{keywordflow}{do} j=js,je ; \textcolor{keywordflow}{do} i=is,ie
420         eta\_anom(i,j) = e\_d(i,j,k) - cs%Ref\_eta\_im(j,k)
421         \textcolor{keywordflow}{if} (cs%Ref\_eta\_im(j,k) < -g%bathyT(i,j)) eta\_anom(i,j) = 0.0
422 \textcolor{keywordflow}{      enddo} ;\textcolor{keywordflow}{ enddo}
423       \textcolor{keyword}{call }global\_i\_mean(eta\_anom(:,:), eta\_mean\_anom(:,k), g, tmp\_scale=us%Z\_to\_m)
424 \textcolor{keywordflow}{    enddo}
425 
426     \textcolor{keywordflow}{if} (cs%fldno > 0) \textcolor{keyword}{allocate}(fld\_mean\_anom(g%isd:g%ied,nz,cs%fldno))
427     \textcolor{keywordflow}{do} m=1,cs%fldno
428       \textcolor{keywordflow}{do} j=js,je ; \textcolor{keywordflow}{do} i=is,ie
429         fld\_anom(i,j) = cs%var(m)%p(i,j,k) - cs%Ref\_val\_im(m)%p(j,k)
430 \textcolor{keywordflow}{      enddo} ;\textcolor{keywordflow}{ enddo}
431       \textcolor{keyword}{call }global\_i\_mean(fld\_anom(:,:), fld\_mean\_anom(:,k,m), g, h(:,:,k))
432 \textcolor{keywordflow}{    enddo}
433 
434     \textcolor{keywordflow}{do} j=js,je ; \textcolor{keywordflow}{if} (cs%Iresttime\_im(j) > 0.0) \textcolor{keywordflow}{then}
435       damp = dt * cs%Iresttime\_im(j) ; damp\_1pdamp = damp / (1.0 + damp)
436 
437       \textcolor{keywordflow}{do} i=is,ie
438         h\_above(i,1) = 0.0 ; h\_below(i,nz+1) = 0.0
439 \textcolor{keywordflow}{      enddo}
440       \textcolor{keywordflow}{do} k=nz,1,-1 ; \textcolor{keywordflow}{do} i=is,ie
441         h\_below(i,k) = h\_below(i,k+1) + max(h(i,j,k)-gv%Angstrom\_H, 0.0)
442 \textcolor{keywordflow}{      enddo} ;\textcolor{keywordflow}{ enddo}
443       \textcolor{keywordflow}{do} k=2,nz+1 ; \textcolor{keywordflow}{do} i=is,ie
444         h\_above(i,k) = h\_above(i,k-1) + max(h(i,j,k-1)-gv%Angstrom\_H, 0.0)
445 \textcolor{keywordflow}{      enddo} ;\textcolor{keywordflow}{ enddo}
446       \textcolor{keywordflow}{do} k=2,nz
447         \textcolor{comment}{! w is positive for an upward (lightward) flux of mass, resulting}
448         \textcolor{comment}{! in the downward movement of an interface.}
449         w = damp\_1pdamp * eta\_mean\_anom(j,k) * gv%Z\_to\_H
450         \textcolor{keywordflow}{do} i=is,ie
451           \textcolor{keywordflow}{if} (w > 0.0) \textcolor{keywordflow}{then}
452             w\_int(i,j,k) = min(w, h\_below(i,k))
453             eb(i,j,k-1) = eb(i,j,k-1) + w\_int(i,j,k)
454           \textcolor{keywordflow}{else}
455             w\_int(i,j,k) = max(w, -h\_above(i,k))
456             ea(i,j,k) = ea(i,j,k) - w\_int(i,j,k)
457 \textcolor{keywordflow}{          endif}
458 \textcolor{keywordflow}{        enddo}
459 \textcolor{keywordflow}{      enddo}
460       \textcolor{keywordflow}{do} k=1,nz ; \textcolor{keywordflow}{do} i=is,ie
461         ea\_k = max(0.0, -w\_int(i,j,k))
462         eb\_k = max(0.0, w\_int(i,j,k+1))
463         \textcolor{keywordflow}{do} m=1,cs%fldno
464           cs%var(m)%p(i,j,k) = (h(i,j,k)*cs%var(m)%p(i,j,k) + &
465               cs%Ref\_val\_im(m)%p(j,k) * (ea\_k + eb\_k)) / &
466                      (h(i,j,k) + (ea\_k + eb\_k)) - &
467               damp\_1pdamp * fld\_mean\_anom(j,k,m)
468 \textcolor{keywordflow}{        enddo}
469 
470         h(i,j,k) = max(h(i,j,k) + (w\_int(i,j,k+1) - w\_int(i,j,k)), &
471                        min(h(i,j,k), gv%Angstrom\_H))
472 \textcolor{keywordflow}{      enddo} ;\textcolor{keywordflow}{ enddo}
473 \textcolor{keywordflow}{    endif} ;\textcolor{keywordflow}{ enddo}
474 
475     \textcolor{keywordflow}{if} (cs%fldno > 0) \textcolor{keyword}{deallocate}(fld\_mean\_anom)
476 
477 \textcolor{keywordflow}{  endif}
478 
479   \textcolor{keywordflow}{do} c=1,cs%num\_col
480 \textcolor{comment}{! c is an index for the next 3 lines but a multiplier for the rest of the loop}
481 \textcolor{comment}{! Therefore we use c as per C code and increment the index where necessary.}
482     i = cs%col\_i(c) ; j = cs%col\_j(c)
483     damp = dt * cs%Iresttime\_col(c)
484 
485     e(1) = 0.0 ; e0 = 0.0
486     \textcolor{keywordflow}{do} k=1,nz
487       e(k+1) = e(k) - h(i,j,k)*gv%H\_to\_Z
488 \textcolor{keywordflow}{    enddo}
489     e\_str = e(nz+1) / cs%Ref\_eta(nz+1,c)
490 
491     \textcolor{keywordflow}{if} ( cs%bulkmixedlayer ) \textcolor{keywordflow}{then}
492       i1pdamp = 1.0 / (1.0 + damp)
493       \textcolor{keywordflow}{if} (\textcolor{keyword}{associated}(cs%Rcv\_ml\_ref)) &
494         rcv\_ml(i,j) = i1pdamp * (rcv\_ml(i,j) + cs%Rcv\_ml\_ref(c)*damp)
495       \textcolor{keywordflow}{do} k=1,nkmb
496         \textcolor{keywordflow}{do} m=1,cs%fldno
497           cs%var(m)%p(i,j,k) = i1pdamp * &
498               (cs%var(m)%p(i,j,k) + cs%Ref\_val(m)%p(k,c)*damp)
499 \textcolor{keywordflow}{        enddo}
500 \textcolor{keywordflow}{      enddo}
501 
502       wpb = 0.0; wb = 0.0
503       \textcolor{keywordflow}{do} k=nz,nkmb+1,-1
504         \textcolor{keywordflow}{if} (gv%Rlay(k) > rcv\_ml(i,j)) \textcolor{keywordflow}{then}
505           w = min((((e(k)-e0) - e\_str*cs%Ref\_eta(k,c)) * damp)*gv%Z\_to\_H, &
506                     ((wb + h(i,j,k)) - gv%Angstrom\_H))
507           wm = 0.5*(w-abs(w))
508           \textcolor{keywordflow}{do} m=1,cs%fldno
509             cs%var(m)%p(i,j,k) = (h(i,j,k)*cs%var(m)%p(i,j,k) + &
510                      cs%Ref\_val(m)%p(k,c)*(damp*h(i,j,k) + (wpb - wm))) / &
511                      (h(i,j,k)*(1.0 + damp) + (wpb - wm))
512 \textcolor{keywordflow}{          enddo}
513         \textcolor{keywordflow}{else}
514           \textcolor{keywordflow}{do} m=1,cs%fldno
515             cs%var(m)%p(i,j,k) = i1pdamp * &
516               (cs%var(m)%p(i,j,k) + cs%Ref\_val(m)%p(k,c)*damp)
517 \textcolor{keywordflow}{          enddo}
518           w = wb + (h(i,j,k) - gv%Angstrom\_H)
519           wm = 0.5*(w-abs(w))
520 \textcolor{keywordflow}{        endif}
521         eb(i,j,k) = eb(i,j,k) + wpb
522         ea(i,j,k) = ea(i,j,k) - wm
523         h(i,j,k)  = h(i,j,k)  + (wb - w)
524         wb = w
525         wpb = w - wm
526 \textcolor{keywordflow}{      enddo}
527 
528       \textcolor{keywordflow}{if} (wb < 0) \textcolor{keywordflow}{then}
529         \textcolor{keywordflow}{do} k=nkmb,1,-1
530           w = min((wb + (h(i,j,k) - gv%Angstrom\_H)),0.0)
531           h(i,j,k)  = h(i,j,k)  + (wb - w)
532           ea(i,j,k) = ea(i,j,k) - w
533           wb = w
534 \textcolor{keywordflow}{        enddo}
535       \textcolor{keywordflow}{else}
536         w = wb
537         \textcolor{keywordflow}{do} k=gv%nkml,nkmb
538           eb(i,j,k) = eb(i,j,k) + w
539 \textcolor{keywordflow}{        enddo}
540 
541         k = gv%nkml
542         h(i,j,k) = h(i,j,k) + w
543         \textcolor{keywordflow}{do} m=1,cs%fldno
544           cs%var(m)%p(i,j,k) = (cs%var(m)%p(i,j,k)*h(i,j,k) + &
545                                 cs%Ref\_val(m)%p(k,c)*w) / (h(i,j,k) + w)
546 \textcolor{keywordflow}{        enddo}
547 \textcolor{keywordflow}{      endif}
548 
549       \textcolor{keywordflow}{do} k=1,nkmb
550         \textcolor{keywordflow}{do} m=1,cs%fldno
551           cs%var(m)%p(i,j,k) = i1pdamp * &
552               (cs%var(m)%p(i,j,k) + cs%Ref\_val(m)%p(gv%nkml,c)*damp)
553 \textcolor{keywordflow}{        enddo}
554 \textcolor{keywordflow}{      enddo}
555 
556     \textcolor{keywordflow}{else}                                          \textcolor{comment}{! not BULKMIXEDLAYER}
557 
558       wpb = 0.0
559       wb = 0.0
560       \textcolor{keywordflow}{do} k=nz,1,-1
561         w = min((((e(k)-e0) - e\_str*cs%Ref\_eta(k,c)) * damp)*gv%Z\_to\_H, &
562                   ((wb + h(i,j,k)) - gv%Angstrom\_H))
563         wm = 0.5*(w - abs(w))
564         \textcolor{keywordflow}{do} m=1,cs%fldno
565           cs%var(m)%p(i,j,k) = (h(i,j,k)*cs%var(m)%p(i,j,k) + &
566               cs%Ref\_val(m)%p(k,c) * (damp*h(i,j,k) + (wpb - wm))) / &
567                      (h(i,j,k)*(1.0 + damp) + (wpb - wm))
568 \textcolor{keywordflow}{        enddo}
569         eb(i,j,k) = eb(i,j,k) + wpb
570         ea(i,j,k) = ea(i,j,k) - wm
571         h(i,j,k)  = h(i,j,k)  + (wb - w)
572         wb = w
573         wpb = w - wm
574 \textcolor{keywordflow}{      enddo}
575 
576 \textcolor{keywordflow}{    endif}                                         \textcolor{comment}{! end BULKMIXEDLAYER}
577 \textcolor{keywordflow}{  enddo} \textcolor{comment}{! end of c loop}
578 
579   \textcolor{keywordflow}{if} (\textcolor{keyword}{associated}(cs%diag)) \textcolor{keywordflow}{then} ; \textcolor{keywordflow}{if} (query\_averaging\_enabled(cs%diag)) \textcolor{keywordflow}{then}
580     \textcolor{keywordflow}{if} (cs%id\_w\_sponge > 0) \textcolor{keywordflow}{then}
581       idt = gv%H\_to\_m / dt  \textcolor{comment}{! Do any height unit conversion here for efficiency.}
582       \textcolor{keywordflow}{do} k=1,nz+1 ; \textcolor{keywordflow}{do} j=js,je ; \textcolor{keywordflow}{do} i=is,ie
583         w\_int(i,j,k) = w\_int(i,j,k) * idt \textcolor{comment}{! Scale values by clobbering array since it is local}
584 \textcolor{keywordflow}{      enddo} ;\textcolor{keywordflow}{ enddo} ;\textcolor{keywordflow}{ enddo}
585       \textcolor{keyword}{call }post\_data(cs%id\_w\_sponge, w\_int(:,:,:), cs%diag)
586 \textcolor{keywordflow}{    endif}
587 \textcolor{keywordflow}{  endif} ;\textcolor{keywordflow}{ endif}
588 
\end{DoxyCode}
\mbox{\Hypertarget{namespacemom__sponge_ad4b2c0efb73f14a43936a11b39027f57}\label{namespacemom__sponge_ad4b2c0efb73f14a43936a11b39027f57}} 
\index{mom\+\_\+sponge@{mom\+\_\+sponge}!init\+\_\+sponge\+\_\+diags@{init\+\_\+sponge\+\_\+diags}}
\index{init\+\_\+sponge\+\_\+diags@{init\+\_\+sponge\+\_\+diags}!mom\+\_\+sponge@{mom\+\_\+sponge}}
\subsubsection{\texorpdfstring{init\+\_\+sponge\+\_\+diags()}{init\_sponge\_diags()}}
{\footnotesize\ttfamily subroutine, public mom\+\_\+sponge\+::init\+\_\+sponge\+\_\+diags (\begin{DoxyParamCaption}\item[{type(time\+\_\+type), intent(in), target}]{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[{type(diag\+\_\+ctrl), intent(inout), target}]{diag,  }\item[{type(\hyperlink{structmom__sponge_1_1sponge__cs}{sponge\+\_\+cs}), pointer}]{CS }\end{DoxyParamCaption})}



This subroutine sets up diagnostics for the sponges. It is separate from initialize\+\_\+sponge because it requires fields that are not readily available where initialize\+\_\+sponge is called. 


\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}  & {\em gv} & The ocean\textquotesingle{}s vertical grid structure\\
\hline
\mbox{\tt in}  & {\em us} & A dimensional unit scaling type\\
\hline
\mbox{\tt in,out}  & {\em diag} & A structure that is used to regulate diagnostic output\\
\hline
 & {\em cs} & A pointer to the control structure for this module that is set by a previous call to initialize\+\_\+sponge. \\
\hline
\end{DoxyParams}


Definition at line 194 of file M\+O\+M\+\_\+sponge.\+F90.


\begin{DoxyCode}
194   \textcolor{keywordtype}{type}(time\_type),       \textcolor{keywordtype}{target}, \textcolor{keywordtype}{intent(in)}    :: time\textcolor{comment}{ !< The current model time}
195   \textcolor{keywordtype}{type}(ocean\_grid\_type),         \textcolor{keywordtype}{intent(in)}    :: g\textcolor{comment}{    !< The ocean's grid structure}
196   \textcolor{keywordtype}{type}(verticalgrid\_type),       \textcolor{keywordtype}{intent(in)}    :: gv\textcolor{comment}{   !< The ocean's vertical grid structure}
197   \textcolor{keywordtype}{type}(unit\_scale\_type),         \textcolor{keywordtype}{intent(in)}    :: us\textcolor{comment}{   !< A dimensional unit scaling type}
198   \textcolor{keywordtype}{type}(diag\_ctrl),       \textcolor{keywordtype}{target}, \textcolor{keywordtype}{intent(inout)} :: diag\textcolor{comment}{ !< A structure that is used to regulate diagnostic
       output}
199   \textcolor{keywordtype}{type}(sponge\_cs),               \textcolor{keywordtype}{pointer}       :: cs\textcolor{comment}{   !< A pointer to the control structure for this
       module that}
200 \textcolor{comment}{                                                       !! is set by a previous call to initialize\_sponge.}
201 
202   \textcolor{keywordflow}{if} (.not.\textcolor{keyword}{associated}(cs)) \textcolor{keywordflow}{return}
203 
204   cs%diag => diag
205   cs%id\_w\_sponge = register\_diag\_field(\textcolor{stringliteral}{'ocean\_model'}, \textcolor{stringliteral}{'w\_sponge'}, diag%axesTi, &
206       time, \textcolor{stringliteral}{'The diapycnal motion due to the sponges'}, \textcolor{stringliteral}{'m s-1'}, conversion=us%s\_to\_T)
207 
\end{DoxyCode}
\mbox{\Hypertarget{namespacemom__sponge_a2c3c6a03d98c13221031af667b42428d}\label{namespacemom__sponge_a2c3c6a03d98c13221031af667b42428d}} 
\index{mom\+\_\+sponge@{mom\+\_\+sponge}!initialize\+\_\+sponge@{initialize\+\_\+sponge}}
\index{initialize\+\_\+sponge@{initialize\+\_\+sponge}!mom\+\_\+sponge@{mom\+\_\+sponge}}
\subsubsection{\texorpdfstring{initialize\+\_\+sponge()}{initialize\_sponge()}}
{\footnotesize\ttfamily subroutine, public mom\+\_\+sponge\+::initialize\+\_\+sponge (\begin{DoxyParamCaption}\item[{real, dimension(szi\+\_\+(g),szj\+\_\+(g)), intent(in)}]{Iresttime,  }\item[{real, dimension(szi\+\_\+(g),szj\+\_\+(g),szk\+\_\+(g)+1), intent(in)}]{int\+\_\+height,  }\item[{type(ocean\+\_\+grid\+\_\+type), intent(in)}]{G,  }\item[{type(param\+\_\+file\+\_\+type), intent(in)}]{param\+\_\+file,  }\item[{type(\hyperlink{structmom__sponge_1_1sponge__cs}{sponge\+\_\+cs}), pointer}]{CS,  }\item[{type(verticalgrid\+\_\+type), intent(in)}]{GV,  }\item[{real, dimension( g \%jsd\+: g \%jed), intent(in), optional}]{Iresttime\+\_\+i\+\_\+mean,  }\item[{real, dimension( g \%jsd\+: g \%jed, g \%ke+1), intent(in), optional}]{int\+\_\+height\+\_\+i\+\_\+mean }\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 iresttime} & The inverse of the restoring time \mbox{[}T-\/1 $\sim$$>$ s-\/1\mbox{]}.\\
\hline
\mbox{\tt in}  & {\em int\+\_\+height} & The interface heights to damp back toward \mbox{[}Z $\sim$$>$ m\mbox{]}.\\
\hline
\mbox{\tt in}  & {\em param\+\_\+file} & A structure to parse for run-\/time parameters\\
\hline
 & {\em cs} & A pointer that is set to point to the control structure for this module\\
\hline
\mbox{\tt in}  & {\em gv} & The ocean\textquotesingle{}s vertical grid structure\\
\hline
\mbox{\tt in}  & {\em iresttime\+\_\+i\+\_\+mean} & The inverse of the restoring time for\\
\hline
\mbox{\tt in}  & {\em int\+\_\+height\+\_\+i\+\_\+mean} & The interface heights toward which to \\
\hline
\end{DoxyParams}


Definition at line 90 of file M\+O\+M\+\_\+sponge.\+F90.


\begin{DoxyCode}
90   \textcolor{keywordtype}{type}(ocean\_grid\_type),   \textcolor{keywordtype}{intent(in)} :: g\textcolor{comment}{          !< The ocean's grid structure}
91   \textcolor{keywordtype}{real}, \textcolor{keywordtype}{dimension(SZI\_(G),SZJ\_(G))}, &
92                            \textcolor{keywordtype}{intent(in)} :: iresttime\textcolor{comment}{  !< The inverse of the restoring time [T-1 ~> s-1].}
93   \textcolor{keywordtype}{real}, \textcolor{keywordtype}{dimension(SZI\_(G),SZJ\_(G),SZK\_(G)+1)}, &
94                            \textcolor{keywordtype}{intent(in)} :: int\_height\textcolor{comment}{ !< The interface heights to damp back toward [Z ~> m].}
95   \textcolor{keywordtype}{type}(param\_file\_type),   \textcolor{keywordtype}{intent(in)} :: param\_file\textcolor{comment}{ !< A structure to parse for run-time parameters}
96   \textcolor{keywordtype}{type}(sponge\_cs),         \textcolor{keywordtype}{pointer}    :: cs\textcolor{comment}{         !< A pointer that is set to point to the control}
97 \textcolor{comment}{                                                    !! structure for this module}
98   \textcolor{keywordtype}{type}(verticalgrid\_type), \textcolor{keywordtype}{intent(in)} :: gv\textcolor{comment}{         !< The ocean's vertical grid structure}
99   \textcolor{keywordtype}{real}, \textcolor{keywordtype}{dimension(SZJ\_(G))}, &
100                  \textcolor{keywordtype}{optional}, \textcolor{keywordtype}{intent(in)} :: iresttime\_i\_mean\textcolor{comment}{ !< The inverse of the restoring time for}
101 \textcolor{comment}{                                                          !! the zonal mean properties [T-1 ~> s-1].}
102   \textcolor{keywordtype}{real}, \textcolor{keywordtype}{dimension(SZJ\_(G),SZK\_(G)+1)}, &
103                  \textcolor{keywordtype}{optional}, \textcolor{keywordtype}{intent(in)} :: int\_height\_i\_mean\textcolor{comment}{ !< The interface heights toward which to}
104 \textcolor{comment}{                                                           !! damp the zonal mean heights [Z ~> m].}
105 
106 
107 \textcolor{comment}{! This include declares and sets the variable "version".}
108 \textcolor{preprocessor}{#include "version\_variable.h"}
109 \textcolor{preprocessor}{}  \textcolor{keywordtype}{character(len=40)}  :: mdl = \textcolor{stringliteral}{"MOM\_sponge"}  \textcolor{comment}{! This module's name.}
110   \textcolor{keywordtype}{logical} :: use\_sponge
111   \textcolor{keywordtype}{integer} :: i, j, k, col, total\_sponge\_cols
112 
113   \textcolor{keywordflow}{if} (\textcolor{keyword}{associated}(cs)) \textcolor{keywordflow}{then}
114     \textcolor{keyword}{call }mom\_error(warning, \textcolor{stringliteral}{"initialize\_sponge called with an associated "}// &
115                             \textcolor{stringliteral}{"control structure."})
116     \textcolor{keywordflow}{return}
117 \textcolor{keywordflow}{  endif}
118 
119 \textcolor{comment}{! Set default, read and log parameters}
120   \textcolor{keyword}{call }log\_version(param\_file, mdl, version)
121   \textcolor{keyword}{call }get\_param(param\_file, mdl, \textcolor{stringliteral}{"SPONGE"}, use\_sponge, &
122                  \textcolor{stringliteral}{"If true, sponges may be applied anywhere in the domain. "}//&
123                  \textcolor{stringliteral}{"The exact location and properties of those sponges are "}//&
124                  \textcolor{stringliteral}{"specified from MOM\_initialization.F90."}, default=.false.)
125 
126   \textcolor{keywordflow}{if} (.not.use\_sponge) \textcolor{keywordflow}{return}
127   \textcolor{keyword}{allocate}(cs)
128 
129   \textcolor{keywordflow}{if} (\textcolor{keyword}{present}(iresttime\_i\_mean) .neqv. \textcolor{keyword}{present}(int\_height\_i\_mean)) &
130     \textcolor{keyword}{call }mom\_error(fatal, \textcolor{stringliteral}{"initialize\_sponge:  The optional arguments \(\backslash\)n"}//&
131            \textcolor{stringliteral}{"Iresttime\_i\_mean and int\_height\_i\_mean must both be present \(\backslash\)n"}//&
132            \textcolor{stringliteral}{"if either one is."})
133 
134   cs%do\_i\_mean\_sponge = \textcolor{keyword}{present}(iresttime\_i\_mean)
135 
136   cs%nz = g%ke
137 \textcolor{comment}{!  CS%isc = G%isc ; CS%iec = G%iec ; CS%jsc = G%jsc ; CS%jec = G%jec}
138 \textcolor{comment}{!  CS%isd = G%isd ; CS%ied = G%ied ; CS%jsd = G%jsd ; CS%jed = G%jed}
139   \textcolor{comment}{! CS%bulkmixedlayer may be set later via a call to set\_up\_sponge\_ML\_density.}
140   cs%bulkmixedlayer = .false.
141 
142   cs%num\_col = 0 ; cs%fldno = 0
143   \textcolor{keywordflow}{do} j=g%jsc,g%jec ; \textcolor{keywordflow}{do} i=g%isc,g%iec
144     \textcolor{keywordflow}{if} ((iresttime(i,j)>0.0) .and. (g%mask2dT(i,j)>0)) &
145       cs%num\_col = cs%num\_col + 1
146 \textcolor{keywordflow}{  enddo} ;\textcolor{keywordflow}{ enddo}
147 
148   \textcolor{keywordflow}{if} (cs%num\_col > 0) \textcolor{keywordflow}{then}
149 
150     \textcolor{keyword}{allocate}(cs%Iresttime\_col(cs%num\_col)) ; cs%Iresttime\_col = 0.0
151     \textcolor{keyword}{allocate}(cs%col\_i(cs%num\_col))         ; cs%col\_i = 0
152     \textcolor{keyword}{allocate}(cs%col\_j(cs%num\_col))         ; cs%col\_j = 0
153 
154     col = 1
155     \textcolor{keywordflow}{do} j=g%jsc,g%jec ; \textcolor{keywordflow}{do} i=g%isc,g%iec
156       \textcolor{keywordflow}{if} ((iresttime(i,j)>0.0) .and. (g%mask2dT(i,j)>0)) \textcolor{keywordflow}{then}
157         cs%col\_i(col) = i ; cs%col\_j(col) = j
158         cs%Iresttime\_col(col) = iresttime(i,j)
159         col = col +1
160 \textcolor{keywordflow}{      endif}
161 \textcolor{keywordflow}{    enddo} ;\textcolor{keywordflow}{ enddo}
162 
163     \textcolor{keyword}{allocate}(cs%Ref\_eta(cs%nz+1,cs%num\_col))
164     \textcolor{keywordflow}{do} col=1,cs%num\_col ; \textcolor{keywordflow}{do} k=1,cs%nz+1
165       cs%Ref\_eta(k,col) = int\_height(cs%col\_i(col),cs%col\_j(col),k)
166 \textcolor{keywordflow}{    enddo} ;\textcolor{keywordflow}{ enddo}
167 
168 \textcolor{keywordflow}{  endif}
169 
170   \textcolor{keywordflow}{if} (cs%do\_i\_mean\_sponge) \textcolor{keywordflow}{then}
171     \textcolor{keyword}{allocate}(cs%Iresttime\_im(g%jsd:g%jed)) ; cs%Iresttime\_im(:) = 0.0
172     \textcolor{keyword}{allocate}(cs%Ref\_eta\_im(g%jsd:g%jed,g%ke+1)) ; cs%Ref\_eta\_im(:,:) = 0.0
173 
174     \textcolor{keywordflow}{do} j=g%jsc,g%jec
175       cs%Iresttime\_im(j) = iresttime\_i\_mean(j)
176 \textcolor{keywordflow}{    enddo}
177     \textcolor{keywordflow}{do} k=1,cs%nz+1 ; \textcolor{keywordflow}{do} j=g%jsc,g%jec
178       cs%Ref\_eta\_im(j,k) = int\_height\_i\_mean(j,k)
179 \textcolor{keywordflow}{    enddo} ;\textcolor{keywordflow}{ enddo}
180 \textcolor{keywordflow}{  endif}
181 
182   total\_sponge\_cols = cs%num\_col
183   \textcolor{keyword}{call }sum\_across\_pes(total\_sponge\_cols)
184 
185   \textcolor{keyword}{call }log\_param(param\_file, mdl, \textcolor{stringliteral}{"!Total sponge columns"}, total\_sponge\_cols, &
186                  \textcolor{stringliteral}{"The total number of columns where sponges are applied."})
187 
\end{DoxyCode}
\mbox{\Hypertarget{namespacemom__sponge_af3da4a8b352c4130919d7bfedf1a5a3e}\label{namespacemom__sponge_af3da4a8b352c4130919d7bfedf1a5a3e}} 
\index{mom\+\_\+sponge@{mom\+\_\+sponge}!set\+\_\+up\+\_\+sponge\+\_\+field@{set\+\_\+up\+\_\+sponge\+\_\+field}}
\index{set\+\_\+up\+\_\+sponge\+\_\+field@{set\+\_\+up\+\_\+sponge\+\_\+field}!mom\+\_\+sponge@{mom\+\_\+sponge}}
\subsubsection{\texorpdfstring{set\+\_\+up\+\_\+sponge\+\_\+field()}{set\_up\_sponge\_field()}}
{\footnotesize\ttfamily subroutine, public mom\+\_\+sponge\+::set\+\_\+up\+\_\+sponge\+\_\+field (\begin{DoxyParamCaption}\item[{real, dimension( g \%isd\+: g \%ied, g \%jsd\+: g \%jed, g \%ke), intent(in)}]{sp\+\_\+val,  }\item[{real, dimension( g \%isd\+: g \%ied, g \%jsd\+: g \%jed, g \%ke), intent(in), target}]{f\+\_\+ptr,  }\item[{type(ocean\+\_\+grid\+\_\+type), intent(in)}]{G,  }\item[{integer, intent(in)}]{nlay,  }\item[{type(\hyperlink{structmom__sponge_1_1sponge__cs}{sponge\+\_\+cs}), pointer}]{CS,  }\item[{real, dimension( g \%jsd\+: g \%jed, g \%ke), intent(in), optional}]{sp\+\_\+val\+\_\+i\+\_\+mean }\end{DoxyParamCaption})}



This subroutine stores the reference profile for the variable whose address is given by f\+\_\+ptr. nlay is the number of layers in this variable. 


\begin{DoxyParams}[1]{Parameters}
\mbox{\tt in}  & {\em g} & The ocean\textquotesingle{}s grid structure\\
\hline
\mbox{\tt in}  & {\em sp\+\_\+val} & The reference profiles of the quantity being registered.\\
\hline
\mbox{\tt in}  & {\em f\+\_\+ptr} & a pointer to the field which will be damped\\
\hline
\mbox{\tt in}  & {\em nlay} & the number of layers in this quantity\\
\hline
 & {\em cs} & A pointer to the control structure for this module that is set by a previous call to initialize\+\_\+sponge.\\
\hline
\mbox{\tt in}  & {\em sp\+\_\+val\+\_\+i\+\_\+mean} & The i-\/mean reference value for \\
\hline
\end{DoxyParams}


Definition at line 214 of file M\+O\+M\+\_\+sponge.\+F90.


\begin{DoxyCode}
214   \textcolor{keywordtype}{type}(ocean\_grid\_type), \textcolor{keywordtype}{intent(in)} :: g\textcolor{comment}{      !< The ocean's grid structure}
215   \textcolor{keywordtype}{real}, \textcolor{keywordtype}{dimension(SZI\_(G),SZJ\_(G),SZK\_(G))}, &
216                          \textcolor{keywordtype}{intent(in)} :: sp\_val\textcolor{comment}{ !< The reference profiles of the quantity being registered.}
217   \textcolor{keywordtype}{real}, \textcolor{keywordtype}{dimension(SZI\_(G),SZJ\_(G),SZK\_(G))}, &
218                  \textcolor{keywordtype}{target}, \textcolor{keywordtype}{intent(in)} :: f\_ptr\textcolor{comment}{  !< a pointer to the field which will be damped}
219   \textcolor{keywordtype}{integer},               \textcolor{keywordtype}{intent(in)} :: nlay\textcolor{comment}{   !< the number of layers in this quantity}
220   \textcolor{keywordtype}{type}(sponge\_cs),       \textcolor{keywordtype}{pointer}    :: cs\textcolor{comment}{     !< A pointer to the control structure for this module that}
221 \textcolor{comment}{                                              !! is set by a previous call to initialize\_sponge.}
222   \textcolor{keywordtype}{real}, \textcolor{keywordtype}{dimension(SZJ\_(G),SZK\_(G))},&
223                \textcolor{keywordtype}{optional}, \textcolor{keywordtype}{intent(in)} :: sp\_val\_i\_mean\textcolor{comment}{ !< The i-mean reference value for}
224 \textcolor{comment}{                                              !! this field with i-mean sponges.}
225 
226   \textcolor{keywordtype}{integer} :: j, k, col
227   \textcolor{keywordtype}{character(len=256)} :: mesg \textcolor{comment}{! String for error messages}
228 
229   \textcolor{keywordflow}{if} (.not.\textcolor{keyword}{associated}(cs)) \textcolor{keywordflow}{return}
230 
231   cs%fldno = cs%fldno + 1
232 
233   \textcolor{keywordflow}{if} (cs%fldno > max\_fields\_) \textcolor{keywordflow}{then}
234     \textcolor{keyword}{write}(mesg,\textcolor{stringliteral}{'("Increase MAX\_FIELDS\_ to at least ",I3," in MOM\_memory.h or decrease &}
235 \textcolor{stringliteral}{}\textcolor{stringliteral}{           &the number of fields to be damped in the call to &}
236 \textcolor{stringliteral}{}\textcolor{stringliteral}{           &initialize\_sponge." )'}) cs%fldno
237     \textcolor{keyword}{call }mom\_error(fatal,\textcolor{stringliteral}{"set\_up\_sponge\_field: "}//mesg)
238 \textcolor{keywordflow}{  endif}
239 
240   \textcolor{keyword}{allocate}(cs%Ref\_val(cs%fldno)%p(cs%nz,cs%num\_col))
241   cs%Ref\_val(cs%fldno)%p(:,:) = 0.0
242   \textcolor{keywordflow}{do} col=1,cs%num\_col
243     \textcolor{keywordflow}{do} k=1,nlay
244       cs%Ref\_val(cs%fldno)%p(k,col) = sp\_val(cs%col\_i(col),cs%col\_j(col),k)
245 \textcolor{keywordflow}{    enddo}
246     \textcolor{keywordflow}{do} k=nlay+1,cs%nz
247       cs%Ref\_val(cs%fldno)%p(k,col) = 0.0
248 \textcolor{keywordflow}{    enddo}
249 \textcolor{keywordflow}{  enddo}
250 
251   cs%var(cs%fldno)%p => f\_ptr
252 
253   \textcolor{keywordflow}{if} (nlay/=cs%nz) \textcolor{keywordflow}{then}
254     \textcolor{keyword}{write}(mesg,\textcolor{stringliteral}{'("Danger: Sponge reference fields require nz (",I3,") layers.&}
255 \textcolor{stringliteral}{}\textcolor{stringliteral}{        & A field with ",I3," layers was passed to set\_up\_sponge\_field.")'}) &
256           cs%nz, nlay
257     \textcolor{keywordflow}{if} (is\_root\_pe()) \textcolor{keyword}{call }mom\_error(warning, \textcolor{stringliteral}{"set\_up\_sponge\_field: "}//mesg)
258 \textcolor{keywordflow}{  endif}
259 
260   \textcolor{keywordflow}{if} (cs%do\_i\_mean\_sponge) \textcolor{keywordflow}{then}
261     \textcolor{keywordflow}{if} (.not.\textcolor{keyword}{present}(sp\_val\_i\_mean)) \textcolor{keyword}{call }mom\_error(fatal, &
262       \textcolor{stringliteral}{"set\_up\_sponge\_field: sp\_val\_i\_mean must be present with i-mean sponges."})
263 
264     \textcolor{keyword}{allocate}(cs%Ref\_val\_im(cs%fldno)%p(cs%jsd:cs%jed,cs%nz))
265     cs%Ref\_val(cs%fldno)%p(:,:) = 0.0
266     \textcolor{keywordflow}{do} k=1,cs%nz ; \textcolor{keywordflow}{do} j=cs%jsc,cs%jec
267       cs%Ref\_val\_im(cs%fldno)%p(j,k) = sp\_val\_i\_mean(j,k)
268 \textcolor{keywordflow}{    enddo} ;\textcolor{keywordflow}{ enddo}
269 \textcolor{keywordflow}{  endif}
270 
\end{DoxyCode}
\mbox{\Hypertarget{namespacemom__sponge_ac5a144fffdfc612c6e3de802261cc85c}\label{namespacemom__sponge_ac5a144fffdfc612c6e3de802261cc85c}} 
\index{mom\+\_\+sponge@{mom\+\_\+sponge}!set\+\_\+up\+\_\+sponge\+\_\+ml\+\_\+density@{set\+\_\+up\+\_\+sponge\+\_\+ml\+\_\+density}}
\index{set\+\_\+up\+\_\+sponge\+\_\+ml\+\_\+density@{set\+\_\+up\+\_\+sponge\+\_\+ml\+\_\+density}!mom\+\_\+sponge@{mom\+\_\+sponge}}
\subsubsection{\texorpdfstring{set\+\_\+up\+\_\+sponge\+\_\+ml\+\_\+density()}{set\_up\_sponge\_ml\_density()}}
{\footnotesize\ttfamily subroutine, public mom\+\_\+sponge\+::set\+\_\+up\+\_\+sponge\+\_\+ml\+\_\+density (\begin{DoxyParamCaption}\item[{real, dimension(szi\+\_\+(g),szj\+\_\+(g)), intent(in)}]{sp\+\_\+val,  }\item[{type(ocean\+\_\+grid\+\_\+type), intent(in)}]{G,  }\item[{type(\hyperlink{structmom__sponge_1_1sponge__cs}{sponge\+\_\+cs}), pointer}]{CS,  }\item[{real, dimension(szj\+\_\+(g)), intent(in), optional}]{sp\+\_\+val\+\_\+i\+\_\+mean }\end{DoxyParamCaption})}



This subroutine stores the reference value for mixed layer density. It is handled differently from other values because it is only used in determining which layers can be inflated. 


\begin{DoxyParams}[1]{Parameters}
\mbox{\tt in}  & {\em g} & The ocean\textquotesingle{}s grid structure\\
\hline
\mbox{\tt in}  & {\em sp\+\_\+val} & The reference values of the mixed layer density \mbox{[}R $\sim$$>$ kg m-\/3\mbox{]}\\
\hline
 & {\em cs} & A pointer to the control structure for this module that is set by a previous call to initialize\+\_\+sponge.\\
\hline
\mbox{\tt in}  & {\em sp\+\_\+val\+\_\+i\+\_\+mean} & the reference values of the zonal mean mixed \\
\hline
\end{DoxyParams}


Definition at line 277 of file M\+O\+M\+\_\+sponge.\+F90.


\begin{DoxyCode}
277   \textcolor{keywordtype}{type}(ocean\_grid\_type), \textcolor{keywordtype}{intent(in)} :: g\textcolor{comment}{    !< The ocean's grid structure}
278   \textcolor{keywordtype}{real}, \textcolor{keywordtype}{dimension(SZI\_(G),SZJ\_(G))}, &
279                          \textcolor{keywordtype}{intent(in)} :: sp\_val\textcolor{comment}{ !< The reference values of the mixed layer density [R ~> kg
       m-3]}
280   \textcolor{keywordtype}{type}(sponge\_cs),       \textcolor{keywordtype}{pointer}    :: cs\textcolor{comment}{   !< A pointer to the control structure for this module that is}
281 \textcolor{comment}{                                            !! set by a previous call to initialize\_sponge.}
282   \textcolor{keywordtype}{real}, \textcolor{keywordtype}{dimension(SZJ\_(G))}, &
283                \textcolor{keywordtype}{optional}, \textcolor{keywordtype}{intent(in)} :: sp\_val\_i\_mean\textcolor{comment}{ !< the reference values of the zonal mean mixed}
284 \textcolor{comment}{                                            !! layer density [R ~> kg m-3], for use if Iresttime\_i\_mean >
       0.}
285 \textcolor{comment}{!   This subroutine stores the reference value for mixed layer density.  It is}
286 \textcolor{comment}{! handled differently from other values because it is only used in determining}
287 \textcolor{comment}{! which layers can be inflated.}
288 
289 \textcolor{comment}{! Arguments: sp\_val - The reference values of the mixed layer density.}
290 \textcolor{comment}{!  (in/out)  CS - A pointer to the control structure for this module that is}
291 \textcolor{comment}{!                 set by a previous call to initialize\_sponge.}
292 
293   \textcolor{keywordtype}{integer} :: j, col
294   \textcolor{keywordtype}{character(len=256)} :: mesg \textcolor{comment}{! String for error messages}
295 
296   \textcolor{keywordflow}{if} (.not.\textcolor{keyword}{associated}(cs)) \textcolor{keywordflow}{return}
297 
298   \textcolor{keywordflow}{if} (\textcolor{keyword}{associated}(cs%Rcv\_ml\_ref)) \textcolor{keywordflow}{then}
299     \textcolor{keyword}{call }mom\_error(fatal, \textcolor{stringliteral}{"set\_up\_sponge\_ML\_density appears to have been "}//&
300                            \textcolor{stringliteral}{"called twice."})
301 \textcolor{keywordflow}{  endif}
302 
303   cs%bulkmixedlayer = .true.
304   \textcolor{keyword}{allocate}(cs%Rcv\_ml\_ref(cs%num\_col)) ; cs%Rcv\_ml\_ref(:) = 0.0
305   \textcolor{keywordflow}{do} col=1,cs%num\_col
306     cs%Rcv\_ml\_ref(col) = sp\_val(cs%col\_i(col),cs%col\_j(col))
307 \textcolor{keywordflow}{  enddo}
308 
309   \textcolor{keywordflow}{if} (cs%do\_i\_mean\_sponge) \textcolor{keywordflow}{then}
310     \textcolor{keywordflow}{if} (.not.\textcolor{keyword}{present}(sp\_val\_i\_mean)) \textcolor{keyword}{call }mom\_error(fatal, &
311       \textcolor{stringliteral}{"set\_up\_sponge\_field: sp\_val\_i\_mean must be present with i-mean sponges."})
312 
313     \textcolor{keyword}{allocate}(cs%Rcv\_ml\_ref\_im(cs%jsd:cs%jed)) ; cs%Rcv\_ml\_ref\_im(:) = 0.0
314     \textcolor{keywordflow}{do} j=cs%jsc,cs%jec
315       cs%Rcv\_ml\_ref\_im(j) = sp\_val\_i\_mean(j)
316 \textcolor{keywordflow}{    enddo}
317 \textcolor{keywordflow}{  endif}
318 
\end{DoxyCode}
\mbox{\Hypertarget{namespacemom__sponge_a9b62e032925716da3a7b099364ddd720}\label{namespacemom__sponge_a9b62e032925716da3a7b099364ddd720}} 
\index{mom\+\_\+sponge@{mom\+\_\+sponge}!sponge\+\_\+end@{sponge\+\_\+end}}
\index{sponge\+\_\+end@{sponge\+\_\+end}!mom\+\_\+sponge@{mom\+\_\+sponge}}
\subsubsection{\texorpdfstring{sponge\+\_\+end()}{sponge\_end()}}
{\footnotesize\ttfamily subroutine, public mom\+\_\+sponge\+::sponge\+\_\+end (\begin{DoxyParamCaption}\item[{type(\hyperlink{structmom__sponge_1_1sponge__cs}{sponge\+\_\+cs}), pointer}]{CS }\end{DoxyParamCaption})}



This call deallocates any memory in the sponge control structure. 


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


Definition at line 593 of file M\+O\+M\+\_\+sponge.\+F90.


\begin{DoxyCode}
593   \textcolor{keywordtype}{type}(sponge\_cs),         \textcolor{keywordtype}{pointer}    :: cs\textcolor{comment}{   !< A pointer to the control structure for this module}
594 \textcolor{comment}{                                              !! that is set by a previous call to initialize\_sponge.}
595   \textcolor{keywordtype}{integer} :: m
596 
597   \textcolor{keywordflow}{if} (.not.\textcolor{keyword}{associated}(cs)) \textcolor{keywordflow}{return}
598 
599   \textcolor{keywordflow}{if} (\textcolor{keyword}{associated}(cs%col\_i)) \textcolor{keyword}{deallocate}(cs%col\_i)
600   \textcolor{keywordflow}{if} (\textcolor{keyword}{associated}(cs%col\_j)) \textcolor{keyword}{deallocate}(cs%col\_j)
601 
602   \textcolor{keywordflow}{if} (\textcolor{keyword}{associated}(cs%Iresttime\_col)) \textcolor{keyword}{deallocate}(cs%Iresttime\_col)
603   \textcolor{keywordflow}{if} (\textcolor{keyword}{associated}(cs%Rcv\_ml\_ref)) \textcolor{keyword}{deallocate}(cs%Rcv\_ml\_ref)
604   \textcolor{keywordflow}{if} (\textcolor{keyword}{associated}(cs%Ref\_eta)) \textcolor{keyword}{deallocate}(cs%Ref\_eta)
605 
606   \textcolor{keywordflow}{if} (\textcolor{keyword}{associated}(cs%Iresttime\_im)) \textcolor{keyword}{deallocate}(cs%Iresttime\_im)
607   \textcolor{keywordflow}{if} (\textcolor{keyword}{associated}(cs%Rcv\_ml\_ref\_im)) \textcolor{keyword}{deallocate}(cs%Rcv\_ml\_ref\_im)
608   \textcolor{keywordflow}{if} (\textcolor{keyword}{associated}(cs%Ref\_eta\_im)) \textcolor{keyword}{deallocate}(cs%Ref\_eta\_im)
609 
610   \textcolor{keywordflow}{do} m=1,cs%fldno
611     \textcolor{keywordflow}{if} (\textcolor{keyword}{associated}(cs%Ref\_val(cs%fldno)%p)) \textcolor{keyword}{deallocate}(cs%Ref\_val(cs%fldno)%p)
612     \textcolor{keywordflow}{if} (\textcolor{keyword}{associated}(cs%Ref\_val\_im(cs%fldno)%p)) &
613       \textcolor{keyword}{deallocate}(cs%Ref\_val\_im(cs%fldno)%p)
614 \textcolor{keywordflow}{  enddo}
615 
616   \textcolor{keyword}{deallocate}(cs)
617 
\end{DoxyCode}
