Cantera / cantera

Chemical kinetics, thermodynamics, and transport tool suite
https://cantera.org
Other
607 stars 346 forks source link

Pure substance convergence failure setting "UV" near saturation condition #971

Open speth opened 3 years ago

speth commented 3 years ago

Problem description

I ran into a case where the pure substance solver fails to converge when setting U and V to values which should be close to the saturated vapor curve. This example is for hydrogen, but I expect that it affects the other pure substance models as well. I'm also interested in whether this occurs along the saturated liquid curve.

Steps to reproduce

import cantera as ct
h2 = ct.Hydrogen()
h2.PQ = 1.5*ct.one_atm, 0.8
h2.UV = h2.u + 178000 / h2.density, None
h2()

Decreasing the value of the constant (178000) to 176000 allows the solver to converge, giving a point in the two-phase region with a quality of 0.9971, while increasing the value to 179000 gives a fully vaporized mixture.

Behavior

CanteraError: 
***********************************************************************
CanteraError thrown by Substance::set_xy:
No convergence. U = -4054528.3002410065, V = 0.4160401077523147
***********************************************************************

System information

ischoegl commented 3 years ago

Interesting. I wonder whether it’s a similar root finding issue like the one I suspect in #605. It may make sense to use a ‘canned’ root finder (boost?) instead of the custom ones that are currently implemented in the tpx solvers?

speth commented 3 years ago

Yes, I would agree that home-grown root finders are not generally the best choice. Besides Boost, which we are successfully using in a couple of places, the other thought would be to look at what CoolProp uses for this purpose.

bryanwweber commented 3 years ago

I think the lever rule algorithm in CoolProp works pretty well, so I agree it would be worth investigating how they handle this and see if the code could be ported, and/or adding CoolProp as a dependency (which we want to do anyways).

Although this might not involve our lever rule solver... Anyhow, CoolProp is certainly more robust in general so definitely worth looking at.

ischoegl commented 3 years ago

@bryanwweber / @speth ... is the current thought to deprecate TPX and move to CoolProp as a required dependency, or would it be to make CoolProp an optional extension?

Ad lever rule: TPX uses this also, but I am not sure that this is the problem. I recall some root finding beyond that was home-grown (for saturation pressure?), which at least for #605 may have caused some issues. It's been a while, and at the time I decided to not investigate further - the code appears to date back some time, and comments are sparse.

speth commented 3 years ago

Good question. I think if we are able to fairly easily pull CoolProp in as a Git submodule and compile it into Cantera automatically, like we do for some of our other dependencies, it would make sense to drop the TPX substance models. If that turns out to be too complicated, I might be more inclined to keep the TPX models around to provide at least some pure fluid capabilities when CoolProp isn't available.