Skip to content

Comments

IBM force calculation simplification (Dr Bala recommendations)#1234

Open
mrvandenboom wants to merge 4 commits intoMFlowCode:masterfrom
mrvandenboom:bala_force_changes
Open

IBM force calculation simplification (Dr Bala recommendations)#1234
mrvandenboom wants to merge 4 commits intoMFlowCode:masterfrom
mrvandenboom:bala_force_changes

Conversation

@mrvandenboom
Copy link
Contributor

@mrvandenboom mrvandenboom commented Feb 22, 2026

User description

(cherry picked from commit 2a034dc) (cherry picked from commit 1d8b109)

Description

This change takes advantage of the symmetric and asymmetric attributes of the tensors to simplify the calculation of force and torque on immersed boundaries.

Type of change

  • Bug fix
  • New feature
  • [ X] Refactor
  • Documentation
  • Other: describe

Testing

ran ./mfc.sh lint
ran ./mfc.sh format
ran ./mfc.sh test -a on Hipergator (CPU). All tests passed.

Summary by CodeRabbit

  • Refactor
    • Reorganized internal simulation computation logic for more efficient handling of force and torque calculations by consolidating updates and reducing redundant operations.

CodeAnt-AI Description

Compute torque from combined pressure and viscous forces and reduce atomic updates

What Changed

  • Viscous contributions are added as direct divergence rows to the local force instead of forming many intermediate cross-product terms
  • Torque is now computed once from the final local force (via a single cross product with the radial vector) so it reflects combined pressure and viscous contributions correctly
  • Atomic updates to global forces and torques occur only after each point's force and torque are fully assembled, reducing repeated atomic writes

Impact

✅ Correct torque from combined pressure and viscous contributions
✅ Fewer atomic updates during force/torque assembly
✅ Lower per-point computation and contention during force assembly

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

(cherry picked from commit 2a034dc)
(cherry picked from commit 1d8b109)
Copilot AI review requested due to automatic review settings February 22, 2026 04:11
@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

The IBM simulation module undergoes internal refactoring of force and torque computation logic. The changes reorganize how viscous stress derivatives are processed—shifting from atomic updates interleaved with force/torque calculations to incremental computation of x, y, and z divergence components with deferred torque updates that occur via cross-product at the end of Jacobian cell processing.

Changes

Cohort / File(s) Summary
IBM Force/Torque Computation Refactor
src/simulation/m_ibm.fpp
Reorganized viscous stress derivative handling to compute divergence contributions incrementally (x, y, z dimensions separately) and accumulate into force contributions. Moved atomic force updates to occur once per Jacobian cell; deferred torque calculations to final cross-product step after all force divergence accumulation. Net reduction of 20 lines.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Poem

🐰 Viscous stresses flow like morning dew,
Now x, then y, then z are through,
Torques defer with patient grace,
Cross-products bloom in final space,
IBM's dance, refined and true!

🚥 Pre-merge checks | ✅ 3
✅ Passed checks (3 passed)
Check name Status Explanation
Title check ✅ Passed The title accurately reflects the main change: a simplification of IBM force calculations, which aligns with the refactoring of force and torque computation in src/simulation/m_ibm.fpp based on Dr. Bala's recommendations.
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 the required sections: a clear summary, type of change (marked as Refactor), and testing information. However, the GPU testing details section is incomplete.

✏️ 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
@codeant-ai
Copy link
Contributor

codeant-ai bot commented Feb 22, 2026

Nitpicks 🔍

🔒 No security issues identified
⚡ Recommended areas for review

  • Torque correctness
    The PR changes torque assembly: it no longer computes derivatives of the cross-product of the viscous stress (previous approach) and instead computes the cross-product once from the final, combined local force contribution. This is mathematically valid (torque = r x F) but can produce subtle numerical differences compared to the old per-component cross-derivative method. Verify equivalence across test cases (especially near boundaries and with non-uniform viscosity) and check that s_compute_viscous_stress_tensor returns the tensor rows in the ordering assumed here.

  • Atomic update / precision check
    Forces and torques are updated using GPU atomics. Ensure the target GPU atomic implementation supports the required precision (real(wp)) and that the $:GPU_ATOMIC pragmas correctly protect concurrent updates for both forces and torques. Also validate that local accumulators are private in the parallel region on all backends.

@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

Refactors immersed-boundary (IBM) force/torque accumulation in simulation to simplify the force/torque calculation by leveraging tensor symmetry/asymmetry characteristics, per Dr. Bala’s recommendations.

Changes:

  • Simplifies viscous-force contribution assembly by removing per-component cross-product derivatives.
  • Computes torque via a single r × F cross product after all force contributions are accumulated.
  • Reorders/clarifies some inline comments around viscous contribution and atomic updates.

end do
viscous_stress_div = (viscous_cross_2 - viscous_cross_1)/(2._wp*dz)
local_torque_contribution(1:3) = local_torque_contribution(1:3) + viscous_stress_div(3, 1:3)
viscous_stress_div(3, 1:3) = (viscous_stress_div_2(3, 1:3) - viscous_stress_div_1(3, 1:3))/(2._wp*dz) ! get z derivative of the second-row of viscous stress tensor
Copy link

Copilot AI Feb 22, 2026

Choose a reason for hiding this comment

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

Inline comment is incorrect: this statement computes the z-derivative of the third row (index 3) of the viscous stress tensor, not the second row. Please update the comment to avoid confusion for future maintenance.

Suggested change
viscous_stress_div(3, 1:3) = (viscous_stress_div_2(3, 1:3) - viscous_stress_div_1(3, 1:3))/(2._wp*dz) ! get z derivative of the second-row of viscous stress tensor
viscous_stress_div(3, 1:3) = (viscous_stress_div_2(3, 1:3) - viscous_stress_div_1(3, 1:3))/(2._wp*dz) ! get z derivative of the third-row of viscous stress tensor

Copilot uses AI. Check for mistakes.

call s_cross_product(radial_vector, local_force_contribution, local_torque_contribution)

! Update the force values atomically to prevent race conditions
Copy link

Copilot AI Feb 22, 2026

Choose a reason for hiding this comment

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

This comment says only the force is updated atomically, but the loop performs atomic updates for both forces and torques. Consider updating the comment to reflect both arrays to prevent misleading documentation.

Suggested change
! Update the force values atomically to prevent race conditions
! Update the force and torque values atomically to prevent race conditions

Copilot uses AI. Check for mistakes.
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 1 file

Confidence score: 5/5

  • Automated review surfaced no issues in the provided summaries.
  • No files require special attention.

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/simulation/m_ibm.fpp`:
- Line 1130: Remove the trailing whitespace on the blank line flagged by CI (a
line that contains only spaces) in the m_ibm.fpp source so the formatter passes;
locate the empty/blank line in the file, delete the trailing spaces (convert it
to a truly empty line), run ./mfc.sh format to verify no formatting diffs
remain, and commit the change.

viscous_stress_div(3, 1:3) = (viscous_stress_div_2(3, 1:3) - viscous_stress_div_1(3, 1:3))/(2._wp*dz) ! get z derivative of the second-row of viscous stress tensor
local_force_contribution(1:3) = local_force_contribution(1:3) + viscous_stress_div(3, 1:3) ! add the z components of the divergence to the force
end if

Copy link
Contributor

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟠 Major

Trailing whitespace — this is causing the CI formatting failure.

Line 1130 appears to contain trailing whitespace. The pipeline log confirms: formatting diff found in m_ibm.fpp. Remove the trailing spaces to pass the ./mfc.sh format check.

🔧 Fix trailing whitespace
-                            
+
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@src/simulation/m_ibm.fpp` at line 1130, Remove the trailing whitespace on the
blank line flagged by CI (a line that contains only spaces) in the m_ibm.fpp
source so the formatter passes; locate the empty/blank line in the file, delete
the trailing spaces (convert it to a truly empty line), run ./mfc.sh format to
verify no formatting diffs remain, and commit the change.

@codecov
Copy link

codecov bot commented Feb 22, 2026

Codecov Report

❌ Patch coverage is 71.42857% with 2 lines in your changes missing coverage. Please review.
✅ Project coverage is 44.06%. Comparing base (df28255) to head (25ce36d).
⚠️ Report is 9 commits behind head on master.

Files with missing lines Patch % Lines
src/simulation/m_ibm.fpp 71.42% 2 Missing ⚠️
Additional details and impacted files
@@           Coverage Diff           @@
##           master    #1234   +/-   ##
=======================================
  Coverage   44.05%   44.06%           
=======================================
  Files          70       70           
  Lines       20496    20481   -15     
  Branches     1989     1989           
=======================================
- Hits         9030     9024    -6     
+ Misses      10328    10319    -9     
  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 22, 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 22, 2026
@codeant-ai
Copy link
Contributor

codeant-ai bot commented Feb 22, 2026

CodeAnt AI Incremental review completed.

@codeant-ai
Copy link
Contributor

codeant-ai bot commented Feb 22, 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 22, 2026
@codeant-ai
Copy link
Contributor

codeant-ai bot commented Feb 22, 2026

CodeAnt AI Incremental review completed.

@github-actions
Copy link

Claude Code Review

No issues found. Checked for bugs and CLAUDE.md compliance.

@github-actions
Copy link

Claude Code Review

No issues found. Checked for bugs and CLAUDE.md compliance.

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.

2 participants