Warning, /doc/examples/baroclinic_gyre/baroclinic_gyre.rst is written in an unsupported language. File is not indexed.
view on githubraw file Latest commit 0bad585a on 2022-02-16 18:55:09 UTC
94151a9b18 Jeff*0001
0002 .. _tutorial_baroclinic_gyre:
0003
0004 Baroclinic Ocean Gyre
0005 =====================
0006
0007 (in directory: :filelink:`verification/tutorial_baroclinic_gyre`)
0008
0009 This section describes an example experiment using MITgcm to simulate a
ce0d9af5ea Jeff*0010 baroclinic, wind and buoyancy-forced, double-gyre ocean circulation. Unlike tutorial
0011 :ref:`Barotropic Ocean Gyre <sec_eg_baro>`, which used a Cartesian grid and a single vertical
0012 layer, here the grid employs spherical polar coordinates with 15 vertical layers.
94151a9b18 Jeff*0013 The configuration is similar to the double-gyre setup first solved numerically
0014 in Cox and Bryan (1984) :cite:`cox:84`: the model is configured to
0015 represent an enclosed sector of fluid on a sphere, spanning the tropics to mid-latitudes,
0016 :math:`60^{\circ} \times 60^{\circ}` in lateral extent.
0017 The fluid is :math:`1.8` km deep and is forced by a zonal wind
0018 stress which is constant in time, :math:`\tau_{\lambda}`, varying sinusoidally in the
0019 north-south direction. The Coriolis parameter, :math:`f`, is defined
0020 according to latitude :math:`\varphi`
0021
0022 .. math::
0023 f(\varphi) = 2 \Omega \sin( \varphi )
0024
0025 with the rotation rate, :math:`\Omega` set to :math:`\frac{2 \pi}{86164} \text{s}^{-1}` (i.e., corresponding the to standard Earth rotation rate).
0026 The sinusoidal wind-stress variations are defined according to
0027
0028 .. math::
0029 \tau_{\lambda}(\varphi) = -\tau_{0}\cos \left(2 \pi \frac{\varphi-\varphi_o}{L_{\varphi}} \right)
0030
0031 where :math:`L_{\varphi}` is the lateral domain extent
0032 (:math:`60^{\circ}`), :math:`\varphi_o` is set to :math:`15^{\circ} \text{N}` and :math:`\tau_0` is :math:`0.1 \text{ N m}^{-2}`.
0033 :numref:`baroclinic_gyre_config` summarizes the
0034 configuration simulated. As indicated by the axes in the lower left of the figure, the
0035 model code works internally in a locally orthogonal coordinate
0036 :math:`(x,y,z)`. For this experiment description the local orthogonal
0037 model coordinate :math:`(x,y,z)` is synonymous with the coordinates
0038 :math:`(\lambda,\varphi,r)` shown in :numref:`sphere_coor`.
0039 Initially the fluid is stratified
0040 with a reference potential temperature profile that varies from :math:`\theta=30 \text{ } ^{\circ}`\ C
0041 in the surface layer to :math:`\theta=2 \text{ } ^{\circ}`\ C in the bottom layer.
0042 The equation of state used in this experiment is linear:
0043
0044 .. math::
0045 \rho = \rho_{0} ( 1 - \alpha_{\theta}\theta^{\prime} )
0046 :label: rho_lineareos
0047
0048 which is implemented in the model as a density anomaly equation
0049
0050 .. math::
0051 \rho^{\prime} = -\rho_{0}\alpha_{\theta}\theta^{\prime}
0052 :label: rhoprime_lineareos
0053
0054 with :math:`\rho_{0}=999.8\,{\rm kg\,m}^{-3}` and
0055 :math:`\alpha_{\theta}=2\times10^{-4}\,{\rm K}^{-1}`.
0056 Given the linear equation of state, in this configuration the model state variable for temperature is
0057 equivalent to either in-situ temperature, :math:`T`, or potential
0058 temperature, :math:`\theta`. For consistency with later examples, in
0059 which the equation of state is non-linear, here we use the variable :math:`\theta` to
0060 represent temperature.
0061
0062 .. figure:: figs/baroclinic_gyre_config.png
0063 :width: 95%
0064 :align: center
0065 :alt: baroclinic gyre configuration
0066 :name: baroclinic_gyre_config
0067
0068 Schematic of simulation domain and wind-stress forcing function for baroclinic gyre numerical experiment. The domain is enclosed by solid walls.
0069
0070 Temperature is restored in the surface layer to a linear profile:
0071
0072 .. math::
0073 {\cal F}_\theta = - \frac{1}{\tau_{\theta}} (\theta-\theta^*), \phantom{WWW}
0bad585a21 Navi*0074 \theta^* = \frac{\theta_{\rm max} - \theta_{\rm min}}{L_\varphi} (\varphi - \varphi_o)
94151a9b18 Jeff*0075 :label: baroc_restore_theta
0076
0bad585a21 Navi*0077 where the relaxation timescale :math:`\tau_{\theta} = 30` days and :math:`\theta_{\rm max}=30^{\circ}` C, :math:`\theta_{\rm min}=0^{\circ}` C.
94151a9b18 Jeff*0078
0079 .. _baroc_eq_solved:
0080
0081 Equations solved
0082 ----------------
0083
0084 For this problem the implicit free surface, **HPE**
0085 form of the equations (see :numref:`hydro_and_quasihydro`; :numref:`press_meth_linear`)
0086 described in Marshall et al. (1997) :cite:`marshall:97a` are
0087 employed. The flow is three-dimensional with just temperature,
0088 :math:`\theta`, as an active tracer.
0089 The viscous and diffusive terms provides viscous dissipation
0090 and a diffusive sub-grid scale closure for the momentum and temperature equations, respectively.
0091 A wind-stress momentum forcing is added to the
0092 momentum equation for the zonal flow, :math:`u`. Other terms in the
0093 model are explicitly switched off for this experiment configuration (see
0094 :numref:`sec_eg_baroclinic_code_config`). This yields an active set of
0095 equations solved in this configuration, written in spherical polar
0096 coordinates as follows:
0097
0098 .. math::
0099 \frac{Du}{Dt} - fv -\frac{uv}{a}\tan{\varphi} +
0100 \frac{1}{\rho_c a \cos{\varphi}}\frac{\partial p^{\prime}}{\partial \lambda} +
0bad585a21 Navi*0101 \nabla _h \cdot (-A_{h} \nabla _h u) + \frac{\partial}{\partial z} \left( -A_{z}\frac{\partial u}{\partial z} \right)
94151a9b18 Jeff*0102 = \mathcal{F}_u
0103 :label: baroc_gyre_umom
0104
0105 .. math::
0106 \frac{Dv}{Dt} + fu + \frac{u^2}{a}\tan{\varphi} +
0107 \frac{1}{\rho_c a}\frac{\partial p^{\prime}}{\partial \varphi} +
0bad585a21 Navi*0108 \nabla _h \cdot (-A_{h} \nabla _h v) + \frac{\partial}{\partial z} \left( -A_{z}\frac{\partial v}{\partial z} \right)
94151a9b18 Jeff*0109 = \mathcal{F}_v
0110 :label: baroc_gyre_vmom
0111
0112 .. math::
0113 \frac{\partial \eta}{\partial t} + \frac{1}{a \cos{\varphi}} \left( \frac{\partial H \widehat{u}}{\partial \lambda} +
0114 \frac{\partial H \widehat{v} \cos{\varphi}}{\partial \varphi} \right) = 0
0115 :label: baroc_gyre_cont
0116
0117 .. math::
0bad585a21 Navi*0118 \frac{D\theta}{Dt} + \nabla _h \cdot (-\kappa_{h} \nabla _h \theta)
94151a9b18 Jeff*0119 + \frac{\partial}{\partial z} \left( -\kappa_{z}\frac{\partial \theta}{\partial z} \right)
0120 = \mathcal{F}_\theta
0121 :label: barooc_gyre_theta
0122
0123 .. math::
0124 p^{\prime} = g\rho_{c} \eta + \int^{0}_{z} g \rho^{\prime} dz
0125 :label: baroc_gyre_press
0126
0127 where :math:`u` and :math:`v` are the components of the horizontal flow
0128 vector :math:`\vec{u}` on the sphere
0129 (:math:`u=\dot{\lambda},v=\dot{\varphi}`), :math:`a` is the distance from the center of the Earth,
0130 :math:`\rho_c` is a fluid density (which appears in the momentum equations,
0131 and can be set differently than :math:`\rho_0` in :eq:`rhoprime_lineareos`),
0132 :math:`A_h` and :math:`A_v` are horizontal and vertical viscosity, and
0133 :math:`\kappa_h` and :math:`\kappa_v` are horizontal and vertical diffusivity, respectively.
0134 The terms :math:`H\widehat{u}` and :math:`H\widehat{v}` are the components of the
0135 vertical integral term given in equation :eq:`free-surface` and explained
0136 in more detail in :numref:`press_meth_linear`.
0137 However, for the problem presented here, the continuity relation
0138 :eq:`baroc_gyre_cont` differs from the general form
0139 given in :numref:`press_meth_linear`, equation :eq:`linear-free-surface=P-E`
0140 because the source terms
0141 :math:`{\mathcal P}-{\mathcal E}+{\mathcal R}` are all zero.
0142
0143 The forcing terms :math:`\mathcal{F}_u`, :math:`\mathcal{F}_v`, and :math:`\mathcal{F}_\theta` are
0144 applied as source terms in the model surface layer and are zero in the interior.
0145 The windstress forcing, :math:`{\mathcal F}_u` and :math:`{\mathcal F}_v`, is
0146 applied in the zonal and meridional momentum
0bad585a21 Navi*0147 equations, respectively; in this configuration, :math:`\mathcal{F}_u = \tau_x / (\rho_c\Delta z_s)`
94151a9b18 Jeff*0148 (where :math:`\Delta z_s` is the depth of the surface model gridcell), and
0149 :math:`\mathcal{F}_v = 0`. Similarly, :math:`\mathcal{F}_\theta` is applied in the temperature equation,
0150 as given by :eq:`baroc_restore_theta`.
0151
0152 In :eq:`baroc_gyre_press` the pressure field, :math:`p^{\prime}`, is separated into a barotropic
0153 part due to variations in sea-surface height, :math:`\eta`, and a
0154 hydrostatic part due to variations in density, :math:`\rho^{\prime}`,
0155 integrated through the water column. Note the :math:`g` in the first term on the right hand side is
0156 MITgcm parameter :varlink:`gBaro` whereas in the seond term :math:`g` is parameter :varlink:`gravity`;
0157 allowing for different gravity constants here is useful, for example, if one wanted to slow down external gravity waves.
0158
0159 In the momentum equations, lateral and vertical boundary conditions for
0bad585a21 Navi*0160 the :math:`\nabla_{h}^{2}` and :math:`\partial_z^2` operators are specified in the
94151a9b18 Jeff*0161 runtime configuration - see :numref:`sec_eg_baroclinic_code_config`.
0162 For temperature, the boundary condition along the bottom and sidewalls is zero-flux.
0163
0164 Discrete Numerical Configuration
0165 --------------------------------
0166
0167 The domain is discretized with a uniform grid spacing in latitude and
0168 longitude :math:`\Delta \lambda=\Delta \varphi=1^{\circ}`, so that there
0169 are 60 active ocean grid cells in the zonal and meridional directions. As in tutorial
0170 :ref:`Barotropic Ocean Gyre <sec_eg_baro>`, a border row of land cells surrounds the
0171 ocean domain, so the full numerical grid size is 62\ :math:`\times`\ 62 in the horizontal.
0172 The domain has 15 levels in the vertical, varying from :math:`\Delta z = 50` m deep in the surface layer
0173 to 190 m deep in the bottom layer, as shown by the faint red lines in :numref:`baroclinic_gyre_config`.
0174 The internal, locally orthogonal,
0175 model coordinate variables :math:`x` and :math:`y` are initialized from
0176 the values of :math:`\lambda`, :math:`\varphi`, :math:`\Delta \lambda`
0177 and :math:`\Delta \varphi` in radians according to:
0178
0179 .. math::
0180 \begin{aligned} x &= a\cos(\varphi)\lambda, \phantom{WWW} \Delta x = a\cos(\varphi)\Delta \lambda \\
0181 y &= a\varphi, \phantom{WWWWWW} \Delta y = a\Delta \varphi \end{aligned}
0182
0183 See :numref:`operators` for additional description of spherical coordinates.
0184
0185 As described in :numref:`tracer_eqns`, the time evolution of
0186 potential temperature :math:`\theta` in :eq:`barooc_gyre_theta`
0187 is evaluated prognostically. The centered
0188 second-order scheme with Adams-Bashforth II time stepping described in
0189 :numref:`sub_tracer_eqns_ab` is used to step forward the
0190 temperature equation.
0191
0192 Prognostic terms in the momentum equations are
0193 solved using flux form as described in :numref:`flux-form_momentum_equations`.
0194 The pressure forces that drive
0bad585a21 Navi*0195 the fluid motions, :math:`\partial_{\lambda} p^\prime`
0196 and :math:`\partial_{\varphi} p^\prime`, are found by
94151a9b18 Jeff*0197 summing pressure due to surface elevation :math:`\eta` and the
0198 hydrostatic pressure, as discussed in :numref:`baroc_eq_solved`.
0199 The hydrostatic part of the pressure is
0200 diagnosed explicitly by integrating density.
0201 The sea-surface height is found by solving implicitly the 2-D (elliptic) surface pressure equation
0202 (see :numref:`press_meth_linear`).
0203
0204 Numerical Stability Criteria
0205 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~
0206
0207 The analysis in this section is similar to that discussed in
0208 tutorial :ref:`Barotropic Ocean Gyre <barotropic_gyre_stab_crit>`,
0209 albeit with some added wrinkles. In this experiment, we not only have a larger model domain extent, with greater variation
0210 in the Coriolis parameter between the southernmost and northernmost gridpoints, but also significant variation
0211 in the grid :math:`\Delta x` spacing.
0212
0213 In order to choose an appropriate time step, note that our smallest gridcells (i.e., in the far north)
0214 have :math:`\Delta x \approx 29` km, which
0215 is similar to our grid spacing in tutorial :ref:`Barotropic Ocean Gyre <barotropic_gyre_stab_crit>`. Thus, using the advective
0bad585a21 Navi*0216 CFL condition, first assuming our solution will achieve maximum horizontal advection :math:`|c_{\rm max}|` ~ 1 ms\ :sup:`-1`)
94151a9b18 Jeff*0217
0218 .. math::
0bad585a21 Navi*0219 S_{\rm adv} = 2 \left( \frac{ |c_{\rm max}| \Delta t}{ \Delta x} \right) < 0.5 \text{ for stability}
94151a9b18 Jeff*0220 :label: eq_baroc_cfl_stability
0221
0222 we choose the same time step as in tutorial :ref:`Barotropic Ocean Gyre <barotropic_gyre_stab_crit>`,
0bad585a21 Navi*0223 :math:`\Delta t` = 1200 s (= 20 minutes), resulting in :math:`S_{\rm adv} = 0.08`.
94151a9b18 Jeff*0224 Also note this time step is stable for propagation of internal gravity waves:
0225 approximating the propagation speed as :math:`\sqrt{g' h}` where :math:`g'` is reduced gravity (our maximum
0226 :math:`\Delta \rho` using our linear equation of state is
0227 :math:`\rho_{0} \alpha_{\theta} \Delta \theta = 6` kg/m\ :sup:`3`) and :math:`h` is the upper layer depth
0bad585a21 Navi*0228 (we'll assume 150 m), produces an estimated propagation speed generally less than :math:`|c_{\rm max}| = 3` ms\ :sup:`--1`
94151a9b18 Jeff*0229 (see Adcroft 1995 :cite:`adcroft:95` or Gill 1982 :cite:`gill:82`), thus still comfortably below the threshold.
0230
0231 Using our chosen value of :math:`\Delta t`, numerical stability for inertial oscillations using Adams-Bashforth II
0232
0233 .. math::
0bad585a21 Navi*0234 S_{\rm inert} = f {\Delta t} < 0.5 \text{ for stability}
94151a9b18 Jeff*0235 :label: eq_baroc_inertial_stability
0236
0237 evaluates to 0.17 for the largest :math:`f` value in our domain (:math:`1.4\times10^{-4}` s\ :sup:`--1`),
0238 below the stability threshold.
0239
0240 To choose a horizontal Laplacian eddy viscosity :math:`A_{h}`, note that the largest :math:`\Delta x`
0241 value in our domain (i.e., in the south) is :math:`\approx 110` km. With the Munk boundary width as follows,
0242
0243 .. math::
0bad585a21 Navi*0244 M = \frac{2\pi}{\sqrt{3}} \left( \frac { A_{h} }{ \beta } \right) ^{\frac{1}{3}}
94151a9b18 Jeff*0245 :label: baroc_munk_layer
0246
0247 in order to to have a well resolved boundary current in the subtropical gyre we will set
0248 :math:`A_{h} = 5000` m\ :sup:`2` s\ :sup:`--1`. This results in a boundary current
0249 resolved across two to three grid cells in the southern portion of the domain.
0250
0251 Given that our choice for :math:`A_{h}` in this experiment is an order of magnitude larger than in
0252 tutorial :ref:`Barotropic Ocean Gyre <barotropic_gyre_stab_crit>`,
0253 let's re-examine the stability of horizontal Laplacian friction:
0254
0255 .. math::
0bad585a21 Navi*0256 S_{\rm Lh} = 2 \left( 4 \frac{A_{h} \Delta t}{{\Delta x}^2} \right) < 0.6 \text{ for stability}
94151a9b18 Jeff*0257 :label: baroc_laplacian_stability
0258
0259 evaluates to 0.057 for our smallest :math:`\Delta x`, which is below the stability threshold.
0260 Note this same stability test also applies to horizontal Laplacian diffusion of tracers, with :math:`\kappa_{h}` replacing
0261 :math:`A_{h}`, but we will choose :math:`\kappa_{h} \ll A_{h}` so this should not pose any stability issues.
0262
0263 Finally, stability of vertical diffusion of momentum:
0264
0265 .. math::
0bad585a21 Navi*0266 S_{\rm Lv} = 4 \frac{A_{v} \Delta t}{{\Delta z}^2} < 0.6 \text{ for stability}
94151a9b18 Jeff*0267 :label: baroc_laplacian_v_stability
0268
0269 Here we will choose :math:`A_{v} = 1\times10^{-2}` m\ :sup:`2` s\ :sup:`--1`,
9c8516d9da Jeff*0270 so :math:`S_{lv}` evaluates to 0.02 for our minimum :math:`\Delta z`,
94151a9b18 Jeff*0271 well below the stability threshold. Note if we were to use Adams Bashforth II for diffusion of tracers
0272 the same check would apply, with :math:`\kappa_{v}` replacing :math:`A_{v}`. However, we will instead choose
0273 an implicit scheme for computing vertical diffusion of tracers (see :numref:`baroc_input_data`), which is unconditionally stable.
0274
0275 .. _sec_eg_baroclinic_code_config:
0276
0277 Configuration
0278 -------------
0279
0280 The model configuration for this experiment resides under the directory :filelink:`verification/tutorial_baroclinic_gyre/`.
0281
0282 The experiment files
0283
0284 - :filelink:`verification/tutorial_baroclinic_gyre/code/packages.conf`
0285 - :filelink:`verification/tutorial_baroclinic_gyre/code/SIZE.h`
0286 - :filelink:`verification/tutorial_baroclinic_gyre/code/DIAGNOSTICS_SIZE.h`
0287 - :filelink:`verification/tutorial_baroclinic_gyre/input/data`
0288 - :filelink:`verification/tutorial_baroclinic_gyre/input/data.pkg`
0289 - :filelink:`verification/tutorial_baroclinic_gyre/input/data.mnc`
0290 - :filelink:`verification/tutorial_baroclinic_gyre/input/data.diagnostics`
0291 - :filelink:`verification/tutorial_baroclinic_gyre/input/eedata`
0292 - verification/tutorial_baroclinic_gyre/input/bathy.bin
0293 - verification/tutorial_baroclinic_gyre/input/windx_cosy.bin
0294 - verification/tutorial_baroclinic_gyre/input/SST_relax.bin
0295
0296 contain the code customizations, parameter settings, and input data files for this
0297 experiment. Below we describe these customizations in detail.
0298
0299 .. _tut_baroc_code_config:
0300
0301 Compile-time Configuration
0302 ~~~~~~~~~~~~~~~~~~~~~~~~~~
0303
0304 File :filelink:`code/packages.conf <verification/tutorial_baroclinic_gyre/code/packages.conf>`
0305 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
0306
0307 .. literalinclude:: ../../../verification/tutorial_baroclinic_gyre/code/packages.conf
0308 :linenos:
0309 :caption: verification/tutorial_baroclinic_gyre/code/packages.conf
0310
0311 Here we specify which MITgcm packages we want to include in our configuration. ``gfd``
0312 is a pre-defined "package group" (see :ref:`using_packages`)
0313 of standard packages necessary for most setups; it is also the :ref:`default compiled packages <default_pkg_list>` setting
0314 and the minimum set of packages necessary for GFD-type setups.
0315 In addition to package group ``gfd`` we include two additional packages (individual packages, not package groups), :filelink:`mnc </pkg/mnc>`
0316 and :filelink:`diagnostics </pkg/diagnostics>`. Package :filelink:`mnc </pkg/mnc>` is required
0317 for output to be dumped in `netCDF <http://www.unidata.ucar.edu/software/netcdf>`_ format. Package :filelink:`diagnostics </pkg/diagnostics>`
0318 allows one to choose output from a extensive list of model diagnostics, and specify output frequency, with multiple time averaging or snapshot options available.
0319 Without this package enabled, output is limited to a small number of snapshot output fields. Subsequent tutorial experiments will explore the use
0320 of packages which expand the physical and scientific capabilities of MITgcm, e.g., such as physical parameterizations or modeling capabilities
0321 for tracers, ice, etc., that are not compiled unless specified.
0322
0323 .. _baroc_code_size:
0324
0325 File :filelink:`code/SIZE.h <verification/tutorial_baroclinic_gyre/code/SIZE.h>`
0326 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
0327
0328 .. literalinclude:: ../../../verification/tutorial_baroclinic_gyre/code/SIZE.h
0329 :linenos:
0330 :caption: verification/tutorial_baroclinic_gyre/code/SIZE.h
0331
0332 For this second tutorial, we will break the model domain into multiple tiles. Although initially we will
0333 run the model on a single processor, a multi-tiled setup
0334 is required when we demonstrate how to run the model using either
0335 `MPI <https://en.wikipedia.org/wiki/Message_Passing_Interface>`_ or using multiple threads.
0336
0337 The following lines calculate the horizontal size of the global model domain (NOT to be edited).
0338 Our values for :filelink:`SIZE.h <verification/tutorial_baroclinic_gyre/code/SIZE.h>` parameters
0339 below must multiply so that our horizontal model domain is 62\ :math:`\times`\ 62:
0340
0341 .. literalinclude:: ../../../verification/tutorial_baroclinic_gyre/code/SIZE.h
0342 :start-at: sNx*nSx
0343 :end-at: sNy*nSy
0344 :lineno-match:
0345
0346 Now let's look at all individual :filelink:`SIZE.h <verification/tutorial_baroclinic_gyre/code/SIZE.h>` parameter settings.
0347
0348 - Although our model domain is 62\ :math:`\times`\ 62, here we specify the size of a single tile to be one-half that
0349 in both :math:`x` and :math:`y`. Thus, the model requires four of these tiles to cover the full ocean sector domain
0350 (see below, where we set :varlink:`nSx` and :varlink:`nSy`). Note that the grid
0351 can only be subdivided into tiles in the horizontal dimensions, not in the vertical.
0352
0353 .. literalinclude:: ../../../verification/tutorial_baroclinic_gyre/code/SIZE.h
0354 :start-at: sNx =
0355 :end-at: sNy =
0356 :lineno-match:
0357
0358 - As in tutorial :ref:`Barotropic Ocean Gyre <barotropic_gyre_stab_crit>`, here we set the overlap extent of a model tile
0359 to the value 2 in both :math:`x` and :math:`y`. In other words, although our model tiles are sized 31\ :math:`\times`\ 31,
0360 in MITgcm array storage there are an additional 2 border rows surrounding
0361 each tile which contain model data from neighboring tiles.
0362 Some horizontal advection schemes and other parameter and setup choices
0363 require a larger overlap setting (see :numref:`adv_scheme_summary`).
0364 In our configuration, we are using a second-order center-differences advection scheme (the MITgcm default)
0365 which does not requires setting a overlap beyond the MITgcm minimum 2.
0366
0367 .. literalinclude:: ../../../verification/tutorial_barotropic_gyre/code/SIZE.h
0368 :start-at: OLx =
0369 :end-at: OLy =
0370 :lineno-match:
0371
0372 - These lines set parameters :varlink:`nSx` and :varlink:`nSy`,
0373 the number of model tiles in the :math:`x` and :math:`y` directions, respectively,
0374 which execute on a single process. Initially, we will run the model on a single core,
0375 thus both :varlink:`nSx` and :varlink:`nSy` are set to 2 so that all :math:`2 \times 2 = 4` tiles are integrated forward in time.
0376
0377 .. literalinclude:: ../../../verification/tutorial_baroclinic_gyre/code/SIZE.h
0378 :start-at: nSx =
0379 :end-at: nSy =
0380 :lineno-match:
0381
0382 - These lines set parameters :varlink:`nPx` and :varlink:`nPy`, the number of processes
0383 to use in the :math:`x` and :math:`y` directions, respectively.
0384 As noted, initially we will run using a single process, so for now these parameters are both set to 1.
0385
0386 .. literalinclude:: ../../../verification/tutorial_baroclinic_gyre/code/SIZE.h
0387 :start-at: nPx =
0388 :end-at: nPy =
0389 :lineno-match:
0390
0391 - Here we tell the model we are using 15 vertical levels.
0392
0393 .. literalinclude:: ../../../verification/tutorial_baroclinic_gyre/code/SIZE.h
0394 :start-at: Nr =
0395 :end-at: Nr =
0396 :lineno-match:
0397
0398 File :filelink:`code/DIAGNOSTICS_SIZE.h <verification/tutorial_baroclinic_gyre/code/DIAGNOSTICS_SIZE.h>`
0399 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
0400
0401 .. literalinclude:: ../../../verification/tutorial_baroclinic_gyre/code/DIAGNOSTICS_SIZE.h
0402 :linenos:
0403 :caption: verification/tutorial_baroclinic_gyre/code/DIAGNOSTICS_SIZE.h
0404
0405 In the default version :filelink:`/pkg/diagnostics/DIAGNOSTICS_SIZE.h` the storage array for diagnostics is purposely
0406 set quite small, in other words forcing the user to assess how many diagnostics will be computed and thus choose an appropriate
0407 size for a storage array. In the above file we have modified the value of parameter :varlink:`numDiags`:
0408
0409 .. literalinclude:: ../../../verification/tutorial_baroclinic_gyre/code/DIAGNOSTICS_SIZE.h
0410 :start-at: numDiags =
0411 :end-at: numDiags =
0412 :lineno-match:
0413
0414 from its default value ``1*Nr``, which would only allow a single 3-D diagnostic to be computed and saved, to ``20*Nr``,
0415 which will permit up to some combination of up to 20 3-D diagnostics or 300 2-D diagnostic fields.
0416
0417 Run-time Configuration
0418 ~~~~~~~~~~~~~~~~~~~~~~
0419
0420 .. _baroc_input_data:
0421
0422 File :filelink:`input/data <verification/tutorial_baroclinic_gyre/input/data>`
0423 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
0424
0425 .. literalinclude:: ../../../verification/tutorial_baroclinic_gyre/input/data
0426 :linenos:
0427 :caption: verification/tutorial_baroclinic_gyre/input/data
0428
0429 Parameters for this configuration
0430 are set as follows.
0431
0432 PARM01 - Continuous equation parameters
0433 #######################################
0434
0435 - These lines set parameters :varlink:`viscAh` and :varlink:`viscAr`, the horizontal and vertical Laplacian viscosities respectively,
0436 to :math:`5000` m\ :sup:`2` s\ :sup:`--1` and :math:`1 \times 10^{-2}` m\ :sup:`2` s\ :sup:`--1`. Note the subscript :math:`r`
0437 is used for the vertical, reflecting MITgcm's generic :math:`r`-vertical coordinate capability (i.e., the model is capable of
0438 using either a :math:`z`-coordinate or a :math:`p`-coordinate system).
0439
0440 .. literalinclude:: ../../../verification/tutorial_baroclinic_gyre/input/data
0441 :start-at: viscAh
0442 :end-at: viscAr
0443 :lineno-match:
0444
0445 - These lines set parameters to specify the boundary conditions for momentum on the model domain sidewalls and bottom.
0446 Parameter :varlink:`no_slip_sides` is set to ``.TRUE.``, i.e., no-slip lateral boundary conditions (the default), which will yield a Munk (1950) :cite:`munk:50` western boundary solution.
0447 Parameter :varlink:`no_slip_bottom` is set to ``.FALSE.``, i.e., free-slip bottom boundary condition (default is true).
0448 If instead of a Munk layer we desired a Stommel (1948) :cite:`stommel:48` western boundary layer solution, we would opt for free-slip lateral boundary conditions and no-slip conditions along the bottom.
0449
0450 .. literalinclude:: ../../../verification/tutorial_baroclinic_gyre/input/data
0451 :start-at: slip_sides
0452 :end-at: slip_bottom
0453 :lineno-match:
0454
0455 - These lines set parameters :varlink:`diffKhT` and :varlink:`diffKrT`,
0456 the horizontal and vertical Laplacian temperature diffusivities respectively,
0457 to :math:`1000` m\ :sup:`2` s\ :sup:`--1` and :math:`1 \times 10^{-5}` m\ :sup:`2` s\ :sup:`--1`.The boundary condition on this
0458 operator is zero-flux at all boundaries.
0459
0460 .. literalinclude:: ../../../verification/tutorial_baroclinic_gyre/input/data
0461 :start-at: diffKhT
0462 :end-at: diffKrT
0463 :lineno-match:
0464
0465 - By default, MITgcm does not apply any parameterization to mix statically unstable columns of water. In a coarse resolution, hydrostatic
0466 configuration, typically such a parameterization is desired. We recommend a scheme which
0467 simply applies (presumably, large) vertical diffusivity between statically unstable grid cells in the vertical. This vertical diffusivity
0468 is set by parameter :varlink:`ivdc_kappa`, which here we set to :math:`1.0` m\ :sup:`2` s\ :sup:`--1`. This scheme requires that
0469 :varlink:`implicitDiffusion` is set to ``.TRUE.`` (see :numref:`implicit-backward-stepping`;
0470 more specifically, applying a large vertical diffusivity to represent convective mixing
0471 requires the use of an implicit
0472 time-stepping method for vertical diffusion, rather than Adams Bashforth II).
0473 Alternatively, a traditional convective adjustment scheme is available; this can be activated
0474 through the :varlink:`cAdjFreq` parameter, see :numref:`ocean_convection_parms`.
0475
0476 .. literalinclude:: ../../../verification/tutorial_baroclinic_gyre/input/data
0477 :start-at: ivdc
0478 :end-at: implicitDiff
0479 :lineno-match:
0480
0481 .. _tut_baroc_linear_eos:
0482
0483 - The following parameters tell the model to use a linear equation of state.
0484 Note a list of :varlink:`Nr` (=15, from :filelink:`SIZE.h <verification/tutorial_baroclinic_gyre/code/SIZE.h>`)
0485 potential temperature values in :sup:`o`\ C is specified for parameter :varlink:`tRef`, ordered from surface to depth.
0486 :varlink:`tRef` is used for two purposes here.
0bad585a21 Navi*0487 First, anomalies in density are computed using this reference :math:`\theta`, :math:`\theta'(x,y,z) = \theta(x,y,z) - \theta_{\rm ref}(z)`;
94151a9b18 Jeff*0488 see use in :eq:`rho_lineareos` and :eq:`rhoprime_lineareos`.
0489 Second, the model will use these reference temperatures for its initial state, as we are not providing a pickup file
0490 nor specifying an initial temperature hydrographic file (in later tutorials we will demonstrate how to do so).
0491 For each depth level the initial and reference profiles will be uniform in :math:`x` and :math:`y`.
0492 Note when checking static stability or computing :math:`N^2`, the density gradient resulting from these specified reference levels
0493 is added to :math:`\partial \rho' / \partial z` from :eq:`rhoprime_lineareos`.
0494 Finally, we set the thermal expansion coefficient :math:`\alpha_{\theta}` (:varlink:`tAlpha`)
0495 as used in :eq:`rho_lineareos` and :eq:`rhoprime_lineareos`, while setting
0496 the haline contraction coefficient (:varlink:`sBeta`) to zero (see :eq:`rho_lineareos`, which omits a salinity contribution to the
0497 linear equation of state; like tutorial :ref:`Barotropic Ocean Gyre <sec_eg_baro>`,
0498 salinity is not included as a tracer in this very idealized model setup).
0499
0500 .. literalinclude:: ../../../verification/tutorial_baroclinic_gyre/input/data
0501 :start-at: eosType
0502 :end-at: sBeta
0503 :lineno-match:
0504
0505 - This line sets parameter :math:`\rho_0` (:varlink:`rhoNil`) to 999.8 kg/m\ :sup:`3`, the surface reference density for our linear equation of state,
0506 i.e., the density of water at tRef(k=1). This value will also be used
0507 as :math:`\rho_c` (parameter :varlink:`rhoConst`) in :eq:`baroc_gyre_umom`-:eq:`baroc_gyre_press`,
0508 lacking a separate explicit assignment of :varlink:`rhoConst` in ``data``.
0509 Note this value is the model default value for :varlink:`rhoNil`.
0510
0511 .. literalinclude:: ../../../verification/tutorial_baroclinic_gyre/input/data
0512 :start-at: rhoNil
0513 :end-at: rhoNil
0514 :lineno-match:
0515
0516 - This line sets parameter :varlink:`gravity`, the acceleration due to gravity :math:`g` in :eq:`baroc_gyre_press`, and this value will also
0517 be used to set :varlink:`gBaro`, the barotopic (i.e., free surface-related)
0518 gravity parameter which we set in tutorial :ref:`Barotropic Ocean Gyre <barotropic_gyre_stab_crit>`.
0519 This is the MITgcm default value.
0520
0521 .. literalinclude:: ../../../verification/tutorial_baroclinic_gyre/input/data
0522 :start-at: gravity
0523 :end-at: gravity
0524 :lineno-match:
0525
0526 - These lines set parameters which prescribe the linearized free surface formulation,
0527 similar to tutorial :ref:`Barotropic Ocean Gyre <barotropic_gyre_stab_crit>`. Note
0528 we have added parameter :varlink:`exactConserv`, set to ``.TRUE.``: this instructs the model to
0529 recompute divergence after the pressure solver step, ensuring volume conservation of the free surface solution
0530 (the model default is NOT to recompute divergence, but given the small numerical cost, we typically recommend doing so).
0531
0532 .. literalinclude:: ../../../verification/tutorial_baroclinic_gyre/input/data
0533 :start-at: rigidLid
0534 :end-at: exactConserv
0535 :lineno-match:
0536
0537 - As in tutorial :ref:`Barotropic Ocean Gyre <barotropic_gyre_stab_crit>`, we
0538 suppress MITgcm’s forward time integration of salt in the tracer equations.
0539
0540 .. literalinclude:: ../../../verification/tutorial_baroclinic_gyre/input/data
0541 :start-at: saltStepping
0542 :end-at: saltStepping
0543 :lineno-match:
0544
0545 PARM02 - Elliptic solver parameters
0546 ###################################
0547
0548 These parameters are unchanged from tutorial :ref:`Barotropic Ocean Gyre <barotropic_gyre_stab_crit>`.
0549
0550 .. _baroc_parm03:
0551
0552 PARM03 - Time stepping parameters
0553 #################################
0554
0555 - In tutorial :ref:`Barotropic Ocean Gyre <barotropic_gyre_stab_crit>` we specified a starting iteration number :varlink:`nIter0`
0556 and a number of time steps to integrate, :varlink:`nTimeSteps`. Here we opt to use another approach to control run start and duration:
0557 we set a :varlink:`startTime` and :varlink:`endTime`, both in units of seconds. Given a starting time of 0.0, the model starts
0558 from rest using specified initial values of temperature (here, as previously noted, from the :varlink:`tRef` parameter) rather than attempting
0559 to restart from a saved checkpoint file. The specified value for :varlink:`endTime`, 12000.0 seconds
0560 is equivalent to 10 time steps, set for testing purposes.
0561 To integrate over a longer, more physically relevant period of time, uncomment the :varlink:`endTime` and :varlink:`monitorFreq` lines
0562 located near the end of this parameter block. Note, for simplicity, our units for these time choices assume a 360-day "year"
0563 and 30-day "month" (although lacking a seasonal cycle in our forcing, defining a "year" is immaterial; we will demonstrate how to apply time-varying
0564 forcings in later tutorials).
0565
0566 .. literalinclude:: ../../../verification/tutorial_baroclinic_gyre/input/data
0567 :start-at: startTime
0568 :end-at: endTime
0569 :lineno-match:
0570
0571 .. literalinclude:: ../../../verification/tutorial_baroclinic_gyre/input/data
0572 :start-at: for longer
0573 :end-at: Freq=2592
0574 :lineno-match:
0575
0576 - Remaining time stepping parameter choices (specifically, :math:`\Delta t`,
0577 checkpoint frequency, output frequency, and monitor settings)
0578 are described in tutorial :ref:`Barotropic Ocean Gyre <barotropic_gyre_stab_crit>`;
0579 refer to the description :ref:`here <baro_time_stepping_parms>`.
0580
0581 .. literalinclude:: ../../../verification/tutorial_baroclinic_gyre/input/data
0582 :start-at: deltaT
0583 :end-at: monitorSelect
0584 :lineno-match:
0585
0586 - The parameter :varlink:`tauThetaClimRelax` sets the time scale, in seconds,
0587 for restoring potential temperature in the model's top surface layer (see :eq:`baroc_restore_theta`).
0588 Our choice here of 2,592,000 seconds is equal to 30 days.
0589
0590 .. literalinclude:: ../../../verification/tutorial_baroclinic_gyre/input/data
0591 :start-at: tauTheta
0592 :end-at: tauTheta
0593 :lineno-match:
0594
0595 PARM04 - Gridding parameters
0596 ############################
0597
0598 - This line sets parameter :varlink:`usingSphericalPolarGrid`, which specifies that the simulation will use spherical polar coordinates
0599 (and affects the interpretation of other grid coordinate parameters).
0600
0601 .. literalinclude:: ../../../verification/tutorial_baroclinic_gyre/input/data
0602 :start-at: usingSpherical
0603 :end-at: usingSpherical
0604 :lineno-match:
0605
0606 - These lines set the horizontal grid spacing, as vectors :varlink:`delX` and :varlink:`delY`
0607 (i.e., :math:`\Delta x` and :math:`\Delta y` respectively), with units of degrees
0608 as dictated by our choice :varlink:`usingSphericalPolarGrid`.
0609 As before, this syntax indicates that we specify 62 values in both the :math:`x` and :math:`y` directions, which matches the
0610 global domain size as specified in :filelink:`SIZE.h <verification/tutorial_barotropic_gyre/code/SIZE.h>`.
0611 Our ocean sector domain starts at :math:`0^\circ` longitude and :math:`15^\circ` N; accounting for a surrounding land
0612 row of cells, we thus set the origin in longitude to :math:`-1.0^\circ` and in latitude to :math:`14.0^\circ`.
0613 Again note that our origin specifies the southern and western edges of the gridcell, not the cell center location.
0614 Setting the origin in latitude is critical given that it affects the Coriolis parameter :math:`f`
0615 (which appears in :eq:`baroc_gyre_umom` and :eq:`baroc_gyre_vmom`); the default value for :varlink:`ygOrigin` is :math:`0.0^\circ`.
0616 Note that setting :varlink:`xgOrigin` is optional, given that absolute longitude does not appear in the equation discretization.
0617
0618 .. literalinclude:: ../../../verification/tutorial_baroclinic_gyre/input/data
0619 :start-at: delX
0620 :end-at: ygOrigin
0621 :lineno-match:
0622
0623 - This line sets parameter :varlink:`delR`, the vertical grid spacing in the :math:`z`-coordinate (i.e., :math:`\Delta z`),
0624 to a vector of 15 depths (in meters), from 50 m in the surface layer to a bottom layer depth of 190 m. The sum of these
0625 specified depths equals 1800 m, the full depth :math:`H` of our idealized ocean sector.
0626
0627 .. literalinclude:: ../../../verification/tutorial_baroclinic_gyre/input/data
0628 :start-at: delR
0629 :end-at: delR
0630 :lineno-match:
0631
0632 PARM05 - Input datasets
0633 #######################
0634
0635 - Similar to tutorial :ref:`Barotropic Ocean Gyre <barotropic_gyre_stab_crit>`, these lines specify filenames for bathymetry
0636 and surface wind stress forcing files.
0637
0638 .. literalinclude:: ../../../verification/tutorial_baroclinic_gyre/input/data
0639 :start-at: bathyFile
0640 :end-at: zonalWindFile
0641 :lineno-match:
0642
0643 - This line specifies parameter :varlink:`thetaClimFile`, the filename for the (2-D) restoring temperature field.
0644
0645 .. literalinclude:: ../../../verification/tutorial_baroclinic_gyre/input/data
0646 :start-at: thetaClimFile
0647 :end-at: thetaClimFile
0648 :lineno-match:
0649
0650 File :filelink:`input/data.pkg <verification/tutorial_baroclinic_gyre/input/data.pkg>`
0651 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
0652
0653 .. literalinclude:: ../../../verification/tutorial_baroclinic_gyre/input/data.pkg
0654 :linenos:
0655 :caption: verification/tutorial_baroclinic_gyre/input/data.pkg
0656
0657 Here we activate two MITgcm packages that are not included with the model by default:
0658 package :filelink:`mnc <pkg/mnc>` (see :numref:`pkg_mnc`) specifies that model output should be written in `netCDF <http://www.unidata.ucar.edu/software/netcdf>`_ format,
0659 and package :filelink:`diagnostics <pkg/diagnostics>` (see :numref:`sub_outp_pkg_diagnostics`) allows user-selectable diagnostic output.
0660 The boolean parameters set are :varlink:`useMNC` and :varlink:`useDiagnostics`, respectively.
0661 Note these add-on packages also need to be specified when the model is compiled, see :numref:`tut_baroc_code_config`.
0662 Apart from these two additional packages, only standard packages (i.e., those compiled in MITgcm by default) are required for this setup.
0663
0664 .. _baroc_datamnc:
0665
0666 File :filelink:`input/data.mnc <verification/tutorial_baroclinic_gyre/input/data.mnc>`
0667 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
0668
0669 .. literalinclude:: ../../../verification/tutorial_baroclinic_gyre/input/data.mnc
0670 :linenos:
0671 :caption: verification/tutorial_baroclinic_gyre/input/data.mnc
0672
0673 This file sets parameters which affect package :filelink:`pkg/mnc` behavior; in fact, with :filelink:`pkg/mnc` enabled, it is required
0674 (many packages look for file ``data.«PACKAGENAME»`` and will terminate if not present).
0675 By setting the parameter :varlink:`monitor_mnc` to ``.FALSE.``
0676 we are specifying NOT to create separate `netCDF <http://www.unidata.ucar.edu/software/netcdf>`_
0677 output files for :filelink:`pkg/monitor` output, but rather to include this monitor output in the standard output file
0678 (see :numref:`baro_gyre_build_run`). See :numref:`pkg_mnc_inputs` for a complete
0679 listing of :filelink:`pkg/mnc` namelist parameters and their default settings.
0680
ce0d9af5ea Jeff*0681 Unlike raw binary output, which overwrites any existing files, when using mnc output the model will create new directories if the parameters
0682 :varlink:`mnc_use_outdir` and :varlink:`mnc_outdir_str` are set, as above; the model will append a 4-digit number to :varlink:`mnc_outdir_str`,
0683 starting at 0001, incrementing as needed if existing directories already exist.
0684 If these parameters are NOT set, the model will terminate with an error if one attempts
0685 to overwrite an existing ``.nc`` file (in other words, to re-run in an previous run directory,
0686 one must delete all ``*.nc`` files before restarting). Note that our subdirectory name choice ``mnc_test_`` is required
0687 by :ref:`MITgcm automated testing <code_testing_protocols>` protocols, and can be changed to something more mnemonic, if desired.
0688
0689 In general, it is good practice to write diagnostic output into subdirectories, to keep the top run directory
0690 less "cluttered"; some unix file systems do not respond well when very large numbers of files are produced, which can
0691 occur in setups divided into many tiles and/or when many diagnostics are selected for output.
94151a9b18 Jeff*0692
0693 .. _baroc_diags_list:
0694
0695 File :filelink:`input/data.diagnostics <verification/tutorial_baroclinic_gyre/input/data.diagnostics>`
0696 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
0697
0698 .. literalinclude:: ../../../verification/tutorial_baroclinic_gyre/input/data.diagnostics
0699 :linenos:
0700 :caption: verification/tutorial_baroclinic_gyre/input/data.diagnostics
0701
0702 .. _baroc_diags_parms:
0703
0704 DIAGNOSTICS_LIST - Diagnostic Package Choices
0705 #############################################
0706
0707 In this section we specify what diagnostics we want to compute, how frequently to compute them, and the name of output files.
0708 Multiple diagnostic fields can be grouped into individual files (i.e., an individual output file here is associated with a 'list' of diagnostics).
0709
0710 .. literalinclude:: ../../../verification/tutorial_baroclinic_gyre/input/data.diagnostics
0711 :start-at: fields(1:3,1
0712 :end-at: frequency(1
0713 :lineno-match:
0714
0715 The above lines tell MITgcm that our first list will consist of three diagnostic variables:
0716
0717 - ETAN - the linearized free surface height (m)
0718 - TRELAX - the heat flux entering the ocean due to surface temperature relaxation (W/m\ :sup:`2`)
0719 - MXLDEPTH - the depth of the mixed layer (m), as defined here by a given magnitude decrease
0720 in density from the surface (we'll use the model default for :math:`\Delta \rho`)
0721
0722 Note that all these diagnostic
0723 fields are 2-D output. **2-D and 3-D diagnostics CANNOT be mixed in a diagnostics list.**
0724 These variables are specified in parameter :varlink:`fields`: the first index is specified as ``1:«NUMBER_OF_DIAGS»``, the second index
0725 designates this for diagnostics list 1. Next, the output filename for diagnostics list 1 is specified in variable :varlink:`fileName`. Finally,
0726 for this list we specify variable :varlink:`frequency` to provide time-averaged output every 31,104,000 seconds,
0727 i.e., once per year. Had we entered
0728 a negative value for :varlink:`frequency`, MITgcm would have instead written snapshot data at this interval.
0729 Next, we set up a second diagnostics list for several 3-D diagnostics.
0730
0731 .. literalinclude:: ../../../verification/tutorial_baroclinic_gyre/input/data.diagnostics
0732 :start-at: fields(1:5,2
0733 :end-at: frequency(2
0734 :lineno-match:
0735
0736 The diagnostics in list 2 are:
0737
0738 - THETA - potential temperature (:sup:`o`\ C )
0739 - PHYHYD - hydrostatic pressure potential anomaly (m\ :sup:`2`/s\ :sup:`2`)
0740 - UVEL, VVEL, WVEL - the zonal, meridional, and vertical velocity components respectively (m/s)
0741
0742 Here we did not specify parameter :varlink:`levels`, so all depth levels will be included in the output.
0743 An example of syntax to limit which depths are output is ``levels(1:5,2) = 1.,2.,3.,``, which would dump just the top three levels.
0744 We again specify an output file name via parameter :varlink:`fileName`, and specify a time-average period of one year
0745 through parameter :varlink:`frequency`.
0746
0747 .. _baroc_stat_diags:
0748
0749 DIAG_STATIS_PARMS - Diagnostic Per Level Statistics
0750 ###################################################
0751
0752 It is also possible to request output statistics averaged for global mean and by level average (for 3-D diagnostics) over the full domain,
0753 and/or for a pre-defined :math:`(x,y)` region of the model grid. The statistics computed for each diagnostic are as follows:
0754
0755 - (area weighted) mean (in both space and time, if time-averaged frequency is selected)
0756 - (area weighted) standard deviation
0757 - minimum value
0758 - maximum value
0759 - volume of the area used in the calculation (multiplied by the number of time steps if time-averaged).
0760
0761 While these statistics could in theory also be calculated (by the user) from 2-D and 3-D :varlink:`DIAGNOSTICS_LIST` output, the advantage
0762 is that much higher frequency statistical output can be achieved without filling up copious amounts of disk space.
0763
0764 Options for namelist :varlink:`DIAG_STATIS_PARMS` are set as follows:
0765
0766 .. literalinclude:: ../../../verification/tutorial_baroclinic_gyre/input/data.diagnostics
0767 :start-at: stat_fields(1
0768 :end-at: stat_freq
0769 :lineno-match:
0770
0771 The syntax here is analogous with :varlink:`DIAGNOSTICS_LIST` namelist parameters, except the parameter names begin with ``stat``
0772 (here, :varlink:`stat_fields`, :varlink:`stat_fName`, :varlink:`stat_freq`). Frequency can be set to snapshot or time-averaged output,
0773 and multiple lists of diagnostics (i.e., separate output files) can be specified. The only major difference from
0774 :varlink:`DIAGNOSTICS_LIST` syntax is that 2-D and 3-D diagnostics can be mixed in a list.
0775 As noted, it is possible to select limited horizontal regions of interest, in addition to the full domain calculation.
0776
0777 File :filelink:`input/eedata <verification/tutorial_baroclinic_gyre/input/eedata>`
0778 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
0779 .. literalinclude:: ../../../verification/tutorial_baroclinic_gyre/input/eedata
0780 :linenos:
0781 :caption: verification/tutorial_baroclinic_gyre/input/eedata
0782
0783 As shown, this file is configured for a single-threaded run, but will be modified later in this tutorial for a multi-threaded setup
0784 (:numref:`baroc_openmp`).
0785
0786 .. _baroc_gyre_bathy_file:
0787
0788 Files ``input/bathy.bin``, ``input/windx_cosy.bin``
0789 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
0790
83cdbd2346 Jeff*0791 The purpose and format of these files is similar to tutorial :ref:`Barotropic Ocean Gyre <baro_gyre_bathy_file>`,
ce0d9af5ea Jeff*0792 and were generated by matlab script :filelink:`verification/tutorial_baroclinic_gyre/input/gendata.m`
0793 (alternatively, python script :filelink:`gendata.py <verification/tutorial_baroclinic_gyre/input/gendata.py>`).
83cdbd2346 Jeff*0794 See :numref:`sec_mitgcm_inp_file_format` for additional information on MITgcm input data file format specifications.
94151a9b18 Jeff*0795
0796 File ``input/SST_relax.bin``
0797 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
0798
83cdbd2346 Jeff*0799 This file specifies a 2-D(:math:`x,y`) map of surface relaxation temperature values,
ce0d9af5ea Jeff*0800 as generated by :filelink:`verification/tutorial_baroclinic_gyre/input/gendata.m` or
0801 :filelink:`gendata.py <verification/tutorial_baroclinic_gyre/input/gendata.py>`.
94151a9b18 Jeff*0802
0803 .. _building_tutorial_baroc:
0804
0805 Building and running the model
0806 ------------------------------
0807
0808 To build and run the model on a single processor, follow the procedure outlined in :numref:`baro_gyre_build_run`.
0809 To run the model for a longer period (i.e., to obtain a reasonable solution; for testing purposes,
0810 by default the model is set to run only a few time steps) uncomment the lines in ``data`` which specify
0811 larger numbers for parameters :varlink:`endTime` and :varlink:`monitorFreq`. This will run the model for 100 years, which
0812 will likely take several hours on a single processor (depending on your computer specs); below we also give instructions for running the model
0813 in parallel either using `MPI <https://en.wikipedia.org/wiki/Message_Passing_Interface>`_
0814 or multi-threaded (`OpenMP <https://en.wikipedia.org/wiki/OpenMP>`_), which
0815 will cut down run time significantly.
0816
0817 Output Files
0818 ~~~~~~~~~~~~
0819
0820 As in tutorial :ref:`sec_eg_baro`, standard output is produced (redirected into
0821 file ``output.txt`` as specified in :numref:`baro_gyre_build_run`); like before, this file
0822 includes model startup information, parameters, etc. (see :numref:`barotropic_gyre_std_out`).
0823 And because we set :varlink:`monitor_mnc` ``=.FALSE.`` in :ref:`data.mnc <baroc_datamnc>`,
0824 our standard output file will include all monitor statistics output. Note monitor statistics and cg2d
0825 information are evaluated over the global domain, despite the bifurcation of the grid into four separate tiles.
0826 As before, the file ``STDERR.0000`` will contain a log of any run-time errors.
0827
0828 With :filelink:`pkg/mnc` compiled and activated in ``data.pkg``, other output is
0829 in `netCDF <http://www.unidata.ucar.edu/software/netcdf>`_ format: grid information,
0830 snapshot output specified in ``data``, diagnostics output specified in ``data.diagnostics``
0831 and separate files containing hydrostatic pressure data (see below).
0832 There are two notable differences from standard binary output. Recall that we specified
0833 that the grid was subdivided into four separate tiles (in :ref:`SIZE.h <baroc_code_size>`);
0834 instead of a ``.XXX.YYY.`` file naming scheme for different tiles (as discussed :ref:`here <tut_barotropic_tilenaming>`),
0835 with :filelink:`pkg/nmc` the file names contain ``.t«nnn».`` where «nnn» is the
0836 tile number. Secondly, model data from multiple
0837 time snapshots (or periods) is included in a single file. Although an iteration
0838 number is still part of the file name (here, ``0000000000``),
0839 this is the iteration number at the start of the run (instead of
0840 marking the specific iteration number for the data contained in the file, as the case
0841 for standard binary output). Note that if you dump data frequently, standard binary can produce
0842 huge quantities of separate files, whereas using `netCDF <http://www.unidata.ucar.edu/software/netcdf>`_
0843 will greatly reduce the number of files. On the other hand, the
0844 `netCDF <http://www.unidata.ucar.edu/software/netcdf>`_ files created can instead become quite large.
0845
0846 To more easily process and plot our results as a single array over the full domain,
ce0d9af5ea Jeff*0847 we will first reassemble the individual tiles into new `netCDF <http://www.unidata.ucar.edu/software/netcdf>`_ format global data files.
0848 To accomplish this, we will make use of utility script :filelink:`utils/python/MITgcmutils/scripts/gluemncbig`.
0849 From the output run (top) directory, type:
0850
0851 .. _baroc_gluemnc_steps:
94151a9b18 Jeff*0852
0853 ::
0854
0855 % ln -s ../../../utils/python/MITgcmutils/scripts/gluemncbig .
0856 % ./gluemncbig -o grid.nc mnc_test_*/grid.t*.nc
0857 % ./gluemncbig -o state.nc mnc_test_*/state*.t*.nc
0858 % ./gluemncbig -o dynDiag.nc mnc_test_*/dynDiag*.t*.nc
0859 % ./gluemncbig -o surfDiag.nc mnc_test_*/surfDiag*.t*.nc
0860 % ./gluemncbig -o phiHyd.nc mnc_test_*/phiHyd*.t*.nc
0861 % ./gluemncbig -o phiHydLow.nc mnc_test_*/phiHydLow*.t*.nc
ce0d9af5ea Jeff*0862 % ln -s mnc_test_0001/dynStDiag.0000000000.t001.nc dynStDiag.nc
94151a9b18 Jeff*0863
ce0d9af5ea Jeff*0864 For help using this utility, type ``gluemncbig --help`` (note, this utility requires python).
94151a9b18 Jeff*0865 The files ``grid.nc``, ``state.nc``, etc. are concatenated from the separate ``t001``, ``t002``, ``t003``, ``t004`` files
ce0d9af5ea Jeff*0866 into global grid files of horizontal dimension 62\ :math:`\times`\ 62. ``gluemncbig`` is a fairly intelligent script, and by inserting the wildcards
0867 in the path/filename specification, it will grab the most recent run (in case you have started up runs multiple times in this directory,
0868 thus having ``mnc_test_0001``, ``mnc_test_0002``, etc. directories present; see :numref:`baroc_datamnc`).
0869 Note that the last line above is simply making
0870 a link to a file in the ``mnc_test_0001`` output subdirectory; this is the :ref:`statistical-dynamical diagnostics <baroc_stat_diags>`
0871 output, which is already assembled over the global domain (and also note here we are required to be specific which ``mnc_test_`` directory to link from).
0872 For convenience we simply place the link at the top level
0873 of the run directory, where the other assembled ``.nc`` files are saved by ``gluemncbig``.
94151a9b18 Jeff*0874
0875 Let's proceed through the netcdf output that is produced.
0876
0877 - ``grid.nc`` - includes all the model grid variables used by MITgcm.
0878 This includes the grid cell center points and separation (:varlink:`XC`, :varlink:`YC`, :varlink:`dxC`, :varlink:`dyC`),
0879 corner point locations and separation (:varlink:`XG`, :varlink:`YG`, :varlink:`dxG`, :varlink:`dyG`),
0880 the separation between velocity points (:varlink:`dyU`, :varlink:`dxV`),
0881 vertical coordinate location and separation (:varlink:`RC`, :varlink:`RF`, :varlink:`drC`, :varlink:`drF`),
0882 grid cell areas (:varlink:`rA`, :varlink:`rAw`, :varlink:`rAs`, :varlink:`rAz`),
0883 and bathymetry information (:varlink:`Depth`, :varlink:`HFacC`, :varlink:`HFacW`, :varlink:`HFacS)`.
0884 See :numref:`spatial_discret_dyn_eq` for definitions and description of the C grid staggering of these variables.
0885 There are also grid variables in vector form that are not used in the MITgcm source code
0886 (X, Y, Xp1, Yp1, Z, Zp1, Zu, Zl); see description in ``grid.nc``. The variables named p1 include an additional data point
0887 and are dimensioned +1 larger than the standard array size; for example, ``Xp1`` is the longitude of the gridcell left corner, and
0888 includes an extra data point for the last gridcell's right corner longitude.
0889
0890 - ``state.nc`` - includes snapshots of state variables U, V, W, Temp, S, and Eta
0891 at model times T in seconds (variable iter(T) stores the model iteration corresponding with these model times).
0892 Also included are vector forms of grid variables X, Y, Z, Xp1, Yp1, and Zl.
0893 As mentioned, in model output-by-tile files, e.g., ``state.0000000000.t001.nc``, the iteration number ``0000000000`` is the parameter :varlink:`nIter0` for the model run
0894 (recall, we initialized our model with :varlink:`nIter0` =0).
0895 Snapshots of model state are written for model iterations 0, 25920, 51840, ...
0896 according to our ``data`` file parameter choice :varlink:`dumpFreq` (:varlink:`dumpFreq`/:varlink:`deltaT` = 25920).
0897
0898 - ``surfDiag.nc`` - includes output diagnostics as specified from list 1 in
0899 :ref:`data.diagnostics <baroc_diags_list>`.
0900 Here we specified that list 1 include 2-D diagnostics ``ETAN``, ``TRELAX``, and ``MXLDEPTH``.
0901 Also includes an array of model times corresponding to the end of the time-average period, the iteration
0902 number corresponding to these model times, and vector forms of grid variables which describe these data.
0903 A Z index is included in the output arrays, even though
0904 its dimension is one (given that this list contains only 2-D fields).
0905
0906 - ``dynDiag.nc`` - similar to ``surfDiag.nc`` except this file contains the time-averaged 3-D diagnostics
0907 we specified in list 2 of :ref:`data.diagnostics <baroc_diags_list>`:
0908 ``THETA``, ``PHIHYD``, ``UVEL``, ``VVEL``, ``WVEL``.
0909
ce0d9af5ea Jeff*0910 - ``dynStDiag.nc`` - includes output statistical-dynamical diagnostics as specified in the ``DIAG_STATIS_PARMS`` section of
0911 :filelink:`data.diagnostics <verification/tutorial_baroclinic_gyre/input/data.diagnostics>`. Like ``surfDiag.nc`` it also
0912 includes an array of model times and corresponding iteration numbers for each time-average period end. Output variables are 3-D:
0913 (time, region, depth). In :filelink:`data.diagnostics <verification/tutorial_baroclinic_gyre/input/data.diagnostics>`,
0914 we have not defined any additional regions (and by default only global output is produced, "region 1"). Depth-integrated statistics
0915 are computed (in which case the depth subscript has a range of one element; this is also the case for surface diagnostics such as ``TRELAX``),
0916 but output is also tabulated at each depth for some variables (i.e., the depth subscript will range from 1 to :varlink:`Nr`).
0917
94151a9b18 Jeff*0918 - ``phiHyd.nc``, ``phiHydLow.nc`` - these files contain a snapshot 3-D field of hydrostatic
0919 pressure potential anomaly (:math:`p'/\rho_c`, see :numref:`finding_the_pressure_field`)
0920 and a snapshot 2-D field of bottom hydrostatic pressure potential anomaly, respectively.
0921 These are technically not MITgcm state variables, as they are computed `during` the time step
0922 (normal snapshot state variables are dumped `after` the time step),
0923 ergo they are not included in file ``state.nc``. Like ``state.nc`` output however
0924 these fields are written at interval according to
0925 :varlink:`dumpFreq`, except are not written out at time :varlink:`nIter0` (i.e., have one time
0926 record fewer than ``state.nc``). Also note when writing standard binary output, these filenames begin as ``PH`` and ``PHL`` respectively.
0927
9c8516d9da Jeff*0928 .. _phi_hyd_discussion:
0929
94151a9b18 Jeff*0930 The hydrostatic pressure potential anomaly :math:`\phi'` is computed as follows:
0931
0932 .. math:: \phi' = \frac{1}{\rho_c} \left( \rho_c g \eta + \int_{z}^{0} (\rho - \rho_0) g dz \right)
0933
0934 following :eq:`rho_lineareos`, :eq:`rhoprime_lineareos` and :eq:`baroc_gyre_press`. Note that with the linear free surface approximation,
0935 the contribution of the free surface position :math:`\eta` to :math:`\phi'` involves the constant density :math:`\rho_c`
0936 and not the density anomaly :math:`\rho'`, in contrast with contributions from below :math:`z=0`.
0937
0938 Several additional files are output in standard binary format. These are:
0939
0940 ``RhoRef.data, RhoRef.meta`` - this is a 1-D (k=1...\ :varlink:`Nr`) array of reference density, defined as:
0941
0bad585a21 Navi*0942 .. math:: \rho_{\rm ref}(k) = \rho_0 \big[ 1 - \alpha_{\theta} (\theta_{\rm ref}(k) - \theta_{\rm ref}(1)) \big]
94151a9b18 Jeff*0943
0944 ``PHrefC.data, PHrefC.meta, PHrefF.data, PHrefF.meta`` - these are 1-D (k=1...\ :varlink:`Nr` for PHrefC and
0945 k=1...\ :varlink:`Nr`\ +1 for PHrefF) arrays containing a reference
0946 hydrostatic “pressure potential” :math:`\phi = p/\rho_c` (see :numref:`finding_the_pressure_field`).
0947 Using a linear equation of state, ``PHrefC`` is simply :math:`\frac{\rho_c g |z|}{\rho_c}`,
0948 with output computed at the midpoint of each vertical cell, whereas ``PHrefF``
0949 is computed at the surface and bottom of each vertical cell.
0950 Note that these quantities are not especially useful when using a linear equation of state
0951 (to compute the full hydrostatic pressure potential, one would use ``RhoRef`` and
0952 integrate downward, and add ``phiHyd``, rather than use these fields),
0953 but are of greater utility using a non-linear equation of state.
0954
0955 ``pickup.ckptA.001.001.data``, ``pickup.ckptA.001.001.meta``, ``pickup.0000518400.001.001.data``, ``pickup.0000518400.001.001.meta`` etc. - as
0956 described in detail in :ref:`tutorial Barotropic Gyre <barot_describe_checkp>`,
0957 these are temporary and permanent checkpoint files, output in binary format. Note that separate checkpoint files are written for each model tile.
0958
0959 And finally, because we are using the diagnostics package, upon startup the file ``available_diagnostics.log``
0960 will be generated. This (plain text) file contains a list of all diagnostics available for output in this setup, including a description of each diagnostic and its units,
0961 and the number of levels for which the diagnostic is available (i.e., 2-D or 3-D field). This list of available diagnostics will change based
0962 on what packages are included in the setup. For example, if your setup includes a seaice package, many seaice diagnostics
ce0d9af5ea Jeff*0963 will be listed in ``available_diagnostics.log`` that are not available for the :ref:`tutorial Baroclinic Gyre <tutorial_baroclinic_gyre>` setup.
94151a9b18 Jeff*0964
0965 .. _baroc_mpi:
0966
0967 Running with MPI
0968 ----------------
0969
0970 In the :filelink:`verification/tutorial_baroclinic_gyre/code` directory
0971 there is a alternate file :filelink:`verification/tutorial_baroclinic_gyre/code/SIZE.h_mpi`.
0972 Overwrite :filelink:`verification/tutorial_baroclinic_gyre/code/SIZE.h` with this file
0973 and re-compile the model from scratch (the most simple approach is to create a new build directory ``build_mpi``;
0974 if instead you wanted to re-compile in your existing build directory, you should
0975 ``make CLEAN`` first, which will delete any existing files and dependencies you had created previously):
0976
0977 ::
0978
0979 % ../../../tools/genmake2 -mods ../code -mpi -of=«/PATH/TO/OPTFILE»
0980 % make depend
0981 % make
0982
0983 Note we have added the option ``-mpi`` to the :filelink:`genmake2 <tools/genmake2>` command that generates the makefile.
0984 A successful build requires MPI libraries installed on your system, and you may need to add to your ``$PATH`` environment variable
0985 and/or set environment variable ``$MPI_INC_DIR`` (for more details, see :numref:`build_mpi`). If there is a problem
0986 finding `MPI <https://en.wikipedia.org/wiki/Message_Passing_Interface>`_ libraries, :filelink:`genmake2 <tools/genmake2>` output will complain.
0987
ce0d9af5ea Jeff*0988 Several lines in :filelink:`verification/tutorial_baroclinic_gyre/code/SIZE.h_mpi` are different from the standard version.
94151a9b18 Jeff*0989 First, we change :varlink:`nSx` and :varlink:`nSy` to 1, so that each process integrates the model for a single tile.
0990
0991 .. literalinclude:: ../../../verification/tutorial_baroclinic_gyre/code/SIZE.h_mpi
0992 :start-at: nSx =
0993 :end-at: nSy =
0994 :lineno-match:
0995
0996 Next, we we change :varlink:`nPx` and :varlink:`nPy` so that we use two processes in each dimension, for a total of :math:`2*2 = 4` processes.
0997 Effectively, we have subdivided the model grid into four separate tiles, and the model equations are solved in parallel on four separate processes
0998 (presumably, on a unique physical processor or core). Because of the overlap regions
0999 (i.e., gridpoints along the tile edges are duplicated in two or more tiles), and limitations
1000 in the transfer speed of data between processes, the model will not run 4\ :math:`\times` faster, but should be at least 2-3\ :math:`\times` faster than running
1001 on a single process.
1002
1003 .. literalinclude:: ../../../verification/tutorial_baroclinic_gyre/code/SIZE.h_mpi
1004 :start-at: nPx =
1005 :end-at: nPy =
1006 :lineno-match:
1007
1008 Finally, to run the model (from your run directory), using four processes running in parallel:
1009
1010 ::
1011
1012 % mpirun -np 4 ../build_mpi/mitgcmuv
1013
1014 On some systems the `MPI <https://en.wikipedia.org/wiki/Message_Passing_Interface>`_
1015 run command (and the subsequent command-line option ``-np``) might be something other than ``mpirun``; ask your local system administrator.
1016 When using a large `HPC <https://en.wikipedia.org/wiki/Supercomputer>`_ cluster,
ce0d9af5ea Jeff*1017 prior steps might be required to allocate four processor cores to your job, and/or it might be necessary to
94151a9b18 Jeff*1018 write this command within a batch scheduler script; again, check with your local system documentation or system administrator.
ce0d9af5ea Jeff*1019 If four cores are not available when you execute the above ``mpirun`` command, an error will occur.
1020
1021 When running in parallel, :filelink:`pkg/mnc` output will create separate output subdirectories for each
1022 process, assuming option :varlink:`mnc_use_outdir`
1023 is set to ``TRUE`` (here, by specifying ``-np 4`` four directories will be created, one for each
1024 tile -- ``mnc_test_00001`` through ``mnc_test_00004`` -- the first time
1025 the model is run). The (global) statistical-dynamical diagnostics output file will be written in only the first of these directories.
1026 The ``gluemncbig`` steps outlined :ref:`above <baroc_gluemnc_steps>` remain unchanged (if in doubt, one can always
1027 tell ``gluemncbig`` which specific directories to read,
1028 e.g., in bash ``mnc_test_{0009..0012}`` will grab only directories 0009, 0010, 0011, 0012).
1029 Also note it is no longer necessary to redirect standard output
94151a9b18 Jeff*1030 to a file such as ``output.txt``; rather, separate ``STDOUT.xxxx`` and ``STDERR.xxxx``
1031 files are created by each process, where ``xxxx`` is the process number (starting from ``0000``).
ce0d9af5ea Jeff*1032 Other than some additional `MPI <https://en.wikipedia.org/wiki/Message_Passing_Interface>`_-related information,
1033 the standard output content is similar to that from the single-process run.
94151a9b18 Jeff*1034
1035 .. _baroc_openmp:
1036
1037 Running with OpenMP
1038 -------------------
1039
1040 To run multi-threaded (using shared memory, `OpenMP <https://en.wikipedia.org/wiki/OpenMP>`_),
1041 the original :filelink:`SIZE.h <verification/tutorial_baroclinic_gyre/code/SIZE.h>` file is used.
1042 In our example, for compatibility with MITgcm :ref:`testing protocols <code_testing_protocols>`, we will
1043 run using two separate threads, but the user should feel free to experiment using four threads if their local machine contains four cores.
1044 Like the :ref:`previous section <baroc_mpi>` we must first re-compile the executable from scratch,
1045 using a special command line option (for this configuration, ``-omp``). However it is not necessary to specify
1046 how many threads at compile-time (unlike `MPI <https://en.wikipedia.org/wiki/Message_Passing_Interface>`_, which requires specific processor count
1047 information to be set in :filelink:`SIZE.h <verification/tutorial_baroclinic_gyre/code/SIZE.h>`).
1048 Create and navigate into a new build directory ``build_openmp`` and type:
1049
1050 ::
1051
1052 % ../../../tools/genmake2 -mods ../code -omp -of=«/PATH/TO/OPTFILE»
1053 % make depend
1054 % make
1055
1056 In a run directory, overwrite the contents of :filelink:`eedata <verification/tutorial_baroclinic_gyre/input/eedata>` with file
1057 :filelink:`verification/tutorial_baroclinic_gyre/input/eedata.mth`. The parameter :varlink:`nTy` is changed; we now specify to
1058 use two threads across the :math:`y`-domain. Since our model domain is subdivided into four tiles, each thread will now
1059 integrate two tiles in the :math:`x`-domain. Alternatively, to run a multi-threaded example using four threads, both lines should be set to 2.
1060
1061 .. literalinclude:: ../../../verification/tutorial_baroclinic_gyre/input/eedata.mth
1062 :start-at: nTx=
1063 :end-at: nTy=
1064 :lineno-match:
1065
1066 To run the model, we first need to set two `environment variables <https://en.wikipedia.org/wiki/Environment_variable>`_, before invoking the executable:
1067
1068 ::
1069
1070 % export OMP_STACKSIZE=400M
1071 % export OMP_NUM_THREADS=2
1072 % ../build_openmp/mitgcmuv >output.txt
1073
1074 Your system's `environment variables <https://en.wikipedia.org/wiki/Environment_variable>`_ may differ from above;
1075 see :numref:`running_openmp` and/or ask your system administrator
1076 (also note, above is `bash shell <https://en.wikipedia.org/wiki/Bash_(Unix_shell)>`_ syntax;
1077 different syntax is required for `C shell <https://en.wikipedia.org/wiki/C_shell>`_). The important point to note is that
1078 we must tell the operating system environment how many threads will be used, prior to running the executable.
1079 The total number of threads set in ``OMP_NUM_THREADS`` must match :varlink:`nTx` * :varlink:`nTy` as specified in file ``eedata``.
1080 Moreover, the model domain must be subdivided into sufficient number of tiles in :filelink:`SIZE.h <verification/tutorial_baroclinic_gyre/code/SIZE.h>`
1081 through the choices of :varlink:`nSx` and :varlink:`nSy`: the number of tiles (:varlink:`nSx` * :varlink:`nSy`) must be equal to or greater than the number of threads.
1082 More specifically, :varlink:`nSx` must be equal to or an integer multiple of :varlink:`nTx`, and :varlink:`nSy` must be equal to or an integer multiple of :varlink:`nTy`.
1083
1084 Also note that at this time, :filelink:`pkg/mnc` is automatically disabled for multi-threaded setups, so output
1085 is dumped in standard binary format (i.e., using :filelink:`pkg/msdio`). You will receive a gentle warning message if you run
1086 this multi-threaded setup and keep :varlink:`useMNC` set to ``.TRUE.`` in ``data.pkg``.
1087 The full filenames for grid variables (e.g., ``XC``, ``YC``, etc.), snapshot output (e.g., ``Eta``, ``T``, ``PHL``)
1088 and :filelink:`pkg/diagnostics` output (e.g., ``surfDiag``, ``oceStDiag``, etc.) include a suffix
1089 that contains the time iteration number and tile identification (tile 001 includes ``.001.001`` in the filename,
1090 tile 002 ``.002.001``, tile 003 ``.001.002``, and tile 004 ``.002.002``).
1091 Unfortunately there is no analogous script
1092 to :filelink:`utils/python/MITgcmutils/scripts/gluemncbig` to concatenate raw binary files, but it is relatively straightforward
1093 to do so in matlab (reading in files using :filelink:`utils/matlab/rdmds.m`), or equally simple in python -- or, one could simply set
1094 :varlink:`globalFiles` to ``.TRUE.`` and the model will output global files for you (note, this global option is not available for :filelink:`pkg/mnc` output).
1095 One additional difference between :filelink:`pkg/msdio` and
1096 :filelink:`pkg/mnc` is that :ref:`Diagnostics Per Level Statistics <baroc_stat_diags>` are written in plain text, not binary, with :filelink:`pkg/msdio`.
1097
ce0d9af5ea Jeff*1098 .. _baroclinic_gyre_solution:
1099
94151a9b18 Jeff*1100 Model solution
1101 --------------
1102
1103 In this section, we will examine details of the model solution,
ce0d9af5ea Jeff*1104 using monthly and annual mean time average data provided in diagnostics files ``dynStDiag.nc``, ``dynDiag.nc``, and ``surfDiag.nc``.
1105 See companion :filelink:`matlab <verification/tutorial_baroclinic_gyre/analysis/matlab_plots.m>`
1106 or :filelink:`python <verification/tutorial_baroclinic_gyre/analysis/python_plots.py>`
1107 (or :filelink:`python using xarray <verification/tutorial_baroclinic_gyre/analysis/python_xr_plots.py>`)
1108 script which shows the code to read output `netCDF <http://www.unidata.ucar.edu/software/netcdf>`_ files
1109 and create figures shown in this section.
94151a9b18 Jeff*1110
1111 Our ocean sector model is forced mechanically by wind stress and thermodynamically
1112 though temperature relaxation at the surface. As such,
1113 we expect our solution to not only exhibit wind-driven gyres in the upper layers,
1114 but also include a deep, overturning circulation. Our focus in this section
1115 will be on the former; this component of the solution equilibrates on a time scale of decades,
1116 more or less, whereas the deep cell depends on a slower, diffusive timescale.
1117 We will begin by examining some of our :ref:`Diagnostics Per Level Statistics <baroc_stat_diags>` output, to assess
1118 how close we are to equilibration at different ocean model levels. Recall we've requested
1119 these statistics to be computed monthly.
1120
1121 Load diagnostics ``TRELAX_ave``, ``THETA_lv_avg``, and ``THETA_lv_std`` from file ``dynStDiag.nc``.
1122 In :numref:`baroclinic_gyre_trelax_timeseries`\a
1123 we plot the global model surface mean heat flux (``TRELAX_ave``) as a function of time.
1124 At the beginning of the run,
1125 we observe that the ocean is cooling dramatically; this is mainly because our ocean surface layer is
1126 initialized to a uniform :math:`30^{\circ}` C (as specified :ref:`here <tut_baroc_linear_eos>`), which results in
1127 very strong relaxation initially in the northern portion of ocean model, where the
1128 restoring temperature is just above :math:`0^{\circ}` C.
1129 (As an aside comment, such large initialization shocks are often best avoided
1130 if possible, as they may cause model instability, which
1131 may necessitate smaller time steps at model onset and/or more realistic initial conditions.)
1132 However, this initial burst of cooling quickly diminishes over the first decade
1133 of integration, as the surface layer approaches temperature values close to the specified profile;
1134 see :numref:`baroclinic_gyre_trelax_timeseries`\b
1135 where the mean temperature at surface, thermocline, and abyssal depth are plotted as a function of time.
1136 Note that while the total heat flux shows that the global heat content is slowly decreasing,
1137 even after 100 years, the temperature of the deepest water is slowly warming.
1138 In :numref:`baroclinic_gyre_trelax_timeseries`\c we plot standard deviation of temperature
1139 (by level) over time. Given that each level is initialized at uniform temperature,
1140 initially the standard deviation is zero, but should tend to level off at some non-zero
1141 value over time, as the solution at each depth equilibrates.
1142 Not surprisingly, the largest gradients in temperature exist at the surface, whereas in the
1143 abyss the differences in temperature are quite small.
1144 In summary, we conclude that while the surface appears to approach equilibrium rapidly,
1145 even after 100 years there are changes occurring in deep circulation, presumably related
1146 to the meridional overturning circulation.
1147 We leave it as an exercise to the reader to
1148 integrate the solution further and/or examine and calculate the meridional overturning circulation strength over time.
1149
1150 .. figure:: figs/trelax_theta_timeseries.png
1151 :width: 100%
1152 :align: center
1153 :alt: baroclinic gyre surface heat flux
1154 :name: baroclinic_gyre_trelax_timeseries
1155
ce0d9af5ea Jeff*1156 a\) Surface heat flux due to temperature restoring, negative values indicate heat flux out of the ocean;
1157 b) and c) potential temperature mean and standard deviation by level, respectively.
94151a9b18 Jeff*1158
1159 Next, let's examine the effect of wind stress on the ocean's upper layers.
1160 Given the orientation of the wind stress and its variation over a full sine wave as shown in :numref:`baroclinic_gyre_config`
1161 (crudely mimicking easterlies in the tropics, mid-latitude westerlies, and polar easterlies),
1162 we anticipate a double-gyre solution, with a subtropical gyre and a subpolar gyre.
1163 Let's begin by examining the free surface solution (load diagnostics ``ETAN`` and ``TRELAX`` from file ``surfDiag.nc``).
1164 In :numref:`baroclinic_gyre_trelax_freesurface` we show contours of free surface height
1165 (``ETAN``; this is what we plotted in our :ref:`barotropic gyre tutorial solution <barotropic_gyre_solution>`)
1166 overlaying a 2-D color plot of ``TRELAX``
ce0d9af5ea Jeff*1167 (blue is where heat is released from the ocean, red where heat enters the ocean), averaged over year 100.
94151a9b18 Jeff*1168 Note that a subtropical gyre is readily apparent, as suggested by geostropic currents in balance with
1169 the free surface elevation (not shown, but the reader is encouraged to load diagnostics ``UVEL`` and ``VVEL``
1170 and plot the circulation at various levels). Heat is entering the ocean mainly along the southern boundary,
1171 where upwelling of cold water is occurring, but also along the boundary current between :math:`50^{\circ}`\ N and :math:`65^{\circ}`\ N, where we
1172 would expect southward flow (i.e., advecting water that is colder than the local restoring temperature).
1173 Heat is exiting the ocean where the western boundary current transports warm water northward,
1174 before turning eastward into the basin
1175 at :math:`40^{\circ}`\ N, and also weakly throughout the higher latitude bands,
1176 where deeper mixed layers occur (not shown, but variations in mixed layer
1177 depth can be easily visualized by loading diagnostic ``MXLDEPTH``).
1178
1179 .. figure:: figs/trelax_freesurface.png
ce0d9af5ea Jeff*1180 :width: 80%
94151a9b18 Jeff*1181 :align: center
1182 :alt: baroclinic gyre free surface and relaxation
1183 :name: baroclinic_gyre_trelax_freesurface
1184
ce0d9af5ea Jeff*1185 Contours of free surface height (m) averaged over year 100; shading is surface heat flux due to
1186 temperature restoring (W/m\ :sup:`2`), blue indicating cooling.
94151a9b18 Jeff*1187
0bad585a21 Navi*1188 So what happened to our model solution subpolar gyre? Let's compute depth-integrated velocity :math:`U_{\rm bt}, V_{\rm bt}`
94151a9b18 Jeff*1189 (units: m\ :sup:`2` s\ :sup:`-1`) and use it calculate the barotropic transport streamfunction:
1190
0bad585a21 Navi*1191 .. math:: U_{\rm bt} = - \frac{\partial \Psi}{\partial y}, \phantom{WW} V_{\rm bt} = \frac{\partial \Psi}{\partial x}
94151a9b18 Jeff*1192
0bad585a21 Navi*1193 Compute :math:`U_{\rm bt}` by summing the diagnostic ``UVEL`` multiplied by gridcell depth
94151a9b18 Jeff*1194 (``grid.nc`` variable :varlink:`drF`, i.e.,
1195 the separation between gridcell faces in the vertical). Now do a cumulative sum of
0bad585a21 Navi*1196 :math:`-U_{\rm bt}` times the gridcell spacing the in the :math:`y` direction (you
94151a9b18 Jeff*1197 will need to load ``grid.nc`` variable :varlink:`dyG`, the separation between gridcell faces in :math:`y`).
1198 A plot of the resulting :math:`\Psi` field is shown in :numref:`baroclinic_gyre_psi`.
0bad585a21 Navi*1199 Note one could also cumulative sum :math:`V_{\rm bt}` times the grid spacing in the :math:`x`-direction and obtain a similar result.
94151a9b18 Jeff*1200
1201 .. figure:: figs/baroc_psi.png
ce0d9af5ea Jeff*1202 :width: 80%
94151a9b18 Jeff*1203 :align: center
1204 :alt: baroclinic gyre barotropic streamfunction
1205 :name: baroclinic_gyre_psi
1206
1207 Barotropic streamfunction (Sv) as computed over year 100.
1208
1209 When velocities are integrated over depth, the subpolar gyre is readily apparent,
1210 as might be expected given our wind stress forcing profile. The pattern in :numref:`baroclinic_gyre_psi` in fact resembles
1211 the double-gyre free surface solution we observed in :numref:`baro_jet_solution`
1212 from tutorial :ref:`sec_eg_baro`, when our model grid was only a single layer in the vertical.
1213
1214 Is the magnitude of :math:`\Psi`
1215 we obtain in our solution reasonable? To check this, consider the Sverdrup transport:
1216
0bad585a21 Navi*1217 .. math:: \rho v_{\rm bt} = \hat{\boldsymbol{k}} \cdot \frac{ \nabla \times \vec{\boldsymbol{\tau}}}{\beta}
94151a9b18 Jeff*1218
1219 If we plug in a typical mid-latitude value for :math:`\beta` (:math:`2 \times 10^{-11}` m\ :sup:`-1` s\ :sup:`-1`)
0bad585a21 Navi*1220 and note that :math:`\tau` varies by :math:`0.1` Nm\ :sup:`—2` over :math:`15^{\circ}` latitude,
94151a9b18 Jeff*1221 and multiply by the width of our ocean sector, we obtain an estimate of approximately 20 Sv.
1222 This estimate agrees reasonably well with the strength of the circulation in :numref:`baroclinic_gyre_psi`.
1223
1224 Finally, let's examine the model solution potential temperature field averaged over year 100.
1225 Read in diagnostic ``THETA`` from the file ``dynDiag.nc``. :numref:`baroclinic_gyre_thetaplots`\a shows a plan view of temperature
1226 at 220 m depth (vertical level k=4). :numref:`baroclinic_gyre_thetaplots`\b shows a slice in the :math:`xz` plane at :math:`28.5^{\circ}`\ N
1227 (:math:`y`-dimension j=15), through the center of the subtropical gyre.
1228
1229 .. figure:: figs/baroc_thetaplots.png
1230 :width: 100%
1231 :align: center
1232 :alt: baroclinic gyre plots of theta
1233 :name: baroclinic_gyre_thetaplots
1234
1235 Contour plot of potential temperature at year 100 a) at a depth of 220 m and b) through a section at :math:`28.5^{\circ}`\ N. Contour interval is 2K.
1236
1237 The dynamics of the subtropical gyre are governed by
1238 Ventilated Thermocline Theory (see, for example, Pedlosky (1996) :cite:`pedlosky:96` or
1239 Vallis (2017) :cite:`vallis:17`). Note the presence of warm "mode water" on the western side of the basin;
1240 the contours of the warm water in the southern half of the sector crudely align with the free surface
1241 heights we observed in :numref:`baroclinic_gyre_psi`. In :numref:`baroclinic_gyre_thetaplots`\b note
1242 the presence of a thermocline, i.e., the bunching up of the contours
1243 between 200 m and 400 m depth, with weak stratification below the thermocline.
1244 What sets the penetration depth of the subtropical gyre? Following a simple advective scaling argument
1245 (see Vallis (2017) :cite:`vallis:17` or Cushman-Roisin and Beckers (2011) :cite:`cushmanroisin:11`;
ce0d9af5ea Jeff*1246 this scaling is obtained via thermal wind and the linearized barotropic vorticity equation),
94151a9b18 Jeff*1247 the depth of the thermocline :math:`h` should scale as:
1248
0bad585a21 Navi*1249 .. math:: h = \left( \frac{w_{\rm Ek} f^2 L_x}{\beta \Delta b} \right) ^2 = \left( \frac{(\tau / L_y) f L_x}{\beta \rho'} \right) ^2
94151a9b18 Jeff*1250
0bad585a21 Navi*1251 where :math:`w_{\rm Ek}` is a representive value for Ekman pumping, :math:`\Delta b = g \rho' / \rho_0`
94151a9b18 Jeff*1252 is the variation in buoyancy across the gyre,
1253 and :math:`L_x` and :math:`L_y` are length scales in the
1254 :math:`x` and :math:`y` directions, respectively.
1255 Plugging in applicable values at :math:`30^{\circ}`\ N,
1256 we obtain an estimate for :math:`h` of 200 m, which agrees quite well with that observed in :numref:`baroclinic_gyre_thetaplots`\b.
1257