Intrepid
Intrepid_CubatureSparse.hpp
Go to the documentation of this file.
1 // @HEADER
2 // ************************************************************************
3 //
4 // Intrepid Package
5 // Copyright (2007) Sandia Corporation
6 //
7 // Under terms of Contract DE-AC04-94AL85000, there is a non-exclusive
8 // license for use of this work by or on behalf of the U.S. Government.
9 //
10 // Redistribution and use in source and binary forms, with or without
11 // modification, are permitted provided that the following conditions are
12 // met:
13 //
14 // 1. Redistributions of source code must retain the above copyright
15 // notice, this list of conditions and the following disclaimer.
16 //
17 // 2. Redistributions in binary form must reproduce the above copyright
18 // notice, this list of conditions and the following disclaimer in the
19 // documentation and/or other materials provided with the distribution.
20 //
21 // 3. Neither the name of the Corporation nor the names of the
22 // contributors may be used to endorse or promote products derived from
23 // this software without specific prior written permission.
24 //
25 // THIS SOFTWARE IS PROVIDED BY SANDIA CORPORATION "AS IS" AND ANY
26 // EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
27 // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
28 // PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL SANDIA CORPORATION OR THE
29 // CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
30 // EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
31 // PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
32 // PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
33 // LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
34 // NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
35 // SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
36 //
37 // Questions? Contact Pavel Bochev (pbboche@sandia.gov)
38 // Denis Ridzal (dridzal@sandia.gov), or
39 // Kara Peterson (kjpeter@sandia.gov)
40 //
41 // ************************************************************************
42 // @HEADER
43 
49 #ifndef INTREPID_CUBATURE_SPARSE_HPP
50 #define INTREPID_CUBATURE_SPARSE_HPP
51 
52 #include "Intrepid_ConfigDefs.hpp"
53 #include "Intrepid_Cubature.hpp"
55 #include "Intrepid_CubatureSparseHelper.hpp"
56 #include "Teuchos_Assert.hpp"
57 
58 
63 #define INTREPID_CUBATURE_SPARSE2D_GAUSS_MAX 59
64 
69 #define INTREPID_CUBATURE_SPARSE3D_GAUSS_MAX 57
70 
71 
72 namespace Intrepid{
73 
74 template<class Scalar, int dimension_, class ArrayPoint = FieldContainer<Scalar>, class ArrayWeight = ArrayPoint>
75 class CubatureSparse : public Intrepid::Cubature<Scalar,ArrayPoint,ArrayWeight> {
76  private:
77 
78  int level_;
79 
80  int numPoints_;
81 
82  const int degree_;
83 
84 
85  public:
86 
87  ~CubatureSparse() {}
88 
89 
90  CubatureSparse(const int degree);
91 
98  virtual void getCubature(ArrayPoint & cubPoints,
99  ArrayWeight & cubWeights) const;
100 
103  virtual int getNumPoints() const;
104 
107  virtual int getDimension() const;
108 
112  virtual void getAccuracy(std::vector<int> & accuracy) const;
113 
114 }; // end class CubatureSparse
115 
116 // helper functions
117 
118 template<class Scalar, int DIM>
119 void iterateThroughDimensions(int level,
120  int dims_left,
121  SGNodes<Scalar,DIM> & cubPointsND,
122  Teuchos::Array<Scalar> & partial_node,
123  Scalar partial_weight);
124 
125 inline int factorial(int num)
126 {
127  int answer = 1;
128  if(num >= 1)
129  {
130  while(num > 0)
131  {
132  answer = answer*num;
133  num--;
134  }
135  }
136  else if(num == 0)
137  answer = 1;
138  else
139  answer = -1;
140 
141  return answer;
142 }
143 
144 inline double combination(int top, int bot)
145 {
146  double answer = factorial(top)/(factorial(bot) * factorial(top-bot));
147  return answer;
148 }
149 
150 inline int iterateThroughDimensionsForNumCalc(int dims_left,
151  int level,
152  int levels_left,
153  int level_so_far,
154  Teuchos::Array<int> & nodes,
155  int product,
156  bool no_uni_quad)
157 {
158  int numNodes = 0;
159  for(int j = 1; j <= levels_left; j++)
160  {
161  bool temp_bool = no_uni_quad;
162  int temp_knots = nodes[j-1]*product;
163  int temp_lsf = level_so_far + j;
164 
165  if(j==1)
166  temp_bool = false;
167 
168  if(dims_left == 1)
169  {
170  if(temp_lsf < level && temp_bool == true)
171  numNodes += 0;
172  else
173  {
174  numNodes += temp_knots;
175  }
176  }
177  else
178  {
179  numNodes += iterateThroughDimensionsForNumCalc(dims_left-1,level, levels_left-j+1, temp_lsf, nodes, temp_knots, temp_bool);
180  }
181  }
182  return numNodes;
183 }
184 
185 inline int calculateNumPoints(int dim, int level)
186 {
187  //int* uninum = new int[level];
188  Teuchos::Array<int> uninum(level);
189  uninum[0] = 1;
190  for(int i = 1; i <= level-1; i++)
191  {
192  uninum[i] = 2*i;
193  }
194 
195  int numOfNodes = iterateThroughDimensionsForNumCalc(dim, level, level, 0, uninum, 1, true);
196  return numOfNodes;
197 }
198 
199 
200 } // end namespace Intrepid
201 
202 
203 // include templated definitions
205 
206 #endif
virtual void getAccuracy(std::vector< int > &accuracy) const
Returns algebraic accuracy (e.g. max. degree of polynomial that is integrated exactly).
Header file for the Intrepid::CubatureDirectLineGauss class.
virtual int getDimension() const
Returns dimension of the integration domain.
virtual int getNumPoints() const
Returns the number of cubature points.
Definition file for the Intrepid::CubatureSparse class.
Defines the base class for cubature (integration) rules in Intrepid.
virtual void getCubature(ArrayPoint &cubPoints, ArrayWeight &cubWeights) const
Returns cubature points and weights (return arrays must be pre-sized/pre-allocated).
Header file for the Intrepid::Cubature class.