00001 // Function.h --- 00002 // 00003 // Filename: Function.h 00004 // Description: 00005 // Author: Subhasis Ray 00006 // Maintainer: 00007 // Created: Fri May 30 19:34:13 2014 (+0530) 00008 // Version: 00009 // Last-Updated: 00010 // By: 00011 // Update #: 0 00012 // URL: 00013 // Keywords: 00014 // Compatibility: 00015 // 00016 // 00017 00018 // Commentary: 00019 // 00020 // A new version of Func with FieldElements to collect data. 00021 // 00022 // 00023 00024 // Change log: 00025 // 00026 // 00027 // 00028 // 00029 // This program is free software; you can redistribute it and/or 00030 // modify it under the terms of the GNU General Public License as 00031 // published by the Free Software Foundation; either version 3, or 00032 // (at your option) any later version. 00033 // 00034 // This program is distributed in the hope that it will be useful, 00035 // but WITHOUT ANY WARRANTY; without even the implied warranty of 00036 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00037 // General Public License for more details. 00038 // 00039 // You should have received a copy of the GNU General Public License 00040 // along with this program; see the file COPYING. If not, write to 00041 // the Free Software Foundation, Inc., 51 Franklin Street, Fifth 00042 // Floor, Boston, MA 02110-1301, USA. 00043 // 00044 // 00045 00046 // Code: 00047 00048 #ifndef _FUNCTION_H 00049 #define _FUNCTION_H 00050 00051 #include "muParser.h" 00052 00058 double *_functionAddVar(const char *name, void *data); 00059 00060 class Function 00061 { 00062 public: 00063 static const int VARMAX; 00064 Function(); 00065 Function(const Function& rhs); 00066 ~Function(); 00067 void setExpr( const Eref& e, string expr); 00068 string getExpr( const Eref& e ) const; 00069 00070 00071 // get a list of variable identifiers. 00072 // this is created by the parser 00073 vector<string> getVars() const; 00074 void setVarValues(vector< string > vars, vector < double > vals); 00075 00076 00077 // get/set the value of variable `name` 00078 void setVar(unsigned int index, double value); 00079 Variable * getVar(unsigned int ii); 00080 00081 // get function eval result 00082 double getValue() const; 00083 00084 double getRate() const; 00085 00086 // get/set operation mode 00087 void setMode(unsigned int mode); 00088 unsigned int getMode() const; 00089 00090 void setNumVar(unsigned int num); 00091 unsigned int getNumVar() const; 00092 00093 void setConst(string name, double value); 00094 double getConst(string name) const; 00095 00096 void setIndependent(string index); 00097 string getIndependent() const; 00098 00099 vector < double > getY() const; 00100 00101 double getDerivative() const; 00102 00103 Function& operator=(const Function rhs); 00104 00105 unsigned int addVar(); 00106 /* void dropVar(unsigned int msgLookup); */ 00107 00108 void process(const Eref& e, ProcPtr p); 00109 void reinit(const Eref& e, ProcPtr p); 00110 00111 static const Cinfo * initCinfo(); 00112 00113 protected: 00114 friend double * _functionAddVar(const char * name, void *data); 00115 mutable bool _valid; 00116 unsigned int _numVar; 00117 double _lastValue; 00118 double _value; 00119 double _rate; 00120 unsigned int _mode; 00121 // this stores variables received via incoming messages, identifiers of the form x{i} are included in this 00122 vector<Variable *> _varbuf; 00123 // this stores variable values pulled by sending request. identifiers of the form y{i} are included in this 00124 vector< double * > _pullbuf; 00125 map< string, double *> _constbuf; // for constants 00126 string _independent; // index of independent variable 00127 mu::Parser _parser; 00128 void _clearBuffer(); 00129 void _showError(mu::Parser::exception_type &e) const; 00130 char* _stoich; // Used by kinetic solvers when this is zombified. 00131 }; 00132 00133 00134 #endif 00135 00136 00137 // 00138 // Function.h ends here