G+Smo  24.08.0
Geometry + Simulation Modules
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
gsIOUtils.h
Go to the documentation of this file.
1 
14 #pragma once
15 
16 #include <gsCore/gsDebug.h>
19 #include <gsIO/gsBase64.h>
20 
21 namespace gismo {
22 
28 template<class T>
29 void makeMesh(const gsBasis<T>& basis, gsMesh<T> & mesh, int n = 0)
30 {
31  const unsigned d = basis.dim();
32 
33  typedef typename gsMesh<T>::VertexHandle Vertex;
34  typename gsBasis<T>::domainIter domIter = basis.makeDomainIterator();
35 
36  // variables for iterating over a cube (element is a cube)
40 
41  // maps integer representation of a vertex into pointer to the
42  // vertex coordinates
43  std::vector<Vertex> map(1ULL<<d);
44 
45  // neighbour[i] are integer representations of certain neighbours of
46  // vertex i (i counts in lexicographics order over all vertices)
47  std::vector<std::vector<unsigned> > neighbour(1ULL<<d,
48  std::vector<unsigned>() );
49 
50  cur.setZero(d);
51  int counter = 0;
52  do
53  {
54  // set neighbour
55  for (unsigned dim = 0; dim < d; dim++)
56  {
57  if (cur(dim) == 0)
58  {
59  const unsigned tmp = counter | (1<< dim) ;
60  neighbour[counter].push_back(tmp);
61  }
62  }
63  counter++;
64 
65  } while (nextCubePoint<gsVector<unsigned> >(cur, zeros, ones));
66 
67  gsVector<T> vertex(d);
68 
69  for (; domIter->good(); domIter->next())
70  {
71  const gsVector<T>& low = domIter->lowerCorner();
72  const gsVector<T>& upp = domIter->upperCorner();
73  const T vol = domIter->volume();
74 
75  vertex.setZero();
76  cur.setZero();
77  counter = 0;
78 
79  // add points to the mesh
80  do
81  {
82  // get appropriate coordinate of a point
83  for (unsigned dim = 0; dim < d; dim++)
84  {
85  vertex(dim) = ( cur(dim) ? upp(dim) : low(dim) );
86  }
87 
88  Vertex v = mesh.addVertex(vertex);
89  v->data = vol;
90  map[counter++] = v;
91 
92  } while (nextCubePoint<gsVector<unsigned> >(cur, zeros, ones));
93 
94 
95  // add edges to the mesh (connect points)
96  for (size_t index = 0; index != neighbour.size(); index++)
97  {
98  const std::vector<unsigned> & v = neighbour[index];
99 
100  for (size_t ngh = 0; ngh != v.size(); ngh++)
101  {
102  // add more vertices (n) for better physical resolution
103  mesh.addLine( map[index], map[v[ngh]], n );
104  //mesh.addEdge( map[index], map[v[ngh]] );
105  }
106  }
107 
108  // idea: instead of edges add the faces to the mesh
109  // mesh->addFace( mesh.vertices().back(),
110  // *(mesh.vertices().end()-3),
111  // *(mesh.vertices.end()-4),
112  // *(mesh.vertices.end()-2)
113  // );
114 
115  }
116 }
117 
118 namespace internal
119 {
120 
122 template <short_t d, typename T>
124  std::vector<gsMesh<T> >& meshes,
125  int n = 0)
126 {
127  // prepare meshes
128  meshes.clear();
129  for (unsigned i = 0; i < basis.maxLevel() + 1; i++)
130  {
131  meshes.push_back(gsMesh<T>());
132  }
133 
134  // variables for iterating over a cube (element is a cube)
137  gsVector<unsigned> cur;
138 
139  // neighbour[i] are integer representations of certain neighbours of
140  // vertex i (i counts in lexicographics order over all vertices)
141  std::vector<std::vector<unsigned> > neighbour(1 << d,
142  std::vector<unsigned>() );
143 
144 
145  cur.setZero(d);
146  int counter = 0;
147  do
148  {
149  // set neighbour
150  for (unsigned dim = 0; dim < d; dim++)
151  {
152  if (cur(dim) == 0)
153  {
154  const unsigned tmp = counter | (1<< dim) ;
155  neighbour[counter].push_back(tmp);
156  }
157  }
158  counter++;
159 
160  } while (nextCubePoint<gsVector<unsigned> >(cur, zeros, ones));
161 
162 
163  // maps integer representation of a vertex into pointer to the
164  // vertex coordinates
165  typedef typename gsMesh<T>::VertexHandle Vertex;
166  std::vector<Vertex> map(1 << d);
167 
168  gsVector<T> vertex(d);
169 
170  gsHDomainIterator<T, d> domIter(basis);
171 
172  for (; domIter.good(); domIter.next())
173  {
174 
175  int level = domIter.getLevel();
176 
177  const gsVector<T>& low = domIter.lowerCorner();
178  const gsVector<T>& upp = domIter.upperCorner();
179 
180 
181  vertex.setZero();
182  cur.setZero();
183  counter = 0;
184 
185  // add points to the mesh
186  do
187  {
188  // get appropriate coordinate of a point
189  for (unsigned dim = 0; dim < d; dim++)
190  {
191  vertex(dim) = ( cur(dim) ? upp(dim) : low(dim) );
192  }
193 
194  meshes[level].addVertex(vertex);
195  map[counter++] = meshes[level].vertices().back();
196 
197  } while (nextCubePoint<gsVector<unsigned> >(cur, zeros, ones));
198 
199 
200  // add edges to the mesh (connect points)
201  for (size_t index = 0; index != neighbour.size(); index++)
202  {
203  const std::vector<unsigned> & v = neighbour[index];
204 
205  for (size_t ngh = 0; ngh != v.size(); ngh++)
206  {
207  // add more vertices (n) for better physical resolution
208  meshes[level].addLine( map[index], map[v[ngh]], n );
209  }
210  }
211  }
212 }
213 
214 } // end namespace internal
215 
216 
217 
226 template <typename T>
228  std::vector<gsMesh<T> >& meshes,
229  int n = 0)
230 {
231 
232  const gsHTensorBasis<1, T>* hBasis1 =
233  dynamic_cast<const gsHTensorBasis<1, T>* >(&basis);
234 
235  if (hBasis1 != NULL)
236  {
237  internal::makeHierarchicalMesh<1, T>(*hBasis1, meshes, n);
238  return true;
239  }
240 
241 
242  const gsHTensorBasis<2, T>* hBasis2 =
243  dynamic_cast<const gsHTensorBasis<2, T>* >(&basis);
244 
245  if (hBasis2 != NULL)
246  {
247  internal::makeHierarchicalMesh<2, T>(*hBasis2, meshes, n);
248  return true;
249  }
250 
251 
252  const gsHTensorBasis<3, T>* hBasis3 =
253  dynamic_cast<const gsHTensorBasis<3, T>* >(&basis);
254 
255  if (hBasis3 != NULL)
256  {
257  internal::makeHierarchicalMesh<3, T>(*hBasis3, meshes, n);
258  return true;
259  }
260 
261  return false;
262 }
263 
264 } // namespace gismo
Re-implements gsDomainIterator for iteration over all boundary elements of a hierarchical parameter d...
Definition: gsHDomain.h:24
Provides definition of HTensorBasis abstract interface.
Provides declaration of iterator of hierarchical domain.
bool nextCubePoint(Vec &cur, const Vec &end)
Iterate in lexigographic order through the points of the integer lattice contained in the cube [0...
Definition: gsCombinatorics.h:327
void makeMesh(const gsBasis< T > &basis, gsMesh< T > &mesh, int n=0)
Returns the computational mesh of basis.
Definition: gsIOUtils.h:29
bool good() const
Is the iterator still pointing to a valid element?
Definition: gsDomainIterator.h:112
This file contains the debugging and messaging system of G+Smo.
bool makeHierarchicalMesh(const gsBasis< T > &basis, std::vector< gsMesh< T > > &meshes, int n=0)
Definition: gsIOUtils.h:227
Class Representing a triangle mesh with 3D vertices.
Definition: gsMesh.h:31
Class representing a (scalar) hierarchical tensor basis of functions .
Definition: gsHTensorBasis.h:74
void addLine(gsMatrix< T > const &points)
Definition: gsMesh.hpp:329
const gsVector< T > & upperCorner() const
Returns the upper corner of the current element.
Definition: gsHDomainIterator.h:122
unsigned maxLevel() const
Returns the level in which the indices are stored internally.
Definition: gsHTensorBasis.h:811
void makeHierarchicalMesh(const gsHTensorBasis< d, T > &basis, std::vector< gsMesh< T > > &meshes, int n=0)
Look at function gismo::makeHierarchicalMesh.
Definition: gsIOUtils.h:123
virtual domainIter makeDomainIterator() const
Create a domain iterator for the computational mesh of this basis, that points to the first element o...
Definition: gsBasis.hpp:493
A basis represents a family of scalar basis functions defined over a common parameter domain...
Definition: gsBasis.h:78
bool next()
Proceeds to the next element.
Definition: gsHDomainIterator.h:75
const gsVector< T > & lowerCorner() const
Returns the lower corner of the current element.
Definition: gsHDomainIterator.h:120
gsVertex class that represents a 3D vertex for a gsMesh.
Definition: gsVertex.h:26