Curved edges
Block edges are straight by default. Give an edge a shape when the geometry is curved: the arc of a cylinder, a bump in a channel wall, an airfoil surface. The shape describes the edge between its two corners, so it always ends exactly at the corners, and the interior of the block follows the curved edges by transfinite interpolation.
Edges are attached with QuadEdges in make_quad() and Quad
(named by the face they form), with CornerEdge in make_hexa() and
Hex, and with BlockMesh.add_edge() for edges shared by several
blocks.
import math
import torch
import phipict.meshing as pm
block = pm.make_quad(
[(0, 0), (2, 0), (0, 1), (2, 1)],
cells=(32, 16),
edges=pm.QuadEdges(y_minus=pm.Arc(through=(1.0, 0.15))), # a bump
)
In 2D, y_minus/y_plus run along x (from -x to +x), x_minus/
x_plus along y (from -y to +y); points of a shape are given in that
direction.
Shapes
Shape |
Use it for |
|---|---|
|
straight edges (the default) |
|
circular arcs, given by a point on the arc ( |
|
straight segments through interior points |
|
smooth curves through (or, for B-splines, near) interior points |
|
a densely sampled curve (e.g. from CAD), resampled with the grading |
|
given vertex positions, used as they are |
|
any curve given as a function |
around_origin = pm.Arc(center=(0.0, 0.0))
through_point = pm.Arc(through=(0.0, 1.0))
zigzag = pm.Polyline([(0.5, 0.1), (1.0, -0.1), (1.5, 0.1)])
smooth = pm.Spline([(0.5, 0.1), (1.0, -0.1), (1.5, 0.1)])
sine = pm.Parametric(
lambda t: torch.stack([2.0 * t, 0.1 * torch.sin(2 * math.pi * t)], dim=1)
)
Vertices are placed along the curve by arc length, so a grading distributes them along a curved edge as it would along a straight one.
Measured and precomputed surfaces
When the vertices of an edge are known, e.g. the points of an airfoil surface, use
Points: they become the vertices of the edge exactly, and their number
fixes the cell count of that axis (leave it at None). Sampled
instead treats the points as a curve and places the vertices with the grading:
t = torch.linspace(0.0, math.pi, 41, dtype=torch.float64)
surface = torch.stack([1.0 - torch.cos(t), 0.2 * torch.sin(t)], dim=1) # 41 points
over_surface = pm.make_quad(
[surface[0], surface[-1], (0.0, 1.0), (2.0, 1.0)],
cells=(None, 16), # 40 cells along x, from the points
grading=(None, pm.Simple(8.0)),
edges=pm.QuadEdges(y_minus=pm.Points(surface)),
)
resampled = pm.make_quad(
[surface[0], surface[-1], (0.0, 1.0), (2.0, 1.0)],
cells=(24, 16),
grading=(pm.Symmetric(3.0), pm.Simple(8.0)),
edges=pm.QuadEdges(y_minus=pm.Sampled(surface)),
)
Per-edge gradings
An Edge combines a shape with a grading of its own, overriding the
grading of its axis for that edge. This is needed when opposite edges of a block
must be distributed differently, e.g. an arc that meets a uniformly spaced ring
while the opposite edge meets a graded block:
transition = pm.make_quad(
[(0.35, -0.35), (1.5, -1.5), (0.35, 0.35), (1.5, 1.5)],
cells=(8, 16),
grading=(None, pm.Symmetric(2.0)), # +x edge: graded
edges=pm.QuadEdges(
x_minus=pm.Edge(pm.Arc(center=(0.0, 0.0)), pm.Uniform()), # arc: uniform
),
)
3D edges
In 3D, CornerEdge names an edge by its two corner indices (solver order,
i + 2j + 4k for the corner at (i, j, k)); the shape runs from the first to
the second:
corners = [(0, 0, 0), (1, 0, 0), (0, 1, 0), (1, 1, 0),
(0, 0, 1), (1, 0, 1), (0, 1, 1), (1, 1, 1)]
dome = pm.make_hexa(
corners,
cells=(8, 8, 8),
edges=[
pm.CornerEdge(4, 5, pm.Arc(through=(0.5, 0.0, 1.2))),
pm.CornerEdge(6, 7, pm.Arc(through=(0.5, 1.0, 1.2))),
],
)
Interior interpolation
The interior vertices follow from the edges by transfinite (Coons)
interpolation, as in blockMesh. For reproducing grids made with PICT’s
generate_grid_vertices_2D, 2D blocks can use its row interpolation instead:
pm.make_quad(..., interpolation=pm.Interpolation.PICT_ROWS). For the common cases
(at most one curved edge per pair of opposite edges) both give the same vertices.
API
Shapes of block edges.
As in blockMesh, a shape describes an edge between two given end points, so the end points always coincide with the block corners:
pm.Arc(center=(0, 0)) # circular arc around the origin
pm.Arc(through=(0.7, 0.7)) # circular arc through a point
pm.Polyline([(1, 0.2), (2, 0.1)]) # straight segments via interior points
pm.Spline([(1, 0.2), (2, 0.1)]) # Catmull-Rom spline via interior points
pm.Parametric(lambda t: ...) # any curve c(t), t in [0, 1]
pm.Points(surface) # given vertex positions, used as they are
The vertices along an edge are placed by arc length, so a grading distributes
them along the curve as it would along a straight edge. Points is the
exception: it fixes the vertices themselves, e.g. those of a measured or
precomputed surface, and with them the number of cells of the edge.
- class phipict.meshing.curves.Arc(*, through: Sequence[float] | Tensor | None = None, center: Sequence[float] | Tensor | None = None)[source]
Circular arc, given by a point on it or by its centre.
With
through, the arc passes through that point (blockMesharc). Withcenter(blockMesharc ... origin), the arc runs around the centre the short way; if the end points have different distances to it, the radius changes linearly with the angle.- through
A point on the arc between its end points.
- Type:
torch.Tensor or None
- center
Centre of the arc.
- Type:
torch.Tensor or None
- class phipict.meshing.curves.BSpline(points: Sequence[Sequence[float] | Tensor] | Tensor)[source]
Cubic B-spline with interior control points (blockMesh
BSpline).The curve passes through the end points but, unlike
Spline, only approaches the interior points.- points
Interior control points
[n, dims], without the end points.- Type:
- reversed() EdgeShape[source]
See
EdgeShape.reversed().
- class phipict.meshing.curves.EdgeShape[source]
Shape of an edge between two end points.
- abstractmethod evaluate(start: Tensor, end: Tensor, t: Tensor) Tensor[source]
Points at curve parameters
tin [0, 1] (not arc length).
- reversed() EdgeShape[source]
The same edge traversed from its end to its start.
- sample(start: Tensor, end: Tensor, weights: Tensor) Tensor[source]
Points along the edge at normalised arc lengths.
- Parameters:
start (torch.Tensor) – End points of the edge, shape
[dims].end (torch.Tensor) – End points of the edge, shape
[dims].weights (torch.Tensor) – Normalised arc lengths from 0 to 1, shape
[n].
- Returns:
Points of shape
[n, dims]; the first and last are exactlystartandendwhen the weights span [0, 1].- Return type:
- class phipict.meshing.curves.Line[source]
Straight edge, the default.
- class phipict.meshing.curves.Parametric(fn: Callable[[Tensor], Tensor])[source]
A curve given as a function of a parameter in [0, 1].
- fn
Maps parameters
tof shape[n]to points[n, dims].fn(0)andfn(1)must match the edge’s end points (within a small tolerance).- Type:
Callable
- reversed() EdgeShape[source]
See
EdgeShape.reversed().
- class phipict.meshing.curves.Points(points: Sequence[Sequence[float] | Tensor] | Tensor)[source]
The vertices of an edge, given explicitly and used as they are.
Unlike the other shapes, the points are not resampled: they are the edge’s vertices, so they fix its number of cells (
len(points) - 1) and its vertex distribution. A grading of the edge is ignored. UseSampledto resample a curve with a grading instead.- points
Vertices
[n, dims]from the start to the end of the edge. The end points must coincide with the edge’s corners (within a small tolerance).- Type:
- property cells: int
Number of cells of the edge.
- check_ends(start: Tensor, end: Tensor) None[source]
Raise if the end points do not coincide with
start/end.
- reversed() EdgeShape[source]
See
EdgeShape.reversed().
- class phipict.meshing.curves.Polyline(points: Sequence[Sequence[float] | Tensor] | Tensor)[source]
Straight segments through interior points (blockMesh
polyLine).- points
Interior points
[n, dims], without the end points.- Type:
- reversed() EdgeShape[source]
See
EdgeShape.reversed().
- class phipict.meshing.curves.Sampled(points: Sequence[Sequence[float] | Tensor] | Tensor)[source]
A densely sampled curve, e.g. an airfoil surface, including its end points.
The first and last points must coincide with the edge’s end points (within a small tolerance) and are replaced by them.
- points
Points
[n, dims]along the curve, end points included.- Type:
- reversed() EdgeShape[source]
See
EdgeShape.reversed().
- class phipict.meshing.curves.Spline(points: Sequence[Sequence[float] | Tensor] | Tensor)[source]
Catmull-Rom spline through interior points (blockMesh
spline).- points
Interior points
[n, dims], without the end points.- Type:
- reversed() EdgeShape[source]
See
EdgeShape.reversed().
- class phipict.meshing.Edge(shape: EdgeShape = Line(), grading: Grading | float | int | None = None)[source]
An edge with its own shape and/or grading.
- shape
Shape of the edge. Default is straight.
- Type:
EdgeShape
- grading
Distribution of the edge’s vertices, overriding the grading of its axis. Default is None (the axis grading).
- Type:
Grading or float or None
- class phipict.meshing.QuadEdges(x_minus: Edge | EdgeShape | None = None, x_plus: Edge | EdgeShape | None = None, y_minus: Edge | EdgeShape | None = None, y_plus: Edge | EdgeShape | None = None)[source]
The four edges of a 2D block, named by the face they form.
y_minus/y_plusrun along x (from-xto+x),x_minus/x_plusalong y (from-yto+y); shapes and points are given in that direction.
- class phipict.meshing.CornerEdge(start: int, end: int, edge: Edge | EdgeShape)[source]
An edge of a 3D block between two of its corners.
- start, end
Corner indices in the solver order (
i + 2 j + 4 kfor the corner at(x, y, z) = (i, j, k)); the corners must differ along one axis.- Type:
- edge
The edge, given from
starttoend.- Type:
Edge or EdgeShape