Skip to content

Vectorize I_nm/I_mk coupling integrals and remove per-element assembly loops - #99

Merged
HopeBestWorld merged 5 commits into
mainfrom
copilot/edit-imn-imk-functions
Aug 1, 2026
Merged

Vectorize I_nm/I_mk coupling integrals and remove per-element assembly loops#99
HopeBestWorld merged 5 commits into
mainfrom
copilot/edit-imn-imk-functions

Conversation

Copilot AI commented Jul 21, 2026

Copy link
Copy Markdown
Contributor

I_nm and I_mk were scalar/branch-oriented and required nested Python loops in matrix assembly, limiting performance and making fast-path formulas harder to apply selectively. This change makes both integrals array-native and applies case-specific formulas via mask-based indexing so expensive/general formulas run only where required.

  • Vectorized coupling APIs (multi_equations.py)

    • Added grid normalization to accept:
      • scalar mode indices,
      • 1D row/column mode vectors (implicit meshgrid),
      • pre-shaped 2D index arrays.
    • Refactored I_nm and I_mk to compute with logical masks for:
      • zero-mode fast paths,
      • mixed zero/nonzero cases,
      • general-case formulas,
      • equality/singularity edge handling only on relevant subsets.
  • Assembly/cache integration (meem_engine.py)

    • Replaced nested (n,m) precompute loops for I_nm with a single vectorized call over mode grids.
    • Replaced nested (m,k) closure loop for I_mk with a single vectorized call, preserving existing cache interfaces and downstream block assembly behavior.
  • Illustrative usage

    n_modes = np.arange(N)[:, None]
    m_modes = np.arange(M)[None, :]
    I_nm_vals = I_nm(n_modes, m_modes, i, d, h)
    
    m_modes = np.arange(Mi)[:, None]
    k_modes = np.arange(K)[None, :]
    I_mk_vals = I_mk(m_modes, k_modes, i, d, m0, h, m_k_arr, N_k_arr)

Base automatically changed from faster-bessels to main July 27, 2026 15:24
@codecov

codecov Bot commented Jul 27, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 98.87640% with 1 line in your changes missing coverage. Please review.
✅ Project coverage is 98.53372%. Comparing base (0a1a4f0) to head (f36dbfb).

Files with missing lines Patch % Lines
package/src/openflash/multi_equations.py 98.79518% 1 Missing ⚠️
Additional details and impacted files
@@                 Coverage Diff                 @@
##                main         #99         +/-   ##
===================================================
- Coverage   98.56061%   98.53372%   -0.02688%     
===================================================
  Files             11          11                 
  Lines           1320        1364         +44     
===================================================
+ Hits            1301        1344         +43     
- Misses            19          20          +1     
Flag Coverage Δ
unit 98.53372% <98.87640%> (-0.02688%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

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

@rebeccamccabe rebeccamccabe left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

@copilot look at the suggestions I have made which starts with nan and explicitly assigns zeros, instead of starting with zeros and having lack of assignment be the zeros. this is a change for readability to ensure the formulas are easier to check and it is clear exactly where there are zeros. apply these changes and the equivalent changes for the remainder of the function.

Comment thread package/src/openflash/multi_equations.py Outdated
Comment thread package/src/openflash/multi_equations.py Outdated
Comment thread package/src/openflash/multi_equations.py Outdated
Comment thread package/src/openflash/multi_equations.py Outdated

Copilot AI commented Jul 27, 2026

Copy link
Copy Markdown
Contributor Author

@copilot look at the suggestions I have made which starts with nan and explicitly assigns zeros, instead of starting with zeros and having lack of assignment be the zeros. this is a change for readabi...

Implemented in commit 920f560. I_nm and I_mk now initialize outputs with NaN and explicitly assign zero-valued masked branches (including the dj == d[...] and m0 == inf cases), with equivalent explicit-zero handling applied across the remaining masked branches in both functions.

@rebeccamccabe rebeccamccabe left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

restoring lost comments

Comment thread package/src/openflash/multi_equations.py Outdated
Comment thread package/src/openflash/multi_equations.py Outdated
Co-authored-by: Becca <32020426+rebeccamccabe@users.noreply.github.com>
@rebeccamccabe
rebeccamccabe marked this pull request as ready for review July 27, 2026 17:11
@HopeBestWorld
HopeBestWorld merged commit fd0d54b into main Aug 1, 2026
11 checks passed
@rebeccamccabe
rebeccamccabe deleted the copilot/edit-imn-imk-functions branch August 4, 2026 17:16
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.

3 participants