Skip to content

Commit

Permalink
Merge pull request #2593 from SciML/ChrisRackauckas-patch-8
Browse files Browse the repository at this point in the history
Create unitfulvalue for compatibility with ForwardDiff removal
  • Loading branch information
ChrisRackauckas authored Feb 9, 2025
2 parents 0591c1f + a434d9c commit fdc43fc
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 4 deletions.
6 changes: 6 additions & 0 deletions lib/OrdinaryDiffEqCore/src/OrdinaryDiffEqCore.jl
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,12 @@ const TryAgain = SlowConvergence
DEFAULT_PRECS(W, du, u, p, t, newW, Plprev, Prprev, solverdata) = nothing, nothing
isdiscretecache(cache) = false

@static if isdefined(DiffEqBase, :unitfulvalue)
unitfulvalue(x) = DiffEqBase.unitfulvalue(x)
else
unitfulvalue(x) = DiffEqBase.ForwardDiff.value(x)
end

include("doc_utils.jl")
include("misc_utils.jl")

Expand Down
8 changes: 4 additions & 4 deletions lib/OrdinaryDiffEqCore/src/solve.jl
Original file line number Diff line number Diff line change
Expand Up @@ -232,11 +232,11 @@ function DiffEqBase.__init(
abstol_internal = false
elseif abstol === nothing
if uBottomEltypeNoUnits == uBottomEltype
abstol_internal = DiffEqBase.ForwardDiff.value(real(convert(uBottomEltype,
abstol_internal = unitfulvalue(real(convert(uBottomEltype,
oneunit(uBottomEltype) *
1 // 10^6)))
else
abstol_internal = DiffEqBase.ForwardDiff.value.(real.(oneunit.(u) .* 1 // 10^6))
abstol_internal = unitfulvalue.(real.(oneunit.(u) .* 1 // 10^6))
end
else
abstol_internal = real.(abstol)
Expand All @@ -246,10 +246,10 @@ function DiffEqBase.__init(
reltol_internal = false
elseif reltol === nothing
if uBottomEltypeNoUnits == uBottomEltype
reltol_internal = DiffEqBase.ForwardDiff.value(real(convert(uBottomEltype,
reltol_internal = unitfulvalue(real(convert(uBottomEltype,
oneunit(uBottomEltype) * 1 // 10^3)))
else
reltol_internal = DiffEqBase.ForwardDiff.value.(real.(oneunit.(u) .* 1 // 10^3))
reltol_internal = unitfulvalue.(real.(oneunit.(u) .* 1 // 10^3))
end
else
reltol_internal = real.(reltol)
Expand Down

0 comments on commit fdc43fc

Please sign in to comment.