Sacado_PCE_HermiteEBasisImp.hpp

Go to the documentation of this file.
00001 // $Id: Sacado_PCE_HermiteEBasisImp.hpp,v 1.3 2008/05/12 16:39:43 etphipp Exp $ 
00002 // $Source: /space/CVS/Trilinos/packages/sacado/src/pce/Sacado_PCE_HermiteEBasisImp.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::HermiteEBasis<T>::
00034 HermiteEBasis(unsigned int degree) :
00035   d(degree),
00036   basis(d+1, StandardPoly<T>(d)),
00037   norms(d+1, T(0.0))
00038 {
00039   // Fill in basis coefficients
00040   basis[0].coeff(0) = T(1.0);
00041   if (d >= 1)
00042     basis[1].coeff(1) = T(1.0);
00043   for (unsigned int k=2; k<=d; k++) {
00044     basis[k].coeff(0) = -(T(k-1)/T(2.0))*basis[k-2].coeff(0);
00045     for (unsigned int i=1; i<=k; i++)
00046       basis[k].coeff(i) = 
00047   basis[k-1].coeff(i-1) - (T(k-1)/T(2.0))*basis[k-2].coeff(i);
00048   }
00049 
00050   // Compute norms
00051   norms[0] = T(2.0)*std::sqrt(std::atan(1.0));  // = sqrt(pi)
00052   for (unsigned int k=1; k<=d; k++)
00053     norms[k] = T(k)/T(2.0)*norms[k-1];
00054 }
00055 
00056 template <typename T>
00057 Sacado::PCE::HermiteEBasis<T>::
00058 HermiteEBasis(const Sacado::PCE::HermiteEBasis<T>& b) :
00059   d(b.d),
00060   basis(b.basis),
00061   norms(b.norms)
00062 {
00063 }
00064 
00065 template <typename T>
00066 Sacado::PCE::HermiteEBasis<T>& 
00067 Sacado::PCE::HermiteEBasis<T>::
00068 operator=(const Sacado::PCE::HermiteEBasis<T>& b)
00069 {
00070   if (this != &b) {
00071     d = b.d;
00072     basis = b.basis;
00073     norms = b.norms;
00074   }
00075   return *this;
00076 }
00077 
00078 template <typename T>
00079 Sacado::PCE::HermiteEBasis<T>::
00080 ~HermiteEBasis()
00081 {
00082 }
00083 
00084 template <typename T>
00085 unsigned int
00086 Sacado::PCE::HermiteEBasis<T>::
00087 size() const
00088 {
00089   return d+1;
00090 }
00091 
00092 template <typename T>
00093 const std::vector<T>&
00094 Sacado::PCE::HermiteEBasis<T>::
00095 norm_squared() const
00096 {
00097   return norms;
00098 }
00099 
00100 template <typename T>
00101 T
00102 Sacado::PCE::HermiteEBasis<T>::
00103 derivCoeff(unsigned int i) const
00104 {
00105   return T(i);
00106 }
00107 
00108 template <typename T>
00109 void
00110 Sacado::PCE::HermiteEBasis<T>::
00111 project(const Sacado::PCE::StandardPoly<T>& p, std::vector<T>& coeffs) const
00112 {
00113   // Initialize
00114   for (unsigned int i=0; i<=d; i++)
00115     coeffs[i] = T(0.0);
00116 
00117   unsigned int dp = p.degree();
00118   if (dp > d)
00119     dp = d;
00120 
00121   // Handle degree 0 case
00122   if (dp == 0) {
00123     coeffs[0] = p.coeff(0);
00124     return;
00125   }
00126 
00127   // Temporary array
00128   std::vector<T> h(dp+1,T(0.));
00129 
00130   coeffs[0] = p.coeff(dp-1);
00131   coeffs[1] = p.coeff(dp);
00132   unsigned int dc = 1;
00133 
00134   for (int k=dp-2; k>=0; --k) {
00135 
00136     // Multiply by t
00137     h[0] = T(0.5)*coeffs[1] + p.coeff(k);
00138     for (unsigned int i=1; i<=dc-1; i++) {
00139       h[i] = coeffs[i-1] + (T(i+1)/T(2.0))*coeffs[i+1];
00140     }
00141     h[dc] = coeffs[dc-1];
00142     h[dc+1] = coeffs[dc];
00143     
00144     // Copy into coeffs
00145     for (unsigned int i=0; i<=dc+1; i++)
00146       coeffs[i] = h[i];
00147 
00148     dc = dc+1;
00149   }
00150 }
00151 
00152 template <typename T>
00153 Sacado::PCE::StandardPoly<T>
00154 Sacado::PCE::HermiteEBasis<T>::
00155 toStandardBasis(const T coeffs[], unsigned int n) const
00156 {
00157   unsigned int dp = d;
00158   if (n < d+1)
00159     dp = n-1;
00160   StandardPoly<T> p(dp);
00161 
00162   for (unsigned int i=0; i<=dp; i++)
00163     p.add(coeffs[i], basis[i], 1.0);
00164 
00165   return p;
00166 }
00167 
00168 template <typename T>
00169 const Sacado::PCE::StandardPoly<T>&
00170 Sacado::PCE::HermiteEBasis<T>::
00171 getBasisPoly(unsigned int i) const
00172 {
00173   return basis[i];
00174 }
00175 
00176 template <typename T>
00177 void
00178 Sacado::PCE::HermiteEBasis<T>::
00179 print(std::ostream& os) const
00180 {
00181   os << "Hermite basis of degree " << d << ".  Basis vectors:\n";
00182   for (unsigned int i=0; i<basis.size(); i++)
00183     os << "\t" << basis[i];
00184   os << "Basis vector norms (squared):\n\t";
00185   for (unsigned int i=0; i<norms.size(); i++)
00186     os << norms[i] << " ";
00187   os << "\n";
00188 }

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