Skip to content

Commit

Permalink
Validate against nonlinear and modulation in FullyAnisotropicMedium.f…
Browse files Browse the repository at this point in the history
…rom_diagonal
  • Loading branch information
caseyflex authored and momchil-flex committed Nov 13, 2024
1 parent 9a35483 commit 2490f92
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 0 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- Some failing examples in the expressions plugin documentation.
- Inaccuracy in transforming gradients from edge to `PolySlab.vertices`.
- Bug in `run_async` where an adjoint simulation would sometimes be assigned to the wrong forward simulation.
- Validate against nonlinearity or modulation in `FullyAnisotropicMedium.from_diagonal`.


## [2.7.6] - 2024-10-30
Expand Down
32 changes: 32 additions & 0 deletions tests/test_components/test_medium.py
Original file line number Diff line number Diff line change
Expand Up @@ -516,6 +516,38 @@ def test_fully_anisotropic_media():
assert all(np.isin(np.round(perm_d), np.round(np.diag(perm_diag))))
assert all(np.isin(np.round(cond_d), np.round(np.diag(cond_diag))))

with pytest.raises(ValidationError):
_ = td.FullyAnisotropicMedium.from_diagonal(
xx=td.Medium(
permittivity=2,
nonlinear_spec=td.NonlinearSpec(
models=[
td.NonlinearSusceptibility(chi3=2),
td.TwoPhotonAbsorption(beta=1.3),
td.KerrNonlinearity(n2=1.3),
]
),
),
yy=td.Medium(permittivity=4),
zz=td.Medium(permittivity=1),
rotation=td.RotationAroundAxis(axis=2, angle=np.pi / 4),
)

with pytest.raises(ValidationError):
_ = td.FullyAnisotropicMedium.from_diagonal(
xx=td.Medium(permittivity=2),
yy=td.Medium(
permittivity=4,
modulation_spec=td.ModulationSpec(
permittivity=td.SpaceTimeModulation(
time_modulation=td.ContinuousWaveTimeModulation(freq0=1e12, amplitude=0.02)
)
),
),
zz=td.Medium(permittivity=1),
rotation=td.RotationAroundAxis(axis=2, angle=np.pi / 4),
)


def test_nonlinear_medium(log_capture):
med = td.Medium(
Expand Down
12 changes: 12 additions & 0 deletions tidy3d/components/medium.py
Original file line number Diff line number Diff line change
Expand Up @@ -5191,6 +5191,18 @@ def from_diagonal(cls, xx: Medium, yy: Medium, zz: Medium, rotation: RotationTyp
Resulting fully anisotropic medium.
"""

if any(comp.nonlinear_spec is not None for comp in [xx, yy, zz]):
raise ValidationError(
"Nonlinearities are not currently supported for the components "
"of a fully anisotropic medium."
)

if any(comp.modulation_spec is not None for comp in [xx, yy, zz]):
raise ValidationError(
"Modulation is not currently supported for the components "
"of a fully anisotropic medium."
)

permittivity_diag = np.diag([comp.permittivity for comp in [xx, yy, zz]]).tolist()
conductivity_diag = np.diag([comp.conductivity for comp in [xx, yy, zz]]).tolist()

Expand Down

0 comments on commit 2490f92

Please sign in to comment.