G+Smo  24.08.0
Geometry + Simulation Modules
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
gsTensorDomainBoundaryIterator.h
Go to the documentation of this file.
1 
14 #pragma once
15 
17 
19 
21 
22 namespace gismo
23 {
24 
32 // Class which enables iteration over all elements of a tensor product parameter domain
33 // Documentation in gsDomainIterator.h
34 
35 template<class T, int D, typename uiter>
36 //template<class T, int D=Dynamic, typename uiter = typename gsKnotVector<T>::const_uiterator>
38 {
39 public:
40 
42  : gsDomainIterator<T>(b, s),
43  d( m_basis->dim() ),
44  lower ( gsVector<T, D>::Zero(d) ),
45  upper ( gsVector<T, D>::Zero(d) )
46  {
48  par = s.parameter();
49  dir = s.direction();
50  meshBegin.resize(d);
51  meshEnd.resize(d);
52  curElement.resize(d);
53  breaks.reserve(d);
54 
55  for (int i=0; i < dir; ++i)
56  {
57  breaks.push_back( m_basis->component(i).domain()->breaks() );
58  meshEnd[i] = breaks[i].end() - 1;
59  meshBegin[i] = curElement[i] = breaks[i].begin();
60  //meshEnd[i] = m_basis->component(i).domain()->uend() - 1;
61  //meshBegin[i] =
62  //curElement[i] = m_basis->component(i).knots().ubegin();
63 
64  if (meshEnd[i] == curElement[i])
65  m_isGood = false;
66  }
67 
68  // Fixed direction
69  breaks.push_back( m_basis->component(dir).domain()->breaks() );
70 
71  meshEnd[dir] = ( par ? breaks[dir].end() - 1 : breaks[dir].begin() + 1 );
72  curElement[dir] =
73  meshBegin[dir] = ( par ? breaks[dir].end() - 2 : breaks[dir].begin() );
74  tindex = curElement[dir] - breaks[dir].begin();
75  //meshEnd[dir] = ( par ? m_basis->component(dir).knots().uend() - 1 :
76  // m_basis->component(dir).knots().ubegin() + 1 );
77  //curElement[dir] =
78  //meshBegin[dir] = ( par ?
79  // m_basis->component(dir).knots().uend() - 2 :
80  // m_basis->component(dir).knots().ubegin() );
81  //tindex = curElement[dir] - m_basis->component(i).knots().ubegin();
82 
83  for (int i=dir+1; i < d; ++i)
84  {
85  breaks.push_back( m_basis->component(i).domain()->breaks() );
86  meshEnd[i] = breaks[i].end() - 1;
87  meshBegin[i] = curElement[i] = breaks[i].begin();
88  //meshEnd[i] = m_basis->component(i).knots().uend() - 1;
89  //meshBegin[i] =
90  //curElement[i] = m_basis->component(i).knots().ubegin();
91 
92  if (meshEnd[i] == curElement[i])
93  m_isGood = false;
94  }
95 
96  // Set to one quadrature point by default
97  m_quadrature.setNodes( gsVector<index_t>::Ones(d) );
98 
99  if (m_isGood)
100  update();
101  }
102 
103  // ---> Documentation in gsDomainIterator.h
104  // proceed to the next element; returns true if end not reached yet
105  bool next()
106  {
107  m_isGood = m_isGood && nextLexicographic(curElement, meshBegin, meshEnd);
108  if (m_isGood)
109  update();
110  return m_isGood;
111  }
112 
113  // ---> Documentation in gsDomainIterator.h
114  // proceed to the next element (skipping #increment elements);
115  // returns true if end not reached yet
116  bool next(index_t increment)
117  {
118  for (index_t i = 0; i < increment; i++)
119  m_isGood = m_isGood && nextLexicographic(curElement, meshBegin, meshEnd);
120  if (m_isGood)
121  update();
122  return m_isGood;
123  }
124 
128  void reset()
129  {
130  curElement=meshBegin;
131  m_isGood = true;
132  for(int i=0; i < d; ++i)
133  {
134  if (i!=dir && curElement[i]==meshEnd[i])
135  m_isGood=false;
136  }
137  if (m_isGood)
138  update();
139  }
140 
143  {
144  gsVector<unsigned, D> curr_index(d);
145  for (int i = 0; i < dir; ++i)
146  curr_index[i] = curElement[i] - meshBegin[i];
147  for (int i = dir+1; i < d; ++i)
148  curr_index[i] = curElement[i] - meshBegin[i];
149  curr_index[dir] = tindex;
150  return curr_index;
151  }
152 
153  const gsVector<T> & lowerCorner() const
154  { return lower; }
155 
156  const gsVector<T> & upperCorner() const
157  { return upper; }
158 
159  const T getPerpendicularCellSize() const
160  {
161  return *(curElement[dir]+1) - *curElement[dir];
162  }
163 
165  size_t numElements() const
166  {
167  size_t result = 1;
168  for (short_t i = 0; i < dir; ++i)
169  result *= breaks[i].size() - 1;
170  for (short_t i = dir+1; i < d; ++i)
171  result *= breaks[i].size() - 1;
172 
173  return result;
174  }
175 
176  void adjacent( const gsVector<bool> & orient,
177  gsDomainIterator<T> & other )
178  {
179  // 2D only for now
180 
182  static_cast< gsTensorDomainBoundaryIterator &>(other);
183 
184  int a1 = !dir;
185  int a2 = !other_.dir;
186 
187  other_.curElement[a2] = std::lower_bound(
188  other_.breaks[a2].begin(), other_.breaks[a2].end(),
189  orient[0] ? *curElement[a1] : *(curElement[a1]+1) );
190  other_.update();
191  }
192 
194  void setBreaks(std::vector<T> newBreaks, index_t i) // i: direction
195  {
196  breaks[i].swap(newBreaks);
197  meshEnd[i] = breaks[i].end() - 1;
198  meshBegin[i] = curElement[i] = breaks[i].begin();
199  reset();
200  }
201 
202 private:
203 
207  void update()
208  {
209  for (int i = 0; i < dir ; ++i)
210  {
211  lower[i] = *curElement[i];
212  upper[i] = *(curElement[i]+1);
213  center[i] = (T)(0.5) * (lower[i] + upper[i]);
214  }
215  lower[dir] =
216  upper[dir] =
217  center[dir] = (par ? *(curElement[dir]+1) : *curElement[dir] );
218  for (int i = dir+1; i < d; ++i)
219  {
220  lower[i] = *curElement[i];
221  upper[i] = *(curElement[i]+1);
222  center[i] = (T)(0.5) * (lower[i] + upper[i]);
223  }
224 
225  //gsDebug<<"lower: "<< lower.transpose() <<", upper="<<upper.transpose() <<"\n";
226  }
227 
228 // Data members
229 protected:
234 
235 private:
236 
237  // the dimension of the parameter space
238  short_t d;
239 
240  // Boundary parameters
241  short_t dir;
242  bool par;
243  unsigned tindex;
244 
245  // coordinates of the grid cell boundaries
246  std::vector< std::vector<T> > breaks;
247 
248  // Quadrature rule
249  gsGaussRule<T> m_quadrature;
250 
251  // First mesh-line on the tensor grid
252  gsVector<uiter, D> meshBegin;
253 
254  // Last mesh-line on the tensor grid
255  gsVector<uiter, D> meshEnd;
256 
257  // Current element as pointers to it's supporting mesh-lines
258  gsVector<uiter, D> curElement;
259 
260  // parameter coordinates of current grid cell
261  gsVector<T> lower, upper;
262 
263 public:
264 # define Eigen gsEigen
265  EIGEN_MAKE_ALIGNED_OPERATOR_NEW
266 # undef Eigen
267 }; // class gsTensorDomainBoundaryIterator
268 
269 
270 } // namespace gismo
Provides the Gauss-Legendre quadrature rule.
void reset()
Definition: gsTensorDomainBoundaryIterator.h:128
gsVector< unsigned, D > index() const
Return the tensor index of the current element.
Definition: gsTensorDomainBoundaryIterator.h:142
#define short_t
Definition: gsConfig.h:35
bool parameter() const
Returns the parameter value (false=0=start, true=1=end) that corresponds to this side.
Definition: gsBoundary.h:128
#define index_t
Definition: gsConfig.h:32
const gsVector< T > & lowerCorner() const
Returns the lower corner of the current element.
Definition: gsTensorDomainBoundaryIterator.h:153
Provides combinatorial unitilies.
void setBreaks(std::vector< T > newBreaks, index_t i)
Function to set the breakpoints in direction i manually.
Definition: gsTensorDomainBoundaryIterator.h:194
void update()
Definition: gsTensorDomainBoundaryIterator.h:207
A vector with arbitrary coefficient type and fixed or dynamic size.
Definition: gsVector.h:35
Class which enables iteration over all elements of a parameter domain.
Definition: gsDomainIterator.h:67
const gsVector< T > & upperCorner() const
Returns the upper corner of the current element.
Definition: gsTensorDomainBoundaryIterator.h:156
Re-implements gsDomainIterator for iteration over all elements of the boundary of a tensor product pa...
Definition: gsTensorDomainBoundaryIterator.h:37
Provides declaration of DomainIterator abstract interface.
Struct which represents a certain side of a box.
Definition: gsBoundary.h:84
bool m_isGood
Definition: gsDomainIterator.h:223
bool nextLexicographic(Vec &cur, const Vec &size)
Iterates through a tensor lattice with the given size. Updates cur and returns true if another entry ...
Definition: gsCombinatorics.h:196
const T getPerpendicularCellSize() const
Returns the perpendicular cell size of boundary iterator.
Definition: gsTensorDomainBoundaryIterator.h:159
const gsBasis< T > * m_basis
The basis on which the domain iterator is defined.
Definition: gsDomainIterator.h:219
bool next()
Proceeds to the next element.
Definition: gsTensorDomainBoundaryIterator.h:105
gsVector< T > center
Coordinates of a central point in the element (in the parameter domain).
Definition: gsDomainIterator.h:215
Class that represents the (tensor) Gauss-Legendre quadrature rule.
Definition: gsGaussRule.h:27
short_t direction() const
Returns the parametric direction orthogonal to this side.
Definition: gsBoundary.h:113
size_t numElements() const
Returns the number of elements.
Definition: gsTensorDomainBoundaryIterator.h:165
A basis represents a family of scalar basis functions defined over a common parameter domain...
Definition: gsBasis.h:78
bool next(index_t increment)
Proceeds to the next element (skipping increment elements).
Definition: gsTensorDomainBoundaryIterator.h:116