Sacado Package Browser (Single Doxygen Collection) Version of the Day
Sacado_ELRFad_SFadTraits.hpp
Go to the documentation of this file.
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_SFADTRAITS_HPP
00052 #define SACADO_ELRFAD_SFADTRAITS_HPP
00053 
00054 #include "Sacado_Traits.hpp"
00055 #include <sstream>
00056 
00057 // Forward declarations
00058 namespace Sacado {
00059   namespace ELRFad {
00060     template <typename T, int Num> class SFad;
00061   }
00062 }
00063 
00064 namespace Sacado {
00065 
00067   template <typename ValueT, int Num>
00068   struct Promote< ELRFad::SFad<ValueT,Num>, 
00069       ELRFad::SFad<ValueT,Num> > {
00070     typedef ELRFad::SFad<ValueT,Num> type;
00071   };
00072 
00074   template <typename ValueT, int Num, typename R>
00075   struct Promote< ELRFad::SFad<ValueT,Num>, R > {
00076     typedef typename ValueType< ELRFad::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 ELRFad::SFad<value_type,Num> type;
00081   };
00082 
00084   template <typename L, typename ValueT, int Num>
00085   struct Promote< L, ELRFad::SFad<ValueT, Num> > {
00086   public:
00087 
00088     typedef typename ValueType<L>::type value_type_l;
00089     typedef typename ValueType< ELRFad::SFad<ValueT,Num> >::type value_type_r;
00090     typedef typename Promote<value_type_l,value_type_r>::type value_type;
00091 
00092     typedef ELRFad::SFad<value_type,Num> type;
00093   };
00094 
00096   template <typename ValueT, int Num>
00097   struct ScalarType< ELRFad::SFad<ValueT,Num> > {
00098     typedef typename ELRFad::SFad<ValueT,Num>::ScalarT type;
00099   };
00100 
00102   template <typename ValueT, int Num>
00103   struct ValueType< ELRFad::SFad<ValueT,Num> > {
00104     typedef ValueT type;
00105   };
00106 
00108   template <typename ValueT, int Num>
00109   struct IsADType< ELRFad::SFad<ValueT,Num> > {
00110     static const bool value = true;
00111   };
00112 
00114   template <typename ValueT, int Num>
00115   struct IsScalarType< ELRFad::SFad<ValueT,Num> > {
00116     static const bool value = false;
00117   };
00118 
00120   template <typename ValueT, int Num>
00121   struct Value< ELRFad::SFad<ValueT,Num> > {
00122     typedef typename ValueType< ELRFad::SFad<ValueT,Num> >::type value_type;
00123     static const value_type& eval(const ELRFad::SFad<ValueT,Num>& x) { 
00124       return x.val(); }
00125   };
00126 
00128   template <typename ValueT, int Num>
00129   struct ScalarValue< ELRFad::SFad<ValueT,Num> > {
00130     typedef typename ValueType< ELRFad::SFad<ValueT,Num> >::type value_type;
00131     typedef typename ScalarType< ELRFad::SFad<ValueT,Num> >::type scalar_type;
00132     static const scalar_type& eval(const ELRFad::SFad<ValueT,Num>& x) { 
00133       return ScalarValue<value_type>::eval(x.val()); }
00134   };
00135 
00137   template <typename ValueT, int Num>
00138   struct StringName< ELRFad::SFad<ValueT,Num> > {
00139     static std::string eval() { 
00140       std::stringstream ss;
00141       ss << "Sacado::ELRFad::SFad< " 
00142    << StringName<ValueT>::eval() << ", " << Num << " >";
00143       return ss.str(); 
00144     }
00145   };
00146 
00147 } // namespace Sacado
00148 
00149 // Define Teuchos traits classes
00150 #ifdef HAVE_SACADO_TEUCHOS
00151 #include "Teuchos_PromotionTraits.hpp"
00152 #include "Teuchos_ScalarTraits.hpp"
00153 #include "Sacado_Fad_ScalarTraitsImp.hpp"
00154 
00155 namespace Teuchos {
00156 
00158   template <typename ValueT, int Num>
00159   struct PromotionTraits< Sacado::ELRFad::SFad<ValueT,Num>, 
00160         Sacado::ELRFad::SFad<ValueT,Num> > {
00161     typedef typename Sacado::Promote< Sacado::ELRFad::SFad<ValueT,Num>,
00162               Sacado::ELRFad::SFad<ValueT,Num> >::type
00163     promote;
00164   };
00165 
00167   template <typename ValueT, int Num, typename R>
00168   struct PromotionTraits< Sacado::ELRFad::SFad<ValueT,Num>, R > {
00169     typedef typename Sacado::Promote< Sacado::ELRFad::SFad<ValueT,Num>,
00170               R >::type 
00171     promote;
00172   };
00173 
00175   template <typename L, typename ValueT, int Num>
00176   struct PromotionTraits< L, Sacado::ELRFad::SFad<ValueT,Num> > {
00177   public:
00178     typedef typename Sacado::Promote< L, 
00179               Sacado::ELRFad::SFad<ValueT,Num> >::type 
00180     promote;
00181   };
00182 
00184   template <typename ValueT, int Num>
00185   struct ScalarTraits< Sacado::ELRFad::SFad<ValueT,Num> > :
00186     public Sacado::Fad::ScalarTraitsImp< Sacado::ELRFad::SFad<ValueT,Num> >
00187   {};
00188 }
00189 #endif // HAVE_SACADO_TEUCHOS
00190 
00191 #endif // SACADO_ELRFAD_SFADTRAITS_HPP
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines