Skip to content

Commit

Permalink
Enable E741 and E226
Browse files Browse the repository at this point in the history
  • Loading branch information
jwallwork23 committed Sep 14, 2024
1 parent be872bf commit 41c7ba4
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 23 deletions.
16 changes: 8 additions & 8 deletions movement/monge_ampere.py
Original file line number Diff line number Diff line change
Expand Up @@ -404,9 +404,9 @@ def __init__(self, mesh, monitor_function, phi_init=None, H_init=None, **kwargs)
self.apply_initial_guess(phi_init, H_init)

# Setup residuals
I = ufl.Identity(self.dim)
self.theta_form = self.monitor * ufl.det(I + self.H_old) * self.dx
self.residual = self.monitor * ufl.det(I + self.H_old) - self.theta
id = ufl.Identity(self.dim)
self.theta_form = self.monitor * ufl.det(id + self.H_old) * self.dx
self.residual = self.monitor * ufl.det(id + self.H_old) - self.theta
psi = firedrake.TestFunction(self.P1)
self._residual_l2_form = psi * self.residual * self.dx
self._norm_l2_form = psi * self.theta * self.dx
Expand Down Expand Up @@ -586,9 +586,9 @@ def __init__(self, mesh, monitor_function, phi_init=None, H_init=None, **kwargs)
self.apply_initial_guess(phi_init, H_init)

# Setup residuals
I = ufl.Identity(self.dim)
self.theta_form = self.monitor * ufl.det(I + self.H_old) * self.dx
self.residual = self.monitor * ufl.det(I + self.H_old) - self.theta
id = ufl.Identity(self.dim)
self.theta_form = self.monitor * ufl.det(id + self.H_old) * self.dx
self.residual = self.monitor * ufl.det(id + self.H_old) - self.theta
psi = firedrake.TestFunction(self.P1)
self._residual_l2_form = psi * self.residual * self.dx
self._norm_l2_form = psi * self.theta * self.dx
Expand Down Expand Up @@ -630,14 +630,14 @@ def equidistributor(self):
if hasattr(self, "_equidistributor"):
return self._equidistributor
n = ufl.FacetNormal(self.mesh)
I = ufl.Identity(self.dim)
id = ufl.Identity(self.dim)
phi, H = firedrake.split(self.phi_and_hessian)
psi, tau = firedrake.TestFunctions(self.V)
F = (
ufl.inner(tau, H) * self.dx
+ ufl.dot(ufl.div(tau), ufl.grad(phi)) * self.dx
- ufl.dot(ufl.dot(tangential(ufl.grad(phi), n), tau), n) * self.ds
- psi * (self.monitor * ufl.det(I + H) - self.theta) * self.dx
- psi * (self.monitor * ufl.det(id + H) - self.theta) * self.dx
)
phi, H = firedrake.TrialFunctions(self.V)

Expand Down
8 changes: 4 additions & 4 deletions movement/spring.py
Original file line number Diff line number Diff line change
Expand Up @@ -151,13 +151,13 @@ def _stiffness_matrix(self):
for e in range(*self.edge_indices):
off = self._edge_offset(e)
i, j = (self._coordinate_offset(v) for v in self.plex.getCone(e))
l = edge_lengths.dat.data_with_halos[off]
length = edge_lengths.dat.data_with_halos[off]
angle = angles.dat.data_with_halos[off]
c = np.cos(angle)
s = np.sin(angle)
c2 = c * c / l
sc = s * c / l
s2 = s * s / l
c2 = c * c / length
sc = s * c / length
s2 = s * s / length
K[2 * i][2 * i] += c2
K[2 * i][2 * i + 1] += sc
K[2 * i][2 * j] += -c2
Expand Down
2 changes: 0 additions & 2 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,7 @@ select = [
]
ignore = [
"E501", # line too long
"E226", # missing whitespace around arithmetic operator
"E402", # module level import not at top of file
"E741", # ambiguous variable name
"F403", # unable to detect undefined names
"F405", # name may be undefined, or defined from star imports
]
Expand Down
18 changes: 9 additions & 9 deletions test/test_spring.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,12 +72,12 @@ def test_boundary_conditions_triangle_all_boundary(self):
"""
mesh = UnitTriangleMesh()
mover = SpringMover(mesh, 1.0, method="lineal")
I = np.eye(2 * mesh.num_vertices())
id = np.eye(2 * mesh.num_vertices())
K = mover._stiffness_matrix()
self.assertFalse(np.allclose(K, I))
self.assertFalse(np.allclose(K, id))
K_bc = mover.assemble_stiffness_matrix()
self.assertFalse(np.allclose(K, K_bc))
self.assertTrue(np.allclose(K_bc, I))
self.assertTrue(np.allclose(K_bc, id))

def test_boundary_conditions_triangle_one_segment(self):
"""
Expand All @@ -88,12 +88,12 @@ def test_boundary_conditions_triangle_one_segment(self):
mesh = UnitTriangleMesh()
mover = SpringMover(mesh, 1.0, method="lineal")
K = mover._stiffness_matrix()
I = np.eye(2 * mesh.num_vertices())
self.assertFalse(np.allclose(K, I))
id = np.eye(2 * mesh.num_vertices())
self.assertFalse(np.allclose(K, id))
bc = DirichletBC(mover.coord_space, 0, 1)
K_bc = mover.assemble_stiffness_matrix(bc)
self.assertFalse(np.allclose(K, K_bc))
self.assertFalse(np.allclose(K_bc, I))
self.assertFalse(np.allclose(K_bc, id))
self.assertTrue(np.allclose(np.where(np.isclose(K, K_bc), I, K_bc), I))

def test_boundary_conditions_1x1_square_all_boundary(self):
Expand All @@ -104,11 +104,11 @@ def test_boundary_conditions_1x1_square_all_boundary(self):
mesh = UnitSquareMesh(1, 1)
mover = SpringMover(mesh, 1.0, method="lineal")
K = mover._stiffness_matrix()
I = np.eye(2 * mesh.num_vertices())
self.assertFalse(np.allclose(K, I))
id = np.eye(2 * mesh.num_vertices())
self.assertFalse(np.allclose(K, id))
K_bc = mover.assemble_stiffness_matrix()
self.assertFalse(np.allclose(K, K_bc))
self.assertTrue(np.allclose(K_bc, I))
self.assertTrue(np.allclose(K_bc, id))


class TestQuantities(unittest.TestCase):
Expand Down

0 comments on commit 41c7ba4

Please sign in to comment.