I have a model representing some chemical process, and I want the reaction model to be switchable between an absorption and a desorption class (which define the respective model), based on a 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 like:
Sorption TestAbsorption(absorbing=true); // uses the absorption model
Sorption TestDesorption(absorbing=false); // uses the desorption model
Of course, this way does not work. absorbing
is known at compile time, so I have a feeling it should be ok to achieve this somehow.
I tried to use replaceable
, but I don't want to (unnecessarily) make two separate subclasses of Sorption
just to switch the type of reaction model. It seems replaceable/redeclare is only useable when inheriting, but I may be wrong? Is there a way to do what I want?
AbsorptionModel
and DesorptionModel
both inherit from the same base class, and have identical interfaces, if that is relevant.