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

Apply black formatting (using ruff) and the ruff linter #256

Merged
merged 6 commits into from
Feb 10, 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
6 changes: 0 additions & 6 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 @@ -28,14 +28,11 @@ jobs:
uses: actions/setup-python@v5
with:
python-version: ${{ matrix.python-version }}
- name: Lint with flake8
- name: Lint with ruff
run: |
python -m pip install flake8
flake8 --statistics .
- name: Check documentation style
run: |
python -m pip install pydocstyle[toml]
python -m pydocstyle ufl/
pip install ruff
ruff check .
ruff format --check .
- name: Install UFL
run: python -m pip install .[ci]
- name: Run unit tests
Expand Down
18 changes: 15 additions & 3 deletions demo/Constant.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,27 @@
# Modified by Martin Sandve Alnes, 2009
#
# Test form for scalar and vector constants.
from ufl import (Coefficient, Constant, FunctionSpace, Mesh, TestFunction, TrialFunction, VectorConstant, dot, dx, grad,
inner, triangle)
from ufl import (
Coefficient,
Constant,
FunctionSpace,
Mesh,
TestFunction,
TrialFunction,
VectorConstant,
dot,
dx,
grad,
inner,
triangle,
)
from ufl.finiteelement import FiniteElement
from ufl.pullback import identity_pullback
from ufl.sobolevspace import H1

cell = triangle
element = FiniteElement("Lagrange", cell, 1, (), identity_pullback, H1)
domain = Mesh(FiniteElement("Lagrange", cell, 1, (2, ), identity_pullback, H1))
domain = Mesh(FiniteElement("Lagrange", cell, 1, (2,), identity_pullback, H1))
space = FunctionSpace(domain, element)

v = TestFunction(space)
Expand Down
16 changes: 13 additions & 3 deletions demo/ConvectionJacobi.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,23 @@
# Author: Martin Sandve Alnes
# Date: 2008-10-03
#
from ufl import Coefficient, FunctionSpace, Mesh, TestFunction, TrialFunction, dot, dx, grad, triangle
from ufl import (
Coefficient,
FunctionSpace,
Mesh,
TestFunction,
TrialFunction,
dot,
dx,
grad,
triangle,
)
from ufl.finiteelement import FiniteElement
from ufl.pullback import identity_pullback
from ufl.sobolevspace import H1

element = FiniteElement("Lagrange", triangle, 1, (2, ), identity_pullback, H1)
domain = Mesh(FiniteElement("Lagrange", triangle, 1, (2, ), identity_pullback, H1))
element = FiniteElement("Lagrange", triangle, 1, (2,), identity_pullback, H1)
domain = Mesh(FiniteElement("Lagrange", triangle, 1, (2,), identity_pullback, H1))
space = FunctionSpace(domain, element)

u = TrialFunction(space)
Expand Down
4 changes: 2 additions & 2 deletions demo/ConvectionJacobi2.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@
from ufl.pullback import identity_pullback
from ufl.sobolevspace import H1

element = FiniteElement("Lagrange", triangle, 1, (2, ), identity_pullback, H1)
domain = Mesh(FiniteElement("Lagrange", triangle, 1, (2, ), identity_pullback, H1))
element = FiniteElement("Lagrange", triangle, 1, (2,), identity_pullback, H1)
domain = Mesh(FiniteElement("Lagrange", triangle, 1, (2,), identity_pullback, H1))
space = FunctionSpace(domain, element)

u = TrialFunction(space)
Expand Down
4 changes: 2 additions & 2 deletions demo/ConvectionVector.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@
from ufl.pullback import identity_pullback
from ufl.sobolevspace import H1

element = FiniteElement("Lagrange", triangle, 1, (2, ), identity_pullback, H1)
domain = Mesh(FiniteElement("Lagrange", triangle, 1, (2, ), identity_pullback, H1))
element = FiniteElement("Lagrange", triangle, 1, (2,), identity_pullback, H1)
domain = Mesh(FiniteElement("Lagrange", triangle, 1, (2,), identity_pullback, H1))
space = FunctionSpace(domain, element)

v = TestFunction(space)
Expand Down
4 changes: 2 additions & 2 deletions demo/Elasticity.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@
from ufl.pullback import identity_pullback
from ufl.sobolevspace import H1

element = FiniteElement("Lagrange", tetrahedron, 1, (3, ), identity_pullback, H1)
domain = Mesh(FiniteElement("Lagrange", tetrahedron, 1, (3, ), identity_pullback, H1))
element = FiniteElement("Lagrange", tetrahedron, 1, (3,), identity_pullback, H1)
domain = Mesh(FiniteElement("Lagrange", tetrahedron, 1, (3,), identity_pullback, H1))
space = FunctionSpace(domain, element)

v = TestFunction(space)
Expand Down
2 changes: 1 addition & 1 deletion demo/EnergyNorm.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
from ufl.sobolevspace import H1

element = FiniteElement("Lagrange", tetrahedron, 1, (), identity_pullback, H1)
domain = Mesh(FiniteElement("Lagrange", tetrahedron, 1, (3, ), identity_pullback, H1))
domain = Mesh(FiniteElement("Lagrange", tetrahedron, 1, (3,), identity_pullback, H1))
space = FunctionSpace(domain, element)

v = Coefficient(space)
Expand Down
16 changes: 14 additions & 2 deletions demo/Equation.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,13 +34,25 @@
# the unknown u to the right-hand side, all terms may
# be listed on one line and left- and right-hand sides
# extracted by lhs() and rhs().
from ufl import Coefficient, FunctionSpace, Mesh, TestFunction, TrialFunction, dot, dx, grad, lhs, rhs, triangle
from ufl import (
Coefficient,
FunctionSpace,
Mesh,
TestFunction,
TrialFunction,
dot,
dx,
grad,
lhs,
rhs,
triangle,
)
from ufl.finiteelement import FiniteElement
from ufl.pullback import identity_pullback
from ufl.sobolevspace import H1

element = FiniteElement("Lagrange", triangle, 1, (), identity_pullback, H1)
domain = Mesh(FiniteElement("Lagrange", triangle, 1, (2, ), identity_pullback, H1))
domain = Mesh(FiniteElement("Lagrange", triangle, 1, (2,), identity_pullback, H1))
space = FunctionSpace(domain, element)

k = 0.1
Expand Down
16 changes: 13 additions & 3 deletions demo/ExplicitConvection.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,23 @@
# Author: Martin Sandve Alnes
# Date: 2008-10-03
#
from ufl import Coefficient, FunctionSpace, Mesh, TestFunction, TrialFunction, dot, dx, grad, triangle
from ufl import (
Coefficient,
FunctionSpace,
Mesh,
TestFunction,
TrialFunction,
dot,
dx,
grad,
triangle,
)
from ufl.finiteelement import FiniteElement
from ufl.pullback import identity_pullback
from ufl.sobolevspace import H1

element = FiniteElement("Lagrange", triangle, 1, (2, ), identity_pullback, H1)
domain = Mesh(FiniteElement("Lagrange", triangle, 1, (2, ), identity_pullback, H1))
element = FiniteElement("Lagrange", triangle, 1, (2,), identity_pullback, H1)
domain = Mesh(FiniteElement("Lagrange", triangle, 1, (2,), identity_pullback, H1))
space = FunctionSpace(domain, element)

u = TrialFunction(space)
Expand Down
21 changes: 18 additions & 3 deletions demo/FunctionOperators.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,18 +16,33 @@
# along with UFL. If not, see <http://www.gnu.org/licenses/>.
#
# Test form for operators on Coefficients.
from ufl import Coefficient, FunctionSpace, Mesh, TestFunction, TrialFunction, dot, dx, grad, max_value, sqrt, triangle
from ufl import (
Coefficient,
FunctionSpace,
Mesh,
TestFunction,
TrialFunction,
dot,
dx,
grad,
max_value,
sqrt,
triangle,
)
from ufl.finiteelement import FiniteElement
from ufl.pullback import identity_pullback
from ufl.sobolevspace import H1

element = FiniteElement("Lagrange", triangle, 1, (), identity_pullback, H1)
domain = Mesh(FiniteElement("Lagrange", triangle, 1, (2, ), identity_pullback, H1))
domain = Mesh(FiniteElement("Lagrange", triangle, 1, (2,), identity_pullback, H1))
space = FunctionSpace(domain, element)

v = TestFunction(space)
u = TrialFunction(space)
f = Coefficient(space)
g = Coefficient(space)

a = sqrt(1 / max_value(1 / f, -1 / f)) * sqrt(g) * dot(grad(v), grad(u)) * dx + v * u * sqrt(f * g) * g * dx
a = (
sqrt(1 / max_value(1 / f, -1 / f)) * sqrt(g) * dot(grad(v), grad(u)) * dx
+ v * u * sqrt(f * g) * g * dx
)
2 changes: 1 addition & 1 deletion demo/H1norm.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
from ufl.sobolevspace import H1

element = FiniteElement("Lagrange", triangle, 1, (), identity_pullback, H1)
domain = Mesh(FiniteElement("Lagrange", triangle, 1, (2, ), identity_pullback, H1))
domain = Mesh(FiniteElement("Lagrange", triangle, 1, (2,), identity_pullback, H1))
space = FunctionSpace(domain, element)

f = Coefficient(space)
Expand Down
4 changes: 2 additions & 2 deletions demo/HarmonicMap.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@
from ufl.sobolevspace import H1

cell = triangle
X = FiniteElement("Lagrange", cell, 1, (2, ), identity_pullback, H1)
X = FiniteElement("Lagrange", cell, 1, (2,), identity_pullback, H1)
Y = FiniteElement("Lagrange", cell, 1, (), identity_pullback, H1)
domain = Mesh(FiniteElement("Lagrange", cell, 1, (2, ), identity_pullback, H1))
domain = Mesh(FiniteElement("Lagrange", cell, 1, (2,), identity_pullback, H1))
X_space = FunctionSpace(domain, X)
Y_space = FunctionSpace(domain, Y)

Expand Down
4 changes: 2 additions & 2 deletions demo/HarmonicMap2.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,10 @@
from ufl.sobolevspace import H1

cell = triangle
X = FiniteElement("Lagrange", cell, 1, (2, ), identity_pullback, H1)
X = FiniteElement("Lagrange", cell, 1, (2,), identity_pullback, H1)
Y = FiniteElement("Lagrange", cell, 1, (), identity_pullback, H1)
M = MixedElement([X, Y])
domain = Mesh(FiniteElement("Lagrange", cell, 1, (2, ), identity_pullback, H1))
domain = Mesh(FiniteElement("Lagrange", cell, 1, (2,), identity_pullback, H1))
space = FunctionSpace(domain, M)

u = Coefficient(space)
Expand Down
23 changes: 17 additions & 6 deletions demo/Heat.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,22 +20,33 @@
# The bilinear form a(v, u1) and linear form L(v) for
# one backward Euler step with the heat equation.
#
from ufl import Coefficient, Constant, FunctionSpace, Mesh, TestFunction, TrialFunction, dot, dx, grad, triangle
from ufl import (
Coefficient,
Constant,
FunctionSpace,
Mesh,
TestFunction,
TrialFunction,
dot,
dx,
grad,
triangle,
)
from ufl.finiteelement import FiniteElement
from ufl.pullback import identity_pullback
from ufl.sobolevspace import H1

cell = triangle
element = FiniteElement("Lagrange", cell, 1, (), identity_pullback, H1)
domain = Mesh(FiniteElement("Lagrange", cell, 1, (2, ), identity_pullback, H1))
domain = Mesh(FiniteElement("Lagrange", cell, 1, (2,), identity_pullback, H1))
space = FunctionSpace(domain, element)

v = TestFunction(space) # Test function
u1 = TrialFunction(space) # Value at t_n
u0 = Coefficient(space) # Value at t_n-1
c = Coefficient(space) # Heat conductivity
f = Coefficient(space) # Heat source
k = Constant(domain) # Time step
u0 = Coefficient(space) # Value at t_n-1
c = Coefficient(space) # Heat conductivity
f = Coefficient(space) # Heat source
k = Constant(domain) # Time step

a = v * u1 * dx + k * c * dot(grad(v), grad(u1)) * dx
L = v * u0 * dx + k * v * f * dx
20 changes: 15 additions & 5 deletions demo/HornSchunck.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,27 @@
# http://code.google.com/p/debiosee/wiki/DemosOptiocFlowHornSchunck
# but not tested so this could contain errors!
#
from ufl import Coefficient, Constant, FunctionSpace, Mesh, derivative, dot, dx, grad, inner, triangle
from ufl import (
Coefficient,
Constant,
FunctionSpace,
Mesh,
derivative,
dot,
dx,
grad,
inner,
triangle,
)
from ufl.finiteelement import FiniteElement
from ufl.pullback import identity_pullback
from ufl.sobolevspace import H1

# Finite element spaces for scalar and vector fields
cell = triangle
S = FiniteElement("Lagrange", cell, 1, (), identity_pullback, H1)
V = FiniteElement("Lagrange", cell, 1, (2, ), identity_pullback, H1)
domain = Mesh(FiniteElement("Lagrange", cell, 1, (2, ), identity_pullback, H1))
V = FiniteElement("Lagrange", cell, 1, (2,), identity_pullback, H1)
domain = Mesh(FiniteElement("Lagrange", cell, 1, (2,), identity_pullback, H1))
S_space = FunctionSpace(domain, S)
V_space = FunctionSpace(domain, V)

Expand All @@ -29,8 +40,7 @@
lamda = Constant(domain)

# Coefficiental to minimize
M = (dot(u, grad(I1)) + (I1 - I0))**2 * dx\
+ lamda * inner(grad(u), grad(u)) * dx
M = (dot(u, grad(I1)) + (I1 - I0)) ** 2 * dx + lamda * inner(grad(u), grad(u)) * dx

# Derived linear system
L = derivative(M, u)
Expand Down
Loading
Loading