Skip to content
This repository has been archived by the owner on Jan 4, 2021. It is now read-only.

Fluid properties problems #23

Open
jelemer opened this issue Mar 31, 2017 · 18 comments
Open

Fluid properties problems #23

jelemer opened this issue Mar 31, 2017 · 18 comments

Comments

@jelemer
Copy link

jelemer commented Mar 31, 2017

Hello,

Let me start by saying that I appreciate the work done by you on the ExternalMedia library. I am a PhD student at Chalmers University and I am using ExternalMedia to couple my Modelica models to the CoolProp database, with purpose of calculating properties in organic Rankine cycles and similar power cycles for waste heat recovery in automotive applications. For some fluids this works perfectly, but for other fluids there are some issues that I am not able to solve, so maybe you can help me here.

Basically there are two main errors I get depending on the fluid, I will give two examples here. First example is the fluid D4, which gives the following error:
The following error was detected at time: 0
Viscosity model is not available for this fluid
The stack of functions is:
setState_ph_Unique6
setState_ph_Unique6(100000.0, 100000.0, 0)
Error: Failed to start model.

Another example is Methanol, which gives:
The following error was detected at time: 0
options.T is not valid in saturation_P_pure_1D_T
The stack of functions is:
getMolarMass_Unique2
getMolarMass_Unique2()
Error: Failed to start model.

I reproduced these errors in a very simple model:

   model TestEM

    package Medium = ExternalMedia.Media.CoolPropMedium (
        mediumName = "Methanol",
        ThermoStates = Modelica.Media.Interfaces.Choices.IndependentVariables.pT,
        AbsolutePressure(start=1e5),
        SpecificEnthalpy(start=1e5));
    Medium.BaseProperties props;

  equation 
    props.p = 1e5;
    props.h = 1e5;

    annotation (uses(Modelica(version="3.2.1")));
  end TestEM;

The weird thing is, that these fluids work in a Python script if I call CoolProp directly with the same input:

  import CoolProp.CoolProp as CP
  print("CoolProp version:", CP.get_global_param_string("version"))
  fluid = "D4"
  db = "HEOS"
  P = 1e5
  h = 1e5
  print CP.PropsSI("T", "P", P, "H", h, fluid)

I downloaded the latest version of ExternalMedia from github and compiled it using one of the bat files available. Do you have any suggestion what is going wrong here? If you need any more info regarding this or if something is unclear, please let me know.

Kind regards,

Jelmer Rijpkema

System info:
ExternalMedia version: 3.2.1
CoolProp version: 6.1.1dev
Environment: Dymola
OS: Windows 7

@ibell
Copy link

ibell commented Mar 31, 2017

Hi Jelmer,

The first family of error of missing viscosity models is, as the error says, because a viscosity model does not exist. What fluid(s) do you get this error for? As you can see in http://www.coolprop.org/fluid_properties/PurePseudoPure.html#list-of-fluids there are quite a few fluids for which no viscosity model is available. In some cases we have just not implemented it yet, in others, there is no model in the literature.

Stupid question: are the units all the same? Enthalpies in molar or mass basis?

@JonWel
Copy link
Contributor

JonWel commented Mar 31, 2017

Hi @jelemer ,

So there is not viscosity model for D4, hence the error.
To go around this, you should add the option calc_transport=false which will disable the computation of viscosity.

The other issue seems to be related to the flash routine, I'll have to investigate what's happening here. As Ian said, better check in which units Modelica is working.

@ibell @jowr Should calc_transport=true be the default option? Should we have a more clever choice automatically checking if a viscosity model is available? For instance outputting a warning that calc_transport has automatically been set to false if the model is set without any specification from the user on calc_transport?

@jelemer
Copy link
Author

jelemer commented Apr 3, 2017

Thank you for the quick feedback, I added the calc_transport=0 to the substanceNames and this worked. I was a bit confused about this error I must say, since I only use thermodynamic properties in my model and no transport properties.

Regarding the other part, I am not sure how to set the units in ExternalMedia, but I checked the result for Ethanol, which is working, and the temperature was the same both for the Python script and the Modelica model, indicating that the input has the same units. Are there any other things I can do to test this issue?

@JonWel
Copy link
Contributor

JonWel commented Apr 4, 2017

@jelemer I understand that it can be confusing, that's why I asked to Ian and Jorrit if this may be a good idea to set to disable by default.

For the methanol case, I'll have to investigate more.

@jelemer
Copy link
Author

jelemer commented Apr 5, 2017

Thanks for the feedback and I will wait for the Methanol case. If there is anything I can do to assist in the investigation, please let me know.

@jelemer
Copy link
Author

jelemer commented Apr 10, 2017

Hello again,

I have encountered some issues by setting the calc_transport=0. Since ExternalMedia returns a NaN when this option is turned off, I get the following error in Modelica:

cycle.evaporator.side1.medium_out.state_rec2.1_.lambda >= 0.0
The following error was detected at time: 0
Value is: -1.#IND
Non-linear solver will attempt to handle this problem.

I did a quick fix by changing the following code in coolpropsolver.cpp:

properties->eta    = NAN;
properties->lambda = NAN;

to

properties->eta    = 0.0;
properties->lambda = 0.0;

@jowr
Copy link
Member

jowr commented Apr 10, 2017

Your error message indicates that you use the transport properties for a calculation. If not, your Modelica code should ignore the NAN values.

@jelemer
Copy link
Author

jelemer commented Apr 10, 2017

Well, I do not do any calculations using transport properties in my code. It might be that they are initialized somewhere and I have not properly switched them off. What I do now is to set calc_transport=0 in the substanceNames when I initialize my CoolPropMedium. Are there any other options I have to set to make sure that Modelica does not include any transport properties?

@jelemer
Copy link
Author

jelemer commented Apr 10, 2017

@jowr Based on your previous comment, I investigated the problem a bit more. I am running Dymola using the Python interface. One of the options I added when I run the model is

Advanced.AssertAllInsideMinMax=true

Setting this option to false, solved this problem. Thanks for the help.

@jowr
Copy link
Member

jowr commented Apr 10, 2017

Great, I am happy to hear that it worked. I hope our comments helped a little, but you basically solved this yourself :-)

@jowr jowr closed this as completed Apr 10, 2017
@jelemer
Copy link
Author

jelemer commented Apr 11, 2017

Sorry for the confusion, but although my issues with the transport properties are now solved, I still have the issue regarding the flash routine. This issue unfortunately does not only occur for Methanol, but also for other fluids. Do you have any suggestion how to fix or even debug this?

@jowr
Copy link
Member

jowr commented Apr 11, 2017

You are using p and T as state variables, but you call with p and h - the solver internally tries to find the correct T to match your provided h and maybe changing ThermoStates = Modelica.Media.Interfaces.Choices.IndependentVariables.pT to something like ThermoStates = Modelica.Media.Interfaces.Choices.IndependentVariables.ph helps?

@jowr jowr reopened this Apr 11, 2017
@jelemer
Copy link
Author

jelemer commented Apr 11, 2017

Unfortunately that did not help, I do use that declaration in my original model, but I left it out for the simple model I presented here. I also tried giving p and T as input with ThermoStates = Modelica.Media.Interfaces.Choices.IndependentVariables.pT, but this also did not work.

@jowr
Copy link
Member

jowr commented Apr 11, 2017

Maybe you can enable the debug output and post the logs here? There is an example in ExternalMedia...

@jelemer
Copy link
Author

jelemer commented Apr 11, 2017

@jowr I have been trying to figure out which example you were referring to, but I am not sure what you mean. The logs in Dymola show no more than the error I previously presented: options.T is not valid in saturation_P_pure_1D_T.

I have also seen that you can set the debug level for the CoolPropMedium with the flag debug=x and the flag works, however, there is no information written to std::cout when I run the model, probably due to how Dymola handles this. Could you be a bit more specific about how to enable the debug output or which example you are referring to?

The simplified model that I am currently using is given below.

model TestEM
  constant String s = ExternalMedia.Common.CheckCoolPropOptions("Methanol|calc_transport=0|debug=100", debug=false);

  package Medium = ExternalMedia.Media.CoolPropMedium (
    substanceNames = {s},
    ThermoStates = Modelica.Media.Interfaces.Choices.IndependentVariables.ph,
    AbsolutePressure(start=1e5),
    SpecificEnthalpy(start=1e5));

  Medium.BaseProperties props;

equation
  props.p = 1e5;
  props.h = 1e5;

end TestEM;

@jelemer
Copy link
Author

jelemer commented Apr 11, 2017

Oh by the way, when I add the option to use tabulated values (enable_TTSE=1) the code above works as well as my own simulations.

@jowr
Copy link
Member

jowr commented Apr 11, 2017

After translating the model, you get a file called dymosim.exe. This file can be called from the command line and for your example, I get the following output:

dymosim.exe started
Runtime license not available, trying to check out the Dymola Standard license instead.

... "dsin.txt" loading (dymosim input file)
calc_transport has the value of 0
debug has the value of 1000
TTSE is off
enable_TTSE has the value of 0
BICUBIC is off
enable_BICUBIC has the value of 0
enable_EXTTP has the value of 1
twophase_derivsmoothing_xend has the value of 0.0
rho_smoothing_xend has the value of 0.0
Check passed, reducing Methanol|calc_transport=0|debug=1000|enable_TTSE=0|enable_BICUBIC=0|enable_EXTTP=1|twophase_derivsmoothing_xend=0.0|rho_smoothing_xend=0.0 to fluid Methanol, with HEOS backend.
Setting constants for fluid Methanol
Setting near-critical saturation conditions for fluid Methanol
setSat_p(8.2076341500000004e+006)
options.T is not valid in saturation_P_pure_1D_T
Press the Stop button in Dymola to end the simulation!

The code obviously gets stuck during initialization and I tried to change your example to exclude the BaseProperties, which are known to give problems under certain circumstances, but also this code fails:

model TestEM
  constant String s = ExternalMedia.Common.CheckCoolPropOptions("Methanol|calc_transport=0|debug=100", debug=false);

  package Medium = ExternalMedia.Media.CoolPropMedium (substanceNames = {s});
  Medium.ThermodynamicState state;

  Medium.AbsolutePressure p(start=1e5);
  Medium.SpecificEnthalpy h(start=1e5);
  
  Medium.Density d;

equation 
  p = 1e5+1e5*time;
  h = 1e5+1e5*time;
  state = Medium.setState_ph(p,h);
  d = Medium.density(state);
end TestEM;

It looks like the near critical state causes some problems...

@jelemer
Copy link
Author

jelemer commented Apr 12, 2017

Ah yes, when I run the dymosim.exe I get the same output. So is there any way to get around this? As for now I can use the workaround using the tabulated values.

I just wanted to express my appreciation for all the help so far, this helped me a lot and although the issue is not completely solved yet, I now have a way to run my models.

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

No branches or pull requests

4 participants