From 41c7ba490679b4f9ac1eaeb9cb0ecfa047c74203 Mon Sep 17 00:00:00 2001 From: Joe Wallwork Date: Sat, 14 Sep 2024 12:02:59 +0100 Subject: [PATCH] Enable E741 and E226 --- movement/monge_ampere.py | 16 ++++++++-------- movement/spring.py | 8 ++++---- pyproject.toml | 2 -- test/test_spring.py | 18 +++++++++--------- 4 files changed, 21 insertions(+), 23 deletions(-) diff --git a/movement/monge_ampere.py b/movement/monge_ampere.py index 9ea3ada..48289b4 100644 --- a/movement/monge_ampere.py +++ b/movement/monge_ampere.py @@ -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 @@ -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 @@ -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) diff --git a/movement/spring.py b/movement/spring.py index 92a597a..49e1b08 100644 --- a/movement/spring.py +++ b/movement/spring.py @@ -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 diff --git a/pyproject.toml b/pyproject.toml index 5fc0d58..e84de87 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -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 ] diff --git a/test/test_spring.py b/test/test_spring.py index 4a55998..78945ca 100644 --- a/test/test_spring.py +++ b/test/test_spring.py @@ -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): """ @@ -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): @@ -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):