2013-08-07 30 views
1

比方說,我可以根據某種條件導入組件,比如我想說一個布爾變量。我試過這個,但它給了我一個錯誤信息。例如,考慮下面的代碼:基於布爾條件在Modelica中使用單元/組件

model myNewModel 
    parameter Boolean use_Something; 
    myLibrary.myComponent component[if use_Something then 1 else 0]; 
    // In other words (pseudo): 
    // if use_Something then 'Import The Component' else 'Do Nothing At All'; 
end myNewModel; 

這,直觀,安全的語句,只要布爾變量是真實的,因爲預期它會工作。對於某些單位,例如Modelica標準庫的fluidports,它也可以使用[0]大小。但是,只要將變量設置爲false,我就會遇到有關許多組件與「零大小」不兼容的錯誤。例如,我遇到了Modelica標準庫中的MassFlowSources問題。有沒有一種平滑/優雅的方法來解決這個問題?提前致謝!

回答

3

您可以在Modelica中使用條件組件。

model myNewModel 
    parameter Boolean use_Something; 
    myLibrary.myComponent component if use_Something; 
end myNewModel;

此組件可能只能用於連接語句。如果條件爲false,則該工具會忽略這些連接。

+0

謝謝!這解決了我的問題。 – fredrikg