I am trying to build a component which can be connected through one of two connectors based on a parameter. In the following example, depending on the boolean value, only one connector will be used at a time.
model component_2_connectors
parameter Boolean isRotational = true;
Real flux;
Real potential;
Modelica.Mechanics.Rotational.Interfaces.Flange_a flange_a if isRotational annotation (Placement(transformation(extent={{-110,30},{-90,50}})));
Modelica.Mechanics.Translational.Interfaces.Flange_a flange_a1 if not(isRotational) annotation (Placement(transformation(extent={{-110,-50},{-90,-30}})));
equation
if isRotational then
flux = flange_a.tau;
potential = flange_a.phi;
else
flux = flange_a1.f;
potential = flange_a1.s;
end if;
annotation ();
end component_2_connectors;
- So I have read several threads regarding conditional declaration (especially this one #14668468).
- I thought of extending two partial models containing each a connector and the associated equations, but I did not find a way to conditionnaly extend a partial model.
- I don't mind having both connectors enabled at all time, as long as only one is visible in the icon view (see below). But did not work either.
model component_2_connectors
parameter Boolean isRotational = true;
Real flux;
Real potential;
Modelica.Mechanics.Rotational.Interfaces.Flange_a flange_a annotation (Placement(transformation(extent={{-110,30},{-90,50}}), **visible= isRotational**));
Modelica.Mechanics.Translational.Interfaces.Flange_a flange_a1 annotation (Placement(transformation(extent={{-110,-50},{-90,-30}}), **visible= not(isRotational)**));
equation
if (cardinality(flange_a) == 0) then
flange_a.tau = 0;
flange_a.phi = 0;
end if;
if (cardinality(flange_a1) == 0) then
flange_a1.f = 0;
flange_a1.s = 0;
end if;
if isRotational then
flux = flange_a.tau;
potential = flange_a.phi;
else
flux = flange_a1.f;
potential = flange_a1.s;
end if;
annotation ();
end component_2_connectors;
Do you have any suggestion?