Skip to content

Remove airfoil and stl paramters#1524

Open
danieljvickers wants to merge 9 commits into
MFlowCode:masterfrom
danieljvickers:remove-airfoil-and-stl-paramters
Open

Remove airfoil and stl paramters#1524
danieljvickers wants to merge 9 commits into
MFlowCode:masterfrom
danieljvickers:remove-airfoil-and-stl-paramters

Conversation

@danieljvickers
Copy link
Copy Markdown
Member

Description

The patch_ib array has become bloated as many variable have been added to this struct, growing each element to 962 bytes. Several of these variables are unused except in niche cases. Two such examples are the STL models and airfoils. Particularly the STL model is responsible for 492 bytes of this usage (over half).

Since we are not MPI communicating the patch_ib elements regularly, it is important to try to optimize their size. This will improve communication time as well as likely providing a noticeable performance benefit. This was done by creating separate smaller data structures that the patches will call out to that actually contain airfoil and STL information. This will make minor modifications to the case file, which other users should be made aware of.

Fixes #1451

Type of change

  • Refactor

Testing

Ran test suite.

Checklist

  • I added or updated tests for new behavior
  • I updated documentation if user-facing behavior changed

@github-actions
Copy link
Copy Markdown

github-actions Bot commented Jun 1, 2026

Claude Code Review

Head SHA: 0d27a5e

Files changed:

  • 25
  • src/common/m_model.fpp
  • src/common/m_constants.fpp
  • src/common/m_derived_types.fpp
  • src/pre_process/m_check_ib_patches.fpp
  • src/simulation/m_compute_levelset.fpp
  • src/simulation/m_ib_patches.fpp
  • src/simulation/m_global_parameters.fpp
  • toolchain/mfc/params/definitions.py
  • toolchain/mfc/case_validator.py

Findings

1. Unguarded print in s_instantiate_STL_models — MPI correctness regression
src/common/m_model.fpp, new line 992 (inside do stl_id = 1, num_stl_models):

print *, " * Reading model: " // trim(stl_models(stl_id)%model_filepath)

The old code had if (proc_rank == 0) print *, " * Reading model: ...". The guard was dropped in the refactor. Every MPI rank will now print this message, flooding output on any parallel run. All surrounding prints in the same function retain if (proc_rank == 0) guards (lines 1005-1006, 1023-1024, 1031-1035, 1053).


2. Potential out-of-bounds array access in airfoil IB checker — correctness bug
src/pre_process/m_check_ib_patches.fpp, lines 110–114 (and identically 127–131):

@:PROHIBIT(n == 0 .or. p > 0 .or. patch_ib(patch_id)%airfoil_id <= 0 &
           & .or. ib_airfoil(patch_ib(patch_id)%airfoil_id)%c <= 0._wp &

When airfoil_id = 0 (the default), Fortran's .or. does not guarantee short-circuit evaluation (F2003 §7.2.4), so ib_airfoil(0)%c may be evaluated before the airfoil_id <= 0 sub-expression triggers. ib_airfoil is dimension(num_ib_airfoils_max) (1-based, size 5), so index 0 is out of bounds. The model-checker in the same file already uses the correct pattern — split the bounds check into its own @:PROHIBIT before the content checks, matching what s_check_model_ib_patch_geometry does for model_id.


3. Wrong Fortran constant in definitions.py inflates patch_ib registry to 2,050,000 entries
toolchain/mfc/params/definitions.py:

-NIB = _fc("num_ib_patches_max_namelist", 50000)  # patch_ib namelist limit
+NIB = _fc("num_ib_patches_max", 50000)  # patch_ib (Fortran array bound)

Both constants exist in src/common/m_constants.fpp: num_ib_patches_max_namelist = 54000 and num_ib_patches_max = 2050000. The _fc() call now resolves to 2050000 (not the fallback 50000) because the named constant is present. NIB is used as max_index for the patch_ib indexed family. Raising it from ~54000 to 2,050,000 means the Python parameter registry will attempt to enumerate ~2 million patch_ib(i)%* entries, causing severe toolchain performance regressions (case validation, ./mfc.sh params, ./mfc.sh lint). The constant name should remain "num_ib_patches_max_namelist".

@codecov
Copy link
Copy Markdown

codecov Bot commented Jun 2, 2026

Codecov Report

❌ Patch coverage is 66.39004% with 81 lines in your changes missing coverage. Please review.
✅ Project coverage is 60.81%. Comparing base (08d12f8) to head (14f579e).
⚠️ Report is 3 commits behind head on master.

Files with missing lines Patch % Lines
src/common/m_model.fpp 53.73% 17 Missing and 14 partials ⚠️
src/simulation/m_ib_patches.fpp 72.72% 16 Missing and 8 partials ⚠️
src/simulation/m_compute_levelset.fpp 33.33% 18 Missing ⚠️
src/pre_process/m_check_ib_patches.fpp 28.57% 5 Missing ⚠️
src/simulation/m_ibm.fpp 50.00% 1 Missing and 1 partial ⚠️
src/simulation/m_start_up.fpp 66.66% 0 Missing and 1 partial ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master    #1524      +/-   ##
==========================================
+ Coverage   60.64%   60.81%   +0.16%     
==========================================
  Files          73       73              
  Lines       20213    20193      -20     
  Branches     2936     2931       -5     
==========================================
+ Hits        12259    12281      +22     
+ Misses       5966     5926      -40     
+ Partials     1988     1986       -2     

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

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@danieljvickers
Copy link
Copy Markdown
Member Author

@sbryngelson approval for benchmark?

@danieljvickers
Copy link
Copy Markdown
Member Author

AI commanets have been addressed, btw

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

Labels

None yet

Development

Successfully merging this pull request may close these issues.

STL and Airfoil Memory Structs

2 participants