Skip to content

Commit 1c230af

Browse files
authored
Merge pull request #80 from mfschubert/recon2
improve longitudinal field calculation
2 parents e76aafe + a63d35f commit 1c230af

File tree

6 files changed

+13
-17
lines changed

6 files changed

+13
-17
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
## Unreleased
44
- Restructure codebase to integrate code originally in the `_orig` submodule within the main `src/fmmax` modules, separating the code available under the two licenses to the top (AGPL) and bottom (MIT) of each file.
55
- Include `transverse_permittivity_matrix` in the `LayerSolveResult`.
6+
- Update the manner in which the `ez` and `hz` field components are computed. Instead of relying on the Toeplitz matrix obtained from the inverse of permittivity (permeability), they now make use of the inverse of the Toeplitz matrix obtained from the permittiivity (permeability).
67

78
## 1.4.2 (July 10, 2025)
89
- Avoid use of `jax.pure_callback` in the eigendecomposition. This requires jax newer than 0.4.36.

src/fmmax/fields.py

Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -529,21 +529,16 @@ def fields_from_wave_amplitudes(
529529
)
530530
angular_frequency = angular_frequency[..., jnp.newaxis, jnp.newaxis]
531531

532-
# We use the the Fourier convolution matrix for the inverse of permittivity,
533-
# rather than inverting the Fourier convolution matrix of permittivity itself.
534-
# This improves convergence of the computed z-component of electric field.
535-
ez = (
536-
-layer_solve_result.inverse_z_permittivity_matrix
537-
@ (1j * kx * hy - 1j * ky * hx)
538-
/ (1j * angular_frequency)
532+
ez = jnp.linalg.solve(
533+
layer_solve_result.z_permittivity_matrix,
534+
-(1j * kx * hy - 1j * ky * hx) / (1j * angular_frequency),
539535
)
540536

541537
# Compute the z-directed magnetic field. The expression is similar to
542538
# equation 14 from [2012 Liu], but modified to allow for magnetic materials.
543-
hz = (
544-
layer_solve_result.inverse_z_permeability_matrix
545-
@ (1j * kx * ey - 1j * ky * ex)
546-
/ (1j * angular_frequency)
539+
hz = jnp.linalg.solve(
540+
layer_solve_result.z_permeability_matrix,
541+
(1j * kx * ey - 1j * ky * ex) / (1j * angular_frequency),
547542
)
548543

549544
assert ex.shape == ey.shape == ez.shape == hx.shape == hy.shape == hz.shape

tests/examples/test_crystal.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ def test_regression(self):
3636
with self.subTest("efield"):
3737
onp.testing.assert_allclose(
3838
[onp.mean(onp.abs(ex)), onp.mean(onp.abs(ey)), onp.mean(onp.abs(ez))],
39-
[8.311728e00, 1.293643e-06, 5.980783e00],
39+
[8.311728e00, 1.293643e-06, 5.886467e00],
4040
rtol=1e-4,
4141
)
4242
with self.subTest("hfield"):
@@ -70,7 +70,7 @@ def test_CW_regression(self):
7070
with self.subTest("efield"):
7171
onp.testing.assert_allclose(
7272
[onp.mean(onp.abs(ex)), onp.mean(onp.abs(ey)), onp.mean(onp.abs(ez))],
73-
[4.830812e-01, 4.060432e-04, 3.205514e-01],
73+
[4.830812e-01, 4.060432e-04, 3.208762e-01],
7474
rtol=1e-4,
7575
atol=1e-6,
7676
)
@@ -111,7 +111,7 @@ def test_broadband_regression(self):
111111
onp.mean(onp.abs(ey[wavelength_idx, ...])),
112112
onp.mean(onp.abs(ez[wavelength_idx, ...])),
113113
],
114-
[4.830811e-01, 4.060428e-04, 3.205514e-01],
114+
[4.830811e-01, 4.060428e-04, 3.208762e-01],
115115
rtol=1e-4,
116116
)
117117
with self.subTest("hfield"):

tests/examples/test_metal_dipole.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,4 +39,4 @@ def test_regression(self):
3939
with self.subTest("hy"):
4040
onp.testing.assert_allclose(onp.mean(onp.abs(hy)), 0.0, atol=1e-4)
4141
with self.subTest("hz"):
42-
onp.testing.assert_allclose(onp.mean(onp.abs(hz)), 9.952436, atol=1e-4)
42+
onp.testing.assert_allclose(onp.mean(onp.abs(hz)), 9.893226, atol=1e-4)

tests/examples/test_metal_pillars.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ def test_compute_fields_regression(self):
5252
onp.testing.assert_allclose(
5353
jnp.mean(jnp.abs(efields) ** 2, axis=(2, 3, 4, 5)),
5454
onp.asarray(
55-
[[0.046316, 0.052124], [1.047591, 1.859426], [0.145127, 0.077935]]
55+
[[0.046316, 0.052124], [1.047591, 1.859426], [0.322618, 0.095657]]
5656
),
5757
rtol=0.01,
5858
)

tests/examples/test_uled.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ def test_regression(self):
4343
[
4444
[64.48044, 8.389313, 2.740909],
4545
[8.386348, 64.499756, 2.740864],
46-
[15.16424, 15.166618, 8.501956],
46+
[15.824419, 15.819216, 8.312174],
4747
],
4848
rtol=1e-3,
4949
)

0 commit comments

Comments
 (0)