29 dal::bit_vector res = convex_tab.index();
30 for (dal::bv_visitor cv(convex_tab.index()); !cv.finished(); ++cv)
37 mesh_convex_structure::ind_pt_ct::const_iterator it;
39 for (it=convex_tab[ic].pts.begin();
40 it != convex_tab[ic].pts.end() && (*it) != ip; ++it) ++ind;
41 GMM_ASSERT1(it != convex_tab[ic].pts.end(),
42 "This point does not exist on this convex.");
48 std::vector<size_type> doubles;
52 for (
size_type l = 0; l < convex_tab[cv].pts.size(); ++l) {
54 if (ind == i) ind = j;
55 else if (ind == j) { ind = i; doubles.push_back(cv); }
60 if (std::find(doubles.begin(), doubles.end(), cv) == doubles.end()) {
61 for (
size_type l = 0; l < convex_tab[cv].pts.size(); ++l)
62 if (convex_tab[cv].pts[l] == j) convex_tab[cv].pts[l] = i;
70 std::vector<size_type> doubles;
73 for (
size_type k = 0; k < convex_tab[i].pts.size(); ++k) {
77 if (ind == i) ind = j;
78 else if (ind == j) { ind = i; doubles.push_back(ip); }
82 for (
size_type k = 0; k < convex_tab[j].pts.size(); ++k) {
84 if (std::find(doubles.begin(), doubles.end(), ip) == doubles.end()) {
86 if (points_tab[ip][l] == j) points_tab[ip][l] = i;
101 for (
size_type l = 0; l < convex_tab[ic].pts.size(); ++l) {
103 std::vector<size_type>::iterator it1= points_tab[ind].
begin(), it2 = it1;
104 std::vector<size_type>::iterator ite= points_tab[ind].
end();
105 for (; it2 != ite; ++it2) { *it1 = *it2;
if (*it1 != ic) ++it1; }
106 points_tab[ind].pop_back();
118 for (
short_type iff = 0; iff < ps->nb_faces(); ++iff)
125 for (dal::bv_visitor i(nn); !i.finished(); ++i)
126 if (convex_tab[i].cstruct->dim() == n)
133 for (dal::bv_visitor i(nn); !i.finished(); ++i)
134 dmax = std::max(dmax, convex_tab[i].cstruct->dim());
135 for ( ; dmax > 1; --dmax)
to_faces(dmax);
142 for (
size_type l = 0; l < convex_tab[cv].pts.size(); ++l)
143 if (convex_tab[cv].pts[l] == i2) { ++nb;
break; }
149 std::vector<size_type> &ipt)
const {
153 for (
size_type l = 0; l < convex_tab[cv].pts.size(); ++l)
154 if (convex_tab[cv].pts[l] == i2) { ipt.push_back(cv);
break; }
163 for (
size_type l = 0; l < convex_tab[cv].pts.size(); ++l)
164 if (ip != convex_tab[cv].pts[l]) {
166 if (std::find(s.begin(), s.end(), ind) != s.end()) s.push_back(ind);
174 const mesh_convex_structure *q = &(convex_tab[ic]);
175 std::vector<size_type>::const_iterator r = q->pts.begin();
176 const convex_ind_ct *p = &(q->cstruct->ind_points_of_face(iff));
180 size_type mesh_structure::memsize(
void)
const {
182 + convex_tab.memsize();
183 for (
size_type i = 0; i < convex_tab.size(); ++i)
184 mems += convex_tab[i].pts.size() *
sizeof(
size_type);
186 mems += points_tab[i].size() *
sizeof(
size_type);
192 for (i = 0; i < j; i++)
193 if (!convex_tab.index_valid(i))
196 if (points_tab.
size())
197 for (i=0, j = (points_tab.
end()-points_tab.
begin())-1; i < j; ++i, --j){
198 while (i < j && !(points_tab[i].empty())) ++i;
199 while (i < j && points_tab[j].empty()) --j;
205 points_tab = dal::dynamic_tas<ind_cv_ct, 8>();
206 convex_tab = dal::dynamic_tas<mesh_convex_structure, 8>();
210 void mesh_structure::stat(
void) {
211 cout <<
"mesh structure with " <<
nb_convex() <<
" valid convex, "
212 <<
"for a total memory size of " << memsize() <<
" bytes.\n";
225 && (convex_tab[ic].cstruct->dim()==convex_tab[icv].cstruct->dim()))
232 const std::vector<short_type> &ftab,
235 std::vector<size_type> ipts;
237 switch (ftab.size()) {
241 ipts.resize(pt.size());
242 std::copy(pt.begin(), pt.end(), ipts.begin());
249 ipts.resize(pt.size());
250 std::copy(pt.begin(), pt.end(), ipts.begin());
256 const mesh_convex_structure &q = convex_tab[ic];
257 const convex_ind_ct &ind = q.cstruct->ind_common_points_of_faces(ftab);
259 ipts.resize(ind.size());
260 auto it = ind.cbegin();
261 for (
size_type &ipt : ipts) ipt = q.pts[*it++];
266 if (ipts.size() == 0) {
270 auto ipt0 = ipts.cbegin();
271 auto ipt1 = ipt0 + 1;
273 for (
size_type icv : points_tab[*ipt0]) {
289 && (convex_tab[ic].cstruct->dim()==convex_tab[icv].cstruct->dim()))
290 if (std::find(s.begin(), s.end(), icv) == s.end())
304 && (convex_tab[ic].cstruct->dim()==convex_tab[icv].cstruct->dim()))
312 if (neighbor_element ==
size_type(-1))
return convex_face::invalid_face();
315 auto nNeighborElementFaces = pcs->nb_faces();
316 for (
short_type iff = 0; iff < nNeighborElementFaces; ++iff) {
317 auto nPointsOnFace = pcs->nb_points_of_face(iff);
319 nPointsOnFace, face_points.begin()))
320 return {neighbor_element, iff};
322 GMM_ASSERT2(
false,
"failed to determine neighboring face");
323 return convex_face::invalid_face();
329 ind_cv_ct::const_iterator it = std::find(ct.begin(), ct.end(), ip);
330 return (it != ct.end()) ? (it - ct.begin()):
size_type(-1);
339 void mesh_edge_list_convex(
pconvex_structure cvs, std::vector<size_type> points_of_convex,
340 size_type cv_id, edge_list &el,
bool merge_convex)
342 dim_type n = cvs->dim();
344 size_type ncv = merge_convex ? 0 : cv_id;
347 for (dim_type k = 0; k < n; ++k)
348 for (dim_type l = dim_type(k+1); l <= n; ++l)
349 el.add(edge_list_elt(points_of_convex[k],
350 points_of_convex[l], ncv));
355 for (dim_type j = 0; j < n; ++j)
356 if ((k & (1 << j)) == 0)
357 el.add(edge_list_elt(points_of_convex[k],
358 points_of_convex[k | (1 << j)], ncv));
361 for (dim_type k = 0; k < n - 1; ++k)
362 for (dim_type l = dim_type(k+1); l < n; ++l) {
363 el.add(edge_list_elt(points_of_convex[k],
364 points_of_convex[l], ncv));
365 el.add(edge_list_elt(points_of_convex[k+n],
366 points_of_convex[l+n], ncv));
368 for (dim_type k = 0; k < n; ++k)
369 el.add(edge_list_elt(points_of_convex[k],
370 points_of_convex[k+n], ncv));
377 indpttab[0].resize(cvstab[0]->nb_points());
378 std::copy(points_of_convex.begin(),
379 points_of_convex.end(), indpttab[0].begin());
388 std::vector< size_type > pts = indpttab[ncs];
389 if (cvs->dim() == 1) {
391 for (
size_type j = 1; j < cvs->nb_points(); ++j) {
393 el.add(edge_list_elt((indpttab[ncs])[j-1],(indpttab[ncs])[j],ncv));
400 cvstab[ncs+f] = (cvs->faces_structure())[f];
401 indpttab[ncs+f].resize(cvs->nb_points_of_face(f));
410 for (
size_type k = 0; k < cvs->nb_points_of_face(f); ++k)
411 (indpttab[ncs+f])[k] = pts[cvs->ind_points_of_face(f)[k]];
423 void mesh_edge_list(
const mesh_structure &m, edge_list &el,
425 std::vector<size_type> p;
426 for (dal::bv_visitor cv(m.convex_index()); !cv.finished(); ++cv) {
427 p.resize(m.nb_points_of_convex(cv));
428 std::copy(m.ind_points_of_convex(cv).begin(),
429 m.ind_points_of_convex(cv).end(), p.begin());
430 mesh_edge_list_convex(m.structure_of_convex(cv), p, cv,
438 std::vector<size_type> &cmk) {
440 cmk.reserve(cvlst.card()); cmk.resize(0);
442 std::deque<int> pile;
443 std::vector<size_type> tab, connectivity(cvlst.last_true()+1),
444 temp(cvlst.last_true()+1);
448 std::fill(connectivity.begin(), connectivity.end(),
size_type(-1));
452 for (dal::bv_visitor j(cvlst); !j.finished(); ++j) {
454 mesh_structure::ind_cv_ct::const_iterator itp = ct.begin(),
458 for (; itp != itpe; ++itp) {
460 mesh_structure::ind_cv_ct::const_iterator
463 for ( ; it != ite; ++it)
464 if (temp[*it] != j+1) { temp[*it] = j+1; nei++; }
466 connectivity[j] = nei-1;
467 if (nei < connectivity[cv]) cv = j;
478 mesh_structure::ind_cv_ct::const_iterator
481 for ( ; it != ite; ++it)
482 if (connectivity[*it] !=
size_type(-1)) {
484 pile.push_front(
int(*it));
489 cv = std::min_element(connectivity.begin(), connectivity.end()) - connectivity.begin();
490 if (connectivity[cv] ==
size_type(-1))
break;
492 else { cv = pile.back(); pile.pop_back(); }
Mesh structure definition.
Mesh structure definition.
bool is_convex_valid(size_type i)
Return true if i is in convex_index()
size_type add_face_of_convex(size_type ic, short_type f)
Insert a new convex corresponding to face f of the convex ic.
short_type nb_points_of_convex(size_type ic) const
Return the number of points of convex ic.
const dal::bit_vector & convex_index() const
Return the list of valid convex IDs.
size_type neighbor_of_convex(size_type ic, short_type f) const
Return a neighbor convex of a given convex face.
short_type nb_faces_of_convex(size_type ic) const
Return the number of faces of convex ic.
bool is_convex_face_having_points(size_type ic, short_type face_num, short_type nb, ITER pit) const
Return true if the face of the convex contains the given list of points.
void clear()
erase the mesh
bool is_convex_having_points(size_type ic, short_type nb, ITER pit) const
Return true if the convex contains the listed points.
ind_pt_face_ct ind_points_of_face_of_convex(size_type ic, short_type f) const
Return a container of the (global) point number for face f or convex ic.
size_type nb_convex() const
The total number of convexes in the mesh.
size_type local_ind_of_convex_point(size_type ic, size_type ip) const
Return the "local" index for point ip of the mesh.
void neighbors_of_convex(size_type ic, short_type f, ind_set &s) const
Return in s a list of neighbors of a given convex face.
void swap_convex(size_type cv1, size_type cv2)
Exchange two convex IDs.
const ind_cv_ct & convex_to_point(size_type ip) const
Return a container of the convexes attached to point ip.
size_type add_convex(pconvex_structure cs, ITER ipts, bool *present=0)
Insert a new convex in the mesh_structure.
void add_faces_of_convex(size_type ic)
Insert new convexes corresponding to the faces of the convex ic.
pconvex_structure structure_of_convex(size_type ic) const
Return the pconvex_structure of the convex ic.
void ind_points_to_point(size_type, ind_set &) const
Return a container of the points attached (via an edge) to point ip.
size_type ind_in_convex_of_point(size_type ic, size_type ip) const
Find the local index of the point of global index ip with respect to the convex cv.
void optimize_structure()
Reorder the convex IDs and point IDs, such that there is no hole in their numbering.
void to_faces(dim_type n)
build a new mesh, such that its convexes are the faces of the convexes of the previous one
convex_face adjacent_face(size_type ic, short_type f) const
Return a face of the neighbouring element that is adjacent to the given face.
const ind_set & ind_points_of_convex(size_type ic) const
Return a container to the list of points attached to convex ic.
void sup_convex(size_type ic)
Remove the convex ic.
void swap_points(size_type i, size_type j)
Exchange two point IDs.
void to_edges()
build a new mesh, such that its convexes are the edges of the convexes of the previous one
size_type memsize(void) const
Gives the total memory occupied by the array.
iterator begin(void)
Iterator on the first element.
size_type size(void) const
Number of allocated elements.
iterator end(void)
Iterator on the last + 1 element.
indexed array reference (given a container X, and a set of indexes I, this class provides a pseudo-co...
gmm::uint16_type short_type
used as the common short type integer in the library
std::shared_ptr< const convex_structure > pconvex_structure
Pointer on a convex structure description.
pconvex_structure parallelepiped_structure(dim_type nc, dim_type k)
Give a pointer on the structures of a parallelepiped of dimension d.
void cuthill_mckee_on_convexes(const bgeot::mesh_structure &ms, std::vector< size_type > &cmk)
Return the cuthill_mc_kee ordering on the convexes.
pconvex_structure prism_P1_structure(dim_type nc)
Give a pointer on the structures of a prism of dimension d.
pconvex_structure simplex_structure(dim_type nc)
Give a pointer on the structures of a simplex of dimension d.
size_t size_type
used as the common size type in the library