Using units / components in Modelica based on a boolean condition

Let's say I probably want to import a component based on some condition, let's say a Boolean variable. I tried this, but it gives me an error message. For example, consider the following code:

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;

This is an intuitively safe statement, and as long as the logical variable is correct, it will work as intended. For some units, for example, fluids from the Standardlica standard library, it also works with size [0]. But as soon as I turn the variable to false, I run into errors that many components are not compatible with the "zero size". I had this problem, for example, using MassFlowSources in the Modelica standard library. Is there a sleek / elegant way around this? Thanks in advance!

+1
source share
1 answer

You can use conditional components in Modelica.

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

-. , .

+3

Source: https://habr.com/ru/post/1545865/


All Articles