Sacado_Tay_Taylor.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 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       template <typename U> 
00056       struct apply {
00057   typedef Taylor<U> type;
00058       };
00059 
00061       typedef T value_type;
00062 
00064       Taylor();
00065 
00067 
00070       Taylor(const T& x);
00071 
00073 
00076       Taylor(unsigned int d, const T & x);
00077 
00079 
00082       Taylor(unsigned int d);
00083 
00085       Taylor(const Taylor& x);
00086 
00088       ~Taylor();
00089 
00091 
00095       void resize(unsigned int d, bool keep_coeffs);
00096 
00098 
00101       void reserve(unsigned int d);
00102 
00104 
00113       void copyForWrite() { th.makeOwnCopy(); }
00114 
00119 
00121       Taylor<T>& operator=(const T& val);
00122 
00124       Taylor<T>& operator=(const Taylor<T>& x);
00125 
00127 
00132 
00134       const T& val() const { return th->coeff_[0];}
00135 
00137       T& val() { return th->coeff_[0];}
00138 
00140 
00145 
00147       unsigned int degree() const { return th->deg_;}
00148 
00150       bool hasFastAccess(unsigned int d) const { return th->deg_>=d;}
00151 
00153       const T* coeff() const { return th->coeff_;}
00154 
00156       T* coeff() { return th->coeff_;}
00157 
00159       T coeff(unsigned int i) const { 
00160   T tmp= i<=th->deg_ ? th->coeff_[i]:T(0.); return tmp;}
00161     
00163       T& fastAccessCoeff(unsigned int i) { return th->coeff_[i];}
00164 
00166       T fastAccessCoeff(unsigned int i) const { return th->coeff_[i];}
00167     
00169 
00174 
00176       Taylor<T> operator + () const;
00177 
00179       Taylor<T> operator - () const;
00180 
00182       Taylor<T>& operator += (const T& x);
00183 
00185       Taylor<T>& operator -= (const T& x);
00186 
00188       Taylor<T>& operator *= (const T& x);
00189 
00191       Taylor<T>& operator /= (const T& x);
00192 
00194       Taylor<T>& operator += (const Taylor<T>& x);
00195 
00197       Taylor<T>& operator -= (const Taylor<T>& x);
00198   
00200       Taylor<T>& operator *= (const Taylor<T>& x);
00201 
00203       Taylor<T>& operator /= (const Taylor<T>& x);
00204 
00206 
00207     protected:
00208 
00210       unsigned int length() const { return th->len_; }
00211 
00213       void resizeCoeffs(unsigned int len);
00214 
00215     protected:
00216 
00217       struct TaylorData {
00218 
00220   T* coeff_;
00221 
00223   unsigned int deg_;
00224 
00226   unsigned int len_;
00227 
00229   TaylorData();
00230 
00232   TaylorData(const T& x);
00233 
00235   TaylorData(unsigned int d, const T & x);
00236 
00238   TaylorData(unsigned int d);
00239 
00241   TaylorData(unsigned int d, unsigned int l);
00242 
00244   TaylorData(const TaylorData& x);
00245 
00247   ~TaylorData();
00248 
00250   TaylorData& operator=(const TaylorData& x);
00251 
00252       };
00253 
00254       Sacado::Handle<TaylorData> th;
00255 
00256     }; // class Taylor
00257 
00258     // Operations
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> operator/(const Taylor<T>& a, 
00278                 const Taylor<T>& b);
00279     template <typename T> Taylor<T> operator/(const T& a, 
00280                 const Taylor<T>& b);
00281     template <typename T> Taylor<T> operator/(const Taylor<T>& a, 
00282                 const T& b);
00283     template <typename T> Taylor<T> exp(const Taylor<T>& a);
00284     template <typename T> Taylor<T> log(const Taylor<T>& a);
00285     template <typename T> Taylor<T> log10(const Taylor<T>& a);
00286     template <typename T> Taylor<T> sqrt(const Taylor<T>& a);
00287     template <typename T> Taylor<T> pow(const Taylor<T>& a, 
00288           const Taylor<T>& b);
00289     template <typename T> Taylor<T> pow(const T& a,
00290           const Taylor<T>& b);
00291     template <typename T> Taylor<T> pow(const Taylor<T>& a,
00292           const T& b);
00293     template <typename T> void sincos(const Taylor<T>& a,
00294               Taylor<T>& s, Taylor<T>& c);
00295     template <typename T> Taylor<T> cos(const Taylor<T>& a);
00296     template <typename T> Taylor<T> sin(const Taylor<T>& a);
00297     template <typename T> Taylor<T> tan(const Taylor<T>& a);
00298     template <typename T> void sinhcosh(const Taylor<T>& a,
00299           Taylor<T>& s, Taylor<T>& c);
00300     template <typename T> Taylor<T> cosh(const Taylor<T>& a);
00301     template <typename T> Taylor<T> sinh(const Taylor<T>& a);
00302     template <typename T> Taylor<T> tanh(const Taylor<T>& a);
00303     template <typename T> Taylor<T> quad(const T& c0,
00304            const Taylor<T>& a,
00305            const Taylor<T>& b);
00306     template <typename T> Taylor<T> acos(const Taylor<T>& a);
00307     template <typename T> Taylor<T> asin(const Taylor<T>& a);
00308     template <typename T> Taylor<T> atan(const Taylor<T>& a);
00309     template <typename T> Taylor<T> atan2(const Taylor<T>& a,
00310             const Taylor<T>& b);
00311     template <typename T> Taylor<T> atan2(const T& a,
00312             const Taylor<T>& b);
00313     template <typename T> Taylor<T> atan2(const Taylor<T>& a,
00314             const T& b);
00315     template <typename T> Taylor<T> acosh(const Taylor<T>& a);
00316     template <typename T> Taylor<T> asinh(const Taylor<T>& a);
00317     template <typename T> Taylor<T> atanh(const Taylor<T>& a);
00318     template <typename T> Taylor<T> abs(const Taylor<T>& a);
00319     template <typename T> Taylor<T> fabs(const Taylor<T>& a);
00320     template <typename T> Taylor<T> max(const Taylor<T>& a,
00321           const Taylor<T>& b);
00322     template <typename T> Taylor<T> max(const T& a,
00323           const Taylor<T>& b);
00324     template <typename T> Taylor<T> max(const Taylor<T>& a,
00325           const T& b);
00326     template <typename T> Taylor<T> min(const Taylor<T>& a,
00327           const Taylor<T>& b);
00328     template <typename T> Taylor<T> min(const T& a,
00329           const Taylor<T>& b);
00330     template <typename T> Taylor<T> min(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> bool operator>(const Taylor<T>& a,
00363            const Taylor<T>& b);
00364     template <typename T> bool operator>(const T& a,
00365            const Taylor<T>& b);
00366     template <typename T> bool operator>(const Taylor<T>& a,
00367            const T& b);
00368     template <typename T> std::ostream& operator << (std::ostream& os,
00369                  const Taylor<T>& a);
00370 
00371   } // namespace Tay
00372 
00373 } // namespace Sacado
00374 
00375 #include "Sacado_Tay_TaylorTraits.hpp"
00376 #include "Sacado_Tay_TaylorImp.hpp"
00377 
00378 #endif // SACADO_TAY_TAYLOR_HPP
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines
Generated on Wed Apr 13 10:19:36 2011 for Sacado Package Browser (Single Doxygen Collection) by  doxygen 1.6.3