diff --git a/src/Mesh.cpp b/src/Mesh.cpp index 2ac6d6bb42..b4e0584dcb 100644 --- a/src/Mesh.cpp +++ b/src/Mesh.cpp @@ -209,14 +209,10 @@ namespace { uint64_t retrieveMeshDimensionality(Mesh const &m) { - try + if (m.containsAttribute("axisLabels")) { return m.axisLabels().size(); } - catch (no_such_attribute_error const &) - { - // no-op, continue with fallback below - } // maybe we have record components and can ask them if (auto it = m.begin(); it != m.end()) @@ -233,7 +229,27 @@ namespace std::vector Mesh::gridUnitSIPerDimension() const { - return getAttribute("gridUnitSI").get>(); + if (containsAttribute("gridUnitSI")) + { + if (auto series_opt = retrieveSeries_optional(); series_opt.has_value()) + { + if (auto version = series_opt->openPMD(); version < "2.") + { + // If the openPMD version is lower than 2.0, the gridUnitSI is a + // scalar interpreted for all axes. Copy it d times. + return std::vector( + retrieveMeshDimensionality(*this), + getAttribute("gridUnitSI").get()); + } + } + return getAttribute("gridUnitSI").get>(); + } + else + { + // gridUnitSI is an optional attribute + // if it is missing, the mesh is interpreted as unscaled + return std::vector(retrieveMeshDimensionality(*this), 1.); + } } Mesh &Mesh::setGridUnitSIPerDimension(std::vector gridUnitSI) @@ -328,7 +344,7 @@ std::vector> Mesh::gridUnitDimension() const } else { - // gridUnitSI is an optional attribute + // gridUnitDimension is an optional attribute // if it is missing, the mesh is interpreted as spatial std::array spatialMesh; fromMapOfUnitDimension(spatialMesh.begin(), {{UnitDimension::L, 1}}); diff --git a/test/SerialIOTest.cpp b/test/SerialIOTest.cpp index b92816ac6e..7bd51b3b18 100644 --- a/test/SerialIOTest.cpp +++ b/test/SerialIOTest.cpp @@ -947,10 +947,15 @@ inline void constant_scalar(std::string const &file_ending) E_mesh.setDataOrder(dataOrder); E_mesh.setGridSpacing(gridSpacing); E_mesh.setGridGlobalOffset(gridGlobalOffset); - E_mesh.setGridUnitSI(std::vector(3, gridUnitSI)); E_mesh.setAxisLabels(axisLabels); E_mesh.setUnitDimension(unitDimensions); E_mesh.setTimeOffset(timeOffset); + REQUIRE( + E_mesh.gridUnitSIPerDimension() == std::vector{1., 1., 1.}); + E_mesh.setGridUnitSI(std::vector(3, gridUnitSI)); + REQUIRE( + E_mesh.gridUnitSIPerDimension() == + std::vector{gridUnitSI, gridUnitSI, gridUnitSI}); // constant scalar auto pos =