diff --git a/interfaces/cython/cantera/test/test_onedim.py b/interfaces/cython/cantera/test/test_onedim.py index 38b479daa..2bbeb493e 100644 --- a/interfaces/cython/cantera/test/test_onedim.py +++ b/interfaces/cython/cantera/test/test_onedim.py @@ -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') diff --git a/src/oneD/StFlow.cpp b/src/oneD/StFlow.cpp index 043dd4aa6..eea955e9d 100644 --- a/src/oneD/StFlow.cpp +++ b/src/oneD/StFlow.cpp @@ -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]; }