Skip to content

Commit

Permalink
Validate the use of dielectrics only in RectangularDielectric (#1859)
Browse files Browse the repository at this point in the history
Signed-off-by: Lucas Heitzmann Gabrielli <[email protected]>
  • Loading branch information
lucas-flexcompute authored Jul 29, 2024
1 parent 6980943 commit b08633c
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 0 deletions.
34 changes: 34 additions & 0 deletions tests/test_plugins/test_waveguide.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,40 @@ def test_array_validators():
)


def test_non_metallic_validator():
with pytest.raises(ValidationError, match="conductor"):
waveguide.RectangularDielectric(
wavelength=1.55,
core_width=0.3,
core_thickness=0.22,
clad_thickness=[1, 1],
core_medium=td.material_library["Ag"].medium,
clad_medium=[td.Medium(permittivity=1.45**2)] * 2,
)

with pytest.raises(ValidationError, match="conductor"):
waveguide.RectangularDielectric(
wavelength=1.55,
core_width=0.3,
core_thickness=0.22,
clad_thickness=1,
core_medium=td.Medium(permittivity=3.48**2),
clad_medium=td.material_library["Ag"].medium,
)

with pytest.raises(ValidationError, match="conductor"):
waveguide.RectangularDielectric(
wavelength=1.55,
core_width=0.3,
core_thickness=0.22,
clad_thickness=[1, 1],
box_thickness=[1, 1],
core_medium=td.Medium(permittivity=3.48**2),
clad_medium=[td.Medium(permittivity=1.45**2)] * 2,
box_medium=[td.Medium(permittivity=1.45**2), td.material_library["Ag"].medium],
)


def test_layer_validators():
with pytest.raises(ValidationError, match="Number"):
waveguide.RectangularDielectric(
Expand Down
13 changes: 13 additions & 0 deletions tidy3d/plugins/waveguide/rectangular_dielectric.py
Original file line number Diff line number Diff line change
Expand Up @@ -215,6 +215,19 @@ def _set_non_negative_array(cls, val):
raise ValidationError("Values may not be negative.")
return val

@pydantic.validator("core_medium", "clad_medium", "box_medium")
def _check_non_metallic(cls, val, values):
if val is None:
return val
media = val if isinstance(val, tuple) else (val,)
freqs = C_0 / values["wavelength"]
if any(medium.eps_model(f).real < 1 for medium in media for f in freqs):
raise ValidationError(
"'RectangularDielectric' can only be used with dielectric media. "
"Found a conductor with real permittivity < 1."
)
return val

@pydantic.validator("gap", always=True)
@skip_if_fields_missing(["core_width"])
def _validate_gaps(cls, val, values):
Expand Down

0 comments on commit b08633c

Please sign in to comment.