Skip to content

Commit 1fc2a50

Browse files
committed
Add tests for generate_bvp_cost
1 parent 8d52453 commit 1fc2a50

File tree

1 file changed

+18
-0
lines changed

1 file changed

+18
-0
lines changed

lib/ModelingToolkitBase/test/bvproblem.jl

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -324,6 +324,15 @@ end
324324
_t = tspan[2]
325325
@test costfn(sol, prob.p, _t) (sol(0.6; idxs = x(t)) + 3)^2 + sol(0.3; idxs = x(t))^2
326326

327+
bvp = SciMLBase.BVProblem{true, SciMLBase.AutoSpecialize}(lksys, [u0map; parammap], tspan)
328+
sol = solve(bvp, MIRK4(), dt = 0.05)
329+
@test SciMLBase.successful_retcode(sol)
330+
331+
costfn = ModelingToolkitBase.generate_bvp_cost(
332+
lksys; expression = Val{false}, wrap_gfw = Val{true}
333+
)
334+
@test costfn(sol, bvp.p) (sol(0.6; idxs = x(t)) + 3)^2 + sol(0.3; idxs = x(t))^2
335+
327336
### With a parameter
328337
@parameters t_c
329338
costs = [y(t_c) + x(0.0), x(0.4)^2]
@@ -338,4 +347,13 @@ end
338347
)
339348
@test costfn(sol, prob.p, _t)
340349
log(sol(0.56; idxs = y(t)) + sol(0.0; idxs = x(t))) - sol(0.4; idxs = x(t))^2
350+
351+
bvp = SciMLBase.BVProblem{true, SciMLBase.AutoSpecialize}(lksys, [u0map; parammap], tspan)
352+
sol = solve(bvp, MIRK4(), dt = 0.05)
353+
@test SciMLBase.successful_retcode(sol)
354+
355+
costfn = ModelingToolkitBase.generate_bvp_cost(
356+
lksys; expression = Val{false}, wrap_gfw = Val{true}
357+
)
358+
@test costfn(sol, bvp.p) log(sol(0.56; idxs = y(t)) + sol(0.0; idxs = x(t))) - sol(0.4; idxs = x(t))^2
341359
end

0 commit comments

Comments
 (0)