Skip to content

implement get_tmp_cache #113

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Jul 28, 2024
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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.2.0"
version = "0.2.1"

[deps]
FastBroadcast = "7034ab61-46d4-4ed7-9d0f-46aef9175898"
Expand Down
3 changes: 2 additions & 1 deletion src/PositiveIntegrators.jl
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,8 @@ using OrdinaryDiffEq: @cache,
recursivefill!, _vec, wrapprecs, dolinsolve
import OrdinaryDiffEq: alg_order, isfsal,
calculate_residuals, calculate_residuals!,
alg_cache, initialize!, perform_step!,
alg_cache, get_tmp_cache,
initialize!, perform_step!,
_ode_interpolant, _ode_interpolant!

# 2. Export functionality defining the public API
Expand Down
9 changes: 9 additions & 0 deletions src/mprk.jl
Original file line number Diff line number Diff line change
Expand Up @@ -337,6 +337,8 @@ struct MPEConservativeCache{PType, uType, tabType, F} <: OrdinaryDiffEqMutableCa
linsolve::F
end

get_tmp_cache(integrator, ::MPE, cache::OrdinaryDiffEqMutableCache) = (cache.σ,)

# In-place
function alg_cache(alg::MPE, u, rate_prototype, ::Type{uEltypeNoUnits},
::Type{uBottomEltypeNoUnits}, ::Type{tTypeNoUnits},
Expand Down Expand Up @@ -638,6 +640,8 @@ struct MPRK22ConservativeCache{uType, PType, tabType, F} <:
linsolve::F
end

get_tmp_cache(integrator, ::MPRK22, cache::OrdinaryDiffEqMutableCache) = (cache.σ,)

# In-place
function alg_cache(alg::MPRK22, u, rate_prototype, ::Type{uEltypeNoUnits},
::Type{uBottomEltypeNoUnits}, ::Type{tTypeNoUnits},
Expand Down Expand Up @@ -1218,6 +1222,11 @@ struct MPRK43ConservativeCache{uType, PType, tabType, F} <: OrdinaryDiffEqMutabl
linsolve::F
end

function get_tmp_cache(integrator, ::Union{MPRK43I, MPRK43II},
cache::OrdinaryDiffEqMutableCache)
(cache.σ,)
end

# In-place
function alg_cache(alg::Union{MPRK43I, MPRK43II}, u, rate_prototype, ::Type{uEltypeNoUnits},
::Type{uBottomEltypeNoUnits}, ::Type{tTypeNoUnits},
Expand Down
4 changes: 4 additions & 0 deletions src/sspmprk.jl
Original file line number Diff line number Diff line change
Expand Up @@ -223,6 +223,8 @@ struct SSPMPRK22ConservativeCache{uType, PType, tabType, F} <:
linsolve::F
end

get_tmp_cache(integrator, ::SSPMPRK22, cache::OrdinaryDiffEqMutableCache) = (cache.σ,)

# In-place
function alg_cache(alg::SSPMPRK22, u, rate_prototype, ::Type{uEltypeNoUnits},
::Type{uBottomEltypeNoUnits}, ::Type{tTypeNoUnits},
Expand Down Expand Up @@ -734,6 +736,8 @@ struct SSPMPRK43ConservativeCache{uType, PType, tabType, F} <: OrdinaryDiffEqMut
linsolve::F
end

get_tmp_cache(integrator, ::SSPMPRK43, cache::OrdinaryDiffEqMutableCache) = (cache.σ,)

# In-place
function alg_cache(alg::SSPMPRK43, u, rate_prototype, ::Type{uEltypeNoUnits},
::Type{uBottomEltypeNoUnits}, ::Type{tTypeNoUnits},
Expand Down
18 changes: 15 additions & 3 deletions test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -1198,7 +1198,7 @@ end
end
end

# Here we check that the type of p_prototype actually
# Here we check that the type of p_prototype actually
# defines the types of the Ps inside the algorithm caches.
# We test sparse, tridiagonal, and dense matrices.
@testset "Prototype type check" begin
Expand Down Expand Up @@ -1246,7 +1246,7 @@ end
p_prototype = P_dense)
prob_sparse = ConservativePDSProblem(prod_sparse!, u0, tspan;
p_prototype = P_sparse)
## nonconservative PDS
## nonconservative PDS
prob_default2 = PDSProblem(prod_dense!, dest!, u0, tspan)
prob_tridiagonal2 = PDSProblem(prod_tridiagonal!, dest!, u0, tspan;
p_prototype = P_tridiagonal)
Expand All @@ -1262,7 +1262,19 @@ end
for prob in (prob_default, prob_tridiagonal, prob_dense, prob_sparse,
prob_default2,
prob_tridiagonal2, prob_dense2, prob_sparse2)
solve(prob, alg; dt, adaptive = false)
sol1 = solve(prob, alg; dt, adaptive = false)

# test get_tmp_cache and integrator interface - modifying
# values from the cache should not changes the final results
integrator = init(prob, alg; dt, adaptive = false)
step!(integrator)
cache = @inferred get_tmp_cache(integrator)
@test !isempty(cache)
tmp = first(cache)
fill!(tmp, NaN)
sol2 = solve!(integrator)
@test sol1.t ≈ sol2.t
@test sol1.u ≈ sol2.u
end
end
end
Expand Down
Loading