Skip to content

Commit 2490f92

Browse files
caseyflexmomchil-flex
authored andcommitted
Validate against nonlinear and modulation in FullyAnisotropicMedium.from_diagonal
1 parent 9a35483 commit 2490f92

File tree

3 files changed

+45
-0
lines changed

3 files changed

+45
-0
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
2727
- Some failing examples in the expressions plugin documentation.
2828
- Inaccuracy in transforming gradients from edge to `PolySlab.vertices`.
2929
- Bug in `run_async` where an adjoint simulation would sometimes be assigned to the wrong forward simulation.
30+
- Validate against nonlinearity or modulation in `FullyAnisotropicMedium.from_diagonal`.
3031

3132

3233
## [2.7.6] - 2024-10-30

tests/test_components/test_medium.py

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -516,6 +516,38 @@ def test_fully_anisotropic_media():
516516
assert all(np.isin(np.round(perm_d), np.round(np.diag(perm_diag))))
517517
assert all(np.isin(np.round(cond_d), np.round(np.diag(cond_diag))))
518518

519+
with pytest.raises(ValidationError):
520+
_ = td.FullyAnisotropicMedium.from_diagonal(
521+
xx=td.Medium(
522+
permittivity=2,
523+
nonlinear_spec=td.NonlinearSpec(
524+
models=[
525+
td.NonlinearSusceptibility(chi3=2),
526+
td.TwoPhotonAbsorption(beta=1.3),
527+
td.KerrNonlinearity(n2=1.3),
528+
]
529+
),
530+
),
531+
yy=td.Medium(permittivity=4),
532+
zz=td.Medium(permittivity=1),
533+
rotation=td.RotationAroundAxis(axis=2, angle=np.pi / 4),
534+
)
535+
536+
with pytest.raises(ValidationError):
537+
_ = td.FullyAnisotropicMedium.from_diagonal(
538+
xx=td.Medium(permittivity=2),
539+
yy=td.Medium(
540+
permittivity=4,
541+
modulation_spec=td.ModulationSpec(
542+
permittivity=td.SpaceTimeModulation(
543+
time_modulation=td.ContinuousWaveTimeModulation(freq0=1e12, amplitude=0.02)
544+
)
545+
),
546+
),
547+
zz=td.Medium(permittivity=1),
548+
rotation=td.RotationAroundAxis(axis=2, angle=np.pi / 4),
549+
)
550+
519551

520552
def test_nonlinear_medium(log_capture):
521553
med = td.Medium(

tidy3d/components/medium.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5191,6 +5191,18 @@ def from_diagonal(cls, xx: Medium, yy: Medium, zz: Medium, rotation: RotationTyp
51915191
Resulting fully anisotropic medium.
51925192
"""
51935193

5194+
if any(comp.nonlinear_spec is not None for comp in [xx, yy, zz]):
5195+
raise ValidationError(
5196+
"Nonlinearities are not currently supported for the components "
5197+
"of a fully anisotropic medium."
5198+
)
5199+
5200+
if any(comp.modulation_spec is not None for comp in [xx, yy, zz]):
5201+
raise ValidationError(
5202+
"Modulation is not currently supported for the components "
5203+
"of a fully anisotropic medium."
5204+
)
5205+
51945206
permittivity_diag = np.diag([comp.permittivity for comp in [xx, yy, zz]]).tolist()
51955207
conductivity_diag = np.diag([comp.conductivity for comp in [xx, yy, zz]]).tolist()
51965208

0 commit comments

Comments
 (0)