Skip to content

Commit 649a451

Browse files
committed
test compile_expression_dual_evaluation with symbolics
Tests for non-dependence of compile_expression_dual_evaluation on numerics by checking it works with purely symbolic expressions.
1 parent 56c9b94 commit 649a451

1 file changed

Lines changed: 57 additions & 0 deletions

File tree

tests/test_dual_evaluation.py

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
import pytest
2+
import ufl
3+
from tsfc.finatinterface import create_element
4+
from tsfc import compile_expression_dual_evaluation
5+
6+
7+
def test_ufl_only_simple():
8+
mesh = ufl.Mesh(ufl.VectorElement("P", ufl.triangle, 1))
9+
V = ufl.FunctionSpace(mesh, ufl.FiniteElement("P", ufl.triangle, 2))
10+
v = ufl.Coefficient(V)
11+
expr = ufl.inner(v, v)
12+
W = V
13+
to_element = create_element(W.ufl_element())
14+
ast, oriented, needs_cell_sizes, coefficients, _ = compile_expression_dual_evaluation(expr, to_element, coffee=False)
15+
16+
17+
def test_ufl_only_spatialcoordinate():
18+
mesh = ufl.Mesh(ufl.VectorElement("P", ufl.triangle, 1))
19+
V = ufl.FunctionSpace(mesh, ufl.FiniteElement("P", ufl.triangle, 2))
20+
x, y = ufl.SpatialCoordinate(mesh)
21+
expr = x*y - y**2 + x
22+
W = V
23+
to_element = create_element(W.ufl_element())
24+
ast, oriented, needs_cell_sizes, coefficients, _ = compile_expression_dual_evaluation(expr, to_element, coffee=False)
25+
26+
27+
def test_ufl_only_from_contravariant_piola():
28+
mesh = ufl.Mesh(ufl.VectorElement("P", ufl.triangle, 1))
29+
V = ufl.FunctionSpace(mesh, ufl.FiniteElement("RT", ufl.triangle, 1))
30+
v = ufl.Coefficient(V)
31+
expr = ufl.inner(v, v)
32+
W = ufl.FunctionSpace(mesh, ufl.FiniteElement("P", ufl.triangle, 2))
33+
to_element = create_element(W.ufl_element())
34+
ast, oriented, needs_cell_sizes, coefficients, _ = compile_expression_dual_evaluation(expr, to_element, coffee=False)
35+
36+
37+
def test_ufl_only_to_contravariant_piola():
38+
mesh = ufl.Mesh(ufl.VectorElement("P", ufl.triangle, 1))
39+
V = ufl.FunctionSpace(mesh, ufl.FiniteElement("P", ufl.triangle, 2))
40+
v = ufl.Coefficient(V)
41+
expr = ufl.as_vector([v, v])
42+
W = ufl.FunctionSpace(mesh, ufl.FiniteElement("RT", ufl.triangle, 1))
43+
to_element = create_element(W.ufl_element())
44+
ast, oriented, needs_cell_sizes, coefficients, _ = compile_expression_dual_evaluation(expr, to_element, coffee=False)
45+
46+
47+
def test_ufl_only_shape_mismatch():
48+
mesh = ufl.Mesh(ufl.VectorElement("P", ufl.triangle, 1))
49+
V = ufl.FunctionSpace(mesh, ufl.FiniteElement("RT", ufl.triangle, 1))
50+
v = ufl.Coefficient(V)
51+
expr = ufl.inner(v, v)
52+
assert expr.ufl_shape == ()
53+
W = V
54+
to_element = create_element(W.ufl_element())
55+
assert to_element.value_shape == (2,)
56+
with pytest.raises(ValueError):
57+
ast, oriented, needs_cell_sizes, coefficients, _ = compile_expression_dual_evaluation(expr, to_element, coffee=False)

0 commit comments

Comments
 (0)