Sacado Package Browser (Single Doxygen Collection) Version of the Day
Sacado_trad2_Traits.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_TRAD2_TRAITS_HPP
00033 #define SACADO_TRAD2_TRAITS_HPP
00034 
00035 #include "Sacado_Traits.hpp"
00036 
00037 // Forward declarations
00038 namespace Sacado {
00039   namespace Rad2 {
00040     template <typename T> class ADvar;
00041     template <typename T> class ADvari;
00042   }
00043 }
00044 
00045 namespace Sacado {
00046 
00048   template <typename T>
00049   class Promote< Rad2::ADvar<T>, Rad2::ADvar<T> > {
00050   public:
00051 
00052     typedef Rad2::ADvar<T> type;
00053   };
00054 
00056   template <typename L, typename R>
00057   class Promote< Rad2::ADvar<L>, R > {
00058   public:
00059 
00060     typedef typename ValueType< Rad2::ADvar<L> >::type value_type_l;
00061     typedef typename ValueType<R>::type value_type_r;
00062     typedef typename Promote<value_type_l,value_type_r>::type value_type;
00063 
00064     typedef Rad2::ADvar<value_type> type;
00065   };
00066 
00068   template <typename L, typename R>
00069   class Promote< L, Rad2::ADvar<R> > {
00070   public:
00071 
00072     typedef typename ValueType<L>::type value_type_l;
00073     typedef typename ValueType< Rad2::ADvar<R> >::type value_type_r;
00074     typedef typename Promote<value_type_l,value_type_r>::type value_type;
00075 
00076     typedef Rad2::ADvar<value_type> type;
00077   };
00078 
00080   template <typename T>
00081   struct ScalarType< Rad2::ADvar<T> > {
00082     typedef typename ScalarType<T>::type type;
00083   };
00084 
00086   template <typename T>
00087   struct ScalarType< Rad2::ADvari<T> > {
00088     typedef typename ScalarType<T>::type type;
00089   };
00090 
00092   template <typename T>
00093   struct ValueType< Rad2::ADvar<T> > {
00094     typedef T type;
00095   };
00096 
00098   template <typename T>
00099   struct ValueType< Rad2::ADvari<T> > {
00100     typedef T type;
00101   };
00102 
00104   template <typename T>
00105   struct IsADType< Rad2::ADvar<T> > {
00106     static const bool value = true;
00107   };
00108 
00110   template <typename T>
00111   struct IsADType< Rad2::ADvari<T> > {
00112     static const bool value = true;
00113   };
00114 
00116   template <typename T>
00117   struct IsScalarType< Rad2::ADvar<T> > {
00118     static const bool value = false;
00119   };
00120 
00122   template <typename T>
00123   struct IsScalarType< Rad2::ADvari<T> > {
00124     static const bool value = false;
00125   };
00126 
00128   template <typename T>
00129   struct Value< Rad2::ADvar<T> > {
00130     typedef typename ValueType< Rad2::ADvar<T> >::type value_type;
00131     static value_type eval(const Rad2::ADvar<T>& x) { 
00132       return x.val(); }
00133   };
00134 
00136   template <typename T> 
00137   struct MarkConstant< Rad2::ADvar<T> > {
00138     static void eval(Rad2::ADvar<T>& x) { AD_Const(x); }
00139   };
00140 
00142   template <typename T> 
00143   struct MarkConstant< Rad2::ADvari<T> > {
00144     static void eval(Rad2::ADvari<T>& x) { AD_Const(x); }
00145   };
00146 
00148   template <typename T>
00149   struct ScalarValue< Rad2::ADvar<T> > {
00150     typedef typename ValueType< Rad2::ADvar<T> >::type value_type;
00151     typedef typename ScalarType< Rad2::ADvar<T> >::type scalar_type;
00152     static scalar_type eval(const Rad2::ADvar<T>& x) { 
00153       return ScalarValue<value_type>::eval(x.val()); }
00154   };
00155 
00157   template <typename T>
00158   struct StringName< Rad2::ADvar<T> > {
00159     static std::string eval() { 
00160       return std::string("Sacado::Rad2::ADvar< ") + 
00161   StringName<T>::eval() + " >"; }
00162   };
00163 
00164 } // namespace Sacado
00165 
00166 #endif // SACADO_TRAD_TRAITS_HPP
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines