G+Smo  25.01.0
Geometry + Simulation Modules
 
Loading...
Searching...
No Matches
gsQuadrature.h
Go to the documentation of this file.
1
14#pragma once
15
16#include <gsIO/gsOptionList.h>
23
25
26namespace gismo
27{
28
31{
32 typedef GISMO_COEFF_TYPE Real;
33
35 enum rule
36 {
39 PatchRule = 3
40
41 };
42 /*
43 Reference:
44 Johannessen, K. A. (2017). Optimal quadrature for univariate and tensor product splines.
45 Computer Methods in Applied Mechanics and Engineering, 316, 84–99.
46 https://doi.org/10.1016/j.cma.2016.04.030
47 */
48
50 template<class T>
51 static gsQuadRule<T> get(const gsBasis<T> & basis,
52 const gsOptionList & options, short_t fixDir = -1)
53 {
54 const index_t qu = options.askInt("quRule", GaussLegendre);
55 const Real quA = options.getReal("quA");
56 const index_t quB = options.getInt ("quB");
57 const gsVector<index_t> nnodes = numNodes(basis,quA,quB,fixDir);
58 return get<T>(qu, nnodes);
59 }
60
62 template<class T>
63 static typename gsQuadRule<T>::uPtr
64 getPtr(const gsBasis<T> & basis,
65 const gsOptionList & options, short_t fixDir = -1)
66 {
67 const index_t qu = options.askInt("quRule", GaussLegendre);
68 const Real quA = options.getReal("quA");
69 const index_t quB = options.getInt ("quB");
70 const bool over = options.askSwitch ("overInt", false); // use overintegration?
71
72 if ( (qu==GaussLegendre || qu==GaussLobatto) )
73 {
74 if (!over)
75 {
76 switch (qu)
77 {
78 case GaussLegendre :
79 return gsGaussRule<T>::make(numNodes(basis,quA,quB,fixDir));
80 case GaussLobatto :
81 return gsLobattoRule<T>::make(numNodes(basis,quA,quB,fixDir));
82 default:
83 GISMO_ERROR("Invalid Quadrature rule request ("<<qu<<")");
84 };
85 }
86 else
87 {
88 /*
89 Uses quadrature rule with quA and quB for the interior
90 elements and one with quAb and quBb for the boundary elements
91 */
92 const Real quAb = options.askReal("quAb",quA+1);
93 const index_t quBb = options.askInt ("quBb",quB);
94
95 const gsVector<index_t> nnodesI = numNodes(basis,quA,quB,fixDir);
96 const gsVector<index_t> nnodesB = numNodes(basis,quAb,quBb,fixDir);
97
98 std::vector<gsQuadRule<T> > quInterior(nnodesI.size());
99 std::vector<gsQuadRule<T> > quBoundary(nnodesB.size());
100
101 for (index_t d = 0; d != nnodesI.size(); d++)
102 {
103 quInterior[d] = getUnivariate<T>(qu,nnodesI[d]);
104 quBoundary[d] = getUnivariate<T>(qu,nnodesB[d]);
105 }
106
107 return gsOverIntegrateRule<T>::make(basis,quInterior,quBoundary);
108 }
109 }
110 else if (qu==PatchRule)
111 {
112 // quA: Order of the target space
113 // quB: Regularity of the target space
114 return gsPatchRule<T>::make(basis,cast<T,index_t>(quA),quB,over,fixDir);
115 }
116 else
117 {
118 GISMO_ERROR("Quadrature with index "<<qu<<" unknown.");
119 }
120 }
121
123 template<class T>
124 static inline gsQuadRule<T> get(index_t qu, gsVector<index_t> const & numNodes, unsigned digits = 0)
125 {
126 switch (qu)
127 {
128 case GaussLegendre :
129 return gsGaussRule<T>(numNodes, digits);
130 case GaussLobatto :
131 return gsLobattoRule<T>(numNodes, digits);
132 default:
133 GISMO_ERROR("Invalid Quadrature rule request ("<<qu<<")");
134 };
135 }
136
138 template<class T>
139 static inline gsQuadRule<T> getUnivariate(index_t qu, index_t numNodes, unsigned digits = 0)
140 {
141 switch (qu)
142 {
143 case GaussLegendre :
144 return gsGaussRule<T>(numNodes, digits);
145 case GaussLobatto :
146 return gsLobattoRule<T>(numNodes, digits);
147 default:
148 GISMO_ERROR("Invalid Quadrature rule request ("<<qu<<")");
149 };
150 }
151
154 template<class T>
156 const Real quA, const index_t quB, short_t fixDir = -1)
157 {
158 const short_t d = basis.dim();
159 GISMO_ASSERT( fixDir < d && fixDir>-2, "Invalid input fixDir = "<<fixDir);
160 gsVector<index_t> nnodes(d);
161
162 if (-1==fixDir)
163 fixDir = d;
164 else
165 nnodes[fixDir] = 1;
166
167 short_t i;
168 for(i=0; i!=fixDir; ++i )
169 //note: +0.5 for rounding
170 nnodes[i] = cast<Real,index_t>(quA * basis.degree(i) + quB + 0.5);
171 for(++i; i<d; ++i )
172 nnodes[i] = cast<Real,index_t>(quA * basis.degree(i) + quB + 0.5);
173 return nnodes;
174 }
175
176 // template<class T>
177 // static std::pair<gsMatrix<T>,gsVector<T>> getAllNodesAndWeights(const gsBasis<T> & basis,
178 // const gsOptionList & options)
179 // {
180
181 // }
182
194 template<class T>
195 static gsMatrix<T> getAllNodes(const gsBasis<T> & basis,
196 const gsOptionList & options)
197 {
198 typename gsBasis<real_t>::domainIter domIt = basis.makeDomainIterator();
199
200 index_t quadSize = 0;
201 typename gsQuadRule<T>::uPtr QuRule;
202 QuRule = getPtr(basis, options);
203
204 for (; domIt->good(); domIt->next())
205 {
206 QuRule = gsQuadrature::getPtr(basis, options);
207 quadSize+=QuRule->numNodes();
208 }
209
210 gsMatrix<T> result(basis.domainDim(),quadSize);
211
212 index_t offset = 0;
213 gsMatrix<T> nodes;
214 gsVector<T> weights;
215 for (domIt->reset(); domIt->good(); domIt->next() )
216 {
217 QuRule = gsQuadrature::getPtr(basis, options);
218 // Map the Quadrature rule to the element
219 QuRule->mapTo( domIt->lowerCorner(), domIt->upperCorner(),
220 nodes, weights);
221 result.block(0,offset,basis.domainDim(),QuRule->numNodes()) = nodes;
222 offset += QuRule->numNodes();
223 }
224 return result;
225 }
226
237 template<class T>
238 static gsMatrix<T> getAllNodes(const gsBasis<T> & basis,
239 const gsOptionList & options, const patchSide side)
240 {
241 typename gsBasis<real_t>::domainIter domIt = basis.makeDomainIterator(side);
242
243 index_t quadSize = 0;
244 typename gsQuadRule<T>::uPtr QuRule;
245 QuRule = getPtr(basis, options,side.side().direction());
246
247 for (; domIt->good(); domIt->next())
248 {
249 QuRule = gsQuadrature::getPtr(basis, options, side.side().direction());
250 quadSize+=QuRule->numNodes();
251 }
252
253 gsMatrix<T> result(basis.domainDim(),quadSize);
254
255 index_t offset = 0;
256 gsMatrix<T> nodes;
257 gsVector<T> weights;
258 for (domIt->reset(); domIt->good(); domIt->next() )
259 {
260 QuRule = gsQuadrature::getPtr(basis, options, side.side().direction());
261 // Map the Quadrature rule to the element
262 QuRule->mapTo( domIt->lowerCorner(), domIt->upperCorner(),
263 nodes, weights);
264 result.block(0,offset,basis.domainDim(),QuRule->numNodes()) = nodes;
265 offset += QuRule->numNodes();
266 }
267 return result;
268 }
269
273 template<class T>
274 static gsMatrix<T> getAllNodes(const gsBasis<T> & basis, const gsGeometry<T> & geom,
275 const gsOptionList & options, const patchSide side)
276 {
277 gsMatrix<T> nodes = getAllNodes(basis,options,side);
278 return geom.eval(nodes);
279 }
280
284 template<class T>
285 static gsMatrix<T> getAllNodes(const gsBasis<T> & basis,
286 const gsOptionList & options, const std::vector<patchSide> sides)
287 {
288 std::vector<gsMatrix<T>> nodes(sides.size());
289 index_t cols = 0;
290 for (size_t s = 0; s != sides.size(); s++)
291 {
292 nodes[s] = getAllNodes(basis,options,sides[s]);
293 cols += nodes[s].cols();
294 }
295 gsMatrix<T> result(basis.domainDim(),cols);
296 cols = 0;
297
298 for (size_t s = 0; s != sides.size(); s++)
299 {
300 result.block(0,cols,nodes[s].rows(),nodes[s].cols()) = nodes[s];
301 cols += nodes[s].cols();
302 }
303
304 return result;
305 }
306
310 template<class T>
311 static gsMatrix<T> getAllNodes(const gsBasis<T> & basis, const gsGeometry<T> & geom,
312 const gsOptionList & options, const std::vector<patchSide> sides)
313 {
314 gsMatrix<T> nodes = getAllNodes(basis,options,sides);
315 return geom.eval(nodes);
316 }
317
318 template<class T>
319 static gsMatrix<T> getAllNodes(const gsMultiBasis<T> & bases,
320 const gsOptionList & options)
321 {
322 return getAllNodes(bases,options);
323 }
324
328 template<class T>
329 static std::vector<gsMatrix<T>> getAllNodes(const gsMultiBasis<T> & bases,
330 const gsOptionList & options, const std::vector<patchSide> sides)
331 {
332 GISMO_ASSERT(bases.nBases()==sides.size(),"Number of bases must be equal to the number of fixed directions");
333 std::vector<gsMatrix<T>> nodes(bases.nBases());
334 for (size_t p = 0; p != bases.nBases(); p++)
335 nodes[p] = getAllNodes(bases.basis(p),options,sides[p]);
336
337 return nodes;
338 }
339
340
352 template<class T>
353 static gsMatrix<T> getAllNodes(const gsMultiBasis<T> & bases, const gsMultiPatch<T> & mp,
354 const gsOptionList & options, const std::vector<patchSide> sides)
355 {
356 std::vector<gsMatrix<T>> nodes = getAllNodes(bases,options,sides);
357 index_t cols = 0;
358 for (size_t p = 0; p != nodes.size(); p++)
359 cols += nodes[p].cols();
360
361 gsMatrix<T> result(mp.targetDim(),cols);
362 cols = 0;
363 for (size_t p = 0; p != nodes.size(); p++)
364 {
365 result.block(0,cols,mp.targetDim(),nodes[p].cols()) = mp.patch(p).eval(nodes[p]);
366 cols += nodes[p].cols();
367 }
368
369 return result;
370 }
371};
372
373
374}// namespace gismo
A basis represents a family of scalar basis functions defined over a common parameter domain.
Definition gsBasis.h:79
gsMatrix< T > eval(const gsMatrix< T > &u) const
Evaluate the function,.
Definition gsFunctionSet.hpp:120
Class that represents the (tensor) Gauss-Legendre quadrature rule.
Definition gsGaussRule.h:28
static uPtr make(gsVector< index_t > const &numNodes, const unsigned digits=0)
Make function returning a smart pointer.
Definition gsGaussRule.h:44
Abstract base class representing a geometry map.
Definition gsGeometry.h:93
Class that represents the (tensor) Gauss-Lobatto quadrature rule.
Definition gsLobattoRule.h:27
static uPtr make(gsVector< index_t > const &numNodes, const unsigned digits=0)
Make function returning a smart pointer.
Definition gsLobattoRule.h:43
A matrix with arbitrary coefficient type and fixed or dynamic size.
Definition gsMatrix.h:41
Holds a set of patch-wise bases and their topology information.
Definition gsMultiBasis.h:37
const gsBasis< T > & basis(const size_t i) const
Return the i-th basis block.
Definition gsMultiBasis.h:267
size_t nBases() const
Number of patch-wise bases.
Definition gsMultiBasis.h:264
Container class for a set of geometry patches and their topology, that is, the interface connections ...
Definition gsMultiPatch.h:100
Class which holds a list of parameters/options, and provides easy access to them.
Definition gsOptionList.h:33
Real askReal(const std::string &label, const Real &value=0) const
Reads value for option label from options.
Definition gsOptionList.cpp:139
bool askSwitch(const std::string &label, const bool &value=false) const
Reads value for option label from options.
Definition gsOptionList.cpp:128
const index_t & getInt(const std::string &label) const
Reads value for option label from options.
Definition gsOptionList.cpp:37
Real getReal(const std::string &label) const
Reads value for option label from options.
Definition gsOptionList.cpp:44
index_t askInt(const std::string &label, const index_t &value=0) const
Reads value for option label from options.
Definition gsOptionList.cpp:117
static uPtr make(const gsBasis< T > &basis, const std::vector< gsQuadRule< T > > &quadInterior, const std::vector< gsQuadRule< T > > &quadBoundary)
Construct a smart-pointer to the rule.
Definition gsOverIntegrateRule.h:75
static uPtr make(const gsBasis< T > &basis, const index_t degree, const index_t regularity, const bool overintegrate, const short_t fixDir=-1)
Make function returning a smart pointer.
Definition gsPatchRule.h:126
Class representing a reference quadrature rule.
Definition gsQuadRule.h:29
index_t numNodes() const
Number of nodes in the currently kept rule.
Definition gsQuadRule.h:106
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 short_t
Definition gsConfig.h:35
#define GISMO_COEFF_TYPE
Definition gsConfig.h:26
#define index_t
Definition gsConfig.h:32
#define GISMO_ERROR(message)
Definition gsDebug.h:118
#define GISMO_ASSERT(cond, message)
Definition gsDebug.h:89
Provides declaration of DomainIterator abstract interface.
Provides the Gauss-Legendre quadrature rule.
Provides the Gauss-Lobatto quadrature rule.
Provides the Newton-Cotes quadrature rule.
Provides a list of labeled parameters/options that can be set and accessed easily.
Over-integrates a Gauss-Legendre or Gauss-Lobatto rule.
Provides patch-wise quadrature rule.
The G+Smo namespace, containing all definitions for the library.
Helper class for obtaining a quadrature rule.
Definition gsQuadrature.h:31
static gsMatrix< T > getAllNodes(const gsBasis< T > &basis, const gsOptionList &options, const patchSide side)
Get all quadrature nodes for a specified side of a given basis.
Definition gsQuadrature.h:238
static gsQuadRule< T > getUnivariate(index_t qu, index_t numNodes, unsigned digits=0)
Constructs a quadrature rule based on input options.
Definition gsQuadrature.h:139
static gsMatrix< T > getAllNodes(const gsBasis< T > &basis, const gsGeometry< T > &geom, const gsOptionList &options, const patchSide side)
Get all quadrature nodes for a specified side of a basis and evaluates them using a geometry.
Definition gsQuadrature.h:274
static gsMatrix< T > getAllNodes(const gsBasis< T > &basis, const gsOptionList &options, const std::vector< patchSide > sides)
Retrieves all quadrature nodes for multiple sides of a given basis.
Definition gsQuadrature.h:285
static gsMatrix< T > getAllNodes(const gsMultiBasis< T > &bases, const gsMultiPatch< T > &mp, const gsOptionList &options, const std::vector< patchSide > sides)
Gets all quadrature nodes for several sides of a multi-basis for multi-patch geometry.
Definition gsQuadrature.h:353
static gsQuadRule< T > get(const gsBasis< T > &basis, const gsOptionList &options, short_t fixDir=-1)
Constructs a quadrature rule based on input options.
Definition gsQuadrature.h:51
rule
Quadrature rule types.
Definition gsQuadrature.h:36
@ PatchRule
Patch-wise quadrature rule (Johannessen 2017)
Definition gsQuadrature.h:39
@ GaussLegendre
Gauss-Legendre quadrature.
Definition gsQuadrature.h:37
@ GaussLobatto
Gauss-Lobatto quadrature.
Definition gsQuadrature.h:38
static gsVector< index_t > numNodes(const gsBasis< T > &basis, const Real quA, const index_t quB, short_t fixDir=-1)
Definition gsQuadrature.h:155
static gsMatrix< T > getAllNodes(const gsBasis< T > &basis, const gsOptionList &options)
Retrieves all quadrature nodes for the given basis.
Definition gsQuadrature.h:195
static gsQuadRule< T >::uPtr getPtr(const gsBasis< T > &basis, const gsOptionList &options, short_t fixDir=-1)
Constructs a quadrature rule based on input options.
Definition gsQuadrature.h:64
static std::vector< gsMatrix< T > > getAllNodes(const gsMultiBasis< T > &bases, const gsOptionList &options, const std::vector< patchSide > sides)
Collects all quadrature nodes for a multi-basis.
Definition gsQuadrature.h:329
static gsMatrix< T > getAllNodes(const gsBasis< T > &basis, const gsGeometry< T > &geom, const gsOptionList &options, const std::vector< patchSide > sides)
Collects and evaluates all quadrature nodes for multiple sides of a given basis.
Definition gsQuadrature.h:311
static gsQuadRule< T > get(index_t qu, gsVector< index_t > const &numNodes, unsigned digits=0)
Constructs a quadrature rule based on input options.
Definition gsQuadrature.h:124
Struct which represents a certain side of a patch.
Definition gsBoundary.h:232