@@ -177,7 +177,29 @@ def check_field_size(failure_label: FailureOutput):
177177 check_field_size (FailureOutput .MAX_SOLID_ELEMENT_ID )
178178
179179
180- def test_assembly_model (dpf_server ):
180+ _MAX_RESERVE_FACTOR = 1000.0
181+
182+
183+ def _get_margin_of_safety_from_irf (irf : float ) -> float :
184+ return _get_reserve_factor_from_irf (irf ) - 1.0
185+
186+
187+ def _get_reserve_factor_from_irf (irf : float ) -> float :
188+ if irf > 0.0 :
189+ return min (1.0 / irf , _MAX_RESERVE_FACTOR )
190+ else :
191+ return _MAX_RESERVE_FACTOR
192+
193+
194+ @pytest .mark .parametrize (
195+ "failure_measure" ,
196+ [
197+ FailureMeasureEnum .INVERSE_RESERVE_FACTOR ,
198+ FailureMeasureEnum .RESERVE_FACTOR ,
199+ FailureMeasureEnum .MARGIN_OF_SAFETY ,
200+ ],
201+ )
202+ def test_assembly_model (dpf_server , failure_measure ):
181203 """Verify the handling of assemblies."""
182204
183205 timer = Timer ()
@@ -201,16 +223,26 @@ def test_assembly_model(dpf_server):
201223 failure_output = composite_model .evaluate_failure_criteria (
202224 combined_criterion = combined_failure_criterion ,
203225 composite_scope = CompositeScope (),
226+ measure = failure_measure ,
204227 )
205228
206229 timer .add ("After get failure output" )
207230
208- def check_output (failure_label : FailureOutput , expected_output : dict [int , float ]):
231+ def check_value_output (failure_label : FailureOutput , expected_output : dict [int , float ]):
209232 for element_id , expected_value in expected_output .items ():
233+ if failure_measure == FailureMeasureEnum .MARGIN_OF_SAFETY :
234+ expected_value = _get_margin_of_safety_from_irf (expected_value )
235+ elif failure_measure == FailureMeasureEnum .RESERVE_FACTOR :
236+ expected_value = _get_reserve_factor_from_irf (expected_value )
210237 failure_field = failure_output .get_field ({FAILURE_LABEL : failure_label })
211238 assert failure_field .get_entity_data_by_id (element_id ) == pytest .approx (expected_value )
212239
213- expected_output = {
240+ def check_mode_or_layer_output (failure_label : FailureOutput , expected_output : dict [int , float ]):
241+ for element_id , expected_value in expected_output .items ():
242+ failure_field = failure_output .get_field ({FAILURE_LABEL : failure_label })
243+ assert failure_field .get_entity_data_by_id (element_id ) == pytest .approx (expected_value )
244+
245+ expected_irf_output = {
214246 1 : 1.11311715 ,
215247 2 : 1.11311715 ,
216248 5 : 1.85777034 ,
@@ -220,7 +252,7 @@ def check_output(failure_label: FailureOutput, expected_output: dict[int, float]
220252 9 : 0.62122959 ,
221253 10 : 0.62122959 ,
222254 }
223- check_output (FailureOutput .FAILURE_VALUE , expected_output )
255+ check_value_output (FailureOutput .FAILURE_VALUE , expected_irf_output )
224256
225257 expected_modes = {
226258 1 : FailureModeEnum .s1t .value ,
@@ -232,7 +264,7 @@ def check_output(failure_label: FailureOutput, expected_output: dict[int, float]
232264 9 : FailureModeEnum .s2t .value ,
233265 10 : FailureModeEnum .s2t .value ,
234266 }
235- check_output (FailureOutput .FAILURE_MODE , expected_modes )
267+ check_mode_or_layer_output (FailureOutput .FAILURE_MODE , expected_modes )
236268
237269 expected_layer_index = {
238270 1 : 2 ,
@@ -251,41 +283,47 @@ def check_output(failure_label: FailureOutput, expected_output: dict[int, float]
251283 # at 0 instead of 1
252284 expected_layer_index [element_id ] -= 1
253285
254- check_output (FailureOutput .MAX_LAYER_INDEX , expected_layer_index )
286+ check_mode_or_layer_output (FailureOutput .MAX_LAYER_INDEX , expected_layer_index )
255287
256- expected_output_ref_surface = {
288+ expected_output_irf_ref_surface = {
257289 1 : 1.85777034 ,
258290 2 : 1.85777034 ,
259291 3 : 1.11311715 ,
260292 4 : 1.11311715 ,
261293 }
262294
263295 if version_equal_or_later (dpf_server , "8.0" ):
264- check_output (FailureOutput .FAILURE_VALUE_REF_SURFACE , expected_output_ref_surface )
296+ check_value_output (FailureOutput .FAILURE_VALUE_REF_SURFACE , expected_output_irf_ref_surface )
265297
266298 expected_output_local_layer = {
267299 1 : 2 ,
268300 2 : 2 ,
269301 3 : 2 ,
270302 4 : 2 ,
271303 }
272- check_output (FailureOutput .MAX_LOCAL_LAYER_IN_ELEMENT , expected_output_local_layer )
304+ check_mode_or_layer_output (
305+ FailureOutput .MAX_LOCAL_LAYER_IN_ELEMENT , expected_output_local_layer
306+ )
273307
274308 expected_output_global_layer = {
275309 1 : 2 ,
276310 2 : 2 ,
277311 3 : 2 ,
278312 4 : 2 ,
279313 }
280- check_output (FailureOutput .MAX_GLOBAL_LAYER_IN_STACK , expected_output_global_layer )
314+ check_mode_or_layer_output (
315+ FailureOutput .MAX_GLOBAL_LAYER_IN_STACK , expected_output_global_layer
316+ )
281317
282318 expected_output_solid_element = {
283319 1 : 5 ,
284320 2 : 6 ,
285321 3 : 1 ,
286322 4 : 2 ,
287323 }
288- check_output (FailureOutput .MAX_SOLID_ELEMENT_ID , expected_output_solid_element )
324+ check_mode_or_layer_output (
325+ FailureOutput .MAX_SOLID_ELEMENT_ID , expected_output_solid_element
326+ )
289327
290328 property_dict = composite_model .get_constant_property_dict (
291329 [MaterialProperty .Stress_Limits_Xt ], composite_definition_label = solid_label
0 commit comments