00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
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
00048
00049
00050 class FunctionalPolynomial : public EvaluatableExpr
00051 {
00052 public:
00053
00054 FunctionalPolynomial(const RCP<ScalarExpr>& expr);
00055
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
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
00099
00100 virtual std::ostream& toText(std::ostream& os, bool paren) const ;
00101
00102
00103 virtual XMLObject toXML() const ;
00104
00105
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
00128
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