@@ -290,3 +290,48 @@ def test_max_geometry_validation():
290
290
]
291
291
with pytest .raises (pd .ValidationError , match = f" { MAX_GEOMETRY_COUNT + 2 } " ):
292
292
_ = td .Scene (structures = not_fine )
293
+
294
+
295
+ def test_structure_manual_priority ():
296
+ """make sure structure is properly orderd based on the priority settings."""
297
+
298
+ box = td .Structure (
299
+ geometry = td .Box (size = (1 , 1 , 1 ), center = (0 , 0 , 0 )),
300
+ medium = td .Medium (permittivity = 2.0 ),
301
+ )
302
+ structures = []
303
+ priorities = [2 , 4 , - 1 , - 4 , 0 ]
304
+ for priority in priorities :
305
+ structures .append (box .updated_copy (priority = priority ))
306
+ scene = td .Scene (
307
+ structures = structures ,
308
+ )
309
+
310
+ sorted_priorities = [s .priority for s in scene .sorted_structures ]
311
+ assert all (np .diff (sorted_priorities ) >= 0 )
312
+
313
+
314
+ def test_structure_automatic_priority ():
315
+ """make sure metallic structure has the highest priority in `conductor` mode."""
316
+
317
+ box = td .Structure (
318
+ geometry = td .Box (size = (1 , 1 , 1 ), center = (0 , 0 , 0 )),
319
+ medium = td .Medium (permittivity = 2.0 ),
320
+ )
321
+ box_pec = box .updated_copy (medium = td .PEC )
322
+ box_lossymetal = box .updated_copy (
323
+ medium = td .LossyMetalMedium (conductivity = 1.0 , frequency_range = (1e14 , 2e14 ))
324
+ )
325
+ structures = [box_pec , box_lossymetal , box ]
326
+ scene = td .Scene (
327
+ structures = structures ,
328
+ structure_priority_mode = "equal" ,
329
+ )
330
+
331
+ # in equal mode, the order is preserved
332
+ scene .sorted_structures == structures
333
+
334
+ # conductor mode
335
+ scene = scene .updated_copy (structure_priority_mode = "conductor" )
336
+ assert scene .sorted_structures [- 1 ].medium == td .PEC
337
+ assert isinstance (scene .sorted_structures [- 2 ].medium , td .LossyMetalMedium )
0 commit comments