Skip to content

Commit 4cdccae

Browse files
authored
Merge pull request #335 from doraemonho/main
Add LSRK54 time stepping method
2 parents 32fa72e + ff63faa commit 4cdccae

File tree

4 files changed

+109
-7
lines changed

4 files changed

+109
-7
lines changed

Project.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ authors = ["Gregory L. Wagner <wagner.greg@gmail.com>", "Navid C. Constantinou <
66
description = "Tools for building fast, hackable, pseudospectral partial differential equation solvers on periodic domains."
77
documentation = "https://fourierflows.github.io/FourierFlowsDocumentation/stable/"
88
repository = "https://github.com/FourierFlows/FourierFlows.jl"
9-
version = "0.10.0"
9+
version = "0.10.1"
1010

1111
[deps]
1212
CUDA = "052768ef-5323-5732-b1bb-66c8b64840ba"

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ and [Navid C. Constantinou][] (@navidcy).
102102

103103
The code is citable via [zenodo](https://zenodo.org). Please cite as:
104104

105-
> Gregory L. Wagner, Navid C. Constantinou, and contributors. (2022). FourierFlows/FourierFlows.jl: FourierFlows v0.10.0 (Version v0.10.0). Zenodo. [http://doi.org/10.5281/zenodo.1161724](http://doi.org/10.5281/zenodo.1161724)
105+
> Gregory L. Wagner, Navid C. Constantinou, and contributors. (2022). FourierFlows/FourierFlows.jl: FourierFlows v0.10.1 (Version v0.10.1). Zenodo. [http://doi.org/10.5281/zenodo.1161724](http://doi.org/10.5281/zenodo.1161724)
106106
107107

108108
## Contributing

src/timesteppers.jl

Lines changed: 106 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,8 @@ const fullyexplicitsteppers= [
4040
:AB3,
4141
:FilteredForwardEuler,
4242
:FilteredRK4,
43-
:FilteredAB3
43+
:FilteredAB3,
44+
:LSRK54
4445
]
4546

4647
isexplicit(stepper) = any(Symbol(stepper) .== fullyexplicitsteppers)
@@ -73,6 +74,7 @@ end
7374
# * RK4
7475
# * Filtered RK4
7576
# * ETDRK4
77+
# * LSRK54
7678
# * Filtered ETDRK4
7779
# * AB3
7880
# * Filtered AB3
@@ -166,6 +168,11 @@ k₂ = RHS(uⁿ + k₁ * dt/2, tⁿ + dt/2)
166168
k₃ = RHS(uⁿ + k₂ * dt/2, tⁿ + dt/2)
167169
k₄ = RHS(uⁿ + k₃ * dt, tⁿ + dt)
168170
```
171+
172+
!!! info "Usage"
173+
If you are limited by memory then consider switching to [`LSRK54TimeStepper`](@ref).
174+
The [`LSRK54TimeStepper`](@ref) timestepper has half the memory footprint compared
175+
to the `RK4TimeStepper` with a 25~30% performance trade off.
169176
"""
170177
struct RK4TimeStepper{T} <: AbstractTimeStepper{T}
171178
sol₁ :: T
@@ -277,10 +284,104 @@ function stepforward!(sol, clock, ts::FilteredRK4TimeStepper, equation, vars, pa
277284
return nothing
278285
end
279286

287+
# --
288+
# LSRK(5)4
289+
# --
290+
291+
"""
292+
struct LSRK54TimeStepper{T} <: AbstractTimeStepper{T}
293+
294+
A 4th-order 5-stages 2-storage Runge-Kutta timestepper for time-stepping
295+
`∂u/∂t = RHS(u, t)` via:
296+
```
297+
S² = 0
298+
299+
for i = 1:5
300+
S² = Aᵢ * S² + dt * RHS(uⁿ, t₀ + Cᵢ * dt)
301+
uⁿ += Bᵢ * S²
302+
end
303+
304+
uⁿ⁺¹ = uⁿ
305+
```
306+
307+
where `Aᵢ`, `Bᵢ`, and `Cᵢ` are the ``A``, ``B``, and ``C`` coefficients from
308+
the LSRK tableau table at the ``i``-th stage. For details, please refer to
309+
310+
> Carpenter, M. H. and Kennedy, C. A. (1994). Fourth-order 2N-storage Runge–Kutta schemes, Technical Report NASA TM-109112, NASA Langley Research Center, VA.
311+
312+
!!! info "Usage"
313+
The `LSRK54TimeStepper` is *slower* than the [`RK4TimeStepper`](@ref) but
314+
with *less* memory footprint; half compared to [`RK4TimeStepper`](@ref).
315+
316+
If you are bound by performance then use [`RK4TimeStepper`](@ref); if your
317+
simulation is bound by memory then consider using `LSRK54TimeStepper`.
318+
"""
319+
struct LSRK54TimeStepper{T,V} <: AbstractTimeStepper{T}
320+
:: T
321+
RHS :: T
322+
A :: V
323+
B :: V
324+
C :: V
325+
end
326+
327+
"""
328+
LSRK54TimeStepper(equation::Equation, dev::Device=CPU())
280329
281-
# ------
330+
Construct a 4th-order 5-stages low storage Runge-Kutta timestepper for `equation` on device `dev`.
331+
"""
332+
function LSRK54TimeStepper(equation::Equation, dev::Device=CPU())
333+
@devzeros typeof(dev) equation.T equation.dims S² RHS
334+
335+
T = equation.T
336+
A = T[0,
337+
-567301805773//1357537059087,
338+
-2404267990393//2016746695238,
339+
-3550918686646//2091501179385,
340+
-1275806237668//842570457699]
341+
342+
B = T[1432997174477//9575080441755,
343+
5161836677717//13612068292357,
344+
1720146321549//2090206949498,
345+
3134564353537//4481467310338,
346+
2277821191437//14882151754819]
347+
C = T[0,
348+
1432997174477//9575080441755,
349+
2526269341429//6820363962896,
350+
2006345519317//3224310063776,
351+
2802321613138//2924317926251]
352+
353+
return LSRK54TimeStepper(S², RHS, Tuple(A), Tuple(B), Tuple(C))
354+
end
355+
356+
function LSRK54!(sol, clock, ts, equation, vars, params, grid, t, dt)
357+
T = equation.T
358+
A, B, C = ts.A, ts.B, ts.C
359+
360+
# initialize the S² term
361+
@. ts.= 0
362+
363+
for i = 1:5
364+
equation.calcN!(ts.RHS, sol, t + C[i] * dt , clock, vars, params, grid)
365+
addlinearterm!(ts.RHS, equation.L, sol)
366+
367+
@. ts.= A[i] * ts.+ dt * ts.RHS
368+
@. sol += B[i] * ts.
369+
end
370+
371+
return nothing
372+
end
373+
374+
function stepforward!(sol, clock, ts::LSRK54TimeStepper, equation, vars, params, grid)
375+
LSRK54!(sol, clock, ts, equation, vars, params, grid, clock.t, clock.dt)
376+
clock.t += clock.dt
377+
clock.step += 1
378+
379+
return nothing
380+
end
381+
382+
# --
282383
# ETDRK4
283-
# ------
384+
# --
284385

285386
"""
286387
struct ETDRK4TimeStepper{T,TL} <: AbstractTimeStepper{T}
@@ -430,9 +531,9 @@ function stepforward!(sol, clock, ts::FilteredETDRK4TimeStepper, equation, vars,
430531
end
431532

432533

433-
# ---
534+
# --
434535
# AB3
435-
# ---
536+
# --
436537

437538
const ab3h1 = 23/12
438539
const ab3h2 = 16/12

test/runtests.jl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ const rtol_timesteppers = 1e-12
2626
const steppers = [
2727
"ForwardEuler",
2828
"RK4",
29+
"LSRK54",
2930
"ETDRK4",
3031
"AB3",
3132
"FilteredForwardEuler",

0 commit comments

Comments
 (0)