Skip to content

Commit

Permalink
Fixed mode rotation for non-colocated field components
Browse files Browse the repository at this point in the history
  • Loading branch information
QimingFlex committed Nov 15, 2024
1 parent bbc09f0 commit 8236774
Show file tree
Hide file tree
Showing 3 changed files with 228 additions and 157 deletions.
3 changes: 1 addition & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- Differentiable `smooth_min`, `smooth_max`, and `least_squares` functions in `tidy3d.plugins.autograd`.
- 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`.

- `bend_angle_rotation` in `mode_spec` to improve accuracy in some cases when both `bend_radius` and `angle_theta` are defined."

### Changed
- `CustomMedium` design regions require far less data when performing inverse design by reducing adjoint field monitor size for dims with one pixel.
Expand All @@ -33,7 +33,6 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- Users can manually specify the background medium for a structure to be used for geometry gradient calculations by supplying `Structure.background_permittivity`. This is useful when there are overlapping structures or structures embedded in other mediums.
- Autograd functions can now be called directly on `DataArray` (e.g., `np.sum(data_array)`) in objective functions.
- Automatic differentiation support for local field projections with `FieldProjectionAngleMonitor` and `FieldProjectionCartesianMonitor` using `FieldProjector.project_fields(far_field_monitor)`.
- `bend_angle_rotation` in `mode_spec` to improve accuracy when both bend and angle are defined."

### Changed
- Improved autograd tracer handling in `DataArray`, resulting in significant speedups for differentiation involving large monitors.
Expand Down
23 changes: 6 additions & 17 deletions tidy3d/components/mode.py
Original file line number Diff line number Diff line change
Expand Up @@ -131,12 +131,12 @@ class ModeSpec(Tidy3dBaseModel):
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 right geometries in the simulation with rotated structures.",
"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(
Expand Down Expand Up @@ -172,17 +172,6 @@ def bend_radius_not_zero(cls, val, values):
raise SetupError("The magnitude of 'bend_radius' must be larger than 0.")
return val

@pd.validator("bend_angle_rotation", always=True)
@skip_if_fields_missing(["bend_radius", "bend_axis"])
def validate_bend_correction_requirements(cls, val, values):
"""Ensure that both ``bend_axis`` and ``bend_radius`` are provided if ``bend_correction`` is enabled."""
if val is True:
if values.get("bend_axis") is None or values.get("bend_radius") is None:
raise SetupError(
"'bend_correction' can only be enabled when both 'bend_axis' and 'bend_radius' are provided."
)
return val

@pd.validator("angle_theta", allow_reuse=True, always=True)
def glancing_incidence(cls, val):
"""Warn if close to glancing incidence."""
Expand Down
Loading

0 comments on commit 8236774

Please sign in to comment.