[1D] Simplify interface for setting tolerances
This commit is contained in:
parent
63b6660632
commit
3e4c944416
6 changed files with 98 additions and 51 deletions
|
|
@ -252,19 +252,44 @@ public:
|
|||
}
|
||||
|
||||
//! set the error tolerances for all solution components.
|
||||
//! @deprecated Use setTransientTolerances() and setSteadyTolerances().
|
||||
void setTolerances(size_t nr, const doublereal* rtol,
|
||||
size_t na, const doublereal* atol, int ts = 0);
|
||||
|
||||
//! set the error tolerances for solution component \a n.
|
||||
//! @deprecated Use setTransientTolerances() and setSteadyTolerances().
|
||||
void setTolerances(size_t n, doublereal rtol, doublereal atol, int ts = 0);
|
||||
|
||||
//! set scalar error tolerances. All solution components will
|
||||
//! have the same relative and absolute error tolerances.
|
||||
//! set scalar error tolerances. All solution components will have the
|
||||
//! same relative and absolute error tolerances.
|
||||
//! @deprecated Use setTransientTolerances() and setSteadyTolerances().
|
||||
void setTolerances(doublereal rtol, doublereal atol,int ts=0);
|
||||
|
||||
void setTolerancesTS(doublereal rtol, doublereal atol);
|
||||
//! Set tolerances for time-stepping mode
|
||||
/*!
|
||||
* @param rtol Relative tolerance
|
||||
* @param atol Absolute tolerance
|
||||
* @param n component index these tolerances apply to. If set to -1
|
||||
* (the default), these tolerances will be applied to all solution
|
||||
* components.
|
||||
*/
|
||||
void setTransientTolerances(doublereal rtol, doublereal atol, size_t n=npos);
|
||||
|
||||
void setTolerancesSS(doublereal rtol, doublereal atol);
|
||||
//! @deprecated use setTransientTolerances()
|
||||
void setTolerancesTS(doublereal rtol, doublereal atol, size_t n=npos);
|
||||
|
||||
//! Set tolerances for steady-state mode
|
||||
/*!
|
||||
* @param rtol Relative tolerance
|
||||
* @param atol Absolute tolerance
|
||||
* @param n component index these tolerances apply to. If set to -1
|
||||
* (the default), these tolerances will be applied to all solution
|
||||
* components.
|
||||
*/
|
||||
void setSteadyTolerances(doublereal rtol, doublereal atol, size_t n=npos);
|
||||
|
||||
//! @deprecated use setSteadyTolerances()
|
||||
void setTolerancesSS(doublereal rtol, doublereal atol, size_t n=npos);
|
||||
|
||||
//! Relative tolerance of the nth component.
|
||||
doublereal rtol(size_t n) {
|
||||
|
|
|
|||
|
|
@ -365,7 +365,10 @@ cdef extern from "cantera/oneD/Domain1D.h":
|
|||
void setBounds(size_t, double, double)
|
||||
double upperBound(size_t)
|
||||
double lowerBound(size_t)
|
||||
void setTolerances(size_t, double, double, int)
|
||||
void setTransientTolerances(double, double)
|
||||
void setTransientTolerances(double, double, size_t)
|
||||
void setSteadyTolerances(double, double)
|
||||
void setSteadyTolerances(double, double, size_t)
|
||||
double rtol(size_t)
|
||||
double atol(size_t)
|
||||
double grid(size_t)
|
||||
|
|
|
|||
|
|
@ -77,7 +77,15 @@ cdef class Domain1D:
|
|||
unspecified components. The keyword *Y* can be used to stand for all
|
||||
species mass fractions in flow domains.
|
||||
"""
|
||||
self._set_tolerances(1, default, Y, kwargs)
|
||||
if default is not None:
|
||||
self.domain.setSteadyTolerances(default[0], default[1])
|
||||
|
||||
if Y is not None:
|
||||
for n in range(4, self.n_components):
|
||||
self.domain.setSteadyTolerances(Y[0], Y[1], n)
|
||||
|
||||
for name,(lower,upper) in kwargs.items():
|
||||
self.domain.setSteadyTolerances(lower, upper, self.component_name(name))
|
||||
|
||||
def set_transient_tolerances(self, *, default=None, Y=None, **kwargs):
|
||||
"""
|
||||
|
|
@ -89,21 +97,15 @@ cdef class Domain1D:
|
|||
unspecified components. The keyword *Y* can be used to stand for all
|
||||
species mass fractions in flow domains.
|
||||
"""
|
||||
self._set_tolerances(-1, default, Y, kwargs)
|
||||
|
||||
def _set_tolerances(self, is_transient, default, Y, components):
|
||||
if default is not None:
|
||||
for n in range(self.n_components):
|
||||
self.domain.setTolerances(n, default[0], default[1],
|
||||
is_transient)
|
||||
self.domain.setTransientTolerances(default[0], default[1])
|
||||
|
||||
if Y is not None:
|
||||
for n in range(4, self.n_components):
|
||||
self.domain.setTolerances(n, Y[0], Y[1], is_transient)
|
||||
self.domain.setTransientTolerances(Y[0], Y[1], n)
|
||||
|
||||
for name,(lower,upper) in components.items():
|
||||
self.domain.setTolerances(self.component_name(name),
|
||||
lower, upper, is_transient)
|
||||
for name,(lower,upper) in kwargs.items():
|
||||
self.domain.setTransientTolerances(lower, upper, self.component_name(name))
|
||||
|
||||
def bounds(self, component):
|
||||
"""
|
||||
|
|
|
|||
|
|
@ -17,6 +17,8 @@ void Domain1D::
|
|||
setTolerances(size_t nr, const doublereal* rtol,
|
||||
size_t na, const doublereal* atol, int ts)
|
||||
{
|
||||
warn_deprecated("Domain1D::setTolerances",
|
||||
"Use setTransientTolerances or setSteadyTolerances.");
|
||||
if (nr < m_nv || na < m_nv)
|
||||
throw CanteraError("Domain1D::setTolerances",
|
||||
"wrong array size for solution error tolerances. "
|
||||
|
|
@ -34,6 +36,8 @@ setTolerances(size_t nr, const doublereal* rtol,
|
|||
void Domain1D::
|
||||
setTolerances(size_t n, doublereal rtol, doublereal atol, int ts)
|
||||
{
|
||||
warn_deprecated("Domain1D::setTolerances",
|
||||
"Use setTransientTolerances or setSteadyTolerances.");
|
||||
if (ts >= 0) {
|
||||
m_rtol_ss[n] = rtol;
|
||||
m_atol_ss[n] = atol;
|
||||
|
|
@ -47,6 +51,8 @@ setTolerances(size_t n, doublereal rtol, doublereal atol, int ts)
|
|||
void Domain1D::
|
||||
setTolerances(doublereal rtol, doublereal atol,int ts)
|
||||
{
|
||||
warn_deprecated("Domain1D::setTolerances",
|
||||
"Use setTransientTolerances or setSteadyTolerances.");
|
||||
for (size_t n = 0; n < m_nv; n++) {
|
||||
if (ts >= 0) {
|
||||
m_rtol_ss[n] = rtol;
|
||||
|
|
@ -59,24 +65,46 @@ setTolerances(doublereal rtol, doublereal atol,int ts)
|
|||
}
|
||||
}
|
||||
|
||||
void Domain1D::
|
||||
setTolerancesTS(doublereal rtol, doublereal atol)
|
||||
void Domain1D::setTransientTolerances(doublereal rtol, doublereal atol, size_t n)
|
||||
{
|
||||
for (size_t n = 0; n < m_nv; n++) {
|
||||
if (n == npos) {
|
||||
for (n = 0; n < m_nv; n++) {
|
||||
m_rtol_ts[n] = rtol;
|
||||
m_atol_ts[n] = atol;
|
||||
}
|
||||
} else {
|
||||
m_rtol_ts[n] = rtol;
|
||||
m_atol_ts[n] = atol;
|
||||
}
|
||||
}
|
||||
|
||||
void Domain1D::
|
||||
setTolerancesSS(doublereal rtol, doublereal atol)
|
||||
void Domain1D::setTolerancesTS(doublereal rtol, doublereal atol, size_t n)
|
||||
{
|
||||
for (size_t n = 0; n < m_nv; n++) {
|
||||
warn_deprecated("Domain1D::setTolerancesTS",
|
||||
"Use setTransientTolerances");
|
||||
setTransientTolerances(rtol, atol, n);
|
||||
}
|
||||
|
||||
void Domain1D::setSteadyTolerances(doublereal rtol, doublereal atol, size_t n)
|
||||
{
|
||||
if (n == npos) {
|
||||
for (n = 0; n < m_nv; n++) {
|
||||
m_rtol_ss[n] = rtol;
|
||||
m_atol_ss[n] = atol;
|
||||
}
|
||||
} else {
|
||||
m_rtol_ss[n] = rtol;
|
||||
m_atol_ss[n] = atol;
|
||||
}
|
||||
}
|
||||
|
||||
void Domain1D::setTolerancesSS(doublereal rtol, doublereal atol, size_t n)
|
||||
{
|
||||
warn_deprecated("Domain1D::setTolerancesSS",
|
||||
"Use setSteadyTolerances");
|
||||
setSteadyTolerances(rtol, atol, n);
|
||||
}
|
||||
|
||||
void Domain1D::
|
||||
eval(size_t jg, doublereal* xg, doublereal* rg,
|
||||
integer* mask, doublereal rdt)
|
||||
|
|
|
|||
|
|
@ -161,10 +161,8 @@ StFlow::StFlow(IdealGasPhase* ph, size_t nsp, size_t points) :
|
|||
|
||||
|
||||
//-------------------- default error tolerances ----------------
|
||||
vector_fp rtol(m_nv, 1.0e-8);
|
||||
vector_fp atol(m_nv, 1.0e-15);
|
||||
setTolerances(rtol.size(), DATA_PTR(rtol), atol.size(), DATA_PTR(atol),false);
|
||||
setTolerances(rtol.size(), DATA_PTR(rtol), atol.size(), DATA_PTR(atol),true);
|
||||
setTransientTolerances(1.0e-8, 1.0e-15);
|
||||
setSteadyTolerances(1.0e-8, 1.0e-15);
|
||||
|
||||
//-------------------- grid refinement -------------------------
|
||||
m_refiner->setActive(0, false);
|
||||
|
|
|
|||
|
|
@ -122,9 +122,8 @@ init()
|
|||
setBounds(2, lower, 2, upper);
|
||||
|
||||
// set tolerances
|
||||
vector_fp rtol(2, 1e-4);
|
||||
vector_fp atol(2, 1.e-5);
|
||||
setTolerances(2, DATA_PTR(rtol), 2, DATA_PTR(atol));
|
||||
setSteadyTolerances(1e-4, 1e-5);
|
||||
setTransientTolerances(1e-4, 1e-5);
|
||||
|
||||
// if a flow domain is present on the left, then this must be
|
||||
// a right inlet. Note that an inlet object can only be a
|
||||
|
|
@ -288,9 +287,8 @@ init() //_init(1);
|
|||
setBounds(1, &lower, 1, &upper);
|
||||
|
||||
// set tolerances
|
||||
const doublereal rtol = 1e-4;
|
||||
const doublereal atol = 1.e-4;
|
||||
setTolerances(1, &rtol, 1, &atol);
|
||||
setSteadyTolerances(1e-4, 1e-4);
|
||||
setTransientTolerances(1e-4, 1e-4);
|
||||
}
|
||||
|
||||
void Empty1D::
|
||||
|
|
@ -351,9 +349,8 @@ init()
|
|||
setBounds(1, &lower, 1, &upper);
|
||||
|
||||
// set tolerances
|
||||
const doublereal rtol = 1e-4;
|
||||
const doublereal atol = 1.e-4;
|
||||
setTolerances(1, &rtol, 1, &atol);
|
||||
setSteadyTolerances(1e-4, 1e-4);
|
||||
setTransientTolerances(1e-4, 1e-4);
|
||||
}
|
||||
|
||||
void Symm1D::
|
||||
|
|
@ -438,9 +435,8 @@ init()
|
|||
setBounds(1, &lower, 1, &upper);
|
||||
|
||||
// set tolerances
|
||||
const doublereal rtol = 1e-4;
|
||||
const doublereal atol = 1.e-4;
|
||||
setTolerances(1, &rtol, 1, &atol);
|
||||
setSteadyTolerances(1e-4, 1e-4);
|
||||
setTransientTolerances(1e-4, 1e-4);
|
||||
if (m_flow_right) {
|
||||
m_flow_right->setViscosityFlag(false);
|
||||
}
|
||||
|
|
@ -565,9 +561,8 @@ init()
|
|||
setBounds(1, &lower, 1, &upper);
|
||||
|
||||
// set tolerances
|
||||
const doublereal rtol = 1e-4;
|
||||
const doublereal atol = 1.e-4;
|
||||
setTolerances(1, &rtol, 1, &atol);
|
||||
setSteadyTolerances(1e-4, 1e-4);
|
||||
setTransientTolerances(1e-4, 1e-4);
|
||||
|
||||
if (m_flow_left) {
|
||||
m_flow = m_flow_left;
|
||||
|
|
@ -704,9 +699,8 @@ init()
|
|||
setBounds(1, &lower, 1, &upper);
|
||||
|
||||
// set tolerances
|
||||
const doublereal rtol = 1e-4;
|
||||
const doublereal atol = 1.e-4;
|
||||
setTolerances(1, &rtol, 1, &atol);
|
||||
setSteadyTolerances(1e-4, 1e-4);
|
||||
setTransientTolerances(1e-4, 1e-4);
|
||||
}
|
||||
|
||||
void Surf1D::
|
||||
|
|
@ -795,13 +789,10 @@ init()
|
|||
upper[n+1] = 2.0;
|
||||
}
|
||||
setBounds(m_nv, DATA_PTR(lower), m_nv, DATA_PTR(upper));
|
||||
vector_fp rtol(m_nv), atol(m_nv);
|
||||
for (size_t n = 0; n < m_nv; n++) {
|
||||
rtol[n] = 1.0e-5;
|
||||
atol[n] = 1.0e-9;
|
||||
}
|
||||
atol[0] = 1.0e-4;
|
||||
setTolerances(m_nv, DATA_PTR(rtol), m_nv, DATA_PTR(atol));
|
||||
setSteadyTolerances(1.0e-5, 1.0e-9);
|
||||
setTransientTolerances(1.0e-5, 1.0e-9);
|
||||
setSteadyTolerances(1.0e-5, 1.0e-4, 0);
|
||||
setTransientTolerances(1.0e-5, 1.0e-4, 0);
|
||||
}
|
||||
|
||||
void ReactingSurf1D::
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue