Skip to content
Snippets Groups Projects
Commit 20dffa45 authored by Brian Groenke's avatar Brian Groenke
Browse files

Add callback types and function stubs

parent 696fc730
No related branches found
No related tags found
1 merge request!57Add support for per-layer callbacks
......@@ -9,14 +9,14 @@ end
using Base: @propagate_inbounds
using Reexport
# Common types and methods
export Layer, SubSurface, Top, Bottom
export Process, SubSurfaceProcess, BoundaryProcess, CompoundProcess, Coupled
export BoundaryStyle, Dirichlet, Neumann
export AbstractParameterization, Parameterization
export variables, initialcondition!, diagnosticstep!, prognosticstep!, interact!, boundaryflux, boundaryvalue, observe
# Common types and methods
export Callback, CallbackStyle
include("types.jl")
export variables, initialcondition!, diagnosticstep!, prognosticstep!, interact!
export boundaryflux, boundaryvalue, criterion, affect!, observe
include("methods.jl")
# Submodules
......
"""
variables(::Layer, ::Process)
Defines variables for a given Process on Layer. Implementations should return a `Tuple` of `Var`s.
Defines variables for a given Process on the given Layer. Implementations should return a `Tuple` of `Var`s.
"""
variables(::Layer, ::Process) = ()
"""
callbacks(::Layer, ::Process)
Defines callbacks for a given Process on the given Layer. Implementations should return a `Tuple` or `Callback`s.
"""
callbacks(::Layer, ::Process) = ()
"""
initialcondition!(::Layer, ::Process, state)
Defines the initial condition for a given Process on Layer. `initialcondition!` should write initial values into all relevant
Defines the initial condition for a given Process on the given Layer. `initialcondition!` should write initial values into all relevant
state variables in `state`.
"""
initialcondition!(::Layer, ::Process, state) = nothing
......@@ -53,6 +59,18 @@ boundaryflux(s::BoundaryStyle, bc::BoundaryProcess, b::Union{Top,Bottom}, p::Sub
Computes the value of the boundary condition specified by `bc` for the given layer/process combinations.
"""
boundaryvalue(bc::BoundaryProcess, b, p, layer, sbc, ssub) = error("missing implementation of boundaryvalue for $(typeof(b)) $(typeof(bc)) on $(typeof(layer)) with $(typeof(p))")
"""
criterion(c::Callback, ::Layer, ::Process, state)
Callback criterion/condition. Should return a `Bool` for discrete callbacks and a real number for continuous callbacks.
"""
criterion(c::Callback, ::Layer, ::Process, state) = error("missing implementation of criterion for $(typeof(c))")
"""
affect!(c::Callback, ::Layer, ::Process, state)
Callback action executed when `criterion` is met (boolean condition for discrete callbacks, zero for continuous callbacks).
"""
affect!(c::Callback, ::Layer, ::Process, state) = error("missing implementation of affect! for $(typeof(c))")
"""
observe(::Val{name}, ::Layer, ::Process, state1)
......@@ -86,3 +104,5 @@ where `BP` is a `BoundaryProcess` that provides the boundary conditions.
"""
BoundaryStyle(::Type{BP}) where {BP<:BoundaryProcess} = error("No style specified for boundary process $BP")
BoundaryStyle(bc::BoundaryProcess) = BoundaryStyle(typeof(bc))
# default callback style impl
CallbackStyle(::Type{<:Callback}) = Discrete()
......@@ -88,3 +88,17 @@ struct Dirichlet <: BoundaryStyle end
`BoundaryStyle` instance for Neumann boundary conditions.
"""
struct Neumann <: BoundaryStyle end
"""
Callback
Base type for callback implementations.
"""
abstract type Callback end
"""
CallbackStyle
Trait for callback types.
"""
abstract type CallbackStyle end
struct Discrete <: CallbackStyle end
struct Continuous <: CallbackStyle end
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment