Skip to content

Commit

Permalink
Add flake8 and isort checks on python files in cpp folder (#2838)
Browse files Browse the repository at this point in the history
* Add flake8 checks on python files in cpp folder

* flake8 fixes in cpp

* Add isort checks on python files in cpp folder

* Move flake8 marker to root directory

* Remove python/.flake8
  • Loading branch information
francesco-ballarin committed Oct 30, 2023
1 parent 9210862 commit 20a45a9
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 11 deletions.
File renamed without changes.
8 changes: 8 additions & 0 deletions .github/workflows/ccpp.yml
Original file line number Diff line number Diff line change
Expand Up @@ -67,13 +67,21 @@ jobs:
- name: Flake8 checks
run: |
cd cpp/
python3 -m flake8 cmake
python3 -m flake8 demo
python3 -m flake8 test
cd ..
cd python/
python3 -m flake8 dolfinx
python3 -m flake8 demo
python3 -m flake8 test
- name: isort checks (non-blocking)
continue-on-error: true
run: |
cd cpp/
python3 -m isort --check .
cd ..
cd python/
python3 -m isort --check .
- name: mypy checks
Expand Down
14 changes: 7 additions & 7 deletions cpp/demo/hyperelasticity/hyperelasticity.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,9 @@

# Kinematics
d = len(u)
I = Identity(d) # Identity tensor
I = Identity(d) # Identity tensor # noqa: E741
F = variable(I + grad(u)) # Deformation gradient
C = F.T*F # Right Cauchy-Green tensor
C = F.T * F # Right Cauchy-Green tensor

# Invariants of deformation tensors
Ic = tr(C)
Expand All @@ -52,18 +52,18 @@
# Elasticity parameters
E = 10.0
nu = 0.3
mu = E/(2*(1 + nu))
lmbda = E*nu/((1 + nu)*(1 - 2*nu))
mu = E / (2 * (1 + nu))
lmbda = E * nu / ((1 + nu) * (1 - 2 * nu))

# Both the first variation of the potential energy, and the Jacobian of
# the variation, can be automatically computed by a call to
# ``derivative``::

# Stored strain energy density (compressible neo-Hookean model)
psi = (mu/2)*(Ic - 3) - mu*ln(J) + (lmbda/2)*(ln(J))**2
psi = (mu / 2) * (Ic - 3) - mu * ln(J) + (lmbda / 2) * (ln(J))**2

# Total potential energy
Pi = psi*dx # - inner(B, u)*dx - inner(T, u)*ds
Pi = psi * dx # - inner(B, u) * dx - inner(T, u) * ds

# First variation of Pi (directional derivative about u in the direction of v)
F_form = derivative(Pi, u, v)
Expand All @@ -72,7 +72,7 @@
J_form = derivative(F_form, u, du)

# Compute Cauchy stress
sigma = (1/J)*diff(psi, F)*F.T
sigma = (1 / J) * diff(psi, F) * F.T

forms = [F_form, J_form]
elements = [e]
Expand Down
2 changes: 1 addition & 1 deletion cpp/demo/poisson_matrix_free/poisson.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
from ufl import (Coefficient, Constant, FunctionSpace, Mesh, TestFunction,
TrialFunction, action, dx, grad, inner)

coord_element = element("Lagrange", "triangle", 1, shape=(2,))
coord_element = element("Lagrange", "triangle", 1, shape=(2,))
mesh = Mesh(coord_element)

# Function Space
Expand Down
6 changes: 3 additions & 3 deletions cpp/test/poisson.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
from ufl import (Coefficient, Constant, FunctionSpace, Mesh,
TestFunction, TrialFunction, dx, grad, inner)
from basix.ufl import element
from ufl import (Coefficient, Constant, FunctionSpace, Mesh, TestFunction,
TrialFunction, dx, grad, inner)

e = element("Lagrange", "tetrahedron", 2)
coord_element = element("Lagrange", "tetrahedron", 1, shape=(3,))
coord_element = element("Lagrange", "tetrahedron", 1, shape=(3,))
mesh = Mesh(coord_element)

V = FunctionSpace(mesh, e)
Expand Down

0 comments on commit 20a45a9

Please sign in to comment.