Skip to content

Gap automeshing #2390

New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Open
wants to merge 4 commits into
base: daniil/min_size_autodetect
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
86 changes: 86 additions & 0 deletions tests/test_components/test_layerrefinement.py
Original file line number Diff line number Diff line change
Expand Up @@ -402,3 +402,89 @@ def test_dl_min_from_smallest_feature():
)

_ = sim.grid


def test_gap_meshing():
w = 1
l = 10

l_shape_1 = td.Structure(
medium=td.PECMedium(),
geometry=td.PolySlab(
axis=2,
slab_bounds=[0, 2],
vertices=[
[0, 0],
[l, 0],
[l, w],
[w, w],
[w, l],
[0, l],
],
),
)

gap = 0.1
l_shape_2 = td.Structure(
medium=td.PECMedium(),
geometry=td.PolySlab(
axis=2,
slab_bounds=[0, 2],
vertices=[
[w + gap, w + gap],
[w + gap + l, w + gap],
[w + gap + l, w + gap + w],
[w + gap + w, w + gap + w],
[w + gap + w, w + gap + l],
[w + gap, w + gap + l],
[0, w + gap + l],
[0, gap + l],
[w + gap, gap + l],
],
),
)

# ax = l_shape_1.plot(z=1)
# l_shape_2.plot(z=1, ax=ax)

for num_iters in range(2):
grid_spec = td.GridSpec(
grid_x=td.AutoGrid(min_steps_per_wvl=10),
grid_y=td.AutoGrid(min_steps_per_wvl=10),
grid_z=td.AutoGrid(min_steps_per_wvl=10),
layer_refinement_specs=[
td.LayerRefinementSpec(
axis=2,
corner_finder=None,
gap_meshing_iters=num_iters,
size=[td.inf, td.inf, 2],
center=[0, 0, 1],
)
],
wavelength=7,
)

sim = td.Simulation(
structures=[l_shape_1, l_shape_2],
grid_spec=grid_spec,
size=(1.2 * l, 1.2 * l, 2),
center=(0.5 * l, 0.5 * l, 0),
run_time=1e-15,
)

# ax = sim.plot(z=1)
# sim.plot_grid(z=1, ax=ax)
# ax.set_xlim([0, 2])
# ax.set_ylim([0, 2])

resolved_x = np.any(
np.logical_and(sim.grid.boundaries.x > w, sim.grid.boundaries.x < w + gap)
)
resolved_y = np.any(
np.logical_and(sim.grid.boundaries.y > w, sim.grid.boundaries.y < w + gap)
)

if num_iters == 0:
assert (not resolved_x) and (not resolved_y)
else:
assert resolved_x and resolved_y
47 changes: 39 additions & 8 deletions tidy3d/components/grid/corner_finder.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,16 +75,14 @@ def _no_min_dl_override(self):
)
)

def _corners_and_convexity(
self,
@classmethod
def _merged_pec_on_plane(
cls,
normal_axis: Axis,
coord: float,
structure_list: List[Structure],
ravel: bool,
) -> Tuple[ArrayFloat2D, ArrayFloat1D]:
"""On a 2D plane specified by axis = `normal_axis` and coordinate `coord`, find out corners of merged
geometries made of `medium`.

"""On a 2D plane specified by axis = `normal_axis` and coordinate `coord`, merge geometries made of PEC.

Parameters
----------
Expand All @@ -94,8 +92,6 @@ def _corners_and_convexity(
Position of plane along the normal axis.
structure_list : List[Structure]
List of structures present in simulation.
ravel : bool
Whether to put the resulting corners in a single list or per polygon.

Returns
-------
Expand All @@ -121,6 +117,41 @@ def _corners_and_convexity(
# merge geometries
merged_geos = merging_geometries_on_plane(geometry_list, plane, medium_list)

return merged_geos

def _corners_and_convexity(
self,
normal_axis: Axis,
coord: float,
structure_list: List[Structure],
ravel: bool,
) -> Tuple[ArrayFloat2D, ArrayFloat1D]:
"""On a 2D plane specified by axis = `normal_axis` and coordinate `coord`, find out corners of merged
geometries made of PEC.


Parameters
----------
normal_axis : Axis
Axis normal to the 2D plane.
coord : float
Position of plane along the normal axis.
structure_list : List[Structure]
List of structures present in simulation.
ravel : bool
Whether to put the resulting corners in a single list or per polygon.

Returns
-------
ArrayFloat2D
Corner coordinates.
"""

# merge geometries
merged_geos = self._merged_pec_on_plane(
normal_axis=normal_axis, coord=coord, structure_list=structure_list
)

# corner finder
corner_list = []
convexity_list = []
Expand Down
Loading