Skip to content

Comments

Fix/mhd cleaning speed#1235

Open
ChrisZYJ wants to merge 6 commits intoMFlowCode:masterfrom
ChrisZYJ:fix/mhd-cleaning-speed
Open

Fix/mhd cleaning speed#1235
ChrisZYJ wants to merge 6 commits intoMFlowCode:masterfrom
ChrisZYJ:fix/mhd-cleaning-speed

Conversation

@ChrisZYJ
Copy link
Contributor

@ChrisZYJ ChrisZYJ commented Feb 22, 2026

User description

Placing my changes here as I don't have write access to #1180

Summary by CodeRabbit

  • Improvements

    • Apply hyper-cleaning speed constraints to MHD wave speeds when hyper-cleaning is enabled, improving stability of relevant simulations.
  • New Features

    • Validator enforces the required wave speed setting for MHD runs to prevent incompatible configurations.
  • Tests

    • Regenerated test metadata and environment records across multiple test cases to reflect updated configuration runs.

CodeAnt-AI Description

Fix MHD hyperbolic cleaning wave sign and enforce correct MHD wave_speeds

What Changed

  • Hyperbolic (Dedner/GLM) cleaning now clamps Riemann-wave bounds to +/- cleaning speed so cleaning waves have the correct sign and magnitude (fixes left-state sign error).
  • Validator now rejects configurations that set wave_speeds = 2 for MHD and requires wave_speeds = 1, producing a clear validation error.
  • Golden test outputs for MHD hyper-cleaning and rotor tests regenerated to reflect the corrected cleaning behavior.

Impact

✅ Fewer MHD hyper-cleaning instabilities during runs
✅ Clearer validation errors for incorrect MHD wave_speeds
✅ Test outputs match corrected MHD cleaning behavior

💡 Usage Guide

Checking Your Pull Request

Every time you make a pull request, our system automatically looks through it. We check for security issues, mistakes in how you're setting up your infrastructure, and common code problems. We do this to make sure your changes are solid and won't cause any trouble later.

Talking to CodeAnt AI

Got a question or need a hand with something in your pull request? You can easily get in touch with CodeAnt AI right here. Just type the following in a comment on your pull request, and replace "Your question here" with whatever you want to ask:

@codeant-ai ask: Your question here

This lets you have a chat with CodeAnt AI about your pull request, making it easier to understand and improve your code.

Example

@codeant-ai ask: Can you suggest a safer alternative to storing this secret?

Preserve Org Learnings with CodeAnt

You can record team preferences so CodeAnt AI applies them in future reviews. Reply directly to the specific CodeAnt AI suggestion (in the same thread) and replace "Your feedback here" with your input:

@codeant-ai: Your feedback here

This helps CodeAnt AI learn and adapt to your team's coding style and standards.

Example

@codeant-ai: Do not flag unused imports.

Retrigger review

Ask CodeAnt AI to review the PR again, by typing:

@codeant-ai: review

Check Your Repository Health

To analyze the health of your code repository, visit our dashboard at https://app.codeant.ai. This tool helps you identify potential issues and areas for improvement in your codebase, ensuring your repository maintains high standards of code health.

sbryngelson and others added 3 commits February 20, 2026 22:53
…ic speed

min(c_fast%L, -hyper_cleaning_speed) forces c_fast%L negative, but
fast magnetosonic speeds should be positive. Changed to max() to
match the right-state treatment.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Update golden files for hyper_cleaning and mhd_rotor tests to reflect
the corrected min/max sign for the left-state fast magnetosonic speed.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@codeant-ai
Copy link
Contributor

codeant-ai bot commented Feb 22, 2026

CodeAnt AI is reviewing your PR.


Thanks for using CodeAnt! 🎉

We're free for open-source projects. if you're enjoying it, help us grow by sharing.

Share on X ·
Reddit ·
LinkedIn

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Feb 22, 2026

📝 Walkthrough

Walkthrough

Moves the hyper_cleaning wave-speed clamp into the wave_speeds == 1 branch of the MHD Riemann solver (Dedner GLM context), and adds a validator preventing MHD with wave_speeds = 2. Also updates several test golden-metadata files with environment/toolchain rewrites.

Changes

Cohort / File(s) Summary
MHD Hyper-cleaning Logic
src/simulation/m_riemann_solvers.fpp
Relocated hyper_cleaning adjustment to the wave_speeds == 1 branch; clamp s_L/s_R using hyper_cleaning_speed and added Dedner GLM comment.
MHD Validation
toolchain/mfc/case_validator.py
Added validation: if MHD enabled and wave_speeds == 2, raise error enforcing wave_speeds = 1.
Test Golden Metadata
tests/B4DC99F9/golden-metadata.txt, tests/EC8F87D9/golden-metadata.txt, tests/F057F8E6/golden-metadata.txt
Re-recorded environment metadata: timestamps, git branch/commits, host/toolchain paths (mpicc/mpicxx/gfortran), CPU/architecture and config toggles (PRE_PROCESS/SIMULATION/POST_PROCESS) updated across files.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Suggested labels

Review effort 4/5, size:XXL

Suggested reviewers

  • sbryngelson

Poem

🐰 I hopped through code with careful paws,
Bounding speeds with sensible laws.
Dedner whispers in the solver's ear,
Wave clamps set — no chaos here.
A tidy fix, a carrot cheer! 🥕

🚥 Pre-merge checks | ✅ 2 | ❌ 1

❌ Failed checks (1 inconclusive)

Check name Status Explanation Resolution
Title check ❓ Inconclusive The title 'Fix/mhd cleaning speed' is vague and uses a common prefix pattern that doesn't clearly convey the specific change being made without additional context. Improve clarity by using a more descriptive title like 'Fix MHD hyperbolic cleaning wave speed sign constraints' or 'Correct Dedner GLM cleaning speed application in MHD Riemann solver'.
✅ Passed checks (2 passed)
Check name Status Explanation
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.
Description check ✅ Passed The pull request description provides clear summary of changes, motivation, and includes a detailed CodeAnt-AI description with impact overview.

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

✨ Finishing Touches
  • 📝 Generate docstrings (stacked PR)
  • 📝 Generate docstrings (commit on current branch)
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment

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

❤️ Share

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

@codeant-ai codeant-ai bot added the size:L This PR changes 100-499 lines, ignoring generated files label Feb 22, 2026
Copy link
Contributor

@cubic-dev-ai cubic-dev-ai bot left a comment

Choose a reason for hiding this comment

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

No issues found across 8 files

Confidence score: 5/5

  • Automated review surfaced no issues in the provided summaries.
  • No files require special attention.

@codeant-ai
Copy link
Contributor

codeant-ai bot commented Feb 22, 2026

Nitpicks 🔍

🔒 No security issues identified
⚡ Recommended areas for review

  • Validation locality / duplication
    wave_speeds is retrieved and validated in multiple places (e.g. check_riemann_solver and the new check_mhd_simulation). Having duplicated checks risks inconsistent error messages and maintenance burden — consider centralizing logic or delegating all wave_speeds validation to one check.

@codeant-ai
Copy link
Contributor

codeant-ai bot commented Feb 22, 2026

CodeAnt AI finished reviewing your PR.

Copy link
Contributor

@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

🧹 Nitpick comments (2)
toolchain/mfc/case_validator.py (2)

1036-1037: Consider wave_speeds != 1 to align with the error message and guard against future additions.

The condition wave_speeds == 2 and the message "MHD requires wave_speeds = 1" are currently consistent (valid values are only 1 or 2), but expressing the constraint as != 1 better matches the stated requirement and stays correct if new wave_speeds values are ever introduced.

♻️ Suggested change
-        self.prohibit(mhd and wave_speeds is not None and wave_speeds == 2,
+        self.prohibit(mhd and wave_speeds is not None and wave_speeds != 1,
                      "MHD requires wave_speeds = 1")
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@toolchain/mfc/case_validator.py` around lines 1036 - 1037, The check in the
case validation currently prohibits only wave_speeds == 2 when MHD is enabled;
update the condition in the prohibit call (the one using self.prohibit with mhd
and wave_speeds) to reject any value other than 1 (i.e., use wave_speeds is not
None and wave_speeds != 1) so the error message "MHD requires wave_speeds = 1"
stays correct and remains future-proof; keep the same error string and the same
call site (the self.prohibit line referencing mhd and wave_speeds).

186-193: Update PHYSICS_DOCS to document the new wave_speeds = 1 MHD constraint.

The check_mhd entry's explanation does not reflect the new simulation-specific requirement, and check_mhd_simulation has no PHYSICS_DOCS entry at all. Per the contributing guidelines, physics constraints added to validator methods should be reflected in PHYSICS_DOCS so the auto-generated documentation stays accurate.

Suggested addition to PHYSICS_DOCS:

"check_mhd_simulation": {
    "title": "MHD Simulation Constraints",
    "category": "Feature Compatibility",
    "explanation": (
        "MHD simulations require riemann_solver = 1 (HLL) or 4 (HLLD). "
        "wave_speeds must be 1 (Roe averages) — wave_speeds = 2 is incompatible "
        "with the hyperbolic GLM cleaning speed treatment. "
        "HLLD is not available for RMHD. Hyperbolic cleaning requires 2D or 3D."
    ),
},

Based on learnings: "When adding a check_ method to case_validator.py, document its physics in the PHYSICS_DOCS dict with title, category, explanation, and optional math/references/exceptions."

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@toolchain/mfc/case_validator.py` around lines 186 - 193, PHYSICS_DOCS is
missing documentation for the new wave_speeds constraint: update the "check_mhd"
explanation to mention the new requirement that wave_speeds = 1 for MHD and add
a new "check_mhd_simulation" entry in PHYSICS_DOCS describing riemann_solver = 1
(HLL) or 4 (HLLD), wave_speeds must be 1 (Roe averages) and that wave_speeds = 2
is incompatible with hyperbolic GLM cleaning, plus notes that HLLD is
unavailable for RMHD and hyperbolic cleaning requires 2D/3D; use the
PHYSICS_DOCS dict and reference the validator methods check_mhd and
check_mhd_simulation so the auto-generated docs reflect the new constraint.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@tests/EC8F87D9/golden-metadata.txt`:
- Around line 1-7: The golden file was generated from a dirty workspace on
branch fix/mhd-cleaning-speed for test EC8F87D9; confirm whether the uncommitted
changes used to generate tests/golden-metadata.txt actually match the committed
fix by comparing the working tree to the commit (e.g., git status/diff against
commit 36bf82625f0ad02f42ceeb2fe0fba0eda80fab9f). If they differ, regenerate the
golden using a clean checkout of the intended commit and commit that golden (or
include the missing changes in the branch); if they match, update the metadata
to reflect a clean generation (remove “dirty” note or update the recorded Git
hash to the final commit) and leave the 1e-3 tolerance as-is since it is
intentionally loose for cross‑platform FP variability.

---

Duplicate comments:
In `@tests/B4DC99F9/golden-metadata.txt`:
- Line 7: The golden-metadata.txt for test "mhd_rotor" contains non-portable,
dirty-workspace and machine-specific info (commit shows as dirty and host
LAPTOP-OMEN); regenerate the golden metadata from a clean repo state (no
uncommitted changes) or CI runner so the commit hash is clean and
remove/normalize host-specific fields, then update the test's
golden-metadata.txt to the deterministic values (clean commit id and neutral
host/machine fields) so the test no longer depends on a local dirty workspace or
personal laptop.

---

Nitpick comments:
In `@toolchain/mfc/case_validator.py`:
- Around line 1036-1037: The check in the case validation currently prohibits
only wave_speeds == 2 when MHD is enabled; update the condition in the prohibit
call (the one using self.prohibit with mhd and wave_speeds) to reject any value
other than 1 (i.e., use wave_speeds is not None and wave_speeds != 1) so the
error message "MHD requires wave_speeds = 1" stays correct and remains
future-proof; keep the same error string and the same call site (the
self.prohibit line referencing mhd and wave_speeds).
- Around line 186-193: PHYSICS_DOCS is missing documentation for the new
wave_speeds constraint: update the "check_mhd" explanation to mention the new
requirement that wave_speeds = 1 for MHD and add a new "check_mhd_simulation"
entry in PHYSICS_DOCS describing riemann_solver = 1 (HLL) or 4 (HLLD),
wave_speeds must be 1 (Roe averages) and that wave_speeds = 2 is incompatible
with hyperbolic GLM cleaning, plus notes that HLLD is unavailable for RMHD and
hyperbolic cleaning requires 2D/3D; use the PHYSICS_DOCS dict and reference the
validator methods check_mhd and check_mhd_simulation so the auto-generated docs
reflect the new constraint.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 2

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

Inline comments:
In `@tests/F057F8E6/golden-metadata.txt`:
- Line 13: The golden metadata shows "CMake v3.22.1 on LAPTOP-OMEN" (WSL2) which
may differ from CI and cause FP mismatches; re-run the test suite in the CI
environment (or reproduce the CI container/toolchain locally) to confirm the
committed goldens match CI results, and if they do not, regenerate the goldens
using the CI toolchain and update the golden files (or add CI-approved golden
artifacts) so that tests pass in CI; ensure the change references the metadata
entry "CMake v3.22.1 on LAPTOP-OMEN" when validating/regenerating.
- Line 7: The golden metadata shows the working tree was "(dirty)" for commit
b90fc2c922c770d767018bf7c7bf323c5dbe9e97 on branch fix/mhd-cleaning-speed;
inspect that commit and the working tree state by running a clean checkout of
that SHA (or checkout the branch and stash/reset local changes), then run git
status and git diff to identify any uncommitted changes; confirm any differences
are only environment/path items (e.g., local Fypp path or compiler wrapper) and
not code that affects physics/algorithms, regenerate the golden outputs from the
clean checkout and compare them to the current goldens (and update
tests/golden-metadata.txt only after proving reproducibility from the committed
tree) to ensure no unintended code changes were baked into the goldens.

@codecov
Copy link

codecov bot commented Feb 22, 2026

Codecov Report

❌ Patch coverage is 33.33333% with 2 lines in your changes missing coverage. Please review.
✅ Project coverage is 44.06%. Comparing base (df28255) to head (a502d7e).
⚠️ Report is 9 commits behind head on master.

Files with missing lines Patch % Lines
src/simulation/m_riemann_solvers.fpp 33.33% 2 Missing ⚠️
Additional details and impacted files
@@           Coverage Diff           @@
##           master    #1235   +/-   ##
=======================================
  Coverage   44.05%   44.06%           
=======================================
  Files          70       70           
  Lines       20496    20496           
  Branches     1989     1989           
=======================================
+ Hits         9030     9031    +1     
  Misses      10328    10328           
+ Partials     1138     1137    -1     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@sbryngelson
Copy link
Member

Supersedes #1180 (fixes #1201).

@codeant-ai
Copy link
Contributor

codeant-ai bot commented Feb 22, 2026

CodeAnt AI is running Incremental review


Thanks for using CodeAnt! 🎉

We're free for open-source projects. if you're enjoying it, help us grow by sharing.

Share on X ·
Reddit ·
LinkedIn

@codeant-ai codeant-ai bot added size:L This PR changes 100-499 lines, ignoring generated files and removed size:L This PR changes 100-499 lines, ignoring generated files labels Feb 22, 2026
@codeant-ai
Copy link
Contributor

codeant-ai bot commented Feb 22, 2026

CodeAnt AI Incremental review completed.

@github-actions
Copy link

Claude Code Review

No issues found. Checked for bugs and CLAUDE.md compliance.

@github-actions
Copy link

Claude Code Review

No issues found. Checked for bugs and CLAUDE.md compliance.

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

Labels

size:L This PR changes 100-499 lines, ignoring generated files

Development

Successfully merging this pull request may close these issues.

2 participants