From 42dc359c3a65629b1bd30853e07782d564767400 Mon Sep 17 00:00:00 2001 From: Chris Eldred Date: Thu, 20 Jun 2019 14:57:10 +0100 Subject: [PATCH 1/7] add l2 pullbacks to discontinuous elements --- tsfc/fiatinterface.py | 10 +++++++--- tsfc/finatinterface.py | 10 +++++++--- 2 files changed, 14 insertions(+), 6 deletions(-) diff --git a/tsfc/fiatinterface.py b/tsfc/fiatinterface.py index e0c70f78..7ba8bcd9 100644 --- a/tsfc/fiatinterface.py +++ b/tsfc/fiatinterface.py @@ -61,7 +61,11 @@ "NCE": None, "NCF": None, "DPC": FIAT.DPC, - "S": FIAT.Serendipity + "S": FIAT.Serendipity, + "DPC L2": FIAT.DPC, + "Discontinuous Lagrange L2": FIAT.DiscontinuousLagrange, + "Gauss-Legendre L2": FIAT.GaussLegendre, + "DQ L2": None, } """A :class:`.dict` mapping UFL element family names to their FIAT-equivalent constructors. If the value is ``None``, the UFL @@ -133,14 +137,14 @@ 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': lmbda = FIAT.GaussLegendre else: raise ValueError("Variant %r not supported on %s" % (kind, element.cell())) - elif element.family() == "DPC": + elif element.family() in ["DPC", "DPC L2"]: if element.cell().geometric_dimension() == 2: element = element.reconstruct(cell=ufl.hypercube(2)) elif element.cell.geometric_dimension() == 3: diff --git a/tsfc/finatinterface.py b/tsfc/finatinterface.py index d371605f..b079dcf9 100644 --- a/tsfc/finatinterface.py +++ b/tsfc/finatinterface.py @@ -66,7 +66,11 @@ "NCF": None, "Real": finat.DiscontinuousLagrange, "DPC": finat.DPC, - "S": finat.Serendipity + "S": finat.Serendipity, + "DPC L2": finat.DPC, + "Discontinuous Lagrange L2": finat.DiscontinuousLagrange, + "Gauss-Legendre L2": finat.GaussLegendre, + "DQ L2": None, } """A :class:`.dict` mapping UFL element family names to their FInAT-equivalent constructors. If the value is ``None``, the UFL @@ -139,7 +143,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 @@ -153,7 +157,7 @@ def convert_finiteelement(element, **kwargs): return finat.RuntimeTabulated(cell, degree, variant=kind, shift_axes=shift_axes, restriction=restriction, continuous=False), deps else: raise ValueError("Variant %r not supported on %s" % (kind, element.cell())) - elif element.family() == "DPC": + elif element.family() == ["DPC", "DPC L2"]: if element.cell().geometric_dimension() == 2: element = element.reconstruct(cell=ufl.cell.hypercube(2)) elif element.cell().geometric_dimension() == 3: From f9302665275044e43ae007b04f9f030c8edc7598 Mon Sep 17 00:00:00 2001 From: Chris Eldred Date: Thu, 20 Jun 2019 15:20:21 +0100 Subject: [PATCH 2/7] add testing --- tests/test_create_fiat_element.py | 17 ++++++++++++++--- tests/test_create_finat_element.py | 17 ++++++++++++++--- 2 files changed, 28 insertions(+), 6 deletions(-) diff --git a/tests/test_create_fiat_element.py b/tests/test_create_fiat_element.py index c8989733..8f3f6dda 100644 --- a/tests/test_create_fiat_element.py +++ b/tests/test_create_fiat_element.py @@ -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 @@ -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) @@ -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) @@ -83,6 +86,10 @@ def test_triangle_variant_spectral_fail(): with pytest.raises(ValueError): 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')) @@ -95,6 +102,10 @@ def test_quadrilateral_variant_spectral_dq(): assert isinstance(element.element.A, FIAT.GaussLegendre) 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')) diff --git a/tests/test_create_finat_element.py b/tests/test_create_finat_element.py index e135576d..e1ccedd2 100644 --- a/tests/test_create_finat_element.py +++ b/tests/test_create_finat_element.py @@ -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 @@ -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) @@ -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) @@ -91,6 +94,10 @@ def test_triangle_variant_spectral_fail(): with pytest.raises(ValueError): 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')) @@ -103,6 +110,10 @@ def test_quadrilateral_variant_spectral_dq(): assert isinstance(element.product.factors[0], finat.GaussLegendre) 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) From b91144521180e3575d15b2a084ad2c27cf36d9fc Mon Sep 17 00:00:00 2001 From: Chris Eldred Date: Thu, 20 Jun 2019 16:05:20 +0100 Subject: [PATCH 3/7] DROP BEFORE MERGE --- requirements-git.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/requirements-git.txt b/requirements-git.txt index 2d8326de..67a4378a 100644 --- a/requirements-git.txt +++ b/requirements-git.txt @@ -1,5 +1,5 @@ git+https://github.com/coneoproject/COFFEE.git#egg=coffee -git+https://github.com/firedrakeproject/ufl.git#egg=ufl +git+https://github.com/firedrakeproject/ufl.git#egg=ufl@l2pullbacks git+https://github.com/firedrakeproject/fiat.git#egg=fiat git+https://github.com/FInAT/FInAT.git#egg=finat git+https://github.com/firedrakeproject/loopy.git@firedrake#egg=loopy From 8f3432d9491aa9e9b9f432b4cbfeb08f484c9c6a Mon Sep 17 00:00:00 2001 From: Chris Eldred Date: Thu, 20 Jun 2019 16:08:43 +0100 Subject: [PATCH 4/7] DROP BEFORE MERGE --- requirements-git.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/requirements-git.txt b/requirements-git.txt index 67a4378a..17f990b4 100644 --- a/requirements-git.txt +++ b/requirements-git.txt @@ -1,5 +1,5 @@ git+https://github.com/coneoproject/COFFEE.git#egg=coffee -git+https://github.com/firedrakeproject/ufl.git#egg=ufl@l2pullbacks +git+https://github.com/firedrakeproject/ufl.git@l2pullbacks#egg=ufl git+https://github.com/firedrakeproject/fiat.git#egg=fiat git+https://github.com/FInAT/FInAT.git#egg=finat git+https://github.com/firedrakeproject/loopy.git@firedrake#egg=loopy From 3ba9c2acf1c10552823331334072d4f03ebd1263 Mon Sep 17 00:00:00 2001 From: Chris Eldred Date: Thu, 20 Jun 2019 16:33:54 +0100 Subject: [PATCH 5/7] flake8 --- tests/test_create_fiat_element.py | 4 ++++ tests/test_create_finat_element.py | 4 ++++ 2 files changed, 8 insertions(+) diff --git a/tests/test_create_fiat_element.py b/tests/test_create_fiat_element.py index 8f3f6dda..b47facdf 100644 --- a/tests/test_create_fiat_element.py +++ b/tests/test_create_fiat_element.py @@ -86,11 +86,13 @@ def test_triangle_variant_spectral_fail(): with pytest.raises(ValueError): 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) @@ -102,11 +104,13 @@ def test_quadrilateral_variant_spectral_dq(): assert isinstance(element.element.A, FIAT.GaussLegendre) 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) diff --git a/tests/test_create_finat_element.py b/tests/test_create_finat_element.py index e1ccedd2..04b6a2a6 100644 --- a/tests/test_create_finat_element.py +++ b/tests/test_create_finat_element.py @@ -94,11 +94,13 @@ def test_triangle_variant_spectral_fail(): with pytest.raises(ValueError): 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) @@ -110,11 +112,13 @@ def test_quadrilateral_variant_spectral_dq(): assert isinstance(element.product.factors[0], finat.GaussLegendre) 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) From 5a505350a0fb4eb3753cbfa6307b08b8e9880954 Mon Sep 17 00:00:00 2001 From: David Ham Date: Fri, 9 Aug 2019 13:11:36 +0100 Subject: [PATCH 6/7] UFL PR has landed --- requirements-git.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/requirements-git.txt b/requirements-git.txt index 17f990b4..2d8326de 100644 --- a/requirements-git.txt +++ b/requirements-git.txt @@ -1,5 +1,5 @@ git+https://github.com/coneoproject/COFFEE.git#egg=coffee -git+https://github.com/firedrakeproject/ufl.git@l2pullbacks#egg=ufl +git+https://github.com/firedrakeproject/ufl.git#egg=ufl git+https://github.com/firedrakeproject/fiat.git#egg=fiat git+https://github.com/FInAT/FInAT.git#egg=finat git+https://github.com/firedrakeproject/loopy.git@firedrake#egg=loopy From 28c61a3c9d4c5b787e201466bd03018076502d2d Mon Sep 17 00:00:00 2001 From: Thomas Gibson Date: Wed, 21 Aug 2019 11:20:48 +0100 Subject: [PATCH 7/7] Remove hypercube reconstruction --- tsfc/fiatinterface.py | 11 ----------- 1 file changed, 11 deletions(-) diff --git a/tsfc/fiatinterface.py b/tsfc/fiatinterface.py index 54e00c78..a4b6f360 100644 --- a/tsfc/fiatinterface.py +++ b/tsfc/fiatinterface.py @@ -144,17 +144,6 @@ def convert_finiteelement(element, vector_is_mixed): lmbda = FIAT.GaussLegendre else: raise ValueError("Variant %r not supported on %s" % (kind, element.cell())) - elif element.family() in ["DPC", "DPC L2"]: - if element.cell().geometric_dimension() == 2: - element = element.reconstruct(cell=ufl.hypercube(2)) - elif element.cell.geometric_dimension() == 3: - element = element.reconstruct(cell=ufl.hypercube(3)) - elif element.family() == "S": - if element.cell().geometric_dimension() == 2: - element = element.reconstruct(cell=ufl.hypercube(2)) - elif element.cell().geometric_dimension() == 3: - element = element.reconstruct(cell=ufl.hypercube(3)) - return lmbda(cell, element.degree())