Commit 032986c0 authored by Jan Dinkelbach's avatar Jan Dinkelbach Committed by Markus Mirz
Browse files

enable switching control off for emt3ph vsi and add comparison notebook

parent bcebc1b1
......@@ -25,19 +25,23 @@ int main(int argc, char* argv[]) {
Examples::SGIB::ScenarioConfig scenario;
// Real finalTime = 0.003;
Real finalTime = 2;
Real timeStep = 0.0001;
String simName = "EMT_Slack_PiLine_VSI_with_PF_Init";
Bool pvWithControl = true;
CommandLineArgs args(argc, argv);
if (argc > 1) {
simName = args.name;
timeStep = args.timeStep;
finalTime = args.duration;
pvWithControl = args.options_bool["control"];
}
// ----- POWERFLOW FOR INITIALIZATION -----
Real timeStepPF = finalTime;
Real finalTimePF = finalTime+timeStepPF;
String simNamePF = "EMT_Slack_PiLine_VSI_with_PF_Init_PF";
String simNamePF = simName + "_PF";
Logger::setLogDir("logs/" + simNamePF);
// Components
......@@ -84,7 +88,7 @@ int main(int argc, char* argv[]) {
// ----- DYNAMIC SIMULATION -----
Real timeStepEMT = timeStep;
Real finalTimeEMT = finalTime+timeStepEMT;
String simNameEMT = "EMT_Slack_PiLine_VSI_with_PF_Init_EMT";
String simNameEMT = simName + "_EMT";
Logger::setLogDir("logs/" + simNameEMT);
// Components
......@@ -102,6 +106,7 @@ int main(int argc, char* argv[]) {
pv->setFilterParameters(scenario.Lf, scenario.Cf, scenario.Rf, scenario.Rc);
pv->setTransformerParameters(scenario.systemNominalVoltage, scenario.pvNominalVoltage, scenario.transformerNominalPower, scenario.systemNominalVoltage/scenario.pvNominalVoltage, 0, 0, scenario.transformerInductance, scenario.systemOmega);
pv->setInitialStateValues(scenario.pvNominalActivePower, scenario.pvNominalReactivePower, scenario.phi_dInit, scenario.phi_qInit, scenario.gamma_dInit, scenario.gamma_qInit);
pv->withControl(pvWithControl);
// Topology
extnetEMT->connect({ n1EMT });
......
%% Cell type:markdown id: tags:
# Comparison of Slack-Line-VSI model with control switched on or off
%% Cell type:markdown id: tags:
## EMT simulations with control on and off
%% Cell type:code id: tags:
``` python
%%bash
TOP=${TOP:-$(git rev-parse --show-toplevel)}
PATH=${TOP}/build/Examples/Cxx
TIMESTEP=0.1e-3
DURATION=1
EMT_Slack_PiLine_VSI_with_PF_Init --name="EMT_Slack_PiLine_VSI_with_PF_ControlOn" --option="control=true" --timestep=${TIMESTEP} --duration=${DURATION}
EMT_Slack_PiLine_VSI_with_PF_Init --name="EMT_Slack_PiLine_VSI_with_PF_ControlOff" --option="control=false" --timestep=${TIMESTEP} --duration=${DURATION}
```
%% Cell type:code id: tags:
``` python
from villas.dataprocessing.readtools import *
from villas.dataprocessing.timeseries import *
import matplotlib.pyplot as plt
import re
# %matplotlib widget
```
%% Cell type:markdown id: tags:
## PF results
%% Cell type:code id: tags:
``` python
modelName = 'EMT_Slack_PiLine_VSI_with_PF_ControlOn_PF'
path = 'logs/' + modelName + '/'
dpsim_result_file = path + modelName + '.csv'
ts_dpsim_pf = read_timeseries_csv(dpsim_result_file)
```
%% Cell type:markdown id: tags:
## EMT results with control on
%% Cell type:code id: tags:
``` python
modelName = 'EMT_Slack_PiLine_VSI_with_PF_ControlOn_EMT'
path = 'logs/' + modelName + '/'
dpsim_result_file = path + modelName + '.csv'
ts_dpsim = read_timeseries_csv(dpsim_result_file)
```
%% Cell type:markdown id: tags:
## EMT results with control off
%% Cell type:code id: tags:
``` python
modelName = 'EMT_Slack_PiLine_VSI_with_PF_ControlOff_EMT'
path = 'logs/' + modelName + '/'
dpsim_result_file = path + modelName + '.csv'
PEAK1PH_TO_RMS3PH = np.sqrt(3.0/2.0)
ts_dpsim_no_control = read_timeseries_csv(dpsim_result_file)
```
%% Cell type:markdown id: tags:
## EMT plot of grid quantities
%% Cell type:markdown id: tags:
### Voltages
%% Cell type:code id: tags:
``` python
plt.figure(figsize=(12,6))
ts_of_interest = ['v1_0', 'v2_0']
for ts_name, ts_obj in ts_dpsim_pf.items():
if ts_name+'_0' in ts_of_interest:
plt.plot(ts_obj.time, ts_obj.abs().values, label=ts_name+'_pf')
for ts_name, ts_obj in ts_dpsim.items():
if ts_name in ts_of_interest:
plt.plot(ts_obj.time, PEAK1PH_TO_RMS3PH*ts_obj.values, label=ts_name+'_control_on')
for ts_name, ts_obj in ts_dpsim_no_control.items():
if ts_name in ts_of_interest:
plt.plot(ts_obj.time, PEAK1PH_TO_RMS3PH*ts_obj.values, label=ts_name+'_control_off', linestyle=':')
plt.legend()
plt.show()
```
%% Cell type:markdown id: tags:
### Currents
%% Cell type:code id: tags:
``` python
plt.figure(figsize=(12,6))
ts_of_interest = ['i12_0'] # 'i12_1','i12_2'
for ts_name, ts_obj in ts_dpsim.items():
if ts_name in ts_of_interest:
plt.plot(ts_obj.time, PEAK1PH_TO_RMS3PH*ts_obj.values, label=ts_name+'_control_on')
for ts_name, ts_obj in ts_dpsim_no_control.items():
if ts_name in ts_of_interest:
plt.plot(ts_obj.time, PEAK1PH_TO_RMS3PH*ts_obj.values, label=ts_name+'_control_off', linestyle=':')
plt.legend()
plt.show()
```
%% Cell type:markdown id: tags:
## EMT plot of VSI variables
%% Cell type:markdown id: tags:
### States - Power
%% Cell type:code id: tags:
``` python
plt.figure(figsize=(12,6))
ts_of_interest = ['pv_powerctrl_input_pref', 'pv_powerctrl_input_qref']
for ts_name, ts_obj in ts_dpsim.items():
if ts_name in ts_of_interest:
plt.plot(ts_obj.time, ts_obj.values, label=ts_name)
ts_of_interest = ['pv_powerctrl_state_p', 'pv_powerctrl_state_q']
for ts_name, ts_obj in ts_dpsim.items():
if ts_name in ts_of_interest:
plt.plot(ts_obj.time, ts_obj.values, label=ts_name+'_control_on')
for ts_name, ts_obj in ts_dpsim_no_control.items():
if ts_name in ts_of_interest:
plt.plot(ts_obj.time, ts_obj.values, label=ts_name+'_control_off', linestyle=':')
plt.legend()
plt.show()
```
%% Cell type:markdown id: tags:
### Outputs - Voltage
%% Cell type:code id: tags:
``` python
plt.figure(figsize=(12,6))
ts_of_interest = ['pv_vs_0']
for ts_name, ts_obj in ts_dpsim.items():
if ts_name in ts_of_interest:
plt.plot(ts_obj.time, ts_obj.values, label=ts_name+'_control_on')
for ts_name, ts_obj in ts_dpsim_no_control.items():
if ts_name in ts_of_interest:
plt.plot(ts_obj.time, ts_obj.values, label=ts_name+'_control_off', linestyle=':')
plt.legend()
plt.show()
```
%% Cell type:code id: tags:
``` python
```
......@@ -78,8 +78,10 @@ namespace Ph3 {
/// Voltage as control output after transformation interface
Matrix mVsref = Matrix::Zero(3,1);
/// Boolean for connection transformer usage
/// Flag for connection transformer usage
Bool mWithConnectionTransformer=false;
/// Flag for controller usage
Bool mWithControl=true;
// #### solver ####
///
......@@ -107,6 +109,7 @@ namespace Ph3 {
/// Setter for initial values applied in controllers
void setInitialStateValues(Real pInit, Real qInit,
Real phi_dInit, Real phi_qInit, Real gamma_dInit, Real gamma_qInit);
void withControl(Bool controlOn) { mWithControl = controlOn; };
///
Matrix getParkTransformMatrixPowerInvariant(Real theta);
......
......@@ -60,6 +60,9 @@ EMT::Ph3::AvVoltageSourceInverterDQ::AvVoltageSourceInverterDQ(String uid, Strin
addAttribute<Real>("Irc_q", &mIrcq, Flags::read | Flags::write);
addAttribute<Matrix>("Vsref", &mVsref, Flags::read | Flags::write);
// Sub voltage source
addAttributeRef<Matrix>("Vs", mSubCtrledVoltageSource->attribute<Matrix>("v_intf"), Flags::read | Flags::write);
// PLL
mPLL->setAttributeRef("input_ref", attribute<Real>("Vc_q"));
addAttributeRef<Matrix>("pll_output", mPLL->attribute<Matrix>("output_curr"), Flags::read);
......@@ -188,7 +191,7 @@ void EMT::Ph3::AvVoltageSourceInverterDQ::initializeFromNodesAndTerminals(Real f
mIntfCurrent = intfCurrentComplex.real();
// Initialize controlled source
mSubCtrledVoltageSource->setParameters(mVirtualNodes[0]->initialVoltage());
mSubCtrledVoltageSource->setParameters(mVirtualNodes[0]->initialVoltage(), 50);
// Connect electrical subcomponents
mSubCtrledVoltageSource->connect({ SimNode::GND, mVirtualNodes[0] });
......@@ -392,7 +395,8 @@ void EMT::Ph3::AvVoltageSourceInverterDQ::mnaAddPreStepDependencies(AttributeBas
void EMT::Ph3::AvVoltageSourceInverterDQ::mnaPreStep(Real time, Int timeStepCount) {
// pre-step of subcomponents - controlled source
mSubCtrledVoltageSource->setParameters(PEAK1PH_TO_RMS3PH * mVsref);
if (mWithControl)
mSubCtrledVoltageSource->setParameters(PEAK1PH_TO_RMS3PH * mVsref, -1);
// pre-step of subcomponents - others
for (auto subcomp: mSubComponents)
if (auto mnasubcomp = std::dynamic_pointer_cast<MNAInterface>(subcomp))
......
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