Skip to content

Commit

Permalink
Add Bypass and Cloggable Channeltype to jsonReader.hh
Browse files Browse the repository at this point in the history
  • Loading branch information
micheltakken committed Sep 18, 2024
1 parent 056acef commit 658099d
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 0 deletions.
6 changes: 6 additions & 0 deletions src/porting/jsonReaders.hh
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,12 @@ void readChannels(json jsonString, arch::Network<T>& network) {
throw std::invalid_argument("Channel is ill-defined. Please define:\nnode1\nnode2\nheight\nwidth");
}
arch::ChannelType type = arch::ChannelType::NORMAL;
if (channel.contains("bypass") && channel["bypass"]) {
type = arch::ChannelType::BYPASS;
} else if (channel.contains("cloggable") && channel["cloggable"]) {
type = arch::ChannelType::CLOGGABLE;
}

network.addChannel(channel["node1"], channel["node2"], channel["height"], channel["width"], type, channelId);
channelId++;
}
Expand Down
35 changes: 35 additions & 0 deletions tests/abstract/BigDroplet.test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1028,3 +1028,38 @@ TEST(BigDroplet, noSinkTwoDroplets) {
// simulate
testSimulation.simulate();
}

TEST(BigDroplet, ByPass) {
// define network
arch::Network<T> network;
auto node0 = network.addNode(0.0, 0.0, true);
auto node1 = network.addNode(1e-3, 0.0, false);
auto node2 = network.addNode(2e-3, 0.0, false);

// pressure pump (voltage sources)
auto v0 = network.addPressurePump(node1->getId(), node2->getId(), 32.0);

// flowRate pump (current source)
auto i0 = network.addFlowRatePump(node1->getId(), node0->getId(), 20.0);

// channels
auto c1 = network.addChannel(node0->getId(), node1->getId(), 2, arch::ChannelType::NORMAL);
auto c2 = network.addChannel(node1->getId(), node2->getId(), 4, arch::ChannelType::BYPASS);
auto c3 = network.addChannel(node2->getId(), node0->getId(), 8, arch::ChannelType::CLOGGABLE);

ASSERT_EQ(v0->getNodeA(), node1->getId());
ASSERT_EQ(v0->getNodeB(), node2->getId());
ASSERT_EQ(v0->getPressure(), 32.0);
ASSERT_EQ(i0->getNodeA(), node1->getId());
ASSERT_EQ(i0->getNodeB(), node0->getId());
ASSERT_EQ(i0->getFlowRate(), 20.0);
ASSERT_EQ(network.getChannels().at(c1->getId())->getNodeA(), node0->getId());
ASSERT_EQ(network.getChannels().at(c1->getId())->getNodeB(), node1->getId());
ASSERT_EQ(network.getChannels().at(c1->getId())->getChannelType(), arch::ChannelType::NORMAL);
ASSERT_EQ(network.getChannels().at(c2->getId())->getNodeA(), node1->getId());
ASSERT_EQ(network.getChannels().at(c2->getId())->getNodeB(), node2->getId());
ASSERT_EQ(network.getChannels().at(c2->getId())->getChannelType(), arch::ChannelType::BYPASS);
ASSERT_EQ(network.getChannels().at(c3->getId())->getNodeA(), node2->getId());
ASSERT_EQ(network.getChannels().at(c3->getId())->getNodeB(), node0->getId());
ASSERT_EQ(network.getChannels().at(c3->getId())->getChannelType(), arch::ChannelType::CLOGGABLE);
}

0 comments on commit 658099d

Please sign in to comment.