00001 #ifndef EXPRBASE_H
00002 #define EXPRBASE_H
00003
00004 #include "SundanceDefs.h"
00005
00006 #include <string>
00007
00008 #include "TSFUtils.h"
00009 #include "XMLObject.h"
00010 #include "DistributedDOFMap.h"
00011 #include "ExprValue.h"
00012 #include "DenseSerialVector.h"
00013 #include "TSFVector.h"
00014
00015 namespace Sundance
00016 {
00017
00018 using namespace TSF;
00019 using std::string;
00020
00021 using std::ostream;
00022
00023 class MultiIndex;
00024 class Cell;
00025 class Expr;
00026 class ExprArray;
00027 class WorkSet;
00028 class QuadratureFamily;
00029 class CellSet;
00030 class AbstractFunctionSpace;
00031 class FunctionalEvaluator;
00032 class SensitivityEvaluator;
00033
00034
00035
00036
00037
00038 enum ExprType {BASEEXPR, SUMEXPR, PRODUCTEXPR, FUNCEXPR, CONSTANTEXPR,
00039 LISTEXPR, DERIVATIVE, DIFFOP, FUNCEXPRBASE, SYMBOLICFUNCTION,
00040 UNKNOWNFUNCTION, TESTFUNCTION, COORDEXPR, DISCRETEFUNCTION,
00041 STDFUNCTIONEXPR, POWEREXPR, DISCRETEFUNCTIONDERIV,
00042 PARAMETEREXPR, USERFUNCEXPR, HOLDEXPR, REGIONALEXPR,
00043 CELLDIAMETEREXPR, INTEGRALEXPR, UNKNOWNPARAMETER,
00044 TESTPARAMETER, CELLNORMALEXPR};
00045
00046
00047
00048
00049
00050 class ExprBase
00051 {
00052 public:
00053
00054
00055
00056 ExprBase() : funcEvaluatorPtr_(-1), sensEvaluatorPtr_(-1), watching_(false) {;}
00057
00058 virtual ~ExprBase();
00059
00060
00061 virtual double value() const ;
00062
00063 virtual void setParameterValue(const double& alpha) ;
00064
00065
00066 virtual void evaluate(const WorkSet& workSet,
00067 const QuadratureFamily& quadFamily,
00068 DenseSerialVector& result) const ;
00069
00070
00071
00072 virtual void evaluate(const AbstractFunctionSpace& targetSpace, const TSFArray<Cell>& cells,
00073 const TSFArray<int>& cellIndices,
00074 const TSFArray<int>& dofIndices,
00075 const TSFArray<Point>& x,
00076 DenseSerialVector& values) const ;
00077
00078
00079
00080
00081 FunctionalEvaluator& getFunctionalEvaluator(const Expr& expr) const ;
00082
00083 SensitivityEvaluator& getSensitivityEvaluator(const Expr& functional,
00084 const Expr& u,
00085 const Expr& u0) const ;
00086
00087
00088 virtual void watchOn() {watching_ = true;}
00089
00090 virtual void watchOff() {watching_ = false;}
00091
00092
00093 virtual double probeAtMeshPoint(int localPointIndex) const ;
00094
00095
00096 virtual double norm() const ;
00097
00098
00099 virtual double quickNorm() const ;
00100
00101 virtual double maxNorm() const ;
00102
00103 virtual void getVector(TSFVector& vector) const ;
00104
00105 virtual void setVector(const TSFVector& vector);
00106
00107 virtual void readValues(const string& filename);
00108
00109
00110 virtual void getDOFMap(TSFSmartPtr<DOFMapBase>& map) const ;
00111
00112
00113 virtual int getReducedIndex() const ;
00114
00115
00116 virtual ExprValue average(const Cell& cell) const ;
00117
00118
00119 virtual const MultiIndex& multiIndex() const ;
00120
00121
00122
00123
00124 virtual const Expr& listElement(int i) const ;
00125
00126
00127 virtual Expr& listElement(int i) ;
00128
00129 virtual int length() const ;
00130
00131 virtual int size() const ;
00132
00133
00134
00135
00136 virtual void derivative(const MultiIndex& d, Expr& result) const ;
00137
00138
00139 virtual const Expr& getRegionalExpr(const string& region) const ;
00140
00141
00142 virtual bool isDefinedOnRegion(const string& region) const ;
00143
00144
00145 virtual void setRegionalExpr(const string& region, const Expr& expr);
00146
00147
00148
00149 virtual void pow(const double& p, Expr& result) const ;
00150
00151 static void add(const Expr& e1, const Expr& e2, int sign, Expr& result);
00152
00153 static void multiply(const Expr& e1, const Expr& e2, Expr& result);
00154
00155 static void divide(const Expr& e1, const Expr& e2, Expr& result);
00156
00157
00158
00159 virtual bool operator==(const Expr& other) const = 0 ;
00160
00161 virtual bool operator<(const Expr& other) const = 0 ;
00162
00163 virtual bool typeLessThan(const Expr& other) const ;
00164
00165 virtual bool typeGreaterThan(const Expr& other) const ;
00166
00167 virtual int sortPriority() const {return BASEEXPR;}
00168
00169
00170
00171 virtual bool isTermListExpr() const {return false;}
00172
00173 virtual bool isSumExpr() const {return false;}
00174
00175 virtual bool isProductExpr() const {return false;}
00176
00177 virtual bool isFuncExpr() const {return false;}
00178
00179 virtual bool isConstant() const {return false;}
00180
00181 virtual bool isZero() const {return false;}
00182
00183 virtual bool isListExpr() const {return false;}
00184
00185 virtual bool isDiffOp() const {return false;}
00186
00187 virtual bool isDerivative() const {return false;}
00188
00189 virtual bool isVariational() const {return false;}
00190
00191 virtual bool isUnknown() const {return false;}
00192
00193 virtual bool isCoordExpr() const {return false;}
00194
00195 virtual bool isDiscreteFunction() const {return false;}
00196
00197 virtual bool isUserFuncExpr() const {return false;}
00198
00199 virtual bool isParameterExpr() const {return false;}
00200
00201 virtual bool isHoldExpr() const {return false;}
00202
00203 virtual bool isRegionalExpr() const {return false;}
00204
00205 virtual bool isCellDiameterExpr() const {return false;}
00206
00207 virtual bool isCellNormalExpr() const {return false;}
00208
00209 virtual bool isIntegralExpr() const {return false;}
00210
00211 virtual bool isTestParameter() const {return false;}
00212
00213 virtual bool isUnknownParameter() const {return false;}
00214
00215
00216
00217 virtual bool isSpatiallyConstant() const {return false;}
00218
00219
00220 bool watching() const {return watching_;}
00221
00222
00223 virtual bool hasChildren() const {return false;}
00224
00225
00226 virtual void getChildren(ExprArray& ) const {;}
00227
00228
00229 virtual int funcID() const ;
00230
00231
00232 virtual ExprBase* clone() const = 0 ;
00233
00234 virtual void extractPrefactor(double& prefactor, Expr& result) const ;
00235
00236 virtual const string& name() const ;
00237
00238 virtual void print(ostream& os, bool paren=false) const = 0 ;
00239
00240 virtual void matlabDump(ostream& os) const ;
00241
00242
00243 virtual string typeName() const ;
00244
00245
00246
00247
00248 virtual void getBasis(BasisFamily& basis) const ;
00249
00250 virtual int countMonomials() const ;
00251
00252 virtual void getMonomials(ExprArray& monomials, int& offset) const ;
00253
00254 virtual bool getValidWeakForm(Expr& coeff,
00255 Expr& var,
00256 Expr& unk) const ;
00257
00258 virtual bool getMesh(Mesh& ) const {return false;}
00259
00260 virtual void getDomain(TSFNonDupArray<CellSet>& domain) const ;
00261
00262
00263
00264
00265 bool trace() const {return trace_;}
00266
00267 static void traceOn() {trace_ = true;}
00268
00269 static void traceOff() {trace_ = false;}
00270
00271 bool verbosePrint() const {return verbosePrint_;}
00272
00273 static void verbosePrintOn() {verbosePrint_ = true;}
00274
00275 static void verbosePrintOff() {verbosePrint_ = false;}
00276
00277 void traceBinaryOp(const string& mesg, const Expr& other) const ;
00278
00279 void fullForm(ostream& os) const ;
00280
00281
00282 virtual bool lhsAppearsOnRHS(const Expr& ) const {return false;}
00283
00284 virtual void replaceWithCloneOfAssignmentLHS(const Expr& ,
00285 const Expr& ) {;}
00286
00287
00288 virtual string toString(bool paren=false) const ;
00289
00290 virtual XMLObject toXML() const ;
00291
00292
00293 friend class Expr;
00294
00295 int hashCode() const {return (int) (long int) this;}
00296
00297
00298 virtual void differential(const Expr& u, const Expr& du,
00299 Expr& result) const ;
00300
00301
00302 virtual void substitute(const Expr& u, const Expr& du,
00303 Expr& result) const ;
00304
00305
00306 virtual void setFunctionValue(const Expr& u0) ;
00307
00308
00309 virtual void getVariation(Expr& result) const ;
00310
00311
00312 virtual void getDifferential(Expr& result) const ;
00313
00314
00315 virtual void setVariation(const Expr& v) ;
00316
00317
00318 virtual void setDifferential(const Expr& du) ;
00319 protected:
00320
00321 virtual void checkForCancellations(Expr& result);
00322
00323 virtual double constant() const ;
00324
00325
00326 virtual void baseClassMethodCall(const string& method) const ;
00327
00328 mutable int funcEvaluatorPtr_;
00329 mutable int sensEvaluatorPtr_;
00330
00331 static string dummyName_;
00332 static MultiIndex dummyMultiIndex_;
00333 static bool trace_;
00334 static bool verbosePrint_;
00335
00336 private:
00337 bool watching_;
00338 };
00339
00340
00341
00342
00343 }
00344 #endif
00345
00346
00347
00348
00349
00350
00351
00352