Operators
FlowGeometries.Operators.AbstractBoundaryCondition — Type
AbstractBoundaryConditionHow the faces past the end of a bounded direction couple: Dirichlet or Neumann. A wrapping direction has no such face.
FlowGeometries.Operators.AbstractMaskPolicy — Type
AbstractMaskPolicyWhat apply_stencil! does at the edge of the active region: BlankMasked, ShiftWithinRun or ReduceInRun.
A type, like the image and reach conventions in Connectivity: which cells carry a number and which carry masked is visible in the call and fixed at compile time.
FlowGeometries.Operators.BlankMasked — Type
BlankMasked()Write masked at a cell that is inactive or whose stencil reads an inactive cell. The default, and the only policy that never invents a value: where the stencil cannot be formed from active data, there is no derivative.
Its cost is a dead band. Every active cell within nodes - 1 of a masked cell is blanked, so a five-point derivative loses two cells either side of every coastline.
FlowGeometries.Operators.ComponentNullspace — Type
ComponentNullspaceThe constants L annihilates, one per closed component: a connected component of the graph of faces of nonzero coefficient on which L·1 = 0. Component k's cells are the linear indices perm[offsets[k]:offsets[k+1]-1] and totals[k] its measure; full marks one closed component holding every active cell, which needs no perm. Kernels read perm, in the execution backend's memory; offsets and totals stay in host memory, read by the loop over components.
FlowGeometries.Operators.Dirichlet — Type
Dirichlet()A zero value one cell beyond the end of every bounded direction: an end face couples through its geometric area against that zero.
FlowGeometries.Operators.FaceMetrics — Type
FaceMetricsThe staggered metric of a grid under a boundary condition, built once by face_metrics and read by gradient!, divergence!, curl!, rotational_velocity!, to_faces!, to_centres! and laplacian_coefficients. Fields, each face array one per direction shaped by Grids.face_dims:
grid,boundary: what it describes;area_op: the area through which the operators couple across a face: its geometric area between two active cells, zero against an inactive one, and at the end of a bounded direction its geometric area underDirichlet()and zero underNeumann(); zero across a face of zero gap;area_flux: the area through which data crosses a face,area_opwith every bounded end open; the same array underDirichlet();gap: the physical distance between the two centres a face separates, and from its one centre to the face at the end of a bounded direction;edge: per rotation pair(a, b), over its corners, the length of the primal edge through the corner,∏of the physical cell widths along the other directions;(nothing,)in two directions, where it is one;corner: per rotation pair(a, b), over its corners, the areaμof the dual cell around the corner in the(a, b)plane, spanned by the four centres around it: on a rectilinear grid|h_a h_b Δξ_a Δξ_b|with the scale factors read at the corner andΔξthe coordinate distances between those centres;volume: each cell's measure as the region its faces bound, whichdivergence!divides the net flux by: the grid's measure, or where a sampling's quadrature weights stand in for it, the area between the cell's faces, a pole row's included;orientation: per directionσ = ±1, the sign of the coordinate's step along the index. A face value and a derivative alongdare taken along increasing coordinate, whichever way an axis is stored; on a curvilinear grid, whose directions have no coordinate of their own, along increasing index.
Every area, gap, edge length and corner area is nonnegative. A gap is zero between two centres at one point, as along a row of cells on a pole, and the face there has no area: every field the grid samples has one value at that point. Under Neumann() the two areas differ at the ends of bounded directions only, where data crosses and the operators do not couple.
An operator reads it in execution's memory: one held on the host is moved there for the call, and one moved once with Execution.on_backend is read as it is.
FlowGeometries.Operators.GradientPlan — Type
GradientPlanThe geometry of a least-squares gradient, separated from any field: for each cell, the coefficient on each neighbour's difference from it, once per coordinate direction. Built by gradient_plan, applied by gradient!.
The two index buffers are typed independently and hold any Integer, so a plan built off a CSR keeps that CSR's own types.
D is the number of directions the fit resolves, which is the grid's coordinate count: two on a surface — a (λ, φ) or (x, y) mesh — and three in a volume, where the neighbourhood spans a solid angle.
apply_stencil! covers the separable case. A CurvilinearGrid has no separable axis to build a scalar stencil along, and a node set's neighbours come from connectivity, so this is the gradient for both.
The construction, with tangent-plane displacements Δrₖ from Geometry.project_to_tangent_plane, differences Δfₖ = fₖ - f₀ and weights wₖ = 1/|Δrₖ|²: minimising Σₖ wₖ (∇f·Δrₖ - Δfₖ)² gives A ∇f = b with A = Σₖ wₖ Δrₖ⊗Δrₖ and b = Σₖ wₖ Δrₖ Δfₖ. A depends only on the geometry, so it is inverted once here and the per-neighbour coefficients A⁻¹ wₖ Δrₖ are what the plan stores; each apply is then one dot product per cell and allocates nothing.
The fit is:
- exact for a linear field on any stencil, however skewed, the least-squares combination cancelling the leading truncation term;
- second order on locally symmetric stencils, degrading toward first on strongly skewed cells;
- the centred difference where the stencil is separable and orthogonal (
Adiagonal), so it agrees withapply_stencil!where both apply.
Where A is rank deficient — a direction with no data, at a boundary or beside a mask — the pseudo-inverse zeroes that component, under the rule apply_stencil! states for a mask: a value the active data does not determine is not produced.
FlowGeometries.Operators.LaplacianCoefficients — Type
LaplacianCoefficients(grid, coef, measure)L on a Grids.FaceIndexedGrid as data: the face coefficients coef[d][F] = A_F/g_F, one array per direction shaped by Grids.face_dims, and the cell measures, zero on an inactive cell. Its fields:
grid,coef,measure;diag:(L e_I)_I, minus the sum of a cell's own face coefficients over its measure;total: the measure of the active cells;singular,nullspace: whetherLhas a null space, and theComponentNullspacespanning it.
laplacian_coefficients builds it from a FaceMetrics, galerkin_coefficients from a finer level. An operator reads it in execution's memory, as it reads a FaceMetrics.
FlowGeometries.Operators.MaskedStencilPlan — Type
MaskedStencilPlan{R,I,W}The order-th derivative weights of one direction of a masked grid, resolved per cell. row[J], over the mask's own axes, names the row of (indices, weights) cell J reads: the axis table's row J[dim] where its window holds only active cells, a row rebuilt over the cell's active run where the policy degrades it, and 0 where the cell is written masked. Rebuilt rows follow the table's n rows, each padded with zero weights to the table's width.
distance marks weights solved over the window's distances, per line, with no table rows: the form of an order ≥ 2 derivative along a direction whose own scale factor varies along it. mask is the mask the rows were resolved for; derivative! refuses a grid with another.
The apply is one gather per cell, with no mask test and no weight solve, so it runs the same on the host and in a kernel. Build one with masked_stencil_plan.
FlowGeometries.Operators.Neumann — Type
Neumann()No flux through the end of a bounded direction: an end face has no area in the operators.
FlowGeometries.Operators.ReduceInRun — Type
ReduceInRun()ShiftWithinRun, and where the run cannot hold nodes, use the largest window it can, down to order + 1 samples. masked below that, where no derivative of that order exists.
This trades accuracy order for coverage — a five-point scheme becomes three-point in a strait three cells wide — so it carries its own name. Ask for it when a value everywhere matters more than a uniform order.
Under this policy nodes is a ceiling, at the end of the axis as well as the end of a run: an axis with fewer than nodes samples uses as many as it has, and one with fewer than order + 1 is masked throughout. A single-latitude strip, a two-level column and a one-cell-wide channel are ordinary grids, and this asks for "second order where the axis allows it" with no clamping of nodes at the call site. The other two policies raise there, neither of them degrading.
FlowGeometries.Operators.SeparableMetrics — Type
SeparableMetrics()
DenseMetrics()How a face metric is held: as one factor per axis where it is a product of them, and as a full array elsewhere. metric_layout reads which from a grid's geometry and mask types.
FlowGeometries.Operators.ShiftWithinRun — Type
ShiftWithinRun()Shift the stencil to fit inside the run of active samples containing the cell, keeping the full node count — the same thing the stencil already does at the end of a bounded axis, with the end of the active run as the boundary. masked only where the run is shorter than nodes.
The accuracy order is therefore the same everywhere a value is written, as it is under Discretization.fd_weights's inward shift at a bounded end. On a run of at least nodes active samples the weights are identical to the unmasked ones, so the interior of an active region is bit-for-bit unchanged.
FlowGeometries.Operators.StencilPlans — Type
StencilPlans{N}The derivative weights of every direction of one structured grid, as stencil_plans builds them: what derivative! applies along each direction, and a derivative source for strain_rate!, curl! and divergence!.
FlowGeometries.Operators._CellFactors — Type
_CellFactors(geometry, coordinates, dim, order)The inverse metric factor of a derivative along dim, to the power order, evaluated at each cell's own point: the form for a geometry that declares no direction metric-invariant.
FlowGeometries.Operators._RowFactors — Type
_RowFactors(inv_h, size)The inverse metric factor of a derivative on a spatial grid of size, one per direction-1 run, in column-major order over directions 2:M: the form for a geometry that declares direction 1 metric-invariant, where one factor serves a whole run. A batch element repeats the R runs.
FlowGeometries.Discretization.axis_stencils — Method
Discretization.axis_stencils(grid, dim; order=1, nodes=order+1) -> (indices, weights)Discretization.axis_stencils for direction dim of grid, taking that direction's axis and wrap period from the grid.
The table depends on the grid alone, so a caller differencing many fields along the same direction builds it once and hands it to the (out, field, grid, indices, weights, dim) form. The (out, field, grid, dim) form above rebuilds it on every call.
FlowGeometries.Discretization.stencil_plan — Method
Discretization.stencil_plan(grid, dim; order=1, nodes=order+1) -> AbstractStencilPlanDiscretization.stencil_plan for direction dim of grid, taking that direction's axis and wrap period from the grid.
The form to hold in a loop over fields. Which plan it is follows the axis's own spacing, so a uniform direction gets the register-resident weights and a stretched one the table.
FlowGeometries.Operators._bary_weights — Method
_bary_weights(grid, geo, p0, nearest, active_only) -> (a, b, c, (w₁, w₂, w₃))The cell of the grid's Grids.CellMesh containing p0, and the barycentric weights of p0 in it. a == 0 where there is none — outside the mesh, or against an inactive node.
The cells incident on nearest are tried first, and usually hold p0. They need not: a point near an edge can lie nearer the vertex across it than any of its own. From the best of them the search walks across the edge opposite the most negative weight, which ends at the containing cell on a Delaunay mesh, or at the mesh's boundary.
The weights are computed in the tangent plane at p0, where the three vertices sit at their Geometry.local_displacements and p0 itself is the origin.
FlowGeometries.Operators._derivative_factors — Method
_derivative_factors(grid, dim, backend, order) -> _RowFactors | _CellFactors | NothingThe inverse metric factor to the power order that derivative! writes each value along dim with: nothing for a Cartesian metric, which is the identity; one factor per direction-1 run for a geometry that declares direction 1 metric-invariant, placed where backend runs; the per-cell evaluation otherwise. At order ≥ 2 the power holds only where dim is one of the geometry's Geometry.scale_invariant_directions; _along_arc routes the rest.
FlowGeometries.Operators._mask_may_hide — Method
_mask_may_hide(grid, policy, active_only) -> BoolWhether the neighbourhood test has anything to find: under BlankMasked an active-only search may pass over an inactive cell nearer than the farthest active one it keeps. On an Grids.AllActive grid there is no inactive cell to pass over.
FlowGeometries.Operators._metric_row_factors! — Method
_metric_row_factors!(buf, grid, Val(dim), Val(N), order) -> IntWrite the inverse scale factor of every direction-1 run, to the power order, into buf, in column-major order over directions 2:N — the order the sweep writes them in, for any differenced direction. Returns how many.
Direction 1 is metric-invariant here, so one factor covers a whole run and any axis-1 coordinate serves as the point's first component. The other axes are read on the host.
A scale factor of zero, as at a pole, is stored as zero, and a kernel writes masked where its factor is zero.
FlowGeometries.Operators._metric_scratch — Method
_metric_scratch(T, n) -> Vector{T}A task-held buffer of at least n factors, as Connectivity.ball_scratch is for a ball query.
It is filled before a sweep and only read during one, threaded chunks included, so one buffer per task is enough; it grows to the largest grid the task has swept and is refilled per call.
FlowGeometries.Operators._nodecount — Method
_nodecount(nodes) -> IntThe node count, from either a Val or a plain Int.
One body then serves both. With a Val the trip count is a literal, so the loop unrolls and the weights reach registers; with an Int, the form a node count above the specialized set takes, it is an ordinary loop.
FlowGeometries.Operators._plan_sweep_host! — Method
_plan_sweep_host!(out, field, plan, mask, masked, Val(dim), Val(N), Val(M), fac, backend, nodes) -> outThe host sweep for a plan. Same nest as _stencil_sweep_host! — Cartesian range walked directly, nest split at dim, nodes the node count as _dispatch_nodes gives it — with the interior rows read at fixed offsets and the end rows from the plan's own rows.
fac is the metric factor each value is written with — see _RowFactors — or nothing for the plain sweep. Under backend a chunk is a contiguous range of cells, as for the table sweep.
FlowGeometries.Operators._stencil_sweep_host! — Method
_stencil_sweep_host!(out, field, indices, weights, mask, masked, Val(dim), nodes, Val(N),
Val(M), invh, R) -> outThe host sweep. The index-parallel form serves a device launch; this one adds three things a per-work-item body cannot express:
- iterate the Cartesian range directly, with no index recovered per cell from a linear one;
- split the nest at
dim, hoisting the stencil row — which depends only on the index alongdim— out of the contiguous inner loop wherever the differenced direction is a slower-varying one; - carry the node count in the type, so the innermost loop has a known trip count, unrolls, and holds the weights in registers.
The arithmetic and its order are identical to _stencil_cell!, so the two paths agree bit for bit.
fac is the metric factor each value is written with — see _RowFactors — or nothing for the plain sweep. Under backend a chunk is a contiguous range of cells, written in place, so a threaded or distributed sweep is this nest over each chunk's share. dg is the degrading policy's recipe for a cell whose window reads an inactive sample, or nothing to write masked there; scratch its buffers under a serial backend.
FlowGeometries.Operators._sym_eigvals3 — Method
_sym_eigvals3(A, tol) -> (λ₁, λ₂, λ₃)Eigenvalues of a symmetric 3×3, largest first, by the closed form for the characteristic cubic: shift by the mean eigenvalue, scale, and read the three roots off cos at thirds of a turn.
Eigenvalues only. A closed-form eigenvector of a 3×3 loses accuracy when two eigenvalues are close, and _sympinv3 needs none: a pseudo-inverse of a symmetric matrix is a polynomial in that matrix, and its coefficients are functions of the eigenvalues alone.
FlowGeometries.Operators._sympinv — Method
_sympinv(A::NTuple{D,NTuple{D,T}}, tol) -> NTuple{D,NTuple{D,T}}Pseudo-inverse of a symmetric positive-semidefinite A given as its rows, dropping any eigendirection whose eigenvalue is at or below tol. D = 2 and D = 3, which are the tangent plane and the volume.
A direction is dropped, never regularised — see _sympinv2, which this calls at D = 2.
FlowGeometries.Operators._sympinv2 — Method
_sympinv2(a, b, c, tol) -> (p11, p12, p22)Pseudo-inverse of the symmetric 2×2 [a b; b c], dropping any eigendirection whose eigenvalue is below tol. Closed form: a 2×2 symmetric eigenproblem has one.
A direction is dropped, never regularised. A stencil that carries no information along some tangent direction — every neighbour on one line, which happens at a boundary and beside a mask — leaves A singular there, and the data does not determine that component of the gradient. Inverting a nudged matrix answers with a number governed by the nudge.
FlowGeometries.Operators._sympinv3 — Method
_sympinv3(A, tol) -> NTuple{3,NTuple{3,T}}Pseudo-inverse of a symmetric positive-semidefinite 3×3.
At every rank A⁺ is a polynomial in A with no constant term, so this is closed form and needs no eigenvector. Such a polynomial annihilates the null space and acts as 1/λ on the range, which is the Moore–Penrose conditions:
- rank 3:
adj(A)/det(A), the ordinary inverse; - rank 2:
αA² + βAwithα = -(λ₁+λ₂)/(λ₁λ₂)²andβ = (λ₁² + λ₁λ₂ + λ₂²)/(λ₁λ₂)²; - rank 1:
A/λ₁², sinceA = λ₁vvᵀthere; - rank 0: zero.
FlowGeometries.Operators.allocate_faces — Method
allocate_faces(T, grid; execution = SerialBackend()) -> NTuple{N,AbstractArray{T,N}}
allocate_corners(T, grid; execution = SerialBackend()) -> NTuple{P,AbstractArray{T,N}}Zeroed face arrays, one per direction shaped by Grids.face_dims, and corner arrays, one per rotation_pairs pair shaped by Grids.corner_dims, in the memory execution's loops write.
FlowGeometries.Operators.apply_laplacian! — Method
apply_laplacian!(out, Φ, c::LaplacianCoefficients; execution = SerialBackend()) -> out
apply_laplacian!(f, out, Φ, c::LaplacianCoefficients; execution = SerialBackend()) -> outout = L Φ from the coefficients, zero on every inactive cell. A face past the end of a bounded direction contributes c·(0 − Φ_I), the zero ghost of Dirichlet; under Neumann its coefficient is zero. A nonzero coefficient into an inactive cell reads Φ there, which holds zero for an operator that pins it.
With f, out[I] = f(I, (L Φ)_I) on each active cell, I its CartesianIndex: the application and the cellwise step that reads it in one pass, as a relaxation sweep or a residual takes them. out is a different array from Φ, and f writes nothing a neighbouring cell's (L Φ) reads.
FlowGeometries.Operators.apply_stencil! — Method
apply_stencil!(out, field, grid, indices, weights, dim; order=1, active_only=true,
masked=zero, policy=BlankMasked(), execution=SerialBackend()) -> outApply a stencil table built by Discretization.axis_stencils. The mask, the wrap period and the axis all come from grid.
The axis coming too, any mask policy works here. The bare (indices, weights) form has no axis to rebuild a window from at a mask edge, so it accepts only BlankMasked.
This is the form to use in a loop over fields: the table is the same for all of them, and it is the one part of the work that depends on the grid alone.
FlowGeometries.Operators.apply_stencil! — Method
apply_stencil!(out, field, grid, dim; order=1, nodes=order+1, active_only=true, masked=zero) -> outapply_stencil! with the axis, wrap period and mask taken from grid, so a periodic direction wraps and an inactive cell is honoured without restating any of it.
Only a rectilinear direction has a 1-D axis to difference along, so this is a StructuredGrid method.
FlowGeometries.Operators.apply_stencil! — Method
apply_stencil!(out, field, x, indices, weights, dim; order=1, period=nothing, mask=nothing,
masked=zero, policy=BlankMasked(), execution=SerialBackend()) -> outApply a table built by Discretization.axis_stencils and keep the axis, so any mask policy works.
The table depends on the axis alone, so a caller differencing many fields along one direction builds it once. Degrading at a mask edge needs the axis to rebuild a window from, so the bare (indices, weights) form accepts only BlankMasked; this form takes both and serves every policy.
The split is the one the degrade path makes internally: the precomputed row is used wherever the window is intact, which is every cell away from a mask, and the axis is touched only where a window is rebuilt.
Building the table costs O(n · nodes²) for an axis of n samples, and holding it removes that and an O(n · nodes) allocation from every call.
FlowGeometries.Operators.apply_stencil! — Method
apply_stencil!(out, field, x, dim; order=1, nodes=order+1, period=nothing,
mask=nothing, masked=zero) -> out
apply_stencil!(out, field, indices, weights, dim; mask=nothing, masked=zero) -> outApply a weight set along direction dim of field, writing out[I] = Σ_q weights[I[dim], q] · field[…, indices[I[dim], q], …].
Every convention this needs is fixed by the package: the result sits at the same location as the input, so there is no staggering decision, and the stencil shifts inward at a bounded end and wraps on a periodic one, which is Discretization.fd_weights's stated boundary behaviour and removes the need for a halo. Operations that do take those choices live elsewhere — a staggered difference, or a multi-direction operator like a divergence or a curl, each of which needs a result location and a boundary-condition policy.
Pass the axis and an order to have the weights built for you, or precomputed indices/weights from Discretization.axis_stencils to reuse them across many fields.
With a mask, a cell is written as masked when it is inactive or when its stencil reads an inactive cell — the derivative there is not determined by the active data, so it is not invented. out and field may not alias.
FlowGeometries.Operators.apply_stencil! — Method
apply_stencil!(out, field, plan, dim; mask=nothing, masked=zero, execution=SerialBackend()) -> outApply a held Discretization.stencil_plan along direction dim of field.
The primary form: the weights are built once, so a caller differencing many fields along one direction pays for them once, and nothing is allocated per call. The (out, field, x, dim; order, nodes) forms build a plan and call this, which is where their allocation comes from.
mask and masked behave as they do for the table forms: a cell whose stencil reads an inactive cell is written masked.
FlowGeometries.Operators.apply_stencil! — Method
apply_stencil!(out, field, plan::MaskedStencilPlan; masked=zero, execution=SerialBackend()) -> outApply a held MaskedStencilPlan to field, which may carry trailing batch axes past the mask's. The plan is read in execution's memory: one held on the host is moved there for the call, and one moved there once with Execution.on_backend is read as it is.
FlowGeometries.Operators.coarse_coefficients — Method
coarse_coefficients(fine::LaplacianCoefficients, cgrid; ghost = nothing) -> LaplacianCoefficientsL rediscretized on cgrid, a coarsen of fine.grid: a coarse face's coefficient is the coupling area of the fine faces it covers over its own gap, Σ c_f g_f / g_c with the gaps of face_metrics, and an active coarse cell's measure the sum of its children's. The mask and the boundary condition reach the coarse level through the fine coefficients. Along a direction a uniform grid halves, this is half the galerkin_coefficients there, the factor by which the Galerkin operator of piecewise-constant transfers overstates the coarse one (Braess, Computing 55 (1995) 379–393).
A fine face that couples a cell to a zero keeps the zero where it is: across it the ratio is the fine cell's distance to the zero over the coarse cell's, along the direction's coordinate. The zero is an inactive fine cell beyond an inactive coarse one, or past a bounded end the fine grid's end face, or the coordinates ghost[d] = (below, above) where a condition holds its zeros off the end faces.
FlowGeometries.Operators.coarsen — Method
coarsen(grid; pinned = false) -> gridThe next grid down: along every direction of at least four cells, coarse cell i covers fine cells 2i − 1 and 2i (cell n alone for the last of an odd count), its centre their mean; a shorter direction keeps its cells, so a grid with no direction of four cells comes back with the same cells. A coarse cell is active where any fine cell it covers is, or with pinned = true where every one is: on an operator whose inactive cells hold zero through the coefficients that reach them, a coarse level then keeps that hold as a coefficient into an inactive coarse cell. Every coarse axis is a Vector, whatever the fine axis, so the grids below a given grid share one type.
On a Grids.CurvilinearGrid the coarse mesh keeps every other vertex line and the last one.
FlowGeometries.Operators.corner_mask — Method
corner_mask(fm::FaceMetrics, a, b) -> AbstractArray{Bool,N}The (a, b) corners in the complex: those whose four surrounding faces all couple, so a loop of active cells closes around them. On a Cartesian rectilinear grid with no inactive cell every corner does, every interior face having nonzero area, and the mask is Grids.AllActive; on a sphere a row of cells on a pole has faces of no area.
FlowGeometries.Operators.curl! — Method
curl!(ω, u, grid, derivs; masked = NaN, scratch = nothing, execution = SerialBackend()) -> ωThe curl of the vector field u on grid, its components along the local frame: one array ω in two directions — the vertical vorticity, d_λu_φ − d_φu_λ + u_λ tan φ/R on a sphere — and a tuple of three in three. derivs and the masking are as for strain_rate!; scratch is one array per direction.
FlowGeometries.Operators.curl! — Method
curl!(W, v, fm::FaceMetrics; execution = SerialBackend()) -> WW_ab = ∂_a v_b − ∂_b v_a on the (a, b) corners from face-normal velocity v, one array per rotation_pairs pair: the circulation σ_a Δ_a(v_b g_b) − σ_b Δ_b(v_a g_a) around the corner over the area μ of the dual cell it bounds, fm.corner. A corner is written where it is in the complex, corner_mask, and zero elsewhere.
FlowGeometries.Operators.curl — Method
curl(u, grid, derivs; masked = NaN, execution = SerialBackend())curl! into fresh arrays: one in two directions, three in three.
FlowGeometries.Operators.derivative! — Function
derivative!(out, field, grid, dim; order=1, nodes=order+1, policy=BlankMasked(),
masked=zero, active_only=true, execution=SerialBackend(), scratch=nothing) -> outThe derivative with respect to distance along direction dim: apply_stencil! divided by the metric factor,
∂f/∂sᵈ = (1/hᵈ) · ∂f/∂ξᵈ, hᵈ = Geometry.scale_factors(geo, p)[d]On a Cartesian metric every hᵈ is 1 and this is apply_stencil! exactly, at no cost. Anywhere else it is the derivative a physical law is written in, singular points included.
At order = p it is the p-th derivative with respect to distance. Along a direction in Geometry.scale_invariant_directions, where hᵈ is constant along the direction, that is (1/hᵈ)ᵖ·∂ᵖf/∂ξᵈᵖ. Elsewhere — a spheroid's latitude, where h_φ = M(φ) — the weights are solved over the nodes' distances from the cell, Geometry.line_distance.
Where the metric degenerates the derivative does not exist, and masked is written. Longitude at a pole is the case: h_λ = R cos φ is zero at a latitude of ±T(π)/2, the pole as stored, so 1/h_λ does not exist there.
Each value is multiplied by (1/hᵈ)ᵖ as it is written, so a cell written masked holds exactly masked. No scale factor in this package depends on longitude, so hᵈ is constant along the first axis whichever direction is differenced, and it is solved once per direction-1 run. (It is not generally constant along the differenced direction — on a spheroid h_φ = M(φ) varies with φ — so it is not hoisted that way.)
A divergence or a curl is still the caller's to assemble, needing a result location and a boundary policy this does not choose. Note the flux form when doing so: on a sphere
∇·u = (1/(R cos φ)) [ ∂u_λ/∂λ + ∂(u_φ cos φ)/∂φ ]so the second term differentiates u_φ cos φ, not u_φ; taking two physical derivatives and adding them is a different, wrong expression.
FlowGeometries.Operators.derivative! — Method
derivative!(out, field, grid, indices, weights, dim; order=1, active_only=true, masked=zero,
policy=BlankMasked(), execution=SerialBackend()) -> outderivative! from a table the caller holds — the same reuse as the apply_stencil! form above, for the entry point a geometry-aware caller actually uses. Where the order is 2 or more along a direction whose own scale factor varies along it, the weights depend on the cell and are rebuilt per call; hold a masked_stencil_plan there.
FlowGeometries.Operators.derivative! — Method
derivative!(out, field, grid, plan, dim; active_only=true, masked=zero, execution=SerialBackend()) -> outderivative! from a held Discretization.stencil_plan.
The form to use in a loop: the weights depend on the grid alone, so they are built once, by the caller. Where the order is 2 or more along a direction whose own scale factor varies along it, the weights depend on the cell and are rebuilt per call; hold a masked_stencil_plan there.
FlowGeometries.Operators.derivative! — Method
derivative!(out, field, grid, plan::MaskedStencilPlan; masked=zero, execution=SerialBackend()) -> outderivative! along plan.dim from a held MaskedStencilPlan of grid, built for grid's mask. Where the derivative needs weights over distance, the plan must be the grid form's, masked_stencil_plan(grid, dim; order, nodes, policy).
FlowGeometries.Operators.derivative! — Method
derivative!(out, field, grid, plans::StencilPlans, dim; masked = zero, execution = SerialBackend()) -> outderivative! along dim with the plan stencil_plans holds for that direction.
FlowGeometries.Operators.divergence! — Method
divergence!(δ, u, grid, derivs; masked = NaN, scratch = nothing, execution = SerialBackend()) -> δThe divergence of the vector field u on grid, its components along the local frame: the flux form, d_λu_λ + d_φu_φ − u_φ tan φ/R on a sphere's surface. derivs and the masking are as for strain_rate!; scratch is one array per direction.
FlowGeometries.Operators.divergence! — Method
divergence!(δ, v, fm::FaceMetrics; execution = SerialBackend()) -> δδ[I] = (1/V_I) Σ_d σ_d ((A v)[face above] − (A v)[face below]) over the area_op of each face of cell I, V_I its fm.volume, and zero on an inactive cell: the negative adjoint of gradient! under the cell volume and the face weight area_op · gap, so L = D G is symmetric.
FlowGeometries.Operators.divergence — Method
divergence(u, grid, derivs; masked = NaN, execution = SerialBackend())divergence! into a fresh array.
FlowGeometries.Operators.face_metrics — Method
face_metrics(grid, boundary = Neumann()) -> FaceMetricsThe FaceMetrics of a Grids.StructuredGrid, of the centres of a Grids.StaggeredGrid, or of a two-dimensional Grids.CurvilinearGrid holding its cell vertices, under boundary.
On a rectilinear grid a face normal to d has area ∏_{e≠d} |h_e| w_e and gap |h_d| Δξ_d, the scale factors read at the face, w_e the cell widths and Δξ_d the coordinate distance between the centres it separates, so gradient!, divergence! and curl! are exact for a linear field on a Cartesian one. On a curvilinear grid a face is the edge between two cell vertices, its area their distance and its gap the distance between the two centres it separates.
Built on the host, cell by cell, from a grid held there; move the result to a device with Execution.on_backend.
FlowGeometries.Operators.galerkin_coefficients — Method
galerkin_coefficients(fine::LaplacianCoefficients, cgrid) -> LaplacianCoefficientsR L P on cgrid, a coarsen of fine.grid, for injection P and its adjoint R, the measure-weighted average of restrict!: a coarse face's coefficient is the sum of the fine ones crossing it, a coarse cell's measure the sum of its children's.
FlowGeometries.Operators.gradient! — Function
gradient!(outs::Tuple, field, plan; execution=SerialBackend()) -> outs
gradient!(g1, g2, field, plan; execution=SerialBackend()) -> (g1, g2)
gradient!(g1, g2, g3, field, plan; execution=SerialBackend()) -> (g1, g2, g3)Apply a GradientPlan: the components of ∇field at every cell, written one per output array. One dot product per cell over its neighbours, allocating nothing on the host.
There must be exactly ncomponents of them. field and the outputs are indexed linearly, so an N-D array of the grid's shape works as is. The components are named by plan.names — (:λ, :φ) on a sphere, (:x, :y) on a plane, (:x, :y, :z) in a volume — and are per unit distance, the displacements being metric already.
Every cell is its own work item under execution; the plan's arrays are read where execution runs.
FlowGeometries.Operators.gradient! — Method
gradient!(g, χ, fm::FaceMetrics; execution = SerialBackend()) -> gg[d][F] = σ_d (χ_above − χ_below)/gap on every face of nonzero area_op normal to d, a zero ghost past a Dirichlet end, and zero on every other face; σ_d is fm.orientation[d].
FlowGeometries.Operators.gradient_plan — Function
gradient_plan(grid; stencil=Stencils.Axial(1), active_only=true, conn=nothing) -> GradientPlanBuild the least-squares gradient of grid — the geometry of it, with no field involved. See GradientPlan for what it is and why it is that; apply it with gradient!.
This is the counterpart of apply_stencil! for the two architectures that have no separable axis to difference along: a CurvilinearGrid, whose neighbours come from its index topology, and an UnstructuredGrid, whose come from its stored adjacency. conn overrides the neighbour set; otherwise one is built, from stencil where the architecture takes one. A neighbour set with no edges at all raises an ArgumentError, the fit having nothing to read.
One direction per coordinate: a (λ, φ) or (x, y) surface resolves two, in its tangent plane, and a three-coordinate volume resolves three, on the local frame — see Geometry.local_displacement. The fixed-size symmetric solve behind it covers those two cases.
A masked cell gets no coefficients at all and reads zero gradient, and an inactive neighbour is not offered to the fit, on the same rule as everywhere else: not determined by the active data, so not invented.
FlowGeometries.Operators.interpolate — Function
interpolate(field, grid, p; policy=BlankMasked(), masked=NaN, …) -> valueThe value of field at the coordinate p, which is how observational data arrives: a station, a float or a ship track carries a coordinate.
Discretization.interpolation_weights gives the weights along one axis; this composes them, on every layout.
StructuredGrid— multilinear, the tensor product of the per-axis weights. A periodic direction interpolates across its seam, so a coordinate past the last sample wraps to the first.CurvilinearGrid,UnstructuredGrid— a weighted least-squares plane fitted to theknearest cells in the tangent plane atp, which is exact for a linear field and reproduces a cell's own value at its centre. Falls back to the weighted mean where the fit is rank deficient, that being the part of it the data still determines.
Off a rectilinear grid the k nearest cells come from a ball search, and three keywords hold its state across calls. topology and scratch are as for Connectivity.neighbors_within!: with no index the search visits every cell, and Connectivity.indexed brings it to O(log n + k). nearest = (idx, dist), two vectors of at least k entries, holds the cells found. With all three held, a query allocates nothing.
p may be written any way a point is accepted elsewhere.
The mask policies say what an inactive contributor means, as they do for a stencil: BlankMasked — the default — returns masked if any contributor is inactive, and ReduceInRun renormalizes over the active ones. ShiftWithinRun has no meaning here, there being no window to shift, and says so.
A field carrying trailing batch axes beyond the grid's own — many tracers, or an ensemble, sharing one geometry — is evaluated for every element in one call: see interpolate! for the form that writes into a caller's buffer, which this one wraps.
interpolate(field, grid, points::AbstractVector; execution = SerialBackend(), …) -> valuesThe value at every point of points, a vector of coordinates: a vector, or for a field carrying trailing batch axes a (batch elements, points) matrix. Off a rectilinear grid the neighbour search for all of them runs on one cell list over the grid, built once, unless topology is passed.
FlowGeometries.Operators.interpolate! — Function
interpolate!(out, field, grid, p; …) -> out
interpolate!(out, field, grid, points::AbstractVector; execution = SerialBackend(), …) -> outinterpolate for a batched field, writing one value per batch element into out.
The bracketing cell — or, off a rectilinear grid, the neighbour set and the least-squares fit — depends on the point and the geometry alone, so it is solved once and applied to every element. One call is therefore less work than interpolate per slice.
At many points, out[i] (or out[:, i] for a batched field) receives points[i]'s values. The points run under execution on any host or process backend.
FlowGeometries.Operators.interpolate! — Method
interpolate!(out, field, grid, p; k=8, …) -> outinterpolate off a rectilinear grid for a field carrying trailing batch axes, writing one value per batch element.
The k nearest cells and the mask verdict are a property of the point and the geometry, so they are solved once here and the tangent-plane fit is then applied to every element.
FlowGeometries.Operators.interpolate! — Method
interpolate!(out, field, grid, p; active_only=true, masked=NaN, policy=BlankMasked()) -> outinterpolate at one coordinate for a field carrying trailing batch axes: out receives one value per batch element, in the order those axes are laid out.
The bracketing cell and its 2^N corner weights depend on the point and the grid alone, so they are solved once here and applied to every element.
FlowGeometries.Operators.laplacian! — Method
laplacian!(out, χ, fm::FaceMetrics, g; execution = SerialBackend()) -> outL χ = D G χ from gradient! into the face arrays g, then divergence!. For repeated application laplacian_coefficients holds the same operator in one pass.
FlowGeometries.Operators.laplacian_coefficients — Method
laplacian_coefficients(fm::FaceMetrics) -> LaplacianCoefficientsL = D G of divergence! and gradient! under fm, with the coefficients A/g of fm.area_op and fm.gap: separable where the metrics are, and the grid's own measure on an unmasked grid.
Built on the host, the null space's components labelled by a walk over the cell graph, as are coarse_coefficients and galerkin_coefficients; move the result to a device with Execution.on_backend.
FlowGeometries.Operators.map_directions — Method
map_directions(f, Val(N)) -> Tuple(f(Val(1)), …, f(Val(N))). The direction is a type parameter, so a tuple indexed by it inside f reads one fixed slot.
FlowGeometries.Operators.map_rotation_pairs — Method
map_rotation_pairs(f, Val(N)) -> Tuplef(Val(a), Val(b)) for each of rotation_pairs(Val(N)), in that order, as a tuple. The pair's directions are type parameters, so a tuple indexed by a or b inside f reads one fixed slot.
FlowGeometries.Operators.masked_stencil_plan — Method
masked_stencil_plan(x, mask, dim, order, nodes; period=nothing, policy=ReduceInRun()) -> MaskedStencilPlan
masked_stencil_plan(grid, dim; order=1, nodes=order+1, policy=ReduceInRun()) -> MaskedStencilPlanThe order-th derivative's weights along direction dim of a field masked by mask, under policy, for every cell: apply_stencil!'s answer for that mask, held. The axis x, its period and the mask fix it, so a caller differencing many fields builds it once. Built on the host; Adapt moves it to a device.
The grid form solves the weights over distance where derivative! needs them so: at order ≥ 2 along a direction outside Geometry.scale_invariant_directions.
FlowGeometries.Operators.metric_array — Method
metric_array(f, dims, layout, T) -> AbstractArray{T,N}The array a[I] = f(I) over dims: a Grids.SeparableMeasure of its axis factors under SeparableMetrics(), read off f along each axis through one index where f is nonzero, and a dense array under DenseMetrics().
With G_e(i) = f(ref with e → i) and P = f(ref), ∏_e G_e(I[e]) = f(I)·P^{N−1} for a separable f, so the trailing factors are divided by P. A function zero everywhere factors as zeros.
FlowGeometries.Operators.metric_layout — Method
metric_layout(grid) -> SeparableMetrics | DenseMetricsSeparableMetrics() on an unmasked Cartesian or spherical rectilinear grid, where every face area, gap and edge length is a product of one factor per axis; DenseMetrics() on every other grid.
FlowGeometries.Operators.n_rotation_components — Method
n_rotation_components(N) -> IntN(N−1)/2, the independent components of an antisymmetric tensor in N directions.
FlowGeometries.Operators.ncomponents — Method
ncomponents(plan::GradientPlan{D}) -> DHow many directions the plan resolves, and so how many outputs gradient! writes.
FlowGeometries.Operators.project_out_constant! — Method
project_out_constant!(Φ, c::LaplacianCoefficients; execution = SerialBackend()) -> ΦRemove from Φ, on each closed component of L, its measure-weighted mean there: the component of Φ in L's null space.
FlowGeometries.Operators.restrict! — Method
restrict!(coarse, fine, fc, cc; execution = SerialBackend()) -> coarse
prolong_add!(fine, coarse, fc, cc; execution = SerialBackend()) -> fineThe transfers between a level fc and the next one down cc: restrict! writes each coarse cell the measure-weighted mean of its children, Σ V_J f_J / Σ V_J, and prolong_add! adds each coarse value to the active fine cells it covers. Under the cell measures each is the other's adjoint, which galerkin_coefficients assumes.
FlowGeometries.Operators.restrict_residual! — Method
restrict_residual!(coarse, b, x, fc, cc; execution = SerialBackend()) -> coarserestrict! of the residual b + L x on level fc, formed child by child inside the restriction: coarse cell I gets Σ (V_J b_J + V_J (L x)_J) / Σ V_J over its active children, V_J (L x)_J the flux balance over J's faces.
FlowGeometries.Operators.rotation_pairs — Method
rotation_pairs(Val(N)) -> NTuple{P,NTuple{2,Int}}The pairs (a, b), a < b, in lexicographic order: the components of an antisymmetric tensor, and the directions each is staggered in.
FlowGeometries.Operators.rotational_velocity! — Method
rotational_velocity!(u, R, fm::FaceMetrics; execution = SerialBackend()) -> uu_a = −Σ_b ∂_b R_ab on the faces, from the rotation potential R on the corners, one array per rotation_pairs pair: the flux area_op · u through a face is σ_b times the metric-free difference of R ℓ across its bounding edges, ℓ the edge length, so D u = 0 on every grid. A corner outside R's arrays, past the end of a bounded direction, holds zero.
For R zero off corner_mask, ⟨u, v⟩ = −⟨R, curl v⟩ under the face weight area_op · gap and the corner weight ℓ μ, with curl!.
FlowGeometries.Operators.stencil_plans — Method
stencil_plans(grid; order = 1, nodes = order + 1, policy = BlankMasked()) -> StencilPlansA Discretization.stencil_plan along every direction of grid, or, on a grid with an inactive cell, a masked_stencil_plan under policy. A direction shorter than nodes takes the samples it has; one with fewer than order + 1 carries no derivative and is written masked.
The weights depend on the axes, the mask, the order and the policy, never on a field: one serves every derivative taken on the grid, and tasks may share it.
FlowGeometries.Operators.strain_components — Method
strain_components(grid) -> NTuple{K,Symbol}The names of the rate-of-strain components on grid, in order: (:λλ, :φφ, :λφ) on a sphere's surface, (:xx, :yy, :zz, :xy, :xz, :yz) in a Cartesian volume — the diagonal, then the upper triangle row by row.
FlowGeometries.Operators.strain_rate! — Method
strain_rate!(S, u, grid, derivs; masked = NaN, scratch = nothing, execution = SerialBackend()) -> SThe rate of strain ½(∇u + ∇uᵀ) of the vector field u, one array per direction of grid along its local frame, written into the arrays of the NamedTuple S under the names strain_components gives. derivs is stencil_plans(grid) on a structured grid and a gradient_plan elsewhere.
On a curved geometry each component carries the frame's own terms — on a sphere S_λλ = d_λu_λ − u_φ tan φ/R and S_λφ = ½(d_φu_λ + d_λu_φ + u_λ tan φ/R) — from Geometry.log_scale_gradients. A cell is written masked where it is inactive, where a derivative it reads does not exist, or where the metric degenerates, as at a pole. scratch is one array per direction for the derivatives of one component; with it a call allocates nothing.
FlowGeometries.Operators.strain_rate — Method
strain_rate(u, grid, derivs; masked = NaN, execution = SerialBackend()) -> NamedTuplestrain_rate! into fresh arrays, named as strain_components gives.
FlowGeometries.Operators.tensor_to_local! — Method
tensor_to_local!(λλ, φφ, rr, λφ, λr, φr, xx, yy, zz, xy, xz, yz, grid; execution = SerialBackend()) -> nothingWrite the local components of the symmetric tensor field whose ambient Cartesian components are xx … yz at every cell of grid: Geometry.tensor_to_local per cell. An output given as nothing is not written. An inactive cell gets zero.
FlowGeometries.Operators.to_centres! — Method
to_centres!(u, v, fm::FaceMetrics; execution = SerialBackend()) -> uThe cell-centred field of the face-normal velocity v: along each direction the mean over a cell's two faces of nonzero area_flux, zero where it has none and on an inactive cell. On a uniform axis to_centres! ∘ to_faces! has the symbol cos²(kh/2).
FlowGeometries.Operators.to_faces! — Method
to_faces!(v, u, fm::FaceMetrics; execution = SerialBackend()) -> vThe face-normal velocity v of a cell-centred field u, one array per direction: the mean of the two cells a face separates, the one cell's value at the end of a bounded direction, and zero on a face of zero area_flux. u is a tuple of one array of the grid's shape per direction.
FlowGeometries.Operators.to_local! — Method
to_local!(u, v, w, X, Y, Z, grid; execution = SerialBackend()) -> nothingWrite the local components, along ê_λ, ê_φ, ê_r, of the vector field whose ambient Cartesian components are X, Y, Z at every cell of grid: Geometry.vector_from_cartesian per cell. w = nothing drops the outward component. An inactive cell gets zero.
FlowGeometries.Operators.to_planetary! — Method
to_planetary!(X, Y, Z, u, v, w, grid; execution = SerialBackend()) -> nothingWrite the ambient Cartesian components of the vector field whose local components are u, v, w — along ê_λ, ê_φ, ê_r — at every cell of grid: Geometry.vector_to_cartesian per cell. w = nothing is a tangent field. An inactive cell gets zero and its inputs are not read.