G+Smo  24.08.0
Geometry + Simulation Modules
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
gsHBox.h
Go to the documentation of this file.
1 
14 #pragma once
15 
16 #include <gsIO/gsXml.h>
17 #include <gsCore/gsLinearAlgebra.h> // due to EIGEN_MAKE_ALIGNED_OPERATOR_NEW
20 #include <gsHSplines/gsHBoxUtils.h>
21 
22 namespace gismo
23 {
24 
25 // forward declaration to move includes into the .hpp-file
26 template<short_t d, class Z>
27 struct gsAABB;
28 
53 template<int d, class T>
54 class gsHBox
55 {
56 public:
57 # define Eigen gsEigen
58  EIGEN_MAKE_ALIGNED_OPERATOR_NEW
59 # undef Eigen
60 
61 public:
62  typedef gsVector<index_t,d> point;
63  typedef typename gsEigen::aligned_allocator<gsHBox<d,T>> aalloc;
64 
65  typedef typename std::vector<index_t> RefBox;
66  typedef typename std::list<gsHBox<d,T>,typename gsHBox<d,T>::aalloc> Container;
67  typedef typename std::vector<gsHBox<d,T>,typename gsHBox<d,T>::aalloc> SortedContainer;
68  typedef typename std::vector<Container> HContainer; // container[level]
69  typedef typename Container::iterator Iterator;
70  typedef typename Container::reverse_iterator rIterator;
71  typedef typename Container::const_iterator cIterator;
72  typedef typename HContainer::iterator HIterator;
73  typedef typename HContainer::reverse_iterator rHIterator;
74  typedef typename HContainer::const_iterator cHIterator;
75 
77  typedef memory::shared_ptr< gsHBox > Ptr;
78 
80  typedef memory::unique_ptr< gsHBox > uPtr;
81 
82 public:
83 
85  gsHBox();
86 
92  gsHBox(const gsHDomainIterator<T,d> * domHIt);
93 
100  gsHBox(const gsHDomainIterator<T,d> * domHIt, const index_t pid);
101 
111  gsHBox(const typename gsHBox<d,T>::point & low,const typename gsHBox<d,T>::point & upp, index_t level, const gsHTensorBasis<d,T> * basis, const index_t pid = -1);
112 
120  gsHBox(const gsAABB<d, index_t> & box, const gsHTensorBasis<d,T> * basis, const index_t pid = -1);
121 
129  gsHBox(const std::vector<index_t> & indices, const gsHTensorBasis<d,T> * basis, const index_t pid = -1);
130 
132  gsHBox( const gsHBox<d,T> & other );
133 
135  gsHBox( gsHBox<d,T> && other );
136 
138  gsHBox<d,T> & operator= ( const gsHBox<d,T> & other );
139 
141  gsHBox<d,T> & operator= ( gsHBox<d,T> && other );
142 
150  bool isContained(const gsHBox<d,T> & other) const;
151 
159  bool contains(const gsHBox<d,T> & other) const;
160 
168  bool isSame(const gsHBox<d,T> & other) const;
169 
175  bool isActive() const;
176 
183  bool isActiveOrContained() const;
184 
190  const gsMatrix<T> & getCoordinates() const;
191 
197  const gsMatrix<T> & getCenter() const;
198 
204  gsVector<T,d> lowerCorner() const;
205 
211  gsVector<T,d> upperCorner() const;
212 
214  T getCellSize() const;
215 
217  T getMinCellLength() const;
218 
220  T getMaxCellLength() const;
221 
227  const point & lowerIndex() const;
233  const point & upperIndex() const;
234 
240  index_t patch() const;
241 
247  index_t level() const;
248 
254  index_t levelInCenter() const;
255 
259  void setError(T error);
260 
264  void setAndProjectError(T error, index_t alpha=2, index_t beta=0);
265 
271  T error() const;
272 
278  T projectedErrorRef() const;
279 
287  T projectedErrorCrs() const;
288 
289 
295  T projectedImprovement() const;
296 
302  T projectedSetBack() const;
303 
304 
308  void setIndex(index_t index);
309 
315  index_t index() const;
316 
320  void mark();
324  void unmark();
325 
331  bool marked() const;
332 
338  void setMark(bool mark);
339 
345  gsHBox<d,T> getParent() const;
346 
355 
361  Container getChildren() const;
362 
370  Container getDescendants(index_t k) const;
371 
375  Container getSiblings() const;
376 
382  Container getSupportExtension();
383 
392 
400  Container getHneighborhood(index_t m);
401 
409  Container getTneighborhood(index_t m);
410 
411 
421  template<gsHNeighborhood _mode>
422  typename gsHBox<d,T>::Container getNeighborhood(index_t m) { return getNeighborhood_impl<_mode>(m);}
423 
424 
433  Container getNeighborhood(index_t m);
434 
442  Container getCneighborhood(index_t m);
443 
452  Container getCextension(index_t m);
453 
459  Container toContainer();
460 
466  HContainer toHContainer();
467 
472  std::ostream& print( std::ostream& os ) const;
473 
479  RefBox toBox() const;
480 
486  RefBox toRefBox(index_t targetLevel) const;
487  RefBox toRefBox() const
488  {
489  return this->toRefBox(this->level()+1);
490  }
491 
497  RefBox toCrsBox(index_t targetLevel) const;
498  RefBox toCrsBox() const
499  {
500  return this->toCrsBox(this->level()-1);
501  }
502 
503  // Helper functions
504  HContainer boxUnion(const HContainer & container1, const HContainer & container2) const;
505 
506  const gsHTensorBasis<d,T> & basis() const { return *m_basis; }
507  void setBasis(const gsHTensorBasis<d,T> * basis) { m_basis = basis; }
508 
514  Container toUnitBoxes() const;
515 
521  bool good() const;
522 
528  void clean(Container & container) const;
529 
533  void computeCoordinates() const;
537  void computeCenter() const;
538 
539 protected:
540 
541  void _computeIndices();
542  gsAABB<d, index_t> _computeIndices(const gsMatrix<T> & coords, index_t level);
543  gsAABB<d, index_t> _computeIndices(const gsMatrix<T> & coords, const gsMatrix<T> & center);
544  gsAABB<d, index_t> _computeIndices(const gsMatrix<T> & coords);
545 
546  gsAABB<d, index_t> _elevateBox(const gsAABB<d, index_t> & box) const;
547  gsAABB<d, index_t> _lowerBox(const gsAABB<d, index_t> & box) const;
548 
549  Container _getParents(typename gsHBox<d,T>::Container & container) const;
550  HContainer _getParents(typename gsHBox<d,T>::HContainer & container) const;
551 
552 
553  Container _boxUnion(const Container & container1, const Container & container2) const;
554  Container _makeUnique(const Container & container) const;
555 
556  template<gsHNeighborhood _mode>
557  typename std::enable_if<_mode==gsHNeighborhood::Automatic, typename gsHBox<d,T>::Container>::type
558  getNeighborhood_impl(index_t m)
559  {
560  if (dynamic_cast<const gsTHBSplineBasis<d,T>*>(this->basis()))
561  return this->getTneighborhood(m);
562  else if (dynamic_cast<const gsHBSplineBasis<d,T>*>(this->basis()))
563  return this->getHneighborhood(m);
564  }
565 
566  template<gsHNeighborhood _mode>
567  typename std::enable_if<_mode==gsHNeighborhood::T, typename gsHBox<d,T>::Container>::type
568  getNeighborhood_impl(index_t m)
569  {
570  return this->getTneighborhood(m);
571  }
572 
573  template<gsHNeighborhood _mode>
574  typename std::enable_if<_mode==gsHNeighborhood::H, typename gsHBox<d,T>::Container>::type
575  getNeighborhood_impl(index_t m)
576  {
577  return this->getHneighborhood(m);
578  }
579 
580 
581 protected:
582  gsAABB<d, index_t> m_indices;
583 
584  index_t m_pid;
585  mutable gsMatrix<T> m_coords;
586  mutable gsMatrix<T> m_center;
587  const gsHTensorBasis<d,T> * m_basis;
588 
589  T m_error;
590  T m_error_ref;
591  T m_error_crs;
592  index_t m_index;
593  bool m_marked;
594 
595 }; // class gsHBox
596 
597 
598 template<int d, class T>
599 std::ostream& operator<<( std::ostream& os, const gsHBox<d,T>& b )
600 {
601  return b.print( os );
602 }
603 
604 } // namespace gismo
605 
606 // *****************************************************************
607 #ifndef GISMO_BUILD_LIB
608 #include GISMO_HPP_HEADER(gsHBox.hpp)
609 #else
610 #ifdef gsHBox_EXPORT
611 #include GISMO_HPP_HEADER(gsHBox.hpp)
612 #undef EXTERN_CLASS_TEMPLATE
613 #define EXTERN_CLASS_TEMPLATE CLASS_TEMPLATE_INST
614 #endif
615 namespace gismo
616 {
617 EXTERN_CLASS_TEMPLATE gsHBox<1,real_t>;
618 EXTERN_CLASS_TEMPLATE gsHBox<2,real_t>;
619 EXTERN_CLASS_TEMPLATE gsHBox<3,real_t>;
620 EXTERN_CLASS_TEMPLATE gsHBox<4,real_t>;
621 
622 EXTERN_CLASS_TEMPLATE internal::gsXml< gsHBox<1,real_t> >;
623 EXTERN_CLASS_TEMPLATE internal::gsXml< gsHBox<2,real_t> >;
624 EXTERN_CLASS_TEMPLATE internal::gsXml< gsHBox<3,real_t> >;
625 EXTERN_CLASS_TEMPLATE internal::gsXml< gsHBox<4,real_t> >;
626 
627 }
628 #endif
629 // *****************************************************************
Re-implements gsDomainIterator for iteration over all boundary elements of a hierarchical parameter d...
Definition: gsHDomain.h:24
const point & upperIndex() const
Gets the upper index of the box.
Definition: gsHBox.hpp:281
Provides definition of HTensorBasis abstract interface.
bool isContained(const gsHBox< d, T > &other) const
Checks if the other cell is contained in this cell.
Definition: gsHBox.hpp:167
T projectedErrorRef() const
The error contribution of *this when it is refined.
Definition: gsHBox.hpp:307
Container getHneighborhood(index_t m)
Gets the H-neighborhood.
Definition: gsHBox.hpp:493
Provides declaration of iterator of hierarchical domain.
void clean(Container &container) const
Cleans the container from bad elements (see good())
Definition: gsHBox.hpp:948
gsVector< T, d > lowerCorner() const
Gets the lower corner of the box.
Definition: gsHBox.hpp:247
T projectedErrorCrs() const
The error contribution of *this when it is coarsened.
Definition: gsHBox.hpp:310
memory::unique_ptr< gsHBox > uPtr
Unique pointer for gsHTensorBasis.
Definition: gsHBox.h:80
Container getMultiLevelSupportExtension(index_t k)
Gets the multi-level support extension.
Definition: gsHBox.hpp:477
Provides utility functions for gsHBox and gsHBoxContainer.
void setIndex(index_t index)
Assigns an index to the object.
Definition: gsHBox.hpp:325
bool isActive() const
Determines if the box is active on its current level.
Definition: gsHBox.hpp:213
bool isSame(const gsHBox< d, T > &other) const
Determines whether the this box is the same as the other box.
Definition: gsHBox.hpp:199
Container getTneighborhood(index_t m)
Gets the T-neighborhood.
Definition: gsHBox.hpp:517
gsHBox< d, T > & operator=(const gsHBox< d, T > &other)
Assignment operator.
Definition: gsHBox.hpp:132
bool marked() const
Returns whether the element is marked or not.
Definition: gsHBox.hpp:337
void setAndProjectError(T error, index_t alpha=2, index_t beta=0)
Sets the error of the object and compute the projection of the error on a finer mesh. The projection is performed based on a theoretical rate of convergence of alpha*p+beta.
Definition: gsHBox.hpp:296
void setMark(bool mark)
Sets the mark.
Definition: gsHBox.hpp:340
This class provides a Hierarchical Box (gsHBox)
Definition: gsHBox.h:54
index_t levelInCenter() const
Gets the level in the center of the object.
Definition: gsHBox.hpp:225
RefBox toBox() const
Returns a box representation of the object.
Definition: gsHBox.hpp:776
T getMaxCellLength() const
Return the length of the largest edge of the element.
Definition: gsHBox.hpp:273
index_t level() const
Gets the level of the object.
Definition: gsHBox.hpp:287
const gsMatrix< T > & getCoordinates() const
Gets the coordinates of the box (first column lower corner, second column higher corner).
Definition: gsHBox.hpp:231
#define index_t
Definition: gsConfig.h:32
void computeCoordinates() const
Computes the parametric coordinates of this.
Definition: gsHBox.hpp:633
Container getDescendants(index_t k) const
Gets the descendants of the object on level k.
Definition: gsHBox.hpp:382
gsHBox()
Default constructor.
Definition: gsHBox.hpp:27
index_t patch() const
Gets the patch ID of the object.
Definition: gsHBox.hpp:284
Class representing a (scalar) hierarchical tensor basis of functions .
Definition: gsHTensorBasis.h:74
Container toUnitBoxes() const
Returns unit boxes representation of the object.
Definition: gsHBox.hpp:756
Container getChildren() const
Gets the children of the object.
Definition: gsHBox.hpp:374
T projectedSetBack() const
Gives the projected set-back that can be expected for this.
Definition: gsHBox.hpp:319
gsVector< T, d > upperCorner() const
Gets the upper corner of the box.
Definition: gsHBox.hpp:254
void setError(T error)
Sets the error of the object.
Definition: gsHBox.hpp:290
T projectedImprovement() const
Gives the projected improvement that can be expected for this.
Definition: gsHBox.hpp:313
T getMinCellLength() const
Return the length of the smallest edge of the element.
Definition: gsHBox.hpp:267
std::ostream & print(std::ostream &os) const
Prints the object.
Definition: gsHBox.hpp:612
gsHBox< d, T > getAncestor(index_t k) const
Gets the ancestor of the object on level k.
Definition: gsHBox.hpp:351
memory::shared_ptr< gsHBox > Ptr
Shared pointer for gsHTensorBasis.
Definition: gsHBox.h:77
index_t index() const
Gets the index stored in the object.
Definition: gsHBox.hpp:328
const gsMatrix< T > & getCenter() const
Gets the center of the box.
Definition: gsHBox.hpp:238
void computeCenter() const
Computes the center of this.
Definition: gsHBox.hpp:649
Container toContainer()
Returns a container representation of the object.
Definition: gsHBox.hpp:427
bool good() const
Checks if the box has positive indices.
Definition: gsHBox.hpp:942
Container getCextension(index_t m)
Gets the Coarsening extension, which is the coarsening neighborhood before checking for active elemen...
Definition: gsHBox.hpp:557
Container getSupportExtension()
Gets the support extension.
Definition: gsHBox.hpp:444
gsHBox< d, T > getParent() const
Gets the parent of the object.
Definition: gsHBox.hpp:343
HContainer toHContainer()
Returns a hierarchical container representation of the object.
Definition: gsHBox.hpp:435
gsHBox< d, T >::Container getNeighborhood(index_t m)
Gets the neighborhood.
Definition: gsHBox.h:422
This is the main header file that collects wrappers of Eigen for linear algebra.
T getCellSize() const
Return the diagonal of the element.
Definition: gsHBox.hpp:261
const point & lowerIndex() const
Gets the lower index of the box.
Definition: gsHBox.hpp:279
Provides declaration of input/output XML utilities struct.
void mark()
Marks this element for refinement.
Definition: gsHBox.hpp:331
void unmark()
Unmarks this element for refinement.
Definition: gsHBox.hpp:334
bool isActiveOrContained() const
Determines if active or contained in the active elemebt. In other words; checks if the level of this ...
Definition: gsHBox.hpp:219
Container getCneighborhood(index_t m)
Gets the Coarsening neighborhood.
Definition: gsHBox.hpp:591
bool contains(const gsHBox< d, T > &other) const
Checks if the other cell is contains in this cell.
Definition: gsHBox.hpp:184
T error() const
Gets the error stored in the object.
Definition: gsHBox.hpp:304