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

automatic mode rotation for bent waveguide #2028

Merged
merged 1 commit into from
Dec 4, 2024
Merged
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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- Differential operators `grad` and `value_and_grad` in `tidy3d.plugins.autograd` that behave similarly to the autograd operators but support auxiliary data via `aux_data=True` as well as differentiation w.r.t. `DataArray`.
- `@scalar_objective` decorator in `tidy3d.plugins.autograd` that wraps objective functions to ensure they return a scalar value and performs additional checks to ensure compatibility of objective functions with autograd. Used by default in `tidy3d.plugins.autograd.value_and_grad` as well as `tidy3d.plugins.autograd.grad`.
- Autograd support for simulations without adjoint sources in `run` as well as `run_async`, which will not attempt to run the simulation but instead return zero gradients. This can sometimes occur if the objective function gradient does not depend on some simulations, for example when using `min` or `max` in the objective.
- `bend_angle_rotation` in `ModeSpec` to improve accuracy in some cases when both `bend_radius` and `angle_theta` are defined. This option is disabled by default but it can be tried when very high accuracy is required in `ModeSource` and `ModeMonitor` objects that are placed in bend and angled waveguides.

### Changed
- `CustomMedium` design regions require far less data when performing inverse design by reducing adjoint field monitor size for dims with one pixel.
Expand Down
2 changes: 2 additions & 0 deletions tidy3d/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@
PointDataArray,
ScalarFieldDataArray,
ScalarFieldTimeDataArray,
ScalarModeFieldCylindricalDataArray,
ScalarModeFieldDataArray,
SpatialDataArray,
)
Expand Down Expand Up @@ -399,6 +400,7 @@ def set_logging_level(level: str) -> None:
"FieldProjector",
"ScalarFieldDataArray",
"ScalarModeFieldDataArray",
"ScalarModeFieldCylindricalDataArray",
"ScalarFieldTimeDataArray",
"SpatialDataArray",
"ModeAmpsDataArray",
Expand Down
18 changes: 18 additions & 0 deletions tidy3d/components/data/data_array.py
Original file line number Diff line number Diff line change
Expand Up @@ -813,6 +813,24 @@ class ScalarModeFieldDataArray(AbstractSpatialDataArray):
_dims = ("x", "y", "z", "f", "mode_index")


class ScalarModeFieldCylindricalDataArray(AbstractSpatialDataArray):
"""Spatial distribution of a mode in frequency-domain as a function of mode index.

Example
-------
>>> rho = [1,2]
>>> theta = [2,3,4]
>>> axial = [3,4,5,6]
>>> f = [2e14, 3e14]
>>> mode_index = np.arange(5)
>>> coords = dict(rho=rho, theta=theta, axial=axial, f=f, mode_index=mode_index)
>>> fd = ScalarModeFieldCylindricalDataArray((1+1j) * np.random.random((2,3,4,2,5)), coords=coords)
"""

__slots__ = ()
_dims = ("rho", "theta", "axial", "f", "mode_index")


class FluxDataArray(DataArray):
"""Flux through a surface in the frequency-domain.

Expand Down
2 changes: 2 additions & 0 deletions tidy3d/components/data/dataset.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
PointDataArray,
ScalarFieldDataArray,
ScalarFieldTimeDataArray,
ScalarModeFieldCylindricalDataArray,
ScalarModeFieldDataArray,
SpatialDataArray,
TimeDataArray,
Expand Down Expand Up @@ -149,6 +150,7 @@ def colocate(self, x=None, y=None, z=None) -> xr.Dataset:
ScalarFieldDataArray,
ScalarFieldTimeDataArray,
ScalarModeFieldDataArray,
ScalarModeFieldCylindricalDataArray,
EMEScalarModeFieldDataArray,
EMEScalarFieldDataArray,
]
Expand Down
12 changes: 12 additions & 0 deletions tidy3d/components/mode.py
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,18 @@ class ModeSpec(Tidy3dBaseModel):
"yz plane, the ``bend_axis`` is always 1 (the global z axis).",
)

bend_angle_rotation: bool = pd.Field(
False,
title="Use fields rotation when both bend and angle are defined",
description="Defines how modes are computed when both a bend and an angle are defined. "
"If `False`, the two coordinate transformations are directly composed. "
"If `True`, the structures in the simulation are first rotated to compute a mode solution at "
"a reference plane normal to the bend's azimuthal direction. Then, the fields are rotated to align with "
"the mode plane, using the `n_eff` calculated at the reference plane. The second option can "
"produce more accurate results, but more care must be taken, for example, in ensuring that the "
"original mode plane intersects the correct geometries in the simulation with rotated structures.",
)

track_freq: Union[TrackFreq, None] = pd.Field(
"central",
title="Mode Tracking Frequency",
Expand Down
Loading
Loading