Skip to content

Commit 9c15269

Browse files
caches
1 parent 3318e37 commit 9c15269

File tree

3 files changed

+45
-21
lines changed

3 files changed

+45
-21
lines changed

lib/OrdinaryDiffEqFIRK/src/firk_caches.jl

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -527,10 +527,12 @@ mutable struct AdaptiveRadauCache{uType, cuType, uNoUnitsType, rateType, JType,
527527
uprev::uType
528528
z::Vector{uType}
529529
w::Vector{uType}
530+
c_prime::Vector{BigFloat}
530531
dw1::uType
531532
ubuff::uType
532533
dw2::Vector{cuType}
533534
cubuff::Vector{cuType}
535+
dw::Vector{uType}
534536
cont::Vector{uType}
535537
derivatives:: Matrix{uType}
536538
du1::rateType
@@ -587,12 +589,15 @@ function alg_cache(alg::AdaptiveRadau, u, rate_prototype, ::Type{uEltypeNoUnits}
587589
z[i] = w[i] = zero(u)
588590
end
589591

592+
c_prime = Vector{BigFloat}(undef, num_stages) #time stepping
593+
590594
dw1 = zero(u)
591595
ubuff = zero(u)
592596
dw2 = [similar(u, Complex{eltype(u)}) for _ in 1 : (num_stages - 1) ÷ 2]
593597
recursivefill!.(dw2, false)
594598
cubuff = [similar(u, Complex{eltype(u)}) for _ in 1 : (num_stages - 1) ÷ 2]
595599
recursivefill!.(cubuff, false)
600+
dw = Vector{typeof(u)}(undef, num_stages - 1)
596601

597602
cont = Vector{typeof(u)}(undef, num_stages)
598603
for i in 1 : num_stages
@@ -641,7 +646,7 @@ function alg_cache(alg::AdaptiveRadau, u, rate_prototype, ::Type{uEltypeNoUnits}
641646
atol = reltol isa Number ? reltol : zero(reltol)
642647

643648
AdaptiveRadauCache(u, uprev,
644-
z, w, dw1, ubuff, dw2, cubuff, cont, derivatives,
649+
z, w, c_prime, dw1, ubuff, dw2, cubuff, dw, cont, derivatives,
645650
du1, fsalfirst, ks, k, fw,
646651
J, W1, W2,
647652
uf, tab, κ, one(uToltype), 10000, tmp,

lib/OrdinaryDiffEqFIRK/src/firk_perform_step.jl

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1398,7 +1398,7 @@ end
13981398
cache.cont[i] = map(zero, u)
13991399
end
14001400
else
1401-
c_prime = Vector{eltype(u)}(undef, num_stages) #time stepping
1401+
c_prime = Vector{typeof(u)}(undef, num_stages) #time stepping
14021402
c_prime[num_stages] = dt / cache.dtprev
14031403
for i in 1 : num_stages - 1
14041404
c_prime[i] = c[i] * c_prime[num_stages]
@@ -1491,8 +1491,10 @@ end
14911491
break
14921492
end
14931493
end
1494-
1495-
w = @.. w - dw
1494+
1495+
for i in 1 : num_stages
1496+
w[i] -= dw[i]
1497+
end
14961498

14971499
# transform `w` to `z`
14981500
#z = T * w
@@ -1574,8 +1576,8 @@ end
15741576
@muladd function perform_step!(integrator, cache::AdaptiveRadauCache, repeat_step = false)
15751577
@unpack t, dt, uprev, u, f, p, fsallast, fsalfirst = integrator
15761578
@unpack T, TI, γ, α, β, c, #=e,=# num_stages = cache.tab
1577-
@unpack κ, cont, derivatives, z, w = cache
1578-
@unpack dw1, ubuff, dw2, cubuff = cache
1579+
@unpack κ, cont, derivatives, z, w, c_prime = cache
1580+
@unpack dw1, ubuff, dw2, cubuff, dw = cache
15791581
@unpack ks, k, fw, J, W1, W2 = cache
15801582
@unpack tmp, atmp, jac_config, linsolve1, linsolve2, rtol, atol, step_limiter! = cache
15811583
@unpack internalnorm, abstol, reltol, adaptive = integrator.opts
@@ -1604,7 +1606,6 @@ end
16041606
z[i] = w[i] = cache.cont[i] = map(zero, u)
16051607
end
16061608
else
1607-
c_prime = Vector{eltype(u)}(undef, num_stages) #time stepping
16081609
c_prime[num_stages] = dt / cache.dtprev
16091610
for i in 1 : num_stages - 1
16101611
c_prime[i] = c[i] * c_prime[num_stages]
@@ -1692,7 +1693,6 @@ end
16921693
end
16931694

16941695
integrator.stats.nsolve += (num_stages + 1) / 2
1695-
dw = Vector{typeof(u)}(undef, num_stages - 1)
16961696

16971697
for i in 1 : (num_stages - 1) ÷ 2
16981698
dw[2 * i - 1] = z[2 * i - 1]
@@ -1757,7 +1757,7 @@ end
17571757
@.. broadcast=false u=uprev + z[num_stages]
17581758

17591759
step_limiter!(u, integrator, p, t + dt)
1760-
#=
1760+
17611761
if adaptive
17621762
utilde = w2
17631763
edt = e./dt
@@ -1795,7 +1795,7 @@ end
17951795
integrator.EEst = internalnorm(atmp, t)
17961796
end
17971797
end
1798-
=#
1798+
17991799
if integrator.EEst <= oneunit(integrator.EEst)
18001800
cache.dtprev = dt
18011801
if alg.extrapolant != :constant

lib/OrdinaryDiffEqFIRK/src/firk_tableaus.jl

Lines changed: 30 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,11 @@ function BigRadauIIA5Tableau(T1, T2)
134134
c[2] = big"0.644948974278317809819728407470589139196594748065667012843269256725096037745731502653985943310464023481859460122661418912485886545983775734162578395123729143"
135135
c[3] = big"1"
136136

137+
e = Vector{T1}(undef, 3)
138+
e[1] = big"-0.804701356815835379608495496358640916569322134539215617920280276511680200030933806355291481868922518805459899199875734619185214695254668403298825163805293365"
139+
e[2] = big"-0.267446751803505087778945794929857825182629030352446373700645445786652166171126710221557624849436998601914181921833023811045195644454184323577861370786198096"
140+
e[3] = big"-0.202740720976336900360387312310916037542642249112497662477129527815832849767696924955091220025846425370353707227521045881781871836521093030105009933962412198"
141+
137142
TI = Matrix{T1}(undef, 3, 3)
138143
TI[1, 1] = big"4.32557989006315535102435095295614882731995158490590784287320458848019483341979047442263696495019938973156007686663488090615420049217658854859024016717169837"
139144
TI[1, 2] = big"0.339199251815809869542824974053410987511771566126056902312311333553438988409693737874718833892037643701271502187763370262948704203562215007824701228014200056"
@@ -156,7 +161,7 @@ function BigRadauIIA5Tableau(T1, T2)
156161
T[3, 2] = big"1.0"
157162
T[3, 3] = big"0.0"
158163
RadauIIATableau{T1, T2}(T, TI,
159-
c, γ, α, β, 3)
164+
c, γ, α, β, #=e,=# 3)
160165
end
161166

162167
function BigRadauIIA9Tableau(T1, T2)
@@ -175,6 +180,13 @@ function BigRadauIIA9Tableau(T1, T2)
175180
c[4] = big"0.8602401356562194478479129188751197667383780225872255049242335941839742579301655644134901549264276106897445531811874851737136468026848125542506920602484255"
176181
c[5] = big"1.0"
177182

183+
e = Vector{T1}(undef, 5)
184+
e[1] = big"-0.396056873040772391443753928838733350903268235649241407109949157055321706077305169410373530093363946563049059516774269126208180048957098799522070282580085012"
185+
e[2] = big"-0.120998893046492111917470082824942310714828787321581605224083897201222931079742440239750023176022706685332409182564676958242591761944047403771685667130014796"
186+
e[3] = big"-0.428099657316704068620981167438991676522506275261025355075012671900974663138721382194232832263754491637468895406090947322821492290199844487667268567641865902"
187+
e[4] = big"-0.14209725213800672440012694437858306290960212386817941668712296105013559223718245243280058605734579343272550597862802439475182620322497804597976958854332963"
188+
e[5] = big"-0.0718131688854938240955830308703126002625513555250069460240421718019137231332378610692892428976217345796439675210144794505060225760814921842351985264738071248"
189+
178190
TI = Matrix{T1}(undef, 5, 5)
179191
TI[1, 1] = big"30.0415677215444016277146611632467970747634862837368422955138470463852339244593400023985957753164599415374157317627305099177616927640413043608408838747985125"
180192
TI[1, 2] = big"13.8651078562714131651762946846279728486098595017962436746405940971751244384714668104145151259298432908422191238542910724677205181071665482818120092330632702"
@@ -230,7 +242,7 @@ function BigRadauIIA9Tableau(T1, T2)
230242
T[5, 5] = big"0.0"
231243

232244
RadauIIATableau{T1, T2}(T, TI,
233-
c, γ, α, β, 5)
245+
c, γ, α, β, #=e,=# 5)
234246
end
235247

236248

@@ -402,6 +414,15 @@ function BigRadauIIA13Tableau(T1, T2)
402414
c[6] = big"0.926945671319741114851873965819682011056172419542283252724467079656645202452528243814339480013587391545656707320049986592771178724621938506933715568048004783"
403415
c[7] = big"1.0"
404416

417+
e = Vector{T1}(undef, 7)
418+
e[1] = big"-0.252864387074253458829206302755008427271632071911523081751767012887135523702827548481788009254605639434091010898676803950224099333883157851379911155069978279"
419+
e[2] = big"-0.0431154147693765556786027719094601654492921814596937312134031119112531513440588153185568190763617489229387640388525470783702009674718741042530929470636829615"
420+
e[3] = big"-0.301177734439979327067358132631475024908856612462075071661429433362113545599206315692850620370071719845567311214260856007516359780524163248261047915189592181"
421+
e[4] = big"-0.152771711192720814532185222660572424298879489997094076620761921659113290348236035957988677484677250113716116249595661396377139314351659646376567165252091199"
422+
e[5] = big"-0.246155816769719505509940312338612337785792811109326830573144303824690959223435503683715228237563474852776043407904088603594853209284614752559595389755490267"
423+
e[6] = big"-0.0794180284601028524502179548802248076178607044829584655895971993642306464734826800923021367047713399664978080601493771667070406823265242401710433650128072783"
424+
e[7] = big"-0.0363933725938825618683946400054160074125285023799690190921600209776133289723506736807240580451513859987883185020494128433220917384498561166906858467063724684"
425+
405426
TI = Matrix{T1}(undef, 7, 7)
406427
TI[1, 1] = big"258.131926319982229276108947425184471333411128774462923076434633414645220927977539758484670571338176678808837829326061674950321562391576244286310404028770676"
407428
TI[1, 2] = big"189.073763081398508951976143411165126555759459745371576264125287430947886413126866952443113984840310549596923934762141954737541643761162558070450614795561734"
@@ -505,7 +526,7 @@ function BigRadauIIA13Tableau(T1, T2)
505526
T[7, 7] = big"0.0"
506527

507528
RadauIIATableau{T1, T2}(T, TI,
508-
c, γ, α, β, 7)
529+
c, γ, α, β, #=e,=# 7)
509530
end
510531

511532
using Polynomials, LinearAlgebra, GenericSchur, RootedTrees, Symbolics
@@ -524,7 +545,7 @@ function adaptiveRadauTableau(T1, T2, num_stages::Int)
524545
for i in 1:(num_stages - 1)
525546
radau_p = derivative(radau_p)
526547
end
527-
c = roots(radau_p)
548+
c = real(roots(radau_p))
528549
c[num_stages] = 1
529550
c_powers = Matrix{BigFloat}(undef, num_stages, num_stages)
530551
for i in 1 : num_stages
@@ -576,7 +597,7 @@ function adaptiveRadauTableau(T1, T2, num_stages::Int)
576597
end
577598
end
578599
TI = inv(T)
579-
#=
600+
580601
p = num_stages
581602
eb = variables(:b, 1:num_stages + 1)
582603
@variables y
@@ -588,13 +609,11 @@ function adaptiveRadauTableau(T1, T2, num_stages::Int)
588609
constraints = map(Iterators.flatten(RootedTreeIterator(i) for i in 1:p)) do t
589610
residual_order_condition(t, RungeKuttaMethod(eA, eb, ec))
590611
end
591-
AA, bb, islinear = Symbolics.linear_expansion(substitute.(constraints, (eb[1]=>y,)), eb[2:end])
612+
AA, bb, islinear = Symbolics.linear_expansion(substitute.(constraints, (eb[1]=>1/γ,)), eb[2:end])
592613
AA = BigFloat.(map(unwrap, AA))
593614
idxs = qr(AA', ColumnNorm()).p[1:num_stages]
594-
@assert rank(AA[idxs, :]) == num_stages
595615
@assert islinear
596-
Symbolics.expand.((AA[idxs, :] \ -bb[idxs]) - b)=#
597-
#e = b_hat - b
598-
RadauIIATableau{T1, T2}(T, TI, c, γ, α, β, num_stages)
616+
b_hat = Symbolics.expand.((AA[idxs, :] \ -bb[idxs]) - b)
617+
#e = symbolic_to_float(b_hat - b)
618+
RadauIIATableau{T1, T2}(T, TI, c, γ, α, β, #=e,=# num_stages)
599619
end
600-

0 commit comments

Comments
 (0)