MOOSE - Multiscale Object Oriented Simulation Environment
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
Function.cpp File Reference
#include "header.h"
#include "../utility/utility.h"
#include "../utility/numutil.h"
#include "Variable.h"
#include "Function.h"
#include "ElementValueFinfo.h"
+ Include dependency graph for Function.cpp:

Go to the source code of this file.

Macros

#define PARSER_MAXVARS   100
 

Functions

double * _functionAddVar (const char *name, void *data)
 
static SrcFinfo1< double > * derivativeOut ()
 
static SrcFinfo1< double > * rateOut ()
 
static SrcFinfo1< vector
< double > * > * 
requestOut ()
 
static SrcFinfo1< double > * valueOut ()
 

Variables

static const CinfofunctionCinfo = Function::initCinfo()
 
static const double TriggerThreshold = 0.0
 

Macro Definition Documentation

#define PARSER_MAXVARS   100

Definition at line 56 of file Function.cpp.

Function Documentation

double* _functionAddVar ( const char *  name,
void *  data 
)

Call-back to add variables to parser automatically.

We use different storage for constants and variables. Variables are stored in a vector of Variable object pointers. They must have the name x{index} where index is any non-negative integer. Note that the vector is resized to whatever the maximum index is. It is up to the user to make sure that indices are sequential without any gap. In case there is a gap in indices, those entries will remain unused.

If the name starts with anything other than x or y, then it is taken to be a named constant, which must be set before any expression or variables and error is thrown.

NOTE: this is called not on setting expression but on first attempt at evaluation of the same, i.e. when you access value of the Function object.

Definition at line 482 of file Function.cpp.

483 {
484  Function* function = reinterpret_cast< Function * >(data);
485  double * ret = NULL;
486  string strname(name);
487  // Names starting with x are variables, everything else is constant.
488  if (strname[0] == 'x'){
489  int index = atoi(strname.substr(1).c_str());
490  if ((unsigned)index >= function->_varbuf.size()){
491  function->_varbuf.resize(index+1, 0);
492  for (int ii = 0; ii <= index; ++ii){
493  if (function->_varbuf[ii] == 0){
494  function->_varbuf[ii] = new Variable();
495  }
496  }
497  function->_numVar = function->_varbuf.size();
498  }
499  ret = &(function->_varbuf[index]->value);
500  } else if (strname[0] == 'y'){
501  int index = atoi(strname.substr(1).c_str());
502  if ((unsigned)index >= function->_pullbuf.size()){
503  function->_pullbuf.resize(index+1, 0 );
504  for (int ii = 0; ii <= index; ++ii){
505  if (function->_pullbuf[ii] == 0){
506  function->_pullbuf[ii] = new double();
507  }
508  }
509  }
510  ret = function->_pullbuf[index];
511  } else if (strname == "t"){
512  ret = &function->_t;
513  } else {
514  cerr << "Got an undefined symbol: " << name << endl
515  << "Variables must be named xi, yi, where i is integer index."
516  << " You must define the constants beforehand using LookupField c: c[name]"
517  " = value"
518  << endl;
519  throw mu::ParserError("Undefined constant.");
520  }
521 
522  return ret;
523 }
static char name[]
Definition: mfield.cpp:401
static SrcFinfo1< double >* derivativeOut ( )
static

Definition at line 68 of file Function.cpp.

Referenced by Function::initCinfo(), Function::process(), and Function::reinit().

69 {
70  static SrcFinfo1< double > derivativeOut("derivativeOut",
71  "Value of derivative of the function for the current variable values");
72  return &derivativeOut;
73 }
static SrcFinfo1< double > * derivativeOut()
Definition: Function.cpp:68

+ Here is the caller graph for this function:

static SrcFinfo1< double >* rateOut ( )
static

Definition at line 75 of file Function.cpp.

Referenced by Function::initCinfo(), Function::process(), and Function::reinit().

76 {
77  static SrcFinfo1< double > rateOut("rateOut",
78  "Value of time-derivative of the function for the current variable values");
79  return &rateOut;
80 }
static SrcFinfo1< double > * rateOut()
Definition: Function.cpp:75

+ Here is the caller graph for this function:

static SrcFinfo1< vector < double > *>* requestOut ( )
static

Definition at line 82 of file Function.cpp.

Referenced by Function::initCinfo(), and Function::process().

83 {
85  "requestOut",
86  "Sends request for input variable from a field on target object");
87  return &requestOut;
88 
89 }
static SrcFinfo1< vector< double > * > * requestOut()
Definition: Function.cpp:82

+ Here is the caller graph for this function:

static SrcFinfo1<double>* valueOut ( )
static

Definition at line 61 of file Function.cpp.

Referenced by Function::initCinfo(), Function::process(), and Function::reinit().

62 {
63  static SrcFinfo1<double> valueOut("valueOut",
64  "Evaluated value of the function for the current variable values.");
65  return &valueOut;
66 }
static SrcFinfo1< double > * valueOut()
Definition: Function.cpp:61

+ Here is the caller graph for this function:

Variable Documentation

const Cinfo* functionCinfo = Function::initCinfo()
static
const double TriggerThreshold = 0.0
static

Definition at line 59 of file Function.cpp.

Referenced by Function::process().