zekeriyasari / Causal.jl

Causal.jl - A modeling and simulation framework adopting causal modeling approach.
https://zekeriyasari.github.io/Causal.jl/dev/
Other
115 stars 7 forks source link

Single step size simulation #76

Closed zekeriyasari closed 3 years ago

zekeriyasari commented 3 years ago

Single-step size simulation should be possible. This can be achieved by updating the buffer sizes of the sink components in the model.

zekeriyasari commented 3 years ago

Example script

using Causal

# Construct model 
@defmodel model begin 
    @nodes begin 
        gen = SinewaveGenerator() 
        ds = ContinuousLinearSystem(
            A = fill(-1., 1, 1), 
            B = fill(1., 1, 1), 
            C = fill(-1., 1, 1), 
            D = fill(0., 1, 1),
            state = [1.], 
            t = 0.,
            input = Inport(), 
            output = Outport()
        )
        writer = Writer(buflen = 1) # Single-length buffer 
    end 
    @branches begin 
        gen => ds
        ds => writer 
    end 
end 

# Simulate model 
clk = Clock(1) 
sim = simulate!(model, clk)

# Read simulation data 
t, x = getcomponent(model, :writer) |> read 
@show t, x;