Sinks
Sinks are used to simulation data flowing through the connections of the model. The data processing is done online during the simulation. Sink type is a subtype of AbstractSink. An AbstractSink is also a subtype of AbstractComponent (see Components), so an AbstractSink instance has a trigger link to be triggered and a handshake link to signal that evolution is succeeded. In addition, an AbstractSink has an input buffer inbuf whose mode is Cyclic. When an AbstractSink instance is triggered through its trigger link, it basically reads its incoming data and writes to its input buffer inbuf. When its input buffer inbuf is full, the data in inbuf is processed according to the type of AbstractSink. Causal provides three concrete subtypes of AbstractSink which are Writer, Printer and Scope. As the operation of an AbstractSink just depends on incoming data, an AbstractSink does not have an output.
Full API
Causal.@def_sink — Macro@def_sink exwhere ex is the expression to define to define a new AbstractSink component type. The usage is as follows:
@def_sink struct MySink{T1,T2,T3,...,TN, A} <: AbstractSink
param1::T1 = param1_default # optional field
param2::T2 = param2_default # optional field
param3::T3 = param3_default # optional field
⋮
paramN::TN = paramN_default # optional field
action::A = action_function # mandatory field
endHere, MySink has N parameters and action function
action function must have a method action(sink::MySink, t, u) where t is the time data and u is the data flowing into the sink.
New static system must be a subtype of AbstractSink to function properly.
Example
julia> @def_sink struct MySink{A} <: AbstractSink
action::A = actionfunc
end
julia> actionfunc(sink::MySink, t, u) = println(t, u)
actionfunc (generic function with 1 method)
julia> sink = MySink();
julia> sink.action(sink, ones(2), ones(2) * 2)
[1.0, 1.0][2.0, 2.0]