Skip to content

Commit

Permalink
[Python] Use decorator syntax for new FlowReactor properties
Browse files Browse the repository at this point in the history
Also implement getters for all new properties
  • Loading branch information
speth authored and ischoegl committed Jun 14, 2023
1 parent c65cb00 commit c274084
Show file tree
Hide file tree
Showing 5 changed files with 165 additions and 55 deletions.
15 changes: 15 additions & 0 deletions include/cantera/numerics/IdasIntegrator.h
Expand Up @@ -44,6 +44,9 @@ class IdasIntegrator : public Integrator
int nEquations() const override {
return static_cast<int>(m_neq);
}
int maxOrder() const override {
return m_maxord;
}
void setMaxOrder(int n) override;
void setMaxStepSize(double hmax) override;
void setMaxSteps(int nmax) override;
Expand All @@ -64,9 +67,21 @@ class IdasIntegrator : public Integrator
//! Error message information provide by IDAS
string m_error_message;

int maxNonlinIterations() const override {
return m_maxNonlinIters;
}
void setMaxNonlinIterations(int n) override;

int maxNonlinConvFailures() const override {
return m_maxNonlinConvFails;
}
void setMaxNonlinConvFailures(int n) override;

bool algebraicInErrorTest() const override {
return !m_setSuppressAlg;
}
void includeAlgebraicInErrorTest(bool yesno) override;

void setMethod(MethodType t) override;

protected:
Expand Down
19 changes: 19 additions & 0 deletions include/cantera/numerics/Integrator.h
Expand Up @@ -227,6 +227,11 @@ class Integrator
return 0;
}

virtual int maxOrder() const {
warn("maxOrder");
return 0;
}

//! Set the maximum integration order that will be used.
virtual void setMaxOrder(int n) {
warn("setMaxorder");
Expand Down Expand Up @@ -288,12 +293,26 @@ class Integrator
return stats;
}

virtual int maxNonlinIterations() const {
warn("maxNonlinIterations");
return 0;
}
virtual void setMaxNonlinIterations(int n) {
warn("setMaxNonlinIterations");
}

virtual int maxNonlinConvFailures() const {
warn("maxNonlinConvFailures");
return 0;
}
virtual void setMaxNonlinConvFailures(int n) {
warn("setMaxNonlinConvFailures");
}

virtual bool algebraicInErrorTest() const {
warn("algebraicInErrorTest");
return true;
}
virtual void includeAlgebraicInErrorTest(bool yesno) {
warn("includeAlgebraicInErrorTest");
}
Expand Down
24 changes: 24 additions & 0 deletions include/cantera/zeroD/FlowReactor.h
Expand Up @@ -70,24 +70,48 @@ class FlowReactor : public IdealGasReactor
m_sa_to_vol = sa_to_vol;
}

//! Get the steady state tolerances used to determine the initial state for
//! surface coverages
double inletSurfaceAtol() const {
return m_ss_atol;
}

//! Set the steady state tolerances used to determine the initial state for
//! surface coverages
void setInletSurfaceAtol(double atol) {
m_ss_atol = atol;
}

//! Get the steady state tolerances used to determine the initial state for
//! surface coverages
double inletSurfaceRtol() const {
return m_ss_rtol;
}

//! Set the steady state tolerances used to determine the initial state for
//! surface coverages
void setInletSurfaceRtol(double rtol) {
m_ss_rtol = rtol;
}

//! Get the steady state tolerances used to determine the initial state for
//! surface coverages
double inletSurfaceMaxSteps() const {
return m_max_ss_steps;
}

//! Set the steady state tolerances used to determine the initial state for
//! surface coverages
void setInletSurfaceMaxSteps(int max_steps) {
m_max_ss_steps = max_steps;
}

//! Get the steady state tolerances used to determine the initial state for
//! surface coverages
double inletSurfaceMaxErrorFailures() const {
return m_max_ss_error_fails;
}

//! Set the steady state tolerances used to determine the initial state for
//! surface coverages
void setInletSurfaceMaxErrorFailures(int max_fails) {
Expand Down
8 changes: 8 additions & 0 deletions interfaces/cython/cantera/reactor.pxd
Expand Up @@ -14,9 +14,13 @@ cdef extern from "cantera/numerics/Integrator.h" namespace "Cantera":
cdef cppclass CxxIntegrator "Cantera::Integrator":
CxxIntegrator()

int maxOrder()
void setMaxOrder(int) except +translate_exception
int maxNonlinIterations()
void setMaxNonlinIterations(int) except +translate_exception
int maxNonlinConvFailures()
void setMaxNonlinConvFailures(int) except +translate_exception
cbool algebraicInErrorTest()
void includeAlgebraicInErrorTest(cbool) except +translate_exception


Expand Down Expand Up @@ -70,9 +74,13 @@ cdef extern from "cantera/zerodim.h" namespace "Cantera":
double area() except +translate_exception
void setSurfaceAreaToVolumeRatio(double) except +translate_exception
double surfaceAreaToVolumeRatio() except +translate_exception
double inletSurfaceAtol()
void setInletSurfaceAtol(double) except +translate_exception
double inletSurfaceRtol()
void setInletSurfaceRtol(double) except +translate_exception
double inletSurfaceMaxSteps()
void setInletSurfaceMaxSteps(int) except +translate_exception
int inletSurfaceMaxErrorFailures()
void setInletSurfaceMaxErrorFailures(int) except +translate_exception

# walls
Expand Down
154 changes: 99 additions & 55 deletions interfaces/cython/cantera/reactor.pyx
Expand Up @@ -450,53 +450,81 @@ cdef class FlowReactor(Reactor):
def __set__(self, double value):
(<CxxFlowReactor*>self.reactor).setMassFlowRate(value)

property area:
@property
def area(self):
"""
Get/set the area of the reactor [m^2].
When the area is changed, the flow speed is scaled to keep the total mass flow
rate constant.
"""
def __get__(self):
return (<CxxFlowReactor*>self.reactor).area()
def __set__(self, area):
(<CxxFlowReactor*>self.reactor).setArea(area)

property inlet_surface_atol:
""" Set the steady-state tolerances used to determine the initial surface
species coverages"""
def __set__(self, atol):
(<CxxFlowReactor*>self.reactor).setInletSurfaceAtol(atol)

property inlet_surface_rtol:
""" Set the steady-state tolerances used to determine the initial surface
species coverages"""
def __set__(self, rtol):
(<CxxFlowReactor*>self.reactor).setInletSurfaceRtol(rtol)

property inlet_surface_max_steps:
""" Set the maximum number of integrator steps used to determine the initial surface
species coverages"""
def __set__(self, nsteps):
(<CxxFlowReactor*>self.reactor).setInletSurfaceMaxSteps(nsteps)
return (<CxxFlowReactor*>self.reactor).area()

property inlet_surface_max_error_failures:
""" Set the maximum number of integrator error failures allowed when determining
the initial surface species coverages"""
def __set__(self, nsteps):
(<CxxFlowReactor*>self.reactor).setInletSurfaceMaxErrorFailures(nsteps)
@area.setter
def area(self, area):
(<CxxFlowReactor*>self.reactor).setArea(area)

property surface_area_to_volume_ratio:
""" Get/set the surface area to volume ratio of the reactor [m^-1] """
def __get__(self):
return (<CxxFlowReactor*>self.reactor).surfaceAreaToVolumeRatio()
def __set__(self, sa_to_vol):
(<CxxFlowReactor*>self.reactor).setSurfaceAreaToVolumeRatio(sa_to_vol)
@property
def inlet_surface_atol(self):
"""
Get/Set the steady-state tolerances used to determine the initial surface
species coverages.
"""
return (<CxxFlowReactor*>self.reactor).inletSurfaceAtol()

property speed:
@inlet_surface_atol.setter
def inlet_surface_atol(self, atol):
(<CxxFlowReactor*>self.reactor).setInletSurfaceAtol(atol)

@property
def inlet_surface_rtol(self):
"""
Get/Set the steady-state tolerances used to determine the initial surface
species coverages.
"""
return (<CxxFlowReactor*>self.reactor).inletSurfaceRtol()

@inlet_surface_rtol.setter
def inlet_surface_rtol(self, rtol):
(<CxxFlowReactor*>self.reactor).setInletSurfaceRtol(rtol)

@property
def inlet_surface_max_steps(self):
"""
Get/Set the maximum number of integrator steps used to determine the initial
surface species coverages.
"""
return (<CxxFlowReactor*>self.reactor).inletSurfaceMaxSteps()

@inlet_surface_max_steps.setter
def inlet_surface_max_steps(self, nsteps):
(<CxxFlowReactor*>self.reactor).setInletSurfaceMaxSteps(nsteps)

@property
def inlet_surface_max_error_failures(self):
"""
Get/Set the maximum number of integrator error failures allowed when determining
the initial surface species coverages.
"""
return (<CxxFlowReactor*>self.reactor).inletSurfaceMaxErrorFailures()

@inlet_surface_max_error_failures.setter
def inlet_surface_max_error_failures(self, nsteps):
(<CxxFlowReactor*>self.reactor).setInletSurfaceMaxErrorFailures(nsteps)

@property
def surface_area_to_volume_ratio(self):
""" Get/Set the surface area to volume ratio of the reactor [m^-1] """
return (<CxxFlowReactor*>self.reactor).surfaceAreaToVolumeRatio()

@surface_area_to_volume_ratio.setter
def surface_area_to_volume_ratio(self, sa_to_vol):
(<CxxFlowReactor*>self.reactor).setSurfaceAreaToVolumeRatio(sa_to_vol)

@property
def speed(self):
""" Speed [m/s] of the flow in the reactor at the current position """
def __get__(self):
return (<CxxFlowReactor*>self.reactor).speed()
return (<CxxFlowReactor*>self.reactor).speed()


cdef class ExtensibleReactor(Reactor):
Expand Down Expand Up @@ -1326,37 +1354,53 @@ cdef class ReactorNet:
def __set__(self, n):
self.net.setMaxErrTestFails(n)

property max_nonlinear_iterations:
@property
def max_nonlinear_iterations(self):
"""
Set the maximum number of nonlinear solver iterations permitted by the SUNDIALS
solver in one solve attempt. The default value is 4.
Get/Set the maximum number of nonlinear solver iterations permitted by the
SUNDIALS solver in one solve attempt. The default value is 4.
"""
def __set__(self, int n):
self.net.integrator().setMaxNonlinIterations(n)
return self.net.integrator().maxNonlinIterations()

@max_nonlinear_iterations.setter
def max_nonlinear_iterations(self, int n):
self.net.integrator().setMaxNonlinIterations(n)

property max_nonlinear_convergence_failures:
@property
def max_nonlinear_convergence_failures(self):
"""
Set the maximum number of nonlinear solver convergence failures permitted in one
step of the SUNDIALS integrator. The default value is 10.
Get/Set the maximum number of nonlinear solver convergence failures permitted in
one step of the SUNDIALS integrator. The default value is 10.
"""
def __set__(self, int n):
self.net.integrator().setMaxNonlinConvFailures(n)
return self.net.integrator().maxNonlinConvFailures()

property include_algebraic_in_error_test:
@max_nonlinear_convergence_failures.setter
def max_nonlinear_convergence_failures(self, int n):
self.net.integrator().setMaxNonlinConvFailures(n)

@property
def include_algebraic_in_error_test(self):
"""
Set whether to include algebraic variables in the in the local error test.
Get/Set whether to include algebraic variables in the in the local error test.
Applicable only to DAE systems. The default is `True`.
"""
def __set__(self, pybool yesno):
self.net.integrator().includeAlgebraicInErrorTest(yesno)
return self.net.integrator().algebraicInErrorTest()

@include_algebraic_in_error_test.setter
def include_algebraic_in_error_test(self, pybool yesno):
self.net.integrator().includeAlgebraicInErrorTest(yesno)

property max_order:
@property
def max_order(self):
"""
Set the maximum order of the linear multistep method. The default value and
Get/Set the maximum order of the linear multistep method. The default value and
maximum is 5.
"""
def __set__(self, int n):
self.net.integrator().setMaxOrder(n)
return self.net.integrator().maxOrder()

@max_order.setter
def max_order(self, int n):
self.net.integrator().setMaxOrder(n)

property max_steps:
"""
Expand Down

0 comments on commit c274084

Please sign in to comment.