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

safer nu #911

Merged
merged 1 commit into from
Oct 24, 2024
Merged

safer nu #911

merged 1 commit into from
Oct 24, 2024

Conversation

nicolasaunai
Copy link
Member

@nicolasaunai nicolasaunai commented Oct 20, 2024

replaces

$$ -\nu_0 \frac{B}{n} L\nabla^2\mathbf{j} $$

which becomes too small when $B\to 0$, typically around reconnection X points.

Capture d’écran 2024-10-19 à 16 06 24

There, increasing $\nu_0$ is not solving the problem, it only increases dissipation in regions where B is non-zero and cannot prevent the dissipation to go to zero with B.

The proposed formula is:

$$ -\nu_0 (\frac{B}{n+n_\epsilon}+1) L\nabla^2\mathbf{j} $$

which tends to:

with

$$ -\nu_0 L\nabla^2\mathbf{j} $$

when $B\to 0$

and

$$ -\nu_0 (\frac{B}{n_\epsilon}+1) L\nabla^2\mathbf{j} $$

when $n\to 0$

For reference, here is what we get un run055 with constant hyper-resistivity $\nu=0.002$:

image

Copy link

coderabbitai bot commented Oct 20, 2024

📝 Walkthrough

Walkthrough

The changes involve modifications to the Ohm class within the PHARE::core namespace, specifically targeting the spatial_hyperresistive_ method. A new constant, min_density, is introduced with a value of 0.1, which is incorporated into the formula for calculating the hyperresistive term. The formula has been updated to adjust the computation when hyper_mode is set to spatial. Minor formatting adjustments were also made for consistency in the definition of lvlCoeff.

Changes

File Path Change Summary
src/core/numerics/ohm/ohm.hpp Updated spatial_hyperresistive_ method to include new constant min_density in the calculation formula. Minor formatting adjustments to lvlCoeff.

Sequence Diagram(s)

sequenceDiagram
    participant User
    participant Ohm
    participant Layout

    User->>Ohm: Call spatial_hyperresistive_()
    Ohm->>Layout: Calculate laplacian(J(component), index)
    Ohm->>Ohm: Compute hyperresistive term using min_density
    Ohm-->>User: Return computed value
Loading

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.

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 (3)
src/core/numerics/ohm/ohm.hpp (3)

363-364: LGTM with a minor suggestion.

The separation of lvlCoeff calculation improves readability. The introduction of min_density aligns with the PR objective of enhancing stability for low magnetic field strengths.

Consider using a more descriptive name for min_density, such as min_density_threshold, to better convey its purpose in preventing division by zero or near-zero values.


372-373: Approved: Formula update aligns with PR objectives.

The updated formula (b / (nOnE + min_density) + 1) effectively addresses the issue of the expression becoming too small when the magnetic field strength approaches zero. This change enhances the stability of the calculations, particularly around reconnection X points.

Consider pre-computing the inverse of (nOnE + min_density) to potentially improve performance:

-            return -nu_ * (b / (nOnE + min_density) + 1) * lvlCoeff
+            auto inv_denominator = 1.0 / (nOnE + min_density);
+            return -nu_ * (b * inv_denominator + 1) * lvlCoeff
                 * layout_->laplacian(J(component), index);

This optimization could be beneficial if this calculation is performed frequently in performance-critical sections.


Line range hint 363-389: LGTM: Well-structured implementation with improved stability.

The spatial_hyperresistive_ method is well-implemented, using a lambda function to reduce code duplication and correctly handling different components with their respective projections. The changes successfully address the PR objectives by improving the stability of calculations when the magnetic field strength approaches zero.

Consider adding a brief comment explaining the purpose of the min_density constant and how it contributes to the stability of the calculations. This would enhance the maintainability of the code for future developers.

📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL

📥 Commits

Files that changed from the base of the PR and between c262a75 and 9dca30e.

📒 Files selected for processing (1)
  • src/core/numerics/ohm/ohm.hpp (1 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.

@nicolasaunai
Copy link
Member Author

nicolasaunai commented Oct 23, 2024

Ok so here is a result for this new PR.
All panels show the electric field $E_y$ in a symmetric reconnection simulation.
In all simulations $\nu_0 = 0.002$

The upper panel uses constant hyper-resistivity

$$ -\nu_0 \nabla^\mathbf{j} $$

We see that it is too dissipative. Typically if the term is non-negligible on L0, dissipation will be too large on L2 (because the grid scale decreases relative to the dissipative scale imposed by $\nu_0$.

Second panel uses spatial hyper-mode:

$$ -\nu_0\frac{B}{n} L \nabla^\mathbf{j} $$

from master.
In this case, we see the dissipation is basically non-existent around the X line and the electric field gets super strong.
The reason is that in the X point region, $B\to 0$ so the hyper-resistive term becomes negligible no matter how large $\nu_0$ is.

Third panel uses the proposed formula

$$ -\nu_0 \left(\frac{B}{n + n_\epsilon} + 1\right)L\nabla^2\mathbf{j} $$

with $n_\epsilon=0.1$

In contrast to the master version, dissipation clearly operates around the X point despite $\nu_0$ being the same and $B\to 0$, showing the effect of the new formula. We also see the simulation is less dissipative overall than the constant hyper mode, showing the benefit of having the level-dependent coefficient.

Last panel is the same as above with larger nu

image

here a zoom version

image

@nicolasaunai nicolasaunai merged commit 2a7e9b2 into PHAREHUB:master Oct 24, 2024
12 checks passed
UCaromel pushed a commit to UCaromel/PHARE that referenced this pull request Nov 13, 2024
UCaromel pushed a commit to UCaromel/PHARE that referenced this pull request Nov 13, 2024
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.

3 participants