Skip to content

Add LinearSolver interface#489

Open
alexander-novo wants to merge 6 commits into
developfrom
alex/linear_solver
Open

Add LinearSolver interface#489
alexander-novo wants to merge 6 commits into
developfrom
alex/linear_solver

Conversation

@alexander-novo

Copy link
Copy Markdown
Collaborator

Description

Add new LinearSolver interface and one implementation using Re::Solve to be used by e.g. Rosenbrock (#479)

Proposed changes

Interface has three lifecycle functions:

  • configureSolver called whenever the matrix changes sparsity pattern
  • setupSolver called whenever the matrix changes data
  • solve to perform a linear solve

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.

Please see Rosenbrock tests for unit tests.

Further comments

@alexander-novo alexander-novo self-assigned this Jul 13, 2026
@alexander-novo alexander-novo added the enhancement New feature or request label Jul 13, 2026
@pelesh pelesh mentioned this pull request Jul 14, 2026
7 tasks
* Add rosenbrock

* Add rosenbrock tests

* Add RODAS5P tableau

* Add rodas5p order test

* Update Rosenbrock to use new LinearSolver interface

* Moved Rosenbrock support classes to Native folder

* Change Integrator namespace

* Remove ResolveMemoryUtils.hpp

---------

Co-authored-by: alexander-novo <alexander-novo@users.noreply.github.com>
Co-authored-by: Shaked Regev <35384901+shakedregev@users.noreply.github.com>
Co-authored-by: pelesh <peless@ornl.gov>

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

Brief comments on interfacing with Re::Solve

Comment on lines +65 to +69
if (reuse_factors)
{
if (int err = lin_solver_.refactorize())
return err;
}

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 believe there should be a third option reuse_pivot_sequence. Then, this conditional would look something like this:

Suggested change
if (reuse_factors)
{
if (int err = lin_solver_.refactorize())
return err;
}
if (reuse_factors)
{
return 0;
}
else if (reuse_pivot_sequence)
{
if (int err = lin_solver_.refactorize())
return err;
}

Might be a good idea to have an enum instead of multiple boolean flags.

Comment on lines +88 to +98
ReSolve::vector::Vector resolve_rhs(rhs.getSize());
ReSolve::vector::Vector resolve_lhs(lhs.getSize());

if (int err = resolve_rhs.setData(rhs.getData(), memspace_))
return err;

if (int err = resolve_lhs.setData(lhs.getData(), memspace_))
return err;

if (int err = lin_solver_.solve(&resolve_rhs, &resolve_lhs))
return err;

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 really don't like setData methods as they are ticking bomb but we still carry them along. How about we create a view constructor to make a shallow copy of the vector:

Suggested change
ReSolve::vector::Vector resolve_rhs(rhs.getSize());
ReSolve::vector::Vector resolve_lhs(lhs.getSize());
if (int err = resolve_rhs.setData(rhs.getData(), memspace_))
return err;
if (int err = resolve_lhs.setData(lhs.getData(), memspace_))
return err;
if (int err = lin_solver_.solve(&resolve_rhs, &resolve_lhs))
return err;
ReSolve::vector::Vector resolve_rhs(rhs.getSize(), rhs.getData());
ReSolve::vector::Vector resolve_lhs(lhs.getSize(), lhs.getData());
if (int err = lin_solver_.solve(&resolve_rhs, &resolve_lhs))
return err;

Even better would be if that constructor is made private and we implement method createVectorView that would invoke such constructor and create vector object that does not own the data.

@nkoukpaizan nkoukpaizan mentioned this pull request Jul 16, 2026
4 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 good to merge. I suggest two minor changes before we merge it:

  • Have Rosenbrock class inherit from DynamicSolver class.
  • Rebase to the current develop.

Comment on lines +29 to +30
: lin_solver_(lin_solver), memspace_(memorySpaceAsResolve(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.

You really don't need this. The SystemSolver class will manage host/device memory spaces under the hood.

Suggested change
: lin_solver_(lin_solver), memspace_(memorySpaceAsResolve(memspace))
{
: lin_solver_(lin_solver)
{

In the PR the memspace_ is used only to set vector/matrix views. I would just mark those places as @todo to remove them when we improve linear algebra support in GridKit. Better to merge this PR now and address these issues in the next PR.

Comment on lines +32 to +34
class Rosenbrock
{
using RealT = typename GridKit::ScalarTraits<ScalarT>::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.

Rosenbrock class should inherit from DynamicSolver.

Comment thread README.md
that the use of Enzyme is experimental, and some versions of it have been found to break GridKit code.
- [LLVM](https://github.com/llvm/llvm-project) >= 15.x. GridKit is
currently tested with LLVM 16.
- [ReSolve](https://github.com/ORNL/ReSolve) == commit `a93fb6571e3542b2fa779983fef0186a034c53c9` (optional)

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.

We are about to release v0.99.3 so this is probably better dependency requirement.

Suggested change
- [ReSolve](https://github.com/ORNL/ReSolve) == commit `a93fb6571e3542b2fa779983fef0186a034c53c9` (optional)
- [ReSolve](https://github.com/ORNL/ReSolve) >= 0.99.3 (optional)

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

None yet

Development

Successfully merging this pull request may close these issues.

2 participants