Skip to content

Commit

Permalink
wire up FInAT interface to TensorProductElement
Browse files Browse the repository at this point in the history
  • Loading branch information
miklos1 committed Oct 20, 2016
1 parent 03b8b21 commit c38f3ae
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 0 deletions.
29 changes: 29 additions & 0 deletions tests/test_create_finat_element.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,35 @@ def test_triangle_vector(ufl_element, ufl_vector_element):
assert scalar == vector.base_element


@pytest.fixture(params=["CG", "DG"])
def tensor_name(request):
return request.param


@pytest.fixture(params=[ufl.interval, ufl.triangle,
ufl.quadrilateral],
ids=lambda x: x.cellname())
def ufl_A(request, tensor_name):
return ufl.FiniteElement(tensor_name, request.param, 1)


@pytest.fixture
def ufl_B(tensor_name):
return ufl.FiniteElement(tensor_name, ufl.interval, 1)


def test_tensor_prod_simple(ufl_A, ufl_B):
tensor_ufl = ufl.TensorProductElement(ufl_A, ufl_B)

tensor = f.create_element(tensor_ufl)
A = f.create_element(ufl_A)
B = f.create_element(ufl_B)

assert isinstance(tensor, finat.TensorProductElement)

assert tensor.factors == (A, B)


def test_cache_hit(ufl_element):
A = f.create_element(ufl_element)
B = f.create_element(ufl_element)
Expand Down
10 changes: 10 additions & 0 deletions tsfc/finatinterface.py
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,16 @@ def convert_tensorelement(element):
return finat.TensorFiniteElement(scalar_element, element.reference_value_shape())


# TensorProductElement case
@convert.register(ufl.TensorProductElement)
def convert_tensorproductelement(element):
cell = element.cell()
if type(cell) is not ufl.TensorProductCell:
raise ValueError("TensorProductElement not on TensorProductCell?")
return finat.TensorProductElement([create_element(elem)
for elem in element.sub_elements()])


_cache = weakref.WeakKeyDictionary()


Expand Down

0 comments on commit c38f3ae

Please sign in to comment.