Skip to content
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

Fix retro-compatibility with 222 and 221 #339

Merged
merged 8 commits into from
Mar 20, 2023
4 changes: 3 additions & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ jobs:
uses: pyansys/pydpf-actions/[email protected]
with:
python-version: ${{ matrix.python-version }}
ANSYS_VERSION: ${{env.ANSYS_VERSION}}
ANSYS_VERSION: ${{matrix.ANSYS_VERSION}}
PACKAGE_NAME: ${{env.PACKAGE_NAME}}
MODULE: ${{env.MODULE}}
dpf-standalone-TOKEN: ${{secrets.DPF_PIPELINE}}
Expand All @@ -157,6 +157,8 @@ jobs:
shell: bash
run: |
pip install ansys-grpc-dpf==0.4.0
pip uninstall -y protobuf
pip install "protobuf<4.0"
if: matrix.ANSYS_VERSION == '221'

- name: "Prepare Testing Environment"
Expand Down
4 changes: 3 additions & 1 deletion .github/workflows/ci_release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ jobs:
uses: pyansys/pydpf-actions/[email protected]
with:
python-version: ${{ matrix.python-version }}
ANSYS_VERSION: ${{env.ANSYS_VERSION}}
ANSYS_VERSION: ${{matrix.ANSYS_VERSION}}
PACKAGE_NAME: ${{env.PACKAGE_NAME}}
MODULE: ${{env.MODULE}}
dpf-standalone-TOKEN: ${{secrets.DPF_PIPELINE}}
Expand All @@ -153,6 +153,8 @@ jobs:
shell: bash
run: |
pip install ansys-grpc-dpf==0.4.0
pip uninstall -y protobuf
pip install "protobuf<4.0"
if: matrix.ANSYS_VERSION == '221'

- name: "Prepare Testing Environment"
Expand Down
6 changes: 0 additions & 6 deletions src/ansys/dpf/post/harmonic_mechanical_simulation.py
Original file line number Diff line number Diff line change
Expand Up @@ -264,12 +264,6 @@ def _get_result(
wf.add_operator(operator=norm_op)
out = norm_op.outputs.fields_container

extract_scoping = self._model.operator(name="extract_scoping")
extract_scoping.connect(0, out)
merge_scopings = self._model.operator(name="merge::scoping")
merge_scopings.connect(0, extract_scoping.outputs.mesh_scoping_as_scoping)
wf.set_output_name("scoping", merge_scopings.outputs.merged_scoping)

# Set the workflow output
wf.set_output_name("out", out)
# Evaluate the workflow
Expand Down
14 changes: 10 additions & 4 deletions src/ansys/dpf/post/index.py
Original file line number Diff line number Diff line change
Expand Up @@ -147,10 +147,16 @@ def _evaluate_values(self):
# Merge the fields container scoping
fc = self._fc()
if fc is not None:
scopings = dpf.operators.utility.extract_scoping(
field_or_fields_container=fc
).outputs.mesh_scoping_as_scopings_container
merge_op = dpf.operators.utility.merge_scopings(scopings=scopings)
merge_op = dpf.operators.utility.merge_scopings(server=fc._server)
if float(fc._server.version) >= 5.0:
scopings = dpf.operators.utility.extract_scoping(
field_or_fields_container=fc,
server=fc._server,
).outputs.mesh_scoping_as_scopings_container
merge_op.connect(0, scopings)
else:
for i, f in enumerate(fc):
merge_op.connect(i, f.scoping)
self._values = merge_op.eval().ids
else:
raise AttributeError(
Expand Down
6 changes: 0 additions & 6 deletions src/ansys/dpf/post/modal_mechanical_simulation.py
Original file line number Diff line number Diff line change
Expand Up @@ -206,12 +206,6 @@ def _get_result(
wf.add_operator(operator=norm_op)
out = norm_op.outputs.fields_container

extract_scoping = self._model.operator(name="extract_scoping")
extract_scoping.connect(0, out)
merge_scopings = self._model.operator(name="merge::scoping")
merge_scopings.connect(0, extract_scoping.outputs.mesh_scoping_as_scoping)
wf.set_output_name("scoping", merge_scopings.outputs.merged_scoping)

# Set the workflow output
wf.set_output_name("out", out)
# Evaluate the workflow
Expand Down
6 changes: 0 additions & 6 deletions src/ansys/dpf/post/transient_mechanical_simulation.py
Original file line number Diff line number Diff line change
Expand Up @@ -214,12 +214,6 @@ def _get_result(
out = norm_op.outputs.fields_container
comp = None

extract_scoping = self._model.operator(name="extract_scoping")
extract_scoping.connect(0, out)
merge_scopings = self._model.operator(name="merge::scoping")
merge_scopings.connect(0, extract_scoping.outputs.mesh_scoping_as_scoping)
wf.set_output_name("scoping", merge_scopings.outputs.merged_scoping)

# Set the workflow output
wf.set_output_name("out", out)
# Evaluate the workflow
Expand Down
3 changes: 3 additions & 0 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,9 @@ def close_servers():
get_server_version(core._global_server()), "6.0"
)

SERVERS_VERSION_GREATER_THAN_OR_EQUAL_TO_5_0 = meets_version(
get_server_version(core._global_server()), "5.0"
)

# to call at the end
if SERVERS_VERSION_GREATER_THAN_OR_EQUAL_TO_6_0:
Expand Down
1 change: 1 addition & 0 deletions tests/test_dataframe.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
@fixture
def df(static_rst):
simulation = StaticMechanicalSimulation(static_rst)
print(simulation._model._server.version)
return simulation.displacement()


Expand Down
49 changes: 49 additions & 0 deletions tests/test_simulation.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import os.path

import ansys.dpf.core as core
from conftest import SERVERS_VERSION_GREATER_THAN_OR_EQUAL_TO_5_0
import numpy as np
import pytest
from pytest import fixture
Expand Down Expand Up @@ -430,6 +431,10 @@ def test_structural_temperature_elemental(self, static_simulation):
assert field.data.shape == (12,)
assert np.allclose(field.data, field_ref.data)

@pytest.mark.skipif(
not SERVERS_VERSION_GREATER_THAN_OR_EQUAL_TO_5_0,
reason="Available starting DPF 5.0",
)
def test_element_nodal_forces(self, allkindofcomplexity):
static_simulation = post.load_simulation(data_sources=allkindofcomplexity)
element_nodal_forces = static_simulation.element_nodal_forces()
Expand All @@ -442,6 +447,10 @@ def test_element_nodal_forces(self, allkindofcomplexity):
assert field.data.shape == (103766, 3)
assert np.allclose(field.data, field_ref.data)

@pytest.mark.skipif(
not SERVERS_VERSION_GREATER_THAN_OR_EQUAL_TO_5_0,
reason="Available starting DPF 5.0",
)
def test_element_nodal_forces_nodal(self, allkindofcomplexity):
static_simulation = post.load_simulation(data_sources=allkindofcomplexity)
element_nodal_forces = static_simulation.element_nodal_forces_nodal()
Expand All @@ -455,6 +464,10 @@ def test_element_nodal_forces_nodal(self, allkindofcomplexity):
assert field.data.shape == (14982, 3)
assert np.allclose(field.data, field_ref.data)

@pytest.mark.skipif(
not SERVERS_VERSION_GREATER_THAN_OR_EQUAL_TO_5_0,
reason="Available starting DPF 5.0",
)
def test_element_nodal_forces_elemental(self, allkindofcomplexity):
static_simulation = post.load_simulation(data_sources=allkindofcomplexity)
element_nodal_forces = static_simulation.element_nodal_forces_elemental()
Expand Down Expand Up @@ -974,6 +987,10 @@ def test_structural_temperature_elemental(self, transient_simulation):
assert field.component_count == 1
assert np.allclose(field.data, field_ref.data)

@pytest.mark.skipif(
not SERVERS_VERSION_GREATER_THAN_OR_EQUAL_TO_5_0,
reason="Available starting DPF 5.0",
)
def test_element_nodal_forces(self, allkindofcomplexity):
transient_simulation = post.load_simulation(
data_sources=allkindofcomplexity,
Expand All @@ -988,6 +1005,10 @@ def test_element_nodal_forces(self, allkindofcomplexity):
assert field.component_count == 3
assert np.allclose(field.data, field_ref.data)

@pytest.mark.skipif(
not SERVERS_VERSION_GREATER_THAN_OR_EQUAL_TO_5_0,
reason="Available starting DPF 5.0",
)
def test_element_nodal_forces_nodal(self, allkindofcomplexity):
transient_simulation = post.load_simulation(
data_sources=allkindofcomplexity,
Expand All @@ -1003,6 +1024,10 @@ def test_element_nodal_forces_nodal(self, allkindofcomplexity):
assert field.component_count == 3
assert np.allclose(field.data, field_ref.data)

@pytest.mark.skipif(
not SERVERS_VERSION_GREATER_THAN_OR_EQUAL_TO_5_0,
reason="Available starting DPF 5.0",
)
def test_element_nodal_forces_elemental(self, allkindofcomplexity):
transient_simulation = post.load_simulation(
data_sources=allkindofcomplexity,
Expand Down Expand Up @@ -1126,6 +1151,10 @@ def test_reaction_force(self, allkindofcomplexity):
assert field.component_count == 3
assert np.allclose(field.data, field_ref.data)

@pytest.mark.skipif(
not SERVERS_VERSION_GREATER_THAN_OR_EQUAL_TO_5_0,
reason="Available starting DPF 5.0",
)
def test_element_nodal_forces(self, allkindofcomplexity):
modal_simulation = post.load_simulation(
data_sources=allkindofcomplexity,
Expand All @@ -1140,6 +1169,10 @@ def test_element_nodal_forces(self, allkindofcomplexity):
assert field.component_count == 3
assert np.allclose(field.data, field_ref.data)

@pytest.mark.skipif(
not SERVERS_VERSION_GREATER_THAN_OR_EQUAL_TO_5_0,
reason="Available starting DPF 5.0",
)
def test_element_nodal_forces_nodal(self, allkindofcomplexity):
modal_simulation = post.load_simulation(
data_sources=allkindofcomplexity,
Expand All @@ -1155,6 +1188,10 @@ def test_element_nodal_forces_nodal(self, allkindofcomplexity):
assert field.component_count == 3
assert np.allclose(field.data, field_ref.data)

@pytest.mark.skipif(
not SERVERS_VERSION_GREATER_THAN_OR_EQUAL_TO_5_0,
reason="Available starting DPF 5.0",
)
def test_element_nodal_forces_elemental(self, allkindofcomplexity):
modal_simulation = post.load_simulation(
data_sources=allkindofcomplexity,
Expand Down Expand Up @@ -1582,6 +1619,10 @@ def test_reaction_force(self, allkindofcomplexity):
assert field.component_count == 3
assert np.allclose(field.data, field_ref.data)

@pytest.mark.skipif(
not SERVERS_VERSION_GREATER_THAN_OR_EQUAL_TO_5_0,
reason="Available starting DPF 5.0",
)
def test_element_nodal_forces(self, allkindofcomplexity):
harmonic_simulation = post.load_simulation(
data_sources=allkindofcomplexity,
Expand All @@ -1596,6 +1637,10 @@ def test_element_nodal_forces(self, allkindofcomplexity):
assert field.component_count == 3
assert np.allclose(field.data, field_ref.data)

@pytest.mark.skipif(
not SERVERS_VERSION_GREATER_THAN_OR_EQUAL_TO_5_0,
reason="Available starting DPF 5.0",
)
def test_element_nodal_forces_nodal(self, allkindofcomplexity):
harmonic_simulation = post.load_simulation(
data_sources=allkindofcomplexity,
Expand All @@ -1611,6 +1656,10 @@ def test_element_nodal_forces_nodal(self, allkindofcomplexity):
assert field.component_count == 3
assert np.allclose(field.data, field_ref.data)

@pytest.mark.skipif(
not SERVERS_VERSION_GREATER_THAN_OR_EQUAL_TO_5_0,
reason="Available starting DPF 5.0",
)
def test_element_nodal_forces_elemental(self, allkindofcomplexity):
harmonic_simulation = post.load_simulation(
data_sources=allkindofcomplexity,
Expand Down