I have to realise a coupled simulation with Simulink and an external application (LS-DYNA). The leading simulation is done in Simulink, where I want to implement a function block as following:
The interaction is done using the cmd of windows, so the Simulink block should do the following:
function [ x,y ] = ExternalSimlation( u,v )
% open the windows cmd and run the external simulation by passing u and v
[status,cmdout] = system( 'command for executing the external simulation -u -v');
function [ x,y ] = readcmd( cmdout )
%algorithm to evaluate the cmd output
end
[x,y] = readcmd(cmdout);
end
The exact code should NOT be relevant here. My question is, how can I implement the interface into the simulink model? Can I just use one of the custom function blocks, use my code above, and it will work? But which one, I don't really see the difference.
OR, my other idea was to build something like the following:
And then use a while-loop like this:
while ... do
[u,v] = sim('model', 'x',x,'y', y, 'some option just to run a single step');
[x,y] = ExternalSimlation( u,v )
[u,v] = sim('model' .... next step ...)
to execute the simulink simulations step-by-step. How can I realise that? (The rest of the simulation contains complex control algorithms, derivations and integrations)
I don't have experiences in writing batch files, but that seems possible for me as well.
If you wonder why I'm not just testing things out, it's because I don't have the external application available (I just know how the in- and output works) and don't want to waste time in coding a substitutional application just for testing, if it's not possible at all.
Any hints and experiences in coupled simulations with simulink are highly appreciated! Thank you!