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

Mesh blocks: generated meshes, HDF5 mesh files. More...

#include "mesh_block.h"
#include <algorithm>
#include <cmath>
#include <filesystem>
#include <stdexcept>
#include <Kokkos_Core.hpp>
#include "comm.h"
#include "input.h"
#include "hdf5_util.h"

Functions

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).
 
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.
 
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.
 
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.
 
bool is_hdf5_mesh (const std::string &filename)
 Whether a mesh file name denotes an HDF5 mesh file (.h5 or .hdf5).
 
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.
 
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.
 
void write_mesh_h5 (const std::string &, const MeshBlock &)
 Write the mesh whose blocks the ranks hold, in rank order, to an HDF5 mesh file (collective; several ranks need parallel HDF5).
 
MeshBlock read_mesh_h5 (const std::string &filename, bool)
 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).
 

Detailed Description

Mesh blocks: generated meshes, HDF5 mesh files.

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

◆ 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_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 
)

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