Commit 0842582e authored by Markus Mirz's avatar Markus Mirz
Browse files

update circuit examples

parent ed3bb4d2
...@@ -23,6 +23,7 @@ set(CIRCUIT_SOURCES ...@@ -23,6 +23,7 @@ set(CIRCUIT_SOURCES
# EMT examples # EMT examples
Circuits/EMT_VS_R1.cpp Circuits/EMT_VS_R1.cpp
Circuits/EMT_VS_RC1.cpp
Circuits/EMT_CS_R1.cpp Circuits/EMT_CS_R1.cpp
Circuits/EMT_VS_RL1.cpp Circuits/EMT_VS_RL1.cpp
Circuits/EMT_CS_R2CL.cpp Circuits/EMT_CS_R2CL.cpp
......
...@@ -26,6 +26,11 @@ using namespace CPS::DP; ...@@ -26,6 +26,11 @@ using namespace CPS::DP;
using namespace CPS::DP::Ph1; using namespace CPS::DP::Ph1;
int main(int argc, char* argv[]) { int main(int argc, char* argv[]) {
// Define simulation scenario
Real timeStep = 0.0001;
Real finalTime = 0.1;
String simName = "DP_CS_R1";
// Nodes // Nodes
auto n1 = Node::make("n1"); auto n1 = Node::make("n1");
...@@ -43,12 +48,14 @@ int main(int argc, char* argv[]) { ...@@ -43,12 +48,14 @@ int main(int argc, char* argv[]) {
// Define system topology // Define system topology
auto sys = SystemTopology(50, SystemNodeList{n1}, SystemComponentList{cs, r1}); auto sys = SystemTopology(50, SystemNodeList{n1}, SystemComponentList{cs, r1});
// Define simulation scenario // Logging
Real timeStep = 0.0001; auto logger = DataLogger::make(simName);
Real finalTime = 0.1; logger->addAttribute("v1", n1->attribute("voltage"));
String simName = "DP_CS_R_1"; logger->addAttribute("i10", r1->attribute("i_intf"));
Simulation sim(simName, sys, timeStep, finalTime); Simulation sim(simName, sys, timeStep, finalTime);
sim.addLogger(logger);
sim.run(); sim.run();
return 0; return 0;
......
...@@ -26,16 +26,26 @@ using namespace CPS::DP; ...@@ -26,16 +26,26 @@ using namespace CPS::DP;
using namespace CPS::DP::Ph1; using namespace CPS::DP::Ph1;
int main(int argc, char* argv[]) { int main(int argc, char* argv[]) {
// Define simulation scenario
Real timeStep = 0.0001;
Real finalTime = 0.1;
String simName = "DP_CS_R2CL";
// Nodes // Nodes
auto n1 = Node::make("n1"); auto n1 = Node::make("n1");
auto n2 = Node::make("n2"); auto n2 = Node::make("n2");
// Components // Components
auto cs = CurrentSource::make("cs"); auto cs = CurrentSource::make("cs");
cs->setParameters(10);
auto r1 = Resistor::make("r_1"); auto r1 = Resistor::make("r_1");
r1->setParameters(1);
auto c1 = Capacitor::make("c_1"); auto c1 = Capacitor::make("c_1");
c1->setParameters(0.001);
auto l1 = Inductor::make("l_1"); auto l1 = Inductor::make("l_1");
l1->setParameters(0.001);
auto r2 = Resistor::make("r_2"); auto r2 = Resistor::make("r_2");
r2->setParameters(1);
// Topology // Topology
cs->connect({ Node::GND, n1 }); cs->connect({ Node::GND, n1 });
...@@ -44,21 +54,18 @@ int main(int argc, char* argv[]) { ...@@ -44,21 +54,18 @@ int main(int argc, char* argv[]) {
l1->connect({ n2, Node::GND }); l1->connect({ n2, Node::GND });
r2->connect({ n2, Node::GND }); r2->connect({ n2, Node::GND });
cs->setParameters(10);
r1->setParameters(1);
c1->setParameters(0.001);
l1->setParameters(0.001);
r2->setParameters(1);
// Define system topology // Define system topology
auto sys = SystemTopology(50, SystemNodeList{n1, n2}, SystemComponentList{cs, r1, c1, l1, r2}); auto sys = SystemTopology(50, SystemNodeList{n1, n2}, SystemComponentList{cs, r1, c1, l1, r2});
// Define simulation scenario // Logging
Real timeStep = 0.0001; auto logger = DataLogger::make(simName);
Real finalTime = 0.1; logger->addAttribute("v1", n1->attribute("voltage"));
String simName = "DP_CS_R2CL"; logger->addAttribute("v2", n2->attribute("voltage"));
logger->addAttribute("i10", l1->attribute("i_intf"));
Simulation sim(simName, sys, timeStep, finalTime); Simulation sim(simName, sys, timeStep, finalTime);
sim.addLogger(logger);
sim.run(); sim.run();
return 0; return 0;
......
...@@ -26,6 +26,11 @@ using namespace CPS::DP; ...@@ -26,6 +26,11 @@ using namespace CPS::DP;
using namespace CPS::DP::Ph1; using namespace CPS::DP::Ph1;
int main(int argc, char* argv[]) { int main(int argc, char* argv[]) {
// Define simulation scenario
Real timeStep = 0.0001;
Real finalTime = 0.1;
String simName = "DP_VS_CS_R4";
// Nodes // Nodes
auto n1 = Node::make("n1"); auto n1 = Node::make("n1");
auto n2 = Node::make("n2"); auto n2 = Node::make("n2");
...@@ -34,33 +39,37 @@ int main(int argc, char* argv[]) { ...@@ -34,33 +39,37 @@ int main(int argc, char* argv[]) {
// Components // Components
auto vs = VoltageSource::make("vs"); auto vs = VoltageSource::make("vs");
vs->setParameters(10); vs->setParameters(10);
vs->connect(Node::List{ Node::GND, n1 });
auto r1 = Resistor::make("r_1"); auto r1 = Resistor::make("r_1");
r1->setParameters(1); r1->setParameters(1);
r1->connect(Node::List{ n1, n2 });
auto r2 = Resistor::make("r_2", Logger::Level::DEBUG); auto r2 = Resistor::make("r_2", Logger::Level::DEBUG);
r2->setParameters(1); r2->setParameters(1);
r2->connect(Node::List{ n2, Node::GND });
auto r3 = Resistor::make("r_3"); auto r3 = Resistor::make("r_3");
r3->setParameters(10); r3->setParameters(10);
r3->connect(Node::List{ n2, n3 });
auto r4 = Resistor::make("r_4"); auto r4 = Resistor::make("r_4");
r4->setParameters(5); r4->setParameters(5);
r4->connect(Node::List{ n3, Node::GND });
auto cs = CurrentSource::make("cs"); auto cs = CurrentSource::make("cs");
cs->setParameters(1); cs->setParameters(1);
cs->connect(Node::List{ Node::GND, n3 });
// Topology
vs->connect(Node::List{ Node::GND, n1 });
r1->connect(Node::List{ n1, n2 });
r2->connect(Node::List{ n2, Node::GND });
r3->connect(Node::List{ n2, n3 });
r4->connect(Node::List{ n3, Node::GND });
cs->connect(Node::List{ Node::GND, n3 });
// Define system topology // Define system topology
auto sys = SystemTopology(50, SystemNodeList{n1, n2, n3}, SystemComponentList{vs, r1, r2, r3, r4, cs}); auto sys = SystemTopology(50, SystemNodeList{n1, n2, n3}, SystemComponentList{vs, r1, r2, r3, r4, cs});
// Define simulation scenario // Logging
Real timeStep = 0.001; auto logger = DataLogger::make(simName);
Real finalTime = 0.1; logger->addAttribute("v1", n1->attribute("voltage"));
String simName = "DP_IdealVS_CS_R4_1a"; logger->addAttribute("v2", n2->attribute("voltage"));
logger->addAttribute("v3", n3->attribute("voltage"));
Simulation sim(simName, sys, timeStep, finalTime); Simulation sim(simName, sys, timeStep, finalTime);
sim.addLogger(logger);
sim.run(); sim.run();
return 0; return 0;
......
...@@ -26,29 +26,33 @@ using namespace CPS::DP; ...@@ -26,29 +26,33 @@ using namespace CPS::DP;
using namespace CPS::DP::Ph1; using namespace CPS::DP::Ph1;
int main(int argc, char* argv[]) { int main(int argc, char* argv[]) {
// Define simulation scenario
Real timeStep = 0.0001;
Real finalTime = 0.1;
String simName = "DP_VS_R1";
// Nodes // Nodes
auto n1 = Node::make("n1"); auto n1 = Node::make("n1");
// Components // Components
auto vs = VoltageSource::make("v_1"); auto vs = VoltageSource::make("v_1");
vs->setParameters(Complex(10, 0));
auto r = Resistor::make("r_1"); auto r = Resistor::make("r_1");
r->setParameters(1);
// Topology // Topology
vs->connect({Node::GND, n1}); vs->connect({Node::GND, n1});
r->connect({n1, Node::GND}); r->connect({n1, Node::GND});
// Parameters
vs->setParameters(Complex(10, 0));
r->setParameters(1);
auto sys = SystemTopology(50, SystemNodeList{n1}, SystemComponentList{vs, r}); auto sys = SystemTopology(50, SystemNodeList{n1}, SystemComponentList{vs, r});
// Define simulation scenario // Logging
Real timeStep = 0.00005; auto logger = DataLogger::make(simName);
Real finalTime = 0.2; logger->addAttribute("v1", n1->attribute("voltage"));
String simName = "DP_IdealVS_R_1";
Simulation sim(simName, sys, timeStep, finalTime); Simulation sim(simName, sys, timeStep, finalTime);
sim.addLogger(logger);
sim.run(); sim.run();
return 0; return 0;
......
...@@ -26,6 +26,11 @@ using namespace CPS::DP; ...@@ -26,6 +26,11 @@ using namespace CPS::DP;
using namespace CPS::DP::Ph1; using namespace CPS::DP::Ph1;
int main(int argc, char* argv[]) { int main(int argc, char* argv[]) {
// Define simulation scenario
Real timeStep = 0.0001;
Real finalTime = 0.1;
String simName = "DP_VS_R2L3";
// Nodes // Nodes
auto n1 = Node::make("n1"); auto n1 = Node::make("n1");
auto n2 = Node::make("n2"); auto n2 = Node::make("n2");
...@@ -35,31 +40,27 @@ int main(int argc, char* argv[]) { ...@@ -35,31 +40,27 @@ int main(int argc, char* argv[]) {
// Components // Components
auto vs = VoltageSource::make("vs"); auto vs = VoltageSource::make("vs");
vs->setParameters(10); vs->setParameters(10);
vs->connect(Node::List{ Node::GND, n1 });
auto r1 = Resistor::make("r_1"); auto r1 = Resistor::make("r_1");
r1->setParameters(1); r1->setParameters(1);
r1->connect(Node::List{ n1, n2 });
auto l1 = Inductor::make("l_1"); auto l1 = Inductor::make("l_1");
l1->setParameters(0.02); l1->setParameters(0.02);
l1->connect(Node::List{ n2, n3 });
auto l2 = Inductor::make("l_2"); auto l2 = Inductor::make("l_2");
l2->setParameters(0.1); l2->setParameters(0.1);
l2->connect(Node::List{ n3, Node::GND });
auto l3 = Inductor::make("l_3"); auto l3 = Inductor::make("l_3");
l3->setParameters(0.05); l3->setParameters(0.05);
l3->connect(Node::List{ n3, n4 });
auto r2 = Resistor::make("r_2"); auto r2 = Resistor::make("r_2");
r2->setParameters(2); r2->setParameters(2);
// Topology
vs->connect(Node::List{ Node::GND, n1 });
r1->connect(Node::List{ n1, n2 });
l1->connect(Node::List{ n2, n3 });
l2->connect(Node::List{ n3, Node::GND });
l3->connect(Node::List{ n3, n4 });
r2->connect(Node::List{ n4, Node::GND }); r2->connect(Node::List{ n4, Node::GND });
// Define system topology
auto sys = SystemTopology(50, SystemNodeList{n1, n2, n3, n4}, SystemComponentList{vs, r1, l1, l2, l3, r2}); auto sys = SystemTopology(50, SystemNodeList{n1, n2, n3, n4}, SystemComponentList{vs, r1, l1, l2, l3, r2});
// Define simulation scenario
Real timeStep = 0.0001;
Real finalTime = 0.1;
String simName = "DP_IdealVS_R2L3";
// Logging // Logging
auto logger = DataLogger::make(simName); auto logger = DataLogger::make(simName);
logger->addAttribute("v1", n1->attribute("voltage")); logger->addAttribute("v1", n1->attribute("voltage"));
......
...@@ -26,37 +26,35 @@ using namespace CPS::DP; ...@@ -26,37 +26,35 @@ using namespace CPS::DP;
using namespace CPS::DP::Ph1; using namespace CPS::DP::Ph1;
int main(int argc, char* argv[]) { int main(int argc, char* argv[]) {
// Define simulation scenario
Real timeStep = 0.0001;
Real finalTime = 0.1;
String simName = "DP_VS_RC1";
// Nodes // Nodes
auto n1 = Node::make("n1"); auto n1 = Node::make("n1");
auto n2 = Node::make("n2"); auto n2 = Node::make("n2");
// Components // Components
auto vs = VoltageSource::make("vs", Logger::Level::DEBUG); auto vs = VoltageSource::make("vs", Logger::Level::DEBUG);
vs->setParameters(Complex(10, 0));
auto r1 = Resistor::make("r_1", Logger::Level::DEBUG); auto r1 = Resistor::make("r_1", Logger::Level::DEBUG);
r1->setParameters(1);
auto c1 = Capacitor::make("c_1", Logger::Level::DEBUG); auto c1 = Capacitor::make("c_1", Logger::Level::DEBUG);
c1->setParameters(0.001);
// Topology // Topology
vs->connect({ Node::GND, n1 }); vs->connect({ Node::GND, n1 });
r1->connect({ n1, n2 }); r1->connect({ n1, n2 });
c1->connect({ n2, Node::GND }); c1->connect({ n2, Node::GND });
vs->setParameters(Complex(10, 0));
r1->setParameters(1);
c1->setParameters(0.001);
// Define system topology
auto sys = SystemTopology(50, SystemNodeList{n1, n2}, SystemComponentList{vs, r1, c1}); auto sys = SystemTopology(50, SystemNodeList{n1, n2}, SystemComponentList{vs, r1, c1});
// Define simulation scenario
Real timeStep = 0.0001;
Real finalTime = 0.1;
String simName = "DP_IdealVS_RC1";
// Logging // Logging
auto logger = DataLogger::make(simName); auto logger = DataLogger::make(simName);
logger->addAttribute("v1", n1->attribute("voltage")); logger->addAttribute("v1", n1->attribute("voltage"));
logger->addAttribute("v2", n2->attribute("voltage")); logger->addAttribute("v2", n2->attribute("voltage"));
logger->addAttribute("i1", r1->attribute("i_comp")); logger->addAttribute("i1", r1->attribute("i_intf"));
Simulation sim(simName, sys, timeStep, finalTime); Simulation sim(simName, sys, timeStep, finalTime);
sim.addLogger(logger); sim.addLogger(logger);
......
...@@ -26,6 +26,11 @@ using namespace CPS::DP; ...@@ -26,6 +26,11 @@ using namespace CPS::DP;
using namespace CPS::DP::Ph1; using namespace CPS::DP::Ph1;
int main(int argc, char* argv[]) { int main(int argc, char* argv[]) {
// Define simulation scenario
Real timeStep = 0.0001;
Real finalTime = 0.1;
String simName = "DP_VS_RL1";
// Nodes // Nodes
auto n1 = Node::make("n1"); auto n1 = Node::make("n1");
auto n2 = Node::make("n2"); auto n2 = Node::make("n2");
...@@ -46,16 +51,11 @@ int main(int argc, char* argv[]) { ...@@ -46,16 +51,11 @@ int main(int argc, char* argv[]) {
// Define system topology // Define system topology
auto sys = SystemTopology(50, SystemNodeList{n1, n2}, SystemComponentList{vs, r1, l1}); auto sys = SystemTopology(50, SystemNodeList{n1, n2}, SystemComponentList{vs, r1, l1});
// Define simulation scenario
Real timeStep = 0.0001;
Real finalTime = 0.1;
String simName = "DP_IdealVS_RL1";
// Logger // Logger
auto logger = DataLogger::make(simName); auto logger = DataLogger::make(simName);
logger->addAttribute("v1", n1->attribute("voltage")); logger->addAttribute("v1", n1->attribute("voltage"));
logger->addAttribute("v2", n2->attribute("voltage")); logger->addAttribute("v2", n2->attribute("voltage"));
logger->addAttribute("i1", r1->attribute("i_comp")); logger->addAttribute("i1", r1->attribute("i_intf"));
Simulation sim(simName, sys, timeStep, finalTime); Simulation sim(simName, sys, timeStep, finalTime);
sim.addLogger(logger); sim.addLogger(logger);
......
...@@ -26,6 +26,11 @@ using namespace CPS::EMT; ...@@ -26,6 +26,11 @@ using namespace CPS::EMT;
using namespace CPS::EMT::Ph1; using namespace CPS::EMT::Ph1;
int main(int argc, char* argv[]) { int main(int argc, char* argv[]) {
// Define simulation scenario
Real timeStep = 0.0001;
Real finalTime = 0.1;
String simName = "EMT_CS_R_1";
// Nodes // Nodes
auto n1 = Node::make("n1"); auto n1 = Node::make("n1");
...@@ -40,12 +45,13 @@ int main(int argc, char* argv[]) { ...@@ -40,12 +45,13 @@ int main(int argc, char* argv[]) {
// Define system topology // Define system topology
auto sys = SystemTopology(50, SystemNodeList{n1}, SystemComponentList{cs, r1}); auto sys = SystemTopology(50, SystemNodeList{n1}, SystemComponentList{cs, r1});
// Define simulation scenario // Logging
Real timeStep = 0.0001; auto logger = DataLogger::make(simName);
Real finalTime = 0.1; logger->addAttribute("v1", n1->attribute("voltage"));
String simName = "EMT_CS_R_1";
Simulation sim(simName, sys, timeStep, finalTime, Domain::EMT); Simulation sim(simName, sys, timeStep, finalTime, Domain::EMT);
sim.addLogger(logger);
sim.run(); sim.run();
return 0; return 0;
......
...@@ -26,6 +26,11 @@ using namespace CPS::EMT; ...@@ -26,6 +26,11 @@ using namespace CPS::EMT;
using namespace CPS::EMT::Ph1; using namespace CPS::EMT::Ph1;
int main(int argc, char* argv[]) { int main(int argc, char* argv[]) {
// Define simulation scenario
Real timeStep = 0.0001;
Real finalTime = 0.1;
String simName = "EMT_CS_R2CL";
// Nodes // Nodes
auto n1 = Node::make("n1"); auto n1 = Node::make("n1");
auto n2 = Node::make("n2"); auto n2 = Node::make("n2");
...@@ -50,12 +55,14 @@ int main(int argc, char* argv[]) { ...@@ -50,12 +55,14 @@ int main(int argc, char* argv[]) {
// Define system topology // Define system topology
auto sys = SystemTopology(50, SystemNodeList{n1, n2}, SystemComponentList{cs, r1, c1, l1, r2}); auto sys = SystemTopology(50, SystemNodeList{n1, n2}, SystemComponentList{cs, r1, c1, l1, r2});
// Define simulation scenario // Logging
Real timeStep = 0.0001; auto logger = DataLogger::make(simName);
Real finalTime = 0.1; logger->addAttribute("v1", n1->attribute("voltage"));
String simName = "EMT_CS_R2CL"; logger->addAttribute("v2", n2->attribute("voltage"));
Simulation sim(simName, sys, timeStep, finalTime, Domain::EMT); Simulation sim(simName, sys, timeStep, finalTime, Domain::EMT);
sim.addLogger(logger);
sim.run(); sim.run();
return 0; return 0;
......
...@@ -26,6 +26,11 @@ using namespace CPS::EMT; ...@@ -26,6 +26,11 @@ using namespace CPS::EMT;
using namespace CPS::EMT::Ph1; using namespace CPS::EMT::Ph1;
int main(int argc, char* argv[]) { int main(int argc, char* argv[]) {
// Define simulation scenario
Real timeStep = 0.0001;
Real finalTime = 0.1;
String simName = "EMT_VS_CS_R4_AC";
// Nodes // Nodes
auto n1 = Node::make("n1"); auto n1 = Node::make("n1");
auto n2 = Node::make("n2"); auto n2 = Node::make("n2");
...@@ -33,33 +38,38 @@ int main(int argc, char* argv[]) { ...@@ -33,33 +38,38 @@ int main(int argc, char* argv[]) {
// Components // Components
auto vs = VoltageSource::make("vs"); auto vs = VoltageSource::make("vs");
vs->setParameters(10, 50); // 10 * Complex(cos(phi), sin(phi)) vs->setParameters(10, 50);
vs->connect(Node::List{ Node::GND, n1 });
auto r1 = Resistor::make("r_1"); auto r1 = Resistor::make("r_1");
r1->setParameters(1); r1->setParameters(1);
r1->connect(Node::List{ n1, n2 });
auto r2 = Resistor::make("r_2"); auto r2 = Resistor::make("r_2");
r2->setParameters(1); r2->setParameters(1);
r2->connect(Node::List{ n2, Node::GND });
auto r3 = Resistor::make("r_3"); auto r3 = Resistor::make("r_3");
r3->setParameters(10); r3->setParameters(10);
r3->connect(Node::List{ n2, n3 });
auto r4 = Resistor::make("r_4"); auto r4 = Resistor::make("r_4");
r4->setParameters(5); r4->setParameters(5);
r4->connect(Node::List{ n3, Node::GND });
auto cs = CurrentSource::make("cs");