MOM6
MOM_variables.F90
1 !> Provides transparent structures with groups of MOM6 variables and supporting routines
3 
4 ! This file is part of MOM6. See LICENSE.md for the license.
5 
6 use mom_domains, only : mom_domain_type, get_domain_extent, group_pass_type
7 use mom_debugging, only : hchksum
8 use mom_error_handler, only : mom_error, fatal
9 use mom_grid, only : ocean_grid_type
10 use mom_eos, only : eos_type
11 
12 use coupler_types_mod, only : coupler_1d_bc_type, coupler_2d_bc_type
13 use coupler_types_mod, only : coupler_type_spawn, coupler_type_destructor
14 
15 implicit none ; private
16 
17 #include <MOM_memory.h>
18 
19 public allocate_surface_state, deallocate_surface_state, mom_thermovar_chksum
20 public ocean_grid_type, alloc_bt_cont_type, dealloc_bt_cont_type
21 
22 ! A note on unit descriptions in comments: MOM6 uses units that can be rescaled for dimensional
23 ! consistency testing. These are noted in comments with units like Z, H, L, and T, along with
24 ! their mks counterparts with notation like "a velocity [Z T-1 ~> m s-1]". If the units
25 ! vary with the Boussinesq approximation, the Boussinesq variant is given first.
26 
27 !> A structure for creating arrays of pointers to 3D arrays
28 type, public :: p3d
29  real, dimension(:,:,:), pointer :: p => null() !< A pointer to a 3D array
30 end type p3d
31 !> A structure for creating arrays of pointers to 2D arrays
32 type, public :: p2d
33  real, dimension(:,:), pointer :: p => null() !< A pointer to a 2D array
34 end type p2d
35 
36 !> Pointers to various fields which may be used describe the surface state of MOM, and which
37 !! will be returned to a the calling program
38 type, public :: surface
39  real, allocatable, dimension(:,:) :: &
40  sst, & !< The sea surface temperature [degC].
41  sss, & !< The sea surface salinity [ppt ~> psu or gSalt/kg].
42  sfc_density, & !< The mixed layer density [kg m-3].
43  hml, & !< The mixed layer depth [m].
44  u, & !< The mixed layer zonal velocity [m s-1].
45  v, & !< The mixed layer meridional velocity [m s-1].
46  sea_lev, & !< The sea level [m]. If a reduced surface gravity is
47  !! used, that is compensated for in sea_lev.
48  melt_potential, & !< Instantaneous amount of heat that can be used to melt sea ice [J m-2].
49  !! This is computed w.r.t. surface freezing temperature.
50  ocean_mass, & !< The total mass of the ocean [kg m-2].
51  ocean_heat, & !< The total heat content of the ocean in [degC kg m-2].
52  ocean_salt, & !< The total salt content of the ocean in [kgSalt m-2].
53  salt_deficit !< The salt needed to maintain the ocean column at a minimum
54  !! salinity of 0.01 PSU over the call to step_MOM [kgSalt m-2].
55  logical :: t_is_cont = .false. !< If true, the temperature variable SST is actually the
56  !! conservative temperature in [degC].
57  logical :: s_is_abss = .false. !< If true, the salinity variable SSS is actually the
58  !! absolute salinity in [g/kg].
59  real, pointer, dimension(:,:) :: &
60  taux_shelf => null(), & !< The zonal stresses on the ocean under shelves [Pa].
61  tauy_shelf => null() !< The meridional stresses on the ocean under shelves [Pa].
62  real, pointer, dimension(:,:) :: frazil => null()
63  !< The energy needed to heat the ocean column to the freezing point during the call
64  !! to step_MOM [J m-2].
65  real, pointer, dimension(:,:) :: tempxpme => null()
66  !< The net inflow of water into the ocean times the temperature at which this inflow
67  !! occurs during the call to step_MOM [degC kg m-2]. This should be prescribed in the
68  !! forcing fields, but as it often is not, this is a useful heat budget diagnostic.
69  real, pointer, dimension(:,:) :: internal_heat => null()
70  !< Any internal or geothermal heat sources that are applied to the ocean integrated
71  !! over the call to step_MOM [degC kg m-2].
72  type(coupler_2d_bc_type) :: tr_fields !< A structure that may contain an
73  !! array of named fields describing tracer-related quantities.
74  !### NOTE: ALL OF THE ARRAYS IN TR_FIELDS USE THE COUPLER'S INDEXING CONVENTION AND HAVE NO
75  !### HALOS! THIS IS DONE TO CONFORM TO THE TREATMENT IN MOM4, BUT I DON'T LIKE IT! -RWH
76  logical :: arrays_allocated = .false. !< A flag that indicates whether the surface type
77  !! has had its memory allocated.
78 end type surface
79 
80 !> Pointers to an assortment of thermodynamic fields that may be available, including
81 !! potential temperature, salinity, heat capacity, and the equation of state control structure.
82 type, public :: thermo_var_ptrs
83  ! If allocated, the following variables have nz layers.
84  real, pointer :: t(:,:,:) => null() !< Potential temperature [degC].
85  real, pointer :: s(:,:,:) => null() !< Salnity [PSU] or [gSalt/kg], generically [ppt].
86  type(eos_type), pointer :: eqn_of_state => null() !< Type that indicates the
87  !! equation of state to use.
88  real :: p_ref !< The coordinate-density reference pressure [Pa].
89  !! This is the pressure used to calculate Rml from
90  !! T and S when eqn_of_state is associated.
91  real :: c_p !< The heat capacity of seawater [J degC-1 kg-1].
92  !! When conservative temperature is used, this is
93  !! constant and exactly 3991.86795711963 J degC-1 kg-1.
94  logical :: t_is_cont = .false. !< If true, the temperature variable tv%T is
95  !! actually the conservative temperature [degC].
96  logical :: s_is_abss = .false. !< If true, the salinity variable tv%S is
97  !! actually the absolute salinity in units of [gSalt/kg].
98  real :: min_salinity = 0.01 !< The minimum value of salinity when BOUND_SALINITY=True [ppt].
99  !! The default is 0.01 for backward compatibility but should be 0.
100  ! These arrays are accumulated fluxes for communication with other components.
101  real, dimension(:,:), pointer :: frazil => null()
102  !< The energy needed to heat the ocean column to the
103  !! freezing point since calculate_surface_state was2
104  !! last called [J m-2].
105  real, dimension(:,:), pointer :: salt_deficit => null()
106  !< The salt needed to maintain the ocean column
107  !! at a minimum salinity of MIN_SALINITY since the last time
108  !! that calculate_surface_state was called, [gSalt m-2].
109  real, dimension(:,:), pointer :: tempxpme => null()
110  !< The net inflow of water into the ocean times the
111  !! temperature at which this inflow occurs since the
112  !! last call to calculate_surface_state [degC kg m-2].
113  !! This should be prescribed in the forcing fields, but
114  !! as it often is not, this is a useful heat budget diagnostic.
115  real, dimension(:,:), pointer :: internal_heat => null()
116  !< Any internal or geothermal heat sources that
117  !! have been applied to the ocean since the last call to
118  !! calculate_surface_state [degC kg m-2].
119 end type thermo_var_ptrs
120 
121 !> Pointers to all of the prognostic variables allocated in MOM_variables.F90 and MOM.F90.
122 !!
123 !! It is useful for sending these variables for diagnostics, and in preparation for ensembles
124 !! later on. All variables have the same names as the local (public) variables
125 !! they refer to in MOM.F90.
126 type, public :: ocean_internal_state
127  real, pointer, dimension(:,:,:) :: &
128  t => null(), & !< Pointer to the temperature state variable [degC]
129  s => null(), & !< Pointer to the salinity state variable [ppt ~> PSU or g/kg]
130  u => null(), & !< Pointer to the zonal velocity [m s-1]
131  v => null(), & !< Pointer to the meridional velocity [m s-1]
132  h => null() !< Pointer to the layer thicknesses [H ~> m or kg m-2]
133  real, pointer, dimension(:,:,:) :: &
134  uh => null(), & !< Pointer to zonal transports [H m2 s-1 ~> m3 s-1 or kg s-1]
135  vh => null() !< Pointer to meridional transports [H m2 s-1 ~> m3 s-1 or kg s-1]
136  real, pointer, dimension(:,:,:) :: &
137  cau => null(), & !< Pointer to the zonal Coriolis and Advective acceleration [m s-2]
138  cav => null(), & !< Pointer to the meridional Coriolis and Advective acceleration [m s-2]
139  pfu => null(), & !< Pointer to the zonal Pressure force acceleration [m s-2]
140  pfv => null(), & !< Pointer to the meridional Pressure force acceleration [m s-2]
141  diffu => null(), & !< Pointer to the zonal acceleration due to lateral viscosity [m s-1 T-1 ~> m s-2]
142  diffv => null(), & !< Pointer to the meridional acceleration due to lateral viscosity [m s-1 T-1 ~> m s-2]
143  pbce => null(), & !< Pointer to the baroclinic pressure force dependency on free surface movement
144  !! [m2 s-2 H-1 ~> m s-2 or m4 kg-1 s-2]
145  u_accel_bt => null(), & !< Pointer to the zonal barotropic-solver acceleration [m s-2]
146  v_accel_bt => null() !< Pointer to the meridional barotropic-solver acceleration [m s-2]
147  real, pointer, dimension(:,:,:) :: &
148  u_av => null(), & !< Pointer to zonal velocity averaged over the timestep [m s-1]
149  v_av => null(), & !< Pointer to meridional velocity averaged over the timestep [m s-1]
150  u_prev => null(), & !< Pointer to zonal velocity at the end of the last timestep [m s-1]
151  v_prev => null() !< Pointer to meridional velocity at the end of the last timestep [m s-1]
152 end type ocean_internal_state
153 
154 !> Pointers to arrays with accelerations, which can later be used for derived diagnostics, like energy balances.
155 type, public :: accel_diag_ptrs
156 
157  ! Each of the following fields has nz layers.
158  real, pointer, dimension(:,:,:) :: &
159  diffu => null(), & !< Zonal acceleration due to along isopycnal viscosity [m s-1 T-1 ~> m s-2]
160  diffv => null(), & !< Meridional acceleration due to along isopycnal viscosity [m s-1 T-1 ~> m s-2]
161  cau => null(), & !< Zonal Coriolis and momentum advection accelerations [m s-2]
162  cav => null(), & !< Meridional Coriolis and momentum advection accelerations [m s-2]
163  pfu => null(), & !< Zonal acceleration due to pressure forces [m s-2]
164  pfv => null(), & !< Meridional acceleration due to pressure forces [m s-2]
165  du_dt_visc => null(), &!< Zonal acceleration due to vertical viscosity [m s-2]
166  dv_dt_visc => null(), &!< Meridional acceleration due to vertical viscosity [m s-2]
167  du_dt_dia => null(), & !< Zonal acceleration due to diapycnal mixing [m s-2]
168  dv_dt_dia => null() !< Meridional acceleration due to diapycnal mixing [m s-2]
169  real, pointer, dimension(:,:,:) :: du_other => null()
170  !< Zonal velocity changes due to any other processes that are
171  !! not due to any explicit accelerations [m s-1].
172  real, pointer, dimension(:,:,:) :: dv_other => null()
173  !< Meridional velocity changes due to any other processes that are
174  !! not due to any explicit accelerations [m s-1].
175 
176  ! These accelerations are sub-terms included in the accelerations above.
177  real, pointer :: gradkeu(:,:,:) => null() !< gradKEu = - d/dx(u2) [m s-2]
178  real, pointer :: gradkev(:,:,:) => null() !< gradKEv = - d/dy(u2) [m s-2]
179  real, pointer :: rv_x_v(:,:,:) => null() !< rv_x_v = rv * v at u [m s-2]
180  real, pointer :: rv_x_u(:,:,:) => null() !< rv_x_u = rv * u at v [m s-2]
181 
182 end type accel_diag_ptrs
183 
184 !> Pointers to arrays with transports, which can later be used for derived diagnostics, like energy balances.
185 type, public :: cont_diag_ptrs
186 
187 ! Each of the following fields has nz layers.
188  real, pointer, dimension(:,:,:) :: &
189  uh => null(), & !< Resolved zonal layer thickness fluxes, [H m2 s-1 ~> m3 s-1 or kg s-1]
190  vh => null(), & !< Resolved meridional layer thickness fluxes, [H m2 s-1 ~> m3 s-1 or kg s-1]
191  uhgm => null(), & !< Isopycnal height diffusion induced zonal volume fluxes [H m2 s-1 ~> m3 s-1 or kg s-1]
192  vhgm => null() !< Isopycnal height diffusion induced meridional volume fluxes [H m2 s-1 ~> m3 s-1 or kg s-1]
193 
194 ! Each of the following fields is found at nz+1 interfaces.
195  real, pointer :: diapyc_vel(:,:,:) => null() !< The net diapycnal velocity [H s-1 ~> m s-1 or kg m-2 s-1]
196 
197 end type cont_diag_ptrs
198 
199 !> Vertical viscosities, drag coefficients, and related fields.
200 type, public :: vertvisc_type
201  real :: prandtl_turb !< The Prandtl number for the turbulent diffusion
202  !! that is captured in Kd_shear [nondim].
203  real, pointer, dimension(:,:) :: &
204  bbl_thick_u => null(), & !< The bottom boundary layer thickness at the u-points [Z ~> m].
205  bbl_thick_v => null(), & !< The bottom boundary layer thickness at the v-points [Z ~> m].
206  kv_bbl_u => null(), & !< The bottom boundary layer viscosity at the u-points [Z2 T-1 ~> m2 s-1].
207  kv_bbl_v => null(), & !< The bottom boundary layer viscosity at the v-points [Z2 T-1 ~> m2 s-1].
208  ustar_bbl => null() !< The turbulence velocity in the bottom boundary layer at h points [Z T-1 ~> m s-1].
209  real, pointer, dimension(:,:) :: tke_bbl => null()
210  !< A term related to the bottom boundary layer source of turbulent kinetic
211  !! energy, currently in [Z3 T-3 ~> m3 s-3], but may at some time be changed
212  !! to [kg Z3 m-3 T-3 ~> W m-2].
213  real, pointer, dimension(:,:) :: &
214  taux_shelf => null(), & !< The zonal stresses on the ocean under shelves [Pa].
215  tauy_shelf => null() !< The meridional stresses on the ocean under shelves [Pa].
216  real, pointer, dimension(:,:) :: tbl_thick_shelf_u => null()
217  !< Thickness of the viscous top boundary layer under ice shelves at u-points [Z ~> m].
218  real, pointer, dimension(:,:) :: tbl_thick_shelf_v => null()
219  !< Thickness of the viscous top boundary layer under ice shelves at v-points [Z ~> m].
220  real, pointer, dimension(:,:) :: kv_tbl_shelf_u => null()
221  !< Viscosity in the viscous top boundary layer under ice shelves at u-points [Z2 T-1 ~> m2 s-1].
222  real, pointer, dimension(:,:) :: kv_tbl_shelf_v => null()
223  !< Viscosity in the viscous top boundary layer under ice shelves at v-points [Z2 T-1 ~> m2 s-1].
224  real, pointer, dimension(:,:) :: nkml_visc_u => null()
225  !< The number of layers in the viscous surface mixed layer at u-points [nondim].
226  !! This is not an integer because there may be fractional layers, and it is stored in
227  !! terms of layers, not depth, to facilitate the movement of the viscous boundary layer
228  !! with the flow.
229  real, pointer, dimension(:,:) :: nkml_visc_v => null()
230  !< The number of layers in the viscous surface mixed layer at v-points [nondim].
231  real, pointer, dimension(:,:) :: &
232  mld => null() !< Instantaneous active mixing layer depth [H ~> m or kg m-2].
233  real, pointer, dimension(:,:,:) :: &
234  ray_u => null(), & !< The Rayleigh drag velocity to be applied to each layer at u-points [Z T-1 ~> m s-1].
235  ray_v => null() !< The Rayleigh drag velocity to be applied to each layer at v-points [Z T-1 ~> m s-1].
236  real, pointer, dimension(:,:,:) :: kd_extra_t => null()
237  !< The extra diffusivity of temperature due to double diffusion relative to the
238  !! diffusivity of density [Z2 T-1 ~> m2 s-1].
239  real, pointer, dimension(:,:,:) :: kd_extra_s => null()
240  !< The extra diffusivity of salinity due to double diffusion relative to the
241  !! diffusivity of density [Z2 T-1 ~> m2 s-1].
242  ! One of Kd_extra_T and Kd_extra_S is always 0. Kd_extra_S is positive for salt fingering;
243  ! Kd_extra_T is positive for double diffusive convection. They are only allocated if
244  ! DOUBLE_DIFFUSION is true.
245  real, pointer, dimension(:,:,:) :: kd_shear => null()
246  !< The shear-driven turbulent diapycnal diffusivity at the interfaces between layers
247  !! in tracer columns [Z2 T-1 ~> m2 s-1].
248  real, pointer, dimension(:,:,:) :: kv_shear => null()
249  !< The shear-driven turbulent vertical viscosity at the interfaces between layers
250  !! in tracer columns [Z2 T-1 ~> m2 s-1].
251  real, pointer, dimension(:,:,:) :: kv_shear_bu => null()
252  !< The shear-driven turbulent vertical viscosity at the interfaces between layers in
253  !! corner columns [Z2 T-1 ~> m2 s-1].
254  real, pointer, dimension(:,:,:) :: kv_slow => null()
255  !< The turbulent vertical viscosity component due to "slow" processes (e.g., tidal,
256  !! background, convection etc) [Z2 T-1 ~> m2 s-1].
257  real, pointer, dimension(:,:,:) :: tke_turb => null()
258  !< The turbulent kinetic energy per unit mass at the interfaces [Z2 T-2 ~> m2 s-2].
259  !! This may be at the tracer or corner points
260  logical :: add_kv_slow !< If True, add Kv_slow when calculating the 'coupling coefficient' (a_cpl)
261  !! at the interfaces in find_coupling_coef.
262 end type vertvisc_type
263 
264 !> Container for information about the summed layer transports
265 !! and how they will vary as the barotropic velocity is changed.
266 type, public :: bt_cont_type
267  real, allocatable :: fa_u_ee(:,:) !< The effective open face area for zonal barotropic transport
268  !! drawing from locations far to the east [H L ~> m2 or kg m-1].
269  real, allocatable :: fa_u_e0(:,:) !< The effective open face area for zonal barotropic transport
270  !! drawing from nearby to the east [H L ~> m2 or kg m-1].
271  real, allocatable :: fa_u_w0(:,:) !< The effective open face area for zonal barotropic transport
272  !! drawing from nearby to the west [H L ~> m2 or kg m-1].
273  real, allocatable :: fa_u_ww(:,:) !< The effective open face area for zonal barotropic transport
274  !! drawing from locations far to the west [H L ~> m2 or kg m-1].
275  real, allocatable :: ubt_ww(:,:) !< uBT_WW is the barotropic velocity [L T-1 ~> m s-1], beyond which the marginal
276  !! open face area is FA_u_WW. uBT_WW must be non-negative.
277  real, allocatable :: ubt_ee(:,:) !< uBT_EE is a barotropic velocity [L T-1 ~> m s-1], beyond which the marginal
278  !! open face area is FA_u_EE. uBT_EE must be non-positive.
279  real, allocatable :: fa_v_nn(:,:) !< The effective open face area for meridional barotropic transport
280  !! drawing from locations far to the north [H L ~> m2 or kg m-1].
281  real, allocatable :: fa_v_n0(:,:) !< The effective open face area for meridional barotropic transport
282  !! drawing from nearby to the north [H L ~> m2 or kg m-1].
283  real, allocatable :: fa_v_s0(:,:) !< The effective open face area for meridional barotropic transport
284  !! drawing from nearby to the south [H L ~> m2 or kg m-1].
285  real, allocatable :: fa_v_ss(:,:) !< The effective open face area for meridional barotropic transport
286  !! drawing from locations far to the south [H L ~> m2 or kg m-1].
287  real, allocatable :: vbt_ss(:,:) !< vBT_SS is the barotropic velocity, [L T-1 ~> m s-1], beyond which the marginal
288  !! open face area is FA_v_SS. vBT_SS must be non-negative.
289  real, allocatable :: vbt_nn(:,:) !< vBT_NN is the barotropic velocity, [L T-1 ~> m s-1], beyond which the marginal
290  !! open face area is FA_v_NN. vBT_NN must be non-positive.
291  real, allocatable :: h_u(:,:,:) !< An effective thickness at zonal faces [H ~> m or kg m-2].
292  real, allocatable :: h_v(:,:,:) !< An effective thickness at meridional faces [H ~> m or kg m-2].
293  type(group_pass_type) :: pass_polarity_bt !< Structure for polarity group halo updates
294  type(group_pass_type) :: pass_fa_uv !< Structure for face area group halo updates
295 end type bt_cont_type
296 
297 contains
298 
299 !> Allocates the fields for the surface (return) properties of
300 !! the ocean model. Unused fields are unallocated.
301 subroutine allocate_surface_state(sfc_state, G, use_temperature, do_integrals, &
302  gas_fields_ocn, use_meltpot)
303  type(ocean_grid_type), intent(in) :: g !< ocean grid structure
304  type(surface), intent(inout) :: sfc_state !< ocean surface state type to be allocated.
305  logical, optional, intent(in) :: use_temperature !< If true, allocate the space for thermodynamic variables.
306  logical, optional, intent(in) :: do_integrals !< If true, allocate the space for vertically
307  !! integrated fields.
308  type(coupler_1d_bc_type), &
309  optional, intent(in) :: gas_fields_ocn !< If present, this type describes the ocean
310  !! ocean and surface-ice fields that will participate
311  !! in the calculation of additional gas or other
312  !! tracer fluxes, and can be used to spawn related
313  !! internal variables in the ice model.
314  logical, optional, intent(in) :: use_meltpot !< If true, allocate the space for melt potential
315 
316  ! local variables
317  logical :: use_temp, alloc_integ, use_melt_potential
318  integer :: is, ie, js, je, isd, ied, jsd, jed
319  integer :: isdb, iedb, jsdb, jedb
320 
321  is = g%isc ; ie = g%iec ; js = g%jsc ; je = g%jec
322  isd = g%isd ; ied = g%ied ; jsd = g%jsd ; jed = g%jed
323  isdb = g%isdB ; iedb = g%iedB; jsdb = g%jsdB ; jedb = g%jedB
324 
325  use_temp = .true. ; if (present(use_temperature)) use_temp = use_temperature
326  alloc_integ = .true. ; if (present(do_integrals)) alloc_integ = do_integrals
327  use_melt_potential = .false. ; if (present(use_meltpot)) use_melt_potential = use_meltpot
328 
329  if (sfc_state%arrays_allocated) return
330 
331  if (use_temp) then
332  allocate(sfc_state%SST(isd:ied,jsd:jed)) ; sfc_state%SST(:,:) = 0.0
333  allocate(sfc_state%SSS(isd:ied,jsd:jed)) ; sfc_state%SSS(:,:) = 0.0
334  else
335  allocate(sfc_state%sfc_density(isd:ied,jsd:jed)) ; sfc_state%sfc_density(:,:) = 0.0
336  endif
337  allocate(sfc_state%sea_lev(isd:ied,jsd:jed)) ; sfc_state%sea_lev(:,:) = 0.0
338  allocate(sfc_state%Hml(isd:ied,jsd:jed)) ; sfc_state%Hml(:,:) = 0.0
339  allocate(sfc_state%u(isdb:iedb,jsd:jed)) ; sfc_state%u(:,:) = 0.0
340  allocate(sfc_state%v(isd:ied,jsdb:jedb)) ; sfc_state%v(:,:) = 0.0
341 
342  if (use_melt_potential) then
343  allocate(sfc_state%melt_potential(isd:ied,jsd:jed)) ; sfc_state%melt_potential(:,:) = 0.0
344  endif
345 
346  if (alloc_integ) then
347  ! Allocate structures for the vertically integrated ocean_mass, ocean_heat, and ocean_salt.
348  allocate(sfc_state%ocean_mass(isd:ied,jsd:jed)) ; sfc_state%ocean_mass(:,:) = 0.0
349  if (use_temp) then
350  allocate(sfc_state%ocean_heat(isd:ied,jsd:jed)) ; sfc_state%ocean_heat(:,:) = 0.0
351  allocate(sfc_state%ocean_salt(isd:ied,jsd:jed)) ; sfc_state%ocean_salt(:,:) = 0.0
352  endif
353  allocate(sfc_state%salt_deficit(isd:ied,jsd:jed)) ; sfc_state%salt_deficit(:,:) = 0.0
354  endif
355 
356  if (present(gas_fields_ocn)) &
357  call coupler_type_spawn(gas_fields_ocn, sfc_state%tr_fields, &
358  (/is,is,ie,ie/), (/js,js,je,je/), as_needed=.true.)
359 
360  sfc_state%arrays_allocated = .true.
361 
362 end subroutine allocate_surface_state
363 
364 !> Deallocates the elements of a surface state type.
365 subroutine deallocate_surface_state(sfc_state)
366  type(surface), intent(inout) :: sfc_state !< ocean surface state type to be deallocated here.
367 
368  if (.not.sfc_state%arrays_allocated) return
369 
370  if (allocated(sfc_state%melt_potential)) deallocate(sfc_state%melt_potential)
371  if (allocated(sfc_state%SST)) deallocate(sfc_state%SST)
372  if (allocated(sfc_state%SSS)) deallocate(sfc_state%SSS)
373  if (allocated(sfc_state%sfc_density)) deallocate(sfc_state%sfc_density)
374  if (allocated(sfc_state%sea_lev)) deallocate(sfc_state%sea_lev)
375  if (allocated(sfc_state%Hml)) deallocate(sfc_state%Hml)
376  if (allocated(sfc_state%u)) deallocate(sfc_state%u)
377  if (allocated(sfc_state%v)) deallocate(sfc_state%v)
378  if (allocated(sfc_state%ocean_mass)) deallocate(sfc_state%ocean_mass)
379  if (allocated(sfc_state%ocean_heat)) deallocate(sfc_state%ocean_heat)
380  if (allocated(sfc_state%ocean_salt)) deallocate(sfc_state%ocean_salt)
381  if (allocated(sfc_state%salt_deficit)) deallocate(sfc_state%salt_deficit)
382 
383  call coupler_type_destructor(sfc_state%tr_fields)
384 
385  sfc_state%arrays_allocated = .false.
386 
387 end subroutine deallocate_surface_state
388 
389 !> Allocates the arrays contained within a BT_cont_type and initializes them to 0.
390 subroutine alloc_bt_cont_type(BT_cont, G, alloc_faces)
391  type(bt_cont_type), pointer :: bt_cont !< The BT_cont_type whose elements will be allocated
392  type(ocean_grid_type), intent(in) :: g !< The ocean's grid structure
393  logical, optional, intent(in) :: alloc_faces !< If present and true, allocate
394  !! memory for effective face thicknesses.
395 
396  integer :: isd, ied, jsd, jed, isdb, iedb, jsdb, jedb
397  isd = g%isd ; ied = g%ied ; jsd = g%jsd ; jed = g%jed
398  isdb = g%IsdB ; iedb = g%IedB ; jsdb = g%JsdB ; jedb = g%JedB
399 
400  if (associated(bt_cont)) call mom_error(fatal, &
401  "alloc_BT_cont_type called with an associated BT_cont_type pointer.")
402 
403  allocate(bt_cont)
404  allocate(bt_cont%FA_u_WW(isdb:iedb,jsd:jed)) ; bt_cont%FA_u_WW(:,:) = 0.0
405  allocate(bt_cont%FA_u_W0(isdb:iedb,jsd:jed)) ; bt_cont%FA_u_W0(:,:) = 0.0
406  allocate(bt_cont%FA_u_E0(isdb:iedb,jsd:jed)) ; bt_cont%FA_u_E0(:,:) = 0.0
407  allocate(bt_cont%FA_u_EE(isdb:iedb,jsd:jed)) ; bt_cont%FA_u_EE(:,:) = 0.0
408  allocate(bt_cont%uBT_WW(isdb:iedb,jsd:jed)) ; bt_cont%uBT_WW(:,:) = 0.0
409  allocate(bt_cont%uBT_EE(isdb:iedb,jsd:jed)) ; bt_cont%uBT_EE(:,:) = 0.0
410 
411  allocate(bt_cont%FA_v_SS(isd:ied,jsdb:jedb)) ; bt_cont%FA_v_SS(:,:) = 0.0
412  allocate(bt_cont%FA_v_S0(isd:ied,jsdb:jedb)) ; bt_cont%FA_v_S0(:,:) = 0.0
413  allocate(bt_cont%FA_v_N0(isd:ied,jsdb:jedb)) ; bt_cont%FA_v_N0(:,:) = 0.0
414  allocate(bt_cont%FA_v_NN(isd:ied,jsdb:jedb)) ; bt_cont%FA_v_NN(:,:) = 0.0
415  allocate(bt_cont%vBT_SS(isd:ied,jsdb:jedb)) ; bt_cont%vBT_SS(:,:) = 0.0
416  allocate(bt_cont%vBT_NN(isd:ied,jsdb:jedb)) ; bt_cont%vBT_NN(:,:) = 0.0
417 
418  if (present(alloc_faces)) then ; if (alloc_faces) then
419  allocate(bt_cont%h_u(isdb:iedb,jsd:jed,1:g%ke)) ; bt_cont%h_u(:,:,:) = 0.0
420  allocate(bt_cont%h_v(isd:ied,jsdb:jedb,1:g%ke)) ; bt_cont%h_v(:,:,:) = 0.0
421  endif ; endif
422 
423 end subroutine alloc_bt_cont_type
424 
425 !> Deallocates the arrays contained within a BT_cont_type.
426 subroutine dealloc_bt_cont_type(BT_cont)
427  type(bt_cont_type), pointer :: bt_cont !< The BT_cont_type whose elements will be deallocated.
428 
429  if (.not.associated(bt_cont)) return
430 
431  deallocate(bt_cont%FA_u_WW) ; deallocate(bt_cont%FA_u_W0)
432  deallocate(bt_cont%FA_u_E0) ; deallocate(bt_cont%FA_u_EE)
433  deallocate(bt_cont%uBT_WW) ; deallocate(bt_cont%uBT_EE)
434 
435  deallocate(bt_cont%FA_v_SS) ; deallocate(bt_cont%FA_v_S0)
436  deallocate(bt_cont%FA_v_N0) ; deallocate(bt_cont%FA_v_NN)
437  deallocate(bt_cont%vBT_SS) ; deallocate(bt_cont%vBT_NN)
438 
439  if (allocated(bt_cont%h_u)) deallocate(bt_cont%h_u)
440  if (allocated(bt_cont%h_v)) deallocate(bt_cont%h_v)
441 
442  deallocate(bt_cont)
443 
444 end subroutine dealloc_bt_cont_type
445 
446 !> Diagnostic checksums on various elements of a thermo_var_ptrs type for debugging.
447 subroutine mom_thermovar_chksum(mesg, tv, G)
448  character(len=*), intent(in) :: mesg !< A message that appears in the checksum lines
449  type(thermo_var_ptrs), intent(in) :: tv !< A structure pointing to various thermodynamic variables
450  type(ocean_grid_type), intent(in) :: g !< The ocean's grid structure
451 
452  ! Note that for the chksum calls to be useful for reproducing across PE
453  ! counts, there must be no redundant points, so all variables use is..ie
454  ! and js...je as their extent.
455  if (associated(tv%T)) &
456  call hchksum(tv%T, mesg//" tv%T", g%HI)
457  if (associated(tv%S)) &
458  call hchksum(tv%S, mesg//" tv%S", g%HI)
459  if (associated(tv%frazil)) &
460  call hchksum(tv%frazil, mesg//" tv%frazil", g%HI)
461  if (associated(tv%salt_deficit)) &
462  call hchksum(tv%salt_deficit, mesg//" tv%salt_deficit", g%HI)
463  if (associated(tv%TempxPmE)) &
464  call hchksum(tv%TempxPmE, mesg//" tv%TempxPmE", g%HI)
465 end subroutine mom_thermovar_chksum
466 
467 end module mom_variables
mom_variables::surface
Pointers to various fields which may be used describe the surface state of MOM, and which will be ret...
Definition: MOM_variables.F90:38
mom_variables::thermo_var_ptrs
Pointers to an assortment of thermodynamic fields that may be available, including potential temperat...
Definition: MOM_variables.F90:82
mom_variables::p2d
A structure for creating arrays of pointers to 2D arrays.
Definition: MOM_variables.F90:32
mom_eos
Provides subroutines for quantities specific to the equation of state.
Definition: MOM_EOS.F90:2
mom_variables::bt_cont_type
Container for information about the summed layer transports and how they will vary as the barotropic ...
Definition: MOM_variables.F90:266
mom_eos::eos_type
A control structure for the equation of state.
Definition: MOM_EOS.F90:86
mom_variables::vertvisc_type
Vertical viscosities, drag coefficients, and related fields.
Definition: MOM_variables.F90:200
mom_domains
Describes the decomposed MOM domain and has routines for communications across PEs.
Definition: MOM_domains.F90:2
mom_variables
Provides transparent structures with groups of MOM6 variables and supporting routines.
Definition: MOM_variables.F90:2
mom_variables::cont_diag_ptrs
Pointers to arrays with transports, which can later be used for derived diagnostics,...
Definition: MOM_variables.F90:185
mom_variables::accel_diag_ptrs
Pointers to arrays with accelerations, which can later be used for derived diagnostics,...
Definition: MOM_variables.F90:155
mom_grid
Provides the ocean grid type.
Definition: MOM_grid.F90:2
mom_debugging
Provides checksumming functions for debugging.
Definition: MOM_debugging.F90:7
mom_variables::p3d
A structure for creating arrays of pointers to 3D arrays.
Definition: MOM_variables.F90:28
mom_domains::mom_domain_type
The MOM_domain_type contains information about the domain decompositoin.
Definition: MOM_domains.F90:99
mom_variables::ocean_internal_state
Pointers to all of the prognostic variables allocated in MOM_variables.F90 and MOM....
Definition: MOM_variables.F90:126
mom_error_handler
Routines for error handling and I/O management.
Definition: MOM_error_handler.F90:2
mom_grid::ocean_grid_type
Ocean grid type. See mom_grid for details.
Definition: MOM_grid.F90:25