[1D] Check that specified grid is monotonically increasing

This commit is contained in:
Ray Speth 2014-07-10 22:34:05 +00:00
parent 27e2aa16b8
commit a2e3e97a1f
2 changed files with 14 additions and 0 deletions

View file

@ -50,6 +50,16 @@ class TestOnedim(utilities.CanteraTest):
inlet.X = {'H2':0.3, 'O2':0.5, 'AR':0.2}
self.assertNear(inlet.X[gas2.species_index('H2')], 0.3)
def test_grid_check(self):
gas = ct.Solution('h2o2.xml')
flame = ct.FreeFlow(gas)
with self.assertRaises(RuntimeError):
flame.grid = [0, 0.1, 0.1, 0.2]
with self.assertRaises(RuntimeError):
flame.grid = [0, 0.1, 0.2, 0.05]
def test_unpicklable(self):
import pickle
gas = ct.Solution('h2o2.xml')

View file

@ -137,6 +137,10 @@ void StFlow::setupGrid(size_t n, const doublereal* z)
m_z[0] = z[0];
for (j = 1; j < m_points; j++) {
if (z[j] <= z[j-1]) {
throw CanteraError("StFlow::setupGrid",
"grid points must be monotonically increasing");
}
m_z[j] = z[j];
m_dz[j-1] = m_z[j] - m_z[j-1];
}