|
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 // 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 #include "Sacado_dummy_arg.hpp" 00059 00060 namespace Sacado { 00061 00063 namespace CacheFad { 00064 00066 00077 template <typename T, typename Storage> 00078 class GeneralFad : public Storage { 00079 00080 public: 00081 00083 typedef T value_type; 00084 00086 typedef typename ScalarType<T>::type scalar_type; 00087 00092 00094 GeneralFad() : Storage(T(0.)), update_val_(true) {} 00095 00097 00100 GeneralFad(const T & x) : Storage(x), update_val_(true) {} 00101 00103 00106 GeneralFad(const int sz, const T & x) : 00107 Storage(sz, x), update_val_(true) {} 00108 00110 00115 GeneralFad(const int sz, const int i, const T & x) : 00116 Storage(sz, x), update_val_(true) { 00117 this->fastAccessDx(i)=1.; 00118 } 00119 00121 GeneralFad(const GeneralFad& x) : 00122 Storage(x), update_val_(x.update_val_) {} 00123 00125 template <typename S> GeneralFad(const Expr<S>& x); 00126 00128 ~GeneralFad() {} 00129 00131 00137 void diff(const int ith, const int n); 00138 00140 void setUpdateValue(bool update_val) { update_val_ = update_val; } 00141 00143 bool updateValue() const { return update_val_; } 00144 00146 void cache() const {} 00147 00149 template <typename S> 00150 bool isEqualTo(const Expr<S>& x) const { 00151 typedef IsEqual<value_type> IE; 00152 if (x.size() != this->size()) return false; 00153 bool eq = IE::eval(x.val(), this->val()); 00154 for (int i=0; i<this->size(); i++) 00155 eq = eq && IE::eval(x.dx(i), this->dx(i)); 00156 return eq; 00157 } 00158 00160 00165 00170 int availableSize() const { return this->length(); } 00171 00173 bool hasFastAccess() const { return this->size()!=0;} 00174 00176 bool isPassive() const { return this->size()==0;} 00177 00179 void setIsConstant(bool is_const) { 00180 if (is_const && this->size()!=0) 00181 this->resize(0); 00182 } 00183 00185 00190 00192 GeneralFad& operator=(const T& val); 00193 00195 GeneralFad& 00196 operator=(const GeneralFad& x); 00197 00199 template <typename S> 00200 GeneralFad& operator=(const Expr<S>& x); 00201 00203 00208 00210 GeneralFad& operator += (const T& x); 00211 00213 GeneralFad& operator -= (const T& x); 00214 00216 GeneralFad& operator *= (const T& x); 00217 00219 GeneralFad& operator /= (const T& x); 00220 00222 00226 GeneralFad& operator += (const typename dummy<value_type,scalar_type>::type& x); 00227 00229 00233 GeneralFad& operator -= (const typename dummy<value_type,scalar_type>::type& x); 00234 00236 00240 GeneralFad& operator *= (const typename dummy<value_type,scalar_type>::type& x); 00241 00243 00247 GeneralFad& operator /= (const typename dummy<value_type,scalar_type>::type& x); 00248 00250 template <typename S> 00251 GeneralFad& operator += (const Expr<S>& x); 00252 00254 template <typename S> 00255 GeneralFad& operator -= (const Expr<S>& x); 00256 00258 template <typename S> 00259 GeneralFad& operator *= (const Expr<S>& x); 00260 00262 template <typename S> 00263 GeneralFad& operator /= (const Expr<S>& x); 00264 00266 00267 protected: 00268 00270 bool update_val_; 00271 00272 }; // class GeneralFad 00273 00274 } // namespace CacheFad 00275 00276 } // namespace Sacado 00277 00278 #include "Sacado_CacheFad_GeneralFadImp.hpp" 00279 00280 #endif // SACADO_CACHEFAD_GENERALFAD_HPP
1.7.4