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

Unit inference and multiplication with literal #3417

Open
henrikt-ma opened this issue Sep 22, 2023 · 2 comments
Open

Unit inference and multiplication with literal #3417

henrikt-ma opened this issue Sep 22, 2023 · 2 comments

Comments

@henrikt-ma
Copy link
Collaborator

henrikt-ma commented Sep 22, 2023

This is a unit checking topic affecting #3266 and #3257.

What is the desired unit inference behavior in the following model?

model LiteralTimesInferredUnit
  Real power(unit = "W") = 10;
  constant Real i1(unit = "A") = 5;
  Real i3 = 5;
  Real u1;
  Real u2;
  Real u3;
equation
  power = u1 * i1;
  power = u2 * 5; /* "5" is a literal meant to represent a constant current equal to i1. */
  power = u3 * i3; /* Not getting a unit for u3 seems better than getting "W". */
end LiteralTimesInferredUnit;

To clarify the problem, wouldn't it be unfortunate if we ended up assigning the unit "1" to the literal 5, and then infer that u2 has the same unit as power?

The above example has no declared units in the expression u2 * 5, but the example can also be generalized to efficiency * u2 * 5 or u2 * 5 * efficiency, where efficiency has unit W/W, showing that the problem isn't unique to expressions without any declared units.

The problem makes me ready to give up on the pure bottom-up approach operating on the Modelica expression tree, making me ready to take a more global approach to multiplicative expressions. It would then be possible to say that we can't even infer the unit of a factor subexpression with empty unit as long as the whole multiplicative expression also contains variables whose units still remain to be inferred. That is, unit inference shouldn't be able to make any progress on u2 * 5, meaning that the unit of u2 cannot be inferred. However, if the unit of u2 would be inferred to V from some other equation, there wouldn't be any more variables with units remaining to be inferred in the product, and then the factor 5 with empty unit could safely be assigned the unit "1" to avoid the wildcard effect.

Edit: For comparison, I think we all agree that the expected behavior for u3 and i3 is that none of them get an inferred unit, as the splitting of "W" into two factors would be completely arbitrary.

@mestinso
Copy link

i3 is not declared in your model, can you fix/clarify.

@henrikt-ma
Copy link
Collaborator Author

i3 is not declared in your model, can you fix/clarify.

Sorry, fixed now. (There were two variables declared i1; the second of these is now correctly called i3.)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants