Skip to content

Commit 316678e

Browse files
committed
(*)Refactor p_ave calculation
Rearranged the calculation of the layer average pressure used in the density integrals to have one less multiply and be clearer to read. This could change answers at roundoff if REFERENCE_HEIGHT is nonzero (it is 0 by default and in all known cases) or if SSH_IN_EOS_PRESSURE_FOR_PGF is set to true. Because the former is mostly used for approximate self-consistency testing and the latter option has just been added, it is unlikely that answers will change for any production runs.
1 parent 9e28e75 commit 316678e

File tree

4 files changed

+18
-25
lines changed

4 files changed

+18
-25
lines changed

src/core/MOM_density_integrals.F90

Lines changed: 6 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -268,8 +268,7 @@ subroutine int_density_dz_generic_pcm(T, S, z_t, z_b, rho_ref, rho_0, G_e, HI, &
268268
pos = i*15+(m-2)*5
269269
T15(pos+1) = (wtT_L*T(i,j)) + (wtT_R*T(i+1,j))
270270
S15(pos+1) = (wtT_L*S(i,j)) + (wtT_R*S(i+1,j))
271-
p15(pos+1) = -GxRho * ( ((wt_L*z_t(i,j)) + (wt_R*z_t(i+1,j))) - &
272-
((wt_L*z0pres(i,j)) + (wt_R*z0pres(i+1,j))) )
271+
p15(pos+1) = -GxRho * ((wt_L*(z_t(i,j)-z0pres(i,j))) + (wt_R*(z_t(i+1,j)-z0pres(i+1,j))))
273272
do n=2,5
274273
T15(pos+n) = T15(pos+1) ; S15(pos+n) = S15(pos+1)
275274
p15(pos+n) = p15(pos+n-1) + GxRho*0.25*dz_x(m,i)
@@ -335,8 +334,7 @@ subroutine int_density_dz_generic_pcm(T, S, z_t, z_b, rho_ref, rho_0, G_e, HI, &
335334
pos = i*15+(m-2)*5
336335
T15(pos+1) = (wtT_L*T(i,j)) + (wtT_R*T(i,j+1))
337336
S15(pos+1) = (wtT_L*S(i,j)) + (wtT_R*S(i,j+1))
338-
p15(pos+1) = -GxRho * ( ((wt_L*z_t(i,j)) + (wt_R*z_t(i,j+1))) - &
339-
((wt_L*z0pres(i,j)) + (wt_R*z0pres(i,j+1))) )
337+
p15(pos+1) = -GxRho * ((wt_L*(z_t(i,j)-z0pres(i,j))) + (wt_R*(z_t(i,j+1)-z0pres(i,j+1))))
340338
do n=2,5
341339
T15(pos+n) = T15(pos+1) ; S15(pos+n) = S15(pos+1)
342340
p15(pos+n) = p15(pos+n-1) + GxRho*0.25*dz_y(m,i)
@@ -627,8 +625,7 @@ subroutine int_density_dz_generic_plm(k, tv, T_t, T_b, S_t, S_b, e, rho_ref, &
627625
S15(pos+1) = (w_left*Stl) + (w_right*Str)
628626
S15(pos+5) = (w_left*Sbl) + (w_right*Sbr)
629627

630-
p15(pos+1) = -GxRho * ( ((w_left*e(i,j,K)) + (w_right*e(i+1,j,K))) - &
631-
((w_left*z0pres(i,j)) + (w_right*z0pres(i+1,j))) )
628+
p15(pos+1) = -GxRho * ((w_left*(e(i,j,K)-z0pres(i,j))) + (w_right*(e(i+1,j,K)-z0pres(i+1,j))))
632629

633630
! Pressure
634631
do n=2,5
@@ -724,8 +721,7 @@ subroutine int_density_dz_generic_plm(k, tv, T_t, T_b, S_t, S_b, e, rho_ref, &
724721
S15(pos+1) = (w_left*Stl) + (w_right*Str)
725722
S15(pos+5) = (w_left*Sbl) + (w_right*Sbr)
726723

727-
p15(pos+1) = -GxRho * ( ((w_left*e(i,j,K)) + (w_right*e(i,j+1,K))) - &
728-
((w_left*z0pres(i,j)) + (w_right*z0pres(i,j+1))) )
724+
p15(pos+1) = -GxRho * ((w_left*(e(i,j,K)-z0pres(i,j))) + (w_right*(e(i,j+1,K)-z0pres(i,j+1))))
729725

730726
! Pressure
731727
do n=2,5
@@ -1037,8 +1033,7 @@ subroutine int_density_dz_generic_ppm(k, tv, T_t, T_b, S_t, S_b, e, &
10371033
dz_x(m,i) = (w_left*(e(i,j,K) - e(i,j,K+1))) + (w_right*(e(i+1,j,K) - e(i+1,j,K+1)))
10381034

10391035
pos = i*15+(m-2)*5
1040-
p15(pos+1) = -GxRho * ( ((w_left*e(i,j,K)) + (w_right*e(i+1,j,K))) - &
1041-
((w_left*z0pres(i,j)) + (w_right*z0pres(i+1,j))) )
1036+
p15(pos+1) = -GxRho * ((w_left*(e(i,j,K)-z0pres(i,j))) + (w_right*(e(i+1,j,K)-z0pres(i+1,j))))
10421037
do n=2,5
10431038
p15(pos+n) = p15(pos+n-1) + GxRho*0.25*dz_x(m,i)
10441039
enddo
@@ -1143,8 +1138,7 @@ subroutine int_density_dz_generic_ppm(k, tv, T_t, T_b, S_t, S_b, e, &
11431138
dz_y(m,i) = (w_left*(e(i,j,K) - e(i,j,K+1))) + (w_right*(e(i,j+1,K) - e(i,j+1,K+1)))
11441139

11451140
pos = i*15+(m-2)*5
1146-
p15(pos+1) = -GxRho * ( ((w_left*e(i,j,K)) + (w_right*e(i,j+1,K))) - &
1147-
((w_left*z0pres(i,j)) + (w_right*z0pres(i,j+1))) )
1141+
p15(pos+1) = -GxRho * ((w_left*(e(i,j,K)-z0pres(i,j))) + (w_right*(e(i,j+1,K)-z0pres(i,j+1))))
11481142
do n=2,5
11491143
p15(pos+n) = p15(pos+n-1) + GxRho*0.25*dz_y(m,i)
11501144
enddo

src/equation_of_state/MOM_EOS_Wright.F90

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -592,8 +592,8 @@ subroutine int_density_dz_wright(T, S, z_t, z_b, rho_ref, rho_0, G_e, HI, &
592592
lambda = (wtT_L*lambda_2d(i,j)) + (wtT_R*lambda_2d(i+1,j))
593593

594594
dz = (wt_L*(z_t(i,j) - z_b(i,j))) + (wt_R*(z_t(i+1,j) - z_b(i+1,j)))
595-
p_ave = -GxRho*(0.5*((wt_L*(z_t(i,j)+z_b(i,j))) + (wt_R*(z_t(i+1,j)+z_b(i+1,j)))) - &
596-
((wt_L*z0pres(i,j)) + (wt_R*z0pres(i+1,j))))
595+
p_ave = -GxRho*((wt_L * (0.5*(z_t(i,j)+z_b(i,j)) - z0pres(i,j))) + &
596+
(wt_R * (0.5*(z_t(i+1,j)+z_b(i+1,j)) - z0pres(i+1,j))))
597597

598598
I_al0 = 1.0 / al0
599599
I_Lzz = 1.0 / (p0 + (lambda * I_al0) + p_ave)
@@ -634,8 +634,8 @@ subroutine int_density_dz_wright(T, S, z_t, z_b, rho_ref, rho_0, G_e, HI, &
634634
lambda = (wtT_L*lambda_2d(i,j)) + (wtT_R*lambda_2d(i,j+1))
635635

636636
dz = (wt_L*(z_t(i,j) - z_b(i,j))) + (wt_R*(z_t(i,j+1) - z_b(i,j+1)))
637-
p_ave = -GxRho*(0.5*((wt_L*(z_t(i,j)+z_b(i,j))) + (wt_R*(z_t(i,j+1)+z_b(i,j+1)))) - &
638-
((wt_L*z0pres(i,j)) + (wt_R*z0pres(i,j+1))))
637+
p_ave = -GxRho*((wt_L*(0.5*(z_t(i,j)+z_b(i,j))-z0pres(i,j))) + &
638+
(wt_R*(0.5*(z_t(i,j+1)+z_b(i,j+1))-z0pres(i,j+1))))
639639

640640
I_al0 = 1.0 / al0
641641
I_Lzz = 1.0 / (p0 + (lambda * I_al0) + p_ave)

src/equation_of_state/MOM_EOS_Wright_full.F90

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -597,8 +597,8 @@ subroutine int_density_dz_wright_full(T, S, z_t, z_b, rho_ref, rho_0, G_e, HI, &
597597
lambda = (wtT_L*lambda_2d(i,j)) + (wtT_R*lambda_2d(i+1,j))
598598

599599
dz = (wt_L*(z_t(i,j) - z_b(i,j))) + (wt_R*(z_t(i+1,j) - z_b(i+1,j)))
600-
p_ave = -GxRho*(0.5*((wt_L*(z_t(i,j)+z_b(i,j))) + (wt_R*(z_t(i+1,j)+z_b(i+1,j)))) - &
601-
((wt_L*z0pres(i,j)) + (wt_R*z0pres(i+1,j))))
600+
p_ave = -GxRho*((wt_L * (0.5*(z_t(i,j)+z_b(i,j)) - z0pres(i,j))) + &
601+
(wt_R * (0.5*(z_t(i+1,j)+z_b(i+1,j)) - z0pres(i+1,j))))
602602

603603
I_al0 = 1.0 / al0
604604
I_Lzz = 1.0 / ((p0 + p_ave) + lambda * I_al0)
@@ -639,8 +639,8 @@ subroutine int_density_dz_wright_full(T, S, z_t, z_b, rho_ref, rho_0, G_e, HI, &
639639
lambda = (wtT_L*lambda_2d(i,j)) + (wtT_R*lambda_2d(i,j+1))
640640

641641
dz = (wt_L*(z_t(i,j) - z_b(i,j))) + (wt_R*(z_t(i,j+1) - z_b(i,j+1)))
642-
p_ave = -GxRho*(0.5*((wt_L*(z_t(i,j)+z_b(i,j))) + (wt_R*(z_t(i,j+1)+z_b(i,j+1)))) - &
643-
((wt_L*z0pres(i,j)) + (wt_R*z0pres(i,j+1))))
642+
p_ave = -GxRho*((wt_L*(0.5*(z_t(i,j)+z_b(i,j))-z0pres(i,j))) + &
643+
(wt_R*(0.5*(z_t(i,j+1)+z_b(i,j+1))-z0pres(i,j+1))))
644644

645645
I_al0 = 1.0 / al0
646646
I_Lzz = 1.0 / ((p0 + p_ave) + lambda * I_al0)

src/equation_of_state/MOM_EOS_Wright_red.F90

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -599,8 +599,8 @@ subroutine int_density_dz_wright_red(T, S, z_t, z_b, rho_ref, rho_0, G_e, HI, &
599599
lambda = (wtT_L*lambda_2d(i,j)) + (wtT_R*lambda_2d(i+1,j))
600600

601601
dz = (wt_L*(z_t(i,j) - z_b(i,j))) + (wt_R*(z_t(i+1,j) - z_b(i+1,j)))
602-
p_ave = -GxRho*(0.5*((wt_L*(z_t(i,j)+z_b(i,j))) + (wt_R*(z_t(i+1,j)+z_b(i+1,j)))) - &
603-
((wt_L*z0pres(i,j)) + (wt_R*z0pres(i+1,j))))
602+
p_ave = -GxRho*((wt_L * (0.5*(z_t(i,j)+z_b(i,j)) - z0pres(i,j))) + &
603+
(wt_R * (0.5*(z_t(i+1,j)+z_b(i+1,j)) - z0pres(i+1,j))))
604604

605605
I_al0 = 1.0 / al0
606606
I_Lzz = 1.0 / ((p0 + p_ave) + lambda * I_al0)
@@ -641,9 +641,8 @@ subroutine int_density_dz_wright_red(T, S, z_t, z_b, rho_ref, rho_0, G_e, HI, &
641641
lambda = (wtT_L*lambda_2d(i,j)) + (wtT_R*lambda_2d(i,j+1))
642642

643643
dz = (wt_L*(z_t(i,j) - z_b(i,j))) + (wt_R*(z_t(i,j+1) - z_b(i,j+1)))
644-
p_ave = -GxRho*(0.5*((wt_L*(z_t(i,j)+z_b(i,j))) + (wt_R*(z_t(i,j+1)+z_b(i,j+1)))) - &
645-
((wt_L*z0pres(i,j)) + (wt_R*z0pres(i,j+1))))
646-
644+
p_ave = -GxRho*((wt_L*(0.5*(z_t(i,j)+z_b(i,j))-z0pres(i,j))) + &
645+
(wt_R*(0.5*(z_t(i,j+1)+z_b(i,j+1))-z0pres(i,j+1))))
647646

648647
I_al0 = 1.0 / al0
649648
I_Lzz = 1.0 / ((p0 + p_ave) + lambda * I_al0)

0 commit comments

Comments
 (0)