From 9f01fdbb0d0cfa03f346f620ad388ff4d5cd06ba Mon Sep 17 00:00:00 2001 From: Qiming Date: Fri, 23 Aug 2024 13:58:21 -0400 Subject: [PATCH] Errored out Bloch boundaries in 2d sims --- CHANGELOG.md | 1 + tidy3d/components/simulation.py | 11 ++++++++++- 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index e7249beae..d86291be4 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -12,6 +12,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. diff --git a/tidy3d/components/simulation.py b/tidy3d/components/simulation.py index 9cb64d822..33d5f368d 100644 --- a/tidy3d/components/simulation.py +++ b/tidy3d/components/simulation.py @@ -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") @@ -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( @@ -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 "