Skip to content

Commit

Permalink
fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Uziel Linares committed Apr 18, 2021
1 parent 87f3346 commit 44ceef8
Showing 1 changed file with 95 additions and 9 deletions.
104 changes: 95 additions & 9 deletions test/validated_integ.jl
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,6 @@ interval_rand(X::IntervalBox) = interval_rand.(X)
normalized_box = IntervalBox(-1 .. 1, Val(orderQ))

tTM, qv, qTM = validated_integ(falling_ball!, X0, tini, tend, orderQ, orderT, abstol)
tTM, qv, qTM = validated_integ2(falling_ball!, q0, δq0,
tini, tend, orderQ, orderT, abstol)

@test length(qv) == length(qTM[1, :]) == length(tTM)
@test length(tTM) < 501
Expand All @@ -56,18 +54,72 @@ interval_rand(X::IntervalBox) = interval_rand.(X)
tTM2, qv2, qTM2 = validated_integ(falling_ball!, X0tm, tini, tend, orderQ, orderT, abstol)
@test all(iszero, (qTM - qTM2))

tTM, qv, qTM = validated_integ2(falling_ball!, q0, δq0, tini, tend,
orderQ, orderT, abstol)
@taylorize function x_square(dx, x, p, t)
dx[1] = x[1]^2
nothing
end

exactsol(t, x0) = x0[1] / (1 - x0[1] * t)

tini, tend = 0., 0.45
abstol = 1e-15
orderQ = 5
orderT = 20
q0 = [2.]
δq0 = IntervalBox(-0.1 .. 0.1, Val(1))
X0 = IntervalBox(q0 .+ δq0)
ξ = set_variables("ξₓ", numvars=1, order=2*orderQ)

tTM, qv, qTM = validated_integ(x_square, X0, tini, tend, orderQ, orderT, abstol)

@test length(qv) == length(qTM[1, :]) == length(tTM)
@test length(tTM) < 501
normalized_box = IntervalBox(-1 .. 1, Val(1))

for n = 2:length(tTM)
for it = 1:10
δt = interval_rand(domain(qTM[1, n]))
q0ξ = interval_rand(δq0)
q = evaluate.(evaluate(qTM[:, n], δt), (normalized_box,))
@test all(exactsol(tTM[n-1] + δt, tini, q0 .+ q0ξ) .∈ q)
q = evaluate.(evaluate.(qTM[:, n], δt), (normalized_box,))
@test all(exactsol(tTM[n-1]+δt, q0 .+ q0ξ) .∈ q)
end
end

end

@testset "Forward integration for validated_integ2" begin
@taylorize function falling_ball!(dx, x, p, t)
dx[1] = x[2]
dx[2] = -one(x[1])
nothing
end
exactsol(t, t0, x0) =
(x0[1] + x0[2]*(t-t0) - 0.5*(t-t0)^2, x0[2] - (t-t0))

# Initial conditions
tini, tend = 0.0, 10.0
q0 = [10.0, 0.0]
δq0 = IntervalBox(-0.25 .. 0.25, 2)

# Parameters
abstol = 1e-20
orderQ = 2
orderT = 4
ξ = set_variables("ξₓ ξᵥ", order=2*orderQ, numvars=length(q0))
normalized_box = IntervalBox(-1 .. 1, Val(orderQ))

tTM, qv, qTM = validated_integ2(falling_ball!, q0, δq0,
tini, tend, orderQ, orderT, abstol)

@test length(qv) == length(qTM[1, :]) == length(tTM)
@test length(tTM) < 501

for n = 2:length(tTM)
for it = 1:10
δt = interval_rand(domain(qTM[1,n]))
q0ξ = interval_rand(δq0)
q = evaluate.(evaluate.(qTM[:,n], δt), (normalized_box,))
@test all(exactsol(tTM[n-1]+δt, tini, q0 .+ q0ξ) .∈ q)
end
end

Expand All @@ -85,7 +137,6 @@ interval_rand(X::IntervalBox) = interval_rand.(X)
q0 = [2.]
δq0 = IntervalBox(-0.1 .. 0.1, Val(1))
ξ = set_variables("ξₓ", numvars=1, order=2*orderQ)
# tTM, qv, qTM = validated_integ(x_square, q0, δq0, tini, tend, orderQ, orderT, abstol)
tTM, qv, qTM = validated_integ2(x_square, q0, δq0, tini, tend, orderQ, orderT, abstol)

@test length(qv) == length(qTM[1, :]) == length(tTM)
Expand All @@ -103,6 +154,7 @@ interval_rand(X::IntervalBox) = interval_rand.(X)

end


@testset "Backward integration" begin
@taylorize function falling_ball!(dx, x, p, t)
dx[1] = x[2]
Expand All @@ -125,8 +177,6 @@ interval_rand(X::IntervalBox) = interval_rand.(X)
normalized_box = IntervalBox(-1 .. 1, Val(orderQ))

tTM, qv, qTM = validated_integ(falling_ball!, X0, tini, tend, orderQ, orderT, abstol)
tTM, qv, qTM = validated_integ2(falling_ball!, q0, δq0,
tini, tend, orderQ, orderT, abstol)

@test length(qv) == length(qTM[1, :]) == length(tTM)
@test length(tTM) < 501
Expand All @@ -146,4 +196,40 @@ interval_rand(X::IntervalBox) = interval_rand.(X)
tTM2, qv2, qTM2 = validated_integ(falling_ball!, X0tm, tini, tend, orderQ, orderT, abstol)
@test all(iszero, (qTM - qTM2))
end

@testset "Backward integration for validated_integ2" begin
@taylorize function falling_ball!(dx, x, p, t)
dx[1] = x[2]
dx[2] = -one(x[1])
nothing
end
exactsol(t, t0, x0) = (x0[1] + x0[2]*(t-t0) - 0.5*(t-t0)^2, x0[2] - (t-t0))

# Initial conditions
tini, tend = 10.0, 0.0
q0 = [10.0, 0.0]
δq0 = IntervalBox(-0.25 .. 0.25, 2)

# Parameters
abstol = 1e-20
orderQ = 2
orderT = 4
ξ = set_variables("ξₓ ξᵥ", order=2*orderQ, numvars=length(q0))
normalized_box = IntervalBox(-1 .. 1, Val(orderQ))

tTM, qv, qTM = validated_integ2(falling_ball!, q0, δq0,
tini, tend, orderQ, orderT, abstol)

@test length(qv) == length(qTM[1, :]) == length(tTM)
@test length(tTM) < 501

for n = 2:length(tTM)
for it = 1:10
δt = interval_rand(domain(qTM[1,n]))
q0ξ = interval_rand(δq0)
q = evaluate.(evaluate.(qTM[:,n], δt), (normalized_box,))
@test all(exactsol(tTM[n-1]+δt, tini, q0 .+ q0ξ) .∈ q)
end
end
end
end

0 comments on commit 44ceef8

Please sign in to comment.