Mallard 0.8.0
Unstructured, GPU accelerated, high-order finite volume CFD solver
Mallard website
Loading...
Searching...
No Matches
distributed_mesh.h
Go to the documentation of this file.
1
12#ifndef DISTRIBUTED_MESH_H
13#define DISTRIBUTED_MESH_H
14
15#include <array>
16#include <cstdint>
17#include <memory>
18#include <unordered_map>
19#include <unordered_set>
20#include <vector>
21
22#include "distribution.h"
23#include "mesh_block.h"
24#include "periodic.h"
25
26class Mesh;
27
51 public:
53 using PeriodicMap = std::unordered_map<uint64_t, std::pair<uint64_t, std::array<int8_t, 3>>>;
54
59 explicit DistributedMesh(MeshBlock block, const std::vector<Mesh::PeriodicPair> & periodic = {});
60
61 uint64_t n_global_cells() const { return cell_dist.back(); }
62 uint64_t first_cell() const { return block.first_cell; }
63 uint32_t n_block_cells() const { return static_cast<uint32_t>(block.n_cells()); }
64
66 const std::vector<uint64_t> & cell_distribution() const { return cell_dist; }
67
69 const std::vector<uint64_t> & graph_offsets() const { return graph_offsets_; }
70 const std::vector<uint64_t> & graph_neighbors() const { return graph_neighbors_; }
71
73 const PeriodicMap & block_periodic_classes() const { return block_periodic; }
74
76 const MeshBlock & mesh_block() const { return block; }
77
79 std::vector<std::array<double, N_DIM>> block_cell_centers() const;
80
82 void distribute(const std::vector<int> & owner);
83
91 std::shared_ptr<Mesh> build_local_mesh(int halo_layers, Distribution & dist);
92
93 private:
95 struct Cells {
96 std::vector<uint64_t> gid;
97 std::vector<int> owner;
98 std::vector<uint8_t> layer;
99 std::vector<uint64_t> node_offsets{0}, nodes; // global node ids
100 std::vector<uint32_t> boundary_offsets{0};
101 std::vector<std::array<uint32_t, 2>> boundary; // (local face, zone)
102 PeriodicMap periodic; // classes of their periodic nodes
103 };
104
112 void match_periodic(const std::vector<Mesh::PeriodicPair> & pairs);
113
115 const std::pair<uint64_t, std::array<int8_t, 3>> * periodic_class(uint64_t g) const;
116
118 uint64_t node_key(uint64_t g) const;
119
120 size_t rank_of_cell(uint64_t g) const;
121 size_t rank_of_node(uint64_t g) const;
122 void append_record(std::vector<uint64_t> & out, uint32_t i) const;
123 void read_records(const std::vector<uint64_t> & in, uint8_t layer);
124 std::vector<std::array<double, N_DIM>> fetch_nodes(const std::vector<uint64_t> & sorted_ids) const;
125 void grow_layer();
126
127 MeshBlock block;
128 std::vector<uint64_t> cell_dist, node_dist;
129 std::vector<std::string> zones; // the block's zones, then "unassigned"
130 PeriodicNodes periodic_classes; // translations and zones only
131 PeriodicMap block_periodic; // classes of the periodic nodes of the block's cells and faces
132 std::vector<uint64_t> graph_offsets_, graph_neighbors_;
133 std::vector<uint32_t> boundary_offsets{0};
134 std::vector<std::array<uint32_t, 2>> boundary; // per block cell: (local face, zone)
135
136 // After distribute()
137 std::vector<int> owner; // per block cell
138 std::vector<uint64_t> directory_offsets{0}; // per block node: cells using it (by node key)
139 std::vector<std::pair<uint64_t, int>> directory; // (cell, owner)
140 Cells cells;
141 std::unordered_map<uint64_t, uint32_t> halo_index; // halo cell -> index in cells
142 std::vector<uint64_t> owned_nodes; // keys of the owned cells' nodes, sorted
143 std::unordered_set<uint64_t> searched_nodes; // halo nodes whose cells are all here
144 std::vector<std::pair<uint64_t, int>> next_layer; // layer 1, found by distribute()
145 int layers = 0;
146};
147
148#endif // DISTRIBUTED_MESH_H
The mesh during setup, spread over the ranks. Each rank starts from its block of the mesh (cells,...
Definition distributed_mesh.h:50
std::vector< std::array< double, N_DIM > > block_cell_centers() const
Vertex average of every block cell (collective).
Definition distributed_mesh.cpp:541
std::unordered_map< uint64_t, std::pair< uint64_t, std::array< int8_t, 3 > > > PeriodicMap
Periodic node -> (key, lattice offset), as in PeriodicNodes but by global id.
Definition distributed_mesh.h:53
const PeriodicMap & block_periodic_classes() const
Periodic classes of the periodic nodes of the block's cells and boundary faces, and no others.
Definition distributed_mesh.h:73
const std::vector< uint64_t > & graph_neighbors() const
Definition distributed_mesh.h:70
const std::vector< uint64_t > & cell_distribution() const
First block cell of every rank, and the total (ParMETIS vtxdist).
Definition distributed_mesh.h:66
void distribute(const std::vector< int > &owner)
Send every block cell to its owner rank, and drop the dual graph (collective).
Definition distributed_mesh.cpp:607
std::shared_ptr< Mesh > build_local_mesh(int halo_layers, Distribution &dist)
This rank's mesh: its owned cells in global order, then halo_layers layers of vertex neighbors,...
Definition distributed_mesh.cpp:729
uint32_t n_block_cells() const
Definition distributed_mesh.h:63
const std::vector< uint64_t > & graph_offsets() const
Dual graph of the block cells (cells sharing a face), by global id (CSR); until distribute().
Definition distributed_mesh.h:69
const MeshBlock & mesh_block() const
This rank's block of the mesh.
Definition distributed_mesh.h:76
uint64_t n_global_cells() const
Definition distributed_mesh.h:61
uint64_t first_cell() const
Definition distributed_mesh.h:62
Definition mesh.h:111
KOKKOS_INLINE_FUNCTION rtype dot(const rtype *a, const rtype *b)
Compute the dot product of two arrays.
Definition common_math.h:32
A rank's share of a distributed mesh: owned cells, halo layers and the halo exchange plan.
A rank's contiguous block of a mesh, by global id, and the sources that produce one: HDF5 mesh files,...
Identification of the nodes of periodic boundary zones.
Local numbering: owned cells first (in global order), then halo layer 1, 2, ... Every local cell keep...
Definition distribution.h:26
Contiguous ranges of a mesh's cells and nodes and a set of its boundary faces. Global ids are positio...
Definition mesh_block.h:35
uint64_t n_cells() const
Definition mesh_block.h:51
uint64_t first_cell
Definition mesh_block.h:36
Periodic classes of the mesh nodes: the translation of each lattice direction, and per node its key (...
Definition periodic.h:28
TableBatchT< Space > out
Definition teno_setup.cpp:681
Geometry< Space > g
Definition teno_setup.cpp:678