You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
When creating a Solution for methanol using a Peng-Robinson equation of state, the incorrect density (off by orders of magnitude) is returned at temperatures and pressure where we'd expect methanol to be in a liquid phase. For example, at a TP of (300, 101325), I see a density of ~1.3 kg/m3, whereas liquid methanol would be around ~780 kg/m3.
Digging into the C++ code, it appears that there is some logic to "force" a certain solution to the cubic equation of state when multiple are found. However, I don't see any Python interface for doing that. In general, it's unclear whether a solution using the Peng-Robinson equation of state will reliable detect whether a fluid is in the liquid or vapor phase, and there doesn't seem to be a way to "help" the solver find the right density. If you can point me in the right direction, I'd be happy to work on a PR that addresses this issue.
spec=ct.Solution('methanol.yaml')
# Boiling point, used belowTb=64.96+273.15# Source of comparison:# https://www.engineeringtoolbox.com/methanol-density-specific-weight-temperature-pressure-d_2091.html# Expect to be a liquid:spec.TP=300, 101325print("Density @ 300K:", spec.density_mass) # Expected: 784.3 kg/m3# Expect to be a liquid:spec.TP=Tb-10, 101325print("Density @ Tb-10:", spec.density_mass)
# Expect to be a gas:spec.TP=400, 101325print("Density @ 400K:", spec.density_mass) # Expected: 0.976 kg/m3spec.TP=500, 101325print("Density @ 500K:", spec.density_mass) # Expected: 0.774 kg/m3
Printout:
Density @ 300K: 1.3016220571692458
Density @ Tb-10: 1.190107980566739
Density @ 400K: 0.9762144154660121
Density @ 500K: 0.7809704748372757
Behavior
As you can see, the density is very low (indicating a gas) even at temperatures below the boiling point of methanol. Expected values are shown as comments to the right of each line. I haven't debugged the C++ code to confirm this, but I suspect that there are multiple roots of the cubic polynomial, and the one corresponding to a gas phase is being returned.
System information
Cantera 3.0.0, installed with poetry
Mac M2 OSX
Python 3.12.3
Attachments
Additional context
The text was updated successfully, but these errors were encountered:
In my experience, the Peng Robinson equation of state is mostly meant for gaseous solutions. The MixtureFugacityTP class is the one responsible for deciding phase information. Unfortunately, I believe that class is incomplete and mostly the gas information is what it uses.
I think a better handling of the detection of the saturation temperature is what would be needed. The Gibbs balance between the liquid and vapor phases would allow for a better selection of the vapor or liquid solution. One thing is that I don't think any two-phase solutions are permitted currently.
@wandadars is correct - in its current form, Cantera is not set up for two-phase Solutions (outside of pure substances). Peng-Robinson et al are currently implemented to capture real gas behavior only. There are, however, some known glitches with the cubic solver, see #1699 or #1157, so logic improvements would be welcome. Beyond, all phases are implemented in C++ only; Python only serves as a more user-friendly interface, and does not provide access to all internal functions.
PS: apart from that, it does appear that some exception handling would be beneficial to indicate when the state can no longer be represented correctly.
Problem description
When creating a
Solution
for methanol using aPeng-Robinson
equation of state, the incorrect density (off by orders of magnitude) is returned at temperatures and pressure where we'd expect methanol to be in a liquid phase. For example, at a TP of(300, 101325)
, I see a density of~1.3 kg/m3
, whereas liquid methanol would be around~780 kg/m3
.Digging into the C++ code, it appears that there is some logic to "force" a certain solution to the cubic equation of state when multiple are found. However, I don't see any Python interface for doing that. In general, it's unclear whether a solution using the Peng-Robinson equation of state will reliable detect whether a fluid is in the liquid or vapor phase, and there doesn't seem to be a way to "help" the solver find the right density. If you can point me in the right direction, I'd be happy to work on a PR that addresses this issue.
Steps to reproduce
Using the following YAML file:
I load a
Solution
using Python:Printout:
Behavior
As you can see, the density is very low (indicating a gas) even at temperatures below the boiling point of methanol. Expected values are shown as comments to the right of each line. I haven't debugged the C++ code to confirm this, but I suspect that there are multiple roots of the cubic polynomial, and the one corresponding to a gas phase is being returned.
System information
Cantera
3.0.0, installed withpoetry
Attachments
Additional context
The text was updated successfully, but these errors were encountered: