diff --git a/lib/BoundaryValueDiffEqAscher/src/BoundaryValueDiffEqAscher.jl b/lib/BoundaryValueDiffEqAscher/src/BoundaryValueDiffEqAscher.jl index 1ef8cbca..11a97276 100644 --- a/lib/BoundaryValueDiffEqAscher/src/BoundaryValueDiffEqAscher.jl +++ b/lib/BoundaryValueDiffEqAscher/src/BoundaryValueDiffEqAscher.jl @@ -7,7 +7,8 @@ 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, __get_bcresid_prototype + __extract_mesh, get_dense_ad, __get_bcresid_prototype, + __split_kwargs using ConcreteStructs: @concrete using DiffEqBase: DiffEqBase using DifferentiationInterface: DifferentiationInterface, Constant, prepare_jacobian diff --git a/lib/BoundaryValueDiffEqAscher/src/ascher.jl b/lib/BoundaryValueDiffEqAscher/src/ascher.jl index 150bc8aa..79891e9f 100644 --- a/lib/BoundaryValueDiffEqAscher/src/ascher.jl +++ b/lib/BoundaryValueDiffEqAscher/src/ascher.jl @@ -58,7 +58,7 @@ function get_fixed_points(prob::BVProblem, alg::AbstractAscher) end function SciMLBase.__init(prob::BVProblem, alg::AbstractAscher; dt = 0.0, - adaptive = true, abstol = 1e-4, kwargs...) + adaptive = true, abstol = 1e-4, verbose = true, kwargs...) (; tspan, p) = prob _, T, ncy, n, u0 = __extract_problem_details(prob; dt, check_positive_dt = true) t₀, t₁ = tspan @@ -145,27 +145,24 @@ function SciMLBase.__init(prob::BVProblem, alg::AbstractAscher; dt = 0.0, cache = AscherCache{iip, T}( prob, f, jac, bc, bcjac, k, copy(mesh), mesh, mesh_dt, ncomp, ny, p, zeta, fixpnt, alg, prob.problem_type, bcresid_prototype, residual, - zval, yval, gval, err, g, w, v, lz, ly, dmz, delz, deldmz, dqdmz, - dmv, pvtg, pvtw, TU, valst, (; abstol, dt, adaptive, kwargs...)) + zval, yval, gval, err, g, w, v, lz, ly, dmz, delz, deldmz, dqdmz, dmv, + pvtg, pvtw, TU, valst, (; abstol, dt, adaptive, verbose, kwargs...)) return cache end -function __split_ascher_kwargs(; abstol, dt, adaptive = true, kwargs...) - return ((abstol, adaptive, dt), (; abstol, adaptive, kwargs...)) -end - function SciMLBase.solve!(cache::AscherCache{iip, T}) where {iip, T} - (abstol, adaptive, _), kwargs = __split_ascher_kwargs(; cache.kwargs...) + (abstol, adaptive, verbose, _), kwargs = __split_kwargs(; cache.kwargs...) info::ReturnCode.T = ReturnCode.Success # We do the first iteration outside the loop to preserve type-stability of the # `original` field of the solution - z, y, info, error_norm = __perform_ascher_iteration(cache, abstol, adaptive; kwargs...) + z, y, info, error_norm = __perform_ascher_iteration( + cache, abstol, adaptive, verbose; kwargs...) if adaptive while SciMLBase.successful_retcode(info) && norm(error_norm) > abstol z, y, info, error_norm = __perform_ascher_iteration( - cache, abstol, adaptive; kwargs...) + cache, abstol, adaptive, verbose; kwargs...) end end u = [vcat(zᵢ, yᵢ) for (zᵢ, yᵢ) in zip(z, y)] @@ -174,12 +171,13 @@ function SciMLBase.solve!(cache::AscherCache{iip, T}) where {iip, T} cache.prob, cache.alg, cache.original_mesh, u; retcode = info) end -function __perform_ascher_iteration(cache::AscherCache{iip, T}, abstol, adaptive::Bool; - nlsolve_kwargs = (;), kwargs...) where {iip, T} +function __perform_ascher_iteration(cache::AscherCache{iip, T}, abstol, adaptive::Bool, + verbose::Bool; nlsolve_kwargs = (;), kwargs...) where {iip, T} info::ReturnCode.T = ReturnCode.Success nlprob = __construct_nlproblem(cache) nlsolve_alg = __concrete_nonlinearsolve_algorithm(nlprob, cache.alg.nlsolve) - nlsol = __solve(nlprob, nlsolve_alg; abstol, kwargs..., nlsolve_kwargs...) + nlsol = __solve(nlprob, nlsolve_alg; abstol = abstol, + verbose = verbose, kwargs..., nlsolve_kwargs...) error_norm = 2 * abstol info = nlsol.retcode @@ -207,16 +205,19 @@ function __perform_ascher_iteration(cache::AscherCache{iip, T}, abstol, adaptive __expand_cache_for_error!(cache) _nlprob = __construct_nlproblem(cache) - nlsol = __solve(_nlprob, nlsolve_alg; abstol, kwargs..., nlsolve_kwargs...) + nlsol = __solve(_nlprob, nlsolve_alg; abstol = abstol, + verbose = verbose, kwargs..., nlsolve_kwargs...) error_norm = error_estimate!(cache) if norm(error_norm) > abstol + verbose && @warn "Global error norm bigger than tolerance, refining mesh" mesh_selector!(cache, z, dmz, mesh, mesh_dt, abstol) __expand_cache_for_next_iter!(cache) end else # Something bad happened if 2 * (length(cache.mesh) - 1) > cache.alg.max_num_subintervals - # The solving process failed + # New mesh would be too large + verbose && @warn "Mesh being too large and still failing to solve, exiting" info = ReturnCode.Failure else # doesn't need to halve the mesh again, just use the expanded cache diff --git a/lib/BoundaryValueDiffEqCore/src/utils.jl b/lib/BoundaryValueDiffEqCore/src/utils.jl index c0e0665c..2b0a5709 100644 --- a/lib/BoundaryValueDiffEqCore/src/utils.jl +++ b/lib/BoundaryValueDiffEqCore/src/utils.jl @@ -489,3 +489,8 @@ function _sparse_like(I, J, x::AbstractArray, m = maximum(I), n = maximum(J)) V = __ones_like(x, length(I)) return sparse(I′, J′, V, m, n) end + +# Keywords processing +function __split_kwargs(; abstol, dt, adaptive = true, verbose = true, kwargs...) + return ((abstol, adaptive, verbose, dt), (; abstol, adaptive, verbose, kwargs...)) +end diff --git a/lib/BoundaryValueDiffEqFIRK/src/BoundaryValueDiffEqFIRK.jl b/lib/BoundaryValueDiffEqFIRK/src/BoundaryValueDiffEqFIRK.jl index dbd48aef..dc34634b 100644 --- a/lib/BoundaryValueDiffEqFIRK/src/BoundaryValueDiffEqFIRK.jl +++ b/lib/BoundaryValueDiffEqFIRK/src/BoundaryValueDiffEqFIRK.jl @@ -18,7 +18,8 @@ using BoundaryValueDiffEqCore: BoundaryValueDiffEqAlgorithm, BVPJacobianAlgorith MaybeDiffCache, __extract_mesh, __extract_u0, __has_initial_guess, __initial_guess_length, __initial_guess_on_mesh, __flatten_initial_guess, - __build_solution, __Fix3, _sparse_like, get_dense_ad + __build_solution, __Fix3, _sparse_like, get_dense_ad, + __split_kwargs using ConcreteStructs: @concrete using DiffEqBase: DiffEqBase diff --git a/lib/BoundaryValueDiffEqFIRK/src/adaptivity.jl b/lib/BoundaryValueDiffEqFIRK/src/adaptivity.jl index 014101c8..f150e03b 100644 --- a/lib/BoundaryValueDiffEqFIRK/src/adaptivity.jl +++ b/lib/BoundaryValueDiffEqFIRK/src/adaptivity.jl @@ -160,7 +160,7 @@ Generate new mesh based on the defect. @views function mesh_selector!(cache::Union{ FIRKCacheExpand{iip, T}, FIRKCacheNested{iip, T}}) where {iip, T} (; order, defect, mesh, mesh_dt) = cache - (abstol, _, _), kwargs = __split_mirk_kwargs(; cache.kwargs...) + (abstol, _, _, _), kwargs = __split_kwargs(; cache.kwargs...) N = length(mesh) safety_factor = T(1.3) diff --git a/lib/BoundaryValueDiffEqFIRK/src/firk.jl b/lib/BoundaryValueDiffEqFIRK/src/firk.jl index bb79a236..203b2a04 100644 --- a/lib/BoundaryValueDiffEqFIRK/src/firk.jl +++ b/lib/BoundaryValueDiffEqFIRK/src/firk.jl @@ -79,18 +79,18 @@ function shrink_y(y, N, stage) end function SciMLBase.__init(prob::BVProblem, alg::AbstractFIRK; dt = 0.0, - abstol = 1e-3, adaptive = true, kwargs...) + abstol = 1e-3, adaptive = true, verbose = true, kwargs...) if alg.nested_nlsolve - return init_nested( - prob, alg; dt = dt, abstol = abstol, adaptive = adaptive, kwargs...) + return init_nested(prob, alg; dt = dt, abstol = abstol, + adaptive = adaptive, verbose = verbose, kwargs...) else - return init_expanded( - prob, alg; dt = dt, abstol = abstol, adaptive = adaptive, kwargs...) + return init_expanded(prob, alg; dt = dt, abstol = abstol, + adaptive = adaptive, verbose = verbose, kwargs...) end end function init_nested(prob::BVProblem, alg::AbstractFIRK; dt = 0.0, - abstol = 1e-3, adaptive = true, kwargs...) + abstol = 1e-3, adaptive = true, verbose = true, kwargs...) @set! alg.jac_alg = concrete_jacobian_algorithm(alg.jac_alg, prob, alg) iip = isinplace(prob) @@ -177,13 +177,13 @@ function init_nested(prob::BVProblem, alg::AbstractFIRK; dt = 0.0, return FIRKCacheNested{iip, T}( alg_order(alg), stage, M, size(X), f, bc, prob_, prob.problem_type, - prob.p, alg, TU, ITU, bcresid_prototype, mesh, mesh_dt, - k_discrete, y, y₀, residual, fᵢ_cache, fᵢ₂_cache, defect, nestprob, - nest_tol, resid₁_size, (; abstol, dt, adaptive, kwargs...)) + prob.p, alg, TU, ITU, bcresid_prototype, mesh, mesh_dt, k_discrete, + y, y₀, residual, fᵢ_cache, fᵢ₂_cache, defect, nestprob, nest_tol, + resid₁_size, (; abstol, dt, adaptive, verbose, kwargs...)) end function init_expanded(prob::BVProblem, alg::AbstractFIRK; dt = 0.0, - abstol = 1e-3, adaptive = true, kwargs...) + abstol = 1e-3, adaptive = true, verbose = true, kwargs...) @set! alg.jac_alg = concrete_jacobian_algorithm(alg.jac_alg, prob, alg) if adaptive && isa(alg, FIRKNoAdaptivity) @@ -258,9 +258,9 @@ function init_expanded(prob::BVProblem, alg::AbstractFIRK; dt = 0.0, prob_ = !(prob.u0 isa AbstractArray) ? remake(prob; u0 = X) : prob return FIRKCacheExpand{iip, T}( - alg_order(alg), stage, M, size(X), f, bc, prob_, prob.problem_type, prob.p, - alg, TU, ITU, bcresid_prototype, mesh, mesh_dt, k_discrete, y, y₀, residual, - fᵢ_cache, fᵢ₂_cache, defect, resid₁_size, (; abstol, dt, adaptive, kwargs...)) + alg_order(alg), stage, M, size(X), f, bc, prob_, prob.problem_type, prob.p, alg, + TU, ITU, bcresid_prototype, mesh, mesh_dt, k_discrete, y, y₀, residual, fᵢ_cache, + fᵢ₂_cache, defect, resid₁_size, (; abstol, dt, adaptive, verbose, kwargs...)) end """ @@ -289,23 +289,19 @@ function __expand_cache!(cache::FIRKCacheNested) return cache end -function __split_mirk_kwargs(; abstol, dt, adaptive = true, kwargs...) - return ((abstol, adaptive, dt), (; abstol, adaptive, kwargs...)) -end - function SciMLBase.solve!(cache::FIRKCacheExpand) - (abstol, adaptive, _), kwargs = __split_mirk_kwargs(; cache.kwargs...) + (abstol, adaptive, verbose, _), kwargs = __split_kwargs(; cache.kwargs...) info::ReturnCode.T = ReturnCode.Success # We do the first iteration outside the loop to preserve type-stability of the # `original` field of the solution sol_nlprob, info, defect_norm = __perform_firk_iteration( - cache, abstol, adaptive; kwargs...) + cache, abstol, adaptive, verbose; kwargs...) if adaptive while SciMLBase.successful_retcode(info) && defect_norm > abstol sol_nlprob, info, defect_norm = __perform_firk_iteration( - cache, abstol, adaptive; kwargs...) + cache, abstol, adaptive, verbose; kwargs...) end end @@ -320,18 +316,18 @@ function SciMLBase.solve!(cache::FIRKCacheExpand) end function SciMLBase.solve!(cache::FIRKCacheNested) - (abstol, adaptive, _), kwargs = __split_mirk_kwargs(; cache.kwargs...) + (abstol, adaptive, verbose, _), kwargs = __split_kwargs(; cache.kwargs...) info::ReturnCode.T = ReturnCode.Success # We do the first iteration outside the loop to preserve type-stability of the # `original` field of the solution sol_nlprob, info, defect_norm = __perform_firk_iteration( - cache, abstol, adaptive; kwargs...) + cache, abstol, adaptive, verbose; kwargs...) if adaptive while SciMLBase.successful_retcode(info) && defect_norm > abstol sol_nlprob, info, defect_norm = __perform_firk_iteration( - cache, abstol, adaptive; kwargs...) + cache, abstol, adaptive, verbose; kwargs...) end end @@ -345,11 +341,11 @@ function SciMLBase.solve!(cache::FIRKCacheNested) end function __perform_firk_iteration(cache::Union{FIRKCacheExpand, FIRKCacheNested}, abstol, - adaptive::Bool; nlsolve_kwargs = (;), kwargs...) + adaptive::Bool, verbose::Bool; nlsolve_kwargs = (;), kwargs...) nlprob = __construct_nlproblem(cache, vec(cache.y₀), copy(cache.y₀)) nlsolve_alg = __concrete_nonlinearsolve_algorithm(nlprob, cache.alg.nlsolve) - sol_nlprob = __solve( - nlprob, nlsolve_alg; abstol, kwargs..., nlsolve_kwargs..., alias_u0 = true) + sol_nlprob = __solve(nlprob, nlsolve_alg; abstol = abstol, verbose = verbose, + kwargs..., nlsolve_kwargs..., alias_u0 = true) recursive_unflatten!(cache.y₀, sol_nlprob.u) defect_norm = 2 * abstol @@ -362,11 +358,16 @@ function __perform_firk_iteration(cache::Union{FIRKCacheExpand, FIRKCacheNested} if info == ReturnCode.Success # Nonlinear Solve was successful defect_norm = defect_estimate!(cache) # The defect is greater than 10%, the solution is not acceptable - defect_norm > cache.alg.defect_threshold && (info = ReturnCode.Failure) + if defect_norm > cache.alg.defect_threshold + verbose && + @warn "Defect norm is $defect_norm, bigger than threshold $(cache.alg.defect_threshold), halving mesh" + info = ReturnCode.Failure + end end if info == ReturnCode.Success # Nonlinear Solve Successful and defect norm is acceptable if defect_norm > abstol + verbose && @warn "Defect norm bigger than tolerance, refining mesh" # We construct a new mesh to equidistribute the defect mesh, mesh_dt, _, info = mesh_selector!(cache) if info == ReturnCode.Success @@ -381,6 +382,7 @@ function __perform_firk_iteration(cache::Union{FIRKCacheExpand, FIRKCacheNested} # We cannot obtain a solution for the current mesh if 2 * (length(cache.mesh) - 1) > cache.alg.max_num_subintervals # New mesh would be too large + verbose && @warn "Mesh being too large and still failing to solve, exiting" info = ReturnCode.Failure else half_mesh!(cache) diff --git a/lib/BoundaryValueDiffEqMIRK/src/BoundaryValueDiffEqMIRK.jl b/lib/BoundaryValueDiffEqMIRK/src/BoundaryValueDiffEqMIRK.jl index 38a2f11a..654cc255 100644 --- a/lib/BoundaryValueDiffEqMIRK/src/BoundaryValueDiffEqMIRK.jl +++ b/lib/BoundaryValueDiffEqMIRK/src/BoundaryValueDiffEqMIRK.jl @@ -18,7 +18,7 @@ using BoundaryValueDiffEqCore: BoundaryValueDiffEqAlgorithm, BVPJacobianAlgorith __extract_mesh, __extract_u0, __has_initial_guess, __initial_guess_length, __initial_guess_on_mesh, __flatten_initial_guess, __build_solution, __Fix3, - get_dense_ad + get_dense_ad, __split_kwargs using ConcreteStructs: @concrete using DiffEqBase: DiffEqBase diff --git a/lib/BoundaryValueDiffEqMIRK/src/adaptivity.jl b/lib/BoundaryValueDiffEqMIRK/src/adaptivity.jl index b5b2accf..be5d0342 100644 --- a/lib/BoundaryValueDiffEqMIRK/src/adaptivity.jl +++ b/lib/BoundaryValueDiffEqMIRK/src/adaptivity.jl @@ -28,7 +28,7 @@ Generate new mesh based on the defect. """ @views function mesh_selector!(cache::MIRKCache{iip, T}) where {iip, T} (; order, defect, mesh, mesh_dt) = cache - (abstol, _, _), kwargs = __split_mirk_kwargs(; cache.kwargs...) + (abstol, _, _, _), kwargs = __split_kwargs(; cache.kwargs...) N = length(mesh) safety_factor = T(1.3) diff --git a/lib/BoundaryValueDiffEqMIRK/src/mirk.jl b/lib/BoundaryValueDiffEqMIRK/src/mirk.jl index 73966fbf..0f0bf744 100644 --- a/lib/BoundaryValueDiffEqMIRK/src/mirk.jl +++ b/lib/BoundaryValueDiffEqMIRK/src/mirk.jl @@ -32,7 +32,7 @@ end Base.eltype(::MIRKCache{iip, T}) where {iip, T} = T function SciMLBase.__init(prob::BVProblem, alg::AbstractMIRK; dt = 0.0, - abstol = 1e-3, adaptive = true, kwargs...) + abstol = 1e-3, adaptive = true, verbose = true, kwargs...) @set! alg.jac_alg = concrete_jacobian_algorithm(alg.jac_alg, prob, alg) iip = isinplace(prob) @@ -104,9 +104,9 @@ function SciMLBase.__init(prob::BVProblem, alg::AbstractMIRK; dt = 0.0, return MIRKCache{iip, T}( alg_order(alg), stage, N, size(X), f, bc, prob_, prob.problem_type, - prob.p, alg, TU, ITU, bcresid_prototype, mesh, mesh_dt, - k_discrete, k_interp, y, y₀, residual, fᵢ_cache, fᵢ₂_cache, defect, - new_stages, resid₁_size, (; abstol, dt, adaptive, kwargs...)) + prob.p, alg, TU, ITU, bcresid_prototype, mesh, mesh_dt, k_discrete, + k_interp, y, y₀, residual, fᵢ_cache, fᵢ₂_cache, defect, new_stages, + resid₁_size, (; abstol, dt, adaptive, verbose, kwargs...)) end """ @@ -127,23 +127,19 @@ function __expand_cache!(cache::MIRKCache) return cache end -function __split_mirk_kwargs(; abstol, dt, adaptive = true, kwargs...) - return ((abstol, adaptive, dt), (; abstol, adaptive, kwargs...)) -end - function SciMLBase.solve!(cache::MIRKCache) - (abstol, adaptive, _), kwargs = __split_mirk_kwargs(; cache.kwargs...) + (abstol, adaptive, verbose, _), kwargs = __split_kwargs(; cache.kwargs...) info::ReturnCode.T = ReturnCode.Success # We do the first iteration outside the loop to preserve type-stability of the # `original` field of the solution sol_nlprob, info, defect_norm = __perform_mirk_iteration( - cache, abstol, adaptive; kwargs...) + cache, abstol, adaptive, verbose; kwargs...) if adaptive while SciMLBase.successful_retcode(info) && defect_norm > abstol sol_nlprob, info, defect_norm = __perform_mirk_iteration( - cache, abstol, adaptive; kwargs...) + cache, abstol, adaptive, verbose; kwargs...) end end @@ -156,12 +152,12 @@ function SciMLBase.solve!(cache::MIRKCache) return __build_solution(cache.prob, odesol, sol_nlprob) end -function __perform_mirk_iteration( - cache::MIRKCache, abstol, adaptive::Bool; nlsolve_kwargs = (;), kwargs...) +function __perform_mirk_iteration(cache::MIRKCache, abstol, adaptive::Bool, + verbose::Bool; nlsolve_kwargs = (;), kwargs...) nlprob = __construct_nlproblem(cache, vec(cache.y₀), copy(cache.y₀)) nlsolve_alg = __concrete_nonlinearsolve_algorithm(nlprob, cache.alg.nlsolve) - sol_nlprob = __solve( - nlprob, nlsolve_alg; abstol, kwargs..., nlsolve_kwargs..., alias_u0 = true) + sol_nlprob = __solve(nlprob, nlsolve_alg; abstol = abstol, verbose = verbose, + kwargs..., nlsolve_kwargs..., alias_u0 = true) recursive_unflatten!(cache.y₀, sol_nlprob.u) defect_norm = 2 * abstol @@ -174,11 +170,16 @@ function __perform_mirk_iteration( if info == ReturnCode.Success # Nonlinear Solve was successful defect_norm = defect_estimate!(cache) # The defect is greater than 10%, the solution is not acceptable - defect_norm > cache.alg.defect_threshold && (info = ReturnCode.Failure) + if defect_norm > cache.alg.defect_threshold + verbose && + @warn "Defect norm is $defect_norm, bigger than threshold $(cache.alg.defect_threshold), halving mesh" + info = ReturnCode.Failure + end end if info == ReturnCode.Success # Nonlinear Solve Successful and defect norm is acceptable if defect_norm > abstol + verbose && @warn "Defect norm bigger than tolerance, refining mesh" # We construct a new mesh to equidistribute the defect mesh, mesh_dt, _, info = mesh_selector!(cache) if info == ReturnCode.Success @@ -193,6 +194,7 @@ function __perform_mirk_iteration( # We cannot obtain a solution for the current mesh if 2 * (length(cache.mesh) - 1) > cache.alg.max_num_subintervals # New mesh would be too large + verbose && @warn "Mesh being too large and still failing to solve, exiting" info = ReturnCode.Failure else half_mesh!(cache) diff --git a/lib/BoundaryValueDiffEqMIRKN/src/BoundaryValueDiffEqMIRKN.jl b/lib/BoundaryValueDiffEqMIRKN/src/BoundaryValueDiffEqMIRKN.jl index 9b544382..7bf1f98e 100644 --- a/lib/BoundaryValueDiffEqMIRKN/src/BoundaryValueDiffEqMIRKN.jl +++ b/lib/BoundaryValueDiffEqMIRKN/src/BoundaryValueDiffEqMIRKN.jl @@ -19,7 +19,7 @@ using BoundaryValueDiffEqCore: BoundaryValueDiffEqAlgorithm, BVPJacobianAlgorith __initial_guess_on_mesh, __flatten_initial_guess, __build_solution, __Fix3, __default_sparse_ad, __default_nonsparse_ad, get_dense_ad, - concrete_jacobian_algorithm + concrete_jacobian_algorithm, __split_kwargs using ConcreteStructs: @concrete using DiffEqBase: DiffEqBase diff --git a/lib/BoundaryValueDiffEqMIRKN/src/mirkn.jl b/lib/BoundaryValueDiffEqMIRKN/src/mirkn.jl index b02d5411..e3ac3a92 100644 --- a/lib/BoundaryValueDiffEqMIRKN/src/mirkn.jl +++ b/lib/BoundaryValueDiffEqMIRKN/src/mirkn.jl @@ -25,8 +25,8 @@ end Base.eltype(::MIRKNCache{iip, T}) where {iip, T} = T -function SciMLBase.__init(prob::SecondOrderBVProblem, alg::AbstractMIRKN; - dt = 0.0, adaptive = false, kwargs...) +function SciMLBase.__init(prob::SecondOrderBVProblem, alg::AbstractMIRKN; dt = 0.0, + abstol = 1e-4, adaptive = false, verbose = true, kwargs...) @set! alg.jac_alg = concrete_jacobian_algorithm(alg.jac_alg, prob, alg) iip = isinplace(prob) t₀, t₁ = prob.tspan @@ -85,19 +85,16 @@ function SciMLBase.__init(prob::SecondOrderBVProblem, alg::AbstractMIRKN; prob_ = !(prob.u0 isa AbstractArray) ? remake(prob; u0 = X) : prob return MIRKNCache{iip, T}( - alg_order(alg), stage, M, size(X), f, bc, prob_, prob.problem_type, - prob.p, alg, TU, bcresid_prototype, mesh, mesh_dt, k_discrete, y, - y₀, residual, fᵢ_cache, fᵢ₂_cache, resid_size, (; dt, kwargs...)) + alg_order(alg), stage, M, size(X), f, bc, prob_, prob.problem_type, prob.p, + alg, TU, bcresid_prototype, mesh, mesh_dt, k_discrete, y, y₀, residual, + fᵢ_cache, fᵢ₂_cache, resid_size, (; abstol, adaptive, dt, verbose, kwargs...)) end -function __split_mirkn_kwargs(; dt, kwargs...) - return ((dt), (; kwargs...)) -end function SciMLBase.solve!(cache::MIRKNCache{iip, T}) where {iip, T} - (_), kwargs = __split_mirkn_kwargs(; cache.kwargs...) + (abstol, _, verbose, _), kwargs = __split_kwargs(; cache.kwargs...) info::ReturnCode.T = ReturnCode.Success - sol_nlprob, info = __perform_mirkn_iteration(cache; kwargs...) + sol_nlprob, info = __perform_mirkn_iteration(cache, abstol, verbose; kwargs...) solu = ArrayPartition.( cache.y₀.u[1:length(cache.mesh)], cache.y₀.u[(length(cache.mesh) + 1):end]) @@ -106,10 +103,12 @@ function SciMLBase.solve!(cache::MIRKNCache{iip, T}) where {iip, T} return __build_solution(cache.prob, odesol, sol_nlprob) end -function __perform_mirkn_iteration(cache::MIRKNCache; nlsolve_kwargs = (;), kwargs...) +function __perform_mirkn_iteration( + cache::MIRKNCache, abstol, verbose; nlsolve_kwargs = (;), kwargs...) nlprob::NonlinearProblem = __construct_nlproblem(cache, vec(cache.y₀)) nlsolve_alg = __concrete_nonlinearsolve_algorithm(nlprob, cache.alg.nlsolve) - sol_nlprob = __solve(nlprob, nlsolve_alg; kwargs..., nlsolve_kwargs..., alias_u0 = true) + sol_nlprob = __solve(nlprob, nlsolve_alg; abstol = abstol, verbose = verbose, + kwargs..., nlsolve_kwargs..., alias_u0 = true) recursive_unflatten!(cache.y₀, sol_nlprob.u) return sol_nlprob, sol_nlprob.retcode