Skip to content

Commit

Permalink
Merge branch 'master' into bdmc
Browse files Browse the repository at this point in the history
Conflicts:
	tsfc/fiatinterface.py
	tsfc/finatinterface.py
  • Loading branch information
miklos1 committed Aug 26, 2019
2 parents 6ada0ae + f518633 commit 0ada5ba
Show file tree
Hide file tree
Showing 4 changed files with 48 additions and 10 deletions.
21 changes: 18 additions & 3 deletions tests/test_create_fiat_element.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ def test_triangle_basic(ufl_element):
assert isinstance(element, supported_elements[ufl_element.family()])


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

Expand Down Expand Up @@ -62,7 +62,8 @@ def test_tensor_prod_simple(ufl_A, ufl_B):

@pytest.mark.parametrize(('family', 'expected_cls'),
[('P', FIAT.Lagrange),
('DP', FIAT_DiscontinuousLagrange)])
('DP', FIAT_DiscontinuousLagrange),
('DP L2', FIAT_DiscontinuousLagrange)])
def test_interval_variant_default(family, expected_cls):
ufl_element = ufl.FiniteElement(family, ufl.interval, 3)
assert isinstance(create_element(ufl_element), expected_cls)
Expand All @@ -72,7 +73,9 @@ def test_interval_variant_default(family, expected_cls):
[('P', 'equispaced', FIAT.Lagrange),
('P', 'spectral', FIAT.GaussLobattoLegendre),
('DP', 'equispaced', FIAT_DiscontinuousLagrange),
('DP', 'spectral', FIAT.GaussLegendre)])
('DP', 'spectral', FIAT.GaussLegendre),
('DP L2', 'equispaced', FIAT_DiscontinuousLagrange),
('DP L2', 'spectral', FIAT.GaussLegendre)])
def test_interval_variant(family, variant, expected_cls):
ufl_element = ufl.FiniteElement(family, ufl.interval, 3, variant=variant)
assert isinstance(create_element(ufl_element), expected_cls)
Expand All @@ -84,6 +87,12 @@ def test_triangle_variant_spectral_fail():
create_element(ufl_element)


def test_triangle_variant_spectral_fail_l2():
ufl_element = ufl.FiniteElement('DP L2', ufl.triangle, 2, variant='spectral')
with pytest.raises(ValueError):
create_element(ufl_element)


def test_quadrilateral_variant_spectral_q():
element = create_element(ufl.FiniteElement('Q', ufl.quadrilateral, 3, variant='spectral'))
assert isinstance(element.element.A, FIAT.GaussLobattoLegendre)
Expand All @@ -96,6 +105,12 @@ def test_quadrilateral_variant_spectral_dq():
assert isinstance(element.element.B, FIAT.GaussLegendre)


def test_quadrilateral_variant_spectral_dq_l2():
element = create_element(ufl.FiniteElement('DQ L2', ufl.quadrilateral, 1, variant='spectral'))
assert isinstance(element.element.A, FIAT.GaussLegendre)
assert isinstance(element.element.B, FIAT.GaussLegendre)


def test_quadrilateral_variant_spectral_rtcf():
element = create_element(ufl.FiniteElement('RTCF', ufl.quadrilateral, 2, variant='spectral'))
assert isinstance(element.element._elements[0].A, FIAT.GaussLobattoLegendre)
Expand Down
21 changes: 18 additions & 3 deletions tests/test_create_finat_element.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ def test_triangle_vector(ufl_element, ufl_vector_element):
assert scalar == vector.base_element


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

Expand Down Expand Up @@ -70,7 +70,8 @@ def test_tensor_prod_simple(ufl_A, ufl_B):

@pytest.mark.parametrize(('family', 'expected_cls'),
[('P', finat.Lagrange),
('DP', finat.DiscontinuousLagrange)])
('DP', finat.DiscontinuousLagrange),
('DP L2', finat.DiscontinuousLagrange)])
def test_interval_variant_default(family, expected_cls):
ufl_element = ufl.FiniteElement(family, ufl.interval, 3)
assert isinstance(create_element(ufl_element), expected_cls)
Expand All @@ -80,7 +81,9 @@ def test_interval_variant_default(family, expected_cls):
[('P', 'equispaced', finat.Lagrange),
('P', 'spectral', finat.GaussLobattoLegendre),
('DP', 'equispaced', finat.DiscontinuousLagrange),
('DP', 'spectral', finat.GaussLegendre)])
('DP', 'spectral', finat.GaussLegendre),
('DP L2', 'equispaced', finat.DiscontinuousLagrange),
('DP L2', 'spectral', finat.GaussLegendre)])
def test_interval_variant(family, variant, expected_cls):
ufl_element = ufl.FiniteElement(family, ufl.interval, 3, variant=variant)
assert isinstance(create_element(ufl_element), expected_cls)
Expand All @@ -92,6 +95,12 @@ def test_triangle_variant_spectral_fail():
create_element(ufl_element)


def test_triangle_variant_spectral_fail_l2():
ufl_element = ufl.FiniteElement('DP L2', ufl.triangle, 2, variant='spectral')
with pytest.raises(ValueError):
create_element(ufl_element)


def test_quadrilateral_variant_spectral_q():
element = create_element(ufl.FiniteElement('Q', ufl.quadrilateral, 3, variant='spectral'))
assert isinstance(element.product.factors[0], finat.GaussLobattoLegendre)
Expand All @@ -104,6 +113,12 @@ def test_quadrilateral_variant_spectral_dq():
assert isinstance(element.product.factors[1], finat.GaussLegendre)


def test_quadrilateral_variant_spectral_dq_l2():
element = create_element(ufl.FiniteElement('DQ L2', ufl.quadrilateral, 1, variant='spectral'))
assert isinstance(element.product.factors[0], finat.GaussLegendre)
assert isinstance(element.product.factors[1], finat.GaussLegendre)


def test_cache_hit(ufl_element):
A = create_element(ufl_element)
B = create_element(ufl_element)
Expand Down
8 changes: 6 additions & 2 deletions tsfc/fiatinterface.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,10 +42,12 @@
"FacetBubble": FIAT.FacetBubble,
"Crouzeix-Raviart": FIAT.CrouzeixRaviart,
"Discontinuous Lagrange": FIAT.DiscontinuousLagrange,
"Discontinuous Lagrange L2": FIAT.DiscontinuousLagrange,
"Discontinuous Taylor": FIAT.DiscontinuousTaylor,
"Discontinuous Raviart-Thomas": FIAT.DiscontinuousRaviartThomas,
"Gauss-Lobatto-Legendre": FIAT.GaussLobattoLegendre,
"Gauss-Legendre": FIAT.GaussLegendre,
"Gauss-Legendre L2": FIAT.GaussLegendre,
"Lagrange": FIAT.Lagrange,
"Nedelec 1st kind H(curl)": FIAT.Nedelec,
"Nedelec 2nd kind H(curl)": FIAT.NedelecSecondKind,
Expand All @@ -54,16 +56,18 @@
"Regge": FIAT.Regge,
"Hellan-Herrmann-Johnson": FIAT.HellanHerrmannJohnson,
"DPC": FIAT.DPC,
"DPC L2": FIAT.DPC,
"BDMCE": FIAT.BrezziDouglasMariniCubeEdge,
"BDMCF": FIAT.BrezziDouglasMariniCubeFace,
"S": FIAT.Serendipity,
# These require special treatment below
"DQ": None,
"DQ L2": None,
"Q": None,
"RTCE": None,
"RTCF": None,
"NCE": None,
"NCF": None
"NCF": None,
}
"""A :class:`.dict` mapping UFL element family names to their
FIAT-equivalent constructors. If the value is ``None``, the UFL
Expand Down Expand Up @@ -135,7 +139,7 @@ def convert_finiteelement(element, vector_is_mixed):
lmbda = FIAT.GaussLobattoLegendre
else:
raise ValueError("Variant %r not supported on %s" % (kind, element.cell()))
elif element.family() == "Discontinuous Lagrange":
elif element.family() in ["Discontinuous Lagrange", "Discontinuous Lagrange L2"]:
if kind == 'equispaced':
lmbda = FIAT.DiscontinuousLagrange
elif kind == 'spectral' and element.cell().cellname() == 'interval':
Expand Down
8 changes: 6 additions & 2 deletions tsfc/finatinterface.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,11 @@
"FacetBubble": finat.FacetBubble,
"Crouzeix-Raviart": finat.CrouzeixRaviart,
"Discontinuous Lagrange": finat.DiscontinuousLagrange,
"Discontinuous Lagrange L2": finat.DiscontinuousLagrange,
"Discontinuous Raviart-Thomas": lambda c, d: finat.DiscontinuousElement(finat.RaviartThomas(c, d)),
"Discontinuous Taylor": finat.DiscontinuousTaylor,
"Gauss-Legendre": finat.GaussLegendre,
"Gauss-Legendre L2": finat.GaussLegendre,
"Gauss-Lobatto-Legendre": finat.GaussLobattoLegendre,
"HDiv Trace": finat.HDivTrace,
"Hellan-Herrmann-Johnson": finat.HellanHerrmannJohnson,
Expand All @@ -58,17 +60,19 @@
"Raviart-Thomas": finat.RaviartThomas,
"Regge": finat.Regge,
"DPC": finat.DPC,
"DPC L2": finat.DPC,
"BDMCE": finat.BrezziDouglasMariniCubeEdge,
"BDMCF": finat.BrezziDouglasMariniCubeFace,
"S": finat.Serendipity,
"Real": finat.DiscontinuousLagrange,
# These require special treatment below
"DQ": None,
"Q": None,
"RTCE": None,
"RTCF": None,
"NCE": None,
"NCF": None,
"Real": finat.DiscontinuousLagrange
"DQ L2": None,
}
"""A :class:`.dict` mapping UFL element family names to their
FInAT-equivalent constructors. If the value is ``None``, the UFL
Expand Down Expand Up @@ -141,7 +145,7 @@ def convert_finiteelement(element, **kwargs):
return finat.RuntimeTabulated(cell, degree, variant=kind, shift_axes=shift_axes, restriction=restriction), deps
else:
raise ValueError("Variant %r not supported on %s" % (kind, element.cell()))
elif element.family() == "Discontinuous Lagrange":
elif element.family() in ["Discontinuous Lagrange", "Discontinuous Lagrange L2"]:
kind = element.variant() or 'equispaced'
if kind == 'equispaced':
lmbda = finat.DiscontinuousLagrange
Expand Down

0 comments on commit 0ada5ba

Please sign in to comment.