Skip to content

Commit

Permalink
🚨 Add Rotated Cube STL Unit Tests
Browse files Browse the repository at this point in the history
  • Loading branch information
micheltakken committed Aug 15, 2024
1 parent aeb4302 commit f9e5852
Showing 1 changed file with 217 additions and 1 deletion.
218 changes: 217 additions & 1 deletion tests/hybrid/Hybrid.test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,224 @@
#include <mpi.h>
#endif
#include "gtest/gtest.h"
#include <iostream>

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<T> 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<T>({-5e-5, -5e-5}), std::vector<T>({1e-4, 1e-4}), std::vector<int>({0, 1, 2, 3}));

// openings
std::unordered_map<int, arch::Opening<T>> Openings;
Openings.try_emplace(0, arch::Opening<T>(network.getNode(0), std::vector<T>({1.0, 0.0}), 1e-4));
Openings.try_emplace(1, arch::Opening<T>(network.getNode(1), std::vector<T>({0.0, 1.0}), 1e-4));
Openings.try_emplace(2, arch::Opening<T>(network.getNode(2), std::vector<T>({-1.0, 0.0}), 1e-4));
Openings.try_emplace(3, arch::Opening<T>(network.getNode(3), std::vector<T>({0.0, -1.0}), 1e-4));

// simulator
sim::ResistanceModelPoiseuille<T> resistanceModel = sim::ResistanceModelPoiseuille<T>(1e-6);
sim::lbmSimulator<T> 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<T> 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<T>({-5e-5, -5e-5}), std::vector<T>({1e-4, 1e-4}), std::vector<int>({0, 1, 2, 3}));

// openings
std::unordered_map<int, arch::Opening<T>> Openings;
Openings.try_emplace(0, arch::Opening<T>(network.getNode(0), std::vector<T>({0.984807753, 0.173648178}), 1e-4));
Openings.try_emplace(1, arch::Opening<T>(network.getNode(1), std::vector<T>({-0.173648178, 0.984807753}), 1e-4));
Openings.try_emplace(2, arch::Opening<T>(network.getNode(2), std::vector<T>({-0.984807753, -0.173648178}), 1e-4));
Openings.try_emplace(3, arch::Opening<T>(network.getNode(3), std::vector<T>({0.173648178, -0.984807753}), 1e-4));

// simulator
sim::ResistanceModelPoiseuille<T> resistanceModel = sim::ResistanceModelPoiseuille<T>(1e-6);
sim::lbmSimulator<T> 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<T> 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<T>({-5e-5, -5e-5}), std::vector<T>({1e-4, 1e-4}), std::vector<int>({0, 1, 2, 3}));

// openings
std::unordered_map<int, arch::Opening<T>> Openings;
Openings.try_emplace(0, arch::Opening<T>(network.getNode(0), std::vector<T>({0.9396929621, 0.342020143}), 1e-4));
Openings.try_emplace(1, arch::Opening<T>(network.getNode(1), std::vector<T>({-0.342020143, 0.9396929621}), 1e-4));
Openings.try_emplace(2, arch::Opening<T>(network.getNode(2), std::vector<T>({-0.9396929621, -0.342020143}), 1e-4));
Openings.try_emplace(3, arch::Opening<T>(network.getNode(3), std::vector<T>({0.342020143, -0.9396929621}), 1e-4));

// simulator
sim::ResistanceModelPoiseuille<T> resistanceModel = sim::ResistanceModelPoiseuille<T>(1e-6);
sim::lbmSimulator<T> 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<T> 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<T>({-5e-5, -5e-5}), std::vector<T>({1e-4, 1e-4}), std::vector<int>({0, 1, 2, 3}));

// openings
std::unordered_map<int, arch::Opening<T>> Openings;
Openings.try_emplace(0, arch::Opening<T>(network.getNode(0), std::vector<T>({0.866025404, 0.5}), 1e-4));
Openings.try_emplace(1, arch::Opening<T>(network.getNode(1), std::vector<T>({-0.5, 0.866025404}), 1e-4));
Openings.try_emplace(2, arch::Opening<T>(network.getNode(2), std::vector<T>({-0.866025404, -0.5}), 1e-4));
Openings.try_emplace(3, arch::Opening<T>(network.getNode(3), std::vector<T>({0.5, -0.866025404}), 1e-4));

// simulator
sim::ResistanceModelPoiseuille<T> resistanceModel = sim::ResistanceModelPoiseuille<T>(1e-6);
sim::lbmSimulator<T> 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<T> 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<T>({-5e-5, -5e-5}), std::vector<T>({1e-4, 1e-4}), std::vector<int>({0, 1, 2, 3}));

// openings
std::unordered_map<int, arch::Opening<T>> Openings;
Openings.try_emplace(0, arch::Opening<T>(network.getNode(0), std::vector<T>({0.707106781, 0.707106781}), 1e-4));
Openings.try_emplace(1, arch::Opening<T>(network.getNode(1), std::vector<T>({-0.707106781, 0.707106781}), 1e-4));
Openings.try_emplace(2, arch::Opening<T>(network.getNode(2), std::vector<T>({-0.707106781, -0.707106781}), 1e-4));
Openings.try_emplace(3, arch::Opening<T>(network.getNode(3), std::vector<T>({0.707106781, -0.707106781}), 1e-4));

// simulator
sim::ResistanceModelPoiseuille<T> resistanceModel = sim::ResistanceModelPoiseuille<T>(1e-6);
sim::lbmSimulator<T> 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";
Expand Down Expand Up @@ -423,14 +638,15 @@ 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?)
* -> cube0 has additional 0.5*dx margin, to have the edge between cells. Todo: add an if function for whether
* 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";
Expand Down

0 comments on commit f9e5852

Please sign in to comment.