From 9469765b13602c61ac84b2e570e62d6c79ef99b9 Mon Sep 17 00:00:00 2001 From: India Marsden Date: Tue, 10 Sep 2024 14:23:36 +0100 Subject: [PATCH 01/12] Make mesh cells all be cell complexes --- firedrake/mesh.py | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/firedrake/mesh.py b/firedrake/mesh.py index 906547ae72..a9fca2cecf 100644 --- a/firedrake/mesh.py +++ b/firedrake/mesh.py @@ -1216,7 +1216,6 @@ def _ufl_cell(self): # TODO: this needs to be updated for mixed-cell meshes. nfacets = self._comm.allreduce(nfacets, op=MPI.MAX) - # Note that the geometric dimension of the cell is not set here # despite it being a property of a UFL cell. It will default to # equal the topological dimension. @@ -1224,7 +1223,7 @@ def _ufl_cell(self): # represent a mesh topology (as here) have geometric dimension # equal their topological dimension. This is reflected in the # corresponding UFL mesh. - return ufl.Cell(_cells[tdim][nfacets]) + return constructCellComplex(_cells[tdim][nfacets]) @utils.cached_property def _ufl_mesh(self): @@ -1955,7 +1954,7 @@ def _mark_entity_classes(self): @utils.cached_property def _ufl_cell(self): - return ufl.Cell(_cells[0][0]) + return constructCellComplex(_cells[0][0]) @utils.cached_property def _ufl_mesh(self): From 7aed12d9ec9c33736d756787b4b3bcc5b144b2ea Mon Sep 17 00:00:00 2001 From: India Marsden Date: Mon, 25 Nov 2024 12:25:54 +0000 Subject: [PATCH 02/12] DROP BEFORE MERGE --- .github/workflows/build.yml | 3 +++ 1 file changed, 3 insertions(+) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 909db6990a..3ceca9c802 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -83,6 +83,9 @@ jobs: --install defcon \ --install gadopt \ --install asQ \ + --package-branch tsfc indiamai/new_def_integration \ + --package-branch fiat indiamai/union_different_coeff_size \ + --package-branch FInAT indiamai/new_def_integration \ || (cat firedrake-install.log && /bin/false) - name: Install test dependencies run: | From a457a5679f8ee118da2d0476e389d131d17f8444 Mon Sep 17 00:00:00 2001 From: India Marsden Date: Tue, 26 Nov 2024 11:01:52 +0000 Subject: [PATCH 03/12] First try at adding redefining_fe to packages --- .github/workflows/build.yml | 1 + requirements-git.txt | 1 + 2 files changed, 2 insertions(+) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 3ceca9c802..478d4a95bd 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -86,6 +86,7 @@ jobs: --package-branch tsfc indiamai/new_def_integration \ --package-branch fiat indiamai/union_different_coeff_size \ --package-branch FInAT indiamai/new_def_integration \ + --package-branch redefining_fe indiamai/dual_sets \ || (cat firedrake-install.log && /bin/false) - name: Install test dependencies run: | diff --git a/requirements-git.txt b/requirements-git.txt index c037220ed1..a6369a694d 100644 --- a/requirements-git.txt +++ b/requirements-git.txt @@ -6,3 +6,4 @@ git+https://github.com/dolfin-adjoint/pyadjoint.git#egg=pyadjoint-ad git+https://github.com/firedrakeproject/loopy.git@main#egg=loopy git+https://github.com/firedrakeproject/pytest-mpi.git@main#egg=pytest-mpi git+https://github.com/firedrakeproject/petsc.git@firedrake#egg=petsc +git+https://github.com/indiamai/redefining_fe.git#egg=redefining_fe \ No newline at end of file From 05086228e65e0015a576f6cd1b8c16599d158e55 Mon Sep 17 00:00:00 2001 From: India Marsden Date: Mon, 2 Dec 2024 13:32:03 +0000 Subject: [PATCH 04/12] Fix import accidently deleted in merge --- firedrake/mesh.py | 1 + 1 file changed, 1 insertion(+) diff --git a/firedrake/mesh.py b/firedrake/mesh.py index a9fca2cecf..06492165ac 100644 --- a/firedrake/mesh.py +++ b/firedrake/mesh.py @@ -37,6 +37,7 @@ from firedrake.adjoint_utils import MeshGeometryMixin from pyadjoint import stop_annotating import gem +from redefining_fe import constructCellComplex try: import netgen From 94a96dcb192f4159cbce45279ef176c58034885b Mon Sep 17 00:00:00 2001 From: India Marsden Date: Mon, 9 Dec 2024 10:55:45 +0000 Subject: [PATCH 05/12] Add changes from tsfc --- tsfc/finatinterface.py | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/tsfc/finatinterface.py b/tsfc/finatinterface.py index b7e3d0ad72..bcc1ff159e 100644 --- a/tsfc/finatinterface.py +++ b/tsfc/finatinterface.py @@ -25,6 +25,7 @@ import FIAT import finat import finat.ufl +import redefining_fe import ufl __all__ = ("as_fiat_cell", "create_base_element", @@ -111,6 +112,8 @@ def as_fiat_cell(cell): :arg cell: the :class:`ufl.Cell` to convert.""" if not isinstance(cell, ufl.AbstractCell): raise ValueError("Expecting a UFL Cell") + if isinstance(cell, redefining_fe.cells.CellComplexToUFL): + return cell.to_fiat() return FIAT.ufc_cell(cell) @@ -220,6 +223,9 @@ def convert_finiteelement(element, **kwargs): return lmbda(cell, element.degree(), **finat_kwargs), set() +@convert.register(redefining_fe.triples.IndiaTripleUFL) +def convert_india_def(element, **kwargs): + return finat.fiat_elements.IndiaDefElement(element.triple), set() # Element modifiers and compound element types @convert.register(finat.ufl.BrokenElement) From f0813214062c2695620c58b684825c3f72679c78 Mon Sep 17 00:00:00 2001 From: India Marsden Date: Mon, 9 Dec 2024 10:57:53 +0000 Subject: [PATCH 06/12] DROP BEFORE MERGE remove finat and tsfc branches --- .github/workflows/build.yml | 2 -- 1 file changed, 2 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 478d4a95bd..5b1afe7455 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -83,9 +83,7 @@ jobs: --install defcon \ --install gadopt \ --install asQ \ - --package-branch tsfc indiamai/new_def_integration \ --package-branch fiat indiamai/union_different_coeff_size \ - --package-branch FInAT indiamai/new_def_integration \ --package-branch redefining_fe indiamai/dual_sets \ || (cat firedrake-install.log && /bin/false) - name: Install test dependencies From e755dbffc9aa921470659b578c4b146746bd3bb6 Mon Sep 17 00:00:00 2001 From: India Marsden Date: Mon, 9 Dec 2024 10:58:31 +0000 Subject: [PATCH 07/12] Lint --- tsfc/finatinterface.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/tsfc/finatinterface.py b/tsfc/finatinterface.py index bcc1ff159e..9ff7e5d9d6 100644 --- a/tsfc/finatinterface.py +++ b/tsfc/finatinterface.py @@ -223,10 +223,12 @@ def convert_finiteelement(element, **kwargs): return lmbda(cell, element.degree(), **finat_kwargs), set() + @convert.register(redefining_fe.triples.IndiaTripleUFL) def convert_india_def(element, **kwargs): return finat.fiat_elements.IndiaDefElement(element.triple), set() + # Element modifiers and compound element types @convert.register(finat.ufl.BrokenElement) def convert_brokenelement(element, **kwargs): From 59bca7388603d209b49587257341a1baa15d9986 Mon Sep 17 00:00:00 2001 From: India Marsden <37078108+indiamai@users.noreply.github.com> Date: Sat, 11 Jan 2025 12:09:08 +0000 Subject: [PATCH 08/12] Rename redefining fe to fuse (#3960) Rename package --- .github/workflows/build.yml | 4 ++-- firedrake/mesh.py | 2 +- pyproject.toml | 1 + requirements-git.txt | 2 +- 4 files changed, 5 insertions(+), 4 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index f4ce3da9e0..fac37eef50 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -84,8 +84,8 @@ jobs: --install defcon \ --install gadopt \ --install asQ \ - --package-branch fiat indiamai/union_different_coeff_size \ - --package-branch redefining_fe indiamai/dual_sets \ + --package-branch fiat indiamai/integrate_fuse \ + --package-branch fuse main \ || (cat firedrake-install.log && /bin/false) - name: Install test dependencies run: | diff --git a/firedrake/mesh.py b/firedrake/mesh.py index 547b7b2e87..65009f719e 100644 --- a/firedrake/mesh.py +++ b/firedrake/mesh.py @@ -37,7 +37,7 @@ from firedrake.adjoint_utils import MeshGeometryMixin from pyadjoint import stop_annotating import gem -from redefining_fe import constructCellComplex +from fuse import constructCellComplex try: import netgen diff --git a/pyproject.toml b/pyproject.toml index bb934e4182..892483e37e 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -39,6 +39,7 @@ dependencies = [ "pyadjoint-ad @ git+https://github.com/dolfin-adjoint/pyadjoint.git", "loopy @ git+https://github.com/firedrakeproject/loopy.git@main", "libsupermesh @ git+https://github.com/firedrakeproject/libsupermesh.git", + "fuse-element @ git+https://github.com/indiamai/fuse.git", ] classifiers = [ "Development Status :: 5 - Production/Stable", diff --git a/requirements-git.txt b/requirements-git.txt index ed6fb71bba..990ec151fb 100644 --- a/requirements-git.txt +++ b/requirements-git.txt @@ -5,4 +5,4 @@ git+https://github.com/firedrakeproject/loopy.git@main#egg=loopy git+https://github.com/firedrakeproject/pytest-mpi.git@main#egg=pytest-mpi git+https://github.com/firedrakeproject/petsc.git@firedrake#egg=petsc git+https://github.com/firedrakeproject/libsupermesh.git#egg=libsupermesh -git+https://github.com/indiamai/redefining_fe.git#egg=redefining_fe \ No newline at end of file +git+https://github.com/indiamai/fuse.git#egg=fuse \ No newline at end of file From 6aa685c2475b4b7a541c44e7e206b105443e0230 Mon Sep 17 00:00:00 2001 From: India Marsden Date: Mon, 13 Jan 2025 16:10:01 +0000 Subject: [PATCH 09/12] Add original code back in as comment --- firedrake/mesh.py | 1 + 1 file changed, 1 insertion(+) diff --git a/firedrake/mesh.py b/firedrake/mesh.py index 65009f719e..15464ce2a2 100644 --- a/firedrake/mesh.py +++ b/firedrake/mesh.py @@ -1224,6 +1224,7 @@ def _ufl_cell(self): # represent a mesh topology (as here) have geometric dimension # equal their topological dimension. This is reflected in the # corresponding UFL mesh. + # return ufl.Cell(_cells[tdim][nfacets]) return constructCellComplex(_cells[tdim][nfacets]) @utils.cached_property From 361d81a4507b341e013bba0709a4a8e37233bb82 Mon Sep 17 00:00:00 2001 From: India Marsden Date: Fri, 17 Jan 2025 13:26:47 +0000 Subject: [PATCH 10/12] Clean up mesh.py --- firedrake/mesh.py | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/firedrake/mesh.py b/firedrake/mesh.py index 15464ce2a2..a6b5156b68 100644 --- a/firedrake/mesh.py +++ b/firedrake/mesh.py @@ -16,6 +16,7 @@ import rtree from textwrap import dedent from pathlib import Path +from firedrake.petsc import PETSc from pyop2 import op2 from pyop2.mpi import ( @@ -1263,6 +1264,7 @@ def cell_closure(self): cell = self.ufl_cell() assert tdim == cell.topological_dimension() + if self.submesh_parent is not None: return dmcommon.submesh_create_cell_closure_cell_submesh(plex, self.submesh_parent.topology_dm, @@ -1274,10 +1276,16 @@ def cell_closure(self): entity_per_cell = np.zeros(len(topology), dtype=IntType) for d, ents in topology.items(): entity_per_cell[d] = len(ents) - return dmcommon.closure_ordering(plex, vertex_numbering, cell_numbering, entity_per_cell) - + # elif hasattr(cell, "to_fiat"): + # TODO + # topology = cell.to_fiat().topology + # entity_per_cell = np.zeros(len(topology), dtype=IntType) + # for d, ents in topology.items(): + # entity_per_cell[d] = len(ents) + # return dmcommon.closure_ordering(plex, vertex_numbering, + # cell_numbering, entity_per_cell) elif cell.cellname() == "quadrilateral": from firedrake_citations import Citations Citations().register("Homolya2016") @@ -1308,6 +1316,7 @@ def cell_closure(self): @utils.cached_property def entity_orientations(self): + plex = self.topology_dm return dmcommon.entity_orientations(self, self.cell_closure) @PETSc.Log.EventDecorator() @@ -1333,7 +1342,6 @@ def merge_ids(x, y, datatype): op.Free() else: unique_markers = None - local_facet_number, facet_cell = \ dmcommon.facet_numbering(dm, kind, facets, self._cell_numbering, From ff9764e4d5939f67cd31a9ecc72fe47dc522d459 Mon Sep 17 00:00:00 2001 From: India Marsden Date: Fri, 17 Jan 2025 13:32:38 +0000 Subject: [PATCH 11/12] lint --- firedrake/mesh.py | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/firedrake/mesh.py b/firedrake/mesh.py index a6b5156b68..8581a198ec 100644 --- a/firedrake/mesh.py +++ b/firedrake/mesh.py @@ -16,7 +16,6 @@ import rtree from textwrap import dedent from pathlib import Path -from firedrake.petsc import PETSc from pyop2 import op2 from pyop2.mpi import ( @@ -1264,7 +1263,7 @@ def cell_closure(self): cell = self.ufl_cell() assert tdim == cell.topological_dimension() - + if self.submesh_parent is not None: return dmcommon.submesh_create_cell_closure_cell_submesh(plex, self.submesh_parent.topology_dm, @@ -1316,7 +1315,6 @@ def cell_closure(self): @utils.cached_property def entity_orientations(self): - plex = self.topology_dm return dmcommon.entity_orientations(self, self.cell_closure) @PETSc.Log.EventDecorator() From 6710bd110c43512305238aaf1708b951dd32e44c Mon Sep 17 00:00:00 2001 From: India Marsden Date: Mon, 20 Jan 2025 15:36:42 +0000 Subject: [PATCH 12/12] temp testing file --- tests/firedrake/regression/test_fuse.py | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) create mode 100644 tests/firedrake/regression/test_fuse.py diff --git a/tests/firedrake/regression/test_fuse.py b/tests/firedrake/regression/test_fuse.py new file mode 100644 index 0000000000..8009bbbff3 --- /dev/null +++ b/tests/firedrake/regression/test_fuse.py @@ -0,0 +1,21 @@ +from test_helmholtz import helmholtz +from test_poisson_strong_bcs import run_test +import pytest +import numpy as np + + + +@pytest.mark.parametrize(['params', 'degree', 'quadrilateral'], + [(p, d, q) + for p in [{}, {'snes_type': 'ksponly', 'ksp_type': 'preonly', 'pc_type': 'lu'}] + for d in (1, 2, 3) + for q in [False, True]]) +def test_poisson_analytic(params, degree, quadrilateral): + assert (run_test(2, degree, parameters=params, quadrilateral=False) < 1.e-9) + +def test_helmholtz(): + diff = np.array([helmholtz(i)[0] for i in range(3, 6)]) + print("l2 error norms:", diff) + conv = np.log2(diff[:-1] / diff[1:]) + print("convergence order:", conv) + assert (np.array(conv) > 2.8).all() \ No newline at end of file