Sacado Package Browser (Single Doxygen Collection) Version of the Day
Sacado_Fad_SLFadTraits.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 // @HEADER
00031 
00032 #ifndef SACADO_FAD_SLFADTRAITS_HPP
00033 #define SACADO_FAD_SLFADTRAITS_HPP
00034 
00035 #include "Sacado_Traits.hpp"
00036 #include <sstream>
00037 
00038 // Forward declarations
00039 namespace Sacado {
00040   namespace Fad {
00041     template <typename T, int Num> class SLFad;
00042   }
00043 }
00044 
00045 namespace Sacado {
00046 
00048   template <typename ValueT, int Num>
00049   struct Promote< Fad::SLFad<ValueT,Num>, 
00050       Fad::SLFad<ValueT,Num> > {
00051     typedef Fad::SLFad<ValueT,Num> type;
00052   };
00053 
00055   template <typename ValueT, int Num, typename R>
00056   struct Promote< Fad::SLFad<ValueT,Num>, R > {
00057     typedef typename ValueType< Fad::SLFad<ValueT,Num> >::type value_type_l;
00058     typedef typename ValueType<R>::type value_type_r;
00059     typedef typename Promote<value_type_l,value_type_r>::type value_type;
00060 
00061     typedef Fad::SLFad<value_type,Num> type;
00062   };
00063 
00065   template <typename L, typename ValueT, int Num>
00066   struct Promote< L, Fad::SLFad<ValueT, Num> > {
00067   public:
00068 
00069     typedef typename ValueType<L>::type value_type_l;
00070     typedef typename ValueType< Fad::SLFad<ValueT,Num> >::type value_type_r;
00071     typedef typename Promote<value_type_l,value_type_r>::type value_type;
00072 
00073     typedef Fad::SLFad<value_type,Num> type;
00074   };
00075 
00077   template <typename ValueT, int Num>
00078   struct ScalarType< Fad::SLFad<ValueT,Num> > {
00079     typedef typename Fad::SLFad<ValueT,Num>::ScalarT type;
00080   };
00081 
00083   template <typename ValueT, int Num>
00084   struct ValueType< Fad::SLFad<ValueT,Num> > {
00085     typedef ValueT type;
00086   };
00087 
00089   template <typename ValueT, int Num>
00090   struct IsADType< Fad::SLFad<ValueT,Num> > {
00091     static const bool value = true;
00092   };
00093 
00095   template <typename ValueT, int Num>
00096   struct IsScalarType< Fad::SLFad<ValueT,Num> > {
00097     static const bool value = false;
00098   };
00099 
00101   template <typename ValueT, int Num>
00102   struct Value< Fad::SLFad<ValueT,Num> > {
00103     typedef typename ValueType< Fad::SLFad<ValueT,Num> >::type value_type;
00104     static const value_type& eval(const Fad::SLFad<ValueT,Num>& x) { 
00105       return x.val(); }
00106   };
00107 
00109   template <typename ValueT, int Num>
00110   struct ScalarValue< Fad::SLFad<ValueT,Num> > {
00111     typedef typename ValueType< Fad::SLFad<ValueT,Num> >::type value_type;
00112     typedef typename ScalarType< Fad::SLFad<ValueT,Num> >::type scalar_type;
00113     static const scalar_type& eval(const Fad::SLFad<ValueT,Num>& x) { 
00114       return ScalarValue<value_type>::eval(x.val()); }
00115   };
00116 
00118   template <typename ValueT, int Num>
00119   struct StringName< Fad::SLFad<ValueT,Num> > {
00120     static std::string eval() { 
00121       std::stringstream ss;
00122       ss << "Sacado::Fad::SLFad< " 
00123    << StringName<ValueT>::eval() << ", " << Num << " >";
00124       return ss.str(); 
00125     }
00126   };
00127 
00129   template <typename ValueT, int Num>
00130   struct IsEqual< Fad::SLFad<ValueT,Num> > {
00131     static bool eval(const Fad::SLFad<ValueT,Num>& x, 
00132          const Fad::SLFad<ValueT,Num>& y) {
00133       return x.isEqualTo(y);
00134     }
00135   };
00136 
00138   template <typename ValueT, int Num>
00139   struct IsStaticallySized< Fad::SLFad<ValueT,Num> > {
00140     static const bool value = true;
00141   };
00142 
00143 } // namespace Sacado
00144 
00145 // Define Teuchos traits classes
00146 #ifdef HAVE_SACADO_TEUCHOS
00147 #include "Teuchos_PromotionTraits.hpp"
00148 #include "Teuchos_ScalarTraits.hpp"
00149 #include "Sacado_Fad_ScalarTraitsImp.hpp"
00150 
00151 namespace Teuchos {
00152 
00154   template <typename ValueT, int Num>
00155   struct PromotionTraits< Sacado::Fad::SLFad<ValueT,Num>, 
00156         Sacado::Fad::SLFad<ValueT,Num> > {
00157     typedef typename Sacado::Promote< Sacado::Fad::SLFad<ValueT,Num>,
00158               Sacado::Fad::SLFad<ValueT,Num> >::type
00159     promote;
00160   };
00161 
00163   template <typename ValueT, int Num, typename R>
00164   struct PromotionTraits< Sacado::Fad::SLFad<ValueT,Num>, R > {
00165     typedef typename Sacado::Promote< Sacado::Fad::SLFad<ValueT,Num>, R >::type 
00166     promote;
00167   };
00168 
00170   template <typename L, typename ValueT, int Num>
00171   struct PromotionTraits< L, Sacado::Fad::SLFad<ValueT,Num> > {
00172   public:
00173     typedef typename Sacado::Promote< L, Sacado::Fad::SLFad<ValueT,Num> >::type 
00174     promote;
00175   };
00176 
00178   template <typename ValueT, int Num>
00179   struct ScalarTraits< Sacado::Fad::SLFad<ValueT,Num> > :
00180     public Sacado::Fad::ScalarTraitsImp< Sacado::Fad::SLFad<ValueT,Num> >
00181   {};
00182 
00184   template <typename Ordinal, typename ValueT, int Num>
00185   struct SerializationTraits<Ordinal, Sacado::Fad::SLFad<ValueT,Num> > :
00186     public Sacado::Fad::SerializationTraitsImp< Ordinal, 
00187             Sacado::Fad::SLFad<ValueT,Num> > 
00188   {};
00189 
00191   template <typename Ordinal, typename ValueT, int Num>
00192   struct ValueTypeSerializer<Ordinal, Sacado::Fad::SLFad<ValueT,Num> > :
00193     public Sacado::Fad::SerializerImp< Ordinal, 
00194                Sacado::Fad::SLFad<ValueT,Num>,
00195                ValueTypeSerializer<Ordinal,ValueT> > 
00196   {
00197     typedef Sacado::Fad::SLFad<ValueT,Num> FadType;
00198     typedef ValueTypeSerializer<Ordinal,ValueT> ValueSerializer;
00199     typedef Sacado::Fad::SerializerImp< Ordinal,FadType,ValueSerializer> Base;
00200     ValueTypeSerializer(const Teuchos::RCP<const ValueSerializer>& vs,
00201       Ordinal sz = 0) :
00202       Base(vs, sz) {}
00203   };
00204 }
00205 #endif // HAVE_SACADO_TEUCHOS
00206 
00207 #endif // SACADO_FAD_SFADTRAITS_HPP
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines