Subsystem
Construction of SubSystems
A SubSystem
consists of connected components. Thus, to construct a SubSystem
, we first construct components, connect them and specify the input and output of SubSystem
. See the basic constructor.
Jusdl.Components.Systems.SubSystems.SubSystem
— TypeSubSystem(components, input, output)
Constructs a SubSystem
consisting of components
. input
and output
determines the inpyt and output of SubSystem
. input
and output
may be of type Nothing
, Bus
of Vector{<:Link}
.
Basic Operation of SubSystems
The operation of a SubSystem
is very similar to that of a StaticSystem
. The only difference is that when a SubSystem
is triggered through its trigger
link, it distributes the trigger to the trigger links of its components. Then, each of the components of the SubSystem
takes steps individually.
Let us construct a subsystem consisting of a generator and an adder.
julia> using Jusdl # hide
julia> gen = ConstantGenerator()
ConstantGenerator(amp:1.0)
julia> adder = Adder(Bus(2))
Adder(signs:(+, +), input:Bus(nlinks:2, eltype:Link{Float64}, isreadable:false, iswritable:false), output:Bus(nlinks:1, eltype:Link{Float64}, isreadable:false, iswritable:false))
Connect the generator and adder.
julia> connect(gen.output, adder.input[1])
We are ready to construct a SubSystem
.
julia> sub = SubSystem([gen, adder], [adder.input[2]], adder.output)
SubSystem{Bus{Link{Float64}},Bus{Link{Float64}},Link{Float64},Link{Bool},Array{AbstractComponent,1}}(Bus(nlinks:1, eltype:Link{Float64}, isreadable:false, iswritable:false), Bus(nlinks:1, eltype:Link{Float64}, isreadable:false, iswritable:false), Link(state:open, eltype:Float64, hasmaster:false, numslaves:0, isreadable:false, iswritable:false), Link(state:open, eltype:Bool, hasmaster:false, numslaves:0, isreadable:false, iswritable:false), Callback[], UUID("d309f9ef-7203-4684-bfb8-5eb5d4b05b0b"), AbstractComponent[ConstantGenerator(amp:1.0), Adder(signs:(+, +), input:Bus(nlinks:2, eltype:Link{Float64}, isreadable:false, iswritable:false), output:Bus(nlinks:1, eltype:Link{Float64}, isreadable:false, iswritable:false))])
To trigger the sub
, we need to launch it,
julia> t = launch(sub)
2-element Array{Tuple{Task,Task},1}:
(Task (runnable) @0x00007f70295cba90, Task (runnable) @0x00007f70295cb820)
(Task (runnable) @0x00007f70295e5ae0, Task (runnable) @0x00007f70295e5870)
sub
is ready to be triggered,
julia> drive(sub, 1.)
Put some data to the input of sub
.
julia> put!(sub.input, [1.])
1-element Array{Float64,1}:
1.0
The step needs to be approved.
julia> approve(sub)
true
Now print the data written to the outputs of the components of sub
.
julia> sub.components[1].output[1].buffer.data[1]
1.0
julia> sub.components[2].output[1].buffer.data[1]
2.0
Note that when sub
is triggered, sub
transfer the trigger to all its internal components.