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 // One scalar logging attribute per state, with unit-bearing, readable names.
138 std::vector<Attribute<Real>::Ptr> mStateLogAttributes;
139
140 // Reused workspaces for the per-step nonlinear state-space relinearization.
141 Matrix mStateDerivativeWorkspace = Matrix::Zero(mStateSize, 1);
142 Matrix mOutputWorkspace = Matrix::Zero(mOutputSize, 1);
143 Matrix mStateOffsetWorkspace = Matrix::Zero(mStateSize, 1);
144 Matrix mOutputOffsetWorkspace = Matrix::Zero(mOutputSize, 1);
145
146 // Optional fully implicit Newton correction context used by the benchmark.
147 // The normal EMT path leaves this disabled and retains one linearization.
148 Bool mImplicitNewtonActive = false;
149 Matrix mNewtonBaseState;
150 Matrix mNewtonBaseVoltage;
151 Matrix mNewtonBaseDerivative;
152 Matrix mNewtonGuessState;
153 Matrix mNewtonGuessVoltage;
154
155 MatrixFixedSize<2, 3> getParkTransformMatrix(Real theta) const;
156
157 MatrixFixedSize<3, 2> getInverseParkTransformMatrix(Real theta) const;
158
160 void evaluateStateDerivative(const Matrix &x, const Matrix &u,
161 Matrix &stateDerivative) const;
162
164 void evaluateOutput(const Matrix &x, const Matrix &u, Matrix &output) const;
165
167 void buildStateSpaceModel(const Matrix &x, const Matrix &u, Matrix &A,
168 Matrix &B, Matrix &C, Matrix &D, Matrix &E,
169 Matrix &F);
170
172 Real regularizedOmega(Real omega) const;
173
174protected:
175 Bool updateComponentParameters() override final;
176
177 void updateLogAttributes(const Matrix &u) const override final;
178
179public:
181
182 SSN_GFM(String uid, String name, Logger::Level logLevel = Logger::Level::off);
183
184 SSN_GFM(String name, Logger::Level logLevel = Logger::Level::off)
185 : SSN_GFM(name, name, logLevel) {}
186
187 std::vector<String> getLocalStateNames() const override final;
188 Matrix getState() const;
193 void setImplicitNewtonGuess(const Matrix &state, const Matrix &voltage);
197 std::vector<SSNComp::LocalAbcStateBlock>
198 getLocalAbcStateBlocks() const override final;
199
208 void setParameters(Real lf, Real cf, Real rf, Real rc, Real nominalVoltage,
209 Real omegaN, Real pRef, Real qRef, Real virtualInertia,
210 Real dampingCoefficient, Real voltageDroopGain,
211 Real reactiveIntegralGain, Real kpVoltage, Real kiVoltage,
212 Real kpCurrent, Real kiCurrent, Real activeDampingGain,
213 Real powerFilterCutoff, Real delayBandwidth);
214
217 Real absoluteStep);
218
222 void setVirtualImpedance(Real virtualResistance, Real virtualReactance = 0.0);
223
226
229 void setReactivePowerDroop(Real droopGain, Real cutoff);
230
232 void calculateAnalyticalJacobians(const Matrix &x, const Matrix &u, Matrix &A,
233 Matrix &B, Matrix &C, Matrix &D) const;
234
237 void calculateNumericalJacobians(const Matrix &x, const Matrix &u, Matrix &A,
238 Matrix &B, Matrix &C, Matrix &D) const;
239
240 void initializeFromNodesAndTerminals(Real frequency) override final;
241};
242
243} // namespace Ph3
244} // namespace EMT
245} // 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 setImplicitNewtonGuess(const Matrix &state, const Matrix &voltage)
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: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