From 79ac0fb14820479b67cb332eddefdd48c1d37f03 Mon Sep 17 00:00:00 2001 From: Chris Rackauckas Date: Thu, 24 Nov 2022 03:15:59 +0100 Subject: [PATCH] format --- docs/src/index.md | 7 +++---- src/jacobian.jl | 3 ++- src/raphson.jl | 37 ++++++++++++++++++++----------------- src/utils.jl | 5 ++--- test/basictests.jl | 2 +- 5 files changed, 28 insertions(+), 26 deletions(-) diff --git a/docs/src/index.md b/docs/src/index.md index eea1a76f8..35419a3c2 100644 --- a/docs/src/index.md +++ b/docs/src/index.md @@ -12,8 +12,7 @@ allow for automatically generating high-performance code. Performance is key: the current methods are made to be highly performant on scalar and statically sized small problems, with options for large-scale systems. -If you run into any performance issues, please file an issue. Note that this -package is distinct from [SciMLNLSolve.jl](https://github.com/SciML/SciMLNLSolve.jl). +If you run into any performance issues, please file an issue. Consult the [NonlinearSystemSolvers](@ref nonlinearsystemsolvers) page for information on how to import solvers from different packages. @@ -79,7 +78,7 @@ Pkg.status(;mode = PKGMODE_MANIFEST) # hide ``` ```@raw html -You can also download the +You can also download the project file. -``` \ No newline at end of file +``` diff --git a/src/jacobian.jl b/src/jacobian.jl index 1c356c65c..96c07ada9 100644 --- a/src/jacobian.jl +++ b/src/jacobian.jl @@ -32,7 +32,8 @@ function jacobian(f, x::Number, solver) if alg_autodiff(solver.alg) J = ForwardDiff.derivative(f, x) else - J = FiniteDiff.finite_difference_derivative(f, x, alg_difftype(solver.alg), eltype(x)) + J = FiniteDiff.finite_difference_derivative(f, x, alg_difftype(solver.alg), + eltype(x)) end return J end diff --git a/src/raphson.jl b/src/raphson.jl index c5742e0f3..b1362596d 100644 --- a/src/raphson.jl +++ b/src/raphson.jl @@ -12,7 +12,8 @@ function NewtonRaphson(; chunk_size = Val{0}(), autodiff = Val{true}(), _unwrap_val(concrete_jac)}(linsolve, precs) end -mutable struct NewtonRaphsonCache{iip, fType, algType, uType, duType, resType, pType, INType, tolType, +mutable struct NewtonRaphsonCache{iip, fType, algType, uType, duType, resType, pType, + INType, tolType, probType, ufType, L, jType, JC} f::fType alg::algType @@ -32,22 +33,25 @@ mutable struct NewtonRaphsonCache{iip, fType, algType, uType, duType, resType, p abstol::tolType prob::probType - function NewtonRaphsonCache{iip}(f::fType, alg::algType, u::uType, fu::resType, p::pType, - uf::ufType, linsolve::L, J::jType, du1::duType, jac_config::JC, iter::Int, - force_stop::Bool, maxiters::Int, internalnorm::INType, - retcode::SciMLBase.ReturnCode.T, abstol::tolType, prob::probType) where { - iip, fType, algType, uType, duType, resType, pType, INType, tolType, - probType, ufType, L, jType, JC} + function NewtonRaphsonCache{iip}(f::fType, alg::algType, u::uType, fu::resType, + p::pType, + uf::ufType, linsolve::L, J::jType, du1::duType, + jac_config::JC, iter::Int, + force_stop::Bool, maxiters::Int, internalnorm::INType, + retcode::SciMLBase.ReturnCode.T, abstol::tolType, + prob::probType) where { + iip, fType, algType, uType, + duType, resType, pType, INType, + tolType, + probType, ufType, L, jType, JC} new{iip, fType, algType, uType, duType, resType, pType, INType, tolType, - probType, ufType, L, jType, JC}(f, alg, u, fu, p, - uf, linsolve, J, du1, jac_config, iter, - force_stop, maxiters, internalnorm, - retcode, abstol, prob) + probType, ufType, L, jType, JC}(f, alg, u, fu, p, + uf, linsolve, J, du1, jac_config, iter, + force_stop, maxiters, internalnorm, + retcode, abstol, prob) end - end - function jacobian_caches(alg::NewtonRaphson, f, u, p, ::Val{true}) uf = JacobianWrapper(f, p) J = false .* u .* u' @@ -105,8 +109,8 @@ function SciMLBase.__init(prob::NonlinearProblem{uType, iip}, alg::NewtonRaphson uf, linsolve, J, du1, jac_config = jacobian_caches(alg, f, u, p, Val(iip)) return NewtonRaphsonCache{iip}(f, alg, u, fu, p, uf, linsolve, J, du1, jac_config, - 1, false, maxiters, internalnorm, - ReturnCode.Default, abstol, prob) + 1, false, maxiters, internalnorm, + ReturnCode.Default, abstol, prob) end function perform_step!(cache::NewtonRaphsonCache{true}) @@ -139,7 +143,6 @@ function perform_step!(cache::NewtonRaphsonCache{false}) end function SciMLBase.solve!(cache::NewtonRaphsonCache) - while !cache.force_stop && cache.iter < cache.maxiters perform_step!(cache) cache.iter += 1 @@ -150,5 +153,5 @@ function SciMLBase.solve!(cache::NewtonRaphsonCache) end SciMLBase.build_solution(cache.prob, cache.alg, cache.u, cache.fu; - retcode = cache.retcode) + retcode = cache.retcode) end diff --git a/src/utils.jl b/src/utils.jl index e09ce7a52..318ca01f9 100644 --- a/src/utils.jl +++ b/src/utils.jl @@ -159,9 +159,8 @@ _vec(v) = vec(v) _vec(v::Number) = v _vec(v::AbstractVector) = v - -function alg_difftype(alg::AbstractNewtonAlgorithm{CS, AD, FDT, ST, CJ} - ) where {CS, AD, FDT, ST, CJ} +function alg_difftype(alg::AbstractNewtonAlgorithm{CS, AD, FDT, ST, CJ}) where {CS, AD, FDT, + ST, CJ} FDT end diff --git a/test/basictests.jl b/test/basictests.jl index 72e3a1967..f89ba0ba2 100644 --- a/test/basictests.jl +++ b/test/basictests.jl @@ -66,7 +66,7 @@ f, u0 = (u, p) -> u * u - p, 1.0 # NewtonRaphson g = function (p) probN = NonlinearProblem{false}(f, oftype(p, u0), p) - sol = solve(probN, NewtonRaphson(), abstol=1e-10) + sol = solve(probN, NewtonRaphson(), abstol = 1e-10) return sol.u end