00001 // $Id: Sacado_CacheFad_GeneralFad.hpp,v 1.9 2007/11/14 00:18:18 etphipp Exp $ 00002 // $Source: /space/CVS/Trilinos/packages/sacado/src/Sacado_CacheFad_GeneralFad.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 // 00031 // The forward-mode AD classes in Sacado are a derivative work of the 00032 // expression template classes in the Fad package by Nicolas Di Cesare. 00033 // The following banner is included in the original Fad source code: 00034 // 00035 // ************ DO NOT REMOVE THIS BANNER **************** 00036 // 00037 // Nicolas Di Cesare <Nicolas.Dicesare@ann.jussieu.fr> 00038 // http://www.ann.jussieu.fr/~dicesare 00039 // 00040 // CEMRACS 98 : C++ courses, 00041 // templates : new C++ techniques 00042 // for scientific computing 00043 // 00044 //******************************************************** 00045 // 00046 // A short implementation ( not all operators and 00047 // functions are overloaded ) of 1st order Automatic 00048 // Differentiation in forward mode (FAD) using 00049 // EXPRESSION TEMPLATES. 00050 // 00051 //******************************************************** 00052 // @HEADER 00053 00054 #ifndef SACADO_CACHEFAD_GENERALFAD_HPP 00055 #define SACADO_CACHEFAD_GENERALFAD_HPP 00056 00057 #include "Sacado_CacheFad_Expression.hpp" 00058 00059 namespace Sacado { 00060 00062 namespace CacheFad { 00063 00065 00076 template <typename T, typename Storage> 00077 class GeneralFad { 00078 00079 public: 00080 00082 typedef T value_type; 00083 00088 00090 GeneralFad() : s_(T(0.)) {} 00091 00093 00096 GeneralFad(const T & x) : s_(x) {} 00097 00099 00102 GeneralFad(const int sz, const T & x) : s_(sz, x) {} 00103 00105 00110 GeneralFad(const int sz, const int i, const T & x) : 00111 s_(sz, x) { 00112 s_.dx_[i]=1.; 00113 } 00114 00116 GeneralFad(const GeneralFad& x) : 00117 s_(x.s_) {} 00118 00120 template <typename S> GeneralFad(const Expr<S>& x); 00121 00123 ~GeneralFad() {} 00124 00126 00132 void diff(const int ith, const int n); 00133 00135 00140 void resize(int sz) { s_.resize(sz); } 00141 00143 void zero() { s_.zero(); } 00144 00146 00151 00153 const T& val() const { return s_.val_;} 00154 00156 T& val() { return s_.val_;} 00157 00159 00164 00166 int size() const { return s_.size();} 00167 00169 bool hasFastAccess() const { return s_.size()!=0;} 00170 00172 bool isPassive() const { return s_.size()!=0;} 00173 00175 void setIsConstant(bool is_const) { 00176 if (is_const && s_.size()!=0) 00177 s_.resize(0); 00178 } 00179 00181 const T* dx() const { return &(s_.dx_[0]);} 00182 00184 T dx(int i) const { 00185 return s_.size() ? s_.dx_[i] : T(0.); } 00186 00188 T& fastAccessDx(int i) { return s_.dx_[i];} 00189 00191 const T& fastAccessDx(int i) const { return s_.dx_[i];} 00192 00194 00199 00201 GeneralFad& operator=(const T& val); 00202 00204 GeneralFad& 00205 operator=(const GeneralFad& x); 00206 00208 template <typename S> 00209 GeneralFad& operator=(const Expr<S>& x); 00210 00212 00217 00219 GeneralFad& operator += (const T& x); 00220 00222 GeneralFad& operator -= (const T& x); 00223 00225 GeneralFad& operator *= (const T& x); 00226 00228 GeneralFad& operator /= (const T& x); 00229 00231 template <typename S> 00232 GeneralFad& operator += (const Expr<S>& x); 00233 00235 template <typename S> 00236 GeneralFad& operator -= (const Expr<S>& x); 00237 00239 template <typename S> 00240 GeneralFad& operator *= (const Expr<S>& x); 00241 00243 template <typename S> 00244 GeneralFad& operator /= (const Expr<S>& x); 00245 00247 00248 protected: 00249 00251 Storage s_; 00252 00253 }; // class GeneralFad 00254 00255 } // namespace CacheFad 00256 00257 } // namespace Sacado 00258 00259 #include "Sacado_CacheFad_GeneralFadImp.hpp" 00260 00261 #endif // SACADO_CACHEFAD_GENERALFAD_HPP
1.4.7