SundanceFunctionalPolynomial.hpp
Go to the documentation of this file.
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 #ifndef SUNDANCE_FUNCTIONALPOLYNOMIAL_H
00032 #define SUNDANCE_FUNCTIONALPOLYNOMIAL_H
00033 
00034 #include "SundanceDefs.hpp"
00035 #include "SundanceEvaluatableExpr.hpp"
00036 
00037 
00038 namespace Sundance
00039 {
00040 using namespace Sundance;
00041 using namespace Teuchos;
00042 
00043 
00044 
00045 
00046 /**
00047  * Specialized class for representing polynomials in symbolic
00048  * functions and their derivatives. 
00049  */
00050 class FunctionalPolynomial : public EvaluatableExpr
00051 {
00052 public:
00053   /** ctor */
00054   FunctionalPolynomial(const RCP<ScalarExpr>& expr);
00055   /** ctor */
00056   FunctionalPolynomial(const Map<int, RCP<ScalarExpr> >& funcs,
00057     const Map<int, Set<MultiIndex> >& funcMultiIndices,
00058     const Array<Map<MultipleDeriv, RCP<ScalarExpr> > > & coeffs);
00059 
00060   /** virtual destructor */
00061   virtual ~FunctionalPolynomial() {;}
00062 
00063 
00064   /** */
00065   virtual Set<MultipleDeriv> 
00066   internalFindW(int order, const EvalContext& context) const ;
00067 
00068       
00069 
00070   /** */
00071   virtual RCP<ExprBase> getRcp() {return rcp(this);}
00072 
00073   /** */
00074   virtual Evaluator* createEvaluator(const EvaluatableExpr* expr,
00075     const EvalContext& context) const ;
00076 
00077   /** */
00078   RCP<FunctionalPolynomial> addPoly(const FunctionalPolynomial* other,
00079     int sign) const ;
00080 
00081   /** */
00082   RCP<FunctionalPolynomial> multiplyPoly(const FunctionalPolynomial* other) const ;
00083 
00084   /** */
00085   RCP<FunctionalPolynomial> multiplyScalar(const RCP<ScalarExpr>& alpha) const ;
00086 
00087   /** */
00088   RCP<FunctionalPolynomial> addFunction(const RCP<ScalarExpr>& u,
00089     int sign) const ;
00090 
00091   /** */
00092   static bool isConvertibleToPoly(const ScalarExpr* expr) ;
00093 
00094   /** */
00095   static RCP<FunctionalPolynomial> toPoly(const RCP<ScalarExpr>& expr);
00096 
00097 
00098   /** Write a simple text description suitable 
00099    * for output to a terminal */
00100   virtual std::ostream& toText(std::ostream& os, bool paren) const ;
00101       
00102   /** Write in XML */
00103   virtual XMLObject toXML() const ;
00104 
00105   /** Ordering operator for use in transforming exprs to standard form */
00106   virtual bool lessThan(const ScalarExpr* other) const ;
00107 
00108 private:
00109 
00110   /** */
00111   Map<int, RCP<ScalarExpr> > funcs_;
00112 
00113   /** */
00114   Map<int, Set<MultiIndex> > funcMultiIndices_;
00115 
00116   /** */
00117   Array<Map<MultipleDeriv, RCP<ScalarExpr> > > coeffs_;
00118 
00119   /** */
00120   Array<Set<MultipleDeriv> > keys_;
00121 
00122   /** */
00123   Set<Deriv> findFuncsForSummation(const Set<MultipleDeriv>& prevSet,
00124     const MultipleDeriv& thisSet) const ;
00125       
00126   /**    
00127    * Given a term's key, find the term that will appear as
00128    * its successor in the evaluation recurrence.
00129    */
00130   MultipleDeriv successorTerm(const MultipleDeriv& md) const ;
00131 
00132   /** */
00133   void stepRecurrence(int level, const Map<MultipleDeriv, std::string>& sPrev,
00134     Map<MultipleDeriv, std::string>& sCurr) const ;
00135 
00136   /** */
00137   std::string evalString() const ;
00138 };
00139 }
00140 
00141 #endif

Site Contact