From 8b4facd168de6917b98cf84469c47de0d8e801ff Mon Sep 17 00:00:00 2001 From: Thomas Bendall <14180399+tommbendall@users.noreply.github.com> Date: Thu, 22 Jan 2026 08:54:33 +0000 Subject: [PATCH 1/4] Implement change to calculation of required stencil depth --- .../mol/adjt_reconstruct_w3_field_alg_mod.x90 | 1 - .../gravity_wave_infrastructure_mod.f90 | 13 +++-- .../algorithm/algorithm_test.f90 | 2 +- .../jedi-interface/jedi_geometry_mod.f90 | 1 - .../initialisation/lfric2lfric_init_mesh.f90 | 36 +++++++++---- .../source/driver/shallow_water_model_mod.F90 | 9 ++-- applications/solver/source/solver.F90 | 2 +- .../source/driver/transport_driver_mod.f90 | 25 ++++++--- dependencies.yaml | 4 +- .../integration-test/cma_test/cma_test.f90 | 4 +- .../common/remap_on_extended_mesh_alg_mod.x90 | 3 +- .../transport/ffsl/ffsl_hori_alg_mod.x90 | 11 ++-- .../mol/reconstruct_w3_field_alg_mod.x90 | 3 +- .../mol/wt_advective_update_alg_mod.x90 | 3 +- .../configuration/check_configuration_mod.F90 | 52 ++++++++++++++----- .../gungho/source/driver/gungho_model_mod.F90 | 8 +-- 16 files changed, 120 insertions(+), 57 deletions(-) diff --git a/applications/adjoint_tests/source/algorithm/transport/mol/adjt_reconstruct_w3_field_alg_mod.x90 b/applications/adjoint_tests/source/algorithm/transport/mol/adjt_reconstruct_w3_field_alg_mod.x90 index 0ccda5295..777dced82 100644 --- a/applications/adjoint_tests/source/algorithm/transport/mol/adjt_reconstruct_w3_field_alg_mod.x90 +++ b/applications/adjoint_tests/source/algorithm/transport/mol/adjt_reconstruct_w3_field_alg_mod.x90 @@ -22,7 +22,6 @@ module adjt_reconstruct_w3_field_alg_mod use function_space_collection_mod, only : function_space_collection use transport_metadata_collection_mod, only : transport_metadata_collection use transport_metadata_mod, only : transport_metadata_type - use check_configuration_mod, only : get_required_stencil_depth implicit none diff --git a/applications/gravity_wave/source/driver/gravity_wave_infrastructure_mod.f90 b/applications/gravity_wave/source/driver/gravity_wave_infrastructure_mod.f90 index 46b88ddad..f8db4605b 100644 --- a/applications/gravity_wave/source/driver/gravity_wave_infrastructure_mod.f90 +++ b/applications/gravity_wave/source/driver/gravity_wave_infrastructure_mod.f90 @@ -81,7 +81,8 @@ subroutine initialise_infrastructure( program_name, & logical(l_def) :: prepartitioned logical :: apply_partition_check - integer(i_def) :: stencil_depth + integer(i_def), allocatable :: stencil_depths + integer(i_def) :: geometry integer(i_def) :: method integer(i_def) :: number_of_layers @@ -191,7 +192,9 @@ subroutine initialise_infrastructure( program_name, & !======================================================================= ! 1.3 Initialise mesh objects and assign InterGrid maps !======================================================================= - stencil_depth = get_required_stencil_depth() + allocate( stencil_depths(size(base_mesh_names)) ) + call get_required_stencil_depth(stencil_depths, base_mesh_names) + apply_partition_check = .false. if ( .not. prepartitioned .and. l_multigrid ) then apply_partition_check = .true. @@ -201,7 +204,7 @@ subroutine initialise_infrastructure( program_name, & modeldb%mpi%get_comm_rank(), & modeldb%mpi%get_comm_size(), & base_mesh_names, & - extrusion, stencil_depth, & + extrusion, stencil_depths, & apply_partition_check ) allocate( twod_names, source=base_mesh_names ) @@ -237,6 +240,10 @@ subroutine initialise_infrastructure( program_name, & nullify(chi_inventory, panel_id_inventory) deallocate(base_mesh_names) + deallocate(twod_names) + deallocate(extrusion) + deallocate(extrusion_2d) + deallocate(stencil_depths) end subroutine initialise_infrastructure diff --git a/applications/jedi_lfric_tests/integration-test/algorithm/algorithm_test.f90 b/applications/jedi_lfric_tests/integration-test/algorithm/algorithm_test.f90 index 9748e3f94..a62b68ecb 100644 --- a/applications/jedi_lfric_tests/integration-test/algorithm/algorithm_test.f90 +++ b/applications/jedi_lfric_tests/integration-test/algorithm/algorithm_test.f90 @@ -69,7 +69,7 @@ program algorithm_test logical(l_def) :: apply_partition_check integer(i_def) :: geometry - integer(i_def) :: stencil_depth + integer(i_def) :: stencil_depth(1) integer(i_def) :: method integer(i_def) :: number_of_layers real(r_def) :: domain_bottom diff --git a/applications/jedi_lfric_tests/source/jedi-interface/jedi_geometry_mod.f90 b/applications/jedi_lfric_tests/source/jedi-interface/jedi_geometry_mod.f90 index 4fd1b473b..bebc16e4e 100644 --- a/applications/jedi_lfric_tests/source/jedi-interface/jedi_geometry_mod.f90 +++ b/applications/jedi_lfric_tests/source/jedi-interface/jedi_geometry_mod.f90 @@ -94,7 +94,6 @@ module jedi_geometry_mod !> subroutine initialise( self, mpi_comm, configuration ) ! Access config directly until modeldb ready - use driver_mesh_mod, only: init_mesh use driver_config_mod, only: init_config use jedi_lfric_mesh_setup_mod, only: initialise_mesh use jedi_lfric_tests_mod, only: jedi_lfric_tests_required_namelists diff --git a/applications/lfric2lfric/source/initialisation/lfric2lfric_init_mesh.f90 b/applications/lfric2lfric/source/initialisation/lfric2lfric_init_mesh.f90 index f1134fce5..b8073bcf5 100644 --- a/applications/lfric2lfric/source/initialisation/lfric2lfric_init_mesh.f90 +++ b/applications/lfric2lfric/source/initialisation/lfric2lfric_init_mesh.f90 @@ -75,7 +75,8 @@ module lfric2lfric_init_mesh_mod !> @param[in] total_ranks Total number of MPI ranks in this job. !> @param[in] mesh_names Mesh names to load from the mesh input file(s). !> @param[in] extrusion Extrusion object to be applied to meshes. -!> @param[in] stencil_depth Required stencil depth for the application. +!> @param[in] stencil_depths_in Required stencil depth for the application +!! for each mesh. !> @param[in] regrid_method Apply check for even partitions with the !> configured partition strategy if the !> regridding method is 'map'. @@ -85,7 +86,7 @@ subroutine init_mesh( configuration, & local_rank, total_ranks, & mesh_names, & extrusion, & - stencil_depth, & + stencil_depths_in, & regrid_method ) implicit none @@ -97,7 +98,7 @@ subroutine init_mesh( configuration, & integer(kind=i_def), intent(in) :: total_ranks character(len=*), intent(in) :: mesh_names(2) class(extrusion_type), intent(in) :: extrusion - integer(kind=i_def), intent(in) :: stencil_depth + integer(kind=i_def), intent(in) :: stencil_depths_in integer(kind=i_def), intent(in) :: regrid_method ! Parameters @@ -124,6 +125,7 @@ subroutine init_mesh( configuration, & ! Local variables character(len=str_max_filename) :: mesh_file(2) + integer(kind=i_def) :: stencil_depths(2) procedure(partitioner_interface), pointer :: partitioner_src => null() procedure(partitioner_interface), pointer :: partitioner_dst => null() @@ -173,6 +175,22 @@ subroutine init_mesh( configuration, & call log_event(log_scratch_space, log_level_error) end if + ! Set up stencil depths + if ( size(stencils_depths) == 1 ) then + ! Single stencil depth specified, apply to all meshes + do i = 1, size(mesh_names) + stencil_depths(i) = stencil_depths_in(1) + end do + else if ( size(stencil_depths) == size(mesh_names) ) then + ! Stencil depths specified per mesh + stencil_depths = stencil_depths_in + else + write(log_scratch_space, '(A)') & + 'Number of stencil depths specified does not '// & + 'match number of requested meshes.' + call log_event(log_scratch_space, log_level_error) + end if + !=========================================================================== ! Create local mesh objects: @@ -231,8 +249,8 @@ subroutine init_mesh( configuration, & ! meshes are suitable for the supplied application ! configuration. !=========================================================== - call check_local_mesh( configuration, & - stencil_depth, & + call check_local_mesh( configuration, & + stencil_depths, & mesh_names ) ! Load and assign mesh maps. @@ -304,15 +322,15 @@ subroutine init_mesh( configuration, & call create_local_mesh( mesh_names(dst:dst), & local_rank, total_ranks, & decomposition_dst, & - stencil_depth, & - generate_inner_halos(dst), & + stencil_depths, & + generate_inner_halos(dst), & partitioner_dst ) call create_local_mesh( mesh_names(src:src), & local_rank, total_ranks, & decomposition_src, & - stencil_depth, & - generate_inner_halos(src), & + stencil_depths, & + generate_inner_halos(src), & partitioner_src ) ! Read in the global intergrid mesh mappings, diff --git a/applications/shallow_water/source/driver/shallow_water_model_mod.F90 b/applications/shallow_water/source/driver/shallow_water_model_mod.F90 index f2706ce97..073083639 100644 --- a/applications/shallow_water/source/driver/shallow_water_model_mod.F90 +++ b/applications/shallow_water/source/driver/shallow_water_model_mod.F90 @@ -83,6 +83,7 @@ subroutine initialise_infrastructure( program_name, modeldb) character(str_def), allocatable :: base_mesh_names(:) character(str_def), allocatable :: twod_names(:) + integer(i_def), allocatable :: stencil_depths(:) class(extrusion_type), allocatable :: extrusion type(uniform_extrusion_type), allocatable :: extrusion_2d @@ -93,7 +94,6 @@ subroutine initialise_infrastructure( program_name, modeldb) character(str_def) :: prime_mesh_name - integer(i_def) :: stencil_depth integer(i_def) :: geometry integer(i_def) :: method integer(i_def) :: number_of_layers @@ -180,12 +180,13 @@ subroutine initialise_infrastructure( program_name, modeldb) ! Initialise prime/2d meshes ! --------------------------------------------------------- check_partitions = .false. - stencil_depth = get_required_stencil_depth() + allocate(stencil_depths(size(base_mesh_names))) + call get_required_stencil_depth(stencil_depths, base_mesh_names) call init_mesh( modeldb%configuration, & modeldb%mpi%get_comm_rank(), & modeldb%mpi%get_comm_size(), & base_mesh_names, extrusion, & - stencil_depth, check_partitions ) + stencil_depths, check_partitions ) allocate( twod_names, source=base_mesh_names ) @@ -222,6 +223,8 @@ subroutine initialise_infrastructure( program_name, modeldb) call create_runtime_constants() deallocate(base_mesh_names) + deallocate(twod_names) + deallocate(stencil_depths) nullify(chi_inventory, panel_id_inventory) end subroutine initialise_infrastructure diff --git a/applications/solver/source/solver.F90 b/applications/solver/source/solver.F90 index 466603082..4779fa8fe 100644 --- a/applications/solver/source/solver.F90 +++ b/applications/solver/source/solver.F90 @@ -86,7 +86,7 @@ program solver character(str_def) :: prime_mesh_name - integer(i_def) :: stencil_depth + integer(i_def) :: stencil_depth(1) integer(i_def) :: geometry integer(i_def) :: method integer(i_def) :: number_of_layers diff --git a/applications/transport/source/driver/transport_driver_mod.f90 b/applications/transport/source/driver/transport_driver_mod.f90 index 2f9d4361d..f6c37ecf8 100644 --- a/applications/transport/source/driver/transport_driver_mod.f90 +++ b/applications/transport/source/driver/transport_driver_mod.f90 @@ -125,6 +125,7 @@ subroutine initialise_transport( program_name, modeldb ) character(len=str_def), allocatable :: chain_mesh_tags(:) character(len=str_def) :: aerosol_mesh_name character(len=str_def) :: prime_mesh_name + integer(kind=i_def), allocatable :: stencil_depths logical(kind=l_def) :: use_multires_coupling logical(kind=l_def) :: l_multigrid @@ -132,7 +133,6 @@ subroutine initialise_transport( program_name, modeldb ) logical(kind=l_def) :: apply_partition_check integer(kind=i_def) :: geometry - integer(kind=i_def) :: stencil_depth real(kind=r_def) :: domain_bottom real(kind=r_def) :: domain_height real(kind=r_def) :: scaled_radius @@ -283,7 +283,9 @@ subroutine initialise_transport( program_name, modeldb ) ! 1.3a Initialise prime/2d meshes ! --------------------------------------------------------- - stencil_depth = get_required_stencil_depth() + allocate(stencil_depths(num_base_meshes)) + call get_required_stencil_depth(stencil_depths, base_mesh_names) + apply_partition_check = .false. if ( .not. prepartitioned .and. & ( l_multigrid .or. use_multires_coupling ) ) then @@ -294,7 +296,7 @@ subroutine initialise_transport( program_name, modeldb ) modeldb%mpi%get_comm_rank(), & modeldb%mpi%get_comm_size(), & base_mesh_names, & - extrusion, stencil_depth, & + extrusion, stencil_depths, & apply_partition_check ) call create_mesh( base_mesh_names, extrusion_2d, & @@ -446,11 +448,20 @@ subroutine initialise_transport( program_name, modeldb ) end if - if (allocated(base_mesh_names)) deallocate(base_mesh_names) - if (allocated(meshes_to_shift)) deallocate(meshes_to_shift) - if (allocated(meshes_to_double)) deallocate(meshes_to_double) - + if (allocated(base_mesh_names)) deallocate(base_mesh_names) + if (allocated(meshes_to_shift)) deallocate(meshes_to_shift) + if (allocated(meshes_to_double)) deallocate(meshes_to_double) + if (allocated(twod_names)) deallocate(twod_names) + if (allocated(shifted_names)) deallocate(shifted_names) + if (allocated(double_names)) deallocate(double_names) + if (allocated(extrusion)) deallocate(extrusion) + if (allocated(extrusion_2d)) deallocate(extrusion_2d) + if (allocated(extrusion_shifted)) deallocate(extrusion_shifted) + if (allocated(extrusion_double)) deallocate(extrusion_double) + if (allocated(chain_mesh_tags)) deallocate(chain_mesh_tags) + if (allocated(stencil_depths)) deallocate(stencil_depths) if (allocated(extra_io_mesh_names)) deallocate(extra_io_mesh_names) + nullify(chi_inventory, panel_id_inventory, mesh, aerosol_mesh) end subroutine initialise_transport diff --git a/dependencies.yaml b/dependencies.yaml index caab36487..28f9d160a 100644 --- a/dependencies.yaml +++ b/dependencies.yaml @@ -30,8 +30,8 @@ lfric_apps: ref: lfric_core: - source: git@github.com:MetOffice/lfric_core.git - ref: 2025.12.1 + source: git@github.com:tommbendall/lfric_core.git + ref: TBendall/MultiStencilDepths moci: source: git@github.com:MetOffice/moci.git diff --git a/science/gungho/integration-test/cma_test/cma_test.f90 b/science/gungho/integration-test/cma_test/cma_test.f90 index 2797865da..15d2e18a6 100644 --- a/science/gungho/integration-test/cma_test/cma_test.f90 +++ b/science/gungho/integration-test/cma_test/cma_test.f90 @@ -130,7 +130,7 @@ program cma_test type(namelist_type), pointer :: base_mesh_nml type(namelist_type), pointer :: planet_nml - integer(i_def) :: stencil_depth + integer(i_def) :: stencil_depth(1) character(str_def) :: file_prefix character(str_def) :: prime_mesh_name real(r_def) :: radius @@ -289,7 +289,7 @@ program cma_test domain_height, & scaled_radius ) ) - stencil_depth = get_required_stencil_depth() + stencil_depth = get_required_stencil_depth(base_mesh_names) check_partitions = .false. call init_mesh( configuration, & local_rank, total_ranks, & diff --git a/science/gungho/source/algorithm/transport/common/remap_on_extended_mesh_alg_mod.x90 b/science/gungho/source/algorithm/transport/common/remap_on_extended_mesh_alg_mod.x90 index 87cc7ce82..8b6744efc 100644 --- a/science/gungho/source/algorithm/transport/common/remap_on_extended_mesh_alg_mod.x90 +++ b/science/gungho/source/algorithm/transport/common/remap_on_extended_mesh_alg_mod.x90 @@ -17,7 +17,6 @@ module remap_on_extended_mesh_alg_mod use io_config_mod, only: subroutine_timers use timer_mod, only: timer use function_space_mod, only: function_space_type - use check_configuration_mod, only: get_required_stencil_depth use transport_constants_mod, only: get_extended_mesh_weights, & get_extended_mesh_indices, & ext_mesh_stencil_depth @@ -76,7 +75,7 @@ contains ndata = fs%get_ndata() ! Ensure remapping depth is not larger than the halo depth - depth = min( depth_in, get_required_stencil_depth() ) + depth = min( depth_in, mesh%get_halo_depth() ) ! Both the field to be remapped and the remapped field need to be ! created with the full size halo. For the field to be remapped ! this is due to the interpolation parallel to a panel boundary diff --git a/science/gungho/source/algorithm/transport/ffsl/ffsl_hori_alg_mod.x90 b/science/gungho/source/algorithm/transport/ffsl/ffsl_hori_alg_mod.x90 index 7b8f88d2f..c0a2f2d9b 100644 --- a/science/gungho/source/algorithm/transport/ffsl/ffsl_hori_alg_mod.x90 +++ b/science/gungho/source/algorithm/transport/ffsl/ffsl_hori_alg_mod.x90 @@ -72,8 +72,7 @@ module ffsl_hori_alg_mod transport_boundary_depth, & transport_overwrite_freq, & transport_overwrite_freq_all - use check_configuration_mod, only: check_any_eqn_consistent, & - get_required_stencil_depth + use check_configuration_mod, only: check_any_eqn_consistent use io_config_mod, only: subroutine_timers use transport_config_mod, only: & panel_edge_treatment, & @@ -429,7 +428,7 @@ contains remap_depth) else call field_big_halo%initialise( field_n%get_function_space(), & - halo_depth=get_required_stencil_depth() ) + halo_depth=mesh%get_halo_depth() ) call invoke( setval_x(field_big_halo, field_n) ) end if ! Copy required as PSyclone doesn't allow the same field to be @@ -722,7 +721,7 @@ contains remap_depth) else call field_big_halo%initialise( field_n%get_function_space(), & - halo_depth=get_required_stencil_depth() ) + halo_depth=mesh%get_halo_depth() ) call invoke( setval_x(field_big_halo, field_n) ) end if @@ -1088,8 +1087,8 @@ contains transport_metadata%get_min_value(), & remap_depth) else - call field_x_big_halo%initialise(field_fs, halo_depth=get_required_stencil_depth()) - call field_y_big_halo%initialise(field_fs, halo_depth=get_required_stencil_depth()) + call field_x_big_halo%initialise(field_fs, halo_depth=mesh%get_halo_depth()) + call field_y_big_halo%initialise(field_fs, halo_depth=mesh%get_halo_depth()) call invoke( setval_x(field_x_big_halo, field_x), & setval_x(field_y_big_halo, field_y) ) end if diff --git a/science/gungho/source/algorithm/transport/mol/reconstruct_w3_field_alg_mod.x90 b/science/gungho/source/algorithm/transport/mol/reconstruct_w3_field_alg_mod.x90 index 6bed73bed..e120d7a14 100644 --- a/science/gungho/source/algorithm/transport/mol/reconstruct_w3_field_alg_mod.x90 +++ b/science/gungho/source/algorithm/transport/mol/reconstruct_w3_field_alg_mod.x90 @@ -18,7 +18,6 @@ !! size as an integer argument. module reconstruct_w3_field_alg_mod - use check_configuration_mod, only: get_required_stencil_depth use sci_combine_multidata_field_kernel_mod, & only: combine_multidata_field_kernel_type use constants_mod, only: r_def, i_def, l_def, str_def @@ -196,7 +195,7 @@ contains ! Copy field to a large halo version call field_old_big_halo%initialise( field_old%get_function_space(), & - halo_depth = get_required_stencil_depth() ) + halo_depth=mesh%get_halo_depth() ) call invoke( setval_X( field_old_big_halo, field_old ) ) monotone = (transport_metadata%get_horizontal_monotone() == monotone_koren) diff --git a/science/gungho/source/algorithm/transport/mol/wt_advective_update_alg_mod.x90 b/science/gungho/source/algorithm/transport/mol/wt_advective_update_alg_mod.x90 index 310165201..e2bdd084e 100644 --- a/science/gungho/source/algorithm/transport/mol/wt_advective_update_alg_mod.x90 +++ b/science/gungho/source/algorithm/transport/mol/wt_advective_update_alg_mod.x90 @@ -18,7 +18,6 @@ !! size as an integer argument. module wt_advective_update_alg_mod - use check_configuration_mod, only: get_required_stencil_depth use constants_mod, only: r_def, i_def, l_def, str_def, & r_tran use sci_geometric_constants_mod, only: get_coordinates, & @@ -132,7 +131,7 @@ contains ! Copy field to a large halo version call field_big_halo%initialise( field%get_function_space(), & - halo_depth = get_required_stencil_depth() ) + halo_depth=mesh%get_halo_depth() ) call invoke( setval_X( field_big_halo, field ) ) ! Compute reconstruction on a Wtheta multidata field diff --git a/science/gungho/source/configuration/check_configuration_mod.F90 b/science/gungho/source/configuration/check_configuration_mod.F90 index 86252a85a..78f6a6944 100644 --- a/science/gungho/source/configuration/check_configuration_mod.F90 +++ b/science/gungho/source/configuration/check_configuration_mod.F90 @@ -6,7 +6,7 @@ module check_configuration_mod - use constants_mod, only: i_def, l_def + use constants_mod, only: i_def, l_def, str_def use mixing_config_mod, only: viscosity, & viscosity_mu use transport_config_mod, only: operators, & @@ -48,7 +48,7 @@ module check_configuration_mod substep_transport, & substep_transport_off, & adjust_vhv_wind, & - ffsl_unity_3d, & + ffsl_unity_3d, & wind_mono_top use transport_enumerated_types_mod, & only: scheme_mol_3d, & @@ -612,26 +612,37 @@ subroutine check_configuration(modeldb) end subroutine check_configuration - !> @brief Determine required stencil depth for the current configuration. + !> @brief Determine required stencil depth for the current configuration, + !! for each mesh. !> @details Depending on the choice of science schemes the required local !> mesh needs to support the anticipated stencils. This function !> returns required stencil depth that needs to be supported. - !> @return stencil_depth + !> @param[in,out] stencil_depths Array of stencil depths for each base mesh + !> @param[in] base_mesh_names Array of base mesh names !> !=========================================================================== - function get_required_stencil_depth() result(stencil_depth) + subroutine get_required_stencil_depth(stencil_depths, base_mesh_names) + + use base_mesh_config_mod, only: prime_mesh_name + use formulation_config_mod, only: use_multires_coupling + use multires_coupling_config_mod, only: aerosol_mesh_name, & + coarse_aerosol_transport implicit none - integer(kind=i_def) :: stencil_depth - integer(kind=i_def) :: sl_depth, special_edge_pts + integer(kind=i_def), intent(inout) :: stencil_depths(:) + character(len=str_def), intent(in) :: base_mesh_names(:) + + integer(kind=i_def) :: i + integer(kind=i_def) :: transport_depth, sl_depth + integer(kind=i_def) :: special_edge_pts logical(kind=l_def) :: any_horz_dep_pts - stencil_depth = 2 + transport_depth = 2 if (operators == operators_fv) then ! Need larger halos for fv operators - stencil_depth = max( stencil_depth, fv_horizontal_order/2 ) + transport_depth = max( transport_depth, fv_horizontal_order/2 ) end if any_horz_dep_pts = check_horz_dep_pts() @@ -661,16 +672,33 @@ function get_required_stencil_depth() result(stencil_depth) if ( panel_edge_treatment == panel_edge_treatment_remapping ) then if ( panel_edge_high_order ) then - sl_depth = max( sl_depth, 3 ) + transport_depth = max( sl_depth, 3 ) else sl_depth = max( sl_depth, 2 ) end if end if - stencil_depth = max( stencil_depth, sl_depth ) + transport_depth = max( transport_depth, sl_depth ) end if - end function get_required_stencil_depth + ! Loop through meshes to determine whether transport takes place on it + do i = 1, size(base_mesh_names) + if (trim(base_mesh_names(i)) == trim(prime_mesh_name)) then + ! Assume transport always occurs on prime mesh + stencil_depths(i) = transport_depth + + else if (use_multires_coupling .and. coarse_aerosol_transport .and. & + trim(base_mesh_names(i)) == trim(aerosol_mesh_name)) then + ! Coarse mesh transport for aerosols + stencil_depths(i) = transport_depth + + else + ! No transport on this mesh, so set stencil depth to 2 + stencil_depths(i) = 2 + end if + end do + + end subroutine get_required_stencil_depth !> @brief Determine whether any of the transport schemes are MoL !> @details Loops through the transport schemes specified for different diff --git a/science/gungho/source/driver/gungho_model_mod.F90 b/science/gungho/source/driver/gungho_model_mod.F90 index e91f0fbd6..789204f39 100644 --- a/science/gungho/source/driver/gungho_model_mod.F90 +++ b/science/gungho/source/driver/gungho_model_mod.F90 @@ -417,6 +417,7 @@ subroutine initialise_infrastructure( io_context_name, modeldb ) logical(l_def) :: mesh_already_exists integer(i_def) :: i, j, mesh_ctr + integer(i_def), allocatable :: stencil_depths(:) character(str_def), allocatable :: base_mesh_names(:) character(str_def), allocatable :: meshes_to_shift(:) character(str_def), allocatable :: meshes_to_double(:) @@ -445,7 +446,6 @@ subroutine initialise_infrastructure( io_context_name, modeldb ) integer(i_def) :: geometry integer(i_def) :: extrusion_method - integer(i_def) :: stencil_depth real(r_def) :: domain_bottom real(r_def) :: domain_height real(r_def) :: scaled_radius @@ -672,13 +672,15 @@ subroutine initialise_infrastructure( io_context_name, modeldb ) apply_partition_check = .true. end if - stencil_depth = get_required_stencil_depth() + allocate(stencil_depths(size(base_mesh_names))) + call get_required_stencil_depth(stencil_depths, base_mesh_names) + call init_mesh( modeldb%configuration, & modeldb%mpi%get_comm_rank(), & modeldb%mpi%get_comm_size(), & base_mesh_names, & extrusion, & - get_required_stencil_depth(), & + stencil_depths, & apply_partition_check ) From c02b717bf0b49ac966d13f57c4220d2aa5082a03 Mon Sep 17 00:00:00 2001 From: Thomas Bendall <14180399+tommbendall@users.noreply.github.com> Date: Thu, 22 Jan 2026 13:01:59 +0000 Subject: [PATCH 2/4] hopefully fix issues and copy over KGOs --- .../gravity_wave_infrastructure_mod.f90 | 10 +-- .../lfric2lfric_infrastructure_mod.X90 | 5 +- .../initialisation/lfric2lfric_init_mesh.f90 | 2 +- .../common/lfricinp_lfric_driver_mod.f90 | 2 +- .../driver/name_transport_driver_mod.f90 | 26 ++++-- .../source/driver/shallow_water_model_mod.F90 | 4 +- .../source/driver/transport_driver_mod.f90 | 6 +- .../source/mesh/jedi_lfric_mesh_setup_mod.F90 | 17 +++- ...8-500x500_azspice_gnu_fast-debug-64bit.txt | 6 +- ...00x8-500x500_ex1a_gnu_fast-debug-64bit.txt | 6 +- .../mol/adj_reconstruct_w3_field_alg_mod.x90 | 3 +- .../mol/adj_wt_advective_update_alg_mod.x90 | 3 +- .../mol/atl_wt_advective_update_alg_mod.x90 | 3 +- .../integration-test/cma_test/cma_test.f90 | 3 +- .../configuration/check_configuration_mod.F90 | 80 +++++++++++++++---- .../gungho/source/driver/gungho_model_mod.F90 | 5 +- 16 files changed, 127 insertions(+), 54 deletions(-) diff --git a/applications/gravity_wave/source/driver/gravity_wave_infrastructure_mod.f90 b/applications/gravity_wave/source/driver/gravity_wave_infrastructure_mod.f90 index f8db4605b..ccc95e49f 100644 --- a/applications/gravity_wave/source/driver/gravity_wave_infrastructure_mod.f90 +++ b/applications/gravity_wave/source/driver/gravity_wave_infrastructure_mod.f90 @@ -10,7 +10,6 @@ module gravity_wave_infrastructure_mod use add_mesh_map_mod, only : assign_mesh_maps use driver_modeldb_mod, only : modeldb_type - use check_configuration_mod, only : get_required_stencil_depth use constants_mod, only : i_def, & PRECISION_REAL, & r_def, r_second, & @@ -81,7 +80,7 @@ subroutine initialise_infrastructure( program_name, & logical(l_def) :: prepartitioned logical :: apply_partition_check - integer(i_def), allocatable :: stencil_depths + integer(i_def) :: stencil_depth(1) integer(i_def) :: geometry integer(i_def) :: method @@ -192,9 +191,7 @@ subroutine initialise_infrastructure( program_name, & !======================================================================= ! 1.3 Initialise mesh objects and assign InterGrid maps !======================================================================= - allocate( stencil_depths(size(base_mesh_names)) ) - call get_required_stencil_depth(stencil_depths, base_mesh_names) - + stencil_depth = 1 apply_partition_check = .false. if ( .not. prepartitioned .and. l_multigrid ) then apply_partition_check = .true. @@ -204,7 +201,7 @@ subroutine initialise_infrastructure( program_name, & modeldb%mpi%get_comm_rank(), & modeldb%mpi%get_comm_size(), & base_mesh_names, & - extrusion, stencil_depths, & + extrusion, stencil_depth, & apply_partition_check ) allocate( twod_names, source=base_mesh_names ) @@ -243,7 +240,6 @@ subroutine initialise_infrastructure( program_name, & deallocate(twod_names) deallocate(extrusion) deallocate(extrusion_2d) - deallocate(stencil_depths) end subroutine initialise_infrastructure diff --git a/applications/lfric2lfric/source/initialisation/lfric2lfric_infrastructure_mod.X90 b/applications/lfric2lfric/source/initialisation/lfric2lfric_infrastructure_mod.X90 index 108104c11..2626fd50b 100644 --- a/applications/lfric2lfric/source/initialisation/lfric2lfric_infrastructure_mod.X90 +++ b/applications/lfric2lfric/source/initialisation/lfric2lfric_infrastructure_mod.X90 @@ -21,7 +21,6 @@ module lfric2lfric_infrastructure_mod use driver_fem_mod, only: init_fem use driver_io_mod, only: init_io, & filelist_populator - use check_configuration_mod, only: get_required_stencil_depth use extrusion_mod, only: extrusion_type, & uniform_extrusion_type, & prime_extrusion, & @@ -169,7 +168,7 @@ contains integer(kind=i_def) :: origin_domain integer(kind=i_def) :: target_domain - integer(kind=i_def) :: stencil_depth + integer(kind=i_def) :: stencil_depth(1) integer(kind=i_def) :: source_geometry integer(i_def) :: regrid_method real(kind=r_def) :: domain_bottom @@ -315,7 +314,7 @@ contains !----------------------------------------------------------------------- ! Create the required meshes !----------------------------------------------------------------------- - stencil_depth = get_required_stencil_depth() + stencil_depth = 2 call init_mesh( modeldb%configuration, & modeldb%mpi%get_comm_rank(), & modeldb%mpi%get_comm_size(), & diff --git a/applications/lfric2lfric/source/initialisation/lfric2lfric_init_mesh.f90 b/applications/lfric2lfric/source/initialisation/lfric2lfric_init_mesh.f90 index b8073bcf5..aee5ae7af 100644 --- a/applications/lfric2lfric/source/initialisation/lfric2lfric_init_mesh.f90 +++ b/applications/lfric2lfric/source/initialisation/lfric2lfric_init_mesh.f90 @@ -176,7 +176,7 @@ subroutine init_mesh( configuration, & end if ! Set up stencil depths - if ( size(stencils_depths) == 1 ) then + if ( size(stencil_depths) == 1 ) then ! Single stencil depth specified, apply to all meshes do i = 1, size(mesh_names) stencil_depths(i) = stencil_depths_in(1) diff --git a/applications/lfricinputs/source/common/lfricinp_lfric_driver_mod.f90 b/applications/lfricinputs/source/common/lfricinp_lfric_driver_mod.f90 index a0630d7bf..cd39b0b27 100644 --- a/applications/lfricinputs/source/common/lfricinp_lfric_driver_mod.f90 +++ b/applications/lfricinputs/source/common/lfricinp_lfric_driver_mod.f90 @@ -132,7 +132,7 @@ subroutine lfricinp_initialise_lfric(program_name_arg, & character(str_def) :: prime_mesh_name -integer(i_def) :: stencil_depth +integer(i_def) :: stencil_depth(1) integer(i_def) :: geometry real(r_def) :: domain_bottom real(r_def) :: scaled_radius diff --git a/applications/name_transport/source/driver/name_transport_driver_mod.f90 b/applications/name_transport/source/driver/name_transport_driver_mod.f90 index 94e8365c0..1414140b6 100644 --- a/applications/name_transport/source/driver/name_transport_driver_mod.f90 +++ b/applications/name_transport/source/driver/name_transport_driver_mod.f90 @@ -108,12 +108,12 @@ subroutine initialise_name_transport( program_name, modeldb ) character(len=str_def), allocatable :: shifted_names(:) character(len=str_def), allocatable :: double_names(:) character(len=str_def) :: prime_mesh_name + integer(kind=i_def), allocatable :: stencil_depths(:) logical(kind=l_def) :: prepartitioned logical(kind=l_def) :: apply_partition_check integer(kind=i_def) :: geometry - integer(kind=i_def) :: stencil_depth real(kind=r_def) :: domain_bottom real(kind=r_def) :: domain_height real(kind=r_def) :: scaled_radius @@ -236,14 +236,18 @@ subroutine initialise_name_transport( program_name, modeldb ) ! 1.3a Initialise prime/2d meshes ! --------------------------------------------------------- - stencil_depth = get_required_stencil_depth() + allocate(stencil_depths(num_base_meshes)) + call get_required_stencil_depth( & + stencil_depths, base_mesh_names, modeldb%configuration & + ) + apply_partition_check = .false. call init_mesh( modeldb%configuration, & modeldb%mpi%get_comm_rank(), & modeldb%mpi%get_comm_size(), & base_mesh_names, & - extrusion, stencil_depth, & + extrusion, stencil_depths, & apply_partition_check ) call create_mesh( base_mesh_names, extrusion_2d, & @@ -350,11 +354,19 @@ subroutine initialise_name_transport( program_name, modeldb ) end if - if (allocated(base_mesh_names)) deallocate(base_mesh_names) - if (allocated(meshes_to_shift)) deallocate(meshes_to_shift) - if (allocated(meshes_to_double)) deallocate(meshes_to_double) - + if (allocated(base_mesh_names)) deallocate(base_mesh_names) + if (allocated(meshes_to_shift)) deallocate(meshes_to_shift) + if (allocated(meshes_to_double)) deallocate(meshes_to_double) + if (allocated(twod_names)) deallocate(twod_names) + if (allocated(shifted_names)) deallocate(shifted_names) + if (allocated(double_names)) deallocate(double_names) + if (allocated(extrusion)) deallocate(extrusion) + if (allocated(extrusion_2d)) deallocate(extrusion_2d) + if (allocated(extrusion_shifted)) deallocate(extrusion_shifted) + if (allocated(extrusion_double)) deallocate(extrusion_double) + if (allocated(stencil_depths)) deallocate(stencil_depths) if (allocated(extra_io_mesh_names)) deallocate(extra_io_mesh_names) + nullify(chi_inventory, panel_id_inventory, mesh) end subroutine initialise_name_transport diff --git a/applications/shallow_water/source/driver/shallow_water_model_mod.F90 b/applications/shallow_water/source/driver/shallow_water_model_mod.F90 index 073083639..48de3152c 100644 --- a/applications/shallow_water/source/driver/shallow_water_model_mod.F90 +++ b/applications/shallow_water/source/driver/shallow_water_model_mod.F90 @@ -181,7 +181,9 @@ subroutine initialise_infrastructure( program_name, modeldb) ! --------------------------------------------------------- check_partitions = .false. allocate(stencil_depths(size(base_mesh_names))) - call get_required_stencil_depth(stencil_depths, base_mesh_names) + call get_required_stencil_depth( & + stencil_depths, base_mesh_names, modeldb%configuration & + ) call init_mesh( modeldb%configuration, & modeldb%mpi%get_comm_rank(), & modeldb%mpi%get_comm_size(), & diff --git a/applications/transport/source/driver/transport_driver_mod.f90 b/applications/transport/source/driver/transport_driver_mod.f90 index f6c37ecf8..5cc476343 100644 --- a/applications/transport/source/driver/transport_driver_mod.f90 +++ b/applications/transport/source/driver/transport_driver_mod.f90 @@ -125,7 +125,7 @@ subroutine initialise_transport( program_name, modeldb ) character(len=str_def), allocatable :: chain_mesh_tags(:) character(len=str_def) :: aerosol_mesh_name character(len=str_def) :: prime_mesh_name - integer(kind=i_def), allocatable :: stencil_depths + integer(kind=i_def), allocatable :: stencil_depths(:) logical(kind=l_def) :: use_multires_coupling logical(kind=l_def) :: l_multigrid @@ -284,7 +284,9 @@ subroutine initialise_transport( program_name, modeldb ) ! 1.3a Initialise prime/2d meshes ! --------------------------------------------------------- allocate(stencil_depths(num_base_meshes)) - call get_required_stencil_depth(stencil_depths, base_mesh_names) + call get_required_stencil_depth( & + stencil_depths, base_mesh_names, modeldb%configuration & + ) apply_partition_check = .false. if ( .not. prepartitioned .and. & diff --git a/interfaces/jedi_lfric_interface/source/mesh/jedi_lfric_mesh_setup_mod.F90 b/interfaces/jedi_lfric_interface/source/mesh/jedi_lfric_mesh_setup_mod.F90 index 24665d5b9..a1058e3d4 100644 --- a/interfaces/jedi_lfric_interface/source/mesh/jedi_lfric_mesh_setup_mod.F90 +++ b/interfaces/jedi_lfric_interface/source/mesh/jedi_lfric_mesh_setup_mod.F90 @@ -10,6 +10,7 @@ module jedi_lfric_mesh_setup_mod use add_mesh_map_mod, only: assign_mesh_maps use base_mesh_config_mod, only: GEOMETRY_SPHERICAL, & GEOMETRY_PLANAR + use check_configuration_mod, only: get_required_stencil_depth use constants_mod, only: str_def, i_def, l_def, r_def use create_mesh_mod, only: create_mesh use driver_mesh_mod, only: init_mesh @@ -62,7 +63,7 @@ subroutine initialise_mesh( mesh_name, configuration, mpi_obj, alt_mesh_name ) integer(i_def), parameter :: one_layer = 1_i_def integer(i_def) :: geometry integer(i_def) :: extrusion_method - integer(i_def) :: stencil_depth + integer(i_def), allocatable :: stencil_depths(:) integer(i_def) :: number_of_layers integer(i_def) :: i real(r_def) :: domain_bottom @@ -122,14 +123,19 @@ subroutine initialise_mesh( mesh_name, configuration, mpi_obj, alt_mesh_name ) !------------------------------------------------------------------------- ! 1.2 Create the required meshes !------------------------------------------------------------------------- - stencil_depth = 2 + + allocate(stencil_depths(size(base_mesh_names))) + call get_required_stencil_depth( & + stencil_depths, base_mesh_names, configuration & + ) + apply_partition_check = .false. call init_mesh( configuration, & mpi_obj%get_comm_rank(), & mpi_obj%get_comm_size(), & base_mesh_names, & extrusion, & - stencil_depth, & + stencil_depths, & apply_partition_check ) allocate( twod_names, source=base_mesh_names ) @@ -140,6 +146,11 @@ subroutine initialise_mesh( mesh_name, configuration, mpi_obj, alt_mesh_name ) alt_name=twod_names ) call assign_mesh_maps(twod_names) + deallocate(twod_names) + deallocate(stencil_depths) + deallocate(extrusion) + if (allocated(extrusion_2d)) deallocate(extrusion_2d) + end subroutine initialise_mesh end module jedi_lfric_mesh_setup_mod diff --git a/rose-stem/site/meto/kgos/gungho_model/azspice/checksum_gungho_model_schar_cart-BiP200x8-500x500_azspice_gnu_fast-debug-64bit.txt b/rose-stem/site/meto/kgos/gungho_model/azspice/checksum_gungho_model_schar_cart-BiP200x8-500x500_azspice_gnu_fast-debug-64bit.txt index 5697a8812..9ec922232 100644 --- a/rose-stem/site/meto/kgos/gungho_model/azspice/checksum_gungho_model_schar_cart-BiP200x8-500x500_azspice_gnu_fast-debug-64bit.txt +++ b/rose-stem/site/meto/kgos/gungho_model/azspice/checksum_gungho_model_schar_cart-BiP200x8-500x500_azspice_gnu_fast-debug-64bit.txt @@ -1,3 +1,3 @@ -Inner product checksum rho = 40E1E481066A1517 -Inner product checksum theta = 421139232C3CEFAD -Inner product checksum u = 4393A3C2C7771420 +Inner product checksum rho = 40E1E481066A16AD +Inner product checksum theta = 421139232C3CEDFC +Inner product checksum u = 4393A3C2C7765796 diff --git a/rose-stem/site/meto/kgos/gungho_model/ex1a/checksum_gungho_model_schar_cart-BiP200x8-500x500_ex1a_gnu_fast-debug-64bit.txt b/rose-stem/site/meto/kgos/gungho_model/ex1a/checksum_gungho_model_schar_cart-BiP200x8-500x500_ex1a_gnu_fast-debug-64bit.txt index 5697a8812..9ec922232 100644 --- a/rose-stem/site/meto/kgos/gungho_model/ex1a/checksum_gungho_model_schar_cart-BiP200x8-500x500_ex1a_gnu_fast-debug-64bit.txt +++ b/rose-stem/site/meto/kgos/gungho_model/ex1a/checksum_gungho_model_schar_cart-BiP200x8-500x500_ex1a_gnu_fast-debug-64bit.txt @@ -1,3 +1,3 @@ -Inner product checksum rho = 40E1E481066A1517 -Inner product checksum theta = 421139232C3CEFAD -Inner product checksum u = 4393A3C2C7771420 +Inner product checksum rho = 40E1E481066A16AD +Inner product checksum theta = 421139232C3CEDFC +Inner product checksum u = 4393A3C2C7765796 diff --git a/science/adjoint/source/algorithm/transport/mol/adj_reconstruct_w3_field_alg_mod.x90 b/science/adjoint/source/algorithm/transport/mol/adj_reconstruct_w3_field_alg_mod.x90 index b0bac45cf..60c6202f1 100644 --- a/science/adjoint/source/algorithm/transport/mol/adj_reconstruct_w3_field_alg_mod.x90 +++ b/science/adjoint/source/algorithm/transport/mol/adj_reconstruct_w3_field_alg_mod.x90 @@ -7,7 +7,6 @@ !> @brief Adjoint reconstruction of a W3 field at W2 points for use in the transport scheme. module adj_reconstruct_w3_field_alg_mod - use check_configuration_mod, only: get_required_stencil_depth use constants_mod, only: r_tran, i_def, l_def use r_tran_field_mod, only: r_tran_field_type @@ -90,7 +89,7 @@ contains ! Copy field to a large halo version call field_old_big_halo%initialise( field_old%get_function_space(), & - halo_depth = get_required_stencil_depth() ) + halo_depth=mesh%get_halo_depth() ) call invoke( setval_c( field_old_big_halo, 0.0_r_tran ) ) monotone = (transport_metadata%get_horizontal_monotone() == monotone_koren) diff --git a/science/adjoint/source/algorithm/transport/mol/adj_wt_advective_update_alg_mod.x90 b/science/adjoint/source/algorithm/transport/mol/adj_wt_advective_update_alg_mod.x90 index 83fa0a54f..b694bb4e3 100644 --- a/science/adjoint/source/algorithm/transport/mol/adj_wt_advective_update_alg_mod.x90 +++ b/science/adjoint/source/algorithm/transport/mol/adj_wt_advective_update_alg_mod.x90 @@ -7,7 +7,6 @@ module adj_wt_advective_update_alg_mod - use check_configuration_mod, only : get_required_stencil_depth use constants_mod, only : r_tran, i_def, l_def use r_tran_field_mod, only : r_tran_field_type use finite_element_config_mod, only : element_order_h, & @@ -104,7 +103,7 @@ contains ! Copy field to a large halo version call field_big_halo%initialise( field%get_function_space(), & - halo_depth = get_required_stencil_depth() ) + halo_depth=mesh%get_halo_depth() ) ! Compute reconstruction on a Wtheta multidata field ! each Wt point contains 4 values assigned to each edge, diff --git a/science/adjoint/source/algorithm/transport/mol/atl_wt_advective_update_alg_mod.x90 b/science/adjoint/source/algorithm/transport/mol/atl_wt_advective_update_alg_mod.x90 index 09093efb6..7c2ce0f8b 100644 --- a/science/adjoint/source/algorithm/transport/mol/atl_wt_advective_update_alg_mod.x90 +++ b/science/adjoint/source/algorithm/transport/mol/atl_wt_advective_update_alg_mod.x90 @@ -170,7 +170,6 @@ contains !> @param[in] transport_metadata Contains transport configuration options subroutine atl_hori_wt_update_alg(u_grad_f, wind, wind_dir, ls_field, transport_metadata) - use check_configuration_mod, only : get_required_stencil_depth use poly1d_reconstruction_kernel_mod, only : poly1d_reconstruction_kernel_type use poly2d_reconstruction_kernel_mod, only : poly2d_reconstruction_kernel_type use polyh_wtheta_koren_kernel_mod, only : polyh_wtheta_koren_kernel_type @@ -223,7 +222,7 @@ contains ! Copy field to a large halo version call ls_field_big_halo%initialise( ls_field%get_function_space(), & - halo_depth = get_required_stencil_depth() ) + halo_depth=mesh%get_halo_depth() ) call invoke( setval_X( ls_field_big_halo, ls_field ) ) ! Compute reconstruction on a Wtheta multidata field diff --git a/science/gungho/integration-test/cma_test/cma_test.f90 b/science/gungho/integration-test/cma_test/cma_test.f90 index 15d2e18a6..96e96ce6b 100644 --- a/science/gungho/integration-test/cma_test/cma_test.f90 +++ b/science/gungho/integration-test/cma_test/cma_test.f90 @@ -19,7 +19,6 @@ program cma_test use, intrinsic :: iso_fortran_env, only : real64 - use check_configuration_mod, only : get_required_stencil_depth use cma_test_algorithm_mod, only : cma_test_init, & test_cma_apply_mass_p, & test_cma_apply_mass_v, & @@ -289,7 +288,7 @@ program cma_test domain_height, & scaled_radius ) ) - stencil_depth = get_required_stencil_depth(base_mesh_names) + stencil_depth = 2 check_partitions = .false. call init_mesh( configuration, & local_rank, total_ranks, & diff --git a/science/gungho/source/configuration/check_configuration_mod.F90 b/science/gungho/source/configuration/check_configuration_mod.F90 index 78f6a6944..e2a1e8e6e 100644 --- a/science/gungho/source/configuration/check_configuration_mod.F90 +++ b/science/gungho/source/configuration/check_configuration_mod.F90 @@ -71,6 +71,9 @@ module check_configuration_mod monotone_qm_pos, & ffsl_splitting_swift, & ffsl_splitting_cosmic + use namelist_collection_mod, & + only : namelist_collection_type + use namelist_mod, only : namelist_type implicit none @@ -619,25 +622,66 @@ end subroutine check_configuration !> returns required stencil depth that needs to be supported. !> @param[in,out] stencil_depths Array of stencil depths for each base mesh !> @param[in] base_mesh_names Array of base mesh names - !> + !> @param[in] configuration The configuration object !=========================================================================== - subroutine get_required_stencil_depth(stencil_depths, base_mesh_names) - - use base_mesh_config_mod, only: prime_mesh_name - use formulation_config_mod, only: use_multires_coupling - use multires_coupling_config_mod, only: aerosol_mesh_name, & - coarse_aerosol_transport + subroutine get_required_stencil_depth(stencil_depths, base_mesh_names, configuration) implicit none - integer(kind=i_def), intent(inout) :: stencil_depths(:) - character(len=str_def), intent(in) :: base_mesh_names(:) + integer(kind=i_def), intent(inout) :: stencil_depths(:) + character(len=str_def), intent(in) :: base_mesh_names(:) + type(namelist_collection_type), intent(in) :: configuration + integer(kind=i_def) :: i integer(kind=i_def) :: transport_depth, sl_depth integer(kind=i_def) :: special_edge_pts logical(kind=l_def) :: any_horz_dep_pts + ! Configuration variables + type(namelist_type), pointer :: base_mesh_nml + type(namelist_type), pointer :: formulation_nml + type(namelist_type), pointer :: multires_coupling_nml + type(namelist_type), pointer :: transport_nml + character(len=str_def) :: prime_mesh_name + character(len=str_def) :: aerosol_mesh_name + logical(kind=l_def) :: use_multires_coupling + logical(kind=l_def) :: coarse_aerosol_transport + integer(kind=i_def) :: operators + integer(kind=i_def) :: fv_horizontal_order + integer(kind=i_def) :: panel_edge_treatment + logical(kind=l_def) :: panel_edge_high_order + integer(kind=i_def) :: dep_pt_stencil_extent + integer(kind=i_def) :: ffsl_inner_order + integer(kind=i_def) :: ffsl_outer_order + + ! ------------------------------------------------------------------------ ! + ! Get configuration variables + ! ------------------------------------------------------------------------ ! + + base_mesh_nml => configuration%get_namelist('base_mesh') + formulation_nml => configuration%get_namelist('formulation') + transport_nml => configuration%get_namelist('transport') + + call base_mesh_nml%get_value('prime_mesh_name', prime_mesh_name) + call formulation_nml%get_value('use_multires_coupling', use_multires_coupling) + call transport_nml%get_value('operators', operators) + call transport_nml%get_value('fv_horizontal_order', fv_horizontal_order) + call transport_nml%get_value('panel_edge_treatment', panel_edge_treatment) + call transport_nml%get_value('panel_edge_high_order', panel_edge_high_order) + call transport_nml%get_value('dep_pt_stencil_extent', dep_pt_stencil_extent) + call transport_nml%get_value('ffsl_inner_order', ffsl_inner_order) + call transport_nml%get_value('ffsl_outer_order', ffsl_outer_order) + if (use_multires_coupling) then + multires_coupling_nml => configuration%get_namelist('multires_coupling') + call multires_coupling_nml%get_value('aerosol_mesh_name', aerosol_mesh_name) + call multires_coupling_nml%get_value('coarse_aerosol_transport', coarse_aerosol_transport) + end if + + ! ------------------------------------------------------------------------ ! + ! Set default depth + ! ------------------------------------------------------------------------ ! + transport_depth = 2 if (operators == operators_fv) then @@ -645,9 +689,13 @@ subroutine get_required_stencil_depth(stencil_depths, base_mesh_names) transport_depth = max( transport_depth, fv_horizontal_order/2 ) end if + ! ------------------------------------------------------------------------ ! + ! Determine depth when using a semi-Lagrangian scheme + ! ------------------------------------------------------------------------ ! + any_horz_dep_pts = check_horz_dep_pts() - if ( any_horz_dep_pts ) then + if (any_horz_dep_pts) then ! When an SL scheme is used, the halo depth should be large enough to ! encompass the largest anticipated Courant number (effectively the ! departure distance in the SL scheme), plus any extra cells required for @@ -657,8 +705,8 @@ subroutine get_required_stencil_depth(stencil_depths, base_mesh_names) ! - the order of reconstruction ! - whether special edge treatment is used (this shifts the stencil by 1) - if ( panel_edge_treatment == panel_edge_treatment_special_edges & - .AND. panel_edge_high_order ) then + if (panel_edge_treatment == panel_edge_treatment_special_edges & + .AND. panel_edge_high_order) then special_edge_pts = 1 else special_edge_pts = 0 @@ -670,8 +718,8 @@ subroutine get_required_stencil_depth(stencil_depths, base_mesh_names) + special_edge_pts & ! special edge treatment ) - if ( panel_edge_treatment == panel_edge_treatment_remapping ) then - if ( panel_edge_high_order ) then + if (panel_edge_treatment == panel_edge_treatment_remapping) then + if (panel_edge_high_order) then transport_depth = max( sl_depth, 3 ) else sl_depth = max( sl_depth, 2 ) @@ -681,6 +729,10 @@ subroutine get_required_stencil_depth(stencil_depths, base_mesh_names) transport_depth = max( transport_depth, sl_depth ) end if + ! ------------------------------------------------------------------------ ! + ! Set depth for each mesh + ! ------------------------------------------------------------------------ ! + ! Loop through meshes to determine whether transport takes place on it do i = 1, size(base_mesh_names) if (trim(base_mesh_names(i)) == trim(prime_mesh_name)) then diff --git a/science/gungho/source/driver/gungho_model_mod.F90 b/science/gungho/source/driver/gungho_model_mod.F90 index 789204f39..00c9842f7 100644 --- a/science/gungho/source/driver/gungho_model_mod.F90 +++ b/science/gungho/source/driver/gungho_model_mod.F90 @@ -673,7 +673,9 @@ subroutine initialise_infrastructure( io_context_name, modeldb ) end if allocate(stencil_depths(size(base_mesh_names))) - call get_required_stencil_depth(stencil_depths, base_mesh_names) + call get_required_stencil_depth( & + stencil_depths, base_mesh_names, modeldb%configuration & + ) call init_mesh( modeldb%configuration, & modeldb%mpi%get_comm_rank(), & @@ -924,6 +926,7 @@ subroutine initialise_infrastructure( io_context_name, modeldb ) chi_inventory, panel_id_inventory, files_init_ptr, & orography_mesh, orography_twod_mesh) deallocate(base_mesh_names) + deallocate(stencil_depths) if (allocated(meshes_to_shift)) deallocate(meshes_to_shift) if (allocated(meshes_to_double)) deallocate(meshes_to_double) From 7746a863071bc5a39f1e2215de433d112dabbbe7 Mon Sep 17 00:00:00 2001 From: Thomas Bendall <14180399+tommbendall@users.noreply.github.com> Date: Thu, 22 Jan 2026 15:02:48 +0000 Subject: [PATCH 3/4] hopefully final fixes --- CONTRIBUTORS.md | 1 + .../source/driver/gravity_wave_infrastructure_mod.f90 | 2 +- .../source/initialisation/lfric2lfric_init_mesh.f90 | 5 +++-- 3 files changed, 5 insertions(+), 3 deletions(-) diff --git a/CONTRIBUTORS.md b/CONTRIBUTORS.md index da42a74b5..a07ebda4e 100644 --- a/CONTRIBUTORS.md +++ b/CONTRIBUTORS.md @@ -5,3 +5,4 @@ | james-bruten-mo | James Bruten | Met Office | 2025-12-09 | | jennyhickson | Jenny Hickson | Met Office | 2025-12-10 | | mo-marqh | mark Hedley | Met Office | 2025-12-11 | +| tommbendall | Thomas Bendall | Met Office | 2026-01-22 | \ No newline at end of file diff --git a/applications/gravity_wave/source/driver/gravity_wave_infrastructure_mod.f90 b/applications/gravity_wave/source/driver/gravity_wave_infrastructure_mod.f90 index ccc95e49f..0526e935b 100644 --- a/applications/gravity_wave/source/driver/gravity_wave_infrastructure_mod.f90 +++ b/applications/gravity_wave/source/driver/gravity_wave_infrastructure_mod.f90 @@ -191,7 +191,7 @@ subroutine initialise_infrastructure( program_name, & !======================================================================= ! 1.3 Initialise mesh objects and assign InterGrid maps !======================================================================= - stencil_depth = 1 + stencil_depth = 2 apply_partition_check = .false. if ( .not. prepartitioned .and. l_multigrid ) then apply_partition_check = .true. diff --git a/applications/lfric2lfric/source/initialisation/lfric2lfric_init_mesh.f90 b/applications/lfric2lfric/source/initialisation/lfric2lfric_init_mesh.f90 index aee5ae7af..744176645 100644 --- a/applications/lfric2lfric/source/initialisation/lfric2lfric_init_mesh.f90 +++ b/applications/lfric2lfric/source/initialisation/lfric2lfric_init_mesh.f90 @@ -98,7 +98,7 @@ subroutine init_mesh( configuration, & integer(kind=i_def), intent(in) :: total_ranks character(len=*), intent(in) :: mesh_names(2) class(extrusion_type), intent(in) :: extrusion - integer(kind=i_def), intent(in) :: stencil_depths_in + integer(kind=i_def), intent(in) :: stencil_depths_in(:) integer(kind=i_def), intent(in) :: regrid_method ! Parameters @@ -124,6 +124,7 @@ subroutine init_mesh( configuration, & integer(kind=i_def) :: mesh_selection(2) ! Local variables + integer(kind=i_def) :: i character(len=str_max_filename) :: mesh_file(2) integer(kind=i_def) :: stencil_depths(2) @@ -183,7 +184,7 @@ subroutine init_mesh( configuration, & end do else if ( size(stencil_depths) == size(mesh_names) ) then ! Stencil depths specified per mesh - stencil_depths = stencil_depths_in + stencil_depths(:) = stencil_depths_in(:) else write(log_scratch_space, '(A)') & 'Number of stencil depths specified does not '// & From 27e9ce823c9631c939f3f0baaf8992cc91f734cd Mon Sep 17 00:00:00 2001 From: Thomas Bendall <14180399+tommbendall@users.noreply.github.com> Date: Mon, 26 Jan 2026 17:47:44 +0000 Subject: [PATCH 4/4] alignment --- .../lfric2lfric/source/initialisation/lfric2lfric_init_mesh.f90 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/applications/lfric2lfric/source/initialisation/lfric2lfric_init_mesh.f90 b/applications/lfric2lfric/source/initialisation/lfric2lfric_init_mesh.f90 index 744176645..d1b282198 100644 --- a/applications/lfric2lfric/source/initialisation/lfric2lfric_init_mesh.f90 +++ b/applications/lfric2lfric/source/initialisation/lfric2lfric_init_mesh.f90 @@ -186,7 +186,7 @@ subroutine init_mesh( configuration, & ! Stencil depths specified per mesh stencil_depths(:) = stencil_depths_in(:) else - write(log_scratch_space, '(A)') & + write(log_scratch_space, '(A)') & 'Number of stencil depths specified does not '// & 'match number of requested meshes.' call log_event(log_scratch_space, log_level_error)