Connections and periodicity

Blocks are connected wherever their faces coincide, in any orientation, so you usually do nothing: place the blocks so that neighbouring faces share their vertices and the Mesh connects them. This page is for the cases where you need more: periodic boundaries, faces that should connect but do not, and explicit connections.

How faces are matched

Mesh.auto_connect() (called by the Mesh constructor and BlockMesh.build()) looks at every face that has no patch and no connection:

  1. Faces whose corners coincide are candidates.

  2. For each candidate pair, every relative orientation of the in-face axes is tried (2 in 2D; 8 in 3D: swapped or not, each axis flipped or not). The pair is connected if all vertices coincide under one of them, within rel_tol times the smallest vertex spacing of the faces.

  3. The result is a Connection, from which Connection.axis_codes() derives the face and axis codes of the solver’s Block.ConnectBlock, which you therefore never write yourself.

import phipict.meshing as pm
from phipict import Face

a = pm.make_box((0, 0), (1, 1), cells=(4, 4), name="a")
# the same neighbour, but with its vertex order reversed along both axes
b = pm.make_box((1, 0), (2, 1), cells=(4, 4), name="b").flip("x").flip("y")
mesh = pm.Mesh([a, b])
(c,) = mesh.connections
print(c.face_a.name, c.face_b.name, c.axis_codes(2))
# X_PLUS X_PLUS (3, -1): y of b, running the other way

Every relative orientation gives the same flow: the test suite checks the solver result of a two-block channel for all 4 orientations in 2D and all 24 in 3D.

Faces that do not match

A face that shares its corners with another face but not its vertices is a modelling error: the blocks have different resolutions or gradings along the interface. The solver cannot connect such faces, so this raises NonConformingInterfaceError with the blocks and the reason:

coarse = pm.make_box((0, 0), (1, 1), cells=(4, 4), name="coarse")
fine = pm.make_box((1, 0), (2, 1), cells=(4, 6), name="fine")
try:
    pm.Mesh([coarse, fine])
except pm.NonConformingInterfaceError as err:
    print(err)
# Face X_PLUS of block 'coarse' and face X_MINUS of block 'fine' share their
# corners but are not conforming: [4] vs [6] cells; match the resolutions ...

Faces that touch only partially are not connected and show up as free faces in Mesh.check(). Split a block (MeshBlock.split()) so that the faces match.

Periodicity

Mesh.make_periodic() connects free faces that coincide after a shift:

walls = pm.Patch("walls", pm.Wall())
fp = pm.FacePatches(y_minus=walls, y_plus=walls)
channel = pm.Mesh([
    pm.make_box((0, -1), (2, 1), cells=(8, 8), patches=fp, name="upstream"),
    pm.make_box((2, -1), (6, 1), cells=(16, 8), patches=fp, name="downstream"),
])
channel.make_periodic("x")               # over the full extent in x
# the same: channel.make_periodic(translation=(6.0, 0.0))

A periodic connection of a block with itself along one axis becomes Block.MakePeriodic; all others (as between upstream and downstream here) become ConnectBlock calls. Mesh.extrude() makes the extruded mesh periodic in z unless patches for the z faces are given, and BlockMesh.add_periodic() pairs two patches like OpenFOAM’s cyclic patches.

Explicit connections

Mesh.connect() connects two given faces. The orientation is still found from the geometry unless it is passed, so this is only needed for faces that do not coincide:

left = pm.make_box((0, 0), (1, 1), cells=(4, 4), name="left")
right = pm.make_box((1, 0), (2, 1), cells=(4, 4), name="right")
mesh = pm.Mesh([left, right], auto_connect=False)
mesh.connect("left", Face.X_PLUS, "right", Face.X_MINUS)

Tolerance

rel_tol (default 1e-4) is relative to the smallest vertex spacing of the faces, so it adapts to the resolution. Meshes from files with few significant digits may need a larger value: pm.Mesh(blocks, rel_tol=1e-3).

API

class phipict.meshing.Connection(block_a: int, face_a: Face, block_b: int, face_b: Face, orientation: Orientation, translation: tuple[float, ...] | None = None)[source]

A connection of face face_a of block block_a to a face of block_b.

block_a, block_b

Indices of the blocks in the mesh (may be equal).

Type:

int

face_a, face_b

The connected faces.

Type:

Face

orientation

Relative orientation of the faces.

Type:

Orientation

translation

Offset from face A to face B of a periodic connection, None for faces that coincide.

Type:

tuple of float or None

axis_codes(ndims: int) → tuple[int, int][source]

axis1/axis2 arguments of Block.ConnectBlock.

Each code is (axis of B) << 1 | inverted for the in-face axes of A in the solver’s order; the second is -1 in 2D.

property is_periodic_axis: bool

Whether this is the plain periodicity of one block along one axis.

class phipict.meshing.Orientation(perm: tuple[int, ...], flip: tuple[bool, ...])[source]

How the in-face axes of one face map onto those of another.

perm

perm[k]: the tangential axis slot of face B that slot k of face A runs along (slots in the order of tangential_axes()).

Type:

tuple of int

flip

flip[k]: whether slot k of A runs opposite to its partner in B.

Type:

tuple of bool

class phipict.meshing.NonConformingInterfaceError[source]

Two block faces touch but their vertices do not coincide.