libMesh::ParsedFunction< Output > Class Template Reference
#include <parsed_function.h>

Public Member Functions | |
| ParsedFunction (const std::string &expression, const std::vector< std::string > *additional_vars=NULL, const std::vector< Output > *initial_vals=NULL) | |
| virtual Output | operator() (const Point &p, const Real time=0) |
| virtual void | operator() (const Point &p, const Real time, DenseVector< Output > &output) |
| virtual Output | component (unsigned int i, const Point &p, Real time) |
| virtual Output & | getVarAddress (const std::string &variable_name) |
| virtual AutoPtr< FunctionBase < Output > > | clone () const |
| ParsedFunction (std::string) | |
| virtual Output | operator() (const Point &, const Real=0) |
| virtual void | operator() (const Point &, const Real, DenseVector< Output > &) |
| virtual void | init () |
| virtual void | clear () |
| virtual Output & | getVarAddress (const std::string &) |
| virtual AutoPtr< FunctionBase < Output > > | clone () const |
| void | operator() (const Point &p, DenseVector< Output > &output) |
| bool | initialized () const |
Protected Attributes | |
| const FunctionBase * | _master |
| bool | _initialized |
Private Attributes | |
| std::string | _expression |
| std::vector < FunctionParserBase< Output > > | parsers |
| std::vector< Output > | _spacetime |
| std::vector< std::string > | _additional_vars |
| std::vector< Output > | _initial_vals |
| Output | _dummy |
Detailed Description
template<typename Output = Number>
class libMesh::ParsedFunction< Output >
Definition at line 43 of file parsed_function.h.
Constructor & Destructor Documentation
| libMesh::ParsedFunction< Output >::ParsedFunction | ( | const std::string & | expression, | |
| const std::vector< std::string > * | additional_vars = NULL, |
|||
| const std::vector< Output > * | initial_vals = NULL | |||
| ) | [inline, explicit] |
Definition at line 47 of file parsed_function.h.
References libMesh::ParsedFunction< Output >::_additional_vars, libMesh::ParsedFunction< Output >::_initial_vals, libMesh::FunctionBase< Output >::_initialized, libMesh::ParsedFunction< Output >::_spacetime, end, libMesh::ParsedFunction< Output >::parsers, and libMesh::Real.
Referenced by libMesh::ParsedFunction< Output >::clone().
00049 : _expression(expression) 00050 // Size the spacetime vector to account for space, time, and any additional 00051 // variables passed 00052 //_spacetime(LIBMESH_DIM+1 + (additional_vars ? additional_vars->size() : 0)), 00053 { 00054 std::string variables = "x"; 00055 #if LIBMESH_DIM > 1 00056 variables += ",y"; 00057 #endif 00058 #if LIBMESH_DIM > 2 00059 variables += ",z"; 00060 #endif 00061 variables += ",t"; 00062 00063 _spacetime.resize(LIBMESH_DIM+1 + (additional_vars ? additional_vars->size() : 0)); 00064 00065 // If additional vars were passed, append them to the string 00066 // that we send to the function parser. Also add them to the 00067 // end of our spacetime vector 00068 if (additional_vars) 00069 { 00070 if (initial_vals) 00071 std::copy(initial_vals->begin(), initial_vals->end(), std::back_inserter(_initial_vals)); 00072 00073 std::copy(additional_vars->begin(), additional_vars->end(), std::back_inserter(_additional_vars)); 00074 00075 for (unsigned int i=0; i < additional_vars->size(); ++i) 00076 { 00077 variables += "," + (*additional_vars)[i]; 00078 // Initialize extra variables to the vector passed in or zero 00079 // Note: The initial_vals vector can be shorter than the additional_vars vector 00080 _spacetime[LIBMESH_DIM+1 + i] = (initial_vals && i < initial_vals->size()) ? (*initial_vals)[i] : 0; 00081 } 00082 } 00083 00084 size_t nextstart = 0, end = 0; 00085 00086 while (end != std::string::npos) 00087 { 00088 // If we're past the end of the string, we can't make any more 00089 // subparsers 00090 if (nextstart >= expression.size()) 00091 break; 00092 00093 // If we're at the start of a brace delimited section, then we 00094 // parse just that section: 00095 if (expression[nextstart] == '{') 00096 { 00097 nextstart++; 00098 end = expression.find('}', nextstart); 00099 } 00100 // otherwise we parse the whole thing 00101 else 00102 end = std::string::npos; 00103 00104 // We either want the whole end of the string (end == npos) or 00105 // a substring in the middle. 00106 std::string subexpression = 00107 expression.substr(nextstart, (end == std::string::npos) ? 00108 std::string::npos : end - nextstart); 00109 00110 // fparser can crash on empty expressions 00111 libmesh_assert(!subexpression.empty()); 00112 00113 // Parse (and optimize if possible) the subexpression. 00114 // Add some basic constants, to Real precision. 00115 FunctionParserBase<Output> fp; 00116 fp.AddConstant("pi", std::acos(Real(-1))); 00117 fp.AddConstant("e", std::exp(Real(1))); 00118 fp.Parse(subexpression, variables); 00119 fp.Optimize(); 00120 parsers.push_back(fp); 00121 00122 // If at end, use nextstart=maxSize. Else start at next 00123 // character. 00124 nextstart = (end == std::string::npos) ? 00125 std::string::npos : end + 1; 00126 } 00127 00128 this->_initialized = true; 00129 }
| libMesh::ParsedFunction< Output >::ParsedFunction | ( | std::string | ) | [inline] |
Definition at line 243 of file parsed_function.h.
00243 : _dummy(0) 00244 { 00245 libmesh_not_implemented(); 00246 }
Member Function Documentation
| virtual void libMesh::ParsedFunction< Output >::clear | ( | ) | [inline, virtual] |
Clears the function.
Reimplemented from libMesh::FunctionBase< Output >.
Definition at line 257 of file parsed_function.h.
| virtual AutoPtr<FunctionBase<Output> > libMesh::ParsedFunction< Output >::clone | ( | ) | const [inline, virtual] |
Returns a new copy of the function. The new copy should be as ``deep'' as necessary to allow independent destruction and simultaneous evaluations of the copies in different threads.
Implements libMesh::FunctionBase< Output >.
Definition at line 259 of file parsed_function.h.
| virtual AutoPtr<FunctionBase<Output> > libMesh::ParsedFunction< Output >::clone | ( | ) | const [inline, virtual] |
Returns a new copy of the function. The new copy should be as ``deep'' as necessary to allow independent destruction and simultaneous evaluations of the copies in different threads.
Implements libMesh::FunctionBase< Output >.
Definition at line 214 of file parsed_function.h.
References libMesh::ParsedFunction< Output >::_additional_vars, libMesh::ParsedFunction< Output >::_expression, libMesh::ParsedFunction< Output >::_initial_vals, and libMesh::ParsedFunction< Output >::ParsedFunction().
00214 { 00215 return AutoPtr<FunctionBase<Output> > 00216 (new ParsedFunction(_expression, &_additional_vars, &_initial_vals)); 00217 }
| virtual Output libMesh::ParsedFunction< Output >::component | ( | unsigned int | i, | |
| const Point & | p, | |||
| Real | time | |||
| ) | [inline, virtual] |
- Returns:
- the vector component
iat coordinatepand timetime.
Reimplemented from libMesh::FunctionBase< Output >.
Definition at line 175 of file parsed_function.h.
References libMesh::ParsedFunction< Output >::_spacetime, and libMesh::ParsedFunction< Output >::parsers.
00178 { 00179 _spacetime[0] = p(0); 00180 #if LIBMESH_DIM > 1 00181 _spacetime[1] = p(1); 00182 #endif 00183 #if LIBMESH_DIM > 2 00184 _spacetime[2] = p(2); 00185 #endif 00186 _spacetime[LIBMESH_DIM] = time; 00187 00188 libmesh_assert_less (i, parsers.size()); 00189 00190 // The remaining locations in _spacetime are currently fixed at construction 00191 // but could potentially be made dynamic 00192 return parsers[i].Eval(&_spacetime[0]); 00193 }
| virtual Output& libMesh::ParsedFunction< Output >::getVarAddress | ( | const std::string & | ) | [inline, virtual] |
Definition at line 258 of file parsed_function.h.
References libMesh::ParsedFunction< Output >::_dummy.
00258 { return _dummy; }
| virtual Output& libMesh::ParsedFunction< Output >::getVarAddress | ( | const std::string & | variable_name | ) | [inline, virtual] |
- Returns:
- the address of a parsed variable so you can supply a parameterized value
Definition at line 198 of file parsed_function.h.
References libMesh::ParsedFunction< Output >::_additional_vars, and libMesh::ParsedFunction< Output >::_spacetime.
00199 { 00200 const std::vector<std::string>::iterator it = 00201 std::find(_additional_vars.begin(), _additional_vars.end(), variable_name); 00202 00203 if (it == _additional_vars.end()) 00204 { 00205 std::cerr << "ERROR: Requested variable not found in parsed function\n" << std::endl; 00206 libmesh_error(); 00207 } 00208 00209 // Iterator Arithmetic (How far from the end of the array is our target address?) 00210 return _spacetime[_spacetime.size() - (_additional_vars.end() - it)]; 00211 }
| virtual void libMesh::ParsedFunction< Output >::init | ( | ) | [inline, virtual] |
The actual initialization process.
Reimplemented from libMesh::FunctionBase< Output >.
Definition at line 256 of file parsed_function.h.
| bool libMesh::FunctionBase< Output >::initialized | ( | ) | const [inline, inherited] |
- Returns:
truewhen this object is properly initialized and ready for use,falseotherwise.
Definition at line 194 of file function_base.h.
References libMesh::FunctionBase< Output >::_initialized.
Referenced by libMesh::AnalyticFunction< Output >::operator()().
00195 { 00196 return (this->_initialized); 00197 }
| void libMesh::FunctionBase< Output >::operator() | ( | const Point & | p, | |
| DenseVector< Output > & | output | |||
| ) | [inline, inherited] |
Return function for vectors. Returns in output the values of the data at the coordinate p.
Definition at line 216 of file function_base.h.
References libMesh::FunctionBase< Output >::operator()().
00218 { 00219 // Call the time-dependent function with t=0. 00220 this->operator()(p, 0., output); 00221 }
| virtual void libMesh::ParsedFunction< Output >::operator() | ( | const Point & | p, | |
| const | time, | |||
| DenseVector< Output > & | output | |||
| ) | [inline, virtual] |
Return function for vectors. Returns in output the values of the data at the coordinate p and for time time. Purely virtual, so you have to overload it. Note that this cannot be a const method, check MeshFunction.
Implements libMesh::FunctionBase< Output >.
Definition at line 252 of file parsed_function.h.
| virtual Output libMesh::ParsedFunction< Output >::operator() | ( | const Point & | p, | |
| const | time = 0 | |||
| ) | [inline, virtual] |
- Returns:
- the scalar value at coordinate
pand timetime, which defaults to zero. Purely virtual, so you have to overload it. Note that this cannot be a const method, checkMeshFunction.
Implements libMesh::FunctionBase< Output >.
Definition at line 248 of file parsed_function.h.
| virtual void libMesh::ParsedFunction< Output >::operator() | ( | const Point & | p, | |
| const Real | time, | |||
| DenseVector< Output > & | output | |||
| ) | [inline, virtual] |
Return function for vectors. Returns in output the values of the data at the coordinate p and for time time. Purely virtual, so you have to overload it. Note that this cannot be a const method, check MeshFunction.
Implements libMesh::FunctionBase< Output >.
Definition at line 148 of file parsed_function.h.
References libMesh::ParsedFunction< Output >::_spacetime, libMesh::ParsedFunction< Output >::parsers, and libMesh::DenseVector< T >::size().
00151 { 00152 _spacetime[0] = p(0); 00153 #if LIBMESH_DIM > 1 00154 _spacetime[1] = p(1); 00155 #endif 00156 #if LIBMESH_DIM > 2 00157 _spacetime[2] = p(2); 00158 #endif 00159 _spacetime[LIBMESH_DIM] = time; 00160 00161 unsigned int size = output.size(); 00162 00163 libmesh_assert_equal_to (size, parsers.size()); 00164 00165 // The remaining locations in _spacetime are currently fixed at construction 00166 // but could potentially be made dynamic 00167 for (unsigned int i=0; i != size; ++i) 00168 output(i) = parsers[i].Eval(&_spacetime[0]); 00169 }
| virtual Output libMesh::ParsedFunction< Output >::operator() | ( | const Point & | p, | |
| const Real | time = 0 | |||
| ) | [inline, virtual] |
- Returns:
- the scalar value at coordinate
pand timetime, which defaults to zero. Purely virtual, so you have to overload it. Note that this cannot be a const method, checkMeshFunction.
Implements libMesh::FunctionBase< Output >.
Definition at line 131 of file parsed_function.h.
References libMesh::ParsedFunction< Output >::_spacetime, and libMesh::ParsedFunction< Output >::parsers.
00133 { 00134 _spacetime[0] = p(0); 00135 #if LIBMESH_DIM > 1 00136 _spacetime[1] = p(1); 00137 #endif 00138 #if LIBMESH_DIM > 2 00139 _spacetime[2] = p(2); 00140 #endif 00141 _spacetime[LIBMESH_DIM] = time; 00142 00143 // The remaining locations in _spacetime are currently fixed at construction 00144 // but could potentially be made dynamic 00145 return parsers[0].Eval(&_spacetime[0]); 00146 }
Member Data Documentation
std::vector<std::string> libMesh::ParsedFunction< Output >::_additional_vars [private] |
Definition at line 225 of file parsed_function.h.
Referenced by libMesh::ParsedFunction< Output >::clone(), libMesh::ParsedFunction< Output >::getVarAddress(), and libMesh::ParsedFunction< Output >::ParsedFunction().
Output libMesh::ParsedFunction< Output >::_dummy [private] |
Definition at line 264 of file parsed_function.h.
Referenced by libMesh::ParsedFunction< Output >::getVarAddress().
std::string libMesh::ParsedFunction< Output >::_expression [private] |
Definition at line 220 of file parsed_function.h.
Referenced by libMesh::ParsedFunction< Output >::clone().
std::vector<Output> libMesh::ParsedFunction< Output >::_initial_vals [private] |
Definition at line 226 of file parsed_function.h.
Referenced by libMesh::ParsedFunction< Output >::clone(), and libMesh::ParsedFunction< Output >::ParsedFunction().
bool libMesh::FunctionBase< Output >::_initialized [protected, inherited] |
When init() was called so that everything is ready for calls to operator() (...), then this bool is true.
Definition at line 166 of file function_base.h.
Referenced by libMesh::AnalyticFunction< Output >::AnalyticFunction(), libMesh::AnalyticFunction< Output >::clear(), libMesh::ConstFunction< Output >::ConstFunction(), libMesh::AnalyticFunction< Output >::init(), libMesh::FunctionBase< Output >::initialized(), libMesh::ParsedFunction< Output >::ParsedFunction(), and libMesh::WrappedFunction< Output >::WrappedFunction().
const FunctionBase* libMesh::FunctionBase< Output >::_master [protected, inherited] |
Const pointer to our master, initialized to NULL. There may be cases where multiple functions are required, but to save memory, one master handles some centralized data.
Definition at line 160 of file function_base.h.
std::vector<Output> libMesh::ParsedFunction< Output >::_spacetime [private] |
Definition at line 222 of file parsed_function.h.
Referenced by libMesh::ParsedFunction< Output >::component(), libMesh::ParsedFunction< Output >::getVarAddress(), libMesh::ParsedFunction< Output >::operator()(), and libMesh::ParsedFunction< Output >::ParsedFunction().
std::vector<FunctionParserBase<Output> > libMesh::ParsedFunction< Output >::parsers [private] |
Definition at line 221 of file parsed_function.h.
Referenced by libMesh::ParsedFunction< Output >::component(), libMesh::ParsedFunction< Output >::operator()(), and libMesh::ParsedFunction< Output >::ParsedFunction().
The documentation for this class was generated from the following file:
Site Created By: libMesh Developers
Last modified: February 05 2013 19:55:32 UTC
Hosted By: