Skip to content

Add CyclicSupport.cs, CyclicSupport.high_low_map & CyclicSupport.low_high_map #1875

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 15 commits into from
Nov 9, 2024
Merged
69 changes: 69 additions & 0 deletions src/ansys/dpf/core/cyclic_support.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@

from ansys.dpf.core import server as server_module
from ansys.dpf.core.scoping import Scoping
from ansys.dpf.core import field, property_field


class CyclicSupport:
Expand Down Expand Up @@ -304,6 +305,74 @@
)
return Scoping(scoping=expanded_ids, server=self._server)

def cs(self) -> field.Field:
"""Coordinate system of the cyclic support.

Examples
--------
>>> from ansys.dpf.core import Model
>>> from ansys.dpf.core import examples
>>> multi_stage = examples.download_multi_stage_cyclic_result()
>>> cyc_support = Model(multi_stage).metadata.result_info.cyclic_support
>>> cs = cyc_support.cs()

"""

cs = self._api.cyclic_support_get_cs(self)
return field.Field(field=cs, server=self._server)

Check warning on line 322 in src/ansys/dpf/core/cyclic_support.py

View check run for this annotation

Codecov / codecov/patch

src/ansys/dpf/core/cyclic_support.py#L321-L322

Added lines #L321 - L322 were not covered by tests

def low_high_map(self, stage_num: int = 0) -> property_field.PropertyField:
"""Retrieve a property field containing node map from low to high
base sector of the given stage.

Parameters
----------
stage_num:
Number of the stage required (from 0 to num_stages).

Returns
-------
low_high_map:
Node correspondence between low to high in the base sector of the given stage.

Examples
--------
>>> from ansys.dpf.core import Model
>>> from ansys.dpf.core import examples
>>> multi_stage = examples.download_multi_stage_cyclic_result()
>>> cyc_support = Model(multi_stage).metadata.result_info.cyclic_support
>>> low_high_map = cyc_support.low_high_map(0)

"""
low_high_map = self._api.cyclic_support_get_low_high_map(self, stage_num)
return property_field.PropertyField(property_field=low_high_map, server=self._server)

Check warning on line 348 in src/ansys/dpf/core/cyclic_support.py

View check run for this annotation

Codecov / codecov/patch

src/ansys/dpf/core/cyclic_support.py#L347-L348

Added lines #L347 - L348 were not covered by tests

def high_low_map(self, stage_num: int = 0) -> property_field.PropertyField:
"""Retrieve a property field containing node map from high to low
base sector of the given stage.

Parameters
----------
stage_num:
Number of the stage required (from 0 to num_stages).

Returns
-------
low_high_map:
Node correspondence between high to low in the base sector of the given stage.

Examples
--------
>>> from ansys.dpf.core import Model
>>> from ansys.dpf.core import examples
>>> multi_stage = examples.download_multi_stage_cyclic_result()
>>> cyc_support = Model(multi_stage).metadata.result_info.cyclic_support
>>> high_low_map = cyc_support.high_low_map(0)

"""
high_low_map = self._api.cyclic_support_get_high_low_map(self, stage_num)
return property_field.PropertyField(property_field=high_low_map, server=self._server)

Check warning on line 374 in src/ansys/dpf/core/cyclic_support.py

View check run for this annotation

Codecov / codecov/patch

src/ansys/dpf/core/cyclic_support.py#L373-L374

Added lines #L373 - L374 were not covered by tests

def __del__(self):
try:
self._deleter_func[0](self._deleter_func[1](self))
Expand Down
26 changes: 26 additions & 0 deletions src/ansys/dpf/gate/cyclic_support_grpcapi.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,16 @@ def cyclic_support_get_base_elements_scoping(support, i_stage):
return getattr(CyclicSupportGRPCAPI.list(support),
"base_elements_scoping_"+str(i_stage)).get_ownership()

@staticmethod
def cyclic_support_get_low_high_map(support, i_stage):
return getattr(CyclicSupportGRPCAPI.list(support),
"low_high_map_"+str(i_stage)).get_ownership()

@staticmethod
def cyclic_support_get_high_low_map(support, i_stage):
return getattr(CyclicSupportGRPCAPI.list(support),
"high_low_map_"+str(i_stage)).get_ownership()

@staticmethod
def get_expanded_ids(support, request):
return _get_stub(support._server).GetExpandedIds(request).expanded_ids
Expand All @@ -100,3 +110,19 @@ def cyclic_support_get_expanded_element_ids(support, baseElementId, i_stage, sec
request = CyclicSupportGRPCAPI.init_get_expanded_ids(support, i_stage, sectorsScoping)
request.element_id = baseElementId
return CyclicSupportGRPCAPI.get_expanded_ids(support, request)

@staticmethod
def get_cs(support, request):
return _get_stub(support._server).GetCS(request).cs

@staticmethod
def init_get_cs(support):
from ansys.grpc.dpf import cyclic_support_pb2
request = cyclic_support_pb2.GetCSRequest()
request.support.CopyFrom(support._internal_obj)
return request

@staticmethod
def cyclic_support_get_cs(support):
request = CyclicSupportGRPCAPI.init_get_cs(support)
return CyclicSupportGRPCAPI.get_cs(support, request)
31 changes: 31 additions & 0 deletions tests/test_cyclic_support.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
import weakref
import numpy as np

import conftest
import pytest

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


@pytest.mark.skipif(
not conftest.SERVERS_VERSION_GREATER_THAN_OR_EQUAL_TO_8_2, reason="Requires DPF 8.2 or above."
)
def test_cyc_support_coordinate_system(cyclic_lin_rst):
data_sources = dpf.DataSources(cyclic_lin_rst)
model = dpf.Model(data_sources)
result_info = model.metadata.result_info
cyc_support = result_info.cyclic_support
exp = cyc_support.cs().scoping
assert np.allclose(exp.ids, [12])


def test_cyc_support_multistage(cyclic_multistage):
model = dpf.Model(cyclic_multistage)
cyc_support = model.metadata.result_info.cyclic_support
Expand All @@ -185,6 +198,24 @@ def test_cyc_support_multistage(cyclic_multistage):
assert np.allclose(cyc_support.sectors_set_for_expansion(stage_num=1).ids, list(range(0, 12)))


@pytest.mark.skipif(
not conftest.SERVERS_VERSION_GREATER_THAN_OR_EQUAL_TO_8_2, reason="Requires DPF 8.2 or above."
)
def test_cyc_support_multistage_low_high_map(cyclic_multistage):
model = dpf.Model(cyclic_multistage)
cyc_support = model.metadata.result_info.cyclic_support

high_low_map = cyc_support.high_low_map(0)
assert np.allclose(high_low_map.get_entity_data_by_id(1446), 1447)
assert np.allclose(high_low_map.get_entity_data_by_id(2946), 2948)
assert np.allclose(high_low_map.get_entity_data_by_id(1452), 1466)

low_high_map = cyc_support.low_high_map(1)
assert np.allclose(low_high_map.get_entity_data_by_id(995), 939)
assert np.allclose(low_high_map.get_entity_data_by_id(53), 54)
assert np.allclose(low_high_map.get_entity_data_by_id(70), 56)


def test_delete_cyc_support(cyclic_lin_rst, server_type_legacy_grpc):
data_sources = dpf.DataSources(cyclic_lin_rst, server=server_type_legacy_grpc)
model = dpf.Model(data_sources, server=server_type_legacy_grpc)
Expand Down