Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding new fluids to CoolProp and use it in Modelica #109

Open
bmazurie opened this issue Jul 29, 2024 · 3 comments
Open

Adding new fluids to CoolProp and use it in Modelica #109

bmazurie opened this issue Jul 29, 2024 · 3 comments

Comments

@bmazurie
Copy link

According to CoolProp documentation, it is possible to add new fluids to CoolProp library. To do so, it should be

  • Complete SolutionFLuids.py to add tables for your new fluid
  • Run dev/incompressible_liquids/all_incompressibles.py to regenrate the JSON files with the fitted parameters
  • "as soon as you recompile the sources": "Your new fluid is now part of the codebase and should be available to all CoolProp functions"

I've added my data to SolutionFLuids.py, regenerate the JSON files (I can find the new JSON file KOH.json in ExternalMedia/build/CoolProp.sources/json/ folder). To recompile, I used cmake --build build --config Release --target install mentioned in ExternalMedia documenation(which worked flawlessly for the first installation).

However, when I define my medium in Modelica with:

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

and run a simple model such as (I defined my saturation pressure in the CoolProp's data):

model KOH_functions
  replaceable package Medium_CoolProp_KOH = Test_ExternalMedia_ThermoSysPro.Media.KOHCoolProp;
  Modelica.Units.SI.Pressure P;
equation 
  P=Medium_CoolProp_KOH.saturationPressure(273.15+20);
end KOH_functions;

It runs into translation errors both with OpenModelica 1.23.1 and Dymola23x. (Linux Scibian11 on both):
OpenModelica errors:
image
Dymola errors:
image

  • Do you see anything I may have done wrong in the process?
  • Has adding new fluids to CoolProp and then used in ExternalMedia Modelica Lib been done before? If so, is there any tutorial on the subject?

Thank you very much
Baptiste

@ibeyers
Copy link

ibeyers commented Jul 30, 2024

I believe you maybe failed to recompile Coolprop? So after adding a custom fluid and modifying the json, you need to first recompile Coolprop (I used the python wrapper -> run setup.py file in the \wrappers\Python folder.)
Then you need to recompile ExternalMedia, and tell it to use your modified, recompiled Coolprop.

(just like a high-level pointer, hope that helps)

@bmazurie
Copy link
Author

bmazurie commented Aug 2, 2024

Thank you for your answer.

Indeed CoolProp was the problem. In fact, when dev/incompressible_liquids/all_incompressibles.py is ran to regenrate the JSON files with the fitted parameters, the json goes into ExternalMedia/build/CoolProp.sources/json. But it should be in ExternalMedia/build/CoolProp.sources/dev/incompressible_liquids/json(in my case) in order to be taken into account for the recompilation of CoolProp.

I had another issue regarding the definition of my medium in Modelica, I forget to add INCOMP:: in substanceNames = {"INCOMP::KOH"},. Now it does find the medium when using ExternalMedia.

@bmazurie
Copy link
Author

bmazurie commented Aug 2, 2024

However I would like to point an issue that I have with ExternalMedia and a possible bug.

I start from the same example as before, I defined a medium with CoolProp where I defined data regarding density, cp, mu, k and saturation pressure at different temperature. In Modelica, I use:

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

And I use it in a model to find again those data:

replaceable package Medium_CoolProp_KOH =
      Test_ExternalMedia_ThermoSysPro.Media.KOHCoolProp;
      
  parameter Modelica.Units.SI.Temperature T=273.15+20;
  parameter Modelica.Units.SI.Pressure P_atm=101325;

equation 
  h_KOH=Medium_CoolProp_KOH.specificEnthalpy_pT(P_atm,T);

  d_KOH=Medium_CoolProp_KOH.density_ph(P_atm,h_KOH);
  cp_KOH=Medium_CoolProp_KOH.specificHeatCapacityCp(Medium_CoolProp_KOH.setState_ph(p=P_atm, h=h_KOH, phase=0));
  mu_KOH=Medium_CoolProp_KOH.dynamicViscosity(Medium_CoolProp_KOH.setState_ph(p=P_atm, h=h_KOH, phase=0));
  k_KOH=Medium_CoolProp_KOH.thermalConductivity(Medium_CoolProp_KOH.setState_ph(p=P_atm, h=h_KOH, phase=0));
  P_sat_KOH=Medium_CoolProp_KOH.saturationPressure(T);

It works fine, EXCEPT for the saturation pressure which gives what seems to be a default value:
image

As CoolProp has the Python wrapper, I used it to test my media:

PropsSI('D','T',293.15,'P',101325,'INCOMP::KOH'): 1293.591986384524
PropsSI('C','T',293.15,'P',101325,'INCOMP::KOH'): 2972.5632292009855
PropsSI('VISCOSITY','T',293.15,'P',101325,'INCOMP::KOH'): 0.0024487626442337763
PropsSI('CONDUCTIVITY','T',293.15,'P',101325,'INCOMP::KOH'): 0.5813769155106154
PropsSI('P','T',293.15,'Q',0,'INCOMP::KOH'): 1381.3038209276774

It can be seen that saturation pressure is well defined with Python (and it is the value I used in the data for the definition of the medium in CoolProp). Thus it seems to be a bug with ExternalMedia.

Any idea? Thank you in advance

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants