-
-
Notifications
You must be signed in to change notification settings - Fork 36
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
104 additions
and
9 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
using BoundaryValueDiffEq, LinearAlgebra, Test | ||
|
||
@testset "Overconstrained BVP" begin | ||
SOLVERS = [mirk(; | ||
nlsolve = LevenbergMarquardt(; damping_initial = 1e-6, | ||
α_geodesic = 0.9, b_uphill = 2.0)) for mirk in (MIRK4, MIRK5, MIRK6)] | ||
|
||
# OOP MP-BVP | ||
f1(u, p, t) = [u[2], -u[1]] | ||
|
||
function bc1(sol, p, t) | ||
solₜ₁ = sol[1] | ||
solₜ₂ = sol[end] | ||
return [solₜ₁[1], solₜ₂[1] - 1, solₜ₂[2] + 1.729109] | ||
end | ||
|
||
tspan = (0.0, 100.0) | ||
u0 = [0.0, 1.0] | ||
|
||
bvp1 = BVProblem(BVPFunction{false}(f1, bc1; bcresid_prototype = zeros(3)), u0, tspan) | ||
|
||
for solver in SOLVERS | ||
@time sol = solve(bvp1, solver; verbose = false, dt = 1.0, abstol = 1e-3, | ||
reltol = 1e-3, nlsolve_kwargs = (; maxiters = 50, abstol = 1e-2, reltol = 1e-2)) | ||
@test norm(bc1(sol, nothing, tspan)) < 1e-2 | ||
end | ||
|
||
# IIP MP-BVP | ||
function f1!(du, u, p, t) | ||
du[1] = u[2] | ||
du[2] = -u[1] | ||
return nothing | ||
end | ||
|
||
function bc1!(resid, sol, p, t) | ||
solₜ₁ = sol[1] | ||
solₜ₂ = sol[end] | ||
# We know that this overconstrained system has a solution | ||
resid[1] = solₜ₁[1] | ||
resid[2] = solₜ₂[1] - 1 | ||
resid[3] = solₜ₂[2] + 1.729109 | ||
return nothing | ||
end | ||
|
||
bvp2 = BVProblem(BVPFunction{true}(f1!, bc1!; bcresid_prototype = zeros(3)), u0, tspan) | ||
|
||
for solver in SOLVERS | ||
@time sol = solve(bvp2, solver; verbose = false, dt = 1.0, abstol = 1e-3, | ||
reltol = 1e-3, nlsolve_kwargs = (; maxiters = 50, abstol = 1e-3, reltol = 1e-3)) | ||
resid_f = Array{Float64}(undef, 3) | ||
bc1!(resid_f, sol, nothing, sol.t) | ||
@test norm(resid_f) < 1e-2 | ||
end | ||
|
||
# OOP TP-BVP | ||
bc1a(ua, p) = [ua[1]] | ||
bc1b(ub, p) = [ub[1] - 1, ub[2] + 1.729109] | ||
|
||
bvp3 = TwoPointBVProblem(BVPFunction{false}(f1, (bc1a, bc1b); twopoint = Val(true), | ||
bcresid_prototype = (zeros(1), zeros(2))), u0, tspan) | ||
|
||
for solver in SOLVERS | ||
@time sol = solve(bvp3, solver; verbose = false, dt = 1.0, abstol = 1e-3, | ||
reltol = 1e-3, nlsolve_kwargs = (; maxiters = 50, abstol = 1e-3, reltol = 1e-3)) | ||
@test norm(vcat(bc1a(sol[1], nothing), bc1b(sol[end], nothing))) < 1e-2 | ||
end | ||
|
||
# IIP TP-BVP | ||
bc1a!(resid, ua, p) = (resid[1] = ua[1]) | ||
bc1b!(resid, ub, p) = (resid[1] = ub[1] - 1; resid[2] = ub[2] + 1.729109) | ||
|
||
bvp4 = TwoPointBVProblem(BVPFunction{true}(f1!, (bc1a!, bc1b!); twopoint = Val(true), | ||
bcresid_prototype = (zeros(1), zeros(2))), u0, tspan) | ||
|
||
for solver in SOLVERS | ||
@time sol = solve(bvp3, solver; verbose = false, dt = 1.0, abstol = 1e-3, | ||
reltol = 1e-3, nlsolve_kwargs = (; maxiters = 50, abstol = 1e-3, reltol = 1e-3)) | ||
resida = Array{Float64}(undef, 1) | ||
residb = Array{Float64}(undef, 2) | ||
bc1a!(resida, sol(0.0), nothing) | ||
bc1b!(residb, sol(100.0), nothing) | ||
@test norm(vcat(resida, residb)) < 1e-2 | ||
end | ||
end |
This file contains 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