51 template <
class Scalar,
class ArrayPo
int,
class ArrayWeight>
54 TEUCHOS_TEST_FOR_EXCEPTION((degree < 0),std::out_of_range,
55 ">>> ERROR (CubatureLineSorted): No rule implemented for desired polynomial degree.");
59 if (rule==BURK_CHEBYSHEV1||rule==BURK_CHEBYSHEV2||
60 rule==BURK_LAGUERRE ||rule==BURK_LEGENDRE ||
62 numPoints_ = (degree+1)/2+1;
64 else if (rule==BURK_CLENSHAWCURTIS||rule==BURK_FEJER2) {
65 numPoints_ = degree+1;
67 else if (rule==BURK_TRAPEZOIDAL) {
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;
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++) {
85 numPoints_ = o_ghk[i];
91 Teuchos::Array<Scalar> nodes(numPoints_), weights(numPoints_);
93 if (rule==BURK_CHEBYSHEV1) {
94 IntrepidBurkardtRules::chebyshev1_compute<Scalar>(numPoints_,
95 nodes.getRawPtr(),weights.getRawPtr());
97 else if (rule==BURK_CHEBYSHEV2) {
98 IntrepidBurkardtRules::chebyshev2_compute<Scalar>(numPoints_,
99 nodes.getRawPtr(),weights.getRawPtr());
101 else if (rule==BURK_CLENSHAWCURTIS) {
102 IntrepidBurkardtRules::clenshaw_curtis_compute<Scalar>(numPoints_,
103 nodes.getRawPtr(),weights.getRawPtr());
105 else if (rule==BURK_FEJER2) {
106 IntrepidBurkardtRules::fejer2_compute<Scalar>(numPoints_,
107 nodes.getRawPtr(),weights.getRawPtr());
109 else if (rule==BURK_LEGENDRE) {
110 IntrepidBurkardtRules::legendre_compute<Scalar>(numPoints_,
111 nodes.getRawPtr(),weights.getRawPtr());
113 else if (rule==BURK_PATTERSON) {
114 IntrepidBurkardtRules::patterson_lookup<Scalar>(numPoints_,
115 nodes.getRawPtr(),weights.getRawPtr());
117 else if (rule==BURK_TRAPEZOIDAL) {
118 IntrepidBurkardtRules::trapezoidal_compute<Scalar>(numPoints_,
119 nodes.getRawPtr(),weights.getRawPtr());
121 else if (rule==BURK_HERMITE) {
122 IntrepidBurkardtRules::hermite_compute<Scalar>(numPoints_,
123 nodes.getRawPtr(),weights.getRawPtr());
125 else if (rule==BURK_GENZKEISTER) {
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);
134 else if (rule==BURK_LAGUERRE) {
135 IntrepidBurkardtRules::laguerre_compute<Scalar>(numPoints_,
136 nodes.getRawPtr(),weights.getRawPtr());
141 for (
int i=0; i<numPoints_; i++) {
144 for (
int i=0; i<numPoints_; i++) {
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]);
158 template <
class Scalar,
class ArrayPo
int,
class ArrayWeight>
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;
166 Teuchos::Array<Scalar> nodes(numPoints_), weights(numPoints_);
167 if (rule==BURK_CHEBYSHEV1) {
168 degree_ = 2*numPoints-1;
169 IntrepidBurkardtRules::chebyshev1_compute<Scalar>(numPoints_,
170 nodes.getRawPtr(),weights.getRawPtr());
172 else if (rule==BURK_CHEBYSHEV2) {
173 degree_ = 2*numPoints-1;
174 IntrepidBurkardtRules::chebyshev2_compute<Scalar>(numPoints_,
175 nodes.getRawPtr(),weights.getRawPtr());
177 else if (rule==BURK_CLENSHAWCURTIS) {
178 degree_ = numPoints-1;
179 IntrepidBurkardtRules::clenshaw_curtis_compute<Scalar>(numPoints_,
180 nodes.getRawPtr(),weights.getRawPtr());
182 else if (rule==BURK_FEJER2) {
183 degree_ = numPoints-1;
184 IntrepidBurkardtRules::fejer2_compute<Scalar>(numPoints_,
185 nodes.getRawPtr(),weights.getRawPtr());
187 else if (rule==BURK_LEGENDRE) {
188 degree_ = 2*numPoints-1;
189 IntrepidBurkardtRules::legendre_compute<Scalar>(numPoints_,
190 nodes.getRawPtr(),weights.getRawPtr());
192 else if (rule==BURK_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;
197 correctNumPoints =
true;
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());
208 else if (rule==BURK_TRAPEZOIDAL) {
210 IntrepidBurkardtRules::trapezoidal_compute<Scalar>(numPoints_,
211 nodes.getRawPtr(),weights.getRawPtr());
213 else if (rule==BURK_HERMITE) {
214 degree_ = 2*numPoints-1;
215 IntrepidBurkardtRules::hermite_compute<Scalar>(numPoints_,
216 nodes.getRawPtr(),weights.getRawPtr());
218 else if (rule==BURK_GENZKEISTER) {
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;
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);
239 else if (rule==BURK_LAGUERRE) {
240 degree_ = 2*numPoints-1;
241 IntrepidBurkardtRules::laguerre_compute<Scalar>(numPoints_,
242 nodes.getRawPtr(),weights.getRawPtr());
247 for (
int i=0; i<numPoints_; i++) {
250 for (
int i=0; i<numPoints_; i++) {
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]);
263 template <
class Scalar,
class ArrayPo
int,
class ArrayWeight>
265 std::vector<Scalar> & points, std::vector<Scalar> & weights) {
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]);
278 template <
class Scalar,
class ArrayPo
int,
class ArrayWeight>
280 return cubature_name_;
283 template <
class Scalar,
class ArrayPo
int,
class ArrayWeight>
288 template <
class Scalar,
class ArrayPo
int,
class ArrayWeight>
290 std::vector<int> & accuracy)
const {
291 accuracy.assign(1, degree_);
294 template <
class Scalar,
class ArrayPo
int,
class ArrayWeight>
297 template <
class Scalar,
class ArrayPo
int,
class ArrayWeight>
299 ArrayPoint & cubPoints, ArrayWeight & cubWeights)
const {
300 typename std::map<Scalar,int>::const_iterator it;
302 for (it = points_.begin(); it!=points_.end(); it++) {
303 cubPoints(i) = it->first;
304 cubWeights(i) = weights_[it->second];
309 template <
class Scalar,
class ArrayPo
int,
class ArrayWeight>
314 template <
class Scalar,
class ArrayPo
int,
class ArrayWeight>
316 typename std::map<Scalar,int>::iterator it) {
320 template <
class Scalar,
class ArrayPo
int,
class ArrayWeight>
322 return weights_[node];
325 template <
class Scalar,
class ArrayPo
int,
class ArrayWeight>
328 return weights_[points_[point]];
332 template <
class Scalar,
class ArrayPo
int,
class ArrayWeight>
334 return points_.begin();
337 template <
class Scalar,
class ArrayPo
int,
class ArrayWeight>
339 return points_.end();
342 template <
class Scalar,
class ArrayPo
int,
class ArrayWeight>
347 typename std::map<Scalar,int>::iterator it;
350 typename std::map<Scalar,int> newPoints;
351 std::vector<Scalar> newWeights;
357 typename std::map<Scalar,int> inter;
358 std::set_intersection(points_.begin(),points_.end(),
360 inserter(inter,inter.begin()),inter.value_comp());
361 for (it=inter.begin(); it!=inter.end(); it++) {
363 newWeights.push_back( alpha1*weights_[it->second]
365 newPoints.insert(std::pair<Scalar,int>(node,loc));
368 int isize = inter.size();
371 int size = weights_.size();
373 typename std::map<Scalar,int> diff1;
374 std::set_difference(points_.begin(),points_.end(),
376 inserter(diff1,diff1.begin()),diff1.value_comp());
377 for (it=diff1.begin(); it!=diff1.end(); it++) {
379 newWeights.push_back(alpha1*weights_[it->second]);
380 newPoints.insert(std::pair<Scalar,int>(node,loc));
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++) {
394 newWeights.push_back(alpha2*cubRule2.
getWeight(it->second));
395 newPoints.insert(std::pair<Scalar,int>(node,loc));
400 points_.clear(); points_.insert(newPoints.begin(),newPoints.end());
401 weights_.clear(); weights_.assign(newWeights.begin(),newWeights.end());
402 numPoints_ = (int)points_.size();
423 if (rule==BURK_CLENSHAWCURTIS) {
424 if (growth==GROWTH_SLOWLIN) {
427 else if (growth==GROWTH_SLOWLINODD) {
428 return 2*((level+1)/2)+1;
430 else if (growth==GROWTH_MODLIN) {
433 else if (growth==GROWTH_SLOWEXP) {
445 else if (growth==GROWTH_MODEXP||growth==GROWTH_DEFAULT) {
451 while (o<4*level+1) {
457 else if (growth==GROWTH_FULLEXP) {
462 return (
int)pow(2.0,(
double)level)+1;
466 else if (rule==BURK_FEJER2) {
467 if (growth==GROWTH_SLOWLIN) {
470 else if (growth==GROWTH_SLOWLINODD) {
471 return 2*((level+1)/2)+1;
473 else if (growth==GROWTH_MODLIN) {
476 else if (growth==GROWTH_SLOWEXP) {
478 while (o<2*level+1) {
483 else if (growth==GROWTH_MODEXP||growth==GROWTH_DEFAULT) {
485 while (o<4*level+1) {
490 else if (growth==GROWTH_FULLEXP) {
491 return (
int)pow(2.0,(
double)level+1.0)-1;
495 else if (rule==BURK_PATTERSON) {
496 if (growth==GROWTH_SLOWLIN||
497 growth==GROWTH_SLOWLINODD||
498 growth==GROWTH_MODLIN) {
499 std::cout <<
"Specified Growth Rule Not Allowed!\n";
502 else if (growth==GROWTH_SLOWEXP) {
509 while (p<2*level+1) {
516 else if (growth==GROWTH_MODEXP||growth==GROWTH_DEFAULT) {
523 while (p<4*level+1) {
530 else if (growth==GROWTH_FULLEXP) {
531 return (
int)pow(2.0,(
double)level+1.0)-1;
535 else if (rule==BURK_LEGENDRE) {
536 if (growth==GROWTH_SLOWLIN) {
539 else if (growth==GROWTH_SLOWLINODD) {
540 return 2*((level+1)/2)+1;
542 else if (growth==GROWTH_MODLIN||growth==GROWTH_DEFAULT) {
545 else if (growth==GROWTH_SLOWEXP) {
547 while (2*o-1<2*level+1) {
552 else if (growth==GROWTH_MODEXP) {
554 while (2*o-1<4*level+1) {
559 else if (growth==GROWTH_FULLEXP) {
560 return (
int)pow(2.0,(
double)level+1.0)-1;
564 else if (rule==BURK_HERMITE) {
565 if (growth==GROWTH_SLOWLIN) {
568 else if (growth==GROWTH_SLOWLINODD) {
569 return 2*((level+1)/2)+1;
571 else if (growth==GROWTH_MODLIN||growth==GROWTH_DEFAULT) {
574 else if (growth==GROWTH_SLOWEXP) {
576 while (2*o-1<2*level+1) {
581 else if (growth==GROWTH_MODEXP) {
583 while (2*o-1<4*level+1) {
588 else if (growth==GROWTH_FULLEXP) {
589 return (
int)pow(2.0,(
double)level+1.0)-1;
593 else if (rule==BURK_LAGUERRE) {
594 if (growth==GROWTH_SLOWLIN) {
597 else if (growth==GROWTH_SLOWLINODD) {
598 return 2*((level+1)/2)+1;
600 else if (growth==GROWTH_MODLIN||growth==GROWTH_DEFAULT) {
603 else if (growth==GROWTH_SLOWEXP) {
605 while (2*o-1<2*level+1) {
610 else if (growth==GROWTH_MODEXP) {
612 while (2*o-1<4*level+1) {
617 else if (growth==GROWTH_FULLEXP) {
618 return (
int)pow(2.0,(
double)level+1.0)-1;
622 else if (rule==BURK_CHEBYSHEV1) {
623 if (growth==GROWTH_SLOWLIN) {
626 else if (growth==GROWTH_SLOWLINODD) {
627 return 2*((level+1)/2)+1;
629 else if (growth==GROWTH_MODLIN||growth==GROWTH_DEFAULT) {
632 else if (growth==GROWTH_SLOWEXP) {
634 while (2*o-1<2*level+1) {
639 else if (growth==GROWTH_MODEXP) {
641 while (2*o-1<4*level+1) {
646 else if (growth==GROWTH_FULLEXP) {
647 return (
int)pow(2.0,(
double)level+1.0)-1;
652 else if (rule==BURK_CHEBYSHEV2) {
653 if (growth==GROWTH_SLOWLIN) {
656 else if (growth==GROWTH_SLOWLINODD) {
657 return 2*((level+1)/2)+1;
659 else if (growth==GROWTH_MODLIN||growth==GROWTH_DEFAULT) {
662 else if (growth==GROWTH_SLOWEXP) {
664 while (2*o-1<2*level+1) {
669 else if (growth==GROWTH_MODEXP) {
671 while (2*o-1<4*level+1) {
676 else if (growth==GROWTH_FULLEXP) {
677 return (
int)pow(2.0,(
double)level+1.0)-1;
681 else if (rule==BURK_GENZKEISTER) {
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";
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) {
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) {
708 else if (growth==GROWTH_FULLEXP) {
709 int l = level; l = std::max(l,0); l = std::min(l,4);
714 else if (rule==BURK_TRAPEZOIDAL) {
715 if (growth==GROWTH_SLOWLIN) {
718 else if (growth==GROWTH_SLOWLINODD) {
719 return 2*((level+1)/2)+1;
721 else if (growth==GROWTH_MODLIN) {
724 else if (growth==GROWTH_SLOWEXP) {
736 else if (growth==GROWTH_MODEXP||growth==GROWTH_DEFAULT) {
742 while (o<4*level+1) {
748 else if (growth==GROWTH_FULLEXP) {
753 return (
int)pow(2.0,(
double)level)+1;
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 "this = alpha1*this+alpha2*cubRule2".
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.
EIntrepidBurkardt
Enumeration of integration rules provided by John Burkardt.
std::map< Scalar, int >::iterator end(void)
Initiate iterator at the end of data.