Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Speed up the airfoil drag calculations #118

Open
wants to merge 14 commits into
base: main
Choose a base branch
from

Conversation

askprash
Copy link
Member

@askprash askprash commented Jan 7, 2025

This PR makes some improvements to the airfoil drag calculations to speed up the airsection calculations by roughly ~5x. The airfoil type wasn't really type stable/ it's field types weren't inferable by the compiler. Also the spline evaluations have been cleaned up a little and optimized for better performance.

On my M2 mac the performance of the airfoil section calculations are:

julia> bench = @benchmarkable aerodynamics.airfun($clp, $toc, $Mperp, 
                                               $airfoil_section) seconds = 30 evals = 100
Benchmark(evals=100, seconds=30.0, samples=10000)

julia> bench_airfun = run(bench)
BenchmarkTools.Trial: 10000 samples with 100 evaluations.
 Range (min  max):  696.250 ns   1.106 μs  ┊ GC (min  max): 0.00%  0.00%
 Time  (median):     701.670 ns              ┊ GC (median):    0.00%
 Time  (mean ± σ):   710.746 ns ± 24.497 ns  ┊ GC (mean ± σ):  0.00% ± 0.00%

  ▇█▇▆▅▅▄▂▂▂▁▁    ▃▄▃▃▂▁                                       ▂
  █████████████▇▇██████████▆▇▇▆▆▅▆▆▆▇▅▇▆▆▆▅▆▄▆▅▆▅▄▅▄▃▅▄▄▄▅▃▄▂▅ █
  696 ns        Histogram: log(frequency) by time       824 ns <

 Memory estimate: 96 bytes, allocs estimate: 4.

This PR:

julia> bench_airfun = run(bench)
BenchmarkTools.Trial: 10000 samples with 100 evaluations.
 Range (min  max):  131.250 ns  392.500 ns  ┊ GC (min  max): 0.00%  0.00%
 Time  (median):     133.750 ns               ┊ GC (median):    0.00%
 Time  (mean ± σ):   134.427 ns ±   7.138 ns  ┊ GC (mean ± σ):  0.00% ± 0.00%

              ▂  ▆  █  ▆  ▄                                      
  ▂▁▁▃▁▁▃▁▁▆▁▁█▁▁█▁▁█▁▁█▁▁█▁▁█▁▁▅▁▁▄▁▁▃▁▁▂▁▁▂▁▁▂▁▁▂▁▁▂▁▁▂▁▁▂▁▁▂ ▃
  131 ns           Histogram: frequency by time          140 ns <

 Memory estimate: 0 bytes, allocs estimate: 0.

Copy link

codecov bot commented Jan 7, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 78.43%. Comparing base (8ee97c4) to head (383570a).

Additional details and impacted files
@@            Coverage Diff             @@
##             main     #118      +/-   ##
==========================================
- Coverage   78.49%   78.43%   -0.06%     
==========================================
  Files          79       79              
  Lines       13499    13514      +15     
==========================================
+ Hits        10596    10600       +4     
- Misses       2903     2914      +11     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@askprash askprash marked this pull request as ready for review January 23, 2025 15:21
Copy link
Contributor

@ngomezve ngomezve left a comment

Choose a reason for hiding this comment

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

The PR looks good to me. The aerodynamic functions in airfun.jl in general are the least readable in all of TASOPT: they have essentially no comments or documentation and the variable names are not descriptive. Since the PR is not any worse in this regard than main, I believe it can be pulled in.

@@ -34,29 +34,28 @@ Looks up airfoil performance data at specified conditions, as precomputed and fo
end

@views function airfun(cl, τ, Mach,
Copy link
Contributor

Choose a reason for hiding this comment

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

This function in general is very poorly commented. Not relevant for this PR but this is very hard to interpret.

@@ -125,26 +135,48 @@ Returns im and io s.t. `xarr[im] < x < xarr[io]`.

Additionally returns the interval `dx = xarr[io] - xarr[im]`
"""
function findsegment(x::Float64, xarr::AbstractArray{Float64})
function findsegment(x::Float64, xarr)
Copy link
Contributor

Choose a reason for hiding this comment

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

These functions have no comments or documentation.

@@ -87,12 +81,12 @@ function surfcd2(
Snorm = 0.0
ARe = wing.airsection.Re

for i = 1:n/2
frac = (float(i) - 0.5) / float(n / 2)
for i = 1:n÷2
Copy link
Contributor

Choose a reason for hiding this comment

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

It would be good to comment on why the integer division is used

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.

2 participants