thorade / HelmholtzMedia

Modelica library for the calculation of fluid properties from a Helmholtz energy equation of state (EoS).
BSD 3-Clause "New" or "Revised" License
35 stars 16 forks source link

Problems with Helium model #22

Closed casella closed 10 years ago

casella commented 10 years ago

We are trying to use the Helium model for cryogenic system studies, possibly using OpenModelica. We already found some issues using Dymola. Please download this small package which allows you to reproduce them: http://home.deib.polimi.it/casella/transfer/HelmholtzBugs.mo

We have built a test case, named CheckDerivativesHeliumHelmholzFluids, to check the consistency of density derivatives by integrating them, and then comparing the result with the actual density changes. The model has been tested with other media (e.g., IF97 water, or ExternalMedia models of Helium) and it works. When using the Helium model of your library, if fails with this error message:

The following error was detected at time: 3.901681204235383E-005
Out of memory for array dimensions
It could due to too many matrices, infinite recursion, or uninitialized variables.
You can increase the size of 'Sizebuffer' in dymola/source/matrixop.h.
The stack of functions is:
HelmholtzMedia.HelmholtzFluids.Helium.EoS.f_i_Unique9
HelmholtzMedia.HelmholtzFluids.Helium.EoS.setHelmholtzDerivsSecond_Unique8
HelmholtzMedia.HelmholtzFluids.Helium.setState_phX_Unique42
HelmholtzMedia.Interfaces.PartialHelmholtzMedium.setState_ph_Unique41
HelmholtzMedia.Interfaces.PartialHelmholtzMedium.setState_ph_Unique41(p0, h, 0)

It looks pretty much low-level, can you have a look at it?

thorade commented 10 years ago

Thank you for the bug report, I have edited it a bit and moved parts of it:

thorade commented 10 years ago

Added the test from your file, thanks. If I understand correctly, one should run the simulation and check that

Correct? Using Butane, the simulation runs nicely and d_p_errand d_h_err are smaller than 1e-8. Now I'll start investigating why the simulation fails for Helium.

thorade commented 10 years ago

The error message suggests to increase the size of Sizebuffer. Increasing it by a factor of 10 did not change the error message at all.

thorade commented 10 years ago

The highest level function in the error message is setState_ph. In commit e71c7a361415485206c4c969e8f1272f849841f4 some print commands have been added. At the time of the error, the fluid is in the super-critical liquid-like region with p=230000 (above critical pressure) and h=-2165.19 (below critical enthalpy). Using these values directly, the setState_ph function converges (with 95 Newton iterations! That is slow!). So, still unclear to me where the error comes from.

thorade commented 10 years ago

With the changed start values, the test simulation does now run. Seems like it was due to the many Newton iterations in the setState_ph function. Changing the start values is always dangerous, because it might help in some cases but break others, so in the future watch out for new errors in the super-critical liquid-like region!

casella commented 10 years ago

A few comments regarding the integration test. In principle what you wrote above is correct. In practice, some integration error is inevitable, though one can keep it low by selecting a tight integration tolerance. The tests are set with a relative tolerance of 1e-10, so the relative errors d_p_err and d_h_err should have that order of magnitude (or less). In practice, a relative error of 1e-8 or even 1e-6 (which is then due to inconsistencies between the density function and its derivatives, not by integration errors which are much smaller) would still be acceptable, considering that this error eventually causes a lack or excess of mass of the same order of magnitude during transients in closed circuits where the pressure or the enthalpy spans the same interval.

casella commented 10 years ago

Thanks! The test case now works fine.

    Francesco

Il 22/09/2014 10:26, Matthis Thorade ha scritto:

Closed #22 https://github.com/thorade/HelmholtzMedia/issues/22.

— Reply to this email directly or view it on GitHub https://github.com/thorade/HelmholtzMedia/issues/22#event-168318242.

Francesco Casella - Ph.D. Dipartimento di Elettronica, Informazione e Bioingegneria Politecnico di Milano Via Ponzio 34/5 I-20133 MILANO - ITALY

Tel: +39-02-2399-3465 (Leonardo) +39-02-2399-7749 (Polo di Cremona) Fax: +39-02-2399-3412 e-mail: francesco.casella@polimi.it web: http://home.dei.polimi.it/casella Skype: callto://francesco.casella