MUQ  0.4.3
FullTensorQuadrature.cpp
Go to the documentation of this file.
2 
4 #include <iostream>
5 
6 using namespace muq::Approximation;
7 using namespace muq::Utilities;
8 
10  std::shared_ptr<Quadrature> const& rule,
11  unsigned int order) : FullTensorQuadrature(std::vector<std::shared_ptr<Quadrature>>(dim,rule),
12  order*Eigen::RowVectorXi::Ones(dim)){};
13 
15  std::shared_ptr<Quadrature> const& rule) : FullTensorQuadrature(std::vector<std::shared_ptr<Quadrature>>(dim,rule)){};
16 
17 
18 FullTensorQuadrature::FullTensorQuadrature(std::vector<std::shared_ptr<Quadrature>> const& rulesIn,
19  Eigen::RowVectorXi orders) : Quadrature(rulesIn.size()),
20  rules(rulesIn)
21 {
22  for(int i=0; i<rules.size(); ++i)
23  assert(rules.at(i)->Dim()==1);
24 
25  // If the quadrature orders are specified, call Compute
26  if(orders.size()>0){
27  assert(rulesIn.size()==orders.size());
28  Compute(orders);
29  }
30 }
31 
32 void FullTensorQuadrature::Compute(unsigned int order)
33 {
34  Compute(order*Eigen::RowVectorXi::Ones(dim));
35 }
36 
37 void FullTensorQuadrature::Compute(Eigen::RowVectorXi const& orders) {
38 
39  assert(orders.size()==dim);
40 
41  Eigen::RowVectorXi tensorOrders(dim);
42 
43  // Compute the points and weights from the 1d rules
44  std::vector<Eigen::MatrixXd> allPts(dim);
45  std::vector<Eigen::VectorXd> allWts(dim);
46  for(int i = 0; i<dim; ++i){
47  rules.at(i)->Compute(orders(i));
48  allPts.at(i) = rules.at(i)->Points();
49  allWts.at(i) = rules.at(i)->Weights();
50 
51  tensorOrders(i) = allPts.at(i).cols()-1;
52  }
53 
54  // First, compute all of the multiindices
55  auto multis = MultiIndexFactory::CreateFullTensor(tensorOrders);
56 
57  // Now compute all the terms
58  pts.resize(dim,multis->Size());
59  wts = Eigen::VectorXd::Ones(multis->Size());
60 
61  for(int i=0; i<multis->Size(); ++i){
62  auto& multi = multis->IndexToMulti(i);
63 
64  for(int d=0; d<dim; ++d){
65  wts(i) *= allWts.at(d)(multi->GetValue(d));
66  pts(d,i) = allPts.at(d)(0,multi->GetValue(d));
67  }
68  }
69 
70 }
71 
72 unsigned int FullTensorQuadrature::Exactness(unsigned int quadOrder) const {
73 
74  unsigned int maxOrder = 0;
75  for(auto& rule : rules)
76  maxOrder = std::max(maxOrder, rule->Exactness(quadOrder));
77 
78  return maxOrder;
79 }
Multivariate quadrature rule defined by the tensor product of 1d rules.
virtual unsigned int Exactness(unsigned int quadOrder) const override
std::vector< std::shared_ptr< Quadrature > > rules
FullTensorQuadrature(unsigned int dim, std::shared_ptr< Quadrature > const &rules)
virtual void Compute(unsigned int order) override
Base class for multivariate quadrature rules. @detail An abstract class for computing nodes and weigh...
Definition: Quadrature.h:124