Skip to content

Initial Implementation of Subsystem Model for Partition Simulation - #492

Open
abdourahmanbarry wants to merge 52 commits into
developfrom
abdou/partitioning_microgrid
Open

Initial Implementation of Subsystem Model for Partition Simulation#492
abdourahmanbarry wants to merge 52 commits into
developfrom
abdou/partitioning_microgrid

Conversation

@abdourahmanbarry

@abdourahmanbarry abdourahmanbarry commented Jul 16, 2026

Copy link
Copy Markdown
Collaborator

Description

In this PR, we introduce the initial implementation of the SubsystemModel for partitioned Power Electronics simulation. The implementation provides the infrastructure required to partition Power Electronic networks, and to evaluate subsystem residuals and Jacobians independently. This lays the foundation for implementing co-simulation methods in future pull requests.

Proposed changes

  • We added a SubsystemModel class to represent an individual partition and a BusPartitionInterface component to mark partition boundaries.
  • Implemented residual and Jacobian evaluation for subsystem models.
  • Added support for user-defined coupling functions required for solving subsystems with multi-stage co-simulation methods.

Checklist

  • All tests pass.
  • Code compiles cleanly with flags -Wall -Wpedantic -Wconversion -Wextra.
  • The new code follows GridKit™ style guidelines.
  • There are unit tests for the new code.
  • The new code is documented.
  • The feature branch is rebased with respect to the target branch.
  • I have updated CHANGELOG.md to reflect the changes in this PR. If this is a minor PR that is part of a larger fix already included in the file, state so.

@abdourahmanbarry
abdourahmanbarry force-pushed the abdou/partitioning_microgrid branch from 85a516d to 01a410b Compare July 19, 2026 08:27
@abdourahmanbarry abdourahmanbarry self-assigned this Jul 23, 2026
@abdourahmanbarry
abdourahmanbarry force-pushed the abdou/partitioning_microgrid branch from 66c58ad to b48a401 Compare July 24, 2026 02:46
@abdourahmanbarry
abdourahmanbarry force-pushed the abdou/partitioning_microgrid branch from a375b1f to f65baeb Compare August 3, 2026 05:16
@abdourahmanbarry
abdourahmanbarry marked this pull request as ready for review August 6, 2026 05:57
@abdourahmanbarry

Copy link
Copy Markdown
Collaborator Author

This pull request is ready for review.

@pelesh pelesh added enhancement New feature or request new solver labels Aug 7, 2026
@pelesh pelesh added this to the Release 0.3 milestone Aug 7, 2026
Comment thread examples/PowerElectronics/Partition/CMakeLists.txt Outdated
Comment thread examples/PowerElectronics/Partition/HiresBus.hpp Outdated
Comment thread examples/PowerElectronics/Partition/HiresBus.hpp Outdated
Comment thread examples/PowerElectronics/Partition/Partition.cpp Outdated
Comment thread examples/PowerElectronics/Partition/Partition.cpp Outdated
Comment thread GridKit/Model/PowerElectronics/SubsystemModel.hpp
Comment thread GridKit/Model/PowerElectronics/SubsystemModel.hpp
Comment thread GridKit/Model/PowerElectronics/SubsystemModel.hpp Outdated
Comment on lines +510 to +513
void setTimeFunction(TimeFunction function)
{
forcing_function_ = std::move(function);
}

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Suggested change
void setTimeFunction(TimeFunction function)
{
forcing_function_ = std::move(function);
}
void setTimeFunction(TimeFunction&& function)
{
forcing_function_ = std::move(function);
}

Good to use an r-value reference if you're going to use std::move. But also this may be unnecesary.

Comment thread GridKit/Model/PartitionEvaluator.hpp Outdated
@abdourahmanbarry
abdourahmanbarry force-pushed the abdou/partitioning_microgrid branch from e96184a to 98be2e0 Compare August 11, 2026 18:28
@abdourahmanbarry
abdourahmanbarry force-pushed the abdou/partitioning_microgrid branch from 98be2e0 to f082543 Compare August 11, 2026 18:52
Comment thread examples/PowerElectronics/Partition/PartitionHires.cpp Outdated

@nkoukpaizan nkoukpaizan left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

I few initial comments on the Hires example. I'll take a closer look at the partition interface after comments by @alexander-novo have been addressed.

namespace GridKit
{
/*!
* @brief Hires Bus Component.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

I recommend further documenting what Hires Bus is in this file. I'm surprised there's a need for a derived component class in the examples directory. Consider moving to tests and encapsulating the necessary components.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

I will add a README file to document this example further. It was meant as a simple example to demonstrate the partitioning scheme due the simplicity of the equations involved. I will use it late for order testing of the co-simulation methods. If it is preferred in the tests folder, I can move it there as well.

Comment thread examples/PowerElectronics/Partition/HiresBus.hpp Outdated
GridKit::LinearAlgebra::CsrMatrix<RealT, IdxT>& full_jac,
GridKit::LinearAlgebra::CsrMatrix<RealT, IdxT>& sub_jac,
GridKit::SubsystemModel<RealT, IdxT>& subsystem,
RealT tolerance = static_cast<RealT>(1e-12))

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Are we not expecting machine precision accuracy?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Due to the non-associativity of floating point arithmetic, the the difference between the entries in the subsystem and monolithic Jacobian may be little bit higher than machine precision when the order of evaluation of the components are different between the reference and subsystem. In this case though we should expect exact match since the components are evaluated in the same order in both the monolithic and subsystems. I will tighten the tolerance here.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Couple of comments on this:

  1. The final result is only guaranteed to be within machine precision if a single floating point operation is being done. But since there are potentially multiple sum operations being taken which may be reordered, this can't be guaranteed.
  2. The tolerance is being applied to an absolute error, and not a relative error. So the error may be larger than machine precision of the expected Jacobian values are larger than 1.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

My point was that I would expect I tighter tolerance than 1e-12 and I don't find an absolute error helpful in this context. The modified relative error in GridKit::Testing::isEqual() should help with normalization.

@abdourahmanbarry abdourahmanbarry Aug 13, 2026

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

In my experience, the non-associativity of floating-point addition can sometimes lead to surprisingly large differences. This is just one example from MATLAB:

>> a = 20.7448;
>> b = -16.0002;
>> c = 130001;
>> d = -130003;
>> 
>> p = a + b + c + d;
>> q = a + c + d + b;
>> 
>> abs(p - q)/abs(q)

ans =

     1.840690392499302e-12

>> 

In cpp:

  double a = 20.7448;
  double b = -16.0002;
  double c = 130001.0;
  double d = -130003.0;

  double p = a + b + c + d;
  double q = a + c + d + b;
  std::cout << "Matched: " << GridKit::Testing::isEqual(p, q, 1e-12) << std::endl;

output:
Matched: 0 // false

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

This is well understood behavior. For the example you show, we would want to explicitly mitigate the error by normalizing or by using parentheses. Good algorithms and implementations are designed with this in mind, knowing expected inputs and coefficients. We'd want to catch this kind of thing early in tests. I recommend adding a comment if satisfying a tighter tolerance is not expected.

Comment thread examples/PowerElectronics/Common/JacTestHelper.hpp
Comment thread examples/PowerElectronics/Partition/PartitionHires.cpp Outdated
Comment thread examples/PowerElectronics/Partition/PartitionHires.cpp Outdated
Comment thread examples/PowerElectronics/Partition/CMakeLists.txt Outdated
Comment thread examples/PowerElectronics/Partition/PartitionHires.cpp Outdated
Comment thread examples/PowerElectronics/Partition/PartitionHires.cpp Outdated
Comment thread GridKit/Model/PowerElectronics/PartitionInterface/CMakeLists.txt Outdated
- add documentation for hires problem and partitioning
- test subsystem jacobian and residuals
- Update CMake file
- Add comments to methods and lambda functions
- added check to ensure only allocated components can be added to model
- Change parameter type in addInterface method to PartitionInterface
- Partition interface can be applied to all bus types, not just MicrogridBus
- New clone functionality  allows users to pass components directly without explicitly copying it
- Update CMake file with dense vector dependency
- Add more documentation
- Move  suitable code from constructor to allocate
- move microgrid network builder section to separate file to facilitate code reuse as more examples dependent on it
- Add partition utility code to minimize code duplication in partition examples.
- Added all helper header files in one location
- Remove remaining Hires example files from Partition folder
- Refactored common code in the Microgrid, ScaleMicrogrid, and ScaleMicrogridArbitrary examples into reusable helper functions
- Improved documentation across the PowerElectronics examples
- Updated CMake files
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request new solver

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants