From 576fe69275ec278ddfb29bf600d3f44b85586da5 Mon Sep 17 00:00:00 2001 From: michel Date: Thu, 29 Aug 2024 15:54:31 +0200 Subject: [PATCH] Compile and pass tests NaiveScheme --- examples/Hybrid/Network1a.py | 8 +++++--- python/mmft/simulator/bindings.cpp | 6 ++++-- src/porting/jsonPorter.hh | 6 +++--- src/simulation/Simulation.hh | 6 +++--- src/simulation/simulators/cfdSimulator.h | 2 +- src/simulation/simulators/cfdSimulator.hh | 2 +- tests/hybrid/Hybrid.test.cpp | 6 +++--- 7 files changed, 20 insertions(+), 16 deletions(-) diff --git a/examples/Hybrid/Network1a.py b/examples/Hybrid/Network1a.py index 57cdd83..fe751dc 100644 --- a/examples/Hybrid/Network1a.py +++ b/examples/Hybrid/Network1a.py @@ -51,9 +51,11 @@ def hybridContinuous(): simulation.setContinuousPhase(f0) simulation.setPoiseuilleResistanceModel() - simulation.addLbmSimulator("1a", "../STL/cross.stl", m0, [n5, n7, n8, n9], \ - [[1.0, 0.0], [0.0, -1.0], [0.0, 1.0], [-1.0, 0.0]], [1e-4, 1e-4, 1e-4, 1e-4], \ - 1e-4, 1e-1, 0.1, 20, 1e-1, 0.55) + s1 = simulation.addLbmSimulator("1a", "../STL/cross.stl", m0, [n5, n7, n8, n9], \ + [[1.0, 0.0], [0.0, -1.0], [0.0, 1.0], [-1.0, 0.0]], [1e-4, 1e-4, 1e-4, 1e-4], \ + 1e-4, 1e-1, 20, 1e-1, 0.55) + + s1.setNaiveScheme(0.1, 0.5, 10) network.sort() diff --git a/python/mmft/simulator/bindings.cpp b/python/mmft/simulator/bindings.cpp index 4f01cec..dc43371 100644 --- a/python/mmft/simulator/bindings.cpp +++ b/python/mmft/simulator/bindings.cpp @@ -89,7 +89,6 @@ PYBIND11_MODULE(pysimulator, m) { std::vector widths, T charPhysLength, T charPhysVelocity, - T alpha, T resolution, T epsilon, T tau) { @@ -111,7 +110,7 @@ PYBIND11_MODULE(pysimulator, m) { } return simulation.addLbmSimulator( name, stlFile, simulation.getNetwork()->getModule(moduleId), openings, charPhysLength, - charPhysVelocity, alpha, resolution, epsilon, tau)->getId(); + charPhysVelocity, resolution, epsilon, tau)->getId(); }, "Add a LBM simulator to the simulation.") .def("injectDroplet", [](sim::Simulation &simulation, int dropletId, T injectionTime, int channelId, T injectionPosition) { @@ -126,6 +125,9 @@ PYBIND11_MODULE(pysimulator, m) { sim::ResistanceModelPoiseuille* resistanceModel = new sim::ResistanceModelPoiseuille(simulation.getContinuousPhase()->getViscosity()); simulation.setResistanceModel(resistanceModel); }) + .def("setNaiveScheme", [](sim::Simulation & simulation, T alpha, T beta, int theta) { + simulation.setNaiveHybridScheme(alpha, beta, theta); + }) .def("simulate", &sim::Simulation::simulate) .def("print", &sim::Simulation::printResults) .def("loadSimulation", [](sim::Simulation &simulation, arch::Network &network, std::string file) { diff --git a/src/porting/jsonPorter.hh b/src/porting/jsonPorter.hh index 4aac675..96d3cc9 100644 --- a/src/porting/jsonPorter.hh +++ b/src/porting/jsonPorter.hh @@ -111,16 +111,16 @@ void simulationFromJSON(json jsonString, arch::Network* network_, sim::Simula readResistanceModel(jsonString, simulation); if (platform == sim::Platform::Continuous) { - readUpdateScheme(jsonString, simulation); readSimulators(jsonString, simulation, network_); + readUpdateScheme(jsonString, simulation); network_->sortGroups(); } else if (platform == sim::Platform::Mixing) { readMixingModel(jsonString, simulation); readSpecies(jsonString, simulation); readMixtures(jsonString, simulation); readMixtureInjections(jsonString, simulation, activeFixture); - readUpdateScheme(jsonString, simulation); readSimulators(jsonString, simulation, network_); + readUpdateScheme(jsonString, simulation); network_->sortGroups(); } else if (platform == sim::Platform::Ooc) { readMixingModel(jsonString, simulation); @@ -128,8 +128,8 @@ void simulationFromJSON(json jsonString, arch::Network* network_, sim::Simula readMixtures(jsonString, simulation); readMixtureInjections(jsonString, simulation, activeFixture); readTissues(jsonString, simulation); - readUpdateScheme(jsonString, simulation); readSimulators(jsonString, simulation, network_); + readUpdateScheme(jsonString, simulation); network_->sortGroups(); } else if (platform == sim::Platform::BigDroplet) { throw std::invalid_argument("Droplet simulations are currently only supported for Abstract simulations."); diff --git a/src/simulation/Simulation.hh b/src/simulation/Simulation.hh index 8c93928..b22e436 100644 --- a/src/simulation/Simulation.hh +++ b/src/simulation/Simulation.hh @@ -202,8 +202,8 @@ namespace sim { std::shared_ptr> Simulation::setNaiveHybridScheme(T alpha, T beta, int theta) { auto naiveScheme = std::make_shared>(network->getModules(), alpha, beta, theta); for (auto& [key, simulator] : cfdSimulators) { - simulator->setUpdateScheme(naiveScheme); updateSchemes.try_emplace(simulator->getId(), naiveScheme); + simulator->setUpdateScheme(updateSchemes.at(simulator->getId())); } return naiveScheme; } @@ -211,16 +211,16 @@ namespace sim { template std::shared_ptr> Simulation::setNaiveHybridScheme(int moduleId, T alpha, T beta, int theta) { auto naiveScheme = std::make_shared>(network->getModule(moduleId), alpha, beta, theta); - cfdSimulators.at(moduleId)->setUpdateScheme(naiveScheme); updateSchemes.try_emplace(moduleId, naiveScheme); + cfdSimulators.at(moduleId)->setUpdateScheme(updateSchemes.at(moduleId)); return naiveScheme; } template std::shared_ptr> Simulation::setNaiveHybridScheme(int moduleId, std::unordered_map alpha, std::unordered_map beta, int theta) { auto naiveScheme = std::make_shared>(network->getModule(moduleId), alpha, beta, theta); - cfdSimulators.at(moduleId)->setUpdateScheme(naiveScheme); updateSchemes.try_emplace(moduleId, naiveScheme); + cfdSimulators.at(moduleId)->setUpdateScheme(updateSchemes.at(moduleId)); return naiveScheme; } diff --git a/src/simulation/simulators/cfdSimulator.h b/src/simulation/simulators/cfdSimulator.h index 85aada5..fadb0ce 100755 --- a/src/simulation/simulators/cfdSimulator.h +++ b/src/simulation/simulators/cfdSimulator.h @@ -136,7 +136,7 @@ class CFDSimulator { /** * @brief Set the update scheme for Abstract-CFD coupling for this simulator. */ - void setUpdateScheme(std::shared_ptr> updateScheme); + void setUpdateScheme(const std::shared_ptr>& updateScheme); /** * @brief Set the path, where vtk output from the simulator should be stored. diff --git a/src/simulation/simulators/cfdSimulator.hh b/src/simulation/simulators/cfdSimulator.hh index f4d8919..552436d 100755 --- a/src/simulation/simulators/cfdSimulator.hh +++ b/src/simulation/simulators/cfdSimulator.hh @@ -57,7 +57,7 @@ void CFDSimulator::setInitialized(bool initialization_) { } template -void CFDSimulator::setUpdateScheme(std::shared_ptr> updateScheme_) { +void CFDSimulator::setUpdateScheme(const std::shared_ptr>& updateScheme_) { this->updateScheme = updateScheme_; } diff --git a/tests/hybrid/Hybrid.test.cpp b/tests/hybrid/Hybrid.test.cpp index e8fa1ef..652ada1 100644 --- a/tests/hybrid/Hybrid.test.cpp +++ b/tests/hybrid/Hybrid.test.cpp @@ -14,6 +14,7 @@ TEST(Hybrid, Case1a) { // define network arch::Network network; + testSimulation.setNetwork(&network); // nodes auto node0 = network.addNode(0.0, 0.0, true); @@ -68,7 +69,6 @@ TEST(Hybrid, Case1a) { 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; @@ -78,7 +78,8 @@ TEST(Hybrid, Case1a) { 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)); - testSimulation.addLbmSimulator(name, stlFile, network.getModule(m0->getId()), Openings, charPhysLength, charPhysVelocity, alpha, resolution, epsilon, tau); + testSimulation.addLbmSimulator(name, stlFile, network.getModule(m0->getId()), Openings, charPhysLength, charPhysVelocity, resolution, epsilon, tau); + testSimulation.setNaiveHybridScheme(0.1, 0.5, 10); network.sortGroups(); // pressure pump @@ -90,7 +91,6 @@ TEST(Hybrid, Case1a) { network.isNetworkValid(); // Simulate - testSimulation.setNetwork(&network); testSimulation.simulate(); EXPECT_NEAR(network.getNodes().at(0)->getPressure(), 0, 1e-2);