Commit 1b8365a7 authored by Jan Dinkelbach's avatar Jan Dinkelbach Committed by Markus Mirz
Browse files

add EMT_Line validation example

parent 363e202a
......@@ -31,6 +31,7 @@ set(CIRCUIT_SOURCES
Circuits/DP_Basics_EMT_Sims.cpp
#Circuits/EMT_ResVS_RL_Switch.cpp
Circuits/EMT_VSI.cpp
Circuits/EMT_PiLine.cpp
# Static Phasor examples
Circuits/SP_Circuits.cpp
......
/* Copyright 2017-2020 Institute for Automation of Complex Power Systems,
* EONERC, RWTH Aachen University
* DPsim
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* any later version.
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*********************************************************************************/
#include <DPsim.h>
using namespace DPsim;
using namespace CPS::CIM;
using namespace CPS::EMT;
using namespace CPS::EMT::Ph3;
void simElements() {
Real timeStep = 0.00005;
Real finalTime = 1;
String simName = "EMT_PiLine_Elements";
Logger::setLogDir("logs/"+simName);
// Nodes
auto n1 = SimNode::make("n1", PhaseType::ABC);
auto n2 = SimNode::make("n2", PhaseType::ABC);
auto vn1 = SimNode::make("vn1", PhaseType::ABC);
// Components
auto vs = VoltageSource::make("v_1", Logger::Level::debug);
vs->setParameters(CPS::Math::polar(100000, -PI/2.), 50);
// Parametrization of components
Real resistance = 5;
Real inductance = 0.16;
Real capacitance = 1.0e-6;
Real conductance = 1e-6;
auto res = Resistor::make("R_line", Logger::Level::debug);
res->setParameters(Reader::singlePhaseParameterToThreePhase(resistance));
auto ind = Inductor::make("L_line", Logger::Level::debug);
ind->setParameters(Reader::singlePhaseParameterToThreePhase(inductance));
auto cap1 = Capacitor::make("Cp_1", Logger::Level::debug);
cap1->setParameters(Reader::singlePhaseParameterToThreePhase(capacitance/2.));
auto cap2 = Capacitor::make("Cp_2", Logger::Level::debug);
cap2->setParameters(Reader::singlePhaseParameterToThreePhase(capacitance/2.));
auto con1 = Resistor::make("Gp_1", Logger::Level::debug);
con1->setParameters(Reader::singlePhaseParameterToThreePhase(2./conductance));
auto con2 = Resistor::make("Gp_2", Logger::Level::debug);
con2->setParameters(Reader::singlePhaseParameterToThreePhase(2./conductance));
auto load = Resistor::make("R_load", Logger::Level::debug);
load->setParameters(Reader::singlePhaseParameterToThreePhase(10000));
// Topology
vs->connect({ SimNode::GND, n1 });
res->connect({n1, vn1});
ind->connect({vn1, n2});
cap1->connect({n1, SimNode::GND});
cap2->connect({n2, SimNode::GND});
con1->connect({n1, SimNode::GND});
con2->connect({n2, SimNode::GND});
load->connect({ n2, SimNode::GND });
auto sys = SystemTopology(50,
SystemNodeList{n1, n2, vn1},
SystemComponentList{vs, res, ind, cap1, cap2, con1, con2, load});
//SystemComponentList{vs, res, ind, cap1, cap2, load});
//SystemComponentList{vs, res, ind, load});
// Logging
auto logger = DataLogger::make(simName);
logger->addAttribute("v1", n1->attribute("v"));
logger->addAttribute("v2", n2->attribute("v"));
Simulation sim(simName, Logger::Level::debug);
sim.setSystem(sys);
sim.setDomain(Domain::EMT);
sim.setTimeStep(timeStep);
sim.setFinalTime(finalTime);
sim.addLogger(logger);
sim.run();
}
void simPiLine() {
Real timeStep = 0.00005;
Real finalTime = 1;
String simName = "EMT_PiLine_Component";
Logger::setLogDir("logs/"+simName);
// Nodes
auto n1 = SimNode::make("n1", PhaseType::ABC);
auto n2 = SimNode::make("n2", PhaseType::ABC);
auto vn1 = SimNode::make("vn1", PhaseType::ABC);
// Components
auto vs = VoltageSource::make("v_1", Logger::Level::debug);
vs->setParameters(CPS::Math::polar(100000, -PI/2.), 50);
// Parametrization of components
Real resistance = 5;
Real inductance = 0.16;
Real capacitance = 1.0e-6;
Real conductance = 1e-6;
auto line = PiLine::make("Line", Logger::Level::debug);
line->setParameters(Reader::singlePhaseParameterToThreePhase(resistance), Reader::singlePhaseParameterToThreePhase(inductance), Reader::singlePhaseParameterToThreePhase(capacitance), Reader::singlePhaseParameterToThreePhase(conductance));
auto load = Resistor::make("R_load", Logger::Level::debug);
load->setParameters(Reader::singlePhaseParameterToThreePhase(10000));
// Topology
vs->connect({ SimNode::GND, n1 });
line->connect({ n1, n2 });
load->connect({ n2, SimNode::GND });
auto sys = SystemTopology(50,
SystemNodeList{n1, n2},
SystemComponentList{vs, line, load});
// Logging
auto logger = DataLogger::make(simName);
logger->addAttribute("v1", n1->attribute("v"));
logger->addAttribute("v2", n2->attribute("v"));
Simulation sim(simName, Logger::Level::debug);
sim.setSystem(sys);
sim.setDomain(Domain::EMT);
sim.setTimeStep(timeStep);
sim.setFinalTime(finalTime);
sim.addLogger(logger);
sim.run();
}
int main(int argc, char* argv[]) {
simElements();
simPiLine();
}
......@@ -10,11 +10,11 @@
import matplotlib.pyplot as plt
```
%% Cell type:markdown id: tags:
## PI-Line with RLC elements
## DP PiLine with RLC elements
%% Cell type:code id: tags:
``` python
%%bash
......@@ -42,11 +42,11 @@
#plt.xlim([0,0.02])
```
%% Cell type:markdown id: tags:
## PI-Line model
## DP PiLine composite model
%% Cell type:code id: tags:
``` python
work_dir = 'logs/DP_PiLine_Component/'
......@@ -65,27 +65,98 @@
```
%% Cell type:code id: tags:
``` python
errors = piline_elements_emt['v2_shift'].values - piline_component_emt['v2_shift'].values
plt.plot(piline_elements_emt['v2_shift'].time, errors)
errors_dp = piline_elements_emt['v2_shift'].values - piline_component_emt['v2_shift'].values
plt.plot(piline_elements_emt['v2_shift'].time, errors_dp)
```
%% Cell type:markdown id: tags:
## Assertion of deviation
## Assertion for DP PiLine
%% Cell type:code id: tags:
``` python
assert errors.max() < 1e-3
print(errors_dp.max())
assert errors_dp.max() < 1e-3
```
%% Cell type:markdown id: tags:
## Diakotpics PI-Line
## EMT PiLine with RLC elements
%% Cell type:code id: tags:
``` python
%%bash
TOP=${TOP:-$(git rev-parse --show-toplevel)}
PATH=${TOP}/build/Examples/Cxx
EMT_PiLine
```
%% Cell type:code id: tags:
``` python
work_dir = 'logs/EMT_PiLine_Elements/'
log_name = 'EMT_PiLine_Elements'
print(work_dir + log_name + '.csv')
piline_elements_emt = rt.read_timeseries_dpsim(work_dir + log_name + '.csv')
```
%% Cell type:code id: tags:
``` python
plt.plot(piline_elements_emt['v1_0'].time, piline_elements_emt['v1_0'].values)
plt.plot(piline_elements_emt['v2_0'].time, piline_elements_emt['v2_0'].values)
#plt.xlim([0,0.02])
```
%% Cell type:markdown id: tags:
## EMT PiLine composite model
%% Cell type:code id: tags:
``` python
work_dir = 'logs/EMT_PiLine_Component/'
log_name = 'EMT_PiLine_Component'
print(work_dir + log_name + '.csv')
piline_component_emt = rt.read_timeseries_dpsim(work_dir + log_name + '.csv')
```
%% Cell type:code id: tags:
``` python
plt.plot(piline_component_emt['v1_0'].time, piline_component_emt['v1_0'].values)
plt.plot(piline_component_emt['v2_0'].time, piline_component_emt['v2_0'].values)
#plt.xlim([0,0.02])
```
%% Cell type:code id: tags:
``` python
errors_emt = piline_elements_emt['v2_0'].values - piline_component_emt['v2_0'].values
plt.plot(piline_elements_emt['v2_0'].time, errors_emt)
```
%% Cell type:markdown id: tags:
## Assertion for EMT PiLine
%% Cell type:code id: tags:
``` python
print(errors_emt.max())
assert errors_emt.max() < 1e-3
```
%% Cell type:markdown id: tags:
## Diakoptics PI-Line
%% Cell type:code id: tags:
``` python
work_dir = 'logs/DP_PiLine_Diakoptics/'
......
......@@ -27,6 +27,10 @@ void EMT::Ph3::VoltageSource::setParameters(Complex voltageRef, Real srcFreq) {
attribute<Complex>("V_ref")->set(voltageRef);
attribute<Real>("f_src")->set(srcFreq);
mSLog->info("\nVoltage reference phasor [V]: {:s}"
"\nFrequency [Hz]: {:s}",
Logger::phasorToString(voltageRef),
Logger::realToString(srcFreq));
mParametersSet = true;
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment