G+Smo  25.01.0
Geometry + Simulation Modules
 
Loading...
Searching...
No Matches
gsLagrangeBasis.h
1
2#pragma once
3#include <cmath>
4
5//#include <gismo.h>
7//#include "gsLagrangeBasis.hpp"
9#include <gsCore/gsBoundary.h>
10#include <gsCore/gsBasis.h>
11
12namespace gismo
13{
14
15// forward declaration
16template< class T> class gsLagrangeBasis;
17template <class T> class gsLagrangePoly;
18
19/*template<short_t d, class T>
20 struct gsTraits<gsLagrangeBasis<T>, d>
21 {
22 typedef gsLagrangeBasis<T> TensorBasisType;
23 typedef gsLagrange<T> TensorGeometryType;
24 typedef gsLagrange<T> TensorBoundaryType;
25 };
26
28template<class T>
29struct gsTraits<gsLagrangeBasis<T>,1>
30{
31typedef gsLagrangeBasis<T> TensorBasisType;
32typedef gsLagrange<T> TensorGeometryType;
33typedef gsLagrange<T> TensorBoundaryType;
34};*/
35
44template<class T>
45class gsLagrangeBasis : public gsBasis<T>
46{
47public:
48 typedef gsBasis<T> Base;
49
51 typedef T Scalar_t;
52
55
58
60 static const short_t Dim = 1;
61
63 typedef memory::shared_ptr< gsLagrangeBasis > Ptr;
64
66 typedef memory::unique_ptr< gsLagrangeBasis > uPtr;
67
68// static Ptr Make ( const gsVector<T> & vec, const T & start, const T & end)
69// { return Ptr( new gsLagrangeBasis(vec,start,end) ); }
70
71public:
72
75
77 gsLagrangeBasis ( const std::vector<T> & pars, const T & start, const T & end ) :
78 m_p(pars.size()-1), m_breaks(pars), m_start(start), m_end(end)
79 {
80 check();
81 }
82
84 gsLagrangeBasis ( const T & start, const T & end, int amount_of_inner_breaks ) :
85 m_p(amount_of_inner_breaks+1), m_start(start), m_end(end)
86 {
87 m_breaks.push_back(start);
88 for(int i =0;i<amount_of_inner_breaks;i++)
89 {
90 m_breaks.push_back(
91 start+( (i+1) * (end-start) / (amount_of_inner_breaks+1) ) );
92 }
93 m_breaks.push_back(end);
94 check();
95 }
96
97 ~gsLagrangeBasis() { } //destructor
98
99public:
100
102 // Virtual member functions required by the base class
104
106 short_t domainDim() const { return Dim; }
107
109 void anchors_into(gsMatrix<T>& result) const;
110
112 void anchor_into(index_t i, gsMatrix<T>& result) const
113 {
114 result.resize(1,1);
115 result(0,0)=m_breaks[i];
116 }
117
119 void active_into(const gsMatrix<T> & u, gsMatrix<index_t>& result) const;
120
122 void numActive_into(const gsMatrix<T> & u, gsVector<index_t>& result) const
123 {
124 result.resize(1,u.cols());
125 for(short_t i = 0; i<u.cols();++i)
126 {
127 result(0,i)=m_p+1;
128 }
129 }
130
133 {
134 gsMatrix<index_t> * res = new gsMatrix<index_t>(m_breaks.size(),1);
135 for(short_t i = 0; i<=m_p;++i)
136 {
137 (*res)(i,0)=i;
138 }
139 return *res;
140 }
141
143 gsMatrix<index_t> boundary(boundary::side const & s ) const { return boundary(); }
144
146 GISMO_UPTR_FUNCTION_DEC(gsBasis<T>, boundaryBasis, boxSide const &)
147
148
149 gsMatrix<T> support() const
150 {
151 gsMatrix<T> * res = new gsMatrix<T>(1,2);
152 *res << m_start , m_end ;
153 return *res ;
154 }
155
156
158 gsMatrix<T> support(const index_t & i) const
159 {
160 return support();
161 }
162
167
169 void eval_into(const gsMatrix<T> & u, gsMatrix<T>& result) const;
170
172 void evalSingle_into(index_t i, const gsMatrix<T> & u, gsMatrix<T>& result) const
173 {
174 evalDerSingle_into(i,u,0,result);
175 }
176
178 void deriv_into(const gsMatrix<T> & u, gsMatrix<T>& result ) const;
179
181 void derivSingle_into(index_t i, const gsMatrix<T> & u, gsMatrix<T>& result ) const
182 {
183 evalDerSingle_into(i,u,1,result);
184 }
185
187 void deriv2_into(const gsMatrix<T> & u, gsMatrix<T>& result ) const;
188
191 void deriv2Single_into(index_t i, const gsMatrix<T> & u, gsMatrix<T>& result ) const
192 {
193 evalDerSingle_into(i,u,2,result);
194 }
195
198 void evalAllDers_into(const gsMatrix<T> & u, int n, gsMatrix<T>& result) const;
199
202 void evalAllDersSingle_into(index_t i, const gsMatrix<T> & u, int n, gsMatrix<T>& result) const;
203
206 void evalDerSingle_into(index_t i, const gsMatrix<T> & u, int n, gsMatrix<T>& result) const;
207
208 GISMO_CLONE_FUNCTION(gsLagrangeBasis)
209
210 GISMO_MAKE_GEOMETRY_NEW
211
213 std::ostream &print(std::ostream &os) const
214 {
215 os << "Lagrange Basis: deg=" << this->degree()
216 << ", size="<< this->size()
217 << ", parameters= [";
218 for ( unsigned i = 0; i<m_breaks.size(); ++i )
219 os << m_breaks[i] << " ";
220 os << "], interval= [" << m_start << "," << m_end << "].\n";
221 return os;
222 }
223
224
226 std::string detail() const
227 {
228 // By default just uses print(..)
229 std::ostringstream os;
230 print(os);
231 return os.str();
232 }
233
235 // Virtual member that may be implemented or not by the derived class
237
239 short_t size() const { return m_p+1; }
240
243 {
244 if ( i == 0 )
245 return const_cast<gsLagrangeBasis&>(*this);
246 else
247 throw std::runtime_error("gsLagrangeBasis has only one component");
248 }
249
254
257 {
258 return degree();
259 }
260
263 {
264 return degree();
265 }
266
269 {
270 return size()-1;
271 }
272
278
279 //MEMBER FUNCTIONS (SHOULD BE PRIVATE)
280
284 {
285 gsMatrix<T> L_to_M;
287 gsMatrix<T> M_to_B;
289 result=M_to_B*L_to_M;
290 }
291
293 bool check() const
294 {
295 bool consistent = true;
296 // Checks if the breaks vector is strictly monotonic increasing.
297 for(unsigned i=0;i<m_breaks.size()-1;i++)
298 if(m_breaks[i]>=m_breaks[i+1])
299 {
300 GISMO_ERROR("gsLagrangeBasis Error: not strictly monoton increasing");
301 consistent=false;
302 }
303
304 // Checks if the interval has zero length
305 if(m_start==m_end)
306 {
307 GISMO_ERROR("gsLagrangeBasis Error: interval = 0");
308 consistent=false;
309 }
310 return consistent;
311 }
312
315
316 // getters:
317
320 {
321 return m_p;
322 }
323
325 const std::vector<T> * get_m_breaks() const
326 {
327 return & m_breaks;
328 }
329
331 T get_m_start() const
332 {
333 return m_start;
334 }
335
337 T get_m_end() const
338 {
339 return m_end;
340 }
341
342private:
343
347
351
358 bool _nextPoint(std::vector<int> & vec, int end) const;
359
361 T _getFactor(int i) const
362 {
363 T prod = 1;
364 for(short_t j = 0; j<=m_p;j++)
365 if(i != j)
366 prod*=(m_breaks[i]-m_breaks[j]);
367 return prod;
368 }
369
370 // Data members
371private:
372
373 // Degree
374 short_t m_p;
375 // param vector
376 std::vector<T> m_breaks;
377 // Interval
378 T m_start;
379 T m_end;
380
381
382
383
384}; // class gsLagrangeBasis
385
386} // namespace gismo
387
388
391
392//include the hpp file that contains the file definitions
393#include "gsLagrangeBasis.hpp"
394
395//#ifndef GISMO_HEADERS_ONLY
396//#include GISMO_HPP_HEADER(gsLagrangeBasis.hpp)
397//#endif
398
399
400
401
402
Struct which represents a certain side of a box.
Definition gsBoundary.h:85
A basis represents a family of scalar basis functions defined over a common parameter domain.
Definition gsBasis.h:79
gsBasis< T >::uPtr boundaryBasis(boxSide const &s)
Returns the boundary basis for side s.
Class representing a domain. i.e. a collection of elements (triangles, rectangles,...
Definition gsDomain.h:32
Abstract base class representing a geometry map.
Definition gsGeometry.h:93
A univariate Lagrange basis.
Definition gsLagrangeBasis.h:46
void deriv2_into(const gsMatrix< T > &u, gsMatrix< T > &result) const
Evaluates the (partial) derivatives of the nonzero basis functions at points u into result.
Definition gsLagrangeBasis.hpp:80
gsLagrangeBasis(const T &start, const T &end, int amount_of_inner_breaks)
Construct Lagrange basis with equidistant breaks in the Interval [start,end].
Definition gsLagrangeBasis.h:84
void anchors_into(gsMatrix< T > &result) const
Returns the anchors (greville points) of the basis.
Definition gsLagrangeBasis.hpp:8
short_t maxDegree() const
Returns the polynomial degree.
Definition gsLagrangeBasis.h:256
gsLagrangeBasis()
Default empty constructor.
Definition gsLagrangeBasis.h:74
GISMO_MAKE_GEOMETRY_NEW std::ostream & print(std::ostream &os) const
Prints the object as a string.
Definition gsLagrangeBasis.h:213
void evalAllDersSingle_into(index_t i, const gsMatrix< T > &u, int n, gsMatrix< T > &result) const
Evaluate the basis function i and its derivatives up to order n at points u into result.
Definition gsLagrangeBasis.hpp:113
void getTransformationLagrangeBezier(gsMatrix< T > &result) const
Definition gsLagrangeBasis.h:283
gsLagrangePoly< T > GeometryType
Associated geometry type.
Definition gsLagrangeBasis.h:54
gsLagrangeBasis(const std::vector< T > &pars, const T &start, const T &end)
Construct Lagrange basis along the parameter pars and Interval [start,end].
Definition gsLagrangeBasis.h:77
memory::unique_ptr< gsLagrangeBasis > uPtr
Unique pointer for gsLagrangeBasis.
Definition gsLagrangeBasis.h:66
void numActive_into(const gsMatrix< T > &u, gsVector< index_t > &result) const
Returns the number of active (nonzero) basis functions at points u in result.
Definition gsLagrangeBasis.h:122
void evalSingle_into(index_t i, const gsMatrix< T > &u, gsMatrix< T > &result) const
Evaluates i-th basis functions at value u.
Definition gsLagrangeBasis.h:172
void reparameterizeToZeroOne()
Changes the basis so the curve is defined in the interval [0,1].
Definition gsLagrangeBasis.hpp:181
void _getTransformationLagrangeMonomial(gsMatrix< T > &result) const
Definition gsLagrangeBasis.hpp:193
const std::vector< T > * get_m_breaks() const
Returns the breaks vector of this basis.
Definition gsLagrangeBasis.h:325
memory::shared_ptr< gsLagrangeBasis > Ptr
Shared pointer for gsLagrangeBasis.
Definition gsLagrangeBasis.h:63
gsLagrangeBasis< T > BoundaryBasisType
Associated Boundary basis type.
Definition gsLagrangeBasis.h:57
T Scalar_t
Coefficient type.
Definition gsLagrangeBasis.h:51
bool check() const
Check the LagrangeBasis for consistency.
Definition gsLagrangeBasis.h:293
void eval_into(const gsMatrix< T > &u, gsMatrix< T > &result) const
Evaluates the non-zero basis functions at value u.
Definition gsLagrangeBasis.hpp:50
gsLagrangeBasis< T > & component(index_t i) const
Returns the same basis for i=0, error otherwise.
Definition gsLagrangeBasis.h:242
gsGeometry< T > * interpolateParameters(gsMatrix< T > const &pts, gsMatrix< T > const &vals) const
Applies interpolation given the parameter values pts and values vals. May be reimplemented in derived...
Definition gsLagrangeBasis.h:275
void active_into(const gsMatrix< T > &u, gsMatrix< index_t > &result) const
Returns the indices of active (non zero) basis functions at points (columns of) u,...
Definition gsLagrangeBasis.hpp:20
std::string detail() const
Prints the object as a string with extended details.
Definition gsLagrangeBasis.h:226
T _getFactor(int i) const
Returns the denominator of the ith basis function.
Definition gsLagrangeBasis.h:361
static const short_t Dim
Dimension of the parameter domain.
Definition gsLagrangeBasis.h:60
T get_m_start() const
Returns the start of the parameter interval.
Definition gsLagrangeBasis.h:331
short_t domainDim() const
Returns the dimension d of the parameter space.
Definition gsLagrangeBasis.h:106
bool _nextPoint(std::vector< int > &vec, int end) const
Definition gsLagrangeBasis.hpp:254
gsMatrix< index_t > boundary(boundary::side const &s) const
Returns the indices of the basis functions that touch the domain boundary.
Definition gsLagrangeBasis.h:143
void evalAllDers_into(const gsMatrix< T > &u, int n, gsMatrix< T > &result) const
Evaluate the nonzero basis functions and their derivatives up to order n at points u into result.
Definition gsLagrangeBasis.hpp:95
void anchor_into(index_t i, gsMatrix< T > &result) const
Returns the anchor point for member i of the basis.
Definition gsLagrangeBasis.h:112
gsMatrix< T > support(const index_t &i) const
Returns a bounding box for the basis' domain.
Definition gsLagrangeBasis.h:158
short_t size() const
Returns the number of basis functions in the basis.
Definition gsLagrangeBasis.h:239
void deriv_into(const gsMatrix< T > &u, gsMatrix< T > &result) const
Evaluates the (partial) derivatives of non-zero basis functions at (the columns of) u.
Definition gsLagrangeBasis.hpp:65
gsMatrix< T > supportInterval(index_t dir) const
Returns an interval that contains the parameter values in direction \ dir.
Definition gsLagrangeBasis.hpp:33
gsMatrix< T > support() const
Returns the boundary basis for side s.
Definition gsLagrangeBasis.h:149
gsDomain< T > * domain() const
Definition gsLagrangeBasis.h:252
T get_m_end() const
Returns the end of the parameter interval.
Definition gsLagrangeBasis.h:337
gsMatrix< index_t > boundary() const
Returns the indices of the basis functions that touch the domain boundary.
Definition gsLagrangeBasis.h:132
short_t minDegree() const
Returns the polynomial degree.
Definition gsLagrangeBasis.h:262
void _getTransformationMonomialBezier(gsMatrix< T > &result) const
Definition gsLagrangeBasis.hpp:236
void deriv2Single_into(index_t i, const gsMatrix< T > &u, gsMatrix< T > &result) const
Evaluate the (partial) derivatives of the i-th basis function at points u into result.
Definition gsLagrangeBasis.h:191
short_t get_m_p() const
Returns the degree of this basis.
Definition gsLagrangeBasis.h:319
short_t degree() const
Returns the polynomial degree.
Definition gsLagrangeBasis.h:268
void evalDerSingle_into(index_t i, const gsMatrix< T > &u, int n, gsMatrix< T > &result) const
Evaluate the (partial) derivative(s) of order n the i-th basis function at points u into result.
Definition gsLagrangeBasis.hpp:127
void derivSingle_into(index_t i, const gsMatrix< T > &u, gsMatrix< T > &result) const
Evaluates the (partial)derivatives of the i-th basis function at (the columns of) u.
Definition gsLagrangeBasis.h:181
The geometry class of a Lagrange Polyomial curve.
Definition gsLagrangePoly.h:27
A matrix with arbitrary coefficient type and fixed or dynamic size.
Definition gsMatrix.h:41
A vector with arbitrary coefficient type and fixed or dynamic size.
Definition gsVector.h:37
Provides declaration of Basis abstract interface.
Provides structs and classes related to interfaces and boundaries.
Provides combinatorial unitilies.
#define short_t
Definition gsConfig.h:35
#define index_t
Definition gsConfig.h:32
#define GISMO_NO_IMPLEMENTATION
Definition gsDebug.h:129
#define GISMO_ERROR(message)
Definition gsDebug.h:118
Provides forward declarations of types and structs.
The G+Smo namespace, containing all definitions for the library.
side
Identifiers for topological sides.
Definition gsBoundary.h:58