Skip to content

feat(grid): add get_node() method to all grid types#2680

Merged
wpbonelli merged 2 commits into
modflowpy:developfrom
wpbonelli:get-node
Jan 16, 2026
Merged

feat(grid): add get_node() method to all grid types#2680
wpbonelli merged 2 commits into
modflowpy:developfrom
wpbonelli:get-node

Conversation

@wpbonelli

@wpbonelli wpbonelli commented Jan 15, 2026

Copy link
Copy Markdown
Member

Add a get_node() method to VertexGrid and UnstructuredGrid, consistent with StructuredGrid, for cell ID -> node number conversions. Rename the lrc_list parameter on StructuredGrid.get_node() to cellids and deprecate lrc_list. Add an optional node2d parameter to determine whether to get the 2D or 3D node number, useful for structured and vertex grids, ignored for unstructured.

The cell ID -> node number conversion was done ad hoc in a few places in the codebase, this allows some simplification. Maybe in 4.x we can standardize the signature and pull an abstract method into the base Grid class.

@wpbonelli wpbonelli added this to the 3.10 milestone Jan 15, 2026
@codecov

codecov Bot commented Jan 15, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 94.44444% with 3 lines in your changes missing coverage. Please review.
✅ Project coverage is 72.8%. Comparing base (556c088) to head (018e548).
⚠️ Report is 107 commits behind head on develop.

Files with missing lines Patch % Lines
flopy/discretization/structuredgrid.py 86.6% 2 Missing ⚠️
flopy/discretization/unstructuredgrid.py 93.7% 1 Missing ⚠️
Additional details and impacted files
@@             Coverage Diff             @@
##           develop    #2680      +/-   ##
===========================================
+ Coverage     55.5%    72.8%   +17.2%     
===========================================
  Files          644      667      +23     
  Lines       124135   130158    +6023     
===========================================
+ Hits         68947    94778   +25831     
+ Misses       55188    35380   -19808     
Files with missing lines Coverage Δ
flopy/discretization/vertexgrid.py 81.0% <100.0%> (-2.7%) ⬇️
flopy/export/utils.py 54.3% <100.0%> (-10.3%) ⬇️
flopy/plot/crosssection.py 64.6% <100.0%> (-2.5%) ⬇️
flopy/utils/binaryfile/__init__.py 84.2% <100.0%> (-0.3%) ⬇️
flopy/discretization/unstructuredgrid.py 81.9% <93.7%> (+0.4%) ⬆️
flopy/discretization/structuredgrid.py 53.4% <86.6%> (+5.9%) ⬆️

... and 555 files with indirect coverage changes

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

@wpbonelli wpbonelli marked this pull request as ready for review January 15, 2026 18:20
@wpbonelli

Copy link
Copy Markdown
Member Author

discussed offline with @jlarsen-usgs

@wpbonelli wpbonelli merged commit 94f3c8c into modflowpy:develop Jan 16, 2026
20 checks passed
@wpbonelli wpbonelli deleted the get-node branch January 16, 2026 22:17
wpbonelli added a commit that referenced this pull request Jan 31, 2026
Improve the shared face finding algorithm for HFB (Horizontal Flow Barrier) plotting. Factor out @jlarsen-usgs's index-based approach from #2671 into reusable function(s) and use it instead of floating point comparisons as before. Should be faster.

I moved the new face-related functions to a new module faceutil.py instead of plotutil.py as they are used not only for plotting but for export, and may be useful in other cases. I considered putting them in gridutil.py but that is used by the grid classes, while the face functions use the grid classes, so it would have created a circular import.

I also changed the name of is_vertical_barrier -> is_vertical and inverted the semantics so it works on faces, not barriers (a face between horizontally adjacent cells is a vertical polygon, and a face between vertically adjacent cells is a horizontal polygon, but we call the former a "horizontal"  flow barrier and the latter a "vertical" flow barrier). I figure writing these utils in terms of faces for the general case makes sense, and just interpreting the results for the specific case of HFBs.

This PR builds on

- #2671's shared face finding approach
- #2680 which gives all grid types a consistent get_node() method
- #2681 which adds an ihc init parameter/attribute to UnstructuredGrid

Some ad hoc cell ID -> node number conversion utilities are removed and get_node() used instead.

I am classifying all this a refactor though it introduces a new utility module, as the new utils are in service of the refactor.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant