Skip to content

Add Rosenbrock integrators#479

Open
alexander-novo wants to merge 44 commits into
developfrom
alex/rosenbrock
Open

Add Rosenbrock integrators#479
alexander-novo wants to merge 44 commits into
developfrom
alex/rosenbrock

Conversation

@alexander-novo

@alexander-novo alexander-novo commented Jul 7, 2026

Copy link
Copy Markdown
Collaborator

Description

Add Rosenbrock integrators, which are lighter-weight alternatives to IDA that work well with co-simulation.

Proposed changes

The current version depends on ReSolve and needs porting work to be used with GridKit vectors. The operations used by the Rosenbrock integrators are:

vector_handler_.scal();
vector_handler_.axpy();
vector_handler_.abs();
vector_handler_.max();
vector_handler_.diagSolve();
vector_handler_.amax();

This PR also need's ReSolve's SystemSolver to be ported.

As well, I think some more testing wouldn't go amiss... An integration test on an example power grid would work nicely.

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.

Further comments

@alexander-novo alexander-novo requested a review from pelesh July 7, 2026 17:42
@alexander-novo alexander-novo self-assigned this Jul 7, 2026
@alexander-novo alexander-novo added the enhancement New feature or request label Jul 7, 2026
@pelesh pelesh added this to the Release 0.2 milestone Jul 8, 2026
@pelesh pelesh mentioned this pull request Jul 8, 2026
7 tasks

@pelesh pelesh 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.

This is really nice work!

I would suggest merging #480 first and then rebasing so that we avoid introducing Re::Solve dependency.

Comment thread GridKit/Solver/Dynamic/Rosenbrock.cpp
Comment thread GridKit/Solver/Dynamic/Rosenbrock.cpp
Comment thread GridKit/Solver/Dynamic/RosenbrockTableaus.cpp Outdated
@alexander-novo

Copy link
Copy Markdown
Collaborator Author

@pelesh I've updated the PR to make use of GridKit's own Vector and VectorHandler. Re::Solve is still used for the lienar solver part, however (see Rosenbrock::time_step)

@alexander-novo alexander-novo changed the base branch from develop to slaven/vector-handler July 9, 2026 00:25
@pelesh

pelesh commented Jul 9, 2026

Copy link
Copy Markdown
Collaborator

@pelesh I've updated the PR to make use of GridKit's own Vector and VectorHandler. Re::Solve is still used for the lienar solver part, however (see Rosenbrock::time_step)

Using a linear solver from Re::Solve is a good thing :). We can add bare KLU interface in a separate PR, if needed.

Comment thread GridKit/Solver/Dynamic/RosenbrockTableaus.cpp Outdated
Comment thread GridKit/Solver/Dynamic/Rosenbrock.cpp
Comment thread GridKit/Solver/Dynamic/Rosenbrock.cpp
Comment thread GridKit/Solver/Dynamic/Rosenbrock.cpp Outdated
Comment thread GridKit/Solver/Dynamic/Rosenbrock.cpp
Comment thread GridKit/Solver/Dynamic/Rosenbrock.cpp Outdated
Comment thread GridKit/Solver/Dynamic/Rosenbrock.cpp
Comment thread GridKit/Solver/Dynamic/Rosenbrock.cpp Outdated
Comment thread GridKit/Solver/Dynamic/Rosenbrock.cpp Outdated
Comment thread tests/UnitTests/Solver/Dynamic/RosenbrockTests.hpp

@shakedregev shakedregev 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.

Fix the minor issues and good to merge. I tested it.

Comment thread tests/UnitTests/Solver/Dynamic/CMakeLists.txt Outdated
Comment thread GridKit/Solver/Dynamic/Rosenbrock.cpp Outdated
Comment thread README.md Outdated
@nkoukpaizan nkoukpaizan mentioned this pull request Jul 10, 2026
4 tasks
Comment thread GridKit/Solver/Dynamic/RosenbrockTableaus.cpp Outdated
Comment thread GridKit/Solver/Dynamic/RosenbrockTableaus.cpp Outdated
Comment thread tests/UnitTests/Solver/Dynamic/CMakeLists.txt Outdated

@pelesh pelesh 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.

Very nice compact implementation.

Before merging it would be helpful to create clear interfaces between Rosenbrock integrator and GridKit and between Rosenbrock integrator and linear solver.

Also, please implement each class/structure in a separate source/header files.

Comment on lines +11 to +15
/**
* @brief Converts a GridKit \ref MemorySpace to its corresponding Re::Solve MemorySpace
*
*/
inline ReSolve::memory::MemorySpace memorySpaceAsResolve(MemorySpace memspace)

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 should not be necessary. GridKit should not see Re::Solve memory space and vice versa.

Comment on lines +28 to +30
template <typename RealT>
struct StepControl
{

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 structure and everything that is not Rosenbrock class should be in separate file. For each class or structure there should be a separate *.hpp and *.cpp files.

Comment on lines +50 to +52
template <typename RealT>
class StepController
{

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.

Same here. Please move this to a separate file.

Comment on lines +498 to +500
ReSolve::SystemSolver& lin_solver,
GridKit::LinearAlgebra::VectorHandler<ScalarT, IdxT>& vector_handler,
const ErrorNorm<ScalarT, IdxT>* err_norm,

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.

VectorHandler and ErrorNorm probably should be members of Rosenbrock class. I am not sure why these are passed as constructor parameters.

Comment on lines +610 to +617
/**
* @brief A simple textbook adaptive `StepController` which seeks to meet a relative and absolute tolerance
* based on an error estimate.
*
*/
template <typename RealT>
class AdaptiveStep : public StepController<RealT>
{

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 class should be in a separate file.

Comment on lines +7 to +10
template <class ScalarT, typename IdxT>
Rosenbrock<ScalarT, IdxT>::Tableau Rosenbrock<ScalarT, IdxT>::Tableau::linImplicitEuler()
{
constexpr size_t num_stages = 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.

I would keep tableaus in the Rosenbrock.cpp file.

Comment on lines +995 to +996
InfNorm<ScalarT, IdxT>::RealT InfNorm<ScalarT, IdxT>::errorNorm(State& err, State& y, State& yprev, GridKit::LinearAlgebra::VectorHandler<ScalarT, IdxT>& handler, ReSolve::memory::MemorySpace memspace) const
{

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.

Re::Solve memory space should not show up here. It is internal to Re::Solve and should not be used in GridKit's VectorHandler.

Comment on lines +270 to +271
resolve_rhs_ = std::make_unique<ReSolve::vector::Vector>(size);
resolve_lhs_ = std::make_unique<ReSolve::vector::Vector>(size);

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.

Re::Solve vector should not appear in Rosenbrock class.

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