Skip to content

Commit 982194b

Browse files
committed
mesh: remove overdue deprecated functionality
Removes: * BTAG_PARTITION.part_nr * MeshElementGroup.element_nr_base and node_nr_base * MeshElementGroup.copy * NodalAdjacency.copy * FacialAdjacencyGroup.copy
1 parent 052d11e commit 982194b

File tree

2 files changed

+35
-190
lines changed

2 files changed

+35
-190
lines changed

meshmode/mesh/__init__.py

+20-151
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,9 @@
2121
"""
2222

2323
from abc import ABC, abstractmethod
24-
from dataclasses import dataclass, replace, field
25-
from typing import Any, ClassVar, Hashable, Optional, Tuple, Type, Sequence
24+
from dataclasses import dataclass, field, replace
25+
from typing import Any, ClassVar, Hashable, Optional, Sequence, Tuple, Type
26+
from warnings import warn
2627

2728
import numpy as np
2829
import numpy.linalg as la
@@ -32,6 +33,7 @@
3233

3334
from meshmode.mesh.tools import AffineMap
3435

36+
3537
__doc__ = """
3638
3739
.. autoclass:: MeshElementGroup
@@ -117,23 +119,8 @@ class BTAG_PARTITION(BTAG_NO_BOUNDARY): # noqa: N801
117119
118120
.. versionadded:: 2017.1
119121
"""
120-
def __init__(self, part_id: PartID, part_nr=None):
121-
if part_nr is not None:
122-
from warnings import warn
123-
warn("part_nr is deprecated and will stop working in March 2023. "
124-
"Use part_id instead.",
125-
DeprecationWarning, stacklevel=2)
126-
self.part_id = int(part_nr)
127-
else:
128-
self.part_id = part_id
129-
130-
@property
131-
def part_nr(self):
132-
from warnings import warn
133-
warn("part_nr is deprecated and will stop working in March 2023. "
134-
"Use part_id instead.",
135-
DeprecationWarning, stacklevel=2)
136-
return self.part_id
122+
def __init__(self, part_id: PartID) -> None:
123+
self.part_id = part_id
137124

138125
def __hash__(self):
139126
return hash((type(self), self.part_id))
@@ -251,43 +238,9 @@ class MeshElementGroup(ABC):
251238
"""
252239

253240
order: int
254-
255-
# NOTE: the mesh supports not having vertices if no facial or nodal
256-
# adjacency is required, so we can mark this as optional
257241
vertex_indices: Optional[np.ndarray]
258242
nodes: np.ndarray
259-
260-
# TODO: Remove ` = None` when everything is constructed through the factory
261-
unit_nodes: np.ndarray = None
262-
263-
# FIXME: these should be removed!
264-
# https://github.com/inducer/meshmode/issues/224
265-
element_nr_base: Optional[int] = None
266-
node_nr_base: Optional[int] = None
267-
268-
# TODO: remove when everything has been constructed through the factory
269-
_factory_constructed: bool = False
270-
271-
def __post_init__(self):
272-
if not self._factory_constructed:
273-
from warnings import warn
274-
warn(f"Calling the constructor of '{type(self).__name__}' is "
275-
"deprecated and will stop working in July 2022. "
276-
f"Use '{type(self).__name__}.make_group' instead",
277-
DeprecationWarning, stacklevel=2)
278-
279-
def __getattribute__(self, name):
280-
if name in ("element_nr_base", "node_nr_base"):
281-
new_name = ("base_element_nrs"
282-
if name == "element_nr_base" else
283-
"base_node_nrs")
284-
285-
from warnings import warn
286-
warn(f"'{type(self).__name__}.{name}' is deprecated and will be "
287-
f"removed in July 2022. Use 'Mesh.{new_name}' instead",
288-
DeprecationWarning, stacklevel=2)
289-
290-
return super().__getattribute__(name)
243+
unit_nodes: np.ndarray
291244

292245
@property
293246
def dim(self):
@@ -313,21 +266,6 @@ def nelements(self):
313266
def nnodes(self):
314267
return self.nelements * self.unit_nodes.shape[-1]
315268

316-
def copy(self, **kwargs: Any) -> "MeshElementGroup":
317-
from warnings import warn
318-
warn(f"{type(self).__name__}.copy is deprecated and will be removed in "
319-
f"July 2022. {type(self).__name__} is now a dataclass, so "
320-
"standard functions such as dataclasses.replace should be used "
321-
"instead.",
322-
DeprecationWarning, stacklevel=2)
323-
324-
if "element_nr_base" not in kwargs:
325-
kwargs["element_nr_base"] = None
326-
if "node_nr_base" not in kwargs:
327-
kwargs["node_nr_base"] = None
328-
329-
return replace(self, **kwargs)
330-
331269
def __eq__(self, other):
332270
return (
333271
type(self) is type(other)
@@ -384,62 +322,10 @@ class _ModepyElementGroup(MeshElementGroup):
384322
.. attribute:: _modepy_space
385323
"""
386324

387-
# TODO: remove once `make_group` is used everywhere
388-
dim: Optional[int] = None
389-
390325
_modepy_shape_cls: ClassVar[Type[mp.Shape]] = mp.Shape
391326
_modepy_shape: mp.Shape = field(default=None, repr=False)
392327
_modepy_space: mp.FunctionSpace = field(default=None, repr=False)
393328

394-
def __post_init__(self):
395-
super().__post_init__()
396-
if self._factory_constructed:
397-
return
398-
399-
# {{{ duplicates make_group below, keep in sync
400-
401-
if self.unit_nodes is None:
402-
if self.dim is None:
403-
raise TypeError("either 'dim' or 'unit_nodes' must be provided")
404-
else:
405-
if self.dim is None:
406-
object.__setattr__(self, "dim", self.unit_nodes.shape[0])
407-
408-
if self.unit_nodes.shape[0] != self.dim:
409-
raise ValueError("'dim' does not match 'unit_nodes' dimension")
410-
411-
# dim is now usable
412-
assert self._modepy_shape_cls is not mp.Shape
413-
object.__setattr__(self, "_modepy_shape",
414-
# pylint: disable=abstract-class-instantiated
415-
self._modepy_shape_cls(self.dim))
416-
object.__setattr__(self, "_modepy_space",
417-
mp.space_for_shape(self._modepy_shape, self.order))
418-
419-
if self.unit_nodes is None:
420-
unit_nodes = mp.edge_clustered_nodes_for_space(
421-
self._modepy_space, self._modepy_shape)
422-
object.__setattr__(self, "unit_nodes", unit_nodes)
423-
424-
if self.nodes is not None:
425-
if self.unit_nodes.shape[-1] != self.nodes.shape[-1]:
426-
raise ValueError(
427-
"'nodes' has wrong number of unit nodes per element."
428-
f" expected {self.unit_nodes.shape[-1]}, "
429-
f" but got {self.nodes.shape[-1]}.")
430-
431-
if self.vertex_indices is not None:
432-
if not issubclass(self.vertex_indices.dtype.type, np.integer):
433-
raise TypeError("'vertex_indices' must be integral")
434-
435-
if self.vertex_indices.shape[-1] != self.nvertices:
436-
raise ValueError(
437-
"'vertex_indices' has wrong number of vertices per element."
438-
f" expected {self.nvertices},"
439-
f" got {self.vertex_indices.shape[-1]}")
440-
441-
# }}}
442-
443329
@property
444330
def nvertices(self):
445331
return self._modepy_shape.nvertices # pylint: disable=no-member
@@ -486,11 +372,12 @@ def make_group(cls, order: int,
486372
raise ValueError("'unit_nodes' size does not match the dimension "
487373
f"of a '{type(space).__name__}' space of order {order}")
488374

489-
return cls(order=order, vertex_indices=vertex_indices, nodes=nodes,
490-
dim=dim,
375+
return cls(order=order,
376+
vertex_indices=vertex_indices,
377+
nodes=nodes,
491378
unit_nodes=unit_nodes,
492-
_modepy_shape=shape, _modepy_space=space,
493-
_factory_constructed=True)
379+
_modepy_shape=shape,
380+
_modepy_space=space)
494381

495382
# }}}
496383

@@ -500,6 +387,7 @@ def make_group(cls, order: int,
500387
@dataclass(frozen=True, eq=False)
501388
class SimplexElementGroup(_ModepyElementGroup):
502389
r"""Inherits from :class:`MeshElementGroup`."""
390+
503391
_modepy_shape_cls: ClassVar[Type[mp.Shape]] = mp.Simplex
504392

505393
@property
@@ -511,6 +399,7 @@ def is_affine(self):
511399
@dataclass(frozen=True, eq=False)
512400
class TensorProductElementGroup(_ModepyElementGroup):
513401
r"""Inherits from :class:`MeshElementGroup`."""
402+
514403
_modepy_shape_cls: ClassVar[Type[mp.Shape]] = mp.Hypercube
515404

516405
def is_affine(self):
@@ -549,16 +438,6 @@ class NodalAdjacency:
549438
neighbors_starts: np.ndarray
550439
neighbors: np.ndarray
551440

552-
def copy(self, **kwargs: Any) -> "NodalAdjacency":
553-
from warnings import warn
554-
warn(f"{type(self).__name__}.copy is deprecated and will be removed in "
555-
f"July 2022. {type(self).__name__} is now a dataclass, so "
556-
"standard functions such as dataclasses.replace should be used "
557-
"instead.",
558-
DeprecationWarning, stacklevel=2)
559-
560-
return replace(self, **kwargs)
561-
562441
def __eq__(self, other):
563442
return (
564443
type(self) is type(other)
@@ -605,16 +484,6 @@ class FacialAdjacencyGroup:
605484

606485
igroup: int
607486

608-
def copy(self, **kwargs: Any) -> "FacialAdjacencyGroup":
609-
from warnings import warn
610-
warn(f"{type(self).__name__}.copy is deprecated and will be removed in "
611-
f"July 2022. {type(self).__name__} is now a dataclass, so "
612-
"standard functions such as dataclasses.replace should be used "
613-
"instead.",
614-
DeprecationWarning, stacklevel=2)
615-
616-
return replace(self, **kwargs)
617-
618487
def __eq__(self, other):
619488
return (
620489
type(self) is type(other)
@@ -1076,8 +945,8 @@ def __init__(self, vertices, groups, *, skip_tests=False,
1076945
assert fagrp.neighbor_faces.dtype == self.face_id_dtype
1077946
assert fagrp.neighbor_faces.shape == (nfagrp_elements,)
1078947

1079-
from meshmode.mesh.processing import \
1080-
test_volume_mesh_element_orientations
948+
from meshmode.mesh.processing import (
949+
test_volume_mesh_element_orientations)
1081950

1082951
if self.dim == self.ambient_dim and not skip_element_orientation_test:
1083952
# only for volume meshes, for now
@@ -1269,9 +1138,9 @@ def _test_node_vertex_consistency(mesh, tol):
12691138
if isinstance(mgrp, _ModepyElementGroup):
12701139
assert _test_node_vertex_consistency_resampling(mesh, igrp, tol)
12711140
else:
1272-
from warnings import warn
1273-
warn("not implemented: node-vertex consistency check for '%s'"
1274-
% type(mgrp).__name__)
1141+
warn("Not implemented: node-vertex consistency check for "
1142+
f"groups of type '{type(mgrp).__name__}'.",
1143+
stacklevel=3)
12751144

12761145
return True
12771146

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

1660-
from pytools.py_codegen import PythonCodeGenerator, Indentation
1529+
from pytools.py_codegen import Indentation, PythonCodeGenerator
16611530
cg = PythonCodeGenerator()
16621531
cg("""
16631532
# generated by meshmode.mesh.as_python

0 commit comments

Comments
 (0)