MOOSE - Multiscale Object Oriented Simulation Environment
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
Func.h
Go to the documentation of this file.
1 /* Func.h ---
2  *
3  * Filename: Func.h
4  * Description: A simple function parser and evaluator class for MOOSE.
5  * Author: Subhasis Ray
6  * Maintainer:
7  * Created: Sat May 25 16:14:13 2013 (+0530)
8  * Version:
9  * Last-Updated: Sat Jun 1 19:04:31 2013 (+0530)
10  * By: subha
11  * Update #: 117
12  * URL:
13  * Keywords:
14  * Compatibility:
15  *
16  */
17 
18 /* Commentary:
19  *
20  *
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 /* Code: */
46 
47 #ifndef _FUNC_H
48 #define _FUNC_H
49 
50 #include "muParser.h"
56 static double *_addVar(const char *name, void *data);
57 
58 class Func
59 {
60  public:
61  static const int VARMAX;
62  Func();
63  Func(const Func& rhs);
64  ~Func();
65  void setExpr(string expr);
66  string getExpr() const;
67 
68 
69  // get a list of variable identifiers.
70  // this is created by the parser
71  vector<string> getVars() const;
72  void setVarValues(vector< string > vars, vector < double > vals);
73 
74 
75  // get/set the value of variable `name`
76  void setVar(string name, double value);
77  double getVar(string name) const;
78 
79  // get function eval result
80  double getValue() const;
81 
82  // get/set operation mode
83  void setMode(unsigned int mode);
84  unsigned int getMode() const;
85 
86  void setX(double value);
87  double getX() const;
88 
89  void setY(double value);
90  double getY() const;
91 
92  void setZ(double value);
93  double getZ() const;
94 
95  void setXY(double x, double y);
96  void setXYZ(double x, double y, double z);
97 
98  double getDerivative() const;
99 
100  Func& operator=(const Func rhs);
101 
102  void process(const Eref& e, ProcPtr p);
103  void reinit(const Eref& e, ProcPtr p);
104 
105  static const Cinfo * initCinfo();
106 
107 protected:
108  friend double * _addVar(const char * name, void *data);
109  vector< double *> _varbuf;
110  mu::Parser _parser;
111  double *_x, *_y, *_z;
112  unsigned int _mode;
113  mutable bool _valid;
114  void _clearBuffer();
115  void _showError(mu::Parser::exception_type &e) const;
116 };
117 #endif
118 
119 
120 
121 /* Func.h ends here */
void setVarValues(vector< string > vars, vector< double > vals)
Definition: Func.cpp:647
static const int VARMAX
Definition: Func.h:61
uint32_t value
Definition: moosemodule.h:42
void setVar(string name, double value)
Definition: Func.cpp:432
void setY(double value)
Definition: Func.cpp:509
double * _x
Definition: Func.h:111
static const Cinfo * initCinfo()
Definition: Func.cpp:67
double * _y
Definition: Func.h:111
void _clearBuffer()
Definition: Func.cpp:334
bool _valid
Definition: Func.h:113
static double * _addVar(const char *name, void *data)
Definition: Func.cpp:356
vector< string > getVars() const
Definition: Func.cpp:622
void setX(double value)
Definition: Func.cpp:492
void setXYZ(double x, double y, double z)
Definition: Func.cpp:554
double getZ() const
Definition: Func.cpp:533
double getVar(string name) const
Definition: Func.cpp:464
void reinit(const Eref &e, ProcPtr p)
Definition: Func.cpp:681
double getX() const
Definition: Func.cpp:500
Func()
Definition: Func.cpp:288
double * _z
Definition: Func.h:111
double getValue() const
Definition: Func.cpp:580
void setXY(double x, double y)
Definition: Func.cpp:542
void setZ(double value)
Definition: Func.cpp:525
~Func()
Definition: Func.cpp:328
Definition: Eref.h:26
Definition: Func.h:58
friend double * _addVar(const char *name, void *data)
Definition: Func.cpp:356
void setMode(unsigned int mode)
Definition: Func.cpp:570
mu::Parser _parser
Definition: Func.h:110
static char name[]
Definition: mfield.cpp:401
double getDerivative() const
Definition: Func.cpp:599
unsigned int _mode
Definition: Func.h:112
void process(const Eref &e, ProcPtr p)
Definition: Func.cpp:665
double getY() const
Definition: Func.cpp:517
string getExpr() const
Definition: Func.cpp:419
void setExpr(string expr)
Definition: Func.cpp:365
void _showError(mu::Parser::exception_type &e) const
Definition: Func.cpp:344
Definition: Cinfo.h:18
vector< double * > _varbuf
Definition: Func.h:109
unsigned int getMode() const
Definition: Func.cpp:575
Func & operator=(const Func rhs)
Definition: Func.cpp:312