Skip to content
This repository was archived by the owner on May 15, 2025. It is now read-only.

Add Broyden solver #14

Merged
merged 7 commits into from
Jan 2, 2023
Merged

Add Broyden solver #14

merged 7 commits into from
Jan 2, 2023

Conversation

Deltadahl
Copy link
Contributor

@Deltadahl Deltadahl commented Jan 2, 2023

Adding a Broyden solver.
I've tried to look at the "raphson.jl" implementation and made "broyden.jl" similar.
The algorithm used can be found https://en.wikipedia.org/wiki/Broyden%27s_method.

This is my first open-source PR, so feel free to give any feedback so I can change this implementation, but more importantly, so I learn for future PRs to SciML.

@codecov
Copy link

codecov bot commented Jan 2, 2023

Codecov Report

Merging #14 (aca04ad) into main (92b2eb2) will decrease coverage by 2.47%.
The diff coverage is 92.59%.

@@            Coverage Diff             @@
##             main      #14      +/-   ##
==========================================
- Coverage   91.30%   88.82%   -2.48%     
==========================================
  Files           6        7       +1     
  Lines         161      188      +27     
==========================================
+ Hits          147      167      +20     
- Misses         14       21       +7     
Impacted Files Coverage Δ
src/SimpleNonlinearSolve.jl 0.00% <ø> (ø)
src/broyden.jl 92.59% <92.59%> (ø)
src/falsi.jl 84.09% <0.00%> (-11.37%) ⬇️

📣 We’re building smart automated test selection to slash your CI/CD build times. Learn more

src/broyden.jl Outdated
fₙ = f(x)
T = eltype(x)
if length(x) > 1
J⁻¹ = Matrix{T}(I, length(x), length(x))
Copy link
Member

Choose a reason for hiding this comment

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

oh just here?

src/broyden.jl Outdated
Comment on lines 6 to 20
A low-overhead implementation of Broyden. This method is non-allocating on scalar
and static array problems.
"""
struct Broyden <: AbstractSimpleNonlinearSolveAlgorithm end

function SciMLBase.solve(prob::NonlinearProblem,
alg::Broyden, args...; abstol = nothing,
reltol = nothing,
maxiters = 1000, kwargs...)
f = Base.Fix2(prob.f, prob.p)
x = float(prob.u0)
fₙ = f(x)
T = eltype(x)
if length(x) > 1
J⁻¹ = Matrix{T}(I, length(x), length(x))
Copy link
Member

@ChrisRackauckas ChrisRackauckas Jan 2, 2023

Choose a reason for hiding this comment

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

That will allocate on static array problems. J⁻¹ should be a static array in that case.

@ChrisRackauckas
Copy link
Member

I did a few edits and it looks good. Thanks!

@ChrisRackauckas ChrisRackauckas merged commit 325547e into SciML:main Jan 2, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants