Skip to content

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

Merged
1-Bart-1 merged 2 commits into
mainfrom
separate-function
Jun 12, 2026
Merged

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

Conversation

@1-Bart-1

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

Copy link
Copy Markdown
Member

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

codecov Bot commented Jun 6, 2026

Copy link
Copy Markdown

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!

@1-Bart-1 1-Bart-1 merged commit e04fe54 into main Jun 12, 2026
8 of 9 checks passed
@1-Bart-1 1-Bart-1 deleted the separate-function branch June 12, 2026 14:26
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