Skip to content

Commit 9b85df7

Browse files
Merge pull request #470 from SciML/Fix-integrating-extrapolation-of-SmoothedConstantInterpolation
Fix + test Integrating `SmoothedConstantInterpolation` without smoothing
2 parents 36b0dbe + 593fcf9 commit 9b85df7

File tree

5 files changed

+20
-14
lines changed

5 files changed

+20
-14
lines changed

docs/make.jl

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,4 @@ makedocs(modules = [DataInterpolations],
2626
"Inverting Integrals" => "inverting_integrals.md"
2727
])
2828

29-
30-
3129
deploydocs(repo = "github.com/SciML/DataInterpolations.jl"; push_preview = true)

src/integrals.jl

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -142,16 +142,18 @@ function _extrapolate_integral_right(A::SmoothedConstantInterpolation, t)
142142
elseif A.extrapolation_right in (
143143
ExtrapolationType.Constant, ExtrapolationType.Extension)
144144
d = min(A.t[end] - A.t[end - 1], 2A.d_max) / 2
145-
c = (A.u[end] - A.u[end - 1]) / 2
146-
147-
Δt_transition = min(t - A.t[end], d)
148145
Δt_constant = max(0, t - A.t[end] - d)
149-
out = Δt_transition * A.u[end - 1] -
150-
c *
151-
(((Δt_transition / d)^3) / (3 / d) - ((Δt_transition^2) / d) -
152-
Δt_transition) +
153-
Δt_constant * A.u[end]
154-
146+
out = Δt_constant * A.u[end]
147+
148+
if !iszero(d)
149+
c = (A.u[end] - A.u[end - 1]) / 2
150+
Δt_transition = min(t - A.t[end], d)
151+
out += Δt_transition * A.u[end - 1] -
152+
c *
153+
(((Δt_transition / d)^3) / (3 / d) - ((Δt_transition^2) / d) -
154+
Δt_transition)
155+
end
156+
out
155157
elseif extrapolation_right == ExtrapolationType.Linear
156158
slope = derivative(A, last(A.t))
157159
Δt = t - last(A.t)

test/integral_tests.jl

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,10 @@ end
9595
SmoothedConstantInterpolation(u, t; d_max), first(t), last(t))
9696
for d_max in 0.0:0.1:1.0]
9797
@test all(I_smoothed .≈ I_ref)
98+
99+
A = SmoothedConstantInterpolation(
100+
u, t; extrapolation = ExtrapolationType.Constant, d_max = 0)
101+
@test DataInterpolations.integral(A, 5.0, 6.0) == 16.0
98102
end
99103

100104
@testset "QuadraticInterpolation" begin

test/interpolation_tests.jl

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1081,15 +1081,17 @@ end
10811081
u2 = [[u[i], u[i] + 1] for i in eachindex(u)]
10821082
du2 = [[du[i], du[i]] for i in eachindex(du)]
10831083
ddu2 = [[ddu[i], ddu[i]] for i in eachindex(ddu)]
1084-
A2 = QuinticHermiteSpline(ddu2, du2, u2, t; extrapolation = ExtrapolationType.Extension)
1084+
A2 = QuinticHermiteSpline(
1085+
ddu2, du2, u2, t; extrapolation = ExtrapolationType.Extension)
10851086
@test u2 A2.(t)
10861087
@test A2(100.0) repeat([10.107996], 2) + [0, 1] rtol=1e-5
10871088
@test A2(300.0) repeat([11.364162], 2) + [0, 1] rtol=1e-5
10881089
# Test allocation-free interpolation with Vector{StaticArrays.SVector}
10891090
u2_s = [convert(SVector{length(u2[1])}, i) for i in u2]
10901091
du2_s = [convert(SVector{length(du2[1])}, i) for i in du2]
10911092
ddu2_s = [convert(SVector{length(du2[1])}, i) for i in ddu2]
1092-
A2_s = @inferred(QuinticHermiteSpline(ddu2_s, du2_s, u2_s, t; extrapolation = ExtrapolationType.Extension))
1093+
A2_s = @inferred(QuinticHermiteSpline(
1094+
ddu2_s, du2_s, u2_s, t; extrapolation = ExtrapolationType.Extension))
10931095
@test A2_s(100.0) == A2(100.0)
10941096
@test A2_s(300.0) == A2(300.0)
10951097
@test A2_s(0.7) isa SVector{length(u2[1])}

test/runtests.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,4 +38,4 @@ const GROUP = get(ENV, "GROUP", "All")
3838
if GROUP == "QA"
3939
@safetestset "Quality Assurance" include("qa.jl")
4040
end
41-
end
41+
end

0 commit comments

Comments
 (0)