Skip to content

Commit

Permalink
Handle empty solution in HistoryFunction correctly (#290)
Browse files Browse the repository at this point in the history
  • Loading branch information
devmotion authored Apr 24, 2024
1 parent c78ec37 commit 43201e7
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 18 deletions.
2 changes: 1 addition & 1 deletion Project.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name = "DelayDiffEq"
uuid = "bcd4f6db-9728-5f36-b5f7-82caef46ccdb"
authors = ["Chris Rackauckas <[email protected]>"]
version = "5.47.2"
version = "5.47.3"

[deps]
ArrayInterface = "4fba245c-0d91-5ea0-9b3e-6abc04ee57a9"
Expand Down
42 changes: 25 additions & 17 deletions src/history_function.jl
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
Wrap history function `h` and integrator `integrator` to create a common
interface for retrieving values at any time point with varying accuracy.
Before the initial time point of the solution of the `integrator` values are calculated by
Before the initial time point of the `integrator` values are calculated by
history function `h`, for time points up to the final time point of the solution
interpolated values of the solution are returned, and after the final time point an inter-
or extrapolation of the current state of the `integrator` is retrieved.
Expand All @@ -24,7 +24,7 @@ function (f::HistoryFunction)(p, t, ::Type{Val{deriv}} = Val{0};

tdir_t = tdir * t

@inbounds if tdir_t < tdir * sol.t[1]
if tdir_t < tdir * sol.prob.tspan[1]
if deriv == 0 && idxs === nothing
return f.h(p, t)
elseif idxs === nothing
Expand All @@ -36,14 +36,18 @@ function (f::HistoryFunction)(p, t, ::Type{Val{deriv}} = Val{0};
end
end

tdir_solt = tdir * sol.t[end]
if tdir_t <= tdir_solt
return sol.interp(t, idxs, Val{deriv}, p)
end
if !isempty(sol.t)
tdir_solt = tdir * sol.t[end]
if tdir_t <= tdir_solt
return sol.interp(t, idxs, Val{deriv}, p)
end

# history function is evaluated at time point past the final time point of
# the current solution
if tdir_t - tdir_solt > 10 * eps(tdir_t)
# history function is evaluated at time point past the final time point of
# the current solution
if tdir_t - tdir_solt > 10 * eps(tdir_t)
f.isout = true
end
else
f.isout = true
end

Expand All @@ -62,7 +66,7 @@ function (f::HistoryFunction)(val, p, t, ::Type{Val{deriv}} = Val{0};

tdir_t = tdir * t

@inbounds if tdir_t < tdir * sol.t[1]
if tdir_t < tdir * sol.prob.tspan[1]
if deriv == 0 && idxs === nothing
return f.h(val, p, t)
elseif idxs === nothing
Expand All @@ -74,14 +78,18 @@ function (f::HistoryFunction)(val, p, t, ::Type{Val{deriv}} = Val{0};
end
end

tdir_solt = tdir * sol.t[end]
if tdir_t <= tdir_solt
return sol.interp(val, t, idxs, Val{deriv}, p)
end
if !isempty(sol.t)
tdir_solt = tdir * sol.t[end]
if tdir_t <= tdir_solt
return sol.interp(val, t, idxs, Val{deriv}, p)
end

# history function is evaluated at time point past the final time point of
# the current solution
if tdir_t - tdir_solt > 10 * eps(tdir_t)
# history function is evaluated at time point past the final time point of
# the current solution
if tdir_t - tdir_solt > 10 * eps(tdir_t)
f.isout = true
end
else
f.isout = true
end

Expand Down

2 comments on commit 43201e7

@devmotion
Copy link
Member Author

Choose a reason for hiding this comment

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

@JuliaRegistrator
Copy link

Choose a reason for hiding this comment

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

Registration pull request created: JuliaRegistries/General/105513

Tip: Release Notes

Did you know you can add release notes too? Just add markdown formatted text underneath the comment after the text
"Release notes:" and it will be added to the registry PR, and if TagBot is installed it will also be added to the
release that TagBot creates. i.e.

@JuliaRegistrator register

Release notes:

## Breaking changes

- blah

To add them here just re-invoke and the PR will be updated.

Tagging

After the above pull request is merged, it is recommended that a tag is created on this repository for the registered package version.

This will be done automatically if the Julia TagBot GitHub Action is installed, or can be done manually through the github interface, or via:

git tag -a v5.47.3 -m "<description of version>" 43201e7ac1169ab0c08bc3a41879e4445ce2c827
git push origin v5.47.3

Please sign in to comment.