oemof / tespy

Thermal Engineering Systems in Python (TESPy). This package provides a powerful simulation toolkit for thermal engineering plants such as power plants, district heating systems or heat pumps.
https://tespy.readthedocs.io
MIT License
256 stars 80 forks source link

[bug] T_mix_ph results depend strongly on T0 when water is involved #339

Open BenPortner opened 2 years ago

BenPortner commented 2 years ago

Current behavior

The helper function T_mix_ph can return very different results depending on the starting value when H2O is part of the mixture (see example).

Expected behavior

The function always returns the same value.

Proposed solution

The Newton algorithm should probably return NaN or None if it didn't converge.

Example

from tespy.tools.fluid_properties import T_mix_ph

T_mix_ph([1, 1e5, 2e6, {"H2O":0.99, "O2":0.01}], T0=800)
>>> 273.26000000000005
T_mix_ph([1, 1e5, 2e6, {"H2O":0.99, "O2":0.01}], T0=80)
>>> 749.5470656784826
fwitte commented 2 years ago

Hi,

thank you for reporting this. Unfortunately, TESPy (dev version) currently only solves for pure gaseous mixtures or pure fluids in liquid, two-phase or gaseous phase. The only exception is condensation of water in a gasous stream. Since the enthalpy value in your example is is somewhere in the two-phase region of water, the newton algorithm does not find a solution.

The reason why the Newton algorithm implemented for the fluid property functions does not throw an error is: Within the solving process of a network (especially at the beginning), the enthalpy/pressure values for some streams end up in regions that do not make much sense physically. If the function threw an error, the solving process would stop even if the overall network would still be solved later.

There is already a warning message in place, maybe we can promote that from debug to info or warning. What do you think?

Also, regarding the specific combination of values, you might be interested in the work @nkawerau is currently contributing (see #327). He is working on an implementation letting you choose between CoolProp and thermosteam, which is able to solve for multiphase mixtures.

Have nice week!

BenPortner commented 2 years ago

Hi Francesco,

I think it makes sense to keep the function quiet during normal usage of TesPy. It would still be handy to access the logger information though. Where are the logs currently stored?

Thanks. Ben

fwitte commented 2 years ago

In your home folder there should be a folder .tespy/log or something like that. You an also change logging, I‘ll update this later, when I am at my computer again.