Skip to content

Commit 3a9ec06

Browse files
committed
fix: NedeljkovicSorefMashanovich serialization
1 parent 9bb8868 commit 3a9ec06

File tree

3 files changed

+272
-274
lines changed

3 files changed

+272
-274
lines changed

tests/test_components/test_parameter_perturbation.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -663,14 +663,15 @@ def test_delta_model():
663663
freq = td.C_0 / wvl
664664
delta_model = td.NedeljkovicSorefMashanovich(ref_freq=freq)
665665

666+
# make sure it serializes
667+
delta_model.json()
668+
666669
# make sure it's interpolating correctly
667670
coeffs_3_5 = np.array([3.10e-21, 1.210, 6.05e-20, 1.145, 6.95e-21, 0.986, 9.28e-18, 0.834])
668671
coeffs_4 = np.array([7.4e-22, 1.245, 5.43e-20, 1.153, 7.25e-21, 0.991, 9.99e-18, 0.839])
669672

670673
averaged_vals = (coeffs_3_5 + coeffs_4) / 2
671-
interpolated_results = [
672-
value.item() for _, value in delta_model._coeffs_at_ref_freq.data_vars.items()
673-
]
674+
interpolated_results = [v.item() for v in delta_model._coeffs_at_ref_freq.data.flat]
674675
error = np.abs(np.mean(averaged_vals - np.array(interpolated_results)))
675676

676677
assert error < 1e-16

tidy3d/components/data/data_array.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1253,6 +1253,11 @@ class SpatialVoltageDataArray(AbstractSpatialDataArray):
12531253
_dims = ("x", "y", "z", "voltage")
12541254

12551255

1256+
class PerturbationCoefficientDataArray(DataArray):
1257+
__slots__ = ()
1258+
_dims = ("wvl", "coeff")
1259+
1260+
12561261
DATA_ARRAY_TYPES = [
12571262
SpatialDataArray,
12581263
ScalarFieldDataArray,
@@ -1286,6 +1291,8 @@ class SpatialVoltageDataArray(AbstractSpatialDataArray):
12861291
CellDataArray,
12871292
IndexedDataArray,
12881293
IndexedVoltageDataArray,
1294+
SpatialVoltageDataArray,
1295+
PerturbationCoefficientDataArray,
12891296
]
12901297
DATA_ARRAY_MAP = {data_array.__name__: data_array for data_array in DATA_ARRAY_TYPES}
12911298

0 commit comments

Comments
 (0)