Skip to content

Comments

Fix f_check_interpolation_2D/3D returning only last edge's result#1215

Open
sbryngelson wants to merge 1 commit intoMFlowCode:masterfrom
sbryngelson:fix/interpolation-check-overwrite
Open

Fix f_check_interpolation_2D/3D returning only last edge's result#1215
sbryngelson wants to merge 1 commit intoMFlowCode:masterfrom
sbryngelson:fix/interpolation-check-overwrite

Conversation

@sbryngelson
Copy link
Member

@sbryngelson sbryngelson commented Feb 21, 2026

User description

Summary

  • Fix f_check_interpolation_2D and f_check_interpolation_3D in m_model.fpp which only returned the interpolation decision from the last edge/triangle in the loop, silently discarding earlier true results.

Bug Details

Both subroutines loop over edges (2D) or triangles (3D), checking if any edge length exceeds the cell width. However, the interpolate flag was unconditionally overwritten on every iteration:

if (l1 > cell_width) then
    interpolate = .true.
else
    interpolate = .false.   ! ← clobbers previous .true.
end if

If edge 5 of 10 needs interpolation but the last edge doesn't, the function returns .false., causing the caller to skip interpolation when it's needed. This can produce incorrect levelset fields for OBJ models where mesh resolution varies across the surface.

Fix

Return early on the first edge that exceeds the cell width. Since interpolate is initialized to .false. before the loop, only the true case needs handling.

Test plan

  • Existing OBJ model tests pass
  • 3D immersed boundary cases with non-uniform triangle meshes produce correct levelsets

🤖 Generated with Claude Code


CodeAnt-AI Description

Fix interpolation checks to correctly detect when any boundary edge/triangle needs interpolation

What Changed

  • The 2D and 3D interpolation-check routines now stop and report "interpolate needed" as soon as any edge or triangle side is longer than the cell width, instead of using the last edge's result.
  • Calls that previously could skip interpolation when an earlier edge required it will now trigger interpolation as intended.
  • Observable behavior: OBJ and other imported meshes with non-uniform edge lengths produce correct levelset interpolation decisions.

Impact

✅ Fewer skipped interpolations for OBJ and imported meshes
✅ Correct levelset shapes for non-uniform meshes
✅ Fewer rendering/artifact errors at mesh boundaries

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

Fixes #1219

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Copilot AI review requested due to automatic review settings February 21, 2026 05:02
@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 19 minutes and 22 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
cubic-dev-ai[bot]

This comment was marked as off-topic.

@codeant-ai
Copy link
Contributor

codeant-ai bot commented Feb 21, 2026

Nitpicks 🔍

🔒 No security issues identified
⚡ Recommended areas for review

  • Early-return semantics
    The fix returns immediately when any long edge/triangle is found. Ensure callers expect that behavior and that no additional per-subroutine cleanup or side-effects (e.g., logging or resource handling) are needed after detection. Also confirm that empty inputs (zero edges/triangles) are handled as intended.

  • Intent / API contract
    The parameter interpolate is declared intent(inout) but is always assigned by the subroutines (initialized to .false. and possibly set to .true.). This is effectively an output-only value; using intent(out) would better express intent and avoid reliance on caller-provided state. Verify all callers do not depend on prior value.

  • Performance Issue
    The new checks compute Euclidean lengths with sqrt() inside tight loops (both 2D and 3D). Replacing sqrt with squared-length comparisons (compare to squared cell_width) will avoid the expensive sqrt call and be numerically equivalent for the > test.

@codeant-ai
Copy link
Contributor

codeant-ai bot commented Feb 21, 2026

CodeAnt AI finished reviewing your PR.

@sbryngelson sbryngelson added the bug Something isn't working or doesn't seem right label Feb 21, 2026
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

Fixes incorrect interpolation decisions in f_check_interpolation_2D and f_check_interpolation_3D by preventing later loop iterations from overwriting a previously-detected .true. condition.

Changes:

  • Return early from the 2D edge loop once any edge exceeds cell_width.
  • Return early from the 3D triangle loop once any edge exceeds cell_width.

@danieljvickers
Copy link
Member

In my last PR, I delete this subroutine entirely. You should probably just close this PR and wait for my update to come int to save the time on the compute resources.

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

Labels

bug Something isn't working or doesn't seem right size:XS This PR changes 0-9 lines, ignoring generated files

Development

Successfully merging this pull request may close these issues.

f_check_interpolation_2D/3D returns only last edge's result

2 participants