21
21
"""
22
22
23
23
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
26
27
27
28
import numpy as np
28
29
import numpy .linalg as la
32
33
33
34
from meshmode .mesh .tools import AffineMap
34
35
36
+
35
37
__doc__ = """
36
38
37
39
.. autoclass:: MeshElementGroup
@@ -117,23 +119,8 @@ class BTAG_PARTITION(BTAG_NO_BOUNDARY): # noqa: N801
117
119
118
120
.. versionadded:: 2017.1
119
121
"""
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
137
124
138
125
def __hash__ (self ):
139
126
return hash ((type (self ), self .part_id ))
@@ -251,43 +238,9 @@ class MeshElementGroup(ABC):
251
238
"""
252
239
253
240
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
257
241
vertex_indices : Optional [np .ndarray ]
258
242
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
291
244
292
245
@property
293
246
def dim (self ):
@@ -313,21 +266,6 @@ def nelements(self):
313
266
def nnodes (self ):
314
267
return self .nelements * self .unit_nodes .shape [- 1 ]
315
268
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
-
331
269
def __eq__ (self , other ):
332
270
return (
333
271
type (self ) is type (other )
@@ -384,62 +322,10 @@ class _ModepyElementGroup(MeshElementGroup):
384
322
.. attribute:: _modepy_space
385
323
"""
386
324
387
- # TODO: remove once `make_group` is used everywhere
388
- dim : Optional [int ] = None
389
-
390
325
_modepy_shape_cls : ClassVar [Type [mp .Shape ]] = mp .Shape
391
326
_modepy_shape : mp .Shape = field (default = None , repr = False )
392
327
_modepy_space : mp .FunctionSpace = field (default = None , repr = False )
393
328
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
-
443
329
@property
444
330
def nvertices (self ):
445
331
return self ._modepy_shape .nvertices # pylint: disable=no-member
@@ -486,11 +372,12 @@ def make_group(cls, order: int,
486
372
raise ValueError ("'unit_nodes' size does not match the dimension "
487
373
f"of a '{ type (space ).__name__ } ' space of order { order } " )
488
374
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 ,
491
378
unit_nodes = unit_nodes ,
492
- _modepy_shape = shape , _modepy_space = space ,
493
- _factory_constructed = True )
379
+ _modepy_shape = shape ,
380
+ _modepy_space = space )
494
381
495
382
# }}}
496
383
@@ -500,6 +387,7 @@ def make_group(cls, order: int,
500
387
@dataclass (frozen = True , eq = False )
501
388
class SimplexElementGroup (_ModepyElementGroup ):
502
389
r"""Inherits from :class:`MeshElementGroup`."""
390
+
503
391
_modepy_shape_cls : ClassVar [Type [mp .Shape ]] = mp .Simplex
504
392
505
393
@property
@@ -511,6 +399,7 @@ def is_affine(self):
511
399
@dataclass (frozen = True , eq = False )
512
400
class TensorProductElementGroup (_ModepyElementGroup ):
513
401
r"""Inherits from :class:`MeshElementGroup`."""
402
+
514
403
_modepy_shape_cls : ClassVar [Type [mp .Shape ]] = mp .Hypercube
515
404
516
405
def is_affine (self ):
@@ -549,16 +438,6 @@ class NodalAdjacency:
549
438
neighbors_starts : np .ndarray
550
439
neighbors : np .ndarray
551
440
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
-
562
441
def __eq__ (self , other ):
563
442
return (
564
443
type (self ) is type (other )
@@ -605,16 +484,6 @@ class FacialAdjacencyGroup:
605
484
606
485
igroup : int
607
486
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
-
618
487
def __eq__ (self , other ):
619
488
return (
620
489
type (self ) is type (other )
@@ -1076,8 +945,8 @@ def __init__(self, vertices, groups, *, skip_tests=False,
1076
945
assert fagrp .neighbor_faces .dtype == self .face_id_dtype
1077
946
assert fagrp .neighbor_faces .shape == (nfagrp_elements ,)
1078
947
1079
- from meshmode .mesh .processing import \
1080
- test_volume_mesh_element_orientations
948
+ from meshmode .mesh .processing import (
949
+ test_volume_mesh_element_orientations )
1081
950
1082
951
if self .dim == self .ambient_dim and not skip_element_orientation_test :
1083
952
# only for volume meshes, for now
@@ -1269,9 +1138,9 @@ def _test_node_vertex_consistency(mesh, tol):
1269
1138
if isinstance (mgrp , _ModepyElementGroup ):
1270
1139
assert _test_node_vertex_consistency_resampling (mesh , igrp , tol )
1271
1140
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 )
1275
1144
1276
1145
return True
1277
1146
@@ -1657,7 +1526,7 @@ def as_python(mesh, function_name="make_mesh"):
1657
1526
recreate the mesh given as an input parameter.
1658
1527
"""
1659
1528
1660
- from pytools .py_codegen import PythonCodeGenerator , Indentation
1529
+ from pytools .py_codegen import Indentation , PythonCodeGenerator
1661
1530
cg = PythonCodeGenerator ()
1662
1531
cg ("""
1663
1532
# generated by meshmode.mesh.as_python
0 commit comments