Opened 5 years ago

Closed 5 years ago

#5685 closed defect (fixed)

The NF does not perform unit checking on arrays or elements thereof

Reported by: Francesco Casella Owned by: Per Östlund
Priority: normal Milestone: 1.14.0
Component: New Instantiation Version:
Keywords: Cc:

Description

Please check the following model with OMEdit;

partial model M
  parameter Integer N = 2;
  Modelica.SIunits.MassFlowRate w[N];
  Modelica.SIunits.Volume V[N];
  Modelica.SIunits.Density rho[N];
equation 
  rho[1]*der(V[1]) = w[1]; // Correct equation
  der(V[1]) = w[1];        // Dimensionally inconsistent
  der(V) = w;              // Dimensionally inconsistent
  for i in 1:N loop
    der(V[i]) = w[i];        // Dimensionally inconsistent
  end for;  
end M;

In the last three equations, the density term is missing. Unfortunately, no dimensional inconsistency is detected by the NF.

Change History (5)

comment:1 by Per Östlund, 5 years ago

Priority: blockernormal

I've improved this slightly in #532, by ignoring the last subscripts in component references. The issue is that the unit checking is done before the scalarization, so for example only w is added to the unit table instead of w[1] and w[2]. The change I've made fixes the issue that subscripted variables couldn't be found in the unit table, but assumes all elements of an array have the same unit.

Splitting the variables into scalars would be fairly easy, but that would cause other issues since the unit checking writes back the units it has deduced to the flat model. The best solution would probably be to keep storing non-scalarized variables in the unit table, but use the subscripts to set and get the correct unit. I don't think I've ever seen an array with elements with different units though, so implementing that is probably a rather low priority right now.

in reply to:  1 ; comment:2 by Francesco Casella, 5 years ago

Replying to perost:

I've improved this slightly in #532, by ignoring the last subscripts in component references. The issue is that the unit checking is done before the scalarization, so for example only w is added to the unit table instead of w[1] and w[2]. The change I've made fixes the issue that subscripted variables couldn't be found in the unit table, but assumes all elements of an array have the same unit.

This sounds like a reasonable assumption for "normal" models.

Splitting the variables into scalars would be fairly easy, but that would cause other issues since the unit checking writes back the units it has deduced to the flat model. The best solution would probably be to keep storing non-scalarized variables in the unit table, but use the subscripts to set and get the correct unit. I don't think I've ever seen an array with elements with different units though, so implementing that is probably a rather low priority right now.

Agreed. In fact, if my example cases work (which I will check with the upcoming nightly) I'm inclined to close this ticket, I don't think there is a real need for such elaborate checking, and it would be probably hard to find out a real-life example that needs it.

Would you mind merging the change to maintenance/v.14 as well?

Thanks!

in reply to:  2 comment:3 by Per Östlund, 5 years ago

Replying to casella:

Would you mind merging the change to maintenance/v.14 as well?

Done

comment:4 by Francesco Casella, 5 years ago

Thanks!

comment:5 by Francesco Casella, 5 years ago

Resolution: fixed
Status: newclosed
Note: See TracTickets for help on using tickets.