ThermoSysPro icon indicating copy to clipboard operation
ThermoSysPro copied to clipboard

Unbalanced connectors

Open maltelenz opened this issue 2 months ago • 5 comments

The library has unbalanced connectors, which is invalid Modelica. Here is an example error given by System Modeler:

Error: ThermoSysPro.FlueGases.PressureLosses.SingularPressureLoss: Unbalanced connector. singularPressureLoss.C2 has 0 flow signals and 7 potential signals.

This prevents the complete library from working in tools that implement the rules of the specification.

maltelenz avatar Nov 12 '25 09:11 maltelenz

ThermoSysPro does not use the flow and stream keywords by design. What are the tools that implement this specific rule ?

Sonyoyo avatar Nov 12 '25 13:11 Sonyoyo

I'm working on the Wolfram System Modeler tool, which does check this rule.

I would hope that all tools implement the rules in the specification to the best of their ability, otherwise what is the point of having a language standard? :-)

maltelenz avatar Nov 12 '25 14:11 maltelenz

A solution to this problem that I encountered in other libraries is to used overdetermined types with a residual size of 0.

qlambert-pro avatar Nov 17 '25 14:11 qlambert-pro

Could you please provide an exemple of the solution using "overdetermined types with a residual size of 0"?

Sonyoyo avatar Nov 21 '25 15:11 Sonyoyo

It is used in the PowerGrids library to define [ReferenceAngularVelocityPu](https://github.com/PowerGrids/PowerGrids/blob/d8786ab95d12ad6055a29821cf410a97971e6467/PowerGrids/Types.mo#L28C8-L28C34]. It is also used in the MSL to define Modelica.Electrical.QuasiStatic.Types.Reference.

In your case, that would mean defining the following type:

record Fuel
  Units.SI.MassFlowRate Q "Fuel mass flow rate";
  Units.SI.Temperature T "Fuel temperature";
  Units.SI.AbsolutePressure P "Fuel pressure";
  Units.SI.SpecificEnergy LHV "Lower heating value";
  Units.SI.SpecificHeatCapacity cp "Fuel specific heat capacity at 273.15 K";
  Real hum "Fuel humidity (%)";
  Real Xc "C mass fraction";
  Real Xh "H mass fraction";
  Real Xo "O mass fraction";
  Real Xn "N mass fraction";
  Real Xs "S mass fraction";
  Real Xashes "Ashes mass fraction";
  Real VolM "Percentage of volatile matter";
  Units.SI.Density rho "Fuel density";

  function equalityConstraint
    input Fuel fuel1;
    input Fuel fuel2;
    output Real residue[0];
  algorithm
  end equalityConstraint;
end Fuel;

and change the FuelInlet (and friends) to the following:

  connector FuelInlet "Fuel inlet connector"
    extends Fuel;
    input Boolean a = true "Pseudo-variable for the verification of the connection orientation";
    output Boolean b "Pseudo-variable for the verification of the connection orientation";
  end FuelInlet;

with this solution you need to add calls to Connections.root at the sources of the signal. That is, adding Connections.root(C) in the equation section of ThermoSysPro.Combustion.BoundaryConditions.FuelSourcePQ.

Now that I am looking more closely at your use case, a simpler alternative may be:

record Fuel
  Units.SI.MassFlowRate Q "Fuel mass flow rate";
  Units.SI.Temperature T "Fuel temperature";
  Units.SI.AbsolutePressure P "Fuel pressure";
  Units.SI.SpecificEnergy LHV "Lower heating value";
  Units.SI.SpecificHeatCapacity cp "Fuel specific heat capacity at 273.15 K";
  Real hum "Fuel humidity (%)";
  Real Xc "C mass fraction";
  Real Xh "H mass fraction";
  Real Xo "O mass fraction";
  Real Xn "N mass fraction";
  Real Xs "S mass fraction";
  Real Xashes "Ashes mass fraction";
  Real VolM "Percentage of volatile matter";
  Units.SI.Density rho "Fuel density";
end Fuel;

connector FuelInlet = input Fuel "Flue gases inlet fluid connector";

your connectors would, then, probably benefit from the mayOnlyConnectOnce annotation.

connector FlueGasesOutlet = output FlueGases "Flue gases outlet fluid connector" annotation(mayOnlyConnectOnce = "Should only connect once per element! " );

qlambert-pro avatar Nov 24 '25 08:11 qlambert-pro

Would you like me to make a pull request?

qlambert-pro avatar Nov 28 '25 06:11 qlambert-pro