Skip to content

Commit 54a74b4

Browse files
committed
Add aux field monitors
1 parent 6c2e2c6 commit 54a74b4

File tree

14 files changed

+324
-29
lines changed

14 files changed

+324
-29
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
1212
- New subpixel averaging option `ContourPathAveraging` applied to dielectric material boundaries.
1313
- A property `interior_angle` in `PolySlab` that stores angles formed inside polygon by two adjacent edges.
1414
- `eps_component` argument in `td.Simulation.plot_eps()` to optionally select a specific permittivity component to plot (eg. `"xx"`).
15+
- Monitor `AuxFieldTimeMonitor` for aux fields like the free carrier density in `TwoPhotonAbsorption`.
1516

1617
### Fixed
1718
- Compatibility with `xarray>=2025.03`.

tests/test_components/test_medium.py

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -797,6 +797,29 @@ def test_nonlinear_medium():
797797
)
798798
_ = sim.updated_copy(medium=med, path="structures/0")
799799

800+
grid_spec = td.GridSpec.auto(min_steps_per_wvl=10, wavelength=1)
801+
sim = sim.updated_copy(grid_spec=grid_spec)
802+
aux_fields = ("Nfz",)
803+
with AssertLogLevel(None):
804+
med = td.Medium(
805+
nonlinear_spec=td.NonlinearSpec(models=[td.TwoPhotonAbsorption(beta=1, tau=1)])
806+
)
807+
monitor = td.AuxFieldTimeMonitor(
808+
interval=1, size=(0, 0, 0), name="aux_field_time", fields=aux_fields
809+
)
810+
sim = sim.updated_copy(medium=med, path="structures/0")
811+
sim = sim.updated_copy(monitors=[monitor])
812+
813+
with AssertLogLevel("WARNING", contains_str="stores field"):
814+
med = td.Medium(
815+
nonlinear_spec=td.NonlinearSpec(models=[td.TwoPhotonAbsorption(beta=1, tau=0)])
816+
)
817+
_ = sim.updated_copy(medium=med, path="structures/0")
818+
819+
with AssertLogLevel("WARNING", contains_str="stores field"):
820+
med = td.Medium(nonlinear_spec=td.NonlinearSpec(models=[td.KerrNonlinearity(n2=1)]))
821+
_ = sim.updated_copy(medium=med, path="structures/0")
822+
800823

801824
def test_custom_medium():
802825
Nx, Ny, Nz, Nf = 4, 3, 1, 1

tests/test_components/test_monitor.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -376,6 +376,7 @@ def test_monitor():
376376
name="directivity",
377377
)
378378
m10 = td.PermittivityMonitor(size=size, center=center, freqs=FREQS, name="perm")
379+
m11 = td.AuxFieldTimeMonitor(size=size, center=center, name="aux_field_time", fields=("Nfx",))
379380

380381
tmesh = np.linspace(0, 1, 10)
381382

tests/test_data/test_data_arrays.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
),
3131
]
3232
FIELDS = ("Ex", "Ey", "Ez", "Hx", "Hz")
33+
AUX_FIELDS = ("Nfz",)
3334
INTERVAL = 2
3435
ORDERS_X = list(range(-1, 2))
3536
ORDERS_Y = list(range(-2, 3))
@@ -51,6 +52,9 @@
5152
FIELD_TIME_MONITOR = td.FieldTimeMonitor(
5253
size=SIZE_3D, fields=FIELDS, name="field_time", interval=INTERVAL
5354
)
55+
AUX_FIELD_TIME_MONITOR = td.AuxFieldTimeMonitor(
56+
size=SIZE_3D, fields=AUX_FIELDS, name="aux_field_time", interval=INTERVAL
57+
)
5458
FIELD_MONITOR_2D = td.FieldMonitor(size=SIZE_2D, fields=FIELDS, name="field_2d", freqs=FREQS)
5559
FIELD_TIME_MONITOR_2D = td.FieldTimeMonitor(
5660
size=SIZE_2D, fields=FIELDS, name="field_time_2d", interval=INTERVAL
@@ -80,6 +84,7 @@
8084
MONITORS = [
8185
FIELD_MONITOR,
8286
FIELD_TIME_MONITOR,
87+
AUX_FIELD_TIME_MONITOR,
8388
MODE_MONITOR_WITH_FIELDS,
8489
PERMITTIVITY_MONITOR,
8590
MODE_MONITOR,

tests/test_data/test_monitor_data.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
FreqModeDataArray,
1212
)
1313
from tidy3d.components.data.monitor_data import (
14+
AuxFieldTimeData,
1415
DiffractionData,
1516
DirectivityData,
1617
FieldData,
@@ -24,6 +25,7 @@
2425

2526
from ..utils import AssertLogLevel
2627
from .test_data_arrays import (
28+
AUX_FIELD_TIME_MONITOR,
2729
DIFFRACTION_MONITOR,
2830
DIRECTIVITY_MONITOR,
2931
FIELD_MONITOR,
@@ -120,6 +122,17 @@ def make_field_time_data_2d(symmetry: bool = True):
120122
)
121123

122124

125+
def make_aux_field_time_data(symmetry: bool = True):
126+
sim = SIM_SYM if symmetry else SIM
127+
return AuxFieldTimeData(
128+
monitor=AUX_FIELD_TIME_MONITOR,
129+
Nfz=make_scalar_field_time_data_array("Ez", symmetry),
130+
symmetry=sim.symmetry,
131+
symmetry_center=sim.center,
132+
grid_expanded=sim.discretize_monitor(AUX_FIELD_TIME_MONITOR),
133+
)
134+
135+
123136
def make_mode_solver_data():
124137
mode_data = ModeData(
125138
monitor=MODE_MONITOR_WITH_FIELDS,

tests/test_data/test_sim_data.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
from ..utils import get_nested_shape
1616
from .test_data_arrays import FIELD_MONITOR, SIM, SIM_SYM
1717
from .test_monitor_data import (
18+
make_aux_field_time_data,
1819
make_diffraction_data,
1920
make_directivity_data,
2021
make_field_data,
@@ -32,6 +33,8 @@
3233
FIELD = make_field_data(symmetry=False)
3334
FIELD_TIME_SYM = make_field_time_data()
3435
FIELD_TIME = make_field_time_data(symmetry=False)
36+
AUX_FIELD_TIME_SYM = make_aux_field_time_data()
37+
AUX_FIELD_TIME = make_aux_field_time_data(symmetry=False)
3538
PERMITTIVITY_SYM = make_permittivity_data()
3639
PERMITTIVITY = make_permittivity_data(symmetry=False)
3740
MODE = make_mode_data()
@@ -45,6 +48,7 @@
4548
MONITOR_DATA = (
4649
FIELD,
4750
FIELD_TIME,
51+
AUX_FIELD_TIME,
4852
MODE_SOLVER,
4953
PERMITTIVITY,
5054
MODE,
@@ -56,6 +60,7 @@
5660
MONITOR_DATA_SYM = (
5761
FIELD_SYM,
5862
FIELD_TIME_SYM,
63+
AUX_FIELD_TIME_SYM,
5964
MODE_SOLVER,
6065
PERMITTIVITY_SYM,
6166
MODE,

tests/utils.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -787,6 +787,9 @@ def make_custom_data(lims, unstructured):
787787
size=(0, 0, 0), center=(0, 0, 0), fields=["Ex"], freqs=[1.5e14, 2e14], name="field"
788788
),
789789
td.FieldTimeMonitor(size=(0, 0, 0), center=(0, 0, 0), name="field_time", interval=100),
790+
td.AuxFieldTimeMonitor(
791+
size=(0, 0, 0), center=(0, 0, 0), fields=("Nfx",), name="aux_field_time", interval=100
792+
),
790793
td.FluxMonitor(size=(1, 1, 0), center=(0, 0, 0), freqs=[2e14, 2.5e14], name="flux"),
791794
td.FluxTimeMonitor(size=(1, 1, 0), center=(0, 0, 0), name="flux_time"),
792795
td.PermittivityMonitor(size=(1, 1, 0.1), name="eps", freqs=[1e14]),

tidy3d/__init__.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -269,6 +269,7 @@
269269

270270
# monitors
271271
from .components.monitor import (
272+
AuxFieldTimeMonitor,
272273
DiffractionMonitor,
273274
DirectivityMonitor,
274275
FieldMonitor,
@@ -467,6 +468,7 @@ def set_logging_level(level: str) -> None:
467468
"PlaneWaveBeamProfile",
468469
"FieldMonitor",
469470
"FieldTimeMonitor",
471+
"AuxFieldTimeMonitor",
470472
"FluxMonitor",
471473
"FluxTimeMonitor",
472474
"ModeMonitor",
@@ -503,6 +505,7 @@ def set_logging_level(level: str) -> None:
503505
"ModeSolverDataset",
504506
"FieldData",
505507
"FieldTimeData",
508+
"AuxFieldTimeData",
506509
"PermittivityData",
507510
"FluxData",
508511
"FluxTimeData",

0 commit comments

Comments
 (0)