Skip to content

Commit 07d61f7

Browse files
committed
Fix swarm advection (order=2) crash after adding particles (underworldcode#108)
add_particles_with_coordinates() called PETSc's dm.migrate() directly without invalidating the SwarmVariable _canonical_data caches. The RK2 advection buffer (_X0) retained a stale numpy array with the old particle count, causing a shape mismatch on the next advection call. Add cache invalidation after migrate, mirroring the existing pattern in _recalculate_owner_and_migrate(). Underworld development team with AI support from Claude Code (https://claude.com/claude-code)
1 parent 2c64215 commit 07d61f7

1 file changed

Lines changed: 7 additions & 0 deletions

File tree

src/underworld3/swarm.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3380,6 +3380,13 @@ def add_particles_with_coordinates(self, coordinatesArray) -> int:
33803380
self._remeshed.data[...] = 0
33813381

33823382
self.dm.migrate(remove_sent_points=True)
3383+
3384+
# Invalidate cached data — particle count changed after addNPoints + migrate
3385+
self._particle_coordinates._canonical_data = None
3386+
for var in self._vars.values():
3387+
if hasattr(var, "_canonical_data"):
3388+
var._canonical_data = None
3389+
33833390
return npoints
33843391

33853392
@timing.routine_timer_decorator

0 commit comments

Comments
 (0)