Skip to content

Split calc_forces! out of solve! and make it zero-alloc#245

Open
1-Bart-1 wants to merge 2 commits into
mainfrom
separate-function
Open

Split calc_forces! out of solve! and make it zero-alloc#245
1-Bart-1 wants to merge 2 commits into
mainfrom
separate-function

Conversation

@1-Bart-1
Copy link
Copy Markdown
Member

@1-Bart-1 1-Bart-1 commented Jun 6, 2026

What

Extract the force/moment assembly (everything after the circulation solve) from solve! into a standalone exported calc_forces!(solver, body_aero). solve! is now solve_base! + calc_forces!, with behavior unchanged.

This creates a clean seam: a frozen circulation can be mapped to forces via calc_forces! without re-running the nonlinear gamma solve. It's the backend kernel for an upcoming geometry → forces aero interface in SymbolicAWEModels.jl.

Zero-alloc

calc_forces! is the per-step hot path, so it's now allocation-free:

  • preallocate panel_area_dist buffer (was zeros(T, n) each call)
  • preallocate unrefined_count_dist buffer (was zeros(Int, n) each call)
  • rewrite _compute_reference_velocity_from_distribution to drop its ones() / T.() copies

Added a function-barrier zero-alloc test for calc_forces!.

Verification

Full solver suite green, behavior-preserving:

  • Solver Constructor 3/3, NONLIN re-runs 2/2
  • calc_forces! is zero-alloc 1/1
  • Unrefined Arrays 40/40
  • ForwardDiff linearize 7/7 (Dual path intact; norm_fwd ≈ norm_fd)

🤖 Generated with Claude Code

Extract the force/moment assembly (everything after the circulation
solve) from solve! into a standalone exported calc_forces!(solver,
body_aero). solve! is now solve_base! + calc_forces!; behavior is
unchanged. This lets a frozen circulation be mapped to forces without
re-running the nonlinear gamma solve.

Make calc_forces! allocation-free for the per-step hot path:
- preallocate panel_area_dist buffer (was zeros(T, n) each call)
- preallocate unrefined_count_dist buffer (was zeros(Int, n) each call)
- rewrite _compute_reference_velocity_from_distribution to drop its
  ones()/T.() copies

Add a function-barrier zero-alloc test for calc_forces!.

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

codecov Bot commented Jun 6, 2026

Codecov Report

❌ Patch coverage is 92.00000% with 2 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
ext/VortexStepMethodControlPlotsExt.jl 0.00% 2 Missing ⚠️

📢 Thoughts on this report? Let us know!

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant