Skip to content

Expose DiffusionGrid buffers via protected accessors; migrate Euler grids off friend pattern#7

Open
stanbot8 wants to merge 2 commits intomasterfrom
refactor/diffusion-grid-accessors
Open

Expose DiffusionGrid buffers via protected accessors; migrate Euler grids off friend pattern#7
stanbot8 wants to merge 2 commits intomasterfrom
refactor/diffusion-grid-accessors

Conversation

@stanbot8
Copy link
Copy Markdown
Owner

@stanbot8 stanbot8 commented Apr 13, 2026

Summary

  • Four protected accessors on DiffusionGrid (GetConcentrationPtr, GetScratchPtr, SwapBuffers, GetRawDiffusionCoefficient) so solver subclasses don't need a friend declaration.
  • EulerGrid and EulerDepletionGrid migrated to the new accessors. Their friend decls on DiffusionGrid are dropped; only TestGrid remains.
  • Mechanical rewrite: stencil and loop structure are preserved.

Test plan

  • Builds on Ubuntu 24.04 (-Dnuma=off for WSL)
  • Existing diffusion and euler tests pass
  • CI: ubuntu-system, macos-system

Adds four protected accessors on DiffusionGrid:
  - GetConcentrationPtr / GetScratchPtr : mutable pointers to the live and
    scratch concentration buffers
  - SwapBuffers : swap the live and scratch buffers at the end of a step
  - GetRawDiffusionCoefficient : returns D directly (the stored dc_[0] is
    1 - D for stencil convenience)

Lets solver subclasses implement their own Diffuse* methods without
requiring a friend declaration on DiffusionGrid.
Each Diffuse* method hoists local aliases at the top and the loops use
those aliases. Mechanical rewrite: c1_[i] -> c1[i], mu_ -> mu,
c1_.swap(c2_) -> SwapBuffers(), boundary_condition_->Evaluate(...) ->
GetBoundaryCondition()->Evaluate(...). Stencil and loop structure are
unchanged.

With no subclass reaching into private members, the EulerGrid and
EulerDepletionGrid friend declarations are removed. Existing diffusion
and euler tests still pass.
@stanbot8 stanbot8 force-pushed the refactor/diffusion-grid-accessors branch 2 times, most recently from a6346b3 to 417067b Compare April 13, 2026 04:27
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.

1 participant