Sacado Package Browser (Single Doxygen Collection) Version of the Day
Sacado_ELRCacheFad_Expression.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 //  A short implementation ( not all operators and 
00047 //  functions are overloaded ) of 1st order Automatic
00048 //  Differentiation in forward mode (FAD) using
00049 //  EXPRESSION TEMPLATES.
00050 //
00051 //********************************************************
00052 // @HEADER
00053 
00054 #ifndef SACADO_ELRCACHEFAD_EXPRESSION_HPP
00055 #define SACADO_ELRCACHEFAD_EXPRESSION_HPP
00056 
00057 #include "Sacado_Traits.hpp"
00058 
00059 namespace Sacado {
00060 
00061   namespace ELRCacheFad {
00062 
00064 
00068     template <typename A, typename B> struct ExprPromote {};
00069 
00071     template <typename A> struct ExprPromote<A,A> {
00072       typedef A type;
00073     };
00074 
00076 
00080     template <typename ExprT> 
00081     class Expr {};
00082 
00084 
00087     template <typename ConstT> 
00088     class ConstExpr {
00089 
00090     public:
00091 
00093       typedef ConstT value_type;
00094 
00096       typedef ConstT scalar_type;
00097 
00099       typedef ConstT base_expr_type;
00100 
00102       static const int num_args = 0;
00103 
00105       ConstExpr(const ConstT& constant) : constant_(constant) {}
00106 
00108       int size() const { return 0; }
00109 
00111       bool updateValue() const { return true; }
00112 
00114       void cache() const {}
00115 
00117       value_type val() const { return constant_; }
00118 
00120       void computePartials(const value_type& bar, 
00121          value_type partials[]) const {}
00122 
00124       void getTangents(int i, value_type dots[]) const {}
00125 
00127       template <int Arg>
00128       value_type getTangent(int i) const { return 0.0; }
00129 
00131       template <int Arg>
00132       bool isActive() const { return false; }
00133 
00134     protected:
00135       
00137       const ConstT& constant_;
00138 
00139     }; // class ConstExpr
00140 
00141     template <typename T> struct ExprConstRef {
00142       typedef const T& type;
00143     };
00144     template <typename T> struct ExprConstRef< ConstExpr<T> > {
00145       typedef const ConstExpr<T> type;
00146     };
00147 
00148   } // namespace ELRCacheFad
00149 
00150 } // namespace Sacado
00151 
00152 #endif // SACADO_ELRCACHEFAD_EXPRESSION_HPP
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines