Skip to content

Commit

Permalink
MeshSequence: rename
Browse files Browse the repository at this point in the history
  • Loading branch information
ksagiyam committed Jan 13, 2025
1 parent 15f6eb1 commit adaf776
Show file tree
Hide file tree
Showing 10 changed files with 41 additions and 41 deletions.
10 changes: 5 additions & 5 deletions firedrake/checkpointing.py
Original file line number Diff line number Diff line change
Expand Up @@ -565,7 +565,7 @@ def save_mesh(self, mesh, distribution_name=None, permutation_name=None):
:kwarg distribution_name: the name under which distribution is saved; if `None`, auto-generated name will be used.
:kwarg permutation_name: the name under which permutation is saved; if `None`, auto-generated name will be used.
"""
# TODO: Add general MixedMesh support.
# TODO: Add general MeshSequence support.
mesh = mesh.unique()
mesh.init()
# Handle extruded mesh
Expand Down Expand Up @@ -838,7 +838,7 @@ def get_timestepping_history(self, mesh, name):
@PETSc.Log.EventDecorator("SaveFunctionSpace")
def _save_function_space(self, V):
mesh = V.mesh()
# TODO: Add general MixedMesh support.
# TODO: Add general MeshSequence support.
mesh = mesh.unique()
if isinstance(V.topological, impl.MixedFunctionSpace):
V_name = self._generate_function_space_name(V)
Expand Down Expand Up @@ -919,7 +919,7 @@ def save_function(self, f, idx=None, name=None, timestepping_info={}):
g = Function(V, val=f.dat, name=name)
return self.save_function(g, idx=idx, timestepping_info=timestepping_info)
mesh = V.mesh()
# TODO: Add general MixedMesh support.
# TODO: Add general MeshSequence support.
mesh = mesh.unique()
# -- Save function space --
self._save_function_space(V)
Expand Down Expand Up @@ -1239,7 +1239,7 @@ def _load_mesh_topology(self, tmesh_name, reorder, distribution_parameters):

@PETSc.Log.EventDecorator("LoadFunctionSpace")
def _load_function_space(self, mesh, name):
# TODO: Add general MixedMesh support.
# TODO: Add general MeshSequence support.
mesh = mesh.unique()
mesh.init()
mesh_key = self._generate_mesh_key_from_names(mesh.name,
Expand Down Expand Up @@ -1318,7 +1318,7 @@ def load_function(self, mesh, name, idx=None):
be loaded with idx only when it was saved with idx.
:returns: the loaded :class:`~.Function`.
"""
# TODO: Add general MixedMesh support.
# TODO: Add general MeshSequence support.
mesh = mesh.unique()
tmesh = mesh.topology
if name in self._get_mixed_function_name_mixed_function_space_name_map(mesh.name):
Expand Down
4 changes: 2 additions & 2 deletions firedrake/dmhooks.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@

import firedrake
from firedrake.petsc import PETSc
from firedrake.mesh import MixedMeshGeometry
from firedrake.mesh import MeshSequenceGeometry


@PETSc.Log.EventDecorator()
Expand All @@ -58,7 +58,7 @@ def get_function_space(dm):
if len(meshref_tuple) == 1:
mesh = meshref_tuple[0]()
else:
mesh = MixedMeshGeometry([meshref() for meshref in meshref_tuple])
mesh = MeshSequenceGeometry([meshref() for meshref in meshref_tuple])
if mesh is None:
raise RuntimeError("Somehow your mesh was collected, this should never happen")
V = firedrake.FunctionSpace(mesh, element, name=name)
Expand Down
6 changes: 3 additions & 3 deletions firedrake/functionspace.py
Original file line number Diff line number Diff line change
Expand Up @@ -259,7 +259,7 @@ def MixedFunctionSpace(spaces, name=None, mesh=None):
:class:`finat.ufl.mixedelement.MixedElement`, ignored otherwise.
"""
from firedrake.mesh import MixedMeshGeometry
from firedrake.mesh import MeshSequenceGeometry

if isinstance(spaces, finat.ufl.FiniteElementBase):
# Build the spaces if we got a mixed element
Expand All @@ -275,7 +275,7 @@ def rec(eles):
sub_elements.append(ele)
rec(spaces.sub_elements)
spaces = [FunctionSpace(mesh, element) for element in sub_elements]
# Flatten MixedMeshes.
# Flatten MeshSequences.
meshes = list(itertools.chain(*[space.mesh() for space in spaces]))
try:
cls, = set(type(s) for s in spaces)
Expand All @@ -297,7 +297,7 @@ def rec(eles):
else:
raise ValueError("Can't make mixed space with %s" % type(space))

mixed_mesh_geometry = MixedMeshGeometry(meshes)
mixed_mesh_geometry = MeshSequenceGeometry(meshes)
new = impl.MixedFunctionSpace(spaces, mixed_mesh_geometry.topology, name=name)
return cls.create(new, mixed_mesh_geometry)

Expand Down
24 changes: 12 additions & 12 deletions firedrake/functionspaceimpl.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
from pyop2.utils import as_tuple

from firedrake import dmhooks, utils
from firedrake.mesh import MeshGeometry, MixedMeshTopology, MixedMeshGeometry
from firedrake.mesh import MeshGeometry, MeshSequenceTopology, MeshSequenceGeometry
from firedrake.functionspacedata import get_shared_data, create_element
from firedrake.petsc import PETSc

Expand Down Expand Up @@ -95,8 +95,8 @@ class WithGeometryBase(object):
"""
def __init__(self, mesh, element, component=None, cargo=None):
if type(element) is finat.ufl.MixedElement:
if not isinstance(mesh, MixedMeshGeometry):
raise TypeError(f"Can only use MixedElement with MixedMeshGeometry: got {type(mesh)}")
if not isinstance(mesh, MeshSequenceGeometry):
raise TypeError(f"Can only use MixedElement with MeshSequenceGeometry: got {type(mesh)}")
assert component is None or isinstance(component, int)
assert cargo is None or isinstance(cargo, FunctionSpaceCargo)
super().__init__(mesh, element, label=cargo.topological._label or "")
Expand All @@ -120,8 +120,8 @@ def create(cls, function_space, mesh, parent=None):
"""
if isinstance(function_space, MixedFunctionSpace):
if not isinstance(mesh, MixedMeshGeometry):
raise TypeError(f"Can only use MixedFunctionSpace with MixedMeshGeometry: got {type(mesh)}")
if not isinstance(mesh, MeshSequenceGeometry):
raise TypeError(f"Can only use MixedFunctionSpace with MeshSequenceGeometry: got {type(mesh)}")
function_space = function_space.topological
assert mesh.topology is function_space.mesh()
assert mesh.topology is not mesh
Expand Down Expand Up @@ -372,16 +372,16 @@ def make_function_space(cls, mesh, element, name=None):
# Create a new abstract (Mixed/Real)FunctionSpace, these are neither primal nor dual.
if type(element) is finat.ufl.MixedElement:
if isinstance(mesh, MeshGeometry):
mesh = MixedMeshGeometry([mesh for _ in element.sub_elements])
mesh = MeshSequenceGeometry([mesh for _ in element.sub_elements])
topology = mesh.topology
else:
if not isinstance(mesh, MixedMeshGeometry):
raise TypeError(f"mesh must be MixedMeshGeometry: got {mesh}")
if not isinstance(mesh, MeshSequenceGeometry):
raise TypeError(f"mesh must be MeshSequenceGeometry: got {mesh}")
spaces = [cls.make_function_space(topo, e) for topo, e in zip(topology, element.sub_elements, strict=True)]
new = MixedFunctionSpace(spaces, topology, name=name)
else:
if isinstance(mesh, MixedMeshGeometry):
raise TypeError(f"mesh must not be MixedMeshGeometry: got {mesh}")
if isinstance(mesh, MeshSequenceGeometry):
raise TypeError(f"mesh must not be MeshSequenceGeometry: got {mesh}")
# Check that any Vector/Tensor/Mixed modifiers are outermost.
check_element(element)
if element.family() == "Real":
Expand Down Expand Up @@ -979,8 +979,8 @@ class MixedFunctionSpace(object):
"""
def __init__(self, spaces, mesh, name=None):
super(MixedFunctionSpace, self).__init__()
if not isinstance(mesh, MixedMeshTopology):
raise TypeError(f"mesh must be MixedMeshTopology: got {mesh}")
if not isinstance(mesh, MeshSequenceTopology):
raise TypeError(f"mesh must be MeshSequenceTopology: got {mesh}")
if len(mesh) != len(spaces):
raise RuntimeError(f"len(mesh) ({len(mesh)}) != len(spaces) ({len(spaces)})")
self._spaces = tuple(IndexedFunctionSpace(i, s, self)
Expand Down
16 changes: 8 additions & 8 deletions firedrake/mesh.py
Original file line number Diff line number Diff line change
Expand Up @@ -4691,7 +4691,7 @@ def Submesh(mesh, subdim, subdomain_id, label_name=None, name=None):
return submesh


class MixedMeshGeometry(ufl.MixedMesh):
class MeshSequenceGeometry(ufl.MeshSequence):
"""A representation of mixed mesh geometry."""

def __init__(self, meshes, set_hierarchy=True):
Expand All @@ -4700,7 +4700,7 @@ def __init__(self, meshes, set_hierarchy=True):
Parameters
----------
meshes : tuple or list
`MeshGeometry`s to make `MixedMeshGeometry` with.
`MeshGeometry`s to make `MeshSequenceGeometry` with.
set_hierarchy : bool
Flag for making hierarchy.
Expand All @@ -4717,7 +4717,7 @@ def __init__(self, meshes, set_hierarchy=True):

@utils.cached_property
def topology(self):
return MixedMeshTopology([m.topology for m in self._meshes])
return MeshSequenceTopology([m.topology for m in self._meshes])

@property
def topological(self):
Expand Down Expand Up @@ -4790,13 +4790,13 @@ def set_hierarchy(self):
if ilevel == level:
result.append(self)
else:
result.append(MixedMeshGeometry([hierarchy[ilevel] for hierarchy in hierarchy_list], set_hierarchy=False))
result.append(MeshSequenceGeometry([hierarchy[ilevel] for hierarchy in hierarchy_list], set_hierarchy=False))
result = tuple(result)
for i, m in enumerate(result):
set_level(m, result, i)


class MixedMeshTopology(object):
class MeshSequenceTopology(object):
"""A representation of mixed mesh topology."""

def __init__(self, meshes):
Expand All @@ -4805,7 +4805,7 @@ def __init__(self, meshes):
Parameters
----------
meshes : tuple or list
`MeshTopology`s to make `MixedMeshTopology` with.
`MeshTopology`s to make `MeshSequenceTopology` with.
"""
for m in meshes:
Expand Down Expand Up @@ -4837,8 +4837,8 @@ def ufl_cell(self):

def ufl_mesh(self):
cell = self.ufl_cell()
return ufl.MixedMesh([ufl.Mesh(finat.ufl.VectorElement("Lagrange", cell, 1, dim=cell.topological_dimension()))
for _ in self._meshes])
return ufl.MeshSequence([ufl.Mesh(finat.ufl.VectorElement("Lagrange", cell, 1, dim=cell.topological_dimension()))
for _ in self._meshes])

def __eq__(self, other):
if type(other) != type(self):
Expand Down
4 changes: 2 additions & 2 deletions firedrake/mg/ufl_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ def coarsen(expr, self, coefficient_mapping=None):


@coarsen.register(ufl.Mesh)
@coarsen.register(ufl.MixedMesh)
@coarsen.register(ufl.MeshSequence)
def coarsen_mesh(mesh, self, coefficient_mapping=None):
hierarchy, level = utils.get_level(mesh)
if hierarchy is None:
Expand Down Expand Up @@ -133,7 +133,7 @@ def coarsen_function_space(V, self, coefficient_mapping=None):
return V._coarse

V_fine = V
# Handle MixedFunctionSpace : V_fine.reconstruct requires MixedMesh.
# Handle MixedFunctionSpace : V_fine.reconstruct requires MeshSequence.
fine_mesh = V_fine.mesh() if V_fine.index is None else V_fine.parent.mesh()
mesh_coarse = self(fine_mesh, self)
name = f"coarse_{V.name}" if V.name else None
Expand Down
4 changes: 2 additions & 2 deletions firedrake/ufl_expr.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
from ufl.domain import as_domain
import firedrake
from firedrake import utils, function, cofunction
from firedrake.mesh import MixedMeshGeometry
from firedrake.mesh import MeshSequenceGeometry
from firedrake.constant import Constant
from firedrake.petsc import PETSc

Expand Down Expand Up @@ -385,7 +385,7 @@ def extract_domains(f):
elif isinstance(f, cofunction.Cofunction):
# ufl.domain.extract_domains does not work.
mesh = f.function_space().mesh()
if isinstance(mesh, MixedMeshGeometry):
if isinstance(mesh, MeshSequenceGeometry):
return list(set(mesh._meshes))
else:
return [mesh]
Expand Down
4 changes: 2 additions & 2 deletions tests/tsfc/test_tsfc_182.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import pytest

from ufl import Coefficient, TestFunction, dx, inner, tetrahedron, Mesh, MixedMesh, FunctionSpace
from ufl import Coefficient, TestFunction, dx, inner, tetrahedron, Mesh, MeshSequence, FunctionSpace
from finat.ufl import FiniteElement, MixedElement, VectorElement

from tsfc import compile_form
Expand All @@ -20,7 +20,7 @@ def test_delta_elimination(mode):

element_chi_lambda = MixedElement(element_eps_p, element_lambda)
domain = Mesh(VectorElement("Lagrange", tetrahedron, 1))
domains = MixedMesh([domain, domain])
domains = MeshSequence([domain, domain])
space = FunctionSpace(domains, element_chi_lambda)

chi_lambda = Coefficient(space)
Expand Down
4 changes: 2 additions & 2 deletions tests/tsfc/test_tsfc_204.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
from tsfc import compile_form
from ufl import (Coefficient, FacetNormal,
FunctionSpace, Mesh, MixedMesh, as_matrix,
FunctionSpace, Mesh, MeshSequence, as_matrix,
dot, dS, ds, dx, facet, grad, inner, outer, split, triangle)
from finat.ufl import BrokenElement, FiniteElement, MixedElement, VectorElement


def test_physically_mapped_facet():
mesh = Mesh(VectorElement("P", triangle, 1))
meshes = MixedMesh([mesh, mesh, mesh, mesh, mesh])
meshes = MeshSequence([mesh, mesh, mesh, mesh, mesh])

# set up variational problem
U = FiniteElement("Morley", mesh.ufl_cell(), 2)
Expand Down
6 changes: 3 additions & 3 deletions tsfc/kernel_interface/firedrake_loopy.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
from collections import namedtuple, OrderedDict

from ufl import Coefficient, FunctionSpace
from ufl.domain import MixedMesh
from ufl.domain import MeshSequence
from finat.ufl import MixedElement as ufl_MixedElement, FiniteElement

import gem
Expand Down Expand Up @@ -360,8 +360,8 @@ def set_coordinates(self, domains):
"""
# Create a fake coordinate coefficient for a domain.
for i, domain in enumerate(domains):
if isinstance(domain, MixedMesh):
raise RuntimeError("Found a MixedMesh")
if isinstance(domain, MeshSequence):
raise RuntimeError("Found a MeshSequence")
f = Coefficient(FunctionSpace(domain, domain.ufl_coordinate_element()))
self.domain_coordinate[domain] = f
self._coefficient(f, f"coords_{i}")
Expand Down

0 comments on commit adaf776

Please sign in to comment.