G+Smo  25.01.0
Geometry + Simulation Modules
 
Loading...
Searching...
No Matches
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
21namespace gismo {
22
28template<class T>
29void 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
118namespace internal
119{
120
122template <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)
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
226template <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
A basis represents a family of scalar basis functions defined over a common parameter domain.
Definition gsBasis.h:79
bool good() const
Is the iterator still pointing to a valid element?
Definition gsDomainIterator.h:112
Re-implements gsDomainIterator for iteration over all boundary elements of a hierarchical parameter d...
Definition gsHDomainIterator.h:39
const gsVector< T > & upperCorner() const
Returns the upper corner of the current element.
Definition gsHDomainIterator.h:122
const gsVector< T > & lowerCorner() const
Returns the lower corner of the current element.
Definition gsHDomainIterator.h:120
bool next()
Proceeds to the next element.
Definition gsHDomainIterator.h:75
Class representing a (scalar) hierarchical tensor basis of functions .
Definition gsHTensorBasis.h:75
Class Representing a triangle mesh with 3D vertices.
Definition gsMesh.h:32
void addLine(gsMatrix< T > const &points)
Definition gsMesh.hpp:329
A vector with arbitrary coefficient type and fixed or dynamic size.
Definition gsVector.h:37
gsVertex class that represents a 3D vertex for a gsMesh.
Definition gsVertex.h:27
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
This file contains the debugging and messaging system of G+Smo.
Provides declaration of iterator of hierarchical domain.
Provides definition of HTensorBasis abstract interface.
void makeHierarchicalMesh(const gsHTensorBasis< d, T > &basis, std::vector< gsMesh< T > > &meshes, int n=0)
Look at function gismo::makeHierarchicalMesh.
Definition gsIOUtils.h:123
The G+Smo namespace, containing all definitions for the library.
void makeMesh(const gsBasis< T > &basis, gsMesh< T > &mesh, int n=0)
Returns the computational mesh of basis.
Definition gsIOUtils.h:29
bool makeHierarchicalMesh(const gsBasis< T > &basis, std::vector< gsMesh< T > > &meshes, int n=0)
Definition gsIOUtils.h:227