Skip to content

Commit

Permalink
[Equil] Fix ElemRearrange when unused elements are present
Browse files Browse the repository at this point in the history
The solver could get stuck in an infinite loop when there were elements that
were not used in any species.
  • Loading branch information
speth committed Aug 18, 2016
1 parent 5435af2 commit 0bd8892
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 0 deletions.
27 changes: 27 additions & 0 deletions interfaces/cython/cantera/test/test_equilibrium.py
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,33 @@ def test_equil_gri_lean(self):
self.check(gas, CH4=0, O2=1, H2O=2, CO2=1)


class EquilExtraElements(utilities.CanteraTest):
def setUp(self):
s = """ideal_gas(elements='H Ar C O Cl N',
species='gri30: AR N2 CH4 O2 CO2 H2O CO H2 OH')"""
self.gas = ct.Solution(source=s)
self.gas.TP = 300, 101325
self.gas.set_equivalence_ratio(0.8, 'CH4', 'O2:1.0, N2:3.76')

def test_auto(self):
# Succeeds after falling back to VCS
self.gas.equilibrate('TP')
self.assertNear(self.gas['CH4'].X[0], 0.0)

@unittest.expectedFailure
def test_element_potential(self):
self.gas.equilibrate('TP', solver='element_potential')
self.assertNear(self.gas['CH4'].X[0], 0.0)

def test_gibbs(self):
self.gas.equilibrate('TP', solver='gibbs')
self.assertNear(self.gas['CH4'].X[0], 0.0)

def test_vcs(self):
self.gas.equilibrate('TP', solver='vcs')
self.assertNear(self.gas['CH4'].X[0], 0.0)


class VCS_EquilTest(EquilTestCases, utilities.CanteraTest):
def __init__(self, *args, **kwargs):
EquilTestCases.__init__(self, 'vcs')
Expand Down
1 change: 1 addition & 0 deletions src/equil/BasisOptimize.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -350,6 +350,7 @@ void ElemRearrange(size_t nComponents, const vector_fp& elementAbundances,
// Search the element vector. We first locate elements that are
// present in any amount. Then, we locate elements that are not
// present in any amount. Return its identity in K.
k = nelements;
size_t kk;
for (size_t ielem = jr; ielem < nelements; ielem++) {
kk = orderVectorElements[ielem];
Expand Down

0 comments on commit 0bd8892

Please sign in to comment.