|
Sacado Package Browser (Single Doxygen Collection) Version of the Day
|
00001 // $Id$ 00002 // $Source$ 00003 // @HEADER 00004 // *********************************************************************** 00005 // 00006 // Sacado Package 00007 // Copyright (2006) Sandia Corporation 00008 // 00009 // Under the terms of Contract DE-AC04-94AL85000 with Sandia Corporation, 00010 // the U.S. Government retains certain rights in this software. 00011 // 00012 // This library is free software; you can redistribute it and/or modify 00013 // it under the terms of the GNU Lesser General Public License as 00014 // published by the Free Software Foundation; either version 2.1 of the 00015 // License, or (at your option) any later version. 00016 // 00017 // This library is distributed in the hope that it will be useful, but 00018 // WITHOUT ANY WARRANTY; without even the implied warranty of 00019 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00020 // Lesser General Public License for more details. 00021 // 00022 // You should have received a copy of the GNU Lesser General Public 00023 // License along with this library; if not, write to the Free Software 00024 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 00025 // USA 00026 // Questions? Contact David M. Gay (dmgay@sandia.gov) or Eric T. Phipps 00027 // (etphipp@sandia.gov). 00028 // 00029 // *********************************************************************** 00030 // @HEADER 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 public Fad::DynamicStorage<ValT,LogT> { 00058 00059 typedef Fad::DynamicStorage<ValT,LogT> Storage; 00060 00061 public: 00062 00064 typedef ValT value_type; 00065 00067 typedef LogT logical_type; 00068 00073 00075 LogicalSparseImp() : Storage(value_type(0)) {} 00076 00078 00081 LogicalSparseImp(const value_type & x) : Storage(x) {} 00082 00084 00087 LogicalSparseImp(const int sz, const value_type & x) : Storage(sz, x) {} 00088 00090 00095 LogicalSparseImp(const int sz, const int i, const value_type & x) : 00096 Storage(sz, x) { 00097 this->fastAccessDx(i)=logical_type(1); 00098 } 00099 00101 LogicalSparseImp(const LogicalSparseImp& x) : 00102 Storage(x) {} 00103 00105 template <typename S> LogicalSparseImp(const Expr<S>& x); 00106 00108 ~LogicalSparseImp() {} 00109 00111 00117 void diff(const int ith, const int n); 00118 00120 template <typename S> 00121 bool isEqualTo(const Expr<S>& x) const { 00122 typedef IsEqual<value_type> IE; 00123 if (x.size() != this->size()) return false; 00124 bool eq = IE::eval(x.val(), this->val()); 00125 for (int i=0; i<this->size(); i++) 00126 eq = eq && IE::eval(x.dx(i), this->dx(i)); 00127 return eq; 00128 } 00129 00131 00136 00138 bool hasFastAccess() const { return this->size()!=0;} 00139 00141 bool isPassive() const { return this->size()!=0;} 00142 00144 void setIsConstant(bool is_const) { 00145 if (is_const && this->size()!=0) 00146 this->resize(0); 00147 } 00148 00150 00155 00157 LogicalSparseImp& operator=(const value_type& val); 00158 00160 LogicalSparseImp& 00161 operator=(const LogicalSparseImp& x); 00162 00164 template <typename S> 00165 LogicalSparseImp& operator=(const Expr<S>& x); 00166 00168 00173 00175 LogicalSparseImp& operator += (const value_type& x); 00176 00178 LogicalSparseImp& operator -= (const value_type& x); 00179 00181 LogicalSparseImp& operator *= (const value_type& x); 00182 00184 LogicalSparseImp& operator /= (const value_type& x); 00185 00187 template <typename S> 00188 LogicalSparseImp& operator += (const Expr<S>& x); 00189 00191 template <typename S> 00192 LogicalSparseImp& operator -= (const Expr<S>& x); 00193 00195 template <typename S> 00196 LogicalSparseImp& operator *= (const Expr<S>& x); 00197 00199 template <typename S> 00200 LogicalSparseImp& operator /= (const Expr<S>& x); 00201 00203 00204 }; // class LogicalSparseImp 00205 00207 template <typename ValT, typename LogT> 00208 class Expr< LogicalSparseImp<ValT,LogT> > : 00209 public LogicalSparseImp<ValT,LogT> { 00210 00211 public: 00212 00214 Expr() : 00215 LogicalSparseImp<ValT,LogT>() {} 00216 00218 00221 Expr(const ValT & x) : 00222 LogicalSparseImp<ValT,LogT>(x) {} 00223 00225 00228 Expr(const int sz, const ValT & x) : 00229 LogicalSparseImp<ValT,LogT>(sz,x) {} 00230 00232 00237 Expr(const int sz, const int i, const ValT & x) : 00238 LogicalSparseImp<ValT,LogT>(sz,i,x) {} 00239 00241 Expr(const Expr& x) : 00242 LogicalSparseImp<ValT,LogT>(x) {} 00243 00245 template <typename S> Expr(const Expr<S>& x) : 00246 LogicalSparseImp<ValT,LogT>(x) {} 00247 00249 ~Expr() {} 00250 00251 }; // class Expr<LogicalSparseImp> 00252 00257 template <typename ValT, typename LogT > 00258 class LogicalSparse : public Expr< LogicalSparseImp<ValT,LogT > > { 00259 00260 public: 00261 00263 template <typename T, typename U = LogT> 00264 struct apply { 00265 typedef LogicalSparse<T,U> type; 00266 }; 00267 00272 00274 00277 LogicalSparse() : 00278 Expr< LogicalSparseImp< ValT,LogT > >() {} 00279 00281 00284 LogicalSparse(const ValT& x) : 00285 Expr< LogicalSparseImp< ValT,LogT > >(x) {} 00286 00288 00291 LogicalSparse(const int sz, const ValT& x) : 00292 Expr< LogicalSparseImp< ValT,LogT > >(sz,x) {} 00293 00295 00300 LogicalSparse(const int sz, const int i, const ValT & x) : 00301 Expr< LogicalSparseImp< ValT,LogT > >(sz,i,x) {} 00302 00304 LogicalSparse(const LogicalSparse& x) : 00305 Expr< LogicalSparseImp< ValT,LogT > >(x) {} 00306 00308 template <typename S> LogicalSparse(const Expr<S>& x) : 00309 Expr< LogicalSparseImp< ValT,LogT > >(x) {} 00310 00312 00314 ~LogicalSparse() {} 00315 00317 LogicalSparse& operator=(const ValT& v) { 00318 LogicalSparseImp< ValT,LogT >::operator=(v); 00319 return *this; 00320 } 00321 00323 LogicalSparse& operator=(const LogicalSparse& x) { 00324 LogicalSparseImp< ValT,LogT >::operator=(static_cast<const LogicalSparseImp< ValT,LogT >&>(x)); 00325 return *this; 00326 } 00327 00329 template <typename S> LogicalSparse& operator=(const Expr<S>& x) 00330 { 00331 LogicalSparseImp< ValT,LogT >::operator=(x); 00332 return *this; 00333 } 00334 00335 }; // class LogicalSparse<ValT,LogT> 00336 00337 } // namespace LFad 00338 00339 } // namespace Sacado 00340 00341 #include "Sacado_LFad_LogicalSparseImp.hpp" 00342 #include "Sacado_LFad_LogicalSparseOps.hpp" 00343 00344 #endif // SACADO_LFAD_LOGICALSPARSE_HPP
1.7.4