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 assignment for unassigned parameters #3552

Closed
GarronFish opened this issue Jul 30, 2024 · 3 comments
Closed

unit assignment for unassigned parameters #3552

GarronFish opened this issue Jul 30, 2024 · 3 comments

Comments

@GarronFish
Copy link

In 1290058 the unit for k in Modelica.Blocks.Math.Gain was changed from "1" to "" meaning that the unit for k will be inferred.

This unfortunately results in the unit for y no longer being inferred from the unit of u unless the user manually sets the unit of k to "1" (which is a cumbersome task that most users will not do). Here is a simulation of the model mentioned above:

image

for

model GainEx
  Modelica.Blocks.Sources.ContinuousClock continuousClock
    annotation (Placement(transformation(extent={{-80,-10},{-60,10}})));
  Modelica.Blocks.Math.Gain gain(k=1)
    annotation (Placement(transformation(extent={{-10,-10},{10,10}})));
equation 
  connect(continuousClock.y, gain.u)
    annotation (Line(points={{-59,0},{-12,0}}, color={0,0,127}));
end GainEx;

The result of this is that unit checking is no longer being performed (and probes will die :)).

I propose that by default parameters with unit="" will infer that they have unit="1" unless the parameter is assigned to another parameter with a given unit.

Here are some examples:

model A
parameter Real k=1;  // after translation this has unit="1"
Real u(unit="m")=1; 
Real y;                        // after translation this has unit="m"
equation
y = u * k;
end A;
model B
parameter Real period(unit="s")=1;
parameter Real k=period;  // after translation this has unit="s"
Real u(unit="m")=1;
Real y;                        // after translation this has unit="m.s"
equation 
y = u * k;
end B;
model C
parameter Real k=1;  // after translation this has unit="s" and a warning is generated 
Real u(unit="m")=1;
Real y(unit="m.s");
equation 
y = u * k;
end C;

I think the behavior in C is correct as it can be unexpected that the unit of k is set to "s".

The handling of non-parameters would be as is.

I'm not happy with the different behavior for parameters and non-parameters however I've not been able to think of a better solution.

@casella
Copy link
Collaborator

casella commented Jul 31, 2024

@GarronFish, in general there is no reason why a gain should be dimensionless by default. In some case it is, but in many others it isn't, and it makes lots of sense to infer it if you know the units of the input and output, which come from some physical models.

Currently unit inference is not part of the Modelica Specification. There are proposals to introduce stricter unit semantics in the language, see e.g. #2127, but there is still no wide consensus on how to do it. Unfortunately the issue is complicated and we should probably avoid partial solutions and try to achieve a comprehensive one, which is hard.

@GarronFish
Copy link
Author

Thanks for the reply, I understand now that the situation is more complicated than I originally thought. From a users point of view it would be good if there was a simple way to set the unit of the output of a Math block. For example, could there be an Advanced tab where the unit string could be provided, and this used. Unfortunately, only Literal values can be used for setting Units so this is not possible. I think this is covered in #2127 so I think this ticket can be closed.

@HansOlsson
Copy link
Collaborator

Thanks for the reply, I understand now that the situation is more complicated than I originally thought. From a users point of view it would be good if there was a simple way to set the unit of the output of a Math block. For example, could there be an Advanced tab where the unit string could be provided, and this used. Unfortunately, only Literal values can be used for setting Units so this is not possible. I think this is covered in #2127 so I think this ticket can be closed.

Will close then.
Oh, @GarronFish Dymola does have the possibility to set the unit of the output - but it is a bit hidden:
Right-click at "gain.y" in the diagram and select "Set Unit" (it also works for connections).

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

3 participants