Skip to content

Commit

Permalink
test: various fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
jwallwork23 committed Jan 13, 2023
1 parent 3f00fd2 commit 326e5f7
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 9 deletions.
6 changes: 3 additions & 3 deletions movement/monge_ampere.py
Original file line number Diff line number Diff line change
Expand Up @@ -335,11 +335,11 @@ def move(self):
# Update monitor function
self.monitor.interpolate(self.monitor_function(self.mesh))
firedrake.assemble(self.L_P0, tensor=self.volume)
self.volume.assign(self.volume*self.original_volume**(-1))
self.volume.interpolate(self.volume / self.original_volume)
self.mesh.coordinates.assign(self.xi)

# Evaluate normalisation coefficient
self.theta.assign(firedrake.assemble(self.theta_form)*self.total_volume**(-1))
self.theta.assign(firedrake.assemble(self.theta_form) / self.total_volume)

# Check convergence criteria
minmax, residual, equi = self.diagnostics
Expand Down Expand Up @@ -470,7 +470,7 @@ def monitor(snes, i, rnorm):
update_monitor(cursol)
self.mesh.coordinates.assign(self.x)
firedrake.assemble(self.L_P0, tensor=self.volume)
self.volume.assign(self.volume/self.original_volume)
self.volume.interpolate(self.volume/self.original_volume)
self.mesh.coordinates.assign(self.xi)
minmax, residual, equi = self.diagnostics
PETSc.Sys.Print(f"{i:4d}"
Expand Down
13 changes: 8 additions & 5 deletions test/test_smoothing.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
from firedrake import *
from movement import *
import numpy as np
import os
import pytest


Expand All @@ -26,7 +28,7 @@ def test_forced(method, num_timesteps, plot=False, test=True):
T = 1.0 # Forcing period

# Construct mesh and mover
mesh = firedrake.SquareMesh(n, n, 2)
mesh = SquareMesh(n, n, 2)
V = mesh.coordinates.function_space()
coords = mesh.coordinates.dat.data.copy()
if method == 'laplacian':
Expand All @@ -36,7 +38,7 @@ def update_forcings(t):
"""
Sinusoidal forcing on the top boundary.
"""
for i in firedrake.DirichletBC(V, 0, 4).nodes:
for i in DirichletBC(V, 0, 4).nodes:
mover.f.dat.data[i][1] += A*np.sin(2*np.pi*t/T)*np.sin(np.pi*coords[i][0])

# Move the mesh
Expand All @@ -51,15 +53,16 @@ def update_forcings(t):
import matplotlib.pyplot as plt

fig, axes = plt.subplots()
firedrake.triplot(mover.mesh, axes=axes)
triplot(mover.mesh, axes=axes)
axes.axis(False)
plt.tight_layout()
plt.savefig(f"plots/mesh_{method}.png")

# Check as expected
if test:
expected = np.load("data/forced_mesh_laplacian.npy")
assert np.allclose(new_coords, expected)
pwd = os.path.dirname(__file__)
fname = os.path.join(pwd, "data", "forced_mesh_laplacian.npy")
assert np.allclose(new_coords, np.load(fname))
return mover


Expand Down
5 changes: 4 additions & 1 deletion test/test_spring.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import firedrake
from movement import SpringMover
import numpy as np
import os
import pytest


Expand Down Expand Up @@ -96,7 +97,9 @@ def update_forcings(t):

# Check as expected
if test:
expected = coords if np.isclose(time, 0.0) else np.load(f"data/forced_mesh_lineal_{it}.npy")
pwd = os.path.dirname(__file__)
fname = os.path.join(pwd, "data", f"forced_mesh_lineal_{it}.npy")
expected = coords if np.isclose(time, 0.0) else np.load(fname)
assert np.allclose(new_coords, expected)
return mover

Expand Down

0 comments on commit 326e5f7

Please sign in to comment.