SundanceStdMathFunctors.hpp
Go to the documentation of this file.
00001 /* @HEADER@ */
00002 // ************************************************************************
00003 // 
00004 //                              Sundance
00005 //                 Copyright (2005) Sandia Corporation
00006 // 
00007 // Copyright (year first published) Sandia Corporation.  Under the terms 
00008 // of Contract DE-AC04-94AL85000 with Sandia Corporation, the U.S. Government 
00009 // retains certain rights in this software.
00010 // 
00011 // This library is free software; you can redistribute it and/or modify
00012 // it under the terms of the GNU Lesser General Public License as
00013 // published by the Free Software Foundation; either version 2.1 of the
00014 // License, or (at your option) any later version.
00015 //  
00016 // This library is distributed in the hope that it will be useful, but
00017 // WITHOUT ANY WARRANTY; without even the implied warranty of
00018 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00019 // Lesser General Public License for more details.
00020 //                                                                                 
00021 // You should have received a copy of the GNU Lesser General Public
00022 // License along with this library; if not, write to the Free Software
00023 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
00024 // USA                                                                                
00025 // Questions? Contact Kevin Long (krlong@sandia.gov), 
00026 // Sandia National Laboratories, Livermore, California, USA
00027 // 
00028 // ************************************************************************
00029 /* @HEADER@ */
00030 
00031 #ifndef SUNDANCE_STDMATHFUNCTORS_H
00032 #define SUNDANCE_STDMATHFUNCTORS_H
00033 
00034 #include "SundanceDefs.hpp"
00035 #include "SundanceExceptions.hpp"
00036 #include "SundanceUnaryFunctor.hpp"
00037 #ifdef _MSC_VER
00038 # include "winmath.h"
00039 #endif
00040 
00041 #ifndef DOXYGEN_DEVELOPER_ONLY
00042 
00043 namespace Sundance
00044 {
00045   using namespace Teuchos;
00046 
00047   /** */
00048   class PowerFunctor : public UnaryFunctor
00049   {
00050   public:
00051     /** */
00052     PowerFunctor(const double& p);
00053     
00054     /** Evaluate power function and deriv at an array of values */ 
00055     virtual void eval1(const double* const x, 
00056               int nx, 
00057               double* f, 
00058               double* df) const ;
00059     /** Evaluate power function at an array of values */ 
00060     virtual void eval0(const double* const x, int nx, double* f) const ;
00061 
00062     /** Evaluate power function and first two derivs at an array of values */
00063     virtual void eval2(const double* const x, 
00064                       int nx, 
00065                       double* f, 
00066                       double* df_dx,
00067                       double* d2f_dxx) const ;
00068 
00069     /** Evaluate power function and first three derivs at an array of values */
00070     virtual void eval3(const double* const x, 
00071                       int nx, 
00072                       double* f, 
00073                       double* df_dx,
00074                       double* d2f_dxx,
00075                       double* d3f_dxxx) const ;
00076 
00077   private:
00078     double p_;
00079   };
00080 
00081 
00082   
00083   
00084 
00085   SUNDANCE_UNARY_FUNCTOR(reciprocal, StdReciprocal, "reciprocal function", 
00086                          NonzeroDomain(), 1.0/x[i], -f[i]*f[i], -2.0*df[i]/x[i])
00087 
00088     SUNDANCE_UNARY_FUNCTOR(fabs, StdFabs, "absolute value", UnboundedDomain(), ::fabs(x[i]), ((x[i]>=0.0) ? x[i] : -x[i]), 0.0)
00089 
00090   SUNDANCE_UNARY_FUNCTOR(sign, StdSign, "sign function", UnboundedDomain(), 
00091                          ((x[i]>0.0) ? 1.0 : ( (x[i]<0.0) ? -1.0 : 0.0)), 
00092                          0.0, 0.0)
00093 
00094     SUNDANCE_UNARY_FUNCTOR3(exp, StdExp, "exponential function", UnboundedDomain(), ::exp(x[i]), f[i], f[i], f[i])
00095 
00096     SUNDANCE_UNARY_FUNCTOR3(log, StdLog, "logarithm", PositiveDomain(), ::log(x[i]), 1.0/x[i], -df[i]*df[i], -2.0*d2f[i]*df[i])
00097 
00098   SUNDANCE_UNARY_FUNCTOR(sqrt, StdSqrt, "square root", PositiveDomain(), ::sqrt(x[i]), 0.5/f[i], -0.5*df[i]/x[i])
00099 
00100     SUNDANCE_UNARY_FUNCTOR3(sin, StdSin, "sine function", UnboundedDomain(), ::sin(x[i]), ::cos(x[i]), -f[i], -df[i])
00101 
00102     SUNDANCE_UNARY_FUNCTOR3(cos, StdCos, "cosine function", UnboundedDomain(), ::cos(x[i]), -::sin(x[i]), -f[i], -df[i])
00103 
00104   SUNDANCE_UNARY_FUNCTOR(tan, StdTan, "tangent function", UnboundedDomain(),
00105                          ::tan(x[i]), 1.0 + f[i]*f[i], 2.0*f[i]*df[i])
00106 
00107   SUNDANCE_UNARY_FUNCTOR(asin, StdASin, "inverse sine", 
00108                          BoundedDomain(-1.0, 1.0),
00109                          ::asin(x[i]), 1.0/::sqrt(1.0-x[i]*x[i]),
00110                          x[i]*df[i]*df[i]*df[i])
00111 
00112   SUNDANCE_UNARY_FUNCTOR(acos, StdACos, "inverse cosine",
00113                          BoundedDomain(-1.0, 1.0), 
00114                          ::acos(x[i]), -1.0/::sqrt(1.0-x[i]*x[i]),
00115                          x[i]*df[i]*df[i]*df[i])
00116 
00117   SUNDANCE_UNARY_FUNCTOR(atan, StdATan, "inverse tangent", 
00118                          UnboundedDomain(),
00119                          ::atan(x[i]), 1.0/(1.0 + x[i]*x[i]),
00120                          -2.0*x[i]*df[i]*df[i])
00121 
00122   SUNDANCE_UNARY_FUNCTOR(sinh, StdSinh, "hyperbolic sine",
00123                          UnboundedDomain(),
00124                          ::sinh(x[i]), ::cosh(x[i]), f[i])
00125 
00126   SUNDANCE_UNARY_FUNCTOR(cosh, StdCosh, "hyperbolic cosine",
00127                          UnboundedDomain(),
00128                          ::cosh(x[i]), ::sinh(x[i]), f[i])
00129 
00130   SUNDANCE_UNARY_FUNCTOR(tanh, StdTanh, "hyperbolic tangent",
00131                          UnboundedDomain(),
00132                          ::tanh(x[i]), 1.0 - f[i]*f[i], -2.0*f[i]*df[i])
00133 
00134   SUNDANCE_UNARY_FUNCTOR(asinh, StdASinh, "inverse hyperbolic sine",
00135                          UnboundedDomain(),
00136                          ::asinh(x[i]), 1.0/::sqrt(1.0 + x[i]*x[i]),
00137                          -x[i]*df[i]*df[i]*df[i])
00138 
00139   SUNDANCE_UNARY_FUNCTOR(acosh, StdACosh, "inverse hyperbolic cosine",
00140                          LowerBoundedDomain(1.0),
00141                          ::acosh(x[i]), 1.0/::sqrt(x[i]*x[i]-1.0),
00142                          -x[i]*df[i]*df[i]*df[i])
00143 
00144   SUNDANCE_UNARY_FUNCTOR(atanh, StdATanh, "inverse hyperbolic tangent",
00145                          BoundedDomain(-1.0, 1.0), 
00146                          ::atanh(x[i]), 1.0/(1.0 - x[i]*x[i]),
00147                          2.0*x[i]*df[i]*df[i])
00148 
00149 
00150 }
00151 
00152                   
00153 #endif  /* DOXYGEN_DEVELOPER_ONLY */  
00154 
00155 #endif

Site Contact