Skip to content

Commit

Permalink
Merge branch 'main' into maint/update_supported_python
Browse files Browse the repository at this point in the history
  • Loading branch information
janvonrickenbach authored Oct 9, 2023
2 parents ce41fa4 + 3831fed commit cb3c0a9
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 17 deletions.
67 changes: 51 additions & 16 deletions tests/composite_model_scoping_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,8 @@ def test_composite_model_named_selection_scope(dpf_server, data_files, distribut
failure_container = composite_model.evaluate_failure_criteria(cfc, scope)
irfs = failure_container.get_field({"failure_label": FailureOutput.FAILURE_VALUE})
assert len(irfs.data) == 2
assert irfs.data[0] == pytest.approx(1.4792790331384016, 1e-8)
assert irfs.data[1] == pytest.approx(1.3673715033617213, 1e-8)
assert irfs.get_entity_data_by_id(2) == pytest.approx(1.4792790331384016, 1e-8)
assert irfs.get_entity_data_by_id(3) == pytest.approx(1.3673715033617213, 1e-8)


def test_composite_model_ply_scope(dpf_server):
Expand Down Expand Up @@ -102,21 +102,50 @@ def test_composite_model_ply_scope(dpf_server):
if version_older_than(dpf_server, "7.0"):
# the old implementation did not allow to distinguish between plies of the different parts.
# So both plies select the shell and solid elements.
expected_irfs_by_element_id = {
1: 0.66603946,
2: 0.66603946,
7: 3.24925826,
8: 3.24925826,
9: 0.52981576,
10: 0.52981576,
}

expected_modes_by_element_id = {1: 310.0, 2: 310.0, 7: 310.0, 8: 310.0, 9: 212.0, 10: 222.0}
assert len(irfs.data) == 6
assert irfs.data == pytest.approx(
np.array([0.66603946, 0.66603946, 3.24925826, 0.52981576, 3.24925826, 0.52981576]),
abs=1e-3,
)
assert modes.data == pytest.approx(
np.array([310.0, 310.0, 310.0, 222.0, 310.0, 212.0]), abs=0.1
)
for element_id in irfs.scoping.ids:
assert expected_irfs_by_element_id[element_id] == pytest.approx(
irfs.get_entity_data_by_id(element_id), abs=1e-3
)
assert expected_modes_by_element_id[element_id] == pytest.approx(
modes.get_entity_data_by_id(element_id), abs=0.1
)

else:
# ply scoping is now part specific thanks to the labels
assert len(irfs.data) == 4
assert irfs.data == pytest.approx(
np.array([0.14762838, 0.14762838, 3.24925826, 3.24925826]), abs=1e-3
)
assert modes.data == pytest.approx(np.array([222, 212, 310, 310]), abs=0.1)

expected_irfs_by_element_id = {
1: 0.14762838,
2: 0.14762838,
7: 3.24925826,
8: 3.24925826,
}

expected_modes_by_element_id = {
1: 222,
2: 212,
7: 310,
8: 310,
}

for element_id in irfs.scoping.ids:
assert irfs.get_entity_data_by_id(element_id) == pytest.approx(
expected_irfs_by_element_id[element_id], abs=1e-3
)
assert modes.get_entity_data_by_id(element_id) == pytest.approx(
expected_modes_by_element_id[element_id], abs=1e-1
)


def test_composite_model_named_selection_and_ply_scope(dpf_server, data_files, distributed_rst):
Expand Down Expand Up @@ -147,8 +176,15 @@ def test_composite_model_named_selection_and_ply_scope(dpf_server, data_files, d
modes = failure_container.get_field({"failure_label": FailureOutput.FAILURE_MODE})
assert len(irfs.data) == 2
assert len(modes.data) == 2
assert irfs.data == pytest.approx(np.array([0.49282684, 0.32568454]), abs=1e-3)
assert modes.data == pytest.approx(np.array([222.0, 222.0]), abs=1e-1)
expected_irfs_by_id = {2: 0.49282684, 3: 0.32568454}
expected_modes_by_id = {2: 222.0, 3: 222.0}
for element_id in irfs.scoping.ids:
assert irfs.get_entity_data_by_id(element_id) == pytest.approx(
expected_irfs_by_id[element_id], abs=1e-3
)
assert modes.get_entity_data_by_id(element_id) == pytest.approx(
expected_modes_by_id[element_id], abs=1e-1
)


def test_composite_model_time_scope(dpf_server):
Expand All @@ -173,6 +209,5 @@ def test_composite_model_time_scope(dpf_server):
scope = CompositeScope(time=time)
failure_container = composite_model.evaluate_failure_criteria(cfc, scope)
irfs = failure_container.get_field({"failure_label": FailureOutput.FAILURE_VALUE})
modes = failure_container.get_field({"failure_label": FailureOutput.FAILURE_MODE})
assert len(irfs.data) == 4
assert max(irfs.data) == pytest.approx(expected_max_irf, abs=1e-6)
2 changes: 1 addition & 1 deletion tests/composite_model_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ def test_assembly_model(dpf_server):
composite_model = CompositeModel(files, server=dpf_server)
timer.add("After Setup model")

assert composite_model.composite_definition_labels == [solid_label, shell_label]
assert sorted(composite_model.composite_definition_labels) == sorted([solid_label, shell_label])

combined_failure_criterion = CombinedFailureCriterion(
"max strain & max stress", failure_criteria=[MaxStressCriterion()]
Expand Down

0 comments on commit cb3c0a9

Please sign in to comment.