Skip to content
Closed
Show file tree
Hide file tree
Changes from 10 commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
2734aaa
Fix wrong input name for solid_to_skin operator
PProfizi Jul 10, 2023
cd4746b
Fix retro
PProfizi Jul 10, 2023
548aa0c
Merge branch 'master' into fix/skin_result_extraction
PProfizi Oct 26, 2023
dab0442
Working modif, let's try to add mesh_by_scop back for performance
PProfizi Oct 27, 2023
fe7a25e
Cannot add mesh_by_scop back as it is actually the source of the problem
PProfizi Oct 27, 2023
552b032
Add testing
PProfizi Oct 27, 2023
b040a22
Start fixing refs of tests
PProfizi Oct 27, 2023
15308a2
Fix refs of tests for current server
PProfizi Oct 27, 2023
3bc8779
Fix refs of tests
PProfizi Oct 27, 2023
e3393a0
Fix refs of tests
PProfizi Oct 30, 2023
8f81e3d
Fix typo
PProfizi Nov 3, 2023
29926b8
WIP
PProfizi Nov 7, 2023
f6161a4
Use "initial_mesh_wf_out" name
PProfizi Nov 7, 2023
a43d2fb
Use "result_mesh" name
PProfizi Nov 7, 2023
c34562a
WIP
PProfizi Nov 7, 2023
d7f1189
Fix mesh connection
PProfizi Nov 8, 2023
fa8aa84
Update 02-mesh-skin.py example with titles to plots
PProfizi Nov 13, 2023
adc8a46
Remove progress bar from selection workflows
PProfizi Nov 13, 2023
e24b07a
Remove progress bar from initial mesh workflow
PProfizi Nov 13, 2023
72c1d14
Temporary hack to remove mesh cached in model's streams
PProfizi Nov 13, 2023
f15e96c
Add tests WIP
PProfizi Nov 21, 2023
2d37b76
Apply suggestions from code review
PProfizi Nov 23, 2023
039ab55
Merge remote-tracking branch 'origin/fix/skin_result_extraction' into…
PProfizi Dec 20, 2023
e5abaad
Remove dirty trick to reset model.metadata now a fix has been made
PProfizi Dec 20, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 9 additions & 4 deletions src/ansys/dpf/post/selection.py
Original file line number Diff line number Diff line change
Expand Up @@ -443,11 +443,16 @@ def select_skin(
elements = Scoping(
server=self._server, ids=elements, location=locations.elemental
)
mesh_by_scop_op = operators.mesh.from_scoping(
scoping=elements, server=self._server
forward_op = operators.utility.forward()
mesh_input = forward_op.inputs.any
nodal_scoping = operators.scoping.transpose(
mesh_scoping=elements, server=self._server
)
nodal_scoping.connect(1, forward_op)
op.connect(0, forward_op)
op.inputs.mesh_scoping.connect(
nodal_scoping.outputs.mesh_scoping_as_scoping
)
mesh_input = mesh_by_scop_op.inputs.mesh
op.inputs.mesh.connect(mesh_by_scop_op)

if mesh_input is not None:
self._selection.set_input_name(_WfNames.initial_mesh, mesh_input)
Expand Down
28 changes: 27 additions & 1 deletion tests/test_selection.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
from ansys.dpf import core as dpf
from ansys.dpf import post
from ansys.dpf.post import examples
from ansys.dpf.post.selection import SpatialSelection
from ansys.dpf.post.selection import SpatialSelection, _WfNames
from conftest import SERVERS_VERSION_GREATER_THAN_OR_EQUAL_TO_7_0


Expand Down Expand Up @@ -50,6 +50,32 @@ def test_spatial_selection_select_named_selection(allkindofcomplexity):
assert 14826 in ids


def test_spatial_selection_select_skin(static_rst):
simulation = post.StaticMechanicalSimulation(static_rst)
selection = SpatialSelection()
selection._selection.progress_bar = False
selection.select_skin(
location=post.locations.elemental_nodal,
result_native_location=post.locations.elemental_nodal,
elements=[1, 2, 3],
)
mesh_wf = dpf.Workflow()
mesh_wf.set_output_name(
_WfNames.initial_mesh, simulation._model.metadata.mesh_provider
)
selection._selection.connect_with(
mesh_wf,
output_input_names={_WfNames.initial_mesh: _WfNames.initial_mesh},
)
# This returns a scoping on the initial mesh (logic to change?)
scoping_ids = selection.apply_to(simulation)
assert len(scoping_ids) == 8

# This gives the skin mesh with its 9 shell elements
skin = selection._selection.get_output(_WfNames.skin, dpf.MeshedRegion)
assert len(skin.elements.scoping.ids) == 9


@pytest.mark.skipif(
not SERVERS_VERSION_GREATER_THAN_OR_EQUAL_TO_7_0,
reason="Faces added with ansys-dpf-server 2024.1.pre0.",
Expand Down
134 changes: 82 additions & 52 deletions tests/test_simulation.py
Original file line number Diff line number Diff line change
Expand Up @@ -657,31 +657,27 @@ def test_skin_layer(self, static_simulation: post.StaticMechanicalSimulation):

def test_skin_layer2(self, static_simulation: post.StaticMechanicalSimulation):
result = static_simulation.displacement(set_ids=[1], skin=[1, 2, 3])
assert len(result.index.mesh_index) == 44
assert len(result.index.mesh_index) == 38
static_simulation.plot()
result.plot()

def test_skin_layer3(self, static_simulation: post.StaticMechanicalSimulation):
result = static_simulation.elastic_strain_eqv_von_mises_elemental(
skin=[1, 2, 3]
)
if SERVERS_VERSION_GREATER_THAN_OR_EQUAL_TO_7_1:
assert len(result.index.mesh_index) == 14
else:
assert len(result.index.mesh_index) == 18
assert len(result.index.mesh_index) == 9

def test_skin_layer4(self, static_simulation: post.StaticMechanicalSimulation):
result = static_simulation.stress_principal_nodal(skin=[1, 2, 3])
assert len(result.index.mesh_index) == 44
assert len(result.index.mesh_index) == 38

def test_skin_layer5(self, static_simulation: post.StaticMechanicalSimulation):
result = static_simulation.elastic_strain_eqv_von_mises_nodal(skin=[1, 2, 3])
assert len(result.index.mesh_index) == 44
assert len(result.index.mesh_index) == 38

def test_skin_layer6(self, static_simulation: post.StaticMechanicalSimulation):
result = static_simulation.stress_principal_elemental(skin=[1, 2, 3])
if SERVERS_VERSION_GREATER_THAN_OR_EQUAL_TO_7_1:
assert len(result.index.mesh_index) == 14
else:
assert len(result.index.mesh_index) == 18
assert len(result.index.mesh_index) == 9


class TestTransientMechanicalSimulation:
Expand Down Expand Up @@ -1324,13 +1320,17 @@ def test_skin_layer2(
self, transient_simulation: post.TransientMechanicalSimulation
):
result = transient_simulation.displacement(set_ids=[1], skin=[1, 2, 3])
assert len(result.index.mesh_index) == 44
if SERVERS_VERSION_GREATER_THAN_OR_EQUAL_TO_7_1:
assert len(result.index.mesh_index) == 42
else:
assert len(result.index.mesh_index) == 44

def test_skin_layer3(
self, transient_simulation: post.TransientMechanicalSimulation
):
print(transient_simulation.mesh.named_selections)
result = transient_simulation.stress_principal_elemental(
skin=list(range(1, 100))
skin=transient_simulation.mesh.element_ids
)
if SERVERS_VERSION_GREATER_THAN_OR_EQUAL_TO_7_1:
assert len(result.index.mesh_index) == 124
Expand All @@ -1341,7 +1341,7 @@ def test_skin_layer4(
self, transient_simulation: post.TransientMechanicalSimulation
):
result = transient_simulation.elastic_strain_eqv_von_mises_elemental(
skin=list(range(1, 100))
skin=transient_simulation.mesh.element_ids
)
if SERVERS_VERSION_GREATER_THAN_OR_EQUAL_TO_7_1:
assert len(result.index.mesh_index) == 124
Expand All @@ -1351,7 +1351,9 @@ def test_skin_layer4(
def test_skin_layer5(
self, transient_simulation: post.TransientMechanicalSimulation
):
result = transient_simulation.stress_principal_nodal(skin=list(range(1, 100)))
result = transient_simulation.stress_principal_nodal(
skin=transient_simulation.mesh.element_ids
)
if SERVERS_VERSION_GREATER_THAN_OR_EQUAL_TO_7_1:
assert len(result.index.mesh_index) == 374
else:
Expand All @@ -1361,7 +1363,7 @@ def test_skin_layer6(
self, transient_simulation: post.TransientMechanicalSimulation
):
result = transient_simulation.elastic_strain_eqv_von_mises_nodal(
skin=list(range(1, 100))
skin=transient_simulation.mesh.element_ids
)
if SERVERS_VERSION_GREATER_THAN_OR_EQUAL_TO_7_1:
assert len(result.index.mesh_index) == 374
Expand Down Expand Up @@ -1995,10 +1997,21 @@ def test_disp_skin(self, frame_modal_simulation: post.ModalMechanicalSimulation)
assert np.allclose(
result.max(axis="node_ids").array, [0.05656421, 9.59989137, 1.08656671]
)
result = frame_modal_simulation.displacement(set_ids=[1], skin=[1, 2, 3])
assert len(result.index.mesh_index) == 21

fixed_nodes = frame_modal_simulation.mesh.named_selections["_FIXEDSU"]._scoping
fixed_elements = dpf.operators.scoping.transpose(
mesh_scoping=fixed_nodes,
meshed_region=frame_modal_simulation.mesh._meshed_region,
).eval()
result = frame_modal_simulation.displacement(
set_ids=[1], skin=fixed_elements.ids
)
if SERVERS_VERSION_GREATER_THAN_OR_EQUAL_TO_7_1:
assert len(result.index.mesh_index) == 335
else:
assert len(result.index.mesh_index) == 455
assert np.allclose(
result.max(axis="node_ids").array, [-0.77876072, 7.08211902, 0.05292333]
result.max(axis="node_ids").array, [0.05594125, 0.23687614, 0.21415196]
)

def test_stress_skin(self, frame_modal_simulation: post.ModalMechanicalSimulation):
Expand All @@ -2015,32 +2028,32 @@ def test_stress_skin(self, frame_modal_simulation: post.ModalMechanicalSimulatio
)
assert len(result.columns.set_ids) == 1
if SERVERS_VERSION_GREATER_THAN_OR_EQUAL_TO_7_1:
assert len(result.index.mesh_index) == 36
Copy link
Contributor

Choose a reason for hiding this comment

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

how confident are we all these unit tests changes?

Copy link
Contributor

Choose a reason for hiding this comment

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

did you plot all of these to make sure they were good?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@cbellot000 Yes, I debugged most of them locally to check the actual number of elements involved and whether the new reference is correct this time. This is why I switched to NamedSelections for most of them.

Copy link
Contributor

Choose a reason for hiding this comment

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

I think we can now duplicate all these tests once with reduce_mesh=True, where we should have the same results as before, right?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@cbellot000 I started making specific tests for when we use reduce_mesh, but I do not think we need to duplicate all of the already existing ones for each result.

assert len(result.index.mesh_index) == 72
assert np.allclose(
result.max(axis="element_ids").array,
[
[
36.52192259,
58.73246002,
371.72294617,
12.80614456,
134.60557556,
38.0447108,
88.09000492,
426.21118164,
747.8219401,
30.50066868,
412.80891927,
109.25983429,
]
],
)
else:
assert len(result.index.mesh_index) == 110
assert len(result.index.mesh_index) == 497
assert np.allclose(
result.max(axis="element_ids").array,
[
[
36.52192259,
58.73246002,
371.72294617,
25.97949378,
139.83338165,
69.25232569,
145.15428162,
426.21118164,
840.23429362,
34.79916509,
415.22954305,
109.25983429,
]
],
)
Expand Down Expand Up @@ -2090,9 +2103,9 @@ def test_strain_skin(self, frame_modal_simulation: post.ModalMechanicalSimulatio
set_ids=[1], skin=list(range(1, 100))
)
if SERVERS_VERSION_GREATER_THAN_OR_EQUAL_TO_7_1:
assert len(result.index.mesh_index) == 36
assert len(result.index.mesh_index) == 72
else:
assert len(result.index.mesh_index) == 110
assert len(result.index.mesh_index) == 497
assert len(result.columns.set_ids) == 1

def test_strain_skin2(self, frame_modal_simulation: post.ModalMechanicalSimulation):
Expand Down Expand Up @@ -2751,7 +2764,10 @@ def test_disp_skin(self, harmonic_simulation: post.HarmonicMechanicalSimulation)
[2.76941713e-09, 2.76940199e-09, 4.10914311e-10],
)
result = harmonic_simulation.displacement(set_ids=[1], skin=[1, 2, 3])
assert len(result.index.mesh_index) == 44
if SERVERS_VERSION_GREATER_THAN_OR_EQUAL_TO_7_1:
assert len(result.index.mesh_index) == 40
else:
assert len(result.index.mesh_index) == 44

def test_stress_skin(self, harmonic_simulation: post.HarmonicMechanicalSimulation):
if harmonic_simulation._model._server.meet_version("6.2"):
Expand All @@ -2761,21 +2777,28 @@ def test_stress_skin(self, harmonic_simulation: post.HarmonicMechanicalSimulatio
else:
assert len(result.index.mesh_index) == 3942
assert len(result.columns.set_ids) == 1
outer_nodes = harmonic_simulation.mesh.named_selections[
"OUTER_FACE"
]._scoping
outer_elements = dpf.operators.scoping.transpose(
mesh_scoping=outer_nodes,
meshed_region=harmonic_simulation.mesh._meshed_region,
).eval()
result = harmonic_simulation.stress_elemental(
set_ids=[1], skin=list(range(1, 100))
set_ids=[1], skin=outer_elements.ids
)
if SERVERS_VERSION_GREATER_THAN_OR_EQUAL_TO_7_1:
assert len(result.index.mesh_index) == 122
assert len(result.index.mesh_index) == 240
else:
assert len(result.index.mesh_index) == 192
assert len(result.index.mesh_index) == 560
assert len(result.columns.set_ids) == 1
result = harmonic_simulation.stress_eqv_von_mises_nodal(
set_ids=[1], skin=list(range(1, 100))
set_ids=[1], skin=outer_elements.ids
)
if SERVERS_VERSION_GREATER_THAN_OR_EQUAL_TO_7_1:
assert len(result.index.mesh_index) == 520
assert len(result.index.mesh_index) == 880
else:
assert len(result.index.mesh_index) == 530
assert len(result.index.mesh_index) == 960
assert len(result.columns.set_ids) == 1
result = harmonic_simulation.stress_eqv_von_mises_nodal(
set_ids=[1], skin=True
Expand All @@ -2796,24 +2819,31 @@ def test_strain_skin(self, harmonic_simulation: post.HarmonicMechanicalSimulatio
else:
assert len(result.index.mesh_index) == 3942
assert len(result.columns.set_ids) == 1
outer_nodes = harmonic_simulation.mesh.named_selections[
"OUTER_FACE"
]._scoping
outer_elements = dpf.operators.scoping.transpose(
mesh_scoping=outer_nodes,
meshed_region=harmonic_simulation.mesh._meshed_region,
).eval()
result = harmonic_simulation.stress_principal_elemental(
set_ids=[1], skin=list(range(1, 100))
set_ids=[1], skin=outer_elements.ids
)
if SERVERS_VERSION_GREATER_THAN_OR_EQUAL_TO_7_1:
assert len(result.index.mesh_index) == 122
assert len(result.index.mesh_index) == 240
else:
assert len(result.index.mesh_index) == 192
assert len(result.index.mesh_index) == 560
assert len(result.columns.set_ids) == 1
result = harmonic_simulation.elastic_strain_eqv_von_mises_nodal(
set_ids=[1], skin=list(range(1, 100))
set_ids=[1], skin=outer_elements.ids
)
if SERVERS_VERSION_GREATER_THAN_OR_EQUAL_TO_7_1:
assert len(result.index.mesh_index) == 520
assert len(result.index.mesh_index) == 880
else:
assert len(result.index.mesh_index) == 530
assert len(result.index.mesh_index) == 960
assert len(result.columns.set_ids) == 1
assert np.allclose(
result.select(complex=0).max(axis="node_ids").array, [1.34699501e-06]
result.select(complex=0).max(axis="node_ids").array, [1.22784309e-06]
)
result = harmonic_simulation.elastic_strain_eqv_von_mises_nodal(
set_ids=[1], skin=True
Expand All @@ -2824,12 +2854,12 @@ def test_strain_skin(self, harmonic_simulation: post.HarmonicMechanicalSimulatio
assert len(result.index.mesh_index) == 4802
assert len(result.columns.set_ids) == 1
result = harmonic_simulation.elastic_strain_principal_nodal(
set_ids=[1], skin=list(range(1, 100))
set_ids=[1], skin=outer_elements.ids
)
if SERVERS_VERSION_GREATER_THAN_OR_EQUAL_TO_7_1:
assert len(result.index.mesh_index) == 520
assert len(result.index.mesh_index) == 880
else:
assert len(result.index.mesh_index) == 530
assert len(result.index.mesh_index) == 960
assert len(result.columns.set_ids) == 1
result = harmonic_simulation.elastic_strain_eqv_von_mises_elemental(
set_ids=[1], skin=True
Expand Down