Skip to content

Commit 4e974bb

Browse files
Merge pull request #1 from Shreyas-Ekanathan/master
update
2 parents e686a5c + d0b3b06 commit 4e974bb

File tree

7 files changed

+888
-2
lines changed

7 files changed

+888
-2
lines changed

src/OrdinaryDiffEq.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -400,7 +400,7 @@ export ORK256, CarpenterKennedy2N54, SHLDDRK64, HSLDDRK64, DGLDDRK73_C, DGLDDRK8
400400
RDPK3Sp35, RDPK3SpFSAL35, RDPK3Sp49, RDPK3SpFSAL49, RDPK3Sp510, RDPK3SpFSAL510,
401401
KYK2014DGSSPRK_3S2
402402

403-
export RadauIIA3, RadauIIA5
403+
export RadauIIA3, RadauIIA5, RadauIIA7
404404

405405
export ImplicitEuler, ImplicitMidpoint, Trapezoid, TRBDF2, SDIRK2, SDIRK22,
406406
Kvaerno3, KenCarp3, Cash4, Hairer4, Hairer42, SSPSDIRK2, Kvaerno4,

src/alg_utils.jl

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -204,7 +204,7 @@ qmin_default(alg::DP8) = 1 // 3
204204
qmax_default(alg::Union{OrdinaryDiffEqAlgorithm, DAEAlgorithm}) = 10
205205
qmax_default(alg::CompositeAlgorithm) = minimum(qmax_default.(alg.algs))
206206
qmax_default(alg::DP8) = 6
207-
qmax_default(alg::Union{RadauIIA3, RadauIIA5}) = 8
207+
qmax_default(alg::Union{RadauIIA3, RadauIIA5, RadauIIA7}) = 8
208208

209209
function has_chunksize(alg::OrdinaryDiffEqAlgorithm)
210210
return alg isa Union{OrdinaryDiffEqExponentialAlgorithm,
@@ -575,6 +575,7 @@ alg_order(alg::TanYam7) = 7
575575
alg_order(alg::TsitPap8) = 8
576576
alg_order(alg::RadauIIA3) = 3
577577
alg_order(alg::RadauIIA5) = 5
578+
alg_order(alg::RadauIIA7) = 7
578579
alg_order(alg::ImplicitEuler) = 1
579580
alg_order(alg::RKMK2) = 2
580581
alg_order(alg::RKMK4) = 4

src/algorithms.jl

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1709,6 +1709,56 @@ function RadauIIA5(; chunk_size = Val{0}(), autodiff = Val{true}(),
17091709
end
17101710
TruncatedStacktraces.@truncate_stacktrace RadauIIA5
17111711

1712+
"""
1713+
@article{hairer1999stiff,
1714+
title={Stiff differential equations solved by Radau methods},
1715+
author={Hairer, Ernst and Wanner, Gerhard},
1716+
journal={Journal of Computational and Applied Mathematics},
1717+
volume={111},
1718+
number={1-2},
1719+
pages={93--111},
1720+
year={1999},
1721+
publisher={Elsevier}
1722+
}
1723+
1724+
RadauIIA7: Fully-Implicit Runge-Kutta Method
1725+
An A-B-L stable fully implicit Runge-Kutta method with internal tableau complex basis transform for efficiency.
1726+
"""
1727+
struct RadauIIA7{CS, AD, F, P, FDT, ST, CJ, Tol, C1, C2} <:
1728+
OrdinaryDiffEqNewtonAdaptiveAlgorithm{CS, AD, FDT, ST, CJ}
1729+
linsolve::F
1730+
precs::P
1731+
smooth_est::Bool
1732+
extrapolant::Symbol
1733+
κ::Tol
1734+
maxiters::Int
1735+
fast_convergence_cutoff::C1
1736+
new_W_γdt_cutoff::C2
1737+
controller::Symbol
1738+
end
1739+
1740+
function RadauIIA7(; chunk_size = Val{0}(), autodiff = Val{true}(),
1741+
standardtag = Val{true}(), concrete_jac = nothing,
1742+
diff_type = Val{:forward},
1743+
linsolve = nothing, precs = DEFAULT_PRECS,
1744+
extrapolant = :dense, fast_convergence_cutoff = 1 // 5,
1745+
new_W_γdt_cutoff = 1 // 5,
1746+
controller = :Predictive, κ = nothing, maxiters = 10, smooth_est = true)
1747+
RadauIIA7{_unwrap_val(chunk_size), _unwrap_val(autodiff), typeof(linsolve),
1748+
typeof(precs), diff_type, _unwrap_val(standardtag), _unwrap_val(concrete_jac),
1749+
typeof(κ), typeof(fast_convergence_cutoff), typeof(new_W_γdt_cutoff)}(linsolve,
1750+
precs,
1751+
smooth_est,
1752+
extrapolant,
1753+
κ,
1754+
maxiters,
1755+
fast_convergence_cutoff,
1756+
new_W_γdt_cutoff,
1757+
controller)
1758+
end
1759+
TruncatedStacktraces.@truncate_stacktrace RadauIIA7
1760+
1761+
17121762
################################################################################
17131763

17141764
# SDIRK Methods

src/caches/firk_caches.jl

Lines changed: 181 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -273,3 +273,184 @@ function alg_cache(alg::RadauIIA5, u, rate_prototype, ::Type{uEltypeNoUnits},
273273
tmp, atmp, jac_config, linsolve1, linsolve2, rtol, atol, dt, dt,
274274
Convergence, alg.step_limiter!)
275275
end
276+
277+
mutable struct RadauIIA7ConstantCache{F, Tab, Tol, Dt, U, JType} <:
278+
OrdinaryDiffEqConstantCache
279+
uf::F
280+
tab::Tab
281+
κ::Tol
282+
ηold::Tol
283+
iter::Int
284+
cont1::U
285+
cont2::U
286+
cont3::U
287+
dtprev::Dt
288+
W_γdt::Dt
289+
status::NLStatus
290+
J::JType
291+
end
292+
293+
function alg_cache(alg::RadauIIA7, u, rate_prototype, ::Type{uEltypeNoUnits},
294+
::Type{uBottomEltypeNoUnits},
295+
::Type{tTypeNoUnits}, uprev, uprev2, f, t, dt, reltol, p, calck,
296+
::Val{false}) where {uEltypeNoUnits, uBottomEltypeNoUnits, tTypeNoUnits}
297+
uf = UDerivativeWrapper(f, t, p)
298+
uToltype = constvalue(uBottomEltypeNoUnits)
299+
tab = RadauIIA7Tableau(uToltype, constvalue(tTypeNoUnits))
300+
301+
κ = convert(uToltype, 1 // 100)
302+
J = false .* _vec(rate_prototype) .* _vec(rate_prototype)'
303+
304+
RadauIIA7ConstantCache(uf, tab, κ, one(uToltype), 10000, u, u, u, dt, dt,
305+
Convergence, J)
306+
end
307+
308+
mutable struct RadauIIA7Cache{uType, cuType, uNoUnitsType, rateType, JType, W1Type, W2Type,
309+
UF, JC, F1, F2, Tab, Tol, Dt, rTol, aTol} <:
310+
OrdinaryDiffEqMutableCache
311+
u::uType
312+
uprev::uType
313+
z1::uType
314+
z2::uType
315+
z3::uType
316+
z4::uType
317+
z5::uType
318+
w1::uType
319+
w2::uType
320+
w3::uType
321+
w4::uType
322+
w5::uType
323+
dw1::uType
324+
ubuff::uType
325+
dw23::cuType
326+
dw45::cuType
327+
cubuff::cuType
328+
cont1::uType
329+
cont2::uType
330+
cont3::uType
331+
cont4::uType
332+
du1::rateType #why is this here?
333+
fsalfirst::rateType
334+
k::rateType
335+
k2::rateType
336+
k3::rateType
337+
k4::rateType
338+
k5::rateType
339+
fw1::rateType
340+
fw2::rateType
341+
fw3::rateType
342+
fw4::rateType
343+
fw5::rateType
344+
J::JType
345+
W1::W1Type
346+
W2::W2Type # complex
347+
W3::W3Type #CHECK THIS TYPE
348+
uf::UF
349+
tab::Tab
350+
κ::Tol
351+
ηold::Tol
352+
iter::Int
353+
tmp::uType
354+
atmp::uNoUnitsType
355+
jac_config::JC
356+
linsolve1::F1
357+
linsolve2::F2
358+
linsolve3::F2 #CHECK THIS TYPE
359+
rtol::rTol
360+
atol::aTol
361+
dtprev::Dt
362+
W_γdt::Dt
363+
status::NLStatus
364+
end
365+
TruncatedStacktraces.@truncate_stacktrace RadauIIA7Cache 1
366+
367+
function alg_cache(alg::RadauIIA7, u, rate_prototype, ::Type{uEltypeNoUnits},
368+
::Type{uBottomEltypeNoUnits},
369+
::Type{tTypeNoUnits}, uprev, uprev2, f, t, dt, reltol, p, calck,
370+
::Val{true}) where {uEltypeNoUnits, uBottomEltypeNoUnits, tTypeNoUnits}
371+
uf = UJacobianWrapper(f, t, p)
372+
uToltype = constvalue(uBottomEltypeNoUnits)
373+
tab = RadauIIA7Tableau(uToltype, constvalue(tTypeNoUnits))
374+
375+
κ = alg.κ !== nothing ? convert(uToltype, alg.κ) : convert(uToltype, 1 // 100)
376+
377+
z1 = zero(u)
378+
z2 = zero(u)
379+
z3 = zero(u)
380+
z4 = zero(u)
381+
z5 = zero(u)
382+
w1 = zero(u)
383+
w2 = zero(u)
384+
w3 = zero(u)
385+
w4 = zero(u)
386+
w5 = zero(u)
387+
dw1 = zero(u)
388+
ubuff = zero(u)
389+
dw23 = similar(u, Complex{eltype(u)})
390+
dw45 = similar(u, Complex{eltype(u)})
391+
recursivefill!(dw23, false)
392+
recursivefill!(dw45, false)
393+
cubuff = similar(u, Complex{eltype(u)})
394+
recursivefill!(cubuff, false)
395+
cont1 = zero(u)
396+
cont2 = zero(u)
397+
cont3 = zero(u)
398+
cont4 = zero(u)
399+
400+
fsalfirst = zero(rate_prototype)
401+
k = zero(rate_prototype)
402+
k2 = zero(rate_prototype)
403+
k3 = zero(rate_prototype)
404+
k4 = zero(rate_prototype)
405+
k5 = zero(rate_prototype)
406+
fw1 = zero(rate_prototype)
407+
fw2 = zero(rate_prototype)
408+
fw3 = zero(rate_prototype)
409+
fw4 = zero(rate_prototype)
410+
fw5 = zero(rate_prototype)
411+
412+
J, W1 = build_J_W(alg, u, uprev, p, t, dt, f, uEltypeNoUnits, Val(true))
413+
if J isa AbstractSciMLOperator
414+
error("Non-concrete Jacobian not yet supported by RadauIIA5.")
415+
end
416+
W2 = similar(J, Complex{eltype(W1)})
417+
W3 = similar(J, Complex{eltype(W1)})
418+
recursivefill!(W2, false)
419+
recursivefill!(W3, false)
420+
421+
du1 = zero(rate_prototype)
422+
423+
tmp = zero(u)
424+
atmp = similar(u, uEltypeNoUnits)
425+
recursivefill!(atmp, false)
426+
jac_config = build_jac_config(alg, f, uf, du1, uprev, u, tmp, dw1)
427+
428+
linprob = LinearProblem(W1, _vec(ubuff); u0 = _vec(dw1))
429+
linsolve1 = init(linprob, alg.linsolve, alias_A = true, alias_b = true,
430+
assumptions = LinearSolve.OperatorAssumptions(true))
431+
#Pl = LinearSolve.InvPreconditioner(Diagonal(_vec(weight))),
432+
#Pr = Diagonal(_vec(weight)))
433+
linprob = LinearProblem(W2, _vec(cubuff); u0 = _vec(dw23))
434+
linsolve2 = init(linprob, alg.linsolve, alias_A = true, alias_b = true,
435+
assumptions = LinearSolve.OperatorAssumptions(true))
436+
#Pl = LinearSolve.InvPreconditioner(Diagonal(_vec(weight))),
437+
#Pr = Diagonal(_vec(weight)))
438+
linprob = LinearProblem(W3, _vec(cubuff); u0 = _vec(dw45))
439+
linsolve3 = init(linprob, alg.linsolve, alias_A = true, alias_b = true,
440+
assumptions = LinearSolve.OperatorAssumptions(true))
441+
#Pl = LinearSolve.InvPreconditioner(Diagonal(_vec(weight))),
442+
#Pr = Diagonal(_vec(weight)))
443+
444+
445+
rtol = reltol isa Number ? reltol : zero(reltol)
446+
atol = reltol isa Number ? reltol : zero(reltol)
447+
448+
RadauIIA7Cache(u, uprev,
449+
z1, z2, z3, z4, z5, w1, w2, w3, w4, w5,
450+
dw1, ubuff, dw23, dw45, cubuff, cont1, cont2, cont3, cont4,
451+
du1, fsalfirst, k, k2, k3, k4, k5, fw1, fw2, fw3, fw4, fw5,
452+
J, W1, W2, W3,
453+
uf, tab, κ, one(uToltype), 10000,
454+
tmp, atmp, jac_config, linsolve1, linsolve2, linsolve3, rtol, atol, dt, dt,
455+
Convergence)
456+

0 commit comments

Comments
 (0)