Skip to content

Commit b0d8a2a

Browse files
Export SplitRungeKutta3TimeStepper a few docstring fixes (typos and rendering) (#4571)
* export SplitRungeKutta3TimeStepper * enhance docstring * enhance docstring * fix typo in docs * fix docstring * docstring rendering * tweak docstring * add refs * tweaks * enhance docstrings * Update src/TimeSteppers/runge_kutta_3.jl Co-authored-by: Simone Silvestri <[email protected]> --------- Co-authored-by: Simone Silvestri <[email protected]>
1 parent 2630abf commit b0d8a2a

File tree

12 files changed

+86
-64
lines changed

12 files changed

+86
-64
lines changed

src/Grids/grid_utils.jl

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -343,6 +343,7 @@ It has been known since the time of Euler and Lagrange that
343343
344344
References
345345
==========
346+
346347
* Euler, L. (1778) De mensura angulorum solidorum, Opera omnia, 26, 204-233 (Orig. in Acta adac. sc. Petrop. 1778)
347348
* Lagrange, J.-L. (1798) Solutions de quilquies problèmes relatifs au triangles sphéruques, Oeuvres, 7, 331-359.
348349
"""
@@ -374,6 +375,7 @@ that ``P`` above is the same as the volume defined by the vectors `a`, `b`, and
374375
375376
References
376377
==========
378+
377379
* Eriksson, F. (1990) On the measure of solid angles, Mathematics Magazine, 63 (3), 184-187, doi:10.1080/0025570X.1990.11977515
378380
"""
379381
function spherical_area_triangle(a₁::AbstractVector, a₂::AbstractVector, a₃::AbstractVector)

src/Simulations/callback.jl

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,6 @@ which in turn does nothing by default.
3636
3737
`finalize!` can be specialized on `callback.parameters`,
3838
or specialized for `callback.func`.
39-
`
4039
"""
4140
finalize!(callback::Callback, sim) = finalize!(callback.func, sim)
4241

@@ -55,7 +54,7 @@ If `isnothing(parameters)`, `func(sim::Simulation)` is called.
5554
Otherwise, `func` is called via `func(sim::Simulation, parameters)`.
5655
5756
The `callsite` determines where `Callback` is executed. The possible values for
58-
`callsite` are
57+
`callsite` are:
5958
6059
* `TimeStepCallsite()`: after a time-step.
6160
@@ -143,4 +142,4 @@ function add_callback!(simulation, func, schedule = IterationInterval(1);
143142
return add_callback!(simulation, callback; name)
144143
end
145144

146-
validate_schedule(func, schedule) = schedule
145+
validate_schedule(func, schedule) = schedule

src/Simulations/simulation.jl

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,8 @@ mutable struct Simulation{ML, DT, ST, DI, OW, CB, FT, BL}
2828
end
2929

3030
"""
31-
Simulation(model; Δt,
31+
Simulation(model;
32+
Δt,
3233
verbose = true,
3334
stop_iteration = Inf,
3435
stop_time = Inf,
@@ -43,12 +44,21 @@ Keyword arguments
4344
- `Δt`: Required keyword argument specifying the simulation time step. Can be a `Number`
4445
for constant time steps or a `TimeStepWizard` for adaptive time-stepping.
4546
46-
- `stop_iteration`: Stop the simulation after this many iterations.
47+
- `stop_iteration`: Stop the simulation after this many iterations. Default: `Inf`.
4748
48-
- `stop_time`: Stop the simulation once this much model clock time has passed.
49+
- `stop_time`: Stop the simulation once this much model clock time has passed. Default: `Inf`.
4950
5051
- `wall_time_limit`: Stop the simulation if it's been running for longer than this many
51-
seconds of wall clock time.
52+
seconds of wall clock time. Default: `Inf`.
53+
54+
- `align_time_step`: When `true` it implies that the simulation will automatically adjust the
55+
time-step to meet a constraint imposed by various schedules like `ScheduledTimes`,
56+
`TimeInterval`, `AveragedTimeInterval`, as well as a `stop_time` criterion.
57+
If `false`, i.e., no time-step alignment, then the simulation might blithely step passed
58+
the specified time. Default: `true`.
59+
By `align_time_step = false` we ensure that the time-step does _not_ change within
60+
`time_step!(simulation)`
61+
5262
- `minimum_relative_step`: time steps smaller than `Δt * minimum_relative_step` will be skipped.
5363
This avoids extremely high values when writing the pressure to disk.
5464
Default value is 0. See github.com/CliMA/Oceananigans.jl/issues/3593 for details.

src/TimeSteppers/TimeSteppers.jl

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ module TimeSteppers
33
export
44
QuasiAdamsBashforth2TimeStepper,
55
RungeKutta3TimeStepper,
6+
SplitRungeKutta3TimeStepper,
67
time_step!,
78
Clock,
89
tendencies
@@ -42,13 +43,13 @@ include("split_hydrostatic_runge_kutta_3.jl")
4243
"""
4344
TimeStepper(name::Symbol, args...; kwargs...)
4445
45-
Returns a timestepper with name `name`, instantiated with `args...` and `kwargs...`.
46+
Return a timestepper with name `name`, instantiated with `args...` and `kwargs...`.
4647
4748
Example
4849
=======
4950
5051
```julia
51-
julia> stepper = TimeStepper(:QuasiAdamsBashforth2, CPU(), grid, tracernames)
52+
julia> stepper = TimeStepper(:QuasiAdamsBashforth2, grid, tracernames)
5253
```
5354
"""
5455
TimeStepper(name::Symbol, args...; kwargs...) = TimeStepper(Val(name), args...; kwargs...)

src/TimeSteppers/clock.jl

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -121,5 +121,3 @@ Adapt.adapt_structure(to, clock::Clock) = (time = clock.time,
121121
last_stage_Δt = clock.last_stage_Δt,
122122
iteration = clock.iteration,
123123
stage = clock.stage)
124-
125-

src/TimeSteppers/quasi_adams_bashforth_2.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ end
1616
1717
Return a 2nd-order quasi Adams-Bashforth (AB2) time stepper (`QuasiAdamsBashforth2TimeStepper`)
1818
on `grid`, with `tracers`, and AB2 parameter `χ`. The tendency fields `Gⁿ` and `G⁻`, usually equal to
19-
the prognostic_fields passed as positional argument, can be specified via optional `kwargs`.
19+
the `prognostic_fields` that is passed as positional argument, can be specified via optional `kwargs`.
2020
2121
The 2nd-order quasi Adams-Bashforth timestepper steps forward the state `Uⁿ` by `Δt` via
2222

src/TimeSteppers/runge_kutta_3.jl

Lines changed: 18 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ using Oceananigans: fields
44
"""
55
RungeKutta3TimeStepper{FT, TG} <: AbstractTimeStepper
66
7-
Holds parameters and tendency fields for a low storage, third-order Runge-Kutta-Wray
7+
Hold parameters and tendency fields for a low storage, third-order Runge-Kutta-Wray
88
time-stepping scheme described by [LeMoin1991](@citet).
99
"""
1010
struct RungeKutta3TimeStepper{FT, TG, TI} <: AbstractTimeStepper
@@ -24,12 +24,13 @@ end
2424
Gⁿ = map(similar, prognostic_fields),
2525
G⁻ = map(similar, prognostic_fields))
2626
27-
Return a 3rd-order Runge0Kutta timestepper (`RungeKutta3TimeStepper`) on `grid` and with `tracers`.
28-
The tendency fields `Gⁿ` and `G⁻`, typically equal to the prognostic_fields can be modified via an optional `kwargs`.
27+
Return a 3rd-order Runge-Kutta timestepper (`RungeKutta3TimeStepper`) on `grid`
28+
and with `prognostic_fields`. The tendency fields `Gⁿ` and `G⁻`, typically equal
29+
to the `prognostic_fields` can be modified via the optional `kwargs`.
2930
30-
The scheme described by [LeMoin1991](@citet). In a nutshel, the 3rd-order
31-
Runge Kutta timestepper steps forward the state `Uⁿ` by `Δt` via 3 substeps. A pressure correction
32-
step is applied after at each substep.
31+
The scheme is described by [LeMoin1991](@citet). In a nutshell, the 3rd-order
32+
Runge-Kutta timestepper steps forward the state `Uⁿ` by `Δt` via 3 substeps.
33+
A pressure correction step is applied after at each substep.
3334
3435
The state `U` after each substep `m` is
3536
@@ -39,11 +40,18 @@ Uᵐ⁺¹ = Uᵐ + Δt * (γᵐ * Gᵐ + ζᵐ * Gᵐ⁻¹)
3940
4041
where `Uᵐ` is the state at the ``m``-th substep, `Gᵐ` is the tendency
4142
at the ``m``-th substep, `Gᵐ⁻¹` is the tendency at the previous substep,
42-
and constants ``γ¹ = 8/15``, ``γ² = 5/12``, ``γ³ = 3/4``,
43-
``ζ¹ = 0``, ``ζ² = -17/60``, ``ζ³ = -5/12``.
43+
and constants `γ¹ = 8/15`, `γ² = 5/12`, `γ³ = 3/4`, `ζ¹ = 0`, `ζ² = -17/60`,
44+
and `ζ³ = -5/12`.
45+
46+
The state at the first substep is taken to be the one that corresponds to
47+
the ``n``-th timestep, `U¹ = Uⁿ`, and the state after the third substep is
48+
then the state at the `Uⁿ⁺¹ = U⁴`.
49+
50+
References
51+
==========
52+
Le, H. and Moin, P. (1991). "An improvement of fractional step methods for the incompressible
53+
Navier–Stokes equations." Journal of Computational Physics, 92, 369–379.
4454
45-
The state at the first substep is taken to be the one that corresponds to the ``n``-th timestep,
46-
`U¹ = Uⁿ`, and the state after the third substep is then the state at the `Uⁿ⁺¹ = U⁴`.
4755
"""
4856
function RungeKutta3TimeStepper(grid, prognostic_fields;
4957
implicit_solver::TI = nothing,

src/TimeSteppers/split_hydrostatic_runge_kutta_3.jl

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@ using Oceananigans.Architectures: architecture
22
using Oceananigans: fields
33

44
"""
5-
SplitRungeKutta3TimeStepper{FT, TG} <: AbstractTimeStepper
5+
SplitRungeKutta3TimeStepper{FT, TG, TE, PF, TI} <: AbstractTimeStepper
66
7-
Holds parameters and tendency fields for a low storage, third-order Runge-Kutta-Wray
7+
Hold parameters and tendency fields for a low storage, third-order Runge-Kutta-Wray
88
time-stepping scheme described by [Lan2022](@citet).
99
"""
1010
struct SplitRungeKutta3TimeStepper{FT, TG, TE, PF, TI} <: AbstractTimeStepper
@@ -28,7 +28,7 @@ end
2828
Return a 3rd-order `SplitRungeKutta3TimeStepper` on `grid` and with `tracers`.
2929
The tendency fields `Gⁿ` and `G⁻`, and the previous state ` Ψ⁻` can be modified via optional `kwargs`.
3030
31-
The scheme described by [Lan2022](@citet). In a nutshell, the 3rd-order Runge Kutta timestepper
31+
The scheme is described by [Lan2022](@citet). In a nutshell, the 3rd-order Runge-Kutta timestepper
3232
steps forward the state `Uⁿ` by `Δt` via 3 substeps. A barotropic velocity correction step is applied
3333
after at each substep.
3434
@@ -38,22 +38,27 @@ The state `U` after each substep `m` is
3838
Uᵐ⁺¹ = ζᵐ * Uⁿ + γᵐ * (Uᵐ + Δt * Gᵐ)
3939
```
4040
41-
where `Uᵐ` is the state at the ``m``-th substep, `Uⁿ` is the state at the ``n``-th timestep, `Gᵐ` is the tendency
42-
at the ``m``-th substep, and constants ``γ¹ = 1`, ``γ² = 1/4``, ``γ³ = 1/3``,
43-
``ζ¹ = 0``, ``ζ² = 3/4``, ``ζ³ = 1/3``.
41+
where `Uᵐ` is the state at the ``m``-th substep, `Uⁿ` is the state at the ``n``-th timestep,
42+
`Gᵐ` is the tendency at the ``m``-th substep, and constants `γ¹ = 1`, `γ² = 1/4`, `γ³ = 1/3`,
43+
`ζ¹ = 0`, `ζ² = 3/4`, and `ζ³ = 1/3`.
4444
4545
The state at the first substep is taken to be the one that corresponds to the ``n``-th timestep,
4646
`U¹ = Uⁿ`, and the state after the third substep is then the state at the `Uⁿ⁺¹ = U³`.
47+
48+
References
49+
==========
50+
Lan, R., Ju, L., Wanh, Z., Gunzburger, M., and Jones, P. (2022). "High-order multirate explicit
51+
time-stepping schemes for the baroclinic-barotropic split dynamics in primitive equations",
52+
Journal of Computational Physics 457, 111050.
4753
"""
4854
function SplitRungeKutta3TimeStepper(grid, prognostic_fields, args...;
4955
implicit_solver::TI = nothing,
5056
Gⁿ::TG = map(similar, prognostic_fields),
5157
Ψ⁻::PF = map(similar, prognostic_fields),
5258
G⁻::TE = nothing) where {TI, TG, PF, TE}
5359

54-
5560
@warn("Split barotropic-baroclinic time stepping with SplitRungeKutta3TimeStepper is not tested and experimental.\n" *
56-
"Use at own risk, and report any issues encountered.")
61+
"Use at own risk, and report any issues encountered at [https://github.com/CliMA/Oceananigans.jl/issues](https://github.com/CliMA/Oceananigans.jl/issues).")
5762

5863
!isnothing(implicit_solver) &&
5964
@warn("Implicit-explicit time-stepping with SplitRungeKutta3TimeStepper is not tested. " *
@@ -70,7 +75,6 @@ function SplitRungeKutta3TimeStepper(grid, prognostic_fields, args...;
7075
return SplitRungeKutta3TimeStepper{FT, TG, TE, PF, TI}(γ², γ³, ζ², ζ³, Gⁿ, G⁻, Ψ⁻, implicit_solver)
7176
end
7277

73-
7478
function time_step!(model::AbstractModel{<:SplitRungeKutta3TimeStepper}, Δt; callbacks=[])
7579
Δt == 0 && @warn "Δt == 0 may cause model blowup!"
7680

@@ -172,4 +176,3 @@ function cache_previous_fields!(model)
172176

173177
return nothing
174178
end
175-

src/TurbulenceClosures/turbulence_closure_implementations/TKEBasedVerticalDiffusivities/catke_vertical_diffusivity.jl

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -58,9 +58,9 @@ Turbulent Kinetic Energy (TKE).
5858
!!! note "CATKE vertical diffusivity"
5959
`CATKEVerticalDiffusivity` is a new turbulence closure diffusivity. The default
6060
values for its free parameters are obtained from calibration against large eddy
61-
simulations. For more details please refer to [Wagner25catke](@cite).
61+
simulations. For more details please refer to [Wagner25catke](@citet).
6262
63-
Use with caution and report any issues with the physics at https://github.com/CliMA/Oceananigans.jl/issues.
63+
Use with caution and report any issues with the physics at [https://github.com/CliMA/Oceananigans.jl/issues](https://github.com/CliMA/Oceananigans.jl/issues).
6464
6565
Arguments
6666
=========
@@ -77,18 +77,19 @@ Keyword arguments
7777
7878
- `turbulent_kinetic_energy_equation`: The TKE equation; default: `CATKEEquation()`.
7979
80-
- `maximum_tracer_diffusivity`: Maximum value for tracer diffusivity. CATKE-predicted tracer diffusivities that are larger
81-
than `maximum_tracer_diffusivity` are clipped. Default: `Inf`.
80+
- `maximum_tracer_diffusivity`: Maximum value for tracer diffusivity. CATKE-predicted tracer
81+
diffusivities that are larger than `maximum_tracer_diffusivity`
82+
are clipped. Default: `Inf`.
8283
83-
- `maximum_tke_diffusivity`: Maximum value for TKE diffusivity. CATKE-predicted diffusivities for TKE that are larger
84-
than `maximum_tke_diffusivity` are clipped. Default: `Inf`.
84+
- `maximum_tke_diffusivity`: Maximum value for TKE diffusivity. CATKE-predicted diffusivities
85+
for TKE that are larger than `maximum_tke_diffusivity` are clipped.
86+
Default: `Inf`.
8587
86-
- `maximum_viscosity`: Maximum value for momentum diffusivity. CATKE-predicted momentum diffusivities that are larger
87-
than `maximum_viscosity` are clipped. Default: `Inf`.
88+
- `maximum_viscosity`: Maximum value for momentum diffusivity. CATKE-predicted momentum diffusivities
89+
that are larger than `maximum_viscosity` are clipped. Default: `Inf`.
8890
89-
- `minimum_tke`: Minimum value for the turbulent kinetic energy.
90-
Can be used to model the presence "background" TKE
91-
levels due to, for example, mixing by breaking internal waves.
91+
- `minimum_tke`: Minimum value for the turbulent kinetic energy. Can be used to model the presence
92+
"background" TKE levels due to, for example, mixing by breaking internal waves.
9293
Default: 1e-9.
9394
9495
- `minimum_convective_buoyancy_flux` Minimum value for the convective buoyancy flux. Default: 1e-11.
@@ -99,6 +100,7 @@ Keyword arguments
99100
100101
References
101102
==========
103+
102104
Wagner, G. L., Hillier, A., Constantinou, N. C., Silvestri, S., Souza, A., Burns, K., Hill,
103105
C., Campin, J.-M., Marshall, J., and Ferrari, R. (2025). "Formulation and calibration of CATKE,
104106
a one-equation parameterization for microscale ocean mixing." J. Adv. Model. Earth Sy., 17, e2024MS004522.

src/TurbulenceClosures/turbulence_closure_implementations/anisotropic_minimum_dissipation.jl

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ Keyword arguments
5555
5656
* `Cκ`: Poincaré constant for tracer eddy diffusivities. If one number or function, the same
5757
number or function is applied to all tracers. If a `NamedTuple`, it must possess
58-
a field specifying the Poncaré constant for every tracer.
58+
a field specifying the Poincaré constant for every tracer.
5959
6060
* `Cb`: Buoyancy modification multiplier (`Cb = nothing` turns it off, `Cb = 1` was used by [Abkar16](@citet)).
6161
*Note*: that we _do not_ subtract the horizontally-average component before computing this
@@ -67,8 +67,8 @@ The default Poincaré constant is found by discretizing subgrid scale energy pro
6767
second-order advection scheme. [Verstappen14](@citet) show that the Poincaré constant
6868
should be 4 times larger than for straightforward (spectral) discretisation, resulting in `C = 1/3`
6969
in our formulation. They also empirically demonstrated that this coefficient produces the correct
70-
discrete production-dissipation balance. We further demonstrated this in
71-
https://github.com/CliMA/Oceananigans.jl/issues/4367.
70+
discrete production-dissipation balance. Further demonstration of this can be found at
71+
[https://github.com/CliMA/Oceananigans.jl/issues/4367](https://github.com/CliMA/Oceananigans.jl/issues/4367).
7272
7373
`C`, `Cν` and `Cκ` may be numbers, or functions of `x, y, z`.
7474

0 commit comments

Comments
 (0)