G+Smo  24.08.0
Geometry + Simulation Modules
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
gsQuadRule.h
Go to the documentation of this file.
1 
14 #pragma once
15 
16 #include <gsCore/gsLinearAlgebra.h>
17 
18 namespace gismo
19 {
20 
27 template<class T>
29 {
30 public:
31 
32  typedef memory::unique_ptr<gsQuadRule> uPtr;
33 
36  { }
37 
38  virtual ~gsQuadRule() { }
39 
62  virtual void setNodes( gsVector<index_t> const &,
63  unsigned = 0)
65 
75  unsigned digits = 0 )
76  {
77  gsVector<index_t> nn(1);
78  nn[0] = numNodes;
79  this->setNodes(nn, digits);
80  }
81 
90  const gsMatrix<T> & referenceNodes() const { return m_nodes; }
91 
100  const gsVector<T> & referenceWeights() const { return m_weights; }
101 
102  // Reference element is [-1,1]^d
103  //const gsMatrix<T> & referenceElement() { }
104 
106  index_t numNodes() const { return m_weights.size(); }
107 
109  index_t dim() const { return m_nodes.rows(); }
110 
111 
132  virtual inline void mapTo( const gsVector<T>& lower, const gsVector<T>& upper,
133  gsMatrix<T> & nodes, gsVector<T> & weights ) const;
134 
135  void mapTo(const gsMatrix<T>& ab, gsMatrix<T> & nodes) const;
136 
140  virtual void mapTo( T startVal, T endVal, //mapToInterval
141  gsMatrix<T> & nodes, gsVector<T> & weights ) const;
142 
147  void mapToAll( const std::vector<T> & breaks,
148  gsMatrix<T> & nodes, gsVector<T> & weights ) const;
149 
150 protected:
151 
154  void computeTensorProductRule(const std::vector<gsVector<T> > & nodes,
155  const std::vector<gsVector<T> > & weights);
156 
157  void computeTensorProductRule_into( const std::vector<gsVector<T> > & nodes,
158  const std::vector<gsVector<T> > & weights,
159  gsMatrix<T> & targetNodes,
160  gsVector<T> & targetWeights
161  ) const;
162 
163 protected:
164 
167 
171 
172 }; // class gsQuadRule
173 
174 
175 // Note: left here for inlining
176 template<class T> void
177 gsQuadRule<T>::mapTo( const gsVector<T>& lower, const gsVector<T>& upper,
178  gsMatrix<T> & nodes, gsVector<T> & weights ) const
179 {
180  const index_t d = lower.size();
181  GISMO_ASSERT( d == m_nodes.rows(), "Inconsistent quadrature mapping");
182 
183  nodes.resize( m_nodes.rows(), m_nodes.cols() );
184  weights.resize( m_weights.size() );
185  nodes.setZero();
186  weights.setZero();
187 
188  const gsVector<T> h = (upper-lower) / (T)(2) ;
189  // Linear map from [-1,1]^d to [lower,upper]
190  nodes.noalias() = ( h.asDiagonal() * (m_nodes.array()+1).matrix() ).colwise() + lower;
191 
192  T hprod(1.0); //volume of the cube.
193  for ( index_t i = 0; i!=d; ++i)
194  {
195  // the factor 0.5 is due to the reference interval is [-1,1].
196  hprod *= ( 0 == h[i] ? (T)(0.5) : h[i] );
197  }
198 
199  // Adjust the weights (multiply by the Jacobian of the linear map)
200  weights.noalias() = hprod * m_weights;
201 }
202 
203 } // namespace gismo
204 
205 #ifndef GISMO_BUILD_LIB
206 #include GISMO_HPP_HEADER(gsQuadRule.hpp)
207 #endif
Class representing a reference quadrature rule.
Definition: gsQuadRule.h:28
void setNodes(index_t numNodes, unsigned digits=0)
Initialize a univariate quadrature rule with numNodes quadrature points.
Definition: gsQuadRule.h:74
#define GISMO_NO_IMPLEMENTATION
Definition: gsDebug.h:129
const gsMatrix< T > & referenceNodes() const
Returns reference nodes for the currently kept rule.
Definition: gsQuadRule.h:90
#define index_t
Definition: gsConfig.h:32
gsQuadRule()
Default empty constructor.
Definition: gsQuadRule.h:35
#define GISMO_ASSERT(cond, message)
Definition: gsDebug.h:89
gsVector< T > m_weights
Reference quadrature weights (corresponding to interval [-1,1]).
Definition: gsQuadRule.h:170
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 > m_nodes
Reference quadrature nodes (on the interval [-1,1]).
Definition: gsQuadRule.h:166
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
index_t dim() const
Dimension of the rule.
Definition: gsQuadRule.h:109
const gsVector< T > & referenceWeights() const
Returns reference weights for the currently kept rule.
Definition: gsQuadRule.h:100
virtual void setNodes(gsVector< index_t > const &, unsigned=0)
Initialize quadrature rule with numNodes number of quadrature points per integration variable...
Definition: gsQuadRule.h:62
This is the main header file that collects wrappers of Eigen for linear algebra.
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
index_t numNodes() const
Number of nodes in the currently kept rule.
Definition: gsQuadRule.h:106