From 4911539b565bffd0b30ffd26e04c30f085b85768 Mon Sep 17 00:00:00 2001 From: Ray Speth Date: Thu, 2 Aug 2018 17:16:02 -0400 Subject: [PATCH] [1D] Refine grid after expanding domain width The test for a sufficiently wide domain short circuits the normal control logic which makes a call to refine() after each successful steady-state solve. This caused failures for certain cases where sucessive solutions on wider grids with only a few points still failed to satisfy the gradient criterion at the edges of the domain. --- interfaces/cython/cantera/onedim.py | 4 +++- interfaces/cython/cantera/test/test_onedim.py | 10 ++++++++++ 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/interfaces/cython/cantera/onedim.py b/interfaces/cython/cantera/onedim.py index 01d60e33c..f1695d1a1 100644 --- a/interfaces/cython/cantera/onedim.py +++ b/interfaces/cython/cantera/onedim.py @@ -508,7 +508,7 @@ class FreeFlame(FlameBase): # The domain is considered too narrow if gradient at the left or # right edge is significant, compared to the average gradient across # the domain. - if mLeft > 0.05 or mRight > 0.05: + if mLeft > 0.02 or mRight > 0.02: raise DomainTooNarrow() if original_callback: @@ -527,6 +527,8 @@ class FreeFlame(FlameBase): print('Expanding domain to accomodate flame thickness. ' 'New width: {} m'.format( self.flame.grid[-1] - self.flame.grid[0])) + if refine_grid: + self.refine(loglevel) self.set_steady_callback(original_callback) diff --git a/interfaces/cython/cantera/test/test_onedim.py b/interfaces/cython/cantera/test/test_onedim.py index 5faac30b1..77886f25a 100644 --- a/interfaces/cython/cantera/test/test_onedim.py +++ b/interfaces/cython/cantera/test/test_onedim.py @@ -170,6 +170,16 @@ class TestFreeFlame(utilities.CanteraTest): Tad = self.gas.T self.assertNear(Tad, self.sim.T[-1], 2e-2) + def test_auto_width2(self): + self.create_sim(p=ct.one_atm, Tin=400, reactants='H2:0.8, O2:0.5', + width=0.1) + + self.sim.set_refine_criteria(ratio=4, slope=0.8, curve=0.8) + self.sim.solve(refine_grid=True, auto=True, loglevel=0) + self.assertNear(self.sim.u[0], 17.02, 1e-1) + self.assertLess(self.sim.grid[-1], 2.0) # grid should not be too wide + + def test_converge_adiabatic(self): # Test that the adiabatic flame temperature and species profiles # converge to the correct equilibrium values as the grid is refined