Skip to content

Commit

Permalink
Merge interp
Browse files Browse the repository at this point in the history
  • Loading branch information
nbouziani committed Aug 21, 2023
2 parents ef705e6 + 0afde0d commit 3d22b13
Show file tree
Hide file tree
Showing 87 changed files with 1,196 additions and 2,611 deletions.
1 change: 0 additions & 1 deletion .github/workflows/fenicsx-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@ jobs:
with:
path: ./ffcx
repository: FEniCS/ffcx
ref: main
- name: Install FFCx
run: |
cd ffcx
Expand Down
1 change: 1 addition & 0 deletions AUTHORS
Original file line number Diff line number Diff line change
Expand Up @@ -30,3 +30,4 @@ Contributors:
| Tuomas Airaksinen <[email protected]>
| Nacime Bouziani <[email protected]>
| Reuben W. Hill <[email protected]>
| Nacime Bouziani <[email protected]>
3 changes: 1 addition & 2 deletions demo/FEEC.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,5 +50,4 @@
(sigma, u) = TrialFunctions(W)
(tau, v) = TestFunctions(W)

a = (inner(sigma, tau) - inner(d(tau), u) +
inner(d(sigma), v) + inner(d(u), d(v))) * dx
a = (inner(sigma, tau) - inner(d(tau), u) + inner(d(sigma), v) + inner(d(u), d(v))) * dx
6 changes: 3 additions & 3 deletions demo/HyperElasticity.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,8 @@
c22 = Constant(cell)

# Deformation gradient
I = Identity(d)
F = I + grad(u)
Id = Identity(d)
F = Id + grad(u)
F = variable(F)
Finv = inv(F)
J = det(F)
Expand All @@ -66,7 +66,7 @@
I3_C = J**2

# Green strain tensor
E = (C - I) / 2
E = (C - Id) / 2

# Mapping of strain in fiber directions
Ef = A * E * A.T
Expand Down
8 changes: 5 additions & 3 deletions demo/MixedElasticity.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,8 @@ def skw(tau):
(sigma, u, gamma) = TrialFunctions(W)
(tau, v, eta) = TestFunctions(W)

a = (inner(sigma, tau) - tr(sigma) * tr(tau) +
dot(div(tau), u) - dot(div(sigma), v) +
inner(skw(tau), gamma) + inner(skw(sigma), eta)) * dx
a = (
inner(sigma, tau) - tr(sigma) * tr(tau) + dot(
div(tau), u
) - dot(div(sigma), v) + inner(skw(tau), gamma) + inner(skw(sigma), eta)
) * dx
3 changes: 1 addition & 2 deletions demo/VectorLaplaceGradCurl.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,7 @@ def HodgeLaplaceGradCurl(element, felement):
sigma, u = TrialFunctions(element)
f = Coefficient(felement)

a = (inner(tau, sigma) - inner(grad(tau), u) +
inner(v, grad(sigma)) + inner(curl(v), curl(u))) * dx
a = (inner(tau, sigma) - inner(grad(tau), u) + inner(v, grad(sigma)) + inner(curl(v), curl(u))) * dx
L = inner(v, f) * dx

return a, L
Expand Down
4 changes: 2 additions & 2 deletions doc/sphinx/source/installation.rst
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,8 @@ Installation instructions
=========================

To install UFL, download the source code from the
`UFL Bitbucket repository
<https://bitbucket.org/fenics-project/ufl>`__,
`UFL GitHub repository
<https://github.com/FEniCS/ufl>`__,
and run the following command:

.. code-block:: console
Expand Down
11 changes: 2 additions & 9 deletions setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -58,15 +58,8 @@ ci =
fenics-ufl[test]

[flake8]
ignore = E501, W504,
# Line break before operator, no longer PEP8.
W503,
# Indentation, can trigger for valid code.
E129,
# ambiguous variable name
E741
builtins = ufl
exclude = .git,__pycache__,doc/sphinx/source/conf.py,build,dist,test
max-line-length = 120
exclude = doc/sphinx/source/conf.py,test

[pydocstyle]
# Work on removing these ignores
Expand Down
67 changes: 67 additions & 0 deletions test/test_cell.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
import ufl
import pytest


def test_interval():
cell = ufl.interval
assert cell.num_vertices() == 2
assert cell.num_edges() == 1
assert cell.num_faces() == 0


def test_triangle():
cell = ufl.triangle
assert cell.num_vertices() == 3
assert cell.num_edges() == 3
assert cell.num_faces() == 1


def test_quadrilateral():
cell = ufl.quadrilateral
assert cell.num_vertices() == 4
assert cell.num_edges() == 4
assert cell.num_faces() == 1


def test_tetrahedron():
cell = ufl.tetrahedron
assert cell.num_vertices() == 4
assert cell.num_edges() == 6
assert cell.num_faces() == 4


def test_hexahedron():
cell = ufl.hexahedron
assert cell.num_vertices() == 8
assert cell.num_edges() == 12
assert cell.num_faces() == 6



@pytest.mark.parametrize("cell", [ufl.interval])
def test_cells_1d(cell):
assert cell.num_facets() == cell.num_vertices()
assert cell.num_ridges() == 0
assert cell.num_peaks() == 0


@pytest.mark.parametrize("cell", [ufl.triangle, ufl.quadrilateral])
def test_cells_2d(cell):
assert cell.num_facets() == cell.num_edges()
assert cell.num_ridges() == cell.num_vertices()
assert cell.num_peaks() == 0


@pytest.mark.parametrize("cell", [ufl.tetrahedron, ufl.hexahedron, ufl.prism, ufl.pyramid])
def test_cells_2d(cell):
assert cell.num_facets() == cell.num_faces()
assert cell.num_ridges() == cell.num_edges()
assert cell.num_peaks() == cell.num_vertices()


def test_tensorproductcell():
orig = ufl.TensorProductCell(ufl.interval, ufl.interval)
cell = orig.reconstruct()
assert cell.sub_cells() == orig.sub_cells()
assert cell.topological_dimension() == orig.topological_dimension()
assert cell.geometric_dimension() == orig.geometric_dimension()
8 changes: 4 additions & 4 deletions test/test_complex.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,10 @@
from ufl.algorithms import estimate_total_polynomial_degree
from ufl.algorithms.comparison_checker import do_comparison_check, ComplexComparisonError
from ufl.algorithms.formtransformations import compute_form_adjoint
from ufl import TestFunction, TrialFunction, triangle, FiniteElement, \
as_ufl, inner, grad, dx, dot, outer, conj, sqrt, sin, cosh, \
atan, ln, exp, as_tensor, real, imag, conditional, \
min_value, max_value, gt, lt, cos, ge, le, Coefficient
from ufl import (TestFunction, TrialFunction, triangle, FiniteElement,
as_ufl, inner, grad, dx, dot, outer, conj, sqrt, sin, cosh,
atan, ln, exp, as_tensor, real, imag, conditional,
min_value, max_value, gt, lt, cos, ge, le, Coefficient)


def test_conj(self):
Expand Down
40 changes: 15 additions & 25 deletions test/test_duals.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
#!/usr/bin/env py.test
# -*- coding: utf-8 -*-

from ufl import FiniteElement, FunctionSpace, MixedFunctionSpace, \
Coefficient, Matrix, Cofunction, FormSum, Argument, Coargument,\
TestFunction, TrialFunction, Adjoint, Action, \
action, adjoint, derivative, tetrahedron, triangle, interval, dx
from ufl import (FiniteElement, FunctionSpace, MixedFunctionSpace,
Coefficient, Matrix, Cofunction, FormSum, Argument, Coargument,
TestFunction, TrialFunction, Adjoint, Action,
action, adjoint, derivative, inner, tetrahedron, triangle, interval, dx)
from ufl.constantvalue import Zero
from ufl.form import ZeroBaseForm

Expand Down Expand Up @@ -102,8 +102,6 @@ def test_addition():
domain_2d = default_domain(triangle)
f_2d = FiniteElement("CG", triangle, 1)
V = FunctionSpace(domain_2d, f_2d)
f_2d_2 = FiniteElement("CG", triangle, 2)
V2 = FunctionSpace(domain_2d, f_2d_2)
V_dual = V.dual()

u = TrialFunction(V)
Expand Down Expand Up @@ -137,11 +135,6 @@ def test_addition():
res -= ZeroBaseForm((v,))
assert res == L

with pytest.raises(ValueError):
# Raise error for incompatible arguments
v2 = TestFunction(V2)
res = L + ZeroBaseForm((v2, u))


def test_scalar_mult():
domain_2d = default_domain(triangle)
Expand Down Expand Up @@ -256,7 +249,7 @@ def test_differentiation():
w = Cofunction(U.dual())
dwdu = expand_derivatives(derivative(w, u))
assert isinstance(dwdu, ZeroBaseForm)
assert dwdu.arguments() == (Argument(u.ufl_function_space(), 0),)
assert dwdu.arguments() == (Argument(w.ufl_function_space().dual(), 0), Argument(u.ufl_function_space(), 1))
# Check compatibility with int/float
assert dwdu == 0

Expand Down Expand Up @@ -285,24 +278,21 @@ def test_differentiation():
assert dMdu == 0

# -- Action -- #
Ac = Action(M, u)
dAcdu = expand_derivatives(derivative(Ac, u))

# Action(dM/du, u) + Action(M, du/du) = Action(M, uhat) since dM/du = 0.
# Multiply by 1 to get a FormSum (type compatibility).
assert dAcdu == 1 * Action(M, v)
Ac = Action(w, u)
dAcdu = derivative(Ac, u)
assert dAcdu == action(adjoint(derivative(w, u)), u) + action(w, derivative(u, u))

# -- Adjoint -- #
Ad = Adjoint(M)
dAddu = expand_derivatives(derivative(Ad, u))
# Push differentiation through Adjoint
assert dAddu == 0
dAcdu = expand_derivatives(dAcdu)
# Since dw/du = 0
assert dAcdu == Action(w, v)

# -- Form sum -- #
Fs = M + Ac
uhat = Argument(U, 1)
what = Argument(U, 2)
Fs = M + inner(u * uhat, v) * dx
dFsdu = expand_derivatives(derivative(Fs, u))
# Distribute differentiation over FormSum components
assert dFsdu == 1 * Action(M, v)
assert dFsdu == FormSum([inner(what * uhat, v) * dx, 1])


def test_zero_base_form_mult():
Expand Down
6 changes: 6 additions & 0 deletions test/test_elements.py
Original file line number Diff line number Diff line change
Expand Up @@ -229,3 +229,9 @@ def test_mse():

element = FiniteElement('GLL-Edge L2', interval, degree - 1)
assert element == eval(repr(element))


def test_withmapping():
base = FiniteElement("CG", interval, 1)
element = WithMapping(base, "identity")
assert element == eval(repr(element))
5 changes: 3 additions & 2 deletions test/test_new_ad.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,9 @@
from ufl.classes import Grad
from ufl.algorithms import tree_format
from ufl.algorithms.renumbering import renumber_indices
from ufl.algorithms.apply_derivatives import apply_derivatives, GenericDerivativeRuleset, \
GradRuleset, VariableRuleset, GateauxDerivativeRuleset
from ufl.algorithms.apply_derivatives import (
apply_derivatives, GenericDerivativeRuleset,
GradRuleset, VariableRuleset, GateauxDerivativeRuleset)


# Note: the old tests in test_automatic_differentiation.py are a bit messy
Expand Down
3 changes: 1 addition & 2 deletions test/test_signature.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,7 @@
from ufl import *

from ufl.classes import MultiIndex, FixedIndex
from ufl.algorithms.signature import compute_multiindex_hashdata, \
compute_terminal_hashdata
from ufl.algorithms.signature import compute_multiindex_hashdata, compute_terminal_hashdata

from itertools import chain

Expand Down
Loading

0 comments on commit 3d22b13

Please sign in to comment.