2626 Undefined ,
2727 annotate_type ,
2828)
29- from tidy3d .constants import C_0 , MICROMETER , dp_eps , inf
29+ from tidy3d .constants import C_0 , MICROMETER , dp_eps , fp_eps , inf
3030from tidy3d .exceptions import SetupError
3131from tidy3d .log import log
3232
@@ -1991,16 +1991,33 @@ def _generate_horizontal_snapping_lines(
19911991 return snapping_lines_y , min_gap_width
19921992
19931993 def _resolve_gaps (
1994- self , structures : list [Structure ], grid : Grid , boundaries : tuple , center , size
1994+ self , structures : list [Structure ], grid : Grid , boundary_types : tuple
19951995 ) -> tuple [list [CoordinateOptional ], float ]:
1996- """Detect underresolved gaps and place snapping lines in them. Also return the detected minimal gap width."""
1996+ """
1997+ Detect underresolved gaps and place snapping lines in them. Also return the detected minimal gap width.
1998+
1999+ Parameters
2000+ ----------
2001+ structures : list[Structure]
2002+ List of structures to consider.
2003+ grid : Grid
2004+ Grid to resolve gaps on.
2005+ boundary_types : Tuple[Tuple[str, str], Tuple[str, str], Tuple[str, str]] = [[None, None], [None, None], [None, None]]
2006+ Type of boundary conditions along each dimension: "pec/pmc", "periodic", or
2007+ None for any other. This is relevant only for gap meshing.
2008+
2009+ Returns
2010+ -------
2011+ tuple[list[CoordinateOptional], float]
2012+ List of snapping lines and the detected minimal gap width.
2013+ """
19972014
19982015 # get x and y coordinates of grid lines
19992016 _ , tan_dims = Box .pop_axis ([0 , 1 , 2 ], self .axis )
20002017 x = grid .boundaries .to_list [tan_dims [0 ]]
20012018 y = grid .boundaries .to_list [tan_dims [1 ]]
20022019
2003- _ , boundaries_tan = Box .pop_axis (boundaries , self .axis )
2020+ _ , boundaries_tan = Box .pop_axis (boundary_types , self .axis )
20042021
20052022 # restrict to the size of layer spec
20062023 rmin , rmax = self .bounds
@@ -2036,27 +2053,33 @@ def _resolve_gaps(
20362053
20372054 x , y = new_coords
20382055
2056+ merging_area_bounds = np .array (
2057+ [[x [0 ] - fp_eps , y [0 ] - fp_eps ], [x [- 1 ] + fp_eps , y [- 1 ] + fp_eps ]]
2058+ )
2059+
20392060 # restrict size of the plane where pec polygons are found in case of periodic boundary conditions
20402061 # this is to make sure gaps across periodic boundary conditions are resolved
20412062 # (if there is a PEC structure going into periodic boundary, now it will generate a grid line
20422063 # intersection next to that boundary and it will be propagated to the other side)
2043- restricted_size_tan = [
2044- s * (1.0 - dp_eps ) if b [0 ] == "periodic" else inf
2045- for b , s in zip (
2046- new_boundaries ,
2047- size ,
2048- )
2049- ]
2050- restricted_size = Box .unpop_axis (size [self .axis ], restricted_size_tan , self .axis )
2064+ for ind in range (2 ):
2065+ if new_boundaries [ind ][0 ] == "periodic" :
2066+ merging_area_bounds [0 ][ind ] += fp_eps + dp_eps
2067+ merging_area_bounds [1 ][ind ] -= fp_eps + dp_eps
2068+
2069+ merging_area_center = 0.5 * (merging_area_bounds [0 ] + merging_area_bounds [1 ])
2070+ merging_area_size = merging_area_bounds [1 ] - merging_area_bounds [0 ]
2071+
2072+ merging_area_center = Box .unpop_axis (self .center [self .axis ], merging_area_center , self .axis )
2073+ merging_area_size = Box .unpop_axis (self .size [self .axis ], merging_area_size , self .axis )
20512074
20522075 # get merged pec structures on plane
20532076 # note that we expect this function to also convert all LossyMetal's into PEC
20542077 plane_slice = CornerFinderSpec ._merged_pec_on_plane (
20552078 coord = self .center_axis ,
20562079 normal_axis = self .axis ,
20572080 structure_list = structures ,
2058- center = center ,
2059- size = restricted_size ,
2081+ center = merging_area_center ,
2082+ size = merging_area_size ,
20602083 interior_disjoint_geometries = self .interior_disjoint_geometries ,
20612084 )
20622085
@@ -2635,8 +2658,6 @@ def _make_grid_and_snapping_lines(
26352658 structure_priority_mode = structure_priority_mode ,
26362659 )
26372660
2638- sim_geometry = structures [0 ].geometry
2639-
26402661 snapping_lines = []
26412662 if len (self .layer_refinement_specs ) > 0 :
26422663 num_iters = max (
@@ -2652,8 +2673,6 @@ def _make_grid_and_snapping_lines(
26522673 structures ,
26532674 old_grid ,
26542675 boundary_types ,
2655- center = sim_geometry .center ,
2656- size = sim_geometry .size ,
26572676 )
26582677 new_snapping_lines = new_snapping_lines + one_layer_snapping_lines
26592678 if layer_spec .dl_min_from_gap_width :
0 commit comments