Skip to content

Commit

Permalink
Rename fixpoints to snapping_points
Browse files Browse the repository at this point in the history
  • Loading branch information
weiliangjin2021 committed May 28, 2024
1 parent efa6cd5 commit d0d0e5b
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 29 deletions.
4 changes: 2 additions & 2 deletions tests/test_components/test_grid_spec.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ def test_make_coords():
periodic=(True, False, False),
wavelength=1.0,
num_pml_layers=(10, 4),
fixpoints=(),
snapping_points=(),
)


Expand All @@ -46,7 +46,7 @@ def test_make_coords_2d():
periodic=(True, True, False),
wavelength=1.0,
num_pml_layers=(10, 4),
fixpoints=(),
snapping_points=(),
)


Expand Down
30 changes: 15 additions & 15 deletions tidy3d/components/grid/grid_spec.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ def make_coords(
periodic: bool,
wavelength: pd.PositiveFloat,
num_pml_layers: Tuple[pd.NonNegativeInt, pd.NonNegativeInt],
fixpoints: Tuple[Coordinate, ...],
snapping_points: Tuple[Coordinate, ...],
) -> Coords1D:
"""Generate 1D coords to be used as grid boundaries, based on simulation parameters.
Symmetry, and PML layers will be treated here.
Expand All @@ -104,7 +104,7 @@ def make_coords(
Free-space wavelength.
num_pml_layers : Tuple[int, int]
number of layers in the absorber + and - direction along one dimension.
fixpoints : Tuple[Coordinate, ...]
snapping_points : Tuple[Coordinate, ...]
A set of points that enforce grid boundaries to pass through them.
Returns
Expand All @@ -124,7 +124,7 @@ def make_coords(
wavelength=wavelength,
symmetry=symmetry,
is_periodic=is_periodic,
fixpoints=fixpoints,
snapping_points=snapping_points,
)

# incorporate symmetries
Expand Down Expand Up @@ -427,7 +427,7 @@ def _make_coords_initial(
wavelength: float,
symmetry: Symmetry,
is_periodic: bool,
fixpoints: Tuple[Coordinate, ...],
snapping_points: Tuple[Coordinate, ...],
) -> Coords1D:
"""Customized 1D coords to be used as grid boundaries.
Expand All @@ -444,7 +444,7 @@ def _make_coords_initial(
normal to each of the three axes.
is_periodic : bool
Apply periodic boundary condition or not.
fixpoints : Tuple[Coordinate, ...]
snapping_points : Tuple[Coordinate, ...]
A set of points that enforce grid boundaries to pass through them.
Returns
Expand Down Expand Up @@ -475,9 +475,9 @@ def _make_coords_initial(
self.min_steps_per_wvl,
self.dl_min,
)
# insert fixpoints
interval_coords, max_dl_list = self.mesher.insert_fixpoints(
axis, interval_coords, max_dl_list, fixpoints
# insert snapping_points
interval_coords, max_dl_list = self.mesher.insert_snapping_points(
axis, interval_coords, max_dl_list, snapping_points
)

# Put just a single pixel if 2D-like simulation
Expand Down Expand Up @@ -584,11 +584,11 @@ class GridSpec(Tidy3dBaseModel):
"uses :class:`.AutoGrid`.",
)

fixpoints: Tuple[Coordinate, ...] = pd.Field(
snapping_points: Tuple[Coordinate, ...] = pd.Field(
(),
title="Grid specification fixpoints",
title="Grid specification snapping_points",
description="A set of points that enforce grid boundaries to pass through them. "
"However, some fixpoints might be skipped if they are too close. "
"However, some points might be skipped if they are too close. "
"Note: it only takes effect when at least one of the three dimensions "
"uses :class:`.AutoGrid`.",
)
Expand Down Expand Up @@ -709,7 +709,7 @@ def make_grid(
periodic=periodic[idim],
wavelength=wavelength,
num_pml_layers=num_pml_layers[idim],
fixpoints=self.fixpoints,
snapping_points=self.snapping_points,
)

coords = Coords(**coords_dict)
Expand All @@ -722,7 +722,7 @@ def auto(
min_steps_per_wvl: pd.PositiveFloat = 10.0,
max_scale: pd.PositiveFloat = 1.4,
override_structures: List[StructureType] = (),
fixpoints: Tuple[Coordinate, ...] = (),
snapping_points: Tuple[Coordinate, ...] = (),
dl_min: pd.NonNegativeFloat = 0.0,
mesher: MesherType = GradedMesher(),
) -> GridSpec:
Expand All @@ -742,7 +742,7 @@ def auto(
A list of structures that is added on top of the simulation structures in
the process of generating the grid. This can be used to refine the grid or make it
coarser depending than the expected need for higher/lower resolution regions.
fixpoints : Tuple[Coordinate, ...]
snapping_points : Tuple[Coordinate, ...]
A set of points that enforce grid boundaries to pass through them.
dl_min: pd.NonNegativeFloat
Lower bound of grid size.
Expand All @@ -767,7 +767,7 @@ def auto(
grid_y=grid_1d,
grid_z=grid_1d,
override_structures=override_structures,
fixpoints=fixpoints,
snapping_points=snapping_points,
)

@classmethod
Expand Down
20 changes: 10 additions & 10 deletions tidy3d/components/grid/mesher.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,14 +44,14 @@ def parse_structures(
"""Calculate the positions of all bounding box interfaces along a given axis."""

@abstractmethod
def insert_fixpoints(
def insert_snapping_points(
self,
axis: Axis,
interval_coords: ArrayFloat1D,
max_dl_list: ArrayFloat1D,
fixpoints: List[Coordinate],
snapping_points: List[Coordinate],
) -> Tuple[ArrayFloat1D, ArrayFloat1D]:
"""Insert fixpoints to the intervals."""
"""Insert snapping_points to the intervals."""

@abstractmethod
def make_grid_multiple_intervals(
Expand All @@ -68,14 +68,14 @@ class GradedMesher(Mesher):
"""Implements automatic nonuniform meshing with a set minimum steps per wavelength and
a graded mesh expanding from higher- to lower-resolution regions."""

def insert_fixpoints(
def insert_snapping_points(
self,
axis: Axis,
interval_coords: ArrayFloat1D,
max_dl_list: ArrayFloat1D,
fixpoints: List[Coordinate],
snapping_points: List[Coordinate],
) -> Tuple[ArrayFloat1D, ArrayFloat1D]:
"""Insert fixpoints to the intervals.
"""Insert snapping_points to the intervals.
Parameters
----------
Expand All @@ -85,7 +85,7 @@ def insert_fixpoints(
Coordinate of interval boundaries.
max_dl_list : ArrayFloat1D
Maximal allowed step size of each interval generated from `parse_structures`.
fixpoints : List[Coordinate]
snapping_points : List[Coordinate]
A set of points that enforce grid boundaries to pass through them.
Returns
Expand All @@ -103,18 +103,18 @@ def insert_fixpoints(
"""
# Don't do anything for a 2D-like simulation, or no fix points
if interval_coords.size == 1 or len(fixpoints) < 1:
if interval_coords.size == 1 or len(snapping_points) < 1:
return interval_coords, max_dl_list

min_step = np.amin(max_dl_list) * 0.5
for point in fixpoints:
for point in snapping_points:
new_coord = point[axis]
# Skip if the point is outside the domain
if new_coord >= interval_coords[-1] or new_coord <= interval_coords[0]:
continue
# search insertion location
ind = np.searchsorted(interval_coords, new_coord, side="left")
# Skip fixpoints if the distance to the existing interval boundarires are
# Skip snapping_points if the distance to the existing interval boundarires are
# smaller than half of the minimal maximal step size
if abs(new_coord - interval_coords[ind]) < min_step:
continue
Expand Down
4 changes: 2 additions & 2 deletions tidy3d/components/simulation.py
Original file line number Diff line number Diff line change
Expand Up @@ -712,8 +712,8 @@ def plot_grid(
)
ax.add_patch(rect)

# Plot fixpoints
for point in self.grid_spec.fixpoints:
# Plot snapping points
for point in self.grid_spec.snapping_points:
_, (x_point, y_point) = Geometry.pop_axis(point, axis=axis)
x_point, y_point = (self._evaluate_inf(v) for v in (x_point, y_point))
ax.scatter(x_point, y_point, color=plot_params.edgecolor)
Expand Down

0 comments on commit d0d0e5b

Please sign in to comment.