Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Black formatting and ruff linting #669

Merged
merged 11 commits into from
Feb 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 0 additions & 8 deletions .flake8

This file was deleted.

11 changes: 4 additions & 7 deletions .github/workflows/pythonapp.yml
Original file line number Diff line number Diff line change
Expand Up @@ -42,16 +42,13 @@ jobs:
pip install git+https://github.com/FEniCS/basix.git
- name: Install FFCx
run: pip install .[ci]
- name: Lint with flake8
run: flake8 --statistics ffcx/ test/
- name: Static check with mypy
run: mypy ffcx/
if: matrix.python-version != '3.12'
- name: isort checks (non-blocking)
continue-on-error: true
run: isort --check .
- name: Check documentation style
run: pydocstyle .
- name: ruff checks
run: |
ruff check .
ruff format --check .
- name: Run units tests
run: python -m pytest -n auto --cov=ffcx/ --junitxml=junit/test-results-${{ matrix.os }}-${{ matrix.python-version }}.xml test/
- name: Upload to Coveralls
Expand Down
5 changes: 0 additions & 5 deletions .isort.cfg

This file was deleted.

31 changes: 23 additions & 8 deletions demo/BiharmonicHHJ.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,26 @@
"""

import basix.ufl
from ufl import (Coefficient, FacetNormal, FunctionSpace, Mesh, TestFunctions,
TrialFunctions, dot, dS, ds, dx, grad, inner, jump)

HHJ = basix.ufl.element('HHJ', "triangle", 2)
P = basix.ufl.element('P', "triangle", 3)
from ufl import (
Coefficient,
FacetNormal,
FunctionSpace,
Mesh,
TestFunctions,
TrialFunctions,
dot,
dS,
ds,
dx,
grad,
inner,
jump,
)

HHJ = basix.ufl.element("HHJ", "triangle", 2)
P = basix.ufl.element("P", "triangle", 3)
mixed_element = basix.ufl.mixed_element([HHJ, P])
domain = Mesh(basix.ufl.element("P", "triangle", 1, shape=(2, )))
domain = Mesh(basix.ufl.element("P", "triangle", 1, shape=(2,)))
mixed_space = FunctionSpace(domain, mixed_element)
p_space = FunctionSpace(domain, P)

Expand All @@ -24,9 +37,11 @@
def b(sigma, v):
"""The form b."""
n = FacetNormal(domain)
return inner(sigma, grad(grad(v))) * dx \
- dot(dot(sigma('+'), n('+')), n('+')) * jump(grad(v), n) * dS \
return (
inner(sigma, grad(grad(v))) * dx
- dot(dot(sigma("+"), n("+")), n("+")) * jump(grad(v), n) * dS
- dot(dot(sigma, n), n) * dot(grad(v), n) * ds
)


a = inner(sigma, tau) * dx - b(tau, u) + b(sigma, v)
Expand Down
28 changes: 22 additions & 6 deletions demo/BiharmonicRegge.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,28 @@
The bilinear form a(u, v) and linear form L(v) for Biharmonic equation in Regge formulation.
"""
import basix.ufl
from ufl import (Coefficient, FacetNormal, FunctionSpace, Identity, Mesh,
TestFunctions, TrialFunctions, dot, dS, ds, dx, grad, inner,
jump, tr)
from ufl import (
Coefficient,
FacetNormal,
FunctionSpace,
Identity,
Mesh,
TestFunctions,
TrialFunctions,
dot,
dS,
ds,
dx,
grad,
inner,
jump,
tr,
)

REG = basix.ufl.element("Regge", "tetrahedron", 1)
P = basix.ufl.element("Lagrange", "tetrahedron", 2)
mixed_element = basix.ufl.mixed_element([REG, P])
domain = Mesh(basix.ufl.element("P", "tetrahedron", 1, shape=(3, )))
domain = Mesh(basix.ufl.element("P", "tetrahedron", 1, shape=(3,)))
mixed_space = FunctionSpace(domain, mixed_element)
p_space = FunctionSpace(domain, P)

Expand All @@ -28,9 +42,11 @@ def S(mu):
def b(mu, v):
"""The form b."""
n = FacetNormal(domain)
return inner(S(mu), grad(grad(v))) * dx \
- dot(dot(S(mu('+')), n('+')), n('+')) * jump(grad(v), n) * dS \
return (
inner(S(mu), grad(grad(v))) * dx
- dot(dot(S(mu("+")), n("+")), n("+")) * jump(grad(v), n) * dS
- dot(dot(S(mu), n), n) * dot(grad(v), n) * ds
)


a = inner(S(sigma), S(tau)) * dx - b(tau, u) + b(sigma, v)
Expand Down
22 changes: 17 additions & 5 deletions demo/CellGeometry.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,23 +5,35 @@
"""

import basix.ufl
from ufl import (CellVolume, Circumradius, Coefficient, FacetArea, FacetNormal,
FunctionSpace, Mesh, SpatialCoordinate, TrialFunction, ds, dx)
from ufl import (
CellVolume,
Circumradius,
Coefficient,
FacetArea,
FacetNormal,
FunctionSpace,
Mesh,
SpatialCoordinate,
TrialFunction,
ds,
dx,
)
from ufl.geometry import FacetEdgeVectors

V = basix.ufl.element("P", "tetrahedron", 1)
domain = Mesh(basix.ufl.element("P", "tetrahedron", 1, shape=(3, )))
domain = Mesh(basix.ufl.element("P", "tetrahedron", 1, shape=(3,)))
space = FunctionSpace(domain, V)
u = Coefficient(space)

# TODO: Add all geometry for all cell types to this and other demo files, need for regression test.
# TODO: Add all geometry for all cell types to this and other demo
# files, need for regression test.
x = SpatialCoordinate(domain)
n = FacetNormal(domain)
vol = CellVolume(domain)
rad = Circumradius(domain)
area = FacetArea(domain)

M = u * (x[0] * vol * rad) * dx + u * (x[0] * vol * rad * area) * ds # + u*area*avg(n[0]*x[0]*vol*rad)*dS
M = u * (x[0] * vol * rad) * dx + u * (x[0] * vol * rad * area) * ds

# Test some obscure functionality
fev = FacetEdgeVectors(domain)
Expand Down
5 changes: 2 additions & 3 deletions demo/ComplexPoisson.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,9 @@
"""

import basix.ufl
from ufl import (Coefficient, FunctionSpace, Mesh, TestFunction, TrialFunction,
dx, grad, inner)
from ufl import Coefficient, FunctionSpace, Mesh, TestFunction, TrialFunction, dx, grad, inner

coords = basix.ufl.element("P", "triangle", 2, shape=(2, ))
coords = basix.ufl.element("P", "triangle", 2, shape=(2,))
mesh = Mesh(coords)
dx = dx(mesh)

Expand Down
5 changes: 2 additions & 3 deletions demo/Components.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,9 @@
"""

import basix.ufl
from ufl import (Coefficient, FunctionSpace, Mesh, TestFunction, as_vector, dx,
inner)
from ufl import Coefficient, FunctionSpace, Mesh, TestFunction, as_vector, dx, inner

element = basix.ufl.element("Lagrange", "tetrahedron", 1, shape=(3, ))
element = basix.ufl.element("Lagrange", "tetrahedron", 1, shape=(3,))
domain = Mesh(element)
space = FunctionSpace(domain, element)

Expand Down
26 changes: 20 additions & 6 deletions demo/Conditional.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,20 +20,34 @@
"""

import basix.ufl
from ufl import (And, Constant, FunctionSpace, Mesh, Not, Or,
SpatialCoordinate, TestFunction, conditional, dx, ge, gt,
inner, le, lt)
from ufl import (
And,
Constant,
FunctionSpace,
Mesh,
Not,
Or,
SpatialCoordinate,
TestFunction,
conditional,
dx,
ge,
gt,
inner,
le,
lt,
)

element = basix.ufl.element("Lagrange", "triangle", 2)
domain = Mesh(basix.ufl.element("Lagrange", "triangle", 1, shape=(2, )))
domain = Mesh(basix.ufl.element("Lagrange", "triangle", 1, shape=(2,)))
space = FunctionSpace(domain, element)

v = TestFunction(space)
g = Constant(domain)

x = SpatialCoordinate(domain)
c0 = conditional(le((x[0] - 0.33)**2 + (x[1] - 0.67)**2, 0.015), -1.0, 5.0)
c = conditional(le((x[0] - 0.33)**2 + (x[1] - 0.67)**2, 0.025), c0, 0.0)
c0 = conditional(le((x[0] - 0.33) ** 2 + (x[1] - 0.67) ** 2, 0.015), -1.0, 5.0)
c = conditional(le((x[0] - 0.33) ** 2 + (x[1] - 0.67) ** 2, 0.025), c0, 0.0)

t0 = And(ge(x[0], 0.55), le(x[0], 0.95))
t1 = Or(lt(x[1], 0.05), gt(x[1], 0.45))
Expand Down
11 changes: 6 additions & 5 deletions demo/ExpressionInterpolation.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,12 @@

# Define mesh
cell = "triangle"
v_el = basix.ufl.element("Lagrange", cell, 1, shape=(2, ))
v_el = basix.ufl.element("Lagrange", cell, 1, shape=(2,))
mesh = Mesh(v_el)

# Define mixed function space
el = basix.ufl.element("P", cell, 2)
el_int = basix.ufl.element("Discontinuous Lagrange", cell, 1, shape=(2, ))
el_int = basix.ufl.element("Discontinuous Lagrange", cell, 1, shape=(2,))
me = basix.ufl.mixed_element([el, el_int])
V = FunctionSpace(mesh, me)
u = Coefficient(V)
Expand All @@ -57,9 +57,10 @@

# Get interpolation points for output space
family = basix.finite_element.string_to_family("Lagrange", cell)
b_element = basix.create_element(family, b_cell, 4, basix.LagrangeVariant.gll_warped, discontinuous=True)
b_element = basix.create_element(
family, b_cell, 4, basix.LagrangeVariant.gll_warped, discontinuous=True
)
interpolation_points = b_element.points

# Create expressions that can be used for interpolation
expressions = [(du0, interpolation_points), (du1, interpolation_points),
(powq, quadrature_points)]
expressions = [(du0, interpolation_points), (du1, interpolation_points), (powq, quadrature_points)]
25 changes: 19 additions & 6 deletions demo/FacetIntegrals.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,19 +20,32 @@
"""

import basix.ufl
from ufl import (FacetNormal, FunctionSpace, Mesh, TestFunction, TrialFunction,
avg, ds, dS, grad, inner, jump)
from ufl import (
FacetNormal,
FunctionSpace,
Mesh,
TestFunction,
TrialFunction,
avg,
dS,
ds,
grad,
inner,
jump,
)

element = basix.ufl.element("Discontinuous Lagrange", "triangle", 1)
domain = Mesh(basix.ufl.element("Lagrange", "triangle", 1, shape=(2, )))
domain = Mesh(basix.ufl.element("Lagrange", "triangle", 1, shape=(2,)))
space = FunctionSpace(domain, element)

u = TrialFunction(space)
v = TestFunction(space)

n = FacetNormal(domain)

a = inner(u, v) * ds \
+ inner(u('+'), v('-')) * dS \
+ inner(jump(u, n), avg(grad(v))) * dS \
a = (
inner(u, v) * ds
+ inner(u("+"), v("-")) * dS
+ inner(jump(u, n), avg(grad(v))) * dS
+ inner(avg(grad(u)), jump(v, n)) * dS
)
17 changes: 14 additions & 3 deletions demo/FacetRestrictionAD.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,22 @@
"""Facet restriction demo."""

import basix.ufl
from ufl import (Coefficient, FunctionSpace, Mesh, TestFunction, TrialFunction,
avg, derivative, dS, dx, grad, inner)
from ufl import (
Coefficient,
FunctionSpace,
Mesh,
TestFunction,
TrialFunction,
avg,
derivative,
dS,
dx,
grad,
inner,
)

element = basix.ufl.element("Discontinuous Lagrange", "triangle", 1)
domain = Mesh(basix.ufl.element("Lagrange", "triangle", 1, shape=(2, )))
domain = Mesh(basix.ufl.element("Lagrange", "triangle", 1, shape=(2,)))
space = FunctionSpace(domain, element)

v = TestFunction(space)
Expand Down
Loading