Skip to content

origin made global#1093

Merged
PhilipDeegan merged 4 commits intoPHAREHUB:masterfrom
PhilipDeegan:omg
Nov 7, 2025
Merged

origin made global#1093
PhilipDeegan merged 4 commits intoPHAREHUB:masterfrom
PhilipDeegan:omg

Conversation

@PhilipDeegan
Copy link
Member

@PhilipDeegan PhilipDeegan commented Oct 25, 2025

The point of this is to stop using the origin per patch to calculate the coordinate representation of each field used during initialization

In doing so, we switch to using the AMR index, and the mesh size, which is constant across patches, removing potential for epsilon coordinate mismatch due to using the different origins per patch

@coderabbitai
Copy link

coderabbitai bot commented Oct 25, 2025

📝 Walkthrough

Walkthrough

This PR removes the origin concept from the coordinate system and refactors GridLayout to use AMR-based local indexing. New methods for AMR-local conversions are added, coordinate calculation APIs are simplified to eliminate origin-based offsets, and test patterns are updated to use unified AMR-local iteration instead of dimension-specific nested loops.

Changes

Cohort / File(s) Summary
Core GridLayout API overhaul
src/core/data/grid/gridlayout.hpp, pyphare/pyphare/core/gridlayout.py
Major API changes: removed physicalStartIndices/physicalEndIndices; added AMRLocalIndexer struct and accessors (amr_lcl_idx(), domain_amr_lcl_idx(), ghost_amr_lcl_idx()); added AMRBoxFor()/AMRGhostBoxFor(); updated fieldNodeCoordinates() and cellCenteredCoordinates() signatures to accept Field_t and Point<int, dimension> instead of origin-based coordinates; added localPointToAMR() method.
Origin concept removal
src/amr/wrappers/hierarchy.hpp, pyphare/pyphare/pharein/__init__.py, pyphare/pyphare/pharein/simulation.py, src/diagnostic/diagnostic_model_view.hpp
Removed origin() accessor and origin_ member from Hierarchy; removed origin parameter from constructor and initialization; removed origin serialization from grid metadata; removed check_origin() function; updated getDomainCoords() to initialize lower bounds to 0; changed BaseModelView::origin() to return zero-initialized vector.
AMR utilities refactoring
src/amr/resources_manager/amr_utils.hpp
Simplified layoutFromPatch(): unified dl/origin/nbrCell computation using core::for_N_make_array; removed explicit dimension handling and nullptr branches; added fallbacks for missing geometry (defaults: dl=1.0, origin=0.0).
GridLayout usage in validation
pyphare/pyphare/pharein/maxwellian_fluid_model.py
Updated GridLayout instantiation to use domain_box.lower instead of sim.origin.
Particle and position calculations
src/core/data/particles/particle_utilities.hpp, src/core/data/ions/particle_initializers/maxwellian_particle_initializer.hpp
Simplified positionAsPoint() to compute (iCell[d] + delta[d]) * meshSize[d] directly without origin/startIndex adjustments; replaced per-dimension point construction with dimension-agnostic for_N_make_array; updated index derivation from physicalStartToEndIndices() to indices(layout.AMRBox()).
Field initialization
src/core/data/field/initializers/field_user_initializer.hpp
Updated ghost indices calculation to use layout.AMRGhostBoxFor(field) wrapped by layout.indices(); changed coordinate generation to fieldNodeCoordinates(field_) without origin; updated field indexing to use layout.AMRToLocal(Point{...}).
Core utilities
src/core/utilities/types.hpp, src/core/utilities/point/point.hpp, src/core/utilities/box/box.hpp
Added for_N_make_array helper for convenience wrapping; enhanced Point::as<To>() template and improved as_unsigned()/as_signed(); moved value_type alias earlier in Box struct.
C++ test refactoring (coordinate patterns)
tests/core/numerics/ampere/test_main.cpp, tests/core/numerics/faraday/test_main.cpp, tests/core/numerics/ohm/test_main.cpp, tests/core/numerics/ion_updater/test_updater.cpp
Updated all fieldNodeCoordinates() calls to pass layout.localToAMR(Point{...}.as_signed()); updated density/field iteration to use layout.amr_lcl_idx(); reordered static member qualifiers (static conststatic ... const).
C++ test refactoring (ghost/AMR loops)
tests/amr/data/field/copy_pack/field_data_test_param.hpp, tests/amr/data/field/refine/test_tag_strategy.hpp, tests/amr/data/field/time_interpolate/test_field_data_time_interpolate.cpp, tests/core/data/electrons/test_electrons.cpp
Replaced per-dimension nested ghost-index loops with single iteration over layout.AMRGhostBoxFor(field) or layout.ghost_amr_lcl_idx(field); removed origin retrieval; updated field writes to use local indices; added const qualifiers.
C++ test structural updates
tests/core/data/gridlayout/gridlayout_deriv.cpp, tests/core/data/gridlayout/gridlayout_deriv.hpp, tests/core/data/gridlayout/gridlayout_cell_centered_coord.hpp, tests/core/data/gridlayout/gridlayout_field_centered_coord.hpp, tests/core/data/gridlayout/test_main.cpp
Changed iCellForCentering type from std::vector<std::array<...>> to std::vector<Point<int, ...>>; added GridLayout_t type alias; replaced manual coordinate transformation with direct cellCenteredCoordinates() calls; simplified parameter construction; removed unused helpers and namesToQuantity mapping; updated read() signature to const.
Python test updates
tests/core/data/gridlayout/cellCenteredCoordinates.py, tests/core/data/gridlayout/deriv.py, tests/core/data/gridlayout/fieldNodeCoordinates.py
Updated function signatures to remove origin/startIndex parameters; moved GridLayout instantiation inside loops; simplified coordinate calculations; updated all call sites to pass GridLayout instance and new parameter sets.
Additional test updates
tests/core/data/gridlayout/gridlayout_laplacian.cpp, tests/amr/messengers/test_messenger_tag_strategy.hpp, tests/core/data/maxwellian_particle_initializer/test_maxwellian_particle_initializer.cpp, tests/core/data/particles/test_main.cpp, tests/core/data/particles/test_particle_array_consistency.cpp, tests/initializer/test_initializer.cpp
Updated coordinate calls to use layout.localToAMR() transformations; simplified endDomain calculations; removed origin-based position computations; removed origin assertions; minor refactoring of loop variables and blank lines.

Sequence Diagram(s)

sequenceDiagram
    participant User as User Code
    participant GL as GridLayout
    participant AMRIdx as AMR Indexing
    participant LocalIdx as Local Indexing
    
    User->>GL: Request field node coordinates
    GL->>AMRIdx: Convert to AMR Point
    AMRIdx-->>GL: AMR Point (no origin offset)
    GL->>LocalIdx: Get local indices
    LocalIdx-->>GL: Local index tuple
    GL-->>User: Position (computed from AMR Point)
    
    Note over GL,LocalIdx: Old flow: origin + startIndex + delta<br/>New flow: AMR point directly
Loading
sequenceDiagram
    participant OldCode as Old Approach
    participant NewCode as New Approach
    
    OldCode->>OldCode: for each dimension i:<br/>  pos[i] = origin[i] + (iCell[i] - startIdx[i]) * meshSize[i]
    
    NewCode->>NewCode: pos = (iCell + delta) * meshSize<br/>(origin = 0.0 by default)
    
    Note over OldCode: Origin-based coordinate offset
    Note over NewCode: Simplified AMR-local coordinates
Loading

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~60 minutes

  • Primary complexity drivers:

    • Large scope: GridLayout API modifications affecting coordinate system across multiple files
    • Heterogeneous changes: mix of simple coordinate replacements, loop restructuring, and API signature updates
    • Logic density: coordinate transformation logic simplified but AMR-local indexing patterns introduce new reasoning requirements
    • File spread: changes span core algorithms (particles, fields, grid), AMR wrappers, and 20+ test files
  • Areas requiring extra attention:

    • src/core/data/grid/gridlayout.hpp: AMRLocalIndexer struct and comprehensive API redesign; verify all coordinate transformation methods behave correctly without origin
    • src/amr/wrappers/hierarchy.hpp: origin removal and domain initialization changes; confirm lower bounds correctly set to 0 and domain calculations remain valid
    • src/core/data/particles/particle_utilities.hpp and src/core/data/ions/particle_initializers/maxwellian_particle_initializer.hpp: simplified position calculations; verify correctness of (iCell + delta) * meshSize formula across all dimensions
    • Test files with ghost/AMR loop refactoring (e.g., test_electrons.cpp, test_tag_strategy.hpp): confirm AMR ghost iteration coverage is equivalent to prior nested loops
    • Python test updates: ensure GridLayout instantiation within loops and coordinate signature changes are applied consistently

Possibly related PRs

  • fix master improved #1083: Adds the for_N_make_array helper utility that this PR introduces, indicating shared refactoring goals.
  • Patchghostless #1019: Modifies GridLayout AMR-local indexing API and removes origin-based coordinate methods, directly aligned with this PR's coordinate system overhaul.
  • spatially variable hyperresistivity #893: Updates layoutFromPatch() in amr_utils.hpp to construct GridLayout with patch-level information, complementary to the GridLayout API changes here.

Suggested labels

refactoring, core, grid-layout, breaking-change

Suggested reviewers

  • nicolasaunai
  • UCaromel

Pre-merge checks and finishing touches

❌ Failed checks (1 warning)
Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 4.80% which is insufficient. The required threshold is 80.00%. You can run @coderabbitai generate docstrings to improve docstring coverage.
✅ Passed checks (2 passed)
Check name Status Explanation
Title check ✅ Passed The title 'origin made global' directly describes the main change: removing per-patch origins and standardizing coordinate calculation, aligning with the primary objective of the PR.
Description check ✅ Passed The description clearly explains the purpose: stopping use of per-patch origins, switching to AMR index and constant mesh size, and eliminating epsilon coordinate mismatches—all directly related to the changeset.
✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment

📜 Recent review details

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 6d208ea and 437b467.

📒 Files selected for processing (3)
  • src/core/utilities/point/point.hpp (1 hunks)
  • src/diagnostic/diagnostic_model_view.hpp (1 hunks)
  • tests/core/data/gridlayout/gridlayout_cell_centered_coord.hpp (3 hunks)
🚧 Files skipped from review as they are similar to previous changes (2)
  • src/diagnostic/diagnostic_model_view.hpp
  • tests/core/data/gridlayout/gridlayout_cell_centered_coord.hpp
🧰 Additional context used
📓 Path-based instructions (1)
**/*.hpp

⚙️ CodeRabbit configuration file

Review the C++ code, point out issues relative to principles of clean code, expressiveness, and performance.

Files:

  • src/core/utilities/point/point.hpp
🧠 Learnings (5)
📓 Common learnings
Learnt from: PhilipDeegan
Repo: PHAREHUB/PHARE PR: 784
File: tests/simulator/test_restarts.py:333-339
Timestamp: 2024-10-09T08:32:15.667Z
Learning: PhilipDeegan has indicated a preference for minimal and efficient code, even after making changes to get a function working. There may be opportunities to remove or optimize parts of the code such as sleep/wait/advances.
Learnt from: PhilipDeegan
Repo: PHAREHUB/PHARE PR: 784
File: tests/simulator/test_restarts.py:333-339
Timestamp: 2024-07-26T22:04:34.160Z
Learning: PhilipDeegan has indicated a preference for minimal and efficient code, even after making changes to get a function working. There may be opportunities to remove or optimize parts of the code such as sleep/wait/advances.
Learnt from: PhilipDeegan
Repo: PHAREHUB/PHARE PR: 1068
File: src/amr/data/field/coarsening/electric_field_coarsener.hpp:1-2
Timestamp: 2025-09-17T13:35:11.533Z
Learning: PhilipDeegan prefers header guard names that include the full directory path structure, following the pattern PHARE_[PATH_WITH_UNDERSCORES]_HPP. For example, a file at src/amr/data/field/coarsening/electric_field_coarsener.hpp should use PHARE_AMR_DATA_FIELD_COARSENING_ELECTRIC_FIELD_COARSENER_HPP as the header guard.
Learnt from: PhilipDeegan
Repo: PHAREHUB/PHARE PR: 888
File: src/hdf5/detail/h5/h5_file.hpp:78-79
Timestamp: 2024-10-09T08:32:15.667Z
Learning: Avoid commenting on draft PRs for the user PhilipDeegan.
Learnt from: PhilipDeegan
Repo: PHAREHUB/PHARE PR: 888
File: src/hdf5/detail/h5/h5_file.hpp:78-79
Timestamp: 2024-09-05T17:02:58.784Z
Learning: Avoid commenting on draft PRs for the user PhilipDeegan.
📚 Learning: 2025-04-17T14:41:53.643Z
Learnt from: PhilipDeegan
Repo: PHAREHUB/PHARE PR: 998
File: src/core/utilities/point/point.hpp:195-210
Timestamp: 2025-04-17T14:41:53.643Z
Learning: In `src/core/utilities/point/point.hpp`, the `as_signed()` and `as_unsigned()` methods are intentionally designed to cause compilation errors for unsupported types (only 4-byte types are supported). This forces developers to implement proper conversions themselves when extending the functionality to new types. The comment "else no return cause not yet handled" indicates this is a deliberate design choice.

Applied to files:

  • src/core/utilities/point/point.hpp
📚 Learning: 2024-09-17T13:33:47.475Z
Learnt from: PhilipDeegan
Repo: PHAREHUB/PHARE PR: 888
File: src/core/data/grid/gridlayout.hpp:805-821
Timestamp: 2024-09-17T13:33:47.475Z
Learning: In the `AMRToLocal` function, before converting to `uint32_t`, assert that `local >= 0` to ensure values are valid.

Applied to files:

  • src/core/utilities/point/point.hpp
📚 Learning: 2025-09-17T13:35:11.533Z
Learnt from: PhilipDeegan
Repo: PHAREHUB/PHARE PR: 1068
File: src/amr/data/field/coarsening/electric_field_coarsener.hpp:1-2
Timestamp: 2025-09-17T13:35:11.533Z
Learning: PhilipDeegan prefers header guard names that include the full directory path structure, following the pattern PHARE_[PATH_WITH_UNDERSCORES]_HPP. For example, a file at src/amr/data/field/coarsening/electric_field_coarsener.hpp should use PHARE_AMR_DATA_FIELD_COARSENING_ELECTRIC_FIELD_COARSENER_HPP as the header guard.

Applied to files:

  • src/core/utilities/point/point.hpp
📚 Learning: 2025-09-17T13:50:16.038Z
Learnt from: PhilipDeegan
Repo: PHAREHUB/PHARE PR: 1068
File: src/amr/data/tensorfield/tensor_field_data_factory.hpp:112-112
Timestamp: 2025-09-17T13:50:16.038Z
Learning: PhilipDeegan indicated that getSizeOfMemory returning a placeholder value of 1 in TensorFieldDataFactory is acceptable for their use case, suggesting it may not be critical for PHARE's memory management needs.

Applied to files:

  • src/core/utilities/point/point.hpp
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (6)
  • GitHub Check: build (ubuntu-latest, gcc)
  • GitHub Check: build (ubuntu-latest, clang)
  • GitHub Check: build (macos-13)
  • GitHub Check: build (macos-latest)
  • GitHub Check: build (macos-14)
  • GitHub Check: Analyze (cpp)
🔇 Additional comments (3)
src/core/utilities/point/point.hpp (3)

221-225: Clean generic conversion method.

The new as<To>() template method provides a clean, expressive API for type conversions between Point types. The delegation to toArray<To>() is straightforward and efficient.


227-235: Truncation guard fix successfully applied.

The change from sizeof(int) to sizeof(Type) on line 232 correctly addresses the truncation issue flagged in the previous review. This ensures the method only returns a value when Type is actually 4 bytes, preventing incorrect conversions for wider types.


237-242: Consistent refactor using the new conversion method.

The refactor to use as<std::int32_t>() improves consistency with the new generic conversion API and mirrors the pattern in as_unsigned().


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.

@PhilipDeegan PhilipDeegan force-pushed the omg branch 6 times, most recently from dee9ffa to ee2989c Compare October 26, 2025 17:00
Copy link

@github-advanced-security github-advanced-security bot left a comment

Choose a reason for hiding this comment

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

CodeQL found more than 20 potential problems in the proposed changes. Check the Files changed tab for more details.

@PhilipDeegan PhilipDeegan force-pushed the omg branch 2 times, most recently from 954f79d to 5ae6ae1 Compare October 29, 2025 14:52
@PhilipDeegan PhilipDeegan changed the title WIP origin made global origin made global Oct 31, 2025
@nicolasaunai
Copy link
Member

It is possible that the rounding error we fixed with this PR was responsible for the remaining mismatches identified in #1082

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

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (2)
tests/core/data/maxwellian_particle_initializer/test_maxwellian_particle_initializer.cpp (1)

70-72: Verified: inconsistent lower bound check is a real issue requiring correction.

The positionAsPoint implementation confirms that coordinates are computed as (iCell + delta) * meshSize, where iCell is a global AMR index. This means particles in the AMR box range [50, 99] with meshSize 0.1 will have positions in [5.0, 10.0]. The hardcoded lower bound of 0.0 is inconsistent with the upper bound calculation and incorrectly permits invalid particles.

The suggested fix is correct—apply the diff to use AMR-based bounds consistently on both sides.

src/core/data/grid/gridlayout.hpp (1)

454-529: Restore origin offset when computing coordinates

Removing origin_ from fieldNodeCoordinates and cellCenteredCoordinates now anchors every layout at 0, so any non-zero domain origin yields wrong physical positions for fields and cells. That breaks user configurations relying on translated meshes and can propagate errors into initialization and diagnostics. Please add the origin offset back into both helpers.

-                position[iDir] = (static_cast<double>(amr_idx[iDir]) + halfCell) * meshSize_[iDir];
+                position[iDir] = origin_[iDir]
+                                 + (static_cast<double>(amr_idx[iDir]) + halfCell) * meshSize_[iDir];
@@
-                physicalPosition[iDir]
-                    = (static_cast<double>(coord[iDir]) + halfCell) * meshSize_[iDir];
+                physicalPosition[iDir]
+                    = origin_[iDir]
+                      + (static_cast<double>(coord[iDir]) + halfCell) * meshSize_[iDir];
🧹 Nitpick comments (2)
tests/core/data/gridlayout/gridlayout_cell_centered_coord.hpp (1)

77-77: Remove unused local variable.

The layout variable is declared but never used. Remove it to keep the code minimal and efficient.

Apply this diff:

-    params.back().base = createParam<GridLayoutImpl>(dl, nbCell, Point{origin});
-    auto const& layout = *params.back().base.layout;
+    params.back().base = createParam<GridLayoutImpl>(dl, nbCell, Point{origin});

Based on learnings

src/diagnostic/diagnostic_model_view.hpp (1)

103-103: Clarify empty vector initialization.

The expression std::vector<double>(0, dimension) creates an empty vector (size 0) but is confusing because it appears to pass dimension as a value parameter that is never used. For clarity, use std::vector<double>{} or std::vector<double>(0) instead. If the intent is to return a zero-filled vector of size dimension, use std::vector<double>(dimension, 0.0).

Apply this diff for clarity:

-    NO_DISCARD auto origin() const { return std::vector<double>(0, dimension); }
+    NO_DISCARD auto origin() const { return std::vector<double>{}; }

Or if a zero-filled vector is intended:

-    NO_DISCARD auto origin() const { return std::vector<double>(0, dimension); }
+    NO_DISCARD auto origin() const { return std::vector<double>(dimension, 0.0); }
📜 Review details

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between a1bf9c5 and 6ab75d8.

📒 Files selected for processing (37)
  • pyphare/pyphare/core/gridlayout.py (1 hunks)
  • pyphare/pyphare/pharein/__init__.py (0 hunks)
  • pyphare/pyphare/pharein/maxwellian_fluid_model.py (2 hunks)
  • pyphare/pyphare/pharein/simulation.py (1 hunks)
  • src/amr/resources_manager/amr_utils.hpp (2 hunks)
  • src/amr/wrappers/hierarchy.hpp (2 hunks)
  • src/core/data/field/initializers/field_user_initializer.hpp (2 hunks)
  • src/core/data/grid/gridlayout.hpp (10 hunks)
  • src/core/data/ions/particle_initializers/maxwellian_particle_initializer.hpp (2 hunks)
  • src/core/data/particles/particle_utilities.hpp (1 hunks)
  • src/core/utilities/box/box.hpp (1 hunks)
  • src/core/utilities/point/point.hpp (1 hunks)
  • src/core/utilities/types.hpp (1 hunks)
  • src/diagnostic/diagnostic_model_view.hpp (1 hunks)
  • tests/amr/data/field/copy_pack/field_data_test_param.hpp (2 hunks)
  • tests/amr/data/field/refine/test_field_refinement_on_hierarchy.cpp (1 hunks)
  • tests/amr/data/field/refine/test_tag_strategy.hpp (1 hunks)
  • tests/amr/data/field/time_interpolate/test_field_data_time_interpolate.cpp (4 hunks)
  • tests/amr/messengers/test_messenger_tag_strategy.hpp (1 hunks)
  • tests/core/data/electrons/test_electrons.cpp (4 hunks)
  • tests/core/data/gridlayout/cellCenteredCoordinates.py (6 hunks)
  • tests/core/data/gridlayout/deriv.py (3 hunks)
  • tests/core/data/gridlayout/fieldNodeCoordinates.py (5 hunks)
  • tests/core/data/gridlayout/gridlayout_cell_centered_coord.hpp (3 hunks)
  • tests/core/data/gridlayout/gridlayout_deriv.cpp (5 hunks)
  • tests/core/data/gridlayout/gridlayout_deriv.hpp (1 hunks)
  • tests/core/data/gridlayout/gridlayout_field_centered_coord.hpp (5 hunks)
  • tests/core/data/gridlayout/gridlayout_laplacian.cpp (9 hunks)
  • tests/core/data/gridlayout/test_main.cpp (1 hunks)
  • tests/core/data/maxwellian_particle_initializer/test_maxwellian_particle_initializer.cpp (1 hunks)
  • tests/core/data/particles/test_main.cpp (1 hunks)
  • tests/core/data/particles/test_particle_array_consistency.cpp (1 hunks)
  • tests/core/numerics/ampere/test_main.cpp (10 hunks)
  • tests/core/numerics/faraday/test_main.cpp (17 hunks)
  • tests/core/numerics/ion_updater/test_updater.cpp (1 hunks)
  • tests/core/numerics/ohm/test_main.cpp (10 hunks)
  • tests/initializer/test_initializer.cpp (0 hunks)
💤 Files with no reviewable changes (2)
  • pyphare/pyphare/pharein/init.py
  • tests/initializer/test_initializer.cpp
🧰 Additional context used
📓 Path-based instructions (1)
**/*.hpp

⚙️ CodeRabbit configuration file

Review the C++ code, point out issues relative to principles of clean code, expressiveness, and performance.

Files:

  • src/core/utilities/types.hpp
  • src/core/data/particles/particle_utilities.hpp
  • src/core/utilities/box/box.hpp
  • tests/amr/data/field/copy_pack/field_data_test_param.hpp
  • src/core/data/ions/particle_initializers/maxwellian_particle_initializer.hpp
  • src/core/data/field/initializers/field_user_initializer.hpp
  • src/core/utilities/point/point.hpp
  • tests/amr/messengers/test_messenger_tag_strategy.hpp
  • src/amr/resources_manager/amr_utils.hpp
  • src/diagnostic/diagnostic_model_view.hpp
  • tests/amr/data/field/refine/test_tag_strategy.hpp
  • tests/core/data/gridlayout/gridlayout_cell_centered_coord.hpp
  • src/amr/wrappers/hierarchy.hpp
  • tests/core/data/gridlayout/gridlayout_deriv.hpp
  • tests/core/data/gridlayout/gridlayout_field_centered_coord.hpp
  • src/core/data/grid/gridlayout.hpp
🧠 Learnings (4)
📓 Common learnings
Learnt from: PhilipDeegan
Repo: PHAREHUB/PHARE PR: 784
File: tests/simulator/test_restarts.py:333-339
Timestamp: 2024-10-09T08:32:15.667Z
Learning: PhilipDeegan has indicated a preference for minimal and efficient code, even after making changes to get a function working. There may be opportunities to remove or optimize parts of the code such as sleep/wait/advances.
Learnt from: PhilipDeegan
Repo: PHAREHUB/PHARE PR: 784
File: tests/simulator/test_restarts.py:333-339
Timestamp: 2024-07-26T22:04:34.160Z
Learning: PhilipDeegan has indicated a preference for minimal and efficient code, even after making changes to get a function working. There may be opportunities to remove or optimize parts of the code such as sleep/wait/advances.
Learnt from: PhilipDeegan
Repo: PHAREHUB/PHARE PR: 1068
File: src/amr/data/field/coarsening/electric_field_coarsener.hpp:1-2
Timestamp: 2025-09-17T13:35:11.533Z
Learning: PhilipDeegan prefers header guard names that include the full directory path structure, following the pattern PHARE_[PATH_WITH_UNDERSCORES]_HPP. For example, a file at src/amr/data/field/coarsening/electric_field_coarsener.hpp should use PHARE_AMR_DATA_FIELD_COARSENING_ELECTRIC_FIELD_COARSENER_HPP as the header guard.
Learnt from: PhilipDeegan
Repo: PHAREHUB/PHARE PR: 888
File: src/hdf5/detail/h5/h5_file.hpp:78-79
Timestamp: 2024-10-09T08:32:15.667Z
Learning: Avoid commenting on draft PRs for the user PhilipDeegan.
Learnt from: PhilipDeegan
Repo: PHAREHUB/PHARE PR: 888
File: src/hdf5/detail/h5/h5_file.hpp:78-79
Timestamp: 2024-09-05T17:02:58.784Z
Learning: Avoid commenting on draft PRs for the user PhilipDeegan.
📚 Learning: 2025-09-01T09:41:40.618Z
Learnt from: PhilipDeegan
Repo: PHAREHUB/PHARE PR: 1056
File: tests/core/numerics/interpolator/test_main.cpp:314-318
Timestamp: 2025-09-01T09:41:40.618Z
Learning: The PHARE project uses C++20, which makes the typename keyword optional for dependent types in obvious contexts. The project prefers minimal code without unnecessary keywords, so typename suggestions for dependent types should be avoided when the code compiles successfully in C++20.

Applied to files:

  • src/core/utilities/types.hpp
  • tests/core/data/particles/test_particle_array_consistency.cpp
  • tests/core/data/electrons/test_electrons.cpp
📚 Learning: 2025-02-06T10:52:56.461Z
Learnt from: rochSmets
Repo: PHAREHUB/PHARE PR: 921
File: src/core/data/ions/ions.hpp:138-142
Timestamp: 2025-02-06T10:52:56.461Z
Learning: In PHARE's physics simulations, handling of zero density cells in velocity calculations must be based on physical requirements rather than simple numerical fixes. The solution must account for population-specific behavior in the bulk velocity computation.

Applied to files:

  • src/core/data/ions/particle_initializers/maxwellian_particle_initializer.hpp
  • tests/core/data/particles/test_particle_array_consistency.cpp
📚 Learning: 2025-04-17T14:41:53.643Z
Learnt from: PhilipDeegan
Repo: PHAREHUB/PHARE PR: 998
File: src/core/utilities/point/point.hpp:195-210
Timestamp: 2025-04-17T14:41:53.643Z
Learning: In `src/core/utilities/point/point.hpp`, the `as_signed()` and `as_unsigned()` methods are intentionally designed to cause compilation errors for unsupported types (only 4-byte types are supported). This forces developers to implement proper conversions themselves when extending the functionality to new types. The comment "else no return cause not yet handled" indicates this is a deliberate design choice.

Applied to files:

  • src/core/data/field/initializers/field_user_initializer.hpp
  • src/core/utilities/point/point.hpp
  • src/amr/resources_manager/amr_utils.hpp
🧬 Code graph analysis (20)
src/core/data/particles/particle_utilities.hpp (2)
tests/amr/data/field/refine/test_tag_strategy.hpp (2)
  • position (205-227)
  • position (205-205)
src/core/data/particles/particle_packer.hpp (1)
  • particle (27-27)
tests/core/data/gridlayout/cellCenteredCoordinates.py (1)
pyphare/pyphare/core/gridlayout.py (4)
  • localPointToAMR (314-317)
  • physicalStartIndex (262-264)
  • physicalEndIndex (266-272)
  • isDual (247-251)
src/core/data/ions/particle_initializers/maxwellian_particle_initializer.hpp (2)
src/core/data/grid/gridlayout.hpp (2)
  • indices (232-239)
  • indices (232-232)
src/core/utilities/types.hpp (2)
  • for_N_make_array (486-489)
  • for_N_make_array (486-486)
src/core/data/field/initializers/field_user_initializer.hpp (2)
src/core/data/grid/gridlayout.hpp (2)
  • indices (232-239)
  • indices (232-232)
tests/core/data/gridlayout/gridlayout_field_centered_coord.hpp (1)
  • field (24-37)
tests/amr/messengers/test_messenger_tag_strategy.hpp (1)
tests/core/data/gridlayout/gridlayout_field_centered_coord.hpp (1)
  • field (24-37)
pyphare/pyphare/core/gridlayout.py (4)
src/core/data/particles/particle_array.hpp (2)
  • box (232-232)
  • box (232-232)
src/core/utilities/cellmap.hpp (4)
  • box (189-189)
  • box (189-189)
  • box (190-190)
  • box (190-190)
src/core/data/grid/gridlayout.hpp (4)
  • physicalStartIndex (316-319)
  • physicalStartIndex (316-316)
  • physicalStartIndex (322-326)
  • physicalStartIndex (322-322)
pyphare/pyphare/simulator/simulator.py (1)
  • interp_order (283-285)
tests/core/data/gridlayout/fieldNodeCoordinates.py (1)
pyphare/pyphare/core/gridlayout.py (3)
  • fieldCoords (402-414)
  • qtyCentering (224-225)
  • GridLayout (168-437)
src/amr/resources_manager/amr_utils.hpp (2)
src/core/utilities/types.hpp (2)
  • for_N_make_array (486-489)
  • for_N_make_array (486-486)
src/amr/data/field/field_data_factory.hpp (2)
  • patch (65-78)
  • patch (66-66)
src/diagnostic/diagnostic_model_view.hpp (3)
src/core/utilities/point/point.hpp (1)
  • vector (101-104)
src/amr/resources_manager/resources_manager.hpp (1)
  • dimension (85-294)
src/core/data/grid/gridlayoutimplyee.hpp (3)
  • dimension (994-1016)
  • dimension (1020-1042)
  • dimension (1046-1068)
tests/core/data/particles/test_main.cpp (1)
src/core/data/particles/particle_utilities.hpp (2)
  • positionAsPoint (19-29)
  • positionAsPoint (19-20)
tests/core/data/gridlayout/gridlayout_deriv.cpp (4)
tests/core/data/gridlayout/gridlayout_deriv.hpp (1)
  • read (20-20)
tests/core/numerics/ampere/test_main.cpp (2)
  • read (110-119)
  • read (110-110)
tests/core/numerics/faraday/test_main.cpp (2)
  • read (124-133)
  • read (124-124)
tests/core/numerics/ohm/test_main.cpp (2)
  • read (326-335)
  • read (326-326)
tests/core/data/gridlayout/deriv.py (1)
pyphare/pyphare/core/gridlayout.py (1)
  • GridLayout (168-437)
pyphare/pyphare/pharein/maxwellian_fluid_model.py (2)
pyphare/pyphare/core/gridlayout.py (1)
  • GridLayout (168-437)
pyphare/pyphare/simulator/simulator.py (2)
  • domain_box (275-277)
  • interp_order (283-285)
tests/amr/data/field/refine/test_tag_strategy.hpp (2)
tests/core/data/gridlayout/gridlayout_field_centered_coord.hpp (1)
  • field (24-37)
src/amr/messengers/hybrid_hybrid_messenger_strategy.hpp (4)
  • field (929-956)
  • field (929-930)
  • field (958-964)
  • field (958-958)
tests/core/data/gridlayout/gridlayout_cell_centered_coord.hpp (1)
tests/core/data/gridlayout/gridlayout_params.hpp (2)
  • createParam (54-64)
  • createParam (54-56)
tests/core/data/particles/test_particle_array_consistency.cpp (1)
src/core/data/particles/particle_array.hpp (10)
  • box (232-232)
  • box (232-232)
  • i (75-75)
  • i (75-75)
  • i (76-76)
  • i (76-76)
  • i (305-305)
  • i (305-305)
  • i (306-306)
  • i (306-306)
tests/core/data/gridlayout/gridlayout_field_centered_coord.hpp (2)
tests/core/data/gridlayout/gridlayout_cell_centered_coord.hpp (1)
  • field (27-40)
tests/core/data/gridlayout/gridlayout_params.hpp (2)
  • createParam (54-64)
  • createParam (54-56)
tests/amr/data/field/refine/test_field_refinement_on_hierarchy.cpp (3)
tests/amr/data/field/refine/test_tag_strategy.hpp (4)
  • hierarchy (146-197)
  • hierarchy (146-151)
  • position (205-227)
  • position (205-205)
tests/amr/resources_manager/test_resources_manager_basic_hierarchy.hpp (2)
  • init (47-79)
  • init (47-47)
src/core/data/field/initializers/field_user_initializer.hpp (2)
  • initialize (18-35)
  • initialize (18-19)
tests/core/data/electrons/test_electrons.cpp (3)
tests/core/data/gridlayout/gridlayout_field_centered_coord.hpp (1)
  • field (24-37)
tests/core/data/gridlayout/gridlayout_cell_centered_coord.hpp (1)
  • field (27-40)
src/amr/messengers/hybrid_hybrid_messenger_strategy.hpp (4)
  • field (929-956)
  • field (929-930)
  • field (958-964)
  • field (958-958)
src/core/data/grid/gridlayout.hpp (5)
src/core/utilities/box/box.hpp (7)
  • box (51-51)
  • grow (89-94)
  • grow (89-89)
  • grow (272-277)
  • grow (272-272)
  • that (69-72)
  • that (69-69)
src/amr/data/field/field_geometry.hpp (4)
  • box (136-179)
  • box (136-137)
  • box (198-207)
  • box (198-198)
src/core/utilities/types.hpp (19)
  • generate (273-284)
  • generate (273-273)
  • generate (287-290)
  • generate (287-287)
  • generate (294-304)
  • generate (294-294)
  • generate (307-310)
  • generate (307-307)
  • generate (326-329)
  • generate (326-326)
  • for_N (445-476)
  • for_N (445-445)
  • for_N (479-482)
  • for_N (479-479)
  • auto (151-156)
  • auto (492-495)
  • auto (498-501)
  • for_N_make_array (486-489)
  • for_N_make_array (486-486)
src/core/utilities/point/point.hpp (5)
  • i (68-68)
  • i (68-68)
  • i (69-69)
  • i (69-69)
  • auto (211-211)
src/amr/messengers/hybrid_hybrid_messenger_strategy.hpp (4)
  • field (929-956)
  • field (929-930)
  • field (958-964)
  • field (958-958)
🪛 Ruff (0.14.3)
pyphare/pyphare/pharein/simulation.py

968-968: zip() without an explicit strict= parameter

Add explicit value for parameter strict=

(B905)

⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (7)
  • GitHub Check: Analyze (python)
  • GitHub Check: Analyze (cpp)
  • GitHub Check: build (ubuntu-latest, gcc)
  • GitHub Check: build (ubuntu-latest, clang)
  • GitHub Check: build (macos-14)
  • GitHub Check: build (macos-13)
  • GitHub Check: build (macos-latest)
🔇 Additional comments (58)
tests/core/data/particles/test_particle_array_consistency.cpp (1)

30-32: LGTM! Variable rename improves clarity, dereferencing is safe.

The rename from bix to amr_idx better reflects the PR's shift to AMR-index-based coordinates. The box iterator's operator*() returns a direct reference to its index_ member variable, making the dereferencing inherently safe—no null pointer or invalidation risks.

tests/core/data/particles/test_main.cpp (1)

83-83: LGTM! Simplified to use AMR indices directly.

The direct use of part.iCell aligns with the PR's objective of using AMR indices instead of per-patch coordinate transformations. This simplification is correct and consistent with the new positionAsPoint utility function.

tests/core/data/maxwellian_particle_initializer/test_maxwellian_particle_initializer.cpp (2)

68-68: LGTM! Correctly calculates upper boundary using AMR indices.

The updated calculation properly computes the physical coordinate of the domain's upper boundary using the AMR index directly, eliminating the dependency on per-patch origins. This aligns with the PR's objective.


31-31: ****

The origin parameter is not deprecated. The GridLayout constructor still requires the origin parameter as its third argument, and it is actively stored in the member initializer list. The test setup at line 31 is correct as-is. This PR changes AMR-based calculations but does not modify the constructor signature or remove the origin parameter.

Likely an incorrect or invalid review comment.

src/core/utilities/box/box.hpp (1)

28-28: LGTM!

The type alias relocation improves code organization by placing the member type definition early in the struct, following common C++ conventions.

pyphare/pyphare/pharein/simulation.py (1)

968-968: LGTM!

The domain calculation now correctly removes origin-based offsets, aligning with the PR's goal of using AMR-based coordinates. The zip() usage is safe here since self.dl and self.cells are validated to have equal length by check_domain() earlier.

src/core/data/particles/particle_utilities.hpp (1)

19-29: LGTM!

The simplified coordinate computation correctly uses AMR index space directly with mesh size, eliminating origin-based offsets. The function documentation clearly states the AMR index space assumption, which is essential for correctness.

src/core/utilities/point/point.hpp (1)

221-241: LGTM!

The new templated as<To>() method provides a clean, reusable conversion mechanism. The updated as_unsigned() and as_signed() methods now leverage this helper, improving code maintainability while preserving the intentional compile-time enforcement for unsupported types.

src/core/data/field/initializers/field_user_initializer.hpp (2)

6-10: LGTM!

The added includes support the new AMR-local indexing pattern used in the field initialization.


21-34: LGTM!

The refactored initialization correctly adopts AMR-aware local indexing:

  • Uses AMRGhostBoxFor(field) to obtain the AMR ghost box
  • Computes coordinates without origin offsets via fieldNodeCoordinates(field_, args...)
  • Transforms AMR indices to local indices via AMRToLocal(Point{args...})

This aligns with the PR's goal of eliminating origin-based coordinate calculations.

tests/core/numerics/faraday/test_main.cpp (2)

30-30: LGTM!

The const qualifier reordering improves consistency with modern C++ style conventions.

Also applies to: 44-44, 58-58


237-242: LGTM!

The test updates correctly adapt to the new AMR-space coordinate API by converting local indices to AMR space via layout.localToAMR(Point{...}.as_signed()) before passing to fieldNodeCoordinates(). This pattern is consistent across all dimensions (1D, 2D, 3D) and aligns with the PR's objective to use AMR-based indexing.

Also applies to: 249-254, 299-303, 310-314, 321-325, 332-336, 343-347, 354-358, 444-449, 460-465, 476-481, 492-496, 507-511, 522-526

tests/amr/data/field/refine/test_tag_strategy.hpp (1)

180-186: LGTM!

The refactored field initialization elegantly consolidates dimension-specific logic into a unified AMR-aware pattern:

  • Iterates over AMRGhostBoxFor(field) to obtain AMR indices
  • Computes coordinates via fieldNodeCoordinates(field, amr_idx) without origin
  • Transforms to local indices via AMRToLocal(amr_idx)

This simplification improves maintainability and aligns with the PR's AMR-local indexing approach.

tests/core/data/electrons/test_electrons.cpp (3)

26-26: LGTM!

The const qualifier reordering improves consistency with modern C++ style.


228-244: LGTM!

The 1D field initialization correctly adopts the AMR-local indexing pattern using layout.ghost_amr_lcl_idx(field), which elegantly provides both AMR and local indices in a single iteration. Coordinates are computed via fieldNodeCoordinates(field, amr_idx) without origin offsets.


248-266: LGTM!

The 2D and 3D field initialization correctly adopts the AMR-local indexing pattern:

  • Iterates over AMRGhostBoxFor(field) to obtain AMR indices
  • Computes coordinates via fieldNodeCoordinates(field, amr_idx) without origin
  • Transforms to local indices via AMRToLocal(amr_idx) for field access

This is consistent with the PR's shift to AMR-based coordinate handling.

Also applies to: 269-300

tests/core/data/gridlayout/cellCenteredCoordinates.py (4)

33-41: LGTM! Good defensive coding with assertions.

The transformation to AMR-local indexing is correct, and the assertions validating non-negative indices and proper ordering are helpful safeguards.


44-58: LGTM! Consistent AMR-local indexing for 2D.

The separate computation for X and Y dimensions using localPointToAMR is correct and aligns with the PR's objective of removing origin-based coordinate handling.


95-98: LGTM! Simplified coordinate calculation aligns with PR objectives.

The refactored signature and implementation correctly compute cell-centered coordinates using AMR-local indices, eliminating the need for origin and startIndex parameters.


156-156: No issues found with GridLayout instantiation.

The GridLayout is intentionally instantiated with only interp_order for this test utility script. The coordinate transformation methods (localPointToAMR, physicalStartIndex, etc.) depend on interp_order and centering, not on the box or dl parameters. The default Box(0, 0) contributes box.lower = 0 to the calculation, which does not affect the results since it's added and then effectively neutralized. The actual grid parameters (dl, nbrCell) are properly stored in the separate CenteredCoordParams object. This pattern is consistent with similar coordinate generation scripts in the codebase (deriv.py, fieldNodeCoordinates.py).

pyphare/pyphare/core/gridlayout.py (1)

314-317: LGTM! Correct local-to-AMR coordinate transformation.

The localPointToAMR method properly converts local patch coordinates to AMR global coordinates by adding the box's lower bound and subtracting the local physical start index. This is the inverse of AMRPointToLocal and aligns with the PR's AMR-aware indexing approach.

pyphare/pyphare/pharein/maxwellian_fluid_model.py (2)

199-199: Verify zero-origin assumption is correct for all validation scenarios.

The GridLayout now uses domain_box.lower (which is [0] for 1D) instead of sim.origin. This assumes the validation domain always starts at zero, which aligns with the PR's goal of removing per-patch origins. Ensure this assumption holds for all simulation configurations.


239-239: Consistent with validate1d changes.

The same zero-origin pattern is applied for 2D validation, maintaining consistency with the validate1d changes.

tests/core/data/gridlayout/gridlayout_cell_centered_coord.hpp (1)

21-21: LGTM! Point type is more semantically appropriate.

The change from std::array<std::uint32_t, ...> to Point<int, ...> improves semantic clarity for coordinate/index representation and aligns with the Point-based coordinate system introduced in this PR.

src/amr/wrappers/hierarchy.hpp (2)

266-268: Hardcoded zero-origin assumption is intentional.

The domain lower bound is now always set to 0, eliminating the need for origin configuration. This is a fundamental change aligning with the PR's goal of using AMR indices with constant mesh sizes. The upper bound is correctly computed as lower + nbr_cells * mesh_size.


97-97: The removal of hierarchy.origin() is clean and complete.

Verification confirms no remaining calls to hierarchy.origin() exist in the codebase. The broader references to "origin" are for other classes (GridLayout, diagnostic_model_view, PatchData) and are unrelated to the hierarchy class. The breaking API change has been properly handled.

tests/core/data/gridlayout/test_main.cpp (1)

2-6: LGTM! Good cleanup of unused includes.

Removing unused includes reduces dependencies and improves compilation time. The test main now only includes what it needs.

Based on learnings

tests/amr/messengers/test_messenger_tag_strategy.hpp (1)

32-33: LGTM! Simplified coordinate query aligns with PR objectives.

The removal of the origin parameter from fieldNodeCoordinates simplifies the API and is consistent with the PR's shift to AMR-local indexing. The coordinate calculation now relies solely on the field and index.

src/core/utilities/types.hpp (1)

485-489: LGTM! Clean convenience wrapper.

The for_N_make_array helper provides a cleaner API for the common pattern of calling for_N with make_array mode, reducing boilerplate across the codebase.

tests/amr/data/field/copy_pack/field_data_test_param.hpp (2)

89-97: LGTM! Coordinate calculation simplified.

The change to use fieldNodeCoordinates(field, iCell) directly eliminates the origin parameter, aligning with the AMR-local indexing approach introduced across the PR.


104-112: LGTM! Consistent with sourceFill changes.

The destination fill logic mirrors the source fill simplification, removing origin-based coordinate handling.

tests/core/data/gridlayout/gridlayout_laplacian.cpp (2)

34-36: LGTM! AMR-local coordinate transformation applied.

The updated call wraps the point indices with localToAMR, ensuring coordinates are computed in the AMR coordinate system rather than raw local indices.


63-65: LGTM! Consistent AMR-local coordinate transformations.

All fieldNodeCoordinates calls have been consistently updated to use layout.localToAMR(Point{...}.as_signed()), ensuring uniform AMR-aware coordinate handling across 1D, 2D, and 3D test cases.

Also applies to: 92-94, 137-139, 180-182, 223-225, 284-286, 339-341, 394-396

tests/core/numerics/ohm/test_main.cpp (1)

103-104: LGTM! AMR-local coordinate system consistently applied.

All fieldNodeCoordinates calls have been systematically updated to use layout.localToAMR(Point{...}.as_signed()) across 1D, 2D, and 3D test setup, ensuring uniform AMR-aware indexing throughout the OhmTest fixture.

Also applies to: 118-119, 142-143, 154-156, 165-167, 173-175, 202-203, 218-219, 229-230, 237-238, 251-252, 259-260, 270-271

tests/core/numerics/ion_updater/test_updater.cpp (1)

622-628: LGTM! AMR-local iteration improves correctness.

The switch to layout.amr_lcl_idx() iteration ensures the density check uses only complete interpolation domains, avoiding the incomplete last primal cell. Using amr_idx for coordinates and lcl_idx for array indexing is the correct pattern.

tests/core/data/gridlayout/fieldNodeCoordinates.py (3)

24-30: LGTM! Signature simplified to remove origin dependency.

The fieldCoords function now takes a GridLayout instance (gl) directly and removes the startIndex and origin parameters. The coordinate calculation is simplified to (primalIndex + halfCell) * dl, relying on the GridLayout for centering information. This aligns with the PR's goal of eliminating origin-based coordinate calculations.


101-101: LGTM! GridLayout instantiated per interpolation order.

Creating a GridLayout instance per interpolation order and passing it to fieldCoords is the correct pattern for the updated API.


152-153: LGTM! All call sites updated consistently.

All fieldCoords calls have been updated to pass the gl parameter and remove the obsolete startIndex and origin arguments, ensuring consistent usage across 1D, 2D, and 3D test cases.

Also applies to: 164-166, 185-192

src/core/data/ions/particle_initializers/maxwellian_particle_initializer.hpp (2)

141-147: LGTM! Generic dimension handling eliminates branches.

The icell and deltas helpers using for_N_make_array provide clean, dimension-agnostic implementations that replace explicit 1D/2D/3D branches. This improves maintainability and aligns with the minimal, efficient code style preferred in this codebase.

Based on learnings


153-153: LGTM! AMR box indexing replaces physical domain iteration.

Switching from physicalStartToEndIndices to layout.indices(layout.AMRBox()) aligns with the AMR-local indexing approach introduced across the PR, ensuring consistent coordinate handling.

tests/core/data/gridlayout/gridlayout_deriv.hpp (1)

28-28: LGTM! Type alias improves API accessibility.

Adding the public GridLayout_t alias exposes the layout type to external code without changing any behavior. This is a clean refactor that improves the test fixture API.

Also applies to: 50-50, 72-72

src/amr/resources_manager/amr_utils.hpp (2)

6-6: LGTM: Include reordering for consistency.

The include reordering is a minor cleanup with no functional impact.


164-196: Well-structured refactor using generic utilities.

The refactored layoutFromPatch simplifies the logic by:

  • Eliminating explicit dimension branches
  • Using for_N_make_array uniformly for dl, origin, and nbrCell computation
  • Providing sensible fallbacks (1.0, 0.0) for temporary patches without geometry

This aligns well with the PR's goal of removing per-patch origin handling and is more maintainable.

tests/core/data/gridlayout/gridlayout_field_centered_coord.hpp (4)

19-19: Type change aligns with AMR-local indexing.

The change from std::array<std::uint32_t, ...> to Point<int, ...> is appropriate for AMR coordinates, which can be negative in AMR-local index spaces.


34-35: Simplified coordinate computation using layout API.

The direct use of layout->fieldNodeCoordinates is cleaner than the previous manual computation and aligns with the PR's move toward layout-driven coordinate handling.


61-61: LGTM: Const qualifier placement style change.

The change from const std::map<...> to std::map<...> const is stylistic (east-const vs west-const) with no functional impact.


107-109: Good defensive practice with bounds checking.

The assertion ensures hqIndex is within bounds before accessing the params array, preventing potential out-of-bounds access.

tests/core/data/gridlayout/deriv.py (2)

116-116: GridLayout instantiation updated for per-order configuration.

Creating a GridLayout instance per interpolation order with the explicit interp_order parameter is appropriate for the test structure.


183-183: fieldCoords API updated to use GridLayout object.

The updated signature passing gl (GridLayout instance) instead of origin aligns with the PR's goal of removing origin-based coordinate computation and using layout-driven coordinates.

Also applies to: 198-198

tests/amr/data/field/time_interpolate/test_field_data_time_interpolate.cpp (4)

84-85: Good const correctness for time constants.

Making oldTime and newTime const improves code clarity and prevents accidental modification.


94-116: Excellent refactor to AMR-aware iteration pattern.

The refactored initialization:

  • Uses unified AMRGhostBoxFor iteration instead of nested dimension-specific loops
  • Computes position and local indices once per cell
  • Provides cleaner, more maintainable code

This aligns well with the PR's goal of using AMR-local indexing throughout.


119-119: Const correctness for zeroTransformation method.

Making zeroTransformation() a const method is appropriate since it doesn't modify object state.


310-343: Clean AMR-aware iteration for interpolation verification.

The refactored test:

  • Uses structured bindings for amr_idx/lcl_idx pairs from domain_amr_lcl_idx
  • Computes position from AMR indices and accesses fields via local indices
  • Includes const correctness for interpolateTime

This is a clean, modern approach consistent with the PR's AMR-local indexing pattern.

tests/core/data/gridlayout/gridlayout_deriv.cpp (5)

11-11: Const correctness for filename parameter.

Making the filename parameter const is appropriate and consistent with similar read functions elsewhere in the test suite.


34-52: Well-structured refactor to AMR-local indexing for 1D tests.

The refactored test demonstrates the new pattern:

  • Structured bindings for amr_idx/lcl_idx pairs
  • Coordinates computed from AMR indices via fieldNodeCoordinates
  • Field access via local indices
  • Const correctness for test data

This is clean and maintainable.


88-182: Consistent AMR-local indexing pattern for 2D tests.

All 2D derivative tests follow the unified pattern:

  • AMR-aware iteration with structured bindings
  • Coordinates from fieldNodeCoordinates with AMR indices
  • Field access via local indices
  • Correct 2D index flattening using allocSizeDerived for stride calculation

The consistency across tests is excellent.


197-344: Comprehensive 3D test coverage with AMR-local indexing.

All six 3D derivative tests (DXBY3D, DYBY3D, DZBY3D, DXEZ3D, DYEZ3D, DZEZ3D) follow the unified AMR-local indexing pattern with correct 3D index flattening. The consistency and coverage are excellent.


77-79: Comment markers are section headers, tests are active.

These comment markers (lines 77-79, 186-188) serve as section headers for 2D and 3D test cases. All tests are active and functional, not commented out. This addresses the previous review question about commented tests.

Also applies to: 186-188

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: 3

📜 Review details

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 6ab75d8 and 6d208ea.

📒 Files selected for processing (37)
  • pyphare/pyphare/core/gridlayout.py (1 hunks)
  • pyphare/pyphare/pharein/__init__.py (0 hunks)
  • pyphare/pyphare/pharein/maxwellian_fluid_model.py (2 hunks)
  • pyphare/pyphare/pharein/simulation.py (1 hunks)
  • src/amr/resources_manager/amr_utils.hpp (2 hunks)
  • src/amr/wrappers/hierarchy.hpp (2 hunks)
  • src/core/data/field/initializers/field_user_initializer.hpp (2 hunks)
  • src/core/data/grid/gridlayout.hpp (10 hunks)
  • src/core/data/ions/particle_initializers/maxwellian_particle_initializer.hpp (2 hunks)
  • src/core/data/particles/particle_utilities.hpp (1 hunks)
  • src/core/utilities/box/box.hpp (1 hunks)
  • src/core/utilities/point/point.hpp (1 hunks)
  • src/core/utilities/types.hpp (1 hunks)
  • src/diagnostic/diagnostic_model_view.hpp (1 hunks)
  • tests/amr/data/field/copy_pack/field_data_test_param.hpp (2 hunks)
  • tests/amr/data/field/refine/test_field_refinement_on_hierarchy.cpp (1 hunks)
  • tests/amr/data/field/refine/test_tag_strategy.hpp (1 hunks)
  • tests/amr/data/field/time_interpolate/test_field_data_time_interpolate.cpp (4 hunks)
  • tests/amr/messengers/test_messenger_tag_strategy.hpp (1 hunks)
  • tests/core/data/electrons/test_electrons.cpp (4 hunks)
  • tests/core/data/gridlayout/cellCenteredCoordinates.py (6 hunks)
  • tests/core/data/gridlayout/deriv.py (3 hunks)
  • tests/core/data/gridlayout/fieldNodeCoordinates.py (5 hunks)
  • tests/core/data/gridlayout/gridlayout_cell_centered_coord.hpp (3 hunks)
  • tests/core/data/gridlayout/gridlayout_deriv.cpp (5 hunks)
  • tests/core/data/gridlayout/gridlayout_deriv.hpp (1 hunks)
  • tests/core/data/gridlayout/gridlayout_field_centered_coord.hpp (5 hunks)
  • tests/core/data/gridlayout/gridlayout_laplacian.cpp (9 hunks)
  • tests/core/data/gridlayout/test_main.cpp (1 hunks)
  • tests/core/data/maxwellian_particle_initializer/test_maxwellian_particle_initializer.cpp (1 hunks)
  • tests/core/data/particles/test_main.cpp (1 hunks)
  • tests/core/data/particles/test_particle_array_consistency.cpp (1 hunks)
  • tests/core/numerics/ampere/test_main.cpp (10 hunks)
  • tests/core/numerics/faraday/test_main.cpp (17 hunks)
  • tests/core/numerics/ion_updater/test_updater.cpp (1 hunks)
  • tests/core/numerics/ohm/test_main.cpp (10 hunks)
  • tests/initializer/test_initializer.cpp (0 hunks)
💤 Files with no reviewable changes (2)
  • pyphare/pyphare/pharein/init.py
  • tests/initializer/test_initializer.cpp
🚧 Files skipped from review as they are similar to previous changes (14)
  • tests/amr/data/field/copy_pack/field_data_test_param.hpp
  • pyphare/pyphare/pharein/maxwellian_fluid_model.py
  • src/core/data/field/initializers/field_user_initializer.hpp
  • tests/core/data/gridlayout/fieldNodeCoordinates.py
  • tests/core/data/gridlayout/deriv.py
  • tests/core/data/particles/test_main.cpp
  • tests/core/data/gridlayout/gridlayout_cell_centered_coord.hpp
  • pyphare/pyphare/pharein/simulation.py
  • tests/core/data/gridlayout/gridlayout_laplacian.cpp
  • tests/core/data/gridlayout/test_main.cpp
  • tests/amr/messengers/test_messenger_tag_strategy.hpp
  • src/core/utilities/types.hpp
  • tests/amr/data/field/refine/test_field_refinement_on_hierarchy.cpp
  • tests/core/numerics/ampere/test_main.cpp
🧰 Additional context used
📓 Path-based instructions (1)
**/*.hpp

⚙️ CodeRabbit configuration file

Review the C++ code, point out issues relative to principles of clean code, expressiveness, and performance.

Files:

  • src/core/data/particles/particle_utilities.hpp
  • src/core/utilities/box/box.hpp
  • tests/amr/data/field/refine/test_tag_strategy.hpp
  • src/amr/resources_manager/amr_utils.hpp
  • src/core/utilities/point/point.hpp
  • src/diagnostic/diagnostic_model_view.hpp
  • tests/core/data/gridlayout/gridlayout_field_centered_coord.hpp
  • src/amr/wrappers/hierarchy.hpp
  • tests/core/data/gridlayout/gridlayout_deriv.hpp
  • src/core/data/grid/gridlayout.hpp
  • src/core/data/ions/particle_initializers/maxwellian_particle_initializer.hpp
🧠 Learnings (4)
📓 Common learnings
Learnt from: PhilipDeegan
Repo: PHAREHUB/PHARE PR: 784
File: tests/simulator/test_restarts.py:333-339
Timestamp: 2024-10-09T08:32:15.667Z
Learning: PhilipDeegan has indicated a preference for minimal and efficient code, even after making changes to get a function working. There may be opportunities to remove or optimize parts of the code such as sleep/wait/advances.
Learnt from: PhilipDeegan
Repo: PHAREHUB/PHARE PR: 784
File: tests/simulator/test_restarts.py:333-339
Timestamp: 2024-07-26T22:04:34.160Z
Learning: PhilipDeegan has indicated a preference for minimal and efficient code, even after making changes to get a function working. There may be opportunities to remove or optimize parts of the code such as sleep/wait/advances.
Learnt from: PhilipDeegan
Repo: PHAREHUB/PHARE PR: 1068
File: src/amr/data/field/coarsening/electric_field_coarsener.hpp:1-2
Timestamp: 2025-09-17T13:35:11.533Z
Learning: PhilipDeegan prefers header guard names that include the full directory path structure, following the pattern PHARE_[PATH_WITH_UNDERSCORES]_HPP. For example, a file at src/amr/data/field/coarsening/electric_field_coarsener.hpp should use PHARE_AMR_DATA_FIELD_COARSENING_ELECTRIC_FIELD_COARSENER_HPP as the header guard.
Learnt from: PhilipDeegan
Repo: PHAREHUB/PHARE PR: 888
File: src/hdf5/detail/h5/h5_file.hpp:78-79
Timestamp: 2024-10-09T08:32:15.667Z
Learning: Avoid commenting on draft PRs for the user PhilipDeegan.
Learnt from: PhilipDeegan
Repo: PHAREHUB/PHARE PR: 888
File: src/hdf5/detail/h5/h5_file.hpp:78-79
Timestamp: 2024-09-05T17:02:58.784Z
Learning: Avoid commenting on draft PRs for the user PhilipDeegan.
📚 Learning: 2025-09-01T09:41:40.618Z
Learnt from: PhilipDeegan
Repo: PHAREHUB/PHARE PR: 1056
File: tests/core/numerics/interpolator/test_main.cpp:314-318
Timestamp: 2025-09-01T09:41:40.618Z
Learning: The PHARE project uses C++20, which makes the typename keyword optional for dependent types in obvious contexts. The project prefers minimal code without unnecessary keywords, so typename suggestions for dependent types should be avoided when the code compiles successfully in C++20.

Applied to files:

  • tests/core/data/particles/test_particle_array_consistency.cpp
  • tests/core/data/electrons/test_electrons.cpp
📚 Learning: 2025-02-06T10:52:56.461Z
Learnt from: rochSmets
Repo: PHAREHUB/PHARE PR: 921
File: src/core/data/ions/ions.hpp:138-142
Timestamp: 2025-02-06T10:52:56.461Z
Learning: In PHARE's physics simulations, handling of zero density cells in velocity calculations must be based on physical requirements rather than simple numerical fixes. The solution must account for population-specific behavior in the bulk velocity computation.

Applied to files:

  • tests/core/data/particles/test_particle_array_consistency.cpp
  • src/core/data/ions/particle_initializers/maxwellian_particle_initializer.hpp
📚 Learning: 2025-04-17T14:41:53.643Z
Learnt from: PhilipDeegan
Repo: PHAREHUB/PHARE PR: 998
File: src/core/utilities/point/point.hpp:195-210
Timestamp: 2025-04-17T14:41:53.643Z
Learning: In `src/core/utilities/point/point.hpp`, the `as_signed()` and `as_unsigned()` methods are intentionally designed to cause compilation errors for unsupported types (only 4-byte types are supported). This forces developers to implement proper conversions themselves when extending the functionality to new types. The comment "else no return cause not yet handled" indicates this is a deliberate design choice.

Applied to files:

  • src/amr/resources_manager/amr_utils.hpp
  • src/core/utilities/point/point.hpp
🔇 Additional comments (17)
tests/core/data/particles/test_particle_array_consistency.cpp (1)

28-33: LGTM! Variable rename improves clarity.

The rename from bix to amr_idx better reflects the AMR-aware indexing approach and aligns with the PR's objective of replacing origin-based coordinate computations with explicit AMR indexing.

src/core/utilities/box/box.hpp (1)

28-28: LGTM! Clean consolidation of type alias.

Moving value_type to the top of the struct and removing the duplicate declaration improves code organization and follows standard C++ conventions.

src/core/data/particles/particle_utilities.hpp (2)

15-18: Good documentation of the AMR index space assumption.

The comment clearly states the critical assumption that iCell must be in AMR index space. This is essential for understanding the simplified logic below.


24-27: Simplified calculation aligns with PR objectives and improves performance.

The direct calculation (particle.iCell[iDim] + particle.delta[iDim]) * meshSize[iDim] eliminates intermediate origin and index transformations, which should reduce floating-point rounding errors and potential epsilon mismatches—exactly as intended by this PR. The code is also cleaner and more performant.

However, verify that all call sites of positionAsPoint ensure that particle.iCell is correctly populated in AMR index space, as this is now a hard requirement.

Run the following script to identify all call sites and verify the assumption:

tests/core/data/maxwellian_particle_initializer/test_maxwellian_particle_initializer.cpp (1)

68-68: Correct calculation using AMR-aware indexing.

The new calculation derives the physical domain extent directly from AMR box geometry rather than origin offsets, which aligns with the PR's goal of eliminating potential epsilon coordinate mismatches. The formula (upper + 1) * meshSize correctly computes the physical end of the domain.

tests/core/data/gridlayout/gridlayout_field_centered_coord.hpp (1)

107-110: Good defensive programming with the assertion.

The cast to std::size_t and the subsequent bounds check ensure safe access to params[hqIndex].

tests/amr/data/field/time_interpolate/test_field_data_time_interpolate.cpp (3)

84-85: Const correctness improvement.

The addition of const qualifiers to oldTime and newTime properly indicates these values don't change after initialization.


94-116: Cleaner iteration using AMR-local indexing.

The refactored code using layout.AMRGhostBoxFor(qty) and layout.AMRToLocal(amr_idx) is more expressive than the previous approach and aligns with the PR's goal of eliminating origin-based coordinate calculations.


324-343: Improved test structure with structured bindings.

The use of for (auto const [amr_idx, lcl_idx] : layout.domain_amr_lcl_idx(destField)) provides a clean iteration pattern that's both readable and efficient.

tests/core/data/gridlayout/gridlayout_deriv.hpp (1)

28-28: Type alias improves maintainability.

Adding GridLayout_t as a public type alias makes the GridLayout type accessible and simplifies potential future refactoring.

tests/core/data/gridlayout/gridlayout_deriv.cpp (2)

77-79: Note: These are section headers, not commented-out code.

The lines // // ----- are just comment decorations for the "2D case" section header. The 2D tests below (DXBY2D, DYBY2D, etc.) are all active and functioning. This clarifies the previous review question about commented tests.


41-51: Clean refactor to AMR-local indexing.

The new pattern using ghost_amr_lcl_idx with structured bindings [amr_idx, lcl_idx] eliminates the need for manual coordinate calculations and aligns with the PR's objective of removing origin-dependent logic.

src/amr/wrappers/hierarchy.hpp (1)

256-269: Origin removal is consistent with PR objectives.

The domain lower bounds are now initialized to 0, eliminating the per-patch origin concept. This directly addresses the PR's goal of preventing epsilon coordinate mismatches caused by differing per-patch origins. Coordinates are now computed uniformly using AMR index and mesh size.

src/core/data/grid/gridlayout.hpp (4)

454-485: Critical coordinate calculation now origin-independent.

Line 481 shows the key change: position[iDir] = (static_cast<double>(amr_idx[iDir]) + halfCell) * meshSize_[iDir] now computes coordinates directly from AMR index without origin offset. This eliminates the source of epsilon mismatches that motivated this PR.


1519-1549: Well-designed AMRLocalIndexer provides clean iteration API.

The AMRLocalIndexer struct elegantly maintains synchronized iteration over both AMR and local indices. The structured binding support via operator*() returning std::forward_as_tuple(*amr_it, *lcl_it) enables the clean for (auto const [amr_idx, lcl_idx] : ...) pattern seen throughout the codebase.


296-310: Const correctness improvements.

The addition of const qualifiers (auto const icentering, auto const iDir, etc.) throughout these methods improves code clarity and prevents accidental modifications.


890-895: Modern C++20 requires clause usage.

The use of requires(has_physicalQuantity_v<HasQuantity>) is idiomatic C++20 for constraining template overloads. Ensure the codebase consistently targets C++20 or later.

@PhilipDeegan PhilipDeegan merged commit 5db724c into PHAREHUB:master Nov 7, 2025
13 checks passed
@PhilipDeegan PhilipDeegan deleted the omg branch November 7, 2025 14:13
@coderabbitai coderabbitai bot mentioned this pull request Nov 18, 2025
@coderabbitai coderabbitai bot mentioned this pull request Jan 27, 2026
UCaromel pushed a commit to UCaromel/PHARE that referenced this pull request Feb 6, 2026
@coderabbitai coderabbitai bot mentioned this pull request Feb 24, 2026
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