Initial Implementation of Subsystem Model for Partition Simulation - #492
Initial Implementation of Subsystem Model for Partition Simulation#492abdourahmanbarry wants to merge 52 commits into
Conversation
85a516d to
01a410b
Compare
66c58ad to
b48a401
Compare
a375b1f to
f65baeb
Compare
|
This pull request is ready for review. |
| void setTimeFunction(TimeFunction function) | ||
| { | ||
| forcing_function_ = std::move(function); | ||
| } |
There was a problem hiding this comment.
| 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.
e96184a to
98be2e0
Compare
…es. During partitioning: - BusPartitionInterface connects to the bus partition - ComponentPartitionInterface connects to the component partition
…ample more rebust
- Improved subsystem residual and Jacobian validation against the full-system model. - Updated BusPartitionInterface to support arbitrary ordering of internal and external component variables. - Added ownership and cleanup of copied components used by partition interfaces. - Improved comments and documentation for partitioning, Jacobian verification, and interface behavior.
98be2e0 to
f082543
Compare
nkoukpaizan
left a comment
There was a problem hiding this comment.
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. |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
| 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)) |
There was a problem hiding this comment.
Are we not expecting machine precision accuracy?
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
Couple of comments on this:
- 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.
- 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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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.
- 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
Description
In this PR, we introduce the initial implementation of the
SubsystemModelfor 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
SubsystemModelclass to represent an individual partition and aBusPartitionInterfacecomponent to mark partition boundaries.Checklist
-Wall -Wpedantic -Wconversion -Wextra.