Skip to content

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

Merged
sbryngelson merged 18 commits intoMFlowCode:masterfrom
sbryngelson:fix/low-risk-bugfixes-batch
Mar 12, 2026
Merged

Fix 6 low-risk pre-process bugs (batch)#1241
sbryngelson merged 18 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, fixes #1197, fixes #1202, fixes #1206, fixes #1208, fixes #1221, fixes #1222

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


CodeAnt-AI Description

Fix pre-process bugs that caused incorrect initial conditions and MPI broadcasts

What Changed

  • Restores the THINC monotonicity cutoff (now a real) so interface limiting is applied as intended instead of being silently disabled
  • Corrects stretched-grid cell-center calculations for y and z so stretched grids produce correct coordinates when dimensions differ
  • Removes a duplicated accumulation so QBMM bubble perturbation amplitude matches the intended value (was doubled)
  • Ensures velocity perturbations use the original velocity order so y-perturbations are computed from the unmodified x-velocity
  • Moves and sizes immersed-boundary variable broadcasts correctly so IB velocities, angular velocities, and angles are propagated reliably across MPI ranks
  • Initializes the hyper-cleaning field across all 3D planes, guards 2D runs, and fixes numeric literals so psi values are correct and consistent

Impact

✅ Correct THINC interface limiting
✅ Accurate stretched-grid coordinates
✅ Correct QBMM bubble perturbation amplitudes

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

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.

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 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
@codecov
Copy link

codecov bot commented Feb 23, 2026

Codecov Report

❌ Patch coverage is 25.00000% with 9 lines in your changes missing coverage. Please review.
✅ Project coverage is 44.95%. Comparing base (506c6f5) to head (f6ab8ce).
⚠️ Report is 1 commits behind head on master.

Files with missing lines Patch % Lines
src/pre_process/m_start_up.fpp 25.00% 6 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.95%   44.95%   -0.01%     
==========================================
  Files          70       70              
  Lines       20504    20509       +5     
  Branches     1946     1949       +3     
==========================================
+ Hits         9217     9219       +2     
- Misses      10166    10169       +3     
  Partials     1121     1121              

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

@sbryngelson sbryngelson force-pushed the fix/low-risk-bugfixes-batch branch from 285998d to 068c79c Compare February 23, 2026 14:48
@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
@MFlowCode MFlowCode deleted a comment from github-actions bot Feb 23, 2026
@MFlowCode MFlowCode deleted a comment from github-actions bot Feb 23, 2026
@sbryngelson sbryngelson force-pushed the fix/low-risk-bugfixes-batch branch 2 times, most recently from 9276e0b to 96f562c Compare February 24, 2026 16:03
@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 24, 2026
@sbryngelson sbryngelson force-pushed the fix/low-risk-bugfixes-batch branch from 1dcf0a3 to 22304a1 Compare February 24, 2026 16:50
sbryngelson and others added 5 commits February 28, 2026 14:42
The psi field used by hyperbolic cleaning is initialized with a
3D loop that accesses z_cc, which is out-of-bounds when p == 0.
The 1D prohibition already existed; extend it to 2D.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
In 1D simulations n==0 and p==0, so both the 1D and 2D prohibition
checks were firing simultaneously. Gate the 2D check on n > 0 so
it only triggers for configurations that are actually 2D.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
GLM divergence cleaning is valid in 2D. The z_cc access was already
guarded with `if (p > 0)` in 22304a1. The prohibition broke the
existing 2D hyper_cleaning, mhd_rotor, and orszag_tang tests.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
The @:ASSERT call added in d614938 requires the macros.fpp include,
which was missing, causing Fypp preprocessing to fail in the
documentation build.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@sbryngelson sbryngelson force-pushed the fix/low-risk-bugfixes-batch branch from df91890 to 732146c Compare February 28, 2026 19:42
@MFlowCode MFlowCode deleted a comment from github-actions bot Feb 28, 2026
@MFlowCode MFlowCode deleted a comment from github-actions bot Feb 28, 2026
sbryngelson added a commit to sbryngelson/MFC that referenced this pull request Mar 1, 2026
The linter will intentionally fail until PRs MFlowCode#1187 (WP_MOK),
MFlowCode#1241 (R3bar duplicate), and this PR's dq_prim_dy fix (now in
MFlowCode#1187) merge first.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@sbryngelson sbryngelson marked this pull request as ready for review March 2, 2026 17:20
@qodo-code-review
Copy link
Contributor

Review Summary by Qodo

Fix six low-risk pre-process bugs in IC generation

🐞 Bug fix

Grey Divider

Walkthroughs

Description
• Fixes moncon_cutoff type from integer to real, restoring THINC monotonicity limiting
• Corrects stretched-grid cell-center bounds for y and z dimensions using proper array sizes
• Removes duplicate R3bar accumulation that doubled QBMM bubble perturbation magnitude
• Fixes y-velocity perturbation order to use unmodified x-velocity values
• Extends hyper-cleaning psi initialization across all 3D planes with proper 2D guards
• Moves immersed-boundary variable broadcasts to correct loop scope for proper MPI propagation
Diagram
flowchart LR
  A["Pre-process bugs"] --> B["moncon_cutoff type fix"]
  A --> C["Grid stretching bounds"]
  A --> D["QBMM perturbation"]
  A --> E["Velocity perturbation order"]
  A --> F["Hyper-cleaning 3D init"]
  A --> G["IB broadcast scope"]
  B --> H["THINC limiting restored"]
  C --> I["Correct coordinates"]
  D --> J["Correct amplitude"]
  E --> K["Correct values"]
  F --> L["Full 3D coverage"]
  G --> M["Reliable MPI sync"]
Loading

Grey Divider

File Changes

1. src/common/m_constants.fpp 🐞 Bug fix +1/-1

Fix moncon_cutoff type truncation bug

• Changed moncon_cutoff declaration from integer to real(wp) parameter
• Preserves the assigned value 1e-8_wp which was being silently truncated to 0

src/common/m_constants.fpp


2. src/pre_process/m_assign_variables.fpp 🐞 Bug fix +3/-4

Remove duplicate R3bar and fix documentation

• Fixed typo in documentation comments: "areassigned" → "are assigned" (3 occurrences)
• Removed duplicate R3bar accumulation line in QBMM bubble perturbation calculation

src/pre_process/m_assign_variables.fpp


3. src/pre_process/m_grid.f90 🐞 Bug fix +2/-2

Correct grid stretching array bounds

• Fixed y_cc(0:m) bounds to y_cc(0:n) for y-dimension cell-center coordinates
• Fixed z_cc(0:m) bounds to z_cc(0:p) for z-dimension cell-center coordinates
• Ensures stretched grids produce correct coordinates when dimensions differ

src/pre_process/m_grid.f90


View more (3)
4. src/pre_process/m_mpi_proxy.fpp 🐞 Bug fix +5/-5

Fix IB broadcast loop scope and sizing

• Moved immersed-boundary variable broadcasts (vel, angular_vel, angles) from
 num_bc_patches_max loop to num_patches_max loop
• Added explanatory comment clarifying the indexing difference between patch_ib and patch_bc
• Changed broadcast size from hardcoded 3 to size(patch_ib(i)%${VAR}$) for robustness

src/pre_process/m_mpi_proxy.fpp


5. src/pre_process/m_perturbation.fpp 🐞 Bug fix +2/-2

Fix velocity perturbation calculation order

• Reordered velocity perturbation assignments so y-velocity uses unmodified x-velocity
• Fixed documentation typo: "inverter" → "inverted" in subroutine comment

src/pre_process/m_perturbation.fpp


6. src/pre_process/m_start_up.fpp 🐞 Bug fix +13/-4

Fix hyper-cleaning 3D initialization and precision

• Added #:include 'macros.fpp' directive for macro support
• Extended hyper-cleaning psi initialization from 2D (k=0 plane only) to full 3D with proper loop
 nesting
• Added 2D guards using if (n > 0) and if (p > 0) to prevent invalid array access
• Replaced hard-coded double precision literals (1d-2, 2.0, 0.05) with proper
 working-precision literals (1.0e-2_wp, 2.0_wp, 0.05_wp)
• Introduced r2 variable for cleaner radial distance calculation
• Added assertion to verify psi_idx is set when hyper-cleaning is enabled

src/pre_process/m_start_up.fpp


Grey Divider

Qodo Logo

@qodo-code-review
Copy link
Contributor

qodo-code-review bot commented Mar 2, 2026

Code Review by Qodo

🐞 Bugs (0) 📘 Rule violations (0) 📎 Requirement gaps (0)

Grey Divider

Great, no issues found!

Qodo reviewed your code and found no material issues that require review

Grey Divider

ⓘ The new review experience is currently in Beta. Learn more

Grey Divider

Qodo Logo

@github-actions
Copy link

github-actions bot commented Mar 2, 2026

Claude Code Review

Head SHA: 1cdd7511586b897b70d8a185583144853a01d8db
Files changed: 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


Summary

  • Batch of 6 isolated pre-process bug fixes; no simulation GPU kernels or MPI hot paths touched.
  • All six fixes are straightforward and well-motivated — each addresses a real silent failure.
  • Precision hygiene in m_start_up.fpp is improved: 1d-21.0e-2_wp, 2.02.0_wp, 0.05**20.05_wp**2 (required by conventions).
  • Loop restructuring for hyper_cleaning correctly generalizes 1D/2D/3D; Fortran column-major order is respected (j innermost for sf(j,k,l)).
  • #:include 'macros.fpp' is correctly added to m_start_up.fpp before using @:ASSERT.

Findings

No blocking issues

All six fixes look correct. Detailed per-fix notes:

  1. m_constants.fpp line 47integer → real(wp) for moncon_cutoff: Clearly correct. 1e-8_wp as integer truncates to 0, silently disabling THINC monotonicity. ✓

  2. m_grid.f90 lines 134, 171y_cc(0:m)y_cc(0:n), z_cc(0:m)z_cc(0:p): Classic copy-paste error causing wrong slice assignment on non-cube grids. ✓

  3. m_assign_variables.fpp line 235 — Duplicate R3bar accumulation removed: Was doubling the QBMM bubble perturbation amplitude. ✓

  4. m_perturbation.fpp lines 86–87 — Statement reorder so mom_idx%end reads original mom_idx%beg before mom_idx%beg is modified: Correct dependency ordering. ✓

  5. m_mpi_proxy.fpp lines 79–82, 119–122 — IB vel/angular_vel/angles broadcasts moved from num_bc_patches_max loop to num_patches_max loop: Correct, since patch_ib is indexed 1:num_patches_max. Replacing hardcoded 3 with size(patch_ib(i)%${VAR}$) is also an improvement. ✓

  6. m_start_up.fpp lines 790–801 — Hyper-cleaning loop extended from (j,k) at fixed l=0 to full (j,k,l): Correct 3D generalization. Guards for n=0 and p=0 are handled properly via if (n > 0)/if (p > 0). ✓


Minor / Non-blocking

  • m_start_up.fpp line 793@:ASSERT(psi_idx > 0, ...) is appropriate here. However, since hyper_cleaning is user-supplied, @:PROHIBIT(psi_idx <= 0, ...) might be marginally more idiomatic per MFC conventions (runtime constraint vs. invariant), though the practical difference is negligible.
  • No new regression tests are added for the specific bugs fixed (e.g., stretched non-cube grid, QBMM IC, 3D hyper-cleaning). This is understandable given the batch nature and the fact that these code paths require specific feature combinations, but adding targeted tests for some of these (especially grid bounds) would improve long-term safety.

Verdict

All fixes are correct, well-scoped, and adhere to MFC conventions. Approved.

@github-actions
Copy link

github-actions bot commented Mar 2, 2026

Claude Code Review

Head SHA: 1cdd7511586b897b70d8a185583144853a01d8db

Files changed: 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

Summary

  • All 6 fixes target real bugs in pre-process code paths; none touch simulation GPU kernels or MPI hot paths.
  • Changes are self-contained with minimal blast radius.
  • Numeric literal discipline improved (replacing 1d-2 / 2.0 with 1.0e-2_wp / 2.0_wp per Fortran conventions).
  • The #:include 'macros.fpp' addition is necessary for the new @:ASSERT usage and appears correct.
  • No new GPU macros, no new parameters, no src/common/ changes that affect all three targets (only m_constants.fpp changes, which was a type fix).

Findings

1. moncon_cutoff type fix — correct and critical

File: src/common/m_constants.fpp, line 47

The original integer, parameter :: moncon_cutoff = 1e-8_wp silently truncated the value to 0 at compile time, completely disabling the THINC monotonicity limiter. The fix to real(wp) is correct.

Behavioral note: Any existing case that relied on moncon_cutoff = 0 (e.g., by expecting the limiter to always fire) will now behave differently. This is intentional and correct, but affected golden test files should be regenerated if CI shows output changes.

2. Grid bounds fix — correct, was potentially out-of-bounds

File: src/pre_process/m_grid.f90, lines 134, 171

y_cc(0:m) and z_cc(0:m) used the x-dimension bound m instead of n/p. When m > n (or m > p), this wrote beyond the allocated extent of y_cc/z_cc, which is undefined behaviour. When m < n (or m < p), only a prefix of the array was initialised, leaving tail cells with stale/uninitialized values. Fix is correct.

3. MPI broadcast loop fix — correct

File: src/pre_process/m_mpi_proxy.fpp, lines 79–82, 119–122

Moving IB broadcasts from the patch_bc loop (bounded by num_bc_patches_max) to the patch_icpp loop (bounded by num_patches_max) is correct since patch_ib is indexed 1:num_patches_max. Using size(patch_ib(i)%${VAR}$) instead of the hard-coded 3 is more robust. Confirm that vel, angular_vel, and angles are statically-sized arrays (not allocatable) in the patch_ib type — if they are allocatable, size() could fault on ranks that did not allocate them. Based on typical MFC type definitions this is fine, but worth a quick check.

4. Perturbation velocity ordering fix — correct

File: src/pre_process/m_perturbation.fpp, lines 86–87

Swapping the two lines so mom_idx%end (y-velocity) is set from the unmodified mom_idx%beg before mom_idx%beg (x-velocity) is perturbed is the correct fix. The previous ordering made the y-perturbation magnitude depend on the already-scaled x-velocity, producing a wrong (larger) y-perturbation.

5. Duplicate R3bar accumulation removed — correct

File: src/pre_process/m_assign_variables.fpp, line 235

The removed line was an exact duplicate, doubling the QBMM bubble perturbation amplitude. Removal is correct.

6. hyper_cleaning 3D loop fix — correct, with one note

File: src/pre_process/m_start_up.fpp, lines 790–803

The original code only initialized psi for the l=0 plane in 3D (z-sweep was missing). The new triply-nested loop with if (n > 0) / if (p > 0) guards correctly handles 1D/2D/3D cases. The @:ASSERT(psi_idx > 0, ...) adds useful compile-time-checked runtime validation. Replacing 1d-2 with 1.0e-2_wp and 2.0 with 2.0_wp fixes Fortran literal convention violations.

Note: The radial Gaussian is now computed in 3D as exp(-r²/(2σ²)) where σ=0.05, centred at the origin. For 2D cases (p=0), the l loop runs once (l=0) and z_cc(0) is not included — identical to the original behaviour.


No blocking issues. All 6 fixes appear correct. Approve once CI passes.

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Mar 2, 2026

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: 53ae98d3-344f-4441-8f71-7bf14755ac57

📥 Commits

Reviewing files that changed from the base of the PR and between 506c6f5 and f6ab8ce.

📒 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

📝 Walkthrough

Walkthrough

This pull request contains multiple corrections and enhancements across preprocessing modules. Changes include: converting a constant type from integer to real, correcting array indexing in grid cell-center coordinate calculations, expanding initial condition setup from two dimensions to three dimensions with corresponding loop restructuring, removing a duplicate accumulation line in a calculation routine, adjusting MPI broadcast sizes from fixed to dynamically determined values, and correcting documentation in parameter descriptions and comments.

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed Title clearly identifies the primary change: six low-risk pre-process bug fixes batched together, accurately reflecting the core focus of the changeset.
Description check ✅ Passed Description includes a comprehensive summary of changes, lists all six fixes with issue numbers, specifies the test plan, and follows the required template structure.
Linked Issues check ✅ Passed All six linked issues have corresponding fixes in the changeset: moncon_cutoff type change (#1174), grid bounds corrections (#1179), duplicate R3bar removal (#1183), velocity perturbation order swap (#1216), psi 3D initialization (#1217), and IB broadcast loop fix (#1188).
Out of Scope Changes check ✅ Passed All changes are directly tied to the six linked issues and fall within pre-process initialization and MPI setup; no simulation hot-path or unrelated modifications detected.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.

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


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.

@sbryngelson sbryngelson marked this pull request as draft March 3, 2026 02:44
@github-actions
Copy link

Claude Code Review

Head SHA: f6ab8ce
Files changed: 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


Summary

  • All 6 fixes are in pre-process and common constants — no simulation GPU kernels or MPI hot-paths are touched.
  • Each fix addresses a distinct, well-described upstream issue.
  • Precision discipline is improved (two d-exponent literals and one bare 0.05**2 replaced with _wp-suffixed forms).
  • The macros.fpp include added to m_start_up.fpp is correct and needed for the new @:ASSERT usage.
  • No new bugs introduced; overall a low-risk correctness-only batch.

Findings

1. m_constants.fppmoncon_cutoff type fix (line 47)
Correct fix. integer, parameter :: moncon_cutoff = 1e-8_wp silently truncated to 0, disabling the THINC monotonicity limiter entirely. real(wp) is the right type.

2. m_grid.f90 — y/z cell-center bounds (lines 134, 171)
Correct. y_cc(0:m) and z_cc(0:m) used the x-dimension count instead of 0:n / 0:p. This was a silent out-of-bounds write on any grid where n ≠ m or p ≠ m (stretched grids in particular).

3. m_assign_variables.fpp — duplicate R3bar accumulation (line 236)
Correct removal. The duplicate line doubled the intended perturbation magnitude in QBMM IC.

4. m_perturbation.fpp — velocity perturbation ordering (lines 86–87)
Correct swap. q_prim_vf(mom_idx%end) (y-velocity perturbation) must be computed from the original x-velocity; computing it after the x-velocity is modified produced a wrong y-perturbation scale.

5. m_mpi_proxy.fpp — IB variable broadcast loop placement (lines 79–82, 119–123)
Correct move. The broadcast was inside the patch_bc loop (indexed 1:num_bc_patches_max), but patch_ib is indexed 1:num_patches_max. Moving to the patch_icpp loop fixes the index mismatch. Replacing the hardcoded 3 with size(patch_ib(i)%${VAR}$) is more robust and guards against future field-size changes.

6. m_start_up.fpp — hyper_cleaning psi initialization (lines 790–803)
Correct extension. The original only iterated the k=0 plane (do k=0,n; ... sf(j,k,0)); the fix adds an outer l loop and a new j inner loop to cover all (j,k,l) cells. The if (n > 0) / if (p > 0) guards correctly handle 1D/2D degeneracies. The @:ASSERT(psi_idx > 0, ...) is a good defensive guard consistent with the project's error-checking convention.


Minor observations (non-blocking)

  • The #:include 'macros.fpp' is placed at file scope (line 4) before the module; this is consistent with other pre-process files that use @:ASSERT / @:PROHIBIT.
  • Docstring typo fixes (areassignedare assigned, inverterinverted) are welcome cleanups.

@sbryngelson sbryngelson marked this pull request as ready for review March 11, 2026 19:14
@qodo-code-review
Copy link
Contributor

ⓘ You are approaching your monthly quota for Qodo. Upgrade your plan

Review Summary by Qodo

Fix six low-risk pre-process bugs in IC generation and MPI setup

🐞 Bug fix

Grey Divider

Walkthroughs

Description
• Fixes moncon_cutoff type from integer to real, restoring THINC monotonicity limiting
• Corrects stretched-grid cell-center bounds for y and z dimensions using proper array sizes
• Removes duplicate R3bar accumulation line that doubled QBMM bubble perturbation magnitude
• Fixes y-velocity perturbation computation order to use unmodified x-velocity
• Extends hyper-cleaning psi initialization across all 3D planes with proper 2D guards
• Moves immersed-boundary variable broadcasts to correct loop scope and fixes numeric literals
Diagram
flowchart LR
  A["Pre-process Code"] --> B["Bug Fixes"]
  B --> C["THINC Limiting"]
  B --> D["Grid Stretching"]
  B --> E["QBMM Perturbation"]
  B --> F["Velocity Order"]
  B --> G["Hyper-cleaning Init"]
  B --> H["IB Broadcasts"]
  C --> I["Correct IC"]
  D --> I
  E --> I
  F --> I
  G --> I
  H --> J["Correct MPI Setup"]
Loading

Grey Divider

File Changes

1. src/common/m_constants.fpp 🐞 Bug fix +1/-1

Fix moncon_cutoff type truncation bug

• Changed moncon_cutoff declaration from integer to real(wp) to preserve the 1e-8_wp value
• Prevents silent truncation to 0 that was disabling THINC monotonicity constraint

src/common/m_constants.fpp


2. src/pre_process/m_assign_variables.fpp 🐞 Bug fix +3/-4

Remove duplicate R3bar and fix documentation

• Fixed documentation typos in abstract interface comments (spacing in "are assigned")
• Removed duplicate R3bar accumulation line in QBMM bubble perturbation calculation

src/pre_process/m_assign_variables.fpp


3. src/pre_process/m_grid.f90 🐞 Bug fix +2/-2

Fix grid stretching array bounds for y and z

• Fixed y_cc(0:m) to y_cc(0:n) to use correct y-dimension bound instead of x-dimension
• Fixed z_cc(0:m) to z_cc(0:p) to use correct z-dimension bound instead of x-dimension
• Ensures stretched-grid cell-center coordinates are computed with proper array sizes

src/pre_process/m_grid.f90


View more (3)
4. src/pre_process/m_mpi_proxy.fpp 🐞 Bug fix +5/-5

Fix IB variable broadcast loop scope and sizing

• Moved immersed-boundary variable broadcasts (vel, angular_vel, angles) from
 num_bc_patches_max loop to num_patches_max loop
• Added clarifying comment explaining the indexing difference between patch_ib and patch_bc
• Changed broadcast size from hardcoded 3 to size(patch_ib(i)%${VAR}$) for robustness

src/pre_process/m_mpi_proxy.fpp


5. src/pre_process/m_perturbation.fpp 🐞 Bug fix +2/-2

Fix velocity perturbation computation order

• Reordered velocity perturbation assignments so y-velocity uses unmodified x-velocity value
• Fixed documentation typo: "inverter" to "inverted" in subroutine description

src/pre_process/m_perturbation.fpp


6. src/pre_process/m_start_up.fpp 🐞 Bug fix +13/-4

Fix hyper-cleaning psi 3D initialization and literals

• Added #:include 'macros.fpp' directive for assertion macro support
• Extended hyper-cleaning psi initialization from single k=0 plane to full 3D domain with proper
 loop ordering
• Added 2D guards to prevent accessing z_cc when p=0
• Replaced hard-coded double precision literals (1d-2, 2.0, 0.05) with proper
 working-precision literals (1.0e-2_wp, 2.0_wp, 0.05_wp)
• Added assertion to verify psi_idx is set before use
• Introduced r2 variable for cleaner radial distance computation

src/pre_process/m_start_up.fpp


Grey Divider

Qodo Logo

@qodo-code-review
Copy link
Contributor

qodo-code-review bot commented Mar 11, 2026

Code Review by Qodo

🐞 Bugs (0) 📘 Rule violations (1) 📎 Requirement gaps (0)

Grey Divider


Action required

1. Missing tests for common change 📘 Rule violation ⛯ Reliability
Description
This PR modifies shared code under src/common/ but provides no evidence that pre_process,
simulation, and post_process were all tested. This increases regression risk across multiple
executables that depend on the common constants module.
Code

src/common/m_constants.fpp[47]

+    real(wp), parameter :: moncon_cutoff = 1e-8_wp !< Monotonicity constraint's limiter to prevent extremas in THINC
Evidence
Compliance requires comprehensive testing across all three executables when src/common/ is
changed. The diff shows a change in src/common/m_constants.fpp, and the PR test plan lists CI
checks as unchecked with no recorded results.

CLAUDE.md
src/common/m_constants.fpp[47-47]

Agent prompt
The issue below was found during a code review. Follow the provided context and guidance below and implement a solution

## Issue description
This PR changes `src/common/` but does not provide evidence that all three executables (pre_process, simulation, post_process) were tested, which is required for shared-code modifications.

## Issue Context
The change touches shared constants used across targets, so regressions can impact multiple executables.

## Fix Focus Areas
- src/common/m_constants.fpp[47-47]

ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools


Grey Divider

ⓘ The new review experience is currently in Beta. Learn more

Grey Divider

Qodo Logo

@github-actions
Copy link

Claude Code Review

Head SHA: f6ab8ce

Files changed: 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

Summary

  • All six fixes are clearly correct and address real bugs in pre-process code paths.
  • Changes are well-scoped to pre-process and common constants; no GPU kernel or MPI hot-path modifications.
  • Forbidden literal forms (1d-2, bare 2.0, 0.05 without _wp) in the old hyper-cleaning code are corrected as part of the m_start_up fix.
  • Loop ordering in the refactored hyper-cleaning block (l outermost, j innermost) matches MFC convention and is cache-friendly.

Findings

src/common/m_constants.fppmoncon_cutoff type fix

  • Correct. The integer, parameter declaration silently truncated 1e-8_wp to 0, effectively disabling the THINC monotonicity limiter. The fix to real(wp) restores the intended behaviour.

src/pre_process/m_grid.f90 — grid bounds fix

  • Correct. y_cc(0:m) and z_cc(0:m) used the x-dimension bound on the LHS when the RHS operands correctly use 0:n / 0:p. On non-square grids this would write out-of-bounds or leave cells uninitialised.

src/pre_process/m_mpi_proxy.fpp — IB broadcast loop fix

  • Correct. The old broadcasts were inside the num_bc_patches_max loop body, but patch_ib is indexed 1:num_patches_max; moving them to the num_patches_max loop fixes the index mismatch.
  • Replacing the hardcoded 3 with size(patch_ib(i)%${VAR}$) is a good defensive improvement.

src/pre_process/m_perturbation.fpp — velocity perturbation order

  • Correct. The line swap ensures the y-velocity perturbation is computed from the original x-velocity, not the already-modified value.

src/pre_process/m_assign_variables.fpp — duplicate R3bar accumulation

  • Correct. The duplicated line doubled the bubble perturbation amplitude.

src/pre_process/m_start_up.fpp — hyper-cleaning 3D init

  • Correct. The #:include 'macros.fpp' addition is necessary for the new @:ASSERT call and is appropriately placed.
  • The @:ASSERT(psi_idx > 0, ...) guard is a good addition for early failure with a clear message.
  • One minor observation: the if (n > 0) / if (p > 0) guards inside the innermost loop are evaluated on every cell iteration. These conditions are loop-invariant and a compiler should hoist them, but a cleaner pattern would be to compute r2 as a single expression:
    r2 = x_cc(j)**2 + merge(y_cc(k)**2, 0.0_wp, n > 0) + merge(z_cc(l)**2, 0.0_wp, p > 0)
    This is a style suggestion only, not a correctness concern.

Overall

The batch is ready to merge. All fixes are straightforward, well-motivated, and consistent with MFC conventions. No issues with precision discipline, GPU macros, or compiler portability.

real(wp), parameter :: dflt_ic_eps = 1e-4_wp !< Ensure compression is only applied to surface cells in THINC
real(wp), parameter :: dflt_ic_beta = 1.6_wp !< Sharpness parameter's default value used in THINC
integer, parameter :: moncon_cutoff = 1e-8_wp !< Monotonicity constraint's limiter to prevent extremas in THINC
real(wp), parameter :: moncon_cutoff = 1e-8_wp !< Monotonicity constraint's limiter to prevent extremas in THINC
Copy link
Contributor

Choose a reason for hiding this comment

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

Action required

1. Missing tests for common change 📘 Rule violation ⛯ Reliability

This PR modifies shared code under src/common/ but provides no evidence that pre_process,
simulation, and post_process were all tested. This increases regression risk across multiple
executables that depend on the common constants module.
Agent Prompt
## Issue description
This PR changes `src/common/` but does not provide evidence that all three executables (pre_process, simulation, post_process) were tested, which is required for shared-code modifications.

## Issue Context
The change touches shared constants used across targets, so regressions can impact multiple executables.

## Fix Focus Areas
- src/common/m_constants.fpp[47-47]

ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools

@sbryngelson sbryngelson marked this pull request as draft March 11, 2026 20:50
@sbryngelson sbryngelson marked this pull request as ready for review March 12, 2026 03:06
@qodo-code-review
Copy link
Contributor

ⓘ You are approaching your monthly quota for Qodo. Upgrade your plan

Review Summary by Qodo

Fix six low-risk pre-process bugs affecting initial conditions

🐞 Bug fix

Grey Divider

Walkthroughs

Description
• Fixes moncon_cutoff type from integer to real, restoring THINC monotonicity limiting
• Corrects stretched-grid cell-center calculations for y and z dimensions using wrong bounds
• Removes duplicate R3bar accumulation line that doubled QBMM bubble perturbation magnitude
• Fixes y-velocity perturbation reading already-modified x-velocity instead of original
• Extends hyper-cleaning psi initialization to all 3D planes with proper 2D guards
• Moves immersed-boundary variable broadcasts to correct loop scope for proper MPI propagation
Diagram
flowchart LR
  A["Pre-process Code"] --> B["Bug Fixes"]
  B --> C["moncon_cutoff Type"]
  B --> D["Grid Stretching Bounds"]
  B --> E["QBMM Perturbation"]
  B --> F["Velocity Perturbation Order"]
  B --> G["Hyper-cleaning 3D Init"]
  B --> H["IB MPI Broadcasts"]
  C --> I["Correct THINC Limiting"]
  D --> J["Accurate Coordinates"]
  E --> K["Correct Amplitudes"]
  F --> L["Proper Velocity Values"]
  G --> M["Full 3D Coverage"]
  H --> N["Reliable MPI Propagation"]
Loading

Grey Divider

File Changes

1. src/common/m_constants.fpp 🐞 Bug fix +1/-1

Fix moncon_cutoff type truncation bug

• Changed moncon_cutoff declaration from integer to real(wp) to preserve the 1e-8_wp value
• Prevents silent truncation to 0 that was disabling THINC monotonicity constraint

src/common/m_constants.fpp


2. src/pre_process/m_assign_variables.fpp 🐞 Bug fix +3/-4

Remove duplicate R3bar and fix documentation

• Fixed typo in documentation: "areassigned" → "are assigned" (3 occurrences)
• Removed duplicate R3bar accumulation line in QBMM bubble perturbation calculation

src/pre_process/m_assign_variables.fpp


3. src/pre_process/m_grid.f90 🐞 Bug fix +2/-2

Correct stretched-grid dimension bounds

• Fixed y_cc(0:m) to y_cc(0:n) using correct y-dimension bound
• Fixed z_cc(0:m) to z_cc(0:p) using correct z-dimension bound
• Prevents corrupted cell-center coordinates when grid stretching is enabled with non-uniform
 dimensions

src/pre_process/m_grid.f90


View more (3)
4. src/pre_process/m_mpi_proxy.fpp 🐞 Bug fix +5/-5

Fix IB broadcast loop scope and sizing

• Moved immersed-boundary variable broadcasts (vel, angular_vel, angles) from
 num_bc_patches_max loop to num_patches_max loop
• Added clarifying comment explaining the indexing difference between patch_ib and patch_bc
• Changed broadcast size from hardcoded 3 to size(patch_ib(i)%${VAR}$) for robustness

src/pre_process/m_mpi_proxy.fpp


5. src/pre_process/m_perturbation.fpp 🐞 Bug fix +2/-2

Fix velocity perturbation calculation order

• Reordered velocity perturbation assignments so y-velocity uses original x-velocity value
• Fixed documentation typo: "inverter" → "inverted" in mixlayer perturbation subroutine

src/pre_process/m_perturbation.fpp


6. src/pre_process/m_start_up.fpp 🐞 Bug fix +13/-4

Fix hyper-cleaning 3D initialization and precision

• Added missing #:include 'macros.fpp' directive for macro support
• Extended hyper-cleaning psi initialization from single k=0 plane to full 3D domain with proper
 loop nesting
• Added 2D guards checking n > 0 and p > 0 before accessing y_cc and z_cc arrays
• Replaced hard-coded precision literals (1d-2, bare 2.0, 0.05) with proper working-precision
 versions (1.0e-2_wp, 2.0_wp, 0.05_wp)
• Added assertion to verify psi_idx is set when hyper_cleaning is enabled
• Introduced r2 variable for cleaner radial distance calculation

src/pre_process/m_start_up.fpp


Grey Divider

Qodo Logo

@qodo-code-review
Copy link
Contributor

qodo-code-review bot commented Mar 12, 2026

Code Review by Qodo

🐞 Bugs (0) 📘 Rule violations (1) 📎 Requirement gaps (0)

Grey Divider


Action required

1. Missing tests for common change 📘 Rule violation ⛯ Reliability
Description
This PR modifies shared code under src/common/ but provides no evidence that pre_process,
simulation, and post_process were all tested. This increases regression risk across multiple
executables that depend on the common constants module.
Code

src/common/m_constants.fpp[47]

+    real(wp), parameter :: moncon_cutoff = 1e-8_wp !< Monotonicity constraint's limiter to prevent extremas in THINC
Evidence
Compliance requires comprehensive testing across all three executables when src/common/ is
changed. The diff shows a change in src/common/m_constants.fpp, and the PR test plan lists CI
checks as unchecked with no recorded results.

CLAUDE.md
src/common/m_constants.fpp[47-47]

Agent prompt
The issue below was found during a code review. Follow the provided context and guidance below and implement a solution

## Issue description
This PR changes `src/common/` but does not provide evidence that all three executables (pre_process, simulation, post_process) were tested, which is required for shared-code modifications.
## Issue Context
The change touches shared constants used across targets, so regressions can impact multiple executables.
## Fix Focus Areas
- src/common/m_constants.fpp[47-47]

ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools


Grey Divider

ⓘ The new review experience is currently in Beta. Learn more

Grey Divider

Qodo Logo

@github-actions
Copy link

Claude Code Review

Head SHA: f6ab8ce
Files changed: 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


Summary

  • All 6 bug fixes are genuine, independent corrections to pre-process code paths; no simulation hot-path or GPU kernel changes.
  • Precision hygiene is improved: 1d-2 / bare 0.05 literals replaced with 1.0e-2_wp / 0.05_wp (CLAUDE.md-compliant).
  • The new @:ASSERT(psi_idx > 0) guard and the #:include 'macros.fpp' addition in m_start_up.fpp are the only structural changes; both are safe.

Findings

No blocking issues found. A few minor observations:

  1. m_grid.f90 lines 134 / 171 — correct but worth noting Changing y_cc(0:m)y_cc(0:n) and z_cc(0:m)z_cc(0:p) is clearly right; the old code was silently writing out-of-declared-bounds (or partially overwriting) when m ≠ n / m ≠ p. No concern, just noting that this could have corrupted adjacent memory in asymmetric grids.

  2. m_mpi_proxy.fpp line 119 — size(patch_ib(i)%${VAR}$) instead of hardcoded 3 This is a strictly safer change. If vel, angular_vel, or angles are ever resized, the broadcast count stays correct automatically. No issue.

  3. m_start_up.fpp hyper-cleaning init — loop order The new loop order l → k → j (j innermost) matches Fortran column-major access for sf(j,k,l). This is correct and slightly more cache-friendly than the old 2-loop layout.

  4. m_start_up.fppr2 accumulation in 1-D In 1-D (n=0, p=0), r2 = x_cc(j)**2 with no additions is correct. The conditional guards (if (n > 0), if (p > 0)) work, but note that in a 1-D case the Gaussian is a function of x only — this may or may not be the intended physical behaviour, but it matches the spirit of the original code (which only initialised the k=0, l=0 plane), so no change is needed here.


Verdict

All fixes are correct, focused, and match MFC coding conventions. Approved from a code-review standpoint — the batch is ready to merge pending CI green.

@sbryngelson sbryngelson merged commit 9d27a2d into MFlowCode:master Mar 12, 2026
96 of 148 checks passed
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

5 participants