-
-
Notifications
You must be signed in to change notification settings - Fork 48
/
Copy pathNonlinearSolveSpeedMappingExt.jl
41 lines (33 loc) · 1.41 KB
/
NonlinearSolveSpeedMappingExt.jl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
module NonlinearSolveSpeedMappingExt
using SpeedMapping: speedmapping
using NonlinearSolveBase: NonlinearSolveBase
using NonlinearSolve: NonlinearSolve, SpeedMappingJL
using SciMLBase: SciMLBase, NonlinearProblem, ReturnCode
function SciMLBase.__solve(
prob::NonlinearProblem, alg::SpeedMappingJL, args...;
abstol = nothing, maxiters = 1000, alias_u0::Bool = false,
maxtime = nothing, store_trace::Val = Val(false),
termination_condition = nothing, kwargs...
)
NonlinearSolveBase.assert_extension_supported_termination_condition(
termination_condition, alg
)
m!, u, resid = NonlinearSolveBase.construct_extension_function_wrapper(
prob; alias_u0, make_fixed_point = Val(true)
)
tol = NonlinearSolveBase.get_tolerance(abstol, eltype(u))
time_limit = ifelse(maxtime === nothing, 1000, maxtime)
sol = speedmapping(
u; m!, tol, Lp = Inf, maps_limit = maxiters, alg.orders,
alg.check_obj, store_info = store_trace isa Val{true}, alg.σ_min, alg.stabilize,
time_limit
)
res = prob.u0 isa Number ? first(sol.minimizer) : sol.minimizer
resid = NonlinearSolveBase.Utils.evaluate_f(prob, res)
return SciMLBase.build_solution(
prob, alg, res, resid;
original = sol, stats = SciMLBase.NLStats(sol.maps, 0, 0, 0, sol.maps),
retcode = ifelse(sol.converged, ReturnCode.Success, ReturnCode.Failure)
)
end
end