Chi-Tech
volmesher_predefunpart_execute.cc
Go to the documentation of this file.
2
6
8
9#include "chi_runtime.h"
10#include "chi_log.h"
11#include "chi_mpi.h"
12
13#include "utils/chi_timer.h"
14#include "console/chi_console.h"
15
16//###################################################################
17/**Executes the predefined3D mesher.*/
19{
22 << " VolumeMesherPredefinedUnpartitioned executing. Memory in use = "
24 << std::endl;
25
26 //======================================== Check partitioning params
28 {
29 int Px = this->options.partition_x;
30 int Py = this->options.partition_y;
31 int Pz = this->options.partition_z;
32
33 int desired_process_count = Px*Py*Pz;
34
35 if (desired_process_count != Chi::mpi.process_count)
36 {
38 << "ERROR: Number of processors available ("
40 ") does not match amount of processors "
41 "required by partitioning parameters ("
42 << desired_process_count << ").";
43 Chi::Exit(EXIT_FAILURE);
44 }
45 }
46
47 //======================================== Get unpartitioned mesh
49 "nullptr encountered for unparitioned mesh");
50
51 Chi::log.Log() << "Computed centroids";
53
54
55 //======================================== Apply partitioning scheme
56 std::vector<int64_t> cell_pids;
57 auto grid = chi_mesh::MeshContinuum::New();
58
59 grid->GetBoundaryIDMap() = umesh_ptr_->GetMeshOptions().boundary_id_map;
60
61 if (options.partition_type == PartitionType::KBA_STYLE_XYZ)
62 cell_pids = KBA(*umesh_ptr_);
63 else
64 cell_pids = PARMETIS(*umesh_ptr_);
65
66 //======================================== Load up the cells
67 auto& vertex_subs = umesh_ptr_->GetVertextCellSubscriptions();
68 size_t cell_globl_id = 0;
69 for (auto raw_cell : umesh_ptr_->GetRawCells())
70 {
71 if (CellHasLocalScope(*raw_cell, cell_globl_id, vertex_subs, cell_pids))
72 {
73 auto cell = MakeCell(*raw_cell, cell_globl_id,
74 cell_pids[cell_globl_id], umesh_ptr_->GetVertices());
75
76 for (uint64_t vid : cell->vertex_ids_)
77 grid->vertices.Insert(vid, umesh_ptr_->GetVertices()[vid]);
78
79 grid->cells.push_back(std::move(cell));
80 }
81
82 ++cell_globl_id;
83 }//for raw_cell
84
85 grid->SetGlobalVertexCount(umesh_ptr_->GetVertices().size());
86
87 Chi::log.Log() << "Cells loaded.";
89
90 SetContinuum(grid);
91 SetGridAttributes(umesh_ptr_->GetMeshAttributes(),
92 {umesh_ptr_->GetMeshOptions().ortho_Nx,
93 umesh_ptr_->GetMeshOptions().ortho_Ny,
94 umesh_ptr_->GetMeshOptions().ortho_Nz});
95
96 //======================================== Concluding messages
98 << "### LOCATION[" << Chi::mpi.location_id
99 << "] amount of local cells="
100 << grid->local_cells.size();
101
102 size_t total_local_cells = grid->local_cells.size();
103 size_t total_global_cells = 0;
104
105 MPI_Allreduce(&total_local_cells,
106 &total_global_cells,
107 1,
108 MPI_UNSIGNED_LONG_LONG,
109 MPI_SUM,
110 Chi::mpi.comm);
111
112 Chi::log.Log()
113 << "VolumeMesherPredefinedUnpartitioned: Cells created = "
114 << total_global_cells
115 << std::endl;
116
117 umesh_ptr_ = nullptr;
118}
#define ChiLogicalErrorIf(condition, message)
static chi::Timer program_timer
Definition: chi_runtime.h:79
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 LogAllVerbose1()
Definition: chi_log.h:241
LogStream LogAllError()
Definition: chi_log.h:239
LogStream Log(LOG_LVL level=LOG_0)
Definition: chi_log.cc:35
static double GetMemoryUsageInMB()
Get current memory usage in Megabytes.
void Barrier() const
Definition: mpi_info.cc:38
const int & process_count
Total number of processes.
Definition: mpi_info.h:27
const int & location_id
Current process rank.
Definition: mpi_info.h:26
std::string GetTimeString() const
Definition: chi_timer.cc:38
static std::shared_ptr< MeshContinuum > New()
void SetContinuum(MeshContinuumPtr &grid)
void SetGridAttributes(MeshAttributes new_attribs, std::array< size_t, 3 > ortho_Nis={0, 0, 0})
VOLUME_MESHER_OPTIONS options
std::shared_ptr< const chi_mesh::UnpartitionedMesh > umesh_ptr_
static std::unique_ptr< chi_mesh::Cell > MakeCell(const chi_mesh::UnpartitionedMesh::LightWeightCell &raw_cell, uint64_t global_id, uint64_t partition_id, const std::vector< chi_mesh::Vector3 > &vertices)
static bool CellHasLocalScope(const chi_mesh::UnpartitionedMesh::LightWeightCell &lwcell, uint64_t cell_global_id, const std::vector< std::set< uint64_t > > &vertex_subscriptions, const std::vector< int64_t > &cell_partition_ids)
static std::vector< int64_t > KBA(const chi_mesh::UnpartitionedMesh &umesh)