Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add SciML.build_solution #28

Merged
merged 9 commits into from
Feb 3, 2021
10 changes: 2 additions & 8 deletions src/solve.jl
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,8 @@ function SciMLBase.solve(prob::NonlinearProblem,
alg::AbstractNonlinearSolveAlgorithm, args...;
kwargs...)
solver = init(prob, alg, args...; kwargs...)
sol = solve!(solver)
sol, resid = solve!(solver)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

solve! has a standard interface that shouldn't be broken. We should just stick the resid in the sol.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Okay, I will update the sol struct with resid.

if typeof(sol) <: NewtonSolution
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is this branching needed? It makes the solution type unstable and break non-Newton solvers. We can just assume that sol.u exists.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There are two types of solver, Newton solver and Bracketing methods, which outputs sol.left and sol.right. That's why I wanted to ask how to pass bracketing methods to build_solution?

resid = zero(prob.u0)
if isinplace(prob)
prob.f(resid,sol.u,prob.p)
else
resid = prob.f(sol.u,prob.p)
end
return SciMLBase.build_solution(prob, alg, sol.u, resid;retcode=:Success)
end
end
Expand Down Expand Up @@ -76,7 +70,7 @@ function SciMLBase.solve!(solver::AbstractImmutableNonlinearSolver)
@set! solver.retcode = MAXITERS_EXCEED
end
sol = get_solution(solver)
return sol
return sol, solver.fu
end

"""
Expand Down