ModelicaSpecification icon indicating copy to clipboard operation
ModelicaSpecification copied to clipboard

Question about connector inputs

Open casella opened this issue 3 years ago • 3 comments

The MLS, Section 4.7, Example 3, presents this use pattern

 partial model BaseProperties "Interface of medium model"
  parameter Boolean preferredStates = false;
  constant Integer nXi "Number of independent mass fractions";
  InputAbsolutePressure     p;
  InputSpecificEnthalpy     h;
  InputMassFraction         Xi[nXi];
  SI.Temperature            T;
  SI.Density                d;
  SI.SpecificInternalEnergy u;
  connector InputAbsolutePressure = input SI.AbsolutePressure;
  connector InputSpecificEnthalpy = input SI.SpecificEnthalpy;
  connector InputMassFraction = input SI.MassFraction;
end BaseProperties; 

and then says, in the non-normative section

The use of connector here is a special design pattern. The variables p, h, Xi are marked as input to get correct equation count. Since they are connectors they should neither be given binding equations in derived classes nor when using the model. The design pattern is to give textual equations for them (as below); using connect-equations for these connectors would be possible (and would work) but is not part of the design.

This partial model defines that T, d, u can be computed from the medium model, provided p, h, Xi are given. Every medium with one or multiple substances and one or multiple phases, including incompressible media, has the property that T, d, u can be computed from p, h, Xi. A particular medium may have different “independent variables” from which all other intrinsic thermodynamic variables can be recursively computed.

So, from the Modelica Language Specification, it seems that connector inputs are a construct reserved for models where you don't know in advance who the actual inputs will be, but only how many they need to be. And, maybe, suggest a default set of inputs, which is by no means mandatory and can be overridden by adding equations to the model.

However, if I look at the Modelica Standard Library, the Modelica.Blocks.Interfaces.RealInput definition is

connector RealInput = input Real "'input Real' as connector";

This connector is very extensively used to provide signal inputs to models of all kinds. So it seems that there are millions of existing Modelica models out there, that are all kind of abusing the design pattern suggested by the Language Specification.

Since I guess there were good reasons to define input connectors that way in the Modelica.Blocks.Interface, many, many years ago, and in view of offering "open, coordinated standards for system modelling" as we claim in our motto, should we eventually make peace between MSL and MLS, and amend Section 4.7 in some way, e.g. by removing the part of the statement I marked in boldface in the above quote?

Also, the connector input construct is specifically designed to not require them to actually be connected. Which means, it would be perfectly fine to leave input connectors of Blocks models unconnected, provided the extra needed equation is given somewhere else. Is that really the intention?

casella avatar Sep 16 '22 10:09 casella

Also, the connector input construct is specifically designed to not require them to actually be connected. Which means, it would be perfectly fine to leave input connectors of Blocks models unconnected, provided the extra needed equation is given somewhere else. Is that really the intention?

It would be "ok" - and we have seen it used also for normal blocks, e.g., having a table-block and an equation table.u=... instead of connect(..., table.u); (even before the rule was introduced - I believe the "..." was somewhat complicated). To clarify the extra equation should be given in the model directly using the block - not just "somewhere else".

Additionally, a common good design in Modelica is that classes either have textual (non-connect) equations or graphical (connect) equations, and BaseProperties fit into that design.

For the future I agree that it would be good if we could design some better alternative to this, to clarify the idea - but to me that would be additional annotation stating that you are not supposed to connect to those specific "connectors" (or possibly some other alternative than connectors for them). And then deprecate giving equations for inputs - but I don't see it as high priority - as it is good enough at the moment.

HansOlsson avatar Sep 16 '22 12:09 HansOlsson

@HansOlsson I agree with your comment.

However, it does not address my main question: should we remove the statement I highlighted from the language spec? Otherwise we have a widely used feature (RealInput connectors) in the Modelica Standard Library that is not really following the standard...

casella avatar Sep 16 '22 13:09 casella

@HansOlsson I agree with your comment.

However, it does not address my main question: should we remove the statement I highlighted from the language spec?

It might be that it should be clarified that 'The use of connector here is a special design pattern.' means that it is a very special design pattern used in that specific model. It doesn't imply that using connectors in other models (in somewhat related ways) is part of that of that design pattern.

HansOlsson avatar Sep 19 '22 14:09 HansOlsson