G+Smo  25.01.0
Geometry + Simulation Modules
 
Loading...
Searching...
No Matches
gsTensorDomainIterator.h
Go to the documentation of this file.
1
14#pragma once
15
17
19
21
22namespace gismo
23{
24// Documentation in gsDomainIterator.h
25// Class which enables iteration over all elements of a tensor product parameter domain
26
34template<class T, int D>
36{
37private:
38 typedef typename std::vector<T>::const_iterator uiter;
39
40public:
41
42 gsTensorDomainIterator(const std::vector< std::vector<T> > & breaks_)
43 : d( breaks_.size() ),
44 lower ( gsVector<T, D>::Zero(d) ),
45 upper ( gsVector<T, D>::Zero(d) )
46 {
48
49 // compute breaks and mesh size
50 meshStart.resize(d);
51 meshEnd.resize(d);
52 curElement.resize(d);
53 breaks = breaks_;
54 for (int i=0; i < d; ++i)
55 {
56 meshEnd[i] = breaks[i].end() - 1;
57 curElement[i] = meshStart[i] = breaks[i].begin();
58
59 if (meshEnd[i] == meshStart[i])
60 m_isGood = false;
61 }
62
63 if (m_isGood)
64 update();
65 }
66
67
68 // note: this assumes that b is a tensor product basis
69 gsTensorDomainIterator(const gsBasis<T>& b) // to do: change to gsTensorBasis
71 d( m_basis->dim() ),
72 lower ( gsVector<T, D>::Zero(d) ),
73 upper ( gsVector<T, D>::Zero(d) )
74 {
75 // compute breaks and mesh size
76 meshStart.resize(d);
77 meshEnd.resize(d);
78 curElement.resize(d);
79 breaks.reserve(d);
80 for (int i=0; i < d; ++i)
81 {
82 breaks.push_back( m_basis->component(i).domain()->breaks() );
83 // for n breaks, we have n-1 elements (spans)
84 meshEnd[i] = breaks[i].end() - 1;
85 curElement[i] = meshStart[i] = breaks[i].begin();
86
87 if (meshEnd[i] == meshStart[i])
88 m_isGood = false;
89 }
90
91 if (m_isGood)
92 update();
93 }
94
95 // Documentation in gsDomainIterator.h
96 bool next()
97 {
98 m_isGood = m_isGood && nextLexicographic(curElement, meshStart, meshEnd);
99 if (m_isGood)
100 {
101 update();
102 ++m_id; //increment id
103 }
104 return m_isGood;
105 }
106
107 // Documentation in gsDomainIterator.h
108 bool next(index_t increment)
109 {
110 for (index_t i = 0; i < increment; i++)
111 m_isGood = m_isGood && nextLexicographic(curElement, meshStart, meshEnd);
112 if (m_isGood)
113 {
114 update();
115 m_id += increment; //increment id
116 }
117 return m_isGood;
118 }
119
120 // Documentation in gsDomainIterator.h
121 void reset()
122 {
123 m_id = 0;
124 curElement = meshStart;
125 m_isGood = ( meshEnd.array() != meshStart.array() ).all() ;
126 if (m_isGood)
127 {
128 update();
129 m_id = 0;
130 }
131 }
132
135 {
136 gsVector<unsigned, D> curr_index(d);
137 for (int i = 0; i < d; ++i)
138 curr_index[i] = curElement[i] - breaks[i].begin();
139 return curr_index;
140 }
141
142 void getVertices(gsMatrix<T>& result)
143 {
144 result.resize( D, 1 << D);
145
146 gsVector<T,D> v, l, u;
147 l.setZero();
148 u.setOnes();
149 v.setZero();
150 int r = 0;
151 do {
152 for ( int i = 0; i< D; ++i)
153 result(i,r) = ( v[i] ? upper[i] : lower[i] );
154 }
155 while ( nextCubeVertex(v, l, u) );
156 }
157
158 const gsVector<T> & lowerCorner() const
159 { return lower; }
160
161 const gsVector<T> & upperCorner() const
162 { return upper; }
163
164 bool isBoundaryElement() const
165 {
166 for (int i = 0; i< D; ++i)
167 if ((lower[i]-*meshStart[i]==0) ||
168 (*meshEnd[0]-upper[0] ==0) )
169 return true;
170 return false;
171 }
172
173 index_t domainDim() const {return d;}
174
175private:
176
180 void update()
181 {
182 for (int i = 0; i < d; ++i)
183 {
184 lower[i] = *curElement[i];
185 upper[i] = *(curElement[i]+1);
186 center[i] = (T)(0.5) * (lower[i] + upper[i]);
187 }
188 }
189
190// size_t numElements() const
191// {
192//
193// }
194
195// Data members
196public:
198
199protected:
200 using gsDomainIterator<T>::m_id;
203
204private:
205 // the dimension of the parameter space
206 int d;
207
208 // coordinates of the grid cell boundaries
209 std::vector< std::vector<T> > breaks;
210
211 // Extent of the tensor grid
212 gsVector<uiter, D> meshStart, meshEnd;
213
214 // Current element as pointers to it's supporting mesh-lines
215 gsVector<uiter, D> curElement;
216
217 // parameter coordinates of current grid cell
218 gsVector<T> lower, upper;
219
220public:
221# define Eigen gsEigen
222 EIGEN_MAKE_ALIGNED_OPERATOR_NEW
223# undef Eigen
224}; // class gsTensorDomainIterator
225
226
227} // namespace gismo
A basis represents a family of scalar basis functions defined over a common parameter domain.
Definition gsBasis.h:79
Class which enables iteration over all elements of a parameter domain.
Definition gsDomainIterator.h:68
bool m_isGood
Definition gsDomainIterator.h:223
gsVector< T > center
Coordinates of a central point in the element (in the parameter domain).
Definition gsDomainIterator.h:215
const gsBasis< T > * m_basis
The basis on which the domain iterator is defined.
Definition gsDomainIterator.h:219
A matrix with arbitrary coefficient type and fixed or dynamic size.
Definition gsMatrix.h:41
Re-implements gsDomainIterator for iteration over all elements of a tensor product parameter domain....
Definition gsTensorDomainIterator.h:36
const gsVector< T > & upperCorner() const
Returns the upper corner of the current element.
Definition gsTensorDomainIterator.h:161
gsVector< unsigned, D > index() const
return the tensor index of the current element
Definition gsTensorDomainIterator.h:134
bool next(index_t increment)
Proceeds to the next element (skipping increment elements).
Definition gsTensorDomainIterator.h:108
const gsVector< T > & lowerCorner() const
Returns the lower corner of the current element.
Definition gsTensorDomainIterator.h:158
bool next()
Proceeds to the next element.
Definition gsTensorDomainIterator.h:96
void update()
Definition gsTensorDomainIterator.h:180
void reset()
Resets the iterator so that it points to the first element.
Definition gsTensorDomainIterator.h:121
A vector with arbitrary coefficient type and fixed or dynamic size.
Definition gsVector.h:37
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
bool nextCubeVertex(Vec &cur, const Vec &start, const Vec &end)
Iterate in lexicographic order through the vertices of the cube [start,end]. Updates cur with the cur...
Definition gsCombinatorics.h:252
Provides combinatorial unitilies.
#define index_t
Definition gsConfig.h:32
Provides declaration of DomainIterator abstract interface.
Provides the Gauss-Legendre quadrature rule.
The G+Smo namespace, containing all definitions for the library.