Skip to content

Comments

Fix 6 low-risk pre-process bugs (batch)#1241

Open
sbryngelson wants to merge 11 commits intoMFlowCode:masterfrom
sbryngelson:fix/low-risk-bugfixes-batch
Open

Fix 6 low-risk pre-process bugs (batch)#1241
sbryngelson wants to merge 11 commits intoMFlowCode:masterfrom
sbryngelson:fix/low-risk-bugfixes-batch

Conversation

@sbryngelson
Copy link
Member

@sbryngelson sbryngelson commented Feb 22, 2026

User description

Summary

Batches 6 low-risk bug fixes in pre-process code paths. These fix real numerical issues in IC generation but don't touch simulation GPU kernels or MPI hot paths.

Included fixes

Supersedes

Closes #1174, closes #1179, closes #1183, closes #1216, closes #1217, closes #1188

Test plan

  • All GitHub CI checks pass (ubuntu MPI debug, ubuntu no-mpi, macOS)
  • All changes are in pre-process or MPI setup — no simulation hot-path modifications
  • Verify with stretched grid, QBMM, MHD, and IB test cases if available

🤖 Generated with Claude Code

Summary by CodeRabbit

  • Bug Fixes

    • Fixed grid cell-center indexing in y/z for accurate grid generation.
    • Removed a redundant momentum accumulation step.
  • Improvements

    • Enhanced initialization to better support 3D configurations.
    • Improved numerical precision for monotonicity constraint handling.
  • Chores

    • Reorganized MPI communication sequence for immersed-boundary variables.

CodeAnt-AI Description

Fix several pre-process bugs that caused incorrect initial conditions and grid errors

What Changed

  • THINC monotonicity limiter now uses a tiny real threshold so the limiter is applied correctly (previously treated as zero and effectively disabled)
  • Stretched grid cell-center coordinates for y and z now use the correct dimension bounds so stretched grids produce correct cell centers when dimensions differ
  • QBMM bubble size accumulator corrected so initial bubble perturbation magnitudes are not doubled
  • Random flow perturbation now updates the intended velocity component in the correct order so velocity perturbations use the original values
  • Hyper-cleaning psi initialization now fills all 3D planes, uses consistent precision, and avoids accessing z-coordinates in 2D runs
  • Immersed-boundary patch velocity/angle data are broadcast across MPI in the correct loop so all ranks receive IB motion data

Impact

✅ Correct THINC monotonicity behavior during interface reconstruction
✅ Accurate stretched grid coordinates when x/y/z sizes differ
✅ Correct initial bubble perturbation magnitudes for QBMM cases

💡 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.

Copilot AI review requested due to automatic review settings February 22, 2026 20:58
@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

Six targeted bug fixes across preprocessing and constants: corrected a constant type, removed a duplicate accumulation, fixed grid center index bounds, moved MPI broadcasts to the correct loop, adjusted perturbation assignments, and expanded 3D startup psi initialization to all z-planes.

Changes

Cohort / File(s) Summary
Constants
src/common/m_constants.fpp
Changed moncon_cutoff from integer to real(wp) so 1e-8_wp is retained as a real value.
QBMM / Perturbation
src/pre_process/m_assign_variables.fpp
Removed duplicate R3bar accumulation line in QBMM branch that previously doubled the contribution.
Grid generation
src/pre_process/m_grid.f90
Fixed cell-center assignments to use correct dimension bounds: y_cc(0:n) and z_cc(0:p) (previously used m).
MPI / IB broadcasts
src/pre_process/m_mpi_proxy.fpp
Moved broadcasts of patch_ib(%vel), patch_ib(%angular_vel), and patch_ib(%angles) out of the BC-patch loop into the IB-patch broadcast blocks using correct sizes.
Perturbation ordering
src/pre_process/m_perturbation.fpp
Adjusted assignment order so y-velocity perturbation reads the original x-velocity before x-velocity is modified (prevents unintended coupling).
Startup / 3D init
src/pre_process/m_start_up.fpp
Extended hyper_cleaning psi initialization to loop over l = 0..p, initializing psi across all z-planes and using z_cc(l) in the Gaussian expression.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

Possibly related issues

  • MFlowCode/MFC#1197: Same moncon_cutoff fix — changes moncon_cutoff to real(wp) to avoid truncation-to-zero.
  • MFlowCode/MFC#1208: Same IB broadcast relocation — moves vel/angular_vel/angles broadcasts into correct IB-patch loop.

Possibly related PRs

  • MFlowCode/MFC#1116: Modifies IB-variable MPI broadcast logic in m_mpi_proxy.fpp, strongly related to the broadcast reorganization here.
  • MFlowCode/MFC#1063: Changes s_perturb_primitive in m_assign_variables.fpp; related to the QBMM / perturbation adjustments in this PR.

Suggested labels

Review effort 1/5, size:L

Suggested reviewers

  • wilfonba

Poem

🐰 I hopped through code and found the spots,
Constants mended, grids set in their slots.
Broadcasts moved to the proper loop,
Perturbations fixed — no sneaky dup or loop.
Psi now fills every z-plane — hop, hop, hooray!

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed Title clearly summarizes a batch of low-risk pre-process bug fixes, accurately representing the primary changes across multiple files.
Linked Issues check ✅ Passed All code changes directly address the primary coding requirements from the six linked issues: moncon_cutoff type correction, grid bounds fixes, duplicate removal, velocity order correction, psi 3D initialization, and IB broadcast loop relocation.
Out of Scope Changes check ✅ Passed All six file changes are scoped to the linked issues: constant declaration, grid computation, QBMM accumulation, perturbation order, hyper-cleaning initialization, and MPI broadcast loop—no out-of-scope changes detected.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Description check ✅ Passed The pull request description includes all required template sections: summary of changes, issue references, type of change (Refactor), testing notes, and a comprehensive checklist with GPU considerations noted.

✏️ 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:S This PR changes 10-29 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 6 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

  • IB broadcast placement
    The broadcast of IB patch arrays (vel, angular_vel, angles) has been moved into the IB broadcast block. Verify there are no remaining duplicated broadcasts, that the size/count (3) matches the array shapes everywhere, and that ordering of broadcasts matches the data layout expected on receivers.

  • Monotonicity cutoff type
    The parameter moncon_cutoff was changed from an integer to a real. Verify every usage site expects a real (comparisons, arithmetic, interfaces). Mixed-type assumptions elsewhere could silently convert or truncate values or change logic in monotonicity checks.

  • Y cell-center bounds
    The y cell-center calculation was corrected to use the y-dimension range. Validate index ranges of y_cb and y_cc (uses of -1:n-1) are consistent with alloc/usage elsewhere, and that the min cell size dy and subsequent MPI reduction use the updated values.

  • Z cell-center bounds
    The z cell-center calculation was corrected to use the z-dimension range. Confirm z_cb/z_cc indexing and dz computation are correct for both serial and parallel grid routines and consistent with any callers.

  • Perturbation assignment order
    The order of assignments for perturbed momenta was changed so mom_idx%end is set from the original mom_idx%beg before mom_idx%beg is scaled. Confirm no other code in the same loop reads mom_idx%beg after it is updated (should use original value) and consider making the use of the original value explicit to avoid future ordering bugs.

@codeant-ai
Copy link
Contributor

codeant-ai bot commented Feb 22, 2026

CodeAnt AI finished reviewing your PR.

Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR batches 6 bug fixes in pre-process code paths that address real numerical issues in initial condition generation. The fixes correct type declarations, array bounds, duplicate operations, statement ordering, loop coverage, and MPI broadcast placement.

Changes:

  • Fixed moncon_cutoff declared as integer instead of real(wp), which silently truncated 1e-8 to 0 and disabled MUSCL-THINC monotonicity limiting
  • Corrected grid stretching array bounds for y_cc and z_cc using wrong dimension (m instead of n and p)
  • Removed duplicate R3bar accumulation line that doubled bubble perturbation magnitude in QBMM initial conditions
  • Reordered perturbation statements so y-velocity uses original x-velocity before x-velocity is modified
  • Extended hyper-cleaning psi initialization to cover all z-planes in 3D (was only initializing k=0 plane)
  • Moved IB patch velocity/angular_vel/angles broadcasts from wrong loop to correct loop

Reviewed changes

Copilot reviewed 6 out of 6 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
src/common/m_constants.fpp Changed moncon_cutoff from integer to real(wp) to prevent truncation
src/pre_process/m_grid.f90 Fixed y_cc and z_cc array bounds to use correct dimensions (n and p instead of m)
src/pre_process/m_assign_variables.fpp Removed duplicate R3bar accumulation line in QBMM branch
src/pre_process/m_perturbation.fpp Swapped statement order so y-velocity perturbation uses unmodified x-velocity
src/pre_process/m_start_up.fpp Added outer z-loop for 3D psi initialization and replaced double-precision literal
src/pre_process/m_mpi_proxy.fpp Moved patch_ib vel/angular_vel/angles broadcasts to num_patches_max loop

@MFlowCode MFlowCode deleted a comment from github-actions bot Feb 23, 2026
@MFlowCode MFlowCode deleted a comment from github-actions bot Feb 23, 2026
@codeant-ai
Copy link
Contributor

codeant-ai bot commented Feb 23, 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:S This PR changes 10-29 lines, ignoring generated files and removed size:S This PR changes 10-29 lines, ignoring generated files labels Feb 23, 2026
@codeant-ai
Copy link
Contributor

codeant-ai bot commented Feb 23, 2026

CodeAnt AI Incremental review completed.

@codecov
Copy link

codecov bot commented Feb 23, 2026

Codecov Report

❌ Patch coverage is 27.27273% with 8 lines in your changes missing coverage. Please review.
✅ Project coverage is 44.05%. Comparing base (df28255) to head (068c79c).
⚠️ Report is 10 commits behind head on master.

Files with missing lines Patch % Lines
src/pre_process/m_start_up.fpp 28.57% 5 Missing ⚠️
src/pre_process/m_grid.f90 0.00% 2 Missing ⚠️
src/pre_process/m_perturbation.fpp 0.00% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master    #1241      +/-   ##
==========================================
- Coverage   44.05%   44.05%   -0.01%     
==========================================
  Files          70       70              
  Lines       20496    20499       +3     
  Branches     1989     1992       +3     
==========================================
+ Hits         9030     9031       +1     
- Misses      10328    10330       +2     
  Partials     1138     1138              

☔ 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.

@codeant-ai
Copy link
Contributor

codeant-ai bot commented Feb 23, 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:S This PR changes 10-29 lines, ignoring generated files and removed size:S This PR changes 10-29 lines, ignoring generated files labels Feb 23, 2026
@codeant-ai
Copy link
Contributor

codeant-ai bot commented Feb 23, 2026

CodeAnt AI Incremental review completed.

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

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

Inline comments:
In `@src/pre_process/m_start_up.fpp`:
- Around line 790-797: Add a validator in the CaseValidator
(toolchain/mfc/case_validator.py) to forbid enabling hyper_cleaning in 2D: call
self.prohibit(hyper_cleaning and p is not None and p == 0, "Hyperbolic cleaning
is not supported for 2D simulations") in the validation routine that checks
dimensionality (the same place that already forbids 1D via n==0); this prevents
m_start_up.fpp from accessing unallocated z_cc when p==0 by rejecting
hyper_cleaning for 2D cases.

ℹ️ Review info

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between e8d2790 and 553161d.

📒 Files selected for processing (6)
  • src/common/m_constants.fpp
  • src/pre_process/m_assign_variables.fpp
  • src/pre_process/m_grid.f90
  • src/pre_process/m_mpi_proxy.fpp
  • src/pre_process/m_perturbation.fpp
  • src/pre_process/m_start_up.fpp
💤 Files with no reviewable changes (1)
  • src/pre_process/m_assign_variables.fpp
🚧 Files skipped from review as they are similar to previous changes (2)
  • src/common/m_constants.fpp
  • src/pre_process/m_mpi_proxy.fpp

moncon_cutoff is assigned 1e-8_wp but declared as integer, so Fortran
silently truncates it to 0. This makes all THINC monotonicity constraint
comparisons always true, completely disabling the constraint.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
sbryngelson and others added 9 commits February 23, 2026 09:48
y_cc(0:m) and z_cc(0:m) use the x-dimension size m instead of the
y-dimension n and z-dimension p respectively. Corrupts cell-center
coordinates when grid stretching is enabled and m != n or m != p.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
…tion

Character-for-character identical duplicate line causes R3bar to
always be 2x the intended value for QBMM cases.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
z_cc is only allocated when p > 0. The previous commit accessed z_cc(l)
unconditionally, which would crash or read garbage in 2D runs.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Replace `1d-2` (hard double precision) and bare `2.0`/`0.05` (default
real) with `_wp`-suffixed literals so the Gaussian initialization is
consistent with the working precision across single and double builds.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
patch_ib vel, angular_vel, and angles were broadcast inside the
num_bc_patches_max loop instead of the num_patches_max loop where
the other patch_ib fields are broadcast.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
- Remove redundant if(p>0) branch in psi initialization: z_cc(0)=0
  in 2D, so the 3D formula produces identical results in both cases.
- Replace hardcoded 3 with size(patch_ib(i)%VAR) in MPI_BCAST for
  vel/angular_vel/angles, consistent with other IB broadcasts.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Build the Gaussian r^2 incrementally, guarding y_cc(k) behind n > 0
and z_cc(l) behind p > 0, since these arrays are only allocated in
2D+ and 3D respectively. Prevents undefined behavior if hyper_cleaning
is enabled in a 1D MHD configuration.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@sbryngelson sbryngelson force-pushed the fix/low-risk-bugfixes-batch branch from 285998d to 068c79c Compare February 23, 2026 14:48
@codeant-ai
Copy link
Contributor

codeant-ai bot commented Feb 23, 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:S This PR changes 10-29 lines, ignoring generated files and removed size:S This PR changes 10-29 lines, ignoring generated files labels Feb 23, 2026
@codeant-ai
Copy link
Contributor

codeant-ai bot commented Feb 23, 2026

CodeAnt AI Incremental review completed.

@MFlowCode MFlowCode deleted a comment from github-actions bot Feb 23, 2026
@MFlowCode MFlowCode deleted a comment from github-actions bot Feb 23, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

size:S This PR changes 10-29 lines, ignoring generated files

Development

Successfully merging this pull request may close these issues.

1 participant