Skip to content

Commit 645a832

Browse files
Add variable SSN base and EMT 3-phase piecewise-linear inductor (sogno-platform#474)
This PR adds a variable EMT V-type SSN inheritance branch and a three-phase, two-terminal piecewise-linear inductor with flux state.
2 parents 361e4d7 + ac8fa99 commit 645a832

19 files changed

Lines changed: 1191 additions & 38 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,7 @@
8787

8888
#include <dpsim-models/EMT/EMT_SSNComp.h>
8989
#include <dpsim-models/EMT/EMT_VTypeSSNComp.h>
90+
#include <dpsim-models/EMT/EMT_VTypeVariableSSNComp.h>
9091

9192
#include <dpsim-models/EMT/EMT_Ph1_Capacitor.h>
9293
#include <dpsim-models/EMT/EMT_Ph1_CurrentSource.h>
@@ -132,13 +133,15 @@
132133
#endif
133134
#include <dpsim-models/EMT/EMT_Ph3_NetworkInjection.h>
134135
#include <dpsim-models/EMT/EMT_Ph3_PiLine.h>
136+
#include <dpsim-models/EMT/EMT_Ph3_PiecewiseLinearInductor.h>
135137
#include <dpsim-models/EMT/EMT_Ph3_RXLoad.h>
136138
#include <dpsim-models/EMT/EMT_Ph3_RxLine.h>
137139
#include <dpsim-models/EMT/EMT_Ph3_Switch.h>
138140
#include <dpsim-models/EMT/EMT_Ph3_SynchronGeneratorIdeal.h>
139141
#include <dpsim-models/EMT/EMT_Ph3_SynchronGeneratorTrStab.h>
140142
#include <dpsim-models/EMT/EMT_Ph3_SynchronGeneratorVBR.h>
141143
#include <dpsim-models/EMT/EMT_Ph3_Transformer.h>
144+
#include <dpsim-models/EMT/EMT_Ph3_TwoTerminalVTypeVariableSSNComp.h>
142145

143146
#include <dpsim-models/Signal/CosineFMGenerator.h>
144147
#include <dpsim-models/Signal/DecouplingLine.h>

dpsim-models/include/dpsim-models/EMT/EMT_Ph3_GenericTwoTerminalVTypeSSN.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ class GenericTwoTerminalVTypeSSN final
2525
Logger::Level logLevel = Logger::Level::off)
2626
: GenericTwoTerminalVTypeSSN(name, name, logLevel) {}
2727

28-
SimPowerComp<Real>::Ptr clone(String name) final;
28+
SimPowerComp<Real>::Ptr clone(String name) override final;
2929
};
3030

3131
} // namespace Ph3
Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
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+
8+
#include <dpsim-models/EMT/EMT_Ph3_TwoTerminalVTypeVariableSSNComp.h>
9+
10+
namespace CPS {
11+
namespace EMT {
12+
namespace Ph3 {
13+
14+
/// \brief Three-phase, two-terminal, piecewise-linear flux-state inductor.
15+
///
16+
/// The component uses the state choice
17+
///
18+
/// x = phi_abc
19+
/// u = v_abc
20+
/// y = i_abc
21+
///
22+
/// with
23+
///
24+
/// d(phi)/dt = v
25+
///
26+
/// and a piecewise-linear constitutive relation
27+
///
28+
/// i_abc = f(phi_abc)
29+
///
30+
/// The piecewise-linear characteristic is assumed to be odd-symmetric and is
31+
/// provided by non-negative breakpoint vectors for flux and current.
32+
class PiecewiseLinearInductor final
33+
: public TwoTerminalVTypeVariableSSNComp,
34+
public SharedFactory<PiecewiseLinearInductor> {
35+
private:
36+
std::vector<Real> mFluxBreakpoints;
37+
std::vector<Real> mCurrentBreakpoints;
38+
39+
std::pair<Real, Real> slopeAndOffsetFromFlux(Real flux) const;
40+
41+
protected:
42+
Bool updateComponentParameters() override final;
43+
44+
public:
45+
using SharedFactory<PiecewiseLinearInductor>::make;
46+
47+
PiecewiseLinearInductor(String uid, String name,
48+
Logger::Level logLevel = Logger::Level::off);
49+
PiecewiseLinearInductor(String name,
50+
Logger::Level logLevel = Logger::Level::off)
51+
: PiecewiseLinearInductor(name, name, logLevel) {}
52+
53+
SimPowerComp<Real>::Ptr clone(String name) override final;
54+
55+
void setParameters(const std::vector<Real> &fluxBreakpoints,
56+
const std::vector<Real> &currentBreakpoints);
57+
};
58+
59+
} // namespace Ph3
60+
} // namespace EMT
61+
} // namespace CPS

dpsim-models/include/dpsim-models/EMT/EMT_Ph3_SSN_Full_Serial_RLC.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ class Full_Serial_RLC final : public TwoTerminalVTypeSSNComp,
4141
Full_Serial_RLC(String name, Logger::Level logLevel = Logger::Level::off)
4242
: Full_Serial_RLC(name, name, logLevel) {}
4343

44-
SimPowerComp<Real>::Ptr clone(String name) override;
44+
SimPowerComp<Real>::Ptr clone(String name) override final;
4545

4646
void setParameters(const Matrix &resistance, const Matrix &inductance,
4747
const Matrix &capacitance);

dpsim-models/include/dpsim-models/EMT/EMT_Ph3_SSN_Inductor.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ class Inductor final : public TwoTerminalVTypeSSNComp,
3636
Inductor(String name, Logger::Level logLevel = Logger::Level::off)
3737
: Inductor(name, name, logLevel) {}
3838

39-
SimPowerComp<Real>::Ptr clone(String name) override;
39+
SimPowerComp<Real>::Ptr clone(String name) override final;
4040

4141
void setParameters(const Matrix &inductance);
4242
};

dpsim-models/include/dpsim-models/EMT/EMT_Ph3_TwoTerminalVTypeSSNComp.h

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,12 +21,13 @@ class TwoTerminalVTypeSSNComp : public VTypeSSNComp {
2121
TwoTerminalVTypeSSNComp(String uid, String name,
2222
Logger::Level logLevel = Logger::Level::off);
2323

24-
MatrixComp buildInitialInputFromNodes(Real frequency) final;
24+
MatrixComp buildInitialInputFromNodes(Real frequency) override final;
2525

2626
public:
27-
void mnaCompApplySystemMatrixStamp(SparseMatrixRow &systemMatrix) final;
28-
void mnaCompApplyRightSideVectorStamp(Matrix &rightVector) final;
29-
void mnaCompUpdateVoltage(const Matrix &leftVector) final;
27+
void
28+
mnaCompApplySystemMatrixStamp(SparseMatrixRow &systemMatrix) override final;
29+
void mnaCompApplyRightSideVectorStamp(Matrix &rightVector) override final;
30+
void mnaCompUpdateVoltage(const Matrix &leftVector) override final;
3031
};
3132

3233
} // namespace Ph3
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
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 <dpsim-models/EMT/EMT_VTypeVariableSSNComp.h>
7+
8+
namespace CPS {
9+
namespace EMT {
10+
namespace Ph3 {
11+
12+
/// \brief Abstract base class for three-phase, two-terminal, variable V-type
13+
/// SSN components.
14+
///
15+
/// This class implements the common three-phase/two-terminal logic:
16+
/// - reconstruction of the initial input voltage from terminal phasors
17+
/// - conductance matrix stamp
18+
/// - right-side history current stamp
19+
/// - interface voltage update from the MNA solution
20+
class TwoTerminalVTypeVariableSSNComp : public VTypeVariableSSNComp {
21+
protected:
22+
TwoTerminalVTypeVariableSSNComp(String uid, String name,
23+
Logger::Level logLevel = Logger::Level::off);
24+
25+
MatrixComp buildInitialInputFromNodes(Real frequency) override final;
26+
27+
public:
28+
void
29+
mnaCompApplySystemMatrixStamp(SparseMatrixRow &systemMatrix) override final;
30+
void mnaCompApplyRightSideVectorStamp(Matrix &rightVector) override final;
31+
void mnaCompUpdateVoltage(const Matrix &leftVector) override final;
32+
};
33+
34+
} // namespace Ph3
35+
} // namespace EMT
36+
} // namespace CPS

dpsim-models/include/dpsim-models/EMT/EMT_SSNComp.h

Lines changed: 24 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -11,14 +11,10 @@ namespace EMT {
1111

1212
/// \brief Abstract base class for EMT state-space nodal (SSN) components.
1313
///
14-
/// This class provides the generic state-space and scheduling logic shared by
15-
/// all SSN component types:
16-
/// - storage of state-space matrices A, B, C, D
17-
/// - calculation of trapezoidal discrete-time matrices
18-
/// - steady-state initialization helpers
19-
/// - history-vector calculation
20-
/// - state update
21-
/// - generic pre-step and post-step dependency registration
14+
/// This class implements the common linear SSN logic shared by derived
15+
/// component types, including state-space parameter storage, trapezoidal
16+
/// discretization, steady-state initialization helpers, history-vector
17+
/// calculation, state update, and generic MNA scheduling.
2218
///
2319
/// The exact interpretation of input and output quantities is defined in
2420
/// derived classes.
@@ -28,6 +24,8 @@ class SSNComp : public MNASimPowerComp<Real> {
2824
const Int mOutputSize;
2925

3026
protected:
27+
Real mTimeStep;
28+
3129
Matrix mW;
3230
Matrix mYHist;
3331

@@ -39,12 +37,12 @@ class SSNComp : public MNASimPowerComp<Real> {
3937
Matrix mdA;
4038
Matrix mdB;
4139

42-
const CPS::Attribute<Matrix>::Ptr mX;
40+
const Attribute<Matrix>::Ptr mX;
4341

4442
SSNComp(String uid, String name, Int inputSize, Int outputSize,
4543
Logger::Level logLevel = Logger::Level::off);
4644

47-
Matrix calculateHistoryVector() const;
45+
virtual Matrix calculateHistoryVector() const;
4846

4947
MatrixComp calculateSteadyStateStateFromInput(const MatrixComp &u,
5048
Real frequency) const;
@@ -53,6 +51,11 @@ class SSNComp : public MNASimPowerComp<Real> {
5351

5452
void updateState(const Matrix &uOld, const Matrix &uNew);
5553

54+
void recomputeDiscreteModel();
55+
56+
/// Hook for variable/time-varying SSN components.
57+
virtual void updateStateSpaceModel();
58+
5659
virtual Attribute<Matrix>::Ptr inputAttribute() const = 0;
5760
virtual Attribute<Matrix>::Ptr outputAttribute() const = 0;
5861

@@ -61,20 +64,20 @@ class SSNComp : public MNASimPowerComp<Real> {
6164
const Matrix &D);
6265

6366
void mnaCompInitialize(Real omega, Real timeStep,
64-
Attribute<Matrix>::Ptr leftVector) final;
67+
Attribute<Matrix>::Ptr leftVector) override final;
6568

66-
void
67-
mnaCompAddPreStepDependencies(AttributeBase::List &prevStepDependencies,
68-
AttributeBase::List &attributeDependencies,
69-
AttributeBase::List &modifiedAttributes) final;
69+
void mnaCompAddPreStepDependencies(
70+
AttributeBase::List &prevStepDependencies,
71+
AttributeBase::List &attributeDependencies,
72+
AttributeBase::List &modifiedAttributes) override final;
7073

71-
void mnaCompPreStep(Real time, Int timeStepCount) final;
74+
void mnaCompPreStep(Real time, Int timeStepCount) override final;
7275

73-
void
74-
mnaCompAddPostStepDependencies(AttributeBase::List &prevStepDependencies,
75-
AttributeBase::List &attributeDependencies,
76-
AttributeBase::List &modifiedAttributes,
77-
Attribute<Matrix>::Ptr &leftVector) final;
76+
void mnaCompAddPostStepDependencies(
77+
AttributeBase::List &prevStepDependencies,
78+
AttributeBase::List &attributeDependencies,
79+
AttributeBase::List &modifiedAttributes,
80+
Attribute<Matrix>::Ptr &leftVector) override final;
7881
};
7982

8083
} // namespace EMT

dpsim-models/include/dpsim-models/EMT/EMT_VTypeSSNComp.h

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -22,20 +22,20 @@ class VTypeSSNComp : public SSNComp {
2222
VTypeSSNComp(String uid, String name, Int inputSize, Int outputSize,
2323
Logger::Level logLevel = Logger::Level::off);
2424

25-
Attribute<Matrix>::Ptr inputAttribute() const final;
26-
Attribute<Matrix>::Ptr outputAttribute() const final;
25+
Attribute<Matrix>::Ptr inputAttribute() const override final;
26+
Attribute<Matrix>::Ptr outputAttribute() const override final;
2727

2828
// Reconstruct the steady-state SSN input vector from node/terminal data.
2929
// For V-type SSN components, this corresponds to the interface voltage input.
3030
virtual MatrixComp buildInitialInputFromNodes(Real frequency) = 0;
3131

3232
public:
33-
void initializeFromNodesAndTerminals(Real frequency) final;
33+
void initializeFromNodesAndTerminals(Real frequency) override;
3434

35-
void mnaCompUpdateCurrent(const Matrix &leftVector) final;
35+
void mnaCompUpdateCurrent(const Matrix &leftVector) override final;
3636

3737
void mnaCompPostStep(Real time, Int timeStepCount,
38-
Attribute<Matrix>::Ptr &leftVector) final;
38+
Attribute<Matrix>::Ptr &leftVector) override final;
3939
};
4040

4141
} // namespace EMT
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
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 <dpsim-models/EMT/EMT_VTypeSSNComp.h>
7+
#include <dpsim-models/Solver/MNAVariableCompInterface.h>
8+
9+
namespace CPS {
10+
namespace EMT {
11+
12+
/// \brief Abstract base class for variable EMT V-type SSN components.
13+
///
14+
/// This class extends VTypeSSNComp with support for time-varying or
15+
/// piecewise-linear state-space models whose MNA conductance stamp may change
16+
/// during simulation. An affine output term
17+
///
18+
/// y = C x + D u + F
19+
///
20+
/// is supported in addition to the linear state-space model.
21+
class VTypeVariableSSNComp : public VTypeSSNComp,
22+
public MNAVariableCompInterface {
23+
private:
24+
Bool mParameterChanged;
25+
Matrix mF;
26+
27+
protected:
28+
VTypeVariableSSNComp(String uid, String name, Int inputSize, Int outputSize,
29+
Logger::Level logLevel = Logger::Level::off);
30+
31+
Matrix calculateHistoryVector() const override final;
32+
void updateStateSpaceModel() override final;
33+
34+
const Matrix &outputOffset() const;
35+
void setOutputOffset(const Matrix &F);
36+
37+
/// Update the current stepwise-linearized component model.
38+
/// Returns true if the MNA conductance stamp changed.
39+
virtual Bool updateComponentParameters() = 0;
40+
41+
public:
42+
Bool hasParameterChanged() override final;
43+
44+
void initializeFromNodesAndTerminals(Real frequency) override final;
45+
};
46+
47+
} // namespace EMT
48+
} // namespace CPS

0 commit comments

Comments
 (0)