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

initial refactoring of emt3ph averaged inverter

parent 41ecaa79
...@@ -101,7 +101,7 @@ int main(int argc, char* argv[]) { ...@@ -101,7 +101,7 @@ int main(int argc, char* argv[]) {
pv->setControllerParameters(scenario.KpPLL, scenario.KiPLL, scenario.KpPowerCtrl, scenario.KiPowerCtrl, scenario.KpCurrCtrl, scenario.KiCurrCtrl, scenario.OmegaCutoff); pv->setControllerParameters(scenario.KpPLL, scenario.KiPLL, scenario.KpPowerCtrl, scenario.KiPowerCtrl, scenario.KpCurrCtrl, scenario.KiCurrCtrl, scenario.OmegaCutoff);
pv->setFilterParameters(scenario.Lf, scenario.Cf, scenario.Rf, scenario.Rc); 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->setTransformerParameters(scenario.systemNominalVoltage, scenario.pvNominalVoltage, scenario.transformerNominalPower, scenario.systemNominalVoltage/scenario.pvNominalVoltage, 0, 0, scenario.transformerInductance, scenario.systemOmega);
pv->setInitialStateValues(scenario.thetaPLLInit, scenario.phiPLLInit, scenario.pvNominalActivePower, scenario.pvNominalReactivePower, scenario.phi_dInit, scenario.phi_qInit, scenario.gamma_dInit, scenario.gamma_qInit); pv->setInitialStateValues(scenario.pvNominalActivePower, scenario.pvNominalReactivePower, scenario.phi_dInit, scenario.phi_qInit, scenario.gamma_dInit, scenario.gamma_qInit);
// Topology // Topology
extnetEMT->connect({ n1EMT }); extnetEMT->connect({ n1EMT });
...@@ -111,7 +111,7 @@ int main(int argc, char* argv[]) { ...@@ -111,7 +111,7 @@ int main(int argc, char* argv[]) {
SystemNodeList{n1EMT, n2EMT}, SystemNodeList{n1EMT, n2EMT},
SystemComponentList{extnetEMT, lineEMT, pv}); SystemComponentList{extnetEMT, lineEMT, pv});
// Initialization of dynamic topology (actually necessary here? node objects the same) // Initialization of dynamic topology
CIM::Reader reader(simNameEMT, Logger::Level::debug); CIM::Reader reader(simNameEMT, Logger::Level::debug);
reader.initDynamicSystemTopologyWithPowerflow(systemPF, systemEMT); reader.initDynamicSystemTopologyWithPowerflow(systemPF, systemEMT);
......
...@@ -151,7 +151,7 @@ namespace CIGREMV { ...@@ -151,7 +151,7 @@ namespace CIGREMV {
pv->setControllerParameters(scenario.KpPLL, scenario.KiPLL, scenario.KpPowerCtrl, scenario.KiPowerCtrl, scenario.KpCurrCtrl, scenario.KiCurrCtrl, scenario.OmegaCutoff); pv->setControllerParameters(scenario.KpPLL, scenario.KiPLL, scenario.KpPowerCtrl, scenario.KiPowerCtrl, scenario.KpCurrCtrl, scenario.KiCurrCtrl, scenario.OmegaCutoff);
pv->setFilterParameters(scenario.Lf, scenario.Cf, scenario.Rf, scenario.Rc); pv->setFilterParameters(scenario.Lf, scenario.Cf, scenario.Rf, scenario.Rc);
pv->setTransformerParameters(scenario.systemNominalVoltage, scenario.pvUnitNominalVoltage, scenario.transformerNominalPower, scenario.systemNominalVoltage/scenario.pvUnitNominalVoltage, 0, 0, scenario.transformerInductance, scenario.systemOmega); pv->setTransformerParameters(scenario.systemNominalVoltage, scenario.pvUnitNominalVoltage, scenario.transformerNominalPower, scenario.systemNominalVoltage/scenario.pvUnitNominalVoltage, 0, 0, scenario.transformerInductance, scenario.systemOmega);
pv->setInitialStateValues(scenario.thetaPLLInit, scenario.phiPLLInit, scenario.pInit, scenario.qInit, scenario.phi_dInit, scenario.phi_qInit, scenario.gamma_dInit, scenario.gamma_qInit); pv->setInitialStateValues(scenario.pInit, scenario.qInit, scenario.phi_dInit, scenario.phi_qInit, scenario.gamma_dInit, scenario.gamma_qInit);
system.addComponent(pv); system.addComponent(pv);
system.connectComponentToNodes<Real>(pv, { connectionNode }); system.connectComponentToNodes<Real>(pv, { connectionNode });
} }
......
...@@ -5,32 +5,54 @@ ...@@ -5,32 +5,54 @@
* License, v. 2.0. If a copy of the MPL was not distributed with this * License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at https://mozilla.org/MPL/2.0/. * file, You can obtain one at https://mozilla.org/MPL/2.0/.
*********************************************************************************/ *********************************************************************************/
#pragma once #pragma once
#include <cps/CIM/Reader.h>
#include <cps/SimPowerComp.h> #include <cps/SimPowerComp.h>
#include <cps/Solver/MNAInterface.h> #include <cps/Solver/MNAInterface.h>
#include <cps/Definitions.h> #include <cps/Definitions.h>
#include <cps/EMT/EMT_Ph3_Resistor.h> #include <cps/EMT/EMT_Ph3_Resistor.h>
#include <cps/EMT/EMT_Ph3_Inductor.h> #include <cps/EMT/EMT_Ph3_Inductor.h>
#include <cps/EMT/EMT_Ph3_Capacitor.h> #include <cps/EMT/EMT_Ph3_Capacitor.h>
#include <cps/EMT/EMT_Ph3_ControlledVoltageSource.h> #include <cps/EMT/EMT_Ph3_VoltageSource.h>
#include <cps/EMT/EMT_Ph3_Transformer.h> #include <cps/EMT/EMT_Ph3_Transformer.h>
#include <cps/Base/Base_AvVoltageSourceInverterDQWithStateSpace.h> #include <cps/Base/Base_AvVoltageSourceInverterDQ.h>
#include <cps/Signal/PLL.h>
#include <cps/Signal/PowerControllerVSI.h>
namespace CPS { namespace CPS {
namespace EMT { namespace EMT {
namespace Ph3 { namespace Ph3 {
class AvVoltageSourceInverterDQ : class AvVoltageSourceInverterDQ :
public Base::AvVoltageSourceInverterDQWithStateSpace, public Base::AvVoltageSourceInverterDQ,
public SimPowerComp<Real>, public SimPowerComp<Real>,
public MNAInterface, public MNAInterface,
public SharedFactory<AvVoltageSourceInverterDQ> { public SharedFactory<AvVoltageSourceInverterDQ> {
protected: protected:
// ### Subcomponents ### // ### General Parameters ###
/// Nominal system angle
Real mThetaN = 0;
/// Nominal frequency
Real mOmegaN;
/// Nominal voltage
Real mVnom;
/// Simulation step
Real mTimeStep;
/// Active power reference
Real mPref;
/// Reactive power reference
Real mQref;
// ### Control Subcomponents ###
/// PLL
std::shared_ptr<Signal::PLL> mPLL;
/// Power Controller
std::shared_ptr<Signal::PowerControllerVSI> mPowerControllerVSI;
// ### Electrical Subcomponents ###
/// Controlled voltage source /// Controlled voltage source
std::shared_ptr<EMT::Ph3::ControlledVoltageSource> mSubCtrledVoltageSource; std::shared_ptr<EMT::Ph3::VoltageSource> mSubCtrledVoltageSource;
/// Resistor Rf as part of LCL filter /// Resistor Rf as part of LCL filter
std::shared_ptr<EMT::Ph3::Resistor> mSubResistorF; std::shared_ptr<EMT::Ph3::Resistor> mSubResistorF;
/// Capacitor Cf as part of LCL filter /// Capacitor Cf as part of LCL filter
...@@ -42,101 +64,55 @@ namespace Ph3 { ...@@ -42,101 +64,55 @@ namespace Ph3 {
/// Optional connection transformer /// Optional connection transformer
std::shared_ptr<EMT::Ph3::Transformer> mConnectionTransformer; std::shared_ptr<EMT::Ph3::Transformer> mConnectionTransformer;
// ### inputs ### // ### Inverter Interfacing Variables ###
/// // Control inputs
Matrix mVcdq = Matrix::Zero(2, 1); /// Measured voltage d-axis in local reference frame
/// Real mVcd = 0;
Matrix mVcabc = Matrix::Zero(3, 1); /// Measured voltage q-axis in local reference frame
/// Real mVcq = 0;
Matrix mIrcdq = Matrix::Zero(2, 1); /// Measured current d-axis in local reference frame
/// Real mIrcd = 0;
Matrix mIrcabc = Matrix::Zero(3, 1); /// Measured current q-axis in local reference frame
Real mIrcq = 0;
// ### outputs ### // Control outputs
/// /// Voltage as control output after transformation interface
Matrix mVsdq = Matrix::Zero(2, 1); MatrixComp mVsref = MatrixComp::Zero(1,1);
///
Matrix mVsabc = Matrix::Zero(3, 1); /// Boolean for connection transformer usage
/// in case variable time step simulation should be developed in the future
Real mTimeStep;
///
Bool mCtrlOn = true;
///
Bool mWithConnectionTransformer=false; Bool mWithConnectionTransformer=false;
/// instantaneous omega
Real mOmegaInst = 0;
/// instantaneous frequency
Real mFreqInst = 0;
///
std::vector<Real>* mGenProfile = nullptr;
///
std::vector<Real>::iterator mCurrentPower;
///
Attribute<Real>::Ptr mQRefInput;
// #### solver #### // #### solver ####
/// ///
std::vector<const Matrix*> mRightVectorStamps; std::vector<const Matrix*> mRightVectorStamps;
public: public:
/// /// Defines name amd logging level
AvVoltageSourceInverterDQ(String name, Logger::Level logLevel = Logger::Level::off) AvVoltageSourceInverterDQ(String name, Logger::Level logLevel = Logger::Level::off)
: AvVoltageSourceInverterDQ(name, name, logLevel) {} : AvVoltageSourceInverterDQ(name, name, logLevel) {}
/// /// Defines UID, name, logging level and connection trafo existence
AvVoltageSourceInverterDQ(String uid, String name, Logger::Level logLevel = Logger::Level::off, Bool withTrafo = false); AvVoltageSourceInverterDQ(String uid, String name, Logger::Level logLevel = Logger::Level::off, Bool withTrafo = false);
/// // #### General ####
/// Initializes component from power flow data
void initializeFromNodesAndTerminals(Real frequency);
/// Setter for gengit eral parameters of inverter
void setParameters(Real sysOmega, Real sysVoltNom, Real Pref, Real Qref); void setParameters(Real sysOmega, Real sysVoltNom, Real Pref, Real Qref);
/// /// Setter for parameters of control loops
void setControllerParameters(Real Kp_pll, Real Ki_pll, Real Kp_powerCtrl, Real Ki_powerCtrl, Real Kp_currCtrl, Real Ki_currCtrl, Real Omega_cutoff);
/// Setter for parameters of transformer
void setTransformerParameters(Real nomVoltageEnd1, Real nomVoltageEnd2, void setTransformerParameters(Real nomVoltageEnd1, Real nomVoltageEnd2,
Real ratedPower, Real ratioAbs, Real ratioPhase, Real resistance, Real inductance, Real omega); Real ratedPower, Real ratioAbs, Real ratioPhase, Real resistance, Real inductance, Real omega);
/// /// Setter for parameters of filter
void setControllerParameters(Real Kp_pll, Real Ki_pll, Real Kp_powerCtrl, Real Ki_powerCtrl,
Real Kp_currCtrl, Real Ki_currCtrl, Real Omega_cutoff);
///
void setFilterParameters(Real Lf, Real Cf, Real Rf, Real Rc); void setFilterParameters(Real Lf, Real Cf, Real Rf, Real Rc);
/// /// Setter for initial values applied in controllers
void setInitialStateValues(Real thetaPLLInit, Real phiPLLInit, Real pInit, Real qInit, void setInitialStateValues(Real pInit, Real qInit,
Real phi_dInit, Real phi_qInit, Real gamma_dInit, Real gamma_qInit); Real phi_dInit, Real phi_qInit, Real gamma_dInit, Real gamma_qInit);
///
SimPowerComp<Real>::Ptr clone(String copySuffix);
///
void initializeStateSpaceModel(Real omega, Real timeStep, Attribute<Matrix>::Ptr leftVector);
///
void updateInputStateSpaceModel(const Matrix& leftVector, Real time);
///
void updateStates();
///
void updateBMatrixStateSpaceModel();
/// ///
Matrix getParkTransformMatrixPowerInvariant(Real theta); Matrix getParkTransformMatrixPowerInvariant(Real theta);
/// ///
Matrix getInverseParkTransformMatrixPowerInvariant(Real theta); Matrix parkTransformPowerInvariant(Real theta, const Matrix &fabc);
///
Matrix parkTransformPowerInvariant(Real theta, Real fa, Real fb, Real fc);
///
Matrix inverseParkTransformPowerInvariant(Real theta, Real fd, Real fq);
///
void step(Real time, Int timeStepCount);
///
void updatePowerGeneration();
// #### General ####
///
//void addGenProfile(std::vector<Real>* genProfile);
///
void addAggregatedGenProfile(std::vector<Real>* genProfile, Real customerNumber);
///
void updateSetPoint(Real time);
///
void initializeFromNodesAndTerminals(Real frequency);
// #### interface with villas node ####
void ctrlReceiver(Attribute<Real>::Ptr qref);
// #### MNA section #### // #### MNA section ####
/// Initializes internal variables of the component /// Initializes internal variables of the component
void mnaInitialize(Real omega, Real timeStep, Attribute<Matrix>::Ptr leftVector); void mnaInitialize(Real omega, Real timeStep, Attribute<Matrix>::Ptr leftVector);
...@@ -144,61 +120,72 @@ namespace Ph3 { ...@@ -144,61 +120,72 @@ namespace Ph3 {
void mnaApplySystemMatrixStamp(Matrix& systemMatrix); void mnaApplySystemMatrixStamp(Matrix& systemMatrix);
/// Stamps right side (source) vector /// Stamps right side (source) vector
void mnaApplyRightSideVectorStamp(Matrix& rightVector); void mnaApplyRightSideVectorStamp(Matrix& rightVector);
/// Returns current through the component /// Updates current through the component
void mnaUpdateCurrent(const Matrix& leftVector); void mnaUpdateCurrent(const Matrix& leftVector);
/// Updates voltage across component
class MnaPreStep : public CPS::Task { void mnaUpdateVoltage(const Matrix& leftVector);
/// MNA pre step operations
void mnaPreStep(Real time, Int timeStepCount);
/// MNA post step operations
void mnaPostStep(Real time, Int timeStepCount, Attribute<Matrix>::Ptr &leftVector);
/// Add MNA pre step dependencies
void mnaAddPreStepDependencies(AttributeBase::List &prevStepDependencies, AttributeBase::List &attributeDependencies, AttributeBase::List &modifiedAttributes);
/// Add MNA post step dependencies
void mnaAddPostStepDependencies(AttributeBase::List &prevStepDependencies, AttributeBase::List &attributeDependencies, AttributeBase::List &modifiedAttributes, Attribute<Matrix>::Ptr &leftVector);
// #### Control section ####
/// Control pre step operations
void controlPreStep(Real time, Int timeStepCount);
/// Perform step of controller
void controlStep(Real time, Int timeStepCount);
/// Add control step dependencies
void addControlPreStepDependencies(AttributeBase::List &prevStepDependencies, AttributeBase::List &attributeDependencies, AttributeBase::List &modifiedAttributes);
/// Add control step dependencies
void addControlStepDependencies(AttributeBase::List &prevStepDependencies, AttributeBase::List &attributeDependencies, AttributeBase::List &modifiedAttributes);
class ControlPreStep : public CPS::Task {
public: public:
MnaPreStep(AvVoltageSourceInverterDQ& AvVoltageSourceInverterDQ) : ControlPreStep(AvVoltageSourceInverterDQ& AvVoltageSourceInverterDQ) :
Task(AvVoltageSourceInverterDQ.mName + ".MnaPreStep"), mAvVoltageSourceInverterDQ(AvVoltageSourceInverterDQ) { Task(AvVoltageSourceInverterDQ.mName + ".ControlPreStep"), mAvVoltageSourceInverterDQ(AvVoltageSourceInverterDQ) {
//mAttributeDependencies.push_back(AvVoltageSourceInverterDQ.attribute("P_ref")); mAvVoltageSourceInverterDQ.addControlPreStepDependencies(mPrevStepDependencies, mAttributeDependencies, mModifiedAttributes);
mPrevStepDependencies.push_back(AvVoltageSourceInverterDQ.attribute("i_intf"));
mPrevStepDependencies.push_back(AvVoltageSourceInverterDQ.attribute("v_intf"));
mModifiedAttributes.push_back(AvVoltageSourceInverterDQ.mSubCtrledVoltageSource->attribute("v_intf"));
} }
void execute(Real time, Int timeStepCount) { mAvVoltageSourceInverterDQ.controlPreStep(time, timeStepCount); };
void execute(Real time, Int timeStepCount);
private: private:
AvVoltageSourceInverterDQ& mAvVoltageSourceInverterDQ; AvVoltageSourceInverterDQ& mAvVoltageSourceInverterDQ;
}; };
class AddBStep : public Task { class ControlStep : public CPS::Task {
public: public:
AddBStep(AvVoltageSourceInverterDQ& AvVoltageSourceInverterDQ) : ControlStep(AvVoltageSourceInverterDQ& AvVoltageSourceInverterDQ) :
Task(AvVoltageSourceInverterDQ.mName + ".AddBStep"), mAvVoltageSourceInverterDQ(AvVoltageSourceInverterDQ) { Task(AvVoltageSourceInverterDQ.mName + ".ControlStep"), mAvVoltageSourceInverterDQ(AvVoltageSourceInverterDQ) {
mAttributeDependencies.push_back(AvVoltageSourceInverterDQ.mSubInductorF->attribute("right_vector")); mAvVoltageSourceInverterDQ.addControlStepDependencies(mPrevStepDependencies, mAttributeDependencies, mModifiedAttributes);
mAttributeDependencies.push_back(AvVoltageSourceInverterDQ.mConnectionTransformer->attribute("right_vector"));
mAttributeDependencies.push_back(AvVoltageSourceInverterDQ.mSubCapacitorF->attribute("right_vector"));
mAttributeDependencies.push_back(AvVoltageSourceInverterDQ.mSubCtrledVoltageSource->attribute("right_vector"));
mModifiedAttributes.push_back(AvVoltageSourceInverterDQ.attribute("right_vector"));
} }
void execute(Real time, Int timeStepCount) { mAvVoltageSourceInverterDQ.controlStep(time, timeStepCount); };
void execute(Real time, Int timeStepCount);
private: private:
AvVoltageSourceInverterDQ& mAvVoltageSourceInverterDQ; AvVoltageSourceInverterDQ& mAvVoltageSourceInverterDQ;
}; };
class MnaPreStep : public CPS::Task {
public:
MnaPreStep(AvVoltageSourceInverterDQ& AvVoltageSourceInverterDQ) :
Task(AvVoltageSourceInverterDQ.mName + ".MnaPreStep"), mAvVoltageSourceInverterDQ(AvVoltageSourceInverterDQ) {
mAvVoltageSourceInverterDQ.mnaAddPreStepDependencies(mPrevStepDependencies, mAttributeDependencies, mModifiedAttributes);
}
void execute(Real time, Int timeStepCount) { mAvVoltageSourceInverterDQ.mnaPreStep(time, timeStepCount); };
private:
AvVoltageSourceInverterDQ& mAvVoltageSourceInverterDQ;
};
class MnaPostStep : public CPS::Task { class MnaPostStep : public CPS::Task {
public: public:
MnaPostStep(AvVoltageSourceInverterDQ& AvVoltageSourceInverterDQ, Attribute<Matrix>::Ptr leftVector) : MnaPostStep(AvVoltageSourceInverterDQ& AvVoltageSourceInverterDQ, Attribute<Matrix>::Ptr leftVector) :
Task(AvVoltageSourceInverterDQ.mName + ".MnaPostStep"), mAvVoltageSourceInverterDQ(AvVoltageSourceInverterDQ), mLeftVector(leftVector) Task(AvVoltageSourceInverterDQ.mName + ".MnaPostStep"), mAvVoltageSourceInverterDQ(AvVoltageSourceInverterDQ), mLeftVector(leftVector) {
{ mAvVoltageSourceInverterDQ.mnaAddPostStepDependencies(mPrevStepDependencies, mAttributeDependencies, mModifiedAttributes, mLeftVector);
mAttributeDependencies.push_back(leftVector);
//mAttributeDependencies.push_back(AvVoltageSourceInverterDQ.attribute("Q_ref"));
//mAttributeDependencies.push_back(AvVoltageSourceInverterDQ.mQRefInput);
mAttributeDependencies.push_back(AvVoltageSourceInverterDQ.mSubCtrledVoltageSource->attribute("i_intf"));
mAttributeDependencies.push_back(AvVoltageSourceInverterDQ.mSubResistorF->attribute("i_intf"));
mAttributeDependencies.push_back(AvVoltageSourceInverterDQ.mSubInductorF->attribute("i_intf"));
mAttributeDependencies.push_back(AvVoltageSourceInverterDQ.mConnectionTransformer->attribute("i_intf"));
mAttributeDependencies.push_back(AvVoltageSourceInverterDQ.mSubResistorC->attribute("i_intf"));
mModifiedAttributes.push_back(AvVoltageSourceInverterDQ.attribute("i_intf"));
mModifiedAttributes.push_back(AvVoltageSourceInverterDQ.attribute("v_intf"));
} }
void execute(Real time, Int timeStepCount) { mAvVoltageSourceInverterDQ.mnaPostStep(time, timeStepCount, mLeftVector); };
void execute(Real time, Int timeStepCount);
private: private:
AvVoltageSourceInverterDQ& mAvVoltageSourceInverterDQ; AvVoltageSourceInverterDQ& mAvVoltageSourceInverterDQ;
......
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