Skip to content

Commit

Permalink
Check version in test
Browse files Browse the repository at this point in the history
  • Loading branch information
janvonrickenbach committed Nov 20, 2023
1 parent c65eeb4 commit 40b3965
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 30 deletions.
15 changes: 10 additions & 5 deletions examples/008_assembly_example.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,11 @@
from ansys.dpf.composites.constants import FailureOutput
from ansys.dpf.composites.example_helper import get_continuous_fiber_example_files
from ansys.dpf.composites.failure_criteria import CombinedFailureCriterion, MaxStressCriterion
from ansys.dpf.composites.server_helpers import connect_to_or_start_server, version_older_than
from ansys.dpf.composites.server_helpers import (
connect_to_or_start_server,
version_equal_or_later,
version_older_than,
)

# %%
# Start a DPF server and copy the example files into the current working directory.
Expand Down Expand Up @@ -56,10 +60,11 @@
# Plot IRF
# ~~~~~~~~
# Plot the maximum IRF on the reference surface
irf_field = output_all_elements.get_field(
{"failure_label": FailureOutput.FAILURE_VALUE_REF_SURFACE}
)
irf_field.plot()
if version_equal_or_later(server, "7.1"):
irf_field = output_all_elements.get_field(
{"failure_label": FailureOutput.FAILURE_VALUE_REF_SURFACE}
)
irf_field.plot()


# %%
Expand Down
64 changes: 39 additions & 25 deletions tests/composite_model_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -129,11 +129,23 @@ def test_model_with_multiple_timesteps(dpf_server):
)

# Note evaluate_failure_criteria supports only a single time step
irf_field = failure_output.get_field({"failure_label": FailureOutput.FAILURE_VALUE})
irf_field = failure_output.get_field({FAILURE_LABEL: FailureOutput.FAILURE_VALUE})

for element_id, expected_value in expected_data_by_time_index[time_index].items():
assert irf_field.get_entity_data_by_id(element_id) == pytest.approx(expected_value)

# Just check that the other fields are available
def check_field_size(failure_label: FailureOutput):
field = failure_output.get_field({FAILURE_LABEL: failure_label})
assert len(field.scoping.ids) == 4

check_field_size(FailureOutput.FAILURE_MODE)
check_field_size(FailureOutput.FAILURE_MODE_REF_SURFACE)
check_field_size(FailureOutput.MAX_LAYER_INDEX)
check_field_size(FailureOutput.MAX_GLOBAL_LAYER_IN_STACK)
check_field_size(FailureOutput.MAX_LOCAL_LAYER_IN_ELEMENT)
check_field_size(FailureOutput.MAX_SOLID_ELEMENT_ID)


def test_assembly_model(dpf_server):
"""Verify the handling of assemblies."""
Expand Down Expand Up @@ -210,31 +222,33 @@ def check_output(failure_label: FailureOutput, expected_output: dict[int, float]
3: 1.11311715,
4: 1.11311715,
}
check_output(FailureOutput.FAILURE_VALUE_REF_SURFACE, expected_output_ref_surface)

expected_output_local_layer = {
1: 2,
2: 2,
3: 2,
4: 2,
}
check_output(FailureOutput.MAX_LOCAL_LAYER_IN_ELEMENT, expected_output_local_layer)

expected_output_global_layer = {
1: 2,
2: 2,
3: 2,
4: 2,
}
check_output(FailureOutput.MAX_GLOBAL_LAYER_IN_STACK, expected_output_global_layer)

expected_output_solid_element = {
1: 5,
2: 6,
3: 1,
4: 2,
}
check_output(FailureOutput.MAX_SOLID_ELEMENT_ID, expected_output_solid_element)
if version_equal_or_later(dpf_server, "7.1"):
check_output(FailureOutput.FAILURE_VALUE_REF_SURFACE, expected_output_ref_surface)

expected_output_local_layer = {
1: 2,
2: 2,
3: 2,
4: 2,
}
check_output(FailureOutput.MAX_LOCAL_LAYER_IN_ELEMENT, expected_output_local_layer)

expected_output_global_layer = {
1: 2,
2: 2,
3: 2,
4: 2,
}
check_output(FailureOutput.MAX_GLOBAL_LAYER_IN_STACK, expected_output_global_layer)

expected_output_solid_element = {
1: 5,
2: 6,
3: 1,
4: 2,
}
check_output(FailureOutput.MAX_SOLID_ELEMENT_ID, expected_output_solid_element)

property_dict = composite_model.get_constant_property_dict(
[MaterialProperty.Stress_Limits_Xt], composite_definition_label=solid_label
Expand Down

0 comments on commit 40b3965

Please sign in to comment.