Skip to content

Commit b740f05

Browse files
committed
resolved top_lev bug, only integrate energy up to top_lev
1 parent fbcaf32 commit b740f05

2 files changed

Lines changed: 10 additions & 60 deletions

File tree

src/physics/cam/clubb_intr.F90

Lines changed: 9 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -2493,13 +2493,15 @@ subroutine clubb_tend_cam( state, ptend_all, pbuf, hdtime, &
24932493
qvtend, &
24942494
qctend, &
24952495
inctend, &
2496-
clubb_s, &
24972496
thv, & ! virtual potential temperature [K]
24982497
th ! potential temperature [K]
24992498

25002499
real(r8), dimension(pcols,pverp) :: &
25012500
rho ! Midpoint density in CAM [kg/m^3]
25022501

2502+
real(r8), dimension(pcols,nzt_clubb) :: &
2503+
clubb_s ! diagnosed dry static energy from clubb
2504+
25032505
real(r8) :: &
25042506
invrs_dz_g, & ! Inverse of layer thickness [1/m]
25052507
inv_exner_tmp, & ! Inverse exner function consistent with CLUBB [-]
@@ -4065,33 +4067,16 @@ subroutine clubb_tend_cam( state, ptend_all, pbuf, hdtime, &
40654067
end do
40664068
end if
40674069

4068-
!---- TODO: there seems to a an above top_lev interaction here that changes answers.
4069-
! The error occured because we were zeroing out the [1:top_lev-1] values in
4070-
! in rcm (when it still contained those levels), when it should've been
4071-
! set to state_loc%q(:,:,ixcldliq) and unchanged by clubb.
40724070
! Compute static energy using CLUBB's variables
4073-
!$acc parallel loop gang vector collapse(2) default(present)
4074-
do k = 1, top_lev-1
4075-
do i = 1, ncol
4076-
4077-
! This can be simplified algebraically, but left like this to maintain BFBness
4078-
clubb_s(i,k) = cpairv(i,k,lchnk) * state_loc%t(i,k) - latvap * state_loc%q(i,k,ixcldliq) &
4079-
+ latvap * 0._r8 & ! error kept for BFBness
4080-
!+ latvap * state_loc%q(i,k,ixcldliq) & ! correct line
4081-
+ gravit * state_loc%zm(i,k) + state_loc%phis(i)
4082-
end do
4083-
end do
4084-
40854071
!$acc parallel loop gang vector collapse(2) default(present)
40864072
do k = top_lev, pver
40874073
do i = 1, ncol
40884074
k_clubb = k + 1 - top_lev
4089-
clubb_s(i,k) = cpairv(i,k,lchnk) * thlm(i,k_clubb) / invrs_exner_zt(i,k_clubb) &
4075+
clubb_s(i,k_clubb) = cpairv(i,k,lchnk) * thlm(i,k_clubb) / invrs_exner_zt(i,k_clubb) &
40904076
+ latvap * rcm(i,k_clubb) &
40914077
+ gravit * state_loc%zm(i,k) + state_loc%phis(i)
40924078
end do
40934079
end do
4094-
!--------------------------------- END TODO ---------------------------------
40954080

40964081
! Section below is concentrated on energy fixing for conservation.
40974082
! because CLUBB and CAM's thermodynamic variables are different.
@@ -4121,36 +4106,20 @@ subroutine clubb_tend_cam( state, ptend_all, pbuf, hdtime, &
41214106
wv_b = 0._r8
41224107
wl_b = 0._r8
41234108

4124-
!---- TODO: there seems to a an above top_lev interaction here that changes answers.
4125-
! The error occured because we were zeroing out the [1:top_lev-1] values in
4126-
! in rcm (when it still contained those levels), when it should've been
4127-
! set to state_loc%q(:,:,ixcldliq) and unchanged by clubb.
4128-
do k = 1, top_lev-1
4129-
! Compute integrals for static energy, kinetic energy, water vapor, and liquid water
4130-
! after CLUBB is called. This is for energy conservation purposes.
4131-
se_a = se_a + clubb_s(i,k)*state_loc%pdel(i,k)*rga
4132-
ke_a = ke_a + 0.5_r8*(state_loc%u(i,k)**2+state_loc%v(i,k)**2)*state_loc%pdel(i,k)*rga
4133-
wv_a = wv_a + ( state_loc%q(i,k,ixq) + state_loc%q(i,k,ixcldliq) ) * state_loc%pdeldry(i,k) * rga ! error kept for BFBness
4134-
wl_a = wl_a + 0.0_r8 ! error kept for BFBness
4135-
!wv_a = wv_a + state_loc%q(i,k,ixq)*state_loc%pdeldry(i,k)*rga ! correct way
4136-
!wl_a = wl_a + state_loc%q(i,k,ixcldliq)*state_loc%pdeldry(i,k)*rga ! correct way
4137-
end do
4138-
41394109
! Compute integrals for static energy, kinetic energy, water vapor, and liquid water
41404110
! after CLUBB is called. This is for energy conservation purposes.
41414111
do k = top_lev, pver
41424112
k_clubb = k + 1 - top_lev
4143-
se_a = se_a + clubb_s(i,k)*state_loc%pdel(i,k)*rga
4113+
se_a = se_a + clubb_s(i,k_clubb)*state_loc%pdel(i,k)*rga
41444114
ke_a = ke_a + 0.5_r8*(um(i,k_clubb)**2+vm(i,k_clubb)**2)*state_loc%pdel(i,k)*rga
41454115
wv_a = wv_a + (rtm(i,k_clubb)-rcm(i,k_clubb))*state_loc%pdeldry(i,k)*rga
41464116
wl_a = wl_a + (rcm(i,k_clubb))*state_loc%pdeldry(i,k)*rga
41474117
end do
4148-
!--------------------------------- END TODO ---------------------------------
41494118

41504119
! Based on these integrals, compute the total energy after CLUBB call
41514120
te_a = se_a + ke_a + (latvap+latice) * wv_a + latice * wl_a
41524121

4153-
do k = 1, pver
4122+
do k = top_lev, pver
41544123
! Do the same as above, but for before CLUBB was called.
41554124
se_b = se_b + state_loc%s(i,k)*state_loc%pdel(i,k)*rga
41564125
ke_b = ke_b + 0.5_r8*(state_loc%u(i,k)**2+state_loc%v(i,k)**2)*state_loc%pdel(i,k)*rga
@@ -4185,7 +4154,8 @@ subroutine clubb_tend_cam( state, ptend_all, pbuf, hdtime, &
41854154
do i = 1, ncol
41864155

41874156
do k = clubbtop(i), pver
4188-
clubb_s(i,k) = clubb_s(i,k) - se_dis(i) * gravit
4157+
k_clubb = k + 1 - top_lev
4158+
clubb_s(i,k_clubb) = clubb_s(i,k_clubb) - se_dis(i) * gravit
41894159
end do
41904160
! convert to units of +ve [K]
41914161
se_dis(i) = -1._r8 * se_dis(i) * gravit * invrs_cpairv(i,pver)
@@ -4309,27 +4279,8 @@ subroutine clubb_tend_cam( state, ptend_all, pbuf, hdtime, &
43094279
endif
43104280
endif
43114281

4312-
43134282
call physics_ptend_init( ptend_loc, state%psetcols, 'clubb', ls=.true., lu=.true., lv=.true., lq=lq )
43144283

4315-
!---- TODO: there seems to a an above top_lev interaction here that changes answers.
4316-
! The error occured because we were zeroing out the [1:top_lev-1] values in
4317-
! in rcm (when it still contained those levels), when it should've been
4318-
! set to state_loc%q(:,:,ixcldliq) and unchanged by clubb. Had it been set correctly
4319-
! the ptend_loc%q terms would simplify to zero. I've left the (erroneous?) interaction
4320-
! for now to maintain BFBness
4321-
do k = 1, top_lev-1
4322-
do i = 1, ncol
4323-
ptend_loc%u(i,k) = 0.0_r8
4324-
ptend_loc%v(i,k) = 0.0_r8
4325-
ptend_loc%q(i,k,ixq) = ( state_loc%q(i,k,ixcldliq)) * invrs_hdtime ! error kept for BFBness
4326-
ptend_loc%q(i,k,ixcldliq) = ( - state_loc%q(i,k,ixcldliq)) * invrs_hdtime ! error kept for BFBness
4327-
! ptend_loc%q(i,k,ixq) = 0.0_r8 ! correct line
4328-
! ptend_loc%q(i,k,ixcldliq) = 0.0_r8 ! correct line
4329-
ptend_loc%s(i,k) = (clubb_s(i,k) - state_loc%s(i,k)) * invrs_hdtime ! Tendency of static energy
4330-
end do
4331-
end do
4332-
43334284
do k = top_lev, pver
43344285
do i = 1, ncol
43354286
k_clubb = k + 1 - top_lev
@@ -4338,10 +4289,9 @@ subroutine clubb_tend_cam( state, ptend_all, pbuf, hdtime, &
43384289
ptend_loc%q(i,k,ixq) = ( rtm(i,k_clubb) - rcm(i,k_clubb) &
43394290
-state_loc%q(i,k,ixq) ) * invrs_hdtime ! water vapor
43404291
ptend_loc%q(i,k,ixcldliq) = ( rcm(i,k_clubb) - state_loc%q(i,k,ixcldliq)) * invrs_hdtime ! Tendency of liquid water
4341-
ptend_loc%s(i,k) = ( clubb_s(i,k) - state_loc%s(i,k)) * invrs_hdtime ! Tendency of static energy
4292+
ptend_loc%s(i,k) = ( clubb_s(i,k_clubb) - state_loc%s(i,k)) * invrs_hdtime ! Tendency of static energy
43424293
end do
43434294
end do
4344-
!--------------------------------- END TODO ---------------------------------
43454295

43464296
invrs_macmic_num_steps = 1.0_r8 / REAL(cld_macmic_num_steps,r8)
43474297

src/physics/clubb

Submodule clubb updated 56 files

0 commit comments

Comments
 (0)