Skip to content

Fix IB Periodicity Movement#1405

Closed
danieljvickers wants to merge 1 commit intoMFlowCode:masterfrom
danieljvickers:fix-periodic-ib-movement
Closed

Fix IB Periodicity Movement#1405
danieljvickers wants to merge 1 commit intoMFlowCode:masterfrom
danieljvickers:fix-periodic-ib-movement

Conversation

@danieljvickers
Copy link
Copy Markdown
Member

Ib patch periodicity was never decoded before state correction. This causes errors specifically when the IB is moving across the boundary periodically. One processor reads normal values. The other reads uninstantiated garbage, and this causes conflict.

This one-line change resolves the issue.

@qodo-code-review
Copy link
Copy Markdown
Contributor

ⓘ You've reached your Qodo monthly free-tier limit. Reviews pause until next month — upgrade your plan to continue now, or link your paid account if you already have one.

@github-actions
Copy link
Copy Markdown

github-actions Bot commented May 6, 2026

Claude Code Review

Head SHA: 05fbe8f

Files changed:

  • 1
  • src/simulation/m_ibm.fpp

Findings

Double-decode of patch_id — logic error

File: src/simulation/m_ibm.fpp, inside s_ibm_correct_state

Changed hunk:

patch_id = ghost_points(i)%ib_patch_id
call s_decode_patch_periodicity(patch_id, patch_id)   ! new line

ghost_points(i)%ib_patch_id is already a decoded patch ID, not an encoded one. This is established in s_find_ghost_points (context, ~line 574–576):

encoded_patch_id = ib_markers%sf(i, j, k)
call s_decode_patch_periodicity(encoded_patch_id, patch_id, xp, yp, zp)
ghost_points_in(local_idx)%ib_patch_id = patch_id   ! decoded value stored

Every other call-site of s_decode_patch_periodicity in this file (s_compute_ib_forces, s_find_ghost_points) passes an encoded value from ib_markers%sf as the first argument and writes the decoded result into a separate output variable. This new call passes the already-decoded ib_patch_id as both input and output, which will silently corrupt patch_id whenever the encoding is non-trivial (i.e., whenever periodicity is active).

Additionally, passing the same variable as both the source and destination of a subroutine with intent(in) / intent(out) arguments is an aliasing violation under Fortran semantics, even if it compiles without error.

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented May 6, 2026

📝 Walkthrough

Walkthrough

The file src/simulation/m_ibm.fpp was modified to apply periodicity decoding to patch_id within the GPU ghost-point update loop of the s_ibm_correct_state function. Prior to being used for image-point interpolation, slip handling, and velocity/pressure corrections, the patch_id value is now decoded using the s_decode_patch_periodicity function. This change involves a single line addition to the codebase.

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 inconclusive)

Check name Status Explanation Resolution
Description check ❓ Inconclusive The pull request description explains the problem (IB patch periodicity not decoded before state correction causing processor conflicts) and the solution (one-line change), but lacks the structured template sections like 'Type of change', 'Testing', and the required checklist items. Complete the PR description using the template: specify the type of change, describe testing methodology, and check off the verification checklist items (GPU results match CPU, tested on GPU, etc.).
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title 'Fix IB Periodicity Movement' directly describes the main change: fixing an issue with immersed boundary periodicity movement, which aligns with the changeset's one-line fix to decode patch periodicity before state correction.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

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

Tip

💬 Introducing Slack Agent: The best way for teams to turn conversations into code.

Slack Agent is built on CodeRabbit's deep understanding of your code, so your team can collaborate across the entire SDLC without losing context.

  • Generate code and open pull requests
  • Plan features and break down work
  • Investigate incidents and troubleshoot customer tickets together
  • Automate recurring tasks and respond to alerts with triggers
  • Summarize progress and report instantly

Built for teams:

  • Shared memory across your entire org—no repeating context
  • Per-thread sandboxes to safely plan and execute work
  • Governance built-in—scoped access, auditability, and budget controls

One agent for your entire SDLC. Right inside Slack.

👉 Get started


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.

Copy link
Copy Markdown
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


ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: 998f85bd-e225-450b-8026-a448fdbe8d8c

📥 Commits

Reviewing files that changed from the base of the PR and between d513442 and 05fbe8f.

📒 Files selected for processing (1)
  • src/simulation/m_ibm.fpp

Comment thread src/simulation/m_ibm.fpp
Comment on lines 203 to +204
patch_id = ghost_points(i)%ib_patch_id
call s_decode_patch_periodicity(patch_id, patch_id)
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🔴 Critical | ⚡ Quick win

🧩 Analysis chain

🏁 Script executed:

#!/bin/bash
# Locate the implementation of s_decode_patch_periodicity
ast-grep --pattern 'subroutine s_decode_patch_periodicity($$$)'

# Show the dummy argument declarations inside it
rg -n -A 20 'subroutine s_decode_patch_periodicity' --type=fortran
rg -n -A 20 'subroutine s_decode_patch_periodicity' -g '*.fpp' -g '*.f90'

Repository: MFlowCode/MFC

Length of output: 3208


🏁 Script executed:

#!/bin/bash
# Verify all assignment sites of ib_patch_id to see whether encoded or decoded values are stored
rg -n 'ib_patch_id\s*=' -g '*.fpp' -g '*.f90' -C 2

Repository: MFlowCode/MFC

Length of output: 4173


Aliasing violation and logic error: s_decode_patch_periodicity called with same variable for encoded input and decoded output.

The call s_decode_patch_periodicity(patch_id, patch_id) at line 204 passes the same variable as both the intent(in) argument (encoded patch ID) and the intent(out) argument (decoded patch ID). The subroutine signature confirms this:

subroutine s_decode_patch_periodicity(encoded_patch_id, patch_id, ...)
    integer, intent(in)  :: encoded_patch_id
    integer, intent(out) :: patch_id

This is a non-conforming Fortran argument alias. The Fortran standard prohibits the same actual argument from being associated with both intent(in) and intent(out) dummy arguments in a single call. gfortran's -Waliasing flag specifically warns about this pattern. Under optimization on any of the four required compilers (gfortran, nvfortran, Cray ftn, ifx), the compiler may reorder reads and writes, causing the intent(in) value to be read after the intent(out) write, producing a decoded value derived from garbage instead of the original encoded ID.

Additionally, this introduces a logic error: ghost_points(i)%ib_patch_id is populated with an already-decoded value (line 576: ghost_points_in(local_idx)%ib_patch_id = patch_id where patch_id results from a decode call). Decoding an already-decoded value will produce incorrect results.

Fix: pass the encoded struct field directly as the first argument and write the decoded result to patch_id:

Proposed fix
-               patch_id = ghost_points(i)%ib_patch_id
-               call s_decode_patch_periodicity(patch_id, patch_id)
+               call s_decode_patch_periodicity(ghost_points(i)%ib_patch_id, patch_id)

@danieljvickers danieljvickers deleted the fix-periodic-ib-movement branch May 7, 2026 02:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

1 participant