MOOSE - Multiscale Object Oriented Simulation Environment
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
Function.h
Go to the documentation of this file.
1 // Function.h ---
2 //
3 // Filename: Function.h
4 // Description:
5 // Author: Subhasis Ray
6 // Maintainer:
7 // Created: Fri May 30 19:34:13 2014 (+0530)
8 // Version:
9 // Last-Updated:
10 // By:
11 // Update #: 0
12 // URL:
13 // Keywords:
14 // Compatibility:
15 //
16 //
17 
18 // Commentary:
19 //
20 // A new version of Func with FieldElements to collect data.
21 //
22 //
23 
24 // Change log:
25 //
26 //
27 //
28 //
29 // This program is free software; you can redistribute it and/or
30 // modify it under the terms of the GNU General Public License as
31 // published by the Free Software Foundation; either version 3, or
32 // (at your option) any later version.
33 //
34 // This program is distributed in the hope that it will be useful,
35 // but WITHOUT ANY WARRANTY; without even the implied warranty of
36 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
37 // General Public License for more details.
38 //
39 // You should have received a copy of the GNU General Public License
40 // along with this program; see the file COPYING. If not, write to
41 // the Free Software Foundation, Inc., 51 Franklin Street, Fifth
42 // Floor, Boston, MA 02110-1301, USA.
43 //
44 //
45 
46 // Code:
47 
48 #ifndef _MOOSE_FUNCTION_H_
49 #define _MOOSE_FUNCTION_H_
50 
51 #include "muParser.h"
52 
58 double *_functionAddVar(const char *name, void *data);
59 
60 class Function
61 {
62  public:
63  static const int VARMAX;
64  Function();
65  Function(const Function& rhs);
66  ~Function();
67  virtual void innerSetExpr( const Eref& e, string expr);
68  void setExpr( const Eref& e, string expr);
69  string getExpr( const Eref& e ) const;
70 
71 
72  // get a list of variable identifiers.
73  // this is created by the parser
74  vector<string> getVars() const;
75  void setVarValues(vector< string > vars, vector < double > vals);
76 
77 
78  // get/set the value of variable `name`
79  void setVar(unsigned int index, double value);
80  Variable * getVar(unsigned int ii);
81 
82  // get function eval result
83  double getValue() const;
84 
85  double getRate() const;
86 
87  // get/set operation mode
88  void setMode(unsigned int mode);
89  unsigned int getMode() const;
90 
91  // set/get flag to use trigger mode.
92  void setUseTrigger(bool useTrigger);
93  bool getUseTrigger() const;
94 
95  // set/get flag to do function evaluation at reinit
96  void setDoEvalAtReinit(bool doEvalAtReinit);
97  bool getDoEvalAtReinit() const;
98 
99  void setNumVar(unsigned int num);
100  unsigned int getNumVar() const;
101 
102  void setConst(string name, double value);
103  double getConst(string name) const;
104 
105  void setIndependent(string index);
106  string getIndependent() const;
107 
108  vector < double > getY() const;
109 
110  double getDerivative() const;
111 
112 #if 0
113 
117  void extendMuParser( void );
118 
127  static mu::value_type muCallbackFMod( mu::value_type a, mu::value_type b );
128 #endif
129 
130  Function& operator=(const Function rhs);
131 
132  unsigned int addVar();
133  /* void dropVar(unsigned int msgLookup); */
134 
135  void process(const Eref& e, ProcPtr p);
136  void reinit(const Eref& e, ProcPtr p);
137 
138  static const Cinfo * initCinfo();
139 
140 protected:
141  friend double * _functionAddVar(const char * name, void *data);
142  double _t; // local storage for current time
143  mutable bool _valid;
144  unsigned int _numVar;
145  double _lastValue;
146  double _value;
147  double _rate;
148  unsigned int _mode;
151  // this stores variables received via incoming messages, identifiers of the form x{i} are included in this
152  vector<Variable *> _varbuf;
153  // this stores variable values pulled by sending request. identifiers of the form y{i} are included in this
154  vector< double * > _pullbuf;
155  map< string, double *> _constbuf; // for constants
156  string _independent; // index of independent variable
157  mu::Parser _parser;
158  void _clearBuffer();
159  void _showError(mu::Parser::exception_type &e) const;
160  char* _stoich; // Used by kinetic solvers when this is zombified.
161 };
162 
163 
164 #endif
165 
166 
167 //
bool getDoEvalAtReinit() const
Definition: Function.cpp:621
string _independent
Definition: Function.h:156
uint32_t value
Definition: moosemodule.h:42
double * _functionAddVar(const char *name, void *data)
Definition: Function.cpp:482
virtual void innerSetExpr(const Eref &e, string expr)
Definition: Function.cpp:562
string getIndependent() const
Definition: Function.cpp:654
Function & operator=(const Function rhs)
Definition: Function.cpp:395
void setConst(string name, double value)
Definition: Function.cpp:724
char * _stoich
Definition: Function.h:160
double _lastValue
Definition: Function.h:145
unsigned int addVar()
Definition: Function.cpp:539
double value_type
friend double * _functionAddVar(const char *name, void *data)
Definition: Function.cpp:482
vector< double * > _pullbuf
Definition: Function.h:154
double getDerivative() const
Definition: Function.cpp:668
map< string, double * > _constbuf
Definition: Function.h:155
void setUseTrigger(bool useTrigger)
Definition: Function.cpp:606
void setVarValues(vector< string > vars, vector< double > vals)
double _value
Definition: Function.h:146
void setMode(unsigned int mode)
Definition: Function.cpp:596
vector< string > getVars() const
void _showError(mu::Parser::exception_type &e) const
Definition: Function.cpp:453
double getRate() const
Definition: Function.cpp:641
double getValue() const
Definition: Function.cpp:626
void setIndependent(string index)
Definition: Function.cpp:649
unsigned int getNumVar() const
Definition: Function.cpp:697
void setDoEvalAtReinit(bool doEvalAtReinit)
Definition: Function.cpp:616
void process(const Eref &e, ProcPtr p)
Definition: Function.cpp:741
vector< double > getY() const
Definition: Function.cpp:659
static const Cinfo * initCinfo()
Definition: Function.cpp:91
double _t
Definition: Function.h:142
unsigned int _numVar
Definition: Function.h:144
void _clearBuffer()
Definition: Function.cpp:435
bool _valid
Definition: Function.h:143
void setVar(unsigned int index, double value)
Definition: Function.cpp:702
string getExpr(const Eref &e) const
Definition: Function.cpp:587
vector< Variable * > _varbuf
Definition: Function.h:152
Definition: Eref.h:26
void setExpr(const Eref &e, string expr)
Definition: Function.cpp:556
bool _useTrigger
Definition: Function.h:149
unsigned int _mode
Definition: Function.h:148
static const int VARMAX
Definition: Function.h:63
static char name[]
Definition: mfield.cpp:401
bool _doEvalAtReinit
Definition: Function.h:150
void reinit(const Eref &e, ProcPtr p)
Definition: Function.cpp:783
mu::Parser _parser
Definition: Function.h:157
Variable * getVar(unsigned int ii)
Definition: Function.cpp:712
unsigned int getMode() const
Definition: Function.cpp:601
double getConst(string name) const
Definition: Function.cpp:729
double _rate
Definition: Function.h:147
Definition: Cinfo.h:18
bool getUseTrigger() const
Definition: Function.cpp:611
void setNumVar(unsigned int num)
Definition: Function.cpp:687