How does one add a proportional constant k and a damping constant b to this IOBlock to setup a spring mass damper transfer function?
@parameters t M F(t)
@variables x(t) v(t)
D = Differential(t)
msd = IOBlock([D(v) ~ F/M, D(x) ~ v], # define the equation
[F], # inputs of the system
[x], # outputs of the system
name = :msd)
I’ve created BlockSystems.jl at a time where component based modeling was far more complicated in vanilla MTK than it is now. Since it is/was highly specialized for my specific usecase I would not necessarily recommend it for starting a new project now – i think it is worth using MTK directly. Eventually I want to revisit BlockSystems to make it a much thinner MTK wrapper than it is now, but that for sure will be quite breaking.
If you still want to use BlockSystems: in order to solve the system you always have to generate a callable Julia function based on the symbolic model. You can use generate_io_function for a low level interface or
for a more high level interface. The ordering of states and parameters can be passed explicitly. Otherwise they’ll match the order of iob.iparams (the internal parameters) and states = vcat(iob.outputs, iob.istates) (stacked vector of output states and internal states).
However in order to create a ODEFunction/ODEProblem you need to close all the inputs first. There are plenty options to do that, either create other blocks and connect them or use something like
closed_spacecraft = set_input(spacecraft, F => sin(omega * t))
to direclty close the input with that specific function. Now closed_spacecraft.iparams should show [:omega, :KK, :B] in some order.
If you don’t want to specify the parameters at solve time you may also bake them into the generated code by something like