Skip to content

Commit a175c71

Browse files
authored
Support PropertyField location after server changes (#2322)
Co-authored-by: PProfizi <[email protected]> Co-authored-by: Rafael Canton <[email protected]> Co-authored-by: Josip Vidal <[email protected]> Correcting changes related to the DPF PR "https://tfs.ansys.com:8443/tfs/ANSYS_Development/DPF/_git/DPF/pullrequest/590070?_a=files" We are now relying to the location of the property field, instead of the one of the scoping. Fixing issues with retro compatibility and examples
1 parent 6f4dac3 commit a175c71

File tree

7 files changed

+63
-26
lines changed

7 files changed

+63
-26
lines changed

src/ansys/dpf/core/custom_type_field.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -169,7 +169,7 @@ def _init_api_env(self):
169169
@staticmethod
170170
def _field_create_internal_obj(
171171
api,
172-
client,
172+
server,
173173
nature,
174174
nentities,
175175
location=locations.nodal,
@@ -178,6 +178,7 @@ def _field_create_internal_obj(
178178
with_type=None,
179179
):
180180
dpf_type_name = numpy_type_to_dpf[with_type]
181+
client = server.client
181182
if client is not None:
182183
return api.cscustom_type_field_new_on_client(
183184
client, dpf_type_name, with_type.itemsize, nentities, nentities

src/ansys/dpf/core/field.py

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -234,7 +234,7 @@ def _init_api_env(self):
234234
@staticmethod
235235
def _field_create_internal_obj(
236236
api: field_abstract_api.FieldAbstractAPI,
237-
client,
237+
server,
238238
nature,
239239
nentities,
240240
location=locations.nodal,
@@ -243,6 +243,7 @@ def _field_create_internal_obj(
243243
with_type=None,
244244
):
245245
dim = dimensionality.Dimensionality([ncomp_n, ncomp_m], nature)
246+
client = server.client
246247

247248
if dim.is_1d_dim():
248249
if client is not None:
@@ -659,9 +660,7 @@ def unit(self, value: str | tuple[Homogeneity, str]):
659660
Setting a named dimensionless unit requires DPF 11.0 (2026 R1) or above.
660661
661662
"""
662-
field_def = self.field_definition
663-
field_def.unit = value
664-
self.field_definition = field_def
663+
self.field_definition.unit = value
665664

666665
@property
667666
def dimensionality(self):

src/ansys/dpf/core/field_base.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ def __init__(
7777
else:
7878
self._internal_obj = self.__class__._field_create_internal_obj(
7979
self._api,
80-
client=self._server.client,
80+
server=self._server,
8181
nature=nature,
8282
nentities=nentities,
8383
location=location,
@@ -97,7 +97,7 @@ def _api(self):
9797
@abstractmethod
9898
def _field_create_internal_obj(
9999
api: field_abstract_api.FieldAbstractAPI,
100-
client,
100+
server,
101101
nature,
102102
nentities,
103103
location=locations.nodal,

src/ansys/dpf/core/fields_factory.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -393,7 +393,7 @@ def _create_field(
393393
api.init_field_environment(server)
394394
internal_obj = Field._field_create_internal_obj(
395395
api=api,
396-
client=server.client,
396+
server=server,
397397
nature=nature,
398398
nentities=n_entities,
399399
location=str(location),

src/ansys/dpf/core/property_field.py

Lines changed: 43 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ def _init_api_env(self):
114114
@staticmethod
115115
def _field_create_internal_obj(
116116
api: property_field_abstract_api.PropertyFieldAbstractAPI,
117-
client,
117+
server,
118118
nature,
119119
nentities,
120120
location=locations.nodal,
@@ -123,12 +123,23 @@ def _field_create_internal_obj(
123123
with_type=None,
124124
):
125125
dim = dimensionality.Dimensionality([ncomp_n, ncomp_m], nature)
126-
if client is not None:
127-
return api.csproperty_field_new_on_client(
128-
client, nentities, nentities * dim.component_count
129-
)
126+
client = server.client
127+
if meets_version(server.version, "11.0"):
128+
if client is not None:
129+
return api.csproperty_field_new_location_on_client(
130+
client, nentities, nentities * dim.component_count, location
131+
)
132+
else:
133+
return api.csproperty_field_new_location(
134+
nentities, nentities * dim.component_count, location
135+
)
130136
else:
131-
return api.csproperty_field_new(nentities, nentities * dim.component_count)
137+
if client is not None:
138+
return api.csproperty_field_new_on_client(
139+
client, nentities, nentities * dim.component_count
140+
)
141+
else:
142+
return api.csproperty_field_new(nentities, nentities * dim.component_count)
132143

133144
@version_requires("8.1")
134145
def _load_field_definition(self):
@@ -141,8 +152,8 @@ def _load_field_definition(self):
141152
def location(self):
142153
"""Location of the property field.
143154
144-
A property field contains a scoping, which is the location that is read.
145-
To update location, directly update the scoping location.
155+
The property field location is the one contained in its field definition.
156+
To update location, just update the property field location.
146157
147158
Returns
148159
-------
@@ -156,16 +167,18 @@ def location(self):
156167
157168
>>> from ansys.dpf import core as dpf
158169
>>> pfield = dpf.PropertyField()
159-
>>> list_ids = [1, 2, 4, 6, 7]
160-
>>> scop = dpf.Scoping(ids = list_ids, location = dpf.locations.nodal)
161-
>>> pfield.scoping = scop
162-
>>> pfield.scoping.location = dpf.locations.nodal
170+
>>> pfield.location = dpf.locations.nodal
163171
>>> pfield.location
164172
'Nodal'
165173
166174
"""
167-
location = self.scoping.location
168-
return location if location else None
175+
if meets_version(self._server.version, "11.0"):
176+
if self._field_definition:
177+
return self._field_definition.location
178+
elif self.scoping:
179+
return self.scoping.location
180+
else:
181+
return None
169182

170183
@location.setter
171184
def location(self, value):
@@ -181,14 +194,27 @@ def location(self, value):
181194
--------
182195
>>> from ansys.dpf import core as dpf
183196
>>> pfield = dpf.PropertyField()
184-
>>> scop = dpf.Scoping(ids = list_ids, location = dpf.locations.nodal)
185-
>>> pfield.scoping = scop
197+
>>> list_ids = [1, 2, 4, 6, 7]
186198
>>> pfield.location = 'Nodal'
187199
>>> pfield.location
188200
'Nodal'
189201
190202
"""
191-
self.scoping.location = value
203+
if meets_version(self._server.version, "11.0"):
204+
if self._field_definition:
205+
self._field_definition.location = value
206+
return
207+
else:
208+
raise Exception(
209+
"Property field location is based on field definition, and field definition is not defined"
210+
)
211+
elif self.scoping:
212+
self.scoping.location = value
213+
return
214+
else:
215+
raise Exception(
216+
"Property field location before is based on scoping, and scoping is not defined"
217+
)
192218

193219
@property
194220
def component_count(self):

src/ansys/dpf/core/string_field.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,14 +103,15 @@ def _init_api_env(self):
103103
@staticmethod
104104
def _field_create_internal_obj(
105105
api: string_field_abstract_api.StringFieldAbstractAPI,
106-
client,
106+
server,
107107
nature,
108108
nentities,
109109
location=locations.nodal,
110110
ncomp_n=0,
111111
ncomp_m=0,
112112
with_type=None,
113113
):
114+
client = server.client
114115
if client is not None:
115116
return api.csstring_field_new_on_client(client, nentities, nentities)
116117
else:

src/ansys/dpf/gate/property_field_grpcapi.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,16 @@ def csproperty_field_new_on_client(client, numEntities, data_size):
2424
request.datatype = "int"
2525
return field_grpcapi._get_stub(client).Create(request)
2626

27+
@staticmethod
28+
def csproperty_field_new_location_on_client(client, numEntities, data_size, location):
29+
from ansys.grpc.dpf import field_pb2
30+
request = field_pb2.FieldRequest()
31+
request.size.scoping_size = numEntities
32+
request.size.data_size = data_size
33+
request.location.location = location
34+
request.datatype = "int"
35+
return field_grpcapi._get_stub(client).Create(request)
36+
2737
@staticmethod
2838
def csproperty_field_get_number_elementary_data(field):
2939
return api_to_call.csfield_get_number_elementary_data(field)

0 commit comments

Comments
 (0)