11recursive_length (x:: Vector{<:AbstractArray} ) = sum (length, x)
2- recursive_length (x:: Vector{<:MaybeDiffCache} ) = sum (xᵢ -> length (xᵢ. u ), x)
2+ recursive_length (x:: Vector{<:MaybeDiffCache} ) = sum (xᵢ -> length (xᵢ. du ), x)
33
44function recursive_flatten (x:: Vector{<:AbstractArray} )
55 y = zero (first (x), recursive_length (x))
1717end
1818@views function recursive_flatten_twopoint! (
1919 y:: AbstractVector , x:: Vector{<:AbstractArray} , sizes)
20- x_, xiter = Iterators . peel (x)
20+ x_, xiter = first (x), x[ 2 : end ]
2121 copyto! (y[1 : prod (sizes[1 ])], x_[1 : prod (sizes[1 ])])
2222 i = prod (sizes[1 ])
2323 for xᵢ in xiter
7272 return z
7373end
7474
75+ """
76+ interval(mesh, t)
77+
78+ Find the interval that `t` belongs to in `mesh`. Assumes that `mesh` is sorted.
79+ """
80+ function interval (mesh, t)
81+ return clamp (searchsortedfirst (mesh, t) - 1 , 1 , length (mesh) - 1 )
82+ end
83+
7584# # Easier to dispatch
7685eval_bc_residual (pt, bc:: BC , sol, p) where {BC} = eval_bc_residual (pt, bc, sol, p, sol. t)
7786eval_bc_residual (_, bc:: BC , sol, p, t) where {BC} = bc (sol, p, t)
78- function eval_bc_residual (:: TwoPointBVProblem , (bca, bcb):: BC , sol, p, t) where {BC}
79- ua = sol isa VectorOfArray ? sol[:, 1 ] : sol (first (t))
80- ub = sol isa VectorOfArray ? sol[:, end ] : sol (last (t))
87+ function eval_bc_residual (
88+ :: TwoPointBVProblem , (bca, bcb):: BC , sol:: AbstractVectorOfArray , p, t) where {BC}
89+ ua = sol[:, 1 ]
90+ ub = sol[:, end ]
91+ resida = bca (ua, p)
92+ residb = bcb (ub, p)
93+ return (resida, residb)
94+ end
95+ function eval_bc_residual (
96+ :: TwoPointBVProblem , (bca, bcb):: BC , sol:: AbstractArray , p, t) where {BC}
97+ ua = first (sol)
98+ ub = last (sol)
8199 resida = bca (ua, p)
82100 residb = bcb (ub, p)
83101 return (resida, residb)
@@ -87,18 +105,42 @@ function eval_bc_residual!(resid, pt, bc!::BC, sol, p) where {BC}
87105 return eval_bc_residual! (resid, pt, bc!, sol, p, sol. t)
88106end
89107eval_bc_residual! (resid, _, bc!:: BC , sol, p, t) where {BC} = bc! (resid, sol, p, t)
90- @views function eval_bc_residual! (
91- resid, :: TwoPointBVProblem , (bca!, bcb!) :: BC , sol , p, t) where {BC}
92- ua = sol isa VectorOfArray ? sol [:, 1 ] : sol ( first (t))
93- ub = sol isa VectorOfArray ? sol [:, end ] : sol ( last (t))
108+ @views function eval_bc_residual! (resid, :: TwoPointBVProblem , (bca!, bcb!) :: BC ,
109+ sol :: AbstractVectorOfArray , p, t) where {BC}
110+ ua = sol[:, 1 ]
111+ ub = sol[:, end ]
94112 bca! (resid. resida, ua, p)
95113 bcb! (resid. residb, ub, p)
96114 return resid
97115end
98116@views function eval_bc_residual! (
99- resid:: Tuple , :: TwoPointBVProblem , (bca!, bcb!):: BC , sol, p, t) where {BC}
100- ua = sol isa VectorOfArray ? sol[:, 1 ] : sol (first (t))
101- ub = sol isa VectorOfArray ? sol[:, end ] : sol (last (t))
117+ resid, :: TwoPointBVProblem , (bca!, bcb!):: BC , sol:: AbstractArray , p, t) where {BC}
118+ ua = first (sol)
119+ ub = last (sol)
120+ bca! (resid. resida, ua, p)
121+ bcb! (resid. residb, ub, p)
122+ return resid
123+ end
124+ @views function eval_bc_residual! (resid:: Tuple , :: TwoPointBVProblem , (bca!, bcb!):: BC ,
125+ sol:: AbstractVectorOfArray , p, t) where {BC}
126+ ua = sol[:, 1 ]
127+ ub = sol[:, end ]
128+ bca! (resid[1 ], ua, p)
129+ bcb! (resid[2 ], ub, p)
130+ return resid
131+ end
132+ @views function eval_bc_residual! (resid:: Tuple , :: TwoPointBVProblem , (bca!, bcb!):: BC ,
133+ sol:: AbstractArray , p, t) where {BC}
134+ ua = first (sol)
135+ ub = last (sol)
136+ bca! (resid[1 ], ua, p)
137+ bcb! (resid[2 ], ub, p)
138+ return resid
139+ end
140+ @views function eval_bc_residual! (resid:: Tuple , :: TwoPointBVProblem , (bca!, bcb!):: BC ,
141+ sol:: SciMLBase.ODESolution , p, t) where {BC}
142+ ua = first (sol)
143+ ub = last (sol)
102144 bca! (resid[1 ], ua, p)
103145 bcb! (resid[2 ], ub, p)
104146 return resid
@@ -108,14 +150,22 @@ function eval_bc_residual(::StandardSecondOrderBVProblem, bc::BC, y, dy, p, t) w
108150 res_bc = bc (dy, y, p, t)
109151 return res_bc
110152end
153+ function eval_bc_residual (:: TwoPointSecondOrderBVProblem , (bca, bcb):: BC ,
154+ sol:: AbstractVectorOfArray , p, t) where {BC}
155+ L = length (t)
156+ ua = sol[:, 1 ]
157+ ub = sol[:, L]
158+ dua = sol[:, L + 1 ]
159+ dub = sol[:, end ]
160+ return vcat (bca (dua, ua, p), bcb (dub, ub, p))
161+ end
111162function eval_bc_residual (
112- :: TwoPointSecondOrderBVProblem , (bca, bcb):: BC , sol, p, t) where {BC}
113- M = length (sol[1 ])
163+ :: TwoPointSecondOrderBVProblem , (bca, bcb):: BC , sol:: AbstractArray , p, t) where {BC}
114164 L = length (t)
115- ua = sol isa VectorOfArray ? sol[:, 1 ] : sol ( first (t))[ 1 : M]
116- ub = sol isa VectorOfArray ? sol[:, L] : sol ( last (t))[ 1 : M ]
117- dua = sol isa VectorOfArray ? sol[:, L + 1 ] : sol ( first (t))[(M + 1 ) : end ]
118- dub = sol isa VectorOfArray ? sol[:, end ] : sol ( last (t))[(M + 1 ) : end ]
165+ ua = first (sol)
166+ ub = sol[L ]
167+ dua = sol[ L + 1 ]
168+ dub = last (sol)
119169 return vcat (bca (dua, ua, p), bcb (dub, ub, p))
120170end
121171
@@ -138,14 +188,23 @@ function eval_bc_residual!(resid::AbstractArray{<:AbstractArray},
138188 copyto! (resid[2 ], res_bc[(M + 1 ): end ])
139189end
140190
141- function eval_bc_residual! (
142- resid, :: TwoPointSecondOrderBVProblem , (bca!, bcb!):: BC , sol, p, t) where {BC}
143- M = length (sol[1 ])
191+ function eval_bc_residual! (resid, :: TwoPointSecondOrderBVProblem , (bca!, bcb!):: BC ,
192+ sol:: AbstractVectorOfArray , p, t) where {BC}
193+ L = length (t)
194+ ua = sol[:, 1 ]
195+ ub = sol[:, L]
196+ dua = sol[:, L + 1 ]
197+ dub = sol[:, end ]
198+ bca! (resid[1 ], dua, ua, p)
199+ bcb! (resid[2 ], dub, ub, p)
200+ end
201+ function eval_bc_residual! (resid, :: TwoPointSecondOrderBVProblem ,
202+ (bca!, bcb!):: BC , sol:: AbstractArray , p, t) where {BC}
144203 L = length (t)
145- ua = sol isa VectorOfArray ? sol[:, 1 ] : sol ( first (t))[ 1 : M]
146- ub = sol isa VectorOfArray ? sol[:, L] : sol ( last (t))[ 1 : M ]
147- dua = sol isa VectorOfArray ? sol[:, L + 1 ] : sol ( first (t))[(M + 1 ) : end ]
148- dub = sol isa VectorOfArray ? sol[:, end ] : sol ( last (t))[(M + 1 ) : end ]
204+ ua = first (sol)
205+ ub = sol[L ]
206+ dua = sol[ L + 1 ]
207+ dub = last (sol)
149208 bca! (resid[1 ], dua, ua, p)
150209 bcb! (resid[2 ], dub, ub, p)
151210end
@@ -169,6 +228,7 @@ function __resize!(x::AbstractVector{<:AbstractArray}, n, M)
169228end
170229
171230__resize! (:: Nothing , n, _) = nothing
231+ __resize! (:: Nothing , n, _, _) = nothing
172232
173233function __resize! (x:: AbstractVector{<:MaybeDiffCache} , n, M)
174234 N = n - length (x)
284344end
285345
286346@inline __ones_like (args... ) = __fill_like (1 , args... )
347+ @inline __zeros_like (args... ) = __fill_like (0 , args... )
287348
288349@inline __safe_vec (x) = vec (x)
289350@inline __safe_vec (x:: Tuple ) = mapreduce (__safe_vec, vcat, x)
0 commit comments