diff --git a/.github/workflows/actions.yml b/.github/workflows/actions.yml index 71de7a1..50b13d3 100644 --- a/.github/workflows/actions.yml +++ b/.github/workflows/actions.yml @@ -25,8 +25,8 @@ jobs: -DTrilinos_ENABLE_ALL_PACKAGES:BOOL=OFF \ -DTrilinos_ENABLE_Zoltan:BOOL=ON \ -DTrilinos_ENABLE_Fortran:BOOL=OFF \ - -DZoltan_ENABLE_EXAMPLES:BOOL=ON \ - -DZoltan_ENABLE_TESTS:BOOL=ON \ + -DZoltan_ENABLE_EXAMPLES:BOOL=OFF \ + -DZoltan_ENABLE_TESTS:BOOL=OFF \ -DBUILD_SHARED_LIBS=ON \ -Bbuild -S. sudo cmake --build build --config Release --target install @@ -35,7 +35,7 @@ jobs: cd PnetCDF autoreconf -i CXX=mpicxx CC=mpicc ./configure --disable-fortran --enable-shared - make -j2 + make sudo make install cd .. git clone -b v4.8.1 https://github.com/Unidata/netcdf-c.git @@ -45,6 +45,8 @@ jobs: -DCMAKE_C_COMPILER=mpicc \ -DCMAKE_CXX_COMPILER=mpicxx \ -DCMAKE_BUILD_TYPE=Release \ + -DENABLE_TESTS=OFF \ + -DENABLE_PARALLEL_TESTS=OFF \ -Bbuild -S. sudo cmake --build build --config Release --target install cd .. @@ -69,7 +71,7 @@ jobs: - name: Install dependencies run: | brew install cmake - brew extract --version=2.13.9 catch2 homebrew/cask + brew extract --version=2.13.9 catch2 homebrew/cask-versions brew install catch2@2.13.9 brew install boost brew install hdf5-mpi @@ -81,8 +83,8 @@ jobs: -DTrilinos_ENABLE_ALL_PACKAGES:BOOL=OFF \ -DTrilinos_ENABLE_Zoltan:BOOL=ON \ -DTrilinos_ENABLE_Fortran:BOOL=OFF \ - -DZoltan_ENABLE_EXAMPLES:BOOL=ON \ - -DZoltan_ENABLE_TESTS:BOOL=ON \ + -DZoltan_ENABLE_EXAMPLES:BOOL=OFF \ + -DZoltan_ENABLE_TESTS:BOOL=OFF \ -DBUILD_SHARED_LIBS=ON \ -Bbuild -S. sudo cmake --build build --config Release --target install @@ -94,6 +96,8 @@ jobs: -DCMAKE_C_COMPILER=mpicc \ -DCMAKE_CXX_COMPILER=mpicxx \ -DCMAKE_BUILD_TYPE=Release \ + -DENABLE_TESTS=OFF \ + -DENABLE_PARALLEL_TESTS=OFF \ -Bbuild -S. sudo cmake --build build --config Release --target install cd .. diff --git a/Grid.cpp b/Grid.cpp index 45f41a6..87d10d3 100644 --- a/Grid.cpp +++ b/Grid.cpp @@ -71,17 +71,21 @@ Grid::Grid(MPI_Comm comm, const std::string& filename, if (ret != NC_NOERR) data_nc_id = nc_id; int dim0_nc_id, dim1_nc_id; - NC_CHECK(nc_inq_dimid(data_nc_id, dim0_name.c_str(), &dim0_nc_id)); - NC_CHECK(nc_inq_dimid(data_nc_id, dim1_name.c_str(), &dim1_nc_id)); + // I have switched the order of the dimensions here to reflect the change of + // indices in nextsim-dg + NC_CHECK(nc_inq_dimid(data_nc_id, dim1_name.c_str(), &dim0_nc_id)); + NC_CHECK(nc_inq_dimid(data_nc_id, dim0_name.c_str(), &dim1_nc_id)); CHECK_MPI(MPI_Comm_rank(comm, &_rank)); // Retrieve the extent of each dimension of interest. The dimensions of // interest are the spatial dimensions of the grid. These are named "x" and // "y" by default. + // I have switched the order of the dimensions here to reflect the change of + // indices in nextsim-dg size_t tmp_0, tmp_1; - NC_CHECK(nc_inq_dimlen(data_nc_id, dim0_nc_id, &tmp_0)); - NC_CHECK(nc_inq_dimlen(data_nc_id, dim1_nc_id, &tmp_1)); + NC_CHECK(nc_inq_dimlen(data_nc_id, dim1_nc_id, &tmp_0)); + NC_CHECK(nc_inq_dimlen(data_nc_id, dim0_nc_id, &tmp_1)); _global_ext_0 = static_cast(tmp_0); _global_ext_1 = static_cast(tmp_1); _global_ext_blk_0 = ceil(static_cast(_global_ext_0) / _blk_factor_0); @@ -138,8 +142,10 @@ Grid::Grid(MPI_Comm comm, const std::string& filename, int dim_id[NDIMS]; char dim_name[NDIMS][128]; NC_CHECK(nc_inq_vardimid(data_nc_id, mask_nc_id, &dim_id[0])); - NC_CHECK(nc_inq_dimname(data_nc_id, dim_id[0], &dim_name[0][0])); - NC_CHECK(nc_inq_dimname(data_nc_id, dim_id[1], &dim_name[1][0])); + // I have switched the order of the dimensions here to reflect the change of + // indices in nextsim-dg + NC_CHECK(nc_inq_dimname(data_nc_id, dim_id[1], &dim_name[0][0])); + NC_CHECK(nc_inq_dimname(data_nc_id, dim_id[0], &dim_name[1][0])); if (dim_name[0] != dim0_name || dim_name[1] != dim1_name) { throw std::runtime_error("Dimension ordering provided does not match " "ordering in netCDF grid file"); @@ -147,15 +153,29 @@ Grid::Grid(MPI_Comm comm, const std::string& filename, _land_mask.resize(_num_objects); size_t start[NDIMS], count[NDIMS]; + // I have switched the order of the dimensions here to reflect the change of + // indices in nextsim-dg // Coordinate of first element - start[0] = _global_0; - start[1] = _global_1; + start[1] = _global_0; + start[0] = _global_1; // Number of elements in every extension - count[0] = _local_ext_0; - count[1] = _local_ext_1; + count[1] = _local_ext_0; + count[0] = _local_ext_1; NC_CHECK(nc_get_vara_int(data_nc_id, mask_nc_id, start, count, _land_mask.data())); + // create copy of land mask ready to transpose + std::vector _land_mask_copy(_land_mask); + + // transpose _land_mask to reflect the change of indices in nextsim-dg + int index = 0; + for (size_t j = 0; j < count[1]; j++) { + for (size_t i = 0; i < count[0]; i++) { + _land_mask[index] = _land_mask_copy[i*count[1]+j]; + index++; + } + } + // Apply land mask if (_blk_factor_0 == 1 && _blk_factor_1 == 1) { for (int i = 0; i < _num_objects; i++) { diff --git a/Grid.hpp b/Grid.hpp index c4feba9..ff6b40b 100644 --- a/Grid.hpp +++ b/Grid.hpp @@ -52,7 +52,7 @@ class LIB_EXPORT Grid * dim1) dimensions of the Grid class, where dim1 is defined as the fastest * increasing dimension. For example, if the dimensions of interest in the * netCDF file are named x and y and the variables are dimensioned as (y, x), - * then the y dimension will be mapped to dim0 and x to dim1 of the Grid + * then the y dimension will be mapped to dim1 and x to dim0 of the Grid * class, since the netCDF C/C++ convention is that the last dimension in the * CDL notation is the fastest increasing dimension. The default dimension * names for the netCDF file are "x" for dim0 and "y" for dim1, and the @@ -60,6 +60,12 @@ class LIB_EXPORT Grid * variables defined in the netCDF file follow the same convention in terms of * dimension ordering. * + * The code was originally written with the assumption that nextsim-dg would + * store arrays in (x,y) order. However, the indices have since been swapped + * and now nextsim-dg uses (y,x) order. To account for the switch of indices + * the grid input netcdf file is now transposed when it is read-in and the x + * and y dims are swapped in Grid.cpp. + * * @param comm MPI communicator. * @param filename Grid file in netCDF format. * @param dim0_name Name of 1st grid dimension in netCDF file (optional) diff --git a/test/test_0.nc b/test/test_0.nc index b241be1..6525777 100644 Binary files a/test/test_0.nc and b/test/test_0.nc differ diff --git a/test/test_1.nc b/test/test_1.nc index 5055643..7be5375 100644 Binary files a/test/test_1.nc and b/test/test_1.nc differ diff --git a/test/test_2.nc b/test/test_2.nc index ce353c7..99f701c 100644 Binary files a/test/test_2.nc and b/test/test_2.nc differ