Repository navigation
Fix Newmark crash with polyalgorithm nonlinear solvers - #4112
Merged
Merged
Conversation
Member
|
This should just use NonlinearSolveAlg? |
Member
Author
|
Can't. NLSolver's γ is scalar over the whole state, so Newmark's two coefficients collapse to β = γ², which is just Trapezoid. Generalized-α gives β = γ²/4 for every rho_inf, so nothing dissipative survives either. termi-official hit this in #2187 and left it. |
Member
Author
Member
Author
|
we can do that but it needs the second-order residual and Jacobian interface first. This PR is just the crash. |
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.
nlsolveis a public keyword argument on bothNewmarkBetaandGeneralizedAlpha.The default
NewtonRaphsonworks, and so does any other algorithm whose cache stepsin place, such as
TrustRegion,BroydenandKlement. Everything else crashed on the firststep.
RobustMultiNewtonandFastShortcutNonlinearPolyalgthrewtype NonlinearSolvePolyAlgorithmCache has no field p; every SimpleNonlinearSolvealgorithm threw
type NonlinearSolveNoInitCache has no field p. Same bug class as#3859, fixed for
NonlinearSolveAlgin #3959, in a different sublibrary.The integrator cache was using the inner nonlinear cache as its own storage.
perform_step!constructed a freshNewmarkDiscretizationCacheon every step, andrecovered the three
DiffCacheAD buffers it needed by reaching intonlcache.p.A cache that keeps its parameter object somewhere other than a
pfield has nothingto reach into. The discretization state now lives on the integrator cache and is
refreshed in place per step, so nothing is read back out of the inner cache.
That alone is not sufficient.
NonlinearSolveBase's@generated CommonSolve.solve!specialization for
NonlinearSolvePolyAlgorithmCachereturns the winningsub-cache's solution and never writes back the parent cache's
retcode, which staysat
ReturnCode.Default; theNonlinearSolveNoInitCachespecialization delegates toa one-shot
solveand likewise leaves the cache's ownretcodeuntouched. A callerthat drives these caches through
solve!therefore has to read the returnedsolution rather than the cache. This is specific to
solve!.InternalAPI.step!does assign
cache.retcode(NonlinearSolveBase/src/polyalg.jl:316, 323, 359), whichis why the
newton.jlpath merged in #3959 drives withstep!and is unaffected.Both halves are load-bearing. With only the storage defect fixed, the guard reads
nlcache.retcode, seesDefault, setsforce_stepfailon every step, and the solvereturns
ReturnCode.ConvergenceFailurewith the state still atu0andt[end] == 0.0, a crash traded for a silent stall.The two in-place
perform_step!bodies and the twoinitialize!bodies differedonly in which
αm/αfthey passed into the discretization cache, so they are nowshared
Unionmethods. Newmark-β is generalized-α withαm = αf = 0, and those twoparameters enter only through the residual the inner solver evaluates. Neither the
state update nor the Zienkiewicz-Xie error estimate references them, so the merge is
exact, not an approximation. They no longer need to live on
GeneralizedAlphaCacheat all, since they are read once when the discretization cache is built. Output was
checked bit-identical against master across 285 configurations. Across the changed
source files the diff removes more lines than it adds.
Result matrix,
u'' = -uas aSecondOrderODEProblem,dt = 0.1,adaptive = false, identical for both schemes:NewtonRaphson(default),TrustRegion,Broyden,KlementRobustMultiNewton,FastShortcutNonlinearPolyalgpSimpleNewtonRaphson,SimpleTrustRegion,SimpleBroyden,SimpleKlementpAll twenty configurations agree with the reference to 1e-8 relative and sit at the
expected second-order error against the analytic solution (7.0e-4 for Newmark-β,
1.11e-3 for generalized-α at
rho_inf = 0.8).Not rebuilding a cache per step also drops allocations: on a two-DOF harmonic
oscillator at
dt = 0.01,perform_step!goes from 2512 to 2336 bytes forNewmarkBetaand from 2528 to 2336 forGeneralizedAlpha. AllocCheck's static sitecount goes from 518 to 517; that test is still
brokenon both sides.The new
test/nlsolve_cache_tests.jladds 98 assertions, taking the sublibrary'sCore group from 16 to 114. The six pre-existing testsets are unchanged at 16 of 16 on
both trees. The new file pins both state components of both schemes against a
closed-form step map rather than against each other, so an error common to every
inner solver still shows; it steps across a
tstopthat clipsdtto 0.05, so adiscretization cache refreshed only at init cannot pass; it rebinds
integrator.pfrom a callback and checks the result against two chained constant-parameter solves,
so the parameters actually reaching the residual are pinned; and it drives a stub
inner solver that reports
ConvergenceFailurealongside a finite iterate, so thestep-failure branch is exercised rather than assumed. Against master the file gives
24 passed and 24 errored.
Mutation testing confirms it discriminates. Deleting
evalcache.dt = dt, deletingevalcache.t = t, deletingevalcache.p = p, deleting the retcode guard, revertingnlsol.utonlcache.u, revertingnlsol.retcodetonlcache.retcode, andbuilding the generalized-α cache with
αm = αf = 0each leave the suite red.NonlinearSolveenters the sublibrary as a test-only dependency; 4.20.3 is thelowest floor that resolves against the rest of the downgrade floor set, and the new
tests pass there.
Every number above is an
adaptive = falsenumber. Adaptive Newmark is separatelybroken on master:
solve(prob, NewmarkBeta(), dt = 0.1)with no further keywordarguments throws
DimensionMismatchfrom the error-estimate broadcast, on master andon this branch alike. That is unrelated to the inner solver and is fixed in a
separate PR.
This does not route Newmark through
build_nlsolver/NonlinearSolveAlg. That path'sunknown is the full state under a single scalar
γ, while Newmark solves for theacceleration alone, which enters position with
dt²βand velocity withdt·γ.Mapping it onto the DIRK form pins
β = γ², i.e. Trapezoid.NewmarkBeta()andTrapezoid()already agree to 3e-16 onu'' = -u. Therho_infparameterization of generalized-α gives
β = γ²/4identically, so no dissipativemember is representable. Reaching the shared path needs a second-order residual mode
and a second-order Jacobian interface for
(1-αm)M - (1-αf)(dt²β ∂fᵤ + dt·γ ∂fᵥ),which is #1570 / #3474 territory. The two changes here are correct either way: both
replace reaching into a foreign cache's internals with the public API.
AI Disclosure
Claude assisted with this work.