diff --git a/src/Mesh.cpp b/src/Mesh.cpp index 58c3450c69..c753e28d4a 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,16 @@ namespace std::vector Mesh::gridUnitSIPerDimension() const { - return getAttribute("gridUnitSI").get>(); + if (containsAttribute("gridUnitSI")) + { + 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 +333,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 8e9ede00ed..553a03ea04 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 =