Skip to content

Commit f9c841e

Browse files
Merge pull request #549 from ChrisRackauckas-Claude/fix-firk-vector-evalsol
Fix FIRK vector-of-vector residual AD storage
2 parents 51351bb + 40f1fd6 commit f9c841e

1 file changed

Lines changed: 11 additions & 3 deletions

File tree

  • lib/BoundaryValueDiffEqFIRK/src

lib/BoundaryValueDiffEqFIRK/src/firk.jl

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -705,6 +705,14 @@ function __construct_problem(
705705
return __construct_problem(cache, y, loss_bc, loss_collocation, loss, pt, constraint)
706706
end
707707

708+
@inline function __firk_eval_sol!(eval_sol, y, mesh, cache)
709+
if eltype(first(y)) <: eltype(first(eval_sol.u))
710+
eval_sol.u[1:end] .= y
711+
return eval_sol
712+
end
713+
return EvalSol(__restructure_sol(y, cache.in_size), mesh, cache)
714+
end
715+
708716
function __construct_problem(
709717
cache::FIRKCacheExpand{iip, T, DC, tune_parameters}, y, loss_bc::BC, loss_collocation::C,
710718
loss::LF, ::StandardBVProblem, ::Val{true}
@@ -1400,7 +1408,7 @@ end
14001408
y_ = recursive_unflatten!(y, u)
14011409
resids = [get_tmp(r, u) for r in residual]
14021410
Φ!(resids[2:end], cache, y_, u, trait, constraint)
1403-
eval_sol.u[1:end] .= y_
1411+
eval_sol = __firk_eval_sol!(eval_sol, y_, mesh, cache)
14041412
eval_bc_residual!(resids[1], pt, bc!, eval_sol, p, mesh)
14051413
recursive_flatten!(resid, resids)
14061414
return nothing
@@ -1413,7 +1421,7 @@ end
14131421
y_ = recursive_unflatten!(y, u)
14141422
resids = [r for r in residual]
14151423
Φ!(resids[2:end], cache, y_, u, trait, constraint)
1416-
eval_sol.u[1:end] .= y_
1424+
eval_sol = __firk_eval_sol!(eval_sol, y_, mesh, cache)
14171425
eval_bc_residual!(resids[1], pt, bc!, eval_sol, p, mesh)
14181426
recursive_flatten!(resid, resids)
14191427
return nothing
@@ -1473,7 +1481,7 @@ end
14731481
u, p, y, pt::StandardBVProblem, bc::BC, mesh, cache, eval_sol, trait
14741482
) where {BC}
14751483
y_ = recursive_unflatten!(y, u)
1476-
eval_sol.u[1:end] .= y_
1484+
eval_sol = __firk_eval_sol!(eval_sol, y_, mesh, cache)
14771485
resid_bc = eval_bc_residual(pt, bc, eval_sol, p, mesh)
14781486
resid_co = Φ(cache, y_, u, trait)
14791487
return vcat(resid_bc, mapreduce(vec, vcat, resid_co))

0 commit comments

Comments
 (0)