Func

class Func

Func: general purpose function calculator using real numbers. It can parse mathematical expression defining a function and evaluate it and/or its derivative for specified variable values. The variables can be input from other moose objects. In case of arbitrary variable names, the source message must have the variable name as the first argument. For most common cases, input messages to set x, y, z and xy, xyz are made available without such requirement. This class handles only real numbers (C-double). Predefined constants are: pi=3.141592..., e=2.718281...

proc

void (shared message field) This is a shared message to receive Process messages from the scheduler objects.The first entry in the shared msg is a MsgDest for the Process operation. It has a single argument, ProcInfo, which holds lots of information about current time, thread, dt and so on. The second entry is a MsgDest for the Reinit operation. It also uses ProcInfo.

getValue()

(destination message field) Requests field value. The requesting Element must provide a handler for the returned value.

getDerivative()

(destination message field) Requests field value. The requesting Element must provide a handler for the returned value.

setMode()

(destination message field) Assigns field value.

getMode()

(destination message field) Requests field value. The requesting Element must provide a handler for the returned value.

setExpr()

(destination message field) Assigns field value.

getExpr()

(destination message field) Requests field value. The requesting Element must provide a handler for the returned value.

setVar()

(destination message field) Assigns field value.

getVar()

(destination message field) Requests field value. The requesting Element must provide a handler for the returned value.

getVars()

(destination message field) Requests field value. The requesting Element must provide a handler for the returned value.

setX()

(destination message field) Assigns field value.

getX()

(destination message field) Requests field value. The requesting Element must provide a handler for the returned value.

setY()

(destination message field) Assigns field value.

getY()

(destination message field) Requests field value. The requesting Element must provide a handler for the returned value.

setZ()

(destination message field) Assigns field value.

getZ()

(destination message field) Requests field value. The requesting Element must provide a handler for the returned value.

varIn()

(destination message field) Handle value for specified variable coming from other objects

xIn()

(destination message field) Handle value for variable named x. This is a shorthand. If the expression does not have any variable named x, this the first variable in the sequence vars.

yIn()
(destination message field) Handle value for variable named y. This is a utility for two/three
variable functions where the y value comes from a source separate from that of x. This is a shorthand. If the

expression does not have any variable named y, this the second variable in the sequence vars.

zIn()
(destination message field) Handle value for variable named z. This is a utility for three
variable functions where the z value comes from a source separate from that of x or y. This is a shorthand. If the expression does not have any variable named y, this the second variable in the sequence vars.
xyIn()

(destination message field) Handle value for variables x and y for two-variable function

xyzIn()

(destination message field) Handle value for variables x, y and z for three-variable function

process()

(destination message field) Handles process call, updates internal time stamp.

reinit()

(destination message field) Handles reinit call.

valueOut

double (source message field) Evaluated value of the function for the current variable values.

derivativeOut

double (source message field) Value of derivative of the function for the current variable values

value

double (value field) Result of the function evaluation with current variable values.

derivative

double (value field) Derivative of the function at given variable values.

mode
unsigned int (value field) Mode of operation:
1: only the function value will be calculated 2: only the derivative will be calculated 3: both function value and derivative at current variable values will be calculated.
expr

string (value field) Mathematical expression defining the function. The underlying parser is muParser. In addition to the available functions and operators from muParser, some more functions are added.

Functions Name args explanation sin 1 sine function 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 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 rand 1 rand(seed), random float between 0 and 1,

if seed = -1, then a 'random' seed is created.
rand2 3 rand(a, b, seed), random float between a and b,
if seed = -1, a 'random' seed is created using either by random_device or by reading system clock

Operators Op meaning prioroty = assignement -1 && logical and 1 || logical or 2 <= less or equal 4 >= greater or equal 4 != not equal 4 == equal 4 > greater than 4 < less than 4 + addition 5 - subtraction 5 * multiplication 6 / division 6 ^ raise x to the power of y 7

?: if then else operator C++ style syntax

vars

vector<string> (value field) Variable names in the expression

x

double (value field) Value for variable named x. This is a shorthand. If the expression does not have any variable named x, this the first variable in the sequence vars.

y
double (value field) Value for variable named y. This is a utility for two/three
variable functions where the y value comes from a source separate from that of x. This is a shorthand. If the

expression does not have any variable named y, this the second variable in the sequence vars.

z
double (value field) Value for variable named z. This is a utility for three
variable functions where the z value comes from a source separate from that of x or z. This is a shorthand. If the expression does not have any variable named z, this the third variable in the sequence vars.
var

string,double (lookup field) Lookup table for variable values.