Intrepid
/usr/src/RPM/BUILD/trilinos10-10.6.4/packages/intrepid/src/Discretization/Integration/Intrepid_CubatureSparse.hpp
Go to the documentation of this file.
00001 // @HEADER
00002 // ************************************************************************
00003 //
00004 //                           Intrepid Package
00005 //                 Copyright (2007) Sandia Corporation
00006 //
00007 // Under terms of Contract DE-AC04-94AL85000, there is a non-exclusive
00008 // license for use of this work by or on behalf of the U.S. Government.
00009 //
00010 // This library is free software; you can redistribute it and/or modify
00011 // it under the terms of the GNU Lesser General Public License as
00012 // published by the Free Software Foundation; either version 2.1 of the
00013 // License, or (at your option) any later version.
00014 //
00015 // This library is distributed in the hope that it will be useful, but
00016 // WITHOUT ANY WARRANTY; without even the implied warranty of
00017 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00018 // Lesser General Public License for more details.
00019 //
00020 // You should have received a copy of the GNU Lesser General Public
00021 // License along with this library; if not, write to the Free Software
00022 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
00023 // USA
00024 // Questions? Contact Pavel Bochev (pbboche@sandia.gov) or
00025 //                    Denis Ridzal (dridzal@sandia.gov).
00026 //
00027 // ************************************************************************
00028 // @HEADER
00029 
00035 #ifndef INTREPID_CUBATURE_SPARSE_HPP
00036 #define INTREPID_CUBATURE_SPARSE_HPP
00037 
00038 #include "Intrepid_ConfigDefs.hpp"
00039 #include "Intrepid_Cubature.hpp"
00040 #include "Intrepid_CubatureDirectLineGauss.hpp"
00041 #include "Intrepid_CubatureSparseHelper.hpp"
00042 #include "Teuchos_TestForException.hpp"
00043 
00044 
00049 #define INTREPID_CUBATURE_SPARSE2D_GAUSS_MAX 59
00050 
00055 #define INTREPID_CUBATURE_SPARSE3D_GAUSS_MAX 57
00056 
00057 
00058 namespace Intrepid{
00059 
00060 template<class Scalar, int dimension_, class ArrayPoint = FieldContainer<Scalar>, class ArrayWeight = ArrayPoint>
00061 class CubatureSparse : public Intrepid::Cubature<Scalar,ArrayPoint,ArrayWeight> {
00062   private:
00063 
00064   int level_;
00065 
00066   int numPoints_;
00067 
00068   const int degree_;
00069 
00070   
00071   public:
00072 
00073   ~CubatureSparse() {}
00074 
00075 
00076   CubatureSparse(const int degree);
00077 
00084   virtual void getCubature(ArrayPoint  & cubPoints,
00085                            ArrayWeight & cubWeights) const;
00086 
00089   virtual int getNumPoints() const;
00090 
00093   virtual int getDimension() const;
00094 
00098   virtual void getAccuracy(std::vector<int> & accuracy) const;
00099 
00100 }; // end class CubatureSparse 
00101 
00102 // helper functions
00103 
00104 template<class Scalar, int DIM>
00105 void iterateThroughDimensions(int level,
00106                               int dims_left,
00107                               SGNodes<Scalar,DIM> & cubPointsND,
00108                               Teuchos::Array<Scalar> & partial_node,
00109                               Scalar partial_weight);
00110 
00111 inline int factorial(int num)
00112 {
00113   int answer = 1;
00114   if(num >= 1)
00115   {
00116     while(num > 0)
00117     {
00118       answer = answer*num;
00119       num--;
00120     }
00121   }
00122   else if(num == 0)
00123     answer = 1;
00124   else
00125     answer = -1;
00126 
00127   return answer;
00128 }
00129 
00130 inline double combination(int top, int bot)
00131 {
00132   double answer = factorial(top)/(factorial(bot) * factorial(top-bot));
00133   return answer;
00134 }
00135 
00136 inline int iterateThroughDimensionsForNumCalc(int dims_left,
00137                                               int level,
00138                                               int levels_left,
00139                                               int level_so_far,
00140                                               Teuchos::Array<int> & nodes,
00141                                               int product,
00142                                               bool no_uni_quad)
00143 {
00144   int numNodes = 0;
00145   for(int j = 1; j <= levels_left; j++)
00146   {
00147     bool temp_bool = no_uni_quad;
00148     int temp_knots = nodes[j-1]*product;
00149     int temp_lsf = level_so_far + j;
00150 
00151     if(j==1)
00152       temp_bool = false;
00153 
00154     if(dims_left == 1)
00155     {
00156       if(temp_lsf < level && temp_bool == true)
00157         numNodes += 0;
00158       else
00159       {
00160         numNodes += temp_knots;
00161       }
00162     }
00163     else
00164     {
00165       numNodes += iterateThroughDimensionsForNumCalc(dims_left-1,level, levels_left-j+1, temp_lsf, nodes, temp_knots, temp_bool);
00166     }
00167   }
00168   return numNodes;
00169 }
00170 
00171 inline int calculateNumPoints(int dim, int level)
00172 {
00173   //int* uninum = new int[level];
00174   Teuchos::Array<int> uninum(level);
00175   uninum[0] = 1;
00176   for(int i = 1; i <= level-1; i++)
00177   {
00178     uninum[i] = 2*i;
00179   }
00180 
00181   int numOfNodes = iterateThroughDimensionsForNumCalc(dim, level, level, 0, uninum, 1, true);
00182   return numOfNodes;
00183 }
00184 
00185 
00186 } // end namespace Intrepid
00187 
00188 
00189 // include templated definitions
00190 #include <Intrepid_CubatureSparseDef.hpp>
00191 
00192 #endif