-
Notifications
You must be signed in to change notification settings - Fork 73
Generalized linear two terminal State Space Nodal component models #406
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
georgii-tishenin
merged 5 commits into
sogno-platform:master
from
MarvinTollnitschRWTH:generic-linear-ssn
Dec 12, 2025
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
92c2153
Added trapezoidal discretization for state space matrices A, B
MarvinTollnitschRWTH 1231409
Added SSN models: Ph1 serial RLC, & generalized two terminal SSN
MarvinTollnitschRWTH 951e880
Made Ph1::SSN::RLC & general. two terminal SSN models usable in pybind
MarvinTollnitschRWTH 2899c09
Added example circuits for new generalized two terminal SSN models
MarvinTollnitschRWTH ff0965c
Remove unnecessary use of mSLog->flush()
georgii-tishenin File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
93 changes: 93 additions & 0 deletions
93
dpsim-models/include/dpsim-models/EMT/EMT_Ph1_SSNTypeI2T.h
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,93 @@ | ||
| // SPDX-FileCopyrightText: 2025 Institute for Automation of Complex Power Systems, EONERC, RWTH Aachen University | ||
| // SPDX-License-Identifier: MPL-2.0 | ||
|
|
||
| #pragma once | ||
|
|
||
| #include <dpsim-models/MNASimPowerComp.h> | ||
| #include <dpsim-models/Solver/MNAInterface.h> | ||
|
|
||
| namespace CPS { | ||
| namespace EMT { | ||
| namespace Ph1 { | ||
| /// \brief SSNTypeI2T | ||
| /// Model for a one phase, two terminal I-type SSN component which can be represented using | ||
| /// a state space equation system | ||
| /// x' = A * x + B * u | ||
| /// y = C * x + D * u | ||
| /// with x: state vector, y: output vector, u: input vector, | ||
| /// where u represents external current (mIntfCurrent), | ||
| /// y represents external voltage (mIntfVoltage), | ||
| /// x represents any component states. | ||
| class SSNTypeI2T : public MNASimPowerComp<Real>, | ||
| public SharedFactory<SSNTypeI2T> { | ||
| private: | ||
| void ssnUpdateState(); | ||
| void setSSNMatricesToZero(); | ||
|
|
||
| protected: | ||
| Matrix mX; | ||
| Matrix mU; | ||
| Matrix mUOld; | ||
| Matrix mW; | ||
| Matrix mYHist; | ||
|
|
||
| public: | ||
| const CPS::Attribute<Matrix>::Ptr mA; | ||
|
georgii-tishenin marked this conversation as resolved.
|
||
| const CPS::Attribute<Matrix>::Ptr mB; | ||
| const CPS::Attribute<Matrix>::Ptr mC; | ||
| const CPS::Attribute<Matrix>::Ptr mD; | ||
|
|
||
| const CPS::Attribute<Matrix>::Ptr mdA; | ||
| const CPS::Attribute<Matrix>::Ptr mdB; | ||
| const CPS::Attribute<Matrix>::Ptr mdC; | ||
|
|
||
| /// Defines UID, name, component parameters and logging level | ||
| SSNTypeI2T(String uid, String name, | ||
| Logger::Level logLevel = Logger::Level::off); | ||
| /// Defines name and logging level | ||
| SSNTypeI2T(String name, Logger::Level logLevel = Logger::Level::off) | ||
| : SSNTypeI2T(name, name, logLevel) {} | ||
|
|
||
| SimPowerComp<Real>::Ptr clone(String name) override; | ||
|
|
||
| void manualInit(Matrix initialState, Matrix initialInput, | ||
| Matrix initialOldInput, Real initCurrent, Real initVoltage); | ||
| // #### General #### | ||
| void setParameters(const Matrix A, const Matrix B, const Matrix C, | ||
| const Matrix D); | ||
| /// Initializes component from power flow data | ||
| void initializeFromNodesAndTerminals(Real frequency) override; | ||
|
|
||
| // #### MNA section #### | ||
| /// Initializes internal variables of the component | ||
| void mnaCompInitialize(Real omega, Real timeStep, | ||
| Attribute<Matrix>::Ptr leftVector) override; | ||
| /// Stamps system matrix | ||
| void mnaCompApplySystemMatrixStamp(SparseMatrixRow &systemMatrix) override; | ||
| /// Stamps right side (source) vector | ||
| void mnaCompApplyRightSideVectorStamp(Matrix &rightVector) override; | ||
| /// Update interface voltage from MNA system result | ||
| void mnaCompUpdateVoltage(const Matrix &leftVector) override; | ||
| /// Update interface current from MNA system result | ||
| void mnaCompUpdateCurrent(const Matrix &leftVector) override; | ||
|
|
||
| void mnaCompPreStep(Real time, Int timeStepCount) override; | ||
| void mnaCompPostStep(Real time, Int timeStepCount, | ||
| Attribute<Matrix>::Ptr &leftVector) override; | ||
|
|
||
| /// Add MNA pre step dependencies | ||
| void mnaCompAddPreStepDependencies( | ||
| AttributeBase::List &prevStepDependencies, | ||
| AttributeBase::List &attributeDependencies, | ||
| AttributeBase::List &modifiedAttributes) override; | ||
|
MarvinTollnitschRWTH marked this conversation as resolved.
|
||
|
|
||
| /// Add MNA post step dependencies | ||
| void | ||
| mnaCompAddPostStepDependencies(AttributeBase::List &prevStepDependencies, | ||
| AttributeBase::List &attributeDependencies, | ||
| AttributeBase::List &modifiedAttributes, | ||
| Attribute<Matrix>::Ptr &leftVector) override; | ||
| }; | ||
| } // namespace Ph1 | ||
| } // namespace EMT | ||
| } // namespace CPS | ||
94 changes: 94 additions & 0 deletions
94
dpsim-models/include/dpsim-models/EMT/EMT_Ph1_SSNTypeV2T.h
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,94 @@ | ||
| // SPDX-FileCopyrightText: 2025 Institute for Automation of Complex Power Systems, EONERC, RWTH Aachen University | ||
| // SPDX-License-Identifier: MPL-2.0 | ||
|
|
||
| #pragma once | ||
|
|
||
| #include <dpsim-models/MNASimPowerComp.h> | ||
| #include <dpsim-models/Solver/MNAInterface.h> | ||
|
|
||
| namespace CPS { | ||
| namespace EMT { | ||
| namespace Ph1 { | ||
| /// \brief SSNTypeV2T | ||
| /// Model for a one phase, two terminal V-type SSN component which can be represented using | ||
| /// a state space equation system | ||
| /// x' = A * x + B * u | ||
| /// y = C * x + D * u | ||
| /// with x: state vector, y: output vector, u: input vector, | ||
| /// where u represents external voltage (mIntfVoltage), | ||
| /// y represents external current (mIntfCurrent), | ||
| /// x represents any component states. | ||
| class SSNTypeV2T : public MNASimPowerComp<Real>, | ||
| public SharedFactory<SSNTypeV2T> { | ||
| private: | ||
| void ssnUpdateState(); | ||
| void setSSNMatricesToZero(); | ||
|
|
||
| protected: | ||
| Matrix mX; | ||
| Matrix mU; | ||
| Matrix mUOld; | ||
| Matrix mW; | ||
| Matrix mYHist; | ||
|
|
||
| public: | ||
| const CPS::Attribute<Matrix>::Ptr mA; | ||
| const CPS::Attribute<Matrix>::Ptr mB; | ||
| const CPS::Attribute<Matrix>::Ptr mC; | ||
| const CPS::Attribute<Matrix>::Ptr mD; | ||
|
|
||
| const CPS::Attribute<Matrix>::Ptr mdA; | ||
| const CPS::Attribute<Matrix>::Ptr mdB; | ||
| const CPS::Attribute<Matrix>::Ptr mdC; | ||
|
|
||
| /// Defines UID, name, component parameters and logging level | ||
| SSNTypeV2T(String uid, String name, | ||
| Logger::Level logLevel = Logger::Level::off); | ||
| /// Defines name and logging level | ||
| SSNTypeV2T(String name, Logger::Level logLevel = Logger::Level::off) | ||
| : SSNTypeV2T(name, name, logLevel) {} | ||
|
|
||
| SimPowerComp<Real>::Ptr clone(String name) override; | ||
|
|
||
| void manualInit(Matrix initialState, Matrix initialInput, | ||
| Matrix initialOldInput, Real initCurrent, Real initVoltage); | ||
|
|
||
| // #### General #### | ||
| void setParameters(const Matrix A, const Matrix B, const Matrix C, | ||
| const Matrix D); | ||
| /// Initializes component from power flow data | ||
| void initializeFromNodesAndTerminals(Real frequency) override; | ||
|
|
||
| // #### MNA section #### | ||
| /// Initializes internal variables of the component | ||
| void mnaCompInitialize(Real omega, Real timeStep, | ||
| Attribute<Matrix>::Ptr leftVector) override; | ||
| /// Stamps system matrix | ||
| void mnaCompApplySystemMatrixStamp(SparseMatrixRow &systemMatrix) override; | ||
| /// Stamps right side (source) vector | ||
| void mnaCompApplyRightSideVectorStamp(Matrix &rightVector) override; | ||
| /// Update interface voltage from MNA system result | ||
| void mnaCompUpdateVoltage(const Matrix &leftVector) override; | ||
| /// Update interface current from MNA system result | ||
| void mnaCompUpdateCurrent(const Matrix &leftVector) override; | ||
|
|
||
| void mnaCompPreStep(Real time, Int timeStepCount) override; | ||
| void mnaCompPostStep(Real time, Int timeStepCount, | ||
| Attribute<Matrix>::Ptr &leftVector) override; | ||
|
|
||
| /// Add MNA pre step dependencies | ||
| void mnaCompAddPreStepDependencies( | ||
| AttributeBase::List &prevStepDependencies, | ||
| AttributeBase::List &attributeDependencies, | ||
| AttributeBase::List &modifiedAttributes) override; | ||
|
|
||
| /// Add MNA post step dependencies | ||
| void | ||
| mnaCompAddPostStepDependencies(AttributeBase::List &prevStepDependencies, | ||
| AttributeBase::List &attributeDependencies, | ||
| AttributeBase::List &modifiedAttributes, | ||
| Attribute<Matrix>::Ptr &leftVector) override; | ||
| }; | ||
| } // namespace Ph1 | ||
| } // namespace EMT | ||
| } // namespace CPS |
100 changes: 100 additions & 0 deletions
100
dpsim-models/include/dpsim-models/EMT/EMT_Ph1_SSN_Full_Serial_RLC.h
|
georgii-tishenin marked this conversation as resolved.
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,100 @@ | ||
| // SPDX-FileCopyrightText: 2025 Institute for Automation of Complex Power Systems, EONERC, RWTH Aachen University | ||
| // SPDX-License-Identifier: MPL-2.0 | ||
|
|
||
| #pragma once | ||
|
|
||
| #include <dpsim-models/Base/Base_Ph1_Capacitor.h> | ||
| #include <dpsim-models/Base/Base_Ph1_Inductor.h> | ||
| #include <dpsim-models/Base/Base_Ph1_Resistor.h> | ||
| #include <dpsim-models/MNASimPowerComp.h> | ||
| #include <dpsim-models/Solver/MNAInterface.h> | ||
|
|
||
| namespace CPS { | ||
| namespace EMT { | ||
| namespace Ph1 { | ||
| namespace SSN { | ||
| /// \brief Full_Serial_RLC | ||
| /// | ||
| /// This element represents an one port circuit consisting of a resistor, | ||
| /// an inductor and a capacitor connected in series. The terminals are at | ||
| /// the beginning and the end of the component chain. | ||
| /// The states are the capacitor voltage and the inductor current, the output | ||
| /// is the latter of those states (inductor current). The input is the voltage | ||
| /// across the whole circuit. States and past inputs are updated after each | ||
| /// time step and are used to calculate the current (input) voltage, | ||
| /// represented as MNA node voltages. | ||
| /// SSN theory and variable naming based on | ||
| /// C. Dufour, J. Mahseredjian and J. Belanger, | ||
| /// "A combined state-space nodal method for the simulation of power system | ||
| /// transients," 2011 IEEE Power and Energy Society General Meeting, Detroit, | ||
| /// MI, USA, 2011, pp. 1-1, doi: 10.1109/PES.2011.6038887. keywords: | ||
| /// {Mathematical model;Analytical models;Equations;Power system transients; | ||
| /// Couplings;Switching circuits} | ||
|
|
||
| class Full_Serial_RLC final : public MNASimPowerComp<Real>, | ||
| public SharedFactory<Full_Serial_RLC>, | ||
| public Base::Ph1::Resistor, | ||
| public Base::Ph1::Inductor, | ||
| public Base::Ph1::Capacitor { | ||
| public: | ||
| /// Defines UID, name, component parameters and logging level | ||
| Full_Serial_RLC(String uid, String name, | ||
| Logger::Level logLevel = Logger::Level::off); | ||
| /// Defines name and logging level | ||
| Full_Serial_RLC(String name, Logger::Level logLevel = Logger::Level::off) | ||
| : Full_Serial_RLC(name, name, logLevel) {} | ||
|
|
||
| SimPowerComp<Real>::Ptr clone(String name) override; | ||
| void setParameters(Real resistance, Real inductance, Real capacitance); | ||
|
|
||
| // #### General #### | ||
| /// Initializes component from power flow data | ||
| void initializeFromNodesAndTerminals(Real frequency) override; | ||
|
|
||
| // #### MNA section #### | ||
| /// Initializes internal variables of the component | ||
| void mnaCompInitialize(Real omega, Real timeStep, | ||
| Attribute<Matrix>::Ptr leftVector) override; | ||
| /// Stamps system matrix | ||
| void mnaCompApplySystemMatrixStamp(SparseMatrixRow &systemMatrix) override; | ||
| /// Stamps right side (source) vector | ||
| void mnaCompApplyRightSideVectorStamp(Matrix &rightVector) override; | ||
| /// Update interface voltage from MNA system result | ||
| void mnaCompUpdateVoltage(const Matrix &leftVector) override; | ||
| /// Update interface current from MNA system result | ||
| void mnaCompUpdateCurrent(const Matrix &leftVector) override; | ||
| /// MNA pre step operations | ||
| void mnaCompPreStep(Real time, Int timeStepCount) override; | ||
| /// MNA post step operations | ||
| void mnaCompPostStep(Real time, Int timeStepCount, | ||
| Attribute<Matrix>::Ptr &leftVector) override; | ||
| /// Add MNA pre step dependencies | ||
| void mnaCompAddPreStepDependencies( | ||
| AttributeBase::List &prevStepDependencies, | ||
| AttributeBase::List &attributeDependencies, | ||
| AttributeBase::List &modifiedAttributes) override; | ||
| /// Add MNA post step dependencies | ||
| void | ||
| mnaCompAddPostStepDependencies(AttributeBase::List &prevStepDependencies, | ||
| AttributeBase::List &attributeDependencies, | ||
| AttributeBase::List &modifiedAttributes, | ||
| Attribute<Matrix>::Ptr &leftVector) override; | ||
|
|
||
| private: | ||
| Matrix mState = Matrix::Zero(2, 1); | ||
| Real mYHistory = 0; | ||
|
|
||
| Real mDufourUNT = 0; | ||
|
|
||
| Matrix mDufourAKHat = Matrix::Zero(2, 2); | ||
| Matrix mDufourBKHat = Matrix::Zero(2, 1); | ||
|
georgii-tishenin marked this conversation as resolved.
|
||
| Matrix mDufourBKNHat = Matrix::Zero(2, 1); | ||
| Real mDufourWKN = 0; | ||
| Matrix mDufourCKN = Matrix::Zero(1, 2); | ||
|
|
||
| void ssnUpdateState(); | ||
| }; | ||
| } // namespace SSN | ||
| } // namespace Ph1 | ||
| } // namespace EMT | ||
| } // namespace CPS | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.