Skip to content

Improve AEM matrix solve and robustness in WiTNO#7

Open
lambolambert wants to merge 1 commit intoTNO:mainfrom
lambolambert:fix/witno
Open

Improve AEM matrix solve and robustness in WiTNO#7
lambolambert wants to merge 1 commit intoTNO:mainfrom
lambolambert:fix/witno

Conversation

@lambolambert
Copy link

Thank you for maintaining pyfastwell! This small PR focuses solely on improving numerical stability and preventing a minor method-name issue in the AEM solver (WiTNO). I kept the scope deliberately small and avoided any behavioral or API changes.

  • Summary of changes:
    • Switched from inv(m) @ brhs to np.linalg.solve(m, brhs) for better stability and performance.
    • Fixed a method call to _get_Infast, which prevents an AttributeError if higher-order modes are used (n > 0).
    • Added explicit numpy/pandas imports to avoid relying on wildcard imports.
    • Removed a duplicate assignment that was immediately overwritten.
  • Tests and examples still pass locally. If you prefer any of these changes to be split further or revised, I’m happy to adjust. Thanks for your time and consideration!

Changes (wi_tno.py only)

  • Use np.linalg.solve instead of matrix inverse:
    • src/pyfastwell/wellflow/wi_tno.py:339, 477
    • Rationale: solve is numerically more stable and faster than computing inv(m) @ brhs. No behavior change; improved stability.
  • Correct method call name for higher-order mode support:
    • src/pyfastwell/wellflow/wi_tno.py:324
    • Rationale: setupmatrix called get_Infast, but the method is defined as _get_Infast. Using the correct name prevents an AttributeError when n > 0. Matches existing usage in setupmatrix_new.
  • Add explicit imports:
    • src/pyfastwell/wellflow/wi_tno.py:3–4
    • Rationale: The module uses np and pd. Adding import numpy as np and import pandas as pd avoids reliance on wildcard imports leaking symbols.
  • Remove duplicate assignment:
    • src/pyfastwell/wellflow/wi_tno.py:165
    • Rationale: rweff was computed twice in a row; first value was immediately overwritten. Keeping a single, intended expression clarifies code without changing results.

Validation

  • Full test suite passes locally:
    • cd tests && MPLBACKEND=Agg uv run --no-project python -m unittest -v
    • 16 tests passed; no regressions.

…using numpy.linalg.solve, and updated method calls for clarity.
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