问题
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 ?
回答1:
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.
回答2:
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.
来源:https://stackoverflow.com/questions/3884948/how-does-simulink-simulation-engine-work