G+Smo  24.08.0
Geometry + Simulation Modules
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
gsTHBSplineBasis.h
Go to the documentation of this file.
1 
15 #pragma once
16 
18 #include <gsHSplines/gsTHBSpline.h>
19 
20 
21 namespace gismo
22 {
23 
34 template<short_t d, class T>
35 class gsTHBSplineBasis : public gsHTensorBasis<d,T>
36 {
37 public:
40 
41  typedef typename gsHTensorBasis<d,T>::CMatrix CMatrix;
42 
43  typedef typename gsHTensorBasis<d,T>::cmatIterator cmatIterator;
44 
46 
47  typedef typename gsHTensorBasis<d,T>::point point;
48 
50  typedef memory::shared_ptr< gsTHBSplineBasis > Ptr;
51 
53  typedef memory::unique_ptr< gsTHBSplineBasis > uPtr;
54 
56  typedef typename
57  util::conditional<d==1, gsConstantBasis<T>, gsTHBSplineBasis<static_cast<short_t>(d-1),T> >::type BoundaryBasisType;
58 
62 
63  // polygon lines in parameter domain
64  // the stucture is [levels [ line [ segments [ x y z w ] ] ] ],
65  // where x y z w describes segment from (x, y) to (z, w)
66  typedef typename std::vector< std::vector< std::vector< std::vector<T> > > > Polylines;
67 
68  // axis aligned bounding boxes in parameter domain
69  // the structure is [levels [ boxes [ low_x low_y upp_x upp_y] ] ]
70  // where the box is define by lower left corner (low_x, low_y) and upper right
71  // corner (upp_x, upp_y)
72  typedef typename std::vector< std::vector< std::vector<index_t> > > AxisAlignedBoundingBox;
73 
74  //typedef typename std::vector< gsAabb<T> > AxisAlignedBoundingBox;
75 
76  // trimming curves in parameter domain
77  // the stucture is [level [connected componenet [ line [ segments [ x y z w ] ] ] ] ],
78  // where x y z w describes segment from (x, y) to (z, w), and first line
79  // indicates outer loop and next line describes holes
80  typedef typename std::vector< std::vector< std::vector< std::vector< std::vector<T> > > > > TrimmingCurves;
81 
82 public:
83 
85  {
86  representBasis();
87  }
88 
90  const std::vector<index_t> & boxes)
91  : gsHTensorBasis<d,T>(tbasis, boxes)
92  { representBasis(); }
93 
94  gsTHBSplineBasis(gsTensorBSplineBasis<d,T> const& tbasis,
95  gsMatrix<T> const & boxes)
96  : gsHTensorBasis<d,T>(tbasis, boxes)
97  { representBasis(); }
98 
99  gsTHBSplineBasis( gsTensorBSplineBasis<d,T> const& tbasis,
100  gsMatrix<T> const & boxes,
101  const std::vector<index_t> & levels)
102  : gsHTensorBasis<d,T>(tbasis, boxes, levels)
103  { representBasis(); }
104 
106  gsTHBSplineBasis(gsBasis<T> const& tbasis, bool manualLevels=false)
107  : gsHTensorBasis<d,T>(tbasis, manualLevels)
108  { representBasis(); }
109 
110 #ifdef __DOXYGEN__
111  typename BoundaryBasisType::uPtr boundaryBasis(boxSide const & s);
113 #endif
114  GISMO_UPTR_FUNCTION_DEF(BoundaryBasisType, boundaryBasis, boxSide const &)
115  {
116  return basisSlice(n1.direction(),n1.parameter());
117  }
118 
119 public:
120 
121  // Look at gsBasis.h for the documentation of this function
122  gsMatrix<index_t> boundaryOffset(boxSide const & s, index_t offset ) const;
123 
125  BoundaryBasisType * basisSlice(index_t dir_fixed,T par ) const;
126 
127  // Look at gsBasis class for documentation
128  void active_into(const gsMatrix<T>& u, gsMatrix<index_t>& result) const;
129 
130  index_t numActiveMax(const gsMatrix<T> & u, gsMatrix<index_t> & offset) const;
131 
132  // returns all actives at \a u from level \a lvl only
133  // Does not clear result, only appends data
134  void activeAtLevel_into(index_t lvl, const gsMatrix<T>& u,
135  std::vector<index_t> & result) const;
136 
137  // Look at gsBasis class for documentation
138  void deriv2_into(const gsMatrix<T>& u, gsMatrix<T>& result)const;
139 
140  // Look at gsBasis class for documentatation
141  void deriv2Single_into(index_t i,
142  const gsMatrix<T>& u,
143  gsMatrix<T>& result) const;
144 
145  // Look at gsBasis class for documentation
146  void deriv_into(const gsMatrix<T>& u, gsMatrix<T>& result) const;
147 
148  // Look at gsBasis class for documentation
149  void derivSingle_into(index_t i,
150  const gsMatrix<T> & u,
151  gsMatrix<T>& result) const;
152 
153  void evalAllDers_into(const gsMatrix<T> & u, int n,
154  std::vector<gsMatrix<T> > & result,
155  bool sameElement = false) const;
156 
157  // look at eval_into
158  void fastEval_into(const gsMatrix<T>& u,
159  gsMatrix<T>& result) const
160  {
161  gsMatrix<index_t> indices;
162  this->active_into(u, indices);
163 
164  result.setZero(indices.rows(), u.cols());
165 
166  const unsigned maxLvl = this->m_tree.getMaxInsLevel() + 1;
167  std::vector< gsMatrix<T> > tmpResults(maxLvl, gsMatrix<T>());
168  std::vector< gsMatrix<index_t> > tmpActive(maxLvl, gsMatrix<index_t>());
169  gsVector<int> processed(maxLvl);
170 
171  for (int pt = 0; pt != u.cols(); pt++)
172  {
173  processed.setZero();
174 
175  for (int ind = 0; ind != indices.rows(); ind++)
176  {
177  unsigned index = indices(ind, pt);
178  if (ind != 0 && index == 0)
179  break;
180 
181  unsigned lvl = getPresLevelOfBasisFun(index);
182 
183  if (processed(lvl) == 0)
184  {
185  this->m_bases[lvl]->eval_into(u.col(pt), tmpResults[lvl]);
186  this->m_bases[lvl]->active_into(u.col(pt), tmpActive[lvl]);
187  processed(lvl) = 1;
188  }
189 
190  if (m_is_truncated[index] == -1)
191  {
192  index_t flatTenIndx = this->flatTensorIndexOf(index, lvl);
193  int localIndex = -1;
194  for (int row = 0; row != tmpActive[lvl].rows(); ++row)
195  {
196  if (tmpActive[lvl](row, 0) == flatTenIndx)
197  {
198  localIndex = row;
199  break;
200  }
201  }
202  result(ind, pt) = tmpResults[lvl](localIndex, 0);
203  }
204  else // basis function is truncated
205  {
206  const gsMatrix<T>& basis = tmpResults[lvl];
207  const gsMatrix<index_t>& active = tmpActive[lvl];
208 
209 
210  const gsSparseVector<T>& coefs = getCoefs(index);
211  T tmp = coefs(active(0, 0)) * basis(0, 0);
212  for (int i = 1; i < active.rows(); i++)
213  {
214  tmp += coefs(active(i, 0)) * basis(i, 0);
215  }
216  result(ind, pt) = tmp;
217  }
218  }
219  }
220  }
221 
222  // look at deriv_into
223  void fastDeriv_into(const gsMatrix<T>& u,
224  gsMatrix<T>& result) const
225  {
226  gsMatrix<index_t> indices;
227  this->active_into(u, indices);
228 
229  result.setZero(indices.rows() * d, u.cols());
230 
231  const unsigned maxLvl = this->m_tree.getMaxInsLevel() + 1;
232  std::vector< gsMatrix<T> > tmpDeriv( maxLvl, gsMatrix<T>());
233  std::vector< gsMatrix<index_t> > tmpActive(maxLvl, gsMatrix<index_t>());
234  gsVector<int> processed(maxLvl);
235 
236  for (index_t pt = 0; pt != u.cols(); pt++)
237  {
238  processed.setZero();
239 
240  for (int ind = 0; ind != indices.rows(); ind++)
241  {
242  index_t index = indices(ind, pt);
243  if (ind != 0 && index == 0)
244  break;
245 
246  unsigned lvl = getPresLevelOfBasisFun(index);
247 
248  if (processed(lvl) == 0)
249  {
250  this->m_bases[lvl]->deriv_into(u.col(pt), tmpDeriv[lvl]);
251  this->m_bases[lvl]->active_into(u.col(pt), tmpActive[lvl]);
252  processed(lvl) = 1;
253  }
254 
255  if (m_is_truncated[index] == -1)
256  {
257  index_t flatTenIndx = this->flatTensorIndexOf(index, lvl);
258  int localIndex = -1;
259  for (int row = 0; row != tmpActive[lvl].rows(); ++row)
260  {
261  if (tmpActive[lvl](row, 0) == flatTenIndx)
262  {
263  localIndex = row;
264  break;
265  }
266  }
267 
268  result.block(ind * d, pt, d, 1) =
269  tmpDeriv[lvl].block(localIndex * d, 0, d, 1);
270  }
271  else // basis function is truncated
272  {
273  const gsMatrix<T>& basis = tmpDeriv[lvl];
274  const gsMatrix<index_t>& active = tmpActive[lvl];
275  const gsSparseVector<T>& coefs = getCoefs(index);
276 
277  for (unsigned dim = 0; dim != d; dim++) // for all deric
278  {
279  for (index_t i = 0; i != active.rows(); ++i)
280  {
281  result(ind * d + dim, pt) +=
282  coefs(active(i, 0)) * basis(i * d + dim, 0);
283  }
284  }
285  }
286  }
287  }
288  }
289 
290  // look at deriv2_into
291  void fastDeriv2_into(const gsMatrix<T>& u,
292  gsMatrix<T>& result) const
293  {
294  gsMatrix<index_t> indices;
295  this->active_into(u, indices);
296  const unsigned numDers = (d * (d + 1)) / 2;
297 
298  result.setZero(indices.rows() * numDers, u.cols());
299 
300  const unsigned maxLvl = this->m_tree.getMaxInsLevel() + 1;
301  std::vector< gsMatrix<T> > tmpDeriv2(maxLvl, gsMatrix<T>());
302  std::vector< gsMatrix<index_t> > tmpActive(maxLvl, gsMatrix<index_t>());
303  gsVector<int> processed(maxLvl);
304 
305  for (int pt = 0; pt != u.cols(); pt++)
306  {
307  processed.setZero();
308 
309  for (int ind = 0; ind != indices.rows(); ind++)
310  {
311 
312  unsigned index = indices(ind, pt);
313  if (ind != 0 && index == 0)
314  break;
315 
316  unsigned lvl = getPresLevelOfBasisFun(index);
317 
318  if (processed(lvl) == 0)
319  {
320  this->m_bases[lvl]->deriv2_into(u.col(pt), tmpDeriv2[lvl]);
321  this->m_bases[lvl]->active_into(u.col(pt), tmpActive[lvl]);
322  processed(lvl) = 1;
323  }
324 
325  if (m_is_truncated[index] == -1)
326  {
327  index_t flatTenIndx = this->flatTensorIndexOf(index, lvl);
328  int localIndx = -1;
329  for (int row = 0; row != tmpActive[lvl].rows(); ++row)
330  {
331  if (tmpActive[lvl](row, 0) == flatTenIndx)
332  {
333  localIndx = row;
334  break;
335  }
336  }
337 
338  result.block(ind * numDers, pt, numDers, 1) =
339  tmpDeriv2[lvl].block(localIndx * numDers, 0, numDers, 1);
340  }
341  else // basis function is truncated
342  {
343  const gsMatrix<T>& basis = tmpDeriv2[lvl];
344  const gsMatrix<index_t>& active = tmpActive[lvl];
345  const gsSparseVector<T>& coefs = getCoefs(index);
346 
347  for (unsigned der = 0; der != numDers; der++)
348  {
349  for (index_t i = 0; i != active.rows(); ++i)
350  {
351  result(ind * numDers + der, pt) +=
352  coefs(active(i, 0)) *
353  basis(i * numDers + der, 0);
354  }
355  }
356  }
357  }
358  }
359  }
360 
361  // Look at gsBasis class for documentation
362  void eval_into(const gsMatrix<T> & u, gsMatrix<T>& result) const;
363 
364  // Because of overriding one of the "eval_into" functions, all
365  // functions in the base class with this name are hidden from the
366  // derived class: Compiler does not search the base class as soon
367  // as the function name is found in the derived class.
368  // Therefore we need to add a "using" declaration to "reveal" the
369  // function again. THis brings into scope all definitions of
370  // eval_into from the base class.
371  using gsBasis<T>::eval_into;
372 
374  unsigned numTruncated() const
375  { return m_presentation.size(); }
376 
377  bool isTruncated(unsigned i) const
378  {
379  return (this->m_is_truncated[i] != -1);
380  }
381 
383  typename std::map<index_t, gsSparseVector<T> >::const_iterator truncatedBegin() const
384  { return m_presentation.begin(); }
385 
387  typename std::map<index_t, gsSparseVector<T> >::const_iterator truncatedEnd() const
388  { return m_presentation.end(); }
389 
391  const gsSparseVector<T>& getCoefs(unsigned i) const
392  {
393  if (this->m_is_truncated[i] == -1)
394  {
395  GISMO_ERROR("This basis function has no sparse representation. "
396  "It is not truncated.");
397  }
398  else
399  {
400  return this->m_presentation.find(i)->second;
401  }
402  }
403 
404 
405  void evalSingle_into(index_t i,
406  const gsMatrix<T>& u,
407  gsMatrix<T>& result) const;
408 
409 private:
410 
411  index_t getPresLevelOfBasisFun(const index_t index) const
412  {
413  return (m_is_truncated[index] == -1 ?
414  this->levelOf(index) : m_is_truncated[index] );
415  }
416 
418  void representBasis(); // rename: precompute coeffs
419 
420 
428  void _representBasisFunction(const unsigned j,
429  const unsigned pres_level,
430  const gsVector<index_t, d>& finest_low,
431  const gsVector<index_t, d>& finest_high);
432 
433 
434 
445  void _saveNewBasisFunPresentation(const gsMatrix<T>& coefs,
446  const gsVector<index_t, d>& act_size_of_coefs,
447  const unsigned j,
448  const unsigned pres_level,
449  const gsVector<index_t, d>& finest_low);
450 
451 
452 
462  unsigned _basisFunIndexOnLevel(const gsVector<index_t, d>& index,
463  const unsigned level,
464  const gsVector<index_t, d>& fin_low,
465  const unsigned new_level);
466 
467 
468 
480  void _truncate(gsMatrix<T>& coefs,
481  const gsVector<index_t, d>& act_size_of_coefs,
482  const gsVector<index_t, d>& size_of_coefs,
483  const unsigned level,
484  const gsVector<index_t, d>& bspl_vec_ti,
485  const unsigned bspl_vec_ti_level,
486  const gsVector<index_t, d>& finest_low);
487 
488 
502  unsigned _updateSizeOfCoefs(const unsigned clevel,
503  const unsigned flevel,
504  const gsVector<index_t, d>& finest_low,
505  const gsVector<index_t, d>& finest_high,
506  gsVector<index_t, d>& size_of_coefs);
507 
508 public:
509 
511  short_t domainDim() const { return d; }
512 
513  GISMO_CLONE_FUNCTION(gsTHBSplineBasis)
514 
515 
516  std::ostream &print(std::ostream &os) const
517  {
518  os << "Truncated ";
520  //this->printCharMatrix(os);
521  return os;
522  }
523 
524  GISMO_MAKE_GEOMETRY_NEW
525 
526 
540  unsigned level,
541  const gsMatrix<T>& geom_coef,
542  gsMatrix<T>& cp, gsKnotVector<T>& k1,
543  gsKnotVector<T>& k2) const;
544 
554  void getBsplinePatches(const gsMatrix<T>& geom_coef, gsMatrix<T>& cp, gsMatrix<index_t>& b1, gsMatrix<index_t>& b2, gsVector<index_t>& level, gsMatrix<index_t>& nvertices) const;
555 
561 
573  std::vector<std::vector<std::vector< std::vector<T> > > >& trim_curves) const;
574 
581  const gsMatrix<T>& geom_coef,
582  std::vector<std::vector<std::vector< std::vector<T> > > >& trim_curves) const;
583 
584  /*
585  * @brief Return the connected components of domain levels in knot vector indices (the boundary of a CC and the holes in the corresponding component)
586  * @param[out] level levels of the boxes (level[i]: level of the i-th box,)
587  * @param[out] connectedComponents the connected components in format vector<connected_component<polylines<segments<index_t> > > > where the first polyline is the outer curve and the rest are holes
588  */
589  void getConnectedComponents(std::vector<std::vector<std::vector< std::vector<index_t> > > >& connectedComponents, gsVector<index_t>& level) const;
590 
591 
593  void transferbyLvl (std::vector<gsSparseMatrix<T> >& result);
594 
603  void decomposeDomain(typename gsTHBSplineBasis::AxisAlignedBoundingBox& boundaryAABB,
604  typename gsTHBSplineBasis::TrimmingCurves& trimCurves) const;
605 
610  gsTensorBSpline<d,T> getBSplinePatch(const std::vector<index_t>& boundingBox,
611  const unsigned level,
612  const gsMatrix<T>& geomCoefs) const;
613 
614 private:
620  {
622  representBasis();
623  }
624 
636  // todo: rename as: representAtLevel
637  void globalRefinement(const gsMatrix<T> & thbCoefs, int level,
638  gsMatrix<T> & lvlCoefs) const;
639 
640  gsSparseMatrix<T> coarsening(const std::vector<gsSortedVector<index_t> >& old,
641  const std::vector<gsSortedVector<index_t> >& n,
642  const gsSparseMatrix<T,RowMajor> & transfer) const;
643 
644  gsSparseMatrix<T> coarsening_direct( const std::vector<gsSortedVector<index_t> >& old,
645  const std::vector<gsSortedVector<index_t> >& n,
646  const std::vector<gsSparseMatrix<T,RowMajor> >& transfer) const;
647 
648  gsSparseMatrix<T> coarsening_direct2( const std::vector<gsSortedVector<index_t> >& old,
649  const std::vector<gsSortedVector<index_t> >& n,
650  const std::vector<gsSparseMatrix<T,RowMajor> >& transfer) const;
651 
652 
653  // ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
654  // Utility functions for decomposeDomain
655  // ......................................................................
656 
660  bool isFirstBoxCompletelyInsideSecond(const std::vector<index_t>& firstBox,
661  const std::vector<index_t>& secondBox) const
662  {
663  return secondBox[0] < firstBox[0] && secondBox[1] < firstBox[1] &&
664  firstBox[2] < secondBox[2] && firstBox[3] < secondBox[3];
665  }
666 
667 
671  bool areBoxesTheSame(const std::vector<index_t>& firstBox,
672  const std::vector<index_t>& secondBox) const
673  {
674  return firstBox[0] == secondBox[0] && firstBox[1] == secondBox[1] &&
675  firstBox[2] == secondBox[2] && firstBox[3] == secondBox[3];
676  }
677 
686  void breakCycles(typename gsTHBSplineBasis::AxisAlignedBoundingBox& aabb,
687  typename gsTHBSplineBasis::Polylines& polylines) const;
688 
689 
695  index_t identifyCycle(const std::vector< std::vector< T> >& polyline,
696  std::pair<T, T>& pt) const;
697 
698 
709  void breakPolylineIntoTwoParts(const std::vector< std::vector<T> >& polyline,
710  const index_t segment,
711  const std::pair<T, T>& pt,
712  std::vector< std::vector<T> >& part1,
713  std::vector< std::vector<T> >& part2) const;
714 
715 
717  void findNewAABB(const std::vector< std::vector<T> >& polyline,
718  std::vector<index_t>& aabb) const;
719 
720 
721 private:
722 
723  template<short_t dd>
724  typename util::enable_if<dd==2,void>::type
725  getBsplinePatchGlobal_impl(gsVector<index_t> b1,
727  unsigned level,
728  const gsMatrix<T>& geom_coef,
729  gsMatrix<T>& cp, gsKnotVector<T>& k1,
730  gsKnotVector<T>& k2) const;
731 
732  template<short_t dd>
733  typename util::enable_if<dd!=2,void>::type
734  getBsplinePatchGlobal_impl(gsVector<index_t> ,
736  unsigned ,
737  const gsMatrix<T>&,
740 
741  template<short_t dd>
742  typename util::enable_if<dd==2,gsTensorBSpline<d,T> >::type
743  getBSplinePatch_impl(const std::vector<index_t>& boundingBox,
744  const unsigned level,
745  const gsMatrix<T>& geomCoefs) const;
746 
747  template<short_t dd>
748  typename util::enable_if<dd!=2,gsTensorBSpline<d,T> >::type
749  getBSplinePatch_impl(const std::vector<index_t>&,
750  const unsigned,
751  const gsMatrix<T>&) const { GISMO_NO_IMPLEMENTATION }
752 
753 
754 private:
755 
756  // m_is_truncated(j)
757  // if -1 : j-th basis function is not truncated,
758  // if \em k>0 : j-th basis function is truncated and its representation level is \em k
759  gsVector<int> m_is_truncated;
760 
761 
762  // m_presentation[j] is presentation of the j-th basis function in terms of
763  // B-Splines at level m_is_truncated[j]
764  //
765  // if m_is_truncated[j] is equal to -1, then there is no entry
766  // m_presentation[j]
767  std::map<index_t, gsSparseVector<T> > m_presentation;
768 
769  using gsHTensorBasis<d,T>::m_bases;
770  using gsHTensorBasis<d,T>::m_xmatrix;
771  using gsHTensorBasis<d,T>::m_xmatrix_offset;
772  using gsHTensorBasis<d,T>::m_deg;
773 };
778 #ifdef GISMO_WITH_PYBIND11
779 
783  void pybind11_init_gsTHBSplineBasis2(pybind11::module &m);
784  void pybind11_init_gsTHBSplineBasis3(pybind11::module &m);
785  void pybind11_init_gsTHBSplineBasis4(pybind11::module &m);
786 
787 #endif // GISMO_WITH_PYBIND11
788 
789 } // namespace gismo
790 
791 #ifndef GISMO_BUILD_LIB
792 #include GISMO_HPP_HEADER(gsTHBSplineBasis.hpp)
793 #endif
794 
void _saveNewBasisFunPresentation(const gsMatrix< T > &coefs, const gsVector< index_t, d > &act_size_of_coefs, const unsigned j, const unsigned pres_level, const gsVector< index_t, d > &finest_low)
Saves a presentation of the j-th basis function. Presentation is given by the coefficients coefs...
Definition: gsTHBSplineBasis.hpp:241
Provides definition of HTensorBasis abstract interface.
bool manualLevels() const
Returns true if levels are assigned manually.
Definition: gsHTensorBasis.h:332
index_t flatTensorIndexOf(const index_t i) const
Returns the tensor index of the function indexed i (in continued indices).
Definition: gsHTensorBasis.h:932
memory::shared_ptr< gsTHBSplineBasis > Ptr
Shared pointer for gsTHBSplineBasis.
Definition: gsTHBSplineBasis.h:50
void deriv_into(const gsMatrix< T > &u, gsMatrix< T > &result) const
Evaluates the first partial derivatives of the nonzero basis function.
Definition: gsTHBSplineBasis.hpp:1568
void _representBasisFunction(const unsigned j, const unsigned pres_level, const gsVector< index_t, d > &finest_low, const gsVector< index_t, d > &finest_high)
Computes representation of j-th basis function on pres_level and saves it.
Definition: gsTHBSplineBasis.hpp:143
A truncated hierarchical B-Spline function, in d dimensions.
Definition: gsTHBSpline.h:37
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: gsTHBSplineBasis.hpp:1486
#define GISMO_NO_IMPLEMENTATION
Definition: gsDebug.h:129
void evalAllDers_into(const gsMatrix< T > &u, int n, std::vector< gsMatrix< T > > &result, bool sameElement=false) const
Evaluate the nonzero functions and their derivatives up to order n at points u into result...
Definition: gsTHBSplineBasis.hpp:1673
void eval_into(const gsMatrix< T > &u, gsMatrix< T > &result) const
Evaluates nonzero basis functions at point u into result.
Definition: gsTHBSplineBasis.hpp:1510
gsMultiPatch< T > getBsplinePatchesToMultiPatch_trimming(const gsMatrix< T > &geom_coef, std::vector< std::vector< std::vector< std::vector< T > > > > &trim_curves) const
Return a multipatch structure of B-splines.
Definition: gsTHBSplineBasis.hpp:887
unsigned _basisFunIndexOnLevel(const gsVector< index_t, d > &index, const unsigned level, const gsVector< index_t, d > &fin_low, const unsigned new_level)
Computes tensor index of a basis function on a finer level (new_level) which is presented with tensor...
Definition: gsTHBSplineBasis.hpp:300
void breakPolylineIntoTwoParts(const std::vector< std::vector< T > > &polyline, const index_t segment, const std::pair< T, T > &pt, std::vector< std::vector< T > > &part1, std::vector< std::vector< T > > &part2) const
Breaks polyline into two parts.
Definition: gsTHBSplineBasis.hpp:2189
void deriv2_into(const gsMatrix< T > &u, gsMatrix< T > &result) const
Evaluate the second derivatives of all active basis function at points u.
Definition: gsTHBSplineBasis.hpp:1541
gsMatrix< index_t > active(const gsMatrix< T > &u) const
Returns the indices of active (nonzero) functions at points u, as a list of indices.
Definition: gsFunctionSet.h:453
#define short_t
Definition: gsConfig.h:35
A tensor product of d B-spline functions, with arbitrary target dimension.
Definition: gsTensorBSpline.h:44
util::conditional< d==1, gsConstantBasis< T >, gsTHBSplineBasis< static_cast< short_t >d-1), T > >::type BoundaryBasisType
Associated Boundary basis type.
Definition: gsTHBSplineBasis.h:57
const gsSparseVector< T > & getCoefs(unsigned i) const
Returns sparse representation of the i-th basis function.
Definition: gsTHBSplineBasis.h:391
short_t domainDim() const
Returns the dimension of the parameter space.
Definition: gsTHBSplineBasis.h:511
void findNewAABB(const std::vector< std::vector< T > > &polyline, std::vector< index_t > &aabb) const
Finds new axis aligned bounding box for given polyline.
Definition: gsTHBSplineBasis.hpp:2243
std::map< index_t, gsSparseVector< T > >::const_iterator truncatedBegin() const
Returns an iterator to the representation of the first truncated basis function.
Definition: gsTHBSplineBasis.h:383
gsTHBSpline< d, T > GeometryType
Associated geometry type.
Definition: gsTHBSplineBasis.h:39
Provides declaration of THBSplineBasis class.
std::vector< tensorBasis * > m_bases
The list of nested spaces.
Definition: gsHTensorBasis.h:361
void _truncate(gsMatrix< T > &coefs, const gsVector< index_t, d > &act_size_of_coefs, const gsVector< index_t, d > &size_of_coefs, const unsigned level, const gsVector< index_t, d > &bspl_vec_ti, const unsigned bspl_vec_ti_level, const gsVector< index_t, d > &finest_low)
Performs truncation.
Definition: gsTHBSplineBasis.hpp:339
gsHTensorBasis()
Default empty constructor.
Definition: gsHTensorBasis.h:113
#define index_t
Definition: gsConfig.h:32
void printBasic(std::ostream &os=gsInfo) const
Prints the spline-space hierarchy.
Definition: gsHTensorBasis.h:560
void evalSingle_into(index_t i, const gsMatrix< T > &u, gsMatrix< T > &result) const
Evaluate the i-th basis function at points u into result.
Definition: gsTHBSplineBasis.hpp:1462
This class is derived from std::vector, and adds sort tracking.
Definition: gsSortedVector.h:109
void breakCycles(typename gsTHBSplineBasis::AxisAlignedBoundingBox &aabb, typename gsTHBSplineBasis::Polylines &polylines) const
Breaks the cycles of polylines and returns updated polylines.
Definition: gsTHBSplineBasis.hpp:2101
A tensor product B-spline basis.
Definition: gsTensorBSplineBasis.h:36
bool areBoxesTheSame(const std::vector< index_t > &firstBox, const std::vector< index_t > &secondBox) const
Checks if the boxes are the same.
Definition: gsTHBSplineBasis.h:671
BoundaryBasisType * basisSlice(index_t dir_fixed, T par) const
Gives back the basis at a slice in dir_fixed at par.
Definition: gsTHBSplineBasis.hpp:76
void decomposeDomain(typename gsTHBSplineBasis::AxisAlignedBoundingBox &boundaryAABB, typename gsTHBSplineBasis::TrimmingCurves &trimCurves) const
Decomposes domain of the THB-Spline-Basis into partitions.
Definition: gsTHBSplineBasis.hpp:1951
index_t identifyCycle(const std::vector< std::vector< T > > &polyline, std::pair< T, T > &pt) const
Identify if the polyline can be split into two cycles.
Definition: gsTHBSplineBasis.hpp:2141
void globalRefinement(const gsMatrix< T > &thbCoefs, int level, gsMatrix< T > &lvlCoefs) const
Returns a representation of thbCoefs as tensor-product B-spline coefficientes lvlCoefs at level level...
Definition: gsTHBSplineBasis.hpp:1037
Class representing a (scalar) hierarchical tensor basis of functions .
Definition: gsHTensorBasis.h:74
std::map< index_t, gsSparseVector< T > >::const_iterator truncatedEnd() const
Returns an iterator past the last truncated basis function.
Definition: gsTHBSplineBasis.h:387
void update_structure()
Initialize the characteristic and coefficient matrices and the internal bspline representations.
Definition: gsTHBSplineBasis.h:619
const gsBasis< T > & basis(const index_t k) const
Helper which casts and returns the k-th piece of this function set as a gsBasis.
Definition: gsFunctionSet.hpp:33
unsigned _updateSizeOfCoefs(const unsigned clevel, const unsigned flevel, const gsVector< index_t, d > &finest_low, const gsVector< index_t, d > &finest_high, gsVector< index_t, d > &size_of_coefs)
We get current size of the coefficients. Function updates this sizes accordingly to the refinement fr...
Definition: gsTHBSplineBasis.hpp:424
memory::unique_ptr< gsTHBSplineBasis > uPtr
Unique pointer for gsTHBSplineBasis.
Definition: gsTHBSplineBasis.h:53
void getBsplinePatches(const gsMatrix< T > &geom_coef, gsMatrix< T > &cp, gsMatrix< index_t > &b1, gsMatrix< index_t > &b2, gsVector< index_t > &level, gsMatrix< index_t > &nvertices) const
Return the list of B-spline patches to represent a THB-spline geometry.
Definition: gsTHBSplineBasis.hpp:522
gsTensorBSpline< d, T > getBSplinePatch(const std::vector< index_t > &boundingBox, const unsigned level, const gsMatrix< T > &geomCoefs) const
Returns a tensor B-Spline patch defined by boundingBox.
Definition: gsTHBSplineBasis.hpp:2094
unsigned numTruncated() const
Returns the number of truncated basis functions.
Definition: gsTHBSplineBasis.h:374
void transferbyLvl(std::vector< gsSparseMatrix< T > > &result)
returns transfer matrices betweend the levels of the given hierarchical spline
Definition: gsTHBSplineBasis.hpp:2311
Container class for a set of geometry patches and their topology, that is, the interface connections ...
Definition: gsMultiPatch.h:33
Struct which represents a certain side of a box.
Definition: gsBoundary.h:84
GISMO_MAKE_GEOMETRY_NEW void getBsplinePatchGlobal(gsVector< index_t > b1, gsVector< index_t > b2, unsigned level, const gsMatrix< T > &geom_coef, gsMatrix< T > &cp, gsKnotVector< T > &k1, gsKnotVector< T > &k2) const
Returns the B-spline representation of a THB-spline subpatch.
Definition: gsTHBSplineBasis.hpp:2085
virtual void update_structure()
Updates the basis structure (eg. charact. matrices, etc), to be called after any modifications.
Definition: gsHTensorBasis.hpp:1308
virtual short_t dim() const
Returns the dimension of the parameter space.
Definition: gsHTensorBasis.h:431
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 points u into result.
Definition: gsTHBSplineBasis.hpp:1593
gsTHBSplineBasis(gsBasis< T > const &tbasis, bool manualLevels=false)
Constructor out of a tensor BSpline Basis.
Definition: gsTHBSplineBasis.h:106
hdomain_type m_tree
The tree structure of the index space.
Definition: gsHTensorBasis.h:380
index_t levelOf(index_t i) const
Returns the level of the function indexed i (in continued indices)
Definition: gsHTensorBasis.h:817
void getBsplinePatches_trimming(const gsMatrix< T > &geom_coef, gsMatrix< T > &cp, gsMatrix< index_t > &b1, gsMatrix< index_t > &b2, gsVector< index_t > &level, gsMatrix< index_t > &nvertices, std::vector< std::vector< std::vector< std::vector< T > > > > &trim_curves) const
Return the list of B-spline patches to represent a THB-spline geometry.
Definition: gsTHBSplineBasis.hpp:717
gsMultiPatch< T > getBsplinePatchesToMultiPatch(const gsMatrix< T > &geom_coef) const
Return a multipatch structure of B-splines.
Definition: gsTHBSplineBasis.hpp:579
#define GISMO_ERROR(message)
Definition: gsDebug.h:118
Class for representing a knot vector.
Definition: gsKnotVector.h:79
gsMatrix< index_t > boundaryOffset(boxSide const &s, index_t offset) const
Definition: gsTHBSplineBasis.hpp:32
gsSparseMatrix< T > coarsening(const std::vector< gsSortedVector< index_t > > &old, const std::vector< gsSortedVector< index_t > > &n, const gsSparseMatrix< T, RowMajor > &transfer) const
returns a transfer matrix using the characteristic matrix of the old and new basis ...
Definition: gsTHBSplineBasis.hpp:2356
void transfer(const std::vector< gsSortedVector< index_t > > &old, gsSparseMatrix< T > &result)
Returns transfer matrix between the hirarchical spline given by the characteristic matrix &quot;old&quot; and t...
Definition: gsHTensorBasis.hpp:1735
void representBasis()
Computes and saves representation of all basis functions.
Definition: gsTHBSplineBasis.hpp:96
Truncated hierarchical B-spline basis.
Definition: gsTHBSplineBasis.h:35
bool isFirstBoxCompletelyInsideSecond(const std::vector< index_t > &firstBox, const std::vector< index_t > &secondBox) const
Checks if the first box is completely inside second box.
Definition: gsTHBSplineBasis.h:660
Sparse vector class, based on gsEigen::SparseVector.
Definition: gsSparseVector.h:34
BoundaryBasisType::uPtr boundaryBasis(boxSide const &s)
Gives back the boundary basis at boxSide s.
void active_into(const gsMatrix< T > &u, gsMatrix< index_t > &result) const
Returns the indices of active basis functions at points u, as a list of indices, in result...
Definition: gsTHBSplineBasis.hpp:1417
A basis represents a family of scalar basis functions defined over a common parameter domain...
Definition: gsBasis.h:78
std::ostream & print(std::ostream &os) const
Prints the object as a string.
Definition: gsTHBSplineBasis.h:516