G+Smo  25.01.0
Geometry + Simulation Modules
 
Loading...
Searching...
No Matches
gsNewtonCotesRule.hpp
Go to the documentation of this file.
1
14#pragma once
15
16#include <gsCore/gsBasis.h>
17#include <gsIO/gsOptionList.h>
18
19namespace gismo
20{
21
22template<class T> void
23gsNewtonCotesRule<T>::init(const gsBasis<T> & basis, const T quA,
24 const index_t quB, short_t fixDir)
25//const unsigned digits)
26{
27 const short_t d = basis.dim();
28 GISMO_ASSERT( fixDir < d && fixDir>-2, "Invalid input fixDir = "<<fixDir);
29
30 std::vector<gsVector<T> > nodes(d);
31 std::vector<gsVector<T> > weights(d);
32 if (-1==fixDir)
33 fixDir = d;
34 else
35 {
36 nodes [fixDir].setZero(1); // numNodes == 1
37 weights[fixDir].setConstant(1, 2.0);
38 }
39
40 //if (digits <= 30 )
41 //{
42 short_t i;
43 for(i=0; i!=fixDir; ++i )
44 {
45 //note: +0.5 for rounding
46 const index_t numNodes = cast<T,index_t>(quA * static_cast<T>(basis.degree(i)) + static_cast<T>(quB) + static_cast<T>(0.5));
47 //const bool found =
48 computeReference(numNodes, nodes[i], weights[i]);
49 }
50 ++i;// skip fixed direction
51 for(; i<d; ++i )
52 {
53 const index_t numNodes = cast<T,index_t>(quA * static_cast<T>(basis.degree(i)) + static_cast<T>(quB) + static_cast<T>(0.5));
54 computeReference(numNodes, nodes[i], weights[i]);
55 }
56
57 //}
58 //else
59 //{
60 // for( short_t i=0; i<d; ++i )
61 // {
62 // const index_t numNodes = quA * basis.degree(i) + quB;
63 // computeReference(numNodes, nodes[i], weights[i], digits);
64 // }
65 //}
66
67 this->computeTensorProductRule(nodes, weights);
68}
69
70template<class T>
72 const T quA, const index_t quB,
73 const short_t fixDir)
74//const unsigned digits)
75{
76 init(basis, quA, quB, fixDir);
77}
78
79template<class T>
81 const gsOptionList & options,
82 const short_t fixDir)
83//const unsigned digits)
84{
85 const T quA = options.getReal("quA");
86 const index_t quB = options.getInt ("quB");
87 init(basis, quA, quB, fixDir);
88}
89
90
91template<class T> void
93 unsigned digits)
94{
95 GISMO_UNUSED(digits);
96 const index_t d = numNodes.rows();
97
98 // Get base rule nodes and weights
99 std::vector<gsVector<T> > nodes(d);
100 std::vector<gsVector<T> > weights(d);
101
102 for (index_t i = 0; i < d; ++i)
103 computeReference(numNodes[i], nodes[i], weights[i]);
104
105 this->computeTensorProductRule(nodes, weights);
106}
107
108
109
110template<class T> void
112 gsVector<T> & x, // Quadrature points
113 gsVector<T> & w) // Quadrature weights
114{
115
116 index_t i,j,k;
117 x.resize(n);
118
119 if ( 1 == n )
120 {
121 x[0] = (T)(0);
122 w.setConstant(1,(T)(2));
123 return;
124 }
125
126 //todo: if (closed) ... else (open)
127 x[0] = (T)(-1);
128 x[n-1] = (T)( 1);
129 for (i = 1; i < n-1; ++i)
130 x[i] = ( T ) (2*i-n+1) / (T)(n-1);
131
132 // todo: if weights_required
133 // weights
134 w.resize(n);
135 gsVector<T> d(n);
136 T a, b;
137 for (i = 0; i < n; ++i)
138 {
139 // Compute the Lagrange basis polynomial
140 d.setZero();
141 d[i] = (T)1.0;
142
143 for (j = 2; j <= n; ++j)
144 for (k = j; k <= n; ++k)
145 d[n+j-k-1] = ( d[n+j-k-2] - d[n+j-k-1] ) / ( x[n-k] - x[n+j-k-1] );
146
147 for ( j = 1; j <= n - 1; ++j)
148 for ( k = 1; k <= n - j; ++k)
149 d[n-k-1] = d[n-k-1] - x[n-k-j] * d[n-k];
150
151 // Evaluate the antiderivative of the polynomial at the endpoints
152 a = b = d[n-1] / (T)( n );
153 for ( j = n - 2; 0 <= j; --j)
154 {
155 const T dj1= d[j] / (T)(j+1);
156 a+= dj1;
157 b = -b + dj1;
158 }
159 w[i] = a + b;
160 }
161 x[0] += 1e-12;
162 x[n-1] -= 1e-12;
163}
164
165} // namespace gismo
A basis represents a family of scalar basis functions defined over a common parameter domain.
Definition gsBasis.h:79
void setNodes(gsVector< index_t > const &numNodes, unsigned digits=0)
Initialize quadrature rule with numNodes number of quadrature points per integration variable.
Definition gsNewtonCotesRule.hpp:92
gsNewtonCotesRule()
Default empty constructor.
Definition gsNewtonCotesRule.h:34
static void computeReference(index_t n, gsVector< T > &x, gsVector< T > &w)
Computes the Newton-Cotes quadrature rule with n nodes in the interval [-1,1].
Definition gsNewtonCotesRule.hpp:111
Class which holds a list of parameters/options, and provides easy access to them.
Definition gsOptionList.h:33
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
A vector with arbitrary coefficient type and fixed or dynamic size.
Definition gsVector.h:37
Provides declaration of Basis abstract interface.
#define short_t
Definition gsConfig.h:35
#define index_t
Definition gsConfig.h:32
#define GISMO_UNUSED(x)
Definition gsDebug.h:112
#define GISMO_ASSERT(cond, message)
Definition gsDebug.h:89
Provides a list of labeled parameters/options that can be set and accessed easily.
The G+Smo namespace, containing all definitions for the library.