diff --git a/doc/conf.py b/doc/conf.py index 749fa98..9b6b1ab 100644 --- a/doc/conf.py +++ b/doc/conf.py @@ -1,5 +1,3 @@ -# -*- coding: utf-8 -*- -# # MeshPy documentation build configuration file, created by # sphinx-quickstart on Tue Jul 1 12:35:03 2008. # @@ -46,7 +44,7 @@ # General substitutions. project = "MeshPy" -copyright = u"2008, Andreas Klöckner" +copyright = "2008, Andreas Klöckner" # The default replacements for |version| and |release|, also used in various diff --git a/examples/box-in-box.py b/examples/box-in-box.py index 61b1ff4..8129ec7 100644 --- a/examples/box-in-box.py +++ b/examples/box-in-box.py @@ -24,16 +24,14 @@ def main(): # region attributes mesh_info.regions.resize(1) - mesh_info.regions[0] = ( + mesh_info.regions[0] = [ # point in region - [0, 0, 0] - + [ - # region number - 1, - # max volume in region - 0.001, - ] - ) + 0, 0, 0, + # region number + 1, + # max volume in region + 0.001, + ] mesh = build(mesh_info, max_volume=0.06, volume_constraints=True, attributes=True) diff --git a/examples/jw_meshtools.py b/examples/jw_meshtools.py index ed56d31..6ad7c37 100644 --- a/examples/jw_meshtools.py +++ b/examples/jw_meshtools.py @@ -206,7 +206,7 @@ def MakeSurfaceMesh(xstr, ystr, zstr, u0, u1, v0, v1, n1, n2): max_len = max([np.max(np.diff(all_u)), np.max(np.diff(all_v))]) # make mesh - uv_points = np.array(uv_bound + [uv_bound[0]]) + uv_points = np.array([*uv_bound, uv_bound[0]]) p1, v1 = PointSegments(uv_points) p_uv, elements, bou, li_bou = DoTriMesh(p1, v1, edge_length=max_len, show=False) @@ -302,9 +302,9 @@ def MakeSphere(P0, R, mesh_len, epsilon=1e-8, type="cart"): if type == "cart": # make part of the sphere - xstr = "%g*np.cos(u)*np.sin(v)" % (R) - ystr = "%g*np.sin(u)*np.sin(v)" % (R) - zstr = "%g*np.cos(v)" % (R) + xstr = f"{R:g}*np.cos(u)*np.sin(v)" + ystr = f"{R:g}*np.sin(u)*np.sin(v)" + zstr = f"{R:g}*np.cos(v)" Nu = int(2 * np.pi * R / mesh_len) pp, tt = MakeSurfaceMesh( xstr, ystr, zstr, 0, 2 * np.pi, np.pi / 4.0, np.pi / 2.0, Nu, int(Nu / 3.0) @@ -350,9 +350,9 @@ def MakeSphere(P0, R, mesh_len, epsilon=1e-8, type="cart"): else: # make part of the sphere - xstr = "%g*np.cos(u)*np.sin(v)" % (R) - ystr = "%g*np.sin(u)*np.sin(v)" % (R) - zstr = "%g*np.cos(v)" % (R) + xstr = f"{R:g}*np.cos(u)*np.sin(v)" + ystr = f"{R:g}*np.sin(u)*np.sin(v)" + zstr = f"{R:g}*np.cos(v)" Nu = int(2.0 * np.pi * R / mesh_len) pn, tn = MakeSurfaceMesh( xstr, ystr, zstr, 0, 2.0 * np.pi, 0, np.pi, Nu, int(Nu / 3.0) @@ -867,7 +867,7 @@ def FindBoundaryElement(t, Seg, BoundE): # print("Boundary Segment ",Seg," Boundary Element ",t[BoundE[i]]) # sort in a way that the first two indices are boundary indices # main indices first - ThirdIndex = list(set(t[BoundE[i], 0:3]) - set(Seg[0:2]))[0] + ThirdIndex = next(set(t[BoundE[i], 0:3]) - set(Seg[0:2])) dbllist = list(t[BoundE[i], 0:3]) * 2 kk = 1 + dbllist.index(ThirdIndex) MainIndices = dbllist[kk : kk + 3] @@ -1400,7 +1400,7 @@ def ConnectBoundary(boundary_segments, Pall, pstart=None): # indj gives the position of the segment in allseg indj = nodes.index(indices[j]) # find the number of boundary the node belongs to - this_boundary = (np.where((np.array(boundaries) <= indj))[0])[-1] + this_boundary = (np.where(np.array(boundaries) <= indj)[0])[-1] if not flag_sorted[this_boundary]: # define the indices for slicing diff --git a/examples/tet-size-control.py b/examples/tet-size-control.py index 5853fb2..efe720b 100644 --- a/examples/tet-size-control.py +++ b/examples/tet-size-control.py @@ -27,11 +27,11 @@ def add_to_all_vertex_indices(facets, increment): return [[pt + increment for pt in facet] for facet in facets] -mesh_info.set_facets( - [[0, 1, 2, 3]] # base - + box_without_minus_z # first box - + add_to_all_vertex_indices(box_without_minus_z, 4) # second box -) +mesh_info.set_facets([ + [0, 1, 2, 3], # base + *box_without_minus_z, # first box + *add_to_all_vertex_indices(box_without_minus_z, 4) # second box +]) # set the volume properties -- this is where the tet size constraints are mesh_info.regions.resize(2) @@ -50,7 +50,7 @@ def add_to_all_vertex_indices(facets, increment): 1e-2, # max tet volume in region ] -mesh = build(mesh_info, area_constraints=True) +mesh = build(mesh_info, volume_constraints=True) # this is a no-op, but it shows how to access the output data for point in mesh.points: diff --git a/examples/tri-refinement-spec.py b/examples/tri-refinement-spec.py index 16f7f5e..a5c27e7 100644 --- a/examples/tri-refinement-spec.py +++ b/examples/tri-refinement-spec.py @@ -31,7 +31,7 @@ def main(): # info.regions.resize(1) # points [x,y] in region, + region number, + regional area constraints - info.regions[0] = [0, 0] + [1, 0.05] + info.regions[0] = [0, 0, 1, 0.05] mesh = triangle.build(info, volume_constraints=True, max_volume=0.1) diff --git a/meshpy/common.py b/meshpy/common.py index 52b891c..9f9b040 100644 --- a/meshpy/common.py +++ b/meshpy/common.py @@ -87,9 +87,9 @@ def write_neu(self, outfile, bc=None, periodicity=None, # header -------------------------------------------------------------- outfile.write("CONTROL INFO 2.1.2\n") outfile.write("** GAMBIT NEUTRAL FILE\n") - outfile.write("%s\n" % description) - outfile.write("PROGRAM: MeshPy VERSION: %s\n" % version) - outfile.write("%s\n" % datetime.now().ctime()) + outfile.write(f"{description}\n") + outfile.write(f"PROGRAM: MeshPy VERSION: {version}\n") + outfile.write(f"{datetime.now().ctime()}\n") bc_markers = list(bc.keys()) if periodicity: @@ -144,7 +144,7 @@ def write_neu(self, outfile, bc=None, periodicity=None, flags = 0 outfile.write("GROUP:%11d ELEMENTS:%11d MATERIAL:%11s NFLAGS: %11d\n" % (1, len(grp_elements), repr(material), flags)) - outfile.write(("epsilon: %s\n" % material).rjust(32)) # FIXME + 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], pad=8) diff --git a/meshpy/gmsh.py b/meshpy/gmsh.py index 39e9e0b..8deb369 100644 --- a/meshpy/gmsh.py +++ b/meshpy/gmsh.py @@ -1,6 +1,6 @@ from warnings import warn -from gmsh_interop.runner import * # noqa: F403, F401 +from gmsh_interop.runner import * # noqa: F403 warn("meshpy.gmsh is deprecated. Use gmsh_interop.runner instead.", diff --git a/meshpy/gmsh_reader.py b/meshpy/gmsh_reader.py index e9ae38c..3fb891a 100644 --- a/meshpy/gmsh_reader.py +++ b/meshpy/gmsh_reader.py @@ -1,6 +1,6 @@ from warnings import warn -from gmsh_interop.reader import * # noqa: F403, F401 +from gmsh_interop.reader import * # noqa: F403 warn("meshpy.gmsh_reader is deprecated. Use gmsh_interop.reader instead.", diff --git a/meshpy/naca.py b/meshpy/naca.py index 4543dde..3f15c31 100644 --- a/meshpy/naca.py +++ b/meshpy/naca.py @@ -133,7 +133,7 @@ def explain(*s): def explain(*s): pass - explain("Airfoil: NACA-%s" % naca_digits) + explain(f"Airfoil: NACA-{naca_digits}") if sharp_trailing_edge: explain("Sharp trailing edge") @@ -259,7 +259,7 @@ def main(): verbose=options.verbose) if options.output is None: - options.output = "naca-%s.dat" % digits + options.output = f"naca-{digits}.dat" print("Output file:", options.output) write_points(points, options.output) diff --git a/meshpy/ply.py b/meshpy/ply.py index 8022f90..2eb5ffd 100644 --- a/meshpy/ply.py +++ b/meshpy/ply.py @@ -38,7 +38,7 @@ def make_parser(it): .split()): return parse_int else: - raise ValueError("unknown type '%s'" % tp) + raise ValueError(f"unknown type '{tp}'") def parse_ply(name): diff --git a/meshpy/tools.py b/meshpy/tools.py index c335342..700d903 100644 --- a/meshpy/tools.py +++ b/meshpy/tools.py @@ -16,7 +16,7 @@ def get_refined_face(a, b): try: face_points = face_point_dict[a, b] except KeyError: - a_pt, b_pt = [points[idx] for idx in [a, b]] + a_pt, b_pt = (points[idx] for idx in (a, b)) dx = (b_pt - a_pt)/factor # build subdivided facet @@ -41,13 +41,13 @@ def get_refined_face(a, b): return face_points for a, b, c in elements: - a_pt, b_pt, c_pt = [points[idx] for idx in [a, b, c]] + a_pt, b_pt, c_pt = (points[idx] for idx in (a, b, c)) dr = (b_pt - a_pt)/factor ds = (c_pt - a_pt)/factor - ab_refined, bc_refined, ac_refined = [ + ab_refined, bc_refined, ac_refined = ( get_refined_face(*pt_indices) - for pt_indices in [(a, b), (b, c), (a, c)]] + for pt_indices in [(a, b), (b, c), (a, c)]) el_point_dict = {} diff --git a/meshpy/triangle.py b/meshpy/triangle.py index d5f1aca..1af0989 100644 --- a/meshpy/triangle.py +++ b/meshpy/triangle.py @@ -1,9 +1,11 @@ +from typing import ClassVar, List + import meshpy._internals as internals from meshpy.common import MeshInfoBase, dump_array class MeshInfo(internals.TriMeshInfo, MeshInfoBase): - _constituents = [ + _constituents: ClassVar[List[str]] = [ "points", "point_attributes", "point_markers", "elements", "element_attributes", "element_volumes", "neighbors", @@ -127,7 +129,7 @@ def build(mesh_info, verbose=False, refinement_func=None, attributes=False, opts = "pzj" if quality_meshing: if min_angle is not None: - opts += "q%f" % min_angle + opts += f"q{min_angle:f}" else: opts += "q" @@ -145,7 +147,7 @@ def build(mesh_info, verbose=False, refinement_func=None, attributes=False, if volume_constraints: opts += "a" if max_volume: - opts += "a%.20f" % max_volume + opts += f"a{max_volume:.20f}" if refinement_func is not None: opts += "u" @@ -199,7 +201,7 @@ def refine(input_p, verbose=False, refinement_func=None, quality_meshing=True, if quality_meshing: if min_angle is not None: - opts += "q%f" % min_angle + opts += f"q{min_angle:f}" else: opts += "q" @@ -229,5 +231,8 @@ def write_gnuplot_mesh(filename, out_p, facets=False): for points in segments: for pt in points: - gp_file.write("%f %f\n" % tuple(out_p.points[pt])) - gp_file.write("%f %f\n\n" % tuple(out_p.points[points[0]])) + x, y = out_p.points[pt] + gp_file.write(f"{x:f} {y:f}\n") + + x, y = out_p.points[points[0]] + gp_file.write(f"{x:f} {y:f}\n\n") diff --git a/pyproject.toml b/pyproject.toml index 6719b27..4e9e982 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -61,23 +61,24 @@ preview = true extend-select = [ "B", # flake8-bugbear "C", # flake8-comprehensions - "D", # pydocstyle "E", # pycodestyle "F", # pyflakes + "G", # flake8-logging-format "I", # flake8-isort "N", # pep8-naming "NPY", # numpy "Q", # flake8-quotes + "RUF", # ruff + "UP", # pyupgrade "W", # pycodestyle ] extend-ignore = [ + "C90", # McCabe complexity "E226", # missing whitespace around arithmetic operator "E241", # multiple spaces after comma "E242", # tab after comma "E265", # block comment should start with # "E402", # module level import not at the top of file - "D", # pydocstyle - "C90", # McCabe complexity ] [tool.ruff.lint.per-file-ignores]