Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added NonlinearSusceptibility with chi3 support #992

Merged
merged 1 commit into from
Aug 15, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

### Added
- Added `hlim` and `vlim` kwargs to `Simulation.plot()` and `Simulation.plot_eps()` for setting horizontal and veritcal plot limits.
- Added support for chi3 nonlinearity via `NonlinearSusceptibility` class.

### Changed
- `nyquist_step` also taking the frequency range of frequency-domain monitors into account.
Expand Down
59 changes: 58 additions & 1 deletion tests/sims/simulation_2_4_0rc2.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
"name": null,
"frequency_range": null,
"allow_gain": false,
"nonlinear_spec": null,
"type": "Medium",
"permittivity": 1.0,
"conductivity": 0.0
Expand Down Expand Up @@ -45,6 +46,7 @@
"name": null,
"frequency_range": null,
"allow_gain": false,
"nonlinear_spec": null,
"type": "Medium",
"permittivity": 2.0,
"conductivity": 0.0
Expand All @@ -70,6 +72,7 @@
"name": null,
"frequency_range": null,
"allow_gain": false,
"nonlinear_spec": null,
"type": "Medium",
"permittivity": 1.0,
"conductivity": 3.0
Expand All @@ -91,6 +94,7 @@
"name": null,
"frequency_range": null,
"allow_gain": false,
"nonlinear_spec": null,
"type": "Sellmeier",
"coeffs": [
[
Expand Down Expand Up @@ -124,6 +128,7 @@
"name": null,
"frequency_range": null,
"allow_gain": false,
"nonlinear_spec": null,
"type": "Lorentz",
"eps_inf": 2.0,
"coeffs": [
Expand Down Expand Up @@ -155,6 +160,7 @@
"name": null,
"frequency_range": null,
"allow_gain": false,
"nonlinear_spec": null,
"type": "Debye",
"eps_inf": 2.0,
"coeffs": [
Expand All @@ -179,6 +185,7 @@
"name": null,
"frequency_range": null,
"allow_gain": false,
"nonlinear_spec": null,
"type": "Debye",
"eps_inf": 2.0,
"coeffs": [
Expand Down Expand Up @@ -209,6 +216,7 @@
"name": null,
"frequency_range": null,
"allow_gain": false,
"nonlinear_spec": null,
"type": "Drude",
"eps_inf": 2.0,
"coeffs": [
Expand Down Expand Up @@ -239,11 +247,13 @@
"name": null,
"frequency_range": null,
"allow_gain": false,
"nonlinear_spec": null,
"type": "Medium2D",
"ss": {
"name": null,
"frequency_range": null,
"allow_gain": false,
"nonlinear_spec": null,
"type": "PoleResidue",
"eps_inf": 1.0,
"poles": [
Expand All @@ -263,6 +273,7 @@
"name": null,
"frequency_range": null,
"allow_gain": false,
"nonlinear_spec": null,
"type": "PoleResidue",
"eps_inf": 1.0,
"poles": [
Expand Down Expand Up @@ -305,6 +316,7 @@
"name": "PEC",
"frequency_range": null,
"allow_gain": false,
"nonlinear_spec": null,
"type": "PECMedium"
}
},
Expand All @@ -328,11 +340,13 @@
"name": null,
"frequency_range": null,
"allow_gain": null,
"nonlinear_spec": null,
"type": "AnisotropicMedium",
"xx": {
"name": null,
"frequency_range": null,
"allow_gain": false,
"nonlinear_spec": null,
"type": "Medium",
"permittivity": 1.0,
"conductivity": 0.0
Expand All @@ -341,6 +355,7 @@
"name": null,
"frequency_range": null,
"allow_gain": false,
"nonlinear_spec": null,
"type": "Medium",
"permittivity": 2.0,
"conductivity": 0.0
Expand All @@ -349,6 +364,7 @@
"name": null,
"frequency_range": null,
"allow_gain": false,
"nonlinear_spec": null,
"type": "Medium",
"permittivity": 3.0,
"conductivity": 0.0
Expand Down Expand Up @@ -387,6 +403,7 @@
"name": null,
"frequency_range": null,
"allow_gain": false,
"nonlinear_spec": null,
"type": "PoleResidue",
"eps_inf": 1.0,
"poles": [
Expand Down Expand Up @@ -423,6 +440,7 @@
"name": null,
"frequency_range": null,
"allow_gain": false,
"nonlinear_spec": null,
"type": "CustomMedium",
"interp_method": "nearest",
"subpixel": false,
Expand Down Expand Up @@ -451,6 +469,7 @@
"name": null,
"frequency_range": null,
"allow_gain": false,
"nonlinear_spec": null,
"type": "CustomDrude",
"eps_inf": "SpatialDataArray",
"coeffs": [
Expand Down Expand Up @@ -483,6 +502,7 @@
"name": null,
"frequency_range": null,
"allow_gain": false,
"nonlinear_spec": null,
"type": "CustomLorentz",
"eps_inf": "SpatialDataArray",
"coeffs": [
Expand Down Expand Up @@ -516,6 +536,7 @@
"name": null,
"frequency_range": null,
"allow_gain": false,
"nonlinear_spec": null,
"type": "CustomDebye",
"eps_inf": "SpatialDataArray",
"coeffs": [
Expand Down Expand Up @@ -548,6 +569,7 @@
"name": null,
"frequency_range": null,
"allow_gain": false,
"nonlinear_spec": null,
"type": "CustomPoleResidue",
"eps_inf": "SpatialDataArray",
"poles": [
Expand Down Expand Up @@ -580,6 +602,7 @@
"name": null,
"frequency_range": null,
"allow_gain": false,
"nonlinear_spec": null,
"type": "CustomSellmeier",
"coeffs": [
[
Expand All @@ -591,6 +614,36 @@
"subpixel": false
}
},
{
"geometry": {
"type": "Box",
"center": [
-1.0,
0.5,
0.5
],
"size": [
1.0,
1.0,
1.0
]
},
"name": null,
"type": "Structure",
"medium": {
"name": null,
"frequency_range": null,
"allow_gain": false,
"nonlinear_spec": {
"numiters": 20,
"type": "NonlinearSusceptibility",
"chi3": 0.1
},
"type": "Medium",
"permittivity": 1.0,
"conductivity": 0.0
}
},
{
"geometry": {
"type": "PolySlab",
Expand Down Expand Up @@ -623,6 +676,7 @@
"name": null,
"frequency_range": null,
"allow_gain": false,
"nonlinear_spec": null,
"type": "PoleResidue",
"eps_inf": 1.0,
"poles": [
Expand Down Expand Up @@ -653,6 +707,7 @@
"name": null,
"frequency_range": null,
"allow_gain": false,
"nonlinear_spec": null,
"type": "Medium",
"permittivity": 5.0,
"conductivity": 0.0
Expand Down Expand Up @@ -684,6 +739,7 @@
"name": null,
"frequency_range": null,
"allow_gain": false,
"nonlinear_spec": null,
"type": "Medium",
"permittivity": 5.0,
"conductivity": 0.0
Expand Down Expand Up @@ -1808,6 +1864,7 @@
"name": null,
"frequency_range": null,
"allow_gain": false,
"nonlinear_spec": null,
"type": "Medium",
"permittivity": 2.0,
"conductivity": 0.0
Expand All @@ -1821,4 +1878,4 @@
"normalize_index": 0,
"courant": 0.8,
"version": "2.4.0rc2"
}
}
12 changes: 12 additions & 0 deletions tests/test_components/test_medium.py
Original file line number Diff line number Diff line change
Expand Up @@ -508,3 +508,15 @@ def test_perturbation_medium():
poles=[(1j, 3), (2j, 4)],
poles_perturbation=[(None, pp_real)],
)


def test_nonlinear_medium():
med = td.Medium(nonlinear_spec=td.NonlinearSusceptibility(chi3=1.5, numiters=20))

with pytest.raises(pydantic.ValidationError):
med = td.PoleResidue(
poles=[(-1, 1)], nonlinear_spec=td.NonlinearSusceptibility(chi3=1.5, numiters=20)
)

with pytest.raises(pydantic.ValidationError):
med = td.Medium(nonlinear_spec=td.NonlinearSusceptibility(chi3=1.5, numiters=200))
9 changes: 9 additions & 0 deletions tests/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -194,6 +194,15 @@
),
medium=custom_sellmeier,
),
td.Structure(
geometry=td.Box(
size=(1, 1, 1),
center=(-1.0, 0.5, 0.5),
),
medium=td.Medium(
nonlinear_spec=td.NonlinearSusceptibility(chi3=0.1, numiters=20),
),
),
td.Structure(
geometry=td.PolySlab(
vertices=[(-1.5, -1.5), (-0.5, -1.5), (-0.5, -0.5)], slab_bounds=[-1, 1]
Expand Down
3 changes: 2 additions & 1 deletion tidy3d/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
from .components.medium import CustomMedium, CustomPoleResidue
from .components.medium import CustomSellmeier, FullyAnisotropicMedium
from .components.medium import CustomLorentz, CustomDrude, CustomDebye, CustomAnisotropicMedium
from .components.medium import NonlinearSusceptibility
from .components.transformation import RotationAroundAxis
from .components.medium import PerturbationMedium, PerturbationPoleResidue
from .components.parameter_perturbation import ParameterPerturbation
Expand Down Expand Up @@ -87,7 +88,7 @@
from .material_library.parametric_materials import Graphene

# for docs
from .components.medium import AbstractMedium
from .components.medium import AbstractMedium, NonlinearSpec
from .components.geometry import Geometry
from .components.source import Source, SourceTime
from .components.monitor import Monitor
Expand Down
Loading