Skip to content

Commit

Permalink
Validate Medium2D components to be either both PEC or non-PEC
Browse files Browse the repository at this point in the history
  • Loading branch information
weiliangjin2021 committed May 23, 2024
1 parent a5d945a commit 6958012
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 0 deletions.
3 changes: 3 additions & 0 deletions tests/test_components/test_medium.py
Original file line number Diff line number Diff line change
Expand Up @@ -433,6 +433,9 @@ def test_medium2d(log_capture): # noqa: F811
plt.close()
assert_log_level(log_capture, "WARNING")

with pytest.raises(pydantic.ValidationError):
_ = td.Medium2D(ss=td.PECMedium(), tt=td.Medium())


def test_rotation():
# check that transpose is inverse
Expand Down
11 changes: 11 additions & 0 deletions tidy3d/components/medium.py
Original file line number Diff line number Diff line change
Expand Up @@ -5473,6 +5473,17 @@ def _validate_modulation_spec(cls, val):
)
return val

@skip_if_fields_missing(["ss"])
@pd.validator("tt", always=True)
def _validate_inplane_pec(cls, val, values):
"""ss/tt components must be both PEC or non-PEC."""
if isinstance(val, PECMedium) != isinstance(values["ss"], PECMedium):
raise ValidationError(
"Materials describing ss- and tt-components must be "
"either both 'PECMedium', or non-'PECMedium'."
)
return val

@classmethod
def _weighted_avg(
cls, meds: List[IsotropicUniformMediumType], weights: List[float]
Expand Down

0 comments on commit 6958012

Please sign in to comment.