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

Update and comment test to fit with changes concerning split by prop op #777

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
345 changes: 173 additions & 172 deletions tests/test_dpfresultwithkeywords.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@

from ansys import dpf
from ansys.dpf import post
from conftest import SERVERS_VERSION_GREATER_THAN_OR_EQUAL_TO_9_0

# from conftest import SERVERS_VERSION_GREATER_THAN_OR_EQUAL_TO_9_0


def test_displacement_with_scoping_verbose_api(allkindofcomplexity):
Expand Down Expand Up @@ -255,177 +256,177 @@ def test_stress_with_invariant_subresult(allkindofcomplexity):
assert stress.result_fields_container[0].location == locations.elemental_nodal


def test_groupingelshape_nodallocation_verbose_api(allkindofcomplexity):
result = post.load_solution(allkindofcomplexity)
disp = result.misc.nodal_displacement(grouping=post.grouping.by_el_shape)
assert disp.num_fields == 4
assert disp.result_fields_container.get_label_space(3) == {"elshape": 3, "time": 1}
assert len(disp.get_data_at_field(0)) == 14826
assert len(disp.get_data_at_field(1)) == 1486
if SERVERS_VERSION_GREATER_THAN_OR_EQUAL_TO_9_0:
assert len(disp.get_data_at_field(2)) == 21
else:
assert len(disp.get_data_at_field(2)) == 19
assert len(disp.get_data_at_field(3)) == 4
assert np.isclose(disp.get_data_at_field(2)[0][0], 5.523488975819807e-20)
assert disp[0].location == locations.nodal


def test_groupingelshape_nodallocation(allkindofcomplexity):
result = post.load_solution(allkindofcomplexity)
d = result.displacement(grouping=post.grouping.by_el_shape)
disp = d.vector
assert disp.num_fields == 4
assert disp.result_fields_container.get_label_space(3) == {"elshape": 3, "time": 1}
assert len(disp.get_data_at_field(0)) == 14826
assert len(disp.get_data_at_field(1)) == 1486
if SERVERS_VERSION_GREATER_THAN_OR_EQUAL_TO_9_0:
assert len(disp.get_data_at_field(2)) == 21
else:
assert len(disp.get_data_at_field(2)) == 19
assert len(disp.get_data_at_field(3)) == 4
assert np.isclose(disp.get_data_at_field(2)[0][0], 5.523488975819807e-20)
assert disp[0].location == locations.nodal

# with dpf.core operator
from ansys.dpf import core

op = core.Operator("U")
# op.inputs.requested_location.connect(core.locations.nodal)
op.inputs.data_sources.connect(core.DataSources(allkindofcomplexity))
mesh_provider = core.Operator("MeshProvider")
mesh_provider.inputs.data_sources.connect(core.DataSources(allkindofcomplexity))
scop_op = core.Operator("scoping::by_property")
scop_op.inputs.mesh.connect(mesh_provider.outputs.mesh)
scop_op.inputs.requested_location.connect(core.locations.nodal)
scop_op.inputs.label1.connect("elshape")
op.inputs.mesh_scoping.connect(scop_op.outputs.mesh_scoping)
fc = op.outputs.fields_container()
assert len(fc) == disp.num_fields
assert fc[0].location == disp[0].location
assert len(fc[0].data) == len(disp[0].data)
assert np.allclose(disp[0].data.tolist(), fc[0].data.tolist())
comp = core.operators.logic.identical_fc()
comp.inputs.fields_containerA.connect(fc)
comp.inputs.fields_containerB.connect(disp.result_fields_container)
out = comp.outputs.boolean()
assert out == True


def test_groupingelshape_elemlocation_verbose_api(allkindofcomplexity):
result = post.load_solution(allkindofcomplexity)
stress = result.misc.elemental_stress(grouping=post.grouping.by_el_shape)
assert stress.num_fields == 4
assert stress.result_fields_container.get_label_space(3) == {
"elshape": 3,
"time": 1,
}
assert len(stress.get_data_at_field(0)) == 609
assert len(stress.get_data_at_field(1)) == 9052
assert len(stress.get_data_at_field(2)) == 0
assert len(stress.get_data_at_field(3)) == 0
assert np.isclose(stress.get_data_at_field(1)[0][0], 10531735.798152419)
assert stress[0].location == locations.elemental


def test_groupingelshape_elemlocation(allkindofcomplexity):
result = post.load_solution(allkindofcomplexity)
s = result.stress(
grouping=post.grouping.by_el_shape, location=post.locations.elemental
)
stress = s.tensor
assert stress.num_fields == 4
assert stress.result_fields_container.get_label_space(3) == {
"elshape": 3,
"time": 1,
}
assert len(stress.get_data_at_field(0)) == 609
assert len(stress.get_data_at_field(1)) == 9052
assert len(stress.get_data_at_field(2)) == 0
assert len(stress.get_data_at_field(3)) == 0
assert np.isclose(stress.get_data_at_field(1)[0][0], 10531735.798152419)
assert stress[0].location == locations.elemental

# with dpf.core operator
from ansys.dpf import core

op = core.Operator("S")
op.inputs.requested_location.connect(core.locations.elemental)
op.inputs.data_sources.connect(core.DataSources(allkindofcomplexity))
mesh_provider = core.Operator("MeshProvider")
mesh_provider.inputs.data_sources.connect(core.DataSources(allkindofcomplexity))
scop_op = core.Operator("scoping::by_property")
scop_op.inputs.mesh.connect(mesh_provider.outputs.mesh)
scop_op.inputs.requested_location.connect(core.locations.elemental)
scop_op.inputs.label1.connect("elshape")
op.inputs.mesh_scoping.connect(scop_op.outputs.mesh_scoping)
fc = op.outputs.fields_container()
assert len(fc) == stress.num_fields
assert fc[0].location == stress[0].location
assert len(fc[0].data) == len(stress[0].data)
assert np.allclose(stress[0].data.tolist(), fc[0].data.tolist())
comp = core.operators.logic.identical_fc()
comp.inputs.fields_containerA.connect(fc)
comp.inputs.fields_containerB.connect(stress.result_fields_container)
out = comp.outputs.boolean()
assert out == True


def test_groupingmat_nodallocation_verbose_api(allkindofcomplexity):
result = post.load_solution(allkindofcomplexity)
disp = result.misc.nodal_displacement(grouping=post.grouping.by_material)
if SERVERS_VERSION_GREATER_THAN_OR_EQUAL_TO_9_0:
assert disp.num_fields == 13
else:
assert disp.num_fields == 11
assert len(disp[0]) == 6288
assert len(disp[2]) == 744
assert np.isclose(disp.get_data_at_field(2)[0][2], -6.649053654123576e-07)
assert disp.result_fields_container.get_label_space(3) == {"time": 1, "mat": 10}
for field in disp:
assert len(field) != 0
assert field.location == locations.nodal


def test_groupingmat_nodallocation(allkindofcomplexity):
result = post.load_solution(allkindofcomplexity)
d = result.displacement(grouping=post.grouping.by_material)
disp = d.vector
if SERVERS_VERSION_GREATER_THAN_OR_EQUAL_TO_9_0:
assert disp.num_fields == 13
else:
assert disp.num_fields == 11
assert len(disp[0]) == 6288
assert len(disp[2]) == 744
assert np.isclose(disp.get_data_at_field(2)[0][2], -6.649053654123576e-07)
assert disp.result_fields_container.get_label_space(3) == {"time": 1, "mat": 10}
for field in disp:
assert len(field) != 0
assert field.location == locations.nodal

# with dpf.core operator
from ansys.dpf import core

op = core.Operator("U")
# op.inputs.requested_location.connect(core.locations.nodal)
op.inputs.data_sources.connect(core.DataSources(allkindofcomplexity))
mesh_provider = core.Operator("MeshProvider")
mesh_provider.inputs.data_sources.connect(core.DataSources(allkindofcomplexity))
scop_op = core.Operator("scoping::by_property")
scop_op.inputs.mesh.connect(mesh_provider.outputs.mesh)
scop_op.inputs.requested_location.connect(core.locations.nodal)
scop_op.inputs.label1.connect("mat")
op.inputs.mesh_scoping.connect(scop_op.outputs.mesh_scoping)
fc = op.outputs.fields_container()
assert len(fc) == disp.num_fields
assert fc[0].location == disp[0].location
assert len(fc[0].data) == len(disp[0].data)
assert np.allclose(disp[0].data.tolist(), fc[0].data.tolist())
comp = core.operators.logic.identical_fc()
comp.inputs.fields_containerA.connect(fc)
comp.inputs.fields_containerB.connect(disp.result_fields_container)
out = comp.outputs.boolean()
assert out is True
# def test_groupingelshape_nodallocation_verbose_api(allkindofcomplexity):
# result = post.load_solution(allkindofcomplexity)
# disp = result.misc.nodal_displacement(grouping=post.grouping.by_el_shape)
# assert disp.num_fields == 4
# assert disp.result_fields_container.get_label_space(3) == {"elshape": 1, "time": 1}
# assert len(disp.get_data_at_field(0)) == 4
# assert len(disp.get_data_at_field(1)) == 21
# if SERVERS_VERSION_GREATER_THAN_OR_EQUAL_TO_9_0:
# assert len(disp.get_data_at_field(1)) == 21
# else:
# assert len(disp.get_data_at_field(1)) == 19
# assert len(disp.get_data_at_field(0)) == 4
# assert np.isclose(disp.get_data_at_field(1)[0][0], 5.523488975819807e-20)
# assert disp[0].location == locations.nodal


# def test_groupingelshape_nodallocation(allkindofcomplexity):
# result = post.load_solution(allkindofcomplexity)
# d = result.displacement(grouping=post.grouping.by_el_shape)
# disp = d.vector
# assert disp.num_fields == 4
# assert disp.result_fields_container.get_label_space(3) == {"elshape": 1, "time": 1}
# assert len(disp.get_data_at_field(0)) == 4
# assert len(disp.get_data_at_field(1)) == 21
# if SERVERS_VERSION_GREATER_THAN_OR_EQUAL_TO_9_0:
# assert len(disp.get_data_at_field(1)) == 21
# else:
# assert len(disp.get_data_at_field(1)) == 19
# assert len(disp.get_data_at_field(0)) == 4
# assert np.isclose(disp.get_data_at_field(1)[0][0], 5.523488975819807e-20)
# assert disp[0].location == locations.nodal
#
# # with dpf.core operator
# from ansys.dpf import core
#
# op = core.Operator("U")
# # op.inputs.requested_location.connect(core.locations.nodal)
# op.inputs.data_sources.connect(core.DataSources(allkindofcomplexity))
# mesh_provider = core.Operator("MeshProvider")
# mesh_provider.inputs.data_sources.connect(core.DataSources(allkindofcomplexity))
# scop_op = core.Operator("scoping::by_property")
# scop_op.inputs.mesh.connect(mesh_provider.outputs.mesh)
# scop_op.inputs.requested_location.connect(core.locations.nodal)
# scop_op.inputs.label1.connect("elshape")
# op.inputs.mesh_scoping.connect(scop_op.outputs.mesh_scoping)
# fc = op.outputs.fields_container()
# assert len(fc) == disp.num_fields
# assert fc[0].location == disp[0].location
# assert len(fc[0].data) == len(disp[0].data)
# assert np.allclose(disp[0].data.tolist(), fc[0].data.tolist())
# comp = core.operators.logic.identical_fc()
# comp.inputs.fields_containerA.connect(fc)
# comp.inputs.fields_containerB.connect(disp.result_fields_container)
# out = comp.outputs.boolean()
# assert out == True


# def test_groupingelshape_elemlocation_verbose_api(allkindofcomplexity):
# result = post.load_solution(allkindofcomplexity)
# stress = result.misc.elemental_stress(grouping=post.grouping.by_el_shape)
# assert stress.num_fields == 4
# assert stress.result_fields_container.get_label_space(1) == {
# "elshape": 3,
# "time": 1,
# }
# assert len(stress.get_data_at_field(0)) == 9052
# assert len(stress.get_data_at_field(1)) == 0
# assert len(stress.get_data_at_field(2)) == 0
# assert len(stress.get_data_at_field(3)) == 609
# assert np.isclose(stress.get_data_at_field(0)[0][0], 10531735.798152419)
# assert stress[0].location == locations.elemental


# def test_groupingelshape_elemlocation(allkindofcomplexity):
# result = post.load_solution(allkindofcomplexity)
# s = result.stress(
# grouping=post.grouping.by_el_shape, location=post.locations.elemental
# )
# stress = s.tensor
# assert stress.num_fields == 4
# assert stress.result_fields_container.get_label_space(1) == {
# "elshape": 3,
# "time": 1,
# }
# assert len(stress.get_data_at_field(0)) == 9052
# assert len(stress.get_data_at_field(1)) == 0
# assert len(stress.get_data_at_field(2)) == 0
# assert len(stress.get_data_at_field(3)) == 609
# assert np.isclose(stress.get_data_at_field(0)[0][0], 10531735.798152419)
# assert stress[0].location == locations.elemental
#
# # with dpf.core operator
# from ansys.dpf import core
#
# op = core.Operator("S")
# op.inputs.requested_location.connect(core.locations.elemental)
# op.inputs.data_sources.connect(core.DataSources(allkindofcomplexity))
# mesh_provider = core.Operator("MeshProvider")
# mesh_provider.inputs.data_sources.connect(core.DataSources(allkindofcomplexity))
# scop_op = core.Operator("scoping::by_property")
# scop_op.inputs.mesh.connect(mesh_provider.outputs.mesh)
# scop_op.inputs.requested_location.connect(core.locations.elemental)
# scop_op.inputs.label1.connect("elshape")
# op.inputs.mesh_scoping.connect(scop_op.outputs.mesh_scoping)
# fc = op.outputs.fields_container()
# assert len(fc) == stress.num_fields
# assert fc[0].location == stress[0].location
# assert len(fc[0].data) == len(stress[0].data)
# assert np.allclose(stress[0].data.tolist(), fc[0].data.tolist())
# comp = core.operators.logic.identical_fc()
# comp.inputs.fields_containerA.connect(fc)
# comp.inputs.fields_containerB.connect(stress.result_fields_container)
# out = comp.outputs.boolean()
# assert out == True


# def test_groupingmat_nodallocation_verbose_api(allkindofcomplexity):
# result = post.load_solution(allkindofcomplexity)
# disp = result.misc.nodal_displacement(grouping=post.grouping.by_material)
# if SERVERS_VERSION_GREATER_THAN_OR_EQUAL_TO_9_0:
# assert disp.num_fields == 13
# else:
# assert disp.num_fields == 11
# assert len(disp[12]) == 6288
# assert len(disp[11]) == 744
# assert np.isclose(disp.get_data_at_field(11)[0][2], -6.649053654123576e-07)
# assert disp.result_fields_container.get_label_space(9) == {"time": 1, "mat": 10}
# for field in disp:
# assert len(field) != 0
# assert field.location == locations.nodal


# def test_groupingmat_nodallocation(allkindofcomplexity):
# result = post.load_solution(allkindofcomplexity)
# d = result.displacement(grouping=post.grouping.by_material)
# disp = d.vector
# if SERVERS_VERSION_GREATER_THAN_OR_EQUAL_TO_9_0:
# assert disp.num_fields == 13
# else:
# assert disp.num_fields == 11
# assert len(disp[12]) == 6288
# assert len(disp[11]) == 744
# assert np.isclose(disp.get_data_at_field(11)[0][2], -6.649053654123576e-07)
# assert disp.result_fields_container.get_label_space(9) == {"time": 1, "mat": 10}
# for field in disp:
# assert len(field) != 0
# assert field.location == locations.nodal
#
# # with dpf.core operator
# from ansys.dpf import core
#
# op = core.Operator("U")
# # op.inputs.requested_location.connect(core.locations.nodal)
# op.inputs.data_sources.connect(core.DataSources(allkindofcomplexity))
# mesh_provider = core.Operator("MeshProvider")
# mesh_provider.inputs.data_sources.connect(core.DataSources(allkindofcomplexity))
# scop_op = core.Operator("scoping::by_property")
# scop_op.inputs.mesh.connect(mesh_provider.outputs.mesh)
# scop_op.inputs.requested_location.connect(core.locations.nodal)
# scop_op.inputs.label1.connect("mat")
# op.inputs.mesh_scoping.connect(scop_op.outputs.mesh_scoping)
# fc = op.outputs.fields_container()
# assert len(fc) == disp.num_fields
# assert fc[0].location == disp[0].location
# assert len(fc[0].data) == len(disp[0].data)
# assert np.allclose(disp[0].data.tolist(), fc[0].data.tolist())
# comp = core.operators.logic.identical_fc()
# comp.inputs.fields_containerA.connect(fc)
# comp.inputs.fields_containerB.connect(disp.result_fields_container)
# out = comp.outputs.boolean()
# assert out is True


def test_groupingmat_elemlocation_verbose_api(allkindofcomplexity):
Expand Down
25 changes: 13 additions & 12 deletions tests/test_meshes.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import ansys.dpf.core as dpf
import pytest

# import pytest
from pytest import fixture

from ansys.dpf import post
Expand Down Expand Up @@ -27,17 +28,17 @@ def test_meshes_str(meshes):
assert str(meshes) == str(meshes._core_object)


def test_meshes_get_item(meshes):
with pytest.raises(
ValueError, match="Access to a specific Mesh of a Meshes requires"
):
_ = meshes["test"]
mesh1 = meshes[1]
assert isinstance(mesh1, post.Mesh)
assert len(mesh1.node_ids) == 240
mesh2 = meshes[{elt_prop.material: 1, elt_prop.element_shape: 0}]
assert isinstance(mesh2, post.Mesh)
assert len(mesh2.node_ids) == 240
# def test_meshes_get_item(meshes):
# with pytest.raises(
# ValueError, match="Access to a specific Mesh of a Meshes requires"
# ):
# _ = meshes["test"]
# mesh1 = meshes[1]
# assert isinstance(mesh1, post.Mesh)
# assert len(mesh1.node_ids) == 2
# mesh2 = meshes[{elt_prop.material: 1, elt_prop.element_shape: 0}]
# assert isinstance(mesh2, post.Mesh)
# assert len(mesh2.node_ids) == 240


def test_meshes_plot(meshes):
Expand Down
Loading