modelica / ModelicaStandardLibrary

Free (standard conforming) library to model mechanical (1D/3D), electrical (analog, digital, machines), magnetic, thermal, fluid, control systems and hierarchical state machines. Also numerical functions and functions for strings, files and streams are included.
https://doc.modelica.org
BSD 3-Clause "New" or "Revised" License
472 stars 169 forks source link

Moist air at very low temperatures #2815

Open thorade opened 5 years ago

thorade commented 5 years ago

The nonlinear solver sometimes uses very low or even negative temperatures in function calls to h_pTX, resulting in errors, because of the log(T) in the h_Tlow function. I suggest to catch negative temperatures and return h=-inf for T<=0, will send a PR.

The following model was used to investigate and it revealed another problem:

model MoistAirTLowTest
  replaceable package Medium = Modelica.Media.Air.MoistAir;
  Modelica.Blocks.Sources.Ramp Tramp(
    height=-320,
    duration=0.8,
    offset=323.15,
    startTime=0.1)
    annotation (Placement(transformation(extent={{-80,38},{-60,60}})));

  Medium.AbsolutePressure pamb= 101325;
  Medium.Temperature T;
  Medium.SpecificEnthalpy h;

equation 
  T = Tramp.y;
  h = Medium.h_pTX(pamb,T,Medium.reference_X);
  annotation (uses(Modelica(version="3.2.2")));
end MoistAirTLowTest;

After simulation, plot h with T as independent variable. The bump in the curve might push the solver even further in the wrong direction, I believe.

moistairtlowtest
dietmarw commented 5 years ago

Next time, no need to create the issue. Just send the PR :-)

beutlich commented 5 years ago

Next time, no need to create the issue. Just send the PR :-)

Did I miss something?

annotation (uses(Modelica(version="3.2.2")));

And not even up-to-date. :wink:

dietmarw commented 5 years ago

The PR is basically an issue in itself. If somebody like @thorade is so nice to offer a PR they can simply save the effort of creating a separate issue.

beutlich commented 5 years ago

will send a PR.

Ah, I missed it.

thorade commented 5 years ago

The PR will only address the safeguard for log(T) but not the little bump. Ah, and forgive the crappy commit message, only thought about it after pushing.

Also, not sure yet why my model calls it in that region, and why there are no errors from saturationPressure or sublimationPressure.

beutlich commented 5 years ago

Ah, and forgive the crappy commit message, only thought about it after pushing

You still can git commit -ammend and git push --force, but otherwise, if we squash merge ...