@@ -1226,8 +1226,8 @@ def center_axis(self) -> float:
1226
1226
1227
1227
@cached_property
1228
1228
def _is_inplane_unbounded (self ) -> bool :
1229
- """Whether the layer is unbounded in inplane dimensions."""
1230
- return np .isinf (self .size [(self .axis + 1 ) % 3 ]) and np .isinf (self .size [(self .axis + 2 ) % 3 ])
1229
+ """Whether the layer is unbounded in any of the inplane dimensions."""
1230
+ return np .isinf (self .size [(self .axis + 1 ) % 3 ]) or np .isinf (self .size [(self .axis + 2 ) % 3 ])
1231
1231
1232
1232
def _unpop_axis (self , ax_coord : float , plane_coord : Any ) -> CoordinateOptional :
1233
1233
"""Combine coordinate along axis with identical coordinates on the plane tangential to the axis.
@@ -1318,7 +1318,14 @@ def _corners(self, structure_list: List[Structure]) -> List[CoordinateOptional]:
1318
1318
if self .corner_finder is None :
1319
1319
return []
1320
1320
1321
- inplane_points = self .corner_finder .corners (self .axis , self .center_axis , structure_list )
1321
+ # filter structures outside the layer
1322
+ structures_intersect = structure_list
1323
+ if not self ._is_inplane_unbounded :
1324
+ structures_intersect = [s for s in structure_list if self .intersects (s .geometry )]
1325
+ inplane_points = self .corner_finder .corners (
1326
+ self .axis , self .center_axis , structures_intersect
1327
+ )
1328
+
1322
1329
# filter corners outside the inplane bounds
1323
1330
if not self ._is_inplane_unbounded :
1324
1331
inplane_points = [point for point in inplane_points if self ._inplane_inside (point )]
@@ -1625,22 +1632,30 @@ def internal_snapping_points(self, structures: List[Structure]) -> List[Coordina
1625
1632
snapping_points += layer_spec .generate_snapping_points (list (structures ))
1626
1633
return snapping_points
1627
1634
1628
- def all_snapping_points (self , structures : List [Structure ]) -> List [CoordinateOptional ]:
1635
+ def all_snapping_points (
1636
+ self ,
1637
+ structures : List [Structure ],
1638
+ internal_snapping_points : List [CoordinateOptional ] = None ,
1639
+ ) -> List [CoordinateOptional ]:
1629
1640
"""Internal and external snapping points. External snapping points take higher priority.
1630
1641
So far, internal snapping points are generated by `layer_refinement_specs`.
1631
1642
1632
1643
Parameters
1633
1644
----------
1634
1645
structures : List[Structure]
1635
1646
List of physical structures.
1647
+ internal_snapping_points : List[CoordinateOptional]
1648
+ If `None`, recomputes internal snapping points.
1636
1649
1637
1650
Returns
1638
1651
-------
1639
1652
List[CoordinateOptional]
1640
1653
List of snapping points coordinates.
1641
1654
"""
1642
1655
1643
- return self .internal_snapping_points (structures ) + list (self .snapping_points )
1656
+ if internal_snapping_points is None :
1657
+ return self .internal_snapping_points (structures ) + list (self .snapping_points )
1658
+ return internal_snapping_points + list (self .snapping_points )
1644
1659
1645
1660
@property
1646
1661
def external_override_structures (self ) -> List [StructureType ]:
@@ -1677,7 +1692,11 @@ def internal_override_structures(
1677
1692
return override_structures
1678
1693
1679
1694
def all_override_structures (
1680
- self , structures : List [Structure ], wavelength : pd .PositiveFloat , sim_size : Tuple [float , 3 ]
1695
+ self ,
1696
+ structures : List [Structure ],
1697
+ wavelength : pd .PositiveFloat ,
1698
+ sim_size : Tuple [float , 3 ],
1699
+ internal_override_structures : List [MeshOverrideStructure ] = None ,
1681
1700
) -> List [StructureType ]:
1682
1701
"""Internal and external mesh override structures. External override structures take higher priority.
1683
1702
So far, internal override structures all come from `layer_refinement_specs`.
@@ -1688,17 +1707,22 @@ def all_override_structures(
1688
1707
List of structures, with the simulation structure being the first item.
1689
1708
wavelength : pd.PositiveFloat
1690
1709
Wavelength to use for minimal step size in vaccum.
1710
+ internal_override_structures : List[MeshOverrideStructure]
1711
+ If `None`, recomputes internal override structures.
1691
1712
1692
1713
Returns
1693
1714
-------
1694
1715
List[StructureType]
1695
1716
List of override structures.
1696
1717
"""
1697
1718
1698
- return (
1699
- self .internal_override_structures (structures , wavelength , sim_size )
1700
- + self .external_override_structures
1701
- )
1719
+ if internal_override_structures is None :
1720
+ return (
1721
+ self .internal_override_structures (structures , wavelength , sim_size )
1722
+ + self .external_override_structures
1723
+ )
1724
+
1725
+ return internal_override_structures + self .external_override_structures
1702
1726
1703
1727
def _min_vacuum_dl_in_autogrid (self , wavelength : float , sim_size : Tuple [float , 3 ]) -> float :
1704
1728
"""Compute grid step size in vacuum for Autogrd. If AutoGrid is applied along more than 1 dimension,
@@ -1757,6 +1781,8 @@ def make_grid(
1757
1781
periodic : Tuple [bool , bool , bool ],
1758
1782
sources : List [SourceType ],
1759
1783
num_pml_layers : List [Tuple [pd .NonNegativeInt , pd .NonNegativeInt ]],
1784
+ internal_override_structures : List [MeshOverrideStructure ] = None ,
1785
+ internal_snapping_points : List [CoordinateOptional ] = None ,
1760
1786
) -> Grid :
1761
1787
"""Make the entire simulation grid based on some simulation parameters.
1762
1788
@@ -1772,6 +1798,10 @@ def make_grid(
1772
1798
List of sources.
1773
1799
num_pml_layers : List[Tuple[float, float]]
1774
1800
List containing the number of absorber layers in - and + boundaries.
1801
+ internal_override_structures : List[MeshOverrideStructure]
1802
+ If `None`, recomputes internal override structures.
1803
+ internal_snapping_points : List[CoordinateOptional]
1804
+ If `None`, recomputes internal snapping points.
1775
1805
1776
1806
Returns
1777
1807
-------
@@ -1830,7 +1860,10 @@ def make_grid(
1830
1860
1831
1861
sim_size = list (structures [0 ].geometry .size )
1832
1862
all_structures = list (structures ) + self .all_override_structures (
1833
- list (structures ), wavelength , sim_size
1863
+ list (structures ),
1864
+ wavelength ,
1865
+ sim_size ,
1866
+ internal_override_structures ,
1834
1867
)
1835
1868
1836
1869
# apply internal `dl_min` if any AutoGrid has unset `dl_min`
@@ -1856,7 +1889,7 @@ def make_grid(
1856
1889
periodic = periodic [idim ],
1857
1890
wavelength = wavelength ,
1858
1891
num_pml_layers = num_pml_layers [idim ],
1859
- snapping_points = self .all_snapping_points (structures ),
1892
+ snapping_points = self .all_snapping_points (structures , internal_snapping_points ),
1860
1893
)
1861
1894
1862
1895
coords = Coords (** coords_dict )
0 commit comments