Skip to content

Hook for custom solve against mass matrix for explicit time integrators#30

Open
mhodzelmans wants to merge 6 commits into
mainfrom
custom_massinverse
Open

Hook for custom solve against mass matrix for explicit time integrators#30
mhodzelmans wants to merge 6 commits into
mainfrom
custom_massinverse

Conversation

@mhodzelmans

@mhodzelmans mhodzelmans commented Jun 26, 2026

Copy link
Copy Markdown
Contributor

The existing RK4 and explicit euler method compute the inverse of the mass matrix, then reuse that for computing accelerations. This is inefficient. Generally, a factorization we solve against is faster.

This patch introduces a virtual class / function object containing the functionality to solve against the mass matrix. i.e. a compute step for caching, and a solve step. The dynamicBase owns one of these. It's defaulted to the pre-existing explicit inverse. Setters are available now for custom things. One function object using standard Eigen LDLT is added.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

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 introduces an extensible “mass inverse” hook for explicit dynamic time integrators so they can apply (M^{-1}) via a reusable solve/factorization instead of explicitly forming and multiplying by a stored inverse.

Changes:

  • Add gsDynamicMassInverse function-object interface with default explicit-inverse and a sparse-solver-backed implementation.
  • Update Explicit Euler and RK4 to use _applyMassInverse(time, rhs, result) instead of explicitly forming Minv.
  • Update gsDynamicBase to own/cache a mass-inverse object and expose setters for custom implementations.

Reviewed changes

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

File Description
src/gsDynamicSolvers/gsDynamicRK4.hpp Switch RK4 acceleration computation to _applyMassInverse(...); also changes RK4 stage-4 evaluation time/state.
src/gsDynamicSolvers/gsDynamicMassInverse.h New mass-inverse function-object interface plus explicit-inverse and sparse-solver-backed implementations.
src/gsDynamicSolvers/gsDynamicExplicitEuler.hpp Switch Explicit Euler acceleration computation to _applyMassInverse(...).
src/gsDynamicSolvers/gsDynamicBase.h Add mass-inverse ownership/caching, time-dependence handling, and setters to customize inverse/solve strategy.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread src/gsDynamicSolvers/gsDynamicBase.h
Comment thread src/gsDynamicSolvers/gsDynamicBase.h
Comment thread src/gsDynamicSolvers/gsDynamicMassInverse.h
Comment thread src/gsDynamicSolvers/gsDynamicRK4.hpp
Comment thread src/gsDynamicSolvers/gsDynamicRK4.hpp
Comment thread src/gsDynamicSolvers/gsDynamicRK4.hpp
Comment thread src/gsDynamicSolvers/gsDynamicRK4.hpp

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

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

Comment thread src/gsDynamicSolvers/gsDynamicBase.h
Comment thread src/gsDynamicSolvers/gsDynamicBase.h
Comment thread src/gsDynamicSolvers/gsDynamicBase.h
Comment on lines +44 to +56
void compute(const gsSparseMatrix<T> & mass)
{
gsSparseMatrix<T> eye(mass.rows(), mass.cols());
eye.setIdentity();
typename gsSparseSolver<T>::LU solver(mass);
gsMatrix<T> inverse = solver.solve(eye);
m_massInv = inverse.sparseView();
}

void apply(const gsVector<T> & rhs, gsVector<T> & result) const
{
result = m_massInv * rhs;
}

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Don't bother checking for square mass

Comment thread src/gsDynamicSolvers/gsDynamicMassInverse.h
mhodzelmans and others added 2 commits June 26, 2026 15:58
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

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

Comment thread src/gsDynamicSolvers/gsDynamicMassInverse.h
Comment on lines +85 to +88
void apply(const gsVector<T> & rhs, gsVector<T> & result) const override
{
result = m_solver->solve(rhs);
}
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants