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
11#include "cantera/numerics/Integrator.h"
12#include "cantera/numerics/SundialsContext.h"
13#include "cantera/base/ctexceptions.h"
14
15#include "sundials/sundials_nvector.h"
16
17 namespace 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 */
26 class CVodesIntegrator : public Integrator
27{
28 public:
29 /**
30 * Constructor. Default settings: dense Jacobian, no user-supplied
31 * Jacobian function, Newton iteration.
32 */
33 CVodesIntegrator();
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
78 protected:
79 //! Applies user-specified options to the underlying CVODES solver. Called
80 //! during integrator initialization or reinitialization.
81 void applyOptions();
82
83 private:
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.
113 bool m_sens_ok;
114};
115
116} // namespace
117
118#endif
Integrator.h
SundialsContext.h
Cantera::CVodesIntegrator
Wrapper class for 'cvodes' integrator from LLNL.
Definition: CVodesIntegrator.h:27
Cantera::CVodesIntegrator::nEvals
virtual int nEvals() const
The number of function evaluations.
Definition: CVodesIntegrator.cpp:588
Cantera::CVodesIntegrator::lastOrder
virtual int lastOrder() const
Order used during the last solution step.
Definition: CVodesIntegrator.cpp:581
Cantera::CVodesIntegrator::setMinStepSize
virtual void setMinStepSize(double hmin)
Set the minimum step size.
Definition: CVodesIntegrator.cpp:218
Cantera::CVodesIntegrator::m_linsol
void * m_linsol
Sundials linear solver object.
Definition: CVodesIntegrator.h:89
Cantera::CVodesIntegrator::m_error_message
std::string m_error_message
Error message information provide by CVodes.
Definition: CVodesIntegrator.h:76
Cantera::CVodesIntegrator::CVodesIntegrator
CVodesIntegrator()
Constructor.
Definition: CVodesIntegrator.cpp:92
Cantera::CVodesIntegrator::m_time
double m_time
The current integrator time.
Definition: CVodesIntegrator.h:93
Cantera::CVodesIntegrator::m_sens_ok
bool m_sens_ok
Indicates whether the sensitivities stored in m_yS have been updated for at the current integrator ti...
Definition: CVodesIntegrator.h:113
Cantera::CVodesIntegrator::initialize
virtual void initialize(double t0, FuncEval &func)
Initialize the integrator for a new problem.
Definition: CVodesIntegrator.cpp:278
Cantera::CVodesIntegrator::m_sundials_ctx
SundialsContext m_sundials_ctx
SUNContext object for Sundials>=6.0.
Definition: CVodesIntegrator.h:88
Cantera::CVodesIntegrator::integrate
virtual void integrate(double tout)
Integrate the system of equations.
Definition: CVodesIntegrator.cpp:526
Cantera::CVodesIntegrator::setMaxSteps
virtual void setMaxSteps(int nmax)
Set the maximum number of time-steps the integrator can take before reaching the next output time.
Definition: CVodesIntegrator.cpp:226
Cantera::CVodesIntegrator::step
virtual doublereal step(double tout)
Integrate the system of equations.
Definition: CVodesIntegrator.cpp:546
Cantera::CVodesIntegrator::setSensitivityTolerances
virtual void setSensitivityTolerances(double reltol, double abstol)
Set the sensitivity error tolerances.
Definition: CVodesIntegrator.cpp:188
Cantera::CVodesIntegrator::solution
virtual double * solution()
The current value of the solution of the system of equations.
Definition: CVodesIntegrator.cpp:160
Cantera::CVodesIntegrator::setTolerances
virtual void setTolerances(double reltol, size_t n, double *abstol)
Set error tolerances.
Definition: CVodesIntegrator.cpp:165
Cantera::CVodesIntegrator::maxSteps
virtual int maxSteps()
Returns the maximum number of time-steps the integrator can take before reaching the next output time...
Definition: CVodesIntegrator.cpp:234
Cantera::CVodesIntegrator::setMaxStepSize
virtual void setMaxStepSize(double hmax)
Set the maximum step size.
Definition: CVodesIntegrator.cpp:210
Cantera::CVodesIntegrator::applyOptions
void applyOptions()
Applies user-specified options to the underlying CVODES solver.
Definition: CVodesIntegrator.cpp:389
Cantera::CVodesIntegrator::nEquations
virtual int nEquations() const
The number of equations.
Definition: CVodesIntegrator.h:47
Cantera::CVodesIntegrator::derivative
virtual double * derivative(double tout, int n)
n-th derivative of the output function at time tout.
Definition: CVodesIntegrator.cpp:565
Cantera::CVodesIntegrator::setProblemType
virtual void setProblemType(int probtype)
Set the problem type.
Definition: CVodesIntegrator.cpp:194
Cantera::CVodesIntegrator::setMethod
virtual void setMethod(MethodType t)
Set the solution method.
Definition: CVodesIntegrator.cpp:199
Cantera::CVodesIntegrator::m_linsol_matrix
void * m_linsol_matrix
matrix used by Sundials
Definition: CVodesIntegrator.h:90
Cantera::CVodesIntegrator::setMaxErrTestFails
virtual void setMaxErrTestFails(int n)
Set the maximum permissible number of error test failures.
Definition: CVodesIntegrator.cpp:239
Cantera::CVodesIntegrator::getErrorInfo
virtual std::string getErrorInfo(int N)
Returns a string listing the weighted error estimates associated with each solution component.
Definition: CVodesIntegrator.cpp:621
Cantera::CVodesIntegrator::setMaxOrder
virtual void setMaxOrder(int n)
Set the maximum integration order that will be used.
Definition: CVodesIntegrator.h:51
Cantera::FuncEval
Virtual base class for ODE right-hand-side function evaluators.
Definition: FuncEval.h:27
Cantera::Integrator
Abstract base class for ODE system integrators.
Definition: Integrator.h:53
Cantera::SundialsContext
A wrapper for managing a SUNContext object, need for Sundials >= 6.0.
Definition: SundialsContext.h:20
ctexceptions.h
Definitions for the classes that are thrown when Cantera experiences an error condition (also contain...
Cantera
Namespace for the Cantera kernel.
Definition: AnyMap.cpp:557
Cantera::MethodType
MethodType
Specifies the method used to integrate the system of equations.
Definition: Integrator.h:32