@@ -81,11 +81,11 @@ function SciMLBase.__init(
8181 end
8282 else
8383 if prob. problem_type isa TwoPointBVProblem
84- vcat ([__alloc (__vec (bcresid_prototype))],
85- __alloc .(copy .(@view (y₀. u[2 : end ]))), __alloc .( copy .(y₀ . u)) )
84+ vcat (__alloc .( copy .(y₀ . u)), [__alloc (__vec (bcresid_prototype))],
85+ __alloc .(copy .(@view (y₀. u[2 : end ]))))
8686 else
87- vcat ([__alloc (bcresid_prototype)],
88- __alloc .(copy .(@view (y₀. u[2 : end ]))), __alloc .( copy .(y₀ . u)) )
87+ vcat (__alloc .( copy .(y₀ . u)), [__alloc (bcresid_prototype)],
88+ __alloc .(copy .(@view (y₀. u[2 : end ]))))
8989 end
9090 end
9191 else
@@ -296,10 +296,10 @@ end
296296
297297# Let's only do inplace version now since Optimization.jl only supports that.
298298
299- # J = [J_equality ;
300- # J_inequality ]
301- # where J_equality is the Jacobian we are computed from bc and collocation
302- # and J_inequality is the Jacobian from inequality constraints(whole-time inequality)
299+ # J = [J_constraints ;
300+ # J_bvp ]
301+ # where J_constraints is the Jacobian from equality/inequality constraints(whole-time equality/inequality)
302+ # and J_bvp is the Jacobian computed from bc and collocation
303303
304304@views function __mirk_loss! (
305305 resid, u, p, y, pt:: StandardBVProblem , bc!:: BC , residual, mesh, cache,
@@ -357,13 +357,13 @@ end
357357 y_ = recursive_unflatten! (y, u)
358358 L = length (y_)
359359 resids = [get_tmp (r, u) for r in residual]
360- Φ! (resids[2 : L], cache, y_, u, trait)
360+ # whole-time inequality constraints
361+ cache. prob. f. inequality .(resids[1 : L], y_, nothing )
362+ Φ! (resids[(L + 2 ): 2 L], cache, y_, u, trait)
361363 EvalSol. u[1 : end ] .= __restructure_sol (y_, cache. in_size)
362364 EvalSol. cache. k_discrete[1 : end ] .= cache. k_discrete
363- eval_bc_residual! (resids[1 ], pt, bc!, EvalSol, p, mesh)
365+ eval_bc_residual! (resids[L + 1 ], pt, bc!, EvalSol, p, mesh)
364366
365- # whole-time inequality constraints
366- cache. prob. f. inequality .(resids[(L + 1 ): end ], y_, nothing )
367367 recursive_flatten! (resid, resids)
368368 return nothing
369369end
@@ -497,7 +497,7 @@ function __construct_problem(cache::MIRKCache{iip}, y, loss_bc::BC, loss_colloca
497497 cache. prob. f. inequality, resid_prototype, bc_diffmode, y, Constant (cache. p))
498498 J_inequality = DI. jacobian (cache. prob. f. inequality, resid_prototype,
499499 cache_inequality, bc_diffmode, y, Constant (cache. p))
500- jac_prototype = vcat (jac_prototype, J_inequality )
500+ jac_prototype = vcat (J_inequality, jac_prototype )
501501 end
502502
503503 jac = if iip
@@ -554,14 +554,13 @@ function __mirk_mpoint_jacobian!(
554554 inequality_diffcache, loss_bc:: BC , loss_collocation:: C , loss_inequality,
555555 resid_bc, resid_collocation, resid_prototype, L:: Int , p) where {BC, C}
556556 N = length (x)
557- DI. jacobian! (
558- loss_bc, resid_bc, @view (J[1 : L, :]), bc_diffcache, bc_diffmode, x, Constant (p))
559- DI. jacobian! (loss_collocation, resid_collocation, @view (J[(L + 1 ): N, :]),
560- nonbc_diffcache, nonbc_diffmode, x, Constant (p))
561-
562557 # The Jacobian of constraints
563- DI. jacobian! (loss_inequality, resid_prototype, @view (J[(N + 1 ) : end , :]),
558+ DI. jacobian! (loss_inequality, resid_prototype, @view (J[1 : N , :]),
564559 inequality_diffcache, bc_diffmode, x, Constant (p))
560+ DI. jacobian! (loss_bc, resid_bc, @view (J[(N + 1 ): (N + L), :]),
561+ bc_diffcache, bc_diffmode, x, Constant (p))
562+ DI. jacobian! (loss_collocation, resid_collocation, @view (J[(N + L + 1 ): 2 N, :]),
563+ nonbc_diffcache, nonbc_diffmode, x, Constant (p))
565564 return nothing
566565end
567566
0 commit comments