#include <NFfunction.hh>
Built from the muParser freeware package, this factory creates Parser objects that can be used to evaluate arbitrary functions. The function to evaluate is given as a string (which can contain the given functions or constants below, case sensitive) along with pointers to particular varables that exist. The Parser, when initialized, translates the string into bytecode that can be evaluated fast. At runtime, the bytecode that was created can be evaluated and every time it is evaluated, it uses the current value of the given pointers to variables. Thus, NFsim can use functions of arbitrary complexity for defining reaction rates and parameters.
Supported functions:
name   | n_args   | description |
sin | 1 | sine function (arg is in radians) |
cos | 1 | cosine function |
tan | 1 | tangens function |
asin | 1 | arcus sine function |
acos | 1 | arcus cosine function |
atan | 1 | arcus tangens function |
sinh | 1 | hyperbolic sine function |
cosh | 1 | hyperbolic cosine |
tanh | 1 | hyperbolic tangens function |
asinh | 1 | hyperbolic arcus sine function |
acosh | 1 | hyperbolic arcus tangens function |
atanh | 1 | hyperbolic arcur tangens function |
log2 | 1 | logarithm to the base 2 |
log10 | 1 | logarithm to the base 10 |
log | 1 | logarithm to the base 10 |
ln | 1 | logarithm to base e (2.71828...) |
exp | 1 | e raised to the power of x |
sqrt | 1 | square root of a value |
sign | 1 | sign function -1 if x<0; 1 if x>0 |
rint | 1 | round to nearest integer |
abs | 1 | absolute value |
if | 3 | if ... then ... else ... |
min | var. | min of all arguments |
max | var. | max of all arguments |
sum | var. | sum of all arguments |
avg | var. | mean value of all arguments |
Supported constants (to a precision of at least 10^-8):
name   | value   | description |
_PI | 3.141... | you all know pi, right? |
_e | 2.718... | the base of natural logs |
_Na | 6.022...e23 | Avogadro's number |
For muParser documentation, see: http://muparser.sourceforge.net/
Static Public Member Functions | |
static mu::Parser * | create (string function, vector< string > &variableNames, vector< double * > &variablePtrs) |
static mu::Parser * | create () |
static double | Eval (mu::Parser *p) |
static void | test () |
Parser * FuncFactory::create | ( | string | function, | |
vector< string > & | variableNames, | |||
vector< double * > & | variablePtrs | |||
) | [static] |
Use this function to create a new function parser that can operate on the given variables. The vectors should contain (in the same order) the variable names and pointers to the actual variable values. Do not use local variables or variables that will be forgotten before the Parser is destroyed. To evaluate functions, you can either just call the Eval() function of the Parser object (as in p->Eval()), or, call the Eval function of FuncFactory to do error checking (as in FuncFactory::Eval(p)).
Parser * FuncFactory::create | ( | ) | [static] |
Creates a function without any variables and without any functions defined. You will have to do that yourself. But, this does add in any predefined constants we want, and that is why this function exists.
double FuncFactory::Eval | ( | mu::Parser * | p | ) | [static] |
Evaluates the given Parser object safely, meaning exceptions and errors are caught and program execution is terminated - if you have to do better than simple program termination, well than you can catch your own errors (see the muParser documenation).
void FuncFactory::test | ( | ) | [static] |
Runs a couple tests of the FuncFactory and the muParser functions to make sure everything is working as promised. (To run this, use the arguements '-test mathFuncParser')