Commit 04703fd9 authored by Jan Dinkelbach's avatar Jan Dinkelbach Committed by Markus Mirz
Browse files

update slack line pqload examples for dp1ph and emt3ph and add comparison notebook

parent 4b34c60a
......@@ -86,7 +86,7 @@ int main(int argc, char** argv){
auto pv = systemEMT.component<CPS::SimPowerComp<Real>>("pv_N11");
Examples::CIGREMV::logPVAttributes(logger, pv);
std::shared_ptr<SwitchEvent3Ph> loadStepEvent = Examples::createEventAddPowerConsumption3Ph("N11", 2-timeStep, 1500.0e3, systemEMT, Domain::EMT);
std::shared_ptr<SwitchEvent3Ph> loadStepEvent = Examples::createEventAddPowerConsumption3Ph("N11", 2-timeStep, 1500.0e3, systemEMT, Domain::EMT, logger);
Simulation sim(simName, systemEMT, timeStep, finalTime, Domain::EMT, Solver::Type::MNA, Logger::Level::debug, true);
sim.addEvent(loadStepEvent);
......
......@@ -23,17 +23,25 @@ using namespace CPS::CIM;
int main(int argc, char* argv[]) {
// Parameters
// Component parameters
Real Vnom = 20e3;
Real pLoadNom = 100e3;
Real qLoadNom = 50e3;
Real lineResistance = 0.05;
Real lineInductance = 0.1;
Real lineCapacitance = 0.1e-6;
// Simulation parameters
Real timeStep = 0.001;
Real finalTime = 2.0;
CommandLineArgs args(argc, argv);
if (argc > 1) {
timeStep = args.timeStep;
finalTime = args.duration;
}
// ----- POWERFLOW FOR INITIALIZATION -----
Real timeStepPF = 2.0;
Real timeStepPF = finalTime;
Real finalTimePF = finalTime+timeStepPF;
String simNamePF = "DP_Slack_PiLine_PQLoad_with_PF_Init_PF";
Logger::setLogDir("logs/" + simNamePF);
......@@ -80,7 +88,7 @@ int main(int argc, char* argv[]) {
simPF.run();
// ----- DYNAMIC SIMULATION -----
Real timeStepDP = 0.001;
Real timeStepDP = timeStep;
Real finalTimeDP = finalTime+timeStepDP;
String simNameDP = "DP_Slack_PiLine_PQLoad_with_PF_Init_DP";
Logger::setLogDir("logs/" + simNameDP);
......@@ -115,9 +123,10 @@ int main(int argc, char* argv[]) {
auto loggerDP = DataLogger::make(simNameDP);
loggerDP->addAttribute("v1", n1DP->attribute("v"));
loggerDP->addAttribute("v2", n2DP->attribute("v"));
loggerDP->addAttribute("i12", lineDP->attribute("i_intf"));
// load step sized in absolute terms
std::shared_ptr<SwitchEvent> loadStepEvent = Examples::createEventAddPowerConsumption("n2", 1-timeStepDP, 100e3, systemDP, Domain::DP, loggerDP);
std::shared_ptr<SwitchEvent> loadStepEvent = Examples::createEventAddPowerConsumption("n2", 0.1-timeStepDP, 100e3, systemDP, Domain::DP, loggerDP);
// Simulation
Simulation sim(simNameDP, Logger::Level::debug);
......
......@@ -30,10 +30,18 @@ int main(int argc, char* argv[]) {
Real lineResistance = 0.05;
Real lineInductance = 0.1;
Real lineCapacitance = 0.1e-6;
// Simulation parameters
Real timeStep = 0.0001;
Real finalTime = 2.0;
CommandLineArgs args(argc, argv);
if (argc > 1) {
timeStep = args.timeStep;
finalTime = args.duration;
}
// ----- POWERFLOW FOR INITIALIZATION -----
Real timeStepPF = 2.0;
Real timeStepPF = finalTime;
Real finalTimePF = finalTime+timeStepPF;
String simNamePF = "EMT_Slack_PiLine_PQLoad_with_PF_Init_PF";
Logger::setLogDir("logs/" + simNamePF);
......@@ -81,7 +89,7 @@ int main(int argc, char* argv[]) {
simPF.run();
// ----- DYNAMIC SIMULATION -----
Real timeStepEMT = 0.0001;
Real timeStepEMT = timeStep;
Real finalTimeEMT = finalTime+timeStepEMT;
String simNameEMT = "EMT_Slack_PiLine_PQLoad_with_PF_Init_EMT";
Logger::setLogDir("logs/" + simNameEMT);
......@@ -117,7 +125,7 @@ int main(int argc, char* argv[]) {
loggerEMT->addAttribute("i12", lineEMT->attribute("i_intf"));
// load step sized in absolute terms
// std::shared_ptr<SwitchEvent> loadStepEvent = Examples::createEventAddPowerConsumption("n2", 1-timeStepEMT, 100e3, systemEMT, Domain::EMT, loggerEMT);
std::shared_ptr<SwitchEvent3Ph> loadStepEvent = Examples::createEventAddPowerConsumption3Ph("n2", 0.1-timeStepEMT, 100e3, systemEMT, Domain::EMT, loggerEMT);
// Simulation
Simulation sim(simNameEMT, Logger::Level::debug);
......@@ -127,7 +135,7 @@ int main(int argc, char* argv[]) {
sim.setDomain(Domain::EMT);
sim.doPowerFlowInit(false);
sim.addLogger(loggerEMT);
// sim.addEvent(loadStepEvent);
sim.addEvent(loadStepEvent);
sim.run();
}
......@@ -216,14 +216,14 @@ namespace CIGREMV {
loadSwitch->open();
system.addComponent(loadSwitch);
system.connectComponentToNodes<Complex>(loadSwitch, { CPS::SimNode<Complex>::GND, connectionNode});
logger->addAttribute("pv_switchedload_i", loadSwitch->attribute("i_intf"));
logger->addAttribute("switchedload_i", loadSwitch->attribute("i_intf"));
return DPsim::SwitchEvent::make(eventTime, loadSwitch, true);
} else {
return nullptr;
}
}
std::shared_ptr<DPsim::SwitchEvent3Ph> createEventAddPowerConsumption3Ph(String nodeName, Real eventTime, Real additionalActivePower, SystemTopology& system, Domain domain) {
std::shared_ptr<DPsim::SwitchEvent3Ph> createEventAddPowerConsumption3Ph(String nodeName, Real eventTime, Real additionalActivePower, SystemTopology& system, Domain domain, DPsim::DataLogger::Ptr logger) {
// TODO: use base classes ph3
if (domain == CPS::Domain::EMT) {
......@@ -234,6 +234,7 @@ namespace CIGREMV {
loadSwitch->openSwitch();
system.addComponent(loadSwitch);
system.connectComponentToNodes<Real>(loadSwitch, { CPS::SimNode<Real>::GND, system.node<CPS::SimNode<Real>>(nodeName) });
logger->addAttribute("switchedload_i", loadSwitch->attribute("i_intf"));
return DPsim::SwitchEvent3Ph::make(eventTime, loadSwitch, true);
} else {
return nullptr;
......
{
"cells": [
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
" %%bash\n",
"TOP=${TOP:-$(git rev-parse --show-toplevel)}\n",
"PATH=${TOP}/build/Examples/Cxx\n",
"\n",
"TIMESTEP=50e-6\n",
"DURATION=0.2\n",
"\n",
"EMT_Slack_PiLine_PQLoad_with_PF_Init --timestep=${TIMESTEP} --duration=${DURATION}\n",
"DP_Slack_PiLine_PQLoad_with_PF_Init --timestep=${TIMESTEP} --duration=${DURATION}"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"from villas.dataprocessing.readtools import *\n",
"from villas.dataprocessing.timeseries import *\n",
"import re\n",
"\n",
"model_name = 'Slack_PiLine_PQLoad_with_PF_Init'\n",
"\n",
"path_DP = 'logs/' + 'DP_' + model_name + '_DP/'\n",
"dpsim_result_file_DP = path_DP + 'DP_' + model_name + '_DP.csv'\n",
"ts_dpsim_DP = read_timeseries_csv(dpsim_result_file_DP)\n",
"\n",
"path_EMT = 'logs/' + 'EMT_' + model_name + '_EMT/'\n",
"dpsim_result_file_EMT = path_EMT + 'EMT_' + model_name + '_EMT.csv'\n",
"ts_dpsim_EMT = read_timeseries_csv(dpsim_result_file_EMT)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Plot voltages"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"import matplotlib.pyplot as plt\n",
"\n",
"%matplotlib widget\n",
"\n",
"plt.figure(figsize=(12,8))\n",
"\n",
"var_names = ['v1','v2']\n",
"for var_name in var_names: \n",
" plt.plot(ts_dpsim_EMT[var_name+'_0'].interpolate(50e-6).time, np.sqrt(3/2)*ts_dpsim_EMT[var_name+'_0'].interpolate(50e-6).values, label='EMT')\n",
" plt.plot(ts_dpsim_DP[var_name].interpolate(50e-6).time, ts_dpsim_DP[var_name].interpolate(50e-6).frequency_shift(50).values, label='DP backshift', linestyle='--')\n",
" \n",
"plt.legend()\n",
"plt.show()"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Plot current"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"var_name = 'i12'\n",
"\n",
"ts_emt_compare = TimeSeries('ts_emt_compare', ts_dpsim_EMT[var_name+'_0'].interpolate(50e-6).time, np.sqrt(3/2)*ts_dpsim_EMT[var_name+'_0'].interpolate(50e-6).values)\n",
"ts_dp_compare = TimeSeries('ts_dp_compare', ts_dpsim_DP[var_name].interpolate(50e-6).time, ts_dpsim_DP[var_name].interpolate(50e-6).frequency_shift(50).values)\n",
"\n",
"plt.figure(figsize=(12,8))\n",
"plt.plot(ts_emt_compare.time, ts_emt_compare.values, label='EMT')\n",
"plt.plot(ts_dp_compare.time, ts_dp_compare.values, label='DP backshift', linestyle='--')\n",
"plt.legend()\n",
"plt.show()"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Calculate difference"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"ts_emt_compare.rmse(ts_emt_compare, ts_dp_compare)"
]
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.7.6"
}
},
"nbformat": 4,
"nbformat_minor": 4
}
%% Cell type:code id: tags:
``` python
%%bash
TOP=${TOP:-$(git rev-parse --show-toplevel)}
PATH=${TOP}/build/Examples/Cxx
TIMESTEP=50e-6
DURATION=0.2
EMT_Slack_PiLine_PQLoad_with_PF_Init --timestep=${TIMESTEP} --duration=${DURATION}
DP_Slack_PiLine_PQLoad_with_PF_Init --timestep=${TIMESTEP} --duration=${DURATION}
```
%% Cell type:code id: tags:
``` python
from villas.dataprocessing.readtools import *
from villas.dataprocessing.timeseries import *
import re
model_name = 'Slack_PiLine_PQLoad_with_PF_Init'
path_DP = 'logs/' + 'DP_' + model_name + '_DP/'
dpsim_result_file_DP = path_DP + 'DP_' + model_name + '_DP.csv'
ts_dpsim_DP = read_timeseries_csv(dpsim_result_file_DP)
path_EMT = 'logs/' + 'EMT_' + model_name + '_EMT/'
dpsim_result_file_EMT = path_EMT + 'EMT_' + model_name + '_EMT.csv'
ts_dpsim_EMT = read_timeseries_csv(dpsim_result_file_EMT)
```
%% Cell type:markdown id: tags:
## Plot voltages
%% Cell type:code id: tags:
``` python
import matplotlib.pyplot as plt
%matplotlib widget
plt.figure(figsize=(12,8))
var_names = ['v1','v2']
for var_name in var_names:
plt.plot(ts_dpsim_EMT[var_name+'_0'].interpolate(50e-6).time, np.sqrt(3/2)*ts_dpsim_EMT[var_name+'_0'].interpolate(50e-6).values, label='EMT')
plt.plot(ts_dpsim_DP[var_name].interpolate(50e-6).time, ts_dpsim_DP[var_name].interpolate(50e-6).frequency_shift(50).values, label='DP backshift', linestyle='--')
plt.legend()
plt.show()
```
%% Cell type:markdown id: tags:
## Plot current
%% Cell type:code id: tags:
``` python
var_name = 'i12'
ts_emt_compare = TimeSeries('ts_emt_compare', ts_dpsim_EMT[var_name+'_0'].interpolate(50e-6).time, np.sqrt(3/2)*ts_dpsim_EMT[var_name+'_0'].interpolate(50e-6).values)
ts_dp_compare = TimeSeries('ts_dp_compare', ts_dpsim_DP[var_name].interpolate(50e-6).time, ts_dpsim_DP[var_name].interpolate(50e-6).frequency_shift(50).values)
plt.figure(figsize=(12,8))
plt.plot(ts_emt_compare.time, ts_emt_compare.values, label='EMT')
plt.plot(ts_dp_compare.time, ts_dp_compare.values, label='DP backshift', linestyle='--')
plt.legend()
plt.show()
```
%% Cell type:markdown id: tags:
## Calculate difference
%% Cell type:code id: tags:
``` python
ts_emt_compare.rmse(ts_emt_compare, ts_dp_compare)
```
Supports Markdown
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