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 
00123 } // namespace Sacado
00124 
00125 // Define Teuchos traits classes
00126 #ifdef HAVE_SACADO_TEUCHOS
00127 #include "Teuchos_PromotionTraits.hpp"
00128 #include "Teuchos_ScalarTraits.hpp"
00129 #include "Sacado_Fad_ScalarTraitsImp.hpp"
00130 
00131 namespace Teuchos {
00132 
00134   template <typename ValueT>
00135   struct PromotionTraits< Sacado::Fad::DMFad<ValueT>, 
00136         Sacado::Fad::DMFad<ValueT> > {
00137     typedef typename Sacado::Promote< Sacado::Fad::DMFad<ValueT>,
00138               Sacado::Fad::DMFad<ValueT> >::type
00139     promote;
00140   };
00141 
00143   template <typename ValueT, typename R>
00144   struct PromotionTraits< Sacado::Fad::DMFad<ValueT>, R > {
00145     typedef typename Sacado::Promote< Sacado::Fad::DMFad<ValueT>, R >::type 
00146     promote;
00147   };
00148 
00150   template <typename L, typename ValueT>
00151   struct PromotionTraits< L, Sacado::Fad::DMFad<ValueT> > {
00152   public:
00153     typedef typename Sacado::Promote< L, Sacado::Fad::DMFad<ValueT> >::type 
00154     promote;
00155   };
00156 
00158   template <typename ValueT>
00159   struct ScalarTraits< Sacado::Fad::DMFad<ValueT> > :
00160     public Sacado::Fad::ScalarTraitsImp< Sacado::Fad::DMFad<ValueT> >
00161   {};
00162 }
00163 #endif // HAVE_SACADO_TEUCHOS
00164 
00165 #endif // SACADO_FAD_DMFADTRAITS_HPP
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines