Skip to content

Add FACE to dims to check in _update_particle_states_position#2688

Merged
fluidnumericsJoe merged 1 commit into
mainfrom
bugfix/issue-2687
Jun 19, 2026
Merged

Add FACE to dims to check in _update_particle_states_position#2688
fluidnumericsJoe merged 1 commit into
mainfrom
bugfix/issue-2687

Conversation

@fluidnumericsJoe

Copy link
Copy Markdown
Contributor

Resolves the TODO comment and issue #2687

Description

Checklist

@erikvansebille erikvansebille left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Good catch and solution; only one question below

lon_max = float(ds.uxgrid.node_lon.max())
pset = ParticleSet(fieldset, lon=[lon_max - 0.1], lat=[10.0], z=[0.5], pclass=Particle)

with pytest.raises(GridSearchingError):

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Why does this not throw an ErrorOutOfBounds? Would that not be more similar to how it's done in Sgrid?

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.

The grid search returns a value of GRID_SEARCH_ERROR on the face index when it's not found in the grid; this is done in spatialhash.query()

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.

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.

Why does the Sgrid return a value of grid index -1, corresponding to RIGHT_OUT_OF_BOUNDS ?

GRID_SEARCH_ERROR = -3
LEFT_OUT_OF_BOUNDS = -2
RIGHT_OUT_OF_BOUNDS = -1

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Ah I see; I was confused

We use these LEFT and RIGHT only in the 1d_search:

index = np.where(x < arr[0], LEFT_OUT_OF_BOUNDS, index)
index = np.where(x > arr[-1], RIGHT_OUT_OF_BOUNDS, index)

This is especially useful for z/depth, where users may want to distinguish between a particle moving into the air or into the ground. And it just so happens we can also use it on rectilinear grids in the horizontal, because these use 1d_search

On CurviLinear grids, Xgrid would also not be able to disinguish between LEFT and RIGHT. So your test is fine as is

@fluidnumericsJoe fluidnumericsJoe merged commit ab0adbc into main Jun 19, 2026
18 of 19 checks passed
@fluidnumericsJoe fluidnumericsJoe deleted the bugfix/issue-2687 branch June 19, 2026 17:27
@github-project-automation github-project-automation Bot moved this from Backlog to Done in Parcels development Jun 19, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

Least square interpolators and piece-wise constant face interpolators particles out of bounds

2 participants