Skip to content

Commit

Permalink
Handle the server argument for mesh_scoping_factory.py/named_selectio…
Browse files Browse the repository at this point in the history
…n_scoping.
  • Loading branch information
PProfizi committed Jan 10, 2025
1 parent 52ed660 commit c002175
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 13 deletions.
2 changes: 1 addition & 1 deletion src/ansys/dpf/core/mesh_scoping_factory.py
Original file line number Diff line number Diff line change
Expand Up @@ -106,4 +106,4 @@ def named_selection_scoping(named_selection_name, model, server=None):
-------
scoping : Scoping
"""
return model.metadata.named_selection(named_selection_name)
return model.metadata.named_selection(named_selection=named_selection_name, server=server)
33 changes: 26 additions & 7 deletions src/ansys/dpf/core/meshed_region.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,14 @@

"""MeshedRegion."""

from __future__ import annotations

from typing import TYPE_CHECKING

if TYPE_CHECKING: # pragma: nocover
from ansys.dpf.core.server_types import AnyServerType
from ansys.dpf.core.scoping import Scoping

import traceback
import warnings

Expand Down Expand Up @@ -378,36 +386,47 @@ def _get_available_named_selections(self):
named_selections.append(self._api.meshed_region_get_named_selection_name(self, index))
return named_selections

def named_selection(self, named_selection):
"""
Scoping containing the list of nodes or elements in the named selection.
def named_selection(
self,
named_selection: str,
server: AnyServerType = None,
) -> Scoping:
"""Scoping containing the list of nodes or elements in the named selection.
Parameters
----------
named_selection : str
named_selection:
Name of the named selection.
server:
Server on which to create the scoping if different from the server of the model.
Returns
-------
named_selection : Scoping
named_selection:
A scoping containing the IDs of the entities in the named selection.
The location depends on the type of entities targeted by the named selection.
"""
out_scoping = None
if server_meet_version("2.1", self._server):
out = self._api.meshed_region_get_named_selection_scoping(self, named_selection)
return scoping.Scoping(scoping=out, server=self._server)
out_scoping = scoping.Scoping(scoping=out, server=server)
else:
if hasattr(self, "_stream_provider"):
from ansys.dpf.core.dpf_operator import Operator

op = Operator("scoping_provider_by_ns", server=self._server)
op.connect(1, named_selection)
op.connect(3, self._stream_provider, 0)
return op.get_output(0, types.scoping)
out_scoping = op.get_output(0, types.scoping)
else:
raise Exception(
"Getting a named selection from a meshed region is "
"only implemented for meshed region created from a "
"model for server version 2.0. Please update your server."
)
if server:
# Copy the scoping to another server
out_scoping.deep_copy(server=server)

@version_requires("3.0")
def set_named_selection_scoping(self, named_selection_name, scoping):
Expand Down
22 changes: 17 additions & 5 deletions src/ansys/dpf/core/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,14 @@
"""

from __future__ import annotations

from typing import TYPE_CHECKING

if TYPE_CHECKING: # pragma: nocover
from ansys.dpf.core.server_types import AnyServerType
from ansys.dpf.core.scoping import Scoping

from ansys import dpf
from ansys.dpf.core import Operator
from ansys.dpf.core.common import types
Expand Down Expand Up @@ -587,19 +595,23 @@ def available_named_selections(self):
"""
return self.meshed_region.available_named_selections

def named_selection(self, named_selection):
def named_selection(self, named_selection: str, server: AnyServerType = None) -> Scoping:
"""Scoping containing the list of nodes or elements in the named selection.
Parameters
----------
named_selection : str
name of the named selection
named_selection:
Name of the named selection.
server:
Server on which to create the scoping if different from the server of the model.
Returns
-------
named_selection : :class:`ansys.dpf.core.scoping.Scoping`
named_selection:
A scoping containing the IDs of the entities in the named selection.
The location depends on the type of entities targeted by the named selection.
"""
return self.meshed_region.named_selection(named_selection)
return self.meshed_region.named_selection(named_selection=named_selection, server=server)

def _build_connector(self):
return DataSourcesOrStreamsConnector(self)

0 comments on commit c002175

Please sign in to comment.