Skip to content

Commit

Permalink
more interpolation tests (#70)
Browse files Browse the repository at this point in the history
* test displaying solutions (with interpolations)

* test interpolation with indices

* set version to v0.1.8

* (smoke) tests for first-derivatives

* derivative is not a kwarg

* fix typo

* fix typo
  • Loading branch information
ranocha authored Apr 24, 2024
1 parent 0ee9b69 commit 5319740
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 6 deletions.
2 changes: 1 addition & 1 deletion Project.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name = "PositiveIntegrators"
uuid = "d1b20bf0-b083-4985-a874-dc5121669aa5"
authors = ["Stefan Kopecz, Hendrik Ranocha, and contributors"]
version = "0.1.7"
version = "0.1.8"

[deps]
FastBroadcast = "7034ab61-46d4-4ed7-9d0f-46aef9175898"
Expand Down
56 changes: 51 additions & 5 deletions test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -13,21 +13,35 @@ using LinearSolve: RFLUFactorization, LUFactorization
using Aqua: Aqua

"""
experimental_order_of_convergence(prob, alg, dts, test_times)
experimental_order_of_convergence(prob, alg, dts, test_times;
only_first_index = false)
Solve `prob` with `alg` and fixed time steps taken from `dts`, and compute
the mean error at the times `test_times`.
Return the associated experimental order of convergence.
If `only_first_index == true`, only the first solution component is used
to compute the error.
"""
function experimental_order_of_convergence(prob, alg, dts, test_times)
function experimental_order_of_convergence(prob, alg, dts, test_times;
only_first_index = false)
@assert length(dts) > 1
errors = zeros(eltype(dts), length(dts))
analytic = t -> prob.f.analytic(prob.u0, prob.p, t)

for (i, dt) in enumerate(dts)
sol = solve(prob, alg; dt = dt, adaptive = false)
errors[i] = mean(test_times) do t
norm(sol(t) - analytic(t))
if i == 1
display(sol)
end
if only_first_index
errors[i] = mean(test_times) do t
norm(sol(t; idxs = 1) - first(analytic(t)))
end
else
errors[i] = mean(test_times) do t
norm(sol(t) - analytic(t))
end
end
end

Expand Down Expand Up @@ -381,6 +395,22 @@ const prob_pds_linmod_mvector = ConservativePDSProblem(prob_pds_linmod_inplace.f
]
eoc = experimental_order_of_convergence(prob, alg, dts, test_times)
@test isapprox(eoc, PositiveIntegrators.alg_order(alg); atol = 0.2)
eoc = experimental_order_of_convergence(prob, alg, dts, test_times;
only_first_index = true)
@test isapprox(eoc, PositiveIntegrators.alg_order(alg); atol = 0.2)
end
end

@testset "Interpolation tests" begin
alg = @inferred MPE()
dt = 0.5^6
problems = (prob_pds_linmod, prob_pds_linmod_array,
prob_pds_linmod_mvector, prob_pds_linmod_inplace)
for prob in problems
sol = solve(prob, alg; dt, adaptive = false)
# check derivative of interpolation
@test_nowarn sol(0.5, Val{1})
@test_nowarn sol(0.5, Val{1}; idxs = 1)
end
end
end
Expand Down Expand Up @@ -469,7 +499,7 @@ const prob_pds_linmod_mvector = ConservativePDSProblem(prob_pds_linmod_inplace.f
problems = (prob_pds_linmod, prob_pds_linmod_array,
prob_pds_linmod_mvector, prob_pds_linmod_inplace)
for alpha in (0.5, 1.0, 2.0), prob in problems
alg = MPRK22(alpha)
alg = @inferred MPRK22(alpha)
eoc = experimental_order_of_convergence(prob, alg, dts)
@test isapprox(eoc, PositiveIntegrators.alg_order(alg); atol = 0.2)

Expand All @@ -479,6 +509,22 @@ const prob_pds_linmod_mvector = ConservativePDSProblem(prob_pds_linmod_inplace.f
]
eoc = experimental_order_of_convergence(prob, alg, dts, test_times)
@test isapprox(eoc, PositiveIntegrators.alg_order(alg); atol = 0.2)
eoc = experimental_order_of_convergence(prob, alg, dts, test_times;
only_first_index = true)
@test isapprox(eoc, PositiveIntegrators.alg_order(alg); atol = 0.2)
end
end

@testset "Interpolation tests" begin
dt = 0.5^6
problems = (prob_pds_linmod, prob_pds_linmod_array,
prob_pds_linmod_mvector, prob_pds_linmod_inplace)
for alpha in (0.5, 1.0, 2.0), prob in problems
alg = @inferred MPRK22(alpha)
sol = solve(prob, alg; dt, adaptive = false)
# check derivative of interpolation
@test_nowarn sol(0.5, Val{1})
@test_nowarn sol(0.5, Val{1}; idxs = 1)
end
end
end
Expand Down

2 comments on commit 5319740

@ranocha
Copy link
Collaborator 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/105561

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 v0.1.8 -m "<description of version>" 531974096e4f6db48edf32a713790c159c9a43cb
git push origin v0.1.8

Please sign in to comment.