I was undecided about where to begin the posts about glueing FMI2 calls to the Scicos Block interface, mentioned in the last post, so I’ll take the most obvious route and start from the beginning…
… of block processing/simulation, I mean. And that is triggered by the Initialization flag (4):
“Initialization: At the begining of the simulation, this job is called under flag=4 to initialize continuous and discrete states (if necessary). It also initialize the output port of the block. This function is not used in all of the blocks, it is used for blocks that needed dynamically allocated memory (the allocation is done under this flag), for blocks that read and write data from files, for opening a file, or by the scope to initialize the graphics window.”
So, aside from continuos/discrete state and output initialization (in arrays x, z and outptr, respectively), this flag also indicates the moment when all manual memory allocations (if needed) should be performed for a given block.
That’s our case, because FMI2 API involves allocation of components to hold internal state values.
But, as scicos_block is the only data structure provided at the computational function call, where will they be stored ?
Taking a look at scicos_block4.h header, it seems there is a field intended for this very role:
Then, assuming that the work pointer is the one to be used, we initialized the block inside our Scicos/FMI2 wrapper:
(Error handling is not shown to simplify visualization)
[De/Re]initialization
As we are describing initialization procedures for FMI2-based blocks, it makes sense to also talk about ending and reinitializing them:
flags
inputs
outputs
description
...
...
...
...
5
x, z, inptr
x, z, outptr
final call to block for ending the simulation
6
t, nevprt, x, z, inptr, mode, phase
x, z, outptr
reinitialization (if needed)
...
...
...
...
From the documentation:
“Ending: This job is called when flag=5 at the end. This case is used to close files opened by the block at the begining or during the simulation, to free the allocated memory, etc.”
“Reinitialization: This job is called under flag=6. In this case, the values of the inputs are available and the function create a fixed point iteration for the outputs of the block. On this occasion, the function can also reinitialize its initial states.”
Be aware that this implementation is subject to change, as I better understand of how to deal with the API. But, for now, that’s all I have to show you.
Thanks for sticking with me one more time. See Ya !