Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 0 additions & 2 deletions .github/workflows/test_suite.yml
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,6 @@ jobs:
./run_test_jan2010_integration.sh python3
./run_test_advection.sh python3
./run_test_error_handling_test.sh python3
cd -

# MPI tests on latest Ubuntu OS without XIOS support
test-ubuntu-mpi-noxios:
Expand Down Expand Up @@ -246,4 +245,3 @@ jobs:
./run_test_jan2010_integration.sh python
./run_test_advection.sh python
./run_test_error_handling_test.sh python
cd -
9 changes: 5 additions & 4 deletions core/src/ParaGridIO.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,14 +33,15 @@ ParaGridIO::ParaGridIO(ParametricGrid& grid)
, dimensionKeys({
// clang-format off
// Accept post-May 2024 (xdim, ydim, zdim) dimension names and pre-May 2024 (x, y, z)
{ "yx", ModelArray::Type::H },
{ "ydimxdim", ModelArray::Type::H },
{ "yxdg_comp", ModelArray::Type::DG },
{ "y_dimx_dim", ModelArray::Type::H },
{ "ydimxdimdg_comp", ModelArray::Type::DG },
{ "yxdgstress_comp", ModelArray::Type::DGSTRESS },
{ "y_dimx_dimdg_comp", ModelArray::Type::DG },
{ "ydimxdimdgstress_comp", ModelArray::Type::DGSTRESS },
{ "ycgxcg", ModelArray::Type::CG },
{ "y_dimx_dimdgstress_comp", ModelArray::Type::DGSTRESS },
{ "y_cgx_cg", ModelArray::Type::CG },
{ "yvertexxvertexncoords", ModelArray::Type::VERTEX },
{ "y_vertexx_vertexncoords", ModelArray::Type::VERTEX },
// clang-format on
})
, isDG({
Expand Down
89 changes: 59 additions & 30 deletions core/src/Xios.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -501,83 +501,112 @@ void Xios::setupDomains()
// Set domain extents based on model metadata
size_t counter = 0;
for (ModelArray::Dimension& dim : ModelArray::typeDimensions[type]) {
const std::string& domainName = ModelArray::definedDimensions[dim].name;
if (counter == 0) {
const std::string dimName = "x";
int ni_glo;
int ni;
int ibegin;
if (dim == ModelArray::Dimension::X) {
cxios_set_domain_ni_glo(domain, metadata.getGlobalExtentX());
cxios_set_domain_ni(domain, metadata.getLocalExtentX());
cxios_set_domain_ibegin(domain, metadata.getLocalCornerX());
ni_glo = metadata.getGlobalExtentX();
ni = metadata.getLocalExtentX();
ibegin = metadata.getLocalCornerX();
} else if (dim == ModelArray::Dimension::XVERTEX) {
cxios_set_domain_ni_glo(domain, metadata.getGlobalExtentX() + 1);
cxios_set_domain_ni(domain, metadata.getLocalExtentX() + 1);
cxios_set_domain_ibegin(domain, metadata.getLocalCornerX());
ni_glo = metadata.getGlobalExtentX() + 1;
ni = metadata.getLocalExtentX() + 1;
ibegin = metadata.getLocalCornerX();
} else if (dim == ModelArray::Dimension::XCG) {
cxios_set_domain_ni_glo(domain, CGDEGREE * metadata.getGlobalExtentX() + 1);
cxios_set_domain_ni(domain, CGDEGREE * metadata.getLocalExtentX() + 1);
cxios_set_domain_ibegin(domain, CGDEGREE * metadata.getLocalCornerX());
ni_glo = CGDEGREE * metadata.getGlobalExtentX() + 1;
ni = CGDEGREE * metadata.getLocalExtentX() + 1;
ibegin = CGDEGREE * metadata.getLocalCornerX();
} else {
throw std::runtime_error(
"Xios: Could not set domain extents based on dimension '"
+ ModelArray::definedDimensions.at(dim).name + "'");
"Xios: Could not set domain extents based on dimension '" + dimName + "'");
}
cxios_set_domain_ni_glo(domain, ni_glo);
if (!cxios_is_defined_domain_ni_glo(domain)) {
throw std::runtime_error(
"Xios: Failed to set global x-size for domain '" + domainId + "'");
}
cxios_set_domain_ni(domain, ni);
if (!cxios_is_defined_domain_ni(domain)) {
throw std::runtime_error(
"Xios: Failed to set local x-size for domain '" + domainId + "'");
}
cxios_set_domain_ibegin(domain, ibegin);
if (!cxios_is_defined_domain_ibegin(domain)) {
throw std::runtime_error(
"Xios: Failed to set local starting x-index for domain '" + domainId + "'");
}
cxios_set_domain_dim_i_name(domain, domainName.c_str(), domainName.length());
std::vector<double> lonvalue;
for (int i = 0; i < ni; i++) {
lonvalue.push_back(ibegin + i);
}
cxios_set_domain_lonvalue_1d(domain, lonvalue.data(), &ni);
if (!cxios_is_defined_domain_lonvalue_1d(domain)) {
throw std::runtime_error(
"Xios: Failed to set local x-indices for domain '" + domainId + "'");
}
cxios_set_domain_dim_i_name(domain, dimName.c_str(), dimName.length());
if (!cxios_is_defined_domain_dim_i_name(domain)) {
throw std::runtime_error(
"Xios: Failed to set x-coordinate name for domain '" + domainId + "'");
}
cxios_set_domain_lon_name(domain, domainName.c_str(), domainName.length());
cxios_set_domain_lon_name(domain, dimName.c_str(), dimName.length());
if (!cxios_is_defined_domain_lon_name(domain)) {
throw std::runtime_error(
"Xios: Failed to set longitude name for domain '" + domainId + "'");
}
} else if (counter == 1) {
const std::string dimName = "y";
int nj_glo;
int nj;
int jbegin;
if (dim == ModelArray::Dimension::Y) {
cxios_set_domain_nj_glo(domain, metadata.getGlobalExtentY());
cxios_set_domain_nj(domain, metadata.getLocalExtentY());
cxios_set_domain_jbegin(domain, metadata.getLocalCornerY());
nj_glo = metadata.getGlobalExtentY();
nj = metadata.getLocalExtentY();
jbegin = metadata.getLocalCornerY();
} else if (dim == ModelArray::Dimension::YVERTEX) {
cxios_set_domain_nj_glo(domain, metadata.getGlobalExtentY() + 1);
cxios_set_domain_nj(domain, metadata.getLocalExtentY() + 1);
cxios_set_domain_jbegin(domain, metadata.getLocalCornerY());
nj_glo = metadata.getGlobalExtentY() + 1;
nj = metadata.getLocalExtentY() + 1;
jbegin = metadata.getLocalCornerY();
} else if (dim == ModelArray::Dimension::YCG) {
cxios_set_domain_nj_glo(domain, CGDEGREE * metadata.getGlobalExtentY() + 1);
cxios_set_domain_nj(domain, CGDEGREE * metadata.getLocalExtentY() + 1);
cxios_set_domain_jbegin(domain, CGDEGREE * metadata.getLocalCornerY());
nj_glo = CGDEGREE * metadata.getGlobalExtentY() + 1;
nj = CGDEGREE * metadata.getLocalExtentY() + 1;
jbegin = CGDEGREE * metadata.getLocalCornerY();
} else {
throw std::runtime_error(
"Xios: Could not set domain extents based on dimension '"
+ ModelArray::definedDimensions.at(dim).name + "'");
"Xios: Could not set domain extents based on dimension '" + dimName + "'");
}
cxios_set_domain_nj_glo(domain, nj_glo);
if (!cxios_is_defined_domain_nj_glo(domain)) {
throw std::runtime_error(
"Xios: Failed to set global y-size for domain '" + domainId + "'");
}
cxios_set_domain_nj(domain, nj);
if (!cxios_is_defined_domain_nj(domain)) {
throw std::runtime_error(
"Xios: Failed to set local y-size for domain '" + domainId + "'");
}
cxios_set_domain_jbegin(domain, jbegin);
if (!cxios_is_defined_domain_jbegin(domain)) {
throw std::runtime_error(
"Xios: Failed to set local starting y-index for domain '" + domainId + "'");
}
cxios_set_domain_dim_j_name(domain, domainName.c_str(), domainName.length());
std::vector<double> latvalue;
for (int j = 0; j < nj; j++) {
latvalue.push_back(jbegin + j);
}
cxios_set_domain_latvalue_1d(domain, latvalue.data(), &nj);
if (!cxios_is_defined_domain_latvalue_1d(domain)) {
throw std::runtime_error(
"Xios: Failed to set local y-indices for domain '" + domainId + "'");
}
cxios_set_domain_dim_j_name(domain, dimName.c_str(), dimName.length());
if (!cxios_is_defined_domain_dim_j_name(domain)) {
throw std::runtime_error(
"Xios: Failed to set y-coordinate name for domain '" + domainId + "'");
}
cxios_set_domain_lat_name(domain, domainName.c_str(), domainName.length());
cxios_set_domain_lat_name(domain, dimName.c_str(), dimName.length());
if (!cxios_is_defined_domain_lat_name(domain)) {
throw std::runtime_error(
"Xios: Failed to set latitude name for domain '" + domainId + "'");
Expand Down Expand Up @@ -928,12 +957,12 @@ void Xios::setupFields()

// Create map for field types
const std::map<std::string, ModelArray::Type> dimensionKeys = {
{ "yx", ModelArray::Type::H },
{ "ydimxdim", ModelArray::Type::H },
{ "yxdg_comp", ModelArray::Type::DG },
{ "y_dimx_dim", ModelArray::Type::H },
{ "ydimxdimdg_comp", ModelArray::Type::DG },
{ "yxdgstress_comp", ModelArray::Type::DGSTRESS },
{ "y_dimx_dimdg_comp", ModelArray::Type::DG },
{ "ydimxdimdgstress_comp", ModelArray::Type::DGSTRESS },
{ "y_dimx_dimdgstress_comp", ModelArray::Type::DGSTRESS },
{ "y_cgx_cg", ModelArray::Type::CG },
{ "yvertexxvertexncoords", ModelArray::Type::VERTEX },
{ "y_vertexx_vertexncoords", ModelArray::Type::VERTEX },
Expand Down
8 changes: 4 additions & 4 deletions core/src/discontinuousgalerkin/ModelArrayDetails.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,10 @@ namespace Nextsim {
// clang-format off
std::map<ModelArray::Dimension, ModelArray::DimensionSpec> ModelArray::definedDimensions = {
// set default global size, local size and start position for each dimension
{ ModelArray::Dimension::X, { "xdim", "x", 0, 0, 0 } },
{ ModelArray::Dimension::Y, { "ydim", "y", 0, 0, 0 } },
{ ModelArray::Dimension::XVERTEX, { "xvertex", "xvertex", 1, 1, 0 } }, // defined as x + 1
{ ModelArray::Dimension::YVERTEX, { "yvertex", "yvertex", 1, 1, 0 } }, // defined as y + 1
{ ModelArray::Dimension::X, { "x_dim", "xdim", 0, 0, 0 } },
{ ModelArray::Dimension::Y, { "y_dim", "ydim", 0, 0, 0 } },
{ ModelArray::Dimension::XVERTEX, { "x_vertex", "xvertex", 1, 1, 0 } }, // defined as x + 1
{ ModelArray::Dimension::YVERTEX, { "y_vertex", "yvertex", 1, 1, 0 } }, // defined as y + 1
{ ModelArray::Dimension::XCG, { "x_cg", "x_cg", CGDEGREE, CGDEGREE, 0 } },
{ ModelArray::Dimension::YCG, { "y_cg", "y_cg", CGDEGREE, CGDEGREE, 0 } },
// The DG components are also included here to store the names
Expand Down
8 changes: 4 additions & 4 deletions core/src/finitevolume/ModelArrayDetails.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,10 @@

namespace Nextsim {
std::map<ModelArray::Dimension, ModelArray::DimensionSpec> ModelArray::definedDimensions = {
{ ModelArray::Dimension::X, { "xdim", "x", 0, 0, 0 } },
{ ModelArray::Dimension::Y, { "ydim", "y", 0, 0, 0 } },
{ ModelArray::Dimension::XVERTEX, { "xvertex", "xvertex", 1, 1, 0 } }, // defined as x + 1
{ ModelArray::Dimension::YVERTEX, { "yvertex", "yvertex", 1, 1, 0 } }, // defined as y + 1
{ ModelArray::Dimension::X, { "x_dim", "xdim", 0, 0, 0 } },
{ ModelArray::Dimension::Y, { "y_dim", "ydim", 0, 0, 0 } },
{ ModelArray::Dimension::XVERTEX, { "x_vertex", "xvertex", 1, 1, 0 } }, // defined as x + 1
{ ModelArray::Dimension::YVERTEX, { "y_vertex", "yvertex", 1, 1, 0 } }, // defined as y + 1
};

ModelArray::TypeDimensions ModelArray::typeDimensions = {
Expand Down
15 changes: 10 additions & 5 deletions core/src/include/Xios.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -151,12 +151,17 @@ class Xios : public Configured<Xios> {
xios::CAxis* getAxis(const std::string& axisId);

/* Domain */
// NOTE: Dimension names get processed as <dim>_<domainId> by XIOS, so we define the domainIds
// so that these coincide with the altnames when applied to dimensions x and y.
std::map<ModelArray::Type, std::string> domainIds = {
{ ModelArray::Type::H, "HDomain" },
{ ModelArray::Type::VERTEX, "VertexDomain" },
{ ModelArray::Type::DG, "HDomain" },
{ ModelArray::Type::DGSTRESS, "HDomain" },
{ ModelArray::Type::CG, "CGDomain" },
// Standard cell-based x- and y-dimensions (alt. names x_dim and y_dim)
{ ModelArray::Type::H, "dim" },
{ ModelArray::Type::DG, "dim" },
{ ModelArray::Type::DGSTRESS, "dim" },
// Vertex-based x- and y-dimensions (alt. names x_vertex and y_vertex)
{ ModelArray::Type::VERTEX, "vertex" },
// CG-based x- and y-dimensions (alt. names x_cg and y_cg)
{ ModelArray::Type::CG, "cg" },
};
xios::CDomainGroup* getDomainGroup();
xios::CDomain* getDomain(const std::string& domainId);
Expand Down
4 changes: 2 additions & 2 deletions core/src/include/gridNames.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,8 @@ static const std::string vIOStressName = "viostress";
static const std::string coordsName = "coords";
static const std::string latitudeName = "latitude";
static const std::string longitudeName = "longitude";
static const std::string xName = "x";
static const std::string yName = "y";
static const std::string xName = "x_dim";
static const std::string yName = "y_dim";
static const std::string gridAzimuthName = "grid_azimuth";

static const std::string mdiName = "missing_value";
Expand Down
4 changes: 4 additions & 0 deletions core/src/include/xios_c_interface.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -90,10 +90,14 @@ bool cxios_is_defined_domain_lat_name(xios::CDomain* domain_hdl);
bool cxios_is_defined_domain_lon_name(xios::CDomain* domain_hdl);
bool cxios_is_defined_domain_ni_glo(xios::CDomain* domain_hdl);
bool cxios_is_defined_domain_nj_glo(xios::CDomain* domain_hdl);
void cxios_set_domain_lonvalue_1d(xios::CDomain* domain_hdl, double* data, const int* ni);
void cxios_set_domain_latvalue_1d(xios::CDomain* domain_hdl, double* data, const int* nj);
bool cxios_is_defined_domain_ni(xios::CDomain* domain_hdl);
bool cxios_is_defined_domain_nj(xios::CDomain* domain_hdl);
bool cxios_is_defined_domain_ibegin(xios::CDomain* domain_hdl);
bool cxios_is_defined_domain_jbegin(xios::CDomain* domain_hdl);
bool cxios_is_defined_domain_lonvalue_1d(xios::CDomain* domain_hdl);
bool cxios_is_defined_domain_latvalue_1d(xios::CDomain* domain_hdl);

// grid group methods
void cxios_gridgroup_handle_create(xios::CGridGroup** _ret, const char* _id, int _id_len);
Expand Down
6 changes: 3 additions & 3 deletions core/src/iodef.xml.jinja
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@

<!-- Axes defining extrusions for certain fields based on degrees of freedom per node -->
<axis_definition>
<axis id="DGAxis" n_glo="{{ DGCOMP }}" name="dg_comp" dim_name="DGAxis"/>
<axis id="DGSAxis" n_glo="{{ DGSTRESSCOMP }}" name="dgstress_comp" dim_name="DGSAxis"/>
<axis id="VertexAxis" n_glo="2" name="ncoords" dim_name="VertexAxis"/>
<axis id="DGAxis" n_glo="{{ DGCOMP }}" name="dg_comp" dim_name="dg_comp"/>
<axis id="DGSAxis" n_glo="{{ DGSTRESSCOMP }}" name="dgstress_comp" dim_name="dgstress_comp"/>
<axis id="VertexAxis" n_glo="2" name="ncoords" dim_name="ncoords"/>
</axis_definition>

<grid_definition>
Expand Down
5 changes: 4 additions & 1 deletion core/test/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ set(ModulesRoot "../src/modules")

# Generate netCDF files for tests
execute_process(
COMMAND "${Python_EXECUTABLE}" "${CMAKE_CURRENT_SOURCE_DIR}/old_names.py"
COMMAND "${Python_EXECUTABLE}" "${CMAKE_CURRENT_SOURCE_DIR}/alt_names.py"
WORKING_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}"
)
execute_process(
Expand Down Expand Up @@ -271,6 +271,9 @@ if(ENABLE_MPI)
)

add_mpi_test("${XIOS_TESTS}")

# Ensure XiosWrite_test is run before XiosRead_test
set_tests_properties(testXiosRead_MPI2 PROPERTIES DEPENDS testXiosWrite_MPI2)
else()
add_executable(testHaloExchangeCB_MPI3
"HaloExchangeCB_test.cpp"
Expand Down
14 changes: 7 additions & 7 deletions core/test/ParaGridIO_input_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,10 @@
time_meta[:] = the_time
time_meta.units = "seconds since 1970-01-01T00:00:00Z"

xDim = ncFile.createDimension("x", nx)
yDim = ncFile.createDimension("y", ny)
xVertexDim = ncFile.createDimension("xvertex", nx + 1)
yVertexDim = ncFile.createDimension("yvertex", ny + 1)
xDim = ncFile.createDimension("x_dim", nx)
yDim = ncFile.createDimension("y_dim", ny)
xVertexDim = ncFile.createDimension("x_vertex", nx + 1)
yVertexDim = ncFile.createDimension("y_vertex", ny + 1)
xcg_dim = ncFile.createDimension("x_cg", nx * ncg + 1)
ycg_dim = ncFile.createDimension("y_cg", ny * ncg + 1)
dg_comp = ncFile.createDimension("dg_comp", n_dg)
Expand All @@ -49,17 +49,17 @@
tDim = ncFile.createDimension("time", None)

# Position and time variables
nc_lons = ncFile.createVariable("longitude", "f8", ("y", "x"))
nc_lons = ncFile.createVariable("longitude", "f8", ("y_dim", "x_dim"))
nc_lons[:, :] = element_x
nc_lats = ncFile.createVariable("latitude", "f8", ("y", "x"))
nc_lats = ncFile.createVariable("latitude", "f8", ("y_dim", "x_dim"))
nc_lats[:, :] = element_y

nc_times = ncFile.createVariable("time", "f8", ("time"))

# (unix_times_e, era5_times) = create_era5_times(start_time, stop_time)
# For each field and time, get the corresponding file name for each dataset
# get the source data
data = ncFile.createVariable(field_name, "f8", ("time", "y", "x"))
data = ncFile.createVariable(field_name, "f8", ("time", "y_dim", "x_dim"))
data[0, :, :] = time_data
# 'fill' the time axis
nc_times[0] = the_time
Expand Down
6 changes: 3 additions & 3 deletions core/test/ParaGrid_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -489,12 +489,12 @@ TEST_CASE("Check an exception is thrown for an invalid file name")
}

#ifdef USE_MPI
MPI_TEST_CASE("Check if a file with the old dimension names can be read", 2)
MPI_TEST_CASE("Check if a file with the alternative dimension names can be read", 2)
#else
TEST_CASE("Check if a file with the old dimension names can be read")
TEST_CASE("Check if a file with the alternative dimension names can be read")
#endif
{
std::string inputFilename = std::string(TEST_FILE_SOURCE) + "/old_names.nc";
std::string inputFilename = std::string(TEST_FILE_SOURCE) + "/alt_names.nc";

Module::setImplementation<IStructure>("Nextsim::ParametricGrid");

Expand Down
Loading
Loading