DPsim
Loading...
Searching...
No Matches
EMT_Ph3_SSN_GFM.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
6#include <vector>
7
9
10namespace CPS {
11namespace EMT {
12namespace Ph3 {
13
39 public SharedFactory<SSN_GFM> {
40
41private:
42 static constexpr Int mStateSize = 17;
43 static constexpr Int mInputSize = 3;
44 static constexpr Int mOutputSize = 3;
45
46 enum StateIndex : Int {
47 PFiltered = 0,
48 QFiltered = 1,
49 Omega = 2,
50 Theta = 3,
51 VoltageMagnitude = 4,
52
53 VoltageIntegratorD = 5,
54 VoltageIntegratorQ = 6,
55
56 CurrentIntegratorD = 7,
57 CurrentIntegratorQ = 8,
58
59 DelayVoltageD = 9,
60 DelayVoltageQ = 10,
61
62 VcA = 11,
63 VcB = 12,
64 VcC = 13,
65
66 IfA = 14,
67 IfB = 15,
68 IfC = 16
69 };
70
71 // Electrical parameters
72 Real mLf;
73 Real mCf;
74 Real mRf;
75 Real mRc;
76
77 // Nominal quantities and references
78 Real mOmegaN;
79 Real mNominalVoltage;
80 Real mPRef;
81 Real mQRef;
82
83 // VSG parameters
84 Real mVirtualInertia;
85 Real mDampingCoefficient;
86 Real mVoltageDroopGain;
87 Real mReactiveIntegralGain;
88
89 // Voltage controller
90 Real mKpVoltage;
91 Real mKiVoltage;
92
93 // Current controller
94 Real mKpCurrent;
95 Real mKiCurrent;
96
97 // Active damping and measurement dynamics
98 Real mActiveDampingGain;
99 Real mPowerFilterCutoff;
100 Real mDelayBandwidth;
101
102 // Virtual output impedance (opt-in). Zero recovers the islanded model.
103 Real mVirtualResistance;
104 Real mVirtualReactance;
105
106 // Scale on the grid-current feedforward in the voltage loop (1 = islanded).
107 Real mGridCurrentFeedforward;
108
109 // Proportional Q-V droop (opt-in). Cutoff > 0 selects droop over the integral
110 // excitation. Setpoint is captured at initialization.
111 Real mReactivePowerDroop;
112 Real mReactiveDroopCutoff;
113 Real mVoltageSetpoint;
114
115 // Numerical linearization settings
116 Real mJacobianRelativeStep;
117 Real mJacobianAbsoluteStep;
118
119 // Logging attributes
120 const Attribute<Real>::Ptr mPInst;
121 const Attribute<Real>::Ptr mQInst;
122 const Attribute<Real>::Ptr mOmegaGFM;
123 const Attribute<Real>::Ptr mThetaGFM;
124 const Attribute<Real>::Ptr mVoltageMagnitudeGFM;
125
126 const Attribute<Real>::Ptr mVcD;
127 const Attribute<Real>::Ptr mVcQ;
128
129 const Attribute<Real>::Ptr mIGridD;
130 const Attribute<Real>::Ptr mIGridQ;
131
132 const Attribute<Real>::Ptr mIfD;
133 const Attribute<Real>::Ptr mIfQ;
134
135 const Attribute<Real>::Ptr mVoltageReferenceD;
136 const Attribute<Real>::Ptr mVoltageReferenceQ;
137
138 Matrix getParkTransformMatrix(Real theta) const;
139
140 Matrix getInverseParkTransformMatrix(Real theta) const;
141
143 void evaluateStateDerivative(const Matrix &x, const Matrix &u,
144 Matrix &stateDerivative) const;
145
147 void evaluateOutput(const Matrix &x, const Matrix &u, Matrix &output) const;
148
150 void buildStateSpaceModel(const Matrix &x, const Matrix &u, Matrix &A,
151 Matrix &B, Matrix &C, Matrix &D, Matrix &E,
152 Matrix &F) const;
153
155 Real regularizedOmega(Real omega) const;
156
157protected:
158 Bool updateComponentParameters() override final;
159
160 void updateLogAttributes(const Matrix &u) const override final;
161
162public:
164
165 SSN_GFM(String uid, String name, Logger::Level logLevel = Logger::Level::off);
166
167 SSN_GFM(String name, Logger::Level logLevel = Logger::Level::off)
168 : SSN_GFM(name, name, logLevel) {}
169
170 std::vector<String> getLocalStateNames() const override final;
171 Matrix getState() const;
175 std::vector<SSNComp::LocalAbcStateBlock>
176 getLocalAbcStateBlocks() const override final;
177
186 void setParameters(Real lf, Real cf, Real rf, Real rc, Real nominalVoltage,
187 Real omegaN, Real pRef, Real qRef, Real virtualInertia,
188 Real dampingCoefficient, Real voltageDroopGain,
189 Real reactiveIntegralGain, Real kpVoltage, Real kiVoltage,
190 Real kpCurrent, Real kiCurrent, Real activeDampingGain,
191 Real powerFilterCutoff, Real delayBandwidth);
192
195 Real absoluteStep);
196
200 void setVirtualImpedance(Real virtualResistance, Real virtualReactance = 0.0);
201
204
207 void setReactivePowerDroop(Real droopGain, Real cutoff);
208
210 void calculateAnalyticalJacobians(const Matrix &x, const Matrix &u, Matrix &A,
211 Matrix &B, Matrix &C, Matrix &D) const;
212
215 void calculateNumericalJacobians(const Matrix &x, const Matrix &u, Matrix &A,
216 Matrix &B, Matrix &C, Matrix &D) const;
217
218 void initializeFromNodesAndTerminals(Real frequency) override final;
219};
220
221} // namespace Ph3
222} // namespace EMT
223} // namespace CPS
AttributePointer< Attribute< T > > Ptr
Definition Attribute.h:249
void calculateNumericalJacobians(const Matrix &x, const Matrix &u, Matrix &A, Matrix &B, Matrix &C, Matrix &D) const
Numerically calculate A, B, C and D by central differences, as the reference for EMT_Ph3_SSN_GFM_Jaco...
void setNumericalLinearizationParameters(Real relativeStep, Real absoluteStep)
Configure finite-difference steps for local linearization.
SSN_GFM(String uid, String name, Logger::Level logLevel=Logger::Level::off)
Matrix getStateDerivative() const
Bool updateComponentParameters() override final
Matrix getInterfaceCurrent() const
std::vector< SSNComp::LocalAbcStateBlock > getLocalAbcStateBlocks() const override final
Matrix getInterfaceVoltage() const
void updateLogAttributes(const Matrix &u) const override final
Update derived attributes used for logging/inspection.
void setReactivePowerDroop(Real droopGain, Real cutoff)
Opt-in proportional Q-V droop replacing the integral excitation. droopGain is Dq [V/var]; cutoff [rad...
void setParameters(Real lf, Real cf, Real rf, Real rc, Real nominalVoltage, Real omegaN, Real pRef, Real qRef, Real virtualInertia, Real dampingCoefficient, Real voltageDroopGain, Real reactiveIntegralGain, Real kpVoltage, Real kiVoltage, Real kpCurrent, Real kiCurrent, Real activeDampingGain, Real powerFilterCutoff, Real delayBandwidth)
Configure the GFM model.
std::vector< String > getLocalStateNames() const override final
void calculateAnalyticalJacobians(const Matrix &x, const Matrix &u, Matrix &A, Matrix &B, Matrix &C, Matrix &D) const
Analytically calculate A, B, C and D, as the simulation does.
void setGridCurrentFeedforward(Real scale)
Scale on the voltage-loop grid-current feedforward (default 1).
void setVirtualImpedance(Real virtualResistance, Real virtualReactance=0.0)
Opt-in virtual output impedance Zv = Rv + jXv, subtracted from the EMF reference across the filter cu...
void initializeFromNodesAndTerminals(Real frequency) override final
Initializes Component variables according to power flow data stored in Nodes.
SSN_GFM(String name, Logger::Level logLevel=Logger::Level::off)
TwoTerminalVTypeVariableSSNComp(String uid, String name, Logger::Level logLevel=Logger::Level::off)
Abstract base class for EMT state-space nodal (SSN) components.
Definition EMT_SSNComp.h:24
String uid()
Returns unique id.
spdlog::level::level_enum Level
Definition Logger.h:33
static std::shared_ptr< SSN_GFM > 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