jcaiuwyo / cantera

Automatically exported from code.google.com/p/cantera
0 stars 0 forks source link

Problem in vcs_phaseStability #187

Open GoogleCodeExporter opened 9 years ago

GoogleCodeExporter commented 9 years ago
What steps will reproduce the problem?
1. Run the attached script

What is the expected output? What do you see instead?
The expected output is a list of temperatures; after T=605.805805806 I get:
Segmentation fault (core dumped)

What version of the product are you using? On what operating system?
latest svn trunk (r2575) on Linux (x64), python2.7, gcc

Please provide any additional information below.
The example provided above is based on the python/equilibrium/multiphase_plasma 
example. Also, note that it does not always crash (importantly, not when 
running it in gdb!). The problem (seems to) lies in the vcs_phaseStability.cpp 
file, more precisely in the VCS_SOLVE::vcs_popPhaseRxnStepSizes function. 

In the script I attached, there are many solid phases included in the Mixture 
that are not allowed given the stoichiometry of the mix. This leads to cases 
where a negative value is calculated for the unsigned integer irxn:
size_t irxn = kspec - m_numComponents; (line 403)
Since irxn is used as a vector index (line 428, line 432), this leads to 
undefined behavior. 

This bug is very similar to the one patched with r2211. Maybe someone with a 
better understanding of the VCSnonideal solver can see what value irxn should 
take when kspec < m_numComponents.

Thanks!
Charles

Original issue reported on code.google.com by chdoi...@gmail.com on 18 Nov 2013 at 5:27

GoogleCodeExporter commented 9 years ago
The script:

Original comment by chdoi...@gmail.com on 18 Nov 2013 at 5:32

Attachments:

GoogleCodeExporter commented 9 years ago
Segfault also occurs with the 2.1 branch.

Original comment by yarmond on 20 Nov 2013 at 4:39

GoogleCodeExporter commented 9 years ago

Original comment by yarmond on 20 Nov 2013 at 4:39

GoogleCodeExporter commented 9 years ago
At least on my system, this still crashes when running in gdb.

Unfortunately, I don't think a fix similar to the one in r2211 will work here. 
In that case, there is code to handle the case where kspec < m_numComponents as 
long as irxn is given the special value 'npos'. But in 
vcs_popPhaseRxnStepSizes, I'm not sure what's supposed to happen when kspec < 
m_numComponents.

Original comment by yarmond on 22 Nov 2013 at 4:40

GoogleCodeExporter commented 9 years ago
Attached is a version of the script updated for the 'new' Python module. 
Running this code in Valgrind shows errors in two locations, both related to 
using 'kspec - m_numComponents' as an index: 

One is in VCS_SOLVE::vcs_popPhaseID, where irxn is calculated under the 
condition 'Vphase->m_singleSpecies'. (Line 285 of vcs_phaseStability.cpp in 
r2990).

The second is the previously-reported one in 
VCS_SOLVE::vcs_popPhaseRxnStepSizes (Line 367 of vcs_phaseStability.cpp in 
r2990).

Original comment by yarmond on 7 Jun 2014 at 5:59

Attachments: