zoomy_core.mesh.distributed

zoomy_core.mesh.distributed#

Distributed meshes: each MPI rank holds its owned cells plus two halo layers and never the whole mesh, with cells numbered along a Hilbert (2D) or Morton (3D) space-filling curve. Backend-neutral (numpy, h5py, mpi4py); a backend adds the halo exchange and global reductions.

Module Contents#

Classes#

ArraySource

In-memory mesh (identical on every rank) renumbered on the fly; cell_ids / vertex_ids map the global numbering back to the mesh.

FileSource

Mesh file written by write_mesh; each read touches only the rows asked for.

Partition

One rank’s piece: local cells (owned, then halo layer 1, then 2) and the exchange lists; cells / vertices map local to the source’s numbering.

Functions#

curve_keys

Position along the space-filling curve of centres (dim, n) in the box lo..hi (Hilbert in 2D, Morton in 3D, x in 1D).

curve_order

Cell order along the space-filling curve through the centres (dim, n), ties by index.

cell_face_tags

(faces_per_cell, n_inner_cells) physical tag of each boundary face at its inner cell’s local face, -1 elsewhere.

partitioned

Arrays of mesh in the global numbering (cells along the curve, vertices by first appearance), built from the cells’ own faces so a periodic remap of boundary_face_cells does not enter.

write_mesh

Write mesh as a partition-ready mesh file (serial); use write_mesh_parallel for large meshes.

read_mesh

Read a mesh file as one serial BaseMesh.

source

FileSource for a path, ArraySource for a mesh.

write_mesh_parallel

Write the mesh file of write_mesh from pieces held by the ranks, no rank holding the whole mesh.

distribute

Build this rank’s local BaseMesh (owned cells, two halo layers, cut faces tagged halo) and its Partition. Periodic partners of owned cells join layer 1 and those of layer 1 join layer 2.

Data#

API#

zoomy_core.mesh.distributed.HALO#

‘halo’

zoomy_core.mesh.distributed.FORMAT_VERSION#

3

zoomy_core.mesh.distributed.curve_keys(centers, lo, hi)#

Position along the space-filling curve of centres (dim, n) in the box lo..hi (Hilbert in 2D, Morton in 3D, x in 1D).

zoomy_core.mesh.distributed.curve_order(centers)#

Cell order along the space-filling curve through the centres (dim, n), ties by index.

zoomy_core.mesh.distributed.cell_face_tags(mesh)#

(faces_per_cell, n_inner_cells) physical tag of each boundary face at its inner cell’s local face, -1 elsewhere.

zoomy_core.mesh.distributed.partitioned(mesh)#

Arrays of mesh in the global numbering (cells along the curve, vertices by first appearance), built from the cells’ own faces so a periodic remap of boundary_face_cells does not enter.

zoomy_core.mesh.distributed.write_mesh(mesh, path, cell_data=None)#

Write mesh as a partition-ready mesh file (serial); use write_mesh_parallel for large meshes.

Args

  • cell_data: {name: (n_cells,)} per-cell values in the mesh’s cell order.

zoomy_core.mesh.distributed.read_mesh(path)#

Read a mesh file as one serial BaseMesh.

class zoomy_core.mesh.distributed.ArraySource(mesh)#

In-memory mesh (identical on every rank) renumbered on the fly; cell_ids / vertex_ids map the global numbering back to the mesh.

Initialization

Renumber mesh into the global numbering.

is_file#

False

cells(ids)#

Vertex ids of the cells ids, (verts_per_cell, n).

face_tags(ids)#

Face tags of the cells ids, (faces_per_cell, n).

vertices(ids)#

Coordinates of the vertices ids, (dim, n).

periodic_partners(bcs)#

Periodic faces of bcs in the global numbering as (cell, slot, partner): face slot of cell takes partner’s state.

periodic_vertices(bcs)#

Seam vertex identification of bcs in the global vertex numbering, (canon, translations).

class zoomy_core.mesh.distributed.FileSource(path)#

Mesh file written by write_mesh; each read touches only the rows asked for.

Initialization

Open the mesh file at path; raises ValueError if it is not partition-ready.

is_file#

True

cell_data(name, ids)#

Per-cell values name of the cells ids.

cells(ids)#

Vertex ids of the cells ids, (verts_per_cell, n).

face_tags(ids)#

Face tags of the cells ids, (faces_per_cell, n).

vertices(ids)#

Coordinates of the vertices ids, (dim, n).

abstract periodic_partners(bcs)#

Not supported from a file; pass the mesh object instead.

periodic_vertices#

None

zoomy_core.mesh.distributed.source(mesh)#

FileSource for a path, ArraySource for a mesh.

zoomy_core.mesh.distributed.write_mesh_parallel(comm, path, mesh_type, X, v0, cv, c0, *, faces=None, face_tags=None, tag_names=None, default_tag=0, cell_data=None)#

Write the mesh file of write_mesh from pieces held by the ranks, no rank holding the whole mesh.

Args

  • X: this rank’s vertices (dim, n), ids v0, v0 + 1, ... in contiguous rank-ordered blocks.

  • cv: this rank’s cells (verts_per_cell, n) with global vertex ids, ids c0, c0 + 1, ....

  • faces: boundary elements (verts_per_face, n) with face_tags (any rank); untagged boundary faces get default_tag.

  • cell_data: {name: (n,)} of this rank’s cells.

class zoomy_core.mesh.distributed.Partition(comm, src, offsets, gids, n_own, n_ring, vids, send, recv, periodic=None, periodic_ids=None)#

One rank’s piece: local cells (owned, then halo layer 1, then 2) and the exchange lists; cells / vertices map local to the source’s numbering.

Initialization

Store the rank’s cells, vertices, exchange lists and periodic data, and clone comm for host-side collectives.

gather(X, root=0)#

Owned columns of X (rows, local cells) from every rank in the source’s cell order, on root (None elsewhere).

scatter(X_global)#

Local columns (owned plus halo) of a global (rows, cells) array.

sum_to_global(G_local, ids, n_global)#

Sum local contributions per global index over all copies on all ranks, i.e. the derivative with respect to a global quantity every rank holds copies of.

Args

  • ids: global index of each local column (self.vertices, self.cells), or None for replicated parameters.

resolve_periodic(local_mesh)#

Point every periodic face whose partner cell this piece holds at the partner’s halo copy.

check(local_mesh)#

Raise if a cut face touches an owned or first-layer cell, i.e. the halo is too thin.

parallel_io()#

Whether each rank can write its own block (mesh-file source and h5py with MPI).

write_mesh(path, names=None)#

Write the output file’s /mesh (each rank its share of the input blocks) and the field names.

write_fields(path, i, time, Q, Qaux)#

Write snapshot i, each rank its owned columns of Q and Qaux.

zoomy_core.mesh.distributed.distribute(src, comm, bcs=None)#

Build this rank’s local BaseMesh (owned cells, two halo layers, cut faces tagged halo) and its Partition. Periodic partners of owned cells join layer 1 and those of layer 1 join layer 2.

Args

  • src: ArraySource, FileSource, mesh or path.

  • bcs: boundary conditions; their Periodic entries are paired across ranks.

Returns

(local_mesh, partition).