queso-0.57.1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Pages
QUESO::TensorProductQuadrature< V, M > Class Template Reference

Numerical quadrature using a tensor product of Base1DQuadrature rules. More...

#include <TensorProductQuadrature.h>

Inheritance diagram for QUESO::TensorProductQuadrature< V, M >:
QUESO::MultiDQuadratureBase< V, M > QUESO::BaseQuadrature

Public Member Functions

 TensorProductQuadrature (const VectorSubset< V, M > &domain, const std::vector< QUESO::SharedPtr< Base1DQuadrature >::Type > &q_rules)
 
virtual ~TensorProductQuadrature ()
 
- Public Member Functions inherited from QUESO::MultiDQuadratureBase< V, M >
 MultiDQuadratureBase (const VectorSubset< V, M > &domain)
 
virtual ~MultiDQuadratureBase ()=0
 Pure virtual destructor, forcing this to be an abstract object. More...
 
const std::vector< typename
QUESO::SharedPtr< V >::Type > & 
positions () const
 
const VectorSubset< V, M > & getDomain () const
 
- Public Member Functions inherited from QUESO::BaseQuadrature
 BaseQuadrature ()
 
virtual ~BaseQuadrature ()=0
 Pure virtual destructor, forcing this to be an abstract object. More...
 
const std::vector< double > & weights () const
 Array of the weights used in the numerical integration. More...
 

Additional Inherited Members

- Protected Attributes inherited from QUESO::MultiDQuadratureBase< V, M >
std::vector< typename
QUESO::SharedPtr< V >::Type > 
m_positions
 Locations of quadrature points. More...
 
const VectorSubset< V, M > & m_domain
 Domain over which the quadrature will be performed. More...
 
- Protected Attributes inherited from QUESO::BaseQuadrature
std::vector< double > m_weights
 

Detailed Description

template<class V = GslVector, class M = GslMatrix>
class QUESO::TensorProductQuadrature< V, M >

Numerical quadrature using a tensor product of Base1DQuadrature rules.

The user constructs a vector of Base1DQuadrature rules from which this class will construct a multi-dimensional quadrature rule using a tensor product of the one-dimensional rules. Thus, the dimension of this tensor product rule will be the size of the vector of one-dimensional rules provided by the user and, therefore, should match the dimension of the domain also supplied by the user.

Definition at line 47 of file TensorProductQuadrature.h.

Constructor & Destructor Documentation

template<class V , class M >
QUESO::TensorProductQuadrature< V, M >::TensorProductQuadrature ( const VectorSubset< V, M > &  domain,
const std::vector< QUESO::SharedPtr< Base1DQuadrature >::Type > &  q_rules 
)

Definition at line 36 of file TensorProductQuadrature.C.

References dim, QUESO::MultiDimensionalIndexing::globalToCoord(), QUESO::MultiDQuadratureBase< V, M >::m_positions, QUESO::BaseQuadrature::m_weights, QUESO::queso_require_equal_to_msg, and QUESO::VectorSubset< V, M >::vectorSpace().

38  : MultiDQuadratureBase<V,M>(domain)
39  {
40  const unsigned int dim = domain.vectorSpace().dimGlobal();
41 
42  queso_require_equal_to_msg(dim, q_rules.size(), "Mismatched quadrature rule size and vector space dimension!");
43 
44  // We figure the number of q_points in each dimension and the total
45  unsigned int total_n_q_points = 1;
46  std::vector<unsigned int> n_q_points(dim);
47  for( unsigned int i = 0; i < dim; i++ )
48  {
49  n_q_points[i] = q_rules[i]->positions().size();
50  total_n_q_points *= q_rules[i]->positions().size();
51  }
52 
53  this->m_positions.resize(total_n_q_points,SharedPtr<GslVector>::Type());
54  this->m_weights.resize(total_n_q_points);
55 
56  // The positions are just a tensor product of the positions for each of the 1-D rules.
57  // Thus, we leverage the MultiDimensionalIndexing to move from "global" quadrature point
58  // number to the index in each of the dimensions. Each of these dimensional indices tells
59  // us which component of the corresponding 1-D rule to extract.
60  // The final quadrature weight will be the product of each of the corresponding weights
61  // for the 1-D rule, with the correspondence dictated by the "local" index in that dimension
62  // (as with the position).
63  std::vector<unsigned int> indices(dim);
64  for( unsigned int q = 0; q < total_n_q_points; q++ )
65  {
66  MultiDimensionalIndexing::globalToCoord( q, n_q_points, indices );
67 
68  // Make sure indices size isn't something we don't expect after population
69  queso_assert_equal_to(indices.size(),dim);
70 
71  // Create new vector from our vector space
72  // We are taking ownership of this pointer.
73  typename QUESO::SharedPtr<V>::Type domain_vec(domain.vectorSpace().newVector());
74 
75  // Now populate the weights and positions
76  double weight = 1.0;
77  for( unsigned int i = 0; i < dim; i++ )
78  {
79  unsigned int idx = indices[i];
80  (*domain_vec)[i] = q_rules[i]->positions()[idx];
81  weight *= q_rules[i]->weights()[idx];
82  }
83 
84  // m_positions is taking ownership of the V*
85  this->m_positions[q] = domain_vec;
86  this->m_weights[q] = weight;
87  }
88  }
std::shared_ptr< T > Type
Definition: SharedPtr.h:69
static void globalToCoord(unsigned int global, const std::vector< unsigned int > &n_points, std::vector< unsigned int > &coord_indices)
Inverse of coordToGlobal map.
std::vector< double > m_weights
Definition of a shared pointer.
int dim
Definition: ann_test.cpp:472
MonteCarloSGOptions::MonteCarloSGOptions(const BaseEnvironment &env, const char *prefix, const McOptionsValues &alternativeOptionsValues queso_require_equal_to_msg)(m_env.optionsInputFileName(), std::string(""), std::string("this constructor is incompatible with the existence of an options input file"))
std::vector< typename QUESO::SharedPtr< V >::Type > m_positions
Locations of quadrature points.
template<class V = GslVector, class M = GslMatrix>
virtual QUESO::TensorProductQuadrature< V, M >::~TensorProductQuadrature ( )
inlinevirtual

Definition at line 54 of file TensorProductQuadrature.h.

54 {}

The documentation for this class was generated from the following files:

Generated on Tue Jun 5 2018 19:49:21 for queso-0.57.1 by  doxygen 1.8.5