G+Smo  24.08.0
Geometry + Simulation Modules
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
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 
12 namespace gismo
13 {
14 
15 // forward declaration
16 template< class T> class gsLagrangeBasis;
17 template <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 
28 template<class T>
29 struct gsTraits<gsLagrangeBasis<T>,1>
30 {
31 typedef gsLagrangeBasis<T> TensorBasisType;
32 typedef gsLagrange<T> TensorGeometryType;
33 typedef gsLagrange<T> TensorBoundaryType;
34 };*/
35 
44 template<class T>
45 class gsLagrangeBasis : public gsBasis<T>
46 {
47 public:
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 
71 public:
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 
99 public:
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 
252  gsDomain<T> * domain() const
254 
257  {
258  return degree();
259  }
260 
263  {
264  return degree();
265  }
266 
268  short_t degree() const
269  {
270  return size()-1;
271  }
272 
276  gsMatrix<T> const& vals) const
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 
319  short_t get_m_p() const
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 
342 private:
343 
346  void _getTransformationLagrangeMonomial(gsMatrix<T> & result) const;
347 
350  void _getTransformationMonomialBezier(gsMatrix<T> & result) const;
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
371 private:
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 
Class representing a domain. i.e. a collection of elements (triangles, rectangles, cubes, simplices.
Definition: gsDomain.h:31
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
gsMatrix< T > support(const index_t &i) const
Returns a bounding box for the basis&#39; domain.
Definition: gsLagrangeBasis.h:158
T get_m_end() const
Returns the end of the parameter interval.
Definition: gsLagrangeBasis.h:337
Abstract base class representing a geometry map.
Definition: gsGeometry.h:92
gsBasis< T >::uPtr boundaryBasis(boxSide const &s)
Returns the boundary basis for side s.
gsLagrangePoly< T > GeometryType
Associated geometry type.
Definition: gsLagrangeBasis.h:54
T Scalar_t
Coefficient type.
Definition: gsLagrangeBasis.h:51
#define GISMO_NO_IMPLEMENTATION
Definition: gsDebug.h:129
const std::vector< T > * get_m_breaks() const
Returns the breaks vector of this basis.
Definition: gsLagrangeBasis.h:325
void getTransformationLagrangeBezier(gsMatrix< T > &result) const
Definition: gsLagrangeBasis.h:283
static const short_t Dim
Dimension of the parameter domain.
Definition: gsLagrangeBasis.h:60
#define short_t
Definition: gsConfig.h:35
Provides structs and classes related to interfaces and boundaries.
gsMatrix< index_t > boundary() const
Returns the indices of the basis functions that touch the domain boundary.
Definition: gsLagrangeBasis.h:132
void _getTransformationLagrangeMonomial(gsMatrix< T > &result) const
Definition: gsLagrangeBasis.hpp:193
std::string detail() const
Prints the object as a string with extended details.
Definition: gsLagrangeBasis.h:226
short_t get_m_p() const
Returns the degree of this basis.
Definition: gsLagrangeBasis.h:319
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
short_t degree() const
Returns the polynomial degree.
Definition: gsLagrangeBasis.h:268
side
Identifiers for topological sides.
Definition: gsBoundary.h:58
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
Provides declaration of Basis abstract interface.
bool _nextPoint(std::vector< int > &vec, int end) const
Definition: gsLagrangeBasis.hpp:254
memory::shared_ptr< gsLagrangeBasis > Ptr
Shared pointer for gsLagrangeBasis.
Definition: gsLagrangeBasis.h:63
#define index_t
Definition: gsConfig.h:32
void eval_into(const gsMatrix< T > &u, gsMatrix< T > &result) const
Evaluates the non-zero basis functions at value u.
Definition: gsLagrangeBasis.hpp:50
memory::unique_ptr< gsLagrangeBasis > uPtr
Unique pointer for gsLagrangeBasis.
Definition: gsLagrangeBasis.h:66
Provides combinatorial unitilies.
GISMO_MAKE_GEOMETRY_NEW std::ostream & print(std::ostream &os) const
Prints the object as a string.
Definition: gsLagrangeBasis.h:213
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, as a list of indices, in result.
Definition: gsLagrangeBasis.hpp:20
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
T get_m_start() const
Returns the start of the parameter interval.
Definition: gsLagrangeBasis.h:331
The geometry class of a Lagrange Polyomial curve.
Definition: gsLagrangeBasis.h:17
gsLagrangeBasis< T > & component(index_t i) const
Returns the same basis for i=0, error otherwise.
Definition: gsLagrangeBasis.h:242
short_t domainDim() const
Returns the dimension d of the parameter space.
Definition: gsLagrangeBasis.h:106
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
short_t minDegree() const
Returns the polynomial degree.
Definition: gsLagrangeBasis.h:262
gsDomain< T > * domain() const
Definition: gsLagrangeBasis.h:252
void anchors_into(gsMatrix< T > &result) const
Returns the anchors (greville points) of the basis.
Definition: gsLagrangeBasis.hpp:8
Interface for the set of functions defined on a domain (the total number of functions in the set equa...
Definition: gsFuncData.h:23
Provides forward declarations of types and structs.
Struct which represents a certain side of a box.
Definition: gsBoundary.h:84
gsMatrix< T > supportInterval(index_t dir) const
Returns an interval that contains the parameter values in direction \ dir.
Definition: gsLagrangeBasis.hpp:33
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
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
gsLagrangeBasis()
Default empty constructor.
Definition: gsLagrangeBasis.h:74
short_t maxDegree() const
Returns the polynomial degree.
Definition: gsLagrangeBasis.h:256
bool check() const
Check the LagrangeBasis for consistency.
Definition: gsLagrangeBasis.h:293
void anchor_into(index_t i, gsMatrix< T > &result) const
Returns the anchor point for member i of the basis.
Definition: gsLagrangeBasis.h:112
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
#define GISMO_ERROR(message)
Definition: gsDebug.h:118
T _getFactor(int i) const
Returns the denominator of the ith basis function.
Definition: gsLagrangeBasis.h:361
short_t size() const
Returns the number of basis functions in the basis.
Definition: gsLagrangeBasis.h:239
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< T > BoundaryBasisType
Associated Boundary basis type.
Definition: gsLagrangeBasis.h:57
void _getTransformationMonomialBezier(gsMatrix< T > &result) const
Definition: gsLagrangeBasis.hpp:236
A univariate Lagrange basis.
Definition: gsLagrangeBasis.h:16
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 reparameterizeToZeroOne()
Changes the basis so the curve is defined in the interval [0,1].
Definition: gsLagrangeBasis.hpp:181
A basis represents a family of scalar basis functions defined over a common parameter domain...
Definition: gsBasis.h:78
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 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
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
gsMatrix< T > support() const
Returns the boundary basis for side s.
Definition: gsLagrangeBasis.h:149