Skip to content

Commit

Permalink
LoadStep example fixed
Browse files Browse the repository at this point in the history
  • Loading branch information
matthiasmees authored and gnakti committed Jun 29, 2023
1 parent d1d7d4b commit 4329479
Show file tree
Hide file tree
Showing 7 changed files with 273 additions and 150 deletions.
2 changes: 1 addition & 1 deletion dpsim-models/src/EMT/EMT_Ph3_VSIVoltageControlDQ.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -369,7 +369,7 @@ void EMT::Ph3::VSIVoltageControlDQ::controlStep(Real time, Int timeStepCount) {
Matrix vcdq, ircdq;
Real theta = mPLL->mOutputPrev->get()(0, 0);
vcdq = parkTransformPowerInvariant(theta, **mVirtualNodes[2]->mVoltage);
ircdq = parkTransformPowerInvariant(theta, - **mSubResistorC->mIntfCurrent);
ircdq = parkTransformPowerInvariant(theta, - **mSubResistorF->mIntfCurrent);
Matrix intfVoltageDQ = parkTransformPowerInvariant(mThetaN, **mIntfVoltage);
Matrix intfCurrentDQ = parkTransformPowerInvariant(mThetaN, **mIntfCurrent);
**mElecActivePower = - 1. * (intfVoltageDQ(0, 0)*intfCurrentDQ(0, 0) + intfVoltageDQ(1, 0)*intfCurrentDQ(1, 0));
Expand Down
4 changes: 2 additions & 2 deletions dpsim-models/src/EMT/EMT_Ph3_VSIVoltageControlVCO.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -359,7 +359,7 @@ void EMT::Ph3::VSIVoltageControlVCO::controlStep(Real time, Int timeStepCount) {
Matrix vcdq, ircdq;
Real theta = mVCO->mOutputPrev->get();
vcdq = parkTransformPowerInvariant(theta, **mVirtualNodes[2]->mVoltage);
ircdq = parkTransformPowerInvariant(theta, - **mSubResistorC->mIntfCurrent);
ircdq = parkTransformPowerInvariant(theta, - **mSubResistorF->mIntfCurrent);
Matrix intfVoltageDQ = parkTransformPowerInvariant(mThetaN, **mIntfVoltage);
Matrix intfCurrentDQ = parkTransformPowerInvariant(mThetaN, **mIntfCurrent);
**mElecActivePower = - 1. * (intfVoltageDQ(0, 0)*intfCurrentDQ(0, 0) + intfVoltageDQ(1, 0)*intfCurrentDQ(1, 0));
Expand Down Expand Up @@ -419,7 +419,7 @@ void EMT::Ph3::VSIVoltageControlVCO::mnaUpdateCurrent(const Matrix& leftvector)
if (mWithConnectionTransformer)
**mIntfCurrent = mConnectionTransformer->mIntfCurrent->get();
else
**mIntfCurrent = mSubResistorC->mIntfCurrent->get();
**mIntfCurrent = mSubResistorF->mIntfCurrent->get();
}

//Voltage update
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ int main(int argc, char* argv[]) {
simPF.addLogger(loggerPF);
simPF.run(); */

/*
// Components Powerflow Init
auto n1PF = SimNode<Complex>::make("n1", PhaseType::Single);
auto n2PF = SimNode<Complex>::make("n2", PhaseType::Single);
Expand All @@ -99,11 +100,11 @@ int main(int argc, char* argv[]) {
Real load2_q=load2_s.imag();
auto load1PF = SP::Ph1::Load::make("Load1", Logger::Level::debug);
load1PF->setParameters(load1_p, load1_q , 400);
load1PF->setParameters(load1_p, load1_q , 0);
load1PF->modifyPowerFlowBusType(PowerflowBusType::PQ);
auto load2PF = SP::Ph1::Load::make("Load1", Logger::Level::debug);
load2PF->setParameters(load2_p, load2_q , 400);
load2PF->setParameters(load2_p, load2_q , 0);
load2PF->modifyPowerFlowBusType(PowerflowBusType::PQ);
auto switch1PF = SP::Ph1::PiLine::make("Switch_1", Logger::Level::debug);
Expand Down Expand Up @@ -133,6 +134,55 @@ int main(int argc, char* argv[]) {
loggerPF->logAttribute("v3", n3PF->attribute("v"));
loggerPF->logAttribute("v4", n4PF->attribute("v"));
// Simulation
Simulation simPF(simNamePF, Logger::Level::debug);
simPF.setSystem(systemPF);
simPF.setTimeStep(timeStepPF);
simPF.setFinalTime(finalTimePF);
simPF.setDomain(Domain::SP);
simPF.setSolverType(Solver::Type::NRP);
simPF.setSolverAndComponentBehaviour(Solver::Behaviour::Initialization);
simPF.doInitFromNodesAndTerminals(false);
simPF.addLogger(loggerPF);
simPF.run();
*/

// Components Powerflow Init
auto n1PF = SimNode<Complex>::make("n1", PhaseType::Single);
auto n2PF = SimNode<Complex>::make("n2", PhaseType::Single);

Complex load1_s=3*std::pow(400, 2)/(Complex(83e-3, 137e-6*2*M_PI*60));
Real load1_p=load1_s.real();
Real load1_q=load1_s.imag();

Complex load2_s=3*std::pow(400, 2)/(Complex(Yazdani.Res2, Yazdani.Ind2*2*M_PI*60 - 1/(2*M_PI*60*Yazdani.Cap2)));
Real load2_p=load2_s.real();
Real load2_q=load2_s.imag();

auto extnetPF = SP::Ph1::NetworkInjection::make("Slack", Logger::Level::debug);
extnetPF->setParameters(400);
extnetPF->setBaseVoltage(400);
extnetPF->modifyPowerFlowBusType(PowerflowBusType::VD);

auto linePF = SP::Ph1::PiLine::make("PiLine", Logger::Level::debug);
linePF->setParameters(0.88e-3, 0, 0);
linePF->setBaseVoltage(400);


// Topology
extnetPF->connect({ n1PF });
linePF->connect({ n1PF, n2PF });

auto systemPF = SystemTopology(60,
SystemNodeList{n1PF, n2PF},
SystemComponentList{linePF, extnetPF});

// Logging
auto loggerPF = DataLogger::make(simNamePF);
loggerPF->logAttribute("v1", n1PF->attribute("v"));
loggerPF->logAttribute("v2", n2PF->attribute("v"));


// Simulation
Simulation simPF(simNamePF, Logger::Level::debug);
simPF.setSystem(systemPF);
Expand Down Expand Up @@ -245,21 +295,22 @@ int main(int argc, char* argv[]) {
auto resOnEMT = EMT::Ph3::Resistor::make("ResOn", Logger::Level::debug);
resOnEMT->setParameters(CPS::Math::singlePhaseParameterToThreePhase(0.88e-3));

/*

auto pv = EMT::Ph3::VSIVoltageControlVCO::make("pv", "pv", Logger::Level::debug, false);
pv->setParameters(Yazdani.OmegaNull, Yazdani.Vdref, Yazdani.Vqref);
pv->setControllerParameters(Yazdani.KpVoltageCtrl, Yazdani.KiVoltageCtrl, Yazdani.KpCurrCtrl, Yazdani.KiCurrCtrl, Yazdani.OmegaNull);
pv->setFilterParameters(Yazdani.Lf, Yazdani.Cf, Yazdani.Rf, Yazdani.Rc);
pv->setInitialStateValues(Yazdani.phi_dInit, Yazdani.phi_qInit, Yazdani.gamma_dInit, Yazdani.gamma_qInit);
pv->withControl(pvWithControl);
*/


/*
auto pv = EMT::Ph3::VSIVoltageControlDQ::make("pv", "pv", Logger::Level::debug, false);
pv->setParameters(Yazdani.OmegaNull, Yazdani.Vdref, Yazdani.Vqref);
pv->setControllerParameters(Yazdani.KpVoltageCtrl, Yazdani.KiVoltageCtrl, Yazdani.KpCurrCtrl, Yazdani.KiCurrCtrl, Yazdani.KpPLL, Yazdani.KiPLL, Yazdani.OmegaCutoff);
pv->setFilterParameters(Yazdani.Lf, Yazdani.Cf, Yazdani.Rf, Yazdani.Rc);
pv->setInitialStateValues(Yazdani.phi_dInit, Yazdani.phi_qInit, Yazdani.gamma_dInit, Yazdani.gamma_qInit);
pv->withControl(pvWithControl);
*/

// Fault Event
Real SwitchOpen = 1e9;
Expand Down Expand Up @@ -303,7 +354,7 @@ int main(int argc, char* argv[]) {
// Logging
auto loggerEMT = DataLogger::make(simNameEMT);
loggerEMT->logAttribute("Spannung_PCC", n1EMT->attribute("v"));
loggerEMT->logAttribute("Spannung_Node_3", n3EMT->attribute("v"));
loggerEMT->logAttribute("Spannung_Node_2", n2EMT->attribute("v"));
loggerEMT->logAttribute("Spannung_Quelle", pv->attribute("Vs"));
loggerEMT->logAttribute("Strom_RLC", pv->attribute("i_intf"));
//loggerEMT->logAttribute("PLL_Phase", pv->attribute("pll_output"));
Expand Down
2 changes: 1 addition & 1 deletion dpsim/examples/cxx/Examples.h
Original file line number Diff line number Diff line change
Expand Up @@ -535,7 +535,7 @@ namespace SGIB {
Real gamma_qInit = 0;

// VSI generated values
Real Vdref = 400; //work with Amplitude (*sqrt(3/2))
Real Vdref = 400 * sqrt(3./2.); //work with Amplitude (*sqrt(3/2))
Real Vqref = 0;
Real systemFrequency = 60;
Real OmegaNull = 2*M_PI*60; //System circular frequency
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,16 @@
"cells": [
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# DP Simulation of topology with slack, line and PQ load"
],
"metadata": {}
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"from villas.dataprocessing.readtools import *\n",
"from villas.dataprocessing.timeseries import *\n",
Expand All @@ -18,20 +20,20 @@
"import re\n",
"\n",
"# %matplotlib widget"
],
"outputs": [],
"metadata": {}
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Simulation"
],
"metadata": {}
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"# Parameters\n",
"V_nom = 20e3\n",
Expand Down Expand Up @@ -149,53 +151,53 @@
"sim_dp.add_logger(logger_dp)\n",
"sim_dp.add_event(load_step_event)\n",
"sim_dp.run()"
],
"outputs": [],
"metadata": {}
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## PF results"
],
"metadata": {}
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"modelName = 'DP_Slack_PiLine_PQLoad_with_PF_Init_PF'\n",
"path = 'logs/' + modelName + '/'\n",
"dpsim_result_file = path + modelName + '.csv'\n",
"\n",
"ts_dpsim_pf = read_timeseries_csv(dpsim_result_file)"
],
"outputs": [],
"metadata": {}
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## DP results"
],
"metadata": {}
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"modelName = 'DP_Slack_PiLine_PQLoad_with_PF_Init_DP'\n",
"path = 'logs/' + modelName + '/'\n",
"dpsim_result_file = path + modelName + '.csv'\n",
"\n",
"ts_dpsim = read_timeseries_csv(dpsim_result_file)"
],
"outputs": [],
"metadata": {}
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"plt.figure(figsize=(12,6))\n",
"for ts_name, ts_obj in ts_dpsim.items():\n",
Expand All @@ -206,13 +208,13 @@
"plt.xlim(4.9, 5.5)\n",
"plt.legend()\n",
"plt.show()"
],
"outputs": [],
"metadata": {}
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"plt.figure(figsize=(12,6))\n",
"for ts_name, ts_obj in ts_dpsim.items():\n",
Expand All @@ -221,13 +223,13 @@
"plt.xlim(4.9, 5.5)\n",
"plt.legend()\n",
"plt.show()"
],
"outputs": [],
"metadata": {}
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"Fs = int(1 / (ts_dpsim['i12'].time[1] - ts_dpsim['i12'].time[0]))\n",
"plt.figure(figsize=(12,6))\n",
Expand All @@ -236,21 +238,19 @@
"plt.xlim(-6,5)\n",
"plt.legend()\n",
"plt.show()"
],
"outputs": [],
"metadata": {}
]
},
{
"cell_type": "code",
"execution_count": null,
"source": [],
"metadata": {},
"outputs": [],
"metadata": {}
"source": []
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3",
"display_name": "Python 3 (ipykernel)",
"language": "python",
"name": "python3"
},
Expand All @@ -264,7 +264,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.8.9"
"version": "3.9.12"
}
},
"nbformat": 4,
Expand Down
Loading

0 comments on commit 4329479

Please sign in to comment.