From f13e2715bb9efed59167c7ddfb67040234765a01 Mon Sep 17 00:00:00 2001 From: Ray Speth Date: Fri, 18 Mar 2016 15:55:39 -0400 Subject: [PATCH] [1D] Add accessor functions for steady and relative tolerances The existing functions for getting tolerances are difficult to use because they return the tolerances based on the steady/unsteady mode of the solver which the user shouldn't have to care about (and can't easily set). --- include/cantera/oneD/Domain1D.h | 20 ++++++++++++ interfaces/cython/cantera/_cantera.pxd | 4 +++ interfaces/cython/cantera/onedim.pyx | 44 ++++++++++++++++++++++++++ 3 files changed, 68 insertions(+) diff --git a/include/cantera/oneD/Domain1D.h b/include/cantera/oneD/Domain1D.h index 1846611d1..7d77c46a5 100644 --- a/include/cantera/oneD/Domain1D.h +++ b/include/cantera/oneD/Domain1D.h @@ -271,6 +271,26 @@ public: return (m_rdt == 0.0 ? m_atol_ss[n] : m_atol_ts[n]); } + //! Steady relative tolerance of the nth component + double steady_rtol(size_t n) { + return m_rtol_ss[n]; + } + + //! Steady absolute tolerance of the nth component + double steady_atol(size_t n) { + return m_atol_ss[n]; + } + + //! Transient relative tolerance of the nth component + double transient_rtol(size_t n) { + return m_rtol_ts[n]; + } + + //! Transient absolute tolerance of the nth component + double transient_atol(size_t n) { + return m_atol_ts[n]; + } + //! Upper bound on the nth component. doublereal upperBound(size_t n) const { return m_max[n]; diff --git a/interfaces/cython/cantera/_cantera.pxd b/interfaces/cython/cantera/_cantera.pxd index a8bd982aa..a3ddbc071 100644 --- a/interfaces/cython/cantera/_cantera.pxd +++ b/interfaces/cython/cantera/_cantera.pxd @@ -604,6 +604,10 @@ cdef extern from "cantera/oneD/Domain1D.h": void setSteadyTolerances(double, double, size_t) double rtol(size_t) double atol(size_t) + double steady_rtol(size_t) + double steady_atol(size_t) + double transient_rtol(size_t) + double transient_atol(size_t) double grid(size_t) void setupGrid(size_t, double*) except + void setID(string) diff --git a/interfaces/cython/cantera/onedim.pyx b/interfaces/cython/cantera/onedim.pyx index b530370c5..67622b04b 100644 --- a/interfaces/cython/cantera/onedim.pyx +++ b/interfaces/cython/cantera/onedim.pyx @@ -131,6 +131,50 @@ cdef class Domain1D: k = self.component_index(component) return self.domain.rtol(k), self.domain.atol(k) + def steady_reltol(self, component=None): + """ + Return the relative error tolerance for the steady state problem for a + specified solution component, or all components if none is specified. + """ + if component is None: + return np.array([self.domain.steady_rtol(n) + for n in range(self.n_components)]) + else: + return self.domain.steady_rtol(self.component_index(component)) + + def steady_abstol(self, component=None): + """ + Return the absolute error tolerance for the steady state problem for a + specified solution component, or all components if none is specified. + """ + if component is None: + return np.array([self.domain.steady_atol(n) + for n in range(self.n_components)]) + else: + return self.domain.steady_atol(self.component_index(component)) + + def transient_reltol(self, component=None): + """ + Return the relative error tolerance for the transient problem for a + specified solution component, or all components if none is specified. + """ + if component is None: + return np.array([self.domain.transient_rtol(n) + for n in range(self.n_components)]) + else: + return self.domain.transient_rtol(self.component_index(component)) + + def transient_abstol(self, component=None): + """ + Return the absolute error tolerance for the transient problem for a + specified solution component, or all components if none is specified. + """ + if component is None: + return np.array([self.domain.transient_atol(n) + for n in range(self.n_components)]) + else: + return self.domain.transient_atol(self.component_index(component)) + property grid: """ The grid for this domain """ def __get__(self):