Skip to content

Issue #1519 weights in label arrays #1520

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

Merged
merged 12 commits into from
May 2, 2025

Conversation

JoerivanEngelen
Copy link
Contributor

@JoerivanEngelen JoerivanEngelen commented May 1, 2025

Fixes #1519 and #668

Description

Implements the following:

  • Provide weights to xugrid -> PyMetis calls
  • Also call PyMetis for structured grids, instead of the naive uniform splitter without options for weighting grids.
  • Change name of label array to "label" instead of "idomain"
  • Move get_label_array to imod.prepare.create_partition_labels, and add this to public API. Calling the old get_label_array results in a DeprecationWarning, after which args are passed on to imod.prepare.create_partition_labels.
  • Fix bug where arrays provided to exchange creator do not have to be named "idomain" anymore. They are now renamed to enforce a name.
  • Pin xarray to 2025.3.0 to avoid error and HFB package with __repr__

I was still on the fence about the latter, on one hand, I like that these changes as they keep the code paths very similar and support providing weights, on the other hand, the way Metis is now called, it results in sloppy looking label arrays for structured grids.

For this trivial example with idomain equal to one everywhere. We had this:

image

and with METIS we get this:

image

That is still somewhat acceptable, though confusing as it looks sloppy, so it deserves some extra explanation.
Perhaps manually create a simple label array here is better?

For the hondsrug example, which is not a perfect square model, METIS accounts for the fact that the model domain is rectangular, which the previous implementation does not:

image

So in the end I think it is an improvement

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

@JoerivanEngelen JoerivanEngelen requested review from Manangka and Huite May 1, 2025 16:24
@JoerivanEngelen JoerivanEngelen marked this pull request as ready for review May 2, 2025 12:45
Copy link

sonarqubecloud bot commented May 2, 2025

of ``Ugrid2d.from_structured`` if available, to save some costly
conversions.
"""
weights_uda = as_ugrid_dataarray(weights)
Copy link
Collaborator

Choose a reason for hiding this comment

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

I'm wondering what the performance impact is of converting this. Have you tested it? Models that are being split are usually big

Copy link
Contributor Author

@JoerivanEngelen JoerivanEngelen May 2, 2025

Choose a reason for hiding this comment

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

Good point. I've tested this before, as we also convert structured grids to unstructured grids it for the horizontal flow barrier package (to snap to edges). There, it posed a performance hit as the conversion had to be called multiple times (the LHM has ~20 HFB packages). That's why as_ugrid_dataarray caches the result of this conversion, so it doesn't have to be converted multiple times. I think for the LHM (a very large model > 20M cells), it is bearable to call the conversion once. It takes about a minute for that.

I also call as_ugrid_dataarray here, as it might save some performance in the case users also work with a HFB package.

@JoerivanEngelen JoerivanEngelen merged commit 9bf5286 into master May 2, 2025
7 checks passed
@JoerivanEngelen JoerivanEngelen deleted the issue_#1519_weights_in_label_arrays branch May 2, 2025 13:52
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.

[FEATURE] - Allow users to set weights when creating label arrays for partitioning
2 participants