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 calculateNumericalJacobians(const Matrix &x, const Matrix &u, Matrix &A,
151 Matrix &B, Matrix &C, Matrix &D) const;
152
154 void buildStateSpaceModel(const Matrix &x, const Matrix &u, Matrix &A,
155 Matrix &B, Matrix &C, Matrix &D, Matrix &E,
156 Matrix &F) const;
157
159 Real regularizedOmega(Real omega) const;
160
161protected:
162 Bool updateComponentParameters() override final;
163
164 void updateLogAttributes(const Matrix &u) const override final;
165
166public:
168
169 SSN_GFM(String uid, String name, Logger::Level logLevel = Logger::Level::off);
170
171 SSN_GFM(String name, Logger::Level logLevel = Logger::Level::off)
172 : SSN_GFM(name, name, logLevel) {}
173
174 std::vector<String> getLocalStateNames() const override final;
175 Matrix getState() const;
179 std::vector<SSNComp::LocalAbcStateBlock>
180 getLocalAbcStateBlocks() const override final;
181
190 void setParameters(Real lf, Real cf, Real rf, Real rc, Real nominalVoltage,
191 Real omegaN, Real pRef, Real qRef, Real virtualInertia,
192 Real dampingCoefficient, Real voltageDroopGain,
193 Real reactiveIntegralGain, Real kpVoltage, Real kiVoltage,
194 Real kpCurrent, Real kiCurrent, Real activeDampingGain,
195 Real powerFilterCutoff, Real delayBandwidth);
196
199 Real absoluteStep);
200
204 void setVirtualImpedance(Real virtualResistance, Real virtualReactance = 0.0);
205
208
211 void setReactivePowerDroop(Real droopGain, Real cutoff);
212
213 void initializeFromNodesAndTerminals(Real frequency) override final;
214};
215
216} // namespace Ph3
217} // namespace EMT
218} // namespace CPS
AttributePointer< Attribute< T > > Ptr
Definition Attribute.h:250
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 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