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 #ifndef SACADO_LFAD_LOGICALSPARSE_HPP
00033 #define SACADO_LFAD_LOGICALSPARSE_HPP
00034
00035 #include "Sacado_LFad_LogicalSparseTraits.hpp"
00036 #include "Sacado_LFad_ExpressionTraits.hpp"
00037 #include "Sacado_Fad_DynamicStorage.hpp"
00038
00039 namespace Sacado {
00040
00042 namespace LFad {
00043
00045
00049 template <typename ExprT> class Expr {};
00050
00055 template <typename ValT, typename LogT>
00056 class LogicalSparseImp {
00057
00058 public:
00059
00061 typedef ValT value_type;
00062
00064 typedef LogT logical_type;
00065
00070
00072 LogicalSparseImp() : s_(value_type(0)) {}
00073
00075
00078 LogicalSparseImp(const value_type & x) : s_(x) {}
00079
00081
00084 LogicalSparseImp(const int sz, const value_type & x) : s_(sz, x) {}
00085
00087
00092 LogicalSparseImp(const int sz, const int i, const value_type & x) :
00093 s_(sz, x) {
00094 s_.dx_[i]=logical_type(1);
00095 }
00096
00098 LogicalSparseImp(const LogicalSparseImp& x) :
00099 s_(x.s_) {}
00100
00102 template <typename S> LogicalSparseImp(const Expr<S>& x);
00103
00105 ~LogicalSparseImp() {}
00106
00108
00114 void diff(const int ith, const int n);
00115
00117
00122 void resize(int sz) { s_.resize(sz); }
00123
00125 void zero() { s_.zero(); }
00126
00128
00133
00135 const value_type& val() const { return s_.val_;}
00136
00138 value_type& val() { return s_.val_;}
00139
00141
00146
00148 int size() const { return s_.size();}
00149
00151 bool hasFastAccess() const { return s_.size()!=0;}
00152
00154 bool isPassive() const { return s_.size()!=0;}
00155
00157 void setIsConstant(bool is_const) {
00158 if (is_const && s_.size()!=0)
00159 s_.resize(0);
00160 }
00161
00163 const logical_type* dx() const { return &(s_.dx_[0]);}
00164
00166 logical_type dx(int i) const {
00167 return s_.size() ? s_.dx_[i] : logical_type(0); }
00168
00170 logical_type& fastAccessDx(int i) { return s_.dx_[i];}
00171
00173 const logical_type& fastAccessDx(int i) const { return s_.dx_[i];}
00174
00176
00181
00183 LogicalSparseImp& operator=(const value_type& val);
00184
00186 LogicalSparseImp&
00187 operator=(const LogicalSparseImp& x);
00188
00190 template <typename S>
00191 LogicalSparseImp& operator=(const Expr<S>& x);
00192
00194
00199
00201 LogicalSparseImp& operator += (const value_type& x);
00202
00204 LogicalSparseImp& operator -= (const value_type& x);
00205
00207 LogicalSparseImp& operator *= (const value_type& x);
00208
00210 LogicalSparseImp& operator /= (const value_type& x);
00211
00213 template <typename S>
00214 LogicalSparseImp& operator += (const Expr<S>& x);
00215
00217 template <typename S>
00218 LogicalSparseImp& operator -= (const Expr<S>& x);
00219
00221 template <typename S>
00222 LogicalSparseImp& operator *= (const Expr<S>& x);
00223
00225 template <typename S>
00226 LogicalSparseImp& operator /= (const Expr<S>& x);
00227
00229
00230 protected:
00231
00233 Fad::DynamicStorage<value_type,logical_type> s_;
00234
00235 };
00236
00238 template <typename ValT, typename LogT>
00239 class Expr< LogicalSparseImp<ValT,LogT> > :
00240 public LogicalSparseImp<ValT,LogT> {
00241
00242 public:
00243
00245 Expr() :
00246 LogicalSparseImp<ValT,LogT>() {}
00247
00249
00252 Expr(const ValT & x) :
00253 LogicalSparseImp<ValT,LogT>(x) {}
00254
00256
00259 Expr(const int sz, const ValT & x) :
00260 LogicalSparseImp<ValT,LogT>(sz,x) {}
00261
00263
00268 Expr(const int sz, const int i, const ValT & x) :
00269 LogicalSparseImp<ValT,LogT>(sz,i,x) {}
00270
00272 Expr(const Expr& x) :
00273 LogicalSparseImp<ValT,LogT>(x) {}
00274
00276 template <typename S> Expr(const Expr<S>& x) :
00277 LogicalSparseImp<ValT,LogT>(x) {}
00278
00280 ~Expr() {}
00281
00282 };
00283
00288 template <typename ValT, typename LogT >
00289 class LogicalSparse : public Expr< LogicalSparseImp<ValT,LogT > > {
00290
00291 public:
00292
00297
00299
00302 LogicalSparse() :
00303 Expr< LogicalSparseImp< ValT,LogT > >() {}
00304
00306
00309 LogicalSparse(const ValT& x) :
00310 Expr< LogicalSparseImp< ValT,LogT > >(x) {}
00311
00313
00316 LogicalSparse(const int sz, const ValT& x) :
00317 Expr< LogicalSparseImp< ValT,LogT > >(sz,x) {}
00318
00320
00325 LogicalSparse(const int sz, const int i, const ValT & x) :
00326 Expr< LogicalSparseImp< ValT,LogT > >(sz,i,x) {}
00327
00329 LogicalSparse(const LogicalSparse& x) :
00330 Expr< LogicalSparseImp< ValT,LogT > >(x) {}
00331
00333 template <typename S> LogicalSparse(const Expr<S>& x) :
00334 Expr< LogicalSparseImp< ValT,LogT > >(x) {}
00335
00337
00339 ~LogicalSparse() {}
00340
00342 LogicalSparse& operator=(const ValT& val) {
00343 LogicalSparseImp< ValT,LogT >::operator=(val);
00344 return *this;
00345 }
00346
00348 LogicalSparse& operator=(const LogicalSparse& x) {
00349 LogicalSparseImp< ValT,LogT >::operator=(static_cast<const LogicalSparseImp< ValT,LogT >&>(x));
00350 return *this;
00351 }
00352
00354 template <typename S> LogicalSparse& operator=(const Expr<S>& x)
00355 {
00356 LogicalSparseImp< ValT,LogT >::operator=(x);
00357 return *this;
00358 }
00359
00360 };
00361
00362 }
00363
00364 }
00365
00366 #include "Sacado_LFad_LogicalSparseImp.hpp"
00367 #include "Sacado_LFad_LogicalSparseOps.hpp"
00368
00369 #endif // SACADO_LFAD_LOGICALSPARSE_HPP