Skip to content

Commit

Permalink
refactor: minor stylistic fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
avik-pal committed Oct 23, 2024
1 parent 21b02bd commit ecded14
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 19 deletions.
4 changes: 2 additions & 2 deletions src/algorithms/broyden.jl
Original file line number Diff line number Diff line change
Expand Up @@ -152,14 +152,14 @@ end
Broyden Update Rule corresponding to "bad broyden's method" [broyden1965class](@cite).
"""
@concrete struct BadBroydenUpdateRule <: AbstractApproximateJacobianUpdateRule{true} end
struct BadBroydenUpdateRule <: AbstractApproximateJacobianUpdateRule{true} end

"""
GoodBroydenUpdateRule()
Broyden Update Rule corresponding to "good broyden's method" [broyden1965class](@cite).
"""
@concrete struct GoodBroydenUpdateRule <: AbstractApproximateJacobianUpdateRule{true} end
struct GoodBroydenUpdateRule <: AbstractApproximateJacobianUpdateRule{true} end

@concrete mutable struct BroydenUpdateRuleCache{mode} <:
AbstractApproximateJacobianUpdateRuleCache{true}
Expand Down
11 changes: 3 additions & 8 deletions src/algorithms/extension_algs.jl
Original file line number Diff line number Diff line change
Expand Up @@ -362,11 +362,7 @@ function FixedPointAccelerationJL(;
end
end
if extrapolation_period === missing
if algorithm === :SEA || algorithm === :VEA
extrapolation_period = 6
else
extrapolation_period = 7
end
extrapolation_period = algorithm === :SEA || algorithm === :VEA ? 6 : 7
else
if (algorithm === :SEA || algorithm === :VEA) && extrapolation_period % 2 != 0
error("`extrapolation_period` must be multiples of 2 for SEA and VEA")
Expand Down Expand Up @@ -404,11 +400,10 @@ end
This algorithm is only available if `SIAMFANLEquations.jl` is installed.
"""
@concrete struct SIAMFANLEquationsJL{L <: Union{Symbol, Nothing}} <:
AbstractNonlinearSolveExtensionAlgorithm
@concrete struct SIAMFANLEquationsJL <: AbstractNonlinearSolveExtensionAlgorithm
method::Symbol
delta
linsolve::L
linsolve <: Union{Symbol, Nothing}
m::Int
beta
autodiff
Expand Down
2 changes: 1 addition & 1 deletion src/algorithms/klement.jl
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ end
Update rule for [`Klement`](@ref).
"""
@concrete struct KlementUpdateRule <: AbstractApproximateJacobianUpdateRule{false} end
struct KlementUpdateRule <: AbstractApproximateJacobianUpdateRule{false} end

@concrete mutable struct KlementUpdateRuleCache <:
AbstractApproximateJacobianUpdateRuleCache{false}
Expand Down
12 changes: 6 additions & 6 deletions src/algorithms/lbroyden.jl
Original file line number Diff line number Diff line change
Expand Up @@ -18,30 +18,30 @@ and line search.
function LimitedMemoryBroyden(; max_resets::Int = 3, linesearch = nothing,
threshold::Union{Val, Int} = Val(10), reset_tolerance = nothing, alpha = nothing)
threshold isa Int && (threshold = Val(threshold))
initialization = BroydenLowRankInitialization{_unwrap_val(threshold)}(alpha, threshold)
initialization = BroydenLowRankInitialization(alpha, threshold)
return ApproximateJacobianSolveAlgorithm{false, :LimitedMemoryBroyden}(; linesearch,
descent = NewtonDescent(), update_rule = GoodBroydenUpdateRule(),
max_resets, initialization, reinit_rule = NoChangeInStateReset(; reset_tolerance))
end

"""
BroydenLowRankInitialization{T}(alpha, threshold::Val{T})
BroydenLowRankInitialization(alpha, threshold::Val)
An initialization for `LimitedMemoryBroyden` that uses a low rank approximation of the
Jacobian. The low rank updates to the Jacobian matrix corresponds to what SciPy calls
["simple"](https://docs.scipy.org/doc/scipy/reference/generated/scipy.optimize.broyden2.html#scipy-optimize-broyden2).
"""
@concrete struct BroydenLowRankInitialization{T} <: AbstractJacobianInitialization
@concrete struct BroydenLowRankInitialization <: AbstractJacobianInitialization
alpha
threshold::Val{T}
threshold <: Val
end

jacobian_initialized_preinverted(::BroydenLowRankInitialization) = true

function __internal_init(
prob::AbstractNonlinearProblem, alg::BroydenLowRankInitialization{T},
prob::AbstractNonlinearProblem, alg::BroydenLowRankInitialization,
solver, f::F, fu, u, p; maxiters = 1000,
internalnorm::IN = L2_NORM, kwargs...) where {T, F, IN}
internalnorm::IN = L2_NORM, kwargs...) where {F, IN}
if u isa Number # Use the standard broyden
return __internal_init(prob, IdentityInitialization(true, FullStructure()),
solver, f, fu, u, p; maxiters, kwargs...)
Expand Down
3 changes: 1 addition & 2 deletions src/algorithms/levenberg_marquardt.jl
Original file line number Diff line number Diff line change
Expand Up @@ -95,8 +95,7 @@ end

function __internal_init(
prob::AbstractNonlinearProblem, f::LevenbergMarquardtDampingFunction,
initial_damping, J, fu, u, ::Val{NF};
internalnorm::F = L2_NORM, kwargs...) where {F, NF}
initial_damping, J, fu, u, ::Val{NF}; kwargs...) where {NF}
T = promote_type(eltype(u), eltype(fu))
DᵀD = __init_diagonal(u, T(f.min_damping))
if NF
Expand Down

0 comments on commit ecded14

Please sign in to comment.