ModelicaStandardLibrary icon indicating copy to clipboard operation
ModelicaStandardLibrary copied to clipboard

Wrong input type in specificEnthalpy_pTX, temperature_phX, and density_phX

Open casella opened this issue 10 months ago • 5 comments

Consider this simple MWE:

model TestFunctionDefault
  package Medium = Modelica.Media.Air.SimpleAir;
  Medium.SpecificEnthalpy h = Medium.specificEnthalpy_pT(1e5, 300);
end TestFunctionDefault;

This model compiles in Dymola 2024X and produces the expected result. However, when I try to compile it with OpenModelica, I get this error:

[1] 18:31:01 Translation Error
[Modelica.Media: 4706:7-4709:26]: Type mismatch for positional argument 3 in TestMedia.TestFunctionDefault.Medium.specificEnthalpy_pTX(X=fill(0.0, 0)). The argument has type:
  Integer[0]
expected type:
  Real[1]

This output looks a bit odd at first sight, what's wrong in calling specificEnthalpy_pT(1e5, 300)? I thought it was an OMC bug, but in fact it turns out to be an MSL issue.

specificEnthalpy_pT, as defined in PartialPureSubstance, calls specificEnthalpy_pTX(p, T, fill(0, 0)), which is defined in PartialMedium as specificEnthalpy(setState_pTX(p, T, X)), so it calls setState_pTX with a third argument X = fill(0, 0).

Unfortunately, setState_pTX for SimpleAir is defined in PartialSimpleIdealGasMedium as:

  redeclare function specificEnthalpy_pTX
    "Return specific enthalpy from p, T, and X or Xi"
    extends Modelica.Icons.Function;
    input AbsolutePressure p "Pressure";
    input Temperature T "Temperature";
    input MassFraction X[nX] "Mass fractions";
    output SpecificEnthalpy h "Specific enthalpy at p, T, X";
  algorithm
    h := cp_const*(T - T0);
  end specificEnthalpy_pTX;

with input MassFraction X[nX] instead of MassFraction X[:]. Since by default nX = size(substanceNames, 1) = 1, it then expects an array of dimension one, but instead gets an array of dimension zero, coming from fill(0,0).

I'm not sure why Dymola does not complain about this issue, but for sure it needs to be fixed. This holds for functions specificEnthalpy_pTX, temperature_phX, and density_phX in both PartialSimpleMedium and PartialSimpleIdealGasMedium.

casella avatar Apr 16 '24 16:04 casella

SimulationX also reports the dimension error

Error in TestFunctionDefault: Wrong argument dimension.
Help: Check.DimCallArg
 
h=Medium.specificEnthalpy_pT(100000.,300);
The argument 3 (fill(0,0)) in the function call has the wrong dimension ([0]-vector). Expected dimension [1]-vector.

I wonder why OMC deduced type Integer[0] from fill(0,0). Should it be fill(0.0,0)?

beutlich avatar Apr 16 '24 18:04 beutlich

I wonder why OMC deduced type Integer[0] from fill(0,0). Should it be fill(0.0,0)?

OMC would normally convert it to fill(0.0, 0) automatically, but that's done after checking if the types match. So the error message just uses the actual types rather than what the types would've been had they been compatible.

perost avatar Apr 16 '24 20:04 perost

OK, there also is #4393 now which is independent of the dimension error.

beutlich avatar Apr 19 '24 14:04 beutlich

This issue is causing regressons in OMC, so I would put it in MSL 4.1.0, I don't see any reason to postpone it to 4.2.0. The proposed modification is actually less restrictive, so there should be no backwards compatibility problems.

casella avatar Jun 26 '24 13:06 casella

We need to cherry pick #4390 to maint/4.1.x so we get this fixed in the forthcoming release.

casella avatar Jun 27 '24 08:06 casella

We need to cherry pick #4390 to maint/4.1.x so we get this fixed in the forthcoming release.

@Esther-Devakirubai can you please take care of that? Thanks!

casella avatar Jul 31 '24 09:07 casella

We need to cherry pick #4390 to maint/4.1.x so we get this fixed in the forthcoming release.

@Esther-Devakirubai can you please take care of that? Thanks!

@casella Yes Sure! Thanks

Esther-Devakirubai avatar Aug 01 '24 11:08 Esther-Devakirubai

#4390 backported to maint/4.1.x by #4453

Esther-Devakirubai avatar Aug 16 '24 15:08 Esther-Devakirubai