Skip to content

Remove all references to "EmptyBox"#1165

Open
PhilipDeegan wants to merge 1 commit intoPHAREHUB:masterfrom
PhilipDeegan:empty_box
Open

Remove all references to "EmptyBox"#1165
PhilipDeegan wants to merge 1 commit intoPHAREHUB:masterfrom
PhilipDeegan:empty_box

Conversation

@PhilipDeegan
Copy link
Member

replace with std::optional when required.

closes #1092

@coderabbitai
Copy link

coderabbitai bot commented Feb 27, 2026

Warning

Rate limit exceeded

@PhilipDeegan has exceeded the limit for the number of commits that can be reviewed per hour. Please wait 18 minutes and 55 seconds before requesting another review.

⌛ How to resolve this issue?

After the wait time has elapsed, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

🚦 How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout.

Please see our FAQ for further information.

📥 Commits

Reviewing files that changed from the base of the PR and between 80890ad and dc26e6a.

📒 Files selected for processing (5)
  • src/core/data/grid/gridlayout.hpp
  • src/core/data/particles/particle_array.hpp
  • src/core/utilities/box/box.hpp
  • src/core/utilities/cellmap.hpp
  • tests/core/numerics/pusher/test_pusher.cpp
📝 Walkthrough

Walkthrough

Grid/box API refactor: removed Box::isEmpty() and emptyBox(), switched AMR box handling in GridLayout to std::optional with a public alias AMRBox_t, adjusted mesh-size initialization, and updated CellMap/ParticleArray and tests to stop special-casing a sentinel "empty" box. (50 words)

Changes

Cohort / File(s) Summary
Box Utilities Refactor
src/core/utilities/box/box.hpp
Removed Box::isEmpty() and the free helper emptyBox(); emptiness is no longer represented via a sentinel Box — API removal only.
GridLayout constructor & internals
src/core/data/grid/gridlayout.hpp
Added public alias AMRBox_t = Box<int, dimension>; constructor now accepts std::optional<AMRBox_t> const AMRBox = std::nullopt; AMRBox_ type updated to AMRBox_t; AMR box derived from nbrCells when optional absent; replaced per-dimension inverse-mesh-size init with generate-based initialization; added <optional>.
CellMap boundary check
src/core/utilities/cellmap.hpp
Removed the prior non-empty-box guard in CellMap::addToCell; now inserts based solely on the cell being within the box.
ParticleArray mapping update
src/core/data/particles/particle_array.hpp
Tightened condition in ParticleArray::change_icell: update of cellMap_ now skips only when box size == 1 (previously used isEmpty()), preventing special-casing of a single-cell box.
Test adjustment
tests/core/numerics/pusher/test_pusher.cpp
Renamed template parameter to dim; DummyLayout::AMRBox() now returns a default-constructed Box<int, dimension>{} instead of using removed emptyBox(); updated related dimension usages.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

Possibly related PRs

  • vtkpp #1141: Modifies GridLayout AMRBox member/constructor and related public API; strong overlap with this change.

Suggested reviewers

  • UCaromel
  • nicolasaunai
🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 9.09% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly describes the main change: removing EmptyBox references and replacing them with std::optional.
Description check ✅ Passed The description relates to the changeset by indicating that EmptyBox references are replaced with std::optional.
Linked Issues check ✅ Passed The code changes directly address issue #1092 by removing isEmpty() and emptyBox() from Box class, and introducing std::optional<AMRBox_t> in GridLayout constructor.
Out of Scope Changes check ✅ Passed All changes are scoped to removing EmptyBox references and introducing std::optional as alternatives, with no unrelated modifications detected.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

🧹 Nitpick comments (1)
src/core/data/grid/gridlayout.hpp (1)

114-127: Optional AMRBox parameter is a clean replacement for EmptyBox semantics.

The constructor properly handles both provided and absent AMRBox values, with appropriate validation. The capture-less lambda for inverseMeshSize_ initialization is efficient.

Consider enhancing the error message to include actual sizes for easier debugging:

💡 Optional: Include sizes in error message
-            if (AMRBox_.size() != boxFromNbrCells(nbrCells).size())
-                throw std::runtime_error("Error - invalid AMR box, incorrect number of cells");
+            auto const expected = boxFromNbrCells(nbrCells);
+            if (AMRBox_.size() != expected.size())
+                throw std::runtime_error("Error - invalid AMR box: got "
+                                         + std::to_string(AMRBox_.size()) + " cells, expected "
+                                         + std::to_string(expected.size()));
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@src/core/data/grid/gridlayout.hpp` around lines 114 - 127, The runtime_error
thrown when AMRBox_.size() mismatches boxFromNbrCells(nbrCells).size() lacks
detail; update the constructor in which AMRBox_ is set (uses AMRBox_,
boxFromNbrCells, meshSize_, nbrCells) to include the actual sizes in the
exception message so debugging is easier (e.g., include AMRBox_.size() and
boxFromNbrCells(nbrCells).size() values and contextual text in the thrown
std::runtime_error).
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Nitpick comments:
In `@src/core/data/grid/gridlayout.hpp`:
- Around line 114-127: The runtime_error thrown when AMRBox_.size() mismatches
boxFromNbrCells(nbrCells).size() lacks detail; update the constructor in which
AMRBox_ is set (uses AMRBox_, boxFromNbrCells, meshSize_, nbrCells) to include
the actual sizes in the exception message so debugging is easier (e.g., include
AMRBox_.size() and boxFromNbrCells(nbrCells).size() values and contextual text
in the thrown std::runtime_error).

ℹ️ Review info

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between d7d962d and 65166c9.

📒 Files selected for processing (5)
  • src/core/data/grid/gridlayout.hpp
  • src/core/data/particles/particle_array.hpp
  • src/core/utilities/box/box.hpp
  • src/core/utilities/cellmap.hpp
  • tests/core/numerics/pusher/test_pusher.cpp

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 2

🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@src/core/data/grid/gridlayout.hpp`:
- Around line 124-125: The current check only compares total cell count
(AMRBox_.size()) with boxFromNbrCells(nbrCells).size(), which allows mismatched
per-dimension extents to slip through and break AMRToLocal/localToAMR; replace
this with an element-wise shape validation: obtain the expected per-dimension
extents from boxFromNbrCells(nbrCells) and compare each corresponding dimension
to AMRBox_ (e.g., same number of dimensions and equal extents for every index),
and throw the runtime_error if any dimension differs so AMRToLocal and
localToAMR can safely assume matching shapes.

In `@tests/core/numerics/pusher/test_pusher.cpp`:
- Around line 122-126: The AMRBox() factory constructs an enormous Box<int,
dimension> from 0..1000 per axis which causes ParticleArray/CellMap allocation
blowups; change AMRBox() (the AMRBox() function returning PHARE::core::Box<int,
dimension> built with ConstArray<int, dim>) to use a much smaller extent (e.g.
8..32 per axis or a small test-specific constant) or make the extents
configurable for tests so ParticleArray/CellMap allocations remain tiny for CI;
update any callers relying on AMRBox() to use the reduced-size box or the new
parameter so tests still exercise logic without huge memory/time cost.

ℹ️ Review info

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 65166c9 and c22f461.

📒 Files selected for processing (5)
  • src/core/data/grid/gridlayout.hpp
  • src/core/data/particles/particle_array.hpp
  • src/core/utilities/box/box.hpp
  • src/core/utilities/cellmap.hpp
  • tests/core/numerics/pusher/test_pusher.cpp
🚧 Files skipped from review as they are similar to previous changes (1)
  • src/core/data/particles/particle_array.hpp

Comment on lines +187 to +188
auto const box_is_valid = box_.size() > 1;
if (box_is_valid)
Copy link
Member Author

Choose a reason for hiding this comment

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

now it's an implementation detail rather than a function/interface that is somewhat nonsensical

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.

Box refactor potential

1 participant