Type of switch based on a boolean parameter (no inheritance)?

I have a model representing some chemical process, and I want the reaction model to be switched between the absorption and desorption class (which defines the corresponding model) based on the Boolean parameter. I tried to do it like this:

model Sorption
  boolean parameter absorbing;
  AbsorptionModel if absorbing else Desorptionmodel reaction;
equation
  reaction.T = T; //dummy usage
  ...

Use it as:

Sorption TestAbsorption(absorbing=true); // uses the absorption model
Sorption TestDesorption(absorbing=false); // uses the desorption model

Of course, this method does not work. absorbingknown at compile time, so I feel that it must be good to achieve this somehow.

I tried to use replaceable, but I don't want (optionally) to make two separate subclasses Sorptionjust to switch the type of reaction model. Removable / redeclare seems to be applicable only for inheritance, but can I be wrong? Is there a way to do what I want?

AbsorptionModel DesorptionModel , .

+4
1

, , , , ( ).

model Sorption
  boolean parameter absorbing;
  replaceable model RModel = AbsorptionModel;
  RModel reaction;
equation
  reaction.T = T; //dummy usage
  ...

:

Sorption TestAbsorption(redeclare model RModel = AbsorptionModel); // uses the absorption model
Sorption TestDesorption(redeclare model RModel = Desorptionmodel); // uses the desorption model
+4

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


All Articles