Skip to content

Commit dceb0e0

Browse files
Introduce SubpixelSpec to allow for selecting subpixel averaging methods for different materials
Validate dielectric subpixel in adjoint plugin Enable VolumetricAveraging to automatically switch to Staircasing if the field is substantially normal to the interface
1 parent c061859 commit dceb0e0

File tree

14 files changed

+247
-169
lines changed

14 files changed

+247
-169
lines changed

CHANGELOG.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
1010
- A batch of `ModeSolver` objects can be run concurrently using `tidy3d.plugins.mode.web.run_batch()`
1111
- `RectangularWaveguide.plot_field` optionally draws geometry edges over fields.
1212
- `RectangularWaveguide` supports layered cladding above and below core.
13+
- `SubpixelSpec` accepted by `Simulation.subpixel` to select subpixel averaging methods separately for dielectric, metal, and PEC materials. Specifically, added support for conformal mesh methods near PEC structures that can be specified through the field `pec` in the `SubpixelSpec` class. Note: previously, `subpixel=False` was implementing staircasing for every material except PEC. Now, `subpixel=False` implements direct staircasing for all materials. For PEC, the behavior of `subpixel=False` in Tidy3D < 2.7 is now achieved through `subpixel=SubpixelSpec(pec=HeuristicPECStaircasing())`, while `subpixel=True` in Tidy3D < 2.7 is now achieved through `subpixel=SubpixelSpec(pec=Staircasing())`. The default is `subpixel=SubpixelSpec(pec=PECConformal())` for more accurate PEC modelling.
1314

1415
### Fixed
1516
- `ModeSolver.plot_field` correctly returning the plot axes.
@@ -52,7 +53,6 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
5253
- Introduces the `microwave` plugin which includes `ImpedanceCalculator` for computing the characteristic impedance of transmission lines.
5354
- `Simulation` now accepts `LumpedElementType`, which currently only supports the `LumpedResistor` type. `LumpedPort` together with `LumpedResistor` make up the new `TerminalComponentModeler` in the `smatrix` plugin.
5455
- Uniaxial medium Lithium Niobate to material library.
55-
- Added support for conformal mesh methods near PEC structures that can be specified through the field `pec_conformal_mesh_spec` in the `Simulation` class. Note: previously, `subpixel=False` was implementing staircasing for every material except PEC. Now, `subpixel=False` implements direct staircasing for all materials. For PEC, the behavior of `subpixel=False` in Tidy3D < 2.7 is now achieved through `subpixel=True` and `pec_conformal_mesh_spec=HeuristicConformalMeshSpec()`, while `subpixel=True` in Tidy3D < 2.7 is now achieved through the default settings `subpixel=True` and `pec_conformal_mesh_spec=StaircasingConformalMeshSpec()`. Additionally, a new `BenklerConformalMeshSpec()` was introduced for more accurate PEC modelling.
5656
- Properties `num_time_steps_adjoint` and `tmesh_adjoint` to `JaxSimulation` to estimate adjoint run time.
5757
- Ability to add `path` to `updated_copy()` method to recursively update sub-components of a tidy3d model. For example `sim2 = sim.updated_copy(size=new_size, path="structures/0/geometry")` creates a recursively updated copy of `sim` where `sim.structures[0].geometry` is updated with `size=new_size`.
5858
- Python 3.12 support. Python 3.8 deprecation. Updated dependencies.

docs/api/discretization.rst

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -15,14 +15,3 @@ Discretization
1515
tidy3d.FieldGrid
1616
tidy3d.YeeGrid
1717
tidy3d.Grid
18-
19-
PEC Conformal Mesh Spec
20-
-----------------------
21-
22-
.. autosummary::
23-
:toctree: _autosummary/
24-
:template: module.rst
25-
26-
tidy3d.StaircasingConformalMeshSpec
27-
tidy3d.HeuristicConformalMeshSpec
28-
tidy3d.BenklerConformalMeshSpec

docs/api/index.rst

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ API |:computer:|
1616
mode
1717
lumped_elements
1818
discretization
19+
subpixel_averaging
1920
output_data
2021
scene
2122
logging
@@ -38,6 +39,7 @@ API |:computer:|
3839
.. include:: /api/mode.rst
3940
.. include:: /api/lumped_elements.rst
4041
.. include:: /api/discretization.rst
42+
.. include:: /api/subpixel_averaging.rst
4143
.. include:: /api/output_data.rst
4244
.. include:: /api/scene.rst
4345
.. include:: /api/logging.rst

docs/api/subpixel_averaging.rst

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
.. currentmodule:: tidy3d
2+
3+
Subpixel Averaging
4+
==================
5+
6+
.. autosummary::
7+
:toctree: _autosummary/
8+
:template: module.rst
9+
10+
tidy3d.SubpixelSpec
11+
12+
Types of Subpixel Averaging Methods
13+
-----------------------------------
14+
15+
.. autosummary::
16+
:toctree: _autosummary/
17+
:template: module.rst
18+
19+
tidy3d.Staircasing
20+
tidy3d.VolumetricAveraging
21+
tidy3d.HeuristicPECStaircasing
22+
tidy3d.PolarizedAveraging
23+
tidy3d.PECConformal

tests/sims/simulation_sample.h5

-88 Bytes
Binary file not shown.

tests/sims/simulation_sample.json

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2722,9 +2722,5 @@
27222722
"courant": 0.8,
27232723
"normalize_index": 0,
27242724
"shutoff": 0.0001,
2725-
"pec_conformal_mesh_spec": {
2726-
"attrs": {},
2727-
"type": "StaircasingConformalMeshSpec"
2728-
},
27292725
"run_time": 1e-12
27302726
}

tests/test_components/test_simulation.py

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1969,30 +1969,32 @@ def test_dt():
19691969

19701970

19711971
def test_conformal_dt():
1972-
"""make sure dt is reduced when BenklerConformalMeshSpec is applied."""
1972+
"""make sure dt is reduced when PEC structures are present and PECConformal is used."""
1973+
box = td.Structure(
1974+
geometry=td.Box(size=(1, 1, 1)),
1975+
medium=td.PECMedium(),
1976+
)
19731977
sim = td.Simulation(
19741978
size=(2.0, 2.0, 2.0),
19751979
run_time=1e-12,
1980+
structures=[box],
19761981
grid_spec=td.GridSpec.uniform(dl=0.1),
1982+
subpixel=td.SubpixelSpec(pec=td.Staircasing()),
19771983
)
19781984
dt = sim.dt
19791985

1980-
# Benkler
1981-
sim_conformal = sim.updated_copy(pec_conformal_mesh_spec=td.BenklerConformalMeshSpec())
1986+
# Conformal
1987+
sim_conformal = sim.updated_copy(subpixel=td.SubpixelSpec(pec=td.PECConformal()))
19821988
assert sim_conformal.dt < dt
19831989

1984-
# Benkler: same courant
1990+
# Conformal: same courant
19851991
sim_conformal2 = sim.updated_copy(
1986-
pec_conformal_mesh_spec=td.BenklerConformalMeshSpec(timestep_reduction=0)
1992+
subpixel=td.SubpixelSpec(pec=td.PECConformal(timestep_reduction=0))
19871993
)
19881994
assert sim_conformal2.dt == dt
19891995

1990-
# staircasing
1991-
sim_staircasing = sim.updated_copy(pec_conformal_mesh_spec=td.StaircasingConformalMeshSpec())
1992-
assert sim_staircasing.dt == dt
1993-
19941996
# heuristic
1995-
sim_heuristic = sim.updated_copy(pec_conformal_mesh_spec=td.StaircasingConformalMeshSpec())
1997+
sim_heuristic = sim.updated_copy(subpixel=td.SubpixelSpec(pec=td.HeuristicPECStaircasing()))
19961998
assert sim_heuristic.dt == dt
19971999

19982000

tidy3d/__init__.py

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,11 @@
33
# grid
44
from .components.grid.grid import Grid, Coords
55
from .components.grid.grid_spec import GridSpec, UniformGrid, CustomGrid, AutoGrid
6-
from .components.grid.grid_spec import BenklerConformalMeshSpec, StaircasingConformalMeshSpec
7-
from .components.grid.grid_spec import HeuristicConformalMeshSpec
6+
7+
# subpixel
8+
from .components.subpixel_spec import SubpixelSpec, Staircasing
9+
from .components.subpixel_spec import VolumetricAveraging, PolarizedAveraging
10+
from .components.subpixel_spec import HeuristicPECStaircasing, PECConformal
811

912
# geometry
1013
from .components.geometry.base import Box, Transformed, ClipOperation, GeometryGroup
@@ -352,9 +355,12 @@ def set_logging_level(level: str) -> None:
352355
"TriangularGridDataset",
353356
"TetrahedralGridDataset",
354357
"medium_from_nk",
355-
"BenklerConformalMeshSpec",
356-
"StaircasingConformalMeshSpec",
357-
"HeuristicConformalMeshSpec",
358+
"SubpixelSpec",
359+
"Staircasing",
360+
"VolumetricAveraging",
361+
"PolarizedAveraging",
362+
"HeuristicPECStaircasing",
363+
"PECConformal",
358364
"EMESimulation",
359365
"EMESimulationData",
360366
"EMEMonitor",

tidy3d/components/eme/simulation.py

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -175,13 +175,6 @@ class EMESimulation(AbstractYeeGridSimulation):
175175
validate_default=True,
176176
)
177177

178-
subpixel: bool = pd.Field(
179-
True,
180-
title="Subpixel Averaging",
181-
description="If ``True``, uses subpixel averaging of the permittivity "
182-
"based on structure definition, resulting in much higher accuracy for a given grid size.",
183-
)
184-
185178
store_port_modes: bool = pd.Field(
186179
True,
187180
title="Store Port Modes",

tidy3d/components/grid/grid_spec.py

Lines changed: 1 addition & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99

1010
from .grid import Coords1D, Coords, Grid
1111
from .mesher import GradedMesher, MesherType
12-
from ..base import Tidy3dBaseModel, cached_property
12+
from ..base import Tidy3dBaseModel
1313
from ..types import Axis, Symmetry, annotate_type, TYPE_TAG_STR
1414
from ..source import SourceType
1515
from ..structure import Structure, StructureType
@@ -18,61 +18,6 @@
1818
from ...exceptions import SetupError
1919
from ...constants import MICROMETER, C_0, fp_eps
2020

21-
# Default Courant number reduction rate in Benkler's scheme
22-
DEFAULT_COURANT_REDUCTION_BENKLER = 0.3
23-
24-
25-
class ConformalMeshSpec(Tidy3dBaseModel, ABC):
26-
"""Base class defining conformal mesh specifications."""
27-
28-
@cached_property
29-
def courant_ratio(self) -> float:
30-
"""The scaling ratio applied to Courant number so that the courant number
31-
in the simulation is ``sim.courant * courant_ratio``.
32-
"""
33-
return 1.0
34-
35-
36-
class StaircasingConformalMeshSpec(ConformalMeshSpec):
37-
"""Simple staircasing scheme based on
38-
[Taflove, The Electrical Engineering Handbook 3.629-670 (2005): 15.].
39-
"""
40-
41-
42-
class HeuristicConformalMeshSpec(ConformalMeshSpec):
43-
"""Slightly different from the staircasing scheme: the field component near PEC
44-
is considered to be outside PEC if it's substantially normal to the interface.
45-
"""
46-
47-
48-
class BenklerConformalMeshSpec(ConformalMeshSpec):
49-
"""Conformal mesh scheme based on
50-
[S. Benkler, IEEE Transactions on Antennas and Propagation 54.6, 1843 (2006)], which is similar
51-
to the approach described in [S. Dey, R. Mittra, IEEE Microwave and Guided Wave Letters 7.9, 273 (1997)].
52-
"""
53-
54-
timestep_reduction: float = pd.Field(
55-
DEFAULT_COURANT_REDUCTION_BENKLER,
56-
title="Time Step Size Reduction Rate",
57-
description="Reduction factor between 0 and 1 such that the simulation's time step size "
58-
"will be ``1 - timestep_reduction`` times its default value. "
59-
"Accuracy can be improved with a smaller time step size; but simulation time increased as well.",
60-
lt=1,
61-
ge=0,
62-
)
63-
64-
@cached_property
65-
def courant_ratio(self) -> float:
66-
"""The scaling ratio applied to Courant number so that the courant number
67-
in the simulation is ``sim.courant * courant_ratio``.
68-
"""
69-
return 1 - self.timestep_reduction
70-
71-
72-
ConformalMeshSpecType = Union[
73-
BenklerConformalMeshSpec, StaircasingConformalMeshSpec, HeuristicConformalMeshSpec
74-
]
75-
7621

7722
class GridSpec1d(Tidy3dBaseModel, ABC):
7823

0 commit comments

Comments
 (0)