Skip to content

Fix ESDIRK order loss under a mass matrix - #4245

Closed
singhharsh1708 wants to merge 1 commit into
SciML:masterfrom
singhharsh1708:esdirk-mass-matrix-order
Closed

singhharsh1708 wants to merge 1 commit into
SciML:masterfrom
singhharsh1708:esdirk-mass-matrix-order

Conversation

@singhharsh1708

@singhharsh1708 singhharsh1708 commented Aug 13, 2026 •

Copy link
Copy Markdown
Member

An ESDIRK's explicit first stage builds zs[1] from integrator.fsalfirst, which under a mass matrix holds the residual f rather than the rate M \ f, so the first step carries an O(dt) error that never refines away and every ESDIRK drops to first order when M != I.
A convergence test under a mass matrix for TRBDF2, Kvaerno3, KenCarp3 and KenCarp4, with M = I alongside as the control, fails on master for all four and passes here; TRBDF2 goes from order 0.966 to 1.985. ROBER still solves to Success with TRBDF2, KenCarp4 and Kvaerno3, so behaviour with a consistent first step is unchanged. Full OrdinaryDiffEqSDIRK suite passes.
M is never inverted anywhere else, only folded into W, so the proper fix is stages carrying f(Y); @oscardssmith said a better version is coming and this stands until it does.
The rate is computed with solve(LinearProblem(M, f), alg.linsolve) on the steps whose fsalfirst holds the residual, so it uses whatever linear solver the user chose rather than a fixed factorization; that makes LinearSolve a direct SDIRK dependency. Only an AbstractMatrix mass matrix is converted; UniformScaling and operator mass matrices keep the residual as before.
Fixes #4173.
AI Disclosure: Claude assisted with this change.

@singhharsh1708
singhharsh1708 force-pushed the esdirk-mass-matrix-order branch 2 times, most recently from 51e4af2 to 6dbfff4 Compare August 13, 2026 18:23
"""
_explicit_stage1_rate(mass_matrix, fsalfirst) = fsalfirst
function _explicit_stage1_rate(mass_matrix::AbstractMatrix, fsalfirst)
F = lu(mass_matrix, check = false)

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.

Why hardcode an lu here?

@singhharsh1708 singhharsh1708 Aug 13, 2026 •

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

switched to backslash.Singular case now uses integrator.isdae instead.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Replaced by solve(LinearProblem(M, f), alg.linsolve), so it lands on whatever the user's linear solver picks; LinearSolve is now a direct SDIRK dependency.

@singhharsh1708
singhharsh1708 force-pushed the esdirk-mass-matrix-order branch from 6dbfff4 to be6c5e9 Compare August 13, 2026 21:20
_explicit_stage1_rate(mass_matrix, fsalfirst, isdae) = fsalfirst
function _explicit_stage1_rate(mass_matrix::AbstractMatrix, fsalfirst, isdae)
isdae && return fsalfirst
return mass_matrix \ fsalfirst

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

no never backslash

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Gone: the solve goes through LinearSolve with the algorithm's linsolve now.

@singhharsh1708

Copy link
Copy Markdown
Member Author

Makes sense, M isn't inverted anywhere else, it's always folded into W. To do this properly the stages would need to carry f(Y) instead of dt*Ydot so the W solve absorbs it, which is a fair bit bigger than this PR. Should I do that here, or just error for now when there's a non-identity mass matrix with an explicit first stage?

@oscardssmith

Copy link
Copy Markdown
Member

I think I have a better version of this. pr incoming

@singhharsh1708

Copy link
Copy Markdown
Member Author

Sounds good. The convergence test in here should apply to whatever the fix ends up being, happy to split it out or you can just lift it.

@singhharsh1708

Copy link
Copy Markdown
Member Author

The red Integrators_II lts lane here is #4425, LinearSolve's QR fallback marking cache.tmp shared on Julia 1.10, not this change.

@singhharsh1708
singhharsh1708 force-pushed the esdirk-mass-matrix-order branch 5 times, most recently from 6ed9bc8 to a3accca Compare September 1, 2026 02:26
@singhharsh1708

singhharsh1708 commented Sep 1, 2026 •

Copy link
Copy Markdown
Member Author

@ChrisRackauckas ready for another look, the backslash is gone and it goes through alg.linsolve now.

@singhharsh1708
singhharsh1708 force-pushed the esdirk-mass-matrix-order branch from a3accca to 7345649 Compare September 6, 2026 07:42
@singhharsh1708
singhharsh1708 force-pushed the esdirk-mass-matrix-order branch from 7345649 to d5aed48 Compare September 13, 2026 13:16
@ChrisRackauckas

Copy link
Copy Markdown
Member

Letting Oscar take this.

@singhharsh1708
singhharsh1708 deleted the esdirk-mass-matrix-order branch September 13, 2026 17:27
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.

ESDIRK methods handle mass matrices incorrectly

4 participants