Skip to content
Merged
3 changes: 2 additions & 1 deletion src/ansys/dpf/core/custom_type_field.py
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@ def _init_api_env(self):
@staticmethod
def _field_create_internal_obj(
api,
client,
server,
nature,
nentities,
location=locations.nodal,
Expand All @@ -178,6 +178,7 @@ def _field_create_internal_obj(
with_type=None,
):
dpf_type_name = numpy_type_to_dpf[with_type]
client = server.client
if client is not None:
return api.cscustom_type_field_new_on_client(
client, dpf_type_name, with_type.itemsize, nentities, nentities
Expand Down
7 changes: 3 additions & 4 deletions src/ansys/dpf/core/field.py
Original file line number Diff line number Diff line change
Expand Up @@ -234,7 +234,7 @@ def _init_api_env(self):
@staticmethod
def _field_create_internal_obj(
api: field_abstract_api.FieldAbstractAPI,
client,
server,
nature,
nentities,
location=locations.nodal,
Expand All @@ -243,6 +243,7 @@ def _field_create_internal_obj(
with_type=None,
):
dim = dimensionality.Dimensionality([ncomp_n, ncomp_m], nature)
client = server.client

if dim.is_1d_dim():
if client is not None:
Expand Down Expand Up @@ -659,9 +660,7 @@ def unit(self, value: str | tuple[Homogeneity, str]):
Setting a named dimensionless unit requires DPF 11.0 (2026 R1) or above.

"""
field_def = self.field_definition
field_def.unit = value
self.field_definition = field_def
self.field_definition.unit = value

@property
def dimensionality(self):
Expand Down
4 changes: 2 additions & 2 deletions src/ansys/dpf/core/field_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ def __init__(
else:
self._internal_obj = self.__class__._field_create_internal_obj(
self._api,
client=self._server.client,
server=self._server,
nature=nature,
nentities=nentities,
location=location,
Expand All @@ -97,7 +97,7 @@ def _api(self):
@abstractmethod
def _field_create_internal_obj(
api: field_abstract_api.FieldAbstractAPI,
client,
server,
nature,
nentities,
location=locations.nodal,
Expand Down
2 changes: 1 addition & 1 deletion src/ansys/dpf/core/fields_factory.py
Original file line number Diff line number Diff line change
Expand Up @@ -393,7 +393,7 @@ def _create_field(
api.init_field_environment(server)
internal_obj = Field._field_create_internal_obj(
api=api,
client=server.client,
server=server,
nature=nature,
nentities=n_entities,
location=str(location),
Expand Down
60 changes: 43 additions & 17 deletions src/ansys/dpf/core/property_field.py
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ def _init_api_env(self):
@staticmethod
def _field_create_internal_obj(
api: property_field_abstract_api.PropertyFieldAbstractAPI,
client,
server,
nature,
nentities,
location=locations.nodal,
Expand All @@ -123,12 +123,23 @@ def _field_create_internal_obj(
with_type=None,
):
dim = dimensionality.Dimensionality([ncomp_n, ncomp_m], nature)
if client is not None:
return api.csproperty_field_new_on_client(
client, nentities, nentities * dim.component_count
)
client = server.client
if meets_version(server.version, "11.0"):
if client is not None:
return api.csproperty_field_new_location_on_client(
client, nentities, nentities * dim.component_count, location
)
else:
return api.csproperty_field_new_location(
nentities, nentities * dim.component_count, location
)
else:
return api.csproperty_field_new(nentities, nentities * dim.component_count)
if client is not None:
return api.csproperty_field_new_on_client(
client, nentities, nentities * dim.component_count
)
else:
return api.csproperty_field_new(nentities, nentities * dim.component_count)

@version_requires("8.1")
def _load_field_definition(self):
Expand All @@ -141,8 +152,8 @@ def _load_field_definition(self):
def location(self):
"""Location of the property field.

A property field contains a scoping, which is the location that is read.
To update location, directly update the scoping location.
The property field location is the one contained in its field definition.
To update location, just update the property field location.

Returns
-------
Expand All @@ -156,16 +167,18 @@ def location(self):

>>> from ansys.dpf import core as dpf
>>> pfield = dpf.PropertyField()
>>> list_ids = [1, 2, 4, 6, 7]
>>> scop = dpf.Scoping(ids = list_ids, location = dpf.locations.nodal)
>>> pfield.scoping = scop
>>> pfield.scoping.location = dpf.locations.nodal
>>> pfield.location = dpf.locations.nodal
>>> pfield.location
'Nodal'

"""
location = self.scoping.location
return location if location else None
if meets_version(self._server.version, "11.0"):
if self._field_definition:
return self._field_definition.location
elif self.scoping:
return self.scoping.location
else:
return None

@location.setter
def location(self, value):
Expand All @@ -181,14 +194,27 @@ def location(self, value):
--------
>>> from ansys.dpf import core as dpf
>>> pfield = dpf.PropertyField()
>>> scop = dpf.Scoping(ids = list_ids, location = dpf.locations.nodal)
>>> pfield.scoping = scop
>>> list_ids = [1, 2, 4, 6, 7]
>>> pfield.location = 'Nodal'
>>> pfield.location
'Nodal'

"""
self.scoping.location = value
if meets_version(self._server.version, "11.0"):
if self._field_definition:
self._field_definition.location = value
return
else:
raise Exception(
"Property field location is based on field definition, and field definition is not defined"
)
elif self.scoping:
self.scoping.location = value
return
else:
raise Exception(
"Property field location before is based on scoping, and scoping is not defined"
)

@property
def component_count(self):
Expand Down
3 changes: 2 additions & 1 deletion src/ansys/dpf/core/string_field.py
Original file line number Diff line number Diff line change
Expand Up @@ -103,14 +103,15 @@ def _init_api_env(self):
@staticmethod
def _field_create_internal_obj(
api: string_field_abstract_api.StringFieldAbstractAPI,
client,
server,
nature,
nentities,
location=locations.nodal,
ncomp_n=0,
ncomp_m=0,
with_type=None,
):
client = server.client
if client is not None:
return api.csstring_field_new_on_client(client, nentities, nentities)
else:
Expand Down
10 changes: 10 additions & 0 deletions src/ansys/dpf/gate/property_field_grpcapi.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,16 @@ def csproperty_field_new_on_client(client, numEntities, data_size):
request.datatype = "int"
return field_grpcapi._get_stub(client).Create(request)

@staticmethod
def csproperty_field_new_location_on_client(client, numEntities, data_size, location):
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why did we need a new API here, couldn't we do field_def_new and then set_location?

from ansys.grpc.dpf import field_pb2
request = field_pb2.FieldRequest()
request.size.scoping_size = numEntities
request.size.data_size = data_size
request.location.location = location
request.datatype = "int"
return field_grpcapi._get_stub(client).Create(request)

@staticmethod
def csproperty_field_get_number_elementary_data(field):
return api_to_call.csfield_get_number_elementary_data(field)
Expand Down
Loading