Chi-Tech
MeshGenerator.h
Go to the documentation of this file.
1#ifndef CHITECH_MESHGENERATOR_H
2#define CHITECH_MESHGENERATOR_H
3
4#include "ChiObject.h"
6
7namespace chi
8{
9class GraphPartitioner;
10}
11
12namespace chi_mesh
13{
14
15class MeshContinuum;
16
17/** Mesh generation can be very complicated in parallel. Some mesh formats
18 * do not store connectivity information and therefore we have to establish
19 * connectivity after the file is read. Most mesh formats are also not
20 * partitioned for multiple processors when read/generated. The design of these
21 * types of objects need to consider the previous generation of how we did this.
22 * We had the concept of a VolumeMesher, which essentially took an
23 * `UnpartitionedMesh` and converted it into a partitioned mesh (i.e. the
24 * required `MeshContinuum` object). Up to now we've really only had two
25 * variants. The `VolumeMesherPredefinedUnpartitioned` and the
26 * `VolumeMesherExtruder`. Both of which operated on an `UnpartitionedMesh`
27 * object. With this new design we want to unify these concepts to make them
28 * more extendable and therefore we split a `MeshGenerator`'s execution into a
29 * phase that generates an unpartitioned mesh and a phase that then converts
30 * this mesh into real mesh (with both steps customizable). The phase that
31 * creates the real mesh can be hooked up to a partitioner that can also be
32 * designed to be pluggable.
33 * */
35{
36public:
37 /**Final execution step. */
38 virtual void Execute();
39
41 explicit MeshGenerator(const chi::InputParameters& params);
42
43 /**Virtual method to generate the unpartitioned mesh for the next step.*/
44 virtual std::unique_ptr<UnpartitionedMesh>
45 GenerateUnpartitionedMesh(std::unique_ptr<UnpartitionedMesh> input_umesh);
46
48 {
49 virtual const chi_mesh::Vertex& at(uint64_t vid) const = 0;
50 };
51 template <typename T>
53 {
54 explicit STLVertexListHelper(const T& list) : list_(list) {}
55 const chi_mesh::Vertex& at(uint64_t vid) const override
56 {
57 return list_.at(vid);
58 };
59 const T& list_;
60 };
61
62protected:
63 // 01
64 /**Builds a cell-graph and executes the partitioner that assigns cell
65 * partition ids based on the supplied number of partitions.*/
66 std::vector<int64_t> PartitionMesh(const UnpartitionedMesh& input_umesh,
67 int num_partitions);
68
69 /**Executes the partitioner and configures the mesh as a real mesh.*/
70 std::shared_ptr<MeshContinuum>
71 SetupMesh(std::unique_ptr<UnpartitionedMesh> input_umesh_ptr,
72 const std::vector<int64_t>& cell_pids);
73
74 // 02 utils
75 /**Broadcasts PIDs to other locations.*/
76
77 static void BroadcastPIDs(std::vector<int64_t>& cell_pids,
78 int root,
79 MPI_Comm communicator);
80 /**Determines if a cells needs to be included as a ghost or as a local cell.*/
81 bool
82 CellHasLocalScope(int location_id,
84 uint64_t cell_global_id,
85 const std::vector<std::set<uint64_t>>& vertex_subscriptions,
86 const std::vector<int64_t>& cell_partition_ids) const;
87
88 /**Converts a light-weight cell to a real cell.*/
89 static std::unique_ptr<chi_mesh::Cell>
91 uint64_t global_id,
92 uint64_t partition_id,
93 const VertexListHelper& vertices);
94
96 MeshAttributes new_attribs,
97 std::array<size_t, 3> ortho_cells_per_dimension);
98
99 static void ComputeAndPrintStats(const chi_mesh::MeshContinuum& grid) ;
100
101 const double scale_;
102 const bool replicated_;
103 std::vector<MeshGenerator*> inputs_;
105};
106
107} // namespace chi_mesh
108
109#endif // CHITECH_MESHGENERATOR_H
virtual void Execute()
bool CellHasLocalScope(int location_id, 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) const
std::shared_ptr< MeshContinuum > SetupMesh(std::unique_ptr< UnpartitionedMesh > input_umesh_ptr, const std::vector< int64_t > &cell_pids)
chi::GraphPartitioner * partitioner_
MeshGenerator(const chi::InputParameters &params)
static void ComputeAndPrintStats(const chi_mesh::MeshContinuum &grid)
static void BroadcastPIDs(std::vector< int64_t > &cell_pids, int root, MPI_Comm communicator)
static void SetGridAttributes(chi_mesh::MeshContinuum &grid, MeshAttributes new_attribs, std::array< size_t, 3 > ortho_cells_per_dimension)
std::vector< MeshGenerator * > inputs_
static std::unique_ptr< chi_mesh::Cell > SetupCell(const UnpartitionedMesh::LightWeightCell &raw_cell, uint64_t global_id, uint64_t partition_id, const VertexListHelper &vertices)
std::vector< int64_t > PartitionMesh(const UnpartitionedMesh &input_umesh, int num_partitions)
virtual std::unique_ptr< UnpartitionedMesh > GenerateUnpartitionedMesh(std::unique_ptr< UnpartitionedMesh > input_umesh)
static chi::InputParameters GetInputParameters()
MeshAttributes
Definition: chi_mesh.h:70
const chi_mesh::Vertex & at(uint64_t vid) const override
Definition: MeshGenerator.h:55
virtual const chi_mesh::Vertex & at(uint64_t vid) const =0