Skip to content

Commit

Permalink
#58: Add displacement attribute to LaplacianSmoother
Browse files Browse the repository at this point in the history
  • Loading branch information
jwallwork23 committed Feb 29, 2024
1 parent 0e608db commit 3cb5cb4
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 2 deletions.
5 changes: 3 additions & 2 deletions demos/laplacian_smoothing.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,6 @@ def update_forcings(t):


# We are now able to apply the mesh movement method. This works just as before. ::
# TODO: displacement

time = 0.0
fig, axes = plt.subplots(ncols=4, nrows=3, figsize=(12, 10))
Expand All @@ -94,6 +93,8 @@ def update_forcings(t):

# Move the mesh and calculate the mesh speed
mover.move(t, update_forcings=update_forcings, fixed_boundaries=[1, 2, 3])
displacement = np.linalg.norm(mover.displacement)
print(f"time = {t:.1f} s, displacement = {displacement:.2f} m")

# Plot the current mesh, adding a time label
ax = axes[idx // 4, idx % 4]
Expand All @@ -114,6 +115,6 @@ def update_forcings(t):
coord_data = mover.mesh.coordinates.dat.data
linf_error = np.max(np.abs(coord_data - coord_data_init))
print(f"l_infinity error: {linf_error:.3f} m")
assert linf_error < 0.01
assert np.isclose(linf_error, 0.0)

# This tutorial can be downloaded as a `Python script <laplacian_smoothing.py>`__.
4 changes: 4 additions & 0 deletions movement/laplacian_smoothing.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import ufl
import movement.solver_parameters as solver_parameters
from movement.mover import PrimeMover
import numpy as np


__all__ = ["LaplacianSmoother"]
Expand All @@ -20,6 +21,7 @@ def __init__(self, mesh, timestep, **kwargs):
assert timestep > 0.0
self.dt = timestep
self.f = firedrake.Function(self.coord_space)
self.displacement = np.zeros(self.mesh.num_vertices())

@PETSc.Log.EventDecorator()
def _setup_solver(self, fixed_boundaries=[]):
Expand Down Expand Up @@ -56,5 +58,7 @@ def move(self, time, update_forcings=None, fixed_boundaries=[]):
self._solver.solve()

# Update mesh coordinates
coords = self._x.dat.data_with_halos.copy()
self._x.dat.data_with_halos[:] += self.v.dat.data_with_halos * self.dt
self.mesh.coordinates.assign(self._x)
self.displacement = self.mesh.coordinates.dat.data_with_halos - coords

0 comments on commit 3cb5cb4

Please sign in to comment.