2121 fᵢ₂_cache
2222 resid_size
2323 nlsolve_kwargs
24+ optimize_kwargs
2425 kwargs
2526end
2627
2728Base. eltype (:: MIRKNCache{iip, T} ) where {iip, T} = T
2829
29- function SciMLBase. __init (prob:: SecondOrderBVProblem , alg:: AbstractMIRKN ; dt = 0.0 ,
30- adaptive = false , abstol = 1e-6 , controller = NoErrorControl (),
31- nlsolve_kwargs = (; abstol = abstol), kwargs... )
30+ function SciMLBase. __init (prob:: SecondOrderBVProblem , alg:: AbstractMIRKN ;
31+ dt = 0.0 , adaptive = false , abstol = 1e-6 ,
32+ controller = NoErrorControl (), nlsolve_kwargs = (; abstol = abstol),
33+ optimize_kwargs = (; abstol = abstol), kwargs... )
3234 @set! alg. jac_alg = concrete_jacobian_algorithm (alg. jac_alg, prob, alg)
3335 iip = isinplace (prob)
36+ @assert (iip || isnothing (alg. optimize)) " Out-of-place constraints don't allow optimization solvers "
3437 t₀, t₁ = prob. tspan
3538 ig, T, M, Nig, X = __extract_problem_details (prob; dt, check_positive_dt = true )
3639 mesh = __extract_mesh (prob. u0, t₀, t₁, Nig)
@@ -93,9 +96,10 @@ function SciMLBase.__init(prob::SecondOrderBVProblem, alg::AbstractMIRKN; dt = 0
9396 prob_ = ! (prob. u0 isa AbstractArray) ? remake (prob; u0 = X) : prob
9497
9598 return MIRKNCache {iip, T} (
96- alg_order (alg), stage, M, size (X), f, bc, prob_, prob. problem_type, prob. p, alg, TU,
97- bcresid_prototype, mesh, mesh_dt, k_discrete, y, y₀, residual, fᵢ_cache, fᵢ₂_cache,
98- resid_size, nlsolve_kwargs, (; abstol, dt, adaptive, controller, kwargs... ))
99+ alg_order (alg), stage, M, size (X), f, bc, prob_, prob. problem_type,
100+ prob. p, alg, TU, bcresid_prototype, mesh, mesh_dt, k_discrete,
101+ y, y₀, residual, fᵢ_cache, fᵢ₂_cache, resid_size, nlsolve_kwargs,
102+ optimize_kwargs, (; abstol, dt, adaptive, controller, kwargs... ))
99103end
100104
101105function SciMLBase. solve! (cache:: MIRKNCache{iip, T} ) where {iip, T}
@@ -112,9 +116,11 @@ function SciMLBase.solve!(cache::MIRKNCache{iip, T}) where {iip, T}
112116end
113117
114118function __perform_mirkn_iteration (cache:: MIRKNCache )
115- nlprob:: NonlinearProblem = __construct_nlproblem (cache, vec (cache. y₀), copy (cache. y₀))
116- nlsolve_alg = __concrete_solve_algorithm (nlprob, cache. alg. nlsolve)
117- sol_nlprob = __solve (nlprob, nlsolve_alg; cache. nlsolve_kwargs... , alias_u0 = true )
119+ nlprob = __construct_nlproblem (cache, vec (cache. y₀), copy (cache. y₀))
120+ solve_alg = __concrete_solve_algorithm (nlprob, cache. alg. nlsolve, cache. alg. optimize)
121+ kwargs = __concrete_kwargs (
122+ cache. alg. nlsolve, cache. alg. optimize, cache. nlsolve_kwargs, cache. optimize_kwargs)
123+ sol_nlprob = solve (nlprob, solve_alg, kwargs... )
118124 recursive_unflatten! (cache. y₀, sol_nlprob. u)
119125
120126 return sol_nlprob, sol_nlprob. retcode
@@ -227,9 +233,8 @@ function __construct_nlproblem(cache::MIRKNCache{iip}, y, loss_bc::BC, loss_coll
227233 cache_collocation, loss_bc, loss_collocation, L, cache. p)
228234 end
229235 resid_prototype = vcat (resid_bc, resid_collocation)
230- nlf = NonlinearFunction {iip} (
231- loss; jac = jac, resid_prototype = resid_prototype, jac_prototype = jac_prototype)
232- __internal_nlsolve_problem (cache. prob, resid_prototype, y, nlf, y, cache. p)
236+ return __construct_internal_problem (cache. prob, cache. alg, loss, jac, jac_prototype,
237+ resid_prototype, y, cache. p, cache. M, 2 * N)
233238end
234239
235240function __construct_nlproblem (cache:: MIRKNCache{iip} , y, loss_bc:: BC , loss_collocation:: C ,
@@ -270,9 +275,8 @@ function __construct_nlproblem(cache::MIRKNCache{iip}, y, loss_bc::BC, loss_coll
270275 end
271276
272277 resid_prototype = copy (resid)
273- nlf = NonlinearFunction {iip} (
274- loss; jac = jac, resid_prototype = resid_prototype, jac_prototype = jac_prototype)
275- return __internal_nlsolve_problem (cache. prob, resid_prototype, y, nlf, y, cache. p)
278+ return __construct_internal_problem (cache. prob, cache. alg, loss, jac, jac_prototype,
279+ resid_prototype, y, cache. p, cache. M, 2 * N)
276280end
277281
278282function __mirkn_2point_jacobian! (J, x, diffmode, diffcache, loss_fn:: L , resid, p) where {L}
0 commit comments