Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 8 additions & 2 deletions schemes/rrtmgp/utils/rrtmgp_dry_static_energy_tendency.F90
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,8 @@ subroutine rrtmgp_dry_static_energy_tendency_run(pdel, calc_sw_heat, calc_lw_hea
logical, intent(in) :: calc_lw_heat ! Flag to calculate net longwave heating
real(kind_phys), dimension(:,:), intent(in) :: qrs ! shortwave heating rate adjusted by air pressure thickness (J Pa kg-1 s-1)
real(kind_phys), dimension(:,:), intent(in) :: qrl ! longwave heating rate adjusted by air pressure thickness (J Pa kg-1 s-1)
real(kind_phys), dimension(:,:), intent(out) :: qrs_prime ! shortwave heating rate (J kg-1 s-1)
real(kind_phys), dimension(:,:), intent(out) :: qrl_prime ! longwave heating rate (J kg-1 s-1)
real(kind_phys), dimension(:,:), intent(inout) :: qrs_prime ! shortwave heating rate (J kg-1 s-1)
real(kind_phys), dimension(:,:), intent(inout) :: qrl_prime ! longwave heating rate (J kg-1 s-1)
character(len=*), intent(out) :: errmsg
integer, intent(out) :: errflg

Expand All @@ -48,10 +48,16 @@ subroutine rrtmgp_dry_static_energy_tendency_run(pdel, calc_sw_heat, calc_lw_hea
errmsg = ''
errflg = 0

! calc_sw_heat is .true. iff dosw is .false.
! If dosw is true, use that value calculated in rrtmgp_sw_calculate_heating_rate_run
! If dosw is false, perform this calculation
if (calc_sw_heat) then
qrs_prime(:,:) = qrs(:,:) / pdel(:,:)
end if

! calc_lw_heat is .true. iff dolw is .false.
! If dolw is true, use that value calculated in rrtmgp_lw_calculate_heating_rate_run
! If dolw is false, perform this calculation
if (calc_lw_heat) then
qrl_prime(:,:) = qrl(:,:) / pdel(:,:)
end if
Expand Down
4 changes: 2 additions & 2 deletions schemes/rrtmgp/utils/rrtmgp_dry_static_energy_tendency.meta
Original file line number Diff line number Diff line change
Expand Up @@ -40,13 +40,13 @@
units = J kg-1 s-1
type = real | kind = kind_phys
dimensions = (horizontal_loop_extent, vertical_layer_dimension)
intent = out
intent = inout
[ qrl_prime ]
standard_name = tendency_of_dry_air_enthalpy_at_constant_pressure_due_to_longwave_radiation
units = J kg-1 s-1
type = real | kind = kind_phys
dimensions = (horizontal_loop_extent, vertical_layer_dimension)
intent = out
intent = inout
[ errmsg ]
standard_name = ccpp_error_message
units = none
Expand Down
14 changes: 14 additions & 0 deletions test/unit-test/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,20 @@ add_library(phys_utils ${PHYS_UTILS_SRC})
target_compile_options(phys_utils PRIVATE -ffree-line-length-none)
target_include_directories(phys_utils PUBLIC ${CMAKE_CURRENT_BINARY_DIR})

set(RRTMGP_SRC
../../schemes/rrtmgp/utils/radiation_utils.F90
../../schemes/rrtmgp/utils/radiation_tools.F90
../../schemes/rrtmgp/rrtmgp_sw_solar_var_setup.F90
../../schemes/rrtmgp/utils/rrtmgp_dry_static_energy_tendency.F90
../../schemes/rrtmgp/utils/calculate_net_heating.F90
include/interpolate_stub.F90
include/ccpp_kinds.F90
)

add_library(rrtmgp ${RRTMGP_SRC})
target_compile_options(rrtmgp PRIVATE -ffree-line-length-none)
target_include_directories(rrtmgp PUBLIC ${CMAKE_CURRENT_BINARY_DIR})

add_subdirectory(../../schemes/mmm mmm)

if(ATMOSPHERIC_PHYSICS_ENABLE_TESTS OR ATMOSPHERIC_PHYSICS_ENABLE_CODE_COVERAGE)
Expand Down
38 changes: 38 additions & 0 deletions test/unit-test/include/interpolate_stub.F90
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
module interpolate_data
use ccpp_kinds, only: kind_phys
public :: lininterp_init
public :: lininterp

integer, public, parameter :: extrap_method_bndry = 1
public :: interp_type
type interp_type
real(kind_phys), pointer :: wgts(:)
real(kind_phys), pointer :: wgtn(:)
integer, pointer :: jjm(:)
integer, pointer :: jjp(:)
end type interp_type

contains
subroutine lininterp_init(yin, nin, yout, nout, extrap_method, interp_wgts)
integer, intent(in) :: nin
integer, intent(in) :: nout
real(kind_phys), intent(in) :: yin(:) ! input mesh
real(kind_phys), intent(in) :: yout(:) ! output mesh
integer, intent(in) :: extrap_method ! if 0 set values outside output grid to 0
! if 1 set to boundary value
! if 2 set to cyclic boundaries
type (interp_type), intent(out) :: interp_wgts

! routine is a stub
end subroutine lininterp_init

subroutine lininterp(arrin, nin, arrout, nout, interp_wgts)
integer, intent(in) :: nin, nout
real(kind_phys), intent(in) :: arrin(nin)
real(kind_phys), intent(out) :: arrout(nout)
type (interp_type) :: interp_wgts

! routine is a stub
end subroutine lininterp

end module interpolate_data
1 change: 1 addition & 0 deletions test/unit-test/tests/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
add_subdirectory(utilities)
add_subdirectory(phys_utils)
add_subdirectory(mmm)
add_subdirectory(rrtmgp)
8 changes: 8 additions & 0 deletions test/unit-test/tests/rrtmgp/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
add_pfunit_ctest(rrtmgp_tests
TEST_SOURCES test_radiation_utils.pf
TEST_SOURCES test_radiation_tools.pf
TEST_SOURCES test_rrtmgp_sw_solar_var_setup.pf
TEST_SOURCES test_rrtmgp_dry_static_energy_tendency.pf
TEST_SOURCES test_calculate_net_heating.pf
LINK_LIBRARIES rrtmgp
)
72 changes: 72 additions & 0 deletions test/unit-test/tests/rrtmgp/test_calculate_net_heating.pf
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
@test
subroutine calculate_net_heating()
use funit
use ccpp_kinds, only: kind_phys
use calculate_net_heating, only: calculate_net_heating_run

integer :: errflg, ncol
character(len=512) :: errmsg
real(kind_phys) :: qrl(1,2), qrs(1,2)
real(kind_phys) :: qrl_prime(1,2), qrs_prime(1,2)
real(kind_phys) :: fsns(1), fsnt(1), flns(1), flnt(1)
real(kind_phys) :: rad_heat(1,2)
real(kind_phys) :: net_flx(1)

qrl_prime(1,1) = 10._kind_phys
qrl_prime(1,2) = 20._kind_phys
qrs_prime(1,1) = 30._kind_phys
qrs_prime(1,2) = 40._kind_phys
fsns(1) = 1._kind_phys
fsnt(1) = 2._kind_phys
flns(1) = 3._kind_phys
flnt(1) = 4._kind_phys
ncol = 1

call calculate_net_heating_run(ncol, qrl_prime, qrs_prime, &
.false., fsns, fsnt, flns, flnt, rad_heat, &
net_flx, errmsg, errflg)

@assertEqual('', errmsg)
@assertEqual(0, errflg)
@assertEqual(40._kind_phys, rad_heat(1,1))
@assertEqual(60._kind_phys, rad_heat(1,2))
@assertEqual(0._kind_phys, net_flx(1))

end subroutine calculate_net_heating

@test
subroutine calculate_net_heating_offline()
use funit
use ccpp_kinds, only: kind_phys
use calculate_net_heating, only: calculate_net_heating_run

integer :: errflg, ncol
character(len=512) :: errmsg
real(kind_phys) :: qrl(1,2), qrs(1,2)
real(kind_phys) :: qrl_prime(1,2), qrs_prime(1,2)
real(kind_phys) :: fsns(1), fsnt(1), flns(1), flnt(1)
real(kind_phys) :: rad_heat(1,2)
real(kind_phys) :: net_flx(1)

qrl_prime(1,1) = 10._kind_phys
qrl_prime(1,2) = 20._kind_phys
qrs_prime(1,1) = 30._kind_phys
qrs_prime(1,2) = 40._kind_phys
fsns(1) = 1._kind_phys
fsnt(1) = 2._kind_phys
flns(1) = 3._kind_phys
flnt(1) = 4._kind_phys
ncol = 1
rad_heat = 0._kind_phys

call calculate_net_heating_run(ncol, qrl_prime, qrs_prime, &
.true., fsns, fsnt, flns, flnt, rad_heat, &
net_flx, errmsg, errflg)

@assertEqual('', errmsg)
@assertEqual(0, errflg)
@assertEqual(0._kind_phys, rad_heat(1,1))
@assertEqual(0._kind_phys, rad_heat(1,2))
@assertEqual(0._kind_phys, net_flx(1))

end subroutine calculate_net_heating_offline
63 changes: 63 additions & 0 deletions test/unit-test/tests/rrtmgp/test_radiation_tools.pf
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
@test
subroutine tlev_topat1()
use funit
use ccpp_kinds, only: kind_phys
use radiation_tools, only: cmp_tlev

integer :: ncol, nlev
real(kind_phys) :: minp
real(kind_phys) :: tsfc(1)
real(kind_phys) :: p_lay(1,2), t_lay(1,2)
real(kind_phys) :: p_lev(1,3), t_lev(1,3)

ncol = 1
nlev = 2

tsfc = 300._kind_phys
minp = 20._kind_phys
p_lev(1,1) = 10._kind_phys
p_lev(1,2) = 30._kind_phys
p_lev(1,3) = 50._kind_phys
t_lay(1,1) = 280._kind_phys
t_lay(1,2) = 290._kind_phys
p_lay(1,1) = 12._kind_phys
p_lay(1,2) = 35._kind_phys

call cmp_tlev(ncol,nlev,minp,p_lay,t_lay,p_lev,tsfc,t_lev)

@assertEqual(280._kind_phys, t_lev(1,1))
@assertEqual(288.55993351768552_kind_phys, t_lev(1,2))
@assertEqual(300._kind_phys, t_lev(1,3))
end subroutine tlev_topat1

@test
subroutine tlev_bottomat1()
use funit
use ccpp_kinds, only: kind_phys
use radiation_tools, only: cmp_tlev

integer :: ncol, nlev
real(kind_phys) :: minp
real(kind_phys) :: tsfc(1)
real(kind_phys) :: p_lay(1,2), t_lay(1,2)
real(kind_phys) :: p_lev(1,3), t_lev(1,3)

ncol = 1
nlev = 2

tsfc = 300._kind_phys
minp = 20._kind_phys
p_lev(1,3) = 10._kind_phys
p_lev(1,2) = 30._kind_phys
p_lev(1,1) = 50._kind_phys
t_lay(1,2) = 280._kind_phys
t_lay(1,1) = 290._kind_phys
p_lay(1,2) = 12._kind_phys
p_lay(1,1) = 35._kind_phys

call cmp_tlev(ncol,nlev,minp,p_lay,t_lay,p_lev,tsfc,t_lev)

@assertEqual(300._kind_phys, t_lev(1,1))
@assertEqual(288.55993351768552_kind_phys, t_lev(1,2))
@assertEqual(280._kind_phys, t_lev(1,3))
end subroutine tlev_bottomat1
Loading
Loading