// @HEADER // ***************************************************************************** // Sacado Package // // Copyright 2006 NTESS and the Sacado contributors. // SPDX-License-Identifier: LGPL-2.1-or-later // // *********************************************************************** // // The forward-mode AD classes in Sacado are a derivative work of the // expression template classes in the Fad package by Nicolas Di Cesare. // The following banner is included in the original Fad source code: // // ************ DO NOT REMOVE THIS BANNER **************** // // Nicolas Di Cesare // http://www.ann.jussieu.fr/~dicesare // // CEMRACS 98 : C++ courses, // templates : new C++ techniques // for scientific computing // //******************************************************** // // A short implementation ( not all operators and // functions are overloaded ) of 1st order Automatic // Differentiation in forward mode (FAD) using // EXPRESSION TEMPLATES. // //******************************************************** // @HEADER #ifndef SACADO_ELRCACHEFAD_EXPRESSION_HPP #define SACADO_ELRCACHEFAD_EXPRESSION_HPP #include "Sacado_Traits.hpp" namespace Sacado { namespace ELRCacheFad { //! Meta-function for determining concrete base expression /*! * This determines the concrete base expression type of each leaf in * an expression tree. The Promote meta-function is then used to promote * all of the leaves to a single expression type that the whole expression * can be assigned/promoted to. This allows Promote to operate on * expressions as well as AD types. */ template struct BaseExpr {}; //! Wrapper for a generic expression template /*! * This template class serves as a wrapper for all Fad expression * template classes. */ template class Expr {}; //! Meta-function for determining nesting with an expression /*! * This determines the level of nesting within nested Fad types. * The default implementation works for any type that isn't a Fad type * or an expression of Fad types. */ template struct ExprLevel { static const unsigned value = 0; }; template struct ExprLevel< Expr > { static const unsigned value = ExprLevel< typename Expr::value_type >::value + 1; }; //! Determine whether a given type is an expression template struct IsFadExpr { static const bool value = false; }; template struct IsFadExpr< Expr > { static const bool value = true; }; //! Constant expression template /*! * This template class represents a constant expression. */ template class ConstExpr { public: //! Typename of argument values typedef ConstT value_type; //! Typename of scalar's (which may be different from ConstT) typedef typename ScalarType::type scalar_type; //! Typename of base-expressions typedef ConstT base_expr_type; //! Number of arguments static const int num_args = 0; //! Constructor SACADO_INLINE_FUNCTION ConstExpr(const ConstT& constant) : constant_(constant) {} //! Return size of the derivative array of the operation SACADO_INLINE_FUNCTION int size() const { return 0; } //! Return whether value should be updated SACADO_INLINE_FUNCTION bool updateValue() const { return true; } //! Cache values SACADO_INLINE_FUNCTION void cache() const {} //! Return value of operation SACADO_INLINE_FUNCTION value_type val() const { return constant_; } //! Return partials w.r.t. arguments SACADO_INLINE_FUNCTION void computePartials(const value_type& bar, value_type partials[]) const {} //! Rturn tangent component \c i of arguments SACADO_INLINE_FUNCTION void getTangents(int i, value_type dots[]) const {} //! Return tangent component \c i of argument \c Arg template SACADO_INLINE_FUNCTION value_type getTangent(int i) const { return 0.0; } //! Return whether argument is active template SACADO_INLINE_FUNCTION bool isActive() const { return false; } //! Return whether expression is linear SACADO_INLINE_FUNCTION bool isLinear() const { return true; } protected: //! The constant const ConstT& constant_; }; // class ConstExpr template struct ExprConstRef { typedef const T& type; }; template struct ExprConstRef< ConstExpr > { typedef const ConstExpr type; }; } // namespace ELRCacheFad template struct IsExpr< ELRCacheFad::Expr > { static const bool value = true; }; template struct BaseExprType< ELRCacheFad::Expr > { typedef typename ELRCacheFad::Expr::base_expr_type type; }; } // namespace Sacado #include "Sacado_SFINAE_Macros.hpp" #endif // SACADO_ELRCACHEFAD_EXPRESSION_HPP