IBM force calculation simplification (Dr Bala recommendations)#1234
IBM force calculation simplification (Dr Bala recommendations)#1234mrvandenboom wants to merge 8 commits intoMFlowCode:masterfrom
Conversation
Nitpicks 🔍
|
There was a problem hiding this comment.
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 × Fcross 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 |
There was a problem hiding this comment.
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.
| 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 |
|
|
||
| call s_cross_product(radial_vector, local_force_contribution, local_torque_contribution) | ||
|
|
||
| ! Update the force values atomically to prevent race conditions |
There was a problem hiding this comment.
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.
| ! Update the force values atomically to prevent race conditions | |
| ! Update the force and torque values atomically to prevent race conditions |
There was a problem hiding this comment.
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.
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## master #1234 +/- ##
=======================================
Coverage 44.95% 44.95%
=======================================
Files 70 70
Lines 20503 20488 -15
Branches 1946 1946
=======================================
- Hits 9217 9211 -6
+ Misses 10164 10155 -9
Partials 1122 1122 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
Claude Code Review1 file changed: Summary
FindingsIssue 1 — Dead variables left in declaration and GPU private clause (m_ibm.fpp)
Line ~1053 (variable declaration): real(wp), dimension(1:3, 1:3) :: viscous_stress_div, viscous_stress_div_1, viscous_stress_div_2, viscous_cross_1, viscous_cross_2Line ~1074 (GPU_PARALLEL_LOOP private clause): $:GPU_PARALLEL_LOOP(private='[... viscous_cross_1, viscous_cross_2, ...]', ...)These should be removed. On GPU builds the unused private allocations are harmless but waste per-thread stack space, and they create misleading code. The Recommendation: Remove Issue 2 — Incorrect comment on z-direction block (m_ibm.fpp)The new z-direction line says "second-row" but indexes row 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 tensorThis is a copy-paste error from the y-direction comment. It should read "third-row". Issue 3 — GPU test coverage not confirmedThis PR modifies code in Improvement Opportunities
|
Review Summary by QodoSimplify IBM force and torque calculations with combined contributions
WalkthroughsDescription• Simplify force and torque calculation by computing torque once from combined pressure and viscous forces • Remove redundant cross-product calculations for intermediate viscous stress terms • Reduce atomic update contention by assembling complete force before updating global arrays • Move torque computation after all force contributions are accumulated Diagramflowchart LR
A["Pressure gradient\ncontribution"] --> B["Accumulate all\nforce components"]
C["Viscous stress\nderivatives"] --> B
B --> D["Compute torque\nonce from final force"]
D --> E["Atomic update\nglobal arrays"]
File Changes1. src/simulation/m_ibm.fpp
|
Code Review by Qodo
1. Dead GPU privates left
|
Claude Code ReviewHead SHA: Files changed: 1
Summary:
Findings1. Comment typo — z-direction row index (minor) viscous_stress_div(3, 1:3) = ... ! get z derivative of the second-row of viscous stress tensorThe comment says "second-row" but the code accesses index 3 (third row). Should read "third-row". 2. Potentially dead local arrays — ! OLD (removed)
call s_cross_product(radial_vector, viscous_stress_div_1(l, 1:3), viscous_cross_1(l, 1:3))
...If these arrays are no longer referenced anywhere else in the subroutine they should be removed from the local variable declarations and any associated 3. Correctness — verified correct 4. "TODO :: This is really bad code" comment preserved Overall: Approve with the comment typo fix and a check that |
📝 WalkthroughWalkthroughThe pull request refactors the force and torque computation logic in the IBM simulation module. Previously, atomic updates occurred inside the per-IBPoint loop. The change consolidates this by accumulating viscous stress derivatives into local force and torque contribution variables, then performing a single cross-product calculation and atomic update block after all local contributions are computed. Comments are adjusted to reflect the updated computation sequence focusing on force divergence contributions rather than per-step operations. 🚥 Pre-merge checks | ✅ 3✅ Passed checks (3 passed)
✏️ 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. Comment |
There was a problem hiding this comment.
🧹 Nitpick comments (1)
src/simulation/m_ibm.fpp (1)
1077-1077: Clarify two inline comments to match behavior.Line 1077 says “second-row” but this is the third-row derivative, and Line 1085 mentions only force while both force and torque are updated atomically.
✏️ Suggested comment-only diff
- 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 @@ - ! Update the force values atomically to prevent race conditions + ! Update the force and torque values atomically to prevent race conditionsAlso applies to: 1085-1085
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
Testing
ran ./mfc.sh lint
ran ./mfc.sh format
ran ./mfc.sh test -a on Hipergator (CPU). All tests passed.
CodeAnt-AI Description
Compute torque from combined pressure and viscous forces and reduce atomic updates
What Changed
Impact
✅ Correct torque from combined pressure and viscous contributions✅ Fewer atomic updates during force/torque assembly✅ Lower contention during per-point 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:
This lets you have a chat with CodeAnt AI about your pull request, making it easier to understand and improve your code.
Example
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:
This helps CodeAnt AI learn and adapt to your team's coding style and standards.
Example
Retrigger review
Ask CodeAnt AI to review the PR again, by typing:
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.