Cantera  2.4.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  //! Fill in the vector *y* with the current state of the system
53  virtual void getState(double* y) {
54  throw NotImplementedError("FuncEval::getState");
55  }
56 
57  //! Number of equations.
58  virtual size_t neq()=0;
59 
60  //! Number of sensitivity parameters.
61  virtual size_t nparams() {
62  return m_sens_params.size();
63  }
64 
65  //! Enable or disable suppression of errors when calling eval()
66  void suppressErrors(bool suppress) {
67  m_suppress_errors = suppress;
68  }
69 
70  //! Get current state of error suppression
71  bool suppressErrors() const {
72  return m_suppress_errors;
73  };
74 
75  //! Return a string containing the text of any suppressed errors
76  std::string getErrors() const;
77 
78  //! Clear any previously-stored suppressed errors
79  void clearErrors() {
80  m_errors.clear();
81  };
82 
83  //! Values for the problem parameters for which sensitivities are computed
84  //! This is the array which is perturbed and passed back as the fourth
85  //! argument to eval().
87 
88  //! Scaling factors for each sensitivity parameter
90 
91 protected:
92  // If true, errors are accumulated in m_errors. Otherwise, they are printed
93  bool m_suppress_errors;
94 
95  //! Errors occuring during function evaluations
96  std::vector<std::string> m_errors;
97 };
98 
99 }
100 
101 #endif
An error indicating that an unimplemented function has been called.
Definition: ctexceptions.h:187
vector_fp m_paramScales
Scaling factors for each sensitivity parameter.
Definition: FuncEval.h:89
void clearErrors()
Clear any previously-stored suppressed errors.
Definition: FuncEval.h:79
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...
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:53
virtual size_t neq()=0
Number of equations.
std::vector< std::string > m_errors
Errors occuring during function evaluations.
Definition: FuncEval.h:96
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:81
bool suppressErrors() const
Get current state of error suppression.
Definition: FuncEval.h:71
virtual size_t nparams()
Number of sensitivity parameters.
Definition: FuncEval.h:61
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: AnyMap.cpp:8
void suppressErrors(bool suppress)
Enable or disable suppression of errors when calling eval()
Definition: FuncEval.h:66
Definitions for the classes that are thrown when Cantera experiences an error condition (also contain...