Skip to content

Commit 50dfb23

Browse files
Add explicit constructors for the timesteppers (#4175)
* change to the timestepper * fix the constructor
1 parent eb8fa3e commit 50dfb23

File tree

1 file changed

+27
-21
lines changed

1 file changed

+27
-21
lines changed

src/TimeSteppers/TimeSteppers.jl

Lines changed: 27 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -20,27 +20,6 @@ Abstract supertype for time steppers.
2020
"""
2121
abstract type AbstractTimeStepper end
2222

23-
"""
24-
TimeStepper(name::Symbol, args...; kwargs...)
25-
26-
Returns a timestepper with name `name`, instantiated with `args...` and `kwargs...`.
27-
28-
Example
29-
=======
30-
31-
```julia
32-
julia> stepper = TimeStepper(:QuasiAdamsBashforth2, CPU(), grid, tracernames)
33-
```
34-
"""
35-
function TimeStepper(name::Symbol, args...; kwargs...)
36-
fullname = Symbol(name, :TimeStepper)
37-
TS = getglobal(@__MODULE__, fullname)
38-
return TS(args...; kwargs...)
39-
end
40-
41-
# Fallback
42-
TimeStepper(stepper::AbstractTimeStepper, args...; kwargs...) = stepper
43-
4423
function update_state! end
4524
function compute_tendencies! end
4625

@@ -60,4 +39,31 @@ include("quasi_adams_bashforth_2.jl")
6039
include("runge_kutta_3.jl")
6140
include("split_hydrostatic_runge_kutta_3.jl")
6241

42+
"""
43+
TimeStepper(name::Symbol, args...; kwargs...)
44+
45+
Returns a timestepper with name `name`, instantiated with `args...` and `kwargs...`.
46+
47+
Example
48+
=======
49+
50+
```julia
51+
julia> stepper = TimeStepper(:QuasiAdamsBashforth2, CPU(), grid, tracernames)
52+
```
53+
"""
54+
TimeStepper(name::Symbol, args...; kwargs...) = TimeStepper(Val(name), args...; kwargs...)
55+
56+
# Fallback
57+
TimeStepper(stepper::AbstractTimeStepper, args...; kwargs...) = stepper
58+
59+
#individual contructors
60+
TimeStepper(::Val{:QuasiAdamsBashforth2}, args...; kwargs...) =
61+
QuasiAdamsBashforth2TimeStepper(args...; kwargs...)
62+
63+
TimeStepper(::Val{:RungeKutta3}, args...; kwargs...) =
64+
RungeKutta3TimeStepper(args...; kwargs...)
65+
66+
TimeStepper(::Val{:SplitRungeKutta3}, args...; kwargs...) =
67+
SplitRungeKutta3TimeStepper(args...; kwargs...)
68+
6369
end # module

0 commit comments

Comments
 (0)