Skip to content

Commit 59f6708

Browse files
Accept a Python range when setting scoping IDs. (#2001)
* Add AnyServerType type for typehint. * Refactor scoping.py to improve typehint and allow range as input for ids. * Refactor mesh_scoping_factory.py to improve typehint and docstrings. * Remove duplicate treatment of range * Add coverage for range * Apply suggestions from code review Co-authored-by: JennaPaikowsky <[email protected]> * Fix mesh_scoping_factory.py/named_selection_scoping. Requires a dedicated PR to properly use the server argument. * Update src/ansys/dpf/core/scoping.py * Update Scoping docstring example with time_freq scoping. * Remove TODOs * Properly expose the possibility to get the list of IDs in a scoping as a Python list. * Update testing --------- Co-authored-by: JennaPaikowsky <[email protected]>
1 parent 30bec39 commit 59f6708

File tree

3 files changed

+157
-83
lines changed

3 files changed

+157
-83
lines changed

src/ansys/dpf/core/mesh_scoping_factory.py

Lines changed: 41 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -23,87 +23,101 @@
2323
"""
2424
mesh_scoping_factory.
2525
26-
Contains functions to simplify creating mesh scopings.
26+
Contains functions to simplify creating a mesh scoping.
2727
"""
2828

29+
from __future__ import annotations
30+
31+
from typing import TYPE_CHECKING
32+
33+
if TYPE_CHECKING: # pragma: nocover
34+
from ansys.dpf.core.server_types import AnyServerType
35+
from ansys.dpf.core.scoping import IdVectorType
36+
from ansys.dpf.core.model import Model
37+
2938
from ansys.dpf.core import Scoping
3039
from ansys.dpf.core.common import locations
3140

3241

33-
def nodal_scoping(node_ids, server=None):
34-
"""Create a specific nodal :class:`ansys.dpf.core.Scoping` associated with a mesh.
42+
def nodal_scoping(node_ids: IdVectorType, server: AnyServerType = None) -> Scoping:
43+
"""Create a nodal :class:`ansys.dpf.core.Scoping` defining a list of node IDs.
3544
3645
Parameters
3746
----------
38-
node_ids : list[int]
39-
List of IDs for the nodes.
40-
server : DpfServer, optional
47+
node_ids:
48+
List of node IDs.
49+
server:
4150
Server with the channel connected to the remote or local instance.
4251
The default is ``None``, in which case an attempt is made to use the
4352
global server.
4453
4554
Returns
4655
-------
47-
scoping : Scoping
56+
scoping:
57+
A nodal scoping containing the node IDs provided.
4858
"""
4959
scoping = Scoping(server=server, ids=node_ids, location=locations.nodal)
5060
return scoping
5161

5262

53-
def elemental_scoping(element_ids, server=None):
54-
"""Create a specific elemental :class:`ansys.dpf.core.Scoping` associated with a mesh.
63+
def elemental_scoping(element_ids: IdVectorType, server: AnyServerType = None) -> Scoping:
64+
"""Create an elemental :class:`ansys.dpf.core.Scoping` defining a list of element IDs.
5565
5666
Parameters
5767
----------
58-
element_ids : list[int]
59-
List of IDs for the elements.
60-
server : DpfServer, optional
68+
element_ids:
69+
List of element IDs.
70+
server:
6171
Server with the channel connected to the remote or local instance.
6272
The default is ``None``, in which case an attempt is made to use the
6373
global server.
6474
6575
Returns
6676
-------
67-
scoping : Scoping
77+
scoping:
78+
An elemental scoping containing the element IDs provided.
6879
"""
6980
scoping = Scoping(server=server, ids=element_ids, location=locations.elemental)
7081
return scoping
7182

7283

73-
def face_scoping(face_ids, server=None):
74-
"""Create a specific face :class:`ansys.dpf.core.Scoping` associated with a mesh.
84+
def face_scoping(face_ids: IdVectorType, server: AnyServerType = None) -> Scoping:
85+
"""Create a face :class:`ansys.dpf.core.Scoping`defining a list of face IDs.
7586
7687
Parameters
7788
----------
78-
face_ids : list[int]
79-
List of IDs for the faces.
80-
server : DpfServer, optional
89+
face_ids:
90+
List of face IDs.
91+
server:
8192
Server with the channel connected to the remote or local instance.
8293
The default is ``None``, in which case an attempt is made to use the
8394
global server.
8495
8596
Returns
8697
-------
87-
scoping : Scoping
98+
scoping:
99+
A face scoping containing the face IDs provided.
88100
"""
89101
scoping = Scoping(server=server, ids=face_ids, location=locations.faces)
90102
return scoping
91103

92104

93-
def named_selection_scoping(named_selection_name, model, server=None):
94-
"""Create a specific :class:`ansys.dpf.core.Scoping` associated with a specified model's mesh.
105+
def named_selection_scoping(
106+
named_selection_name: str, model: Model, server: AnyServerType = None
107+
) -> Scoping:
108+
"""Create a :class:`ansys.dpf.core.Scoping` based on a named selection in a model.
95109
96110
Parameters
97111
----------
98-
named_selection_name : str
112+
named_selection_name:
99113
Name of the named selection.
100-
server : DpfServer, optional
101-
Server with the channel connected to the remote or local instance.
102-
The default is ``None``, in which case an attempt is made to use the
103-
global server.
114+
model:
115+
Model where the named selection exists.
104116
105117
Returns
106118
-------
107-
scoping : Scoping
119+
scoping:
120+
A scoping containing the IDs of the entities in the named selection.
121+
The location depends on the type of entities targeted by the named selection.
108122
"""
109123
return model.metadata.named_selection(named_selection_name)

0 commit comments

Comments
 (0)