diff --git a/applications/io_demo/source/driver/io_benchmark/io_benchmark_setup_mod.f90 b/applications/io_demo/source/driver/io_benchmark/io_benchmark_setup_mod.f90 index b79adb1816..51a5a21b52 100644 --- a/applications/io_demo/source/driver/io_benchmark/io_benchmark_setup_mod.f90 +++ b/applications/io_demo/source/driver/io_benchmark/io_benchmark_setup_mod.f90 @@ -18,7 +18,8 @@ module io_benchmark_setup_mod use fs_continuity_mod, only: Wtheta use function_space_mod, only: function_space_type use function_space_collection_mod, only: function_space_collection - use lfric_xios_file_mod, only: lfric_xios_file_type, OPERATION_TIMESERIES + use lfric_xios_file_mod, only: lfric_xios_file_type, OPERATION_TIMESERIES, & + CONVENTION_UGRID use lfric_xios_read_mod, only: read_field_generic use lfric_xios_write_mod, only: write_field_generic use linked_list_mod, only: linked_list_type @@ -101,7 +102,8 @@ subroutine setup_io_benchmark_files(file_list, modeldb) io_mode=FILE_MODE_WRITE, & operation=OPERATION_TIMESERIES, & freq=diagnostic_frequency, & - fields_in_file=io_benchmark_fields ) ) + fields_in_file=io_benchmark_fields, & + file_convention=CONVENTION_UGRID ) ) nullify(io_benchmark_fields) diff --git a/components/lfric-xios/integration-test/lfric_xios_cyclic_temporal_test.f90 b/components/lfric-xios/integration-test/lfric_xios_cyclic_temporal_test.f90 index f0c719ce44..f125e0f142 100644 --- a/components/lfric-xios/integration-test/lfric_xios_cyclic_temporal_test.f90 +++ b/components/lfric-xios/integration-test/lfric_xios_cyclic_temporal_test.f90 @@ -16,7 +16,8 @@ program lfric_xios_cyclic_temporal_test use lfric_xios_action_mod, only: advance use lfric_xios_context_mod, only: lfric_xios_context_type use lfric_xios_driver_mod, only: lfric_xios_initialise, lfric_xios_finalise - use lfric_xios_file_mod, only: lfric_xios_file_type, OPERATION_TIMESERIES + use lfric_xios_file_mod, only: lfric_xios_file_type, OPERATION_TIMESERIES, & + CONVENTION_UGRID use linked_list_mod, only: linked_list_type use log_mod, only: log_event, log_level_info use test_db_mod, only: test_db_type @@ -53,12 +54,14 @@ program lfric_xios_cyclic_temporal_test operation=OPERATION_TIMESERIES, & freq=file_freq, & cyclic=.true., & + file_convention=CONVENTION_UGRID, & fields_in_file=test_db%temporal_fields ) ) call file_list%insert_item( lfric_xios_file_type( "lfric_xios_cyclic_output", & xios_id="lfric_xios_cyclic_output", & io_mode=FILE_MODE_WRITE, & operation=OPERATION_TIMESERIES, & freq=1, & + file_convention=CONVENTION_UGRID, & fields_in_file=test_db%temporal_fields ) ) call io_context%initialise_xios_context( test_db%comm, & diff --git a/components/lfric-xios/integration-test/lfric_xios_temporal_interp_test.f90 b/components/lfric-xios/integration-test/lfric_xios_temporal_interp_test.f90 index 7e7974d805..4ffa8111b1 100644 --- a/components/lfric-xios/integration-test/lfric_xios_temporal_interp_test.f90 +++ b/components/lfric-xios/integration-test/lfric_xios_temporal_interp_test.f90 @@ -16,7 +16,8 @@ program lfric_xios_temporal_interp_test use lfric_xios_action_mod, only: advance use lfric_xios_context_mod, only: lfric_xios_context_type use lfric_xios_driver_mod, only: lfric_xios_initialise, lfric_xios_finalise - use lfric_xios_file_mod, only: lfric_xios_file_type, OPERATION_TIMESERIES + use lfric_xios_file_mod, only: lfric_xios_file_type, OPERATION_TIMESERIES, & + CONVENTION_UGRID use lfric_xios_constants_mod, only: lx_second use linked_list_mod, only: linked_list_type use log_mod, only: log_event, log_level_info @@ -65,12 +66,14 @@ program lfric_xios_temporal_interp_test freq=file_freq, & cyclic=.true., & update_freq=20*lx_second, & + file_convention=CONVENTION_UGRID, & fields_in_file=test_db%temporal_fields ) ) call file_list%insert_item( lfric_xios_file_type( "lfric_xios_interp_output", & xios_id="lfric_xios_interp_output", & io_mode=FILE_MODE_WRITE, & operation=OPERATION_TIMESERIES, & freq=1, & + file_convention=CONVENTION_UGRID, & fields_in_file=test_db%temporal_fields ) ) call io_context%initialise_xios_context( test_db%comm, & diff --git a/components/lfric-xios/integration-test/lfric_xios_temporal_iodef_test.f90 b/components/lfric-xios/integration-test/lfric_xios_temporal_iodef_test.f90 index 30e0bae455..51295f5b8d 100644 --- a/components/lfric-xios/integration-test/lfric_xios_temporal_iodef_test.f90 +++ b/components/lfric-xios/integration-test/lfric_xios_temporal_iodef_test.f90 @@ -18,7 +18,8 @@ program lfric_xios_temporal_iodef_test use lfric_xios_action_mod, only: advance use lfric_xios_context_mod, only: lfric_xios_context_type use lfric_xios_driver_mod, only: lfric_xios_initialise, lfric_xios_finalise - use lfric_xios_file_mod, only: lfric_xios_file_type, OPERATION_TIMESERIES + use lfric_xios_file_mod, only: lfric_xios_file_type, OPERATION_TIMESERIES, & + CONVENTION_UGRID use linked_list_mod, only: linked_list_type use log_mod, only: log_event, log_level_info use test_db_mod, only: test_db_type @@ -47,12 +48,14 @@ program lfric_xios_temporal_iodef_test xios_id="lfric_xios_temporal_input", & io_mode=FILE_MODE_READ, & operation=OPERATION_TIMESERIES, & + file_convention=CONVENTION_UGRID, & fields_in_file=test_db%temporal_fields ) ) call file_list%insert_item( lfric_xios_file_type( "lfric_xios_temporal_output", & xios_id="lfric_xios_temporal_output", & io_mode=FILE_MODE_WRITE, & operation=OPERATION_TIMESERIES, & freq=1, & + file_convention=CONVENTION_UGRID, & fields_in_file=test_db%temporal_fields ) ) call io_context%initialise_xios_context( test_db%comm, & diff --git a/components/lfric-xios/integration-test/lfric_xios_temporal_test.f90 b/components/lfric-xios/integration-test/lfric_xios_temporal_test.f90 index 70575b5fd5..484c8d6f4f 100644 --- a/components/lfric-xios/integration-test/lfric_xios_temporal_test.f90 +++ b/components/lfric-xios/integration-test/lfric_xios_temporal_test.f90 @@ -18,7 +18,8 @@ program lfric_xios_temporal_test use lfric_xios_action_mod, only: advance use lfric_xios_context_mod, only: lfric_xios_context_type use lfric_xios_driver_mod, only: lfric_xios_initialise, lfric_xios_finalise - use lfric_xios_file_mod, only: lfric_xios_file_type, OPERATION_TIMESERIES + use lfric_xios_file_mod, only: lfric_xios_file_type, OPERATION_TIMESERIES, & + CONVENTION_UGRID use linked_list_mod, only: linked_list_type use log_mod, only: log_event, log_level_info use test_db_mod, only: test_db_type @@ -51,12 +52,14 @@ program lfric_xios_temporal_test io_mode=FILE_MODE_READ, & operation=OPERATION_TIMESERIES, & freq=file_freq, & + file_convention=CONVENTION_UGRID, & fields_in_file=test_db%temporal_fields ) ) call file_list%insert_item( lfric_xios_file_type( "lfric_xios_temporal_output", & xios_id="lfric_xios_temporal_output", & io_mode=FILE_MODE_WRITE, & operation=OPERATION_TIMESERIES, & freq=1, & + file_convention=CONVENTION_UGRID, & fields_in_file=test_db%temporal_fields ) ) call io_context%initialise_xios_context( test_db%comm, & diff --git a/components/lfric-xios/source/lfric_xios_field_mod.f90 b/components/lfric-xios/source/lfric_xios_field_mod.f90 index 03653966aa..cd5557c08f 100644 --- a/components/lfric-xios/source/lfric_xios_field_mod.f90 +++ b/components/lfric-xios/source/lfric_xios_field_mod.f90 @@ -116,18 +116,21 @@ end function lfric_xios_field_constructor !> Registers a representation of the model field with the associated XIOS field !> group -subroutine register(self) +subroutine register(self, ugrid) implicit none class(lfric_xios_field_type), intent(inout) :: self + logical, optional, intent(in) :: ugrid type(xios_fieldgroup) :: fieldgroup_hdl type(xios_domain) :: domain type(xios_axis) :: vert_axis, ndata_axis type(xios_gridgroup) :: grid_definition type(xios_grid) :: new_grid - character(str_def) :: domain_id, axis_id, grid_id + character(str_def) :: domain_id, axis_id, grid_id, grid_tag + + logical :: ugrid_format type(mesh_type), pointer :: mesh => null() type(function_space_type), pointer :: vspace => null() @@ -136,6 +139,11 @@ subroutine register(self) "] with field group ["//trim(self%fieldgroup_id)//"]", & log_level_trace ) + ugrid_format = .true. + if (present(ugrid)) then + ugrid_format = ugrid + end if + ! If this field is already registered with XIOS, get the existing handle, ! otherwise a new one will be created below as part of `xios_add_child`. if (xios_is_valid_field(self%xios_id)) then @@ -168,6 +176,13 @@ subroutine register(self) axis_id ="vert_axis_half_levels" end select + ! Use CF domains if not UGRID + grid_tag = "_grid" + if (.not. ugrid_format) then + domain_id = trim(domain_id)//"_cf" + grid_tag = "_cf_grid" + end if + mesh => self%model_field%get_mesh() ! If field had only a single layer of DoFs then define this using a domain, ! otherwise use a grid. @@ -179,12 +194,12 @@ subroutine register(self) ! Create grid ID using function space information. if (vspace%get_ndata() == 1) then - grid_id = trim(name_from_functionspace(self%model_field%which_function_space()))//"_grid" + grid_id = trim(name_from_functionspace(self%model_field%which_function_space()))//trim(grid_tag) else if (mesh%get_nlayers() == 1) then - grid_id = trim(domain_id)//"_"//char(vspace%get_ndata())//"_grid" + grid_id = trim(domain_id)//"_"//char(vspace%get_ndata())//trim(grid_tag) else grid_id = trim(name_from_functionspace(self%model_field%which_function_space()))// & - "_ndata_"//char(vspace%get_ndata())//"_grid" + "_ndata_"//char(vspace%get_ndata())//trim(grid_tag) end if ! If this grid does not already exist, create it. diff --git a/components/lfric-xios/source/lfric_xios_file_mod.f90 b/components/lfric-xios/source/lfric_xios_file_mod.f90 index 651b36fa0e..b523f2bf97 100644 --- a/components/lfric-xios/source/lfric_xios_file_mod.f90 +++ b/components/lfric-xios/source/lfric_xios_file_mod.f90 @@ -338,8 +338,9 @@ subroutine register_with_context(self) type(xios_duration) :: timestep_duration type(xios_date) :: start_date - integer(i_def) :: i, record_offset - logical :: output_freq_defined + integer(i_def) :: i, record_offset, convention_def_enum + logical :: convention_defined_xml, output_freq_defined + character(str_def) :: iodef_file_convention call log_event( "Registering XIOS file ["//trim(self%xios_id)//"]", & log_level_trace ) @@ -366,20 +367,39 @@ subroutine register_with_context(self) ! Set I/O mode (no need for case defalt as we will fall back to XIOS's ! default behaviour) - call xios_set_attr( self%handle, type="one_file" ) + call xios_set_attr(self%handle, type="one_file") select case(self%io_mode) case (FILE_MODE_READ) - call xios_set_attr( self%handle, mode="read" ) + call xios_set_attr(self%handle, mode="read") case (FILE_MODE_WRITE) - call xios_set_attr( self%handle, mode="write" ) + call xios_set_attr(self%handle, mode="write") end select - ! Set XIOS file convention - select case(self%file_convention) + ! Set XIOS file convention definition + + ! Check if file convention has been defined in iodef.xml config + call xios_is_defined_file_attr(self%xios_id, convention=convention_defined_xml) + + if (convention_defined_xml) then + call xios_get_file_attr(self%xios_id, convention=iodef_file_convention) + if (trim(iodef_file_convention) == "CF") then + convention_def_enum = CONVENTION_CF + else if (trim(iodef_file_convention) == "UGRID") then + convention_def_enum = CONVENTION_UGRID + end if + else if (self%file_convention /= undef_file_convention) then + convention_def_enum = self%file_convention + else ! Default to UGRID if no convention provided + convention_def_enum = CONVENTION_UGRID + end if + + select case(convention_def_enum) case (CONVENTION_CF) - call xios_set_attr( self%handle, convention="CF" ) + call xios_set_attr(self%handle, convention="CF") + call xios_set_attr(self%handle, convention_str="CF-1.12") case (CONVENTION_UGRID) - call xios_set_attr( self%handle, convention="UGRID" ) + call xios_set_attr(self%handle, convention="UGRID") + call xios_set_attr(self%handle, convention_str="CF-1.12 UGRID-1.0") end select ! Create CF-compliant time description @@ -431,7 +451,7 @@ subroutine register_with_context(self) if (self%mode_is_read()) then call xios_set_attr(self%handle, read_metadata_par=.true.) call xios_set_attr(file_fields, read_access=.true.) - end if + end if ! Set up fields in file if (allocated(self%fields)) then @@ -446,7 +466,7 @@ subroutine register_with_context(self) ! Iterate over field collection and register fields do i = 1, size(self%fields) - call self%fields(i)%register() + call self%fields(i)%register(ugrid=(self%file_convention == CONVENTION_UGRID)) end do ! Set up time axis if needed diff --git a/components/lfric-xios/source/lfric_xios_format_mod.f90 b/components/lfric-xios/source/lfric_xios_format_mod.f90 index fa3b6ef59f..5c019d1b1a 100644 --- a/components/lfric-xios/source/lfric_xios_format_mod.f90 +++ b/components/lfric-xios/source/lfric_xios_format_mod.f90 @@ -48,7 +48,7 @@ module lfric_xios_format_mod !> @param[in] fpxy Field proxy of LFRic field to be formatted !> @param[in] m Number of rows in input matrix !> @param[in] n Number of columns in input matrix -!> @param[in] legacy Use legacy checkpoint domains? +!> @param[in] legacy Use legacy domains? !> subroutine format_field(xios_data, field_name, fpxy, m, n, legacy) implicit none @@ -119,7 +119,7 @@ end subroutine format_field !> @param[in] fpxy Field proxy of LFRic field to be read !> @param[in] m Number of rows in field data matrix !> @param[in] n Number of columns in field data matrix -!> @param[in] legacy Use legacy checkpoint domains? +!> @param[in] legacy Use legacy domains? !> subroutine inverse_format_field(xios_data, field_name, fpxy, m, n, legacy) implicit none diff --git a/components/lfric-xios/source/lfric_xios_metafile_mod.F90 b/components/lfric-xios/source/lfric_xios_metafile_mod.F90 index dfd4d0da60..2bb12a8121 100644 --- a/components/lfric-xios/source/lfric_xios_metafile_mod.F90 +++ b/components/lfric-xios/source/lfric_xios_metafile_mod.F90 @@ -53,9 +53,9 @@ module lfric_xios_metafile_mod contains - !> @brief Support for legacy checkpoints + !> @brief Support for legacy I/O !> @details This affects lbc and gungho prognostics, which have traditionally been - !> using the legacy checkpoint domains checkpoint_W3, checkpoint_W2 etc. + !> using the legacy domains legacy_W3, legacy_W2 etc. !> @param[in] field XIOS field object !> @param[in] field_id XIOS fielld id subroutine handle_legacy_fields(field, field_id) @@ -64,9 +64,9 @@ subroutine handle_legacy_fields(field, field_id) type(xios_field), intent(in) :: field character(*), intent(in) :: field_id - character(20), parameter :: Wtheta = 'checkpoint_Wtheta' - character(20), parameter :: W3 = 'checkpoint_W3' - character(20), parameter :: W2 = 'checkpoint_W2' + character(20), parameter :: Wtheta = 'legacy_Wtheta' + character(20), parameter :: W3 = 'legacy_W3' + character(20), parameter :: W2 = 'legacy_W2' character(20), parameter :: wtheta_fields(7) = [character(20) :: & 'theta', 'm_v', 'm_cl', 'm_r', 'm_ci', 'm_s', 'm_g'] @@ -187,8 +187,8 @@ end function get_field_precision !> @param[in] mode ID prefix to be used, .e.g, "checkpoint_" !> @param[in] operation XIOS field operation, e.g., "once" !> @param[in] id_as_name Use dictionary field ID as field name? - !> @param[in] legacy Use legacy checkpointing domain? - subroutine add_field(metafile, dict_field_id, mode, operation, id_as_name, legacy) + !> @param[in] legacy Use legacy domains for checkpointing + subroutine add_field( metafile, dict_field_id, mode, operation, id_as_name, legacy ) implicit none type(metafile_type), intent(in) :: metafile(:) character(*), intent(in) :: dict_field_id @@ -214,7 +214,7 @@ subroutine add_field(metafile, dict_field_id, mode, operation, id_as_name, legac character(str_def) :: axis_ref integer(i_def) :: prec logical(l_def) :: use_id_as_name - logical(l_def) :: use_legacy + logical(l_def) :: use_ugrid_ckp, use_legacy integer(i_def) :: i use_id_as_name = .false. @@ -223,6 +223,10 @@ subroutine add_field(metafile, dict_field_id, mode, operation, id_as_name, legac use_legacy = .false. if (present(legacy)) use_legacy = legacy + ! Flag to use UGRID for checkpointing, disabled until XIOS supports UGRID + ! for full set of checkpoint fields + use_ugrid_ckp = .false. + do i = 1, size(metafile) file_id = metafile(i)%get_id() if (mode == CHECKPOINTING ) then @@ -262,14 +266,23 @@ subroutine add_field(metafile, dict_field_id, mode, operation, id_as_name, legac if (use_legacy) then call handle_legacy_fields(field, dict_field_id) else + ! Set correct domain/grid IDs for fields grid_ref = get_field_grid_ref(dict_field_id) if (grid_ref /= '') then - call xios_set_attr(field, grid_ref=grid_ref) + if (use_ugrid_ckp) then + call xios_set_attr(field, grid_ref=trim(grid_ref)) + else + call xios_set_attr(field, grid_ref=trim(grid_ref)//"_cf") + end if else domain_ref = get_field_domain_ref(dict_field_id) axis_ref = get_field_axis_ref(dict_field_id) - if (domain_ref /= '') call xios_set_attr(field, domain_ref=domain_ref) - if (axis_ref /= '') call xios_set_attr(field, axis_ref=axis_ref) + if (use_ugrid_ckp) then + if (domain_ref /= '') call xios_set_attr(field, domain_ref=trim(domain_ref)) + else + if (domain_ref /= '') call xios_set_attr(field, domain_ref=trim(domain_ref)//"_cf") + end if + if (axis_ref /= '') call xios_set_attr(field, axis_ref=trim(axis_ref)) end if end if end if diff --git a/components/lfric-xios/source/lfric_xios_read_mod.F90 b/components/lfric-xios/source/lfric_xios_read_mod.F90 index 80fd905f86..25b492e490 100644 --- a/components/lfric-xios/source/lfric_xios_read_mod.F90 +++ b/components/lfric-xios/source/lfric_xios_read_mod.F90 @@ -243,8 +243,8 @@ subroutine read_field_generic(xios_field_name, field_proxy) call log_event( "Reading from XIOS field [" // trim(xios_field_name // "]"), & LOG_LEVEL_TRACE ) - ! detect field with legacy checkpointing domain - legacy = (index(get_field_domain_ref(xios_field_name), 'checkpoint_') == 1) + ! detect field with legacy domain + legacy = (index(get_field_domain_ref(xios_field_name), 'legacy_') == 1) ! sanity check if (.not. legacy .and. .not. (hdim*vdim == undf)) then diff --git a/components/lfric-xios/source/lfric_xios_setup_mod.x90 b/components/lfric-xios/source/lfric_xios_setup_mod.x90 index 8f95b4a873..d88ff5b16a 100644 --- a/components/lfric-xios/source/lfric_xios_setup_mod.x90 +++ b/components/lfric-xios/source/lfric_xios_setup_mod.x90 @@ -23,9 +23,6 @@ module lfric_xios_setup_mod use function_space_collection_mod, only: function_space_collection use fs_continuity_mod, only: W0, W1, W2, W3, Wtheta, W2H, W2V, & name_from_functionspace - use io_config_mod, only: file_convention, & - file_convention_ugrid, & - file_convention_cf use lfric_mpi_mod, only: global_mpi use lfric_xios_file_mod, only: lfric_xios_file_type use lfric_xios_process_output_mod, only: xyz_scaling_factor @@ -33,7 +30,8 @@ module lfric_xios_setup_mod use lfric_core_version_mod, only: lfric_core_version_char use linked_list_mod, only: linked_list_type, linked_list_item_type use log_mod, only: log_event, log_level_error, & - log_level_warning, log_level_info + log_level_warning, log_level_info, & + log_level_trace use mesh_mod, only: mesh_type use mesh_collection_mod, only: mesh_collection use model_clock_mod, only: model_clock_type @@ -264,10 +262,10 @@ contains ! Levels variables integer(kind=i_def) :: nfull_levels - ! Checkpoint domain parameters + ! Legacy domain parameters character(len=str_def) :: domain_name, domain_fs_name - integer(kind=i_def), parameter :: domain_function_spaces(5) & - = (/W0, W1, W2, W3, Wtheta/) + integer(kind=i_def), parameter :: domain_function_spaces(7) & + = (/W0, W1, W2, W3, Wtheta, W2H, W2V/) integer(kind=i_def) :: fs_index ! Variables needed to compute output domain coordinates in lat-long @@ -288,8 +286,8 @@ contains type(function_space_type), pointer :: output_field_fs type(function_space_type), pointer :: w2h_fs - ! Identify discontinuous spaces - integer(kind=i_def) :: use_i_index(2) = (/ W3, Wtheta /) + ! Function spaces that can be written as layers of data + integer(kind=i_def) :: use_i_index(4) = (/ W3, Wtheta, W2H, W2V /) ! Factor to convert coords from radians to degrees if needed ! set as 1.0 for planar mesh @@ -394,47 +392,73 @@ contains bnd_nodes_lon=(reshape(nodes_lon_local(1:coord_dim_owned), (/1, coord_dim_owned/) ) ) bnd_nodes_lat=(reshape(nodes_lat_local(1:coord_dim_owned), (/1, coord_dim_owned/) ) ) - ! Initialise XIOS UGRID domains + ! Initialise XIOS domains if (mesh_is_prime_mesh) then call set_prime_io_mesh(mesh) call set_prime_io_mesh(twod_mesh) - call init_xios_ugrid_domain( "node", mesh, W0, sample_chi, & + ! UGRID domains + call init_xios_domain( "node", mesh, W0, sample_chi, & bnd_nodes_lon, bnd_nodes_lat, & "Mesh2d", nverts=1 ) - call init_xios_ugrid_domain( "edge", mesh, W2H, sample_chi, & + call init_xios_domain( "edge", mesh, W2H, sample_chi, & bnd_edges_lon, bnd_edges_lat, & "Mesh2d", nverts=2 ) - call init_xios_ugrid_domain( "face", mesh, W3, sample_chi, & + call init_xios_domain( "face", mesh, W3, sample_chi, & bnd_faces_lon, bnd_faces_lat, & "Mesh2d", nverts=4 ) + + ! CF domains (different domain names for each mesh entity) - these may not needed, + ! so future effort could be made to make this optional + call init_xios_domain( "node_cf", mesh, W0, sample_chi, & + bnd_nodes_lon, bnd_nodes_lat, & + "node_cf", nverts=1 ) + call init_xios_domain( "edge_cf", mesh, W2H, sample_chi, & + bnd_edges_lon, bnd_edges_lat, & + "edge_cf", nverts=2 ) + call init_xios_domain( "face_cf", mesh, W3, sample_chi, & + bnd_faces_lon, bnd_faces_lat, & + "face_cf", nverts=4 ) else - call init_xios_ugrid_domain( trim(adjustl(mesh%get_mesh_name()))//"_node", mesh, W0, & - sample_chi, bnd_nodes_lon, bnd_nodes_lat, & - trim(adjustl(mesh%get_mesh_name())), nverts=1 ) - call init_xios_ugrid_domain( trim(adjustl(mesh%get_mesh_name()))//"_edge", mesh, W2H, & - sample_chi, bnd_edges_lon, bnd_edges_lat, & - trim(adjustl(mesh%get_mesh_name())), nverts=2 ) - call init_xios_ugrid_domain( trim(adjustl(mesh%get_mesh_name()))//"_face", mesh, W3, & - sample_chi, bnd_faces_lon, bnd_faces_lat, & - trim(adjustl(mesh%get_mesh_name())), nverts=4 ) + ! UGRID domains + call init_xios_domain( trim(adjustl(mesh%get_mesh_name()))//"_node", mesh, W0, & + sample_chi, bnd_nodes_lon, bnd_nodes_lat, & + trim(adjustl(mesh%get_mesh_name())), nverts=1 ) + call init_xios_domain( trim(adjustl(mesh%get_mesh_name()))//"_edge", mesh, W2H, & + sample_chi, bnd_edges_lon, bnd_edges_lat, & + trim(adjustl(mesh%get_mesh_name())), nverts=2 ) + call init_xios_domain( trim(adjustl(mesh%get_mesh_name()))//"_face", mesh, W3, & + sample_chi, bnd_faces_lon, bnd_faces_lat, & + trim(adjustl(mesh%get_mesh_name())), nverts=4 ) + + ! CF domains (different domain names for each mesh entity) - these may not needed, + ! so future effort could be made to make this optional + call init_xios_domain( trim(adjustl(mesh%get_mesh_name()))//"_node_cf", mesh, W0, & + sample_chi, bnd_nodes_lon, bnd_nodes_lat, & + trim(adjustl(mesh%get_mesh_name()))//"_node_cf", nverts=1 ) + call init_xios_domain( trim(adjustl(mesh%get_mesh_name()))//"_edge_cf", mesh, W2H, & + sample_chi, bnd_edges_lon, bnd_edges_lat, & + trim(adjustl(mesh%get_mesh_name()))//"_edge_cf", nverts=2 ) + call init_xios_domain( trim(adjustl(mesh%get_mesh_name()))//"_face_cf", mesh, W3, & + sample_chi, bnd_faces_lon, bnd_faces_lat, & + trim(adjustl(mesh%get_mesh_name()))//"_face_cf", nverts=4 ) end if - ! Create all the regular checkpoint domains based on current function spaces + ! Create all the regular legacy domains based on current function spaces ! Loop over function spaces we need to create domains for (just for the prime mesh): if (mesh_is_prime_mesh) then do fs_index = lbound(domain_function_spaces, 1), & ubound(domain_function_spaces, 1) domain_fs_name = name_from_functionspace(domain_function_spaces(fs_index)) - domain_name = "checkpoint_" // trim(domain_fs_name) + domain_name = "legacy_" // trim(domain_fs_name) ! Enable use of the XIOS i_index for relevant function spaces if (any( use_i_index == domain_function_spaces(fs_index) )) then - call checkpoint_domain_init( domain_function_spaces(fs_index), & + call legacy_domain_init( domain_function_spaces(fs_index), & trim(domain_name), mesh, & sample_chi, .true. ) else - call checkpoint_domain_init( domain_function_spaces(fs_index), & + call legacy_domain_init( domain_function_spaces(fs_index), & trim(domain_name), mesh, & sample_chi, .false. ) end if @@ -482,20 +506,6 @@ contains ! Configure global file definition call xios_get_handle("file_definition", file_definition) - select case(file_convention) - case (file_convention_ugrid) - call xios_set_attr( file_definition, convention="UGRID" ) - call xios_set_attr(file_definition, convention_str="CF-1.12 UGRID-1.0") - - case (file_convention_cf) - call xios_set_attr( file_definition, convention="CF" ) - call xios_set_attr(file_definition, convention_str="CF-1.12") - - case default - call log_event("Invalid choice for file convention", log_level_error) - - end select - core_version_char = lfric_core_version_char() call xios_set_attr(file_definition, description="LFRic file format " // & core_version_char) @@ -704,7 +714,7 @@ contains end subroutine calc_xios_domain_coords - !> @brief Performs XIOS checkpoint domain initialisation + !> @brief Performs XIOS legacy domain initialisation !> !> @param[in] fs_id Function space id !> @param[in] domain_name XIOS domain name @@ -717,8 +727,8 @@ contains !> @param[in] k_order_v Function space order vertical (optional, !! default = 0) !> - subroutine checkpoint_domain_init(fs_id, domain_name, mesh, & - chi, use_index, k_order_h, k_order_v) + subroutine legacy_domain_init(fs_id, domain_name, mesh, & + chi, use_index, k_order_h, k_order_v) implicit none @@ -735,13 +745,13 @@ contains integer(kind=i_def) :: i integer(kind=i_def) :: k_ord_h, k_ord_v, ord_idx - ! Checkpoint domain - integer(kind=i_def) :: ibegin_checkpoint - real(dp_xios), allocatable :: checkpoint_lon(:) - real(dp_xios), allocatable :: checkpoint_lat(:) - real(dp_xios), allocatable :: bnd_checkpoint_lon(:,:) - real(dp_xios), allocatable :: bnd_checkpoint_lat(:,:) - integer(kind=i_halo_index), allocatable :: cp_domain_index(:) + ! legacy domain + integer(kind=i_def) :: ibegin + real(dp_xios), allocatable :: lon(:) + real(dp_xios), allocatable :: lat(:) + real(dp_xios), allocatable :: bnd_lon(:,:) + real(dp_xios), allocatable :: bnd_lat(:,:) + integer(kind=i_halo_index), allocatable :: legacy_domain_index(:) ! Variables needed to compute output domain coordinates in lat-long @@ -754,9 +764,9 @@ contains ! Variables for the gather to determine global domain sizes ! from the local partitioned ones - integer(kind=i_def) :: global_undf_checkpoint + integer(kind=i_def) :: global_undf integer(kind=i_def), allocatable :: local_undf(:) - integer(kind=i_def), allocatable :: all_undfs_checkpoint_domain(:) + integer(kind=i_def), allocatable :: all_undfs_domain(:) ! Factor to convert coords from radians to degrees if needed ! set as 1.0 for planar mesh @@ -782,9 +792,9 @@ contains ! Set up arrays to hold number of dofs for local and global domains allocate(local_undf(1)) - allocate(all_undfs_checkpoint_domain(global_mpi%get_comm_size())) + allocate(all_undfs_domain(global_mpi%get_comm_size())) - all_undfs_checkpoint_domain = 0 + all_undfs_domain = 0 ! Create appropriate function space in order to be able to get the ! physical coordinates @@ -817,54 +827,54 @@ contains !!!!!!!!!!!! Global domain calculation !!!!!!!!!!!!!!!!!!!!!!!!!! - call global_mpi%all_gather ( local_undf, all_undfs_checkpoint_domain, 1 ) + call global_mpi%all_gather ( local_undf, all_undfs_domain, 1 ) ! Now get the global sum of undf across all ranks to set the global domain sizes - ! for checkpoint domain - global_undf_checkpoint = sum(all_undfs_checkpoint_domain) + ! for legacy domain + global_undf = sum(all_undfs_domain) ! Calculate ibegin for each rank as we have the array of undfs in order ! we can just sum to get it. if (global_mpi%get_comm_rank() == 0) then - ibegin_checkpoint = 0 + ibegin = 0 else - ibegin_checkpoint = sum(all_undfs_checkpoint_domain(1:global_mpi%get_comm_rank())) + ibegin = sum(all_undfs_domain(1:global_mpi%get_comm_rank())) end if - ! Allocate coordinate arrays to be the size required for checkpoint domain. + ! Allocate coordinate arrays to be the size required for legacy domain. ! Essentially up to last owned dof of the current partition. - allocate( checkpoint_lon( size( proxy_coord_output(1)%data(1: local_undf(1)))) ) - allocate( checkpoint_lat( size( proxy_coord_output(2)%data(1: local_undf(1)))) ) + allocate( lon( size( proxy_coord_output(1)%data(1: local_undf(1)))) ) + allocate( lat( size( proxy_coord_output(2)%data(1: local_undf(1)))) ) ! Populate the arrays with data - checkpoint_lon = proxy_coord_output(1)%data(1: local_undf(1)) * r2d - checkpoint_lat = proxy_coord_output(2)%data(1: local_undf(1)) * r2d + lon = proxy_coord_output(1)%data(1: local_undf(1)) * r2d + lat = proxy_coord_output(2)%data(1: local_undf(1)) * r2d - allocate(bnd_checkpoint_lon(1,size(checkpoint_lon))) - allocate(bnd_checkpoint_lat(1,size(checkpoint_lat))) + allocate(bnd_lon(1,size(lon))) + allocate(bnd_lat(1,size(lat))) ! Construct bounds arrays - bnd_checkpoint_lon=(reshape(checkpoint_lon, (/1, size(checkpoint_lon)/) ) ) - bnd_checkpoint_lat=(reshape(checkpoint_lat, (/1, size(checkpoint_lat)/) ) ) + bnd_lon=(reshape(lon, (/1, size(lon)/) ) ) + bnd_lat=(reshape(lat, (/1, size(lat)/) ) ) ! Create the XIOS domain call xios_get_handle("domain_definition", domain_definition) call xios_add_child(domain_definition, new_domain, trim(domain_name)) ! Give coordinate information to the XIOS domain - call xios_set_domain_attr(trim(domain_name), ni_glo=global_undf_checkpoint, & - ibegin=ibegin_checkpoint, ni=local_undf(1), & + call xios_set_domain_attr(trim(domain_name), ni_glo=global_undf, & + ibegin=ibegin, ni=local_undf(1), & type='unstructured', nvertex=1) - call xios_set_domain_attr(trim(domain_name), lonvalue_1d=checkpoint_lon, & - latvalue_1d=checkpoint_lat) - call xios_set_domain_attr(trim(domain_name), bounds_lon_1d=bnd_checkpoint_lon, & - bounds_lat_1d=bnd_checkpoint_lat) + call xios_set_domain_attr(trim(domain_name), lonvalue_1d=lon, & + latvalue_1d=lat) + call xios_set_domain_attr(trim(domain_name), bounds_lon_1d=bnd_lon, & + bounds_lat_1d=bnd_lat) ! If we have requested to use domain index then get it and use it if (use_index) then ! Populate domain_index for this rank - call output_field_fs%get_global_dof_id(cp_domain_index) + call output_field_fs%get_global_dof_id(legacy_domain_index) ! temporary fix for higher-order domain decomposition if (k_ord_h > 0 .or. k_ord_v > 0) then @@ -873,42 +883,42 @@ contains ord_idx = 1 end if - ! Pass local portion of domain_index (up to undf) - call xios_set_domain_attr(domain_name, i_index=int(cp_domain_index(1:local_undf(1))/ord_idx)) + ! Pass local portion of legacy_domain_index (up to undf) + call xios_set_domain_attr(domain_name, i_index=int(legacy_domain_index(1:local_undf(1))/ord_idx)) end if - if ( allocated(cp_domain_index) ) deallocate(cp_domain_index) - if ( allocated(checkpoint_lon) ) deallocate(checkpoint_lon) - if ( allocated(checkpoint_lat) ) deallocate(checkpoint_lat) - if ( allocated(bnd_checkpoint_lon) ) deallocate(bnd_checkpoint_lon) - if ( allocated(bnd_checkpoint_lat) ) deallocate(bnd_checkpoint_lat) - if ( allocated(local_undf) ) deallocate(local_undf) - if ( allocated(all_undfs_checkpoint_domain) ) deallocate(all_undfs_checkpoint_domain) + if ( allocated(legacy_domain_index) ) deallocate(legacy_domain_index) + if ( allocated(lon) ) deallocate(lon) + if ( allocated(lat) ) deallocate(lat) + if ( allocated(bnd_lon) ) deallocate(bnd_lon) + if ( allocated(bnd_lat) ) deallocate(bnd_lat) + if ( allocated(local_undf) ) deallocate(local_undf) + if ( allocated(all_undfs_domain) ) deallocate(all_undfs_domain) nullify( output_field_fs ) return - end subroutine checkpoint_domain_init + end subroutine legacy_domain_init !> @brief Initialises unstructured XIOS domain from function space !> @details Calculates coordinates from function space and local mesh, obtains !> local portion of the domain index and passes information to XIOS !> domain object !> - !> @param[in] domain_id The name of the XIOS domain - !> @param[in] mesh The partitioned mesh - !> @param[in] fs_id The id of the function space corresponding - !! to the domain - !> @param[in] chi Input coordinate field - !> @param[in] lon_bounds Longitude coords of the domain bounds - !> @param[in] lat_bounds Latitude coords of the domain bounds - !> @param[in] mesh_name Name of the consolidated mesh - !> @param[in] nverts Number of vertices bounding each domain - !! element + !> @param[in] domain_id_ The name of the XIOS domain + !> @param[in] mesh The partitioned mesh + !> @param[in] fs_id The id of the function space corresponding + !! to the domain + !> @param[in] chi Input coordinate field + !> @param[in] lon_bounds Longitude coords of the domain bounds + !> @param[in] lat_bounds Latitude coords of the domain bounds + !> @param[in] mesh_name Name of the consolidated mesh + !> @param[in] nverts Number of vertices bounding each domain + !! element !> - subroutine init_xios_ugrid_domain( domain_id, mesh, fs_id, chi, & - lon_bounds, lat_bounds, mesh_name, & - nverts ) + subroutine init_xios_domain( domain_id, mesh, fs_id, chi, & + lon_bounds, lat_bounds, domain_name, & + nverts ) implicit none @@ -918,7 +928,7 @@ contains type(field_type), intent(in) :: chi(:) real(dp_xios), allocatable, intent(inout) :: lat_bounds(:,:) real(dp_xios), allocatable, intent(inout) :: lon_bounds(:,:) - character(len=*), intent(in) :: mesh_name + character(len=*), intent(in) :: domain_name integer(kind=i_def), intent(in) :: nverts type(function_space_type), pointer :: domain_fs @@ -946,6 +956,8 @@ contains ! set as 1.0 for planar mesh real(kind=r_def) :: r2d + call log_event("Creating XIOS domain ["//trim(domain_id)//"].", log_level_trace) + if ( mesh%is_geometry_spherical() ) then r2d = radians_to_degrees else @@ -1055,8 +1067,7 @@ contains ! UGRID and planar (projected coordinates). ! Post processing will be applied to these files to work around ! XIOS limitations, pending feature development in XIOS. - if ( mesh%is_geometry_planar() .and. & - file_convention == file_convention_ugrid ) then + if ( mesh%is_geometry_planar() ) then lat_data = lat_data * xyz_scaling_factor lon_data = lon_data * xyz_scaling_factor lat_bounds = lat_bounds * xyz_scaling_factor @@ -1080,10 +1091,7 @@ contains call xios_set_domain_attr( trim(domain_id), bounds_lon_1d=lon_bounds, & bounds_lat_1d=lat_bounds ) - ! Consolidate the domains into a single 2D UGRID mesh - if (file_convention == file_convention_ugrid) then - call xios_set_domain_attr( trim(domain_id), name=trim(mesh_name) ) - end if + call xios_set_domain_attr( trim(domain_id), name=trim(domain_name), dim_i_name=trim(domain_name) ) ! Pass local portion of domain_index to XIOS call xios_set_domain_attr( domain_id, i_index=int( domain_index( 1 : local_domain_size ) ) ) @@ -1096,7 +1104,7 @@ contains deallocate(domain_index) nullify(domain_fs) - end subroutine init_xios_ugrid_domain + end subroutine init_xios_domain !> @brief Initialises XIOS axis from function space and mesh !> @details Calculates vertical levels and coordinates from function space diff --git a/components/lfric-xios/source/lfric_xios_temporal_mod.x90 b/components/lfric-xios/source/lfric_xios_temporal_mod.x90 index cb6d7a96d2..9422f7fa3f 100644 --- a/components/lfric-xios/source/lfric_xios_temporal_mod.x90 +++ b/components/lfric-xios/source/lfric_xios_temporal_mod.x90 @@ -290,6 +290,7 @@ contains mode="read", & type="one_file", & record_offset=record_offset, & + convention="UGRID", & time_counter_name="time", & enabled=.true. ) diff --git a/components/lfric-xios/source/lfric_xios_write_mod.F90 b/components/lfric-xios/source/lfric_xios_write_mod.F90 index 31515adb64..93e5bafac3 100644 --- a/components/lfric-xios/source/lfric_xios_write_mod.F90 +++ b/components/lfric-xios/source/lfric_xios_write_mod.F90 @@ -171,8 +171,8 @@ subroutine write_field_generic(field_name, field_proxy) hdim = undf/vdim - ! detect field with legacy checkpointing domain - legacy = (index(get_field_domain_ref(field_name), 'checkpoint_') == 1) + ! detect field with legacy domain + legacy = (index(get_field_domain_ref(field_name), 'legacy_') == 1) ! sanity check if (.not. legacy .and. .not. (hdim*vdim == undf)) then diff --git a/rose-stem/app/io_demo/file/iodef.xml b/rose-stem/app/io_demo/file/iodef.xml index 0f3626f954..1aa3ce111c 100644 --- a/rose-stem/app/io_demo/file/iodef.xml +++ b/rose-stem/app/io_demo/file/iodef.xml @@ -13,7 +13,7 @@ type="one_file" time_counter="none"> - + diff --git a/rose-stem/app/io_demo/file/iodef_temporal.xml b/rose-stem/app/io_demo/file/iodef_temporal.xml index 16dd8919ec..318652f629 100644 --- a/rose-stem/app/io_demo/file/iodef_temporal.xml +++ b/rose-stem/app/io_demo/file/iodef_temporal.xml @@ -11,7 +11,7 @@ type="one_file" time_counter="none"> - +