@@ -326,4 +326,62 @@ def test_grid_refinement():
326326 )
327327
328328
329- # # print(max_shrink)
329+ def test_parse_structures ():
330+ """Test some aspects of the structure parsing."""
331+
332+ source = td .PointDipole (
333+ source_time = td .GaussianPulse (freq0 = 1e14 , fwidth = 1e13 ),
334+ size = (0 , 0 , 0 ),
335+ polarization = "Ex" ,
336+ )
337+
338+ box1 = td .Structure (
339+ geometry = td .Box (center = (0 , 0 , 0 ), size = (2 , 2 , 2 )), medium = td .Medium (permittivity = 9 )
340+ )
341+ # covers box1 along x and y but not z, smaller permittivity
342+ box2 = td .Structure (
343+ geometry = td .Box (center = (0 , 0 , 0 ), size = (200 , 200 , 1 )), medium = td .Medium (permittivity = 4 )
344+ )
345+ # covers box1 along x only, smaller permittivity
346+ box3 = td .Structure (
347+ geometry = td .Box (center = (0 , 1.5 , 0 ), size = (200 , 4 , 1 )), medium = td .Medium (permittivity = 4 )
348+ )
349+ # fully covers one edge of box1
350+ box4 = td .Structure (
351+ geometry = td .Box (center = (0 , 1.01 , 0 ), size = (200 , 0.2 , 2 )), medium = td .Medium (permittivity = 2 )
352+ )
353+
354+ # Test that the box2 permittivity is used along z in the region where it fully covers box1
355+ sim = td .Simulation (
356+ size = (3 , 3 , 3 ),
357+ grid_spec = td .GridSpec .auto (),
358+ run_time = 1e-13 ,
359+ structures = [box1 , box2 ],
360+ sources = [source ],
361+ )
362+ sizes = sim .grid .sizes .to_list [2 ]
363+ assert sizes [sizes .size // 2 ] > 0.1
364+
365+ # Test that the box3 permittivity is not used along z as it doesn't fully cover box1
366+ sim = td .Simulation (
367+ size = (3 , 3 , 3 ),
368+ grid_spec = td .GridSpec .auto (),
369+ run_time = 1e-13 ,
370+ structures = [box1 , box3 ],
371+ sources = [source ],
372+ )
373+ sizes = sim .grid .sizes .to_list [2 ]
374+ assert sizes [sizes .size // 2 ] < 0.1
375+
376+ # Test that there is no grid boundary along y at the box1 right side covered by box4
377+ boundaries = sim .grid .boundaries .to_list [1 ]
378+ assert 1.0 in boundaries
379+ sim = td .Simulation (
380+ size = (3 , 3 , 3 ),
381+ grid_spec = td .GridSpec .auto (),
382+ run_time = 1e-13 ,
383+ structures = [box1 , box4 ],
384+ sources = [source ],
385+ )
386+ boundaries = sim .grid .boundaries .to_list [1 ]
387+ assert 1.0 not in boundaries
0 commit comments