Skip to content

Commit

Permalink
WIP: Define 3D OpenLB Continuous Simulator
Browse files Browse the repository at this point in the history
  • Loading branch information
micheltakken committed Aug 26, 2024
1 parent 7d180d3 commit d459461
Show file tree
Hide file tree
Showing 13 changed files with 749 additions and 242 deletions.
8 changes: 4 additions & 4 deletions src/porting/jsonReaders.hh
Original file line number Diff line number Diff line change
Expand Up @@ -269,7 +269,7 @@ void readSimulators(json jsonString, sim::Simulation<T>& simulation, arch::Netwo

if(simulator["Type"] == "LBM")
{
auto simulator = simulation.addLbmSimulator(name, stlFile, network->getModule(moduleId), Openings, charPhysLength,
auto simulator = simulation.addLbmSimulator3D(name, stlFile, network->getModule(moduleId), Openings, charPhysLength,
charPhysVelocity, alpha, resolution, epsilon, tau);
simulator->setVtkFolder(vtkFolder);
}
Expand All @@ -279,7 +279,7 @@ void readSimulators(json jsonString, sim::Simulation<T>& simulation, arch::Netwo
for (auto& [specieId, speciePtr] : simulation.getSpecies()) {
species.try_emplace(specieId, speciePtr.get());
}
auto simulator = simulation.addLbmMixingSimulator(name, stlFile, network->getModule(moduleId), species,
auto simulator = simulation.addLbmMixingSimulator2D(name, stlFile, network->getModule(moduleId), species,
Openings, charPhysLength, charPhysVelocity, alpha, resolution, epsilon, tau);
simulator->setVtkFolder(vtkFolder);
}
Expand All @@ -291,14 +291,14 @@ void readSimulators(json jsonString, sim::Simulation<T>& simulation, arch::Netwo
}
std::string organStlFile = simulator["organStlFile"];
int tissueId = simulator["tissue"];
auto simulator = simulation.addLbmOocSimulator(name, stlFile, tissueId, organStlFile, network->getModule(moduleId), species,
auto simulator = simulation.addLbmOocSimulator2D(name, stlFile, tissueId, organStlFile, network->getModule(moduleId), species,
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, charPhysLength,
auto simulator = simulation.addEssLbmSimulator3D(name, stlFile, network->getModule(moduleId), Openings, charPhysLength,
charPhysVelocity, alpha, resolution, epsilon, tau);
simulator->setVtkFolder(vtkFolder);
#else
Expand Down
32 changes: 24 additions & 8 deletions src/simulation/Simulation.h
Original file line number Diff line number Diff line change
Expand Up @@ -65,16 +65,19 @@ template<typename T>
class Fluid;

template<typename T>
class lbmSimulator;
class lbmSimulator2D;

template<typename T>
class lbmMixingSimulator;
class lbmMixingSimulator2D;

template<typename T>
class lbmOocSimulator;
class lbmOocSimulator2D;

template<typename T>
class essLbmSimulator;
class lbmSimulator3D;

template<typename T>
class essLbmSimulator3D;

template<typename T>
class MembraneModel;
Expand Down Expand Up @@ -310,7 +313,20 @@ class Simulation {
* @param[in] tau Relaxation time of this simulator (0.5 < tau < 2.0).
* @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,
lbmSimulator2D<T>* addLbmSimulator2D(std::string name, std::string stlFile, std::shared_ptr<arch::Module<T>> module, std::unordered_map<int, arch::Opening<T>> openings,
T charPhysLength, T charPhysVelocity, T alpha, T resolution, T epsilon, T tau);

/**
* @brief Adds a new module to the network.
* @param[in] name Name of the module.
* @param[in] stlFile Location of the stl file that gives the geometry of the domain.
* @param[in] module Shared pointer to the module on which this solver acts.
* @param[in] openings Map of openings corresponding to the nodes.
* @param[in] alpha Relaxation parameter for this simulator.
* @param[in] parameters Parameters to set LBM simulation.
* @return Pointer to the newly created module.
*/
lbmSimulator3D<T>* addLbmSimulator3D(std::string name, std::string stlFile, std::shared_ptr<arch::Module<T>> module, std::unordered_map<int, arch::Opening<T>> openings,
T charPhysLength, T charPhysVelocity, T alpha, T resolution, T epsilon, T tau);

/**
Expand All @@ -328,7 +344,7 @@ class Simulation {
* @param[in] tau Relaxation time of this simulator (0.5 < tau < 2.0).
* @return Pointer to the newly created module.
*/
lbmMixingSimulator<T>* addLbmMixingSimulator(std::string name, std::string stlFile, std::shared_ptr<arch::Module<T>> module, std::unordered_map<int, Specie<T>*> species,
lbmMixingSimulator2D<T>* addLbmMixingSimulator2D(std::string name, std::string stlFile, std::shared_ptr<arch::Module<T>> module, std::unordered_map<int, Specie<T>*> species,
std::unordered_map<int, arch::Opening<T>> openings, T charPhysLength, T charPhysVelocity, T alpha, T resolution, T epsilon, T tau);


Expand All @@ -349,7 +365,7 @@ class Simulation {
* @param[in] tau Relaxation time of this simulator (0.5 < tau < 2.0).
* @return Pointer to the newly created module.
*/
lbmOocSimulator<T>* addLbmOocSimulator(std::string name, std::string stlFile, int tissueId, std::string organStlFile, std::shared_ptr<arch::Module<T>> module, std::unordered_map<int, Specie<T>*> species,
lbmOocSimulator2D<T>* addLbmOocSimulator2D(std::string name, std::string stlFile, int tissueId, std::string organStlFile, std::shared_ptr<arch::Module<T>> module, std::unordered_map<int, Specie<T>*> species,
std::unordered_map<int, arch::Opening<T>> openings, T charPhysLength, T charPhysVelocity, T alpha, T resolution, T epsilon, T tau);

/**
Expand All @@ -358,7 +374,7 @@ class Simulation {
* @param[in] module Shared pointer to the module on which this solver acts.
* @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,
essLbmSimulator3D<T>* addEssLbmSimulator3D(std::string name, std::string stlFile, std::shared_ptr<arch::Module<T>> module, std::unordered_map<int, arch::Opening<T>> openings,
T charPhysLength, T charPhysVelocity, T alpha, T resolution, T epsilon, T tau);

/**
Expand Down
34 changes: 26 additions & 8 deletions src/simulation/Simulation.hh
Original file line number Diff line number Diff line change
Expand Up @@ -199,13 +199,13 @@ 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,
lbmSimulator2D<T>* Simulation<T>::addLbmSimulator2D(std::string name, std::string stlFile, std::shared_ptr<arch::Module<T>> module, std::unordered_map<int, arch::Opening<T>> openings,
T charPhysLength, T charPhysVelocity, T alpha, T resolution, T epsilon, T 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);
auto addCfdSimulator = new lbmSimulator2D<T>(id, name, stlFile, module, openings, resistanceModel, charPhysLength, charPhysVelocity, alpha, resolution, epsilon, tau);

// add Simulator
cfdSimulators.try_emplace(id, addCfdSimulator);
Expand All @@ -217,14 +217,32 @@ namespace sim {
}

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

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

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

template<typename T>
lbmMixingSimulator2D<T>* Simulation<T>::addLbmMixingSimulator2D(std::string name, std::string stlFile, std::shared_ptr<arch::Module<T>> module, std::unordered_map<int, Specie<T>*> species,
std::unordered_map<int, arch::Opening<T>> openings, T charPhysLength, T charPhysVelocity, T alpha, T resolution, T epsilon, T tau)
{
std::cout << "Trying to add a mixing simulator" << std::endl;
if (resistanceModel != nullptr) {
// create Simulator
auto id = cfdSimulators.size();
auto addCfdSimulator = new lbmMixingSimulator<T>(id, name, stlFile, module, species, openings, resistanceModel, charPhysLength, charPhysVelocity, alpha, resolution, epsilon, tau);
auto addCfdSimulator = new lbmMixingSimulator2D<T>(id, name, stlFile, module, species, openings, resistanceModel, charPhysLength, charPhysVelocity, alpha, resolution, epsilon, tau);

// add Simulator
cfdSimulators.try_emplace(id, addCfdSimulator);
Expand All @@ -236,13 +254,13 @@ namespace sim {
}

template<typename T>
lbmOocSimulator<T>* Simulation<T>::addLbmOocSimulator(std::string name, std::string stlFile, int tissueId, std::string organStlFile, std::shared_ptr<arch::Module<T>> module, std::unordered_map<int, Specie<T>*> species,
lbmOocSimulator2D<T>* Simulation<T>::addLbmOocSimulator2D(std::string name, std::string stlFile, int tissueId, std::string organStlFile, std::shared_ptr<arch::Module<T>> module, std::unordered_map<int, Specie<T>*> species,
std::unordered_map<int, arch::Opening<T>> openings, T charPhysLength, T charPhysVelocity, T alpha, T resolution, T epsilon, T tau)
{
if (resistanceModel != nullptr) {
// create Simulator
auto id = cfdSimulators.size();
auto addCfdSimulator = new lbmOocSimulator<T>(id, name, stlFile, tissues.at(tissueId), organStlFile, module, species, openings, resistanceModel, charPhysLength, charPhysVelocity, alpha, resolution, epsilon, tau);
auto addCfdSimulator = new lbmOocSimulator2D<T>(id, name, stlFile, tissues.at(tissueId), organStlFile, module, species, openings, resistanceModel, charPhysLength, charPhysVelocity, alpha, resolution, epsilon, tau);

// add Simulator
cfdSimulators.try_emplace(id, addCfdSimulator);
Expand All @@ -254,14 +272,14 @@ namespace sim {
}

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,
essLbmSimulator3D<T>* Simulation<T>::addEssLbmSimulator3D(std::string name, std::string stlFile, std::shared_ptr<arch::Module<T>> module, std::unordered_map<int, arch::Opening<T>> openings,
T charPhysLength, T charPhysVelocity, T alpha, T resolution, T epsilon, T tau)
{
#ifdef USE_ESSLBM
if (resistanceModel != nullptr) {
// create Simulator
auto id = cfdSimulators.size();
auto addCfdSimulator = new essLbmSimulator<T>(id, name, stlFile, module, openings, resistanceModel, charPhysLength, charPhysVelocity, alpha, resolution, epsilon, tau);
auto addCfdSimulator = new essLbmSimulator3D<T>(id, name, stlFile, module, openings, resistanceModel, charPhysLength, charPhysVelocity, alpha, resolution, epsilon, tau);

// add Simulator
cfdSimulators.try_emplace(id, addCfdSimulator);
Expand Down
4 changes: 2 additions & 2 deletions src/simulation/simulators/cfdSimulator.h
Original file line number Diff line number Diff line change
Expand Up @@ -50,10 +50,10 @@ class CFDSimulator {
*/
virtual void executeCoupling() { };

public:

CFDSimulator(int id, std::string name, std::string stlFile, std::shared_ptr<arch::Module<T>> cfdModule, std::unordered_map<int, arch::Opening<T>> openings, T alpha, ResistanceModel<T>* ResistanceModel);

public:

/**
* @brief Get id of the simulator.
* @returns id.
Expand Down
4 changes: 2 additions & 2 deletions src/simulation/simulators/essContinuous.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ namespace sim {
* @brief Class that defines the lbm module which is the interface between the 1D solver and OLB.
*/
template<typename T>
class essLbmSimulator : public CFDSimulator<T> {
class essLbmSimulator3D : public CFDSimulator<T> {
private:
int step = 0; ///< Iteration step of this module.
int stepIter = 1000; ///< Number of iterations for the value tracer.
Expand Down Expand Up @@ -70,7 +70,7 @@ namespace sim {
* @param[in] nodes Map of nodes that are on the boundary of the module.
* @param[in] openings Map of the in-/outlets of the module.
*/
essLbmSimulator(int id_, std::string name_, std::string stlFile_, std::shared_ptr<arch::Module<T>> cfdModule, std::unordered_map<int, arch::Opening<T>> openings_,
essLbmSimulator3D(int id_, std::string name_, std::string stlFile_, std::shared_ptr<arch::Module<T>> cfdModule, std::unordered_map<int, arch::Opening<T>> openings_,
ResistanceModel<T>* resistanceModel, T charPhysLength_, T charPhysVelocity_, T alpha, T resolution_, T epsilon_, T relaxationTime_);
/**
* @brief Initialize an instance of the LBM solver for this module.
Expand Down
22 changes: 11 additions & 11 deletions src/simulation/simulators/essContinuous.hh
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
namespace sim{

template<typename T>
essLbmSimulator<T>::essLbmSimulator(int id_, std::string name_, std::string stlFile_, std::shared_ptr<arch::Module<T>> cfdModule_, std::unordered_map<int, arch::Opening<T>> openings_,
essLbmSimulator3D<T>::essLbmSimulator(int id_, std::string name_, std::string stlFile_, std::shared_ptr<arch::Module<T>> cfdModule_, std::unordered_map<int, arch::Opening<T>> openings_,
ResistanceModel<T>* resistanceModel_, T charPhysLength_, T charPhysVelocity_, T alpha_, T resolution_, T epsilon_, T relaxationTime_) :
CFDSimulator<T>(id_, name_, stlFile_, cfdModule_, openings_, alpha_, resistanceModel_),
charPhysLength(charPhysLength_), charPhysVelocity(charPhysVelocity_), resolution(resolution_),
Expand All @@ -17,14 +17,14 @@ namespace sim{
}

template<typename T>
void essLbmSimulator<T>::setBoundaryValues(int iT)
void essLbmSimulator3D<T>::setBoundaryValues(int iT)
{
setFlowRates(flowRates);
setPressures(pressures);
}

template<typename T>
void essLbmSimulator<T>::storeCfdResults()
void essLbmSimulator3D<T>::storeCfdResults()
{
for(auto& [key,value] : solver_->getPressures())
pressures[key] = value;
Expand All @@ -33,7 +33,7 @@ namespace sim{
}

template<typename T>
void essLbmSimulator<T>::lbmInit(T dynViscosity, T density)
void essLbmSimulator3D<T>::lbmInit(T dynViscosity, T density)
{

std::string work_dir = "/home/michel/Git/mmft-hybrid-simulator/build/";
Expand Down Expand Up @@ -83,14 +83,14 @@ namespace sim{
}

template<typename T>
void essLbmSimulator<T>::solve()
void essLbmSimulator3D<T>::solve()
{
solver_->solve(10, 10, 10);
storeCfdResults();
}

template<typename T>
void essLbmSimulator<T>::setPressures(std::unordered_map<int, T> pressure_)
void essLbmSimulator3D<T>::setPressures(std::unordered_map<int, T> pressure_)
{
std::unordered_map<int, float> interface;
for(auto& [key, value] : pressure_)
Expand All @@ -100,7 +100,7 @@ namespace sim{
}

template<typename T>
void essLbmSimulator<T>::setFlowRates(std::unordered_map<int, T> flowRate_)
void essLbmSimulator3D<T>::setFlowRates(std::unordered_map<int, T> flowRate_)
{
std::unordered_map<int, float> interface;
for(auto& [key, value] : flowRate_)
Expand All @@ -110,24 +110,24 @@ namespace sim{
}

template<typename T>
std::unordered_map<int, T> essLbmSimulator<T>::getPressures() const {
std::unordered_map<int, T> essLbmSimulator3D<T>::getPressures() const {
return pressures;
}


template<typename T>
std::unordered_map<int, T> essLbmSimulator<T>::getFlowRates() const {
std::unordered_map<int, T> essLbmSimulator3D<T>::getFlowRates() const {
return flowRates;
}

template<typename T>
bool essLbmSimulator<T>::hasConverged() const
bool essLbmSimulator3D<T>::hasConverged() const
{
return solver_->hasConverged();
}

template<typename T>
void essLbmSimulator<T>::setVtkFolder(std::string vtkFolder_) {
void essLbmSimulator3D<T>::setVtkFolder(std::string vtkFolder_) {
this->vtkFolder = vtkFolder_;
}

Expand Down
Loading

0 comments on commit d459461

Please sign in to comment.