Repository navigation
Conversation
New carbon/boundary_condition_distributed.h: BoundaryConditions (six faces,
each BcKind::{None, Dirichlet, Neumann} plus one constant scalar; Neumann is
the outward-normal derivative). Trivially copyable and constexpr so it can
ride inside the by-value kernel Span. Header only and not yet used anywhere,
so behaviour is unchanged.
Span carries a BoundaryConditions block (default none) and gains neighbour_idx_bc, a sibling of neighbour_idx that checks the global domain before the buffer, because a single-rank open axis has no halo storage. A read across a face with a condition resolves to the in-domain mirror cell, and Partition::neighbour_bc turns it into a virtual boundary value (node-centred: Dirichlet 2g - u_m, Neumann u_m + 2*k*h*g). Edge and corner reads and faces without a condition stay invalid. Opt-in: neighbour, read_pull and Cursor are unchanged. Span now static_asserts that it stays trivially copyable. test_dense_distributed_bc_host (no GPU, no MPI) checks that neighbour_bc equals neighbour when no conditions are set, matches an independent per-cell oracle on emulated slab / pencil / brick worlds at radius 1 and 2 including mixed periodic axes, reproduces linear fields exactly, and keeps the documented limits.
Appends a defaulted BoundaryConditions parameter after block_override on all three constructors (source compatible), stores it, exposes boundary_conditions(), and passes it into every per-GPU Span. init_common_ rejects a condition on a periodic axis, on an axis whose extent is not larger than the stencil radius there, and a non-finite value. The grid stays immutable after construction. halo_extent, the layouts and HaloDistributed are not touched.
AGENTS.md layout list, a dated changelog entry, and a doxygen pointer from BoundaryModeDistributed to the new type.
BoundaryView holds, per GPU and per global face, the condition (kind and value, per component) of every stored face cell as raw pointers, so one trivially copyable struct serves host and device. resolve() mirrors neighbour_idx_bc but looks the condition up at the face cell under the target of the read; dirichlet_at() is the pinning query. HostBoundaryStore holds the arrays on the host and decides which part of each face a GPU stores: its owned tangential range widened by the stencil radius, clipped to the domain, nothing for faces it does not touch or on periodic axes. Partition::neighbour_bc gains a templated overload taking a view; the existing overload is unchanged. test_boundary_data_host (no GPU, no MPI) checks equivalence with the constants path, patches and per-component kinds against an independent oracle including diagonal reads, stored ranges and coverage, the pinning helper and validation.
BoundaryData<Components> owns the per-GPU storage for spatially varying face conditions: fill() from a deterministic function of global position (or from the per-face constants), upload() through Transfer, view(gpu) for device kernels and host_view(gpu) for host use. It needs no access token and no loader change; the data must stay constant while a Skeleton using it runs.
Runs a six-point neighbour-sum kernel through a Skeleton, reading every neighbour with neighbour_bc and a BoundaryData view, over a grid with a Dirichlet rectangle, a Dirichlet disc, Neumann regions and unconditioned faces, and compares every owned cell with an independent host oracle. It requires boundary reads and invalid reads to both occur, so it cannot pass by taking only one path.
Current enters a conducting box through a disc terminal on the top face and leaves through an offset one on the bottom face, insulating elsewhere, with a resistive sphere between. The flux differs from cell to cell on one face, so it is declared with BoundaryData and read through neighbour_bc with a view in a Jacobi sweep run by a Skeleton; a second BoundaryData gives the conductivity zero flux on every face. It solves the declared terminals and the same current spread evenly over each face, writes a two-panel PPM of the potential, and fails unless the iteration has converged and the current crossing the plane midway between the terminals matches the injected current to 1%.
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Based on #78 (#78, per-face constant Dirichlet and Neumann conditions). This branch contains #78's commits as well, so until #78 merges the diff shows both. The commits that belong to this PR are the last five:
Summary
#78 gives each face of a
DenseDistributedgrid one boundary condition: one kind and one constant. This addsBoundaryData<Components>, a separate object holding the condition (Dirichlet or Neumann, and its value) of every cell of every exterior face, per component. A kernel takesbnd.view(loader.relative_gpu_id())in its loading lambda and callsneighbour_bc(span, view, idx, offset, comp)in the device lambda. The formulas are #78's (Dirichlet2g - u_m, Neumannu_m + 2khg), but the condition is read at the face cell under the target of the read. It is opt-in: the loader, access tokens, Skeleton and #78's code are untouched.What it enables
BoundaryView::dirichlet_attells a solver which nodes to pin.One thing it does not add: for a radius-1 stencil, a Dirichlet disc on an otherwise zero-flux face could already be done with #78 by setting the face to Neumann and pinning the nodes under the disc. I checked this on a pole-piece problem and the two results are identical (difference 0.0). The gain there is declaring it once.
Example: offset current terminals
examples/offset_current_terminals.cusolves steady current flow in a conducting box. Current enters through a disc terminal on the top face and leaves through an offset one on the bottom face, with a resistive sphere between; everything else is insulating. The flux differs from cell to cell on one face, so it is declared withBoundaryDataand read throughneighbour_bcin a Jacobi sweep run by a Skeleton. The conductivity field gets its ownBoundaryData(zero flux on every face), so two fields on one grid carry different conditions.The example also solves the same total current spread evenly over each face, which is all one constant per face can say, and compares the two. All 45 units of injected current cross the plane midway between the terminals (44.98 computed) while the even spread carries none sideways, and the potential swing is about 4x larger (3.9 against 0.9). The program exits non-zero unless the iteration has converged and the current matches to 1%; flipping the Neumann sign reverses the current and fails it. The figure is plotted from the example's
--rawoutput.Status
Tested: a new CPU-only test (21.4M checks, emulated slab/pencil/brick ranks, radius 1 and 2) covers constant data matching #78, Dirichlet rectangle and disc patches, per-component kinds, diagonal reads across rank boundaries, stored ranges and coverage, and the pinning helper; four deliberate mutations each make it fail. A device test running a Skeleton against an independent oracle passes (1,728 cells), and the example passes its own checks (25^3 box, 4000 sweeps), both on the SYCL backend with the OpenMP host as device; each fails when the Neumann sign is flipped. The #78 test and the existing host test give identical results.
Not yet verified: the CUDA build, real GPUs, multi-GPU and MPI runs.
Limits: conditions must stay constant while a Skeleton using them runs. Reads across two faces at once (edges, corners) stay invalid.
fillruns on the host.