Skip to content

Use cell-index map for neighbor lookups and refactor MDBC neighbor loop#198

Open
AhmedSalih3d wants to merge 3 commits into
BeforeLidDrivenCavityExamplefrom
codex/optimize-neighborloop-algorithm
Open

Use cell-index map for neighbor lookups and refactor MDBC neighbor loop#198
AhmedSalih3d wants to merge 3 commits into
BeforeLidDrivenCavityExamplefrom
codex/optimize-neighborloop-algorithm

Conversation

@AhmedSalih3d

Copy link
Copy Markdown
Owner

Motivation

  • Replace expensive search-based neighbor lookups with a direct map to speed up neighbor cell discovery and reduce allocations.
  • Simplify and harden the MDBC ghost-point neighbor accumulation by avoiding repeated searches and early-skipping empty cells.
  • Improve reuse and sizing of neighbor containers to reduce allocation churn during neighbor-list rebuilds.

Description

  • Add a CellIndexMap / NeighborCellIndexMap (Dict{CartesianIndex,Int}) to map cell coordinates to their index and thread it through BuildNeighborCellLists!, NeighborLoopMDBC!, ApplyMDBCBeforeHalf!, and SimulationLoop.
  • Overload BuildNeighborCellLists! to populate and size-hint the CellIndexMap and NeighborCellLists, and switch neighbor lookups to get(CellIndexMap, cell, 0) to avoid searchsortedfirst in hot loops.
  • Modify NeighborLoopMDBC! to use an inlined GhostCellIndex helper instead of the previous f, iterate FullStencil, and skip missing neighbors early; return per-ghost contributions using ComputeInteractionsMDBC! as before.
  • Update ApplyMDBCBeforeHalf!, SimulationLoop, and the top-level run logic to create and pass NeighborCellIndexMap and to call the new BuildNeighborCellLists! signatures; remove unused GhostNormals unpack and other small cleanups.

Testing

  • Ran the package unit test suite with ] test against the modified code and observed all tests pass.
  • Executed a short smoke simulation run (example input) to validate neighbor-list rebuilds and MDBC corrections, and it completed without errors.

Codex Task

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

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant