Skip to content

Commit b0aa1b5

Browse files
committed
add struct for tableau
1 parent f8ea589 commit b0aa1b5

File tree

5 files changed

+25
-11
lines changed

5 files changed

+25
-11
lines changed

examples/trixi_rosenbrock.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,4 +30,4 @@ sol = solve(
3030
ode_default_options()..., callback = callbacks,
3131
# verbose=1,
3232
krylov_algo = :gmres,
33-
);
33+
);

libs/Implicit/src/Implicit.jl

Lines changed: 24 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -160,14 +160,13 @@ end
160160

161161
struct Rosenbrock <: Direct{3} end
162162

163-
function (::Rosenbrock)(res, uₙ, Δt, f!, du, u, p, t, stages, stage, workspace, M)
163+
function (::Rosenbrock)(res, uₙ, Δt, f!, du, u, p, t, stages, stage, workspace, M, RK)
164164
invdt = inv(Δt)
165-
alpha, c, m, _ = RosenbrockTableau()
166165
@. u = uₙ
167166
@. res = 0
168167
for j in 1:(stage-1)
169-
@. u = u + alpha[stage, j] * stages[j]
170-
@. res = res + c[stage, j] * stages[j] * invdt
168+
@. u = u + RK.a[stage, j] * stages[j]
169+
@. res = res + RK.c[stage, j] * stages[j] * invdt
171170
end
172171

173172
## It does not work for non-autonomous systems.
@@ -179,11 +178,18 @@ function (::Rosenbrock)(res, uₙ, Δt, f!, du, u, p, t, stages, stage, workspac
179178
if stage == 3
180179
@. u = uₙ
181180
for j in 1:stage
182-
@. u = u + m[j] * stages[j]
181+
@. u = u + RK.m[j] * stages[j]
183182
end
184183
end
185184

186185
end
186+
abstract type RKTableau end
187+
188+
struct RosenbrockButcher{T1 <: AbstractArray, T2 <: AbstractArray} <: RKTableau
189+
a::T1
190+
c::T1
191+
m::T2
192+
end
187193

188194
function RosenbrockTableau()
189195

@@ -209,11 +215,17 @@ function RosenbrockTableau()
209215
a = alpha * inv(gamma)
210216
m = transpose(b) * inv(gamma)
211217
c = diagm(inv.(diag(gamma))) - inv(gamma)
218+
return RosenbrockButcher(a, c, vec(m))
212219

213-
return a, c, m, nstage # alpha, c, m
220+
end
214221

222+
function RKTableau(alg::Direct)
223+
return RosenbrockTableau()
215224
end
216225

226+
function RKTableau(alg::NonDirect)
227+
return RosenbrockTableau()
228+
end
217229

218230

219231
function nonlinear_problem(alg::SimpleImplicitAlgorithm, f::F) where {F}
@@ -249,7 +261,7 @@ end
249261
# which are used in Trixi.jl.
250262
mutable struct SimpleImplicit{
251263
RealT <: Real, uType, Params, Sol, F, M, Alg <: SimpleImplicitAlgorithm,
252-
SimpleImplicitOptions,
264+
SimpleImplicitOptions, RKTableau,
253265
} <: AbstractTimeIntegrator
254266
u::uType
255267
du::uType
@@ -266,6 +278,7 @@ mutable struct SimpleImplicit{
266278
alg::Alg # SimpleImplicitAlgorithm
267279
opts::SimpleImplicitOptions
268280
finalstep::Bool # added for convenience
281+
RK::RKTableau
269282
end
270283

271284
# Forward integrator.stats.naccept to integrator.iter (see GitHub PR#771)
@@ -294,8 +307,7 @@ function init(
294307
SimpleImplicitOptions(
295308
callback, ode.tspan;
296309
kwargs...,
297-
), false,
298-
)
310+
), false, RKTableau(alg))
299311

300312
# initialize callbacks
301313
if callback isa CallbackSet
@@ -365,8 +377,9 @@ function stage!(integrator, alg::Direct)
365377
workspace = krylov_workspace(:gmres, kc)
366378

367379
for stage in 1:stages(alg)
368-
alg(integrator.res, integrator.u, integrator.dt, integrator.f, integrator.du, integrator.u_tmp, integrator.p, integrator.t, integrator.stages, stage, workspace, M)
380+
alg(integrator.res, integrator.u, integrator.dt, integrator.f, integrator.du, integrator.u_tmp, integrator.p, integrator.t, integrator.stages, stage, workspace, M, integrator.RK)
369381
end
382+
370383
end
371384

372385
function step!(integrator::SimpleImplicit)
@@ -389,6 +402,7 @@ function step!(integrator::SimpleImplicit)
389402

390403
# one time step
391404
integrator.u_tmp .= integrator.u
405+
392406
stage!(integrator, alg)
393407

394408
integrator.u .= integrator.u_tmp

out/mesh.h5

36 KB
Binary file not shown.

out/solution_000000000.h5

34 KB
Binary file not shown.

out/solution_000000003.h5

34 KB
Binary file not shown.

0 commit comments

Comments
 (0)