Skip to content

Commit

Permalink
Enable B and C linting rules (#123)
Browse files Browse the repository at this point in the history
Closes #72.
  • Loading branch information
ddundo authored Sep 10, 2024
1 parent ee99ed1 commit 05323dc
Show file tree
Hide file tree
Showing 8 changed files with 18 additions and 17 deletions.
2 changes: 1 addition & 1 deletion movement/math.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ def equation_of_hyperplane(*points):
try:
hyperplane = Hyperplane(*(Point(points[i]) for i in indices[:dim]))

def equation(*xyz):
def equation(*xyz, hyperplane=hyperplane):
return hyperplane.distance(Point(xyz))

return equation
Expand Down
7 changes: 4 additions & 3 deletions movement/monge_ampere.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,8 +85,8 @@ def MongeAmpereMover(mesh, monitor_function, method="relaxation", **kwargs):
}
try:
return implemented_methods[method](mesh, monitor_function, **kwargs)
except KeyError:
raise ValueError(f"Method '{method}' not recognised.")
except KeyError as e:
raise ValueError(f"Method '{method}' not recognised.") from e


def tangential(v, n):
Expand Down Expand Up @@ -156,7 +156,8 @@ def __init__(self, mesh, monitor_function, **kwargs):
if len(self._all_boundary_segments) == 0:
warn(
"Provided mesh has no boundary segments with Physical ID tags. If the "
"boundaries aren't fully periodic then this will likely cause errors."
"boundaries aren't fully periodic then this will likely cause errors.",
stacklevel=1,
)
elif (
len(self.fixed_boundary_segments) == 1
Expand Down
5 changes: 3 additions & 2 deletions movement/mover.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,8 @@ def __init__(
if not raise_convergence_errors:
warn(
f"{type(self)}.move called with raise_convergence_errors=False."
" Beware: this option can produce poor quality meshes!"
" Beware: this option can produce poor quality meshes!",
stacklevel=1,
)
self.raise_convergence_errors = raise_convergence_errors
self.dim = self.mesh.topological_dimension()
Expand All @@ -65,7 +66,7 @@ def __init__(
self._local_coordinates_vec = dm_coords.createLocalVec()
self._update_plex_coordinates()
except ValueError:
warn("Cannot update DMPlex coordinates for periodic meshes.")
warn("Cannot update DMPlex coordinates for periodic meshes.", stacklevel=1)
self._local_coordinates_vec = None

self.dx = firedrake.dx(domain=self.mesh, degree=quadrature_degree)
Expand Down
10 changes: 4 additions & 6 deletions movement/spring.py
Original file line number Diff line number Diff line change
Expand Up @@ -186,10 +186,9 @@ def assemble_stiffness_matrix(self, boundary_conditions=None):
:returns: the stiffness matrix with boundary conditions applied
:rtype: :class:`numpy.ndarray`
"""
if not boundary_conditions:
boundary_conditions = firedrake.DirichletBC(
self.coord_space, 0, "on_boundary"
)
boundary_conditions = boundary_conditions or firedrake.DirichletBC(
self.coord_space, 0, "on_boundary"
)
if isinstance(boundary_conditions, firedrake.DirichletBC):
boundary_conditions = [boundary_conditions]
assert isinstance(boundary_conditions, Iterable)
Expand All @@ -208,8 +207,7 @@ def assemble_stiffness_matrix(self, boundary_conditions=None):
tags = boundary_condition.sub_domain
if tags == "on_boundary":
tags = bnd.unique_markers
if not isinstance(tags, Iterable):
tags = [tags]
tags = [tags] if not isinstance(tags, Iterable) else tags
if not set(tags).issubset(set(bnd.unique_markers)):
raise ValueError(f"{tags} contains invalid boundary tags.")
subsets = np.array([bnd.subset(tag).indices for tag in tags]).flatten()
Expand Down
2 changes: 1 addition & 1 deletion movement/tangling.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,5 +64,5 @@ def check(self):
msg = f"Mesh has {num_tangled} tangled element{plural}."
if self.raise_error:
raise ValueError(msg)
warnings.warn(msg)
warnings.warn(msg, stacklevel=1)
return num_tangled
4 changes: 2 additions & 2 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,8 @@ line-length = 88

[tool.ruff.lint]
select = [
# "B", # flake8-bugbear TODO: enable this (#72)
# "C", # mccabe complexity TODO: enable this (#72)
"B", # flake8-bugbear
"C", # mccabe complexity
"E", "W", # Pycodestyle
"F", # Pyflakes
"I", # isort
Expand Down
2 changes: 1 addition & 1 deletion test/monitors.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,6 @@ def ring_monitor(mesh):
beta = Constant(200.0) # width
gamma = Constant(0.15) # radius
dim = mesh.geometric_dimension()
xyz = SpatialCoordinate(mesh) - as_vector([0.5]*dim)
xyz = SpatialCoordinate(mesh) - as_vector([0.5] * dim)
r = dot(xyz, xyz)
return Constant(1.0) + alpha / cosh(beta * (r - gamma)) ** 2
3 changes: 2 additions & 1 deletion test/test_forced_movement.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,10 @@ def move(
mesh,
fixed_boundary_tags=None,
moving_boundary_tags=None,
vector=[1, 0],
vector=None,
**kwargs,
):
vector = vector or [1, 0]
mover = self.mover(mesh)
bcs = []
if fixed_boundary_tags:
Expand Down

0 comments on commit 05323dc

Please sign in to comment.