Opened 6 years ago

Last modified 6 years ago

#5209 closed defect

Non-evaluated package constants and issue with apparently unused functions with the NF — at Version 1

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

Description (last modified by Francesco Casella)

Please check Modelica.Electrical.Spice3.Examples.Graetz. The C compiler complains about

Modelica_trunk_Modelica.Electrical.Spice3.Examples.Graetz_functions.c:1812:24: error: use of undeclared identifier '_Modelica'
  _Kelvin = _Celsius - _Modelica._Constants._T_zero;
                       ^

The output of the NF contains

function Modelica.SI.Conversions.from_degC "Inline before index reduction" "Convert from degCelsius to Kelvin"
  input Real Celsius(quantity = "ThermodynamicTemperature", unit = "degC") "Celsius value";
  output Real Kelvin(quantity = "ThermodynamicTemperature", unit = "K", displayUnit = "degC", min = 0.0, start = 288.15, nominal = 300.0) "Kelvin value";
algorithm
  Kelvin := Celsius - Modelica.Constants.T_zero;
end Modelica.SI.Conversions.from_degC;

where, for some reason, Modelica.Constants.T_zero was not replaced with -273.15, as the old front-end does. I guess that should be fixed.

There are two additional weird things in the way this model is flattened.

One is that the function from_degC is apparently not called anywhere - I couldn't find any more instance of that function name in the flattened code besides the function definition itself. So the first question is

  • why is this function definition included in the flat model in the first place?

BTW, this happens also with the old front-end.

The other weird thing is that the following declaration shows up in the body of the Graetz model

  final constant Real Modelica.Constants.T_zero = -273.15 "Absolute zero temperature";

while T_zero is not used anywhere in that model - it is only used in the from_degC function body. So, two additional questions arise

  • why is this constant defined here and not in the function body?
  • why aren't all constants defined by literal values constant-evaluated by the front-end in the first place?

This issue may affect other models in other libraries, as it appears to be at a rather fundamental level.

Change History (1)

comment:1 by Francesco Casella, 6 years ago

Description: modified (diff)
Note: See TracTickets for help on using tickets.