\hypertarget{MOM__MEKE_8F90_source}{}\section{M\+O\+M\+\_\+\+M\+E\+K\+E.\+F90}
\label{MOM__MEKE_8F90_source}\index{/home/cermak/src/\+M\+O\+M6/src/parameterizations/lateral/\+M\+O\+M\+\_\+\+M\+E\+K\+E.\+F90@{/home/cermak/src/\+M\+O\+M6/src/parameterizations/lateral/\+M\+O\+M\+\_\+\+M\+E\+K\+E.\+F90}}

\begin{DoxyCode}
00001 \textcolor{comment}{!> Implements the Mesoscale Eddy Kinetic Energy framework}
00002 \textcolor{comment}{!! with topographic beta effect included in computing beta in Rhines scale}
00003 
\Hypertarget{MOM__MEKE_8F90_source_l00004}\hyperlink{namespacemom__meke}{00004} \textcolor{keyword}{module} \hyperlink{namespacemom__meke}{mom\_meke}
00005 
00006 \textcolor{comment}{! This file is part of MOM6. See LICENSE.md for the license.}
00007 
00008 \textcolor{keywordtype}{use }mom\_debugging\textcolor{keywordtype}{,     only} : hchksum, uvchksum
00009 \textcolor{keywordtype}{use }mom\_cpu\_clock\textcolor{keywordtype}{,     only} : cpu\_clock\_id, cpu\_clock\_begin, cpu\_clock\_end, clock\_routine
00010 \textcolor{keywordtype}{use }mom\_diag\_mediator\textcolor{keywordtype}{, only} : post\_data, register\_diag\_field, safe\_alloc\_ptr
00011 \textcolor{keywordtype}{use }mom\_diag\_mediator\textcolor{keywordtype}{, only} : diag\_ctrl, time\_type
00012 \textcolor{keywordtype}{use }mom\_domains\textcolor{keywordtype}{,       only} : create\_group\_pass, do\_group\_pass, group\_pass\_type
00013 \textcolor{keywordtype}{use }mom\_error\_handler\textcolor{keywordtype}{, only} : mom\_error, fatal, warning, note, mom\_mesg
00014 \textcolor{keywordtype}{use }mom\_file\_parser\textcolor{keywordtype}{,   only} : read\_param, get\_param, log\_version, param\_file\_type
00015 \textcolor{keywordtype}{use }mom\_grid\textcolor{keywordtype}{,          only} : ocean\_grid\_type
00016 \textcolor{keywordtype}{use }mom\_hor\_index\textcolor{keywordtype}{,     only} : hor\_index\_type
00017 \textcolor{keywordtype}{use }mom\_io\textcolor{keywordtype}{,            only} : vardesc, var\_desc
00018 \textcolor{keywordtype}{use }mom\_restart\textcolor{keywordtype}{,       only} : mom\_restart\_cs, register\_restart\_field, query\_initialized
00019 \textcolor{keywordtype}{use }\hyperlink{namespacemom__unit__scaling}{mom\_unit\_scaling}\textcolor{keywordtype}{,  only} : \hyperlink{structmom__unit__scaling_1_1unit__scale__type}{unit\_scale\_type}
00020 \textcolor{keywordtype}{use }mom\_variables\textcolor{keywordtype}{,     only} : vertvisc\_type
00021 \textcolor{keywordtype}{use }mom\_verticalgrid\textcolor{keywordtype}{,  only} : verticalgrid\_type
00022 \textcolor{keywordtype}{use }mom\_meke\_types\textcolor{keywordtype}{,    only} : meke\_type
00023 
00024 \textcolor{keywordtype}{implicit none} ; \textcolor{keywordtype}{private}
00025 
00026 \textcolor{preprocessor}{#include <MOM\_memory.h>}
00027 \textcolor{preprocessor}{}
00028 \textcolor{keywordtype}{public} \hyperlink{namespacemom__meke_a5f752f097ddeba7071e1703110e51bc2}{step\_forward\_meke}, \hyperlink{namespacemom__meke_a099f1cfad37430ef1bd60972a92b1be4}{meke\_init}, 
      \hyperlink{namespacemom__meke_a1900316331157e48f1a6029bac63fbd0}{meke\_alloc\_register\_restart}, \hyperlink{namespacemom__meke_acc007bf1aa24263f699b059d3e9cc6eb}{meke\_end}
00029 \textcolor{comment}{}
00030 \textcolor{comment}{!> Control structure that contains MEKE parameters and diagnostics handles}
\Hypertarget{MOM__MEKE_8F90_source_l00031}\hyperlink{structmom__meke_1_1meke__cs}{00031} \textcolor{keyword}{type}, \textcolor{keyword}{public} :: \hyperlink{structmom__meke_1_1meke__cs}{meke\_cs} ; \textcolor{keywordtype}{private}
00032   \textcolor{comment}{! Parameters}
\Hypertarget{MOM__MEKE_8F90_source_l00033}\hyperlink{structmom__meke_1_1meke__cs_a2e07312fa30c9d9596e6d3052ffcf03b}{00033}   \textcolor{keywordtype}{real}, \textcolor{keywordtype}{dimension(:,:)}, \textcolor{keywordtype}{pointer} :: equilibrium\_value => null() \textcolor{comment}{!< The equilbrium value}
00034 \textcolor{comment}{                        !! of MEKE to be calculated at each time step [L2 T-2 ~> m2 s-2]}
\Hypertarget{MOM__MEKE_8F90_source_l00035}\hyperlink{structmom__meke_1_1meke__cs_aaf5934fd66b3fc648adfe16f796b86d2}{00035}   \textcolor{keywordtype}{real} :: meke\_frcoeff\textcolor{comment}{  !< Efficiency of conversion of ME into MEKE [nondim]}
\Hypertarget{MOM__MEKE_8F90_source_l00036}\hyperlink{structmom__meke_1_1meke__cs_a4f1e09f9a261661c7c7ac80071462251}{00036}   \textcolor{keywordtype}{real} :: meke\_gmcoeff\textcolor{comment}{  !< Efficiency of conversion of PE into MEKE [nondim]}
\Hypertarget{MOM__MEKE_8F90_source_l00037}\hyperlink{structmom__meke_1_1meke__cs_a62fa7853ac13a5b6b6578623ee97f65d}{00037}   \textcolor{keywordtype}{real} :: meke\_gmecoeff\textcolor{comment}{ !< Efficiency of conversion of MEKE into ME by GME [nondim]}
\Hypertarget{MOM__MEKE_8F90_source_l00038}\hyperlink{structmom__meke_1_1meke__cs_a3711b7737887bfa2a72f2c4e87fc9872}{00038}   \textcolor{keywordtype}{real} :: meke\_damping\textcolor{comment}{  !< Local depth-independent MEKE dissipation rate [T-1 ~> s-1].}
\Hypertarget{MOM__MEKE_8F90_source_l00039}\hyperlink{structmom__meke_1_1meke__cs_adf3ce1c6863c71de6e495760ca7ed3fe}{00039}   \textcolor{keywordtype}{real} :: meke\_cd\_scale\textcolor{comment}{ !< The ratio of the bottom eddy velocity to the column mean}
00040 \textcolor{comment}{                        !! eddy velocity, i.e. sqrt(2*MEKE). This should be less than 1}
00041 \textcolor{comment}{                        !! to account for the surface intensification of MEKE.}
\Hypertarget{MOM__MEKE_8F90_source_l00042}\hyperlink{structmom__meke_1_1meke__cs_af1b29c512119ee6689561791a7a8386b}{00042}   \textcolor{keywordtype}{real} :: meke\_cb\textcolor{comment}{       !< Coefficient in the \(\backslash\)f$\(\backslash\)gamma\_\{bot\}\(\backslash\)f$ expression [nondim]}
\Hypertarget{MOM__MEKE_8F90_source_l00043}\hyperlink{structmom__meke_1_1meke__cs_a2a6ecf96d65459ac02ee50d3a454cefc}{00043}   \textcolor{keywordtype}{real} :: meke\_min\_gamma\textcolor{comment}{!< Minimum value of gamma\_b^2 allowed [nondim]}
\Hypertarget{MOM__MEKE_8F90_source_l00044}\hyperlink{structmom__meke_1_1meke__cs_aab6448e3dac88b2328fa7863472fa666}{00044}   \textcolor{keywordtype}{real} :: meke\_ct\textcolor{comment}{       !< Coefficient in the \(\backslash\)f$\(\backslash\)gamma\_\{bt\}\(\backslash\)f$ expression [nondim]}
\Hypertarget{MOM__MEKE_8F90_source_l00045}\hyperlink{structmom__meke_1_1meke__cs_ae679f694df55de7c846a1291707e370c}{00045}   \textcolor{keywordtype}{logical} :: visc\_drag\textcolor{comment}{  !< If true use the vertvisc\_type to calculate bottom drag.}
\Hypertarget{MOM__MEKE_8F90_source_l00046}\hyperlink{structmom__meke_1_1meke__cs_a914e3f10cf750fc8dfbbcd7f60821f37}{00046}   \textcolor{keywordtype}{logical} :: meke\_geometric\textcolor{comment}{ !< If true, uses the GM coefficient formulation from the GEOMETRIC}
00047 \textcolor{comment}{                        !! framework (Marshall et al., 2012)}
\Hypertarget{MOM__MEKE_8F90_source_l00048}\hyperlink{structmom__meke_1_1meke__cs_ab0634af3de913947d1194322e9e57d98}{00048}   \textcolor{keywordtype}{real}    :: meke\_geometric\_alpha\textcolor{comment}{ !< The nondimensional coefficient governing the efficiency of the}
00049 \textcolor{comment}{                        !! GEOMETRIC thickness diffusion.}
\Hypertarget{MOM__MEKE_8F90_source_l00050}\hyperlink{structmom__meke_1_1meke__cs_ab849158f3f1c5f481f78e2ec12af4c41}{00050}   \textcolor{keywordtype}{logical} :: meke\_equilibrium\_alt\textcolor{comment}{ !< If true, use an alternative calculation for the}
00051 \textcolor{comment}{                        !! equilibrium value of MEKE.}
\Hypertarget{MOM__MEKE_8F90_source_l00052}\hyperlink{structmom__meke_1_1meke__cs_a85ed16382bbd0b945f0de77488377854}{00052}   \textcolor{keywordtype}{logical} :: \hyperlink{namespacemom__meke_a843244b0cc72a08489920dcda464b063}{meke\_equilibrium\_restoring}\textcolor{comment}{ !< If true, restore MEKE back to its
       equilibrium value,}
00053 \textcolor{comment}{                        !!  which is calculated at each time step.}
\Hypertarget{MOM__MEKE_8F90_source_l00054}\hyperlink{structmom__meke_1_1meke__cs_a2c15716381992046dcb5e673bee9f147}{00054}   \textcolor{keywordtype}{logical} :: gm\_src\_alt\textcolor{comment}{ !< If true, use the GM energy conversion form S^2*N^2*kappa rather}
00055 \textcolor{comment}{                        !! than the streamfunction for the MEKE GM source term.}
\Hypertarget{MOM__MEKE_8F90_source_l00056}\hyperlink{structmom__meke_1_1meke__cs_a20c46c20c28f8966d60731425bbd0ad0}{00056}   \textcolor{keywordtype}{logical} :: rd\_as\_max\_scale\textcolor{comment}{ !< If true the length scale can not exceed the}
00057 \textcolor{comment}{                        !! first baroclinic deformation radius.}
\Hypertarget{MOM__MEKE_8F90_source_l00058}\hyperlink{structmom__meke_1_1meke__cs_a30961ae39e5285a09bda4f1235b5e26f}{00058}   \textcolor{keywordtype}{logical} :: use\_old\_lscale\textcolor{comment}{ !< Use the old formula for mixing length scale.}
\Hypertarget{MOM__MEKE_8F90_source_l00059}\hyperlink{structmom__meke_1_1meke__cs_a189479b2e098888bc24903761fd42592}{00059}   \textcolor{keywordtype}{logical} :: use\_min\_lscale\textcolor{comment}{ !< Use simple minimum for mixing length scale.}
\Hypertarget{MOM__MEKE_8F90_source_l00060}\hyperlink{structmom__meke_1_1meke__cs_a3bc6630f6dc5a617772c1634bddace78}{00060}   \textcolor{keywordtype}{real} :: cdrag\textcolor{comment}{         !< The bottom drag coefficient for MEKE [nondim].}
\Hypertarget{MOM__MEKE_8F90_source_l00061}\hyperlink{structmom__meke_1_1meke__cs_ae58fd82be69975281c651d1730b0a99a}{00061}   \textcolor{keywordtype}{real} :: meke\_bgsrc\textcolor{comment}{    !< Background energy source for MEKE [L2 T-3 ~> W kg-1] (= m2 s-3).}
\Hypertarget{MOM__MEKE_8F90_source_l00062}\hyperlink{structmom__meke_1_1meke__cs_aebb4e86120ecc576431c6c65d90e9e8f}{00062}   \textcolor{keywordtype}{real} :: meke\_dtscale\textcolor{comment}{  !< Scale factor to accelerate time-stepping [nondim]}
\Hypertarget{MOM__MEKE_8F90_source_l00063}\hyperlink{structmom__meke_1_1meke__cs_a1c12d23e36170a69853fff8085cb8001}{00063}   \textcolor{keywordtype}{real} :: meke\_khcoeff\textcolor{comment}{  !< Scaling factor to convert MEKE into Kh [nondim]}
\Hypertarget{MOM__MEKE_8F90_source_l00064}\hyperlink{structmom__meke_1_1meke__cs_a357850e9e13b02635c859fdb770364bb}{00064}   \textcolor{keywordtype}{real} :: meke\_uscale\textcolor{comment}{   !< MEKE velocity scale for bottom drag [L T-1 ~> m s-1]}
\Hypertarget{MOM__MEKE_8F90_source_l00065}\hyperlink{structmom__meke_1_1meke__cs_aaefbf10b25abc47f0a93cdf7fda3d5f7}{00065}   \textcolor{keywordtype}{real} :: meke\_kh\textcolor{comment}{       !< Background lateral diffusion of MEKE [L2 T-1 ~> m2 s-1]}
\Hypertarget{MOM__MEKE_8F90_source_l00066}\hyperlink{structmom__meke_1_1meke__cs_af30830f682f374aed201f92aab6a126d}{00066}   \textcolor{keywordtype}{real} :: meke\_k4\textcolor{comment}{       !< Background bi-harmonic diffusivity (of MEKE) [L4 T-1 ~> m4 s-1]}
\Hypertarget{MOM__MEKE_8F90_source_l00067}\hyperlink{structmom__meke_1_1meke__cs_a0b781be0b98ff59c96255c1b0d73fc54}{00067}   \textcolor{keywordtype}{real} :: khmeke\_fac\textcolor{comment}{    !< A factor relating MEKE%Kh to the diffusivity used for}
00068 \textcolor{comment}{                        !! MEKE itself [nondim].}
\Hypertarget{MOM__MEKE_8F90_source_l00069}\hyperlink{structmom__meke_1_1meke__cs_adb196645dc565e3ad5902aef066c54e4}{00069}   \textcolor{keywordtype}{real} :: viscosity\_coeff\_ku\textcolor{comment}{ !< The scaling coefficient in the expression for}
00070 \textcolor{comment}{                        !! viscosity used to parameterize lateral harmonic momentum mixing}
00071 \textcolor{comment}{                        !! by unresolved eddies represented by MEKE.}
\Hypertarget{MOM__MEKE_8F90_source_l00072}\hyperlink{structmom__meke_1_1meke__cs_a70588c16f51e4e2b4bb4862647c959c3}{00072}   \textcolor{keywordtype}{real} :: viscosity\_coeff\_au\textcolor{comment}{ !< The scaling coefficient in the expression for}
00073 \textcolor{comment}{                        !! viscosity used to parameterize lateral biharmonic momentum mixing}
00074 \textcolor{comment}{                        !! by unresolved eddies represented by MEKE.}
\Hypertarget{MOM__MEKE_8F90_source_l00075}\hyperlink{structmom__meke_1_1meke__cs_a9b288c1fd0438f54a19029c6ac5f9244}{00075}   \textcolor{keywordtype}{real} :: lfixed\textcolor{comment}{        !< Fixed mixing length scale [L ~> m].}
\Hypertarget{MOM__MEKE_8F90_source_l00076}\hyperlink{structmom__meke_1_1meke__cs_afdd51af558161b7a00e5c32dd3b647a1}{00076}   \textcolor{keywordtype}{real} :: adeform\textcolor{comment}{       !< Weighting towards deformation scale of mixing length [nondim]}
\Hypertarget{MOM__MEKE_8F90_source_l00077}\hyperlink{structmom__meke_1_1meke__cs_a86d2d5963b984abb9864f808c4bfafa2}{00077}   \textcolor{keywordtype}{real} :: arhines\textcolor{comment}{       !< Weighting towards Rhines scale of mixing length [nondim]}
\Hypertarget{MOM__MEKE_8F90_source_l00078}\hyperlink{structmom__meke_1_1meke__cs_a6279ce45ced1b6dde299205d9aa24b80}{00078}   \textcolor{keywordtype}{real} :: africt\textcolor{comment}{        !< Weighting towards frictional arrest scale of mixing length [nondim]}
\Hypertarget{MOM__MEKE_8F90_source_l00079}\hyperlink{structmom__meke_1_1meke__cs_ae89d82e9276ecdcb3f28c6e8dc958f35}{00079}   \textcolor{keywordtype}{real} :: aeady\textcolor{comment}{         !< Weighting towards Eady scale of mixing length [nondim]}
\Hypertarget{MOM__MEKE_8F90_source_l00080}\hyperlink{structmom__meke_1_1meke__cs_a497262f6b7162cde30390dcbe5455ece}{00080}   \textcolor{keywordtype}{real} :: agrid\textcolor{comment}{         !< Weighting towards grid scale of mixing length [nondim]}
\Hypertarget{MOM__MEKE_8F90_source_l00081}\hyperlink{structmom__meke_1_1meke__cs_ade1d4ce3f5be6d1c5f9f4ce3a3faf943}{00081}   \textcolor{keywordtype}{real} :: meke\_advection\_factor\textcolor{comment}{ !< A scaling in front of the advection of MEKE [nondim]}
\Hypertarget{MOM__MEKE_8F90_source_l00082}\hyperlink{structmom__meke_1_1meke__cs_a72daecf2fa02a92418bb1d237f47e970}{00082}   \textcolor{keywordtype}{real} :: meke\_topographic\_beta\textcolor{comment}{ !< Weight for how much topographic beta is considered}
00083 \textcolor{comment}{                                !! when computing beta in Rhines scale [nondim]}
\Hypertarget{MOM__MEKE_8F90_source_l00084}\hyperlink{structmom__meke_1_1meke__cs_ae22b548c5ea585b4986702ac846ab784}{00084}   \textcolor{keywordtype}{real} :: meke\_restoring\_rate\textcolor{comment}{ !< Inverse of the timescale used to nudge MEKE toward its equilibrium value
       [s-1].}
00085 
\Hypertarget{MOM__MEKE_8F90_source_l00086}\hyperlink{structmom__meke_1_1meke__cs_afa038f03d01a10b0a40572705b9e64af}{00086}   \textcolor{keywordtype}{logical} :: kh\_flux\_enabled\textcolor{comment}{ !< If true, lateral diffusive MEKE flux is enabled.}
\Hypertarget{MOM__MEKE_8F90_source_l00087}\hyperlink{structmom__meke_1_1meke__cs_a8f9e4f98b733067fe68b6cca86634085}{00087}   \textcolor{keywordtype}{logical} :: initialize\textcolor{comment}{ !< If True, invokes a steady state solver to calculate MEKE.}
\Hypertarget{MOM__MEKE_8F90_source_l00088}\hyperlink{structmom__meke_1_1meke__cs_a2494161c67a519f3003f469e7d2c780d}{00088}   \textcolor{keywordtype}{logical} :: debug\textcolor{comment}{      !< If true, write out checksums of data for debugging}
00089 
\Hypertarget{MOM__MEKE_8F90_source_l00090}\hyperlink{structmom__meke_1_1meke__cs_ae6853d4571281b0cbe96915b26661301}{00090}   \textcolor{keywordtype}{type}(diag\_ctrl), \textcolor{keywordtype}{pointer} :: diag => null() \textcolor{comment}{!< A type that regulates diagnostics output}
00091 \textcolor{comment}{  !>@\{ Diagnostic handles}
\Hypertarget{MOM__MEKE_8F90_source_l00092}\hyperlink{structmom__meke_1_1meke__cs_aef3d439189002d15c934398870eef279}{00092}   \textcolor{keywordtype}{integer} :: id\_meke = -1, id\_ue = -1, id\_kh = -1, id\_src = -1
\Hypertarget{MOM__MEKE_8F90_source_l00093}\hyperlink{structmom__meke_1_1meke__cs_a9485919fb6ea068436a2ac810c163da7}{00093}   \textcolor{keywordtype}{integer} :: id\_ub = -1, id\_ut = -1
\Hypertarget{MOM__MEKE_8F90_source_l00094}\hyperlink{structmom__meke_1_1meke__cs_ab249fba2a56c5d350539d371b288dc6e}{00094}   \textcolor{keywordtype}{integer} :: id\_gm\_src = -1, id\_mom\_src = -1, id\_gme\_snk = -1, id\_decay = -1
\Hypertarget{MOM__MEKE_8F90_source_l00095}\hyperlink{structmom__meke_1_1meke__cs_a381541f77a33a6fedbc1d1ad35727918}{00095}   \textcolor{keywordtype}{integer} :: id\_khmeke\_u = -1, id\_khmeke\_v = -1, id\_ku = -1, id\_au = -1
\Hypertarget{MOM__MEKE_8F90_source_l00096}\hyperlink{structmom__meke_1_1meke__cs_ac6b0905bd36001e15f8fd2d20ee058ca}{00096}   \textcolor{keywordtype}{integer} :: id\_le = -1, id\_gamma\_b = -1, id\_gamma\_t = -1
\Hypertarget{MOM__MEKE_8F90_source_l00097}\hyperlink{structmom__meke_1_1meke__cs_ae792c88ebef95e377654b37efdc19de3}{00097}   \textcolor{keywordtype}{integer} :: id\_lrhines = -1, id\_leady = -1
\Hypertarget{MOM__MEKE_8F90_source_l00098}\hyperlink{structmom__meke_1_1meke__cs_a6829347b619918eecd5421dcd6d8d40f}{00098}   \textcolor{keywordtype}{integer} :: id\_meke\_equilibrium = -1\textcolor{comment}{}
00099 \textcolor{comment}{  !>@\}}
00100 
00101   \textcolor{comment}{! Infrastructure}
\Hypertarget{MOM__MEKE_8F90_source_l00102}\hyperlink{structmom__meke_1_1meke__cs_ae558238d9a5dd889d1d0d5215dcb6345}{00102}   \textcolor{keywordtype}{integer} :: id\_clock\_pass\textcolor{comment}{ !< Clock for group pass calls}
\Hypertarget{MOM__MEKE_8F90_source_l00103}\hyperlink{structmom__meke_1_1meke__cs_ab2f2e88ff8d9e61a88ba1d76c8863244}{00103}   \textcolor{keywordtype}{type}(group\_pass\_type) :: pass\_meke\textcolor{comment}{ !< Group halo pass handle for MEKE%MEKE and maybe MEKE%Kh\_diff}
\Hypertarget{MOM__MEKE_8F90_source_l00104}\hyperlink{structmom__meke_1_1meke__cs_a0fcdbb671fac5c5a9ce075dc3d0f1675}{00104}   \textcolor{keywordtype}{type}(group\_pass\_type) :: pass\_kh\textcolor{comment}{   !< Group halo pass handle for MEKE%Kh, MEKE%Ku, and/or MEKE%Au}
00105 \textcolor{keyword}{end type }\hyperlink{structmom__meke_1_1meke__cs}{meke\_cs}
00106 
00107 \textcolor{keyword}{contains}
00108 \textcolor{comment}{}
00109 \textcolor{comment}{!> Integrates forward-in-time the MEKE eddy energy equation.}
00110 \textcolor{comment}{!! See \(\backslash\)ref section\_MEKE\_equations.}
00111 \textcolor{keyword}{subroutine }\hyperlink{namespacemom__meke_a5f752f097ddeba7071e1703110e51bc2}{step\_forward\_meke}(MEKE, h, SN\_u, SN\_v, visc, dt, G, GV, US, CS, hu, hv)
\Hypertarget{MOM__MEKE_8F90_source_l00112}\hyperlink{namespacemom__meke_a5f752f097ddeba7071e1703110e51bc2}{00112}   \textcolor{keywordtype}{type}(meke\_type),                          \textcolor{keywordtype}{pointer}       :: MEKE\textcolor{comment}{ !< MEKE data.}
00113   \textcolor{keywordtype}{type}(ocean\_grid\_type),                    \textcolor{keywordtype}{intent(inout)} :: G\textcolor{comment}{    !< Ocean grid.}
00114   \textcolor{keywordtype}{type}(verticalgrid\_type),                  \textcolor{keywordtype}{intent(in)}    :: GV\textcolor{comment}{   !< Ocean vertical grid structure.}
00115   \textcolor{keywordtype}{type}(\hyperlink{structmom__unit__scaling_1_1unit__scale__type}{unit\_scale\_type}),                    \textcolor{keywordtype}{intent(in)}    :: US\textcolor{comment}{   !< A dimensional unit
       scaling type}
00116   \textcolor{keywordtype}{real}, \textcolor{keywordtype}{dimension(SZI\_(G),SZJ\_(G),SZK\_(G))}, \textcolor{keywordtype}{intent(in)}    :: h\textcolor{comment}{    !< Layer thickness [H ~> m or kg m-2].}
00117   \textcolor{keywordtype}{real}, \textcolor{keywordtype}{dimension(SZIB\_(G),SZJ\_(G))},        \textcolor{keywordtype}{intent(in)}    :: SN\_u\textcolor{comment}{ !< Eady growth rate at u-points [T-1 ~>
       s-1].}
00118   \textcolor{keywordtype}{real}, \textcolor{keywordtype}{dimension(SZI\_(G),SZJB\_(G))},        \textcolor{keywordtype}{intent(in)}    :: SN\_v\textcolor{comment}{ !< Eady growth rate at v-points [T-1 ~>
       s-1].}
00119   \textcolor{keywordtype}{type}(vertvisc\_type),                      \textcolor{keywordtype}{intent(in)}    :: visc\textcolor{comment}{ !< The vertical viscosity type.}
00120   \textcolor{keywordtype}{real},                                     \textcolor{keywordtype}{intent(in)}    :: dt\textcolor{comment}{   !< Model(baroclinic) time-step [T ~> s].}
00121   \textcolor{keywordtype}{type}(\hyperlink{structmom__meke_1_1meke__cs}{meke\_cs}),                            \textcolor{keywordtype}{pointer}       :: CS\textcolor{comment}{   !< MEKE control structure.}
00122   \textcolor{keywordtype}{real}, \textcolor{keywordtype}{dimension(SZIB\_(G),SZJ\_(G),SZK\_(G))}, \textcolor{keywordtype}{intent(in)}   :: hu\textcolor{comment}{   !< Accumlated zonal mass flux [H L2 ~> m3
       or kg].}
00123   \textcolor{keywordtype}{real}, \textcolor{keywordtype}{dimension(SZI\_(G),SZJB\_(G),SZK\_(G))}, \textcolor{keywordtype}{intent(in)}   :: hv\textcolor{comment}{   !< Accumlated meridional mass flux [H L2
       ~> m3 or kg]}
00124 
00125   \textcolor{comment}{! Local variables}
00126   \textcolor{keywordtype}{real}, \textcolor{keywordtype}{dimension(SZI\_(G),SZJ\_(G))} :: &
00127     mass, &         \textcolor{comment}{! The total mass of the water column [R Z ~> kg m-2].}
00128     I\_mass, &       \textcolor{comment}{! The inverse of mass [R-1 Z-1 ~> m2 kg-1].}
00129     src, &          \textcolor{comment}{! The sum of all MEKE sources [L2 T-3 ~> W kg-1] (= m2 s-3).}
00130     MEKE\_decay, &   \textcolor{comment}{! A diagnostic of the MEKE decay timescale [T-1 ~> s-1].}
00131     drag\_rate\_visc, & \textcolor{comment}{! Near-bottom velocity contribution to bottom dratg [L T-1 ~> m s-1]}
00132     drag\_rate, &    \textcolor{comment}{! The MEKE spindown timescale due to bottom drag [T-1 ~> s-1].}
00133     drag\_rate\_J15, &  \textcolor{comment}{! The MEKE spindown timescale due to bottom drag with the Jansen 2015 scheme.}
00134                     \textcolor{comment}{! Unfortunately, as written the units seem inconsistent. [T-1 ~> s-1].}
00135     del2meke, &     \textcolor{comment}{! Laplacian of MEKE, used for bi-harmonic diffusion [T-2 ~> s-2].}
00136     del4meke, &     \textcolor{comment}{! Time-integrated MEKE tendency arising from the biharmonic of MEKE [L2 T-2 ~> m2 s-2].}
00137     lmixscale, &    \textcolor{comment}{! Eddy mixing length [L ~> m].}
00138     barotrfac2, &   \textcolor{comment}{! Ratio of EKE\_barotropic / EKE [nondim]}
00139     bottomfac2, &   \textcolor{comment}{! Ratio of EKE\_bottom / EKE [nondim]}
00140     tmp             \textcolor{comment}{! Temporary variable for diagnostic computation}
00141 
00142   \textcolor{keywordtype}{real}, \textcolor{keywordtype}{dimension(SZIB\_(G),SZJ\_(G))} :: &
00143     MEKE\_uflux, &   \textcolor{comment}{! The zonal advective and diffusive flux of MEKE with units of [R Z L4 T-3 ~> kg m-2
       s-3].}
00144                     \textcolor{comment}{! In one place, MEKE\_uflux is used as temporary work space with units of [L2 T-2 ~> m2
       s-2].}
00145     kh\_u, &         \textcolor{comment}{! The zonal diffusivity that is actually used [L2 T-1 ~> m2 s-1].}
00146     barohu, &       \textcolor{comment}{! Depth integrated accumulated zonal mass flux [R Z L2 ~> kg].}
00147     drag\_vel\_u      \textcolor{comment}{! A (vertical) viscosity associated with bottom drag at}
00148                     \textcolor{comment}{! u-points [Z T-1 ~> m s-1].}
00149   \textcolor{keywordtype}{real}, \textcolor{keywordtype}{dimension(SZI\_(G),SZJB\_(G))} :: &
00150     MEKE\_vflux, &   \textcolor{comment}{! The meridional advective and diffusive flux of MEKE with units of [R Z L4 T-3 ~> kg
       m-2 s-3].}
00151                     \textcolor{comment}{! In one place, MEKE\_vflux is used as temporary work space with units of [L2 T-2 ~> m2
       s-2].}
00152     kh\_v, &         \textcolor{comment}{! The meridional diffusivity that is actually used [L2 T-1 ~> m2 s-1].}
00153     barohv, &       \textcolor{comment}{! Depth integrated accumulated meridional mass flux [R Z L2 ~> kg].}
00154     drag\_vel\_v      \textcolor{comment}{! A (vertical) viscosity associated with bottom drag at}
00155                     \textcolor{comment}{! v-points [Z T-1 ~> m s-1].}
00156   \textcolor{keywordtype}{real} :: Kh\_here   \textcolor{comment}{! The local horizontal viscosity [L2 T-1 ~> m2 s-1]}
00157   \textcolor{keywordtype}{real} :: Inv\_Kh\_max \textcolor{comment}{! The inverse of the local horizontal viscosity [T L-2 ~> s m-2]}
00158   \textcolor{keywordtype}{real} :: K4\_here   \textcolor{comment}{! The local horizontal biharmonic viscosity [L4 T-1 ~> m4 s-1]}
00159   \textcolor{keywordtype}{real} :: Inv\_K4\_max \textcolor{comment}{! The inverse of the local horizontal biharmonic viscosity [T L-4 ~> s m-4]}
00160   \textcolor{keywordtype}{real} :: cdrag2
00161   \textcolor{keywordtype}{real} :: advFac    \textcolor{comment}{! The product of the advection scaling factor and 1/dt [T-1 ~> s-1]}
00162   \textcolor{keywordtype}{real} :: mass\_neglect \textcolor{comment}{! A negligible mass [R Z ~> kg m-2].}
00163   \textcolor{keywordtype}{real} :: ldamping  \textcolor{comment}{! The MEKE damping rate [T-1 ~> s-1].}
00164   \textcolor{keywordtype}{real} :: Rho0      \textcolor{comment}{! A density used to convert mass to distance [R ~> kg m-3].}
00165   \textcolor{keywordtype}{real} :: sdt       \textcolor{comment}{! dt to use locally [T ~> s] (could be scaled to accelerate)}
00166   \textcolor{keywordtype}{real} :: sdt\_damp  \textcolor{comment}{! dt for damping [T ~> s] (sdt could be split).}
00167   \textcolor{keywordtype}{logical} :: use\_drag\_rate \textcolor{comment}{! Flag to indicate drag\_rate is finite}
00168   \textcolor{keywordtype}{integer} :: i, j, k, is, ie, js, je, Isq, Ieq, Jsq, Jeq, nz
00169 
00170   is = g%isc ; ie = g%iec ; js = g%jsc ; je = g%jec ; nz = g%ke
00171   isq = g%IscB ; ieq = g%IecB ; jsq = g%JscB ; jeq = g%JecB
00172 
00173   \textcolor{keywordflow}{if} (.not.\textcolor{keyword}{associated}(cs)) \textcolor{keyword}{call }mom\_error(fatal, &
00174          \textcolor{stringliteral}{"MOM\_MEKE: Module must be initialized before it is used."})
00175   \textcolor{keywordflow}{if} (.not.\textcolor{keyword}{associated}(meke)) \textcolor{keyword}{call }mom\_error(fatal, &
00176          \textcolor{stringliteral}{"MOM\_MEKE: MEKE must be initialized before it is used."})
00177 
00178   \textcolor{keywordflow}{if} ((cs%MEKE\_damping > 0.0) .or. (cs%MEKE\_Cd\_scale > 0.0) .or. (cs%MEKE\_Cb>0.) &
00179       .or. cs%visc\_drag) \textcolor{keywordflow}{then}
00180     use\_drag\_rate = .true.
00181   \textcolor{keywordflow}{else}
00182     use\_drag\_rate = .false.
00183 \textcolor{keywordflow}{  endif}
00184 
00185   \textcolor{comment}{! Only integrate the MEKE equations if MEKE is required.}
00186   \textcolor{keywordflow}{if} (.not.\textcolor{keyword}{associated}(meke%MEKE)) \textcolor{keywordflow}{then}
00187 \textcolor{comment}{!   call MOM\_error(FATAL, "MOM\_MEKE: MEKE%MEKE is not associated!")}
00188     \textcolor{keywordflow}{return}
00189 \textcolor{keywordflow}{  endif}
00190 
00191     \textcolor{keywordflow}{if} (cs%debug) \textcolor{keywordflow}{then}
00192       \textcolor{keywordflow}{if} (\textcolor{keyword}{associated}(meke%mom\_src)) &
00193         \textcolor{keyword}{call }hchksum(meke%mom\_src, \textcolor{stringliteral}{'MEKE mom\_src'}, g%HI, scale=us%RZ3\_T3\_to\_W\_m2*us%L\_to\_Z**2)
00194       \textcolor{keywordflow}{if} (\textcolor{keyword}{associated}(meke%GME\_snk)) &
00195         \textcolor{keyword}{call }hchksum(meke%GME\_snk, \textcolor{stringliteral}{'MEKE GME\_snk'}, g%HI, scale=us%RZ3\_T3\_to\_W\_m2*us%L\_to\_Z**2)
00196       \textcolor{keywordflow}{if} (\textcolor{keyword}{associated}(meke%GM\_src)) &
00197         \textcolor{keyword}{call }hchksum(meke%GM\_src, \textcolor{stringliteral}{'MEKE GM\_src'}, g%HI, scale=us%RZ3\_T3\_to\_W\_m2*us%L\_to\_Z**2)
00198       \textcolor{keywordflow}{if} (\textcolor{keyword}{associated}(meke%MEKE)) \textcolor{keyword}{call }hchksum(meke%MEKE, \textcolor{stringliteral}{'MEKE MEKE'}, g%HI, scale=us%L\_T\_to\_m\_s**2)
00199       \textcolor{keyword}{call }uvchksum(\textcolor{stringliteral}{"MEKE SN\_[uv]"}, sn\_u, sn\_v, g%HI, scale=us%s\_to\_T, &
00200                     scalar\_pair=.true.)
00201       \textcolor{keyword}{call }uvchksum(\textcolor{stringliteral}{"MEKE h[uv]"}, hu, hv, g%HI, haloshift=1, &
00202                     scale=gv%H\_to\_m*(us%L\_to\_m**2))
00203 \textcolor{keywordflow}{    endif}
00204 
00205     sdt = dt*cs%MEKE\_dtScale \textcolor{comment}{! Scaled dt to use for time-stepping}
00206     rho0 = gv%Rho0
00207     mass\_neglect = gv%H\_to\_RZ * gv%H\_subroundoff
00208     cdrag2 = cs%cdrag**2
00209 
00210     \textcolor{comment}{! With a depth-dependent (and possibly strong) damping, it seems}
00211     \textcolor{comment}{! advisable to use Strang splitting between the damping and diffusion.}
00212     sdt\_damp = sdt ; \textcolor{keywordflow}{if} (cs%MEKE\_KH >= 0.0 .or. cs%MEKE\_K4 >= 0.) sdt\_damp = 0.5*sdt
00213 
00214     \textcolor{comment}{! Calculate depth integrated mass exchange if doing advection [R Z L2 ~> kg]}
00215     \textcolor{keywordflow}{if} (cs%MEKE\_advection\_factor>0.) \textcolor{keywordflow}{then}
00216       \textcolor{keywordflow}{do} j=js,je ; \textcolor{keywordflow}{do} i=is-1,ie
00217         barohu(i,j) = 0.
00218 \textcolor{keywordflow}{      enddo} ;\textcolor{keywordflow}{ enddo}
00219       \textcolor{keywordflow}{do} k=1,nz
00220         \textcolor{keywordflow}{do} j=js,je ; \textcolor{keywordflow}{do} i=is-1,ie
00221           barohu(i,j) = hu(i,j,k) * gv%H\_to\_RZ
00222 \textcolor{keywordflow}{        enddo} ;\textcolor{keywordflow}{ enddo}
00223 \textcolor{keywordflow}{      enddo}
00224       \textcolor{keywordflow}{do} j=js-1,je ; \textcolor{keywordflow}{do} i=is,ie
00225         barohv(i,j) = 0.
00226 \textcolor{keywordflow}{      enddo} ;\textcolor{keywordflow}{ enddo}
00227       \textcolor{keywordflow}{do} k=1,nz
00228         \textcolor{keywordflow}{do} j=js-1,je ; \textcolor{keywordflow}{do} i=is,ie
00229           barohv(i,j) = hv(i,j,k) * gv%H\_to\_RZ
00230 \textcolor{keywordflow}{        enddo} ;\textcolor{keywordflow}{ enddo}
00231 \textcolor{keywordflow}{      enddo}
00232 \textcolor{keywordflow}{    endif}
00233 
00234     \textcolor{keywordflow}{if} (cs%MEKE\_Cd\_scale == 0.0 .and. .not. cs%visc\_drag) \textcolor{keywordflow}{then}
00235       \textcolor{comment}{!$OMP parallel do default(shared) private(ldamping)}
00236       \textcolor{keywordflow}{do} j=js,je ; \textcolor{keywordflow}{do} i=is,ie
00237         drag\_rate(i,j) = 0. ; drag\_rate\_j15(i,j) = 0.
00238 \textcolor{keywordflow}{      enddo} ;\textcolor{keywordflow}{ enddo}
00239 \textcolor{keywordflow}{    endif}
00240 
00241     \textcolor{comment}{! Calculate drag\_rate\_visc(i,j) which accounts for the model bottom mean flow}
00242     \textcolor{keywordflow}{if} (cs%visc\_drag) \textcolor{keywordflow}{then}
00243       \textcolor{comment}{!$OMP parallel do default(shared)}
00244       \textcolor{keywordflow}{do} j=js,je ; \textcolor{keywordflow}{do} i=is-1,ie
00245         drag\_vel\_u(i,j) = 0.0
00246         \textcolor{keywordflow}{if} ((g%mask2dCu(i,j) > 0.0) .and. (visc%bbl\_thick\_u(i,j) > 0.0)) &
00247           drag\_vel\_u(i,j) = visc%Kv\_bbl\_u(i,j) / visc%bbl\_thick\_u(i,j)
00248 \textcolor{keywordflow}{      enddo} ;\textcolor{keywordflow}{ enddo}
00249       \textcolor{comment}{!$OMP parallel do default(shared)}
00250       \textcolor{keywordflow}{do} j=js-1,je ; \textcolor{keywordflow}{do} i=is,ie
00251         drag\_vel\_v(i,j) = 0.0
00252         \textcolor{keywordflow}{if} ((g%mask2dCv(i,j) > 0.0) .and. (visc%bbl\_thick\_v(i,j) > 0.0)) &
00253           drag\_vel\_v(i,j) = visc%Kv\_bbl\_v(i,j) / visc%bbl\_thick\_v(i,j)
00254 \textcolor{keywordflow}{      enddo} ;\textcolor{keywordflow}{ enddo}
00255 
00256       \textcolor{comment}{!$OMP parallel do default(shared)}
00257       \textcolor{keywordflow}{do} j=js,je ; \textcolor{keywordflow}{do} i=is,ie
00258         drag\_rate\_visc(i,j) = (0.25*g%IareaT(i,j) * us%Z\_to\_L * &
00259                 ((g%areaCu(i-1,j)*drag\_vel\_u(i-1,j) + &
00260                   g%areaCu(i,j)*drag\_vel\_u(i,j)) + &
00261                  (g%areaCv(i,j-1)*drag\_vel\_v(i,j-1) + &
00262                   g%areaCv(i,j)*drag\_vel\_v(i,j)) ) )
00263 \textcolor{keywordflow}{      enddo} ;\textcolor{keywordflow}{ enddo}
00264     \textcolor{keywordflow}{else}
00265       \textcolor{comment}{!$OMP parallel do default(shared)}
00266       \textcolor{keywordflow}{do} j=js,je ; \textcolor{keywordflow}{do} i=is,ie
00267         drag\_rate\_visc(i,j) = 0.
00268 \textcolor{keywordflow}{      enddo} ;\textcolor{keywordflow}{ enddo}
00269 \textcolor{keywordflow}{    endif}
00270 
00271     \textcolor{comment}{!$OMP parallel do default(shared)}
00272     \textcolor{keywordflow}{do} j=js-1,je+1
00273       \textcolor{keywordflow}{do} i=is-1,ie+1 ; mass(i,j) = 0.0 ;\textcolor{keywordflow}{ enddo}
00274       \textcolor{keywordflow}{do} k=1,nz ; \textcolor{keywordflow}{do} i=is-1,ie+1
00275         mass(i,j) = mass(i,j) + g%mask2dT(i,j) * (gv%H\_to\_RZ * h(i,j,k)) \textcolor{comment}{! [R Z ~> kg m-2]}
00276 \textcolor{keywordflow}{      enddo} ;\textcolor{keywordflow}{ enddo}
00277       \textcolor{keywordflow}{do} i=is-1,ie+1
00278         i\_mass(i,j) = 0.0
00279         \textcolor{keywordflow}{if} (mass(i,j) > 0.0) i\_mass(i,j) = 1.0 / mass(i,j) \textcolor{comment}{! [R-1 Z-1 ~> m2 kg-1]}
00280 \textcolor{keywordflow}{      enddo}
00281 \textcolor{keywordflow}{    enddo}
00282 
00283     \textcolor{keywordflow}{if} (cs%initialize) \textcolor{keywordflow}{then}
00284       \textcolor{keyword}{call }\hyperlink{namespacemom__meke_a0ef9a8bcdf705b544db9b8c28a5e6a56}{meke\_equilibrium}(cs, meke, g, gv, us, sn\_u, sn\_v, drag\_rate\_visc, i\_mass)
00285       cs%initialize = .false.
00286 \textcolor{keywordflow}{    endif}
00287 
00288     \textcolor{comment}{! Calculates bottomFac2, barotrFac2 and LmixScale}
00289     \textcolor{keyword}{call }\hyperlink{namespacemom__meke_a8180d5d0cacf48bcbdffead9e6a06efd}{meke\_lengthscales}(cs, meke, g, gv, us, sn\_u, sn\_v, meke%MEKE, bottomfac2, 
      barotrfac2, lmixscale)
00290     \textcolor{keywordflow}{if} (cs%debug) \textcolor{keywordflow}{then}
00291       \textcolor{keywordflow}{if} (cs%visc\_drag) &
00292         \textcolor{keyword}{call }uvchksum(\textcolor{stringliteral}{"MEKE drag\_vel\_[uv]"}, drag\_vel\_u, drag\_vel\_v, g%HI, &
00293                       scale=us%Z\_to\_m*us%s\_to\_T, scalar\_pair=.true.)
00294       \textcolor{keyword}{call }hchksum(mass, \textcolor{stringliteral}{'MEKE mass'},g%HI,haloshift=1, scale=us%RZ\_to\_kg\_m2)
00295       \textcolor{keyword}{call }hchksum(drag\_rate\_visc, \textcolor{stringliteral}{'MEKE drag\_rate\_visc'}, g%HI, scale=us%L\_T\_to\_m\_s)
00296       \textcolor{keyword}{call }hchksum(bottomfac2, \textcolor{stringliteral}{'MEKE bottomFac2'}, g%HI)
00297       \textcolor{keyword}{call }hchksum(barotrfac2, \textcolor{stringliteral}{'MEKE barotrFac2'}, g%HI)
00298       \textcolor{keyword}{call }hchksum(lmixscale, \textcolor{stringliteral}{'MEKE LmixScale'}, g%HI,scale=us%L\_to\_m)
00299 \textcolor{keywordflow}{    endif}
00300 
00301     \textcolor{comment}{! Aggregate sources of MEKE (background, frictional and GM)}
00302     \textcolor{comment}{!$OMP parallel do default(shared)}
00303     \textcolor{keywordflow}{do} j=js,je ; \textcolor{keywordflow}{do} i=is,ie
00304       src(i,j) = cs%MEKE\_BGsrc
00305 \textcolor{keywordflow}{    enddo} ;\textcolor{keywordflow}{ enddo}
00306 
00307     \textcolor{keywordflow}{if} (\textcolor{keyword}{associated}(meke%mom\_src)) \textcolor{keywordflow}{then}
00308       \textcolor{comment}{!$OMP parallel do default(shared)}
00309       \textcolor{keywordflow}{do} j=js,je ; \textcolor{keywordflow}{do} i=is,ie
00310         src(i,j) = src(i,j) - cs%MEKE\_FrCoeff*i\_mass(i,j)*meke%mom\_src(i,j)
00311 \textcolor{keywordflow}{      enddo} ;\textcolor{keywordflow}{ enddo}
00312 \textcolor{keywordflow}{    endif}
00313 
00314     \textcolor{keywordflow}{if} (\textcolor{keyword}{associated}(meke%GME\_snk)) \textcolor{keywordflow}{then}
00315       \textcolor{comment}{!$OMP parallel do default(shared)}
00316       \textcolor{keywordflow}{do} j=js,je ; \textcolor{keywordflow}{do} i=is,ie
00317         src(i,j) = src(i,j) - cs%MEKE\_GMECoeff*i\_mass(i,j)*meke%GME\_snk(i,j)
00318 \textcolor{keywordflow}{      enddo} ;\textcolor{keywordflow}{ enddo}
00319 \textcolor{keywordflow}{    endif}
00320 
00321     \textcolor{keywordflow}{if} (\textcolor{keyword}{associated}(meke%GM\_src)) \textcolor{keywordflow}{then}
00322       \textcolor{keywordflow}{if} (cs%GM\_src\_alt) \textcolor{keywordflow}{then}
00323         \textcolor{comment}{!$OMP parallel do default(shared)}
00324         \textcolor{keywordflow}{do} j=js,je ; \textcolor{keywordflow}{do} i=is,ie
00325           src(i,j) = src(i,j) - cs%MEKE\_GMcoeff*meke%GM\_src(i,j) / &
00326                      (gv%Rho0 * max(1.0*us%m\_to\_Z, g%bathyT(i,j)))
00327 \textcolor{keywordflow}{        enddo} ;\textcolor{keywordflow}{ enddo}
00328       \textcolor{keywordflow}{else}
00329         \textcolor{comment}{!$OMP parallel do default(shared)}
00330         \textcolor{keywordflow}{do} j=js,je ; \textcolor{keywordflow}{do} i=is,ie
00331           src(i,j) = src(i,j) - cs%MEKE\_GMcoeff*i\_mass(i,j)*meke%GM\_src(i,j)
00332 \textcolor{keywordflow}{        enddo} ;\textcolor{keywordflow}{ enddo}
00333 \textcolor{keywordflow}{      endif}
00334 \textcolor{keywordflow}{    endif}
00335 
00336     \textcolor{keywordflow}{if} (cs%MEKE\_equilibrium\_restoring) \textcolor{keywordflow}{then}
00337       \textcolor{keyword}{call }\hyperlink{namespacemom__meke_a843244b0cc72a08489920dcda464b063}{meke\_equilibrium\_restoring}(cs, g, us, sn\_u, sn\_v)
00338       \textcolor{keywordflow}{do} j=js,je ; \textcolor{keywordflow}{do} i=is,ie
00339         src(i,j) = src(i,j) - cs%MEKE\_restoring\_rate*(meke%MEKE(i,j) - cs%equilibrium\_value(i,j))
00340 \textcolor{keywordflow}{      enddo} ;\textcolor{keywordflow}{ enddo}
00341 \textcolor{keywordflow}{    endif}
00342 
00343     \textcolor{comment}{! Increase EKE by a full time-steps worth of source}
00344     \textcolor{comment}{!$OMP parallel do default(shared)}
00345     \textcolor{keywordflow}{do} j=js,je ; \textcolor{keywordflow}{do} i=is,ie
00346       meke%MEKE(i,j) = (meke%MEKE(i,j) + sdt*src(i,j))*g%mask2dT(i,j)
00347 \textcolor{keywordflow}{    enddo} ;\textcolor{keywordflow}{ enddo}
00348 
00349     \textcolor{keywordflow}{if} (use\_drag\_rate) \textcolor{keywordflow}{then}
00350       \textcolor{comment}{! Calculate a viscous drag rate (includes BBL contributions from mean flow and eddies)}
00351       \textcolor{comment}{!$OMP parallel do default(shared)}
00352       \textcolor{keywordflow}{do} j=js,je ; \textcolor{keywordflow}{do} i=is,ie
00353         drag\_rate(i,j) = (us%L\_to\_Z*rho0 * i\_mass(i,j)) * sqrt( drag\_rate\_visc(i,j)**2 + &
00354                  cdrag2 * ( max(0.0, 2.0*bottomfac2(i,j)*meke%MEKE(i,j)) + cs%MEKE\_Uscale**2 ) )
00355 \textcolor{keywordflow}{      enddo} ;\textcolor{keywordflow}{ enddo}
00356 \textcolor{keywordflow}{    endif}
00357 
00358     \textcolor{comment}{! First stage of Strang splitting}
00359     \textcolor{comment}{!$OMP parallel do default(shared)}
00360     \textcolor{keywordflow}{do} j=js,je ; \textcolor{keywordflow}{do} i=is,ie
00361       ldamping = cs%MEKE\_damping + drag\_rate(i,j) * bottomfac2(i,j)
00362       \textcolor{keywordflow}{if} (meke%MEKE(i,j) < 0.) ldamping = 0.
00363       \textcolor{comment}{! notice that the above line ensures a damping only if MEKE is positive,}
00364       \textcolor{comment}{! while leaving MEKE unchanged if it is negative}
00365       meke%MEKE(i,j) =  meke%MEKE(i,j) / (1.0 + sdt\_damp*ldamping)
00366       meke\_decay(i,j) = ldamping*g%mask2dT(i,j)
00367 \textcolor{keywordflow}{    enddo} ;\textcolor{keywordflow}{ enddo}
00368 
00369     \textcolor{keywordflow}{if} (cs%kh\_flux\_enabled .or. cs%MEKE\_K4 >= 0.0) \textcolor{keywordflow}{then}
00370       \textcolor{comment}{! Update MEKE in the halos for lateral or bi-harmonic diffusion}
00371       \textcolor{keyword}{call }cpu\_clock\_begin(cs%id\_clock\_pass)
00372       \textcolor{keyword}{call }do\_group\_pass(cs%pass\_MEKE, g%Domain)
00373       \textcolor{keyword}{call }cpu\_clock\_end(cs%id\_clock\_pass)
00374 \textcolor{keywordflow}{    endif}
00375 
00376     \textcolor{keywordflow}{if} (cs%MEKE\_K4 >= 0.0) \textcolor{keywordflow}{then}
00377       \textcolor{comment}{! Calculate Laplacian of MEKE using MEKE\_uflux and MEKE\_vflux as temporary work space.}
00378       \textcolor{comment}{!$OMP parallel do default(shared)}
00379       \textcolor{keywordflow}{do} j=js-1,je+1 ; \textcolor{keywordflow}{do} i=is-2,ie+1
00380         \textcolor{comment}{! MEKE\_uflux is used here as workspace with units of [L2 T-2 ~> m2 s-2].}
00381         meke\_uflux(i,j) = ((g%dy\_Cu(i,j)*g%IdxCu(i,j)) * g%mask2dCu(i,j)) * &
00382             (meke%MEKE(i+1,j) - meke%MEKE(i,j))
00383       \textcolor{comment}{! This would have units of [R Z L2 T-2 ~> kg s-2]}
00384       \textcolor{comment}{! MEKE\_uflux(I,j) = ((G%dy\_Cu(I,j)*G%IdxCu(I,j)) * &}
00385       \textcolor{comment}{!     ((2.0*mass(i,j)*mass(i+1,j)) / ((mass(i,j)+mass(i+1,j)) + mass\_neglect)) ) * &}
00386       \textcolor{comment}{!     (MEKE%MEKE(i+1,j) - MEKE%MEKE(i,j))}
00387 \textcolor{keywordflow}{      enddo} ;\textcolor{keywordflow}{ enddo}
00388       \textcolor{comment}{!$OMP parallel do default(shared)}
00389       \textcolor{keywordflow}{do} j=js-2,je+1 ; \textcolor{keywordflow}{do} i=is-1,ie+1
00390         \textcolor{comment}{! MEKE\_vflux is used here as workspace with units of [L2 T-2 ~> m2 s-2].}
00391         meke\_vflux(i,j) = ((g%dx\_Cv(i,j)*g%IdyCv(i,j)) * g%mask2dCv(i,j)) * &
00392             (meke%MEKE(i,j+1) - meke%MEKE(i,j))
00393       \textcolor{comment}{! This would have units of [R Z L2 T-2 ~> kg s-2]}
00394       \textcolor{comment}{! MEKE\_vflux(i,J) = ((G%dx\_Cv(i,J)*G%IdyCv(i,J)) * &}
00395       \textcolor{comment}{!     ((2.0*mass(i,j)*mass(i,j+1)) / ((mass(i,j)+mass(i,j+1)) + mass\_neglect)) ) * &}
00396       \textcolor{comment}{!     (MEKE%MEKE(i,j+1) - MEKE%MEKE(i,j))}
00397 \textcolor{keywordflow}{      enddo} ;\textcolor{keywordflow}{ enddo}
00398 
00399       \textcolor{comment}{!$OMP parallel do default(shared)}
00400       \textcolor{keywordflow}{do} j=js-1,je+1 ; \textcolor{keywordflow}{do} i=is-1,ie+1 \textcolor{comment}{! del2MEKE has units [T-2 ~> s-2].}
00401         del2meke(i,j) = g%IareaT(i,j) * &
00402             ((meke\_uflux(i,j) - meke\_uflux(i-1,j)) + (meke\_vflux(i,j) - meke\_vflux(i,j-1)))
00403 \textcolor{keywordflow}{      enddo} ;\textcolor{keywordflow}{ enddo}
00404 
00405       \textcolor{comment}{! Bi-harmonic diffusion of MEKE}
00406       \textcolor{comment}{!$OMP parallel do default(shared) private(K4\_here,Inv\_K4\_max)}
00407       \textcolor{keywordflow}{do} j=js,je ; \textcolor{keywordflow}{do} i=is-1,ie
00408         k4\_here = cs%MEKE\_K4 \textcolor{comment}{! [L4 T-1 ~> m4 s-1]}
00409         \textcolor{comment}{! Limit Kh to avoid CFL violations.}
00410         inv\_k4\_max = 64.0 * sdt * ((g%dy\_Cu(i,j)*g%IdxCu(i,j)) * &
00411                      max(g%IareaT(i,j), g%IareaT(i+1,j)))**2
00412         \textcolor{keywordflow}{if} (k4\_here*inv\_k4\_max > 0.3) k4\_here = 0.3 / inv\_k4\_max
00413 
00414         \textcolor{comment}{! Here the units of MEKE\_uflux are [R Z L4 T-3 ~> kg m2 s-3].}
00415         meke\_uflux(i,j) = ((k4\_here * (g%dy\_Cu(i,j)*g%IdxCu(i,j))) * &
00416             ((2.0*mass(i,j)*mass(i+1,j)) / ((mass(i,j)+mass(i+1,j)) + mass\_neglect)) ) * &
00417             (del2meke(i+1,j) - del2meke(i,j))
00418 \textcolor{keywordflow}{      enddo} ;\textcolor{keywordflow}{ enddo}
00419       \textcolor{comment}{!$OMP parallel do default(shared) private(K4\_here,Inv\_K4\_max)}
00420       \textcolor{keywordflow}{do} j=js-1,je ; \textcolor{keywordflow}{do} i=is,ie
00421         k4\_here = cs%MEKE\_K4 \textcolor{comment}{! [L4 T-1 ~> m4 s-1]}
00422         inv\_k4\_max = 64.0 * sdt * ((g%dx\_Cv(i,j)*g%IdyCv(i,j)) * max(g%IareaT(i,j), g%IareaT(i,j+1)))**2
00423         \textcolor{keywordflow}{if} (k4\_here*inv\_k4\_max > 0.3) k4\_here = 0.3 / inv\_k4\_max
00424 
00425         \textcolor{comment}{! Here the units of MEKE\_vflux are [R Z L4 T-3 ~> kg m2 s-3].}
00426         meke\_vflux(i,j) = ((k4\_here * (g%dx\_Cv(i,j)*g%IdyCv(i,j))) * &
00427             ((2.0*mass(i,j)*mass(i,j+1)) / ((mass(i,j)+mass(i,j+1)) + mass\_neglect)) ) * &
00428             (del2meke(i,j+1) - del2meke(i,j))
00429 \textcolor{keywordflow}{      enddo} ;\textcolor{keywordflow}{ enddo}
00430       \textcolor{comment}{! Store change in MEKE arising from the bi-harmonic in del4MEKE [L2 T-2 ~> m2 s-2].}
00431       \textcolor{comment}{!$OMP parallel do default(shared)}
00432       \textcolor{keywordflow}{do} j=js,je ; \textcolor{keywordflow}{do} i=is,ie
00433         del4meke(i,j) = (sdt*(g%IareaT(i,j)*i\_mass(i,j))) * &
00434             ((meke\_uflux(i-1,j) - meke\_uflux(i,j)) + &
00435              (meke\_vflux(i,j-1) - meke\_vflux(i,j)))
00436 \textcolor{keywordflow}{      enddo} ;\textcolor{keywordflow}{ enddo}
00437 \textcolor{keywordflow}{    endif} \textcolor{comment}{!}
00438 
00439     \textcolor{keywordflow}{if} (cs%kh\_flux\_enabled) \textcolor{keywordflow}{then}
00440       \textcolor{comment}{! Lateral diffusion of MEKE}
00441       kh\_here = max(0., cs%MEKE\_Kh)
00442       \textcolor{comment}{!$OMP parallel do default(shared) firstprivate(Kh\_here) private(Inv\_Kh\_max)}
00443       \textcolor{keywordflow}{do} j=js,je ; \textcolor{keywordflow}{do} i=is-1,ie
00444         \textcolor{comment}{! Limit Kh to avoid CFL violations.}
00445         \textcolor{keywordflow}{if} (\textcolor{keyword}{associated}(meke%Kh)) &
00446           kh\_here = max(0., cs%MEKE\_Kh) + &
00447               cs%KhMEKE\_Fac*0.5*(meke%Kh(i,j)+meke%Kh(i+1,j))
00448         \textcolor{keywordflow}{if} (\textcolor{keyword}{associated}(meke%Kh\_diff)) &
00449           kh\_here = max(0.,cs%MEKE\_Kh) + &
00450               cs%KhMEKE\_Fac*0.5*(meke%Kh\_diff(i,j)+meke%Kh\_diff(i+1,j))
00451         inv\_kh\_max = 2.0*sdt * ((g%dy\_Cu(i,j)*g%IdxCu(i,j)) * &
00452                      max(g%IareaT(i,j),g%IareaT(i+1,j)))
00453         \textcolor{keywordflow}{if} (kh\_here*inv\_kh\_max > 0.25) kh\_here = 0.25 / inv\_kh\_max
00454         kh\_u(i,j) = kh\_here
00455 
00456         \textcolor{comment}{! Here the units of MEKE\_uflux and MEKE\_vflux are [R Z L4 T-3 ~> kg m2 s-3].}
00457         meke\_uflux(i,j) = ((kh\_here * (g%dy\_Cu(i,j)*g%IdxCu(i,j))) * &
00458             ((2.0*mass(i,j)*mass(i+1,j)) / ((mass(i,j)+mass(i+1,j)) + mass\_neglect)) ) * &
00459             (meke%MEKE(i,j) - meke%MEKE(i+1,j))
00460 \textcolor{keywordflow}{      enddo} ;\textcolor{keywordflow}{ enddo}
00461       \textcolor{comment}{!$OMP parallel do default(shared) firstprivate(Kh\_here) private(Inv\_Kh\_max)}
00462       \textcolor{keywordflow}{do} j=js-1,je ; \textcolor{keywordflow}{do} i=is,ie
00463         \textcolor{keywordflow}{if} (\textcolor{keyword}{associated}(meke%Kh)) &
00464           kh\_here = max(0.,cs%MEKE\_Kh) + cs%KhMEKE\_Fac * 0.5*(meke%Kh(i,j)+meke%Kh(i,j+1))
00465         \textcolor{keywordflow}{if} (\textcolor{keyword}{associated}(meke%Kh\_diff)) &
00466           kh\_here = max(0.,cs%MEKE\_Kh) + cs%KhMEKE\_Fac * 0.5*(meke%Kh\_diff(i,j)+meke%Kh\_diff(i,j+1))
00467         inv\_kh\_max = 2.0*sdt * ((g%dx\_Cv(i,j)*g%IdyCv(i,j)) * max(g%IareaT(i,j),g%IareaT(i,j+1)))
00468         \textcolor{keywordflow}{if} (kh\_here*inv\_kh\_max > 0.25) kh\_here = 0.25 / inv\_kh\_max
00469         kh\_v(i,j) = kh\_here
00470 
00471         \textcolor{comment}{! Here the units of MEKE\_uflux and MEKE\_vflux are [R Z L4 T-3 ~> kg m2 s-3].}
00472         meke\_vflux(i,j) = ((kh\_here * (g%dx\_Cv(i,j)*g%IdyCv(i,j))) * &
00473             ((2.0*mass(i,j)*mass(i,j+1)) / ((mass(i,j)+mass(i,j+1)) + mass\_neglect)) ) * &
00474             (meke%MEKE(i,j) - meke%MEKE(i,j+1))
00475 \textcolor{keywordflow}{      enddo} ;\textcolor{keywordflow}{ enddo}
00476       \textcolor{keywordflow}{if} (cs%MEKE\_advection\_factor>0.) \textcolor{keywordflow}{then}
00477         advfac = cs%MEKE\_advection\_factor / sdt \textcolor{comment}{! [T-1 ~> s-1]}
00478         \textcolor{comment}{!$OMP parallel do default(shared)}
00479         \textcolor{keywordflow}{do} j=js,je ; \textcolor{keywordflow}{do} i=is-1,ie
00480           \textcolor{comment}{! Here the units of the quantities added to MEKE\_uflux are [R Z L4 T-3 ~> kg m2 s-3].}
00481           \textcolor{keywordflow}{if} (barohu(i,j)>0.) \textcolor{keywordflow}{then}
00482             meke\_uflux(i,j) = meke\_uflux(i,j) + barohu(i,j)*meke%MEKE(i,j)*advfac
00483           \textcolor{keywordflow}{elseif} (barohu(i,j)<0.) \textcolor{keywordflow}{then}
00484             meke\_uflux(i,j) = meke\_uflux(i,j) + barohu(i,j)*meke%MEKE(i+1,j)*advfac
00485 \textcolor{keywordflow}{          endif}
00486 \textcolor{keywordflow}{        enddo} ;\textcolor{keywordflow}{ enddo}
00487         \textcolor{comment}{!$OMP parallel do default(shared)}
00488         \textcolor{keywordflow}{do} j=js-1,je ; \textcolor{keywordflow}{do} i=is,ie
00489           \textcolor{comment}{! Here the units of the quantities added to MEKE\_vflux are [R Z L4 T-3 ~> kg m2 s-3].}
00490           \textcolor{keywordflow}{if} (barohv(i,j)>0.) \textcolor{keywordflow}{then}
00491             meke\_vflux(i,j) = meke\_vflux(i,j) + barohv(i,j)*meke%MEKE(i,j)*advfac
00492           \textcolor{keywordflow}{elseif} (barohv(i,j)<0.) \textcolor{keywordflow}{then}
00493             meke\_vflux(i,j) = meke\_vflux(i,j) + barohv(i,j)*meke%MEKE(i,j+1)*advfac
00494 \textcolor{keywordflow}{          endif}
00495 \textcolor{keywordflow}{        enddo} ;\textcolor{keywordflow}{ enddo}
00496 \textcolor{keywordflow}{      endif}
00497 
00498       \textcolor{comment}{!$OMP parallel do default(shared)}
00499       \textcolor{keywordflow}{do} j=js,je ; \textcolor{keywordflow}{do} i=is,ie
00500         meke%MEKE(i,j) = meke%MEKE(i,j) + (sdt*(g%IareaT(i,j)*i\_mass(i,j))) * &
00501             ((meke\_uflux(i-1,j) - meke\_uflux(i,j)) + &
00502              (meke\_vflux(i,j-1) - meke\_vflux(i,j)))
00503 \textcolor{keywordflow}{      enddo} ;\textcolor{keywordflow}{ enddo}
00504 \textcolor{keywordflow}{    endif} \textcolor{comment}{! MEKE\_KH>0}
00505 
00506     \textcolor{comment}{! Add on bi-harmonic tendency}
00507     \textcolor{keywordflow}{if} (cs%MEKE\_K4 >= 0.0) \textcolor{keywordflow}{then}
00508       \textcolor{comment}{!$OMP parallel do default(shared)}
00509       \textcolor{keywordflow}{do} j=js,je ; \textcolor{keywordflow}{do} i=is,ie
00510         meke%MEKE(i,j) = meke%MEKE(i,j) + del4meke(i,j)
00511 \textcolor{keywordflow}{      enddo} ;\textcolor{keywordflow}{ enddo}
00512 \textcolor{keywordflow}{    endif}
00513 
00514     \textcolor{comment}{! Second stage of Strang splitting}
00515     \textcolor{keywordflow}{if} (cs%MEKE\_KH >= 0.0 .or. cs%MEKE\_K4 >= 0.0) \textcolor{keywordflow}{then}
00516       \textcolor{keywordflow}{if} (sdt>sdt\_damp) \textcolor{keywordflow}{then}
00517         \textcolor{comment}{! Recalculate the drag rate, since MEKE has changed.}
00518         \textcolor{keywordflow}{if} (use\_drag\_rate) \textcolor{keywordflow}{then}
00519           \textcolor{comment}{!$OMP parallel do default(shared)}
00520           \textcolor{keywordflow}{do} j=js,je ; \textcolor{keywordflow}{do} i=is,ie
00521             drag\_rate(i,j) = (us%L\_to\_Z*rho0 * i\_mass(i,j)) * sqrt( drag\_rate\_visc(i,j)**2 + &
00522                    cdrag2 * ( max(0.0, 2.0*bottomfac2(i,j)*meke%MEKE(i,j)) + cs%MEKE\_Uscale**2 ) )
00523 \textcolor{keywordflow}{          enddo} ;\textcolor{keywordflow}{ enddo}
00524           \textcolor{comment}{!$OMP parallel do default(shared)}
00525           \textcolor{keywordflow}{do} j=js,je ; \textcolor{keywordflow}{do} i=is,ie
00526             ldamping = cs%MEKE\_damping + drag\_rate(i,j) * bottomfac2(i,j)
00527             \textcolor{keywordflow}{if} (meke%MEKE(i,j) < 0.) ldamping = 0.
00528             \textcolor{comment}{! notice that the above line ensures a damping only if MEKE is positive,}
00529             \textcolor{comment}{! while leaving MEKE unchanged if it is negative}
00530             meke%MEKE(i,j) =  meke%MEKE(i,j) / (1.0 + sdt\_damp*ldamping)
00531             meke\_decay(i,j) = ldamping*g%mask2dT(i,j)
00532 \textcolor{keywordflow}{          enddo} ;\textcolor{keywordflow}{ enddo}
00533 \textcolor{keywordflow}{        endif}
00534 \textcolor{keywordflow}{      endif}
00535 \textcolor{keywordflow}{    endif} \textcolor{comment}{! MEKE\_KH>=0}
00536 
00537  \textcolor{comment}{!   do j=js,je ; do i=is,ie}
00538  \textcolor{comment}{!     MEKE%MEKE(i,j) =  MAX(MEKE%MEKE(i,j),0.0)}
00539  \textcolor{comment}{!   enddo ; enddo}
00540 
00541     \textcolor{keyword}{call }cpu\_clock\_begin(cs%id\_clock\_pass)
00542     \textcolor{keyword}{call }do\_group\_pass(cs%pass\_MEKE, g%Domain)
00543     \textcolor{keyword}{call }cpu\_clock\_end(cs%id\_clock\_pass)
00544 
00545     \textcolor{comment}{! Calculate diffusivity for main model to use}
00546     \textcolor{keywordflow}{if} (cs%MEKE\_KhCoeff>0.) \textcolor{keywordflow}{then}
00547       \textcolor{keywordflow}{if} (.not.cs%MEKE\_GEOMETRIC) \textcolor{keywordflow}{then}
00548         \textcolor{keywordflow}{if} (cs%use\_old\_lscale) \textcolor{keywordflow}{then}
00549           \textcolor{keywordflow}{if} (cs%Rd\_as\_max\_scale) \textcolor{keywordflow}{then}
00550             \textcolor{comment}{!$OMP parallel do default(shared)}
00551             \textcolor{keywordflow}{do} j=js,je ; \textcolor{keywordflow}{do} i=is,ie
00552               meke%Kh(i,j) = (cs%MEKE\_KhCoeff * &
00553                          sqrt(2.*max(0.,barotrfac2(i,j)*meke%MEKE(i,j))*g%areaT(i,j)) ) * &
00554                          min(meke%Rd\_dx\_h(i,j), 1.0)
00555 \textcolor{keywordflow}{            enddo} ;\textcolor{keywordflow}{ enddo}
00556           \textcolor{keywordflow}{else}
00557             \textcolor{comment}{!$OMP parallel do default(shared)}
00558             \textcolor{keywordflow}{do} j=js,je ; \textcolor{keywordflow}{do} i=is,ie
00559               meke%Kh(i,j) = cs%MEKE\_KhCoeff * &
00560                   sqrt(2.*max(0., barotrfac2(i,j)*meke%MEKE(i,j))*g%areaT(i,j))
00561 \textcolor{keywordflow}{            enddo} ;\textcolor{keywordflow}{ enddo}
00562 \textcolor{keywordflow}{          endif}
00563         \textcolor{keywordflow}{else}
00564           \textcolor{comment}{!$OMP parallel do default(shared)}
00565           \textcolor{keywordflow}{do} j=js,je ; \textcolor{keywordflow}{do} i=is,ie
00566             meke%Kh(i,j) = cs%MEKE\_KhCoeff * &
00567                 sqrt(2.*max(0., barotrfac2(i,j)*meke%MEKE(i,j))) * lmixscale(i,j)
00568 \textcolor{keywordflow}{          enddo} ;\textcolor{keywordflow}{ enddo}
00569 \textcolor{keywordflow}{        endif}
00570 \textcolor{keywordflow}{      endif}
00571 \textcolor{keywordflow}{    endif}
00572 
00573     \textcolor{comment}{! Calculate viscosity for the main model to use}
00574     \textcolor{keywordflow}{if} (cs%viscosity\_coeff\_Ku /=0.) \textcolor{keywordflow}{then}
00575       \textcolor{keywordflow}{do} j=js,je ; \textcolor{keywordflow}{do} i=is,ie
00576         meke%Ku(i,j) = cs%viscosity\_coeff\_Ku * sqrt(2.*max(0.,meke%MEKE(i,j))) * lmixscale(i,j)
00577 \textcolor{keywordflow}{      enddo} ;\textcolor{keywordflow}{ enddo}
00578 \textcolor{keywordflow}{    endif}
00579 
00580     \textcolor{keywordflow}{if} (cs%viscosity\_coeff\_Au /=0.) \textcolor{keywordflow}{then}
00581       \textcolor{keywordflow}{do} j=js,je ; \textcolor{keywordflow}{do} i=is,ie
00582         meke%Au(i,j) = cs%viscosity\_coeff\_Au * sqrt(2.*max(0.,meke%MEKE(i,j))) * lmixscale(i,j)**3
00583 \textcolor{keywordflow}{      enddo} ;\textcolor{keywordflow}{ enddo}
00584 \textcolor{keywordflow}{    endif}
00585 
00586     \textcolor{keywordflow}{if} (\textcolor{keyword}{associated}(meke%Kh) .or. \textcolor{keyword}{associated}(meke%Ku) .or. \textcolor{keyword}{associated}(meke%Au)) \textcolor{keywordflow}{then}
00587       \textcolor{keyword}{call }cpu\_clock\_begin(cs%id\_clock\_pass)
00588       \textcolor{keyword}{call }do\_group\_pass(cs%pass\_Kh, g%Domain)
00589       \textcolor{keyword}{call }cpu\_clock\_end(cs%id\_clock\_pass)
00590 \textcolor{keywordflow}{    endif}
00591 
00592     \textcolor{comment}{! Offer fields for averaging.}
00593     \textcolor{keywordflow}{if} (any([cs%id\_Ue, cs%id\_Ub, cs%id\_Ut] > 0)) &
00594       tmp(:,:) = 0.
00595     \textcolor{keywordflow}{if} (cs%id\_MEKE>0) \textcolor{keyword}{call }post\_data(cs%id\_MEKE, meke%MEKE, cs%diag)
00596     \textcolor{keywordflow}{if} (cs%id\_Ue>0) \textcolor{keywordflow}{then}
00597       \textcolor{keywordflow}{do} j=js,je ; \textcolor{keywordflow}{do} i=is,ie
00598         tmp(i,j) = sqrt(max(0., 2. * meke%MEKE(i,j)))
00599 \textcolor{keywordflow}{      enddo} ;\textcolor{keywordflow}{ enddo}
00600       \textcolor{keyword}{call }post\_data(cs%id\_Ue, tmp, cs%diag)
00601 \textcolor{keywordflow}{    endif}
00602     \textcolor{keywordflow}{if} (cs%id\_Ub>0) \textcolor{keywordflow}{then}
00603       \textcolor{keywordflow}{do} j=js,je ; \textcolor{keywordflow}{do} i=is,ie
00604         tmp(i,j) = sqrt(max(0., 2. * meke%MEKE(i,j) * bottomfac2(i,j)))
00605 \textcolor{keywordflow}{      enddo} ;\textcolor{keywordflow}{ enddo}
00606       \textcolor{keyword}{call }post\_data(cs%id\_Ub, tmp, cs%diag)
00607 \textcolor{keywordflow}{    endif}
00608     \textcolor{keywordflow}{if} (cs%id\_Ut>0) \textcolor{keywordflow}{then}
00609       \textcolor{keywordflow}{do} j=js,je ; \textcolor{keywordflow}{do} i=is,ie
00610         tmp(i,j) = sqrt(max(0., 2. * meke%MEKE(i,j) * barotrfac2(i,j)))
00611 \textcolor{keywordflow}{      enddo} ;\textcolor{keywordflow}{ enddo}
00612       \textcolor{keyword}{call }post\_data(cs%id\_Ut, tmp, cs%diag)
00613 \textcolor{keywordflow}{    endif}
00614     \textcolor{keywordflow}{if} (cs%id\_Kh>0) \textcolor{keyword}{call }post\_data(cs%id\_Kh, meke%Kh, cs%diag)
00615     \textcolor{keywordflow}{if} (cs%id\_Ku>0) \textcolor{keyword}{call }post\_data(cs%id\_Ku, meke%Ku, cs%diag)
00616     \textcolor{keywordflow}{if} (cs%id\_Au>0) \textcolor{keyword}{call }post\_data(cs%id\_Au, meke%Au, cs%diag)
00617     \textcolor{keywordflow}{if} (cs%id\_KhMEKE\_u>0) \textcolor{keyword}{call }post\_data(cs%id\_KhMEKE\_u, kh\_u, cs%diag)
00618     \textcolor{keywordflow}{if} (cs%id\_KhMEKE\_v>0) \textcolor{keyword}{call }post\_data(cs%id\_KhMEKE\_v, kh\_v, cs%diag)
00619     \textcolor{keywordflow}{if} (cs%id\_src>0) \textcolor{keyword}{call }post\_data(cs%id\_src, src, cs%diag)
00620     \textcolor{keywordflow}{if} (cs%id\_decay>0) \textcolor{keyword}{call }post\_data(cs%id\_decay, meke\_decay, cs%diag)
00621     \textcolor{keywordflow}{if} (cs%id\_GM\_src>0) \textcolor{keyword}{call }post\_data(cs%id\_GM\_src, meke%GM\_src, cs%diag)
00622     \textcolor{keywordflow}{if} (cs%id\_mom\_src>0) \textcolor{keyword}{call }post\_data(cs%id\_mom\_src, meke%mom\_src, cs%diag)
00623     \textcolor{keywordflow}{if} (cs%id\_GME\_snk>0) \textcolor{keyword}{call }post\_data(cs%id\_GME\_snk, meke%GME\_snk, cs%diag)
00624     \textcolor{keywordflow}{if} (cs%id\_Le>0) \textcolor{keyword}{call }post\_data(cs%id\_Le, lmixscale, cs%diag)
00625     \textcolor{keywordflow}{if} (cs%id\_gamma\_b>0) \textcolor{keywordflow}{then}
00626       \textcolor{keywordflow}{do} j=js,je ; \textcolor{keywordflow}{do} i=is,ie
00627         bottomfac2(i,j) = sqrt(bottomfac2(i,j))
00628 \textcolor{keywordflow}{      enddo} ;\textcolor{keywordflow}{ enddo}
00629       \textcolor{keyword}{call }post\_data(cs%id\_gamma\_b, bottomfac2, cs%diag)
00630 \textcolor{keywordflow}{    endif}
00631     \textcolor{keywordflow}{if} (cs%id\_gamma\_t>0) \textcolor{keywordflow}{then}
00632       \textcolor{keywordflow}{do} j=js,je ; \textcolor{keywordflow}{do} i=is,ie
00633         barotrfac2(i,j) = sqrt(barotrfac2(i,j))
00634 \textcolor{keywordflow}{      enddo} ;\textcolor{keywordflow}{ enddo}
00635       \textcolor{keyword}{call }post\_data(cs%id\_gamma\_t, barotrfac2, cs%diag)
00636 \textcolor{keywordflow}{    endif}
00637 
00638 \textcolor{keyword}{end subroutine }\hyperlink{namespacemom__meke_a5f752f097ddeba7071e1703110e51bc2}{step\_forward\_meke}
00639 \textcolor{comment}{}
00640 \textcolor{comment}{!> Calculates the equilibrium solutino where the source depends only on MEKE diffusivity}
00641 \textcolor{comment}{!! and there is no lateral diffusion of MEKE.}
00642 \textcolor{comment}{!! Results is in MEKE%MEKE.}
00643 \textcolor{keyword}{subroutine }\hyperlink{namespacemom__meke_a0ef9a8bcdf705b544db9b8c28a5e6a56}{meke\_equilibrium}(CS, MEKE, G, GV, US, SN\_u, SN\_v, drag\_rate\_visc, I\_mass)
\Hypertarget{MOM__MEKE_8F90_source_l00644}\hyperlink{namespacemom__meke_a0ef9a8bcdf705b544db9b8c28a5e6a56}{00644}   \textcolor{keywordtype}{type}(ocean\_grid\_type),             \textcolor{keywordtype}{intent(inout)} :: G\textcolor{comment}{    !< Ocean grid.}
00645   \textcolor{keywordtype}{type}(verticalgrid\_type),           \textcolor{keywordtype}{intent(in)}    :: GV\textcolor{comment}{   !< Ocean vertical grid structure.}
00646   \textcolor{keywordtype}{type}(\hyperlink{structmom__unit__scaling_1_1unit__scale__type}{unit\_scale\_type}),             \textcolor{keywordtype}{intent(in)}    :: US\textcolor{comment}{   !< A dimensional unit scaling
       type}
00647   \textcolor{keywordtype}{type}(\hyperlink{structmom__meke_1_1meke__cs}{meke\_cs}),                     \textcolor{keywordtype}{pointer}       :: CS\textcolor{comment}{   !< MEKE control structure.}
00648   \textcolor{keywordtype}{type}(meke\_type),                   \textcolor{keywordtype}{pointer}       :: MEKE\textcolor{comment}{ !< A structure with MEKE data.}
00649   \textcolor{keywordtype}{real}, \textcolor{keywordtype}{dimension(SZIB\_(G),SZJ\_(G))}, \textcolor{keywordtype}{intent(in)}    :: SN\_u\textcolor{comment}{ !< Eady growth rate at u-points [T-1 ~> s-1].}
00650   \textcolor{keywordtype}{real}, \textcolor{keywordtype}{dimension(SZI\_(G),SZJB\_(G))}, \textcolor{keywordtype}{intent(in)}    :: SN\_v\textcolor{comment}{ !< Eady growth rate at v-points [T-1 ~> s-1].}
00651   \textcolor{keywordtype}{real}, \textcolor{keywordtype}{dimension(SZI\_(G),SZJ\_(G))},  \textcolor{keywordtype}{intent(in)}    :: drag\_rate\_visc\textcolor{comment}{ !< Mean flow velocity contribution}
00652 \textcolor{comment}{                                                           !! to the MEKE drag rate [L T-1 ~> m s-1]}
00653   \textcolor{keywordtype}{real}, \textcolor{keywordtype}{dimension(SZI\_(G),SZJ\_(G))},  \textcolor{keywordtype}{intent(in)}    :: I\_mass\textcolor{comment}{  !< Inverse of column mass [R-1 Z-1 ~> m2
       kg-1].}
00654   \textcolor{comment}{! Local variables}
00655   \textcolor{keywordtype}{real} :: beta \textcolor{comment}{! Combined topograpic and planetary vorticity gradient [T-1 L-1 ~> s-1 m-1]}
00656   \textcolor{keywordtype}{real} :: SN   \textcolor{comment}{! The local Eady growth rate [T-1 ~> s-1]}
00657   \textcolor{keywordtype}{real} :: bottomFac2, barotrFac2    \textcolor{comment}{! Vertical structure factors [nondim]}
00658   \textcolor{keywordtype}{real} :: LmixScale, LRhines, LEady \textcolor{comment}{! Various mixing length scales [L ~> m]}
00659   \textcolor{keywordtype}{real} :: I\_H, KhCoeff
00660   \textcolor{keywordtype}{real} :: Kh    \textcolor{comment}{! A lateral diffusivity [L2 T-1 ~> m2 s-1]}
00661   \textcolor{keywordtype}{real} :: Ubg2  \textcolor{comment}{! Background (tidal?) velocity squared [L2 T-2 ~> m2 s-2]}
00662   \textcolor{keywordtype}{real} :: cd2
00663   \textcolor{keywordtype}{real} :: drag\_rate \textcolor{comment}{! The MEKE spindown timescale due to bottom drag [T-1 ~> s-1].}
00664   \textcolor{keywordtype}{real} :: src   \textcolor{comment}{! The sum of MEKE sources [L2 T-3 ~> W kg-1]}
00665   \textcolor{keywordtype}{real} :: ldamping  \textcolor{comment}{! The MEKE damping rate [T-1 ~> s-1].}
00666   \textcolor{keywordtype}{real} :: EKE, EKEmin, EKEmax, EKEerr \textcolor{comment}{! [L2 T-2 ~> m2 s-2]}
00667   \textcolor{keywordtype}{real} :: resid, ResMin, ResMax \textcolor{comment}{! Residuals [L2 T-3 ~> W kg-1]}
00668   \textcolor{keywordtype}{real} :: FatH    \textcolor{comment}{! Coriolis parameter at h points; to compute topographic beta [T-1 ~> s-1]}
00669   \textcolor{keywordtype}{real} :: beta\_topo\_x, beta\_topo\_y    \textcolor{comment}{! Topographic PV gradients in x and y [T-1 L-1 ~> s-1 m-1]}
00670   \textcolor{keywordtype}{integer} :: i, j, is, ie, js, je, n1, n2
00671   \textcolor{keywordtype}{real} :: tolerance \textcolor{comment}{! Width of EKE bracket [L2 T-2 ~> m2 s-2].}
00672   \textcolor{keywordtype}{logical} :: useSecant, debugIteration
00673 
00674   \textcolor{keywordtype}{real} :: Lgrid, Ldeform, Lfrict
00675 
00676   is = g%isc ; ie = g%iec ; js = g%jsc ; je = g%jec
00677 
00678   debugiteration = .false.
00679   khcoeff = cs%MEKE\_KhCoeff
00680   ubg2 = cs%MEKE\_Uscale**2
00681   cd2 = cs%cdrag**2
00682   tolerance = 1.0e-12*us%m\_s\_to\_L\_T**2
00683 
00684 \textcolor{comment}{!$OMP do}
00685   \textcolor{keywordflow}{do} j=js,je ; \textcolor{keywordflow}{do} i=is,ie
00686     \textcolor{comment}{! SN = 0.25*max( (SN\_u(I,j) + SN\_u(I-1,j)) + (SN\_v(i,J) + SN\_v(i,J-1)), 0.)}
00687     \textcolor{comment}{! This avoids extremes values in equilibrium solution due to bad values in SN\_u, SN\_v}
00688     sn = min(sn\_u(i,j), sn\_u(i-1,j), sn\_v(i,j), sn\_v(i,j-1))
00689 
00690     \textcolor{keywordflow}{if} (cs%MEKE\_equilibrium\_alt) \textcolor{keywordflow}{then}
00691       meke%MEKE(i,j) = (cs%MEKE\_GEOMETRIC\_alpha * sn * us%Z\_to\_m*g%bathyT(i,j))**2 / cd2
00692     \textcolor{keywordflow}{else}
00693       fath = 0.25*((g%CoriolisBu(i,j) + g%CoriolisBu(i-1,j-1)) + &
00694                    (g%CoriolisBu(i-1,j) + g%CoriolisBu(i,j-1))) \textcolor{comment}{! Coriolis parameter at h points}
00695 
00696       \textcolor{comment}{! Since zero-bathymetry cells are masked, this avoids calculations on land}
00697       \textcolor{keywordflow}{if} (cs%MEKE\_topographic\_beta == 0. .or. g%bathyT(i,j) == 0.) \textcolor{keywordflow}{then}
00698         beta\_topo\_x = 0. ; beta\_topo\_y = 0.
00699       \textcolor{keywordflow}{else}
00700         \textcolor{comment}{!### Consider different combinations of these estimates of topographic beta, and the use}
00701         \textcolor{comment}{!    of the water column thickness instead of the bathymetric depth.}
00702         beta\_topo\_x = -cs%MEKE\_topographic\_beta * fath * 0.5 * ( &
00703                       (g%bathyT(i+1,j)-g%bathyT(i,j)) * g%IdxCu(i,j)  &
00704                   / max(g%bathyT(i+1,j),g%bathyT(i,j), gv%H\_subroundoff) &
00705               +       (g%bathyT(i,j)-g%bathyT(i-1,j)) * g%IdxCu(i-1,j) &
00706                   / max(g%bathyT(i,j),g%bathyT(i-1,j), gv%H\_subroundoff) )
00707         beta\_topo\_y = -cs%MEKE\_topographic\_beta * fath * 0.5 * ( &
00708                       (g%bathyT(i,j+1)-g%bathyT(i,j)) * g%IdyCv(i,j)  &
00709                   / max(g%bathyT(i,j+1),g%bathyT(i,j), gv%H\_subroundoff) + &
00710                       (g%bathyT(i,j)-g%bathyT(i,j-1)) * g%IdyCv(i,j-1) &
00711                   / max(g%bathyT(i,j),g%bathyT(i,j-1), gv%H\_subroundoff) )
00712 \textcolor{keywordflow}{      endif}
00713       beta =  sqrt((g%dF\_dx(i,j) + beta\_topo\_x)**2 + &
00714                    (g%dF\_dy(i,j) + beta\_topo\_y)**2 )
00715 
00716       i\_h = us%L\_to\_Z*gv%Rho0 * i\_mass(i,j)
00717 
00718       \textcolor{keywordflow}{if} (khcoeff*sn*i\_h>0.) \textcolor{keywordflow}{then}
00719         \textcolor{comment}{! Solve resid(E) = 0, where resid = Kh(E) * (SN)^2 - damp\_rate(E) E}
00720         ekemin = 0.   \textcolor{comment}{! Use the trivial root as the left bracket}
00721         resmin = 0.   \textcolor{comment}{! Need to detect direction of left residual}
00722         ekemax = 0.01*us%m\_s\_to\_L\_T**2 \textcolor{comment}{! First guess at right bracket}
00723         usesecant = .false. \textcolor{comment}{! Start using a bisection method}
00724 
00725         \textcolor{comment}{! First find right bracket for which resid<0}
00726         resid = 1.0*us%m\_to\_L**2*us%T\_to\_s**3 ; n1 = 0
00727         \textcolor{keywordflow}{do} \textcolor{keywordflow}{while} (resid>0.)
00728           n1 = n1 + 1
00729           eke = ekemax
00730           \textcolor{keyword}{call }\hyperlink{namespacemom__meke_aed5885cde342caa59b2b9cde72a3e1e7}{meke\_lengthscales\_0d}(cs, us, g%areaT(i,j), beta, g%bathyT(i,j), &
00731                                     meke%Rd\_dx\_h(i,j), sn, eke, &
00732                                     bottomfac2, barotrfac2, lmixscale, lrhines, leady)
00733           \textcolor{comment}{! TODO: Should include resolution function in Kh}
00734           kh = (khcoeff * sqrt(2.*barotrfac2*eke) * lmixscale)
00735           src = kh * (sn * sn)
00736           drag\_rate = i\_h * sqrt(drag\_rate\_visc(i,j)**2 + cd2 * ( 2.0*bottomfac2*eke + ubg2 ) )
00737           ldamping = cs%MEKE\_damping + drag\_rate * bottomfac2
00738           resid = src - ldamping * eke
00739           \textcolor{comment}{! if (debugIteration) then}
00740           \textcolor{comment}{!   write(0,*) n1, 'EKE=',EKE,'resid=',resid}
00741           \textcolor{comment}{!   write(0,*) 'EKEmin=',EKEmin,'ResMin=',ResMin}
00742           \textcolor{comment}{!   write(0,*) 'src=',src,'ldamping=',ldamping}
00743           \textcolor{comment}{!   write(0,*) 'gamma-b=',bottomFac2,'gamma-t=',barotrFac2}
00744           \textcolor{comment}{!   write(0,*) 'drag\_visc=',drag\_rate\_visc(i,j),'Ubg2=',Ubg2}
00745           \textcolor{comment}{! endif}
00746           \textcolor{keywordflow}{if} (resid>0.) \textcolor{keywordflow}{then}    \textcolor{comment}{! EKE is to the left of the root}
00747             ekemin = eke        \textcolor{comment}{! so we move the left bracket here}
00748             ekemax = 10. * eke  \textcolor{comment}{! and guess again for the right bracket}
00749             \textcolor{keywordflow}{if} (resid<resmin) usesecant = .true.
00750             resmin = resid
00751             \textcolor{keywordflow}{if} (ekemax > 2.e17*us%m\_s\_to\_L\_T**2) \textcolor{keywordflow}{then}
00752               \textcolor{keywordflow}{if} (debugiteration) stop \textcolor{stringliteral}{'Something has gone very wrong'}
00753               debugiteration = .true.
00754               resid = 1. ; n1 = 0
00755               ekemin = 0. ; resmin = 0.
00756               ekemax = 0.01*us%m\_s\_to\_L\_T**2
00757               usesecant = .false.
00758 \textcolor{keywordflow}{            endif}
00759 \textcolor{keywordflow}{          endif}
00760 \textcolor{keywordflow}{        enddo} \textcolor{comment}{! while(resid>0.) searching for right bracket}
00761         resmax = resid
00762 
00763         \textcolor{comment}{! Bisect the bracket}
00764         n2 = 0 ; ekeerr = ekemax - ekemin
00765         \textcolor{keywordflow}{do} \textcolor{keywordflow}{while} (ekeerr > tolerance)
00766           n2 = n2 + 1
00767           \textcolor{keywordflow}{if} (usesecant) \textcolor{keywordflow}{then}
00768             eke = ekemin + (ekemax - ekemin) * (resmin / (resmin - resmax))
00769           \textcolor{keywordflow}{else}
00770             eke = 0.5 * (ekemin + ekemax)
00771 \textcolor{keywordflow}{          endif}
00772           ekeerr = min( eke-ekemin, ekemax-eke )
00773           \textcolor{comment}{! TODO: Should include resolution function in Kh}
00774           kh = (khcoeff * sqrt(2.*barotrfac2*eke) * lmixscale)
00775           src = kh * (sn * sn)
00776           drag\_rate = i\_h * sqrt( drag\_rate\_visc(i,j)**2 + cd2 * ( 2.0*bottomfac2*eke + ubg2 ) )
00777           ldamping = cs%MEKE\_damping + drag\_rate * bottomfac2
00778           resid = src - ldamping * eke
00779           \textcolor{keywordflow}{if} (usesecant .and. resid>resmin) usesecant = .false.
00780           \textcolor{keywordflow}{if} (resid>0.) \textcolor{keywordflow}{then}              \textcolor{comment}{! EKE is to the left of the root}
00781             ekemin = eke                  \textcolor{comment}{! so we move the left bracket here}
00782             \textcolor{keywordflow}{if} (resid<resmin) usesecant = .true.
00783             resmin = resid                \textcolor{comment}{! Save this for the secant method}
00784           \textcolor{keywordflow}{elseif} (resid<0.) \textcolor{keywordflow}{then}          \textcolor{comment}{! EKE is to the right of the root}
00785             ekemax = eke                  \textcolor{comment}{! so we move the right bracket here}
00786             resmax = resid                \textcolor{comment}{! Save this for the secant method}
00787           \textcolor{keywordflow}{else}
00788             \textcolor{keywordflow}{exit}                          \textcolor{comment}{! resid=0 => EKE is exactly at the root}
00789 \textcolor{keywordflow}{          endif}
00790           \textcolor{keywordflow}{if} (n2>200) stop \textcolor{stringliteral}{'Failing to converge?'}
00791 \textcolor{keywordflow}{        enddo} \textcolor{comment}{! while(EKEmax-EKEmin>tolerance)}
00792 
00793       \textcolor{keywordflow}{else}
00794         eke = 0.
00795 \textcolor{keywordflow}{      endif}
00796       meke%MEKE(i,j) = eke
00797 \textcolor{keywordflow}{    endif}
00798 \textcolor{keywordflow}{  enddo} ;\textcolor{keywordflow}{ enddo}
00799 
00800 \textcolor{keyword}{end subroutine }\hyperlink{namespacemom__meke_a0ef9a8bcdf705b544db9b8c28a5e6a56}{meke\_equilibrium}
00801 
00802 
00803 \textcolor{comment}{!< This subroutine calculates a new equilibrium value for MEKE at each time step. This is not copied into}
00804 \textcolor{comment}{!! MEKE%MEKE; rather, it is used as a restoring term to nudge MEKE%MEKE back to an equilibrium value}
00805 \textcolor{keyword}{subroutine }\hyperlink{namespacemom__meke_a843244b0cc72a08489920dcda464b063}{meke\_equilibrium\_restoring}(CS, G, US, SN\_u, SN\_v)
\Hypertarget{MOM__MEKE_8F90_source_l00806}\hyperlink{namespacemom__meke_a843244b0cc72a08489920dcda464b063}{00806}   \textcolor{keywordtype}{type}(ocean\_grid\_type),             \textcolor{keywordtype}{intent(inout)} :: G\textcolor{comment}{    !< Ocean grid.}
00807   \textcolor{keywordtype}{type}(\hyperlink{structmom__unit__scaling_1_1unit__scale__type}{unit\_scale\_type}),             \textcolor{keywordtype}{intent(in)}    :: US\textcolor{comment}{   !< A dimensional unit scaling
       type.}
00808   \textcolor{keywordtype}{type}(\hyperlink{structmom__meke_1_1meke__cs}{meke\_cs}),                     \textcolor{keywordtype}{pointer}       :: CS\textcolor{comment}{   !< MEKE control structure.}
00809   \textcolor{keywordtype}{real}, \textcolor{keywordtype}{dimension(SZIB\_(G),SZJ\_(G))}, \textcolor{keywordtype}{intent(in)}    :: SN\_u\textcolor{comment}{ !< Eady growth rate at u-points [T-1 ~> s-1].}
00810   \textcolor{keywordtype}{real}, \textcolor{keywordtype}{dimension(SZI\_(G),SZJB\_(G))}, \textcolor{keywordtype}{intent(in)}    :: SN\_v\textcolor{comment}{ !< Eady growth rate at v-points [T-1 ~> s-1].}
00811   \textcolor{comment}{! Local variables}
00812   \textcolor{keywordtype}{real} :: SN                      \textcolor{comment}{! The local Eady growth rate [T-1 ~> s-1]}
00813   \textcolor{keywordtype}{integer} :: i, j, is, ie, js, je \textcolor{comment}{! local indices}
00814   \textcolor{keywordtype}{real} :: cd2                     \textcolor{comment}{! bottom drag}
00815 
00816   is = g%isc ; ie = g%iec ; js = g%jsc ; je = g%jec
00817   cd2 = cs%cdrag**2
00818 
00819   \textcolor{keywordflow}{if} (.not. \textcolor{keyword}{associated}(cs%equilibrium\_value)) \textcolor{keyword}{allocate}(cs%equilibrium\_value(szi\_(g),szj\_(g)))
00820   cs%equilibrium\_value(:,:) = 0.0
00821 
00822 \textcolor{comment}{!$OMP do}
00823   \textcolor{keywordflow}{do} j=js,je ; \textcolor{keywordflow}{do} i=is,ie
00824     \textcolor{comment}{! SN = 0.25*max( (SN\_u(I,j) + SN\_u(I-1,j)) + (SN\_v(i,J) + SN\_v(i,J-1)), 0.)}
00825     \textcolor{comment}{! This avoids extremes values in equilibrium solution due to bad values in SN\_u, SN\_v}
00826     sn = min(sn\_u(i,j), sn\_u(i-1,j), sn\_v(i,j), sn\_v(i,j-1))
00827     cs%equilibrium\_value(i,j) = (cs%MEKE\_GEOMETRIC\_alpha * sn * us%Z\_to\_m*g%bathyT(i,j))**2 / cd2
00828 \textcolor{keywordflow}{  enddo} ;\textcolor{keywordflow}{ enddo}
00829 
00830   \textcolor{keywordflow}{if} (cs%id\_MEKE\_equilibrium>0) \textcolor{keyword}{call }post\_data(cs%id\_MEKE\_equilibrium, cs%equilibrium\_value, cs%diag)
00831 
00832 \textcolor{keyword}{end subroutine }\hyperlink{namespacemom__meke_a843244b0cc72a08489920dcda464b063}{meke\_equilibrium\_restoring}
00833 \textcolor{comment}{}
00834 \textcolor{comment}{!> Calculates the eddy mixing length scale and \(\backslash\)f$\(\backslash\)gamma\_b\(\backslash\)f$ and \(\backslash\)f$\(\backslash\)gamma\_t\(\backslash\)f$}
00835 \textcolor{comment}{!! functions that are ratios of either bottom or barotropic eddy energy to the}
00836 \textcolor{comment}{!! column eddy energy, respectively.  See \(\backslash\)ref section\_MEKE\_equations.}
00837 \textcolor{keyword}{subroutine }\hyperlink{namespacemom__meke_a8180d5d0cacf48bcbdffead9e6a06efd}{meke\_lengthscales}(CS, MEKE, G, GV, US, SN\_u, SN\_v, &
00838             EKE, bottomFac2, barotrFac2, LmixScale)
\Hypertarget{MOM__MEKE_8F90_source_l00839}\hyperlink{namespacemom__meke_a8180d5d0cacf48bcbdffead9e6a06efd}{00839}   \textcolor{keywordtype}{type}(\hyperlink{structmom__meke_1_1meke__cs}{meke\_cs}),                     \textcolor{keywordtype}{pointer}       :: CS\textcolor{comment}{   !< MEKE control structure.}
00840   \textcolor{keywordtype}{type}(meke\_type),                   \textcolor{keywordtype}{pointer}       :: MEKE\textcolor{comment}{ !< MEKE data.}
00841   \textcolor{keywordtype}{type}(ocean\_grid\_type),             \textcolor{keywordtype}{intent(inout)} :: G\textcolor{comment}{    !< Ocean grid.}
00842   \textcolor{keywordtype}{type}(verticalgrid\_type),           \textcolor{keywordtype}{intent(in)}    :: GV\textcolor{comment}{   !< Ocean vertical grid structure.}
00843   \textcolor{keywordtype}{type}(\hyperlink{structmom__unit__scaling_1_1unit__scale__type}{unit\_scale\_type}),             \textcolor{keywordtype}{intent(in)}    :: US\textcolor{comment}{   !< A dimensional unit scaling
       type}
00844   \textcolor{keywordtype}{real}, \textcolor{keywordtype}{dimension(SZIB\_(G),SZJ\_(G))}, \textcolor{keywordtype}{intent(in)}    :: SN\_u\textcolor{comment}{ !< Eady growth rate at u-points [T-1 ~> s-1].}
00845   \textcolor{keywordtype}{real}, \textcolor{keywordtype}{dimension(SZI\_(G),SZJB\_(G))}, \textcolor{keywordtype}{intent(in)}    :: SN\_v\textcolor{comment}{ !< Eady growth rate at v-points [T-1 ~> s-1].}
00846   \textcolor{keywordtype}{real}, \textcolor{keywordtype}{dimension(SZI\_(G),SZJ\_(G))},  \textcolor{keywordtype}{intent(in)}    :: EKE\textcolor{comment}{  !< Eddy kinetic energy [L2 T-2 ~> m2 s-2].}
00847   \textcolor{keywordtype}{real}, \textcolor{keywordtype}{dimension(SZI\_(G),SZJ\_(G))},  \textcolor{keywordtype}{intent(out)}   :: bottomFac2\textcolor{comment}{ !< gamma\_b^2}
00848   \textcolor{keywordtype}{real}, \textcolor{keywordtype}{dimension(SZI\_(G),SZJ\_(G))},  \textcolor{keywordtype}{intent(out)}   :: barotrFac2\textcolor{comment}{ !< gamma\_t^2}
00849   \textcolor{keywordtype}{real}, \textcolor{keywordtype}{dimension(SZI\_(G),SZJ\_(G))},  \textcolor{keywordtype}{intent(out)}   :: LmixScale\textcolor{comment}{ !< Eddy mixing length [L ~> m].}
00850   \textcolor{comment}{! Local variables}
00851   \textcolor{keywordtype}{real}, \textcolor{keywordtype}{dimension(SZI\_(G),SZJ\_(G))} :: LRhines, LEady  \textcolor{comment}{! Possible mixing length scales [L ~> m]}
00852   \textcolor{keywordtype}{real} :: beta \textcolor{comment}{! Combined topograpic and planetary vorticity gradient [T-1 L-1 ~> s-1 m-1]}
00853   \textcolor{keywordtype}{real} :: SN   \textcolor{comment}{! The local Eady growth rate [T-1 ~> s-1]}
00854   \textcolor{keywordtype}{real} :: FatH \textcolor{comment}{! Coriolis parameter at h points [T-1 ~> s-1]}
00855   \textcolor{keywordtype}{real} :: beta\_topo\_x, beta\_topo\_y  \textcolor{comment}{! Topographic PV gradients in x and y [T-1 L-1 ~> s-1 m-1]}
00856   \textcolor{keywordtype}{integer} :: i, j, is, ie, js, je
00857 
00858   is = g%isc ; ie = g%iec ; js = g%jsc ; je = g%jec
00859 
00860 \textcolor{comment}{!$OMP do}
00861   \textcolor{keywordflow}{do} j=js,je ; \textcolor{keywordflow}{do} i=is,ie
00862     \textcolor{keywordflow}{if} (.not.cs%use\_old\_lscale) \textcolor{keywordflow}{then}
00863       \textcolor{keywordflow}{if} (cs%aEady > 0.) \textcolor{keywordflow}{then}
00864         sn = 0.25 * ( (sn\_u(i,j) + sn\_u(i-1,j)) + (sn\_v(i,j) + sn\_v(i,j-1)) )
00865       \textcolor{keywordflow}{else}
00866         sn = 0.
00867 \textcolor{keywordflow}{      endif}
00868       fath = 0.25* ( ( g%CoriolisBu(i,j) + g%CoriolisBu(i-1,j-1) ) + &
00869                      ( g%CoriolisBu(i-1,j) + g%CoriolisBu(i,j-1) ) )  \textcolor{comment}{! Coriolis parameter at h points}
00870 
00871       \textcolor{comment}{! If bathyT is zero, then a division by zero FPE will be raised.  In this}
00872       \textcolor{comment}{! case, we apply Adcroft's rule of reciprocals and set the term to zero.}
00873       \textcolor{comment}{! Since zero-bathymetry cells are masked, this should not affect values.}
00874       \textcolor{keywordflow}{if} (cs%MEKE\_topographic\_beta == 0. .or. g%bathyT(i,j) == 0.0) \textcolor{keywordflow}{then}
00875         beta\_topo\_x = 0. ; beta\_topo\_y = 0.
00876       \textcolor{keywordflow}{else}
00877         \textcolor{comment}{!### Consider different combinations of these estimates of topographic beta, and the use}
00878         \textcolor{comment}{!    of the water column thickness instead of the bathymetric depth.}
00879         beta\_topo\_x = -cs%MEKE\_topographic\_beta * fath * 0.5 * ( &
00880                       (g%bathyT(i+1,j)-g%bathyT(i,j)) * g%IdxCu(i,j)  &
00881                  / max(g%bathyT(i+1,j),g%bathyT(i,j), gv%H\_subroundoff) &
00882               +       (g%bathyT(i,j)-g%bathyT(i-1,j)) * g%IdxCu(i-1,j) &
00883                  / max(g%bathyT(i,j),g%bathyT(i-1,j), gv%H\_subroundoff) )
00884         beta\_topo\_y = -cs%MEKE\_topographic\_beta * fath * 0.5 * ( &
00885                       (g%bathyT(i,j+1)-g%bathyT(i,j)) * g%IdyCv(i,j)  &
00886                  / max(g%bathyT(i,j+1),g%bathyT(i,j), gv%H\_subroundoff) + &
00887                       (g%bathyT(i,j)-g%bathyT(i,j-1)) * g%IdyCv(i,j-1) &
00888                  / max(g%bathyT(i,j),g%bathyT(i,j-1), gv%H\_subroundoff) )
00889 \textcolor{keywordflow}{      endif}
00890       beta =  sqrt((g%dF\_dx(i,j) + beta\_topo\_x)**2 + &
00891                    (g%dF\_dy(i,j) + beta\_topo\_y)**2 )
00892 
00893     \textcolor{keywordflow}{else}
00894       beta = 0.
00895 \textcolor{keywordflow}{    endif}
00896     \textcolor{comment}{! Returns bottomFac2, barotrFac2 and LmixScale}
00897     \textcolor{keyword}{call }\hyperlink{namespacemom__meke_aed5885cde342caa59b2b9cde72a3e1e7}{meke\_lengthscales\_0d}(cs, us, g%areaT(i,j), beta, g%bathyT(i,j),  &
00898                               meke%Rd\_dx\_h(i,j), sn, meke%MEKE(i,j), &
00899                               bottomfac2(i,j), barotrfac2(i,j), lmixscale(i,j), &
00900                               lrhines(i,j), leady(i,j))
00901 \textcolor{keywordflow}{  enddo} ;\textcolor{keywordflow}{ enddo}
00902   \textcolor{keywordflow}{if} (cs%id\_Lrhines>0) \textcolor{keyword}{call }post\_data(cs%id\_LRhines, lrhines, cs%diag)
00903   \textcolor{keywordflow}{if} (cs%id\_Leady>0) \textcolor{keyword}{call }post\_data(cs%id\_LEady, leady, cs%diag)
00904 
00905 \textcolor{keyword}{end subroutine }\hyperlink{namespacemom__meke_a8180d5d0cacf48bcbdffead9e6a06efd}{meke\_lengthscales}
00906 \textcolor{comment}{}
00907 \textcolor{comment}{!> Calculates the eddy mixing length scale and \(\backslash\)f$\(\backslash\)gamma\_b\(\backslash\)f$ and \(\backslash\)f$\(\backslash\)gamma\_t\(\backslash\)f$}
00908 \textcolor{comment}{!! functions that are ratios of either bottom or barotropic eddy energy to the}
00909 \textcolor{comment}{!! column eddy energy, respectively.  See \(\backslash\)ref section\_MEKE\_equations.}
00910 \textcolor{keyword}{subroutine }\hyperlink{namespacemom__meke_aed5885cde342caa59b2b9cde72a3e1e7}{meke\_lengthscales\_0d}(CS, US, area, beta, depth, Rd\_dx, SN, EKE, & ! Z\_to\_L,
       &
00911                                 bottomFac2, barotrFac2, LmixScale, Lrhines, Leady)
\Hypertarget{MOM__MEKE_8F90_source_l00912}\hyperlink{namespacemom__meke_aed5885cde342caa59b2b9cde72a3e1e7}{00912}   \textcolor{keywordtype}{type}(\hyperlink{structmom__meke_1_1meke__cs}{meke\_cs}), \textcolor{keywordtype}{pointer}       :: CS\textcolor{comment}{         !< MEKE control structure.}
00913   \textcolor{keywordtype}{type}(\hyperlink{structmom__unit__scaling_1_1unit__scale__type}{unit\_scale\_type}), \textcolor{keywordtype}{intent(in)} :: US\textcolor{comment}{    !< A dimensional unit scaling type}
00914   \textcolor{keywordtype}{real},          \textcolor{keywordtype}{intent(in)}    :: area\textcolor{comment}{       !< Grid cell area [L2 ~> m2]}
00915   \textcolor{keywordtype}{real},          \textcolor{keywordtype}{intent(in)}    :: beta\textcolor{comment}{       !< Planetary beta = |grad F| [T-1 L-1 ~> s-1 m-1]}
00916   \textcolor{keywordtype}{real},          \textcolor{keywordtype}{intent(in)}    :: depth\textcolor{comment}{      !< Ocean depth [Z ~> m]}
00917   \textcolor{keywordtype}{real},          \textcolor{keywordtype}{intent(in)}    :: Rd\_dx\textcolor{comment}{      !< Resolution Ld/dx [nondim].}
00918   \textcolor{keywordtype}{real},          \textcolor{keywordtype}{intent(in)}    :: SN\textcolor{comment}{         !< Eady growth rate [T-1 ~> s-1].}
00919   \textcolor{keywordtype}{real},          \textcolor{keywordtype}{intent(in)}    :: EKE\textcolor{comment}{        !< Eddy kinetic energy [L2 T-2 ~> m2 s-2].}
00920 \textcolor{comment}{!  real,          intent(in)    :: Z\_to\_L     !< A conversion factor from depth units (Z) to}
00921 \textcolor{comment}{!                                             !! the units for lateral distances (L).}
00922   \textcolor{keywordtype}{real},          \textcolor{keywordtype}{intent(out)}   :: bottomFac2\textcolor{comment}{ !< gamma\_b^2}
00923   \textcolor{keywordtype}{real},          \textcolor{keywordtype}{intent(out)}   :: barotrFac2\textcolor{comment}{ !< gamma\_t^2}
00924   \textcolor{keywordtype}{real},          \textcolor{keywordtype}{intent(out)}   :: LmixScale\textcolor{comment}{  !< Eddy mixing length [L ~> m].}
00925   \textcolor{keywordtype}{real},          \textcolor{keywordtype}{intent(out)}   :: Lrhines\textcolor{comment}{    !< Rhines length scale [L ~> m].}
00926   \textcolor{keywordtype}{real},          \textcolor{keywordtype}{intent(out)}   :: Leady\textcolor{comment}{      !< Eady length scale [L ~> m].}
00927   \textcolor{comment}{! Local variables}
00928   \textcolor{keywordtype}{real} :: Lgrid, Ldeform, Lfrict \textcolor{comment}{! Length scales [L ~> m]}
00929   \textcolor{keywordtype}{real} :: Ue  \textcolor{comment}{! An eddy velocity [L T-1 ~> m s-1]}
00930 
00931   \textcolor{comment}{! Length scale for MEKE derived diffusivity}
00932   lgrid = sqrt(area)               \textcolor{comment}{! Grid scale}
00933   ldeform = lgrid * rd\_dx          \textcolor{comment}{! Deformation scale}
00934   lfrict = (us%Z\_to\_L * depth) / cs%cdrag  \textcolor{comment}{! Frictional arrest scale}
00935   \textcolor{comment}{! gamma\_b^2 is the ratio of bottom eddy energy to mean column eddy energy}
00936   \textcolor{comment}{! used in calculating bottom drag}
00937   bottomfac2 = cs%MEKE\_CD\_SCALE**2
00938   \textcolor{keywordflow}{if} (lfrict*cs%MEKE\_Cb>0.) bottomfac2 = bottomfac2 + 1./( 1. + cs%MEKE\_Cb*(ldeform/lfrict) )**0.8
00939   bottomfac2 = max(bottomfac2, cs%MEKE\_min\_gamma)
00940   \textcolor{comment}{! gamma\_t^2 is the ratio of barotropic eddy energy to mean column eddy energy}
00941   \textcolor{comment}{! used in the velocity scale for diffusivity}
00942   barotrfac2 = 1.
00943   \textcolor{keywordflow}{if} (lfrict*cs%MEKE\_Ct>0.) barotrfac2 = 1. / ( 1. + cs%MEKE\_Ct*(ldeform/lfrict) )**0.25
00944   barotrfac2 = max(barotrfac2, cs%MEKE\_min\_gamma)
00945   \textcolor{keywordflow}{if} (cs%use\_old\_lscale) \textcolor{keywordflow}{then}
00946     \textcolor{keywordflow}{if} (cs%Rd\_as\_max\_scale) \textcolor{keywordflow}{then}
00947       lmixscale = min(ldeform, lgrid) \textcolor{comment}{! The smaller of Ld or dx}
00948     \textcolor{keywordflow}{else}
00949       lmixscale = lgrid
00950 \textcolor{keywordflow}{    endif}
00951   \textcolor{keywordflow}{else}
00952     ue = sqrt( 2.0 * max( 0., barotrfac2*eke ) ) \textcolor{comment}{! Barotropic eddy flow scale}
00953     lrhines = sqrt( ue / max( beta, 1.e-30*us%T\_to\_s*us%L\_to\_m ) )       \textcolor{comment}{! Rhines scale}
00954     \textcolor{keywordflow}{if} (cs%aEady > 0.) \textcolor{keywordflow}{then}
00955       leady = ue / max( sn, 1.e-15*us%T\_to\_s ) \textcolor{comment}{! Bound Eady time-scale < 1e15 seconds}
00956     \textcolor{keywordflow}{else}
00957       leady = 0.
00958 \textcolor{keywordflow}{    endif}
00959     \textcolor{keywordflow}{if} (cs%use\_min\_lscale) \textcolor{keywordflow}{then}
00960       lmixscale = 1.e7
00961       \textcolor{keywordflow}{if} (cs%aDeform*ldeform > 0.) lmixscale = min(lmixscale,cs%aDeform*ldeform)
00962       \textcolor{keywordflow}{if} (cs%aFrict *lfrict  > 0.) lmixscale = min(lmixscale,cs%aFrict *lfrict)
00963       \textcolor{keywordflow}{if} (cs%aRhines*lrhines > 0.) lmixscale = min(lmixscale,cs%aRhines*lrhines)
00964       \textcolor{keywordflow}{if} (cs%aEady  *leady   > 0.) lmixscale = min(lmixscale,cs%aEady  *leady)
00965       \textcolor{keywordflow}{if} (cs%aGrid  *lgrid   > 0.) lmixscale = min(lmixscale,cs%aGrid  *lgrid)
00966       \textcolor{keywordflow}{if} (cs%Lfixed          > 0.) lmixscale = min(lmixscale,cs%Lfixed)
00967     \textcolor{keywordflow}{else}
00968       lmixscale = 0.
00969       \textcolor{keywordflow}{if} (cs%aDeform*ldeform > 0.) lmixscale = lmixscale + 1./(cs%aDeform*ldeform)
00970       \textcolor{keywordflow}{if} (cs%aFrict *lfrict  > 0.) lmixscale = lmixscale + 1./(cs%aFrict *lfrict)
00971       \textcolor{keywordflow}{if} (cs%aRhines*lrhines > 0.) lmixscale = lmixscale + 1./(cs%aRhines*lrhines)
00972       \textcolor{keywordflow}{if} (cs%aEady  *leady   > 0.) lmixscale = lmixscale + 1./(cs%aEady  *leady)
00973       \textcolor{keywordflow}{if} (cs%aGrid  *lgrid   > 0.) lmixscale = lmixscale + 1./(cs%aGrid  *lgrid)
00974       \textcolor{keywordflow}{if} (cs%Lfixed          > 0.) lmixscale = lmixscale + 1./cs%Lfixed
00975       \textcolor{keywordflow}{if} (lmixscale > 0.) lmixscale = 1. / lmixscale
00976 \textcolor{keywordflow}{    endif}
00977 \textcolor{keywordflow}{  endif}
00978 
00979 \textcolor{keyword}{end subroutine }\hyperlink{namespacemom__meke_aed5885cde342caa59b2b9cde72a3e1e7}{meke\_lengthscales\_0d}
00980 \textcolor{comment}{}
00981 \textcolor{comment}{!> Initializes the MOM\_MEKE module and reads parameters.}
00982 \textcolor{comment}{!! Returns True if module is to be used, otherwise returns False.}
00983 \textcolor{keyword}{logical }\textcolor{keyword}{function }\hyperlink{namespacemom__meke_a099f1cfad37430ef1bd60972a92b1be4}{meke\_init}(Time, G, US, param\_file, diag, CS, MEKE, restart\_CS)
\Hypertarget{MOM__MEKE_8F90_source_l00984}\hyperlink{namespacemom__meke_a099f1cfad37430ef1bd60972a92b1be4}{00984}   \textcolor{keywordtype}{type}(time\_type),         \textcolor{keywordtype}{intent(in)}    :: Time\textcolor{comment}{       !< The current model time.}
00985   \textcolor{keywordtype}{type}(ocean\_grid\_type),   \textcolor{keywordtype}{intent(inout)} :: G\textcolor{comment}{          !< The ocean's grid structure.}
00986   \textcolor{keywordtype}{type}(\hyperlink{structmom__unit__scaling_1_1unit__scale__type}{unit\_scale\_type}),   \textcolor{keywordtype}{intent(in)}    :: US\textcolor{comment}{         !< A dimensional unit scaling type}
00987   \textcolor{keywordtype}{type}(param\_file\_type),   \textcolor{keywordtype}{intent(in)}    :: param\_file\textcolor{comment}{ !< Parameter file parser structure.}
00988   \textcolor{keywordtype}{type}(diag\_ctrl), \textcolor{keywordtype}{target}, \textcolor{keywordtype}{intent(inout)} :: diag\textcolor{comment}{       !< Diagnostics structure.}
00989   \textcolor{keywordtype}{type}(\hyperlink{structmom__meke_1_1meke__cs}{meke\_cs}),           \textcolor{keywordtype}{pointer}       :: CS\textcolor{comment}{         !< MEKE control structure.}
00990   \textcolor{keywordtype}{type}(meke\_type),         \textcolor{keywordtype}{pointer}       :: MEKE\textcolor{comment}{       !< MEKE-related fields.}
00991   \textcolor{keywordtype}{type}(mom\_restart\_cs),    \textcolor{keywordtype}{pointer}       :: restart\_CS\textcolor{comment}{ !< Restart control structure for MOM\_MEKE.}
00992 
00993   \textcolor{comment}{! Local variables}
00994   \textcolor{keywordtype}{real}    :: I\_T\_rescale   \textcolor{comment}{! A rescaling factor for time from the internal representation in this}
00995                            \textcolor{comment}{! run to the representation in a restart file.}
00996   \textcolor{keywordtype}{real}    :: L\_rescale     \textcolor{comment}{! A rescaling factor for length from the internal representation in this}
00997                            \textcolor{comment}{! run to the representation in a restart file.}
00998   \textcolor{keywordtype}{real}    :: MEKE\_restoring\_timescale \textcolor{comment}{! The timescale used to nudge MEKE toward its equilibrium value.}
00999   \textcolor{keywordtype}{real} :: cdrag            \textcolor{comment}{! The default bottom drag coefficient [nondim].}
01000   \textcolor{keywordtype}{integer} :: i, j, is, ie, js, je, isd, ied, jsd, jed
01001   \textcolor{keywordtype}{logical} :: laplacian, biharmonic, useVarMix, coldStart
01002   \textcolor{comment}{! This include declares and sets the variable "version".}
01003 \textcolor{preprocessor}{# include "version\_variable.h"}
01004 \textcolor{preprocessor}{}  \textcolor{keywordtype}{character(len=40)}  :: mdl = \textcolor{stringliteral}{"MOM\_MEKE"} \textcolor{comment}{! This module's name.}
01005 
01006   is = g%isc ; ie = g%iec ; js = g%jsc ; je = g%jec
01007   isd = g%isd ; ied = g%ied ; jsd = g%jsd ; jed = g%jed
01008 
01009   \textcolor{comment}{! Determine whether this module will be used}
01010   \textcolor{keyword}{call }get\_param(param\_file, mdl, \textcolor{stringliteral}{"USE\_MEKE"}, \hyperlink{namespacemom__meke_a099f1cfad37430ef1bd60972a92b1be4}{meke\_init}, default=.false., do\_not\_log=.true.)
01011   \textcolor{keyword}{call }log\_version(param\_file, mdl, version, \textcolor{stringliteral}{""}, all\_default=.not.\hyperlink{namespacemom__meke_a099f1cfad37430ef1bd60972a92b1be4}{meke\_init})
01012   \textcolor{keyword}{call }get\_param(param\_file, mdl, \textcolor{stringliteral}{"USE\_MEKE"}, \hyperlink{namespacemom__meke_a099f1cfad37430ef1bd60972a92b1be4}{meke\_init}, &
01013                  \textcolor{stringliteral}{"If true, turns on the MEKE scheme which calculates "}// &
01014                  \textcolor{stringliteral}{"a sub-grid mesoscale eddy kinetic energy budget."}, &
01015                  default=.false.)
01016   \textcolor{keywordflow}{if} (.not. \hyperlink{namespacemom__meke_a099f1cfad37430ef1bd60972a92b1be4}{meke\_init}) \textcolor{keywordflow}{return}
01017 
01018   \textcolor{keywordflow}{if} (.not. \textcolor{keyword}{associated}(meke)) \textcolor{keywordflow}{then}
01019     \textcolor{comment}{! The MEKE structure should have been allocated in MEKE\_alloc\_register\_restart()}
01020     \textcolor{keyword}{call }mom\_error(warning, \textcolor{stringliteral}{"MEKE\_init called with NO associated "}// &
01021                             \textcolor{stringliteral}{"MEKE-type structure."})
01022     \textcolor{keywordflow}{return}
01023 \textcolor{keywordflow}{  endif}
01024   \textcolor{keywordflow}{if} (\textcolor{keyword}{associated}(cs)) \textcolor{keywordflow}{then}
01025     \textcolor{keyword}{call }mom\_error(warning, &
01026       \textcolor{stringliteral}{"MEKE\_init called with an associated control structure."})
01027     \textcolor{keywordflow}{return}
01028   \textcolor{keywordflow}{else} ; \textcolor{keyword}{allocate}(cs) ;\textcolor{keywordflow}{ endif}
01029 
01030   \textcolor{keyword}{call }mom\_mesg(\textcolor{stringliteral}{"MEKE\_init: reading parameters "}, 5)
01031 
01032   \textcolor{comment}{! Read all relevant parameters and write them to the model log.}
01033   \textcolor{keyword}{call }get\_param(param\_file, mdl, \textcolor{stringliteral}{"MEKE\_DAMPING"}, cs%MEKE\_damping, &
01034                  \textcolor{stringliteral}{"The local depth-independent MEKE dissipation rate."}, &
01035                  units=\textcolor{stringliteral}{"s-1"}, default=0.0, scale=us%T\_to\_s)
01036   \textcolor{keyword}{call }get\_param(param\_file, mdl, \textcolor{stringliteral}{"MEKE\_CD\_SCALE"}, cs%MEKE\_Cd\_scale, &
01037                  \textcolor{stringliteral}{"The ratio of the bottom eddy velocity to the column mean "}//&
01038                  \textcolor{stringliteral}{"eddy velocity, i.e. sqrt(2*MEKE). This should be less than 1 "}//&
01039                  \textcolor{stringliteral}{"to account for the surface intensification of MEKE."}, &
01040                  units=\textcolor{stringliteral}{"nondim"}, default=0.)
01041   \textcolor{keyword}{call }get\_param(param\_file, mdl, \textcolor{stringliteral}{"MEKE\_CB"}, cs%MEKE\_Cb, &
01042                  \textcolor{stringliteral}{"A coefficient in the expression for the ratio of bottom projected "}//&
01043                  \textcolor{stringliteral}{"eddy energy and mean column energy (see Jansen et al. 2015)."},&
01044                  units=\textcolor{stringliteral}{"nondim"}, default=25.)
01045   \textcolor{keyword}{call }get\_param(param\_file, mdl, \textcolor{stringliteral}{"MEKE\_MIN\_GAMMA2"}, cs%MEKE\_min\_gamma, &
01046                  \textcolor{stringliteral}{"The minimum allowed value of gamma\_b^2."},&
01047                  units=\textcolor{stringliteral}{"nondim"}, default=0.0001)
01048   \textcolor{keyword}{call }get\_param(param\_file, mdl, \textcolor{stringliteral}{"MEKE\_CT"}, cs%MEKE\_Ct, &
01049                  \textcolor{stringliteral}{"A coefficient in the expression for the ratio of barotropic "}//&
01050                  \textcolor{stringliteral}{"eddy energy and mean column energy (see Jansen et al. 2015)."},&
01051                  units=\textcolor{stringliteral}{"nondim"}, default=50.)
01052   \textcolor{keyword}{call }get\_param(param\_file, mdl, \textcolor{stringliteral}{"MEKE\_GMCOEFF"}, cs%MEKE\_GMcoeff, &
01053                  \textcolor{stringliteral}{"The efficiency of the conversion of potential energy "}//&
01054                  \textcolor{stringliteral}{"into MEKE by the thickness mixing parameterization. "}//&
01055                  \textcolor{stringliteral}{"If MEKE\_GMCOEFF is negative, this conversion is not "}//&
01056                  \textcolor{stringliteral}{"used or calculated."}, units=\textcolor{stringliteral}{"nondim"}, default=-1.0)
01057   \textcolor{keyword}{call }get\_param(param\_file, mdl, \textcolor{stringliteral}{"MEKE\_GEOMETRIC"}, cs%MEKE\_GEOMETRIC, &
01058                  \textcolor{stringliteral}{"If MEKE\_GEOMETRIC is true, uses the GM coefficient formulation "}//&
01059                  \textcolor{stringliteral}{"from the GEOMETRIC framework (Marshall et al., 2012)."}, default=.false.)
01060   \textcolor{keyword}{call }get\_param(param\_file, mdl, \textcolor{stringliteral}{"MEKE\_GEOMETRIC\_ALPHA"}, cs%MEKE\_GEOMETRIC\_alpha, &
01061                  \textcolor{stringliteral}{"The nondimensional coefficient governing the efficiency of the GEOMETRIC \(\backslash\)n"}//&
01062                  \textcolor{stringliteral}{"thickness diffusion."}, units=\textcolor{stringliteral}{"nondim"}, default=0.05)
01063   \textcolor{keyword}{call }get\_param(param\_file, mdl, \textcolor{stringliteral}{"MEKE\_EQUILIBRIUM\_ALT"}, cs%MEKE\_equilibrium\_alt, &
01064                  \textcolor{stringliteral}{"If true, use an alternative formula for computing the (equilibrium)"}//&
01065                  \textcolor{stringliteral}{"initial value of MEKE."}, default=.false.)
01066   \textcolor{keyword}{call }get\_param(param\_file, mdl, \textcolor{stringliteral}{"MEKE\_EQUILIBRIUM\_RESTORING"}, cs%MEKE\_equilibrium\_restoring, &
01067                  \textcolor{stringliteral}{"If true, restore MEKE back to its equilibrium value, which is calculated at "}//&
01068                  \textcolor{stringliteral}{"each time step."}, default=.false.)
01069   \textcolor{keywordflow}{if} (cs%MEKE\_equilibrium\_restoring) \textcolor{keywordflow}{then}
01070     \textcolor{keyword}{call }get\_param(param\_file, mdl, \textcolor{stringliteral}{"MEKE\_RESTORING\_TIMESCALE"}, meke\_restoring\_timescale, &
01071                    \textcolor{stringliteral}{"The timescale used to nudge MEKE toward its equilibrium value."}, units=\textcolor{stringliteral}{"s"}, &
01072                    default=1e6, scale=us%T\_to\_s)
01073     cs%MEKE\_restoring\_rate = 1.0 / meke\_restoring\_timescale
01074 \textcolor{keywordflow}{  endif}
01075 
01076   \textcolor{keyword}{call }get\_param(param\_file, mdl, \textcolor{stringliteral}{"MEKE\_FRCOEFF"}, cs%MEKE\_FrCoeff, &
01077                  \textcolor{stringliteral}{"The efficiency of the conversion of mean energy into "}//&
01078                  \textcolor{stringliteral}{"MEKE.  If MEKE\_FRCOEFF is negative, this conversion "}//&
01079                  \textcolor{stringliteral}{"is not used or calculated."}, units=\textcolor{stringliteral}{"nondim"}, default=-1.0)
01080   \textcolor{keyword}{call }get\_param(param\_file, mdl, \textcolor{stringliteral}{"MEKE\_GMECOEFF"}, cs%MEKE\_GMECoeff, &
01081                  \textcolor{stringliteral}{"The efficiency of the conversion of MEKE into mean energy "}//&
01082                  \textcolor{stringliteral}{"by GME.  If MEKE\_GMECOEFF is negative, this conversion "}//&
01083                  \textcolor{stringliteral}{"is not used or calculated."}, units=\textcolor{stringliteral}{"nondim"}, default=-1.0)
01084   \textcolor{keyword}{call }get\_param(param\_file, mdl, \textcolor{stringliteral}{"MEKE\_BGSRC"}, cs%MEKE\_BGsrc, &
01085                  \textcolor{stringliteral}{"A background energy source for MEKE."}, units=\textcolor{stringliteral}{"W kg-1"}, &
01086                  default=0.0, scale=us%m\_to\_L**2*us%T\_to\_s**3)
01087   \textcolor{keyword}{call }get\_param(param\_file, mdl, \textcolor{stringliteral}{"MEKE\_KH"}, cs%MEKE\_Kh, &
01088                  \textcolor{stringliteral}{"A background lateral diffusivity of MEKE. "}//&
01089                  \textcolor{stringliteral}{"Use a negative value to not apply lateral diffusion to MEKE."}, &
01090                  units=\textcolor{stringliteral}{"m2 s-1"}, default=-1.0, scale=us%m\_to\_L**2*us%T\_to\_s)
01091   \textcolor{keyword}{call }get\_param(param\_file, mdl, \textcolor{stringliteral}{"MEKE\_K4"}, cs%MEKE\_K4, &
01092                  \textcolor{stringliteral}{"A lateral bi-harmonic diffusivity of MEKE. "}//&
01093                  \textcolor{stringliteral}{"Use a negative value to not apply bi-harmonic diffusion to MEKE."}, &
01094                  units=\textcolor{stringliteral}{"m4 s-1"}, default=-1.0, scale=us%m\_to\_L**4*us%T\_to\_s)
01095   \textcolor{keyword}{call }get\_param(param\_file, mdl, \textcolor{stringliteral}{"MEKE\_DTSCALE"}, cs%MEKE\_dtScale, &
01096                  \textcolor{stringliteral}{"A scaling factor to accelerate the time evolution of MEKE."}, &
01097                  units=\textcolor{stringliteral}{"nondim"}, default=1.0)
01098   \textcolor{keyword}{call }get\_param(param\_file, mdl, \textcolor{stringliteral}{"MEKE\_KHCOEFF"}, cs%MEKE\_KhCoeff, &
01099                  \textcolor{stringliteral}{"A scaling factor in the expression for eddy diffusivity "}//&
01100                  \textcolor{stringliteral}{"which is otherwise proportional to the MEKE velocity- "}//&
01101                  \textcolor{stringliteral}{"scale times an eddy mixing-length. This factor "}//&
01102                  \textcolor{stringliteral}{"must be >0 for MEKE to contribute to the thickness/ "}//&
01103                  \textcolor{stringliteral}{"and tracer diffusivity in the rest of the model."}, &
01104                  units=\textcolor{stringliteral}{"nondim"}, default=1.0)
01105   \textcolor{keyword}{call }get\_param(param\_file, mdl, \textcolor{stringliteral}{"MEKE\_USCALE"}, cs%MEKE\_Uscale, &
01106                  \textcolor{stringliteral}{"The background velocity that is combined with MEKE to "}//&
01107                  \textcolor{stringliteral}{"calculate the bottom drag."}, units=\textcolor{stringliteral}{"m s-1"}, default=0.0, scale=us%m\_s\_to\_L\_T)
01108   \textcolor{keyword}{call }get\_param(param\_file, mdl, \textcolor{stringliteral}{"MEKE\_GM\_SRC\_ALT"}, cs%GM\_src\_alt, &
01109                  \textcolor{stringliteral}{"If true, use the GM energy conversion form S^2*N^2*kappa rather "}//&
01110                  \textcolor{stringliteral}{"than the streamfunction for the MEKE GM source term."}, default=.false.)
01111   \textcolor{keyword}{call }get\_param(param\_file, mdl, \textcolor{stringliteral}{"MEKE\_VISC\_DRAG"}, cs%visc\_drag, &
01112                  \textcolor{stringliteral}{"If true, use the vertvisc\_type to calculate the bottom "}//&
01113                  \textcolor{stringliteral}{"drag acting on MEKE."}, default=.true.)
01114   \textcolor{keyword}{call }get\_param(param\_file, mdl, \textcolor{stringliteral}{"MEKE\_KHTH\_FAC"}, meke%KhTh\_fac, &
01115                  \textcolor{stringliteral}{"A factor that maps MEKE%Kh to KhTh."}, units=\textcolor{stringliteral}{"nondim"}, &
01116                  default=0.0)
01117   \textcolor{keyword}{call }get\_param(param\_file, mdl, \textcolor{stringliteral}{"MEKE\_KHTR\_FAC"}, meke%KhTr\_fac, &
01118                  \textcolor{stringliteral}{"A factor that maps MEKE%Kh to KhTr."}, units=\textcolor{stringliteral}{"nondim"}, &
01119                  default=0.0)
01120   \textcolor{keyword}{call }get\_param(param\_file, mdl, \textcolor{stringliteral}{"MEKE\_KHMEKE\_FAC"}, cs%KhMEKE\_Fac, &
01121                  \textcolor{stringliteral}{"A factor that maps MEKE%Kh to Kh for MEKE itself."}, &
01122                  units=\textcolor{stringliteral}{"nondim"}, default=0.0)
01123   \textcolor{keyword}{call }get\_param(param\_file, mdl, \textcolor{stringliteral}{"MEKE\_OLD\_LSCALE"}, cs%use\_old\_lscale, &
01124                  \textcolor{stringliteral}{"If true, use the old formula for length scale which is "}//&
01125                  \textcolor{stringliteral}{"a function of grid spacing and deformation radius."},  &
01126                  default=.false.)
01127   \textcolor{keyword}{call }get\_param(param\_file, mdl, \textcolor{stringliteral}{"MEKE\_MIN\_LSCALE"}, cs%use\_min\_lscale, &
01128                  \textcolor{stringliteral}{"If true, use a strict minimum of provided length scales "}//&
01129                  \textcolor{stringliteral}{"rather than harmonic mean."},  &
01130                  default=.false.)
01131   \textcolor{keyword}{call }get\_param(param\_file, mdl, \textcolor{stringliteral}{"MEKE\_RD\_MAX\_SCALE"}, cs%Rd\_as\_max\_scale, &
01132                  \textcolor{stringliteral}{"If true, the length scale used by MEKE is the minimum of "}//&
01133                  \textcolor{stringliteral}{"the deformation radius or grid-spacing. Only used if "}//&
01134                  \textcolor{stringliteral}{"MEKE\_OLD\_LSCALE=True"}, units=\textcolor{stringliteral}{"nondim"}, default=.false.)
01135   \textcolor{keyword}{call }get\_param(param\_file, mdl, \textcolor{stringliteral}{"MEKE\_VISCOSITY\_COEFF\_KU"}, cs%viscosity\_coeff\_Ku, &
01136                  \textcolor{stringliteral}{"If non-zero, is the scaling coefficient in the expression for"}//&
01137                  \textcolor{stringliteral}{"viscosity used to parameterize harmonic lateral momentum mixing by"}//&
01138                  \textcolor{stringliteral}{"unresolved eddies represented by MEKE. Can be negative to"}//&
01139                  \textcolor{stringliteral}{"represent backscatter from the unresolved eddies."}, &
01140                  units=\textcolor{stringliteral}{"nondim"}, default=0.0)
01141   \textcolor{keyword}{call }get\_param(param\_file, mdl, \textcolor{stringliteral}{"MEKE\_VISCOSITY\_COEFF\_AU"}, cs%viscosity\_coeff\_Au, &
01142                  \textcolor{stringliteral}{"If non-zero, is the scaling coefficient in the expression for"}//&
01143                  \textcolor{stringliteral}{"viscosity used to parameterize biharmonic lateral momentum mixing by"}//&
01144                  \textcolor{stringliteral}{"unresolved eddies represented by MEKE. Can be negative to"}//&
01145                  \textcolor{stringliteral}{"represent backscatter from the unresolved eddies."}, &
01146                  units=\textcolor{stringliteral}{"nondim"}, default=0.0)
01147   \textcolor{keyword}{call }get\_param(param\_file, mdl, \textcolor{stringliteral}{"MEKE\_FIXED\_MIXING\_LENGTH"}, cs%Lfixed, &
01148                  \textcolor{stringliteral}{"If positive, is a fixed length contribution to the expression "}//&
01149                  \textcolor{stringliteral}{"for mixing length used in MEKE-derived diffusivity."}, &
01150                  units=\textcolor{stringliteral}{"m"}, default=0.0, scale=us%m\_to\_L)
01151   \textcolor{keyword}{call }get\_param(param\_file, mdl, \textcolor{stringliteral}{"MEKE\_ALPHA\_DEFORM"}, cs%aDeform, &
01152                  \textcolor{stringliteral}{"If positive, is a coefficient weighting the deformation scale "}//&
01153                  \textcolor{stringliteral}{"in the expression for mixing length used in MEKE-derived diffusivity."}, &
01154                  units=\textcolor{stringliteral}{"nondim"}, default=0.0)
01155   \textcolor{keyword}{call }get\_param(param\_file, mdl, \textcolor{stringliteral}{"MEKE\_ALPHA\_RHINES"}, cs%aRhines, &
01156                  \textcolor{stringliteral}{"If positive, is a coefficient weighting the Rhines scale "}//&
01157                  \textcolor{stringliteral}{"in the expression for mixing length used in MEKE-derived diffusivity."}, &
01158                  units=\textcolor{stringliteral}{"nondim"}, default=0.0)
01159   \textcolor{keyword}{call }get\_param(param\_file, mdl, \textcolor{stringliteral}{"MEKE\_ALPHA\_EADY"}, cs%aEady, &
01160                  \textcolor{stringliteral}{"If positive, is a coefficient weighting the Eady length scale "}//&
01161                  \textcolor{stringliteral}{"in the expression for mixing length used in MEKE-derived diffusivity."}, &
01162                  units=\textcolor{stringliteral}{"nondim"}, default=0.0)
01163   \textcolor{keyword}{call }get\_param(param\_file, mdl, \textcolor{stringliteral}{"MEKE\_ALPHA\_FRICT"}, cs%aFrict, &
01164                  \textcolor{stringliteral}{"If positive, is a coefficient weighting the frictional arrest scale "}//&
01165                  \textcolor{stringliteral}{"in the expression for mixing length used in MEKE-derived diffusivity."}, &
01166                  units=\textcolor{stringliteral}{"nondim"}, default=0.0)
01167   \textcolor{keyword}{call }get\_param(param\_file, mdl, \textcolor{stringliteral}{"MEKE\_ALPHA\_GRID"}, cs%aGrid, &
01168                  \textcolor{stringliteral}{"If positive, is a coefficient weighting the grid-spacing as a scale "}//&
01169                  \textcolor{stringliteral}{"in the expression for mixing length used in MEKE-derived diffusivity."}, &
01170                  units=\textcolor{stringliteral}{"nondim"}, default=0.0)
01171   \textcolor{keyword}{call }get\_param(param\_file, mdl, \textcolor{stringliteral}{"MEKE\_COLD\_START"}, coldstart, &
01172                  \textcolor{stringliteral}{"If true, initialize EKE to zero. Otherwise a local equilibrium solution "}//&
01173                  \textcolor{stringliteral}{"is used as an initial condition for EKE."}, default=.false.)
01174   \textcolor{keyword}{call }get\_param(param\_file, mdl, \textcolor{stringliteral}{"MEKE\_BACKSCAT\_RO\_C"}, meke%backscatter\_Ro\_c, &
01175                  \textcolor{stringliteral}{"The coefficient in the Rossby number function for scaling the biharmonic "}//&
01176                  \textcolor{stringliteral}{"frictional energy source. Setting to non-zero enables the Rossby number function."}, &
01177                  units=\textcolor{stringliteral}{"nondim"}, default=0.0)
01178   \textcolor{keyword}{call }get\_param(param\_file, mdl, \textcolor{stringliteral}{"MEKE\_BACKSCAT\_RO\_POW"}, meke%backscatter\_Ro\_pow, &
01179                  \textcolor{stringliteral}{"The power in the Rossby number function for scaling the biharmonic "}//&
01180                  \textcolor{stringliteral}{"frictional energy source."}, units=\textcolor{stringliteral}{"nondim"}, default=0.0)
01181   \textcolor{keyword}{call }get\_param(param\_file, mdl, \textcolor{stringliteral}{"MEKE\_ADVECTION\_FACTOR"}, cs%MEKE\_advection\_factor, &
01182                  \textcolor{stringliteral}{"A scale factor in front of advection of eddy energy. Zero turns advection off. "}//&
01183                  \textcolor{stringliteral}{"Using unity would be normal but other values could accommodate a mismatch "}//&
01184                  \textcolor{stringliteral}{"between the advecting barotropic flow and the vertical structure of MEKE."}, &
01185                  units=\textcolor{stringliteral}{"nondim"}, default=0.0)
01186   \textcolor{keyword}{call }get\_param(param\_file, mdl, \textcolor{stringliteral}{"MEKE\_TOPOGRAPHIC\_BETA"}, cs%MEKE\_topographic\_beta, &
01187                  \textcolor{stringliteral}{"A scale factor to determine how much topographic beta is weighed in "} //&
01188                  \textcolor{stringliteral}{"computing beta in the expression of Rhines scale. Use 1 if full "}//&
01189                  \textcolor{stringliteral}{"topographic beta effect is considered; use 0 if it's completely ignored."}, &
01190                  units=\textcolor{stringliteral}{"nondim"}, default=0.0)
01191 
01192   \textcolor{comment}{! Nonlocal module parameters}
01193   \textcolor{keyword}{call }get\_param(param\_file, mdl, \textcolor{stringliteral}{"CDRAG"}, cdrag, &
01194                  \textcolor{stringliteral}{"CDRAG is the drag coefficient relating the magnitude of "}//&
01195                  \textcolor{stringliteral}{"the velocity field to the bottom stress."}, units=\textcolor{stringliteral}{"nondim"}, &
01196                  default=0.003)
01197   \textcolor{keyword}{call }get\_param(param\_file, mdl, \textcolor{stringliteral}{"MEKE\_CDRAG"}, cs%cdrag, &
01198                  \textcolor{stringliteral}{"Drag coefficient relating the magnitude of the velocity "}//&
01199                  \textcolor{stringliteral}{"field to the bottom stress in MEKE."}, units=\textcolor{stringliteral}{"nondim"}, &
01200                  default=cdrag)
01201   \textcolor{keyword}{call }get\_param(param\_file, mdl, \textcolor{stringliteral}{"LAPLACIAN"}, laplacian, default=.false., do\_not\_log=.true.)
01202   \textcolor{keyword}{call }get\_param(param\_file, mdl, \textcolor{stringliteral}{"BIHARMONIC"}, biharmonic, default=.false., do\_not\_log=.true.)
01203 
01204   \textcolor{keywordflow}{if} (cs%viscosity\_coeff\_Ku/=0. .and. .not. laplacian) \textcolor{keyword}{call }mom\_error(fatal, &
01205                  \textcolor{stringliteral}{"LAPLACIAN must be true if MEKE\_VISCOSITY\_COEFF\_KU is true."})
01206 
01207   \textcolor{keywordflow}{if} (cs%viscosity\_coeff\_Au/=0. .and. .not. biharmonic) \textcolor{keyword}{call }mom\_error(fatal, &
01208                  \textcolor{stringliteral}{"BIHARMONIC must be true if MEKE\_VISCOSITY\_COEFF\_AU is true."})
01209 
01210   \textcolor{keyword}{call }get\_param(param\_file, mdl, \textcolor{stringliteral}{"DEBUG"}, cs%debug, default=.false., do\_not\_log=.true.)
01211 
01212   \textcolor{comment}{! Identify if any lateral diffusive processes are active}
01213   cs%kh\_flux\_enabled = .false.
01214   \textcolor{keywordflow}{if} ((cs%MEKE\_KH >= 0.0)  .or. (cs%KhMEKE\_FAC > 0.0) .or. (cs%MEKE\_advection\_factor > 0.0)) &
01215     cs%kh\_flux\_enabled = .true.
01216 
01217 \textcolor{comment}{! Register fields for output from this module.}
01218   cs%diag => diag
01219   cs%id\_MEKE = register\_diag\_field(\textcolor{stringliteral}{'ocean\_model'}, \textcolor{stringliteral}{'MEKE'}, diag%axesT1, time, &
01220      \textcolor{stringliteral}{'Mesoscale Eddy Kinetic Energy'}, \textcolor{stringliteral}{'m2 s-2'}, conversion=us%L\_T\_to\_m\_s**2)
01221   \textcolor{keywordflow}{if} (.not. \textcolor{keyword}{associated}(meke%MEKE)) cs%id\_MEKE = -1
01222   cs%id\_Kh = register\_diag\_field(\textcolor{stringliteral}{'ocean\_model'}, \textcolor{stringliteral}{'MEKE\_KH'}, diag%axesT1, time, &
01223      \textcolor{stringliteral}{'MEKE derived diffusivity'}, \textcolor{stringliteral}{'m2 s-1'}, conversion=us%L\_to\_m**2*us%s\_to\_T)
01224   \textcolor{keywordflow}{if} (.not. \textcolor{keyword}{associated}(meke%Kh)) cs%id\_Kh = -1
01225   cs%id\_Ku = register\_diag\_field(\textcolor{stringliteral}{'ocean\_model'}, \textcolor{stringliteral}{'MEKE\_KU'}, diag%axesT1, time, &
01226      \textcolor{stringliteral}{'MEKE derived lateral viscosity'}, \textcolor{stringliteral}{'m2 s-1'}, conversion=us%L\_to\_m**2*us%s\_to\_T)
01227   \textcolor{keywordflow}{if} (.not. \textcolor{keyword}{associated}(meke%Ku)) cs%id\_Ku = -1
01228   cs%id\_Au = register\_diag\_field(\textcolor{stringliteral}{'ocean\_model'}, \textcolor{stringliteral}{'MEKE\_AU'}, diag%axesT1, time, &
01229      \textcolor{stringliteral}{'MEKE derived lateral biharmonic viscosity'}, \textcolor{stringliteral}{'m4 s-1'}, conversion=us%L\_to\_m**4*us%s\_to\_T)
01230   \textcolor{keywordflow}{if} (.not. \textcolor{keyword}{associated}(meke%Au)) cs%id\_Au = -1
01231   cs%id\_Ue = register\_diag\_field(\textcolor{stringliteral}{'ocean\_model'}, \textcolor{stringliteral}{'MEKE\_Ue'}, diag%axesT1, time, &
01232      \textcolor{stringliteral}{'MEKE derived eddy-velocity scale'}, \textcolor{stringliteral}{'m s-1'}, conversion=us%L\_T\_to\_m\_s)
01233   \textcolor{keywordflow}{if} (.not. \textcolor{keyword}{associated}(meke%MEKE)) cs%id\_Ue = -1
01234   cs%id\_Ub = register\_diag\_field(\textcolor{stringliteral}{'ocean\_model'}, \textcolor{stringliteral}{'MEKE\_Ub'}, diag%axesT1, time, &
01235      \textcolor{stringliteral}{'MEKE derived bottom eddy-velocity scale'}, \textcolor{stringliteral}{'m s-1'}, conversion=us%L\_T\_to\_m\_s)
01236   \textcolor{keywordflow}{if} (.not. \textcolor{keyword}{associated}(meke%MEKE)) cs%id\_Ub = -1
01237   cs%id\_Ut = register\_diag\_field(\textcolor{stringliteral}{'ocean\_model'}, \textcolor{stringliteral}{'MEKE\_Ut'}, diag%axesT1, time, &
01238      \textcolor{stringliteral}{'MEKE derived barotropic eddy-velocity scale'}, \textcolor{stringliteral}{'m s-1'}, conversion=us%L\_T\_to\_m\_s)
01239   \textcolor{keywordflow}{if} (.not. \textcolor{keyword}{associated}(meke%MEKE)) cs%id\_Ut = -1
01240   cs%id\_src = register\_diag\_field(\textcolor{stringliteral}{'ocean\_model'}, \textcolor{stringliteral}{'MEKE\_src'}, diag%axesT1, time, &
01241      \textcolor{stringliteral}{'MEKE energy source'}, \textcolor{stringliteral}{'m2 s-3'}, conversion=(us%L\_T\_to\_m\_s**2)*us%s\_to\_T)
01242   cs%id\_decay = register\_diag\_field(\textcolor{stringliteral}{'ocean\_model'}, \textcolor{stringliteral}{'MEKE\_decay'}, diag%axesT1, time, &
01243      \textcolor{stringliteral}{'MEKE decay rate'}, \textcolor{stringliteral}{'s-1'}, conversion=us%s\_to\_T)
01244   cs%id\_GM\_src = register\_diag\_field(\textcolor{stringliteral}{'ocean\_model'}, \textcolor{stringliteral}{'MEKE\_GM\_src'}, diag%axesT1, time, &
01245      \textcolor{stringliteral}{'MEKE energy available from thickness mixing'}, &
01246      \textcolor{stringliteral}{'W m-2'}, conversion=us%RZ3\_T3\_to\_W\_m2*us%L\_to\_Z**2)
01247   \textcolor{keywordflow}{if} (.not. \textcolor{keyword}{associated}(meke%GM\_src)) cs%id\_GM\_src = -1
01248   cs%id\_mom\_src = register\_diag\_field(\textcolor{stringliteral}{'ocean\_model'}, \textcolor{stringliteral}{'MEKE\_mom\_src'},diag%axesT1, time, &
01249      \textcolor{stringliteral}{'MEKE energy available from momentum'}, &
01250      \textcolor{stringliteral}{'W m-2'}, conversion=us%RZ3\_T3\_to\_W\_m2*us%L\_to\_Z**2)
01251   \textcolor{keywordflow}{if} (.not. \textcolor{keyword}{associated}(meke%mom\_src)) cs%id\_mom\_src = -1
01252   cs%id\_GME\_snk = register\_diag\_field(\textcolor{stringliteral}{'ocean\_model'}, \textcolor{stringliteral}{'MEKE\_GME\_snk'},diag%axesT1, time, &
01253      \textcolor{stringliteral}{'MEKE energy lost to GME backscatter'}, &
01254      \textcolor{stringliteral}{'W m-2'}, conversion=us%RZ3\_T3\_to\_W\_m2*us%L\_to\_Z**2)
01255   \textcolor{keywordflow}{if} (.not. \textcolor{keyword}{associated}(meke%GME\_snk)) cs%id\_GME\_snk = -1
01256   cs%id\_Le = register\_diag\_field(\textcolor{stringliteral}{'ocean\_model'}, \textcolor{stringliteral}{'MEKE\_Le'}, diag%axesT1, time, &
01257      \textcolor{stringliteral}{'Eddy mixing length used in the MEKE derived eddy diffusivity'}, \textcolor{stringliteral}{'m'}, conversion=us%L\_to\_m)
01258   cs%id\_Lrhines = register\_diag\_field(\textcolor{stringliteral}{'ocean\_model'}, \textcolor{stringliteral}{'MEKE\_Lrhines'}, diag%axesT1, time, &
01259      \textcolor{stringliteral}{'Rhines length scale used in the MEKE derived eddy diffusivity'}, \textcolor{stringliteral}{'m'}, conversion=us%L\_to\_m)
01260   cs%id\_Leady = register\_diag\_field(\textcolor{stringliteral}{'ocean\_model'}, \textcolor{stringliteral}{'MEKE\_Leady'}, diag%axesT1, time, &
01261      \textcolor{stringliteral}{'Eady length scale used in the MEKE derived eddy diffusivity'}, \textcolor{stringliteral}{'m'}, conversion=us%L\_to\_m)
01262   cs%id\_gamma\_b = register\_diag\_field(\textcolor{stringliteral}{'ocean\_model'}, \textcolor{stringliteral}{'MEKE\_gamma\_b'}, diag%axesT1, time, &
01263      \textcolor{stringliteral}{'Ratio of bottom-projected eddy velocity to column-mean eddy velocity'}, \textcolor{stringliteral}{'nondim'})
01264   cs%id\_gamma\_t = register\_diag\_field(\textcolor{stringliteral}{'ocean\_model'}, \textcolor{stringliteral}{'MEKE\_gamma\_t'}, diag%axesT1, time, &
01265      \textcolor{stringliteral}{'Ratio of barotropic eddy velocity to column-mean eddy velocity'}, \textcolor{stringliteral}{'nondim'})
01266 
01267   \textcolor{keywordflow}{if} (cs%kh\_flux\_enabled) \textcolor{keywordflow}{then}
01268     cs%id\_KhMEKE\_u = register\_diag\_field(\textcolor{stringliteral}{'ocean\_model'}, \textcolor{stringliteral}{'KHMEKE\_u'}, diag%axesCu1, time, &
01269      \textcolor{stringliteral}{'Zonal diffusivity of MEKE'}, \textcolor{stringliteral}{'m2 s-1'}, conversion=us%L\_to\_m**2*us%s\_to\_T)
01270     cs%id\_KhMEKE\_v = register\_diag\_field(\textcolor{stringliteral}{'ocean\_model'}, \textcolor{stringliteral}{'KHMEKE\_v'}, diag%axesCv1, time, &
01271      \textcolor{stringliteral}{'Meridional diffusivity of MEKE'}, \textcolor{stringliteral}{'m2 s-1'}, conversion=us%L\_to\_m**2*us%s\_to\_T)
01272 \textcolor{keywordflow}{  endif}
01273 
01274   \textcolor{keywordflow}{if} (cs%MEKE\_equilibrium\_restoring) \textcolor{keywordflow}{then}
01275     cs%id\_MEKE\_equilibrium = register\_diag\_field(\textcolor{stringliteral}{'ocean\_model'}, \textcolor{stringliteral}{'MEKE\_equilibrium'}, diag%axesT1, time, &
01276      \textcolor{stringliteral}{'Equilibrated Mesoscale Eddy Kinetic Energy'}, \textcolor{stringliteral}{'m2 s-2'}, conversion=us%L\_T\_to\_m\_s**2)
01277 \textcolor{keywordflow}{  endif}
01278 
01279   cs%id\_clock\_pass = cpu\_clock\_id(\textcolor{stringliteral}{'(Ocean continuity halo updates)'}, grain=clock\_routine)
01280 
01281   \textcolor{comment}{! Detect whether this instance of MEKE\_init() is at the beginning of a run}
01282   \textcolor{comment}{! or after a restart. If at the beginning, we will initialize MEKE to a local}
01283   \textcolor{comment}{! equilibrium.}
01284   cs%initialize = .not.query\_initialized(meke%MEKE, \textcolor{stringliteral}{"MEKE"}, restart\_cs)
01285   \textcolor{keywordflow}{if} (coldstart) cs%initialize = .false.
01286   \textcolor{keywordflow}{if} (cs%initialize) \textcolor{keyword}{call }mom\_error(warning, &
01287                        \textcolor{stringliteral}{"MEKE\_init: Initializing MEKE with a local equilibrium balance."})
01288 
01289   \textcolor{comment}{! Account for possible changes in dimensional scaling for variables that have been}
01290   \textcolor{comment}{! read from a restart file.}
01291   i\_t\_rescale = 1.0
01292   \textcolor{keywordflow}{if} ((us%s\_to\_T\_restart /= 0.0) .and. (us%s\_to\_T\_restart /= us%s\_to\_T)) &
01293     i\_t\_rescale = us%s\_to\_T\_restart / us%s\_to\_T
01294   l\_rescale = 1.0
01295   \textcolor{keywordflow}{if} ((us%m\_to\_L\_restart /= 0.0) .and. (us%m\_to\_L\_restart /= us%m\_to\_L)) &
01296     l\_rescale = us%m\_to\_L / us%m\_to\_L\_restart
01297 
01298   \textcolor{keywordflow}{if} (l\_rescale*i\_t\_rescale /= 1.0) \textcolor{keywordflow}{then}
01299     \textcolor{keywordflow}{if} (\textcolor{keyword}{associated}(meke%MEKE)) \textcolor{keywordflow}{then} ; \textcolor{keywordflow}{if} (query\_initialized(meke%MEKE, \textcolor{stringliteral}{"MEKE\_MEKE"}, restart\_cs)) \textcolor{keywordflow}{then}
01300       \textcolor{keywordflow}{do} j=js,je ; \textcolor{keywordflow}{do} i=is,ie
01301         meke%MEKE(i,j) = l\_rescale*i\_t\_rescale * meke%MEKE(i,j)
01302 \textcolor{keywordflow}{      enddo} ;\textcolor{keywordflow}{ enddo}
01303 \textcolor{keywordflow}{    endif} ;\textcolor{keywordflow}{ endif}
01304 \textcolor{keywordflow}{  endif}
01305   \textcolor{keywordflow}{if} (l\_rescale**2*i\_t\_rescale /= 1.0) \textcolor{keywordflow}{then}
01306     \textcolor{keywordflow}{if} (\textcolor{keyword}{associated}(meke%Kh)) \textcolor{keywordflow}{then} ; \textcolor{keywordflow}{if} (query\_initialized(meke%Kh, \textcolor{stringliteral}{"MEKE\_Kh"}, restart\_cs)) \textcolor{keywordflow}{then}
01307       \textcolor{keywordflow}{do} j=js,je ; \textcolor{keywordflow}{do} i=is,ie
01308         meke%Kh(i,j) = l\_rescale**2*i\_t\_rescale * meke%Kh(i,j)
01309 \textcolor{keywordflow}{      enddo} ;\textcolor{keywordflow}{ enddo}
01310 \textcolor{keywordflow}{    endif} ;\textcolor{keywordflow}{ endif}
01311     \textcolor{keywordflow}{if} (\textcolor{keyword}{associated}(meke%Ku)) \textcolor{keywordflow}{then} ; \textcolor{keywordflow}{if} (query\_initialized(meke%Ku, \textcolor{stringliteral}{"MEKE\_Ku"}, restart\_cs)) \textcolor{keywordflow}{then}
01312       \textcolor{keywordflow}{do} j=js,je ; \textcolor{keywordflow}{do} i=is,ie
01313         meke%Ku(i,j) = l\_rescale**2*i\_t\_rescale * meke%Ku(i,j)
01314 \textcolor{keywordflow}{      enddo} ;\textcolor{keywordflow}{ enddo}
01315 \textcolor{keywordflow}{    endif} ;\textcolor{keywordflow}{ endif}
01316     \textcolor{keywordflow}{if} (\textcolor{keyword}{associated}(meke%Kh\_diff)) \textcolor{keywordflow}{then} ; \textcolor{keywordflow}{if} (query\_initialized(meke%Kh, \textcolor{stringliteral}{"MEKE\_Kh\_diff"}, restart\_cs)) \textcolor{keywordflow}{then}
01317       \textcolor{keywordflow}{do} j=js,je ; \textcolor{keywordflow}{do} i=is,ie
01318         meke%Kh\_diff(i,j) = l\_rescale**2*i\_t\_rescale * meke%Kh\_diff(i,j)
01319 \textcolor{keywordflow}{      enddo} ;\textcolor{keywordflow}{ enddo}
01320 \textcolor{keywordflow}{    endif} ;\textcolor{keywordflow}{ endif}
01321 \textcolor{keywordflow}{  endif}
01322   \textcolor{keywordflow}{if} (l\_rescale**4*i\_t\_rescale /= 1.0) \textcolor{keywordflow}{then}
01323     \textcolor{keywordflow}{if} (\textcolor{keyword}{associated}(meke%Au)) \textcolor{keywordflow}{then} ; \textcolor{keywordflow}{if} (query\_initialized(meke%Au, \textcolor{stringliteral}{"MEKE\_Au"}, restart\_cs)) \textcolor{keywordflow}{then}
01324       \textcolor{keywordflow}{do} j=js,je ; \textcolor{keywordflow}{do} i=is,ie
01325         meke%Au(i,j) = l\_rescale**4*i\_t\_rescale * meke%Au(i,j)
01326 \textcolor{keywordflow}{      enddo} ;\textcolor{keywordflow}{ enddo}
01327 \textcolor{keywordflow}{    endif} ;\textcolor{keywordflow}{ endif}
01328 \textcolor{keywordflow}{  endif}
01329 
01330   \textcolor{comment}{! Set up group passes.  In the case of a restart, these fields need a halo update now.}
01331   \textcolor{keywordflow}{if} (\textcolor{keyword}{associated}(meke%MEKE)) \textcolor{keywordflow}{then}
01332     \textcolor{keyword}{call }create\_group\_pass(cs%pass\_MEKE, meke%MEKE, g%Domain)
01333     \textcolor{keywordflow}{if} (\textcolor{keyword}{associated}(meke%Kh\_diff)) \textcolor{keyword}{call }create\_group\_pass(cs%pass\_MEKE, meke%Kh\_diff, g%Domain)
01334     \textcolor{keywordflow}{if} (.not.cs%initialize) \textcolor{keyword}{call }do\_group\_pass(cs%pass\_MEKE, g%Domain)
01335 \textcolor{keywordflow}{  endif}
01336   \textcolor{keywordflow}{if} (\textcolor{keyword}{associated}(meke%Kh)) \textcolor{keyword}{call }create\_group\_pass(cs%pass\_Kh, meke%Kh, g%Domain)
01337   \textcolor{keywordflow}{if} (\textcolor{keyword}{associated}(meke%Ku)) \textcolor{keyword}{call }create\_group\_pass(cs%pass\_Kh, meke%Ku, g%Domain)
01338   \textcolor{keywordflow}{if} (\textcolor{keyword}{associated}(meke%Au)) \textcolor{keyword}{call }create\_group\_pass(cs%pass\_Kh, meke%Au, g%Domain)
01339 
01340   \textcolor{keywordflow}{if} (\textcolor{keyword}{associated}(meke%Kh) .or. \textcolor{keyword}{associated}(meke%Ku) .or. \textcolor{keyword}{associated}(meke%Au)) &
01341     \textcolor{keyword}{call }do\_group\_pass(cs%pass\_Kh, g%Domain)
01342 
01343 \textcolor{keyword}{end function }\hyperlink{namespacemom__meke_a099f1cfad37430ef1bd60972a92b1be4}{meke\_init}
01344 \textcolor{comment}{}
01345 \textcolor{comment}{!> Allocates memory and register restart fields for the MOM\_MEKE module.}
01346 \textcolor{keyword}{subroutine }\hyperlink{namespacemom__meke_a1900316331157e48f1a6029bac63fbd0}{meke\_alloc\_register\_restart}(HI, param\_file, MEKE, restart\_CS)
\Hypertarget{MOM__MEKE_8F90_source_l01347}\hyperlink{namespacemom__meke_a1900316331157e48f1a6029bac63fbd0}{01347} \textcolor{comment}{! Arguments}
01348   \textcolor{keywordtype}{type}(hor\_index\_type),  \textcolor{keywordtype}{intent(in)}    :: HI\textcolor{comment}{         !< Horizontal index structure}
01349   \textcolor{keywordtype}{type}(param\_file\_type), \textcolor{keywordtype}{intent(in)}    :: param\_file\textcolor{comment}{ !< Parameter file parser structure.}
01350   \textcolor{keywordtype}{type}(meke\_type),       \textcolor{keywordtype}{pointer}       :: MEKE\textcolor{comment}{       !< A structure with MEKE-related fields.}
01351   \textcolor{keywordtype}{type}(mom\_restart\_cs),  \textcolor{keywordtype}{pointer}       :: restart\_CS\textcolor{comment}{ !< Restart control structure for MOM\_MEKE.}
01352 \textcolor{comment}{! Local variables}
01353   \textcolor{keywordtype}{type}(vardesc) :: vd
01354   \textcolor{keywordtype}{real} :: MEKE\_GMcoeff, MEKE\_FrCoeff, MEKE\_GMECoeff, MEKE\_KHCoeff, MEKE\_viscCoeff\_Ku, MEKE\_viscCoeff\_Au
01355   \textcolor{keywordtype}{logical} :: Use\_KH\_in\_MEKE
01356   \textcolor{keywordtype}{logical} :: useMEKE
01357   \textcolor{keywordtype}{integer} :: isd, ied, jsd, jed
01358 
01359 \textcolor{comment}{! Determine whether this module will be used}
01360   usemeke = .false.; \textcolor{keyword}{call }read\_param(param\_file,\textcolor{stringliteral}{"USE\_MEKE"},usemeke)
01361 
01362 \textcolor{comment}{! Read these parameters to determine what should be in the restarts}
01363   meke\_gmcoeff =-1.; \textcolor{keyword}{call }read\_param(param\_file,\textcolor{stringliteral}{"MEKE\_GMCOEFF"},meke\_gmcoeff)
01364   meke\_frcoeff =-1.; \textcolor{keyword}{call }read\_param(param\_file,\textcolor{stringliteral}{"MEKE\_FRCOEFF"},meke\_frcoeff)
01365   meke\_gmecoeff =-1.; \textcolor{keyword}{call }read\_param(param\_file,\textcolor{stringliteral}{"MEKE\_GMECOEFF"},meke\_gmecoeff)
01366   meke\_khcoeff =1.; \textcolor{keyword}{call }read\_param(param\_file,\textcolor{stringliteral}{"MEKE\_KHCOEFF"},meke\_khcoeff)
01367   meke\_visccoeff\_ku =0.; \textcolor{keyword}{call }read\_param(param\_file,\textcolor{stringliteral}{"MEKE\_VISCOSITY\_COEFF\_KU"},meke\_visccoeff\_ku)
01368   meke\_visccoeff\_au =0.; \textcolor{keyword}{call }read\_param(param\_file,\textcolor{stringliteral}{"MEKE\_VISCOSITY\_COEFF\_AU"},meke\_visccoeff\_au)
01369   use\_kh\_in\_meke = .false.; \textcolor{keyword}{call }read\_param(param\_file,\textcolor{stringliteral}{"USE\_KH\_IN\_MEKE"}, use\_kh\_in\_meke)
01370 \textcolor{comment}{! Allocate control structure}
01371   \textcolor{keywordflow}{if} (\textcolor{keyword}{associated}(meke)) \textcolor{keywordflow}{then}
01372     \textcolor{keyword}{call }mom\_error(warning, \textcolor{stringliteral}{"MEKE\_alloc\_register\_restart called with an associated "}// &
01373                              \textcolor{stringliteral}{"MEKE type."})
01374     \textcolor{keywordflow}{return}
01375   else; \textcolor{keyword}{allocate}(meke);\textcolor{keywordflow}{ endif}
01376 
01377   \textcolor{keywordflow}{if} (.not. usemeke) \textcolor{keywordflow}{return}
01378 
01379 \textcolor{comment}{! Allocate memory}
01380   \textcolor{keyword}{call }mom\_mesg(\textcolor{stringliteral}{"MEKE\_alloc\_register\_restart: allocating and registering"}, 5)
01381   isd = hi%isd ; ied = hi%ied ; jsd = hi%jsd ; jed = hi%jed
01382   \textcolor{keyword}{allocate}(meke%MEKE(isd:ied,jsd:jed)) ; meke%MEKE(:,:) = 0.0
01383   vd = var\_desc(\textcolor{stringliteral}{"MEKE"}, \textcolor{stringliteral}{"m2 s-2"}, hor\_grid=\textcolor{stringliteral}{'h'}, z\_grid=\textcolor{stringliteral}{'1'}, &
01384            longname=\textcolor{stringliteral}{"Mesoscale Eddy Kinetic Energy"})
01385   \textcolor{keyword}{call }register\_restart\_field(meke%MEKE, vd, .false., restart\_cs)
01386   \textcolor{keywordflow}{if} (meke\_gmcoeff>=0.) \textcolor{keywordflow}{then}
01387     \textcolor{keyword}{allocate}(meke%GM\_src(isd:ied,jsd:jed)) ; meke%GM\_src(:,:) = 0.0
01388 \textcolor{keywordflow}{  endif}
01389   \textcolor{keywordflow}{if} (meke\_frcoeff>=0. .or. meke\_gmecoeff>=0.)  \textcolor{keywordflow}{then}
01390     \textcolor{keyword}{allocate}(meke%mom\_src(isd:ied,jsd:jed)) ; meke%mom\_src(:,:) = 0.0
01391 \textcolor{keywordflow}{  endif}
01392   \textcolor{keywordflow}{if} (meke\_gmecoeff>=0.) \textcolor{keywordflow}{then}
01393     \textcolor{keyword}{allocate}(meke%GME\_snk(isd:ied,jsd:jed)) ; meke%GME\_snk(:,:) = 0.0
01394 \textcolor{keywordflow}{  endif}
01395   \textcolor{keywordflow}{if} (meke\_khcoeff>=0.) \textcolor{keywordflow}{then}
01396     \textcolor{keyword}{allocate}(meke%Kh(isd:ied,jsd:jed)) ; meke%Kh(:,:) = 0.0
01397     vd = var\_desc(\textcolor{stringliteral}{"MEKE\_Kh"}, \textcolor{stringliteral}{"m2 s-1"}, hor\_grid=\textcolor{stringliteral}{'h'}, z\_grid=\textcolor{stringliteral}{'1'}, &
01398              longname=\textcolor{stringliteral}{"Lateral diffusivity from Mesoscale Eddy Kinetic Energy"})
01399     \textcolor{keyword}{call }register\_restart\_field(meke%Kh, vd, .false., restart\_cs)
01400 \textcolor{keywordflow}{  endif}
01401   \textcolor{keyword}{allocate}(meke%Rd\_dx\_h(isd:ied,jsd:jed)) ; meke%Rd\_dx\_h(:,:) = 0.0
01402   \textcolor{keywordflow}{if} (meke\_visccoeff\_ku/=0.) \textcolor{keywordflow}{then}
01403     \textcolor{keyword}{allocate}(meke%Ku(isd:ied,jsd:jed)) ; meke%Ku(:,:) = 0.0
01404     vd = var\_desc(\textcolor{stringliteral}{"MEKE\_Ku"}, \textcolor{stringliteral}{"m2 s-1"}, hor\_grid=\textcolor{stringliteral}{'h'}, z\_grid=\textcolor{stringliteral}{'1'}, &
01405              longname=\textcolor{stringliteral}{"Lateral viscosity from Mesoscale Eddy Kinetic Energy"})
01406     \textcolor{keyword}{call }register\_restart\_field(meke%Ku, vd, .false., restart\_cs)
01407 \textcolor{keywordflow}{  endif}
01408   \textcolor{keywordflow}{if} (use\_kh\_in\_meke) \textcolor{keywordflow}{then}
01409     \textcolor{keyword}{allocate}(meke%Kh\_diff(isd:ied,jsd:jed)) ; meke%Kh\_diff(:,:) = 0.0
01410     vd = var\_desc(\textcolor{stringliteral}{"MEKE\_Kh\_diff"}, \textcolor{stringliteral}{"m2 s-1"},hor\_grid=\textcolor{stringliteral}{'h'},z\_grid=\textcolor{stringliteral}{'1'}, &
01411              longname=\textcolor{stringliteral}{"Copy of thickness diffusivity for diffusing MEKE"})
01412     \textcolor{keyword}{call }register\_restart\_field(meke%Kh\_diff, vd, .false., restart\_cs)
01413 \textcolor{keywordflow}{  endif}
01414 
01415   \textcolor{keywordflow}{if} (meke\_visccoeff\_au/=0.) \textcolor{keywordflow}{then}
01416     \textcolor{keyword}{allocate}(meke%Au(isd:ied,jsd:jed)) ; meke%Au(:,:) = 0.0
01417     vd = var\_desc(\textcolor{stringliteral}{"MEKE\_Au"}, \textcolor{stringliteral}{"m4 s-1"}, hor\_grid=\textcolor{stringliteral}{'h'}, z\_grid=\textcolor{stringliteral}{'1'}, &
01418              longname=\textcolor{stringliteral}{"Lateral biharmonic viscosity from Mesoscale Eddy Kinetic Energy"})
01419     \textcolor{keyword}{call }register\_restart\_field(meke%Au, vd, .false., restart\_cs)
01420 \textcolor{keywordflow}{  endif}
01421 
01422 \textcolor{keyword}{end subroutine }\hyperlink{namespacemom__meke_a1900316331157e48f1a6029bac63fbd0}{meke\_alloc\_register\_restart}
01423 \textcolor{comment}{}
01424 \textcolor{comment}{!> Deallocates any variables allocated in MEKE\_init or}
01425 \textcolor{comment}{!! MEKE\_alloc\_register\_restart.}
01426 \textcolor{keyword}{subroutine }\hyperlink{namespacemom__meke_acc007bf1aa24263f699b059d3e9cc6eb}{meke\_end}(MEKE, CS)
\Hypertarget{MOM__MEKE_8F90_source_l01427}\hyperlink{namespacemom__meke_acc007bf1aa24263f699b059d3e9cc6eb}{01427}   \textcolor{keywordtype}{type}(meke\_type), \textcolor{keywordtype}{pointer} :: MEKE\textcolor{comment}{ !< A structure with MEKE-related fields.}
01428   \textcolor{keywordtype}{type}(\hyperlink{structmom__meke_1_1meke__cs}{meke\_cs}),   \textcolor{keywordtype}{pointer} :: CS\textcolor{comment}{   !< The control structure for MOM\_MEKE.}
01429 
01430   \textcolor{keywordflow}{if} (\textcolor{keyword}{associated}(cs)) \textcolor{keyword}{deallocate}(cs)
01431 
01432   \textcolor{keywordflow}{if} (.not.\textcolor{keyword}{associated}(meke)) \textcolor{keywordflow}{return}
01433 
01434   \textcolor{keywordflow}{if} (\textcolor{keyword}{associated}(meke%MEKE)) \textcolor{keyword}{deallocate}(meke%MEKE)
01435   \textcolor{keywordflow}{if} (\textcolor{keyword}{associated}(meke%GM\_src)) \textcolor{keyword}{deallocate}(meke%GM\_src)
01436   \textcolor{keywordflow}{if} (\textcolor{keyword}{associated}(meke%mom\_src)) \textcolor{keyword}{deallocate}(meke%mom\_src)
01437   \textcolor{keywordflow}{if} (\textcolor{keyword}{associated}(meke%GME\_snk)) \textcolor{keyword}{deallocate}(meke%GME\_snk)
01438   \textcolor{keywordflow}{if} (\textcolor{keyword}{associated}(meke%Kh)) \textcolor{keyword}{deallocate}(meke%Kh)
01439   \textcolor{keywordflow}{if} (\textcolor{keyword}{associated}(meke%Kh\_diff)) \textcolor{keyword}{deallocate}(meke%Kh\_diff)
01440   \textcolor{keywordflow}{if} (\textcolor{keyword}{associated}(meke%Ku)) \textcolor{keyword}{deallocate}(meke%Ku)
01441   \textcolor{keywordflow}{if} (\textcolor{keyword}{associated}(meke%Au)) \textcolor{keyword}{deallocate}(meke%Au)
01442   \textcolor{keyword}{deallocate}(meke)
01443 
01444 \textcolor{keyword}{end subroutine }\hyperlink{namespacemom__meke_acc007bf1aa24263f699b059d3e9cc6eb}{meke\_end}
01445 \textcolor{comment}{}
01446 \textcolor{comment}{!> \(\backslash\)namespace mom\_meke}
01447 \textcolor{comment}{!!}
01448 \textcolor{comment}{!! \(\backslash\)section section\_MEKE The Mesoscale Eddy Kinetic Energy (MEKE) framework}
01449 \textcolor{comment}{!!}
01450 \textcolor{comment}{!! The MEKE framework accounts for the mean potential energy removed by}
01451 \textcolor{comment}{!! the first order closures used to parameterize mesoscale eddies.}
01452 \textcolor{comment}{!! It requires closure at the second order, namely dissipation and transport}
01453 \textcolor{comment}{!! of eddy energy.}
01454 \textcolor{comment}{!!}
01455 \textcolor{comment}{!! Monitoring the sub-grid scale eddy energy budget provides a means to predict}
01456 \textcolor{comment}{!! a sub-grid eddy-velocity scale which can be used in the lower order closures.}
01457 \textcolor{comment}{!!}
01458 \textcolor{comment}{!! \(\backslash\)subsection section\_MEKE\_equations MEKE equations}
01459 \textcolor{comment}{!!}
01460 \textcolor{comment}{!! The eddy kinetic energy equation is:}
01461 \textcolor{comment}{!! \(\backslash\)f[ \(\backslash\)partial\_\{\(\backslash\)tilde\{t\}\} E =}
01462 \textcolor{comment}{!!   \(\backslash\)overbrace\{ \(\backslash\)dot\{E\}\_b + \(\backslash\)gamma\_\(\backslash\)eta \(\backslash\)dot\{E\}\_\(\backslash\)eta + \(\backslash\)gamma\_v \(\backslash\)dot\{E\}\_v}
01463 \textcolor{comment}{!!             \}^\(\backslash\)text\{sources\}}
01464 \textcolor{comment}{!! - \(\backslash\)overbrace\{ ( \(\backslash\)lambda + C\_d | U\_d | \(\backslash\)gamma\_b^2 ) E}
01465 \textcolor{comment}{!!             \}^\(\backslash\)text\{local dissipation\}}
01466 \textcolor{comment}{!! + \(\backslash\)overbrace\{ \(\backslash\)nabla \(\backslash\)cdot ( ( \(\backslash\)kappa\_E + \(\backslash\)gamma\_M \(\backslash\)kappa\_M ) \(\backslash\)nabla E}
01467 \textcolor{comment}{!!                              - \(\backslash\)kappa\_4 \(\backslash\)nabla^3 E )}
01468 \textcolor{comment}{!!             \}^\(\backslash\)text\{smoothing\}}
01469 \textcolor{comment}{!! \(\backslash\)f]}
01470 \textcolor{comment}{!! where \(\backslash\)f$ E \(\backslash\)f$ is the eddy kinetic energy (variable <code>MEKE</code>) with units of}
01471 \textcolor{comment}{!! m<sup>2</sup>s<sup>-2</sup>,}
01472 \textcolor{comment}{!! and \(\backslash\)f$\(\backslash\)tilde\{t\} = a t\(\backslash\)f$ is a scaled time. The non-dimensional factor}
01473 \textcolor{comment}{!! \(\backslash\)f$ a\(\backslash\)geq 1 \(\backslash\)f$ is used to accelerate towards equilibrium.}
01474 \textcolor{comment}{!!}
01475 \textcolor{comment}{!! The MEKE equation is two-dimensional and obtained by depth averaging the}
01476 \textcolor{comment}{!! the three-dimensional eddy energy equation. In the following expressions}
01477 \textcolor{comment}{!! \(\backslash\)f$ \(\backslash\)left< \(\backslash\)phi \(\backslash\)right> = \(\backslash\)frac\{1\}\{H\} \(\backslash\)int^\(\backslash\)eta\_\{-D\} \(\backslash\)phi \(\backslash\), dz \(\backslash\)f$ maps}
01478 \textcolor{comment}{!! three dimensional terms into the two-dimensional quantities needed.}
01479 \textcolor{comment}{!!}
01480 \textcolor{comment}{!! \(\backslash\)subsubsection section\_MEKE\_source\_terms MEKE source terms}
01481 \textcolor{comment}{!!}
01482 \textcolor{comment}{!! The source term \(\backslash\)f$ \(\backslash\)dot\{E\}\_b \(\backslash\)f$ is a constant background source}
01483 \textcolor{comment}{!! of energy intended to avoid the limit \(\backslash\)f$E\(\backslash\)rightarrow 0\(\backslash\)f$.}
01484 \textcolor{comment}{!!}
01485 \textcolor{comment}{!! The "GM" source term}
01486 \textcolor{comment}{!! \(\backslash\)f[ \(\backslash\)dot\{E\}\_\(\backslash\)eta = - \(\backslash\)left< \(\backslash\)overline\{w^\(\backslash\)prime b^\(\backslash\)prime\} \(\backslash\)right>}
01487 \textcolor{comment}{!! = \(\backslash\)left< \(\backslash\)kappa\_h N^2S^2 \(\backslash\)right>}
01488 \textcolor{comment}{!! \(\backslash\)approx \(\backslash\)left< \(\backslash\)kappa\_h g\(\backslash\)prime |\(\backslash\)nabla\_\(\backslash\)sigma \(\backslash\)eta|^2 \(\backslash\)right>\(\backslash\)f]}
01489 \textcolor{comment}{!! equals the mean potential energy removed by the Gent-McWilliams closure,}
01490 \textcolor{comment}{!! and is excluded/included in the MEKE budget by the efficiency parameter}
01491 \textcolor{comment}{!! \(\backslash\)f$ \(\backslash\)gamma\_\(\backslash\)eta \(\backslash\)in [0,1] \(\backslash\)f$.}
01492 \textcolor{comment}{!!}
01493 \textcolor{comment}{!! The "frictional" source term}
01494 \textcolor{comment}{!! \(\backslash\)f[ \(\backslash\)dot\{E\}\_\{v\} = \(\backslash\)left<  \(\backslash\)partial\_i u\_j \(\backslash\)tau\_\{ij\} \(\backslash\)right> \(\backslash\)f]}
01495 \textcolor{comment}{!! equals the mean kinetic energy removed by lateral viscous fluxes, and}
01496 \textcolor{comment}{!! is excluded/included in the MEKE budget by the efficiency parameter}
01497 \textcolor{comment}{!! \(\backslash\)f$ \(\backslash\)gamma\_v \(\backslash\)in [0,1] \(\backslash\)f$.}
01498 \textcolor{comment}{!!}
01499 \textcolor{comment}{!! \(\backslash\)subsubsection section\_MEKE\_dissipation\_terms MEKE dissipation terms}
01500 \textcolor{comment}{!!}
01501 \textcolor{comment}{!! The local dissipation of \(\backslash\)f$ E \(\backslash\)f$ is parameterized through a linear}
01502 \textcolor{comment}{!! damping, \(\backslash\)f$\(\backslash\)lambda\(\backslash\)f$, and bottom drag, \(\backslash\)f$ C\_d | U\_d | \(\backslash\)gamma\_b^2 \(\backslash\)f$.}
01503 \textcolor{comment}{!! The \(\backslash\)f$ \(\backslash\)gamma\_b \(\backslash\)f$ accounts for the weak projection of the column-mean}
01504 \textcolor{comment}{!! eddy velocty to the bottom. In other words, the bottom velocity is}
01505 \textcolor{comment}{!! estimated as \(\backslash\)f$ \(\backslash\)gamma\_b U\_e \(\backslash\)f$.}
01506 \textcolor{comment}{!! The bottom drag coefficient, \(\backslash\)f$ C\_d \(\backslash\)f$ is the same as that used in the bottom}
01507 \textcolor{comment}{!! friction in the mean model equations.}
01508 \textcolor{comment}{!!}
01509 \textcolor{comment}{!! The bottom drag velocity scale, \(\backslash\)f$ U\_d \(\backslash\)f$, has contributions from the}
01510 \textcolor{comment}{!! resolved state and \(\backslash\)f$ E \(\backslash\)f$:}
01511 \textcolor{comment}{!! \(\backslash\)f[ U\_d = \(\backslash\)sqrt\{ U\_b^2 + |u|^2\_\{z=-D\} + |\(\backslash\)gamma\_b U\_e|^2 \} .\(\backslash\)f]}
01512 \textcolor{comment}{!! where the eddy velocity scale, \(\backslash\)f$ U\_e \(\backslash\)f$, is given by:}
01513 \textcolor{comment}{!! \(\backslash\)f[ U\_e = \(\backslash\)sqrt\{ 2 E \} .\(\backslash\)f]}
01514 \textcolor{comment}{!! \(\backslash\)f$ U\_b \(\backslash\)f$ is a constant background bottom velocity scale and is}
01515 \textcolor{comment}{!! typically not used (i.e. set to zero).}
01516 \textcolor{comment}{!!}
01517 \textcolor{comment}{!! Following Jansen et al., 2015, the projection of eddy energy on to the bottom}
01518 \textcolor{comment}{!! is given by the ratio of bottom energy to column mean energy:}
01519 \textcolor{comment}{!! \(\backslash\)f[}
01520 \textcolor{comment}{!! \(\backslash\)gamma\_b^2  = \(\backslash\)frac\{E\_b\}\{E\} = \(\backslash\)gamma\_\{d0\}}
01521 \textcolor{comment}{!!    + \(\backslash\)left( 1 + c\_\{b\} \(\backslash\)frac\{L\_d\}\{L\_f\} \(\backslash\)right)^\{-\(\backslash\)frac\{4\}\{5\}\}}
01522 \textcolor{comment}{!! ,}
01523 \textcolor{comment}{!! \(\backslash\)f]}
01524 \textcolor{comment}{!! \(\backslash\)f[}
01525 \textcolor{comment}{!! \(\backslash\)gamma\_b^2  \(\backslash\)leftarrow  \(\backslash\)max\{\(\backslash\)left( \(\backslash\)gamma\_b^2, \(\backslash\)gamma\_\{min\}^2 \(\backslash\)right)\}}
01526 \textcolor{comment}{!! .}
01527 \textcolor{comment}{!! \(\backslash\)f]}
01528 \textcolor{comment}{!!}
01529 \textcolor{comment}{!! \(\backslash\)subsection section\_MEKE\_smoothing MEKE smoothing terms}
01530 \textcolor{comment}{!!}
01531 \textcolor{comment}{!! \(\backslash\)f$ E \(\backslash\)f$ is laterally diffused by a diffusivity \(\backslash\)f$ \(\backslash\)kappa\_E + \(\backslash\)gamma\_M}
01532 \textcolor{comment}{!! \(\backslash\)kappa\_M \(\backslash\)f$ where \(\backslash\)f$ \(\backslash\)kappa\_E \(\backslash\)f$ is a constant diffusivity and the term}
01533 \textcolor{comment}{!! \(\backslash\)f$ \(\backslash\)gamma\_M \(\backslash\)kappa\_M \(\backslash\)f$ is a "self diffusion" using the diffusivity}
01534 \textcolor{comment}{!! calculated in the section \(\backslash\)ref section\_MEKE\_diffusivity.}
01535 \textcolor{comment}{!! \(\backslash\)f$ \(\backslash\)kappa\_4 \(\backslash\)f$ is a constant bi-harmonic diffusivity.}
01536 \textcolor{comment}{!!}
01537 \textcolor{comment}{!! \(\backslash\)subsection section\_MEKE\_diffusivity Diffusivity derived from MEKE}
01538 \textcolor{comment}{!!}
01539 \textcolor{comment}{!! The predicted eddy velocity scale, \(\backslash\)f$ U\_e \(\backslash\)f$, can be combined with a}
01540 \textcolor{comment}{!! mixing length scale to form a diffusivity.}
01541 \textcolor{comment}{!! The primary use of a MEKE derived diffusivity is for use in thickness}
01542 \textcolor{comment}{!! diffusion (module mom\_thickness\_diffuse) and optionally in along}
01543 \textcolor{comment}{!! isopycnal mixing of tracers (module mom\_tracer\_hor\_diff).}
01544 \textcolor{comment}{!! The original form used (enabled with MEKE\_OLD\_LSCALE=True):}
01545 \textcolor{comment}{!!}
01546 \textcolor{comment}{!! \(\backslash\)f[  \(\backslash\)kappa\_M = \(\backslash\)gamma\_\(\backslash\)kappa \(\backslash\)sqrt\{ \(\backslash\)gamma\_t^2 U\_e^2 A\_\(\backslash\)Delta \} \(\backslash\)f]}
01547 \textcolor{comment}{!!}
01548 \textcolor{comment}{!! where \(\backslash\)f$ A\_\(\backslash\)Delta \(\backslash\)f$ is the area of the grid cell.}
01549 \textcolor{comment}{!! Following Jansen et al., 2015, we now use}
01550 \textcolor{comment}{!!}
01551 \textcolor{comment}{!! \(\backslash\)f[  \(\backslash\)kappa\_M = \(\backslash\)gamma\_\(\backslash\)kappa l\_M \(\backslash\)sqrt\{ \(\backslash\)gamma\_t^2 U\_e^2 \} \(\backslash\)f]}
01552 \textcolor{comment}{!!}
01553 \textcolor{comment}{!! where \(\backslash\)f$ \(\backslash\)gamma\_\(\backslash\)kappa \(\backslash\)in [0,1] \(\backslash\)f$ is a non-dimensional factor and,}
01554 \textcolor{comment}{!! following Jansen et al., 2015, \(\backslash\)f$\(\backslash\)gamma\_t^2\(\backslash\)f$ is the ratio of barotropic}
01555 \textcolor{comment}{!! eddy energy to column mean eddy energy given by}
01556 \textcolor{comment}{!! \(\backslash\)f[}
01557 \textcolor{comment}{!! \(\backslash\)gamma\_t^2  = \(\backslash\)frac\{E\_t\}\{E\} = \(\backslash\)left( 1 + c\_\{t\} \(\backslash\)frac\{L\_d\}\{L\_f\} \(\backslash\)right)^\{-\(\backslash\)frac\{1\}\{4\}\}}
01558 \textcolor{comment}{!! ,}
01559 \textcolor{comment}{!! \(\backslash\)f]}
01560 \textcolor{comment}{!! \(\backslash\)f[}
01561 \textcolor{comment}{!! \(\backslash\)gamma\_t^2  \(\backslash\)leftarrow  \(\backslash\)max\{\(\backslash\)left( \(\backslash\)gamma\_t^2, \(\backslash\)gamma\_\{min\}^2 \(\backslash\)right)\}}
01562 \textcolor{comment}{!! .}
01563 \textcolor{comment}{!! \(\backslash\)f]}
01564 \textcolor{comment}{!!}
01565 \textcolor{comment}{!! The length-scale is a configurable combination of multiple length scales:}
01566 \textcolor{comment}{!!}
01567 \textcolor{comment}{!! \(\backslash\)f[}
01568 \textcolor{comment}{!! l\_M = \(\backslash\)left(}
01569 \textcolor{comment}{!!       \(\backslash\)frac\{\(\backslash\)alpha\_d\}\{L\_d\}}
01570 \textcolor{comment}{!!     + \(\backslash\)frac\{\(\backslash\)alpha\_f\}\{L\_f\}}
01571 \textcolor{comment}{!!     + \(\backslash\)frac\{\(\backslash\)alpha\_R\}\{L\_R\}}
01572 \textcolor{comment}{!!     + \(\backslash\)frac\{\(\backslash\)alpha\_e\}\{L\_e\}}
01573 \textcolor{comment}{!!     + \(\backslash\)frac\{\(\backslash\)alpha\_\(\backslash\)Delta\}\{L\_\(\backslash\)Delta\}}
01574 \textcolor{comment}{!!     + \(\backslash\)frac\{\(\backslash\)delta[L\_c]\}\{L\_c\}}
01575 \textcolor{comment}{!!       \(\backslash\)right)^\{-1\}}
01576 \textcolor{comment}{!! \(\backslash\)f]}
01577 \textcolor{comment}{!!}
01578 \textcolor{comment}{!! where}
01579 \textcolor{comment}{!!}
01580 \textcolor{comment}{!! \(\backslash\)f\{eqnarray*\}\{}
01581 \textcolor{comment}{!! L\_d & = & \(\backslash\)sqrt\{\(\backslash\)frac\{c\_g^2\}\{f^2+2\(\backslash\)beta c\_g\}\} \(\backslash\)sim \(\backslash\)frac\{ c\_g \}\{f\} \(\backslash\)\(\backslash\)\(\backslash\)\(\backslash\)}
01582 \textcolor{comment}{!! L\_R & = & \(\backslash\)sqrt\{\(\backslash\)frac\{U\_e\}\{\(\backslash\)beta^*\}\} \(\backslash\)\(\backslash\)\(\backslash\)\(\backslash\)}
01583 \textcolor{comment}{!! L\_e & = & \(\backslash\)frac\{U\_e\}\{|S| N\} \(\backslash\)\(\backslash\)\(\backslash\)\(\backslash\)}
01584 \textcolor{comment}{!! L\_f & = & \(\backslash\)frac\{H\}\{c\_d\} \(\backslash\)\(\backslash\)\(\backslash\)\(\backslash\)}
01585 \textcolor{comment}{!! L\_\(\backslash\)Delta & = & \(\backslash\)sqrt\{A\_\(\backslash\)Delta\} .}
01586 \textcolor{comment}{!! \(\backslash\)f\}}
01587 \textcolor{comment}{!!}
01588 \textcolor{comment}{!! \(\backslash\)f$L\_c\(\backslash\)f$ is a constant and \(\backslash\)f$\(\backslash\)delta[L\_c]\(\backslash\)f$ is the impulse function so that the term}
01589 \textcolor{comment}{!! \(\backslash\)f$\(\backslash\)frac\{\(\backslash\)delta[L\_c]\}\{L\_c\}\(\backslash\)f$ evaluates to \(\backslash\)f$\(\backslash\)frac\{1\}\{L\_c\}\(\backslash\)f$ when \(\backslash\)f$L\_c\(\backslash\)f$ is non-zero}
01590 \textcolor{comment}{!! but is dropped if \(\backslash\)f$L\_c=0\(\backslash\)f$.}
01591 \textcolor{comment}{!!}
01592 \textcolor{comment}{!! \(\backslash\)f$\(\backslash\)beta^*\(\backslash\)f$ is the effective \(\backslash\)f$\(\backslash\)beta\(\backslash\)f$ that combines both the planetary vorticity}
01593 \textcolor{comment}{!! gradient (i.e. \(\backslash\)f$\(\backslash\)beta=\(\backslash\)nabla f\(\backslash\)f$) and the topographic \(\backslash\)f$\(\backslash\)beta\(\backslash\)f$ effect,}
01594 \textcolor{comment}{!! with the latter weighed by a weighting constant, \(\backslash\)f$c\_\(\backslash\)beta\(\backslash\)f$, that varies}
01595 \textcolor{comment}{!! from 0 to 1, so that \(\backslash\)f$c\_\(\backslash\)beta=0\(\backslash\)f$ means the topographic \(\backslash\)f$\(\backslash\)beta\(\backslash\)f$ effect is ignored,}
01596 \textcolor{comment}{!! while \(\backslash\)f$c\_\(\backslash\)beta=1\(\backslash\)f$ means it is fully considered. The new \(\backslash\)f$\(\backslash\)beta^*\(\backslash\)f$ therefore}
01597 \textcolor{comment}{!! takes the form of}
01598 \textcolor{comment}{!!}
01599 \textcolor{comment}{!! \(\backslash\)f[}
01600 \textcolor{comment}{!! \(\backslash\)beta^* = \(\backslash\)sqrt\{( \(\backslash\)partial\_xf - c\_\(\backslash\)beta\(\backslash\)frac\{f\}\{D\}\(\backslash\)partial\_xD )^2 +}
01601 \textcolor{comment}{!!           ( \(\backslash\)partial\_yf - c\_\(\backslash\)beta\(\backslash\)frac\{f\}\{D\}\(\backslash\)partial\_yD )^2\}}
01602 \textcolor{comment}{!! \(\backslash\)f]}
01603 \textcolor{comment}{!! where \(\backslash\)f$D\(\backslash\)f$ is water column depth at T points.}
01604 \textcolor{comment}{!!}
01605 \textcolor{comment}{!! \(\backslash\)subsection section\_MEKE\_viscosity Viscosity derived from MEKE}
01606 \textcolor{comment}{!!}
01607 \textcolor{comment}{!! As for \(\backslash\)f$ \(\backslash\)kappa\_M \(\backslash\)f$, the predicted eddy velocity scale can be}
01608 \textcolor{comment}{!! used to form a harmonic eddy viscosity,}
01609 \textcolor{comment}{!!}
01610 \textcolor{comment}{!! \(\backslash\)f[  \(\backslash\)kappa\_u = \(\backslash\)gamma\_u \(\backslash\)sqrt\{ U\_e^2 A\_\(\backslash\)Delta \}  \(\backslash\)f]}
01611 \textcolor{comment}{!!}
01612 \textcolor{comment}{!! as well as a biharmonic eddy viscosity,}
01613 \textcolor{comment}{!!}
01614 \textcolor{comment}{!! \(\backslash\)f[  \(\backslash\)kappa\_4 = \(\backslash\)gamma\_4 \(\backslash\)sqrt\{ U\_e^2 A\_\(\backslash\)Delta^3 \}  \(\backslash\)f]}
01615 \textcolor{comment}{!!}
01616 \textcolor{comment}{!! \(\backslash\)subsection section\_MEKE\_limit\_case Limit cases for local source-dissipative balance}
01617 \textcolor{comment}{!!}
01618 \textcolor{comment}{!! Note that in steady-state (or when \(\backslash\)f$ a>>1 \(\backslash\)f$) and there is no}
01619 \textcolor{comment}{!! diffusion of \(\backslash\)f$ E \(\backslash\)f$ then}
01620 \textcolor{comment}{!! \(\backslash\)f[ \(\backslash\)overline\{E\} \(\backslash\)approx \(\backslash\)frac\{ \(\backslash\)dot\{E\}\_b + \(\backslash\)gamma\_\(\backslash\)eta \(\backslash\)dot\{E\}\_\(\backslash\)eta +}
01621 \textcolor{comment}{!!               \(\backslash\)gamma\_v \(\backslash\)dot\{E\}\_v \}\{ \(\backslash\)lambda + C\_d|U\_d|\(\backslash\)gamma\_b^2 \} . \(\backslash\)f]}
01622 \textcolor{comment}{!!}
01623 \textcolor{comment}{!! In the linear drag limit, where}
01624 \textcolor{comment}{!! \(\backslash\)f$ U\_e << \(\backslash\)min(U\_b, |u|\_\{z=-D\}, C\_d^\{-1\}\(\backslash\)lambda) \(\backslash\)f$, the equilibrium becomes}
01625 \textcolor{comment}{!! \(\backslash\)f$ \(\backslash\)overline\{E\} \(\backslash\)approx \(\backslash\)frac\{ \(\backslash\)dot\{E\}\_b + \(\backslash\)gamma\_\(\backslash\)eta \(\backslash\)dot\{E\}\_\(\backslash\)eta +}
01626 \textcolor{comment}{!!               \(\backslash\)gamma\_v \(\backslash\)dot\{E\}\_v \}\{ \(\backslash\)lambda + C\_d \(\backslash\)sqrt\{ U\_b^2 + |u|^2\_\{z=-D\} \} \} \(\backslash\)f$.}
01627 \textcolor{comment}{!!}
01628 \textcolor{comment}{!! In the nonlinear drag limit, where \(\backslash\)f$ U\_e >> \(\backslash\)max(U\_b, |u|\_\{z=-D\}, C\_d^\{-1\}\(\backslash\)lambda) \(\backslash\)f$,}
01629 \textcolor{comment}{!! the equilibrium becomes}
01630 \textcolor{comment}{!! \(\backslash\)f$ \(\backslash\)overline\{E\} \(\backslash\)approx \(\backslash\)left( \(\backslash\)frac\{ \(\backslash\)dot\{E\}\_b + \(\backslash\)gamma\_\(\backslash\)eta \(\backslash\)dot\{E\}\_\(\backslash\)eta +}
01631 \textcolor{comment}{!!               \(\backslash\)gamma\_v \(\backslash\)dot\{E\}\_v \}\{ \(\backslash\)sqrt\{2\} C\_d \(\backslash\)gamma\_b^3 \} \(\backslash\)right)^\(\backslash\)frac\{2\}\{3\} \(\backslash\)f$.}
01632 \textcolor{comment}{!!}
01633 \textcolor{comment}{!! \(\backslash\)subsubsection section\_MEKE\_module\_parameters MEKE module parameters}
01634 \textcolor{comment}{!!}
01635 \textcolor{comment}{!! | Symbol                | Module parameter |}
01636 \textcolor{comment}{!! | ------                | --------------- |}
01637 \textcolor{comment}{!! | -                     | <code>USE\_MEKE</code> |}
01638 \textcolor{comment}{!! | \(\backslash\)f$ a \(\backslash\)f$             | <code>MEKE\_DTSCALE</code> |}
01639 \textcolor{comment}{!! | \(\backslash\)f$ \(\backslash\)dot\{E\}\_b \(\backslash\)f$     | <code>MEKE\_BGSRC</code> |}
01640 \textcolor{comment}{!! | \(\backslash\)f$ \(\backslash\)gamma\_\(\backslash\)eta \(\backslash\)f$   | <code>MEKE\_GMCOEFF</code> |}
01641 \textcolor{comment}{!! | \(\backslash\)f$ \(\backslash\)gamma\_v \(\backslash\)f$      | <code>MEKE\_FrCOEFF</code> |}
01642 \textcolor{comment}{!! | \(\backslash\)f$ \(\backslash\)lambda \(\backslash\)f$       | <code>MEKE\_DAMPING</code> |}
01643 \textcolor{comment}{!! | \(\backslash\)f$ U\_b \(\backslash\)f$           | <code>MEKE\_USCALE</code> |}
01644 \textcolor{comment}{!! | \(\backslash\)f$ \(\backslash\)gamma\_\{d0\} \(\backslash\)f$   | <code>MEKE\_CD\_SCALE</code> |}
01645 \textcolor{comment}{!! | \(\backslash\)f$ c\_\{b\} \(\backslash\)f$         | <code>MEKE\_CB</code> |}
01646 \textcolor{comment}{!! | \(\backslash\)f$ c\_\{t\} \(\backslash\)f$         | <code>MEKE\_CT</code> |}
01647 \textcolor{comment}{!! | \(\backslash\)f$ \(\backslash\)kappa\_E \(\backslash\)f$      | <code>MEKE\_KH</code> |}
01648 \textcolor{comment}{!! | \(\backslash\)f$ \(\backslash\)kappa\_4 \(\backslash\)f$      | <code>MEKE\_K4</code> |}
01649 \textcolor{comment}{!! | \(\backslash\)f$ \(\backslash\)gamma\_\(\backslash\)kappa \(\backslash\)f$ | <code>MEKE\_KHCOEFF</code> |}
01650 \textcolor{comment}{!! | \(\backslash\)f$ \(\backslash\)gamma\_M \(\backslash\)f$      | <code>MEKE\_KHMEKE\_FAC</code> |}
01651 \textcolor{comment}{!! | \(\backslash\)f$ \(\backslash\)gamma\_u \(\backslash\)f$      | <code>MEKE\_VISCOSITY\_COEFF\_KU</code> |}
01652 \textcolor{comment}{!! | \(\backslash\)f$ \(\backslash\)gamma\_4 \(\backslash\)f$      | <code>MEKE\_VISCOSITY\_COEFF\_AU</code> |}
01653 \textcolor{comment}{!! | \(\backslash\)f$ \(\backslash\)gamma\_\{min\}^2 \(\backslash\)f$| <code>MEKE\_MIN\_GAMMA2</code> |}
01654 \textcolor{comment}{!! | \(\backslash\)f$ \(\backslash\)alpha\_d \(\backslash\)f$      | <code>MEKE\_ALPHA\_DEFORM</code> |}
01655 \textcolor{comment}{!! | \(\backslash\)f$ \(\backslash\)alpha\_f \(\backslash\)f$      | <code>MEKE\_ALPHA\_FRICT</code> |}
01656 \textcolor{comment}{!! | \(\backslash\)f$ \(\backslash\)alpha\_R \(\backslash\)f$      | <code>MEKE\_ALPHA\_RHINES</code> |}
01657 \textcolor{comment}{!! | \(\backslash\)f$ \(\backslash\)alpha\_e \(\backslash\)f$      | <code>MEKE\_ALPHA\_EADY</code> |}
01658 \textcolor{comment}{!! | \(\backslash\)f$ \(\backslash\)alpha\_\(\backslash\)Delta \(\backslash\)f$ | <code>MEKE\_ALPHA\_GRID</code> |}
01659 \textcolor{comment}{!! | \(\backslash\)f$ L\_c \(\backslash\)f$           | <code>MEKE\_FIXED\_MIXING\_LENGTH</code> |}
01660 \textcolor{comment}{!! | \(\backslash\)f$ c\_\(\backslash\)beta \(\backslash\)f$       | <code>MEKE\_TOPOGRAPHIC\_BETA</code> |}
01661 \textcolor{comment}{!! | -                     | <code>MEKE\_KHTH\_FAC</code> |}
01662 \textcolor{comment}{!! | -                     | <code>MEKE\_KHTR\_FAC</code> |}
01663 \textcolor{comment}{!!}
01664 \textcolor{comment}{!! | Symbol                | Model parameter |}
01665 \textcolor{comment}{!! | ------                | --------------- |}
01666 \textcolor{comment}{!! | \(\backslash\)f$ C\_d \(\backslash\)f$           | <code>CDRAG</code> |}
01667 \textcolor{comment}{!!}
01668 \textcolor{comment}{!! \(\backslash\)subsection section\_MEKE\_references References}
01669 \textcolor{comment}{!!}
01670 \textcolor{comment}{!! Jansen, M. F., A. J. Adcroft, R. Hallberg, and I. M. Held, 2015: Parameterization of eddy fluxes based
       on a}
01671 \textcolor{comment}{!! mesoscale energy budget. Ocean Modelling, 92, 28--41, http://doi.org/10.1016/j.ocemod.2015.05.007 .}
01672 \textcolor{comment}{!!}
01673 \textcolor{comment}{!! Marshall, D. P., and A. J. Adcroft, 2010: Parameterization of ocean eddies: Potential vorticity mixing,
       energetics}
01674 \textcolor{comment}{!! and Arnold first stability theorem. Ocean Modelling, 32, 188--204,
       http://doi.org/10.1016/j.ocemod.2010.02.001 .}
01675 
01676 \textcolor{keyword}{end module }\hyperlink{namespacemom__meke}{mom\_meke}
01677 
\end{DoxyCode}
