modelica-3rdparty / ExternalMedia

The ExternalMedia library provides a framework for interfacing external codes computing fluid properties to Modelica.Media-compatible component models.
53 stars 36 forks source link

Selection of different state variables (ph, pt, dT) for a CoolProp 2-phase medium #87

Open ferrucci-franco opened 1 year ago

ferrucci-franco commented 1 year ago

Hi there,

I'm trying to understand how the selection of different state variables affects the resulting system of equations and I've encountered a possible inconsistency:

Looking at the CO2 CoolProp medium example, it says: package CO2CoolProp "CoolProp model of CO2" extends ExternalMedia.Media.CoolPropMedium( mediumName = "CarbonDioxide", substanceNames = {"CO2"}, ThermoStates = Modelica.Media.Interfaces.Choices.IndependentVariables.ph, SpecificEnthalpy(start=2e5)); end CO2CoolProp;

However, I think there is should be: package CO2CoolProp "CoolProp model of CO2" extends ExternalMedia.Media.CoolPropMedium( mediumName = "CarbonDioxide", substanceNames = {"CO2"}, ThermoStates = Modelica.Media.Interfaces.Choices.IndependentVariables.ph, // this doesn't affect the variable selection inputChoice = ExternalMedia.Common.InputChoice.ph, // this DOES! SpecificEnthalpy(start=2e5)); end CO2CoolProp;

I think that the constant named ThermoStates (defined in partial package PartialMedium) is not used in ExternalMedia, but instead you have created a parameter called basePropertiesInputChoice (defined in the re-declaration of BaseProperties model inside ExternalTwoPhaseMedium.mo). The parameter basePropertiesInputChoice is of type ExternalMedia.Common.InputChoice and not of type Modelica.Media.Interfaces.Choices.IndependentVariables.

Note that, for instance, the enumerator type Modelica.Media.Interfaces.Choices.IndependentVariables does NOT include InputChoice.dT (density and temperature...is that a MSL bug?)...I guess that this is why you had to define a new enumerator type ExternalMedia.Common.InputChoice.

In any case, does anyone have an example of a dynamical system using a CoolProp medium, in which the state variables are changed from 'ph' to 'dT' or to 'pT', and the simulation runs correctly in both cases (with possibly a change in the number of non-linear equations)?

Thank you!

casella commented 1 year ago

@ferrucci-franco I don't have such an example, but for sure this should be cleaned up. We'll look at it after the summer break.