Skip to content

Commit

Permalink
Compile and pass tests NaiveScheme
Browse files Browse the repository at this point in the history
  • Loading branch information
micheltakken committed Aug 29, 2024
1 parent 9de100f commit 576fe69
Show file tree
Hide file tree
Showing 7 changed files with 20 additions and 16 deletions.
8 changes: 5 additions & 3 deletions examples/Hybrid/Network1a.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()

Expand Down
6 changes: 4 additions & 2 deletions python/mmft/simulator/bindings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,6 @@ PYBIND11_MODULE(pysimulator, m) {
std::vector<T> widths,
T charPhysLength,
T charPhysVelocity,
T alpha,
T resolution,
T epsilon,
T tau) {
Expand All @@ -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<T> &simulation, int dropletId, T injectionTime, int channelId, T injectionPosition) {
Expand All @@ -126,6 +125,9 @@ PYBIND11_MODULE(pysimulator, m) {
sim::ResistanceModelPoiseuille<T>* resistanceModel = new sim::ResistanceModelPoiseuille<T>(simulation.getContinuousPhase()->getViscosity());
simulation.setResistanceModel(resistanceModel);
})
.def("setNaiveScheme", [](sim::Simulation<T> & simulation, T alpha, T beta, int theta) {
simulation.setNaiveHybridScheme(alpha, beta, theta);
})
.def("simulate", &sim::Simulation<T>::simulate)
.def("print", &sim::Simulation<T>::printResults)
.def("loadSimulation", [](sim::Simulation<T> &simulation, arch::Network<T> &network, std::string file) {
Expand Down
6 changes: 3 additions & 3 deletions src/porting/jsonPorter.hh
Original file line number Diff line number Diff line change
Expand Up @@ -111,25 +111,25 @@ void simulationFromJSON(json jsonString, arch::Network<T>* network_, sim::Simula
readResistanceModel<T>(jsonString, simulation);

if (platform == sim::Platform::Continuous) {
readUpdateScheme(jsonString, simulation);
readSimulators<T>(jsonString, simulation, network_);
readUpdateScheme(jsonString, simulation);
network_->sortGroups();
} else if (platform == sim::Platform::Mixing) {
readMixingModel<T>(jsonString, simulation);
readSpecies<T>(jsonString, simulation);
readMixtures<T>(jsonString, simulation);
readMixtureInjections<T>(jsonString, simulation, activeFixture);
readUpdateScheme(jsonString, simulation);
readSimulators<T>(jsonString, simulation, network_);
readUpdateScheme(jsonString, simulation);
network_->sortGroups();
} else if (platform == sim::Platform::Ooc) {
readMixingModel<T>(jsonString, simulation);
readSpecies<T>(jsonString, simulation);
readMixtures<T>(jsonString, simulation);
readMixtureInjections<T>(jsonString, simulation, activeFixture);
readTissues<T>(jsonString, simulation);
readUpdateScheme(jsonString, simulation);
readSimulators<T>(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.");
Expand Down
6 changes: 3 additions & 3 deletions src/simulation/Simulation.hh
Original file line number Diff line number Diff line change
Expand Up @@ -202,25 +202,25 @@ namespace sim {
std::shared_ptr<mmft::NaiveScheme<T>> Simulation<T>::setNaiveHybridScheme(T alpha, T beta, int theta) {
auto naiveScheme = std::make_shared<mmft::NaiveScheme<T>>(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;
}

template<typename T>
std::shared_ptr<mmft::NaiveScheme<T>> Simulation<T>::setNaiveHybridScheme(int moduleId, T alpha, T beta, int theta) {
auto naiveScheme = std::make_shared<mmft::NaiveScheme<T>>(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<typename T>
std::shared_ptr<mmft::NaiveScheme<T>> Simulation<T>::setNaiveHybridScheme(int moduleId, std::unordered_map<int, T> alpha, std::unordered_map<int, T> beta, int theta) {
auto naiveScheme = std::make_shared<mmft::NaiveScheme<T>>(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;
}

Expand Down
2 changes: 1 addition & 1 deletion src/simulation/simulators/cfdSimulator.h
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ class CFDSimulator {
/**
* @brief Set the update scheme for Abstract-CFD coupling for this simulator.
*/
void setUpdateScheme(std::shared_ptr<mmft::Scheme<T>> updateScheme);
void setUpdateScheme(const std::shared_ptr<mmft::Scheme<T>>& updateScheme);

/**
* @brief Set the path, where vtk output from the simulator should be stored.
Expand Down
2 changes: 1 addition & 1 deletion src/simulation/simulators/cfdSimulator.hh
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ void CFDSimulator<T>::setInitialized(bool initialization_) {
}

template <typename T>
void CFDSimulator<T>::setUpdateScheme(std::shared_ptr<mmft::Scheme<T>> updateScheme_) {
void CFDSimulator<T>::setUpdateScheme(const std::shared_ptr<mmft::Scheme<T>>& updateScheme_) {
this->updateScheme = updateScheme_;
}

Expand Down
6 changes: 3 additions & 3 deletions tests/hybrid/Hybrid.test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ TEST(Hybrid, Case1a) {

// define network
arch::Network<T> network;
testSimulation.setNetwork(&network);

// nodes
auto node0 = network.addNode(0.0, 0.0, true);
Expand Down Expand Up @@ -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;
Expand All @@ -78,7 +78,8 @@ TEST(Hybrid, Case1a) {
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));

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
Expand All @@ -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);
Expand Down

0 comments on commit 576fe69

Please sign in to comment.