From 4aff176cbd427dac763fc52708cc224ef506e104 Mon Sep 17 00:00:00 2001 From: "ukmo-juan.castillo" Date: Tue, 24 Mar 2026 10:37:11 +0000 Subject: [PATCH 01/10] Obtain geometry and topology information for mapping from the mesh object rather than the base_mesh namelist --- .../algorithm/sci_mapping_constants_mod.x90 | 4 +- .../sci_compute_sample_u_ops_kernel_mod.F90 | 62 ++++++++++++------- .../compute_sample_u_ops_kernel_mod_test.pf | 1 + 3 files changed, 43 insertions(+), 24 deletions(-) diff --git a/components/science/source/algorithm/sci_mapping_constants_mod.x90 b/components/science/source/algorithm/sci_mapping_constants_mod.x90 index ffa819aa1..10453fd47 100644 --- a/components/science/source/algorithm/sci_mapping_constants_mod.x90 +++ b/components/science/source/algorithm/sci_mapping_constants_mod.x90 @@ -303,7 +303,9 @@ contains compute_sample_u_ops_kernel_type(u_lon_sample, & u_lat_sample, & u_up_sample, & - chi, panel_id) ) + chi, panel_id, & + mesh%is_geometry_planar(), & + mesh%is_topology_periodic()) ) if ( LPROF ) call stop_timing( id, 'runtime_constants.mapping' ) diff --git a/components/science/source/kernel/inter_function_space/sci_compute_sample_u_ops_kernel_mod.F90 b/components/science/source/kernel/inter_function_space/sci_compute_sample_u_ops_kernel_mod.F90 index 4bfbb79e1..7c16a1ddb 100644 --- a/components/science/source/kernel/inter_function_space/sci_compute_sample_u_ops_kernel_mod.F90 +++ b/components/science/source/kernel/inter_function_space/sci_compute_sample_u_ops_kernel_mod.F90 @@ -15,15 +15,15 @@ module sci_compute_sample_u_ops_kernel_mod use argument_mod, only : arg_type, func_type, & - GH_FIELD, GH_REAL, & - GH_OPERATOR, & + GH_FIELD, GH_SCALAR, GH_REAL,& + GH_LOGICAL, GH_OPERATOR, & GH_INC, GH_READ, GH_WRITE, & ANY_DISCONTINUOUS_SPACE_3, & GH_BASIS, GH_DIFF_BASIS, & CELL_COLUMN, GH_EVALUATOR, & reference_element_data_type, & normals_to_faces - use constants_mod, only : r_def, i_def + use constants_mod, only : r_def, i_def, l_def use fs_continuity_mod, only : W2broken, W3, Wtheta, Wchi use kernel_mod, only : kernel_type use sci_chi_transform_mod, only : chi2llr @@ -33,9 +33,10 @@ module sci_compute_sample_u_ops_kernel_mod use reference_element_mod, only : W, S, N, E, T, B use finite_element_config_mod, only: coord_system - use base_mesh_config_mod, only: geometry, topology, & - geometry_spherical, & - geometry_planar + use base_mesh_config_mod, only: geometry_spherical, & + geometry_planar, & + topology_fully_periodic, & + topology_non_periodic use planet_config_mod, only: scaled_radius implicit none @@ -50,12 +51,14 @@ module sci_compute_sample_u_ops_kernel_mod !> type, public, extends(kernel_type) :: compute_sample_u_ops_kernel_type private - type(arg_type) :: meta_args(5) = (/ & - arg_type(GH_OPERATOR, GH_REAL, GH_WRITE, W2broken, W3), & - arg_type(GH_OPERATOR, GH_REAL, GH_WRITE, W2broken, W3), & - arg_type(GH_OPERATOR, GH_REAL, GH_WRITE, W2broken, WTHETA), & - arg_type(GH_FIELD*3, GH_REAL, GH_READ, Wchi), & - arg_type(GH_FIELD, GH_REAL, GH_READ, ANY_DISCONTINUOUS_SPACE_3) & + type(arg_type) :: meta_args(7) = (/ & + arg_type(GH_OPERATOR, GH_REAL, GH_WRITE, W2broken, W3), & + arg_type(GH_OPERATOR, GH_REAL, GH_WRITE, W2broken, W3), & + arg_type(GH_OPERATOR, GH_REAL, GH_WRITE, W2broken, WTHETA), & + arg_type(GH_FIELD*3, GH_REAL, GH_READ, Wchi), & + arg_type(GH_FIELD, GH_REAL, GH_READ, ANY_DISCONTINUOUS_SPACE_3), & + arg_type(GH_SCALAR, GH_LOGICAL, GH_READ), & + arg_type(GH_SCALAR, GH_LOGICAL, GH_READ) & /) type(func_type) :: meta_funcs(1) = (/ & func_type(Wchi, GH_BASIS, GH_DIFF_BASIS) & @@ -89,6 +92,8 @@ module sci_compute_sample_u_ops_kernel_mod !> @param[in] chi2 Coordinates in the second direction !> @param[in] chi3 Coordinates in the third direction !> @param[in] panel_id A field giving the ID for mesh panels +!> @param[in] is_planar_geometry A logical saying if the mesh geometry is planar +!> @param[in] is_periodic_topology A logical saying if the mesh topology is periodic !> @param[in] ndf_w2b Number of DoFs per cell for broken W2 !> @param[in] ndf_w3 Number of DoFs per cell for W3 !> @param[in] ndf_wt Number of DoFs per cell for Wtheta @@ -110,6 +115,8 @@ subroutine compute_sample_u_ops_code( col, nlayers, & ncell_3d_3, u_rad_op, & chi1, chi2, chi3, & panel_id, & + is_planar_geometry, & + is_periodic_topology, & ndf_w2b, ndf_w3, ndf_wt, & ndf_chi, undf_chi, map_chi, & chi_basis, chi_diff_basis, & @@ -137,6 +144,8 @@ subroutine compute_sample_u_ops_code( col, nlayers, & ! Fields real(kind=r_def), dimension(undf_pid), intent(in) :: panel_id real(kind=r_def), dimension(undf_chi), intent(in) :: chi1, chi2, chi3 + logical(kind=l_def), intent(in) :: is_planar_geometry + logical(kind=l_def), intent(in) :: is_periodic_topology ! Operators real(kind=r_def), dimension(ncell_3d_1,ndf_w2b,ndf_w3), intent(inout) :: u_lon_op @@ -144,7 +153,7 @@ subroutine compute_sample_u_ops_code( col, nlayers, & real(kind=r_def), dimension(ncell_3d_3,ndf_w2b,ndf_wt), intent(inout) :: u_rad_op ! Internal variables - integer(kind=i_def) :: df_w2, df_wt, df_chi, k, ipanel, cell_3d + integer(kind=i_def) :: df_w2, df_wt, df_chi, k, ipanel, cell_3d, topology real(kind=r_def), dimension(3,3,ndf_w2b) :: jacobian, jac_inv real(kind=r_def), dimension(ndf_w2b) :: dj real(kind=r_def), dimension(3) :: llr, X_vector, Y_vector, Z_vector @@ -157,10 +166,15 @@ subroutine compute_sample_u_ops_code( col, nlayers, & ipanel = int(panel_id(map_pid(1)), i_def) + if (is_periodic_topology) then + topology = topology_fully_periodic + else + topology = topology_non_periodic + end if + ! For spherical geometry, need to rotate from (lon,lat,r) components ! For planar geometry, components should already be in (X,Y,Z) coordinates - select case ( geometry ) - case ( geometry_planar ) + if ( is_planar_geometry ) then X_vector = (/ 1.0_r_def, 0.0_r_def, 0.0_r_def /) Y_vector = (/ 0.0_r_def, 1.0_r_def, 0.0_r_def /) @@ -180,9 +194,10 @@ subroutine compute_sample_u_ops_code( col, nlayers, & chi3_e(df_chi) = chi3(map_chi(df_chi) + k) end do - call coordinate_jacobian(coord_system, geometry, topology, scaled_radius, & - ndf_chi, ndf_w2b, chi1_e, chi2_e, chi3_e, & - ipanel, chi_basis, chi_diff_basis, jacobian, dj) + call coordinate_jacobian(coord_system, geometry_planar, topology, & + scaled_radius, ndf_chi, ndf_w2b, chi1_e, & + chi2_e, chi3_e, ipanel, chi_basis, & + chi_diff_basis, jacobian, dj) call coordinate_jacobian_inverse(ndf_w2b, jacobian, dj, jac_inv) ! X and Y components contribute equally to all W2 DoFs @@ -210,7 +225,7 @@ subroutine compute_sample_u_ops_code( col, nlayers, & end do - case ( geometry_spherical ) + else lon_vector_llr = (/ 1.0_r_def, 0.0_r_def, 0.0_r_def /) lat_vector_llr = (/ 0.0_r_def, 1.0_r_def, 0.0_r_def /) @@ -230,9 +245,10 @@ subroutine compute_sample_u_ops_code( col, nlayers, & chi3_e(df_chi) = chi3(map_chi(df_chi) + k) end do - call coordinate_jacobian(coord_system, geometry, topology, scaled_radius, & - ndf_chi, ndf_w2b, chi1_e, chi2_e, chi3_e, & - ipanel, chi_basis, chi_diff_basis, jacobian, dj) + call coordinate_jacobian(coord_system, geometry_spherical, topology, & + scaled_radius, ndf_chi, ndf_w2b, chi1_e, & + chi2_e, chi3_e, ipanel, chi_basis, & + chi_diff_basis, jacobian, dj) call coordinate_jacobian_inverse(ndf_w2b, jacobian, dj, jac_inv) ! Convert (lon,lat,r) vectors into (X,Y,Z) components @@ -284,7 +300,7 @@ subroutine compute_sample_u_ops_code( col, nlayers, & end do - end select + end if ! Enforce boundary condition at bottom and top cell_3d = 1 + (col-1)*nlayers diff --git a/components/science/unit-test/kernel/inter_function_space/compute_sample_u_ops_kernel_mod_test.pf b/components/science/unit-test/kernel/inter_function_space/compute_sample_u_ops_kernel_mod_test.pf index f5fda906e..0c7059e53 100644 --- a/components/science/unit-test/kernel/inter_function_space/compute_sample_u_ops_kernel_mod_test.pf +++ b/components/science/unit-test/kernel/inter_function_space/compute_sample_u_ops_kernel_mod_test.pf @@ -275,6 +275,7 @@ contains chi_data(:,2), & chi_data(:,3), & panel_id_data, & + .false., .false., & ndf_w2b, ndf_w3, ndf_wt, & ndf_wchi, undf_wchi, map_wchi(:,cell), & basis_wchi, diff_basis_wchi, & From c21acf9ba2118201be71c6d029272b0da1da168d Mon Sep 17 00:00:00 2001 From: "ukmo-juan.castillo" Date: Tue, 24 Mar 2026 12:16:25 +0000 Subject: [PATCH 02/10] Modify test not to use 'magic' variables --- .../compute_sample_u_ops_kernel_mod_test.pf | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/components/science/unit-test/kernel/inter_function_space/compute_sample_u_ops_kernel_mod_test.pf b/components/science/unit-test/kernel/inter_function_space/compute_sample_u_ops_kernel_mod_test.pf index 0c7059e53..b4381b349 100644 --- a/components/science/unit-test/kernel/inter_function_space/compute_sample_u_ops_kernel_mod_test.pf +++ b/components/science/unit-test/kernel/inter_function_space/compute_sample_u_ops_kernel_mod_test.pf @@ -6,7 +6,7 @@ module compute_sample_u_ops_kernel_mod_test - use constants_mod, only : i_def, r_def + use constants_mod, only : i_def, r_def, l_def use reference_element_mod, only : W, S, E, N, B, T use funit @@ -147,6 +147,9 @@ contains real(r_def), allocatable :: u_lat_op(:,:,:) real(r_def), allocatable :: u_up_op(:,:,:) + loginal(l_def) :: is_planar_geometry + loginal(l_def) :: is_periodic_topology + ! ------------------------------------------------------------------------ ! ! Make mesh and function space details ! ------------------------------------------------------------------------ ! @@ -218,6 +221,8 @@ contains u_up_op(:,:,:) = 0.0_r_def u_w2_data(:) = 0.0_r_def u_w2b_data(:) = 0.0_r_def + is_planar_geometry = .false. + is_periodic_topology = .false. ! Set values for components, that vary with column and layer do k = 0, nlayers - 1 @@ -275,7 +280,8 @@ contains chi_data(:,2), & chi_data(:,3), & panel_id_data, & - .false., .false., & + is_planar_geometry, & + is_periodic_topology, & ndf_w2b, ndf_w3, ndf_wt, & ndf_wchi, undf_wchi, map_wchi(:,cell), & basis_wchi, diff_basis_wchi, & From 6a2a9930eba85e41b6f9339b9474e5921f6294d0 Mon Sep 17 00:00:00 2001 From: "ukmo-juan.castillo" Date: Tue, 24 Mar 2026 13:11:58 +0000 Subject: [PATCH 03/10] Fix a typo --- .../compute_sample_u_ops_kernel_mod_test.pf | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/components/science/unit-test/kernel/inter_function_space/compute_sample_u_ops_kernel_mod_test.pf b/components/science/unit-test/kernel/inter_function_space/compute_sample_u_ops_kernel_mod_test.pf index b4381b349..e3a10015a 100644 --- a/components/science/unit-test/kernel/inter_function_space/compute_sample_u_ops_kernel_mod_test.pf +++ b/components/science/unit-test/kernel/inter_function_space/compute_sample_u_ops_kernel_mod_test.pf @@ -147,8 +147,8 @@ contains real(r_def), allocatable :: u_lat_op(:,:,:) real(r_def), allocatable :: u_up_op(:,:,:) - loginal(l_def) :: is_planar_geometry - loginal(l_def) :: is_periodic_topology + logical(l_def) :: is_planar_geometry + logical(l_def) :: is_periodic_topology ! ------------------------------------------------------------------------ ! ! Make mesh and function space details From dc23584f744db0c8bbd4672d7167ec87c28ca134 Mon Sep 17 00:00:00 2001 From: "ukmo-juan.castillo" Date: Tue, 24 Mar 2026 13:47:04 +0000 Subject: [PATCH 04/10] Add name to contributors list --- CONTRIBUTORS.md | 50 +++++++++++++++++++++++++------------------------ 1 file changed, 26 insertions(+), 24 deletions(-) diff --git a/CONTRIBUTORS.md b/CONTRIBUTORS.md index 330823d6e..f6f35502e 100644 --- a/CONTRIBUTORS.md +++ b/CONTRIBUTORS.md @@ -1,26 +1,28 @@ # Contributors -| GitHub user | Real Name | Affiliation | Date | -| ---------------- | ---------------------- | ----------- | ---------- | -| andrewcoughtrie | Andrew Coughtrie | Met Office | 2025.12.12 | -| james-bruten-mo | James Bruten | Met Office | 2025-12-09 | -| jedbakerMO | Jed Baker | Met Office | 2025-12-29 | -| jennyhickson | Jenny Hickson | Met Office | 2025-12-10 | -| mo-marqh | Mark Hedley | Met Office | 2025-12-11 | -| mo-rickywong | Ricky Wong | Met Office | 2025-01-30 | -| mike-hobson | Mike Hobson | Met Office | 2025-12-17 | -| MatthewHambley | Matthew Hambley | Met Office | 2025-12-15 | -| mo-lottieturner | Lottie Turner | Met Office | 2025-12-16 | -| tommbendall | Thomas Bendall | Met Office | 2026-01-23 | -| yaswant | Yaswant Pradhan | Met Office | 2025-12-16 | -| stevemullerworth | Steve Mullerworth | Met Office | 2026-01-08 | -| harry-shepherd | Harry Shepherd | Met Office | 2026-01-08 | -| EdHone | Ed Hone | Met Office | 2026-01-09 | -| tom-j-h | Tom Hill | Met Office | 2026-01-19 | -| mo-alistairp | Alistair Pirrie | Met Office | 2026-01-12 | -| t00sa | Sam Clarke-Green | Met Office | 2026-01-27 | -| MetBenjaminWent | Benjamin Went | Met Office | 2026-01-30 | -| jcsmeto | James Cunningham-Smith | Met Office | 2026-02-06 | -| thomasmelvin | Thomas Melvin | Met Office | 2026-01-15 | -| ericaneininger | Erica Neininger | Met Office | 2026-03-02 | -| mo-lucy-gordon | Lucy Gordon | Met Office | 2026-03-18 | \ No newline at end of file +| GitHub user | Real Name | Affiliation | Date | +| ------------------- | ---------------------- | ----------- | ---------- | +| andrewcoughtrie | Andrew Coughtrie | Met Office | 2025.12.12 | +| james-bruten-mo | James Bruten | Met Office | 2025-12-09 | +| jedbakerMO | Jed Baker | Met Office | 2025-12-29 | +| jennyhickson | Jenny Hickson | Met Office | 2025-12-10 | +| mo-marqh | Mark Hedley | Met Office | 2025-12-11 | +| mo-rickywong | Ricky Wong | Met Office | 2025-01-30 | +| mike-hobson | Mike Hobson | Met Office | 2025-12-17 | +| MatthewHambley | Matthew Hambley | Met Office | 2025-12-15 | +| mo-lottieturner | Lottie Turner | Met Office | 2025-12-16 | +| tommbendall | Thomas Bendall | Met Office | 2026-01-23 | +| yaswant | Yaswant Pradhan | Met Office | 2025-12-16 | +| stevemullerworth | Steve Mullerworth | Met Office | 2026-01-08 | +| harry-shepherd | Harry Shepherd | Met Office | 2026-01-08 | +| EdHone | Ed Hone | Met Office | 2026-01-09 | +| tom-j-h | Tom Hill | Met Office | 2026-01-19 | +| mo-alistairp | Alistair Pirrie | Met Office | 2026-01-12 | +| t00sa | Sam Clarke-Green | Met Office | 2026-01-27 | +| MetBenjaminWent | Benjamin Went | Met Office | 2026-01-30 | +| jcsmeto | James Cunningham-Smith | Met Office | 2026-02-06 | +| thomasmelvin | Thomas Melvin | Met Office | 2026-01-15 | +| ericaneininger | Erica Neininger | Met Office | 2026-03-02 | +| mo-lucy-gordon | Lucy Gordon | Met Office | 2026-03-18 | +| ukmo-juan-castillo | Juan M. Castillo | Met Office | 2026-03-24 | + From d7eb78c56e52e05c4d92217dabedaab7be827042 Mon Sep 17 00:00:00 2001 From: "ukmo-juan.castillo" Date: Wed, 25 Mar 2026 16:46:29 +0000 Subject: [PATCH 05/10] Pass the integer values of geometry and topology to the kernel instead of logicals --- .../algorithm/sci_mapping_constants_mod.x90 | 24 ++++++++- .../sci_compute_sample_u_ops_kernel_mod.F90 | 50 ++++++++----------- .../compute_sample_u_ops_kernel_mod_test.pf | 13 ++--- 3 files changed, 47 insertions(+), 40 deletions(-) diff --git a/components/science/source/algorithm/sci_mapping_constants_mod.x90 b/components/science/source/algorithm/sci_mapping_constants_mod.x90 index 10453fd47..92e7bdc1c 100644 --- a/components/science/source/algorithm/sci_mapping_constants_mod.x90 +++ b/components/science/source/algorithm/sci_mapping_constants_mod.x90 @@ -43,6 +43,11 @@ module sci_mapping_constants_mod tik, LPROF ! Configuration + use base_mesh_config_mod, only: geometry_spherical, & + geometry_planar, & + topology_channel, & + topology_fully_periodic, & + topology_non_periodic use finite_element_config_mod, only: element_order_h, & element_order_v @@ -273,6 +278,8 @@ contains type(operator_type), pointer :: u_lat_sample type(operator_type), pointer :: u_up_sample integer(tik) :: id + integer(kind=i_def) :: geometry + integer(kind=i_def) :: topology if (.not. u_lon_sample_inventory%is_initialised()) then call u_lon_sample_inventory%initialise(name='u_lon_sample') @@ -288,6 +295,20 @@ contains chi => get_coordinates(mesh_id) panel_id => get_panel_id(mesh_id) + if (mesh%is_geometry_planar()) then + geometry = geometry_planar + else + geometry = geometry_spherical + end if + + if (mesh%is_topology_non_periodic()) then + topology = topology_non_periodic + else if (mesh%is_topology_periodic) then + topology = topology_fully_periodic + else if (mesh%is_topology_channel) then + topology = topology_channel + end if + if ( LPROF ) call start_timing( id, 'runtime_constants.mapping' ) ! Kernels only work for lowest order spaces so use finite volume @@ -304,8 +325,7 @@ contains u_lat_sample, & u_up_sample, & chi, panel_id, & - mesh%is_geometry_planar(), & - mesh%is_topology_periodic()) ) + geometry, topology) ) if ( LPROF ) call stop_timing( id, 'runtime_constants.mapping' ) diff --git a/components/science/source/kernel/inter_function_space/sci_compute_sample_u_ops_kernel_mod.F90 b/components/science/source/kernel/inter_function_space/sci_compute_sample_u_ops_kernel_mod.F90 index 7c16a1ddb..99664d200 100644 --- a/components/science/source/kernel/inter_function_space/sci_compute_sample_u_ops_kernel_mod.F90 +++ b/components/science/source/kernel/inter_function_space/sci_compute_sample_u_ops_kernel_mod.F90 @@ -16,7 +16,7 @@ module sci_compute_sample_u_ops_kernel_mod use argument_mod, only : arg_type, func_type, & GH_FIELD, GH_SCALAR, GH_REAL,& - GH_LOGICAL, GH_OPERATOR, & + GH_INTEGER, GH_OPERATOR, & GH_INC, GH_READ, GH_WRITE, & ANY_DISCONTINUOUS_SPACE_3, & GH_BASIS, GH_DIFF_BASIS, & @@ -34,9 +34,7 @@ module sci_compute_sample_u_ops_kernel_mod use finite_element_config_mod, only: coord_system use base_mesh_config_mod, only: geometry_spherical, & - geometry_planar, & - topology_fully_periodic, & - topology_non_periodic + geometry_planar use planet_config_mod, only: scaled_radius implicit none @@ -57,8 +55,8 @@ module sci_compute_sample_u_ops_kernel_mod arg_type(GH_OPERATOR, GH_REAL, GH_WRITE, W2broken, WTHETA), & arg_type(GH_FIELD*3, GH_REAL, GH_READ, Wchi), & arg_type(GH_FIELD, GH_REAL, GH_READ, ANY_DISCONTINUOUS_SPACE_3), & - arg_type(GH_SCALAR, GH_LOGICAL, GH_READ), & - arg_type(GH_SCALAR, GH_LOGICAL, GH_READ) & + arg_type(GH_SCALAR, GH_INTEGER, GH_READ), & + arg_type(GH_SCALAR, GH_INTEGER, GH_READ) & /) type(func_type) :: meta_funcs(1) = (/ & func_type(Wchi, GH_BASIS, GH_DIFF_BASIS) & @@ -92,8 +90,8 @@ module sci_compute_sample_u_ops_kernel_mod !> @param[in] chi2 Coordinates in the second direction !> @param[in] chi3 Coordinates in the third direction !> @param[in] panel_id A field giving the ID for mesh panels -!> @param[in] is_planar_geometry A logical saying if the mesh geometry is planar -!> @param[in] is_periodic_topology A logical saying if the mesh topology is periodic +!> @param[in] geometry Mesh geometry type +!> @param[in] topology Mesh topology type !> @param[in] ndf_w2b Number of DoFs per cell for broken W2 !> @param[in] ndf_w3 Number of DoFs per cell for W3 !> @param[in] ndf_wt Number of DoFs per cell for Wtheta @@ -115,8 +113,7 @@ subroutine compute_sample_u_ops_code( col, nlayers, & ncell_3d_3, u_rad_op, & chi1, chi2, chi3, & panel_id, & - is_planar_geometry, & - is_periodic_topology, & + geometry, topology, & ndf_w2b, ndf_w3, ndf_wt, & ndf_chi, undf_chi, map_chi, & chi_basis, chi_diff_basis, & @@ -144,8 +141,8 @@ subroutine compute_sample_u_ops_code( col, nlayers, & ! Fields real(kind=r_def), dimension(undf_pid), intent(in) :: panel_id real(kind=r_def), dimension(undf_chi), intent(in) :: chi1, chi2, chi3 - logical(kind=l_def), intent(in) :: is_planar_geometry - logical(kind=l_def), intent(in) :: is_periodic_topology + integer(kind=i_def), intent(in) :: geometry + integer(kind=i_def), intent(in) :: topology ! Operators real(kind=r_def), dimension(ncell_3d_1,ndf_w2b,ndf_w3), intent(inout) :: u_lon_op @@ -153,7 +150,7 @@ subroutine compute_sample_u_ops_code( col, nlayers, & real(kind=r_def), dimension(ncell_3d_3,ndf_w2b,ndf_wt), intent(inout) :: u_rad_op ! Internal variables - integer(kind=i_def) :: df_w2, df_wt, df_chi, k, ipanel, cell_3d, topology + integer(kind=i_def) :: df_w2, df_wt, df_chi, k, ipanel, cell_3d real(kind=r_def), dimension(3,3,ndf_w2b) :: jacobian, jac_inv real(kind=r_def), dimension(ndf_w2b) :: dj real(kind=r_def), dimension(3) :: llr, X_vector, Y_vector, Z_vector @@ -166,15 +163,10 @@ subroutine compute_sample_u_ops_code( col, nlayers, & ipanel = int(panel_id(map_pid(1)), i_def) - if (is_periodic_topology) then - topology = topology_fully_periodic - else - topology = topology_non_periodic - end if - ! For spherical geometry, need to rotate from (lon,lat,r) components ! For planar geometry, components should already be in (X,Y,Z) coordinates - if ( is_planar_geometry ) then + select case ( geometry ) + case ( geometry_planar ) X_vector = (/ 1.0_r_def, 0.0_r_def, 0.0_r_def /) Y_vector = (/ 0.0_r_def, 1.0_r_def, 0.0_r_def /) @@ -194,10 +186,9 @@ subroutine compute_sample_u_ops_code( col, nlayers, & chi3_e(df_chi) = chi3(map_chi(df_chi) + k) end do - call coordinate_jacobian(coord_system, geometry_planar, topology, & - scaled_radius, ndf_chi, ndf_w2b, chi1_e, & - chi2_e, chi3_e, ipanel, chi_basis, & - chi_diff_basis, jacobian, dj) + call coordinate_jacobian(coord_system, geometry, topology, scaled_radius, & + ndf_chi, ndf_w2b, chi1_e, chi2_e, chi3_e, & + ipanel, chi_basis, chi_diff_basis, jacobian, dj) call coordinate_jacobian_inverse(ndf_w2b, jacobian, dj, jac_inv) ! X and Y components contribute equally to all W2 DoFs @@ -225,7 +216,7 @@ subroutine compute_sample_u_ops_code( col, nlayers, & end do - else + case ( geometry_spherical ) lon_vector_llr = (/ 1.0_r_def, 0.0_r_def, 0.0_r_def /) lat_vector_llr = (/ 0.0_r_def, 1.0_r_def, 0.0_r_def /) @@ -245,10 +236,9 @@ subroutine compute_sample_u_ops_code( col, nlayers, & chi3_e(df_chi) = chi3(map_chi(df_chi) + k) end do - call coordinate_jacobian(coord_system, geometry_spherical, topology, & - scaled_radius, ndf_chi, ndf_w2b, chi1_e, & - chi2_e, chi3_e, ipanel, chi_basis, & - chi_diff_basis, jacobian, dj) + call coordinate_jacobian(coord_system, geometry, topology, scaled_radius, & + ndf_chi, ndf_w2b, chi1_e, chi2_e, chi3_e, & + ipanel, chi_basis, chi_diff_basis, jacobian, dj) call coordinate_jacobian_inverse(ndf_w2b, jacobian, dj, jac_inv) ! Convert (lon,lat,r) vectors into (X,Y,Z) components @@ -300,7 +290,7 @@ subroutine compute_sample_u_ops_code( col, nlayers, & end do - end if + end select ! Enforce boundary condition at bottom and top cell_3d = 1 + (col-1)*nlayers diff --git a/components/science/unit-test/kernel/inter_function_space/compute_sample_u_ops_kernel_mod_test.pf b/components/science/unit-test/kernel/inter_function_space/compute_sample_u_ops_kernel_mod_test.pf index e3a10015a..cc79bb19d 100644 --- a/components/science/unit-test/kernel/inter_function_space/compute_sample_u_ops_kernel_mod_test.pf +++ b/components/science/unit-test/kernel/inter_function_space/compute_sample_u_ops_kernel_mod_test.pf @@ -6,7 +6,7 @@ module compute_sample_u_ops_kernel_mod_test - use constants_mod, only : i_def, r_def, l_def + use constants_mod, only : i_def, r_def use reference_element_mod, only : W, S, E, N, B, T use funit @@ -85,6 +85,8 @@ contains @test subroutine test_all() + use base_mesh_config_mod, only : geometry_spherical, & + topology_non_periodic use matrix_vector_kernel_mod, only : matrix_vector_code use sci_average_w2b_to_w2_kernel_mod, only : average_w2b_to_w2_code use sci_compute_sample_u_ops_kernel_mod, only : compute_sample_u_ops_code @@ -147,9 +149,6 @@ contains real(r_def), allocatable :: u_lat_op(:,:,:) real(r_def), allocatable :: u_up_op(:,:,:) - logical(l_def) :: is_planar_geometry - logical(l_def) :: is_periodic_topology - ! ------------------------------------------------------------------------ ! ! Make mesh and function space details ! ------------------------------------------------------------------------ ! @@ -221,8 +220,6 @@ contains u_up_op(:,:,:) = 0.0_r_def u_w2_data(:) = 0.0_r_def u_w2b_data(:) = 0.0_r_def - is_planar_geometry = .false. - is_periodic_topology = .false. ! Set values for components, that vary with column and layer do k = 0, nlayers - 1 @@ -280,8 +277,8 @@ contains chi_data(:,2), & chi_data(:,3), & panel_id_data, & - is_planar_geometry, & - is_periodic_topology, & + geometry_spherical, & + topology_non_periodic, & ndf_w2b, ndf_w3, ndf_wt, & ndf_wchi, undf_wchi, map_wchi(:,cell), & basis_wchi, diff_basis_wchi, & From a5fa24aedde836f65c77036fd07c662c9c76e1cd Mon Sep 17 00:00:00 2001 From: "ukmo-juan.castillo" Date: Wed, 25 Mar 2026 19:16:02 +0000 Subject: [PATCH 06/10] Minor fixes --- .../science/source/algorithm/sci_mapping_constants_mod.x90 | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/components/science/source/algorithm/sci_mapping_constants_mod.x90 b/components/science/source/algorithm/sci_mapping_constants_mod.x90 index 92e7bdc1c..ab3ab612a 100644 --- a/components/science/source/algorithm/sci_mapping_constants_mod.x90 +++ b/components/science/source/algorithm/sci_mapping_constants_mod.x90 @@ -45,7 +45,6 @@ module sci_mapping_constants_mod ! Configuration use base_mesh_config_mod, only: geometry_spherical, & geometry_planar, & - topology_channel, & topology_fully_periodic, & topology_non_periodic use finite_element_config_mod, only: element_order_h, & @@ -303,10 +302,8 @@ contains if (mesh%is_topology_non_periodic()) then topology = topology_non_periodic - else if (mesh%is_topology_periodic) then + else if (mesh%is_topology_periodic()) then topology = topology_fully_periodic - else if (mesh%is_topology_channel) then - topology = topology_channel end if if ( LPROF ) call start_timing( id, 'runtime_constants.mapping' ) From 93e07d4a8a35282347af2b67c244a3fc47d07477 Mon Sep 17 00:00:00 2001 From: "ukmo-juan.castillo" Date: Thu, 26 Mar 2026 13:19:06 +0000 Subject: [PATCH 07/10] Some more small fixes --- .../source/algorithm/sci_mapping_constants_mod.x90 | 3 +-- .../sci_compute_sample_u_ops_kernel_mod.F90 | 8 ++++---- 2 files changed, 5 insertions(+), 6 deletions(-) diff --git a/components/science/source/algorithm/sci_mapping_constants_mod.x90 b/components/science/source/algorithm/sci_mapping_constants_mod.x90 index ab3ab612a..7e2a4d6e0 100644 --- a/components/science/source/algorithm/sci_mapping_constants_mod.x90 +++ b/components/science/source/algorithm/sci_mapping_constants_mod.x90 @@ -296,10 +296,9 @@ contains if (mesh%is_geometry_planar()) then geometry = geometry_planar - else + else if (mesh%is_geometry_spherical()) then geometry = geometry_spherical end if - if (mesh%is_topology_non_periodic()) then topology = topology_non_periodic else if (mesh%is_topology_periodic()) then diff --git a/components/science/source/kernel/inter_function_space/sci_compute_sample_u_ops_kernel_mod.F90 b/components/science/source/kernel/inter_function_space/sci_compute_sample_u_ops_kernel_mod.F90 index 99664d200..2faaf701f 100644 --- a/components/science/source/kernel/inter_function_space/sci_compute_sample_u_ops_kernel_mod.F90 +++ b/components/science/source/kernel/inter_function_space/sci_compute_sample_u_ops_kernel_mod.F90 @@ -23,7 +23,7 @@ module sci_compute_sample_u_ops_kernel_mod CELL_COLUMN, GH_EVALUATOR, & reference_element_data_type, & normals_to_faces - use constants_mod, only : r_def, i_def, l_def + use constants_mod, only : r_def, i_def use fs_continuity_mod, only : W2broken, W3, Wtheta, Wchi use kernel_mod, only : kernel_type use sci_chi_transform_mod, only : chi2llr @@ -33,7 +33,7 @@ module sci_compute_sample_u_ops_kernel_mod use reference_element_mod, only : W, S, N, E, T, B use finite_element_config_mod, only: coord_system - use base_mesh_config_mod, only: geometry_spherical, & + use base_mesh_config_mod, only: geometry_spherical, & geometry_planar use planet_config_mod, only: scaled_radius @@ -187,7 +187,7 @@ subroutine compute_sample_u_ops_code( col, nlayers, & end do call coordinate_jacobian(coord_system, geometry, topology, scaled_radius, & - ndf_chi, ndf_w2b, chi1_e, chi2_e, chi3_e, & + ndf_chi, ndf_w2b, chi1_e, chi2_e, chi3_e, & ipanel, chi_basis, chi_diff_basis, jacobian, dj) call coordinate_jacobian_inverse(ndf_w2b, jacobian, dj, jac_inv) @@ -237,7 +237,7 @@ subroutine compute_sample_u_ops_code( col, nlayers, & end do call coordinate_jacobian(coord_system, geometry, topology, scaled_radius, & - ndf_chi, ndf_w2b, chi1_e, chi2_e, chi3_e, & + ndf_chi, ndf_w2b, chi1_e, chi2_e, chi3_e, & ipanel, chi_basis, chi_diff_basis, jacobian, dj) call coordinate_jacobian_inverse(ndf_w2b, jacobian, dj, jac_inv) From 1603f0a5ea1f0ff619accb18cf611092587d358f Mon Sep 17 00:00:00 2001 From: "ukmo-juan.castillo" Date: Mon, 30 Mar 2026 11:06:00 +0100 Subject: [PATCH 08/10] Use base_mesh as parameter by default in the sci_mapping subroutine for the kernel that changed --- .../algorithm/sci_mapping_constants_mod.x90 | 15 ++------------- 1 file changed, 2 insertions(+), 13 deletions(-) diff --git a/components/science/source/algorithm/sci_mapping_constants_mod.x90 b/components/science/source/algorithm/sci_mapping_constants_mod.x90 index 7e2a4d6e0..7ac1e3ad2 100644 --- a/components/science/source/algorithm/sci_mapping_constants_mod.x90 +++ b/components/science/source/algorithm/sci_mapping_constants_mod.x90 @@ -46,7 +46,8 @@ module sci_mapping_constants_mod use base_mesh_config_mod, only: geometry_spherical, & geometry_planar, & topology_fully_periodic, & - topology_non_periodic + topology_non_periodic, & + geometry, topology use finite_element_config_mod, only: element_order_h, & element_order_v @@ -277,8 +278,6 @@ contains type(operator_type), pointer :: u_lat_sample type(operator_type), pointer :: u_up_sample integer(tik) :: id - integer(kind=i_def) :: geometry - integer(kind=i_def) :: topology if (.not. u_lon_sample_inventory%is_initialised()) then call u_lon_sample_inventory%initialise(name='u_lon_sample') @@ -294,16 +293,6 @@ contains chi => get_coordinates(mesh_id) panel_id => get_panel_id(mesh_id) - if (mesh%is_geometry_planar()) then - geometry = geometry_planar - else if (mesh%is_geometry_spherical()) then - geometry = geometry_spherical - end if - if (mesh%is_topology_non_periodic()) then - topology = topology_non_periodic - else if (mesh%is_topology_periodic()) then - topology = topology_fully_periodic - end if if ( LPROF ) call start_timing( id, 'runtime_constants.mapping' ) From fd969212280dcb798b1f844338a037ad86488c01 Mon Sep 17 00:00:00 2001 From: "ukmo-juan.castillo" Date: Mon, 30 Mar 2026 11:14:13 +0100 Subject: [PATCH 09/10] Remove unnecessary variables --- .../science/source/algorithm/sci_mapping_constants_mod.x90 | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/components/science/source/algorithm/sci_mapping_constants_mod.x90 b/components/science/source/algorithm/sci_mapping_constants_mod.x90 index 7ac1e3ad2..a527a122b 100644 --- a/components/science/source/algorithm/sci_mapping_constants_mod.x90 +++ b/components/science/source/algorithm/sci_mapping_constants_mod.x90 @@ -43,11 +43,7 @@ module sci_mapping_constants_mod tik, LPROF ! Configuration - use base_mesh_config_mod, only: geometry_spherical, & - geometry_planar, & - topology_fully_periodic, & - topology_non_periodic, & - geometry, topology + use base_mesh_config_mod, only: geometry, topology use finite_element_config_mod, only: element_order_h, & element_order_v From b4eab04ccc6057572ab5644310b15ea08514ceda Mon Sep 17 00:00:00 2001 From: "ukmo-juan.castillo" Date: Tue, 21 Apr 2026 09:51:05 +0100 Subject: [PATCH 10/10] Changes suggested by the reviewer --- .../sci_compute_sample_u_ops_kernel_mod.F90 | 18 +++++++++--------- .../compute_sample_u_ops_kernel_mod_test.pf | 15 +++------------ 2 files changed, 12 insertions(+), 21 deletions(-) diff --git a/components/science/source/kernel/inter_function_space/sci_compute_sample_u_ops_kernel_mod.F90 b/components/science/source/kernel/inter_function_space/sci_compute_sample_u_ops_kernel_mod.F90 index 2faaf701f..cb45a48f1 100644 --- a/components/science/source/kernel/inter_function_space/sci_compute_sample_u_ops_kernel_mod.F90 +++ b/components/science/source/kernel/inter_function_space/sci_compute_sample_u_ops_kernel_mod.F90 @@ -50,13 +50,13 @@ module sci_compute_sample_u_ops_kernel_mod type, public, extends(kernel_type) :: compute_sample_u_ops_kernel_type private type(arg_type) :: meta_args(7) = (/ & - arg_type(GH_OPERATOR, GH_REAL, GH_WRITE, W2broken, W3), & - arg_type(GH_OPERATOR, GH_REAL, GH_WRITE, W2broken, W3), & - arg_type(GH_OPERATOR, GH_REAL, GH_WRITE, W2broken, WTHETA), & - arg_type(GH_FIELD*3, GH_REAL, GH_READ, Wchi), & - arg_type(GH_FIELD, GH_REAL, GH_READ, ANY_DISCONTINUOUS_SPACE_3), & - arg_type(GH_SCALAR, GH_INTEGER, GH_READ), & - arg_type(GH_SCALAR, GH_INTEGER, GH_READ) & + arg_type(GH_OPERATOR, GH_REAL, GH_WRITE, W2broken, W3), &! u_lon_op + arg_type(GH_OPERATOR, GH_REAL, GH_WRITE, W2broken, W3), &! u_lat_op + arg_type(GH_OPERATOR, GH_REAL, GH_WRITE, W2broken, WTHETA), &! u_rad_op + arg_type(GH_FIELD*3, GH_REAL, GH_READ, Wchi), &! chi1, chi2, chi3 + arg_type(GH_FIELD, GH_REAL, GH_READ, ANY_DISCONTINUOUS_SPACE_3), &! panel_id + arg_type(GH_SCALAR, GH_INTEGER, GH_READ), &! geometry + arg_type(GH_SCALAR, GH_INTEGER, GH_READ) &! topology /) type(func_type) :: meta_funcs(1) = (/ & func_type(Wchi, GH_BASIS, GH_DIFF_BASIS) & @@ -90,8 +90,8 @@ module sci_compute_sample_u_ops_kernel_mod !> @param[in] chi2 Coordinates in the second direction !> @param[in] chi3 Coordinates in the third direction !> @param[in] panel_id A field giving the ID for mesh panels -!> @param[in] geometry Mesh geometry type -!> @param[in] topology Mesh topology type +!> @param[in] geometry Mesh geometry enumeration value +!> @param[in] topology Mesh topology enumeration value !> @param[in] ndf_w2b Number of DoFs per cell for broken W2 !> @param[in] ndf_w3 Number of DoFs per cell for W3 !> @param[in] ndf_wt Number of DoFs per cell for Wtheta diff --git a/components/science/unit-test/kernel/inter_function_space/compute_sample_u_ops_kernel_mod_test.pf b/components/science/unit-test/kernel/inter_function_space/compute_sample_u_ops_kernel_mod_test.pf index cc79bb19d..808b7df00 100644 --- a/components/science/unit-test/kernel/inter_function_space/compute_sample_u_ops_kernel_mod_test.pf +++ b/components/science/unit-test/kernel/inter_function_space/compute_sample_u_ops_kernel_mod_test.pf @@ -6,6 +6,8 @@ module compute_sample_u_ops_kernel_mod_test + use base_mesh_config_mod, only : geometry_spherical, & + topology_non_periodic use constants_mod, only : i_def, r_def use reference_element_mod, only : W, S, E, N, B, T use funit @@ -24,26 +26,17 @@ contains @before subroutine set_up() - use base_mesh_config_mod, only : geometry_spherical, & - topology_non_periodic use extrusion_config_mod, only : method_uniform, & stretching_method_linear use finite_element_config_mod, only : cellshape_quadrilateral, & coord_system_native - use feign_config_mod, only : feign_base_mesh_config, & - feign_extrusion_config, & + use feign_config_mod, only : feign_extrusion_config, & feign_finite_element_config, & feign_planet_config use sci_chi_transform_mod, only : init_chi_transforms implicit none - call feign_base_mesh_config( file_prefix='foo', & - prime_mesh_name='unit_test', & - geometry=geometry_spherical, & - prepartitioned=.false., & - topology=topology_non_periodic, & - fplane=.false., f_lat_deg=0.0_r_def ) call feign_extrusion_config( method=method_uniform, & planet_radius=radius, & @@ -85,8 +78,6 @@ contains @test subroutine test_all() - use base_mesh_config_mod, only : geometry_spherical, & - topology_non_periodic use matrix_vector_kernel_mod, only : matrix_vector_code use sci_average_w2b_to_w2_kernel_mod, only : average_w2b_to_w2_code use sci_compute_sample_u_ops_kernel_mod, only : compute_sample_u_ops_code