Based on the answer of Markus A. I produced an example of how to use the connector sizing in order to avoid to use the cardinality with a ThermoSysPro
connector.
I deleted the placement annotation part and the code lines with h
, h_vol
and Q
from ThermoSysPro
to improve readability.
model Example_pressure_source_sizing_connector_without_cardinality
parameter Modelica.Units.SI.AbsolutePressure P0=2e5 "Fluid pressure if not connected";
parameter Integer nPortsP(min=0)=0 "Number of Pressure ports" annotation (Dialog(connectorSizing=true));
Modelica.Blocks.Interfaces.RealInput InputP[nPortsP];
ThermoSysPro.WaterSteam.Connectors.FluidInlet C;
equation
/* Pression */
if nPortsP == 0 then /*if there is no connection then use the default pressure defined in parameter*/
C.P = P0;
elseif nPortsP == 1 then /* if there is a connection then use the signal of the real input */
C.P = InputP[1];
else
assert(nPortsP<=1, "To many connection to the port", AssertionLevel.error); /*assert to be sure to have only one connection*/
end if;
end Example_pressure_source_sizing_connector_without_cardinality;
For me it works pretty well on Dymola 2022, and it avoids me to use a conditional connector with the need to use a boolean parameter (as the example of: Modelica.Electrical.Analog.Interfaces.ConditionalHeatPort
etc.)
EDIT :
There is a limitation to this approach.
For now, on Dymola 2022, It is not working for an Input signal sized as a vector. (and was not working either with cardinality as far as I know).
For example :
With a connector :
connector Connector_vector
Modelica.Units.SI.AbsolutePressure P_F[5];
end Connector_vector;
Used within this model :
model Pressure_source_sizing_connector
parameter Modelica.Units.SI.AbsolutePressure P_F0[5]={30,30,30,30,30} "Fluid pressure if not connected";
parameter Integer nPortsP(min=0)=0 "Number of Pressure ports" annotation (Dialog(connectorSizing=true));
parameter Integer vector_size = 5;
Modelica.Blocks.Interfaces.RealInput InputP[nPortsP*vector_size];
Connector_vector Connector_vector;
equation
/* Pression */
if nPortsP == 0 then /*if there is no connection then use the default pressure defined in parameter*/
Connector_vector.P_F = P_F0;
elseif nPortsP == 1 then /* if there is a connection then use the signal of the real input */
Connector_vector.P_F = InputP;
else
assert(nPortsP<=1, "To many connection to the port", AssertionLevel.error); /*assert to be sure to have only one connection*/
end if;
end Pressure_source_sizing_connector;
And connect it to a combitable of the same size :
model Test_connexion
Pressure_source_sizing_connector example_pressure_source_sizing_connector;
Modelica.Blocks.Sources.CombiTimeTable combiTimeTable(table=[0.0,0.0,0.0,0.0,0.0,0.0; 1,1,2,3,4,5]);
equation
connect(combiTimeTable.y, example_pressure_source_sizing_connector.InputP);
end Test_connexion;
There is not a nPortsP modifier. Nevertheless If I add it manually
model Test_connexion
Pressure_source_sizing_connector example_pressure_source_sizing_connector(nPortsP=1);
Modelica.Blocks.Sources.CombiTimeTable combiTimeTable(table=[0.0,0.0,0.0,0.0,0.0,0.0; 1,1,2,3,4,5]);
equation
connect(combiTimeTable.y, example_pressure_source_sizing_connector.InputP);
end Test_connexion;
There is no problem. Maybe it will be fixed one day.