Mallard 0.8.0
Unstructured, GPU accelerated, high-order finite volume CFD solver
Mallard website
Loading...
Searching...
No Matches
mesh_block.h
Go to the documentation of this file.
1
13#ifndef MESH_BLOCK_H
14#define MESH_BLOCK_H
15
16#include <array>
17#include <cstdint>
18#include <string>
19#include <vector>
20
21#include <toml.hpp>
22
23#include "common_typedef.h"
24#include "mesh.h"
25
35struct MeshBlock {
38 std::vector<uint64_t> cell_offsets{0}; // CSR into cell_nodes
39 std::vector<uint64_t> cell_nodes;
40 std::vector<std::array<double, N_DIM>> node_coords;
41 std::vector<uint64_t> face_offsets{0}; // boundary faces, CSR into face_nodes
42 std::vector<uint64_t> face_nodes;
43 std::vector<uint32_t> face_zone; // index into zone_names
44 std::vector<std::string> zone_names; // every zone, on every rank
45 // High-order boundary faces: CSR per boundary face (empty if none at all)
46 // into the coordinates of all its nodes, corners first in Gmsh order;
47 // linear faces have none
48 std::vector<uint64_t> face_high_order_offsets;
49 std::vector<std::array<double, N_DIM>> face_high_order_nodes;
50
51 uint64_t n_cells() const { return cell_offsets.size() - 1; }
52 uint64_t n_nodes() const { return node_coords.size(); }
53 uint64_t n_faces() const { return face_offsets.size() - 1; }
54
55 template <typename Range>
56 void add_cell(const Range & nodes) {
57 cell_nodes.insert(cell_nodes.end(), std::begin(nodes), std::end(nodes));
58 cell_offsets.push_back(cell_nodes.size());
59 }
60 void add_cell(std::initializer_list<uint64_t> nodes) { add_cell<std::initializer_list<uint64_t>>(nodes); }
61
62 template <typename Range>
63 void add_face(const Range & nodes, uint32_t zone) {
64 face_nodes.insert(face_nodes.end(), std::begin(nodes), std::end(nodes));
65 face_offsets.push_back(face_nodes.size());
66 face_zone.push_back(zone);
67 }
68};
69
76
78Stretching mesh_stretching(const toml::value & input);
79
87 const Stretching & stretching = {});
88
95 MeshType kind, uint64_t first_cell, uint64_t end_cell,
96 uint64_t first_node, uint64_t end_node, const Stretching & stretching = {});
97
99std::array<uint64_t, 2> cartesian_3d_size(uint32_t nx, uint32_t ny, uint32_t nz, MeshType kind);
100
102std::array<rtype, 2> wedge_node(rtype x, rtype y, rtype Ly);
103
105inline uint64_t block_begin(uint64_t n, int r, int p) { return n * uint64_t(r) / uint64_t(p); }
106
114MeshBlock read_mesh_block(const toml::value & input);
115
117MeshBlock read_gmsh_block(const std::string & filename);
118
120bool is_hdf5_mesh(const std::string & filename);
121
123bool have_hdf5();
124
126bool have_parallel_hdf5();
127
133MeshBlock read_mesh_h5(const std::string & filename, bool whole = false);
134
139void write_mesh_h5(const std::string & filename, const MeshBlock & block);
140
141#endif // MESH_BLOCK_H
KOKKOS_INLINE_FUNCTION rtype dot(const rtype *a, const rtype *b)
Compute the dot product of two arrays.
Definition common_math.h:32
Typedefs for common types.
float rtype
Definition common_typedef.h:39
Mesh class declaration.
MeshType
Definition mesh.h:28
std::array< rtype, 3 > Stretching
Tanh stretching factor of each direction of a generated mesh, 0 for uniform spacing.
Definition mesh.h:62
MeshBlock cartesian_3d_block(uint32_t nx, uint32_t ny, uint32_t nz, rtype Lx, rtype Ly, rtype Lz, MeshType kind, uint64_t first_cell, uint64_t end_cell, uint64_t first_node, uint64_t end_node, const Stretching &stretching={})
A generated 3D box (see Mesh::init_cart_3d): the cells [first_cell, end_cell) and nodes [first_node,...
Definition mesh_block.cpp:149
std::array< uint64_t, 2 > cartesian_3d_size(uint32_t nx, uint32_t ny, uint32_t nz, MeshType kind)
Total cell and node counts of a generated 3D box.
Definition mesh_block.cpp:144
MeshBlock read_mesh_block(const toml::value &input)
This rank's block of the mesh described by the [mesh] table (collective): an HDF5 mesh file (....
Definition mesh_block.cpp:266
MeshBlock read_mesh_h5(const std::string &filename, bool whole=false)
Read this rank's block of an HDF5 mesh file (collective): cells, nodes and boundary faces split evenl...
Definition mesh_block.cpp:472
uint64_t block_begin(uint64_t n, int r, int p)
First element of block r of n elements split into p near-equal blocks.
Definition mesh_block.h:105
Stretching mesh_stretching(const toml::value &input)
[mesh] stretching: the tanh factor of each direction, 0 (uniform) if not given.
Definition mesh_block.cpp:43
bool is_hdf5_mesh(const std::string &filename)
Whether a mesh file name denotes an HDF5 mesh file (.h5 or .hdf5).
Definition mesh_block.cpp:261
void write_mesh_h5(const std::string &filename, const MeshBlock &block)
Write the mesh whose blocks the ranks hold, in rank order, to an HDF5 mesh file (collective; several ...
Definition mesh_block.cpp:468
bool have_parallel_hdf5()
Whether several ranks can write one HDF5 mesh file together.
Definition mesh_block.cpp:466
rtype stretched_coordinate(uint32_t i, uint32_t n, rtype L, rtype beta)
Node i of n along a side of length L of a generated mesh, clustered toward both ends by the tanh stre...
Definition mesh_block.cpp:36
MeshBlock read_gmsh_block(const std::string &filename)
This rank's block of a Gmsh file (every rank reads the whole file).
Definition mesh_io.cpp:626
std::array< rtype, 2 > wedge_node(rtype x, rtype y, rtype Ly)
Node (x, y) of the supersonic wedge mesh, moved from the box node (x, y).
Definition mesh_block.cpp:26
bool have_hdf5()
Whether this build reads and writes HDF5 mesh files.
Definition mesh_block.cpp:464
MeshBlock cartesian_2d_block(uint32_t nx, uint32_t ny, rtype Lx, rtype Ly, MeshType kind, int r, int p, const Stretching &stretching={})
Part r of p of a generated 2D mesh (cartesian, cartesian_tri or wedge): near-equal blocks of its cell...
Definition mesh_block.cpp:59
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
void add_cell(std::initializer_list< uint64_t > nodes)
Definition mesh_block.h:60
uint64_t n_faces() const
Definition mesh_block.h:53
std::vector< uint64_t > face_offsets
Definition mesh_block.h:41
std::vector< std::array< double, N_DIM > > face_high_order_nodes
Definition mesh_block.h:49
std::vector< uint64_t > face_nodes
Definition mesh_block.h:42
uint64_t n_cells() const
Definition mesh_block.h:51
uint64_t first_cell
Definition mesh_block.h:36
uint64_t first_node
Definition mesh_block.h:37
std::vector< uint64_t > face_high_order_offsets
Definition mesh_block.h:48
std::vector< uint64_t > cell_offsets
Definition mesh_block.h:38
std::vector< uint32_t > face_zone
Definition mesh_block.h:43
uint64_t n_nodes() const
Definition mesh_block.h:52
void add_face(const Range &nodes, uint32_t zone)
Definition mesh_block.h:63
std::vector< std::string > zone_names
Definition mesh_block.h:44
std::vector< uint64_t > cell_nodes
Definition mesh_block.h:39
std::vector< std::array< double, N_DIM > > node_coords
Definition mesh_block.h:40
void add_cell(const Range &nodes)
Definition mesh_block.h:56
uint8_t r
Definition teno_setup.cpp:687
uint8_t beta[teno::MAX_NK][3]
Definition teno_setup.cpp:315