00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
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
00055 virtual void eval1(const double* const x,
00056 int nx,
00057 double* f,
00058 double* df) const ;
00059
00060 virtual void eval0(const double* const x, int nx, double* f) const ;
00061
00062
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
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
00154
00155 #endif