Skip to content

Plan: finite-difference data, samples, reconstruction and staggered components (#321) - #513

Open
berkgeveci wants to merge 1 commit into
Kitware:mainfrom
berkgeveci:docs/plan-finite-difference
Open

berkgeveci wants to merge 1 commit into
Kitware:mainfrom
berkgeveci:docs/plan-finite-difference

Conversation

@berkgeveci

Copy link
Copy Markdown
Collaborator

The plan for #321, finite-difference data, as docs/design/plans/finite-difference-data.md. It turns the proposal of 2026-11-01 into decisions; finite_differences (#415) already did most of its operator stage.

The core: td.Samples(data, offset=..., kind=..., ghosts=...), values on a structured grid's lattice (each axis at 0 or ½ a cell: points, cell centres, faces, edges, PETSc DMStag's locations), point samples or averages, with no basis. A filter that needs a function between the values refuses it and names the remedy, so the reconstruction becomes an explicit choice (td.reconstruct), and the solver's difference operators stay distinct from differentiating a reconstruction (finite_differences on Samples, with a declared boundary rule). Values, H1, Constant and today's results do not change.

Decisions D1-D9, each with a recommendation; reply per decision. Of note:

  • D3: no implicit basis for Samples; _with_basis stays for Values, and the guide says what it chooses.
  • D5: staggered vectors are one field per component, brought together by td.collocate, with no composite type.
  • D7: td.face_values maps MAC face components onto Tack's face numbering without a copy, so divergence, perot and upwind_flux take them.

The guide (step 1, docs only) follows in its own PR.

Docs only: mkdocs build --strict is clean.

This plan will be merged (accepted) after the 0.8 release.

🤖 Generated with Claude Code

| `(0, ½, ½)` | x-faces (MAC's `u`) | `nx × (ny-1) × (nz-1)` |
| `(½, 0, 0)` | x-edges (Yee's `Ex`) | `(nx-1) × ny × nz` |

These are PETSc `DMStag`'s locations. An axis offset by `½` has one sample

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

AMReX's IndexType (cell or node per axis) is the same offset, and its face-centred MultiFabs are where much of this data will come from. Worth naming beside DMStag, so a Catalyst AMReX adaptor can map IndexType and nGrow straight onto offset and ghosts.

lay them out, so a native array is taken as it is (zero-copy for a contiguous
NumPy or device array).

**On a mapped grid** the offset is in index space: a sample's position is the

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

On a curvilinear grid, the position at a half index is itself a reconstruction of the geometry (trilinear in the cell, presumably). Please say which.

average-preserving reconstruction of higher order (a conservative one) is a
later method, not this plan's.
- **`boundary`:** what a location gets where its stencil reaches past the valid
samples (D6). `"nearest"` (the default) uses the samples there are, as VTK's

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What does "nearest" mean for "multilinear" at a point outside the centres' hull: clamp to the nearest sample, or extrapolate from the nearest cell? The guide's cell-centre example shows that this strip is where the choice is visible.

### D6. Ghost layers in the native array, and the valid region

A solver's array often includes its halo. `ghosts=g` (a number, or one per axis)
says the array holds `g` extra samples on each side of each axis; the valid

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ghosts per axis and per side, (lo, hi). Some solvers pad only one side, or pad faces differently from cells.

`Samples` too, `kind="point"`. Its stencils stay those of #415. It gains a
`boundary` argument for samples:

- `"one-sided"` (today's behaviour, and the default): the stencils narrow at the

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A "periodic" rule. Periodic boxes are common in finite-difference output, and the stencil wraps the index with no halo.

stored normal points down its axis. It is an implicit array over the native
buffers, not a copy. `divergence`, `perot` and `upwind_flux` then take MAC
velocities directly, and the divergence of a MAC field at the cell centres is
the solver's own compact stencil. (`kind="average"` face samples times the face

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

MAC solvers store point samples of normal velocity at face centres, and their compact divergence is sum(u A) / V with those point samples (the midpoint rule). So "point samples are not [fluxes]" contradicts "the solver's own compact stencil" on the line above. Since divergence takes fluxes, face_values needs to multiply by face area (an option, or a fluxes=True) for the MAC case to work as stated.

@jlee-kitware

Copy link
Copy Markdown
Collaborator

Separating samples, reconstruction and operators is right, and Samples with no implicit basis makes the choice visible without changing existing results. One inconsistency in D7 on MAC fluxes, and a few gaps.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants