Skip to content

Commit 07415ba

Browse files
prototype interpolated_data property
1 parent df5727b commit 07415ba

File tree

12 files changed

+225
-123
lines changed

12 files changed

+225
-123
lines changed

schemas/EMESimulation.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8374,6 +8374,10 @@
83748374
"minLength": 1,
83758375
"type": "string"
83768376
},
8377+
"reduce_data": {
8378+
"default": false,
8379+
"type": "boolean"
8380+
},
83778381
"size": {
83788382
"anyOf": [
83798383
{

schemas/ModeSimulation.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7812,6 +7812,10 @@
78127812
"minLength": 1,
78137813
"type": "string"
78147814
},
7815+
"reduce_data": {
7816+
"default": false,
7817+
"type": "boolean"
7818+
},
78157819
"size": {
78167820
"anyOf": [
78177821
{

schemas/Simulation.json

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11002,6 +11002,10 @@
1100211002
"minLength": 1,
1100311003
"type": "string"
1100411004
},
11005+
"reduce_data": {
11006+
"default": false,
11007+
"type": "boolean"
11008+
},
1100511009
"size": {
1100611010
"anyOf": [
1100711011
{
@@ -11778,6 +11782,10 @@
1177811782
"minLength": 1,
1177911783
"type": "string"
1178011784
},
11785+
"reduce_data": {
11786+
"default": false,
11787+
"type": "boolean"
11788+
},
1178111789
"size": {
1178211790
"anyOf": [
1178311791
{

schemas/TerminalComponentModeler.json

Lines changed: 26 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -11072,13 +11072,6 @@
1107211072
}
1107311073
]
1107411074
},
11075-
"interp_spec": {
11076-
"allOf": [
11077-
{
11078-
"$ref": "#/definitions/ModeInterpSpec"
11079-
}
11080-
]
11081-
},
1108211075
"interval_space": {
1108311076
"default": [
1108411077
1,
@@ -11310,13 +11303,6 @@
1131011303
}
1131111304
]
1131211305
},
11313-
"interp_spec": {
11314-
"allOf": [
11315-
{
11316-
"$ref": "#/definitions/ModeInterpSpec"
11317-
}
11318-
]
11319-
},
1132011306
"interval_space": {
1132111307
"default": [
1132211308
1,
@@ -11358,6 +11344,10 @@
1135811344
"minLength": 1,
1135911345
"type": "string"
1136011346
},
11347+
"reduce_data": {
11348+
"default": false,
11349+
"type": "boolean"
11350+
},
1136111351
"size": {
1136211352
"anyOf": [
1136311353
{
@@ -11502,6 +11492,13 @@
1150211492
}
1150311493
]
1150411494
},
11495+
"interp_spec": {
11496+
"allOf": [
11497+
{
11498+
"$ref": "#/definitions/ModeInterpSpec"
11499+
}
11500+
]
11501+
},
1150511502
"num_modes": {
1150611503
"default": 1,
1150711504
"exclusiveMinimum": 0,
@@ -11608,6 +11605,7 @@
1160811605
"bend_radius": null,
1160911606
"filter_pol": null,
1161011607
"group_index_step": false,
11608+
"interp_spec": null,
1161111609
"num_modes": 1,
1161211610
"num_pml": [
1161311611
0,
@@ -11792,13 +11790,6 @@
1179211790
}
1179311791
]
1179411792
},
11795-
"interp_spec": {
11796-
"allOf": [
11797-
{
11798-
"$ref": "#/definitions/ModeInterpSpec"
11799-
}
11800-
]
11801-
},
1180211793
"interval_space": {
1180311794
"default": [
1180411795
1,
@@ -11844,6 +11835,7 @@
1184411835
"bend_radius": null,
1184511836
"filter_pol": null,
1184611837
"group_index_step": false,
11838+
"interp_spec": null,
1184711839
"num_modes": 1,
1184811840
"num_pml": [
1184911841
0,
@@ -12060,13 +12052,6 @@
1206012052
}
1206112053
]
1206212054
},
12063-
"interp_spec": {
12064-
"allOf": [
12065-
{
12066-
"$ref": "#/definitions/ModeInterpSpec"
12067-
}
12068-
]
12069-
},
1207012055
"interval_space": {
1207112056
"default": [
1207212057
1,
@@ -12112,6 +12097,7 @@
1211212097
"bend_radius": null,
1211312098
"filter_pol": null,
1211412099
"group_index_step": false,
12100+
"interp_spec": null,
1211512101
"num_modes": 1,
1211612102
"num_pml": [
1211712103
0,
@@ -12138,6 +12124,10 @@
1213812124
"minLength": 1,
1213912125
"type": "string"
1214012126
},
12127+
"reduce_data": {
12128+
"default": false,
12129+
"type": "boolean"
12130+
},
1214112131
"size": {
1214212132
"anyOf": [
1214312133
{
@@ -12365,6 +12355,7 @@
1236512355
"bend_radius": null,
1236612356
"filter_pol": null,
1236712357
"group_index_step": false,
12358+
"interp_spec": null,
1236812359
"num_modes": 1,
1236912360
"num_pml": [
1237012361
0,
@@ -12542,6 +12533,13 @@
1254212533
],
1254312534
"default": false
1254412535
},
12536+
"interp_spec": {
12537+
"allOf": [
12538+
{
12539+
"$ref": "#/definitions/ModeInterpSpec"
12540+
}
12541+
]
12542+
},
1254512543
"num_modes": {
1254612544
"default": 1,
1254712545
"exclusiveMinimum": 0,
@@ -17792,19 +17790,6 @@
1779217790
"type": "PECFrame"
1779317791
}
1779417792
},
17795-
"interp_spec": {
17796-
"allOf": [
17797-
{
17798-
"$ref": "#/definitions/ModeInterpSpec"
17799-
}
17800-
],
17801-
"default": {
17802-
"attrs": {},
17803-
"method": "cheb",
17804-
"num_points": 21,
17805-
"type": "ModeInterpSpec"
17806-
}
17807-
},
1780817793
"mode_index": {
1780917794
"minimum": 0,
1781017795
"type": "integer"

tests/test_components/test_mode_interp.py

Lines changed: 31 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@
88

99
import tidy3d as td
1010
from tidy3d.plugins.mode import ModeSolver
11-
from tidy3d.plugins.smatrix.ports.wave import DEFAULT_WAVE_PORT_MODE_SPEC
1211

12+
# from tidy3d.plugins.smatrix.ports.wave import DEFAULT_WAVE_PORT_MODE_SPEC
1313
from ..test_data.test_data_arrays import MODE_SPEC, SIZE_2D
1414
from ..utils import AssertLogLevel
1515

@@ -322,12 +322,10 @@ def get_mode_solver_data():
322322
"""Create a simple ModeSolverData object for testing."""
323323
from tidy3d.components.data.data_array import GroupIndexDataArray, ModeDispersionDataArray
324324

325-
from ..test_data.test_data_arrays import (
326-
make_scalar_mode_field_data_array,
327-
)
325+
from ..test_data.test_data_arrays import SIM, make_scalar_mode_field_data_array
328326
from ..test_data.test_monitor_data import N_COMPLEX
329327

330-
freqs = np.linspace(1e14, 2e14, 5)
328+
freqs = N_COMPLEX.f.data
331329
num_modes = len(N_COMPLEX.mode_index)
332330
mode_indices = np.arange(num_modes)
333331
mode_spec = td.ModeSpec(num_modes=num_modes, sort_spec=td.ModeSortSpec(track_freq="central"))
@@ -337,6 +335,7 @@ def get_mode_solver_data():
337335
freqs=freqs,
338336
mode_spec=mode_spec,
339337
name="test_monitor",
338+
colocate=False,
340339
)
341340

342341
# Create n_group_raw and dispersion_raw with same shape as n_complex
@@ -353,18 +352,18 @@ def get_mode_solver_data():
353352
# Create mode data with the right frequencies
354353
mode_data = td.ModeSolverData(
355354
monitor=monitor,
356-
Ex=make_scalar_mode_field_data_array("Ex"),
357-
Ey=make_scalar_mode_field_data_array("Ey"),
358-
Ez=make_scalar_mode_field_data_array("Ez"),
359-
Hx=make_scalar_mode_field_data_array("Hx"),
360-
Hy=make_scalar_mode_field_data_array("Hy"),
361-
Hz=make_scalar_mode_field_data_array("Hz"),
362-
n_complex=N_COMPLEX.copy(),
355+
Ex=make_scalar_mode_field_data_array("Ex", symmetry=False),
356+
Ey=make_scalar_mode_field_data_array("Ey", symmetry=False),
357+
Ez=make_scalar_mode_field_data_array("Ez", symmetry=False),
358+
Hx=make_scalar_mode_field_data_array("Hx", symmetry=False),
359+
Hy=make_scalar_mode_field_data_array("Hy", symmetry=False),
360+
Hz=make_scalar_mode_field_data_array("Hz", symmetry=False),
361+
n_complex=N_COMPLEX,
363362
n_group_raw=n_group_raw,
364363
dispersion_raw=dispersion_raw,
365364
symmetry=(0, 0, 0),
366365
symmetry_center=(0, 0, 0),
367-
grid_expanded=td.Grid(boundaries=td.Coords(x=[0, 1], y=[0, 1], z=[0, 1])),
366+
grid_expanded=SIM.discretize_monitor(monitor),
368367
)
369368
return mode_data
370369

@@ -425,23 +424,24 @@ def test_mode_solver_data_interp_cheb():
425424
freqs=freqs_cheb,
426425
mode_spec=mode_spec,
427426
name="test_cheb",
427+
colocate=False,
428428
)
429429

430-
from ..test_data.test_data_arrays import make_scalar_mode_field_data_array
430+
from ..test_data.test_data_arrays import SIM, make_scalar_mode_field_data_array
431431
from ..test_data.test_monitor_data import N_COMPLEX
432432

433433
mode_data = td.ModeSolverData(
434434
monitor=monitor,
435-
Ex=make_scalar_mode_field_data_array("Ex"),
436-
Ey=make_scalar_mode_field_data_array("Ey"),
437-
Ez=make_scalar_mode_field_data_array("Ez"),
438-
Hx=make_scalar_mode_field_data_array("Hx"),
439-
Hy=make_scalar_mode_field_data_array("Hy"),
440-
Hz=make_scalar_mode_field_data_array("Hz"),
435+
Ex=make_scalar_mode_field_data_array("Ex", symmetry=False),
436+
Ey=make_scalar_mode_field_data_array("Ey", symmetry=False),
437+
Ez=make_scalar_mode_field_data_array("Ez", symmetry=False),
438+
Hx=make_scalar_mode_field_data_array("Hx", symmetry=False),
439+
Hy=make_scalar_mode_field_data_array("Hy", symmetry=False),
440+
Hz=make_scalar_mode_field_data_array("Hz", symmetry=False),
441441
n_complex=N_COMPLEX.copy(),
442442
symmetry=(0, 0, 0),
443443
symmetry_center=(0, 0, 0),
444-
grid_expanded=td.Grid(boundaries=td.Coords(x=[0, 1], y=[0, 1], z=[0, 1])),
444+
grid_expanded=SIM.discretize_monitor(monitor),
445445
)
446446

447447
# Interpolate to 50 frequencies
@@ -895,32 +895,27 @@ def test_mode_monitor_interp_spec_none():
895895
# ============================================================================
896896

897897

898-
def make_wave_port():
898+
def make_wave_port(num_interp_points=3, method="linear"):
899899
"""Make a WavePort."""
900-
from tidy3d.components.microwave.path_integrals.integrals.current import (
901-
AxisAlignedCurrentIntegral,
902-
)
903900
from tidy3d.plugins.smatrix.ports.wave import WavePort
904901

905902
return WavePort(
906903
center=(0, 0, 0),
907904
size=(1, 1, 0),
908905
direction="+",
909906
name="port1",
910-
current_integral=AxisAlignedCurrentIntegral(
911-
center=(0, 0, 0),
912-
size=(1, 1, 0),
913-
sign="+",
914-
extrapolate_to_endpoints=True,
915-
snap_contour_to_grid=True,
907+
mode_spec=td.MicrowaveModeSpec(
908+
num_modes=1,
909+
sort_spec=td.ModeSortSpec(track_freq="central"),
910+
interp_spec=td.ModeInterpSpec(num_points=num_interp_points, method=method),
916911
),
917912
)
918913

919914

920915
def test_wave_port_to_monitors_propagates_default_interp_spec():
921916
"""Test that WavePort.to_monitors() propagates default interp_spec to ModeMonitor."""
922917

923-
port = make_wave_port()
918+
port = make_wave_port(num_interp_points=3, method="linear")
924919

925920
freqs = np.linspace(1e14, 2e14, 20)
926921
monitors = port.to_monitors(freqs=freqs)
@@ -929,16 +924,13 @@ def test_wave_port_to_monitors_propagates_default_interp_spec():
929924
monitor = monitors[0]
930925
assert isinstance(monitor, td.ModeMonitor)
931926
assert monitor.mode_spec.interp_spec is not None
932-
assert (
933-
monitor.mode_spec.interp_spec.num_points
934-
== DEFAULT_WAVE_PORT_MODE_SPEC.interp_spec.num_points
935-
)
936-
assert monitor.mode_spec.interp_spec.method == DEFAULT_WAVE_PORT_MODE_SPEC.interp_spec.method
927+
assert monitor.mode_spec.interp_spec.num_points == 3
928+
assert monitor.mode_spec.interp_spec.method == "linear"
937929

938930

939931
def test_wave_port_to_monitors_propagates_custom_interp_spec():
940932
"""Test that WavePort.to_monitors() propagates custom interp_spec to ModeMonitor."""
941-
custom_mode_spec = td.ModeSpec(
933+
custom_mode_spec = td.MicrowaveModeSpec(
942934
num_modes=1,
943935
sort_spec=td.ModeSortSpec(track_freq="central"),
944936
interp_spec=td.ModeInterpSpec(num_points=8, method="cheb"),
@@ -958,7 +950,7 @@ def test_wave_port_to_monitors_propagates_custom_interp_spec():
958950

959951
def test_wave_port_to_monitors_propagates_none_interp_spec():
960952
"""Test that WavePort.to_monitors() propagates interp_spec=None to ModeMonitor."""
961-
mode_spec_no_interp = td.ModeSpec(
953+
mode_spec_no_interp = td.MicrowaveModeSpec(
962954
num_modes=1, sort_spec=td.ModeSortSpec(track_freq="central"), interp_spec=None
963955
)
964956
port = make_wave_port().updated_copy(mode_spec=mode_spec_no_interp)

tidy3d/components/base.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1397,3 +1397,16 @@ def __getattribute__(self, name: str):
13971397

13981398
_LazyProxy.__name__ = proxy_name
13991399
return _LazyProxy
1400+
1401+
1402+
class InterpolatableMixin(Tidy3dBaseModel):
1403+
"""Mixin to add a `reduce_data` field to a model."""
1404+
1405+
reduce_data: bool = pydantic.Field(
1406+
False,
1407+
title="Reduce Data",
1408+
description="If `mode_spec.interp_spec` is defined, one can use this flag "
1409+
"to record fields and quatities only at interpolation source frequency points. "
1410+
"The :class:`.ModeMonitorData` at requested frequencies can be obtain through "
1411+
"the :attr:`.ModeMonitorData.interpolated_copy` property.",
1412+
)

0 commit comments

Comments
 (0)