Skip to content

Commit

Permalink
Merge pull request #1919 from flexcompute/qiming/error_bloch
Browse files Browse the repository at this point in the history
added validator to error out Bloch boundaries in along 0-dim in 2D simulations
  • Loading branch information
momchil-flex authored Aug 30, 2024
2 parents 2e5c80e + 9f01fdb commit 636746e
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

### Changed
- `PolySlab` now raises error when differentiating and dilation causes damage to the polygon.
- Validator `boundaries_for_zero_dims` to raise error when Bloch boundaries are used along 0-sized dims.

### Fixed
- `DataArray` interpolation failure due to incorrect ordering of coordinates when interpolating with autograd tracers.
Expand Down
11 changes: 10 additions & 1 deletion tidy3d/components/simulation.py
Original file line number Diff line number Diff line change
Expand Up @@ -2410,7 +2410,7 @@ def tfsf_with_symmetry(cls, val, values):
@pydantic.validator("boundary_spec", always=True)
@skip_if_fields_missing(["size", "symmetry"])
def boundaries_for_zero_dims(cls, val, values):
"""Error if absorbing boundaries, unmatching pec/pmc, or symmetry is used along a zero dimension."""
"""Error if absorbing boundaries, bloch boundaries, unmatching pec/pmc, or symmetry is used along a zero dimension."""
boundaries = val.to_list
size = values.get("size")
symmetry = values.get("symmetry")
Expand All @@ -2420,6 +2420,7 @@ def boundaries_for_zero_dims(cls, val, values):
if size_dim == 0:
axis = axis_names[dim]
num_absorbing_bdries = sum(isinstance(bnd, AbsorberSpec) for bnd in boundary)
num_bloch_bdries = sum(isinstance(bnd, BlochBoundary) for bnd in boundary)

if num_absorbing_bdries > 0:
raise SetupError(
Expand All @@ -2428,6 +2429,14 @@ def boundaries_for_zero_dims(cls, val, values):
f"Use either 'Periodic' or 'BlochBoundary' along {axis}."
)

if num_bloch_bdries > 0:
raise SetupError(
f"The simulation has zero size along the {axis} axis, "
"using a Bloch boundary along such an axis is not supported because of "
"the Bloch vector definition in units of '2 * pi / (size along dimension)'. Use a small "
"but nonzero size along the dimension instead."
)

if symmetry_dim != 0:
raise SetupError(
f"The simulation has zero size along the {axis} axis, so "
Expand Down

0 comments on commit 636746e

Please sign in to comment.