Skip to content

Commit

Permalink
use full form
Browse files Browse the repository at this point in the history
  • Loading branch information
avik-pal committed Oct 30, 2023
1 parent d63e00b commit 7e3610e
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 16 deletions.
2 changes: 1 addition & 1 deletion src/common_defaults.jl
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ end
end
@inline ODE_DEFAULT_NORM(u, t) = norm(u)

@inline NLSOLVE_DEFAULT_NORM(u) = ODE_DEFAULT_NORM(u, nothing)
@inline NONLINEARSOLVE_DEFAULT_NORM(u) = ODE_DEFAULT_NORM(u, nothing)

@inline ODE_DEFAULT_ISOUTOFDOMAIN(u, p, t) = false
@inline function ODE_DEFAULT_PROG_MESSAGE(dt, u::Array, p, t)
Expand Down
32 changes: 17 additions & 15 deletions src/termination_conditions.jl
Original file line number Diff line number Diff line change
Expand Up @@ -109,11 +109,11 @@ end
function (cache::NonlinearTerminationModeCache)(mode::AbstractSafeNonlinearTerminationMode,

Check warning on line 109 in src/termination_conditions.jl

View check run for this annotation

Codecov / codecov/patch

src/termination_conditions.jl#L109

Added line #L109 was not covered by tests
du, u, uprev)
if mode isa AbsSafeTerminationMode || mode isa AbsSafeBestTerminationMode
objective = NLSOLVE_DEFAULT_NORM(du)
objective = NONLINEARSOLVE_DEFAULT_NORM(du)
criteria = cache.abstol

Check warning on line 113 in src/termination_conditions.jl

View check run for this annotation

Codecov / codecov/patch

src/termination_conditions.jl#L111-L113

Added lines #L111 - L113 were not covered by tests
else
objective = NLSOLVE_DEFAULT_NORM(du) /
(NLSOLVE_DEFAULT_NORM(du .+ u) + eps(cache.abstol))
objective = NONLINEARSOLVE_DEFAULT_NORM(du) /

Check warning on line 115 in src/termination_conditions.jl

View check run for this annotation

Codecov / codecov/patch

src/termination_conditions.jl#L115

Added line #L115 was not covered by tests
(NONLINEARSOLVE_DEFAULT_NORM(du .+ u) + eps(cache.abstol))
criteria = cache.reltol

Check warning on line 117 in src/termination_conditions.jl

View check run for this annotation

Codecov / codecov/patch

src/termination_conditions.jl#L117

Added line #L117 was not covered by tests
end

Expand All @@ -138,7 +138,7 @@ function (cache::NonlinearTerminationModeCache)(mode::AbstractSafeNonlinearTermi
if objective cache.mode.patience_objective_multiplier * criteria
if cache.nsteps cache.mode.patience_steps
if cache.nsteps < length(cache.objectives_trace)
min_obj, max_obj = extrema(@view(cache.objectives_trace[1:cache.nsteps]))
min_obj, max_obj = extrema(@view(cache.objectives_trace[1:(cache.nsteps)]))

Check warning on line 141 in src/termination_conditions.jl

View check run for this annotation

Codecov / codecov/patch

src/termination_conditions.jl#L138-L141

Added lines #L138 - L141 were not covered by tests
else
min_obj, max_obj = extrema(cache.objectives_trace)

Check warning on line 143 in src/termination_conditions.jl

View check run for this annotation

Codecov / codecov/patch

src/termination_conditions.jl#L143

Added line #L143 was not covered by tests
end
Expand Down Expand Up @@ -169,22 +169,23 @@ function check_convergence(::SimpleNonlinearSolveTerminationMode, duₙ, uₙ, u
isapprox(uₙ, uₙ₋₁; atol = abstol, rtol = reltol)
end
function check_convergence(::NormTerminationMode, duₙ, uₙ, uₙ₋₁, abstol, reltol)
du_norm = NLSOLVE_DEFAULT_NORM(duₙ)
return du_norm abstol || du_norm reltol * NLSOLVE_DEFAULT_NORM(duₙ .+ uₙ)
du_norm = NONLINEARSOLVE_DEFAULT_NORM(duₙ)
return du_norm abstol || du_norm reltol * NONLINEARSOLVE_DEFAULT_NORM(duₙ .+ uₙ)

Check warning on line 173 in src/termination_conditions.jl

View check run for this annotation

Codecov / codecov/patch

src/termination_conditions.jl#L171-L173

Added lines #L171 - L173 were not covered by tests
end
function check_convergence(::RelNormTerminationMode, duₙ, uₙ, uₙ₋₁, abstol, reltol)
return all(abs.(duₙ) .≤ reltol .* abs.(uₙ))

Check warning on line 176 in src/termination_conditions.jl

View check run for this annotation

Codecov / codecov/patch

src/termination_conditions.jl#L175-L176

Added lines #L175 - L176 were not covered by tests
end
function check_convergence(::Union{RelNormTerminationMode, RelSafeTerminationMode,

Check warning on line 178 in src/termination_conditions.jl

View check run for this annotation

Codecov / codecov/patch

src/termination_conditions.jl#L178

Added line #L178 was not covered by tests
RelSafeBestTerminationMode}, duₙ, uₙ, uₙ₋₁, abstol, reltol)
return NLSOLVE_DEFAULT_NORM(duₙ) reltol * NLSOLVE_DEFAULT_NORM(duₙ .+ uₙ)
return NONLINEARSOLVE_DEFAULT_NORM(duₙ)

Check warning on line 180 in src/termination_conditions.jl

View check run for this annotation

Codecov / codecov/patch

src/termination_conditions.jl#L180

Added line #L180 was not covered by tests
reltol * NONLINEARSOLVE_DEFAULT_NORM(duₙ .+ uₙ)
end
function check_convergence(::AbsTerminationMode, duₙ, uₙ, uₙ₋₁, abstol, reltol)
return all(abs.(duₙ) .≤ abstol)

Check warning on line 184 in src/termination_conditions.jl

View check run for this annotation

Codecov / codecov/patch

src/termination_conditions.jl#L183-L184

Added lines #L183 - L184 were not covered by tests
end
function check_convergence(::Union{AbsNormTerminationMode, AbsSafeTerminationMode,

Check warning on line 186 in src/termination_conditions.jl

View check run for this annotation

Codecov / codecov/patch

src/termination_conditions.jl#L186

Added line #L186 was not covered by tests
AbsSafeBestTerminationMode}, duₙ, uₙ, uₙ₋₁, abstol, reltol)
return NLSOLVE_DEFAULT_NORM(duₙ) abstol
return NONLINEARSOLVE_DEFAULT_NORM(duₙ) abstol

Check warning on line 188 in src/termination_conditions.jl

View check run for this annotation

Codecov / codecov/patch

src/termination_conditions.jl#L188

Added line #L188 was not covered by tests
end

# NOTE: Deprecate the following API eventually. This API leads to quite a bit of type
Expand Down Expand Up @@ -363,11 +364,11 @@ function (cond::NLSolveTerminationCondition)(storage::Union{
end

if mode SAFE_BEST_TERMINATION_MODES
objective = NLSOLVE_DEFAULT_NORM(du)
objective = NONLINEARSOLVE_DEFAULT_NORM(du)

Check warning on line 367 in src/termination_conditions.jl

View check run for this annotation

Codecov / codecov/patch

src/termination_conditions.jl#L367

Added line #L367 was not covered by tests
criteria = abstol
else
objective = NLSOLVE_DEFAULT_NORM(du) /
(NLSOLVE_DEFAULT_NORM(du .+ u) + eps(aType))
objective = NONLINEARSOLVE_DEFAULT_NORM(du) /

Check warning on line 370 in src/termination_conditions.jl

View check run for this annotation

Codecov / codecov/patch

src/termination_conditions.jl#L370

Added line #L370 was not covered by tests
(NONLINEARSOLVE_DEFAULT_NORM(du .+ u) + eps(aType))
criteria = reltol
end

Expand Down Expand Up @@ -426,18 +427,19 @@ end

@inline @inbounds function _has_converged(du, u, uprev, mode, abstol, reltol)
if mode == NLSolveTerminationMode.Norm
du_norm = NLSOLVE_DEFAULT_NORM(du)
return du_norm abstol || du_norm reltol * NLSOLVE_DEFAULT_NORM(du + u)
du_norm = NONLINEARSOLVE_DEFAULT_NORM(du)
return du_norm abstol || du_norm reltol * NONLINEARSOLVE_DEFAULT_NORM(du + u)

Check warning on line 431 in src/termination_conditions.jl

View check run for this annotation

Codecov / codecov/patch

src/termination_conditions.jl#L430-L431

Added lines #L430 - L431 were not covered by tests
elseif mode == NLSolveTerminationMode.Rel
return all(abs.(du) .≤ reltol .* abs.(u))
elseif mode (NLSolveTerminationMode.RelNorm, NLSolveTerminationMode.RelSafe,
NLSolveTerminationMode.RelSafeBest)
return NLSOLVE_DEFAULT_NORM(du) reltol * NLSOLVE_DEFAULT_NORM(du .+ u)
return NONLINEARSOLVE_DEFAULT_NORM(du)

Check warning on line 436 in src/termination_conditions.jl

View check run for this annotation

Codecov / codecov/patch

src/termination_conditions.jl#L436

Added line #L436 was not covered by tests
reltol * NONLINEARSOLVE_DEFAULT_NORM(du .+ u)
elseif mode == NLSolveTerminationMode.Abs
return all(abs.(du) .≤ abstol)
elseif mode (NLSolveTerminationMode.AbsNorm, NLSolveTerminationMode.AbsSafe,
NLSolveTerminationMode.AbsSafeBest)
return NLSOLVE_DEFAULT_NORM(du) abstol
return NONLINEARSOLVE_DEFAULT_NORM(du) abstol
elseif mode == NLSolveTerminationMode.SteadyStateDefault
return all((abs.(du) .≤ abstol) .| (abs.(du) .≤ reltol .* abs.(u)))
elseif mode == NLSolveTerminationMode.NLSolveDefault
Expand Down

0 comments on commit 7e3610e

Please sign in to comment.