G+Smo  24.08.0
Geometry + Simulation Modules
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
gsQuadRule.hpp
Go to the documentation of this file.
1 
14 #pragma once
15 
16 #include <gsUtils/gsPointGrid.h>
18 
19 namespace gismo
20 {
21 
22 
23 template<class T> void
24 gsQuadRule<T>::mapTo( T startVal, T endVal,
25  gsMatrix<T> & nodes, gsVector<T> & weights ) const
26 {
27  GISMO_ASSERT( 1 == m_nodes.rows(), "Inconsistent quadrature mapping");
28 
29  const T h = (endVal-startVal) / (T)(2);
30 
31  // Linear map from [-1,1]^d to [startVal,endVal]
32  nodes = (h * (m_nodes.array()+1)) + startVal;
33 
34  // Adjust the weights (multiply by the Jacobian of the linear map)
35  weights.noalias() = (0==h?T(0.5):h) * m_weights;
36 }
37 
38 // Note: left here for inlining
39 template<class T> void
41  gsMatrix<T> & nodes) const
42 {
43  GISMO_ASSERT( ab.rows() == m_nodes.rows(), "Inconsistent quadrature mapping");
44  nodes.resize( m_nodes.rows(), m_nodes.cols() );
45  nodes.setZero();
46  const gsVector<T> h = (ab.col(1)-ab.col(0)) / (T)(2) ;
47  nodes.noalias() = ( h.asDiagonal() * (m_nodes.array()+1).matrix() ).colwise() + ab.col(0);
48 }
49 
50 
51 template<class T> void
52 gsQuadRule<T>::mapToAll( const std::vector<T> & breaks,
53  gsMatrix<T> & nodes, gsVector<T> & weights ) const
54 {
55  GISMO_ASSERT( 1 == m_nodes.rows(), "Inconsistent quadrature mapping.");
56  GISMO_ASSERT( breaks.size()>1, "At least 2 breaks are needed.");
57 
58  const size_t nint = breaks.size() - 1;
59  const index_t nnodes = numNodes();
60 
61  nodes .resize(1, nint*nnodes);
62  weights.resize( nint*nnodes );
63 
64  for ( size_t i = 0; i!=nint; ++i)
65  {
66  const T startVal = breaks[i ];
67  const T endVal = breaks[i+1];
68  const T h = (endVal-startVal) / (T)(2);
69 
70  // Linear map from [-1,1]^d to [startVal,endVal]
71  nodes.middleCols(i*nnodes,nnodes) = (h * (m_nodes.array()+1)) + startVal;
72 
73  // Adjust the weights (multiply by the Jacobian of the linear map)
74  weights.segment(i*nnodes,nnodes) = (0==h?T(0.5):h) * m_weights;
75  }
76 }
77 
78 
79 template<class T> void
81  const std::vector<gsVector<T> > & weights)
82 {
83  this->computeTensorProductRule_into(nodes,weights,m_nodes,m_weights);
84 }
85 
86 template<class T> void
88  const std::vector<gsVector<T> > & weights,
89  gsMatrix<T> & targetNodes,
90  gsVector<T> & targetWeights) const
91 {
92  const short_t d = static_cast<short_t>(nodes.size());
93  GISMO_ASSERT( static_cast<size_t>(d) == weights.size(),
94  "Nodes and weights do not agree." );
95 
96  // compute the tensor quadrature rule
97  gsPointGrid(nodes, targetNodes);
98 
99  gsVector<index_t> numNodes(d);
100  for( short_t i=0; i<d; ++i )
101  numNodes[i] = weights[i].rows();
102 
103  GISMO_ASSERT( targetNodes.cols() == numNodes.prod(),
104  "Inconsistent sizes in nodes and weights.");
105 
106  // Compute weight products
107  targetWeights.resize( targetNodes.cols() );
108  size_t r = 0;
109  gsVector<index_t> curr(d);
110  curr.setZero();
111  do {
112  targetWeights[r] = weights[0][curr[0]];
113  for (short_t i=1; i<d; ++i)
114  targetWeights[r] *= weights[i][curr[i]];
115  ++r;
116  } while (nextLexicographic(curr, numNodes));
117 }
118 
119 
120 } // namespace gismo
Class representing a reference quadrature rule.
Definition: gsQuadRule.h:28
#define short_t
Definition: gsConfig.h:35
#define index_t
Definition: gsConfig.h:32
Provides combinatorial unitilies.
#define GISMO_ASSERT(cond, message)
Definition: gsDebug.h:89
void computeTensorProductRule(const std::vector< gsVector< T > > &nodes, const std::vector< gsVector< T > > &weights)
Computes the tensor product rule from coordinate-wise 1D nodes and weights.
Definition: gsQuadRule.hpp:80
gsMatrix< T > gsPointGrid(gsVector< T > const &a, gsVector< T > const &b, gsVector< unsigned > const &np)
Construct a Cartesian grid of uniform points in a hypercube, using np[i] points in direction i...
Definition: gsPointGrid.hpp:82
virtual void mapTo(const gsVector< T > &lower, const gsVector< T > &upper, gsMatrix< T > &nodes, gsVector< T > &weights) const
Maps quadrature rule (i.e., points and weights) from the reference domain to an element.
Definition: gsQuadRule.h:177
bool nextLexicographic(Vec &cur, const Vec &size)
Iterates through a tensor lattice with the given size. Updates cur and returns true if another entry ...
Definition: gsCombinatorics.h:196
Provides functions to generate structured point data.
void mapToAll(const std::vector< T > &breaks, gsMatrix< T > &nodes, gsVector< T > &weights) const
Maps a univariate quadrature rule (i.e., points and weights) from the reference interval to a number ...
Definition: gsQuadRule.hpp:52