00001 /* @HEADER@ */ 00002 // ************************************************************************ 00003 // 00004 // Sundance 00005 // Copyright (2005) Sandia Corporation 00006 // 00007 // Copyright (year first published) Sandia Corporation. Under the terms 00008 // of Contract DE-AC04-94AL85000 with Sandia Corporation, the U.S. Government 00009 // retains certain rights in this software. 00010 // 00011 // This library is free software; you can redistribute it and/or modify 00012 // it under the terms of the GNU Lesser General Public License as 00013 // published by the Free Software Foundation; either version 2.1 of the 00014 // License, or (at your option) any later version. 00015 // 00016 // This library is distributed in the hope that it will be useful, but 00017 // WITHOUT ANY WARRANTY; without even the implied warranty of 00018 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00019 // Lesser General Public License for more details. 00020 // 00021 // You should have received a copy of the GNU Lesser General Public 00022 // License along with this library; if not, write to the Free Software 00023 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 00024 // USA 00025 // Questions? Contact Kevin Long (krlong@sandia.gov), 00026 // Sandia National Laboratories, Livermore, California, USA 00027 // 00028 // ************************************************************************ 00029 /* @HEADER@ */ 00030 00031 00032 00033 #ifndef SUNDANCE_PRODUCTEXPR_H 00034 #define SUNDANCE_PRODUCTEXPR_H 00035 00036 #include "SundanceBinaryExpr.hpp" 00037 00038 00039 namespace Sundance 00040 { 00041 using namespace Sundance; 00042 using namespace Teuchos; 00043 00044 00045 00046 00047 00048 /** 00049 * ProductExpr represents a product of two scalar-valued expressions 00050 */ 00051 class ProductExpr : public BinaryExpr 00052 { 00053 public: 00054 /** */ 00055 ProductExpr(const RCP<ScalarExpr>& a, 00056 const RCP<ScalarExpr>& b); 00057 00058 /** virtual dtor */ 00059 virtual ~ProductExpr() {;} 00060 00061 /** Indicate whether this expression is a "hungry" 00062 * differential operator that is awaiting an argument. */ 00063 virtual bool isHungryDiffOp() const ; 00064 00065 /** */ 00066 virtual Evaluator* createEvaluator(const EvaluatableExpr* expr, 00067 const EvalContext& context) const ; 00068 00069 /** */ 00070 virtual Set<MultiSet<int> > internalFindQ_W(int order, 00071 const EvalContext& context) const ; 00072 00073 /** */ 00074 virtual Set<MultiSet<int> > internalFindQ_V(int order, 00075 const EvalContext& context) const ; 00076 00077 00078 00079 /** */ 00080 virtual bool isProduct() const {return true;} 00081 00082 /** 00083 * Indicate whether the expression is linear 00084 * with respect to test functions */ 00085 virtual bool isLinearInTests() const 00086 { 00087 bool leftIsLinear = leftScalar()->isLinearInTests() ; 00088 bool rightIsLinear = rightScalar()->isLinearInTests() ; 00089 00090 bool leftHasTests = leftScalar()->hasTestFunctions() ; 00091 bool rightHasTests = rightScalar()->hasTestFunctions() ; 00092 00093 return (leftIsLinear && !rightHasTests) 00094 || (!leftHasTests && rightIsLinear); 00095 } 00096 00097 /** Indicate whether the expression is linear in the given 00098 * functions */ 00099 virtual bool isLinearForm(const Expr& u) const 00100 { 00101 bool L = leftScalar()->isLinearForm(u); 00102 bool R = rightScalar()->isLinearForm(u); 00103 return ( (L || R) && !(L==R) ); 00104 } 00105 00106 /** Indicate whether the expression is a quadratic form in the given 00107 * functions */ 00108 virtual bool isQuadraticForm(const Expr& u) const 00109 { 00110 bool LQ = leftScalar()->isQuadraticForm(u); 00111 bool RQ = rightScalar()->isQuadraticForm(u); 00112 bool LL = leftScalar()->isLinearForm(u); 00113 bool RL = leftScalar()->isLinearForm(u); 00114 bool LI = leftScalar()->isIndependentOf(u); 00115 bool RI = rightScalar()->isIndependentOf(u); 00116 00117 if (LI && RQ) return true; 00118 if (RI && LQ) return true; 00119 if (LL && RL) return true; 00120 return false; 00121 } 00122 00123 /** */ 00124 virtual RCP<ExprBase> getRcp() {return rcp(this);} 00125 protected: 00126 /** */ 00127 virtual bool parenthesizeSelf() const {return true;} 00128 /** */ 00129 virtual bool parenthesizeOperands() const {return true;} 00130 /** */ 00131 virtual const std::string& xmlTag() const ; 00132 /** */ 00133 virtual const std::string& opChar() const ; 00134 00135 private: 00136 00137 }; 00138 } 00139 00140 #endif