Skip to content

Commit f8f57e8

Browse files
authored
Update tests related to addition of new element types (INTER and MPC) (#664)
* Update tests related to addition of new element types (INTER and MPC) * Update the PR: run pre commit * Update the PR: add a condition on server version
1 parent e6e2201 commit f8f57e8

File tree

3 files changed

+153
-133
lines changed

3 files changed

+153
-133
lines changed

tests/conftest.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -204,6 +204,10 @@ def grpc_server():
204204
server.shutdown()
205205

206206

207+
SERVERS_VERSION_GREATER_THAN_OR_EQUAL_TO_9_0 = meets_version(
208+
get_server_version(core._global_server()), "9.0"
209+
)
210+
207211
SERVERS_VERSION_GREATER_THAN_OR_EQUAL_TO_8_0 = meets_version(
208212
get_server_version(core._global_server()), "8.0"
209213
)

tests/test_dpfresultwithkeywords.py

Lines changed: 111 additions & 98 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77

88
from ansys import dpf
99
from ansys.dpf import post
10+
from conftest import SERVERS_VERSION_GREATER_THAN_OR_EQUAL_TO_9_0
1011

1112

1213
def test_displacement_with_scoping_verbose_api(allkindofcomplexity):
@@ -254,55 +255,61 @@ def test_stress_with_invariant_subresult(allkindofcomplexity):
254255
assert stress.result_fields_container[0].location == locations.elemental_nodal
255256

256257

257-
# def test_groupingelshape_nodallocation_verbose_api(allkindofcomplexity):
258-
# result = post.load_solution(allkindofcomplexity)
259-
# disp = result.misc.nodal_displacement(grouping=post.grouping.by_el_shape)
260-
# assert disp.num_fields == 4
261-
# assert disp.result_fields_container.get_label_space(3) == {"elshape": 3, "time": 1}
262-
# assert len(disp.get_data_at_field(0)) == 14826
263-
# assert len(disp.get_data_at_field(1)) == 1486
264-
# assert len(disp.get_data_at_field(2)) == 19
265-
# assert len(disp.get_data_at_field(3)) == 4
266-
# assert np.isclose(disp.get_data_at_field(2)[0][0], 5.523488975819807e-20)
267-
# assert disp[0].location == locations.nodal
268-
269-
270-
# def test_groupingelshape_nodallocation(allkindofcomplexity):
271-
# result = post.load_solution(allkindofcomplexity)
272-
# d = result.displacement(grouping=post.grouping.by_el_shape)
273-
# disp = d.vector
274-
# assert disp.num_fields == 4
275-
# assert disp.result_fields_container.get_label_space(3) == {"elshape": 3, "time": 1}
276-
# assert len(disp.get_data_at_field(0)) == 14826
277-
# assert len(disp.get_data_at_field(1)) == 1486
278-
# assert len(disp.get_data_at_field(2)) == 19
279-
# assert len(disp.get_data_at_field(3)) == 4
280-
# assert np.isclose(disp.get_data_at_field(2)[0][0], 5.523488975819807e-20)
281-
# assert disp[0].location == locations.nodal
282-
#
283-
# with dpf.core operator
284-
# from ansys.dpf import core
285-
#
286-
# op = core.Operator("U")
287-
# # op.inputs.requested_location.connect(core.locations.nodal)
288-
# op.inputs.data_sources.connect(core.DataSources(allkindofcomplexity))
289-
# mesh_provider = core.Operator("MeshProvider")
290-
# mesh_provider.inputs.data_sources.connect(core.DataSources(allkindofcomplexity))
291-
# scop_op = core.Operator("scoping::by_property")
292-
# scop_op.inputs.mesh.connect(mesh_provider.outputs.mesh)
293-
# scop_op.inputs.requested_location.connect(core.locations.nodal)
294-
# scop_op.inputs.label1.connect("elshape")
295-
# op.inputs.mesh_scoping.connect(scop_op.outputs.mesh_scoping)
296-
# fc = op.outputs.fields_container()
297-
# assert len(fc) == disp.num_fields
298-
# assert fc[0].location == disp[0].location
299-
# assert len(fc[0].data) == len(disp[0].data)
300-
# assert np.allclose(disp[0].data.tolist(), fc[0].data.tolist())
301-
# comp = core.operators.logic.identical_fc()
302-
# comp.inputs.fields_containerA.connect(fc)
303-
# comp.inputs.fields_containerB.connect(disp.result_fields_container)
304-
# out = comp.outputs.boolean()
305-
# assert out == True
258+
def test_groupingelshape_nodallocation_verbose_api(allkindofcomplexity):
259+
result = post.load_solution(allkindofcomplexity)
260+
disp = result.misc.nodal_displacement(grouping=post.grouping.by_el_shape)
261+
assert disp.num_fields == 4
262+
assert disp.result_fields_container.get_label_space(3) == {"elshape": 3, "time": 1}
263+
assert len(disp.get_data_at_field(0)) == 14826
264+
assert len(disp.get_data_at_field(1)) == 1486
265+
if SERVERS_VERSION_GREATER_THAN_OR_EQUAL_TO_9_0:
266+
assert len(disp.get_data_at_field(2)) == 21
267+
else:
268+
assert len(disp.get_data_at_field(2)) == 19
269+
assert len(disp.get_data_at_field(3)) == 4
270+
assert np.isclose(disp.get_data_at_field(2)[0][0], 5.523488975819807e-20)
271+
assert disp[0].location == locations.nodal
272+
273+
274+
def test_groupingelshape_nodallocation(allkindofcomplexity):
275+
result = post.load_solution(allkindofcomplexity)
276+
d = result.displacement(grouping=post.grouping.by_el_shape)
277+
disp = d.vector
278+
assert disp.num_fields == 4
279+
assert disp.result_fields_container.get_label_space(3) == {"elshape": 3, "time": 1}
280+
assert len(disp.get_data_at_field(0)) == 14826
281+
assert len(disp.get_data_at_field(1)) == 1486
282+
if SERVERS_VERSION_GREATER_THAN_OR_EQUAL_TO_9_0:
283+
assert len(disp.get_data_at_field(2)) == 21
284+
else:
285+
assert len(disp.get_data_at_field(2)) == 19
286+
assert len(disp.get_data_at_field(3)) == 4
287+
assert np.isclose(disp.get_data_at_field(2)[0][0], 5.523488975819807e-20)
288+
assert disp[0].location == locations.nodal
289+
290+
# with dpf.core operator
291+
from ansys.dpf import core
292+
293+
op = core.Operator("U")
294+
# op.inputs.requested_location.connect(core.locations.nodal)
295+
op.inputs.data_sources.connect(core.DataSources(allkindofcomplexity))
296+
mesh_provider = core.Operator("MeshProvider")
297+
mesh_provider.inputs.data_sources.connect(core.DataSources(allkindofcomplexity))
298+
scop_op = core.Operator("scoping::by_property")
299+
scop_op.inputs.mesh.connect(mesh_provider.outputs.mesh)
300+
scop_op.inputs.requested_location.connect(core.locations.nodal)
301+
scop_op.inputs.label1.connect("elshape")
302+
op.inputs.mesh_scoping.connect(scop_op.outputs.mesh_scoping)
303+
fc = op.outputs.fields_container()
304+
assert len(fc) == disp.num_fields
305+
assert fc[0].location == disp[0].location
306+
assert len(fc[0].data) == len(disp[0].data)
307+
assert np.allclose(disp[0].data.tolist(), fc[0].data.tolist())
308+
comp = core.operators.logic.identical_fc()
309+
comp.inputs.fields_containerA.connect(fc)
310+
comp.inputs.fields_containerB.connect(disp.result_fields_container)
311+
out = comp.outputs.boolean()
312+
assert out == True
306313

307314

308315
def test_groupingelshape_elemlocation_verbose_api(allkindofcomplexity):
@@ -364,55 +371,61 @@ def test_groupingelshape_elemlocation(allkindofcomplexity):
364371
assert out == True
365372

366373

367-
# def test_groupingmat_nodallocation_verbose_api(allkindofcomplexity):
368-
# result = post.load_solution(allkindofcomplexity)
369-
# disp = result.misc.nodal_displacement(grouping=post.grouping.by_material)
370-
# assert disp.num_fields == 11
371-
# assert len(disp[0]) == 6288
372-
# assert len(disp[2]) == 744
373-
# assert np.isclose(disp.get_data_at_field(2)[0][2], -6.649053654123576e-07)
374-
# assert disp.result_fields_container.get_label_space(3) == {"time": 1, "mat": 10}
375-
# for field in disp:
376-
# assert len(field) != 0
377-
# assert field.location == locations.nodal
378-
379-
380-
# def test_groupingmat_nodallocation(allkindofcomplexity):
381-
# result = post.load_solution(allkindofcomplexity)
382-
# d = result.displacement(grouping=post.grouping.by_material)
383-
# disp = d.vector
384-
# assert disp.num_fields == 11
385-
# assert len(disp[0]) == 6288
386-
# assert len(disp[2]) == 744
387-
# assert np.isclose(disp.get_data_at_field(2)[0][2], -6.649053654123576e-07)
388-
# assert disp.result_fields_container.get_label_space(3) == {"time": 1, "mat": 10}
389-
# for field in disp:
390-
# assert len(field) != 0
391-
# assert field.location == locations.nodal
392-
#
393-
# # with dpf.core operator
394-
# from ansys.dpf import core
395-
#
396-
# op = core.Operator("U")
397-
# # op.inputs.requested_location.connect(core.locations.nodal)
398-
# op.inputs.data_sources.connect(core.DataSources(allkindofcomplexity))
399-
# mesh_provider = core.Operator("MeshProvider")
400-
# mesh_provider.inputs.data_sources.connect(core.DataSources(allkindofcomplexity))
401-
# scop_op = core.Operator("scoping::by_property")
402-
# scop_op.inputs.mesh.connect(mesh_provider.outputs.mesh)
403-
# scop_op.inputs.requested_location.connect(core.locations.nodal)
404-
# scop_op.inputs.label1.connect("mat")
405-
# op.inputs.mesh_scoping.connect(scop_op.outputs.mesh_scoping)
406-
# fc = op.outputs.fields_container()
407-
# assert len(fc) == disp.num_fields
408-
# assert fc[0].location == disp[0].location
409-
# assert len(fc[0].data) == len(disp[0].data)
410-
# assert np.allclose(disp[0].data.tolist(), fc[0].data.tolist())
411-
# comp = core.operators.logic.identical_fc()
412-
# comp.inputs.fields_containerA.connect(fc)
413-
# comp.inputs.fields_containerB.connect(disp.result_fields_container)
414-
# out = comp.outputs.boolean()
415-
# assert out is True
374+
def test_groupingmat_nodallocation_verbose_api(allkindofcomplexity):
375+
result = post.load_solution(allkindofcomplexity)
376+
disp = result.misc.nodal_displacement(grouping=post.grouping.by_material)
377+
if SERVERS_VERSION_GREATER_THAN_OR_EQUAL_TO_9_0:
378+
assert disp.num_fields == 13
379+
else:
380+
assert disp.num_fields == 11
381+
assert len(disp[0]) == 6288
382+
assert len(disp[2]) == 744
383+
assert np.isclose(disp.get_data_at_field(2)[0][2], -6.649053654123576e-07)
384+
assert disp.result_fields_container.get_label_space(3) == {"time": 1, "mat": 10}
385+
for field in disp:
386+
assert len(field) != 0
387+
assert field.location == locations.nodal
388+
389+
390+
def test_groupingmat_nodallocation(allkindofcomplexity):
391+
result = post.load_solution(allkindofcomplexity)
392+
d = result.displacement(grouping=post.grouping.by_material)
393+
disp = d.vector
394+
if SERVERS_VERSION_GREATER_THAN_OR_EQUAL_TO_9_0:
395+
assert disp.num_fields == 13
396+
else:
397+
assert disp.num_fields == 11
398+
assert len(disp[0]) == 6288
399+
assert len(disp[2]) == 744
400+
assert np.isclose(disp.get_data_at_field(2)[0][2], -6.649053654123576e-07)
401+
assert disp.result_fields_container.get_label_space(3) == {"time": 1, "mat": 10}
402+
for field in disp:
403+
assert len(field) != 0
404+
assert field.location == locations.nodal
405+
406+
# with dpf.core operator
407+
from ansys.dpf import core
408+
409+
op = core.Operator("U")
410+
# op.inputs.requested_location.connect(core.locations.nodal)
411+
op.inputs.data_sources.connect(core.DataSources(allkindofcomplexity))
412+
mesh_provider = core.Operator("MeshProvider")
413+
mesh_provider.inputs.data_sources.connect(core.DataSources(allkindofcomplexity))
414+
scop_op = core.Operator("scoping::by_property")
415+
scop_op.inputs.mesh.connect(mesh_provider.outputs.mesh)
416+
scop_op.inputs.requested_location.connect(core.locations.nodal)
417+
scop_op.inputs.label1.connect("mat")
418+
op.inputs.mesh_scoping.connect(scop_op.outputs.mesh_scoping)
419+
fc = op.outputs.fields_container()
420+
assert len(fc) == disp.num_fields
421+
assert fc[0].location == disp[0].location
422+
assert len(fc[0].data) == len(disp[0].data)
423+
assert np.allclose(disp[0].data.tolist(), fc[0].data.tolist())
424+
comp = core.operators.logic.identical_fc()
425+
comp.inputs.fields_containerA.connect(fc)
426+
comp.inputs.fields_containerB.connect(disp.result_fields_container)
427+
out = comp.outputs.boolean()
428+
assert out is True
416429

417430

418431
def test_groupingmat_elemlocation_verbose_api(allkindofcomplexity):

tests/test_simulation.py

Lines changed: 38 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,14 @@
66
from pytest import fixture
77

88
from ansys.dpf import post
9-
from ansys.dpf.post.common import AvailableSimulationTypes # elemental_properties
9+
from ansys.dpf.post.common import AvailableSimulationTypes, elemental_properties
1010
from ansys.dpf.post.index import ref_labels
11-
12-
# from ansys.dpf.post.meshes import Meshes
11+
from ansys.dpf.post.meshes import Meshes
1312
from conftest import (
1413
SERVERS_VERSION_GREATER_THAN_OR_EQUAL_TO_4_0,
1514
SERVERS_VERSION_GREATER_THAN_OR_EQUAL_TO_6_2,
1615
SERVERS_VERSION_GREATER_THAN_OR_EQUAL_TO_7_1,
16+
SERVERS_VERSION_GREATER_THAN_OR_EQUAL_TO_9_0,
1717
)
1818

1919

@@ -104,38 +104,41 @@ def test_simulation_plot(static_simulation):
104104
static_simulation.plot(cpos="xy")
105105

106106

107-
# def test_simulation_split_mesh_by_properties(allkindofcomplexity):
108-
# simulation = post.StaticMechanicalSimulation(allkindofcomplexity)
109-
# meshes = simulation.split_mesh_by_properties(
110-
# properties=[
111-
# elemental_properties.material,
112-
# elemental_properties.element_shape,
113-
# ]
114-
# )
115-
# assert isinstance(meshes, Meshes)
116-
# assert len(meshes) == 16
117-
# meshes = simulation.split_mesh_by_properties(
118-
# properties={
119-
# elemental_properties.material: 1,
120-
# elemental_properties.element_shape: [0, 1],
121-
# }
122-
# )
123-
# assert isinstance(meshes, Meshes)
124-
# assert len(meshes) == 2
125-
# meshes = simulation.split_mesh_by_properties(
126-
# properties={
127-
# elemental_properties.material: 1,
128-
# elemental_properties.element_shape: [0, 2],
129-
# }
130-
# )
131-
# assert isinstance(meshes, post.Mesh)
132-
# meshes = simulation.split_mesh_by_properties(
133-
# properties={
134-
# elemental_properties.material: 22,
135-
# elemental_properties.element_shape: [0, 2],
136-
# }
137-
# )
138-
# assert meshes is None
107+
def test_simulation_split_mesh_by_properties(allkindofcomplexity):
108+
simulation = post.StaticMechanicalSimulation(allkindofcomplexity)
109+
meshes = simulation.split_mesh_by_properties(
110+
properties=[
111+
elemental_properties.material,
112+
elemental_properties.element_shape,
113+
]
114+
)
115+
assert isinstance(meshes, Meshes)
116+
if SERVERS_VERSION_GREATER_THAN_OR_EQUAL_TO_9_0:
117+
assert len(meshes) == 18
118+
else:
119+
assert len(meshes) == 16
120+
meshes = simulation.split_mesh_by_properties(
121+
properties={
122+
elemental_properties.material: 1,
123+
elemental_properties.element_shape: [0, 1],
124+
}
125+
)
126+
assert isinstance(meshes, Meshes)
127+
assert len(meshes) == 2
128+
meshes = simulation.split_mesh_by_properties(
129+
properties={
130+
elemental_properties.material: 1,
131+
elemental_properties.element_shape: [0, 2],
132+
}
133+
)
134+
assert isinstance(meshes, post.Mesh)
135+
meshes = simulation.split_mesh_by_properties(
136+
properties={
137+
elemental_properties.material: 22,
138+
elemental_properties.element_shape: [0, 2],
139+
}
140+
)
141+
assert meshes is None
139142

140143

141144
class TestStaticMechanicalSimulation:

0 commit comments

Comments
 (0)