Skip to content

Commit fa36d42

Browse files
Merge pull request #537 from ChrisRackauckas-Claude/agent/mirk-f-prototype-u0-fallback
Allow constrained MIRK without f_prototype
2 parents 36e9daa + fa38178 commit fa36d42

2 files changed

Lines changed: 16 additions & 8 deletions

File tree

lib/BoundaryValueDiffEqMIRK/src/mirk.jl

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,11 @@ function SciMLBase.__init(
8484
y = __alloc.(copy.(y₀.u))
8585
TU, ITU = constructMIRK(alg, T)
8686
stage = alg_stage(alg)
87-
f_prototype = isnothing(prob.f.f_prototype) ? nothing : __vec(prob.f.f_prototype)
87+
f_prototype = if isnothing(prob.f.f_prototype)
88+
constraint ? __vec(u0) : nothing
89+
else
90+
__vec(prob.f.f_prototype)
91+
end
8892
L_f_prototype = isnothing(f_prototype) ? N : length(f_prototype)
8993

9094
k_discrete = if !constraint

lib/BoundaryValueDiffEqMIRK/test/Core/dynamic_optimization_tests.jl

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -78,12 +78,16 @@ end
7878
res[2] = u(1.0)[1]
7979
end
8080

81-
constrained_fun = BVPFunction(constrained_f!, constrained_bc!; f_prototype = zeros(2))
82-
constrained_prob = BVProblem(
83-
constrained_fun, [0.0, 0.0], (0.0, 1.0); lb = [-10.0, -10.0], ub = [10.0, 10.0]
84-
)
85-
sol = solve(constrained_prob, MIRK4(; optimize = IpoptOptimizer()); dt = 0.01)
81+
for constrained_fun in (
82+
BVPFunction(constrained_f!, constrained_bc!),
83+
BVPFunction(constrained_f!, constrained_bc!; f_prototype = zeros(2)),
84+
)
85+
constrained_prob = BVProblem(
86+
constrained_fun, [0.0, 0.0], (0.0, 1.0); lb = [-10.0, -10.0], ub = [10.0, 10.0]
87+
)
88+
sol = solve(constrained_prob, MIRK4(; optimize = IpoptOptimizer()); dt = 0.01)
8689

87-
@test SciMLBase.successful_retcode(sol)
88-
@test sol(0.5) [sinh(0.5) / sinh(1.0), -cosh(0.5) / sinh(1.0)] rtol = 1.0e-4
90+
@test SciMLBase.successful_retcode(sol)
91+
@test sol(0.5) [sinh(0.5) / sinh(1.0), -cosh(0.5) / sinh(1.0)] rtol = 1.0e-4
92+
end
8993
end

0 commit comments

Comments
 (0)