Skip to content

Commit f00e62a

Browse files
oparrenoPProfizi
andauthored
Add CyclicSupport.cs, CyclicSupport.high_low_map & CyclicSupport.low_high_map (#1875)
* enable methods in pyDPF * spelling * modifs from review * adding to existing test new apis * styling * fix example * naming error * only activate tests from 24R2 * import conftest and styling * update version * add server type * rollback * Use skipif instead of server failure Signed-off-by: paul.profizi <[email protected]> * Use skipif instead of server failure Signed-off-by: paul.profizi <[email protected]> --------- Signed-off-by: paul.profizi <[email protected]> Co-authored-by: paul.profizi <[email protected]>
1 parent 104b0b2 commit f00e62a

File tree

3 files changed

+126
-0
lines changed

3 files changed

+126
-0
lines changed

src/ansys/dpf/core/cyclic_support.py

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232

3333
from ansys.dpf.core import server as server_module
3434
from ansys.dpf.core.scoping import Scoping
35+
from ansys.dpf.core import field, property_field
3536

3637

3738
class CyclicSupport:
@@ -304,6 +305,74 @@ def expand_element_id(self, element_id, sectors=None, stage_num=0):
304305
)
305306
return Scoping(scoping=expanded_ids, server=self._server)
306307

308+
def cs(self) -> field.Field:
309+
"""Coordinate system of the cyclic support.
310+
311+
Examples
312+
--------
313+
>>> from ansys.dpf.core import Model
314+
>>> from ansys.dpf.core import examples
315+
>>> multi_stage = examples.download_multi_stage_cyclic_result()
316+
>>> cyc_support = Model(multi_stage).metadata.result_info.cyclic_support
317+
>>> cs = cyc_support.cs()
318+
319+
"""
320+
321+
cs = self._api.cyclic_support_get_cs(self)
322+
return field.Field(field=cs, server=self._server)
323+
324+
def low_high_map(self, stage_num: int = 0) -> property_field.PropertyField:
325+
"""Retrieve a property field containing node map from low to high
326+
base sector of the given stage.
327+
328+
Parameters
329+
----------
330+
stage_num:
331+
Number of the stage required (from 0 to num_stages).
332+
333+
Returns
334+
-------
335+
low_high_map:
336+
Node correspondence between low to high in the base sector of the given stage.
337+
338+
Examples
339+
--------
340+
>>> from ansys.dpf.core import Model
341+
>>> from ansys.dpf.core import examples
342+
>>> multi_stage = examples.download_multi_stage_cyclic_result()
343+
>>> cyc_support = Model(multi_stage).metadata.result_info.cyclic_support
344+
>>> low_high_map = cyc_support.low_high_map(0)
345+
346+
"""
347+
low_high_map = self._api.cyclic_support_get_low_high_map(self, stage_num)
348+
return property_field.PropertyField(property_field=low_high_map, server=self._server)
349+
350+
def high_low_map(self, stage_num: int = 0) -> property_field.PropertyField:
351+
"""Retrieve a property field containing node map from high to low
352+
base sector of the given stage.
353+
354+
Parameters
355+
----------
356+
stage_num:
357+
Number of the stage required (from 0 to num_stages).
358+
359+
Returns
360+
-------
361+
low_high_map:
362+
Node correspondence between high to low in the base sector of the given stage.
363+
364+
Examples
365+
--------
366+
>>> from ansys.dpf.core import Model
367+
>>> from ansys.dpf.core import examples
368+
>>> multi_stage = examples.download_multi_stage_cyclic_result()
369+
>>> cyc_support = Model(multi_stage).metadata.result_info.cyclic_support
370+
>>> high_low_map = cyc_support.high_low_map(0)
371+
372+
"""
373+
high_low_map = self._api.cyclic_support_get_high_low_map(self, stage_num)
374+
return property_field.PropertyField(property_field=high_low_map, server=self._server)
375+
307376
def __del__(self):
308377
try:
309378
self._deleter_func[0](self._deleter_func[1](self))

src/ansys/dpf/gate/cyclic_support_grpcapi.py

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,16 @@ def cyclic_support_get_base_elements_scoping(support, i_stage):
7575
return getattr(CyclicSupportGRPCAPI.list(support),
7676
"base_elements_scoping_"+str(i_stage)).get_ownership()
7777

78+
@staticmethod
79+
def cyclic_support_get_low_high_map(support, i_stage):
80+
return getattr(CyclicSupportGRPCAPI.list(support),
81+
"low_high_map_"+str(i_stage)).get_ownership()
82+
83+
@staticmethod
84+
def cyclic_support_get_high_low_map(support, i_stage):
85+
return getattr(CyclicSupportGRPCAPI.list(support),
86+
"high_low_map_"+str(i_stage)).get_ownership()
87+
7888
@staticmethod
7989
def get_expanded_ids(support, request):
8090
return _get_stub(support._server).GetExpandedIds(request).expanded_ids
@@ -100,3 +110,19 @@ def cyclic_support_get_expanded_element_ids(support, baseElementId, i_stage, sec
100110
request = CyclicSupportGRPCAPI.init_get_expanded_ids(support, i_stage, sectorsScoping)
101111
request.element_id = baseElementId
102112
return CyclicSupportGRPCAPI.get_expanded_ids(support, request)
113+
114+
@staticmethod
115+
def get_cs(support, request):
116+
return _get_stub(support._server).GetCS(request).cs
117+
118+
@staticmethod
119+
def init_get_cs(support):
120+
from ansys.grpc.dpf import cyclic_support_pb2
121+
request = cyclic_support_pb2.GetCSRequest()
122+
request.support.CopyFrom(support._internal_obj)
123+
return request
124+
125+
@staticmethod
126+
def cyclic_support_get_cs(support):
127+
request = CyclicSupportGRPCAPI.init_get_cs(support)
128+
return CyclicSupportGRPCAPI.get_cs(support, request)

tests/test_cyclic_support.py

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
import weakref
2525
import numpy as np
2626

27+
import conftest
2728
import pytest
2829

2930
from ansys import dpf
@@ -171,6 +172,18 @@ def test_cyc_support_from_to_workflow(cyclic_lin_rst, server_type):
171172
assert len(exp.base_nodes_scoping().ids) == 32
172173

173174

175+
@pytest.mark.skipif(
176+
not conftest.SERVERS_VERSION_GREATER_THAN_OR_EQUAL_TO_8_2, reason="Requires DPF 8.2 or above."
177+
)
178+
def test_cyc_support_coordinate_system(cyclic_lin_rst):
179+
data_sources = dpf.DataSources(cyclic_lin_rst)
180+
model = dpf.Model(data_sources)
181+
result_info = model.metadata.result_info
182+
cyc_support = result_info.cyclic_support
183+
exp = cyc_support.cs().scoping
184+
assert np.allclose(exp.ids, [12])
185+
186+
174187
def test_cyc_support_multistage(cyclic_multistage):
175188
model = dpf.Model(cyclic_multistage)
176189
cyc_support = model.metadata.result_info.cyclic_support
@@ -185,6 +198,24 @@ def test_cyc_support_multistage(cyclic_multistage):
185198
assert np.allclose(cyc_support.sectors_set_for_expansion(stage_num=1).ids, list(range(0, 12)))
186199

187200

201+
@pytest.mark.skipif(
202+
not conftest.SERVERS_VERSION_GREATER_THAN_OR_EQUAL_TO_8_2, reason="Requires DPF 8.2 or above."
203+
)
204+
def test_cyc_support_multistage_low_high_map(cyclic_multistage):
205+
model = dpf.Model(cyclic_multistage)
206+
cyc_support = model.metadata.result_info.cyclic_support
207+
208+
high_low_map = cyc_support.high_low_map(0)
209+
assert np.allclose(high_low_map.get_entity_data_by_id(1446), 1447)
210+
assert np.allclose(high_low_map.get_entity_data_by_id(2946), 2948)
211+
assert np.allclose(high_low_map.get_entity_data_by_id(1452), 1466)
212+
213+
low_high_map = cyc_support.low_high_map(1)
214+
assert np.allclose(low_high_map.get_entity_data_by_id(995), 939)
215+
assert np.allclose(low_high_map.get_entity_data_by_id(53), 54)
216+
assert np.allclose(low_high_map.get_entity_data_by_id(70), 56)
217+
218+
188219
def test_delete_cyc_support(cyclic_lin_rst, server_type_legacy_grpc):
189220
data_sources = dpf.DataSources(cyclic_lin_rst, server=server_type_legacy_grpc)
190221
model = dpf.Model(data_sources, server=server_type_legacy_grpc)

0 commit comments

Comments
 (0)