Skip to content

Commit

Permalink
AbstractFiniteElement (#197)
Browse files Browse the repository at this point in the history
* Remove a lots of finiteelement stuff

* __all_classes__

* remove mixedelement

* remove use of deleted elements

* remove print

* working on element interface

* working on new elements

* Add broken demos

* make (almost) all tests pass

* Move demos out of broken folder, fix a few tests

* Hermite is H1

* flake8

* symmetric elements

* subelements in splitting test

* fix another test

* MixedElasticity demo

* fix final test

* rename FiniteElementBase -> AbstractFiniteElement

* doc

* Template structure for pullback

* working on pull back

* fixes

* skip flake8 on pull_back for now

* flake and pydocstyle

* update tests

* basix branch

* flake8

* start making ffc tests pass

* fix imports

* flake

* isort

* make test pass

* ffc branch

* as_domain in measure (if domain is not None)

* corrections

* dolfinx branch

* Add some types

* no product needed

* sub_rsh

* ()

* flattened... not property

* documentation

* remove component functions

* flake, remove unused function

* remove _is_linear

* put function back

* remove is_cellwise_constant

* remove is_globally_constant

* remove sorting of elements by hash

* improve doc

* working on new pull back classes

* update pull backs in demos and tests

* flake8

* add mixed pull back

* symmetric pull back

* flake

* flake8

* a -> A

* Get (physical) value shape from the pull back

* tidy up element classes

* flake

* add embedded super- and sub-degrees

* Add Legacy elements (for TSFC support)

* flake

* tsfc branch

* don't look up components for scalar-valued elements

* sub_elements() -> sub_elements

* sobolev_space() -> sobolev_space

* is_identity rather than checking type

* abstractproperty

* docs

* use is_identity

* doc

* simplify pullback code

* tweak docstrings

* clarify

* property and custom pullback

* ()

* Use IdentityPullBack if mixed elements sub elements all use it

* Docstring

* fixes in legacy

* l -> L

* physical pull back

* @Property in legacy

* fixing legacy elements

* fix symmetry ordering

* generalise symmetric pull back to sub-elements with a value size

* update AUTHORS

* fdlake

* fix when element may not be fully initialised

* set self._sub_elements before they're needed

* update index order in legacy

* Rename pull_back -> pullback and improve docs

* rename pullback in tests

* fix embedded degrees

* flake

* pullback rename in demos

* replace degree() with embedded_superdegree

* embedded degrees in hdivcurl

* fix more embedded degrees

* correct blockshape

* max not sum

* Revert "max not sum"

This reverts commit 145fbb4.

* only for testing

* set branches to main
  • Loading branch information
mscroggs authored Oct 16, 2023
1 parent 66b78e1 commit ff3f69f
Show file tree
Hide file tree
Showing 187 changed files with 3,094 additions and 2,883 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/tsfc-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ jobs:
with:
path: ./tsfc
repository: firedrakeproject/tsfc
ref: master
ref: mscroggs/newfl-legacy
- name: Install tsfc
run: |
cd tsfc
Expand Down
1 change: 1 addition & 0 deletions AUTHORS
Original file line number Diff line number Diff line change
Expand Up @@ -31,3 +31,4 @@ Contributors:
| Nacime Bouziani <[email protected]>
| Reuben W. Hill <[email protected]>
| Nacime Bouziani <[email protected]>
| Matthew Scroggs <[email protected]>
15 changes: 9 additions & 6 deletions demo/Constant.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,20 +18,23 @@
# Modified by Martin Sandve Alnes, 2009
#
# Test form for scalar and vector constants.
from ufl import (Coefficient, Constant, FiniteElement, FunctionSpace, Mesh, TestFunction, TrialFunction, VectorConstant,
VectorElement, 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)
domain = Mesh(VectorElement("Lagrange", cell, 1))
element = FiniteElement("Lagrange", cell, 1, (), identity_pullback, H1)
domain = Mesh(FiniteElement("Lagrange", cell, 1, (2, ), identity_pullback, H1))
space = FunctionSpace(domain, element)

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

c = Constant(space)
d = VectorConstant(space)
c = Constant(domain)
d = VectorConstant(domain)

a = c * dot(grad(v), grad(u)) * dx
L = inner(d, grad(v)) * dx
9 changes: 6 additions & 3 deletions demo/ConvectionJacobi.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,13 @@
# Author: Martin Sandve Alnes
# Date: 2008-10-03
#
from ufl import Coefficient, FunctionSpace, Mesh, TestFunction, TrialFunction, VectorElement, 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 = VectorElement("Lagrange", triangle, 1)
domain = Mesh(VectorElement("Lagrange", triangle, 1))
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
9 changes: 6 additions & 3 deletions demo/ConvectionJacobi2.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,13 @@
# Author: Martin Sandve Alnes
# Date: 2008-10-03
#
from ufl import Coefficient, FunctionSpace, Mesh, TestFunction, TrialFunction, VectorElement, dx, i, j, triangle
from ufl import Coefficient, FunctionSpace, Mesh, TestFunction, TrialFunction, dx, i, j, triangle
from ufl.finiteelement import FiniteElement
from ufl.pullback import identity_pullback
from ufl.sobolevspace import H1

element = VectorElement("Lagrange", triangle, 1)
domain = Mesh(VectorElement("Lagrange", triangle, 1))
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
9 changes: 6 additions & 3 deletions demo/ConvectionVector.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,13 @@
# Author: Martin Sandve Alnes
# Date: 2008-10-03
#
from ufl import Coefficient, FunctionSpace, Mesh, TestFunction, VectorElement, dot, dx, grad, triangle
from ufl import Coefficient, FunctionSpace, Mesh, TestFunction, dot, dx, grad, triangle
from ufl.finiteelement import FiniteElement
from ufl.pullback import identity_pullback
from ufl.sobolevspace import H1

element = VectorElement("Lagrange", triangle, 1)
domain = Mesh(VectorElement("Lagrange", triangle, 1))
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
9 changes: 6 additions & 3 deletions demo/Elasticity.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,13 @@
# Modified by: Martin Sandve Alnes
# Date: 2009-01-12
#
from ufl import FunctionSpace, Mesh, TestFunction, TrialFunction, VectorElement, dx, grad, inner, tetrahedron
from ufl import FunctionSpace, Mesh, TestFunction, TrialFunction, dx, grad, inner, tetrahedron
from ufl.finiteelement import FiniteElement
from ufl.pullback import identity_pullback
from ufl.sobolevspace import H1

element = VectorElement("Lagrange", tetrahedron, 1)
domain = Mesh(VectorElement("Lagrange", tetrahedron, 1))
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
9 changes: 6 additions & 3 deletions demo/EnergyNorm.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,13 @@
#
# This example demonstrates how to define a functional, here
# the energy norm (squared) for a reaction-diffusion problem.
from ufl import Coefficient, FiniteElement, FunctionSpace, Mesh, VectorElement, dot, dx, grad, tetrahedron
from ufl import Coefficient, FunctionSpace, Mesh, dot, dx, grad, tetrahedron
from ufl.finiteelement import FiniteElement
from ufl.pullback import identity_pullback
from ufl.sobolevspace import H1

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

v = Coefficient(space)
Expand Down
10 changes: 6 additions & 4 deletions demo/Equation.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,13 @@
# 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, FiniteElement, FunctionSpace, Mesh, TestFunction, TrialFunction, VectorElement, 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)
domain = Mesh(VectorElement("Lagrange", triangle, 1))
element = FiniteElement("Lagrange", triangle, 1, (), identity_pullback, H1)
domain = Mesh(FiniteElement("Lagrange", triangle, 1, (2, ), identity_pullback, H1))
space = FunctionSpace(domain, element)

k = 0.1
Expand Down
9 changes: 6 additions & 3 deletions demo/ExplicitConvection.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,13 @@
# Author: Martin Sandve Alnes
# Date: 2008-10-03
#
from ufl import Coefficient, FunctionSpace, Mesh, TestFunction, TrialFunction, VectorElement, 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 = VectorElement("Lagrange", triangle, 1)
domain = Mesh(VectorElement("Lagrange", triangle, 1))
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
56 changes: 0 additions & 56 deletions demo/FEEC.py

This file was deleted.

10 changes: 6 additions & 4 deletions demo/FunctionOperators.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,13 @@
# along with UFL. If not, see <http://www.gnu.org/licenses/>.
#
# Test form for operators on Coefficients.
from ufl import (Coefficient, FiniteElement, FunctionSpace, Mesh, TestFunction, TrialFunction, VectorElement, 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)
domain = Mesh(VectorElement("Lagrange", triangle, 1))
element = FiniteElement("Lagrange", triangle, 1, (), identity_pullback, H1)
domain = Mesh(FiniteElement("Lagrange", triangle, 1, (2, ), identity_pullback, H1))
space = FunctionSpace(domain, element)

v = TestFunction(space)
Expand Down
9 changes: 6 additions & 3 deletions demo/H1norm.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,13 @@
# Author: Martin Sandve Alnes
# Date: 2008-10-03
#
from ufl import Coefficient, FiniteElement, FunctionSpace, Mesh, VectorElement, dot, dx, grad, triangle
from ufl import Coefficient, FunctionSpace, Mesh, 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)
domain = Mesh(VectorElement("Lagrange", triangle, 1))
element = FiniteElement("Lagrange", triangle, 1, (), identity_pullback, H1)
domain = Mesh(FiniteElement("Lagrange", triangle, 1, (2, ), identity_pullback, H1))
space = FunctionSpace(domain, element)

f = Coefficient(space)
Expand Down
12 changes: 7 additions & 5 deletions demo/HarmonicMap.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,15 @@
# Author: Martin Alnes
# Date: 2009-04-09
#
from ufl import (Coefficient, FiniteElement, FunctionSpace, Mesh, VectorElement, derivative, dot, dx, grad, inner,
triangle)
from ufl import Coefficient, FunctionSpace, Mesh, derivative, dot, dx, grad, inner, triangle
from ufl.finiteelement import FiniteElement
from ufl.pullback import identity_pullback
from ufl.sobolevspace import H1

cell = triangle
X = VectorElement("Lagrange", cell, 1)
Y = FiniteElement("Lagrange", cell, 1)
domain = Mesh(VectorElement("Lagrange", cell, 1))
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))
X_space = FunctionSpace(domain, X)
Y_space = FunctionSpace(domain, Y)

Expand Down
14 changes: 8 additions & 6 deletions demo/HarmonicMap2.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,16 @@
# Author: Martin Alnes
# Date: 2009-04-09
#
from ufl import (Coefficient, FiniteElement, FunctionSpace, Mesh, VectorElement, derivative, dot, dx, grad, inner,
split, triangle)
from ufl import Coefficient, FunctionSpace, Mesh, derivative, dot, dx, grad, inner, split, triangle
from ufl.finiteelement import FiniteElement, MixedElement
from ufl.pullback import identity_pullback
from ufl.sobolevspace import H1

cell = triangle
X = VectorElement("Lagrange", cell, 1)
Y = FiniteElement("Lagrange", cell, 1)
M = X * Y
domain = Mesh(VectorElement("Lagrange", cell, 1))
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))
space = FunctionSpace(domain, M)

u = Coefficient(space)
Expand Down
10 changes: 6 additions & 4 deletions demo/Heat.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,14 @@
# 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, FiniteElement, FunctionSpace, Mesh, TestFunction, TrialFunction, VectorElement,
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)
domain = Mesh(VectorElement("Lagrange", cell, 1))
element = FiniteElement("Lagrange", cell, 1, (), identity_pullback, H1)
domain = Mesh(FiniteElement("Lagrange", cell, 1, (2, ), identity_pullback, H1))
space = FunctionSpace(domain, element)

v = TestFunction(space) # Test function
Expand Down
12 changes: 7 additions & 5 deletions demo/HornSchunck.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,16 @@
# http://code.google.com/p/debiosee/wiki/DemosOptiocFlowHornSchunck
# but not tested so this could contain errors!
#
from ufl import (Coefficient, Constant, FiniteElement, FunctionSpace, Mesh, VectorElement, 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("CG", cell, 1)
V = VectorElement("CG", cell, 1)
domain = Mesh(VectorElement("Lagrange", cell, 1))
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))
S_space = FunctionSpace(domain, S)
V_space = FunctionSpace(domain, V)

Expand Down
16 changes: 9 additions & 7 deletions demo/HyperElasticity.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,22 +3,24 @@
# Date: 2008-12-22
#

from ufl import (Coefficient, Constant, FacetNormal, FunctionSpace, Identity, Mesh, SpatialCoordinate, TestFunction,
TrialFunction, derivative, det, diff, dot, ds, dx, exp, grad, inner, inv, tetrahedron, tr, variable)
from ufl.finiteelement import FiniteElement
# Modified by Garth N. Wells, 2009
from ufl import (Coefficient, Constant, FacetNormal, FiniteElement, FunctionSpace, Identity, Mesh, SpatialCoordinate,
TensorElement, TestFunction, TrialFunction, VectorElement, derivative, det, diff, dot, ds, dx, exp,
grad, inner, inv, tetrahedron, tr, variable)
from ufl.pullback import identity_pullback
from ufl.sobolevspace import H1

# Cell and its properties
cell = tetrahedron
domain = Mesh(VectorElement("Lagrange", cell, 1))
domain = Mesh(FiniteElement("Lagrange", cell, 1, (3, ), identity_pullback, H1))
d = cell.geometric_dimension()
N = FacetNormal(domain)
x = SpatialCoordinate(domain)

# Elements
u_element = VectorElement("CG", cell, 2)
p_element = FiniteElement("CG", cell, 1)
A_element = TensorElement("CG", cell, 1)
u_element = FiniteElement("Lagrange", cell, 2, (3, ), identity_pullback, H1)
p_element = FiniteElement("Lagrange", cell, 1, (), identity_pullback, H1)
A_element = FiniteElement("Lagrange", cell, 1, (3, 3), identity_pullback, H1)

# Spaces
u_space = FunctionSpace(domain, u_element)
Expand Down
10 changes: 6 additions & 4 deletions demo/HyperElasticity1D.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,14 @@
# Author: Martin Sandve Alnes
# Date: 2008-10-03
#
from ufl import (Coefficient, Constant, FiniteElement, FunctionSpace, Mesh, VectorElement, derivative, dx, exp,
interval, variable)
from ufl import Coefficient, Constant, FunctionSpace, Mesh, derivative, dx, exp, interval, variable
from ufl.finiteelement import FiniteElement
from ufl.pullback import identity_pullback
from ufl.sobolevspace import H1

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

u = Coefficient(space)
Expand Down
Loading

0 comments on commit ff3f69f

Please sign in to comment.