Skip to content

Generalized linear two terminal State Space Nodal component models#406

Merged
georgii-tishenin merged 5 commits intosogno-platform:masterfrom
MarvinTollnitschRWTH:generic-linear-ssn
Dec 12, 2025
Merged

Generalized linear two terminal State Space Nodal component models#406
georgii-tishenin merged 5 commits intosogno-platform:masterfrom
MarvinTollnitschRWTH:generic-linear-ssn

Conversation

@MarvinTollnitschRWTH
Copy link
Copy Markdown
Contributor

@MarvinTollnitschRWTH MarvinTollnitschRWTH commented Oct 8, 2025

This PR generalizes the State Space Nodal (SSN) component model implementation by introducing two new linear two-terminal component types defined by state-space matrices A, B, C, and D:

  • SSNTypeV2T – Adds a nodal equation to the MNA system matrix.
  • SSNTypeI2T – Adds a mesh equation to the MNA system matrix (analogous to a voltage source).

Additional updates included in this PR:

  • Added a variant of the trapezoidal discretization method that omits matrices C and D.
  • Implemented an explicit SSN model of a single-phase series RLC circuit to validate the generalized V-type component.
  • Enabled pybind support for all three new component models.
  • Added test notebooks, a C++ test circuit, and a pybind-based test circuit to verify correctness and integration.

Copy link
Copy Markdown
Contributor

@leonardocarreras leonardocarreras left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi! Thanks for your PR!

I left some comments mostly on the software. I did not check the equations.

Please consider using pre-commit automatically, so it will format it before you push.

Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR implements generalized linear two-terminal State Space Nodal (SSN) component models to extend the existing component modeling framework. The implementation provides flexible abstractions for arbitrary linear two-terminal components that can be described using state space matrices A, B, C, and D.

Key changes:

  • Introduces two new generalized SSN component types: SSNTypeV2T (voltage-type) and SSNTypeI2T (current-type)
  • Adds an explicit Full_Serial_RLC implementation using traditional SSN methods
  • Extends the Python bindings to make all three components accessible via pybind

Reviewed Changes

Copilot reviewed 14 out of 15 changed files in this pull request and generated 4 comments.

Show a summary per file
File Description
EMT_generalizedSSN_RLC_dpsimpy.ipynb Test notebook comparing traditional RLC, explicit SSN, and generalized SSN implementations
EMTComponents.cpp Python bindings for new SSN components with parameter setters and attribute getters
EMT_Ph1_General2TerminalSSN.cpp C++ test examples demonstrating usage of generalized SSN components
CMakeLists.txt Build configuration updates to include new test file
MathUtils.cpp/h New overloaded trapezoidal discretization method for A,B matrices only
SSN component implementations Three new component classes with their headers and source files
Components.h Header includes for new SSN components

Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.

@codecov
Copy link
Copy Markdown

codecov bot commented Oct 29, 2025

Codecov Report

❌ Patch coverage is 81.74037% with 128 lines in your changes missing coverage. Please review.
✅ Project coverage is 65.69%. Comparing base (2ff82a9) to head (ff0965c).
⚠️ Report is 6 commits behind head on master.

Files with missing lines Patch % Lines
dpsim-models/src/EMT/EMT_Ph1_SSNTypeI2T.cpp 59.58% 59 Missing ⚠️
dpsim-models/src/EMT/EMT_Ph1_SSNTypeV2T.cpp 56.93% 59 Missing ⚠️
...sim-models/src/EMT/EMT_Ph1_SSN_Full_Serial_RLC.cpp 93.63% 7 Missing ⚠️
dpsim/src/pybind/EMTComponents.cpp 95.58% 3 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master     #406      +/-   ##
==========================================
+ Coverage   65.22%   65.69%   +0.47%     
==========================================
  Files         374      381       +7     
  Lines       22723    23418     +695     
  Branches    11239    11695     +456     
==========================================
+ Hits        14820    15385     +565     
- Misses       7889     7993     +104     
- Partials       14       40      +26     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@leonardocarreras leonardocarreras added the enhancement New feature or request label Nov 10, 2025
@leonardocarreras leonardocarreras moved this to Ready for Review in DPsim Nov 10, 2025
@leonardocarreras
Copy link
Copy Markdown
Contributor

Hi @MarvinTollnitschRWTH @georgii-tishenin, if you want, you can rebase and confirm that this will be good to merge

Copy link
Copy Markdown
Contributor

@georgii-tishenin georgii-tishenin left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi @MarvinTollnitschRWTH,
thanks for addressing the comments.
I rebased the PR, resolved the addressed and not critical comments. All checks now go through as well. There are still a few active comments left, the main topics are:

  • use SPDX header in cpp files as well.
  • do not flush in functions that are not part of component's initialization.
  • make sure there are no outputs in .ipynb files in git history (strangely, the difference shows it for one of the commits).

Please address the active comments or reply to them if you do not agree. Then, we can merge.

@leonardocarreras
Copy link
Copy Markdown
Contributor

@leonardocarreras , @MarvinTollnitschRWTH
in the final commit the outputs are clear. But git history for one of the intermediate commits seems to have the output for EMT_generalizedSSN_RLC_dpsimpy.ipynb (at least it's shown in the difference).

How would you proceed? I see two options:

  1. Squash commits when merging.
  2. git reset to commit before addition of notebooks, commit again and force push

@georgii-tishenin both options work, i think git reset --soft HEAD~6 and adding the files again in the final desired condition is probably the easiest

+ added declaration for "static void calculateStateSpaceTrapezoidalMatrices(...)" which transforms state space matrices A and B and omits C and D to "MathUtils.h"
+ added corresponding definition of "static void calculateStateSpaceTrapezoidalMatrices(...)" to "MathUtils.cpp"

Signed-off-by: Marvin Tollnitsch <marvin.tollnitsch@rwth-aachen.de>
+ added "EMT::Ph1::SSN::Full_Serial_RLC" class with "EMT_Ph1_SSN_Full_Serial_RLC.h" and "EMT_Ph1_SSN_Full_Serial_RLC.cpp"
+ added "EMT::Ph1::SSNTypeI2T" class with "EMT_Ph1_SSNTypeI2T.h" and "EMT_Ph1_SSNTypeI2T.cpp" for a generalized model of an arbitrary two terminal I-type SSN component
+ added "EMT::Ph1::SSNTypeV2T" class with "EMT_Ph1_SSNTypeV2T.h" and "EMT_Ph1_SSNTypeV2T.cpp" for a generalized model of an arbitrary two terminal V-type SSN component

+ added above headers ("EMT_Ph1_SSN_Full_Serial_RLC.h", "EMT_Ph1_SSNTypeI2T.h", "EMT_Ph1_SSNTypeV2T.h") to "Components.h" to include them into the project
+ added above cpp files ("EMT_Ph1_SSN_Full_Serial_RLC.cpp", "EMT_Ph1_SSNTypeI2T.cpp", "EMT_Ph1_SSNTypeV2T.cpp") to the "CMakeLists.txt" for component models

Signed-off-by: Marvin Tollnitsch <marvin.tollnitsch@rwth-aachen.de>
Signed-off-by: Marvin Tollnitsch <marvin.tollnitsch@rwth-aachen.de>
+ added "EMT_Ph1_General2TerminalSSN.cpp" and corresponding notebook "EMT_Ph1_generalizedSSN.ipynb"
+ added "EMT_Ph1_General2TerminalSSN.cpp" to "examples/cxx/CMakeLists.txt" as a circuit source
+ added "EMT_generalizedSSN_RLC_dpsimpy.ipynb" to test generalized SSN RLC implementation in a circuit via pybind

Signed-off-by: Marvin Tollnitsch <marvin.tollnitsch@rwth-aachen.de>
Signed-off-by: Georgii Tishenin <georgii.tishenin@eonerc.rwth-aachen.de>
@georgii-tishenin georgii-tishenin self-requested a review December 12, 2025 13:07
@georgii-tishenin georgii-tishenin merged commit bafb741 into sogno-platform:master Dec 12, 2025
29 checks passed
@github-project-automation github-project-automation bot moved this from Ready for Review to Done in DPsim Dec 12, 2025
@MarvinTollnitschRWTH MarvinTollnitschRWTH deleted the generic-linear-ssn branch December 15, 2025 10:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

4 participants