Mallard 0.8.0
Unstructured, GPU accelerated, high-order finite volume CFD solver
Mallard website
Loading...
Searching...
No Matches
mesh_block.h File Reference

A rank's contiguous block of a mesh, by global id, and the sources that produce one: HDF5 mesh files, Gmsh files and generated meshes. More...

#include <array>
#include <cstdint>
#include <string>
#include <vector>
#include <toml.hpp>
#include "common_typedef.h"
#include "mesh.h"

Go to the source code of this file.

Classes

struct  MeshBlock
 Contiguous ranges of a mesh's cells and nodes and a set of its boundary faces. Global ids are positions in the whole mesh: cell first_cell + i is local cell i, node first_node + i local node i. Cells and boundary faces list global node ids; cell types follow from the node count (triangle 3, quadrilateral 4; tetrahedron 4, pyramid 5, prism 6, hexahedron 8; Gmsh/VTK node order). Concatenating the blocks of ranks 0, 1, ... gives the whole mesh. More...
 

Functions

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 stretching factor beta > 0: L / 2 (1 + tanh(beta (2 i / n - 1)) / tanh(beta)).
 
Stretching mesh_stretching (const toml::value &input)
 [mesh] stretching: the tanh factor of each direction, 0 (uniform) if not given.
 
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 cells and nodes, numbered as Mesh::init_cart, init_cart_tri and init_wedge number them, and the boundary faces of those cells.
 
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, end_node) in the global numbering of the whole box, and the boundary faces of those cells.
 
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.
 
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).
 
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.
 
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 (.h5), a Gmsh file, or a generated mesh. Generated meshes number cells and nodes exactly as Mesh::init. A Gmsh file is read whole by every rank, so large meshes should be converted to HDF5 first.
 
MeshBlock read_gmsh_block (const std::string &filename)
 This rank's block of a Gmsh file (every rank reads the whole file).
 
bool is_hdf5_mesh (const std::string &filename)
 Whether a mesh file name denotes an HDF5 mesh file (.h5 or .hdf5).
 
bool have_hdf5 ()
 Whether this build reads and writes HDF5 mesh files.
 
bool have_parallel_hdf5 ()
 Whether several ranks can write one HDF5 mesh file together.
 
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 evenly in global order. With whole, this rank reads the whole file on its own (not collective).
 
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 ranks need parallel HDF5).
 

Detailed Description

A rank's contiguous block of a mesh, by global id, and the sources that produce one: HDF5 mesh files, Gmsh files and generated meshes.

Author
Matthew Bonanni (mbona.nosp@m.nni0.nosp@m.01@gm.nosp@m.ail..nosp@m.com)
Version
0.4
Date
2026-10-02

Function Documentation

◆ block_begin()

uint64_t block_begin ( uint64_t  n,
int  r,
int  p 
)
inline

First element of block r of n elements split into p near-equal blocks.

◆ cartesian_2d_block()

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 cells and nodes, numbered as Mesh::init_cart, init_cart_tri and init_wedge number them, and the boundary faces of those cells.

◆ cartesian_3d_block()

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, end_node) in the global numbering of the whole box, and the boundary faces of those cells.

◆ cartesian_3d_size()

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.

◆ have_hdf5()

bool have_hdf5 ( )

Whether this build reads and writes HDF5 mesh files.

◆ have_parallel_hdf5()

bool have_parallel_hdf5 ( )

Whether several ranks can write one HDF5 mesh file together.

◆ is_hdf5_mesh()

bool is_hdf5_mesh ( const std::string &  filename)

Whether a mesh file name denotes an HDF5 mesh file (.h5 or .hdf5).

◆ mesh_stretching()

Stretching mesh_stretching ( const toml::value &  input)

[mesh] stretching: the tanh factor of each direction, 0 (uniform) if not given.

◆ read_gmsh_block()

MeshBlock read_gmsh_block ( const std::string &  filename)

This rank's block of a Gmsh file (every rank reads the whole file).

◆ read_mesh_block()

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 (.h5), a Gmsh file, or a generated mesh. Generated meshes number cells and nodes exactly as Mesh::init. A Gmsh file is read whole by every rank, so large meshes should be converted to HDF5 first.

◆ read_mesh_h5()

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 evenly in global order. With whole, this rank reads the whole file on its own (not collective).

◆ stretched_coordinate()

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 stretching factor beta > 0: L / 2 (1 + tanh(beta (2 i / n - 1)) / tanh(beta)).

◆ wedge_node()

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).

◆ write_mesh_h5()

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 ranks need parallel HDF5).