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_ELRFAD_GENERALFAD_HPP
00055 #define SACADO_ELRFAD_GENERALFAD_HPP
00056
00057 #include "Sacado_ELRFad_Expression.hpp"
00058
00059 namespace Sacado {
00060
00062 namespace ELRFad {
00063
00065
00070 template <typename T, typename Storage>
00071 class GeneralFad {
00072
00073 public:
00074
00076 typedef T value_type;
00077
00082
00084 GeneralFad() : s_(T(0.)) {}
00085
00087
00090 GeneralFad(const T & x) : s_(x) {}
00091
00093
00096 GeneralFad(const int sz, const T & x) : s_(sz, x) {}
00097
00099
00104 GeneralFad(const int sz, const int i, const T & x) :
00105 s_(sz, x) {
00106 s_.dx_[i]=1.;
00107 }
00108
00110 GeneralFad(const GeneralFad& x) :
00111 s_(x.s_) {}
00112
00114 template <typename S> GeneralFad(const Expr<S>& x);
00115
00117 ~GeneralFad() {}
00118
00120
00126 void diff(const int ith, const int n);
00127
00129
00134 void resize(int sz) { s_.resize(sz); }
00135
00137 void zero() { s_.zero(); }
00138
00140
00145
00147 const T& val() const { return s_.val_;}
00148
00150 T& val() { return s_.val_;}
00151
00153
00158
00160 int size() const { return s_.size();}
00161
00163 bool hasFastAccess() const { return s_.size()!=0;}
00164
00166 bool isPassive() const { return s_.size()!=0;}
00167
00169 void setIsConstant(bool is_const) {
00170 if (is_const && s_.size()!=0)
00171 s_.resize(0);
00172 }
00173
00175 const T* dx() const { return &(s_.dx_[0]);}
00176
00178 T dx(int i) const {
00179 return s_.size() ? s_.dx_[i] : T(0.); }
00180
00182 T& fastAccessDx(int i) { return s_.dx_[i];}
00183
00185 const T& fastAccessDx(int i) const { return s_.dx_[i];}
00186
00188
00193
00195 GeneralFad& operator=(const T& val);
00196
00198 GeneralFad&
00199 operator=(const GeneralFad& x);
00200
00202 template <typename S>
00203 GeneralFad& operator=(const Expr<S>& x);
00204
00206
00211
00213 GeneralFad& operator += (const T& x);
00214
00216 GeneralFad& operator -= (const T& x);
00217
00219 GeneralFad& operator *= (const T& x);
00220
00222 GeneralFad& operator /= (const T& x);
00223
00225 template <typename S>
00226 GeneralFad& operator += (const Expr<S>& x);
00227
00229 template <typename S>
00230 GeneralFad& operator -= (const Expr<S>& x);
00231
00233 template <typename S>
00234 GeneralFad& operator *= (const Expr<S>& x);
00235
00237 template <typename S>
00238 GeneralFad& operator /= (const Expr<S>& x);
00239
00241
00242 protected:
00243
00245 Storage s_;
00246
00247
00248
00249 template <typename ExprT>
00250 struct LocalAccumOp {
00251 typedef typename ExprT::value_type value_type;
00252 static const int N = ExprT::num_args;
00253 const ExprT& x;
00254 mutable value_type t;
00255 value_type partials[N];
00256 int i;
00257 inline LocalAccumOp(const ExprT& x_) :
00258 x(x_) { x.computePartials(value_type(1.), partials); }
00259 template <typename ArgT>
00260 inline void operator () (ArgT arg) const {
00261 const int Arg = ArgT::value;
00262 if (x.template isActive<Arg>())
00263 t += partials[Arg] * x.template getTangent<Arg>(i);
00264 }
00265 };
00266
00267 };
00268
00269
00270 template <typename T, typename Storage>
00271 std::ostream& operator << (std::ostream& os,
00272 const GeneralFad<T,Storage>& x) {
00273 os << x.val() << " [";
00274
00275 for (int i=0; i< x.size(); i++) {
00276 os << " " << x.dx(i);
00277 }
00278
00279 os << " ]\n";
00280 return os;
00281 }
00282
00283 }
00284
00285 }
00286
00287 #include "Sacado_ELRFad_GeneralFadImp.hpp"
00288
00289 #endif // SACADO_ELRFAD_GENERALFAD_HPP