Chi-Tech
unpartmesh_00b_connectivity.cc
Go to the documentation of this file.
2
3#include "chi_runtime.h"
4#include "chi_log.h"
5
6#include "utils/chi_timer.h"
7
8#include "chi_mpi.h"
9
10//###################################################################
11/**Establishes neighbor connectivity for the light-weight mesh.*/
13{
14 const size_t num_raw_cells = raw_cells_.size();
15 const size_t num_raw_vertices = vertices_.size();
16
17 //======================================== Reset all cell neighbors
18 int num_bndry_faces = 0;
19 for (auto& cell : raw_cells_)
20 for (auto& face : cell->faces)
21 if (not face.has_neighbor) ++num_bndry_faces;
22
24 << " Number of unconnected faces "
25 "before connectivity: " << num_bndry_faces;
26
28 << " Establishing cell connectivity.";
29
30 //======================================== Establish internal connectivity
31 // Populate vertex subscriptions to internal cells
32 vertex_cell_subscriptions_.resize(num_raw_vertices);
33 {
34 uint64_t cur_cell_id=0;
35 for (const auto& cell : raw_cells_)
36 {
37 for (auto vid : cell->vertex_ids)
38 vertex_cell_subscriptions_.at(vid).insert(cur_cell_id);
39 ++cur_cell_id;
40 }
41 }
42
44 << " Vertex cell subscriptions complete.";
45
46 // Process raw cells
47 {
48 uint64_t aux_counter = 0;
49 uint64_t cur_cell_id=0;
50 for (auto& cell : raw_cells_)
51 {
52 for (auto& cur_cell_face : cell->faces)
53 {
54 if (cur_cell_face.has_neighbor) {continue;}
55 const std::set<uint64_t> cfvids(cur_cell_face.vertex_ids.begin(),
56 cur_cell_face.vertex_ids.end());
57
58 std::set<size_t> cells_to_search;
59 for (uint64_t vid : cfvids)
60 for (uint64_t cell_id : vertex_cell_subscriptions_.at(vid))
61 if (cell_id != cur_cell_id)
62 cells_to_search.insert(cell_id);
63
64 for (uint64_t adj_cell_id : cells_to_search)
65 {
66 auto adj_cell = raw_cells_.at(adj_cell_id);
67
68 for (auto& adj_cell_face : adj_cell->faces)
69 {
70 if (adj_cell_face.has_neighbor) {continue;}
71 const std::set<uint64_t> afvids(adj_cell_face.vertex_ids.begin(),
72 adj_cell_face.vertex_ids.end());
73
74 if (cfvids == afvids)
75 {
76 cur_cell_face.neighbor = adj_cell_id;
77 adj_cell_face.neighbor = cur_cell_id;
78
79 cur_cell_face.has_neighbor = true;
80 adj_cell_face.has_neighbor = true;
81
82 goto face_neighbor_found;
83 }
84 }//for adjacent cell face
85 }
86 face_neighbor_found:;
87 }//for face
88
89 ++cur_cell_id;
90 const double fraction_complete = static_cast<double>(cur_cell_id)/
91 static_cast<double>(num_raw_cells);
92 if (fraction_complete >= static_cast<double>(aux_counter+1)*0.1)
93 {
95 << " Surpassing cell " << cur_cell_id
96 << " of " << num_raw_cells
97 << " (" << (aux_counter+1)*10 << "%)";
98 ++aux_counter;
99 }
100 }//for cell
101 }
102
104 << " Establishing cell boundary connectivity.";
105
106 //======================================== Establish boundary connectivity
107 // Make list of internal cells on the boundary
108 std::vector<LightWeightCell*> internal_cells_on_boundary;
109 for (auto& cell : raw_cells_)
110 {
111 bool cell_on_boundary = false;
112 for (auto& face : cell->faces)
113 if (not face.has_neighbor)
114 { cell_on_boundary = true; break; }
115
116 if (cell_on_boundary) internal_cells_on_boundary.push_back(cell);
117 }
118
119 // Populate vertex subscriptions to boundary cells
120 std::vector<std::set<uint64_t>> vertex_bndry_cell_subscriptions(vertices_.size());
121 {
122 uint64_t cur_cell_id=0;
123 for (auto& cell : raw_boundary_cells_)
124 {
125 for (auto vid : cell->vertex_ids)
126 vertex_bndry_cell_subscriptions.at(vid).insert(cur_cell_id);
127 ++cur_cell_id;
128 }
129 }
130
131 // Process boundary cells
132 for (auto& cell : internal_cells_on_boundary)
133 for (auto& face : cell->faces)
134 {
135 if (face.has_neighbor) continue;
136 std::set<uint64_t> cfvids(face.vertex_ids.begin(),
137 face.vertex_ids.end());
138
139 std::set<size_t> cells_to_search;
140 for (uint64_t vid : face.vertex_ids)
141 for (uint64_t cell_id : vertex_bndry_cell_subscriptions[vid])
142 cells_to_search.insert(cell_id);
143
144 for (uint64_t adj_cell_id : cells_to_search)
145 {
146 auto& adj_cell = raw_boundary_cells_[adj_cell_id];
147
148 std::set<uint64_t> afvids(adj_cell->vertex_ids.begin(),
149 adj_cell->vertex_ids.end());
150
151 if (cfvids == afvids)
152 {
153 face.neighbor = adj_cell->material_id;
154 break;
155 }
156 }//for adj_cell_id
157 }//for face
158
159 num_bndry_faces = 0;
160 for (auto cell : raw_cells_)
161 for (auto& face : cell->faces)
162 if (not face.has_neighbor) ++num_bndry_faces;
163
165 << " Number of boundary faces "
166 "after connectivity: " << num_bndry_faces;
167
169 << " Done establishing cell connectivity.";
170
171}
static chi::Timer program_timer
Definition: chi_runtime.h:79
static chi::ChiLog & log
Definition: chi_runtime.h:81
LogStream Log(LOG_LVL level=LOG_0)
Definition: chi_log.cc:35
LogStream Log0Verbose1()
Definition: chi_log.h:234
std::string GetTimeString() const
Definition: chi_timer.cc:38
std::vector< chi_mesh::Vertex > vertices_
std::vector< std::set< uint64_t > > vertex_cell_subscriptions_
std::vector< LightWeightCell * > raw_cells_
std::vector< LightWeightCell * > raw_boundary_cells_