MOM6
MOM_EOS_Wright.F90
1 !> The equation of state using the Wright 1997 expressions
3 
4 ! This file is part of MOM6. See LICENSE.md for the license.
5 
6 !***********************************************************************
7 !* The subroutines in this file implement the equation of state for *
8 !* sea water using the formulae given by Wright, 1997, J. Atmos. *
9 !* Ocean. Tech., 14, 735-740. Coded by R. Hallberg, 7/00. *
10 !***********************************************************************
11 
12 use mom_hor_index, only : hor_index_type
13 
14 implicit none ; private
15 
16 #include <MOM_memory.h>
17 
18 public calculate_compress_wright, calculate_density_wright, calculate_spec_vol_wright
19 public calculate_density_derivs_wright, calculate_specvol_derivs_wright
21 public int_density_dz_wright, int_spec_vol_dp_wright
22 
23 ! A note on unit descriptions in comments: MOM6 uses units that can be rescaled for dimensional
24 ! consistency testing. These are noted in comments with units like Z, H, L, and T, along with
25 ! their mks counterparts with notation like "a velocity [Z T-1 ~> m s-1]". If the units
26 ! vary with the Boussinesq approximation, the Boussinesq variant is given first.
27 
28 
29 !> Compute the in situ density of sea water (in [kg m-3]), or its anomaly with respect to
30 !! a reference density, from salinity (in psu), potential temperature (in deg C), and pressure [Pa],
31 !! using the expressions from Wright, 1997, J. Atmos. Ocean. Tech., 14, 735-740.
33  module procedure calculate_density_scalar_wright, calculate_density_array_wright
34 end interface calculate_density_wright
35 
36 !> Compute the in situ specific volume of sea water (in [m3 kg-1]), or an anomaly with respect
37 !! to a reference specific volume, from salinity (in psu), potential temperature (in deg C), and
38 !! pressure [Pa], using the expressions from Wright, 1997, J. Atmos. Ocean. Tech., 14, 735-740.
40  module procedure calculate_spec_vol_scalar_wright, calculate_spec_vol_array_wright
41 end interface calculate_spec_vol_wright
42 
43 !> For a given thermodynamic state, return the derivatives of density with temperature and salinity
45  module procedure calculate_density_derivs_scalar_wright, calculate_density_derivs_array_wright
46 end interface
47 
48 !> For a given thermodynamic state, return the second derivatives of density with various combinations
49 !! of temperature, salinity, and pressure
51  module procedure calculate_density_second_derivs_scalar_wright, calculate_density_second_derivs_array_wright
52 end interface
53 
54 !>@{ Parameters in the Wright equation of state
55 !real :: a0, a1, a2, b0, b1, b2, b3, b4, b5, c0, c1, c2, c3, c4, c5
56 ! One of the two following blocks of values should be commented out.
57 ! Following are the values for the full range formula.
58 !
59 !real, parameter :: a0 = 7.133718e-4, a1 = 2.724670e-7, a2 = -1.646582e-7
60 !real, parameter :: b0 = 5.613770e8, b1 = 3.600337e6, b2 = -3.727194e4
61 !real, parameter :: b3 = 1.660557e2, b4 = 6.844158e5, b5 = -8.389457e3
62 !real, parameter :: c0 = 1.609893e5, c1 = 8.427815e2, c2 = -6.931554
63 !real, parameter :: c3 = 3.869318e-2, c4 = -1.664201e2, c5 = -2.765195
64 
65 
66 ! Following are the values for the reduced range formula.
67 real, parameter :: a0 = 7.057924e-4, a1 = 3.480336e-7, a2 = -1.112733e-7 ! a0/a1 ~= 2028 ; a0/a2 ~= -6343
68 real, parameter :: b0 = 5.790749e8, b1 = 3.516535e6, b2 = -4.002714e4 ! b0/b1 ~= 165 ; b0/b4 ~= 974
69 real, parameter :: b3 = 2.084372e2, b4 = 5.944068e5, b5 = -9.643486e3
70 real, parameter :: c0 = 1.704853e5, c1 = 7.904722e2, c2 = -7.984422 ! c0/c1 ~= 216 ; c0/c4 ~= -740
71 real, parameter :: c3 = 5.140652e-2, c4 = -2.302158e2, c5 = -3.079464
72 !>@}
73 
74 contains
75 
76 !> This subroutine computes the in situ density of sea water (rho in
77 !! [kg m-3]) from salinity (S [PSU]), potential temperature
78 !! (T [degC]), and pressure [Pa]. It uses the expression from
79 !! Wright, 1997, J. Atmos. Ocean. Tech., 14, 735-740.
80 subroutine calculate_density_scalar_wright(T, S, pressure, rho, rho_ref)
81  real, intent(in) :: T !< Potential temperature relative to the surface [degC].
82  real, intent(in) :: S !< Salinity [PSU].
83  real, intent(in) :: pressure !< pressure [Pa].
84  real, intent(out) :: rho !< In situ density [kg m-3].
85  real, optional, intent(in) :: rho_ref !< A reference density [kg m-3].
86 
87 ! *====================================================================*
88 ! * This subroutine computes the in situ density of sea water (rho in *
89 ! * [kg m-3]) from salinity (S [PSU]), potential temperature *
90 ! * (T [degC]), and pressure [Pa]. It uses the expression from *
91 ! * Wright, 1997, J. Atmos. Ocean. Tech., 14, 735-740. *
92 ! * Coded by R. Hallberg, 7/00 *
93 ! *====================================================================*
94 
95  real, dimension(1) :: T0, S0, pressure0, rho0
96 
97  t0(1) = t
98  s0(1) = s
99  pressure0(1) = pressure
100 
101  call calculate_density_array_wright(t0, s0, pressure0, rho0, 1, 1, rho_ref)
102  rho = rho0(1)
103 
104 end subroutine calculate_density_scalar_wright
105 
106 !> This subroutine computes the in situ density of sea water (rho in
107 !! [kg m-3]) from salinity (S [PSU]), potential temperature
108 !! (T [degC]), and pressure [Pa]. It uses the expression from
109 !! Wright, 1997, J. Atmos. Ocean. Tech., 14, 735-740.
110 subroutine calculate_density_array_wright(T, S, pressure, rho, start, npts, rho_ref)
111  real, dimension(:), intent(in) :: T !< potential temperature relative to the surface [degC].
112  real, dimension(:), intent(in) :: S !< salinity [PSU].
113  real, dimension(:), intent(in) :: pressure !< pressure [Pa].
114  real, dimension(:), intent(inout) :: rho !< in situ density [kg m-3].
115  integer, intent(in) :: start !< the starting point in the arrays.
116  integer, intent(in) :: npts !< the number of values to calculate.
117  real, optional, intent(in) :: rho_ref !< A reference density [kg m-3].
118 
119  ! Original coded by R. Hallberg, 7/00, anomaly coded in 3/18.
120  ! Local variables
121  real :: al0, p0, lambda
122  real :: al_TS, p_TSp, lam_TS, pa_000
123  integer :: j
124 
125  if (present(rho_ref)) pa_000 = (b0*(1.0 - a0*rho_ref) - rho_ref*c0)
126  if (present(rho_ref)) then ; do j=start,start+npts-1
127  al_ts = a1*t(j) +a2*s(j)
128  al0 = a0 + al_ts
129  p_tsp = pressure(j) + (b4*s(j) + t(j) * (b1 + (t(j)*(b2 + b3*t(j)) + b5*s(j))))
130  lam_ts = c4*s(j) + t(j) * (c1 + (t(j)*(c2 + c3*t(j)) + c5*s(j)))
131 
132  ! The following two expressions are mathematically equivalent.
133  ! rho(j) = (b0 + p0_TSp) / ((c0 + lam_TS) + al0*(b0 + p0_TSp)) - rho_ref
134  rho(j) = (pa_000 + (p_tsp - rho_ref*(p_tsp*al0 + (b0*al_ts + lam_ts)))) / &
135  ( (c0 + lam_ts) + al0*(b0 + p_tsp) )
136  enddo ; else ; do j=start,start+npts-1
137  al0 = (a0 + a1*t(j)) +a2*s(j)
138  p0 = (b0 + b4*s(j)) + t(j) * (b1 + t(j)*(b2 + b3*t(j)) + b5*s(j))
139  lambda = (c0 +c4*s(j)) + t(j) * (c1 + t(j)*(c2 + c3*t(j)) + c5*s(j))
140  rho(j) = (pressure(j) + p0) / (lambda + al0*(pressure(j) + p0))
141  enddo ; endif
142 
143 end subroutine calculate_density_array_wright
144 
145 !> This subroutine computes the in situ specific volume of sea water (specvol in
146 !! [m3 kg-1]) from salinity (S [PSU]), potential temperature (T [degC])
147 !! and pressure [Pa]. It uses the expression from
148 !! Wright, 1997, J. Atmos. Ocean. Tech., 14, 735-740.
149 !! If spv_ref is present, specvol is an anomaly from spv_ref.
150 subroutine calculate_spec_vol_scalar_wright(T, S, pressure, specvol, spv_ref)
151  real, intent(in) :: T !< potential temperature relative to the surface [degC].
152  real, intent(in) :: S !< salinity [PSU].
153  real, intent(in) :: pressure !< pressure [Pa].
154  real, intent(out) :: specvol !< in situ specific volume [m3 kg-1].
155  real, optional, intent(in) :: spv_ref !< A reference specific volume [m3 kg-1].
156 
157  ! Local variables
158  real, dimension(1) :: T0, S0, pressure0, spv0
159 
160  t0(1) = t ; s0(1) = s ; pressure0(1) = pressure
161 
162  call calculate_spec_vol_array_wright(t0, s0, pressure0, spv0, 1, 1, spv_ref)
163  specvol = spv0(1)
164 end subroutine calculate_spec_vol_scalar_wright
165 
166 !> This subroutine computes the in situ specific volume of sea water (specvol in
167 !! [m3 kg-1]) from salinity (S [PSU]), potential temperature (T [degC])
168 !! and pressure [Pa]. It uses the expression from
169 !! Wright, 1997, J. Atmos. Ocean. Tech., 14, 735-740.
170 !! If spv_ref is present, specvol is an anomaly from spv_ref.
171 subroutine calculate_spec_vol_array_wright(T, S, pressure, specvol, start, npts, spv_ref)
172  real, dimension(:), intent(in) :: T !< potential temperature relative to the
173  !! surface [degC].
174  real, dimension(:), intent(in) :: S !< salinity [PSU].
175  real, dimension(:), intent(in) :: pressure !< pressure [Pa].
176  real, dimension(:), intent(inout) :: specvol !< in situ specific volume [m3 kg-1].
177  integer, intent(in) :: start !< the starting point in the arrays.
178  integer, intent(in) :: npts !< the number of values to calculate.
179  real, optional, intent(in) :: spv_ref !< A reference specific volume [m3 kg-1].
180 
181  ! Local variables
182  real :: al0, p0, lambda
183  integer :: j
184 
185  do j=start,start+npts-1
186  al0 = (a0 + a1*t(j)) +a2*s(j)
187  p0 = (b0 + b4*s(j)) + t(j) * (b1 + t(j)*((b2 + b3*t(j))) + b5*s(j))
188  lambda = (c0 +c4*s(j)) + t(j) * (c1 + t(j)*((c2 + c3*t(j))) + c5*s(j))
189 
190  if (present(spv_ref)) then
191  specvol(j) = (lambda + (al0 - spv_ref)*(pressure(j) + p0)) / (pressure(j) + p0)
192  else
193  specvol(j) = (lambda + al0*(pressure(j) + p0)) / (pressure(j) + p0)
194  endif
195  enddo
196 end subroutine calculate_spec_vol_array_wright
197 
198 !> For a given thermodynamic state, return the thermal/haline expansion coefficients
199 subroutine calculate_density_derivs_array_wright(T, S, pressure, drho_dT, drho_dS, start, npts)
200  real, intent(in), dimension(:) :: T !< Potential temperature relative to the
201  !! surface [degC].
202  real, intent(in), dimension(:) :: S !< Salinity [PSU].
203  real, intent(in), dimension(:) :: pressure !< pressure [Pa].
204  real, intent(inout), dimension(:) :: drho_dT !< The partial derivative of density with potential
205  !! temperature [kg m-3 degC-1].
206  real, intent(inout), dimension(:) :: drho_dS !< The partial derivative of density with salinity,
207  !! in [kg m-3 PSU-1].
208  integer, intent(in) :: start !< The starting point in the arrays.
209  integer, intent(in) :: npts !< The number of values to calculate.
210 
211  ! Local variables
212  real :: al0, p0, lambda, I_denom2
213  integer :: j
214 
215  do j=start,start+npts-1
216  al0 = (a0 + a1*t(j)) + a2*s(j)
217  p0 = (b0 + b4*s(j)) + t(j) * (b1 + t(j)*((b2 + b3*t(j))) + b5*s(j))
218  lambda = (c0 +c4*s(j)) + t(j) * (c1 + t(j)*((c2 + c3*t(j))) + c5*s(j))
219 
220  i_denom2 = 1.0 / (lambda + al0*(pressure(j) + p0))
221  i_denom2 = i_denom2 *i_denom2
222  drho_dt(j) = i_denom2 * &
223  (lambda* (b1 + t(j)*(2.0*b2 + 3.0*b3*t(j)) + b5*s(j)) - &
224  (pressure(j)+p0) * ( (pressure(j)+p0)*a1 + &
225  (c1 + t(j)*(c2*2.0 + c3*3.0*t(j)) + c5*s(j)) ))
226  drho_ds(j) = i_denom2 * (lambda* (b4 + b5*t(j)) - &
227  (pressure(j)+p0) * ( (pressure(j)+p0)*a2 + (c4 + c5*t(j)) ))
228  enddo
229 
230 end subroutine calculate_density_derivs_array_wright
231 
232 !> The scalar version of calculate_density_derivs which promotes scalar inputs to a 1-element array and then
233 !! demotes the output back to a scalar
234 subroutine calculate_density_derivs_scalar_wright(T, S, pressure, drho_dT, drho_dS)
235  real, intent(in) :: T !< Potential temperature relative to the surface [degC].
236  real, intent(in) :: S !< Salinity [PSU].
237  real, intent(in) :: pressure !< pressure [Pa].
238  real, intent(out) :: drho_dT !< The partial derivative of density with potential
239  !! temperature [kg m-3 degC-1].
240  real, intent(out) :: drho_dS !< The partial derivative of density with salinity,
241  !! in [kg m-3 PSU-1].
242 
243  ! Local variables needed to promote the input/output scalars to 1-element arrays
244  real, dimension(1) :: T0, S0, P0
245  real, dimension(1) :: drdt0, drds0
246 
247  t0(1) = t
248  s0(1) = s
249  p0(1) = pressure
250  call calculate_density_derivs_array_wright(t0, s0, p0, drdt0, drds0, 1, 1)
251  drho_dt = drdt0(1)
252  drho_ds = drds0(1)
253 
254 end subroutine calculate_density_derivs_scalar_wright
255 
256 !> Second derivatives of density with respect to temperature, salinity, and pressure
257 subroutine calculate_density_second_derivs_array_wright(T, S, P, drho_ds_ds, drho_ds_dt, drho_dt_dt, &
258  drho_ds_dp, drho_dt_dp, start, npts)
259  real, dimension(:), intent(in ) :: T !< Potential temperature referenced to 0 dbar [degC]
260  real, dimension(:), intent(in ) :: S !< Salinity [PSU]
261  real, dimension(:), intent(in ) :: P !< Pressure [Pa]
262  real, dimension(:), intent(inout) :: drho_ds_ds !< Partial derivative of beta with respect
263  !! to S [kg m-3 PSU-2]
264  real, dimension(:), intent(inout) :: drho_ds_dt !< Partial derivative of beta with respcct
265  !! to T [kg m-3 PSU-1 degC-1]
266  real, dimension(:), intent(inout) :: drho_dt_dt !< Partial derivative of alpha with respect
267  !! to T [kg m-3 degC-2]
268  real, dimension(:), intent(inout) :: drho_ds_dp !< Partial derivative of beta with respect
269  !! to pressure [kg m-3 PSU-1 Pa-1]
270  real, dimension(:), intent(inout) :: drho_dt_dp !< Partial derivative of alpha with respect
271  !! to pressure [kg m-3 degC-1 Pa-1]
272  integer, intent(in ) :: start !< Starting index in T,S,P
273  integer, intent(in ) :: npts !< Number of points to loop over
274 
275  ! Local variables
276  real :: z0, z1, z2, z3, z4, z5, z6 ,z7, z8, z9, z10, z11, z2_2, z2_3
277  integer :: j
278  ! Based on the above expression with common terms factored, there probably exists a more numerically stable
279  ! and/or efficient expression
280 
281  do j = start,start+npts-1
282  z0 = t(j)*(b1 + b5*s(j) + t(j)*(b2 + b3*t(j)))
283  z1 = (b0 + p(j) + b4*s(j) + z0)
284  z3 = (b1 + b5*s(j) + t(j)*(2.*b2 + 2.*b3*t(j)))
285  z4 = (c0 + c4*s(j) + t(j)*(c1 + c5*s(j) + t(j)*(c2 + c3*t(j))))
286  z5 = (b1 + b5*s(j) + t(j)*(b2 + b3*t(j)) + t(j)*(b2 + 2.*b3*t(j)))
287  z6 = c1 + c5*s(j) + t(j)*(c2 + c3*t(j)) + t(j)*(c2 + 2.*c3*t(j))
288  z7 = (c4 + c5*t(j) + a2*z1)
289  z8 = (c1 + c5*s(j) + t(j)*(2.*c2 + 3.*c3*t(j)) + a1*z1)
290  z9 = (a0 + a2*s(j) + a1*t(j))
291  z10 = (b4 + b5*t(j))
292  z11 = (z10*z4 - z1*z7)
293  z2 = (c0 + c4*s(j) + t(j)*(c1 + c5*s(j) + t(j)*(c2 + c3*t(j))) + z9*z1)
294  z2_2 = z2*z2
295  z2_3 = z2_2*z2
296 
297  drho_ds_ds(j) = (z10*(c4 + c5*t(j)) - a2*z10*z1 - z10*z7)/z2_2 - (2.*(c4 + c5*t(j) + z9*z10 + a2*z1)*z11)/z2_3
298  drho_ds_dt(j) = (z10*z6 - z1*(c5 + a2*z5) + b5*z4 - z5*z7)/z2_2 - (2.*(z6 + z9*z5 + a1*z1)*z11)/z2_3
299  drho_dt_dt(j) = (z3*z6 - z1*(2.*c2 + 6.*c3*t(j) + a1*z5) + (2.*b2 + 4.*b3*t(j))*z4 - z5*z8)/z2_2 - &
300  (2.*(z6 + z9*z5 + a1*z1)*(z3*z4 - z1*z8))/z2_3
301  drho_ds_dp(j) = (-c4 - c5*t(j) - 2.*a2*z1)/z2_2 - (2.*z9*z11)/z2_3
302  drho_dt_dp(j) = (-c1 - c5*s(j) - t(j)*(2.*c2 + 3.*c3*t(j)) - 2.*a1*z1)/z2_2 - (2.*z9*(z3*z4 - z1*z8))/z2_3
303  enddo
304 
305 end subroutine calculate_density_second_derivs_array_wright
306 
307 !> Second derivatives of density with respect to temperature, salinity, and pressure for scalar inputs. Inputs
308 !! promoted to 1-element array and output demoted to scalar
309 subroutine calculate_density_second_derivs_scalar_wright(T, S, P, drho_ds_ds, drho_ds_dt, drho_dt_dt, &
310  drho_ds_dp, drho_dt_dp)
311  real, intent(in ) :: T !< Potential temperature referenced to 0 dbar
312  real, intent(in ) :: S !< Salinity [PSU]
313  real, intent(in ) :: P !< pressure [Pa]
314  real, intent( out) :: drho_ds_ds !< Partial derivative of beta with respect
315  !! to S [kg m-3 PSU-2]
316  real, intent( out) :: drho_ds_dt !< Partial derivative of beta with respcct
317  !! to T [kg m-3 PSU-1 degC-1]
318  real, intent( out) :: drho_dt_dt !< Partial derivative of alpha with respect
319  !! to T [kg m-3 degC-2]
320  real, intent( out) :: drho_ds_dp !< Partial derivative of beta with respect
321  !! to pressure [kg m-3 PSU-1 Pa-1]
322  real, intent( out) :: drho_dt_dp !< Partial derivative of alpha with respect
323  !! to pressure [kg m-3 degC-1 Pa-1]
324  ! Local variables
325  real, dimension(1) :: T0, S0, P0
326  real, dimension(1) :: drdsds, drdsdt, drdtdt, drdsdp, drdtdp
327 
328  t0(1) = t
329  s0(1) = s
330  p0(1) = p
331  call calculate_density_second_derivs_array_wright(t0, s0, p0, drdsds, drdsdt, drdtdt, drdsdp, drdtdp, 1, 1)
332  drho_ds_ds = drdsds(1)
333  drho_ds_dt = drdsdt(1)
334  drho_dt_dt = drdtdt(1)
335  drho_ds_dp = drdsdp(1)
336  drho_dt_dp = drdtdp(1)
337 
338 end subroutine calculate_density_second_derivs_scalar_wright
339 
340 !> For a given thermodynamic state, return the partial derivatives of specific volume
341 !! with temperature and salinity
342 subroutine calculate_specvol_derivs_wright(T, S, pressure, dSV_dT, dSV_dS, start, npts)
343  real, intent(in), dimension(:) :: t !< Potential temperature relative to the surface [degC].
344  real, intent(in), dimension(:) :: s !< Salinity [PSU].
345  real, intent(in), dimension(:) :: pressure !< pressure [Pa].
346  real, intent(inout), dimension(:) :: dsv_dt !< The partial derivative of specific volume with
347  !! potential temperature [m3 kg-1 degC-1].
348  real, intent(inout), dimension(:) :: dsv_ds !< The partial derivative of specific volume with
349  !! salinity [m3 kg-1 / Pa].
350  integer, intent(in) :: start !< The starting point in the arrays.
351  integer, intent(in) :: npts !< The number of values to calculate.
352 
353  ! Local variables
354  real :: al0, p0, lambda, i_denom
355  integer :: j
356 
357  do j=start,start+npts-1
358 ! al0 = (a0 + a1*T(j)) + a2*S(j)
359  p0 = (b0 + b4*s(j)) + t(j) * (b1 + t(j)*((b2 + b3*t(j))) + b5*s(j))
360  lambda = (c0 +c4*s(j)) + t(j) * (c1 + t(j)*((c2 + c3*t(j))) + c5*s(j))
361 
362  ! SV = al0 + lambda / (pressure(j) + p0)
363 
364  i_denom = 1.0 / (pressure(j) + p0)
365  dsv_dt(j) = (a1 + i_denom * (c1 + t(j)*((2.0*c2 + 3.0*c3*t(j))) + c5*s(j))) - &
366  (i_denom**2 * lambda) * (b1 + t(j)*((2.0*b2 + 3.0*b3*t(j))) + b5*s(j))
367  dsv_ds(j) = (a2 + i_denom * (c4 + c5*t(j))) - &
368  (i_denom**2 * lambda) * (b4 + b5*t(j))
369  enddo
370 
371 end subroutine calculate_specvol_derivs_wright
372 
373 !> This subroutine computes the in situ density of sea water (rho in
374 !! [kg m-3]) and the compressibility (drho/dp = C_sound^-2)
375 !! (drho_dp [s2 m-2]) from salinity (sal in psu), potential
376 !! temperature (T [degC]), and pressure [Pa]. It uses the expressions
377 !! from Wright, 1997, J. Atmos. Ocean. Tech., 14, 735-740.
378 !! Coded by R. Hallberg, 1/01
379 subroutine calculate_compress_wright(T, S, pressure, rho, drho_dp, start, npts)
380  real, intent(in), dimension(:) :: t !< Potential temperature relative to the surface [degC].
381  real, intent(in), dimension(:) :: s !< Salinity [PSU].
382  real, intent(in), dimension(:) :: pressure !< pressure [Pa].
383  real, intent(inout), dimension(:) :: rho !< In situ density [kg m-3].
384  real, intent(inout), dimension(:) :: drho_dp !< The partial derivative of density with pressure
385  !! (also the inverse of the square of sound speed)
386  !! [s2 m-2].
387  integer, intent(in) :: start !< The starting point in the arrays.
388  integer, intent(in) :: npts !< The number of values to calculate.
389 
390  ! Coded by R. Hallberg, 1/01
391  ! Local variables
392  real :: al0, p0, lambda, i_denom
393  integer :: j
394 
395  do j=start,start+npts-1
396  al0 = (a0 + a1*t(j)) +a2*s(j)
397  p0 = (b0 + b4*s(j)) + t(j) * (b1 + t(j)*((b2 + b3*t(j))) + b5*s(j))
398  lambda = (c0 +c4*s(j)) + t(j) * (c1 + t(j)*((c2 + c3*t(j))) + c5*s(j))
399 
400  i_denom = 1.0 / (lambda + al0*(pressure(j) + p0))
401  rho(j) = (pressure(j) + p0) * i_denom
402  drho_dp(j) = lambda * i_denom * i_denom
403  enddo
404 end subroutine calculate_compress_wright
405 
406 !> This subroutine calculates analytical and nearly-analytical integrals of
407 !! pressure anomalies across layers, which are required for calculating the
408 !! finite-volume form pressure accelerations in a Boussinesq model.
409 subroutine int_density_dz_wright(T, S, z_t, z_b, rho_ref, rho_0, G_e, HI, &
410  dpa, intz_dpa, intx_dpa, inty_dpa, &
411  bathyT, dz_neglect, useMassWghtInterp, rho_scale, pres_scale)
412  type(hor_index_type), intent(in) :: hi !< The horizontal index type for the arrays.
413  real, dimension(HI%isd:HI%ied,HI%jsd:HI%jed), &
414  intent(in) :: t !< Potential temperature relative to the surface
415  !! [degC].
416  real, dimension(HI%isd:HI%ied,HI%jsd:HI%jed), &
417  intent(in) :: s !< Salinity [PSU].
418  real, dimension(HI%isd:HI%ied,HI%jsd:HI%jed), &
419  intent(in) :: z_t !< Height at the top of the layer in depth units [Z ~> m].
420  real, dimension(HI%isd:HI%ied,HI%jsd:HI%jed), &
421  intent(in) :: z_b !< Height at the top of the layer [Z ~> m].
422  real, intent(in) :: rho_ref !< A mean density [R ~> kg m-3] or [kg m-3], that is subtracted
423  !! out to reduce the magnitude of each of the integrals.
424  !! (The pressure is calucated as p~=-z*rho_0*G_e.)
425  real, intent(in) :: rho_0 !< Density [R ~> kg m-3] or [kg m-3], that is used
426  !! to calculate the pressure (as p~=-z*rho_0*G_e)
427  !! used in the equation of state.
428  real, intent(in) :: g_e !< The Earth's gravitational acceleration
429  !! [L2 Z-1 T-2 ~> m s-2] or [m2 Z-1 s-2 ~> m s-2].
430  real, dimension(HI%isd:HI%ied,HI%jsd:HI%jed), &
431  intent(inout) :: dpa !< The change in the pressure anomaly across the
432  !! layer [R L2 T-2 ~> Pa] or [Pa].
433  real, dimension(HI%isd:HI%ied,HI%jsd:HI%jed), &
434  optional, intent(inout) :: intz_dpa !< The integral through the thickness of the layer
435  !! of the pressure anomaly relative to the anomaly
436  !! at the top of the layer [R Z L2 T-2 ~> Pa m].
437  real, dimension(HI%IsdB:HI%IedB,HI%jsd:HI%jed), &
438  optional, intent(inout) :: intx_dpa !< The integral in x of the difference between the
439  !! pressure anomaly at the top and bottom of the
440  !! layer divided by the x grid spacing [R L2 T-2 ~> Pa].
441  real, dimension(HI%isd:HI%ied,HI%JsdB:HI%JedB), &
442  optional, intent(inout) :: inty_dpa !< The integral in y of the difference between the
443  !! pressure anomaly at the top and bottom of the
444  !! layer divided by the y grid spacing [R L2 T-2 ~> Pa].
445  real, dimension(HI%isd:HI%ied,HI%jsd:HI%jed), &
446  optional, intent(in) :: bathyt !< The depth of the bathymetry [Z ~> m].
447  real, optional, intent(in) :: dz_neglect !< A miniscule thickness change [Z ~> m].
448  logical, optional, intent(in) :: usemasswghtinterp !< If true, uses mass weighting to
449  !! interpolate T/S for top and bottom integrals.
450  real, optional, intent(in) :: rho_scale !< A multiplicative factor by which to scale density
451  !! from kg m-3 to the desired units [R m3 kg-1 ~> 1]
452  real, optional, intent(in) :: pres_scale !< A multiplicative factor to convert pressure
453  !! into Pa [Pa T2 R-1 L-2 ~> 1].
454 
455  ! Local variables
456  real, dimension(HI%isd:HI%ied,HI%jsd:HI%jed) :: al0_2d, p0_2d, lambda_2d
457  real :: al0, p0, lambda
458  real :: rho_anom ! The density anomaly from rho_ref [kg m-3].
459  real :: eps, eps2, rem
460  real :: gxrho ! The gravitational acceleration times density and unit conversion factors [Pa Z-1 ~> kg m-2 s-2]
461  real :: g_earth ! The gravitational acceleration [m2 Z-1 s-2 ~> m s-2]
462  real :: i_rho ! The inverse of the Boussinesq density [m3 kg-1]
463  real :: rho_ref_mks ! The reference density in MKS units, never rescaled from kg m-3 [kg m-3]
464  real :: p_ave, i_al0, i_lzz
465  real :: dz ! The layer thickness [Z ~> m].
466  real :: hwght ! A pressure-thickness below topography [Z ~> m].
467  real :: hl, hr ! Pressure-thicknesses of the columns to the left and right [Z ~> m].
468  real :: idenom ! The inverse of the denominator in the weights [Z-2 ~> m-2].
469  real :: hwt_ll, hwt_lr ! hWt_LA is the weighted influence of A on the left column [nondim].
470  real :: hwt_rl, hwt_rr ! hWt_RA is the weighted influence of A on the right column [nondim].
471  real :: wt_l, wt_r ! The linear weights of the left and right columns [nondim].
472  real :: wtt_l, wtt_r ! The weights for tracers from the left and right columns [nondim].
473  real :: intz(5) ! The integrals of density with height at the
474  ! 5 sub-column locations [R L2 T-2 ~> Pa].
475  real :: pa_to_rl2_t2 ! A conversion factor of pressures from Pa to the output units indicated by
476  ! pres_scale [R L2 T-2 Pa-1 ~> 1] or [1].
477  logical :: do_massweight ! Indicates whether to do mass weighting.
478  real, parameter :: c1_3 = 1.0/3.0, c1_7 = 1.0/7.0 ! Rational constants.
479  real, parameter :: c1_9 = 1.0/9.0, c1_90 = 1.0/90.0 ! Rational constants.
480  integer :: is, ie, js, je, isq, ieq, jsq, jeq, i, j, m
481 
482  ! These array bounds work for the indexing convention of the input arrays, but
483  ! on the computational domain defined for the output arrays.
484  isq = hi%IscB ; ieq = hi%IecB
485  jsq = hi%JscB ; jeq = hi%JecB
486  is = hi%isc ; ie = hi%iec
487  js = hi%jsc ; je = hi%jec
488 
489  if (present(pres_scale)) then
490  gxrho = pres_scale * g_e * rho_0 ; g_earth = pres_scale * g_e
491  pa_to_rl2_t2 = 1.0 / pres_scale
492  else
493  gxrho = g_e * rho_0 ; g_earth = g_e
494  pa_to_rl2_t2 = 1.0
495  endif
496  if (present(rho_scale)) then
497  g_earth = g_earth * rho_scale
498  rho_ref_mks = rho_ref / rho_scale ; i_rho = rho_scale / rho_0
499  else
500  rho_ref_mks = rho_ref ; i_rho = 1.0 / rho_0
501  endif
502 
503  do_massweight = .false.
504  if (present(usemasswghtinterp)) then ; if (usemasswghtinterp) then
505  do_massweight = .true.
506  ! if (.not.present(bathyT)) call MOM_error(FATAL, "int_density_dz_generic: "//&
507  ! "bathyT must be present if useMassWghtInterp is present and true.")
508  ! if (.not.present(dz_neglect)) call MOM_error(FATAL, "int_density_dz_generic: "//&
509  ! "dz_neglect must be present if useMassWghtInterp is present and true.")
510  endif ; endif
511 
512  do j=jsq,jeq+1 ; do i=isq,ieq+1
513  al0_2d(i,j) = (a0 + a1*t(i,j)) + a2*s(i,j)
514  p0_2d(i,j) = (b0 + b4*s(i,j)) + t(i,j) * (b1 + t(i,j)*((b2 + b3*t(i,j))) + b5*s(i,j))
515  lambda_2d(i,j) = (c0 +c4*s(i,j)) + t(i,j) * (c1 + t(i,j)*((c2 + c3*t(i,j))) + c5*s(i,j))
516 
517  al0 = al0_2d(i,j) ; p0 = p0_2d(i,j) ; lambda = lambda_2d(i,j)
518 
519  dz = z_t(i,j) - z_b(i,j)
520  p_ave = -0.5*gxrho*(z_t(i,j)+z_b(i,j))
521 
522  i_al0 = 1.0 / al0
523  i_lzz = 1.0 / (p0 + (lambda * i_al0) + p_ave)
524  eps = 0.5*gxrho*dz*i_lzz ; eps2 = eps*eps
525 
526 ! rho(j) = (pressure(j) + p0) / (lambda + al0*(pressure(j) + p0))
527 
528  rho_anom = (p0 + p_ave)*(i_lzz*i_al0) - rho_ref_mks
529  rem = i_rho * (lambda * i_al0**2) * eps2 * &
530  (c1_3 + eps2*(0.2 + eps2*(c1_7 + c1_9*eps2)))
531  dpa(i,j) = pa_to_rl2_t2 * (g_earth*rho_anom*dz - 2.0*eps*rem)
532  if (present(intz_dpa)) &
533  intz_dpa(i,j) = pa_to_rl2_t2 * (0.5*g_earth*rho_anom*dz**2 - dz*(1.0+eps)*rem)
534  enddo ; enddo
535 
536  if (present(intx_dpa)) then ; do j=js,je ; do i=isq,ieq
537  ! hWght is the distance measure by which the cell is violation of
538  ! hydrostatic consistency. For large hWght we bias the interpolation of
539  ! T & S along the top and bottom integrals, akin to thickness weighting.
540  hwght = 0.0
541  if (do_massweight) &
542  hwght = max(0., -bathyt(i,j)-z_t(i+1,j), -bathyt(i+1,j)-z_t(i,j))
543  if (hwght > 0.) then
544  hl = (z_t(i,j) - z_b(i,j)) + dz_neglect
545  hr = (z_t(i+1,j) - z_b(i+1,j)) + dz_neglect
546  hwght = hwght * ( (hl-hr)/(hl+hr) )**2
547  idenom = 1.0 / ( hwght*(hr + hl) + hl*hr )
548  hwt_ll = (hwght*hl + hr*hl) * idenom ; hwt_lr = (hwght*hr) * idenom
549  hwt_rr = (hwght*hr + hr*hl) * idenom ; hwt_rl = (hwght*hl) * idenom
550  else
551  hwt_ll = 1.0 ; hwt_lr = 0.0 ; hwt_rr = 1.0 ; hwt_rl = 0.0
552  endif
553 
554  intz(1) = dpa(i,j) ; intz(5) = dpa(i+1,j)
555  do m=2,4
556  wt_l = 0.25*real(5-m) ; wt_r = 1.0-wt_l
557  wtt_l = wt_l*hwt_ll + wt_r*hwt_rl ; wtt_r = wt_l*hwt_lr + wt_r*hwt_rr
558 
559  al0 = wtt_l*al0_2d(i,j) + wtt_r*al0_2d(i+1,j)
560  p0 = wtt_l*p0_2d(i,j) + wtt_r*p0_2d(i+1,j)
561  lambda = wtt_l*lambda_2d(i,j) + wtt_r*lambda_2d(i+1,j)
562 
563  dz = wt_l*(z_t(i,j) - z_b(i,j)) + wt_r*(z_t(i+1,j) - z_b(i+1,j))
564  p_ave = -0.5*gxrho*(wt_l*(z_t(i,j)+z_b(i,j)) + &
565  wt_r*(z_t(i+1,j)+z_b(i+1,j)))
566 
567  i_al0 = 1.0 / al0
568  i_lzz = 1.0 / (p0 + (lambda * i_al0) + p_ave)
569  eps = 0.5*gxrho*dz*i_lzz ; eps2 = eps*eps
570 
571  intz(m) = pa_to_rl2_t2 * ( g_earth*dz*((p0 + p_ave)*(i_lzz*i_al0) - rho_ref_mks) - 2.0*eps * &
572  i_rho * (lambda * i_al0**2) * eps2 * (c1_3 + eps2*(0.2 + eps2*(c1_7 + c1_9*eps2))) )
573  enddo
574  ! Use Boole's rule to integrate the values.
575  intx_dpa(i,j) = c1_90*(7.0*(intz(1)+intz(5)) + 32.0*(intz(2)+intz(4)) + 12.0*intz(3))
576  enddo ; enddo ; endif
577 
578  if (present(inty_dpa)) then ; do j=jsq,jeq ; do i=is,ie
579  ! hWght is the distance measure by which the cell is violation of
580  ! hydrostatic consistency. For large hWght we bias the interpolation of
581  ! T & S along the top and bottom integrals, akin to thickness weighting.
582  hwght = 0.0
583  if (do_massweight) &
584  hwght = max(0., -bathyt(i,j)-z_t(i,j+1), -bathyt(i,j+1)-z_t(i,j))
585  if (hwght > 0.) then
586  hl = (z_t(i,j) - z_b(i,j)) + dz_neglect
587  hr = (z_t(i,j+1) - z_b(i,j+1)) + dz_neglect
588  hwght = hwght * ( (hl-hr)/(hl+hr) )**2
589  idenom = 1.0 / ( hwght*(hr + hl) + hl*hr )
590  hwt_ll = (hwght*hl + hr*hl) * idenom ; hwt_lr = (hwght*hr) * idenom
591  hwt_rr = (hwght*hr + hr*hl) * idenom ; hwt_rl = (hwght*hl) * idenom
592  else
593  hwt_ll = 1.0 ; hwt_lr = 0.0 ; hwt_rr = 1.0 ; hwt_rl = 0.0
594  endif
595 
596  intz(1) = dpa(i,j) ; intz(5) = dpa(i,j+1)
597  do m=2,4
598  wt_l = 0.25*real(5-m) ; wt_r = 1.0-wt_l
599  wtt_l = wt_l*hwt_ll + wt_r*hwt_rl ; wtt_r = wt_l*hwt_lr + wt_r*hwt_rr
600 
601  al0 = wtt_l*al0_2d(i,j) + wtt_r*al0_2d(i,j+1)
602  p0 = wtt_l*p0_2d(i,j) + wtt_r*p0_2d(i,j+1)
603  lambda = wtt_l*lambda_2d(i,j) + wtt_r*lambda_2d(i,j+1)
604 
605  dz = wt_l*(z_t(i,j) - z_b(i,j)) + wt_r*(z_t(i,j+1) - z_b(i,j+1))
606  p_ave = -0.5*gxrho*(wt_l*(z_t(i,j)+z_b(i,j)) + &
607  wt_r*(z_t(i,j+1)+z_b(i,j+1)))
608 
609  i_al0 = 1.0 / al0
610  i_lzz = 1.0 / (p0 + (lambda * i_al0) + p_ave)
611  eps = 0.5*gxrho*dz*i_lzz ; eps2 = eps*eps
612 
613  intz(m) = pa_to_rl2_t2 * ( g_earth*dz*((p0 + p_ave)*(i_lzz*i_al0) - rho_ref_mks) - 2.0*eps * &
614  i_rho * (lambda * i_al0**2) * eps2 * (c1_3 + eps2*(0.2 + eps2*(c1_7 + c1_9*eps2))) )
615  enddo
616  ! Use Boole's rule to integrate the values.
617  inty_dpa(i,j) = c1_90*(7.0*(intz(1)+intz(5)) + 32.0*(intz(2)+intz(4)) + 12.0*intz(3))
618  enddo ; enddo ; endif
619 
620 end subroutine int_density_dz_wright
621 
622 !> This subroutine calculates analytical and nearly-analytical integrals in
623 !! pressure across layers of geopotential anomalies, which are required for
624 !! calculating the finite-volume form pressure accelerations in a non-Boussinesq
625 !! model. There are essentially no free assumptions, apart from the use of
626 !! Boole's rule to do the horizontal integrals, and from a truncation in the
627 !! series for log(1-eps/1+eps) that assumes that |eps| < 0.34.
628 subroutine int_spec_vol_dp_wright(T, S, p_t, p_b, spv_ref, HI, dza, &
629  intp_dza, intx_dza, inty_dza, halo_size, &
630  bathyP, dP_neglect, useMassWghtInterp, SV_scale, pres_scale)
631  type(hor_index_type), intent(in) :: hi !< The ocean's horizontal index type.
632  real, dimension(HI%isd:HI%ied,HI%jsd:HI%jed), &
633  intent(in) :: t !< Potential temperature relative to the surface
634  !! [degC].
635  real, dimension(HI%isd:HI%ied,HI%jsd:HI%jed), &
636  intent(in) :: s !< Salinity [PSU].
637  real, dimension(HI%isd:HI%ied,HI%jsd:HI%jed), &
638  intent(in) :: p_t !< Pressure at the top of the layer [R L2 T-2 ~> Pa] or [Pa].
639  real, dimension(HI%isd:HI%ied,HI%jsd:HI%jed), &
640  intent(in) :: p_b !< Pressure at the top of the layer [R L2 T-2 ~> Pa] or [Pa].
641  real, intent(in) :: spv_ref !< A mean specific volume that is subtracted out
642  !! to reduce the magnitude of each of the integrals [R-1 ~> m3 kg-1].
643  !! The calculation is mathematically identical with different values of
644  !! spv_ref, but this reduces the effects of roundoff.
645  real, dimension(HI%isd:HI%ied,HI%jsd:HI%jed), &
646  intent(inout) :: dza !< The change in the geopotential anomaly across
647  !! the layer [T-2 ~> m2 s-2] or [m2 s-2].
648  real, dimension(HI%isd:HI%ied,HI%jsd:HI%jed), &
649  optional, intent(inout) :: intp_dza !< The integral in pressure through the layer of
650  !! the geopotential anomaly relative to the anomaly
651  !! at the bottom of the layer [R L4 T-4 ~> Pa m2 s-2]
652  !! or [Pa m2 s-2].
653  real, dimension(HI%IsdB:HI%IedB,HI%jsd:HI%jed), &
654  optional, intent(inout) :: intx_dza !< The integral in x of the difference between the
655  !! geopotential anomaly at the top and bottom of
656  !! the layer divided by the x grid spacing
657  !! [L2 T-2 ~> m2 s-2] or [m2 s-2].
658  real, dimension(HI%isd:HI%ied,HI%JsdB:HI%JedB), &
659  optional, intent(inout) :: inty_dza !< The integral in y of the difference between the
660  !! geopotential anomaly at the top and bottom of
661  !! the layer divided by the y grid spacing
662  !! [L2 T-2 ~> m2 s-2] or [m2 s-2].
663  integer, optional, intent(in) :: halo_size !< The width of halo points on which to calculate
664  !! dza.
665  real, dimension(HI%isd:HI%ied,HI%jsd:HI%jed), &
666  optional, intent(in) :: bathyp !< The pressure at the bathymetry [R L2 T-2 ~> Pa] or [Pa]
667  real, optional, intent(in) :: dp_neglect !< A miniscule pressure change with
668  !! the same units as p_t [R L2 T-2 ~> Pa] or [Pa]
669  logical, optional, intent(in) :: usemasswghtinterp !< If true, uses mass weighting
670  !! to interpolate T/S for top and bottom integrals.
671  real, optional, intent(in) :: sv_scale !< A multiplicative factor by which to scale specific
672  !! volume from m3 kg-1 to the desired units [kg m-3 R-1 ~> 1]
673  real, optional, intent(in) :: pres_scale !< A multiplicative factor to convert pressure
674  !! into Pa [Pa T2 R-1 L-2 ~> 1].
675 
676  ! Local variables
677  real, dimension(HI%isd:HI%ied,HI%jsd:HI%jed) :: al0_2d, p0_2d, lambda_2d
678  real :: al0 ! A term in the Wright EOS [R-1 ~> m3 kg-1]
679  real :: p0 ! A term in the Wright EOS [R L2 T-2 ~> Pa]
680  real :: lambda ! A term in the Wright EOS [L2 T-2 ~> m2 s-2]
681  real :: al0_scale ! Scaling factor to convert al0 from MKS units [R-1 kg m-3 ~> 1]
682  real :: p0_scale ! Scaling factor to convert p0 from MKS units [R L2 T-2 Pa-1 ~> 1]
683  real :: lam_scale ! Scaling factor to convert lambda from MKS units [L2 s2 T-2 m-2 ~> 1]
684  real :: p_ave ! The layer average pressure [R L2 T-2 ~> Pa]
685  real :: rem ! [L2 T-2 ~> m2 s-2]
686  real :: eps, eps2 ! A nondimensional ratio and its square [nondim]
687  real :: alpha_anom ! The depth averaged specific volume anomaly [R-1 ~> m3 kg-1].
688  real :: dp ! The pressure change through a layer [R L2 T-2 ~> Pa].
689  real :: hwght ! A pressure-thickness below topography [R L2 T-2 ~> Pa].
690  real :: hl, hr ! Pressure-thicknesses of the columns to the left and right [R L2 T-2 ~> Pa].
691  real :: idenom ! The inverse of the denominator in the weights [T4 R-2 L-4 ~> Pa-2].
692  real :: hwt_ll, hwt_lr ! hWt_LA is the weighted influence of A on the left column [nondim].
693  real :: hwt_rl, hwt_rr ! hWt_RA is the weighted influence of A on the right column [nondim].
694  real :: wt_l, wt_r ! The linear weights of the left and right columns [nondim].
695  real :: wtt_l, wtt_r ! The weights for tracers from the left and right columns [nondim].
696  real :: intp(5) ! The integrals of specific volume with pressure at the
697  ! 5 sub-column locations [L2 T-2 ~> m2 s-2].
698  logical :: do_massweight ! Indicates whether to do mass weighting.
699  real, parameter :: c1_3 = 1.0/3.0, c1_7 = 1.0/7.0 ! Rational constants.
700  real, parameter :: c1_9 = 1.0/9.0, c1_90 = 1.0/90.0 ! Rational constants.
701  integer :: isq, ieq, jsq, jeq, ish, ieh, jsh, jeh, i, j, m, halo
702 
703  isq = hi%IscB ; ieq = hi%IecB ; jsq = hi%JscB ; jeq = hi%JecB
704  halo = 0 ; if (present(halo_size)) halo = max(halo_size,0)
705  ish = hi%isc-halo ; ieh = hi%iec+halo ; jsh = hi%jsc-halo ; jeh = hi%jec+halo
706  if (present(intx_dza)) then ; ish = min(isq,ish) ; ieh = max(ieq+1,ieh); endif
707  if (present(inty_dza)) then ; jsh = min(jsq,jsh) ; jeh = max(jeq+1,jeh); endif
708 
709 
710  al0_scale = 1.0 ; if (present(sv_scale)) al0_scale = sv_scale
711  p0_scale = 1.0
712  if (present(pres_scale)) then ; if (pres_scale /= 1.0) then
713  p0_scale = 1.0 / pres_scale
714  endif ; endif
715  lam_scale = al0_scale * p0_scale
716 
717  do_massweight = .false.
718  if (present(usemasswghtinterp)) then ; if (usemasswghtinterp) then
719  do_massweight = .true.
720 ! if (.not.present(bathyP)) call MOM_error(FATAL, "int_spec_vol_dp_generic: "//&
721 ! "bathyP must be present if useMassWghtInterp is present and true.")
722 ! if (.not.present(dP_neglect)) call MOM_error(FATAL, "int_spec_vol_dp_generic: "//&
723 ! "dP_neglect must be present if useMassWghtInterp is present and true.")
724  endif ; endif
725 
726  ! alpha(j) = (lambda + al0*(pressure(j) + p0)) / (pressure(j) + p0)
727  do j=jsh,jeh ; do i=ish,ieh
728  al0_2d(i,j) = al0_scale * ( (a0 + a1*t(i,j)) + a2*s(i,j) )
729  p0_2d(i,j) = p0_scale * ( (b0 + b4*s(i,j)) + t(i,j) * (b1 + t(i,j)*((b2 + b3*t(i,j))) + b5*s(i,j)) )
730  lambda_2d(i,j) = lam_scale * ( (c0 + c4*s(i,j)) + t(i,j) * (c1 + t(i,j)*((c2 + c3*t(i,j))) + c5*s(i,j)) )
731 
732  al0 = al0_2d(i,j) ; p0 = p0_2d(i,j) ; lambda = lambda_2d(i,j)
733  dp = p_b(i,j) - p_t(i,j)
734  p_ave = 0.5*(p_t(i,j)+p_b(i,j))
735 
736  eps = 0.5 * dp / (p0 + p_ave) ; eps2 = eps*eps
737  alpha_anom = al0 + lambda / (p0 + p_ave) - spv_ref
738  rem = lambda * eps2 * (c1_3 + eps2*(0.2 + eps2*(c1_7 + c1_9*eps2)))
739  dza(i,j) = alpha_anom*dp + 2.0*eps*rem
740  if (present(intp_dza)) &
741  intp_dza(i,j) = 0.5*alpha_anom*dp**2 - dp*(1.0-eps)*rem
742  enddo ; enddo
743 
744  if (present(intx_dza)) then ; do j=hi%jsc,hi%jec ; do i=isq,ieq
745  ! hWght is the distance measure by which the cell is violation of
746  ! hydrostatic consistency. For large hWght we bias the interpolation of
747  ! T & S along the top and bottom integrals, akin to thickness weighting.
748  hwght = 0.0
749  if (do_massweight) &
750  hwght = max(0., bathyp(i,j)-p_t(i+1,j), bathyp(i+1,j)-p_t(i,j))
751  if (hwght > 0.) then
752  hl = (p_b(i,j) - p_t(i,j)) + dp_neglect
753  hr = (p_b(i+1,j) - p_t(i+1,j)) + dp_neglect
754  hwght = hwght * ( (hl-hr)/(hl+hr) )**2
755  idenom = 1.0 / ( hwght*(hr + hl) + hl*hr )
756  hwt_ll = (hwght*hl + hr*hl) * idenom ; hwt_lr = (hwght*hr) * idenom
757  hwt_rr = (hwght*hr + hr*hl) * idenom ; hwt_rl = (hwght*hl) * idenom
758  else
759  hwt_ll = 1.0 ; hwt_lr = 0.0 ; hwt_rr = 1.0 ; hwt_rl = 0.0
760  endif
761 
762  intp(1) = dza(i,j) ; intp(5) = dza(i+1,j)
763  do m=2,4
764  wt_l = 0.25*real(5-m) ; wt_r = 1.0-wt_l
765  wtt_l = wt_l*hwt_ll + wt_r*hwt_rl ; wtt_r = wt_l*hwt_lr + wt_r*hwt_rr
766 
767  ! T, S, and p are interpolated in the horizontal. The p interpolation
768  ! is linear, but for T and S it may be thickness wekghted.
769  al0 = wtt_l*al0_2d(i,j) + wtt_r*al0_2d(i+1,j)
770  p0 = wtt_l*p0_2d(i,j) + wtt_r*p0_2d(i+1,j)
771  lambda = wtt_l*lambda_2d(i,j) + wtt_r*lambda_2d(i+1,j)
772 
773  dp = wt_l*(p_b(i,j) - p_t(i,j)) + wt_r*(p_b(i+1,j) - p_t(i+1,j))
774  p_ave = 0.5*(wt_l*(p_t(i,j)+p_b(i,j)) + wt_r*(p_t(i+1,j)+p_b(i+1,j)))
775 
776  eps = 0.5 * dp / (p0 + p_ave) ; eps2 = eps*eps
777  intp(m) = (al0 + lambda / (p0 + p_ave) - spv_ref)*dp + 2.0*eps* &
778  lambda * eps2 * (c1_3 + eps2*(0.2 + eps2*(c1_7 + c1_9*eps2)))
779  enddo
780  ! Use Boole's rule to integrate the values.
781  intx_dza(i,j) = c1_90*(7.0*(intp(1)+intp(5)) + 32.0*(intp(2)+intp(4)) + &
782  12.0*intp(3))
783  enddo ; enddo ; endif
784 
785  if (present(inty_dza)) then ; do j=jsq,jeq ; do i=hi%isc,hi%iec
786  ! hWght is the distance measure by which the cell is violation of
787  ! hydrostatic consistency. For large hWght we bias the interpolation of
788  ! T & S along the top and bottom integrals, akin to thickness weighting.
789  hwght = 0.0
790  if (do_massweight) &
791  hwght = max(0., bathyp(i,j)-p_t(i,j+1), bathyp(i,j+1)-p_t(i,j))
792  if (hwght > 0.) then
793  hl = (p_b(i,j) - p_t(i,j)) + dp_neglect
794  hr = (p_b(i,j+1) - p_t(i,j+1)) + dp_neglect
795  hwght = hwght * ( (hl-hr)/(hl+hr) )**2
796  idenom = 1.0 / ( hwght*(hr + hl) + hl*hr )
797  hwt_ll = (hwght*hl + hr*hl) * idenom ; hwt_lr = (hwght*hr) * idenom
798  hwt_rr = (hwght*hr + hr*hl) * idenom ; hwt_rl = (hwght*hl) * idenom
799  else
800  hwt_ll = 1.0 ; hwt_lr = 0.0 ; hwt_rr = 1.0 ; hwt_rl = 0.0
801  endif
802 
803  intp(1) = dza(i,j) ; intp(5) = dza(i,j+1)
804  do m=2,4
805  wt_l = 0.25*real(5-m) ; wt_r = 1.0-wt_l
806  wtt_l = wt_l*hwt_ll + wt_r*hwt_rl ; wtt_r = wt_l*hwt_lr + wt_r*hwt_rr
807 
808  ! T, S, and p are interpolated in the horizontal. The p interpolation
809  ! is linear, but for T and S it may be thickness wekghted.
810  al0 = wt_l*al0_2d(i,j) + wt_r*al0_2d(i,j+1)
811  p0 = wt_l*p0_2d(i,j) + wt_r*p0_2d(i,j+1)
812  lambda = wt_l*lambda_2d(i,j) + wt_r*lambda_2d(i,j+1)
813 
814  dp = wt_l*(p_b(i,j) - p_t(i,j)) + wt_r*(p_b(i,j+1) - p_t(i,j+1))
815  p_ave = 0.5*(wt_l*(p_t(i,j)+p_b(i,j)) + wt_r*(p_t(i,j+1)+p_b(i,j+1)))
816 
817  eps = 0.5 * dp / (p0 + p_ave) ; eps2 = eps*eps
818  intp(m) = (al0 + lambda / (p0 + p_ave) - spv_ref)*dp + 2.0*eps* &
819  lambda * eps2 * (c1_3 + eps2*(0.2 + eps2*(c1_7 + c1_9*eps2)))
820  enddo
821  ! Use Boole's rule to integrate the values.
822  inty_dza(i,j) = c1_90*(7.0*(intp(1)+intp(5)) + 32.0*(intp(2)+intp(4)) + &
823  12.0*intp(3))
824  enddo ; enddo ; endif
825 end subroutine int_spec_vol_dp_wright
826 
827 end module mom_eos_wright
For a given thermodynamic state, return the second derivatives of density with various combinations o...
For a given thermodynamic state, return the derivatives of density with temperature and salinity.
The equation of state using the Wright 1997 expressions.
Defines the horizontal index type (hor_index_type) used for providing index ranges.
Compute the in situ density of sea water (in [kg m-3]), or its anomaly with respect to a reference de...
Container for horizontal index ranges for data, computational and global domains.
Compute the in situ specific volume of sea water (in [m3 kg-1]), or an anomaly with respect to a refe...