From a7a828141ea1aa1844ea04210f2f088f4d8645d0 Mon Sep 17 00:00:00 2001 From: micheltakken Date: Mon, 3 Jun 2024 16:28:39 +0200 Subject: [PATCH] :heavy_check_mark: Pass Hybrid Test case1a --- src/porting/jsonReaders.hh | 8 +++--- src/simulation/Simulation.h | 4 +-- src/simulation/Simulation.hh | 39 ++++++++++++++------------ tests/hybrid/Hybrid.test.cpp | 53 ++++++++++++++++++++---------------- 4 files changed, 57 insertions(+), 47 deletions(-) diff --git a/src/porting/jsonReaders.hh b/src/porting/jsonReaders.hh index 0a70078..1a89dfb 100644 --- a/src/porting/jsonReaders.hh +++ b/src/porting/jsonReaders.hh @@ -219,15 +219,15 @@ void readSimulators(json jsonString, sim::Simulation& 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."); diff --git a/src/simulation/Simulation.h b/src/simulation/Simulation.h index c8a4340..44b3ff0 100644 --- a/src/simulation/Simulation.h +++ b/src/simulation/Simulation.h @@ -241,7 +241,7 @@ class Simulation { * @return Pointer to the newly created module. */ lbmSimulator* addLbmSimulator(std::string name, std::string stlFile, std::shared_ptr> module, std::unordered_map> openings, - ResistanceModel* 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. @@ -250,7 +250,7 @@ class Simulation { * @param[in] openings Map of openings corresponding to the nodes. */ essLbmSimulator* addEssLbmSimulator(std::string name, std::string stlFile, std::shared_ptr> module, std::unordered_map> openings, - ResistanceModel* 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. diff --git a/src/simulation/Simulation.hh b/src/simulation/Simulation.hh index 2c8dbae..0b9654a 100644 --- a/src/simulation/Simulation.hh +++ b/src/simulation/Simulation.hh @@ -102,34 +102,39 @@ namespace sim { template lbmSimulator* Simulation::addLbmSimulator(std::string name, std::string stlFile, std::shared_ptr> module, std::unordered_map> openings, - ResistanceModel* 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(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(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 essLbmSimulator* Simulation::addEssLbmSimulator(std::string name, std::string stlFile, std::shared_ptr> module, std::unordered_map> openings, - ResistanceModel* 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(id, name, stlFile, openings, charPhysLength, charPhysVelocity, resolution, epsilon, tau); - // create Simulator - auto id = cfdSimulators.size(); - auto addCfdSimulator = new essLbmModule(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 diff --git a/tests/hybrid/Hybrid.test.cpp b/tests/hybrid/Hybrid.test.cpp index 3dba9b8..5e0f9a9 100644 --- a/tests/hybrid/Hybrid.test.cpp +++ b/tests/hybrid/Hybrid.test.cpp @@ -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 position = { 1.75e-3, 0.75e-3 }; std::vector size = { 5e-4, 5e-4 }; + std::unordered_map>> 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 resistanceModel = sim::ResistanceModelPoiseuille(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>> 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> Openings; Openings.try_emplace(5, arch::Opening(network.getNode(5), std::vector({1.0, 0.0}), 1e-4)); Openings.try_emplace(7, arch::Opening(network.getNode(7), std::vector({0.0, -1.0}), 1e-4)); Openings.try_emplace(8, arch::Opening(network.getNode(8), std::vector({0.0, 1.0}), 1e-4)); Openings.try_emplace(9, arch::Opening(network.getNode(9), std::vector({-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 resistanceModel = sim::ResistanceModelPoiseuille(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 @@ -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); @@ -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) {