Skip to content

Extract duplicated NACA airfoil grid-generation block (TODO already present) #1502

@sbryngelson

Description

@sbryngelson

src/simulation/m_ib_patches.fpp contains the NACA 4-digit airfoil coordinate-table generation block twice, near-verbatim:

  • s_ib_airfoil (2D): lines 160-216
  • s_ib_3D_airfoil: lines 318-371

Both compute Np1/Np2/Np, @:ALLOCATE(airfoil_grid_u/l), seed endpoints, run the do i = 1, Np1 + Np2 - 1 camber/thickness loop (the yt = (5._wp*ta)*(0.2969_wp*xa**0.5_wp - ...) formula, sin_c/cos_c, upper/lower surface points), set the trailing endpoints, and GPU_UPDATE(device=[airfoil_grid_l, airfoil_grid_u]). The loop bodies (171-207 vs 328-362) are identical. The 2D copy even carries an explicit TODO:

! TODO :: This allocates the upper and lower airfoil arrays, and does not need to be performed each time the IB
! markers are updated. Place this as a separate subroutine.

Why it's friction: the airfoil table math is duplicated; the marker-marking loops below each block (which legitimately differ between 2D and 3D) are the only parts that should remain distinct.

Safe refactor: extract a s_generate_airfoil_grid(patch_id, ...) helper holding the duplicated block and call it from both. Pure extraction, no numerical change.

Golden-file risk: low if extracted verbatim — same arithmetic, same airfoil_grid_u/l population. Airfoil-IB tests should still be run.

Coordination note: related to #1451 ("STL and Airfoil Memory Structs"), which plans to move airfoil/model params off the IB patch type into dedicated data types — a deeper data-layout refactor that will rewrite how airfoil_grid_u/l are stored. This grid-gen extraction is adjacent (it de-duplicates the generation code, not the storage); it should be coordinated with / possibly folded into #1451 to avoid touching the same code twice.


Filed from a repo-wide code-cleanliness review; verified against master @ 40dde5e.

Code references

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions