Sacado_PCE_StandardPolyImp.hpp

Go to the documentation of this file.
00001 // $Id: Sacado_PCE_StandardPolyImp.hpp,v 1.2 2008/01/22 17:56:14 etphipp Exp $ 
00002 // $Source: /space/CVS/Trilinos/packages/sacado/src/pce/Sacado_PCE_StandardPolyImp.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 template <typename T>
00033 Sacado::PCE::StandardPoly<T>::
00034 StandardPoly(unsigned int deg) :
00035   coeffs(deg+1, T(0.))
00036 {
00037 }
00038 
00039 template <typename T>
00040 Sacado::PCE::StandardPoly<T>::
00041 StandardPoly(const std::vector<T>& coefficients) :
00042   coeffs(coefficients)
00043 {
00044 }
00045 
00046 template <typename T>
00047 Sacado::PCE::StandardPoly<T>::
00048 StandardPoly(const Sacado::PCE::StandardPoly<T>& p) :
00049   coeffs(p.coeffs)
00050 {
00051 }
00052 
00053 template <typename T>
00054 Sacado::PCE::StandardPoly<T>::
00055 ~StandardPoly()
00056 {
00057 }
00058 
00059 template <typename T>
00060 Sacado::PCE::StandardPoly<T>&
00061 Sacado::PCE::StandardPoly<T>::
00062 operator=(const Sacado::PCE::StandardPoly<T>& p)
00063 {
00064   if (this != &p)
00065     coeffs = p.coeffs;
00066   return *this;
00067 }
00068 
00069 template <typename T>
00070 unsigned int
00071 Sacado::PCE::StandardPoly<T>::
00072 degree() const
00073 {
00074   return coeffs.size()-1;
00075 }
00076 
00077 template <typename T>
00078 const T&
00079 Sacado::PCE::StandardPoly<T>::
00080 coeff(unsigned int i) const
00081 {
00082   return coeffs[i];
00083 }
00084 
00085 template <typename T>
00086 T&
00087 Sacado::PCE::StandardPoly<T>::
00088 coeff(unsigned int i)
00089 {
00090   return coeffs[i];
00091 }
00092 
00093 template <typename T>
00094 const T&
00095 Sacado::PCE::StandardPoly<T>::
00096 operator[](unsigned int i) const
00097 {
00098   return coeffs[i];
00099 }
00100 
00101 template <typename T>
00102 T&
00103 Sacado::PCE::StandardPoly<T>::
00104 operator[](unsigned int i)
00105 {
00106   return coeffs[i];
00107 }
00108 
00109 template <typename T>
00110 void
00111 Sacado::PCE::StandardPoly<T>::
00112 multiply(const T& alpha, 
00113    const Sacado::PCE::StandardPoly<T>& a,
00114    const Sacado::PCE::StandardPoly<T>& b, 
00115    const T& beta)
00116 {
00117   const unsigned int d = this->degree();
00118   const unsigned int da = a.degree();
00119   const unsigned int db = b.degree();
00120 
00121   if (alpha == T(0.0))
00122     for (unsigned int k=0; k<=d; k++)
00123       coeffs[k] = beta*coeffs[k];
00124   else if (da >= d && db >=d)
00125     for (unsigned int k=0; k<=d; k++) {
00126       T t = 0.0;
00127       for (unsigned int i=0; i<=k; i++)
00128   t += a.coeffs[i]*b.coeffs[k-i];
00129       coeffs[k] = beta*coeffs[k] + alpha*t;
00130     }
00131   else if (da >= d) {
00132     for (unsigned int k=0; k<=db; k++) {
00133       T t = 0.0;
00134       for (unsigned int i=0; i<=k; i++)
00135   t += a.coeffs[k-i]*b.coeffs[i];
00136       coeffs[k] = beta*coeffs[k] + alpha*t;
00137     }
00138     for (unsigned int k=db+1; k<=d; k++) {
00139       T t = 0.0;
00140       for (unsigned int i=k-db; i<=k; i++)
00141   t += a.coeffs[i]*b.coeffs[k-i];
00142       coeffs[k] = beta*coeffs[k] + alpha*t;
00143     }
00144   }
00145   else if (db >= d) {
00146     for (unsigned int k=0; k<=da; k++) {
00147       T t = 0.0;
00148       for (unsigned int i=0; i<=k; i++)
00149   t += a.coeffs[i]*b.coeffs[k-i];
00150       coeffs[k] = beta*coeffs[k] + alpha*t;
00151     }
00152     for (unsigned int k=da+1; k<=d; k++) {
00153       T t = 0.0;
00154       for (unsigned int i=k-da; i<=k; i++)
00155   t += a.coeffs[k-i]*b.coeffs[i];
00156       coeffs[k] = beta*coeffs[k] + alpha*t;
00157     }
00158   }
00159   else if (da >= db) {
00160     for (unsigned int k=0; k<=db; k++) {
00161       T t = 0.0;
00162       for (unsigned int i=0; i<=k; i++)
00163   t += a.coeffs[i]*b.coeffs[k-i];
00164       coeffs[k] = beta*coeffs[k] + alpha*t;
00165     }
00166     for (unsigned int k=db+1; k<=da; k++) {
00167       T t = 0.0;
00168       for (unsigned int i=k-db; i<=k; i++)
00169   t += a.coeffs[i]*b.coeffs[k-i];
00170       coeffs[k] = beta*coeffs[k] + alpha*t;
00171     }
00172     for (unsigned int k=da+1; k<=d; k++) {
00173       T t = 0.0;
00174       for (unsigned int i=k-db; i<=da; i++)
00175   t += a.coeffs[i]*b.coeffs[k-i];
00176       coeffs[k] = beta*coeffs[k] + alpha*t;
00177     }
00178   }
00179   else {
00180     for (unsigned int k=0; k<=da; k++) {
00181       T t = 0.0;
00182       for (unsigned int i=0; i<=k; i++)
00183   t += a.coeffs[k-i]*b.coeffs[i];
00184       coeffs[k] = beta*coeffs[k] + alpha*t;
00185     }
00186     for (unsigned int k=da+1; k<=db; k++) {
00187       T t = 0.0;
00188       for (unsigned int i=k-da; i<=k; i++)
00189   t += a.coeffs[k-i]*b.coeffs[i];
00190       coeffs[k] = beta*coeffs[k] + alpha*t;
00191     }
00192     for (unsigned int k=db+1; k<=d; k++) {
00193       T t = 0.0;
00194       for (unsigned int i=k-da; i<=db; i++)
00195   t += a.coeffs[k-i]*b.coeffs[i];
00196       coeffs[k] = beta*coeffs[k] + alpha*t;
00197     }
00198   }
00199 }
00200 
00201 template <typename T>
00202 void
00203 Sacado::PCE::StandardPoly<T>::
00204 add(const T& alpha, 
00205     const Sacado::PCE::StandardPoly<T>& a,
00206     const T& gamma)
00207 {
00208   const unsigned int d = this->degree();
00209   const unsigned int da = a.degree();
00210 
00211   if (da >= d)
00212     for (unsigned int i=0; i<=d; i++)
00213       coeffs[i] = alpha*a.coeffs[i] + gamma*coeffs[i];
00214   else {
00215     for (unsigned int i=0; i<=da; i++)
00216       coeffs[i] = alpha*a.coeffs[i] + gamma*coeffs[i];
00217     for (unsigned int i=da+1; i<=d; i++)
00218       coeffs[i] = gamma*coeffs[i];
00219   }
00220 }
00221 
00222 template <typename T>
00223 void
00224 Sacado::PCE::StandardPoly<T>::
00225 add(const T& alpha, 
00226     const Sacado::PCE::StandardPoly<T>& a,
00227     const T& beta,
00228     const Sacado::PCE::StandardPoly<T>& b, 
00229     const T& gamma)
00230 {
00231   const unsigned int d = this->degree();
00232   const unsigned int da = a.degree();
00233   const unsigned int db = b.degree();
00234 
00235   if (da >= d && db >= d)
00236     for (unsigned int i=0; i<=d; i++)
00237       coeffs[i] = alpha*a.coeffs[i] + beta*b.coeffs[i] + gamma*coeffs[i];
00238   else if (da < d) {
00239     for (unsigned int i=0; i<=da; i++)
00240       coeffs[i] = alpha*a.coeffs[i] + beta*b.coeffs[i] + gamma*coeffs[i];
00241     if (db <= d) {
00242       for (unsigned int i=da+1; i<=db; i++)
00243   coeffs[i] = beta*b.coeffs[i] + gamma*coeffs[i];
00244       for (unsigned int i=db+1; i<=d; i++)
00245   coeffs[i] = gamma*coeffs[i];
00246     }
00247     else
00248       for (unsigned int i=da+1; i<=d; i++)
00249   coeffs[i] = beta*b.coeffs[i] + gamma*coeffs[i];
00250   }
00251   else {
00252     for (unsigned int i=0; i<=db; i++)
00253       coeffs[i] = alpha*a.coeffs[i] + beta*b.coeffs[i] + gamma*coeffs[i];
00254     if (da <= d) {
00255       for (unsigned int i=db+1; i<=da; i++)
00256   coeffs[i] = alpha*a.coeffs[i] + gamma*coeffs[i];
00257       for (unsigned int i=da+1; i<=d; i++)
00258   coeffs[i] = gamma*coeffs[i];
00259     }
00260     else
00261       for (unsigned int i=db+1; i<=d; i++)
00262   coeffs[i] = alpha*a.coeffs[i] + gamma*coeffs[i];
00263   }
00264 }
00265 
00266 template <typename T>
00267 void
00268 Sacado::PCE::StandardPoly<T>::
00269 print(std::ostream& os) const
00270 {
00271   os << "[";
00272   for (unsigned int i=0; i<coeffs.size(); i++)
00273     os << " " << coeffs[i];
00274   os << " ]\n";
00275 }

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