From 53fb3bd341e7b81cabaa21597a5e9c1bf44a7be7 Mon Sep 17 00:00:00 2001 From: Ray Speth Date: Tue, 11 Nov 2014 00:12:19 +0000 Subject: [PATCH] [Test] Prevent infinite loop in TestSofcKinetics If an infinite loop occurs in the Newton solver, it indicates a problem, but this way the test will finish (and fail). --- interfaces/cython/cantera/test/test_kinetics.py | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/interfaces/cython/cantera/test/test_kinetics.py b/interfaces/cython/cantera/test/test_kinetics.py index 353e66111..c961a993f 100644 --- a/interfaces/cython/cantera/test/test_kinetics.py +++ b/interfaces/cython/cantera/test/test_kinetics.py @@ -384,9 +384,14 @@ class TestSofcKinetics(utilities.CanteraTest): """ Solve f(x) = C by Newton iteration. """ x0 = xstart dx = 1.0e-6 + + n = 0 while True: + n += 1 f0 = f(x0) - C x0 -= f0/(f(x0 + dx) - C - f0)*dx + if n > 1000: + raise Exception('No convergence in Newton solve') if abs(f0) < 0.00001: return x0