|
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_ELRFAD_DFADTRAITS_HPP 00052 #define SACADO_ELRFAD_DFADTRAITS_HPP 00053 00054 #include "Sacado_Traits.hpp" 00055 00056 // Forward declarations 00057 namespace Sacado { 00058 namespace ELRFad { 00059 template <typename T> class DFad; 00060 } 00061 } 00062 00063 namespace Sacado { 00064 00066 template <typename ValueT> 00067 struct Promote< ELRFad::DFad<ValueT>, ELRFad::DFad<ValueT> > { 00068 typedef ELRFad::DFad<ValueT> type; 00069 }; 00070 00072 template <typename ValueT, typename R> 00073 struct Promote< ELRFad::DFad<ValueT>, R > { 00074 typedef typename ValueType< ELRFad::DFad<ValueT> >::type value_type_l; 00075 typedef typename ValueType<R>::type value_type_r; 00076 typedef typename Promote<value_type_l,value_type_r>::type value_type; 00077 00078 typedef ELRFad::DFad<value_type> type; 00079 }; 00080 00082 template <typename L, typename ValueT> 00083 struct Promote< L, ELRFad::DFad<ValueT> > { 00084 public: 00085 00086 typedef typename ValueType<L>::type value_type_l; 00087 typedef typename ValueType< ELRFad::DFad<ValueT> >::type value_type_r; 00088 typedef typename Promote<value_type_l,value_type_r>::type value_type; 00089 00090 typedef ELRFad::DFad<value_type> type; 00091 }; 00092 00094 template <typename ValueT> 00095 struct ScalarType< ELRFad::DFad<ValueT> > { 00096 typedef typename ELRFad::DFad<ValueT>::ScalarT type; 00097 }; 00098 00100 template <typename ValueT> 00101 struct ValueType< ELRFad::DFad<ValueT> > { 00102 typedef ValueT type; 00103 }; 00104 00106 template <typename ValueT> 00107 struct IsADType< ELRFad::DFad<ValueT> > { 00108 static const bool value = true; 00109 }; 00110 00112 template <typename ValueT> 00113 struct IsScalarType< ELRFad::DFad<ValueT> > { 00114 static const bool value = false; 00115 }; 00116 00118 template <typename ValueT> 00119 struct Value< ELRFad::DFad<ValueT> > { 00120 typedef typename ValueType< ELRFad::DFad<ValueT> >::type value_type; 00121 static const value_type& eval(const ELRFad::DFad<ValueT>& x) { 00122 return x.val(); } 00123 }; 00124 00126 template <typename ValueT> 00127 struct ScalarValue< ELRFad::DFad<ValueT> > { 00128 typedef typename ValueType< ELRFad::DFad<ValueT> >::type value_type; 00129 typedef typename ScalarType< ELRFad::DFad<ValueT> >::type scalar_type; 00130 static const scalar_type& eval(const ELRFad::DFad<ValueT>& x) { 00131 return ScalarValue<value_type>::eval(x.val()); } 00132 }; 00133 00135 template <typename ValueT> 00136 struct StringName< ELRFad::DFad<ValueT> > { 00137 static std::string eval() { 00138 return std::string("Sacado::ELRFad::DFad< ") + 00139 StringName<ValueT>::eval() + " >"; } 00140 }; 00141 00143 template <typename ValueT> 00144 struct IsEqual< ELRFad::DFad<ValueT> > { 00145 static bool eval(const ELRFad::DFad<ValueT>& x, 00146 const ELRFad::DFad<ValueT>& y) { 00147 return x.isEqualTo(y); 00148 } 00149 }; 00150 00152 template <typename ValueT> 00153 struct IsStaticallySized< ELRFad::DFad<ValueT> > { 00154 static const bool value = false; 00155 }; 00156 00157 } // namespace Sacado 00158 00159 // Define Teuchos traits classes 00160 #ifdef HAVE_SACADO_TEUCHOS 00161 #include "Teuchos_PromotionTraits.hpp" 00162 #include "Teuchos_ScalarTraits.hpp" 00163 #include "Sacado_Fad_ScalarTraitsImp.hpp" 00164 00165 namespace Teuchos { 00166 00168 template <typename ValueT> 00169 struct PromotionTraits< Sacado::ELRFad::DFad<ValueT>, 00170 Sacado::ELRFad::DFad<ValueT> > { 00171 typedef typename Sacado::Promote< Sacado::ELRFad::DFad<ValueT>, 00172 Sacado::ELRFad::DFad<ValueT> >::type 00173 promote; 00174 }; 00175 00177 template <typename ValueT, typename R> 00178 struct PromotionTraits< Sacado::ELRFad::DFad<ValueT>, R > { 00179 typedef typename Sacado::Promote< Sacado::ELRFad::DFad<ValueT>, R >::type 00180 promote; 00181 }; 00182 00184 template <typename L, typename ValueT> 00185 struct PromotionTraits< L, Sacado::ELRFad::DFad<ValueT> > { 00186 public: 00187 typedef typename Sacado::Promote< L, Sacado::ELRFad::DFad<ValueT> >::type 00188 promote; 00189 }; 00190 00192 template <typename ValueT> 00193 struct ScalarTraits< Sacado::ELRFad::DFad<ValueT> > : 00194 public Sacado::Fad::ScalarTraitsImp< Sacado::ELRFad::DFad<ValueT> > 00195 {}; 00196 00198 template <typename Ordinal, typename ValueT> 00199 struct SerializationTraits<Ordinal, Sacado::ELRFad::DFad<ValueT> > : 00200 public Sacado::Fad::SerializationTraitsImp< Ordinal, 00201 Sacado::ELRFad::DFad<ValueT> > 00202 {}; 00203 00205 template <typename Ordinal, typename ValueT> 00206 struct ValueTypeSerializer<Ordinal, Sacado::ELRFad::DFad<ValueT> > : 00207 public Sacado::Fad::SerializerImp< Ordinal, 00208 Sacado::ELRFad::DFad<ValueT>, 00209 ValueTypeSerializer<Ordinal,ValueT> > 00210 { 00211 typedef Sacado::ELRFad::DFad<ValueT> FadType; 00212 typedef ValueTypeSerializer<Ordinal,ValueT> ValueSerializer; 00213 typedef Sacado::Fad::SerializerImp< Ordinal,FadType,ValueSerializer> Base; 00214 ValueTypeSerializer(const Teuchos::RCP<const ValueSerializer>& vs, 00215 Ordinal sz = 0) : 00216 Base(vs, sz) {} 00217 }; 00218 } 00219 #endif // HAVE_SACADO_TEUCHOS 00220 00221 #endif // SACADO_ELRFAD_DFADTRAITS_HPP
1.7.4