18 #include "libmesh/libmesh_common.h" 68 virtual std::string
stringify()
const = 0;
70 virtual int precedence()
const = 0;
231 virtual int precedence()
const;
308 template <
class Node_T>
317 virtual EBTermNode * substitute(
const Node_T &)
const = 0;
345 mooseAssert(_epsilon != NULL,
"Epsilon must not be an empty term in EBLogPlogSubstitution");
392 operator std::string()
const {
return _root->stringify(); }
416 #define UNARY_OP_IMPLEMENT(op, OP) \ 417 EBTerm operator op() const \ 419 mooseAssert(_root != NULL, "Empty term provided for unary operator " #op); \ 420 return EBTerm(new EBUnaryOpTermNode(cloneRoot(), EBUnaryOpTermNode::OP)); \ 422 UNARY_OP_IMPLEMENT(-, NEG)
423 UNARY_OP_IMPLEMENT(!, LOGICNOT)
443 #define BINARY_OP_IMPLEMENT(op, OP) \ 444 EBTerm operator op(const EBTerm & term) const \ 446 mooseAssert(_root != NULL, "Empty term provided on left side of operator " #op); \ 447 mooseAssert(term._root != NULL, "Empty term provided on right side of operator " #op); \ 448 return EBTerm(new EBBinaryOpTermNode(cloneRoot(), term.cloneRoot(), EBBinaryOpTermNode::OP)); \ 450 friend EBTerm operator op(int left, const EBTerm & right) \ 452 mooseAssert(right._root != NULL, "Empty term provided on right side of operator " #op); \ 453 return EBTerm(new EBBinaryOpTermNode( \ 454 new EBNumberNode<int>(left), right.cloneRoot(), EBBinaryOpTermNode::OP)); \ 456 friend EBTerm operator op(Real left, const EBTerm & right) \ 458 mooseAssert(right._root != NULL, "Empty term provided on right side of operator " #op); \ 459 return EBTerm(new EBBinaryOpTermNode( \ 460 new EBNumberNode<Real>(left), right.cloneRoot(), EBBinaryOpTermNode::OP)); \ 462 friend EBTerm operator op(const EBFunction & left, const EBTerm & right) \ 464 mooseAssert(EBTerm(left)._root != NULL, "Empty term provided on left side of operator " #op); \ 465 mooseAssert(right._root != NULL, "Empty term provided on right side of operator " #op); \ 466 return EBTerm(new EBBinaryOpTermNode( \ 467 EBTerm(left).cloneRoot(), right.cloneRoot(), EBBinaryOpTermNode::OP)); \ 469 friend EBTerm operator op(const EBFunction & left, const EBFunction & right); \ 470 friend EBTerm operator op(int left, const EBFunction & right); \ 471 friend EBTerm operator op(Real left, const EBFunction & right); 472 BINARY_OP_IMPLEMENT(+, ADD)
473 BINARY_OP_IMPLEMENT(-, SUB)
474 BINARY_OP_IMPLEMENT(*, MUL)
475 BINARY_OP_IMPLEMENT(/, DIV)
476 BINARY_OP_IMPLEMENT(%, MOD)
477 BINARY_OP_IMPLEMENT(<, LESS)
478 BINARY_OP_IMPLEMENT(>, GREATER)
479 BINARY_OP_IMPLEMENT(<=, LESSEQ)
480 BINARY_OP_IMPLEMENT(>=, GREATEREQ)
481 BINARY_OP_IMPLEMENT(==, EQ)
482 BINARY_OP_IMPLEMENT(!=, NOTEQ)
487 #define BINARYCOMP_OP_IMPLEMENT(op, OP) \ 488 EBTerm & operator op(const EBTerm & term) \ 490 mooseAssert(_root != NULL, "Empty term provided on left side of operator " #op); \ 491 mooseAssert(term._root != NULL, "Empty term provided on right side of operator " #op); \ 492 if (dynamic_cast<EBTempIDNode *>(_root)) \ 493 mooseError("Using compound assignment operator on anonymous term. Set it to 0 first!"); \ 494 _root = new EBBinaryOpTermNode(_root, term.cloneRoot(), EBBinaryOpTermNode::OP); \ 497 BINARYCOMP_OP_IMPLEMENT(+=, ADD)
498 BINARYCOMP_OP_IMPLEMENT(-=, SUB)
499 BINARYCOMP_OP_IMPLEMENT(*=, MUL)
500 BINARYCOMP_OP_IMPLEMENT(/=, DIV)
501 BINARYCOMP_OP_IMPLEMENT(%=, MOD)
510 template <
typename T>
541 return (*
this)((a1, a2, a3));
546 return (*
this)((a1, a2, a3, a4));
554 return (*
this)((a1, a2, a3, a4, a5));
563 return (*
this)((a1, a2, a3, a4, a5, a6));
573 return (*
this)((a1, a2, a3, a4, a5, a6, a7));
584 return (*
this)((a1, a2, a3, a4, a5, a6, a7, a8));
596 return (*
this)((a1, a2, a3, a4, a5, a6, a7, a8, a9));
604 operator std::string()
const;
638 #define BINARYFUNC_OP_IMPLEMENT(op, OP) \ 639 friend EBTerm operator op(const EBFunction & left, const EBFunction & right) \ 641 mooseAssert(EBTerm(left)._root != NULL, "Empty term provided on left side of operator " #op); \ 642 mooseAssert(EBTerm(right)._root != NULL, \ 643 "Empty term provided on right side of operator " #op); \ 644 return EBTerm(new EBBinaryOpTermNode( \ 645 EBTerm(left).cloneRoot(), EBTerm(right).cloneRoot(), EBBinaryOpTermNode::OP)); \ 647 friend EBTerm operator op(int left, const EBFunction & right) \ 649 mooseAssert(EBTerm(right)._root != NULL, \ 650 "Empty term provided on right side of operator " #op); \ 651 return EBTerm(new EBBinaryOpTermNode( \ 652 new EBNumberNode<int>(left), EBTerm(right).cloneRoot(), EBBinaryOpTermNode::OP)); \ 654 friend EBTerm operator op(Real left, const EBFunction & right) \ 656 mooseAssert(EBTerm(right)._root != NULL, \ 657 "Empty term provided on right side of operator " #op); \ 658 return EBTerm(new EBBinaryOpTermNode( \ 659 new EBNumberNode<Real>(left), EBTerm(right).cloneRoot(), EBBinaryOpTermNode::OP)); \ 661 BINARYFUNC_OP_IMPLEMENT(+, ADD)
662 BINARYFUNC_OP_IMPLEMENT(-, SUB)
663 BINARYFUNC_OP_IMPLEMENT(*, MUL)
664 BINARYFUNC_OP_IMPLEMENT(/, DIV)
665 BINARYFUNC_OP_IMPLEMENT(%, MOD)
666 BINARYFUNC_OP_IMPLEMENT(<, LESS)
667 BINARYFUNC_OP_IMPLEMENT(>, GREATER)
668 BINARYFUNC_OP_IMPLEMENT(<=, LESSEQ)
669 BINARYFUNC_OP_IMPLEMENT(>=, GREATEREQ)
670 BINARYFUNC_OP_IMPLEMENT(==, EQ)
671 BINARYFUNC_OP_IMPLEMENT(!=, NOTEQ)
675 template <
typename T>
686 template <
typename T>
690 std::ostringstream s;
691 s << std::setprecision(12) << _value;
695 template <
class Node_T>
700 const Node_T * match_node =
dynamic_cast<const Node_T *
>(node);
701 if (match_node == NULL)
704 return substitute(*match_node);
Node representing a function with three arguments.
User facing host object for an expression tree.
virtual EBNumberNode< T > * clone() const
Base class for nodes with two sub nodes (i.e. functions or operators taking two arguments) ...
virtual EBUnaryOpTermNode * clone() const
virtual EBBinaryOpTermNode * clone() const
EBFunction & operator()(const EBTerm &a1, const EBTerm &a2, const EBTerm &a3, const EBTerm &a4, const EBTerm &a5, const EBTerm &a6)
Node representing a unary operator.
CTSub CT_OPERATOR_BINARY CTMul CTCompareLess CTCompareGreater CTCompareEqual _arg template * sin(_arg) *_arg.template D< dtag >()) CT_SIMPLE_UNARY_FUNCTION(tan
virtual ~EBSubstitutionRule()
EBFunction & operator()(const EBTerm &a1, const EBTerm &a2, const EBTerm &a3, const EBTerm &a4)
Template class for leaf nodes holding anonymous IDs in the expression tree.
virtual int precedence() const
virtual ~EBLogPlogSubstitution()
Node representing a binary operator.
ExpressionBuilder::EBTermList operator,(const ExpressionBuilder::EBTerm &larg, const ExpressionBuilder::EBTerm &rarg)
EBUnaryTermNode(EBTermNode *subnode)
Base class for nodes with a single sub node (i.e. functions or operators taking one argument) ...
virtual EBUnaryFuncTermNode * clone() const
const EBTermNode * getSubnode() const
virtual int precedence() const
std::ostream & operator<<(std::ostream &os, const OrderWrapper &order)
EBTermList _eval_arguments
argument list passed in when evaluating the function
Node representing a function with two arguments.
EBLogPlogSubstitution(const EBTerm &epsilon)
EBFunction & operator()(const EBTerm &a1, const EBTerm &a2, const EBTerm &a3, const EBTerm &a4, const EBTerm &a5, const EBTerm &a6, const EBTerm &a7, const EBTerm &a8, const EBTerm &a9)
virtual EBTermNode * clone() const =0
std::vector< EBTerm > EBTermList
The following methods are specializations for using the Parallel::packed_range_* routines for a vecto...
std::basic_ostream< charT, traits > * os
ExpressionBuilder adds an interface to derived classes that enables convenient construction of FParse...
virtual ~EBTernaryTermNode()
EBFunction & operator()(const EBTerm &a1, const EBTerm &a2, const EBTerm &a3)
virtual std::string stringify() const
virtual EBSymbolNode * clone() const
Substitution rule base class that applies to nodes of type Node_T.
EBBinaryTermNode(EBTermNode *left, EBTermNode *right)
Base class for nodes in the expression tree.
auto max(const L &left, const R &right)
virtual EBTempIDNode * clone() const
ADRealEigenVector< T, D, asd > abs(const ADRealEigenVector< T, D, asd > &)
virtual int precedence() const
friend std::ostream & operator<<(std::ostream &os, const EBTermNode &node)
Template class for leaf nodes holding symbols (i.e. variables) in the expression tree.
virtual int precedence() const
CTSub CT_OPERATOR_BINARY CTMul CTCompareLess CTCompareGreater CTCompareEqual _arg template cos(_arg) *_arg.template D< dtag >()) CT_SIMPLE_UNARY_FUNCTION(cos
virtual ~EBTermSubstitution()
Template class for leaf nodes holding numbers in the expression tree.
Real value(unsigned n, unsigned alpha, unsigned beta, Real x)
virtual unsigned int substitute(const EBSubstitutionRuleList &)
Node representing a function with two arguments.
EBUnaryOpTermNode(EBTermNode *subnode, NodeType type)
EBUnaryFuncTermNode(EBTermNode *subnode, NodeType type)
Real root(std::function< Real(Real)> const &f, Real x1, Real x2, Real tol=1.0e-12)
Finds the root of a function using Brent's method.
EBSymbolNode(std::string symbol)
auto conditional(const C &, const L &, const R &)
std::string stringify(const T &t)
virtual EBBinaryFuncTermNode * clone() const
EBFunction & operator()(const EBTerm &a1, const EBTerm &a2)
virtual int precedence() const
CTSub CT_OPERATOR_BINARY CTMul CTCompareLess CTCompareGreater CTCompareEqual _arg template sinh(_arg) *_arg.template D< dtag >()) CT_SIMPLE_UNARY_FUNCTION(erf
virtual std::string stringify() const =0
std::vector< const EBSubstitutionRule * > EBSubstitutionRuleList
virtual EBTernaryFuncTermNode * clone() const
virtual int precedence() const
ExpressionBuilder::EBTerm pow(const ExpressionBuilder::EBTerm &left, T exponent)
const EBTermNode * getRoot() const
Substitution rule to replace all occurences of log(x) with plog(x, epsilon) with a user defined term ...
virtual ~EBBinaryTermNode()
infix_ostream_iterator< T, charT, traits > & operator=(T const &item)
EBFunction & operator()(const EBTerm &a1, const EBTerm &a2, const EBTerm &a3, const EBTerm &a4, const EBTerm &a5, const EBTerm &a6, const EBTerm &a7, const EBTerm &a8)
DIE A HORRIBLE DEATH HERE typedef LIBMESH_DEFAULT_SCALAR_TYPE Real
std::vector< EBTermNode * > EBTermNodeList
User facing host object for a function. This combines a term with an argument list.
virtual int precedence() const
EBTerm(const char *symbol)
virtual ~EBUnaryTermNode()
EBTernaryFuncTermNode(EBTermNode *left, EBTermNode *middle, EBTermNode *right, NodeType type)
EBTermList _arguments
argument list the function is declared with
EBTernaryTermNode(EBTermNode *left, EBTermNode *middle, EBTermNode *right)
virtual EBTermNode * apply(const EBTermNode *) const
CTSub CT_OPERATOR_BINARY CTMul CTCompareLess CTCompareGreater CTCompareEqual _arg template cosh(_arg) *_arg.template D< dtag >()) CT_SIMPLE_UNARY_FUNCTION(cosh
Generic Substitution rule to replace all occurences of a given symbol node term with a user defined t...
EBFunction & operator()(const EBTerm &a1, const EBTerm &a2, const EBTerm &a3, const EBTerm &a4, const EBTerm &a5)
EBTerm(const EBTerm &term)
auto min(const L &left, const R &right)
Substitution rule functor base class to perform flexible term substitutions.
void ErrorVector unsigned int
EBBinaryFuncTermNode(EBTermNode *left, EBTermNode *right, NodeType type)
EBTempIDNode(unsigned int id)
EBFunction & operator()(const EBTerm &a1, const EBTerm &a2, const EBTerm &a3, const EBTerm &a4, const EBTerm &a5, const EBTerm &a6, const EBTerm &a7)
EBTermNode * cloneRoot() const
EBBinaryOpTermNode(EBTermNode *left, EBTermNode *right, NodeType type)
Base class for nodes with two sub nodes (i.e. functions or operators taking two arguments) ...
EBTerm & operator=(const EBTerm &term)