Opened 6 years ago
Closed 6 years ago
#4995 closed defect (fixed)
Constants with non-constant subscripts not evaluated in functions
Reported by: | Per Östlund | Owned by: | Per Östlund |
---|---|---|---|
Priority: | high | Milestone: | 2.0.0 |
Component: | New Instantiation | Version: | v1.13.0-dev-nightly |
Keywords: | Cc: |
Description
The NF only evaluates constants that also has constant subscripts, but this causes some issues with e.g. Modelica.Media.Examples.Tests.MediaTestModels.IdealGases.SimpleNaturalGas that contains the function Medium.molarMass
:
function molarMass input volume.Medium.ThermodynamicState state; output Real MM(quantity = "MolarMass", unit = "kg/mol", min = 0.001, max = 0.25, nominal = 0.032); algorithm MM := 1.0 / sum(array(state.X[j] / Medium.data[j].MM for j in 1:6)); end molarMass;
Medium.data[j].MM
is a constant here, but it's not evaluated since j
is an iterator. This causes the generated code to fail to compile, since Medium.data.MM
isn't accessible in the function scope (and the constant added to the flat model is incorrect anyway since it's missing the binding equation for some reason).
The NF probably needs to evaluate such constants partially, i.e. evaluate only the constant parts of the cref, at least in functions.
See also #4873 for a similar issue.
Fixed in ab87884.