Intrepid
Intrepid_CubatureLineSortedDef.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  int degree, EIntrepidBurkardt rule, bool isNormalized ) {
54  TEUCHOS_TEST_FOR_EXCEPTION((degree < 0),std::out_of_range,
55  ">>> ERROR (CubatureLineSorted): No rule implemented for desired polynomial degree.");
56  degree_ = degree;
57  rule_type_ = rule;
58 
59  if (rule==BURK_CHEBYSHEV1||rule==BURK_CHEBYSHEV2||
60  rule==BURK_LAGUERRE ||rule==BURK_LEGENDRE ||
61  rule==BURK_HERMITE) {
62  numPoints_ = (degree+1)/2+1;
63  }
64  else if (rule==BURK_CLENSHAWCURTIS||rule==BURK_FEJER2) {
65  numPoints_ = degree+1;
66  }
67  else if (rule==BURK_TRAPEZOIDAL) {
68  numPoints_ = 2;
69  }
70  else if (rule==BURK_PATTERSON) {
71  int l = 0, o = (degree-0.5)/1.5;
72  for (int i=0; i<8; i++) {
73  l = (int)pow(2.0,(double)i+1.0)-1;
74  if (l>=o) {
75  numPoints_ = l;
76  break;
77  }
78  }
79  }
80  else if (rule==BURK_GENZKEISTER) {
81  int o_ghk[8] = {1,3,9,19,35,37,41,43};
82  int o = (degree-0.5)/1.5;
83  for (int i=0; i<8; i++) {
84  if (o_ghk[i]>=o) {
85  numPoints_ = o_ghk[i];
86  break;
87  }
88  }
89  }
90 
91  Teuchos::Array<Scalar> nodes(numPoints_), weights(numPoints_);
92 
93  if (rule==BURK_CHEBYSHEV1) { // Gauss-Chebyshev Type 1
94  IntrepidBurkardtRules::chebyshev1_compute<Scalar>(numPoints_,
95  nodes.getRawPtr(),weights.getRawPtr());
96  }
97  else if (rule==BURK_CHEBYSHEV2) { // Gauss-Chebyshev Type 2
98  IntrepidBurkardtRules::chebyshev2_compute<Scalar>(numPoints_,
99  nodes.getRawPtr(),weights.getRawPtr());
100  }
101  else if (rule==BURK_CLENSHAWCURTIS) { // Clenshaw-Curtis
102  IntrepidBurkardtRules::clenshaw_curtis_compute<Scalar>(numPoints_,
103  nodes.getRawPtr(),weights.getRawPtr());
104  }
105  else if (rule==BURK_FEJER2) { // Fejer Type 2
106  IntrepidBurkardtRules::fejer2_compute<Scalar>(numPoints_,
107  nodes.getRawPtr(),weights.getRawPtr());
108  }
109  else if (rule==BURK_LEGENDRE) { // Gauss-Legendre
110  IntrepidBurkardtRules::legendre_compute<Scalar>(numPoints_,
111  nodes.getRawPtr(),weights.getRawPtr());
112  }
113  else if (rule==BURK_PATTERSON) { // Gauss-Patterson
114  IntrepidBurkardtRules::patterson_lookup<Scalar>(numPoints_,
115  nodes.getRawPtr(),weights.getRawPtr());
116  }
117  else if (rule==BURK_TRAPEZOIDAL) { // Trapezoidal Rule
118  IntrepidBurkardtRules::trapezoidal_compute<Scalar>(numPoints_,
119  nodes.getRawPtr(),weights.getRawPtr());
120  }
121  else if (rule==BURK_HERMITE) { // Gauss-Hermite
122  IntrepidBurkardtRules::hermite_compute<Scalar>(numPoints_,
123  nodes.getRawPtr(),weights.getRawPtr());
124  }
125  else if (rule==BURK_GENZKEISTER) { // Hermite-Genz-Keister
126  IntrepidBurkardtRules::hermite_genz_keister_lookup<Scalar>(numPoints_,
127  nodes.getRawPtr(),weights.getRawPtr());
128  if (numPoints_>=37) {
129  for (int i=0; i<numPoints_; i++) {
130  weights[i] *= sqrt(M_PI);
131  }
132  }
133  }
134  else if (rule==BURK_LAGUERRE) { // Gauss-Laguerre
135  IntrepidBurkardtRules::laguerre_compute<Scalar>(numPoints_,
136  nodes.getRawPtr(),weights.getRawPtr());
137  }
138 
139  if (isNormalized) {
140  Scalar sum = 0.0;
141  for (int i=0; i<numPoints_; i++) {
142  sum += weights[i];
143  }
144  for (int i=0; i<numPoints_; i++) {
145  weights[i] /= sum;
146  }
147  }
148 
149  points_.clear(); weights_.clear();
150  typename std::map<Scalar,int>::iterator it(points_.begin());
151  for (int i=0; i<numPoints_; i++) {
152  points_.insert(it,std::pair<Scalar,int>(nodes[i],i));
153  weights_.push_back(weights[i]);
154  it = points_.end();
155  }
156 } // end constructor
157 
158 template <class Scalar, class ArrayPoint, class ArrayWeight>
160  EIntrepidBurkardt rule, int numPoints, bool isNormalized ) {
161  TEUCHOS_TEST_FOR_EXCEPTION((numPoints < 0),std::out_of_range,
162  ">>> ERROR (CubatureLineSorted): No rule implemented for desired number of points.");
163  numPoints_ = numPoints;
164  rule_type_ = rule;
165 
166  Teuchos::Array<Scalar> nodes(numPoints_), weights(numPoints_);
167  if (rule==BURK_CHEBYSHEV1) { // Gauss-Chebyshev Type 1
168  degree_ = 2*numPoints-1;
169  IntrepidBurkardtRules::chebyshev1_compute<Scalar>(numPoints_,
170  nodes.getRawPtr(),weights.getRawPtr());
171  }
172  else if (rule==BURK_CHEBYSHEV2) { // Gauss-Chebyshev Type 2
173  degree_ = 2*numPoints-1;
174  IntrepidBurkardtRules::chebyshev2_compute<Scalar>(numPoints_,
175  nodes.getRawPtr(),weights.getRawPtr());
176  }
177  else if (rule==BURK_CLENSHAWCURTIS) { // Clenshaw-Curtis
178  degree_ = numPoints-1;
179  IntrepidBurkardtRules::clenshaw_curtis_compute<Scalar>(numPoints_,
180  nodes.getRawPtr(),weights.getRawPtr());
181  }
182  else if (rule==BURK_FEJER2) { // Fejer Type 2
183  degree_ = numPoints-1;
184  IntrepidBurkardtRules::fejer2_compute<Scalar>(numPoints_,
185  nodes.getRawPtr(),weights.getRawPtr());
186  }
187  else if (rule==BURK_LEGENDRE) { // Gauss-Legendre
188  degree_ = 2*numPoints-1;
189  IntrepidBurkardtRules::legendre_compute<Scalar>(numPoints_,
190  nodes.getRawPtr(),weights.getRawPtr());
191  }
192  else if (rule==BURK_PATTERSON) { // Gauss-Patterson
193  bool correctNumPoints = false;
194  for (int i=0; i<8; i++) {
195  int l = (int)pow(2.0,(double)i+1.0)-1;
196  if (numPoints==l) {
197  correctNumPoints = true;
198  break;
199  }
200  }
201  TEUCHOS_TEST_FOR_EXCEPTION((correctNumPoints==false),std::out_of_range,
202  ">>> ERROR (CubatureLineSorted): Number of points must be numPoints = 1, 3, 7, 15, 31, 63, 127, 255.");
203  Scalar degree = 1.5*(double)numPoints+0.5;
204  degree_ = (int)degree;
205  IntrepidBurkardtRules::patterson_lookup<Scalar>(numPoints_,
206  nodes.getRawPtr(),weights.getRawPtr());
207  }
208  else if (rule==BURK_TRAPEZOIDAL) { // Trapezoidal Rule
209  degree_ = 2;
210  IntrepidBurkardtRules::trapezoidal_compute<Scalar>(numPoints_,
211  nodes.getRawPtr(),weights.getRawPtr());
212  }
213  else if (rule==BURK_HERMITE) { // Gauss-Hermite
214  degree_ = 2*numPoints-1;
215  IntrepidBurkardtRules::hermite_compute<Scalar>(numPoints_,
216  nodes.getRawPtr(),weights.getRawPtr());
217  }
218  else if (rule==BURK_GENZKEISTER) { // Hermite-Genz-Keister
219  bool correctNumPoints = false;
220  int o_ghk[8] = {1,3,9,19,35,37,41,43};
221  for (int i=0; i<8; i++) {
222  if (o_ghk[i]==numPoints) {
223  correctNumPoints = true;
224  break;
225  }
226  }
227  TEUCHOS_TEST_FOR_EXCEPTION((correctNumPoints==false),std::out_of_range,
228  ">>> ERROR (CubatureLineSorted): Number of points must be numPoints = 1, 3, 9, 35, 37, 41, 43.");
229  Scalar degree = 1.5*(double)numPoints+0.5;
230  degree_ = (int)degree;
231  IntrepidBurkardtRules::hermite_genz_keister_lookup<Scalar>(numPoints_,
232  nodes.getRawPtr(),weights.getRawPtr());
233  if (numPoints_>=37) {
234  for (int i=0; i<numPoints_; i++) {
235  weights[i] *= sqrt(M_PI);
236  }
237  }
238  }
239  else if (rule==BURK_LAGUERRE) { // Gauss-Laguerre
240  degree_ = 2*numPoints-1;
241  IntrepidBurkardtRules::laguerre_compute<Scalar>(numPoints_,
242  nodes.getRawPtr(),weights.getRawPtr());
243  }
244 
245  if (isNormalized) {
246  Scalar sum = 0.0;
247  for (int i=0; i<numPoints_; i++) {
248  sum += weights[i];
249  }
250  for (int i=0; i<numPoints_; i++) {
251  weights[i] /= sum;
252  }
253  }
254  points_.clear(); weights_.clear();
255  typename std::map<Scalar,int>::iterator it(points_.begin());
256  for (int i=0; i<numPoints; i++) {
257  points_.insert(it,std::pair<Scalar,int>(nodes[i],i));
258  weights_.push_back(weights[i]);
259  it = points_.end();
260  }
261 } // end constructor
262 
263 template <class Scalar, class ArrayPoint, class ArrayWeight>
265  std::vector<Scalar> & points, std::vector<Scalar> & weights) {
266 
267  int size = (int)weights.size();
268  TEUCHOS_TEST_FOR_EXCEPTION(((int)points.size()!=size),std::out_of_range,
269  ">>> ERROR (CubatureLineSorted): Input dimension mismatch.");
270  points_.clear(); weights.clear();
271  for (int loc=0; loc<size; loc++) {
272  points_.insert(std::pair<Scalar,int>(points[loc],loc));
273  weights_.push_back(weights[loc]);
274  }
275  numPoints_ = size;
276 }
277 
278 template <class Scalar, class ArrayPoint, class ArrayWeight>
280  return cubature_name_;
281 } // end getName
282 
283 template <class Scalar, class ArrayPoint, class ArrayWeight>
285  return numPoints_;
286 } // end getNumPoints
287 
288 template <class Scalar, class ArrayPoint, class ArrayWeight>
290  std::vector<int> & accuracy) const {
291  accuracy.assign(1, degree_);
292 } // end getAccuracy
293 
294 template <class Scalar, class ArrayPoint, class ArrayWeight>
295 const char* CubatureLineSorted<Scalar,ArrayPoint,ArrayWeight>::cubature_name_ = "INTREPID_CUBATURE_LINESORTED";
296 
297 template <class Scalar, class ArrayPoint, class ArrayWeight>
299  ArrayPoint & cubPoints, ArrayWeight & cubWeights) const {
300  typename std::map<Scalar,int>::const_iterator it;
301  int i = 0;
302  for (it = points_.begin(); it!=points_.end(); it++) {
303  cubPoints(i) = it->first;
304  cubWeights(i) = weights_[it->second];
305  i++;
306  }
307 } // end getCubature
308 
309 template <class Scalar, class ArrayPoint, class ArrayWeight>
311  return 1;
312 } // end getDimension
313 
314 template <class Scalar, class ArrayPoint, class ArrayWeight>
316  typename std::map<Scalar,int>::iterator it) {
317  return it->first;
318 } // end getNode
319 
320 template <class Scalar, class ArrayPoint, class ArrayWeight>
322  return weights_[node];
323 } // end getWeight
324 
325 template <class Scalar, class ArrayPoint, class ArrayWeight>
327  Scalar point) {
328  return weights_[points_[point]];
329 } // end getWeight
330 
331 
332 template <class Scalar, class ArrayPoint, class ArrayWeight>
333 typename std::map<Scalar,int>::iterator CubatureLineSorted<Scalar,ArrayPoint,ArrayWeight>::begin(void) {
334  return points_.begin();
335 } // end begin
336 
337 template <class Scalar, class ArrayPoint, class ArrayWeight>
338 typename std::map<Scalar,int>::iterator CubatureLineSorted<Scalar,ArrayPoint,ArrayWeight>::end(void) {
339  return points_.end();
340 } // end end
341 
342 template <class Scalar, class ArrayPoint, class ArrayWeight>
344  Scalar alpha2, CubatureLineSorted<Scalar> & cubRule2, Scalar alpha1) {
345 
346  // Initialize an iterator on std::map<Scalar,Scalar>
347  typename std::map<Scalar,int>::iterator it;
348 
349  // Temporary Container for updated rule
350  typename std::map<Scalar,int> newPoints;
351  std::vector<Scalar> newWeights;
352 
353  int loc = 0;
354  Scalar node = 0.0;
355 
356  // Set Intersection rule1 and rule2
357  typename std::map<Scalar,int> inter;
358  std::set_intersection(points_.begin(),points_.end(),
359  cubRule2.begin(),cubRule2.end(),
360  inserter(inter,inter.begin()),inter.value_comp());
361  for (it=inter.begin(); it!=inter.end(); it++) {
362  node = it->first;
363  newWeights.push_back( alpha1*weights_[it->second]
364  +alpha2*cubRule2.getWeight(node));
365  newPoints.insert(std::pair<Scalar,int>(node,loc));
366  loc++;
367  }
368  int isize = inter.size();
369 
370  // Set Difference rule1 \ rule2
371  int size = weights_.size();
372  if (isize!=size) {
373  typename std::map<Scalar,int> diff1;
374  std::set_difference(points_.begin(),points_.end(),
375  cubRule2.begin(),cubRule2.end(),
376  inserter(diff1,diff1.begin()),diff1.value_comp());
377  for (it=diff1.begin(); it!=diff1.end(); it++) {
378  node = it->first;
379  newWeights.push_back(alpha1*weights_[it->second]);
380  newPoints.insert(std::pair<Scalar,int>(node,loc));
381  loc++;
382  }
383  }
384 
385  // Set Difference rule2 \ rule1
386  size = cubRule2.getNumPoints();
387  if(isize!=size) {
388  typename std::map<Scalar,int> diff2;
389  std::set_difference(cubRule2.begin(),cubRule2.end(),
390  points_.begin(),points_.end(),
391  inserter(diff2,diff2.begin()),diff2.value_comp());
392  for (it=diff2.begin(); it!=diff2.end(); it++) {
393  node = it->first;
394  newWeights.push_back(alpha2*cubRule2.getWeight(it->second));
395  newPoints.insert(std::pair<Scalar,int>(node,loc));
396  loc++;
397  }
398  }
399 
400  points_.clear(); points_.insert(newPoints.begin(),newPoints.end());
401  weights_.clear(); weights_.assign(newWeights.begin(),newWeights.end());
402  numPoints_ = (int)points_.size();
403 }
404 
405 int growthRule1D(int index, EIntrepidGrowth growth, EIntrepidBurkardt rule) {
406  //
407  // Compute the growth sequence for 1D quadrature rules according to growth.
408  // For more information on growth rules, see
409  //
410  // J. Burkardt. 1D Quadrature Rules For Sparse Grids.
411  // http://people.sc.fsu.edu/~jburkardt/presentations/sgmga_1d_rules.pdf.
412  //
413  // J. Burkardt. SGMGA: Sparse Grid Mixed Growth Anisotropic Rules.
414  // http://people.sc.fsu.edu/~jburkardt/cpp_src/sgmga/sgmga.html.
415  //
416  // Drew P. Kouri
417  // Sandia National Laboratories - CSRI
418  // May 27, 2011
419  //
420 
421  int level = index-1;
422  //int level = index;
423  if (rule==BURK_CLENSHAWCURTIS) { // Clenshaw-Curtis
424  if (growth==GROWTH_SLOWLIN) {
425  return level+1;
426  }
427  else if (growth==GROWTH_SLOWLINODD) {
428  return 2*((level+1)/2)+1;
429  }
430  else if (growth==GROWTH_MODLIN) {
431  return 2*level+1;
432  }
433  else if (growth==GROWTH_SLOWEXP) {
434  if (level==0) {
435  return 1;
436  }
437  else {
438  int o = 2;
439  while(o<2*level+1) {
440  o = 2*(o-1)+1;
441  }
442  return o;
443  }
444  }
445  else if (growth==GROWTH_MODEXP||growth==GROWTH_DEFAULT) {
446  if (level==0) {
447  return 1;
448  }
449  else {
450  int o = 2;
451  while (o<4*level+1) {
452  o = 2*(o-1)+1;
453  }
454  return o;
455  }
456  }
457  else if (growth==GROWTH_FULLEXP) {
458  if (level==0) {
459  return 1;
460  }
461  else {
462  return (int)pow(2.0,(double)level)+1;
463  }
464  }
465  }
466  else if (rule==BURK_FEJER2) { // Fejer Type 2
467  if (growth==GROWTH_SLOWLIN) {
468  return level+1;
469  }
470  else if (growth==GROWTH_SLOWLINODD) {
471  return 2*((level+1)/2)+1;
472  }
473  else if (growth==GROWTH_MODLIN) {
474  return 2*level+1;
475  }
476  else if (growth==GROWTH_SLOWEXP) {
477  int o = 1;
478  while (o<2*level+1) {
479  o = 2*o+1;
480  }
481  return o;
482  }
483  else if (growth==GROWTH_MODEXP||growth==GROWTH_DEFAULT) {
484  int o = 1;
485  while (o<4*level+1) {
486  o = 2*o+1;
487  }
488  return o;
489  }
490  else if (growth==GROWTH_FULLEXP) {
491  return (int)pow(2.0,(double)level+1.0)-1;
492  }
493  }
494 
495  else if (rule==BURK_PATTERSON) { // Gauss-Patterson
496  if (growth==GROWTH_SLOWLIN||
497  growth==GROWTH_SLOWLINODD||
498  growth==GROWTH_MODLIN) {
499  std::cout << "Specified Growth Rule Not Allowed!\n";
500  return 0;
501  }
502  else if (growth==GROWTH_SLOWEXP) {
503  if (level==0) {
504  return 1;
505  }
506  else {
507  int p = 5;
508  int o = 3;
509  while (p<2*level+1) {
510  p = 2*p+1;
511  o = 2*o+1;
512  }
513  return o;
514  }
515  }
516  else if (growth==GROWTH_MODEXP||growth==GROWTH_DEFAULT) {
517  if (level==0) {
518  return 1;
519  }
520  else {
521  int p = 5;
522  int o = 3;
523  while (p<4*level+1) {
524  p = 2*p+1;
525  o = 2*o+1;
526  }
527  return o;
528  }
529  }
530  else if (growth==GROWTH_FULLEXP) {
531  return (int)pow(2.0,(double)level+1.0)-1;
532  }
533  }
534 
535  else if (rule==BURK_LEGENDRE) { // Gauss-Legendre
536  if (growth==GROWTH_SLOWLIN) {
537  return level+1;
538  }
539  else if (growth==GROWTH_SLOWLINODD) {
540  return 2*((level+1)/2)+1;
541  }
542  else if (growth==GROWTH_MODLIN||growth==GROWTH_DEFAULT) {
543  return 2*level+1;
544  }
545  else if (growth==GROWTH_SLOWEXP) {
546  int o = 1;
547  while (2*o-1<2*level+1) {
548  o = 2*o+1;
549  }
550  return o;
551  }
552  else if (growth==GROWTH_MODEXP) {
553  int o = 1;
554  while (2*o-1<4*level+1) {
555  o = 2*o+1;
556  }
557  return o;
558  }
559  else if (growth==GROWTH_FULLEXP) {
560  return (int)pow(2.0,(double)level+1.0)-1;
561  }
562  }
563 
564  else if (rule==BURK_HERMITE) { // Gauss-Hermite
565  if (growth==GROWTH_SLOWLIN) {
566  return level+1;
567  }
568  else if (growth==GROWTH_SLOWLINODD) {
569  return 2*((level+1)/2)+1;
570  }
571  else if (growth==GROWTH_MODLIN||growth==GROWTH_DEFAULT) {
572  return 2*level+1;
573  }
574  else if (growth==GROWTH_SLOWEXP) {
575  int o = 1;
576  while (2*o-1<2*level+1) {
577  o = 2*o+1;
578  }
579  return o;
580  }
581  else if (growth==GROWTH_MODEXP) {
582  int o = 1;
583  while (2*o-1<4*level+1) {
584  o = 2*o+1;
585  }
586  return o;
587  }
588  else if (growth==GROWTH_FULLEXP) {
589  return (int)pow(2.0,(double)level+1.0)-1;
590  }
591  }
592 
593  else if (rule==BURK_LAGUERRE) { // Gauss-Laguerre
594  if (growth==GROWTH_SLOWLIN) {
595  return level+1;
596  }
597  else if (growth==GROWTH_SLOWLINODD) {
598  return 2*((level+1)/2)+1;
599  }
600  else if (growth==GROWTH_MODLIN||growth==GROWTH_DEFAULT) {
601  return 2*level+1;
602  }
603  else if (growth==GROWTH_SLOWEXP) {
604  int o = 1;
605  while (2*o-1<2*level+1) {
606  o = 2*o+1;
607  }
608  return o;
609  }
610  else if (growth==GROWTH_MODEXP) {
611  int o = 1;
612  while (2*o-1<4*level+1) {
613  o = 2*o+1;
614  }
615  return o;
616  }
617  else if (growth==GROWTH_FULLEXP) {
618  return (int)pow(2.0,(double)level+1.0)-1;
619  }
620  }
621 
622  else if (rule==BURK_CHEBYSHEV1) { // Gauss-Chebyshev Type 1
623  if (growth==GROWTH_SLOWLIN) {
624  return level+1;
625  }
626  else if (growth==GROWTH_SLOWLINODD) {
627  return 2*((level+1)/2)+1;
628  }
629  else if (growth==GROWTH_MODLIN||growth==GROWTH_DEFAULT) {
630  return 2*level+1;
631  }
632  else if (growth==GROWTH_SLOWEXP) {
633  int o = 1;
634  while (2*o-1<2*level+1) {
635  o = 2*o+1;
636  }
637  return o;
638  }
639  else if (growth==GROWTH_MODEXP) {
640  int o = 1;
641  while (2*o-1<4*level+1) {
642  o = 2*o+1;
643  }
644  return o;
645  }
646  else if (growth==GROWTH_FULLEXP) {
647  return (int)pow(2.0,(double)level+1.0)-1;
648  }
649  }
650 
651 
652  else if (rule==BURK_CHEBYSHEV2) { // Gauss-Chebyshev Type 2
653  if (growth==GROWTH_SLOWLIN) {
654  return level+1;
655  }
656  else if (growth==GROWTH_SLOWLINODD) {
657  return 2*((level+1)/2)+1;
658  }
659  else if (growth==GROWTH_MODLIN||growth==GROWTH_DEFAULT) {
660  return 2*level+1;
661  }
662  else if (growth==GROWTH_SLOWEXP) {
663  int o = 1;
664  while (2*o-1<2*level+1) {
665  o = 2*o+1;
666  }
667  return o;
668  }
669  else if (growth==GROWTH_MODEXP) {
670  int o = 1;
671  while (2*o-1<4*level+1) {
672  o = 2*o+1;
673  }
674  return o;
675  }
676  else if (growth==GROWTH_FULLEXP) {
677  return (int)pow(2.0,(double)level+1.0)-1;
678  }
679  }
680 
681  else if (rule==BURK_GENZKEISTER) { // Hermite-Genz-Keister
682  static int o_hgk[5] = { 1, 3, 9, 19, 35 };
683  static int p_hgk[5] = { 1, 5, 15, 29, 51 };
684  if (growth==GROWTH_SLOWLIN||
685  growth==GROWTH_SLOWLINODD||
686  growth==GROWTH_MODLIN) {
687  std::cout << "Specified Growth Rule Not Allowed!\n";
688  return 0;
689  }
690  else if (growth==GROWTH_SLOWEXP) {
691  int l = 0, p = p_hgk[l], o = o_hgk[l];
692  while (p<2*level+1 && l<4) {
693  l++;
694  p = p_hgk[l];
695  o = o_hgk[l];
696  }
697  return o;
698  }
699  else if (growth==GROWTH_MODEXP||growth==GROWTH_DEFAULT) {
700  int l = 0, p = p_hgk[l], o = o_hgk[l];
701  while (p<4*level+1 && l<4) {
702  l++;
703  p = p_hgk[l];
704  o = o_hgk[l];
705  }
706  return o;
707  }
708  else if (growth==GROWTH_FULLEXP) {
709  int l = level; l = std::max(l,0); l = std::min(l,4);
710  return o_hgk[l];
711  }
712  }
713 
714  else if (rule==BURK_TRAPEZOIDAL) { // Trapezoidal
715  if (growth==GROWTH_SLOWLIN) {
716  return level+1;
717  }
718  else if (growth==GROWTH_SLOWLINODD) {
719  return 2*((level+1)/2)+1;
720  }
721  else if (growth==GROWTH_MODLIN) {
722  return 2*level+1;
723  }
724  else if (growth==GROWTH_SLOWEXP) {
725  if (level==0) {
726  return 1;
727  }
728  else {
729  int o = 2;
730  while(o<2*level+1) {
731  o = 2*(o-1)+1;
732  }
733  return o;
734  }
735  }
736  else if (growth==GROWTH_MODEXP||growth==GROWTH_DEFAULT) {
737  if (level==0) {
738  return 1;
739  }
740  else {
741  int o = 2;
742  while (o<4*level+1) {
743  o = 2*(o-1)+1;
744  }
745  return o;
746  }
747  }
748  else if (growth==GROWTH_FULLEXP) {
749  if (level==0) {
750  return 1;
751  }
752  else {
753  return (int)pow(2.0,(double)level)+1;
754  }
755  }
756  }
757  return 0;
758 } // end growthRule1D
759 
760 } // Intrepid namespace
CubatureLineSorted(int degree=0, EIntrepidBurkardt rule=BURK_CLENSHAWCURTIS, bool isNormalized=false)
Constructor.
Utilizes cubature (integration) rules contained in the library sandia_rules (John Burkardt...
std::map< Scalar, int >::iterator begin(void)
Initiate iterator at the beginning of data.
void update(Scalar alpha2, CubatureLineSorted< Scalar > &cubRule2, Scalar alpha1)
Replace CubatureLineSorted values with &quot;this = alpha1*this+alpha2*cubRule2&quot;.
void getAccuracy(std::vector< int > &accuracy) const
Returns max. degree of polynomials that are integrated exactly. The return vector has size 1...
void getCubature(ArrayPoint &cubPoints, ArrayWeight &cubWeights) const
Returns cubature points and weights (return arrays must be pre-sized/pre-allocated).
int getNumPoints() const
Returns the number of cubature points.
int getDimension() const
Returns dimension of domain of integration.
Scalar getNode(typename std::map< Scalar, int >::iterator it)
Get a specific node described by the iterator location.
const char * getName() const
Returns cubature name.
Scalar getWeight(int weight)
Get a specific weight described by the integer location.
std::map< Scalar, int >::iterator end(void)
Initiate iterator at the end of data.