Skip to content

Commit

Permalink
Fix some incorrect usage in tests
Browse files Browse the repository at this point in the history
  • Loading branch information
ErikQQY committed Jan 17, 2025
1 parent e1b9cee commit e213f72
Show file tree
Hide file tree
Showing 9 changed files with 26 additions and 25 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ using BoundaryValueDiffEqCore: BVPJacobianAlgorithm, __extract_problem_details,
__concrete_nonlinearsolve_algorithm,
__internal_nlsolve_problem, BoundaryValueDiffEqAlgorithm,
__vec, __vec_f, __vec_f!, __vec_bc, __vec_bc!,
__extract_mesh, get_dense_ad
__extract_mesh, get_dense_ad, __sparse_jacobian_cache
using ConcreteStructs: @concrete
using DiffEqBase: DiffEqBase
using FastClosures: @closure
Expand Down
25 changes: 12 additions & 13 deletions lib/BoundaryValueDiffEqCore/src/utils.jl
Original file line number Diff line number Diff line change
Expand Up @@ -104,15 +104,14 @@ end
return resid
end

function eval_bc_residual(::StandardSecondOrderBVProblem, bc::BC, y, dy, p, mesh) where {BC}
L = length(mesh)
res_bc = bc(dy, y, p, mesh)
function eval_bc_residual(::StandardSecondOrderBVProblem, bc::BC, y, dy, p, t) where {BC}
res_bc = bc(dy, y, p, t)
return res_bc
end
function eval_bc_residual(
::TwoPointSecondOrderBVProblem, (bca, bcb)::BC, sol, p, mesh) where {BC}
::TwoPointSecondOrderBVProblem, (bca, bcb)::BC, sol, p, t) where {BC}
M = length(sol[1])
L = length(mesh)
L = length(t)
ua = sol isa VectorOfArray ? sol[:, 1] : sol(first(t))[1:M]
ub = sol isa VectorOfArray ? sol[:, L] : sol(last(t))[1:M]
dua = sol isa VectorOfArray ? sol[:, L + 1] : sol(first(t))[(M + 1):end]
Expand All @@ -125,22 +124,22 @@ function eval_bc_residual!(resid, ::StandardBVProblem, bc!::BC, sol, p, t) where
end

function eval_bc_residual!(
resid, ::StandardSecondOrderBVProblem, bc!::BC, sol, dsol, p, mesh) where {BC}
resid, ::StandardSecondOrderBVProblem, bc!::BC, sol, dsol, p, t) where {BC}
M = length(sol[1])
res_bc = vcat(resid[1], resid[2])
bc!(res_bc, dsol, sol, p, mesh)
bc!(res_bc, dsol, sol, p, t)
copyto!(resid[1], res_bc[1:M])
copyto!(resid[2], res_bc[(M + 1):end])
end

function eval_bc_residual!(
resid, ::TwoPointSecondOrderBVProblem, (bca!, bcb!)::BC, sol, p, mesh) where {BC}
resid, ::TwoPointSecondOrderBVProblem, (bca!, bcb!)::BC, sol, p, t) where {BC}
M = length(sol[1])
L = length(mesh)
ua = sol isa VectorOfArray ? sol[:, 1] : sol(first(mesh))[1:M]
ub = sol isa VectorOfArray ? sol[:, L] : sol(last(mesh))[1:M]
dua = sol isa VectorOfArray ? sol[:, L + 1] : sol(first(mesh))[(M + 1):end]
dub = sol isa VectorOfArray ? sol[:, end] : sol(last(mesh))[(M + 1):end]
L = length(t)
ua = sol isa VectorOfArray ? sol[:, 1] : sol(first(t))[1:M]
ub = sol isa VectorOfArray ? sol[:, L] : sol(last(t))[1:M]
dua = sol isa VectorOfArray ? sol[:, L + 1] : sol(first(t))[(M + 1):end]
dub = sol isa VectorOfArray ? sol[:, end] : sol(last(t))[(M + 1):end]
bca!(resid[1], dua, ua, p)
bcb!(resid[2], dub, ub, p)
end
Expand Down
6 changes: 4 additions & 2 deletions lib/BoundaryValueDiffEqMIRKN/src/mirkn.jl
Original file line number Diff line number Diff line change
Expand Up @@ -179,17 +179,19 @@ end
@views function __mirkn_loss!(resid, u, p, y, pt::TwoPointSecondOrderBVProblem,
bc!::BC, residual, mesh, cache::MIRKNCache) where {BC}
y_ = recursive_unflatten!(y, u)
soly_ = VectorOfArray(y_)
resids = [get_tmp(r, u) for r in residual]
Φ!(resids[3:end], cache, y_, u, p)
eval_bc_residual!(resids, pt, bc!, y_, p, mesh)
eval_bc_residual!(resids, pt, bc!, soly_, p, mesh)
recursive_flatten!(resid, resids)
return nothing
end

@views function __mirkn_loss(u, p, y, pt::TwoPointSecondOrderBVProblem,
bc!::BC, mesh, cache::MIRKNCache) where {BC}
y_ = recursive_unflatten!(y, u)
soly_ = VectorOfArray(y_)
resid_co = Φ(cache, y_, u, p)
resid_bc = eval_bc_residual(pt, bc!, y_, p, mesh)
resid_bc = eval_bc_residual(pt, bc!, soly_, p, mesh)
return vcat(resid_bc, mapreduce(vec, vcat, resid_co))
end
8 changes: 4 additions & 4 deletions lib/BoundaryValueDiffEqShooting/test/basic_problems_tests.jl
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
@testitem "Basic Shooting" begin
using BoundaryValueDiffEqShooting, LinearAlgebra, LinearSolve, JET
using BoundaryValueDiffEqShooting, LinearAlgebra, LinearSolve, OrdinaryDiffEq, JET

SOLVERS = [Shooting(Tsit5(), NewtonRaphson(; autodiff = AutoFiniteDiff())),
Shooting(Tsit5(), NewtonRaphson(; autodiff = AutoForwardDiff(; chunksize = 2))),
Expand Down Expand Up @@ -126,7 +126,7 @@
end

@testitem "Shooting with Complex Values" begin
using BoundaryValueDiffEqShooting, LinearAlgebra, LinearSolve
using BoundaryValueDiffEqShooting, OrdinaryDiffEq, LinearAlgebra, LinearSolve

SOLVERS = [
Shooting(Vern7(), NewtonRaphson(; autodiff = AutoFiniteDiff())), Shooting(Vern7()),
Expand Down Expand Up @@ -160,7 +160,7 @@ end
end

@testitem "Flow in a Channel" begin
using BoundaryValueDiffEqShooting, LinearAlgebra, LinearSolve
using BoundaryValueDiffEqShooting, OrdinaryDiffEq, LinearAlgebra, LinearSolve

function flow_in_a_channel!(du, u, p, t)
R, P = p
Expand Down Expand Up @@ -209,7 +209,7 @@ end
end
#FIXME: MultipleShooting fails for large out-of-place BVP systems
@testitem "Ray Tracing" begin
using BoundaryValueDiffEqShooting, LinearAlgebra, LinearSolve
using BoundaryValueDiffEqShooting, OrdinaryDiffEq, LinearAlgebra, LinearSolve

@inline v(x, y, z, p) = 1 / (4 + cos(p[1] * x) + sin(p[2] * y) - cos(p[3] * z))
@inline ux(x, y, z, p) = -p[1] * sin(p[1] * x)
Expand Down
2 changes: 1 addition & 1 deletion lib/BoundaryValueDiffEqShooting/test/nlls_tests.jl
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
@testitem "Overconstrained BVP" begin
using BoundaryValueDiffEqShooting, LinearAlgebra, JET
using BoundaryValueDiffEqShooting, OrdinaryDiffEq, LinearAlgebra, JET

SOLVERS = [
Shooting(Tsit5(), NewtonRaphson(),
Expand Down
2 changes: 1 addition & 1 deletion lib/BoundaryValueDiffEqShooting/test/orbital_tests.jl
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
@testitem "Lambert's Problem" begin
using BoundaryValueDiffEqShooting, LinearAlgebra
using BoundaryValueDiffEqShooting, OrdinaryDiffEq, LinearAlgebra

y0 = [-4.7763169762853989E+06, -3.8386398704441520E+05, -5.3500183933132319E+06,
-5528.612564911408, 1216.8442360202787, 4845.114446429901]
Expand Down
2 changes: 1 addition & 1 deletion test/misc/manifolds_tests.jl
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
@testitem "Manifolds.jl Integration" begin
using LinearAlgebra
using LinearAlgebra, OrdinaryDiffEq

struct EmbeddedTorus
R::Float64
Expand Down
2 changes: 1 addition & 1 deletion test/misc/non_vector_input_tests.jl
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
@testitem "Non-Vector Inputs" begin
using LinearAlgebra, NonlinearSolveFirstOrder
using LinearAlgebra, NonlinearSolveFirstOrder, OrdinaryDiffEq

for order in (2, 3, 4, 5, 6)
s = Symbol("MIRK$(order)")
Expand Down
2 changes: 1 addition & 1 deletion test/misc/type_stability_tests.jl
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
@testitem "Type Stability" begin
using LinearAlgebra, BoundaryValueDiffEq
using LinearAlgebra, BoundaryValueDiffEq, OrdinaryDiffEq

f(u, p, t) = [p[1] * u[1] - p[2] * u[1] * u[2], p[3] * u[1] * u[2] - p[4] * u[2]]
function f!(du, u, p, t)
Expand Down

0 comments on commit e213f72

Please sign in to comment.