Intrepid
Intrepid_CubatureTensorDef.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 namespace Intrepid {
50 
51 template <class Scalar, class ArrayPoint, class ArrayWeight>
53  unsigned numCubs = cubatures.size();
54  TEUCHOS_TEST_FOR_EXCEPTION( (numCubs < 1),
55  std::out_of_range,
56  ">>> ERROR (CubatureTensor): Input cubature array must be of size 1 or larger.");
57 
58  cubatures_ = cubatures;
59 
60  std::vector<int> tmp;
61  unsigned numDegrees = 0;
62  for (unsigned i=0; i<numCubs; i++) {
63  cubatures[i]->getAccuracy(tmp);
64  numDegrees += tmp.size();
65  }
66 
67  degree_.assign(numDegrees, 0);
68  int count = 0;
69  dimension_ = 0;
70  for (unsigned i=0; i<numCubs; i++) {
71  cubatures[i]->getAccuracy(tmp);
72  for (unsigned j=0; j<tmp.size(); j++) {
73  degree_[count] = tmp[j];
74  count++;
75  }
76  dimension_ += cubatures[i]->getDimension();
77  }
78 }
79 
80 
81 
82 template <class Scalar, class ArrayPoint, class ArrayWeight>
84  Teuchos::RCP<CubatureDirect<Scalar,ArrayPoint,ArrayWeight> > cubature2) {
85  cubatures_.resize(2);
86  cubatures_[0] = cubature1;
87  cubatures_[1] = cubature2;
88 
89  degree_.assign(2, 0);
90  std::vector<int> d(1);
91  cubatures_[0]->getAccuracy(d); degree_[0] = d[0];
92  cubatures_[1]->getAccuracy(d); degree_[1] = d[0];
93 
94  dimension_ = cubatures_[0]->getDimension() + cubatures_[1]->getDimension();
95 }
96 
97 
98 
99 template <class Scalar, class ArrayPoint, class ArrayWeight>
101  Teuchos::RCP<CubatureDirect<Scalar,ArrayPoint,ArrayWeight> > cubature2,
102  Teuchos::RCP<CubatureDirect<Scalar,ArrayPoint,ArrayWeight> > cubature3) {
103  cubatures_.resize(3);
104  cubatures_[0] = cubature1;
105  cubatures_[1] = cubature2;
106  cubatures_[2] = cubature3;
107 
108  degree_.assign(3, 0);
109  std::vector<int> d(1);
110  cubatures_[0]->getAccuracy(d); degree_[0] = d[0];
111  cubatures_[1]->getAccuracy(d); degree_[1] = d[0];
112  cubatures_[2]->getAccuracy(d); degree_[2] = d[0];
113 
114  dimension_ = cubatures_[0]->getDimension() + cubatures_[1]->getDimension() + cubatures_[2]->getDimension();
115 }
116 
117 
118 
119 template <class Scalar, class ArrayPoint, class ArrayWeight>
121  cubatures_.resize(n);
122  for (int i=0; i<n; i++) {
123  cubatures_[i] = cubature;
124  }
125 
126  std::vector<int> d(1);
127  cubatures_[0]->getAccuracy(d);
128  degree_.assign(n,d[0]);
129 
130  dimension_ = cubatures_[0]->getDimension()*n;
131 }
132 
133 
134 
135 template <class Scalar, class ArrayPoint, class ArrayWeight>
137  ArrayWeight & cubWeights) const {
138  int numCubPoints = getNumPoints();
139  int cubDim = getDimension();
140  // check size of cubPoints and cubWeights
141  TEUCHOS_TEST_FOR_EXCEPTION( ( ( (int)cubPoints.size() < numCubPoints*cubDim ) || ( (int)cubWeights.size() < numCubPoints ) ),
142  std::out_of_range,
143  ">>> ERROR (CubatureTensor): Insufficient space allocated for cubature points or weights.");
144 
145  unsigned numCubs = cubatures_.size();
146  std::vector<unsigned> numLocPoints(numCubs);
147  std::vector<unsigned> locDim(numCubs);
148  std::vector< FieldContainer<Scalar> > points(numCubs);
149  std::vector< FieldContainer<Scalar> > weights(numCubs);
150 
151  // extract required points and weights
152  for (unsigned i=0; i<numCubs; i++) {
153 
154  numLocPoints[i] = cubatures_[i]->getNumPoints();
155  locDim[i] = cubatures_[i]->getDimension();
156  points[i].resize(numLocPoints[i], locDim[i]);
157  weights[i].resize(numLocPoints[i]);
158 
159  // cubPoints and cubWeights are used here only for temporary data retrieval
160  cubatures_[i]->getCubature(cubPoints, cubWeights);
161  for (unsigned pt=0; pt<numLocPoints[i]; pt++) {
162  for (unsigned d=0; d<locDim[i]; d++) {
163  points[i](pt,d) = cubPoints(pt,d);
164  weights[i](pt) = cubWeights(pt);
165  }
166  }
167 
168  }
169 
170  // reset all weights to 1.0
171  for (int i=0; i<numCubPoints; i++) {
172  cubWeights(i) = (Scalar)1.0;
173  }
174 
175  // fill tensor-product cubature
176  int globDimCounter = 0;
177  int shift = 1;
178  for (unsigned i=0; i<numCubs; i++) {
179 
180  for (int j=0; j<numCubPoints; j++) {
181  /* int itmp = ((j*shift) % numCubPoints) + (j / (numCubPoints/shift)); // equivalent, but numerically unstable */
182  int itmp = (j % (numCubPoints/shift))*shift + (j / (numCubPoints/shift));
183  for (unsigned k=0; k<locDim[i]; k++) {
184  cubPoints(itmp , globDimCounter+k) = points[i](j % numLocPoints[i], k);
185  }
186  cubWeights( itmp ) *= weights[i](j % numLocPoints[i]);
187  }
188 
189  shift *= numLocPoints[i];
190  globDimCounter += locDim[i];
191  }
192 
193 } // end getCubature
194 
195 
196 
197 template <class Scalar, class ArrayPoint, class ArrayWeight>
199  unsigned numCubs = cubatures_.size();
200  int numCubPoints = 1;
201  for (unsigned i=0; i<numCubs; i++) {
202  numCubPoints *= cubatures_[i]->getNumPoints();
203  }
204  return numCubPoints;
205 } // end getNumPoints
206 
207 
208 template <class Scalar, class ArrayPoint, class ArrayWeight>
210  return dimension_;
211 } // end dimension
212 
213 
214 
215 template <class Scalar, class ArrayPoint, class ArrayWeight>
216 void CubatureTensor<Scalar,ArrayPoint,ArrayWeight>::getAccuracy(std::vector<int> & degree) const {
217  degree = degree_;
218 } // end getAccuracy
219 
220 } // end namespace Intrepid
CubatureTensor(std::vector< Teuchos::RCP< Cubature< Scalar, ArrayPoint, ArrayWeight > > > cubatures)
Constructor.
virtual int getNumPoints() const
Returns the number of cubature points.
virtual int getDimension() const
Returns dimension of integration domain.
Defines the base class for cubature (integration) rules in Intrepid.
virtual void getAccuracy(std::vector< int > &degree) const
Returns max. degree of polynomials that are integrated exactly. The return vector has the size of the...
Defines direct 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).