Skip to content

Commit

Permalink
Add test circuits for newly implemented three-phase SSN models of ind…
Browse files Browse the repository at this point in the history
…uctor, capacitor and serial RLC circuit

+ add "EMT_Ph3_R3C1L1CS1_RC_vs_SSN.cpp" which contains a linear circuit implemented using resistive companion component models in one simulation and the new SSN component models in another simulation for comparison
+ add "EMT_Ph3_RLC1VS1_RC_vs_SSN.cpp" which contains a linear RLC circuit implemented using resistive compantion component models in one simulation and the new SSN component model in another simulation for comparison
+ add "EMT_Ph3_compare_RC_SSN.ipynb". This notebook simulates the circuits in the files mentioned above to show, compare and assert the results (SSN against RC)

* adjust "dpsim/examples/cxx/CMakeLists.txt" to include "EMT_Ph3_R3C1L1CS1_RC_vs_SSN.cpp" and "EMT_Ph3_RLC1VS1_RC_vs_SSN.cpp"

Signed-off-by: Marvin Tollnitsch <marvin.tollnitsch@rwth-aachen.de>
  • Loading branch information
MarvinTollnitschRWTH committed Sep 28, 2024
1 parent 1444d94 commit 69d09c9
Show file tree
Hide file tree
Showing 4 changed files with 506 additions and 0 deletions.
4 changes: 4 additions & 0 deletions dpsim/examples/cxx/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@ set(CIRCUIT_SOURCES
#Circuits/EMT_ResVS_RL_Switch.cpp
Circuits/EMT_VSI.cpp
Circuits/EMT_PiLine.cpp
Circuits/EMT_Ph3_R3C1L1CS1_RC_vs_SSN.cpp
Circuits/EMT_Ph3_RLC1VS1_RC_vs_SSN.cpp

# EMT examples with PF initialization
Circuits/EMT_Slack_PiLine_PQLoad_with_PF_Init.cpp
Expand Down Expand Up @@ -132,6 +134,8 @@ list(APPEND TEST_SOURCES
Circuits/EMT_DP_SP_Slack_PiLine_PQLoad_FrequencyRamp_CosineFM.cpp
Circuits/DP_SMIB_ReducedOrderSG_LoadStep.cpp
Circuits/DP_SMIB_ReducedOrderSGIterative_LoadStep.cpp
Circuits/EMT_Ph3_LinearSampleCircuit.cpp
Circuits/EMT_Ph3_LinearSampleCircuitSSN.cpp
)

if(WITH_SUNDIALS)
Expand Down
143 changes: 143 additions & 0 deletions dpsim/examples/cxx/Circuits/EMT_Ph3_R3C1L1CS1_RC_vs_SSN.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,143 @@
#include <DPsim.h>

using namespace DPsim;
using namespace CPS::EMT;

void EMT_PH3_R3_C1_L1_CS1() {
// Define simulation scenario
Real timeStep = 0.0001;
Real finalTime = 0.1;
String simNameRC = "EMT_Ph3_R3C1L1CS1_RC_vs_SSN_RC";

// Nodes
auto n1 = SimNode::make("n1", PhaseType::ABC);
auto n2 = SimNode::make("n2", PhaseType::ABC);

// Components

Matrix param = Matrix::Zero(3, 3);
param << 1., 0, 0, 0, 1., 0, 0, 0, 1.;

auto cs0 = Ph3::CurrentSource::make("CS0");
cs0->setParameters(
CPS::Math::singlePhaseVariableToThreePhase(CPS::Math::polar(1.0, 0.0)),
50.0);

auto r1 = Ph3::Resistor::make("R1");
r1->setParameters(10 * param);

auto r2 = Ph3::Resistor::make("R2");
r2->setParameters(param);

auto r3 = Ph3::Resistor::make("R3");
r3->setParameters(5 * param);

auto l1 = Ph3::Inductor::make("L1");
l1->setParameters(0.02 * param);

auto c1 = Ph3::Capacitor::make("C1");
c1->setParameters(0.001 * param);

// Topology
cs0->connect(SimNode::List{n1, SimNode::GND});

r1->connect(SimNode::List{n2, n1});
r2->connect(SimNode::List{n2, SimNode::GND});
r3->connect(SimNode::List{n2, SimNode::GND});

l1->connect(SimNode::List{n2, SimNode::GND});

c1->connect(SimNode::List{n1, n2});

// Define system topology
auto sys = SystemTopology(50, SystemNodeList{n1, n2},
SystemComponentList{cs0, r1, r2, r3, l1, c1});

// Logging
Logger::setLogDir("logs/" + simNameRC);
auto logger = DataLogger::make(simNameRC);
logger->logAttribute("V1", n1->attribute("v"));
logger->logAttribute("V2", n2->attribute("v"));
logger->logAttribute("V_C1", c1->attribute("v_intf"));
logger->logAttribute("I_L1", l1->attribute("i_intf"));

Simulation sim(simNameRC, Logger::Level::info);
sim.setSystem(sys);
sim.addLogger(logger);
sim.setDomain(Domain::EMT);
sim.setTimeStep(timeStep);
sim.setFinalTime(finalTime);
sim.run();
}

void EMT_PH3_SSN_R3_C1_L1_CS1() {
// Define simulation scenario
Real timeStep = 0.0001;
Real finalTime = 0.1;
String simNameSSN = "EMT_Ph3_R3C1L1CS1_RC_vs_SSN_SSN";
Logger::setLogDir("logs/" + simNameSSN);

// Nodes
auto n1 = CPS::EMT::SimNode::make("n1", PhaseType::ABC);
auto n2 = CPS::EMT::SimNode::make("n2", PhaseType::ABC);

// Components

Matrix param = Matrix::Zero(3, 3);
param << 1., 0, 0, 0, 1., 0, 0, 0, 1.;

auto cs0 = Ph3::CurrentSource::make("CS0");
cs0->setParameters(
CPS::Math::singlePhaseVariableToThreePhase(CPS::Math::polar(1.0, 0.0)),
50.0);

auto r1 = Ph3::Resistor::make("R1", Logger::Level::debug);
r1->setParameters(10 * param);

auto r2 = Ph3::Resistor::make("R2", Logger::Level::debug);
r2->setParameters(param);

auto r3 = Ph3::Resistor::make("R3", Logger::Level::debug);
r3->setParameters(5 * param);

auto l1 = Ph3::SSN::Inductor::make("L1");
l1->setParameters(0.02 * param);

auto c1 = Ph3::SSN::Capacitor::make("C1");
c1->setParameters(0.001 * param);

// Topology
cs0->connect(CPS::EMT::SimNode::List{n1, CPS::EMT::SimNode::GND});

r1->connect(CPS::EMT::SimNode::List{n2, n1});
r2->connect(CPS::EMT::SimNode::List{n2, CPS::EMT::SimNode::GND});
r3->connect(CPS::EMT::SimNode::List{n2, CPS::EMT::SimNode::GND});

l1->connect(CPS::EMT::SimNode::List{n2, CPS::EMT::SimNode::GND});

c1->connect(CPS::EMT::SimNode::List{n1, n2});

// Define system topology
auto sys = SystemTopology(50, SystemNodeList{n1, n2},
SystemComponentList{cs0, r1, r2, r3, l1, c1});

// Logging
auto logger = DataLogger::make(simNameSSN);
logger->logAttribute("V1_SSN", n1->attribute("v"));
logger->logAttribute("V2_SSN", n2->attribute("v"));
logger->logAttribute("V_C1_SSN", c1->attribute("v_intf"));
logger->logAttribute("I_L1_SSN", l1->attribute("i_intf"));

Simulation sim(simNameSSN, Logger::Level::info);
sim.setSystem(sys);
sim.addLogger(logger);
sim.setDomain(Domain::EMT);
sim.setTimeStep(timeStep);
sim.setFinalTime(finalTime);
sim.run();
}

int main(int argc, char *argv[]) {
EMT_PH3_R3_C1_L1_CS1();
EMT_PH3_SSN_R3_C1_L1_CS1();
}
114 changes: 114 additions & 0 deletions dpsim/examples/cxx/Circuits/EMT_Ph3_RLC1VS1_RC_vs_SSN.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,114 @@
#include <DPsim.h>

using namespace DPsim;
using namespace CPS::EMT;

void EMT_Ph3_RLC1_VS1() {
// Define simulation scenario
Real timeStep = 0.0001;
Real finalTime = 0.1;
String simNameRC = "EMT_Ph3_RLC1VS1_RC_vs_SSN_RC";

// Nodes
auto n1 = SimNode::make("n1", PhaseType::ABC);
auto n2 = SimNode::make("n2", PhaseType::ABC);
auto n3 = SimNode::make("n3", PhaseType::ABC);

// Components

Matrix param = Matrix::Zero(3, 3);
param << 1., 0, 0, 0, 1., 0, 0, 0, 1.;

auto vs0 = Ph3::VoltageSource::make("VS0");
vs0->setParameters(
CPS::Math::singlePhaseVariableToThreePhase(CPS::Math::polar(1.0, 0.0)),
50.0);

auto r1 = Ph3::Resistor::make("R1");
r1->setParameters(1. * param);

auto l1 = Ph3::Inductor::make("L1");
l1->setParameters(0.05 * param);

auto c1 = Ph3::Capacitor::make("C1");
c1->setParameters(0.01 * param);

// Topology
vs0->connect(SimNode::List{n1, SimNode::GND});

r1->connect(SimNode::List{n1, n2});

l1->connect(SimNode::List{n2, n3});

c1->connect(SimNode::List{n3, SimNode::GND});

// Define system topology
auto sys = SystemTopology(50, SystemNodeList{n1, n2, n3},
SystemComponentList{vs0, r1, l1, c1});

// Logging
Logger::setLogDir("logs/" + simNameRC);
auto logger = DataLogger::make(simNameRC);
logger->logAttribute("I_R", r1->attribute("i_intf"));
logger->logAttribute("V1_RC", n1->attribute("v"));

Simulation sim(simNameRC, Logger::Level::info);
sim.setSystem(sys);
sim.addLogger(logger);
sim.setDomain(Domain::EMT);
sim.setTimeStep(timeStep);
sim.setFinalTime(finalTime);
sim.run();
}

void EMT_Ph3_SSN_RLC1_VS1() {
// Define simulation scenario
Real timeStep = 0.0001;
Real finalTime = 0.1;
String simNameSSN = "EMT_Ph3_RLC1VS1_RC_vs_SSN_SSN";

// Nodes
auto n1 = CPS::EMT::SimNode::make("n1", PhaseType::ABC);

// Components

Matrix param = Matrix::Zero(3, 3);
param << 1., 0, 0, 0, 1., 0, 0, 0, 1.;

auto vs0 = Ph3::VoltageSource::make("VS0");
vs0->setParameters(
CPS::Math::singlePhaseVariableToThreePhase(CPS::Math::polar(1.0, 0.0)),
50.0);

auto rlc = Ph3::SSN::Full_Serial_RLC::make("RLC");
rlc->setParameters(1. * param, 0.05 * param, 0.01 * param);

// Topology
vs0->connect(CPS::EMT::SimNode::List{n1, CPS::EMT::SimNode::GND});

rlc->connect(CPS::EMT::SimNode::List{n1, CPS::EMT::SimNode::GND});

// Define system topology
auto sys =
SystemTopology(50, SystemNodeList{n1}, SystemComponentList{vs0, rlc});

// Logging
Logger::setLogDir("logs/" + simNameSSN);
auto logger = DataLogger::make(simNameSSN);
logger->logAttribute("I_RLC_SSN", rlc->attribute("i_intf"));
logger->logAttribute("V1_SSN", n1->attribute("v"));

Simulation sim(simNameSSN, Logger::Level::info);
sim.setSystem(sys);
sim.addLogger(logger);
sim.setDomain(Domain::EMT);
sim.setSolverType(Solver::Type::MNA);
sim.setTimeStep(timeStep);
sim.setFinalTime(finalTime);
sim.run();
}

int main(int argc, char *argv[]) {
EMT_Ph3_RLC1_VS1();
EMT_Ph3_SSN_RLC1_VS1();
}
Loading

0 comments on commit 69d09c9

Please sign in to comment.