G+Smo  25.01.0
Geometry + Simulation Modules
 
Loading...
Searching...
No Matches
gsQuadRule.h
Go to the documentation of this file.
1
14#pragma once
15
17
18namespace gismo
19{
20
27template<class T>
29{
30public:
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 {
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
150protected:
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
163protected:
164
167
171
172}; // class gsQuadRule
173
174
175// Note: left here for inlining
176template<class T> void
177gsQuadRule<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
A matrix with arbitrary coefficient type and fixed or dynamic size.
Definition gsMatrix.h:41
Class representing a reference quadrature rule.
Definition gsQuadRule.h:29
void setNodes(index_t numNodes, unsigned digits=0)
Initialize a univariate quadrature rule with numNodes quadrature points.
Definition gsQuadRule.h:74
index_t dim() const
Dimension of the rule.
Definition gsQuadRule.h:109
index_t numNodes() const
Number of nodes in the currently kept rule.
Definition gsQuadRule.h:106
const gsVector< T > & referenceWeights() const
Returns reference weights for the currently kept rule.
Definition gsQuadRule.h:100
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
gsVector< T > m_weights
Reference quadrature weights (corresponding to interval [-1,1]).
Definition gsQuadRule.h:170
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
gsQuadRule()
Default empty constructor.
Definition gsQuadRule.h:35
gsMatrix< T > m_nodes
Reference quadrature nodes (on the interval [-1,1]).
Definition gsQuadRule.h:166
const gsMatrix< T > & referenceNodes() const
Returns reference nodes for the currently kept rule.
Definition gsQuadRule.h:90
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
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
A vector with arbitrary coefficient type and fixed or dynamic size.
Definition gsVector.h:37
#define index_t
Definition gsConfig.h:32
#define GISMO_NO_IMPLEMENTATION
Definition gsDebug.h:129
#define GISMO_ASSERT(cond, message)
Definition gsDebug.h:89
This is the main header file that collects wrappers of Eigen for linear algebra.
The G+Smo namespace, containing all definitions for the library.