|
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_TRAITS_HPP 00052 #define SACADO_TRAITS_HPP 00053 00054 #include "Sacado_ConfigDefs.h" 00055 #include <string> 00056 00057 #ifdef HAVE_SACADO_COMPLEX 00058 #include <complex> 00059 #endif 00060 00061 namespace Sacado { 00062 00064 00068 template <typename A, typename B> struct Promote {}; 00069 00071 template <typename A> struct Promote<A,A> { 00072 typedef A type; 00073 }; 00074 00076 #define SACADO_PROMOTE_SPECIALIZATION(type1,type2,type3) \ 00077 template <> struct Promote< type1, type2 > { \ 00078 typedef type3 type; \ 00079 }; \ 00080 template <> struct Promote< type2, type1 > { \ 00081 typedef type3 type; \ 00082 }; 00083 00084 SACADO_PROMOTE_SPECIALIZATION(double,float,double) 00085 SACADO_PROMOTE_SPECIALIZATION(double,long,double) 00086 SACADO_PROMOTE_SPECIALIZATION(double,int,double) 00087 SACADO_PROMOTE_SPECIALIZATION(float,long,float) 00088 SACADO_PROMOTE_SPECIALIZATION(float,int,float) 00089 #ifdef HAVE_SACADO_COMPLEX 00090 SACADO_PROMOTE_SPECIALIZATION(std::complex<double>,std::complex<float>,std::complex<double>) 00091 SACADO_PROMOTE_SPECIALIZATION(std::complex<double>,double,std::complex<double>) 00092 SACADO_PROMOTE_SPECIALIZATION(std::complex<double>,float,std::complex<double>) 00093 SACADO_PROMOTE_SPECIALIZATION(std::complex<double>,long,std::complex<double>) 00094 SACADO_PROMOTE_SPECIALIZATION(std::complex<double>,int,std::complex<double>) 00095 SACADO_PROMOTE_SPECIALIZATION(std::complex<float>,float,std::complex<float>) 00096 SACADO_PROMOTE_SPECIALIZATION(std::complex<float>,long,std::complex<float>) 00097 SACADO_PROMOTE_SPECIALIZATION(std::complex<float>,int,std::complex<float>) 00098 #endif // HAVE_SACADO_COMPLEX 00099 00100 #undef SACADO_PROMOTE_SPECIALIZATION 00101 00103 00107 template <typename T> struct ScalarType {}; 00108 00110 00114 template <typename T> struct ValueType {}; 00115 00117 00121 template <typename T> struct IsADType {}; 00122 00124 00128 template <typename T> struct IsScalarType {}; 00129 00131 00134 template <typename T> struct Value {}; 00135 00137 00141 template <typename T> struct ScalarValue {}; 00142 00144 template <typename T> struct MarkConstant { 00145 static void eval(T& x) {} 00146 }; 00147 00149 template <typename T> struct StringName {}; 00150 00152 template <typename T> struct IsEqual {}; 00153 00155 template <typename T> struct IsStaticallySized {}; 00156 00158 #define SACADO_BUILTIN_SPECIALIZATION(t,NAME) \ 00159 template <> struct ScalarType< t > { \ 00160 typedef t type; \ 00161 }; \ 00162 template <> struct ValueType< t > { \ 00163 typedef t type; \ 00164 }; \ 00165 template <> struct IsADType< t > { \ 00166 static const bool value = false; \ 00167 }; \ 00168 template <> struct IsScalarType< t > { \ 00169 static const bool value = true; \ 00170 }; \ 00171 template <> struct Value< t > { \ 00172 static const t& eval(const t& x) { return x; } \ 00173 }; \ 00174 template <> struct ScalarValue< t > { \ 00175 static const t& eval(const t& x) { return x; } \ 00176 }; \ 00177 template <> struct StringName< t > { \ 00178 static std::string eval() { return NAME; } \ 00179 }; \ 00180 template <> struct IsEqual< t > { \ 00181 static bool eval(const t& x, const t& y) { \ 00182 return x == y; } \ 00183 }; \ 00184 template <> struct IsStaticallySized< t > { \ 00185 static const bool value = true; \ 00186 }; 00187 00188 SACADO_BUILTIN_SPECIALIZATION(char,"char") 00189 SACADO_BUILTIN_SPECIALIZATION(float,"float") 00190 SACADO_BUILTIN_SPECIALIZATION(double,"double") 00191 SACADO_BUILTIN_SPECIALIZATION(int,"int") 00192 SACADO_BUILTIN_SPECIALIZATION(unsigned int,"unsigned int") 00193 SACADO_BUILTIN_SPECIALIZATION(long,"long") 00194 SACADO_BUILTIN_SPECIALIZATION(unsigned long,"unsigned long") 00195 SACADO_BUILTIN_SPECIALIZATION(bool,"bool") 00196 #ifdef HAVE_SACADO_COMPLEX 00197 SACADO_BUILTIN_SPECIALIZATION(std::complex<double>,"std::complex<double>") 00198 SACADO_BUILTIN_SPECIALIZATION(std::complex<float>,"std::complex<float>") 00199 #endif 00200 00201 #undef SACADO_BUILTIN_SPECIALIZATION 00202 00203 } // namespace Sacado 00204 00205 #endif // SACADO_TRAITS_HPP
1.7.4