Skip to content

Commit

Permalink
Merge fix_dualspace
Browse files Browse the repository at this point in the history
  • Loading branch information
nbouziani committed Aug 20, 2023
2 parents 51e2bb1 + 8cf030b commit 0267197
Show file tree
Hide file tree
Showing 82 changed files with 993 additions and 2,482 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
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
8 changes: 4 additions & 4 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, inner, 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
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
73 changes: 30 additions & 43 deletions ufl/__init__.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
# -*- coding: utf-8 -*-
# flake8: noqa
"""The Unified Form Language is an embedded domain specific language
for definition of variational forms intended for finite element
discretization. More precisely, it defines a fixed interface for choosing
Expand All @@ -11,19 +9,19 @@
* To import the language, type::
from ufl import *
import ufl
* To import the underlying classes an UFL expression tree is built
from, type
::
from ufl.classes import *
import ufl.classes
* Various algorithms for working with UFL expression trees can be
accessed by
::
from ufl.algorithms import *
import ufl.algorithms
Classes and algorithms are considered implementation details and
should not be used in form definitions.
Expand All @@ -38,7 +36,7 @@
The development version can be found in the repository at
https://www.bitbucket.org/fenics-project/ufl
https://github.com/FEniCS/ufl
A very brief overview of the language contents follows:
Expand Down Expand Up @@ -219,7 +217,7 @@
- rhs, lhs
- system
- functional
- replace, replace_integral_domains
- replace
- adjoint
- action
- energy_norm,
Expand All @@ -246,7 +244,7 @@
__version__ = importlib.metadata.version("fenics-ufl")

# README
# Imports here should be what the user sees when doing "from ufl import *",
# Imports here should be what the user sees
# which means we should _not_ import f.ex. "Grad", but "grad".
# This way we expose the language, the operation "grad", but less
# of the implementation, the particular class "Grad".
Expand All @@ -272,20 +270,19 @@
from ufl.sobolevspace import L2, H1, H2, HDiv, HCurl, HEin, HDivDiv, HInf

# Finite elements classes
from ufl.finiteelement import FiniteElementBase, FiniteElement, \
MixedElement, VectorElement, TensorElement, EnrichedElement, \
NodalEnrichedElement, RestrictedElement, TensorProductElement, \
HDivElement, HCurlElement, BrokenElement, WithMapping
from ufl.finiteelement import (
FiniteElementBase, FiniteElement, MixedElement, VectorElement, TensorElement, EnrichedElement,
NodalEnrichedElement, RestrictedElement, TensorProductElement, HDivElement, HCurlElement, BrokenElement,
WithMapping)

# Hook to extend predefined element families
from ufl.finiteelement.elementlist import register_element, show_elements # , ufl_elements
from ufl.finiteelement.elementlist import register_element, show_elements

# Function spaces
from ufl.functionspace import FunctionSpace, MixedFunctionSpace

# Arguments
from ufl.argument import Argument, Coargument, TestFunction, TrialFunction, \
Arguments, TestFunctions, TrialFunctions
from ufl.argument import Argument, Coargument, TestFunction, TrialFunction, Arguments, TestFunctions, TrialFunctions

# Coefficients
from ufl.coefficient import Coefficient, Cofunction, Coefficients
Expand Down Expand Up @@ -314,43 +311,34 @@

# Special functions for expression base classes
# (ensure this is imported, since it attaches operators to Expr)
import ufl.exproperators as __exproperators
import ufl.exproperators as __exproperators # noqa: F401

# Containers for expressions with value rank > 0
from ufl.tensors import as_tensor, as_vector, as_matrix, relabel
from ufl.tensors import as_tensor, as_vector, as_matrix
from ufl.tensors import unit_vector, unit_vectors, unit_matrix, unit_matrices

# Operators
from ufl.operators import rank, shape, \
conj, real, imag, \
outer, inner, dot, cross, perp, \
det, inv, cofac, \
transpose, tr, diag, diag_vector, \
dev, skew, sym, \
sqrt, exp, ln, erf, \
cos, sin, tan, \
acos, asin, atan, atan_2, \
cosh, sinh, tanh, \
bessel_J, bessel_Y, bessel_I, bessel_K, \
eq, ne, le, ge, lt, gt, And, Or, Not, \
conditional, sign, max_value, min_value, \
variable, diff, \
Dx, grad, div, curl, rot, nabla_grad, nabla_div, Dn, exterior_derivative, \
jump, avg, cell_avg, facet_avg, \
elem_mult, elem_div, elem_pow, elem_op
from ufl.operators import (
rank, shape, conj, real, imag, outer, inner, dot, cross, perp,
det, inv, cofac, transpose, tr, diag, diag_vector, dev, skew, sym,
sqrt, exp, ln, erf, cos, sin, tan, acos, asin, atan, atan_2, cosh, sinh, tanh,
bessel_J, bessel_Y, bessel_I, bessel_K, eq, ne, le, ge, lt, gt, And, Or, Not,
conditional, sign, max_value, min_value, variable, diff,
Dx, grad, div, curl, rot, nabla_grad, nabla_div, Dn, exterior_derivative,
jump, avg, cell_avg, facet_avg, elem_mult, elem_div, elem_pow, elem_op)

# Measure classes
from ufl.measure import Measure, register_integral_type, integral_types, custom_integral_types

# Form class
from ufl.form import Form, BaseForm, FormSum, ZeroBaseForm, replace_integral_domains
from ufl.form import Form, BaseForm, FormSum, ZeroBaseForm

# Integral classes
from ufl.integral import Integral

# Representations of transformed forms
from ufl.formoperators import replace, derivative, action, energy_norm, rhs, lhs,\
system, functional, adjoint, sensitivity_rhs, extract_blocks #, dirichlet_functional
from ufl.formoperators import (replace, derivative, action, energy_norm, rhs, lhs,
system, functional, adjoint, sensitivity_rhs, extract_blocks)

# Predefined convenience objects
from ufl.objects import (
Expand All @@ -359,8 +347,7 @@
i, j, k, l, p, q, r, s,
dx, ds, dS, dP,
dc, dC, dO, dI, dX,
ds_b, ds_t, ds_tb, ds_v, dS_h, dS_v
)
ds_b, ds_t, ds_tb, ds_v, dS_h, dS_v)

# Useful constants
from math import e, pi
Expand All @@ -383,15 +370,15 @@
'BrokenElement', "WithMapping",
'register_element', 'show_elements',
'FunctionSpace', 'MixedFunctionSpace',
'Argument','Coargument', 'TestFunction', 'TrialFunction',
'Argument', 'Coargument', 'TestFunction', 'TrialFunction',
'Arguments', 'TestFunctions', 'TrialFunctions',
'Coefficient', 'Cofunction', 'Coefficients',
'Matrix', 'Adjoint', 'Action', 'Interp',
'Constant', 'VectorConstant', 'TensorConstant',
'split',
'PermutationSymbol', 'Identity', 'zero', 'as_ufl',
'Index', 'indices',
'as_tensor', 'as_vector', 'as_matrix', 'relabel',
'as_tensor', 'as_vector', 'as_matrix',
'unit_vector', 'unit_vectors', 'unit_matrix', 'unit_matrices',
'rank', 'shape', 'conj', 'real', 'imag',
'outer', 'inner', 'dot', 'cross', 'perp',
Expand All @@ -408,9 +395,9 @@
'Dx', 'grad', 'div', 'curl', 'rot', 'nabla_grad', 'nabla_div', 'Dn', 'exterior_derivative',
'jump', 'avg', 'cell_avg', 'facet_avg',
'elem_mult', 'elem_div', 'elem_pow', 'elem_op',
'Form','FormSum', 'ZeroBaseForm',
'Form', 'BaseForm', 'FormSum', 'ZeroBaseForm',
'Integral', 'Measure', 'register_integral_type', 'integral_types', 'custom_integral_types',
'replace', 'replace_integral_domains', 'derivative', 'action', 'energy_norm', 'rhs', 'lhs', 'extract_blocks',
'replace', 'derivative', 'action', 'energy_norm', 'rhs', 'lhs', 'extract_blocks',
'system', 'functional', 'adjoint', 'sensitivity_rhs',
'dx', 'ds', 'dS', 'dP',
'dc', 'dC', 'dO', 'dI', 'dX',
Expand Down
Loading

0 comments on commit 0267197

Please sign in to comment.