Skip to content

Commit 65d96e1

Browse files
authored
Update UFL element (#614)
* remove convert_element * update UFL interface * branches * update ufl interface, remove family string * DOLFINx branch * fix final test * simplify * flake * update demos * ufl branch (for demos) * no UFL demos * update pull back interface * update CI name * gdim * AUTHORS * pull_back -> pullback * degree() -> degree * add newline to readme * Revert "add newline to readme" This reverts commit 5c0224a. * replace rank with shape * shape not rank * branches
1 parent 330f200 commit 65d96e1

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

45 files changed

+292
-257
lines changed

.github/workflows/pythonapp.yml

+1-9
Original file line numberDiff line numberDiff line change
@@ -94,16 +94,8 @@ jobs:
9494
# when there are test failures
9595
if: always()
9696

97-
- name: Get UFL
98-
uses: actions/checkout@v3
99-
with:
100-
path: ./ufl
101-
repository: FEniCS/ufl
102-
ref: main
103-
104-
- name: Run FFCx and UFL demos
97+
- name: Run FFCx demos
10598
run: |
106-
mv ufl/demo/* demo/
10799
pytest demo/test_demos.py
108100
rm -Rf ufl/
109101

AUTHORS

+3
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,9 @@ Contributors:
6060
Ivan Yashchuk
6161
6262

63+
Matthew Scroggs
64+
65+
www: https://mscroggs.co.uk
6366

6467
Credits for UFC
6568
===============

demo/BiharmonicHHJ.py

+9-6
Original file line numberDiff line numberDiff line change
@@ -4,20 +4,23 @@
44
# Biharmonic equation in Hellan-Herrmann-Johnson (HHJ)
55
# formulation.
66
import basix.ufl
7-
from ufl import (Coefficient, FacetNormal, TestFunctions, TrialFunctions, dot,
8-
dS, ds, dx, grad, inner, jump, triangle)
7+
from ufl import (Coefficient, FacetNormal, FunctionSpace, Mesh, TestFunctions,
8+
TrialFunctions, dot, dS, ds, dx, grad, inner, jump)
99

1010
HHJ = basix.ufl.element('HHJ', "triangle", 2)
1111
P = basix.ufl.element('P', "triangle", 3)
1212
mixed_element = basix.ufl.mixed_element([HHJ, P])
13+
domain = Mesh(basix.ufl.element("P", "triangle", 1, shape=(2, )))
14+
mixed_space = FunctionSpace(domain, mixed_element)
15+
p_space = FunctionSpace(domain, P)
1316

14-
(sigma, u) = TrialFunctions(mixed_element)
15-
(tau, v) = TestFunctions(mixed_element)
16-
f = Coefficient(P)
17+
(sigma, u) = TrialFunctions(mixed_space)
18+
(tau, v) = TestFunctions(mixed_space)
19+
f = Coefficient(p_space)
1720

1821

1922
def b(sigma, v):
20-
n = FacetNormal(triangle)
23+
n = FacetNormal(domain)
2124
return inner(sigma, grad(grad(v))) * dx \
2225
- dot(dot(sigma('+'), n('+')), n('+')) * jump(grad(v), n) * dS \
2326
- dot(dot(sigma, n), n) * dot(grad(v), n) * ds

demo/BiharmonicRegge.py

+10-7
Original file line numberDiff line numberDiff line change
@@ -3,25 +3,28 @@
33
# The bilinear form a(u, v) and linear form L(v) for
44
# Biharmonic equation in Regge formulation.
55
import basix.ufl
6-
from ufl import (Coefficient, FacetNormal, Identity, TestFunctions,
7-
TrialFunctions, dot, dS, ds, dx, grad, inner, jump,
8-
tetrahedron, tr)
6+
from ufl import (Coefficient, FacetNormal, FunctionSpace, Identity, Mesh,
7+
TestFunctions, TrialFunctions, dot, dS, ds, dx, grad, inner,
8+
jump, tr)
99

1010
REG = basix.ufl.element("Regge", "tetrahedron", 1)
1111
P = basix.ufl.element("Lagrange", "tetrahedron", 2)
1212
mixed_element = basix.ufl.mixed_element([REG, P])
13+
domain = Mesh(basix.ufl.element("P", "tetrahedron", 1, shape=(3, )))
14+
mixed_space = FunctionSpace(domain, mixed_element)
15+
p_space = FunctionSpace(domain, P)
1316

14-
(sigma, u) = TrialFunctions(mixed_element)
15-
(tau, v) = TestFunctions(mixed_element)
16-
f = Coefficient(P)
17+
(sigma, u) = TrialFunctions(mixed_space)
18+
(tau, v) = TestFunctions(mixed_space)
19+
f = Coefficient(p_space)
1720

1821

1922
def S(mu):
2023
return mu - Identity(3) * tr(mu)
2124

2225

2326
def b(mu, v):
24-
n = FacetNormal(tetrahedron)
27+
n = FacetNormal(domain)
2528
return inner(S(mu), grad(grad(v))) * dx \
2629
- dot(dot(S(mu('+')), n('+')), n('+')) * jump(grad(v), n) * dS \
2730
- dot(dot(S(mu), n), n) * dot(grad(v), n) * ds

demo/CellGeometry.py

+12-11
Original file line numberDiff line numberDiff line change
@@ -3,23 +3,24 @@
33
# A functional M involving a bunch of cell geometry quantities.
44
import basix.ufl
55
from ufl import (CellVolume, Circumradius, Coefficient, FacetArea, FacetNormal,
6-
SpatialCoordinate, ds, dx, tetrahedron, TrialFunction)
6+
FunctionSpace, Mesh, SpatialCoordinate, TrialFunction, ds, dx)
77
from ufl.geometry import FacetEdgeVectors
88

9-
cell = tetrahedron
10-
V = basix.ufl.element("P", cell.cellname(), 1)
11-
u = Coefficient(V)
9+
V = basix.ufl.element("P", "tetrahedron", 1)
10+
domain = Mesh(basix.ufl.element("P", "tetrahedron", 1, shape=(3, )))
11+
space = FunctionSpace(domain, V)
12+
u = Coefficient(space)
1213

1314
# TODO: Add all geometry for all cell types to this and other demo files, need for regression test.
14-
x = SpatialCoordinate(cell)
15-
n = FacetNormal(cell)
16-
vol = CellVolume(cell)
17-
rad = Circumradius(cell)
18-
area = FacetArea(cell)
15+
x = SpatialCoordinate(domain)
16+
n = FacetNormal(domain)
17+
vol = CellVolume(domain)
18+
rad = Circumradius(domain)
19+
area = FacetArea(domain)
1920

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

2223
# Test some obscure functionality
23-
fev = FacetEdgeVectors(cell)
24-
v = TrialFunction(V)
24+
fev = FacetEdgeVectors(domain)
25+
v = TrialFunction(space)
2526
L = fev[0, 0] * v * ds

demo/Components.py

+6-3
Original file line numberDiff line numberDiff line change
@@ -17,12 +17,15 @@
1717
#
1818
# This example demonstrates how to create vectors component-wise
1919
import basix.ufl
20-
from ufl import Coefficient, TestFunction, as_vector, dot, dx
20+
from ufl import (Coefficient, FunctionSpace, Mesh, TestFunction, as_vector,
21+
dot, dx)
2122

2223
element = basix.ufl.element("Lagrange", "tetrahedron", 1, shape=(3, ))
24+
domain = Mesh(element)
25+
space = FunctionSpace(domain, element)
2326

24-
v = TestFunction(element)
25-
f = Coefficient(element)
27+
v = TestFunction(space)
28+
f = Coefficient(space)
2629

2730
# Create vector
2831
v0 = as_vector([v[0], v[1], 0.0])

demo/Conditional.py

+8-5
Original file line numberDiff line numberDiff line change
@@ -17,15 +17,18 @@
1717
#
1818
# Illustration on how to use Conditional to define a source term
1919
import basix.ufl
20-
from ufl import (And, Constant, Not, Or, SpatialCoordinate, TestFunction,
21-
conditional, dx, ge, gt, le, lt, triangle)
20+
from ufl import (And, Constant, FunctionSpace, Mesh, Not, Or,
21+
SpatialCoordinate, TestFunction, conditional, dx, ge, gt, le,
22+
lt)
2223

2324
element = basix.ufl.element("Lagrange", "triangle", 2)
25+
domain = Mesh(basix.ufl.element("Lagrange", "triangle", 1, shape=(2, )))
26+
space = FunctionSpace(domain, element)
2427

25-
v = TestFunction(element)
26-
g = Constant(triangle)
28+
v = TestFunction(space)
29+
g = Constant(domain)
2730

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

demo/FacetIntegrals.py

+7-5
Original file line numberDiff line numberDiff line change
@@ -20,15 +20,17 @@
2020
#
2121
# Simple example of a form defined over exterior and interior facets.
2222
import basix.ufl
23-
from ufl import (FacetNormal, TestFunction, TrialFunction, avg, ds, dS, grad,
24-
inner, jump, triangle)
23+
from ufl import (FacetNormal, FunctionSpace, Mesh, TestFunction, TrialFunction,
24+
avg, ds, dS, grad, inner, jump)
2525

2626
element = basix.ufl.element("Discontinuous Lagrange", "triangle", 1)
27+
domain = Mesh(basix.ufl.element("Lagrange", "triangle", 1, shape=(2, )))
28+
space = FunctionSpace(domain, element)
2729

28-
u = TrialFunction(element)
29-
v = TestFunction(element)
30+
u = TrialFunction(space)
31+
v = TestFunction(space)
3032

31-
n = FacetNormal(triangle)
33+
n = FacetNormal(domain)
3234

3335
a = u * v * ds \
3436
+ u('+') * v('-') * dS \

demo/FacetRestrictionAD.py

+7-5
Original file line numberDiff line numberDiff line change
@@ -15,14 +15,16 @@
1515
# You should have received a copy of the GNU Lesser General Public License
1616
# along with FFCx. If not, see <http://www.gnu.org/licenses/>.
1717
import basix.ufl
18-
from ufl import (Coefficient, TestFunction, TrialFunction, avg, derivative,
19-
dot, dS, dx, grad, inner)
18+
from ufl import (Coefficient, FunctionSpace, Mesh, TestFunction, TrialFunction,
19+
avg, derivative, dot, dS, dx, grad, inner)
2020

2121
element = basix.ufl.element("Discontinuous Lagrange", "triangle", 1)
22+
domain = Mesh(basix.ufl.element("Lagrange", "triangle", 1, shape=(2, )))
23+
space = FunctionSpace(domain, element)
2224

23-
v = TestFunction(element)
24-
w = Coefficient(element)
25+
v = TestFunction(space)
26+
w = Coefficient(space)
2527
L = inner(grad(w), grad(v)) * dx - dot(avg(grad(w)), avg(grad(v))) * dS
2628

27-
u = TrialFunction(element)
29+
u = TrialFunction(space)
2830
a = derivative(L, w, u)

demo/HyperElasticity.py

+28-20
Original file line numberDiff line numberDiff line change
@@ -5,47 +5,55 @@
55

66
import basix.ufl
77
# Modified by Garth N. Wells, 2009
8-
from ufl import (Coefficient, Constant, FacetNormal, Identity,
9-
SpatialCoordinate, TestFunction, TrialFunction, derivative,
10-
det, diff, dot, ds, dx, exp, grad, inner, inv, tetrahedron,
11-
tr, variable)
8+
from ufl import (Coefficient, Constant, FacetNormal, FunctionSpace, Identity,
9+
Mesh, SpatialCoordinate, TestFunction, TrialFunction,
10+
derivative, det, diff, dot, ds, dx, exp, grad, inner, inv,
11+
tetrahedron, tr, variable)
1212

1313
# Cell and its properties
1414
cell = tetrahedron
1515
d = cell.geometric_dimension()
16-
N = FacetNormal(cell)
17-
x = SpatialCoordinate(cell)
1816

1917
# Elements
2018
u_element = basix.ufl.element("P", cell.cellname(), 2, shape=(3, ))
2119
p_element = basix.ufl.element("P", cell.cellname(), 1)
2220
A_element = basix.ufl.element("P", cell.cellname(), 1, shape=(3, 3))
2321

22+
# Spaces
23+
domain = Mesh(basix.ufl.element("Lagrange", cell.cellname(), 1, shape=(3, )))
24+
u_space = FunctionSpace(domain, u_element)
25+
p_space = FunctionSpace(domain, p_element)
26+
A_space = FunctionSpace(domain, A_element)
27+
28+
# Cell properties
29+
N = FacetNormal(domain)
30+
x = SpatialCoordinate(domain)
31+
2432
# Test and trial functions
25-
v = TestFunction(u_element)
26-
w = TrialFunction(u_element)
33+
v = TestFunction(u_space)
34+
w = TrialFunction(u_space)
2735

2836
# Displacement at current and two previous timesteps
29-
u = Coefficient(u_element)
30-
up = Coefficient(u_element)
31-
upp = Coefficient(u_element)
37+
u = Coefficient(u_space)
38+
up = Coefficient(u_space)
39+
upp = Coefficient(u_space)
3240

3341
# Time parameters
34-
dt = Constant(cell)
42+
dt = Constant(domain)
3543

3644
# Fiber field
37-
A = Coefficient(A_element)
45+
A = Coefficient(A_space)
3846

3947
# External forces
40-
T = Coefficient(u_element)
41-
p0 = Coefficient(p_element)
48+
T = Coefficient(u_space)
49+
p0 = Coefficient(p_space)
4250

4351
# Material parameters FIXME
44-
rho = Constant(cell)
45-
K = Constant(cell)
46-
c00 = Constant(cell)
47-
c11 = Constant(cell)
48-
c22 = Constant(cell)
52+
rho = Constant(domain)
53+
K = Constant(domain)
54+
c00 = Constant(domain)
55+
c11 = Constant(domain)
56+
c22 = Constant(domain)
4957

5058
# Deformation gradient
5159
I = Identity(d)

demo/MassDG0.py

+5-3
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,13 @@
1717
#
1818
# The bilinear form for a mass matrix.
1919
import basix.ufl
20-
from ufl import TestFunction, TrialFunction, dx, inner
20+
from ufl import FunctionSpace, Mesh, TestFunction, TrialFunction, dx, inner
2121

2222
element = basix.ufl.element("DG", "tetrahedron", 0)
23+
domain = Mesh(basix.ufl.element("Lagrange", "tetrahedron", 1, shape=(3, )))
24+
space = FunctionSpace(domain, element)
2325

24-
v = TestFunction(element)
25-
u = TrialFunction(element)
26+
v = TestFunction(space)
27+
u = TrialFunction(space)
2628

2729
a = inner(u, v) * dx

demo/MassHcurl_2D_1.py

+5-3
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,13 @@
1515
# You should have received a copy of the GNU Lesser General Public License
1616
# along with FFCx. If not, see <http://www.gnu.org/licenses/>.
1717
import basix.ufl
18-
from ufl import TestFunction, TrialFunction, dx, inner
18+
from ufl import FunctionSpace, Mesh, TestFunction, TrialFunction, dx, inner
1919

2020
element = basix.ufl.element("N1curl", "triangle", 1)
21+
domain = Mesh(basix.ufl.element("Lagrange", "triangle", 1, shape=(2, )))
22+
space = FunctionSpace(domain, element)
2123

22-
v = TestFunction(element)
23-
u = TrialFunction(element)
24+
v = TestFunction(space)
25+
u = TrialFunction(space)
2426

2527
a = inner(v, u) * dx

demo/MassHdiv_2D_1.py

+5-3
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,13 @@
1515
# You should have received a copy of the GNU Lesser General Public License
1616
# along with FFCx. If not, see <http://www.gnu.org/licenses/>.
1717
import basix.ufl
18-
from ufl import TestFunction, TrialFunction, dx, inner
18+
from ufl import FunctionSpace, Mesh, TestFunction, TrialFunction, dx, inner
1919

2020
element = basix.ufl.element("BDM", "triangle", 1)
21+
domain = Mesh(basix.ufl.element("Lagrange", "triangle", 1, shape=(2, )))
22+
space = FunctionSpace(domain, element)
2123

22-
v = TestFunction(element)
23-
u = TrialFunction(element)
24+
v = TestFunction(space)
25+
u = TrialFunction(space)
2426

2527
a = inner(v, u) * dx

demo/MathFunctions.py

+6-4
Original file line numberDiff line numberDiff line change
@@ -17,13 +17,15 @@
1717
#
1818
# Test all algebra operators on Coefficients.
1919
import basix.ufl
20-
from ufl import (Coefficient, acos, asin, atan, bessel_J, bessel_Y, cos, dx,
21-
erf, exp, ln, sin, sqrt, tan)
20+
from ufl import (Coefficient, FunctionSpace, Mesh, acos, asin, atan, bessel_J,
21+
bessel_Y, cos, dx, erf, exp, ln, sin, sqrt, tan)
2222

2323
element = basix.ufl.element("Lagrange", "triangle", 1)
24+
domain = Mesh(basix.ufl.element("Lagrange", "triangle", 1, shape=(2, )))
25+
space = FunctionSpace(domain, element)
2426

25-
c0 = Coefficient(element)
26-
c1 = Coefficient(element)
27+
c0 = Coefficient(space)
28+
c1 = Coefficient(space)
2729

2830
s0 = 3 * c0 - c1
2931
p0 = c0 * c1

demo/MetaData.py

+8-5
Original file line numberDiff line numberDiff line change
@@ -17,15 +17,18 @@
1717
#
1818
# Test form for metadata.
1919
import basix.ufl
20-
from ufl import Coefficient, TestFunction, TrialFunction, dx, grad, inner
20+
from ufl import (Coefficient, FunctionSpace, Mesh, TestFunction, TrialFunction,
21+
dx, grad, inner)
2122

2223
element = basix.ufl.element("Lagrange", "triangle", 1)
2324
vector_element = basix.ufl.element("Lagrange", "triangle", 1, shape=(2, ))
25+
domain = Mesh(basix.ufl.element("Lagrange", "triangle", 1, shape=(2, )))
26+
space = FunctionSpace(domain, element)
27+
vector_space = FunctionSpace(domain, vector_element)
2428

25-
26-
u = TrialFunction(element)
27-
v = TestFunction(element)
28-
c = Coefficient(vector_element)
29+
u = TrialFunction(space)
30+
v = TestFunction(space)
31+
c = Coefficient(vector_space)
2932

3033
# Terms on the same subdomain using different quadrature degree
3134
a = inner(grad(u), grad(v)) * dx(0, degree=8)\

0 commit comments

Comments
 (0)