How to compose discrete-time static and dynamic models for systems simulation similar to Simulink?

Hi all,

I’m searching for a Simulink replacement. The main purpose is to have a simplified system simulation for quick prototyping. The domain is mechanical/electrical

Usually, I have 4 kinds of models/subsystems

  1. Sensor models that measure some ideal physical values and perturb them according to the model to generate realistic measurements
  2. Environmental models to create ideal input data for 1., such as trajectory generators, temperature settings, orientation, simulation time etc.
  3. Compensation models that try to invert 1., i.e. are algorithms that try to figure out the ideal input data from noisy measurement data
  4. Logging & plotting modules

Details:

  1. Are discrete models based on difference equations, LSTM models, simple lookup tables, digital filters (state space or transfer function formulation), usually a non-deterministic portion is included to simulate noise and drift (integrated noise)
  2. Basically handles external parameter sets, loads data or generates data based on mechanically inspired equations. It’s discretized currently, but in theory it’s in continuous time
  3. Is the rapid prototyping part. I want to exchange these algorithms quickly, ideally tune and optimize its parameters according to some output error metric. Examples are State Space Observer, (Extended) Kalman Filters, discrete filters, switching elements based on the value of input data, complementary filters, LSTM, … That part might get implemented in a µC when the optimal approach has been found
  4. Not much to say, save results, errors, plots, push it to a database, things like that

Is there anything in the awesome Julia ecosystem that could handle that? So far there’s no need to mix continuous and discrete modeling, I guess, discrete systems are sufficient for now. Of course 2. mimics the environment and therefore is continuous, but since this might make things much more complicated, I would be happy with staying in the discrete time domain.

Any input is very welcome :slight_smile:
Thank you very much!
Jan

edit: I forgot that of course I’ve had a look at ModelingToolkit.jl and Modia.jl. MTK seems not to have discrete states implemented yet, see Discrete-Time (Sub-)Systems · Issue #894 · SciML/ModelingToolkit.jl (github.com) and Allowing discrete Difference equations in ODESystem · Issue #1122 · SciML/ModelingToolkit.jl (github.com).
Modia seems also not to support discrete time modeling?

DifferentialEquations.jl seem to support discrete ODEs. Is this the way to go? Discrete Solvers · DifferentialEquations.jl (sciml.ai)

Probably I’m getting something very wrong and discrete time modeling is a subset of all the great tools already implemented :slight_smile:

Thanks!

3 Likes

The intention is for MTK to handle hybrid discrete/continuous systems. There’s currently a large number of issues open labeled “discrete-time”, so for now, MTK is not the solution. Calling DifferentialEquations directly and using PeriodicCallback etc. is a viable alternative, but you won’t get the nice modeling language.

Hi @baggepinnen, thank you very much, I saw that discrete-time label after writing my post. I see, you and @ohmsweetohm1 are pretty active there, thanks for your work! I can try to assist, but it looks like the challenges are located deep inside the architecture of MTK.

Is anybody working actively on the issues, since nobody is assigned? However, I’m afraid this won’t be a short-term solution anyway, so I’d either need to stick to Simulink for now or to look at alternatives :confused:

Will have a look at DifferentialEquations.jl and some Python stuff, like Mathematical Formulation — SimuPy 1.0.0 documentation to come up with comparable systems.

edit: what’s about https://zekeriyasari.github.io/Causal.jl/?

Is the status mentioned above still the same? MTK + discrete time/events is not a smooth experience?
Unfortunately, looks like Causal.jl is not very actively maintained.

Would a solution be to put specific MTK models into a FMU and integrate that into Simulink? Does anybody have experience with that?

Thanks

Unfortunately, yes. There are some highly experimental features available underneath the hood, but they are not exported, nor documented and I do not recommend relying on them since they might break several times before they are ready.

See tests here and here for examples of how the interface might look when it’s ready.