Commit 3230bf59 authored by Markus Mirz's avatar Markus Mirz
Browse files

cleaned generator examples

parent 25ea8a64
__pycache__
*.pyc
*.ipynb_checkpoints
\ No newline at end of file
*.ipynb_checkpoints
.idea
\ No newline at end of file
......@@ -14,14 +14,14 @@
<file leaf-file-name="readtools.py" pinned="false" current-in-tab="false">
<entry file="file://$PROJECT_DIR$/../../../DataProcessing/dataprocessing/readtools.py">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="199">
<state relative-caret-position="408">
<caret line="26" column="50" lean-forward="false" selection-start-line="26" selection-start-column="50" selection-end-line="26" selection-end-column="50" />
<folding />
</state>
</provider>
</entry>
</file>
<file leaf-file-name="SynGen_UnitTest.py" pinned="false" current-in-tab="true">
<file leaf-file-name="SynGen_UnitTest.py" pinned="false" current-in-tab="false">
<entry file="file://$PROJECT_DIR$/SynGen_UnitTest.py">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="357">
......@@ -35,7 +35,7 @@
<entry file="file://$PROJECT_DIR$/../../../DataProcessing/dataprocessing/plottools.py">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="289">
<caret line="19" column="25" lean-forward="true" selection-start-line="19" selection-start-column="25" selection-end-line="19" selection-end-column="25" />
<caret line="19" column="25" lean-forward="false" selection-start-line="19" selection-start-column="25" selection-end-line="19" selection-end-column="25" />
<folding />
</state>
</provider>
......@@ -44,7 +44,7 @@
<file leaf-file-name="plotdpsim.py" pinned="false" current-in-tab="false">
<entry file="file://$PROJECT_DIR$/../../../DataProcessing/dataprocessing/plotdpsim.py">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="-391">
<state relative-caret-position="221">
<caret line="28" column="44" lean-forward="false" selection-start-line="28" selection-start-column="37" selection-end-line="28" selection-end-column="44" />
<folding>
<element signature="e#0#24#0" expanded="true" />
......@@ -53,7 +53,7 @@
</provider>
</entry>
</file>
<file leaf-file-name="plotdpsim_deprecated.py" pinned="false" current-in-tab="false">
<file leaf-file-name="plotdpsim_deprecated.py" pinned="false" current-in-tab="true">
<entry file="file://$PROJECT_DIR$/../../../DataProcessing/dataprocessing/plotdpsim_deprecated.py">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="306">
......@@ -83,7 +83,7 @@
</list>
</option>
</component>
<component name="ProjectFrameBounds" extendedState="6">
<component name="ProjectFrameBounds" extendedState="7">
<option name="x" value="1672" />
<option name="y" value="-8" />
<option name="width" value="1696" />
......@@ -104,7 +104,7 @@
<foldersAlwaysOnTop value="true" />
</navigator>
<panes>
<pane id="Scratches" />
<pane id="Scope" />
<pane id="ProjectPane">
<subPane>
<expand>
......@@ -138,7 +138,7 @@
<select />
</subPane>
</pane>
<pane id="Scope" />
<pane id="Scratches" />
</panes>
</component>
<component name="PropertiesComponent">
......@@ -195,19 +195,19 @@
<servers />
</component>
<component name="ToolWindowManager">
<frame x="1672" y="-8" width="1696" height="1066" extended-state="6" />
<frame x="1672" y="-8" width="1696" height="1066" extended-state="7" />
<editor active="true" />
<layout>
<window_info id="Project" active="false" anchor="left" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="true" show_stripe_button="true" weight="0.24047619" sideWeight="0.5" order="0" side_tool="false" content_ui="combo" />
<window_info id="TODO" active="false" anchor="bottom" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" show_stripe_button="true" weight="0.33" sideWeight="0.5" order="6" side_tool="false" content_ui="tabs" />
<window_info id="Event Log" active="false" anchor="bottom" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" show_stripe_button="true" weight="0.33" sideWeight="0.5" order="7" side_tool="true" content_ui="tabs" />
<window_info id="Run" active="false" anchor="bottom" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="true" show_stripe_button="true" weight="0.3294979" sideWeight="0.5" order="2" side_tool="false" content_ui="tabs" />
<window_info id="Version Control" active="false" anchor="bottom" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" show_stripe_button="false" weight="0.33" sideWeight="0.5" order="7" side_tool="false" content_ui="tabs" />
<window_info id="Python Console" active="false" anchor="bottom" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" show_stripe_button="true" weight="0.33" sideWeight="0.5" order="7" side_tool="false" content_ui="tabs" />
<window_info id="Run" active="false" anchor="bottom" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="true" show_stripe_button="true" weight="0.3294979" sideWeight="0.5" order="2" side_tool="false" content_ui="tabs" />
<window_info id="Structure" active="false" anchor="left" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" show_stripe_button="true" weight="0.25" sideWeight="0.5" order="1" side_tool="false" content_ui="tabs" />
<window_info id="Terminal" active="false" anchor="bottom" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" show_stripe_button="true" weight="0.33" sideWeight="0.5" order="7" side_tool="false" content_ui="tabs" />
<window_info id="Debug" active="false" anchor="bottom" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" show_stripe_button="true" weight="0.39958158" sideWeight="0.5" order="3" side_tool="false" content_ui="tabs" />
<window_info id="Favorites" active="false" anchor="left" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" show_stripe_button="true" weight="0.33" sideWeight="0.5" order="2" side_tool="true" content_ui="tabs" />
<window_info id="Debug" active="false" anchor="bottom" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" show_stripe_button="true" weight="0.39958158" sideWeight="0.5" order="3" side_tool="false" content_ui="tabs" />
<window_info id="Data View" active="false" anchor="right" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" show_stripe_button="true" weight="0.33" sideWeight="0.5" order="3" side_tool="false" content_ui="tabs" />
<window_info id="Cvs" active="false" anchor="bottom" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" show_stripe_button="true" weight="0.25" sideWeight="0.5" order="4" side_tool="false" content_ui="tabs" />
<window_info id="Message" active="false" anchor="bottom" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" show_stripe_button="true" weight="0.33" sideWeight="0.5" order="0" side_tool="false" content_ui="tabs" />
......@@ -228,7 +228,7 @@
<watches-manager />
</component>
<component name="editorHistoryManager">
<entry file="file://$PROJECT_DIR$/SynGen_UnitTest.py">
<entry file="file://$PROJECT_DIR$/../../../DataProcessing/dataprocessing/readtools.py">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="0">
<caret line="0" column="0" lean-forward="false" selection-start-line="0" selection-start-column="0" selection-end-line="0" selection-end-column="0" />
......@@ -236,51 +236,77 @@
</state>
</provider>
</entry>
<entry file="file://$USER_HOME$/.conda/envs/powersim/Lib/codecs.py">
<entry file="file://$PROJECT_DIR$/SynGen_UnitTest.py">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="174">
<caret line="319" column="0" lean-forward="false" selection-start-line="319" selection-start-column="0" selection-end-line="319" selection-end-column="0" />
<state relative-caret-position="357">
<caret line="21" column="10" lean-forward="true" selection-start-line="21" selection-start-column="10" selection-end-line="21" selection-end-column="10" />
<folding />
</state>
</provider>
</entry>
<entry file="file://$PROJECT_DIR$/../../../DataProcessing/dataprocessing/plottoolsDPsim.py">
<entry file="file://$PROJECT_DIR$/../../../DataProcessing/dataprocessing/plotdpsim.py">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="255">
<caret line="48" column="30" lean-forward="true" selection-start-line="48" selection-start-column="30" selection-end-line="48" selection-end-column="30" />
<folding />
<state relative-caret-position="408">
<caret line="28" column="44" lean-forward="false" selection-start-line="28" selection-start-column="37" selection-end-line="28" selection-end-column="44" />
<folding>
<element signature="e#0#24#0" expanded="true" />
</folding>
</state>
</provider>
</entry>
<entry file="file://$PROJECT_DIR$/../../../DataProcessing/dataprocessing/plottools.py">
<entry file="file://$PROJECT_DIR$/../../../DataProcessing/dataprocessing/plotdpsim_deprecated.py">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="289">
<caret line="19" column="25" lean-forward="true" selection-start-line="19" selection-start-column="25" selection-end-line="19" selection-end-column="25" />
<state relative-caret-position="510">
<caret line="33" column="120" lean-forward="false" selection-start-line="33" selection-start-column="4" selection-end-line="33" selection-end-column="120" />
<folding>
<element signature="e#0#18#0" expanded="true" />
</folding>
</state>
</provider>
</entry>
<entry file="file://$PROJECT_DIR$/SynGen_UnitTest.py">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="0">
<caret line="0" column="0" lean-forward="false" selection-start-line="0" selection-start-column="0" selection-end-line="0" selection-end-column="0" />
<folding />
</state>
</provider>
</entry>
<entry file="file://$USER_HOME$/.conda/envs/powersim/Lib/codecs.py">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="174">
<caret line="319" column="0" lean-forward="false" selection-start-line="319" selection-start-column="0" selection-end-line="319" selection-end-column="0" />
</state>
</provider>
</entry>
<entry file="file://$PROJECT_DIR$/../../../DataProcessing/dataprocessing/plottoolsDPsim.py" />
<entry file="file://$PROJECT_DIR$/../../../DataProcessing/dataprocessing/readtools.py">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="199">
<state relative-caret-position="408">
<caret line="26" column="50" lean-forward="false" selection-start-line="26" selection-start-column="50" selection-end-line="26" selection-end-column="50" />
<folding />
</state>
</provider>
</entry>
<entry file="file://$PROJECT_DIR$/../../../DataProcessing/dataprocessing/plotdpsim_deprecated.py">
<entry file="file://$PROJECT_DIR$/../../../DataProcessing/dataprocessing/plottools.py">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="306">
<caret line="33" column="120" lean-forward="false" selection-start-line="33" selection-start-column="4" selection-end-line="33" selection-end-column="120" />
<folding>
<element signature="e#0#18#0" expanded="true" />
</folding>
<state relative-caret-position="289">
<caret line="19" column="25" lean-forward="false" selection-start-line="19" selection-start-column="25" selection-end-line="19" selection-end-column="25" />
<folding />
</state>
</provider>
</entry>
<entry file="file://$PROJECT_DIR$/SynGen_UnitTest.py">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="357">
<caret line="21" column="10" lean-forward="true" selection-start-line="21" selection-start-column="10" selection-end-line="21" selection-end-column="10" />
<folding />
</state>
</provider>
</entry>
<entry file="file://$PROJECT_DIR$/../../../DataProcessing/dataprocessing/plotdpsim.py">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="-391">
<state relative-caret-position="221">
<caret line="28" column="44" lean-forward="false" selection-start-line="28" selection-start-column="37" selection-end-line="28" selection-end-column="44" />
<folding>
<element signature="e#0#24#0" expanded="true" />
......@@ -288,11 +314,13 @@
</state>
</provider>
</entry>
<entry file="file://$PROJECT_DIR$/SynGen_UnitTest.py">
<entry file="file://$PROJECT_DIR$/../../../DataProcessing/dataprocessing/plotdpsim_deprecated.py">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="357">
<caret line="21" column="10" lean-forward="true" selection-start-line="21" selection-start-column="10" selection-end-line="21" selection-end-column="10" />
<folding />
<state relative-caret-position="306">
<caret line="33" column="120" lean-forward="false" selection-start-line="33" selection-start-column="4" selection-end-line="33" selection-end-column="120" />
<folding>
<element signature="e#0#18#0" expanded="true" />
</folding>
</state>
</provider>
</entry>
......
......@@ -9,7 +9,6 @@
#include "Components/VoltSourceRes.h"
#include "Components/InterfacedInductor.h"
#include "Components/SynchronGeneratorEMT.h"
#include "Components/SynchronGeneratorEMTdq.h"
#include "Components/SynchronGenerator.h"
#include "Components/ComponentCommons.h"
#include "Components/VoltSourceResFreq.h"
......
......@@ -4,7 +4,6 @@
#include <string>
#include <iostream>
#include "../Logger.h"
#include "../SystemModel.h"
#include "../MathLibrary.h"
......@@ -13,25 +12,30 @@ namespace DPsim {
/// Base class for all elements that might be added to the matrix.
class BaseComponent {
protected:
/// Component name
std::string mName;
/// Component node 1
int mNode1;
/// Component node 2
int mNode2;
/// Component node 3
int mNode3;
/// Component logger control for internal variables
bool mLogActive;
public:
BaseComponent() { }
BaseComponent(std::string name) { this->mName = name; }
BaseComponent(int src, int dest) { this->mNode1 = src - 1; this->mNode2 = dest - 1; }
BaseComponent(std::string name, int src, int dest) { this->mName = name; this->mNode1 = src - 1; this->mNode2 = dest - 1; }
BaseComponent(std::string name, int node1, int node2, int node3) { this->mName = name; this->mNode1 = node1 - 1; this->mNode2 = node2 - 1; this->mNode3 = node3 - 1; }
BaseComponent(std::string name, int node1, int node2, bool logActive = false) {
this->mName = name;
this->mNode1 = node1 - 1;
this->mNode2 = node2 - 1;
this->mLogActive = logActive;
}
BaseComponent(std::string name, int node1, int node2, int node3, bool logActive = false)
: BaseComponent(name, node1, node2, logActive) {
this->mNode3 = node3 - 1;
}
virtual ~BaseComponent() { }
/// get value of node1
......
......@@ -88,7 +88,8 @@ void SynchronGenerator::initWithPerUnitParam(
}
void SynchronGenerator::init(Real om, Real dt,
Real initActivePower, Real initReactivePower, Real initTerminalVolt, Real initVoltAngle) {
Real initActivePower, Real initReactivePower, Real initTerminalVolt,
Real initVoltAngle, Real initFieldVoltage, Real initMechPower) {
// Create matrices for state space representation
if (DampingWindings == 2)
......@@ -154,7 +155,7 @@ void SynchronGenerator::init(Real om, Real dt,
mReactanceMat = mInductanceMat.inverse();
// steady state per unit initial value
initStatesInPerUnit(initActivePower, initReactivePower, initTerminalVolt, initVoltAngle);
initStatesInPerUnit(initActivePower, initReactivePower, initTerminalVolt, initVoltAngle, initFieldVoltage, initMechPower);
mVaRe = dq0ToAbcTransform(mThetaMech, mVd* mBase_v, mVq* mBase_v, mV0* mBase_v)(0);
mVbRe = dq0ToAbcTransform(mThetaMech, mVd* mBase_v, mVq* mBase_v, mV0* mBase_v)(1);
......@@ -172,7 +173,7 @@ void SynchronGenerator::init(Real om, Real dt,
}
void SynchronGenerator::initStatesInPerUnit(Real initActivePower, Real initReactivePower,
Real initTerminalVolt, Real initVoltAngle) {
Real initTerminalVolt, Real initVoltAngle, Real initFieldVoltage, Real initMechPower) {
double init_P = initActivePower / mNomPower;
double init_Q = initReactivePower / mNomPower;
......@@ -258,13 +259,15 @@ void SynchronGenerator::initStatesInPerUnit(Real initActivePower, Real initReact
mPsikq1 = init_psiq1;
mPsikq2 = init_psiq2;
// Initialize mechanical angle
// Initialize mechanical variables
mMechPower = initMechPower / mNomPower;
mMechTorque = mMechPower / 1;
mThetaMech = initVoltAngle + init_delta - PI / 2.;
}
void SynchronGenerator::step(SystemModel& system, Real fieldVoltage, Real mechPower) {
stepInPerUnit(system.getOmega(), system.getTimeStep(), fieldVoltage, mechPower, system.getNumMethod());
stepInPerUnit(system.getOmega(), system.getTimeStep(), system.getNumMethod());
if (mNode1 >= 0) {
system.addCompToRightSideVector(mNode1, mIaRe, mIaIm);
......@@ -277,7 +280,7 @@ void SynchronGenerator::step(SystemModel& system, Real fieldVoltage, Real mechPo
}
}
void SynchronGenerator::stepInPerUnit(Real om, Real dt, Real fieldVoltage, Real mechPower, NumericalMethod numMethod) {
void SynchronGenerator::stepInPerUnit(Real om, Real dt, NumericalMethod numMethod) {
// mVoltages(5, 0) = fieldVoltage / mBase_v;
// TODO calculate effect of changed field voltage
......@@ -305,10 +308,7 @@ void SynchronGenerator::stepInPerUnit(Real om, Real dt, Real fieldVoltage, Real
//mVoltages(2, 0) = mV0;
if (numMethod == NumericalMethod::Euler) {
mMechPower = mechPower / mNomPower;
mMechTorque = mMechPower / 1;
mElecTorque = (mPsid*mIq - mPsiq*mId);
// Euler step forward
......@@ -374,8 +374,6 @@ void SynchronGenerator::stepInPerUnit(Real om, Real dt, Real fieldVoltage, Real
else if (numMethod == NumericalMethod::Trapezoidal_flux)
{
mMechPower = mechPower / mNomPower;
mMechTorque = mMechPower / 1;
mElecTorque = (mPsid*mIq - mPsiq*mId);
......@@ -486,11 +484,7 @@ void SynchronGenerator::stepInPerUnit(Real om, Real dt, Real fieldVoltage, Real
}
else if (numMethod == NumericalMethod::Trapezoidal_current)
{
// calculate mechanical states
mMechPower = mechPower / mNomPower;
mMechTorque = mMechPower / 1;
else if (numMethod == NumericalMethod::Trapezoidal_current) {
mElecTorque = (mPsid*mIq - mPsiq*mId);
// Euler step forward for angular speed
......@@ -509,8 +503,7 @@ void SynchronGenerator::stepInPerUnit(Real om, Real dt, Real fieldVoltage, Real
DPSMatrix Aux2 = I - (dt / 2) * A;
DPSMatrix InvAux = Aux2.inverse();
if (DampingWindings == 2)
{
if (DampingWindings == 2) {
DPSMatrix dqCurrents(7, 1);
dqCurrents(0, 0) = mIq;
dqCurrents(1, 0) = mId;
......@@ -548,9 +541,7 @@ void SynchronGenerator::stepInPerUnit(Real om, Real dt, Real fieldVoltage, Real
mPsifd = -mLmd*mId + (mLlfd + mLmd)*mIfd + mLmd*mIkd;
mPsikd = -mLmd*mId + mLmd*mIfd + (mLlkd + mLmd)*mIkd;
}
else
{
else {
DPSMatrix dqCurrents(7, 1);
dqCurrents(0, 0) = mIq;
dqCurrents(1, 0) = mId;
......@@ -623,7 +614,7 @@ void SynchronGenerator::stepInPerUnit(Real om, Real dt, Real fieldVoltage, Real
mVfd,
mVkd;
mFluxes2 << mVq,
mFluxes2 << mPsiq,
mPsid,
mPsi0,
mPsikq1,
......@@ -647,7 +638,7 @@ void SynchronGenerator::stepInPerUnit(Real om, Real dt, Real fieldVoltage, Real
mVfd,
mVkd;
mFluxes2 << mVq,
mFluxes2 << mPsiq,
mPsid,
mPsi0,
mPsikq1,
......
......@@ -252,12 +252,13 @@ namespace DPsim {
/// Initializes states in per unit or stator referred variables depending on the setting of the state type.
/// Function parameters have to be given in Real units.
void init(Real om, Real dt,
Real initActivePower, Real initReactivePower, Real initTerminalVolt, Real initVoltAngle);
Real initActivePower, Real initReactivePower, Real initTerminalVolt,
Real initVoltAngle, Real initFieldVoltage, Real initMechPower);
/// Initializes states in per unit. All machine parameters are assumed to be in per unit.
/// Function parameters have to be given in Real units.
void initStatesInPerUnit(Real initActivePower, Real initReactivePower,
Real initTerminalVolt, Real initVoltAngle);
Real initTerminalVolt, Real initVoltAngle, Real initFieldVoltage, Real initMechPower);
/// Performs an Euler forward step with the state space model of a synchronous generator
/// to calculate the flux and current from the voltage vector.
......@@ -265,7 +266,7 @@ namespace DPsim {
/// Performs an Euler forward step with the state space model of a synchronous generator
/// to calculate the flux and current from the voltage vector in per unit.
void stepInPerUnit(Real om, Real dt, Real fieldVoltage, Real mechPower, NumericalMethod numMethod);
void stepInPerUnit(Real om, Real dt, NumericalMethod numMethod);
/// Retrieves calculated voltage from simulation for next step
void postStep(SystemModel& system);
......
......@@ -7,11 +7,8 @@ SynchronGeneratorEMT::SynchronGeneratorEMT(std::string name, int node1, int node
Real Rs, Real Ll, Real Lmd, Real Lmd0, Real Lmq, Real Lmq0,
Real Rfd, Real Llfd, Real Rkd, Real Llkd,
Real Rkq1, Real Llkq1, Real Rkq2, Real Llkq2,
Real inertia) {
this->mNode1 = node1 - 1;
this->mNode2 = node2 - 1;
this->mNode3 = node3 - 1;
Real inertia, bool logActive)
: BaseComponent(name, node1, node2, node3, logActive) {
mNomPower = nomPower;
mNomVolt = nomVolt;
......@@ -31,11 +28,24 @@ SynchronGeneratorEMT::SynchronGeneratorEMT(std::string name, int node1, int node
mBase_Psi = mBase_L * mBase_i;
mBase_T = mNomPower / mBase_OmMech;
// Create logging file
if (mLogActive) {
std::string filename = "SynGen_" + mName + ".csv";
mLog = new Logger(filename);
}
// steady state per unit initial value
initWithPerUnitParam(Rs, Ll, Lmd, Lmd0, Lmq, Lmq0, Rfd, Llfd, Rkd, Llkd, Rkq1, Llkq1, Rkq2, Llkq2, inertia);
}
SynchronGeneratorEMT::~SynchronGeneratorEMT() {
if (mLogActive) {
delete mLog;
}
}
void SynchronGeneratorEMT::initWithPerUnitParam(
Real Rs, Real Ll, Real Lmd, Real Lmd0, Real Lmq, Real Lmq0,
Real Rfd, Real Llfd, Real Rkd, Real Llkd,
......@@ -90,7 +100,8 @@ void SynchronGeneratorEMT::initWithPerUnitParam(
}
void SynchronGeneratorEMT::init(Real om, Real dt,
Real initActivePower, Real initReactivePower, Real initTerminalVolt, Real initVoltAngle) {
Real initActivePower, Real initReactivePower, Real initTerminalVolt,
Real initVoltAngle, Real initFieldVoltage, Real initMechPower) {
// Create matrices for state space representation
if (DampingWindings == 2)
......@@ -157,7 +168,7 @@ void SynchronGeneratorEMT::init(Real om, Real dt,
// steady state per unit initial value
initStatesInPerUnit(initActivePower, initReactivePower, initTerminalVolt, initVoltAngle);
initStatesInPerUnit(initActivePower, initReactivePower, initTerminalVolt, initVoltAngle, initFieldVoltage, initMechPower);
mVa = inverseParkTransform2(mThetaMech, mVd* mBase_v, mVq* mBase_v, mV0* mBase_v)(0);
mVb = inverseParkTransform2(mThetaMech, mVd* mBase_v, mVq* mBase_v, mV0* mBase_v)(1);
......@@ -168,9 +179,10 @@ void SynchronGeneratorEMT::init(Real om, Real dt,
mIc = inverseParkTransform2(mThetaMech, mId* mBase_i, mIq* mBase_i, mI0* mBase_i)(2);
}
void SynchronGeneratorEMT::initStatesInPerUnit(Real initActivePower, Real initReactivePower,
Real initTerminalVolt, Real initVoltAngle) {
void SynchronGeneratorEMT::initStatesInPerUnit(Real initActivePower, Real initReactivePower,
Real initTerminalVolt, Real initVoltAngle, Real initFieldVoltage, Real initMechPower) {
// #### Electrical variables ##############################################
double init_P = initActivePower / mNomPower;
double init_Q = initReactivePower / mNomPower;
double init_S = sqrt(pow(init_P, 2.) + pow(init_Q, 2.));
......@@ -231,14 +243,16 @@ void SynchronGeneratorEMT::initStatesInPerUnit(Real initActivePower, Real initRe
mPsikq1 = init_psiq1;
mPsikq2 = init_psiq2;
// Initialize mechanical angle
//mThetaMech = initVoltAngle + init_delta;
// #### mechanical variables ##############################################
mMechPower = initMechPower / mNomPower;
mMechTorque = mMechPower / 1;
mThetaMech = initVoltAngle + init_delta - M_PI/2;
//mThetaMech = initVoltAngle + init_delta;
}
void SynchronGeneratorEMT::step(SystemModel& system, Real fieldVoltage, Real mechPower, Real time) {
void SynchronGeneratorEMT::step(SystemModel& system, Real time) {
stepInPerUnit(system.getOmega(), system.getTimeStep(), fieldVoltage, mechPower, time, system.getNumMethod());
stepInPerUnit(system.getOmega(), system.getTimeStep(), time, system.getNumMethod());
// Update current source accordingly
if (mNode1 >= 0) {
......@@ -251,9 +265,15 @@ void SynchronGeneratorEMT::step(SystemModel& system, Real fieldVoltage, Real mec
system.addRealToRightSideVector(mNode3, mIc);
}
if (mLogActive) {
DPSMatrix logValues(getFluxes().rows() + getVoltages().rows() + getCurrents().rows(), 1);
logValues << getFluxes(), getVoltages(), getCurrents();
mLog->LogDataLine(time, logValues);
}
}
void SynchronGeneratorEMT::stepInPerUnit(Real om, Real dt, Real fieldVoltage, Real mechPower, Real time, NumericalMethod numMethod) {
void SynchronGeneratorEMT::stepInPerUnit(Real om, Real dt, Real time, NumericalMethod numMethod) {
mVa = (1 / mBase_v) * mVa;
mVb = (1 / mBase_v) * mVb;
......@@ -263,19 +283,13 @@ void SynchronGeneratorEMT::stepInPerUnit(Real om, Real dt, Real fieldVoltage, Re
mIb = (1 / mBase_i) * mIb;
mIc = (1 / mBase_i) * mIc;
mVfd = fieldVoltage / mBase_v;
// TODO calculate effect of changed field voltage
// dq-transform of interface voltage
mVd = parkTransform2(mThetaMech, mVa, mVb, mVc)(0);
mVq = parkTransform2(mThetaMech, mVa, mVb, mVc)(1);
mV0 = parkTransform2(mThetaMech, mVa, mVb, mVc)(2);
if (numMethod == NumericalMethod::Euler) {
mMechPower = mechPower / mNomPower;
mMechTorque = mMechPower / 1;
mElecTorque = (mPsid*mIq - mPsiq*mId);
// Euler step forward
......@@ -328,9 +342,6 @@ void SynchronGeneratorEMT::stepInPerUnit(Real om, Real dt, Real fieldVoltage, Re
//Two steps Adams-Bashforth
if (time < dt) {
// calculate mechanical states
mMechPower = mechPower / mNomPower;
mMechTorque = mMechPower / mOmMech;
mElecTorque = (mPsid*mIq - mPsiq*mId);
mOmMech_past = mOmMech;
......@@ -386,9 +397,6 @@ void SynchronGeneratorEMT::stepInPerUnit(Real om, Real dt, Real fieldVoltage, Re
}
else {
// calculate mechanical states
mMechPower = mechPower / mNomPower;
mMechTorque = mMechPower / mOmMech;
mMechTorque_past = mMechPower / mOmMech_past;
mElecTorque = (mPsid*mIq - mPsiq*mId);
......@@ -447,16 +455,11 @@ void SynchronGeneratorEMT::stepInPerUnit(Real om, Real dt, Real fieldVoltage, Re
else if (numMethod == NumericalMethod::Trapezoidal_flux){
mMechPower = mechPower / mNomPower;
mMechTorque = mMechPower / 1;
mElecTorque = (mPsid*mIq - mPsiq*mId);
// Euler step forward
mOmMech = mOmMech + dt * (1 / (2 * mH) * (mMechTorque - mElecTorque));
if (DampingWindings == 2)
{