.ModelicaReference.Operators.'cardinality()'

Information

Number of connectors in connection. This is a deprecated operator. It should no longer be used, since it will be removed in one of the next Modelica releases.

Syntax

cardinality(c)

Description

Returns the number of (inside and outside) occurrences of connector instance c in a connect statement as an Integer number.

[The cardinality operator allows the definition of connection dependent equations in a model.]

Instead of the cardinality(..) operator, often conditional connectors can be used, that are enabled/disabled via Boolean parameters.

Examples

connector Pin
  Real      v;
  flow Real i;
end Pin;
model Resistor
   Pin p, n;
equation
   // Handle cases if pins are not connected
      if cardinality(p) == 0 and cardinality(n) == 0 then
         p.v = 0;
         n.v = 0;
      elseif cardinality(p) == 0 then
         p.i = 0;
      elseif cardinality(n) == 0 then
         n.i = 0;
      end if;
   // Equations of resistor
      ...
end Resistor;

Generated at 2024-03-28T19:15:55Z by OpenModelicaOpenModelica 1.22.3 using GenerateDoc.mos