1
1
import pytest
2
2
import numpy
3
3
4
- from FIAT import HsiehCloughTocher as HCT
5
- from FIAT .reference_element import ufc_simplex , make_lattice
4
+ from FIAT import RestrictedElement , HsiehCloughTocher as HCT
5
+ from FIAT .reference_element import ufc_simplex
6
6
from FIAT .functional import PointEvaluation
7
+ from FIAT .macro import CkPolynomialSet
7
8
8
9
9
10
@pytest .fixture
@@ -13,12 +14,28 @@ def cell():
13
14
return K
14
15
15
16
17
+ def span_greater_equal (A , B ):
18
+ # span(A) >= span(B)
19
+ _ , residual , * _ = numpy .linalg .lstsq (A .reshape (A .shape [0 ], - 1 ).T ,
20
+ B .reshape (B .shape [0 ], - 1 ).T )
21
+ return numpy .allclose (residual , 0 )
22
+
23
+
24
+ def make_points (K , degree ):
25
+ top = K .get_topology ()
26
+ pts = []
27
+ for dim in top :
28
+ for entity in top [dim ]:
29
+ pts .extend (K .make_points (dim , entity , degree ))
30
+ return pts
31
+
32
+
16
33
@pytest .mark .parametrize ("reduced" , (False , True ))
17
34
def test_hct_constant (cell , reduced ):
18
35
# Test that bfs associated with point evaluation sum up to 1
19
36
fe = HCT (cell , reduced = reduced )
20
37
21
- pts = make_lattice (cell . get_vertices (), 3 )
38
+ pts = make_points (cell , 4 )
22
39
tab = fe .tabulate (2 , pts )
23
40
24
41
coefs = numpy .zeros ((fe .space_dimension (),))
@@ -33,3 +50,27 @@ def test_hct_constant(cell, reduced):
33
50
expected = 1 if sum (alpha ) == 0 else 0
34
51
vals = numpy .dot (coefs , tab [alpha ])
35
52
assert numpy .allclose (vals , expected )
53
+
54
+
55
+ @pytest .mark .parametrize ("reduced" , (False , True ))
56
+ def test_full_polynomials (cell , reduced ):
57
+ # Test that HCT/HCT-red contains all cubics/quadratics
58
+ fe = HCT (cell , reduced = reduced )
59
+ if reduced :
60
+ fe = RestrictedElement (fe , restriction_domain = "vertex" )
61
+
62
+ ref_complex = fe .get_reference_complex ()
63
+ pts = make_points (ref_complex , 4 )
64
+ tab = fe .tabulate (0 , pts )[(0 , 0 )]
65
+
66
+ degree = fe .degree ()
67
+ if reduced :
68
+ degree -= 1
69
+
70
+ P = CkPolynomialSet (cell , degree , variant = "bubble" )
71
+ P_tab = P .tabulate (pts )[(0 , 0 )]
72
+ assert span_greater_equal (tab , P_tab )
73
+
74
+ C1 = CkPolynomialSet (ref_complex , degree , order = 1 , variant = "bubble" )
75
+ C1_tab = C1 .tabulate (pts )[(0 , 0 )]
76
+ assert span_greater_equal (tab , C1_tab )
0 commit comments