Skip to content

Commit

Permalink
🚧 WIP add 1D mixing feature
Browse files Browse the repository at this point in the history
  • Loading branch information
micheltakken committed Oct 31, 2023
1 parent be134cc commit 68b0715
Show file tree
Hide file tree
Showing 19 changed files with 545 additions and 14 deletions.
4 changes: 4 additions & 0 deletions src/architecture/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,20 +1,24 @@
set(SOURCE_LIST
Channel.hh
ChannelPosition.hh
Edge.hh
FlowRatePump.hh
Network.hh
Node.hh
PressurePump.hh
Pump.hh
)

set(HEADER_LIST
Channel.h
ChannelPosition.h
Edge.h
FlowRatePump.h
Network.h
Node.h
Platform.h
PressurePump.h
Pump.h
)

# add subdirectories
Expand Down
77 changes: 77 additions & 0 deletions src/architecture/ChannelPosition.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
/**
* @file ChannelPosition.h
*/

#pragma once

#include "Channel.h"

namespace arch {

/**
* @brief Class to specify the relative position of a point in a channel.
*/
template<typename T>
class ChannelPosition {
private:
RectangularChannel<T>* channel; ///< Channel in which the point is.
T position; ///< Exact relative position (between 0.0 and 1.0) within the channel.

public:
/**
* @brief Constructor to create the position of the point.
* @param[in] channel Channel in which this point currently is.
* @param[in] position Relative position (between 0.0 and 1.0) of the point in this channel.
*/
ChannelPosition(RectangularChannel<T>* channel, T position);

/**
* @brief Change the channel of the channel position (at which the point currently is).
* @param[in] channel New channel to which the position should be set.
*/
void setChannel(RectangularChannel<T>* const channel);

/**
* @brief Reset relative position.
* @param[in] position Relative position (between 0.0 and 1.0) within a channel.
*/
void setPosition(T position);

/**
* @brief Add the volume shift to the current position.
* @param[in] volumeShift Shift of the volume in flow direction in m^3.
*/
void addToPosition(T volumeShift);

/**
* @brief Returns pointer to channel in which this end of the droplet currently is.
* @return Pointer to channel at which this end of the droplet currently is.
*/
RectangularChannel<T>* getChannel() const;

/**
* @brief Returns relative position within the channel.
* @return Relative position (between 0.0 and 1.0) at which this end of the droplet currently is.
*/
T getPosition() const;

/**
* @brief Returns absolute position within channel in m.
* @return Absolute position in m.
*/
T getAbsolutePosition() const;

/**
* @brief Calculates and returns volume towards node 0.
* @return Volume towards node 0 in m^3.
*/
T getVolume0() const;

/**
* @brief Calculates and returns volume towards node 1.
* @return Volume towards node 1 in m^3.
*/
T getVolume1() const;
};

} // namespace arch
58 changes: 58 additions & 0 deletions src/architecture/ChannelPosition.hh
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
#include "ChannelPosition.h"

#include "Channel.h"

namespace arch {

template<typename T>
ChannelPosition<T>::ChannelPosition(RectangularChannel<T>* channel, T position) : channel(channel), position(position) {}

template<typename T>
void ChannelPosition<T>::setChannel(RectangularChannel<T>* const channel) {
this->channel = channel;
}

template<typename T>
void ChannelPosition<T>::setPosition(T position) {
// ensure that position stays in range (e.g., due to rounding errors)
if (position < 0.0) {
this->position = 0.0;
} else if (position > 1.0) {
this->position = 1.0;
} else {
this->position = position;
}
}

template<typename T>
void ChannelPosition<T>::addToPosition(T volumeShift) {
T newPosition = position + volumeShift / channel->getVolume();
setPosition(newPosition);
}

template<typename T>
RectangularChannel<T>* ChannelPosition<T>::getChannel() const {
return channel;
}

template<typename T>
T ChannelPosition<T>::getPosition() const {
return position;
}

template<typename T>
T ChannelPosition<T>::getAbsolutePosition() const {
return position * channel->getLength();
}

template<typename T>
T ChannelPosition<T>::getVolume0() const {
return position * channel->getVolume();
}

template<typename T>
T ChannelPosition<T>::getVolume1() const {
return (1.0 - position) * channel->getVolume();
}

} // namespace arch
8 changes: 8 additions & 0 deletions src/architecture/Network.h
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ class Network {
std::unordered_map<int, std::unique_ptr<PressurePump<T>>> pressurePumps; ///< Map of ids and channel pointers to pressure pumps in the network.
std::unordered_map<int, std::shared_ptr<CFDModule<T>>> modules; ///< Map of ids and module pointers to modules in the network.
std::unordered_map<int, std::unique_ptr<Group<T>>> groups; ///< Map of ids and pointers to groups that form the (unconnected) 1D parts of the network
std::unordered_map<int, std::vector<RectangularChannel<T>*>> channelsAtNode;///< Map of nodes and corresponding channels at these nodes in the network.
Platform platform = Platform::NONE; ///< The microfluidic platform that operates on this network.

public:
Expand Down Expand Up @@ -197,6 +198,13 @@ class Network {
* @brief Sorts the nodes and channels into detached 1D domain groups
*/
void sortGroups();

/**
* @brief Get a map of all channels at a specific node.
* @param[in] nodeId Id of the node at which the adherent channels should be returned.
* @return Vector of pointers to channels adherent to this node.
*/
const std::vector<RectangularChannel<T>*> getChannelsAtNode(int nodeId) const;
};

} // namespace arch
9 changes: 9 additions & 0 deletions src/architecture/Network.hh
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,15 @@ namespace arch {
return platform;
}

template<typename T>
const std::vector<RectangularChannel<T>*> Network<T>::getChannelsAtNode(int nodeId) const {
try {
return channelsAtNode.at(nodeId);
} catch (const std::out_of_range& e) {
throw std::invalid_argument("Node with ID " + std::to_string(nodeId) + " does not exist.");
}
}

template<typename T>
void Network<T>::setPressurePump(int channelId_, T pressure_) {
int nodeAId = channels.at(channelId_).get()->getNodeA();
Expand Down
42 changes: 42 additions & 0 deletions src/architecture/Pump.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
/**
* @file Pump.h
*/

#pragma once

#include "Edge.h"
#include "Fluid.h"

namespace arch {

/**
* @brief Abstract class to specify a pump, which is a component of a chip.
*
*/
template<typename T>
class Pump : public virtual Edge<T> {
private:
int mixtureId; // Id of the mixture that is pumped through the chip by the pump.

public:
/**
* @brief Construct a new Pump object
*/
Pump();

/**
* @brief Set the mixture that should be pumped through the chip by this pump
*
* @param mixtureId Id of the mixture.
*/
void setMixture(int mixtureId);

/**
* @brief Get the mixture that is pumped through the chip by this pump
*
* @return Id of the mixture.
*/
int getMixtureId();
};

} // namespace arch
18 changes: 18 additions & 0 deletions src/architecture/Pump.hh
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
#include "Pump.h"

namespace arch {

template<typename T>
Pump<T>::Pump() { }

template<typename T>
void Pump<T>::setMixture(int mixtureId) {
this->mixtureId = mixtureId;
}

template<typename T>
int Pump<T>::getMixtureId() {
return mixtureId;
}

} // namespace arch
4 changes: 4 additions & 0 deletions src/baseSimulator.h
Original file line number Diff line number Diff line change
@@ -1,13 +1,16 @@
#include "simulation/BolusInjection.h"
#include "simulation/CFDSim.h"
#include "simulation/Fluid.h"
#include "simulation/MixingModels.h"
#include "simulation/Mixture.h"
#include "simulation/ResistanceModels.h"
#include "simulation/Simulation.h"
#include "simulation/Specie.h"

#include "nodalAnalysis/NodalAnalysis.h"

#include "architecture/Channel.h"
#include "architecture/ChannelPosition.h"
#include "architecture/Edge.h"
#include "architecture/FlowRatePump.h"
#include "architecture/modules/Module.h"
Expand All @@ -18,6 +21,7 @@
#include "architecture/Node.h"
#include "architecture/Platform.h"
#include "architecture/PressurePump.h"
#include "architecture/Pump.h"

#include "postProcessors/navierStokesAdvectionDiffusionCouplingPostProcessor2D.h"
#include "postProcessors/saturatedFluxPostProcessor2D.h"
Expand Down
4 changes: 4 additions & 0 deletions src/baseSimulator.hh
Original file line number Diff line number Diff line change
@@ -1,13 +1,16 @@
#include "simulation/BolusInjection.hh"
#include "simulation/CFDSim.hh"
#include "simulation/Fluid.hh"
#include "simulation/MixingModels.hh"
#include "simulation/Mixture.hh"
#include "simulation/ResistanceModels.hh"
#include "simulation/Simulation.hh"
#include "simulation/Specie.hh"

#include "nodalAnalysis/NodalAnalysis.hh"

#include "architecture/Channel.hh"
#include "architecture/ChannelPosition.hh"
#include "architecture/Edge.hh"
#include "architecture/FlowRatePump.hh"
#include "architecture/modules/Module.hh"
Expand All @@ -17,6 +20,7 @@
#include "architecture/Network.hh"
#include "architecture/Node.hh"
#include "architecture/PressurePump.hh"
#include "architecture/Pump.hh"

#include "postProcessors/navierStokesAdvectionDiffusionCouplingPostProcessor2D.hh"
#include "postProcessors/saturatedFluxPostProcessor2D.hh"
Expand Down
Loading

0 comments on commit 68b0715

Please sign in to comment.