mirror of
https://github.com/Cantera/cantera.git
synced 2026-08-08 04:04:52 -05:00
Combine CVODES stats retrieval functions
This commit is contained in:
@@ -56,8 +56,7 @@ public:
|
||||
virtual void setMaxSteps(int nmax);
|
||||
virtual int maxSteps();
|
||||
virtual void setMaxErrTestFails(int n);
|
||||
virtual AnyMap nonlinearSolverStats() const;
|
||||
virtual AnyMap linearSolverStats() const;
|
||||
virtual AnyMap solverStats() const;
|
||||
void setLinearSolverType(const std::string& linSolverType) {
|
||||
m_type = linSolverType;
|
||||
}
|
||||
|
||||
@@ -278,17 +278,10 @@ public:
|
||||
return 0.0;
|
||||
}
|
||||
|
||||
//! Get nonlinear solver stats from integrator
|
||||
virtual AnyMap nonlinearSolverStats() const {
|
||||
//! Get solver stats from integrator
|
||||
virtual AnyMap solverStats() const {
|
||||
AnyMap stats;
|
||||
warn("nonlinearSolverStats");
|
||||
return stats;
|
||||
}
|
||||
|
||||
//! Get linear solver stats from integrator
|
||||
virtual AnyMap linearSolverStats() const {
|
||||
AnyMap stats;
|
||||
warn("linearSolverStats");
|
||||
warn("solverStats");
|
||||
return stats;
|
||||
}
|
||||
|
||||
|
||||
@@ -276,11 +276,8 @@ public:
|
||||
|
||||
virtual void preconditionerSolve(double* rhs, double* output);
|
||||
|
||||
//! Use this to get nonlinear solver stats from Integrator
|
||||
AnyMap nonlinearSolverStats() const;
|
||||
|
||||
//! Get linear solver stats from integrator
|
||||
AnyMap linearSolverStats() const;
|
||||
//! Get solver stats from integrator
|
||||
AnyMap solverStats() const;
|
||||
|
||||
//! Set derivative settings of all reactors
|
||||
//! @param settings the settings map propagated to all reactors and kinetics objects
|
||||
|
||||
@@ -162,8 +162,7 @@ cdef extern from "cantera/zerodim.h" namespace "Cantera":
|
||||
string linearSolverType()
|
||||
void setPreconditioner(shared_ptr[CxxPreconditionerBase] preconditioner)
|
||||
void setDerivativeSettings(CxxAnyMap&)
|
||||
CxxAnyMap linearSolverStats()
|
||||
CxxAnyMap nonlinearSolverStats()
|
||||
CxxAnyMap solverStats()
|
||||
|
||||
cdef extern from "cantera/zeroD/ReactorDelegator.h" namespace "Cantera":
|
||||
cdef cppclass CxxReactorAccessor "Cantera::ReactorAccessor":
|
||||
|
||||
@@ -1503,18 +1503,11 @@ cdef class ReactorNet:
|
||||
return pystr(self.net.linearSolverType())
|
||||
|
||||
|
||||
property linear_solver_stats:
|
||||
"""Linear solver stats from integrator"""
|
||||
property solver_stats:
|
||||
"""ODE solver stats from integrator"""
|
||||
def __get__(self):
|
||||
cdef CxxAnyMap stats
|
||||
stats = self.net.linearSolverStats()
|
||||
return anymap_to_dict(stats)
|
||||
|
||||
property nonlinear_solver_stats:
|
||||
"""Nonlinear solver stats from integrator"""
|
||||
def __get__(self):
|
||||
cdef CxxAnyMap stats
|
||||
stats = self.net.nonlinearSolverStats()
|
||||
stats = self.net.solverStats()
|
||||
return anymap_to_dict(stats)
|
||||
|
||||
property derivative_settings:
|
||||
|
||||
@@ -49,12 +49,8 @@ def integrate_reactor(n_reactors=15, preconditioner=True):
|
||||
else:
|
||||
print(f"Non-preconditioned Integration Time: {integ_time:f}")
|
||||
# Get and output solver stats
|
||||
lin_stats = sim.linear_solver_stats
|
||||
nonlin_stats = sim.nonlinear_solver_stats
|
||||
for key in lin_stats:
|
||||
print(key, lin_stats[key])
|
||||
for key in nonlin_stats:
|
||||
print(key, nonlin_stats[key])
|
||||
for key, value in sim.solver_stats.items():
|
||||
print(key, value)
|
||||
print("\n")
|
||||
# return some variables for plotting
|
||||
return states.time, states.T, states('CO2').Y, states('C12H26').Y
|
||||
|
||||
@@ -621,34 +621,15 @@ int CVodesIntegrator::nEvals() const
|
||||
return ne;
|
||||
}
|
||||
|
||||
AnyMap CVodesIntegrator::nonlinearSolverStats() const
|
||||
{
|
||||
long int iters = 0, conv_fails = 0;
|
||||
// AnyMap to return stats
|
||||
AnyMap stats;
|
||||
#if CT_SUNDIALS_VERSION >= 40
|
||||
CVodeGetNonlinSolvStats(m_cvode_mem, &iters, &conv_fails);
|
||||
#else
|
||||
warn_user("CVodesIntegrator::nonlinearSolverStats", "Function not"
|
||||
"supported with sundials versions less than 4.");
|
||||
#endif
|
||||
// Add values to AnyMap
|
||||
stats["nonlinear_iters"] = iters;
|
||||
stats["nonlinear_conv_fails"] = conv_fails;
|
||||
return stats;
|
||||
}
|
||||
|
||||
AnyMap CVodesIntegrator::linearSolverStats() const
|
||||
AnyMap CVodesIntegrator::solverStats() const
|
||||
{
|
||||
// long int linear solver stats provided by CVodes
|
||||
long int jacEvals = 0, linRhsEvals = 0, linIters = 0, linConvFails = 0,
|
||||
precEvals = 0, precSolves = 0, jtSetupEvals = 0, jTimesEvals = 0;
|
||||
// AnyMap to return stats
|
||||
AnyMap stats;
|
||||
#if CT_SUNDIALS_VERSION >= 60
|
||||
CVodeGetLinSolveStats(m_cvode_mem, &jacEvals, &linRhsEvals, &linIters,
|
||||
&linConvFails, &precEvals, &precSolves, &jtSetupEvals, &jTimesEvals);
|
||||
#elif CT_SUNDIALS_VERSION >= 40
|
||||
precEvals = 0, precSolves = 0, jtSetupEvals = 0, jTimesEvals = 0,
|
||||
nonlin_iters = 0, nonlin_conv_fails = 0;
|
||||
;
|
||||
#if CT_SUNDIALS_VERSION >= 40
|
||||
CVodeGetNonlinSolvStats(m_cvode_mem, &nonlin_iters, &nonlin_conv_fails);
|
||||
CVodeGetNumJacEvals(m_cvode_mem, &jacEvals);
|
||||
CVodeGetNumLinRhsEvals(m_cvode_mem, &linRhsEvals);
|
||||
CVodeGetNumLinIters(m_cvode_mem, &linIters);
|
||||
@@ -658,10 +639,12 @@ AnyMap CVodesIntegrator::linearSolverStats() const
|
||||
CVodeGetNumJTSetupEvals(m_cvode_mem, &jtSetupEvals);
|
||||
CVodeGetNumJtimesEvals(m_cvode_mem, &jTimesEvals);
|
||||
#else
|
||||
warn_user("CVodesIntegrator::linearSolverStats", "Function not"
|
||||
warn_user("CVodesIntegrator::solverStats", "Function not"
|
||||
"supported with sundials versions less than 4.");
|
||||
#endif
|
||||
// Add data to AnyMap
|
||||
|
||||
// AnyMap to return stats
|
||||
AnyMap stats;
|
||||
stats["jac_evals"] = jacEvals;
|
||||
stats["lin_rhs_evals"] = linRhsEvals;
|
||||
stats["lin_iters"] = linIters;
|
||||
@@ -670,6 +653,8 @@ AnyMap CVodesIntegrator::linearSolverStats() const
|
||||
stats["prec_solves"] = precSolves;
|
||||
stats["jt_vec_setup_evals"] = jtSetupEvals;
|
||||
stats["jt_vec_prod_evals"] = jTimesEvals;
|
||||
stats["nonlinear_iters"] = nonlin_iters;
|
||||
stats["nonlinear_conv_fails"] = nonlin_conv_fails;
|
||||
return stats;
|
||||
}
|
||||
|
||||
|
||||
@@ -424,14 +424,9 @@ void ReactorNet::setDerivativeSettings(AnyMap& settings)
|
||||
}
|
||||
}
|
||||
|
||||
AnyMap ReactorNet::nonlinearSolverStats() const
|
||||
AnyMap ReactorNet::solverStats() const
|
||||
{
|
||||
return m_integ->nonlinearSolverStats();
|
||||
}
|
||||
|
||||
AnyMap ReactorNet::linearSolverStats() const
|
||||
{
|
||||
return m_integ->linearSolverStats();
|
||||
return m_integ->solverStats();
|
||||
}
|
||||
|
||||
std::string ReactorNet::linearSolverType() const
|
||||
|
||||
+12
-14
@@ -150,21 +150,19 @@ TEST(AdaptivePreconditionerTests, test_precon_solver_stats)
|
||||
EXPECT_THROW(network.step(), CanteraError);
|
||||
// take a step
|
||||
network.setLinearSolverType("GMRES");
|
||||
// get linear solver stats
|
||||
// get solver stats
|
||||
network.step();
|
||||
AnyMap linearStats = network.linearSolverStats();
|
||||
EXPECT_GE(linearStats["jac_evals"].asInt(), 0);
|
||||
EXPECT_GE(linearStats["lin_rhs_evals"].asInt(), 0);
|
||||
EXPECT_GE(linearStats["lin_iters"].asInt(), 0);
|
||||
EXPECT_GE(linearStats["lin_conv_fails"].asInt(), 0);
|
||||
EXPECT_GE(linearStats["prec_evals"].asInt(), 0);
|
||||
EXPECT_GE(linearStats["prec_solves"].asInt(), 0);
|
||||
EXPECT_GE(linearStats["jt_vec_setup_evals"].asInt(), 0);
|
||||
EXPECT_GE(linearStats["jt_vec_prod_evals"].asInt(), 0);
|
||||
// nonlinear solver stats
|
||||
AnyMap nonlinearStats = network.nonlinearSolverStats();
|
||||
EXPECT_GE(nonlinearStats["nonlinear_iters"].asInt(), 0);
|
||||
EXPECT_GE(nonlinearStats["nonlinear_conv_fails"].asInt(), 0);
|
||||
AnyMap stats = network.solverStats();
|
||||
EXPECT_GE(stats["jac_evals"].asInt(), 0);
|
||||
EXPECT_GE(stats["lin_rhs_evals"].asInt(), 0);
|
||||
EXPECT_GE(stats["lin_iters"].asInt(), 0);
|
||||
EXPECT_GE(stats["lin_conv_fails"].asInt(), 0);
|
||||
EXPECT_GE(stats["prec_evals"].asInt(), 0);
|
||||
EXPECT_GE(stats["prec_solves"].asInt(), 0);
|
||||
EXPECT_GE(stats["jt_vec_setup_evals"].asInt(), 0);
|
||||
EXPECT_GE(stats["jt_vec_prod_evals"].asInt(), 0);
|
||||
EXPECT_GE(stats["nonlinear_iters"].asInt(), 0);
|
||||
EXPECT_GE(stats["nonlinear_conv_fails"].asInt(), 0);
|
||||
}
|
||||
|
||||
int main(int argc, char** argv)
|
||||
|
||||
Reference in New Issue
Block a user