Skip to content

Commit 849ef80

Browse files
Merge branch 'master' into min_timestep_fix
2 parents 89a643d + 883d752 commit 849ef80

File tree

15 files changed

+263
-96
lines changed

15 files changed

+263
-96
lines changed

.github/workflows/CI.yml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@ jobs:
1515
- Core
1616
version:
1717
- '1'
18-
- '1.6'
1918
steps:
2019
- uses: actions/checkout@v4
2120
- uses: julia-actions/setup-julia@v1

Project.toml

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
name = "Sundials"
22
uuid = "c3572dad-4567-51f8-b174-8c6c989267f4"
33
authors = ["Chris Rackauckas <accounts@chrisrackauckas.com>"]
4-
version = "4.20.0"
4+
version = "4.23.1"
55

66
[deps]
77
CEnum = "fa961155-64e5-5f13-b03f-caf6b980ea82"
@@ -17,14 +17,14 @@ SparseArrays = "2f01184e-e22b-5df5-ae63-d93ebab69eaf"
1717
Sundials_jll = "fb77eaff-e24c-56d4-86b1-d163f2edb164"
1818

1919
[compat]
20-
CEnum = "0.2, 0.3, 0.4"
20+
CEnum = "0.5"
2121
DataStructures = "0.18"
2222
DiffEqBase = "6.122"
2323
PrecompileTools = "1"
24-
Reexport = "0.2, 1.0"
25-
SciMLBase = "1.92, 2"
24+
Reexport = "1.0"
25+
SciMLBase = "2.9"
2626
Sundials_jll = "5.2"
27-
julia = "1.6"
27+
julia = "1.9"
2828

2929
[extras]
3030
AlgebraicMultigrid = "2169fc97-5a83-5252-b627-83903c6c433c"

gen/generate.jl

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ function wrap_sundials_api(expr::Expr)
8686
if occursin(r"UserDataB?$", func_name)
8787
# replace Ptr{Void} with Any to allow passing Julia objects through user data
8888
for (i, arg_expr) in enumerate(expr.args[2].args[1].args)
89-
if !(typeof(arg_expr) <: Symbol) &&
89+
if !(arg_expr isa Symbol) &&
9090
arg_expr.args[1] in values(ctor_return_type)
9191
if arg_expr.args[2] == :(Ptr{Cvoid})
9292
arg_expr.args[2] = Any
@@ -96,7 +96,7 @@ function wrap_sundials_api(expr::Expr)
9696
end
9797
end
9898
end
99-
if !(typeof(expr) <: Symbol) && length(expr.args) > 1 &&
99+
if !(expr isa Symbol) && length(expr.args) > 1 &&
100100
(expr.args[2].args[1].args[2].args[2] == :libsundials_sunlinsol ||
101101
expr.args[2].args[1].args[2].args[2] == :libsundials_sunmatrix ||
102102
expr.args[2].args[1].args[2].args[2] == :libsundials_sunnonlinsol)
@@ -124,7 +124,7 @@ function wrap_sundials_api(expr::Expr)
124124
# 2) expr for local var definition, nothing if not required
125125
# 3) expr for low-level wrapper call
126126
# if 1)==3), then no wrapping is required
127-
if typeof(expr) <: Symbol
127+
if expr isa Symbol
128128
arg_name_expr = expr
129129
arg_type_expr = Any
130130
else

src/Sundials.jl

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,7 @@ import LinearAlgebra
1414
import Libdl
1515
using CEnum
1616

17-
const warnkeywords = (:d_discontinuities,
18-
:isoutofdomain,
17+
const warnkeywords = (:isoutofdomain,
1918
:unstable_check,
2019
:calck,
2120
:internalnorm,

src/common_interface/algorithms.jl

Lines changed: 22 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
# Abstract Types
44
abstract type SundialsODEAlgorithm{Method, LinearSolver} <: DiffEqBase.AbstractODEAlgorithm end
55
abstract type SundialsDAEAlgorithm{LinearSolver} <: DiffEqBase.AbstractDAEAlgorithm end
6-
abstract type SundialsNonlinearSolveAlgorithm{LinearSolver} end
6+
abstract type SundialsNonlinearSolveAlgorithm{LinearSolver} <: SciMLBase.AbstractNonlinearAlgorithm end
77

88
SciMLBase.alg_order(alg::Union{SundialsODEAlgorithm, SundialsDAEAlgorithm}) = alg.max_order
99

@@ -723,6 +723,9 @@ KINSOL(;
723723
jac_upper = 0,
724724
jac_lower = 0,
725725
userdata = nothing,
726+
prec_side = 0,
727+
krylov_dim = 0,
728+
globalization_strategy = :None
726729
)
727730
```
728731
@@ -738,7 +741,6 @@ The choices for the linear solver are:
738741
- `:LapackBand`: A version of the banded linear solver that uses the Julia-provided
739742
OpenBLAS-linked LAPACK for multithreaded operations. This will be faster than
740743
`:Band` on larger systems but has noticeable overhead on smaller (<100 ODE) systems.
741-
- `:Diagonal`: This method is specialized for diagonal Jacobians.
742744
- `:GMRES`: A GMRES method. Recommended first choice Krylov method.
743745
- `:BCG`: A biconjugate gradient method
744746
- `:PCG`: A preconditioned conjugate gradient method. Only for symmetric
@@ -747,19 +749,30 @@ The choices for the linear solver are:
747749
- `:KLU`: A sparse factorization method. Requires that the user specify a
748750
Jacobian. The Jacobian must be set as a sparse matrix in the `ODEProblem`
749751
type.
752+
753+
The choices for globalization strategy are:
754+
755+
- `:None`: No globalization strategy
756+
- `:LineSearch`: A line search globalization strategy
750757
"""
751758
struct KINSOL{LinearSolver} <: SundialsNonlinearSolveAlgorithm{LinearSolver}
752759
jac_upper::Int
753760
jac_lower::Int
754761
userdata::Any
762+
prec_side::Int
763+
krylov_dim::Int
764+
globalization_strategy::Symbol
755765
end
766+
756767
Base.@pure function KINSOL(;
757768
linear_solver = :Dense,
758769
jac_upper = 0,
759770
jac_lower = 0,
760-
userdata = nothing)
771+
userdata = nothing,
772+
prec_side = 0,
773+
krylov_dim = 0,
774+
globalization_strategy = :None)
761775
if !(linear_solver in (:None,
762-
:Diagonal,
763776
:Dense,
764777
:LapackDense,
765778
:Band,
@@ -772,9 +785,11 @@ Base.@pure function KINSOL(;
772785
:KLU))
773786
error("Linear solver choice not accepted.")
774787
end
775-
KINSOL{linear_solver}(jac_upper,
776-
jac_lower,
777-
userdata)
788+
if !(globalization_strategy in (:LineSearch, :None))
789+
error("Globalization strategy not accepted.")
790+
end
791+
KINSOL{linear_solver}(jac_upper, jac_lower, userdata, prec_side, krylov_dim,
792+
globalization_strategy)
778793
end
779794

780795
method_choice(alg::SundialsODEAlgorithm{Method}) where {Method} = Method

src/common_interface/function_types.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,7 @@ function massmat(t::Float64,
146146
tmp1::N_Vector,
147147
tmp2::N_Vector,
148148
tmp3::N_Vector)
149-
if typeof(mmf.mass_matrix) <: Array
149+
if mmf.mass_matrix isa Array
150150
M = convert(Matrix, _M)
151151
M .= mmf.mass_matrix
152152
else

src/common_interface/integrator_types.jl

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,10 @@ mutable struct DEOptions{SType, TstopType, SType2, TstopType2, SIX, CType, relto
2020
advance_to_tstop::Bool
2121
stop_at_next_tstop::Bool
2222
progress::Bool
23+
progress_steps::Int
2324
progress_name::String
2425
progress_message::F5
26+
progress_id::Symbol
2527
maxiters::Int
2628
end
2729

@@ -172,6 +174,7 @@ mutable struct IDAIntegrator{N,
172174
tmp::Array{Float64, N}
173175
uprev::Array{Float64, N}
174176
flag::Cint
177+
iter::Int
175178
just_hit_tstop::Bool
176179
event_last_time::Int
177180
vector_event_last_time::Int
@@ -197,6 +200,13 @@ function (integrator::IDAIntegrator)(out,
197200
integrator.flag = @checkflag IDAGetDky(integrator.mem, t, Cint(T), vec(out))
198201
return idxs === nothing ? out : @view out[idxs]
199202
end
203+
function (integrator::IDAIntegrator)(out::SubArray,
204+
t::Number,
205+
deriv::Type{Val{T}} = Val{0};
206+
idxs = nothing) where {T}
207+
throw(ArgumentError("Views are not supported with IDA!"))
208+
end
209+
200210

201211
### Error check (retcode)
202212

@@ -217,7 +227,7 @@ DiffEqBase.postamble!(integrator::AbstractSundialsIntegrator) = nothing
217227
tstop = first(integrator.opts.tstops)
218228
set_stop_time(integrator, tstop)
219229
integrator.tprev = integrator.t
220-
if !(typeof(integrator.opts.callback.continuous_callbacks) <: Tuple{})
230+
if !(integrator.opts.callback.continuous_callbacks isa Tuple{})
221231
integrator.uprev .= integrator.u
222232
end
223233
solver_step(integrator, tstop)
@@ -228,7 +238,7 @@ DiffEqBase.postamble!(integrator::AbstractSundialsIntegrator) = nothing
228238
end
229239
else
230240
integrator.tprev = integrator.t
231-
if !(typeof(integrator.opts.callback.continuous_callbacks) <: Tuple{})
241+
if !(integrator.opts.callback.continuous_callbacks isa Tuple{})
232242
integrator.uprev .= integrator.u
233243
end
234244
if !isempty(integrator.opts.tstops)

src/common_interface/integrator_utils.jl

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ function handle_callbacks!(integrator)
66
continuous_modified = false
77
discrete_modified = false
88
saved_in_cb = false
9-
if !(typeof(continuous_callbacks) <: Tuple{})
9+
if !(continuous_callbacks isa Tuple{})
1010
time, upcrossing, event_occured, event_idx, idx, counter = DiffEqBase.find_first_continuous_callback(integrator,
1111
continuous_callbacks...)
1212
if event_occured
@@ -22,7 +22,7 @@ function handle_callbacks!(integrator)
2222
integrator.vector_event_last_time = 1
2323
end
2424
end
25-
if !(typeof(discrete_callbacks) <: Tuple{})
25+
if !(discrete_callbacks isa Tuple{})
2626
discrete_modified, saved_in_cb = DiffEqBase.apply_discrete_callback!(integrator,
2727
discrete_callbacks...)
2828
end
@@ -46,10 +46,9 @@ function DiffEqBase.savevalues!(integrator::AbstractSundialsIntegrator,
4646
uType = typeof(integrator.sol.prob.u0)
4747
# The call to first is an overload of Base.first implemented in DataStructures
4848
while !isempty(integrator.opts.saveat) &&
49-
integrator.tdir * first(integrator.opts.saveat) < integrator.tdir * integrator.t
49+
first(integrator.opts.saveat) <= integrator.tdir * integrator.t
5050
saved = true
51-
curt = pop!(integrator.opts.saveat)
52-
51+
curt = integrator.tdir * pop!(integrator.opts.saveat)
5352
tmp = integrator(curt)
5453
save_value!(integrator.sol.u, tmp, uType,
5554
integrator.opts.save_idxs, false)
@@ -123,13 +122,13 @@ end
123122
function DiffEqBase.add_tstop!(integrator::AbstractSundialsIntegrator, t)
124123
integrator.tdir * (t - integrator.t) < 0 &&
125124
error("Tried to add a tstop that is behind the current time. This is strictly forbidden")
126-
push!(integrator.opts.tstops, t)
125+
push!(integrator.opts.tstops, integrator.tdir * t)
127126
end
128127

129128
function DiffEqBase.add_saveat!(integrator::AbstractSundialsIntegrator, t)
130129
integrator.tdir * (t - integrator.t) < 0 &&
131130
error("Tried to add a saveat that is behind the current time. This is strictly forbidden")
132-
push!(integrator.opts.saveat, t)
131+
push!(integrator.opts.saveat, integrator.tdir * t)
133132
end
134133

135134
DiffEqBase.get_tmp_cache(integrator::AbstractSundialsIntegrator) = (integrator.tmp,)

0 commit comments

Comments
 (0)