Skip to content

Commit

Permalink
+Rescaled the units of tv%P_Ref to [R L2 T-2]
Browse files Browse the repository at this point in the history
  Rescaled the units of tv%P_Ref to [R L2 T-2] for expanded dimensional
consistency testing.  In some cases, other pressure variables were also
rescaled and calls to calculate_density are recast into the simpler G%HI forms.
All answers are bitwise identical, but the scaled units of an element of a
transparent type were rescaled.
  • Loading branch information
Hallberg-NOAA committed Apr 11, 2020
1 parent 2fc1c2e commit 3223eb6
Show file tree
Hide file tree
Showing 20 changed files with 82 additions and 80 deletions.
11 changes: 6 additions & 5 deletions src/core/MOM.F90
Original file line number Diff line number Diff line change
Expand Up @@ -1805,7 +1805,8 @@ subroutine initialize_MOM(Time, Time_init, param_file, dirs, CS, restart_CSp, &
endif

! This is here in case these values are used inappropriately.
use_frazil = .false. ; bound_salinity = .false. ; CS%tv%P_Ref = 2.0e7
use_frazil = .false. ; bound_salinity = .false.
CS%tv%P_Ref = 2.0e7*US%kg_m3_to_R*US%m_s_to_L_T**2
if (use_temperature) then
call get_param(param_file, "MOM", "FRAZIL", use_frazil, &
"If true, water freezes if it gets too cold, and the "//&
Expand All @@ -1820,8 +1821,8 @@ subroutine initialize_MOM(Time, Time_init, param_file, dirs, CS, restart_CSp, &
"drive the salinity negative otherwise.)", default=.false.)
call get_param(param_file, "MOM", "MIN_SALINITY", CS%tv%min_salinity, &
"The minimum value of salinity when BOUND_SALINITY=True. "//&
"The default is 0.01 for backward compatibility but ideally "//&
"should be 0.", units="PPT", default=0.01, do_not_log=.not.bound_salinity)
"The default is 0.01 for backward compatibility but ideally should be 0.", &
units="PPT", default=0.01, do_not_log=.not.bound_salinity)
call get_param(param_file, "MOM", "C_P", CS%tv%C_p, &
"The heat capacity of sea water, approximated as a "//&
"constant. This is only used if ENABLE_THERMODYNAMICS is "//&
Expand All @@ -1832,8 +1833,8 @@ subroutine initialize_MOM(Time, Time_init, param_file, dirs, CS, restart_CSp, &
if (use_EOS) call get_param(param_file, "MOM", "P_REF", CS%tv%P_Ref, &
"The pressure that is used for calculating the coordinate "//&
"density. (1 Pa = 1e4 dbar, so 2e7 is commonly used.) "//&
"This is only used if USE_EOS and ENABLE_THERMODYNAMICS "//&
"are true.", units="Pa", default=2.0e7)
"This is only used if USE_EOS and ENABLE_THERMODYNAMICS are true.", &
units="Pa", default=2.0e7, scale=US%kg_m3_to_R*US%m_s_to_L_T**2)

if (bulkmixedlayer) then
call get_param(param_file, "MOM", "NKML", nkml, &
Expand Down
21 changes: 11 additions & 10 deletions src/core/MOM_PressureForce_Montgomery.F90
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ subroutine PressureForce_Mont_nonBouss(h, tv, PFu, PFv, G, GV, US, CS, p_atm, pb
geopot_bot ! Bottom geopotential relative to time-mean sea level,
! including any tidal contributions [L2 T-2 ~> m2 s-2].
real :: p_ref(SZI_(G)) ! The pressure used to calculate the coordinate
! density [Pa] (usually 2e7 Pa = 2000 dbar).
! density [R L2 T-2 ~> Pa] (usually 2e7 Pa = 2000 dbar).
real :: rho_in_situ(SZI_(G)) !In-situ density of a layer [R ~> kg m-3].
real :: PFu_bc, PFv_bc ! The pressure gradient force due to along-layer
! compensated density gradients [L T-2 ~> m s-2]
Expand Down Expand Up @@ -227,8 +227,8 @@ subroutine PressureForce_Mont_nonBouss(h, tv, PFu, PFv, G, GV, US, CS, p_atm, pb
do k=1,nkmb ; do i=Isq,Ieq+1
tv_tmp%T(i,j,k) = tv%T(i,j,k) ; tv_tmp%S(i,j,k) = tv%S(i,j,k)
enddo ; enddo
call calculate_density(tv%T(:,j,nkmb), tv%S(:,j,nkmb), p_ref, &
Rho_cv_BL(:), Isq, Ieq-Isq+2, tv%eqn_of_state, scale=US%kg_m3_to_R)
call calculate_density(tv%T(:,j,nkmb), tv%S(:,j,nkmb), p_ref, Rho_cv_BL(:), G%HI, &
tv%eqn_of_state, US, halo=1)
do k=nkmb+1,nz ; do i=Isq,Ieq+1
if (GV%Rlay(k) < Rho_cv_BL(i)) then
tv_tmp%T(i,j,k) = tv%T(i,j,nkmb) ; tv_tmp%S(i,j,k) = tv%S(i,j,nkmb)
Expand All @@ -244,8 +244,8 @@ subroutine PressureForce_Mont_nonBouss(h, tv, PFu, PFv, G, GV, US, CS, p_atm, pb
endif
!$OMP parallel do default(shared) private(rho_in_situ)
do k=1,nz ; do j=Jsq,Jeq+1
call calculate_density(tv_tmp%T(:,j,k),tv_tmp%S(:,j,k),p_ref, &
rho_in_situ,Isq,Ieq-Isq+2,tv%eqn_of_state, scale=US%kg_m3_to_R)
call calculate_density(tv_tmp%T(:,j,k), tv_tmp%S(:,j,k), p_ref, rho_in_situ, G%HI, &
tv%eqn_of_state, US, halo=1)
do i=Isq,Ieq+1 ; alpha_star(i,j,k) = 1.0 / rho_in_situ(i) ; enddo
enddo ; enddo
endif ! use_EOS
Expand Down Expand Up @@ -394,7 +394,7 @@ subroutine PressureForce_Mont_Bouss(h, tv, PFu, PFv, G, GV, US, CS, p_atm, pbce,
! forces from astronomical sources and self-
! attraction and loading, in depth units [Z ~> m].
real :: p_ref(SZI_(G)) ! The pressure used to calculate the coordinate
! density [Pa] (usually 2e7 Pa = 2000 dbar).
! density [R L2 T-2 ~> Pa] (usually 2e7 Pa = 2000 dbar).
real :: I_Rho0 ! 1/Rho0 [R-1 ~> m3 kg-1].
real :: G_Rho0 ! G_Earth / Rho0 [L2 Z-1 T-2 R-1 ~> m4 s-2 kg-1].
real :: PFu_bc, PFv_bc ! The pressure gradient force due to along-layer
Expand Down Expand Up @@ -482,8 +482,8 @@ subroutine PressureForce_Mont_Bouss(h, tv, PFu, PFv, G, GV, US, CS, p_atm, pbce,
do k=1,nkmb ; do i=Isq,Ieq+1
tv_tmp%T(i,j,k) = tv%T(i,j,k) ; tv_tmp%S(i,j,k) = tv%S(i,j,k)
enddo ; enddo
call calculate_density(tv%T(:,j,nkmb), tv%S(:,j,nkmb), p_ref, &
Rho_cv_BL(:), Isq, Ieq-Isq+2, tv%eqn_of_state, scale=US%kg_m3_to_R)
call calculate_density(tv%T(:,j,nkmb), tv%S(:,j,nkmb), p_ref, Rho_cv_BL(:), G%HI, &
tv%eqn_of_state, US, halo=1)

do k=nkmb+1,nz ; do i=Isq,Ieq+1
if (GV%Rlay(k) < Rho_cv_BL(i)) then
Expand All @@ -503,8 +503,9 @@ subroutine PressureForce_Mont_Bouss(h, tv, PFu, PFv, G, GV, US, CS, p_atm, pbce,
! will come down with a fatal error if there is any compressibility.
!$OMP parallel do default(shared)
do k=1,nz+1 ; do j=Jsq,Jeq+1
call calculate_density(tv_tmp%T(:,j,k), tv_tmp%S(:,j,k), p_ref, rho_star(:,j,k), &
Isq, Ieq-Isq+2, tv%eqn_of_state, scale=US%kg_m3_to_R*G_Rho0)
call calculate_density(tv_tmp%T(:,j,k), tv_tmp%S(:,j,k), p_ref, rho_star(:,j,k), G%HI, &
tv%eqn_of_state, US, halo=1)
do i=Isq,Ieq+1 ; rho_star(i,j,k) = G_Rho0*rho_star(i,j,k) ; enddo
enddo ; enddo
endif ! use_EOS

Expand Down
12 changes: 6 additions & 6 deletions src/core/MOM_PressureForce_analytic_FV.F90
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ subroutine PressureForce_AFV_nonBouss(h, tv, PFu, PFv, G, GV, US, CS, ALE_CSp, p
real, dimension(SZI_(G),SZJB_(G),SZK_(G)) :: &
inty_dza ! The change in inty_za through a layer [L2 T-2 ~> m2 s-2].
real :: p_ref(SZI_(G)) ! The pressure used to calculate the coordinate
! density, [Pa] (usually 2e7 Pa = 2000 dbar).
! density, [R L2 T-2 ~> Pa] (usually 2e7 Pa = 2000 dbar).

real :: dp_neglect ! A thickness that is so small it is usually lost
! in roundoff and can be neglected [R L2 T-2 ~> Pa].
Expand Down Expand Up @@ -227,8 +227,8 @@ subroutine PressureForce_AFV_nonBouss(h, tv, PFu, PFv, G, GV, US, CS, ALE_CSp, p
do k=1,nkmb ; do i=Isq,Ieq+1
tv_tmp%T(i,j,k) = tv%T(i,j,k) ; tv_tmp%S(i,j,k) = tv%S(i,j,k)
enddo ; enddo
call calculate_density(tv%T(:,j,nkmb), tv%S(:,j,nkmb), p_ref, &
Rho_cv_BL(:), Isq, Ieq-Isq+2, tv%eqn_of_state, scale=US%kg_m3_to_R)
call calculate_density(tv%T(:,j,nkmb), tv%S(:,j,nkmb), p_ref, Rho_cv_BL(:), G%HI, &
tv%eqn_of_state, US, halo=1)
do k=nkmb+1,nz ; do i=Isq,Ieq+1
if (GV%Rlay(k) < Rho_cv_BL(i)) then
tv_tmp%T(i,j,k) = tv%T(i,j,nkmb) ; tv_tmp%S(i,j,k) = tv%S(i,j,nkmb)
Expand Down Expand Up @@ -489,7 +489,7 @@ subroutine PressureForce_AFV_Bouss(h, tv, PFu, PFv, G, GV, US, CS, ALE_CSp, p_at
! of salinity and temperature within each layer.
real :: rho_in_situ(SZI_(G)) ! The in situ density [R ~> kg m-3].
real :: p_ref(SZI_(G)) ! The pressure used to calculate the coordinate
! density, [Pa] (usually 2e7 Pa = 2000 dbar).
! density, [R L2 T-2 ~> Pa] (usually 2e7 Pa = 2000 dbar).
real :: p0(SZI_(G)) ! An array of zeros to use for pressure [Pa].
real :: h_neglect ! A thickness that is so small it is usually lost
! in roundoff and can be neglected [H ~> m].
Expand Down Expand Up @@ -576,8 +576,8 @@ subroutine PressureForce_AFV_Bouss(h, tv, PFu, PFv, G, GV, US, CS, ALE_CSp, p_at
do k=1,nkmb ; do i=Isq,Ieq+1
tv_tmp%T(i,j,k) = tv%T(i,j,k) ; tv_tmp%S(i,j,k) = tv%S(i,j,k)
enddo ; enddo
call calculate_density(tv%T(:,j,nkmb), tv%S(:,j,nkmb), p_ref, &
Rho_cv_BL(:), Isq, Ieq-Isq+2, tv%eqn_of_state, scale=US%kg_m3_to_R)
call calculate_density(tv%T(:,j,nkmb), tv%S(:,j,nkmb), p_ref, Rho_cv_BL(:), G%HI, &
tv%eqn_of_state, US, halo=1)

do k=nkmb+1,nz ; do i=Isq,Ieq+1
if (GV%Rlay(k) < Rho_cv_BL(i)) then
Expand Down
12 changes: 6 additions & 6 deletions src/core/MOM_PressureForce_blocked_AFV.F90
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ subroutine PressureForce_blk_AFV_nonBouss(h, tv, PFu, PFv, G, GV, US, CS, p_atm,
real, dimension(SZI_(G),SZJB_(G),SZK_(G)) :: &
inty_dza ! The change in inty_za through a layer [L2 T-2 ~> m2 s-2].
real :: p_ref(SZI_(G)) ! The pressure used to calculate the coordinate
! density [Pa] (usually 2e7 Pa = 2000 dbar).
! density [R L2 T-2 ~> Pa] (usually 2e7 Pa = 2000 dbar).

real :: dp_neglect ! A thickness that is so small it is usually lost
! in roundoff and can be neglected [Pa].
Expand Down Expand Up @@ -223,8 +223,8 @@ subroutine PressureForce_blk_AFV_nonBouss(h, tv, PFu, PFv, G, GV, US, CS, p_atm,
do k=1,nkmb ; do i=Isq,Ieq+1
tv_tmp%T(i,j,k) = tv%T(i,j,k) ; tv_tmp%S(i,j,k) = tv%S(i,j,k)
enddo ; enddo
call calculate_density(tv%T(:,j,nkmb), tv%S(:,j,nkmb), p_ref, &
Rho_cv_BL(:), Isq, Ieq-Isq+2, tv%eqn_of_state, scale=US%kg_m3_to_R)
call calculate_density(tv%T(:,j,nkmb), tv%S(:,j,nkmb), p_ref, Rho_cv_BL(:), G%HI, &
tv%eqn_of_state, US, halo=1)
do k=nkmb+1,nz ; do i=Isq,Ieq+1
if (GV%Rlay(k) < Rho_cv_BL(i)) then
tv_tmp%T(i,j,k) = tv%T(i,j,nkmb) ; tv_tmp%S(i,j,k) = tv%S(i,j,nkmb)
Expand Down Expand Up @@ -473,7 +473,7 @@ subroutine PressureForce_blk_AFV_Bouss(h, tv, PFu, PFv, G, GV, US, CS, ALE_CSp,
T_t, T_b ! Top and bottom edge temperatures for linear reconstructions within each layer [degC].
real :: rho_in_situ(SZI_(G)) ! The in situ density [R ~> kg m-3].
real :: p_ref(SZI_(G)) ! The pressure used to calculate the coordinate
! density [Pa] (usually 2e7 Pa = 2000 dbar).
! density [R L2 T-2 ~> Pa] (usually 2e7 Pa = 2000 dbar).
real :: p0(SZI_(G)) ! An array of zeros to use for pressure [Pa].
real :: h_neglect ! A thickness that is so small it is usually lost
! in roundoff and can be neglected [H ~> m or kg m-2].
Expand Down Expand Up @@ -563,8 +563,8 @@ subroutine PressureForce_blk_AFV_Bouss(h, tv, PFu, PFv, G, GV, US, CS, ALE_CSp,
do k=1,nkmb ; do i=Isq,Ieq+1
tv_tmp%T(i,j,k) = tv%T(i,j,k) ; tv_tmp%S(i,j,k) = tv%S(i,j,k)
enddo ; enddo
call calculate_density(tv%T(:,j,nkmb), tv%S(:,j,nkmb), p_ref, &
Rho_cv_BL(:), Isq, Ieq-Isq+2, tv%eqn_of_state, scale=US%kg_m3_to_R)
call calculate_density(tv%T(:,j,nkmb), tv%S(:,j,nkmb), p_ref, Rho_cv_BL(:), G%HI, &
tv%eqn_of_state, US, halo=1)

do k=nkmb+1,nz ; do i=Isq,Ieq+1
if (GV%Rlay(k) < Rho_cv_BL(i)) then
Expand Down
2 changes: 1 addition & 1 deletion src/core/MOM_variables.F90
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ module MOM_variables
real, pointer :: S(:,:,:) => NULL() !< Salnity [PSU] or [gSalt/kg], generically [ppt].
type(EOS_type), pointer :: eqn_of_state => NULL() !< Type that indicates the
!! equation of state to use.
real :: P_Ref !< The coordinate-density reference pressure [Pa].
real :: P_Ref !< The coordinate-density reference pressure [R L2 T-2 ~> Pa].
!! This is the pressure used to calculate Rml from
!! T and S when eqn_of_state is associated.
real :: C_p !< The heat capacity of seawater [Q degC-1 ~> J degC-1 kg-1].
Expand Down
16 changes: 8 additions & 8 deletions src/diagnostics/MOM_diagnostics.F90
Original file line number Diff line number Diff line change
Expand Up @@ -232,7 +232,7 @@ subroutine calculate_diagnostic_fields(u, v, h, uh, vh, tv, ADp, CDp, p_surf, &

! tmp array for surface properties
real :: surface_field(SZI_(G),SZJ_(G))
real :: pressure_1d(SZI_(G)) ! Temporary array for pressure when calling EOS
real :: pressure_1d(SZI_(G)) ! Temporary array for pressure when calling EOS [R L2 T-2 ~> Pa] or [Pa]
real :: wt, wt_p

real :: f2_h ! Squared Coriolis parameter at to h-points [T-2 ~> s-2]
Expand Down Expand Up @@ -347,7 +347,7 @@ subroutine calculate_diagnostic_fields(u, v, h, uh, vh, tv, ADp, CDp, p_surf, &
do j=js,je
if (associated(p_surf)) then ! Pressure loading at top of surface layer [R L2 T-2 ~> Pa]
do i=is,ie
pressure_1d(i) = US%RL2_T2_to_Pa * p_surf(i,j)
pressure_1d(i) = p_surf(i,j)
enddo
else
do i=is,ie
Expand All @@ -356,16 +356,16 @@ subroutine calculate_diagnostic_fields(u, v, h, uh, vh, tv, ADp, CDp, p_surf, &
endif
do k=1,nz ! Integrate vertically downward for pressure
do i=is,ie ! Pressure for EOS at the layer center [Pa]
pressure_1d(i) = pressure_1d(i) + 0.5*GV%H_to_Pa*h(i,j,k)
pressure_1d(i) = pressure_1d(i) + 0.5*(GV%H_to_RZ*GV%g_Earth)*h(i,j,k)
enddo
! Store in-situ density [R ~> kg m-3] in work_3d
call calculate_density(tv%T(:,j,k),tv%S(:,j,k), pressure_1d, &
rho_in_situ, is, ie-is+1, tv%eqn_of_state, scale=US%kg_m3_to_R)
call calculate_density(tv%T(:,j,k), tv%S(:,j,k), pressure_1d, rho_in_situ, G%HI, &
tv%eqn_of_state, US)
do i=is,ie ! Cell thickness = dz = dp/(g*rho) (meter); store in work_3d
work_3d(i,j,k) = (GV%H_to_RZ*h(i,j,k)) / rho_in_situ(i)
enddo
do i=is,ie ! Pressure for EOS at the bottom interface [Pa]
pressure_1d(i) = pressure_1d(i) + 0.5*GV%H_to_Pa*h(i,j,k)
pressure_1d(i) = pressure_1d(i) + 0.5*(GV%H_to_RZ*GV%g_Earth)*h(i,j,k)
enddo
enddo ! k
enddo ! j
Expand Down Expand Up @@ -465,8 +465,8 @@ subroutine calculate_diagnostic_fields(u, v, h, uh, vh, tv, ADp, CDp, p_surf, &
pressure_1d(:) = tv%P_Ref
!$OMP parallel do default(shared)
do k=1,nz ; do j=js-1,je+1
call calculate_density(tv%T(:,j,k), tv%S(:,j,k), pressure_1d, &
Rcv(:,j,k), is-1, ie-is+3, tv%eqn_of_state , scale=US%kg_m3_to_R)
call calculate_density(tv%T(:,j,k), tv%S(:,j,k), pressure_1d, Rcv(:,j,k), G%HI, &
tv%eqn_of_state, US, halo=1)
enddo ; enddo
else ! Rcv should not be used much in this case, so fill in sensible values.
do k=1,nz ; do j=js-1,je+1 ; do i=is-1,ie+1
Expand Down
6 changes: 3 additions & 3 deletions src/initialization/MOM_coord_initialization.F90
Original file line number Diff line number Diff line change
Expand Up @@ -89,11 +89,11 @@ subroutine MOM_initialize_coord(GV, US, PF, write_geom, output_dir, tv, max_dept
case ("linear")
call set_coord_linear(GV%Rlay, GV%g_prime, GV, US, PF)
case ("ts_ref")
call set_coord_from_ts_ref(GV%Rlay, GV%g_prime, GV, US, PF, eos, tv%P_Ref)
call set_coord_from_ts_ref(GV%Rlay, GV%g_prime, GV, US, PF, eos, US%RL2_T2_to_Pa*tv%P_Ref)
case ("ts_profile")
call set_coord_from_TS_profile(GV%Rlay, GV%g_prime, GV, US, PF, eos, tv%P_Ref)
call set_coord_from_TS_profile(GV%Rlay, GV%g_prime, GV, US, PF, eos, US%RL2_T2_to_Pa*tv%P_Ref)
case ("ts_range")
call set_coord_from_TS_range(GV%Rlay, GV%g_prime, GV, US, PF, eos, tv%P_Ref)
call set_coord_from_TS_range(GV%Rlay, GV%g_prime, GV, US, PF, eos, US%RL2_T2_to_Pa*tv%P_Ref)
case ("file")
call set_coord_from_file(GV%Rlay, GV%g_prime, GV, US, PF)
case ("USER")
Expand Down
Loading

0 comments on commit 3223eb6

Please sign in to comment.