Skip to content

Commit

Permalink
improve documentation with interpolation
Browse files Browse the repository at this point in the history
  • Loading branch information
AdelekeBankole committed Sep 20, 2024
1 parent 674f491 commit 95b1f77
Showing 1 changed file with 25 additions and 20 deletions.
45 changes: 25 additions & 20 deletions tests/test_CAM_interface/test_cam_interface.f90
Original file line number Diff line number Diff line change
Expand Up @@ -63,8 +63,8 @@ subroutine test_interp_to_sam_match(test_name)
end subroutine test_interp_to_sam_match

subroutine test_interp_to_sam_one(test_name)
!! Check interpolation to SAM grid by interpolating variable of value 1.0
!! Define a CAM grid from 1111.0 to 10.0
!! Check interpolation to SAM grid by setting up a coarse CAM grid with every variable being 1.0
!! interpolating to a new grid should also have of value 1.0 everywhere.

character(len=*), intent(in) :: test_name

Expand All @@ -74,6 +74,7 @@ subroutine test_interp_to_sam_one(test_name)
real(dp), dimension(4) :: ps_cam
real(dp), dimension(4, 30) :: var_sam, var_sam_exp

! Set up a coarse CAM grid of 4 columns of pressures [1000, 500, 10] hPa with surface pressure 1111 hPa
p_cam = reshape((/ 1000.0, 1000.0, 1000.0, 1000.0, 500.0, 500.0, 500.0, 500.0, 10.0, 10.0, 10.0, 10.0 /), (/ 4, 3 /))
ps_cam = (/ 1111.0, 1111.0, 1111.0, 1111.0/)

Expand All @@ -89,8 +90,8 @@ end subroutine test_interp_to_sam_one

subroutine test_interp_to_sam_pres(test_name)
!! Check interpolation to SAM grid by interpolating pressure to pressure
!! Set top of CAM to 1.0d-4
!! => should match pres from SAM
!! Use a coarse CAM grid of 3 cells and 4 columns
!! => expected variable on SAM grid should be pressure at that point

character(len=*), intent(in) :: test_name

Expand All @@ -108,22 +109,25 @@ subroutine test_interp_to_sam_pres(test_name)
! Fetch SAM grid data
call fetch_sam_data(pres_sam, presi_sam, gamaz_sam, rho_sam, z_sam)

p_cam(:, 1) = pres_sam(5)
p_cam(:, 2) = pres_sam(10)
p_cam(:, 3) = 1.0d-4
! Set up coarse CAM grid with surface pressure equal to SAM surface,
! a top pressure of 1.0d-4 above the SAM grid, and other at 10 and 20 from the SAM grid
ps_cam = presi_sam(1)
var_cam(:, 1) = pres_sam(5)
var_cam(:, 2) = pres_sam(10)
var_cam(:, 3) = 1.0d-4
var_cam_surface = presi_sam(1)
p_cam(:, 1) = pres_sam(10)
p_cam(:, 2) = pres_sam(20)
p_cam(:, 3) = 1.0d-4

! Set the variable on the CAM grid equal to the pressure
var_cam_surface = ps_cam
var_cam = p_cam

! Expected variable value on the SAM grid will be equal to pressure at that point
do i = 1,4
var_sam_exp(i, :) = pres_sam(1:30)
end do

call interp_to_sam(p_cam, ps_cam, var_cam, var_sam, var_cam_surface)

call assert_array_equal(var_sam_exp, var_sam, test_name)
call assert_array_equal(var_sam_exp, var_sam, test_name, rtol_opt=1.0d-14)

end subroutine test_interp_to_sam_pres

Expand All @@ -136,10 +140,10 @@ subroutine test_interp_to_cam_match(test_name)

integer :: i

real(dp), dimension(4, 30) :: p_cam, var_cam, rho_cam, rho_cam_exp
real(dp), dimension(4, 31) :: p_int_cam
real(dp), dimension(4, nrf) :: p_cam, var_cam, rho_cam, rho_cam_exp
real(dp), dimension(4, nrf+1) :: p_int_cam
real(dp), dimension(4) :: ps_cam, var_cam_surface
real(dp), dimension(4, 30) :: var_sam
real(dp), dimension(4, nrf) :: var_sam

real(dp), dimension(48) :: pres_sam, presi_sam, gamaz_sam, rho_sam, z_sam
!! Data from the SAM soundings used in tests
Expand All @@ -148,16 +152,17 @@ subroutine test_interp_to_cam_match(test_name)
call fetch_sam_data(pres_sam, presi_sam, gamaz_sam, rho_sam, z_sam)

do i=1,4
p_cam(i, 1:30) = pres_sam(1:30)
p_int_cam(i, 1:31) = presi_sam(1:31)
! Set up a CAM grid that matches the lower nrf cells of the SAM grid
p_cam(i, :) = pres_sam(:)
p_int_cam(i, :) = presi_sam(1:nrf+1)
! Set SAM variable equal to cell size ("density" 1.0)
var_sam(i, :) = (presi_sam(1:30) - presi_sam(2:31))
! var_sam(i, :) = 1.0
var_sam(i, :) = (presi_sam(1:nrf) - presi_sam(2:nrf+1))
enddo

call interp_to_cam(p_cam, p_int_cam, p_int_cam(:, 1), var_sam, var_cam)

do i=1,30
! Calculate resulting density by dividing by cell size
do i=1,nrf
rho_cam(:, i) = var_cam(:, i) / (p_int_cam(:, i)-p_int_cam(:, i+1))
end do

Expand Down

0 comments on commit 95b1f77

Please sign in to comment.