Cantera / cantera

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

PDSS Water calculation error at 287.9K #577

Closed ctudpython closed 3 years ago

ctudpython commented 5 years ago

Cantera version

2.4.0

Operating System

Windows 7 (Linux also tested)

Python/MATLAB version

3.6.5 (Anaconda distribution)

Description of the problem

When trying to use the PDSS module for non-ideal mixtures, the calculation of the water density crashes at exactly 287.9 K regardless of the pressure used. Other temperatures work just fine.

A small model to check this is to get the xml file for the solution of NaCl from the repository: https://github.com/Cantera/cantera/blob/master/test_problems/VCSnonideal/NaCl_equil/HMW_NaCl.xml and changing a few lines of code (18-23) to disable the solute molalities. We change from:

      <soluteMolalities>
             Na+:6.0954
             Cl-:6.0954
             H+:2.1628E-9
             OH-:1.3977E-6
      </soluteMolalities>

to

      <!--soluteMolalities>
             Na+:6.0954
             Cl-:6.0954
             H+:2.1628E-9
             OH-:1.3977E-6
      </soluteMolalities-->

and we run this small code under jupyter notebook:

import numpy as np
import cantera as ct

liq = ct.Solution('HMW_NaCl.xml', 'NaCl_electrolyte') 
liq.TP = 287.9, 1e5
print(liq.report())

Then, the following error occurs:

CanteraError Traceback (most recent call last)

in () 1 liq = ct.Solution('HMW_NaCl.xml', 'NaCl_electrolyte') ----> 2 liq.TP = 287.9, 1e5 3 print(liq.report()) interfaces\cython\cantera\thermo.pyx in cantera._cantera.ThermoPhase.TP.__set__() CanteraError: *********************************************************************** CanteraError thrown by WaterPropsIAPWS::corr: Error occurred trying to find liquid density at (T,P) = 287.9 1678.12 *********************************************************************** We tried to track the function which is causing the error by comparing inputs and outputs of the failed iteration (which would work if we call the function separately). We tracked the error to the following files/classes/functions: 1)WaterPropsIAPWS.cpp -> void WaterPropsIAPWS::corr ->densLiq = _density_(temperature, pressure, WATER_LIQUID, densLiq) 2)WaterPropsIAPWS.cpp -> doublereal WaterPropsIAPWS::density ->_m_phi.dfind_(p_red, tau, deltaGuess) 3)WaterPropsIAPWSphi.cpp->doublereal WaterPropsIAPWSphi::dfind(doublereal p_red, doublereal tau, doublereal deltaGuess)

And there we did not go deeper. It would give no convergence when called with the previous code, but it would work if we did the calculation alone with the supposed input data of the corresponding failed iteration.

For more data or questions, we would be glad to give/answer them, respectively.

supra08 commented 5 years ago

@ctudpython, can I take up this issue?

ischoegl commented 4 years ago

I confirmed that the exact same behavior is observed with WaterSSTP (via #921 before fix was applied).

In [1]: import cantera as ct
   ...: water = ct.Water(backend='IAPWS95') # uses new option introduced in #921
   ...: water.TP
   ...:
Out[1]: (300.0, 101325.00031846752)

In [2]: water.P_sat
Out[2]: 3536.8066267992676

In [3]: water.TP = 287.9, 1e5
---------------------------------------------------------------------------
CanteraError                              Traceback (most recent call last)
<ipython-input-4-9394a227489f> in <module>()
----> 1 water.TP = 287.9, 1e5

/src/interfaces/cython/cantera/thermo.pyx in cantera._cantera.ThermoPhase.TP.__set__()
   1296             T = values[0] if values[0] is not None else self.T
   1297             P = values[1] if values[1] is not None else self.P
-> 1298             self.thermo.setState_TP(T, P)
   1299 
   1300     property TPX:

CanteraError: 
***********************************************************************
CanteraError thrown by WaterPropsIAPWS::corr:
Error occurred trying to find liquid density at (T,P) = 287.9  1678.1227333795669
***********************************************************************

There is a curious shift from compressed liquid to vapor, similar to the one observed in #721, although unlike in #721, both initial state and end state are in the compressed liquid phase.