Skip to content

Commit

Permalink
✔️ Pass Hybrid Test case1a
Browse files Browse the repository at this point in the history
  • Loading branch information
micheltakken committed Jun 3, 2024
1 parent 207b37a commit a7a8281
Show file tree
Hide file tree
Showing 4 changed files with 57 additions and 47 deletions.
8 changes: 4 additions & 4 deletions src/porting/jsonReaders.hh
Original file line number Diff line number Diff line change
Expand Up @@ -219,15 +219,15 @@ void readSimulators(json jsonString, sim::Simulation<T>& simulation, arch::Netwo

if(simulator["Type"] == "LBM")
{
auto simulator = simulation.addLbmSimulator(name, stlFile, network->getModule(moduleId), Openings, simulation.getResistanceModel(),
charPhysLength, charPhysVelocity, alpha, resolution, epsilon, tau);
auto simulator = simulation.addLbmSimulator(name, stlFile, network->getModule(moduleId), Openings, charPhysLength,
charPhysVelocity, alpha, resolution, epsilon, tau);
simulator->setVtkFolder(vtkFolder);
}
else if(simulator["Type"] == "ESS_LBM")
{
#ifdef USE_ESSLBM
auto simulator = simulation.addEssLbmSimulator(name, stlFile, network->getModule(moduleId), Openings, simulation.getResistanceModel(),
charPhysLength, charPhysVelocity, alpha, resolution, epsilon, tau);
auto simulator = simulation.addEssLbmSimulator(name, stlFile, network->getModule(moduleId), Openings, charPhysLength,
charPhysVelocity, alpha, resolution, epsilon, tau);
simulator->setVtkFolder(vtkFolder);
#else
throw std::invalid_argument("The simulator was not build using the ESS library.");
Expand Down
4 changes: 2 additions & 2 deletions src/simulation/Simulation.h
Original file line number Diff line number Diff line change
Expand Up @@ -241,7 +241,7 @@ class Simulation {
* @return Pointer to the newly created module.
*/
lbmSimulator<T>* addLbmSimulator(std::string name, std::string stlFile, std::shared_ptr<arch::Module<T>> module, std::unordered_map<int, arch::Opening<T>> openings,
ResistanceModel<T>* resistanceModel, T charPhysLength, T charPhysVelocity, T alpha, T resolution, T epsilon, T tau);
T charPhysLength, T charPhysVelocity, T alpha, T resolution, T epsilon, T tau);

/**
* @brief Adds a new module to the network.
Expand All @@ -250,7 +250,7 @@ class Simulation {
* @param[in] openings Map of openings corresponding to the nodes.
*/
essLbmSimulator<T>* addEssLbmSimulator(std::string name, std::string stlFile, std::shared_ptr<arch::Module<T>> module, std::unordered_map<int, arch::Opening<T>> openings,
ResistanceModel<T>* resistanceModel, T charPhysLength, T charPhysVelocity, T resolution, T epsilon, T tau);
T charPhysLength, T charPhysVelocity, T resolution, T epsilon, T tau);

/**
* @brief Set the platform of the simulation.
Expand Down
39 changes: 22 additions & 17 deletions src/simulation/Simulation.hh
Original file line number Diff line number Diff line change
Expand Up @@ -102,34 +102,39 @@ namespace sim {

template<typename T>
lbmSimulator<T>* Simulation<T>::addLbmSimulator(std::string name, std::string stlFile, std::shared_ptr<arch::Module<T>> module, std::unordered_map<int, arch::Opening<T>> openings,
ResistanceModel<T>* resistanceModel, T charPhysLength, T charPhysVelocity, T alpha, T resolution, T epsilon, T tau)
T charPhysLength, T charPhysVelocity, T alpha, T resolution, T epsilon, T tau)
{
// create Simulator
auto id = cfdSimulators.size();
auto addCfdSimulator = new lbmSimulator<T>(id, name, stlFile, module, openings, resistanceModel, charPhysLength, charPhysVelocity, alpha, resolution, epsilon, tau);
if (resistanceModel != nullptr) {
// create Simulator
auto id = cfdSimulators.size();
auto addCfdSimulator = new lbmSimulator<T>(id, name, stlFile, module, openings, resistanceModel, charPhysLength, charPhysVelocity, alpha, resolution, epsilon, tau);

// add Simulator
cfdSimulators.try_emplace(id, addCfdSimulator);
// add Simulator
cfdSimulators.try_emplace(id, addCfdSimulator);

return addCfdSimulator;
return addCfdSimulator;
} else {
throw std::invalid_argument("Attempt to add CFD Simulator without valid resistanceModel.");
}
}

template<typename T>
essLbmSimulator<T>* Simulation<T>::addEssLbmSimulator(std::string name, std::string stlFile, std::shared_ptr<arch::Module<T>> module, std::unordered_map<int, arch::Opening<T>> openings,
ResistanceModel<T>* resistanceModel, T charPhysLength, T charPhysVelocity, T resolution, T epsilon, T tau)
T charPhysLength, T charPhysVelocity, T resolution, T epsilon, T tau)
{
#ifdef USE_ESSLBM
if (resistanceModel != nullptr) {
// create Simulator
auto id = cfdSimulators.size();
auto addCfdSimulator = new essLbmModule<T>(id, name, stlFile, openings, charPhysLength, charPhysVelocity, resolution, epsilon, tau);

// create Simulator
auto id = cfdSimulators.size();
auto addCfdSimulator = new essLbmModule<T>(id, name, stlFile, openings, charPhysLength, charPhysVelocity, resolution, epsilon, tau);


// add Simulator
cfdSimulators.try_emplace(id, addCfdSimulator);

return addCfdSimulator;
// add Simulator
cfdSimulators.try_emplace(id, addCfdSimulator);

return addCfdSimulator;
} else {
throw std::invalid_argument("Attempt to add CFD Simulator without valid resistanceModel.");
}
#else
throw std::invalid_argument("MMFT Simulator was not built using the ESS library.");
#endif
Expand Down
53 changes: 29 additions & 24 deletions tests/hybrid/Hybrid.test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,46 +36,49 @@ TEST(Continuous, Case1a) {
auto c0 = network.addChannel(node0->getId(), node1->getId(), cHeight, cWidth, cLength, arch::ChannelType::NORMAL);
auto c1 = network.addChannel(node0->getId(), node2->getId(), cHeight, cWidth, cLength, arch::ChannelType::NORMAL);
auto c2 = network.addChannel(node0->getId(), node3->getId(), cHeight, cWidth, cLength, arch::ChannelType::NORMAL);
auto c3 = network.addChannel(node1->getId(), node4->getId(), cHeight, cWidth, cLength, arch::ChannelType::NORMAL);
auto c4 = network.addChannel(node2->getId(), node5->getId(), cHeight, cWidth, cLength, arch::ChannelType::NORMAL);
auto c5 = network.addChannel(node3->getId(), node6->getId(), cHeight, cWidth, cLength, arch::ChannelType::NORMAL);
auto c6 = network.addChannel(node4->getId(), node7->getId(), cHeight, cWidth, cLength, arch::ChannelType::NORMAL);
auto c7 = network.addChannel(node6->getId(), node8->getId(), cHeight, cWidth, cLength, arch::ChannelType::NORMAL);
auto c8 = network.addChannel(node9->getId(), node10->getId(), cHeight, cWidth, cLength, arch::ChannelType::NORMAL);
network.addChannel(node1->getId(), node4->getId(), cHeight, cWidth, cLength, arch::ChannelType::NORMAL);
network.addChannel(node2->getId(), node5->getId(), cHeight, cWidth, cLength, arch::ChannelType::NORMAL);
network.addChannel(node3->getId(), node6->getId(), cHeight, cWidth, cLength, arch::ChannelType::NORMAL);
network.addChannel(node4->getId(), node7->getId(), cHeight, cWidth, cLength, arch::ChannelType::NORMAL);
network.addChannel(node6->getId(), node8->getId(), cHeight, cWidth, cLength, arch::ChannelType::NORMAL);
network.addChannel(node9->getId(), node10->getId(), cHeight, cWidth, cLength, arch::ChannelType::NORMAL);

// module
std::string name = "Paper1a-cross-0";
std::string stlFile = "../examples/STL/cross.stl";
std::vector<T> position = { 1.75e-3, 0.75e-3 };
std::vector<T> size = { 5e-4, 5e-4 };
std::unordered_map<int, std::shared_ptr<arch::Node<T>>> nodes;

nodes.try_emplace(5, network.getNode(5));
nodes.try_emplace(7, network.getNode(7));
nodes.try_emplace(8, network.getNode(8));
nodes.try_emplace(9, network.getNode(9));

auto m0 = network.addModule(position, size, nodes);

// fluids
auto fluid0 = testSimulation.addFluid(1e-3, 1e3, 1.0);
//--- continuousPhase ---
testSimulation.setContinuousPhase(fluid0->getId());

sim::ResistanceModelPoiseuille<T> resistanceModel = sim::ResistanceModelPoiseuille<T>(testSimulation.getContinuousPhase()->getViscosity());
testSimulation.setResistanceModel(&resistanceModel);

// simulator
std::string name = "Paper1a-cross-0";
std::string stlFile = "../examples/STL/cross.stl";
T charPhysLength = 1e-4;
T charPhysVelocity = 1e-1;
T alpha = 0.1;
T resolution = 20;
T epsilon = 1e-1;
T tau = 0.55;
std::unordered_map<int, std::shared_ptr<arch::Node<T>>> Nodes;
Nodes.try_emplace(5, network.getNode(5));
Nodes.try_emplace(7, network.getNode(7));
Nodes.try_emplace(8, network.getNode(8));
Nodes.try_emplace(9, network.getNode(9));
std::unordered_map<int, arch::Opening<T>> Openings;
Openings.try_emplace(5, arch::Opening<T>(network.getNode(5), std::vector<T>({1.0, 0.0}), 1e-4));
Openings.try_emplace(7, arch::Opening<T>(network.getNode(7), std::vector<T>({0.0, -1.0}), 1e-4));
Openings.try_emplace(8, arch::Opening<T>(network.getNode(8), std::vector<T>({0.0, 1.0}), 1e-4));
Openings.try_emplace(9, arch::Opening<T>(network.getNode(9), std::vector<T>({-1.0, 0.0}), 1e-4));

network.addModule(name, stlFile, position, size, Nodes, Openings, charPhysLength, charPhysVelocity,
alpha, resolution, epsilon, tau);

// fluids
auto fluid0 = testSimulation.addFluid(1e-3, 1e3, 1.0);
//--- continuousPhase ---
testSimulation.setContinuousPhase(fluid0->getId());

sim::ResistanceModelPoiseuille<T> resistanceModel = sim::ResistanceModelPoiseuille<T>(testSimulation.getContinuousPhase()->getViscosity());
testSimulation.setResistanceModel(&resistanceModel);

testSimulation.addLbmSimulator(name, stlFile, network.getModule(m0->getId()), Openings, charPhysLength, charPhysVelocity, alpha, resolution, epsilon, tau);
network.sortGroups();

// pressure pump
Expand All @@ -87,6 +90,7 @@ TEST(Continuous, Case1a) {
network.isNetworkValid();

// Simulate
testSimulation.setNetwork(&network);
testSimulation.simulate();

ASSERT_NEAR(network.getNodes().at(0)->getPressure(), 0, 1e-3);
Expand All @@ -109,6 +113,7 @@ TEST(Continuous, Case1a) {
ASSERT_NEAR(network.getChannels().at(8)->getFlowRate(), 4.69188e-9, 1e-14);

}

#ifdef USE_ESSLBM
TEST(Hybrid, esstest) {

Expand Down

0 comments on commit a7a8281

Please sign in to comment.