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