Skip to content

Commit

Permalink
Tests and bugfixes
Browse files Browse the repository at this point in the history
  • Loading branch information
franzpoeschel committed Oct 30, 2024
1 parent a0236e3 commit fe9a74c
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 5 deletions.
5 changes: 2 additions & 3 deletions src/Mesh.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -334,9 +334,8 @@ unit_representations::AsArrays Mesh::gridUnitDimension() const
{
// gridUnitDimension is an optional attribute
// if it is missing, the mesh is interpreted as spatial
std::array<double, 7> spatialMesh;
auxiliary::fromMapOfUnitDimension(
spatialMesh.data(), {{UnitDimension::L, 1}});
auto spatialMesh =
unit_representations::asArray({{UnitDimension::L, 1}});
auto dim = retrieveMeshDimensionality(*this);
unit_representations::AsArrays res(dim, spatialMesh);
return res;
Expand Down
4 changes: 3 additions & 1 deletion src/UnitDimension.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ namespace unit_representations
{
auto asArray(AsMap const &udim) -> AsArray
{
AsArray res;
AsArray res{};
auxiliary::fromMapOfUnitDimension(res.data(), udim);
return res;
}
Expand All @@ -40,6 +40,7 @@ namespace unit_representations
auto asArrays(AsMaps const &vec) -> AsArrays
{
AsArrays res;
res.reserve(vec.size());
std::transform(
vec.begin(),
vec.end(),
Expand All @@ -50,6 +51,7 @@ namespace unit_representations
auto asMaps(AsArrays const &vec) -> AsMaps
{
AsMaps res;
res.reserve(vec.size());
std::transform(
vec.begin(),
vec.end(),
Expand Down
16 changes: 15 additions & 1 deletion src/binding/python/UnitDimension.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,5 +31,19 @@ void init_UnitDimension(py::module &m)
.value("I", UnitDimension::I)
.value("theta", UnitDimension::theta)
.value("N", UnitDimension::N)
.value("J", UnitDimension::J);
.value("J", UnitDimension::J)
.def(
"as_index",
[](UnitDimension ud) -> uint8_t {
return static_cast<uint8_t>(ud);
})
.def(
"from_index",
[](uint8_t idx) -> UnitDimension {
return static_cast<UnitDimension>(idx);
})
.def("as_array", &unit_representations::asArray)
.def("as_map", &unit_representations::asMap)
.def("as_arrays", &unit_representations::asArrays)
.def("as_maps", &unit_representations::asMaps);
}
8 changes: 8 additions & 0 deletions test/python/unittest/API/APITest.py
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,14 @@ def testFieldData(self):
self.assertEqual(len(i.meshes), 2)
for m in i.meshes:
self.assertTrue(m in ["E", "rho"])
self.assertEqual(i.meshes[m].unit_dimension, io.Unit_Dimension.as_array(
io.Unit_Dimension.as_map(i.meshes[m].unit_dimension)))
self.assertEqual(io.Unit_Dimension.as_maps(i.meshes[m].grid_unit_dimension), [
{io.Unit_Dimension.L: 1}, {io.Unit_Dimension.L: 1}])
self.assertEqual(io.Unit_Dimension.from_index(0), io.Unit_Dimension.L)
self.assertEqual(io.Unit_Dimension.L.as_index(), 0)
for idx in range(7):
self.assertEqual(idx, io.Unit_Dimension.from_index(idx).as_index())

# Check entries.
self.assertEqual(len(i.meshes), 2)
Expand Down

0 comments on commit fe9a74c

Please sign in to comment.