From 4b44c6618285679d00969cddcd12310586240c48 Mon Sep 17 00:00:00 2001 From: "Bryan W. Weber" Date: Wed, 2 Aug 2017 14:46:40 -0400 Subject: [PATCH] [1D/Cython] Adds Python interface to getRefineCriteria --- interfaces/cython/cantera/_cantera.pxd | 1 + interfaces/cython/cantera/onedim.py | 18 +++++++++++++++--- interfaces/cython/cantera/onedim.pyx | 17 +++++++++++++++++ 3 files changed, 33 insertions(+), 3 deletions(-) diff --git a/interfaces/cython/cantera/_cantera.pxd b/interfaces/cython/cantera/_cantera.pxd index 08e6165e8..22fdf7d67 100644 --- a/interfaces/cython/cantera/_cantera.pxd +++ b/interfaces/cython/cantera/_cantera.pxd @@ -721,6 +721,7 @@ cdef extern from "cantera/oneD/Sim1D.h": void solve(int, cbool) except +translate_exception void refine(int) except +translate_exception void setRefineCriteria(size_t, double, double, double, double) except +translate_exception + vector[double] getRefineCriteria(int) except +translate_exception void save(string, string, string, int) except +translate_exception void restore(string, string, int) except +translate_exception void writeStats(int) except +translate_exception diff --git a/interfaces/cython/cantera/onedim.py b/interfaces/cython/cantera/onedim.py index 8147c9e37..c8a135434 100644 --- a/interfaces/cython/cantera/onedim.py +++ b/interfaces/cython/cantera/onedim.py @@ -57,6 +57,18 @@ class FlameBase(Sim1D): super(FlameBase, self).set_refine_criteria(self.flame, ratio, slope, curve, prune) + def get_refine_criteria(self): + """ + Get a dictionary of the criteria used for grid refinement. The items in + the dictionary are the ``ratio``, ``slope``, ``curve``, and ``prune``, + as defined in `~FlameBase.set_refine_criteria`. + + >>> f.set_refine_criteria(ratio=3.0, slope=0.1, curve=0.2, prune=0) + >>> f.get_refine_criteria() + {'ratio': 3.0, 'slope': 0.1, 'curve': 0.2, 'prune': 0.0} + """ + return super(FlameBase, self).get_refine_criteria(self.flame) + def set_profile(self, component, locations, values): """ Set an initial estimate for a profile of one component. @@ -414,10 +426,10 @@ class FreeFlame(FlameBase): """ Set the initial guess for the solution. The adiabatic flame temperature and equilibrium composition are computed for the inlet gas - composition. - + composition. + :param locs: - A list of four locations to define the temperature and mass fraction profiles. + A list of four locations to define the temperature and mass fraction profiles. Profiles rise linearly between the second and third location. Locations are given as a fraction of the entire domain """ diff --git a/interfaces/cython/cantera/onedim.pyx b/interfaces/cython/cantera/onedim.pyx index b0dc26a43..fcc9294b8 100644 --- a/interfaces/cython/cantera/onedim.pyx +++ b/interfaces/cython/cantera/onedim.pyx @@ -997,6 +997,23 @@ cdef class Sim1D: idom = self.domain_index(domain) self.sim.setRefineCriteria(idom, ratio, slope, curve, prune) + def get_refine_criteria(self, domain): + """ + Get a dictionary of the criteria used to refine one domain. The items in + the dictionary are the ``ratio``, ``slope``, ``curve``, and ``prune``, + as defined in `~Sim1D.set_refine_criteria`. + + :param domain: + domain object, index, or name + + >>> s.set_refine_criteria(d, ratio=5.0, slope=0.2, curve=0.3, prune=0.03) + >>> s.get_refine_criteria(d) + {'ratio': 5.0, 'slope': 0.2, 'curve': 0.3, 'prune': 0.03} + """ + idom = self.domain_index(domain) + c = self.sim.getRefineCriteria(idom) + return {'ratio': c[0], 'slope': c[1], 'curve': c[2], 'prune': c[3]} + def set_grid_min(self, dz, domain=None): """ Set the minimum grid spacing on *domain*. If *domain* is None, then