G+Smo  24.08.0
Geometry + Simulation Modules
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
gsHBSpline.h
Go to the documentation of this file.
1 
14 #pragma once
15 
16 #include <ostream>
17 
18 #include <gsCore/gsLinearAlgebra.h>
19 #include <gsCore/gsGeometry.h>
21 
22 namespace gismo
23 {
24 
36 template<short_t d, class T>
37 class gsHBSpline : public gsGeoTraits<d,T>::GeometryBase
38 {
39 public:
40  typedef typename gsGeoTraits<d,T>::GeometryBase Base;
41 
43 
45  typedef memory::shared_ptr< gsHBSpline > Ptr;
46 
48  typedef memory::unique_ptr< gsHBSpline > uPtr;
49 
50  typedef typename
51  util::conditional<d==1, gsConstantFunction<T>, gsHBSpline<static_cast<short_t>(d-1),T>
52  >::type BoundaryGeometryType;
53 
54  typedef typename gsHBSplineBasis<d,T>::BoundaryBasisType BoundaryBasisType;
55 
56 public:
57 
59  gsHBSpline() { }
60 
62  gsHBSpline( const Basis * basis, const gsMatrix<T> * coefs ) :
63  Base( basis, coefs ) { }
64 
66  gsHBSpline( const Basis & basis, const gsMatrix<T> & coefs ) :
67  Base( basis, coefs ) { }
68 
70  explicit gsHBSpline( const gsTensorBSpline<d,T> & tbsp )
71  {
72  this->m_basis = new Basis( tbsp.basis() );
73  this->m_coefs = tbsp.coefs();
74  }
75 
76  GISMO_CLONE_FUNCTION(gsHBSpline)
77 
78  GISMO_BASIS_ACCESSORS
79 
80 public:
81 
85  void slice(index_t dir_fixed,T par,BoundaryGeometryType & result) const
86  {
87  GISMO_ASSERT(d-1>=0,"d must be greater or equal than 1");
88  GISMO_ASSERT(dir_fixed>=0 && static_cast<unsigned>(dir_fixed)<d,"cannot fix a dir greater than dim or smaller than 0");
89  const BoundaryBasisType * bBasis = this->basis().basisSlice(dir_fixed,par);
90  if(d==1)
91  {
92  gsMatrix<T> val(1,1),point;
93  val(0,0)=par;
94  this->eval_into(val,point);
95  result=BoundaryGeometryType(*bBasis,point);
96  }
97  else
98  {
99  gsMatrix<T> vals,anchorsSlice,anchorsInGeom;
100  bBasis->anchors_into(anchorsSlice);
101  anchorsInGeom.resize(anchorsSlice.rows()+1,anchorsSlice.cols());
102  anchorsInGeom.topRows(dir_fixed)=anchorsSlice.topRows(dir_fixed);
103  anchorsInGeom.row(dir_fixed)=gsVector<T>::Constant(anchorsSlice.cols(),par);
104  anchorsInGeom.bottomRows(anchorsSlice.rows()-dir_fixed)=anchorsSlice.bottomRows(anchorsSlice.rows()-dir_fixed);
105  this->eval_into(anchorsInGeom,vals);
106  BoundaryGeometryType* geom =
107  dynamic_cast<BoundaryGeometryType *>(bBasis->interpolateAtAnchors(vals).release()); //todo make it better
108  GISMO_ASSERT(geom!=NULL,"bBasis should have BoundaryGeometryType.");
109  result = *geom;
110  delete geom;
111  }
112  delete bBasis;
113  }
114 }; // class gsHBSpline
115 
116 #ifdef GISMO_WITH_PYBIND11
117 
121  void pybind11_init_gsHBSpline2(pybind11::module &m);
122  void pybind11_init_gsHBSpline3(pybind11::module &m);
123  void pybind11_init_gsHBSpline4(pybind11::module &m);
124 
125 #endif // GISMO_WITH_PYBIND11
126 
127 } // namespace gismo
128 
129 #ifndef GISMO_BUILD_LIB
130 #include GISMO_HPP_HEADER(gsHBSpline.hpp)
131 #endif
Abstract base class representing a geometry map.
Definition: gsGeometry.h:92
gsMatrix< T > m_coefs
Coefficient matrix of size coefsSize() x geoDim()
Definition: gsGeometry.h:624
gsBasis< T > * m_basis
Pointer to the basis of this geometry.
Definition: gsGeometry.h:627
gsHBSpline()
Default empty constructor.
Definition: gsHBSpline.h:59
A tensor product of d B-spline functions, with arbitrary target dimension.
Definition: gsTensorBSpline.h:44
gsHBSpline(const Basis &basis, const gsMatrix< T > &coefs)
Construct HB-Spline by basis functions and coefficient matrix.
Definition: gsHBSpline.h:66
A hierarchical B-spline basis of parametric dimension d.
Definition: gsHBSplineBasis.h:35
memory::unique_ptr< gsHBSpline > uPtr
Unique pointer for gsHBSpline.
Definition: gsHBSpline.h:48
Provides declaration of Geometry abstract interface.
#define index_t
Definition: gsConfig.h:32
gsHBSpline(const gsTensorBSpline< d, T > &tbsp)
Construct B-Spline from a Tensor B-Spline.
Definition: gsHBSpline.h:70
gsHBSpline(const Basis *basis, const gsMatrix< T > *coefs)
Construct HB-Spline by basis functions and coefficient matrix.
Definition: gsHBSpline.h:62
#define GISMO_ASSERT(cond, message)
Definition: gsDebug.h:89
memory::shared_ptr< gsHBSpline > Ptr
Shared pointer for gsHBSpline.
Definition: gsHBSpline.h:45
A vector with arbitrary coefficient type and fixed or dynamic size.
Definition: gsVector.h:35
Interface for the set of functions defined on a domain (the total number of functions in the set equa...
Definition: gsFuncData.h:23
A hierarchical B-Spline function, in d dimensions.
Definition: gsHBSpline.h:37
void eval_into(const gsMatrix< T > &u, gsMatrix< T > &result) const
Evaluate the function at points u into result.
Definition: gsGeometry.hpp:166
This is the main header file that collects wrappers of Eigen for linear algebra.
void slice(index_t dir_fixed, T par, BoundaryGeometryType &result) const
Definition: gsHBSpline.h:85
virtual const gsBasis< T > & basis() const =0
Returns a const reference to the basis of the geometry.
Provides declaration of HBSplineBasis class.
gsMatrix< T > & coefs()
Definition: gsGeometry.h:340