Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions .github/actions/install/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,14 @@ runs:
firedrake-clean
pip list

- name: "DROP BEFORE MERGE: install FIAT from firedrakeproject/fiat#274"
shell: bash
run: |
. venv/bin/activate
pip install --verbose --no-build-isolation --no-deps --force-reinstall \
git+https://github.com/firedrakeproject/fiat.git@pbrubeck/tensor-facet-quadrature
pip list | grep -i fiat

- name: Run firedrake-check
shell: bash
run: |
Expand Down
41 changes: 39 additions & 2 deletions tests/firedrake/regression/test_quadrature.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
from math import sqrt

from firedrake import *
import pytest
import numpy as np


@pytest.fixture
@pytest.fixture(params=[False, True], ids=["triangle", "quadrilateral"])
def mesh(request):
return UnitSquareMesh(5, 5)
return UnitSquareMesh(5, 5, quadrilateral=request.param)


def test_hand_specified_quadrature(mesh):
Expand Down Expand Up @@ -52,3 +54,38 @@ def test_quadrature_element(mesh, family, mat_type, diagonal):
a = inner(u, v) * dx

assemble(a, mat_type=mat_type, diagonal=diagonal)


@pytest.fixture(params=[FunctionSpace, VectorFunctionSpace, TensorFunctionSpace],
ids=lambda space: space.__name__)
def boundary_quadrature_data(mesh, request):
V = request.param(mesh, "Boundary Quadrature", 2)
x = SpatialCoordinate(mesh)
if V.value_shape == ():
expr = x[0]**2 + x[1]
elif len(V.value_shape) == 1:
expr = as_vector([x[0]**2, x[1]])
else:
expr = as_tensor([[x[0]**2, x[1]], [x[0]*x[1], 1 + x[0]]])
return V, expr


@pytest.mark.parallel([1, 2])
def test_boundary_quadrature_interpolation(boundary_quadrature_data):
V, expr = boundary_quadrature_data
f = Function(V).interpolate(expr)
error = f - expr

# The functionals are point evaluations, so interpolation is exact there
assert sqrt(abs(assemble(inner(error, error) * ds))) < 1e-12
trace = error('+')
assert sqrt(abs(assemble(inner(trace, trace) * dS))) < 1e-12


@pytest.mark.parallel([1, 2])
def test_boundary_quadrature_interpolation_in_form(boundary_quadrature_data):
V, expr = boundary_quadrature_data
error = interpolate(expr, V) - expr
assert sqrt(abs(assemble(inner(error, error) * ds))) < 1e-12
trace = error('+')
assert sqrt(abs(assemble(inner(trace, trace) * dS))) < 1e-12
18 changes: 17 additions & 1 deletion tests/tsfc/test_dual_evaluation.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import ufl
import finat.ufl
from finat.element_factory import create_element
from tsfc import compile_expression_dual_evaluation
from tsfc import compile_expression_dual_evaluation, compile_form
from tsfc.kernel_args import OutputKernelArg


Expand Down Expand Up @@ -128,3 +128,19 @@ def test_dual_argument_is_sum_factorised(cell, restriction, dual):
rate = math.log(flops[1] / flops[0]) / math.log(degrees[1] / degrees[0])
# Lower order terms move the measured rate to either side of dim + 1.
assert rate < dim + 1.5


@pytest.mark.parametrize("degree", [1, 2])
@pytest.mark.parametrize("cell", [ufl.quadrilateral, ufl.hexahedron])
def test_boundary_quadrature_in_facet_integral(cell, degree):
"""Facet quadrature values enter a facet integral on a runtime facet.

On a hexahedron the quadrature points of a facet integral are permuted by
the facet orientation, including the axes with a single point.
"""
mesh = ufl.Mesh(finat.ufl.VectorElement("Q", cell, 1))
u = ufl.Coefficient(ufl.FunctionSpace(mesh, finat.ufl.FiniteElement("Q", cell, 2)))
V = ufl.FunctionSpace(mesh, finat.ufl.FiniteElement("Boundary Quadrature", cell, degree))
for f in [ufl.Coefficient(V), ufl.Interpolate(u, V)]:
kernel, = compile_form(f * u * ufl.ds)
assert kernel.flop_count > 0
16 changes: 15 additions & 1 deletion tests/tsfc/test_flop_count.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ def test_count_flops(expression):
assert flops == expected


@pytest.fixture(params=("expr1", "expr2", "expr3", "expr4"))
@pytest.fixture(params=("expr1", "expr2", "expr3", "expr4", "expr5"))
def expression(request):
if request.param == "expr1":
expr = gem.Sum(gem.Product(gem.Variable("a", ()), gem.Literal(2)),
Expand Down Expand Up @@ -58,6 +58,20 @@ def expression(request):
expr = compile_gem(assignments, (j, k))
# Cjk += \sum_i Aij * Bki
expected = 2 * 10 * 8 * 15
elif request.param == "expr5":
A = gem.Variable("A", (4,))
B = gem.Variable("B", (4,))
n = gem.Variable("n", (), dtype=gem.uint_type)
two = gem.Literal(2, dtype=gem.uint_type)
k = gem.VariableIndex(gem.Remainder(gem.FloorDiv(n, two), two))
expr = gem.Product(gem.Indexed(A, (k,)), gem.Indexed(B, (k,)))
C = gem.Variable("C", (1,))
i, = gem.indices(1)
expr, = preprocess_gem([expr])
assignments = [(C[i], expr)]
expr = compile_gem(assignments, (i,))
# C += A[k] * B[k], where k = n // 2 % 2 is integer arithmetic
expected = 1 + 1

else:
raise ValueError("Unexpected expression")
Expand Down
19 changes: 14 additions & 5 deletions tsfc/fem.py
Original file line number Diff line number Diff line change
Expand Up @@ -912,6 +912,16 @@ def take_singleton(xs):
per_derivative = {alpha: gem.select_expression(tables, f)
for alpha, tables in per_derivative.items()}

if ctx.use_canonical_quadrature_point_ordering:
# Permute the tables from reference to physical quadrature point order
# before they are contracted with ``vec``.
# The facet orientation then does not change ``vec``.
quad_multiindex = ctx.quadrature_rule.point_set.indices
quad_multiindex_permuted = _make_quad_multiindex_permuted(domain, mt, ctx)
mapper = gem.node.MemoizerArg(gem.optimise.filtered_replace_indices)
per_derivative = {alpha: mapper(table, tuple(zip(quad_multiindex, quad_multiindex_permuted)))
for alpha, table in per_derivative.items()}

# Coefficient evaluation
beta = ctx.index_cache.setdefault(ufl_element, element.get_indices())
zeta = element.get_value_indices()
Expand Down Expand Up @@ -946,11 +956,6 @@ def take_singleton(xs):
if isinstance(node, gem.Literal)):
result = gem.optimise.aggressive_unroll(result)

if ctx.use_canonical_quadrature_point_ordering:
quad_multiindex = ctx.quadrature_rule.point_set.indices
quad_multiindex_permuted = _make_quad_multiindex_permuted(domain, mt, ctx)
mapper = gem.node.MemoizerArg(gem.optimise.filtered_replace_indices)
result = mapper(result, tuple(zip(quad_multiindex, quad_multiindex_permuted)))
return result


Expand All @@ -975,6 +980,10 @@ def _make_quad_multiindex_permuted(domain, mt, ctx):
for ref_axis in range(len(quad_multiindex)):
io = cell.extract_intrinsic_orientation(o, ref_axis)
io_perm_map = gem.Literal(quad_rule.intrinsic_orientation_permutation_map_tuple[ref_axis], dtype=gem.uint_type)
if io_perm_map.shape[-1] == 1:
# The only permutation of a single point is the identity.
quad_multiindex_permuted.append(0)
continue
# Effectively swap axes if needed.
ref_index = tuple((phys_index, gem.Indexed(eo_perm_map, (eo, ref_axis, phys_axis))) for phys_axis, phys_index in enumerate(quad_multiindex))
quad_index_permuted = gem.VariableIndex(gem.FlexiblyIndexed(io_perm_map, ((0, ((io, 1), )), (0, ref_index))))
Expand Down
3 changes: 2 additions & 1 deletion tsfc/kernel_interface/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
from itertools import chain, product
import copy

from ufl.algorithms.analysis import has_type
from ufl.algorithms.analysis import extract_base_form_operators, has_type
from ufl.classes import Cofunction, GeometricQuantity, Interpolate
from ufl.finiteelement import AbstractFiniteElement
from ufl.utils.sequences import max_degree
Expand Down Expand Up @@ -244,6 +244,7 @@ def compile_integrand(self, integrand, params, ctx):
# Compile: ufl -> gem
info = self.integral_data_info
functions = [*info.arguments, self.coordinate(info.domain), *info.coefficients]
functions.extend(extract_base_form_operators(integrand))
set_quad_rule(params, info.domain.ufl_cell(), info.integral_type, functions)
quad_rule = params["quadrature_rule"]
config = self.fem_config()
Expand Down
Loading