00001 // $Id: Sacado_Fad_GeneralFad.hpp,v 1.9.2.3 2007/08/14 00:19:06 etphipp Exp $ 00002 // $Source: /space/CVS/Trilinos/packages/sacado/src/Sacado_Fad_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_FAD_GENERALFAD_HPP 00055 #define SACADO_FAD_GENERALFAD_HPP 00056 00057 #include "Sacado_Fad_Expression.hpp" 00058 00059 namespace Sacado { 00060 00062 namespace Fad { 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 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 }; // class GeneralFad 00248 00249 } // namespace Fad 00250 00251 } // namespace Sacado 00252 00253 #include "Sacado_Fad_GeneralFadImp.hpp" 00254 00255 #endif // SACADO_FAD_GENERALFAD_HPP
1.4.7