Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Equations with connectors #2235

Closed
modelica-trac-importer opened this issue Nov 4, 2018 · 5 comments · Fixed by #2486
Closed

Equations with connectors #2235

modelica-trac-importer opened this issue Nov 4, 2018 · 5 comments · Fixed by #2486
Assignees
Labels
discussion Indicates that there's a discussion; not clear if bug, enhancement, or working as intended

Comments

@modelica-trac-importer
Copy link
Collaborator

Reported by kurzbach on 28 Feb 2018 09:36 UTC
In a library of a customer following construct is used:

model M
 expandable connector C
   Real a;
   Real b;
 end C;

 C c1,c2;
 equation
   c1=c2;
end M;

There are following questions:

  1. Is it allowed to use connectors directly in equations? In the specification the equation sign is only defined for simple types and records. Connectors are not mentioned in this context.
  2. if not, is this a speciality to expandable connectors? This is not specified,
  3. Is it allowed to define connectors containing only variables and not flow variables? In the specifiation there is a sentence in 9.3.1: For each non-partial connector class the number of flow variables shall be equal to the number of variables that are neither parameter, constant, input, output, stream nor flow.
  4. Expandable connectors are not allowed to have flow variables. Is the balancing rule not from 2. not applied in this case? This is not specified.

Migrated-From: https://trac.modelica.org/Modelica/ticket/2235

@modelica-trac-importer modelica-trac-importer added the discussion Indicates that there's a discussion; not clear if bug, enhancement, or working as intended label Nov 4, 2018
@modelica-trac-importer
Copy link
Collaborator Author

Comment by hansolsson on 28 Feb 2018 10:39 UTC
Replying to [ticket:2235 Gerd Kurzbach]:

In a library of a customer following construct is used:

model M
 expandable connector C
   Real a;
   Real b;
 end C;

 C c1,c2;
 equation
   c1=c2;
end M;

I will need to investigate this more, but these are preliminary answers:

There are following questions:

  1. Is it allowed to use connectors directly in equations? In the specification the equation sign is only defined for simple types and records. Connectors are not mentioned in this context.

For non-expandable connectors there are two cases:

  • The ones inheriting from a type (like RealInput). There are often equations for these and it should be allowed. (I assume the same goes if they inherit from record.)
  • Hierarchical ones (like an electrical pin). I don't think there are equations involving those in e.g. MSL, and to me it seems odd to have such equations (especially since flow-equations will be weird) - but I don't think there would be any major problem with allowing it.
  1. if not, is this a speciality to expandable connectors? This is not specified,

For expandable connectors I do see major problem.

The reason is that they are expandable and thus may get additional contents. But this non-connect equation is not considered for the elaboration, meaning that other connections might make the sides unequal. Additionally it seems this introduces an equation for potentially present variables - which contradicts the idea in 9.1.3 of not referring to them.

  1. Is it allowed to define connectors containing only variables and not flow variables? In the specifiation there is a sentence in 9.3.1: For each non-partial connector class the number of flow variables shall be equal to the number of variables that are neither parameter, constant, input, output, stream nor flow.

Interesting point. For c1 and c2 one would assume that 'a' and 'b' get causality due to other connections (as specified), and thus there is no problem - and if there is no connection to 'a' and 'b' they are removed, and thus no problem. (Looking more this is specified in 9.1.3.)

Thus it is only a problem for expandable connector classes, not expandable connector components, and this restriction should be lifted for expandable connector (classes).

  1. Expandable connectors are not allowed to have flow variables. Is the balancing rule not from 2. not applied in this case? This is not specified.

Continuing from above.
I agree that should be specified, and I think that the actually present simple variables in the expandable connector will be causal ensuring that it is balanced.

@modelica-trac-importer
Copy link
Collaborator Author

Comment by kurzbach on 28 Feb 2018 11:52 UTC
Replying to [comment:1 Hans Olsson]:

I agree that should be specified, and I think that the actually present simple variables in the expandable connector will be causal ensuring that it is balanced.

Yes, in this case the connector components get causality from other connectors via connect statements.

@modelica-trac-importer
Copy link
Collaborator Author

Comment by hansolsson on 22 Mar 2018 13:20 UTC
Language group:
Normal connectors not based on simple type/record can only be used in connect-equations or accessing a member (possibly in combination with array subscripting). Expandable connectors can only be used in connect-equations.

9.3.1 should say that expandable connectors are excluded from this restriction, since the elements are only constraints.
Agreement.

@modelica-trac-importer
Copy link
Collaborator Author

Comment by eshmoylova on 22 Mar 2018 14:27 UTC
Note that right now in 9.1.3 there is the following paragraph (the emphasis in bold is mine).
After this elaboration the expandable connectors are treated as normal connector instances, and the connections as normal connections, and all potentially present variables and array elements that are not actually present are undefined [a tool may remove them or set them to the default value, e.g. zero for Real variables]. It is an error if there are expressions referring to potentially present variables or array elements that are not actually present or non-declared variables [the expressions can only “read” variables from the bus that are actually declared and present in the connector, in order that the types of the variables can be determined in the local scope].

The sentence in bold implies that the variables inside expandable connectors can be used in non-connect equations. There is even a test for that in the Modelica Compliance library:
https://github.com/modelica/Modelica-Compliance/blob/master/ModelicaCompliance/Connections/Expandable/PresentInExp.mo

There are three more models that use potential variables in other expressions but they all should not pass (for different reasons).
https://github.com/modelica/Modelica-Compliance/blob/master/ModelicaCompliance/Connections/Expandable/NonPresentInExp.mo
https://github.com/modelica/Modelica-Compliance/blob/master/ModelicaCompliance/Classes/Enumeration/WrongConversion4.mo
https://github.com/modelica/Modelica-Compliance/blob/master/ModelicaCompliance/Classes/Enumeration/WrongConversion6.mo

The quoted paragraph and the models in the Compliance library would need to be update to reflect the new restriction.

HansOlsson added a commit to HansOlsson/ModelicaSpecification that referenced this issue Feb 12, 2020
@HansOlsson
Copy link
Collaborator

I don't see that we considered that restriction for expandable connector in that detail, and thus I didn't add it to the PR yet. I also noticed that the overall description of allowed expressions was unclear so I tried to add that.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
discussion Indicates that there's a discussion; not clear if bug, enhancement, or working as intended
Projects
None yet
Development

Successfully merging a pull request may close this issue.