Skip to content

Commit e4f41ac

Browse files
committed
rename to IDSolve
1 parent 505c73d commit e4f41ac

File tree

5 files changed

+34
-28
lines changed

5 files changed

+34
-28
lines changed

lib/ImplicitDiscreteSolve/src/ImplicitDiscreteSolve.jl

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,16 +10,16 @@ using Reexport
1010
@reexport using DiffEqBase
1111

1212
"""
13-
SimpleIDSolve()
13+
IDSolve()
1414
1515
Simple solver for `ImplicitDiscreteSystems`. Uses `SimpleNewtonRaphson` to solve for the next state at every timestep.
1616
"""
17-
struct SimpleIDSolve <: OrdinaryDiffEqAlgorithm end
17+
struct IDSolve <: OrdinaryDiffEqAlgorithm end
1818

1919
include("cache.jl")
2020
include("solve.jl")
2121
include("alg_utils.jl")
2222

23-
export SimpleIDSolve
23+
export IDSolve
2424

2525
end
Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,19 @@
1-
function SciMLBase.isautodifferentiable(alg::SimpleIDSolve)
1+
function SciMLBase.isautodifferentiable(alg::IDSolve)
22
true
33
end
4-
function SciMLBase.allows_arbitrary_number_types(alg::SimpleIDSolve)
4+
function SciMLBase.allows_arbitrary_number_types(alg::IDSolve)
55
true
66
end
7-
function SciMLBase.allowscomplex(alg::SimpleIDSolve)
7+
function SciMLBase.allowscomplex(alg::IDSolve)
88
true
99
end
1010

11-
SciMLBase.isdiscrete(alg::SimpleIDSolve) = true
11+
SciMLBase.isdiscrete(alg::IDSolve) = true
1212

13-
isfsal(alg::SimpleIDSolve) = false
14-
alg_order(alg::SimpleIDSolve) = 0
15-
beta2_default(alg::SimpleIDSolve) = 0
16-
beta1_default(alg::SimpleIDSolve, beta2) = 0
13+
isfsal(alg::IDSolve) = false
14+
alg_order(alg::IDSolve) = 0
15+
beta2_default(alg::IDSolve) = 0
16+
beta1_default(alg::IDSolve, beta2) = 0
1717

18-
dt_required(alg::SimpleIDSolve) = false
19-
isdiscretealg(alg::SimpleIDSolve) = true
18+
dt_required(alg::IDSolve) = false
19+
isdiscretealg(alg::IDSolve) = true

lib/ImplicitDiscreteSolve/src/cache.jl

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,35 +4,35 @@ mutable struct ImplicitDiscreteState{uType, pType, tType}
44
t_next::tType
55
end
66

7-
mutable struct SimpleIDSolveCache{uType} <: OrdinaryDiffEqMutableCache
7+
mutable struct IDSolveCache{uType} <: OrdinaryDiffEqMutableCache
88
u::uType
99
uprev::uType
1010
state::ImplicitDiscreteState
1111
prob::Union{Nothing, SciMLBase.AbstractNonlinearProblem}
1212
end
1313

14-
function alg_cache(alg::SimpleIDSolve, u, rate_prototype, ::Type{uEltypeNoUnits},
14+
function alg_cache(alg::IDSolve, u, rate_prototype, ::Type{uEltypeNoUnits},
1515
::Type{uBottomEltypeNoUnits}, ::Type{tTypeNoUnits}, uprev, uprev2, f, t,
1616
dt, reltol, p, calck,
1717
::Val{true}) where {uEltypeNoUnits, uBottomEltypeNoUnits, tTypeNoUnits}
1818

1919
state = ImplicitDiscreteState(isnothing(u) ? nothing : zero(u), p, t)
20-
SimpleIDSolveCache(u, uprev, state, nothing)
20+
IDSolveCache(u, uprev, state, nothing)
2121
end
2222

23-
isdiscretecache(cache::SimpleIDSolveCache) = true
23+
isdiscretecache(cache::IDSolveCache) = true
2424

25-
struct SimpleIDSolveConstantCache <: OrdinaryDiffEqConstantCache
25+
struct IDSolveConstantCache <: OrdinaryDiffEqConstantCache
2626
prob::Union{Nothing, SciMLBase.AbstractNonlinearProblem}
2727
end
2828

29-
function alg_cache(alg::SimpleIDSolve, u, rate_prototype, ::Type{uEltypeNoUnits},
29+
function alg_cache(alg::IDSolve, u, rate_prototype, ::Type{uEltypeNoUnits},
3030
::Type{uBottomEltypeNoUnits}, ::Type{tTypeNoUnits}, uprev, uprev2, f, t,
3131
dt, reltol, p, calck,
3232
::Val{false}) where {uEltypeNoUnits, uBottomEltypeNoUnits, tTypeNoUnits}
3333

3434
state = ImplicitDiscreteState(isnothing(u) ? nothing : zero(u), p, t)
35-
SimpleIDSolveCache(u, uprev, state, nothing)
35+
IDSolveCache(u, uprev, state, nothing)
3636
end
3737

38-
get_fsalfirstlast(cache::SimpleIDSolveCache, rate_prototype) = (nothing, nothing)
38+
get_fsalfirstlast(cache::IDSolveCache, rate_prototype) = (nothing, nothing)

lib/ImplicitDiscreteSolve/src/solve.jl

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# Remake the nonlinear problem, then update
2-
function perform_step!(integrator, cache::SimpleIDSolveCache, repeat_step = false)
2+
function perform_step!(integrator, cache::IDSolveCache, repeat_step = false)
33
@unpack alg, u, uprev, dt, t, f, p = integrator
44
@unpack state, prob = cache
55
state.u .= uprev
@@ -11,7 +11,7 @@ function perform_step!(integrator, cache::SimpleIDSolveCache, repeat_step = fals
1111
integrator.u = u
1212
end
1313

14-
function initialize!(integrator, cache::SimpleIDSolveCache)
14+
function initialize!(integrator, cache::IDSolveCache)
1515
integrator.u isa AbstractVector && (cache.state.u .= integrator.u)
1616
cache.state.p = integrator.p
1717
cache.state.t_next = integrator.t
@@ -22,11 +22,12 @@ function initialize!(integrator, cache::SimpleIDSolveCache)
2222
else
2323
(u_next, p) -> f(u_next, p.u, p.p, p.t_next)
2424
end
25+
nlls = length(f.resid_prototype) == length(integrator.u)
2526

26-
prob = if isinplace(f)
27-
NonlinearProblem{true}(_f, cache.state.u, cache.state)
27+
prob = if nlls
28+
NonlinearLeastSquaresProblem{isinplace(f)}(_f, cache.state.u, cache.state)
2829
else
29-
NonlinearProblem{false}(_f, cache.state.u, cache.state)
30+
NonlinearProblem{isinplace(f)}(_f, cache.state.u, cache.state)
3031
end
3132
cache.prob = prob
3233
end
@@ -47,7 +48,12 @@ function _initialize_dae!(integrator, prob::ImplicitDiscreteProblem,
4748
else
4849
(u_next, p) -> f(u_next, p.u, p.p, p.t_next)
4950
end
50-
prob = NonlinearProblem{isinplace(f)}(_f, u, initstate)
51+
nlls = length(f.resid_prototype) == length(integrator.u)
52+
prob = if nlls
53+
NonlinearLeastSquaresProblem{isinplace(f)}(_f, cache.state.u, cache.state)
54+
else
55+
NonlinearProblem{isinplace(f)}(_f, cache.state.u, cache.state)
56+
end
5157
sol = solve(prob, SimpleNewtonRaphson())
5258
integrator.u = sol
5359
end

lib/OrdinaryDiffEqCore/src/solve.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -563,7 +563,7 @@ function DiffEqBase.__init(
563563
if initialize_integrator
564564
if isdae || SciMLBase.has_initializeprob(prob.f) || prob isa SciMLBase.ImplicitDiscreteProblem
565565
DiffEqBase.initialize_dae!(integrator)
566-
update_uprev!(integrator)
566+
!isnothing(integrator.u) && update_uprev!(integrator)
567567
end
568568

569569
if save_start

0 commit comments

Comments
 (0)