Skip to content

Commit

Permalink
fix new ruff UP031 errors
Browse files Browse the repository at this point in the history
  • Loading branch information
alexfikl authored and inducer committed Aug 18, 2024
1 parent 1b49c59 commit 95d9a40
Show file tree
Hide file tree
Showing 9 changed files with 46 additions and 52 deletions.
2 changes: 1 addition & 1 deletion examples/airfoil3d.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ def deform_wing(p):
mesh_info.set_holes([(0, 0, 0.5)])

mesh = build(mesh_info)
print("%d elements" % len(mesh.elements))
print(f"{len(mesh.elements)} elements")
mesh.write_vtk("airfoil3d.vtk")


Expand Down
2 changes: 1 addition & 1 deletion examples/box-in-box.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ def main():

mesh = build(mesh_info, max_volume=0.06,
volume_constraints=True, attributes=True)
print("%d elements" % len(mesh.elements))
print(f"{len(mesh.elements)} elements")
mesh.write_vtk("box-in-box.vtk")


Expand Down
10 changes: 5 additions & 5 deletions examples/jw_meshtools.py
Original file line number Diff line number Diff line change
Expand Up @@ -104,21 +104,21 @@ def PlotMeshNumbers(p, t, edges=None, pltshow=True):
plt.triplot(p[:, 0], p[:, 1], t[:, 0:3])
# annotate nodes
for i in range(len(p)):
buf = "%i" % (i)
buf = f"{i}"
x = p[i, 0]
y = p[i, 1]
plt.plot(x, y, "ok", markersize=5)
plt.text(x, y, buf, color="r", fontsize=13)

# annotate elements
for n in range(len(t)):
buf = "%i" % (n)
buf = f"{n}"
ps = (p[t[n, 0], :] + p[t[n, 1], :] + p[t[n, 2], :]) / 3.0
plt.text(ps[0], ps[1], buf, color="b", fontsize=9)

if edges != []:
for n in range(len(edges)):
buf = "%i" % (n)
buf = f"{n}"
ps = (p[edges[n][0], :] + p[edges[n][1], :]) / 2.0
plt.text(ps[0], ps[1], buf, color="g", fontsize=11)

Expand Down Expand Up @@ -2255,8 +2255,8 @@ def DoBemBoundary(AllBound, show=True, show_numbers=False):

if show_numbers:
for i in range(len(x)):
buf = " %i" % (Z["first"] + i)
plt.text(x[i], y[i], buf, color="k", fontsize=13)
buf = Z["first"] + i
plt.text(x[i], y[i], f" {buf}", color="k", fontsize=13)
plt.show()

return VecXm, VecB, Curves, D_nodes, N_nodes, I_nodes
Expand Down
2 changes: 1 addition & 1 deletion examples/mesh_ply.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ def main():
builder.set(mi)
mi.set_holes([builder.center()])
mesh = build(mi)
print("%d elements" % len(mesh.elements))
print(f"{len(mesh.elements)} elements")
mesh.write_vtk("out.vtk")


Expand Down
16 changes: 7 additions & 9 deletions examples/write_dolfin.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,31 +8,29 @@ def main():
mesh = triangle.build(info, max_volume=1e-3, min_angle=25)

print(
"""
f"""
<?xml version="1.0" encoding="UTF-8"?>
<dolfin xmlns:dolfin="http://www.fenics.org/dolfin/">
<mesh celltype="triangle" dim="2">
<vertices size="%d">
<vertices size="{len(mesh.points)}">
"""
% len(mesh.points)
)

for i, pt in enumerate(mesh.points):
print('<vertex index="%d" x="%g" y="%g"/>' % (i, pt[0], pt[1]))
print(f'<vertex index="{i}" x="{pt[0]}" y="{pt[1]}"/>')

print(
"""
f"""
</vertices>
<cells size="%d">
<cells size="{len(mesh.elements)}">
"""
% len(mesh.elements)
)

for i, element in enumerate(mesh.elements):
print(
'<triangle index="%d" v0="%d" v1="%d" v2="%d"/>'
% (i, element[0], element[1], element[2])
f'<triangle index="{i}" '
f'v0="{element[0]}" v1="{element[1]}" v2="{element[2]}"/>'
)

print(
Expand Down
47 changes: 22 additions & 25 deletions meshpy/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -118,8 +118,8 @@ def write_neu(self, outfile, bc=None, periodicity=None,
# nodes ---------------------------------------------------------------
outfile.write("NODAL COORDINATES 2.1.2\n")
for i, pt in enumerate(self.points):
outfile.write("%d %s\n" %
(i+1, " ".join(repr(c) for c in pt)))
point = " ".join(repr(c) for c in pt)
outfile.write(f"{i + 1} {point}\n")
outfile.write("ENDOFSECTION\n")

# elements ------------------------------------------------------------
Expand All @@ -130,9 +130,8 @@ def write_neu(self, outfile, bc=None, periodicity=None,
eltype = 6

for i, el in enumerate(self.elements):
outfile.write("%8d%3d%3d %s\n" %
(i+1, eltype, len(el),
"".join("%8d" % (p+1) for p in el)))
element = "".join(f"{p + 1:>8d}" for p in el)
outfile.write(f"{i + 1:>8d}{eltype:>3d}{len(el):>3d} {element}\n")
outfile.write("ENDOFSECTION\n")

# element groups ------------------------------------------------------
Expand All @@ -142,8 +141,11 @@ def write_neu(self, outfile, bc=None, periodicity=None,
grp_elements = list(range(len(self.elements)))
material = 1
flags = 0
outfile.write("GROUP:%11d ELEMENTS:%11d MATERIAL:%11s NFLAGS: %11d\n"
% (1, len(grp_elements), repr(material), flags))
outfile.write(
f"GROUP:{1:>11d} "
f"ELEMENTS:{len(grp_elements):>11d} "
f"MATERIAL:{material!r:>11} "
f"NFLAGS: {flags:>11d}\n")
outfile.write((f"epsilon: {material}\n").rjust(32)) # FIXME
outfile.write("0\n")
outfile.write(_linebreak_list([str(i+1) for i in grp_elements],
Expand Down Expand Up @@ -180,7 +182,7 @@ def write_neu(self, outfile, bc=None, periodicity=None,
face2el.setdefault(face, []).append((ti, fi+1))

else:
raise ValueError("invalid number of dimensions (%d)" % dim)
raise ValueError(f"invalid number of dimensions: {dim}")

# actually output bc sections
if not self.faces.allocated:
Expand Down Expand Up @@ -208,21 +210,16 @@ def write_neu(self, outfile, bc=None, periodicity=None,
# regular BC

bc_name, bc_code = bc[bc_marker]
outfile.write("%32s%8d%8d%8d%8d\n"
% (bc_name,
1, # face BC
len(face_indices),
0, # zero additional values per face,
bc_code)
outfile.write(
f"{bc_name:>32}{1:>8d}{len(face_indices):>8d}"
f"{0:>8d}{bc_code:>8d}\n"
)
else:
# periodic BC

outfile.write("%s%s%8d%8d%8d\n"
% ("periodic", " ".join(repr(p) for p in periods),
len(face_indices),
0, # zero additional values per face,
0)
periods_repr = " ".join(repr(p) for p in periods)
outfile.write(
f"periodic{periods_repr}{len(face_indices):>8d}{0:>8d}{0:>8d}\n"
)

for fi in face_indices:
Expand All @@ -232,8 +229,8 @@ def write_neu(self, outfile, bc=None, periodicity=None,

el_index, el_face_number = adj_el[0]

outfile.write("%10d%5d%5d\n" %
(el_index+1, eltype, el_face_number))
outfile.write(
f"{el_index + 1:>10d}{eltype:>5d}{el_face_number:>5d}\n")

outfile.write("ENDOFSECTION\n")

Expand All @@ -243,8 +240,7 @@ def write_neu(self, outfile, bc=None, periodicity=None,


def dump_array(name, array):
print("array %s: %d elements, %d values per element"
% (name, len(array), array.unit))
print(f"array {name}: {len(array)} elements, {array.unit} values per element")

if len(array) == 0 or array.unit == 0:
return
Expand All @@ -257,6 +253,7 @@ def dump_array(name, array):

for i, entry in enumerate(array):
if isinstance(entry, list):
print(" %d: %s" % (i, ",".join(str(sub) for sub in entry)))
value = ",".join(str(sub) for sub in entry)
print(f" {i}: {value}")
else:
print(" %d: %s" % (i, entry))
print(f" {i}: {entry}")
11 changes: 5 additions & 6 deletions meshpy/geometry.py
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ def mesher_module(self):
import meshpy.tet
return meshpy.tet
else:
raise ValueError("unsupported dimensionality %d" % dim)
raise ValueError(f"unsupported dimensionality {dim}")

def bounding_box(self):
return bounding_box(self.points)
Expand Down Expand Up @@ -260,7 +260,7 @@ def make_box(a, b, subdivisions=None):
facet_markers = [Marker.MINUS_Z, Marker.MINUS_Y, Marker.PLUS_X,
Marker.PLUS_Y, Marker.MINUS_X, Marker.PLUS_Z]
else:
raise ValueError("unsupported dimension count: %d" % len(a))
raise ValueError(f"unsupported dimension count: {len(a)}")

if subdivisions is not None:
if dimensions != 2:
Expand Down Expand Up @@ -509,10 +509,9 @@ def connect_ring(ring1_idx, ring2_idx, marker):
if rz_points[i][0] == 0:
assert len(ring_points) == 1
else:
assert len(ring_points) == len(base_shape), \
("Ring points length (%d) does not "
"match base shape length (%d)"
% (len(ring_points), len(base_shape)))
assert len(ring_points) == len(base_shape), (
f"Ring points length ({len(ring_points)}) does not "
f"match base shape length ({len(base_shape)})")

rings[i] = ring_points

Expand Down
6 changes: 3 additions & 3 deletions meshpy/tet.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,10 +93,10 @@ def dump(self):
for name in ["points"]:
dump_array(name, getattr(self, name))
for ifacet, facet in enumerate(self.faces):
print("facet %d:" % ifacet)
print(f"facet {ifacet}:" % ifacet)
for ipolygon, polygon in enumerate(facet.polygons):
print(" polygon %d: vertices [%s]" %
(ipolygon, ",".join(str(vi) for vi in polygon.vertices)))
vertices = ",".join(str(vi) for vi in polygon.vertices)
print(f" polygon {ipolygon}: vertices [{vertices}]")

def write_vtk(self, filename):
import pyvtk
Expand Down
2 changes: 1 addition & 1 deletion meshpy/triangle.py
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ def build(mesh_info, verbose=False, refinement_func=None, attributes=False,
opts += "q"

if mesh_order is not None:
opts += "o%d" % mesh_order
opts += f"o{mesh_order}"

if verbose:
opts += "VV"
Expand Down

0 comments on commit 95d9a40

Please sign in to comment.