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

Rename System -> CompositeProcess

parent 13947f71
No related branches found
No related tags found
1 merge request!46Refactor parameter and state handling system
...@@ -49,32 +49,32 @@ but may include its own diagnostic (or even prognostic) variables, if necessary. ...@@ -49,32 +49,32 @@ but may include its own diagnostic (or even prognostic) variables, if necessary.
""" """
abstract type BoundaryProcess <: Process end abstract type BoundaryProcess <: Process end
""" """
System{TProcs} <: Process CompositeProcess{TProcs} <: Process
Represents a explicitly or implicitly coupled system of processes. `TProcs` is always a `Tuple` Represents a explicitly or implicitly coupled system of processes. `TProcs` is always a `Tuple`
of other processes. of other processes.
""" """
struct System{TProcs} <: Process struct CompositeProcess{TProcs} <: Process
processes::TProcs processes::TProcs
System(processes::SubSurfaceProcess...) = new{typeof(processes)}(processes) CompositeProcess(processes::SubSurfaceProcess...) = new{typeof(processes)}(processes)
System(processes::BoundaryProcess...) = new{typeof(processes)}(processes) CompositeProcess(processes::BoundaryProcess...) = new{typeof(processes)}(processes)
end end
""" """
Coupled{P1,P2} = System{Tuple{T1,T2}} where {T1,T2} Coupled{P1,P2} = CompositeProcess{Tuple{T1,T2}} where {T1,T2}
Represents a coupled pair of explicitly processes. Alias for `System{Tuple{P1,P2}}`. Represents a coupled pair of explicitly processes. Alias for `CompositeProcess{Tuple{P1,P2}}`.
`Coupled` provides a simple mechanism for defining new behaviors on composite processes/systems. `Coupled` provides a simple mechanism for defining new behaviors on composite processes/systems.
""" """
const Coupled{P1,P2} = System{Tuple{T1,T2}} where {T1,T2} const Coupled{P1,P2} = CompositeProcess{Tuple{T1,T2}} where {T1,T2}
""" """
Coupled(p1,p2) Coupled(p1,p2)
Alias for `System(p1,p2)`. Alias for `CompositeProcess(p1,p2)`.
""" """
Coupled(p1::P1, p2::P2) where {P1<:Process,P2<:Process} = System(p1,p2) Coupled(p1::P1, p2::P2) where {P1<:Process,P2<:Process} = CompositeProcess(p1,p2)
# Base methods # Base methods
Base.show(io::IO, ps::System{T}) where T = print(io, "$T") Base.show(io::IO, ps::CompositeProcess{T}) where T = print(io, "$T")
@propagate_inbounds @inline Base.getindex(ps::System, i) = ps.processes[i] @propagate_inbounds @inline Base.getindex(ps::CompositeProcess, i) = ps.processes[i]
# allow broadcasting of Process types # allow broadcasting of Process types
Base.Broadcast.broadcastable(p::Process) = Ref(p) Base.Broadcast.broadcastable(p::Process) = Ref(p)
......
...@@ -10,7 +10,7 @@ using Base: @propagate_inbounds ...@@ -10,7 +10,7 @@ using Base: @propagate_inbounds
using Reexport using Reexport
export Layer, SubSurface, Top, Bottom, Boundary export Layer, SubSurface, Top, Bottom, Boundary
export Process, SubSurfaceProcess, BoundaryProcess, System, Coupled export Process, SubSurfaceProcess, BoundaryProcess, CompositeProcess, Coupled
export BoundaryStyle, Dirichlet, Neumann export BoundaryStyle, Dirichlet, Neumann
export AbstractParameterization, Parameterization export AbstractParameterization, Parameterization
export variables, initialcondition!, diagnosticstep!, prognosticstep!, interact!, observe export variables, initialcondition!, diagnosticstep!, prognosticstep!, interact!, observe
......
module Processes module Processes
import CryoGrid: Process, System, Coupled, Layer, Top, Bottom, SubSurface import CryoGrid: Process, CompositeProcess, Coupled, Layer, Top, Bottom, SubSurface
import CryoGrid: diagnosticstep!, initialcondition!, interact!, prognosticstep!, variables, observe import CryoGrid: diagnosticstep!, initialcondition!, interact!, prognosticstep!, variables, observe
using CryoGrid.Layers using CryoGrid.Layers
...@@ -11,7 +11,7 @@ using Lazy: @>> ...@@ -11,7 +11,7 @@ using Lazy: @>>
using Reexport using Reexport
using Unitful using Unitful
include("systems.jl") include("composite.jl")
include("Boundaries/Boundaries.jl") include("Boundaries/Boundaries.jl")
include("Water/Water.jl") include("Water/Water.jl")
include("HeatConduction/HeatConduction.jl") include("HeatConduction/HeatConduction.jl")
......
# Default empty implementations of diagnostic_step! and prognostic_step! for boundary layers # Default empty implementations of diagnostic_step! and prognostic_step! for boundary layers
diagnosticstep!(::Top, ::System, state) = nothing diagnosticstep!(::Top, ::CompositeProcess, state) = nothing
prognosticstep!(::Top, ::System, state) = nothing prognosticstep!(::Top, ::CompositeProcess, state) = nothing
diagnosticstep!(::Bottom, ::System, state) = nothing diagnosticstep!(::Bottom, ::CompositeProcess, state) = nothing
prognosticstep!(::Bottom, ::System, state) = nothing prognosticstep!(::Bottom, ::CompositeProcess, state) = nothing
variables(layer::Layer, ps::System) = tuplejoin((variables(layer,p) for p in ps.processes)...) variables(layer::Layer, ps::CompositeProcess) = tuplejoin((variables(layer,p) for p in ps.processes)...)
""" """
interact!(l1::Layer, ps1::System{P1}, l2::Layer, ps2::System{P2}, s1, s2) where {P1,P2} interact!(l1::Layer, ps1::CompositeProcess{P1}, l2::Layer, ps2::CompositeProcess{P2}, s1, s2) where {P1,P2}
Default implementation of `interact!` for multi-process (System) types. Generates a specialized implementation that calls Default implementation of `interact!` for multi-process (CompositeProcess) types. Generates a specialized implementation that calls
`interact!` on all pairs of processes between the two layers. Since it is a generated function, the process matching `interact!` on all pairs of processes between the two layers. Since it is a generated function, the process matching
occurs at compile-time and the emitted code will simply be a sequence of `interact!` calls. Pairs of processes which occurs at compile-time and the emitted code will simply be a sequence of `interact!` calls. Pairs of processes which
lack a definition of `interact!` should be automatically omitted by the compiler. lack a definition of `interact!` should be automatically omitted by the compiler.
""" """
@generated function interact!(l1::Layer, ps1::System{P1}, l2::Layer, ps2::System{P2}, s1, s2) where {P1,P2} @generated function interact!(l1::Layer, ps1::CompositeProcess{P1}, l2::Layer, ps2::CompositeProcess{P2}, s1, s2) where {P1,P2}
p1types = Tuple(P1.parameters) p1types = Tuple(P1.parameters)
p2types = Tuple(P2.parameters) p2types = Tuple(P2.parameters)
crossprocesses = [(i,j) for (i,p1) in enumerate(p1types) for (j,p2) in enumerate(p2types)] crossprocesses = [(i,j) for (i,p1) in enumerate(p1types) for (j,p2) in enumerate(p2types)]
...@@ -25,11 +25,11 @@ lack a definition of `interact!` should be automatically omitted by the compiler ...@@ -25,11 +25,11 @@ lack a definition of `interact!` should be automatically omitted by the compiler
return expr return expr
end end
""" """
diagnosticstep!(l::Layer, ps::System{P}, state) where {P} diagnosticstep!(l::Layer, ps::CompositeProcess{P}, state) where {P}
Default implementation of `diagnosticstep!` for multi-process types. Calls each process in sequence. Default implementation of `diagnosticstep!` for multi-process types. Calls each process in sequence.
""" """
@generated function diagnosticstep!(l::Layer, ps::System{P}, state) where {P} @generated function diagnosticstep!(l::Layer, ps::CompositeProcess{P}, state) where {P}
expr = Expr(:block) expr = Expr(:block)
for i in 1:length(P.parameters) for i in 1:length(P.parameters)
@>> quote @>> quote
...@@ -39,11 +39,11 @@ Default implementation of `diagnosticstep!` for multi-process types. Calls each ...@@ -39,11 +39,11 @@ Default implementation of `diagnosticstep!` for multi-process types. Calls each
return expr return expr
end end
""" """
prognosticstep!(l::Layer, ps::System{P}, state) where {P} prognosticstep!(l::Layer, ps::CompositeProcess{P}, state) where {P}
Default implementation of `prognosticstep!` for multi-process types. Calls each process in sequence. Default implementation of `prognosticstep!` for multi-process types. Calls each process in sequence.
""" """
@generated function prognosticstep!(l::Layer, ps::System{P}, state) where {P} @generated function prognosticstep!(l::Layer, ps::CompositeProcess{P}, state) where {P}
expr = Expr(:block) expr = Expr(:block)
for i in 1:length(P.parameters) for i in 1:length(P.parameters)
@>> quote @>> quote
...@@ -53,11 +53,11 @@ Default implementation of `prognosticstep!` for multi-process types. Calls each ...@@ -53,11 +53,11 @@ Default implementation of `prognosticstep!` for multi-process types. Calls each
return expr return expr
end end
""" """
initialcondition!(l::Layer, ps::System{P}, state) where {P} initialcondition!(l::Layer, ps::CompositeProcess{P}, state) where {P}
Default implementation of `initialcondition!` for multi-process types. Calls each process in sequence. Default implementation of `initialcondition!` for multi-process types. Calls each process in sequence.
""" """
@generated function initialcondition!(l::Layer, ps::System{P}, state) where {P} @generated function initialcondition!(l::Layer, ps::CompositeProcess{P}, state) where {P}
expr = Expr(:block) expr = Expr(:block)
for i in 1:length(P.parameters) for i in 1:length(P.parameters)
@>> quote @>> quote
...@@ -67,11 +67,11 @@ Default implementation of `initialcondition!` for multi-process types. Calls eac ...@@ -67,11 +67,11 @@ Default implementation of `initialcondition!` for multi-process types. Calls eac
return expr return expr
end end
""" """
initialcondition!(l::Layer, ps::System{P}, state) where {P} initialcondition!(l::Layer, ps::CompositeProcess{P}, state) where {P}
Default implementation of `initialcondition!` for multi-process types. Calls each process in sequence. Default implementation of `initialcondition!` for multi-process types. Calls each process in sequence.
""" """
@generated function initialcondition!(l1::Layer, ps1::System{P1}, l2::Layer, ps2::System{P2}, s1, s2) where {P1,P2} @generated function initialcondition!(l1::Layer, ps1::CompositeProcess{P1}, l2::Layer, ps2::CompositeProcess{P2}, s1, s2) where {P1,P2}
p1types = Tuple(P1.parameters) p1types = Tuple(P1.parameters)
p2types = Tuple(P2.parameters) p2types = Tuple(P2.parameters)
crossprocesses = [(i,j) for (i,p1) in enumerate(p1types) for (j,p2) in enumerate(p2types)] crossprocesses = [(i,j) for (i,p1) in enumerate(p1types) for (j,p2) in enumerate(p2types)]
...@@ -84,11 +84,11 @@ Default implementation of `initialcondition!` for multi-process types. Calls eac ...@@ -84,11 +84,11 @@ Default implementation of `initialcondition!` for multi-process types. Calls eac
return expr return expr
end end
""" """
observe(::Val{name}, l::Layer, ps::System{P}, state) where {P} observe(::Val{name}, l::Layer, ps::CompositeProcess{P}, state) where {P}
Default implementation of `observe` for multi-process types. Calls each process in sequence. Default implementation of `observe` for multi-process types. Calls each process in sequence.
""" """
@generated function observe(val::Val{name}, l::Layer, ps::System{P}, state) where {name,P} @generated function observe(val::Val{name}, l::Layer, ps::CompositeProcess{P}, state) where {name,P}
expr = Expr(:block) expr = Expr(:block)
for i in 1:length(P.parameters) for i in 1:length(P.parameters)
@>> quote @>> quote
......
...@@ -3,7 +3,7 @@ module Setup ...@@ -3,7 +3,7 @@ module Setup
import ForwardDiff import ForwardDiff
import ReverseDiff import ReverseDiff
import CryoGrid: Layer, Top, Bottom, SubSurface, Process, SubSurfaceProcess, BoundaryProcess, System import CryoGrid: Layer, Top, Bottom, SubSurface, Process, SubSurfaceProcess, BoundaryProcess, CompositeProcess
import CryoGrid: variables, initialcondition!, prognosticstep!, diagnosticstep!, interact!, observe import CryoGrid: variables, initialcondition!, prognosticstep!, diagnosticstep!, interact!, observe
using CryoGrid.InputOutput using CryoGrid.InputOutput
......
...@@ -106,5 +106,5 @@ end ...@@ -106,5 +106,5 @@ end
# Auto-detect Jacobian sparsity for problems with one or more heat-only layers. # Auto-detect Jacobian sparsity for problems with one or more heat-only layers.
# Note: This assumes that the processes/forcings on the boundary layers do not violate the tridiagonal structure! # Note: This assumes that the processes/forcings on the boundary layers do not violate the tridiagonal structure!
# Unfortunately, the Stratigraphy type signature is a bit nasty to work with :( # Unfortunately, the Stratigraphy type signature is a bit nasty to work with :(
const HeatOnlySetup = CryoGridSetup{<:Stratigraphy{N,<:Tuple{TTop,Vararg{<:Union{<:StratNode{<:SubSurface, <:System{<:Tuple{<:Heat}}},TBot}}}}} where {N,TTop,TBot} const HeatOnlySetup = CryoGridSetup{<:Stratigraphy{N,<:Tuple{TTop,Vararg{<:Union{<:StratNode{<:SubSurface, <:CompositeProcess{<:Tuple{<:Heat}}},TBot}}}}} where {N,TTop,TBot}
JacobianStyle(::Type{<:HeatOnlySetup}) = TridiagJac() JacobianStyle(::Type{<:HeatOnlySetup}) = TridiagJac()
struct StratNode{TLayer,TProcess,name} struct StratNode{TLayer,TProcess,name}
layer::TLayer layer::TLayer
process::TProcess process::TProcess
StratNode(name::Symbol, layer::TLayer, process::TProcess) where {TLayer<:Layer,TProcess<:System} = StratNode(name::Symbol, layer::TLayer, process::TProcess) where {TLayer<:Layer,TProcess<:CompositeProcess} =
new{TLayer,TProcess,name}(layer,process) new{TLayer,TProcess,name}(layer,process)
end end
""" """
...@@ -13,9 +13,9 @@ nodename(::Type{<:StratNode{L,P,name}}) where {L,P,name} = name ...@@ -13,9 +13,9 @@ nodename(::Type{<:StratNode{L,P,name}}) where {L,P,name} = name
Base.show(io::IO, node::StratNode{L,P,name}) where {L,P,name} = print(io, "$name($L,$P)") Base.show(io::IO, node::StratNode{L,P,name}) where {L,P,name} = print(io, "$name($L,$P)")
# Constructors for stratigraphy nodes # Constructors for stratigraphy nodes
Top(boundaries::BoundaryProcess...) = StratNode(:top, Top(), System(boundaries...)) Top(boundaries::BoundaryProcess...) = StratNode(:top, Top(), CompositeProcess(boundaries...))
Bottom(boundaries::BoundaryProcess...) = StratNode(:bottom, Bottom(), System(boundaries...)) Bottom(boundaries::BoundaryProcess...) = StratNode(:bottom, Bottom(), CompositeProcess(boundaries...))
Ground(name::Symbol, layer::SubSurface, processes::SubSurfaceProcess...) = StratNode(name, layer, System(processes...)) Ground(name::Symbol, layer::SubSurface, processes::SubSurfaceProcess...) = StratNode(name, layer, CompositeProcess(processes...))
""" """
Stratigraphy{N,TNodes,TBounds} Stratigraphy{N,TNodes,TBounds}
......
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