Skip to content

Commit

Permalink
mesh: remove overdue deprecated functionality
Browse files Browse the repository at this point in the history
Removes:
* BTAG_PARTITION.part_nr
* MeshElementGroup.element_nr_base and node_nr_base
* MeshElementGroup.copy
* NodalAdjacency.copy
* FacialAdjacencyGroup.copy
  • Loading branch information
alexfikl committed Mar 5, 2024
1 parent 5dd6b29 commit 4c03df5
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 190 deletions.
171 changes: 20 additions & 151 deletions meshmode/mesh/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,9 @@
"""

from abc import ABC, abstractmethod
from dataclasses import dataclass, replace, field
from typing import Any, ClassVar, Hashable, Optional, Tuple, Type, Sequence
from dataclasses import dataclass, field, replace
from typing import Any, ClassVar, Hashable, Optional, Sequence, Tuple, Type
from warnings import warn

import numpy as np
import numpy.linalg as la
Expand All @@ -32,6 +33,7 @@

from meshmode.mesh.tools import AffineMap


__doc__ = """
.. autoclass:: MeshElementGroup
Expand Down Expand Up @@ -117,23 +119,8 @@ class BTAG_PARTITION(BTAG_NO_BOUNDARY): # noqa: N801
.. versionadded:: 2017.1
"""
def __init__(self, part_id: PartID, part_nr=None):
if part_nr is not None:
from warnings import warn
warn("part_nr is deprecated and will stop working in March 2023. "
"Use part_id instead.",
DeprecationWarning, stacklevel=2)
self.part_id = int(part_nr)
else:
self.part_id = part_id

@property
def part_nr(self):
from warnings import warn
warn("part_nr is deprecated and will stop working in March 2023. "
"Use part_id instead.",
DeprecationWarning, stacklevel=2)
return self.part_id
def __init__(self, part_id: PartID) -> None:
self.part_id = part_id

def __hash__(self):
return hash((type(self), self.part_id))
Expand Down Expand Up @@ -251,43 +238,9 @@ class MeshElementGroup(ABC):
"""

order: int

# NOTE: the mesh supports not having vertices if no facial or nodal
# adjacency is required, so we can mark this as optional
vertex_indices: Optional[np.ndarray]
nodes: np.ndarray

# TODO: Remove ` = None` when everything is constructed through the factory
unit_nodes: np.ndarray = None

# FIXME: these should be removed!
# https://github.com/inducer/meshmode/issues/224
element_nr_base: Optional[int] = None
node_nr_base: Optional[int] = None

# TODO: remove when everything has been constructed through the factory
_factory_constructed: bool = False

def __post_init__(self):
if not self._factory_constructed:
from warnings import warn
warn(f"Calling the constructor of '{type(self).__name__}' is "
"deprecated and will stop working in July 2022. "
f"Use '{type(self).__name__}.make_group' instead",
DeprecationWarning, stacklevel=2)

def __getattribute__(self, name):
if name in ("element_nr_base", "node_nr_base"):
new_name = ("base_element_nrs"
if name == "element_nr_base" else
"base_node_nrs")

from warnings import warn
warn(f"'{type(self).__name__}.{name}' is deprecated and will be "
f"removed in July 2022. Use 'Mesh.{new_name}' instead",
DeprecationWarning, stacklevel=2)

return super().__getattribute__(name)
unit_nodes: np.ndarray

@property
def dim(self):
Expand All @@ -313,21 +266,6 @@ def nelements(self):
def nnodes(self):
return self.nelements * self.unit_nodes.shape[-1]

def copy(self, **kwargs: Any) -> "MeshElementGroup":
from warnings import warn
warn(f"{type(self).__name__}.copy is deprecated and will be removed in "
f"July 2022. {type(self).__name__} is now a dataclass, so "
"standard functions such as dataclasses.replace should be used "
"instead.",
DeprecationWarning, stacklevel=2)

if "element_nr_base" not in kwargs:
kwargs["element_nr_base"] = None
if "node_nr_base" not in kwargs:
kwargs["node_nr_base"] = None

return replace(self, **kwargs)

def __eq__(self, other):
return (
type(self) is type(other)
Expand Down Expand Up @@ -384,62 +322,10 @@ class _ModepyElementGroup(MeshElementGroup):
.. attribute:: _modepy_space
"""

# TODO: remove once `make_group` is used everywhere
dim: Optional[int] = None

_modepy_shape_cls: ClassVar[Type[mp.Shape]] = mp.Shape
_modepy_shape: mp.Shape = field(default=None, repr=False)
_modepy_space: mp.FunctionSpace = field(default=None, repr=False)

def __post_init__(self):
super().__post_init__()
if self._factory_constructed:
return

# {{{ duplicates make_group below, keep in sync

if self.unit_nodes is None:
if self.dim is None:
raise TypeError("either 'dim' or 'unit_nodes' must be provided")
else:
if self.dim is None:
object.__setattr__(self, "dim", self.unit_nodes.shape[0])

if self.unit_nodes.shape[0] != self.dim:
raise ValueError("'dim' does not match 'unit_nodes' dimension")

# dim is now usable
assert self._modepy_shape_cls is not mp.Shape
object.__setattr__(self, "_modepy_shape",
# pylint: disable=abstract-class-instantiated
self._modepy_shape_cls(self.dim))
object.__setattr__(self, "_modepy_space",
mp.space_for_shape(self._modepy_shape, self.order))

if self.unit_nodes is None:
unit_nodes = mp.edge_clustered_nodes_for_space(
self._modepy_space, self._modepy_shape)
object.__setattr__(self, "unit_nodes", unit_nodes)

if self.nodes is not None:
if self.unit_nodes.shape[-1] != self.nodes.shape[-1]:
raise ValueError(
"'nodes' has wrong number of unit nodes per element."
f" expected {self.unit_nodes.shape[-1]}, "
f" but got {self.nodes.shape[-1]}.")

if self.vertex_indices is not None:
if not issubclass(self.vertex_indices.dtype.type, np.integer):
raise TypeError("'vertex_indices' must be integral")

if self.vertex_indices.shape[-1] != self.nvertices:
raise ValueError(
"'vertex_indices' has wrong number of vertices per element."
f" expected {self.nvertices},"
f" got {self.vertex_indices.shape[-1]}")

# }}}

@property
def nvertices(self):
return self._modepy_shape.nvertices # pylint: disable=no-member
Expand Down Expand Up @@ -486,11 +372,12 @@ def make_group(cls, order: int,
raise ValueError("'unit_nodes' size does not match the dimension "
f"of a '{type(space).__name__}' space of order {order}")

return cls(order=order, vertex_indices=vertex_indices, nodes=nodes,
dim=dim,
return cls(order=order,
vertex_indices=vertex_indices,
nodes=nodes,
unit_nodes=unit_nodes,
_modepy_shape=shape, _modepy_space=space,
_factory_constructed=True)
_modepy_shape=shape,
_modepy_space=space)

# }}}

Expand All @@ -500,6 +387,7 @@ def make_group(cls, order: int,
@dataclass(frozen=True, eq=False)
class SimplexElementGroup(_ModepyElementGroup):
r"""Inherits from :class:`MeshElementGroup`."""

_modepy_shape_cls: ClassVar[Type[mp.Shape]] = mp.Simplex

@property
Expand All @@ -511,6 +399,7 @@ def is_affine(self):
@dataclass(frozen=True, eq=False)
class TensorProductElementGroup(_ModepyElementGroup):
r"""Inherits from :class:`MeshElementGroup`."""

_modepy_shape_cls: ClassVar[Type[mp.Shape]] = mp.Hypercube

def is_affine(self):
Expand Down Expand Up @@ -549,16 +438,6 @@ class NodalAdjacency:
neighbors_starts: np.ndarray
neighbors: np.ndarray

def copy(self, **kwargs: Any) -> "NodalAdjacency":
from warnings import warn
warn(f"{type(self).__name__}.copy is deprecated and will be removed in "
f"July 2022. {type(self).__name__} is now a dataclass, so "
"standard functions such as dataclasses.replace should be used "
"instead.",
DeprecationWarning, stacklevel=2)

return replace(self, **kwargs)

def __eq__(self, other):
return (
type(self) is type(other)
Expand Down Expand Up @@ -605,16 +484,6 @@ class FacialAdjacencyGroup:

igroup: int

def copy(self, **kwargs: Any) -> "FacialAdjacencyGroup":
from warnings import warn
warn(f"{type(self).__name__}.copy is deprecated and will be removed in "
f"July 2022. {type(self).__name__} is now a dataclass, so "
"standard functions such as dataclasses.replace should be used "
"instead.",
DeprecationWarning, stacklevel=2)

return replace(self, **kwargs)

def __eq__(self, other):
return (
type(self) is type(other)
Expand Down Expand Up @@ -1076,8 +945,8 @@ def __init__(self, vertices, groups, *, skip_tests=False,
assert fagrp.neighbor_faces.dtype == self.face_id_dtype
assert fagrp.neighbor_faces.shape == (nfagrp_elements,)

from meshmode.mesh.processing import \
test_volume_mesh_element_orientations
from meshmode.mesh.processing import (
test_volume_mesh_element_orientations)

if self.dim == self.ambient_dim and not skip_element_orientation_test:
# only for volume meshes, for now
Expand Down Expand Up @@ -1269,9 +1138,9 @@ def _test_node_vertex_consistency(mesh, tol):
if isinstance(mgrp, _ModepyElementGroup):
assert _test_node_vertex_consistency_resampling(mesh, igrp, tol)
else:
from warnings import warn
warn("not implemented: node-vertex consistency check for '%s'"
% type(mgrp).__name__)
warn("Not implemented: node-vertex consistency check for "
f"groups of type '{type(mgrp).__name__}'.",
stacklevel=3)

return True

Expand Down Expand Up @@ -1657,7 +1526,7 @@ def as_python(mesh, function_name="make_mesh"):
recreate the mesh given as an input parameter.
"""

from pytools.py_codegen import PythonCodeGenerator, Indentation
from pytools.py_codegen import Indentation, PythonCodeGenerator
cg = PythonCodeGenerator()
cg("""
# generated by meshmode.mesh.as_python
Expand Down
Loading

0 comments on commit 4c03df5

Please sign in to comment.