Chi-Tech
chi_surfacemesh_internalconn.cc
Go to the documentation of this file.
1#include "chi_surfacemesh.h"
2
3
4#include <chi_log.h>
5
6#include "utils/chi_timer.h"
7
8#include <algorithm>
9
10//#########################################################
11/** Runs over the faces of the surfacemesh and determines
12 * neighbors. The algorithm first establishes which cells subscribe to each
13 * vertex and then loops over faces and edges. For each edge, only the
14 * subscribing faces are searched for neighbors. This routine has
15 * time complexity O(N).*/
17{
18 std::vector<std::vector<size_t >> vertex_subscriptions;
19
20 //======================================== Initialize vertex subscription
21 size_t num_verts = vertices_.size();
22 vertex_subscriptions.resize(num_verts);
23
24 for (auto& vert_sub : vertex_subscriptions)
25 vert_sub.reserve(5);
26
27 //======================================== Loop over cells and determine
28 // which cells subscribe to a vertex
29 //%%%%%% TRIANGLES %%%%%
30 size_t num_tri_faces = faces_.size();
31 for (size_t tf=0; tf<num_tri_faces; tf++)
32 {
33 auto& try_face = faces_[tf];
34 for (int v=0; v<3; ++v)
35 vertex_subscriptions[v].push_back(tf);
36 }
37 //%%%%% POLYGONS %%%%%
38 size_t num_poly_faces = poly_faces_.size();
39 for (size_t pf=0; pf<num_poly_faces; pf++)
40 {
41 auto poly_face = poly_faces_[pf];
42 for (auto v : poly_face->v_indices)
43 vertex_subscriptions[v].push_back(pf);
44 }
45
46 //======================================== Loop over cells and determine
47 // connectivity
48 //%%%%%% TRIANGLES %%%%%
49 for (auto curFace : faces_)
50 {
51 for (int e=0;e<3;e++)
52 {
53 int* curface_edge = curFace.e_index[e];
54 int vi = curface_edge[0];
55 int vf = curface_edge[1];
56
57 //=============================== Search cells subscribing to vi
58 for (auto ofi : vertex_subscriptions[vi])
59 {
60 auto& other_face = faces_[ofi];
61
62 for (size_t e2=0;e2<3;e2++)
63 {
64 if ( (curface_edge[0]==other_face.e_index[e2][1]) &&
65 (curface_edge[1]==other_face.e_index[e2][0]) )
66 {
67 curface_edge[2] = ofi; //cell index
68 curface_edge[3] = e2; //edge index
69 }
70 }//for e2
71 }//for ofi
72
73 //=============================== Search cells subscribing to vf
74 for (auto ofi : vertex_subscriptions[vf])
75 {
76 auto& other_face = faces_[ofi];
77
78 for (size_t e2=0;e2<3;e2++)
79 {
80 if ( (curface_edge[0]==other_face.e_index[e2][1]) &&
81 (curface_edge[1]==other_face.e_index[e2][0]) )
82 {
83 curface_edge[2] = ofi; //cell index
84 curface_edge[3] = e2; //edge index
85 }
86 }//for e2
87 }//for ofi
88 }//for current face edges
89 }//for faces
90
91 //======================================== Loop over cells and determine
92 // connectivity
93 //%%%%% POLYGONS %%%%%
94 for (auto curFace : poly_faces_)
95 {
96 for (auto& curface_edge : curFace->edges)
97 {
98 int vi = curface_edge[0];
99 int vf = curface_edge[1];
100
101 //=============================== Search cells subscribing to vi
102 for (auto ofi : vertex_subscriptions[vi])
103 {
104 auto other_face = poly_faces_[ofi];
105
106 for (size_t e2=0;e2<other_face->edges.size();e2++)
107 {
108 if ( (curface_edge[0]==other_face->edges[e2][1]) &&
109 (curface_edge[1]==other_face->edges[e2][0]) )
110 {
111 curface_edge[2] = ofi; //cell index
112 curface_edge[3] = e2; //edge index
113 }
114 }//for e2
115 }//for ofi
116
117 //=============================== Search cells subscribing to vf
118 for (auto ofi : vertex_subscriptions[vf])
119 {
120 auto other_face = poly_faces_[ofi];
121
122 for (size_t e2=0;e2<other_face->edges.size();e2++)
123 {
124 if ( (curface_edge[0]==other_face->edges[e2][1]) &&
125 (curface_edge[1]==other_face->edges[e2][0]) )
126 {
127 curface_edge[2] = ofi; //cell index
128 curface_edge[3] = e2; //edge index
129 }
130 }//for e2
131 }//for other faces
132 }//for current face edges
133 }//for faces
134
135}
std::vector< chi_mesh::PolyFace * > poly_faces_
Polygonal faces.
std::vector< chi_mesh::Vertex > vertices_
std::vector< chi_mesh::Face > faces_