Skip to content

_MeshIndexSet first pass#7149

Open
trexfeathers wants to merge 17 commits into
SciTools:FEATURE_index_setfrom
trexfeathers:mesh-index-set
Open

_MeshIndexSet first pass#7149
trexfeathers wants to merge 17 commits into
SciTools:FEATURE_index_setfrom
trexfeathers:mesh-index-set

Conversation

@trexfeathers

Copy link
Copy Markdown
Contributor

No description provided.

@trexfeathers trexfeathers added Feature: UGRID Type: Feature Branch Highlight this for a feature branch labels Jun 10, 2026
@trexfeathers

Copy link
Copy Markdown
Contributor Author

pre-commit.ci autofix

@trexfeathers trexfeathers mentioned this pull request Jun 10, 2026
4 tasks
@trexfeathers

Copy link
Copy Markdown
Contributor Author

@stephenworsley please can you review the approach I have used with this code, accepting that various TODOs are deferred to #7151. Thanks!

@trexfeathers trexfeathers linked an issue Jun 10, 2026 that may be closed by this pull request
4 tasks
@trexfeathers trexfeathers marked this pull request as ready for review June 10, 2026 15:02
raise NotImplementedError()

def is_view_of(self, other: MeshXY) -> bool:
"""Whether this instance is either itself, or a view of the given :class:`MeshXY`.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Have you considered how this ought to behave when you've sliced or indexed a _MeshIndexSet? If I'm interpreting the code correctly, it looks like you ought to end up with another smaller _MeshIndexSet. In such a case, I could imagine you might want this method to also return True.

I also wonder if it might be worth considering two different methods, one for comparing a _MeshIndexSet to a MeshXY, another for comparing two _MeshIndexSets. I haven't entirely thought through which contexts you might expect to call these methods so I've not come to a conclusion on this myself yet.

Copy link
Copy Markdown
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 intended to be possible, and I've taken some steps to avoid it happening:

case _MeshIndexSet():
# Should not base an index set on another index set - base
# on the original mesh instead.
# TODO: do we need to double-check that self.location
# matches mesh_index_set.location? Any other matching to
# check too?
mesh_index_set = mesh
kwargs = dict(
mesh=mesh_index_set.mesh,
location=mesh_index_set.location,
indices=mesh_index_set.indices[keys],
)

result = [self.to_MeshCoord(location=location, axis=ax) for ax in self.AXES]
return tuple(result)

def is_view_of(self, other: "MeshXY") -> bool:

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Offline conversation with @stephenworsley: is_view_of is not necessary, and any value it might offer is offset by potential confusion. We should remove it.

result_dict = {k: v for k, v in self._members.items() if id(v) in result_ids}
return result_dict

def index(

@trexfeathers trexfeathers Jun 10, 2026

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Offline conversation with @stephenworsley: this concept of mutability only really extends to altering the membership of the Manager, there is no decent way 1 to protect the coordinates/connectivities themselves from modification, since users are free to assign those to their own variables, and/or to modify the arrays within them.

If we're comfortable with this 'insecurity', then we could consider generating new constituent coordinates/connectivities that explicitly share the same NumPy array as the ones on the original Mesh (as opposed to directly using the slicing API, since that explicitly creates a copy). That would allow the MeshIndexSet to be a true view, with live updating, potentially avoiding the weirdness of re-indexing every time a Manager is requested.

Footnotes

  1. I need to read up on Ensure MeshCoord points and bounds always agree with the Mesh (while keeping Mesh mutable) #4757

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Feature: UGRID Type: Feature Branch Highlight this for a feature branch

Projects

Status: No status

Development

Successfully merging this pull request may close these issues.

Create MeshIndexSet class

2 participants