From f9e5852ef7f561d47c5e485fa60190769a5835ab Mon Sep 17 00:00:00 2001 From: micheltakken Date: Thu, 15 Aug 2024 12:16:55 +0200 Subject: [PATCH] :rotating_light: Add Rotated Cube STL Unit Tests --- tests/hybrid/Hybrid.test.cpp | 218 ++++++++++++++++++++++++++++++++++- 1 file changed, 217 insertions(+), 1 deletion(-) diff --git a/tests/hybrid/Hybrid.test.cpp b/tests/hybrid/Hybrid.test.cpp index 6203e0c..20cc3ad 100644 --- a/tests/hybrid/Hybrid.test.cpp +++ b/tests/hybrid/Hybrid.test.cpp @@ -3,9 +3,224 @@ #include #endif #include "gtest/gtest.h" +#include using T = double; +TEST(Opening, Cube0) { + + std::string stlFile = "../examples/STL/cube0.stl"; + int resolution = 100; + T dx = 1e-4/resolution; + + // define network + arch::Network network; + + // nodes + network.addNode(-5e-5, 0.0); + network.addNode(0.0, -5e-5); + network.addNode(5e-5, 0.0); + network.addNode(0.0, 5e-5); + + // module + network.addModule(std::vector({-5e-5, -5e-5}), std::vector({1e-4, 1e-4}), std::vector({0, 1, 2, 3})); + + // openings + std::unordered_map> Openings; + Openings.try_emplace(0, arch::Opening(network.getNode(0), std::vector({1.0, 0.0}), 1e-4)); + Openings.try_emplace(1, arch::Opening(network.getNode(1), std::vector({0.0, 1.0}), 1e-4)); + Openings.try_emplace(2, arch::Opening(network.getNode(2), std::vector({-1.0, 0.0}), 1e-4)); + Openings.try_emplace(3, arch::Opening(network.getNode(3), std::vector({0.0, -1.0}), 1e-4)); + + // simulator + sim::ResistanceModelPoiseuille resistanceModel = sim::ResistanceModelPoiseuille(1e-6); + sim::lbmSimulator s0 (0, "cube0", stlFile, network.getModule(0), Openings, &resistanceModel, 0.0, 0.0, 0.0, resolution, 0.0); + s0.readGeometryStl(dx, false); + s0.readOpenings(dx); + + EXPECT_NEAR(Openings.at(0).radial, 0.0, 1e-5); + EXPECT_NEAR(Openings.at(1).radial, -1.5708, 1e-5); + EXPECT_NEAR(Openings.at(2).radial, -3.14159, 1e-5); + EXPECT_NEAR(Openings.at(3).radial, 1.5708, 1e-5); + + for (unsigned char m : {3, 4, 5, 6}) { + EXPECT_EQ(s0.readGeometry().getStatistics().getNvoxel(m), resolution); + } +} + +TEST(Opening, Cube10) { + + std::string stlFile = "../examples/STL/cube10.stl"; + int resolution = 100; + T dx = 1e-4/resolution; + + // define network + arch::Network network; + + // nodes + network.addNode(-4.92404e-5, -8.6824e-6); + network.addNode(8.6824e-6, -4.92404e-5); + network.addNode(4.92404e-5, 8.6824e-6); + network.addNode(-8.6824e-6, 4.92404e-5); + + // module + network.addModule(std::vector({-5e-5, -5e-5}), std::vector({1e-4, 1e-4}), std::vector({0, 1, 2, 3})); + + // openings + std::unordered_map> Openings; + Openings.try_emplace(0, arch::Opening(network.getNode(0), std::vector({0.984807753, 0.173648178}), 1e-4)); + Openings.try_emplace(1, arch::Opening(network.getNode(1), std::vector({-0.173648178, 0.984807753}), 1e-4)); + Openings.try_emplace(2, arch::Opening(network.getNode(2), std::vector({-0.984807753, -0.173648178}), 1e-4)); + Openings.try_emplace(3, arch::Opening(network.getNode(3), std::vector({0.173648178, -0.984807753}), 1e-4)); + + // simulator + sim::ResistanceModelPoiseuille resistanceModel = sim::ResistanceModelPoiseuille(1e-6); + sim::lbmSimulator s0 (0, "cube10", stlFile, network.getModule(0), Openings, &resistanceModel, 0.0, 0.0, 0.0, resolution, 0.0); + s0.readGeometryStl(dx, false); + s0.readOpenings(dx); + + EXPECT_NEAR(Openings.at(0).radial, -0.174533, 1e-5); + EXPECT_NEAR(Openings.at(1).radial, -1.74533, 1e-5); + EXPECT_NEAR(Openings.at(2).radial, 2.96706, 1e-5); + EXPECT_NEAR(Openings.at(3).radial, 1.39626, 1e-5); + + for (unsigned char m : {3, 4, 5, 6}) { + unsigned int voxels = s0.readGeometry().getStatistics().getNvoxel(m); + EXPECT_GE(voxels, resolution); + EXPECT_LE(voxels, 2*resolution); + } +} + +TEST(Opening, Cube20) { + + std::string stlFile = "../examples/STL/cube20.stl"; + int resolution = 100; + T dx = 1e-4/resolution; + + // define network + arch::Network network; + + // nodes + network.addNode(-4.698460e-05, -1.71010e-05); + network.addNode(1.71010e-05, -4.698460e-05); + network.addNode(4.698460e-05, 1.71010e-05); + network.addNode(-1.71010e-05, 4.698460e-05); + + // module + network.addModule(std::vector({-5e-5, -5e-5}), std::vector({1e-4, 1e-4}), std::vector({0, 1, 2, 3})); + + // openings + std::unordered_map> Openings; + Openings.try_emplace(0, arch::Opening(network.getNode(0), std::vector({0.9396929621, 0.342020143}), 1e-4)); + Openings.try_emplace(1, arch::Opening(network.getNode(1), std::vector({-0.342020143, 0.9396929621}), 1e-4)); + Openings.try_emplace(2, arch::Opening(network.getNode(2), std::vector({-0.9396929621, -0.342020143}), 1e-4)); + Openings.try_emplace(3, arch::Opening(network.getNode(3), std::vector({0.342020143, -0.9396929621}), 1e-4)); + + // simulator + sim::ResistanceModelPoiseuille resistanceModel = sim::ResistanceModelPoiseuille(1e-6); + sim::lbmSimulator s0 (0, "cube20", stlFile, network.getModule(0), Openings, &resistanceModel, 0.0, 0.0, 0.0, resolution, 0.0); + s0.readGeometryStl(dx, false); + s0.readOpenings(dx); + + EXPECT_NEAR(Openings.at(0).radial, -0.349066, 1e-5); + EXPECT_NEAR(Openings.at(1).radial, -1.91986, 1e-5); + EXPECT_NEAR(Openings.at(2).radial, 2.79253, 1e-5); + EXPECT_NEAR(Openings.at(3).radial, 1.22173, 1e-5); + + for (unsigned char m : {3, 4, 5, 6}) { + unsigned int voxels = s0.readGeometry().getStatistics().getNvoxel(m); + EXPECT_GE(voxels, resolution); + EXPECT_LE(voxels, 2*resolution); + } +} + +TEST(Opening, Cube30) { + + std::string stlFile = "../examples/STL/cube30.stl"; + int resolution = 100; + T dx = 1e-4/resolution; + + // define network + arch::Network network; + + // nodes + network.addNode(-4.330130e-05, -2.5e-05); + network.addNode(2.5e-05, -4.330130e-05); + network.addNode(4.330130e-05, 2.5e-05); + network.addNode(-2.5e-05, 4.330130e-05); + + // module + network.addModule(std::vector({-5e-5, -5e-5}), std::vector({1e-4, 1e-4}), std::vector({0, 1, 2, 3})); + + // openings + std::unordered_map> Openings; + Openings.try_emplace(0, arch::Opening(network.getNode(0), std::vector({0.866025404, 0.5}), 1e-4)); + Openings.try_emplace(1, arch::Opening(network.getNode(1), std::vector({-0.5, 0.866025404}), 1e-4)); + Openings.try_emplace(2, arch::Opening(network.getNode(2), std::vector({-0.866025404, -0.5}), 1e-4)); + Openings.try_emplace(3, arch::Opening(network.getNode(3), std::vector({0.5, -0.866025404}), 1e-4)); + + // simulator + sim::ResistanceModelPoiseuille resistanceModel = sim::ResistanceModelPoiseuille(1e-6); + sim::lbmSimulator s0 (0, "cube30", stlFile, network.getModule(0), Openings, &resistanceModel, 0.0, 0.0, 0.0, resolution, 0.0); + s0.readGeometryStl(dx, false); + s0.readOpenings(dx); + + EXPECT_NEAR(Openings.at(0).radial, -0.523599, 1e-5); + EXPECT_NEAR(Openings.at(1).radial, -2.0944, 1e-5); + EXPECT_NEAR(Openings.at(2).radial, 2.61799, 1e-5); + EXPECT_NEAR(Openings.at(3).radial, 1.0472, 1e-5); + + for (unsigned char m : {3, 4, 5, 6}) { + unsigned int voxels = s0.readGeometry().getStatistics().getNvoxel(m); + EXPECT_GE(voxels, resolution); + EXPECT_LE(voxels, 2*resolution); + } +} + +TEST(Opening, Cube45) { + + std::string stlFile = "../examples/STL/cube45.stl"; + int resolution = 100; + T dx = 1e-4/resolution; + + // define network + arch::Network network; + + // nodes + network.addNode(-3.535535e-05, -3.535535e-05); + network.addNode(3.535535e-05, -3.535535e-05); + network.addNode(3.535535e-05, 3.535535e-05); + network.addNode(-3.535535e-05, 3.535535e-05); + + // module + network.addModule(std::vector({-5e-5, -5e-5}), std::vector({1e-4, 1e-4}), std::vector({0, 1, 2, 3})); + + // openings + std::unordered_map> Openings; + Openings.try_emplace(0, arch::Opening(network.getNode(0), std::vector({0.707106781, 0.707106781}), 1e-4)); + Openings.try_emplace(1, arch::Opening(network.getNode(1), std::vector({-0.707106781, 0.707106781}), 1e-4)); + Openings.try_emplace(2, arch::Opening(network.getNode(2), std::vector({-0.707106781, -0.707106781}), 1e-4)); + Openings.try_emplace(3, arch::Opening(network.getNode(3), std::vector({0.707106781, -0.707106781}), 1e-4)); + + // simulator + sim::ResistanceModelPoiseuille resistanceModel = sim::ResistanceModelPoiseuille(1e-6); + sim::lbmSimulator s0 (0, "cube45", stlFile, network.getModule(0), Openings, &resistanceModel, 0.0, 0.0, 0.0, resolution, 0.0); + s0.readGeometryStl(dx, false); + s0.readOpenings(dx); + + EXPECT_NEAR(Openings.at(0).radial, -0.785398, 1e-5); + EXPECT_NEAR(Openings.at(1).radial, -2.35619, 1e-5); + EXPECT_NEAR(Openings.at(2).radial, 2.35619, 1e-5); + EXPECT_NEAR(Openings.at(3).radial, 0.785398, 1e-5); + + for (unsigned char m : {3, 4, 5, 6}) { + unsigned int voxels = s0.readGeometry().getStatistics().getNvoxel(m); + EXPECT_GE(voxels, resolution); + EXPECT_LE(voxels, 2*resolution); + } +} + +/* TEST(Opening, Cube0) { std::string stlFile = "../examples/STL/cube0.stl"; @@ -423,6 +638,7 @@ TEST(Opening, Cube45) { EXPECT_GE(geometry->getStatistics().getNvoxel(6), resolution); EXPECT_LE(geometry->getStatistics().getNvoxel(6), 2*resolution); } +*/ /** TODO: * -> extendMargin is probably a function of how diagonal the normal of the face is (45 deg most extreme?) @@ -430,7 +646,7 @@ TEST(Opening, Cube45) { * the bounding box has one or multiple boundaries exactly on the lattice cell. If so, add artificial margin. */ - +/* TEST(Opening, Deg10) { std::string stlFile = "../examples/STL/cross10.stl";