使用Simulink进行协同仿真:逐步执行和与外部应用程序交换参数 [英] Co-Simulation with Simulink: stepwise execution and interchange of parameters with external application
问题描述
我必须实现与Simulink和外部应用程序(LS-DYNA)的耦合仿真。领先的模拟在Simulink中完成,我想要实现一个功能块如下:
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:
互动是使用Windows的cmd,所以Simulink块应该做以下:
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
确切的代码在这里不应该相关。我的问题是,我如何实现接口到simulink模型?我可以只使用一个自定义功能块,使用我上面的代码,它会工作吗?
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:
然后使用如下的while循环:
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 ...)
可以逐步执行simulink模拟。我怎么能认识到? (其余的模拟包含复杂的控制算法,派生和集成)
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.
与simulink耦合模拟的任何提示和经验高度赞赏!
谢谢!
Any hints and experiences in coupled simulations with simulink are highly appreciated! Thank you!
推荐答案
据我所知,将simulink连接到其他应用程序的正确写
S函数。如果外部应用程序有一个C / C ++接口,这也应该是性能最好的解决方案:
http://www.mathworks.de/de/help/simulink/create-cc-s-functions.html
As far as I know the "proper" way to couple simulink to other applications would be to write S-Functions. If the external application has a C/C++ interface this should also by far be the best solution performance-wise: http://www.mathworks.de/de/help/simulink/create-cc-s-functions.html
这篇关于使用Simulink进行协同仿真:逐步执行和与外部应用程序交换参数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!