Commit 2977825
committed
MIRK: cache the flat nlprob u0 buffer instead of reallocating each iteration
`__perform_mirk_iteration` previously called
`__construct_problem(cache, copy(vec(cache.y₀)), copy(cache.y₀))`. The
`copy(vec(...))` allocated a fresh `Vector{T}` every outer mesh-refinement
step purely to materialize the flat representation NonlinearSolve /
LinearSolve require — `vec(::VectorOfArray)` under RAT v4 returns a
`Base.ReshapedArray` which `LinearSolve.LinearCache`'s declared
`Vector{T}` field doesn't accept.
Add a `y₀_flat::Vector{T}` field on `MIRKCache` that mirrors `cache.y₀`,
allocate it once in `__init` (`collect(vec(y₀))`), keep it in sync with
the mesh in `__expand_cache!` (`resize!(..., Nₙ * cache.M)`), and refresh
it in place via `copyto!(cache.y₀_flat, vec(cache.y₀))` at the start of
each outer iteration. The flat mirror is then handed to
`__construct_problem` as `nlprob.u0`, so NonlinearSolve / LinearSolve
still see a concrete `Vector{T}` while the per-iteration allocation
disappears.
Refs #486. This is the minimal step in that
direction that doesn't require upstream changes to LinearSolve /
NonlinearSolveBase to accept `AbstractVector{T}` (or to RAT to change
what `vec(::VOA)` returns); the deeper refactor — passing
`cache.y₀::VectorOfArray` directly through to NonlinearSolve and
dropping the `recursive_unflatten!` round-trips inside the
`__mirk_loss!` family — needs that upstream work first
(see issue #486 comment).
Verified by running `Pkg.test()` for `BoundaryValueDiffEqMIRK`:
all 25 test items / 308 tests pass.
Co-Authored-By: Chris Rackauckas <accounts@chrisrackauckas.com>1 parent b27fede commit 2977825
1 file changed
Lines changed: 11 additions & 2 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
21 | 21 | | |
22 | 22 | | |
23 | 23 | | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
24 | 28 | | |
25 | 29 | | |
26 | 30 | | |
| |||
75 | 79 | | |
76 | 80 | | |
77 | 81 | | |
| 82 | + | |
78 | 83 | | |
79 | 84 | | |
80 | 85 | | |
| |||
235 | 240 | | |
236 | 241 | | |
237 | 242 | | |
238 | | - | |
| 243 | + | |
239 | 244 | | |
240 | 245 | | |
241 | 246 | | |
| |||
252 | 257 | | |
253 | 258 | | |
254 | 259 | | |
| 260 | + | |
255 | 261 | | |
256 | 262 | | |
257 | 263 | | |
| |||
307 | 313 | | |
308 | 314 | | |
309 | 315 | | |
310 | | - | |
| 316 | + | |
| 317 | + | |
| 318 | + | |
| 319 | + | |
311 | 320 | | |
312 | 321 | | |
313 | 322 | | |
| |||
0 commit comments