Skip to content

Commit cb10cfd

Browse files
authored
Merge pull request #86 from SKopecz/SK/SSPMPRK
SSPMPRK schemes and small_constant as algorithm field
2 parents 0091819 + bd6cdca commit cb10cfd

File tree

6 files changed

+1475
-229
lines changed

6 files changed

+1475
-229
lines changed

Project.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
name = "PositiveIntegrators"
22
uuid = "d1b20bf0-b083-4985-a874-dc5121669aa5"
33
authors = ["Stefan Kopecz, Hendrik Ranocha, and contributors"]
4-
version = "0.1.14"
4+
version = "0.1.15"
55

66
[deps]
77
FastBroadcast = "7034ab61-46d4-4ed7-9d0f-46aef9175898"

src/PositiveIntegrators.jl

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ export PDSFunction, PDSProblem
4848
export ConservativePDSFunction, ConservativePDSProblem
4949

5050
export MPE, MPRK22, MPRK43I, MPRK43II
51+
export SSPMPRK22, SSPMPRK43
5152

5253
export prob_pds_linmod, prob_pds_linmod_inplace, prob_pds_nonlinmod,
5354
prob_pds_robertson, prob_pds_brusselator, prob_pds_sir,
@@ -61,6 +62,11 @@ include("proddest.jl")
6162
# modified Patankar-Runge-Kutta (MPRK) methods
6263
include("mprk.jl")
6364

65+
# modified Patankar-Runge-Kutta based on the SSP formulation of RK methods (SSPMPRK)
66+
include("sspmprk.jl")
67+
68+
include("interpolation.jl")
69+
6470
# predefined PDS problems
6571
include("PDSProblemLibrary.jl")
6672

src/interpolation.jl

Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
# Linear interpolations
2+
@muladd @inline function linear_interpolant(Θ, dt, u0, u1, idxs::Nothing, T::Type{Val{0}})
3+
Θm1 = (1 - Θ)
4+
@.. broadcast=false Θm1 * u0+Θ * u1
5+
end
6+
7+
@muladd @inline function linear_interpolant(Θ, dt, u0, u1, idxs, T::Type{Val{0}})
8+
Θm1 = (1 - Θ)
9+
@.. broadcast=false Θm1 * u0[idxs]+Θ * u1[idxs]
10+
end
11+
12+
@muladd @inline function linear_interpolant!(out, Θ, dt, u0, u1, idxs::Nothing,
13+
T::Type{Val{0}})
14+
Θm1 = (1 - Θ)
15+
@.. broadcast=false out=Θm1 * u0 + Θ * u1
16+
out
17+
end
18+
19+
@muladd @inline function linear_interpolant!(out, Θ, dt, u0, u1, idxs, T::Type{Val{0}})
20+
Θm1 = (1 - Θ)
21+
@views @.. broadcast=false out=Θm1 * u0[idxs] + Θ * u1[idxs]
22+
out
23+
end
24+
25+
@inline function linear_interpolant(Θ, dt, u0, u1, idxs::Nothing, T::Type{Val{1}})
26+
@.. broadcast=false (u1 - u0)/dt
27+
end
28+
29+
@inline function linear_interpolant(Θ, dt, u0, u1, idxs, T::Type{Val{1}})
30+
@.. broadcast=false (u1[idxs] - u0[idxs])/dt
31+
end
32+
33+
@inline function linear_interpolant!(out, Θ, dt, u0, u1, idxs::Nothing, T::Type{Val{1}})
34+
@.. broadcast=false out=(u1 - u0) / dt
35+
out
36+
end
37+
38+
@inline function linear_interpolant!(out, Θ, dt, u0, u1, idxs, T::Type{Val{1}})
39+
@views @.. broadcast=false out=(u1[idxs] - u0[idxs]) / dt
40+
out
41+
end
42+
43+
#######################################################################################
44+
# interpolation specializations
45+
const MPRKCaches = Union{MPEConstantCache, MPECache, MPEConservativeCache,
46+
MPRK22ConstantCache, MPRK22Cache, MPRK22ConservativeCache,
47+
MPRK43ConstantCache, MPRK43Cache, MPRK43ConservativeCache,
48+
SSPMPRK22ConstantCache, SSPMPRK22Cache, SSPMPRK22ConservativeCache,
49+
SSPMPRK43ConstantCache, SSPMPRK43Cache, SSPMPRK43ConservativeCache}
50+
51+
function interp_summary(::Type{cacheType},
52+
dense::Bool) where {cacheType <: MPRKCaches}
53+
"1st order linear"
54+
end
55+
56+
function _ode_interpolant(Θ, dt, u0, u1, k,
57+
cache::MPRKCaches,
58+
idxs, # Optionally specialize for ::Nothing and others
59+
T::Type{Val{0}},
60+
differential_vars::Nothing)
61+
linear_interpolant(Θ, dt, u0, u1, idxs, T)
62+
end
63+
64+
function _ode_interpolant!(out, Θ, dt, u0, u1, k,
65+
cache::MPRKCaches,
66+
idxs, # Optionally specialize for ::Nothing and others
67+
T::Type{Val{0}},
68+
differential_vars::Nothing)
69+
linear_interpolant!(out, Θ, dt, u0, u1, idxs, T)
70+
end
71+
72+
function _ode_interpolant(Θ, dt, u0, u1, k,
73+
cache::MPRKCaches,
74+
idxs, # Optionally specialize for ::Nothing and others
75+
T::Type{Val{1}},
76+
differential_vars::Nothing)
77+
linear_interpolant(Θ, dt, u0, u1, idxs, T)
78+
end
79+
80+
function _ode_interpolant!(out, Θ, dt, u0, u1, k,
81+
cache::MPRKCaches,
82+
idxs, # Optionally specialize for ::Nothing and others
83+
T::Type{Val{1}},
84+
differential_vars::Nothing)
85+
linear_interpolant!(out, Θ, dt, u0, u1, idxs, T)
86+
end

0 commit comments

Comments
 (0)