@@ -209,13 +209,15 @@ def bounding_box_from_shapely(geom: Shapely) -> Box:
209209 min_b_3d , max_b_3d = self ._get_mode_limits (grid , mode_symmetry_3d )
210210
211211 intersection_plane = Box .from_bounds (min_b_3d , max_b_3d )
212- conductor_shapely = self ._get_isolated_conductors_as_shapely (intersection_plane , structures )
212+ isolated_conductor_shapely = self ._get_isolated_conductors_as_shapely (
213+ intersection_plane , structures
214+ )
213215
214- conductor_shapely = self ._filter_conductors_touching_sim_bounds (
215- (min_b_3d , max_b_3d ), mode_symmetry_3d , conductor_shapely
216+ filtered_conductor_shapely = self ._filter_conductors_touching_sim_bounds (
217+ (min_b_3d , max_b_3d ), mode_symmetry_3d , isolated_conductor_shapely
216218 )
217219
218- if len (conductor_shapely ) < 1 :
220+ if len (filtered_conductor_shapely ) < 1 :
219221 raise SetupError (
220222 "No valid isolated conductors were found in the mode plane. Please ensure that a 'Structure' "
221223 "with a medium of type 'PEC' or 'LossyMetalMedium' intersects the mode plane and is not touching "
@@ -228,23 +230,39 @@ def bounding_box_from_shapely(geom: Shapely) -> Box:
228230 snap_spec = self ._snap_spec
229231
230232 bounding_boxes = []
231- for shape in conductor_shapely :
233+ for shape in filtered_conductor_shapely :
232234 box = bounding_box_from_shapely (shape )
233235 boxes = self ._apply_symmetries (symmetry , sim_box .center , box )
234236 for box in boxes :
235237 box_snapped = snap_box_to_grid (grid , box , snap_spec )
236238 bounding_boxes .append (box_snapped )
237239
240+ # TODO Improve these checks once FXC-4112-PEC-boundary-position-not-respected-by-ModeSolver is merged
238241 for bounding_box in bounding_boxes :
239- if self ._check_box_intersects_with_conductors (conductor_shapely , bounding_box ):
242+ if self ._check_box_intersects_with_conductors (isolated_conductor_shapely , bounding_box ):
240243 raise SetupError (
241244 "Failed to automatically generate path specification because a generated path "
242245 "specification was found to intersect with a conductor. There is currently limited "
243246 "support for complex conductor geometries, so please provide an explicit current "
244247 "path specification through a 'CustomImpedanceSpec'. Alternatively, enforce a "
245248 "smaller grid around the conductors in the mode plane, which may resolve the issue."
246249 )
247- return bounding_boxes , conductor_shapely
250+
251+ # Check that bounding boxes don't extend outside the original mode plane bounds
252+ mode_plane_min , mode_plane_max = self .bounds
253+ for bounding_box in bounding_boxes :
254+ box_min , box_max = bounding_box .bounds
255+ if any (box_min [i ] < mode_plane_min [i ] for i in range (3 )) or any (
256+ box_max [i ] > mode_plane_max [i ] for i in range (3 )
257+ ):
258+ raise SetupError (
259+ "Failed to automatically generate path specification because a generated path "
260+ "specification extends outside the mode solving plane bounds. This issue can be fixed "
261+ "by enlarging the mode solving plane and ensuring that there is a buffer of at "
262+ "least 2 grid cells between the mode solving plane bounds and the nearest conductors."
263+ )
264+
265+ return bounding_boxes , filtered_conductor_shapely
248266
249267 def _check_box_intersects_with_conductors (
250268 self , shapely_list : list [Shapely ], bounding_box : Box
0 commit comments