@@ -9,10 +9,10 @@ function __solve(prob::BVProblem, _alg::MultipleShooting; odesolve_kwargs = (;),
9
9
iip, bc, u0, u0_size = isinplace (prob), prob. f. bc, deepcopy (u0), size (u0)
10
10
11
11
__alg = concretize_jacobian_algorithm (_alg, prob)
12
- alg = if has_initial_guess && Nig != __alg. nshoots + 1
12
+ alg = if has_initial_guess && Nig != __alg. nshoots
13
13
verbose &&
14
- @warn " Initial guess length != `nshoots + 1`! Adapting to `nshoots = $(Nig - 1 ) `"
15
- update_nshoots (__alg, Nig - 1 )
14
+ @warn " Initial guess length != `nshoots + 1`! Adapting to `nshoots = $(Nig) `"
15
+ update_nshoots (__alg, Nig)
16
16
else
17
17
__alg
18
18
end
@@ -57,13 +57,7 @@ function __solve(prob::BVProblem, _alg::MultipleShooting; odesolve_kwargs = (;),
57
57
compute_bc_residual! = if prob. problem_type isa TwoPointBVProblem
58
58
@views function compute_bc_residual_tp! (resid_bc, us:: ArrayPartition , p,
59
59
cur_nshoots, nodes, resid_nodes:: Union{Nothing, MaybeDiffCache} = nothing )
60
- ua, ub0 = us. x
61
- # Just Recompute the last ODE Solution
62
- lastodeprob = ODEProblem {iip} (f, reshape (ub0, u0_size),
63
- (nodes[end - 1 ], nodes[end ]), p)
64
- sol_ode_last = __solve (lastodeprob, alg. ode_alg; odesolve_kwargs... , verbose,
65
- kwargs... , save_everystep = false , saveat = (), save_end = true )
66
- ub = vec (sol_ode_last. u[end ])
60
+ ua, ub = us. x
67
61
68
62
resid_bc_a, resid_bc_b = if resid_bc isa ArrayPartition
69
63
resid_bc. x
@@ -147,7 +141,7 @@ function __solve(prob::BVProblem, _alg::MultipleShooting; odesolve_kwargs = (;),
147
141
resida, residb = resid_bc. x
148
142
J_bc[1 : length (resida), 1 : N] .= J_bc′[1 : length (resida), 1 : N]
149
143
idxᵢ = (length (resida) + 1 ): (length (resida) + length (residb))
150
- J_bc[idxᵢ, (end - 2 N + 1 ): ( end - N) ] .= J_bc′[idxᵢ, (end - N + 1 ): end ]
144
+ J_bc[idxᵢ, (end - N + 1 ): end ] .= J_bc′[idxᵢ, (end - N + 1 ): end ]
151
145
152
146
return nothing
153
147
end
@@ -215,7 +209,8 @@ function __solve(prob::BVProblem, _alg::MultipleShooting; odesolve_kwargs = (;),
215
209
216
210
bc_jac_cache = (bc_jac_cache_partial, init_jacobian (bc_jac_cache_partial))
217
211
218
- jac_prototype = if @isdefined (J_full)
212
+ jac_prototype = if alg. jac_alg. nonbc_diffmode isa AbstractSparseADType ||
213
+ alg. jac_alg. bc_diffmode isa AbstractSparseADType
219
214
J_full
220
215
else
221
216
__zeros_like (u_at_nodes, length (resid_prototype), length (u_at_nodes))
@@ -236,7 +231,7 @@ function __solve(prob::BVProblem, _alg::MultipleShooting; odesolve_kwargs = (;),
236
231
nodes); resid_prototype, jac = jac_fn, jac_prototype)
237
232
nlprob = NonlinearProblem (loss_function!, u_at_nodes, prob. p)
238
233
sol_nlsolve = __solve (nlprob, alg. nlsolve; nlsolve_kwargs... , verbose, kwargs... )
239
- # u_at_nodes = sol_nlsolve.u
234
+ u_at_nodes = sol_nlsolve. u:: typeof (u0)
240
235
end
241
236
242
237
single_shooting_prob = remake (prob; u0 = reshape (u_at_nodes[1 : N], u0_size))
0 commit comments