| Line | Exclusive | Inclusive | Code |
|---|---|---|---|
| 1 | mutable struct DEOptions{SType, TstopType, SType2, TstopType2, SIX, CType, reltolType, | ||
| 2 | abstolType, | ||
| 3 | F5} | ||
| 4 | saveat::SType | ||
| 5 | tstops::TstopType | ||
| 6 | saveat_cache::SType2 | ||
| 7 | tstops_cache::TstopType2 | ||
| 8 | save_start::Bool | ||
| 9 | save_everystep::Bool | ||
| 10 | save_idxs::SIX | ||
| 11 | dense::Bool | ||
| 12 | timeseries_errors::Bool | ||
| 13 | dense_errors::Bool | ||
| 14 | save_on::Bool | ||
| 15 | save_end::Bool | ||
| 16 | callback::CType | ||
| 17 | abstol::abstolType | ||
| 18 | reltol::reltolType | ||
| 19 | verbose::Bool | ||
| 20 | advance_to_tstop::Bool | ||
| 21 | stop_at_next_tstop::Bool | ||
| 22 | progress::Bool | ||
| 23 | progress_steps::Int | ||
| 24 | progress_name::String | ||
| 25 | progress_message::F5 | ||
| 26 | progress_id::Symbol | ||
| 27 | maxiters::Int | ||
| 28 | end | ||
| 29 | |||
| 30 | abstract type AbstractSundialsIntegrator{algType} <: | ||
| 31 | DiffEqBase.AbstractODEIntegrator{algType, true, Vector{Float64}, Float64} end | ||
| 32 | |||
| 33 | mutable struct CVODEIntegrator{N, | ||
| 34 | pType, | ||
| 35 | solType, | ||
| 36 | algType, | ||
| 37 | fType, | ||
| 38 | UFType, | ||
| 39 | JType, | ||
| 40 | oType, | ||
| 41 | LStype, | ||
| 42 | Atype, | ||
| 43 | CallbackCacheType} <: AbstractSundialsIntegrator{algType} | ||
| 44 | u::Array{Float64, N} | ||
| 45 | u_nvec::NVector | ||
| 46 | p::pType | ||
| 47 | t::Float64 | ||
| 48 | tprev::Float64 | ||
| 49 | mem::Handle{CVODEMem} | ||
| 50 | LS::LStype | ||
| 51 | A::Atype | ||
| 52 | sol::solType | ||
| 53 | alg::algType | ||
| 54 | f::fType | ||
| 55 | userfun::UFType | ||
| 56 | jac::JType | ||
| 57 | opts::oType | ||
| 58 | tout::Vector{Float64} | ||
| 59 | tdir::Float64 | ||
| 60 | u_modified::Bool | ||
| 61 | tmp::Array{Float64, N} | ||
| 62 | uprev::Array{Float64, N} | ||
| 63 | flag::Cint | ||
| 64 | just_hit_tstop::Bool | ||
| 65 | event_last_time::Int | ||
| 66 | vector_event_last_time::Int | ||
| 67 | callback_cache::CallbackCacheType | ||
| 68 | last_event_error::Float64 | ||
| 69 | end | ||
| 70 | |||
| 71 | function (integrator::CVODEIntegrator)(t::Number, | ||
| 72 | deriv::Type{Val{T}} = Val{0}; | ||
| 73 | idxs = nothing) where {T} | ||
| 74 | out = similar(integrator.u) | ||
| 75 | integrator.flag = @checkflag CVodeGetDky(integrator.mem, t, Cint(T), vec(out)) | ||
| 76 | return idxs === nothing ? out : out[idxs] | ||
| 77 | end | ||
| 78 | |||
| 79 | function (integrator::CVODEIntegrator)(out, | ||
| 80 | t::Number, | ||
| 81 | deriv::Type{Val{T}} = Val{0}; | ||
| 82 | idxs = nothing) where {T} | ||
| 83 | integrator.flag = @checkflag CVodeGetDky(integrator.mem, t, Cint(T), vec(out)) | ||
| 84 | return idxs === nothing ? out : @view out[idxs] | ||
| 85 | end | ||
| 86 | |||
| 87 | mutable struct ARKODEIntegrator{N, | ||
| 88 | pType, | ||
| 89 | solType, | ||
| 90 | algType, | ||
| 91 | fType, | ||
| 92 | UFType, | ||
| 93 | JType, | ||
| 94 | oType, | ||
| 95 | LStype, | ||
| 96 | Atype, | ||
| 97 | MLStype, | ||
| 98 | Mtype, | ||
| 99 | CallbackCacheType} <: AbstractSundialsIntegrator{ARKODE} | ||
| 100 | u::Array{Float64, N} | ||
| 101 | u_nvec::NVector | ||
| 102 | p::pType | ||
| 103 | t::Float64 | ||
| 104 | tprev::Float64 | ||
| 105 | mem::Handle{ARKStepMem} | ||
| 106 | LS::LStype | ||
| 107 | A::Atype | ||
| 108 | MLS::MLStype | ||
| 109 | M::Mtype | ||
| 110 | sol::solType | ||
| 111 | alg::algType | ||
| 112 | f::fType | ||
| 113 | userfun::UFType | ||
| 114 | jac::JType | ||
| 115 | opts::oType | ||
| 116 | tout::Vector{Float64} | ||
| 117 | tdir::Float64 | ||
| 118 | u_modified::Bool | ||
| 119 | tmp::Array{Float64, N} | ||
| 120 | uprev::Array{Float64, N} | ||
| 121 | flag::Cint | ||
| 122 | just_hit_tstop::Bool | ||
| 123 | event_last_time::Int | ||
| 124 | vector_event_last_time::Int | ||
| 125 | callback_cache::CallbackCacheType | ||
| 126 | last_event_error::Float64 | ||
| 127 | end | ||
| 128 | |||
| 129 | function (integrator::ARKODEIntegrator)(t::Number, | ||
| 130 | deriv::Type{Val{T}} = Val{0}; | ||
| 131 | idxs = nothing) where {T} | ||
| 132 | out = similar(integrator.u) | ||
| 133 | integrator.flag = @checkflag ARKStepGetDky(integrator.mem, t, Cint(T), vec(out)) | ||
| 134 | return idxs === nothing ? out : out[idxs] | ||
| 135 | end | ||
| 136 | |||
| 137 | function (integrator::ARKODEIntegrator)(out, | ||
| 138 | t::Number, | ||
| 139 | deriv::Type{Val{T}} = Val{0}; | ||
| 140 | idxs = nothing) where {T} | ||
| 141 | integrator.flag = @checkflag ARKStepGetDky(integrator.mem, t, Cint(T), vec(out)) | ||
| 142 | return idxs === nothing ? out : @view out[idxs] | ||
| 143 | end | ||
| 144 | |||
| 145 | mutable struct IDAIntegrator{N, | ||
| 146 | pType, | ||
| 147 | solType, | ||
| 148 | algType, | ||
| 149 | fType, | ||
| 150 | UFType, | ||
| 151 | JType, | ||
| 152 | oType, | ||
| 153 | LStype, | ||
| 154 | Atype, | ||
| 155 | CallbackCacheType, | ||
| 156 | IA} <: AbstractSundialsIntegrator{IDA} | ||
| 157 | u::Array{Float64, N} | ||
| 158 | du::Array{Float64, N} | ||
| 159 | p::pType | ||
| 160 | t::Float64 | ||
| 161 | tprev::Float64 | ||
| 162 | mem::Handle{IDAMem} | ||
| 163 | LS::LStype | ||
| 164 | A::Atype | ||
| 165 | sol::solType | ||
| 166 | alg::algType | ||
| 167 | f::fType | ||
| 168 | userfun::UFType | ||
| 169 | jac::JType | ||
| 170 | opts::oType | ||
| 171 | tout::Vector{Float64} | ||
| 172 | tdir::Float64 | ||
| 173 | u_modified::Bool | ||
| 174 | tmp::Array{Float64, N} | ||
| 175 | uprev::Array{Float64, N} | ||
| 176 | flag::Cint | ||
| 177 | iter::Int | ||
| 178 | just_hit_tstop::Bool | ||
| 179 | event_last_time::Int | ||
| 180 | vector_event_last_time::Int | ||
| 181 | callback_cache::CallbackCacheType | ||
| 182 | last_event_error::Float64 | ||
| 183 | u_nvec::NVector | ||
| 184 | du_nvec::NVector | ||
| 185 | initializealg::IA | ||
| 186 | end | ||
| 187 | |||
| 188 | function (integrator::IDAIntegrator)(t::Number, | ||
| 189 | deriv::Type{Val{T}} = Val{0}; | ||
| 190 | idxs = nothing) where {T} | ||
| 191 | out = similar(integrator.u) | ||
| 192 | integrator.flag = @checkflag IDAGetDky(integrator.mem, t, Cint(T), vec(out)) | ||
| 193 | return idxs === nothing ? out : out[idxs] | ||
| 194 | end | ||
| 195 | |||
| 196 | function (integrator::IDAIntegrator)(out, | ||
| 197 | t::Number, | ||
| 198 | deriv::Type{Val{T}} = Val{0}; | ||
| 199 | idxs = nothing) where {T} | ||
| 200 | integrator.flag = @checkflag IDAGetDky(integrator.mem, t, Cint(T), vec(out)) | ||
| 201 | return idxs === nothing ? out : @view out[idxs] | ||
| 202 | 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 | |||
| 210 | |||
| 211 | ### Error check (retcode) | ||
| 212 | |||
| 213 | function DiffEqBase.check_error(integrator::AbstractSundialsIntegrator) | ||
| 214 | interpret_sundials_retcode(integrator.flag) | ||
| 215 | end | ||
| 216 | |||
| 217 | DiffEqBase.postamble!(integrator::AbstractSundialsIntegrator) = nothing | ||
| 218 | # No-op postamble! to make DiffEqBase.check_error! (and hence iterator interface | ||
| 219 | # implemented in DiffEqBase) work. | ||
| 220 | |||
| 221 | ### Iterator interface | ||
| 222 | |||
| 223 | @inline function DiffEqBase.step!(integrator::AbstractSundialsIntegrator) | ||
| 224 | if integrator.opts.advance_to_tstop | ||
| 225 | # The call to first is an overload of Base.first implemented in DataStructures | ||
| 226 | while integrator.tdir * (integrator.t - first(integrator.opts.tstops)) < -1e6eps() | ||
| 227 | tstop = first(integrator.opts.tstops) | ||
| 228 | set_stop_time(integrator, tstop) | ||
| 229 | integrator.tprev = integrator.t | ||
| 230 | if !(integrator.opts.callback.continuous_callbacks isa Tuple{}) | ||
| 231 | integrator.uprev .= integrator.u | ||
| 232 | end | ||
| 233 | solver_step(integrator, tstop) | ||
| 234 | integrator.t = first(integrator.tout) | ||
| 235 | DiffEqBase.check_error!(integrator) != ReturnCode.Success && return | ||
| 236 | handle_callbacks!(integrator) | ||
| 237 | DiffEqBase.check_error!(integrator) != ReturnCode.Success && return | ||
| 238 | end | ||
| 239 | else | ||
| 240 | integrator.tprev = integrator.t | ||
| 241 | if !(integrator.opts.callback.continuous_callbacks isa Tuple{}) | ||
| 242 | integrator.uprev .= integrator.u | ||
| 243 | end | ||
| 244 | if !isempty(integrator.opts.tstops) | ||
| 245 | tstop = first(integrator.opts.tstops) | ||
| 246 | set_stop_time(integrator, tstop) | ||
| 247 | 58 (100 %) |
58 (100 %)
samples spent calling
solver_step
solver_step(integrator, tstop)
|
|
| 248 | else | ||
| 249 | solver_step(integrator, 1.0) # fake tstop | ||
| 250 | end | ||
| 251 | integrator.t = first(integrator.tout) | ||
| 252 | DiffEqBase.check_error!(integrator) != ReturnCode.Success && return | ||
| 253 | handle_callbacks!(integrator) | ||
| 254 | DiffEqBase.check_error!(integrator) != ReturnCode.Success && return | ||
| 255 | end | ||
| 256 | handle_tstop!(integrator) | ||
| 257 | nothing | ||
| 258 | end |