Go to the documentation of this file.
22 list.insert(list.end(), rargs.begin(), rargs.end());
37 if (term.
_root != NULL)
38 return os << *term.
_root;
40 return os <<
"[NULL]";
53 s <<
'[' << _id <<
']';
60 const char *
name[] = {
"sin",
"cos",
"tan",
"abs",
"log",
"log2",
"log10",
"exp",
"sinh",
"cosh"};
62 s <<
name[_type] <<
'(' << *_subnode <<
')';
69 const char *
name[] = {
"-",
"!"};
74 if (_subnode->precedence() > precedence())
75 s <<
'(' << *_subnode <<
')';
85 const char *
name[] = {
"min",
"max",
"atan2",
"hypot",
"plog"};
87 s <<
name[_type] <<
'(' << *_left <<
',' << *_right <<
')';
94 const char *
name[] = {
"+",
"-",
"*",
"/",
"%",
"^",
"<",
">",
"<=",
">=",
"=",
"!="};
97 if (_left->precedence() > precedence())
98 s <<
'(' << *_left <<
')';
106 if (_right->precedence() > precedence() ||
107 (_right->precedence() == precedence() &&
108 (_type == SUB || _type == DIV || _type == MOD || _type == POW)))
109 s <<
'(' << *_right <<
')';
140 mooseError(
"Unknown type.");
146 const char *
name[] = {
"if"};
147 std::ostringstream s;
148 s <<
name[_type] <<
'(' << *_left <<
',' << *_middle <<
',' << *_right <<
')';
155 this->_eval_arguments = {arg};
169 this->_arguments = this->_eval_arguments;
177 this->_arguments = this->_eval_arguments;
178 this->_term =
EBTerm(func);
184 unsigned int narg = _arguments.size();
185 if (narg != _eval_arguments.size())
186 mooseError(
"EBFunction is used wth a different number of arguments than it was defined with.");
193 for (
unsigned i = 0; i < narg; ++i)
197 result.substitute(rules);
200 for (
unsigned i = 0; i < narg; ++i)
206 ExpressionBuilder::EBFunction::operator std::string()
const
210 std::ostringstream s;
218 unsigned int narg = _arguments.size();
222 std::ostringstream s;
224 for (
unsigned int i = 1; i < narg; ++i)
225 s <<
',' << _arguments[i];
233 return _term.substitute(rule);
239 return _term.substitute(rules);
242 #define UNARY_FUNC_IMPLEMENT(op, OP) \
243 ExpressionBuilder::EBTerm op(const ExpressionBuilder::EBTerm & term) \
245 mooseAssert(term._root != NULL, "Empty term provided as argument of function " #op "()"); \
246 return ExpressionBuilder::EBTerm(new ExpressionBuilder::EBUnaryFuncTermNode( \
247 term.cloneRoot(), ExpressionBuilder::EBUnaryFuncTermNode::OP)); \
260 #define BINARY_FUNC_IMPLEMENT(op, OP) \
261 ExpressionBuilder::EBTerm op(const ExpressionBuilder::EBTerm & left, \
262 const ExpressionBuilder::EBTerm & right) \
264 mooseAssert(left._root != NULL, \
265 "Empty term provided as first argument of function " #op "()"); \
266 mooseAssert(right._root != NULL, \
267 "Empty term provided as second argument of function " #op "()"); \
268 return ExpressionBuilder::EBTerm(new ExpressionBuilder::EBBinaryFuncTermNode( \
269 left.cloneRoot(), right.cloneRoot(), ExpressionBuilder::EBBinaryFuncTermNode::OP)); \
281 mooseAssert(left.
_root != NULL,
"Empty term for base of pow()");
282 mooseAssert(right.
_root != NULL,
"Empty term for exponent of pow()");
287 #define TERNARY_FUNC_IMPLEMENT(op, OP) \
288 ExpressionBuilder::EBTerm op(const ExpressionBuilder::EBTerm & left, \
289 const ExpressionBuilder::EBTerm & middle, \
290 const ExpressionBuilder::EBTerm & right) \
292 mooseAssert(left._root != NULL, \
293 "Empty term provided as first argument of the ternary function " #op "()"); \
294 mooseAssert(middle._root != NULL, \
295 "Empty term provided as second argument of the ternary function " #op "()"); \
296 mooseAssert(right._root != NULL, \
297 "Empty term provided as third argument of the ternary function " #op "()"); \
298 return ExpressionBuilder::EBTerm(new ExpressionBuilder::EBTernaryFuncTermNode( \
300 middle.cloneRoot(), \
302 ExpressionBuilder::EBTernaryFuncTermNode::OP)); \
309 unsigned int nrule = rules.size();
311 for (
unsigned int i = 0; i < nrule; ++i)
313 EBTermNode * replace = rules[i]->apply(_subnode);
322 return _subnode->substitute(rules);
328 unsigned int nrule = rules.size();
329 unsigned int success = 0;
331 for (
unsigned int i = 0; i < nrule; ++i)
333 EBTermNode * replace = rules[i]->apply(_left);
346 for (
unsigned int i = 0; i < nrule; ++i)
348 EBTermNode * replace = rules[i]->apply(_right);
363 unsigned int nrule = rules.size();
364 bool left_success =
false, middle_success =
false, right_success =
false;
367 for (
unsigned int i = 0; i < nrule; ++i)
369 replace = rules[i]->apply(_left);
379 for (
unsigned int i = 0; i < nrule; ++i)
381 replace = rules[i]->apply(_middle);
386 middle_success =
true;
391 for (
unsigned int i = 0; i < nrule; ++i)
393 replace = rules[i]->apply(_right);
398 right_success =
true;
406 middle_success = _middle->substitute(rules);
408 right_success = _right->substitute(rules);
410 return left_success + middle_success + right_success;
418 return substitute(rules);
424 unsigned int nrule = rules.size();
429 for (
unsigned int i = 0; i < nrule; ++i)
431 EBTermNode * replace = rules[i]->apply(_root);
448 if (find_root == NULL)
449 mooseError(
"Function arguments must be pure symbols.");
456 mooseError(
"Trying to substitute in an empty term for ", _find);
463 return _replace->
clone();
User facing host object for a function. This combines a term with an argument list.
EBFunction & operator()(const EBTerm &arg)
virtual int precedence() const
virtual EBTermNode * substitute(const EBUnaryFuncTermNode &) const
virtual std::string stringify() const
Node representing a binary operator.
ExpressionBuilder::EBTerm pow(const ExpressionBuilder::EBTerm &left, T exponent)
const EBTermNode * getRoot() const
Base class for nodes in the expression tree.
virtual std::string stringify() const
TERNARY_FUNC_IMPLEMENT(conditional, CONDITIONAL)
EBFunction & operator=(const EBTerm &)
virtual unsigned int substitute(const EBSubstitutionRuleList &rule)
std::vector< EBTerm > EBTermList
std::ostream & operator<<(std::ostream &os, const ExpressionBuilder::EBTerm &term)
unsigned int substitute(const EBSubstitutionRule &rule)
virtual std::string stringify() const
enum ExpressionBuilder::EBUnaryFuncTermNode::NodeType _type
virtual std::string stringify() const
unsigned int substitute(const EBSubstitutionRule &rule)
virtual std::string stringify() const
virtual EBTermNode * clone() const =0
EBTermNode * cloneRoot() const
virtual unsigned int substitute(const EBSubstitutionRuleList &rule)
Template class for leaf nodes holding symbols (i.e. variables) in the expression tree.
std::vector< const EBSubstitutionRule * > EBSubstitutionRuleList
std::string args()
get the list of arguments and check if they are all symbols
Node representing a function with two arguments.
virtual unsigned int substitute(const EBSubstitutionRuleList &)
virtual EBTermNode * substitute(const EBSymbolNode &) const
ExpressionBuilder::EBTermList operator,(const ExpressionBuilder::EBTerm &larg, const ExpressionBuilder::EBTerm &rarg)
UNARY_FUNC_IMPLEMENT(sin, SIN)
Generic Substitution rule to replace all occurences of a given symbol node term with a user defined t...
virtual std::string stringify() const
Substitution rule functor base class to perform flexible term substitutions.
EBTermSubstitution(const EBTerm &find, const EBTerm &replace)
virtual std::string stringify() const
Node representing a function with two arguments.
const EBTermNode * getSubnode() const
BINARY_FUNC_IMPLEMENT(min, MIN)
virtual unsigned int substitute(const EBSubstitutionRuleList &rule)
User facing host object for an expression tree.