G+Smo  24.08.0
Geometry + Simulation Modules
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
gsDomainIterator.h
Go to the documentation of this file.
1 
14 #pragma once
15 
16 //#include <gsCore/gsBasis.h> // todo: remove
17 #include <gsCore/gsDomain.h>
18 #include <gsCore/gsBoundary.h>
19 
20 namespace gismo
21 {
22 
66 template <class T>
68 {
69 public:
71  typedef memory::shared_ptr< gsDomainIterator > Ptr;
73  typedef memory::unique_ptr< gsDomainIterator > uPtr;
74 
75 public:
76 
77  gsDomainIterator( ) : m_basis(NULL), m_isGood( true ) { }
78 
80  gsDomainIterator( const gsBasis<T>& basisParam, const boxSide & s = boundary::none)
81  : center( gsVector<T>::Zero(basisParam.dim()) ), m_basis( &basisParam ),
82  m_isGood( true ), m_side(s)
83  { }
84 
85  virtual ~gsDomainIterator() { }
86 
87 public:
88 
95  virtual bool next() = 0;
96 
98  virtual bool next(index_t increment) = 0;
99 
101  virtual void reset()
102  {
104  }
105 
106 public:
107 
109  size_t id() const { return m_id; }
110 
112  bool good() const { return m_isGood; }
113 
115  short_t dim() const { return center.size(); }
116 
119  virtual void adjacent( const gsVector<bool> & ,
120  gsDomainIterator & )
121  {
123  }
124 
131  const gsVector<T>& centerPoint () const
132  { return center; }
133 
140  virtual const gsVector<T>& lowerCorner() const
141  {
143  }
144 
151  virtual const gsVector<T>& upperCorner() const
152  {
154  }
155 
160  virtual const T getPerpendicularCellSize() const
161  {
163  }
164 
165  virtual bool isBoundaryElement() const
166  {
168  }
169 
171  T getCellSize() const
172  {
173  return (upperCorner() - lowerCorner()).norm();
174  }
175 
178  {
179  return (upperCorner() - lowerCorner()).minCoeff();
180  }
181 
184  {
185  return (upperCorner() - lowerCorner()).maxCoeff();
186  }
187 
189  T volume() const
190  { return (upperCorner() - lowerCorner()).prod(); }
191 
193  virtual size_t numElements() const
194  {
195  //\todo Remove this implementation. Probably using a shallow
196  //copy, "reset" and "next" would do this better.
197 
198  // Buggy, and probably a terrible implementation,
199  // but needed and therefore can be useful
200  // sometimes.
201  typename gsBasis<T>::domainIter domIter = m_basis->makeDomainIterator(m_side);
202 
203  size_t numEl = 0;
204  for (; domIter->good(); domIter->next(), numEl++){}
205 
206  return numEl;
207  }
208 
209 
210  inline boxSide side() const {return m_side;}
211 
212 public:
213 
216 
217 protected:
220 
223  bool m_isGood;
224 
225  boxSide m_side;
226 
227  size_t m_id;
228 
229 private:
230  // disable copying
232  gsDomainIterator& operator= ( const gsDomainIterator& );
233 }; // class gsDomainIterator
234 
235 
237 //template<class T>
238 //std::ostream &operator<<(std::ostream &os, const gsDomainIterator<T>& b)
239 //{return b.print(os); }
240 
241 
242 } // namespace gismo
virtual bool next()=0
Proceeds to the next element.
Abstracgt Base class representing a domain. i.e. a collection of elements (triangles, rectangles, cubes, simplices.
#define GISMO_NO_IMPLEMENTATION
Definition: gsDebug.h:129
size_t id() const
Returns the element id.
Definition: gsDomainIterator.h:109
T getCellSize() const
Return the diagonal of the element.
Definition: gsDomainIterator.h:171
#define short_t
Definition: gsConfig.h:35
Provides structs and classes related to interfaces and boundaries.
gsDomainIterator(const gsBasis< T > &basisParam, const boxSide &s=boundary::none)
Constructor using a basis.
Definition: gsDomainIterator.h:80
short_t dim() const
Return dimension of the elements.
Definition: gsDomainIterator.h:115
virtual const T getPerpendicularCellSize() const
Returns the perpendicular cell size of boundary iterator.
Definition: gsDomainIterator.h:160
virtual const gsVector< T > & upperCorner() const
Returns the upper corner of the current element.
Definition: gsDomainIterator.h:151
memory::shared_ptr< gsDomainIterator > Ptr
Shared pointer for gsDomainIterator.
Definition: gsDomainIterator.h:71
bool good() const
Is the iterator still pointing to a valid element?
Definition: gsDomainIterator.h:112
#define index_t
Definition: gsConfig.h:32
T getMaxCellLength() const
Return the length of the largest edge of the element.
Definition: gsDomainIterator.h:183
T volume() const
Return the volume of the element.
Definition: gsDomainIterator.h:189
memory::unique_ptr< gsDomainIterator > uPtr
Unique pointer for gsDomainIterator.
Definition: gsDomainIterator.h:73
virtual void adjacent(const gsVector< bool > &, gsDomainIterator &)
Definition: gsDomainIterator.h:119
A vector with arbitrary coefficient type and fixed or dynamic size.
Definition: gsVector.h:35
T getMinCellLength() const
Return the length of the smallest edge of the element.
Definition: gsDomainIterator.h:177
Class which enables iteration over all elements of a parameter domain.
Definition: gsDomainIterator.h:67
virtual const gsVector< T > & lowerCorner() const
Returns the lower corner of the current element.
Definition: gsDomainIterator.h:140
Struct which represents a certain side of a box.
Definition: gsBoundary.h:84
bool m_isGood
Definition: gsDomainIterator.h:223
const gsBasis< T > * m_basis
The basis on which the domain iterator is defined.
Definition: gsDomainIterator.h:219
gsVector< T > center
Coordinates of a central point in the element (in the parameter domain).
Definition: gsDomainIterator.h:215
const gsVector< T > & centerPoint() const
Returns the center of the current element.
Definition: gsDomainIterator.h:131
virtual size_t numElements() const
Returns the number of elements.
Definition: gsDomainIterator.h:193
A basis represents a family of scalar basis functions defined over a common parameter domain...
Definition: gsBasis.h:78
virtual void reset()
Resets the iterator so that it points to the first element.
Definition: gsDomainIterator.h:101