G+Smo  24.08.0
Geometry + Simulation Modules
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
gsQuadrature.h
Go to the documentation of this file.
1 
14 #pragma once
15 
16 #include <gsIO/gsOptionList.h>
22 
23 namespace gismo
24 {
25 
28 {
29  typedef GISMO_COEFF_TYPE Real;
30 
32  enum rule
33  {
36  PatchRule = 3
37 
38  };
39  /*
40  Reference:
41  Johannessen, K. A. (2017). Optimal quadrature for univariate and tensor product splines.
42  Computer Methods in Applied Mechanics and Engineering, 316, 84–99.
43  https://doi.org/10.1016/j.cma.2016.04.030
44  */
45 
47  template<class T>
48  static gsQuadRule<T> get(const gsBasis<T> & basis,
49  const gsOptionList & options, short_t fixDir = -1)
50  {
51  const index_t qu = options.askInt("quRule", GaussLegendre);
52  const Real quA = options.getReal("quA");
53  const index_t quB = options.getInt ("quB");
54  const gsVector<index_t> nnodes = numNodes(basis,quA,quB,fixDir);
55  return get<T>(qu, nnodes);
56  }
57 
59  template<class T>
60  static typename gsQuadRule<T>::uPtr
61  getPtr(const gsBasis<T> & basis,
62  const gsOptionList & options, short_t fixDir = -1)
63  {
64  const index_t qu = options.askInt("quRule", GaussLegendre);
65  const Real quA = options.getReal("quA");
66  const index_t quB = options.getInt ("quB");
67  const bool over = options.askSwitch ("overInt", false); // use overintegration?
68 
69  if ( (qu==GaussLegendre || qu==GaussLobatto) )
70  {
71  if (!over)
72  {
73  switch (qu)
74  {
75  case GaussLegendre :
76  return gsGaussRule<T>::make(numNodes(basis,quA,quB,fixDir));
77  case GaussLobatto :
78  return gsLobattoRule<T>::make(numNodes(basis,quA,quB,fixDir));
79  default:
80  GISMO_ERROR("Invalid Quadrature rule request ("<<qu<<")");
81  };
82  }
83  else
84  {
85  /*
86  Uses quadrature rule with quA and quB for the interior
87  elements and one with quAb and quBb for the boundary elements
88  */
89  const Real quAb = options.askReal("quAb",quA+1);
90  const index_t quBb = options.askInt ("quBb",quB);
91 
92  const gsVector<index_t> nnodesI = numNodes(basis,quA,quB,fixDir);
93  const gsVector<index_t> nnodesB = numNodes(basis,quAb,quBb,fixDir);
94 
95  std::vector<gsQuadRule<T> > quInterior(nnodesI.size());
96  std::vector<gsQuadRule<T> > quBoundary(nnodesB.size());
97 
98  for (index_t d = 0; d != nnodesI.size(); d++)
99  {
100  quInterior[d] = getUnivariate<T>(qu,nnodesI[d]);
101  quBoundary[d] = getUnivariate<T>(qu,nnodesB[d]);
102  }
103 
104  return gsOverIntegrateRule<T>::make(basis,quInterior,quBoundary);
105  }
106  }
107  else if (qu==PatchRule)
108  {
109  // quA: Order of the target space
110  // quB: Regularity of the target space
111  return gsPatchRule<T>::make(basis,cast<T,index_t>(quA),quB,over,fixDir);
112  }
113  else
114  {
115  GISMO_ERROR("Quadrature with index "<<qu<<" unknown.");
116  }
117  }
118 
120  template<class T>
121  static inline gsQuadRule<T> get(index_t qu, gsVector<index_t> const & numNodes, unsigned digits = 0)
122  {
123  switch (qu)
124  {
125  case GaussLegendre :
126  return gsGaussRule<T>(numNodes, digits);
127  case GaussLobatto :
128  return gsLobattoRule<T>(numNodes, digits);
129  default:
130  GISMO_ERROR("Invalid Quadrature rule request ("<<qu<<")");
131  };
132  }
133 
135  template<class T>
136  static inline gsQuadRule<T> getUnivariate(index_t qu, index_t numNodes, unsigned digits = 0)
137  {
138  switch (qu)
139  {
140  case GaussLegendre :
141  return gsGaussRule<T>(numNodes, digits);
142  case GaussLobatto :
143  return gsLobattoRule<T>(numNodes, digits);
144  default:
145  GISMO_ERROR("Invalid Quadrature rule request ("<<qu<<")");
146  };
147  }
148 
151  template<class T>
152  static gsVector<index_t> numNodes(const gsBasis<T> & basis,
153  const Real quA, const index_t quB, short_t fixDir = -1)
154  {
155  const short_t d = basis.dim();
156  GISMO_ASSERT( fixDir < d && fixDir>-2, "Invalid input fixDir = "<<fixDir);
157  gsVector<index_t> nnodes(d);
158 
159  if (-1==fixDir)
160  fixDir = d;
161  else
162  nnodes[fixDir] = 1;
163 
164  short_t i;
165  for(i=0; i!=fixDir; ++i )
166  //note: +0.5 for rounding
167  nnodes[i] = cast<Real,index_t>(quA * basis.degree(i) + quB + 0.5);
168  for(++i; i<d; ++i )
169  nnodes[i] = cast<Real,index_t>(quA * basis.degree(i) + quB + 0.5);
170  return nnodes;
171  }
172 };
173 
174 }// namespace gismo
#define GISMO_COEFF_TYPE
Definition: gsConfig.h:26
Class that represents the (tensor) Gauss-Lobatto quadrature rule.
Definition: gsLobattoRule.h:26
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
Provides the Gauss-Legendre quadrature rule.
Class representing a reference quadrature rule.
Definition: gsQuadRule.h:28
Over-integrates a Gauss-Legendre or Gauss-Lobatto rule.
Provides the Gauss-Lobatto quadrature rule.
#define short_t
Definition: gsConfig.h:35
virtual short_t degree(short_t i) const
Degree with respect to the i-th variable. If the basis is a tensor product of (piecewise) polynomial ...
Definition: gsBasis.hpp:650
Helper class for obtaining a quadrature rule.
Definition: gsQuadrature.h:27
static gsQuadRule< T > getUnivariate(index_t qu, index_t numNodes, unsigned digits=0)
Constructs a quadrature rule based on input options.
Definition: gsQuadrature.h:136
#define index_t
Definition: gsConfig.h:32
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:61
const index_t & getInt(const std::string &label) const
Reads value for option label from options.
Definition: gsOptionList.cpp:37
#define GISMO_ASSERT(cond, message)
Definition: gsDebug.h:89
Provides a list of labeled parameters/options that can be set and accessed easily.
Gauss-Legendre quadrature.
Definition: gsQuadrature.h:34
Patch-wise quadrature rule (Johannessen 2017)
Definition: gsQuadrature.h:36
static gsVector< index_t > numNodes(const gsBasis< T > &basis, const Real quA, const index_t quB, short_t fixDir=-1)
Definition: gsQuadrature.h:152
Gauss-Lobatto quadrature.
Definition: gsQuadrature.h:35
static uPtr make(gsVector< index_t > const &numNodes, const unsigned digits=0)
Make function returning a smart pointer.
Definition: gsLobattoRule.h:43
Real askReal(const std::string &label, const Real &value=0) const
Reads value for option label from options.
Definition: gsOptionList.cpp:139
rule
Quadrature rule types.
Definition: gsQuadrature.h:32
Provides patch-wise quadrature rule.
index_t askInt(const std::string &label, const index_t &value=0) const
Reads value for option label from options.
Definition: gsOptionList.cpp:117
#define GISMO_ERROR(message)
Definition: gsDebug.h:118
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:128
bool askSwitch(const std::string &label, const bool &value=false) const
Reads value for option label from options.
Definition: gsOptionList.cpp:128
Class which holds a list of parameters/options, and provides easy access to them. ...
Definition: gsOptionList.h:32
Class that represents the (tensor) Gauss-Legendre quadrature rule.
Definition: gsGaussRule.h:27
Provides the Newton-Cotes quadrature rule.
A basis represents a family of scalar basis functions defined over a common parameter domain...
Definition: gsBasis.h:78
Real getReal(const std::string &label) const
Reads value for option label from options.
Definition: gsOptionList.cpp:44
static uPtr make(gsVector< index_t > const &numNodes, const unsigned digits=0)
Make function returning a smart pointer.
Definition: gsGaussRule.h:44