9

I would like to understand how Simulink simulation engine works. Does it use a discrete event simulation mecanism (then how continous time is handled ?) ? Does it rely on a static cycle-based code generation ? Or ?

meager
  • 209,754
  • 38
  • 307
  • 315
JCLL
  • 5,059
  • 4
  • 38
  • 62

2 Answers2

4

Before the first cycle, it figures out the order of execution of the blocks (starting with the ones that don't require inputs from any other blocks)

Each cycle, it calculates the output of each block based on the inputs and the block's code. Each block's code is static, it mostly existed before you put the model together. (I don't know if block options actually change the code, or if they are evaluated only at runtime, at each iteration.)

If the simulation step is variable, than each cycle it calculates the size of the next step, based mainly on how fast the model's variables are changing. The faster they change, the smaller the step size should be, so a briefly high derivative isn't assumed to last much longer than it should. (I don't know the details of this calculation, perhaps someone else can shed a light?) So, "continuous" simulation, or variable-step, only means Simulink will make an educated guess each cycle about what step size is small enough to keep time quantization error at an acceptable level. Truly continuous simulation is literally impossible over a completely digital hardware, such as your computer's processor.

Emilio M Bumachar
  • 2,352
  • 2
  • 24
  • 29
  • Thx. That's what I was thinking also. Sorry for this odd question, but how did you get this info ? What level of confidence do you have ? – JCLL Dec 23 '10 at 15:00
  • @JLCC Not much. I have years of experience using Simulink, but that info comes from inferring and getting clues from the documentation (there are a lot of clues there, but I never found a straightforward description). What gives me the most confidence about what I said here is my limited knowledge of s-functions, which are blocks whose code you write yourself. I recommend reading into those, they provide insights about what is going on. What I said about the variable step calculation algorythm is very low confidence. But I'm very sure truly continuous simulation is impossible, though can't ref – Emilio M Bumachar Dec 23 '10 at 16:11
0

I'm certainly not an expert, but the answer is likely to be 'it depends'.

Simulink certainly uses numerical integration for some things, and for some integrators you will end up with discrete time steps. For other integrators, the time-step can be altered as the simulation is running - this is particularly important for simulating 'stiff' sets of equations.

Andrew Walker
  • 36,318
  • 7
  • 54
  • 80