Hook for custom solve against mass matrix for explicit time integrators#30
Open
mhodzelmans wants to merge 6 commits into
Open
Hook for custom solve against mass matrix for explicit time integrators#30mhodzelmans wants to merge 6 commits into
mhodzelmans wants to merge 6 commits into
Conversation
Contributor
There was a problem hiding this comment.
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
gsDynamicMassInversefunction-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 formingMinv. - Update
gsDynamicBaseto 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.
…xplicit inversion.
33895f9 to
936b375
Compare
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; | ||
| } |
Contributor
Author
There was a problem hiding this comment.
Don't bother checking for square mass
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
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>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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.