Skip to content

Commit a571725

Browse files
Trim unused OrdinaryDiffEq code
1 parent 7cb570d commit a571725

File tree

2 files changed

+5
-146
lines changed

2 files changed

+5
-146
lines changed

examples/hybrid/ode_config.jl

Lines changed: 5 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import SciMLBase
2-
import OrdinaryDiffEq as ODE
32
import ClimaTimeSteppers as CTS
43

54
is_explicit_CTS_algo_type(alg_or_tableau) =
@@ -8,35 +7,13 @@ is_explicit_CTS_algo_type(alg_or_tableau) =
87
is_imex_CTS_algo_type(alg_or_tableau) =
98
alg_or_tableau <: CTS.IMEXARKAlgorithmName
109

11-
is_implicit_type(::typeof(ODE.IMEXEuler)) = true
12-
is_implicit_type(alg_or_tableau) =
13-
alg_or_tableau <: Union{
14-
ODE.OrdinaryDiffEqImplicitAlgorithm,
15-
ODE.OrdinaryDiffEqAdaptiveImplicitAlgorithm,
16-
} || is_imex_CTS_algo_type(alg_or_tableau)
17-
18-
is_ordinary_diffeq_newton(::typeof(ODE.IMEXEuler)) = true
19-
is_ordinary_diffeq_newton(alg_or_tableau) =
20-
alg_or_tableau <: Union{
21-
ODE.OrdinaryDiffEqNewtonAlgorithm,
22-
ODE.OrdinaryDiffEqNewtonAdaptiveAlgorithm,
23-
}
24-
2510
is_imex_CTS_algo(::CTS.IMEXAlgorithm) = true
2611
is_imex_CTS_algo(::SciMLBase.AbstractODEAlgorithm) = false
2712

28-
is_implicit(::ODE.OrdinaryDiffEqImplicitAlgorithm) = true
29-
is_implicit(::ODE.OrdinaryDiffEqAdaptiveImplicitAlgorithm) = true
30-
is_implicit(ode_algo) = is_imex_CTS_algo(ode_algo)
31-
32-
is_rosenbrock(::ODE.Rosenbrock23) = true
33-
is_rosenbrock(::ODE.Rosenbrock32) = true
34-
is_rosenbrock(::SciMLBase.AbstractODEAlgorithm) = false
35-
use_transform(ode_algo) =
36-
!(is_imex_CTS_algo(ode_algo) || is_rosenbrock(ode_algo))
13+
use_transform(ode_algo) = !is_imex_CTS_algo(ode_algo)
3714

3815
function jac_kwargs(ode_algo, Y, jacobi_flags)
39-
if is_implicit(ode_algo)
16+
if is_imex_CTS_algo(ode_algo)
4017
W = SchurComplementW(Y, use_transform(ode_algo), jacobi_flags)
4118
if use_transform(ode_algo)
4219
return (; jac_prototype = W, Wfact_t = Wfact!)
@@ -57,32 +34,17 @@ function ode_configuration(
5734
ode_name = split(ode_name, ".")[end]
5835
end
5936
ode_sym = Symbol(ode_name)
60-
alg_or_tableau = if hasproperty(ODE, ode_sym)
61-
@warn "apply_limiter flag is ignored for OrdinaryDiffEq algorithms"
62-
getproperty(ODE, ode_sym)
63-
else
64-
getproperty(CTS, ode_sym)
65-
end
37+
alg_or_tableau = getproperty(CTS, ode_sym)
6638
@info "Using ODE config: `$alg_or_tableau`"
6739

6840
if is_explicit_CTS_algo_type(alg_or_tableau)
6941
return CTS.ExplicitAlgorithm(alg_or_tableau())
70-
elseif !is_implicit_type(alg_or_tableau)
42+
elseif !is_imex_CTS_algo_type(alg_or_tableau)
7143
return alg_or_tableau()
72-
elseif is_ordinary_diffeq_newton(alg_or_tableau)
73-
if max_newton_iters == 1
74-
error("OridinaryDiffEq requires at least 2 Newton iterations")
75-
end
76-
# κ like a relative tolerance; its default value in ODE is 0.01
77-
nlsolve = ODE.NLNewton(;
78-
κ = max_newton_iters == 2 ? Inf : 0.01,
79-
max_iter = max_newton_iters,
80-
)
81-
return alg_or_tableau(; linsolve = linsolve!, nlsolve)
8244
elseif is_imex_CTS_algo_type(alg_or_tableau)
8345
newtons_method = CTS.NewtonsMethod(; max_iters = max_newton_iters)
8446
return CTS.IMEXAlgorithm(alg_or_tableau(), newtons_method)
8547
else
86-
return alg_or_tableau(; linsolve = linsolve!)
48+
error("Uncaught case")
8749
end
8850
end
Lines changed: 0 additions & 103 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,5 @@
1-
using OrdinaryDiffEq:
2-
AbstractNLSolver,
3-
isnewton,
4-
DIRK,
5-
update_W!,
6-
initialize!,
7-
Divergence,
8-
get_new_W!,
9-
initial_η,
10-
compute_step!,
11-
apply_step!,
12-
Convergence,
13-
isJcurrent,
14-
postamble!,
15-
TryAgain
161
using SciMLBase: RECOMPILE_BY_DEFAULT
172

18-
import OrdinaryDiffEq: nlsolve!
193
import SciMLBase: SplitFunction
204

215
#=
@@ -40,90 +24,3 @@ function SplitFunction{iip}(f1, f2; kwargs...) where {iip}
4024
tgrad = f1.tgrad,
4125
)
4226
end
43-
44-
#=
45-
Issue: nlsolve! has a goto statement that restarts the solver when the
46-
conditions for DiffEqBase.SlowConvergence (denoted by TryAgain) are
47-
satisfied. These conditions include !isJcurrent, which is always true
48-
when a custom Wfact or Wfact_t is used because of how calc_W! is written.
49-
So, when a custom Wfact or Wfact_t is used, nlsolve! sometimes enters an
50-
infinite loop (though there are also situations where it converges after
51-
several iterations of the loop). This is probably not the intended
52-
behavior, so this patch limits the number of loop iterations to 100,
53-
after which divergence is declared.
54-
=#
55-
function nlsolve!(
56-
nlsolver::AbstractNLSolver,
57-
integrator,
58-
cache = nothing,
59-
repeat_step = false,
60-
)
61-
num_redos = 0
62-
@label REDO
63-
if isnewton(nlsolver)
64-
cache === nothing && throw(
65-
ArgumentError(
66-
"cache is not passed to `nlsolve!` when using NLNewton",
67-
),
68-
)
69-
if nlsolver.method === DIRK
70-
γW = nlsolver.γ * integrator.dt
71-
else
72-
γW = nlsolver.γ * integrator.dt / nlsolver.α
73-
end
74-
update_W!(nlsolver, integrator, cache, γW, repeat_step)
75-
end
76-
77-
(; maxiters, κ, fast_convergence_cutoff) = nlsolver
78-
79-
initialize!(nlsolver, integrator)
80-
nlsolver.status = Divergence
81-
η = get_new_W!(nlsolver) ? initial_η(nlsolver, integrator) : nlsolver.ηold
82-
83-
local ndz
84-
for iter in 1:maxiters
85-
nlsolver.iter = iter
86-
87-
# compute next step and calculate norm of residuals
88-
iter > 1 && (ndzprev = ndz)
89-
ndz = compute_step!(nlsolver, integrator)
90-
if !isfinite(ndz)
91-
nlsolver.status = Divergence
92-
break
93-
end
94-
95-
# check divergence (not in initial step)
96-
if iter > 1
97-
θ = ndz / ndzprev
98-
99-
# divergence
100-
if θ > 2
101-
nlsolver.status = Divergence
102-
break
103-
end
104-
end
105-
106-
apply_step!(nlsolver, integrator)
107-
108-
# check for convergence
109-
iter > 1 &&= θ / (1 - θ))
110-
if (iter == 1 && ndz < 1e-5) ||
111-
(iter > 1 &&>= zero(η) && η * ndz < κ))
112-
nlsolver.status = Convergence
113-
break
114-
end
115-
end
116-
117-
if isnewton(nlsolver) &&
118-
nlsolver.status == Divergence &&
119-
!isJcurrent(nlsolver, integrator)
120-
num_redos += 1
121-
if num_redos < 100
122-
nlsolver.status = TryAgain
123-
@goto REDO
124-
end
125-
end
126-
127-
nlsolver.ηold = η
128-
postamble!(nlsolver, integrator)
129-
end

0 commit comments

Comments
 (0)