Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(exg-gwf*): check for equal idomain #2149

Merged
merged 4 commits into from
Jan 18, 2025

Conversation

wpbonelli
Copy link
Contributor

@wpbonelli wpbonelli commented Jan 17, 2025

Check that models connected to a flow model by an exchange have an idomain identical to the flow model's idomain. This is an easy error to make, and (up to now) hard to detect.

I only added a test for PRT for now. The logic is identical in GWT and GWE. I wondered if there are suitable autotests for those models to add a test case to? Or maybe this behavior should have its own autotest?

#2144 facilitates adding the same check for flow model interface. I figure that can be done in a separate PR since it probably deserves a separate release note?


Checklist of items for pull request

  • Replaced section above with description of pull request
  • Added new test or modified an existing test
  • Formatted new and modified Fortran source files with fprettify
  • Added doxygen comments to new and modified procedures
  • Updated develop.tex with a plain-language description of the bug fix, change, feature; required for changes that may affect users
  • Removed checklist items not relevant to this pull request

@@ -220,6 +228,34 @@ subroutine exg_ar(this)
call store_error(errmsg, terminate=.TRUE.)
end if
!
! -- Make sure idomains are identical
select type (gwfdis => gwfmodel%dis)
Copy link
Contributor Author

Choose a reason for hiding this comment

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

All the select type statements are unfortunate, but idomain is defined separately for each dis type since it's the real grid shape instead of flat

Copy link
Contributor

Choose a reason for hiding this comment

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

Ahh, bummer. I guess now that all discretizations have IDOMAIN, we could move it to disbasetype and make it a 1D int vector, but that is for another time, I think.

Copy link
Contributor

Choose a reason for hiding this comment

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

If I am understanding correctly, we are trying to assess the equality of grid. Maybe we can have a function is_equal(this, other_dis) result(are_equal) to delegate the check to the particular Discretization module?

Copy link
Contributor

Choose a reason for hiding this comment

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

PS: happy to help and chat more about that option

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@mjr-deltares thanks we should definitely chat on this with @langevin-usgs

It may be relevant to #2153 as well. In that PR, I first planned to load the full flow model dis into fmi, then an is_equal function would be quite natural to use. But the dis types have some strong expectations about how they are initialized and where they get their data from. So in the near term, I was thinking of loading only the minimum necessary info to do the same checks. Hopefully we can come up with a nicer long term solution.

Copy link
Contributor

Choose a reason for hiding this comment

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

This is a good point. In this new check, we are saying the grids are the same if the number of nodes and idomain is the same; it is easy to accidentally leave out idomain when using flopy to construct dis. But certainly, if tops and bottoms were also different, then that would not be detected here, and problems would be very difficult to find. A discretization-based is_equal() (and maybe is_same()?) seems like a nice way to ensure grid equality.

Copy link
Contributor

Choose a reason for hiding this comment

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

OK, let's talk tomorrow and plan a meeting. Btw I had no intention stalling this PR. This should probably go in and then we refactor when we have a plan.

@wpbonelli wpbonelli changed the title refactor(exg-gwf*): check for equal idomain fix(exg-gwf*): check for equal idomain Jan 17, 2025
@wpbonelli wpbonelli added the bug label Jan 17, 2025
Check that models connected to a flow model via an exchange have an identical idomain array to the flow model's.
Copy link
Contributor

@langevin-usgs langevin-usgs left a comment

Choose a reason for hiding this comment

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

Looks good. It's a convoluted check, as you mention, but perhaps a refactor of idomain into disbasetype can be done at some point to clean this up.

@@ -220,6 +228,34 @@ subroutine exg_ar(this)
call store_error(errmsg, terminate=.TRUE.)
end if
!
! -- Make sure idomains are identical
select type (gwfdis => gwfmodel%dis)
Copy link
Contributor

Choose a reason for hiding this comment

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

Ahh, bummer. I guess now that all discretizations have IDOMAIN, we could move it to disbasetype and make it a 1D int vector, but that is for another time, I think.

@wpbonelli wpbonelli marked this pull request as ready for review January 18, 2025 14:14
@wpbonelli wpbonelli merged commit 849578f into MODFLOW-ORG:develop Jan 18, 2025
6 checks passed
@wpbonelli wpbonelli deleted the exg-check-idomain branch January 18, 2025 14:16
@wpbonelli wpbonelli added this to the 6.6.1 milestone Jan 18, 2025
wpbonelli added a commit that referenced this pull request Jan 25, 2025
Support an optional GWFGRID entry in FMI for the flow model's binary grid file. If provided, check the grids have the same size and idomain like we do in EXG as of #2149. This makes for the same error-checking in the exg (coupled) and fmi (post-processing) cases.

Tentative idea is to make the grid file entry optional for some time (1-2 releases), then begin to require it. At which point the reader could be modified to load the full dis, and we could consolidate these haphazard checks into a robust grid comparison.

The grb file reader in zonebudget is moved to a new GridFileReader module in the main src dir. The reader now loads headers and builds an index at init time, after which variables can be read as necessary.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants