16 case CellType::GHOST:
return "GHOST";
17 case CellType::SLAB:
return "SLAB";
20 case CellType::TRIANGLE:
return "TRIANGLE";
21 case CellType::QUADRILATERAL:
return "QUADRILATERAL";
23 case CellType::POLYGON:
return "POLYGON";
24 case CellType::TETRAHEDRON:
return "TETRAHEDRON";
25 case CellType::HEXAHEDRON:
return "HEXAHEDRON";
26 case CellType::WEDGE:
return "WEDGE";
27 case CellType::PYRAMID:
return "PYRAMID";
28 case CellType::POLYHEDRON:
return "POLYHEDRON";
30 case CellType::POINT:
return "POINT";
39 cell_type_(other.cell_type_),
40 cell_sub_type_(other.cell_sub_type_),
41 global_id_(other.global_id_),
42 local_id_(other.local_id_),
43 partition_id_(other.partition_id_),
44 centroid_(other.centroid_),
45 material_id_(other.material_id_),
46 vertex_ids_(other.vertex_ids_),
54 cell_type_(other.cell_type_),
55 cell_sub_type_(other.cell_sub_type_),
56 global_id_(other.global_id_),
57 local_id_(other.local_id_),
58 partition_id_(other.partition_id_),
59 centroid_(other.centroid_),
60 material_id_(other.material_id_),
61 vertex_ids_(std::move(other.vertex_ids_)),
62 faces_(std::move(other.faces_))
88 if (not has_neighbor_)
return false;
89 if (
Chi::mpi.process_count == 1)
return true;
91 auto& adj_cell = grid.
cells[neighbor_id_];
101 if (not has_neighbor_)
return -1;
102 if (
Chi::mpi.process_count == 1)
return 0;
104 auto& adj_cell = grid.
cells[neighbor_id_];
106 return static_cast<int>(adj_cell.partition_id_);
114 if (not has_neighbor_)
return -1;
115 if (
Chi::mpi.process_count == 1)
return neighbor_id_;
117 auto& adj_cell = grid.
cells[neighbor_id_];
120 throw std::logic_error(
"Cell local ID requested from a non-local cell.");
122 return adj_cell.local_id_;
130 const auto& cur_face = *
this;
132 if (not cur_face.has_neighbor_)
134 std::stringstream outstr;
136 <<
"Invalid cell index encountered in call to "
137 <<
"CellFace::GetNeighborAssociatedFace. Index points "
139 throw std::logic_error(outstr.str());
142 const auto& adj_cell = grid.
cells[cur_face.neighbor_id_];
144 int associated_face = -1;
145 std::set<uint64_t> cfvids(cur_face.vertex_ids_.begin(),
146 cur_face.vertex_ids_.end());
150 for (
const auto& adj_face : adj_cell.faces_)
153 std::set<uint64_t> afvids(adj_face.vertex_ids_.begin(),
154 adj_face.vertex_ids_.end());
156 if (afvids == cfvids) {associated_face = af;
break;}
160 if (associated_face<0)
162 std::stringstream outstr;
164 <<
"Could not find associated face in call to "
165 <<
"CellFace::GetNeighborAssociatedFace.\n"
166 <<
"Reference face with centroid at: "
167 << cur_face.centroid_.PrintS() <<
"\n"
168 <<
"Adjacent cell: " << adj_cell.global_id_ <<
"\n";
169 for (
size_t afi=0; afi < adj_cell.faces_.size(); afi++)
172 <<
"Adjacent cell face " << afi <<
" centroid "
173 << adj_cell.faces_[afi].centroid_.PrintS();
175 throw std::runtime_error(outstr.str());
178 return associated_face;
185 if (vertex_ids_.size() <= 1)
187 else if (vertex_ids_.size() == 2)
189 const auto& v0 = grid.
vertices[vertex_ids_[0]];
190 const auto& v1 = grid.
vertices[vertex_ids_[1]];
192 return (v1 - v0).Norm();
197 auto& v2 = centroid_;
198 const auto num_verts = vertex_ids_.size();
199 for (uint64_t v=0; v<num_verts; ++v)
201 uint64_t vid0 = vertex_ids_[v];
202 uint64_t vid1 = (v < (num_verts-1)) ? vertex_ids_[v + 1] : vertex_ids_[0];
204 const auto& v0 = grid.
vertices[vid0];
205 const auto& v1 = grid.
vertices[vid1];
215 area += 0.5*std::fabs(J.
Det());
229 raw.
Write<
size_t>(vertex_ids_.size());
230 for (uint64_t vid : vertex_ids_)
231 raw.
Write<uint64_t>(vid);
235 raw.
Write<
bool>(has_neighbor_);
236 raw.
Write<uint64_t>(neighbor_id_);
250 const size_t num_face_verts = raw.
Read<
size_t>(address, &address);
252 for (
size_t fv=0; fv<num_face_verts; ++fv)
268 std::stringstream outstr;
270 outstr <<
"num_vertex_ids: " << vertex_ids_.size() <<
"\n";
273 for (uint64_t vid : vertex_ids_)
274 outstr <<
"vid" << counter++ <<
": " << vid <<
"\n";
277 outstr <<
"normal: " << normal_.PrintS() <<
"\n";
278 outstr <<
"centroid: " << centroid_.PrintS() <<
"\n";
279 outstr <<
"has_neighbor: " << has_neighbor_ <<
"\n";
280 outstr <<
"neighbor_id: " << neighbor_id_ <<
"\n";
293 for (uint64_t vid : vertex_ids_)
295 centroid_ /=
static_cast<double>(vertex_ids_.size());
305 raw.
Write<uint64_t>(global_id_);
306 raw.
Write<uint64_t>(local_id_);
307 raw.
Write<uint64_t>(partition_id_);
309 raw.
Write<
int>(material_id_);
314 raw.
Write<
size_t>(vertex_ids_.size());
315 for (uint64_t vid : vertex_ids_)
316 raw.
Write<uint64_t>(vid);
318 raw.
Write<
size_t>(faces_.size());
319 for (
const auto& face : faces_)
320 raw.
Append(face.Serialize());
332 auto cell_global_id = raw.
Read<uint64_t>(address, &address);
333 auto cell_local_id = raw.
Read<uint64_t>(address, &address);
334 auto cell_prttn_id = raw.
Read<uint64_t>(address, &address);
335 auto cell_centroid = raw.
Read<Vec3> (address, &address);
336 auto cell_matrl_id = raw.
Read<
int> (address, &address);
339 auto cell_sub_type = raw.
Read<
CellType>(address, &address);
341 Cell cell(cell_type, cell_sub_type);
342 cell.global_id_ = cell_global_id;
343 cell.local_id_ = cell_local_id;
344 cell.partition_id_ = cell_prttn_id;
345 cell.centroid_ = cell_centroid;
346 cell.material_id_ = cell_matrl_id;
348 auto num_vertex_ids = raw.
Read<
size_t>(address, &address);
349 cell.vertex_ids_.reserve(num_vertex_ids);
350 for (
size_t v=0; v<num_vertex_ids; ++v)
351 cell.vertex_ids_.push_back(raw.
Read<uint64_t>(address, &address));
353 auto num_faces = raw.
Read<
size_t>(address, &address);
354 cell.faces_.reserve(num_faces);
355 for (
size_t f=0; f<num_faces; ++f)
366 std::stringstream outstr;
368 outstr <<
"cell_type: " <<
CellTypeName(cell_type_) <<
"\n";
369 outstr <<
"cell_sub_type: " <<
CellTypeName(cell_sub_type_) <<
"\n";
370 outstr <<
"global_id: " << global_id_ <<
"\n";
371 outstr <<
"local_id: " << local_id_ <<
"\n";
372 outstr <<
"partition_id: " << partition_id_ <<
"\n";
373 outstr <<
"centroid: " << centroid_.PrintS() <<
"\n";
374 outstr <<
"material_id: " << material_id_ <<
"\n";
376 outstr <<
"num_vertex_ids: " << vertex_ids_.size() <<
"\n";
379 for (uint64_t vid : vertex_ids_)
380 outstr <<
"vid" << counter++ <<
": " << vid <<
"\n";
384 outstr <<
"num_faces: " << faces_.size() <<
"\n";
386 for (
const auto& face : faces_)
387 outstr <<
"Face " << f++ <<
":\n" << face.ToString();
399 const auto k_hat =
Vector3(0,0,1);
402 for (uint64_t vid : vertex_ids_)
404 centroid_ /=
static_cast<double>(vertex_ids_.size());
406 for (
auto& face : faces_)
408 face.RecomputeCentroid(grid);
412 const auto v0 = grid.
vertices[face.vertex_ids_[0]];
413 const auto v1 = grid.
vertices[face.vertex_ids_[1]];
415 const auto v01 = v1 - v0;
417 face.normal_ = v01.Cross(k_hat).Normalized();
425 const size_t num_face_verts = face.vertex_ids_.size();
426 double total_area = 0.0;
427 auto weighted_normal =
Vector3(0,0,0);
428 for (
size_t fv=0; fv<num_face_verts; ++fv)
430 size_t fvp1 = (fv < (num_face_verts-1))? fv+1 : 0;
432 uint64_t fvid_m = face.vertex_ids_[fv ];
433 uint64_t fvid_p = face.vertex_ids_[fvp1];
435 auto leg_m = grid.
vertices[fvid_m] - face.centroid_;
436 auto leg_p = grid.
vertices[fvid_p] - face.centroid_;
438 auto vn = leg_m.Cross(leg_p);
440 double area = 0.5*vn.Norm();
443 weighted_normal = weighted_normal + area*vn.Normalized();
445 weighted_normal = weighted_normal/total_area;
447 face.normal_ = weighted_normal.Normalized();
static chi::MPI_Info & mpi
const int & location_id
Current process rank.
void Append(const ByteArray &other_raw)
void Write(const T &value)
int GetNeighborPartitionID(const chi_mesh::MeshContinuum &grid) const
Normal normal_
A list of the vertices.
bool has_neighbor_
Flag indicating whether face has a neighbor.
uint64_t neighbor_id_
Otherwise contains boundary_id.
chi_data_types::ByteArray Serialize() const
std::vector< uint64_t > vertex_ids_
void RecomputeCentroid(const chi_mesh::MeshContinuum &grid)
bool IsNeighborLocal(const chi_mesh::MeshContinuum &grid) const
double ComputeFaceArea(const chi_mesh::MeshContinuum &grid) const
Vertex centroid_
The face centroid.
static CellFace DeSerialize(const chi_data_types::ByteArray &raw, size_t &address)
uint64_t GetNeighborLocalID(const chi_mesh::MeshContinuum &grid) const
int GetNeighborAssociatedFace(const chi_mesh::MeshContinuum &grid) const
std::string ToString() const
std::vector< CellFace > faces_
static Cell DeSerialize(const chi_data_types::ByteArray &raw, size_t &address)
void RecomputeCentroidsAndNormals(const chi_mesh::MeshContinuum &grid)
Cell & operator=(const Cell &other)
std::string ToString() const
chi_data_types::ByteArray Serialize() const
std::vector< uint64_t > vertex_ids_
std::string CellTypeName(CellType type)
void SetColJVec(int j, Vector3 vec)