refactor: vectorize explicit stencils, extract shared latent heat in 1D solvers#73
Merged
djsilva99 merged 2 commits intodjsilva99:developfrom Mar 31, 2026
Merged
Conversation
- Extract duplicated latent heat block into _latent_heat.py - Vectorize explicit_general and explicit_k FDM stencils with numpy - Remove copy.deepcopy from explicit solvers - All 25 tests pass, ~1.6x speedup on test suite Closes djsilva99#45
Codecov Report❌ Patch coverage is @@ Coverage Diff @@
## develop #73 +/- ##
===========================================
+ Coverage 70.66% 72.79% +2.13%
===========================================
Files 21 22 +1
Lines 2335 2272 -63
===========================================
+ Hits 1650 1654 +4
+ Misses 685 618 -67
... and 2 files with indirect coverage changes 🚀 New features to boost your workflow:
|
Owner
|
@formeo thanks a lot for the contribution — the implementation looks solid and the code quality is great overall 👍 I have a few small requests before merging:
Thanks again — really nice work! |
Author
|
Thanks Daniel! All three addressed:
The new test runs with
This covers the latent heat heating path in |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Related to #45
What changed
New file:
_latent_heat.pyExtracts the latent heat phase-transition logic that was duplicated in all
4 solvers into a single
apply_latent_heat()function.Explicit solvers (
explicit_general.py,explicit_k.py)copy.deepcopy+ per-element Python loops with numpy vectorizedFDM stencil computation
Implicit solvers (
implicit_general.py,implicit_k.py)apply_latent_heat()calln = obj.num_pointslocal variable, remove unusedcopyimportWhat didn't change
y, lheat)np.linalg.solvewith a tridiagonal matrix(no scipy.linalg.solve_banded — that could be a separate PR)
Testing
All 25 existing tests pass. Test runtime dropped from ~118s to ~72s on
the same machine (the effect will be larger on bigger grids since the
vectorization benefit scales with
num_points).Stats