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

Issue #728 metaswap grid agnostic well #1256

Conversation

JoerivanEngelen
Copy link
Contributor

@JoerivanEngelen JoerivanEngelen commented Oct 25, 2024

Fixes #728

Description

This PR updates two MetaSWAP packages that depend on wells to use of the deprecated WellDisStructured object to the Mf6Wel object.

It fixes the first small step of the big metaswap refactor. I chose a feature branch as base branch to merge into, to still have the option to create some hotfixes for a new release of iMOD Python while primod is being updated.

I also renamed some variable names and dimension names with clearer names. Furthermore, I type annotated some method.

Checklist

  • Links to correct issue
  • Update changelog, if changes affect users
  • PR title starts with Issue #nr, e.g. Issue #737
  • Unit tests were added
  • If feature added: Added/extended example

well_row = self.well["row"] - 1
well_column = self.well["column"] - 1
well_layer = self.well["layer"]
cellid = self.well["cellid"]
Copy link
Collaborator

Choose a reason for hiding this comment

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

You could rename this to well_cellid

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done for this local variable, also in the CouplerMapping equivalent function

if len(cellid.coords["nmax_cellid"]) != 3:
raise TypeError("Coupling to unstructured grids is not supported.")

well_layer = cellid.sel(nmax_cellid="layer").data
Copy link
Collaborator

Choose a reason for hiding this comment

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

What is nmac_cellid? I cant figure it our by just looking at this file
Could you rename it to something more describing?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I based this name on an example I found in the UGRID conventions. There it is named nMaxMesh2_face_nodes, meaning max amount of nodes per face. The "max" is relevant in Ugrids, as meshes can be flexible so the amount of nodes per face can vary in the grid.

In our case this is not happening, so the "max" is wrong here. I'll rename to ncellid, as that is a better name for this dimension.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Looking better at this: ncellid already refers to the rows in the table. nmax_cellid refers to columns, maybe ndim_cellid is a better name?

Copy link
Contributor

Choose a reason for hiding this comment

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

+1 for ndim_cellid

Copy link
Contributor Author

Choose a reason for hiding this comment

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

After a brief discussion with @Manangka, I renamed it to dim_cellid.

imod/mf6/wel.py Outdated
@@ -248,7 +320,7 @@ def _create_cellid(
df_for_cellid = assigned_wells.groupby("index").first()
Copy link
Collaborator

Choose a reason for hiding this comment

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

Would unique_assigned_wells be a better name?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Indeed, renamed

@@ -248,7 +320,7 @@ def _create_cellid(
df_for_cellid = assigned_wells.groupby("index").first()
d_for_cellid = df_for_cellid[["x", "y", "layer"]].to_dict("list")

return self._derive_cellid_from_points(like, **d_for_cellid)
return derive_cellid_from_points(like, **d_for_cellid)
Copy link
Collaborator

Choose a reason for hiding this comment

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

If the well is ever moved the cellid needs to be updated.
Thus method then needs to be called whenever the row,column or layer is adjusted

I don't know how likely that is but i cant imagine a use cage where you start with a base model with wells and then move some of them to see the effect of it.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is not a likely use case, as the Mf6Wel is always generated at writing, so after regridding/clipping etc.

imod/mf6/wel.py Outdated
@@ -248,7 +320,7 @@ def _create_cellid(
df_for_cellid = assigned_wells.groupby("index").first()
d_for_cellid = df_for_cellid[["x", "y", "layer"]].to_dict("list")
Copy link
Collaborator

Choose a reason for hiding this comment

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

I find the name cellid confusing. In MODFLOW terms this is the row, column, layer or the 2dcellid, layer.
In this case it would call it something like id, identifier, name or well_id

Copy link
Contributor Author

Choose a reason for hiding this comment

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

But row, column, layer is what I refer to with the cellid. At some point in the future we might also have to support 2dcellid, but that will probably not happen soon.

Copy link

Quality Gate Failed Quality Gate failed

Failed conditions
15.4% Duplication on New Code (required ≤ 3%)

See analysis details on SonarCloud

@JoerivanEngelen JoerivanEngelen merged commit cb9337d into issue_#1255_msw_refactoring Oct 28, 2024
3 of 6 checks passed
@JoerivanEngelen JoerivanEngelen deleted the issue_#728_metaswap_grid_agnostic_well branch October 28, 2024 10:25
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.

4 participants