dragonfly_sim.utils.mesh_io_utils

Mesh input: dolfinx meshes from XDMF files or from structured CGNS grids.

A structured multi-block CGNS grid of a 2D case is often stored as a 3D grid one cell thick in span (e.g. ONERA’s OAT15A grids). read_cgns_planar reads it with PyVista (VTK’s CGNS reader), keeps one span plane of every block as quadrilaterals, merges the nodes the blocks share, and finds the wall and far field edges from the CGNS boundary condition families. read_cgns_volume reads a 3D grid (e.g. the Simple Transonic Wing’s wing_vol_L*.cgns) into one hexahedral mesh the same way. cgns_to_dolfinx_mesh turns either into a distributed dolfinx mesh in memory: no intermediate file.

Boundary tags: load_dolfinx_mesh also reads the boundary facet tags a mesh file carries (an XDMF “Facet tags” grid, the physical groups of a gmsh .msh, the Wall and Farfield families of a planar CGNS grid) and stores them on the returned mesh with attach_facet_tags, where core/mesh_manager.py:Mesh finds them. They can define the wall and symmetry boundaries in place of a function of the facet midpoints (DG_windtunnel_model’s wall_tags and symmetry_tags).

Block interface nodes are merged by EXACT coordinate match, which holds for grids whose 1-to-1 interfaces were written point-matched (Pointwise exports are); a grid that needs a tolerance merge fails the boundary check below.

Attributes

_HEX_FACES

Functions

_block_hexes(nk, nj, ni, offset)

Hexes of an nk x nj x ni node block in dolfinx ordering (i fastest, then

_block_quads(nj, ni, offset)

Quads of an nj x ni node block in dolfinx ordering [(i,j), (i+1,j), (i,j+1), (i+1,j+1)].

_center_jacobians(points, hexes)

Jacobian determinants of the trilinear map at the cell centers, hexes in

_cgns_facet_tags(mesh, edge_sets, comm)

MeshTags of the facets of a planar CGNS mesh from node index pairs, one

_family_patch_lines(reader, family, plane_index)

Points of every boundary patch of family, cut at the span plane: a list

_hex_faces(hexes)

The six faces of every hex, as sorted node quadruples.

_plane_points(grid, plane_index)

Points of k-plane plane_index of a StructuredGrid, shape (nj, ni, 3).

_quad_edges(quads)

The four edges of every quad (dolfinx ordering), as sorted node pairs.

_read_msh(path, comm, tdim)

_read_xdmf(path, comm, mesh_name, facet_tags_name)

_signed_areas(points, quads)

Signed areas of quads in dolfinx ordering (positive: counterclockwise).

_xdmf_grid_names(path)

The names of the Grid nodes of an XDMF file (read by every rank).

attach_facet_tags(mesh, facet_tags[, tag_names])

Store boundary facet tags on a dolfinx mesh, where core/mesh_manager.py:Mesh

cgns_to_dolfinx_mesh(cgns_path[, comm, tdim])

A distributed dolfinx mesh from a structured CGNS grid: rank 0 reads it

load_dolfinx_mesh(path[, comm, mesh_name, tdim, ...])

A dolfinx mesh from an XDMF file (grid mesh_name), a gmsh .msh file or a

merge_structured_blocks(blocks)

Merge 2D structured node blocks into one quad mesh.

merge_structured_volume_blocks(blocks)

Merge 3D structured node blocks into one hexahedral mesh.

read_cgns_planar(cgns_path[, plane_index, ...])

Read a structured multi-block CGNS grid that is one cell thick (or planar)

read_cgns_volume(cgns_path[, interface_rel_tol])

Read a structured multi-block 3D CGNS grid into one hexahedral mesh. Serial.

Module Contents

dragonfly_sim.utils.mesh_io_utils._block_hexes(nk, nj, ni, offset)

Hexes of an nk x nj x ni node block in dolfinx ordering (i fastest, then j, then k: [(i,j,k), (i+1,j,k), (i,j+1,k), (i+1,j+1,k), the same at k+1]).

dragonfly_sim.utils.mesh_io_utils._block_quads(nj, ni, offset)

Quads of an nj x ni node block in dolfinx ordering [(i,j), (i+1,j), (i,j+1), (i+1,j+1)].

dragonfly_sim.utils.mesh_io_utils._center_jacobians(points, hexes)

Jacobian determinants of the trilinear map at the cell centers, hexes in dolfinx ordering (positive: right-handed; 8x the volume for a parallelepiped).

dragonfly_sim.utils.mesh_io_utils._cgns_facet_tags(mesh, edge_sets, comm)

MeshTags of the facets of a planar CGNS mesh from node index pairs, one array per tag value ({value: (n, 2) array on rank 0, empty elsewhere}); the pairs are in the input (merged-block) node numbering.

dragonfly_sim.utils.mesh_io_utils._family_patch_lines(reader, family, plane_index)

Points of every boundary patch of family, cut at the span plane: a list of (n, 3) arrays, one node line per patch, in order along the line.

dragonfly_sim.utils.mesh_io_utils._hex_faces(hexes)

The six faces of every hex, as sorted node quadruples.

dragonfly_sim.utils.mesh_io_utils._plane_points(grid, plane_index)

Points of k-plane plane_index of a StructuredGrid, shape (nj, ni, 3).

dragonfly_sim.utils.mesh_io_utils._quad_edges(quads)

The four edges of every quad (dolfinx ordering), as sorted node pairs.

dragonfly_sim.utils.mesh_io_utils._read_msh(path, comm, tdim)
dragonfly_sim.utils.mesh_io_utils._read_xdmf(path, comm, mesh_name, facet_tags_name)
dragonfly_sim.utils.mesh_io_utils._signed_areas(points, quads)

Signed areas of quads in dolfinx ordering (positive: counterclockwise).

dragonfly_sim.utils.mesh_io_utils._xdmf_grid_names(path)

The names of the Grid nodes of an XDMF file (read by every rank).

dragonfly_sim.utils.mesh_io_utils.attach_facet_tags(mesh, facet_tags, tag_names=None)

Store boundary facet tags on a dolfinx mesh, where core/mesh_manager.py:Mesh looks for them: mesh.facet_tags, a dolfinx MeshTags of the facets (or None), and mesh.facet_tag_names, a dict {name: tag value} of the tags that have a name (gmsh physical groups, CGNS families). Returns the mesh.

dragonfly_sim.utils.mesh_io_utils.cgns_to_dolfinx_mesh(cgns_path, comm=MPI.COMM_WORLD, tdim=2, **kwargs)

A distributed dolfinx mesh from a structured CGNS grid: rank 0 reads it and dolfinx partitions it, ghosting cells across shared facets as XDMFFile.read_mesh does (the interior-facet forms need it). Collective.

tdim=2: a grid one cell thick, reduced to quadrilaterals (read_cgns_planar, kwargs passed on). info holds chord, n_points, n_cells, n_raw_points, n_wall_edges and n_farfield_edges. tdim=3: a volume grid, as hexahedra (read_cgns_volume, kwargs passed on). info holds n_points, n_cells, n_raw_points, n_blocks and n_boundary_faces.

Returns (mesh, info), info being the same on every rank.

dragonfly_sim.utils.mesh_io_utils.load_dolfinx_mesh(path, comm=MPI.COMM_WORLD, mesh_name='mesh', tdim=2, facet_tags_name=None, **cgns_kwargs)

A dolfinx mesh from an XDMF file (grid mesh_name), a gmsh .msh file or a structured CGNS grid (cgns_to_dolfinx_mesh with tdim, cgns_kwargs passed on), by file extension. Returns (mesh, info); info is cgns_to_dolfinx_mesh’s dict, or {} for the others. Collective.

The boundary facet tags the file carries are stored on the mesh (attach_facet_tags): mesh.facet_tags is a MeshTags or None, mesh.facet_tag_names maps tag names to values where the format has names. XDMF: the grid named facet_tags_name (default: “Facet tags” if the file has it); .msh: the physical groups of facets, tdim being the mesh dimension; CGNS: the Wall (1) and Farfield (2) families of a planar grid, none for a volume grid.

dragonfly_sim.utils.mesh_io_utils.merge_structured_blocks(blocks)

Merge 2D structured node blocks into one quad mesh.

blocks: list of (nj, ni, 2) node arrays. Returns (points (N, 2), quads (M, 4) in dolfinx ordering, counterclockwise). Nodes shared by blocks are merged by exact coordinate match; a block whose (i, j) axes are left-handed has its quads flipped.

dragonfly_sim.utils.mesh_io_utils.merge_structured_volume_blocks(blocks)

Merge 3D structured node blocks into one hexahedral mesh.

blocks: list of (nk, nj, ni, 3) node arrays. Returns (points (N, 3), hexes (M, 8) in dolfinx ordering, right-handed). Nodes shared by blocks are merged by exact coordinate match; a block whose (i, j, k) axes are left-handed has its hexes mirrored in i.

dragonfly_sim.utils.mesh_io_utils.read_cgns_planar(cgns_path, plane_index=0, wall_family='Wall', farfield_family='Farfield', scale_to_chord=True)

Read a structured multi-block CGNS grid that is one cell thick (or planar) and reduce it to a 2D quadrilateral mesh. Serial.

plane_index: which span plane of every block to keep (0 or 1). The span direction is the coordinate axis that is constant on that plane; the other two, in ascending order, become (x, y) – an X-Z airfoil grid maps (X, Z) -> (x, y).

scale_to_chord: shift the points so the wall’s leading edge (its smallest x) is at x = 0 and scale them by 1 / chord, the wall’s x extent.

Returns a dict: points (N, 2), quads (M, 4) (dolfinx ordering, counterclockwise), wall_edges and farfield_edges (node index pairs), chord (in the file’s units), n_raw_points (before merging).

Raises ValueError if a cell has non-positive area, an edge has more than two cells, or the boundary edges are not exactly the wall and far field edges.

dragonfly_sim.utils.mesh_io_utils.read_cgns_volume(cgns_path, interface_rel_tol=1e-10)

Read a structured multi-block 3D CGNS grid into one hexahedral mesh. Serial.

The blocks’ nodes are merged by exact coordinate match (see merge_structured_volume_blocks), in the file’s units. The CGNS boundary conditions are not read – VTK skips BC_t types such as BCWallViscous and BCFarfield – so the solver finds its boundaries geometrically, as for an untagged XDMF mesh.

interface_rel_tol: two boundary faces whose centroids are closer than this times the grid’s bounding-box diagonal are an unmerged block interface.

Returns a dict: points (N, 3), hexes (M, 8) (dolfinx ordering, right-handed), boundary_faces (node index quadruples), n_raw_points (before merging), n_blocks.

Raises ValueError if a cell is inverted or degenerate at its center, a face has more than two cells, or block interfaces did not merge.

dragonfly_sim.utils.mesh_io_utils._HEX_FACES