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
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042
00043
00044
00045
00046
00047
00048
00049
00050
00051
00052
00053
00054 #ifndef SACADO_CACHEFAD_EXPRESSION_HPP
00055 #define SACADO_CACHEFAD_EXPRESSION_HPP
00056
00057 #include "Sacado_Traits.hpp"
00058
00059 namespace Sacado {
00060
00061 namespace CacheFad {
00062
00064
00068 template <typename ExprT>
00069 class Expr {
00070
00071 public:
00072
00074 typedef typename ExprT::value_type value_type;
00075
00077 explicit Expr(const ExprT& expr) : expr_(expr) {}
00078
00080 int size() const {return expr_.size();}
00081
00083 bool hasFastAccess() const { return expr_.hasFastAccess();}
00084
00086 value_type val() const { return expr_.val();}
00087
00089 value_type dx(int i) const { return expr_.dx(i);}
00090
00092 value_type fastAccessDx(int i) const { return expr_.fastAccessDx(i);}
00093
00094 protected:
00095
00097 Expr() {}
00098
00100 ExprT expr_;
00101
00102 };
00103
00105
00108 template <typename ConstT>
00109 class ConstExpr {
00110
00111 public:
00112
00114 typedef ConstT value_type;
00115
00117 ConstExpr(const ConstT& constant) : constant_(constant) {}
00118
00120 int size() const { return 0; }
00121
00123 bool hasFastAccess() const { return 1; }
00124
00126 value_type val() const { return constant_; }
00127
00129 value_type dx(int i) const { return value_type(0); }
00130
00132 value_type fastAccessDx(int i) const { return value_type(0); }
00133
00134 protected:
00135
00137 const ConstT& constant_;
00138
00139 };
00140
00142
00151 template <typename ExprT, template<typename> class Op>
00152 class UnaryExpr {
00153
00154 public:
00155
00157 typedef typename ExprT::value_type value_type;
00158
00160 UnaryExpr(const ExprT& expr) : expr_(expr), op_(expr) {}
00161
00163 int size() const { return expr_.size(); }
00164
00166 bool hasFastAccess() const { return expr_.hasFastAccess(); }
00167
00169 value_type val() const { return op_.computeValue(expr_); }
00170
00172 value_type dx(int i) const { return op_.computeDx(i,expr_); }
00173
00175 value_type fastAccessDx(int i) const {
00176 return op_.computeFastAccessDx(i,expr_);
00177 }
00178
00179 protected:
00180
00182 const ExprT& expr_;
00183
00185 Op<ExprT> op_;
00186
00187 };
00188
00189
00190
00191
00192
00193
00194
00195
00196
00197 template <typename T> struct ExprConstRef {
00198 typedef const T& type;
00199 };
00200 template <typename T> struct ExprConstRef< ConstExpr<T> > {
00201 typedef const ConstExpr<T> type;
00202 };
00203
00205
00215 template <typename ExprT1, typename ExprT2,
00216 template<typename,typename> class Op>
00217 class BinaryExpr {
00218
00219 public:
00220
00222 typedef typename ExprT1::value_type value_type_1;
00223
00225 typedef typename ExprT2::value_type value_type_2;
00226
00228 typedef typename Sacado::Promote<value_type_1,
00229 value_type_2>::type value_type;
00230
00232 BinaryExpr(const ExprT1& expr1, const ExprT2& expr2) :
00233 expr1_(expr1), expr2_(expr2), op_(expr1,expr2) {}
00234
00236 int size() const {
00237 int sz1 = expr1_.size(), sz2 = expr2_.size();
00238 return sz1 > sz2 ? sz1 : sz2;
00239 }
00240
00242 bool hasFastAccess() const {
00243 return expr1_.hasFastAccess() && expr2_.hasFastAccess();}
00244
00246 value_type val() const {
00247 return op_.computeValue(expr1_,expr2_); }
00248
00250 value_type dx(int i) const {
00251 return op_.computeDx(i,expr1_,expr2_); }
00252
00254 value_type fastAccessDx(int i) const {
00255 return op_.computeFastAccessDx(i,expr1_,expr2_);
00256 }
00257
00258 protected:
00259
00261 typename ExprConstRef<ExprT1>::type expr1_;
00262
00264 typename ExprConstRef<ExprT2>::type expr2_;
00265
00267 Op<ExprT1,ExprT2> op_;
00268
00269 };
00270
00271 }
00272
00273 }
00274
00275 #endif // SACADO_CACHEFAD_EXPRESSION_HPP