Skip to content

Commit

Permalink
🚀 Naive Hybrid Update Scheme for mVLSI
Browse files Browse the repository at this point in the history
* Add update scheme definition
* Define 'Naive' update scheme
  • Loading branch information
micheltakken authored Aug 29, 2024
2 parents 3d4ba15 + 576fe69 commit ec84c7c
Show file tree
Hide file tree
Showing 31 changed files with 977 additions and 131 deletions.
7 changes: 7 additions & 0 deletions .github/pull_request_template.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
## This PR updates

(Add description)

## PR Checklist
- [ ] Did you include comments/documentation?
- [ ] Did you include and pass unit tests?
13 changes: 13 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -154,3 +154,16 @@ if(TEST)
target_link_libraries(simulatorTest PUBLIC gtest testLib)
gtest_discover_tests(simulatorTest)
endif()

# create benchmarks
option(BENCHMARK "Configure for building benchmarks")
if(BENCHMARK)
find_package(benchmark REQUIRED)
set(TARGET_NAME simulatorBenchmark)
add_executable(simulatorBenchmark)
target_sources(simulatorBenchmark PUBLIC benchmarks/benchmark.cpp)
target_link_libraries(simulatorBenchmark PUBLIC gtest gtest_main)
target_link_libraries(simulatorBenchmark PUBLIC gtest lbmLib)
target_link_libraries(simulatorBenchmark PUBLIC gtest simLib)
target_link_libraries(simulatorBenchmark PUBLIC benchmark::benchmark)
endif()
5 changes: 5 additions & 0 deletions benchmarks/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
target_sources(${TARGET_NAME} PRIVATE ${SOURCE_LIST})
target_link_libraries(${TARGET_NAME} PUBLIC gtest gtest_main)
target_link_libraries(${TARGET_NAME} PUBLIC nlohmann_json::nlohmann_json)
target_link_libraries(${TARGET_NAME} PUBLIC lbmLib)
target_link_libraries(${TARGET_NAME} PUBLIC simLib)
24 changes: 24 additions & 0 deletions benchmarks/benchmark.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
#include "gtest/gtest.h"
#include "benchmark/benchmark.h"

#include "../src/baseSimulator.h"
#include "../src/baseSimulator.hh"

using T = double;

void BM_simRun(benchmark::State& state) {

std::string file = "../examples/Hybrid/Network4a.JSON";

// Load and set the network from a JSON file
arch::Network<T> network = porting::networkFromJSON<T>(file);

// Load and set the simulation from a JSON file
sim::Simulation<T> testSimulation = porting::simulationFromJSON<T>(file, &network);
for (auto _ : state) {
testSimulation.simulate();
}
}
BENCHMARK(BM_simRun);

BENCHMARK_MAIN();
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
1 change: 1 addition & 0 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ set(HEADER_LIST
# add subdirectories
add_subdirectory(nodalAnalysis)
add_subdirectory(architecture)
add_subdirectory(hybridDynamics)
add_subdirectory(simulation)
add_subdirectory(olbProcessors)
add_subdirectory(porting)
Expand Down
3 changes: 3 additions & 0 deletions src/baseSimulator.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,9 @@

#include "nodalAnalysis/NodalAnalysis.h"

#include "hybridDynamics/Scheme.h"
#include "hybridDynamics/Naive.h"

#include "architecture/Channel.h"
#include "architecture/ChannelPosition.h"
#include "architecture/Edge.h"
Expand Down
3 changes: 3 additions & 0 deletions src/baseSimulator.hh
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@

#include "nodalAnalysis/NodalAnalysis.hh"

#include "hybridDynamics/Scheme.hh"
#include "hybridDynamics/Naive.hh"

#include "architecture/Channel.hh"
#include "architecture/ChannelPosition.hh"
#include "architecture/Edge.hh"
Expand Down
13 changes: 13 additions & 0 deletions src/hybridDynamics/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
set(SOURCE_LIST
Scheme.hh
Naive.hh
)

set(HEADER_LIST
Scheme.h
Naive.h
)

target_sources(${TARGET_NAME} PUBLIC ${SOURCE_LIST} ${HEADER_LIST})
target_include_directories(${TARGET_NAME} PUBLIC ${CMAKE_CURRENT_LIST_DIR})
target_link_libraries(${TARGET_NAME} PUBLIC eigen)
77 changes: 77 additions & 0 deletions src/hybridDynamics/Naive.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
/**
* @file Naive.h
*/

#pragma once

#include <memory>
#include <unordered_map>
#include <vector>

namespace arch {

// Forward declared dependencies
template<typename T>
class Module;

}

namespace mmft{

/**
* @brief The Naive Scheme is an update scheme that sets the relaxation factor of an iterative update scheme to a
* given constant for all nodes.
*/
template<typename T>
class NaiveScheme : public Scheme<T> {

public:
/**
* @brief Constructor of the Naive Scheme with provided constants.
* @param[in] modules The map of modules with boundary nodes upon which this scheme acts.
* @param[in] alpha The relaxation value for the pressure value update.
* @param[in] beta The relaxation value of the flow rate value update.
* @param[in] theta The amount of LBM stream and collide cycles between updates for a module.
*/
NaiveScheme(const std::unordered_map<int, std::shared_ptr<arch::Module<T>>>& modules, T alpha, T beta, int theta);

/**
* @brief Constructor of the Naive Scheme with provided constants.
* @param[in] modules The map of modules with boundary nodes upon which this scheme acts.
* @param[in] alpha The relaxation value for the pressure value update.
* @param[in] beta The relaxation value of the flow rate value update.
* @param[in] theta The amount of LBM stream and collide cycles between updates for a module.
*/
NaiveScheme(const std::shared_ptr<arch::Module<T>> module, T alpha, T beta, int theta);

/**
* @brief Constructor of the Naive Scheme with provided constants.
* @param[in] modules The map of modules with boundary nodes upon which this scheme acts.
* @param[in] alpha The relaxation value for the pressure value update.
* @param[in] beta The relaxation value of the flow rate value update.
* @param[in] theta The amount of LBM stream and collide cycles between updates for a module.
*/
NaiveScheme(const std::shared_ptr<arch::Module<T>> module, std::unordered_map<int, T> alpha, std::unordered_map<int, T> beta, int theta);

/**
* @brief Constructor of the Naive Scheme with provided constants.
* @param[in] nodeIds The Ids of the set of nodes on which this scheme acts
* @param[in] moduleIds The Ids of the set of modules on which this scheme acts.
* @param[in] alpha The relaxation value for the pressure value update.
* @param[in] beta The relaxation value of the flow rate value update.
* @param[in] theta The amount of LBM stream and collide cycles between updates for a module.
*/
NaiveScheme(std::vector<int> nodeIds, std::vector<int> moduleIds, T alpha, T beta, int theta);

/**
* @brief Constructor of the Naive Scheme with provided constants. The ids of the nodes and modules
* are passed in the maps.
* @param[in] alpha The relaxation value for the pressure value update.
* @param[in] beta The relaxation value of the flow rate value update.
* @param[in] theta The amount of LBM stream and collide cycles between updates for a module.
*/
NaiveScheme(std::unordered_map<int, T> alpha, std::unordered_map<int, T> beta, std::unordered_map<int, int> theta);

};

} // namespace mmft
36 changes: 36 additions & 0 deletions src/hybridDynamics/Naive.hh
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
#include "Naive.h"

namespace mmft {

template<typename T>
NaiveScheme<T>::NaiveScheme(const std::unordered_map<int, std::shared_ptr<arch::Module<T>>>& modules, T alpha, T beta, int theta) :
Scheme<T>(modules, alpha, beta, theta) { }

template<typename T>
NaiveScheme<T>::NaiveScheme(const std::shared_ptr<arch::Module<T>> module, T alpha, T beta, int theta) :
Scheme<T>(module, alpha, beta, theta) { }

template<typename T>
NaiveScheme<T>::NaiveScheme(const std::shared_ptr<arch::Module<T>> module, std::unordered_map<int, T> alpha, std::unordered_map<int, T> beta, int theta) :
Scheme<T>(module, alpha, beta, theta) { }

template<typename T>
NaiveScheme<T>::NaiveScheme(std::vector<int> nodeIds, std::vector<int> moduleIds, T alpha, T beta, int theta) :
Scheme<T>()
{
for (auto nodeId : nodeIds) {
this->alpha.try_emplace(nodeId, alpha);
}
for (auto nodeId : nodeIds) {
this->beta.try_emplace(nodeId, beta);
}
for (auto moduleId : moduleIds) {
this->alpha.try_emplace(moduleId, theta);
}
}

template<typename T>
NaiveScheme<T>::NaiveScheme(std::unordered_map<int, T> alpha_, std::unordered_map<int, T> beta_, std::unordered_map<int, int> theta_) :
Scheme<T>(alpha_, beta_, theta_) { }

} // namespace mmft
Loading

0 comments on commit ec84c7c

Please sign in to comment.