From 6e3a85c001373fdc1fc530bda9480a4013ad6268 Mon Sep 17 00:00:00 2001 From: mawc2019 Date: Sun, 30 Jul 2023 20:33:35 -0400 Subject: [PATCH] tweak the format --- python/adjoint/filters.py | 26 +++++++++++++++++--------- 1 file changed, 17 insertions(+), 9 deletions(-) diff --git a/python/adjoint/filters.py b/python/adjoint/filters.py index 347ebc472..1c8b5d212 100644 --- a/python/adjoint/filters.py +++ b/python/adjoint/filters.py @@ -197,12 +197,12 @@ def _get_resolution(resolution: ArrayLikeType) -> tuple: return resolution[0], resolution[0] else: raise ValueError( - "The dimension of the design-grid resolution is incorrect.") + "The dimension of the design-grid resolution is incorrect." + ) elif isinstance(resolution, (int, float)): return resolution, resolution else: - raise ValueError( - "The input for design-grid resolution is invalid.") + raise ValueError("The input for design-grid resolution is invalid.") def mesh_grid( @@ -210,7 +210,8 @@ def mesh_grid( Lx: float, Ly: float, resolution: ArrayLikeType, - periodic_axes: ArrayLikeType = None) -> tuple: + periodic_axes: ArrayLikeType = None, +) -> tuple: """Obtains the numbers of grid points and the coordinates of the grid of the design region. @@ -227,7 +228,6 @@ def mesh_grid( A four-element tuple composed of the numbers of grid points and the coordinates of the grid. """ - resolution = _get_resolution(resolution) Nx = int(round(Lx * resolution[0])) + 1 Ny = int(round(Ly * resolution[1])) + 1 @@ -241,9 +241,17 @@ def mesh_grid( if periodic_axes is not None: periodic_axes = np.array(periodic_axes) if 0 in periodic_axes: - xv = np.arange(0, np.ceil(2 * radius / Lx) * Lx / 2, 1 / resolution[0]) if resolution[0] > 0 else [0] + xv = ( + np.arange(0, np.ceil(2 * radius / Lx) * Lx / 2, 1 / resolution[0]) + if resolution[0] > 0 + else [0] + ) if 1 in periodic_axes: - yv = np.arange(0, np.ceil(2 * radius / Ly) * Ly / 2, 1 / resolution[1]) if resolution[1] > 0 else [0] + yv = ( + np.arange(0, np.ceil(2 * radius / Ly) * Ly / 2, 1 / resolution[1]) + if resolution[1] > 0 + else [0] + ) X, Y = np.meshgrid(xv, yv, sparse=True, indexing="ij") @@ -349,7 +357,7 @@ def gaussian_filter( Returns: The filtered design weights. """ - Nx, Ny, X, Y = mesh_grid(3*sigma, Lx, Ly, resolution, periodic_axes) + Nx, Ny, X, Y = mesh_grid(3 * sigma, Lx, Ly, resolution, periodic_axes) x = x.reshape(Nx, Ny) # Ensure the input is 2d h = np.exp(-(X**2 + Y**2) / sigma**2) @@ -1058,4 +1066,4 @@ def gray_indicator(x): [1] Lazarov, B. S., Wang, F., & Sigmund, O. (2016). Length scale and manufacturability in density-based topology optimization. Archive of Applied Mechanics, 86(1-2), 189-218. """ - return npa.mean(4 * x.flatten() * (1 - x.flatten())) * 100 \ No newline at end of file + return npa.mean(4 * x.flatten() * (1 - x.flatten())) * 100