Skip to content

Commit c618090

Browse files
committed
Work in rescaled units in write_energy
Revised write_energy() and accumulate_net_input() to work more extensively in dimensionally rescaled variables by using the new unscale arguments to the reproducing_sum functions. As a result of these changes, 15 rescaling factors were eliminated or moved toward the end of write_energy(). All answers are bitwise identical.
1 parent 5d0bf79 commit c618090

File tree

1 file changed

+68
-76
lines changed

1 file changed

+68
-76
lines changed

src/diagnostics/MOM_sum_output.F90

+68-76
Original file line numberDiff line numberDiff line change
@@ -340,8 +340,8 @@ subroutine write_energy(u, v, h, tv, day, n, G, GV, US, CS, tracer_CSp, dt_forci
340340
real :: areaTm(SZI_(G),SZJ_(G)) ! A masked version of areaT [L2 ~> m2].
341341
real :: KE(SZK_(GV)) ! The total kinetic energy of a layer [J].
342342
real :: PE(SZK_(GV)+1)! The available potential energy of an interface [J].
343-
real :: KE_tot ! The total kinetic energy [J].
344-
real :: PE_tot ! The total available potential energy [J].
343+
real :: KE_tot ! The total kinetic energy [R Z L4 T-2 ~> J].
344+
real :: PE_tot ! The total available potential energy [R Z L4 T-2 ~> J].
345345
real :: Z_0APE(SZK_(GV)+1) ! The uniform depth which overlies the same
346346
! volume as is below an interface [Z ~> m].
347347
real :: H_0APE(SZK_(GV)+1) ! A version of Z_0APE, converted to m, usually positive [m].
@@ -351,9 +351,10 @@ subroutine write_energy(u, v, h, tv, day, n, G, GV, US, CS, tracer_CSp, dt_forci
351351
! the total mass of the ocean [m2 s-2].
352352
real :: vol_lay(SZK_(GV)) ! The volume of fluid in a layer [Z L2 ~> m3].
353353
real :: volbelow ! The volume of all layers beneath an interface [Z L2 ~> m3].
354-
real :: mass_lay(SZK_(GV)) ! The mass of fluid in a layer [kg].
354+
real :: mass_lay(SZK_(GV)) ! The mass of fluid in a layer [R Z L2 ~> kg].
355+
real :: mass_tot_RZL2 ! The total mass of the ocean [R Z L2 ~> kg].
355356
real :: mass_tot ! The total mass of the ocean [kg].
356-
real :: vol_tot ! The total ocean volume [m3].
357+
real :: vol_tot ! The total ocean volume [Z L2 ~> m3].
357358
real :: mass_chg ! The change in total ocean mass of fresh water since
358359
! the last call to this subroutine [kg].
359360
real :: mass_anom ! The change in fresh water that cannot be accounted for
@@ -399,14 +400,11 @@ subroutine write_energy(u, v, h, tv, day, n, G, GV, US, CS, tracer_CSp, dt_forci
399400
real, dimension(SZI_(G),SZJ_(G),SZK_(GV)) :: &
400401
tmp1 ! A temporary array used in reproducing sums [various]
401402
real, dimension(SZI_(G),SZJ_(G),SZK_(GV)+1) :: &
402-
PE_pt ! The potential energy at each point [J].
403+
PE_pt ! The potential energy at each point [R Z L4 T-2 ~> J].
403404
real, dimension(SZI_(G),SZJ_(G)) :: &
404-
Temp_int, Salt_int ! Layer and cell integrated heat and salt [J] and [g Salt].
405-
real :: HL2_to_kg ! A conversion factor from a thickness-volume to mass [kg H-1 L-2 ~> kg m-3 or 1]
406-
real :: KE_scale_factor ! The combination of unit rescaling factors in the kinetic energy
407-
! calculation [kg T2 H-1 L-2 s-2 ~> kg m-3 or 1]
408-
real :: PE_scale_factor ! The combination of unit rescaling factors in the potential energy
409-
! calculation [kg T2 R-1 Z-1 L-2 s-2 ~> 1]
405+
Temp_int, Salt_int ! Layer and cell integrated heat and salt [Q R Z L2 ~> J] and [g Salt].
406+
real :: RZL4_to_J ! The combination of unit rescaling factors to convert the spatially integrated
407+
! kinetic or potential energies into mks units [T2 kg m2 R-1 Z-1 L-4 s-2 ~> 1]
410408
integer :: num_nc_fields ! The number of fields that will actually go into
411409
! the NetCDF file.
412410
integer :: i, j, k, is, ie, js, je, nz, m, Isq, Ieq, Jsq, Jeq, isr, ier, jsr, jer
@@ -532,7 +530,7 @@ subroutine write_energy(u, v, h, tv, day, n, G, GV, US, CS, tracer_CSp, dt_forci
532530
Isq = G%IscB ; Ieq = G%IecB ; Jsq = G%JscB ; Jeq = G%JecB
533531
isr = is - (G%isd-1) ; ier = ie - (G%isd-1) ; jsr = js - (G%jsd-1) ; jer = je - (G%jsd-1)
534532

535-
HL2_to_kg = GV%H_to_kg_m2*US%L_to_m**2
533+
RZL4_to_J = US%RZL2_to_kg*US%L_T_to_m_s**2 ! Used to unscale energies
536534

537535
if (.not.associated(CS)) call MOM_error(FATAL, &
538536
"write_energy: Module must be initialized before it is used.")
@@ -544,28 +542,21 @@ subroutine write_energy(u, v, h, tv, day, n, G, GV, US, CS, tracer_CSp, dt_forci
544542
areaTm(i,j) = G%mask2dT(i,j)*G%areaT(i,j)
545543
enddo ; enddo
546544

547-
if (GV%Boussinesq) then
548-
tmp1(:,:,:) = 0.0
549-
do k=1,nz ; do j=js,je ; do i=is,ie
550-
tmp1(i,j,k) = h(i,j,k) * (HL2_to_kg*areaTm(i,j))
551-
enddo ; enddo ; enddo
545+
tmp1(:,:,:) = 0.0
546+
do k=1,nz ; do j=js,je ; do i=is,ie
547+
tmp1(i,j,k) = h(i,j,k) * (GV%H_to_RZ*areaTm(i,j))
548+
enddo ; enddo ; enddo
549+
mass_tot_RZL2 = reproducing_sum(tmp1, isr, ier, jsr, jer, sums=mass_lay, EFP_sum=mass_EFP, unscale=US%RZL2_to_kg)
552550

553-
mass_tot = reproducing_sum(tmp1, isr, ier, jsr, jer, sums=mass_lay, EFP_sum=mass_EFP)
554-
do k=1,nz ; vol_lay(k) = (US%m_to_L**2*GV%H_to_Z/GV%H_to_kg_m2)*mass_lay(k) ; enddo
551+
if (GV%Boussinesq) then
552+
do k=1,nz ; vol_lay(k) = (1.0 / GV%Rho0) * mass_lay(k) ; enddo
555553
else
556-
tmp1(:,:,:) = 0.0
557-
do k=1,nz ; do j=js,je ; do i=is,ie
558-
tmp1(i,j,k) = HL2_to_kg * h(i,j,k) * areaTm(i,j)
559-
enddo ; enddo ; enddo
560-
mass_tot = reproducing_sum(tmp1, isr, ier, jsr, jer, sums=mass_lay, EFP_sum=mass_EFP)
561-
562554
if (CS%do_APE_calc) then
563555
call find_eta(h, tv, G, GV, US, eta, dZref=G%Z_ref)
564556
do k=1,nz ; do j=js,je ; do i=is,ie
565-
tmp1(i,j,k) = US%Z_to_m*US%L_to_m**2*(eta(i,j,K)-eta(i,j,K+1)) * areaTm(i,j)
557+
tmp1(i,j,k) = (eta(i,j,K)-eta(i,j,K+1)) * areaTm(i,j)
566558
enddo ; enddo ; enddo
567-
vol_tot = reproducing_sum(tmp1, isr, ier, jsr, jer, sums=vol_lay)
568-
do k=1,nz ; vol_lay(k) = US%m_to_Z*US%m_to_L**2 * vol_lay(k) ; enddo
559+
vol_tot = reproducing_sum(tmp1, isr, ier, jsr, jer, sums=vol_lay, unscale=US%Z_to_m*US%L_to_m**2)
569560
endif
570561
endif ! Boussinesq
571562

@@ -692,7 +683,6 @@ subroutine write_energy(u, v, h, tv, day, n, G, GV, US, CS, tracer_CSp, dt_forci
692683
! Calculate the Available Potential Energy integrated over each interface. With a nonlinear
693684
! equation of state or with a bulk mixed layer this calculation is only approximate.
694685
! With an ALE model this does not make sense and should be revisited.
695-
PE_scale_factor = US%RZ_to_kg_m2*US%L_to_m**2*US%L_T_to_m_s**2
696686
PE_pt(:,:,:) = 0.0
697687
if (GV%Boussinesq) then
698688
do j=js,je ; do i=is,ie
@@ -702,7 +692,7 @@ subroutine write_energy(u, v, h, tv, day, n, G, GV, US, CS, tracer_CSp, dt_forci
702692
hint = Z_0APE(K) + (hbelow - (G%bathyT(i,j) + G%Z_ref))
703693
hbot = Z_0APE(K) - (G%bathyT(i,j) + G%Z_ref)
704694
hbot = (hbot + ABS(hbot)) * 0.5
705-
PE_pt(i,j,K) = (0.5 * PE_scale_factor * areaTm(i,j)) * (GV%Rho0*GV%g_prime(K)) * &
695+
PE_pt(i,j,K) = (0.5 * areaTm(i,j)) * (GV%Rho0*GV%g_prime(K)) * &
706696
(hint * hint - hbot * hbot)
707697
enddo
708698
enddo ; enddo
@@ -711,7 +701,7 @@ subroutine write_energy(u, v, h, tv, day, n, G, GV, US, CS, tracer_CSp, dt_forci
711701
do K=nz,1,-1
712702
hint = Z_0APE(K) + eta(i,j,K) ! eta and H_0 have opposite signs.
713703
hbot = max(Z_0APE(K) - (G%bathyT(i,j) + G%Z_ref), 0.0)
714-
PE_pt(i,j,K) = (0.5 * PE_scale_factor * areaTm(i,j) * (GV%Rho0*GV%g_prime(K))) * &
704+
PE_pt(i,j,K) = (0.5 * areaTm(i,j) * (GV%Rho0*GV%g_prime(K))) * &
715705
(hint * hint - hbot * hbot)
716706
enddo
717707
enddo ; enddo
@@ -720,47 +710,44 @@ subroutine write_energy(u, v, h, tv, day, n, G, GV, US, CS, tracer_CSp, dt_forci
720710
do K=nz,2,-1
721711
hint = Z_0APE(K) + eta(i,j,K) ! eta and H_0 have opposite signs.
722712
hbot = max(Z_0APE(K) - (G%bathyT(i,j) + G%Z_ref), 0.0)
723-
PE_pt(i,j,K) = (0.25 * PE_scale_factor * areaTm(i,j) * &
713+
PE_pt(i,j,K) = (0.25 * areaTm(i,j) * &
724714
((GV%Rlay(k)+GV%Rlay(k-1))*GV%g_prime(K))) * &
725715
(hint * hint - hbot * hbot)
726716
enddo
727717
hint = Z_0APE(1) + eta(i,j,1) ! eta and H_0 have opposite signs.
728718
hbot = max(Z_0APE(1) - (G%bathyT(i,j) + G%Z_ref), 0.0)
729-
PE_pt(i,j,1) = (0.5 * PE_scale_factor * areaTm(i,j) * (GV%Rlay(1)*GV%g_prime(1))) * &
719+
PE_pt(i,j,1) = (0.5 * areaTm(i,j) * (GV%Rlay(1)*GV%g_prime(1))) * &
730720
(hint * hint - hbot * hbot)
731721
enddo ; enddo
732722
endif
733723

734-
PE_tot = reproducing_sum(PE_pt, isr, ier, jsr, jer, sums=PE)
724+
PE_tot = reproducing_sum(PE_pt, isr, ier, jsr, jer, sums=PE, unscale=RZL4_to_J)
735725
do k=1,nz+1 ; H_0APE(K) = US%Z_to_m*Z_0APE(K) ; enddo
736726
else
737727
PE_tot = 0.0
738728
do k=1,nz+1 ; PE(K) = 0.0 ; H_0APE(K) = 0.0 ; enddo
739729
endif
740730

741-
! Calculate the Kinetic Energy integrated over each layer.
742-
KE_scale_factor = HL2_to_kg*US%L_T_to_m_s**2
731+
! Calculate the Kinetic Energy integrated over each layer.
743732
tmp1(:,:,:) = 0.0
744733
do k=1,nz ; do j=js,je ; do i=is,ie
745-
tmp1(i,j,k) = (0.25 * KE_scale_factor * (areaTm(i,j) * h(i,j,k))) * &
734+
tmp1(i,j,k) = (0.25 * GV%H_to_RZ*(areaTm(i,j) * h(i,j,k))) * &
746735
(((u(I-1,j,k)**2) + (u(I,j,k)**2)) + ((v(i,J-1,k)**2) + (v(i,J,k)**2)))
747736
enddo ; enddo ; enddo
748737

749-
KE_tot = reproducing_sum(tmp1, isr, ier, jsr, jer, sums=KE)
738+
KE_tot = reproducing_sum(tmp1, isr, ier, jsr, jer, sums=KE, unscale=RZL4_to_J)
750739

751-
toten = KE_tot + PE_tot
752-
753-
Salt = 0.0 ; Heat = 0.0
740+
! Use reproducing sums to do global integrals relate to the heat, salinity and water budgets.
754741
if (CS%use_temperature) then
755742
Temp_int(:,:) = 0.0 ; Salt_int(:,:) = 0.0
756743
do k=1,nz ; do j=js,je ; do i=is,ie
757-
Salt_int(i,j) = Salt_int(i,j) + US%S_to_ppt*tv%S(i,j,k) * &
758-
(h(i,j,k)*(HL2_to_kg * areaTm(i,j)))
759-
Temp_int(i,j) = Temp_int(i,j) + (US%Q_to_J_kg*tv%C_p * tv%T(i,j,k)) * &
760-
(h(i,j,k)*(HL2_to_kg * areaTm(i,j)))
744+
Salt_int(i,j) = Salt_int(i,j) + tv%S(i,j,k) * (h(i,j,k)*(GV%H_to_RZ * areaTm(i,j)))
745+
Temp_int(i,j) = Temp_int(i,j) + (tv%C_p * tv%T(i,j,k)) * (h(i,j,k)*(GV%H_to_RZ * areaTm(i,j)))
761746
enddo ; enddo ; enddo
762-
salt_EFP = reproducing_sum_EFP(Salt_int, isr, ier, jsr, jer, only_on_PE=.true.)
763-
heat_EFP = reproducing_sum_EFP(Temp_int, isr, ier, jsr, jer, only_on_PE=.true.)
747+
salt_EFP = reproducing_sum_EFP(Salt_int, isr, ier, jsr, jer, only_on_PE=.true., &
748+
unscale=US%RZL2_to_kg*US%S_to_ppt)
749+
heat_EFP = reproducing_sum_EFP(Temp_int, isr, ier, jsr, jer, only_on_PE=.true., &
750+
unscale=US%RZL2_to_kg*US%Q_to_J_kg)
764751

765752
! Combining the sums avoids multiple blocking all-PE updates.
766753
EFP_list(1) = salt_EFP ; EFP_list(2) = heat_EFP ; EFP_list(3) = CS%fresh_water_in_EFP
@@ -770,13 +757,11 @@ subroutine write_energy(u, v, h, tv, day, n, G, GV, US, CS, tracer_CSp, dt_forci
770757
salt_EFP = EFP_list(1) ; heat_EFP = EFP_list(2) ; CS%fresh_water_in_EFP = EFP_list(3)
771758
CS%net_salt_in_EFP = EFP_list(4) ; CS%net_heat_in_EFP = EFP_list(5)
772759

773-
Salt = EFP_to_real(salt_EFP)
774-
Heat = EFP_to_real(heat_EFP)
775760
else
776761
call EFP_sum_across_PEs(CS%fresh_water_in_EFP)
777762
endif
778763

779-
! Calculate the maximum CFL numbers.
764+
! Calculate the maximum CFL numbers.
780765
max_CFL(1:2) = 0.0
781766
do k=1,nz ; do j=js,je ; do I=Isq,Ieq
782767
CFL_Iarea = G%IareaT(i,j)
@@ -803,7 +788,12 @@ subroutine write_energy(u, v, h, tv, day, n, G, GV, US, CS, tracer_CSp, dt_forci
803788

804789
call max_across_PEs(max_CFL, 2)
805790

791+
! From this point onward, many of the calculations set or use variables in unscaled (mks) units.
792+
793+
Salt = 0.0 ; Heat = 0.0
806794
if (CS%use_temperature) then
795+
Salt = EFP_to_real(salt_EFP)
796+
Heat = EFP_to_real(heat_EFP)
807797
if (CS%previous_calls == 0) then
808798
CS%salt_prev_EFP = salt_EFP ; CS%heat_prev_EFP = heat_EFP
809799
endif
@@ -826,13 +816,15 @@ subroutine write_energy(u, v, h, tv, day, n, G, GV, US, CS, tracer_CSp, dt_forci
826816
endif
827817
mass_chg = EFP_to_real(mass_chg_EFP)
828818

819+
mass_tot = US%RZL2_to_kg * mass_tot_RZL2
829820
if (CS%use_temperature) then
830821
salin = Salt / mass_tot
831822
salin_anom = Salt_anom / mass_tot
832823
! salin_chg = Salt_chg / mass_tot
833824
temp = heat / (mass_tot*US%Q_to_J_kg*US%degC_to_C*tv%C_p)
834825
temp_anom = Heat_anom / (mass_tot*US%Q_to_J_kg*US%degC_to_C*tv%C_p)
835826
endif
827+
toten = RZL4_to_J * (KE_tot + PE_tot)
836828
En_mass = toten / mass_tot
837829

838830
call get_time(day, start_of_day, num_days)
@@ -952,9 +944,12 @@ subroutine write_energy(u, v, h, tv, day, n, G, GV, US, CS, tracer_CSp, dt_forci
952944

953945
call CS%fileenergy_nc%write_field(CS%fields(1), real(CS%ntrunc), reday)
954946
call CS%fileenergy_nc%write_field(CS%fields(2), toten, reday)
947+
do k=1,nz+1 ; PE(K) = RZL4_to_J*PE(K) ; enddo
955948
call CS%fileenergy_nc%write_field(CS%fields(3), PE, reday)
949+
do k=1,nz ; KE(k) = RZL4_to_J*KE(k) ; enddo
956950
call CS%fileenergy_nc%write_field(CS%fields(4), KE, reday)
957951
call CS%fileenergy_nc%write_field(CS%fields(5), H_0APE, reday)
952+
do k=1,nz ; mass_lay(k) = US%RZL2_to_kg*mass_lay(k) ; enddo
958953
call CS%fileenergy_nc%write_field(CS%fields(6), mass_lay, reday)
959954

960955
call CS%fileenergy_nc%write_field(CS%fields(7), mass_tot, reday)
@@ -1018,34 +1013,29 @@ subroutine accumulate_net_input(fluxes, sfc_state, tv, dt, G, US, CS)
10181013
!! to MOM_sum_output_init.
10191014
! Local variables
10201015
real, dimension(SZI_(G),SZJ_(G)) :: &
1021-
FW_in, & ! The net fresh water input, integrated over a timestep [kg].
1016+
FW_in, & ! The net fresh water input, integrated over a timestep [R Z L2 ~> kg].
10221017
salt_in, & ! The total salt added by surface fluxes, integrated
10231018
! over a time step [ppt kg].
10241019
heat_in ! The total heat added by surface fluxes, integrated
1025-
! over a time step [J].
1026-
real :: RZL2_to_kg ! A combination of scaling factors for mass [kg R-1 Z-1 L-2 ~> 1]
1027-
real :: QRZL2_to_J ! A combination of scaling factors for heat [J Q-1 R-1 Z-1 L-2 ~> 1]
1020+
! over a time step [Q R Z L2 ~> J].
10281021

10291022
type(EFP_type) :: &
10301023
FW_in_EFP, & ! The net fresh water input, integrated over a timestep
10311024
! and summed over space [kg].
10321025
salt_in_EFP, & ! The total salt added by surface fluxes, integrated
1033-
! over a time step and summed over space [ppt kg].
1026+
! over a time step and summed over space [R Z L2 ~> ppt kg].
10341027
heat_in_EFP ! The total heat added by boundary fluxes, integrated
10351028
! over a time step and summed over space [J].
10361029

10371030
integer :: i, j, is, ie, js, je, isr, ier, jsr, jer
10381031

10391032
is = G%isc ; ie = G%iec ; js = G%jsc ; je = G%jec
10401033

1041-
RZL2_to_kg = US%L_to_m**2*US%RZ_to_kg_m2
1042-
QRZL2_to_J = RZL2_to_kg*US%Q_to_J_kg
1043-
10441034
FW_in(:,:) = 0.0
10451035
if (associated(fluxes%evap)) then
10461036
if (associated(fluxes%lprec) .and. associated(fluxes%fprec)) then
10471037
do j=js,je ; do i=is,ie
1048-
FW_in(i,j) = RZL2_to_kg * dt*G%areaT(i,j)*(fluxes%evap(i,j) + &
1038+
FW_in(i,j) = dt*G%areaT(i,j)*(fluxes%evap(i,j) + &
10491039
(((fluxes%lprec(i,j) + fluxes%vprec(i,j)) + fluxes%lrunoff(i,j)) + &
10501040
(fluxes%fprec(i,j) + fluxes%frunoff(i,j))))
10511041
enddo ; enddo
@@ -1056,27 +1046,26 @@ subroutine accumulate_net_input(fluxes, sfc_state, tv, dt, G, US, CS)
10561046
endif
10571047

10581048
if (associated(fluxes%seaice_melt)) then ; do j=js,je ; do i=is,ie
1059-
FW_in(i,j) = FW_in(i,j) + RZL2_to_kg*dt * &
1060-
G%areaT(i,j) * fluxes%seaice_melt(i,j)
1049+
FW_in(i,j) = FW_in(i,j) + dt * G%areaT(i,j) * fluxes%seaice_melt(i,j)
10611050
enddo ; enddo ; endif
10621051

10631052
salt_in(:,:) = 0.0 ; heat_in(:,:) = 0.0
10641053
if (CS%use_temperature) then
10651054

10661055
if (associated(fluxes%sw)) then ; do j=js,je ; do i=is,ie
1067-
heat_in(i,j) = heat_in(i,j) + dt * QRZL2_to_J * G%areaT(i,j) * (fluxes%sw(i,j) + &
1056+
heat_in(i,j) = heat_in(i,j) + dt * G%areaT(i,j) * (fluxes%sw(i,j) + &
10681057
(fluxes%lw(i,j) + (fluxes%latent(i,j) + fluxes%sens(i,j))))
10691058
enddo ; enddo ; endif
10701059

10711060
if (associated(fluxes%seaice_melt_heat)) then ; do j=js,je ; do i=is,ie
1072-
heat_in(i,j) = heat_in(i,j) + dt * QRZL2_to_J * G%areaT(i,j) * &
1061+
heat_in(i,j) = heat_in(i,j) + dt * G%areaT(i,j) * &
10731062
fluxes%seaice_melt_heat(i,j)
10741063
enddo ; enddo ; endif
10751064

10761065
! smg: new code
10771066
! include heat content from water transport across ocean surface
10781067
! if (associated(fluxes%heat_content_lprec)) then ; do j=js,je ; do i=is,ie
1079-
! heat_in(i,j) = heat_in(i,j) + dt * QRZL2_to_J * G%areaT(i,j) * &
1068+
! heat_in(i,j) = heat_in(i,j) + dt * G%areaT(i,j) * &
10801069
! (fluxes%heat_content_lprec(i,j) + (fluxes%heat_content_fprec(i,j) &
10811070
! + (fluxes%heat_content_lrunoff(i,j) + (fluxes%heat_content_frunoff(i,j) &
10821071
! + (fluxes%heat_content_cond(i,j) + (fluxes%heat_content_vprec(i,j) &
@@ -1086,41 +1075,41 @@ subroutine accumulate_net_input(fluxes, sfc_state, tv, dt, G, US, CS)
10861075
! smg: old code
10871076
if (associated(fluxes%heat_content_evap)) then
10881077
do j=js,je ; do i=is,ie
1089-
heat_in(i,j) = heat_in(i,j) + dt * QRZL2_to_J * G%areaT(i,j) * &
1078+
heat_in(i,j) = heat_in(i,j) + dt * G%areaT(i,j) * &
10901079
(fluxes%heat_content_evap(i,j) + fluxes%heat_content_lprec(i,j) + &
10911080
fluxes%heat_content_cond(i,j) + fluxes%heat_content_fprec(i,j) + &
10921081
fluxes%heat_content_lrunoff(i,j) + fluxes%heat_content_frunoff(i,j))
10931082
enddo ; enddo
10941083
elseif (associated(tv%TempxPmE)) then
10951084
do j=js,je ; do i=is,ie
1096-
heat_in(i,j) = heat_in(i,j) + (tv%C_p * QRZL2_to_J*G%areaT(i,j)) * tv%TempxPmE(i,j)
1085+
heat_in(i,j) = heat_in(i,j) + (tv%C_p * G%areaT(i,j)) * tv%TempxPmE(i,j)
10971086
enddo ; enddo
10981087
elseif (associated(fluxes%evap)) then
10991088
do j=js,je ; do i=is,ie
1100-
heat_in(i,j) = heat_in(i,j) + (US%Q_to_J_kg*tv%C_p * sfc_state%SST(i,j)) * FW_in(i,j)
1089+
heat_in(i,j) = heat_in(i,j) + (tv%C_p * sfc_state%SST(i,j)) * FW_in(i,j)
11011090
enddo ; enddo
11021091
endif
11031092

11041093
! The following heat sources may or may not be used.
11051094
if (associated(tv%internal_heat)) then
11061095
do j=js,je ; do i=is,ie
1107-
heat_in(i,j) = heat_in(i,j) + (tv%C_p * QRZL2_to_J*G%areaT(i,j)) * tv%internal_heat(i,j)
1096+
heat_in(i,j) = heat_in(i,j) + (tv%C_p * G%areaT(i,j)) * tv%internal_heat(i,j)
11081097
enddo ; enddo
11091098
endif
11101099
if (associated(tv%frazil)) then ; do j=js,je ; do i=is,ie
1111-
heat_in(i,j) = heat_in(i,j) + QRZL2_to_J * G%areaT(i,j) * tv%frazil(i,j)
1100+
heat_in(i,j) = heat_in(i,j) + G%areaT(i,j) * tv%frazil(i,j)
11121101
enddo ; enddo ; endif
11131102
if (associated(fluxes%heat_added)) then ; do j=js,je ; do i=is,ie
1114-
heat_in(i,j) = heat_in(i,j) + QRZL2_to_J * dt*G%areaT(i,j) * fluxes%heat_added(i,j)
1103+
heat_in(i,j) = heat_in(i,j) + dt*G%areaT(i,j) * fluxes%heat_added(i,j)
11151104
enddo ; enddo ; endif
11161105
! if (associated(sfc_state%sw_lost)) then ; do j=js,je ; do i=is,ie
1117-
! heat_in(i,j) = heat_in(i,j) - US%L_to_m**2*G%areaT(i,j) * sfc_state%sw_lost(i,j)
1106+
! sfc_state%sw_lost must be in units of [Q R Z ~> J m-2]
1107+
! heat_in(i,j) = heat_in(i,j) - G%areaT(i,j) * sfc_state%sw_lost(i,j)
11181108
! enddo ; enddo ; endif
11191109

11201110
if (associated(fluxes%salt_flux)) then ; do j=js,je ; do i=is,ie
11211111
! integrate salt_flux in [R Z T-1 ~> kgSalt m-2 s-1] to give [ppt kg]
1122-
salt_in(i,j) = RZL2_to_kg * dt * &
1123-
G%areaT(i,j)*(1000.0*fluxes%salt_flux(i,j))
1112+
salt_in(i,j) = dt * G%areaT(i,j)*(1000.0*fluxes%salt_flux(i,j))
11241113
enddo ; enddo ; endif
11251114
endif
11261115

@@ -1129,9 +1118,12 @@ subroutine accumulate_net_input(fluxes, sfc_state, tv, dt, G, US, CS)
11291118
! The on-PE sums are stored here, but the sums across PEs are deferred to
11301119
! the next call to write_energy to avoid extra barriers.
11311120
isr = is - (G%isd-1) ; ier = ie - (G%isd-1) ; jsr = js - (G%jsd-1) ; jer = je - (G%jsd-1)
1132-
FW_in_EFP = reproducing_sum_EFP(FW_in, isr, ier, jsr, jer, only_on_PE=.true.)
1133-
heat_in_EFP = reproducing_sum_EFP(heat_in, isr, ier, jsr, jer, only_on_PE=.true.)
1134-
salt_in_EFP = reproducing_sum_EFP(salt_in, isr, ier, jsr, jer, only_on_PE=.true.)
1121+
FW_in_EFP = reproducing_sum_EFP(FW_in, isr, ier, jsr, jer, only_on_PE=.true., &
1122+
unscale=US%RZL2_to_kg)
1123+
heat_in_EFP = reproducing_sum_EFP(heat_in, isr, ier, jsr, jer, only_on_PE=.true., &
1124+
unscale=US%RZL2_to_kg*US%Q_to_J_kg)
1125+
salt_in_EFP = reproducing_sum_EFP(salt_in, isr, ier, jsr, jer, only_on_PE=.true., &
1126+
unscale=US%RZL2_to_kg)
11351127

11361128
CS%fresh_water_in_EFP = CS%fresh_water_in_EFP + FW_in_EFP
11371129
CS%net_salt_in_EFP = CS%net_salt_in_EFP + salt_in_EFP

0 commit comments

Comments
 (0)