Skip to content

Commit 551cf3a

Browse files
Merge pull request #2426 from Parcels-code/particle_particle_interaction_v4
Making particle-particle interaction tutorial v4-compatible
2 parents ea9517a + aee2249 commit 551cf3a

File tree

18 files changed

+430
-1971
lines changed

18 files changed

+430
-1971
lines changed

docs/user_guide/examples/tutorial_interaction.ipynb

Lines changed: 428 additions & 0 deletions
Large diffs are not rendered by default.

docs/user_guide/examples_v3/tutorial_interaction.ipynb

Lines changed: 0 additions & 433 deletions
This file was deleted.

docs/user_guide/index.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ examples/tutorial_statuscodes.ipynb
5454
examples/tutorial_gsw_density.ipynb
5555
examples/tutorial_Argofloats.ipynb
5656
examples/tutorial_diffusion.ipynb
57+
examples/tutorial_interaction.ipynb
5758
```
5859

5960
```{toctree}
@@ -65,7 +66,6 @@ examples/tutorial_interpolation.ipynb
6566
```
6667

6768
<!-- examples/tutorial_particle_field_interaction.ipynb -->
68-
<!-- examples/tutorial_interaction.ipynb -->
6969
<!-- examples/tutorial_analyticaladvection.ipynb -->
7070
<!-- examples/tutorial_kernelloop.ipynb -->
7171

docs/user_guide/v4-migration.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ Version 4 of Parcels is unreleased at the moment. The information in this migrat
1414
- The `particle` argument in the Kernel signature has been renamed to `particles`.
1515
- `math` functions should be replaced with array compatible equivalents (e.g., `math.sin` -> `np.sin`). Instead of `ParcelsRandom` you should use numpy's random functions.
1616
- `particle.depth` has been changed to `particles.z` to be consistent with the [CF conventions for trajectory data](https://cfconventions.org/cf-conventions/cf-conventions.html#trajectory-data), and to make Parcels also generalizable to atmospheric contexts.
17+
- The `InteractionKernel` class has been removed. Since normal Kernels now have access to _all_ particles, particle-particle interaction can be performed within normal Kernels.
1718

1819
## FieldSet
1920

src/parcels/_core/particleset.py

Lines changed: 0 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -53,9 +53,6 @@ class ParticleSet:
5353
Optional list of "trajectory" values (integers) for the particle IDs
5454
partition_function :
5555
Function to use for partitioning particles over processors. Default is to use kMeans
56-
periodic_domain_zonal :
57-
Zonal domain size, used to apply zonally periodic boundaries for particle-particle
58-
interaction. If None, no zonally periodic boundaries are applied
5956
6057
Other Variables can be initialised using further arguments (e.g. v=... for a Variable named 'v')
6158
"""
@@ -74,7 +71,6 @@ def __init__(
7471
self._data = None
7572
self._repeat_starttime = None
7673
self._kernel = None
77-
self._interaction_kernel = None
7874

7975
self.fieldset = fieldset
8076
lon = np.empty(shape=0) if lon is None else _convert_to_flat_array(lon)
@@ -228,8 +224,6 @@ def add(self, particles):
228224
for d in self._data:
229225
self._data[d] = np.concatenate((self._data[d], particles._data[d]))
230226

231-
# Adding particles invalidates the neighbor search structure.
232-
self._dirty_neighbor = True
233227
return self
234228

235229
def __iadd__(self, particles):
@@ -256,44 +250,6 @@ def remove_indices(self, indices):
256250
for d in self._data:
257251
self._data[d] = np.delete(self._data[d], indices, axis=0)
258252

259-
def _active_particles_mask(self, time, dt):
260-
active_indices = (time - self._data["time"]) / dt >= 0
261-
non_err_indices = np.isin(self._data["state"], [StatusCode.Success, StatusCode.Evaluate])
262-
active_indices = np.logical_and(active_indices, non_err_indices)
263-
self._active_particle_idx = np.where(active_indices)[0]
264-
return active_indices
265-
266-
def _compute_neighbor_tree(self, time, dt):
267-
active_mask = self._active_particles_mask(time, dt)
268-
269-
self._values = np.vstack(
270-
(
271-
self._data["z"],
272-
self._data["lat"],
273-
self._data["lon"],
274-
)
275-
)
276-
if self._dirty_neighbor:
277-
self._neighbor_tree.rebuild(self._values, active_mask=active_mask)
278-
self._dirty_neighbor = False
279-
else:
280-
self._neighbor_tree.update_values(self._values, new_active_mask=active_mask)
281-
282-
def _neighbors_by_index(self, particle_idx):
283-
neighbor_idx, distances = self._neighbor_tree.find_neighbors_by_idx(particle_idx)
284-
neighbor_idx = self._active_particle_idx[neighbor_idx]
285-
mask = neighbor_idx != particle_idx
286-
neighbor_idx = neighbor_idx[mask]
287-
if "horiz_dist" in self._data._ptype.variables:
288-
self._data["vert_dist"][neighbor_idx] = distances[0, mask]
289-
self._data["horiz_dist"][neighbor_idx] = distances[1, mask]
290-
return True # TODO fix for v4 ParticleDataIterator(self.particledata, subset=neighbor_idx)
291-
292-
def _neighbors_by_coor(self, coor):
293-
neighbor_idx = self._neighbor_tree.find_neighbors_by_coor(coor)
294-
neighbor_ids = self._data["trajectory"][neighbor_idx]
295-
return neighbor_ids
296-
297253
def populate_indices(self):
298254
"""Pre-populate guesses of particle ei (element id) indices"""
299255
for i, grid in enumerate(self.fieldset.gridset):
@@ -359,13 +315,6 @@ def Kernel(self, pyfunc):
359315
pyfuncs=[pyfunc],
360316
)
361317

362-
def InteractionKernel(self, pyfunc_inter):
363-
from parcels.interaction.interactionkernel import InteractionKernel
364-
365-
if pyfunc_inter is None:
366-
return None
367-
return InteractionKernel(self.fieldset, self._ptype, pyfunc=pyfunc_inter)
368-
369318
def data_indices(self, variable_name, compare_values, invert=False):
370319
"""Get the indices of all particles where the value of `variable_name` equals (one of) `compare_values`.
371320

src/parcels/interaction/__init__.py

Lines changed: 0 additions & 1 deletion
This file was deleted.

src/parcels/interaction/interactionkernel.py

Lines changed: 0 additions & 216 deletions
This file was deleted.

src/parcels/interaction/neighborsearch/__init__.py

Lines changed: 0 additions & 19 deletions
This file was deleted.

0 commit comments

Comments
 (0)