Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

spatially variable hyperresistivity #893

Merged
merged 6 commits into from
Oct 18, 2024
Merged

Conversation

nicolasaunai
Copy link
Member

@nicolasaunai nicolasaunai commented Sep 19, 2024

implements #880

  • implements new projections of B on E needed to compute the norm of the magnetic field on E locations

Summary by CodeRabbit

  • New Features

    • Introduced new functions for converting magnetic field components to electric field components, enhancing electromagnetic field simulations.
    • Added capabilities for transforming weight points between different dimensional representations in the grid layout system.
    • Enhanced the hyperresistive_ method in the Ohm class for improved physical modeling of electric and magnetic field interactions.
    • Added a new hyper_mode configuration option for simulations, allowing for more nuanced resistivity calculations.
    • Expanded GridLayout functionality by including a level number parameter for improved grid management.
    • Updated simulation configuration to include new parameters for enhanced configurability.
  • Bug Fixes

    • Improved readability of lambda functions in the TensorField class without altering functionality.
  • Chores

    • Updated CMake configuration parameters for the build process.

Copy link

coderabbitai bot commented Sep 19, 2024

📝 Walkthrough
📝 Walkthrough

Walkthrough

The changes introduce a new integer parameter level_number to the GridLayout constructor and static constexpr functions for converting magnetic field components to electric field components. The Ohm class is updated with a new enumeration HyperMode and modified methods for hyperresistivity calculations, including a new method for spatial hyperresistivity. Additionally, simulation configuration is enhanced with a new hyper_mode parameter. These modifications collectively enhance the functionality and configurability of the involved classes.

Changes

Files Change Summary
src/amr/resources_manager/amr_utils.hpp Updated return statement to include new parameter lvlNbr in a function returning GridLayoutT.
src/core/data/grid/gridlayout.hpp Added level_number parameter to GridLayout constructor; introduced static constexpr functions for field conversions; added levelNumber() method.
src/core/data/grid/gridlayoutimplyee.hpp Added static constexpr functions for transforming weight points between different dimensional representations.
src/core/numerics/ohm/ohm.hpp Introduced HyperMode enum; modified hyperresistive_ method to include new parameters and added spatial_hyperresistive_ method for detailed calculations.
pyphare/pyphare/pharein/__init__.py Added hyper_mode parameter to simulation configuration in populateDict function.
pyphare/pyphare/pharein/simulation.py Added new keyword argument hyper_mode to the wrapper function for simulation configuration.

Possibly related PRs

  • Refac hierarchies #859: The changes in this PR involve refactoring hierarchy management, which may relate to the modifications in the GridLayout class and its parameters, as both involve structural changes to how data is managed and returned in the simulation framework.
  • remove compute_timestamps #866: This PR removes the compute_timestamps functionality, which could be related to the changes in how data is structured and returned in the main PR, particularly in the context of managing simulation parameters and diagnostics.
  • silent werror on ubuntu builds #906: The changes in the CMake configuration may indirectly relate to the main PR by affecting how the project is built and tested, which could influence the integration of the new parameter in the layoutFromPatch function.

Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

@nicolasaunai nicolasaunai marked this pull request as draft September 19, 2024 09:32
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: 4

Outside diff range and nitpick comments (1)
src/core/numerics/ohm/ohm.hpp (1)

341-376: Simplify computation of dl2 using std::inner_product

The calculation of dl2 can be made more concise and expressive by using std::inner_product instead of std::accumulate with a custom lambda.

Apply this diff to improve the code:

-        double const dl2{std::accumulate(std::begin(layout_->meshSize()),
-                                         std::end(layout_->meshSize()), 0.,
-                                         [](double acc, double d) { return acc + d * d; })};
+        double const dl2{std::inner_product(std::begin(layout_->meshSize()),
+                                            std::end(layout_->meshSize()),
+                                            std::begin(layout_->meshSize()),
+                                            0.0)};
Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 2f84939 and 9a12fd0.

Files selected for processing (5)
  • src/core/data/grid/gridlayout.hpp (3 hunks)
  • src/core/data/grid/gridlayoutimplyee.hpp (3 hunks)
  • src/core/data/tensorfield/tensorfield.hpp (1 hunks)
  • src/core/data/vecfield/vecfield.hpp (1 hunks)
  • src/core/numerics/ohm/ohm.hpp (5 hunks)
Files skipped from review due to trivial changes (2)
  • src/core/data/tensorfield/tensorfield.hpp
  • src/core/data/vecfield/vecfield.hpp
Additional context used
Path-based instructions (3)
src/core/data/grid/gridlayout.hpp (1)

Pattern **/*.hpp: Review the C++ code, point out issues relative to principles of clean code, expressiveness, and performance.

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

Pattern **/*.hpp: Review the C++ code, point out issues relative to principles of clean code, expressiveness, and performance.

src/core/numerics/ohm/ohm.hpp (1)

Pattern **/*.hpp: Review the C++ code, point out issues relative to principles of clean code, expressiveness, and performance.

Additional comments not posted (8)
src/core/data/grid/gridlayout.hpp (3)

1076-1076: LGTM!

The BxToEx function is a straightforward wrapper that delegates to the corresponding function in GridLayoutImpl. The implementation looks good.


1100-1100: LGTM!

The ByToEy function is a straightforward wrapper that delegates to the corresponding function in GridLayoutImpl. The implementation looks good.


1124-1124: LGTM!

The BzToEz function is a straightforward wrapper that delegates to the corresponding function in GridLayoutImpl. The implementation looks good.

src/core/numerics/ohm/ohm.hpp (3)

14-15: Inclusion of <numeric> header is appropriate

The <numeric> header is required for the use of std::accumulate in the code below.


82-83: Correct integration of hyperresistive_ term into E_Eq_ computation

The addition of the hyperresistive_ term enhances the physical modeling capabilities and aligns with the PR objectives.


285-286: Incorrect placement of #include <cmath>

Including the <cmath> header inside a function or code block is invalid. Headers should be included at the top of the file, outside any namespace or function.

Apply this diff to move the include statement:

 // Add at the top of the file, after existing includes:
+#include <cmath>

 // Remove the misplaced include inside the function:
-#include <cmath>

Likely invalid or redundant comment.

src/core/data/grid/gridlayoutimplyee.hpp (2)

788-828: Implementation of BzToEz() is correct

The BzToEz() function correctly calculates the weight points for transforming Bz to Ez in 1D, 2D, and 3D cases. The logic and coefficients are appropriate.


713-725: Fix missing variable names in WeightPoint declarations for dimension == 3 in BxToEx()

In the BxToEx() function, within the dimension == 3 branch, the WeightPoint declarations for P6, P7, and P8 are missing variable names, leading to syntax errors. Each constexpr WeightPoint<dimension> declaration should include a variable name.

Apply the following diff to correct the declarations:

             constexpr WeightPoint<dimension> P5{Point<int, dimension>{0, 0, d2pShift}, 0.125};
-            constexpr WeightPoint<dimension>{0, d2pShift, d2pShift}, 0.125};
+            constexpr WeightPoint<dimension> P6{Point<int, dimension>{0, d2pShift, d2pShift}, 0.125};
-            constexpr WeightPoint<dimension>{p2dShift, 0, d2pShift}, 0.125};
+            constexpr WeightPoint<dimension> P7{Point<int, dimension>{p2dShift, 0, d2pShift}, 0.125};
-            constexpr WeightPoint<dimension>{p2dShift, d2pShift, d2pShift}, 0.125};
+            constexpr WeightPoint<dimension> P8{Point<int, dimension>{p2dShift, d2pShift, d2pShift}, 0.125};

Likely invalid or redundant comment.

src/core/numerics/ohm/ohm.hpp Outdated Show resolved Hide resolved
src/core/data/grid/gridlayoutimplyee.hpp Show resolved Hide resolved
src/core/data/grid/gridlayoutimplyee.hpp Show resolved Hide resolved
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: 0

🧹 Outside diff range and nitpick comments (2)
src/core/data/grid/gridlayout.hpp (2)

115-123: LGTM: Constructor updated to include level number.

The addition of the level_number parameter and its initialization is a good improvement for supporting multi-level simulations or AMR.

Consider adding a brief comment explaining the purpose of the level_number parameter for better code documentation.


Line range hint 1077-1126: LGTM: Added B to E projection methods.

The new BxToEx(), ByToEy(), and BzToEz() methods are good additions, providing access to layout-specific projection information. The implementation correctly delegates to GridLayoutImpl.

For consistency with other similar methods in the class, consider adding brief documentation comments for each of these new methods, explaining their purpose and return value.

📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL

📥 Commits

Files that changed from the base of the PR and between 3159471 and d8c1d2b.

📒 Files selected for processing (3)
  • src/amr/resources_manager/amr_utils.hpp (1 hunks)
  • src/core/data/grid/gridlayout.hpp (6 hunks)
  • src/core/numerics/ohm/ohm.hpp (6 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • src/core/numerics/ohm/ohm.hpp
🧰 Additional context used
📓 Path-based instructions (2)
src/amr/resources_manager/amr_utils.hpp (1)

Pattern **/*.hpp: Review the C++ code, point out issues relative to principles of clean code, expressiveness, and performance.

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

Pattern **/*.hpp: Review the C++ code, point out issues relative to principles of clean code, expressiveness, and performance.

🔇 Additional comments (3)
src/amr/resources_manager/amr_utils.hpp (1)

185-186: LGTM! Consider verifying impact and updating documentation.

The addition of the lvlNbr parameter to the GridLayoutT constructor enhances the object's functionality by including patch level information. This change aligns well with the PR objectives.

To ensure this change doesn't introduce any issues:

  1. Verify that all other uses of the GridLayoutT constructor in the codebase have been updated to include the new lvlNbr parameter.
  2. Check if any existing documentation for GridLayoutT needs to be updated to reflect this change.

Consider adding a brief comment explaining the purpose of including the patch level number in the GridLayoutT object, if it's not already documented elsewhere.

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

1174-1174: LGTM: Added getter for level number.

The levelNumber() method is a good addition, providing controlled access to the levelNumber_ member variable.


1518-1519: LGTM: Added level number member variable.

The addition of the levelNumber_ member variable is consistent with the other changes and provides necessary storage for the level number in multi-level simulation scenarios.

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

🧹 Outside diff range and nitpick comments (6)
src/core/numerics/ohm/ohm.hpp (3)

31-33: Consider improving readability of hyper_mode initialization.

The initialization of hyper_mode is correct, but the use of a ternary operator in the member initializer list can be hard to read. Consider moving this logic to a separate function for improved clarity:

-        , hyper_mode{cppdict::get_value(dict, "hyper_mode", std::string{"constant"}) == "constant"
-                         ? HyperMode::constant
-                         : HyperMode::spatial}
+        , hyper_mode{getHyperMode(dict)}
+    {
+    }
+
+    static HyperMode getHyperMode(PHARE::initializer::PHAREDict const& dict)
+    {
+        auto mode = cppdict::get_value(dict, "hyper_mode", std::string{"constant"});
+        return mode == "constant" ? HyperMode::constant : HyperMode::spatial;
+    }

This change would improve readability and make the constructor easier to understand at a glance.


358-362: Address TODO and add explanatory comment for constant_hyperresistive_.

The method has been updated to align with the changes in hyperresistive_. However, there are two points to consider:

  1. The TODO comment references an open issue. It would be helpful to add more context about what needs to be done or why this is flagged as a TODO.

  2. Consider adding a brief comment explaining the calculation being performed. This will help future maintainers understand the purpose and logic of this method.

Example:

 template<auto component, typename VecField>
 auto constant_hyperresistive_(VecField const& J, MeshIndex<VecField::dimension> index) const
-{ // TODO : https://github.com/PHAREHUB/PHARE/issues/3
+{
+    // TODO: Implement more efficient calculation method (see https://github.com/PHAREHUB/PHARE/issues/3)
+    // Calculate the constant hyperresistive term using the Laplacian of the current density
     return -nu_ * layout_->laplacian(J(component), index);
 }

293-293: Move <cmath> include to the top of the file.

The <cmath> header is correctly included for the std::sqrt function used in the spatial_hyperresistive_ method. However, it's unconventional to place include statements in the middle of a file. For better readability and adherence to coding standards, move this include to the top of the file with the other includes.

 #include "initializer/data_provider.hpp"
 
 #include <numeric>
+#include <cmath>
 
 
 namespace PHARE::core
 {
 // ... (rest of the file)
-#include <cmath>
 // ... (rest of the file)

This change will improve the organization of the file and make it easier for developers to see all dependencies at a glance.

src/core/data/grid/gridlayoutimplyee.hpp (3)

688-728: Approved: Well-implemented transformation function

The BxToEx function is correctly implemented for all dimensions (1D, 2D, 3D) and properly handles the transformation from Bx (primal dual dual) to Ex (dual primal primal). The use of constexpr and static is appropriate for compile-time optimization.

Consider adding a brief comment explaining the meaning of the weight values (0.5, 0.25, 0.125) for better code readability. For example:

// Weight 0.5 for 1D, 0.25 for 2D, 0.125 for 3D due to averaging over additional dimensions
constexpr double weight = (dimension == 1) ? 0.5 : (dimension == 2) ? 0.25 : 0.125;

788-828: Approved: Correct implementation with room for consistency improvement

The BzToEz function is correctly implemented for all dimensions (1D, 2D, 3D) and properly handles the transformation from Bz (dual dual primal) to Ez (primal primal dual). The use of constexpr and static is appropriate for compile-time optimization.

For consistency with the BxToEx function, consider using a single constexpr variable for the weight calculation:

constexpr double weight = (dimension == 1) ? 0.5 : (dimension == 2) ? 0.25 : 0.25;

Then use this weight variable instead of hard-coded values in the WeightPoint constructors. This approach would improve readability and make it easier to modify weights in the future if needed.


Line range hint 688-962: Overall assessment: Well-implemented with room for consistency improvements

The newly added functions BxToEx, BzToEz, and ByToEy are generally well-implemented and provide important functionality for field transformations in the Yee grid layout. They correctly handle different dimensions and use appropriate C++ features for optimization.

To improve consistency and readability across these functions, consider the following refactoring:

  1. Introduce a helper function to calculate weights based on dimension:
constexpr double calculateWeight(std::size_t dimension)
{
    return (dimension == 1) ? 0.5 : (dimension == 2) ? 0.25 : 0.125;
}
  1. Use this helper function in all three transformation functions instead of hard-coded values.

  2. Consider creating a template function for generating WeightPoint arrays to reduce code duplication across the different dimension cases.

These changes would make the code more maintainable and easier to understand, while also reducing the likelihood of inconsistencies between similar functions.

📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL

📥 Commits

Files that changed from the base of the PR and between d8c1d2b and d03d643.

📒 Files selected for processing (8)
  • pyphare/pyphare/pharein/init.py (1 hunks)
  • pyphare/pyphare/pharein/simulation.py (1 hunks)
  • src/amr/resources_manager/amr_utils.hpp (1 hunks)
  • src/core/data/grid/gridlayout.hpp (6 hunks)
  • src/core/data/grid/gridlayoutimplyee.hpp (3 hunks)
  • src/core/data/tensorfield/tensorfield.hpp (1 hunks)
  • src/core/data/vecfield/vecfield.hpp (1 hunks)
  • src/core/numerics/ohm/ohm.hpp (6 hunks)
🚧 Files skipped from review as they are similar to previous changes (6)
  • pyphare/pyphare/pharein/init.py
  • pyphare/pyphare/pharein/simulation.py
  • src/amr/resources_manager/amr_utils.hpp
  • src/core/data/grid/gridlayout.hpp
  • src/core/data/tensorfield/tensorfield.hpp
  • src/core/data/vecfield/vecfield.hpp
🧰 Additional context used
📓 Path-based instructions (2)
src/core/data/grid/gridlayoutimplyee.hpp (1)

Pattern **/*.hpp: Review the C++ code, point out issues relative to principles of clean code, expressiveness, and performance.

src/core/numerics/ohm/ohm.hpp (1)

Pattern **/*.hpp: Review the C++ code, point out issues relative to principles of clean code, expressiveness, and performance.

🔇 Additional comments (2)
src/core/numerics/ohm/ohm.hpp (2)

19-20: LGTM: Well-defined enum for hyperresistivity modes.

The addition of the HyperMode enum class is a good practice. It provides type safety and clearly defines the available modes for hyperresistivity calculations.


14-15: Verify the necessity of the <numeric> include.

The <numeric> header has been added, but there doesn't appear to be any direct use of its functions in the visible changes. Please ensure that this include is necessary, possibly for code not shown in this diff.

To check if this include is used elsewhere in the file or project, you can run:

If no results are found, consider removing this include to keep the header dependencies minimal.

✅ Verification successful

Remove the unnecessary <numeric> include.

The <numeric> header is not used in src/core/numerics/ohm/ohm.hpp. Please remove this include to minimize dependencies.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Search for uses of functions from <numeric> in the current file and project
echo "Searching in current file:"
rg --type cpp -e 'std::(accumulate|reduce|inner_product|adjacent_difference|partial_sum|iota)' src/core/numerics/ohm/ohm.hpp

echo "\nSearching in entire project:"
rg --type cpp -e 'std::(accumulate|reduce|inner_product|adjacent_difference|partial_sum|iota)'

Length of output: 3836

src/core/numerics/ohm/ohm.hpp Outdated Show resolved Hide resolved
src/core/numerics/ohm/ohm.hpp Outdated Show resolved Hide resolved
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: 1

🧹 Outside diff range and nitpick comments (1)
src/core/numerics/ohm/ohm.hpp (1)

31-33: LGTM: Clear initialization of hyper_mode

The initialization of hyper_mode is well-implemented. It correctly uses cppdict::get_value to provide a default value of "constant" if the key is not present in the dictionary.

For improved readability, consider using an if-else statement instead of the ternary operator:

-        , hyper_mode{cppdict::get_value(dict, "hyper_mode", std::string{"constant"}) == "constant"
-                         ? HyperMode::constant
-                         : HyperMode::spatial}
+        , hyper_mode{[&dict]() {
+              auto mode = cppdict::get_value(dict, "hyper_mode", std::string{"constant"});
+              if (mode == "constant")
+                  return HyperMode::constant;
+              else if (mode == "spatial")
+                  return HyperMode::spatial;
+              else
+                  throw std::invalid_argument("Invalid hyper_mode value");
+          }()}

This change would also add error checking for invalid hyper_mode values.

📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL

📥 Commits

Files that changed from the base of the PR and between 08ce776 and b7b6db9.

📒 Files selected for processing (1)
  • src/core/numerics/ohm/ohm.hpp (6 hunks)
🧰 Additional context used
📓 Path-based instructions (1)
src/core/numerics/ohm/ohm.hpp (1)

Pattern **/*.hpp: Review the C++ code, point out issues relative to principles of clean code, expressiveness, and performance.

🔇 Additional comments (3)
src/core/numerics/ohm/ohm.hpp (3)

19-20: LGTM: Well-defined enum class for HyperMode

The addition of the HyperMode enum class is a good practice. It provides clear, type-safe options for the hyperresistivity mode, which enhances code readability and prevents errors from using incorrect values.


344-354: ⚠️ Potential issue

Improve error handling in hyperresistive_ method

The method now correctly uses the hyper_mode to determine the calculation method. However, the else clause that returns 0 could hide potential errors. Consider the following improvements:

  1. Make the else case unreachable by design:
     if (hyper_mode == HyperMode::constant)
         return constant_hyperresistive_<component>(J, index);
-    else if (hyper_mode == HyperMode::spatial)
+    else // hyper_mode == HyperMode::spatial
         return spatial_hyperresistive_<component>(J, B, n, index);
-    else // should not happen but otherwise -Wreturn-type fails with Werror
-        return 0.;
  1. If you want to keep the else case for future extensibility, throw an exception instead of returning 0:
     if (hyper_mode == HyperMode::constant)
         return constant_hyperresistive_<component>(J, index);
     else if (hyper_mode == HyperMode::spatial)
         return spatial_hyperresistive_<component>(J, B, n, index);
-    else // should not happen but otherwise -Wreturn-type fails with Werror
-        return 0.;
+    else
+        throw std::runtime_error("Invalid HyperMode");

These changes will ensure that unexpected cases are properly handled and don't silently return incorrect results.

Likely invalid or redundant comment.


14-15: Verify the necessity of the header

The <numeric> header has been added, but it's not immediately clear where functions from this header are used in the visible code. Could you please clarify the reason for including this header? If it's not being used, consider removing it to keep the includes minimal.

✅ Verification successful

Remove unnecessary <numeric> header

No functions from the <numeric> header are used in src/core/numerics/ohm/ohm.hpp. Consider removing this include to keep the dependencies minimal.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Check if any functions from <numeric> are used in the file
rg --type cpp -i '\b(accumulate|adjacent_difference|inner_product|partial_sum|iota|reduce|transform_reduce)\b' src/core/numerics/ohm/ohm.hpp

Length of output: 142


Script:

#!/bin/bash
# List all #include directives in src/core/numerics/ohm/ohm.hpp
rg '^#include\s+<[^>]+>' src/core/numerics/ohm/ohm.hpp

# Search for any numerical operations that might implicitly use <numeric>
rg --type cpp -i '\b(accumulate|adjacent_difference|inner_product|partial_sum|iota|reduce|transform_reduce|std::accumulate|std::inner_product)\b' src/core/numerics/ohm/ohm.hpp

Length of output: 309

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

🧹 Outside diff range and nitpick comments (2)
src/core/numerics/ohm/ohm.hpp (2)

32-34: Consider improving readability and error handling in the constructor.

While the current initialization of hyper_mode is functional, it could be improved for better readability and error handling. Consider using an if-else structure or a separate function for clarity. Also, it might be beneficial to provide a default value or throw an exception if the "hyper_mode" key is missing from the dictionary.

Example:

hyper_mode{getHyperMode(dict)}

// ...

HyperMode getHyperMode(const PHARE::initializer::PHAREDict& dict) {
    auto mode = cppdict::get_value(dict, "hyper_mode", std::string{"constant"});
    if (mode == "constant") return HyperMode::constant;
    if (mode == "spatial") return HyperMode::spatial;
    throw std::invalid_argument("Invalid hyper_mode value");
}

294-294: Move the include to the top of the file.

The <cmath> header has been added in an unusual location within the file. While it's needed for the std::sqrt function used in the spatial_hyperresistive_ method, it's conventional and more maintainable to place all include statements at the top of the file.

Please move this include statement to join the other includes at the beginning of the file.

📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL

📥 Commits

Files that changed from the base of the PR and between b7b6db9 and 63b6012.

📒 Files selected for processing (1)
  • src/core/numerics/ohm/ohm.hpp (6 hunks)
🧰 Additional context used
📓 Path-based instructions (1)
src/core/numerics/ohm/ohm.hpp (1)

Pattern **/*.hpp: Review the C++ code, point out issues relative to principles of clean code, expressiveness, and performance.

🔇 Additional comments (4)
src/core/numerics/ohm/ohm.hpp (4)

14-16: LGTM: New includes added appropriately.

The addition of <numeric> and <algorithm> headers is appropriate, likely to support new functionality in the class. These standard library headers provide useful algorithms and functions that can improve code quality and performance.


20-21: LGTM: New enum class HyperMode added.

The introduction of the HyperMode enum class is a good design choice. It provides type-safe options for selecting between constant and spatial hyperresistivity modes, enhancing code readability and reducing the likelihood of errors.


359-363: LGTM: constant_hyperresistive_ method updated correctly.

The method signature has been appropriately updated to align with the new hyperresistive_ method. The implementation remains correct and unchanged.


345-355: ⚠️ Potential issue

Improve error handling in hyperresistive_ method.

The method now correctly uses the hyper_mode to determine the calculation method. However, the else clause that returns 0 could hide potential errors. Consider the following improvements:

  1. Make the else case unreachable by design:
    if (hyper_mode == HyperMode::constant)
        return constant_hyperresistive_<component>(J, index);
-   else if (hyper_mode == HyperMode::spatial)
+   else // hyper_mode == HyperMode::spatial
        return spatial_hyperresistive_<component>(J, B, n, index);
-   else // should not happen but otherwise -Wreturn-type fails with Werror
-       return 0.;
  1. If you want to keep the else case for future extensibility, throw an exception instead of returning 0:
    if (hyper_mode == HyperMode::constant)
        return constant_hyperresistive_<component>(J, index);
    else if (hyper_mode == HyperMode::spatial)
        return spatial_hyperresistive_<component>(J, B, n, index);
-   else // should not happen but otherwise -Wreturn-type fails with Werror
-       return 0.;
+   else
+       throw std::runtime_error("Invalid HyperMode");

These changes will ensure that unexpected cases are properly handled and don't silently return incorrect results.

Likely invalid or redundant comment.

src/core/numerics/ohm/ohm.hpp Outdated Show resolved Hide resolved
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

🧹 Outside diff range and nitpick comments (6)
src/core/numerics/ohm/ohm.hpp (2)

31-33: LGTM with a minor suggestion for readability.

The initialization of the hyper_mode member variable is correct and provides a default value. However, for improved readability, consider using an if-else statement instead of a ternary operator, especially if more modes are added in the future.

, hyper_mode{[&dict]() {
    auto mode = cppdict::get_value(dict, "hyper_mode", std::string{"constant"});
    if (mode == "constant")
        return HyperMode::constant;
    else if (mode == "spatial")
        return HyperMode::spatial;
    else
        throw std::invalid_argument("Invalid hyper_mode value");
}()}

This approach allows for easier extension and better error handling.


358-362: LGTM: Minor signature update in constant_hyperresistive_.

The method signature has been updated to match the new usage in hyperresistive_. The implementation remains unchanged, which is correct for the constant mode.

Don't forget to address the TODO comment referencing issue #3 when appropriate.

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

115-123: LGTM. Consider adding documentation for the new parameter.

The addition of the level_number parameter to the constructor is well-implemented and maintains backwards compatibility.

Consider adding a brief comment explaining the purpose of the level_number parameter in the constructor's documentation.


1174-1174: LGTM. Consider using an explicit return type.

The levelNumber() method is correctly implemented as a const member function.

Consider using an explicit return type instead of auto for clarity:

-auto levelNumber() const { return levelNumber_; }
+int levelNumber() const { return levelNumber_; }
src/core/data/grid/gridlayoutimplyee.hpp (2)

688-728: Approved: Well-implemented transformation function

The BxToEx function is correctly implemented for all dimensions (1D, 2D, 3D) and properly handles the transformation from Bx (primal dual dual) to Ex (dual primal primal). The use of constexpr and static is appropriate for compile-time optimization.

Consider using a single constexpr variable for the weight calculation to improve readability:

constexpr double weight = (dimension == 1) ? 0.5 : (dimension == 2) ? 0.25 : 0.125;

Then use this weight variable instead of hard-coded values in the WeightPoint constructors.


788-828: Approved: Consistent implementation with BxToEx

The BzToEz function is correctly implemented for all dimensions (1D, 2D, 3D) and properly handles the transformation from Bz (dual dual primal) to Ez (primal primal dual). The implementation is consistent with the BxToEx function, which is good for code maintainability.

For consistency with the previous suggestion, consider using a single constexpr variable for the weight calculation:

constexpr double weight = (dimension == 1) ? 0.5 : (dimension == 2) ? 0.25 : 0.25;

Then use this weight variable instead of hard-coded values in the WeightPoint constructors.

📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL

📥 Commits

Files that changed from the base of the PR and between 63b6012 and 8c22d42.

📒 Files selected for processing (8)
  • pyphare/pyphare/pharein/init.py (1 hunks)
  • pyphare/pyphare/pharein/simulation.py (2 hunks)
  • src/amr/resources_manager/amr_utils.hpp (1 hunks)
  • src/core/data/grid/gridlayout.hpp (6 hunks)
  • src/core/data/grid/gridlayoutimplyee.hpp (3 hunks)
  • src/core/data/tensorfield/tensorfield.hpp (1 hunks)
  • src/core/data/vecfield/vecfield.hpp (1 hunks)
  • src/core/numerics/ohm/ohm.hpp (6 hunks)
🚧 Files skipped from review as they are similar to previous changes (5)
  • pyphare/pyphare/pharein/init.py
  • pyphare/pyphare/pharein/simulation.py
  • src/amr/resources_manager/amr_utils.hpp
  • src/core/data/tensorfield/tensorfield.hpp
  • src/core/data/vecfield/vecfield.hpp
🧰 Additional context used
📓 Path-based instructions (3)
src/core/data/grid/gridlayout.hpp (1)

Pattern **/*.hpp: Review the C++ code, point out issues relative to principles of clean code, expressiveness, and performance.

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

Pattern **/*.hpp: Review the C++ code, point out issues relative to principles of clean code, expressiveness, and performance.

src/core/numerics/ohm/ohm.hpp (1)

Pattern **/*.hpp: Review the C++ code, point out issues relative to principles of clean code, expressiveness, and performance.

🔇 Additional comments (4)
src/core/numerics/ohm/ohm.hpp (2)

19-20: LGTM: HyperMode enum addition.

The addition of the HyperMode enum is a good choice for type-safe selection of hyperresistivity modes. It improves code readability and prevents potential errors from using incorrect values.


344-354: ⚠️ Potential issue

Improve error handling in hyperresistive_ method.

The method now correctly uses the hyper_mode to determine the calculation method. However, the else clause that returns 0 could hide potential errors. Consider the following improvements:

  1. Make the else case unreachable by design:
    if (hyper_mode == HyperMode::constant)
        return constant_hyperresistive_<component>(J, index);
-   else if (hyper_mode == HyperMode::spatial)
+   else // hyper_mode == HyperMode::spatial
        return spatial_hyperresistive_<component>(J, B, n, index);
-   else // should not happen but otherwise -Wreturn-type fails with Werror
-       return 0.;
  1. If you want to keep the else case for future extensibility, throw an exception instead of returning 0:
    if (hyper_mode == HyperMode::constant)
        return constant_hyperresistive_<component>(J, index);
    else if (hyper_mode == HyperMode::spatial)
        return spatial_hyperresistive_<component>(J, B, n, index);
-   else // should not happen but otherwise -Wreturn-type fails with Werror
-       return 0.;
+   else
+       throw std::runtime_error("Invalid HyperMode");

These changes will ensure that unexpected cases are properly handled and don't silently return incorrect results.

Likely invalid or redundant comment.

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

Line range hint 1077-1126: LGTM. B to E projection methods are well-implemented.

The new static constexpr methods for B to E field projections (BxToEx(), ByToEy(), BzToEz()) are correctly implemented and consistent with the existing codebase.

These methods enhance the functionality of the GridLayout class by providing necessary projections for magnetic field components onto electric field components.


1518-1519: LGTM. New member variable is correctly declared and initialized.

The levelNumber_ member variable is properly declared as an int and initialized to 0, which is consistent with the constructor's default parameter.

This addition allows the GridLayout class to keep track of its level in a potential multi-level grid structure.

src/core/numerics/ohm/ohm.hpp Show resolved Hide resolved
src/core/numerics/ohm/ohm.hpp Outdated Show resolved Hide resolved
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: 1

🧹 Outside diff range and nitpick comments (8)
src/core/numerics/ohm/ohm.hpp (2)

27-29: Consider improving readability of hyper_mode initialization.

The current initialization is concise but could be made more readable. Consider using an if-else statement or extracting the logic to a separate function.

-        , hyper_mode{cppdict::get_value(dict, "hyper_mode", std::string{"constant"}) == "constant"
-                         ? HyperMode::constant
-                         : HyperMode::spatial}
+        , hyper_mode{initHyperMode(dict)}
+
+    // ... (in the class definition)
+    static HyperMode initHyperMode(const PHARE::initializer::PHAREDict& dict) {
+        auto mode = cppdict::get_value(dict, "hyper_mode", std::string{"constant"});
+        return (mode == "constant") ? HyperMode::constant : HyperMode::spatial;
+    }

This change would improve readability and make the logic easier to understand and maintain.


340-349: LGTM: Good implementation of hyperresistivity modes.

The updated hyperresistive_ method effectively uses the hyper_mode to determine the calculation method. The error handling for an unknown mode is a good practice.

Consider simplifying the conditional structure:

-    if (hyper_mode == HyperMode::constant)
-        return constant_hyperresistive_<component>(J, index);
-    else if (hyper_mode == HyperMode::spatial)
-        return spatial_hyperresistive_<component>(J, B, n, index);
-    else // should not happen but otherwise -Wreturn-type fails with Werror
-        throw std::runtime_error("Error - Ohm - unknown hyper_mode");
+    switch (hyper_mode) {
+        case HyperMode::constant:
+            return constant_hyperresistive_<component>(J, index);
+        case HyperMode::spatial:
+            return spatial_hyperresistive_<component>(J, B, n, index);
+        default:
+            throw std::runtime_error("Error - Ohm - unknown hyper_mode");
+    }

This change would make the code more readable and easier to extend if new modes are added in the future.

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

1174-1174: LGTM: New levelNumber accessor method added.

The levelNumber() method is correctly implemented as a const member function, providing read-only access to the levelNumber_ member. This is good for encapsulation.

Consider explicitly specifying the return type for clarity:

-auto levelNumber() const { return levelNumber_; }
+int levelNumber() const { return levelNumber_; }

Line range hint 1077-1126: LGTM: New B to E projection methods added.

The addition of static constexpr methods BxToEx(), ByToEy(), and BzToEz() for B to E field projections is well-implemented. The delegation to GridLayoutImpl methods suggests good design for layout-specific implementations.

Consider adding brief documentation comments for these new methods to explain their purpose and return values, similar to other methods in the class. For example:

/**
 * @brief BxToEx returns the indexes and associated coefficients to compute the linear
 * interpolation necessary to project Bx onto Ex.
 */
NO_DISCARD auto static constexpr BxToEx() { return GridLayoutImpl::BxToEx(); }
src/core/data/grid/gridlayoutimplyee.hpp (4)

688-728: Approved with a minor optimization suggestion

The BxToEx function is well-implemented, correctly handling the transformation from Bx (primal dual dual) to Ex (dual primal primal) for all dimensions (1D, 2D, 3D). The use of constexpr is appropriate for compile-time optimization.

Consider defining a constant for the weight calculation to improve readability:

constexpr double weight = (dimension == 1) ? 0.5 : (dimension == 2) ? 0.25 : 0.125;

Then use this weight variable instead of hard-coded values in the WeightPoint constructors.


788-828: Approved with refactoring suggestion for code reuse

The BzToEz function is correctly implemented, handling the transformation from Bz (dual dual primal) to Ez (primal primal dual) for all dimensions (1D, 2D, 3D). The use of constexpr is appropriate for compile-time optimization.

Consider creating a template function to handle the common logic in BxToEx, BzToEz, and potentially other similar functions. This would reduce code duplication and improve maintainability. For example:

template<int ShiftX, int ShiftY, int ShiftZ>
NO_DISCARD auto static constexpr TransformField()
{
    auto constexpr p2dShift = primalToDual();
    auto constexpr d2pShift = dualToPrimal();
    constexpr double weight = (dimension == 1) ? 0.5 : (dimension == 2) ? 0.25 : 0.125;

    if constexpr (dimension == 1)
    {
        constexpr WeightPoint<dimension> P1{Point<int, dimension>{0}, weight};
        constexpr WeightPoint<dimension> P2{Point<int, dimension>{ShiftX}, weight};
        return std::array<WeightPoint<dimension>, 2>{P1, P2};
    }
    else if constexpr (dimension == 2)
    {
        // ... (similar implementation for 2D)
    }
    else if constexpr (dimension == 3)
    {
        // ... (similar implementation for 3D)
    }
}

Then, you can use this template function in BxToEx and BzToEz:

NO_DISCARD auto static constexpr BxToEx()
{
    return TransformField<primalToDual(), dualToPrimal(), dualToPrimal>();
}

NO_DISCARD auto static constexpr BzToEz()
{
    return TransformField<dualToPrimal(), dualToPrimal(), primalToDual>();
}

This approach would significantly reduce code duplication and make it easier to maintain and extend these functions in the future.


923-962: Approved with reiteration of refactoring suggestion

The ByToEy function is correctly implemented, handling the transformation from By (dual primal dual) to Ey (primal dual primal) for all dimensions (1D, 2D, 3D). The use of constexpr is appropriate for compile-time optimization.

As mentioned in the previous comment, the similarity between ByToEy, BxToEx, and BzToEz strongly suggests the need for a template function to handle these transformations. This would significantly reduce code duplication and improve maintainability.

Using the previously suggested TransformField template function, you could implement ByToEy as:

NO_DISCARD auto static constexpr ByToEy()
{
    return TransformField<dualToPrimal(), primalToDual(), dualToPrimal>();
}

This approach would make the code more concise, easier to maintain, and less prone to errors when implementing similar functions in the future.


Line range hint 1-962: Overall: Well-implemented with suggestions for improvement

The changes in this file successfully implement new projections of the magnetic field (B) onto the electric field (E), aligning with the PR objectives. The new functions (BxToEx, BzToEz, ByToEy) are well-structured, correctly handle all dimensions, and use constexpr for compile-time optimization.

Main suggestions for improvement:

  1. Implement a template function to handle the common logic in these transformation functions, reducing code duplication and improving maintainability.
  2. Consider using a constant for weight calculations to improve readability.

These changes enhance the functionality of the GridLayoutImplYee class, providing necessary tools for computing the norm of the magnetic field at specific E locations. The implementation is solid, and with the suggested refactoring, it will be even more robust and easier to maintain.

Consider creating a separate file for these field transformation functions if the GridLayoutImplYee class becomes too large. This would improve code organization and make it easier to test and maintain these functions independently.

📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL

📥 Commits

Files that changed from the base of the PR and between 8c22d42 and 31cdd1b.

📒 Files selected for processing (8)
  • pyphare/pyphare/pharein/init.py (1 hunks)
  • pyphare/pyphare/pharein/simulation.py (2 hunks)
  • src/amr/resources_manager/amr_utils.hpp (1 hunks)
  • src/core/data/grid/gridlayout.hpp (6 hunks)
  • src/core/data/grid/gridlayoutimplyee.hpp (3 hunks)
  • src/core/data/tensorfield/tensorfield.hpp (1 hunks)
  • src/core/data/vecfield/vecfield.hpp (1 hunks)
  • src/core/numerics/ohm/ohm.hpp (6 hunks)
🚧 Files skipped from review as they are similar to previous changes (5)
  • pyphare/pyphare/pharein/init.py
  • pyphare/pyphare/pharein/simulation.py
  • src/amr/resources_manager/amr_utils.hpp
  • src/core/data/tensorfield/tensorfield.hpp
  • src/core/data/vecfield/vecfield.hpp
🧰 Additional context used
📓 Path-based instructions (3)
src/core/data/grid/gridlayout.hpp (1)

Pattern **/*.hpp: Review the C++ code, point out issues relative to principles of clean code, expressiveness, and performance.

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

Pattern **/*.hpp: Review the C++ code, point out issues relative to principles of clean code, expressiveness, and performance.

src/core/numerics/ohm/ohm.hpp (1)

Pattern **/*.hpp: Review the C++ code, point out issues relative to principles of clean code, expressiveness, and performance.

🔇 Additional comments (4)
src/core/numerics/ohm/ohm.hpp (3)

15-15: LGTM: Clear and concise enumeration added.

The HyperMode enumeration is a good addition, providing a clear way to distinguish between constant and spatial hyperresistivity modes.


Line range hint 1-396: Overall LGTM: Good improvements to the Ohm class.

The changes to the Ohm class, including the addition of the HyperMode enum, the new spatial_hyperresistive_ method, and the updates to the hyperresistive_ method, significantly enhance the functionality of the class. The implementation allows for more flexible hyperresistivity calculations based on the chosen mode.

Some minor suggestions for improvement have been made, primarily focusing on readability and robustness. Additionally, it would be beneficial to get more context about the TODO comments and the plans for addressing issue #3.

Great work on implementing these new features!


360-390: LGTM with suggestions: New spatial hyperresistivity calculation.

The new spatial_hyperresistive_ method is a good addition, providing a more complex calculation for the hyperresistive term. Here are some suggestions for improvement:

  1. Add a comment explaining the purpose of the lvlCoeff calculation.
  2. Consider handling the case where nOnE is zero to prevent potential division by zero errors.
  3. The TODO comment suggests that there might be future changes planned. It would be helpful to have more context about this.

Here's a suggested improvement for the lambda function:

     auto computeHR = [&](auto BxProj, auto ByProj, auto BzProj, auto nProj) {
         auto const BxOnE = GridLayout::project(B(Component::X), index, BxProj);
         auto const ByOnE = GridLayout::project(B(Component::Y), index, ByProj);
         auto const BzOnE = GridLayout::project(B(Component::Z), index, BzProj);
         auto const nOnE  = GridLayout::project(n, index, nProj);
         auto b           = std::sqrt(BxOnE * BxOnE + ByOnE * ByOnE + BzOnE * BzOnE);
+        if (nOnE == 0) {
+            // Handle division by zero case
+            return 0.0; // or throw an exception, depending on your error handling strategy
+        }
         return -nu_ * b / nOnE * lvlCoeff * layout_->laplacian(J(component), index);
     };

Could you provide more information about the plans for addressing issue #3? This might help in understanding the future direction of this method.

#!/bin/bash
# Fetch the content of issue #3
gh issue view 3 --repo PHAREHUB/PHARE
src/core/data/grid/gridlayout.hpp (1)

115-123: LGTM: Constructor updated correctly with new level number parameter.

The addition of the level_number parameter with a default value of 0 is well-implemented. It maintains backward compatibility while allowing the specification of a level number when needed. The initialization of levelNumber_ in the constructor's initializer list is the correct approach.

Comment on lines +354 to 357
auto constant_hyperresistive_(VecField const& J, MeshIndex<VecField::dimension> index) const
{ // TODO : https://github.com/PHAREHUB/PHARE/issues/3
return -nu_ * layout_->laplacian(J(component), index);
}
Copy link

Choose a reason for hiding this comment

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

💡 Codebase verification

LGTM: Method signature updated correctly.

The constant_hyperresistive_ method signature has been updated to match the changes in the hyperresistive_ method, ensuring consistency in the class interface.

However, the method still unconditionally computes the hyperresistive term. According to issue #3, the implementation should conditionally include resistive and hyperresistive terms based on their coefficients.

Could you please update the method to align with the proposed design in issue #3 or provide an update on how and when this will be addressed?

🔗 Analysis chain

LGTM: Method signature updated correctly.

The constant_hyperresistive_ method signature has been updated to match the changes in the hyperresistive_ method. This ensures consistency in the class interface.

Regarding the TODO comment, could you provide more information about the plans for addressing issue #3? This might help in understanding the future direction of this method.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Fetch the content of issue #3
gh issue view 3 --repo PHAREHUB/PHARE

Length of output: 1044

@nicolasaunai nicolasaunai mentioned this pull request Oct 12, 2024
@nicolasaunai nicolasaunai marked this pull request as ready for review October 12, 2024 09:44
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

🧹 Outside diff range and nitpick comments (11)
src/core/data/vecfield/vecfield.hpp (2)

Line range hint 35-55: LGTM with minor suggestions for improvement.

The VecFieldNames structure is well-designed and follows good C++ practices. Here are a few suggestions to further improve it:

  1. Consider adding const qualifiers to the string members if they're not intended to be modified after construction. This would make the immutability of these members explicit.

  2. The use of explicit for the templated constructor is good practice. It prevents unintended implicit conversions.

You could modify the structure as follows:

struct VecFieldNames
{
    const std::string vecName;
    const std::string xName;
    const std::string yName;
    const std::string zName;

    // ... rest of the code remains the same
};

35-37: Add documentation for the VecFieldNames structure.

To improve code readability and maintainability, consider adding documentation for the VecFieldNames structure. This documentation should explain the purpose of the structure and how it's intended to be used.

Here's a suggested documentation block:

/**
 * @brief Stores the names of a vector field and its components.
 *
 * This structure is used to encapsulate the names associated with a vector field,
 * including the name of the field itself and the names of its X, Y, and Z components.
 * It provides a convenient way to store and pass around these names as a single unit.
 */
struct VecFieldNames
{
    // ... existing code ...
};
.github/workflows/cmake_ubuntu.yml (1)

81-85: Approved: Consistent build configuration with improved debugging

The changes in the main CMake configuration are consistent with the SAMRAI subproject changes and align with the project's preference for keeping asserts enabled. The Debug build type with -O3 optimization maintains debugging capabilities while ensuring performance.

Suggestion for clarity:
Consider separating the optimization flag from the project-specific flags in CMAKE_CXX_FLAGS for better readability:

-              -DCMAKE_CXX_FLAGS="-O3 -DPHARE_DIAG_DOUBLES=1 " -Dphare_configurator=ON
+              -DCMAKE_CXX_FLAGS="-O3" -DPHARE_DIAG_DOUBLES=1 -Dphare_configurator=ON

This separation makes it easier to distinguish between compiler optimization flags and project-specific definitions.

src/core/numerics/ohm/ohm.hpp (2)

27-29: Consider using if-else for better readability

The current initialization of hyper_mode uses a ternary operator, which is concise but can be less readable for complex conditions. Consider using an if-else statement for improved clarity.

Here's a suggested refactor:

-        , hyper_mode{cppdict::get_value(dict, "hyper_mode", std::string{"constant"}) == "constant"
-                         ? HyperMode::constant
-                         : HyperMode::spatial}
+        , hyper_mode{[&dict]() {
+             auto mode = cppdict::get_value(dict, "hyper_mode", std::string{"constant"});
+             if (mode == "constant")
+                 return HyperMode::constant;
+             else if (mode == "spatial")
+                 return HyperMode::spatial;
+             else
+                 throw std::runtime_error("Invalid hyper_mode value");
+         }()}

This change also adds error handling for invalid mode values.


340-349: LGTM: hyperresistive_ method update

The hyperresistive_ method has been successfully updated to accommodate both constant and spatial hyperresistivity calculations. The conditional structure and error handling are appropriate.

Consider using a switch statement instead of if-else for better readability and to leverage compiler optimizations:

-    if (hyper_mode == HyperMode::constant)
-        return constant_hyperresistive_<component>(J, index);
-    else if (hyper_mode == HyperMode::spatial)
-        return spatial_hyperresistive_<component>(J, B, n, index);
-    else // should not happen but otherwise -Wreturn-type fails with Werror
-        throw std::runtime_error("Error - Ohm - unknown hyper_mode");
+    switch (hyper_mode) {
+        case HyperMode::constant:
+            return constant_hyperresistive_<component>(J, index);
+        case HyperMode::spatial:
+            return spatial_hyperresistive_<component>(J, B, n, index);
+        default:
+            throw std::runtime_error("Error - Ohm - unknown hyper_mode");
+    }
src/core/data/grid/gridlayout.hpp (4)

115-123: LGTM! Consider adding documentation for the new parameter.

The addition of the level_number parameter to the constructor is well-implemented and maintains backward compatibility. The initialization of the levelNumber_ member is correct.

Consider adding a brief comment explaining the purpose of the level_number parameter in the constructor's documentation.


1174-1174: LGTM! Consider explicit return type.

The levelNumber() method is correctly implemented as a const getter for the levelNumber_ member.

Consider using an explicit return type for clarity:

-auto levelNumber() const { return levelNumber_; }
+int levelNumber() const { return levelNumber_; }

Line range hint 1077-1126: LGTM! Consider adding documentation for the new methods.

The new B to E projection methods (BxToEx(), ByToEy(), BzToEz()) are correctly implemented as static constexpr methods delegating to GridLayoutImpl. This approach is consistent with other similar methods in the class.

Consider adding brief documentation comments for these new methods, explaining their purpose and return values, similar to the existing comments for other projection methods in the class.


Line range hint 115-1519: Overall, the changes enhance the GridLayout class effectively.

The additions to the GridLayout class, including the new level_number parameter in the constructor, the levelNumber() getter, and the B to E projection methods, are well-implemented and consistent with the existing code style. These changes enhance the functionality of the class without introducing breaking changes.

Consider the following suggestions for future improvements:

  1. Add comprehensive documentation for the new level_number concept, explaining its purpose and how it relates to the overall grid layout system.
  2. If the B to E projections are part of a larger feature, consider adding a comment block explaining the overall purpose and any related methods or classes that work together to implement this feature.
  3. Ensure that any code using the GridLayout class is updated to take advantage of the new level_number functionality where appropriate.
src/core/data/grid/gridlayoutimplyee.hpp (2)

688-728: Approved: Well-implemented transformation with a minor suggestion

The BxToEx function correctly implements the transformation from Bx (primal dual dual) to Ex (dual primal primal) for all dimensions (1D, 2D, 3D). The use of constexpr is appropriate for compile-time optimization.

Consider using a single constexpr variable for the weight calculation to improve readability:

constexpr double weight = (dimension == 1) ? 0.5 : (dimension == 2) ? 0.25 : 0.125;

Then use this weight variable instead of hard-coded values in the WeightPoint constructors.


788-828: Approved: Correct implementation with a minor suggestion

The BzToEz function correctly implements the transformation from Bz (dual dual primal) to Ez (primal primal dual) for all dimensions (1D, 2D, 3D). The use of constexpr is appropriate for compile-time optimization.

Similar to the previous suggestion, consider using a single constexpr variable for the weight calculation to improve readability:

constexpr double weight = (dimension == 1) ? 0.5 : (dimension == 2) ? 0.25 : 0.25;

Then use this weight variable instead of hard-coded values in the WeightPoint constructors.

📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL

📥 Commits

Files that changed from the base of the PR and between 31cdd1b and ca03fe7.

📒 Files selected for processing (9)
  • .github/workflows/cmake_ubuntu.yml (1 hunks)
  • pyphare/pyphare/pharein/init.py (1 hunks)
  • pyphare/pyphare/pharein/simulation.py (2 hunks)
  • src/amr/resources_manager/amr_utils.hpp (1 hunks)
  • src/core/data/grid/gridlayout.hpp (6 hunks)
  • src/core/data/grid/gridlayoutimplyee.hpp (3 hunks)
  • src/core/data/tensorfield/tensorfield.hpp (1 hunks)
  • src/core/data/vecfield/vecfield.hpp (1 hunks)
  • src/core/numerics/ohm/ohm.hpp (6 hunks)
🚧 Files skipped from review as they are similar to previous changes (4)
  • pyphare/pyphare/pharein/init.py
  • pyphare/pyphare/pharein/simulation.py
  • src/amr/resources_manager/amr_utils.hpp
  • src/core/data/tensorfield/tensorfield.hpp
🧰 Additional context used
📓 Path-based instructions (4)
src/core/data/grid/gridlayout.hpp (1)

Pattern **/*.hpp: Review the C++ code, point out issues relative to principles of clean code, expressiveness, and performance.

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

Pattern **/*.hpp: Review the C++ code, point out issues relative to principles of clean code, expressiveness, and performance.

src/core/data/vecfield/vecfield.hpp (1)

Pattern **/*.hpp: Review the C++ code, point out issues relative to principles of clean code, expressiveness, and performance.

src/core/numerics/ohm/ohm.hpp (1)

Pattern **/*.hpp: Review the C++ code, point out issues relative to principles of clean code, expressiveness, and performance.

📓 Learnings (1)
.github/workflows/cmake_ubuntu.yml (1)
Learnt from: PhilipDeegan
PR: PHAREHUB/PHARE#898
File: .github/workflows/cmake_ubuntu.yml:81-85
Timestamp: 2024-10-15T16:27:04.609Z
Learning: In this project, the `RelWithDebInfo` build type includes `-DNDEBUG`, which disables asserts. To keep asserts enabled while having some optimizations, the `Debug` build type is used with the `-O3` optimization flag.
🔇 Additional comments (6)
.github/workflows/cmake_ubuntu.yml (1)

77-77: Approved: Build type change improves debugging capabilities

The change from RelWithDebInfo to Debug build type for SAMRAI, while adding -O3 to CMAKE_CXX_FLAGS, is a good approach. This keeps asserts enabled (which are typically disabled in RelWithDebInfo) while still maintaining optimizations. This aligns with the project's preference for keeping asserts enabled during development and testing.

src/core/numerics/ohm/ohm.hpp (4)

15-15: LGTM: HyperMode enum addition

The HyperMode enum is well-defined and clearly represents the two modes of operation for the hyperresistivity calculation. This addition enhances the code's readability and type safety.


359-390: 🛠️ Refactor suggestion

⚠️ Potential issue

Address potential division by zero and consider minor optimization in spatial_hyperresistive_

The new spatial_hyperresistive_ method is well-structured and uses a lambda to reduce code duplication. However, there are two points to consider:

  1. Potential division by zero: In the lambda function, there's a division by nOnE. Add a check to prevent division by zero:
 auto computeHR = [&](auto BxProj, auto ByProj, auto BzProj, auto nProj) {
     auto const BxOnE = GridLayout::project(B(Component::X), index, BxProj);
     auto const ByOnE = GridLayout::project(B(Component::Y), index, ByProj);
     auto const BzOnE = GridLayout::project(B(Component::Z), index, BzProj);
     auto const nOnE  = GridLayout::project(n, index, nProj);
     auto b           = std::sqrt(BxOnE * BxOnE + ByOnE * ByOnE + BzOnE * BzOnE);
+    if (nOnE == 0) {
+        return 0.0; // or throw an exception, depending on your error handling strategy
+    }
     return -nu_ * b / nOnE * lvlCoeff * layout_->laplacian(J(component), index);
 };
  1. Minor optimization: The lvlCoeff calculation could be moved outside the lambda since it doesn't depend on the lambda parameters:
 template<auto component, typename VecField, typename Field>
 auto spatial_hyperresistive_(VecField const& J, VecField const& B, Field const& n,
                              MeshIndex<VecField::dimension> index) const
 { // TODO : https://github.com/PHAREHUB/PHARE/issues/3
     auto const lvlCoeff = 1. / std::pow(4, layout_->levelNumber());
 
-    auto computeHR = [&](auto BxProj, auto ByProj, auto BzProj, auto nProj) {
+    auto computeHR = [&, lvlCoeff](auto BxProj, auto ByProj, auto BzProj, auto nProj) {
         // ... (rest of the lambda implementation)
     };
 
     // ... (rest of the method implementation)
 }

These changes will improve the robustness and potentially the performance of the spatial_hyperresistive_ method.

Likely invalid or redundant comment.


354-357: LGTM: constant_hyperresistive_ method signature update

The constant_hyperresistive_ method signature has been correctly updated to match the changes in the hyperresistive_ method, ensuring consistency in the class interface.

Regarding the TODO comment, could you provide more information about the plans for addressing issue #3? This might help in understanding the future direction of this method.

✅ Verification successful

Verified: constant_hyperresistive_ method and TODO comment

The constant_hyperresistive_ method signature update aligns with the hyperresistive_ method changes, ensuring consistency in the class interface.

The TODO comment references issue #3, which is currently open and outlines plans to implement switches for resistivity and hyperresistivity terms. This clarifies the future direction for the method.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Fetch the content of issue #3
gh issue view 3 --repo PHAREHUB/PHARE

Length of output: 1172


Script:

#!/bin/bash
# Corrected: Fetch the content of issue #3
gh issue view 3 --repo PHAREHUB/PHARE

Length of output: 1044


12-12: LGTM: Removal of unused <numeric> header

The removal of the <numeric> header is appropriate if it's no longer being used in this file. This change helps reduce compilation time and potential conflicts.

To ensure that the <numeric> header is indeed unnecessary, please run the following script to search for any std:: functions that might be using it:

✅ Verification successful

Verified: Removal of unused <numeric> header

The <numeric> header is not utilized in this file, as no std:: functions from <numeric> are present. Removing it helps reduce unnecessary dependencies and improves compilation efficiency.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Search for any usage of std:: functions from the <numeric> header
rg --type cpp 'std::\w+' src/core/numerics/ohm/ohm.hpp

Length of output: 1172


Script:

#!/bin/bash
# Search for any usage of std:: functions from the <numeric> header
rg --type cpp 'std::\w+' src/core/numerics/ohm/ohm.hpp

Length of output: 428

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

Line range hint 1-1183: Overall assessment: Well-implemented changes with minor improvements suggested

The new functions BxToEx, BzToEz, and ByToEy successfully implement the required projections of the magnetic field (B) onto the electric field (E) for all dimensions (1D, 2D, 3D). These changes align well with the PR objectives and enhance the functionality related to hyperresistivity within the PHARE framework.

Key points:

  1. The implementations are correct and follow a consistent pattern across functions.
  2. Proper use of constexpr and static for compile-time optimization.
  3. Correct handling of different dimensions and shifts.

Suggestions for improvement:

  1. Use a single constexpr variable for weight calculations to improve readability.
  2. Fix the minor issue with missing variable names in the ByToEy function for the 3D case.

These changes provide a solid foundation for computing the norm of the magnetic field at specific E locations, as intended by the PR.

@@ -281,6 +286,7 @@ class Ohm : public LayoutHolder<GridLayout>
return -gradPOnEy / nOnEy;
}
else
#include <cmath>
Copy link

Choose a reason for hiding this comment

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

⚠️ Potential issue

Move <cmath> header inclusion to the top of the file

The <cmath> header is currently included within a method body, which is incorrect and unconventional. Move this inclusion to the top of the file with the other header inclusions for better organization and to ensure it's available throughout the entire file.

Apply this change:

#ifndef PHARE_OHM_HPP
#define PHARE_OHM_HPP

+#include <cmath>

#include "core/data/grid/gridlayoutdefs.hpp"
#include "core/data/grid/gridlayout_utils.hpp"
#include "core/data/vecfield/vecfield_component.hpp"

#include "initializer/data_provider.hpp"

-// ... (later in the file)
-#include <cmath>
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
#include <cmath>
#ifndef PHARE_OHM_HPP
#define PHARE_OHM_HPP
#include <cmath>
#include "core/data/grid/gridlayoutdefs.hpp"
#include "core/data/grid/gridlayout_utils.hpp"
#include "core/data/vecfield/vecfield_component.hpp"
#include "initializer/data_provider.hpp"

Comment on lines +923 to +962
NO_DISCARD auto static constexpr ByToEy()
{
// By is dual primal dual
// Ey is primal dual primal
// the operation is thus dpd to pdp
auto constexpr p2dShift = primalToDual();
auto constexpr d2pShift = dualToPrimal();

if constexpr (dimension == 1)
{
constexpr WeightPoint<dimension> P1{Point<int, dimension>{0}, 0.5};
constexpr WeightPoint<dimension> P2{Point<int, dimension>{d2pShift}, 0.5};
return std::array<WeightPoint<dimension>, 2>{P1, P2};
}
else if constexpr (dimension == 2)
{
constexpr WeightPoint<dimension> P1{Point<int, dimension>{0, 0}, 0.25};
constexpr WeightPoint<dimension> P2{Point<int, dimension>{d2pShift, 0}, 0.25};
constexpr WeightPoint<dimension> P3{Point<int, dimension>{0, p2dShift}, 0.25};
constexpr WeightPoint<dimension> P4{Point<int, dimension>{d2pShift, p2dShift},
0.25};
return std::array<WeightPoint<dimension>, 4>{P1, P2, P3, P4};
}
else if constexpr (dimension == 3)
{
constexpr WeightPoint<dimension> P1{Point<int, dimension>{0, 0, 0}, 0.25};
constexpr WeightPoint<dimension> P2{Point<int, dimension>{d2pShift, 0, 0}, 0.25};
constexpr WeightPoint<dimension> P3{Point<int, dimension>{0, p2dShift, 0}, 0.25};
constexpr WeightPoint<dimension> P4{Point<int, dimension>{d2pShift, p2dShift, 0},
0.25};
constexpr WeightPoint<dimension> P5{Point<int, dimension>{0, 0, d2pShift}, 0.25};
constexpr WeightPoint<dimension> P6{Point<int, dimension>{d2pShift, 0, d2pShift},
0.25};
constexpr WeightPoint<dimension> P7{Point<int, dimension>{0, p2dShift, d2pShift},
0.25};
constexpr WeightPoint<dimension> P8{
Point<int, dimension>{d2pShift, p2dShift, d2pShift}, 0.25};
return std::array<WeightPoint<dimension>, 8>{P1, P2, P3, P4, P5, P6, P7, P8};
}
}
Copy link

Choose a reason for hiding this comment

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

⚠️ Potential issue

Approved with suggestions: Correct implementation with minor issues

The ByToEy function is correctly implemented for all dimensions (1D, 2D, 3D) and properly handles the transformation from By (dual primal dual) to Ey (primal dual primal). The use of constexpr and static is appropriate for compile-time optimization.

In the 3D case, there's a minor issue where P6, P7, and P8 are missing variable names. This should be corrected to ensure proper compilation. Apply the following diff to fix this issue:

-                constexpr WeightPoint<dimension>{Point<int, dimension>{d2pShift, 0, d2pShift},
-                                                    0.25};
-                constexpr WeightPoint<dimension>{Point<int, dimension>{0, p2dShift, d2pShift},
-                                                    0.25};
-                constexpr WeightPoint<dimension>{
-                    Point<int, dimension>{d2pShift, p2dShift, d2pShift}, 0.25};
+                constexpr WeightPoint<dimension> P6{Point<int, dimension>{d2pShift, 0, d2pShift},
+                                                    0.25};
+                constexpr WeightPoint<dimension> P7{Point<int, dimension>{0, p2dShift, d2pShift},
+                                                    0.25};
+                constexpr WeightPoint<dimension> P8{
+                    Point<int, dimension>{d2pShift, p2dShift, d2pShift}, 0.25};

For consistency with the previous functions, consider using a single constexpr variable for the weight calculation:

constexpr double weight = (dimension == 1) ? 0.5 : (dimension == 2) ? 0.25 : 0.25;

Then use this weight variable instead of hard-coded values in the WeightPoint constructors.

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

🧹 Outside diff range and nitpick comments (8)
src/core/numerics/ohm/ohm.hpp (3)

27-29: LGTM: hyper_mode initialization added

The initialization of hyper_mode in the constructor is well-implemented. However, consider using a case-insensitive comparison for better robustness:

-        , hyper_mode{cppdict::get_value(dict, "hyper_mode", std::string{"constant"}) == "constant"
+        , hyper_mode{std::tolower(cppdict::get_value(dict, "hyper_mode", std::string{"constant"})[0]) == 'c'
                         ? HyperMode::constant
                         : HyperMode::spatial}

This change would allow for variations like "Constant" or "CONSTANT" to be correctly interpreted.


353-356: LGTM: constant_hyperresistive_ method signature updated

The method signature has been correctly updated to match the changes in the hyperresistive_ method.

The TODO comment referencing issue #3 (#3) indicates that there are pending changes. Consider creating a separate task to track this TODO item and ensure it's addressed in future updates.

Would you like me to create a GitHub issue to track this TODO item?


358-389: LGTM: New spatial_hyperresistive_ method added with suggestions

The new spatial_hyperresistive_ method is well-implemented. Here are some suggestions for improvement:

  1. Add a comment explaining the purpose of the lvlCoeff calculation.
  2. Add a check to prevent division by zero when nOnE is zero:
 auto computeHR = [&](auto BxProj, auto ByProj, auto BzProj, auto nProj) {
     auto const BxOnE = GridLayout::project(B(Component::X), index, BxProj);
     auto const ByOnE = GridLayout::project(B(Component::Y), index, ByProj);
     auto const BzOnE = GridLayout::project(B(Component::Z), index, BzProj);
     auto const nOnE  = GridLayout::project(n, index, nProj);
     auto b           = std::sqrt(BxOnE * BxOnE + ByOnE * ByOnE + BzOnE * BzOnE);
+    if (nOnE == 0) {
+        return 0.0; // or throw an exception, depending on your error handling strategy
+    }
     return -nu_ * b / nOnE * lvlCoeff * layout_->laplacian(J(component), index);
 };
  1. Consider creating a separate task to track the TODO item referencing issue implement switches for resistivity and hyperresistivity terms #3.

Would you like me to create a GitHub issue to track the TODO item mentioned in the comment?

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

115-123: LGTM! Consider adding documentation for the new parameter.

The addition of the level_number parameter to the constructor is a good improvement for supporting multi-level simulations. The default value of 0 ensures backward compatibility.

Consider adding a brief comment explaining the purpose of the level_number parameter in the constructor's documentation.


Line range hint 1077-1126: LGTM! Consider adding brief comments for consistency.

The addition of BxToEx(), ByToEy(), and BzToEz() methods is a good improvement for magnetic to electric field component conversions. They are correctly implemented as static constexpr methods and delegate to the GridLayoutImpl.

For consistency with other similar methods in this class (e.g., momentsToEx()), consider adding brief comments explaining the purpose of these new methods. For example:

/**
 * @brief BxToEx returns the indexes and associated coef to compute the linear
 * interpolation necessary to project Bx onto Ex.
 */
NO_DISCARD auto static constexpr BxToEx() { return GridLayoutImpl::BxToEx(); }
src/core/data/grid/gridlayoutimplyee.hpp (3)

688-728: Approved: Well-implemented transformation function

The BxToEx function is correctly implemented for all dimensions (1D, 2D, 3D) and properly handles the transformation from Bx (primal dual dual) to Ex (dual primal primal). The use of constexpr and static is appropriate for compile-time optimization.

Consider adding a brief comment explaining the meaning of the weight values (0.5, 0.25, 0.125) for better code readability.


788-828: Approved: Correct implementation with a minor suggestion

The BzToEz function is correctly implemented for all dimensions (1D, 2D, 3D) and properly handles the transformation from Bz (dual dual primal) to Ez (primal primal dual). The use of constexpr and static is appropriate for compile-time optimization.

For consistency with the BxToEx function, consider using a single constexpr variable for the weight calculation:

constexpr double weight = (dimension == 1) ? 0.5 : (dimension == 2) ? 0.25 : 0.25;

Then use this weight variable instead of hard-coded values in the WeightPoint constructors.


923-962: Approved: Correct implementation with consistency suggestion

The ByToEy function is correctly implemented for all dimensions (1D, 2D, 3D) and properly handles the transformation from By (dual primal dual) to Ey (primal dual primal). The use of constexpr and static is appropriate for compile-time optimization.

For consistency with the previous functions, consider using a single constexpr variable for the weight calculation:

constexpr double weight = (dimension == 1) ? 0.5 : (dimension == 2) ? 0.25 : 0.25;

Then use this weight variable instead of hard-coded values in the WeightPoint constructors.

📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL

📥 Commits

Files that changed from the base of the PR and between ca03fe7 and 280f1d5.

📒 Files selected for processing (9)
  • .github/workflows/cmake_ubuntu.yml (1 hunks)
  • pyphare/pyphare/pharein/init.py (1 hunks)
  • pyphare/pyphare/pharein/simulation.py (3 hunks)
  • src/amr/resources_manager/amr_utils.hpp (1 hunks)
  • src/core/data/grid/gridlayout.hpp (6 hunks)
  • src/core/data/grid/gridlayoutimplyee.hpp (3 hunks)
  • src/core/data/tensorfield/tensorfield.hpp (1 hunks)
  • src/core/data/vecfield/vecfield.hpp (1 hunks)
  • src/core/numerics/ohm/ohm.hpp (5 hunks)
🚧 Files skipped from review as they are similar to previous changes (5)
  • .github/workflows/cmake_ubuntu.yml
  • pyphare/pyphare/pharein/simulation.py
  • src/amr/resources_manager/amr_utils.hpp
  • src/core/data/tensorfield/tensorfield.hpp
  • src/core/data/vecfield/vecfield.hpp
🧰 Additional context used
📓 Path-based instructions (3)
src/core/data/grid/gridlayout.hpp (1)

Pattern **/*.hpp: Review the C++ code, point out issues relative to principles of clean code, expressiveness, and performance.

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

Pattern **/*.hpp: Review the C++ code, point out issues relative to principles of clean code, expressiveness, and performance.

src/core/numerics/ohm/ohm.hpp (1)

Pattern **/*.hpp: Review the C++ code, point out issues relative to principles of clean code, expressiveness, and performance.

🔇 Additional comments (5)
src/core/numerics/ohm/ohm.hpp (2)

15-16: LGTM: New enum HyperMode added

The addition of the HyperMode enum is well-implemented. It provides a clear and type-safe way to specify the hyperresistivity mode.


339-349: LGTM: hyperresistive_ method updated

The changes to the hyperresistive_ method are well-implemented, providing flexibility based on the hyper_mode. The error handling for an unknown mode is appropriate.

However, the TODO comment that was present in the previous version has been removed. Please verify if the issue referenced in that comment has been addressed or if it should be maintained.

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

1174-1174: LGTM! Good addition of the accessor method.

The levelNumber() method is a well-implemented accessor for the new levelNumber_ member. It correctly provides read-only access and is marked as const.


Line range hint 1-1519: Overall, good improvements to support multi-level simulations and field conversions.

The changes to the GridLayout class, including the addition of the level_number parameter, levelNumber() accessor, and B to E field conversion methods, enhance the functionality for multi-level simulations and improve the flexibility of field component manipulations. These additions are well-implemented and maintain good coding practices.

Consider addressing the minor documentation suggestions to further improve code clarity and maintainability.

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

239-242: Additions of Ohm's Law parameters are correctly implemented

The code correctly adds resistivity, hyper_resistivity, and hyper_mode to the simulation configuration within the populateDict function. This enhancement allows for better configurability of the simulation's Ohm's Law parameters, supporting spatially variable hyperresistivity as described in PR #893.

{ // TODO : https://github.com/PHAREHUB/PHARE/issues/3
auto const lvlCoeff = 1. / std::pow(4, layout_->levelNumber());

auto computeHR = [&](auto BxProj, auto ByProj, auto BzProj, auto nProj) {

Check notice

Code scanning / CodeQL

Large object passed by value Note

This parameter of type
array<WeightPoint<3UL>, 8UL>
is 192 bytes - consider passing a const pointer/reference instead.
{ // TODO : https://github.com/PHAREHUB/PHARE/issues/3
auto const lvlCoeff = 1. / std::pow(4, layout_->levelNumber());

auto computeHR = [&](auto BxProj, auto ByProj, auto BzProj, auto nProj) {

Check notice

Code scanning / CodeQL

Large object passed by value Note

This parameter of type
array<WeightPoint<3UL>, 8UL>
is 192 bytes - consider passing a const pointer/reference instead.
{ // TODO : https://github.com/PHAREHUB/PHARE/issues/3
auto const lvlCoeff = 1. / std::pow(4, layout_->levelNumber());

auto computeHR = [&](auto BxProj, auto ByProj, auto BzProj, auto nProj) {

Check notice

Code scanning / CodeQL

Large object passed by value Note

This parameter of type
array<WeightPoint<3UL>, 8UL>
is 192 bytes - consider passing a const pointer/reference instead.
@PhilipDeegan PhilipDeegan merged commit af3f2be into PHAREHUB:master Oct 18, 2024
12 checks passed
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