Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 1 addition & 5 deletions src/underworld3/checkpoint/disk_snapshot.py
Original file line number Diff line number Diff line change
Expand Up @@ -689,11 +689,7 @@ def _read_swarm_from_sidecar(swarm, sidecar_path: str) -> None:

# Invalidate canonical-data caches so subsequent var.data reads
# re-resolve to the rebuilt PETSc fields.
if hasattr(swarm._particle_coordinates, "_canonical_data"):
swarm._particle_coordinates._canonical_data = None
for var in swarm._vars.values():
if hasattr(var, "_canonical_data"):
var._canonical_data = None
swarm._invalidate_canonical_data()

# Restore counted as a population change (matches in-memory path).
swarm._population_generation += 1
Expand Down
8 changes: 6 additions & 2 deletions src/underworld3/function/_function.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -610,7 +610,9 @@ def _project_to_work_variable(expr, mesh, smoothing=1e-6):
)
projector.uw_function = flat_source
projector.smoothing = smoothing
projector.solve(zero_init_guess=False)
# _force_setup=True: rebuild solver state to avoid stale cached
# projector after Stokes/DM modifications (issue #215, Bug 2).
projector.solve(zero_init_guess=False, _force_setup=True)
Comment on lines +613 to +615

# Fan flat result back to the tensor work variable
for idx in range(n_components):
Expand All @@ -637,7 +639,9 @@ def _project_to_work_variable(expr, mesh, smoothing=1e-6):

projector.uw_function = scalar_expr
projector.smoothing = smoothing
projector.solve(zero_init_guess=False)
# _force_setup=True: rebuild solver state to avoid stale cached
# projector after Stokes/DM modifications (issue #215, Bug 2).
projector.solve(zero_init_guess=False, _force_setup=True)

return work_var

Expand Down
20 changes: 11 additions & 9 deletions src/underworld3/swarm.py
Original file line number Diff line number Diff line change
Expand Up @@ -1031,6 +1031,12 @@ def _update(self):

return

# TODO(BUG): Stale proxy DM after swarm data write
# _update() marks proxy as stale, but _update_proxy_if_stale() (lazy
# re-interpolation) only fires when material.sym is accessed. Code that
# reads the proxy MeshVariable DM directly (e.g. a Projection solver
# evaluating its uw_function at quadrature points) gets stale data.
# See GitHub issue #215 (Bug 3).
def _update_proxy_if_stale(self):
"""
Actually update the proxy mesh variable if it's marked as stale.
Expand Down Expand Up @@ -2643,6 +2649,9 @@ def _invalidate_canonical_data(self):
for var in list(self._vars.values()):
if hasattr(var, "_canonical_data"):
var._canonical_data = None
# Mark proxy as stale — particle positions or values changed
if hasattr(var, "_update"):
var._update()

# Invalidate cached spatial index
self._kdtree = None
Expand Down Expand Up @@ -3571,10 +3580,7 @@ def add_particles_with_coordinates(self, coordinatesArray) -> int:
self.dm.migrate(remove_sent_points=True)

# Invalidate cached data — particle count changed after addNPoints + migrate
self._particle_coordinates._canonical_data = None
for var in self._vars.values():
if hasattr(var, "_canonical_data"):
var._canonical_data = None
self._invalidate_canonical_data()

# Informational: addNPoints + direct dm.migrate path doesn't go
# through Swarm.migrate, so bump explicitly.
Expand Down Expand Up @@ -4204,11 +4210,7 @@ def apply_snapshot_payload(self, payload: dict) -> None:

# Invalidate canonical-data caches — the underlying arrays
# have been reallocated by the addNPoints path.
if hasattr(self._particle_coordinates, "_canonical_data"):
self._particle_coordinates._canonical_data = None
for var in self._vars.values():
if hasattr(var, "_canonical_data"):
var._canonical_data = None
self._invalidate_canonical_data()

# The raw PETSc primitives used above (removePoint loop +
# addNPoints + direct field writes) deliberately bypass
Expand Down
Loading
Loading