|
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 // NumericalTraits class to illustrate TRAITS 00047 // 00048 //******************************************************** 00049 // @HEADER 00050 00051 #ifndef SACADO_ELRCACHEFAD_SFADTRAITS_HPP 00052 #define SACADO_ELRCACHEFAD_SFADTRAITS_HPP 00053 00054 #include "Sacado_Traits.hpp" 00055 #include <sstream> 00056 00057 // Forward declarations 00058 namespace Sacado { 00059 namespace ELRCacheFad { 00060 template <typename T, int Num> class SFad; 00061 } 00062 } 00063 00064 namespace Sacado { 00065 00067 template <typename ValueT, int Num> 00068 struct Promote< ELRCacheFad::SFad<ValueT,Num>, 00069 ELRCacheFad::SFad<ValueT,Num> > { 00070 typedef ELRCacheFad::SFad<ValueT,Num> type; 00071 }; 00072 00074 template <typename ValueT, int Num, typename R> 00075 struct Promote< ELRCacheFad::SFad<ValueT,Num>, R > { 00076 typedef typename ValueType< ELRCacheFad::SFad<ValueT,Num> >::type value_type_l; 00077 typedef typename ValueType<R>::type value_type_r; 00078 typedef typename Promote<value_type_l,value_type_r>::type value_type; 00079 00080 typedef ELRCacheFad::SFad<value_type,Num> type; 00081 }; 00082 00084 template <typename L, typename ValueT, int Num> 00085 struct Promote< L, ELRCacheFad::SFad<ValueT, Num> > { 00086 public: 00087 00088 typedef typename ValueType<L>::type value_type_l; 00089 typedef typename ValueType< ELRCacheFad::SFad<ValueT,Num> >::type value_type_r; 00090 typedef typename Promote<value_type_l,value_type_r>::type value_type; 00091 00092 typedef ELRCacheFad::SFad<value_type,Num> type; 00093 }; 00094 00096 template <typename ValueT, int Num> 00097 struct ScalarType< ELRCacheFad::SFad<ValueT,Num> > { 00098 typedef typename ELRCacheFad::SFad<ValueT,Num>::ScalarT type; 00099 }; 00100 00102 template <typename ValueT, int Num> 00103 struct ValueType< ELRCacheFad::SFad<ValueT,Num> > { 00104 typedef ValueT type; 00105 }; 00106 00108 template <typename ValueT, int Num> 00109 struct IsADType< ELRCacheFad::SFad<ValueT,Num> > { 00110 static const bool value = true; 00111 }; 00112 00114 template <typename ValueT, int Num> 00115 struct IsScalarType< ELRCacheFad::SFad<ValueT,Num> > { 00116 static const bool value = false; 00117 }; 00118 00120 template <typename ValueT, int Num> 00121 struct Value< ELRCacheFad::SFad<ValueT,Num> > { 00122 typedef typename ValueType< ELRCacheFad::SFad<ValueT,Num> >::type value_type; 00123 static const value_type& eval(const ELRCacheFad::SFad<ValueT,Num>& x) { 00124 return x.val(); } 00125 }; 00126 00128 template <typename ValueT, int Num> 00129 struct ScalarValue< ELRCacheFad::SFad<ValueT,Num> > { 00130 typedef typename ValueType< ELRCacheFad::SFad<ValueT,Num> >::type value_type; 00131 typedef typename ScalarType< ELRCacheFad::SFad<ValueT,Num> >::type scalar_type; 00132 static const scalar_type& eval(const ELRCacheFad::SFad<ValueT,Num>& x) { 00133 return ScalarValue<value_type>::eval(x.val()); } 00134 }; 00135 00137 template <typename ValueT, int Num> 00138 struct StringName< ELRCacheFad::SFad<ValueT,Num> > { 00139 static std::string eval() { 00140 std::stringstream ss; 00141 ss << "Sacado::ELRCacheFad::SFad< " 00142 << StringName<ValueT>::eval() << ", " << Num << " >"; 00143 return ss.str(); 00144 } 00145 }; 00146 00148 template <typename ValueT, int Num> 00149 struct IsEqual< ELRCacheFad::SFad<ValueT,Num> > { 00150 static bool eval(const ELRCacheFad::SFad<ValueT,Num>& x, 00151 const ELRCacheFad::SFad<ValueT,Num>& y) { 00152 return x.isEqualTo(y); 00153 } 00154 }; 00155 00157 template <typename ValueT, int Num> 00158 struct IsStaticallySized< ELRCacheFad::SFad<ValueT,Num> > { 00159 static const bool value = true; 00160 }; 00161 00162 } // namespace Sacado 00163 00164 // Define Teuchos traits classes 00165 #ifdef HAVE_SACADO_TEUCHOS 00166 #include "Teuchos_PromotionTraits.hpp" 00167 #include "Teuchos_ScalarTraits.hpp" 00168 #include "Sacado_Fad_ScalarTraitsImp.hpp" 00169 00170 namespace Teuchos { 00171 00173 template <typename ValueT, int Num> 00174 struct PromotionTraits< Sacado::ELRCacheFad::SFad<ValueT,Num>, 00175 Sacado::ELRCacheFad::SFad<ValueT,Num> > { 00176 typedef typename Sacado::Promote< Sacado::ELRCacheFad::SFad<ValueT,Num>, 00177 Sacado::ELRCacheFad::SFad<ValueT,Num> >::type 00178 promote; 00179 }; 00180 00182 template <typename ValueT, int Num, typename R> 00183 struct PromotionTraits< Sacado::ELRCacheFad::SFad<ValueT,Num>, R > { 00184 typedef typename Sacado::Promote< Sacado::ELRCacheFad::SFad<ValueT,Num>, 00185 R >::type 00186 promote; 00187 }; 00188 00190 template <typename L, typename ValueT, int Num> 00191 struct PromotionTraits< L, Sacado::ELRCacheFad::SFad<ValueT,Num> > { 00192 public: 00193 typedef typename Sacado::Promote< L, 00194 Sacado::ELRCacheFad::SFad<ValueT,Num> >::type 00195 promote; 00196 }; 00197 00199 template <typename ValueT, int Num> 00200 struct ScalarTraits< Sacado::ELRCacheFad::SFad<ValueT,Num> > : 00201 public Sacado::Fad::ScalarTraitsImp< Sacado::ELRCacheFad::SFad<ValueT,Num> > 00202 {}; 00203 00205 template <typename Ordinal, typename ValueT, int Num> 00206 struct SerializationTraits<Ordinal, Sacado::ELRCacheFad::SFad<ValueT,Num> > : 00207 public Sacado::Fad::SerializationTraitsImp< Ordinal, 00208 Sacado::ELRCacheFad::SFad<ValueT,Num> > 00209 {}; 00210 00212 template <typename Ordinal, typename ValueT, int Num> 00213 struct ValueTypeSerializer<Ordinal, Sacado::ELRCacheFad::SFad<ValueT,Num> > : 00214 public Sacado::Fad::SerializerImp< Ordinal, 00215 Sacado::ELRCacheFad::SFad<ValueT,Num>, 00216 ValueTypeSerializer<Ordinal,ValueT> > 00217 { 00218 typedef Sacado::ELRCacheFad::SFad<ValueT,Num> FadType; 00219 typedef ValueTypeSerializer<Ordinal,ValueT> ValueSerializer; 00220 typedef Sacado::Fad::SerializerImp< Ordinal,FadType,ValueSerializer> Base; 00221 ValueTypeSerializer(const Teuchos::RCP<const ValueSerializer>& vs, 00222 Ordinal sz = 0) : 00223 Base(vs, sz) {} 00224 }; 00225 } 00226 #endif // HAVE_SACADO_TEUCHOS 00227 00228 #endif // SACADO_ELRCACHEFAD_SFADTRAITS_HPP
1.7.4