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
70
77
78 // -------------------------------------------------------------------------
79 // Control subcomponents
80 // -------------------------------------------------------------------------
81 std::shared_ptr<Signal::PLL> mPLL;
82 std::shared_ptr<Signal::PowerControllerVSI> mPowerControllerVSI;
83
84 // -------------------------------------------------------------------------
85 // Electrical subcomponents
86 // -------------------------------------------------------------------------
87 std::shared_ptr<EMT::Ph3::VoltageSource> mSubControlledVoltageSource;
88 std::shared_ptr<EMT::Ph3::Resistor> mSubResistorF;
89 std::shared_ptr<EMT::Ph3::Inductor> mSubInductorF;
90 std::shared_ptr<EMT::Ph3::Capacitor> mSubCapacitorF;
91
92 // -------------------------------------------------------------------------
93 // Helpers
94 // -------------------------------------------------------------------------
97
98 Matrix parkTransformPowerInvariant(Real theta, const Matrix &fabc) const;
100 const Matrix &fdq) const;
101
104
105public:
107
108 // -------------------------------------------------------------------------
109 // Public attributes
110 // -------------------------------------------------------------------------
111
115
119
123
126
129
132
135
140
141 // -------------------------------------------------------------------------
142 // Construction
143 // -------------------------------------------------------------------------
144 GFL(String uid, String name, Logger::Level logLevel = Logger::Level::off);
145
146 GFL(String name, Logger::Level logLevel = Logger::Level::off)
147 : GFL(name, name, logLevel) {}
148
150
151 // -------------------------------------------------------------------------
152 // Parameters
153 // -------------------------------------------------------------------------
154
156 void setParameters(Real sysOmega, Real sysVoltNom, Real pRef, Real qRef);
157
159 void setControllerParameters(Real kpPLL, Real kiPLL, Real kpPowerCtrl,
160 Real kiPowerCtrl, Real kpCurrCtrl,
161 Real kiCurrCtrl, Real omegaCutoff);
162
164 void setFilterParameters(Real lf, Real cf, Real rf);
165
170 void setInitialStateValues(Real pInit, Real qInit, Real phiDInit,
171 Real phiQInit, Real gammaDInit, Real gammaQInit);
172
173 void withControl(Bool controlOn) { mWithControl = controlOn; }
174
175 // -------------------------------------------------------------------------
176 // Initialization
177 // -------------------------------------------------------------------------
178 void initializeParentFromNodesAndTerminals(Real frequency) override;
179
180 // -------------------------------------------------------------------------
181 // MNA
182 // -------------------------------------------------------------------------
183 void mnaParentInitialize(Real omega, Real timeStep,
184 Attribute<Matrix>::Ptr leftVector) override;
185
186 void mnaCompUpdateCurrent(const Matrix &leftVector) override;
187 void mnaCompUpdateVoltage(const Matrix &leftVector) override;
188
189 void mnaParentPreStep(Real time, Int timeStepCount) override;
190
191 void mnaParentPostStep(Real time, Int timeStepCount,
192 Attribute<Matrix>::Ptr &leftVector) override;
193
195 AttributeBase::List &prevStepDependencies,
196 AttributeBase::List &attributeDependencies,
197 AttributeBase::List &modifiedAttributes) override;
198
199 void
201 AttributeBase::List &attributeDependencies,
202 AttributeBase::List &modifiedAttributes,
203 Attribute<Matrix>::Ptr &leftVector) override;
204
205 // -------------------------------------------------------------------------
206 // Control
207 // -------------------------------------------------------------------------
208 void controlPreStep(Real time, Int timeStepCount);
209 void controlStep(Real time, Int timeStepCount);
210
211 void addControlPreStepDependencies(AttributeBase::List &prevStepDependencies,
212 AttributeBase::List &attributeDependencies,
213 AttributeBase::List &modifiedAttributes);
214
215 void addControlStepDependencies(AttributeBase::List &prevStepDependencies,
216 AttributeBase::List &attributeDependencies,
217 AttributeBase::List &modifiedAttributes);
218
219 class ControlPreStep : public CPS::Task {
220 public:
221 explicit ControlPreStep(GFL &gfl)
222 : Task(**gfl.mName + ".ControlPreStep"), mGFL(gfl) {
223 mGFL.addControlPreStepDependencies(
225 }
226
227 void execute(Real time, Int timeStepCount) override {
228 mGFL.controlPreStep(time, timeStepCount);
229 }
230
231 private:
232 GFL &mGFL;
233 };
234
235 class ControlStep : public CPS::Task {
236 public:
237 explicit ControlStep(GFL &gfl)
238 : Task(**gfl.mName + ".ControlStep"), mGFL(gfl) {
239 mGFL.addControlStepDependencies(
241 }
242
243 void execute(Real time, Int timeStepCount) override {
244 mGFL.controlStep(time, timeStepCount);
245 }
246
247 private:
248 GFL &mGFL;
249 };
250};
251
252} // namespace Ph3
253} // namespace EMT
254} // 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 parkTransformPowerInvariant(Real theta, const Matrix &fabc) const
void setInitialStateValues(Real pInit, Real qInit, Real phiDInit, Real phiQInit, Real gammaDInit, Real gammaQInit)
const Attribute< Real >::Ptr mIgridQ
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)
SimPowerComp< Real >::Ptr clone(String name) override
Returns a modified copy of the component with the given suffix added to the name and without.
Matrix inverseParkTransformPowerInvariant(Real theta, const Matrix &fdq) const
void mnaCompUpdateCurrent(const Matrix &leftVector) override
Matrix getInverseParkTransformMatrixPowerInvariant(Real theta) const
void mnaCompUpdateVoltage(const Matrix &leftVector) override
std::shared_ptr< EMT::Ph3::Capacitor > mSubCapacitorF
Definition EMT_Ph3_GFL.h:90
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.
const Attribute< Real >::Ptr mVcd
PCC voltage in controller dq frame.
const Attribute< Real >::Ptr mVcq
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
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:81
std::shared_ptr< EMT::Ph3::Inductor > mSubInductorF
Definition EMT_Ph3_GFL.h:89
void withControl(Bool controlOn)
const Attribute< Real >::Ptr mOmegaPLL
Estimated PLL angular frequency [rad/s].
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:82
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:87
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
void controlStep(Real time, Int timeStepCount)
std::shared_ptr< EMT::Ph3::Resistor > mSubResistorF
Definition EMT_Ph3_GFL.h:88
Matrix getParkTransformMatrixPowerInvariant(Real theta) const
void updatePowerAndFrequencyAttributes()
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:53
std::vector< AttributeBase::Ptr > mPrevStepDependencies
Definition Task.h:54
std::vector< AttributeBase::Ptr > mAttributeDependencies
Definition Task.h:52
Task()
Definition Task.h:30
std::string mName
Definition Task.h:51
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:81
std::string String
Definition Definitions.h:65
double Real
Definition Definitions.h:62
int Int
Definition Definitions.h:61
bool Bool
Definition Definitions.h:64