Sacado_Tay_Taylor.hpp

Go to the documentation of this file.
00001 // $Id: Sacado_Tay_Taylor.hpp,v 1.7 2007/08/01 19:58:54 etphipp Exp $ 
00002 // $Source: /space/CVS/Trilinos/packages/sacado/src/Sacado_Tay_Taylor.hpp,v $ 
00003 // @HEADER
00004 // ***********************************************************************
00005 // 
00006 //                           Sacado Package
00007 //                 Copyright (2006) Sandia Corporation
00008 // 
00009 // Under terms of Contract DE-AC04-94AL85000, there is a non-exclusive
00010 // license for use of this work by or on behalf of the U.S. Government.
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_TAY_TAYLOR_HPP
00033 #define SACADO_TAY_TAYLOR_HPP
00034 
00035 #include "Sacado_Handle.hpp"
00036 #include <cmath>
00037 #include <algorithm>  // for std::min and std::max
00038 #include <ostream>  // for std::ostream
00039 
00040 namespace Sacado {
00041 
00043   namespace Tay {
00044 
00046 
00050     template <typename T> 
00051     class Taylor {
00052     public:
00053 
00055       typedef T value_type;
00056 
00058       Taylor();
00059 
00061 
00064       Taylor(const T& x);
00065 
00067 
00070       Taylor(unsigned int d, const T & x);
00071 
00073 
00076       Taylor(unsigned int d);
00077 
00079       Taylor(const Taylor& x);
00080 
00082       ~Taylor();
00083 
00085 
00089       void resize(unsigned int d, bool keep_coeffs);
00090 
00092 
00095       void reserve(unsigned int d);
00096 
00098 
00107       void copyForWrite() { th.makeOwnCopy(); }
00108 
00113 
00115       Taylor<T>& operator=(const T& val);
00116 
00118       Taylor<T>& operator=(const Taylor<T>& x);
00119 
00121 
00126 
00128       const T& val() const { return th->coeff_[0];}
00129 
00131       T& val() { return th->coeff_[0];}
00132 
00134 
00139 
00141       unsigned int degree() const { return th->deg_;}
00142 
00144       bool hasFastAccess(unsigned int d) const { return th->deg_>=d;}
00145 
00147       const T* coeff() const { return th->coeff_;}
00148 
00150       T* coeff() { return th->coeff_;}
00151 
00153       T coeff(unsigned int i) const { 
00154   T tmp= i<=th->deg_ ? th->coeff_[i]:T(0.); return tmp;}
00155     
00157       T& fastAccessCoeff(unsigned int i) { return th->coeff_[i];}
00158 
00160       T fastAccessCoeff(unsigned int i) const { return th->coeff_[i];}
00161     
00163 
00168 
00170       Taylor<T> operator + () const;
00171 
00173       Taylor<T> operator - () const;
00174 
00176       Taylor<T>& operator += (const T& x);
00177 
00179       Taylor<T>& operator -= (const T& x);
00180 
00182       Taylor<T>& operator *= (const T& x);
00183 
00185       Taylor<T>& operator /= (const T& x);
00186 
00188       Taylor<T>& operator += (const Taylor<T>& x);
00189 
00191       Taylor<T>& operator -= (const Taylor<T>& x);
00192   
00194       Taylor<T>& operator *= (const Taylor<T>& x);
00195 
00197       Taylor<T>& operator /= (const Taylor<T>& x);
00198 
00200 
00201     protected:
00202 
00204       unsigned int length() const { return th->len_; }
00205 
00207       void resizeCoeffs(unsigned int len);
00208 
00209     protected:
00210 
00211       struct TaylorData {
00212 
00214   T* coeff_;
00215 
00217   unsigned int deg_;
00218 
00220   unsigned int len_;
00221 
00223   TaylorData();
00224 
00226   TaylorData(const T& x);
00227 
00229   TaylorData(unsigned int d, const T & x);
00230 
00232   TaylorData(unsigned int d);
00233 
00235   TaylorData(unsigned int d, unsigned int l);
00236 
00238   TaylorData(const TaylorData& x);
00239 
00241   ~TaylorData();
00242 
00244   TaylorData& operator=(const TaylorData& x);
00245 
00246       };
00247 
00248       Sacado::Handle<TaylorData> th;
00249 
00250     }; // class Taylor
00251 
00252     // Operations
00253     template <typename T> Taylor<T> operator+(const Taylor<T>& a,
00254                 const Taylor<T>& b);
00255     template <typename T> Taylor<T> operator+(const T& a, 
00256                 const Taylor<T>& b);
00257     template <typename T> Taylor<T> operator+(const Taylor<T>& a, 
00258                 const T& b);
00259     template <typename T> Taylor<T> operator-(const Taylor<T>& a, 
00260                 const Taylor<T>& b);
00261     template <typename T> Taylor<T> operator-(const T& a, 
00262                 const Taylor<T>& b);
00263     template <typename T> Taylor<T> operator-(const Taylor<T>& a, 
00264                 const T& b);
00265     template <typename T> Taylor<T> operator*(const Taylor<T>& a, 
00266                 const Taylor<T>& b);
00267     template <typename T> Taylor<T> operator*(const T& a, 
00268                 const Taylor<T>& b);
00269     template <typename T> Taylor<T> operator*(const Taylor<T>& a, 
00270                 const T& b);
00271     template <typename T> Taylor<T> operator/(const Taylor<T>& a, 
00272                 const Taylor<T>& b);
00273     template <typename T> Taylor<T> operator/(const T& a, 
00274                 const Taylor<T>& b);
00275     template <typename T> Taylor<T> operator/(const Taylor<T>& a, 
00276                 const T& b);
00277     template <typename T> Taylor<T> exp(const Taylor<T>& a);
00278     template <typename T> Taylor<T> log(const Taylor<T>& a);
00279     template <typename T> Taylor<T> log10(const Taylor<T>& a);
00280     template <typename T> Taylor<T> sqrt(const Taylor<T>& a);
00281     template <typename T> Taylor<T> pow(const Taylor<T>& a, 
00282           const Taylor<T>& b);
00283     template <typename T> Taylor<T> pow(const T& a,
00284           const Taylor<T>& b);
00285     template <typename T> Taylor<T> pow(const Taylor<T>& a,
00286           const T& b);
00287     template <typename T> void sincos(const Taylor<T>& a,
00288               Taylor<T>& s, Taylor<T>& c);
00289     template <typename T> Taylor<T> cos(const Taylor<T>& a);
00290     template <typename T> Taylor<T> sin(const Taylor<T>& a);
00291     template <typename T> Taylor<T> tan(const Taylor<T>& a);
00292     template <typename T> void sinhcosh(const Taylor<T>& a,
00293           Taylor<T>& s, Taylor<T>& c);
00294     template <typename T> Taylor<T> cosh(const Taylor<T>& a);
00295     template <typename T> Taylor<T> sinh(const Taylor<T>& a);
00296     template <typename T> Taylor<T> tanh(const Taylor<T>& a);
00297     template <typename T> Taylor<T> quad(const T& c0,
00298            const Taylor<T>& a,
00299            const Taylor<T>& b);
00300     template <typename T> Taylor<T> acos(const Taylor<T>& a);
00301     template <typename T> Taylor<T> asin(const Taylor<T>& a);
00302     template <typename T> Taylor<T> atan(const Taylor<T>& a);
00303     template <typename T> Taylor<T> atan2(const Taylor<T>& a,
00304             const Taylor<T>& b);
00305     template <typename T> Taylor<T> atan2(const T& a,
00306             const Taylor<T>& b);
00307     template <typename T> Taylor<T> atan2(const Taylor<T>& a,
00308             const T& b);
00309     template <typename T> Taylor<T> acosh(const Taylor<T>& a);
00310     template <typename T> Taylor<T> asinh(const Taylor<T>& a);
00311     template <typename T> Taylor<T> atanh(const Taylor<T>& a);
00312     template <typename T> Taylor<T> abs(const Taylor<T>& a);
00313     template <typename T> Taylor<T> fabs(const Taylor<T>& a);
00314     template <typename T> Taylor<T> max(const Taylor<T>& a,
00315           const Taylor<T>& b);
00316     template <typename T> Taylor<T> max(const T& a,
00317           const Taylor<T>& b);
00318     template <typename T> Taylor<T> max(const Taylor<T>& a,
00319           const T& b);
00320     template <typename T> Taylor<T> min(const Taylor<T>& a,
00321           const Taylor<T>& b);
00322     template <typename T> Taylor<T> min(const T& a,
00323           const Taylor<T>& b);
00324     template <typename T> Taylor<T> min(const Taylor<T>& a,
00325           const T& b);
00326     template <typename T> bool operator==(const Taylor<T>& a,
00327             const Taylor<T>& b);
00328     template <typename T> bool operator==(const T& a,
00329             const Taylor<T>& b);
00330     template <typename T> bool operator==(const Taylor<T>& a,
00331             const T& b);
00332     template <typename T> bool operator!=(const Taylor<T>& a,
00333             const Taylor<T>& b);
00334     template <typename T> bool operator!=(const T& a,
00335             const Taylor<T>& b);
00336     template <typename T> bool operator!=(const Taylor<T>& a,
00337             const T& b);
00338     template <typename T> bool operator<=(const Taylor<T>& a,
00339             const Taylor<T>& b);
00340     template <typename T> bool operator<=(const T& a,
00341             const Taylor<T>& b);
00342     template <typename T> bool operator<=(const Taylor<T>& a,
00343             const T& b);
00344     template <typename T> bool operator>=(const Taylor<T>& a,
00345             const Taylor<T>& b);
00346     template <typename T> bool operator>=(const T& a,
00347             const Taylor<T>& b);
00348     template <typename T> bool operator>=(const Taylor<T>& a,
00349             const T& b);
00350     template <typename T> bool operator<(const Taylor<T>& a,
00351            const Taylor<T>& b);
00352     template <typename T> bool operator<(const T& a,
00353            const Taylor<T>& b);
00354     template <typename T> bool operator<(const Taylor<T>& a,
00355            const T& b);
00356     template <typename T> bool operator>(const Taylor<T>& a,
00357            const Taylor<T>& b);
00358     template <typename T> bool operator>(const T& a,
00359            const Taylor<T>& b);
00360     template <typename T> bool operator>(const Taylor<T>& a,
00361            const T& b);
00362     template <typename T> std::ostream& operator << (std::ostream& os,
00363                  const Taylor<T>& a);
00364 
00365   } // namespace Tay
00366 
00367 } // namespace Sacado
00368 
00369 #include "Sacado_Tay_TaylorTraits.hpp"
00370 #include "Sacado_Tay_TaylorImp.hpp"
00371 
00372 #endif // SACADO_TAY_TAYLOR_HPP

Generated on Wed May 12 21:59:06 2010 for Sacado Package Browser (Single Doxygen Collection) by  doxygen 1.4.7