Skip to content

Comments

Fix s_write_intf_data_file using wrong loop index for distance check#1191

Open
sbryngelson wants to merge 1 commit intoMFlowCode:masterfrom
sbryngelson:fix/intf-data-loop-index
Open

Fix s_write_intf_data_file using wrong loop index for distance check#1191
sbryngelson wants to merge 1 commit intoMFlowCode:masterfrom
sbryngelson:fix/intf-data-loop-index

Conversation

@sbryngelson
Copy link
Member

@sbryngelson sbryngelson commented Feb 21, 2026

Summary

Severity: HIGH — interface contour extraction uses stale loop index, produces wrong point distances.

File: src/post_process/m_data_output.fpp, lines 1549-1563

In s_write_intf_data_file, the Euclidean distance euc_d between a candidate interface point and existing stored points is computed using x_d1(i) and y_d1(i), where i is stale from a previous outer loop (value = m+1 after the maxalpha search loop). This references out-of-bounds or wrong data. Additionally, euc_d is computed once outside the inner loop, so the distance check is the same for all stored points.

Before

! euc_d uses stale 'i' from the previous loop, not the stored-point index
euc_d = sqrt((x_cc(j) - x_d1(i))**2 + (y_cc(k) - y_d1(i))**2)
tgp = sqrt(dx(j)**2 + dy(k)**2)
do i = 1, counter        ! i is now a different loop variable
    if (euc_d < tgp) then
        cycle             ! wrong: should exit, not cycle
    elseif (euc_d > tgp .and. i == counter) then
        ! add point

After

tgp = sqrt(dx(j)**2 + dy(k)**2)
do i = 1, counter
    euc_d = sqrt((x_cc(j) - x_d1(i))**2 + (y_cc(k) - y_d1(i))**2)
    if (euc_d < tgp) then
        exit              ! too close to existing point, reject candidate
    elseif (i == counter) then
        ! add point — passed all distance checks

Three fixes:

  1. Moved euc_d computation inside the loop so it checks distance to each stored point
  2. Changed cycle to exit for correct early termination (reject if too close to any point)
  3. Removed dead code in the counter == 0 branch (distance to self)

Test plan

  • Run post-processing with interface data output
  • Verify extracted contour points are properly spaced

🤖 Generated with Claude Code

Fixes #1211

Copilot AI review requested due to automatic review settings February 21, 2026 03:23
@codeant-ai
Copy link
Contributor

codeant-ai bot commented Feb 21, 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 21, 2026

Warning

Rate limit exceeded

@sbryngelson has exceeded the limit for the number of commits that can be reviewed per hour. Please wait 28 minutes and 27 seconds before requesting another review.

⌛ How to resolve this issue?

After the wait time has elapsed, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

🚦 How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout.

Please see our FAQ for further information.

✨ Finishing Touches
🧪 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:XS This PR changes 0-9 lines, ignoring generated files label Feb 21, 2026
@codeant-ai
Copy link
Contributor

codeant-ai bot commented Feb 21, 2026

Nitpicks 🔍

🔒 No security issues identified
⚡ Recommended areas for review

  • Logic change
    The inner-loop termination was changed from cycle to exit. Verify this breaks only the inner do i loop (so the candidate point is rejected) and does not skip needed iterations of the outer loops. Confirm intended behaviour when multiple stored points are checked — ensure candidates are only added when they pass all checks.

  • Distance calculation
    The Euclidean distance euc_d is now computed inside the loop using the stored-point index i, which fixes the stale-index bug. Ensure the indices used (x_cc(j) - x_d1(i) and y_cc(k) - y_d1(i)) match the grid indexing convention in the rest of the module.

  • Performance Issue
    The code computes sqrt for every stored-point comparison. For many stored points this may be expensive; consider comparing squared distances instead to avoid repeated square-root operations.

@codeant-ai
Copy link
Contributor

codeant-ai bot commented Feb 21, 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 fixes a critical bug in the interface data output logic where distance calculations were using stale loop indices, potentially causing incorrect spacing validation of interface contour points.

Changes:

  • Moved Euclidean distance computation inside the loop over stored points to use the correct index
  • Replaced cycle with exit to properly terminate when a candidate point is too close to existing points
  • Removed redundant distance calculations and simplified the conditional logic

cubic-dev-ai[bot]

This comment was marked as off-topic.

euc_d was computed outside the inner loop using the outer variable i
(stale from a previous loop) instead of the current stored-point
index. Moved distance computation inside the do-loop over stored
points and changed cycle to exit for correct early termination when
a candidate point is too close to any existing point.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@codecov
Copy link

codecov bot commented Feb 21, 2026

Codecov Report

❌ Patch coverage is 0% with 3 lines in your changes missing coverage. Please review.
✅ Project coverage is 44.05%. Comparing base (84c46e0) to head (2c3fcc9).

Files with missing lines Patch % Lines
src/post_process/m_data_output.fpp 0.00% 3 Missing ⚠️
Additional details and impacted files
@@           Coverage Diff           @@
##           master    #1191   +/-   ##
=======================================
  Coverage   44.05%   44.05%           
=======================================
  Files          70       70           
  Lines       20498    20496    -2     
  Branches     1990     1990           
=======================================
  Hits         9030     9030           
+ Misses      10329    10327    -2     
  Partials     1139     1139           

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

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

Labels

size:XS This PR changes 0-9 lines, ignoring generated files

Development

Successfully merging this pull request may close these issues.

Add Fortran/Fypp static analysis linter to catch copy-paste bugs

1 participant