G+Smo  24.08.0
Geometry + Simulation Modules
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
gsTensorBSpline.h
Go to the documentation of this file.
1 
14 #pragma once
15 
16 #include <gsCore/gsGeometry.h>
18 
19 namespace gismo
20 {
21 
26 template <short_t d, class T>
27 void constructCoefsForSlice(index_t dir_fixed, const index_t index,
28  const gsMatrix<T> & fullCoefs,
29  const gsVector<index_t, d> & sizes,
30  gsMatrix<T>& result);
31 
43 template<short_t d, class T>
44 class gsTensorBSpline GISMO_FINAL : public gsGeoTraits<d,T>::GeometryBase
45 {
46 public:
47  typedef gsKnotVector<T> KnotVectorType;
48 
49  typedef T Scalar_t;
50 
51  typedef typename gsBSplineTraits<d,T>::Basis Basis;
52 
53  typedef typename gsGeoTraits<d,T>::GeometryBase Base;
54 
57 
59  typedef memory::shared_ptr< gsTensorBSpline > Ptr;
60 
62  typedef memory::unique_ptr< gsTensorBSpline > uPtr;
63 
65  typedef typename gsBSplineTraits<static_cast<short_t>(d-1),T>::Geometry BoundaryGeometryType;
66 
69 
70 public:
71 
74 
75  using gsGeometry<T>::swap;
76 
77 #if !EIGEN_HAS_RVALUE_REFERENCES
78  gsTensorBSpline & operator=(gsTensorBSpline other)
79  { this->swap(other); return *this;}
80 #endif
81 
82  // Construct B-Spline by basis functions and coefficient matrix
83  //gsTensorBSpline( const gsConstantBasis<T> & basis, const gsMatrix<T> & coefs )
84  //{ }
85 
88  : Base( basis, give(coefs) )
89  { }
90 
93  template<typename U>
94  gsTensorBSpline( KnotVectorType KV1, gsKnotVector<U> KV2,
95  gsMatrix<T> tcoefs,
96  typename util::enable_if<d==2,U>::type * = NULL)
97  {
98  GISMO_ASSERT(d==2, "Wrong dimension: tried to make a "
99  << d<<"D tensor B-spline using 2 knot-vectors.");
100 
101  std::vector<Family_t*> cbases;
102  cbases.push_back(new gsBSplineBasis<T>(give(KV1)) );
103  cbases.push_back(new gsBSplineBasis<T>(give(KV2)) );
104  Basis * tbasis = Basis::New(cbases); //d==2
105 
106  GISMO_ASSERT(tbasis->size()==tcoefs.rows(),
107  "Coefficient matrix for the tensor B-spline does not have "
108  "the expected number of control points (rows)." );
109 
110  this->m_basis = tbasis;
111  this->m_coefs = give(tcoefs);
112  }
113 
117  gsTensorBSpline(gsMatrix<T> const & corner,
118  KnotVectorType KV1,
119  KnotVectorType KV2);
120 
123  gsTensorBSpline( KnotVectorType KV1,
124  KnotVectorType KV2,
125  KnotVectorType KV3,
126  gsMatrix<T> tcoefs )
127  {
128  GISMO_ASSERT(d==3, "Wrong dimension: tried to make a "
129  << d<<"D tensor B-spline using 3 knot-vectors.");
130 
131  std::vector<Family_t*> cbases;
132  cbases.push_back(new gsBSplineBasis<T>(give(KV1)) );
133  cbases.push_back(new gsBSplineBasis<T>(give(KV2)) );
134  cbases.push_back(new gsBSplineBasis<T>(give(KV3)) );
135  Basis * tbasis = Basis::New(cbases); //d==3
136 
137  GISMO_ASSERT(tbasis->size()==tcoefs.rows(),
138  "Coefficient matrix for the tensor B-spline does not have "
139  "the expected number of control points (rows)." );
140 
141  this->m_basis = tbasis;
142  this->m_coefs = give(tcoefs);
143  }
144 
147  gsTensorBSpline( KnotVectorType KV1,
148  KnotVectorType KV2,
149  KnotVectorType KV3,
150  KnotVectorType KV4,
151  gsMatrix<T> tcoefs )
152  {
153  GISMO_ASSERT(d==4, "Wrong dimension: tried to make a "
154  << d<<"D tensor B-spline using 4 knot-vectors.");
155 
156  std::vector<Family_t*> cbases;
157  cbases.reserve(4);
158  cbases.push_back(new gsBSplineBasis<T>(give(KV1)) );
159  cbases.push_back(new gsBSplineBasis<T>(give(KV2)) );
160  cbases.push_back(new gsBSplineBasis<T>(give(KV3)) );
161  cbases.push_back(new gsBSplineBasis<T>(give(KV4)) );
162  Basis * tbasis = Basis::New(cbases); //d==4
163 
164  GISMO_ASSERT(tbasis->size()==tcoefs.rows(),
165  "Coefficient matrix for the tensor B-spline does not have "
166  "the expected number of control points (rows)." );
167 
168  this->m_basis = tbasis;
169  this->m_coefs = give(tcoefs);
170  }
171 
172  GISMO_CLONE_FUNCTION(gsTensorBSpline)
173 
174  GISMO_BASIS_ACCESSORS
175 
176 public:
177 
178  // Look at gsGeometry class for a description
179  void degreeElevate(short_t const i = 1, short_t const dir = -1);
180 
182  void insertKnot( T knot, int dir, int i = 1);
183 
185  KnotVectorType & knots(const int i) { return this->basis().knots(i); }
186 
188  const KnotVectorType & knots(const int i) const { return this->basis().knots(i); }
189 
190  /*** Virtual member functions required by the base class ***/
191 
193  std::ostream &print(std::ostream &os) const;
194 
195  /*** Additional members for tensor B-Splines ***/
196 
198  short_t degree(const unsigned & i) const
199  { return this->basis().component(i).degree(); }
200 
203  void reverse(unsigned k);
204 
206  void swapDirections(const unsigned i, const unsigned j);
207 
208  void toggleOrientation();
209 
212  bool isPatchCorner(gsMatrix<T> const &v, T tol = 1e-3) const;
213 
217  void findCorner(const gsMatrix<T> & v,
218  gsVector<index_t,d> & curr,
219  T tol = 1e-3);
220 
224  void setOriginCorner(gsMatrix<T> const &v);
225 
230  void setFurthestCorner(gsMatrix<T> const &v);
231 
234  inline void setPeriodic( int dir )
235  {
236  this->m_coefs = this->basis().perCoefs( this->m_coefs, dir );
237  this->basis().setPeriodic( dir );
238  }
239 
242  typename gsGeometry<T>::uPtr localRep(const gsMatrix<T> & u) const;
243 
244 public:
245 
249  void slice(index_t dir_fixed,T par,BoundaryGeometryType & result) const;
250 
254  std::vector<gsGeometry<T>* > uniformSplit(index_t dir = -1) const;
255 
258  std::vector<gsGeometry<T>* > splitAtMult(index_t minMult = 1, index_t dir = -1) const;
259 
263  void splitAt( index_t dir,T xi, gsTensorBSpline<d,T>& left, gsTensorBSpline<d,T>& right) const;
264 
265  typename gsGeometry<T>::uPtr iface(const boundaryInterface & bi,
266  const gsGeometry<T> & other) const;
267 
268 protected:
269  // TODO Check function
270  // check function: check the coefficient number, degree, knot vector ...
271 
272  using Base::m_basis;
273  using Base::m_coefs;
274 
275 }; // class gsTensorBSpline
276 
277 #ifdef GISMO_WITH_PYBIND11
278 
282  void pybind11_init_gsTensorBSpline2(pybind11::module &m);
283  void pybind11_init_gsTensorBSpline3(pybind11::module &m);
284  void pybind11_init_gsTensorBSpline4(pybind11::module &m);
285 
286 #endif // GISMO_WITH_PYBIND11
287 
288 } // namespace gismo
289 
290 #ifndef GISMO_BUILD_LIB
291 #include GISMO_HPP_HEADER(gsTensorBSpline.hpp)
292 #endif
KnotVectorType & knots(const int i)
Returns a reference to the knot vector in direction i.
Definition: gsTensorBSpline.h:185
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
void reverse(unsigned k)
Definition: gsTensorBSpline.hpp:190
void swapDirections(const unsigned i, const unsigned j)
Swap directions.
Definition: gsTensorBSpline.hpp:201
std::vector< gsGeometry< T > * > uniformSplit(index_t dir=-1) const
Definition: gsTensorBSpline.hpp:386
Traits for BSplineBasis in more dimensions.
Definition: gsBSplineBasis.h:31
short_t degree(const unsigned &i) const
Returns the degree of the basis wrt direction i.
Definition: gsTensorBSpline.h:198
index_t size() const
Returns the number of elements in the basis.
Definition: gsTensorBasis.h:108
gsTensorBSpline()
Default empty constructor.
Definition: gsTensorBSpline.h:73
bool isPatchCorner(gsMatrix< T > const &v, T tol=1e-3) const
Return true if point u is a corner of the patch with tolerance tol.
Definition: gsTensorBSpline.hpp:217
gsBasis< T > * m_basis
Pointer to the basis of this geometry.
Definition: gsGeometry.h:627
void setPeriodic(int dir)
Definition: gsTensorBSpline.h:234
memory::unique_ptr< gsTensorBSpline > uPtr
Unique pointer for gsTensorBSpline.
Definition: gsTensorBSpline.h:62
#define short_t
Definition: gsConfig.h:35
gsBSplineBasis< T > Family_t
Family type.
Definition: gsTensorBSpline.h:56
A tensor product of d B-spline functions, with arbitrary target dimension.
Definition: gsTensorBSpline.h:44
void insertKnot(T knot, int dir, int i=1)
Inserts knot knot at direction dir, i times.
Definition: gsTensorBSpline.hpp:314
void splitAt(index_t dir, T xi, gsTensorBSpline< d, T > &left, gsTensorBSpline< d, T > &right) const
Definition: gsTensorBSpline.hpp:449
gsTensorBSpline(const Basis &basis, gsMatrix< T > coefs)
Construct B-Spline by basis functions and coefficient matrix.
Definition: gsTensorBSpline.h:87
gsGeometry< T >::uPtr localRep(const gsMatrix< T > &u) const
Definition: gsTensorBSpline.hpp:339
S give(S &x)
Definition: gsMemory.h:266
Provides declaration of Geometry abstract interface.
#define index_t
Definition: gsConfig.h:32
A tensor product B-spline basis.
Definition: gsTensorBSplineBasis.h:36
#define GISMO_ASSERT(cond, message)
Definition: gsDebug.h:89
A univariate B-spline basis.
Definition: gsBSplineBasis.h:694
std::vector< gsGeometry< T > * > splitAtMult(index_t minMult=1, index_t dir=-1) const
Definition: gsTensorBSpline.hpp:537
Interface for the set of functions defined on a domain (the total number of functions in the set equa...
Definition: gsFuncData.h:23
gsTensorBSpline(KnotVectorType KV1, KnotVectorType KV2, KnotVectorType KV3, gsMatrix< T > tcoefs)
Definition: gsTensorBSpline.h:123
void findCorner(const gsMatrix< T > &v, gsVector< index_t, d > &curr, T tol=1e-3)
returns the tensor-index curr of the corner control point v, or an invalid index if the corner is not...
Definition: gsTensorBSpline.hpp:235
void setFurthestCorner(gsMatrix< T > const &v)
Modifies the parameterization such that the point v is the ending corner of the parametrization of th...
Definition: gsTensorBSpline.hpp:273
void slice(index_t dir_fixed, T par, BoundaryGeometryType &result) const
Definition: gsTensorBSpline.hpp:125
memory::unique_ptr< gsGeometry > uPtr
Unique pointer for gsGeometry.
Definition: gsGeometry.h:100
void degreeElevate(short_t const i=1, short_t const dir=-1)
Elevate the degree by the given amount i for the direction dir. If dir is -1 then degree elevation is...
Definition: gsTensorBSpline.hpp:286
gsTensorBSpline(KnotVectorType KV1, gsKnotVector< U > KV2, gsMatrix< T > tcoefs, typename util::enable_if< d==2, U >::type *=NULL)
Definition: gsTensorBSpline.h:94
Class for representing a knot vector.
Definition: gsKnotVector.h:79
void setOriginCorner(gsMatrix< T > const &v)
Modifies the parameterization such that the point v is the origin of the parametrization of the patch...
Definition: gsTensorBSpline.hpp:261
Struct which represents an interface between two patches.
Definition: gsBoundary.h:649
const KnotVectorType & knots(const int i) const
Returns a reference to the knot vector i.
Definition: gsTensorBSpline.h:188
virtual const gsBasis< T > & basis() const =0
Returns a const reference to the basis of the geometry.
gsTensorBSpline(KnotVectorType KV1, KnotVectorType KV2, KnotVectorType KV3, KnotVectorType KV4, gsMatrix< T > tcoefs)
Definition: gsTensorBSpline.h:147
void constructCoefsForSlice(index_t dir_fixed, const index_t index, const gsMatrix< T > &fullCoefs, const gsVector< index_t, d > &sizes, gsMatrix< T > &result)
Definition: gsTensorBSpline.hpp:32
std::ostream & print(std::ostream &os) const
Prints the object as a string.
Definition: gsTensorBSpline.hpp:373
memory::shared_ptr< gsTensorBSpline > Ptr
Shared pointer for gsTensorBSpline.
Definition: gsTensorBSpline.h:59
gsBSplineTraits< static_cast< short_t >d-1), T >::Geometry BoundaryGeometryType
Associated Boundary basis type.
Definition: gsTensorBSpline.h:65
gsMatrix< T > & coefs()
Definition: gsGeometry.h:340
Provides declaration of TensorBSplineBasis abstract interface.