Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

Round port locations and layer centers to one picometer by default #273

Merged
merged 1 commit into from
Dec 11, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
13 changes: 11 additions & 2 deletions gplugins/tidy3d/component.py
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,7 @@ def get_ports(
mode_spec: td.ModeSpec,
size_mult: float | tuple[float, float] = (4.0, 2.0),
cz: float | None = None,
grid_eps: float | None = None,
) -> list[Port]:
"""
Returns a list of Port instances for each optical port in the component.
Expand All @@ -141,6 +142,7 @@ def get_ports(
mode_spec (td.ModeSpec): The mode specification for the ports.
size_mult (float | tuple[float, float], optional): The size multiplier for the ports. Defaults to (4.0, 2.0).
cz (float | None, optional): The z-coordinate for the ports. If None, the z-coordinate of the component is used. Defaults to None.
grid_eps (float | None, optional): Rounding tolerance for port coordinates. If None, the coordinates are not rounded. Defaults to None.

Returns:
list[Port]: A list of Port instances.
Expand All @@ -161,9 +163,12 @@ def get_ports(
size[2] = size_mult[1] * port.width
size[axis] = 0

if grid_eps is not None:
center = np.round(center, abs(int(np.log10(grid_eps))))

ports.append(
Port(
center=center,
center=tuple(center),
size=tuple(size),
direction=direction,
mode_spec=mode_spec,
Expand Down Expand Up @@ -235,6 +240,7 @@ def get_component_modeler(
boundary_spec: td.BoundarySpec = td.BoundarySpec.all_sides(boundary=td.PML()),
run_time: float = 10e-12,
shutoff: float = 1e-5,
grid_eps: float = 1e-6,
folder_name: str = "default",
path_dir: str = ".",
verbose: bool = True,
Expand All @@ -259,6 +265,7 @@ def get_component_modeler(
boundary_spec: The boundary specification for the ComponentModeler. Defaults to td.BoundarySpec.all_sides(boundary=td.PML()).
run_time: The run time for the ComponentModeler.
shutoff: The shutoff value for the ComponentModeler. Defaults to 1e-5.
grid_eps: Rounding tolerance for coordinates, e.g. port locations and layer centers (μm).
folder_name: The folder name for the ComponentModeler. Defaults to "default".
path_dir: The directory path for the ComponentModeler. Defaults to ".".
verbose: Whether to print verbose output for the ComponentModeler. Defaults to True.
Expand All @@ -279,6 +286,8 @@ def get_component_modeler(
case _:
raise ValueError(f"Invalid center_z: {center_z}")

cz = np.round(cz, abs(int(np.log10(grid_eps)))).item()

freqs = td.C_0 / np.linspace(
wavelength - bandwidth / 2, wavelength + bandwidth / 2, num_freqs
)
Expand All @@ -302,7 +311,7 @@ def get_component_modeler(
**kwargs,
)

ports = self.get_ports(mode_spec, port_size_mult)
ports = self.get_ports(mode_spec, port_size_mult, grid_eps=grid_eps)

modeler = ComponentModeler(
simulation=sim,
Expand Down