Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Problem in vcs_phaseStability #187

Open
GoogleCodeExporter opened this issue Mar 26, 2015 · 5 comments
Open

Problem in vcs_phaseStability #187

GoogleCodeExporter opened this issue Mar 26, 2015 · 5 comments

Comments

@GoogleCodeExporter
Copy link

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
Copy link
Author

The script:

#Script adapted from multiphase_plasma.py to demonstrate the problem described by issue 187.

from Cantera import *
import numpy as np
# create objects representing the gas phase and the condensed
# phases. The gas is a mixture of multiple species, and the condensed
# phases are all modeled as incompressible stoichiometric
# substances. See file KOH.cti for more information.
phases = importPhases('KOH.cti',
                      ['K_solid',
                       'K_liquid', 'KOH_a', 'KOH_b',
                       'KOH_liquid', 'K2O2_solid',
                       'K2O_solid', 'KO2_solid',
                       'ice', 'liquid_water','KOH_plasma'])

# create the Mixture object from the list of phases
mix = Mixture(phases)

# open the output file and write the column headings
f = open('equil_koh.csv','w')
writeCSV(f,['T']+mix.speciesNames())

# loop over temperature
for t in np.linspace(300,5000,1000):
    print 'T = ',t
    mix.set(T= t, P = 0.01*OneAtm, Moles="O2:1")

    # set the mixture to a state of chemical equilibrium holding
    # temperature and pressure fixed
    # mix.equilibrate("TP",maxsteps=10000,loglevel=1)
    mix.vcs_equilibrate("TP",printLvl=0,maxsteps=10000,loglevel=0)

    # write out the moles of each species
    writeCSV(f,[t]+ list(mix.speciesMoles()))

# close the output file
f.close()

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

@GoogleCodeExporter
Copy link
Author

Segfault also occurs with the 2.1 branch.

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

  • Changed state: Accepted
  • Added labels: ****
  • Removed labels: ****

@GoogleCodeExporter
Copy link
Author

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

  • Added labels: ****
  • Removed labels: ****

@GoogleCodeExporter
Copy link
Author

Here 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

#Script adapted from multiphase_plasma.py to demonstrate 
# the problem described by issue 187.

from cantera import *
import numpy as np
import sys
import time

phases = import_phases('KOH.xml',
                       ['K_solid',
                        'K_liquid', 'KOH_a', 'KOH_b',
                        'KOH_liquid', 'K2O2_solid',
                        'K2O_solid', 'KO2_solid',
                        'ice', 'liquid_water','KOH_plasma'])

mix = Mixture(phases)

# loop over temperature
print '######### START OF EQUILIBRIUM SOLVES #########'
for t in np.linspace(400.1, 5000, 1000):
    print 'T = ',t
    sys.stdout.flush()
    time.sleep(0.01)

    mix.T = t
    mix.P = 0.01*one_atm
    mix.species_moles = "O2:1"

    mix.equilibrate("TP", 'vcs')
    print mix.phase_moles()

@speth
Copy link
Member

speth commented Jun 3, 2015

An even simpler case that demonstrates this problem (triggering the error in vcs_popPhaseID):

import cantera as ct

gas = ct.Solution('gri30.xml')
carbon = ct.Solution('graphite.xml')

gas.TPX = 923, ct.one_atm, {'H': 0.45, 'O': 0.55}
mix = ct.Mixture([(gas, 1.0), (carbon, 0.0)])
mix.T = 923
mix.P = ct.one_atm
mix.equilibrate('TP', solver='vcs', max_steps=10000)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants