2626import pytest
2727
2828from ansys .dpf .composites .composite_model import CompositeModel , CompositeScope
29- from ansys .dpf .composites .constants import FailureOutput
29+ from ansys .dpf .composites .constants import FAILURE_LABEL , FailureOutput
3030from ansys .dpf .composites .data_sources import get_composite_files_from_workbench_result_folder
3131from ansys .dpf .composites .failure_criteria import (
3232 CombinedFailureCriterion ,
3535 MaxStressCriterion ,
3636)
3737from ansys .dpf .composites .layup_info import get_all_analysis_ply_names
38- from ansys .dpf .composites .server_helpers ._versions import version_older_than
38+ from ansys .dpf .composites .server_helpers ._versions import version_equal_or_later , version_older_than
3939
4040from .helper import get_basic_shell_files
4141
@@ -49,13 +49,13 @@ def test_composite_model_element_scope(dpf_server, data_files):
4949
5050 composite_scope = CompositeScope (elements = [1 , 3 ])
5151 failure_container = composite_model .evaluate_failure_criteria (cfc , composite_scope )
52- irfs = failure_container .get_field ({"failure_label" : FailureOutput .FAILURE_VALUE })
52+ irfs = failure_container .get_field ({FAILURE_LABEL : FailureOutput .FAILURE_VALUE })
5353 min_id = irfs .scoping .ids [np .argmin (irfs .data )]
5454 max_id = irfs .scoping .ids [np .argmax (irfs .data )]
5555
5656 composite_scope = CompositeScope (elements = [min_id , max_id ])
5757 max_container = composite_model .evaluate_failure_criteria (cfc , composite_scope )
58- max_irfs = max_container .get_field ({"failure_label" : FailureOutput .FAILURE_VALUE })
58+ max_irfs = max_container .get_field ({FAILURE_LABEL : FailureOutput .FAILURE_VALUE })
5959 assert len (max_irfs .data ) == 2
6060 assert max_irfs .get_entity_data_by_id (min_id )[0 ] == pytest .approx (min (irfs .data ), 1e-8 )
6161 assert max_irfs .get_entity_data_by_id (max_id )[0 ] == pytest .approx (max (irfs .data ), 1e-8 )
@@ -78,7 +78,7 @@ def test_composite_model_named_selection_scope(dpf_server, data_files, distribut
7878
7979 scope = CompositeScope (named_selections = [ns_name ])
8080 failure_container = composite_model .evaluate_failure_criteria (cfc , scope )
81- irfs = failure_container .get_field ({"failure_label" : FailureOutput .FAILURE_VALUE })
81+ irfs = failure_container .get_field ({FAILURE_LABEL : FailureOutput .FAILURE_VALUE })
8282 assert len (irfs .data ) == 2
8383 assert irfs .get_entity_data_by_id (2 ) == pytest .approx (1.4792790331384016 , 1e-8 )
8484 assert irfs .get_entity_data_by_id (3 ) == pytest .approx (1.3673715033617213 , 1e-8 )
@@ -118,8 +118,8 @@ def test_composite_model_ply_scope(dpf_server):
118118
119119 scope = CompositeScope (plies = ply_ids )
120120 failure_container = composite_model .evaluate_failure_criteria (cfc , scope )
121- irfs = failure_container .get_field ({"failure_label" : FailureOutput .FAILURE_VALUE })
122- modes = failure_container .get_field ({"failure_label" : FailureOutput .FAILURE_MODE })
121+ irfs = failure_container .get_field ({FAILURE_LABEL : FailureOutput .FAILURE_VALUE })
122+ modes = failure_container .get_field ({FAILURE_LABEL : FailureOutput .FAILURE_MODE })
123123
124124 if version_older_than (dpf_server , "7.0" ):
125125 # the old implementation did not allow to distinguish between plies of the different parts.
@@ -194,8 +194,8 @@ def test_composite_model_named_selection_and_ply_scope(dpf_server, data_files, d
194194
195195 scope = CompositeScope (named_selections = [ns_name ], plies = ply_ids )
196196 failure_container = composite_model .evaluate_failure_criteria (cfc , scope )
197- irfs = failure_container .get_field ({"failure_label" : FailureOutput .FAILURE_VALUE })
198- modes = failure_container .get_field ({"failure_label" : FailureOutput .FAILURE_MODE })
197+ irfs = failure_container .get_field ({FAILURE_LABEL : FailureOutput .FAILURE_VALUE })
198+ modes = failure_container .get_field ({FAILURE_LABEL : FailureOutput .FAILURE_MODE })
199199 assert len (irfs .data ) == 2
200200 assert len (modes .data ) == 2
201201 expected_irfs_by_id = {2 : 0.49282684 , 3 : 0.32568454 }
@@ -230,6 +230,53 @@ def test_composite_model_time_scope(dpf_server):
230230 for time , expected_max_irf in time_id_and_expected_max_irf .items ():
231231 scope = CompositeScope (time = time )
232232 failure_container = composite_model .evaluate_failure_criteria (cfc , scope )
233- irfs = failure_container .get_field ({"failure_label" : FailureOutput .FAILURE_VALUE })
233+ irfs = failure_container .get_field ({FAILURE_LABEL : FailureOutput .FAILURE_VALUE })
234234 assert len (irfs .data ) == 4
235235 assert max (irfs .data ) == pytest .approx (expected_max_irf , abs = 1e-6 )
236+
237+
238+ def test_ply_wise_scoping_in_assembly_with_imported_solid_model (dpf_server ):
239+ """Ensure that the ply-wise scoping works in combination with the reference surface plot."""
240+ if version_older_than (dpf_server , "8.0" ):
241+ pytest .xfail ("Not supported because of limitations in the handling of assemblies." )
242+
243+ result_folder = pathlib .Path (__file__ ).parent / "data" / "assembly_imported_solid_model"
244+ composite_files = get_composite_files_from_workbench_result_folder (result_folder )
245+
246+ # Create a composite model
247+ composite_model = CompositeModel (composite_files , dpf_server )
248+
249+ plies = [
250+ "Setup 2_shell::P1L1__ModelingPly.2" ,
251+ "Setup_solid::P1L1__ModelingPly.2" ,
252+ "Setup 3_solid::P1L1__ModelingPly.1" ,
253+ ]
254+
255+ # Evaluate combined failure criterion
256+ combined_failure_criterion = CombinedFailureCriterion (failure_criteria = [MaxStressCriterion ()])
257+ failure_result = composite_model .evaluate_failure_criteria (
258+ combined_criterion = combined_failure_criterion , composite_scope = CompositeScope (plies = plies )
259+ )
260+
261+ # check the on reference surface data
262+ for failure_output in [
263+ FailureOutput .FAILURE_VALUE_REF_SURFACE ,
264+ FailureOutput .FAILURE_MODE_REF_SURFACE ,
265+ FailureOutput .MAX_GLOBAL_LAYER_IN_STACK ,
266+ FailureOutput .MAX_LOCAL_LAYER_IN_ELEMENT ,
267+ FailureOutput .MAX_SOLID_ELEMENT_ID ,
268+ ]:
269+ field = failure_result .get_field ({FAILURE_LABEL : failure_output })
270+
271+ if version_equal_or_later (dpf_server , "9.0" ):
272+ assert field .size == 21
273+ elif version_equal_or_later (dpf_server , "8.0" ):
274+ # Servers of the 2024 R2 series do not extract the reference surface
275+ # of imported solid models. So the reference surface mesh
276+ # contains only the shell elements and reference surface of the
277+ # standard solid model.
278+ assert field .size == 12
279+ else :
280+ # Servers before 8.0 are not tested because of several limitations:
281+ # handling of assemblies, reference surface not supported
282+ assert False
0 commit comments