From 3be5378aded84d74c6d98d4b4d9f561f5e3cfcf9 Mon Sep 17 00:00:00 2001 From: Tom Gustafsson Date: Mon, 1 Jun 2020 17:33:50 +0300 Subject: [PATCH 01/19] Try adding automatic flake8 linting --- .github/workflows/lint.yml | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) create mode 100644 .github/workflows/lint.yml diff --git a/.github/workflows/lint.yml b/.github/workflows/lint.yml new file mode 100644 index 000000000..45288fa8c --- /dev/null +++ b/.github/workflows/lint.yml @@ -0,0 +1,26 @@ +name: Lint + +on: [push, pull_request] + +jobs: + run-linters: + name: Run linters + runs-on: ubuntu-latest + + steps: + - name: Check out Git repository + uses: actions/checkout@v2 + + - name: Set up Python + uses: actions/setup-python@v1 + with: + python-version: 3.8 + + - name: Install Python dependencies + run: pip install flake8 + + - name: Run linters + uses: samuelmeuli/lint-action@v1 + with: + github_token: ${{ secrets.github_token }} + flake8: true From b31f62cf0b04136971df7010aa20df1e04303cfd Mon Sep 17 00:00:00 2001 From: Tom Gustafsson Date: Mon, 1 Jun 2020 17:37:26 +0300 Subject: [PATCH 02/19] Run only on push --- .github/workflows/lint.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/lint.yml b/.github/workflows/lint.yml index 45288fa8c..0cb00b77a 100644 --- a/.github/workflows/lint.yml +++ b/.github/workflows/lint.yml @@ -1,6 +1,6 @@ name: Lint -on: [push, pull_request] +on: push jobs: run-linters: From b5adca417c60f7c650fa7e674296205c6511355d Mon Sep 17 00:00:00 2001 From: Tom Gustafsson Date: Mon, 1 Jun 2020 17:42:59 +0300 Subject: [PATCH 03/19] Continue even if linter fails --- .github/workflows/lint.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/lint.yml b/.github/workflows/lint.yml index 0cb00b77a..c0b5d7abc 100644 --- a/.github/workflows/lint.yml +++ b/.github/workflows/lint.yml @@ -20,6 +20,7 @@ jobs: run: pip install flake8 - name: Run linters + continue-on-error: true uses: samuelmeuli/lint-action@v1 with: github_token: ${{ secrets.github_token }} From 2d04f48c9009357d32a0864b2d27bcddb29334e9 Mon Sep 17 00:00:00 2001 From: Tom Gustafsson Date: Mon, 1 Jun 2020 17:52:37 +0300 Subject: [PATCH 04/19] Run only in skfem directory --- .github/workflows/lint.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/lint.yml b/.github/workflows/lint.yml index c0b5d7abc..1f81cfc4e 100644 --- a/.github/workflows/lint.yml +++ b/.github/workflows/lint.yml @@ -20,8 +20,8 @@ jobs: run: pip install flake8 - name: Run linters - continue-on-error: true uses: samuelmeuli/lint-action@v1 with: github_token: ${{ secrets.github_token }} flake8: true + flake8_dir: skfem From 6e07ffd1147fb1bcddfebff5ad049ed5d26691c8 Mon Sep 17 00:00:00 2001 From: Tom Gustafsson Date: Mon, 1 Jun 2020 20:13:44 +0300 Subject: [PATCH 05/19] Ignore variable-naming related errors --- .github/workflows/lint.yml | 1 + skfem/utils.py | 2 ++ 2 files changed, 3 insertions(+) diff --git a/.github/workflows/lint.yml b/.github/workflows/lint.yml index 1f81cfc4e..03e329ba5 100644 --- a/.github/workflows/lint.yml +++ b/.github/workflows/lint.yml @@ -25,3 +25,4 @@ jobs: github_token: ${{ secrets.github_token }} flake8: true flake8_dir: skfem + flake8_args: "--ignore=E741" diff --git a/skfem/utils.py b/skfem/utils.py index d5cea8f23..b7f9890f5 100644 --- a/skfem/utils.py +++ b/skfem/utils.py @@ -66,10 +66,12 @@ def solver_eigen_scipy(**kwargs) -> EigenSolver: 'mode': 'normal', } params.update(kwargs) + def solver(K, M, **solve_time_kwargs): params.update(solve_time_kwargs) from scipy.sparse.linalg import eigsh return eigsh(K, M=M, **params) + return solver From f066b7b873d1606ba7f6338d30e7a8bd5b2bb56b Mon Sep 17 00:00:00 2001 From: Tom Gustafsson Date: Mon, 1 Jun 2020 20:20:39 +0300 Subject: [PATCH 06/19] Extend ignore instead --- .github/workflows/lint.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/lint.yml b/.github/workflows/lint.yml index 03e329ba5..bb99e5b1c 100644 --- a/.github/workflows/lint.yml +++ b/.github/workflows/lint.yml @@ -25,4 +25,4 @@ jobs: github_token: ${{ secrets.github_token }} flake8: true flake8_dir: skfem - flake8_args: "--ignore=E741" + flake8_args: "--extend-ignore=E741" From c6090accdda6621290099714aee5f2ddcbd45c6b Mon Sep 17 00:00:00 2001 From: Tom Gustafsson Date: Mon, 1 Jun 2020 20:22:22 +0300 Subject: [PATCH 07/19] Conform PEP8 --- skfem/utils.py | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/skfem/utils.py b/skfem/utils.py index b7f9890f5..ae5682fe4 100644 --- a/skfem/utils.py +++ b/skfem/utils.py @@ -338,5 +338,8 @@ def deriv(u, du, v, dv, w): # for backwards compatibility -L2_projection = lambda a, b, c=None: project(a, basis_to=b, I=c) -derivative = lambda a, b, c, d=0: project(a, basis_from=b, basis_to=c, diff=d) +def L2_projection(a, b, c=None): + return project(a, basis_to=b, I=c) + +def derivative(a, b, c, d=0): + return project(a, basis_from=b, basis_to=c, diff=d) From c56bbc17f0e11f0f785bc5b5799b03716908c512 Mon Sep 17 00:00:00 2001 From: Tom Gustafsson Date: Mon, 1 Jun 2020 20:31:04 +0300 Subject: [PATCH 08/19] Conform PEP8 --- skfem/quadrature.py | 10 ++++++---- skfem/utils.py | 1 + 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/skfem/quadrature.py b/skfem/quadrature.py index 9710ed2c0..bfe7ea5dd 100644 --- a/skfem/quadrature.py +++ b/skfem/quadrature.py @@ -217,10 +217,12 @@ def get_quadrature_tet(norder: int) -> Tuple[np.ndarray, np.ndarray]: ), }[ norder - ] # last one available from http://www.cfd-online.com/Wiki/Code:_Quadrature_on_Tetrahedra - except: + ] + # last one available from + # http://www.cfd-online.com/Wiki/Code:_Quadrature_on_Tetrahedra + except KeyError: raise NotImplementedError( - "The requested order of quadrature " "is not available." + "The requested order of quadrature is not available." ) @@ -2211,7 +2213,7 @@ def get_quadrature_tri(norder: int) -> Tuple[np.ndarray, np.ndarray]: ), ), }[norder] - except: + except KeyError: raise NotImplementedError("The requested order of quadrature" "is not implemented!") diff --git a/skfem/utils.py b/skfem/utils.py index ae5682fe4..229da0f19 100644 --- a/skfem/utils.py +++ b/skfem/utils.py @@ -341,5 +341,6 @@ def deriv(u, du, v, dv, w): def L2_projection(a, b, c=None): return project(a, basis_to=b, I=c) + def derivative(a, b, c, d=0): return project(a, basis_from=b, basis_to=c, diff=d) From ee95c7ee8bf7b1eedfd647ad344181738f368114 Mon Sep 17 00:00:00 2001 From: Tom Gustafsson Date: Mon, 1 Jun 2020 20:33:02 +0300 Subject: [PATCH 09/19] Ignore wildcard import errors in __init__.py --- skfem/__init__.py | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/skfem/__init__.py b/skfem/__init__.py index 68611bc68..d4e011df5 100644 --- a/skfem/__init__.py +++ b/skfem/__init__.py @@ -1,11 +1,11 @@ """Support for wildcard import.""" -from skfem.mesh import * -from skfem.assembly import * -from skfem.mapping import * -from skfem.element import * -from skfem.utils import * -from skfem.version import __version__ +from skfem.mesh import * # noqa +from skfem.assembly import * # noqa +from skfem.mapping import * # noqa +from skfem.element import * # noqa +from skfem.utils import * # noqa +from skfem.version import __version__ # noqa from skfem.assembly import __all__ as all_assembly from skfem.mesh import __all__ as all_mesh From dec988978f494554b70b0a45c3be3f2feee62dd6 Mon Sep 17 00:00:00 2001 From: Tom Gustafsson Date: Mon, 1 Jun 2020 20:35:51 +0300 Subject: [PATCH 10/19] Ignore flake8 errors --- skfem/__init__.py | 28 ++++++++++++++-------------- 1 file changed, 14 insertions(+), 14 deletions(-) diff --git a/skfem/__init__.py b/skfem/__init__.py index d4e011df5..2f5633ebb 100644 --- a/skfem/__init__.py +++ b/skfem/__init__.py @@ -13,18 +13,18 @@ __all__ = all_mesh + all_assembly + all_element + [ - 'MappingAffine', - 'MappingIsoparametric', - 'MappingMortar', - 'adaptive_theta', - 'build_pc_ilu', - 'build_pc_diag', - 'condense', - 'derivative', - 'L2_projection', - 'project', - 'solve', - 'solver_direct_scipy', - 'solver_iter_pcg', - 'solver_iter_krylov', + 'MappingAffine', # noqa + 'MappingIsoparametric', # noqa + 'MappingMortar', # noqa + 'adaptive_theta', # noqa + 'build_pc_ilu', # noqa + 'build_pc_diag', # noqa + 'condense', # noqa + 'derivative', # noqa + 'L2_projection', # noqa + 'project', # noqa + 'solve', # noqa + 'solver_direct_scipy', # noqa + 'solver_iter_pcg', # noqa + 'solver_iter_krylov', # noqa ] From 526212405a84c517eb669a82828e00bb184d005d Mon Sep 17 00:00:00 2001 From: Tom Gustafsson Date: Mon, 1 Jun 2020 20:39:42 +0300 Subject: [PATCH 11/19] Ignore flake8 errors --- skfem/mapping/__init__.py | 8 +++--- skfem/mapping/mapping_affine.py | 4 +-- skfem/mapping/mapping_isoparametric.py | 36 +++++++++++++------------- skfem/mapping/mapping_mortar.py | 4 +-- 4 files changed, 26 insertions(+), 26 deletions(-) diff --git a/skfem/mapping/__init__.py b/skfem/mapping/__init__.py index 210e6df0e..99ce2b203 100644 --- a/skfem/mapping/__init__.py +++ b/skfem/mapping/__init__.py @@ -5,7 +5,7 @@ """ -from .mapping import Mapping -from .mapping_affine import MappingAffine -from .mapping_isoparametric import MappingIsoparametric -from .mapping_mortar import MappingMortar +from .mapping import Mapping # noqa +from .mapping_affine import MappingAffine # noqa +from .mapping_isoparametric import MappingIsoparametric # noqa +from .mapping_mortar import MappingMortar # noqa diff --git a/skfem/mapping/mapping_affine.py b/skfem/mapping/mapping_affine.py index 659de44a8..fc6d866fa 100644 --- a/skfem/mapping/mapping_affine.py +++ b/skfem/mapping/mapping_affine.py @@ -42,10 +42,10 @@ def __init__(self, mesh): if dim == 1: self.invA[0, 0] = 1.0 / self.A[0, 0] elif dim == 2: - self.invA[0, 0] = self.A[1, 1] / self.detA + self.invA[0, 0] = self.A[1, 1] / self.detA # noqa self.invA[0, 1] = -self.A[0, 1] / self.detA self.invA[1, 0] = -self.A[1, 0] / self.detA - self.invA[1, 1] = self.A[0, 0] / self.detA + self.invA[1, 1] = self.A[0, 0] / self.detA # noqa elif dim == 3: self.invA[0, 0] = (-self.A[1, 2] * self.A[2, 1] + self.A[1, 1] * self.A[2, 2]) / self.detA diff --git a/skfem/mapping/mapping_isoparametric.py b/skfem/mapping/mapping_isoparametric.py index 698048b13..86149421c 100644 --- a/skfem/mapping/mapping_isoparametric.py +++ b/skfem/mapping/mapping_isoparametric.py @@ -16,7 +16,7 @@ def __init__(self, mesh: Mesh, elem: Element, bndelem: Optional[Element] = None): - """Initialize an isoparametric mapping between + r"""Initialize an isoparametric mapping between the reference and the global element. This means that the mapping is defined through @@ -172,19 +172,19 @@ def invDF(self, X, tind=None): if self.dim == 2: detDF = self.detDF(X, tind) - invDF[0, 0] = J[1][1] + invDF[0, 0] = J[1][1] # noqa invDF[0, 1] = -J[0][1] invDF[1, 0] = -J[1][0] - invDF[1, 1] = J[0][0] + invDF[1, 1] = J[0][0] # noqa elif self.dim == 3: invDF[0, 0] = -J[1][2] * J[2][1] + J[1][1] * J[2][2] - invDF[1, 0] = J[1][2] * J[2][0] - J[1][0] * J[2][2] + invDF[1, 0] = J[1][2] * J[2][0] - J[1][0] * J[2][2] # noqa invDF[2, 0] = -J[1][1] * J[2][0] + J[1][0] * J[2][1] - invDF[0, 1] = J[0][2] * J[2][1] - J[0][1] * J[2][2] + invDF[0, 1] = J[0][2] * J[2][1] - J[0][1] * J[2][2] # noqa invDF[1, 1] = -J[0][2] * J[2][0] + J[0][0] * J[2][2] - invDF[2, 1] = J[0][1] * J[2][0] - J[0][0] * J[2][1] + invDF[2, 1] = J[0][1] * J[2][0] - J[0][0] * J[2][1] # noqa invDF[0, 2] = -J[0][2] * J[1][1] + J[0][1] * J[1][2] - invDF[1, 2] = J[0][2] * J[1][0] - J[0][0] * J[1][2] + invDF[1, 2] = J[0][2] * J[1][0] - J[0][0] * J[1][2] # noqa invDF[2, 2] = -J[0][1] * J[1][0] + J[0][0] * J[1][1] else: raise Exception("Not implemented for the given dimension.") @@ -194,19 +194,19 @@ def invDF(self, X, tind=None): def normals(self, X, tind, find, t2f): if self.dim == 1: Nref = np.array([[-1.], - [ 1.]]) + [ 1.]]) # noqa elif self.dim == 2: - Nref = np.array([[ 0., -1.], - [ 1., 0.], - [ 0., 1.], - [-1., 0.]]) + Nref = np.array([[ 0., -1.], # noqa + [ 1., 0.], # noqa + [ 0., 1.], # noqa + [-1., 0.]]) # noqa elif self.dim == 3: - Nref = np.array([[ 1., 0., 0.], - [ 0., 0., 1.], - [ 0., 1., 0.], - [ 0., -1., 0.], - [ 0., 0., -1.], - [-1., 0., 0.]]) + Nref = np.array([[ 1., 0., 0.], # noqa + [ 0., 0., 1.], # noqa + [ 0., 1., 0.], # noqa + [ 0., -1., 0.], # noqa + [ 0., 0., -1.], # noqa + [-1., 0., 0.]]) # noqa else: raise Exception("Not implemented for the given dimension.") diff --git a/skfem/mapping/mapping_mortar.py b/skfem/mapping/mapping_mortar.py index 953d09ebc..97a8c0517 100644 --- a/skfem/mapping/mapping_mortar.py +++ b/skfem/mapping/mapping_mortar.py @@ -75,8 +75,8 @@ def param(p): p = np.array([np.hstack((param(mesh1.p), param(mesh2.p)))]) t = np.array([ixorig[:-1], ixorig[1:]]) - # create 1-dimensional supermesh from the intersections of the projected - # facet elements + # create 1-dimensional supermesh from the intersections of the + # projected facet elements p = p[:, np.concatenate((t[0], np.array([t[1, -1]])))] range_max = np.min([np.max(param_p1), np.max(param_p2)]) range_min = np.max([np.min(param_p1), np.min(param_p2)]) From 466416f6d7f78d905ea2f759213bc70ee9fe5f4e Mon Sep 17 00:00:00 2001 From: Tom Gustafsson Date: Mon, 1 Jun 2020 20:42:55 +0300 Subject: [PATCH 12/19] Ignore flake8 errors --- skfem/__init__.py | 30 +++++++++++++------------- skfem/assembly/__init__.py | 2 +- skfem/assembly/form/__init__.py | 8 +++---- skfem/assembly/form/form_parameters.py | 3 ++- skfem/mapping/mapping_affine.py | 2 +- 5 files changed, 23 insertions(+), 22 deletions(-) diff --git a/skfem/__init__.py b/skfem/__init__.py index 2f5633ebb..84c938710 100644 --- a/skfem/__init__.py +++ b/skfem/__init__.py @@ -12,19 +12,19 @@ from skfem.element import __all__ as all_element -__all__ = all_mesh + all_assembly + all_element + [ - 'MappingAffine', # noqa - 'MappingIsoparametric', # noqa - 'MappingMortar', # noqa - 'adaptive_theta', # noqa - 'build_pc_ilu', # noqa - 'build_pc_diag', # noqa - 'condense', # noqa - 'derivative', # noqa - 'L2_projection', # noqa - 'project', # noqa - 'solve', # noqa - 'solver_direct_scipy', # noqa - 'solver_iter_pcg', # noqa - 'solver_iter_krylov', # noqa +__all__ = all_mesh + all_assembly + all_element + [ # noqa + 'MappingAffine', + 'MappingIsoparametric', + 'MappingMortar', + 'adaptive_theta', + 'build_pc_ilu', + 'build_pc_diag', + 'condense', + 'derivative', + 'L2_projection', + 'project', + 'solve', + 'solver_direct_scipy', + 'solver_iter_pcg', + 'solver_iter_krylov', ] diff --git a/skfem/assembly/__init__.py b/skfem/assembly/__init__.py index f8e5438e4..418fcb14c 100644 --- a/skfem/assembly/__init__.py +++ b/skfem/assembly/__init__.py @@ -1,5 +1,5 @@ # -*- coding: utf-8 -*- -"""This module contains rest of the tools for performing the finite element +r"""This module contains rest of the tools for performing the finite element assembly. The basic workflow of assembly is the following: 1. Initialize :class:`~skfem.mesh.Mesh` and :class:`~skfem.mesh.Element`. diff --git a/skfem/assembly/form/__init__.py b/skfem/assembly/form/__init__.py index 23336f165..0ec6e70e0 100644 --- a/skfem/assembly/form/__init__.py +++ b/skfem/assembly/form/__init__.py @@ -1,4 +1,4 @@ -from .form import Form -from .bilinear_form import bilinear_form, BilinearForm -from .linear_form import linear_form, LinearForm -from .functional import functional, Functional +from .form import Form # noqa +from .bilinear_form import bilinear_form, BilinearForm # noqa +from .linear_form import linear_form, LinearForm # noqa +from .functional import functional, Functional # noqa diff --git a/skfem/assembly/form/form_parameters.py b/skfem/assembly/form/form_parameters.py index 5fa37f18c..9ebf1673f 100644 --- a/skfem/assembly/form/form_parameters.py +++ b/skfem/assembly/form/form_parameters.py @@ -2,8 +2,9 @@ from numpy import ndarray -# TODO: Deprecated. Remove after old style forms are gone. + class FormParameters(NamedTuple): + """Deprecated. Remove after old style forms are gone.""" w: Optional[ndarray] = None dw: Optional[ndarray] = None ddw: Optional[ndarray] = None diff --git a/skfem/mapping/mapping_affine.py b/skfem/mapping/mapping_affine.py index fc6d866fa..1ea3526b5 100644 --- a/skfem/mapping/mapping_affine.py +++ b/skfem/mapping/mapping_affine.py @@ -170,7 +170,7 @@ def detDG(self, X, find=None): def normals(self, X, tind, find, t2f): if self.dim == 1: Nref = np.array([[-1.0], - [ 1.0]]) + [1.0]]) elif self.dim == 2: Nref = np.array([[0.0, -1.0], [1.0, 1.0], From 5e4e196066861afa8720531ed9f4a8dd180ece5c Mon Sep 17 00:00:00 2001 From: Tom Gustafsson Date: Mon, 1 Jun 2020 23:34:14 +0300 Subject: [PATCH 13/19] Fix flake8 errors --- skfem/assembly/basis/basis.py | 49 +++++++++++++++-------------- skfem/assembly/basis/facet_basis.py | 16 +++++----- 2 files changed, 33 insertions(+), 32 deletions(-) diff --git a/skfem/assembly/basis/basis.py b/skfem/assembly/basis/basis.py index 97a01f22b..0e428f96d 100644 --- a/skfem/assembly/basis/basis.py +++ b/skfem/assembly/basis/basis.py @@ -19,7 +19,7 @@ class Basis: Please see the following implementations: - :class:`~skfem.assembly.InteriorBasis`, basis functions inside elements - - :class:`~skfem.assembly.FacetBasis`, basis functions on element boundaries + - :class:`~skfem.assembly.FacetBasis`, basis functions on boundaries """ @@ -70,7 +70,7 @@ def _build_dofnum(self, mesh, element): offset = element.nodal_dofs * mesh.p.shape[1] # edge dofs - if mesh.dim() == 3: + if mesh.dim() == 3: self.edge_dofs = np.reshape( np.arange(element.edge_dofs * mesh.edges.shape[1], dtype=np.int64), @@ -78,7 +78,7 @@ def _build_dofnum(self, mesh, element): order='F') + offset offset = offset + element.edge_dofs * mesh.edges.shape[1] else: - self.edge_dofs = np.empty((0,0)) + self.edge_dofs = np.empty((0, 0)) # facet dofs self.facet_dofs = np.reshape( @@ -172,7 +172,8 @@ def _get_dofs(self, off = n_nodal facets = { - self.dofnames[i + off]: np.zeros((0, len(facet_ix)), dtype=np.int64) + self.dofnames[i + off]: np.zeros((0, len(facet_ix)), + dtype=np.int64) for i in range(n_facet) if self.dofnames[i + off] not in skip } for i in range(n_facet): @@ -213,13 +214,13 @@ def find_dofs(self, This corresponds to a list of facet indices that can be passed over: >>> basis = InteriorBasis(m, ElementTriP1()) - >>> basis.find_dofs({'left': m.facets_satisfying(lambda x: x[0] == 0)}) - {'left': Dofs(nodal={'u': array([0, 2, 5])}, facet={}, edge={}, interior={})} + >>> basis.find_dofs({'left': np.array([1, 5])})['left'] + Dofs(nodal={'u': array([0, 2, 5])}, facet={}, edge={}, interior={}) Parameters ---------- facets - A dictionary of facet indices. If `None`, use `self.mesh.boundaries` + A dictionary of facets. If `None`, use `self.mesh.boundaries` if set or otherwise use `{'all': self.mesh.boundary_facets()}`. skip List of dofnames to skip. @@ -242,17 +243,17 @@ def get_dofs(self, facets: Optional[Any] = None) -> Any: Parameters ---------- facets - A list of facet indices. If None, find facets by - Mesh.boundary_facets(). If callable, call Mesh.facets_satisfying to - get facets. If array, find the corresponding dofs. If dict of - arrays, find dofs for each entry. If dict of callables, call + A list of facet indices. If `None`, find facets by + Mesh.boundary_facets. If callable, call Mesh.facets_satisfying + to get facets. If array, find the corresponding DOFs. If dict of + arrays, find DOFs for each entry. If dict of callables, call Mesh.facets_satisfying for each entry to get facets and then find - dofs for those. + DOFs for those. Returns ------- Dofs or Dict[str, Dofs] - A subset of degrees-of-freedom as :class:`skfem.assembly.dofs.Dofs`. + A subset of DOFs as :class:`skfem.assembly.dofs.Dofs`. """ if facets is None: @@ -313,12 +314,12 @@ def linear_combination(n, refn): out[j, k, :, :] += \ values * self.basis[i][c][n][j, k] elif len(refn.shape) == 5: # third derivatives - #import pdb; pdb.set_trace() for j in range(out.shape[0]): for k in range(out.shape[1]): for l in range(out.shape[2]): out[j, k, l, :, :] += \ - values * self.basis[i][c][-1][n][j, k, l] + values * \ + self.basis[i][c][-1][n][j, k, l] elif len(refn.shape) == 6: # fourth derivatives for j in range(out.shape[0]): for k in range(out.shape[1]): @@ -355,20 +356,20 @@ def linear_combination(n, refn): def split_indices(self) -> List[ndarray]: """Return indices for the solution components.""" if isinstance(self.elem, ElementComposite): - off = np.zeros(4, dtype=np.int) + o = np.zeros(4, dtype=np.int) output = [None] * len(self.elem.elems) for k in range(len(self.elem.elems)): e = self.elem.elems[k] output[k] = np.concatenate(( - self.nodal_dofs[off[0]:(off[0] + e.nodal_dofs)].flatten(), - self.edge_dofs[off[1]:(off[1] + e.edge_dofs)].flatten(), - self.facet_dofs[off[2]:(off[2] + e.facet_dofs)].flatten(), - self.interior_dofs[off[3]:(off[3] + e.interior_dofs)].flatten() + self.nodal_dofs[o[0]:(o[0] + e.nodal_dofs)].flatten(), + self.edge_dofs[o[1]:(o[1] + e.edge_dofs)].flatten(), + self.facet_dofs[o[2]:(o[2] + e.facet_dofs)].flatten(), + self.interior_dofs[o[3]:(o[3] + e.interior_dofs)].flatten() )).astype(np.int) - off += np.array([e.nodal_dofs, - e.edge_dofs, - e.facet_dofs, - e.interior_dofs]) + o += np.array([e.nodal_dofs, + e.edge_dofs, + e.facet_dofs, + e.interior_dofs]) return output raise ValueError("Basis.elem has only a single component!") diff --git a/skfem/assembly/basis/facet_basis.py b/skfem/assembly/basis/facet_basis.py index a7ff69beb..e80feb482 100644 --- a/skfem/assembly/basis/facet_basis.py +++ b/skfem/assembly/basis/facet_basis.py @@ -17,7 +17,7 @@ class FacetBasis(Basis): def __init__(self, mesh, elem, - mapping = None, + mapping=None, intorder: int = None, side: int = None, facets: ndarray = None, @@ -39,7 +39,7 @@ def __init__(self, integrated exactly by the used quadrature. Not used if `quadrature` is specified. side - If 0 or 1, the basis functions are evaluated on the interior facets. + If 0 or 1, basis functions are evaluated on the interior facets. The numbers 0 and 1 refer to the different sides of the facets. Side 0 corresponds to the indices `mesh.f2t[0]`. If `None`, basis is evaluated only on the exterior facets. @@ -65,7 +65,7 @@ def __init__(self, self.find = np.nonzero(self.mesh.f2t[1] == -1)[0] self.tind = self.mesh.f2t[0, self.find] elif hasattr(self.mapping, 'helper_to_orig') and side in [0, 1]: - self.mapping.side = side # side effect + self.mapping.side = side self.find = self.mapping.helper_to_orig[side] self.tind = self.mesh.f2t[0, self.find] elif side in [0, 1]: @@ -86,10 +86,10 @@ def __init__(self, # construct normal vectors from side=0 always Y0 = self.mapping.invF(x, tind=self.mesh.f2t[0, self.find]) self.normals = DiscreteField( - value = self.mapping.normals(Y0, - self.mesh.f2t[0, self.find], - self.find, - self.mesh.t2f) + value=self.mapping.normals(Y0, + self.mesh.f2t[0, self.find], + self.find, + self.mesh.t2f) ) self.nelems = len(self.find) @@ -113,5 +113,5 @@ def global_coordinates(self) -> ndarray: def mesh_parameters(self) -> ndarray: return DiscreteField((np.abs(self.mapping.detDG(self.X, self.find)) - ** (1. / (self.mesh.dim() - 1.)))\ + ** (1. / (self.mesh.dim() - 1.))) if self.mesh.dim() != 1 else np.array([0.])) From 1970f486db9c11cb44f8178148292feebaae958d Mon Sep 17 00:00:00 2001 From: Tom Gustafsson Date: Mon, 1 Jun 2020 23:42:18 +0300 Subject: [PATCH 14/19] Fix flake8 errors --- skfem/assembly/basis/__init__.py | 6 +++--- skfem/assembly/basis/interior_basis.py | 7 ++++--- skfem/element/__init__.py | 8 ++++---- skfem/element/element.py | 6 +++--- skfem/element/element_composite.py | 9 +++++---- skfem/element/element_global.py | 12 ++++++------ skfem/element/element_h1.py | 8 ++++---- skfem/element/element_hcurl.py | 6 +++--- skfem/element/element_hdiv.py | 6 +++--- skfem/element/element_hex/__init__.py | 4 ++-- skfem/element/element_hex/element_hex_s2.py | 6 +++--- skfem/element/element_line/__init__.py | 8 ++++---- skfem/element/element_quad/__init__.py | 14 +++++++------- skfem/element/element_tet/__init__.py | 12 ++++++------ skfem/element/element_tet/element_tet_mini.py | 2 +- skfem/element/element_tet/element_tet_p1.py | 2 +- skfem/element/element_tet/element_tet_p2.py | 2 +- skfem/element/element_tri/__init__.py | 16 ++++++++-------- 18 files changed, 68 insertions(+), 66 deletions(-) diff --git a/skfem/assembly/basis/__init__.py b/skfem/assembly/basis/__init__.py index d09765682..0d325f787 100644 --- a/skfem/assembly/basis/__init__.py +++ b/skfem/assembly/basis/__init__.py @@ -1,3 +1,3 @@ -from .basis import Basis -from .interior_basis import InteriorBasis -from .facet_basis import FacetBasis +from .basis import Basis # noqa +from .interior_basis import InteriorBasis # noqa +from .facet_basis import FacetBasis # noqa diff --git a/skfem/assembly/basis/interior_basis.py b/skfem/assembly/basis/interior_basis.py index 5144cf111..5e132a420 100644 --- a/skfem/assembly/basis/interior_basis.py +++ b/skfem/assembly/basis/interior_basis.py @@ -119,9 +119,10 @@ def refinterp(self, nt = self.nelems t = np.tile(m.t, (1, nt)) dt = np.max(t) - t += (dt + 1) * (np.tile(np.arange(nt), (m.t.shape[0] * m.t.shape[1], 1)) - .flatten('F') - .reshape((-1, m.t.shape[0])).T) + t += (dt + 1) *\ + (np.tile(np.arange(nt), (m.t.shape[0] * m.t.shape[1], 1)) + .flatten('F') + .reshape((-1, m.t.shape[0])).T) if X.shape[0] == 1: p = np.array([x.flatten()]) diff --git a/skfem/element/__init__.py b/skfem/element/__init__.py index 405c177ad..7e670f913 100644 --- a/skfem/element/__init__.py +++ b/skfem/element/__init__.py @@ -54,10 +54,10 @@ ElementQuadBFS from .element_tet import ElementTetP0, ElementTetP1, ElementTetP2,\ ElementTetRT0, ElementTetN0, ElementTetMini -from .element_hex import ElementHex1, ElementHexS2 -from .element_line import ElementLineP1, ElementLineP2, ElementLinePp,\ - ElementLineHermite -from .element_composite import ElementComposite +from .element_hex import ElementHex1, ElementHexS2 # noqa +from .element_line import ElementLineP1, ElementLineP2,\ # noqa + ElementLinePp, ElementLineHermite +from .element_composite import ElementComposite # noqa __all__ = [ diff --git a/skfem/element/element.py b/skfem/element/element.py index 9b45164b0..23c34140c 100644 --- a/skfem/element/element.py +++ b/skfem/element/element.py @@ -37,7 +37,7 @@ class Element(): Mesh type for calculating number of edges, etc. """ - nodal_dofs: int = 0 + nodal_dofs: int = 0 facet_dofs: int = 0 interior_dofs: int = 0 edge_dofs: int = 0 @@ -99,9 +99,9 @@ def _bfun_counts(self): """ return np.array([self.nodal_dofs * self.mesh_type.t.shape[0], - self.edge_dofs * self.mesh_type.t2e.shape[0]\ + self.edge_dofs * self.mesh_type.t2e.shape[0] if hasattr(self.mesh_type, 'edges') else 0, - self.facet_dofs * self.mesh_type.t2f.shape[0]\ + self.facet_dofs * self.mesh_type.t2f.shape[0] if hasattr(self.mesh_type, 'facets') else 0, self.interior_dofs]) diff --git a/skfem/element/element_composite.py b/skfem/element/element_composite.py index fa64a4adc..873a2c6a6 100644 --- a/skfem/element/element_composite.py +++ b/skfem/element/element_composite.py @@ -43,7 +43,8 @@ def __init__(self, *elems): self.dofnames = dofnames doflocs = [] - for i in range(np.sum(np.array([e._bfun_counts() for e in self.elems]))): + for i in range(np.sum(np.array([e._bfun_counts() + for e in self.elems]))): n, ind = self._deduce_bfun(i) doflocs.append(self.elems[n].doflocs[ind]) self.doflocs = np.array(doflocs) @@ -60,15 +61,15 @@ def _deduce_bfun(self, i: int): ns += sum([tmp for j in range(int(counts[0] / len(tmp)))], []) if counts[1] > 0: tmp = sum([[j] * self.elems[j].edge_dofs - for j in range(len(self.elems))], []) + for j in range(len(self.elems))], []) ns += sum([tmp for j in range(int(counts[1] / len(tmp)))], []) if counts[2] > 0: tmp = sum([[j] * self.elems[j].facet_dofs - for j in range(len(self.elems))], []) + for j in range(len(self.elems))], []) ns += sum([tmp for j in range(int(counts[2] / len(tmp)))], []) if counts[3] > 0: tmp = sum([[j] * self.elems[j].interior_dofs - for j in range(len(self.elems))], []) + for j in range(len(self.elems))], []) ns += sum([tmp for j in range(int(counts[3] / len(tmp)))], []) mask = np.array(ns) diff --git a/skfem/element/element_global.py b/skfem/element/element_global.py index 289052d17..b4dd494ee 100644 --- a/skfem/element/element_global.py +++ b/skfem/element/element_global.py @@ -96,7 +96,7 @@ def _pbasis_create(self, i, j=None, k=None, dx=0, dy=0, dz=0): np.max([j - dy, 0]), np.max([k - dz, 0]),))) - def _pbasis_init(self, maxdeg, dim, Ndiff, is_tensorial = False): + def _pbasis_init(self, maxdeg, dim, Ndiff, is_tensorial=False): """Define power bases. Parameters @@ -115,10 +115,10 @@ def _pbasis_init(self, maxdeg, dim, Ndiff, is_tensorial = False): for k in range(Ndiff + 1): diffs = list(itertools.product(*((list(range(dim)),) * k))) for diff in diffs: - desc = ''.join([str(d) for d in diff]) - dx = sum([1 for d in diff if d==0]) - dy = sum([1 for d in diff if d==1]) if dim == 2 else None - dz = sum([1 for d in diff if d==2]) if dim == 3 else None + # desc = ''.join([str(d) for d in diff]) + dx = sum([1 for d in diff if d == 0]) + dy = sum([1 for d in diff if d == 1]) if dim == 2 else None + dz = sum([1 for d in diff if d == 2]) if dim == 3 else None if dim == 1: self._pbasis[diff] = [ self._pbasis_create(i=i, dx=dx) @@ -148,7 +148,7 @@ def _eval_dofs(self, mesh, tind=None): N = len(self._pbasis[()]) V = np.zeros((len(tind), N, N)) w = { - 'v': np.array([mesh.p[:, mesh.t[itr, tind]]\ + 'v': np.array([mesh.p[:, mesh.t[itr, tind]] for itr in range(mesh.t.shape[0])]), } if mesh.p.shape[0] >= 2: diff --git a/skfem/element/element_h1.py b/skfem/element/element_h1.py index dd69899eb..04d67f256 100644 --- a/skfem/element/element_h1.py +++ b/skfem/element/element_h1.py @@ -12,13 +12,13 @@ def gbasis(self, mapping, X, i, tind=None): invDF = mapping.invDF(X, tind) if len(X.shape) == 2: return (DiscreteField( - value = np.broadcast_to(phi, (invDF.shape[2], invDF.shape[3])), - grad = np.einsum('ijkl,il->jkl', invDF, dphi) + value=np.broadcast_to(phi, (invDF.shape[2], invDF.shape[3])), + grad=np.einsum('ijkl,il->jkl', invDF, dphi) ),) elif len(X.shape) == 3: return (DiscreteField( - value = np.broadcast_to(phi, (invDF.shape[2], invDF.shape[3])), - grad = np.einsum('ijkl,ikl->jkl', invDF, dphi) + value=np.broadcast_to(phi, (invDF.shape[2], invDF.shape[3])), + grad=np.einsum('ijkl,ikl->jkl', invDF, dphi) ),) def lbasis(self, X, i): diff --git a/skfem/element/element_hcurl.py b/skfem/element/element_hcurl.py index 31a2af46d..4f8e9b830 100644 --- a/skfem/element/element_hcurl.py +++ b/skfem/element/element_hcurl.py @@ -22,9 +22,9 @@ def gbasis(self, mapping, X, i, tind=None): detDF = mapping.detDF(X, tind) orient = self.orient(mapping, i, tind) return (DiscreteField( - value = np.einsum('ijkl,il,k->jkl', invDF, phi, orient), - curl = np.einsum('ijkl,jl,kl->ikl', DF, dphi, - 1. / detDF * orient[:, None]) + value=np.einsum('ijkl,il,k->jkl', invDF, phi, orient), + curl=np.einsum('ijkl,jl,kl->ikl', DF, dphi, + 1. / detDF * orient[:, None]) ),) def lbasis(self, X, i): diff --git a/skfem/element/element_hdiv.py b/skfem/element/element_hdiv.py index f8b0bc9d7..7c837f57f 100644 --- a/skfem/element/element_hdiv.py +++ b/skfem/element/element_hdiv.py @@ -18,9 +18,9 @@ def gbasis(self, mapping, X, i, tind=None): detDF = mapping.detDF(X, tind) orient = self.orient(mapping, i, tind) return (DiscreteField( - value = np.einsum('ijkl,jl,kl->ikl', DF, phi, - 1. / np.abs(detDF) * orient[:, None]), - div = dphi / (np.abs(detDF) * orient[:, None]) + value=np.einsum('ijkl,jl,kl->ikl', DF, phi, + 1. / np.abs(detDF) * orient[:, None]), + div=dphi / (np.abs(detDF) * orient[:, None]) ),) def lbasis(self, X, i): diff --git a/skfem/element/element_hex/__init__.py b/skfem/element/element_hex/__init__.py index 5f51c3a0f..33f38ec14 100644 --- a/skfem/element/element_hex/__init__.py +++ b/skfem/element/element_hex/__init__.py @@ -1,2 +1,2 @@ -from .element_hex1 import ElementHex1 -from .element_hex_s2 import ElementHexS2 +from .element_hex1 import ElementHex1 # noqa +from .element_hex_s2 import ElementHexS2 # noqa diff --git a/skfem/element/element_hex/element_hex_s2.py b/skfem/element/element_hex/element_hex_s2.py index fa6656aab..06972a5bc 100644 --- a/skfem/element/element_hex/element_hex_s2.py +++ b/skfem/element/element_hex/element_hex_s2.py @@ -50,11 +50,11 @@ def lbasis(self, X, i): y *= s[1] z *= s[2] phi = (1 + x) * (1 + y) * (1 + z) * (x + y + z - 2) / 8 - dphi = np.array([s[0] * (1 + y) * (1 + z) * (x + y + z - 2)\ + dphi = np.array([s[0] * (1 + y) * (1 + z) * (x + y + z - 2) + s[0] * (1 + x) * (1 + y) * (1 + z), - s[1] * (1 + x) * (1 + z) * (x + y + z - 2)\ + s[1] * (1 + x) * (1 + z) * (x + y + z - 2) + s[1] * (1 + x) * (1 + y) * (1 + z), - s[2] * (1 + x) * (1 + y) * (x + y + z - 2)\ + s[2] * (1 + x) * (1 + y) * (x + y + z - 2) + s[2] * (1 + x) * (1 + y) * (1 + z)]) / 8 elif i < 20: s = [ diff --git a/skfem/element/element_line/__init__.py b/skfem/element/element_line/__init__.py index 676c88256..107c66920 100644 --- a/skfem/element/element_line/__init__.py +++ b/skfem/element/element_line/__init__.py @@ -1,4 +1,4 @@ -from .element_line_p1 import ElementLineP1 -from .element_line_p2 import ElementLineP2 -from .element_line_pp import ElementLinePp -from .element_line_hermite import ElementLineHermite +from .element_line_p1 import ElementLineP1 # noqa +from .element_line_p2 import ElementLineP2 # noqa +from .element_line_pp import ElementLinePp # noqa +from .element_line_hermite import ElementLineHermite # noqa diff --git a/skfem/element/element_quad/__init__.py b/skfem/element/element_quad/__init__.py index 3fd8f9238..8c6de730a 100644 --- a/skfem/element/element_quad/__init__.py +++ b/skfem/element/element_quad/__init__.py @@ -1,7 +1,7 @@ -from .element_quad0 import ElementQuad0 -from .element_quad1 import ElementQuad1 -from .element_quad2 import ElementQuad2 -from .element_quad_s2 import ElementQuadS2 -from .element_quad_dg import ElementQuadDG -from .element_quadp import ElementQuadP -from .element_quad_bfs import ElementQuadBFS +from .element_quad0 import ElementQuad0 # noqa +from .element_quad1 import ElementQuad1 # noqa +from .element_quad2 import ElementQuad2 # noqa +from .element_quad_s2 import ElementQuadS2 # noqa +from .element_quad_dg import ElementQuadDG # noqa +from .element_quadp import ElementQuadP # noqa +from .element_quad_bfs import ElementQuadBFS # noqa diff --git a/skfem/element/element_tet/__init__.py b/skfem/element/element_tet/__init__.py index 4ffd41b77..0e572b7b5 100644 --- a/skfem/element/element_tet/__init__.py +++ b/skfem/element/element_tet/__init__.py @@ -1,6 +1,6 @@ -from .element_tet_p0 import ElementTetP0 -from .element_tet_p1 import ElementTetP1 -from .element_tet_p2 import ElementTetP2 -from .element_tet_rt0 import ElementTetRT0 -from .element_tet_n0 import ElementTetN0 -from .element_tet_mini import ElementTetMini +from .element_tet_p0 import ElementTetP0 # noqa +from .element_tet_p1 import ElementTetP1 # noqa +from .element_tet_p2 import ElementTetP2 # noqa +from .element_tet_rt0 import ElementTetRT0 # noqa +from .element_tet_n0 import ElementTetN0 # noqa +from .element_tet_mini import ElementTetMini # noqa diff --git a/skfem/element/element_tet/element_tet_mini.py b/skfem/element/element_tet/element_tet_mini.py index 1c5cd8f36..c2d20480e 100644 --- a/skfem/element/element_tet/element_tet_mini.py +++ b/skfem/element/element_tet/element_tet_mini.py @@ -13,7 +13,7 @@ class ElementTetMini(ElementH1): doflocs = np.array([[0., 0., 0.], [1., 0., 0.], [0., 1., 0.], - [0., 0., 1.], + [0., 0., 1.], [np.nan] * dim]) mesh_type = MeshTet diff --git a/skfem/element/element_tet/element_tet_p1.py b/skfem/element/element_tet/element_tet_p1.py index 6504c1fc6..191cbd7ce 100644 --- a/skfem/element/element_tet/element_tet_p1.py +++ b/skfem/element/element_tet/element_tet_p1.py @@ -34,7 +34,7 @@ def lbasis(self, X, i): 1 + 0*x, 0*x]) elif i == 3: - phi = z + phi = z dphi = np.array([0*x, 0*x, 1 + 0*x]) diff --git a/skfem/element/element_tet/element_tet_p2.py b/skfem/element/element_tet/element_tet_p2.py index 009458126..3b9856f2f 100644 --- a/skfem/element/element_tet/element_tet_p2.py +++ b/skfem/element/element_tet/element_tet_p2.py @@ -15,7 +15,7 @@ class ElementTetP2(ElementH1): [0., 1., 0.], [0., 0., 1.], [.5, 0., 0.], - [.5, .5, 0.], + [.5, .5, 0.], [0., .5, 0.], [0., .0, .5], [.5, .0, .5], diff --git a/skfem/element/element_tri/__init__.py b/skfem/element/element_tri/__init__.py index 48ccf54ad..54ec4554f 100644 --- a/skfem/element/element_tri/__init__.py +++ b/skfem/element/element_tri/__init__.py @@ -1,8 +1,8 @@ -from .element_tri_p1 import ElementTriP1 -from .element_tri_p2 import ElementTriP2 -from .element_tri_dg import ElementTriDG -from .element_tri_p0 import ElementTriP0 -from .element_tri_rt0 import ElementTriRT0 -from .element_tri_mini import ElementTriMini -from .element_tri_morley import ElementTriMorley -from .element_tri_argyris import ElementTriArgyris +from .element_tri_p1 import ElementTriP1 # noqa +from .element_tri_p2 import ElementTriP2 # noqa +from .element_tri_dg import ElementTriDG # noqa +from .element_tri_p0 import ElementTriP0 # noqa +from .element_tri_rt0 import ElementTriRT0 # noqa +from .element_tri_mini import ElementTriMini # noqa +from .element_tri_morley import ElementTriMorley # noqa +from .element_tri_argyris import ElementTriArgyris # noqa From 6d43f9cf2d10a6625b9e4091c872f4a5e96833c9 Mon Sep 17 00:00:00 2001 From: Tom Gustafsson Date: Mon, 1 Jun 2020 23:57:11 +0300 Subject: [PATCH 15/19] Fix flake8 errors --- skfem/element/__init__.py | 14 +++++++------ skfem/element/element_global.py | 2 +- skfem/element/element_tet/element_tet_n0.py | 2 +- skfem/element/element_tet/element_tet_p2.py | 16 +++++++-------- skfem/element/element_tet/element_tet_rt0.py | 2 +- skfem/element/element_tri/element_tri_p2.py | 6 +++--- skfem/importers/__init__.py | 2 +- skfem/importers/meshio.py | 5 +++-- skfem/mesh/__init__.py | 7 ++++--- skfem/mesh/mesh.py | 2 +- skfem/mesh/mesh2d/__init__.py | 6 +++--- skfem/mesh/mesh2d/mesh_quad.py | 8 ++++---- skfem/mesh/mesh2d/mesh_tri.py | 4 ++-- skfem/mesh/mesh3d/__init__.py | 6 +++--- skfem/mesh/mesh3d/mesh_hex.py | 4 ++-- skfem/mesh/mesh3d/mesh_tet.py | 21 ++++++++++---------- skfem/mesh/mesh_line.py | 9 ++++++--- skfem/models/helpers.py | 2 +- 18 files changed, 63 insertions(+), 55 deletions(-) diff --git a/skfem/element/__init__.py b/skfem/element/__init__.py index 7e670f913..0dd9054cb 100644 --- a/skfem/element/__init__.py +++ b/skfem/element/__init__.py @@ -1,12 +1,14 @@ -"""This module defines finite elements (in a very generic sense). The naming of -the element classes reflects their compatibility with the mesh types. +"""This module defines finite elements (in a very generic sense). + +The naming of the element classes reflects their compatibility with the mesh +types. >>> from skfem.element import ElementTriP1 >>> ElementTriP1.mesh_type skfem.mesh.mesh2d.mesh_tri.MeshTri -In order to use an element, you simply initialize the respective object and pass -it to the constructor of :class:`~skfem.assembly.InteriorBasis` or +In order to use an element, you simply initialize the respective object and +pass it to the constructor of :class:`~skfem.assembly.InteriorBasis` or :class:`~skfem.assembly.FacetBasis`. The supported elements include @@ -55,8 +57,8 @@ from .element_tet import ElementTetP0, ElementTetP1, ElementTetP2,\ ElementTetRT0, ElementTetN0, ElementTetMini from .element_hex import ElementHex1, ElementHexS2 # noqa -from .element_line import ElementLineP1, ElementLineP2,\ # noqa - ElementLinePp, ElementLineHermite +from .element_line import ElementLineP1, ElementLineP2,\ + ElementLinePp, ElementLineHermite # noqa from .element_composite import ElementComposite # noqa diff --git a/skfem/element/element_global.py b/skfem/element/element_global.py index b4dd494ee..caac875e4 100644 --- a/skfem/element/element_global.py +++ b/skfem/element/element_global.py @@ -35,8 +35,8 @@ def gbasis(self, mapping, X, i, tind=None): N = len(self._pbasis[()]) # loop over new basis for k in range(self.derivatives + 1): + diffs = list(itertools.product(*((list(range(self.dim)),) * k))) for itr in range(N): - diffs = list(itertools.product(*((list(range(self.dim)),) * k))) for diff in diffs: U[k][diff] += (V[:, itr, i][:, None] * self._pbasis[diff][itr](*x)) diff --git a/skfem/element/element_tet/element_tet_n0.py b/skfem/element/element_tet/element_tet_n0.py index a6e3c8151..903d9f291 100644 --- a/skfem/element/element_tet/element_tet_n0.py +++ b/skfem/element/element_tet/element_tet_n0.py @@ -13,7 +13,7 @@ class ElementTetN0(ElementHcurl): [0., .5, 0.], [0., 0., .5], [.5, 0., .5], - [0., .5, .5],]) + [0., .5, .5]]) mesh_type = MeshTet def lbasis(self, X, i): diff --git a/skfem/element/element_tet/element_tet_p2.py b/skfem/element/element_tet/element_tet_p2.py index 3b9856f2f..8477f3321 100644 --- a/skfem/element/element_tet/element_tet_p2.py +++ b/skfem/element/element_tet/element_tet_p2.py @@ -25,7 +25,7 @@ class ElementTetP2(ElementH1): def lbasis(self, X, i): x, y, z = X - if i == 0: # at (0,0,0) + if i == 0: # at (0,0,0) phi = (1. - 3.*x + 2.*x**2 - 3.*y + 4.*x*y + 2.*y**2 - 3.*z + 4.*x*z + 4.*y*z + 2.*z**2) dphi = np.array([ @@ -33,49 +33,49 @@ def lbasis(self, X, i): -3. + 4.*x + 4.*y + 4.*z, -3. + 4.*x + 4.*y + 4.*z, ]) - elif i == 1: # at (1,0,0) + elif i == 1: # at (1,0,0) phi = - 1.*x + 2.*x**2 dphi = np.array([ -1 + 4*x, 0*x, 0*x, ]) - elif i == 2: # at (0,1,0) + elif i == 2: # at (0,1,0) phi = - 1.*y + 2.*y**2 dphi = np.array([ 0*x, -1. + 4.*y, 0*x, ]) - elif i == 3: # at (0,0,1) + elif i == 3: # at (0,0,1) phi = - 1.*z + 2.*z**2 dphi = np.array([ 0*x, 0*x, -1. + 4.*z, ]) - elif i == 4: # between (0,1) + elif i == 4: # between (0,1) phi = 4.*x - 4.*x**2 - 4.*x*y - 4*x*z dphi = np.array([ 4. - 8.*x - 4.*y - 4.*z, -4.*x, -4.*x, ]) - elif i == 5: # between (1,2) + elif i == 5: # between (1,2) phi = 4.*x*y dphi = np.array([ 4.*y, 4.*x, 0*x, ]) - elif i == 6: # between (0,2) + elif i == 6: # between (0,2) phi = 0. + 4.*y - 4.*x*y - 4.*y**2 - 4.*y*z dphi = np.array([ -4.*y, 4. - 4.*x - 8.*y - 4.*z, -4.*y, ]) - elif i == 7: # between (0,3) + elif i == 7: # between (0,3) phi = 0. + 4.*z - 4.*x*z - 4.*y*z - 4.*z**2 dphi = np.array([ -4.*z, diff --git a/skfem/element/element_tet/element_tet_rt0.py b/skfem/element/element_tet/element_tet_rt0.py index e74a61841..19a6fc119 100644 --- a/skfem/element/element_tet/element_tet_rt0.py +++ b/skfem/element/element_tet/element_tet_rt0.py @@ -12,7 +12,7 @@ class ElementTetRT0(ElementHdiv): doflocs = np.array([[.5, .5, .0], [.5, .0, .5], [.0, .5, .5], - [.5, .5, .5],]) + [.5, .5, .5]]) mesh_type = MeshTet def lbasis(self, X, i): diff --git a/skfem/element/element_tri/element_tri_p2.py b/skfem/element/element_tri/element_tri_p2.py index bda523a46..898fd60f2 100644 --- a/skfem/element/element_tri/element_tri_p2.py +++ b/skfem/element/element_tri/element_tri_p2.py @@ -32,13 +32,13 @@ def lbasis(self, X, i): elif i == 2: phi = 2. * y ** 2 - y dphi = np.array([0. * x, 4. * y - 1]) - elif i == 3: # 0->1 + elif i == 3: # 0->1 phi = 4. * x - 4. * x ** 2 - 4. * x * y dphi = np.array([4 - 8. * x - 4. * y, -4. * x]) - elif i == 4: # 1->2 + elif i == 4: # 1->2 phi = 4. * x * y dphi = np.array([4. * y, 4. * x]) - elif i == 5: # 0->2 + elif i == 5: # 0->2 phi = 4. * y - 4. * x * y - 4. * y ** 2 dphi = np.array([-4. * y, 4 - 4. * x - 8. * y]) else: diff --git a/skfem/importers/__init__.py b/skfem/importers/__init__.py index e0f190785..1f3a92be0 100644 --- a/skfem/importers/__init__.py +++ b/skfem/importers/__init__.py @@ -1 +1 @@ -from ..io import * +from ..io import * # noqa diff --git a/skfem/importers/meshio.py b/skfem/importers/meshio.py index 37d0bf473..123c22d2d 100644 --- a/skfem/importers/meshio.py +++ b/skfem/importers/meshio.py @@ -1,6 +1,7 @@ import warnings +from ..io.meshio import * # noqa + + warnings.warn("skfem.importers is removed in the next release. " "Use skfem.io instead.", DeprecationWarning) - -from ..io.meshio import * diff --git a/skfem/mesh/__init__.py b/skfem/mesh/__init__.py index e1e81d221..b4d24c25e 100644 --- a/skfem/mesh/__init__.py +++ b/skfem/mesh/__init__.py @@ -1,7 +1,8 @@ # -*- coding: utf-8 -*- -"""This module defines different types of finite element meshes. Meshes can be -created using various built-in constructors or loaded from external formats -using `meshio `_. The supported types are +"""This module defines different types of finite element meshes. Meshes can +be created using various built-in constructors or loaded from external +formats using `meshio `_. The supported +types are - :class:`~skfem.mesh.MeshTri`, triangular mesh - :class:`~skfem.mesh.MeshQuad`, quadrilateral mesh diff --git a/skfem/mesh/mesh.py b/skfem/mesh/mesh.py index 61c9e407f..16409fccc 100644 --- a/skfem/mesh/mesh.py +++ b/skfem/mesh/mesh.py @@ -405,7 +405,7 @@ def define_boundary(self, name: str, test: Callable[[ndarray], ndarray], boundary. boundaries_only If True, include only facets on the boundary of the mesh. - + """ if self.boundaries is None: self.boundaries = {} diff --git a/skfem/mesh/mesh2d/__init__.py b/skfem/mesh/mesh2d/__init__.py index 8fdf76d79..b58aacbba 100644 --- a/skfem/mesh/mesh2d/__init__.py +++ b/skfem/mesh/mesh2d/__init__.py @@ -1,3 +1,3 @@ -from .mesh2d import Mesh2D -from .mesh_tri import MeshTri -from .mesh_quad import MeshQuad +from .mesh2d import Mesh2D # noqa +from .mesh_tri import MeshTri # noqa +from .mesh_quad import MeshQuad # noqa diff --git a/skfem/mesh/mesh2d/mesh_quad.py b/skfem/mesh/mesh2d/mesh_quad.py index 4240f6a2e..970deeddf 100644 --- a/skfem/mesh/mesh2d/mesh_quad.py +++ b/skfem/mesh/mesh2d/mesh_quad.py @@ -16,7 +16,7 @@ class MeshQuad(Mesh2D): - :meth:`~skfem.mesh.MeshQuad.load` (requires meshio) - :meth:`~skfem.mesh.MeshQuad.init_refdom` - :meth:`~skfem.mesh.MeshQuad.init_tensor` - + Attributes ---------- facets @@ -112,7 +112,7 @@ def init_tensor(cls: Type[MeshType], """ npx = len(x) npy = len(y) - X, Y = np.meshgrid(np.sort(x), np.sort(y)) + X, Y = np.meshgrid(np.sort(x), np.sort(y)) p = np.vstack((X.flatten('F'), Y.flatten('F'))) ix = np.arange(npx * npy) nt = (npx - 1) * (npy - 1) @@ -135,7 +135,7 @@ def init_tensor(cls: Type[MeshType], @classmethod def init_refdom(cls: Type[MeshType]) -> MeshType: """Initialize a mesh that includes only the reference quad. - + The mesh topology is as follows:: *-------------* @@ -201,7 +201,7 @@ def _uniform_refine(self): # quadrilateral middle point mid = range(self.t.shape[1]) + np.max(t2f) + 1 - + # new vertices are the midpoints of edges ... newp1 = 0.5*np.vstack((p[0, e[0]] + p[0, e[1]], p[1, e[0]] + p[1, e[1]])) diff --git a/skfem/mesh/mesh2d/mesh_tri.py b/skfem/mesh/mesh2d/mesh_tri.py index c0d5b3838..9c396d805 100644 --- a/skfem/mesh/mesh2d/mesh_tri.py +++ b/skfem/mesh/mesh2d/mesh_tri.py @@ -122,7 +122,7 @@ def init_tensor(cls: Type[MeshType], """ npx = len(x) npy = len(y) - X, Y = np.meshgrid(np.sort(x), np.sort(y)) + X, Y = np.meshgrid(np.sort(x), np.sort(y)) p = np.vstack((X.flatten('F'), Y.flatten('F'))) ix = np.arange(npx * npy) nt = (npx - 1) * (npy - 1) @@ -152,7 +152,7 @@ def init_tensor(cls: Type[MeshType], @classmethod def init_symmetric(cls) -> MeshType: r"""Initialize a symmetric mesh of the unit square. - + The mesh topology is as follows:: *------------* diff --git a/skfem/mesh/mesh3d/__init__.py b/skfem/mesh/mesh3d/__init__.py index c6f423f6b..eae01831e 100644 --- a/skfem/mesh/mesh3d/__init__.py +++ b/skfem/mesh/mesh3d/__init__.py @@ -1,3 +1,3 @@ -from .mesh3d import Mesh3D -from .mesh_tet import MeshTet -from .mesh_hex import MeshHex +from .mesh3d import Mesh3D # noqa +from .mesh_tet import MeshTet # noqa +from .mesh_hex import MeshHex # noqa diff --git a/skfem/mesh/mesh3d/mesh_hex.py b/skfem/mesh/mesh3d/mesh_hex.py index b0896b2f5..a00e747e5 100644 --- a/skfem/mesh/mesh3d/mesh_hex.py +++ b/skfem/mesh/mesh3d/mesh_hex.py @@ -136,7 +136,7 @@ def init_tensor(cls: Type[MeshType], npx = len(x) npy = len(y) npz = len(z) - X, Y, Z = np.meshgrid(np.sort(x), np.sort(y), np.sort(z)) + X, Y, Z = np.meshgrid(np.sort(x), np.sort(y), np.sort(z)) p = np.vstack((X.flatten('F'), Y.flatten('F'), Z.flatten('F'))) ix = np.arange(npx * npy * npz) ne = (npx - 1) * (npy - 1) * (npz - 1) @@ -237,7 +237,7 @@ def _build_mappings(self): self.f2t[0, e_first] = t_tmp[ix_first] self.f2t[1, e_last] = t_tmp[ix_last] - ## second row to zero if repeated (i.e., on boundary) + # second row to zero if repeated (i.e., on boundary) self.f2t[1, np.nonzero(self.f2t[0, :] == self.f2t[1, :])[0]] = -1 def _uniform_refine(self): diff --git a/skfem/mesh/mesh3d/mesh_tet.py b/skfem/mesh/mesh3d/mesh_tet.py index 084c16d81..444aa2316 100644 --- a/skfem/mesh/mesh3d/mesh_tet.py +++ b/skfem/mesh/mesh3d/mesh_tet.py @@ -129,24 +129,25 @@ def init_tensor(cls: Type[MeshType], # Copyright (c) 2016-2018 Nico Schlömer - # Permission is hereby granted, free of charge, to any person obtaining a - # copy of this software and associated documentation files (the + # Permission is hereby granted, free of charge, to any person obtaining + # a copy of this software and associated documentation files (the # "Software"), to deal in the Software without restriction, including # without limitation the rights to use, copy, modify, merge, publish, # distribute, sublicense, and/or sell copies of the Software, and to # permit persons to whom the Software is furnished to do so, subject to # the following conditions: - # The above copyright notice and this permission notice shall be included - # in all copies or substantial portions of the Software. + # The above copyright notice and this permission notice shall be + # included in all copies or substantial portions of the Software. - # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS - # OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + # EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF # MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND - # NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE - # LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION - # OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION - # WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + # NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS + # BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN + # ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN + # CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + # THE SOFTWARE. # Create the vertices. nx, ny, nz = len(x), len(y), len(z) diff --git a/skfem/mesh/mesh_line.py b/skfem/mesh/mesh_line.py index 9f96777be..668ca25c2 100644 --- a/skfem/mesh/mesh_line.py +++ b/skfem/mesh/mesh_line.py @@ -51,7 +51,7 @@ def __init__(self, self.p = p self.boundaries = boundaries self.subdomains = subdomains - + self.facets = np.arange(self.p.shape[1])[None, :] self.t = np.vstack([self.facets[0, :-1], self.facets[0, 1:]]) if t is None else t @@ -99,7 +99,9 @@ def _adaptive_refine(self, marked): newp = np.hstack((p, 0.5*(p[:, self.t[0, marked]] + p[:, self.t[1, marked]]))) newt = np.vstack((t[0, marked], mid)) - newt = np.hstack((t[:, nonmarked], newt, np.vstack((mid, t[1, marked])))) + newt = np.hstack((t[:, nonmarked], + newt, + np.vstack((mid, t[1, marked])))) # update fields self.p = newp @@ -156,7 +158,8 @@ def __mul__(self, other): return MeshQuad.init_tensor(self.p[0], other.p[0]) def param(self): - return np.max(np.abs(self.p[0, self.t[1, :]] - self.p[0, self.t[0, :]])) + return np.max(np.abs(self.p[0, self.t[1, :]] + - self.p[0, self.t[0, :]])) def mapping(self): from skfem.mapping import MappingAffine diff --git a/skfem/models/helpers.py b/skfem/models/helpers.py index 205a5685e..0cacf9a94 100644 --- a/skfem/models/helpers.py +++ b/skfem/models/helpers.py @@ -1,3 +1,3 @@ """Legacy location for skfem.helpers.""" -from skfem.helpers import * +from skfem.helpers import * # noqa From a3592598beffe4031af6c01ac925b3c5926aa9cd Mon Sep 17 00:00:00 2001 From: Tom Gustafsson Date: Tue, 2 Jun 2020 00:09:10 +0300 Subject: [PATCH 16/19] Fix flake8 errors --- skfem/io/json.py | 3 ++- skfem/io/meshio.py | 6 ++--- skfem/mesh/mesh.py | 6 +++-- skfem/mesh/mesh2d/mesh_tri.py | 47 ++++++++++++++++++----------------- skfem/mesh/mesh_line.py | 2 +- skfem/visuals/matplotlib.py | 6 ++--- 6 files changed, 37 insertions(+), 33 deletions(-) diff --git a/skfem/io/json.py b/skfem/io/json.py index 0d7fb337e..7a5f770a6 100644 --- a/skfem/io/json.py +++ b/skfem/io/json.py @@ -2,7 +2,8 @@ import json -from skfem.mesh import * +from skfem.mesh import MeshLine, MeshTri, MeshQuad,\ + MeshTet, MeshHex, Mesh def from_file(filename: str): diff --git a/skfem/io/meshio.py b/skfem/io/meshio.py index aa344ba1a..6bb076d94 100644 --- a/skfem/io/meshio.py +++ b/skfem/io/meshio.py @@ -78,7 +78,7 @@ def find_tagname(tag): return key return None - if m.cell_sets: # MSH 4.1 + if m.cell_sets: # MSH 4.1 subdomains = {k: v[meshio_type] for k, v in m.cell_sets_dict.items() if meshio_type in v} @@ -90,7 +90,7 @@ def find_tagname(tag): enumerate(map(tuple, mtmp.facets.T)) if f in v]) for k, v in facets.items()} - else: # MSH 2.2? + else: # MSH 2.2? elements_tag = m.cell_data_dict['gmsh:physical'][meshio_type] subdomains = {} tags = np.unique(elements_tag) @@ -124,7 +124,7 @@ def find_tagname(tag): mtmp.boundaries = boundaries mtmp.subdomains = subdomains - except Exception as e: + except Exception: warnings.warn("Unable to load tagged boundaries/subdomains.") return mtmp diff --git a/skfem/mesh/mesh.py b/skfem/mesh/mesh.py index 16409fccc..175dc4663 100644 --- a/skfem/mesh/mesh.py +++ b/skfem/mesh/mesh.py @@ -429,11 +429,13 @@ def __add__(self, other): boundaries = { **(self.boundaries if self.boundaries is not None else {}), **(other.boundaries if other.boundaries is not None else {}), - } if self.boundaries is not None or other.boundaries is not None else None + } if self.boundaries is not None or other.boundaries is not None\ + else None subdomains = { **(self.subdomains if self.subdomains is not None else {}), **(other.subdomains if other.subdomains is not None else {}), - } if self.subdomains is not None or other.subdomains is not None else None + } if self.subdomains is not None or other.subdomains is not None\ + else None return type(self)(p, t, boundaries, subdomains) @staticmethod diff --git a/skfem/mesh/mesh2d/mesh_tri.py b/skfem/mesh/mesh2d/mesh_tri.py index 9c396d805..9aec5a63b 100644 --- a/skfem/mesh/mesh2d/mesh_tri.py +++ b/skfem/mesh/mesh2d/mesh_tri.py @@ -177,7 +177,7 @@ def init_symmetric(cls) -> MeshType: @classmethod def init_sqsymmetric(cls: Type[MeshType]) -> MeshType: r"""Initialize a symmetric mesh of the unit square. - + The mesh topology is as follows:: *------*------* @@ -206,17 +206,17 @@ def init_sqsymmetric(cls: Type[MeshType]) -> MeshType: @classmethod def init_refdom(cls: Type[MeshType]) -> MeshType: r"""Initialize a mesh that includes only the reference triangle. - + The mesh topology is as follows:: * - |\ - | \ - | \ - | \ - | \ - | \ - | \ + |\ + | \ + | \ + | \ + | \ + | \ + | \ O-------------* """ @@ -228,7 +228,7 @@ def init_refdom(cls: Type[MeshType]) -> MeshType: @classmethod def init_lshaped(cls: Type[MeshType]) -> MeshType: r"""Initialize a mesh for the L-shaped domain. - + The mesh topology is as follows:: *-------* @@ -363,39 +363,40 @@ def find_facets(m, marked_elems): t2facets = facets[m.t2f] t2facets[2, t2facets[0, :] + t2facets[1, :] > 0] = 1 facets[m.t2f[t2facets == 1]] = 1 - + return facets def split_elements(m, facets): """Define new elements.""" ix = (-1)*np.ones(m.facets.shape[1], dtype=np.int64) - ix[facets == 1] = np.arange(np.count_nonzero(facets)) + m.p.shape[1] - ix = ix[m.t2f] # (0, 1) (1, 2) (0, 2) + ix[facets == 1] = (np.arange(np.count_nonzero(facets)) + + m.p.shape[1]) + ix = ix[m.t2f] # (0, 1) (1, 2) (0, 2) - red = (ix[0] >= 0) * (ix[1] >= 0) * (ix[2] >= 0) - blue1 = (ix[0] ==-1) * (ix[1] >= 0) * (ix[2] >= 0) - blue2 = (ix[0] >= 0) * (ix[1] ==-1) * (ix[2] >= 0) - green = (ix[0] ==-1) * (ix[1] ==-1) * (ix[2] >= 0) - rest = (ix[0] ==-1) * (ix[1] ==-1) * (ix[2] ==-1) + red = (ix[0] >= 0) * (ix[1] >= 0) * (ix[2] >= 0) # noqa + blue1 = (ix[0] ==-1) * (ix[1] >= 0) * (ix[2] >= 0) # noqa + blue2 = (ix[0] >= 0) * (ix[1] ==-1) * (ix[2] >= 0) # noqa + green = (ix[0] ==-1) * (ix[1] ==-1) * (ix[2] >= 0) # noqa + rest = (ix[0] ==-1) * (ix[1] ==-1) * (ix[2] ==-1) # noqa # new red elements t_red = np.hstack(( np.vstack((m.t[0, red], ix[0, red], ix[2, red])), np.vstack((m.t[1, red], ix[0, red], ix[1, red])), np.vstack((m.t[2, red], ix[1, red], ix[2, red])), - np.vstack(( ix[1, red], ix[2, red], ix[0, red])), + np.vstack(( ix[1, red], ix[2, red], ix[0, red])), # noqa )) # new blue elements t_blue1 = np.hstack(( np.vstack((m.t[1, blue1], m.t[0, blue1], ix[2, blue1])), - np.vstack((m.t[1, blue1], ix[1, blue1], ix[2, blue1])), - np.vstack((m.t[2, blue1], ix[2, blue1], ix[1, blue1])), + np.vstack((m.t[1, blue1], ix[1, blue1], ix[2, blue1])), # noqa + np.vstack((m.t[2, blue1], ix[2, blue1], ix[1, blue1])), # noqa )) t_blue2 = np.hstack(( - np.vstack((m.t[0, blue2], ix[0, blue2], ix[2, blue2])), - np.vstack(( ix[2, blue2], ix[0, blue2], m.t[1, blue2])), + np.vstack((m.t[0, blue2], ix[0, blue2], ix[2, blue2])), # noqa + np.vstack(( ix[2, blue2], ix[0, blue2], m.t[1, blue2])), # noqa np.vstack((m.t[2, blue2], ix[2, blue2], m.t[1, blue2])), )) diff --git a/skfem/mesh/mesh_line.py b/skfem/mesh/mesh_line.py index 668ca25c2..faccde348 100644 --- a/skfem/mesh/mesh_line.py +++ b/skfem/mesh/mesh_line.py @@ -47,7 +47,7 @@ def __init__(self, if p is None and t is None: p = np.array([[0., 1.]], dtype=np.float_) if len(p.shape) == 1: - p = np.array([p]) + p = np.array([p]) self.p = p self.boundaries = boundaries self.subdomains = subdomains diff --git a/skfem/visuals/matplotlib.py b/skfem/visuals/matplotlib.py index fe71c09c2..91ac5fe95 100644 --- a/skfem/visuals/matplotlib.py +++ b/skfem/visuals/matplotlib.py @@ -9,7 +9,8 @@ from numpy import ndarray from ..assembly import InteriorBasis -from ..mesh import * +from ..mesh import Mesh, Mesh2D, MeshLine,\ + MeshTri, MeshTet, MeshQuad @singledispatch @@ -30,7 +31,7 @@ def _(m: MeshTet, **kwargs) -> Axes: fig = plt.figure() ax = Axes3D(fig) indexing = m.facets[:, bnd_facets].T - ax.plot_trisurf(m.p[0, :], m.p[1, :], m.p[2,:], + ax.plot_trisurf(m.p[0, :], m.p[1, :], m.p[2, :], triangles=indexing, cmap=plt.cm.viridis, edgecolor='k') ax.set_axis_off() return ax @@ -109,7 +110,6 @@ def _(m: Mesh2D, **kwargs) -> Axes: return ax - @singledispatch def plot(m, u, **kwargs) -> Axes: """Plot functions defined on nodes of the mesh.""" From 09accff4ef47e339a9a12d0d199799b72b466bd7 Mon Sep 17 00:00:00 2001 From: Tom Gustafsson Date: Tue, 2 Jun 2020 00:14:08 +0300 Subject: [PATCH 17/19] Fix flake8 errors --- skfem/io/__init__.py | 2 +- skfem/io/json.py | 2 +- skfem/io/meshio.py | 3 ++- skfem/mesh/mesh.py | 4 ++-- skfem/mesh/mesh2d/mesh_tri.py | 4 ++-- skfem/visuals/__init__.py | 2 +- skfem/visuals/matplotlib.py | 4 ++-- 7 files changed, 11 insertions(+), 10 deletions(-) diff --git a/skfem/io/__init__.py b/skfem/io/__init__.py index d65017e61..65d0c6fb7 100644 --- a/skfem/io/__init__.py +++ b/skfem/io/__init__.py @@ -1 +1 @@ -from .meshio import from_meshio +from .meshio import from_meshio # noqa diff --git a/skfem/io/json.py b/skfem/io/json.py index 7a5f770a6..04f7f24c1 100644 --- a/skfem/io/json.py +++ b/skfem/io/json.py @@ -32,4 +32,4 @@ def from_file(filename: str): def to_file(mesh: Mesh, filename: str): with open(filename, 'w') as handle: - d = json.dump(mesh.to_dict(), handle) + _ = json.dump(mesh.to_dict(), handle) diff --git a/skfem/io/meshio.py b/skfem/io/meshio.py index 6bb076d94..f12782dae 100644 --- a/skfem/io/meshio.py +++ b/skfem/io/meshio.py @@ -29,7 +29,8 @@ def from_meshio(m, force_mesh_type=None): The mesh object from meshio. force_mesh_type An optional string forcing the mesh type if automatic detection - fails. See skfem.importers.meshio.MESH_TYPE_MAPPING for possible values. + fails. See skfem.importers.meshio.MESH_TYPE_MAPPING for possible + values. """ diff --git a/skfem/mesh/mesh.py b/skfem/mesh/mesh.py index 175dc4663..646fc6d81 100644 --- a/skfem/mesh/mesh.py +++ b/skfem/mesh/mesh.py @@ -430,12 +430,12 @@ def __add__(self, other): **(self.boundaries if self.boundaries is not None else {}), **(other.boundaries if other.boundaries is not None else {}), } if self.boundaries is not None or other.boundaries is not None\ - else None + else None subdomains = { **(self.subdomains if self.subdomains is not None else {}), **(other.subdomains if other.subdomains is not None else {}), } if self.subdomains is not None or other.subdomains is not None\ - else None + else None return type(self)(p, t, boundaries, subdomains) @staticmethod diff --git a/skfem/mesh/mesh2d/mesh_tri.py b/skfem/mesh/mesh2d/mesh_tri.py index 9aec5a63b..fa8ce44cf 100644 --- a/skfem/mesh/mesh2d/mesh_tri.py +++ b/skfem/mesh/mesh2d/mesh_tri.py @@ -371,7 +371,7 @@ def split_elements(m, facets): ix = (-1)*np.ones(m.facets.shape[1], dtype=np.int64) ix[facets == 1] = (np.arange(np.count_nonzero(facets)) + m.p.shape[1]) - ix = ix[m.t2f] # (0, 1) (1, 2) (0, 2) + ix = ix[m.t2f] red = (ix[0] >= 0) * (ix[1] >= 0) * (ix[2] >= 0) # noqa blue1 = (ix[0] ==-1) * (ix[1] >= 0) * (ix[2] >= 0) # noqa @@ -411,7 +411,7 @@ def split_elements(m, facets): m.p[:, m.facets[1, facets == 1]]) return np.hstack((m.p, p)),\ - np.hstack((m.t[:, rest], t_red, t_blue1, t_blue2, t_green)) + np.hstack((m.t[:, rest], t_red, t_blue1, t_blue2, t_green)) sorted_mesh = MeshTri(self.p, sort_mesh(self.p, self.t), sort_t=False) facets = find_facets(sorted_mesh, marked) diff --git a/skfem/visuals/__init__.py b/skfem/visuals/__init__.py index 8b1378917..4ede8e6df 100644 --- a/skfem/visuals/__init__.py +++ b/skfem/visuals/__init__.py @@ -1 +1 @@ - +# noqa diff --git a/skfem/visuals/matplotlib.py b/skfem/visuals/matplotlib.py index 91ac5fe95..90563c629 100644 --- a/skfem/visuals/matplotlib.py +++ b/skfem/visuals/matplotlib.py @@ -9,8 +9,8 @@ from numpy import ndarray from ..assembly import InteriorBasis -from ..mesh import Mesh, Mesh2D, MeshLine,\ - MeshTri, MeshTet, MeshQuad +from ..mesh import Mesh2D, MeshLine, MeshTri,\ + MeshTet, MeshQuad @singledispatch From 604038b03eb6a99f9c7dfa5f178369b82c633029 Mon Sep 17 00:00:00 2001 From: Tom Gustafsson Date: Tue, 2 Jun 2020 00:15:28 +0300 Subject: [PATCH 18/19] Fix flake8 errors --- skfem/mesh/mesh.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/skfem/mesh/mesh.py b/skfem/mesh/mesh.py index 646fc6d81..193f9a3d8 100644 --- a/skfem/mesh/mesh.py +++ b/skfem/mesh/mesh.py @@ -430,12 +430,12 @@ def __add__(self, other): **(self.boundaries if self.boundaries is not None else {}), **(other.boundaries if other.boundaries is not None else {}), } if self.boundaries is not None or other.boundaries is not None\ - else None + else None subdomains = { **(self.subdomains if self.subdomains is not None else {}), **(other.subdomains if other.subdomains is not None else {}), } if self.subdomains is not None or other.subdomains is not None\ - else None + else None return type(self)(p, t, boundaries, subdomains) @staticmethod From 83a27aa092f24f682f3683ff8291227a9dfcbdba Mon Sep 17 00:00:00 2001 From: Tom Gustafsson Date: Tue, 2 Jun 2020 00:24:52 +0300 Subject: [PATCH 19/19] Add flake8 configuration file --- .flake8 | 9 +++++++++ 1 file changed, 9 insertions(+) create mode 100644 .flake8 diff --git a/.flake8 b/.flake8 new file mode 100644 index 000000000..97621075b --- /dev/null +++ b/.flake8 @@ -0,0 +1,9 @@ +[flake8] +ignore = W504,W503,E226,E126,E123,E121,E24,E704,E741 +exclude = + docs + .git + .github + paper + tests + setup.py \ No newline at end of file