From 1adf4ce02eeda6d78c48577211fcfa1d1c783962 Mon Sep 17 00:00:00 2001 From: AdelekeBankole Date: Fri, 23 Aug 2024 17:01:55 +0100 Subject: [PATCH] improve documentation with interpolation --- .../test_CAM_interface/test_cam_interface.F90 | 45 ++++++++++--------- 1 file changed, 25 insertions(+), 20 deletions(-) diff --git a/tests/test_CAM_interface/test_cam_interface.F90 b/tests/test_CAM_interface/test_cam_interface.F90 index f46f259..a4cfdb1 100644 --- a/tests/test_CAM_interface/test_cam_interface.F90 +++ b/tests/test_CAM_interface/test_cam_interface.F90 @@ -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 @@ -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/) @@ -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 @@ -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 @@ -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 @@ -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