ansys.dpf.core.Scoping#

class ansys.dpf.core.Scoping(scoping: ansys.grpc.dpf.scoping_pb2.Scoping | ctypes.c_void_p = None, server: ansys.dpf.core.server_types.AnyServerType = None, ids: IdVectorType = None, location: ansys.dpf.core.common.locations = None)#

Represents a scoping, which is a subset of a model support.

Parameters:
  • scoping – gRPC message or pointer for an existing scoping on the server.

  • server – Server with channel connected to the remote or local instance. The default is None, in which case an attempt is made to use the global server.

  • ids – List of entity IDs.

  • location – Location for this scoping. Defines the type of entities the IDs correspond to. For example, if location is locations.nodal, then the scoping is a list of node IDs.

Examples

Create a scoping for mesh entities.

>>> from ansys.dpf import core as dpf
>>> # 1. using the mesh_scoping_factory
>>> from ansys.dpf.core import mesh_scoping_factory
>>> # a. scoping with elemental location that targets the elements with id 2, 7 and 11
>>> my_elemental_scoping = mesh_scoping_factory.elemental_scoping([2, 7, 11])
>>> # b. scoping with nodal location that targets the elements with id 4 to 6
>>> my_nodal_scoping = mesh_scoping_factory.nodal_scoping(range(4, 7))
>>> #2. using the Scoping class directly
>>> # a. scoping with elemental location that targets the elements with id 2, 7 and 11
>>> my_elemental_scoping = dpf.Scoping(location=dpf.locations.elemental, ids=[2, 7, 11])
>>> # b. scoping with nodal  location that targets the elements with id 4 to 6
>>> my_nodal_scoping = dpf.Scoping(ids=range(4, 7))
>>> # 3. create a time_freq scoping that targets the second load step
>>> from ansys.dpf.core import time_freq_scoping_factory
>>> # a. using the time_freq_scoping_factory
>>> my_load_step_scoping = time_freq_scoping_factory.scoping_by_load_step(2)
>>> # b. using the Scoping class directly
>>> my_load_step_scoping = dpf.Scoping(location=dpf.locations.time_freq_step, ids=[2])
_server#
_api#
_count()#

Return the number of scoping ids.

Returns:

count – Number of scoping IDs.

Return type:

int

_get_location()#

Retrieve the location of the IDs.

Returns:

location – Location of the IDs.

Return type:

str

_set_location(loc=locations.nodal)#

Set the location.

Parameters:

loc (str or core.locations enum) – Location needed.

_set_ids(ids: IdVectorType)#

Set the ids.

Scoping IDs are stored as int32. Converts automatically int64 Numpy arrays to int32.

Parameters:

ids – Entity IDs to set.

_get_ids(np_array=None)#

Return an array of scoping ids.

Returns:

  • ids (list[int], numpy.array (if np_array==True)) – Array of IDs.

  • np_array (bool, optional)

Notes

Print a progress bar.

get_ids(np_array: bool = False) list[int] | ansys.dpf.gate.dpf_array.DPFArray#

Return the list of entity IDs in the scoping as a list or as a numpy.ndarray.

Parameters:

np_array – Whether to return the list of IDs as a numpy array.

Returns:

List of entity IDs in the scoping.

Return type:

ids

set_id(index: int, scopingid: int)#

Set the ID of the entity at index in the scoping.

Parameters:
  • index – Index in the scoping.

  • scopingid – ID of the entity.

_get_id(index)#

Retrieve the index that the scoping ID is located on.

Parameters:

index (int) – Index of the scoping

Returns:

id – ID of the scoping’s index.

Return type:

int

_get_index(scopingid)#

Retrieve an ID corresponding to an ID in the scoping.

Parameters:

id (int) – ID to retrieve.

Returns:

index – Index of the ID.

Return type:

int

id(index: int) int#

Retrieve the entity ID at a given index.

Parameters:

index – Index of the entity in the scoping.

Returns:

ID of the entity at index in the scoping.

Return type:

entity_id

index(id: int) int#

Retrieve the index for a given entity ID.

Parameters:

id – Entity ID at the index in the scoping.

Returns:

Index in the scoping for the entity ID.

Return type:

index

property ids: ansys.dpf.gate.dpf_array.DPFArray | list[int]#

Retrieve the entity IDs in the scoping.

Returns:

List of IDs in the scoping. By default, a mutable DPFArray is returned. To change the return type to a list for the complete python session, see ansys.dpf.core.settings.get_runtime_client_config() and ansys.dpf.core.runtime_config.RuntimeClientConfig.return_arrays(). To get the list of IDs from a scoping as a Python list without changing a default configuration, use ansys.dpf.core.scoping.Scoping.get_ids() instead.

Return type:

ids

property location: str#

Location of the scoping as a string.

This defines the type of entity the IDs correspond to (such as node ID, element ID, face ID, and so on).

Returns:

The location of the scoping. One of the values of locations.

Return type:

location

__len__()#

Return the number of scoping ids.

Returns:

The number of scoping ids.

Return type:

int

__del__()#

Clean up resources associated with the instance.

This method calls the deleter function to release resources. If an exception occurs during deletion, a warning is issued.

Raises:

Warning – If an exception occurs while attempting to delete resources.

__iter__()#

Return an iterator over the scoping ids.

__getitem__(key)#

Retrieve the ID at a requested index.

__setitem__(index, id)#

Set the ID at a given index.

property size: int#

Length of the list of IDs.

Returns:

Size of the scoping.

Return type:

size

__str__()#

Describe the entity.

Returns:

description

Return type:

str

deep_copy(server=None)#

Create a deep copy of the scoping’s data on a given server.

This method is useful for passiong data from one server instance to another.

Parameters:

server (ansys.dpf.core.server, optional) – Server with the channel connected to the remote or local instance. The default is None, in which case an attempt is made to use the global server.

Returns:

scoping_copy

Return type:

Scoping

as_local_scoping()#

Create a deep copy of the scoping that can be accessed and modified locally.

This method allows you to access and modify the local copy of the scoping without sending a request to the server. It should be used in a with statement so that the local field is released and the data is sent to the server in one action. If it is not used in a with statement, Scoping.release_data() should be used to update the scoping.

Warning

If this as_local_scoping method is not used as a context manager in a with statement or if the method release_data() is not called, the data will not be updated.

Returns:

local_scoping

Return type:

Scoping

Examples

>>> from ansys.dpf import core as dpf
>>> num_entities = 3
>>> scoping_to_local = dpf.Scoping()
>>> with scoping_to_local.as_local_scoping() as scoping:
...     for i in range(0,num_entities):
...         scoping[i] = i+1