-
-
Notifications
You must be signed in to change notification settings - Fork 36
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Support for u0 initial guess function #133
Merged
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
e3e8936
Support for u0 initial guess function
avik-pal d845ecf
Bump DiffEqBase version
avik-pal cc4de87
Add tests for initial guess function
avik-pal 94cd200
Fix incorrect rebase
avik-pal 4740b04
Add depwarn for single argument initial guess
avik-pal File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
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,82 @@ | ||
using BoundaryValueDiffEq, OrdinaryDiffEq, Test, LinearAlgebra | ||
|
||
@testset "Initial Guess" begin | ||
# Problem taken from https://github.com/SciML/BoundaryValueDiffEq.jl/issues/117#issuecomment-1780981510 | ||
function affine_connection(a, Xc, Yc) | ||
MR = 3.0 | ||
Mr = 2.0 | ||
Zc = similar(Xc) | ||
θ = a[1] | ||
sinθ, cosθ = sincos(θ) | ||
Γ¹₂₂ = (MR + Mr * cosθ) * sinθ / Mr | ||
Γ²₁₂ = -Mr * sinθ / (MR + Mr * cosθ) | ||
|
||
Zc[1] = Xc[2] * Γ¹₂₂ * Yc[2] | ||
Zc[2] = Γ²₁₂ * (Xc[1] * Yc[2] + Xc[2] * Yc[1]) | ||
return Zc | ||
end | ||
|
||
function chart_log_problem!(du, u, p, t) | ||
mid = div(length(u), 2) | ||
a = u[1:mid] | ||
dx = u[(mid + 1):end] | ||
ddx = -affine_connection(a, dx, dx) | ||
du[1:mid] .= dx | ||
du[(mid + 1):end] .= ddx | ||
return du | ||
end | ||
|
||
function bc1!(residual, u, p, t) | ||
a1, a2 = p[1:2], p[3:4] | ||
mid = div(length(u[1]), 2) | ||
residual[1:mid] = u[1][1:mid] - a1 | ||
residual[(mid + 1):end] = u[end][1:mid] - a2 | ||
return residual | ||
end | ||
|
||
function initial_guess_1(p, t) | ||
a1, a2 = p[1:2], p[3:4] | ||
return vcat(t * a1 + (1 - t) * a2, zero(a1)) | ||
end | ||
|
||
function initial_guess_2(t) | ||
a1, a2 = [0.5, -1.2], [-0.5, 0.3] | ||
return vcat(t * a1 + (1 - t) * a2, zero(a1)) | ||
end | ||
|
||
dt = 0.05 | ||
p = [0.5, -1.2, -0.5, 0.3] | ||
tspan = (0.0, 1.0) | ||
|
||
bvp1 = BVProblem(chart_log_problem!, bc1!, initial_guess_1, tspan, p) | ||
|
||
algs = [Shooting(Tsit5()), MultipleShooting(10, Tsit5()), MIRK4(), MIRK5(), MIRK6()] | ||
|
||
for alg in algs | ||
if alg isa Shooting || alg isa MultipleShooting | ||
sol = solve(bvp1, alg) | ||
else | ||
sol = solve(bvp1, alg; dt) | ||
end | ||
@test SciMLBase.successful_retcode(sol) | ||
resid = zeros(4) | ||
bc1!(resid, sol, p, sol.t) | ||
@test norm(resid) < 1e-10 | ||
end | ||
|
||
bvp2 = BVProblem(chart_log_problem!, bc1!, initial_guess_2, tspan, p) | ||
|
||
for alg in algs | ||
if alg isa Shooting || alg isa MultipleShooting | ||
sol = solve(bvp2, alg) | ||
@test_deprecated solve(bvp2, alg) | ||
else | ||
sol = solve(bvp2, alg; dt) | ||
@test_deprecated solve(bvp2, alg; dt) | ||
end | ||
@test SciMLBase.successful_retcode(sol) | ||
resid = zeros(4) | ||
bc1!(resid, sol, p, sol.t) | ||
@test norm(resid) < 1e-10 | ||
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
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
note that in v1.10 this isn't needed, and it can be incorrect.