Skip to content

Commit bafb741

Browse files
Generalized linear two terminal State Space Nodal component models (#406)
2 parents 2ff82a9 + ff0965c commit bafb741

15 files changed

Lines changed: 2249 additions & 6 deletions

dpsim-models/include/dpsim-models/Components.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,9 @@
8787
#include <dpsim-models/EMT/EMT_Ph1_CurrentSource.h>
8888
#include <dpsim-models/EMT/EMT_Ph1_Inductor.h>
8989
#include <dpsim-models/EMT/EMT_Ph1_Resistor.h>
90+
#include <dpsim-models/EMT/EMT_Ph1_SSNTypeI2T.h>
91+
#include <dpsim-models/EMT/EMT_Ph1_SSNTypeV2T.h>
92+
#include <dpsim-models/EMT/EMT_Ph1_SSN_Full_Serial_RLC.h>
9093
#include <dpsim-models/EMT/EMT_Ph1_Switch.h>
9194
#include <dpsim-models/EMT/EMT_Ph1_VoltageSource.h>
9295
#include <dpsim-models/EMT/EMT_Ph1_VoltageSourceNorton.h>
Lines changed: 93 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,93 @@
1+
// SPDX-FileCopyrightText: 2025 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 <dpsim-models/MNASimPowerComp.h>
7+
#include <dpsim-models/Solver/MNAInterface.h>
8+
9+
namespace CPS {
10+
namespace EMT {
11+
namespace Ph1 {
12+
/// \brief SSNTypeI2T
13+
/// Model for a one phase, two terminal I-type SSN component which can be represented using
14+
/// a state space equation system
15+
/// x' = A * x + B * u
16+
/// y = C * x + D * u
17+
/// with x: state vector, y: output vector, u: input vector,
18+
/// where u represents external current (mIntfCurrent),
19+
/// y represents external voltage (mIntfVoltage),
20+
/// x represents any component states.
21+
class SSNTypeI2T : public MNASimPowerComp<Real>,
22+
public SharedFactory<SSNTypeI2T> {
23+
private:
24+
void ssnUpdateState();
25+
void setSSNMatricesToZero();
26+
27+
protected:
28+
Matrix mX;
29+
Matrix mU;
30+
Matrix mUOld;
31+
Matrix mW;
32+
Matrix mYHist;
33+
34+
public:
35+
const CPS::Attribute<Matrix>::Ptr mA;
36+
const CPS::Attribute<Matrix>::Ptr mB;
37+
const CPS::Attribute<Matrix>::Ptr mC;
38+
const CPS::Attribute<Matrix>::Ptr mD;
39+
40+
const CPS::Attribute<Matrix>::Ptr mdA;
41+
const CPS::Attribute<Matrix>::Ptr mdB;
42+
const CPS::Attribute<Matrix>::Ptr mdC;
43+
44+
/// Defines UID, name, component parameters and logging level
45+
SSNTypeI2T(String uid, String name,
46+
Logger::Level logLevel = Logger::Level::off);
47+
/// Defines name and logging level
48+
SSNTypeI2T(String name, Logger::Level logLevel = Logger::Level::off)
49+
: SSNTypeI2T(name, name, logLevel) {}
50+
51+
SimPowerComp<Real>::Ptr clone(String name) override;
52+
53+
void manualInit(Matrix initialState, Matrix initialInput,
54+
Matrix initialOldInput, Real initCurrent, Real initVoltage);
55+
// #### General ####
56+
void setParameters(const Matrix A, const Matrix B, const Matrix C,
57+
const Matrix D);
58+
/// Initializes component from power flow data
59+
void initializeFromNodesAndTerminals(Real frequency) override;
60+
61+
// #### MNA section ####
62+
/// Initializes internal variables of the component
63+
void mnaCompInitialize(Real omega, Real timeStep,
64+
Attribute<Matrix>::Ptr leftVector) override;
65+
/// Stamps system matrix
66+
void mnaCompApplySystemMatrixStamp(SparseMatrixRow &systemMatrix) override;
67+
/// Stamps right side (source) vector
68+
void mnaCompApplyRightSideVectorStamp(Matrix &rightVector) override;
69+
/// Update interface voltage from MNA system result
70+
void mnaCompUpdateVoltage(const Matrix &leftVector) override;
71+
/// Update interface current from MNA system result
72+
void mnaCompUpdateCurrent(const Matrix &leftVector) override;
73+
74+
void mnaCompPreStep(Real time, Int timeStepCount) override;
75+
void mnaCompPostStep(Real time, Int timeStepCount,
76+
Attribute<Matrix>::Ptr &leftVector) override;
77+
78+
/// Add MNA pre step dependencies
79+
void mnaCompAddPreStepDependencies(
80+
AttributeBase::List &prevStepDependencies,
81+
AttributeBase::List &attributeDependencies,
82+
AttributeBase::List &modifiedAttributes) override;
83+
84+
/// Add MNA post step dependencies
85+
void
86+
mnaCompAddPostStepDependencies(AttributeBase::List &prevStepDependencies,
87+
AttributeBase::List &attributeDependencies,
88+
AttributeBase::List &modifiedAttributes,
89+
Attribute<Matrix>::Ptr &leftVector) override;
90+
};
91+
} // namespace Ph1
92+
} // namespace EMT
93+
} // namespace CPS
Lines changed: 94 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,94 @@
1+
// SPDX-FileCopyrightText: 2025 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 <dpsim-models/MNASimPowerComp.h>
7+
#include <dpsim-models/Solver/MNAInterface.h>
8+
9+
namespace CPS {
10+
namespace EMT {
11+
namespace Ph1 {
12+
/// \brief SSNTypeV2T
13+
/// Model for a one phase, two terminal V-type SSN component which can be represented using
14+
/// a state space equation system
15+
/// x' = A * x + B * u
16+
/// y = C * x + D * u
17+
/// with x: state vector, y: output vector, u: input vector,
18+
/// where u represents external voltage (mIntfVoltage),
19+
/// y represents external current (mIntfCurrent),
20+
/// x represents any component states.
21+
class SSNTypeV2T : public MNASimPowerComp<Real>,
22+
public SharedFactory<SSNTypeV2T> {
23+
private:
24+
void ssnUpdateState();
25+
void setSSNMatricesToZero();
26+
27+
protected:
28+
Matrix mX;
29+
Matrix mU;
30+
Matrix mUOld;
31+
Matrix mW;
32+
Matrix mYHist;
33+
34+
public:
35+
const CPS::Attribute<Matrix>::Ptr mA;
36+
const CPS::Attribute<Matrix>::Ptr mB;
37+
const CPS::Attribute<Matrix>::Ptr mC;
38+
const CPS::Attribute<Matrix>::Ptr mD;
39+
40+
const CPS::Attribute<Matrix>::Ptr mdA;
41+
const CPS::Attribute<Matrix>::Ptr mdB;
42+
const CPS::Attribute<Matrix>::Ptr mdC;
43+
44+
/// Defines UID, name, component parameters and logging level
45+
SSNTypeV2T(String uid, String name,
46+
Logger::Level logLevel = Logger::Level::off);
47+
/// Defines name and logging level
48+
SSNTypeV2T(String name, Logger::Level logLevel = Logger::Level::off)
49+
: SSNTypeV2T(name, name, logLevel) {}
50+
51+
SimPowerComp<Real>::Ptr clone(String name) override;
52+
53+
void manualInit(Matrix initialState, Matrix initialInput,
54+
Matrix initialOldInput, Real initCurrent, Real initVoltage);
55+
56+
// #### General ####
57+
void setParameters(const Matrix A, const Matrix B, const Matrix C,
58+
const Matrix D);
59+
/// Initializes component from power flow data
60+
void initializeFromNodesAndTerminals(Real frequency) override;
61+
62+
// #### MNA section ####
63+
/// Initializes internal variables of the component
64+
void mnaCompInitialize(Real omega, Real timeStep,
65+
Attribute<Matrix>::Ptr leftVector) override;
66+
/// Stamps system matrix
67+
void mnaCompApplySystemMatrixStamp(SparseMatrixRow &systemMatrix) override;
68+
/// Stamps right side (source) vector
69+
void mnaCompApplyRightSideVectorStamp(Matrix &rightVector) override;
70+
/// Update interface voltage from MNA system result
71+
void mnaCompUpdateVoltage(const Matrix &leftVector) override;
72+
/// Update interface current from MNA system result
73+
void mnaCompUpdateCurrent(const Matrix &leftVector) override;
74+
75+
void mnaCompPreStep(Real time, Int timeStepCount) override;
76+
void mnaCompPostStep(Real time, Int timeStepCount,
77+
Attribute<Matrix>::Ptr &leftVector) override;
78+
79+
/// Add MNA pre step dependencies
80+
void mnaCompAddPreStepDependencies(
81+
AttributeBase::List &prevStepDependencies,
82+
AttributeBase::List &attributeDependencies,
83+
AttributeBase::List &modifiedAttributes) override;
84+
85+
/// Add MNA post step dependencies
86+
void
87+
mnaCompAddPostStepDependencies(AttributeBase::List &prevStepDependencies,
88+
AttributeBase::List &attributeDependencies,
89+
AttributeBase::List &modifiedAttributes,
90+
Attribute<Matrix>::Ptr &leftVector) override;
91+
};
92+
} // namespace Ph1
93+
} // namespace EMT
94+
} // namespace CPS
Lines changed: 100 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,100 @@
1+
// SPDX-FileCopyrightText: 2025 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 <dpsim-models/Base/Base_Ph1_Capacitor.h>
7+
#include <dpsim-models/Base/Base_Ph1_Inductor.h>
8+
#include <dpsim-models/Base/Base_Ph1_Resistor.h>
9+
#include <dpsim-models/MNASimPowerComp.h>
10+
#include <dpsim-models/Solver/MNAInterface.h>
11+
12+
namespace CPS {
13+
namespace EMT {
14+
namespace Ph1 {
15+
namespace SSN {
16+
/// \brief Full_Serial_RLC
17+
///
18+
/// This element represents an one port circuit consisting of a resistor,
19+
/// an inductor and a capacitor connected in series. The terminals are at
20+
/// the beginning and the end of the component chain.
21+
/// The states are the capacitor voltage and the inductor current, the output
22+
/// is the latter of those states (inductor current). The input is the voltage
23+
/// across the whole circuit. States and past inputs are updated after each
24+
/// time step and are used to calculate the current (input) voltage,
25+
/// represented as MNA node voltages.
26+
/// SSN theory and variable naming based on
27+
/// C. Dufour, J. Mahseredjian and J. Belanger,
28+
/// "A combined state-space nodal method for the simulation of power system
29+
/// transients," 2011 IEEE Power and Energy Society General Meeting, Detroit,
30+
/// MI, USA, 2011, pp. 1-1, doi: 10.1109/PES.2011.6038887. keywords:
31+
/// {Mathematical model;Analytical models;Equations;Power system transients;
32+
/// Couplings;Switching circuits}
33+
34+
class Full_Serial_RLC final : public MNASimPowerComp<Real>,
35+
public SharedFactory<Full_Serial_RLC>,
36+
public Base::Ph1::Resistor,
37+
public Base::Ph1::Inductor,
38+
public Base::Ph1::Capacitor {
39+
public:
40+
/// Defines UID, name, component parameters and logging level
41+
Full_Serial_RLC(String uid, String name,
42+
Logger::Level logLevel = Logger::Level::off);
43+
/// Defines name and logging level
44+
Full_Serial_RLC(String name, Logger::Level logLevel = Logger::Level::off)
45+
: Full_Serial_RLC(name, name, logLevel) {}
46+
47+
SimPowerComp<Real>::Ptr clone(String name) override;
48+
void setParameters(Real resistance, Real inductance, Real capacitance);
49+
50+
// #### General ####
51+
/// Initializes component from power flow data
52+
void initializeFromNodesAndTerminals(Real frequency) override;
53+
54+
// #### MNA section ####
55+
/// Initializes internal variables of the component
56+
void mnaCompInitialize(Real omega, Real timeStep,
57+
Attribute<Matrix>::Ptr leftVector) override;
58+
/// Stamps system matrix
59+
void mnaCompApplySystemMatrixStamp(SparseMatrixRow &systemMatrix) override;
60+
/// Stamps right side (source) vector
61+
void mnaCompApplyRightSideVectorStamp(Matrix &rightVector) override;
62+
/// Update interface voltage from MNA system result
63+
void mnaCompUpdateVoltage(const Matrix &leftVector) override;
64+
/// Update interface current from MNA system result
65+
void mnaCompUpdateCurrent(const Matrix &leftVector) override;
66+
/// MNA pre step operations
67+
void mnaCompPreStep(Real time, Int timeStepCount) override;
68+
/// MNA post step operations
69+
void mnaCompPostStep(Real time, Int timeStepCount,
70+
Attribute<Matrix>::Ptr &leftVector) override;
71+
/// Add MNA pre step dependencies
72+
void mnaCompAddPreStepDependencies(
73+
AttributeBase::List &prevStepDependencies,
74+
AttributeBase::List &attributeDependencies,
75+
AttributeBase::List &modifiedAttributes) override;
76+
/// Add MNA post step dependencies
77+
void
78+
mnaCompAddPostStepDependencies(AttributeBase::List &prevStepDependencies,
79+
AttributeBase::List &attributeDependencies,
80+
AttributeBase::List &modifiedAttributes,
81+
Attribute<Matrix>::Ptr &leftVector) override;
82+
83+
private:
84+
Matrix mState = Matrix::Zero(2, 1);
85+
Real mYHistory = 0;
86+
87+
Real mDufourUNT = 0;
88+
89+
Matrix mDufourAKHat = Matrix::Zero(2, 2);
90+
Matrix mDufourBKHat = Matrix::Zero(2, 1);
91+
Matrix mDufourBKNHat = Matrix::Zero(2, 1);
92+
Real mDufourWKN = 0;
93+
Matrix mDufourCKN = Matrix::Zero(1, 2);
94+
95+
void ssnUpdateState();
96+
};
97+
} // namespace SSN
98+
} // namespace Ph1
99+
} // namespace EMT
100+
} // namespace CPS

dpsim-models/include/dpsim-models/MathUtils.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,10 @@ class Math {
119119
const Matrix &C,
120120
const Real &dt, Matrix &Ad,
121121
Matrix &Bd, Matrix &Cd);
122+
static void calculateStateSpaceTrapezoidalMatrices(const Matrix &A,
123+
const Matrix &B,
124+
const Real &dt, Matrix &Ad,
125+
Matrix &Bd);
122126
/// Apply the trapezoidal based state space matrices Ad, Bd, Cd to get the states at the current time step
123127
static Matrix applyStateSpaceTrapezoidalMatrices(const Matrix &Ad,
124128
const Matrix &Bd,

dpsim-models/src/CMakeLists.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,9 @@ list(APPEND MODELS_SOURCES
7070
EMT/EMT_Ph1_VoltageSourceRamp.cpp
7171
EMT/EMT_Ph1_VoltageSourceNorton.cpp
7272
EMT/EMT_Ph1_Switch.cpp
73+
EMT/EMT_Ph1_SSN_Full_Serial_RLC.cpp
74+
EMT/EMT_Ph1_SSNTypeI2T.cpp
75+
EMT/EMT_Ph1_SSNTypeV2T.cpp
7376

7477
EMT/EMT_Ph3_CurrentSource.cpp
7578
EMT/EMT_Ph3_VoltageSource.cpp

0 commit comments

Comments
 (0)