Chi-Tech
chi_volumemesher_01b_create_polygoncells.cc
Go to the documentation of this file.
4
5#include "chi_runtime.h"
6#include "chi_log.h"
7#include "chi_mpi.h"
8
9
10//###################################################################
11/**Creates 2D polygon cells for each face of an unpartitioned mesh.*/
15{
16 //=================================== Copy nodes
17 {
18 uint64_t id = 0;
19 for (const auto& vertex : umesh.GetVertices())
20 grid->vertices.Insert(id++, vertex);
21 }
22
23 size_t num_cells=0;
24 for (auto& raw_cell : umesh.GetRawCells())
25 {
26 // Check valid template cell
27 if (raw_cell->type != chi_mesh::CellType::POLYGON)
28 {
30 << "chi_mesh::VolumeMesher::CreatePolygonCells "
31 "called with a cell not being of primary type"
32 " chi_mesh::CellType::POLYGON.";
33 Chi::Exit(EXIT_FAILURE);
34 }
35
36 //====================================== Make cell
37 auto cell = std::make_unique<chi_mesh::Cell>(CellType::POLYGON,
38 raw_cell->sub_type);
39
40 cell->global_id_ = num_cells;
41 cell->local_id_ = num_cells;
42 cell->partition_id_ = Chi::mpi.location_id;
43
44 cell->centroid_ = raw_cell->centroid;
45 cell->material_id_ = raw_cell->material_id;
46 cell->vertex_ids_ = raw_cell->vertex_ids;
47
48 // Copy faces + compute face centroid and normal
49 const chi_mesh::Vector3 khat(0.0, 0.0, 1.0);
50 for (auto& raw_face : raw_cell->faces)
51 {
52 chi_mesh::CellFace new_face;
53
54 new_face.vertex_ids_ = raw_face.vertex_ids;
55
56 const auto& v0 = grid->vertices[new_face.vertex_ids_[0]];
57 const auto& v1 = grid->vertices[new_face.vertex_ids_[1]];
58 new_face.centroid_ = v0 * 0.5 + v1 * 0.5;
59
60 chi_mesh::Vector3 va = v1 - v0;
61 chi_mesh::Vector3 vn = va.Cross(khat);
62 vn = vn/vn.Norm();
63 new_face.normal_ = vn;
64
65 new_face.has_neighbor_ = raw_face.has_neighbor;
66 new_face.neighbor_id_ = raw_face.neighbor;
67
68 cell->faces_.push_back(new_face);
69 }
70
71 //====================================== Push to grid
72 grid->cells.push_back(std::move(cell));
73 ++num_cells;
74 }//for raw_cell
75}
static void Exit(int error_code)
Definition: chi_runtime.cc:342
static chi::ChiLog & log
Definition: chi_runtime.h:81
static chi::MPI_Info & mpi
Definition: chi_runtime.h:78
LogStream LogAllError()
Definition: chi_log.h:239
const int & location_id
Current process rank.
Definition: mpi_info.h:26
Normal normal_
A list of the vertices.
Definition: cell.h:39
bool has_neighbor_
Flag indicating whether face has a neighbor.
Definition: cell.h:41
uint64_t neighbor_id_
Otherwise contains boundary_id.
Definition: cell.h:42
std::vector< uint64_t > vertex_ids_
Definition: cell.h:38
Vertex centroid_
The face centroid.
Definition: cell.h:40
const std::vector< chi_mesh::Vertex > & GetVertices() const
std::vector< LightWeightCell * > & GetRawCells()
static void CreatePolygonCells(const chi_mesh::UnpartitionedMesh &umesh, chi_mesh::MeshContinuumPtr &grid)
std::shared_ptr< MeshContinuum > MeshContinuumPtr
Definition: chi_mesh.h:44
Vector3 Cross(const Vector3 &that) const
double Norm() const