Skip to content

Commit

Permalink
Format
Browse files Browse the repository at this point in the history
  • Loading branch information
avik-pal committed Mar 20, 2024
1 parent 5439788 commit 5e60223
Show file tree
Hide file tree
Showing 7 changed files with 64 additions and 29 deletions.
3 changes: 2 additions & 1 deletion ext/BoundaryValueDiffEqODEInterfaceExt.jl
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@ module BoundaryValueDiffEqODEInterfaceExt

using SciMLBase, BoundaryValueDiffEq, ODEInterface, RecursiveArrayTools
import BoundaryValueDiffEq: __extract_u0, __flatten_initial_guess,
__extract_mesh, __initial_guess_length, __initial_guess, __has_initial_guess
__extract_mesh, __initial_guess_length, __initial_guess,
__has_initial_guess
import SciMLBase: __solve
import ODEInterface: OptionsODE, OPT_ATOL, OPT_RTOL, OPT_METHODCHOICE, OPT_DIAGNOSTICOUTPUT,
OPT_ERRORCONTROL, OPT_SINGULARTERM, OPT_MAXSTEPS, OPT_BVPCLASS,
Expand Down
42 changes: 29 additions & 13 deletions ext/BoundaryValueDiffEqOrdinaryDiffEqExt.jl
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,16 @@ end
probs = [
BVProblem(BVPFunction{true}(f1!, bc1!), u0, tspan; nlls = Val(false)),
BVProblem(BVPFunction{false}(f1, bc1), u0, tspan; nlls = Val(false)),
BVProblem(BVPFunction{true}(f1!, (bc1_a!, bc1_b!); bcresid_prototype,
twopoint = Val(true)), u0, tspan; nlls = Val(false)),
BVProblem(BVPFunction{false}(f1, (bc1_a, bc1_b); bcresid_prototype,
twopoint = Val(true)), u0, tspan; nlls = Val(false)),
BVProblem(
BVPFunction{true}(f1!, (bc1_a!, bc1_b!); bcresid_prototype,
twopoint = Val(true)),
u0,
tspan;
nlls = Val(false)),
BVProblem(
BVPFunction{false}(f1, (bc1_a, bc1_b); bcresid_prototype,
twopoint = Val(true)),
u0, tspan; nlls = Val(false))
]

algs = []
Expand Down Expand Up @@ -94,16 +100,26 @@ end
bcresid_prototype2 = (Array{Float64}(undef, 1), Array{Float64}(undef, 2))

probs = [
BVProblem(BVPFunction{true}(f1_nlls!, bc1_nlls!;
bcresid_prototype = bcresid_prototype1), u0, tspan; nlls = Val(true)),
BVProblem(BVPFunction{false}(f1_nlls, bc1_nlls;
bcresid_prototype = bcresid_prototype1), u0, tspan; nlls = Val(true)),
BVProblem(BVPFunction{true}(f1_nlls!, (bc1_nlls_a!, bc1_nlls_b!);
bcresid_prototype = bcresid_prototype2, twopoint = Val(true)), u0, tspan;
nlls = Val(true)),
BVProblem(BVPFunction{false}(f1_nlls, (bc1_nlls_a, bc1_nlls_b);
bcresid_prototype = bcresid_prototype2, twopoint = Val(true)), u0, tspan;
BVProblem(
BVPFunction{true}(f1_nlls!, bc1_nlls!;
bcresid_prototype = bcresid_prototype1),
u0, tspan; nlls = Val(true)),
BVProblem(
BVPFunction{false}(f1_nlls, bc1_nlls;
bcresid_prototype = bcresid_prototype1),
u0, tspan; nlls = Val(true)),
BVProblem(
BVPFunction{true}(f1_nlls!, (bc1_nlls_a!, bc1_nlls_b!);
bcresid_prototype = bcresid_prototype2, twopoint = Val(true)),
u0,
tspan;
nlls = Val(true)),
BVProblem(
BVPFunction{false}(f1_nlls, (bc1_nlls_a, bc1_nlls_b);
bcresid_prototype = bcresid_prototype2, twopoint = Val(true)),
u0,
tspan;
nlls = Val(true))
]

algs = []
Expand Down
2 changes: 2 additions & 0 deletions src/algorithms.jl
Original file line number Diff line number Diff line change
Expand Up @@ -305,9 +305,11 @@ ODEs. It incorporates a new basis representation replacing b-splines, and improv
the linear and nonlinear algebraic equation solvers.
!!! warning
Only supports two-point boundary value problems.
!!! note
Only available if the `ODEInterface` package is loaded.
"""
struct COLNEW <: BoundaryValueDiffEqAlgorithm
Expand Down
2 changes: 1 addition & 1 deletion test/misc/odeinterface_wrapper.jl
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
using Test, BoundaryValueDiffEq, LinearAlgebra, ODEInterface, Random, OrdinaryDiffEq,
RecursiveArrayTools
RecursiveArrayTools

# Adaptation of https://github.com/luchr/ODEInterface.jl/blob/958b6023d1dabf775033d0b89c5401b33100bca3/examples/BasicExamples/ex7.jl
function ex7_f!(du, u, p, t)
Expand Down
22 changes: 15 additions & 7 deletions test/shooting/basic_problems.jl
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ using BoundaryValueDiffEq, LinearAlgebra, LinearSolve, OrdinaryDiffEq, Test, JET
MultipleShooting(10, Tsit5(), NewtonRaphson(; autodiff = AutoFiniteDiff())),
MultipleShooting(10, Tsit5(),
NewtonRaphson(; autodiff = AutoForwardDiff(; chunksize = 2))),
MultipleShooting(10, Tsit5()),
MultipleShooting(10, Tsit5())
]
JET_SKIP = [false, false, true, false, false, true]
JET_BROKEN = [false, false, false, false, false, false]
Expand Down Expand Up @@ -144,7 +144,7 @@ end
Shooting(Vern7(), NewtonRaphson(; autodiff = AutoFiniteDiff())),
Shooting(Vern7()),
MultipleShooting(10, Vern7(), NewtonRaphson(; autodiff = AutoFiniteDiff())),
MultipleShooting(10, Vern7()),
MultipleShooting(10, Vern7())
]

function f1!(du, u, p, t)
Expand Down Expand Up @@ -216,7 +216,7 @@ end
Shooting(AutoTsit5(Rosenbrock23()),
NewtonRaphson(; autodiff = AutoForwardDiff(; chunksize = 8))),
MultipleShooting(10, AutoTsit5(Rosenbrock23()),
NewtonRaphson(; autodiff = AutoForwardDiff(; chunksize = 8))),
NewtonRaphson(; autodiff = AutoForwardDiff(; chunksize = 8)))
]
@info "Solver: $solver"
sol = @time solve(flow_bvp, solver; abstol = 1e-8, reltol = 1e-8,
Expand Down Expand Up @@ -333,12 +333,20 @@ end
nlls = Val(false))
prob_iip = BVProblem(BVPFunction{true}(ray_tracing!, ray_tracing_bc!), u0, tspan, p;
nlls = Val(true))
prob_tp_oop = BVProblem(BVPFunction{false}(ray_tracing,
(ray_tracing_bc_a, ray_tracing_bc_b); twopoint = Val(true)), u0, tspan, p;
prob_tp_oop = BVProblem(
BVPFunction{false}(ray_tracing,
(ray_tracing_bc_a, ray_tracing_bc_b); twopoint = Val(true)),
u0,
tspan,
p;
nlls = Val(true))
prob_tp_iip = BVProblem(BVPFunction{true}(ray_tracing!,
prob_tp_iip = BVProblem(
BVPFunction{true}(ray_tracing!,
(ray_tracing_bc_a!, ray_tracing_bc_b!);
bcresid_prototype = (zeros(5), zeros(3)), twopoint = Val(true)), u0, tspan, p;
bcresid_prototype = (zeros(5), zeros(3)), twopoint = Val(true)),
u0,
tspan,
p;
nlls = Val(true))

@info "Ray Tracing: Multiple Shooting"
Expand Down
18 changes: 13 additions & 5 deletions test/shooting/nonlinear_least_squares.jl
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ using BoundaryValueDiffEq, LinearAlgebra, OrdinaryDiffEq, Test, JET
MultipleShooting(10, Tsit5(), GaussNewton(; autodiff = AutoFiniteDiff())),
MultipleShooting(10, Tsit5(),
TrustRegion(; autodiff = AutoForwardDiff(; chunksize = 2))),
MultipleShooting(10, Tsit5(), TrustRegion(; autodiff = AutoFiniteDiff())),
MultipleShooting(10, Tsit5(), TrustRegion(; autodiff = AutoFiniteDiff()))
]
JET_SKIP = [false, false, false, false, false, false, false, false, false, false]
JET_BROKEN = [false, false, false, false, false, false, false, false, false, false]
Expand Down Expand Up @@ -103,8 +103,12 @@ using BoundaryValueDiffEq, LinearAlgebra, OrdinaryDiffEq, Test, JET
bc1a(ua, p) = [ua[1]]
bc1b(ub, p) = [ub[1] - 1, ub[2] + 1.729109]

bvp3 = BVProblem(BVPFunction{false}(f1, (bc1a, bc1b); twopoint = Val(true),
bcresid_prototype = (zeros(1), zeros(2))), u0, tspan; nlls = Val(true))
bvp3 = BVProblem(
BVPFunction{false}(f1, (bc1a, bc1b); twopoint = Val(true),
bcresid_prototype = (zeros(1), zeros(2))),
u0,
tspan;
nlls = Val(true))

for (i, solver) in enumerate(SOLVERS)
@info "Testing $solver"
Expand All @@ -125,8 +129,12 @@ using BoundaryValueDiffEq, LinearAlgebra, OrdinaryDiffEq, Test, JET
bc1a!(resid, ua, p) = (resid[1] = ua[1])
bc1b!(resid, ub, p) = (resid[1] = ub[1] - 1; resid[2] = ub[2] + 1.729109)

bvp4 = BVProblem(BVPFunction{true}(f1!, (bc1a!, bc1b!); twopoint = Val(true),
bcresid_prototype = (zeros(1), zeros(2))), u0, tspan; nlls = Val(true))
bvp4 = BVProblem(
BVPFunction{true}(f1!, (bc1a!, bc1b!); twopoint = Val(true),
bcresid_prototype = (zeros(1), zeros(2))),
u0,
tspan;
nlls = Val(true))

for (i, solver) in enumerate(SOLVERS)
@info "Testing $solver"
Expand Down
4 changes: 2 additions & 2 deletions test/shooting/orbital.jl
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,15 @@ using BoundaryValueDiffEq, OrdinaryDiffEq, LinearAlgebra, Test
-5.3500183933132319E+06,
-5528.612564911408,
1216.8442360202787,
4845.114446429901,
4845.114446429901
]
init_val = [
-4.7763169762853989E+06,
-3.8386398704441520E+05,
-5.3500183933132319E+06,
7.0526926403748598E+06,
-7.9650476230388973E+05,
-1.1911128863666430E+06,
-1.1911128863666430E+06
]
J2 = 1.08262668E-3
req = 6378137
Expand Down

0 comments on commit 5e60223

Please sign in to comment.