Cantera 2.6.0
CVodesIntegrator.h
Go to the documentation of this file.
1/**
2 * @file CVodesIntegrator.h
3 */
4
5// This file is part of Cantera. See License.txt in the top-level directory or
6// at https://cantera.org/license.txt for license and copyright information.
7
8#ifndef CT_CVODESWRAPPER_H
9#define CT_CVODESWRAPPER_H
10
14
15#include "sundials/sundials_nvector.h"
16
17namespace Cantera
18{
19
20/**
21 * Wrapper class for 'cvodes' integrator from LLNL.
22 *
23 * @see FuncEval.h. Classes that use CVodesIntegrator:
24 * ImplicitChem, ImplicitSurfChem, Reactor
25 */
27{
28public:
29 /**
30 * Constructor. Default settings: dense Jacobian, no user-supplied
31 * Jacobian function, Newton iteration.
32 */
34 virtual ~CVodesIntegrator();
35 virtual void setTolerances(double reltol, size_t n, double* abstol);
36 virtual void setTolerances(double reltol, double abstol);
37 virtual void setSensitivityTolerances(double reltol, double abstol);
38 virtual void setProblemType(int probtype);
39 virtual void initialize(double t0, FuncEval& func);
40 virtual void reinitialize(double t0, FuncEval& func);
41 virtual void integrate(double tout);
42 virtual doublereal step(double tout);
43 virtual double& solution(size_t k);
44 virtual double* solution();
45 virtual double* derivative(double tout, int n);
46 virtual int lastOrder() const;
47 virtual int nEquations() const {
48 return static_cast<int>(m_neq);
49 }
50 virtual int nEvals() const;
51 virtual void setMaxOrder(int n) {
52 m_maxord = n;
53 }
54 virtual void setMethod(MethodType t);
55 virtual void setMaxStepSize(double hmax);
56 virtual void setMinStepSize(double hmin);
57 virtual void setMaxSteps(int nmax);
58 virtual int maxSteps();
59 virtual void setMaxErrTestFails(int n);
60 virtual void setBandwidth(int N_Upper, int N_Lower) {
61 m_mupper = N_Upper;
62 m_mlower = N_Lower;
63 }
64 virtual int nSensParams() {
65 return static_cast<int>(m_np);
66 }
67 virtual double sensitivity(size_t k, size_t p);
68
69 //! Returns a string listing the weighted error estimates associated
70 //! with each solution component.
71 //! This information can be used to identify which variables are
72 //! responsible for integrator failures or unexpected small timesteps.
73 virtual std::string getErrorInfo(int N);
74
75 //! Error message information provide by CVodes
76 std::string m_error_message;
77
78protected:
79 //! Applies user-specified options to the underlying CVODES solver. Called
80 //! during integrator initialization or reinitialization.
81 void applyOptions();
82
83private:
84 void sensInit(double t0, FuncEval& func);
85
86 size_t m_neq;
87 void* m_cvode_mem;
88 SundialsContext m_sundials_ctx; //!< SUNContext object for Sundials>=6.0
89 void* m_linsol; //!< Sundials linear solver object
90 void* m_linsol_matrix; //!< matrix used by Sundials
91 FuncEval* m_func;
92 double m_t0;
93 double m_time; //!< The current integrator time
94 N_Vector m_y, m_abstol;
95 N_Vector m_dky;
96 int m_type;
97 int m_itol;
98 int m_method;
99 int m_maxord;
100 double m_reltol;
101 double m_abstols;
102 double m_reltolsens, m_abstolsens;
103 size_t m_nabs;
104 double m_hmax, m_hmin;
105 int m_maxsteps;
106 int m_maxErrTestFails;
107 N_Vector* m_yS;
108 size_t m_np;
109 int m_mupper, m_mlower;
110
111 //! Indicates whether the sensitivities stored in m_yS have been updated
112 //! for at the current integrator time.
114};
115
116} // namespace
117
118#endif
Wrapper class for 'cvodes' integrator from LLNL.
virtual int nEvals() const
The number of function evaluations.
virtual int lastOrder() const
Order used during the last solution step.
virtual void setMinStepSize(double hmin)
Set the minimum step size.
void * m_linsol
Sundials linear solver object.
std::string m_error_message
Error message information provide by CVodes.
double m_time
The current integrator time.
bool m_sens_ok
Indicates whether the sensitivities stored in m_yS have been updated for at the current integrator ti...
virtual void initialize(double t0, FuncEval &func)
Initialize the integrator for a new problem.
SundialsContext m_sundials_ctx
SUNContext object for Sundials>=6.0.
virtual void integrate(double tout)
Integrate the system of equations.
virtual void setMaxSteps(int nmax)
Set the maximum number of time-steps the integrator can take before reaching the next output time.
virtual doublereal step(double tout)
Integrate the system of equations.
virtual void setSensitivityTolerances(double reltol, double abstol)
Set the sensitivity error tolerances.
virtual double * solution()
The current value of the solution of the system of equations.
virtual void setTolerances(double reltol, size_t n, double *abstol)
Set error tolerances.
virtual int maxSteps()
Returns the maximum number of time-steps the integrator can take before reaching the next output time...
virtual void setMaxStepSize(double hmax)
Set the maximum step size.
void applyOptions()
Applies user-specified options to the underlying CVODES solver.
virtual int nEquations() const
The number of equations.
virtual double * derivative(double tout, int n)
n-th derivative of the output function at time tout.
virtual void setProblemType(int probtype)
Set the problem type.
virtual void setMethod(MethodType t)
Set the solution method.
void * m_linsol_matrix
matrix used by Sundials
virtual void setMaxErrTestFails(int n)
Set the maximum permissible number of error test failures.
virtual std::string getErrorInfo(int N)
Returns a string listing the weighted error estimates associated with each solution component.
virtual void setMaxOrder(int n)
Set the maximum integration order that will be used.
Virtual base class for ODE right-hand-side function evaluators.
Definition: FuncEval.h:27
Abstract base class for ODE system integrators.
Definition: Integrator.h:53
A wrapper for managing a SUNContext object, need for Sundials >= 6.0.
Definitions for the classes that are thrown when Cantera experiences an error condition (also contain...
Namespace for the Cantera kernel.
Definition: AnyMap.h:29
MethodType
Specifies the method used to integrate the system of equations.
Definition: Integrator.h:32