Cantera  2.3.0
FuncEval.h
Go to the documentation of this file.
1 /**
2  * @file FuncEval.h
3  */
4 
5 // This file is part of Cantera. See License.txt in the top-level directory or
6 // at http://www.cantera.org/license.txt for license and copyright information.
7 
8 #ifndef CT_FUNCEVAL_H
9 #define CT_FUNCEVAL_H
10 
11 #include "cantera/base/ct_defs.h"
13 #include "cantera/base/global.h"
14 
15 namespace Cantera
16 {
17 /**
18  * Virtual base class for ODE right-hand-side function evaluators.
19  * Classes derived from FuncEval evaluate the right-hand-side function
20  * \f$ \vec{F}(t,\vec{y})\f$ in
21  * \f[
22  * \dot{\vec{y}} = \vec{F}(t,\vec{y}).
23  * \f]
24  * @ingroup odeGroup
25  */
26 class FuncEval
27 {
28 public:
29  FuncEval();
30  virtual ~FuncEval() {}
31 
32  /**
33  * Evaluate the right-hand-side function. Called by the integrator.
34  * @param[in] t time.
35  * @param[in] y solution vector, length neq()
36  * @param[out] ydot rate of change of solution vector, length neq()
37  * @param[in] p sensitivity parameter vector, length nparams()
38  */
39  virtual void eval(double t, double* y, double* ydot, double* p)=0;
40 
41  //! Evaluate the right-hand side using return code to indicate status.
42  /*!
43  * Errors are indicated using the return value, rather than by throwing
44  * exceptions. This method is used when calling from a C-based integrator
45  * such as CVODES. Exceptions may either be stored or printed, based on the
46  * setting of suppressErrors().
47  * @returns 0 for a successful evaluation; 1 after a potentially-
48  * recoverable error; -1 after an unrecoverable error.
49  */
50  int eval_nothrow(double t, double* y, double* ydot);
51 
52  /**
53  * Fill the solution vector with the initial conditions
54  * at initial time t0.
55  * @deprecated Use getState() instead. To be removed after Cantera 2.3.
56  */
57  virtual void getInitialConditions(double t0, size_t leny, double* y) {
58  warn_deprecated("FuncEval::getInitialConditions",
59  "Use getState instead. To be removed after Cantera 2.3.");
60  getState(y);
61  }
62 
63  //! Fill in the vector *y* with the current state of the system
64  virtual void getState(double* y) {
65  throw NotImplementedError("FuncEval::getState");
66  }
67 
68  //! Number of equations.
69  virtual size_t neq()=0;
70 
71  //! Number of sensitivity parameters.
72  virtual size_t nparams() {
73  return m_sens_params.size();
74  }
75 
76  //! Enable or disable suppression of errors when calling eval()
77  void suppressErrors(bool suppress) {
78  m_suppress_errors = suppress;
79  }
80 
81  //! Get current state of error suppression
82  bool suppressErrors() const {
83  return m_suppress_errors;
84  };
85 
86  //! Return a string containing the text of any suppressed errors
87  std::string getErrors() const;
88 
89  //! Clear any previously-stored suppressed errors
90  void clearErrors() {
91  m_errors.clear();
92  };
93 
94  //! Values for the problem parameters for which sensitivities are computed
95  //! This is the array which is perturbed and passed back as the fourth
96  //! argument to eval().
98 
99  //! Scaling factors for each sensitivity parameter
101 
102 protected:
103  // If true, errors are accumulated in m_errors. Otherwise, they are printed
104  bool m_suppress_errors;
105 
106  //! Errors occuring during function evaluations
107  std::vector<std::string> m_errors;
108 };
109 
110 }
111 
112 #endif
An error indicating that an unimplemented function has been called.
Definition: ctexceptions.h:193
vector_fp m_paramScales
Scaling factors for each sensitivity parameter.
Definition: FuncEval.h:100
void clearErrors()
Clear any previously-stored suppressed errors.
Definition: FuncEval.h:90
std::string getErrors() const
Return a string containing the text of any suppressed errors.
Definition: FuncEval.cpp:45
This file contains definitions of terms that are used in internal routines and are unlikely to need m...
void warn_deprecated(const std::string &method, const std::string &extra)
Print a warning indicating that method is deprecated.
Definition: global.cpp:54
virtual void eval(double t, double *y, double *ydot, double *p)=0
Evaluate the right-hand-side function.
This file contains definitions for utility functions and text for modules, inputfiles, logs, textlogs, (see Input File Handling, Diagnostic Output, and Writing messages to the screen).
virtual void getState(double *y)
Fill in the vector y with the current state of the system.
Definition: FuncEval.h:64
virtual size_t neq()=0
Number of equations.
std::vector< std::string > m_errors
Errors occuring during function evaluations.
Definition: FuncEval.h:107
vector_fp m_sens_params
Values for the problem parameters for which sensitivities are computed This is the array which is per...
Definition: FuncEval.h:92
bool suppressErrors() const
Get current state of error suppression.
Definition: FuncEval.h:82
virtual size_t nparams()
Number of sensitivity parameters.
Definition: FuncEval.h:72
virtual void getInitialConditions(double t0, size_t leny, double *y)
Fill the solution vector with the initial conditions at initial time t0.
Definition: FuncEval.h:57
int eval_nothrow(double t, double *y, double *ydot)
Evaluate the right-hand side using return code to indicate status.
Definition: FuncEval.cpp:12
std::vector< double > vector_fp
Turn on the use of stl vectors for the basic array type within cantera Vector of doubles.
Definition: ct_defs.h:157
Virtual base class for ODE right-hand-side function evaluators.
Definition: FuncEval.h:26
Namespace for the Cantera kernel.
Definition: application.cpp:29
void suppressErrors(bool suppress)
Enable or disable suppression of errors when calling eval()
Definition: FuncEval.h:77
Definitions for the classes that are thrown when Cantera experiences an error condition (also contain...