DPsim
Loading...
Searching...
No Matches
EMT_Ph3_GFL.h
Go to the documentation of this file.
1// SPDX-FileCopyrightText: 2026 Institute for Automation of Complex Power Systems, EONERC, RWTH Aachen University
2// SPDX-License-Identifier: MPL-2.0
3
4#pragma once
5
15
16namespace CPS {
17namespace EMT {
18namespace Ph3 {
19
42class GFL final : public CompositePowerComp<Real>, public SharedFactory<GFL> {
43protected:
44 // -------------------------------------------------------------------------
45 // Parameters
46 // -------------------------------------------------------------------------
48 Real mVnom = 0.0;
49 Real mPRef = 0.0;
50 Real mQRef = 0.0;
51
52 Real mLf = 0.0;
53 Real mCf = 0.0;
54 Real mRf = 0.0;
55
56 Real mKpPLL = 0.0;
57 Real mKiPLL = 0.0;
63
65
71
78
79 // -------------------------------------------------------------------------
80 // Control subcomponents
81 // -------------------------------------------------------------------------
82 std::shared_ptr<Signal::PLL> mPLL;
83 std::shared_ptr<Signal::PowerControllerVSI> mPowerControllerVSI;
84
85 // -------------------------------------------------------------------------
86 // Electrical subcomponents
87 // -------------------------------------------------------------------------
88 std::shared_ptr<EMT::Ph3::VoltageSource> mSubControlledVoltageSource;
89 std::shared_ptr<EMT::Ph3::Resistor> mSubResistorF;
90 std::shared_ptr<EMT::Ph3::Inductor> mSubInductorF;
91 std::shared_ptr<EMT::Ph3::Capacitor> mSubCapacitorF;
92
93 Matrix mDirectResistorConductance = Matrix::Zero(3, 3);
94 Matrix mDirectInductorConductance = Matrix::Zero(3, 3);
95 Matrix mDirectCapacitorConductance = Matrix::Zero(3, 3);
96 Matrix mDirectInductorVoltage = Matrix::Zero(3, 1);
97 Matrix mDirectInductorCurrent = Matrix::Zero(3, 1);
98 Matrix mDirectInductorHistory = Matrix::Zero(3, 1);
99 Matrix mDirectCapacitorCurrent = Matrix::Zero(3, 1);
100 Matrix mDirectCapacitorHistory = Matrix::Zero(3, 1);
101 Matrix mDirectSourceVoltage = Matrix::Zero(3, 1);
102
103 // -------------------------------------------------------------------------
104 // Helpers
105 // -------------------------------------------------------------------------
109
111 const Matrix &fabc) const;
113 inverseParkTransformPowerInvariant(Real theta, const Matrix &fdq) const;
114
117
118public:
120
121 // -------------------------------------------------------------------------
122 // Public attributes
123 // -------------------------------------------------------------------------
124
128
132
136
139
142
147
150
155
156 // -------------------------------------------------------------------------
157 // Construction
158 // -------------------------------------------------------------------------
159 GFL(String uid, String name, Logger::Level logLevel = Logger::Level::off);
161 GFL(String uid, String name, Bool useSubcomponents,
162 Logger::Level logLevel = Logger::Level::off);
163
164 GFL(String name, Logger::Level logLevel = Logger::Level::off)
165 : GFL(name, name, logLevel) {}
166 GFL(String name, Bool useSubcomponents,
167 Logger::Level logLevel = Logger::Level::off)
168 : GFL(name, name, useSubcomponents, logLevel) {}
169
171
172 // -------------------------------------------------------------------------
173 // Parameters
174 // -------------------------------------------------------------------------
175
177 void setParameters(Real sysOmega, Real sysVoltNom, Real pRef, Real qRef);
178
180 void setControllerParameters(Real kpPLL, Real kiPLL, Real kpPowerCtrl,
181 Real kiPowerCtrl, Real kpCurrCtrl,
182 Real kiCurrCtrl, Real omegaCutoff);
183
185 void setFilterParameters(Real lf, Real cf, Real rf);
186
191 void setInitialStateValues(Real pInit, Real qInit, Real phiDInit,
192 Real phiQInit, Real gammaDInit, Real gammaQInit);
193
194 void withControl(Bool controlOn) { mWithControl = controlOn; }
195
196 // -------------------------------------------------------------------------
197 // Initialization
198 // -------------------------------------------------------------------------
199 void initializeParentFromNodesAndTerminals(Real frequency) override;
200
201 // -------------------------------------------------------------------------
202 // MNA
203 // -------------------------------------------------------------------------
204 void mnaParentInitialize(Real omega, Real timeStep,
205 Attribute<Matrix>::Ptr leftVector) override;
206 void mnaParentApplySystemMatrixStamp(SparseMatrixRow &systemMatrix) override;
207 void mnaParentApplyRightSideVectorStamp(Matrix &rightVector) override;
208
209 void mnaCompUpdateCurrent(const Matrix &leftVector) override;
210 void mnaCompUpdateVoltage(const Matrix &leftVector) override;
211
212 void mnaParentPreStep(Real time, Int timeStepCount) override;
213
214 void mnaParentPostStep(Real time, Int timeStepCount,
215 Attribute<Matrix>::Ptr &leftVector) override;
216
218 AttributeBase::List &prevStepDependencies,
219 AttributeBase::List &attributeDependencies,
220 AttributeBase::List &modifiedAttributes) override;
221
222 void
224 AttributeBase::List &attributeDependencies,
225 AttributeBase::List &modifiedAttributes,
226 Attribute<Matrix>::Ptr &leftVector) override;
227
228 // -------------------------------------------------------------------------
229 // Control
230 // -------------------------------------------------------------------------
231 void controlPreStep(Real time, Int timeStepCount);
232 void controlStep(Real time, Int timeStepCount);
233
234 void addControlPreStepDependencies(AttributeBase::List &prevStepDependencies,
235 AttributeBase::List &attributeDependencies,
236 AttributeBase::List &modifiedAttributes);
237
238 void addControlStepDependencies(AttributeBase::List &prevStepDependencies,
239 AttributeBase::List &attributeDependencies,
240 AttributeBase::List &modifiedAttributes);
241
242 class ControlPreStep : public CPS::Task {
243 public:
244 explicit ControlPreStep(GFL &gfl)
245 : Task(**gfl.mName + ".ControlPreStep"), mGFL(gfl) {
246 mGFL.addControlPreStepDependencies(
248 }
249
250 void execute(Real time, Int timeStepCount) override {
251 mGFL.controlPreStep(time, timeStepCount);
252 }
253
254 private:
255 GFL &mGFL;
256 };
257
258 class ControlStep : public CPS::Task {
259 public:
260 explicit ControlStep(GFL &gfl)
261 : Task(**gfl.mName + ".ControlStep"), mGFL(gfl) {
262 mGFL.addControlStepDependencies(
264 }
265
266 void execute(Real time, Int timeStepCount) override {
267 mGFL.controlStep(time, timeStepCount);
268 }
269
270 private:
271 GFL &mGFL;
272 };
273};
274
275} // namespace Ph3
276} // namespace EMT
277} // namespace CPS
std::vector< Ptr > List
Definition Attribute.h:123
AttributePointer< Attribute< T > > Ptr
Definition Attribute.h:249
CompositePowerComp(String uid, String name, Bool hasPreStep, Bool hasPostStep, Logger::Level logLevel)
void execute(Real time, Int timeStepCount) override
void execute(Real time, Int timeStepCount) override
Matrix mDirectCapacitorCurrent
Definition EMT_Ph3_GFL.h:99
void setInitialStateValues(Real pInit, Real qInit, Real phiDInit, Real phiQInit, Real gammaDInit, Real gammaQInit)
const Attribute< Real >::Ptr mIgridQ
MatrixFixedSize< 2, 1 > parkTransformPowerInvariant(Real theta, const Matrix &fabc) const
const Attribute< Matrix >::Ptr mPowerctrlStates
const Attribute< Matrix >::Ptr mPowerctrlInputs
Power-controller logging vectors.
void controlPreStep(Real time, Int timeStepCount)
void mnaParentPreStep(Real time, Int timeStepCount) override
void updateMeasurementAttributes(Real theta)
void addControlStepDependencies(AttributeBase::List &prevStepDependencies, AttributeBase::List &attributeDependencies, AttributeBase::List &modifiedAttributes)
Matrix mDirectInductorVoltage
Definition EMT_Ph3_GFL.h:96
SimPowerComp< Real >::Ptr clone(String name) override
Returns a modified copy of the component with the given suffix added to the name and without.
void mnaCompUpdateCurrent(const Matrix &leftVector) override
void mnaCompUpdateVoltage(const Matrix &leftVector) override
std::shared_ptr< EMT::Ph3::Capacitor > mSubCapacitorF
Definition EMT_Ph3_GFL.h:91
GFL(String name, Bool useSubcomponents, Logger::Level logLevel=Logger::Level::off)
void addControlPreStepDependencies(AttributeBase::List &prevStepDependencies, AttributeBase::List &attributeDependencies, AttributeBase::List &modifiedAttributes)
GFL(String name, Logger::Level logLevel=Logger::Level::off)
const Attribute< Matrix >::Ptr mPowerctrlOutputs
void setFilterParameters(Real lf, Real cf, Real rf)
Filter parameters. No Rc exists in this model.
Matrix mDirectInductorConductance
Definition EMT_Ph3_GFL.h:94
const Attribute< Real >::Ptr mVcd
PCC voltage in controller dq frame.
const Attribute< Real >::Ptr mVcq
Matrix mDirectInductorCurrent
Definition EMT_Ph3_GFL.h:97
void setControllerParameters(Real kpPLL, Real kiPLL, Real kpPowerCtrl, Real kiPowerCtrl, Real kpCurrCtrl, Real kiCurrCtrl, Real omegaCutoff)
Controller parameters.
const Attribute< Real >::Ptr mPInst
Instantaneous controller-frame active/reactive power.
Bool mControllerParametersSet
Definition EMT_Ph3_GFL.h:68
Matrix mDirectCapacitorHistory
void setParameters(Real sysOmega, Real sysVoltNom, Real pRef, Real qRef)
General operating parameters.
const Attribute< Matrix >::Ptr mPllOutput
PLL output [theta, phi_pll].
void mnaParentPostStep(Real time, Int timeStepCount, Attribute< Matrix >::Ptr &leftVector) override
std::shared_ptr< Signal::PLL > mPLL
Definition EMT_Ph3_GFL.h:82
std::shared_ptr< EMT::Ph3::Inductor > mSubInductorF
Definition EMT_Ph3_GFL.h:90
void withControl(Bool controlOn)
const Attribute< Real >::Ptr mOmegaPLL
Estimated PLL angular frequency [rad/s].
Matrix mDirectSourceVoltage
void mnaParentApplyRightSideVectorStamp(Matrix &rightVector) override
void initializeParentFromNodesAndTerminals(Real frequency) override
const Attribute< Matrix >::Ptr mVs
Actual controlled source voltage.
std::shared_ptr< Signal::PowerControllerVSI > mPowerControllerVSI
Definition EMT_Ph3_GFL.h:83
const Attribute< Matrix >::Ptr mVsref
Controlled source voltage reference in abc instantaneous peak values.
std::shared_ptr< EMT::Ph3::VoltageSource > mSubControlledVoltageSource
Definition EMT_Ph3_GFL.h:88
const Attribute< Real >::Ptr mIgridD
Positive converter-to-grid current in controller dq frame.
void mnaParentAddPostStepDependencies(AttributeBase::List &prevStepDependencies, AttributeBase::List &attributeDependencies, AttributeBase::List &modifiedAttributes, Attribute< Matrix >::Ptr &leftVector) override
MatrixFixedSize< 3, 1 > inverseParkTransformPowerInvariant(Real theta, const Matrix &fdq) const
void controlStep(Real time, Int timeStepCount)
std::shared_ptr< EMT::Ph3::Resistor > mSubResistorF
Definition EMT_Ph3_GFL.h:89
Matrix mDirectCapacitorConductance
Definition EMT_Ph3_GFL.h:95
const Attribute< Matrix >::Ptr mDirectSourceVoltageAttr
Storage for the source voltage in direct mode, exposed through mVs.
void mnaParentApplySystemMatrixStamp(SparseMatrixRow &systemMatrix) override
MatrixFixedSize< 2, 3 > getParkTransformMatrixPowerInvariant(Real theta) const
void updatePowerAndFrequencyAttributes()
Matrix mDirectInductorHistory
Definition EMT_Ph3_GFL.h:98
Matrix mDirectResistorConductance
Definition EMT_Ph3_GFL.h:93
MatrixFixedSize< 3, 2 > getInverseParkTransformMatrixPowerInvariant(Real theta) const
void mnaParentInitialize(Real omega, Real timeStep, Attribute< Matrix >::Ptr leftVector) override
void mnaParentAddPreStepDependencies(AttributeBase::List &prevStepDependencies, AttributeBase::List &attributeDependencies, AttributeBase::List &modifiedAttributes) override
const Attribute< Real >::Ptr mQInst
GFL(String uid, String name, Logger::Level logLevel=Logger::Level::off)
String uid()
Returns unique id.
spdlog::level::level_enum Level
Definition Logger.h:33
std::shared_ptr< SimPowerComp< VarType > > Ptr
Tasks to be defined by every component.
Definition Task.h:25
std::vector< AttributeBase::Ptr > mModifiedAttributes
Definition Task.h:70
std::vector< AttributeBase::Ptr > mPrevStepDependencies
Definition Task.h:71
std::vector< AttributeBase::Ptr > mAttributeDependencies
Definition Task.h:69
Task()
Definition Task.h:30
std::string mName
Definition Task.h:68
static std::shared_ptr< GFL > make(Args &&...args)
Definition PtrFactory.h:19
Eigen::Matrix< Real, Eigen::Dynamic, Eigen::Dynamic, Eigen::ColMajor > Matrix
Dense matrix for real numbers.
Definition Definitions.h:79
std::string String
Definition Definitions.h:63
Eigen::Matrix< Real, rows, cols, Eigen::ColMajor > MatrixFixedSize
Dense matrix for real numbers with fixed dimension.
Definition Definitions.h:99
double Real
Definition Definitions.h:60
int Int
Definition Definitions.h:59
bool Bool
Definition Definitions.h:62
Eigen::SparseMatrix< Real, Eigen::RowMajor > SparseMatrixRow
Sparse matrix for real numbers (row major).
Definition Definitions.h:72