Sacado_LFad_LogicalSparse.hpp

Go to the documentation of this file.
00001 // $Id: Sacado_LFad_LogicalSparse.hpp,v 1.2 2008/06/16 21:57:46 etphipp Exp $ 
00002 // $Source: /space/CVS/Trilinos/packages/sacado/src/Sacado_LFad_LogicalSparse.hpp,v $ 
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 
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     }; // class LogicalSparseImp
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     }; // class Expr<LogicalSparseImp>
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     }; // class LogicalSparse<ValT,LogT>
00361 
00362   } // namespace LFad
00363 
00364 } // namespace Sacado
00365 
00366 #include "Sacado_LFad_LogicalSparseImp.hpp"
00367 #include "Sacado_LFad_LogicalSparseOps.hpp"
00368 
00369 #endif // SACADO_LFAD_LOGICALSPARSE_HPP

Generated on Wed May 12 21:59:04 2010 for Sacado Package Browser (Single Doxygen Collection) by  doxygen 1.4.7