Sacado_PCE_TripleProductImp.hpp

Go to the documentation of this file.
00001 // $Id: Sacado_PCE_TripleProductImp.hpp,v 1.1 2007/11/14 00:18:19 etphipp Exp $ 
00002 // $Source: /space/CVS/Trilinos/packages/sacado/src/pce/Sacado_PCE_TripleProductImp.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 #include "Sacado_PCE_StandardPoly.hpp"
00033 
00034 template <typename BasisT>
00035 Sacado::PCE::TripleProduct<BasisT>::
00036 TripleProduct(unsigned int degree) :
00037   l(degree+1),
00038   basis(2*degree),
00039   Cijk(l*l*l)
00040 {
00041   compute();
00042 }
00043 
00044 template <typename BasisT>
00045 Sacado::PCE::TripleProduct<BasisT>::
00046 TripleProduct(const Sacado::PCE::TripleProduct<BasisT>& tp) :
00047   l(tp.l),
00048   basis(tp.basis),
00049   Cijk(tp.Cijk)
00050 {
00051 }
00052 
00053 template <typename BasisT>
00054 Sacado::PCE::TripleProduct<BasisT>::
00055 ~TripleProduct()
00056 {
00057 }
00058 
00059 template <typename BasisT>
00060 Sacado::PCE::TripleProduct<BasisT>&
00061 Sacado::PCE::TripleProduct<BasisT>::
00062 operator=(const Sacado::PCE::TripleProduct<BasisT>& tp)
00063 {
00064   if (this != &tp) {
00065     l = tp.l;
00066     basis = tp.basis;
00067     Cijk = tp.Cijk;
00068   }
00069   return *this;
00070 }
00071 
00072 template <typename BasisT>
00073 const typename Sacado::PCE::TripleProduct<BasisT>::value_type&
00074 Sacado::PCE::TripleProduct<BasisT>::
00075 value(unsigned int i, unsigned int j, unsigned int k) const
00076 {
00077   return Cijk[ l*(l*k + j) + i ];
00078 }
00079 
00080 template <typename BasisT>
00081 const typename Sacado::PCE::TripleProduct<BasisT>::value_type&
00082 Sacado::PCE::TripleProduct<BasisT>::
00083 norm_squared(unsigned int i) const
00084 {
00085   return basis.norm_squared()[i];
00086 }
00087 
00088 template <typename BasisT>
00089 void
00090 Sacado::PCE::TripleProduct<BasisT>::
00091 resize(unsigned int degree)
00092 {
00093   if (degree+1 != l) {
00094     l = degree+1;
00095     basis = BasisT(2*degree);
00096     Cijk.resize(l*l*l);
00097     compute();
00098   }
00099 }
00100 
00101 // Important note:  To get the correct value for <\Psi_i \Psi_j \Psi_k>,
00102 // we have to expand \Psi_i*\Psi_j in the full degree_i+degree_j basis, not
00103 // just the degree d basis.  There for the basis needs to be of size 2*d
00104 template <typename BasisT>
00105 void
00106 Sacado::PCE::TripleProduct<BasisT>::
00107 compute()  
00108 {
00109   const std::vector<value_type>& nrm_sq = basis.norm_squared();
00110   StandardPoly<value_type> pij(2*(l-1));
00111   std::vector<value_type> a(2*l);
00112   for (unsigned int i=0; i<l; i++) {
00113     const StandardPoly<value_type>& pi = basis.getBasisPoly(i);
00114     for (unsigned int j=0; j<l; j++) {
00115       const StandardPoly<value_type>& pj = basis.getBasisPoly(j);
00116       pij.multiply(1.0, pi, pj, 0.0);
00117       basis.project(pij, a);
00118       for (unsigned int k=0; k<l; k++)
00119   Cijk[ l*(l*k+j) + i ] = a[k]*nrm_sq[k];
00120     }
00121   }
00122 }

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