modelica-3rdparty / ExternalMedia

The ExternalMedia library provides a framework for interfacing external codes computing fluid properties to Modelica.Media-compatible component models.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

ExternalMedia not working when using it through "Medium.BaseProperties" model

ferrucci-franco opened this issue · comments

Hi there,

I'm using you fantastic ExternalMedia library and I'm getting translation errors when using it through a Medium.BaseProperties model.

I wrote the code below in order to show the error. In the code, Test1 fails and Test2 runs correctly when using NH3CoolProp Medium. Note that both models run correctly when using package Medium = Modelica.Media.IdealGases.SingleGases.NH3.

Here is the code:

package ExternalMediaError

package NH3CoolProp "CoolProp model of NH3"
extends ExternalMedia.Media.CoolPropMedium(
mediumName = "Ammonia",
substanceNames = {"NH3"},
ThermoStates = Modelica.Media.Interfaces.Choices.IndependentVariables.ph,
SpecificEnthalpy (start=2e5));
end NH3CoolProp;

partial model Test0
package Medium = ExternalMediaError.NH3CoolProp;
//package Medium = Modelica.Media.IdealGases.SingleGases.NH3;
parameter Medium.AbsolutePressure p0 = 1e5;
parameter Medium.Temperature T0 = 350;
Medium.IsobaricExpansionCoefficient beta;
end Test0;

model Test1
extends Test0;
Medium.BaseProperties medium(
preferredMediumStates=true,
p(start=p0, fixed=false),
T(start=T0, fixed=false));

equation
medium.T = T0;
medium.p = p0;
beta = Medium.isobaricExpansionCoefficient(medium.state);
annotation(experiment(StartTime = 0, StopTime = 1, Tolerance = 1e-06, Interval = 0.002));
end Test1;

model Test2
extends Test0;
Medium.ThermodynamicState state;
Medium.Density d = Medium.density(state) "Density";
Medium.SpecificInternalEnergy u = Medium.specificInternalEnergy(state);
Medium.SpecificInternalEnergy h = Medium.specificEnthalpy(state);

equation
state = Medium.setState_pT(p0, T0);
beta = Medium.isobaricExpansionCoefficient(state);

annotation(experiment(StartTime = 0, StopTime = 1, Tolerance = 1e-06, Interval = 0.002));

end Test2;

end ExternalMediaError;

Here are the errors (OMEdit 1.18.0 running on Windows 10):

[1] 16:29:44 Translation Error
[ExternalMedia.Media.BaseClasses.ExternalTwoPhaseMedium: 186:15-190:19]: External function ‘TwoPhaseMedium_getMolarMass_C_impl‘ could not be found in any of the given shared libraries:
C:/Users/ferrucci/OneDrive/workspace/modelica/openModelica/lib/ExternalMedia 3.3.0/Resources/Library/win64/ExternalMediaLib.dll
C:/Users/ferrucci/OneDrive/workspace/modelica/openModelica/lib/ExternalMedia 3.3.0/Resources/Library/ExternalMediaLib.dll

[2] 16:29:44 Translation Error
[ExternalMedia.Media.BaseClasses.ExternalTwoPhaseMedium: 198:15-202:26]: External function ‘TwoPhaseMedium_getCriticalPressure_C_impl‘ could not be found in any of the given shared libraries:
C:/Users/ferrucci/OneDrive/workspace/modelica/openModelica/lib/ExternalMedia 3.3.0/Resources/Library/win64/ExternalMediaLib.dll
C:/Users/ferrucci/OneDrive/workspace/modelica/openModelica/lib/ExternalMedia 3.3.0/Resources/Library/ExternalMediaLib.dll

Notes:
I don't know why it's complaining about ExternalMediaLib.dll, since I'm using libExternalMediaLib.a

I don't know why it's complaining about ExternalMediaLib.dll, since I'm using libExternalMediaLib.a

Static libraries .a can only be used when it's been linked into the model. If a value is needed during compile-time, a dynamic library .dll is required.

Hi again,

I found a workaround for the error: I filled the externalFluidConstants record by hand (so the code does not call woPhaseMedium_getCriticalPressure_C_impl and TwoPhaseMedium_getMolarMass_C_impl C functions, which apparently OM cannot find).

The media definition is now:

package NH3CoolProp "CoolProp model of NH3"
extends ExternalMedia.Media.CoolPropMedium(
mediumName = "Ammonia",
substanceNames = {"NH3"},
inputChoice=ExternalMedia.Common.InputChoice.pT,
externalFluidConstants=FluidConstants(
iupacName="Ammonia",
casRegistryNumber="7664-41-7",
chemicalFormula="H_{3}N_{1}",
structureFormula="unknown",
molarMass=0.01703026,
criticalTemperature=4.054e+02,
criticalPressure=11333000,
criticalMolarVolume=7.569004444444444e-05,
acentricFactor=0.253,
triplePointTemperature=1.95495e+02,
triplePointPressure=6.091223108131509e+03,
meltingPoint=195.4200,
normalBoilingPoint=2.398235545665792e+02,
dipoleMoment=1.42));
end NH3CoolProp;

NOTE: I removed the line:
ThermoStates = Modelica.Media.Interfaces.Choices.IndependentVariables.pT
since I couldn't see its use (Could someone confirm this???. Instead, I added the the following line:
inputChoice=ExternalMedia.Common.InputChoice.pT
which actually changed the state selection. I know this beacuse, if I changed to
inputChoice=ExternalMedia.Common.InputChoice.ph
then, the initialization process needed to solve a non-linear system of equations.

@ferrucci-franco your Test1 model compiles correctly with the new 3.3.2 version. It then fails at runtime with

ExternalMedia error: unable to solve 1phase PY flash with Tmin=195.494, Tmax=239.585 due to error: HSU_P_flash_singlephase_Brent could not find a solution because Hmolar [0 J/mol] is below the minimum value of 1.94632523329 J/mol

but I guess that's another story.

We'll release 3.3.2 anytime soon, in the meantime you can get it from the latest binaries here.