Skip to content

make initial dt nothing #2838

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions lib/OrdinaryDiffEqCore/src/initdt.jl
Original file line number Diff line number Diff line change
Expand Up @@ -103,8 +103,8 @@
still works for matrix-free definitions of the mass matrix.
=#

if prob.f.mass_matrix != I && (!(prob.f isa DynamicalODEFunction) ||
any(mm != I for mm in prob.f.mass_matrix))
if prob.f.mass_matrix !== I && (!(prob.f isa DynamicalODEFunction) ||
any(mm !== I for mm in prob.f.mass_matrix))
Comment on lines -106 to +107
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

todo: undo these

ftmp = zero(f₀)
try
integrator.alg.linsolve(ftmp, copy(prob.f.mass_matrix), f₀, true)
Expand Down
27 changes: 14 additions & 13 deletions lib/OrdinaryDiffEqCore/src/solve.jl
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,7 @@ function SciMLBase.__init(
!default_linear_interpolation(prob, alg),
calck = (callback !== nothing && callback !== CallbackSet()) ||
(dense) || !isempty(saveat), # and no dense output
dt = isdiscretealg(alg) && isempty(tstops) ?
eltype(prob.tspan)(1) : eltype(prob.tspan)(0),
dt = nothing,
dtmin = eltype(prob.tspan)(0),
dtmax = eltype(prob.tspan)((prob.tspan[end] - prob.tspan[1])),
force_dtmin = false,
Expand Down Expand Up @@ -127,7 +126,7 @@ function SciMLBase.__init(
if (((!(alg isa OrdinaryDiffEqAdaptiveAlgorithm) &&
!(alg isa OrdinaryDiffEqCompositeAlgorithm) &&
!(alg isa DAEAlgorithm)) || !adaptive || !isadaptive(alg)) &&
dt == tType(0) && isempty(tstops)) && dt_required(alg)
isnothing(dt) && isempty(tstops)) && dt_required(alg)
throw(ArgumentError("Fixed timestep methods require a choice of dt or choosing the tstops"))
end
if !isadaptive(alg) && adaptive
Expand Down Expand Up @@ -343,7 +342,7 @@ function SciMLBase.__init(
alg_choice = _alg isa CompositeAlgorithm ? Int[] : nothing

if (!adaptive || !isadaptive(_alg)) && save_everystep && tspan[2] - tspan[1] != Inf
if dt == 0
if isnothing(dt)
steps = length(tstops)
else
# For fixed dt, the only time dtmin makes sense is if it's smaller than eps().
Expand Down Expand Up @@ -400,14 +399,16 @@ function SciMLBase.__init(
else
uprev2 = uprev
end


_dt = isdiscretealg(alg) && isempty(tstops) ?
eltype(prob.tspan)(1) : eltype(prob.tspan)(0)
if prob isa DAEProblem
cache = alg_cache(_alg, du, u, res_prototype, rate_prototype, uEltypeNoUnits,
uBottomEltypeNoUnits, tTypeNoUnits, uprev, uprev2, f, t, dt,
uBottomEltypeNoUnits, tTypeNoUnits, uprev, uprev2, f, t, _dt,
reltol_internal, p, calck, Val(isinplace(prob)))
else
cache = alg_cache(_alg, u, rate_prototype, uEltypeNoUnits, uBottomEltypeNoUnits,
tTypeNoUnits, uprev, uprev2, f, t, dt, reltol_internal, p, calck,
tTypeNoUnits, uprev, uprev2, f, t, _dt, reltol_internal, p, calck,
Val(isinplace(prob)))
end

Expand Down Expand Up @@ -494,8 +495,8 @@ function SciMLBase.__init(
# we don't want to differentiate through eigenvalue estimation
eigen_est = inv(one(tType))
tprev = t
dtcache = tType(dt)
dtpropose = tType(dt)
dtcache = tType(_dt)
dtpropose = tType(_dt)
iter = 0
kshortsize = 0
reeval_fsal = false
Expand Down Expand Up @@ -530,7 +531,7 @@ function SciMLBase.__init(
typeof(opts), typeof(fsalfirst),
typeof(last_event_error), typeof(callback_cache),
typeof(initializealg), typeof(differential_vars)}(
sol, u, du, k, t, tType(dt), f, p,
sol, u, du, k, t, tType(_dt), f, p,
uprev, uprev2, duprev, tprev,
_alg, dtcache, dtchangeable,
dtpropose, tdir, eigen_est, EEst,
Expand Down Expand Up @@ -596,7 +597,7 @@ function SciMLBase.__init(
end
end

handle_dt!(integrator)
handle_dt!(integrator, dt)
integrator
end

Expand Down Expand Up @@ -632,8 +633,8 @@ end

# Helpers

function handle_dt!(integrator)
if iszero(integrator.dt) && integrator.opts.adaptive
function handle_dt!(integrator, dt)
if isnothing(dt) && integrator.opts.adaptive
auto_dt_reset!(integrator)
if sign(integrator.dt) != integrator.tdir && !iszero(integrator.dt) &&
!isnan(integrator.dt)
Expand Down
Loading