Chi-Tech
volmesher_extruder_extrudecells.cc
Go to the documentation of this file.
2
4
5#include "chi_mpi.h"
6
7//###################################################################
8/**Extrude template cells into polygons.*/
12{
13 const chi_mesh::Vector3 khat(0.0,0.0,1.0);
14 //================================================== Start extrusion
15 size_t num_global_cells = 0;
16 for (size_t iz=0; iz<(vertex_layers_.size() - 1); iz++)
17 {
18 for (const auto& template_cell : template_grid.local_cells)
19 {
20 //========================================= Check template cell type
21 if (template_cell.Type() != chi_mesh::CellType::POLYGON)
22 throw std::logic_error("Extruder::ExtrudeCells: "
23 "Template cell error. Not of base type POLYGON");
24
25 //========================================= Check cell not inverted
26 {
27 const auto& v0 = template_cell.centroid_;
28 const auto& v1 = template_grid.vertices[template_cell.vertex_ids_[0]];
29 const auto& v2 = template_grid.vertices[template_cell.vertex_ids_[1]];
30
31 auto v01 = v1 - v0;
32 auto v02 = v2 - v0;
33
34 if (v01.Cross(v02).Dot(khat)<0.0)
35 throw std::logic_error("Extruder attempting to extrude a template"
36 " cell with a normal pointing downward. This"
37 " causes erratic behavior and needs to be"
38 " corrected.");
39 }
40
41 auto projected_centroid = ProjectCentroidToLevel(template_cell.centroid_, iz);
42 int pid = GetCellKBAPartitionIDFromCentroid(projected_centroid);
43
44 bool has_local_scope = HasLocalScope(template_cell, template_grid, iz);
45
46 if (has_local_scope)
47 {
48 auto cell = MakeExtrudedCell(template_cell,
49 grid,
50 iz,
51 num_global_cells,
52 pid,
53 template_grid.local_cells.size());
54
55 cell->material_id_ = template_cell.material_id_;
56
57 grid.cells.push_back(std::move(cell));
58 }
59 ++num_global_cells;
60
61 }//for template cell
62
63 }//for iz
64
65
66}
67
void push_back(std::unique_ptr< chi_mesh::Cell > new_cell)
LocalCellHandler local_cells
GlobalCellHandler cells
chi_mesh::Vector3 ProjectCentroidToLevel(const chi_mesh::Vector3 &centroid, size_t level)
bool HasLocalScope(const chi_mesh::Cell &template_cell, const chi_mesh::MeshContinuum &template_continuum, size_t z_level)
int GetCellKBAPartitionIDFromCentroid(chi_mesh::Vector3 &centroid)
void ExtrudeCells(chi_mesh::MeshContinuum &template_grid, chi_mesh::MeshContinuum &grid)
std::unique_ptr< chi_mesh::Cell > MakeExtrudedCell(const chi_mesh::Cell &template_cell, const chi_mesh::MeshContinuum &grid, size_t z_level, uint64_t cell_global_id, int partition_id, size_t num_template_cells)
std::vector< double > vertex_layers_