diff --git a/components/driver/source/driver_mesh_mod.f90 b/components/driver/source/driver_mesh_mod.f90 index 40157459a..e4911e225 100644 --- a/components/driver/source/driver_mesh_mod.f90 +++ b/components/driver/source/driver_mesh_mod.f90 @@ -56,6 +56,11 @@ module driver_mesh_mod use finite_element_config_mod, only: cellshape_quadrilateral use base_mesh_config_mod, only: geometry_spherical, & topology_fully_periodic + use timing_mod, only: start_timing, stop_timing, & + tik, LPROF + use ugrid_2d_mod, only: ugrid_2d_type + use ugrid_file_mod, only: ugrid_file_type + use ncdf_quad_mod, only: ncdf_quad_type implicit none @@ -146,7 +151,12 @@ subroutine init_mesh( config, & character(str_def) :: fmt_str, number_str integer(i_def) :: i, n_digit + integer(tik) :: timing_id + type(ugrid_2d_type) :: ugrid_2d + class(ugrid_file_type), allocatable :: file_handler + + if ( LPROF ) call start_timing(timing_id, 'driver.init_mesh') !============================================================================ ! Extract configuration variables !============================================================================ @@ -212,7 +222,6 @@ subroutine init_mesh( config, & allocate(names, source=mesh_names) end if - !=========================================================================== ! Create local mesh objects: ! Two code pathes presented, either: @@ -245,6 +254,18 @@ subroutine init_mesh( config, & write(number_str, fmt_str) local_rank write(input_mesh_file, '(A, "_", A, "-", I0, ".nc")') & trim(file_prefix), trim(number_str), total_ranks + !==== + ! Open mesh file + ! Once! + !==== + write(log_scratch_space, '(A)') & + 'opening file: "'// trim(input_mesh_file) // & + '" with MPI-IO for shared access' + call log_event(log_scratch_space, LOG_LEVEL_debug) + + allocate( ncdf_quad_type :: file_handler ) + call ugrid_2d%set_file_handler( file_handler ) + call ugrid_2d%file_handler_open(trim(input_mesh_file)) call log_event( 'Using pre-partitioned mesh file:', log_level_debug ) call log_event( ' '//trim(input_mesh_file), log_level_debug ) @@ -256,7 +277,7 @@ subroutine init_mesh( config, & !=========================================================== ! Each partitioned mesh file will contain meshes of the ! same name as all other partitions. - call load_local_mesh( input_mesh_file, mesh_names ) + call load_local_mesh( input_mesh_file, mesh_names, ugrid_2d ) ! Apply configuration related checks to ensure that these ! meshes are suitable for the supplied application @@ -273,7 +294,7 @@ subroutine init_mesh( config, & ! need to be loaded after the relevant local meshes have ! been loaded. tmp_mesh_names = local_mesh_collection%get_mesh_names() - call load_local_mesh_maps( input_mesh_file, tmp_mesh_names ) + call load_local_mesh_maps( input_mesh_file, tmp_mesh_names, ugrid_2d ) if (allocated(tmp_mesh_names)) deallocate(tmp_mesh_names) else @@ -298,6 +319,19 @@ subroutine init_mesh( config, & end if write(input_mesh_file,'(A)') trim(file_prefix) // '.nc' + !==== + ! Open mesh file + ! Once! + !==== + write(log_scratch_space, '(A)') & + 'opening file: "'// trim(input_mesh_file) // & + '" with MPI-IO for shared access' + call log_event(log_scratch_space, LOG_LEVEL_debug) + + allocate( ncdf_quad_type :: file_handler ) + call ugrid_2d%set_file_handler( file_handler ) + call ugrid_2d%file_handler_open(trim(input_mesh_file)) + ! 2.2a Set constants that will control partitioning. !=========================================================== call get_partition_parameters( config%partitioning, mesh_selection, & @@ -306,7 +340,7 @@ subroutine init_mesh( config, & ! 2.2b Read in all global meshes from input file !=========================================================== - call load_global_mesh( input_mesh_file, mesh_names ) + call load_global_mesh( input_mesh_file, mesh_names, ugrid_2d ) ! 2.2c Apply configuration related checks to ensure that these ! meshes are suitable for the supplied application @@ -328,13 +362,17 @@ subroutine init_mesh( config, & ! 2.2f Read in the global intergrid mesh mappings, ! then create the associated local mesh maps !=========================================================== - call create_local_mesh_maps( input_mesh_file ) + call create_local_mesh_maps( input_mesh_file, ugrid_2d ) ! Clear the global mesh call global_mesh_collection%clear() end if ! prepartitioned + call ugrid_2d%file_handler_close() + if (allocated(file_handler)) deallocate( file_handler ) + + !============================================================================ ! 3.0 Extrude the specified meshes from local mesh objects into ! mesh objects on the given extrusion. @@ -350,6 +388,7 @@ subroutine init_mesh( config, & call assign_mesh_maps(mesh_names) deallocate(stencil_depths) + if ( LPROF ) call stop_timing(timing_id, 'driver.init_mesh') end subroutine init_mesh diff --git a/components/driver/source/mesh/load_global_mesh_mod.f90 b/components/driver/source/mesh/load_global_mesh_mod.f90 index 074b27e54..c50be0dfc 100644 --- a/components/driver/source/mesh/load_global_mesh_mod.f90 +++ b/components/driver/source/mesh/load_global_mesh_mod.f90 @@ -16,6 +16,7 @@ module load_global_mesh_mod use global_mesh_collection_mod, only: global_mesh_collection + use ugrid_2d_mod, only: ugrid_2d_type implicit none @@ -37,7 +38,7 @@ module load_global_mesh_mod !> @param[in] mesh_names The names of the global meshes to load !> from the . subroutine load_global_mesh_multiple( input_mesh_file, & - mesh_names ) + mesh_names, ugrid_2d ) implicit none @@ -45,10 +46,11 @@ subroutine load_global_mesh_multiple( input_mesh_file, & character(str_def), intent(in) :: mesh_names(:) integer(i_def) :: i + type(ugrid_2d_type), intent(inout) :: ugrid_2d do i=1, size(mesh_names) call load_global_mesh_single( input_mesh_file, & - mesh_names(i) ) + mesh_names(i), ugrid_2d ) end do end subroutine load_global_mesh_multiple @@ -61,7 +63,7 @@ end subroutine load_global_mesh_multiple !> @param[in] mesh_name The name of the global mesh to load !> from the . subroutine load_global_mesh_single( input_mesh_file, & - mesh_name ) + mesh_name, ugrid_2d ) implicit none @@ -71,6 +73,8 @@ subroutine load_global_mesh_single( input_mesh_file, & type(ugrid_mesh_data_type) :: ugrid_mesh_data type(global_mesh_type) :: global_mesh + type(ugrid_2d_type), intent(inout) :: ugrid_2d + if (.not. global_mesh_collection%check_for(mesh_name)) then write(log_scratch_space,'(A)') & @@ -79,7 +83,7 @@ subroutine load_global_mesh_single( input_mesh_file, & ! Load mesh data into global_mesh call ugrid_mesh_data%read_from_file( trim(input_mesh_file), & - mesh_name ) + mesh_name, ugrid_2d ) global_mesh = global_mesh_type( ugrid_mesh_data ) call ugrid_mesh_data%clear() diff --git a/components/driver/source/mesh/load_local_mesh_maps_mod.f90 b/components/driver/source/mesh/load_local_mesh_maps_mod.f90 index a866e1268..b98de37f5 100644 --- a/components/driver/source/mesh/load_local_mesh_maps_mod.f90 +++ b/components/driver/source/mesh/load_local_mesh_maps_mod.f90 @@ -12,6 +12,7 @@ module load_local_mesh_maps_mod log_scratch_space, & LOG_LEVEL_ERROR use ncdf_quad_mod, only: ncdf_quad_type + use ugrid_2d_mod, only: ugrid_2d_type use local_mesh_collection_mod, only: local_mesh_collection @@ -39,18 +40,19 @@ module load_local_mesh_maps_mod !> @param[in] source_mesh_name The name of the local source mesh to !> load maps from the . subroutine load_local_mesh_maps_multiple_source( input_mesh_file, & - source_mesh_names ) + source_mesh_names, ugrid_2d ) implicit none character(str_max_filename), intent(in) :: input_mesh_file - character(str_def), intent(in) :: source_mesh_names(:) + character(str_def), intent(inout) :: source_mesh_names(:) + type(ugrid_2d_type), intent(inout) :: ugrid_2d integer(i_def) :: i do i=1, size(source_mesh_names) call load_local_mesh_maps_single_source( input_mesh_file, & - source_mesh_names(i) ) + source_mesh_names(i), ugrid_2d ) end do end subroutine load_local_mesh_maps_multiple_source @@ -67,22 +69,21 @@ end subroutine load_local_mesh_maps_multiple_source !> @param[in] source_mesh_name The name of the local source mesh to load !> maps from the . subroutine load_local_mesh_maps_single_source( input_mesh_file, & - source_mesh_name ) + source_mesh_name, ugrid_2d ) implicit none character(str_max_filename), intent(in) :: input_mesh_file - character(str_def), intent(in) :: source_mesh_name + character(str_def), intent(inout) :: source_mesh_name character(str_def), allocatable :: target_mesh_names(:) integer(i_def), allocatable :: lid_mesh_map(:,:,:) integer(i_def) :: i - type(ncdf_quad_type) :: file_handler - type(local_mesh_type), pointer :: source_mesh => null() type(local_mesh_type), pointer :: target_mesh => null() + type(ugrid_2d_type), intent(inout) :: ugrid_2d integer(i_def) :: target_mesh_id @@ -100,15 +101,13 @@ subroutine load_local_mesh_maps_single_source( input_mesh_file, & if (allocated(target_mesh_names)) then - call file_handler%file_open(trim(input_mesh_file)) - do i=1, size(target_mesh_names) if ( local_mesh_collection%check_for( target_mesh_names(i) ) ) then ! Read in the local mesh map. - call file_handler%read_map( source_mesh_name, & - target_mesh_names(i), & - lid_mesh_map ) + call ugrid_2d%file_handler_read_map( source_mesh_name, & + target_mesh_names(i), & + lid_mesh_map ) target_mesh & => local_mesh_collection%get_local_mesh(target_mesh_names(i)) @@ -123,8 +122,6 @@ subroutine load_local_mesh_maps_single_source( input_mesh_file, & end if end do - call file_handler%file_close() - deallocate( target_mesh_names ) end if diff --git a/components/driver/source/mesh/load_local_mesh_mod.f90 b/components/driver/source/mesh/load_local_mesh_mod.f90 index 2488e7ce3..318b6ec48 100644 --- a/components/driver/source/mesh/load_local_mesh_mod.f90 +++ b/components/driver/source/mesh/load_local_mesh_mod.f90 @@ -16,6 +16,7 @@ module load_local_mesh_mod use sci_query_mod, only: is_lbc use local_mesh_collection_mod, only: local_mesh_collection + use ugrid_2d_mod, only: ugrid_2d_type implicit none @@ -37,16 +38,17 @@ module load_local_mesh_mod !> @param[in] mesh_names The names of the local mesh data to !> load from the . subroutine load_local_mesh_multiple( input_mesh_file, & - mesh_names ) + mesh_names, ugrid_2d ) implicit none character(str_max_filename), intent(in) :: input_mesh_file character(str_def), intent(in) :: mesh_names(:) integer(i_def) :: i + type(ugrid_2d_type), intent(inout) :: ugrid_2d do i=1, size(mesh_names) - call load_local_mesh_single( input_mesh_file, mesh_names(i) ) + call load_local_mesh_single( input_mesh_file, mesh_names(i), ugrid_2d ) end do end subroutine load_local_mesh_multiple @@ -59,7 +61,7 @@ end subroutine load_local_mesh_multiple !> @param[in] mesh_name The name of the local mesh data to !> load from the . subroutine load_local_mesh_single( input_mesh_file, & - mesh_name ) + mesh_name, ugrid_2d ) implicit none @@ -70,11 +72,12 @@ subroutine load_local_mesh_single( input_mesh_file, & type(local_mesh_type) :: local_mesh integer(i_def) :: local_mesh_id + type(ugrid_2d_type), intent(inout) :: ugrid_2d if (.not. local_mesh_collection%check_for(mesh_name)) then ! Load mesh data into local_mesh - call ugrid_mesh_data%read_from_file( input_mesh_file, mesh_name ) + call ugrid_mesh_data%read_from_file( input_mesh_file, mesh_name, ugrid_2d ) if (ugrid_mesh_data%contains_mesh()) then diff --git a/components/driver/source/mesh/runtime_partition_mod.f90 b/components/driver/source/mesh/runtime_partition_mod.f90 index aa849c9a8..168fcccfc 100644 --- a/components/driver/source/mesh/runtime_partition_mod.f90 +++ b/components/driver/source/mesh/runtime_partition_mod.f90 @@ -28,6 +28,7 @@ module runtime_partition_mod use local_mesh_collection_mod, only: local_mesh_collection use global_mesh_collection_mod, only: global_mesh_collection + use ugrid_2d_mod, only: ugrid_2d_type implicit none @@ -198,13 +199,13 @@ end subroutine create_local_mesh !! mesh object. !! !> @param[in] input_mesh_file Input file to load mesh maps from. -subroutine create_local_mesh_maps( input_mesh_file ) +subroutine create_local_mesh_maps( input_mesh_file, ugrid_2d ) implicit none character(len=str_max_filename) :: input_mesh_file - type(ncdf_quad_type) :: file_handler + type(ugrid_2d_type), intent(inout) :: ugrid_2d character(str_def), allocatable :: source_mesh_names(:) character(str_def), allocatable :: target_mesh_names(:) @@ -225,7 +226,6 @@ subroutine create_local_mesh_maps( input_mesh_file ) ! Read in the maps for each global mesh !================================================================= - call file_handler%file_open(trim(input_mesh_file)) allocate( source_mesh_names, & source=global_mesh_collection%get_mesh_names() ) @@ -251,9 +251,9 @@ subroutine create_local_mesh_maps( input_mesh_file ) if ( associated(target_local_mesh) ) then ! Read in the global mesh map - call file_handler%read_map( source_mesh_names(i), & - target_mesh_names(j), & - gid_mesh_map ) + call ugrid_2d%file_handler_read_map( source_mesh_names(i), & + target_mesh_names(j), & + gid_mesh_map ) ! Create the local mesh map ntarget_per_source_cell_x = size(gid_mesh_map, 1) @@ -296,8 +296,6 @@ subroutine create_local_mesh_maps( input_mesh_file ) deallocate( source_mesh_names) end if - call file_handler%file_close() - return end subroutine create_local_mesh_maps diff --git a/components/driver/unit-test/mesh/create_mesh_mod_test.pf b/components/driver/unit-test/mesh/create_mesh_mod_test.pf index 4a50fecbe..d62def11a 100644 --- a/components/driver/unit-test/mesh/create_mesh_mod_test.pf +++ b/components/driver/unit-test/mesh/create_mesh_mod_test.pf @@ -26,6 +26,9 @@ module create_mesh_mod_test use extrusion_config_mod, only: method_uniform use partitioning_config_mod, only: panel_decomposition_auto, & partitioner_planar + use ugrid_2d_mod, only: ugrid_2d_type + use ugrid_file_mod, only: ugrid_file_type + use ncdf_quad_mod, only: ncdf_quad_type use pfunit @@ -94,6 +97,13 @@ contains integer(i_def) :: local_mesh_id logical(l_def), parameter :: enforce_constraints = .true. + type(ugrid_2d_type) :: ugrid_2d + + class(ugrid_file_type), allocatable :: file_handler + + allocate( ncdf_quad_type :: file_handler ) + call ugrid_2d%set_file_handler( file_handler ) + call ugrid_2d%file_handler_open(trim(filename)) ! Reset in case of repeated initialisation call mesh_collection%clear() @@ -104,7 +114,7 @@ contains nullify( partitioner_ptr ) ! Read mesh from file and initialise mesh collections - call ugrid_mesh_data%read_from_file( trim( filename ), mesh_name ) + call ugrid_mesh_data%read_from_file( trim( filename ), mesh_name, ugrid_2d ) global_mesh = global_mesh_type( ugrid_mesh_data ) call ugrid_mesh_data%clear() call global_mesh_collection%add_new_global_mesh( global_mesh ) diff --git a/infrastructure/source/io/ugrid_2d_mod.F90 b/infrastructure/source/io/ugrid_2d_mod.F90 index 007ea13ad..15996afe0 100644 --- a/infrastructure/source/io/ugrid_2d_mod.F90 +++ b/infrastructure/source/io/ugrid_2d_mod.F90 @@ -15,6 +15,7 @@ module ugrid_2d_mod imdi, rmdi, cmdi use file_mod, only: file_mode_write use ugrid_file_mod, only: ugrid_file_type +use log_mod, only: log_event, log_level_error use local_mesh_map_collection_mod, only: local_mesh_map_collection_type @@ -133,6 +134,7 @@ module ugrid_2d_mod class(ugrid_file_type), allocatable :: file_handler logical :: populated_with_mesh = .false. + logical :: file_handler_file_open = .false. contains procedure :: get_n_meshes @@ -140,6 +142,9 @@ module ugrid_2d_mod procedure :: get_dimensions procedure :: set_by_generator procedure :: set_file_handler + procedure :: file_handler_open + procedure :: file_handler_close + procedure :: file_handler_read_map procedure :: set_from_file_read procedure :: write_to_file procedure :: append_to_file @@ -258,9 +263,7 @@ subroutine get_mesh_names(self, filename, mesh_names) character(len=*), intent(in) :: filename character(len=*), intent(out) :: mesh_names(:) - call self%file_handler%file_open(trim(filename)) call self%file_handler%get_mesh_names(mesh_names) - call self%file_handler%file_close() return end subroutine get_mesh_names @@ -279,9 +282,7 @@ subroutine get_n_meshes(self, filename, n_meshes) character(len=*), intent(in) :: filename integer(i_def), intent(out) :: n_meshes - call self%file_handler%file_open(trim(filename)) n_meshes = self%file_handler%get_n_meshes() - call self%file_handler%file_close() return end subroutine get_n_meshes @@ -483,6 +484,96 @@ subroutine set_file_handler(self, file_handler) return end subroutine set_file_handler +!------------------------------------------------------------------------------- +!> @brief Open the filename file using the file_handler +!> @details Receives a filename and opens the filename using the +!> file_handler, which must be already set. +!> +!> @param[in] filename The filename to open. +!------------------------------------------------------------------------------- +subroutine file_handler_open(self, filename) + implicit none + + class(ugrid_2d_type), intent(inout) :: self + character(len=*), intent(in) :: filename + + if ( .not. allocated (self%file_handler) ) then + call log_event('ugrid_2d file handler not set on open', log_level_error) + end if + + if ( .not. self%file_handler_file_open ) then + call self%file_handler%file_open(trim(filename)) + self%file_handler_file_open = .true. + end if + return +end subroutine file_handler_open + +!------------------------------------------------------------------------------- +!> @brief Closes the file using the file_handler +!> @details Closes the file using the provided +!> file_handler, which must be already set. +!> +!------------------------------------------------------------------------------- +subroutine file_handler_close(self) + implicit none + + class(ugrid_2d_type), intent(inout) :: self + + if ( .not. allocated (self%file_handler) ) then + call log_event('ugrid_2d file handler not set on close', log_level_error) + end if + + if ( self%file_handler_file_open ) then + call self%file_handler%file_close() + self%file_handler_file_open = .false. + end if + return +end subroutine file_handler_close + +!------------------------------------------------------------------------------- +!> @brief Call `read-map` on the file_handler. +!> @details Wrapper to enable the ugrid_2d object's file_handler to call its +!> `read_map` subroutine and pass through relevant arguments. +!> The file_handler must be set on the object and the file open. +!> +!> @param[in] source_mesh_name Name of the source mesh object +!> @param[in] target_mesh_name Name of the target mesh object +!> @param[out] mesh_map Intergrid mapping array which maps +!> source mesh cells to target mesh +!> cells. Allocatable integer array, +!> returned as +!> [n target cells per source x, +!> n target cells per source y, +!> n source cells] +!------------------------------------------------------------------------------- +subroutine file_handler_read_map( self, & + source_mesh_name, & + target_mesh_name, & + mesh_map ) + + implicit none + + class(ugrid_2d_type), intent(inout) :: self + character(str_def), intent(inout) :: source_mesh_name + character(str_def), intent(inout) :: target_mesh_name + integer(i_def), intent(out), allocatable :: mesh_map(:,:,:) + + if ( .not. allocated (self%file_handler) ) then + call log_event('ugrid_2d file handler not set on close', log_level_error) + end if + + if ( .not. self%file_handler_file_open ) then + call log_event('ugrid_2d file handler file not open on read_map', & + log_level_error) + end if + + call self%file_handler%read_map(source_mesh_name, & + target_mesh_name, & + mesh_map ) + + return +end subroutine file_handler_read_map + !------------------------------------------------------------------------------- !> @brief Reads ugrid information and populates internal arrays. !> @details Calls back to the file handler strategy (component) in order to @@ -504,11 +595,10 @@ subroutine set_from_file_read(self, mesh_name, filename) self%mesh_name = trim(mesh_name) - call self%file_handler%file_open(trim(filename)) if (.not. self%file_handler%is_mesh_present(trim(mesh_name))) then self%populated_with_mesh = .false. - call self%file_handler%file_close() + return end if @@ -547,9 +637,6 @@ subroutine set_from_file_read(self, mesh_name, filename) self%nmaps, self%target_mesh_names ) - - call self%file_handler%file_close() - self%populated_with_mesh = .true. return diff --git a/infrastructure/source/mesh/ugrid_mesh_data_mod.f90 b/infrastructure/source/mesh/ugrid_mesh_data_mod.f90 index 2e6206df5..c9f94f2dc 100644 --- a/infrastructure/source/mesh/ugrid_mesh_data_mod.f90 +++ b/infrastructure/source/mesh/ugrid_mesh_data_mod.f90 @@ -16,6 +16,7 @@ module ugrid_mesh_data_mod str_longlong, cmdi, imdi, rmdi use log_mod, only: log_event, log_scratch_space, & LOG_LEVEL_ERROR, LOG_LEVEL_TRACE + use ugrid_2d_mod, only: ugrid_2d_type implicit none @@ -170,11 +171,7 @@ module ugrid_mesh_data_mod !> @param[in] global_mesh_name Name of ugrid mesh topology to create !> global mesh object from. !> - subroutine read_from_file( self, filename, global_mesh_name ) - - use ugrid_2d_mod, only: ugrid_2d_type - use ugrid_file_mod, only: ugrid_file_type - use ncdf_quad_mod, only: ncdf_quad_type + subroutine read_from_file( self, filename, global_mesh_name, ugrid_2d ) implicit none @@ -182,14 +179,10 @@ subroutine read_from_file( self, filename, global_mesh_name ) character(*), intent(in) :: filename character(*), intent(in) :: global_mesh_name - type(ugrid_2d_type) :: ugrid_2d - - class(ugrid_file_type), allocatable :: file_handler + type(ugrid_2d_type), intent(inout) :: ugrid_2d call self%clear() - allocate( ncdf_quad_type :: file_handler ) - call ugrid_2d%set_file_handler( file_handler ) call ugrid_2d%set_from_file_read( trim(global_mesh_name), trim(filename) ) self%populated_with_mesh = .false. @@ -205,8 +198,6 @@ subroutine read_from_file( self, filename, global_mesh_name ) self%populated_with_mesh = .true. end if - if (allocated(file_handler)) deallocate( file_handler ) - end subroutine read_from_file diff --git a/infrastructure/unit-test/function_space/function_space_chain_mod_test.pf b/infrastructure/unit-test/function_space/function_space_chain_mod_test.pf index defeb59e5..f7316295d 100644 --- a/infrastructure/unit-test/function_space/function_space_chain_mod_test.pf +++ b/infrastructure/unit-test/function_space/function_space_chain_mod_test.pf @@ -33,6 +33,9 @@ use local_mesh_collection_mod, only: local_mesh_collection_type, & local_mesh_collection use ugrid_mesh_data_mod, only: ugrid_mesh_data_type use panel_decomposition_mod, only: custom_decomposition_type +use ugrid_2d_mod, only: ugrid_2d_type +use ugrid_file_mod, only: ugrid_file_type +use ncdf_quad_mod, only: ncdf_quad_type implicit none @@ -132,6 +135,13 @@ logical(l_def), parameter :: enforce_constraints = .true. procedure (partitioner_interface), pointer :: partitioner_ptr => null() type(custom_decomposition_type) :: decomposition + type(ugrid_2d_type) :: ugrid_2d + + class(ugrid_file_type), allocatable :: file_handler_ + + allocate( ncdf_quad_type :: file_handler_ ) + call ugrid_2d%set_file_handler( file_handler_ ) + call ugrid_2d%file_handler_open(trim(filename)) call lfric_comm%set_comm_mpi_val(this%getMpiCommunicator()) @@ -150,7 +160,7 @@ function_space_collection = function_space_collection_type() ! Create all the meshes: global and local do i=1, size(mesh_names) - call ugrid_mesh_data%read_from_file(trim(filename), mesh_names(i)) + call ugrid_mesh_data%read_from_file(trim(filename), mesh_names(i), ugrid_2d) global_mesh = global_mesh_type( ugrid_mesh_data ) call ugrid_mesh_data%clear() call global_mesh_collection%add_new_global_mesh( global_mesh ) @@ -167,6 +177,8 @@ do i=1, size(mesh_names) call global_mesh%clear() call local_mesh%clear() enddo +call ugrid_2d%file_handler_close() +if (allocated(file_handler_)) deallocate( file_handler_ ) ! Now all the meshes exist, read in global mesh maps, convert them to local ids ! and associate them with the approprate source local mesh diff --git a/infrastructure/unit-test/mesh/global_mesh_collection_mod_test.pf b/infrastructure/unit-test/mesh/global_mesh_collection_mod_test.pf index aea985f31..d885c7d5f 100644 --- a/infrastructure/unit-test/mesh/global_mesh_collection_mod_test.pf +++ b/infrastructure/unit-test/mesh/global_mesh_collection_mod_test.pf @@ -16,6 +16,9 @@ module global_mesh_collection_mod_test use global_mesh_collection_mod, only: global_mesh_collection_type, & global_mesh_collection use ugrid_mesh_data_mod, only: ugrid_mesh_data_type + use ugrid_2d_mod, only: ugrid_2d_type + use ugrid_file_mod, only: ugrid_file_type + use ncdf_quad_mod, only: ncdf_quad_type use funit @@ -91,12 +94,20 @@ contains character(str_max_filename) :: filename integer (i_def) :: global_mesh_id + type(ugrid_2d_type) :: ugrid_2d + + class(ugrid_file_type), allocatable :: file_handler filename = CubedSphereFile + allocate( ncdf_quad_type :: file_handler ) + call ugrid_2d%set_file_handler( file_handler ) + call ugrid_2d%file_handler_open(trim(filename)) - call ugrid_mesh_data%read_from_file(trim(filename), mesh_name) + call ugrid_mesh_data%read_from_file(trim(filename), mesh_name, ugrid_2d) global_mesh = global_mesh_type( ugrid_mesh_data ) call ugrid_mesh_data%clear() + call ugrid_2d%file_handler_close() + if (allocated(file_handler)) deallocate( file_handler ) global_mesh_id = global_mesh%get_id() call global_mesh_collection%add_new_global_mesh( global_mesh ) global_mesh_ptr => global_mesh_collection % & @@ -124,12 +135,20 @@ contains character(str_max_filename) :: filename integer (i_def) :: global_mesh_id + type(ugrid_2d_type) :: ugrid_2d + + class(ugrid_file_type), allocatable :: file_handler filename = BiPeriodicFile + allocate( ncdf_quad_type :: file_handler ) + call ugrid_2d%set_file_handler( file_handler ) + call ugrid_2d%file_handler_open(trim(filename)) - call ugrid_mesh_data%read_from_file(trim(filename), mesh_name) + call ugrid_mesh_data%read_from_file(trim(filename), mesh_name, ugrid_2d) global_mesh = global_mesh_type( ugrid_mesh_data ) call ugrid_mesh_data%clear() + call ugrid_2d%file_handler_close() + if (allocated(file_handler)) deallocate( file_handler ) global_mesh_id = global_mesh%get_id() call global_mesh_collection%add_new_global_mesh( global_mesh ) global_mesh_ptr => global_mesh_collection % & @@ -216,6 +235,14 @@ contains integer (i_def) :: kgo_integer type(ncdf_quad_type) :: file_handler + type(ugrid_2d_type) :: ugrid_2d + + class(ugrid_file_type), allocatable :: file_handler_ + + allocate( ncdf_quad_type :: file_handler_ ) + call ugrid_2d%set_file_handler( file_handler_ ) + call ugrid_2d%file_handler_open(trim(filename)) + ! First read all the requested global meshes into memory. ! This is done because the intergrid map ids are based @@ -224,7 +251,7 @@ contains do i=1, size(multigrid_mesh_names) call ugrid_mesh_data%read_from_file( trim(filename), & - multigrid_mesh_names(i) ) + multigrid_mesh_names(i), ugrid_2d ) global_mesh = global_mesh_type( ugrid_mesh_data ) call ugrid_mesh_data%clear() multigrid_ids(i) = global_mesh%get_id() @@ -233,11 +260,13 @@ contains do i=1, size(another_chain) call ugrid_mesh_data%read_from_file( trim(filename), & - another_chain(i) ) + another_chain(i), ugrid_2d ) global_mesh = global_mesh_type( ugrid_mesh_data ) call ugrid_mesh_data%clear() call global_mesh_collection%add_new_global_mesh( global_mesh ) end do + call ugrid_2d%file_handler_close() + if (allocated(file_handler_)) deallocate( file_handler_ ) ! Now get the ids of the `chains` from the collection do i=1, size(multigrid_mesh_names) diff --git a/infrastructure/unit-test/mesh/global_mesh_mod_test.pf b/infrastructure/unit-test/mesh/global_mesh_mod_test.pf index d4654bca6..db6a72323 100644 --- a/infrastructure/unit-test/mesh/global_mesh_mod_test.pf +++ b/infrastructure/unit-test/mesh/global_mesh_mod_test.pf @@ -16,6 +16,9 @@ module global_mesh_mod_test use global_mesh_collection_mod, only: global_mesh_collection_type, & global_mesh_collection use ugrid_mesh_data_mod, only: ugrid_mesh_data_type + use ugrid_2d_mod, only: ugrid_2d_type + use ugrid_file_mod, only: ugrid_file_type + use ncdf_quad_mod, only: ncdf_quad_type use funit @@ -99,15 +102,24 @@ contains real(r_def) :: vert_coords(2) real(r_def) :: cell_coords(2) + type(ugrid_2d_type) :: ugrid_2d + + class(ugrid_file_type), allocatable :: file_handler !------------------------------------- ! Test construction of a biperiodic mesh !------------------------------------- filename = 'data/mesh_BiP8x8-750x250.nc' - call ugrid_mesh_data%read_from_file(trim(filename), mesh_name) + allocate( ncdf_quad_type :: file_handler ) + call ugrid_2d%set_file_handler( file_handler ) + call ugrid_2d%file_handler_open(trim(filename)) + + call ugrid_mesh_data%read_from_file(trim(filename), mesh_name, ugrid_2d) global_mesh = global_mesh_type( ugrid_mesh_data ) call ugrid_mesh_data%clear() + call ugrid_2d%file_handler_close() + if (allocated(file_handler)) deallocate( file_handler ) ! Check the global mesh id global_mesh_id1 = global_mesh%get_id() @@ -258,14 +270,23 @@ contains real(r_def) :: cell_coords(2) real(r_def) :: vert_coords(2) + type(ugrid_2d_type) :: ugrid_2d + + class(ugrid_file_type), allocatable :: file_handler !--------------------------------------- ! Test construction of a cubed-sphere mesh !--------------------------------------- filename = 'data/mesh_C4.nc' - call ugrid_mesh_data%read_from_file(trim(filename), mesh_name) + allocate( ncdf_quad_type :: file_handler ) + call ugrid_2d%set_file_handler( file_handler ) + call ugrid_2d%file_handler_open(trim(filename)) + + call ugrid_mesh_data%read_from_file(trim(filename), mesh_name, ugrid_2d) global_mesh = global_mesh_type( ugrid_mesh_data ) call ugrid_mesh_data%clear() + call ugrid_2d%file_handler_close() + if (allocated(file_handler)) deallocate( file_handler ) ! Check the global mesh id global_mesh_id2 = global_mesh%get_id() @@ -417,15 +438,23 @@ contains type(global_mesh_type) :: global_mesh character(str_def) :: mesh_name = 'C4' + type(ugrid_2d_type) :: ugrid_2d + + class(ugrid_file_type), allocatable :: file_handler filename='data/mesh_C32_MG.nc' + allocate( ncdf_quad_type :: file_handler ) + call ugrid_2d%set_file_handler( file_handler ) + call ugrid_2d%file_handler_open(trim(filename)) !------------------------------------------------- ! Test construction of a cubed-sphere mesh is same !------------------------------------------------- mesh_name = 'C4' - call ugrid_mesh_data%read_from_file(trim(filename), mesh_name) + call ugrid_mesh_data%read_from_file(trim(filename), mesh_name, ugrid_2d) global_mesh = global_mesh_type( ugrid_mesh_data ) call ugrid_mesh_data%clear() + call ugrid_2d%file_handler_close() + if (allocated(file_handler)) deallocate( file_handler ) ! Check details of C4 mesh @@ -540,6 +569,9 @@ contains type(global_mesh_map_type), pointer :: global_mesh_map => null() type(global_mesh_type) :: global_mesh integer(i_def), allocatable :: mesh_map(:,:,:) + type(ugrid_2d_type) :: ugrid_2d + + class(ugrid_file_type), allocatable :: file_handler_ !------------------------------------------------- ! Test construction of a cubed-sphere mesh is same @@ -548,18 +580,23 @@ contains npanels = 6 filename='data/mesh_C32_MG.nc' + allocate( ncdf_quad_type :: file_handler_ ) + call ugrid_2d%set_file_handler( file_handler_ ) + call ugrid_2d%file_handler_open(trim(filename)) ! 1.0 First read all the requested global meshes into memory. ! This is done because the intergrid map ids are based ! on the global mesh ids. So all the required global mesh ! topologies must be read in first. do i=1, size(multigrid_mesh_names) - call ugrid_mesh_data%read_from_file(trim(filename), multigrid_mesh_names(i)) + call ugrid_mesh_data%read_from_file(trim(filename), multigrid_mesh_names(i), ugrid_2d) global_mesh = global_mesh_type( ugrid_mesh_data ) call ugrid_mesh_data%clear() MultiGrid_ids(i) = global_mesh%get_id() call global_mesh_collection%add_new_global_mesh( global_mesh ) end do + call ugrid_2d%file_handler_close() + if (allocated(file_handler_)) deallocate( file_handler_ ) ! Check that each ID appears only once ! diff --git a/infrastructure/unit-test/mesh/local_mesh_collection_mod_test.pf b/infrastructure/unit-test/mesh/local_mesh_collection_mod_test.pf index fed2bad63..3ba3d28ab 100644 --- a/infrastructure/unit-test/mesh/local_mesh_collection_mod_test.pf +++ b/infrastructure/unit-test/mesh/local_mesh_collection_mod_test.pf @@ -23,6 +23,9 @@ module local_mesh_collection_mod_test partitioner_interface use ugrid_mesh_data_mod, only : ugrid_mesh_data_type use panel_decomposition_mod, only : custom_decomposition_type + use ugrid_2d_mod, only: ugrid_2d_type + use ugrid_file_mod, only: ugrid_file_type + use ncdf_quad_mod, only: ncdf_quad_type use pfunit @@ -100,13 +103,22 @@ contains logical(l_def) :: generate_inner_halos logical(l_def), parameter :: enforce_constraints = .false. + type(ugrid_2d_type) :: ugrid_2d + + class(ugrid_file_type), allocatable :: file_handler filename = 'data/mesh_BiP8x8-750x250.nc' mesh_name = 'unit_test' - call ugrid_mesh_data%read_from_file(trim(filename), mesh_name) + allocate( ncdf_quad_type :: file_handler ) + call ugrid_2d%set_file_handler( file_handler ) + call ugrid_2d%file_handler_open(trim(filename)) + + call ugrid_mesh_data%read_from_file(trim(filename), mesh_name, ugrid_2d) global_mesh = global_mesh_type( ugrid_mesh_data ) call ugrid_mesh_data%clear() + call ugrid_2d%file_handler_close() + if (allocated(file_handler)) deallocate( file_handler ) global_mesh_id = global_mesh%get_id() call global_mesh_collection%add_new_global_mesh( global_mesh ) global_mesh_ptr => global_mesh_collection%get_global_mesh( global_mesh_id ) diff --git a/infrastructure/unit-test/mesh/local_mesh_mod_test.pf b/infrastructure/unit-test/mesh/local_mesh_mod_test.pf index 495f0a08a..dc8ae7ca9 100644 --- a/infrastructure/unit-test/mesh/local_mesh_mod_test.pf +++ b/infrastructure/unit-test/mesh/local_mesh_mod_test.pf @@ -28,6 +28,9 @@ module local_mesh_mod_test partitioner_interface use ugrid_mesh_data_mod, only: ugrid_mesh_data_type use panel_decomposition_mod, only: custom_decomposition_type + use ugrid_2d_mod, only: ugrid_2d_type + use ugrid_file_mod, only: ugrid_file_type + use ncdf_quad_mod, only: ncdf_quad_type implicit none @@ -144,17 +147,26 @@ contains logical(l_def), parameter :: enforce_constraints = .false. logical(l_def) :: answer + type(ugrid_2d_type) :: ugrid_2d + + class(ugrid_file_type), allocatable :: file_handler ! Create a local mesh from partitioning a global mesh on 1 and 4 processors num_processes = this%context%getNumProcesses() filename = 'data/mesh_BiP8x8-750x250.nc' + allocate( ncdf_quad_type :: file_handler ) + call ugrid_2d%set_file_handler( file_handler ) + call ugrid_2d%file_handler_open(trim(filename)) + mesh_name = 'unit_test' npanels = 1 - call ugrid_mesh_data%read_from_file(trim(filename), mesh_name) + call ugrid_mesh_data%read_from_file(trim(filename), mesh_name, ugrid_2d) global_mesh = global_mesh_type( ugrid_mesh_data ) call ugrid_mesh_data%clear() + call ugrid_2d%file_handler_close() + if (allocated(file_handler)) deallocate( file_handler ) global_mesh_id = global_mesh%get_id() call global_mesh_collection%add_new_global_mesh( global_mesh ) global_mesh_ptr => global_mesh_collection%get_global_mesh( global_mesh_id ) @@ -484,9 +496,15 @@ contains type(local_mesh_type), target :: local_mesh(2) type(local_mesh_map_type), pointer :: local_mesh_map integer(i_def), allocatable :: mesh_map(:,:,:) + type(ugrid_2d_type) :: ugrid_2d + + class(ugrid_file_type), allocatable :: file_handler_ npanels = 6 filename='data/mesh_C32_MG.nc' + allocate( ncdf_quad_type :: file_handler_ ) + call ugrid_2d%set_file_handler( file_handler_ ) + call ugrid_2d%file_handler_open(trim(filename)) xproc = 1 yproc = 1 @@ -499,7 +517,7 @@ contains partitioner_ptr => partitioner_cubedsphere_serial decomposition = custom_decomposition_type(xproc, yproc) do i=1, size(mesh_names) - call ugrid_mesh_data%read_from_file(trim(filename), mesh_names(i)) + call ugrid_mesh_data%read_from_file(trim(filename), mesh_names(i), ugrid_2d) global_mesh = global_mesh_type( ugrid_mesh_data ) call ugrid_mesh_data%clear() global_mesh_ptr => global_mesh @@ -511,6 +529,8 @@ contains call local_mesh(i)%initialise( global_mesh_ptr, partition ) nullify(global_mesh_ptr) end do + call ugrid_2d%file_handler_close() + if (allocated(file_handler_)) deallocate( file_handler_ ) nullify(partitioner_ptr) @@ -768,16 +788,26 @@ contains 41,void,42,void, 43,44,void,void, & 45,46,void,void, 47,48,void,void, & 49,void,void,void ], (/ 2, 2, 16/) ) + type(ugrid_2d_type) :: ugrid_2d + + class(ugrid_file_type), allocatable :: file_handler_ + + allocate( ncdf_quad_type :: file_handler_ ) + call ugrid_2d%set_file_handler( file_handler_ ) + call ugrid_2d%file_handler_open(trim(filename)) + !=========================================================================== ! Setup !=========================================================================== ! 1.0 Read in local meshes do i=1, size(mesh_names) - call ugrid_mesh_data%read_from_file( filename, mesh_names(i) ) + call ugrid_mesh_data%read_from_file( filename, mesh_names(i), ugrid_2d ) call local_meshes(i)%initialise( ugrid_mesh_data ) call ugrid_mesh_data%clear() end do + call ugrid_2d%file_handler_close() + if (allocated(file_handler_)) deallocate( file_handler_ ) ! 2.0 Read in local mesh_maps call file_handler%file_open(filename) diff --git a/infrastructure/unit-test/mesh/mesh_colouring_mod_test.pf b/infrastructure/unit-test/mesh/mesh_colouring_mod_test.pf index 4c87b6dec..92b6f6599 100644 --- a/infrastructure/unit-test/mesh/mesh_colouring_mod_test.pf +++ b/infrastructure/unit-test/mesh/mesh_colouring_mod_test.pf @@ -20,6 +20,9 @@ module mesh_colouring_mod_test use local_mesh_mod, only : local_mesh_type use ugrid_mesh_data_mod, only : ugrid_mesh_data_type use panel_decomposition_mod, only: custom_decomposition_type + use ugrid_2d_mod, only: ugrid_2d_type + use ugrid_file_mod, only: ugrid_file_type + use ncdf_quad_mod, only: ncdf_quad_type implicit none @@ -132,11 +135,22 @@ subroutine test_compute_colours_cubedsphere(this) logical(l_def), parameter :: generate_inner_halos = .true. logical(l_def), parameter :: enforce_constraints = .false. + type(ugrid_2d_type) :: ugrid_2d + + class(ugrid_file_type), allocatable :: file_handler filename = "data/mesh_C4.nc" - call ugrid_mesh_data%read_from_file(trim(filename), mesh_name) + allocate( ncdf_quad_type :: file_handler ) + call ugrid_2d%set_file_handler( file_handler ) + call ugrid_2d%file_handler_open(trim(filename)) + ! Run through mesh construction process to initialise tiling via + ! the mesh_type API + call ugrid_mesh_data%read_from_file( trim(filename), mesh_name, ugrid_2d ) global_mesh = global_mesh_type( ugrid_mesh_data ) call ugrid_mesh_data%clear() + call ugrid_2d%file_handler_close() + if (allocated(file_handler)) deallocate( file_handler ) + global_mesh_ptr => global_mesh decomposition = custom_decomposition_type(this%xproc, this%yproc) @@ -259,11 +273,22 @@ subroutine test_compute_colours_biperiodic(this) logical(l_def), parameter :: generate_inner_halos = .true. logical(l_def), parameter :: enforce_constraints = .false. integer(i_def), parameter :: max_stencil_depth = 1 + type(ugrid_2d_type) :: ugrid_2d + + class(ugrid_file_type), allocatable :: file_handler filename = "data/mesh_BiP8x8-750x250.nc" - call ugrid_mesh_data%read_from_file(trim(filename), mesh_name) + allocate( ncdf_quad_type :: file_handler ) + call ugrid_2d%set_file_handler( file_handler ) + call ugrid_2d%file_handler_open(trim(filename)) + ! Run through mesh construction process to initialise tiling via + ! the mesh_type API + call ugrid_mesh_data%read_from_file( trim(filename), mesh_name, ugrid_2d ) global_mesh = global_mesh_type( ugrid_mesh_data ) call ugrid_mesh_data%clear() + call ugrid_2d%file_handler_close() + if (allocated(file_handler)) deallocate( file_handler ) + global_mesh_ptr => global_mesh decomposition = custom_decomposition_type(this%xproc, this%yproc) @@ -362,13 +387,22 @@ subroutine test_compute_colours_generic(this) logical(l_def), parameter :: generate_inner_halos = .true. logical(l_def), parameter :: enforce_constraints = .false. integer(i_def), parameter :: max_stencil_depth = 1 + type(ugrid_2d_type) :: ugrid_2d + class(ugrid_file_type), allocatable :: file_handler + + filename = "data/mesh_C4.nc" + allocate( ncdf_quad_type :: file_handler ) + call ugrid_2d%set_file_handler( file_handler ) + call ugrid_2d%file_handler_open(trim(filename)) ! Force colour generator to use generic colour routine by not saying ! it's a cubed sphere - filename = "data/mesh_C4.nc" - call ugrid_mesh_data%read_from_file(trim(filename), mesh_name) + call ugrid_mesh_data%read_from_file( trim(filename), mesh_name, ugrid_2d ) global_mesh = global_mesh_type( ugrid_mesh_data ) call ugrid_mesh_data%clear() + call ugrid_2d%file_handler_close() + if (allocated(file_handler)) deallocate( file_handler ) + global_mesh_ptr => global_mesh partitioner_ptr => partitioner_cubedsphere_serial diff --git a/infrastructure/unit-test/mesh/mesh_map_collection_mod_test.pf b/infrastructure/unit-test/mesh/mesh_map_collection_mod_test.pf index e3d5c7425..50a20c0b6 100644 --- a/infrastructure/unit-test/mesh/mesh_map_collection_mod_test.pf +++ b/infrastructure/unit-test/mesh/mesh_map_collection_mod_test.pf @@ -24,6 +24,9 @@ module mesh_map_collection_mod_test partitioner_cubedsphere_serial use ugrid_mesh_data_mod, only: ugrid_mesh_data_type use panel_decomposition_mod, only: custom_decomposition_type + use ugrid_2d_mod, only: ugrid_2d_type + use ugrid_file_mod, only: ugrid_file_type + use ncdf_quad_mod, only: ncdf_quad_type use pfunit @@ -89,6 +92,13 @@ contains procedure (partitioner_interface), pointer :: partitioner_ptr => null() type(custom_decomposition_type) :: decomposition type(lfric_comm_type) :: lfric_comm + type(ugrid_2d_type) :: ugrid_2d + + class(ugrid_file_type), allocatable :: file_handler + + allocate( ncdf_quad_type :: file_handler ) + call ugrid_2d%set_file_handler( file_handler ) + call ugrid_2d%file_handler_open(trim(filename)) call lfric_comm%set_comm_mpi_val(this%getMpiCommunicator()) @@ -106,7 +116,7 @@ contains ! Get coarse mesh name = 'C4' - call ugrid_mesh_data%read_from_file(trim(filename), name) + call ugrid_mesh_data%read_from_file(trim(filename), name, ugrid_2d) coarse_global_mesh = global_mesh_type( ugrid_mesh_data ) coarse_global_mesh_ptr => coarse_global_mesh call ugrid_mesh_data%clear() @@ -127,10 +137,12 @@ contains this%coarse_mesh = mesh_type( coarse_local_mesh_ptr, extrusion ) ! Get fine mesh name = 'C8' - call ugrid_mesh_data%read_from_file(trim(filename), name) + call ugrid_mesh_data%read_from_file(trim(filename), name, ugrid_2d) fine_global_mesh = global_mesh_type( ugrid_mesh_data ) fine_global_mesh_ptr => fine_global_mesh call ugrid_mesh_data%clear() + call ugrid_2d%file_handler_close() + if (allocated(file_handler)) deallocate( file_handler ) fine_partition = partition_type( fine_global_mesh_ptr, & partitioner_ptr, & diff --git a/infrastructure/unit-test/mesh/mesh_map_mod_test.pf b/infrastructure/unit-test/mesh/mesh_map_mod_test.pf index 012cd33fe..3c4bec309 100644 --- a/infrastructure/unit-test/mesh/mesh_map_mod_test.pf +++ b/infrastructure/unit-test/mesh/mesh_map_mod_test.pf @@ -23,6 +23,9 @@ module mesh_map_mod_test partitioner_cubedsphere_serial use ugrid_mesh_data_mod, only: ugrid_mesh_data_type use panel_decomposition_mod, only: custom_decomposition_type + use ugrid_2d_mod, only: ugrid_2d_type + use ugrid_file_mod, only: ugrid_file_type + use ncdf_quad_mod, only: ncdf_quad_type use pfunit @@ -163,6 +166,13 @@ contains procedure (partitioner_interface), pointer :: partitioner_ptr => null() type(custom_decomposition_type) :: decomposition type(lfric_comm_type) :: lfric_comm + type(ugrid_2d_type) :: ugrid_2d + + class(ugrid_file_type), allocatable :: file_handler + + allocate( ncdf_quad_type :: file_handler ) + call ugrid_2d%set_file_handler( file_handler ) + call ugrid_2d%file_handler_open(trim(filename)) call lfric_comm%set_comm_mpi_val(this%getMpiCommunicator()) @@ -180,7 +190,7 @@ contains ! Get coarse mesh name = 'C4' - call ugrid_mesh_data%read_from_file(trim(filename), name) + call ugrid_mesh_data%read_from_file( trim(filename), name, ugrid_2d ) coarse_global_mesh = global_mesh_type( ugrid_mesh_data ) coarse_global_mesh_ptr => coarse_global_mesh call ugrid_mesh_data%clear() @@ -201,10 +211,12 @@ contains this%coarse_mesh = mesh_type( coarse_local_mesh_ptr, extrusion ) ! Get fine mesh name = 'C8' - call ugrid_mesh_data%read_from_file(trim(filename), name) + call ugrid_mesh_data%read_from_file( trim(filename), name, ugrid_2d ) fine_global_mesh = global_mesh_type( ugrid_mesh_data ) fine_global_mesh_ptr => fine_global_mesh call ugrid_mesh_data%clear() + call ugrid_2d%file_handler_close() + if (allocated(file_handler)) deallocate( file_handler ) fine_partition = partition_type( fine_global_mesh_ptr, & partitioner_ptr, & diff --git a/infrastructure/unit-test/mesh/mesh_mod_test.pf b/infrastructure/unit-test/mesh/mesh_mod_test.pf index 853811920..ad8752e5d 100644 --- a/infrastructure/unit-test/mesh/mesh_mod_test.pf +++ b/infrastructure/unit-test/mesh/mesh_mod_test.pf @@ -37,6 +37,9 @@ module mesh_mod_test partitioner_cubedsphere_serial use ugrid_mesh_data_mod, only: ugrid_mesh_data_type use panel_decomposition_mod, only: custom_decomposition_type + use ugrid_2d_mod, only: ugrid_2d_type + use ugrid_file_mod, only: ugrid_file_type + use ncdf_quad_mod, only: ncdf_quad_type use pfunit @@ -797,6 +800,9 @@ contains integer(i_def), parameter :: max_stencil_depth = 1 logical(l_def), parameter :: generate_inner_halos = .true. logical(l_def), parameter :: enforce_constraints = .true. + type(ugrid_2d_type) :: ugrid_2d + + class(ugrid_file_type), allocatable :: file_handler_ ! Clear out the global and local mesh collection, as they may contain ! unit test meshes - which is not what we want. @@ -807,9 +813,13 @@ contains mesh_collection = mesh_collection_type() partitioner_ptr => partitioner_cubedsphere_serial + allocate( ncdf_quad_type :: file_handler_ ) + call ugrid_2d%set_file_handler( file_handler_ ) + call ugrid_2d%file_handler_open(trim(filename)) + ! Create all the meshes: global and local do i=1, size(mesh_names) - call ugrid_mesh_data%read_from_file(trim(filename), mesh_names(i)) + call ugrid_mesh_data%read_from_file( trim(filename), mesh_names(i), ugrid_2d ) global_mesh = global_mesh_type( ugrid_mesh_data ) call ugrid_mesh_data%clear() call global_mesh_collection%add_new_global_mesh( global_mesh ) @@ -827,6 +837,8 @@ contains call global_mesh%clear() call local_mesh%clear() end do + call ugrid_2d%file_handler_close() + if (allocated(file_handler_)) deallocate( file_handler_ ) ! Now all the meshes exist, read in global mesh maps, convert them to local ids ! and associate them with the approprate source local mesh diff --git a/infrastructure/unit-test/mesh/mesh_tiling_mod_test.pf b/infrastructure/unit-test/mesh/mesh_tiling_mod_test.pf index ef0112604..e4a498b04 100644 --- a/infrastructure/unit-test/mesh/mesh_tiling_mod_test.pf +++ b/infrastructure/unit-test/mesh/mesh_tiling_mod_test.pf @@ -19,6 +19,9 @@ module mesh_tiling_mod_test use lfric_mpi_mod, only: global_mpi, & lfric_comm_type use panel_decomposition_mod, only: custom_decomposition_type + use ugrid_2d_mod, only: ugrid_2d_type + use ugrid_file_mod, only: ugrid_file_type + use ncdf_quad_mod, only: ncdf_quad_type use pfunit @@ -123,13 +126,21 @@ contains procedure(partitioner_interface), pointer :: partitioner_ptr => null() logical(l_def), parameter :: enforce_constraints = .false. + type(ugrid_2d_type) :: ugrid_2d + class(ugrid_file_type), allocatable :: file_handler + + allocate( ncdf_quad_type :: file_handler ) + call ugrid_2d%set_file_handler( file_handler ) + call ugrid_2d%file_handler_open(trim(filename)) ! Run through mesh construction process to initialise tiling via ! the mesh_type API - call ugrid_mesh_data%read_from_file( trim(filename), mesh_name ) + call ugrid_mesh_data%read_from_file( trim(filename), mesh_name, ugrid_2d ) global_mesh = global_mesh_type( ugrid_mesh_data ) call ugrid_mesh_data%clear() - global_mesh_id = global_mesh%get_id() + call ugrid_2d%file_handler_close() + if (allocated(file_handler)) deallocate( file_handler ) + global_mesh_id = global_mesh%get_id() call global_mesh_collection%add_new_global_mesh( global_mesh ) global_mesh_ptr => global_mesh_collection%get_global_mesh( global_mesh_id ) diff --git a/infrastructure/unit-test/mesh/partition_mod_test.pf b/infrastructure/unit-test/mesh/partition_mod_test.pf index 54747c204..b4989e29e 100644 --- a/infrastructure/unit-test/mesh/partition_mod_test.pf +++ b/infrastructure/unit-test/mesh/partition_mod_test.pf @@ -24,6 +24,9 @@ module partition_mod_test use reference_element_mod, only: reference_cube_type use ugrid_mesh_data_mod, only: ugrid_mesh_data_type use panel_decomposition_mod, only: custom_decomposition_type + use ugrid_2d_mod, only: ugrid_2d_type + use ugrid_file_mod, only: ugrid_file_type + use ncdf_quad_mod, only: ncdf_quad_type implicit none @@ -125,6 +128,9 @@ contains logical(l_def), parameter :: enforce_constraints = .false. character(len = str_max_filename) :: filename + type(ugrid_2d_type) :: ugrid_2d + + class(ugrid_file_type), allocatable :: file_handler num_processes = this%context%getNumProcesses() select case (num_processes) @@ -146,9 +152,15 @@ contains generate_inner_halos = .true. filename = 'data/mesh_BiP8x8-750x250.nc' - call ugrid_mesh_data%read_from_file(trim(filename), mesh_name) + allocate( ncdf_quad_type :: file_handler ) + call ugrid_2d%set_file_handler( file_handler ) + call ugrid_2d%file_handler_open(trim(filename)) + + call ugrid_mesh_data%read_from_file(trim(filename), mesh_name, ugrid_2d) global_mesh = global_mesh_type( ugrid_mesh_data ) call ugrid_mesh_data%clear() + call ugrid_2d%file_handler_close() + if (allocated(file_handler)) deallocate( file_handler ) global_mesh_id = global_mesh%get_id() call global_mesh_collection%add_new_global_mesh( global_mesh ) global_mesh_ptr => global_mesh_collection%get_global_mesh( global_mesh_id ) @@ -342,6 +354,9 @@ contains logical(l_def), parameter :: enforce_constraints = .false. character(len = str_max_filename) :: filename + type(ugrid_2d_type) :: ugrid_2d + + class(ugrid_file_type), allocatable :: file_handler num_processes = this%context%getNumProcesses() select case (num_processes) @@ -363,10 +378,15 @@ contains generate_inner_halos = .true. filename = 'data/mesh_planar.nc' + allocate( ncdf_quad_type :: file_handler ) + call ugrid_2d%set_file_handler( file_handler ) + call ugrid_2d%file_handler_open(trim(filename)) - call ugrid_mesh_data%read_from_file(trim(filename), mesh_name) + call ugrid_mesh_data%read_from_file(trim(filename), mesh_name, ugrid_2d) global_mesh = global_mesh_type( ugrid_mesh_data ) call ugrid_mesh_data%clear() + call ugrid_2d%file_handler_close() + if (allocated(file_handler)) deallocate( file_handler ) global_mesh_id = global_mesh%get_id() call global_mesh_collection%add_new_global_mesh( global_mesh ) @@ -589,6 +609,9 @@ contains logical(l_def), parameter :: enforce_constraints = .false. character(len = str_max_filename) :: filename + type(ugrid_2d_type) :: ugrid_2d + + class(ugrid_file_type), allocatable :: file_handler num_processes = this%context%getNumProcesses() select case (num_processes) @@ -610,10 +633,15 @@ contains generate_inner_halos = .true. filename = 'data/mesh_trench_x.nc' + allocate( ncdf_quad_type :: file_handler ) + call ugrid_2d%set_file_handler( file_handler ) + call ugrid_2d%file_handler_open(trim(filename)) - call ugrid_mesh_data%read_from_file(trim(filename), mesh_name) + call ugrid_mesh_data%read_from_file(trim(filename), mesh_name, ugrid_2d) global_mesh = global_mesh_type( ugrid_mesh_data ) call ugrid_mesh_data%clear() + call ugrid_2d%file_handler_close() + if (allocated(file_handler)) deallocate( file_handler ) global_mesh_id = global_mesh%get_id() call global_mesh_collection%add_new_global_mesh( global_mesh ) @@ -807,6 +835,9 @@ contains logical(l_def), parameter :: enforce_constraints =.false. character(len = str_max_filename) :: filename + type(ugrid_2d_type) :: ugrid_2d + + class(ugrid_file_type), allocatable :: file_handler num_processes = this%context%getNumProcesses() select case (num_processes) @@ -828,10 +859,15 @@ contains generate_inner_halos = .true. filename = 'data/mesh_trench_y.nc' + allocate( ncdf_quad_type :: file_handler ) + call ugrid_2d%set_file_handler( file_handler ) + call ugrid_2d%file_handler_open(trim(filename)) - call ugrid_mesh_data%read_from_file(trim(filename), mesh_name) + call ugrid_mesh_data%read_from_file(trim(filename), mesh_name, ugrid_2d) global_mesh = global_mesh_type( ugrid_mesh_data ) call ugrid_mesh_data%clear() + call ugrid_2d%file_handler_close() + if (allocated(file_handler)) deallocate( file_handler ) global_mesh_id = global_mesh%get_id() call global_mesh_collection%add_new_global_mesh( global_mesh ) @@ -1057,6 +1093,9 @@ contains logical(l_def), parameter :: enforce_constraints = .false. character(len = str_max_filename) :: filename + type(ugrid_2d_type) :: ugrid_2d + + class(ugrid_file_type), allocatable :: file_handler xproc = 1 yproc = 1 @@ -1068,9 +1107,14 @@ contains generate_inner_halos = .true. filename = 'data/mesh_C4.nc' - call ugrid_mesh_data%read_from_file(trim(filename), mesh_name) + allocate( ncdf_quad_type :: file_handler ) + call ugrid_2d%set_file_handler( file_handler ) + call ugrid_2d%file_handler_open(trim(filename)) + call ugrid_mesh_data%read_from_file(trim(filename), mesh_name, ugrid_2d) global_mesh = global_mesh_type( ugrid_mesh_data ) call ugrid_mesh_data%clear() + call ugrid_2d%file_handler_close() + if (allocated(file_handler)) deallocate( file_handler ) global_mesh_id = global_mesh%get_id() call global_mesh_collection%add_new_global_mesh( global_mesh ) global_mesh_ptr => global_mesh_collection%get_global_mesh( global_mesh_id ) diff --git a/infrastructure/unit-test/mesh/ugrid_mesh_data_mod_test.pf b/infrastructure/unit-test/mesh/ugrid_mesh_data_mod_test.pf index 74bc38346..456aad801 100644 --- a/infrastructure/unit-test/mesh/ugrid_mesh_data_mod_test.pf +++ b/infrastructure/unit-test/mesh/ugrid_mesh_data_mod_test.pf @@ -13,6 +13,9 @@ module ugrid_mesh_data_mod_test use lfric_mpi_mod, only: global_mpi, & lfric_comm_type use ugrid_mesh_data_mod, only: ugrid_mesh_data_type + use ugrid_2d_mod, only: ugrid_2d_type + use ugrid_file_mod, only: ugrid_file_type + use ncdf_quad_mod, only: ncdf_quad_type use pfunit @@ -101,13 +104,20 @@ contains character(str_def) :: coord_units_xy(2) character(str_longlong) :: constructor_inputs + type(ugrid_2d_type) :: ugrid_2d + + class(ugrid_file_type), allocatable :: file_handler !------------------------------------- ! Test ugrid_mesh_data object !------------------------------------- mesh_name_in = 'unit_test' filename = 'data/mesh_BiP8x8-750x250.nc' - call ugrid_mesh_data%read_from_file(trim(filename), mesh_name_in) + allocate( ncdf_quad_type :: file_handler ) + call ugrid_2d%set_file_handler( file_handler ) + call ugrid_2d%file_handler_open(trim(filename)) + + call ugrid_mesh_data%read_from_file(trim(filename), mesh_name_in, ugrid_2d) call ugrid_mesh_data%get_data( & mesh_name_out, & @@ -187,6 +197,8 @@ contains @assertEqual( [128_i_def, 24_i_def, 121_i_def, 120_i_def], edge_on_face_2d(:,64) ) call ugrid_mesh_data%clear() + call ugrid_2d%file_handler_close() + if (allocated(file_handler)) deallocate( file_handler ) if ( allocated(target_global_mesh_names) ) deallocate( target_global_mesh_names ) @@ -450,6 +462,10 @@ contains 271,272,273,231, 273,274,275,233, 275,276,277,235, 277,278,279,237, & 279,280,281,239 ], (/4, kgo_n_faces/) ) + type(ugrid_2d_type) :: ugrid_2d + + class(ugrid_file_type), allocatable :: file_handler + kgo_domain_extents(:,1) = [ -4.0_r_def, -4.0_r_def] kgo_domain_extents(:,2) = [ 16.0_r_def, -4.0_r_def] kgo_domain_extents(:,3) = [ 16.0_r_def, 16.0_r_def] @@ -457,7 +473,11 @@ contains mesh_name_in = 'SQ20' filename = 'data/dev_LAM_locals_20-24.nc' - call ugrid_mesh_data%read_from_file(trim(filename), mesh_name_in) + + allocate( ncdf_quad_type :: file_handler ) + call ugrid_2d%set_file_handler( file_handler ) + call ugrid_2d%file_handler_open(trim(filename)) + call ugrid_mesh_data%read_from_file(trim(filename), mesh_name_in, ugrid_2d) call ugrid_mesh_data%get_data( & mesh_name_out, & @@ -561,6 +581,8 @@ contains @assertEqual( kgo_edge_on_cell_gid, edge_on_cell_gid ) call ugrid_mesh_data%clear() + call ugrid_2d%file_handler_close() + if (allocated(file_handler)) deallocate( file_handler ) end subroutine test_ugrid_local_mesh_data